39 lines
2.8 KiB
TypeScript
39 lines
2.8 KiB
TypeScript
// App Review information on the editable version: contact, demo account (none), notes. Idempotent.
|
|
// storebound apple review-details [--contact-from <Apple ID of another app>] [--dry]
|
|
// The contact (name, phone, email) is personal data, so it is never in the config: it comes from
|
|
// .storebound/credentials.json "reviewContact", or is copied from another app of the same team with --contact-from.
|
|
// Notes: apple.info.reviewNotes in storebound.config.ts.
|
|
import type { Ctx } from '../lib/ctx';
|
|
import { need } from '../lib/ctx';
|
|
import { reviewContact } from '../lib/credentials';
|
|
import { done, log } from '../lib/log';
|
|
import { ascClient } from './asc';
|
|
|
|
export async function run(ctx: Ctx): Promise<void> {
|
|
const { config, root } = ctx.loaded;
|
|
const c = await ascClient(root, need(config.apple?.bundleId, 'apple.bundleId'), config.apple?.appId);
|
|
const version = await c.editableVersion();
|
|
if (!version) throw new Error('no editable App Store version (apple listing --version x.y.z creates it)');
|
|
|
|
let contact: Record<string, string> | null = null;
|
|
const from = ctx.args.get('contact-from');
|
|
if (from) {
|
|
for (const v of await c.all(`/v1/apps/${from}/appStoreVersions?limit=10`)) {
|
|
const a = (await c.maybe(`/v1/appStoreVersions/${v.id}/appStoreReviewDetail`))?.data?.attributes;
|
|
if (a?.contactEmail) { contact = { contactFirstName: a.contactFirstName, contactLastName: a.contactLastName, contactPhone: a.contactPhone, contactEmail: a.contactEmail }; break; }
|
|
}
|
|
if (!contact) throw new Error(`app ${from} has no review contact on its recent versions`);
|
|
} else {
|
|
const rc = reviewContact(root);
|
|
if (rc) contact = { contactFirstName: rc.firstName, contactLastName: rc.lastName, contactPhone: rc.phone, contactEmail: rc.email };
|
|
}
|
|
if (!contact) throw new Error('no review contact: add "reviewContact" to .storebound/credentials.json or pass --contact-from <app id>');
|
|
|
|
const attributes = { ...contact, demoAccountRequired: false, demoAccountName: null, demoAccountPassword: null, notes: config.apple?.info?.reviewNotes ?? '' };
|
|
if (ctx.args.has('dry')) { log('apple', `would set review details (contact ${from ? 'copied from ' + from : 'from credentials'}, notes ${attributes.notes.length} chars)`); return; }
|
|
const cur = (await c.maybe(`/v1/appStoreVersions/${version.id}/appStoreReviewDetail`))?.data;
|
|
if (cur) await c.asc('PATCH', `/v1/appStoreReviewDetails/${cur.id}`, { data: { type: 'appStoreReviewDetails', id: cur.id, attributes } });
|
|
else await c.asc('POST', '/v1/appStoreReviewDetails', { data: { type: 'appStoreReviewDetails', attributes,
|
|
relationships: { appStoreVersion: { data: { type: 'appStoreVersions', id: version.id } } } } });
|
|
done('apple', `review details set on ${version.attributes.versionString} (no demo account, notes ${attributes.notes.length} chars)`);
|
|
}
|