@superwall/cli 1.6.2 → 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 (162) hide show
  1. package/README.md +281 -34
  2. package/dist/apple-CkKlHBZ9.js +195 -0
  3. package/dist/auth.d.ts +4 -19
  4. package/dist/auth.js +4 -2
  5. package/dist/{actions-H7f6knyY.js → billing-XCZU_T46.js} +98 -28
  6. package/dist/{bind-BIzaGq8K.js → bind-drne__Ys.js} +38 -33
  7. package/dist/{build-B7BS1rF2.js → build-Gpdq5QXP.js} +20 -26
  8. package/dist/client-BZ1UbpXz.js +66 -0
  9. package/dist/client-DP6Rc0t_.js +176 -0
  10. package/dist/config-BO1Y87kV.js +105 -0
  11. package/dist/create-BBrtgUgS.js +969 -0
  12. package/dist/{create-CwnnNqv4.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-6RMOPIdn.js → drivers-DNrx4LWA.js} +185 -172
  16. package/dist/entry.d.ts +0 -5
  17. package/dist/entry.js +28083 -801
  18. package/dist/environment-DF1qKlny.js +58 -0
  19. package/dist/{existing-DHpPn1y6.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-BR2LR-EK.js → integrate-DcJhpXy8.js} +277 -253
  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-Bhxgqwtm.js → login-D0lh3_JI.js} +144 -66
  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-BnVD6tJ9.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-Dvcyef3_.js → products-DH_fK9tY.js} +6 -39
  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-DqMs9xNR.js → reports-DdPq4blM.js} +7 -6
  43. package/dist/{resources-Bf9O1JNM.js → resources-Dqr01Dep.js} +150 -55
  44. package/dist/{run-D-NbZLpj.js → run-C9qg_QlC.js} +16 -22
  45. package/dist/scan-Cv5uOwVY.js +4 -0
  46. package/dist/{scan-BmAW413l.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-BGi6GyxC.js → selection-Rdw-ZUoG.js} +94 -51
  50. package/dist/send-BxD9yf6F.js +150 -0
  51. package/dist/{dev-CgGAb5Al.js → server-D0tGG8C4.js} +82 -87
  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-AxAf7bDB.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-BGAVPSQc.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-Dv3LyZ5m.js +0 -151
  133. package/dist/api-output-aJNw7Syy.js +0 -20
  134. package/dist/app-mJC5NDtW.js +0 -189
  135. package/dist/asa-D6H7Pjae.js +0 -1194
  136. package/dist/asc-xCin0akG.js +0 -539
  137. package/dist/auth-ZlLL-Gko.js +0 -139
  138. package/dist/billing-C8kBge_S.js +0 -80
  139. package/dist/command-3fGYyC8r.js +0 -301
  140. package/dist/dev-Dx99K183.js +0 -22
  141. package/dist/doctor-CyUvut31.js +0 -88
  142. package/dist/feedback-RKyGuQ8_.js +0 -152
  143. package/dist/hosted-BeGVAntr.js +0 -32
  144. package/dist/migrate-C-4ISELN.js +0 -284
  145. package/dist/org-CQduIOic.js +0 -40
  146. package/dist/output-C-4UKMot.js +0 -136
  147. package/dist/params-l3CrvRtR.js +0 -51
  148. package/dist/pipeline-CHX0Syre.js +0 -977
  149. package/dist/print-skill-BiZLdCKv.js +0 -74
  150. package/dist/promote-Pgpz-3xl.js +0 -88
  151. package/dist/publish-BPeuc3lq.js +0 -35
  152. package/dist/push-DcSQ4odB.js +0 -35
  153. package/dist/query-CWLaZkdm.js +0 -53
  154. package/dist/resource-jwASPCrw.js +0 -483
  155. package/dist/skills-FK5aDuNV.js +0 -64
  156. package/dist/spinner-DFctF_Jw.js +0 -18
  157. package/dist/storekit-CC4gnTI6.js +0 -29
  158. package/dist/telemetry-Ch9cCTI-.js +0 -169
  159. package/dist/ui-4gLyfrgl.js +0 -27737
  160. package/dist/update-DIXbL-H9.js +0 -59
  161. package/dist/upgrade-De7JMI1g.js +0 -72
  162. /package/dist/{devtools-8EgLo86w.js → devtools-ByZ6XYnn.js} +0 -0
@@ -1,36 +1,42 @@
1
- import { b as apiKeyFromEnv, f as DASHBOARD_URL, r as formatJson, t as blocks, y as VERSION } from "./output-C-4UKMot.js";
2
- import { r as setTelemetryTags, s as getOnboardedApp } from "./telemetry-Ch9cCTI-.js";
3
- import "./update-DIXbL-H9.js";
4
- import { i as loadSession } from "./token-BGAVPSQc.js";
5
- import { a as superwallApi, t as defineCommand } from "./command-3fGYyC8r.js";
6
- import { i as stripReport, n as ui } from "./ui-4gLyfrgl.js";
7
- import { n as ensureSkillsCurrent } from "./skills-AxAf7bDB.js";
8
- import "./spawn-DSoTXy_j.js";
9
- import "./login-Bhxgqwtm.js";
10
- import { i as SUPPORTED_LABEL, t as scanProject } from "./scan-BmAW413l.js";
11
- import { t as detectDrivers } from "./drivers-6RMOPIdn.js";
12
- import "./hosted-BeGVAntr.js";
13
- import { t as detectExisting } from "./existing-DHpPn1y6.js";
14
- import { t as withSpinner } from "./spinner-DFctF_Jw.js";
15
- import { T as rowName, b as platformLabel, g as listResource, o as createProduct, p as listApplications } from "./resources-Bf9O1JNM.js";
16
- import "./org-CQduIOic.js";
17
- import { n as resolveAppBinding, r as resolveScopeFromKey, t as platformForIntegration } from "./bind-BIzaGq8K.js";
18
- import { r as actionById } from "./actions-H7f6knyY.js";
19
- import { a as recoverUnmatchedScope, i as pickApp, n as ensureAgentDriverReady, o as stage, r as performLoginWithUi, t as chooseAction } from "./app-mJC5NDtW.js";
20
- import { a as copyToClipboard, r as buildCopyPrompt, t as runAction } from "./run-D-NbZLpj.js";
21
- import { c as listAscConfigs, i as listAscApps, n as fetchUnimportedAscProducts, o as createAscConfig, r as findAscAppId, t as ascTypeDisplay } from "./asc-products-Dvcyef3_.js";
22
- import { t as generateStoreKit } from "./storekit-CC4gnTI6.js";
23
- import { n as saveReport, t as loadReport } from "./reports-DqMs9xNR.js";
24
- import { t as detectBilling } from "./billing-C8kBge_S.js";
25
- import { basename, join } from "node:path";
26
- import { homedir } from "node:os";
1
+ import "./token-DzRh7dI1.js";
2
+ import { r as formatJson, t as blocks } from "./output-Ggzq5_-t.js";
3
+ import { _ as VERSION, c as DASHBOARD_URL } from "./environment-DF1qKlny.js";
4
+ import { a as sessionOrgName, n as removeSession, t as readSession } from "./storage-s2Dnz-yl.js";
5
+ import { i as superwallApi } from "./client-DP6Rc0t_.js";
6
+ import { r as readOnboardedApp } from "./config-BO1Y87kV.js";
7
+ import { i as updateTelemetryTags } from "./telemetry-DtG92m5O.js";
8
+ import "./spawn-DmmmHIP-.js";
9
+ import { n as withSpinner } from "./spinner-CneRK5rk.js";
10
+ import { n as ui } from "./ui-D_qf3Gvw.js";
11
+ import "./theme-DUsCh-Vd.js";
12
+ import { t as stripReport } from "./log-NVhVe_oe.js";
13
+ import { n as SUPPORTED_LABEL, t as scanProject } from "./scan-DLrsrFS9.js";
14
+ import { t as detectExisting } from "./existing-78LWSsqS.js";
15
+ import { r as expandHome } from "./paths-DxSLdpOI.js";
16
+ import { D as listField, S as rowName, T as field, f as listApplications, m as listResource, o as createProduct, v as platformLabel } from "./resources-Dqr01Dep.js";
17
+ import "./org-D0g_q3mv.js";
18
+ import "./lookup-D-nmmAbw.js";
19
+ import "./scope-V336uz8j.js";
20
+ import { a as listAscConfigs, r as createAscConfig } from "./client-BZ1UbpXz.js";
21
+ import { i as listUnimportedAscProducts, n as findAscAppId, r as listAscApps, t as ascTypeDisplay } from "./products-DH_fK9tY.js";
22
+ import "./input-vi0bou04.js";
23
+ import { n as resolveAppBinding, r as resolveScopeFromKey, t as platformForIntegration } from "./bind-drne__Ys.js";
24
+ import "./login-D0lh3_JI.js";
25
+ import { s as ensureSkillsCurrent } from "./skills-BvFOa4y6.js";
26
+ import { t as generateStoreKit } from "./storekit-yY_kS2iR.js";
27
+ import { n as performLoginWithUi, t as createLoginGate } from "./login-B2TsCE2H.js";
28
+ import { a as copyToClipboard, r as buildCopyPrompt, t as runAction } from "./run-C9qg_QlC.js";
29
+ import { n as selectHostedStatus, t as detectDrivers } from "./drivers-DNrx4LWA.js";
30
+ import { r as actionById, t as detectBilling } from "./billing-XCZU_T46.js";
31
+ import { n as writeReport, t as readReport } from "./reports-DdPq4blM.js";
27
32
  import { readFileSync, writeFileSync } from "node:fs";
33
+ import { basename } from "node:path";
28
34
  import fg from "fast-glob";
29
35
 
30
36
  //#region src/core/account/index.ts
31
37
  async function resolveAccount(opts) {
32
38
  const projectKey = opts.existing.apiKey;
33
- const flagKey = opts.argv.apiKey ?? apiKeyFromEnv();
39
+ const flagKey = opts.apiKey;
34
40
  if (projectKey) {
35
41
  if (!opts.interactive || flagKey === projectKey) return { apiKey: projectKey };
36
42
  const use = await opts.ui.confirm({ message: `This project already has a Superwall key (${projectKey}). Use this app?` });
@@ -38,50 +44,57 @@ async function resolveAccount(opts) {
38
44
  if (use) return { apiKey: projectKey };
39
45
  }
40
46
  if (flagKey) return { apiKey: flagKey };
41
- throw new Error(opts.interactive ? "Couldn't connect your app - re-run and complete the browser login." : "No public API key found. Pass --api-key or set SUPERWALL_API_KEY.");
47
+ throw new Error(opts.interactive ? "Couldn't connect your app - re-run and complete the browser login." : "No public API key found. Pass --api-key.");
42
48
  }
43
49
 
44
50
  //#endregion
45
- //#region src/core/api/discover.ts
46
- async function discoverPublicApiKey(api, opts = {}) {
47
- const apps = (await listApplications(api)).filter((a) => a.public_api_key);
48
- if (apps.length === 0) return null;
49
- if (opts.bundleId) {
50
- const match = apps.find((a) => a.bundle_id === opts.bundleId);
51
- if (match?.public_api_key) return {
52
- apiKey: match.public_api_key,
53
- app: match
54
- };
55
- }
56
- if (apps.length === 1) {
57
- const only = apps[0];
58
- return {
59
- apiKey: only.public_api_key,
60
- app: only
61
- };
62
- }
63
- if (opts.onMany) {
64
- const picked = await opts.onMany(apps);
65
- if (picked?.public_api_key) return {
66
- apiKey: picked.public_api_key,
67
- app: picked
68
- };
51
+ //#region src/core/workflows/agent/fallback.ts
52
+ async function runFallback(installDir) {
53
+ const scan = await scanProject(installDir);
54
+ const top = scan.apps[0];
55
+ if (!top) {
56
+ if (scan.unsupported.length) throw new Error("Detected a web app. This command supports mobile apps.");
57
+ throw new Error(`No ${SUPPORTED_LABEL} app found here.`);
69
58
  }
70
- return null;
59
+ ui.info(`Detected ${top.framework.name}${top.details ? ` · ${top.details}` : ""}`);
60
+ ui.note([
61
+ `1. Install the SDK: ${top.framework.sdkPackage}`,
62
+ `2. Configure Superwall with your public API key at app launch.`,
63
+ `3. Register one placement: register("campaign_trigger").`,
64
+ ``,
65
+ `Full guide: ${top.framework.docsUrl}`
66
+ ].join("\n"), "Manual setup");
67
+ ui.note([
68
+ "For automated setup, install an agent and run `superwall integrate` again:",
69
+ "Claude Code: npm install --global @anthropic-ai/claude-code",
70
+ "Codex: npm install --global @openai/codex"
71
+ ].join("\n"), "Automated setup");
72
+ ui.outro("Re-run `superwall integrate` after installing an agent.");
73
+ }
74
+
75
+ //#endregion
76
+ //#region src/core/api/discover.ts
77
+ async function discoverPublicApiKey(api) {
78
+ const [only, ...rest] = (await listApplications(api)).flatMap((app) => app.public_api_key ? [{
79
+ apiKey: app.public_api_key,
80
+ app
81
+ }] : []);
82
+ return only && rest.length === 0 ? only : null;
71
83
  }
72
84
 
73
85
  //#endregion
74
- //#region src/core/dashboard/stages.ts
86
+ //#region src/core/workflows/dashboard-setup.ts
75
87
  const SKIP = "__skip__";
76
- function count(n, noun) {
88
+ function formatCount(n, noun) {
77
89
  return `${n} ${noun}${n === 1 ? "" : "s"}`;
78
90
  }
79
91
  async function runProductsStage(ctx) {
80
92
  const { api, scope } = ctx;
81
93
  const [products, ascConfigs] = await withSpinner("Checking products", async () => [await listResource(api, "products", scope), await listAscConfigs(api).catch(() => [])]);
82
94
  const teamId = ascConfigs[0] ? String(ascConfigs[0].team_id ?? ascConfigs[0].id ?? "") : void 0;
83
- const storeKitFiles = await findStoreKitFiles(ctx.projectDir);
84
- if (products.length > 0) ui.success(`${count(products.length, "product")} already in Superwall.`);
95
+ const storeKitFiles = await listStoreKitFiles(ctx.projectDir);
96
+ const [firstStoreKit] = storeKitFiles;
97
+ if (products.length > 0) ui.success(`${formatCount(products.length, "product")} already in Superwall.`);
85
98
  else ui.info("No products in Superwall yet.");
86
99
  for (;;) {
87
100
  const how = await ui.select({
@@ -95,7 +108,7 @@ async function runProductsStage(ctx) {
95
108
  {
96
109
  value: "storekit",
97
110
  label: "Import from a StoreKit file",
98
- hint: storeKitFiles.length ? basename(storeKitFiles[0]) : "No StoreKit file found",
111
+ hint: firstStoreKit ? basename(firstStoreKit) : "No StoreKit file found",
99
112
  disabled: storeKitFiles.length === 0
100
113
  },
101
114
  ...products.length > 0 ? [{
@@ -130,29 +143,27 @@ async function ascFlow(ctx, products, teamId) {
130
143
  }
131
144
  return importFromAsc(ctx, team, products);
132
145
  }
133
- async function findStoreKitFiles(dir) {
146
+ async function listStoreKitFiles(dir) {
134
147
  if (!dir) return [];
135
- try {
136
- return await fg("**/*.storekit", {
137
- cwd: dir,
138
- absolute: true,
139
- deep: 6,
140
- suppressErrors: true,
141
- ignore: [
142
- "**/node_modules/**",
143
- "**/Pods/**",
144
- "**/build/**",
145
- "**/DerivedData/**",
146
- "**/.git/**"
147
- ]
148
- });
149
- } catch {
150
- return [];
151
- }
148
+ return fg("**/*.storekit", {
149
+ cwd: dir,
150
+ absolute: true,
151
+ deep: 6,
152
+ suppressErrors: true,
153
+ ignore: [
154
+ "**/node_modules/**",
155
+ "**/Pods/**",
156
+ "**/build/**",
157
+ "**/DerivedData/**",
158
+ "**/.git/**"
159
+ ]
160
+ });
152
161
  }
153
162
  async function importFromStoreKit(ctx, existingProducts, files) {
154
163
  const { api, scope } = ctx;
155
- let path = files[0];
164
+ const [first] = files;
165
+ if (!first) return "done";
166
+ let path = first;
156
167
  if (files.length > 1) {
157
168
  const sel = await ui.select({
158
169
  message: "Which StoreKit file?",
@@ -169,7 +180,7 @@ async function importFromStoreKit(ctx, existingProducts, files) {
169
180
  }
170
181
  let ids;
171
182
  try {
172
- ids = storeKitProductIds(JSON.parse(readFileSync(path, "utf8")));
183
+ ids = parseStoreKitProductIds(JSON.parse(readFileSync(path, "utf8")));
173
184
  } catch {
174
185
  ui.error(`Couldn't read \`${basename(path)}\` as a StoreKit file.`);
175
186
  return "done";
@@ -185,7 +196,7 @@ async function importFromStoreKit(ctx, existingProducts, files) {
185
196
  return "done";
186
197
  }
187
198
  const picked = await ui.multiselect({
188
- message: `${count(toImport.length, "product")} in the StoreKit file`,
199
+ message: `${formatCount(toImport.length, "product")} in the StoreKit file`,
189
200
  options: toImport.map((id) => ({
190
201
  value: id,
191
202
  label: id
@@ -198,27 +209,24 @@ async function importFromStoreKit(ctx, existingProducts, files) {
198
209
  await withSpinner(`Importing ${id}`, () => createProduct(api, scope, id));
199
210
  imported++;
200
211
  }
201
- ui.success(`Imported ${count(imported, "product")} from the StoreKit file.`);
212
+ ui.success(`Imported ${formatCount(imported, "product")} from the StoreKit file.`);
202
213
  return "done";
203
214
  }
204
- function storeKitProductIds(json) {
215
+ function parseStoreKitProductIds(json) {
205
216
  const ids = /* @__PURE__ */ new Set();
206
- const add = (arr) => {
207
- if (Array.isArray(arr)) {
208
- for (const p of arr) if (p?.productID) ids.add(String(p.productID));
217
+ const add = (items) => {
218
+ for (const item of items) {
219
+ const id = field(item, "productID");
220
+ if (id) ids.add(String(id));
209
221
  }
210
222
  };
211
- const j = json ?? {};
212
- add(j.products);
213
- add(j.nonRenewingSubscriptions);
214
- for (const g of j.subscriptionGroups ?? []) add(g?.subscriptions);
223
+ add(listField(json, "products"));
224
+ add(listField(json, "nonRenewingSubscriptions"));
225
+ for (const group of listField(json, "subscriptionGroups")) add(listField(group, "subscriptions"));
215
226
  return [...ids];
216
227
  }
217
228
  function existingIdSet(products) {
218
- return new Set(products.map((p) => {
219
- const r = p;
220
- return String(r.identifier ?? r.product_identifier ?? rowName(p));
221
- }));
229
+ return new Set(products.map((p) => String(p.identifier ?? p.product_identifier ?? rowName(p))));
222
230
  }
223
231
  async function connectAppStoreConnect(ctx) {
224
232
  const { api } = ctx;
@@ -291,7 +299,8 @@ function keyIdFromFilename(path) {
291
299
  }
292
300
  async function importFromAsc(ctx, teamId, existingProducts) {
293
301
  const { api, scope, bundleId } = ctx;
294
- let ascAppId = bundleId ? await withSpinner("Finding your app in App Store Connect", () => findAscAppId(api, teamId, bundleId)) : void 0;
302
+ let ascAppId;
303
+ if (bundleId) ascAppId = await withSpinner("Finding your app in App Store Connect", () => findAscAppId(api, teamId, bundleId));
295
304
  if (!ascAppId) {
296
305
  const apps = await withSpinner("Loading App Store Connect apps", () => listAscApps(api, teamId));
297
306
  if (apps.length === 0) {
@@ -311,13 +320,13 @@ async function importFromAsc(ctx, teamId, existingProducts) {
311
320
  if (sel === null) return "back";
312
321
  ascAppId = sel;
313
322
  }
314
- const unimported = await withSpinner("Loading products from App Store Connect", () => fetchUnimportedAscProducts(api, teamId, ascAppId, existingIdSet(existingProducts)));
323
+ const unimported = await withSpinner("Loading products from App Store Connect", () => listUnimportedAscProducts(api, teamId, ascAppId, existingIdSet(existingProducts)));
315
324
  if (unimported.length === 0) {
316
325
  ui.success("All App Store Connect products are already imported.");
317
326
  return "done";
318
327
  }
319
328
  const picked = await ui.multiselect({
320
- message: `${count(unimported.length, "product")} to import from App Store Connect`,
329
+ message: `${formatCount(unimported.length, "product")} to import from App Store Connect`,
321
330
  options: unimported.map((p) => ({
322
331
  value: p.productId,
323
332
  label: p.productId,
@@ -333,15 +342,12 @@ async function importFromAsc(ctx, teamId, existingProducts) {
333
342
  await withSpinner(`Importing ${id}`, () => createProduct(api, scope, id, { name: p?.referenceName || void 0 }));
334
343
  imported++;
335
344
  }
336
- ui.success(`Imported ${count(imported, "product")} from App Store Connect.`);
345
+ ui.success(`Imported ${formatCount(imported, "product")} from App Store Connect.`);
337
346
  return "done";
338
347
  }
339
348
  function required(v) {
340
349
  return v?.trim() ? void 0 : "Required";
341
350
  }
342
- function expandHome(p) {
343
- return p.startsWith("~") ? join(homedir(), p.slice(1)) : p;
344
- }
345
351
  function cleanPath(input) {
346
352
  let s = input.trim();
347
353
  if (s.length >= 2 && (s[0] === "'" && s.endsWith("'") || s[0] === "\"" && s.endsWith("\""))) s = s.slice(1, -1);
@@ -362,8 +368,8 @@ function runPaywallStage() {
362
368
  async function runVerifyStage(ctx) {
363
369
  const { api, scope } = ctx;
364
370
  const [products, campaigns] = await withSpinner("Verifying setup", async () => [await listResource(api, "products", scope), await listResource(api, "campaigns", scope)]);
365
- line(products.length > 0, `Products in Superwall: ${products.length}`);
366
- line(campaigns.length > 0, `Campaigns: ${campaigns.length}`);
371
+ renderCheck(products.length > 0, `Products in Superwall: ${products.length}`);
372
+ renderCheck(campaigns.length > 0, `Campaigns: ${campaigns.length}`);
367
373
  ui.note([
368
374
  "To verify end to end:",
369
375
  "1. Run the app on a device/simulator.",
@@ -371,43 +377,18 @@ async function runVerifyStage(ctx) {
371
377
  "3. Confirm the paywall presents and a test purchase completes."
372
378
  ].join("\n"), "Next");
373
379
  }
374
- function line(ok, text) {
380
+ function renderCheck(ok, text) {
375
381
  if (ok) ui.success(text);
376
382
  else ui.warn(text);
377
383
  }
378
384
  function writeStoreKit(products) {
379
385
  const out = "Superwall.storekit";
380
386
  writeFileSync(out, `${formatJson(generateStoreKit(products))}\n`);
381
- ui.success(`Wrote \`${out}\` with ${count(products.length, "product")}.`);
387
+ ui.success(`Wrote \`${out}\` with ${formatCount(products.length, "product")}.`);
382
388
  }
383
389
 
384
390
  //#endregion
385
- //#region src/core/agent/fallback.ts
386
- async function runFallback(installDir) {
387
- const scan = await scanProject(installDir);
388
- const top = scan.apps[0];
389
- if (!top) {
390
- if (scan.unsupported.length) throw new Error("Detected a web app. This command supports mobile apps.");
391
- throw new Error(`No ${SUPPORTED_LABEL} app found here.`);
392
- }
393
- ui.info(`Detected ${top.framework.name}${top.details ? ` · ${top.details}` : ""}`);
394
- ui.note([
395
- `1. Install the SDK: ${top.framework.sdkPackage}`,
396
- `2. Configure Superwall with your public API key at app launch.`,
397
- `3. Register one placement: register("campaign_trigger").`,
398
- ``,
399
- `Full guide: ${top.framework.docsUrl}`
400
- ].join("\n"), "Manual setup");
401
- ui.note([
402
- "For automated setup, install an agent and run `superwall integrate` again:",
403
- "Claude Code: npm install --global @anthropic-ai/claude-code",
404
- "Codex: npm install --global @openai/codex"
405
- ].join("\n"), "Automated setup");
406
- ui.outro("Re-run `superwall integrate` after installing an agent.");
407
- }
408
-
409
- //#endregion
410
- //#region src/commands/workflow/integrate/agent.ts
391
+ //#region src/core/workflows/agent.ts
411
392
  async function copyIntegrationPrompt(context) {
412
393
  const prompt = buildCopyPrompt(actionById.integrate, context);
413
394
  if (await copyToClipboard(prompt)) ui.note("Paste it into Claude Code, Codex, Cursor, or another coding agent.", "Integration prompt copied to clipboard");
@@ -433,7 +414,7 @@ async function runActionWithUI(driver, fallbackDrivers, action, context) {
433
414
  spin.stop(action.successLabel);
434
415
  if (action.outputMode === "report" && result.finalText) {
435
416
  const report = stripReport(result.finalText);
436
- saveReport(context.app.path, action.id, report);
417
+ writeReport(context.app.path, action.id, report);
437
418
  ui.report(report);
438
419
  }
439
420
  }
@@ -448,18 +429,131 @@ function printPlan(agent, action, context) {
448
429
  `Prior: ${context.priorReport ? "review report found" : "none"}`
449
430
  ].join("\n"), "Plan");
450
431
  }
451
- function finish(context, action) {
432
+ function finish(output, action) {
452
433
  const finalBlocks = [blocks.nextSteps({
453
434
  integrate: ["Set up the dashboard (campaign + paywall) so the placement presents something.", "Verify on device for placement 'campaign_trigger'."],
454
435
  "placements-implement": ["Set up the dashboard so the new placements present paywalls."],
455
436
  "dashboard-setup": ["Design the paywall and attach products in the dashboard.", "Verify on device."]
456
437
  }[action.id] ?? [])];
457
438
  if (action.id !== "review" && action.id !== "review-fix") finalBlocks.push(blocks.outro(`Done. ${DASHBOARD_URL}`));
458
- context.output.render(...finalBlocks);
439
+ output.render(...finalBlocks);
440
+ }
441
+
442
+ //#endregion
443
+ //#region src/core/workflows/app.ts
444
+ async function recoverUnmatchedScope(app, apiKey) {
445
+ for (;;) {
446
+ const orgName = sessionOrgName(readSession());
447
+ const orgLabel = orgName ? `\`${orgName}\`` : "the apps this account can open";
448
+ ui.error(`This project's API key (\`${apiKey}\`) doesn't match any app in ${orgLabel}. You might be logged in to the wrong account.`);
449
+ const choice = await ui.select({
450
+ message: "How do you want to fix it?",
451
+ options: [
452
+ {
453
+ value: "relogin",
454
+ label: "Log in with a different account"
455
+ },
456
+ {
457
+ value: "bind",
458
+ label: `Connect this app to ${orgLabel} instead`,
459
+ hint: "creates or picks an app and issues a new API key"
460
+ },
461
+ {
462
+ value: "skip",
463
+ label: "Skip for now"
464
+ }
465
+ ]
466
+ });
467
+ if (choice === null || choice === "skip") return null;
468
+ if (choice === "relogin") {
469
+ removeSession();
470
+ if (!await performLoginWithUi(app)) return null;
471
+ const resolved = await withSpinner("Finding this app in Superwall", () => resolveScopeFromKey(superwallApi(), apiKey).catch(() => null));
472
+ if (resolved) {
473
+ ui.success(`Found \`${resolved.appName ?? app.name}\``);
474
+ return {
475
+ scope: {
476
+ projectId: resolved.projectId,
477
+ applicationId: resolved.applicationId,
478
+ appName: resolved.appName ?? app.name
479
+ },
480
+ bundleId: resolved.bundleId
481
+ };
482
+ }
483
+ continue;
484
+ }
485
+ try {
486
+ const bound = await resolveAppBinding(superwallApi(), {
487
+ platform: platformForIntegration(app.integration),
488
+ appName: app.name
489
+ });
490
+ if (!bound) continue;
491
+ ui.note(`Your code still uses \`${apiKey}\`.\nReplace it with \`${bound.apiKey}\` so the app talks to ${orgLabel}.`, "Swap the API key");
492
+ return {
493
+ scope: {
494
+ projectId: bound.projectId,
495
+ applicationId: bound.applicationId,
496
+ appName: app.name
497
+ },
498
+ bundleId: bound.app.bundle_id
499
+ };
500
+ } catch (error) {
501
+ ui.warn(error instanceof Error ? error.message : String(error));
502
+ }
503
+ }
504
+ }
505
+ async function ensureAgentDriverReady(driver, ensureLogin, dryRun) {
506
+ if (driver.id !== "superwall" || dryRun) return true;
507
+ if (!await ensureLogin()) {
508
+ ui.warn("Superwall Agent needs sign-in. Run `superwall login`, or install Claude Code/Codex and re-run.");
509
+ return false;
510
+ }
511
+ const status = await withSpinner("Checking Superwall Agent credit", () => selectHostedStatus());
512
+ if (!status) {
513
+ ui.warn("Superwall Agent needs an OAuth login. Run `superwall login` (not `--api-key`), or install Claude Code/Codex.");
514
+ return false;
515
+ }
516
+ if (status.exhausted) {
517
+ ui.warn("Your hosted Superwall Agent credit is exhausted. Install Claude Code/Codex or copy the prompt into your own agent.");
518
+ return false;
519
+ }
520
+ return true;
521
+ }
522
+ async function pickApp(installDir, interactive) {
523
+ const scan = await withSpinner("Scanning your project", () => scanProject(installDir));
524
+ const [firstApp] = scan.apps;
525
+ if (!firstApp) {
526
+ const [webApp] = scan.unsupported;
527
+ if (webApp) throw new Error(`Detected a web app${webApp.details ? ` (\`${webApp.details}\`)` : ""}. This command supports mobile apps.`);
528
+ const skipped = scan.skipped.length ? ` Skipped: ${scan.skipped.join(", ")}.` : "";
529
+ throw new Error(`No ${SUPPORTED_LABEL} app found in this directory.${skipped}`);
530
+ }
531
+ if (scan.unsupported.length) ui.info(`Also found unsupported web apps: ${scan.unsupported.map((app) => app.name).join(", ")}`);
532
+ if (scan.apps.length === 1) {
533
+ ui.info(`Detected \`${firstApp.framework.name}\`` + (firstApp.details ? ` · \`${firstApp.details}\`` : "") + (firstApp.relPath !== "." ? ` (${firstApp.relPath})` : ""));
534
+ return firstApp;
535
+ }
536
+ if (!interactive) throw new Error("Multiple apps found. Pass --install-dir for the app you want to change.");
537
+ const choice = await ui.select({
538
+ message: scan.isMonorepo ? "Found multiple apps - which one?" : "Which app?",
539
+ options: scan.apps.map((app) => ({
540
+ value: app.path,
541
+ label: `${app.name} · ${app.framework.name}`,
542
+ hint: app.relPath === "." ? void 0 : app.relPath
543
+ })),
544
+ initialValue: firstApp.path
545
+ });
546
+ if (choice === null) return null;
547
+ return scan.apps.find((app) => app.path === choice) ?? firstApp;
548
+ }
549
+ async function stage(label, work) {
550
+ ui.step(label);
551
+ await new Promise((resolve$1) => setTimeout(resolve$1, 40));
552
+ await work();
459
553
  }
460
554
 
461
555
  //#endregion
462
- //#region src/commands/workflow/integrate/campaigns.ts
556
+ //#region src/core/workflows/campaigns.ts
463
557
  async function runCampaignsAndPlacements(driver, fallbackDrivers, actionContext, stageContext, ensureAgentReady) {
464
558
  const { api, scope } = stageContext;
465
559
  const campaigns = await withSpinner("Checking campaigns", () => listResource(api, "campaigns", scope));
@@ -486,15 +580,12 @@ async function runCampaignsAndPlacements(driver, fallbackDrivers, actionContext,
486
580
  if (!await ensureAgentReady()) return;
487
581
  await runActionWithUI(driver, fallbackDrivers, actionById["placements-implement"], {
488
582
  ...context,
489
- priorReport: loadReport(actionContext.app.path, "placements-review")
583
+ priorReport: readReport(actionContext.app.path, "placements-review")
490
584
  });
491
585
  }
492
586
  if (await ui.confirm({ message: "Create campaigns so these placements can present paywalls?" })) {
493
587
  if (!await ensureAgentReady()) return;
494
- await runActionWithUI(driver, fallbackDrivers, actionById["dashboard-setup"], {
495
- ...context,
496
- campaigns: campaignSummary(await listResource(api, "campaigns", scope).catch(() => campaigns))
497
- });
588
+ await runActionWithUI(driver, fallbackDrivers, actionById["dashboard-setup"], context);
498
589
  }
499
590
  }
500
591
  function placementsOf(campaign) {
@@ -509,36 +600,25 @@ function campaignSummary(campaigns) {
509
600
  }
510
601
 
511
602
  //#endregion
512
- //#region src/commands/workflow/integrate.ts
513
- const runIntegrate = defineCommand({
514
- name: "integrate",
515
- auth: "optional",
516
- run: runPipeline
517
- });
518
- function runActionCommand(action) {
519
- return defineCommand({
520
- name: action,
521
- auth: "optional",
522
- run: (ctx) => runFlow(ctx, action)
523
- });
524
- }
525
- async function runPipeline(ctx) {
526
- const { installDir, dryRun, argv } = ctx;
603
+ //#region src/core/workflows/integrate.ts
604
+ async function runIntegrate(ctx) {
605
+ const { installDir, dryRun } = ctx;
527
606
  ui.intro(`Superwall v${VERSION}`);
528
607
  const drivers = await withSpinner("Checking your setup", () => detectDrivers());
529
- if (drivers.length === 0) {
608
+ const [first] = drivers;
609
+ if (!first) {
530
610
  ui.warn("No coding agent found.");
531
611
  await runFallback(installDir);
532
612
  return;
533
613
  }
534
- const wanted = argv.driver;
535
- const picked = wanted ? drivers.find((d) => d.driver.id === wanted) : drivers[0];
536
- if (wanted && !picked) throw new Error(`Driver "${wanted}" not available. Detected: ${drivers.map((d) => d.driver.id).join(", ") || "none"}.`);
614
+ const wanted = ctx.driver;
615
+ const picked = wanted ? drivers.find((d) => d.driver.id === wanted) : first;
616
+ if (!picked) throw new Error(`Driver "${wanted}" not available. Detected: ${drivers.map((d) => d.driver.id).join(", ")}.`);
537
617
  const driver = picked.driver;
538
618
  const fallbackDrivers = wanted ? [] : drivers.filter((candidate) => candidate !== picked).map((candidate) => candidate.driver);
539
619
  const app = await pickApp(installDir, ctx.interactive);
540
620
  if (!app) return;
541
- setTelemetryTags({
621
+ updateTelemetryTags({
542
622
  driver: driver.id,
543
623
  framework: app.framework.integration
544
624
  });
@@ -567,28 +647,21 @@ async function runPipeline(ctx) {
567
647
  if (intent === null) return;
568
648
  ui.info(`RevenueCat: \`${intent}\``);
569
649
  }
570
- let session = loadSession();
571
- if (session?.apiKey) process.env.SUPERWALL_API_KEY = session.apiKey;
650
+ const session = readSession();
572
651
  let scopePromise = null;
573
652
  if (session && existing.apiKey) scopePromise = resolveScopeFromKey(superwallApi(), existing.apiKey).catch(() => null);
574
- const provisionedRef = { current: null };
575
- const ensureLogin = async () => {
576
- if (session) return true;
577
- if (!ctx.interactive || dryRun) return false;
578
- const signedIn = await performLoginWithUi(app, (result) => {
579
- provisionedRef.current = result;
580
- });
581
- if (!signedIn) return false;
582
- session = signedIn;
583
- if (session.apiKey) process.env.SUPERWALL_API_KEY = session.apiKey;
584
- return true;
585
- };
653
+ const login = createLoginGate(app, {
654
+ session,
655
+ interactive: ctx.interactive,
656
+ dryRun
657
+ });
658
+ const ensureLogin = login.ensure;
586
659
  let apiKey = existing.apiKey ?? "";
587
- const flagKey = argv.apiKey ?? apiKeyFromEnv();
660
+ const flagKey = ctx.apiKey;
588
661
  let scope = null;
589
662
  let bundleId;
590
663
  if (!apiKey && !flagKey) {
591
- const remembered = getOnboardedApp(app.path);
664
+ const remembered = readOnboardedApp(app.path);
592
665
  if (remembered) {
593
666
  apiKey = remembered.publicApiKey;
594
667
  if (remembered.projectId && remembered.applicationId) scope = {
@@ -609,7 +682,7 @@ async function runPipeline(ctx) {
609
682
  }
610
683
  }
611
684
  } else if (await ensureLogin()) {
612
- const provisioned = provisionedRef.current;
685
+ const provisioned = login.provisioned();
613
686
  if (provisioned?.publicApiKey) {
614
687
  apiKey = provisioned.publicApiKey;
615
688
  if (provisioned.projectId && provisioned.applicationId) scope = {
@@ -633,20 +706,21 @@ async function runPipeline(ctx) {
633
706
  bundleId = bound.app.bundle_id;
634
707
  ui.success(`Using \`${bound.app.name ?? bound.app.id}\` (${platformLabel(bound.app.platform)})`);
635
708
  } catch (e) {
636
- ui.warn(e.message);
709
+ ui.warn(e instanceof Error ? e.message : String(e));
637
710
  }
638
711
  }
639
712
  }
640
713
  if (!apiKey) {
641
714
  const account = await resolveAccount({
642
715
  existing,
643
- argv,
716
+ apiKey: ctx.apiKey,
644
717
  interactive: ctx.interactive,
645
718
  ui: ctx.ui
646
719
  });
647
720
  if (!account) return void ui.warn("Cancelled.");
648
721
  apiKey = account.apiKey;
649
722
  }
723
+ if (session?.apiKey) process.env.SUPERWALL_API_KEY = session.apiKey;
650
724
  const ctxAction = {
651
725
  app,
652
726
  apiKey,
@@ -658,7 +732,8 @@ async function runPipeline(ctx) {
658
732
  ui.info("SDK already integrated - skipped.");
659
733
  if (!dryRun) await ensureSkillsCurrent();
660
734
  } else if (!dryRun) {
661
- const how = !ctx.interactive ? "now" : await ui.select({
735
+ let how = "now";
736
+ if (ctx.interactive) how = await ui.select({
662
737
  message: `Integrate the Superwall SDK into \`${app.name}\`?`,
663
738
  options: [{
664
739
  value: "now",
@@ -686,13 +761,15 @@ async function runPipeline(ctx) {
686
761
  await runActionWithUI(driver, fallbackDrivers, actionById["integrate"], ctxAction);
687
762
  await ensureSkillsCurrent(true);
688
763
  }
689
- const canResolveHeadless = !ctx.interactive && !!apiKey && !!loadSession();
690
- if (!dryRun && !ctx.interactive && !loadSession()) {
764
+ const canResolveHeadless = !ctx.interactive && !!apiKey && !!readSession();
765
+ if (!dryRun && !ctx.interactive && !readSession()) {
691
766
  ui.warn("You aren't logged in — headless mode cannot run the placements/campaigns stages. Run `superwall login` first. The SDK code changes (if any) were applied, but the integration is INCOMPLETE.");
692
767
  process.exitCode = 1;
693
768
  }
694
769
  if (!dryRun && !scope && (canResolveHeadless || ctx.interactive && await ensureLogin())) {
695
- const resolved = await withSpinner("Finding this app in Superwall", () => scopePromise ? scopePromise : resolveScopeFromKey(superwallApi(), apiKey).catch(() => null));
770
+ const resolved = await withSpinner("Finding this app in Superwall", () => {
771
+ return scopePromise ?? resolveScopeFromKey(superwallApi(), apiKey).catch(() => null);
772
+ });
696
773
  if (resolved) {
697
774
  scope = resolved;
698
775
  bundleId = resolved.bundleId;
@@ -723,85 +800,35 @@ async function runPipeline(ctx) {
723
800
  }
724
801
  ui.outro(`Done. ${DASHBOARD_URL}`);
725
802
  }
726
- async function runFlow(ctx, forced) {
727
- const { installDir, dryRun, argv } = ctx;
803
+ async function runReview(ctx, fix) {
804
+ const { installDir, dryRun } = ctx;
728
805
  ui.intro(`Superwall v${VERSION}`);
729
- const drivers = await withSpinner("Checking your setup", () => detectDrivers());
730
- if (drivers.length === 0) {
806
+ const [driver, ...fallbacks] = await withSpinner("Checking your setup", () => detectDrivers());
807
+ if (!driver) {
731
808
  ui.warn("No coding agent found.");
732
809
  await runFallback(installDir);
733
810
  return;
734
811
  }
735
- const driver = drivers[0];
736
- const fallbackDrivers = drivers.slice(1).map((candidate) => candidate.driver);
737
- let session = loadSession();
812
+ const fallbackDrivers = fallbacks.map((candidate) => candidate.driver);
738
813
  const app = await pickApp(installDir, ctx.interactive);
739
814
  if (!app) return void ui.warn("Cancelled.");
740
- const provisionedRef = { current: null };
741
- const ensureLogin = async () => {
742
- if (session) return true;
743
- if (!ctx.interactive || dryRun) return false;
744
- const signedIn = await performLoginWithUi(app, (result) => {
745
- provisionedRef.current = result;
746
- });
747
- if (!signedIn) return false;
748
- session = signedIn;
749
- if (session.apiKey) process.env.SUPERWALL_API_KEY = session.apiKey;
750
- return true;
751
- };
752
- setTelemetryTags({
815
+ const login = createLoginGate(app, {
816
+ session: readSession(),
817
+ interactive: ctx.interactive,
818
+ dryRun
819
+ });
820
+ updateTelemetryTags({
753
821
  driver: driver.driver.id,
754
822
  framework: app.framework.integration
755
823
  });
756
824
  const existing = detectExisting(app);
757
825
  if (existing.fullyIntegrated) ui.success(`Superwall is already set up in \`${app.name}\`.`);
758
826
  else if (existing.sdkInstalled) ui.info(`Partial Superwall setup found in \`${app.name}\`.`);
759
- const choice = await chooseAction(forced, existing, app, ctx.interactive);
760
- if (!choice) return;
761
- const action = actionById[choice];
762
- if (action.requiresOrgKey && !process.env.SUPERWALL_API_KEY && !loadSession()) {
763
- ui.warn("That needs an authenticated session - run `superwall login` first (or set SUPERWALL_API_KEY).");
764
- ui.outro("");
765
- return;
766
- }
767
- let apiKey = existing.apiKey ?? "";
768
- if (action.id === "integrate" || action.id === "dashboard-setup") {
769
- const flagKey = argv.apiKey ?? apiKeyFromEnv();
770
- if (!apiKey && !flagKey) {
771
- const remembered = getOnboardedApp(app.path);
772
- if (remembered) {
773
- apiKey = remembered.publicApiKey;
774
- ui.info(`Using \`${app.name}\` - created during onboarding.`);
775
- }
776
- }
777
- if (!apiKey && !flagKey && ctx.interactive && await ensureLogin()) if (provisionedRef.current?.publicApiKey) {
778
- apiKey = provisionedRef.current.publicApiKey;
779
- ui.success(`Created \`${app.name}\` in Superwall`);
780
- } else try {
781
- const bound = await resolveAppBinding(superwallApi(), {
782
- platform: platformForIntegration(app.integration),
783
- appName: app.name
784
- });
785
- if (!bound) return void ui.warn("Cancelled.");
786
- apiKey = bound.apiKey;
787
- } catch (e) {
788
- ui.warn(e.message);
789
- }
790
- if (!apiKey) {
791
- const account = await resolveAccount({
792
- existing,
793
- argv,
794
- interactive: ctx.interactive,
795
- ui: ctx.ui
796
- });
797
- if (!account) return void ui.warn("Cancelled.");
798
- apiKey = account.apiKey;
799
- }
800
- }
801
- const priorReport = action.id === "review-fix" ? loadReport(app.path, "review") : action.id === "placements-implement" ? loadReport(app.path, "placements-review") : void 0;
827
+ const action = actionById[fix ? "review-fix" : "review"];
828
+ const priorReport = fix ? readReport(app.path, "review") : void 0;
802
829
  const actionCtx = {
803
830
  app,
804
- apiKey,
831
+ apiKey: existing.apiKey ?? "",
805
832
  existing,
806
833
  priorReport
807
834
  };
@@ -810,14 +837,11 @@ async function runFlow(ctx, forced) {
810
837
  ui.outro("Dry run - no changes made.");
811
838
  return;
812
839
  }
813
- if (action.id === "integrate" && existing.fullyIntegrated) ui.note("SDK + configure() already present - no code changes made.", "Already integrated");
814
- else {
815
- if (!await ensureAgentDriverReady(driver.driver, ensureLogin, dryRun)) return;
816
- await runActionWithUI(driver.driver, fallbackDrivers, action, actionCtx);
817
- }
818
- await ensureSkillsCurrent(action.id === "integrate" && !existing.fullyIntegrated);
819
- finish(ctx, action);
840
+ if (!await ensureAgentDriverReady(driver.driver, login.ensure, dryRun)) return;
841
+ await runActionWithUI(driver.driver, fallbackDrivers, action, actionCtx);
842
+ await ensureSkillsCurrent();
843
+ finish(ctx.output, action);
820
844
  }
821
845
 
822
846
  //#endregion
823
- export { runActionCommand, runIntegrate };
847
+ export { runIntegrate, runReview };