@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
@@ -0,0 +1,62 @@
1
+ import { n as fg, t as THEME } from "./theme-DUsCh-Vd.js";
2
+ import pc from "picocolors";
3
+ import { link } from "ansi-escapes";
4
+ import wrapAnsi from "wrap-ansi";
5
+ import { pathToFileURL } from "node:url";
6
+
7
+ //#region src/ui/log.ts
8
+ function brand(text) {
9
+ return fg(THEME.primary, text);
10
+ }
11
+ function stripReport(raw) {
12
+ const lines = raw.replace(/\r/g, "").split("\n").filter((l) => !/^\s*\[STATUS\]/i.test(l));
13
+ while (lines[0]?.trim() === "") lines.shift();
14
+ while (lines.at(-1)?.trim() === "") lines.pop();
15
+ return lines.join("\n");
16
+ }
17
+ function styleMarkdown(text) {
18
+ return text.split("\n").map((line) => styleMarkdownLine(line)).join("\n");
19
+ }
20
+ function styleMarkdownLine(line, opts = {}) {
21
+ const heading = line.match(/^\s*(#{1,6})\s+(.*)$/)?.[2];
22
+ if (heading !== void 0) return brand(pc.bold(styleInline(heading, opts.hyperlinks ?? false)));
23
+ return styleInline(line, opts.hyperlinks ?? false);
24
+ }
25
+ function wrapReportLine(line, columns) {
26
+ const prefix = line.match(/^(\s*(?:(?:[-*+])|(?:\d+[.)]))\s+)/)?.[1] ?? "";
27
+ const content = prefix ? line.slice(prefix.length) : line;
28
+ const width = Math.max(12, columns - prefix.length);
29
+ return wrapAnsi(styleMarkdownLine(content, { hyperlinks: true }), width, {
30
+ hard: true,
31
+ trim: false
32
+ }).split("\n").map((part, index) => `${index === 0 ? prefix : " ".repeat(prefix.length)}${part}`);
33
+ }
34
+ function styleInline(line, hyperlinks) {
35
+ const re = /\[([^\]]+)]\(([^)]+)\)|\*\*(.+?)\*\*|`([^`]+)`|(https?:\/\/[^\s]+)/g;
36
+ let out = "";
37
+ let last = 0;
38
+ let match;
39
+ while (match = re.exec(line)) {
40
+ out += line.slice(last, match.index);
41
+ if (match[1] != null && match[2] != null) {
42
+ const label = match[1];
43
+ const target = match[2];
44
+ out += hyperlinks ? link(brand(pc.underline(label)), terminalLinkTarget(target)) : `${label} (${target})`;
45
+ } else if (match[3] != null) out += pc.bold(match[3]);
46
+ else if (match[4] != null) out += brand(match[4]);
47
+ else if (match[5] != null) out += hyperlinks ? link(brand(pc.underline(match[5])), match[5]) : match[5];
48
+ last = re.lastIndex;
49
+ }
50
+ out += line.slice(last);
51
+ return out;
52
+ }
53
+ function terminalLinkTarget(target) {
54
+ const local = target.match(/^(\/.*?)(?::(\d+))?$/);
55
+ const file = local?.[1];
56
+ if (file === void 0) return target;
57
+ const url = pathToFileURL(file).href;
58
+ return local?.[2] ? `${url}#L${local[2]}` : url;
59
+ }
60
+
61
+ //#endregion
62
+ export { styleMarkdown as n, wrapReportLine as r, stripReport as t };
@@ -0,0 +1,53 @@
1
+ import { n as ui } from "./ui-D_qf3Gvw.js";
2
+ import { a as onboardingHooks, r as BROWSER_UNAVAILABLE, t as performLogin } from "./login-BbTIrCFT.js";
3
+
4
+ //#region src/core/workflows/login.ts
5
+ async function performLoginWithUi(app, onProvisioned) {
6
+ const spin = ui.spinner();
7
+ const hooks = onboardingHooks(app);
8
+ try {
9
+ const session = await performLogin({
10
+ onVerify: ({ url, userCode, browserOpened }) => {
11
+ ui.info(`Approve this login in your browser · code \`${userCode}\`\n${url}`);
12
+ if (!browserOpened) ui.warn(BROWSER_UNAVAILABLE);
13
+ spin.start("Waiting for you to approve in the browser");
14
+ },
15
+ onStatus: (message) => spin.message(message),
16
+ onOnboard: async () => {
17
+ const setup = await hooks.onOnboard();
18
+ if (setup) spin.start("Creating your account");
19
+ return setup;
20
+ },
21
+ onProvisioned: (result) => {
22
+ hooks.onProvisioned(result);
23
+ onProvisioned?.(result);
24
+ }
25
+ });
26
+ spin.stop(`Logged in as \`${session.userEmail ?? "you"}\``);
27
+ return session;
28
+ } catch (error) {
29
+ spin.stop("Login failed");
30
+ ui.warn(error instanceof Error ? error.message : String(error));
31
+ return null;
32
+ }
33
+ }
34
+ function createLoginGate(app, options) {
35
+ let session = options.session;
36
+ let provisioned = null;
37
+ return {
38
+ ensure: async () => {
39
+ if (session) return true;
40
+ if (!options.interactive || options.dryRun) return false;
41
+ const signedIn = await performLoginWithUi(app, (result) => {
42
+ provisioned = result;
43
+ });
44
+ if (!signedIn) return false;
45
+ session = signedIn;
46
+ return true;
47
+ },
48
+ provisioned: () => provisioned
49
+ };
50
+ }
51
+
52
+ //#endregion
53
+ export { performLoginWithUi as n, createLoginGate as t };
@@ -0,0 +1,16 @@
1
+ import "./token-DaxQgQkv.js";
2
+ import "./output-Ggzq5_-t.js";
3
+ import "./environment-eBXjELoN.js";
4
+ import "./storage-6h9vyiAz.js";
5
+ import "./client-BL0f_yGf.js";
6
+ import "./config-BO1Y87kV.js";
7
+ import "./telemetry-DKyDhURo.js";
8
+ import "./spawn-DmmmHIP-.js";
9
+ import "./spinner-C2U6QBJ9.js";
10
+ import "./ui-D_qf3Gvw.js";
11
+ import "./scan-CKuk-_6W.js";
12
+ import "./paths-CRlU72cq.js";
13
+ import { n as runLogin, t as performLogin } from "./login-BbTIrCFT.js";
14
+ import "./skills-CZcpnEnG.js";
15
+
16
+ export { performLogin, runLogin };
@@ -1,13 +1,25 @@
1
- import { _ as OAUTH_SCOPE, c as AUTH_HOST, d as CLI_CLIENT_ID, g as Integration, o as API_HOST } from "./output-C4o2gJ1K.js";
2
- import { c as getOnboardedOrg, l as getOnboardingIdempotencyKey, m as setOnboardedOrg, p as setOnboardedApp } from "./telemetry-DeA1mvnT.js";
3
- import { a as saveSession } from "./token-C0it-Xh7.js";
4
- import { n as ui } from "./ui-Dy0b-9L8.js";
1
+ import { f as Integration, i as AUTH_HOST, p as OAUTH_SCOPE, s as CLI_CLIENT_ID, t as API_HOST } from "./environment-eBXjELoN.js";
2
+ import { i as serializeSession, o as writeSession } from "./storage-6h9vyiAz.js";
3
+ import { a as readOnboardingIdempotencyKey, d as writeOnboardedApp, f as writeOnboardedOrg, i as readOnboardedOrg } from "./config-BO1Y87kV.js";
4
+ import { r as track } from "./telemetry-DKyDhURo.js";
5
+ import { n as ui } from "./ui-D_qf3Gvw.js";
6
+ import { t as scanProject } from "./scan-CKuk-_6W.js";
7
+ import { s as ensureSkillsCurrent } from "./skills-CZcpnEnG.js";
5
8
  import { spawn } from "node:child_process";
9
+ import { setTimeout } from "node:timers/promises";
6
10
 
7
11
  //#region src/core/account/onboarding.ts
12
+ function resolveOnboardPlatform(integration) {
13
+ switch (integration) {
14
+ case Integration.swift: return "ios";
15
+ case Integration.android: return "android";
16
+ case Integration.web: return "web";
17
+ default: return;
18
+ }
19
+ }
8
20
  function onboardingHooks(app) {
9
21
  const ref = { current: null };
10
- const platform = app?.integration === Integration.swift ? "ios" : app?.integration === Integration.android ? "android" : app?.integration === Integration.web ? "web" : void 0;
22
+ const platform = resolveOnboardPlatform(app?.integration);
11
23
  return {
12
24
  onOnboard: async () => {
13
25
  let onboardApp;
@@ -34,7 +46,7 @@ function onboardingHooks(app) {
34
46
  },
35
47
  onProvisioned: (result) => {
36
48
  ref.current = result;
37
- if (app && result.publicApiKey) setOnboardedApp(app.path, {
49
+ if (app && result.publicApiKey) writeOnboardedApp(app.path, {
38
50
  publicApiKey: result.publicApiKey,
39
51
  projectId: result.projectId,
40
52
  applicationId: result.applicationId
@@ -45,7 +57,7 @@ function onboardingHooks(app) {
45
57
  }
46
58
 
47
59
  //#endregion
48
- //#region src/core/auth/browser.ts
60
+ //#region src/core/account/browser.ts
49
61
  const BROWSER_UNAVAILABLE = "Couldn't open a browser here. Open the URL above to approve the login.";
50
62
  function hasDisplay(env, platform) {
51
63
  if (platform !== "linux") return true;
@@ -77,9 +89,8 @@ function openBrowser(url, deps = {}) {
77
89
  }
78
90
 
79
91
  //#endregion
80
- //#region src/core/auth/login.ts
92
+ //#region src/core/account/login.ts
81
93
  const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
82
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
83
94
  async function performLogin(opts = {}) {
84
95
  const issuer = opts.issuer ?? AUTH_HOST();
85
96
  const apiHost = opts.apiHost ?? API_HOST();
@@ -96,42 +107,35 @@ async function performLogin(opts = {}) {
96
107
  });
97
108
  const { accessToken, refreshToken, expiresIn, idToken } = await pollForToken(disc.token_endpoint, clientId, dev, opts.onStatus);
98
109
  let apiToken = accessToken;
99
- if (idToken) await getJson(`${apiHost}/v2/me`, idToken).catch(() => null);
100
- const me = await getJson(`${apiHost}/v2/me`, apiToken).catch(() => null);
101
- let orgList = [];
110
+ if (idToken) await findJson(`${apiHost}/v2/me`, idToken).catch(() => null);
111
+ const me = await findJson(`${apiHost}/v2/me`, apiToken).catch(() => null);
112
+ let hasOrg = false;
102
113
  try {
103
- orgList = (await getJson(`${apiHost}/v2/me/organizations`, apiToken)).data ?? [];
114
+ hasOrg = ((await findJson(`${apiHost}/v2/me/organizations`, apiToken)).data ?? []).length > 0;
104
115
  } catch {
105
- orgList = [];
116
+ hasOrg = false;
106
117
  }
107
- const uniqueOrgs = [...new Map(orgList.map((o) => [String(o.id), o])).values()];
108
- let org;
109
118
  let createdNewOrg = false;
110
- if (uniqueOrgs.length === 0) {
111
- const remembered = getOnboardedOrg();
112
- if (remembered) org = {
113
- id: remembered.id,
114
- name: remembered.name
115
- };
116
- else if (opts.onOnboard) {
117
- const setup = await opts.onOnboard();
118
- if (!setup) throw new Error("Cancelled.");
119
- opts.onStatus?.("Creating your account…");
120
- if (setup.app) {
121
- const provisioned = await provisionAccount(apiHost, apiToken, setup);
122
- if (provisioned.orgId) org = {
123
- id: provisioned.orgId,
124
- name: setup.orgName
125
- };
126
- opts.onProvisioned?.(provisioned);
127
- } else org = await createOrganization(apiHost, apiToken, setup.orgName);
128
- if (org) setOnboardedOrg({
129
- id: String(org.id),
130
- name: org.name
131
- });
132
- createdNewOrg = true;
133
- } else throw new Error("Your account has no organization yet - run `superwall login` interactively to create one.");
134
- } else if (uniqueOrgs.length === 1) org = uniqueOrgs[0];
119
+ if (!hasOrg && !readOnboardedOrg()) {
120
+ if (!opts.onOnboard) throw new Error("Your account has no organization yet - run `superwall login` interactively to create one.");
121
+ const setup = await opts.onOnboard();
122
+ if (!setup) throw new Error("Cancelled.");
123
+ opts.onStatus?.("Creating your account…");
124
+ let org;
125
+ if (setup.app) {
126
+ const provisioned = await provisionAccount(apiHost, apiToken, setup.orgName, setup.app);
127
+ if (provisioned.orgId) org = {
128
+ id: provisioned.orgId,
129
+ name: setup.orgName
130
+ };
131
+ opts.onProvisioned?.(provisioned);
132
+ } else org = await createOrganization(apiHost, apiToken, setup.orgName);
133
+ if (org) writeOnboardedOrg({
134
+ id: String(org.id),
135
+ name: org.name
136
+ });
137
+ createdNewOrg = true;
138
+ }
135
139
  if (createdNewOrg && refreshToken) {
136
140
  opts.onStatus?.("Activating your organization…");
137
141
  const fresh = await refreshAccessToken(disc.token_endpoint, clientId, refreshToken);
@@ -139,9 +143,6 @@ async function performLogin(opts = {}) {
139
143
  }
140
144
  const session = {
141
145
  authMethod: "oauth",
142
- orgId: org ? String(org.id) : void 0,
143
- orgName: org?.name,
144
- orgCount: createdNewOrg ? 1 : uniqueOrgs.length,
145
146
  userEmail: me?.email,
146
147
  host: apiHost,
147
148
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -151,7 +152,7 @@ async function performLogin(opts = {}) {
151
152
  tokenEndpoint: disc.token_endpoint,
152
153
  oauthClientId: clientId
153
154
  };
154
- saveSession(session);
155
+ writeSession(session);
155
156
  return session;
156
157
  }
157
158
  async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
@@ -159,7 +160,7 @@ async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
159
160
  if (!key) throw new Error("An API key is required.");
160
161
  let org = {};
161
162
  try {
162
- const first = (await getJson(`${apiHost}/v2/me/organizations`, key)).data?.[0];
163
+ const first = (await findJson(`${apiHost}/v2/me/organizations`, key)).data?.[0];
163
164
  if (first) org = {
164
165
  id: String(first.id),
165
166
  name: first.name
@@ -170,12 +171,11 @@ async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
170
171
  const session = {
171
172
  authMethod: "api_key",
172
173
  apiKey: key,
173
- orgId: org.id,
174
174
  orgName: org.name,
175
175
  host: apiHost,
176
176
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
177
177
  };
178
- saveSession(session);
178
+ writeSession(session);
179
179
  return session;
180
180
  }
181
181
  async function discover(issuer) {
@@ -202,7 +202,7 @@ async function pollForToken(tokenEndpoint, clientId, dev, onStatus) {
202
202
  const deadline = Date.now() + (dev.expires_in ?? 600) * 1e3;
203
203
  let interval = dev.interval ?? 5;
204
204
  while (Date.now() < deadline) {
205
- await sleep(interval * 1e3);
205
+ await setTimeout(interval * 1e3);
206
206
  const r = await fetch(tokenEndpoint, {
207
207
  method: "POST",
208
208
  headers: { "content-type": "application/x-www-form-urlencoded" },
@@ -240,11 +240,10 @@ async function createOrganization(apiHost, token, name) {
240
240
  name: created.name
241
241
  };
242
242
  }
243
- async function provisionAccount(apiHost, token, setup) {
244
- const app = setup.app;
243
+ async function provisionAccount(apiHost, token, orgName, app) {
245
244
  const res = await postJson(`${apiHost}/internal/v2/onboarding/provision`, token, {
246
- idempotency_key: getOnboardingIdempotencyKey(),
247
- organization: { name: setup.orgName },
245
+ idempotency_key: readOnboardingIdempotencyKey(),
246
+ organization: { name: orgName },
248
247
  applications: [{
249
248
  name: app.name,
250
249
  platform: app.platform,
@@ -277,7 +276,7 @@ async function refreshAccessToken(tokenEndpoint, clientId, refreshToken) {
277
276
  return null;
278
277
  }
279
278
  }
280
- async function getJson(url, accessToken) {
279
+ async function findJson(url, accessToken) {
281
280
  const r = await fetch(url, { headers: {
282
281
  authorization: `Bearer ${accessToken}`,
283
282
  accept: "application/json"
@@ -301,6 +300,70 @@ async function postJson(url, accessToken, body) {
301
300
  }
302
301
  return r.json();
303
302
  }
303
+ async function runLogin(ctx, { flags, openBrowser: openBrowser$1 }) {
304
+ const { ui: ui$1 } = ctx;
305
+ ui$1.intro("Superwall login");
306
+ const apiKeyArg = flags.apiKey;
307
+ if (apiKeyArg) {
308
+ const spin$1 = ui$1.spinner();
309
+ spin$1.start("Verifying your API key");
310
+ try {
311
+ const session = await loginWithApiKey(apiKeyArg);
312
+ spin$1.stop("Logged in");
313
+ track("login finished", {
314
+ status: "success",
315
+ method: "api_key"
316
+ });
317
+ if (ctx.json) return ctx.output.data(serializeSession(session));
318
+ ui$1.success(`Logged in with an API key${session.orgName ? ` · \`${session.orgName}\`` : ""}.`);
319
+ ui$1.outro("You're all set - run `superwall integrate` to set up your app.");
320
+ } catch (e) {
321
+ spin$1.stop("Login failed");
322
+ track("login finished", {
323
+ status: "error",
324
+ method: "api_key"
325
+ });
326
+ throw e;
327
+ }
328
+ return;
329
+ }
330
+ if (!ctx.interactive) throw new Error("Browser login requires an interactive terminal. Use `superwall login --api-key <key>`.");
331
+ const hooks = onboardingHooks((await scanProject(ctx.installDir).catch(() => null))?.apps[0]);
332
+ const spin = ui$1.spinner();
333
+ try {
334
+ const session = await performLogin({
335
+ issuer: flags.host,
336
+ clientId: flags.clientId,
337
+ openBrowser: openBrowser$1,
338
+ onVerify: ({ url, userCode, browserOpened }) => {
339
+ ui$1.info(`Approve this login in your browser · code \`${userCode}\`\n${url}`);
340
+ if (!browserOpened) ui$1.warn(BROWSER_UNAVAILABLE);
341
+ spin.start("Waiting for you to approve in the browser");
342
+ },
343
+ onStatus: (m) => spin.message(m),
344
+ onOnboard: async () => {
345
+ const setup = await hooks.onOnboard();
346
+ if (setup) spin.start("Creating your account");
347
+ return setup;
348
+ },
349
+ onProvisioned: hooks.onProvisioned
350
+ });
351
+ spin.stop(`Logged in as \`${session.userEmail ?? "you"}\``);
352
+ track("login finished", {
353
+ status: "success",
354
+ method: "oauth"
355
+ });
356
+ if (!ctx.json) await ensureSkillsCurrent(false, "login").catch(() => {});
357
+ ui$1.outro(hooks.provisioned()?.publicApiKey ? "Your app is ready - run `superwall integrate` to set up the SDK." : "You're all set - run `superwall integrate` to set up your app.");
358
+ } catch (e) {
359
+ spin.stop("Login failed");
360
+ track("login finished", {
361
+ status: "error",
362
+ method: "oauth"
363
+ });
364
+ throw e;
365
+ }
366
+ }
304
367
 
305
368
  //#endregion
306
- export { onboardingHooks as a, openBrowser as i, performLogin as n, BROWSER_UNAVAILABLE as r, loginWithApiKey as t };
369
+ export { onboardingHooks as a, openBrowser as i, runLogin as n, BROWSER_UNAVAILABLE as r, performLogin as t };
@@ -0,0 +1,71 @@
1
+ import { t as ApiError } from "./client-BL0f_yGf.js";
2
+ import { F as orgProjects, L as rememberOrg, p as listProjects } from "./resources-DLON3-61.js";
3
+
4
+ //#region src/core/api/lookup.ts
5
+ const DASHBOARD_PATH = /^\/(\d+)(?:\/(\d+))?(?:\/|$)/;
6
+ function parseDashboardUrl(value) {
7
+ let url;
8
+ try {
9
+ url = new URL(value);
10
+ } catch {
11
+ return;
12
+ }
13
+ if (!/(^|\.)superwall\.com$/.test(url.hostname)) return void 0;
14
+ const match = DASHBOARD_PATH.exec(url.pathname);
15
+ if (!match) return void 0;
16
+ return {
17
+ orgId: match[1],
18
+ applicationId: match[2]
19
+ };
20
+ }
21
+ function notFound(error) {
22
+ return error instanceof ApiError && (error.status === 404 || error.status === 403);
23
+ }
24
+ async function findProject(api, projectId, known) {
25
+ const local = known?.find((project) => String(project.id) === projectId);
26
+ if (local) return local;
27
+ try {
28
+ const project = await api.get(`/v2/projects/${encodeURIComponent(projectId)}`);
29
+ rememberOrg(project);
30
+ return project;
31
+ } catch (error) {
32
+ if (notFound(error)) return void 0;
33
+ throw error;
34
+ }
35
+ }
36
+ const selectFromProjects = (projects, matches) => {
37
+ for (const project of projects) {
38
+ const app = project.applications?.find(matches);
39
+ if (app) return {
40
+ project,
41
+ app
42
+ };
43
+ }
44
+ };
45
+ async function findApplication(api, ref, known) {
46
+ const dashboard = parseDashboardUrl(ref);
47
+ const id = dashboard?.applicationId ?? ref;
48
+ const byId = (app) => String(app.id) === id;
49
+ const local = selectFromProjects(known ?? await listProjects(api), (app) => byId(app) || app.name === ref);
50
+ if (local) return local;
51
+ if (!/^\d+$/.test(id)) return void 0;
52
+ const [paywall] = await api.get(`/v2/paywalls?application_id=${encodeURIComponent(id)}&limit=1`).then((page) => page.data ?? []).catch((error) => {
53
+ if (notFound(error)) return [];
54
+ throw error;
55
+ });
56
+ if (paywall?.project_id !== void 0) {
57
+ const project = await findProject(api, String(paywall.project_id));
58
+ const found$1 = project && selectFromProjects([project], byId);
59
+ if (found$1) return found$1;
60
+ }
61
+ if (!dashboard?.orgId) return void 0;
62
+ const found = selectFromProjects(await orgProjects(api, dashboard.orgId), byId);
63
+ if (found) rememberOrg(found.project);
64
+ return found;
65
+ }
66
+ function appNotFound(ref) {
67
+ return /* @__PURE__ */ new Error(`No app ${ref} that this account can open. Pass its dashboard link instead — https://app.superwall.com/<org>/<app>/… names the organization, which finds apps that have no paywalls yet.`);
68
+ }
69
+
70
+ //#endregion
71
+ export { findApplication as n, findProject as r, appNotFound as t };