@limrun/ui 0.14.0-rc.4 → 0.14.0

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.
Files changed (115) hide show
  1. package/README.md +9 -26
  2. package/dist/components/remote-control.d.ts +36 -0
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +1189 -1089
  6. package/package.json +10 -51
  7. package/src/components/remote-control.tsx +267 -0
  8. package/src/index.ts +1 -1
  9. package/vite.config.ts +0 -9
  10. package/dist/app-store-relay/index.cjs +0 -9
  11. package/dist/app-store-relay/index.d.ts +0 -100
  12. package/dist/app-store-relay/index.js +0 -484
  13. package/dist/app-store-relay/react.cjs +0 -1
  14. package/dist/app-store-relay/react.d.ts +0 -15
  15. package/dist/app-store-relay/react.js +0 -69
  16. package/dist/apple-credentials/index.cjs +0 -1
  17. package/dist/apple-credentials/index.d.ts +0 -59
  18. package/dist/apple-credentials/index.js +0 -227
  19. package/dist/browser-storage-BnO-Ma-e.mjs +0 -219
  20. package/dist/browser-storage-DLxIqZk5.js +0 -1
  21. package/dist/client-D1drDXxE.js +0 -1
  22. package/dist/client-DSuNtWDv.mjs +0 -184
  23. package/dist/core/device-install/apple/client.d.ts +0 -18
  24. package/dist/core/device-install/apple/crypto.d.ts +0 -20
  25. package/dist/core/device-install/apple/gsa-srp.d.ts +0 -26
  26. package/dist/core/device-install/apple/index.d.ts +0 -5
  27. package/dist/core/device-install/apple/provisioning.d.ts +0 -212
  28. package/dist/core/device-install/apple/relay.d.ts +0 -40
  29. package/dist/core/device-install/index.d.ts +0 -4
  30. package/dist/core/device-install/operations/index.d.ts +0 -6
  31. package/dist/core/device-install/operations/limbuild-client.d.ts +0 -43
  32. package/dist/core/device-install/operations/operations.d.ts +0 -47
  33. package/dist/core/device-install/operations/relay-client.d.ts +0 -26
  34. package/dist/core/device-install/operations/relay-protocol.d.ts +0 -27
  35. package/dist/core/device-install/operations/usbmux.d.ts +0 -32
  36. package/dist/core/device-install/operations/webusb.d.ts +0 -21
  37. package/dist/core/device-install/storage/browser-storage.d.ts +0 -56
  38. package/dist/core/device-install/storage/index.d.ts +0 -2
  39. package/dist/core/device-install/storage/secret-store.d.ts +0 -101
  40. package/dist/core/device-install/types.d.ts +0 -57
  41. package/dist/core/errors.d.ts +0 -1
  42. package/dist/core/play-publish/google.d.ts +0 -13
  43. package/dist/core/play-publish/publish.d.ts +0 -34
  44. package/dist/device-build/index.cjs +0 -1
  45. package/dist/device-build/index.d.ts +0 -4
  46. package/dist/device-build/index.js +0 -85
  47. package/dist/device-build/react.cjs +0 -1
  48. package/dist/device-build/react.d.ts +0 -21
  49. package/dist/device-build/react.js +0 -68
  50. package/dist/device-build/signing.d.ts +0 -20
  51. package/dist/device-install/demo/demo.d.ts +0 -0
  52. package/dist/device-install/index.cjs +0 -1
  53. package/dist/device-install/index.d.ts +0 -18
  54. package/dist/device-install/index.js +0 -591
  55. package/dist/device-install/react.cjs +0 -1
  56. package/dist/device-install/react.d.ts +0 -24
  57. package/dist/device-install/react.js +0 -105
  58. package/dist/errors-BSkqS7U-.js +0 -1
  59. package/dist/errors-gy8yQJos.mjs +0 -6
  60. package/dist/gsa-srp-Bme3JLEi.mjs +0 -266
  61. package/dist/gsa-srp-CCIfUz7Y.js +0 -1
  62. package/dist/index-ChhtuQ7e.js +0 -22
  63. package/dist/index-YDu8K9a4.mjs +0 -11279
  64. package/dist/limbuild-client-BagK_FWE.mjs +0 -83
  65. package/dist/limbuild-client-CVDwq54z.js +0 -1
  66. package/dist/play-publish/index.cjs +0 -1
  67. package/dist/play-publish/index.d.ts +0 -2
  68. package/dist/play-publish/index.js +0 -109
  69. package/dist/play-publish/react.cjs +0 -1
  70. package/dist/play-publish/react.d.ts +0 -31
  71. package/dist/play-publish/react.js +0 -91
  72. package/dist/provisioning-B_DefBEp.mjs +0 -239
  73. package/dist/provisioning-BlQMccX_.js +0 -1
  74. package/src/app-store-relay/index.test.ts +0 -60
  75. package/src/app-store-relay/index.ts +0 -511
  76. package/src/app-store-relay/react.ts +0 -131
  77. package/src/apple-credentials/index.test.ts +0 -158
  78. package/src/apple-credentials/index.ts +0 -241
  79. package/src/core/device-install/apple/client.ts +0 -143
  80. package/src/core/device-install/apple/crypto.ts +0 -205
  81. package/src/core/device-install/apple/gsa-srp.ts +0 -123
  82. package/src/core/device-install/apple/index.ts +0 -5
  83. package/src/core/device-install/apple/provisioning.test.ts +0 -84
  84. package/src/core/device-install/apple/provisioning.ts +0 -380
  85. package/src/core/device-install/apple/relay.ts +0 -182
  86. package/src/core/device-install/index.ts +0 -4
  87. package/src/core/device-install/operations/index.ts +0 -6
  88. package/src/core/device-install/operations/limbuild-client.ts +0 -144
  89. package/src/core/device-install/operations/operations.ts +0 -234
  90. package/src/core/device-install/operations/relay-client.ts +0 -286
  91. package/src/core/device-install/operations/relay-protocol.ts +0 -71
  92. package/src/core/device-install/operations/usbmux.ts +0 -270
  93. package/src/core/device-install/operations/webusb-dom.d.ts +0 -54
  94. package/src/core/device-install/operations/webusb.ts +0 -110
  95. package/src/core/device-install/storage/browser-storage.test.ts +0 -65
  96. package/src/core/device-install/storage/browser-storage.ts +0 -325
  97. package/src/core/device-install/storage/index.ts +0 -2
  98. package/src/core/device-install/storage/secret-store.ts +0 -298
  99. package/src/core/device-install/types.ts +0 -69
  100. package/src/core/errors.ts +0 -3
  101. package/src/core/play-publish/google.ts +0 -113
  102. package/src/core/play-publish/publish.test.ts +0 -68
  103. package/src/core/play-publish/publish.ts +0 -89
  104. package/src/device-build/index.ts +0 -42
  105. package/src/device-build/react.ts +0 -130
  106. package/src/device-build/signing.ts +0 -94
  107. package/src/device-install/README.md +0 -423
  108. package/src/device-install/demo/demo.css +0 -493
  109. package/src/device-install/demo/demo.tsx +0 -1061
  110. package/src/device-install/demo/index.html +0 -12
  111. package/src/device-install/index.ts +0 -50
  112. package/src/device-install/react.ts +0 -195
  113. package/src/play-publish/README.md +0 -66
  114. package/src/play-publish/index.ts +0 -12
  115. package/src/play-publish/react.ts +0 -208
@@ -1,511 +0,0 @@
1
- import {
2
- createAdHocProfileRequest,
3
- createBundleIDRequest,
4
- createDevelopmentProfileRequest,
5
- downloadCertificateRequest,
6
- downloadDistributionCertificateRequest,
7
- downloadProfileRequest,
8
- findAdHocProfilesRequest,
9
- findBundleIDRequest,
10
- findDevelopmentCertificatesRequest,
11
- findDevelopmentProfilesRequest,
12
- findDeviceRequest,
13
- findDistributionCertificatesRequest,
14
- listTeamsRequest,
15
- proxyProvisioningRequest,
16
- registerDeviceRequest,
17
- submitDevelopmentCSRRequest,
18
- submitDistributionCSRRequest,
19
- type AppleDeveloperPortalAppID,
20
- type AppleDeveloperPortalDevice,
21
- type AppleDeveloperPortalResponse,
22
- type AppleDeveloperPortalTeam,
23
- type AppleProvisioningRequest,
24
- type AppleRelayResponse,
25
- type AppleRelayWebSocketClient,
26
- } from '../core/device-install/apple';
27
-
28
- export * from '../core/device-install/apple/client';
29
- export * from '../core/device-install/apple/crypto';
30
- export * from '../core/device-install/apple/gsa-srp';
31
- export type {
32
- AppleDeveloperPortalAppID,
33
- AppleDeveloperPortalDevice,
34
- AppleDeveloperPortalResponse,
35
- AppleDeveloperPortalTeam,
36
- AppleProvisioningRequest,
37
- AppleRelayResponse,
38
- } from '../core/device-install/apple';
39
- export {
40
- AppleRelayWebSocketClient,
41
- fetchAppleAccountSession,
42
- openAppleRelayWebSocket,
43
- proxyPhoneTwoFactorCode,
44
- proxySrpComplete,
45
- proxySrpInit,
46
- proxyTwoFactorCode,
47
- triggerPhoneTwoFactor,
48
- triggerTrustedDeviceTwoFactor,
49
- } from '../core/device-install/apple';
50
-
51
- export type AppleRelayClientOptions = {
52
- relay: AppleRelayWebSocketClient;
53
- };
54
-
55
- export type AppleTeamScopedOptions = AppleRelayClientOptions & {
56
- teamId?: string;
57
- };
58
-
59
- export type AppleCertificateKind = 'development' | 'distribution';
60
-
61
- export type AppleProfileKind = 'development' | 'adhoc';
62
-
63
- export type RequestAppleProvisioningOptions<T = unknown> = AppleRelayClientOptions & {
64
- request: AppleProvisioningRequest;
65
- label?: string;
66
- validatePortalResponse?: boolean;
67
- mapBody?: (body: AppleDeveloperPortalResponse | undefined, response: AppleRelayResponse<T>) => T;
68
- };
69
-
70
- export type MappedAppleProvisioningOptions<T> = RequestAppleProvisioningOptions<T> & {
71
- mapBody: (body: AppleDeveloperPortalResponse | undefined, response: AppleRelayResponse<T>) => T;
72
- };
73
-
74
- export type ListAppleCertificatesOptions = AppleTeamScopedOptions & {
75
- certificateKind?: AppleCertificateKind;
76
- };
77
-
78
- export type CreateAppleCertificateOptions = AppleTeamScopedOptions & {
79
- certificateKind?: AppleCertificateKind;
80
- csrPEM: string;
81
- };
82
-
83
- export type DownloadAppleCertificateOptions = AppleTeamScopedOptions & {
84
- certificateKind?: AppleCertificateKind;
85
- certificateId: string;
86
- };
87
-
88
- export type DeleteAppleCertificateOptions = DownloadAppleCertificateOptions;
89
-
90
- export type ListAppleBundleIDsOptions = AppleTeamScopedOptions & {
91
- search?: string;
92
- };
93
-
94
- export type CreateAppleBundleIDOptions = AppleTeamScopedOptions & {
95
- bundleId: string;
96
- name?: string;
97
- };
98
-
99
- export type UpdateAppleBundleIDOptions = AppleTeamScopedOptions & {
100
- appIdId: string;
101
- bundleId?: string;
102
- name?: string;
103
- };
104
-
105
- export type DeleteAppleBundleIDOptions = AppleTeamScopedOptions & {
106
- appIdId: string;
107
- };
108
-
109
- export type ListAppleDevicesOptions = AppleTeamScopedOptions & {
110
- deviceUDID?: string;
111
- };
112
-
113
- export type RegisterAppleDeviceOptions = AppleTeamScopedOptions & {
114
- deviceUDID: string;
115
- name?: string;
116
- };
117
-
118
- export type UpdateAppleDeviceOptions = AppleTeamScopedOptions & {
119
- deviceId: string;
120
- name?: string;
121
- };
122
-
123
- export type DeleteAppleDeviceOptions = AppleTeamScopedOptions & {
124
- deviceId: string;
125
- };
126
-
127
- export type ListAppleProfilesOptions = AppleTeamScopedOptions & {
128
- profileKind?: AppleProfileKind;
129
- bundleId?: string;
130
- };
131
-
132
- export type CreateAppleProfileOptions = AppleTeamScopedOptions & {
133
- profileKind?: AppleProfileKind;
134
- bundleId: string;
135
- appIdId: string;
136
- certificateIds: string[];
137
- deviceIds: string[];
138
- name?: string;
139
- };
140
-
141
- export type DownloadAppleProfileOptions = AppleTeamScopedOptions & {
142
- profileId: string;
143
- };
144
-
145
- export type DeleteAppleProfileOptions = DownloadAppleProfileOptions;
146
-
147
- export function requestAppleProvisioning<T>(options: MappedAppleProvisioningOptions<T>): Promise<T>;
148
- export function requestAppleProvisioning<T = AppleDeveloperPortalResponse>(
149
- options: RequestAppleProvisioningOptions<T>,
150
- ): Promise<AppleRelayResponse<T>>;
151
- export async function requestAppleProvisioning<T = AppleDeveloperPortalResponse>({
152
- relay,
153
- request,
154
- label = 'Apple Developer Portal request',
155
- validatePortalResponse = true,
156
- mapBody,
157
- }: RequestAppleProvisioningOptions<T>) {
158
- const response = await proxyProvisioningRequest<T>(relay, request);
159
- if (validatePortalResponse) {
160
- assertAppleDeveloperPortalResponseOK(response.body as AppleDeveloperPortalResponse | undefined, label);
161
- }
162
- return mapBody ? mapBody(response.body as AppleDeveloperPortalResponse | undefined, response) : response;
163
- }
164
-
165
- export async function listAppleTeams(options: AppleRelayClientOptions) {
166
- return requestAppleProvisioning<AppleDeveloperPortalTeam[]>({
167
- ...options,
168
- request: listTeamsRequest(),
169
- label: 'Apple Developer team list',
170
- mapBody: (body) =>
171
- uniqueAppleTeams([
172
- ...(body?.teams ?? []),
173
- ...(body?.availableProviders ?? []),
174
- ...(body?.provider ? [body.provider] : []),
175
- ]),
176
- });
177
- }
178
-
179
- export async function listAppleCertificates({
180
- certificateKind = 'development',
181
- teamId = '',
182
- ...options
183
- }: ListAppleCertificatesOptions) {
184
- return requestAppleProvisioning<Array<Record<string, unknown>>>({
185
- ...options,
186
- request:
187
- certificateKind === 'distribution' ?
188
- findDistributionCertificatesRequest(teamId)
189
- : findDevelopmentCertificatesRequest(teamId),
190
- label: 'Apple Developer certificate list',
191
- mapBody: (body) => body?.certRequests ?? [],
192
- });
193
- }
194
-
195
- export async function createAppleCertificate({
196
- certificateKind = 'development',
197
- teamId = '',
198
- csrPEM,
199
- ...options
200
- }: CreateAppleCertificateOptions) {
201
- return requestAppleProvisioning<Record<string, unknown> | undefined>({
202
- ...options,
203
- request:
204
- certificateKind === 'distribution' ?
205
- submitDistributionCSRRequest({ csrPEM, teamID: teamId })
206
- : submitDevelopmentCSRRequest({ csrPEM, teamID: teamId }),
207
- label:
208
- certificateKind === 'distribution' ?
209
- 'Apple Distribution certificate creation'
210
- : 'Apple Development certificate creation',
211
- mapBody: (body) => body?.certRequest,
212
- });
213
- }
214
-
215
- export async function downloadAppleCertificate({
216
- certificateKind = 'development',
217
- certificateId,
218
- teamId = '',
219
- ...options
220
- }: DownloadAppleCertificateOptions) {
221
- return requestAppleProvisioning<AppleRelayResponse>({
222
- ...options,
223
- request:
224
- certificateKind === 'distribution' ?
225
- downloadDistributionCertificateRequest(certificateId, teamId)
226
- : downloadCertificateRequest(certificateId, teamId),
227
- label: 'Apple certificate download',
228
- validatePortalResponse: false,
229
- mapBody: (_body, response) => response,
230
- });
231
- }
232
-
233
- export async function deleteAppleCertificate({
234
- certificateKind = 'development',
235
- certificateId,
236
- teamId = '',
237
- ...options
238
- }: DeleteAppleCertificateOptions) {
239
- return requestAppleProvisioning<AppleDeveloperPortalResponse | undefined>({
240
- ...options,
241
- request: {
242
- method: 'POST',
243
- path: '/account/ios/certificate/revokeCertificate.action',
244
- payload: {
245
- teamId,
246
- certificateId,
247
- type: certificateKind === 'distribution' ? 'WXV89964HE' : '83Q87W3TGH',
248
- },
249
- },
250
- label: 'Apple certificate deletion',
251
- mapBody: (body) => body,
252
- });
253
- }
254
-
255
- export async function listAppleBundleIDs({
256
- teamId = '',
257
- search = '',
258
- ...options
259
- }: ListAppleBundleIDsOptions) {
260
- const query = search.trim().toLowerCase();
261
- return requestAppleProvisioning<AppleDeveloperPortalAppID[]>({
262
- ...options,
263
- request: findBundleIDRequest({ bundleID: search, teamID: teamId }),
264
- label: 'Apple bundle ID list',
265
- // Apple's listAppIds.action returns the full paginated list and does not
266
- // honor a server-side search filter, so apply the `search` filter here.
267
- mapBody: (body) => {
268
- const appIds = body?.appIds ?? [];
269
- if (!query) return appIds;
270
- return appIds.filter((appId) =>
271
- [appId.identifier, appId.bundleId, appId.name].some(
272
- (value) => typeof value === 'string' && value.toLowerCase().includes(query),
273
- ),
274
- );
275
- },
276
- });
277
- }
278
-
279
- export async function createAppleBundleID({
280
- teamId = '',
281
- bundleId,
282
- name,
283
- ...options
284
- }: CreateAppleBundleIDOptions) {
285
- return requestAppleProvisioning<Record<string, unknown> | undefined>({
286
- ...options,
287
- request: createBundleIDRequest({ bundleID: bundleId, teamID: teamId, name }),
288
- label: 'Apple bundle ID creation',
289
- mapBody: (body) => body?.appId,
290
- });
291
- }
292
-
293
- export async function updateAppleBundleID({
294
- teamId = '',
295
- appIdId,
296
- bundleId,
297
- name,
298
- ...options
299
- }: UpdateAppleBundleIDOptions) {
300
- return requestAppleProvisioning<Record<string, unknown> | undefined>({
301
- ...options,
302
- request: {
303
- method: 'POST',
304
- path: '/account/ios/identifiers/updateAppId.action',
305
- payload: {
306
- teamId,
307
- appIdId,
308
- ...(bundleId ? { identifier: bundleId } : {}),
309
- ...(name ? { name } : {}),
310
- },
311
- },
312
- label: 'Apple bundle ID update',
313
- mapBody: (body) => body?.appId,
314
- });
315
- }
316
-
317
- export async function deleteAppleBundleID({ teamId = '', appIdId, ...options }: DeleteAppleBundleIDOptions) {
318
- return requestAppleProvisioning<AppleDeveloperPortalResponse | undefined>({
319
- ...options,
320
- request: {
321
- method: 'POST',
322
- path: '/account/ios/identifiers/deleteAppId.action',
323
- payload: { teamId, appIdId },
324
- },
325
- label: 'Apple bundle ID deletion',
326
- mapBody: (body) => body,
327
- });
328
- }
329
-
330
- export async function listAppleDevices({
331
- teamId = '',
332
- deviceUDID = '',
333
- ...options
334
- }: ListAppleDevicesOptions) {
335
- const wantedUDID = normalizeAppleUDID(deviceUDID);
336
- return requestAppleProvisioning<AppleDeveloperPortalDevice[]>({
337
- ...options,
338
- request: findDeviceRequest({ deviceUDID, teamID: teamId }),
339
- label: 'Apple device list',
340
- // Apple's listDevices.action returns the full paginated list and does not
341
- // honor a server-side UDID filter, so apply the `deviceUDID` filter here.
342
- mapBody: (body) => {
343
- const devices = body?.devices ?? [];
344
- if (!wantedUDID) return devices;
345
- return devices.filter((device) => normalizeAppleUDID(device.deviceNumber) === wantedUDID);
346
- },
347
- });
348
- }
349
-
350
- function normalizeAppleUDID(udid?: string) {
351
- return (udid ?? '')
352
- .replace(/-/g, '')
353
- .replace(/[^a-fA-F0-9]/g, '')
354
- .toUpperCase();
355
- }
356
-
357
- export async function registerAppleDevice({
358
- teamId = '',
359
- deviceUDID,
360
- name,
361
- ...options
362
- }: RegisterAppleDeviceOptions) {
363
- return requestAppleProvisioning<Record<string, unknown> | undefined>({
364
- ...options,
365
- request: registerDeviceRequest({ deviceUDID, teamID: teamId, name }),
366
- label: 'Apple device registration',
367
- mapBody: (body) => body?.device,
368
- });
369
- }
370
-
371
- export async function updateAppleDevice({
372
- teamId = '',
373
- deviceId,
374
- name,
375
- ...options
376
- }: UpdateAppleDeviceOptions) {
377
- return requestAppleProvisioning<Record<string, unknown> | undefined>({
378
- ...options,
379
- request: {
380
- method: 'POST',
381
- path: '/account/ios/device/updateDevice.action',
382
- payload: { teamId, deviceId, ...(name ? { name } : {}) },
383
- },
384
- label: 'Apple device update',
385
- mapBody: (body) => body?.device,
386
- });
387
- }
388
-
389
- export async function deleteAppleDevice({ teamId = '', deviceId, ...options }: DeleteAppleDeviceOptions) {
390
- return requestAppleProvisioning<AppleDeveloperPortalResponse | undefined>({
391
- ...options,
392
- request: {
393
- method: 'POST',
394
- path: '/account/ios/device/deleteDevice.action',
395
- payload: { teamId, deviceId },
396
- },
397
- label: 'Apple device deletion',
398
- mapBody: (body) => body,
399
- });
400
- }
401
-
402
- export async function listAppleProfiles({
403
- profileKind = 'development',
404
- teamId = '',
405
- bundleId = '',
406
- ...options
407
- }: ListAppleProfilesOptions) {
408
- return requestAppleProvisioning<Array<Record<string, unknown>>>({
409
- ...options,
410
- request:
411
- profileKind === 'adhoc' ?
412
- findAdHocProfilesRequest({ bundleID: bundleId, teamID: teamId })
413
- : findDevelopmentProfilesRequest({ bundleID: bundleId, teamID: teamId }),
414
- label: 'Apple provisioning profile list',
415
- mapBody: (body) => body?.provisioningProfiles ?? [],
416
- });
417
- }
418
-
419
- export async function createAppleProfile({
420
- profileKind = 'development',
421
- teamId = '',
422
- bundleId,
423
- appIdId,
424
- certificateIds,
425
- deviceIds,
426
- name,
427
- ...options
428
- }: CreateAppleProfileOptions) {
429
- const [certificateId] = certificateIds;
430
- if (!certificateId) {
431
- throw new Error('At least one certificate ID is required to create an Apple provisioning profile.');
432
- }
433
- return requestAppleProvisioning<Record<string, unknown> | undefined>({
434
- ...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
- }),
453
- label: 'Apple provisioning profile creation',
454
- mapBody: (body) => body?.provisioningProfile,
455
- });
456
- }
457
-
458
- export async function downloadAppleProfile({
459
- teamId = '',
460
- profileId,
461
- ...options
462
- }: DownloadAppleProfileOptions) {
463
- return requestAppleProvisioning<AppleRelayResponse>({
464
- ...options,
465
- request: downloadProfileRequest(profileId, teamId),
466
- label: 'Apple provisioning profile download',
467
- validatePortalResponse: false,
468
- mapBody: (_body, response) => response,
469
- });
470
- }
471
-
472
- export async function deleteAppleProfile({ teamId = '', profileId, ...options }: DeleteAppleProfileOptions) {
473
- return requestAppleProvisioning<AppleDeveloperPortalResponse | undefined>({
474
- ...options,
475
- request: {
476
- method: 'POST',
477
- path: '/account/ios/profile/deleteProvisioningProfile.action',
478
- payload: { teamId, provisioningProfileId: profileId },
479
- },
480
- label: 'Apple provisioning profile deletion',
481
- mapBody: (body) => body,
482
- });
483
- }
484
-
485
- export function assertAppleDeveloperPortalResponseOK(
486
- response: AppleDeveloperPortalResponse | undefined,
487
- label: string,
488
- ) {
489
- if (!response) {
490
- throw new Error(`${label} returned an empty response.`);
491
- }
492
- if (response.resultCode !== undefined && response.resultCode !== 0) {
493
- throw new Error(
494
- `${label} failed: ${response.userString ?? response.resultString ?? response.resultCode}`,
495
- );
496
- }
497
- }
498
-
499
- function uniqueAppleTeams(teams: AppleDeveloperPortalTeam[]) {
500
- const seen = new Set<string>();
501
- const result: AppleDeveloperPortalTeam[] = [];
502
- for (const team of teams) {
503
- const key = String(
504
- team.teamId ?? team.providerId ?? team.publicProviderId ?? team.name ?? JSON.stringify(team),
505
- );
506
- if (seen.has(key)) continue;
507
- seen.add(key);
508
- result.push(team);
509
- }
510
- return result;
511
- }
@@ -1,131 +0,0 @@
1
- import { useCallback, useEffect, useRef, useState } from 'react';
2
- import {
3
- startBrowserOwnedAppleIDLogin,
4
- type AppleIDLoginInput,
5
- type AppleIDLoginResult,
6
- type AppleRelayResponse,
7
- } from './index';
8
- import { errorMessage } from '../core/errors';
9
-
10
- export type UseAppleIDLoginOptions = Pick<AppleIDLoginInput, 'registryApiUrl' | 'token' | 'organizationId'>;
11
-
12
- export type AppleIDLoginStatus =
13
- | 'idle'
14
- | 'authenticating'
15
- | 'two-factor-required'
16
- | 'authenticated'
17
- | 'error';
18
-
19
- export type UseAppleIDLoginResult = {
20
- status: AppleIDLoginStatus;
21
- session?: AppleIDLoginResult;
22
- completeResponse?: AppleRelayResponse;
23
- twoFactorChallengeResponse?: AppleRelayResponse;
24
- error?: string;
25
- startLogin: (
26
- input: Pick<AppleIDLoginInput, 'accountName' | 'password'>,
27
- ) => Promise<AppleIDLoginResult | undefined>;
28
- submitTwoFactorCode: (code: string) => Promise<AppleRelayResponse | undefined>;
29
- finalize: () => Promise<AppleRelayResponse | undefined>;
30
- close: () => Promise<void>;
31
- };
32
-
33
- export function useAppleIDLogin({
34
- registryApiUrl,
35
- token,
36
- organizationId,
37
- }: UseAppleIDLoginOptions): UseAppleIDLoginResult {
38
- const [status, setStatus] = useState<AppleIDLoginStatus>('idle');
39
- const [session, setSession] = useState<AppleIDLoginResult | undefined>();
40
- const [completeResponse, setCompleteResponse] = useState<AppleRelayResponse | undefined>();
41
- const [twoFactorChallengeResponse, setTwoFactorChallengeResponse] = useState<
42
- AppleRelayResponse | undefined
43
- >();
44
- const [error, setError] = useState<string | undefined>();
45
- const sessionRef = useRef<AppleIDLoginResult | undefined>(undefined);
46
-
47
- const close = useCallback(async () => {
48
- await sessionRef.current?.close().catch(() => undefined);
49
- sessionRef.current = undefined;
50
- setSession(undefined);
51
- setCompleteResponse(undefined);
52
- setTwoFactorChallengeResponse(undefined);
53
- setError(undefined);
54
- setStatus('idle');
55
- }, []);
56
-
57
- useEffect(() => {
58
- return () => {
59
- void sessionRef.current?.close();
60
- sessionRef.current = undefined;
61
- };
62
- }, []);
63
-
64
- const startLogin = useCallback(
65
- async ({ accountName, password }: Pick<AppleIDLoginInput, 'accountName' | 'password'>) => {
66
- setStatus('authenticating');
67
- setError(undefined);
68
- await sessionRef.current?.close().catch(() => undefined);
69
- try {
70
- const next = await startBrowserOwnedAppleIDLogin({
71
- registryApiUrl,
72
- token,
73
- organizationId,
74
- accountName,
75
- password,
76
- });
77
- sessionRef.current = next;
78
- setSession(next);
79
- setCompleteResponse(next.completeResponse);
80
- setTwoFactorChallengeResponse(next.twoFactorChallengeResponse);
81
- setStatus(next.requiresTwoFactor ? 'two-factor-required' : 'authenticated');
82
- return next;
83
- } catch (caught) {
84
- setSession(undefined);
85
- sessionRef.current = undefined;
86
- setError(errorMessage(caught));
87
- setStatus('error');
88
- return undefined;
89
- }
90
- },
91
- [registryApiUrl, organizationId, token],
92
- );
93
-
94
- const submitTwoFactorCode = useCallback(async (code: string) => {
95
- const current = sessionRef.current;
96
- if (!current) {
97
- throw new Error('Start Apple ID login before submitting a two-factor code.');
98
- }
99
- setStatus('authenticating');
100
- setError(undefined);
101
- try {
102
- const response = await current.finishTwoFactor(code);
103
- setStatus('authenticated');
104
- return response;
105
- } catch (caught) {
106
- setError(errorMessage(caught));
107
- setStatus('error');
108
- return undefined;
109
- }
110
- }, []);
111
-
112
- const finalize = useCallback(async () => {
113
- const current = sessionRef.current;
114
- if (!current) {
115
- throw new Error('Start Apple ID login before finalizing the Apple session.');
116
- }
117
- return current.finalize();
118
- }, []);
119
-
120
- return {
121
- status,
122
- session,
123
- completeResponse,
124
- twoFactorChallengeResponse,
125
- error,
126
- startLogin,
127
- submitTwoFactorCode,
128
- finalize,
129
- close,
130
- };
131
- }