@superwall/cli 1.7.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -52
- package/dist/{setup-Bxj22rYi.js → apple-CSzNTGHM.js} +82 -76
- package/dist/auth.d.ts +4 -19
- package/dist/auth.js +4 -2
- package/dist/{actions-B7ym3oVS.js → billing-C3Q8DBU2.js} +98 -28
- package/dist/{bind-YrJvuRF9.js → bind-BumHTi9O.js} +38 -33
- package/dist/{build-DLoCW5Ri.js → build-Bpviiclc.js} +20 -26
- package/dist/client-BL0f_yGf.js +176 -0
- package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
- package/dist/config-BO1Y87kV.js +105 -0
- package/dist/create-BSfvpWoD.js +19 -0
- package/dist/{create-pkANt1Gs.js → create-BUcVG4Ab.js} +195 -169
- package/dist/{notification-url-DuKF2659.js → create-CfK3PeKA.js} +235 -539
- package/dist/doctor-BWqIYcMn.js +83 -0
- package/dist/{drivers-Qx9LxmRN.js → drivers-CPhdPkW5.js} +185 -172
- package/dist/entry.d.ts +0 -5
- package/dist/entry.js +28072 -1134
- package/dist/environment-eBXjELoN.js +58 -0
- package/dist/{existing-AVEfZu2A.js → existing-BltvQiX5.js} +12 -6
- package/dist/held-CPve03KJ.js +16 -0
- package/dist/held-DgnTFMl3.js +1112 -0
- package/dist/input-vi0bou04.js +42 -0
- package/dist/{integrate-brmhPG-S.js → integrate-BRsqoe01.js} +277 -254
- package/dist/log-NVhVe_oe.js +62 -0
- package/dist/login-BCEH5q0U.js +53 -0
- package/dist/login-BPOONe7n.js +16 -0
- package/dist/{login-Do4wFuLv.js → login-BbTIrCFT.js} +118 -55
- package/dist/lookup-rr1AkCJA.js +71 -0
- package/dist/migrate-C9X2Vz81.js +274 -0
- package/dist/notification-url-CV86qiKP.js +100 -0
- package/dist/{open-studio-DOw-6ydc.js → open-CcpXotHG.js} +34 -43
- package/dist/org-BQQDo7wm.js +35 -0
- package/dist/output-Ggzq5_-t.js +122 -0
- package/dist/paths-CRlU72cq.js +29 -0
- package/dist/playbook-DVMXN7fh.js +53 -0
- package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
- package/dist/promote-Da8xctzy.js +91 -0
- package/dist/push-BV-grvQg.js +22 -0
- package/dist/push-D6R9icWN.js +495 -0
- package/dist/registry-BYVD-_h6.js +10385 -0
- package/dist/{reports-CfJqoava.js → reports-D_qbl7_u.js} +7 -6
- package/dist/{resources-Bf9O1JNM.js → resources-DLON3-61.js} +162 -55
- package/dist/{run-DsVZ5snL.js → run-Co-BwhOg.js} +16 -22
- package/dist/scan-B88OlWOt.js +4 -0
- package/dist/{scan-zKsddO72.js → scan-CKuk-_6W.js} +48 -37
- package/dist/scope-DV22_Ufm.js +198 -0
- package/dist/screenshot-file-tVBfUEIi.js +16 -0
- package/dist/{selection-CxZoX4NT.js → selection-C2_KbLuo.js} +100 -51
- package/dist/server-C4f6ccUr.js +22 -0
- package/dist/{dev-DmB3XqaJ.js → server-D0d2oP-5.js} +86 -94
- package/dist/session-B-Uz0cQ7.js +40 -0
- package/dist/session-BuvArt1j.js +6 -0
- package/dist/session-C4rbE3VS.js +796 -0
- package/dist/skills/animate-onboarding/SKILL.md +467 -0
- package/dist/skills/animate-onboarding/references/engine.md +494 -0
- package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
- package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
- package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
- package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
- package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
- package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
- package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
- package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
- package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
- package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
- package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
- package/dist/skills/animate-onboarding/references/performance.md +41 -0
- package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
- package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
- package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
- package/dist/skills/index.json +37 -0
- package/dist/skills/mobile-design/SKILL.md +447 -0
- package/dist/skills/mobile-design/references/responsive.md +162 -0
- package/dist/skills/onboarding-questions/SKILL.md +231 -0
- package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
- package/dist/skills/onboarding-questions/references/craft.md +142 -0
- package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
- package/dist/skills/superwall/SKILL.md +82 -9
- package/dist/skills/superwall/references/api.md +153 -37
- package/dist/skills/superwall/references/apple-setup.md +316 -0
- package/dist/skills/superwall/references/asc.md +74 -38
- package/dist/skills/superwall/references/data-analytics.md +55 -21
- package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
- package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
- package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
- package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
- package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
- package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
- package/dist/skills/superwall/workflows/placements/android.md +2 -2
- package/dist/skills/superwall/workflows/placements/expo.md +2 -2
- package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
- package/dist/skills/superwall/workflows/placements/ios.md +2 -2
- package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
- package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
- package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
- package/dist/skills/superwall/workflows/review/playbook.md +1 -1
- package/dist/skills/superwall-editor/SKILL.md +61 -0
- package/dist/skills/superwall-editor/references/cli.md +135 -0
- package/dist/skills/superwall-editor/references/design.md +51 -0
- package/dist/skills/superwall-editor/references/native-elements.md +171 -0
- package/dist/skills/superwall-editor/references/workflow.md +65 -0
- package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
- package/dist/skills/superwall-framework/SKILL.md +85 -31
- package/dist/skills/superwall-framework/references/cli.md +58 -27
- package/dist/skills/superwall-framework/references/examples.md +4 -3
- package/dist/skills/superwall-framework/references/layout.md +64 -9
- package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
- package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
- package/dist/skills/wwdc/SKILL.md +22 -0
- package/dist/skills/wwdc/references/docs.md +52 -0
- package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
- package/dist/skills-CLGJuMnF.js +14 -0
- package/dist/{skills-DPzlnfCK.js → skills-CZcpnEnG.js} +100 -122
- package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
- package/dist/spinner-C2U6QBJ9.js +294 -0
- package/dist/storage-6h9vyiAz.js +31 -0
- package/dist/storage-CerJ5KLP.d.ts +16 -0
- package/dist/storekit-CK9JmM2D.js +16 -0
- package/dist/storekit-CinJra3V.js +47 -0
- package/dist/telemetry-DKyDhURo.js +56 -0
- package/dist/theme-DUsCh-Vd.js +25 -0
- package/dist/timing-BVxPrYq3.js +5 -0
- package/dist/{token-C0it-Xh7.js → token-DaxQgQkv.js} +6 -38
- package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
- package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
- package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
- package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
- package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
- package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
- package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
- package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
- package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
- package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
- package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
- package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
- package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
- package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
- package/dist/tools-skills/mobile-design/SKILL.md +447 -0
- package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
- package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
- package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
- package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
- package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
- package/dist/tools-skills/superwall/SKILL.md +263 -0
- package/dist/tools-skills/superwall/references/api.md +303 -0
- package/dist/tools-skills/superwall/references/asa.md +166 -0
- package/dist/tools-skills/superwall/references/asc.md +95 -0
- package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
- package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
- package/dist/tools-skills/superwall/references/docs.md +51 -0
- package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
- package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
- package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
- package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
- package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
- package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
- package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
- package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
- package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
- package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
- package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
- package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
- package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
- package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
- package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
- package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
- package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
- package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
- package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
- package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
- package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
- package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
- package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
- package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
- package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
- package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
- package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
- package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
- package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
- package/dist/tools-skills/superwall-editor/references/design.md +51 -0
- package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
- package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
- package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
- package/dist/tools-skills/wwdc/SKILL.md +22 -0
- package/dist/tools-skills/wwdc/references/docs.md +52 -0
- package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
- package/dist/tools.d.ts +96 -0
- package/dist/tools.js +11360 -0
- package/dist/ui-D_qf3Gvw.js +53 -0
- package/dist/upgrade-DPo0a4Es.js +117 -0
- package/dist/upgrade-ffseQDMx.js +7 -0
- package/package.json +10 -5
- package/dist/api-CZzirVMj.js +0 -151
- package/dist/api-output-aJNw7Syy.js +0 -20
- package/dist/app-DH6U8yuI.js +0 -190
- package/dist/asa-C-sQzPPn.js +0 -1194
- package/dist/asc-1ZBJ6DwS.js +0 -778
- package/dist/auth-YRhlV3DE.js +0 -140
- package/dist/billing-CCYHdApx.js +0 -80
- package/dist/bundle-id-CKxl_026.js +0 -121
- package/dist/command-CMIz81Da.js +0 -301
- package/dist/dev-DZy6pOnB.js +0 -22
- package/dist/doctor-H-hf-Yww.js +0 -88
- package/dist/feedback-CKf-rpBW.js +0 -152
- package/dist/hosted-CXe9TrWx.js +0 -32
- package/dist/migrate-C9ERDR6y.js +0 -284
- package/dist/org-sj7uyvp-.js +0 -40
- package/dist/output-C4o2gJ1K.js +0 -146
- package/dist/params-l3CrvRtR.js +0 -51
- package/dist/pipeline-BqzqZhX1.js +0 -977
- package/dist/print-skill-ZojRSybs.js +0 -74
- package/dist/promote-BG8X4Nv_.js +0 -88
- package/dist/publish-sxLh-G4G.js +0 -35
- package/dist/push-bQ6Vxtg8.js +0 -35
- package/dist/query-_FbybaH-.js +0 -53
- package/dist/resource-CGIwSd29.js +0 -323
- package/dist/revenue-provider-ebsRINY8.js +0 -100
- package/dist/scope-BvzD-kO4.js +0 -223
- package/dist/skills-D_R-lEsK.js +0 -64
- package/dist/spinner-TWa0hia6.js +0 -18
- package/dist/storekit-Cj9Cpjcz.js +0 -29
- package/dist/telemetry-DeA1mvnT.js +0 -169
- package/dist/ui-Dy0b-9L8.js +0 -27738
- package/dist/update-B2fWIc4q.js +0 -59
- package/dist/upgrade-BmzkTKrh.js +0 -72
- /package/dist/{devtools-8EgLo86w.js → devtools-pBl_vt03.js} +0 -0
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { r as formatJson, t as blocks } from "./output-Ggzq5_-t.js";
|
|
2
|
+
import { _ as VERSION, d as ENV_APPLE_PASSWORD, u as ENV_APPLE_ID, y as appleCredentialsFromEnv } from "./environment-eBXjELoN.js";
|
|
3
|
+
import { t as ApiError } from "./client-BL0f_yGf.js";
|
|
4
|
+
import { i as savedKey, m as KEY_LABEL, n as testModeWarning, o as chooseIosApp, s as resolveApp, t as upsertHeldKey, x as keyKind, y as findIntegrations } from "./held-DgnTFMl3.js";
|
|
5
|
+
import { t as apiCall } from "./spinner-C2U6QBJ9.js";
|
|
6
|
+
import { n as SUPERWALL_HOME } from "./paths-CRlU72cq.js";
|
|
7
|
+
import { A as parseJson, D as field, j as textField, k as listField } from "./resources-DLON3-61.js";
|
|
8
|
+
import { c as replaceAppPurchaseKey, s as replaceAppAscKey } from "./client-BZ1UbpXz.js";
|
|
9
|
+
import { t as timing } from "./timing-BVxPrYq3.js";
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
8
11
|
import { join } from "node:path";
|
|
9
|
-
import { homedir } from "node:os";
|
|
10
12
|
import { createHash, pbkdf2Sync, randomBytes } from "node:crypto";
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
12
13
|
|
|
13
|
-
//#region src/core/apple/pending.ts
|
|
14
|
+
//#region src/core/app-store-connect/apple-web/pending.ts
|
|
14
15
|
const LIFETIME_MS = 600 * 1e3;
|
|
15
16
|
function dir() {
|
|
16
|
-
return SUPERWALL_HOME()
|
|
17
|
+
return SUPERWALL_HOME();
|
|
17
18
|
}
|
|
18
19
|
function file() {
|
|
19
20
|
return join(dir(), "apple-sign-in.json");
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function writePending(pending, now = Date.now()) {
|
|
22
23
|
mkdirSync(dir(), {
|
|
23
24
|
recursive: true,
|
|
24
25
|
mode: 448
|
|
@@ -29,12 +30,12 @@ function savePending(pending, now = Date.now()) {
|
|
|
29
30
|
};
|
|
30
31
|
writeFileSync(file(), `${formatJson(stored)}\n`, { mode: 384 });
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
+
function readPending(now = Date.now()) {
|
|
33
34
|
try {
|
|
34
35
|
if (!existsSync(file())) return void 0;
|
|
35
36
|
const stored = JSON.parse(readFileSync(file(), "utf8"));
|
|
36
37
|
if (now - stored.savedAt > LIFETIME_MS) {
|
|
37
|
-
|
|
38
|
+
removePending();
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
41
|
return stored.pending;
|
|
@@ -42,12 +43,12 @@ function loadPending(now = Date.now()) {
|
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
+
function removePending() {
|
|
46
47
|
rmSync(file(), { force: true });
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
//#endregion
|
|
50
|
-
//#region src/core/apple/cookies.ts
|
|
51
|
+
//#region src/core/app-store-connect/apple-web/cookies.ts
|
|
51
52
|
function parse(url, line) {
|
|
52
53
|
const [pair = "", ...attributes] = line.split(";");
|
|
53
54
|
const separator = pair.indexOf("=");
|
|
@@ -87,7 +88,9 @@ function matches(cookie, url) {
|
|
|
87
88
|
}
|
|
88
89
|
function createCookieJar(initial = []) {
|
|
89
90
|
let cookies = [...initial];
|
|
90
|
-
const same = (a, b) =>
|
|
91
|
+
const same = (a, b) => {
|
|
92
|
+
return a.name === b.name && a.domain === b.domain && a.path === b.path;
|
|
93
|
+
};
|
|
91
94
|
return {
|
|
92
95
|
store(url, setCookie) {
|
|
93
96
|
for (const line of setCookie) {
|
|
@@ -99,19 +102,20 @@ function createCookieJar(initial = []) {
|
|
|
99
102
|
},
|
|
100
103
|
header(url) {
|
|
101
104
|
const sent = cookies.filter((cookie) => matches(cookie, url));
|
|
102
|
-
|
|
105
|
+
if (sent.length === 0) return void 0;
|
|
106
|
+
return sent.map((cookie) => `${cookie.name}=${cookie.value}`).join("; ");
|
|
103
107
|
},
|
|
104
108
|
snapshot: () => cookies.map((cookie) => ({ ...cookie }))
|
|
105
109
|
};
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
//#endregion
|
|
109
|
-
//#region src/core/apple/hashcash.ts
|
|
113
|
+
//#region src/core/app-store-connect/apple-web/hashcash.ts
|
|
110
114
|
function leadingZeroBits(sum, bits) {
|
|
111
115
|
const whole = Math.floor(bits / 8);
|
|
112
116
|
for (let index = 0; index < whole; index++) if (sum[index] !== 0) return false;
|
|
113
117
|
const remaining = bits % 8;
|
|
114
|
-
return remaining === 0 || (sum
|
|
118
|
+
return remaining === 0 || (sum.readUInt8(whole) & 255 << 8 - remaining) === 0;
|
|
115
119
|
}
|
|
116
120
|
const two = (value) => String(value).padStart(2, "0");
|
|
117
121
|
function mintHashcash(bits, challenge, now) {
|
|
@@ -123,7 +127,7 @@ function mintHashcash(bits, challenge, now) {
|
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
//#endregion
|
|
126
|
-
//#region src/core/apple/srp.ts
|
|
130
|
+
//#region src/core/app-store-connect/apple-web/srp.ts
|
|
127
131
|
const MODULUS_HEX = "ac6bdb41324a9a9bf166de5e1389582faf72b6651987ee07fc3192943db56050a37329cbb4a099ed8193e0757767a13dd52312ab4b03310dcd7f48a9da04fd50e8083969edb767b0cf6095179a163ab3661a05fbd5faaae82918a9962f0b93b855f97993ec975eeaa80d740adbf4ff747359d041d5c33ea71d281e446b14773bca97b43a23fb801676bd207a436c6481f1d2b9078717461a5b9d32e688f87748544523b524b0d57d5ea77a2775d2ecfa032cfbdbf52fb3786160279004e57ae6af874e7303ce53299ccc041c7bc308d82a5698f3a8d0c38271ae35f8e9dbfbb694b5c803d89f7ae435de236d525f54759b65e372fcd68ef20fa7111f9e4aff73";
|
|
128
132
|
const MODULUS = BigInt(`0x${MODULUS_HEX}`);
|
|
129
133
|
const GENERATOR = 2n;
|
|
@@ -136,7 +140,9 @@ const evenHex = (value) => {
|
|
|
136
140
|
const hex = value.toString(16);
|
|
137
141
|
return hex.length % 2 === 1 ? `0${hex}` : hex;
|
|
138
142
|
};
|
|
139
|
-
const paddedHash = (...values) =>
|
|
143
|
+
const paddedHash = (...values) => {
|
|
144
|
+
return BigInt(`0x${hashHex(values.map((value) => value.padStart(WIDTH, "0")).join(""))}`);
|
|
145
|
+
};
|
|
140
146
|
function modPow(base, exponent, modulus) {
|
|
141
147
|
let result = 1n;
|
|
142
148
|
let factor = base % modulus;
|
|
@@ -175,7 +181,7 @@ function createProof(input) {
|
|
|
175
181
|
const sessionKey = hashHex(evenHex(modPow(((serverPublic - k * modPow(GENERATOR, x, MODULUS) % MODULUS) % MODULUS + MODULUS) % MODULUS, input.secret + u * x, MODULUS)));
|
|
176
182
|
const modulusHash = digest(Buffer.from(MODULUS_HEX, "hex"));
|
|
177
183
|
const generatorHash = digest(Buffer.from(evenHex(GENERATOR).padStart(WIDTH, "0"), "hex"));
|
|
178
|
-
const mixed = Buffer.from(modulusHash.map((byte, index) => byte ^ generatorHash
|
|
184
|
+
const mixed = Buffer.from(modulusHash.map((byte, index) => byte ^ generatorHash.readUInt8(index)));
|
|
179
185
|
const accountHash = digest(Buffer.from(input.accountName, "utf8")).toString("hex");
|
|
180
186
|
const m1 = hashHex(mixed.toString("hex") + accountHash + saltHex + clientHex + serverHex + sessionKey);
|
|
181
187
|
const m2 = hashHex(clientHex + m1 + sessionKey);
|
|
@@ -186,7 +192,7 @@ function createProof(input) {
|
|
|
186
192
|
}
|
|
187
193
|
|
|
188
194
|
//#endregion
|
|
189
|
-
//#region src/core/apple/transport.ts
|
|
195
|
+
//#region src/core/app-store-connect/apple-web/transport.ts
|
|
190
196
|
const MAX_REDIRECTS = 5;
|
|
191
197
|
var AppleUnreachableError = class extends Error {
|
|
192
198
|
constructor(cause) {
|
|
@@ -234,28 +240,9 @@ function createTransport(jar, doFetch = fetch) {
|
|
|
234
240
|
}
|
|
235
241
|
} };
|
|
236
242
|
}
|
|
237
|
-
function parseJson(body) {
|
|
238
|
-
if (body.trim() === "") return void 0;
|
|
239
|
-
try {
|
|
240
|
-
return JSON.parse(body);
|
|
241
|
-
} catch {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function field(value, key) {
|
|
246
|
-
return typeof value === "object" && value !== null ? Reflect.get(value, key) : void 0;
|
|
247
|
-
}
|
|
248
|
-
function textField(value, key) {
|
|
249
|
-
const found = field(value, key);
|
|
250
|
-
return typeof found === "string" && found.trim() !== "" ? found.trim() : void 0;
|
|
251
|
-
}
|
|
252
|
-
function listField(value, key) {
|
|
253
|
-
const found = field(value, key);
|
|
254
|
-
return Array.isArray(found) ? found : [];
|
|
255
|
-
}
|
|
256
243
|
|
|
257
244
|
//#endregion
|
|
258
|
-
//#region src/core/apple/session.ts
|
|
245
|
+
//#region src/core/app-store-connect/apple-web/session.ts
|
|
259
246
|
const AUTH_URL = "https://idmsa.apple.com/appleauth/auth";
|
|
260
247
|
const ASC_URL = "https://appstoreconnect.apple.com";
|
|
261
248
|
var AppleError = class extends Error {
|
|
@@ -332,7 +319,7 @@ function createAppleSession(options = {}) {
|
|
|
332
319
|
if (response.status < 200 || response.status >= 300 || serviceMessages(parsed).length > 0) throw new AppleError("verification", failureMessage(response), response.status);
|
|
333
320
|
return parsed;
|
|
334
321
|
};
|
|
335
|
-
const
|
|
322
|
+
const resolveServiceKey = async () => {
|
|
336
323
|
let location;
|
|
337
324
|
try {
|
|
338
325
|
location = (await doFetch(`${ASC_URL}/logout`, {
|
|
@@ -342,18 +329,19 @@ function createAppleSession(options = {}) {
|
|
|
342
329
|
} catch (error) {
|
|
343
330
|
throw new AppleUnreachableError(error);
|
|
344
331
|
}
|
|
345
|
-
|
|
332
|
+
if (!location) throw new AppleError("request", "Apple didn't return its sign-in configuration.");
|
|
333
|
+
const key = new URL(location, ASC_URL).searchParams.get("widgetKey")?.trim();
|
|
346
334
|
if (!key) throw new AppleError("request", "Apple didn't return its sign-in configuration.");
|
|
347
335
|
return key;
|
|
348
336
|
};
|
|
349
|
-
const
|
|
337
|
+
const createHashcash = async () => {
|
|
350
338
|
const response = await transport.send("GET", `${AUTH_URL}/signin?widgetKey=${encodeURIComponent(serviceKey)}`);
|
|
351
339
|
const bits = Number(response.headers.get("x-apple-hc-bits"));
|
|
352
340
|
const challenge = response.headers.get("x-apple-hc-challenge");
|
|
353
341
|
if (!challenge || !Number.isInteger(bits) || bits <= 0) return void 0;
|
|
354
342
|
return mintHashcash(bits, challenge, now());
|
|
355
343
|
};
|
|
356
|
-
const
|
|
344
|
+
const resolveTeams = async () => {
|
|
357
345
|
const response = await transport.send("GET", `${ASC_URL}/olympus/v1/session`);
|
|
358
346
|
if (response.status < 200 || response.status >= 300) throw new AppleError(response.status === 401 || response.status === 403 ? "forbidden" : "request", `App Store Connect didn't accept the sign-in: ${failureMessage(response)}`, response.status);
|
|
359
347
|
const body = parseJson(response.body);
|
|
@@ -363,15 +351,17 @@ function createAppleSession(options = {}) {
|
|
|
363
351
|
appleId = textField(field(body, "user"), "emailAddress") ?? appleId;
|
|
364
352
|
if (!current) throw new AppleError("forbidden", "This Apple Account has no App Store Connect team. Join the Apple Developer Program or accept your team invite, then try again.");
|
|
365
353
|
};
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
354
|
+
const listTrustedPhones = (optionsBody) => {
|
|
355
|
+
return listField(optionsBody, "trustedPhoneNumbers").flatMap((phone) => {
|
|
356
|
+
const id = field(phone, "id");
|
|
357
|
+
if (typeof id !== "number") return [];
|
|
358
|
+
return [{
|
|
359
|
+
id,
|
|
360
|
+
mode: textField(phone, "pushMode") ?? "sms",
|
|
361
|
+
label: textField(phone, "numberWithDialCode") ?? ""
|
|
362
|
+
}];
|
|
363
|
+
});
|
|
364
|
+
};
|
|
375
365
|
const requireContinuation = () => {
|
|
376
366
|
if (!serviceKey || !sessionId || !scnt) throw new AppleError("verification", "The Apple sign-in expired. Start again.");
|
|
377
367
|
};
|
|
@@ -381,7 +371,7 @@ function createAppleSession(options = {}) {
|
|
|
381
371
|
sessionId = "";
|
|
382
372
|
scnt = "";
|
|
383
373
|
factor = void 0;
|
|
384
|
-
serviceKey = await
|
|
374
|
+
serviceKey = await resolveServiceKey();
|
|
385
375
|
const ephemeral = createEphemeral(options.random);
|
|
386
376
|
const init = await transport.send("POST", `${AUTH_URL}/signin/init`, {
|
|
387
377
|
headers: authHeaders(),
|
|
@@ -407,7 +397,7 @@ function createAppleSession(options = {}) {
|
|
|
407
397
|
serverPublicKey,
|
|
408
398
|
secret: ephemeral.secret
|
|
409
399
|
});
|
|
410
|
-
const hashcash = await
|
|
400
|
+
const hashcash = await createHashcash();
|
|
411
401
|
const complete = await transport.send("POST", `${AUTH_URL}/signin/complete?isRememberMeEnabled=false`, {
|
|
412
402
|
headers: {
|
|
413
403
|
...authHeaders(),
|
|
@@ -430,7 +420,7 @@ function createAppleSession(options = {}) {
|
|
|
430
420
|
if (complete.status === 401 || complete.status === 403) throw new AppleError("credentials", "Incorrect Apple Account email or password.", complete.status);
|
|
431
421
|
if (complete.status === 412) throw new AppleError("account-action", "Apple needs you to review something on this account first. Sign in at https://account.apple.com, finish the prompt, then try again.", complete.status);
|
|
432
422
|
if (complete.status !== 200 || serviceMessages(parseJson(complete.body)).length > 0) throw new AppleError("request", `Apple sign-in failed: ${failureMessage(complete)}`, complete.status);
|
|
433
|
-
await
|
|
423
|
+
await resolveTeams();
|
|
434
424
|
return "signed-in";
|
|
435
425
|
},
|
|
436
426
|
async requestCode(request = {}) {
|
|
@@ -439,7 +429,7 @@ function createAppleSession(options = {}) {
|
|
|
439
429
|
const length = field(field(body, "securityCode"), "length");
|
|
440
430
|
const codeLength = typeof length === "number" && length > 0 ? length : 6;
|
|
441
431
|
const noTrustedDevices = field(body, "noTrustedDevices") === true;
|
|
442
|
-
const phones =
|
|
432
|
+
const phones = listTrustedPhones(body);
|
|
443
433
|
if (!request.sms && !request.phone && !noTrustedDevices) {
|
|
444
434
|
factor = {
|
|
445
435
|
method: "device",
|
|
@@ -451,8 +441,9 @@ function createAppleSession(options = {}) {
|
|
|
451
441
|
};
|
|
452
442
|
}
|
|
453
443
|
if (phones.length === 0) throw new AppleError("verification", "This Apple Account has no trusted phone number.");
|
|
454
|
-
const
|
|
455
|
-
|
|
444
|
+
const wanted = request.phone;
|
|
445
|
+
const phone = wanted ? phones.find((candidate) => phoneMatches(wanted, candidate.label)) : phones[0];
|
|
446
|
+
if (!phone) throw new AppleError("verification", `No trusted phone number matches ${wanted}. Apple lists: ${phones.map((candidate) => candidate.label).join(", ")}.`);
|
|
456
447
|
if (!(noTrustedDevices && phones.length === 1)) await auth("PUT", "/verify/phone", {
|
|
457
448
|
phoneNumber: { id: phone.id },
|
|
458
449
|
mode: phone.mode
|
|
@@ -480,7 +471,7 @@ function createAppleSession(options = {}) {
|
|
|
480
471
|
});
|
|
481
472
|
else await auth("POST", "/verify/trusteddevice/securitycode", { securityCode });
|
|
482
473
|
await auth("GET", "/2sv/trust");
|
|
483
|
-
await
|
|
474
|
+
await resolveTeams();
|
|
484
475
|
},
|
|
485
476
|
pending() {
|
|
486
477
|
requireContinuation();
|
|
@@ -506,7 +497,7 @@ function createAppleSession(options = {}) {
|
|
|
506
497
|
body: { provider: { providerId: id } }
|
|
507
498
|
});
|
|
508
499
|
if (response.status < 200 || response.status >= 300) throw new AppleError("request", `Couldn't switch Apple team: ${failureMessage(response)}`, response.status);
|
|
509
|
-
await
|
|
500
|
+
await resolveTeams();
|
|
510
501
|
if (current?.id !== id) throw new AppleError("request", `Apple didn't switch to team ${id}.`);
|
|
511
502
|
},
|
|
512
503
|
async iris(method, path, request = {}) {
|
|
@@ -527,16 +518,16 @@ function createAppleSession(options = {}) {
|
|
|
527
518
|
}
|
|
528
519
|
|
|
529
520
|
//#endregion
|
|
530
|
-
//#region src/
|
|
521
|
+
//#region src/core/app-store-connect/setup/deps.ts
|
|
531
522
|
const appleDeps = {
|
|
532
523
|
session: createAppleSession,
|
|
533
524
|
credentials: appleCredentialsFromEnv,
|
|
534
525
|
pending: {
|
|
535
|
-
load: () =>
|
|
536
|
-
save: (pending) =>
|
|
537
|
-
clear:
|
|
526
|
+
load: () => readPending(),
|
|
527
|
+
save: (pending) => writePending(pending),
|
|
528
|
+
clear: removePending
|
|
538
529
|
},
|
|
539
|
-
sleep: (ms) =>
|
|
530
|
+
sleep: (ms) => timing.sleep(ms),
|
|
540
531
|
writeKeyFile: (name, privateKey) => {
|
|
541
532
|
const path = join(process.cwd(), name);
|
|
542
533
|
writeFileSync(path, privateKey, { mode: 384 });
|
|
@@ -545,266 +536,7 @@ const appleDeps = {
|
|
|
545
536
|
};
|
|
546
537
|
|
|
547
538
|
//#endregion
|
|
548
|
-
//#region src/core/
|
|
549
|
-
function readApps(body) {
|
|
550
|
-
return listField(body, "data").flatMap((app) => {
|
|
551
|
-
const id = textField(app, "id");
|
|
552
|
-
if (!id) return [];
|
|
553
|
-
const attributes = field(app, "attributes");
|
|
554
|
-
return [{
|
|
555
|
-
id,
|
|
556
|
-
name: textField(attributes, "name"),
|
|
557
|
-
bundleId: textField(attributes, "bundleId")
|
|
558
|
-
}];
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
async function listApps(session) {
|
|
562
|
-
return readApps(await session.iris("GET", "/apps", { query: { limit: "200" } }));
|
|
563
|
-
}
|
|
564
|
-
async function findApp(session, bundleId) {
|
|
565
|
-
return readApps(await session.iris("GET", "/apps", { query: {
|
|
566
|
-
"filter[bundleId]": bundleId,
|
|
567
|
-
limit: "10"
|
|
568
|
-
} })).find((app) => app.bundleId === bundleId);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
//#endregion
|
|
572
|
-
//#region src/commands/platform/apple-app.ts
|
|
573
|
-
const NEW_APP = "__new__";
|
|
574
|
-
const LISTED_APPS = 8;
|
|
575
|
-
const isIos = (app) => (app.platform ?? "").toLowerCase() === "ios";
|
|
576
|
-
async function iosApps(ctx, api, flags) {
|
|
577
|
-
const projects = await apiCall(ctx, "Loading your apps", () => listProjects(api));
|
|
578
|
-
const scoped = flags.project ? projects.filter((project) => String(project.id) === flags.project) : projects;
|
|
579
|
-
if (flags.project && scoped.length === 0) throw new Error(`No project ${flags.project} in this organization.`);
|
|
580
|
-
const candidates = scoped.flatMap((project) => (project.applications ?? []).filter(isIos).map((app) => ({
|
|
581
|
-
project,
|
|
582
|
-
app
|
|
583
|
-
})));
|
|
584
|
-
if (!flags.app) return {
|
|
585
|
-
scoped,
|
|
586
|
-
candidates
|
|
587
|
-
};
|
|
588
|
-
const named = candidates.find(({ app }) => String(app.id) === flags.app || app.name === flags.app);
|
|
589
|
-
if (!named) throw new Error(`No iOS app ${flags.app} in this organization.`);
|
|
590
|
-
return {
|
|
591
|
-
scoped,
|
|
592
|
-
candidates,
|
|
593
|
-
named
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
function severalApps(candidates) {
|
|
597
|
-
const shown = candidates.slice(0, LISTED_APPS).map(({ app }) => `${app.id} (${app.name ?? "unnamed"})`).join(", ");
|
|
598
|
-
const more = candidates.length > LISTED_APPS ? `, and ${candidates.length - LISTED_APPS} more (\`superwall apps\` lists them all)` : "";
|
|
599
|
-
return /* @__PURE__ */ new Error(`Several iOS apps found: ${shown}${more}. Pass --app <id>.`);
|
|
600
|
-
}
|
|
601
|
-
const appOptions = (candidates) => candidates.map(({ app, project }) => ({
|
|
602
|
-
value: String(app.id),
|
|
603
|
-
label: app.name ?? String(app.id),
|
|
604
|
-
hint: app.bundle_id ?? project.name
|
|
605
|
-
}));
|
|
606
|
-
async function chooseIosApp(ctx, api, flags) {
|
|
607
|
-
const { candidates, named } = await iosApps(ctx, api, flags);
|
|
608
|
-
if (named) return named;
|
|
609
|
-
if (candidates.length === 0) throw new Error("There's no iOS app in Superwall yet. Create one with `superwall apps create`, or run `superwall setup apple`.");
|
|
610
|
-
if (candidates.length === 1) return candidates[0];
|
|
611
|
-
if (!ctx.interactive) throw severalApps(candidates);
|
|
612
|
-
const picked = await ctx.ui.select({
|
|
613
|
-
message: "Which Superwall app?",
|
|
614
|
-
options: appOptions(candidates)
|
|
615
|
-
});
|
|
616
|
-
if (picked === null) throw new Error("Cancelled.");
|
|
617
|
-
return candidates.find(({ app }) => String(app.id) === picked);
|
|
618
|
-
}
|
|
619
|
-
async function chooseAppIntent(ctx, api, flags) {
|
|
620
|
-
const { scoped, candidates, named } = await iosApps(ctx, api, flags);
|
|
621
|
-
if (named) return {
|
|
622
|
-
kind: "existing",
|
|
623
|
-
...named
|
|
624
|
-
};
|
|
625
|
-
const createIn = scoped.length === 1 ? scoped[0] : void 0;
|
|
626
|
-
if (candidates.length === 0) {
|
|
627
|
-
if (!ctx.interactive && !flags.bundleId) throw new Error("There's no iOS app in Superwall yet. Pass --bundle-id <id> to create one for that App Store Connect app.");
|
|
628
|
-
return {
|
|
629
|
-
kind: "create",
|
|
630
|
-
project: createIn
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
if (flags.bundleId) {
|
|
634
|
-
const found = candidates.find(({ app }) => app.bundle_id === flags.bundleId);
|
|
635
|
-
return found ? {
|
|
636
|
-
kind: "existing",
|
|
637
|
-
...found
|
|
638
|
-
} : {
|
|
639
|
-
kind: "create",
|
|
640
|
-
project: createIn
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
if (!ctx.interactive) {
|
|
644
|
-
if (candidates.length === 1) return {
|
|
645
|
-
kind: "existing",
|
|
646
|
-
...candidates[0]
|
|
647
|
-
};
|
|
648
|
-
throw severalApps(candidates);
|
|
649
|
-
}
|
|
650
|
-
const picked = await ctx.ui.select({
|
|
651
|
-
message: "Which Superwall app is this for?",
|
|
652
|
-
options: [...appOptions(candidates), {
|
|
653
|
-
value: NEW_APP,
|
|
654
|
-
label: "Create a new iOS app"
|
|
655
|
-
}]
|
|
656
|
-
});
|
|
657
|
-
if (picked === null) throw new Error("Cancelled.");
|
|
658
|
-
if (picked === NEW_APP) return {
|
|
659
|
-
kind: "create",
|
|
660
|
-
project: createIn
|
|
661
|
-
};
|
|
662
|
-
return {
|
|
663
|
-
kind: "existing",
|
|
664
|
-
...candidates.find(({ app }) => String(app.id) === picked)
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
async function chooseAppleApp(ctx, session, bundleId) {
|
|
668
|
-
const hasBundle = (app) => app.bundleId !== void 0;
|
|
669
|
-
const team = session.team().name;
|
|
670
|
-
if (bundleId) {
|
|
671
|
-
const found = await apiCall(ctx, "Finding the App Store Connect app", () => findApp(session, bundleId));
|
|
672
|
-
if (found && hasBundle(found)) return found;
|
|
673
|
-
const others = (await listApps(session)).filter(hasBundle).map((app) => app.bundleId);
|
|
674
|
-
const shown = others.slice(0, LISTED_APPS).join(", ");
|
|
675
|
-
const more = others.length > LISTED_APPS ? `, and ${others.length - LISTED_APPS} more` : "";
|
|
676
|
-
throw new Error(`No App Store Connect app with bundle ID ${bundleId} on the Apple team "${team}". Nothing was created.` + (others.length > 0 ? `\nThis team's apps: ${shown}${more}.` : "\nThis team has no apps yet.") + "\nCheck the bundle ID, sign in with an Apple Account on the right team, or create the app in App Store Connect.");
|
|
677
|
-
}
|
|
678
|
-
const apps = (await apiCall(ctx, "Loading App Store Connect apps", () => listApps(session))).filter(hasBundle);
|
|
679
|
-
if (apps.length === 0) throw new Error(`The Apple team "${team}" has no apps in App Store Connect yet. Create the app there, then run this again.`);
|
|
680
|
-
if (!ctx.interactive) throw new Error(`Pass --bundle-id <id>. This team's apps: ${apps.map((app) => app.bundleId).join(", ")}.`);
|
|
681
|
-
const picked = await ctx.ui.select({
|
|
682
|
-
message: "Which App Store Connect app?",
|
|
683
|
-
options: apps.map((app) => ({
|
|
684
|
-
value: app.id,
|
|
685
|
-
label: app.name ?? app.bundleId,
|
|
686
|
-
hint: app.bundleId
|
|
687
|
-
}))
|
|
688
|
-
});
|
|
689
|
-
if (picked === null) throw new Error("Cancelled.");
|
|
690
|
-
return apps.find((app) => app.id === picked);
|
|
691
|
-
}
|
|
692
|
-
async function projectForNewApp(ctx, api, intent, name) {
|
|
693
|
-
if (intent.project) return String(intent.project.id);
|
|
694
|
-
const projects = await listProjects(api);
|
|
695
|
-
if (projects.length === 0) {
|
|
696
|
-
const created = await apiCall(ctx, "Creating a project", () => createProject(api, name));
|
|
697
|
-
return String(created.id);
|
|
698
|
-
}
|
|
699
|
-
if (!ctx.interactive) throw new Error(`Several projects found: ${projects.map((project) => `${project.id} (${project.name ?? "unnamed"})`).join(", ")}. Pass --project <id>.`);
|
|
700
|
-
const picked = await ctx.ui.select({
|
|
701
|
-
message: "Which project should the new app go in?",
|
|
702
|
-
options: projects.map((project) => ({
|
|
703
|
-
value: String(project.id),
|
|
704
|
-
label: project.name ?? String(project.id)
|
|
705
|
-
}))
|
|
706
|
-
});
|
|
707
|
-
if (picked === null) throw new Error("Cancelled.");
|
|
708
|
-
return picked;
|
|
709
|
-
}
|
|
710
|
-
async function resolveApp(ctx, api, session, intent, flags) {
|
|
711
|
-
if (intent.kind === "existing") {
|
|
712
|
-
const { app, project } = intent;
|
|
713
|
-
const name$1 = app.name ?? String(app.id);
|
|
714
|
-
const saved = savedBundleId(app);
|
|
715
|
-
if (flags.bundleId && saved && flags.bundleId !== saved) throw new Error(differentBundleId(name$1, String(app.id), saved, flags.bundleId));
|
|
716
|
-
const chosen$1 = await chooseAppleApp(ctx, session, flags.bundleId ?? saved ?? void 0);
|
|
717
|
-
return {
|
|
718
|
-
projectId: String(project.id),
|
|
719
|
-
applicationId: String(app.id),
|
|
720
|
-
name: name$1,
|
|
721
|
-
bundleId: chosen$1.bundleId,
|
|
722
|
-
savedBundleId: saved,
|
|
723
|
-
ascAppId: chosen$1.id,
|
|
724
|
-
created: false
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
const chosen = await chooseAppleApp(ctx, session, flags.bundleId);
|
|
728
|
-
const name = chosen.name ?? chosen.bundleId;
|
|
729
|
-
const projectId = await projectForNewApp(ctx, api, intent, name);
|
|
730
|
-
const created = ((await apiCall(ctx, `Creating ${name} in Superwall`, () => createApplication(api, { projectId }, {
|
|
731
|
-
name,
|
|
732
|
-
platform: "ios",
|
|
733
|
-
bundleId: chosen.bundleId
|
|
734
|
-
}))).applications ?? []).filter(isIos).find((app) => app.bundle_id === chosen.bundleId);
|
|
735
|
-
if (!created) throw new Error(`Superwall created ${name} but didn't return it. Nothing was created at Apple. Run this again with --app <id> (\`superwall apps\` lists ids).`);
|
|
736
|
-
return {
|
|
737
|
-
projectId,
|
|
738
|
-
applicationId: String(created.id),
|
|
739
|
-
name,
|
|
740
|
-
bundleId: chosen.bundleId,
|
|
741
|
-
savedBundleId: chosen.bundleId,
|
|
742
|
-
ascAppId: chosen.id,
|
|
743
|
-
created: true
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
function savedBundleId(app) {
|
|
747
|
-
const value = app.bundle_id?.trim();
|
|
748
|
-
return value ? value : null;
|
|
749
|
-
}
|
|
750
|
-
function differentBundleId(name, applicationId, saved, wanted) {
|
|
751
|
-
return `\`${name}\` has the bundle ID ${saved} in Superwall, not ${wanted}. Nothing was created or saved. To change it, run \`superwall apps bundle-id ${wanted} --app ${applicationId} --replace\` first, once a person has agreed.`;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
//#endregion
|
|
755
|
-
//#region src/core/apple/keys.ts
|
|
756
|
-
const RESOURCE = {
|
|
757
|
-
team: "apiKeys",
|
|
758
|
-
purchase: "subscriptionKeys"
|
|
759
|
-
};
|
|
760
|
-
function decodePrivateKey(value) {
|
|
761
|
-
const trimmed = value.trim();
|
|
762
|
-
if (trimmed.includes("PRIVATE KEY")) return `${trimmed}\n`;
|
|
763
|
-
const decoded = Buffer.from(trimmed, "base64").toString("utf8").trim();
|
|
764
|
-
let pem = decoded;
|
|
765
|
-
try {
|
|
766
|
-
const unquoted = JSON.parse(decoded);
|
|
767
|
-
if (typeof unquoted === "string") pem = unquoted.trim();
|
|
768
|
-
} catch {
|
|
769
|
-
pem = decoded;
|
|
770
|
-
}
|
|
771
|
-
if (!pem.includes("PRIVATE KEY")) throw new AppleError("request", "Apple returned something that isn't a private key.");
|
|
772
|
-
return `${pem}\n`;
|
|
773
|
-
}
|
|
774
|
-
async function createKey(session, kind, attributes) {
|
|
775
|
-
const resource = RESOURCE[kind];
|
|
776
|
-
const issuerId = session.team().issuerId;
|
|
777
|
-
if (!issuerId) throw new AppleError("request", "App Store Connect didn't say which issuer this team uses.");
|
|
778
|
-
const id = textField(field(await session.iris("POST", `/${resource}`, { body: { data: {
|
|
779
|
-
type: resource,
|
|
780
|
-
attributes
|
|
781
|
-
} } }), "data"), "id");
|
|
782
|
-
if (!id) throw new AppleError("request", "Apple created a key but didn't return its ID.");
|
|
783
|
-
const privateKey = textField(field(field(await session.iris("GET", `/${resource}/${encodeURIComponent(id)}`, { query: { [`fields[${resource}]`]: "privateKey" } }), "data"), "attributes"), "privateKey");
|
|
784
|
-
if (!privateKey) throw new AppleError("request", `Apple created key ${id} but didn't release its private key. Revoke it in App Store Connect → Users and Access → Integrations, then try again.`);
|
|
785
|
-
return {
|
|
786
|
-
id,
|
|
787
|
-
issuerId,
|
|
788
|
-
privateKey: decodePrivateKey(privateKey)
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
function createTeamKey(session, options) {
|
|
792
|
-
return createKey(session, "team", {
|
|
793
|
-
nickname: options.name,
|
|
794
|
-
roles: [options.role],
|
|
795
|
-
allAppsVisible: true,
|
|
796
|
-
keyType: "PUBLIC_API"
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
function createPurchaseKey(session, options) {
|
|
800
|
-
return createKey(session, "purchase", { nickname: options.name });
|
|
801
|
-
}
|
|
802
|
-
async function checkKeyAccess(session, kind) {
|
|
803
|
-
await session.iris("GET", `/${RESOURCE[kind]}`, { query: { limit: "1" } });
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
//#endregion
|
|
807
|
-
//#region src/commands/platform/apple-sign-in.ts
|
|
539
|
+
//#region src/core/app-store-connect/setup/sign-in.ts
|
|
808
540
|
const MAX_CODE_ATTEMPTS = 3;
|
|
809
541
|
function describeChallenge(challenge) {
|
|
810
542
|
if (challenge.method === "device") return "Apple sent a code to your trusted devices.";
|
|
@@ -870,10 +602,12 @@ async function signInToApple(ctx, deps, flags) {
|
|
|
870
602
|
method: "device",
|
|
871
603
|
codeLength: 6
|
|
872
604
|
};
|
|
873
|
-
if (!continued || !code) challenge = await apiCall(ctx, "Requesting a verification code", () =>
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
605
|
+
if (!continued || !code) challenge = await apiCall(ctx, "Requesting a verification code", () => {
|
|
606
|
+
return session.requestCode({
|
|
607
|
+
sms: flags.sms,
|
|
608
|
+
phone: flags.phone
|
|
609
|
+
});
|
|
610
|
+
});
|
|
877
611
|
for (let attempt = 1;; attempt++) {
|
|
878
612
|
if (!code) {
|
|
879
613
|
if (!ctx.interactive) {
|
|
@@ -892,10 +626,12 @@ async function signInToApple(ctx, deps, flags) {
|
|
|
892
626
|
});
|
|
893
627
|
if (typed === null) throw new Error("Cancelled.");
|
|
894
628
|
if (typed.trim().toLowerCase() === "sms") {
|
|
895
|
-
challenge = await apiCall(ctx, "Requesting a text message", () =>
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
629
|
+
challenge = await apiCall(ctx, "Requesting a text message", () => {
|
|
630
|
+
return session.requestCode({
|
|
631
|
+
sms: true,
|
|
632
|
+
phone: flags.phone
|
|
633
|
+
});
|
|
634
|
+
});
|
|
899
635
|
continue;
|
|
900
636
|
}
|
|
901
637
|
code = typed.trim();
|
|
@@ -922,14 +658,91 @@ async function signInToApple(ctx, deps, flags) {
|
|
|
922
658
|
session
|
|
923
659
|
};
|
|
924
660
|
}
|
|
661
|
+
async function chooseTeam(ctx, session, requested) {
|
|
662
|
+
const teams = session.teams();
|
|
663
|
+
if (requested) {
|
|
664
|
+
const found = teams.find((team) => String(team.id) === requested || team.name.toLowerCase() === requested.toLowerCase());
|
|
665
|
+
if (!found) throw new Error(`This Apple Account isn't on team ${requested}. Its teams: ${teams.map((team) => `${team.id} (${team.name})`).join(", ")}.`);
|
|
666
|
+
await session.selectTeam(found.id);
|
|
667
|
+
return session.team();
|
|
668
|
+
}
|
|
669
|
+
if (teams.length <= 1) return session.team();
|
|
670
|
+
if (!ctx.interactive) throw new Error(`This Apple Account is on several teams: ${teams.map((team) => `${team.id} (${team.name})`).join(", ")}. Pass --team <id>.`);
|
|
671
|
+
const picked = await ctx.ui.select({
|
|
672
|
+
message: "Which Apple team?",
|
|
673
|
+
options: teams.map((team) => ({
|
|
674
|
+
value: String(team.id),
|
|
675
|
+
label: team.name
|
|
676
|
+
})),
|
|
677
|
+
initialValue: String(session.team().id)
|
|
678
|
+
});
|
|
679
|
+
if (picked === null) throw new Error("Cancelled.");
|
|
680
|
+
await session.selectTeam(Number(picked));
|
|
681
|
+
return session.team();
|
|
682
|
+
}
|
|
683
|
+
async function signIn(ctx, deps, command, flags) {
|
|
684
|
+
const signedIn = await signInToApple(ctx, deps, flags);
|
|
685
|
+
if (signedIn.status === "signed-in") return signedIn.session;
|
|
686
|
+
const next = `superwall ${command} --code <code>`;
|
|
687
|
+
if (ctx.json) ctx.output.data({
|
|
688
|
+
status: "verification_required",
|
|
689
|
+
method: signedIn.challenge.method,
|
|
690
|
+
destination: signedIn.challenge.destination ?? null,
|
|
691
|
+
next
|
|
692
|
+
});
|
|
693
|
+
else ctx.ui.warn(`${describeChallenge(signedIn.challenge)}\nRun \`${next}\` with the same flags within 10 minutes to continue, or add --sms to get a text instead.`);
|
|
694
|
+
ctx.fail();
|
|
695
|
+
}
|
|
925
696
|
|
|
926
697
|
//#endregion
|
|
927
|
-
//#region src/
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
purchase_key: "In-App Purchase key"
|
|
698
|
+
//#region src/core/app-store-connect/apple-web/keys.ts
|
|
699
|
+
const RESOURCE = {
|
|
700
|
+
team: "apiKeys",
|
|
701
|
+
purchase: "subscriptionKeys"
|
|
932
702
|
};
|
|
703
|
+
function decodePrivateKey(value) {
|
|
704
|
+
const trimmed = value.trim();
|
|
705
|
+
if (trimmed.includes("PRIVATE KEY")) return `${trimmed}\n`;
|
|
706
|
+
const decoded = Buffer.from(trimmed, "base64").toString("utf8").trim();
|
|
707
|
+
const unquoted = parseJson(decoded);
|
|
708
|
+
const pem = typeof unquoted === "string" ? unquoted.trim() : decoded;
|
|
709
|
+
if (!pem.includes("PRIVATE KEY")) throw new AppleError("request", "Apple returned something that isn't a private key.");
|
|
710
|
+
return `${pem}\n`;
|
|
711
|
+
}
|
|
712
|
+
async function createKey(session, kind, attributes) {
|
|
713
|
+
const resource = RESOURCE[kind];
|
|
714
|
+
const issuerId = session.team().issuerId;
|
|
715
|
+
if (!issuerId) throw new AppleError("request", "App Store Connect didn't say which issuer this team uses.");
|
|
716
|
+
const id = textField(field(await session.iris("POST", `/${resource}`, { body: { data: {
|
|
717
|
+
type: resource,
|
|
718
|
+
attributes
|
|
719
|
+
} } }), "data"), "id");
|
|
720
|
+
if (!id) throw new AppleError("request", "Apple created a key but didn't return its ID.");
|
|
721
|
+
const privateKey = textField(field(field(await session.iris("GET", `/${resource}/${encodeURIComponent(id)}`, { query: { [`fields[${resource}]`]: "privateKey" } }), "data"), "attributes"), "privateKey");
|
|
722
|
+
if (!privateKey) throw new AppleError("request", `Apple created key ${id} but didn't release its private key. Revoke it in App Store Connect → Users and Access → Integrations, then try again.`);
|
|
723
|
+
return {
|
|
724
|
+
id,
|
|
725
|
+
issuerId,
|
|
726
|
+
privateKey: decodePrivateKey(privateKey)
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
function createTeamKey(session, options) {
|
|
730
|
+
return createKey(session, "team", {
|
|
731
|
+
nickname: options.name,
|
|
732
|
+
roles: [options.role],
|
|
733
|
+
allAppsVisible: true,
|
|
734
|
+
keyType: "PUBLIC_API"
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function createPurchaseKey(session, options) {
|
|
738
|
+
return createKey(session, "purchase", { nickname: options.name });
|
|
739
|
+
}
|
|
740
|
+
async function checkKeyAccess(session, kind) {
|
|
741
|
+
await session.iris("GET", `/${RESOURCE[kind]}`, { query: { limit: "1" } });
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
//#endregion
|
|
745
|
+
//#region src/core/app-store-connect/keys/create.ts
|
|
933
746
|
const KEY_NAME = "Superwall";
|
|
934
747
|
const KEY_FILE = {
|
|
935
748
|
api_key: "AuthKey",
|
|
@@ -951,32 +764,11 @@ const ACTIVATION_STATUSES = new Set([
|
|
|
951
764
|
422,
|
|
952
765
|
502
|
|
953
766
|
]);
|
|
954
|
-
function
|
|
955
|
-
const value =
|
|
956
|
-
if (typeof value === "number") return String(value);
|
|
957
|
-
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
958
|
-
}
|
|
959
|
-
function keyKind(value) {
|
|
960
|
-
return KEY_KINDS.find((kind) => kind === value);
|
|
961
|
-
}
|
|
962
|
-
function keyRole(ctx) {
|
|
963
|
-
const value = (text(ctx, "key-role") ?? "app_manager").toUpperCase().replace(/-/g, "_");
|
|
767
|
+
function keyRole(requested) {
|
|
768
|
+
const value = (requested ?? "app_manager").toUpperCase().replace(/-/g, "_");
|
|
964
769
|
if (value === "APP_MANAGER" || value === "ADMIN") return value;
|
|
965
770
|
throw new Error("--key-role must be app_manager or admin.");
|
|
966
771
|
}
|
|
967
|
-
const appFlags = (ctx) => ({
|
|
968
|
-
app: text(ctx, "app"),
|
|
969
|
-
project: text(ctx, "project"),
|
|
970
|
-
bundleId: text(ctx, "bundle-id")
|
|
971
|
-
});
|
|
972
|
-
const signInFlags = (ctx) => ({
|
|
973
|
-
appleId: text(ctx, "apple-id"),
|
|
974
|
-
password: typeof ctx.argv["apple-password"] === "string" && ctx.argv["apple-password"] !== "" ? ctx.argv["apple-password"] : void 0,
|
|
975
|
-
code: text(ctx, "code"),
|
|
976
|
-
sms: ctx.argv.sms === true,
|
|
977
|
-
phone: text(ctx, "phone")
|
|
978
|
-
});
|
|
979
|
-
const savedKey = (saved, kind) => (kind === "api_key" ? saved.app_store_connect_configuration : saved.in_app_purchase_configuration) ?? void 0;
|
|
980
772
|
function keyRefusal(error, kind) {
|
|
981
773
|
const message = error.message.toLowerCase();
|
|
982
774
|
if (message.includes("maximum") || message.includes("revoke")) return "This team is at Apple's limit of active keys. Revoke an unused one in App Store Connect → Users and Access → Integrations, then run this again.";
|
|
@@ -997,44 +789,11 @@ async function untilActive(ctx, deps, label, work, rejected) {
|
|
|
997
789
|
}
|
|
998
790
|
});
|
|
999
791
|
}
|
|
1000
|
-
async function chooseTeam(ctx, session, requested) {
|
|
1001
|
-
const teams = session.teams();
|
|
1002
|
-
if (requested) {
|
|
1003
|
-
const found = teams.find((team) => String(team.id) === requested || team.name.toLowerCase() === requested.toLowerCase());
|
|
1004
|
-
if (!found) throw new Error(`This Apple Account isn't on team ${requested}. Its teams: ${teams.map((team) => `${team.id} (${team.name})`).join(", ")}.`);
|
|
1005
|
-
await session.selectTeam(found.id);
|
|
1006
|
-
return session.team();
|
|
1007
|
-
}
|
|
1008
|
-
if (teams.length <= 1) return session.team();
|
|
1009
|
-
if (!ctx.interactive) throw new Error(`This Apple Account is on several teams: ${teams.map((team) => `${team.id} (${team.name})`).join(", ")}. Pass --team <id>.`);
|
|
1010
|
-
const picked = await ctx.ui.select({
|
|
1011
|
-
message: "Which Apple team?",
|
|
1012
|
-
options: teams.map((team) => ({
|
|
1013
|
-
value: String(team.id),
|
|
1014
|
-
label: team.name
|
|
1015
|
-
})),
|
|
1016
|
-
initialValue: String(session.team().id)
|
|
1017
|
-
});
|
|
1018
|
-
if (picked === null) throw new Error("Cancelled.");
|
|
1019
|
-
await session.selectTeam(Number(picked));
|
|
1020
|
-
return session.team();
|
|
1021
|
-
}
|
|
1022
|
-
async function signIn(ctx, deps, command) {
|
|
1023
|
-
const signedIn = await signInToApple(ctx, deps, signInFlags(ctx));
|
|
1024
|
-
if (signedIn.status === "signed-in") return signedIn.session;
|
|
1025
|
-
const next = `superwall ${command} --code <code>`;
|
|
1026
|
-
if (ctx.json) emitJson(ctx, {
|
|
1027
|
-
status: "verification_required",
|
|
1028
|
-
method: signedIn.challenge.method,
|
|
1029
|
-
destination: signedIn.challenge.destination ?? null,
|
|
1030
|
-
next
|
|
1031
|
-
});
|
|
1032
|
-
else ctx.ui.warn(`${describeChallenge(signedIn.challenge)}\nRun \`${next}\` with the same flags within 10 minutes to continue, or add --sms to get a text instead.`);
|
|
1033
|
-
process.exitCode = 1;
|
|
1034
|
-
}
|
|
1035
792
|
async function keyAccess(ctx, session, kind) {
|
|
1036
793
|
try {
|
|
1037
|
-
await apiCall(ctx, `Checking ${KEY_LABEL[kind]} access`, () =>
|
|
794
|
+
await apiCall(ctx, `Checking ${KEY_LABEL[kind]} access`, () => {
|
|
795
|
+
return checkKeyAccess(session, APPLE_KIND[kind]);
|
|
796
|
+
});
|
|
1038
797
|
return "ok";
|
|
1039
798
|
} catch (error) {
|
|
1040
799
|
if (!(error instanceof AppleError)) throw error;
|
|
@@ -1049,10 +808,13 @@ function keepKey(ctx, deps, kind, key, reason) {
|
|
|
1049
808
|
async function createAndSaveKey(ctx, deps, api, session, app, kind, role) {
|
|
1050
809
|
let key;
|
|
1051
810
|
try {
|
|
1052
|
-
key = await apiCall(ctx, `Creating the ${KEY_LABEL[kind]}`, () =>
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
811
|
+
key = await apiCall(ctx, `Creating the ${KEY_LABEL[kind]}`, () => {
|
|
812
|
+
if (kind === "api_key") return createTeamKey(session, {
|
|
813
|
+
name: KEY_NAME,
|
|
814
|
+
role
|
|
815
|
+
});
|
|
816
|
+
return createPurchaseKey(session, { name: KEY_NAME });
|
|
817
|
+
});
|
|
1056
818
|
} catch (error) {
|
|
1057
819
|
if (!(error instanceof AppleError)) throw error;
|
|
1058
820
|
const detail = keyRefusal(error, kind);
|
|
@@ -1072,11 +834,14 @@ async function createAndSaveKey(ctx, deps, api, session, app, kind, role) {
|
|
|
1072
834
|
privateKey: key.privateKey
|
|
1073
835
|
};
|
|
1074
836
|
const setApplicationBundleId = kind === "purchase_key" && app.savedBundleId === null;
|
|
1075
|
-
const save = () =>
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
837
|
+
const save = () => {
|
|
838
|
+
if (kind === "api_key") return replaceAppAscKey(api, appRef, credentials);
|
|
839
|
+
return replaceAppPurchaseKey(api, appRef, {
|
|
840
|
+
...credentials,
|
|
841
|
+
bundleId: app.bundleId,
|
|
842
|
+
setApplicationBundleId
|
|
843
|
+
});
|
|
844
|
+
};
|
|
1080
845
|
let reason;
|
|
1081
846
|
try {
|
|
1082
847
|
const verdict = await untilActive(ctx, deps, `Saving the ${KEY_LABEL[kind]} on ${app.name}`, save, (result) => !result.valid);
|
|
@@ -1089,28 +854,25 @@ async function createAndSaveKey(ctx, deps, api, session, app, kind, role) {
|
|
|
1089
854
|
}
|
|
1090
855
|
reason = `Apple hasn't accepted the new key yet${verdict.error ? ` (${verdict.error})` : ""}.`;
|
|
1091
856
|
} catch (error) {
|
|
1092
|
-
|
|
1093
|
-
reason = `Superwall couldn't save the key: ${error.message}.`;
|
|
857
|
+
reason = `Superwall couldn't save the key: ${error instanceof Error ? error.message : String(error)}.`;
|
|
1094
858
|
}
|
|
1095
859
|
return {
|
|
1096
860
|
status: "failed",
|
|
1097
861
|
detail: keepKey(ctx, deps, kind, key, reason)
|
|
1098
862
|
};
|
|
1099
863
|
}
|
|
1100
|
-
async function
|
|
864
|
+
async function createAtApple(ctx, request) {
|
|
1101
865
|
const { api } = ctx;
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1104
|
-
const role = keyRole(
|
|
1105
|
-
const flags = appFlags(ctx);
|
|
1106
|
-
const command = `asc keys create ${kind}`;
|
|
866
|
+
const deps = appleDeps;
|
|
867
|
+
const { kind } = request;
|
|
868
|
+
const role = keyRole(request.role);
|
|
1107
869
|
ctx.output.render(blocks.intro(`Create an ${KEY_LABEL[kind]}`));
|
|
1108
|
-
const chosen = await chooseIosApp(ctx, api,
|
|
870
|
+
const chosen = await chooseIosApp(ctx, api, request.app);
|
|
1109
871
|
const applicationId = String(chosen.app.id);
|
|
1110
872
|
const appName = chosen.app.name ?? applicationId;
|
|
1111
|
-
const existing = savedKey(await apiCall(ctx, "Checking what is saved", () =>
|
|
1112
|
-
if (existing &&
|
|
1113
|
-
if (ctx.json) return
|
|
873
|
+
const existing = savedKey(await apiCall(ctx, "Checking what is saved", () => findIntegrations(api, applicationId)), kind);
|
|
874
|
+
if (existing && !request.replace) {
|
|
875
|
+
if (ctx.json) return ctx.output.data({
|
|
1114
876
|
status: "already_saved",
|
|
1115
877
|
kind,
|
|
1116
878
|
key_id: existing.key_id,
|
|
@@ -1123,151 +885,85 @@ async function createAppKey(ctx, deps) {
|
|
|
1123
885
|
ctx.ui.success(`\`${appName}\` already has an ${KEY_LABEL[kind]} (${existing.key_id}). Nothing was created. Pass --replace to create another and save it instead.`);
|
|
1124
886
|
return;
|
|
1125
887
|
}
|
|
1126
|
-
const session = await signIn(ctx, deps,
|
|
888
|
+
const session = await signIn(ctx, deps, `asc keys create ${kind}`, request.signIn);
|
|
1127
889
|
if (!session) return;
|
|
1128
|
-
const
|
|
1129
|
-
ctx.output.render(blocks.info(`Apple team \`${
|
|
890
|
+
const appleTeam = await chooseTeam(ctx, session, request.team);
|
|
891
|
+
ctx.output.render(blocks.info(`Apple team \`${appleTeam.name}\``));
|
|
1130
892
|
if (ctx.dryRun) {
|
|
1131
893
|
const access = await keyAccess(ctx, session, kind);
|
|
1132
|
-
if (ctx.json) return
|
|
894
|
+
if (ctx.json) return ctx.output.data({
|
|
1133
895
|
dryRun: true,
|
|
1134
896
|
kind,
|
|
1135
|
-
team,
|
|
897
|
+
team: appleTeam,
|
|
1136
898
|
access
|
|
1137
899
|
});
|
|
1138
900
|
ctx.ui.report(`${access === "ok" ? "✓" : "✗"} ${KEY_LABEL[kind]} ${access}`);
|
|
1139
901
|
ctx.ui.info("[dry-run] nothing was created or changed.");
|
|
1140
902
|
return;
|
|
1141
903
|
}
|
|
1142
|
-
const
|
|
904
|
+
const resolved = await resolveApp(ctx, api, session, {
|
|
1143
905
|
kind: "existing",
|
|
1144
906
|
...chosen
|
|
1145
|
-
},
|
|
1146
|
-
if (kind === "purchase_key" &&
|
|
1147
|
-
const warning = await testModeWarning(ctx, api,
|
|
907
|
+
}, request.app);
|
|
908
|
+
if (kind === "purchase_key" && resolved.savedBundleId === null) {
|
|
909
|
+
const warning = await testModeWarning(ctx, api, resolved.applicationId, resolved.bundleId);
|
|
1148
910
|
if (warning) ctx.output.render(blocks.warning(warning));
|
|
1149
911
|
}
|
|
1150
|
-
const result = await createAndSaveKey(ctx, deps, api, session,
|
|
912
|
+
const result = await createAndSaveKey(ctx, deps, api, session, resolved, kind, role);
|
|
1151
913
|
const created = result.status === "done";
|
|
1152
|
-
if (ctx.json)
|
|
914
|
+
if (ctx.json) ctx.output.data({
|
|
1153
915
|
status: created ? "created" : "failed",
|
|
1154
916
|
kind,
|
|
1155
917
|
key_id: created ? result.detail : null,
|
|
1156
918
|
detail: created ? null : result.detail,
|
|
1157
919
|
replaced: created && existing ? existing.key_id : null,
|
|
1158
|
-
team,
|
|
920
|
+
team: appleTeam,
|
|
1159
921
|
app: {
|
|
1160
|
-
id:
|
|
1161
|
-
project_id:
|
|
1162
|
-
name:
|
|
1163
|
-
bundle_id:
|
|
922
|
+
id: resolved.applicationId,
|
|
923
|
+
project_id: resolved.projectId,
|
|
924
|
+
name: resolved.name,
|
|
925
|
+
bundle_id: resolved.bundleId
|
|
1164
926
|
},
|
|
1165
|
-
...kind === "purchase_key" ? { bundle_id_saved: created &&
|
|
1166
|
-
});
|
|
1167
|
-
else if (created) ctx.ui.success(`${KEY_LABEL[kind]} ${result.detail} created and saved on \`${app.name}\`.`);
|
|
1168
|
-
if (!created) process.exitCode = 1;
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
//#endregion
|
|
1172
|
-
//#region src/commands/platform/notification-url.ts
|
|
1173
|
-
const RETRY_DELAYS = [
|
|
1174
|
-
1e3,
|
|
1175
|
-
2e3,
|
|
1176
|
-
3e3
|
|
1177
|
-
];
|
|
1178
|
-
async function settled(sleep, work) {
|
|
1179
|
-
for (let attempt = 0;; attempt++) {
|
|
1180
|
-
const outcome = await work();
|
|
1181
|
-
const delay = RETRY_DELAYS[attempt];
|
|
1182
|
-
if (outcome.status !== "failed" || !outcome.retryable || delay === void 0) return outcome;
|
|
1183
|
-
await sleep(delay);
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
function ensureNotificationUrl(ctx, sleep, api, app, options) {
|
|
1187
|
-
return apiCall(ctx, "Setting the server notification URL", () => settled(sleep, () => setServerNotifications(api, app, options)));
|
|
1188
|
-
}
|
|
1189
|
-
function holder(environment) {
|
|
1190
|
-
switch (environment.owner) {
|
|
1191
|
-
case "this_app": return "this app's Superwall URL";
|
|
1192
|
-
case "none": return "none";
|
|
1193
|
-
case "superwall_app": return environment.application ? `another Superwall app, ${environment.application.name} (app ${environment.application.id})` : "another Superwall app";
|
|
1194
|
-
case "other": return "another server";
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
function environmentLines(outcome) {
|
|
1198
|
-
return ["production", "sandbox"].flatMap((name) => {
|
|
1199
|
-
const environment = outcome[name];
|
|
1200
|
-
if (!environment) return [];
|
|
1201
|
-
const label = name === "production" ? "Production" : "Sandbox";
|
|
1202
|
-
const shown = environment.owner === "this_app" || environment.owner === "none" ? "" : ` ${environment.url ?? ""}`;
|
|
1203
|
-
return [`${label}: ${holder(environment)}${shown}`];
|
|
927
|
+
...kind === "purchase_key" ? { bundle_id_saved: created && resolved.savedBundleId === null } : {}
|
|
1204
928
|
});
|
|
929
|
+
else if (created) ctx.ui.success(`${KEY_LABEL[kind]} ${result.detail} created and saved on \`${resolved.name}\`.`);
|
|
930
|
+
if (!created) ctx.fail();
|
|
1205
931
|
}
|
|
1206
|
-
function
|
|
1207
|
-
|
|
1208
|
-
case "set": return "Apple now sends this app's server notifications to Superwall.";
|
|
1209
|
-
case "already_set": return "Apple already sends this app's server notifications to Superwall.";
|
|
1210
|
-
case "not_set": return "Apple has no server notification URL for this app in production, sandbox, or both. No other server holds either.";
|
|
1211
|
-
case "conflict": {
|
|
1212
|
-
const holders = ["production", "sandbox"].map((name) => outcome[name]).filter((environment) => environment?.owner === "superwall_app" || environment?.owner === "other");
|
|
1213
|
-
return holders.length > 0 && holders.every((environment) => environment.owner === "superwall_app") ? "Apple sends this app's server notifications to another Superwall app. Superwall won't replace it." : "Apple sends this app's server notifications to another server. Superwall won't replace it.";
|
|
1214
|
-
}
|
|
1215
|
-
case "skipped": return outcome.message ?? "Apple can't be asked about this app's server notification URL.";
|
|
1216
|
-
case "failed": return outcome.message ?? "Apple couldn't be asked about this app's server notification URL.";
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
async function runNotificationUrl(ctx, sleep) {
|
|
1220
|
-
const { api } = ctx;
|
|
1221
|
-
const action = ctx.argv.value ?? "get";
|
|
1222
|
-
if (action !== "get" && action !== "check" && action !== "set") throw new Error(`Unknown "asc notification-url ${action}". Use get | check | set.`);
|
|
1223
|
-
const chosen = await chooseIosApp(ctx, api, appFlags(ctx));
|
|
932
|
+
async function runAscKeysCreate(ctx, { args, flags }) {
|
|
933
|
+
const kind = keyKind(args.kind);
|
|
1224
934
|
const app = {
|
|
1225
|
-
|
|
1226
|
-
|
|
935
|
+
app: flags.app,
|
|
936
|
+
project: flags.project,
|
|
937
|
+
bundleId: flags.bundleId
|
|
1227
938
|
};
|
|
1228
|
-
if (
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
return;
|
|
1236
|
-
}
|
|
1237
|
-
const setRevenueProvider = ctx.argv["set-revenue-provider"] === true;
|
|
1238
|
-
if (action === "set" && ctx.dryRun) {
|
|
1239
|
-
const url = await apiCall(ctx, "Loading the URL", () => getAppNotificationUrl(api, app));
|
|
1240
|
-
if (ctx.json) return emitJson(ctx, {
|
|
1241
|
-
dryRun: true,
|
|
1242
|
-
action: "set",
|
|
1243
|
-
application_id: app.applicationId,
|
|
1244
|
-
url,
|
|
1245
|
-
set_revenue_provider: setRevenueProvider
|
|
1246
|
-
});
|
|
1247
|
-
ctx.ui.info(`[dry-run] would set ${url} where Apple has no server notification URL.`);
|
|
1248
|
-
return;
|
|
1249
|
-
}
|
|
1250
|
-
const outcome = action === "check" ? await apiCall(ctx, "Reading the server notification URL", () => checkServerNotifications(api, app)) : await ensureNotificationUrl(ctx, sleep, api, app, { setRevenueProvider });
|
|
1251
|
-
const ok = action === "check" ? outcome.status !== "failed" && outcome.status !== "skipped" : outcome.status === "set" || outcome.status === "already_set";
|
|
1252
|
-
if (ctx.json) emitJson(ctx, {
|
|
1253
|
-
application_id: app.applicationId,
|
|
1254
|
-
url: outcome.url,
|
|
1255
|
-
apple: {
|
|
1256
|
-
status: outcome.status,
|
|
1257
|
-
message: outcome.message,
|
|
1258
|
-
production: outcome.production,
|
|
1259
|
-
sandbox: outcome.sandbox
|
|
939
|
+
if (flags.keyFile !== void 0) return upsertHeldKey(ctx, {
|
|
940
|
+
action: "create",
|
|
941
|
+
key: {
|
|
942
|
+
keyId: flags.keyId,
|
|
943
|
+
issuer: flags.issuer,
|
|
944
|
+
keyFile: flags.keyFile,
|
|
945
|
+
name: flags.name
|
|
1260
946
|
},
|
|
1261
|
-
...
|
|
947
|
+
...flags.app === void 0 ? {} : { app },
|
|
948
|
+
kind,
|
|
949
|
+
team: flags.team
|
|
950
|
+
});
|
|
951
|
+
if (!kind) throw new Error("Usage: superwall asc keys create <api_key | purchase_key> --app <id>");
|
|
952
|
+
return createAtApple(ctx, {
|
|
953
|
+
kind,
|
|
954
|
+
role: flags.keyRole,
|
|
955
|
+
replace: flags.replace,
|
|
956
|
+
team: flags.team,
|
|
957
|
+
app,
|
|
958
|
+
signIn: {
|
|
959
|
+
appleId: flags.appleId,
|
|
960
|
+
password: flags.applePassword,
|
|
961
|
+
code: flags.code,
|
|
962
|
+
sms: flags.sms,
|
|
963
|
+
phone: flags.phone
|
|
964
|
+
}
|
|
1262
965
|
});
|
|
1263
|
-
else {
|
|
1264
|
-
const message = [describeNotificationUrl(outcome), ...environmentLines(outcome).map((line) => ` ${line}`)].join("\n");
|
|
1265
|
-
if (!ok) ctx.ui.error(message);
|
|
1266
|
-
else if (outcome.status === "set" || outcome.status === "already_set") ctx.ui.success(message);
|
|
1267
|
-
else ctx.ui.info(message);
|
|
1268
|
-
}
|
|
1269
|
-
if (!ok) process.exitCode = 1;
|
|
1270
966
|
}
|
|
1271
967
|
|
|
1272
968
|
//#endregion
|
|
1273
|
-
export {
|
|
969
|
+
export { chooseTeam as a, runAscKeysCreate as i, keyAccess as n, signIn as o, keyRole as r, appleDeps as s, createAndSaveKey as t };
|