@sitepong/fastnode 0.1.2 → 0.2.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.
- package/README.md +148 -0
- package/dist/actions/index.cjs +758 -110
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.mjs +758 -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-owkOFNW8.d.ts → cert-e5GAgAPb.d.ts} +1 -1
- package/dist/{cert-BmJGtYtb.d.cts → cert-uLLdb5a7.d.cts} +1 -1
- package/dist/cli/index.cjs +758 -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 +758 -110
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.cjs +751 -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 +747 -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-BFdNOmPJ.d.cts → index-BN0iWhuw.d.cts} +1 -1
- package/dist/index-BNP7Bpu5.d.ts +61 -0
- package/dist/{index-1Vu2cRQ2.d.ts → index-BbY_H_f6.d.ts} +1 -1
- package/dist/{index-D6zjGlPL.d.cts → index-BgHagzj1.d.cts} +1 -1
- package/dist/{index-D5eihzwM.d.cts → index-BjkOUQcQ.d.cts} +1 -1
- package/dist/{index-D1Izm7qt.d.ts → index-BwwpAlk2.d.ts} +363 -2
- package/dist/{index-A5MimeQk.d.ts → index-C2YLoFVl.d.ts} +1 -1
- package/dist/{index-TfXqwuac.d.ts → index-CEldrbyz.d.ts} +1 -1
- package/dist/{index-BLubSlgK.d.cts → index-CdfgEZwh.d.cts} +363 -2
- package/dist/{index-DfCUVJX1.d.cts → index-Clyf4-lu.d.cts} +1 -1
- package/dist/index-CtydPNxA.d.cts +61 -0
- package/dist/{index-BQJIJlK7.d.cts → index-DHxi-QPC.d.cts} +3 -3
- package/dist/{index-BN0ubxjZ.d.ts → index-Di4Ic0EE.d.ts} +3 -3
- package/dist/{index-EcVvViW8.d.cts → index-DrCOh0Vh.d.cts} +1 -1
- package/dist/{index-B0yhu_LZ.d.ts → index-EKU_G1G5.d.ts} +1 -1
- package/dist/{index-CWNLnSOL.d.cts → index-XsMsVc3O.d.cts} +1 -1
- package/dist/{index-B9yXicrQ.d.ts → index-jeI44Q5G.d.ts} +1 -1
- package/dist/{index-DHw08dUc.d.ts → index-mddpvrRX.d.ts} +1 -1
- package/dist/index.cjs +1233 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +226 -10
- package/dist/index.d.ts +226 -10
- package/dist/index.mjs +1230 -111
- package/dist/index.mjs.map +1 -1
- package/dist/lane/index.cjs +758 -110
- package/dist/lane/index.cjs.map +1 -1
- package/dist/lane/index.mjs +758 -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/cli/index.mjs
CHANGED
|
@@ -1783,9 +1783,9 @@ Please accept the agreement at https://developer.apple.com/account before contin
|
|
|
1783
1783
|
throw new Error(msg);
|
|
1784
1784
|
}
|
|
1785
1785
|
}
|
|
1786
|
-
async function
|
|
1787
|
-
const log = config.onLog ??
|
|
1788
|
-
|
|
1786
|
+
async function beginLogin(config) {
|
|
1787
|
+
const log = config.onLog ?? (() => {
|
|
1788
|
+
});
|
|
1789
1789
|
log("Fetching Apple service key...");
|
|
1790
1790
|
const serviceKey = await fetchServiceKey();
|
|
1791
1791
|
const initRes = await fetch(`${AUTH_BASE}/signin?widgetKey=${serviceKey}`, {
|
|
@@ -1802,27 +1802,94 @@ async function loginWithAppleId(config) {
|
|
|
1802
1802
|
const cookieStr = Object.entries(initCookies).map(([k, v]) => k.startsWith("DES") ? `${k}="${v}"` : `${k}=${v}`).join("; ");
|
|
1803
1803
|
log("Starting SIRP Apple ID login...");
|
|
1804
1804
|
const response = await doSirp(config.email, config.password, serviceKey, cookieStr, hashcash);
|
|
1805
|
-
const
|
|
1805
|
+
const baseState = {
|
|
1806
1806
|
cookies: { ...initCookies, ...response.cookies },
|
|
1807
1807
|
sessionId: response.sessionId,
|
|
1808
1808
|
scnt: response.scnt,
|
|
1809
1809
|
serviceKey,
|
|
1810
|
-
userEmail: config.email
|
|
1811
|
-
pendingAgreements: []
|
|
1810
|
+
userEmail: config.email
|
|
1812
1811
|
};
|
|
1813
1812
|
if (response.status === 403) {
|
|
1814
1813
|
throw new Error(`Invalid username and password combination. Used '${config.email}' as the username.`);
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
await fetchOlympusSession(session);
|
|
1818
|
-
} else if (response.status === 409) {
|
|
1819
|
-
await handleTwoStepOrFactor(session, log, promptFn);
|
|
1820
|
-
await fetchOlympusSession(session);
|
|
1821
|
-
} else if (response.status === 412) {
|
|
1814
|
+
}
|
|
1815
|
+
if (response.status === 412) {
|
|
1822
1816
|
throw new Error("Need to acknowledge Apple's Apple ID and Privacy statement. Please manually log into https://appleid.apple.com.");
|
|
1817
|
+
}
|
|
1818
|
+
if (response.status === 200) {
|
|
1819
|
+
log("Login successful (no 2FA).");
|
|
1820
|
+
const session = { ...baseState, pendingAgreements: [] };
|
|
1821
|
+
await finalizeSession(session, log);
|
|
1822
|
+
return { kind: "logged_in", session };
|
|
1823
|
+
}
|
|
1824
|
+
if (response.status === 409) {
|
|
1825
|
+
log("2FA required, fetching challenge...");
|
|
1826
|
+
const challenge = await fetchTwoFactorChallenge(baseState);
|
|
1827
|
+
return { kind: "needs_2fa", pending: baseState, challenge };
|
|
1828
|
+
}
|
|
1829
|
+
throw new Error(`Unexpected login response (${response.status}): ${JSON.stringify(response.body).slice(0, 500)}`);
|
|
1830
|
+
}
|
|
1831
|
+
async function fetchTwoFactorChallenge(pending) {
|
|
1832
|
+
const r = await fetch(`${AUTH_BASE}`, { headers: buildAuthHeadersFromPending(pending) });
|
|
1833
|
+
const body = await r.json();
|
|
1834
|
+
const trustedPhoneNumbers = (body.trustedPhoneNumbers ?? []).map((p) => ({
|
|
1835
|
+
id: p.id,
|
|
1836
|
+
numberWithDialCode: p.numberWithDialCode,
|
|
1837
|
+
pushMode: p.pushMode
|
|
1838
|
+
}));
|
|
1839
|
+
const phoneOnly = body.noTrustedDevices === true;
|
|
1840
|
+
const codeLength = body.securityCode?.length ?? 6;
|
|
1841
|
+
return {
|
|
1842
|
+
kind: phoneOnly ? "phone_only" : "device",
|
|
1843
|
+
codeLength,
|
|
1844
|
+
trustedPhoneNumbers
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
async function requestSmsCode(input) {
|
|
1848
|
+
await fetch(`${AUTH_BASE}/verify/phone`, {
|
|
1849
|
+
method: "PUT",
|
|
1850
|
+
headers: { ...buildAuthHeadersFromPending(input.pending), "Content-Type": "application/json" },
|
|
1851
|
+
body: JSON.stringify({ phoneNumber: { id: input.phoneId }, mode: input.mode ?? "sms" })
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
async function submitTwoFactorCode(input) {
|
|
1855
|
+
const log = input.onLog ?? (() => {
|
|
1856
|
+
});
|
|
1857
|
+
let path;
|
|
1858
|
+
let body;
|
|
1859
|
+
if (input.source === "device") {
|
|
1860
|
+
path = `${AUTH_BASE}/verify/trusteddevice/securitycode`;
|
|
1861
|
+
body = JSON.stringify({ securityCode: { code: input.code } });
|
|
1823
1862
|
} else {
|
|
1824
|
-
throw new Error(
|
|
1863
|
+
if (input.phoneId == null) throw new Error("phoneId is required when source='phone'");
|
|
1864
|
+
path = `${AUTH_BASE}/verify/phone/securitycode`;
|
|
1865
|
+
body = JSON.stringify({
|
|
1866
|
+
securityCode: { code: input.code },
|
|
1867
|
+
phoneNumber: { id: input.phoneId },
|
|
1868
|
+
mode: input.mode ?? "sms"
|
|
1869
|
+
});
|
|
1825
1870
|
}
|
|
1871
|
+
log("Submitting 2FA code...");
|
|
1872
|
+
const verifyRes = await fetch(path, {
|
|
1873
|
+
method: "POST",
|
|
1874
|
+
headers: { ...buildAuthHeadersFromPending(input.pending), "Content-Type": "application/json" },
|
|
1875
|
+
body
|
|
1876
|
+
});
|
|
1877
|
+
if (!verifyRes.ok) {
|
|
1878
|
+
const err = await verifyRes.json().catch(() => ({}));
|
|
1879
|
+
const msgs = (err?.service_errors ?? err?.serviceErrors ?? []).map((e) => e.message).filter(Boolean);
|
|
1880
|
+
throw new Error(msgs.join("; ") || `Verification failed (${verifyRes.status})`);
|
|
1881
|
+
}
|
|
1882
|
+
const session = {
|
|
1883
|
+
...input.pending,
|
|
1884
|
+
cookies: { ...input.pending.cookies, ...parseCookies(verifyRes.headers) },
|
|
1885
|
+
pendingAgreements: []
|
|
1886
|
+
};
|
|
1887
|
+
await trustSession(session);
|
|
1888
|
+
await finalizeSession(session, log);
|
|
1889
|
+
return session;
|
|
1890
|
+
}
|
|
1891
|
+
async function finalizeSession(session, log) {
|
|
1892
|
+
await fetchOlympusSession(session);
|
|
1826
1893
|
const agreements = await fetchContractMessages(session);
|
|
1827
1894
|
if (agreements.length > 0) {
|
|
1828
1895
|
for (const msg of agreements) {
|
|
@@ -1831,7 +1898,53 @@ async function loginWithAppleId(config) {
|
|
|
1831
1898
|
}
|
|
1832
1899
|
session.pendingAgreements = agreements;
|
|
1833
1900
|
log(`Logged in as ${session.userEmail}`);
|
|
1834
|
-
|
|
1901
|
+
}
|
|
1902
|
+
async function loginWithAppleId(config) {
|
|
1903
|
+
const log = config.onLog ?? console.log;
|
|
1904
|
+
const promptFn = config.onPrompt ?? defaultPrompt;
|
|
1905
|
+
const result = await beginLogin({ email: config.email, password: config.password, onLog: log });
|
|
1906
|
+
if (result.kind === "logged_in") return result.session;
|
|
1907
|
+
const { pending, challenge } = result;
|
|
1908
|
+
const phones = challenge.trustedPhoneNumbers;
|
|
1909
|
+
if (challenge.kind === "device") {
|
|
1910
|
+
log("Two-factor Authentication (6 digit code) is enabled for this account");
|
|
1911
|
+
log("(Input 'sms' to escape this prompt and select a trusted phone number to send the code as a text message)");
|
|
1912
|
+
const input = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
1913
|
+
if (input.toLowerCase() === "sms") {
|
|
1914
|
+
log("Please select a trusted phone number:");
|
|
1915
|
+
for (let i = 0; i < phones.length; i++) log(` ${i + 1}. ${phones[i].numberWithDialCode}`);
|
|
1916
|
+
const choice2 = await promptFn("Enter number: ");
|
|
1917
|
+
const phone2 = phones[Math.max(0, parseInt(choice2, 10) - 1)] ?? phones[0];
|
|
1918
|
+
await requestSmsCode({ pending, phoneId: phone2.id, mode: phone2.pushMode });
|
|
1919
|
+
log(`Code sent to ${phone2.numberWithDialCode}`);
|
|
1920
|
+
const code2 = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
1921
|
+
return submitTwoFactorCode({ pending, code: code2, source: "phone", phoneId: phone2.id, mode: phone2.pushMode ?? "sms", onLog: log });
|
|
1922
|
+
}
|
|
1923
|
+
return submitTwoFactorCode({ pending, code: input, source: "device", onLog: log });
|
|
1924
|
+
}
|
|
1925
|
+
log("Two-factor Authentication (6 digit code) is enabled for this account");
|
|
1926
|
+
if (phones.length === 1) {
|
|
1927
|
+
const phone2 = phones[0];
|
|
1928
|
+
log(`Code automatically sent to ${phone2.numberWithDialCode}`);
|
|
1929
|
+
const code2 = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
1930
|
+
return submitTwoFactorCode({ pending, code: code2, source: "phone", phoneId: phone2.id, mode: phone2.pushMode ?? "sms", onLog: log });
|
|
1931
|
+
}
|
|
1932
|
+
log("Please select a trusted phone number:");
|
|
1933
|
+
for (let i = 0; i < phones.length; i++) log(` ${i + 1}. ${phones[i].numberWithDialCode}`);
|
|
1934
|
+
const choice = await promptFn("Enter number: ");
|
|
1935
|
+
const phone = phones[Math.max(0, parseInt(choice, 10) - 1)] ?? phones[0];
|
|
1936
|
+
await requestSmsCode({ pending, phoneId: phone.id, mode: phone.pushMode });
|
|
1937
|
+
log(`Code sent to ${phone.numberWithDialCode}`);
|
|
1938
|
+
const code = await promptFn(`Please enter the ${challenge.codeLength} digit code: `);
|
|
1939
|
+
return submitTwoFactorCode({ pending, code, source: "phone", phoneId: phone.id, mode: phone.pushMode ?? "sms", onLog: log });
|
|
1940
|
+
}
|
|
1941
|
+
function buildAuthHeadersFromPending(pending) {
|
|
1942
|
+
const h = { "X-Apple-Widget-Key": pending.serviceKey, Accept: "application/json" };
|
|
1943
|
+
if (pending.sessionId) h["X-Apple-Id-Session-Id"] = pending.sessionId;
|
|
1944
|
+
if (pending.scnt) h["scnt"] = pending.scnt;
|
|
1945
|
+
const c = Object.entries(pending.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
1946
|
+
if (c) h["Cookie"] = c;
|
|
1947
|
+
return h;
|
|
1835
1948
|
}
|
|
1836
1949
|
async function doSirp(user, password, serviceKey, cookieStr, hashcash) {
|
|
1837
1950
|
const client = new SRPClient(2048);
|
|
@@ -1887,99 +2000,6 @@ async function doSirp(user, password, serviceKey, cookieStr, hashcash) {
|
|
|
1887
2000
|
scnt: completeRes.headers.get("scnt") ?? ""
|
|
1888
2001
|
};
|
|
1889
2002
|
}
|
|
1890
|
-
async function handleTwoStepOrFactor(session, log, promptFn) {
|
|
1891
|
-
const r = await fetch(`${AUTH_BASE}`, { headers: buildAuthHeaders(session) });
|
|
1892
|
-
const body = await r.json();
|
|
1893
|
-
if (body.trustedDevices?.length > 0) {
|
|
1894
|
-
await handleTwoStep(session, body, log, promptFn);
|
|
1895
|
-
} else if (body.trustedPhoneNumbers?.length > 0) {
|
|
1896
|
-
await handleTwoFactor(session, body, log, promptFn);
|
|
1897
|
-
} else {
|
|
1898
|
-
throw new Error("2FA required but no trusted devices or phone numbers found.");
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
async function handleTwoFactor(session, authBody, log, promptFn) {
|
|
1902
|
-
log("Two-factor Authentication (6 digit code) is enabled for this account");
|
|
1903
|
-
const codeLength = authBody.securityCode?.length ?? 6;
|
|
1904
|
-
const phones = authBody.trustedPhoneNumbers ?? [];
|
|
1905
|
-
const noTrusted = authBody.noTrustedDevices === true;
|
|
1906
|
-
let codeType;
|
|
1907
|
-
let reqBody;
|
|
1908
|
-
if (noTrusted && phones.length === 1) {
|
|
1909
|
-
const phone = phones[0];
|
|
1910
|
-
log(`Code automatically sent to ${phone.numberWithDialCode}`);
|
|
1911
|
-
const code = await promptFn(`Please enter the ${codeLength} digit code you received at ${phone.numberWithDialCode}: `);
|
|
1912
|
-
codeType = "phone";
|
|
1913
|
-
reqBody = JSON.stringify({ securityCode: { code }, phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" });
|
|
1914
|
-
} else if (noTrusted) {
|
|
1915
|
-
const phone = await choosePhone(phones, log, promptFn);
|
|
1916
|
-
await requestPhoneCode(session, phone);
|
|
1917
|
-
log(`Successfully requested text message to ${phone.numberWithDialCode}`);
|
|
1918
|
-
const code = await promptFn(`Please enter the ${codeLength} digit code: `);
|
|
1919
|
-
codeType = "phone";
|
|
1920
|
-
reqBody = JSON.stringify({ securityCode: { code }, phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" });
|
|
1921
|
-
} else {
|
|
1922
|
-
log("(Input 'sms' to escape this prompt and select a trusted phone number to send the code as a text message)");
|
|
1923
|
-
const input = await promptFn(`Please enter the ${codeLength} digit code: `);
|
|
1924
|
-
if (input.toLowerCase() === "sms") {
|
|
1925
|
-
const phone = await choosePhone(phones, log, promptFn);
|
|
1926
|
-
await requestPhoneCode(session, phone);
|
|
1927
|
-
const code = await promptFn(`Please enter the ${codeLength} digit code sent to ${phone.numberWithDialCode}: `);
|
|
1928
|
-
codeType = "phone";
|
|
1929
|
-
reqBody = JSON.stringify({ securityCode: { code }, phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" });
|
|
1930
|
-
} else {
|
|
1931
|
-
codeType = "trusteddevice";
|
|
1932
|
-
reqBody = JSON.stringify({ securityCode: { code: input } });
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
log("Requesting session...");
|
|
1936
|
-
const verifyRes = await fetch(`${AUTH_BASE}/verify/${codeType}/securitycode`, {
|
|
1937
|
-
method: "POST",
|
|
1938
|
-
headers: { ...buildAuthHeaders(session), "Content-Type": "application/json" },
|
|
1939
|
-
body: reqBody
|
|
1940
|
-
});
|
|
1941
|
-
if (!verifyRes.ok) {
|
|
1942
|
-
const err = await verifyRes.json().catch(() => ({}));
|
|
1943
|
-
const msgs = (err?.service_errors ?? err?.serviceErrors ?? []).map((e) => e.message).filter(Boolean);
|
|
1944
|
-
throw new Error(msgs.join("; ") || `Verification failed (${verifyRes.status})`);
|
|
1945
|
-
}
|
|
1946
|
-
Object.assign(session.cookies, parseCookies(verifyRes.headers));
|
|
1947
|
-
await trustSession(session);
|
|
1948
|
-
}
|
|
1949
|
-
async function handleTwoStep(session, authBody, log, promptFn) {
|
|
1950
|
-
log("Two-step Verification (4 digit code) is enabled for this account");
|
|
1951
|
-
const devices = authBody.trustedDevices ?? [];
|
|
1952
|
-
log("Please select a trusted device:");
|
|
1953
|
-
for (let i = 0; i < devices.length; i++) {
|
|
1954
|
-
log(` ${i + 1}. ${devices[i].name} ${devices[i].modelName ?? "SMS"} (${devices[i].id})`);
|
|
1955
|
-
}
|
|
1956
|
-
const choice = await promptFn("Enter device number: ");
|
|
1957
|
-
const device = devices[Math.max(0, parseInt(choice, 10) - 1)] ?? devices[0];
|
|
1958
|
-
await fetch(`${AUTH_BASE}/verify/device/${device.id}/securitycode`, { method: "PUT", headers: buildAuthHeaders(session) });
|
|
1959
|
-
log("Successfully requested notification");
|
|
1960
|
-
const code = await promptFn("Please enter the 4 digit code: ");
|
|
1961
|
-
const verifyRes = await fetch(`${AUTH_BASE}/verify/phone/securitycode`, {
|
|
1962
|
-
method: "POST",
|
|
1963
|
-
headers: { ...buildAuthHeaders(session), "Content-Type": "application/json" },
|
|
1964
|
-
body: JSON.stringify({ phoneNumber: { id: device.id }, securityCode: { code }, mode: "sms" })
|
|
1965
|
-
});
|
|
1966
|
-
if (!verifyRes.ok) throw new Error("Incorrect verification code.");
|
|
1967
|
-
Object.assign(session.cookies, parseCookies(verifyRes.headers));
|
|
1968
|
-
await trustSession(session);
|
|
1969
|
-
}
|
|
1970
|
-
async function choosePhone(phones, log, promptFn) {
|
|
1971
|
-
log("Please select a trusted phone number:");
|
|
1972
|
-
for (let i = 0; i < phones.length; i++) log(` ${i + 1}. ${phones[i].numberWithDialCode}`);
|
|
1973
|
-
const choice = await promptFn("Enter number: ");
|
|
1974
|
-
return phones[Math.max(0, parseInt(choice, 10) - 1)] ?? phones[0];
|
|
1975
|
-
}
|
|
1976
|
-
async function requestPhoneCode(session, phone) {
|
|
1977
|
-
await fetch(`${AUTH_BASE}/verify/phone`, {
|
|
1978
|
-
method: "PUT",
|
|
1979
|
-
headers: { ...buildAuthHeaders(session), "Content-Type": "application/json" },
|
|
1980
|
-
body: JSON.stringify({ phoneNumber: { id: phone.id }, mode: phone.pushMode ?? "sms" })
|
|
1981
|
-
});
|
|
1982
|
-
}
|
|
1983
2003
|
async function trustSession(session) {
|
|
1984
2004
|
const r = await fetch(`${AUTH_BASE}/2sv/trust`, { headers: buildAuthHeaders(session) });
|
|
1985
2005
|
Object.assign(session.cookies, parseCookies(r.headers));
|
|
@@ -6322,6 +6342,12 @@ var init_xcode_metrics = __esm({
|
|
|
6322
6342
|
});
|
|
6323
6343
|
|
|
6324
6344
|
// src/client/portal.ts
|
|
6345
|
+
function pickUniqueKeyName(base, taken) {
|
|
6346
|
+
if (!taken.has(base)) return base;
|
|
6347
|
+
let n = 1;
|
|
6348
|
+
while (taken.has(`${base} - ${n}`)) n++;
|
|
6349
|
+
return `${base} - ${n}`;
|
|
6350
|
+
}
|
|
6325
6351
|
var PORTAL_BASE, PortalClient;
|
|
6326
6352
|
var init_portal = __esm({
|
|
6327
6353
|
"src/client/portal.ts"() {
|
|
@@ -6342,6 +6368,279 @@ var init_portal = __esm({
|
|
|
6342
6368
|
async init() {
|
|
6343
6369
|
await this.post("account/listTeams.action", {});
|
|
6344
6370
|
}
|
|
6371
|
+
/**
|
|
6372
|
+
* JSON POST — different content type than the standard form-encoded
|
|
6373
|
+
* `post()`. Used by the App Store Connect API key endpoints
|
|
6374
|
+
* (`account/auth/key/v2/create`), which Spaceship discovered take a
|
|
6375
|
+
* JSON body even though every other portal mutation is form-encoded.
|
|
6376
|
+
*
|
|
6377
|
+
* Like the form-encoded `post()`, this also runs the response through
|
|
6378
|
+
* `checkPortalResponse` — Apple returns HTTP 200 even for errors and
|
|
6379
|
+
* encodes the error in `resultCode`/`userString` fields, so a raw
|
|
6380
|
+
* status check would silently miss real failures.
|
|
6381
|
+
*/
|
|
6382
|
+
async postJson(path, body) {
|
|
6383
|
+
const headers = {
|
|
6384
|
+
Cookie: this.cookieStr,
|
|
6385
|
+
"Content-Type": "application/json",
|
|
6386
|
+
Accept: "application/json"
|
|
6387
|
+
};
|
|
6388
|
+
if (this.csrf) {
|
|
6389
|
+
headers["csrf"] = this.csrf;
|
|
6390
|
+
headers["csrf_ts"] = this.csrfTs;
|
|
6391
|
+
}
|
|
6392
|
+
console.log(`[portal] POST(json) ${path}`);
|
|
6393
|
+
const res = await fetch(`${PORTAL_BASE}/${path}`, {
|
|
6394
|
+
method: "POST",
|
|
6395
|
+
headers,
|
|
6396
|
+
body: JSON.stringify(body)
|
|
6397
|
+
});
|
|
6398
|
+
if (res.headers.get("csrf")) {
|
|
6399
|
+
this.csrf = res.headers.get("csrf");
|
|
6400
|
+
this.csrfTs = res.headers.get("csrf_ts") ?? "";
|
|
6401
|
+
}
|
|
6402
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
6403
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
6404
|
+
if (m && !this.cookieStr.includes(m[1] + "=")) this.cookieStr += "; " + m[1] + "=" + m[2];
|
|
6405
|
+
}
|
|
6406
|
+
const text = await res.text();
|
|
6407
|
+
let data = null;
|
|
6408
|
+
try {
|
|
6409
|
+
data = text ? JSON.parse(text) : null;
|
|
6410
|
+
} catch {
|
|
6411
|
+
}
|
|
6412
|
+
console.log(`[portal] POST(json) ${path} \u2192 ${res.status} ${text.slice(0, 400)}`);
|
|
6413
|
+
checkPortalResponse(data, this.session);
|
|
6414
|
+
return { status: res.status, body: data, rawText: text };
|
|
6415
|
+
}
|
|
6416
|
+
/**
|
|
6417
|
+
* GET helper for the portal endpoints that take query parameters
|
|
6418
|
+
* (currently just `account/auth/key/download`). Returns the raw text
|
|
6419
|
+
* since download endpoints can return PEMs or JSON depending on Apple's
|
|
6420
|
+
* mood — caller decides how to parse.
|
|
6421
|
+
*/
|
|
6422
|
+
async getRaw(path, params = {}) {
|
|
6423
|
+
const url = new URL(`${PORTAL_BASE}/${path}`);
|
|
6424
|
+
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
6425
|
+
const headers = {
|
|
6426
|
+
Cookie: this.cookieStr,
|
|
6427
|
+
Accept: "application/json, text/plain, application/x-pem-file, */*"
|
|
6428
|
+
};
|
|
6429
|
+
if (this.csrf) {
|
|
6430
|
+
headers["csrf"] = this.csrf;
|
|
6431
|
+
headers["csrf_ts"] = this.csrfTs;
|
|
6432
|
+
}
|
|
6433
|
+
console.log(`[portal] GET ${url.pathname}${url.search}`);
|
|
6434
|
+
const res = await fetch(url.toString(), { headers });
|
|
6435
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
6436
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
6437
|
+
if (m && !this.cookieStr.includes(m[1] + "=")) this.cookieStr += "; " + m[1] + "=" + m[2];
|
|
6438
|
+
}
|
|
6439
|
+
const text = await res.text();
|
|
6440
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
6441
|
+
console.log(`[portal] GET ${url.pathname} \u2192 ${res.status} ${contentType} ${text.length}b`);
|
|
6442
|
+
return { status: res.status, rawText: text, contentType };
|
|
6443
|
+
}
|
|
6444
|
+
// ── App Store Connect API Keys (.p8) ────────────────────────────────────
|
|
6445
|
+
/**
|
|
6446
|
+
* Create an App Store Connect API key via the developer portal's
|
|
6447
|
+
* `account/auth/key/v2/create` endpoint. Reverse-engineered from the
|
|
6448
|
+
* _current_ @expo/apple-utils npm package (v2.1.21), which is what
|
|
6449
|
+
* EAS CLI uses to manage Apple credentials in production.
|
|
6450
|
+
*
|
|
6451
|
+
* This differs from older published reverse-engineering guides:
|
|
6452
|
+
* • URL uses the `/v2/create` suffix (Apple kept it)
|
|
6453
|
+
* • Field is `serviceConfigurations`, shape is an object keyed by
|
|
6454
|
+
* service id (NOT `serviceConfigurationsRequests: [...]` array)
|
|
6455
|
+
* • Body REQUIRES `scope: "team"`
|
|
6456
|
+
* • Needs a scope-specific CSRF warmup via the `keys` endpoint
|
|
6457
|
+
* before the create call (EAS's `ensureCSRFAsync("keys", …)`)
|
|
6458
|
+
*
|
|
6459
|
+
* For an App Store Connect API key (PUBLIC_API, used by altool for
|
|
6460
|
+
* TestFlight uploads), `serviceConfigurations` is an empty object `{}`.
|
|
6461
|
+
* For an APNs auth key, it's `{ "U27F4V844T": [] }`. For MusicKit:
|
|
6462
|
+
* `{ "6A7HVUVQ3M": [musicId] }`, etc.
|
|
6463
|
+
*
|
|
6464
|
+
* Apple's name validator rejects parentheses, brackets, and most
|
|
6465
|
+
* punctuation — sanitize to alphanumeric + space + dash + underscore
|
|
6466
|
+
* + period and collapse whitespace.
|
|
6467
|
+
*/
|
|
6468
|
+
async createApiKey(rawName, serviceConfigurations = {}) {
|
|
6469
|
+
const baseName = rawName.replace(/[^A-Za-z0-9 _\-.]/g, " ").replace(/\s+/g, " ").trim().slice(0, 45);
|
|
6470
|
+
if (!baseName) throw new Error("createApiKey: name is empty after sanitization");
|
|
6471
|
+
let existingNames = /* @__PURE__ */ new Set();
|
|
6472
|
+
try {
|
|
6473
|
+
const list = await this.listApiKeys();
|
|
6474
|
+
existingNames = new Set(
|
|
6475
|
+
(list.keys ?? []).map((k) => String(k.keyName ?? "").trim())
|
|
6476
|
+
);
|
|
6477
|
+
} catch {
|
|
6478
|
+
}
|
|
6479
|
+
const name = pickUniqueKeyName(baseName, existingNames);
|
|
6480
|
+
const body = {
|
|
6481
|
+
teamId: this.teamId,
|
|
6482
|
+
name,
|
|
6483
|
+
serviceConfigurations,
|
|
6484
|
+
scope: "team"
|
|
6485
|
+
};
|
|
6486
|
+
const result = await this.postJson("account/auth/key/v2/create", body);
|
|
6487
|
+
const created = result.body?.keys?.[0] ?? result.body?.key ?? result.body?.data ?? result.body;
|
|
6488
|
+
const keyId = created?.keyId ?? created?.id ?? created?.kid ?? created?.attributes?.kid;
|
|
6489
|
+
if (!keyId) {
|
|
6490
|
+
throw new Error(`createApiKey: no key id in response. Body: ${result.rawText.slice(0, 400)}`);
|
|
6491
|
+
}
|
|
6492
|
+
return { keyId, raw: created };
|
|
6493
|
+
}
|
|
6494
|
+
/**
|
|
6495
|
+
* Fetch a single API key by id via `account/auth/key/get`. Reverse-
|
|
6496
|
+
* engineered from Spaceship's `get_key`. Returns the raw key record so
|
|
6497
|
+
* the caller can extract whatever fields it needs (e.g. issuerId).
|
|
6498
|
+
*
|
|
6499
|
+
* Form-encoded POST — same shape as every other PortalClient mutation
|
|
6500
|
+
* except the JSON `create` endpoint.
|
|
6501
|
+
*/
|
|
6502
|
+
async getApiKey(keyId) {
|
|
6503
|
+
const data = await this.post("account/auth/key/get", {
|
|
6504
|
+
teamId: this.teamId,
|
|
6505
|
+
keyId
|
|
6506
|
+
});
|
|
6507
|
+
return data?.keys?.[0] ?? data?.key ?? data?.data ?? data;
|
|
6508
|
+
}
|
|
6509
|
+
/**
|
|
6510
|
+
* Revoke an existing key. Form-encoded POST per Spaceship's
|
|
6511
|
+
* `revoke_key!`. Used for cleaning up orphan keys created during
|
|
6512
|
+
* failed wizard runs.
|
|
6513
|
+
*/
|
|
6514
|
+
async revokeApiKey(keyId) {
|
|
6515
|
+
await this.post("account/auth/key/revoke", {
|
|
6516
|
+
teamId: this.teamId,
|
|
6517
|
+
keyId
|
|
6518
|
+
});
|
|
6519
|
+
}
|
|
6520
|
+
// ── APNs Authentication Keys (.p8) ──────────────────────────────────────
|
|
6521
|
+
/** Apple's hardcoded service id for APNs auth keys (from Spaceship). */
|
|
6522
|
+
static APNS_SERVICE_ID = "U27F4V844T";
|
|
6523
|
+
/**
|
|
6524
|
+
* Create an APNs Authentication Key (.p8) via the developer portal.
|
|
6525
|
+
*
|
|
6526
|
+
* Apple requires BOTH `serviceConfigurations` (the map) AND
|
|
6527
|
+
* `serviceConfigurationsRequests` (the array of full config objects)
|
|
6528
|
+
* in the v2/create body. Just sending the map alone results in
|
|
6529
|
+
* "No value was provided for the parameter 'serviceConfigurations'".
|
|
6530
|
+
*
|
|
6531
|
+
* The exact body comes from @expo/apple-utils v2.1.21 — both fields
|
|
6532
|
+
* are produced by separate functions (`d` for the map, `h` for the
|
|
6533
|
+
* array) and merged into the create payload.
|
|
6534
|
+
*
|
|
6535
|
+
* Apple also rejects duplicate key names ("Another key with same
|
|
6536
|
+
* name exists") — we dedupe by listing existing keys first and
|
|
6537
|
+
* appending " (N)" until we find a free slot, mirroring the
|
|
6538
|
+
* provisioning profile dedup.
|
|
6539
|
+
*/
|
|
6540
|
+
async createApnsAuthKey(rawName) {
|
|
6541
|
+
const baseName = rawName.replace(/[^A-Za-z0-9 _\-.]/g, " ").replace(/\s+/g, " ").trim().slice(0, 45);
|
|
6542
|
+
if (!baseName) throw new Error("createApnsAuthKey: name is empty after sanitization");
|
|
6543
|
+
let existingNames = /* @__PURE__ */ new Set();
|
|
6544
|
+
try {
|
|
6545
|
+
const list = await this.listApiKeys();
|
|
6546
|
+
existingNames = new Set(
|
|
6547
|
+
(list.keys ?? []).map((k) => String(k.keyName ?? "").trim())
|
|
6548
|
+
);
|
|
6549
|
+
} catch {
|
|
6550
|
+
}
|
|
6551
|
+
const name = pickUniqueKeyName(baseName, existingNames);
|
|
6552
|
+
const body = {
|
|
6553
|
+
teamId: this.teamId,
|
|
6554
|
+
name,
|
|
6555
|
+
serviceConfigurations: {
|
|
6556
|
+
[_PortalClient.APNS_SERVICE_ID]: []
|
|
6557
|
+
},
|
|
6558
|
+
serviceConfigurationsRequests: [
|
|
6559
|
+
{
|
|
6560
|
+
isNew: true,
|
|
6561
|
+
serviceId: _PortalClient.APNS_SERVICE_ID,
|
|
6562
|
+
identifiers: {},
|
|
6563
|
+
environment: "all",
|
|
6564
|
+
scope: "team"
|
|
6565
|
+
}
|
|
6566
|
+
],
|
|
6567
|
+
scope: "team"
|
|
6568
|
+
};
|
|
6569
|
+
const result = await this.postJson("account/auth/key/v2/create", body);
|
|
6570
|
+
const created = result.body?.keys?.[0];
|
|
6571
|
+
if (!created?.keyId) {
|
|
6572
|
+
throw new Error(`createApnsAuthKey: no key id in response. Body: ${result.rawText.slice(0, 400)}`);
|
|
6573
|
+
}
|
|
6574
|
+
const pem = await this.downloadApiKey(created.keyId);
|
|
6575
|
+
return { keyId: created.keyId, pem, raw: created };
|
|
6576
|
+
}
|
|
6577
|
+
/**
|
|
6578
|
+
* Find existing APNs auth keys in the team. Used by the wizard to
|
|
6579
|
+
* detect "you already have one" cases and offer to reuse rather than
|
|
6580
|
+
* proliferate keys.
|
|
6581
|
+
*/
|
|
6582
|
+
async listApnsAuthKeys() {
|
|
6583
|
+
const list = await this.listApiKeys();
|
|
6584
|
+
return (list.keys ?? []).filter(
|
|
6585
|
+
(k) => (k.services ?? []).some((s) => s.id === _PortalClient.APNS_SERVICE_ID || /apns/i.test(s.name ?? ""))
|
|
6586
|
+
).map((k) => ({
|
|
6587
|
+
keyId: k.keyId,
|
|
6588
|
+
keyName: k.keyName,
|
|
6589
|
+
canDownload: Boolean(k.canDownload)
|
|
6590
|
+
}));
|
|
6591
|
+
}
|
|
6592
|
+
/**
|
|
6593
|
+
* Download an existing App Store Connect API key as PEM. Spaceship's
|
|
6594
|
+
* `download_key` endpoint — GET with teamId + keyId in query string.
|
|
6595
|
+
* Returns the raw .p8 PEM text. Apple shows the .p8 exactly once
|
|
6596
|
+
* (after creation), so call this immediately after createApiKey.
|
|
6597
|
+
*/
|
|
6598
|
+
async downloadApiKey(keyId) {
|
|
6599
|
+
const { status, rawText, contentType } = await this.getRaw("account/auth/key/download", {
|
|
6600
|
+
teamId: this.teamId,
|
|
6601
|
+
keyId
|
|
6602
|
+
});
|
|
6603
|
+
if (status !== 200) {
|
|
6604
|
+
throw new Error(`downloadApiKey failed (${status}): ${rawText.slice(0, 200)}`);
|
|
6605
|
+
}
|
|
6606
|
+
if (rawText.includes("BEGIN PRIVATE KEY")) return rawText;
|
|
6607
|
+
if (contentType.includes("json")) {
|
|
6608
|
+
try {
|
|
6609
|
+
const parsed = JSON.parse(rawText);
|
|
6610
|
+
const candidates = [
|
|
6611
|
+
parsed?.privateKey,
|
|
6612
|
+
parsed?.key?.privateKey,
|
|
6613
|
+
parsed?.keys?.[0]?.privateKey,
|
|
6614
|
+
parsed?.data?.attributes?.privateKey,
|
|
6615
|
+
parsed?.value
|
|
6616
|
+
];
|
|
6617
|
+
for (const c of candidates) {
|
|
6618
|
+
if (typeof c === "string" && c.includes("BEGIN PRIVATE KEY")) return c;
|
|
6619
|
+
}
|
|
6620
|
+
} catch {
|
|
6621
|
+
}
|
|
6622
|
+
}
|
|
6623
|
+
throw new Error(`downloadApiKey returned no PEM. Content-Type=${contentType} body=${rawText.slice(0, 300)}`);
|
|
6624
|
+
}
|
|
6625
|
+
/**
|
|
6626
|
+
* List existing API keys via the portal. Used to discover the team's
|
|
6627
|
+
* issuer id — every key in the team shares the same issuer id, and
|
|
6628
|
+
* altool needs it alongside the key id and .p8 file.
|
|
6629
|
+
*
|
|
6630
|
+
* Form-encoded POST (NOT JSON), with pagination params, per Spaceship's
|
|
6631
|
+
* `list_keys` method. JSON returned 415 from this endpoint.
|
|
6632
|
+
*/
|
|
6633
|
+
async listApiKeys() {
|
|
6634
|
+
const data = await this.post("account/auth/key/list", {
|
|
6635
|
+
teamId: this.teamId,
|
|
6636
|
+
pageNumber: "1",
|
|
6637
|
+
pageSize: "500",
|
|
6638
|
+
sort: "name=asc"
|
|
6639
|
+
});
|
|
6640
|
+
const keys = data?.keys ?? [];
|
|
6641
|
+
const issuerId = data?.issuerId ?? data?.issuer ?? data?.team?.issuerId ?? keys[0]?.issuerId ?? keys[0]?.issuer;
|
|
6642
|
+
return { keys, issuerId };
|
|
6643
|
+
}
|
|
6345
6644
|
async post(path, params) {
|
|
6346
6645
|
const body = new URLSearchParams();
|
|
6347
6646
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -6409,6 +6708,31 @@ var init_portal = __esm({
|
|
|
6409
6708
|
async deleteAppId(appIdId) {
|
|
6410
6709
|
await this.post("account/ios/identifiers/deleteAppId.action", { teamId: this.teamId, appIdId });
|
|
6411
6710
|
}
|
|
6711
|
+
/**
|
|
6712
|
+
* Toggle a capability (a.k.a. "service") on a bundle ID. Mirrors
|
|
6713
|
+
* Spaceship::Portal's `update_service` — the legacy portal endpoint
|
|
6714
|
+
* still works and is the only session-cookie-authenticated way to flip
|
|
6715
|
+
* capabilities like Push Notifications and Sign in with Apple from
|
|
6716
|
+
* outside the Apple Developer web UI.
|
|
6717
|
+
*
|
|
6718
|
+
* Common service codes (from Spaceship portal/portal_client.rb):
|
|
6719
|
+
* push → push notifications
|
|
6720
|
+
* APG3427HIY → Sign in with Apple
|
|
6721
|
+
* IAD53UNK2F → in-app purchase
|
|
6722
|
+
* homeKit → HomeKit
|
|
6723
|
+
* healthKit → HealthKit
|
|
6724
|
+
*
|
|
6725
|
+
* @param featureType Apple's internal capability key (string code or short name)
|
|
6726
|
+
* @param enabled true → turn on, false → turn off
|
|
6727
|
+
*/
|
|
6728
|
+
async setBundleCapability(params) {
|
|
6729
|
+
await this.post("account/ios/identifiers/updateAppService.action", {
|
|
6730
|
+
teamId: this.teamId,
|
|
6731
|
+
displayId: params.appIdId,
|
|
6732
|
+
featureType: params.featureType,
|
|
6733
|
+
featureValue: params.enabled ? "on" : "off"
|
|
6734
|
+
});
|
|
6735
|
+
}
|
|
6412
6736
|
// ── Certificates ───────────────────────────────────────────────────────
|
|
6413
6737
|
async listCertificates(types) {
|
|
6414
6738
|
const iosTypes = types ?? [
|
|
@@ -6426,12 +6750,21 @@ var init_portal = __esm({
|
|
|
6426
6750
|
return data.certRequests ?? [];
|
|
6427
6751
|
}
|
|
6428
6752
|
async listPushCertificates() {
|
|
6753
|
+
const types = Array.from(
|
|
6754
|
+
/* @__PURE__ */ new Set([
|
|
6755
|
+
_PortalClient.CERT_TYPES.IOS_PRODUCTION_PUSH,
|
|
6756
|
+
_PortalClient.CERT_TYPES.IOS_DEVELOPMENT_PUSH,
|
|
6757
|
+
// Legacy push codes from OLDER_IOS_CERTIFICATE_TYPES
|
|
6758
|
+
"3BQKVH9I2X",
|
|
6759
|
+
"BKLRAVXMGM"
|
|
6760
|
+
])
|
|
6761
|
+
);
|
|
6429
6762
|
const data = await this.post("account/ios/certificate/listCertRequests.action", {
|
|
6430
6763
|
teamId: this.teamId,
|
|
6431
6764
|
pageSize: "500",
|
|
6432
6765
|
pageNumber: "1",
|
|
6433
6766
|
sort: "certRequestStatusCode=asc",
|
|
6434
|
-
types:
|
|
6767
|
+
types: types.join(",")
|
|
6435
6768
|
});
|
|
6436
6769
|
return data.certRequests ?? [];
|
|
6437
6770
|
}
|
|
@@ -6573,18 +6906,332 @@ var init_portal = __esm({
|
|
|
6573
6906
|
}
|
|
6574
6907
|
});
|
|
6575
6908
|
|
|
6909
|
+
// src/client/iris.ts
|
|
6910
|
+
var IRIS_BASE, IrisClient, IrisAuthError;
|
|
6911
|
+
var init_iris = __esm({
|
|
6912
|
+
"src/client/iris.ts"() {
|
|
6913
|
+
IRIS_BASE = "https://appstoreconnect.apple.com/iris/v1";
|
|
6914
|
+
IrisClient = class {
|
|
6915
|
+
constructor(session) {
|
|
6916
|
+
this.session = session;
|
|
6917
|
+
this.cookieStr = Object.entries(session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
6918
|
+
}
|
|
6919
|
+
session;
|
|
6920
|
+
cookieStr;
|
|
6921
|
+
buildHeaders() {
|
|
6922
|
+
return {
|
|
6923
|
+
Cookie: this.cookieStr,
|
|
6924
|
+
Accept: "application/vnd.api+json, application/json, text/plain, */*",
|
|
6925
|
+
"Content-Type": "application/vnd.api+json",
|
|
6926
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
6927
|
+
// Mimic the App Store Connect web UI's user agent
|
|
6928
|
+
"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"
|
|
6929
|
+
};
|
|
6930
|
+
}
|
|
6931
|
+
/**
|
|
6932
|
+
* Issue a request and absorb any new cookies (Apple rotates session
|
|
6933
|
+
* cookies on a lot of iris calls).
|
|
6934
|
+
*/
|
|
6935
|
+
async request(method, path, body) {
|
|
6936
|
+
const headers = this.buildHeaders();
|
|
6937
|
+
if (process.env.FASTNODE_DEBUG) {
|
|
6938
|
+
console.log(`[iris] ${method} ${path}${body ? ` body=${JSON.stringify(body).slice(0, 200)}` : ""}`);
|
|
6939
|
+
}
|
|
6940
|
+
const res = await fetch(`${IRIS_BASE}${path}`, {
|
|
6941
|
+
method,
|
|
6942
|
+
headers,
|
|
6943
|
+
body: body ? JSON.stringify(body) : void 0
|
|
6944
|
+
});
|
|
6945
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
6946
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
6947
|
+
if (m) {
|
|
6948
|
+
this.session.cookies[m[1]] = m[2];
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
this.cookieStr = Object.entries(this.session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
6952
|
+
const text = await res.text();
|
|
6953
|
+
let parsed = null;
|
|
6954
|
+
try {
|
|
6955
|
+
parsed = text ? JSON.parse(text) : null;
|
|
6956
|
+
} catch {
|
|
6957
|
+
}
|
|
6958
|
+
if (process.env.FASTNODE_DEBUG) {
|
|
6959
|
+
console.log(`[iris] \u2192 ${res.status} ${text.slice(0, 300)}`);
|
|
6960
|
+
}
|
|
6961
|
+
return { status: res.status, body: parsed, rawText: text };
|
|
6962
|
+
}
|
|
6963
|
+
/**
|
|
6964
|
+
* List existing API keys. Used both as a sanity check (the user has
|
|
6965
|
+
* permission) and to discover the team's issuer id (which is the same
|
|
6966
|
+
* for every key in the team and is needed by altool).
|
|
6967
|
+
*
|
|
6968
|
+
* Important: Apple's iris endpoint rejects most query parameters with
|
|
6969
|
+
* `PARAMETER_ERROR.INVALID`. Call with no params and let the API return
|
|
6970
|
+
* its default page.
|
|
6971
|
+
*/
|
|
6972
|
+
async listApiKeys() {
|
|
6973
|
+
const { status, body, rawText } = await this.request("GET", "/apiKeys");
|
|
6974
|
+
if (status === 403) {
|
|
6975
|
+
throw new IrisAuthError(
|
|
6976
|
+
"You don't have permission to manage App Store Connect API keys (this requires the Account Holder or Admin role)."
|
|
6977
|
+
);
|
|
6978
|
+
}
|
|
6979
|
+
if (status >= 400 || !body) {
|
|
6980
|
+
throw new Error(`iris listApiKeys failed (${status}): ${rawText.slice(0, 200)}`);
|
|
6981
|
+
}
|
|
6982
|
+
const issuerId = body?.meta?.issuerId ?? body?.data?.[0]?.attributes?.issuerId;
|
|
6983
|
+
const keys = (body.data ?? []).map((d) => ({
|
|
6984
|
+
id: d.id,
|
|
6985
|
+
kid: d.attributes?.kid ?? d.id,
|
|
6986
|
+
nickname: d.attributes?.nickname ?? "",
|
|
6987
|
+
issuerId: d.attributes?.issuerId ?? issuerId,
|
|
6988
|
+
roles: d.attributes?.roles ?? [],
|
|
6989
|
+
allAppsVisible: d.attributes?.allAppsVisible ?? true
|
|
6990
|
+
}));
|
|
6991
|
+
return { keys, issuerId };
|
|
6992
|
+
}
|
|
6993
|
+
/**
|
|
6994
|
+
* Create a new API key. Apple returns the .p8 PEM exactly once in the
|
|
6995
|
+
* create response — capture it immediately or the key is dead weight.
|
|
6996
|
+
*
|
|
6997
|
+
* `keyType` is required by Apple's iris API:
|
|
6998
|
+
* • PUBLIC_API — the standard team-wide API key (what TestFlight uploads need)
|
|
6999
|
+
* • MARKETING_API — for App Analytics access only
|
|
7000
|
+
*/
|
|
7001
|
+
async createApiKey(input) {
|
|
7002
|
+
const requestBody = {
|
|
7003
|
+
data: {
|
|
7004
|
+
type: "apiKeys",
|
|
7005
|
+
attributes: {
|
|
7006
|
+
nickname: input.nickname,
|
|
7007
|
+
roles: input.roles ?? ["APP_MANAGER"],
|
|
7008
|
+
allAppsVisible: input.allAppsVisible ?? true,
|
|
7009
|
+
keyType: input.keyType ?? "PUBLIC_API"
|
|
7010
|
+
}
|
|
7011
|
+
}
|
|
7012
|
+
};
|
|
7013
|
+
console.log("[iris] createApiKey request:", JSON.stringify(requestBody));
|
|
7014
|
+
const { status, body, rawText } = await this.request("POST", "/apiKeys", requestBody);
|
|
7015
|
+
console.log(`[iris] createApiKey response: ${status} ${rawText.slice(0, 800)}`);
|
|
7016
|
+
if (status === 403) {
|
|
7017
|
+
throw new IrisAuthError(
|
|
7018
|
+
"You don't have permission to create App Store Connect API keys (this requires the Account Holder or Admin role)."
|
|
7019
|
+
);
|
|
7020
|
+
}
|
|
7021
|
+
if (status >= 400 || !body) {
|
|
7022
|
+
const msg = body?.errors?.[0]?.detail ?? body?.errors?.[0]?.title ?? rawText.slice(0, 300) ?? `iris createApiKey failed (${status})`;
|
|
7023
|
+
throw new Error(msg);
|
|
7024
|
+
}
|
|
7025
|
+
const data = body.data ?? body;
|
|
7026
|
+
if (!data?.id) {
|
|
7027
|
+
throw new Error(`iris createApiKey returned no key id. Raw response: ${rawText.slice(0, 400)}`);
|
|
7028
|
+
}
|
|
7029
|
+
const key = {
|
|
7030
|
+
id: data.id,
|
|
7031
|
+
kid: data.attributes?.kid ?? data.id,
|
|
7032
|
+
nickname: data.attributes?.nickname ?? input.nickname,
|
|
7033
|
+
privateKey: data.attributes?.privateKey,
|
|
7034
|
+
issuerId: data.attributes?.issuerId,
|
|
7035
|
+
roles: data.attributes?.roles ?? input.roles ?? ["APP_MANAGER"],
|
|
7036
|
+
allAppsVisible: data.attributes?.allAppsVisible ?? true
|
|
7037
|
+
};
|
|
7038
|
+
return key;
|
|
7039
|
+
}
|
|
7040
|
+
/**
|
|
7041
|
+
* Fetch the .p8 PEM AND the team's issuer id for a previously-created
|
|
7042
|
+
* ASC API key. Both come back in a single request via:
|
|
7043
|
+
*
|
|
7044
|
+
* GET /iris/v1/apiKeys/{id}?fields[apiKeys]=privateKey&include=provider
|
|
7045
|
+
*
|
|
7046
|
+
* Sparse fieldset requesting ONLY `privateKey` is the magic that makes
|
|
7047
|
+
* Apple actually include the (base64-encoded) PEM in the response —
|
|
7048
|
+
* the default view returns `privateKey: null`. The `include=provider`
|
|
7049
|
+
* pulls the team's contentProvider record into `included[]`, and its
|
|
7050
|
+
* `id` field IS the issuer id altool needs (a UUID like
|
|
7051
|
+
* `cfadaf94-44ca-4c2c-8fa6-ecc28d3c7d0d`).
|
|
7052
|
+
*
|
|
7053
|
+
* Reverse-engineered from @expo/apple-utils v2.1.21 (the package that
|
|
7054
|
+
* powers EAS CLI), specifically the `ApiKey.downloadAsync` method
|
|
7055
|
+
* combined with `ApiKey.infoAsync` reading `provider?.id`.
|
|
7056
|
+
*
|
|
7057
|
+
* Returns `{ pem, issuerId }`, or `null` if Apple won't return the
|
|
7058
|
+
* private key (typically because the key was already downloaded once).
|
|
7059
|
+
*/
|
|
7060
|
+
async fetchApiKeyPrivateKey(keyId) {
|
|
7061
|
+
try {
|
|
7062
|
+
const url = `${IRIS_BASE}/apiKeys/${keyId}?fields%5BapiKeys%5D=privateKey&include=provider`;
|
|
7063
|
+
const res = await fetch(url, {
|
|
7064
|
+
headers: {
|
|
7065
|
+
...this.buildHeaders(),
|
|
7066
|
+
Accept: "application/vnd.api+json, application/json, text/plain, */*"
|
|
7067
|
+
}
|
|
7068
|
+
});
|
|
7069
|
+
const text = await res.text();
|
|
7070
|
+
console.log(`[iris] fetchApiKeyPrivateKey \u2192 ${res.status} (${text.length} bytes)`);
|
|
7071
|
+
if (res.status !== 200) {
|
|
7072
|
+
console.log(`[iris] err: ${text.slice(0, 300)}`);
|
|
7073
|
+
return null;
|
|
7074
|
+
}
|
|
7075
|
+
const body = JSON.parse(text);
|
|
7076
|
+
const encoded = body?.data?.attributes?.privateKey;
|
|
7077
|
+
if (typeof encoded !== "string" || encoded.length === 0) {
|
|
7078
|
+
console.log(`[iris] no privateKey in response`);
|
|
7079
|
+
return null;
|
|
7080
|
+
}
|
|
7081
|
+
const pem = Buffer.from(encoded, "base64").toString("utf-8");
|
|
7082
|
+
if (!pem.includes("BEGIN PRIVATE KEY")) {
|
|
7083
|
+
console.log(`[iris] decoded body didn't contain PEM marker`);
|
|
7084
|
+
return null;
|
|
7085
|
+
}
|
|
7086
|
+
const provider = (body?.included ?? []).find((i) => i.type === "contentProviders");
|
|
7087
|
+
const issuerId = provider?.id;
|
|
7088
|
+
console.log(`[iris] \u2713 PEM ${pem.length} bytes, issuerId=${issuerId ?? "(missing)"}`);
|
|
7089
|
+
return { pem, issuerId };
|
|
7090
|
+
} catch (err) {
|
|
7091
|
+
console.log(`[iris] fetchApiKeyPrivateKey error: ${err.message}`);
|
|
7092
|
+
return null;
|
|
7093
|
+
}
|
|
7094
|
+
}
|
|
7095
|
+
/**
|
|
7096
|
+
* @deprecated Kept as a fallback probe for debugging. The real path
|
|
7097
|
+
* is the sparse fieldset above — everything in this brute-force list
|
|
7098
|
+
* returned 404 during testing. Left here so we can re-verify if Apple
|
|
7099
|
+
* changes anything.
|
|
7100
|
+
*/
|
|
7101
|
+
async fetchApiKeyPrivateKeyBruteForce(keyId) {
|
|
7102
|
+
const attempts = [
|
|
7103
|
+
// Sparse fieldsets — JSON-API spec lets us request specific attributes.
|
|
7104
|
+
// Apple may exclude privateKey by default and return it only when asked.
|
|
7105
|
+
{ kind: "GET", path: `/apiKeys/${keyId}?fields[apiKeys]=privateKey,kid,issuerId,nickname,roles` },
|
|
7106
|
+
{ kind: "GET", path: `/apiKeys/${keyId}?include=privateKey` },
|
|
7107
|
+
{ kind: "GET", path: `/apiKeys/${keyId}?fields[apiKeys]=privateKey` },
|
|
7108
|
+
// Custom Accept headers — maybe Apple negotiates content type
|
|
7109
|
+
{ kind: "GET", path: `/apiKeys/${keyId}`, accept: "application/x-pem-file" },
|
|
7110
|
+
{ kind: "GET", path: `/apiKeys/${keyId}`, accept: "application/octet-stream" },
|
|
7111
|
+
{ kind: "GET", path: `/apiKeys/${keyId}/p8`, accept: "application/x-pem-file" },
|
|
7112
|
+
// POST variants — Apple sometimes uses POST to mint a download token
|
|
7113
|
+
{ kind: "POST", path: `/apiKeys/${keyId}/secrets`, body: {} },
|
|
7114
|
+
{ kind: "POST", path: `/apiKeys/${keyId}/regenerate`, body: {} },
|
|
7115
|
+
{ kind: "POST", path: `/apiKeys/${keyId}/p8`, body: {} },
|
|
7116
|
+
// Bare GET (last) — confirms canonical fields, in case my parser missed any
|
|
7117
|
+
{ kind: "GET", path: `/apiKeys/${keyId}` },
|
|
7118
|
+
// Different host — the legacy developer.apple.com user-and-access namespace
|
|
7119
|
+
{ kind: "ABSOLUTE", url: `https://appstoreconnect.apple.com/api/v1/apiKeys/${keyId}/p8` },
|
|
7120
|
+
{ kind: "ABSOLUTE", url: `https://appstoreconnect.apple.com/access/api/keys/${keyId}/download` }
|
|
7121
|
+
];
|
|
7122
|
+
for (const attempt of attempts) {
|
|
7123
|
+
try {
|
|
7124
|
+
let result;
|
|
7125
|
+
if (attempt.kind === "GET") {
|
|
7126
|
+
result = await this.requestWithHeaders("GET", attempt.path, void 0, {
|
|
7127
|
+
...attempt.accept ? { Accept: attempt.accept } : {}
|
|
7128
|
+
});
|
|
7129
|
+
console.log(`[iris] fetchApiKeyPrivateKey GET ${attempt.path}${attempt.accept ? ` accept=${attempt.accept}` : ""} \u2192 ${result.status} (${result.rawText.length} bytes)`);
|
|
7130
|
+
} else if (attempt.kind === "POST") {
|
|
7131
|
+
result = await this.request("POST", attempt.path, attempt.body);
|
|
7132
|
+
console.log(`[iris] fetchApiKeyPrivateKey POST ${attempt.path} \u2192 ${result.status} (${result.rawText.length} bytes)`);
|
|
7133
|
+
} else {
|
|
7134
|
+
result = await this.requestAbsolute("GET", attempt.url);
|
|
7135
|
+
console.log(`[iris] fetchApiKeyPrivateKey GET ${attempt.url} \u2192 ${result.status} (${result.rawText.length} bytes)`);
|
|
7136
|
+
}
|
|
7137
|
+
if (result.status === 200) {
|
|
7138
|
+
console.log(`[iris] body: ${result.rawText.slice(0, 1500)}`);
|
|
7139
|
+
}
|
|
7140
|
+
if (result.status !== 200) continue;
|
|
7141
|
+
if (result.rawText && result.rawText.includes("BEGIN PRIVATE KEY")) {
|
|
7142
|
+
console.log(`[iris] \u2713 found PEM (plain text response)`);
|
|
7143
|
+
return result.rawText;
|
|
7144
|
+
}
|
|
7145
|
+
if (result.body) {
|
|
7146
|
+
const candidates = [
|
|
7147
|
+
result.body?.data?.attributes?.privateKey,
|
|
7148
|
+
result.body?.data?.attributes?.p8,
|
|
7149
|
+
result.body?.data?.attributes?.privateKeyContent,
|
|
7150
|
+
result.body?.data?.attributes?.kpem,
|
|
7151
|
+
result.body?.data?.attributes?.secret,
|
|
7152
|
+
result.body?.data?.attributes?.keyContent,
|
|
7153
|
+
result.body?.privateKey,
|
|
7154
|
+
result.body?.p8,
|
|
7155
|
+
result.body?.value,
|
|
7156
|
+
result.body?.secret
|
|
7157
|
+
];
|
|
7158
|
+
for (const c of candidates) {
|
|
7159
|
+
if (typeof c === "string" && c.includes("BEGIN PRIVATE KEY")) {
|
|
7160
|
+
console.log(`[iris] \u2713 found PEM in JSON response`);
|
|
7161
|
+
return c;
|
|
7162
|
+
}
|
|
7163
|
+
}
|
|
7164
|
+
}
|
|
7165
|
+
} catch (err) {
|
|
7166
|
+
console.log(`[iris] fetchApiKeyPrivateKey attempt failed: ${err.message}`);
|
|
7167
|
+
}
|
|
7168
|
+
}
|
|
7169
|
+
console.log(`[iris] fetchApiKeyPrivateKey: no working download path for key ${keyId}`);
|
|
7170
|
+
return null;
|
|
7171
|
+
}
|
|
7172
|
+
/** Internal: like request() but lets us override headers. */
|
|
7173
|
+
async requestWithHeaders(method, path, body, extraHeaders = {}) {
|
|
7174
|
+
const headers = { ...this.buildHeaders(), ...extraHeaders };
|
|
7175
|
+
const res = await fetch(`${IRIS_BASE}${path}`, {
|
|
7176
|
+
method,
|
|
7177
|
+
headers,
|
|
7178
|
+
body: body ? JSON.stringify(body) : void 0
|
|
7179
|
+
});
|
|
7180
|
+
for (const raw of res.headers.getSetCookie?.() ?? []) {
|
|
7181
|
+
const m = raw.match(/^([^=]+)=([^;]*)/);
|
|
7182
|
+
if (m) this.session.cookies[m[1]] = m[2];
|
|
7183
|
+
}
|
|
7184
|
+
this.cookieStr = Object.entries(this.session.cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
7185
|
+
const text = await res.text();
|
|
7186
|
+
let parsed = null;
|
|
7187
|
+
try {
|
|
7188
|
+
parsed = text ? JSON.parse(text) : null;
|
|
7189
|
+
} catch {
|
|
7190
|
+
}
|
|
7191
|
+
return { status: res.status, body: parsed, rawText: text };
|
|
7192
|
+
}
|
|
7193
|
+
/** Internal: fetch an absolute URL with the session cookies. */
|
|
7194
|
+
async requestAbsolute(method, url) {
|
|
7195
|
+
const headers = this.buildHeaders();
|
|
7196
|
+
const res = await fetch(url, { method, headers });
|
|
7197
|
+
const text = await res.text();
|
|
7198
|
+
let parsed = null;
|
|
7199
|
+
try {
|
|
7200
|
+
parsed = text ? JSON.parse(text) : null;
|
|
7201
|
+
} catch {
|
|
7202
|
+
}
|
|
7203
|
+
return { status: res.status, body: parsed, rawText: text };
|
|
7204
|
+
}
|
|
7205
|
+
async deleteApiKey(keyId) {
|
|
7206
|
+
await this.request("DELETE", `/apiKeys/${keyId}`);
|
|
7207
|
+
}
|
|
7208
|
+
};
|
|
7209
|
+
IrisAuthError = class extends Error {
|
|
7210
|
+
constructor(message) {
|
|
7211
|
+
super(message);
|
|
7212
|
+
this.name = "IrisAuthError";
|
|
7213
|
+
}
|
|
7214
|
+
};
|
|
7215
|
+
}
|
|
7216
|
+
});
|
|
7217
|
+
|
|
6576
7218
|
// src/client/index.ts
|
|
6577
7219
|
var client_exports = {};
|
|
6578
7220
|
__export(client_exports, {
|
|
6579
7221
|
AppStoreConnectClient: () => AppStoreConnectClient,
|
|
6580
7222
|
AppStoreConnectError: () => AppStoreConnectError,
|
|
7223
|
+
IrisAuthError: () => IrisAuthError,
|
|
7224
|
+
IrisClient: () => IrisClient,
|
|
6581
7225
|
PortalClient: () => PortalClient,
|
|
6582
7226
|
ProgramLicenseAgreementError: () => ProgramLicenseAgreementError,
|
|
6583
7227
|
RateLimitError: () => RateLimitError,
|
|
6584
7228
|
RequestClient: () => RequestClient,
|
|
6585
7229
|
TokenManager: () => TokenManager,
|
|
7230
|
+
beginLogin: () => beginLogin,
|
|
6586
7231
|
checkPortalResponse: () => checkPortalResponse,
|
|
6587
|
-
loginWithAppleId: () => loginWithAppleId
|
|
7232
|
+
loginWithAppleId: () => loginWithAppleId,
|
|
7233
|
+
requestSmsCode: () => requestSmsCode,
|
|
7234
|
+
submitTwoFactorCode: () => submitTwoFactorCode
|
|
6588
7235
|
});
|
|
6589
7236
|
var AppStoreConnectClient;
|
|
6590
7237
|
var init_client = __esm({
|
|
@@ -6629,6 +7276,7 @@ var init_client = __esm({
|
|
|
6629
7276
|
init_request();
|
|
6630
7277
|
init_apple_session();
|
|
6631
7278
|
init_portal();
|
|
7279
|
+
init_iris();
|
|
6632
7280
|
AppStoreConnectClient = class {
|
|
6633
7281
|
http;
|
|
6634
7282
|
certificates;
|