storebound/cli/lib/loc-lock.ts

16 lines
1.3 KiB
TypeScript

// App Store Connect refuses to edit a localization that is already live: PATCH /v1/inAppPurchaseLocalizations/<id> (and
// subscriptionLocalizations, subscriptionGroupLocalizations) answers 409 ENTITY_ERROR.ATTRIBUTE.INVALID.UNMODIFIABLE
// "Cannot edit InAppPurchaseLocalization when it is in ACTIVE state" once the product was approved. The text then
// changes only with the next review of the product (or a new localization). The localization's `state` is read, the
// dry run marks such edits "not editable now" and the write skips them with a warning; a 409 of this kind that still
// comes (a state we did not know) is skipped the same way instead of ending the run. Pure.
/** Localization states that cannot be edited (Apple's own error names ACTIVE; the API lists APPROVED). */
const LOCKED = new Set(['ACTIVE', 'APPROVED']);
export const isLockedLocState = (state: unknown): boolean => typeof state === 'string' && LOCKED.has(state.toUpperCase());
export const lockedLocNote = (state: string): string => `not editable now (state ${state}; changes ship with the next review of the product / needs a new localization)`;
/** True for Apple's 409 UNMODIFIABLE answer to an edit of a live resource. */
export const isUnmodifiableError = (e: unknown): boolean => /UNMODIFIABLE|Cannot edit \w+ when it is in \w+ state/i.test(e instanceof Error ? e.message : String(e));