@limrun/ui 0.14.0-rc.3 → 0.14.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-store-relay/index.cjs +3 -3
- package/dist/app-store-relay/index.d.ts +108 -4
- package/dist/app-store-relay/index.js +353 -160
- package/dist/app-store-relay/react.cjs +1 -1
- package/dist/app-store-relay/react.js +32 -33
- package/dist/apple-credentials/index.cjs +1 -0
- package/dist/apple-credentials/index.d.ts +110 -0
- package/dist/apple-credentials/index.js +291 -0
- package/dist/browser-storage-BnO-Ma-e.mjs +219 -0
- package/dist/browser-storage-DLxIqZk5.js +1 -0
- package/dist/client-C9z_sgOf.js +1 -0
- package/dist/{client-C8ZDEjtD.mjs → client-CFDB4mX5.mjs} +38 -31
- package/dist/components/remote-control.d.ts +156 -0
- package/dist/core/device-install/apple/provisioning.d.ts +25 -0
- package/dist/core/device-install/apple/relay.d.ts +13 -0
- package/dist/core/device-install/storage/browser-storage.d.ts +8 -0
- package/dist/core/device-install/storage/index.d.ts +1 -0
- package/dist/core/device-install/storage/secret-store.d.ts +124 -0
- package/dist/core/device-install/types.d.ts +6 -0
- package/dist/core/errors.d.ts +1 -0
- package/dist/core/play-publish/google.d.ts +1 -1
- package/dist/device-build/index.cjs +1 -1
- package/dist/device-build/index.js +21 -20
- package/dist/device-build/react.cjs +1 -1
- package/dist/device-build/react.js +42 -43
- package/dist/device-install/index.cjs +1 -1
- package/dist/device-install/index.js +64 -63
- package/dist/device-install/react.cjs +1 -1
- package/dist/device-install/react.js +47 -49
- package/dist/errors-BSkqS7U-.js +1 -0
- package/dist/errors-gy8yQJos.mjs +6 -0
- package/dist/gsa-srp-Bme3JLEi.mjs +266 -0
- package/dist/gsa-srp-CCIfUz7Y.js +1 -0
- package/dist/index-ChhtuQ7e.js +22 -0
- package/dist/index-YDu8K9a4.mjs +11279 -0
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1405 -1125
- package/dist/play-publish/index.cjs +1 -1
- package/dist/play-publish/index.js +27 -24
- package/dist/play-publish/react.cjs +1 -1
- package/dist/play-publish/react.d.ts +12 -2
- package/dist/play-publish/react.js +70 -60
- package/dist/{provisioning-BmsEnF6X.mjs → provisioning-CDPvxd1h.mjs} +64 -33
- package/dist/provisioning-CbC4h--7.js +1 -0
- package/package.json +6 -1
- package/src/app-store-relay/index.ts +358 -23
- package/src/app-store-relay/react.ts +1 -4
- package/src/apple-credentials/index.test.ts +180 -0
- package/src/apple-credentials/index.ts +388 -0
- package/src/components/remote-control.css +32 -0
- package/src/components/remote-control.tsx +865 -5
- package/src/core/device-install/apple/client.ts +13 -6
- package/src/core/device-install/apple/provisioning.test.ts +30 -0
- package/src/core/device-install/apple/provisioning.ts +39 -0
- package/src/core/device-install/apple/relay.ts +20 -0
- package/src/core/device-install/operations/operations.ts +7 -5
- package/src/core/device-install/storage/browser-storage.test.ts +65 -0
- package/src/core/device-install/storage/browser-storage.ts +33 -0
- package/src/core/device-install/storage/index.ts +1 -0
- package/src/core/device-install/storage/secret-store.ts +332 -0
- package/src/core/device-install/types.ts +6 -0
- package/src/core/errors.ts +3 -0
- package/src/core/play-publish/google.ts +11 -2
- package/src/device-build/react.ts +1 -4
- package/src/device-install/demo/demo.tsx +1 -4
- package/src/device-install/react.ts +1 -4
- package/src/play-publish/README.md +5 -4
- package/src/play-publish/react.ts +72 -32
- package/vite.config.ts +1 -0
- package/dist/browser-storage-Cx9eW-bm.mjs +0 -205
- package/dist/browser-storage-jJaIht4K.js +0 -1
- package/dist/client-BtC4n_qf.js +0 -1
- package/dist/index-CMeQfhYy.js +0 -22
- package/dist/index-DFdCvi2_.mjs +0 -11543
- package/dist/provisioning-Va0PH4Kk.js +0 -1
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAdHocProfileRequest,
|
|
3
|
+
createAppStoreProfileRequest,
|
|
3
4
|
createBundleIDRequest,
|
|
4
5
|
createDevelopmentProfileRequest,
|
|
5
6
|
downloadCertificateRequest,
|
|
6
7
|
downloadDistributionCertificateRequest,
|
|
7
8
|
downloadProfileRequest,
|
|
8
9
|
findAdHocProfilesRequest,
|
|
10
|
+
findAppStoreProfilesRequest,
|
|
9
11
|
findBundleIDRequest,
|
|
10
12
|
findDevelopmentCertificatesRequest,
|
|
11
13
|
findDevelopmentProfilesRequest,
|
|
12
14
|
findDeviceRequest,
|
|
13
15
|
findDistributionCertificatesRequest,
|
|
14
16
|
listTeamsRequest,
|
|
17
|
+
proxyAppStoreConnectRequest,
|
|
15
18
|
proxyProvisioningRequest,
|
|
16
19
|
registerDeviceRequest,
|
|
17
20
|
submitDevelopmentCSRRequest,
|
|
@@ -35,11 +38,13 @@ export type {
|
|
|
35
38
|
AppleDeveloperPortalTeam,
|
|
36
39
|
AppleProvisioningRequest,
|
|
37
40
|
AppleRelayResponse,
|
|
41
|
+
AppStoreConnectRequest,
|
|
38
42
|
} from '../core/device-install/apple';
|
|
39
43
|
export {
|
|
40
44
|
AppleRelayWebSocketClient,
|
|
41
45
|
fetchAppleAccountSession,
|
|
42
46
|
openAppleRelayWebSocket,
|
|
47
|
+
proxyAppStoreConnectRequest,
|
|
43
48
|
proxyPhoneTwoFactorCode,
|
|
44
49
|
proxySrpComplete,
|
|
45
50
|
proxySrpInit,
|
|
@@ -58,7 +63,7 @@ export type AppleTeamScopedOptions = AppleRelayClientOptions & {
|
|
|
58
63
|
|
|
59
64
|
export type AppleCertificateKind = 'development' | 'distribution';
|
|
60
65
|
|
|
61
|
-
export type AppleProfileKind = 'development' | 'adhoc';
|
|
66
|
+
export type AppleProfileKind = 'development' | 'adhoc' | 'appstore';
|
|
62
67
|
|
|
63
68
|
export type RequestAppleProvisioningOptions<T = unknown> = AppleRelayClientOptions & {
|
|
64
69
|
request: AppleProvisioningRequest;
|
|
@@ -134,7 +139,9 @@ export type CreateAppleProfileOptions = AppleTeamScopedOptions & {
|
|
|
134
139
|
bundleId: string;
|
|
135
140
|
appIdId: string;
|
|
136
141
|
certificateIds: string[];
|
|
137
|
-
|
|
142
|
+
/** Devices the profile binds. Ignored for App Store profiles, which bind none. */
|
|
143
|
+
deviceIds?: string[];
|
|
144
|
+
/** Profile name. Required for App Store profiles; there is no default. */
|
|
138
145
|
name?: string;
|
|
139
146
|
};
|
|
140
147
|
|
|
@@ -408,8 +415,8 @@ export async function listAppleProfiles({
|
|
|
408
415
|
return requestAppleProvisioning<Array<Record<string, unknown>>>({
|
|
409
416
|
...options,
|
|
410
417
|
request:
|
|
411
|
-
profileKind === 'adhoc' ?
|
|
412
|
-
|
|
418
|
+
profileKind === 'adhoc' ? findAdHocProfilesRequest({ bundleID: bundleId, teamID: teamId })
|
|
419
|
+
: profileKind === 'appstore' ? findAppStoreProfilesRequest({ bundleID: bundleId, teamID: teamId })
|
|
413
420
|
: findDevelopmentProfilesRequest({ bundleID: bundleId, teamID: teamId }),
|
|
414
421
|
label: 'Apple provisioning profile list',
|
|
415
422
|
mapBody: (body) => body?.provisioningProfiles ?? [],
|
|
@@ -422,7 +429,7 @@ export async function createAppleProfile({
|
|
|
422
429
|
bundleId,
|
|
423
430
|
appIdId,
|
|
424
431
|
certificateIds,
|
|
425
|
-
deviceIds,
|
|
432
|
+
deviceIds = [],
|
|
426
433
|
name,
|
|
427
434
|
...options
|
|
428
435
|
}: CreateAppleProfileOptions) {
|
|
@@ -430,26 +437,39 @@ export async function createAppleProfile({
|
|
|
430
437
|
if (!certificateId) {
|
|
431
438
|
throw new Error('At least one certificate ID is required to create an Apple provisioning profile.');
|
|
432
439
|
}
|
|
440
|
+
let request: AppleProvisioningRequest;
|
|
441
|
+
if (profileKind === 'appstore') {
|
|
442
|
+
if (!name) {
|
|
443
|
+
throw new Error('An explicit name is required to create an App Store provisioning profile.');
|
|
444
|
+
}
|
|
445
|
+
request = createAppStoreProfileRequest({
|
|
446
|
+
teamID: teamId,
|
|
447
|
+
appIDID: appIdId,
|
|
448
|
+
certificateID: certificateId,
|
|
449
|
+
name,
|
|
450
|
+
});
|
|
451
|
+
} else if (profileKind === 'adhoc') {
|
|
452
|
+
request = createAdHocProfileRequest({
|
|
453
|
+
bundleID: bundleId,
|
|
454
|
+
teamID: teamId,
|
|
455
|
+
appIDID: appIdId,
|
|
456
|
+
certificateID: certificateId,
|
|
457
|
+
deviceIDs: deviceIds,
|
|
458
|
+
name,
|
|
459
|
+
});
|
|
460
|
+
} else {
|
|
461
|
+
request = createDevelopmentProfileRequest({
|
|
462
|
+
bundleID: bundleId,
|
|
463
|
+
teamID: teamId,
|
|
464
|
+
appIDID: appIdId,
|
|
465
|
+
certificateID: certificateId,
|
|
466
|
+
deviceIDs: deviceIds,
|
|
467
|
+
name,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
433
470
|
return requestAppleProvisioning<Record<string, unknown> | undefined>({
|
|
434
471
|
...options,
|
|
435
|
-
request
|
|
436
|
-
profileKind === 'adhoc' ?
|
|
437
|
-
createAdHocProfileRequest({
|
|
438
|
-
bundleID: bundleId,
|
|
439
|
-
teamID: teamId,
|
|
440
|
-
appIDID: appIdId,
|
|
441
|
-
certificateID: certificateId,
|
|
442
|
-
deviceIDs: deviceIds,
|
|
443
|
-
name,
|
|
444
|
-
})
|
|
445
|
-
: createDevelopmentProfileRequest({
|
|
446
|
-
bundleID: bundleId,
|
|
447
|
-
teamID: teamId,
|
|
448
|
-
appIDID: appIdId,
|
|
449
|
-
certificateID: certificateId,
|
|
450
|
-
deviceIDs: deviceIds,
|
|
451
|
-
name,
|
|
452
|
-
}),
|
|
472
|
+
request,
|
|
453
473
|
label: 'Apple provisioning profile creation',
|
|
454
474
|
mapBody: (body) => body?.provisioningProfile,
|
|
455
475
|
});
|
|
@@ -482,6 +502,321 @@ export async function deleteAppleProfile({ teamId = '', profileId, ...options }:
|
|
|
482
502
|
});
|
|
483
503
|
}
|
|
484
504
|
|
|
505
|
+
/**
|
|
506
|
+
* A JSON:API resource returned by the session-authenticated App Store
|
|
507
|
+
* Connect API. Kept loose on purpose: the endpoint is not a public contract
|
|
508
|
+
* and Apple adds attributes freely.
|
|
509
|
+
*/
|
|
510
|
+
export type AppStoreConnectResource = {
|
|
511
|
+
type?: string;
|
|
512
|
+
id?: string;
|
|
513
|
+
attributes?: Record<string, unknown>;
|
|
514
|
+
relationships?: Record<string, unknown>;
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
type AppStoreConnectEnvelope = {
|
|
518
|
+
data?: AppStoreConnectResource | AppStoreConnectResource[];
|
|
519
|
+
included?: AppStoreConnectResource[];
|
|
520
|
+
errors?: Array<{ status?: string; code?: string; title?: string; detail?: string }>;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
export type SwitchAppStoreConnectProviderOptions = AppleRelayClientOptions & {
|
|
524
|
+
/** The numeric provider ID of the team, from the team list's providerId. */
|
|
525
|
+
providerId: string | number;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Points the App Store Connect session at the given team (provider). Must
|
|
530
|
+
* run before any other App Store Connect call when the account belongs to
|
|
531
|
+
* multiple teams, because the session carries an active provider.
|
|
532
|
+
*/
|
|
533
|
+
export async function switchAppStoreConnectProvider({
|
|
534
|
+
relay,
|
|
535
|
+
providerId,
|
|
536
|
+
}: SwitchAppStoreConnectProviderOptions) {
|
|
537
|
+
const numericProviderId = Number(providerId);
|
|
538
|
+
const response = await proxyAppStoreConnectRequest<Record<string, unknown>>(relay, {
|
|
539
|
+
method: 'POST',
|
|
540
|
+
path: '/olympus/v1/session',
|
|
541
|
+
payload: {
|
|
542
|
+
provider: { providerId: Number.isNaN(numericProviderId) ? providerId : numericProviderId },
|
|
543
|
+
},
|
|
544
|
+
});
|
|
545
|
+
if (response.status < 200 || response.status >= 300) {
|
|
546
|
+
throw new Error(
|
|
547
|
+
`App Store Connect provider switch failed: HTTP ${response.status} ${response.rawBody ?? ''}`.trim(),
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
return response;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Roles Apple accepts on App Store Connect API keys. APP_MANAGER is enough
|
|
555
|
+
* to upload builds and manage TestFlight, which is why it is the default
|
|
556
|
+
* for keys minted by ensureAppStoreConnectApiKeySecret.
|
|
557
|
+
*/
|
|
558
|
+
export type AppStoreConnectApiKeyRole =
|
|
559
|
+
| 'ADMIN'
|
|
560
|
+
| 'APP_MANAGER'
|
|
561
|
+
| 'CUSTOMER_SUPPORT'
|
|
562
|
+
| 'DEVELOPER'
|
|
563
|
+
| 'FINANCE'
|
|
564
|
+
| 'MARKETING'
|
|
565
|
+
| 'SALES';
|
|
566
|
+
|
|
567
|
+
export type ListAppStoreConnectApiKeysOptions = AppleRelayClientOptions;
|
|
568
|
+
|
|
569
|
+
/** Lists the team's App Store Connect API keys. Requires an Admin session. */
|
|
570
|
+
export async function listAppStoreConnectApiKeys({ relay }: ListAppStoreConnectApiKeysOptions) {
|
|
571
|
+
const response = await proxyAppStoreConnectRequest<AppStoreConnectEnvelope>(relay, {
|
|
572
|
+
path: '/iris/v1/apiKeys',
|
|
573
|
+
});
|
|
574
|
+
assertAppStoreConnectResponseOK(response, 'App Store Connect API key list');
|
|
575
|
+
return resourceArray(response.body?.data);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export type CreateAppStoreConnectApiKeyOptions = AppleRelayClientOptions & {
|
|
579
|
+
/** Display name of the key. Required; implementors brand keys themselves. */
|
|
580
|
+
nickname: string;
|
|
581
|
+
roles?: AppStoreConnectApiKeyRole[];
|
|
582
|
+
allAppsVisible?: boolean;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Creates a team App Store Connect API key through the logged-in session,
|
|
587
|
+
* the same way the App Store Connect website does. The session user must
|
|
588
|
+
* be a team Admin. The private key is NOT part of the response; download
|
|
589
|
+
* it once with downloadAppStoreConnectApiKeyPrivateKey.
|
|
590
|
+
*/
|
|
591
|
+
export async function createAppStoreConnectApiKey({
|
|
592
|
+
relay,
|
|
593
|
+
nickname,
|
|
594
|
+
roles = ['APP_MANAGER'],
|
|
595
|
+
allAppsVisible = true,
|
|
596
|
+
}: CreateAppStoreConnectApiKeyOptions) {
|
|
597
|
+
if (!nickname) {
|
|
598
|
+
throw new Error('A nickname is required to create an App Store Connect API key.');
|
|
599
|
+
}
|
|
600
|
+
const response = await proxyAppStoreConnectRequest<AppStoreConnectEnvelope>(relay, {
|
|
601
|
+
method: 'POST',
|
|
602
|
+
path: '/iris/v1/apiKeys',
|
|
603
|
+
payload: {
|
|
604
|
+
data: {
|
|
605
|
+
type: 'apiKeys',
|
|
606
|
+
attributes: {
|
|
607
|
+
nickname,
|
|
608
|
+
allAppsVisible,
|
|
609
|
+
keyType: 'PUBLIC_API',
|
|
610
|
+
roles,
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
});
|
|
615
|
+
assertAppStoreConnectResponseOK(response, 'App Store Connect API key creation');
|
|
616
|
+
const key = singleResource(response.body?.data);
|
|
617
|
+
if (!key?.id) {
|
|
618
|
+
throw new Error('App Store Connect API key creation did not return a key ID.');
|
|
619
|
+
}
|
|
620
|
+
return key;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export type DownloadAppStoreConnectApiKeyOptions = AppleRelayClientOptions & {
|
|
624
|
+
keyId: string;
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
export type DownloadedAppStoreConnectApiKey = {
|
|
628
|
+
/** PEM contents of the .p8 private key. */
|
|
629
|
+
privateKeyPem: string;
|
|
630
|
+
/** Issuer ID for JWTs signed with this key, when Apple returned it. */
|
|
631
|
+
issuerId?: string;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Downloads the private half of an App Store Connect API key. Apple serves
|
|
636
|
+
* it exactly once per key; afterwards the sparse fieldset comes back empty
|
|
637
|
+
* and the key must be revoked and re-minted.
|
|
638
|
+
*/
|
|
639
|
+
export async function downloadAppStoreConnectApiKeyPrivateKey({
|
|
640
|
+
relay,
|
|
641
|
+
keyId,
|
|
642
|
+
}: DownloadAppStoreConnectApiKeyOptions): Promise<DownloadedAppStoreConnectApiKey> {
|
|
643
|
+
const response = await proxyAppStoreConnectRequest<AppStoreConnectEnvelope>(relay, {
|
|
644
|
+
path: `/iris/v1/apiKeys/${encodeURIComponent(keyId)}`,
|
|
645
|
+
query: { 'fields[apiKeys]': 'privateKey', include: 'provider' },
|
|
646
|
+
});
|
|
647
|
+
assertAppStoreConnectResponseOK(response, 'App Store Connect API key download');
|
|
648
|
+
const key = singleResource(response.body?.data);
|
|
649
|
+
const privateKeyPem = stringField(key?.attributes, 'privateKey');
|
|
650
|
+
if (!privateKeyPem) {
|
|
651
|
+
throw new Error(
|
|
652
|
+
`App Store Connect API key ${keyId} returned no private key. Apple serves it only once; ` +
|
|
653
|
+
'revoke the key and create a new one.',
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
const provider = (response.body?.included ?? []).find((item) => item.type === 'providers');
|
|
657
|
+
const issuerId =
|
|
658
|
+
stringField(provider?.attributes, 'publicProviderId') ??
|
|
659
|
+
stringField(key?.attributes, 'issuerId') ??
|
|
660
|
+
provider?.id;
|
|
661
|
+
return { privateKeyPem, issuerId };
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export type FindAppStoreConnectAppOptions = AppleRelayClientOptions & {
|
|
665
|
+
bundleId: string;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
/** Looks up the App Store Connect app record for a bundle ID, if any. */
|
|
669
|
+
export async function findAppStoreConnectApp({ relay, bundleId }: FindAppStoreConnectAppOptions) {
|
|
670
|
+
const response = await proxyAppStoreConnectRequest<AppStoreConnectEnvelope>(relay, {
|
|
671
|
+
path: '/iris/v1/apps',
|
|
672
|
+
query: { 'filter[bundleId]': bundleId },
|
|
673
|
+
});
|
|
674
|
+
assertAppStoreConnectResponseOK(response, 'App Store Connect app lookup');
|
|
675
|
+
return resourceArray(response.body?.data).find(
|
|
676
|
+
(app) => stringField(app.attributes, 'bundleId') === bundleId,
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export type CreateAppStoreConnectAppOptions = AppleRelayClientOptions & {
|
|
681
|
+
bundleId: string;
|
|
682
|
+
/** App name shown on the App Store. Required; there is no default. */
|
|
683
|
+
name: string;
|
|
684
|
+
/** Unique internal identifier. Defaults to the bundle ID. */
|
|
685
|
+
sku?: string;
|
|
686
|
+
/** Primary App Store locale. Defaults to en-US. */
|
|
687
|
+
primaryLocale?: string;
|
|
688
|
+
/** Version string of the first App Store version. Defaults to 1.0. */
|
|
689
|
+
versionString?: string;
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Creates the App Store Connect app record for a bundle ID. Only the
|
|
694
|
+
* session-authenticated API can create app records (the key-authenticated
|
|
695
|
+
* public API cannot), which is why this goes through the relay. The body
|
|
696
|
+
* mirrors what the App Store Connect website and fastlane's produce send.
|
|
697
|
+
*/
|
|
698
|
+
export async function createAppStoreConnectApp({
|
|
699
|
+
relay,
|
|
700
|
+
bundleId,
|
|
701
|
+
name,
|
|
702
|
+
sku,
|
|
703
|
+
primaryLocale = 'en-US',
|
|
704
|
+
versionString = '1.0',
|
|
705
|
+
}: CreateAppStoreConnectAppOptions) {
|
|
706
|
+
if (!name) {
|
|
707
|
+
throw new Error('An app name is required to create an App Store Connect app record.');
|
|
708
|
+
}
|
|
709
|
+
const platform = 'IOS';
|
|
710
|
+
const response = await proxyAppStoreConnectRequest<AppStoreConnectEnvelope>(relay, {
|
|
711
|
+
method: 'POST',
|
|
712
|
+
path: '/iris/v1/apps',
|
|
713
|
+
payload: {
|
|
714
|
+
data: {
|
|
715
|
+
type: 'apps',
|
|
716
|
+
attributes: {
|
|
717
|
+
sku: sku || bundleId,
|
|
718
|
+
primaryLocale,
|
|
719
|
+
bundleId,
|
|
720
|
+
},
|
|
721
|
+
relationships: {
|
|
722
|
+
appStoreVersions: {
|
|
723
|
+
data: [{ type: 'appStoreVersions', id: `\${store-version-${platform}}` }],
|
|
724
|
+
},
|
|
725
|
+
appInfos: {
|
|
726
|
+
data: [{ type: 'appInfos', id: '${new-appInfo-id}' }],
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
included: [
|
|
731
|
+
{
|
|
732
|
+
type: 'appInfos',
|
|
733
|
+
id: '${new-appInfo-id}',
|
|
734
|
+
relationships: {
|
|
735
|
+
appInfoLocalizations: {
|
|
736
|
+
data: [{ type: 'appInfoLocalizations', id: '${new-appInfoLocalization-id}' }],
|
|
737
|
+
},
|
|
738
|
+
},
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
type: 'appInfoLocalizations',
|
|
742
|
+
id: '${new-appInfoLocalization-id}',
|
|
743
|
+
attributes: { locale: primaryLocale, name },
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
type: 'appStoreVersions',
|
|
747
|
+
id: `\${store-version-${platform}}`,
|
|
748
|
+
attributes: { platform, versionString },
|
|
749
|
+
relationships: {
|
|
750
|
+
appStoreVersionLocalizations: {
|
|
751
|
+
data: [
|
|
752
|
+
{ type: 'appStoreVersionLocalizations', id: `\${new-${platform}VersionLocalization-id}` },
|
|
753
|
+
],
|
|
754
|
+
},
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
type: 'appStoreVersionLocalizations',
|
|
759
|
+
id: `\${new-${platform}VersionLocalization-id}`,
|
|
760
|
+
attributes: { locale: primaryLocale },
|
|
761
|
+
},
|
|
762
|
+
],
|
|
763
|
+
},
|
|
764
|
+
});
|
|
765
|
+
assertAppStoreConnectResponseOK(response, 'App Store Connect app creation');
|
|
766
|
+
const app = singleResource(response.body?.data);
|
|
767
|
+
if (!app?.id) {
|
|
768
|
+
throw new Error('App Store Connect app creation did not return an app ID.');
|
|
769
|
+
}
|
|
770
|
+
return app;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export type EnsureAppStoreConnectAppOptions = CreateAppStoreConnectAppOptions;
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Returns the App Store Connect app record for the bundle ID, creating it
|
|
777
|
+
* when it does not exist yet. A first-time IPA upload fails without an app
|
|
778
|
+
* record, so run this before the first publish of a new bundle ID.
|
|
779
|
+
*/
|
|
780
|
+
export async function ensureAppStoreConnectApp(options: EnsureAppStoreConnectAppOptions) {
|
|
781
|
+
const existing = await findAppStoreConnectApp({ relay: options.relay, bundleId: options.bundleId });
|
|
782
|
+
if (existing) {
|
|
783
|
+
return { app: existing, created: false };
|
|
784
|
+
}
|
|
785
|
+
return { app: await createAppStoreConnectApp(options), created: true };
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
export function assertAppStoreConnectResponseOK(
|
|
789
|
+
response: AppleRelayResponse<AppStoreConnectEnvelope>,
|
|
790
|
+
label: string,
|
|
791
|
+
) {
|
|
792
|
+
const errors = response.body?.errors;
|
|
793
|
+
if (errors && errors.length > 0) {
|
|
794
|
+
const detail = errors
|
|
795
|
+
.map((error) => error.detail ?? error.title ?? error.code ?? error.status)
|
|
796
|
+
.filter(Boolean)
|
|
797
|
+
.join('; ');
|
|
798
|
+
throw new Error(`${label} failed: ${detail || `HTTP ${response.status}`}`);
|
|
799
|
+
}
|
|
800
|
+
if (response.status < 200 || response.status >= 300) {
|
|
801
|
+
throw new Error(`${label} failed: HTTP ${response.status} ${response.rawBody ?? ''}`.trim());
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function resourceArray(data: AppStoreConnectResource | AppStoreConnectResource[] | undefined) {
|
|
806
|
+
if (!data) return [];
|
|
807
|
+
return Array.isArray(data) ? data : [data];
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
function singleResource(data: AppStoreConnectResource | AppStoreConnectResource[] | undefined) {
|
|
811
|
+
if (!data) return undefined;
|
|
812
|
+
return Array.isArray(data) ? data[0] : data;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function stringField(record: Record<string, unknown> | undefined, key: string) {
|
|
816
|
+
const value = record?.[key];
|
|
817
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
818
|
+
}
|
|
819
|
+
|
|
485
820
|
export function assertAppleDeveloperPortalResponseOK(
|
|
486
821
|
response: AppleDeveloperPortalResponse | undefined,
|
|
487
822
|
label: string,
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type AppleIDLoginResult,
|
|
6
6
|
type AppleRelayResponse,
|
|
7
7
|
} from './index';
|
|
8
|
+
import { errorMessage } from '../core/errors';
|
|
8
9
|
|
|
9
10
|
export type UseAppleIDLoginOptions = Pick<AppleIDLoginInput, 'registryApiUrl' | 'token' | 'organizationId'>;
|
|
10
11
|
|
|
@@ -128,7 +129,3 @@ export function useAppleIDLogin({
|
|
|
128
129
|
close,
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
|
-
|
|
132
|
-
function errorMessage(error: unknown) {
|
|
133
|
-
return error instanceof Error ? error.message : String(error);
|
|
134
|
-
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
|
|
3
|
+
import forge from 'node-forge';
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
import type { AppleRelayWebSocketClient } from '../core/device-install/apple';
|
|
6
|
+
import {
|
|
7
|
+
APPLE_CERTIFICATE_SECRET_TYPE,
|
|
8
|
+
appleCertificateSecretName,
|
|
9
|
+
ensureAppleCertificateSecret,
|
|
10
|
+
type SigningSecret,
|
|
11
|
+
type SigningSecretMetadata,
|
|
12
|
+
type SigningSecretStore,
|
|
13
|
+
type SigningSecretType,
|
|
14
|
+
} from './index';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A self-signed certificate is enough for exportAppleCertificateP12: the
|
|
18
|
+
* p12 bundling never verifies that the key matches the certificate.
|
|
19
|
+
*/
|
|
20
|
+
function selfSignedCertificateBase64() {
|
|
21
|
+
const keys = forge.pki.rsa.generateKeyPair(1024);
|
|
22
|
+
const cert = forge.pki.createCertificate();
|
|
23
|
+
cert.publicKey = keys.publicKey;
|
|
24
|
+
cert.serialNumber = '01';
|
|
25
|
+
cert.validity.notBefore = new Date();
|
|
26
|
+
cert.validity.notAfter = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
|
27
|
+
const attrs = [{ name: 'commonName', value: 'Apple Development Test' }];
|
|
28
|
+
cert.setSubject(attrs);
|
|
29
|
+
cert.setIssuer(attrs);
|
|
30
|
+
cert.sign(keys.privateKey);
|
|
31
|
+
return forge.util.encode64(forge.asn1.toDer(forge.pki.certificateToAsn1(cert)).getBytes());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function memorySecretStore(options: { failPuts?: () => boolean } = {}) {
|
|
35
|
+
const entries = new Map<string, SigningSecret>();
|
|
36
|
+
const store: SigningSecretStore = {
|
|
37
|
+
async put(type: SigningSecretType, name: string, data: Record<string, string>) {
|
|
38
|
+
if (options.failPuts?.()) {
|
|
39
|
+
throw new Error('secret store unavailable');
|
|
40
|
+
}
|
|
41
|
+
const secret: SigningSecret = { type, name, data, createdAt: new Date().toISOString() };
|
|
42
|
+
entries.set(`${type}:${name}`, secret);
|
|
43
|
+
return secret;
|
|
44
|
+
},
|
|
45
|
+
async get(type: SigningSecretType, name: string) {
|
|
46
|
+
return entries.get(`${type}:${name}`);
|
|
47
|
+
},
|
|
48
|
+
async list() {
|
|
49
|
+
return [...entries.values()].map(({ data: _data, ...metadata }): SigningSecretMetadata => metadata);
|
|
50
|
+
},
|
|
51
|
+
async delete(type: SigningSecretType, name: string) {
|
|
52
|
+
entries.delete(`${type}:${name}`);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return { store, entries };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type PortalState = { mintedCertificateIds: string[]; certificateBase64: string };
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Fakes the relay's provisioning proxy: minting appends to
|
|
62
|
+
* mintedCertificateIds, listing reflects what has been minted so far.
|
|
63
|
+
*/
|
|
64
|
+
function fakePortalRelay(state: PortalState): AppleRelayWebSocketClient {
|
|
65
|
+
return {
|
|
66
|
+
async request(_type: string, payload: unknown) {
|
|
67
|
+
const request = payload as { path: string };
|
|
68
|
+
if (request.path.includes('listCertRequests')) {
|
|
69
|
+
return portalOK({
|
|
70
|
+
certRequests: state.mintedCertificateIds.map((certificateId) => ({ certificateId })),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (request.path.includes('submitCertificateRequest')) {
|
|
74
|
+
const certificateId = `CERT${state.mintedCertificateIds.length + 1}`;
|
|
75
|
+
state.mintedCertificateIds.push(certificateId);
|
|
76
|
+
return portalOK({
|
|
77
|
+
certRequest: {
|
|
78
|
+
certificateId,
|
|
79
|
+
serialNum: '01',
|
|
80
|
+
expirationDateString: '2027-01-01',
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (request.path.includes('downloadCertificateContent')) {
|
|
85
|
+
return { status: 200, statusText: 'OK', rawBodyBase64: state.certificateBase64 };
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`unexpected portal path: ${request.path}`);
|
|
88
|
+
},
|
|
89
|
+
} as unknown as AppleRelayWebSocketClient;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function portalOK(body: Record<string, unknown>) {
|
|
93
|
+
return { status: 200, statusText: 'OK', body: { resultCode: 0, ...body } };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
describe('ensureAppleCertificateSecret', () => {
|
|
97
|
+
const teamId = 'TEAM1';
|
|
98
|
+
const secretName = appleCertificateSecretName(teamId, 'DEVELOPMENT');
|
|
99
|
+
|
|
100
|
+
test('surfaces an actionable error when the store write fails after minting', async () => {
|
|
101
|
+
const state: PortalState = {
|
|
102
|
+
mintedCertificateIds: [],
|
|
103
|
+
certificateBase64: selfSignedCertificateBase64(),
|
|
104
|
+
};
|
|
105
|
+
const broken = memorySecretStore({ failPuts: () => true });
|
|
106
|
+
|
|
107
|
+
await expect(
|
|
108
|
+
ensureAppleCertificateSecret({
|
|
109
|
+
relay: fakePortalRelay(state),
|
|
110
|
+
teamId,
|
|
111
|
+
secretStore: broken.store,
|
|
112
|
+
}),
|
|
113
|
+
).rejects.toThrow(/revoke certificate CERT1/);
|
|
114
|
+
expect(state.mintedCertificateIds).toEqual(['CERT1']);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('mints and stores the certificate with its type in the secret name', async () => {
|
|
118
|
+
const state: PortalState = {
|
|
119
|
+
mintedCertificateIds: [],
|
|
120
|
+
certificateBase64: selfSignedCertificateBase64(),
|
|
121
|
+
};
|
|
122
|
+
const org = memorySecretStore();
|
|
123
|
+
|
|
124
|
+
const result = await ensureAppleCertificateSecret({
|
|
125
|
+
relay: fakePortalRelay(state),
|
|
126
|
+
teamId,
|
|
127
|
+
secretStore: org.store,
|
|
128
|
+
});
|
|
129
|
+
expect(result.created).toBe(true);
|
|
130
|
+
expect(result.certificateId).toBe('CERT1');
|
|
131
|
+
const stored = await org.store.get(APPLE_CERTIFICATE_SECRET_TYPE, secretName);
|
|
132
|
+
expect(stored?.data.certificateID).toBe('CERT1');
|
|
133
|
+
expect(stored?.data.certificateType).toBe('DEVELOPMENT');
|
|
134
|
+
expect(stored?.data.certificateP12Base64).toBeTruthy();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('mints distribution certificates under their own secret name', async () => {
|
|
138
|
+
const state: PortalState = {
|
|
139
|
+
mintedCertificateIds: [],
|
|
140
|
+
certificateBase64: selfSignedCertificateBase64(),
|
|
141
|
+
};
|
|
142
|
+
const org = memorySecretStore();
|
|
143
|
+
|
|
144
|
+
const result = await ensureAppleCertificateSecret({
|
|
145
|
+
relay: fakePortalRelay(state),
|
|
146
|
+
teamId,
|
|
147
|
+
secretStore: org.store,
|
|
148
|
+
certificateKind: 'distribution',
|
|
149
|
+
});
|
|
150
|
+
expect(result.created).toBe(true);
|
|
151
|
+
const stored = await org.store.get(
|
|
152
|
+
APPLE_CERTIFICATE_SECRET_TYPE,
|
|
153
|
+
appleCertificateSecretName(teamId, 'DISTRIBUTION'),
|
|
154
|
+
);
|
|
155
|
+
expect(stored?.data.certificateType).toBe('DISTRIBUTION');
|
|
156
|
+
expect(stored?.data.certificateP12Base64).toBeTruthy();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('reuses the stored certificate when it is still on the team', async () => {
|
|
160
|
+
const state: PortalState = {
|
|
161
|
+
mintedCertificateIds: ['CERT1'],
|
|
162
|
+
certificateBase64: selfSignedCertificateBase64(),
|
|
163
|
+
};
|
|
164
|
+
const org = memorySecretStore();
|
|
165
|
+
await org.store.put(APPLE_CERTIFICATE_SECRET_TYPE, secretName, {
|
|
166
|
+
certificateP12Base64: 'cDEy',
|
|
167
|
+
certificateID: 'CERT1',
|
|
168
|
+
teamID: teamId,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const result = await ensureAppleCertificateSecret({
|
|
172
|
+
relay: fakePortalRelay(state),
|
|
173
|
+
teamId,
|
|
174
|
+
secretStore: org.store,
|
|
175
|
+
});
|
|
176
|
+
expect(result.created).toBe(false);
|
|
177
|
+
expect(result.certificateId).toBe('CERT1');
|
|
178
|
+
expect(state.mintedCertificateIds).toEqual(['CERT1']);
|
|
179
|
+
});
|
|
180
|
+
});
|