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