@superwall/cli 1.7.0 → 2.0.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 (165) hide show
  1. package/README.md +192 -52
  2. package/dist/{setup-Bxj22rYi.js → apple-CkKlHBZ9.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-XCZU_T46.js} +98 -28
  6. package/dist/{bind-YrJvuRF9.js → bind-drne__Ys.js} +38 -33
  7. package/dist/{build-DLoCW5Ri.js → build-Gpdq5QXP.js} +20 -26
  8. package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
  9. package/dist/client-DP6Rc0t_.js +176 -0
  10. package/dist/config-BO1Y87kV.js +105 -0
  11. package/dist/{notification-url-DuKF2659.js → create-BBrtgUgS.js} +235 -539
  12. package/dist/{create-pkANt1Gs.js → create-Cwc3SRWJ.js} +194 -168
  13. package/dist/create-Yvf2gStM.js +19 -0
  14. package/dist/doctor-C9ldpPFC.js +83 -0
  15. package/dist/{drivers-Qx9LxmRN.js → drivers-DNrx4LWA.js} +185 -172
  16. package/dist/entry.d.ts +0 -5
  17. package/dist/entry.js +28073 -1134
  18. package/dist/environment-DF1qKlny.js +58 -0
  19. package/dist/{existing-AVEfZu2A.js → existing-78LWSsqS.js} +12 -6
  20. package/dist/held-Cy8Wl4D1.js +1112 -0
  21. package/dist/held-Ddw1XSsr.js +16 -0
  22. package/dist/input-vi0bou04.js +42 -0
  23. package/dist/{integrate-brmhPG-S.js → integrate-DcJhpXy8.js} +277 -254
  24. package/dist/kinds-GFXB3sYu.js +11 -0
  25. package/dist/log-NVhVe_oe.js +62 -0
  26. package/dist/login-B2TsCE2H.js +53 -0
  27. package/dist/login-BoBe8Psl.js +16 -0
  28. package/dist/{login-Do4wFuLv.js → login-D0lh3_JI.js} +118 -55
  29. package/dist/lookup-D-nmmAbw.js +71 -0
  30. package/dist/migrate-Cfec564E.js +274 -0
  31. package/dist/notification-url-YDbq6FMA.js +100 -0
  32. package/dist/{open-studio-DOw-6ydc.js → open-Ba2vBl1_.js} +34 -43
  33. package/dist/org-D0g_q3mv.js +35 -0
  34. package/dist/output-Ggzq5_-t.js +122 -0
  35. package/dist/paths-DxSLdpOI.js +29 -0
  36. package/dist/playbook-DIeb7hne.js +53 -0
  37. package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
  38. package/dist/promote-COD4fYdz.js +91 -0
  39. package/dist/push-CncywhkQ.js +482 -0
  40. package/dist/push-CtD4FZQV.js +22 -0
  41. package/dist/registry-DSrosOYs.js +10228 -0
  42. package/dist/{reports-CfJqoava.js → reports-DdPq4blM.js} +7 -6
  43. package/dist/{resources-Bf9O1JNM.js → resources-Dqr01Dep.js} +150 -55
  44. package/dist/{run-DsVZ5snL.js → run-C9qg_QlC.js} +16 -22
  45. package/dist/scan-Cv5uOwVY.js +4 -0
  46. package/dist/{scan-zKsddO72.js → scan-DLrsrFS9.js} +48 -37
  47. package/dist/scope-V336uz8j.js +198 -0
  48. package/dist/screenshot-file-0UETadF8.js +16 -0
  49. package/dist/{selection-CxZoX4NT.js → selection-Rdw-ZUoG.js} +94 -51
  50. package/dist/send-BxD9yf6F.js +150 -0
  51. package/dist/{dev-DmB3XqaJ.js → server-D0tGG8C4.js} +82 -92
  52. package/dist/server-z1LH94R_.js +22 -0
  53. package/dist/session-1AV_Bs_d.js +6 -0
  54. package/dist/session-CFAmMhem.js +40 -0
  55. package/dist/session-D_nEWKXT.js +768 -0
  56. package/dist/skills/animate-onboarding/SKILL.md +467 -0
  57. package/dist/skills/animate-onboarding/references/engine.md +494 -0
  58. package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
  59. package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
  60. package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
  61. package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
  62. package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  63. package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
  64. package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
  65. package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  66. package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
  67. package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
  68. package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
  69. package/dist/skills/animate-onboarding/references/performance.md +41 -0
  70. package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
  71. package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  72. package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  73. package/dist/skills/index.json +37 -0
  74. package/dist/skills/mobile-design/SKILL.md +447 -0
  75. package/dist/skills/mobile-design/references/responsive.md +162 -0
  76. package/dist/skills/onboarding-questions/SKILL.md +231 -0
  77. package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
  78. package/dist/skills/onboarding-questions/references/craft.md +142 -0
  79. package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
  80. package/dist/skills/superwall/SKILL.md +82 -9
  81. package/dist/skills/superwall/references/api.md +153 -37
  82. package/dist/skills/superwall/references/apple-setup.md +316 -0
  83. package/dist/skills/superwall/references/asc.md +74 -38
  84. package/dist/skills/superwall/references/data-analytics.md +55 -21
  85. package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
  86. package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
  87. package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
  88. package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
  89. package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
  90. package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
  91. package/dist/skills/superwall/workflows/placements/android.md +2 -2
  92. package/dist/skills/superwall/workflows/placements/expo.md +2 -2
  93. package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
  94. package/dist/skills/superwall/workflows/placements/ios.md +2 -2
  95. package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
  96. package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
  97. package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
  98. package/dist/skills/superwall/workflows/review/playbook.md +1 -1
  99. package/dist/skills/superwall-editor/SKILL.md +61 -0
  100. package/dist/skills/superwall-editor/references/cli.md +135 -0
  101. package/dist/skills/superwall-editor/references/design.md +51 -0
  102. package/dist/skills/superwall-editor/references/native-elements.md +171 -0
  103. package/dist/skills/superwall-editor/references/workflow.md +65 -0
  104. package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
  105. package/dist/skills/superwall-framework/SKILL.md +78 -28
  106. package/dist/skills/superwall-framework/references/cli.md +58 -28
  107. package/dist/skills/superwall-framework/references/examples.md +4 -3
  108. package/dist/skills/superwall-framework/references/layout.md +30 -8
  109. package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
  110. package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
  111. package/dist/skills/wwdc/SKILL.md +22 -0
  112. package/dist/skills/wwdc/references/docs.md +52 -0
  113. package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
  114. package/dist/{skills-DPzlnfCK.js → skills-BvFOa4y6.js} +99 -122
  115. package/dist/skills-DMG4bpKk.js +14 -0
  116. package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
  117. package/dist/spinner-CneRK5rk.js +294 -0
  118. package/dist/storage-DYvmIOHa.d.ts +16 -0
  119. package/dist/storage-s2Dnz-yl.js +31 -0
  120. package/dist/storekit-DafAnGkM.js +16 -0
  121. package/dist/storekit-yY_kS2iR.js +47 -0
  122. package/dist/telemetry-DtG92m5O.js +56 -0
  123. package/dist/theme-DUsCh-Vd.js +25 -0
  124. package/dist/timing-BVxPrYq3.js +5 -0
  125. package/dist/{token-C0it-Xh7.js → token-DzRh7dI1.js} +6 -38
  126. package/dist/tools.d.ts +96 -0
  127. package/dist/tools.js +11178 -0
  128. package/dist/ui-D_qf3Gvw.js +53 -0
  129. package/dist/upgrade-Bt4Ouw1y.js +117 -0
  130. package/dist/upgrade-Cqy5orjb.js +7 -0
  131. package/package.json +10 -5
  132. package/dist/api-CZzirVMj.js +0 -151
  133. package/dist/api-output-aJNw7Syy.js +0 -20
  134. package/dist/app-DH6U8yuI.js +0 -190
  135. package/dist/asa-C-sQzPPn.js +0 -1194
  136. package/dist/asc-1ZBJ6DwS.js +0 -778
  137. package/dist/auth-YRhlV3DE.js +0 -140
  138. package/dist/billing-CCYHdApx.js +0 -80
  139. package/dist/bundle-id-CKxl_026.js +0 -121
  140. package/dist/command-CMIz81Da.js +0 -301
  141. package/dist/dev-DZy6pOnB.js +0 -22
  142. package/dist/doctor-H-hf-Yww.js +0 -88
  143. package/dist/feedback-CKf-rpBW.js +0 -152
  144. package/dist/hosted-CXe9TrWx.js +0 -32
  145. package/dist/migrate-C9ERDR6y.js +0 -284
  146. package/dist/org-sj7uyvp-.js +0 -40
  147. package/dist/output-C4o2gJ1K.js +0 -146
  148. package/dist/params-l3CrvRtR.js +0 -51
  149. package/dist/pipeline-BqzqZhX1.js +0 -977
  150. package/dist/print-skill-ZojRSybs.js +0 -74
  151. package/dist/promote-BG8X4Nv_.js +0 -88
  152. package/dist/publish-sxLh-G4G.js +0 -35
  153. package/dist/push-bQ6Vxtg8.js +0 -35
  154. package/dist/query-_FbybaH-.js +0 -53
  155. package/dist/resource-CGIwSd29.js +0 -323
  156. package/dist/revenue-provider-ebsRINY8.js +0 -100
  157. package/dist/scope-BvzD-kO4.js +0 -223
  158. package/dist/skills-D_R-lEsK.js +0 -64
  159. package/dist/spinner-TWa0hia6.js +0 -18
  160. package/dist/storekit-Cj9Cpjcz.js +0 -29
  161. package/dist/telemetry-DeA1mvnT.js +0 -169
  162. package/dist/ui-Dy0b-9L8.js +0 -27738
  163. package/dist/update-B2fWIc4q.js +0 -59
  164. package/dist/upgrade-BmzkTKrh.js +0 -72
  165. /package/dist/{devtools-8EgLo86w.js → devtools-ByZ6XYnn.js} +0 -0
@@ -0,0 +1,53 @@
1
+ //#region src/ui/index.ts
2
+ let active;
3
+ function useRenderer(renderer) {
4
+ active = renderer;
5
+ return renderer;
6
+ }
7
+ const silentRenderer = {
8
+ start: () => {},
9
+ stop: () => {},
10
+ intro: () => {},
11
+ step: () => {},
12
+ info: () => {},
13
+ success: () => {},
14
+ warn: () => {},
15
+ error: () => {},
16
+ note: () => {},
17
+ report: () => {},
18
+ list: () => {},
19
+ outro: () => {},
20
+ spinner: () => ({
21
+ start: () => {},
22
+ message: () => {},
23
+ stop: () => {}
24
+ }),
25
+ select: async () => null,
26
+ multiselect: async () => null,
27
+ confirm: async () => null,
28
+ text: async () => null
29
+ };
30
+ const current = () => active ?? silentRenderer;
31
+ const ui = {
32
+ start: () => current().start(),
33
+ stop: () => current().stop(),
34
+ intro: (t) => current().intro(t),
35
+ step: (t) => current().step(t),
36
+ info: (t) => current().info(t),
37
+ success: (t) => current().success(t),
38
+ warn: (t) => current().warn(t),
39
+ error: (t) => current().error(t),
40
+ note: (t, title) => current().note(t, title),
41
+ report: (t) => current().report(t),
42
+ list: (o) => current().list(o),
43
+ outro: (t) => current().outro(t),
44
+ spinner: () => current().spinner(),
45
+ select: (o) => current().select(o),
46
+ multiselect: (o) => current().multiselect(o),
47
+ confirm: (o) => current().confirm(o),
48
+ text: (o) => current().text(o),
49
+ onInterrupt: (listener) => current().onInterrupt?.(listener) ?? (() => {})
50
+ };
51
+
52
+ //#endregion
53
+ export { ui as n, useRenderer as r, silentRenderer as t };
@@ -0,0 +1,117 @@
1
+ import { _ as VERSION, m as RUNNING_VIA_NPX } from "./environment-DF1qKlny.js";
2
+ import { c as readUpdateCheck, g as writeUpdateCheck } from "./config-BO1Y87kV.js";
3
+ import { r as spawnStream } from "./spawn-DmmmHIP-.js";
4
+ import pc from "picocolors";
5
+
6
+ //#region src/core/support/upgrade.ts
7
+ const CHECK_INTERVAL_MS = 1440 * 60 * 1e3;
8
+ const REGISTRY_URL = "https://registry.npmjs.org/superwall/latest";
9
+ const pending = [];
10
+ function isNewerVersion(latest, current) {
11
+ const l = latest.split(".").map((n) => parseInt(n, 10));
12
+ const c = current.split(".").map((n) => parseInt(n, 10));
13
+ for (let i = 0; i < 3; i++) {
14
+ const a = l[i] ?? 0;
15
+ const b = c[i] ?? 0;
16
+ if (Number.isNaN(a) || Number.isNaN(b)) return false;
17
+ if (a !== b) return a > b;
18
+ }
19
+ return false;
20
+ }
21
+ async function selectLatestVersion() {
22
+ try {
23
+ const res = await fetch(REGISTRY_URL, {
24
+ headers: { accept: "application/json" },
25
+ signal: AbortSignal.timeout(5e3)
26
+ });
27
+ if (!res.ok) return null;
28
+ const { version } = await res.json();
29
+ return version ?? null;
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+ function selectAvailableUpdate() {
35
+ const latest = readUpdateCheck()?.latest;
36
+ if (!latest || !isNewerVersion(latest, VERSION)) return null;
37
+ return latest;
38
+ }
39
+ function refreshUpdateCheck() {
40
+ if (process.env.NODE_TEST_CONTEXT) return;
41
+ const cached = readUpdateCheck();
42
+ if ((cached?.checkedAt ? Date.now() - Date.parse(cached.checkedAt) : Infinity) < CHECK_INTERVAL_MS) return;
43
+ pending.push(selectLatestVersion().then((version) => {
44
+ if (version) writeUpdateCheck({
45
+ latest: version,
46
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString()
47
+ });
48
+ }));
49
+ }
50
+ async function flushUpdateCheck(capMs = 2e3) {
51
+ if (pending.length === 0) return;
52
+ await Promise.race([Promise.allSettled(pending), new Promise((done) => setTimeout(done, capMs).unref())]);
53
+ }
54
+ function maybeNotifyUpdate(stream) {
55
+ const latest = selectAvailableUpdate();
56
+ if (!latest) return;
57
+ stream.write(`${pc.dim(`Update available ${VERSION} → ${latest} · run \`superwall upgrade\``)}\n`);
58
+ }
59
+ async function runUpgrade(ctx) {
60
+ const { ui } = ctx;
61
+ if (RUNNING_VIA_NPX()) {
62
+ if (ctx.json) return ctx.output.data({
63
+ upgraded: false,
64
+ via: "npx"
65
+ });
66
+ ui.info("You're running via npx, which always fetches the latest published version - nothing to upgrade.");
67
+ return;
68
+ }
69
+ ui.intro("Superwall upgrade");
70
+ const spin = ui.spinner();
71
+ spin.start("Checking the latest version");
72
+ const latest = await selectLatestVersion();
73
+ if (!latest) {
74
+ spin.stop("Check failed");
75
+ throw new Error("Couldn't reach the npm registry - try again.");
76
+ }
77
+ if (!isNewerVersion(latest, VERSION)) {
78
+ spin.stop(`You're on the latest version (\`${VERSION}\`)`);
79
+ if (ctx.json) return ctx.output.data({
80
+ upgraded: false,
81
+ version: VERSION
82
+ });
83
+ return;
84
+ }
85
+ spin.message(`Upgrading \`${VERSION}\` → \`${latest}\``);
86
+ const errors = [];
87
+ const { code } = await spawnStream({
88
+ bin: "npm",
89
+ args: [
90
+ "install",
91
+ "--global",
92
+ `superwall@${latest}`
93
+ ],
94
+ cwd: process.cwd(),
95
+ onStdoutLine: () => {},
96
+ onStderrLine: (line) => errors.push(line)
97
+ });
98
+ if (code !== 0) {
99
+ spin.stop("Upgrade failed");
100
+ const detail = errors.slice(-3).join(" ").trim();
101
+ throw new Error(`npm couldn't upgrade the package${detail ? ` (${detail.slice(0, 200)})` : ""}. Try: npm install --global superwall@latest`);
102
+ }
103
+ writeUpdateCheck({
104
+ latest,
105
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString()
106
+ });
107
+ spin.stop(`Upgraded \`${VERSION}\` → \`${latest}\``);
108
+ if (ctx.json) return ctx.output.data({
109
+ upgraded: true,
110
+ from: VERSION,
111
+ to: latest
112
+ });
113
+ ui.outro("You're on the latest version.");
114
+ }
115
+
116
+ //#endregion
117
+ export { runUpgrade as a, refreshUpdateCheck as i, isNewerVersion as n, maybeNotifyUpdate as r, flushUpdateCheck as t };
@@ -0,0 +1,7 @@
1
+ import "./output-Ggzq5_-t.js";
2
+ import "./environment-DF1qKlny.js";
3
+ import "./config-BO1Y87kV.js";
4
+ import "./spawn-DmmmHIP-.js";
5
+ import { a as runUpgrade, i as refreshUpdateCheck, n as isNewerVersion, r as maybeNotifyUpdate, t as flushUpdateCheck } from "./upgrade-Bt4Ouw1y.js";
6
+
7
+ export { flushUpdateCheck, isNewerVersion, maybeNotifyUpdate, refreshUpdateCheck, runUpgrade };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superwall/cli",
3
- "version": "1.7.0",
3
+ "version": "2.0.0",
4
4
  "description": "The official CLI for managing Superwall from your terminal or coding agent.",
5
5
  "keywords": [
6
6
  "agent",
@@ -39,14 +39,19 @@
39
39
  "./auth": {
40
40
  "types": "./dist/auth.d.ts",
41
41
  "import": "./dist/auth.js"
42
+ },
43
+ "./tools": {
44
+ "types": "./dist/tools.d.ts",
45
+ "import": "./dist/tools.js"
42
46
  }
43
47
  },
44
48
  "scripts": {
45
- "build": "tsdown && tsx scripts/vendor-skills.ts",
49
+ "build": "tsdown && tsx scripts/vendor-skills.ts && bun scripts/build-tools.ts",
46
50
  "watch": "tsdown --watch",
47
51
  "regen:asc": "tsx scripts/regen-asc-index.ts",
48
52
  "skills:vendor": "tsx scripts/vendor-skills.ts",
49
- "skills:ensure": "test -f dist/skills/superwall/SKILL.md || tsx scripts/vendor-skills.ts",
53
+ "test:parity": "for area in main api-and-asc apple-search-ads; do tsx --tsconfig tsconfig.json scripts/mcp-parity.ts scripts/mcp-parity/$area.json /tmp/mcp-parity-$area.json || exit 1; done",
54
+ "skills:ensure": "test -f dist/skills/index.json || tsx scripts/vendor-skills.ts",
50
55
  "dev": "bun bin.ts",
51
56
  "test": "bun run skills:ensure && tsx --test --import ./tests/setup.ts $(rg --files tests -g '*.test.ts')",
52
57
  "link:global": "tsdown && bun link",
@@ -54,12 +59,12 @@
54
59
  "prepack": "bun run build",
55
60
  "prepublishOnly": "bun run typecheck && bun run test",
56
61
  "test:run": "tsx --test $(rg --files tests -g '*.test.ts')",
57
- "test:coverage": "bun run skills:ensure && tsx --test --import ./tests/setup.ts --experimental-test-coverage --test-coverage-lines=85 --test-coverage-branches=88 --test-coverage-functions=85 $(rg --files tests -g '*.test.ts')",
62
+ "test:coverage": "bun run skills:ensure && tsx --test --import ./tests/setup.ts --experimental-test-coverage --test-coverage-lines=98 --test-coverage-branches=94 --test-coverage-functions=96 $(rg --files tests -g '*.test.ts')",
58
63
  "clean": "rm -rf dist"
59
64
  },
60
65
  "dependencies": {
61
66
  "@anthropic-ai/claude-agent-sdk": "0.3.201",
62
- "@superwall/studio": "1.7.0",
67
+ "@superwall/studio": "2.0.0",
63
68
  "ansi-escapes": "^7.3.0",
64
69
  "fast-glob": "^3.3.3",
65
70
  "ink": "^5.2.1",
@@ -1,151 +0,0 @@
1
- import "./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 { E as titleCase, T as rowName, b as platformLabel, g as listResource, h as listProjects, m as listOrganizations } from "./resources-Bf9O1JNM.js";
8
- import { t as parseParams } from "./params-l3CrvRtR.js";
9
- import { n as emitJson, t as apiCall } from "./api-output-aJNw7Syy.js";
10
- import pc from "picocolors";
11
-
12
- //#region src/commands/platform/api.ts
13
- function runApi(verb) {
14
- return defineCommand({
15
- name: verb,
16
- auth: "required",
17
- interaction: "none",
18
- output: "both",
19
- async run(ctx) {
20
- const path = String(ctx.argv.path ?? "");
21
- if (!path.startsWith("/")) throw new Error(`Path must start with "/", e.g. /v2/products`);
22
- const params = parseParams(ctx.argv.d);
23
- return emitJson(ctx, await apiCall(ctx, `${verb.toUpperCase()} ${path}`, () => {
24
- switch (verb) {
25
- case "get": return ctx.api.get(withQuery(path, params));
26
- case "delete": return ctx.api.del(withQuery(path, params));
27
- case "post": return ctx.api.post(path, params);
28
- case "patch": return ctx.api.patch(path, params);
29
- }
30
- }) ?? { ok: true });
31
- }
32
- });
33
- }
34
- function withQuery(path, params) {
35
- const entries = Object.entries(params);
36
- if (entries.length === 0) return path;
37
- const qs = new URLSearchParams();
38
- for (const [key, value] of entries) {
39
- if (typeof value === "object" && value !== null) throw new Error(`Nested -d params aren't supported on GET/DELETE (got "${key}").`);
40
- qs.set(key, String(value));
41
- }
42
- return `${path}${path.includes("?") ? "&" : "?"}${qs}`;
43
- }
44
- const runBootstrap = defineCommand({
45
- name: "bootstrap",
46
- auth: "required",
47
- interaction: "none",
48
- output: "both",
49
- async run(ctx) {
50
- const tree = await apiCall(ctx, "Loading your account", () => buildAccountTree(ctx.api));
51
- if (ctx.json) return emitJson(ctx, tree);
52
- const who = [ctx.api.userEmail, ctx.api.org.name].filter(Boolean).join(" · ");
53
- if (who) ctx.ui.step(who);
54
- const text = tree.organizations.flatMap((org) => renderTree([orgNode(org)])).join("\n");
55
- ctx.output.text(text);
56
- }
57
- });
58
- async function buildAccountTree(api) {
59
- const orgs = await listOrganizations(api);
60
- const orgList = orgs.length > 0 ? orgs : [{
61
- id: api.org.id,
62
- name: api.org.name
63
- }];
64
- for (const org of orgList) if (!org.name && String(org.id ?? "") === api.org.id) org.name = api.org.name;
65
- return { organizations: await Promise.all(orgList.map(async (org) => {
66
- const projects = String(org.id ?? "") === api.org.id ? await listProjects(api) : await api.list(`/v2/projects?organization_id=${org.id}`);
67
- const full = await Promise.all(projects.map(async (p) => {
68
- const scope = { projectId: String(p.id) };
69
- const [products, entitlements, apps] = await Promise.all([
70
- listResource(api, "products", scope),
71
- listResource(api, "entitlements", scope),
72
- Promise.all((p.applications ?? []).map(async (a) => {
73
- const appScope = {
74
- ...scope,
75
- applicationId: String(a.id)
76
- };
77
- const [campaigns, paywalls] = await Promise.all([listResource(api, "campaigns", appScope), listResource(api, "paywalls", appScope)]);
78
- return {
79
- ...a,
80
- campaigns,
81
- paywalls
82
- };
83
- }))
84
- ]);
85
- return {
86
- ...p,
87
- products,
88
- entitlements,
89
- applications_full: apps
90
- };
91
- }));
92
- return {
93
- ...org,
94
- projects: full
95
- };
96
- })) };
97
- }
98
- function renderTree(nodes, prefix = "") {
99
- return nodes.flatMap((node, i) => {
100
- const last = i === nodes.length - 1;
101
- const line = `${prefix}${last ? "└── " : "├── "}${node.label}`;
102
- const childPrefix = `${prefix}${last ? " " : "│ "}`;
103
- return [line, ...renderTree(node.children ?? [], childPrefix)];
104
- });
105
- }
106
- const id = (row) => pc.dim(`#${row.id}`);
107
- const group = (name, rows, child) => ({
108
- label: rows.length ? `${name} ${pc.dim(`(${rows.length})`)}` : pc.dim(`${name} (0)`),
109
- children: rows.map(child)
110
- });
111
- function orgNode(org) {
112
- return {
113
- label: `${pc.bold(rowName(org))} ${id(org)}${org.role ? pc.dim(` · ${titleCase(String(org.role))}`) : ""}`,
114
- children: org.projects.map(projectNode)
115
- };
116
- }
117
- function projectNode(p) {
118
- const claimed = /* @__PURE__ */ new Set();
119
- const apps = p.applications_full.map((a) => {
120
- const products = p.products.filter((r) => String(r.platform ?? "") === String(a.platform ?? ""));
121
- for (const r of products) claimed.add(r.id);
122
- return appNode(a, products, p.entitlements);
123
- });
124
- const leftover = p.products.filter((r) => !claimed.has(r.id));
125
- return {
126
- label: `${pc.bold(p.name ?? String(p.id))} ${id(p)}`,
127
- children: [...apps, ...leftover.length ? [group("products (no app)", leftover, (r) => ({ label: `${rowName(r)} ${id(r)}` }))] : []]
128
- };
129
- }
130
- function appNode(a, products, entitlements) {
131
- const key = a.public_api_key ? pc.dim(`pk_…${a.public_api_key.slice(-4)}`) : id(a);
132
- return {
133
- label: `${platformLabel(a.platform)} · ${a.bundle_id ?? a.name ?? a.id} ${key}`,
134
- children: [
135
- group("campaigns", a.campaigns, campaignNode),
136
- group("paywalls", a.paywalls, (r) => ({ label: `${rowName(r)} ${id(r)}` })),
137
- group("products", products, (r) => ({ label: `${rowName(r)} ${id(r)}` })),
138
- group("entitlements", entitlements, (r) => ({ label: `${rowName(r)} ${id(r)}` }))
139
- ]
140
- };
141
- }
142
- function campaignNode(c) {
143
- const placements = c.placements ?? [];
144
- return {
145
- label: `${String(c.description ?? rowName(c))} ${id(c)}`,
146
- children: placements.map((p) => ({ label: `${String(p.event_name ?? p.id)}${p.enabled === false ? pc.dim(" · disabled") : ""}` }))
147
- };
148
- }
149
-
150
- //#endregion
151
- export { runApi, runBootstrap };
@@ -1,20 +0,0 @@
1
- //#region src/commands/api-output.ts
2
- function emitJson(ctx, data) {
3
- ctx.output.data(data);
4
- }
5
- async function apiCall(ctx, label, work) {
6
- if (ctx.outputMode !== "rich") return work();
7
- const spin = ctx.ui.spinner();
8
- spin.start(label);
9
- try {
10
- const result = await work();
11
- spin.stop(label);
12
- return result;
13
- } catch (e) {
14
- spin.stop("Failed");
15
- throw e;
16
- }
17
- }
18
-
19
- //#endregion
20
- export { emitJson as n, apiCall as t };
@@ -1,190 +0,0 @@
1
- import { i as loadSession, r as clearSession } from "./token-C0it-Xh7.js";
2
- import { a as superwallApi } from "./command-CMIz81Da.js";
3
- import { n as ui } from "./ui-Dy0b-9L8.js";
4
- import { a as onboardingHooks, n as performLogin, r as BROWSER_UNAVAILABLE } from "./login-Do4wFuLv.js";
5
- import { i as SUPPORTED_LABEL, t as scanProject } from "./scan-zKsddO72.js";
6
- import { r as getHostedStatus } from "./hosted-CXe9TrWx.js";
7
- import { t as withSpinner } from "./spinner-TWa0hia6.js";
8
- import { n as resolveAppBinding, r as resolveScopeFromKey, t as platformForIntegration } from "./bind-YrJvuRF9.js";
9
- import { t as ACTIONS } from "./actions-B7ym3oVS.js";
10
-
11
- //#region src/commands/workflow/integrate/app.ts
12
- async function performLoginWithUi(app, onProvisioned) {
13
- const spin = ui.spinner();
14
- const hooks = onboardingHooks(app);
15
- try {
16
- const session = await performLogin({
17
- onVerify: ({ url, userCode, browserOpened }) => {
18
- ui.info(`Approve this login in your browser · code \`${userCode}\`\n${url}`);
19
- if (!browserOpened) ui.warn(BROWSER_UNAVAILABLE);
20
- spin.start("Waiting for you to approve in the browser");
21
- },
22
- onStatus: (message) => spin.message(message),
23
- onOnboard: async () => {
24
- const setup = await hooks.onOnboard();
25
- if (setup) spin.start("Creating your account");
26
- return setup;
27
- },
28
- onProvisioned: (result) => {
29
- hooks.onProvisioned(result);
30
- onProvisioned?.(result);
31
- }
32
- });
33
- spin.stop(`Logged in as \`${session.userEmail ?? "you"}\``);
34
- return session;
35
- } catch (error) {
36
- spin.stop("Login failed");
37
- ui.warn(error.message);
38
- return null;
39
- }
40
- }
41
- /**
42
- * The project has an API key that matches nothing in the logged-in org - most
43
- * likely the wrong account. Offer to re-login, rebind, or skip; returns the
44
- * resolved scope when a fix works.
45
- */
46
- async function recoverUnmatchedScope(app, apiKey) {
47
- for (;;) {
48
- const orgName = loadSession()?.orgName;
49
- const orgLabel = orgName ? `\`${orgName}\`` : "your organization";
50
- ui.error(`This project's API key (\`${apiKey}\`) doesn't match any app in ${orgLabel}. You might be logged in to the wrong account.`);
51
- const choice = await ui.select({
52
- message: "How do you want to fix it?",
53
- options: [
54
- {
55
- value: "relogin",
56
- label: "Log in with a different account"
57
- },
58
- {
59
- value: "bind",
60
- label: `Connect this app to ${orgLabel} instead`,
61
- hint: "creates or picks an app and issues a new API key"
62
- },
63
- {
64
- value: "skip",
65
- label: "Skip for now"
66
- }
67
- ]
68
- });
69
- if (choice === null || choice === "skip") return null;
70
- if (choice === "relogin") {
71
- clearSession();
72
- if (!await performLoginWithUi(app)) return null;
73
- const resolved = await withSpinner("Finding this app in Superwall", () => resolveScopeFromKey(superwallApi(), apiKey).catch(() => null));
74
- if (resolved) {
75
- ui.success(`Found \`${resolved.appName ?? app.name}\``);
76
- return {
77
- scope: {
78
- projectId: resolved.projectId,
79
- applicationId: resolved.applicationId,
80
- appName: resolved.appName ?? app.name
81
- },
82
- bundleId: resolved.bundleId
83
- };
84
- }
85
- continue;
86
- }
87
- try {
88
- const bound = await resolveAppBinding(superwallApi(), {
89
- platform: platformForIntegration(app.integration),
90
- appName: app.name
91
- });
92
- if (!bound) continue;
93
- ui.note(`Your code still uses \`${apiKey}\`.\nReplace it with \`${bound.apiKey}\` so the app talks to ${orgLabel}.`, "Swap the API key");
94
- return {
95
- scope: {
96
- projectId: bound.projectId,
97
- applicationId: bound.applicationId,
98
- appName: app.name
99
- },
100
- bundleId: bound.app.bundle_id
101
- };
102
- } catch (error) {
103
- ui.warn(error.message);
104
- }
105
- }
106
- }
107
- async function ensureAgentDriverReady(driver, ensureLogin, dryRun) {
108
- if (driver.id !== "superwall" || dryRun) return true;
109
- if (!await ensureLogin()) {
110
- ui.warn("Superwall Agent needs sign-in. Run `superwall login`, or install Claude Code/Codex and re-run.");
111
- return false;
112
- }
113
- const status = await withSpinner("Checking Superwall Agent credit", () => getHostedStatus());
114
- if (!status) {
115
- ui.warn("Superwall Agent needs an OAuth login. Run `superwall login` (not `--api-key`), or install Claude Code/Codex.");
116
- return false;
117
- }
118
- if (status.exhausted) {
119
- ui.warn("Your hosted Superwall Agent credit is exhausted. Install Claude Code/Codex or copy the prompt into your own agent.");
120
- return false;
121
- }
122
- return true;
123
- }
124
- async function pickApp(installDir, interactive) {
125
- const scan = await withSpinner("Scanning your project", () => scanProject(installDir));
126
- if (scan.apps.length === 0) {
127
- if (scan.unsupported.length) {
128
- const webApp = scan.unsupported[0];
129
- throw new Error(`Detected a web app${webApp.details ? ` (\`${webApp.details}\`)` : ""}. This command supports mobile apps.`);
130
- }
131
- const skipped = scan.skipped.length ? ` Skipped: ${scan.skipped.join(", ")}.` : "";
132
- throw new Error(`No ${SUPPORTED_LABEL} app found in this directory.${skipped}`);
133
- }
134
- if (scan.unsupported.length) ui.info(`Also found unsupported web apps: ${scan.unsupported.map((app) => app.name).join(", ")}`);
135
- if (scan.apps.length === 1) {
136
- const app = scan.apps[0];
137
- ui.info(`Detected \`${app.framework.name}\`` + (app.details ? ` · \`${app.details}\`` : "") + (app.relPath !== "." ? ` (${app.relPath})` : ""));
138
- return app;
139
- }
140
- if (!interactive) throw new Error("Multiple apps found. Pass --install-dir for the app you want to change.");
141
- const choice = await ui.select({
142
- message: scan.isMonorepo ? "Found multiple apps - which one?" : "Which app?",
143
- options: scan.apps.map((app) => ({
144
- value: app.path,
145
- label: `${app.name} · ${app.framework.name}`,
146
- hint: app.relPath === "." ? void 0 : app.relPath
147
- })),
148
- initialValue: scan.apps[0].path
149
- });
150
- if (choice === null) return null;
151
- return scan.apps.find((app) => app.path === choice) ?? scan.apps[0];
152
- }
153
- async function chooseAction(forced, existing, app, interactive) {
154
- if (forced) return forced;
155
- if (!interactive) return "integrate";
156
- if (!existing.sdkInstalled) {
157
- const confirmed = await ui.confirm({ message: `Integrate Superwall into \`${app.name}\`?` });
158
- if (confirmed === null) {
159
- ui.warn("Cancelled.");
160
- return null;
161
- }
162
- if (!confirmed) {
163
- ui.outro("No problem - run `superwall integrate` again anytime.");
164
- return null;
165
- }
166
- return "integrate";
167
- }
168
- const available = ACTIONS.filter((action) => {
169
- if (action.id === "integrate") return false;
170
- if (action.requiresOrgKey && !process.env.SUPERWALL_API_KEY) return false;
171
- return true;
172
- });
173
- return await ui.select({
174
- message: "What do you want to do?",
175
- options: available.map((action) => ({
176
- value: action.id,
177
- label: action.title,
178
- hint: action.hint
179
- })),
180
- initialValue: "review"
181
- });
182
- }
183
- async function stage(label, work) {
184
- ui.step(label);
185
- await new Promise((resolve) => setTimeout(resolve, 40));
186
- await work();
187
- }
188
-
189
- //#endregion
190
- export { recoverUnmatchedScope as a, pickApp as i, ensureAgentDriverReady as n, stage as o, performLoginWithUi as r, chooseAction as t };