@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.
Files changed (229) hide show
  1. package/README.md +192 -52
  2. package/dist/{setup-Bxj22rYi.js → apple-CSzNTGHM.js} +82 -76
  3. package/dist/auth.d.ts +4 -19
  4. package/dist/auth.js +4 -2
  5. package/dist/{actions-B7ym3oVS.js → billing-C3Q8DBU2.js} +98 -28
  6. package/dist/{bind-YrJvuRF9.js → bind-BumHTi9O.js} +38 -33
  7. package/dist/{build-DLoCW5Ri.js → build-Bpviiclc.js} +20 -26
  8. package/dist/client-BL0f_yGf.js +176 -0
  9. package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
  10. package/dist/config-BO1Y87kV.js +105 -0
  11. package/dist/create-BSfvpWoD.js +19 -0
  12. package/dist/{create-pkANt1Gs.js → create-BUcVG4Ab.js} +195 -169
  13. package/dist/{notification-url-DuKF2659.js → create-CfK3PeKA.js} +235 -539
  14. package/dist/doctor-BWqIYcMn.js +83 -0
  15. package/dist/{drivers-Qx9LxmRN.js → drivers-CPhdPkW5.js} +185 -172
  16. package/dist/entry.d.ts +0 -5
  17. package/dist/entry.js +28072 -1134
  18. package/dist/environment-eBXjELoN.js +58 -0
  19. package/dist/{existing-AVEfZu2A.js → existing-BltvQiX5.js} +12 -6
  20. package/dist/held-CPve03KJ.js +16 -0
  21. package/dist/held-DgnTFMl3.js +1112 -0
  22. package/dist/input-vi0bou04.js +42 -0
  23. package/dist/{integrate-brmhPG-S.js → integrate-BRsqoe01.js} +277 -254
  24. package/dist/log-NVhVe_oe.js +62 -0
  25. package/dist/login-BCEH5q0U.js +53 -0
  26. package/dist/login-BPOONe7n.js +16 -0
  27. package/dist/{login-Do4wFuLv.js → login-BbTIrCFT.js} +118 -55
  28. package/dist/lookup-rr1AkCJA.js +71 -0
  29. package/dist/migrate-C9X2Vz81.js +274 -0
  30. package/dist/notification-url-CV86qiKP.js +100 -0
  31. package/dist/{open-studio-DOw-6ydc.js → open-CcpXotHG.js} +34 -43
  32. package/dist/org-BQQDo7wm.js +35 -0
  33. package/dist/output-Ggzq5_-t.js +122 -0
  34. package/dist/paths-CRlU72cq.js +29 -0
  35. package/dist/playbook-DVMXN7fh.js +53 -0
  36. package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
  37. package/dist/promote-Da8xctzy.js +91 -0
  38. package/dist/push-BV-grvQg.js +22 -0
  39. package/dist/push-D6R9icWN.js +495 -0
  40. package/dist/registry-BYVD-_h6.js +10385 -0
  41. package/dist/{reports-CfJqoava.js → reports-D_qbl7_u.js} +7 -6
  42. package/dist/{resources-Bf9O1JNM.js → resources-DLON3-61.js} +162 -55
  43. package/dist/{run-DsVZ5snL.js → run-Co-BwhOg.js} +16 -22
  44. package/dist/scan-B88OlWOt.js +4 -0
  45. package/dist/{scan-zKsddO72.js → scan-CKuk-_6W.js} +48 -37
  46. package/dist/scope-DV22_Ufm.js +198 -0
  47. package/dist/screenshot-file-tVBfUEIi.js +16 -0
  48. package/dist/{selection-CxZoX4NT.js → selection-C2_KbLuo.js} +100 -51
  49. package/dist/server-C4f6ccUr.js +22 -0
  50. package/dist/{dev-DmB3XqaJ.js → server-D0d2oP-5.js} +86 -94
  51. package/dist/session-B-Uz0cQ7.js +40 -0
  52. package/dist/session-BuvArt1j.js +6 -0
  53. package/dist/session-C4rbE3VS.js +796 -0
  54. package/dist/skills/animate-onboarding/SKILL.md +467 -0
  55. package/dist/skills/animate-onboarding/references/engine.md +494 -0
  56. package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
  57. package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
  58. package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
  59. package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
  60. package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  61. package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
  62. package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
  63. package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  64. package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
  65. package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
  66. package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
  67. package/dist/skills/animate-onboarding/references/performance.md +41 -0
  68. package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
  69. package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  70. package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  71. package/dist/skills/index.json +37 -0
  72. package/dist/skills/mobile-design/SKILL.md +447 -0
  73. package/dist/skills/mobile-design/references/responsive.md +162 -0
  74. package/dist/skills/onboarding-questions/SKILL.md +231 -0
  75. package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
  76. package/dist/skills/onboarding-questions/references/craft.md +142 -0
  77. package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
  78. package/dist/skills/superwall/SKILL.md +82 -9
  79. package/dist/skills/superwall/references/api.md +153 -37
  80. package/dist/skills/superwall/references/apple-setup.md +316 -0
  81. package/dist/skills/superwall/references/asc.md +74 -38
  82. package/dist/skills/superwall/references/data-analytics.md +55 -21
  83. package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
  84. package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
  85. package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
  86. package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
  87. package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
  88. package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
  89. package/dist/skills/superwall/workflows/placements/android.md +2 -2
  90. package/dist/skills/superwall/workflows/placements/expo.md +2 -2
  91. package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
  92. package/dist/skills/superwall/workflows/placements/ios.md +2 -2
  93. package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
  94. package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
  95. package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
  96. package/dist/skills/superwall/workflows/review/playbook.md +1 -1
  97. package/dist/skills/superwall-editor/SKILL.md +61 -0
  98. package/dist/skills/superwall-editor/references/cli.md +135 -0
  99. package/dist/skills/superwall-editor/references/design.md +51 -0
  100. package/dist/skills/superwall-editor/references/native-elements.md +171 -0
  101. package/dist/skills/superwall-editor/references/workflow.md +65 -0
  102. package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
  103. package/dist/skills/superwall-framework/SKILL.md +85 -31
  104. package/dist/skills/superwall-framework/references/cli.md +58 -27
  105. package/dist/skills/superwall-framework/references/examples.md +4 -3
  106. package/dist/skills/superwall-framework/references/layout.md +64 -9
  107. package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
  108. package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
  109. package/dist/skills/wwdc/SKILL.md +22 -0
  110. package/dist/skills/wwdc/references/docs.md +52 -0
  111. package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
  112. package/dist/skills-CLGJuMnF.js +14 -0
  113. package/dist/{skills-DPzlnfCK.js → skills-CZcpnEnG.js} +100 -122
  114. package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
  115. package/dist/spinner-C2U6QBJ9.js +294 -0
  116. package/dist/storage-6h9vyiAz.js +31 -0
  117. package/dist/storage-CerJ5KLP.d.ts +16 -0
  118. package/dist/storekit-CK9JmM2D.js +16 -0
  119. package/dist/storekit-CinJra3V.js +47 -0
  120. package/dist/telemetry-DKyDhURo.js +56 -0
  121. package/dist/theme-DUsCh-Vd.js +25 -0
  122. package/dist/timing-BVxPrYq3.js +5 -0
  123. package/dist/{token-C0it-Xh7.js → token-DaxQgQkv.js} +6 -38
  124. package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
  125. package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
  126. package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
  127. package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
  128. package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
  129. package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
  130. package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  131. package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
  132. package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
  133. package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  134. package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
  135. package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
  136. package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
  137. package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
  138. package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
  139. package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  140. package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  141. package/dist/tools-skills/mobile-design/SKILL.md +447 -0
  142. package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
  143. package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
  144. package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
  145. package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
  146. package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
  147. package/dist/tools-skills/superwall/SKILL.md +263 -0
  148. package/dist/tools-skills/superwall/references/api.md +303 -0
  149. package/dist/tools-skills/superwall/references/asa.md +166 -0
  150. package/dist/tools-skills/superwall/references/asc.md +95 -0
  151. package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
  152. package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
  153. package/dist/tools-skills/superwall/references/docs.md +51 -0
  154. package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
  155. package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
  156. package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
  157. package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
  158. package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
  159. package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
  160. package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
  161. package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
  162. package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
  163. package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
  164. package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
  165. package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
  166. package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
  167. package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
  168. package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
  169. package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
  170. package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
  171. package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
  172. package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
  173. package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
  174. package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
  175. package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
  176. package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
  177. package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
  178. package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
  179. package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
  180. package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
  181. package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
  182. package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
  183. package/dist/tools-skills/superwall-editor/references/design.md +51 -0
  184. package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
  185. package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
  186. package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
  187. package/dist/tools-skills/wwdc/SKILL.md +22 -0
  188. package/dist/tools-skills/wwdc/references/docs.md +52 -0
  189. package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
  190. package/dist/tools.d.ts +96 -0
  191. package/dist/tools.js +11360 -0
  192. package/dist/ui-D_qf3Gvw.js +53 -0
  193. package/dist/upgrade-DPo0a4Es.js +117 -0
  194. package/dist/upgrade-ffseQDMx.js +7 -0
  195. package/package.json +10 -5
  196. package/dist/api-CZzirVMj.js +0 -151
  197. package/dist/api-output-aJNw7Syy.js +0 -20
  198. package/dist/app-DH6U8yuI.js +0 -190
  199. package/dist/asa-C-sQzPPn.js +0 -1194
  200. package/dist/asc-1ZBJ6DwS.js +0 -778
  201. package/dist/auth-YRhlV3DE.js +0 -140
  202. package/dist/billing-CCYHdApx.js +0 -80
  203. package/dist/bundle-id-CKxl_026.js +0 -121
  204. package/dist/command-CMIz81Da.js +0 -301
  205. package/dist/dev-DZy6pOnB.js +0 -22
  206. package/dist/doctor-H-hf-Yww.js +0 -88
  207. package/dist/feedback-CKf-rpBW.js +0 -152
  208. package/dist/hosted-CXe9TrWx.js +0 -32
  209. package/dist/migrate-C9ERDR6y.js +0 -284
  210. package/dist/org-sj7uyvp-.js +0 -40
  211. package/dist/output-C4o2gJ1K.js +0 -146
  212. package/dist/params-l3CrvRtR.js +0 -51
  213. package/dist/pipeline-BqzqZhX1.js +0 -977
  214. package/dist/print-skill-ZojRSybs.js +0 -74
  215. package/dist/promote-BG8X4Nv_.js +0 -88
  216. package/dist/publish-sxLh-G4G.js +0 -35
  217. package/dist/push-bQ6Vxtg8.js +0 -35
  218. package/dist/query-_FbybaH-.js +0 -53
  219. package/dist/resource-CGIwSd29.js +0 -323
  220. package/dist/revenue-provider-ebsRINY8.js +0 -100
  221. package/dist/scope-BvzD-kO4.js +0 -223
  222. package/dist/skills-D_R-lEsK.js +0 -64
  223. package/dist/spinner-TWa0hia6.js +0 -18
  224. package/dist/storekit-Cj9Cpjcz.js +0 -29
  225. package/dist/telemetry-DeA1mvnT.js +0 -169
  226. package/dist/ui-Dy0b-9L8.js +0 -27738
  227. package/dist/update-B2fWIc4q.js +0 -59
  228. package/dist/upgrade-BmzkTKrh.js +0 -72
  229. /package/dist/{devtools-8EgLo86w.js → devtools-pBl_vt03.js} +0 -0
@@ -1,778 +0,0 @@
1
- import { v as SUPERWALL_HOME } from "./output-C4o2gJ1K.js";
2
- import "./telemetry-DeA1mvnT.js";
3
- import "./update-B2fWIc4q.js";
4
- import "./token-C0it-Xh7.js";
5
- import { t as defineCommand } from "./command-CMIz81Da.js";
6
- import "./ui-Dy0b-9L8.js";
7
- import "./scan-zKsddO72.js";
8
- import "./existing-AVEfZu2A.js";
9
- import "./spinner-TWa0hia6.js";
10
- import { T as rowName } from "./resources-Bf9O1JNM.js";
11
- import { t as requireOrg } from "./org-sj7uyvp-.js";
12
- import { t as parseParams } from "./params-l3CrvRtR.js";
13
- import { n as emitJson, t as apiCall } from "./api-output-aJNw7Syy.js";
14
- import { c as saveAppAscKey, i as deleteAscConfig, l as saveAppPurchaseKey, o as listAscConfigs, r as createAscConfig, s as replaceAscConfig, t as ascProxy } from "./asc-Bf7zBbyS.js";
15
- import { i as listAscApps, n as fetchUnimportedAscProducts, r as findAscAppId, t as ascTypeDisplay } from "./asc-products-9JXtDxI4.js";
16
- import { S as appleDeps, a as KEY_KINDS, f as keyKind, g as text, i as runNotificationUrl, m as savedKey, o as KEY_LABEL, s as appFlags, u as createAppKey, v as chooseIosApp, x as savedBundleId, y as differentBundleId } from "./notification-url-DuKF2659.js";
17
- import { c as getIntegrations, d as removeAppKey, l as importAppKey, o as copyAppKey, u as listKeySources } from "./scope-BvzD-kO4.js";
18
- import { n as testModeWarning } from "./bundle-id-CKxl_026.js";
19
- import { dirname, join } from "node:path";
20
- import { homedir } from "node:os";
21
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
22
- import { spawn } from "node:child_process";
23
- import { inflateRawSync } from "node:zlib";
24
-
25
- //#region src/core/api/asc-index.ts
26
- const SPEC_URL = "https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip";
27
- const REFRESH_TTL_MS = 10080 * 60 * 1e3;
28
- function cachePath() {
29
- return process.env.SUPERWALL_ASC_INDEX_PATH ?? join(SUPERWALL_HOME() ?? join(homedir(), ".superwall"), "asc-index.json");
30
- }
31
- let mem;
32
- function readCachedIndex() {
33
- if (mem) return mem;
34
- return mem = JSON.parse(readFileSync(cachePath(), "utf8"));
35
- }
36
- function indexIsStale(index$1) {
37
- return !index$1.fetchedAt || Date.now() - index$1.fetchedAt > REFRESH_TTL_MS;
38
- }
39
- function writeCachedIndex(index$1) {
40
- const path = cachePath();
41
- mkdirSync(dirname(path), { recursive: true });
42
- const tmp = `${path}.${process.pid}.tmp`;
43
- writeFileSync(tmp, JSON.stringify(index$1));
44
- renameSync(tmp, path);
45
- mem = index$1;
46
- }
47
- function unzipSingleJson(zip) {
48
- let eocd = zip.length - 22;
49
- while (eocd >= 0 && zip.readUInt32LE(eocd) !== 101010256) eocd--;
50
- if (eocd < 0) throw new Error("App Store Connect spec: no zip directory found.");
51
- let entry = zip.readUInt32LE(eocd + 16);
52
- const count = zip.readUInt16LE(eocd + 10);
53
- for (let i = 0; i < count; i++) {
54
- if (zip.readUInt32LE(entry) !== 33639248) throw new Error("App Store Connect spec: malformed zip directory.");
55
- const method = zip.readUInt16LE(entry + 10);
56
- const compSize = zip.readUInt32LE(entry + 20);
57
- const nameLen = zip.readUInt16LE(entry + 28);
58
- const extraLen = zip.readUInt16LE(entry + 30);
59
- const commentLen = zip.readUInt16LE(entry + 32);
60
- const localOff = zip.readUInt32LE(entry + 42);
61
- if (zip.toString("utf8", entry + 46, entry + 46 + nameLen).endsWith(".json")) {
62
- const lNameLen = zip.readUInt16LE(localOff + 26);
63
- const lExtraLen = zip.readUInt16LE(localOff + 28);
64
- const start = localOff + 30 + lNameLen + lExtraLen;
65
- const data = zip.subarray(start, start + compSize);
66
- return method === 0 ? data : inflateRawSync(data);
67
- }
68
- entry += 46 + nameLen + extraLen + commentLen;
69
- }
70
- throw new Error("App Store Connect spec: no JSON entry in archive.");
71
- }
72
- const METHODS = [
73
- "get",
74
- "post",
75
- "patch",
76
- "delete",
77
- "put"
78
- ];
79
- function deriveIndex(spec) {
80
- const schemas = spec.components?.schemas ?? {};
81
- const deref = (node) => node && node.$ref ? schemas[node.$ref.split("/").pop()] : node;
82
- const fields = (schema) => {
83
- const out = {};
84
- if (!schema) return out;
85
- const required = new Set(schema.required ?? []);
86
- for (const [name, raw] of Object.entries(schema.properties ?? {})) {
87
- const p = deref(raw);
88
- const f = { required: required.has(name) };
89
- if (Array.isArray(p.enum)) f.enum = p.enum;
90
- else if (p.type) f.type = p.type;
91
- out[name] = f;
92
- }
93
- return out;
94
- };
95
- const relationships = (schema) => {
96
- const out = {};
97
- if (!schema) return out;
98
- const required = new Set(schema.required ?? []);
99
- for (const [name, raw] of Object.entries(schema.properties ?? {})) {
100
- const data = deref(deref(raw)?.properties?.data);
101
- const rel = { required: required.has(name) };
102
- const ident = data?.type === "array" ? deref(data.items) : data;
103
- rel.many = data?.type === "array";
104
- const t = deref(ident?.properties?.type);
105
- if (Array.isArray(t?.enum)) rel.target = t.enum[0];
106
- out[name] = rel;
107
- }
108
- return out;
109
- };
110
- const paths = {};
111
- for (const [path, ops] of Object.entries(spec.paths ?? {})) for (const method of METHODS) {
112
- const op = ops[method];
113
- if (!op) continue;
114
- const entry = {
115
- opId: op.operationId,
116
- summary: op.summary,
117
- ...op.deprecated ? { deprecated: true } : {}
118
- };
119
- const bodySchema = deref(deref(op.requestBody)?.content?.["application/json"]?.schema);
120
- if (bodySchema) {
121
- const data = deref(bodySchema.properties?.data);
122
- const type = deref(data?.properties?.type);
123
- if (Array.isArray(type?.enum)) entry.dataType = type.enum[0];
124
- const attrs = fields(deref(data?.properties?.attributes));
125
- const rels = relationships(deref(data?.properties?.relationships));
126
- if (Object.keys(attrs).length) entry.attributes = attrs;
127
- if (Object.keys(rels).length) entry.relationships = rels;
128
- }
129
- const query = (op.parameters ?? []).map(deref).filter((p) => p?.in === "query").map((p) => p.name);
130
- if (query.length) entry.query = query;
131
- (paths[path] ??= {})[method] = entry;
132
- }
133
- return {
134
- specVersion: String(spec.info?.version ?? "unknown"),
135
- openapi: String(spec.openapi ?? "unknown"),
136
- paths
137
- };
138
- }
139
- async function fetchAscIndex() {
140
- const res = await fetch(SPEC_URL);
141
- if (!res.ok) throw new Error(`Couldn't fetch the App Store Connect schema (HTTP ${res.status}). Check your connection and retry.`);
142
- const zip = Buffer.from(await res.arrayBuffer());
143
- const index$1 = deriveIndex(JSON.parse(unzipSingleJson(zip).toString("utf8")));
144
- index$1.fetchedAt = Date.now();
145
- return index$1;
146
- }
147
- function triggerBackgroundRefresh() {
148
- if (process.env.SW_ASC_REFRESH === "1") return;
149
- const entry = process.argv[1];
150
- if (!entry) return;
151
- try {
152
- spawn(process.execPath, [
153
- entry,
154
- "asc",
155
- "docs",
156
- "refresh",
157
- "--quiet"
158
- ], {
159
- detached: true,
160
- stdio: "ignore",
161
- env: {
162
- ...process.env,
163
- SW_ASC_REFRESH: "1"
164
- }
165
- }).unref();
166
- } catch {
167
- return;
168
- }
169
- }
170
-
171
- //#endregion
172
- //#region src/core/api/asc-schema.ts
173
- function index() {
174
- return readCachedIndex();
175
- }
176
- function segments(path) {
177
- return path.split("?")[0].split("/").filter(Boolean);
178
- }
179
- function matches(tmpl, concrete) {
180
- if (tmpl.length !== concrete.length) return false;
181
- return tmpl.every((s, i) => s.startsWith("{") || concrete[i].startsWith("{") || s === concrete[i]);
182
- }
183
- function lookupAscOp(method, rawPath) {
184
- const m = method.toLowerCase();
185
- const concrete = segments(rawPath);
186
- for (const [tmpl, ops] of Object.entries(index().paths)) if (ops[m] && matches(segments(tmpl), concrete)) return {
187
- path: tmpl,
188
- op: ops[m]
189
- };
190
- }
191
- function castAttr(field, v) {
192
- if (typeof v !== "string" || !field) return v;
193
- if (field.type === "boolean") {
194
- if (v === "true") return true;
195
- if (v === "false") return false;
196
- }
197
- if ((field.type === "integer" || field.type === "number") && v.trim() !== "") {
198
- const n = Number(v);
199
- if (!Number.isNaN(n)) return n;
200
- }
201
- return v;
202
- }
203
- function lastId(rawPath) {
204
- const segs = segments(rawPath);
205
- const last = segs[segs.length - 1];
206
- return last && !last.startsWith("{") ? last : void 0;
207
- }
208
- function buildAscBody(op, method, rawPath, flat) {
209
- if (!op.dataType) return flat;
210
- if (flat.data && typeof flat.data === "object") return flat;
211
- const attributes = {};
212
- const relationships = {};
213
- for (const [k, v] of Object.entries(flat)) {
214
- const rel = op.relationships?.[k];
215
- if (rel) {
216
- const ids = rel.many ? Array.isArray(v) ? v : [v] : v;
217
- relationships[k] = { data: rel.many ? ids.map((id) => ({
218
- type: rel.target,
219
- id: String(id)
220
- })) : {
221
- type: rel.target,
222
- id: String(ids)
223
- } };
224
- } else attributes[k] = castAttr(op.attributes?.[k], v);
225
- }
226
- const data = { type: op.dataType };
227
- if (method.toLowerCase() === "patch") {
228
- const id = lastId(rawPath);
229
- if (id) data.id = id;
230
- }
231
- if (Object.keys(attributes).length) data.attributes = attributes;
232
- if (Object.keys(relationships).length) data.relationships = relationships;
233
- return { data };
234
- }
235
- function validateAscBody(op, method, body) {
236
- const problems = [];
237
- const data = body.data ?? {};
238
- const attrs = data.attributes ?? {};
239
- const rels = data.relationships ?? {};
240
- const isPatch = method.toLowerCase() === "patch";
241
- for (const [name, f] of Object.entries(op.attributes ?? {})) {
242
- if (f.required && !isPatch && !(name in attrs)) problems.push(`missing required attribute: ${name}`);
243
- const val = attrs[name];
244
- if (f.enum && typeof val === "string" && !f.enum.includes(val)) problems.push(`${name} "${val}" not allowed — use ${f.enum.join("|")}`);
245
- }
246
- for (const [name, r] of Object.entries(op.relationships ?? {})) if (r.required && !isPatch && !(name in rels)) problems.push(`missing required relationship: ${name}${r.target ? ` → ${r.target}` : ""}`);
247
- return problems;
248
- }
249
- function exampleInvocation(method, path, op) {
250
- const parts = [`superwall asc ${method.toLowerCase()} ${path}`];
251
- for (const [name, f] of Object.entries(op.attributes ?? {})) {
252
- if (!f.required) continue;
253
- parts.push(`-d ${name}=${f.enum ? f.enum[0] : `<${f.type ?? "value"}>`}`);
254
- }
255
- for (const [name, r] of Object.entries(op.relationships ?? {})) if (r.required) parts.push(`-d ${name}=<${r.target ?? "id"} id>`);
256
- return parts.join(" ");
257
- }
258
- function renderOp(method, path, op) {
259
- const lines = [];
260
- lines.push(`### ${method.toUpperCase()} ${path}`);
261
- if (op.summary) lines.push(op.summary);
262
- if (op.deprecated) lines.push("> ⚠ Deprecated in the App Store Connect API.");
263
- const attrs = Object.entries(op.attributes ?? {});
264
- const rels = Object.entries(op.relationships ?? {});
265
- if (op.dataType) lines.push("", `Body → \`data.type: ${op.dataType}\``);
266
- if (attrs.length) {
267
- lines.push("", "Attributes:");
268
- for (const [name, f] of attrs) {
269
- const kind = f.enum ? f.enum.join("|") : f.type ?? "";
270
- lines.push(` - ${name} ${kind}${f.required ? " (required)" : ""}`);
271
- }
272
- }
273
- if (rels.length) {
274
- lines.push("", "Relationships:");
275
- for (const [name, r] of rels) lines.push(` - ${name} → ${r.target ?? "?"}${r.many ? "[]" : ""}${r.required ? " (required)" : ""}`);
276
- }
277
- if (op.query?.length) lines.push("", `Query: ${op.query.map((q) => `\`${q}\``).join(", ")}`);
278
- lines.push("", "Example:", ` ${exampleInvocation(method, path, op)}`);
279
- return lines.join("\n");
280
- }
281
- function renderAscDocs(query, verb) {
282
- const idx = index();
283
- const header = `App Store Connect API — spec ${idx.specVersion}\n`;
284
- if (!query.trim()) {
285
- const roots = /* @__PURE__ */ new Set();
286
- for (const tmpl of Object.keys(idx.paths)) if (segments(tmpl).length === 2) roots.add(tmpl);
287
- const list = [...roots].sort();
288
- return `${header}\n${list.length} top-level resources. Run \`asc docs <path> [verb]\` for a schema, or \`asc docs <search term>\` to filter.
289
-
290
- ` + list.join("\n");
291
- }
292
- if (query.startsWith("/")) {
293
- const concrete = segments(query);
294
- const out = [];
295
- for (const [tmpl, ops] of Object.entries(idx.paths)) {
296
- if (!matches(segments(tmpl), concrete)) continue;
297
- for (const [method, op] of Object.entries(ops)) {
298
- if (verb && method !== verb.toLowerCase()) continue;
299
- out.push(renderOp(method, tmpl, op));
300
- }
301
- }
302
- if (!out.length) return `${header}\nNo operation matches ${query}. Try \`asc docs <search term>\`.`;
303
- return `${header}\n${out.join("\n\n")}`;
304
- }
305
- const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
306
- const hits = [];
307
- for (const [tmpl, ops] of Object.entries(idx.paths)) for (const [method, op] of Object.entries(ops)) {
308
- const hay = `${tmpl} ${op.summary ?? ""} ${op.opId ?? ""}`.toLowerCase();
309
- if (terms.every((t) => hay.includes(t))) hits.push(`${method.toUpperCase().padEnd(6)} ${tmpl}${op.summary ? ` — ${op.summary}` : ""}`);
310
- }
311
- if (!hits.length) return `${header}\nNothing matches "${query}".`;
312
- return `${header}\n${hits.slice(0, 60).join("\n")}${hits.length > 60 ? `\n… ${hits.length - 60} more` : ""}\n\nRun \`asc docs <path> [verb]\` for a full schema.`;
313
- }
314
-
315
- //#endregion
316
- //#region src/commands/platform/app-keys.ts
317
- async function target(ctx) {
318
- const chosen = await chooseIosApp(ctx, ctx.api, appFlags(ctx));
319
- return {
320
- ctx,
321
- app: {
322
- projectId: String(chosen.project.id),
323
- applicationId: String(chosen.app.id)
324
- },
325
- name: chosen.app.name ?? String(chosen.app.id),
326
- savedBundleId: savedBundleId(chosen.app)
327
- };
328
- }
329
- function purchaseKeyBundleId(ctx, { app, name, savedBundleId: saved }) {
330
- const wanted = text(ctx, "bundle-id");
331
- if (!wanted) {
332
- if (saved) return {
333
- bundleId: saved,
334
- setApplicationBundleId: false
335
- };
336
- throw new Error(`\`${name}\` has no bundle ID in Superwall. Pass --bundle-id <id> to save it with the key, or set it first with \`superwall apps bundle-id <id> --app ${app.applicationId}\`.`);
337
- }
338
- if (saved && saved !== wanted) throw new Error(differentBundleId(name, app.applicationId, saved, wanted));
339
- return {
340
- bundleId: wanted,
341
- setApplicationBundleId: saved === null
342
- };
343
- }
344
- function requireKind(ctx, action) {
345
- const kind = keyKind(ctx.argv.value2);
346
- if (!kind) throw new Error(`Usage: superwall asc keys ${action} <api_key | purchase_key> --app <id>`);
347
- return kind;
348
- }
349
- async function listAppKeys(ctx) {
350
- const { app, name } = await target(ctx);
351
- const saved = await apiCall(ctx, "Loading keys", () => getIntegrations(ctx.api, app.applicationId));
352
- const keys = Object.fromEntries(KEY_KINDS.map((kind) => {
353
- const key = savedKey(saved, kind);
354
- return [kind, key ? {
355
- key_id: key.key_id,
356
- issuer_id: key.issuer_id,
357
- ...key.bundle_id ? { bundle_id: key.bundle_id } : {}
358
- } : null];
359
- }));
360
- if (ctx.json) return emitJson(ctx, {
361
- application_id: app.applicationId,
362
- ...keys
363
- });
364
- ctx.ui.step(`Apple keys saved on \`${name}\``);
365
- ctx.ui.report(KEY_KINDS.map((kind) => {
366
- const key = savedKey(saved, kind);
367
- return `${key ? "✓" : "✗"} ${KEY_LABEL[kind]} ${key ? key.key_id : "not saved"}`;
368
- }).join("\n"));
369
- }
370
- async function setAppKey(ctx, input) {
371
- const kind = ctx.argv.value2 === void 0 ? "api_key" : requireKind(ctx, "set");
372
- const chosen = await target(ctx);
373
- const { app, name } = chosen;
374
- const bundle = kind === "purchase_key" ? purchaseKeyBundleId(ctx, chosen) : void 0;
375
- if (ctx.dryRun) {
376
- const plan = {
377
- dryRun: true,
378
- action: "set",
379
- kind,
380
- application_id: app.applicationId,
381
- keyId: input.keyId,
382
- ...bundle ? {
383
- bundle_id: bundle.bundleId,
384
- set_application_bundle_id: bundle.setApplicationBundleId
385
- } : {}
386
- };
387
- const alsoBundle = bundle?.setApplicationBundleId ? ` and its bundle ID ${bundle.bundleId}` : "";
388
- ctx.json ? emitJson(ctx, plan) : ctx.ui.info(`[dry-run] would save ${KEY_LABEL[kind]} ${input.keyId}${alsoBundle} on ${name}`);
389
- return;
390
- }
391
- if (bundle?.setApplicationBundleId) {
392
- const warning = await testModeWarning(ctx, ctx.api, app.applicationId, bundle.bundleId);
393
- if (warning) ctx.ui.warn(warning);
394
- }
395
- const credentials = {
396
- keyId: input.keyId,
397
- issuerId: input.issuerId,
398
- privateKey: readFileSync(input.keyFile, "utf8")
399
- };
400
- const verdict = await apiCall(ctx, `Saving the ${KEY_LABEL[kind]}`, () => kind === "api_key" ? saveAppAscKey(ctx.api, app, credentials) : saveAppPurchaseKey(ctx.api, app, {
401
- ...credentials,
402
- ...bundle
403
- }));
404
- if (ctx.json) emitJson(ctx, {
405
- application_id: app.applicationId,
406
- kind,
407
- key_id: input.keyId,
408
- ...verdict,
409
- ...bundle ? {
410
- bundle_id: bundle.bundleId,
411
- bundle_id_saved: verdict.valid && bundle.setApplicationBundleId
412
- } : {}
413
- });
414
- else if (verdict.valid) ctx.ui.success(bundle?.setApplicationBundleId ? `${KEY_LABEL[kind]} ${input.keyId} and the bundle ID ${bundle.bundleId} saved on \`${name}\`.` : `${KEY_LABEL[kind]} ${input.keyId} saved on \`${name}\`.`);
415
- else ctx.ui.error(`Apple didn't accept ${KEY_LABEL[kind]} ${input.keyId}${verdict.error ? `: ${verdict.error}` : "."}`);
416
- if (!verdict.valid) process.exitCode = 1;
417
- }
418
- async function removeAppKeyCommand(ctx) {
419
- const kind = requireKind(ctx, "rm");
420
- const { app, name } = await target(ctx);
421
- if (ctx.dryRun) {
422
- const plan = {
423
- dryRun: true,
424
- action: "rm",
425
- kind,
426
- application_id: app.applicationId
427
- };
428
- ctx.json ? emitJson(ctx, plan) : ctx.ui.info(`[dry-run] would remove the ${KEY_LABEL[kind]} from ${name}`);
429
- return;
430
- }
431
- await apiCall(ctx, "Removing the key", () => removeAppKey(ctx.api, app.applicationId, kind));
432
- if (ctx.json) return emitJson(ctx, {
433
- deleted: true,
434
- kind,
435
- application_id: app.applicationId
436
- });
437
- ctx.ui.success(`Removed the ${KEY_LABEL[kind]} from \`${name}\`. Nothing was revoked at Apple, and your organization's copy is kept.`);
438
- }
439
- async function listAppKeySources(ctx) {
440
- const { app, name } = await target(ctx);
441
- const sources = await apiCall(ctx, "Loading keys on your other apps", () => listKeySources(ctx.api, app.applicationId));
442
- if (ctx.json) return emitJson(ctx, {
443
- application_id: app.applicationId,
444
- api_key: sources.api_key,
445
- purchase_key: sources.purchase_key
446
- });
447
- const total = sources.api_key.length + sources.purchase_key.length;
448
- if (total === 0) return void ctx.ui.step(`No other app has a key \`${name}\` could use`);
449
- ctx.ui.step(`${total} key${total === 1 ? "" : "s"} on your other apps`);
450
- for (const kind of KEY_KINDS) for (const source of sources[kind]) {
451
- const more = source.others_count > 0 ? ` and ${source.others_count} more` : "";
452
- ctx.ui.info(`\`${source.key_id}\` ${KEY_LABEL[kind]} from ${source.name}${more} (app ${source.application_id})`);
453
- }
454
- }
455
- async function copyAppKeyCommand(ctx) {
456
- const kind = requireKind(ctx, "copy");
457
- const from = text(ctx, "from");
458
- if (!from) throw new Error(`Usage: superwall asc keys copy ${kind} --app <id> --from <app id>. \`superwall asc keys sources --app <id>\` lists the apps to copy from.`);
459
- const { app, name } = await target(ctx);
460
- if (ctx.dryRun) {
461
- const plan = {
462
- dryRun: true,
463
- action: "copy",
464
- kind,
465
- application_id: app.applicationId,
466
- from
467
- };
468
- ctx.json ? emitJson(ctx, plan) : ctx.ui.info(`[dry-run] would copy the ${KEY_LABEL[kind]} from app ${from} to ${name}`);
469
- return;
470
- }
471
- const copy = (confirmed) => apiCall(ctx, `Copying the ${KEY_LABEL[kind]}`, () => copyAppKey(ctx.api, app.applicationId, {
472
- kind,
473
- from,
474
- confirmed
475
- }));
476
- let result = await copy(ctx.argv["allow-unconfirmed"] === true);
477
- if (!result.valid && result.unconfirmed && ctx.interactive) {
478
- ctx.ui.warn(result.unconfirmed);
479
- if (await ctx.ui.confirm({ message: "Save this key anyway?" })) result = await copy(true);
480
- }
481
- if (ctx.json) emitJson(ctx, {
482
- application_id: app.applicationId,
483
- kind,
484
- from,
485
- valid: result.valid,
486
- error: result.error,
487
- unconfirmed: result.unconfirmed
488
- });
489
- else if (result.valid) ctx.ui.success(`${KEY_LABEL[kind]} copied to \`${name}\`.`);
490
- else if (result.unconfirmed) ctx.ui.error(`${result.unconfirmed}\nNothing was saved. Pass --allow-unconfirmed to save it anyway, once a person has confirmed it is the right team's key.`);
491
- else ctx.ui.error(`${result.error ?? "The key wasn't copied."}\nNothing was saved.`);
492
- if (!result.valid) process.exitCode = 1;
493
- }
494
- function describeImport(result, name) {
495
- const label = KEY_LABEL[result.kind];
496
- if (result.status === "imported") return `${label} ${result.key_id ?? ""} imported to ${name}${result.source_name ? ` from ${result.source_name}` : ""}.`;
497
- if (result.status === "already_saved") return `${name} already has an ${label}${result.key_id ? ` (${result.key_id})` : ""}. It was left as it is.`;
498
- if (result.timed_out) return `No ${label} confirmed for ${name} before the search ran out of time (${result.tried} tried). Run it again.`;
499
- return result.tried === 0 ? `Your organization has no ${label} to try on ${name}.` : `None of your organization's ${result.tried} saved ${label}s is confirmed by Apple for ${name}.`;
500
- }
501
- async function importAppKeys(ctx) {
502
- const requested = ctx.argv.value2;
503
- const one = keyKind(requested);
504
- if (requested !== void 0 && !one) throw new Error("Usage: superwall asc keys import [api_key | purchase_key] --app <id>");
505
- const kinds = one ? [one] : KEY_KINDS;
506
- const { app, name } = await target(ctx);
507
- if (ctx.dryRun) {
508
- const plan = {
509
- dryRun: true,
510
- action: "import",
511
- kinds,
512
- application_id: app.applicationId
513
- };
514
- ctx.json ? emitJson(ctx, plan) : ctx.ui.info(`[dry-run] would try your organization's saved keys on ${name}`);
515
- return;
516
- }
517
- const results = [];
518
- for (const kind of kinds) results.push(await apiCall(ctx, `Trying your organization's ${KEY_LABEL[kind]}s`, () => importAppKey(ctx.api, app.applicationId, kind)));
519
- if (results.some((result) => result.status === "not_found")) process.exitCode = 1;
520
- if (ctx.json) return emitJson(ctx, {
521
- application_id: app.applicationId,
522
- results: results.map((result) => ({
523
- kind: result.kind,
524
- status: result.status,
525
- key_id: result.key_id,
526
- source_name: result.source_name,
527
- source_application_id: result.source_application_id,
528
- tried: result.tried,
529
- timed_out: result.timed_out
530
- }))
531
- });
532
- ctx.ui.report(results.map((result) => `${result.status === "not_found" ? "✗" : "✓"} ${describeImport(result, name)}`).join("\n"));
533
- }
534
-
535
- //#endregion
536
- //#region src/commands/platform/keys.ts
537
- async function runAscKeys(ctx, api) {
538
- const action = ctx.argv.value ?? "list";
539
- const forApp = text(ctx, "app") !== void 0;
540
- if (action === "list") return forApp ? listAppKeys(ctx) : listKeys(ctx, api);
541
- if (action === "set") return setKey(ctx, api, forApp);
542
- if (action === "rm") return forApp ? removeAppKeyCommand(ctx) : removeKey(ctx, api);
543
- if (action === "create") return createAppKey(ctx, appleDeps);
544
- if (action === "sources") return listAppKeySources(ctx);
545
- if (action === "copy") return copyAppKeyCommand(ctx);
546
- if (action === "import") return importAppKeys(ctx);
547
- throw new Error(`Unknown "asc keys ${action}". Use list | set | rm | create | sources | copy | import.`);
548
- }
549
- async function listKeys(ctx, api) {
550
- const configs = await apiCall(ctx, "Loading credentials", () => listAscConfigs(api));
551
- if (ctx.json) return emitJson(ctx, configs);
552
- if (configs.length === 0) {
553
- ctx.ui.step("No App Store Connect credentials yet");
554
- if (ctx.interactive) {
555
- if (await ctx.ui.confirm({ message: "Connect an App Store Connect key now?" })) return setKey(ctx, api, false);
556
- return;
557
- }
558
- ctx.ui.info("Add one: superwall asc keys set --key-id <id> --issuer <id> --key-file <path.p8>");
559
- return;
560
- }
561
- ctx.ui.step(`${configs.length} App Store Connect credential${configs.length === 1 ? "" : "s"}`);
562
- for (const c of configs) ctx.ui.info(`\`${rowName(c)}\` ${c.team_id ?? c.id ?? ""}`);
563
- }
564
- async function setKey(ctx, api, forApp) {
565
- const input = await resolveKeyInput(ctx, forApp);
566
- if (!input) return void ctx.ui.warn("Cancelled.");
567
- if (forApp) return setAppKey(ctx, input);
568
- const { keyId, issuerId, keyFile, accountName } = input;
569
- const teamId = text(ctx, "team");
570
- if (ctx.dryRun) {
571
- const plan = {
572
- dryRun: true,
573
- action: "set",
574
- keyId,
575
- issuerId,
576
- keyFile,
577
- ...teamId ? { teamId } : {}
578
- };
579
- ctx.json ? emitJson(ctx, plan) : ctx.ui.info(`[dry-run] would upload ASC key ${keyId} (issuer ${issuerId}) from ${keyFile}`);
580
- return;
581
- }
582
- const credentials = {
583
- keyId,
584
- issuerId,
585
- privateKey: readFileSync(keyFile, "utf8"),
586
- accountName
587
- };
588
- const created = await apiCall(ctx, "Connecting App Store Connect", () => teamId ? replaceAscConfig(api, teamId, credentials) : createAscConfig(api, {
589
- ...credentials,
590
- accountName: accountName ?? "App Store Connect"
591
- }));
592
- if (ctx.json) return emitJson(ctx, created);
593
- ctx.ui.success(`App Store Connect connected ${created.team_id ?? created.id ?? ""}`);
594
- }
595
- async function removeKey(ctx, api) {
596
- const teamId = ctx.argv.value2;
597
- if (!teamId) throw new Error("Usage: superwall asc keys rm <team_id>");
598
- if (keyKind(teamId)) throw new Error(`Usage: superwall asc keys rm ${teamId} --app <id>`);
599
- if (ctx.dryRun) {
600
- const plan = {
601
- dryRun: true,
602
- action: "rm",
603
- teamId
604
- };
605
- ctx.json ? emitJson(ctx, plan) : ctx.ui.info(`[dry-run] would delete ASC credential ${teamId}`);
606
- return;
607
- }
608
- await apiCall(ctx, "Removing credential", () => deleteAscConfig(api, teamId));
609
- if (ctx.json) return emitJson(ctx, {
610
- deleted: true,
611
- teamId
612
- });
613
- ctx.ui.success(`Removed App Store Connect credential ${teamId}`);
614
- }
615
- async function resolveKeyInput(ctx, forApp) {
616
- const { argv, ui, interactive } = ctx;
617
- let keyId = argv["key-id"]?.trim();
618
- let issuerId = argv.issuer?.trim();
619
- let keyFile = argv["key-file"]?.trim();
620
- let name = argv.name?.trim();
621
- if (interactive && (!keyId || !issuerId || !keyFile)) {
622
- ui.note(forApp ? "You'll need the key's Key ID, its Issuer ID, and the downloaded .p8 file,\nfrom App Store Connect → Users and Access → Integrations." : "Create a key in App Store Connect → Users and Access → Integrations →\nApp Store Connect API. You'll need its Key ID, the Issuer ID, and the\ndownloaded .p8 file. This is stored org-wide for the signed proxy.", forApp ? "Save an Apple key on the app" : "Connect App Store Connect");
623
- if (!keyId) {
624
- const v = await ui.text({
625
- message: "Key ID",
626
- placeholder: "2X9R4HXF34",
627
- validate: (s) => s?.trim() ? void 0 : "Required"
628
- });
629
- if (v === null) return null;
630
- keyId = v.trim();
631
- }
632
- if (!issuerId) {
633
- const v = await ui.text({
634
- message: "Issuer ID",
635
- placeholder: "57246542-96fe-1a63-e053-0824d011072a",
636
- validate: (s) => s?.trim() ? void 0 : "Required"
637
- });
638
- if (v === null) return null;
639
- issuerId = v.trim();
640
- }
641
- if (!keyFile) {
642
- const v = await ui.text({
643
- message: "Path to the .p8 key file",
644
- placeholder: "~/Downloads/AuthKey_2X9R4HXF34.p8",
645
- validate: (s) => {
646
- const path$1 = expandHome(s?.trim() ?? "");
647
- if (!path$1) return "Required";
648
- if (!existsSync(path$1)) return "No file at that path";
649
- }
650
- });
651
- if (v === null) return null;
652
- keyFile = v.trim();
653
- }
654
- if (!name && !forApp) {
655
- const v = await ui.text({
656
- message: "Name (optional)",
657
- placeholder: "App Store Connect"
658
- });
659
- if (v === null) return null;
660
- name = v.trim();
661
- }
662
- }
663
- if (!keyId || !issuerId || !keyFile) throw new Error(forApp ? "Usage: superwall asc keys set [api_key | purchase_key] --app <id> --key-id <id> --issuer <id> --key-file <path.p8>" : "Usage: superwall asc keys set --key-id <id> --issuer <id> --key-file <path.p8> [--name <name>] [--team <id>]");
664
- const path = expandHome(keyFile);
665
- if (!existsSync(path)) throw new Error(`Couldn't find the .p8 key file at ${keyFile}`);
666
- return {
667
- keyId,
668
- issuerId,
669
- keyFile: path,
670
- ...name ? { accountName: name } : {}
671
- };
672
- }
673
- function expandHome(path) {
674
- return path.startsWith("~/") ? `${homedir()}/${path.slice(2)}` : path;
675
- }
676
-
677
- //#endregion
678
- //#region src/commands/platform/asc.ts
679
- const VERBS = new Set([
680
- "get",
681
- "post",
682
- "patch",
683
- "delete"
684
- ]);
685
- async function ensureAscIndex(ctx) {
686
- let cached;
687
- try {
688
- cached = readCachedIndex();
689
- } catch {
690
- cached = void 0;
691
- }
692
- if (!cached) {
693
- writeCachedIndex(await apiCall(ctx, "Fetching App Store Connect schema", () => fetchAscIndex()));
694
- return;
695
- }
696
- if (indexIsStale(cached)) triggerBackgroundRefresh();
697
- }
698
- const runAsc = defineCommand({
699
- name: "asc",
700
- auth: "required",
701
- output: "both",
702
- async run(ctx) {
703
- const target$1 = String(ctx.argv.target ?? "");
704
- if (target$1 === "docs") {
705
- const query = String(ctx.argv.value ?? "");
706
- if (query === "refresh") {
707
- const quiet = Boolean(ctx.argv.quiet);
708
- const index$1 = quiet ? await fetchAscIndex() : await apiCall(ctx, "Updating App Store Connect schema", () => fetchAscIndex());
709
- writeCachedIndex(index$1);
710
- if (quiet) return;
711
- if (ctx.json) return emitJson(ctx, { specVersion: index$1.specVersion });
712
- process.stdout.write(`App Store Connect schema updated — spec ${index$1.specVersion}\n`);
713
- return;
714
- }
715
- await ensureAscIndex(ctx);
716
- const md = renderAscDocs(query, ctx.argv.value2);
717
- if (ctx.json) return emitJson(ctx, { markdown: md });
718
- process.stdout.write(`${md}\n`);
719
- return;
720
- }
721
- await requireOrg(ctx.api, ctx.interactive);
722
- if (target$1 === "keys") return runAscKeys(ctx, ctx.api);
723
- if (target$1 === "notification-url") return runNotificationUrl(ctx, appleDeps.sleep);
724
- if (VERBS.has(target$1)) {
725
- const path = String(ctx.argv.value ?? "");
726
- if (!path.startsWith("/")) throw new Error(`Path must start with "/", e.g. /v1/apps`);
727
- let body = parseParams(ctx.argv.d);
728
- if (target$1 === "post" || target$1 === "patch") {
729
- await ensureAscIndex(ctx);
730
- const found = lookupAscOp(target$1, path);
731
- if (found) {
732
- body = buildAscBody(found.op, target$1, path, body);
733
- const problems = validateAscBody(found.op, target$1, body);
734
- if (problems.length && !ctx.argv.force) throw new Error(`Invalid ${target$1.toUpperCase()} ${path} body:\n` + problems.map((p) => ` • ${p}`).join("\n") + `\nFix and retry, run \`superwall asc docs ${path} ${target$1}\`, or pass --force to send as-is.`);
735
- }
736
- }
737
- const teamId$1 = await resolveTeam(ctx, ctx.api);
738
- return emitJson(ctx, await apiCall(ctx, `${target$1.toUpperCase()} ${path}`, () => ascProxy(ctx.api, teamId$1, target$1, path, body)));
739
- }
740
- const teamId = await resolveTeam(ctx, ctx.api);
741
- if (target$1.startsWith("/")) return emitJson(ctx, await apiCall(ctx, `GET ${target$1}`, () => ascProxy(ctx.api, teamId, "GET", target$1)));
742
- if (target$1 === "apps") {
743
- const apps = await apiCall(ctx, "Loading apps", () => listAscApps(ctx.api, teamId));
744
- if (ctx.json) return emitJson(ctx, apps);
745
- ctx.ui.step(`${apps.length} app${apps.length === 1 ? "" : "s"}`);
746
- for (const a of apps) ctx.ui.info(`\`${a.name ?? a.id}\` ${a.bundleId ?? ""} ${a.id}`);
747
- return;
748
- }
749
- if (target$1 === "products" || target$1 === "subscriptions" || target$1 === "iaps") {
750
- const appArg = ctx.argv.value;
751
- if (!appArg) throw new Error(`Usage: superwall asc ${target$1} <bundle-id | asc-app-id>`);
752
- const ascAppId = /^\d+$/.test(appArg) ? appArg : await apiCall(ctx, "Finding app", () => findAscAppId(ctx.api, teamId, appArg));
753
- if (!ascAppId) throw new Error(`No App Store Connect app found for "${appArg}".`);
754
- const all = await apiCall(ctx, "Loading products", () => fetchUnimportedAscProducts(ctx.api, teamId, ascAppId, /* @__PURE__ */ new Set()));
755
- const isSub = (t) => t.includes("SUBSCRIPTION") && t !== "NON_RENEWING_SUBSCRIPTION";
756
- const rows = target$1 === "subscriptions" ? all.filter((p) => isSub(p.type)) : target$1 === "iaps" ? all.filter((p) => !isSub(p.type)) : all;
757
- if (ctx.json) return emitJson(ctx, rows);
758
- ctx.ui.step(`${rows.length} product${rows.length === 1 ? "" : "s"}`);
759
- for (const p of rows) ctx.ui.info(`\`${p.productId}\` ${ascTypeDisplay(p.type)}${p.subscriptionPeriod ? ` ${p.subscriptionPeriod}` : ""}`);
760
- return;
761
- }
762
- throw new Error(`Unknown "${target$1}". Use get|post|patch|delete <path>, a raw path, or: apps | products | subscriptions | iaps | docs | keys | notification-url`);
763
- }
764
- });
765
- async function resolveTeam(ctx, api) {
766
- const flag = ctx.argv.team;
767
- if (flag) return flag;
768
- const configs = await apiCall(ctx, "Finding App Store Connect", () => listAscConfigs(api));
769
- if (configs.length === 0) throw new Error("App Store Connect isn't connected. Run `superwall asc keys set --help`.");
770
- if (configs.length > 1) {
771
- const teams = configs.map((c) => String(c.team_id ?? c.id ?? "")).join(", ");
772
- throw new Error(`Multiple App Store Connect teams (${teams}). Pass --team <id>.`);
773
- }
774
- return String(configs[0].team_id ?? configs[0].id ?? "");
775
- }
776
-
777
- //#endregion
778
- export { runAsc };