apple game-center: literal API paths (query guard reads them); api coverage regenerated
This commit is contained in:
parent
93d7f8a5fc
commit
d427b5c4a4
3 changed files with 27 additions and 13 deletions
|
|
@ -25,9 +25,15 @@ export interface GcState {
|
|||
achievements: GcExisting[];
|
||||
}
|
||||
|
||||
/** Literal paths (the API guard test reads them from the source). */
|
||||
const locsPath = (type: 'gameCenterLeaderboards' | 'gameCenterAchievements', id: string): string =>
|
||||
type === 'gameCenterLeaderboards' ? `/v1/gameCenterLeaderboards/${id}/localizations?limit=200` : `/v1/gameCenterAchievements/${id}/localizations?limit=200`;
|
||||
const itemsPath = (type: 'gameCenterLeaderboards' | 'gameCenterAchievements', detail: string): string =>
|
||||
type === 'gameCenterLeaderboards' ? `/v1/gameCenterDetails/${detail}/gameCenterLeaderboards?limit=200` : `/v1/gameCenterDetails/${detail}/gameCenterAchievements?limit=200`;
|
||||
|
||||
async function withLocs(c: Asc, list: J[], type: 'gameCenterLeaderboards' | 'gameCenterAchievements'): Promise<GcExisting[]> {
|
||||
const out: GcExisting[] = [];
|
||||
for (const x of list) out.push({ id: x.id, attributes: x.attributes ?? {}, localizations: (await c.all(`/v1/${type}/${x.id}/localizations?limit=200`)).map((l: J) => ({ id: l.id, attributes: l.attributes ?? {} })) });
|
||||
for (const x of list) out.push({ id: x.id, attributes: x.attributes ?? {}, localizations: (await c.all(locsPath(type, x.id))).map((l: J) => ({ id: l.id, attributes: l.attributes ?? {} })) });
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -100,12 +106,12 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
log(TAG, `Game Center switched on for version ${s.version.versionString}`);
|
||||
}
|
||||
for (const p of plan) {
|
||||
const type = p.kind === 'leaderboard' ? 'gameCenterLeaderboards' : 'gameCenterAchievements';
|
||||
const type = p.kind === 'leaderboard' ? 'gameCenterLeaderboards' as const : 'gameCenterAchievements' as const;
|
||||
const locType = p.kind === 'leaderboard' ? 'gameCenterLeaderboardLocalizations' : 'gameCenterAchievementLocalizations';
|
||||
const parentRel = p.kind === 'leaderboard' ? 'gameCenterLeaderboard' : 'gameCenterAchievement';
|
||||
let id = p.storeId;
|
||||
if (p.action === 'create') {
|
||||
const find = async () => (await c.all(`/v1/gameCenterDetails/${detail}/${type}?limit=200`)).find((x: J) => x.attributes?.vendorIdentifier === p.id)?.id ?? null;
|
||||
const find = async () => (await c.all(itemsPath(type, detail!))).find((x: J) => x.attributes?.vendorIdentifier === p.id)?.id ?? null;
|
||||
id = (await createOnce({ what: `${p.kind} ${p.id}`, tag: TAG, unique: true, find,
|
||||
create: async () => (await c.asc('POST', `/v1/${type}`, { data: { type, attributes: { ...p.attributes, vendorIdentifier: p.id }, relationships: { gameCenterDetail: { data: { type: 'gameCenterDetails', id: detail } } } } })).data.id as string })).value;
|
||||
log(TAG, `${p.kind} ${p.id}: created`);
|
||||
|
|
@ -118,7 +124,7 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
if (l.action === 'create') {
|
||||
const pid = id!;
|
||||
await createOnce({ what: `${p.kind} ${p.id} ${l.locale}`, tag: TAG, unique: true,
|
||||
find: async () => (await c.all(`/v1/${type}/${pid}/localizations?limit=200`)).find((x: J) => x.attributes?.locale === l.locale)?.id ?? null,
|
||||
find: async () => (await c.all(locsPath(type, pid))).find((x: J) => x.attributes?.locale === l.locale)?.id ?? null,
|
||||
create: async () => (await c.asc('POST', `/v1/${locType}`, { data: { type: locType, attributes: { locale: l.locale, ...l.attributes }, relationships: { [parentRel]: { data: { type, id: pid } } } } })).data.id as string });
|
||||
log(TAG, `${p.kind} ${p.id} ${l.locale}: created`);
|
||||
} else if (l.action === 'update') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue