mirror of
https://github.com/expo/eas-cli.git
synced 2026-11-13 20:28:08 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
608bb669c2 |
No files matched your search
@@ -10,6 +10,7 @@ This is the log of notable changes to EAS CLI and related packages.
|
||||
|
||||
- [eas-cli] Add missing Apple metadata attributes for age ratings and content descriptions. ([#3584](https://github.com/expo/eas-cli/pull/3584) by [@EvanBacon](https://github.com/EvanBacon))
|
||||
- [eas-cli] Add App Clip metadata support to `metadata:push` and `metadata:pull` (default experience action, per-locale subtitle and header image, App Store review invocation URLs). ([#3590](https://github.com/expo/eas-cli/pull/3590) by [@EvanBacon](https://github.com/EvanBacon))
|
||||
- [eas-cli] Allow up to 3 video previews per device type in `metadata:push` and `metadata:pull`. Each preview type now accepts an array of preview configs in addition to the existing single-config form (which remains supported for backwards compatibility). ([@EvanBacon](https://github.com/EvanBacon))
|
||||
|
||||
### 🐛 Bug fixes
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@
|
||||
},
|
||||
"previews": {
|
||||
"type": "object",
|
||||
"description": "Video previews for this locale, organized by display type (e.g., IPHONE_67, IPAD_PRO_129)",
|
||||
"description": "Video previews for this locale, organized by display type (e.g., IPHONE_67, IPAD_PRO_129). Each device type accepts a single preview config (string or object) or an array of up to 3 preview configs.",
|
||||
"additionalProperties": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -348,6 +348,31 @@
|
||||
},
|
||||
"required": ["path"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "Video file path (relative to project root)"
|
||||
},
|
||||
"previewFrameTimeCode": {
|
||||
"type": "string",
|
||||
"description": "Optional preview frame time code (e.g., '00:05:00' for 5 seconds)"
|
||||
}
|
||||
},
|
||||
"required": ["path"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -800,65 +825,6 @@
|
||||
"vi": { "$ref": "#/definitions/apple/AppleAppClipLocalizedInfo", "description": "Vietnamese" }
|
||||
}
|
||||
},
|
||||
"ApplePricing": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"description": "App pricing configuration. NOTE: Apple migrated to base-territory pricing in 2023. EAS metadata currently uses the legacy `appPriceTier` API exposed by @expo/apple-utils.",
|
||||
"properties": {
|
||||
"tier": {
|
||||
"type": "string",
|
||||
"description": "App Store price tier id (e.g. \"0\" for free, \"1\" for tier 1).",
|
||||
"defaultSnippets": [
|
||||
{ "label": "Free", "body": "0" },
|
||||
{ "label": "Tier 1", "body": "1" }
|
||||
]
|
||||
},
|
||||
"schedule": {
|
||||
"type": "array",
|
||||
"description": "Future scheduled price changes. Each entry switches the app to the given tier on `startDate`. Currently parsed but not pushed (the underlying appPriceSchedules endpoint is not yet wrapped by @expo/apple-utils).",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["startDate", "tier"],
|
||||
"properties": {
|
||||
"startDate": {
|
||||
"type": "string",
|
||||
"description": "ISO-8601 date the new price tier takes effect.",
|
||||
"format": "date-time"
|
||||
},
|
||||
"tier": {
|
||||
"type": "string",
|
||||
"description": "App Store price tier id (e.g. \"0\" for free)."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"AppleAvailability": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"description": "Territory availability configuration. Use ISO-3166 alpha-3 codes (e.g. \"USA\", \"GBR\", \"JPN\") which match App Store Connect Territory ids.",
|
||||
"properties": {
|
||||
"territories": {
|
||||
"description": "Territories the app is available in. Use the literal string \"all\" to make the app available worldwide.",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "array",
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"description": "ISO-3166 alpha-3 territory code (e.g. \"USA\")."
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"enum": ["all"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"AppleAgeRatingOverride": {
|
||||
"enum": [
|
||||
"NONE",
|
||||
@@ -1093,14 +1059,6 @@
|
||||
"appClip": {
|
||||
"$ref": "#/definitions/apple/AppleAppClip",
|
||||
"description": "App Clip metadata. Only applies to apps that ship an App Clip target."
|
||||
},
|
||||
"pricing": {
|
||||
"$ref": "#/definitions/apple/ApplePricing",
|
||||
"description": "App pricing configuration (price tier + scheduled changes)."
|
||||
},
|
||||
"availability": {
|
||||
"$ref": "#/definitions/apple/AppleAvailability",
|
||||
"description": "Territory availability configuration."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,8 @@ import {
|
||||
AppleAppClip,
|
||||
AppleAppClipDefaultExperience,
|
||||
AppleAppClipLocalizedInfo,
|
||||
AppleAvailability,
|
||||
AppleMetadata,
|
||||
ApplePreviews,
|
||||
ApplePricing,
|
||||
AppleScreenshots,
|
||||
} from '../types';
|
||||
|
||||
@@ -259,14 +257,4 @@ export class AppleConfigReader {
|
||||
public getAppClipLocalizedInfo(locale: string): AppleAppClipLocalizedInfo | null {
|
||||
return this.schema.appClip?.defaultExperience?.info?.[locale] ?? null;
|
||||
}
|
||||
|
||||
/** Get the pricing block, or null if not configured. */
|
||||
public getPricing(): ApplePricing | null {
|
||||
return this.schema.pricing ?? null;
|
||||
}
|
||||
|
||||
/** Get the availability block, or null if not configured. */
|
||||
public getAvailability(): AppleAvailability | null {
|
||||
return this.schema.availability ?? null;
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,8 @@ import {
|
||||
AppleAppClipDefaultExperience,
|
||||
AppleAppClipLocalizedInfo,
|
||||
AppleAppClipReviewDetail,
|
||||
AppleAvailability,
|
||||
AppleMetadata,
|
||||
ApplePreviews,
|
||||
ApplePricing,
|
||||
AppleScreenshots,
|
||||
} from '../types';
|
||||
|
||||
@@ -213,11 +211,42 @@ export class AppleConfigWriter {
|
||||
Object.keys(screenshots).length > 0 ? screenshots : undefined;
|
||||
}
|
||||
|
||||
/** Set video previews for a specific locale */
|
||||
/**
|
||||
* Set video previews for a specific locale.
|
||||
*
|
||||
* Accepts either the legacy single-config form or the multi-preview array form
|
||||
* for each preview type. When an array contains exactly one entry, it is
|
||||
* unwrapped to the legacy single-object form for stable, minimal config diffs.
|
||||
*/
|
||||
public setPreviews(locale: string, previews: ApplePreviews): void {
|
||||
this.schema.info = this.schema.info ?? {};
|
||||
this.schema.info[locale] = this.schema.info[locale] ?? { title: '' };
|
||||
this.schema.info[locale].previews = Object.keys(previews).length > 0 ? previews : undefined;
|
||||
|
||||
if (Object.keys(previews).length === 0) {
|
||||
this.schema.info[locale].previews = undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
const normalized: ApplePreviews = {};
|
||||
for (const [previewType, value] of Object.entries(previews)) {
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
if (value.length === 0) {
|
||||
continue;
|
||||
}
|
||||
if (value.length === 1) {
|
||||
normalized[previewType as keyof ApplePreviews] = value[0];
|
||||
} else {
|
||||
normalized[previewType as keyof ApplePreviews] = value;
|
||||
}
|
||||
} else {
|
||||
normalized[previewType as keyof ApplePreviews] = value;
|
||||
}
|
||||
}
|
||||
|
||||
this.schema.info[locale].previews = Object.keys(normalized).length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
/** Set the App Clip default experience attributes (action, releaseWithAppStoreVersion). */
|
||||
@@ -243,29 +272,6 @@ export class AppleConfigWriter {
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the pricing configuration (price tier + scheduled changes). */
|
||||
public setPricing(pricing: ApplePricing | null): void {
|
||||
if (!pricing || (pricing.tier == null && !pricing.schedule?.length)) {
|
||||
delete this.schema.pricing;
|
||||
return;
|
||||
}
|
||||
this.schema.pricing = {
|
||||
tier: pricing.tier,
|
||||
schedule: pricing.schedule && pricing.schedule.length > 0 ? pricing.schedule : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/** Set the territory availability configuration. */
|
||||
public setAvailability(availability: AppleAvailability | null): void {
|
||||
if (!availability || availability.territories == null) {
|
||||
delete this.schema.availability;
|
||||
return;
|
||||
}
|
||||
this.schema.availability = {
|
||||
territories: availability.territories,
|
||||
};
|
||||
}
|
||||
|
||||
/** Set per-locale App Clip info (subtitle + header image). */
|
||||
public setAppClipLocalizedInfo(locale: string, info: AppleAppClipLocalizedInfo): void {
|
||||
this.schema.appClip = this.schema.appClip ?? {};
|
||||
|
||||
@@ -6,7 +6,6 @@ import type { AppInfoData } from './tasks/app-info';
|
||||
import type { AppReviewData } from './tasks/app-review-detail';
|
||||
import type { AppVersionData } from './tasks/app-version';
|
||||
import type { PreviewsData } from './tasks/previews';
|
||||
import type { PricingData } from './tasks/pricing';
|
||||
import type { ScreenshotsData } from './tasks/screenshots';
|
||||
|
||||
/**
|
||||
@@ -19,8 +18,7 @@ export type AppleData = { app: App; projectDir: string } & AppInfoData &
|
||||
AppReviewData &
|
||||
ScreenshotsData &
|
||||
PreviewsData &
|
||||
AppClipData &
|
||||
PricingData;
|
||||
AppClipData;
|
||||
|
||||
/**
|
||||
* The unprepared partial apple data, used within the `prepareAsync` tasks.
|
||||
|
||||
@@ -354,6 +354,17 @@ describe(PreviewsTask, () => {
|
||||
// Mock AppPreview.uploadAsync to avoid real file access
|
||||
jest.spyOn(AppPreview, 'uploadAsync').mockResolvedValue(newPreview);
|
||||
|
||||
// Mock AppPreviewSet.infoAsync for the reorder step
|
||||
jest.spyOn(AppPreviewSet, 'infoAsync').mockResolvedValue(
|
||||
new AppPreviewSet(requestContext, 'NEW_PSET_1', {
|
||||
previewType: PreviewType.IPHONE_67,
|
||||
appPreviews: [newPreview],
|
||||
} as any)
|
||||
);
|
||||
|
||||
const reorderMock = jest.fn().mockResolvedValue([]);
|
||||
AppPreviewSet.prototype.reorderPreviewsAsync = reorderMock;
|
||||
|
||||
const previewSets = new Map();
|
||||
previewSets.set('en-US', new Map());
|
||||
|
||||
@@ -375,6 +386,214 @@ describe(PreviewsTask, () => {
|
||||
waitForProcessing: true,
|
||||
})
|
||||
);
|
||||
// Single preview, current order matches: reorder should be skipped.
|
||||
expect(reorderMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uploads multiple previews when configured as an array', async () => {
|
||||
const config = new AppleConfigReader({
|
||||
info: {
|
||||
'en-US': {
|
||||
title: 'My App',
|
||||
previews: {
|
||||
IPHONE_67: [
|
||||
'./previews/intro.mp4',
|
||||
{ path: './previews/features.mp4', previewFrameTimeCode: '00:02:00' },
|
||||
'./previews/outro.mp4',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const locale = new AppStoreVersionLocalization(requestContext, 'LOC_1', {
|
||||
locale: 'en-US',
|
||||
} as any);
|
||||
|
||||
const intro = new AppPreview(requestContext, 'NEW_PV_INTRO', {
|
||||
fileName: 'intro.mp4',
|
||||
fileSize: 10240,
|
||||
previewFrameTimeCode: null,
|
||||
assetDeliveryState: { state: 'COMPLETE', errors: [], warnings: [] },
|
||||
} as any);
|
||||
const features = new AppPreview(requestContext, 'NEW_PV_FEATURES', {
|
||||
fileName: 'features.mp4',
|
||||
fileSize: 10240,
|
||||
previewFrameTimeCode: '00:02:00',
|
||||
assetDeliveryState: { state: 'COMPLETE', errors: [], warnings: [] },
|
||||
} as any);
|
||||
const outro = new AppPreview(requestContext, 'NEW_PV_OUTRO', {
|
||||
fileName: 'outro.mp4',
|
||||
fileSize: 10240,
|
||||
previewFrameTimeCode: null,
|
||||
assetDeliveryState: { state: 'COMPLETE', errors: [], warnings: [] },
|
||||
} as any);
|
||||
|
||||
const scope = nock('https://api.appstoreconnect.apple.com')
|
||||
.post(`/v1/${AppPreviewSet.type}`)
|
||||
.reply(201, {
|
||||
data: {
|
||||
id: 'NEW_PSET_1',
|
||||
type: AppPreviewSet.type,
|
||||
attributes: {
|
||||
previewType: PreviewType.IPHONE_67,
|
||||
appPreviews: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const uploadSpy = jest
|
||||
.spyOn(AppPreview, 'uploadAsync')
|
||||
.mockResolvedValueOnce(intro)
|
||||
.mockResolvedValueOnce(features)
|
||||
.mockResolvedValueOnce(outro);
|
||||
|
||||
// After upload Apple returns the previews in upload order, which already matches config.
|
||||
jest.spyOn(AppPreviewSet, 'infoAsync').mockResolvedValue(
|
||||
new AppPreviewSet(requestContext, 'NEW_PSET_1', {
|
||||
previewType: PreviewType.IPHONE_67,
|
||||
appPreviews: [intro, features, outro],
|
||||
} as any)
|
||||
);
|
||||
|
||||
const reorderMock = jest.fn().mockResolvedValue([]);
|
||||
AppPreviewSet.prototype.reorderPreviewsAsync = reorderMock;
|
||||
|
||||
const previewSets = new Map();
|
||||
previewSets.set('en-US', new Map());
|
||||
|
||||
await new PreviewsTask().uploadAsync({
|
||||
config,
|
||||
context: {
|
||||
previewSets,
|
||||
versionLocales: [locale],
|
||||
projectDir: '/test/project',
|
||||
} as any,
|
||||
});
|
||||
|
||||
expect(scope.isDone()).toBeTruthy();
|
||||
expect(uploadSpy).toHaveBeenCalledTimes(3);
|
||||
expect(uploadSpy).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
requestContext,
|
||||
expect.objectContaining({ filePath: '/test/project/previews/intro.mp4' })
|
||||
);
|
||||
expect(uploadSpy).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
requestContext,
|
||||
expect.objectContaining({
|
||||
filePath: '/test/project/previews/features.mp4',
|
||||
previewFrameTimeCode: '00:02:00',
|
||||
})
|
||||
);
|
||||
expect(uploadSpy).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
requestContext,
|
||||
expect.objectContaining({ filePath: '/test/project/previews/outro.mp4' })
|
||||
);
|
||||
// Order already matches config order, no reorder call expected.
|
||||
expect(reorderMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('reorders previews when ASC order differs from config order', async () => {
|
||||
const config = new AppleConfigReader({
|
||||
info: {
|
||||
'en-US': {
|
||||
title: 'My App',
|
||||
previews: {
|
||||
IPHONE_67: ['./previews/a.mp4', './previews/b.mp4'],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const locale = new AppStoreVersionLocalization(requestContext, 'LOC_1', {
|
||||
locale: 'en-US',
|
||||
} as any);
|
||||
|
||||
// Both previews already exist (matching filename + size), so no upload happens.
|
||||
const previewA = new AppPreview(requestContext, 'PV_A', {
|
||||
fileName: 'a.mp4',
|
||||
fileSize: 10240,
|
||||
previewFrameTimeCode: null,
|
||||
assetDeliveryState: { state: 'COMPLETE', errors: [], warnings: [] },
|
||||
} as any);
|
||||
const previewB = new AppPreview(requestContext, 'PV_B', {
|
||||
fileName: 'b.mp4',
|
||||
fileSize: 10240,
|
||||
previewFrameTimeCode: null,
|
||||
assetDeliveryState: { state: 'COMPLETE', errors: [], warnings: [] },
|
||||
} as any);
|
||||
|
||||
const previewTypeMap = new Map<PreviewType, AppPreviewSet>();
|
||||
// ASC reports them in [b, a] order — config wants [a, b].
|
||||
previewTypeMap.set(
|
||||
PreviewType.IPHONE_67,
|
||||
new AppPreviewSet(requestContext, 'PSET_1', {
|
||||
previewType: PreviewType.IPHONE_67,
|
||||
appPreviews: [previewB, previewA],
|
||||
} as any)
|
||||
);
|
||||
|
||||
jest.spyOn(AppPreview, 'uploadAsync').mockResolvedValue(previewA);
|
||||
|
||||
jest.spyOn(AppPreviewSet, 'infoAsync').mockResolvedValue(
|
||||
new AppPreviewSet(requestContext, 'PSET_1', {
|
||||
previewType: PreviewType.IPHONE_67,
|
||||
appPreviews: [previewB, previewA],
|
||||
} as any)
|
||||
);
|
||||
|
||||
const reorderMock = jest.fn().mockResolvedValue([]);
|
||||
AppPreviewSet.prototype.reorderPreviewsAsync = reorderMock;
|
||||
|
||||
const previewSets = new Map();
|
||||
previewSets.set('en-US', previewTypeMap);
|
||||
|
||||
await new PreviewsTask().uploadAsync({
|
||||
config,
|
||||
context: {
|
||||
previewSets,
|
||||
versionLocales: [locale],
|
||||
projectDir: '/test/project',
|
||||
} as any,
|
||||
});
|
||||
|
||||
expect(AppPreview.uploadAsync).not.toHaveBeenCalled();
|
||||
expect(reorderMock).toHaveBeenCalledWith({ appPreviews: ['PV_A', 'PV_B'] });
|
||||
});
|
||||
|
||||
it('skips a preview type whose array is empty', async () => {
|
||||
const config = new AppleConfigReader({
|
||||
info: {
|
||||
'en-US': {
|
||||
title: 'My App',
|
||||
previews: {
|
||||
IPHONE_67: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const locale = new AppStoreVersionLocalization(requestContext, 'LOC_1', {
|
||||
locale: 'en-US',
|
||||
} as any);
|
||||
|
||||
jest.spyOn(AppPreview, 'uploadAsync');
|
||||
|
||||
const previewSets = new Map();
|
||||
previewSets.set('en-US', new Map());
|
||||
|
||||
await new PreviewsTask().uploadAsync({
|
||||
config,
|
||||
context: {
|
||||
previewSets,
|
||||
versionLocales: [locale],
|
||||
projectDir: '/test/project',
|
||||
} as any,
|
||||
});
|
||||
|
||||
expect(AppPreview.uploadAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uploads new preview with object config including previewFrameTimeCode', async () => {
|
||||
@@ -420,6 +639,16 @@ describe(PreviewsTask, () => {
|
||||
// Mock AppPreview.uploadAsync to avoid real file access
|
||||
jest.spyOn(AppPreview, 'uploadAsync').mockResolvedValue(newPreview);
|
||||
|
||||
jest.spyOn(AppPreviewSet, 'infoAsync').mockResolvedValue(
|
||||
new AppPreviewSet(requestContext, 'NEW_PSET_1', {
|
||||
previewType: PreviewType.IPHONE_67,
|
||||
appPreviews: [newPreview],
|
||||
} as any)
|
||||
);
|
||||
|
||||
const reorderMock = jest.fn().mockResolvedValue([]);
|
||||
AppPreviewSet.prototype.reorderPreviewsAsync = reorderMock;
|
||||
|
||||
const previewSets = new Map();
|
||||
previewSets.set('en-US', new Map());
|
||||
|
||||
@@ -444,4 +673,67 @@ describe(PreviewsTask, () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('downloadAsync (multi-preview)', () => {
|
||||
it('emits an array when there are multiple previews in a set', async () => {
|
||||
const writer = jest.mocked(new AppleConfigWriter());
|
||||
|
||||
const previews = [
|
||||
new AppPreview(requestContext, 'PV_1', {
|
||||
fileName: 'intro.mp4',
|
||||
fileSize: 10240,
|
||||
previewFrameTimeCode: null,
|
||||
videoUrl: 'https://example.com/intro.mp4',
|
||||
assetDeliveryState: { state: 'COMPLETE', errors: [], warnings: [] },
|
||||
} as any),
|
||||
new AppPreview(requestContext, 'PV_2', {
|
||||
fileName: 'features.mp4',
|
||||
fileSize: 10240,
|
||||
previewFrameTimeCode: '00:01:00',
|
||||
videoUrl: 'https://example.com/features.mp4',
|
||||
assetDeliveryState: { state: 'COMPLETE', errors: [], warnings: [] },
|
||||
} as any),
|
||||
];
|
||||
|
||||
jest.spyOn(previews[0], 'getVideoUrl').mockReturnValue('https://example.com/intro.mp4');
|
||||
jest.spyOn(previews[1], 'getVideoUrl').mockReturnValue('https://example.com/features.mp4');
|
||||
|
||||
const previewTypeMap = new Map<PreviewType, AppPreviewSet>();
|
||||
previewTypeMap.set(
|
||||
PreviewType.IPHONE_67,
|
||||
new AppPreviewSet(requestContext, 'PSET_1', {
|
||||
previewType: PreviewType.IPHONE_67,
|
||||
appPreviews: previews,
|
||||
} as any)
|
||||
);
|
||||
|
||||
const locale = new AppStoreVersionLocalization(requestContext, 'LOC_1', {
|
||||
locale: 'en-US',
|
||||
} as any);
|
||||
|
||||
mockFetch.mockResolvedValue({
|
||||
ok: true,
|
||||
buffer: () => Promise.resolve(Buffer.from('fake-video-data')),
|
||||
});
|
||||
|
||||
await new PreviewsTask().downloadAsync({
|
||||
config: writer,
|
||||
context: {
|
||||
previewSets: new Map([['en-US', previewTypeMap]]),
|
||||
versionLocales: [locale],
|
||||
projectDir: '/test/project',
|
||||
} as any,
|
||||
});
|
||||
|
||||
expect(writer.setPreviews).toBeCalledWith('en-US', {
|
||||
[PreviewType.IPHONE_67]: [
|
||||
'store/apple/preview/en-US/IPHONE_67/intro.mp4',
|
||||
{
|
||||
path: 'store/apple/preview/en-US/IPHONE_67/features.mp4',
|
||||
previewFrameTimeCode: '00:01:00',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,268 +0,0 @@
|
||||
import { App, AppPrice, AppPriceTier, Territory } from '@expo/apple-utils';
|
||||
|
||||
import { requestContext } from './fixtures/requestContext';
|
||||
import { AppleConfigReader } from '../../config/reader';
|
||||
import { AppleConfigWriter } from '../../config/writer';
|
||||
import { PartialAppleData } from '../../data';
|
||||
import { PricingTask } from '../pricing';
|
||||
|
||||
jest.mock('../../../../ora');
|
||||
jest.mock('../../config/writer');
|
||||
|
||||
function makePrice(id: string, startDate: string, tierId: string): AppPrice {
|
||||
const tier = new AppPriceTier(requestContext, tierId, {});
|
||||
return new AppPrice(requestContext, id, {
|
||||
startDate,
|
||||
priceTier: tier,
|
||||
} as any);
|
||||
}
|
||||
|
||||
function makeTerritory(code: string, currency = 'USD'): Territory {
|
||||
return new Territory(requestContext, code, { currency });
|
||||
}
|
||||
|
||||
function makeApp(id = 'stub-id'): App {
|
||||
return new App(requestContext, id, {} as any);
|
||||
}
|
||||
|
||||
describe(PricingTask, () => {
|
||||
describe('prepareAsync', () => {
|
||||
it('populates appPrices and availableTerritories from App.infoAsync', async () => {
|
||||
const app = makeApp();
|
||||
const fetched = new App(requestContext, 'stub-id', {
|
||||
prices: [makePrice('p1', '2024-01-01T00:00:00Z', '0')],
|
||||
availableTerritories: [makeTerritory('USA'), makeTerritory('GBR', 'GBP')],
|
||||
} as any);
|
||||
const spy = jest.spyOn(App, 'infoAsync').mockResolvedValue(fetched);
|
||||
|
||||
const context: PartialAppleData = { app, projectDir: '/test' };
|
||||
await new PricingTask().prepareAsync({ context });
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
app.context,
|
||||
expect.objectContaining({
|
||||
id: 'stub-id',
|
||||
query: expect.objectContaining({
|
||||
includes: expect.arrayContaining(['prices', 'availableTerritories']),
|
||||
}),
|
||||
})
|
||||
);
|
||||
expect(context.appPrices).toHaveLength(1);
|
||||
expect(context.availableTerritories).toHaveLength(2);
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('initializes empty arrays when the API call fails', async () => {
|
||||
const spy = jest
|
||||
.spyOn(App, 'infoAsync')
|
||||
.mockRejectedValue(new Error('legacy pricing endpoint not available'));
|
||||
|
||||
const context: PartialAppleData = { app: makeApp(), projectDir: '/test' };
|
||||
await new PricingTask().prepareAsync({ context });
|
||||
|
||||
expect(context.appPrices).toEqual([]);
|
||||
expect(context.availableTerritories).toEqual([]);
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('downloadAsync', () => {
|
||||
it('clears pricing and availability when the app has neither', async () => {
|
||||
const writer = jest.mocked(new AppleConfigWriter());
|
||||
|
||||
await new PricingTask().downloadAsync({
|
||||
config: writer,
|
||||
context: { appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(writer.setPricing).toHaveBeenCalledWith(null);
|
||||
expect(writer.setAvailability).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
it('writes the current price tier (free)', async () => {
|
||||
const writer = jest.mocked(new AppleConfigWriter());
|
||||
|
||||
await new PricingTask().downloadAsync({
|
||||
config: writer,
|
||||
context: {
|
||||
appPrices: [makePrice('p1', '2020-01-01T00:00:00Z', '0')],
|
||||
availableTerritories: [],
|
||||
} as any,
|
||||
});
|
||||
|
||||
expect(writer.setPricing).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ tier: '0', schedule: undefined })
|
||||
);
|
||||
});
|
||||
|
||||
it('writes future price changes as schedule entries', async () => {
|
||||
const writer = jest.mocked(new AppleConfigWriter());
|
||||
const future = new Date(Date.now() + 1000 * 60 * 60 * 24 * 30).toISOString();
|
||||
|
||||
await new PricingTask().downloadAsync({
|
||||
config: writer,
|
||||
context: {
|
||||
appPrices: [makePrice('p1', '2020-01-01T00:00:00Z', '0'), makePrice('p2', future, '5')],
|
||||
availableTerritories: [],
|
||||
} as any,
|
||||
});
|
||||
|
||||
expect(writer.setPricing).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
tier: '0',
|
||||
schedule: [{ startDate: future, tier: '5' }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('writes territory codes', async () => {
|
||||
const writer = jest.mocked(new AppleConfigWriter());
|
||||
|
||||
await new PricingTask().downloadAsync({
|
||||
config: writer,
|
||||
context: {
|
||||
appPrices: [],
|
||||
availableTerritories: [makeTerritory('USA'), makeTerritory('GBR', 'GBP')],
|
||||
} as any,
|
||||
});
|
||||
|
||||
expect(writer.setAvailability).toHaveBeenCalledWith({ territories: ['USA', 'GBR'] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('uploadAsync', () => {
|
||||
it('skips when neither pricing nor availability is configured', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({}),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(updateSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('pushes the configured price tier', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({ pricing: { tier: '0' } }),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith({
|
||||
appPriceTier: '0',
|
||||
territories: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('pushes a paid price tier', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({ pricing: { tier: '5' } }),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith({ appPriceTier: '5', territories: undefined });
|
||||
});
|
||||
|
||||
it('warns and skips push for scheduled price changes (pending expo/third-party#147)', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({
|
||||
pricing: {
|
||||
tier: '0',
|
||||
schedule: [{ startDate: '2099-01-01T00:00:00Z', tier: '5' }],
|
||||
},
|
||||
}),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
// Tier still gets pushed; schedule is logged as a warning.
|
||||
expect(updateSpy).toHaveBeenCalledWith({ appPriceTier: '0', territories: undefined });
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('pushes a single-territory availability list', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({ availability: { territories: ['USA'] } }),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith({
|
||||
appPriceTier: undefined,
|
||||
territories: ['USA'],
|
||||
});
|
||||
});
|
||||
|
||||
it('pushes multiple territories, normalized and deduplicated', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({
|
||||
availability: { territories: ['usa', 'GBR', 'usa', 'JPN'] },
|
||||
}),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith({
|
||||
appPriceTier: undefined,
|
||||
territories: ['USA', 'GBR', 'JPN'],
|
||||
});
|
||||
});
|
||||
|
||||
it('expands `all` to every supported territory', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
const territorySpy = jest
|
||||
.spyOn(Territory, 'getAsync')
|
||||
.mockResolvedValue([
|
||||
makeTerritory('USA'),
|
||||
makeTerritory('GBR', 'GBP'),
|
||||
makeTerritory('JPN', 'JPY'),
|
||||
]);
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({ availability: { territories: 'all' } }),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(territorySpy).toHaveBeenCalled();
|
||||
expect(updateSpy).toHaveBeenCalledWith({
|
||||
appPriceTier: undefined,
|
||||
territories: ['USA', 'GBR', 'JPN'],
|
||||
});
|
||||
territorySpy.mockRestore();
|
||||
});
|
||||
|
||||
it('combines pricing and availability into a single update call', async () => {
|
||||
const app = makeApp();
|
||||
const updateSpy = jest.spyOn(app, 'updateAsync').mockResolvedValue(app);
|
||||
|
||||
await new PricingTask().uploadAsync({
|
||||
config: new AppleConfigReader({
|
||||
pricing: { tier: '0' },
|
||||
availability: { territories: ['USA', 'GBR'] },
|
||||
}),
|
||||
context: { app, appPrices: [], availableTerritories: [] } as any,
|
||||
});
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledTimes(1);
|
||||
expect(updateSpy).toHaveBeenCalledWith({
|
||||
appPriceTier: '0',
|
||||
territories: ['USA', 'GBR'],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,6 @@ import { AppInfoTask } from './app-info';
|
||||
import { AppReviewDetailTask } from './app-review-detail';
|
||||
import { AppVersionOptions, AppVersionTask } from './app-version';
|
||||
import { PreviewsTask } from './previews';
|
||||
import { PricingTask } from './pricing';
|
||||
import { ScreenshotsTask } from './screenshots';
|
||||
import { AppleTask } from '../task';
|
||||
|
||||
@@ -24,6 +23,5 @@ export function createAppleTasks({ version }: AppleTaskOptions = {}): AppleTask[
|
||||
new ScreenshotsTask(),
|
||||
new PreviewsTask(),
|
||||
new AppClipTask(),
|
||||
new PricingTask(),
|
||||
];
|
||||
}
|
||||
@@ -22,19 +22,35 @@ export type PreviewsData = {
|
||||
previewSets: PreviewSetsMap;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize preview config to always return an object with path and optional previewFrameTimeCode.
|
||||
*/
|
||||
function normalizePreviewConfig(config: ApplePreviewConfig): {
|
||||
/** Normalized preview entry used internally by the upload pipeline. */
|
||||
type NormalizedPreviewConfig = {
|
||||
path: string;
|
||||
previewFrameTimeCode?: string;
|
||||
} {
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize a single preview config into an object form with path and optional previewFrameTimeCode.
|
||||
*/
|
||||
function normalizePreviewConfig(config: ApplePreviewConfig): NormalizedPreviewConfig {
|
||||
if (typeof config === 'string') {
|
||||
return { path: config };
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the value stored in `ApplePreviews[previewType]` (which can be a single
|
||||
* config OR an array of configs) into an array of normalized configs.
|
||||
*/
|
||||
function normalizePreviewConfigs(
|
||||
value: ApplePreviewConfig | ApplePreviewConfig[]
|
||||
): NormalizedPreviewConfig[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(normalizePreviewConfig);
|
||||
}
|
||||
return [normalizePreviewConfig(value)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Task for managing App Store video previews.
|
||||
* Downloads existing previews and uploads new ones based on store configuration.
|
||||
@@ -86,34 +102,44 @@ export class PreviewsTask extends AppleTask {
|
||||
continue;
|
||||
}
|
||||
|
||||
// For now, we only handle the first preview per set (App Store allows up to 3)
|
||||
// We can extend this later to support multiple previews
|
||||
const preview = previewModels[0];
|
||||
const downloaded = await downloadPreviewAsync(
|
||||
context.projectDir,
|
||||
localeCode,
|
||||
previewType,
|
||||
preview,
|
||||
0
|
||||
);
|
||||
// Download all previews in this set, preserving order. Mirrors how
|
||||
// screenshots are handled: when a preview is in a broken state
|
||||
// (AWAITING_UPLOAD with no rendered videoUrl) the download will fail,
|
||||
// but we still preserve the entry pointing at its expected local path
|
||||
// so users can either drop in a replacement file or remove the entry
|
||||
// to delete the broken ASC record.
|
||||
const entries: ApplePreviewConfig[] = [];
|
||||
for (let i = 0; i < previewModels.length; i++) {
|
||||
const preview = previewModels[i];
|
||||
const downloaded = await downloadPreviewAsync(
|
||||
context.projectDir,
|
||||
localeCode,
|
||||
previewType,
|
||||
preview,
|
||||
i
|
||||
);
|
||||
|
||||
// When the download succeeds, write the real path. When it fails
|
||||
// (e.g. the preview is in a broken AWAITING_UPLOAD state with no
|
||||
// rendered videoUrl), preserve the entry in config so the user can
|
||||
// either drop in a replacement file or remove the entry to delete
|
||||
// the broken ASC record.
|
||||
const fileName = preview.attributes.fileName || 'preview.mp4';
|
||||
const relativePath =
|
||||
downloaded || path.join('store', 'apple', 'preview', localeCode, previewType, fileName);
|
||||
const fileName = preview.attributes.fileName || `${String(i + 1).padStart(2, '0')}.mp4`;
|
||||
const relativePath =
|
||||
downloaded || path.join('store', 'apple', 'preview', localeCode, previewType, fileName);
|
||||
|
||||
if (preview.attributes.previewFrameTimeCode) {
|
||||
previews[previewType] = {
|
||||
path: relativePath,
|
||||
previewFrameTimeCode: preview.attributes.previewFrameTimeCode,
|
||||
};
|
||||
} else {
|
||||
previews[previewType] = relativePath;
|
||||
if (preview.attributes.previewFrameTimeCode) {
|
||||
entries.push({
|
||||
path: relativePath,
|
||||
previewFrameTimeCode: preview.attributes.previewFrameTimeCode,
|
||||
});
|
||||
} else {
|
||||
entries.push(relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
if (entries.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// For backwards compatibility with existing single-preview configs,
|
||||
// emit the legacy single-object form when there's exactly one entry.
|
||||
previews[previewType] = entries.length === 1 ? entries[0] : entries;
|
||||
}
|
||||
|
||||
if (Object.keys(previews).length > 0) {
|
||||
@@ -146,8 +172,13 @@ export class PreviewsTask extends AppleTask {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const [previewType, previewConfig] of Object.entries(previews)) {
|
||||
if (!previewConfig) {
|
||||
for (const [previewType, previewValue] of Object.entries(previews)) {
|
||||
if (!previewValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const normalized = normalizePreviewConfigs(previewValue);
|
||||
if (normalized.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -155,7 +186,7 @@ export class PreviewsTask extends AppleTask {
|
||||
context.projectDir,
|
||||
localization,
|
||||
previewType as PreviewType,
|
||||
normalizePreviewConfig(previewConfig),
|
||||
normalized,
|
||||
context.previewSets.get(localeCode)
|
||||
);
|
||||
}
|
||||
@@ -164,23 +195,20 @@ export class PreviewsTask extends AppleTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync a preview set - upload new preview, delete old one if changed.
|
||||
* Sync a preview set against the configured previews.
|
||||
*
|
||||
* Mirrors the screenshots task: keeps unchanged previews (matched by filename
|
||||
* + size + completion state), uploads any new/changed previews, deletes
|
||||
* removed entries, and finally reorders the set to match config order.
|
||||
*/
|
||||
async function syncPreviewSetAsync(
|
||||
projectDir: string,
|
||||
localization: AppStoreVersionLocalization,
|
||||
previewType: PreviewType,
|
||||
previewConfig: { path: string; previewFrameTimeCode?: string },
|
||||
previewConfigs: NormalizedPreviewConfig[],
|
||||
existingSets: Map<PreviewType, AppPreviewSet> | undefined
|
||||
): Promise<void> {
|
||||
const locale = localization.attributes.locale;
|
||||
const absolutePath = path.resolve(projectDir, previewConfig.path);
|
||||
const fileName = path.basename(absolutePath);
|
||||
|
||||
if (!fs.existsSync(absolutePath)) {
|
||||
Log.warn(chalk`{yellow Video preview not found: ${absolutePath}}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get or create the preview set
|
||||
let previewSet = existingSets?.get(previewType);
|
||||
@@ -201,62 +229,127 @@ async function syncPreviewSetAsync(
|
||||
|
||||
const existingPreviews = previewSet.attributes.appPreviews || [];
|
||||
|
||||
// Check if we need to update (different filename, size, or no existing preview)
|
||||
const existingPreview = existingPreviews.find(p => p.attributes.fileName === fileName);
|
||||
const localSize = fs.statSync(absolutePath).size;
|
||||
|
||||
if (
|
||||
existingPreview &&
|
||||
existingPreview.isComplete() &&
|
||||
existingPreview.attributes.fileSize === localSize
|
||||
) {
|
||||
// Preview with same filename exists, check if we need to update preview frame time code
|
||||
if (
|
||||
previewConfig.previewFrameTimeCode &&
|
||||
existingPreview.attributes.previewFrameTimeCode !== previewConfig.previewFrameTimeCode
|
||||
) {
|
||||
await logAsync(
|
||||
() =>
|
||||
existingPreview.updateAsync({
|
||||
previewFrameTimeCode: previewConfig.previewFrameTimeCode,
|
||||
}),
|
||||
{
|
||||
pending: `Updating preview frame time code for ${chalk.bold(fileName)} (${locale})...`,
|
||||
success: `Updated preview frame time code for ${chalk.bold(fileName)} (${locale})`,
|
||||
failure: `Failed updating preview frame time code for ${chalk.bold(fileName)} (${locale})`,
|
||||
}
|
||||
);
|
||||
}
|
||||
Log.log(chalk`{dim Preview ${fileName} already exists, skipping upload}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete existing previews that don't match
|
||||
// Build a map of existing previews by filename for comparison.
|
||||
const existingByFilename = new Map<string, AppPreview>();
|
||||
for (const preview of existingPreviews) {
|
||||
if (preview.attributes.fileName !== fileName) {
|
||||
await logAsync(() => preview.deleteAsync(), {
|
||||
pending: `Deleting old preview ${chalk.bold(preview.attributes.fileName)} (${locale})...`,
|
||||
success: `Deleted old preview ${chalk.bold(preview.attributes.fileName)} (${locale})`,
|
||||
failure: `Failed deleting old preview ${chalk.bold(preview.attributes.fileName)} (${locale})`,
|
||||
});
|
||||
}
|
||||
existingByFilename.set(preview.attributes.fileName, preview);
|
||||
}
|
||||
|
||||
// Upload new preview
|
||||
await logAsync(
|
||||
() =>
|
||||
AppPreview.uploadAsync(localization.context, {
|
||||
id: previewSet!.id,
|
||||
filePath: absolutePath,
|
||||
waitForProcessing: true,
|
||||
previewFrameTimeCode: previewConfig.previewFrameTimeCode,
|
||||
}),
|
||||
{
|
||||
pending: `Uploading video preview ${chalk.bold(fileName)} (${locale})...`,
|
||||
success: `Uploaded video preview ${chalk.bold(fileName)} (${locale})`,
|
||||
failure: `Failed uploading video preview ${chalk.bold(fileName)} (${locale})`,
|
||||
// Track which previews to keep (by id), and which configs need uploading.
|
||||
const keptPreviewIds = new Set<string>();
|
||||
type UploadEntry = {
|
||||
absolutePath: string;
|
||||
fileName: string;
|
||||
previewFrameTimeCode?: string;
|
||||
};
|
||||
const toUpload: UploadEntry[] = [];
|
||||
|
||||
for (const previewConfig of previewConfigs) {
|
||||
const absolutePath = path.resolve(projectDir, previewConfig.path);
|
||||
const fileName = path.basename(absolutePath);
|
||||
|
||||
const existing = existingByFilename.get(fileName);
|
||||
const localSize = fs.existsSync(absolutePath) ? fs.statSync(absolutePath).size : null;
|
||||
|
||||
if (
|
||||
existing &&
|
||||
existing.isComplete() &&
|
||||
(localSize === null || existing.attributes.fileSize === localSize)
|
||||
) {
|
||||
keptPreviewIds.add(existing.id);
|
||||
existingByFilename.delete(fileName);
|
||||
|
||||
// If only the previewFrameTimeCode changed, patch it in place.
|
||||
if (
|
||||
previewConfig.previewFrameTimeCode &&
|
||||
existing.attributes.previewFrameTimeCode !== previewConfig.previewFrameTimeCode
|
||||
) {
|
||||
await logAsync(
|
||||
() =>
|
||||
existing.updateAsync({
|
||||
previewFrameTimeCode: previewConfig.previewFrameTimeCode,
|
||||
}),
|
||||
{
|
||||
pending: `Updating preview frame time code for ${chalk.bold(fileName)} (${locale})...`,
|
||||
success: `Updated preview frame time code for ${chalk.bold(fileName)} (${locale})`,
|
||||
failure: `Failed updating preview frame time code for ${chalk.bold(fileName)} (${locale})`,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
Log.log(chalk`{dim Preview ${fileName} already exists, skipping upload}`);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
);
|
||||
|
||||
toUpload.push({
|
||||
absolutePath,
|
||||
fileName,
|
||||
previewFrameTimeCode: previewConfig.previewFrameTimeCode,
|
||||
});
|
||||
}
|
||||
|
||||
// Delete previews that are no longer in config.
|
||||
for (const preview of existingByFilename.values()) {
|
||||
await logAsync(() => preview.deleteAsync(), {
|
||||
pending: `Deleting old preview ${chalk.bold(preview.attributes.fileName)} (${locale})...`,
|
||||
success: `Deleted old preview ${chalk.bold(preview.attributes.fileName)} (${locale})`,
|
||||
failure: `Failed deleting old preview ${chalk.bold(preview.attributes.fileName)} (${locale})`,
|
||||
});
|
||||
}
|
||||
|
||||
// Upload new previews.
|
||||
for (const entry of toUpload) {
|
||||
if (!fs.existsSync(entry.absolutePath)) {
|
||||
Log.warn(chalk`{yellow Video preview not found: ${entry.absolutePath}}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const newPreview = await logAsync(
|
||||
() =>
|
||||
AppPreview.uploadAsync(localization.context, {
|
||||
id: previewSet!.id,
|
||||
filePath: entry.absolutePath,
|
||||
waitForProcessing: true,
|
||||
previewFrameTimeCode: entry.previewFrameTimeCode,
|
||||
}),
|
||||
{
|
||||
pending: `Uploading video preview ${chalk.bold(entry.fileName)} (${locale})...`,
|
||||
success: `Uploaded video preview ${chalk.bold(entry.fileName)} (${locale})`,
|
||||
failure: `Failed uploading video preview ${chalk.bold(entry.fileName)} (${locale})`,
|
||||
}
|
||||
);
|
||||
|
||||
keptPreviewIds.add(newPreview.id);
|
||||
}
|
||||
|
||||
// Reorder previews to match config order (mirrors screenshots).
|
||||
if (keptPreviewIds.size > 0) {
|
||||
const refreshedSet = await AppPreviewSet.infoAsync(localization.context, {
|
||||
id: previewSet.id,
|
||||
});
|
||||
const refreshedPreviews = refreshedSet.attributes.appPreviews || [];
|
||||
const previewsByFilename = new Map<string, AppPreview>();
|
||||
for (const p of refreshedPreviews) {
|
||||
previewsByFilename.set(p.attributes.fileName, p);
|
||||
}
|
||||
|
||||
const orderedIds: string[] = [];
|
||||
for (const previewConfig of previewConfigs) {
|
||||
const fileName = path.basename(previewConfig.path);
|
||||
const preview = previewsByFilename.get(fileName);
|
||||
if (preview) {
|
||||
orderedIds.push(preview.id);
|
||||
}
|
||||
}
|
||||
|
||||
const currentIds = refreshedPreviews.map(p => p.id);
|
||||
if (
|
||||
orderedIds.length > 0 &&
|
||||
(orderedIds.length !== currentIds.length || orderedIds.some((id, i) => id !== currentIds[i]))
|
||||
) {
|
||||
await previewSet.reorderPreviewsAsync({ appPreviews: orderedIds });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,226 +0,0 @@
|
||||
import { App, AppPrice, Territory } from '@expo/apple-utils';
|
||||
import chalk from 'chalk';
|
||||
|
||||
import Log from '../../../log';
|
||||
import { logAsync } from '../../utils/log';
|
||||
import { AppleTask, TaskDownloadOptions, TaskPrepareOptions, TaskUploadOptions } from '../task';
|
||||
import { ApplePriceScheduleEntry, AppleTerritoryCode } from '../types';
|
||||
|
||||
/**
|
||||
* Sentinel territory list meaning "make the app available in every supported
|
||||
* App Store territory". Resolved at upload time against
|
||||
* `Territory.getAsync` so we don't drift if Apple adds new territories.
|
||||
*/
|
||||
export const AVAILABILITY_ALL = 'all' as const;
|
||||
|
||||
export type PricingData = {
|
||||
/**
|
||||
* Current `AppPrice` records for the app. Each record encodes a (startDate,
|
||||
* priceTier) pair — the active price tier is the most recent entry whose
|
||||
* startDate is in the past.
|
||||
*/
|
||||
appPrices: AppPrice[];
|
||||
/** Territories the app is currently available in. */
|
||||
availableTerritories: Territory[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Task for managing app pricing (price tier + scheduled changes) and
|
||||
* territory availability. Apple groups these together because both are set
|
||||
* via the legacy `App` PATCH endpoint that `@expo/apple-utils` exposes via
|
||||
* `App.updateAsync({ appPriceTier, territories })`.
|
||||
*
|
||||
* Newer App Store Connect APIs (`appPriceSchedules`, `appAvailabilities`)
|
||||
* supersede this for accounts on the post-2023 base-territory pricing model,
|
||||
* but those endpoints are not yet wrapped by `@expo/apple-utils`. The reader
|
||||
* accepts a `pricing.schedule` block that we can wire up once the new
|
||||
* helpers land.
|
||||
*
|
||||
* TODO(expo/third-party#147): Once `@expo/apple-utils` is bumped to include
|
||||
* the new pricing helpers, wire up schedule push:
|
||||
*
|
||||
* - Use `AppPriceSchedule.createAsync(context, { appId, baseTerritoryId, manualPrices })`
|
||||
* to push the full schedule. Each `manualPrices` entry takes
|
||||
* `{ appPricePointId, startDate?, endDate? }`.
|
||||
*
|
||||
* - IMPORTANT: `AppPriceSchedule.createAsync` REPLACES the entire prior
|
||||
* schedule. When pushing, the full schedule from config must be sent --
|
||||
* omitting entries will remove them from App Store Connect. There is no
|
||||
* diff/merge behavior.
|
||||
*
|
||||
* - Use `AppPricePoint.getForAppAsync(context, appId, { query })` to
|
||||
* resolve tier names to `appPricePointId` values, filterable by territory.
|
||||
*
|
||||
* - Use `App.getPriceScheduleAsync()` to read the current schedule (singular
|
||||
* relationship: `apps/{id}/appPriceSchedule`).
|
||||
*
|
||||
* - Territory availability is separate from pricing in the modern API --
|
||||
* it's managed via `TerritoryAvailability`, not via price schedules.
|
||||
* The legacy `App.updateAsync({ territories })` path used below still
|
||||
* works for setting availability.
|
||||
*/
|
||||
export class PricingTask extends AppleTask {
|
||||
public name = (): string => 'pricing and availability';
|
||||
|
||||
public async prepareAsync({ context }: TaskPrepareOptions): Promise<void> {
|
||||
context.appPrices = [];
|
||||
context.availableTerritories = [];
|
||||
|
||||
// Pull the current `prices` and `availableTerritories` relationships
|
||||
// onto the in-memory App object. We refetch via `infoAsync` because the
|
||||
// App used elsewhere in the flow is loaded without these includes.
|
||||
let appWithPricing: App;
|
||||
try {
|
||||
appWithPricing = await App.infoAsync(context.app.context, {
|
||||
id: context.app.id,
|
||||
query: {
|
||||
includes: ['prices', 'prices.priceTier', 'availableTerritories'],
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
// Pricing/availability are not always retrievable for every app state
|
||||
// (e.g. apps removed from sale, or accounts on the new pricing model
|
||||
// that 404 the legacy endpoints). Don't block the rest of the sync.
|
||||
Log.warn(
|
||||
chalk`{yellow Skipped pricing/availability prepare - failed to load: ${error?.message ?? error}}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
context.appPrices = appWithPricing.attributes.prices ?? [];
|
||||
context.availableTerritories = appWithPricing.attributes.availableTerritories ?? [];
|
||||
}
|
||||
|
||||
public async downloadAsync({ config, context }: TaskDownloadOptions): Promise<void> {
|
||||
// Pricing → schema.pricing
|
||||
const sortedPrices = [...(context.appPrices ?? [])].sort((a, b) =>
|
||||
(a.attributes.startDate ?? '').localeCompare(b.attributes.startDate ?? '')
|
||||
);
|
||||
|
||||
if (sortedPrices.length === 0) {
|
||||
config.setPricing(null);
|
||||
} else {
|
||||
// The "current" tier is the most recent entry whose startDate is in
|
||||
// the past (or the earliest entry if everything is in the future).
|
||||
const now = new Date().toISOString();
|
||||
const past = sortedPrices.filter(p => (p.attributes.startDate ?? '') <= now);
|
||||
const currentEntry = past.length > 0 ? past[past.length - 1] : sortedPrices[0];
|
||||
const future = sortedPrices.filter(p => (p.attributes.startDate ?? '') > now);
|
||||
|
||||
const schedule: ApplePriceScheduleEntry[] = future.map(p => ({
|
||||
startDate: p.attributes.startDate,
|
||||
tier: p.attributes.priceTier?.id ?? '',
|
||||
}));
|
||||
|
||||
config.setPricing({
|
||||
tier: currentEntry.attributes.priceTier?.id,
|
||||
schedule: schedule.length > 0 ? schedule : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
// Availability → schema.availability
|
||||
const territories = context.availableTerritories ?? [];
|
||||
if (territories.length === 0) {
|
||||
config.setAvailability(null);
|
||||
} else {
|
||||
config.setAvailability({
|
||||
territories: territories.map(t => t.id),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async uploadAsync({ config, context }: TaskUploadOptions): Promise<void> {
|
||||
const pricing = config.getPricing();
|
||||
const availability = config.getAvailability();
|
||||
|
||||
if (!pricing && !availability) {
|
||||
Log.log(chalk`{dim - Skipped pricing and availability, not configured}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pricing?.schedule && pricing.schedule.length > 0) {
|
||||
// TODO(expo/third-party#147): Replace this warning with a call to
|
||||
// AppPriceSchedule.createAsync once @expo/apple-utils is bumped.
|
||||
// Remember: createAsync REPLACES the entire schedule, so the full
|
||||
// config must be sent (not just the diff).
|
||||
Log.warn(
|
||||
chalk`{yellow pricing.schedule is not yet pushed. Scheduled price changes require a newer @expo/apple-utils with AppPriceSchedule support (see expo/third-party#147). Only pricing.tier is applied.}`
|
||||
);
|
||||
}
|
||||
|
||||
// Territory availability is set via the legacy App.updateAsync({ territories })
|
||||
// endpoint below. The modern ASC API uses TerritoryAvailability as a separate
|
||||
// resource from pricing (not part of appPriceSchedules). The legacy path works
|
||||
// for both old and new pricing-model accounts.
|
||||
let resolvedTerritories: AppleTerritoryCode[] | undefined;
|
||||
if (availability?.territories) {
|
||||
resolvedTerritories = await resolveTerritoriesAsync({
|
||||
context,
|
||||
desired: availability.territories,
|
||||
});
|
||||
}
|
||||
|
||||
const appPriceTier = pricing?.tier;
|
||||
if (appPriceTier == null && resolvedTerritories == null) {
|
||||
// Nothing to do — both blocks were configured but neither set a value
|
||||
// we can act on (e.g. only `pricing.schedule` was provided).
|
||||
return;
|
||||
}
|
||||
|
||||
const summary: string[] = [];
|
||||
if (appPriceTier != null) {
|
||||
summary.push(`tier ${chalk.bold(appPriceTier)}`);
|
||||
}
|
||||
if (resolvedTerritories != null) {
|
||||
summary.push(`${chalk.bold(resolvedTerritories.length)} territories`);
|
||||
}
|
||||
|
||||
context.app = await logAsync(
|
||||
() =>
|
||||
context.app.updateAsync({
|
||||
appPriceTier,
|
||||
territories: resolvedTerritories,
|
||||
}),
|
||||
{
|
||||
pending: `Updating pricing and availability (${summary.join(', ')})...`,
|
||||
success: `Updated pricing and availability (${summary.join(', ')})`,
|
||||
failure: 'Failed to update pricing and availability',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a desired territory list (either an explicit code list or the
|
||||
* `'all'` sentinel) into an array of ISO territory codes the App Store
|
||||
* Connect API will accept.
|
||||
*/
|
||||
async function resolveTerritoriesAsync({
|
||||
context,
|
||||
desired,
|
||||
}: {
|
||||
context: { app: App };
|
||||
desired: AppleTerritoryCode[] | typeof AVAILABILITY_ALL;
|
||||
}): Promise<AppleTerritoryCode[]> {
|
||||
if (desired === AVAILABILITY_ALL) {
|
||||
const territories = await Territory.getAsync(context.app.context, {
|
||||
query: { limit: 200 },
|
||||
});
|
||||
return territories.map(t => t.id);
|
||||
}
|
||||
// Deduplicate, drop empties, and uppercase to match ASC's canonical form.
|
||||
const seen = new Set<string>();
|
||||
const out: string[] = [];
|
||||
for (const code of desired) {
|
||||
if (!code) {
|
||||
continue;
|
||||
}
|
||||
const normalized = code.toUpperCase();
|
||||
if (seen.has(normalized)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(normalized);
|
||||
out.push(normalized);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -36,11 +36,16 @@ export type ApplePreviewConfig =
|
||||
|
||||
/**
|
||||
* Video previews organized by display type.
|
||||
* Key is the display type (e.g., 'IPHONE_67'), value is the preview config.
|
||||
* Key is the display type (e.g., 'IPHONE_67'), value is the preview config or an array of preview configs.
|
||||
* Apple supports up to 3 previews per device type. A single object/string is still
|
||||
* accepted for backwards compatibility with existing store configs.
|
||||
* @example { "IPHONE_67": "./previews/demo.mp4" }
|
||||
* @example { "IPHONE_67": { path: "./previews/demo.mp4", previewFrameTimeCode: "00:05:00" } }
|
||||
* @example { "IPHONE_67": ["./previews/intro.mp4", "./previews/features.mp4"] }
|
||||
*/
|
||||
export type ApplePreviews = Partial<Record<ApplePreviewType, ApplePreviewConfig>>;
|
||||
export type ApplePreviews = Partial<
|
||||
Record<ApplePreviewType, ApplePreviewConfig | ApplePreviewConfig[]>
|
||||
>;
|
||||
|
||||
export interface AppleMetadata {
|
||||
version?: string;
|
||||
@@ -54,65 +59,8 @@ export interface AppleMetadata {
|
||||
review?: AppleReview;
|
||||
/** App Clip metadata. Only applies to apps that ship an App Clip target. */
|
||||
appClip?: AppleAppClip;
|
||||
/** Pricing configuration for the app (price tier, scheduled changes). */
|
||||
pricing?: ApplePricing;
|
||||
/** Territory availability configuration for the app. */
|
||||
availability?: AppleAvailability;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pricing configuration for an app.
|
||||
*
|
||||
* NOTE: Apple migrated to "base territory" pricing in 2023, replacing the
|
||||
* legacy global price tier model. The App Store Connect API still exposes a
|
||||
* `priceTier` concept on the legacy `appPrices`/`appPriceTiers` resources,
|
||||
* which is what `@expo/apple-utils` currently exposes via
|
||||
* `App.updateAsync({ appPriceTier })`. Newer apps may need to use
|
||||
* `appPriceSchedules` + `appPricePoints` (which require selecting a base
|
||||
* territory and a price point id), but those endpoints are not yet wrapped by
|
||||
* `@expo/apple-utils`. We use the legacy field for now and document this in
|
||||
* the PR. The schema is intentionally forward-compatible.
|
||||
*/
|
||||
export interface ApplePricing {
|
||||
/**
|
||||
* App Store price tier (e.g. `'0'` for free, `'1'` for tier 1). When
|
||||
* unset on a brand new app, the App Store defaults to free (tier 0).
|
||||
*/
|
||||
tier?: string;
|
||||
/**
|
||||
* Future scheduled price changes. Each entry switches the app to the
|
||||
* given tier on `startDate`. The first entry that matches "now" or earlier
|
||||
* is treated as the current price. This block is currently parsed but not
|
||||
* pushed (the legacy `App.updateAsync` endpoint exposed by
|
||||
* `@expo/apple-utils` only sets the active tier).
|
||||
*/
|
||||
schedule?: ApplePriceScheduleEntry[];
|
||||
}
|
||||
|
||||
export interface ApplePriceScheduleEntry {
|
||||
/** ISO-8601 date the new price tier takes effect. */
|
||||
startDate: string;
|
||||
/** App Store price tier id (e.g. `'0'` for free). */
|
||||
tier: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Territory availability configuration. Use ISO-3166 alpha-3 codes (e.g.
|
||||
* `"USA"`, `"GBR"`, `"JPN"`) — these match the App Store Connect Territory
|
||||
* resource ids.
|
||||
*/
|
||||
export interface AppleAvailability {
|
||||
/**
|
||||
* The territories the app is available in. Use the literal string `'all'`
|
||||
* to make the app available worldwide (every territory currently supported
|
||||
* by App Store Connect). Omitting this field leaves availability untouched.
|
||||
*/
|
||||
territories?: AppleTerritoryCode[] | 'all';
|
||||
}
|
||||
|
||||
/** ISO-3166 alpha-3 territory code (e.g. `"USA"`, `"GBR"`). */
|
||||
export type AppleTerritoryCode = string;
|
||||
|
||||
/** App Clip action enum values from App Store Connect API */
|
||||
export type AppleAppClipAction = `${AppClipAction}`;
|
||||
|
||||
|
||||
Reference in new issue
Block a user