@sitepong/fastnode 0.1.2 → 0.2.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.
- package/README.md +148 -0
- package/dist/actions/index.cjs +737 -110
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.mjs +737 -110
- package/dist/actions/index.mjs.map +1 -1
- package/dist/cert/index.cjs +40 -0
- package/dist/cert/index.cjs.map +1 -1
- package/dist/cert/index.d.cts +3 -3
- package/dist/cert/index.d.ts +3 -3
- package/dist/cert/index.mjs +37 -1
- package/dist/cert/index.mjs.map +1 -1
- package/dist/{cert-BmJGtYtb.d.cts → cert-6m1R8UeW.d.cts} +1 -1
- package/dist/{cert-owkOFNW8.d.ts → cert-DtYDJBjG.d.ts} +1 -1
- package/dist/cli/index.cjs +737 -110
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.mjs +737 -110
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.cjs +730 -109
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.mjs +726 -110
- package/dist/client/index.mjs.map +1 -1
- package/dist/deliver/index.d.cts +2 -2
- package/dist/deliver/index.d.ts +2 -2
- package/dist/{index-D6zjGlPL.d.cts → index-AD8QXY1T.d.cts} +1 -1
- package/dist/{index-DfCUVJX1.d.cts → index-BW8wQUGC.d.cts} +1 -1
- package/dist/{index-EcVvViW8.d.cts → index-BWK-T2-S.d.cts} +1 -1
- package/dist/{index-B0yhu_LZ.d.ts → index-BpiEBPVd.d.ts} +1 -1
- package/dist/index-CCs5irG7.d.cts +61 -0
- package/dist/{index-B9yXicrQ.d.ts → index-CLsvyTkh.d.ts} +1 -1
- package/dist/{index-BLubSlgK.d.cts → index-CMH_GpN9.d.cts} +358 -2
- package/dist/index-CQKpbHZt.d.ts +61 -0
- package/dist/{index-BQJIJlK7.d.cts → index-CQd4bo3G.d.cts} +3 -3
- package/dist/{index-CWNLnSOL.d.cts → index-CdYdwxpQ.d.cts} +1 -1
- package/dist/{index-BFdNOmPJ.d.cts → index-Ce-WMV7c.d.cts} +1 -1
- package/dist/{index-TfXqwuac.d.ts → index-CojSGJ7m.d.ts} +1 -1
- package/dist/{index-1Vu2cRQ2.d.ts → index-CsFIp7OO.d.ts} +1 -1
- package/dist/{index-D1Izm7qt.d.ts → index-D2z7RiAM.d.ts} +358 -2
- package/dist/{index-DHw08dUc.d.ts → index-D82CmjMP.d.ts} +1 -1
- package/dist/{index-BN0ubxjZ.d.ts → index-DZaPkUnC.d.ts} +3 -3
- package/dist/{index-D5eihzwM.d.cts → index-KCB2q1-8.d.cts} +1 -1
- package/dist/{index-A5MimeQk.d.ts → index-Kq3rbG0u.d.ts} +1 -1
- package/dist/index.cjs +1094 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +199 -10
- package/dist/index.d.ts +199 -10
- package/dist/index.mjs +1091 -111
- package/dist/index.mjs.map +1 -1
- package/dist/lane/index.cjs +737 -110
- package/dist/lane/index.cjs.map +1 -1
- package/dist/lane/index.mjs +737 -110
- package/dist/lane/index.mjs.map +1 -1
- package/dist/match/index.d.cts +4 -4
- package/dist/match/index.d.ts +4 -4
- package/dist/pem/index.d.cts +2 -2
- package/dist/pem/index.d.ts +2 -2
- package/dist/pilot/index.d.cts +2 -2
- package/dist/pilot/index.d.ts +2 -2
- package/dist/precheck/index.d.cts +2 -2
- package/dist/precheck/index.d.ts +2 -2
- package/dist/produce/index.d.cts +2 -2
- package/dist/produce/index.d.ts +2 -2
- package/dist/sigh/index.d.cts +2 -2
- package/dist/sigh/index.d.ts +2 -2
- package/package.json +3 -1
- package/dist/index-DfirmFbC.d.ts +0 -32
- package/dist/index-lt819Jgj.d.cts +0 -32
package/dist/client/index.mjs
CHANGED
|
@@ -203,9 +203,9 @@ Please accept the agreement at https://developer.apple.com/account before contin
|
|
|
203
203
|
throw new Error(msg);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
async function
|
|
207
|
-
const log = config.onLog ??
|
|
208
|
-
|
|
206
|
+
async function beginLogin(config) {
|
|
207
|
+
const log = config.onLog ?? (() => {
|
|
208
|
+
});
|
|
209
209
|
log("Fetching Apple service key...");
|
|
210
210
|
const serviceKey = await fetchServiceKey();
|
|
211
211
|
const initRes = await fetch(`${AUTH_BASE}/signin?widgetKey=${serviceKey}`, {
|
|
@@ -222,27 +222,94 @@ async function loginWithAppleId(config) {
|
|
|
222
222
|
const cookieStr = Object.entries(initCookies).map(([k, v]) => k.startsWith("DES") ? `${k}="${v}"` : `${k}=${v}`).join("; ");
|
|
223
223
|
log("Starting SIRP Apple ID login...");
|
|
224
224
|
const response = await doSirp(config.email, config.password, serviceKey, cookieStr, hashcash);
|
|
225
|
-
const
|
|
225
|
+
const baseState = {
|
|
226
226
|
cookies: { ...initCookies, ...response.cookies },
|
|
227
227
|
sessionId: response.sessionId,
|
|
228
228
|
scnt: response.scnt,
|
|
229
229
|
serviceKey,
|
|
230
|
-
userEmail: config.email
|
|
231
|
-
pendingAgreements: []
|
|
230
|
+
userEmail: config.email
|
|
232
231
|
};
|
|
233
232
|
if (response.status === 403) {
|
|
234
233
|
throw new Error(`Invalid username and password combination. Used '${config.email}' as the username.`);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
await fetchOlympusSession(session);
|
|
238
|
-
} else if (response.status === 409) {
|
|
239
|
-
await handleTwoStepOrFactor(session, log, promptFn);
|
|
240
|
-
await fetchOlympusSession(session);
|
|
241
|
-
} else if (response.status === 412) {
|
|
234
|
+
}
|
|
235
|
+
if (response.status === 412) {
|
|
242
236
|
throw new Error("Need to acknowledge Apple's Apple ID and Privacy statement. Please manually log into https://appleid.apple.com.");
|
|
237
|
+
}
|
|
238
|
+
if (response.status === 200) {
|
|
239
|
+
log("Login successful (no 2FA).");
|
|
240
|
+
const session = { ...baseState, pendingAgreements: [] };
|
|
241
|
+
await finalizeSession(session, log);
|
|
242
|
+
return { kind: "logged_in", session };
|
|
243
|
+
}
|
|
244
|
+
if (response.status === 409) {
|
|
245
|
+
log("2FA required, fetching challenge...");
|
|
246
|
+
const challenge = await fetchTwoFactorChallenge(baseState);
|
|
247
|
+
return { kind: "needs_2fa", pending: baseState, challenge };
|
|
248
|
+
}
|
|
249
|
+
throw new Error(`Unexpected login response (${response.status}): ${JSON.stringify(response.body).slice(0, 500)}`);
|
|
250
|
+
}
|
|
251
|
+
async function fetchTwoFactorChallenge(pending) {
|
|
252
|
+
const r = await fetch(`${AUTH_BASE}`, { headers: buildAuthHeadersFromPending(pending) });
|
|
253
|
+
const body = await r.json();
|
|
254
|
+
const trustedPhoneNumbers = (body.trustedPhoneNumbers ?? []).map((p) => ({
|
|
255
|
+
id: p.id,
|
|
256
|
+
numberWithDialCode: p.numberWithDialCode,
|
|
257
|
+
pushMode: p.pushMode
|
|
258
|
+
}));
|
|
259
|
+
const phoneOnly = body.noTrustedDevices === true;
|
|
260
|
+
const codeLength = body.securityCode?.length ?? 6;
|
|
261
|
+
return {
|
|
262
|
+
kind: phoneOnly ? "phone_only" : "device",
|
|
263
|
+
codeLength,
|
|
264
|
+
trustedPhoneNumbers
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
async function requestSmsCode(input) {
|
|
268
|
+
await fetch(`${AUTH_BASE}/verify/phone`, {
|
|
269
|
+
method: "PUT",
|
|
270
|
+
headers: { ...buildAuthHeadersFromPending(input.pending), "Content-Type": "application/json" },
|
|
271
|
+
body: JSON.stringify({ phoneNumber: { id: input.phoneId }, mode: input.mode ?? "sms" })
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async function submitTwoFactorCode(input) {
|
|
275
|
+
const log = input.onLog ?? (() => {
|
|
276
|
+
});
|
|
277
|
+
let path;
|
|
278
|
+
let body;
|
|
279
|
+
if (input.source === "device") {
|
|
280
|
+
path = `${AUTH_BASE}/verify/trusteddevice/securitycode`;
|
|
281
|
+
body = JSON.stringify({ securityCode: { code: input.code } });
|
|
243
282
|
} else {
|
|
244
|
-
throw new Error(
|
|
283
|
+
if (input.phoneId == null) throw new Error("phoneId is required when source='phone'");
|
|
284
|
+
path = `${AUTH_BASE}/verify/phone/securitycode`;
|
|
285
|
+
body = JSON.stringify({
|
|
286
|
+
securityCode: { code: input.code },
|
|
287
|
+
phoneNumber: { id: input.phoneId },
|
|
288
|
+
mode: input.mode ?? "sms"
|
|
289
|
+
});
|
|
245
290
|
}
|
|
291
|
+
log("Submitting 2FA code...");
|
|
292
|
+
const verifyRes = await fetch(path, {
|
|
293
|
+
method: "POST",
|
|
294
|
+
headers: { ...buildAuthHeadersFromPending(input.pending), "Content-Type": "application/json" },
|
|
295
|
+
body
|
|
296
|
+
});
|
|
297
|
+
if (!verifyRes.ok) {
|
|
298
|
+
const err = await verifyRes.json().catch(() => ({}));
|
|
299
|
+
const msgs = (err?.service_errors ?? err?.serviceErrors ?? []).map((e) => e.message).filter(Boolean);
|
|
300
|
+
throw new Error(msgs.join("; ") || `Verification failed (${verifyRes.status})`);
|
|
301
|
+
}
|
|
302
|
+
const session = {
|
|
303
|
+
...input.pending,
|
|
304
|
+
cookies: { ...input.pending.cookies, ...parseCookies(verifyRes.headers) },
|
|
305
|
+
pendingAgreements: []
|
|
306
|
+
};
|
|
307
|
+
await trustSession(session);
|
|
308
|
+
await finalizeSession(session, log);
|
|
309
|
+
return session;
|
|
310
|
+
}
|
|
311
|
+
async function finalizeSession(session, log) {
|
|
312
|
+
await fetchOlympusSession(session);
|
|
246
313
|
const agreements = await fetchContractMessages(session);
|
|
247
314
|
if (agreements.length > 0) {
|
|
248
315
|
for (const msg of agreements) {
|
|
@@ -251,7 +318,53 @@ async function loginWithAppleId(config) {
|
|
|
251
318
|
}
|
|
252
319
|
session.pendingAgreements = agreements;
|
|
253
320
|
log(`Logged in as ${session.userEmail}`);
|
|
254
|
-
|
|
321
|
+
}
|
|
322
|
+
async function loginWithAppleId(config) {
|
|
323
|
+
const log = config.onLog ?? console.log;
|
|
324
|
+
const promptFn = config.onPrompt ?? defaultPrompt;
|
|
325
|
+
const result = await beginLogin({ email: config.email, password: config.password, onLog: log });
|
|
326
|
+
if (result.kind === "logged_in") return result.session;
|
|
327
|
+
const { pending, challenge } = result;
|
|
328
|
+
const phones = challenge.trustedPhoneNumbers;
|
|
329
|
+
if (challenge.kind === "device") {
|
|
330
|
+
log("Two-factor Authentication (6 digit code) is enabled for this account");
|
|
331
|
+
log("(Input 'sms' to escape this prompt and select a trusted phone number to send the code as a text message)");
|
|
332
|
+
const input = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
333
|
+
if (input.toLowerCase() === "sms") {
|
|
334
|
+
log("Please select a trusted phone number:");
|
|
335
|
+
for (let i = 0; i < phones.length; i++) log(` ${i + 1}. ${phones[i].numberWithDialCode}`);
|
|
336
|
+
const choice2 = await promptFn("Enter number: ");
|
|
337
|
+
const phone2 = phones[Math.max(0, parseInt(choice2, 10) - 1)] ?? phones[0];
|
|
338
|
+
await requestSmsCode({ pending, phoneId: phone2.id, mode: phone2.pushMode });
|
|
339
|
+
log(`Code sent to ${phone2.numberWithDialCode}`);
|
|
340
|
+
const code2 = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
341
|
+
return submitTwoFactorCode({ pending, code: code2, source: "phone", phoneId: phone2.id, mode: phone2.pushMode ?? "sms", onLog: log });
|
|
342
|
+
}
|
|
343
|
+
return submitTwoFactorCode({ pending, code: input, source: "device", onLog: log });
|
|
344
|
+
}
|
|
345
|
+
log("Two-factor Authentication (6 digit code) is enabled for this account");
|
|
346
|
+
if (phones.length === 1) {
|
|
347
|
+
const phone2 = phones[0];
|
|
348
|
+
log(`Code automatically sent to ${phone2.numberWithDialCode}`);
|
|
349
|
+
const code2 = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
350
|
+
return submitTwoFactorCode({ pending, code: code2, source: "phone", phoneId: phone2.id, mode: phone2.pushMode ?? "sms", onLog: log });
|
|
351
|
+
}
|
|
352
|
+
log("Please select a trusted phone number:");
|
|
353
|
+
for (let i = 0; i < phones.length; i++) log(` ${i + 1}. ${phones[i].numberWithDialCode}`);
|
|
354
|
+
const choice = await promptFn("Enter number: ");
|
|
355
|
+
const phone = phones[Math.max(0, parseInt(choice, 10) - 1)] ?? phones[0];
|
|
356
|
+
await requestSmsCode({ pending, phoneId: phone.id, mode: phone.pushMode });
|
|
357
|
+
log(`Code sent to ${phone.numberWithDialCode}`);
|
|
358
|
+
const code = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
359
|
+
return submitTwoFactorCode({ pending, code, source: "phone", phoneId: phone.id, mode: phone.pushMode ?? "sms", onLog: log });
|
|
360
|
+
}
|
|
361
|
+
function buildAuthHeadersFromPending(pending) {
|
|
362
|
+
const h = { "X-Apple-Widget-Key": pending.serviceKey, Accept: "application/json" };
|
|
363
|
+
if (pending.sessionId) h["X-Apple-Id-Session-Id"] = pending.sessionId;
|
|
364
|
+
if (pending.scnt) h["scnt"] = pending.scnt;
|
|
365
|
+
const c = Object.entries(pending.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
366
|
+
if (c) h["Cookie"] = c;
|
|
367
|
+
return h;
|
|
255
368
|
}
|
|
256
369
|
async function doSirp(user, password, serviceKey, cookieStr, hashcash) {
|
|
257
370
|
const client = new SRPClient(2048);
|
|
@@ -307,99 +420,6 @@ async function doSirp(user, password, serviceKey, cookieStr, hashcash) {
|
|
|
307
420
|
scnt: completeRes.headers.get("scnt") ?? ""
|
|
308
421
|
};
|
|
309
422
|
}
|
|
310
|
-
async function handleTwoStepOrFactor(session, log, promptFn) {
|
|
311
|
-
const r = await fetch(`${AUTH_BASE}`, { headers: buildAuthHeaders(session) });
|
|
312
|
-
const body = await r.json();
|
|
313
|
-
if (body.trustedDevices?.length > 0) {
|
|
314
|
-
await handleTwoStep(session, body, log, promptFn);
|
|
315
|
-
} else if (body.trustedPhoneNumbers?.length > 0) {
|
|
316
|
-
await handleTwoFactor(session, body, log, promptFn);
|
|
317
|
-
} else {
|
|
318
|
-
throw new Error("2FA required but no trusted devices or phone numbers found.");
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
async function handleTwoFactor(session, authBody, log, promptFn) {
|
|
322
|
-
log("Two-factor Authentication (6 digit code) is enabled for this account");
|
|
323
|
-
const codeLength = authBody.securityCode?.length ?? 6;
|
|
324
|
-
const phones = authBody.trustedPhoneNumbers ?? [];
|
|
325
|
-
const noTrusted = authBody.noTrustedDevices === true;
|
|
326
|
-
let codeType;
|
|
327
|
-
let reqBody;
|
|
328
|
-
if (noTrusted && phones.length === 1) {
|
|
329
|
-
const phone = phones[0];
|
|
330
|
-
log(`Code automatically sent to ${phone.numberWithDialCode}`);
|
|
331
|
-
const code = await promptFn(`Please enter the ${codeLength} digit code you received at ${phone.numberWithDialCode}: `);
|
|
332
|
-
codeType = "phone";
|
|
333
|
-
reqBody = JSON.stringify({ securityCode: { code }, phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" });
|
|
334
|
-
} else if (noTrusted) {
|
|
335
|
-
const phone = await choosePhone(phones, log, promptFn);
|
|
336
|
-
await requestPhoneCode(session, phone);
|
|
337
|
-
log(`Successfully requested text message to ${phone.numberWithDialCode}`);
|
|
338
|
-
const code = await promptFn(`Please enter the ${codeLength} digit code: `);
|
|
339
|
-
codeType = "phone";
|
|
340
|
-
reqBody = JSON.stringify({ securityCode: { code }, phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" });
|
|
341
|
-
} else {
|
|
342
|
-
log("(Input 'sms' to escape this prompt and select a trusted phone number to send the code as a text message)");
|
|
343
|
-
const input = await promptFn(`Please enter the ${codeLength} digit code: `);
|
|
344
|
-
if (input.toLowerCase() === "sms") {
|
|
345
|
-
const phone = await choosePhone(phones, log, promptFn);
|
|
346
|
-
await requestPhoneCode(session, phone);
|
|
347
|
-
const code = await promptFn(`Please enter the ${codeLength} digit code sent to ${phone.numberWithDialCode}: `);
|
|
348
|
-
codeType = "phone";
|
|
349
|
-
reqBody = JSON.stringify({ securityCode: { code }, phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" });
|
|
350
|
-
} else {
|
|
351
|
-
codeType = "trusteddevice";
|
|
352
|
-
reqBody = JSON.stringify({ securityCode: { code: input } });
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
log("Requesting session...");
|
|
356
|
-
const verifyRes = await fetch(`${AUTH_BASE}/verify/${codeType}/securitycode`, {
|
|
357
|
-
method: "POST",
|
|
358
|
-
headers: { ...buildAuthHeaders(session), "Content-Type": "application/json" },
|
|
359
|
-
body: reqBody
|
|
360
|
-
});
|
|
361
|
-
if (!verifyRes.ok) {
|
|
362
|
-
const err = await verifyRes.json().catch(() => ({}));
|
|
363
|
-
const msgs = (err?.service_errors ?? err?.serviceErrors ?? []).map((e) => e.message).filter(Boolean);
|
|
364
|
-
throw new Error(msgs.join("; ") || `Verification failed (${verifyRes.status})`);
|
|
365
|
-
}
|
|
366
|
-
Object.assign(session.cookies, parseCookies(verifyRes.headers));
|
|
367
|
-
await trustSession(session);
|
|
368
|
-
}
|
|
369
|
-
async function handleTwoStep(session, authBody, log, promptFn) {
|
|
370
|
-
log("Two-step Verification (4 digit code) is enabled for this account");
|
|
371
|
-
const devices = authBody.trustedDevices ?? [];
|
|
372
|
-
log("Please select a trusted device:");
|
|
373
|
-
for (let i = 0; i < devices.length; i++) {
|
|
374
|
-
log(` ${i + 1}. ${devices[i].name} ${devices[i].modelName ?? "SMS"} (${devices[i].id})`);
|
|
375
|
-
}
|
|
376
|
-
const choice = await promptFn("Enter device number: ");
|
|
377
|
-
const device = devices[Math.max(0, parseInt(choice, 10) - 1)] ?? devices[0];
|
|
378
|
-
await fetch(`${AUTH_BASE}/verify/device/${device.id}/securitycode`, { method: "PUT", headers: buildAuthHeaders(session) });
|
|
379
|
-
log("Successfully requested notification");
|
|
380
|
-
const code = await promptFn("Please enter the 4 digit code: ");
|
|
381
|
-
const verifyRes = await fetch(`${AUTH_BASE}/verify/phone/securitycode`, {
|
|
382
|
-
method: "POST",
|
|
383
|
-
headers: { ...buildAuthHeaders(session), "Content-Type": "application/json" },
|
|
384
|
-
body: JSON.stringify({ phoneNumber: { id: device.id }, securityCode: { code }, mode: "sms" })
|
|
385
|
-
});
|
|
386
|
-
if (!verifyRes.ok) throw new Error("Incorrect verification code.");
|
|
387
|
-
Object.assign(session.cookies, parseCookies(verifyRes.headers));
|
|
388
|
-
await trustSession(session);
|
|
389
|
-
}
|
|
390
|
-
async function choosePhone(phones, log, promptFn) {
|
|
391
|
-
log("Please select a trusted phone number:");
|
|
392
|
-
for (let i = 0; i < phones.length; i++) log(` ${i + 1}. ${phones[i].numberWithDialCode}`);
|
|
393
|
-
const choice = await promptFn("Enter number: ");
|
|
394
|
-
return phones[Math.max(0, parseInt(choice, 10) - 1)] ?? phones[0];
|
|
395
|
-
}
|
|
396
|
-
async function requestPhoneCode(session, phone) {
|
|
397
|
-
await fetch(`${AUTH_BASE}/verify/phone`, {
|
|
398
|
-
method: "PUT",
|
|
399
|
-
headers: { ...buildAuthHeaders(session), "Content-Type": "application/json" },
|
|
400
|
-
body: JSON.stringify({ phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" })
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
423
|
async function trustSession(session) {
|
|
404
424
|
const r = await fetch(`${AUTH_BASE}/2sv/trust`, { headers: buildAuthHeaders(session) });
|
|
405
425
|
Object.assign(session.cookies, parseCookies(r.headers));
|
|
@@ -2262,6 +2282,264 @@ var PortalClient = class _PortalClient {
|
|
|
2262
2282
|
async init() {
|
|
2263
2283
|
await this.post("account/listTeams.action", {});
|
|
2264
2284
|
}
|
|
2285
|
+
/**
|
|
2286
|
+
* JSON POST — different content type than the standard form-encoded
|
|
2287
|
+
* `post()`. Used by the App Store Connect API key endpoints
|
|
2288
|
+
* (`account/auth/key/v2/create`), which Spaceship discovered take a
|
|
2289
|
+
* JSON body even though every other portal mutation is form-encoded.
|
|
2290
|
+
*
|
|
2291
|
+
* Like the form-encoded `post()`, this also runs the response through
|
|
2292
|
+
* `checkPortalResponse` — Apple returns HTTP 200 even for errors and
|
|
2293
|
+
* encodes the error in `resultCode`/`userString` fields, so a raw
|
|
2294
|
+
* status check would silently miss real failures.
|
|
2295
|
+
*/
|
|
2296
|
+
async postJson(path, body) {
|
|
2297
|
+
const headers = {
|
|
2298
|
+
Cookie: this.cookieStr,
|
|
2299
|
+
"Content-Type": "application/json",
|
|
2300
|
+
Accept: "application/json"
|
|
2301
|
+
};
|
|
2302
|
+
if (this.csrf) {
|
|
2303
|
+
headers["csrf"] = this.csrf;
|
|
2304
|
+
headers["csrf_ts"] = this.csrfTs;
|
|
2305
|
+
}
|
|
2306
|
+
console.log(`[portal] POST(json) ${path}`);
|
|
2307
|
+
const res = await fetch(`${PORTAL_BASE}/${path}`, {
|
|
2308
|
+
method: "POST",
|
|
2309
|
+
headers,
|
|
2310
|
+
body: JSON.stringify(body)
|
|
2311
|
+
});
|
|
2312
|
+
if (res.headers.get("csrf")) {
|
|
2313
|
+
this.csrf = res.headers.get("csrf");
|
|
2314
|
+
this.csrfTs = res.headers.get("csrf_ts") ?? "";
|
|
2315
|
+
}
|
|
2316
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
2317
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
2318
|
+
if (m && !this.cookieStr.includes(m[1] + "=")) this.cookieStr += "; " + m[1] + "=" + m[2];
|
|
2319
|
+
}
|
|
2320
|
+
const text = await res.text();
|
|
2321
|
+
let data = null;
|
|
2322
|
+
try {
|
|
2323
|
+
data = text ? JSON.parse(text) : null;
|
|
2324
|
+
} catch {
|
|
2325
|
+
}
|
|
2326
|
+
console.log(`[portal] POST(json) ${path} \u2192 ${res.status} ${text.slice(0, 400)}`);
|
|
2327
|
+
checkPortalResponse(data, this.session);
|
|
2328
|
+
return { status: res.status, body: data, rawText: text };
|
|
2329
|
+
}
|
|
2330
|
+
/**
|
|
2331
|
+
* GET helper for the portal endpoints that take query parameters
|
|
2332
|
+
* (currently just `account/auth/key/download`). Returns the raw text
|
|
2333
|
+
* since download endpoints can return PEMs or JSON depending on Apple's
|
|
2334
|
+
* mood — caller decides how to parse.
|
|
2335
|
+
*/
|
|
2336
|
+
async getRaw(path, params = {}) {
|
|
2337
|
+
const url = new URL(`${PORTAL_BASE}/${path}`);
|
|
2338
|
+
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
2339
|
+
const headers = {
|
|
2340
|
+
Cookie: this.cookieStr,
|
|
2341
|
+
Accept: "application/json, text/plain, application/x-pem-file, */*"
|
|
2342
|
+
};
|
|
2343
|
+
if (this.csrf) {
|
|
2344
|
+
headers["csrf"] = this.csrf;
|
|
2345
|
+
headers["csrf_ts"] = this.csrfTs;
|
|
2346
|
+
}
|
|
2347
|
+
console.log(`[portal] GET ${url.pathname}${url.search}`);
|
|
2348
|
+
const res = await fetch(url.toString(), { headers });
|
|
2349
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
2350
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
2351
|
+
if (m && !this.cookieStr.includes(m[1] + "=")) this.cookieStr += "; " + m[1] + "=" + m[2];
|
|
2352
|
+
}
|
|
2353
|
+
const text = await res.text();
|
|
2354
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
2355
|
+
console.log(`[portal] GET ${url.pathname} \u2192 ${res.status} ${contentType} ${text.length}b`);
|
|
2356
|
+
return { status: res.status, rawText: text, contentType };
|
|
2357
|
+
}
|
|
2358
|
+
// ── App Store Connect API Keys (.p8) ────────────────────────────────────
|
|
2359
|
+
/**
|
|
2360
|
+
* Create an App Store Connect API key via the developer portal's
|
|
2361
|
+
* `account/auth/key/v2/create` endpoint. Reverse-engineered from the
|
|
2362
|
+
* _current_ @expo/apple-utils npm package (v2.1.21), which is what
|
|
2363
|
+
* EAS CLI uses to manage Apple credentials in production.
|
|
2364
|
+
*
|
|
2365
|
+
* This differs from older published reverse-engineering guides:
|
|
2366
|
+
* • URL uses the `/v2/create` suffix (Apple kept it)
|
|
2367
|
+
* • Field is `serviceConfigurations`, shape is an object keyed by
|
|
2368
|
+
* service id (NOT `serviceConfigurationsRequests: [...]` array)
|
|
2369
|
+
* • Body REQUIRES `scope: "team"`
|
|
2370
|
+
* • Needs a scope-specific CSRF warmup via the `keys` endpoint
|
|
2371
|
+
* before the create call (EAS's `ensureCSRFAsync("keys", …)`)
|
|
2372
|
+
*
|
|
2373
|
+
* For an App Store Connect API key (PUBLIC_API, used by altool for
|
|
2374
|
+
* TestFlight uploads), `serviceConfigurations` is an empty object `{}`.
|
|
2375
|
+
* For an APNs auth key, it's `{ "U27F4V844T": [] }`. For MusicKit:
|
|
2376
|
+
* `{ "6A7HVUVQ3M": [musicId] }`, etc.
|
|
2377
|
+
*
|
|
2378
|
+
* Apple's name validator rejects parentheses, brackets, and most
|
|
2379
|
+
* punctuation — sanitize to alphanumeric + space + dash + underscore
|
|
2380
|
+
* + period and collapse whitespace.
|
|
2381
|
+
*/
|
|
2382
|
+
async createApiKey(rawName, serviceConfigurations = {}) {
|
|
2383
|
+
const name = rawName.replace(/[^A-Za-z0-9 _\-.]/g, " ").replace(/\s+/g, " ").trim().slice(0, 50);
|
|
2384
|
+
if (!name) throw new Error("createApiKey: name is empty after sanitization");
|
|
2385
|
+
try {
|
|
2386
|
+
await this.listApiKeys();
|
|
2387
|
+
} catch {
|
|
2388
|
+
}
|
|
2389
|
+
const body = {
|
|
2390
|
+
teamId: this.teamId,
|
|
2391
|
+
name,
|
|
2392
|
+
serviceConfigurations,
|
|
2393
|
+
scope: "team"
|
|
2394
|
+
};
|
|
2395
|
+
const result = await this.postJson("account/auth/key/v2/create", body);
|
|
2396
|
+
const created = result.body?.keys?.[0] ?? result.body?.key ?? result.body?.data ?? result.body;
|
|
2397
|
+
const keyId = created?.keyId ?? created?.id ?? created?.kid ?? created?.attributes?.kid;
|
|
2398
|
+
if (!keyId) {
|
|
2399
|
+
throw new Error(`createApiKey: no key id in response. Body: ${result.rawText.slice(0, 400)}`);
|
|
2400
|
+
}
|
|
2401
|
+
return { keyId, raw: created };
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Fetch a single API key by id via `account/auth/key/get`. Reverse-
|
|
2405
|
+
* engineered from Spaceship's `get_key`. Returns the raw key record so
|
|
2406
|
+
* the caller can extract whatever fields it needs (e.g. issuerId).
|
|
2407
|
+
*
|
|
2408
|
+
* Form-encoded POST — same shape as every other PortalClient mutation
|
|
2409
|
+
* except the JSON `create` endpoint.
|
|
2410
|
+
*/
|
|
2411
|
+
async getApiKey(keyId) {
|
|
2412
|
+
const data = await this.post("account/auth/key/get", {
|
|
2413
|
+
teamId: this.teamId,
|
|
2414
|
+
keyId
|
|
2415
|
+
});
|
|
2416
|
+
return data?.keys?.[0] ?? data?.key ?? data?.data ?? data;
|
|
2417
|
+
}
|
|
2418
|
+
/**
|
|
2419
|
+
* Revoke an existing key. Form-encoded POST per Spaceship's
|
|
2420
|
+
* `revoke_key!`. Used for cleaning up orphan keys created during
|
|
2421
|
+
* failed wizard runs.
|
|
2422
|
+
*/
|
|
2423
|
+
async revokeApiKey(keyId) {
|
|
2424
|
+
await this.post("account/auth/key/revoke", {
|
|
2425
|
+
teamId: this.teamId,
|
|
2426
|
+
keyId
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
// ── APNs Authentication Keys (.p8) ──────────────────────────────────────
|
|
2430
|
+
/** Apple's hardcoded service id for APNs auth keys (from Spaceship). */
|
|
2431
|
+
static APNS_SERVICE_ID = "U27F4V844T";
|
|
2432
|
+
/**
|
|
2433
|
+
* Create an APNs Authentication Key (.p8) via the developer portal.
|
|
2434
|
+
*
|
|
2435
|
+
* Apple requires BOTH `serviceConfigurations` (the map) AND
|
|
2436
|
+
* `serviceConfigurationsRequests` (the array of full config objects)
|
|
2437
|
+
* in the v2/create body. Just sending the map alone results in
|
|
2438
|
+
* "No value was provided for the parameter 'serviceConfigurations'".
|
|
2439
|
+
*
|
|
2440
|
+
* The exact body comes from @expo/apple-utils v2.1.21 — both fields
|
|
2441
|
+
* are produced by separate functions (`d` for the map, `h` for the
|
|
2442
|
+
* array) and merged into the create payload.
|
|
2443
|
+
*/
|
|
2444
|
+
async createApnsAuthKey(rawName) {
|
|
2445
|
+
const name = rawName.replace(/[^A-Za-z0-9 _\-.]/g, " ").replace(/\s+/g, " ").trim().slice(0, 50);
|
|
2446
|
+
if (!name) throw new Error("createApnsAuthKey: name is empty after sanitization");
|
|
2447
|
+
try {
|
|
2448
|
+
await this.listApiKeys();
|
|
2449
|
+
} catch {
|
|
2450
|
+
}
|
|
2451
|
+
const body = {
|
|
2452
|
+
teamId: this.teamId,
|
|
2453
|
+
name,
|
|
2454
|
+
serviceConfigurations: {
|
|
2455
|
+
[_PortalClient.APNS_SERVICE_ID]: []
|
|
2456
|
+
},
|
|
2457
|
+
serviceConfigurationsRequests: [
|
|
2458
|
+
{
|
|
2459
|
+
isNew: true,
|
|
2460
|
+
serviceId: _PortalClient.APNS_SERVICE_ID,
|
|
2461
|
+
identifiers: {},
|
|
2462
|
+
environment: "all",
|
|
2463
|
+
scope: "team"
|
|
2464
|
+
}
|
|
2465
|
+
],
|
|
2466
|
+
scope: "team"
|
|
2467
|
+
};
|
|
2468
|
+
const result = await this.postJson("account/auth/key/v2/create", body);
|
|
2469
|
+
const created = result.body?.keys?.[0];
|
|
2470
|
+
if (!created?.keyId) {
|
|
2471
|
+
throw new Error(`createApnsAuthKey: no key id in response. Body: ${result.rawText.slice(0, 400)}`);
|
|
2472
|
+
}
|
|
2473
|
+
const pem = await this.downloadApiKey(created.keyId);
|
|
2474
|
+
return { keyId: created.keyId, pem, raw: created };
|
|
2475
|
+
}
|
|
2476
|
+
/**
|
|
2477
|
+
* Find existing APNs auth keys in the team. Used by the wizard to
|
|
2478
|
+
* detect "you already have one" cases and offer to reuse rather than
|
|
2479
|
+
* proliferate keys.
|
|
2480
|
+
*/
|
|
2481
|
+
async listApnsAuthKeys() {
|
|
2482
|
+
const list = await this.listApiKeys();
|
|
2483
|
+
return (list.keys ?? []).filter(
|
|
2484
|
+
(k) => (k.services ?? []).some((s) => s.id === _PortalClient.APNS_SERVICE_ID || /apns/i.test(s.name ?? ""))
|
|
2485
|
+
).map((k) => ({
|
|
2486
|
+
keyId: k.keyId,
|
|
2487
|
+
keyName: k.keyName,
|
|
2488
|
+
canDownload: Boolean(k.canDownload)
|
|
2489
|
+
}));
|
|
2490
|
+
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Download an existing App Store Connect API key as PEM. Spaceship's
|
|
2493
|
+
* `download_key` endpoint — GET with teamId + keyId in query string.
|
|
2494
|
+
* Returns the raw .p8 PEM text. Apple shows the .p8 exactly once
|
|
2495
|
+
* (after creation), so call this immediately after createApiKey.
|
|
2496
|
+
*/
|
|
2497
|
+
async downloadApiKey(keyId) {
|
|
2498
|
+
const { status, rawText, contentType } = await this.getRaw("account/auth/key/download", {
|
|
2499
|
+
teamId: this.teamId,
|
|
2500
|
+
keyId
|
|
2501
|
+
});
|
|
2502
|
+
if (status !== 200) {
|
|
2503
|
+
throw new Error(`downloadApiKey failed (${status}): ${rawText.slice(0, 200)}`);
|
|
2504
|
+
}
|
|
2505
|
+
if (rawText.includes("BEGIN PRIVATE KEY")) return rawText;
|
|
2506
|
+
if (contentType.includes("json")) {
|
|
2507
|
+
try {
|
|
2508
|
+
const parsed = JSON.parse(rawText);
|
|
2509
|
+
const candidates = [
|
|
2510
|
+
parsed?.privateKey,
|
|
2511
|
+
parsed?.key?.privateKey,
|
|
2512
|
+
parsed?.keys?.[0]?.privateKey,
|
|
2513
|
+
parsed?.data?.attributes?.privateKey,
|
|
2514
|
+
parsed?.value
|
|
2515
|
+
];
|
|
2516
|
+
for (const c of candidates) {
|
|
2517
|
+
if (typeof c === "string" && c.includes("BEGIN PRIVATE KEY")) return c;
|
|
2518
|
+
}
|
|
2519
|
+
} catch {
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
throw new Error(`downloadApiKey returned no PEM. Content-Type=${contentType} body=${rawText.slice(0, 300)}`);
|
|
2523
|
+
}
|
|
2524
|
+
/**
|
|
2525
|
+
* List existing API keys via the portal. Used to discover the team's
|
|
2526
|
+
* issuer id — every key in the team shares the same issuer id, and
|
|
2527
|
+
* altool needs it alongside the key id and .p8 file.
|
|
2528
|
+
*
|
|
2529
|
+
* Form-encoded POST (NOT JSON), with pagination params, per Spaceship's
|
|
2530
|
+
* `list_keys` method. JSON returned 415 from this endpoint.
|
|
2531
|
+
*/
|
|
2532
|
+
async listApiKeys() {
|
|
2533
|
+
const data = await this.post("account/auth/key/list", {
|
|
2534
|
+
teamId: this.teamId,
|
|
2535
|
+
pageNumber: "1",
|
|
2536
|
+
pageSize: "500",
|
|
2537
|
+
sort: "name=asc"
|
|
2538
|
+
});
|
|
2539
|
+
const keys = data?.keys ?? [];
|
|
2540
|
+
const issuerId = data?.issuerId ?? data?.issuer ?? data?.team?.issuerId ?? keys[0]?.issuerId ?? keys[0]?.issuer;
|
|
2541
|
+
return { keys, issuerId };
|
|
2542
|
+
}
|
|
2265
2543
|
async post(path, params) {
|
|
2266
2544
|
const body = new URLSearchParams();
|
|
2267
2545
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -2329,6 +2607,31 @@ var PortalClient = class _PortalClient {
|
|
|
2329
2607
|
async deleteAppId(appIdId) {
|
|
2330
2608
|
await this.post("account/ios/identifiers/deleteAppId.action", { teamId: this.teamId, appIdId });
|
|
2331
2609
|
}
|
|
2610
|
+
/**
|
|
2611
|
+
* Toggle a capability (a.k.a. "service") on a bundle ID. Mirrors
|
|
2612
|
+
* Spaceship::Portal's `update_service` — the legacy portal endpoint
|
|
2613
|
+
* still works and is the only session-cookie-authenticated way to flip
|
|
2614
|
+
* capabilities like Push Notifications and Sign in with Apple from
|
|
2615
|
+
* outside the Apple Developer web UI.
|
|
2616
|
+
*
|
|
2617
|
+
* Common service codes (from Spaceship portal/portal_client.rb):
|
|
2618
|
+
* push → push notifications
|
|
2619
|
+
* APG3427HIY → Sign in with Apple
|
|
2620
|
+
* IAD53UNK2F → in-app purchase
|
|
2621
|
+
* homeKit → HomeKit
|
|
2622
|
+
* healthKit → HealthKit
|
|
2623
|
+
*
|
|
2624
|
+
* @param featureType Apple's internal capability key (string code or short name)
|
|
2625
|
+
* @param enabled true → turn on, false → turn off
|
|
2626
|
+
*/
|
|
2627
|
+
async setBundleCapability(params) {
|
|
2628
|
+
await this.post("account/ios/identifiers/updateAppService.action", {
|
|
2629
|
+
teamId: this.teamId,
|
|
2630
|
+
displayId: params.appIdId,
|
|
2631
|
+
featureType: params.featureType,
|
|
2632
|
+
featureValue: params.enabled ? "on" : "off"
|
|
2633
|
+
});
|
|
2634
|
+
}
|
|
2332
2635
|
// ── Certificates ───────────────────────────────────────────────────────
|
|
2333
2636
|
async listCertificates(types) {
|
|
2334
2637
|
const iosTypes = types ?? [
|
|
@@ -2346,12 +2649,21 @@ var PortalClient = class _PortalClient {
|
|
|
2346
2649
|
return data.certRequests ?? [];
|
|
2347
2650
|
}
|
|
2348
2651
|
async listPushCertificates() {
|
|
2652
|
+
const types = Array.from(
|
|
2653
|
+
/* @__PURE__ */ new Set([
|
|
2654
|
+
_PortalClient.CERT_TYPES.IOS_PRODUCTION_PUSH,
|
|
2655
|
+
_PortalClient.CERT_TYPES.IOS_DEVELOPMENT_PUSH,
|
|
2656
|
+
// Legacy push codes from OLDER_IOS_CERTIFICATE_TYPES
|
|
2657
|
+
"3BQKVH9I2X",
|
|
2658
|
+
"BKLRAVXMGM"
|
|
2659
|
+
])
|
|
2660
|
+
);
|
|
2349
2661
|
const data = await this.post("account/ios/certificate/listCertRequests.action", {
|
|
2350
2662
|
teamId: this.teamId,
|
|
2351
2663
|
pageSize: "500",
|
|
2352
2664
|
pageNumber: "1",
|
|
2353
2665
|
sort: "certRequestStatusCode=asc",
|
|
2354
|
-
types:
|
|
2666
|
+
types: types.join(",")
|
|
2355
2667
|
});
|
|
2356
2668
|
return data.certRequests ?? [];
|
|
2357
2669
|
}
|
|
@@ -2491,6 +2803,310 @@ var PortalClient = class _PortalClient {
|
|
|
2491
2803
|
];
|
|
2492
2804
|
};
|
|
2493
2805
|
|
|
2806
|
+
// src/client/iris.ts
|
|
2807
|
+
var IRIS_BASE = "https://appstoreconnect.apple.com/iris/v1";
|
|
2808
|
+
var IrisClient = class {
|
|
2809
|
+
constructor(session) {
|
|
2810
|
+
this.session = session;
|
|
2811
|
+
this.cookieStr = Object.entries(session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
2812
|
+
}
|
|
2813
|
+
session;
|
|
2814
|
+
cookieStr;
|
|
2815
|
+
buildHeaders() {
|
|
2816
|
+
return {
|
|
2817
|
+
Cookie: this.cookieStr,
|
|
2818
|
+
Accept: "application/vnd.api+json, application/json, text/plain, */*",
|
|
2819
|
+
"Content-Type": "application/vnd.api+json",
|
|
2820
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
2821
|
+
// Mimic the App Store Connect web UI's user agent
|
|
2822
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15"
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
/**
|
|
2826
|
+
* Issue a request and absorb any new cookies (Apple rotates session
|
|
2827
|
+
* cookies on a lot of iris calls).
|
|
2828
|
+
*/
|
|
2829
|
+
async request(method, path, body) {
|
|
2830
|
+
const headers = this.buildHeaders();
|
|
2831
|
+
if (process.env.FASTNODE_DEBUG) {
|
|
2832
|
+
console.log(`[iris] ${method} ${path}${body ? ` body=${JSON.stringify(body).slice(0, 200)}` : ""}`);
|
|
2833
|
+
}
|
|
2834
|
+
const res = await fetch(`${IRIS_BASE}${path}`, {
|
|
2835
|
+
method,
|
|
2836
|
+
headers,
|
|
2837
|
+
body: body ? JSON.stringify(body) : void 0
|
|
2838
|
+
});
|
|
2839
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
2840
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
2841
|
+
if (m) {
|
|
2842
|
+
this.session.cookies[m[1]] = m[2];
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
this.cookieStr = Object.entries(this.session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
2846
|
+
const text = await res.text();
|
|
2847
|
+
let parsed = null;
|
|
2848
|
+
try {
|
|
2849
|
+
parsed = text ? JSON.parse(text) : null;
|
|
2850
|
+
} catch {
|
|
2851
|
+
}
|
|
2852
|
+
if (process.env.FASTNODE_DEBUG) {
|
|
2853
|
+
console.log(`[iris] \u2192 ${res.status} ${text.slice(0, 300)}`);
|
|
2854
|
+
}
|
|
2855
|
+
return { status: res.status, body: parsed, rawText: text };
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* List existing API keys. Used both as a sanity check (the user has
|
|
2859
|
+
* permission) and to discover the team's issuer id (which is the same
|
|
2860
|
+
* for every key in the team and is needed by altool).
|
|
2861
|
+
*
|
|
2862
|
+
* Important: Apple's iris endpoint rejects most query parameters with
|
|
2863
|
+
* `PARAMETER_ERROR.INVALID`. Call with no params and let the API return
|
|
2864
|
+
* its default page.
|
|
2865
|
+
*/
|
|
2866
|
+
async listApiKeys() {
|
|
2867
|
+
const { status, body, rawText } = await this.request("GET", "/apiKeys");
|
|
2868
|
+
if (status === 403) {
|
|
2869
|
+
throw new IrisAuthError(
|
|
2870
|
+
"You don't have permission to manage App Store Connect API keys (this requires the Account Holder or Admin role)."
|
|
2871
|
+
);
|
|
2872
|
+
}
|
|
2873
|
+
if (status >= 400 || !body) {
|
|
2874
|
+
throw new Error(`iris listApiKeys failed (${status}): ${rawText.slice(0, 200)}`);
|
|
2875
|
+
}
|
|
2876
|
+
const issuerId = body?.meta?.issuerId ?? body?.data?.[0]?.attributes?.issuerId;
|
|
2877
|
+
const keys = (body.data ?? []).map((d) => ({
|
|
2878
|
+
id: d.id,
|
|
2879
|
+
kid: d.attributes?.kid ?? d.id,
|
|
2880
|
+
nickname: d.attributes?.nickname ?? "",
|
|
2881
|
+
issuerId: d.attributes?.issuerId ?? issuerId,
|
|
2882
|
+
roles: d.attributes?.roles ?? [],
|
|
2883
|
+
allAppsVisible: d.attributes?.allAppsVisible ?? true
|
|
2884
|
+
}));
|
|
2885
|
+
return { keys, issuerId };
|
|
2886
|
+
}
|
|
2887
|
+
/**
|
|
2888
|
+
* Create a new API key. Apple returns the .p8 PEM exactly once in the
|
|
2889
|
+
* create response — capture it immediately or the key is dead weight.
|
|
2890
|
+
*
|
|
2891
|
+
* `keyType` is required by Apple's iris API:
|
|
2892
|
+
* • PUBLIC_API — the standard team-wide API key (what TestFlight uploads need)
|
|
2893
|
+
* • MARKETING_API — for App Analytics access only
|
|
2894
|
+
*/
|
|
2895
|
+
async createApiKey(input) {
|
|
2896
|
+
const requestBody = {
|
|
2897
|
+
data: {
|
|
2898
|
+
type: "apiKeys",
|
|
2899
|
+
attributes: {
|
|
2900
|
+
nickname: input.nickname,
|
|
2901
|
+
roles: input.roles ?? ["APP_MANAGER"],
|
|
2902
|
+
allAppsVisible: input.allAppsVisible ?? true,
|
|
2903
|
+
keyType: input.keyType ?? "PUBLIC_API"
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
};
|
|
2907
|
+
console.log("[iris] createApiKey request:", JSON.stringify(requestBody));
|
|
2908
|
+
const { status, body, rawText } = await this.request("POST", "/apiKeys", requestBody);
|
|
2909
|
+
console.log(`[iris] createApiKey response: ${status} ${rawText.slice(0, 800)}`);
|
|
2910
|
+
if (status === 403) {
|
|
2911
|
+
throw new IrisAuthError(
|
|
2912
|
+
"You don't have permission to create App Store Connect API keys (this requires the Account Holder or Admin role)."
|
|
2913
|
+
);
|
|
2914
|
+
}
|
|
2915
|
+
if (status >= 400 || !body) {
|
|
2916
|
+
const msg = body?.errors?.[0]?.detail ?? body?.errors?.[0]?.title ?? rawText.slice(0, 300) ?? `iris createApiKey failed (${status})`;
|
|
2917
|
+
throw new Error(msg);
|
|
2918
|
+
}
|
|
2919
|
+
const data = body.data ?? body;
|
|
2920
|
+
if (!data?.id) {
|
|
2921
|
+
throw new Error(`iris createApiKey returned no key id. Raw response: ${rawText.slice(0, 400)}`);
|
|
2922
|
+
}
|
|
2923
|
+
const key = {
|
|
2924
|
+
id: data.id,
|
|
2925
|
+
kid: data.attributes?.kid ?? data.id,
|
|
2926
|
+
nickname: data.attributes?.nickname ?? input.nickname,
|
|
2927
|
+
privateKey: data.attributes?.privateKey,
|
|
2928
|
+
issuerId: data.attributes?.issuerId,
|
|
2929
|
+
roles: data.attributes?.roles ?? input.roles ?? ["APP_MANAGER"],
|
|
2930
|
+
allAppsVisible: data.attributes?.allAppsVisible ?? true
|
|
2931
|
+
};
|
|
2932
|
+
return key;
|
|
2933
|
+
}
|
|
2934
|
+
/**
|
|
2935
|
+
* Fetch the .p8 PEM AND the team's issuer id for a previously-created
|
|
2936
|
+
* ASC API key. Both come back in a single request via:
|
|
2937
|
+
*
|
|
2938
|
+
* GET /iris/v1/apiKeys/{id}?fields[apiKeys]=privateKey&include=provider
|
|
2939
|
+
*
|
|
2940
|
+
* Sparse fieldset requesting ONLY `privateKey` is the magic that makes
|
|
2941
|
+
* Apple actually include the (base64-encoded) PEM in the response —
|
|
2942
|
+
* the default view returns `privateKey: null`. The `include=provider`
|
|
2943
|
+
* pulls the team's contentProvider record into `included[]`, and its
|
|
2944
|
+
* `id` field IS the issuer id altool needs (a UUID like
|
|
2945
|
+
* `cfadaf94-44ca-4c2c-8fa6-ecc28d3c7d0d`).
|
|
2946
|
+
*
|
|
2947
|
+
* Reverse-engineered from @expo/apple-utils v2.1.21 (the package that
|
|
2948
|
+
* powers EAS CLI), specifically the `ApiKey.downloadAsync` method
|
|
2949
|
+
* combined with `ApiKey.infoAsync` reading `provider?.id`.
|
|
2950
|
+
*
|
|
2951
|
+
* Returns `{ pem, issuerId }`, or `null` if Apple won't return the
|
|
2952
|
+
* private key (typically because the key was already downloaded once).
|
|
2953
|
+
*/
|
|
2954
|
+
async fetchApiKeyPrivateKey(keyId) {
|
|
2955
|
+
try {
|
|
2956
|
+
const url = `${IRIS_BASE}/apiKeys/${keyId}?fields%5BapiKeys%5D=privateKey&include=provider`;
|
|
2957
|
+
const res = await fetch(url, {
|
|
2958
|
+
headers: {
|
|
2959
|
+
...this.buildHeaders(),
|
|
2960
|
+
Accept: "application/vnd.api+json, application/json, text/plain, */*"
|
|
2961
|
+
}
|
|
2962
|
+
});
|
|
2963
|
+
const text = await res.text();
|
|
2964
|
+
console.log(`[iris] fetchApiKeyPrivateKey \u2192 ${res.status} (${text.length} bytes)`);
|
|
2965
|
+
if (res.status !== 200) {
|
|
2966
|
+
console.log(`[iris] err: ${text.slice(0, 300)}`);
|
|
2967
|
+
return null;
|
|
2968
|
+
}
|
|
2969
|
+
const body = JSON.parse(text);
|
|
2970
|
+
const encoded = body?.data?.attributes?.privateKey;
|
|
2971
|
+
if (typeof encoded !== "string" || encoded.length === 0) {
|
|
2972
|
+
console.log(`[iris] no privateKey in response`);
|
|
2973
|
+
return null;
|
|
2974
|
+
}
|
|
2975
|
+
const pem = Buffer.from(encoded, "base64").toString("utf-8");
|
|
2976
|
+
if (!pem.includes("BEGIN PRIVATE KEY")) {
|
|
2977
|
+
console.log(`[iris] decoded body didn't contain PEM marker`);
|
|
2978
|
+
return null;
|
|
2979
|
+
}
|
|
2980
|
+
const provider = (body?.included ?? []).find((i) => i.type === "contentProviders");
|
|
2981
|
+
const issuerId = provider?.id;
|
|
2982
|
+
console.log(`[iris] \u2713 PEM ${pem.length} bytes, issuerId=${issuerId ?? "(missing)"}`);
|
|
2983
|
+
return { pem, issuerId };
|
|
2984
|
+
} catch (err) {
|
|
2985
|
+
console.log(`[iris] fetchApiKeyPrivateKey error: ${err.message}`);
|
|
2986
|
+
return null;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
/**
|
|
2990
|
+
* @deprecated Kept as a fallback probe for debugging. The real path
|
|
2991
|
+
* is the sparse fieldset above — everything in this brute-force list
|
|
2992
|
+
* returned 404 during testing. Left here so we can re-verify if Apple
|
|
2993
|
+
* changes anything.
|
|
2994
|
+
*/
|
|
2995
|
+
async fetchApiKeyPrivateKeyBruteForce(keyId) {
|
|
2996
|
+
const attempts = [
|
|
2997
|
+
// Sparse fieldsets — JSON-API spec lets us request specific attributes.
|
|
2998
|
+
// Apple may exclude privateKey by default and return it only when asked.
|
|
2999
|
+
{ kind: "GET", path: `/apiKeys/${keyId}?fields[apiKeys]=privateKey,kid,issuerId,nickname,roles` },
|
|
3000
|
+
{ kind: "GET", path: `/apiKeys/${keyId}?include=privateKey` },
|
|
3001
|
+
{ kind: "GET", path: `/apiKeys/${keyId}?fields[apiKeys]=privateKey` },
|
|
3002
|
+
// Custom Accept headers — maybe Apple negotiates content type
|
|
3003
|
+
{ kind: "GET", path: `/apiKeys/${keyId}`, accept: "application/x-pem-file" },
|
|
3004
|
+
{ kind: "GET", path: `/apiKeys/${keyId}`, accept: "application/octet-stream" },
|
|
3005
|
+
{ kind: "GET", path: `/apiKeys/${keyId}/p8`, accept: "application/x-pem-file" },
|
|
3006
|
+
// POST variants — Apple sometimes uses POST to mint a download token
|
|
3007
|
+
{ kind: "POST", path: `/apiKeys/${keyId}/secrets`, body: {} },
|
|
3008
|
+
{ kind: "POST", path: `/apiKeys/${keyId}/regenerate`, body: {} },
|
|
3009
|
+
{ kind: "POST", path: `/apiKeys/${keyId}/p8`, body: {} },
|
|
3010
|
+
// Bare GET (last) — confirms canonical fields, in case my parser missed any
|
|
3011
|
+
{ kind: "GET", path: `/apiKeys/${keyId}` },
|
|
3012
|
+
// Different host — the legacy developer.apple.com user-and-access namespace
|
|
3013
|
+
{ kind: "ABSOLUTE", url: `https://appstoreconnect.apple.com/api/v1/apiKeys/${keyId}/p8` },
|
|
3014
|
+
{ kind: "ABSOLUTE", url: `https://appstoreconnect.apple.com/access/api/keys/${keyId}/download` }
|
|
3015
|
+
];
|
|
3016
|
+
for (const attempt of attempts) {
|
|
3017
|
+
try {
|
|
3018
|
+
let result;
|
|
3019
|
+
if (attempt.kind === "GET") {
|
|
3020
|
+
result = await this.requestWithHeaders("GET", attempt.path, void 0, {
|
|
3021
|
+
...attempt.accept ? { Accept: attempt.accept } : {}
|
|
3022
|
+
});
|
|
3023
|
+
console.log(`[iris] fetchApiKeyPrivateKey GET ${attempt.path}${attempt.accept ? ` accept=${attempt.accept}` : ""} \u2192 ${result.status} (${result.rawText.length} bytes)`);
|
|
3024
|
+
} else if (attempt.kind === "POST") {
|
|
3025
|
+
result = await this.request("POST", attempt.path, attempt.body);
|
|
3026
|
+
console.log(`[iris] fetchApiKeyPrivateKey POST ${attempt.path} \u2192 ${result.status} (${result.rawText.length} bytes)`);
|
|
3027
|
+
} else {
|
|
3028
|
+
result = await this.requestAbsolute("GET", attempt.url);
|
|
3029
|
+
console.log(`[iris] fetchApiKeyPrivateKey GET ${attempt.url} \u2192 ${result.status} (${result.rawText.length} bytes)`);
|
|
3030
|
+
}
|
|
3031
|
+
if (result.status === 200) {
|
|
3032
|
+
console.log(`[iris] body: ${result.rawText.slice(0, 1500)}`);
|
|
3033
|
+
}
|
|
3034
|
+
if (result.status !== 200) continue;
|
|
3035
|
+
if (result.rawText && result.rawText.includes("BEGIN PRIVATE KEY")) {
|
|
3036
|
+
console.log(`[iris] \u2713 found PEM (plain text response)`);
|
|
3037
|
+
return result.rawText;
|
|
3038
|
+
}
|
|
3039
|
+
if (result.body) {
|
|
3040
|
+
const candidates = [
|
|
3041
|
+
result.body?.data?.attributes?.privateKey,
|
|
3042
|
+
result.body?.data?.attributes?.p8,
|
|
3043
|
+
result.body?.data?.attributes?.privateKeyContent,
|
|
3044
|
+
result.body?.data?.attributes?.kpem,
|
|
3045
|
+
result.body?.data?.attributes?.secret,
|
|
3046
|
+
result.body?.data?.attributes?.keyContent,
|
|
3047
|
+
result.body?.privateKey,
|
|
3048
|
+
result.body?.p8,
|
|
3049
|
+
result.body?.value,
|
|
3050
|
+
result.body?.secret
|
|
3051
|
+
];
|
|
3052
|
+
for (const c of candidates) {
|
|
3053
|
+
if (typeof c === "string" && c.includes("BEGIN PRIVATE KEY")) {
|
|
3054
|
+
console.log(`[iris] \u2713 found PEM in JSON response`);
|
|
3055
|
+
return c;
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
} catch (err) {
|
|
3060
|
+
console.log(`[iris] fetchApiKeyPrivateKey attempt failed: ${err.message}`);
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
console.log(`[iris] fetchApiKeyPrivateKey: no working download path for key ${keyId}`);
|
|
3064
|
+
return null;
|
|
3065
|
+
}
|
|
3066
|
+
/** Internal: like request() but lets us override headers. */
|
|
3067
|
+
async requestWithHeaders(method, path, body, extraHeaders = {}) {
|
|
3068
|
+
const headers = { ...this.buildHeaders(), ...extraHeaders };
|
|
3069
|
+
const res = await fetch(`${IRIS_BASE}${path}`, {
|
|
3070
|
+
method,
|
|
3071
|
+
headers,
|
|
3072
|
+
body: body ? JSON.stringify(body) : void 0
|
|
3073
|
+
});
|
|
3074
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
3075
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
3076
|
+
if (m) this.session.cookies[m[1]] = m[2];
|
|
3077
|
+
}
|
|
3078
|
+
this.cookieStr = Object.entries(this.session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
3079
|
+
const text = await res.text();
|
|
3080
|
+
let parsed = null;
|
|
3081
|
+
try {
|
|
3082
|
+
parsed = text ? JSON.parse(text) : null;
|
|
3083
|
+
} catch {
|
|
3084
|
+
}
|
|
3085
|
+
return { status: res.status, body: parsed, rawText: text };
|
|
3086
|
+
}
|
|
3087
|
+
/** Internal: fetch an absolute URL with the session cookies. */
|
|
3088
|
+
async requestAbsolute(method, url) {
|
|
3089
|
+
const headers = this.buildHeaders();
|
|
3090
|
+
const res = await fetch(url, { method, headers });
|
|
3091
|
+
const text = await res.text();
|
|
3092
|
+
let parsed = null;
|
|
3093
|
+
try {
|
|
3094
|
+
parsed = text ? JSON.parse(text) : null;
|
|
3095
|
+
} catch {
|
|
3096
|
+
}
|
|
3097
|
+
return { status: res.status, body: parsed, rawText: text };
|
|
3098
|
+
}
|
|
3099
|
+
async deleteApiKey(keyId) {
|
|
3100
|
+
await this.request("DELETE", `/apiKeys/${keyId}`);
|
|
3101
|
+
}
|
|
3102
|
+
};
|
|
3103
|
+
var IrisAuthError = class extends Error {
|
|
3104
|
+
constructor(message) {
|
|
3105
|
+
super(message);
|
|
3106
|
+
this.name = "IrisAuthError";
|
|
3107
|
+
}
|
|
3108
|
+
};
|
|
3109
|
+
|
|
2494
3110
|
// src/client/index.ts
|
|
2495
3111
|
var AppStoreConnectClient = class {
|
|
2496
3112
|
http;
|
|
@@ -2577,6 +3193,6 @@ var AppStoreConnectClient = class {
|
|
|
2577
3193
|
}
|
|
2578
3194
|
};
|
|
2579
3195
|
|
|
2580
|
-
export { AppStoreConnectClient, AppStoreConnectError, PortalClient, ProgramLicenseAgreementError, RateLimitError, RequestClient, TokenManager, checkPortalResponse, loginWithAppleId };
|
|
3196
|
+
export { AppStoreConnectClient, AppStoreConnectError, IrisAuthError, IrisClient, PortalClient, ProgramLicenseAgreementError, RateLimitError, RequestClient, TokenManager, beginLogin, checkPortalResponse, loginWithAppleId, requestSmsCode, submitTwoFactorCode };
|
|
2581
3197
|
//# sourceMappingURL=index.mjs.map
|
|
2582
3198
|
//# sourceMappingURL=index.mjs.map
|