@sitepong/fastnode 0.2.2 → 0.3.1

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 (126) hide show
  1. package/README.md +64 -1
  2. package/dist/actions/index.cjs +928 -54
  3. package/dist/actions/index.cjs.map +1 -1
  4. package/dist/actions/index.mjs +930 -56
  5. package/dist/actions/index.mjs.map +1 -1
  6. package/dist/apple-session-jUzBrql5.d.cts +122 -0
  7. package/dist/apple-session-jUzBrql5.d.ts +122 -0
  8. package/dist/cert/index.cjs +782 -736
  9. package/dist/cert/index.cjs.map +1 -1
  10. package/dist/cert/index.d.cts +5 -4
  11. package/dist/cert/index.d.ts +5 -4
  12. package/dist/cert/index.mjs +782 -737
  13. package/dist/cert/index.mjs.map +1 -1
  14. package/dist/{cert-Ddl7FpFT.d.ts → cert-ClacRx9y.d.ts} +2 -2
  15. package/dist/{cert-FehieKeb.d.cts → cert-DffLKURp.d.cts} +2 -2
  16. package/dist/cli/index.cjs +1408 -60
  17. package/dist/cli/index.cjs.map +1 -1
  18. package/dist/cli/index.d.cts +3 -2
  19. package/dist/cli/index.d.ts +3 -2
  20. package/dist/cli/index.mjs +1410 -62
  21. package/dist/cli/index.mjs.map +1 -1
  22. package/dist/client/index.cjs +519 -31
  23. package/dist/client/index.cjs.map +1 -1
  24. package/dist/client/index.d.cts +3 -2
  25. package/dist/client/index.d.ts +3 -2
  26. package/dist/client/index.mjs +514 -32
  27. package/dist/client/index.mjs.map +1 -1
  28. package/dist/deliver/index.cjs +334 -13
  29. package/dist/deliver/index.cjs.map +1 -1
  30. package/dist/deliver/index.d.cts +4 -3
  31. package/dist/deliver/index.d.ts +4 -3
  32. package/dist/deliver/index.mjs +330 -15
  33. package/dist/deliver/index.mjs.map +1 -1
  34. package/dist/{enums-B609j2rb.d.cts → enums-yXNVh3UI.d.cts} +8 -1
  35. package/dist/{enums-B609j2rb.d.ts → enums-yXNVh3UI.d.ts} +8 -1
  36. package/dist/gradle/index.cjs +222 -0
  37. package/dist/gradle/index.cjs.map +1 -0
  38. package/dist/gradle/index.d.cts +1 -0
  39. package/dist/gradle/index.d.ts +1 -0
  40. package/dist/gradle/index.mjs +217 -0
  41. package/dist/gradle/index.mjs.map +1 -0
  42. package/dist/gym/index.d.cts +2 -2
  43. package/dist/gym/index.d.ts +2 -2
  44. package/dist/index-8djTPW8O.d.ts +104 -0
  45. package/dist/{index-Bk1Gd-qE.d.cts → index-925_Ov7X.d.cts} +2 -2
  46. package/dist/{index-DrUpRXRG.d.cts → index-B6-MJpO4.d.cts} +1 -1
  47. package/dist/index-BGhV0gS-.d.ts +65 -0
  48. package/dist/{index-OelCoOth.d.cts → index-BbVQzSV1.d.cts} +18 -4
  49. package/dist/index-BhGaVlK1.d.cts +201 -0
  50. package/dist/{index-CtPyeMLH.d.ts → index-C-EEYXSE.d.ts} +18 -4
  51. package/dist/{index-CNHf7I4v.d.cts → index-C18cijCd.d.ts} +32 -3
  52. package/dist/{index-DFni8oZt.d.ts → index-CBM5XZKC.d.ts} +2 -2
  53. package/dist/index-CXJlvmB4.d.cts +63 -0
  54. package/dist/index-CXJlvmB4.d.ts +63 -0
  55. package/dist/{index-BKUapQP2.d.cts → index-CemR3UI9.d.ts} +356 -124
  56. package/dist/{index-DI1ZHr-3.d.ts → index-CmcFPn_G.d.cts} +9 -1
  57. package/dist/{index-CCtYhPN9.d.ts → index-CpGV1f0L.d.cts} +356 -124
  58. package/dist/{index-B8FOfxOw.d.ts → index-D9YQQ3FM.d.ts} +2 -2
  59. package/dist/index-DFstwgGK.d.cts +65 -0
  60. package/dist/{index-YcKz4aRS.d.ts → index-Dkf5sH1E.d.ts} +1 -1
  61. package/dist/index-DnHQ2uT2.d.cts +104 -0
  62. package/dist/index-Dv-Mek07.d.cts +84 -0
  63. package/dist/index-Dv-Mek07.d.ts +84 -0
  64. package/dist/{index-BICa8odo.d.cts → index-N6eV5yym.d.ts} +9 -1
  65. package/dist/{index-oVyLLIEK.d.cts → index-O3EMrd5s.d.cts} +3 -3
  66. package/dist/{index-DZoPGCbE.d.ts → index-Ol0RtbQA.d.ts} +3 -3
  67. package/dist/{index-CplRWSUc.d.ts → index-_24DRp3a.d.cts} +32 -3
  68. package/dist/{index-BZWmOTWE.d.cts → index-isT08RuY.d.cts} +2 -2
  69. package/dist/{index-DImN9PWc.d.ts → index-mEEB7An6.d.ts} +1 -1
  70. package/dist/{index-D13sn8DO.d.cts → index-on573dnO.d.cts} +1 -1
  71. package/dist/index-s2PigtDM.d.ts +201 -0
  72. package/dist/index.cjs +3425 -955
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.cts +237 -14
  75. package/dist/index.d.ts +237 -14
  76. package/dist/index.mjs +3417 -958
  77. package/dist/index.mjs.map +1 -1
  78. package/dist/lane/index.cjs +928 -54
  79. package/dist/lane/index.cjs.map +1 -1
  80. package/dist/lane/index.mjs +930 -56
  81. package/dist/lane/index.mjs.map +1 -1
  82. package/dist/match/index.d.cts +6 -5
  83. package/dist/match/index.d.ts +6 -5
  84. package/dist/pem/index.d.cts +4 -3
  85. package/dist/pem/index.d.ts +4 -3
  86. package/dist/pilot/index.cjs +8 -4
  87. package/dist/pilot/index.cjs.map +1 -1
  88. package/dist/pilot/index.d.cts +4 -3
  89. package/dist/pilot/index.d.ts +4 -3
  90. package/dist/pilot/index.mjs +10 -6
  91. package/dist/pilot/index.mjs.map +1 -1
  92. package/dist/playstore/index.cjs +207 -0
  93. package/dist/playstore/index.cjs.map +1 -0
  94. package/dist/playstore/index.d.cts +1 -0
  95. package/dist/playstore/index.d.ts +1 -0
  96. package/dist/playstore/index.mjs +203 -0
  97. package/dist/playstore/index.mjs.map +1 -0
  98. package/dist/precheck/index.d.cts +4 -3
  99. package/dist/precheck/index.d.ts +4 -3
  100. package/dist/privacy/index.cjs +207 -0
  101. package/dist/privacy/index.cjs.map +1 -0
  102. package/dist/privacy/index.d.cts +2 -0
  103. package/dist/privacy/index.d.ts +2 -0
  104. package/dist/privacy/index.mjs +195 -0
  105. package/dist/privacy/index.mjs.map +1 -0
  106. package/dist/produce/index.cjs +32 -0
  107. package/dist/produce/index.cjs.map +1 -1
  108. package/dist/produce/index.d.cts +4 -3
  109. package/dist/produce/index.d.ts +4 -3
  110. package/dist/produce/index.mjs +32 -1
  111. package/dist/produce/index.mjs.map +1 -1
  112. package/dist/review/index.cjs +141 -0
  113. package/dist/review/index.cjs.map +1 -0
  114. package/dist/review/index.d.cts +2 -0
  115. package/dist/review/index.d.ts +2 -0
  116. package/dist/review/index.mjs +137 -0
  117. package/dist/review/index.mjs.map +1 -0
  118. package/dist/sigh/index.d.cts +4 -3
  119. package/dist/sigh/index.d.ts +4 -3
  120. package/dist/xcode/index.cjs +1 -1
  121. package/dist/xcode/index.cjs.map +1 -1
  122. package/dist/xcode/index.mjs +1 -1
  123. package/dist/xcode/index.mjs.map +1 -1
  124. package/package.json +27 -1
  125. package/dist/index-B9QeTpQK.d.cts +0 -99
  126. package/dist/index-xykpq6Lz.d.ts +0 -99
@@ -1,6 +1,9 @@
1
1
  import { importPKCS8, SignJWT } from 'jose';
2
2
  import { createHash, randomBytes, pbkdf2Sync } from 'crypto';
3
3
  import { createInterface } from 'readline';
4
+ import { writeFileSync, chmodSync, existsSync, unlinkSync, readFileSync, mkdirSync } from 'fs';
5
+ import { homedir } from 'os';
6
+ import { join } from 'path';
4
7
 
5
8
  // src/client/auth.ts
6
9
  var MAX_TOKEN_DURATION = 1200;
@@ -164,6 +167,20 @@ function applePbkdf2(password, salt, iterations, keyLength, protocol) {
164
167
 
165
168
  // src/client/apple-session.ts
166
169
  var AUTH_BASE = "https://idmsa.apple.com/appleauth/auth";
170
+ async function appleJson(res, what) {
171
+ const text = await res.text();
172
+ try {
173
+ return JSON.parse(text);
174
+ } catch {
175
+ const contentType = (res.headers.get("content-type") ?? "").split(";")[0].trim();
176
+ const title = /<title>([^<]{1,120})<\/title>/i.exec(text)?.[1]?.trim();
177
+ const looksHtml = /^\s*<(!doctype|html)/i.test(text) || contentType === "text/html";
178
+ const page = looksHtml ? "an HTML page" : contentType ? `a ${contentType} response` : "a non-JSON response";
179
+ throw new Error(
180
+ `Apple answered the ${what} with ${page} (HTTP ${res.status}${title ? `, "${title}"` : ""}) instead of JSON. Apple is refusing or rate-limiting sign-ins from this server right now; wait a few minutes and try again. If it keeps happening, sign in once at appleid.apple.com to clear any hold on the account.`
181
+ );
182
+ }
183
+ }
167
184
  var OLYMPUS_SESSION = "https://appstoreconnect.apple.com/olympus/v1/session";
168
185
  var WIDGET_KEY_URL = "https://appstoreconnect.apple.com/olympus/v1/app/config?hostname=itunesconnect.apple.com";
169
186
  var ProgramLicenseAgreementError = class extends Error {
@@ -250,7 +267,7 @@ async function beginLogin(config) {
250
267
  }
251
268
  async function fetchTwoFactorChallenge(pending) {
252
269
  const r = await fetch(`${AUTH_BASE}`, { headers: buildAuthHeadersFromPending(pending) });
253
- const body = await r.json();
270
+ const body = await appleJson(r, "two-factor challenge");
254
271
  const trustedPhoneNumbers = (body.trustedPhoneNumbers ?? []).map((p) => ({
255
272
  id: p.id,
256
273
  numberWithDialCode: p.numberWithDialCode,
@@ -271,7 +288,8 @@ async function requestSmsCode(input) {
271
288
  body: JSON.stringify({ phoneNumber: { id: input.phoneId }, mode: input.mode ?? "sms" })
272
289
  });
273
290
  }
274
- async function submitTwoFactorCode(input) {
291
+ async function submitTwoFactorCode(rawInput) {
292
+ const input = { ...rawInput, code: rawInput.code.replace(/[\s\u00a0]+/g, "") };
275
293
  const log = input.onLog ?? (() => {
276
294
  });
277
295
  let path;
@@ -383,9 +401,12 @@ async function doSirp(user, password, serviceKey, cookieStr, hashcash) {
383
401
  body: JSON.stringify({ a: aBase64, accountName: user, protocols: ["s2k", "s2k_fo"] }),
384
402
  redirect: "manual"
385
403
  });
386
- const initBody = await initRes.json();
404
+ const initBody = await appleJson(initRes, "sign-in init");
387
405
  if (initBody.serviceErrors) throw new Error(`Apple auth error: ${JSON.stringify(initBody.serviceErrors)}`);
388
406
  const { iteration: iterations, salt: saltB64, b: bB64, c, protocol } = initBody;
407
+ if (!iterations || !saltB64 || !bB64 || !c || !protocol) {
408
+ throw new Error(`Apple's sign-in init answered without a challenge (HTTP ${initRes.status}): ${JSON.stringify(initBody).slice(0, 300)}`);
409
+ }
389
410
  const salt = Buffer.from(saltB64, "base64");
390
411
  const b = Buffer.from(bB64, "base64");
391
412
  const encryptedPassword = applePbkdf2(password, salt, iterations, 32, protocol);
@@ -428,7 +449,7 @@ async function fetchOlympusSession(session) {
428
449
  const cookieStr = Object.entries(session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
429
450
  const res = await fetch(OLYMPUS_SESSION, { headers: { Cookie: cookieStr, Accept: "application/json" } });
430
451
  if (res.ok) {
431
- const body = await res.json();
452
+ const body = await appleJson(res, "session lookup");
432
453
  if (body?.user?.emailAddress) session.userEmail = body.user.emailAddress;
433
454
  if (body?.provider?.providerId) session.teamId = String(body.provider.providerId);
434
455
  }
@@ -440,7 +461,7 @@ async function fetchContractMessages(session) {
440
461
  headers: { Cookie: cookieStr, Accept: "application/json" }
441
462
  });
442
463
  if (!res.ok) return [];
443
- const body = await res.json();
464
+ const body = await appleJson(res, "agreements lookup");
444
465
  return (body ?? []).map((m) => ({
445
466
  id: m.id ?? "",
446
467
  group: m.group ?? "",
@@ -451,10 +472,23 @@ async function fetchContractMessages(session) {
451
472
  return [];
452
473
  }
453
474
  }
454
- async function fetchServiceKey() {
455
- const res = await fetch(WIDGET_KEY_URL);
456
- const body = await res.json();
457
- if (!body?.authServiceKey) throw new Error("Could not fetch Apple service key");
475
+ var LOGOUT_URL = "https://appstoreconnect.apple.com/logout";
476
+ function serviceKeyFromLocation(location) {
477
+ if (!location) return null;
478
+ try {
479
+ const key = new URL(location).searchParams.get("widgetKey")?.trim();
480
+ return key && /^[0-9a-f]{16,}$/i.test(key) ? key : null;
481
+ } catch {
482
+ return null;
483
+ }
484
+ }
485
+ async function fetchServiceKey(fetchImpl = fetch) {
486
+ const head = await fetchImpl(LOGOUT_URL, { method: "HEAD", redirect: "manual" });
487
+ const fromRedirect = serviceKeyFromLocation(head.headers.get("location"));
488
+ if (fromRedirect) return fromRedirect;
489
+ const res = await fetchImpl(WIDGET_KEY_URL);
490
+ const body = await appleJson(res, "service key request");
491
+ if (!body?.authServiceKey) throw new Error("Could not fetch Apple service key: the sign-out redirect carried no widgetKey and the config endpoint had no authServiceKey.");
458
492
  return body.authServiceKey;
459
493
  }
460
494
  function buildAuthHeaders(session) {
@@ -2052,6 +2086,19 @@ var PreReleaseVersionsResource = class {
2052
2086
  };
2053
2087
 
2054
2088
  // src/resources/review-submission-items.ts
2089
+ var ITEM_RELATIONSHIPS = {
2090
+ appStoreVersionId: ["appStoreVersion", "appStoreVersions"],
2091
+ appCustomProductPageVersionId: ["appCustomProductPageVersion", "appCustomProductPageVersions"],
2092
+ appStoreVersionExperimentId: ["appStoreVersionExperiment", "appStoreVersionExperiments"],
2093
+ appStoreVersionExperimentV2Id: ["appStoreVersionExperimentV2", "appStoreVersionExperiments"],
2094
+ appEventId: ["appEvent", "appEvents"],
2095
+ appAssetLibraryImageId: ["appAssetLibraryImage", "appAssetLibraryImages"],
2096
+ appAssetLibraryVideoId: ["appAssetLibraryVideo", "appAssetLibraryVideos"],
2097
+ backgroundAssetVersionId: ["backgroundAssetVersion", "backgroundAssetVersions"],
2098
+ inAppPurchaseVersionId: ["inAppPurchaseVersion", "inAppPurchaseVersions"],
2099
+ subscriptionVersionId: ["subscriptionVersion", "subscriptionVersions"],
2100
+ subscriptionGroupVersionId: ["subscriptionGroupVersion", "subscriptionGroupVersions"]
2101
+ };
2055
2102
  var ReviewSubmissionItemsResource = class {
2056
2103
  constructor(http) {
2057
2104
  this.http = http;
@@ -2073,32 +2120,20 @@ var ReviewSubmissionItemsResource = class {
2073
2120
  );
2074
2121
  return response.data;
2075
2122
  }
2123
+ /**
2124
+ * Add one item to a review submission. Besides versions, asset library
2125
+ * images and videos can be submitted on their own (ASC API 4.5.1) so
2126
+ * creative assets are approved ahead of a campaign.
2127
+ */
2076
2128
  async create(params) {
2077
2129
  const relationships = {
2078
2130
  reviewSubmission: {
2079
2131
  data: { type: "reviewSubmissions", id: params.reviewSubmissionId }
2080
2132
  }
2081
2133
  };
2082
- if (params.appStoreVersionId) {
2083
- relationships.appStoreVersion = {
2084
- data: { type: "appStoreVersions", id: params.appStoreVersionId }
2085
- };
2086
- }
2087
- if (params.appCustomProductPageVersionId) {
2088
- relationships.appCustomProductPageVersion = {
2089
- data: {
2090
- type: "appCustomProductPageVersions",
2091
- id: params.appCustomProductPageVersionId
2092
- }
2093
- };
2094
- }
2095
- if (params.appStoreVersionExperimentId) {
2096
- relationships.appStoreVersionExperiment = {
2097
- data: {
2098
- type: "appStoreVersionExperiments",
2099
- id: params.appStoreVersionExperimentId
2100
- }
2101
- };
2134
+ for (const [param, [relationship, type]] of Object.entries(ITEM_RELATIONSHIPS)) {
2135
+ const id = params[param];
2136
+ if (id) relationships[relationship] = { data: { type, id } };
2102
2137
  }
2103
2138
  const response = await this.http.post(
2104
2139
  "/v1/reviewSubmissionItems",
@@ -2302,6 +2337,256 @@ var XcodeMetricsResource = class {
2302
2337
  }
2303
2338
  };
2304
2339
 
2340
+ // src/resources/app-asset-libraries.ts
2341
+ var AppAssetLibrariesResource = class {
2342
+ constructor(http) {
2343
+ this.http = http;
2344
+ }
2345
+ http;
2346
+ async getForApp(appId) {
2347
+ const response = await this.http.get(
2348
+ `/v1/apps/${appId}/assetLibrary`
2349
+ );
2350
+ return response.data;
2351
+ }
2352
+ async listImages(libraryId, params = {}) {
2353
+ return this.http.all(`/v1/appAssetLibraries/${libraryId}/images`, params);
2354
+ }
2355
+ async listVideos(libraryId, params = {}) {
2356
+ return this.http.all(`/v1/appAssetLibraries/${libraryId}/videos`, params);
2357
+ }
2358
+ /**
2359
+ * Specs, placement groups and limits. Apple adds placement groups (new
2360
+ * devices) without an API version bump, so read them from here rather than
2361
+ * hard-coding display types.
2362
+ */
2363
+ async refData(params = {}) {
2364
+ const filter = {};
2365
+ if (params.features?.length) filter.features = params.features;
2366
+ if (params.placementTypes?.length) filter.placementTypes = params.placementTypes;
2367
+ if (params.placementProfileGroups?.length) filter.placementProfileGroups = params.placementProfileGroups;
2368
+ const data = await this.http.all("/v1/appAssetLibraryRefData", { filter });
2369
+ return mergeRefData(data.map((d) => d.attributes));
2370
+ }
2371
+ };
2372
+ function mergeRefData(parts) {
2373
+ const merged = {
2374
+ features: [],
2375
+ placementProfileGroups: [],
2376
+ imageSpecs: [],
2377
+ videoSpecs: [],
2378
+ placementTypes: [],
2379
+ displayClasses: []
2380
+ };
2381
+ for (const part of parts) {
2382
+ for (const key of Object.keys(merged)) {
2383
+ merged[key].push(...part[key] ?? []);
2384
+ }
2385
+ }
2386
+ return merged;
2387
+ }
2388
+
2389
+ // src/resources/app-asset-library-assets.ts
2390
+ var AssetLibraryMediaResource = class {
2391
+ constructor(http) {
2392
+ this.http = http;
2393
+ }
2394
+ http;
2395
+ async get(id) {
2396
+ const response = await this.http.get(`/v1/${this.type}/${id}`);
2397
+ return response.data;
2398
+ }
2399
+ async reserve(params, extra = {}) {
2400
+ const { libraryId, ...attributes } = params;
2401
+ const response = await this.http.post(`/v1/${this.type}`, {
2402
+ data: {
2403
+ type: this.type,
2404
+ attributes: { ...attributes, ...extra },
2405
+ relationships: {
2406
+ assetLibrary: { data: { type: "appAssetLibraries", id: libraryId } }
2407
+ }
2408
+ }
2409
+ });
2410
+ return response.data;
2411
+ }
2412
+ async patch(id, attributes) {
2413
+ const response = await this.http.patch(`/v1/${this.type}/${id}`, {
2414
+ data: { type: this.type, id, attributes }
2415
+ });
2416
+ return response.data;
2417
+ }
2418
+ /** Fails with 409 STATE_ERROR.ASSET_HAS_PLACEMENTS while the asset is still placed. */
2419
+ async delete(id) {
2420
+ await this.http.delete(`/v1/${this.type}/${id}`);
2421
+ }
2422
+ async listPlacements(id, params = {}) {
2423
+ return this.http.all(`/v1/${this.type}/${id}/placements`, params);
2424
+ }
2425
+ };
2426
+ var AppAssetLibraryImagesResource = class extends AssetLibraryMediaResource {
2427
+ type = "appAssetLibraryImages";
2428
+ async create(params) {
2429
+ return this.reserve(params);
2430
+ }
2431
+ async update(id, attributes) {
2432
+ return this.patch(id, { ...attributes });
2433
+ }
2434
+ };
2435
+ var AppAssetLibraryVideosResource = class extends AssetLibraryMediaResource {
2436
+ type = "appAssetLibraryVideos";
2437
+ async create(params) {
2438
+ const { previewFrameTimeCode, ...rest } = params;
2439
+ return this.reserve(rest, previewFrameTimeCode ? { previewFrameTimeCode } : {});
2440
+ }
2441
+ async update(id, attributes) {
2442
+ return this.patch(id, { ...attributes });
2443
+ }
2444
+ };
2445
+
2446
+ // src/resources/app-asset-library-placements.ts
2447
+ var TARGET_TYPES = {
2448
+ appStoreVersionLocalization: "appStoreVersionLocalizations",
2449
+ appCustomProductPageLocalization: "appCustomProductPageLocalizations",
2450
+ appEventLocalization: "appEventLocalizations",
2451
+ appStoreVersionExperimentTreatmentLocalization: "appStoreVersionExperimentTreatmentLocalizations"
2452
+ };
2453
+ function targetRelationship(target) {
2454
+ return { [target.kind]: { data: { type: TARGET_TYPES[target.kind], id: target.id } } };
2455
+ }
2456
+ var AppAssetLibraryPlacementsResource = class {
2457
+ constructor(http) {
2458
+ this.http = http;
2459
+ }
2460
+ http;
2461
+ /**
2462
+ * Place an image or video on one localization. Placements cannot be edited —
2463
+ * delete and recreate. The parent version/page must be editable.
2464
+ */
2465
+ async create(params) {
2466
+ if (!params.imageId === !params.videoId) {
2467
+ throw new Error("A placement needs exactly one of imageId or videoId");
2468
+ }
2469
+ const media = params.imageId ? { image: { data: { type: "appAssetLibraryImages", id: params.imageId } } } : { video: { data: { type: "appAssetLibraryVideos", id: params.videoId } } };
2470
+ const response = await this.http.post(
2471
+ "/v1/appAssetLibraryPlacements",
2472
+ {
2473
+ data: {
2474
+ type: "appAssetLibraryPlacements",
2475
+ attributes: { placementType: params.placementType, placementGroup: params.placementGroup },
2476
+ relationships: { ...media, ...targetRelationship(params.target) }
2477
+ }
2478
+ }
2479
+ );
2480
+ return response.data;
2481
+ }
2482
+ async get(id, params = {}) {
2483
+ const response = await this.http.get(
2484
+ `/v1/appAssetLibraryPlacements/${id}`,
2485
+ params.include ? { include: params.include } : void 0
2486
+ );
2487
+ return response.data;
2488
+ }
2489
+ async delete(id) {
2490
+ await this.http.delete(`/v1/appAssetLibraryPlacements/${id}`);
2491
+ }
2492
+ /** Placements on one localization, in display order by default. */
2493
+ async listForTarget(target, params = {}) {
2494
+ const filter = {};
2495
+ if (params.placementType) filter.placementType = params.placementType;
2496
+ if (params.placementGroup) filter.placementGroup = params.placementGroup;
2497
+ const listParams = { filter, include: params.include, sort: "placementGroupPosition" };
2498
+ return this.http.all(
2499
+ `/v1/${TARGET_TYPES[target.kind]}/${target.id}/placements`,
2500
+ listParams
2501
+ );
2502
+ }
2503
+ /** Set the display order of a placement group. In-app event localizations cannot be ordered. */
2504
+ async order(params) {
2505
+ if (params.target.kind === "appEventLocalization") {
2506
+ throw new Error("In-app event placements cannot be ordered");
2507
+ }
2508
+ await this.http.post("/v1/appAssetLibraryPlacementOrderingRequests", {
2509
+ data: {
2510
+ type: "appAssetLibraryPlacementOrderingRequests",
2511
+ attributes: { placementGroup: params.placementGroup },
2512
+ relationships: {
2513
+ orderedPlacements: {
2514
+ data: params.placementIds.map((id) => ({ type: "appAssetLibraryPlacements", id }))
2515
+ },
2516
+ ...targetRelationship(params.target)
2517
+ }
2518
+ }
2519
+ });
2520
+ }
2521
+ };
2522
+ var OLYMPUS_SESSION2 = "https://appstoreconnect.apple.com/olympus/v1/session";
2523
+ function sessionDir() {
2524
+ return process.env.FASTNODE_SESSION_DIR || join(homedir(), ".fastnode", "sessions");
2525
+ }
2526
+ function fileFor(email) {
2527
+ const key = createHash("sha256").update(email.trim().toLowerCase()).digest("hex").slice(0, 16);
2528
+ return join(sessionDir(), `${key}.json`);
2529
+ }
2530
+ function ensureDir() {
2531
+ const dir = sessionDir();
2532
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true, mode: 448 });
2533
+ chmodSync(dir, 448);
2534
+ }
2535
+ function saveAppleSession(session) {
2536
+ ensureDir();
2537
+ const stored = { email: session.userEmail, savedAt: (/* @__PURE__ */ new Date()).toISOString(), session };
2538
+ const path = fileFor(session.userEmail);
2539
+ writeFileSync(path, JSON.stringify(stored), { mode: 384 });
2540
+ chmodSync(path, 384);
2541
+ writeFileSync(join(sessionDir(), "last-apple-id"), session.userEmail, { mode: 384 });
2542
+ }
2543
+ function clearAppleSession(email) {
2544
+ const path = fileFor(email);
2545
+ if (existsSync(path)) unlinkSync(path);
2546
+ }
2547
+ function lastAppleId() {
2548
+ try {
2549
+ return readFileSync(join(sessionDir(), "last-apple-id"), "utf8").trim() || null;
2550
+ } catch {
2551
+ return null;
2552
+ }
2553
+ }
2554
+ async function loadAppleSession(email, fetchImpl = fetch) {
2555
+ const path = fileFor(email);
2556
+ if (!existsSync(path)) return null;
2557
+ let stored;
2558
+ try {
2559
+ stored = JSON.parse(readFileSync(path, "utf8"));
2560
+ } catch {
2561
+ return null;
2562
+ }
2563
+ const cookie = Object.entries(stored.session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
2564
+ try {
2565
+ const res = await fetchImpl(OLYMPUS_SESSION2, { headers: { Cookie: cookie, Accept: "application/json" } });
2566
+ if (!res.ok) {
2567
+ clearAppleSession(email);
2568
+ return null;
2569
+ }
2570
+ } catch {
2571
+ return null;
2572
+ }
2573
+ return stored.session;
2574
+ }
2575
+ async function signInWithAppleId(options) {
2576
+ const email = options.email || lastAppleId() || await options.askEmail();
2577
+ if (!options.fresh) {
2578
+ const saved = await loadAppleSession(email);
2579
+ if (saved) {
2580
+ options.onLog?.(`Using saved Apple ID session for ${email}`);
2581
+ return saved;
2582
+ }
2583
+ }
2584
+ const password = await options.askPassword(email);
2585
+ const session = await loginWithAppleId({ email, password, onLog: options.onLog });
2586
+ saveAppleSession(session);
2587
+ return session;
2588
+ }
2589
+
2305
2590
  // src/client/portal.ts
2306
2591
  var PORTAL_BASE = "https://developer.apple.com/services-account/QH65B2";
2307
2592
  function pickUniqueKeyName(base, taken) {
@@ -2637,7 +2922,10 @@ var PortalClient = class _PortalClient {
2637
2922
  }
2638
2923
  // ── Teams ──────────────────────────────────────────────────────────────
2639
2924
  async listTeams() {
2640
- const data = await this.post("account/listTeams.action", {});
2925
+ const data = await this.post("account/listTeams.action", {
2926
+ pageSize: "500",
2927
+ pageNumber: "1"
2928
+ });
2641
2929
  return data.teams ?? [];
2642
2930
  }
2643
2931
  // ── App IDs / Bundle IDs ───────────────────────────────────────────────
@@ -2651,11 +2939,12 @@ var PortalClient = class _PortalClient {
2651
2939
  return data.appIds ?? [];
2652
2940
  }
2653
2941
  async createAppId(params) {
2942
+ const safeName = params.name.replace(/[^0-9A-Za-z\s]/g, " ").replace(/\s+/g, " ").trim() || "App";
2654
2943
  const reqParams = {
2655
2944
  teamId: this.teamId,
2656
2945
  type: "explicit",
2657
2946
  identifier: params.identifier,
2658
- name: params.name
2947
+ name: safeName
2659
2948
  };
2660
2949
  if (params.enablePush) reqParams.push = "on";
2661
2950
  if (params.enableIAP !== false) reqParams.inAppPurchase = "on";
@@ -2690,6 +2979,191 @@ var PortalClient = class _PortalClient {
2690
2979
  featureValue: params.enabled ? "on" : "off"
2691
2980
  });
2692
2981
  }
2982
+ // ── Application Groups ──────────────────────────────────────────────────
2983
+ //
2984
+ // App Groups (e.g. `group.com.playspina.com`) are the only clean way to
2985
+ // share data — an auth token, in our case — between a host app and an
2986
+ // embedded extension (Messages / Notification Service / etc.). App Store
2987
+ // Connect API keys (.p8) genuinely cannot manage them; Apple only exposes
2988
+ // group create/associate through this legacy session-cookie portal API,
2989
+ // which is why they live on PortalClient (Apple ID session) and not on the
2990
+ // ASC REST client. Endpoint shapes ported 1:1 from Spaceship's
2991
+ // portal_client.rb (listApplicationGroups / addApplicationGroup /
2992
+ // assignApplicationGroupToAppId).
2993
+ /** Apple's internal feature code for the App Groups capability. */
2994
+ static APP_GROUPS_FEATURE = "APG3427HIY";
2995
+ /** List all app groups in the team. */
2996
+ async listAppGroups() {
2997
+ const data = await this.post("account/ios/identifiers/listApplicationGroups.action", {
2998
+ teamId: this.teamId,
2999
+ pageNumber: "1",
3000
+ pageSize: "500",
3001
+ sort: "name=asc"
3002
+ });
3003
+ return data.applicationGroupList ?? [];
3004
+ }
3005
+ /**
3006
+ * Create an app group, returning the raw group record. Idempotent —
3007
+ * Apple rejects a duplicate group identifier ("Multiple App Groups may
3008
+ * not have the same identifier"), so we list first and reuse an existing
3009
+ * group when the identifier already exists in the team.
3010
+ *
3011
+ * Note the two ids on the returned record: `identifier` is the
3012
+ * `group.com.…` string you type, while `applicationGroup` is Apple's
3013
+ * opaque internal handle that association actually requires — do NOT pass
3014
+ * the human identifier to assignAppGroups.
3015
+ */
3016
+ async createAppGroup(params) {
3017
+ const existing = await this.listAppGroups();
3018
+ const hit = existing.find((g) => g.identifier === params.identifier);
3019
+ if (hit) return hit;
3020
+ const safeName = params.name.replace(/[^0-9A-Za-z\s]/g, " ").replace(/\s+/g, " ").trim() || "App Group";
3021
+ const data = await this.post("account/ios/identifiers/addApplicationGroup.action", {
3022
+ teamId: this.teamId,
3023
+ identifier: params.identifier,
3024
+ name: safeName
3025
+ });
3026
+ return data.applicationGroup;
3027
+ }
3028
+ /**
3029
+ * Enable the App Groups capability on an App ID. Required before an
3030
+ * App ID can have a group associated with it — mirrors Spaceship
3031
+ * enabling `AppService::AppGroup` before `associate_groups`.
3032
+ */
3033
+ async enableAppGroups(appIdId) {
3034
+ await this.post("account/ios/identifiers/updateService.action", {
3035
+ teamId: this.teamId,
3036
+ displayId: appIdId,
3037
+ featureType: _PortalClient.APP_GROUPS_FEATURE,
3038
+ featureValue: "true"
3039
+ });
3040
+ }
3041
+ /**
3042
+ * Associate one or more app groups with an App ID. `appGroupIds` are the
3043
+ * internal ids (Spaceship's `app_group_id`), NOT the `group.com.…`
3044
+ * identifiers. Apple wants both `appIdId` and `displayId` set to the
3045
+ * App ID's internal id, per Spaceship's associate_groups_with_app.
3046
+ */
3047
+ async assignAppGroups(params) {
3048
+ await this.post("account/ios/identifiers/assignApplicationGroupToAppId.action", {
3049
+ teamId: this.teamId,
3050
+ appIdId: params.appIdId,
3051
+ displayId: params.appIdId,
3052
+ applicationGroups: params.appGroupIds
3053
+ });
3054
+ }
3055
+ // ── Apple Pay merchants (OMCs) ─────────────────────────────────────────
3056
+ //
3057
+ // Merchant IDs are team-level identifiers (merchant.com.…) that an App ID's
3058
+ // Apple Pay capability must be LINKED to — enabling the capability alone
3059
+ // produces profiles that fail with "doesn't support the … Merchant ID".
3060
+ // Like App Groups, merchants are only manageable through the legacy
3061
+ // session-cookie portal API. Endpoint shapes ported 1:1 from Spaceship's
3062
+ // portal_client.rb (merchants / create_merchant! /
3063
+ // associate_merchants_with_app).
3064
+ /** Apple's internal feature code for the Apple Pay capability. */
3065
+ static APPLE_PAY_FEATURE = "OM633U5T5G";
3066
+ /**
3067
+ * List all Apple Pay merchant IDs in the team. Each record maps
3068
+ * (per Spaceship's merchant.rb attr_mapping): `omcId` = internal id,
3069
+ * `identifier` = the human `merchant.com.…` string, `name` = display name.
3070
+ */
3071
+ async listMerchants() {
3072
+ const data = await this.post("account/ios/identifiers/listOMCs.action", {
3073
+ teamId: this.teamId,
3074
+ pageNumber: "1",
3075
+ pageSize: "500",
3076
+ sort: "name=asc"
3077
+ });
3078
+ return data.identifierList ?? [];
3079
+ }
3080
+ /**
3081
+ * Register (or reuse) a merchant ID, returning its INTERNAL id (`omcId`) —
3082
+ * Apple's opaque handle that association requires, NOT the human
3083
+ * `merchant.com.…` identifier. Idempotent: lists first and reuses an
3084
+ * existing merchant with the same identifier. Endpoint + params ported 1:1
3085
+ * from Spaceship's create_merchant! (addOMC.action).
3086
+ */
3087
+ async createMerchant(params) {
3088
+ const existing = await this.listMerchants();
3089
+ const hit = existing.find((m) => m.identifier === params.identifier);
3090
+ if (hit?.omcId) return String(hit.omcId);
3091
+ const safeName = params.name.replace(/[^0-9A-Za-z\s]/g, " ").replace(/\s+/g, " ").trim() || "Merchant";
3092
+ const data = await this.post("account/ios/identifiers/addOMC.action", {
3093
+ name: safeName,
3094
+ identifier: params.identifier,
3095
+ teamId: this.teamId
3096
+ });
3097
+ const rec = data.omcId ?? data;
3098
+ const id = typeof rec === "string" ? rec : rec?.omcId ?? rec?.merchantId;
3099
+ if (!id) {
3100
+ throw new Error("Apple returned no internal merchant id (omcId) for the registered merchant.");
3101
+ }
3102
+ return String(id);
3103
+ }
3104
+ /**
3105
+ * Enable the Apple Pay capability on an App ID. Apple Pay is a standard
3106
+ * AppService (service_id OM633U5T5G) whose service_uri is the default
3107
+ * `updateService.action` — confirmed in Spaceship's app_service.rb.
3108
+ */
3109
+ async enableApplePay(appIdId) {
3110
+ await this.post("account/ios/identifiers/updateService.action", {
3111
+ teamId: this.teamId,
3112
+ displayId: appIdId,
3113
+ featureType: _PortalClient.APPLE_PAY_FEATURE,
3114
+ featureValue: "true"
3115
+ });
3116
+ }
3117
+ /**
3118
+ * Associate merchant IDs with an App ID's Apple Pay capability. `omcIds`
3119
+ * are the internal ids (each merchant record's `omcId`), NOT the
3120
+ * `merchant.com.…` identifiers. Endpoint + params ported 1:1 from
3121
+ * Spaceship's associate_merchants_with_app (assignOMCToAppId.action — note
3122
+ * the singular "OMC", and NO displayId param).
3123
+ */
3124
+ async assignMerchants(params) {
3125
+ await this.post("account/ios/identifiers/assignOMCToAppId.action", {
3126
+ teamId: this.teamId,
3127
+ appIdId: params.appIdId,
3128
+ omcIds: params.omcIds
3129
+ });
3130
+ }
3131
+ /**
3132
+ * Create an Apple Pay **Payment Processing Certificate** on a merchant ID
3133
+ * from a CSR — the certificate a PSP (e.g. Stripe) hands you as a CSR, which
3134
+ * must be uploaded to the Merchant ID in Apple Developer, then the resulting
3135
+ * `.cer` downloaded and given back to the PSP so it can decrypt payment
3136
+ * tokens. This is the one manual Apple-portal step in wiring up Apple Pay.
3137
+ *
3138
+ * Ported 1:1 from Spaceship's create_certificate! (submitCertificateRequest
3139
+ * .action): the merchant's INTERNAL id (`omcId`) is passed as BOTH `appIdId`
3140
+ * and `specialIdentifierDisplayId` — the latter is how the portal scopes a
3141
+ * cert to a merchant/special identifier rather than an App ID. The cert type
3142
+ * is APPLE_PAY (`4APLUP237T`). Returns the created certRequest (its
3143
+ * `certificateId` feeds `downloadApplePayCertificate`).
3144
+ *
3145
+ * @param omcId the merchant's internal id (from createMerchant/listMerchants)
3146
+ * @param csrContent the PEM CSR string (Stripe's "Apple Pay CSR")
3147
+ */
3148
+ async createApplePayCertificate(params) {
3149
+ const data = await this.post("account/ios/certificate/submitCertificateRequest.action", {
3150
+ teamId: this.teamId,
3151
+ type: _PortalClient.CERT_TYPES.APPLE_PAY,
3152
+ csrContent: params.csrContent,
3153
+ appIdId: params.omcId,
3154
+ specialIdentifierDisplayId: params.omcId
3155
+ });
3156
+ return data.certRequest;
3157
+ }
3158
+ /**
3159
+ * Download an Apple Pay Payment Processing Certificate's raw bytes by its
3160
+ * certificate id (from `createApplePayCertificate`). Thin wrapper over
3161
+ * `downloadCertificate` pinned to the APPLE_PAY type — the DER `.cer` you
3162
+ * upload back into Stripe.
3163
+ */
3164
+ async downloadApplePayCertificate(certificateId) {
3165
+ return this.downloadCertificate(certificateId, _PortalClient.CERT_TYPES.APPLE_PAY);
3166
+ }
2693
3167
  // ── Certificates ───────────────────────────────────────────────────────
2694
3168
  async listCertificates(types) {
2695
3169
  const iosTypes = types ?? [
@@ -3202,6 +3676,10 @@ var AppStoreConnectClient = class {
3202
3676
  inAppPurchases;
3203
3677
  gameCenterDetail;
3204
3678
  xcodeMetrics;
3679
+ appAssetLibraries;
3680
+ appAssetLibraryImages;
3681
+ appAssetLibraryVideos;
3682
+ appAssetLibraryPlacements;
3205
3683
  constructor(config) {
3206
3684
  const tokenManager = new TokenManager({
3207
3685
  keyId: config.keyId,
@@ -3245,12 +3723,16 @@ var AppStoreConnectClient = class {
3245
3723
  this.inAppPurchases = new InAppPurchasesResource(this.http);
3246
3724
  this.gameCenterDetail = new GameCenterDetailResource(this.http);
3247
3725
  this.xcodeMetrics = new XcodeMetricsResource(this.http);
3726
+ this.appAssetLibraries = new AppAssetLibrariesResource(this.http);
3727
+ this.appAssetLibraryImages = new AppAssetLibraryImagesResource(this.http);
3728
+ this.appAssetLibraryVideos = new AppAssetLibraryVideosResource(this.http);
3729
+ this.appAssetLibraryPlacements = new AppAssetLibraryPlacementsResource(this.http);
3248
3730
  }
3249
3731
  async request(path, options) {
3250
3732
  return this.http.request(path, options);
3251
3733
  }
3252
3734
  };
3253
3735
 
3254
- export { AppStoreConnectClient, AppStoreConnectError, IrisAuthError, IrisClient, PortalClient, ProgramLicenseAgreementError, RateLimitError, RequestClient, TokenManager, beginLogin, checkPortalResponse, loginWithAppleId, requestSmsCode, submitTwoFactorCode };
3736
+ export { AppStoreConnectClient, AppStoreConnectError, IrisAuthError, IrisClient, PortalClient, ProgramLicenseAgreementError, RateLimitError, RequestClient, TokenManager, beginLogin, checkPortalResponse, clearAppleSession, lastAppleId, loadAppleSession, loginWithAppleId, requestSmsCode, saveAppleSession, sessionDir, signInWithAppleId, submitTwoFactorCode };
3255
3737
  //# sourceMappingURL=index.mjs.map
3256
3738
  //# sourceMappingURL=index.mjs.map