@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
@@ -1,140 +0,0 @@
1
- import { o as API_HOST } from "./output-C4o2gJ1K.js";
2
- import { i as track } from "./telemetry-DeA1mvnT.js";
3
- import "./update-B2fWIc4q.js";
4
- import { i as loadSession, r as clearSession } from "./token-C0it-Xh7.js";
5
- import { t as defineCommand } from "./command-CMIz81Da.js";
6
- import "./ui-Dy0b-9L8.js";
7
- import { n as ensureSkillsCurrent } from "./skills-DPzlnfCK.js";
8
- import "./spawn-DSoTXy_j.js";
9
- import { a as onboardingHooks, n as performLogin, r as BROWSER_UNAVAILABLE, t as loginWithApiKey } from "./login-Do4wFuLv.js";
10
- import { t as scanProject } from "./scan-zKsddO72.js";
11
-
12
- //#region src/commands/account/auth.ts
13
- const runLogin = defineCommand({
14
- name: "login",
15
- output: "both",
16
- async run(ctx) {
17
- const { ui } = ctx;
18
- ui.intro("Superwall login");
19
- const apiKeyArg = ctx.argv.apiKey;
20
- if (apiKeyArg) {
21
- const spin$1 = ui.spinner();
22
- spin$1.start("Verifying your API key");
23
- try {
24
- const session = await loginWithApiKey(apiKeyArg);
25
- spin$1.stop("Logged in");
26
- track("login finished", {
27
- status: "success",
28
- method: "api_key"
29
- });
30
- if (ctx.json) return ctx.output.data(sessionOutput(session));
31
- ui.success(`Logged in with an API key${session.orgName ? ` · \`${session.orgName}\`` : ""}.`);
32
- ui.outro("You're all set - run `superwall integrate` to set up your app.");
33
- } catch (e) {
34
- spin$1.stop("Login failed");
35
- track("login finished", {
36
- status: "error",
37
- method: "api_key"
38
- });
39
- throw e;
40
- }
41
- return;
42
- }
43
- if (!ctx.interactive) throw new Error("Browser login requires an interactive terminal. Use `superwall login --api-key <key>`.");
44
- const hooks = onboardingHooks((await scanProject(ctx.installDir).catch(() => null))?.apps[0]);
45
- const spin = ui.spinner();
46
- try {
47
- const session = await performLogin({
48
- issuer: ctx.argv.host,
49
- clientId: ctx.argv.clientId,
50
- onVerify: ({ url, userCode, browserOpened }) => {
51
- ui.info(`Approve this login in your browser · code \`${userCode}\`\n${url}`);
52
- if (!browserOpened) ui.warn(BROWSER_UNAVAILABLE);
53
- spin.start("Waiting for you to approve in the browser");
54
- },
55
- onStatus: (m) => spin.message(m),
56
- onOnboard: async () => {
57
- const setup = await hooks.onOnboard();
58
- if (setup) spin.start("Creating your account");
59
- return setup;
60
- },
61
- onProvisioned: hooks.onProvisioned
62
- });
63
- spin.stop(`Logged in as \`${session.userEmail ?? "you"}\`${session.orgName ? ` · \`${session.orgName}\`` : ""}`);
64
- track("login finished", {
65
- status: "success",
66
- method: "oauth"
67
- });
68
- if (!ctx.json) await ensureSkillsCurrent(false, "login").catch(() => {});
69
- ui.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.");
70
- } catch (e) {
71
- spin.stop("Login failed");
72
- track("login finished", {
73
- status: "error",
74
- method: "oauth"
75
- });
76
- throw e;
77
- }
78
- }
79
- });
80
- const runLogout = defineCommand({
81
- name: "logout",
82
- output: "both",
83
- async run(ctx) {
84
- const s = loadSession();
85
- if (ctx.json) {
86
- clearSession();
87
- return ctx.output.data({
88
- loggedOut: Boolean(s),
89
- account: s ? sessionOutput(s) : null
90
- });
91
- }
92
- if (!s) return void ctx.ui.error("You aren't logged in yet.");
93
- if (ctx.interactive) {
94
- if (!await ctx.ui.confirm({ message: `Log out of Superwall${s.userEmail ? ` (\`${s.userEmail}\`)` : ""}?` })) return void ctx.ui.outro("Staying logged in.");
95
- }
96
- clearSession();
97
- ctx.ui.success(`Logged out${s.userEmail ? ` (${s.userEmail})` : ""}.`);
98
- }
99
- });
100
- const runWhoami = defineCommand({
101
- name: "whoami",
102
- output: "both",
103
- run(ctx) {
104
- const s = loadSession();
105
- if (!s) {
106
- if (ctx.json) return ctx.output.data({ authenticated: false });
107
- ctx.ui.error("You aren't logged in yet. Run `superwall login` to sign in.");
108
- return;
109
- }
110
- if (ctx.json) return ctx.output.data(sessionOutput(s));
111
- const credential = s.apiKey ? `API key sk_…${s.apiKey.slice(-4)}` : s.accessToken ? "OAuth session" : " - ";
112
- ctx.ui.list({ items: [{
113
- label: s.userEmail ?? "Logged in",
114
- meta: s.orgName ? `· ${s.orgName}` : void 0,
115
- children: [{
116
- label: credential,
117
- meta: effectiveHost(s)
118
- }]
119
- }] });
120
- }
121
- });
122
- function effectiveHost(session) {
123
- return process.env.SUPERWALL_API_HOST ?? session.host ?? API_HOST();
124
- }
125
- function sessionOutput(session) {
126
- return {
127
- authenticated: true,
128
- user: { email: session.userEmail ?? null },
129
- organization: {
130
- id: session.orgId ?? null,
131
- name: session.orgName ?? null,
132
- count: session.orgCount ?? 1
133
- },
134
- credential: { type: session.apiKey ? "api_key" : session.accessToken ? "oauth" : "unknown" },
135
- host: effectiveHost(session)
136
- };
137
- }
138
-
139
- //#endregion
140
- export { runLogin, runLogout, runWhoami };
@@ -1,80 +0,0 @@
1
- import { n as allDeps, r as readPackageJson } from "./scan-zKsddO72.js";
2
- import { readFileSync } from "node:fs";
3
- import fg from "fast-glob";
4
-
5
- //#region src/core/project/billing.ts
6
- const IGNORE = [
7
- "**/node_modules/**",
8
- "**/.git/**",
9
- "**/Pods/**",
10
- "**/build/**",
11
- "**/.build/**",
12
- "**/dist/**"
13
- ];
14
- function detectBilling(app) {
15
- const deps = allDeps(readPackageJson(app.path));
16
- const inDeps = (names) => names.some((n) => n in deps);
17
- let revenueCat = inDeps([
18
- "react-native-purchases",
19
- "@revenuecat/purchases-js",
20
- "purchases-capacitor",
21
- "purchases_flutter"
22
- ]);
23
- let adapty = inDeps(["react-native-adapty", "adapty_flutter"]);
24
- let qonversion = inDeps(["react-native-qonversion", "qonversion_flutter"]);
25
- const manifests = fg.sync([
26
- "**/Package.resolved",
27
- "**/Package.swift",
28
- "**/Project.swift",
29
- "**/Podfile",
30
- "**/Podfile.lock",
31
- "**/project.pbxproj",
32
- "**/*.gradle",
33
- "**/*.gradle.kts",
34
- "**/pubspec.yaml",
35
- "**/pubspec.lock"
36
- ], {
37
- cwd: app.path,
38
- ignore: IGNORE,
39
- absolute: true,
40
- deep: 5
41
- });
42
- for (const f of manifests) {
43
- let c;
44
- try {
45
- c = readFileSync(f, "utf8");
46
- } catch {
47
- continue;
48
- }
49
- if (/RevenueCat|\bPurchases\b/i.test(c)) revenueCat = true;
50
- if (/Adapty/i.test(c)) adapty = true;
51
- if (/Qonversion/i.test(c)) qonversion = true;
52
- }
53
- if (!revenueCat || !adapty || !qonversion) {
54
- const sources = fg.sync(["**/*.swift", "**/*.kt"], {
55
- cwd: app.path,
56
- ignore: IGNORE,
57
- absolute: true,
58
- deep: 6
59
- }).slice(0, 600);
60
- for (const f of sources) {
61
- let c;
62
- try {
63
- c = readFileSync(f, "utf8");
64
- } catch {
65
- continue;
66
- }
67
- if (/import RevenueCat|com\.revenuecat/.test(c)) revenueCat = true;
68
- if (/import Adapty|com\.adapty/.test(c)) adapty = true;
69
- if (/import Qonversion|com\.qonversion/.test(c)) qonversion = true;
70
- }
71
- }
72
- return {
73
- revenueCat,
74
- adapty,
75
- qonversion
76
- };
77
- }
78
-
79
- //#endregion
80
- export { detectBilling as t };
@@ -1,121 +0,0 @@
1
- import { r as ApiError } from "./command-CMIz81Da.js";
2
- import { h as listProjects } from "./resources-Bf9O1JNM.js";
3
- import { n as emitJson, t as apiCall } from "./api-output-aJNw7Syy.js";
4
- import { f as saveBundleId, i as RefusedByApi, r as pickScope, s as getBundleIdSuggestions } from "./scope-BvzD-kO4.js";
5
-
6
- //#region src/commands/resource/bundle-id.ts
7
- const noun = (platform) => platform === "android" ? "package name" : "bundle ID";
8
- const text = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
9
- function testModeExposure(chosen, candidates) {
10
- const exposed = candidates.filter((candidate) => candidate.production_devices > 0 && candidate.bundle_id !== chosen && !candidate.bundle_id.startsWith(`${chosen}.`));
11
- return {
12
- devices: exposed.reduce((sum, candidate) => sum + candidate.production_devices, 0),
13
- bundleIds: exposed.map((candidate) => candidate.bundle_id)
14
- };
15
- }
16
- async function suggestions(ctx, api, applicationId) {
17
- try {
18
- return await apiCall(ctx, "Reading what the SDK reported", () => getBundleIdSuggestions(api, applicationId));
19
- } catch (error) {
20
- if (error instanceof RefusedByApi) return null;
21
- throw error;
22
- }
23
- }
24
- function exposureLine(exposure, windowDays) {
25
- return `${exposure.devices} production device${exposure.devices === 1 ? "" : "s"} in the last ${windowDays} days used ${exposure.bundleIds.join(", ")}, and would run in test mode.`;
26
- }
27
- async function testModeWarning(ctx, api, applicationId, bundleId) {
28
- const read = await suggestions(ctx, api, applicationId);
29
- if (!read?.available) return void 0;
30
- const exposure = testModeExposure(bundleId, read.candidates);
31
- if (exposure.devices === 0) return void 0;
32
- return `Saving the bundle ID ${bundleId}: ${exposureLine(exposure, read.window_days)}`;
33
- }
34
- function candidateLine(candidate) {
35
- const seen = candidate.last_seen_at.slice(0, 10);
36
- const country = candidate.top_country ? `, mostly ${candidate.top_country}` : "";
37
- return `\`${candidate.bundle_id}\` ${candidate.production_devices} production, ${candidate.sandbox_devices} sandbox devices, last seen ${seen}${country}`;
38
- }
39
- async function runBundleId(ctx) {
40
- const { api } = ctx;
41
- const scope = await pickScope(ctx, api, true);
42
- const applicationId = scope.applicationId;
43
- if (!applicationId) throw new Error("No app found in this project. Pass --app <id>.");
44
- const platform = (scope.appPlatform ?? "").toLowerCase();
45
- if (platform !== "ios" && platform !== "android") throw new Error("Only iOS and Android apps have a bundle ID.");
46
- const saved = text((await listProjects(api)).flatMap((project) => project.applications ?? []).find((candidate) => String(candidate.id) === applicationId)?.bundle_id) ?? null;
47
- const name = scope.appName ?? applicationId;
48
- const wanted = text(ctx.argv.value);
49
- const read = await suggestions(ctx, api, applicationId);
50
- if (!wanted) {
51
- if (ctx.json) return emitJson(ctx, {
52
- application_id: applicationId,
53
- platform,
54
- bundle_id: saved,
55
- suggestions: read
56
- });
57
- ctx.ui.step(saved ? `\`${name}\` has the ${noun(platform)} \`${saved}\`` : `\`${name}\` has no ${noun(platform)} saved`);
58
- if (!read) return void ctx.ui.info("This Superwall API can't suggest one yet.");
59
- if (!read.available) return void ctx.ui.info("The SDK's reports couldn't be read just now.");
60
- if (read.candidates.length === 0) {
61
- ctx.ui.info(`The SDK reported no ${noun(platform)} in the last ${read.window_days} days.`);
62
- return;
63
- }
64
- ctx.ui.info(`What the SDK reported in the last ${read.window_days} days:`);
65
- for (const candidate of read.candidates) ctx.ui.info(candidateLine(candidate));
66
- return;
67
- }
68
- if (saved === wanted) {
69
- if (ctx.json) return emitJson(ctx, {
70
- application_id: applicationId,
71
- bundle_id: saved,
72
- changed: false
73
- });
74
- ctx.ui.success(`\`${name}\` already has the ${noun(platform)} \`${saved}\`.`);
75
- return;
76
- }
77
- const replacing = saved !== null;
78
- if (replacing && ctx.argv.replace !== true) throw new Error(`\`${name}\` already has the ${noun(platform)} ${saved}. Nothing was changed. Pass --replace to replace it with ${wanted}, once a person has agreed.`);
79
- const exposure = read?.available ? testModeExposure(wanted, read.candidates) : null;
80
- const consequences = [replacing ? `This replaces the ${noun(platform)} ${saved} with ${wanted}. Builds whose ${noun(platform)} is neither ${wanted} nor starts with "${wanted}." will run in test mode.` : void 0, exposure && exposure.devices > 0 ? exposureLine(exposure, read?.window_days ?? 30) : void 0].filter((line) => line !== void 0);
81
- if (ctx.dryRun) {
82
- if (ctx.json) return emitJson(ctx, {
83
- dryRun: true,
84
- application_id: applicationId,
85
- from: saved,
86
- to: wanted,
87
- test_mode: exposure
88
- });
89
- ctx.ui.info([`[dry-run] would save the ${noun(platform)} ${wanted} on ${name}.`, ...consequences].join("\n"));
90
- return;
91
- }
92
- if (consequences.length > 0 && ctx.argv.yes !== true) {
93
- if (!ctx.interactive) throw new Error(`${consequences.join("\n")}\nNothing was changed. This is a person's decision: once they agree, run it again with --yes.`);
94
- ctx.ui.warn(consequences.join("\n"));
95
- if (!await ctx.ui.confirm({ message: `Save ${wanted} as the ${noun(platform)}?` })) return void ctx.ui.warn("Cancelled. Nothing was changed.");
96
- }
97
- const appStoreId = text(ctx.argv["app-store-id"]);
98
- let result;
99
- try {
100
- result = await apiCall(ctx, `Saving the ${noun(platform)}`, () => saveBundleId(api, applicationId, {
101
- bundleId: wanted,
102
- ...appStoreId ? { appStoreId } : {},
103
- replace: replacing
104
- }));
105
- } catch (error) {
106
- if (error instanceof ApiError && error.status === 409) throw new Error(`${error.message} Nothing was changed. Pass --replace to replace it, once a person has agreed.`);
107
- throw error;
108
- }
109
- if (ctx.json) return emitJson(ctx, {
110
- application_id: applicationId,
111
- bundle_id: result.bundle_id,
112
- app_store_id: result.app_store_id,
113
- changed: true,
114
- previous: saved,
115
- test_mode: exposure
116
- });
117
- ctx.ui.success(`\`${name}\` now has the ${noun(platform)} \`${result.bundle_id}\`.`);
118
- }
119
-
120
- //#endregion
121
- export { testModeWarning as n, runBundleId as t };
@@ -1,301 +0,0 @@
1
- import { i as writeJson, n as createCommandOutput, o as API_HOST, w as isNonInteractive } from "./output-C4o2gJ1K.js";
2
- import { i as track, n as maybeShowTelemetryNotice } from "./telemetry-DeA1mvnT.js";
3
- import { a as refreshUpdateCheck, i as maybeNotifyUpdate } from "./update-B2fWIc4q.js";
4
- import { a as saveSession, i as loadSession, n as resolveAuthToken, o as NotLoggedInError } from "./token-C0it-Xh7.js";
5
- import { r as useRenderer, t as selectRenderer } from "./ui-Dy0b-9L8.js";
6
- import pc from "picocolors";
7
- import { resolve } from "node:path";
8
-
9
- //#region src/core/api/client.ts
10
- const BODY_SNIPPET = 200;
11
- function parseErrorEnvelope(body) {
12
- let parsed;
13
- try {
14
- parsed = JSON.parse(body);
15
- } catch {
16
- return;
17
- }
18
- if (typeof parsed !== "object" || parsed === null) return void 0;
19
- const text = (key) => {
20
- const value = Reflect.get(parsed, key);
21
- return typeof value === "string" && value !== "" ? value : void 0;
22
- };
23
- const message = text("message");
24
- if (message === void 0) return void 0;
25
- return {
26
- message,
27
- detail: {
28
- type: text("type"),
29
- code: text("code"),
30
- param: text("param"),
31
- docUrl: text("doc_url"),
32
- resourceType: text("resource_type"),
33
- resourceId: text("resource_id")
34
- }
35
- };
36
- }
37
- var ApiError = class extends Error {
38
- detail;
39
- request;
40
- envelope;
41
- hint;
42
- constructor(request, status, body) {
43
- const envelope = body === void 0 ? void 0 : parseErrorEnvelope(body);
44
- const snippet = body?.trim().slice(0, BODY_SNIPPET);
45
- super(envelope?.message ?? (snippet ? `HTTP ${status} — ${snippet}` : `HTTP ${status}`));
46
- this.status = status;
47
- this.body = body;
48
- this.detail = envelope?.detail ?? {};
49
- this.request = request;
50
- this.envelope = envelope !== void 0;
51
- }
52
- };
53
- var ApiUnreachableError = class extends Error {
54
- constructor(host, cause) {
55
- const local = /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])/.test(host);
56
- super(`Couldn't reach the Superwall API at ${host}.\n` + (local ? " That's a local address — start the API, or unset SUPERWALL_API_HOST to use production." : " Check your network or proxy, then try again."));
57
- this.name = "ApiUnreachableError";
58
- this.cause = cause;
59
- }
60
- };
61
- const PAGE_LIMIT = 50;
62
- const createSuperwallApi = (initial) => {
63
- let session = initial;
64
- const host = () => process.env.SUPERWALL_API_HOST ?? session.host ?? API_HOST();
65
- const send = async (url, init) => {
66
- try {
67
- return await fetch(url, init);
68
- } catch (error) {
69
- throw new ApiUnreachableError(host(), error);
70
- }
71
- };
72
- const authorized = async () => {
73
- const resolved = await resolveAuthToken(session);
74
- session = resolved.session;
75
- return resolved.token;
76
- };
77
- const request = async (method, path, body, options = {}) => {
78
- const token = await authorized();
79
- const res = await send(`${host()}${path}`, {
80
- method,
81
- headers: {
82
- ...options.headers,
83
- authorization: `Bearer ${token}`,
84
- accept: "application/json",
85
- ...body !== void 0 ? { "content-type": "application/json" } : {}
86
- },
87
- ...body !== void 0 ? { body: JSON.stringify(body) } : {}
88
- });
89
- if (!res.ok) {
90
- const text = await res.text().catch(() => "");
91
- throw new ApiError(`${method} ${path}`, res.status, text);
92
- }
93
- if (res.status === 204) return void 0;
94
- return await res.json();
95
- };
96
- const api = {
97
- get org() {
98
- const override = process.env.SUPERWALL_ORG_ID;
99
- return {
100
- id: override ?? session.orgId,
101
- name: override ? void 0 : session.orgName,
102
- count: session.orgCount ?? 1
103
- };
104
- },
105
- get userEmail() {
106
- return session.userEmail;
107
- },
108
- get host() {
109
- return host();
110
- },
111
- setOrg(org) {
112
- session = {
113
- ...session,
114
- orgId: org.id,
115
- orgName: org.name
116
- };
117
- saveSession(session);
118
- },
119
- get: (path, options) => request("GET", path, void 0, options),
120
- post: (path, body, options) => request("POST", path, body, options),
121
- put: (path, body, options) => request("PUT", path, body, options),
122
- patch: (path, body, options) => request("PATCH", path, body, options),
123
- del: (path, options) => request("DELETE", path, void 0, options),
124
- async postText(path, body) {
125
- const token = await authorized();
126
- const res = await send(`${host()}${path}`, {
127
- method: "POST",
128
- headers: {
129
- authorization: `Bearer ${token}`,
130
- accept: "text/plain",
131
- "content-type": "text/plain; charset=utf-8"
132
- },
133
- body
134
- });
135
- if (!res.ok) {
136
- const text = await res.text().catch(() => "");
137
- throw new ApiError(`POST ${path}`, res.status, text);
138
- }
139
- return res.text();
140
- },
141
- async list(path) {
142
- const out = [];
143
- let after;
144
- for (let page = 0; page < PAGE_LIMIT; page++) {
145
- const url = `${path}${path.includes("?") ? "&" : "?"}limit=100${after ? `&starting_after=${after}` : ""}`;
146
- const batch = await api.get(url);
147
- out.push(...batch.data);
148
- if (!batch.has_more || batch.data.length === 0) break;
149
- const last = batch.data[batch.data.length - 1];
150
- if (last?.id == null) break;
151
- after = String(last.id);
152
- }
153
- return out;
154
- }
155
- };
156
- return api;
157
- };
158
- const superwallApi = () => {
159
- const session = loadSession();
160
- if (!session) throw new NotLoggedInError();
161
- return createSuperwallApi(session);
162
- };
163
-
164
- //#endregion
165
- //#region src/command.ts
166
- function defineCommand(definition) {
167
- const command = (argv) => executeCommand(definition, argv);
168
- command.definition = definition;
169
- return command;
170
- }
171
- async function executeCommand(definition, argv, runtime = {}) {
172
- const json = Boolean(argv.json);
173
- const environmentNonInteractive = runtime.nonInteractive ?? isNonInteractive();
174
- const explicitNonInteractive = argv.interactive === false;
175
- const outputMode = json ? "json" : environmentNonInteractive ? "text" : "rich";
176
- const interactive = definition.interaction !== "none" && !json && !explicitNonInteractive && !environmentNonInteractive;
177
- const installDir = resolve(argv.installDir ?? process.cwd());
178
- const ui = runtime.renderer ? useRenderer(runtime.renderer(outputMode)) : selectRenderer({ mode: outputMode });
179
- const stdout = runtime.stdout ?? process.stdout;
180
- const output = createCommandOutput(outputMode, ui, { stdout });
181
- if (json && definition.output !== "json" && definition.output !== "both") {
182
- writeJson(stdout, { error: {
183
- code: "json_not_supported",
184
- message: `${definition.name} does not support --json.`
185
- } });
186
- process.exitCode = 1;
187
- return;
188
- }
189
- const startedAt = Date.now();
190
- const base = commandTelemetry(definition, argv, {
191
- json,
192
- interactive
193
- });
194
- ui.start();
195
- const offInterrupt = ui.onInterrupt?.(() => {
196
- ui.stop();
197
- process.stderr.write("\n✗ Cancelled.\n");
198
- process.exit(130);
199
- });
200
- if (outputMode === "rich") maybeShowTelemetryNotice(ui);
201
- track("command started", base);
202
- try {
203
- const api = resolveApi(definition.auth ?? "none", runtime.api ?? superwallApi);
204
- if (definition.auth && definition.auth !== "none") base.logged_in = api !== void 0;
205
- const context = {
206
- argv,
207
- ui,
208
- output,
209
- outputMode,
210
- interactive,
211
- installDir,
212
- json,
213
- dryRun: Boolean(argv.dryRun),
214
- ...api ? { api } : {}
215
- };
216
- await definition.run(context);
217
- track("command finished", {
218
- ...base,
219
- status: "success",
220
- duration_ms: Date.now() - startedAt
221
- });
222
- } catch (error) {
223
- reportError(ui, outputMode, stdout, error);
224
- process.exitCode = 1;
225
- const { code, status } = normalizeError(error);
226
- track("command finished", {
227
- ...base,
228
- status: "error",
229
- error_code: code,
230
- ...status === void 0 ? {} : { http_status: status },
231
- duration_ms: Date.now() - startedAt
232
- });
233
- } finally {
234
- offInterrupt?.();
235
- if (outputMode !== "json") refreshUpdateCheck();
236
- if (outputMode === "rich" && runtime.waitForPaint !== false) await new Promise((done) => setTimeout(done, 50));
237
- ui.stop();
238
- if (outputMode !== "json" && definition.name !== "upgrade") maybeNotifyUpdate(stdout);
239
- }
240
- }
241
- const BARE_WORD = /^[a-z][a-z-]{0,31}$/;
242
- function commandTelemetry(definition, argv, flags) {
243
- const subcommand = [argv.target, argv.action].map((value) => typeof value === "string" ? value : void 0).filter((value) => value !== void 0 && BARE_WORD.test(value));
244
- return {
245
- command: definition.name,
246
- ...subcommand.length === 0 ? {} : { subcommand: subcommand.join(" ") },
247
- auth: definition.auth ?? "none",
248
- json: flags.json,
249
- prompts: flags.interactive,
250
- dry_run: Boolean(argv.dryRun),
251
- skill: argv.skill === true
252
- };
253
- }
254
- function resolveApi(policy, factory) {
255
- if (policy === "required") return factory();
256
- if (policy === "optional") try {
257
- return factory();
258
- } catch (error) {
259
- if (error instanceof NotLoggedInError) return void 0;
260
- throw error;
261
- }
262
- }
263
- function reportError(ui, mode, stdout, error) {
264
- const { code, message, status } = normalizeError(error);
265
- if (mode === "json") {
266
- writeJson(stdout, { error: {
267
- code,
268
- message,
269
- ...status === void 0 ? {} : { status }
270
- } });
271
- return;
272
- }
273
- ui.error([message, ...errorAside(error)].join("\n"));
274
- }
275
- function errorAside(error) {
276
- const aside = [];
277
- if (error instanceof ApiError) {
278
- if (error.hint) aside.push(error.hint);
279
- if (error.detail.docUrl) aside.push(error.detail.docUrl);
280
- if (!error.envelope) aside.push(error.request);
281
- }
282
- return aside.map((line) => pc.dim(line));
283
- }
284
- function normalizeError(error) {
285
- if (error instanceof NotLoggedInError) return {
286
- code: "not_logged_in",
287
- message: "You aren't logged in. Run `superwall login` first."
288
- };
289
- if (error instanceof ApiError) return {
290
- code: "api_error",
291
- message: error.message,
292
- status: error.status
293
- };
294
- return {
295
- code: "command_error",
296
- message: error instanceof Error ? error.message : String(error)
297
- };
298
- }
299
-
300
- //#endregion
301
- export { superwallApi as a, createSuperwallApi as i, executeCommand as n, ApiError as r, defineCommand as t };
@@ -1,22 +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 "./command-CMIz81Da.js";
6
- import "./ui-Dy0b-9L8.js";
7
- import "./skills-DPzlnfCK.js";
8
- import "./spawn-DSoTXy_j.js";
9
- import "./login-Do4wFuLv.js";
10
- import "./scan-zKsddO72.js";
11
- import "./hosted-CXe9TrWx.js";
12
- import "./spinner-TWa0hia6.js";
13
- import "./resources-Bf9O1JNM.js";
14
- import "./selection-CxZoX4NT.js";
15
- import "./org-sj7uyvp-.js";
16
- import "./bind-YrJvuRF9.js";
17
- import "./pipeline-BqzqZhX1.js";
18
- import "./actions-B7ym3oVS.js";
19
- import "./app-DH6U8yuI.js";
20
- import { t as runDev } from "./dev-DmB3XqaJ.js";
21
-
22
- export { runDev };