@superwall/cli 1.7.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/README.md +192 -52
  2. package/dist/{setup-Bxj22rYi.js → apple-CSzNTGHM.js} +82 -76
  3. package/dist/auth.d.ts +4 -19
  4. package/dist/auth.js +4 -2
  5. package/dist/{actions-B7ym3oVS.js → billing-C3Q8DBU2.js} +98 -28
  6. package/dist/{bind-YrJvuRF9.js → bind-BumHTi9O.js} +38 -33
  7. package/dist/{build-DLoCW5Ri.js → build-Bpviiclc.js} +20 -26
  8. package/dist/client-BL0f_yGf.js +176 -0
  9. package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
  10. package/dist/config-BO1Y87kV.js +105 -0
  11. package/dist/create-BSfvpWoD.js +19 -0
  12. package/dist/{create-pkANt1Gs.js → create-BUcVG4Ab.js} +195 -169
  13. package/dist/{notification-url-DuKF2659.js → create-CfK3PeKA.js} +235 -539
  14. package/dist/doctor-BWqIYcMn.js +83 -0
  15. package/dist/{drivers-Qx9LxmRN.js → drivers-CPhdPkW5.js} +185 -172
  16. package/dist/entry.d.ts +0 -5
  17. package/dist/entry.js +28072 -1134
  18. package/dist/environment-eBXjELoN.js +58 -0
  19. package/dist/{existing-AVEfZu2A.js → existing-BltvQiX5.js} +12 -6
  20. package/dist/held-CPve03KJ.js +16 -0
  21. package/dist/held-DgnTFMl3.js +1112 -0
  22. package/dist/input-vi0bou04.js +42 -0
  23. package/dist/{integrate-brmhPG-S.js → integrate-BRsqoe01.js} +277 -254
  24. package/dist/log-NVhVe_oe.js +62 -0
  25. package/dist/login-BCEH5q0U.js +53 -0
  26. package/dist/login-BPOONe7n.js +16 -0
  27. package/dist/{login-Do4wFuLv.js → login-BbTIrCFT.js} +118 -55
  28. package/dist/lookup-rr1AkCJA.js +71 -0
  29. package/dist/migrate-C9X2Vz81.js +274 -0
  30. package/dist/notification-url-CV86qiKP.js +100 -0
  31. package/dist/{open-studio-DOw-6ydc.js → open-CcpXotHG.js} +34 -43
  32. package/dist/org-BQQDo7wm.js +35 -0
  33. package/dist/output-Ggzq5_-t.js +122 -0
  34. package/dist/paths-CRlU72cq.js +29 -0
  35. package/dist/playbook-DVMXN7fh.js +53 -0
  36. package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
  37. package/dist/promote-Da8xctzy.js +91 -0
  38. package/dist/push-BV-grvQg.js +22 -0
  39. package/dist/push-D6R9icWN.js +495 -0
  40. package/dist/registry-BYVD-_h6.js +10385 -0
  41. package/dist/{reports-CfJqoava.js → reports-D_qbl7_u.js} +7 -6
  42. package/dist/{resources-Bf9O1JNM.js → resources-DLON3-61.js} +162 -55
  43. package/dist/{run-DsVZ5snL.js → run-Co-BwhOg.js} +16 -22
  44. package/dist/scan-B88OlWOt.js +4 -0
  45. package/dist/{scan-zKsddO72.js → scan-CKuk-_6W.js} +48 -37
  46. package/dist/scope-DV22_Ufm.js +198 -0
  47. package/dist/screenshot-file-tVBfUEIi.js +16 -0
  48. package/dist/{selection-CxZoX4NT.js → selection-C2_KbLuo.js} +100 -51
  49. package/dist/server-C4f6ccUr.js +22 -0
  50. package/dist/{dev-DmB3XqaJ.js → server-D0d2oP-5.js} +86 -94
  51. package/dist/session-B-Uz0cQ7.js +40 -0
  52. package/dist/session-BuvArt1j.js +6 -0
  53. package/dist/session-C4rbE3VS.js +796 -0
  54. package/dist/skills/animate-onboarding/SKILL.md +467 -0
  55. package/dist/skills/animate-onboarding/references/engine.md +494 -0
  56. package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
  57. package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
  58. package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
  59. package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
  60. package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  61. package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
  62. package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
  63. package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  64. package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
  65. package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
  66. package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
  67. package/dist/skills/animate-onboarding/references/performance.md +41 -0
  68. package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
  69. package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  70. package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  71. package/dist/skills/index.json +37 -0
  72. package/dist/skills/mobile-design/SKILL.md +447 -0
  73. package/dist/skills/mobile-design/references/responsive.md +162 -0
  74. package/dist/skills/onboarding-questions/SKILL.md +231 -0
  75. package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
  76. package/dist/skills/onboarding-questions/references/craft.md +142 -0
  77. package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
  78. package/dist/skills/superwall/SKILL.md +82 -9
  79. package/dist/skills/superwall/references/api.md +153 -37
  80. package/dist/skills/superwall/references/apple-setup.md +316 -0
  81. package/dist/skills/superwall/references/asc.md +74 -38
  82. package/dist/skills/superwall/references/data-analytics.md +55 -21
  83. package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
  84. package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
  85. package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
  86. package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
  87. package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
  88. package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
  89. package/dist/skills/superwall/workflows/placements/android.md +2 -2
  90. package/dist/skills/superwall/workflows/placements/expo.md +2 -2
  91. package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
  92. package/dist/skills/superwall/workflows/placements/ios.md +2 -2
  93. package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
  94. package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
  95. package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
  96. package/dist/skills/superwall/workflows/review/playbook.md +1 -1
  97. package/dist/skills/superwall-editor/SKILL.md +61 -0
  98. package/dist/skills/superwall-editor/references/cli.md +135 -0
  99. package/dist/skills/superwall-editor/references/design.md +51 -0
  100. package/dist/skills/superwall-editor/references/native-elements.md +171 -0
  101. package/dist/skills/superwall-editor/references/workflow.md +65 -0
  102. package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
  103. package/dist/skills/superwall-framework/SKILL.md +85 -31
  104. package/dist/skills/superwall-framework/references/cli.md +58 -27
  105. package/dist/skills/superwall-framework/references/examples.md +4 -3
  106. package/dist/skills/superwall-framework/references/layout.md +64 -9
  107. package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
  108. package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
  109. package/dist/skills/wwdc/SKILL.md +22 -0
  110. package/dist/skills/wwdc/references/docs.md +52 -0
  111. package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
  112. package/dist/skills-CLGJuMnF.js +14 -0
  113. package/dist/{skills-DPzlnfCK.js → skills-CZcpnEnG.js} +100 -122
  114. package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
  115. package/dist/spinner-C2U6QBJ9.js +294 -0
  116. package/dist/storage-6h9vyiAz.js +31 -0
  117. package/dist/storage-CerJ5KLP.d.ts +16 -0
  118. package/dist/storekit-CK9JmM2D.js +16 -0
  119. package/dist/storekit-CinJra3V.js +47 -0
  120. package/dist/telemetry-DKyDhURo.js +56 -0
  121. package/dist/theme-DUsCh-Vd.js +25 -0
  122. package/dist/timing-BVxPrYq3.js +5 -0
  123. package/dist/{token-C0it-Xh7.js → token-DaxQgQkv.js} +6 -38
  124. package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
  125. package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
  126. package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
  127. package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
  128. package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
  129. package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
  130. package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  131. package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
  132. package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
  133. package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  134. package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
  135. package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
  136. package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
  137. package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
  138. package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
  139. package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  140. package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  141. package/dist/tools-skills/mobile-design/SKILL.md +447 -0
  142. package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
  143. package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
  144. package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
  145. package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
  146. package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
  147. package/dist/tools-skills/superwall/SKILL.md +263 -0
  148. package/dist/tools-skills/superwall/references/api.md +303 -0
  149. package/dist/tools-skills/superwall/references/asa.md +166 -0
  150. package/dist/tools-skills/superwall/references/asc.md +95 -0
  151. package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
  152. package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
  153. package/dist/tools-skills/superwall/references/docs.md +51 -0
  154. package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
  155. package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
  156. package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
  157. package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
  158. package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
  159. package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
  160. package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
  161. package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
  162. package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
  163. package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
  164. package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
  165. package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
  166. package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
  167. package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
  168. package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
  169. package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
  170. package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
  171. package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
  172. package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
  173. package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
  174. package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
  175. package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
  176. package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
  177. package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
  178. package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
  179. package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
  180. package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
  181. package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
  182. package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
  183. package/dist/tools-skills/superwall-editor/references/design.md +51 -0
  184. package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
  185. package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
  186. package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
  187. package/dist/tools-skills/wwdc/SKILL.md +22 -0
  188. package/dist/tools-skills/wwdc/references/docs.md +52 -0
  189. package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
  190. package/dist/tools.d.ts +96 -0
  191. package/dist/tools.js +11360 -0
  192. package/dist/ui-D_qf3Gvw.js +53 -0
  193. package/dist/upgrade-DPo0a4Es.js +117 -0
  194. package/dist/upgrade-ffseQDMx.js +7 -0
  195. package/package.json +10 -5
  196. package/dist/api-CZzirVMj.js +0 -151
  197. package/dist/api-output-aJNw7Syy.js +0 -20
  198. package/dist/app-DH6U8yuI.js +0 -190
  199. package/dist/asa-C-sQzPPn.js +0 -1194
  200. package/dist/asc-1ZBJ6DwS.js +0 -778
  201. package/dist/auth-YRhlV3DE.js +0 -140
  202. package/dist/billing-CCYHdApx.js +0 -80
  203. package/dist/bundle-id-CKxl_026.js +0 -121
  204. package/dist/command-CMIz81Da.js +0 -301
  205. package/dist/dev-DZy6pOnB.js +0 -22
  206. package/dist/doctor-H-hf-Yww.js +0 -88
  207. package/dist/feedback-CKf-rpBW.js +0 -152
  208. package/dist/hosted-CXe9TrWx.js +0 -32
  209. package/dist/migrate-C9ERDR6y.js +0 -284
  210. package/dist/org-sj7uyvp-.js +0 -40
  211. package/dist/output-C4o2gJ1K.js +0 -146
  212. package/dist/params-l3CrvRtR.js +0 -51
  213. package/dist/pipeline-BqzqZhX1.js +0 -977
  214. package/dist/print-skill-ZojRSybs.js +0 -74
  215. package/dist/promote-BG8X4Nv_.js +0 -88
  216. package/dist/publish-sxLh-G4G.js +0 -35
  217. package/dist/push-bQ6Vxtg8.js +0 -35
  218. package/dist/query-_FbybaH-.js +0 -53
  219. package/dist/resource-CGIwSd29.js +0 -323
  220. package/dist/revenue-provider-ebsRINY8.js +0 -100
  221. package/dist/scope-BvzD-kO4.js +0 -223
  222. package/dist/skills-D_R-lEsK.js +0 -64
  223. package/dist/spinner-TWa0hia6.js +0 -18
  224. package/dist/storekit-Cj9Cpjcz.js +0 -29
  225. package/dist/telemetry-DeA1mvnT.js +0 -169
  226. package/dist/ui-Dy0b-9L8.js +0 -27738
  227. package/dist/update-B2fWIc4q.js +0 -59
  228. package/dist/upgrade-BmzkTKrh.js +0 -72
  229. /package/dist/{devtools-8EgLo86w.js → devtools-pBl_vt03.js} +0 -0
@@ -1,977 +0,0 @@
1
- import { S as apiKeyFromEnv, o as API_HOST, p as ENV_API_KEY, x as VERSION } from "./output-C4o2gJ1K.js";
2
- import { i as loadSession } from "./token-C0it-Xh7.js";
3
- import { i as createSuperwallApi, r as ApiError } from "./command-CMIz81Da.js";
4
- import { n as ui } from "./ui-Dy0b-9L8.js";
5
- import { D as versionProducts, S as promotePaywallVersion, _ as livePaywall, a as createHeadlessPaywall, b as platformLabel, d as linkSourceCommit, f as listAppPaywalls, h as listProjects, p as listApplications, w as pushPaywallVersion, y as mintSourceAccess } from "./resources-Bf9O1JNM.js";
6
- import { A as assetBaseUrl, C as writeApp, D as writeSnapshot, M as syncAssets, O as frameworkVersion, S as removeBinding, T as writeBindings, _ as collectProjectDeclarations, a as requireClean, c as BIND_VERB, d as pendingPromoteWarning, f as pushedLine, g as weight, h as transition, j as requireAssets, k as loadFramework, m as took, o as requireProject, p as resolveNote, r as projectDir, s as selectSurfaces, t as needsWork, u as kb, v as writeProjectTypes, w as writeBinding, x as readLock, y as describeBindings } from "./selection-CxZoX4NT.js";
7
- import { r as performLoginWithUi } from "./app-DH6U8yuI.js";
8
- import pc from "picocolors";
9
- import * as path from "node:path";
10
- import { resolve } from "node:path";
11
- import * as os$1 from "node:os";
12
- import { cpus } from "node:os";
13
- import { promisify } from "node:util";
14
- import * as fs from "node:fs";
15
- import { globSync, statSync } from "node:fs";
16
- import { execFile } from "node:child_process";
17
- import fg from "fast-glob";
18
- import { productVariables } from "@superwall/studio/products";
19
-
20
- //#region src/core/paywalls/binding/apps.ts
21
- const PLATFORMS = [
22
- "ios",
23
- "android",
24
- "web"
25
- ];
26
- var AppBindingError = class extends Error {};
27
- const platformOf = (app) => {
28
- const normalized = (app.platform ?? "").toLowerCase();
29
- return PLATFORMS.find((platform) => platform === normalized);
30
- };
31
- function requirePlatform(app) {
32
- const platform = platformOf(app);
33
- if (platform !== void 0) return platform;
34
- throw new AppBindingError(`\`${app.name ?? app.id}\` is a ${platformLabel(app.platform)} app on Superwall, and Superwall for Agents pushes to ${PLATFORMS.join(", ")} apps only.`);
35
- }
36
- const platformFor = (apps, value) => {
37
- if (value in apps) return value;
38
- return Object.entries(apps).find(([, id]) => id === value)?.[0];
39
- };
40
- function describePlatforms(apps) {
41
- return Object.keys(apps).join(", ");
42
- }
43
- async function resolveApps(input) {
44
- const { api, superwallDir } = input;
45
- let cached;
46
- const known = () => cached ??= listApplications(api);
47
- const current = () => readLock(superwallDir).apps;
48
- for (const platform of new Set(input.wanted ?? [])) {
49
- if (!PLATFORMS.some((known$1) => known$1 === platform)) throw new AppBindingError(`"${platform}" is not a platform — use one of ${PLATFORMS.join(", ")}.`);
50
- if (platform in current()) continue;
51
- const bound = new Set(Object.values(current()));
52
- const candidates = (await known()).filter((app) => !bound.has(String(app.id)) && platformOf(app) === platform);
53
- const only = candidates.length === 1 ? candidates[0] : void 0;
54
- if (only) {
55
- writeApp(superwallDir, platform, String(only.id));
56
- continue;
57
- }
58
- const picked = candidates.length > 1 && input.pickApplication ? await input.pickApplication(candidates, platform) : null;
59
- if (picked) {
60
- writeApp(superwallDir, platform, String(picked.id));
61
- continue;
62
- }
63
- const label = platformLabel(platform);
64
- throw new AppBindingError(candidates.length === 0 ? `Your account has no ${label} app to bind — create one with \`superwall apps create --platform ${platform}\` or in the dashboard, then push again.` : `Several ${label} apps in your account — run \`superwall push\` interactively once to pick one, or add "${platform}": "<app id>" under "apps" in superwall.lock (\`superwall apps list\` shows ids).`);
65
- }
66
- if (Object.keys(current()).length > 0) return current();
67
- const apps = await known();
68
- if (apps.length === 1 && apps[0] !== void 0) {
69
- writeApp(superwallDir, requirePlatform(apps[0]), String(apps[0].id));
70
- return current();
71
- }
72
- if (apps.length > 1 && input.pickApplication) {
73
- const picked = await input.pickApplication(apps);
74
- if (picked) {
75
- writeApp(superwallDir, requirePlatform(picked), String(picked.id));
76
- return current();
77
- }
78
- }
79
- throw new AppBindingError(apps.length === 0 ? "Your account has no apps yet — create one with `superwall apps create` or in the dashboard." : "Several apps in your account — run `superwall push` interactively once to pick one; the choice is saved to superwall.lock.");
80
- }
81
-
82
- //#endregion
83
- //#region src/core/paywalls/project/scaffold.ts
84
- const REACT_VERSION = "19.1.0";
85
- function projectPackageName(root) {
86
- const name = path.basename(root).toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^[-._]+|[-._]+$/g, "");
87
- return name === "" || name === "superwall" ? "superwall-project" : name;
88
- }
89
- function packageJson(name, frameworkVersion$1) {
90
- return `${JSON.stringify({
91
- name,
92
- private: true,
93
- type: "module",
94
- scripts: {
95
- dev: "superwall dev",
96
- push: "superwall push",
97
- promote: "superwall promote",
98
- ship: "superwall publish"
99
- },
100
- dependencies: {
101
- react: REACT_VERSION,
102
- "react-dom": REACT_VERSION,
103
- superwall: frameworkVersion$1 === "unknown" ? "*" : `^${frameworkVersion$1}`
104
- }
105
- }, null, 2)}\n`;
106
- }
107
- const GITIGNORE = `node_modules/
108
- .superwall
109
- .env
110
- `;
111
- function writeIfAbsent(file, content) {
112
- if (fs.existsSync(file)) return;
113
- try {
114
- fs.writeFileSync(file, content, { flag: "wx" });
115
- } catch {
116
- return;
117
- }
118
- }
119
- function writeProjectScaffold(options) {
120
- writeIfAbsent(path.join(options.superwallDir, "package.json"), packageJson(projectPackageName(options.root), options.frameworkVersion));
121
- writeIfAbsent(path.join(options.superwallDir, ".gitignore"), GITIGNORE);
122
- }
123
-
124
- //#endregion
125
- //#region src/core/paywalls/project/session.ts
126
- var LoginRequiredError = class extends Error {
127
- constructor() {
128
- super(`Pushing paywalls needs a Superwall account.
129
- Interactively: run \`superwall login\`.
130
- In CI or an agent: set ${ENV_API_KEY} to an org API key (sk_…).`);
131
- this.name = "LoginRequiredError";
132
- }
133
- };
134
- async function requireApi(interactive) {
135
- const apiKey = apiKeyFromEnv();
136
- if (apiKey) return createSuperwallApi({
137
- authMethod: "api_key",
138
- apiKey,
139
- host: process.env.SUPERWALL_API_HOST ?? API_HOST(),
140
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
141
- });
142
- const session = loadSession();
143
- if (session) return createSuperwallApi(session);
144
- if (!interactive) throw new LoginRequiredError();
145
- ui.info("You're not signed in to Superwall yet — let's fix that.");
146
- const signedIn = await performLoginWithUi();
147
- if (!signedIn) throw new LoginRequiredError();
148
- return createSuperwallApi(signedIn);
149
- }
150
-
151
- //#endregion
152
- //#region src/core/paywalls/binding/binding.ts
153
- var BindingError = class extends Error {};
154
- const describe = (surface) => `${surface.kind} \`${surface.id}\``;
155
- const humanize = (surfaceId) => surfaceId.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
156
- async function resolveBinding(input) {
157
- const { api, superwallDir, surface, app } = input;
158
- const { platform, applicationId } = app;
159
- const create = input.create ?? true;
160
- const lock = readLock(superwallDir);
161
- const section = surface.kind === "paywall" ? lock.paywalls : lock.funnels;
162
- const locked = section[surface.id]?.[platform];
163
- if (locked) return {
164
- paywallId: locked.paywallId,
165
- applicationId,
166
- platform,
167
- source: "lock"
168
- };
169
- const matches = (paywalls) => {
170
- const headless = paywalls.filter((paywall) => paywall.metadata.headless === "true");
171
- return headless.find((paywall) => paywall.metadata.headlessSurface === surface.id) ?? headless.find((paywall) => paywall.identifier === surface.id);
172
- };
173
- const match = matches(await listAppPaywalls(api, applicationId));
174
- if (match) {
175
- writeBinding(superwallDir, surface.kind, surface.id, platform, { paywallId: match.id });
176
- return {
177
- paywallId: match.id,
178
- applicationId,
179
- platform,
180
- source: "matched"
181
- };
182
- }
183
- if (!create) throw new BindingError(`${describe(surface)} has never been pushed to \`${platform}\` — run \`superwall push\` first.`);
184
- if (!input.renamesResolved) {
185
- const onDisk = new Set(input.surfaces.filter((candidate) => candidate.kind === surface.kind).map((c) => c.id));
186
- const orphans = Object.keys(section).filter((id) => !onDisk.has(id));
187
- if (orphans.length > 0) throw new BindingError(`\`${surface.id}\` is unbound while superwall.lock still binds ${orphans.join(", ")}, which no longer exist on disk. Resolve the renames first — \`superwall push\` asks, or declare them with \`--rename <old>=<new>\`.`);
188
- }
189
- const archived = matches(await listAppPaywalls(api, applicationId, { archived: true }));
190
- if (archived) throw new BindingError(`${describe(surface)} matches archived paywall ${archived.id} on \`${platform}\`. Restore it in the dashboard to push to it, or rename the directory.`);
191
- const created = await createHeadlessPaywall(api, {
192
- applicationId,
193
- name: input.name?.trim() || humanize(surface.id),
194
- identifier: surface.id
195
- });
196
- writeBinding(superwallDir, surface.kind, surface.id, platform, { paywallId: created.id });
197
- return {
198
- paywallId: created.id,
199
- applicationId,
200
- platform,
201
- source: "created"
202
- };
203
- }
204
-
205
- //#endregion
206
- //#region src/core/paywalls/binding/targets.ts
207
- var TargetError = class extends Error {};
208
- const surfaceKey = (surface) => `${surface.kind}/${surface.id}`;
209
- const targetLabel = (target, multi) => multi ? `${target.surface.id} · ${target.platform}` : target.surface.id;
210
- function wantedPlatforms(surfaces, declared) {
211
- const wanted = /* @__PURE__ */ new Set();
212
- for (const surface of surfaces) for (const platform of declared[surfaceKey(surface)] ?? []) wanted.add(platform);
213
- return [...wanted];
214
- }
215
- function parsePlatformFlags(value) {
216
- return (Array.isArray(value) ? value : value === void 0 ? [] : [value]).flatMap((entry) => typeof entry === "string" ? entry.split(",") : []).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
217
- }
218
- function planTargets(input) {
219
- const { surfaces, declared, apps } = input;
220
- const known = Object.keys(apps);
221
- const only = (input.only ?? []).map((entry) => {
222
- const platform = platformFor(apps, entry);
223
- if (platform === void 0) throw new TargetError(`This project has no app for "${entry}" — its platforms are ${describePlatforms(apps) || "none"} (the keys under \`apps\` in superwall.lock). Declare it in a config.ts with \`platforms: [...]\` to bind one.`);
224
- return platform;
225
- });
226
- const targets = [];
227
- for (const surface of surfaces) {
228
- const wanted = declared[surfaceKey(surface)];
229
- let platforms;
230
- if (wanted !== void 0) {
231
- if (wanted.length === 0) throw new TargetError(`${surface.kind} \`${surface.id}\` declares \`platforms: []\` — list at least one, or remove the field.`);
232
- for (const platform of wanted) if (!(platform in apps)) throw new TargetError(`${surface.kind} \`${surface.id}\` targets \`${platform}\`, which superwall.lock does not bind to an app.`);
233
- platforms = [...new Set(wanted)];
234
- } else if (known.length === 1 && known[0] !== void 0) platforms = [known[0]];
235
- else if (known.length === 0) throw new TargetError("This project is not bound to an app yet — run `superwall push` to pick one.");
236
- else throw new TargetError(`${surface.kind} \`${surface.id}\` doesn't say which platforms it's for, and this project pushes to several (${describePlatforms(apps)}). Add \`platforms: [...]\` to ${surface.kind}s/${surface.id}/config.ts.`);
237
- for (const platform of platforms) {
238
- if (only.length > 0 && !only.includes(platform)) continue;
239
- const applicationId = apps[platform];
240
- if (applicationId === void 0) continue;
241
- targets.push({
242
- surface,
243
- platform,
244
- applicationId
245
- });
246
- }
247
- }
248
- if (targets.length === 0 && only.length > 0) throw new TargetError(`No paywall or funnel targets ${only.map((platform) => `\`${platform}\``).join(", ")}.`);
249
- return targets;
250
- }
251
-
252
- //#endregion
253
- //#region src/core/paywalls/products.ts
254
- async function fetchProducts(api, projectId) {
255
- const rows = await api.list(`/v2/products?project_id=${encodeURIComponent(projectId)}`);
256
- const catalogue = {};
257
- for (const row of rows) if (row.identifier) catalogue[row.identifier] = productVariables(row);
258
- return catalogue;
259
- }
260
- async function projectForApplication(api, applicationId) {
261
- const owner = (await listProjects(api).catch(() => [])).find((project) => (project.applications ?? []).some((app) => String(app.id) === applicationId));
262
- return owner ? String(owner.id) : void 0;
263
- }
264
- var MissingProductError = class extends Error {};
265
- function requireProducts(catalogue, surfaces) {
266
- const gaps = surfaces.flatMap((surface) => Object.entries(surface.products ?? {}).filter(([, identifier]) => catalogue[identifier] === void 0).map(([reference, identifier]) => ` ${surface.id}: ${reference} → ${identifier}`));
267
- if (gaps.length === 0) return;
268
- throw new MissingProductError([
269
- gaps.length === 1 ? "This product does not exist on Superwall:" : `These ${gaps.length} products do not exist on Superwall:`,
270
- ...gaps,
271
- "",
272
- "Every variable on them would be undefined on device. Add them in the",
273
- "dashboard, or point the config at products that exist."
274
- ].join("\n"));
275
- }
276
-
277
- //#endregion
278
- //#region src/core/paywalls/source/portability.ts
279
- const SHOWN = 5;
280
- function portabilityWarning(external) {
281
- const names = [...new Set(external)].filter((entry) => entry.trim() !== "").sort();
282
- if (names.length === 0) return void 0;
283
- const shown = names.slice(0, SHOWN).join(", ");
284
- const rest = names.length - SHOWN;
285
- return `${names.length} ${names.length === 1 ? "import resolves" : "imports resolve"} outside superwall/ (${shown}${rest > 0 ? `, and ${rest} more` : ""}) — this project can be edited locally only; remote editing and rebuilds won't be available. For full feature access, move them into superwall/components/ or install from a package registry.`;
286
- }
287
- function warnNotPortable(external) {
288
- const message = portabilityWarning(external);
289
- if (message) ui.warn(message);
290
- }
291
-
292
- //#endregion
293
- //#region src/core/paywalls/source/source.ts
294
- const HARD_EXCLUDES = [
295
- ".superwall/**",
296
- "**/node_modules/**",
297
- ".git/**",
298
- "**/.env*",
299
- "**/.DS_Store"
300
- ];
301
- function gitignoreExcludes(superwallDir) {
302
- let text;
303
- try {
304
- text = fs.readFileSync(path.join(superwallDir, ".gitignore"), "utf8");
305
- } catch {
306
- return [];
307
- }
308
- const excludes = [];
309
- for (const raw of text.split("\n")) {
310
- const line = raw.trim();
311
- if (line === "" || line.startsWith("#") || line.startsWith("!")) continue;
312
- const anchored = line.startsWith("/");
313
- const body = (anchored ? line.slice(1) : line).replace(/\/+$/, "");
314
- if (body === "") continue;
315
- const base = anchored || body.includes("/") ? body : `**/${body}`;
316
- excludes.push(base, `${base}/**`);
317
- }
318
- return excludes;
319
- }
320
- async function collectSourceFiles(superwallDir) {
321
- const entries = await fg("**/*", {
322
- cwd: superwallDir,
323
- dot: true,
324
- onlyFiles: true,
325
- followSymbolicLinks: false,
326
- ignore: [...HARD_EXCLUDES, ...gitignoreExcludes(superwallDir)]
327
- });
328
- if (entries.length === 0) return {
329
- ok: false,
330
- reason: `No source files found in ${superwallDir}.`
331
- };
332
- return {
333
- ok: true,
334
- files: entries.sort().map((relative$1) => ({
335
- path: relative$1,
336
- content: fs.readFileSync(path.join(superwallDir, relative$1))
337
- }))
338
- };
339
- }
340
-
341
- //#endregion
342
- //#region src/core/paywalls/source/commit.ts
343
- const buildCommitMessage = (input) => {
344
- const surface = `${input.kind}/${input.surface}`;
345
- const subject = `publish ${surface} v${input.version}`;
346
- const external = (input.external ?? []).filter((entry) => entry.trim() !== "");
347
- const trailers = [
348
- `Superwall-Paywall: ${input.paywallId}`,
349
- `Superwall-Application: ${input.applicationId}`,
350
- `Superwall-Version: ${input.version}`,
351
- `Superwall-Surface: ${surface}`,
352
- `Superwall-Portable: ${external.length === 0}`
353
- ];
354
- if (external.length > 0) trailers.push(`Superwall-External: ${external.join(", ")}`);
355
- if (input.snapshotSha) trailers.push(`Superwall-Snapshot: ${input.snapshotSha}`);
356
- trailers.push(`Superwall-Framework: ${input.framework}`);
357
- if (input.cli) trailers.push(`Superwall-Cli: ${input.cli}`);
358
- const note = input.note?.replace(/\r\n?/g, "\n").trim();
359
- return `${subject}\n${note ? `\n${note}\n` : ""}\n${trailers.join("\n")}\n`;
360
- };
361
- const tokenSecret = (token) => token.split("?")[0] ?? token;
362
- const redact = (text, ...secrets) => {
363
- let safe = text;
364
- for (const secret of secrets) {
365
- if (secret.length < 8) continue;
366
- safe = safe.split(secret).join("***");
367
- }
368
- return safe;
369
- };
370
-
371
- //#endregion
372
- //#region src/core/paywalls/source/git.ts
373
- const run = promisify(execFile);
374
- const AUTHOR = {
375
- name: "Superwall",
376
- email: "publish@superwall.com"
377
- };
378
- var GitError = class extends Error {};
379
- const gitEnv = (token, extra = {}) => ({
380
- ...process.env,
381
- GIT_CONFIG_COUNT: "1",
382
- GIT_CONFIG_KEY_0: "http.extraHeader",
383
- GIT_CONFIG_VALUE_0: `Authorization: Bearer ${tokenSecret(token)}`,
384
- GIT_TERMINAL_PROMPT: "0",
385
- ...extra
386
- });
387
- async function git(args, options = {}) {
388
- try {
389
- const { stdout } = await run("git", args, {
390
- cwd: options.cwd,
391
- env: options.env,
392
- maxBuffer: 64 * 1024 * 1024
393
- });
394
- return stdout;
395
- } catch (error) {
396
- const detail = typeof error === "object" && error !== null ? String(Reflect.get(error, "stderr") ?? Reflect.get(error, "message") ?? error) : String(error);
397
- throw new GitError(redact(`git ${args[0]} failed: ${gitReason(detail)}`, ...options.secrets ?? []));
398
- }
399
- }
400
- function gitReason(stderr) {
401
- const lines = stderr.split("\n").map((line) => line.trim()).filter((line) => line !== "" && !line.startsWith("Command failed:"));
402
- return (lines.find((line) => /^(fatal|error):/.test(line)) ?? lines[lines.length - 1] ?? "").replace(/^(fatal|error):\s*/, "") || "git reported no reason.";
403
- }
404
- async function gitAvailable() {
405
- try {
406
- await run("git", ["--version"]);
407
- return true;
408
- } catch {
409
- return false;
410
- }
411
- }
412
- const LARGE_FILE_BYTES = 50 * 1024 * 1024;
413
- function materializeSourceTree(dir, files) {
414
- for (const entry of fs.readdirSync(dir)) {
415
- if (entry === ".git") continue;
416
- fs.rmSync(path.join(dir, entry), {
417
- recursive: true,
418
- force: true
419
- });
420
- }
421
- const write = (relative$1, data) => {
422
- const file = path.join(dir, relative$1);
423
- fs.mkdirSync(path.dirname(file), { recursive: true });
424
- fs.writeFileSync(file, data);
425
- };
426
- const large = [];
427
- for (const file of files) {
428
- if (file.content.byteLength > LARGE_FILE_BYTES) large.push(file.path);
429
- write(file.path, file.content);
430
- }
431
- if (large.length > 0) ui.warn(`Committing ${large.length > 1 ? `${large.length} files` : large[0]} over 50 MB — every future clone of this app's source repo pays for it.`);
432
- }
433
- async function pushSourceTree(input) {
434
- const { access } = input;
435
- const secrets = [access.token, tokenSecret(access.token)];
436
- const dir = fs.mkdtempSync(path.join(os$1.tmpdir(), "superwall-source-"));
437
- const env = gitEnv(access.token);
438
- try {
439
- await git([
440
- "clone",
441
- "--depth",
442
- "1",
443
- "--branch",
444
- access.branch,
445
- access.remote,
446
- dir
447
- ], {
448
- env,
449
- secrets
450
- }).catch(async (error) => {
451
- await git([
452
- "clone",
453
- "--depth",
454
- "1",
455
- access.remote,
456
- dir
457
- ], {
458
- env,
459
- secrets
460
- }).catch(() => {
461
- throw error;
462
- });
463
- });
464
- materializeSourceTree(dir, input.files);
465
- await git(["add", "-A"], {
466
- cwd: dir,
467
- env,
468
- secrets
469
- });
470
- if ((await git(["status", "--porcelain"], {
471
- cwd: dir,
472
- env,
473
- secrets
474
- })).trim() === "") return {
475
- commitSha: (await git(["rev-parse", "HEAD"], {
476
- cwd: dir,
477
- env,
478
- secrets
479
- })).trim(),
480
- status: "unchanged"
481
- };
482
- const messageFile = path.join(dir, ".git", "SUPERWALL_COMMITMSG");
483
- fs.writeFileSync(messageFile, buildCommitMessage(input.message));
484
- await git([
485
- "commit",
486
- "-F",
487
- messageFile
488
- ], {
489
- cwd: dir,
490
- env: gitEnv(access.token, {
491
- GIT_AUTHOR_NAME: AUTHOR.name,
492
- GIT_AUTHOR_EMAIL: AUTHOR.email,
493
- GIT_COMMITTER_NAME: AUTHOR.name,
494
- GIT_COMMITTER_EMAIL: AUTHOR.email
495
- }),
496
- secrets
497
- });
498
- await git([
499
- "push",
500
- "origin",
501
- `HEAD:${access.branch}`
502
- ], {
503
- cwd: dir,
504
- env,
505
- secrets
506
- });
507
- return {
508
- commitSha: (await git(["rev-parse", "HEAD"], {
509
- cwd: dir,
510
- env,
511
- secrets
512
- })).trim(),
513
- status: "committed"
514
- };
515
- } finally {
516
- fs.rmSync(dir, {
517
- recursive: true,
518
- force: true
519
- });
520
- }
521
- }
522
-
523
- //#endregion
524
- //#region src/core/paywalls/source/source-push.ts
525
- var GitRequiredError = class extends Error {
526
- constructor() {
527
- super("superwall publish requires git for the source step — install git");
528
- }
529
- };
530
- async function pushSource(input) {
531
- if (!await (input.hasGit ?? gitAvailable)()) throw new GitRequiredError();
532
- for (let attempt = 0;; attempt++) {
533
- const access = await mintSourceAccess(input.api, input.paywallId);
534
- const pushed = await pushSourceTree({
535
- access,
536
- files: input.files,
537
- message: {
538
- kind: input.kind,
539
- surface: input.surface,
540
- version: input.version,
541
- paywallId: input.paywallId,
542
- applicationId: input.applicationId,
543
- snapshotSha: input.snapshotId,
544
- framework: input.framework,
545
- cli: input.cli,
546
- note: input.note,
547
- external: input.external
548
- }
549
- });
550
- try {
551
- await linkSourceCommit(input.api, input.paywallId, input.version, {
552
- commitSha: pushed.commitSha,
553
- tokenId: access.tokenId
554
- });
555
- return pushed;
556
- } catch (error) {
557
- if (attempt === 0 && worthRetrying(error)) continue;
558
- throw error;
559
- }
560
- }
561
- }
562
- const worthRetrying = (error) => error instanceof ApiError && (error.status === 409 || error.status === 400);
563
-
564
- //#endregion
565
- //#region src/core/paywalls/binding/renames.ts
566
- var RenameError = class extends Error {};
567
- function parseRenameFlags(value) {
568
- return (value === void 0 ? [] : Array.isArray(value) ? value : [value]).map((entry) => {
569
- const text = typeof entry === "string" ? entry.trim() : "";
570
- const at = text.indexOf("=");
571
- const from = at === -1 ? "" : text.slice(0, at).trim();
572
- const to = at === -1 ? "" : text.slice(at + 1).trim();
573
- if (!from || !to) throw new RenameError(`--rename takes <old>=<new>, e.g. --rename plus-upgrade=pro-upgrade` + (text ? ` (got "${text}")` : ""));
574
- return {
575
- from,
576
- to
577
- };
578
- });
579
- }
580
- function unresolvedError(orphans, newcomers) {
581
- return new RenameError([
582
- "Cannot tell whether these are new or renamed, and this run cannot ask.",
583
- "",
584
- "Bound in superwall.lock, but no directory on disk:",
585
- ...orphans.map((orphan) => ` ${orphan.id} → ${describeBindings(orphan.bindings)}`),
586
- "On disk, but not in superwall.lock:",
587
- ...newcomers.map((newcomer) => ` ${newcomer.id}`),
588
- "",
589
- "Declare each rename, then run again:",
590
- ...newcomers.flatMap((newcomer) => orphans.map((orphan) => ` --rename ${orphan.id}=${newcomer.id}`)),
591
- "",
592
- "If one of these paywalls is genuinely gone, remove its entry from",
593
- "superwall.lock by hand and run again.",
594
- "",
595
- "Refusing to create — the bound paywalls are what production serves."
596
- ].join("\n"));
597
- }
598
- async function resolveRenames(input) {
599
- const lock = readLock(input.superwallDir);
600
- const orphans = [];
601
- const newcomers = [];
602
- for (const kind of ["paywall", "funnel"]) {
603
- const section = kind === "paywall" ? lock.paywalls : lock.funnels;
604
- const onDisk = input.surfaces.filter((surface) => surface.kind === kind);
605
- const ids = new Set(onDisk.map((surface) => surface.id));
606
- for (const [id, bindings] of Object.entries(section).sort(([a], [b]) => a.localeCompare(b))) if (!ids.has(id)) orphans.push({
607
- kind,
608
- id,
609
- bindings
610
- });
611
- for (const surface of onDisk) if (!(surface.id in section)) newcomers.push(surface);
612
- }
613
- const renamed = [];
614
- const rebind = (orphan, newcomer) => {
615
- writeBindings(input.superwallDir, newcomer.kind, newcomer.id, orphan.bindings);
616
- removeBinding(input.superwallDir, orphan.kind, orphan.id);
617
- renamed.push({
618
- kind: newcomer.kind,
619
- from: orphan.id,
620
- to: newcomer.id,
621
- bindings: orphan.bindings
622
- });
623
- orphans.splice(orphans.indexOf(orphan), 1);
624
- newcomers.splice(newcomers.indexOf(newcomer), 1);
625
- };
626
- for (const declaration of input.declared ?? []) {
627
- const newcomer = newcomers.find((candidate) => candidate.id === declaration.to);
628
- if (!newcomer) throw new RenameError(`--rename ${declaration.from}=${declaration.to}: no unbound directory named "${declaration.to}".`);
629
- const orphan = orphans.find((candidate) => candidate.id === declaration.from && candidate.kind === newcomer.kind);
630
- if (!orphan) throw new RenameError(`--rename ${declaration.from}=${declaration.to}: superwall.lock has no ${newcomer.kind} "${declaration.from}" waiting to be renamed.`);
631
- rebind(orphan, newcomer);
632
- }
633
- for (const newcomer of [...newcomers]) {
634
- const candidates = orphans.filter((orphan) => orphan.kind === newcomer.kind);
635
- if (candidates.length === 0) continue;
636
- if (!input.choose) throw unresolvedError(candidates, [newcomer]);
637
- const decision = await input.choose({
638
- newcomer,
639
- orphans: candidates
640
- });
641
- if (decision.kind === "rename") {
642
- const orphan = candidates.find((candidate) => candidate.id === decision.orphanId);
643
- if (!orphan) throw new RenameError(`No pending rename candidate named "${decision.orphanId}".`);
644
- rebind(orphan, newcomer);
645
- }
646
- }
647
- const dropped = [];
648
- const kept = [];
649
- for (const orphan of orphans) {
650
- if (!input.chooseStale) {
651
- input.notice?.(`\`${orphan.id}\` is still bound to ${describeBindings(orphan.bindings)} but no longer exists on disk — remove it from superwall.lock if that paywall is gone.`);
652
- kept.push(orphan);
653
- continue;
654
- }
655
- if (await input.chooseStale(orphan) === "remove") {
656
- removeBinding(input.superwallDir, orphan.kind, orphan.id);
657
- dropped.push(orphan);
658
- } else kept.push(orphan);
659
- }
660
- return {
661
- renamed,
662
- stale: kept,
663
- dropped
664
- };
665
- }
666
-
667
- //#endregion
668
- //#region src/commands/paywalls/pick-app.ts
669
- async function pickApplicationOption(apps, platform) {
670
- const picked = await ui.select({
671
- message: platform ? `Which ${platformLabel(platform)} app do these paywalls push to? The choice is saved under apps in superwall.lock.` : "Which app do these paywalls belong to?",
672
- options: apps.map((app) => ({
673
- value: String(app.id),
674
- label: app.name ?? app.bundle_id ?? String(app.id),
675
- hint: platformLabel(app.platform)
676
- }))
677
- });
678
- if (!picked) return null;
679
- return apps.find((app) => String(app.id) === picked) ?? null;
680
- }
681
-
682
- //#endregion
683
- //#region src/commands/paywalls/pick-rename.ts
684
- const CREATE = "__create__";
685
- async function pickRenameOption(input) {
686
- const picked = await ui.select({
687
- message: `\`${input.newcomer.id}\` is not in superwall.lock. Is it a new ${input.newcomer.kind}, or renamed?`,
688
- options: [...input.orphans.map((orphan) => ({
689
- value: orphan.id,
690
- label: `Renamed from ${orphan.id}`,
691
- hint: describeBindings(orphan.bindings)
692
- })), {
693
- value: CREATE,
694
- label: `Create a new ${input.newcomer.kind}`
695
- }]
696
- });
697
- if (picked === null) throw new RenameError("Cancelled — superwall.lock is unchanged and nothing was pushed.");
698
- return picked === CREATE ? { kind: "create" } : {
699
- kind: "rename",
700
- orphanId: picked
701
- };
702
- }
703
-
704
- //#endregion
705
- //#region src/commands/paywalls/pick-stale.ts
706
- const REMOVE = "__remove__";
707
- const KEEP = "__keep__";
708
- async function pickStaleOption(orphan) {
709
- const picked = await ui.select({
710
- message: `\`${orphan.id}\` is bound to ${describeBindings(orphan.bindings)} but no longer exists on disk. Removing only forgets it locally — the paywall stays on Superwall, keeps its campaigns, and keeps serving devices.`,
711
- options: [{
712
- value: REMOVE,
713
- label: "Remove the binding",
714
- hint: "restoring the directory re-binds it on the next push"
715
- }, {
716
- value: KEEP,
717
- label: "Keep it",
718
- hint: "superwall.lock is left as it is"
719
- }],
720
- initialValue: REMOVE
721
- });
722
- if (picked === null) throw new RenameError("Cancelled — superwall.lock is unchanged and nothing was pushed.");
723
- return picked === REMOVE ? "remove" : "keep";
724
- }
725
-
726
- //#endregion
727
- //#region src/commands/paywalls/pipeline/index.ts
728
- async function pooled(items, limit, work) {
729
- const results = new Array(items.length);
730
- let cursor = 0;
731
- const runners = Array.from({ length: Math.min(limit, items.length) }, async () => {
732
- while (cursor < items.length) {
733
- const index = cursor++;
734
- const item = items[index];
735
- if (item === void 0) continue;
736
- results[index] = await work(item, index);
737
- }
738
- });
739
- await Promise.all(runners);
740
- return results;
741
- }
742
- async function timed(work) {
743
- const at = Date.now();
744
- return {
745
- value: await work(),
746
- took: took(at)
747
- };
748
- }
749
- async function group(context, id, work) {
750
- const spin = context.outputMode === "rich" ? ui.spinner() : void 0;
751
- spin?.start(id);
752
- try {
753
- const lines = await work((message) => spin?.message(`${id} ${pc.dim(message)}`));
754
- const block = [pc.bold(id), ...lines].join("\n");
755
- if (spin) spin.stop(block);
756
- else ui.info(block);
757
- } catch (error) {
758
- if (spin) spin.stop(pc.red(`${id} failed`));
759
- else ui.info(pc.red(`${id} failed`));
760
- throw error;
761
- }
762
- }
763
- function summary(outcomes, skipped, promoted) {
764
- const count = outcomes.length;
765
- const noun = (n) => n === 1 ? "paywall" : "paywalls";
766
- const unchanged = skipped > 0 ? ` · ${pc.dim(`${skipped} unchanged`)}` : "";
767
- if (count === 0) {
768
- ui.outro(skipped > 0 ? `Nothing to do · ${skipped} unchanged.` : "Nothing to do.");
769
- return;
770
- }
771
- if (promoted) {
772
- ui.outro(`${pc.green(`${count} ${noun(count)} live`)}${unchanged}.`);
773
- return;
774
- }
775
- ui.outro(`${count} ${noun(count)} pushed${unchanged} · run \`superwall promote\` to publish ${count === 1 ? "it" : "them"}.`);
776
- }
777
- const BUILD_CONCURRENCY = Math.max(2, Math.min(8, cpus().length - 1));
778
- async function prepare(context, input) {
779
- const { framework, project, surfaces, declared } = input;
780
- const apps = await resolveApps({
781
- api: context.api,
782
- superwallDir: project.superwallDir,
783
- wanted: wantedPlatforms(surfaces, declared),
784
- pickApplication: input.interactive ? pickApplicationOption : void 0
785
- });
786
- const multi = Object.keys(apps).length > 1;
787
- const targets = planTargets({
788
- surfaces,
789
- declared,
790
- apps,
791
- only: parsePlatformFlags(context.argv.platform)
792
- });
793
- const spin = context.outputMode === "rich" ? ui.spinner() : void 0;
794
- const label = targets.length === 1 && targets[0] !== void 0 ? targetLabel(targets[0], multi) : `${targets.length} paywalls`;
795
- spin?.start(`Building ${label}`);
796
- const at = Date.now();
797
- try {
798
- const builds = await pooled(targets, BUILD_CONCURRENCY, (target) => framework.buildSnapshot(project, target.surface, {
799
- assetBaseUrl: assetBaseUrl(target.applicationId),
800
- platform: target.platform
801
- }));
802
- const projectIds = /* @__PURE__ */ new Map();
803
- for (const target of targets) {
804
- if (projectIds.has(target.applicationId)) continue;
805
- projectIds.set(target.applicationId, await projectForApplication(context.api, target.applicationId));
806
- }
807
- const catalogues = /* @__PURE__ */ new Map();
808
- for (const projectId of new Set(projectIds.values())) {
809
- if (projectId === void 0) continue;
810
- catalogues.set(projectId, await fetchProducts(context.api, projectId));
811
- }
812
- for (const [projectId, catalogue] of catalogues) requireProducts(catalogue, targets.flatMap((target, index) => projectIds.get(target.applicationId) === projectId ? [{
813
- id: target.surface.id,
814
- products: builds[index]?.products
815
- }] : []));
816
- const bindings = [];
817
- for (const [index, target] of targets.entries()) bindings.push(await resolveBinding({
818
- api: context.api,
819
- superwallDir: project.superwallDir,
820
- surface: target.surface,
821
- app: {
822
- platform: target.platform,
823
- applicationId: target.applicationId
824
- },
825
- name: builds[index]?.name,
826
- surfaces: project.surfaces,
827
- renamesResolved: true
828
- }));
829
- const prepared = await pooled(targets, BUILD_CONCURRENCY, async (target, index) => {
830
- const bind = bindings[index];
831
- const build = builds[index];
832
- if (!bind || !build) throw new Error(`Missing binding for ${target.surface.id}`);
833
- requireAssets(build);
834
- const live = await livePaywall(context.api, bind.paywallId);
835
- const lock = readLock(project.superwallDir);
836
- const pushed = (target.surface.kind === "paywall" ? lock.paywalls : lock.funnels)[target.surface.id]?.[target.platform]?.snapshot;
837
- return {
838
- target,
839
- bind,
840
- build,
841
- live: live.version,
842
- changed: needsWork(build.snapshotId, pushed, live.snapshotId),
843
- pending: !needsWork(build.snapshotId, pushed, live.snapshotId) && live.snapshotId !== build.snapshotId
844
- };
845
- });
846
- const modified = prepared.filter((entry) => entry.changed).length;
847
- spin?.stop(`${pc.bold(`Built ${label}`)} ${pc.dim(`${modified} modified · ${prepared.length - modified} unchanged`)} ${took(at)}`);
848
- return {
849
- prepared,
850
- multi
851
- };
852
- } catch (error) {
853
- spin?.stop(pc.red(`Building ${label} failed`));
854
- throw error;
855
- }
856
- }
857
- async function runPushPipeline(context, options) {
858
- const dir = projectDir(context);
859
- const framework = await (options.load ?? loadFramework)(dir);
860
- const project = requireProject(framework.discoverProject(dir), dir);
861
- const installed = frameworkVersion(dir);
862
- const declarations = await collectProjectDeclarations(framework, project.root);
863
- writeProjectTypes(project, declarations.products);
864
- writeProjectScaffold({
865
- root: project.root,
866
- superwallDir: project.superwallDir,
867
- frameworkVersion: installed
868
- });
869
- const surfaces = selectSurfaces(project, context.argv.id);
870
- requireClean(surfaces);
871
- const publishNote = resolveNote(context.argv.message);
872
- ui.intro(`Superwall ${pc.dim(`v${VERSION}`)}`);
873
- const renames = await resolveRenames({
874
- superwallDir: project.superwallDir,
875
- surfaces: project.surfaces,
876
- declared: parseRenameFlags(context.argv.rename),
877
- choose: context.interactive ? pickRenameOption : void 0,
878
- chooseStale: context.interactive ? pickStaleOption : void 0,
879
- notice: (message) => ui.warn(message)
880
- });
881
- for (const pair of renames.renamed) ui.step(`${pair.kind}/${pair.to} keeps ${describeBindings(pair.bindings)} (renamed from ${pair.from})`);
882
- for (const orphan of renames.dropped) ui.step(`${orphan.kind}/${orphan.id} removed from superwall.lock · ${describeBindings(orphan.bindings)} untouched on Superwall`);
883
- const source = await collectSourceFiles(project.superwallDir);
884
- const outcomes = [];
885
- const external = /* @__PURE__ */ new Set();
886
- const { prepared, multi } = await prepare(context, {
887
- framework,
888
- project,
889
- surfaces,
890
- declared: declarations.platforms,
891
- interactive: context.interactive,
892
- promote: options.promote
893
- });
894
- for (const entry of prepared) for (const source$1 of entry.build.externalSources ?? []) external.add(source$1);
895
- const changed = prepared.filter((entry) => entry.changed);
896
- const skipped = prepared.length - changed.length;
897
- const pendingHint = pendingPromoteWarning((options.promote ? prepared.filter((entry) => entry.pending) : []).map((entry) => ({
898
- id: entry.target.surface.id,
899
- platform: entry.target.platform
900
- })), multi);
901
- if (pendingHint) ui.warn(pendingHint);
902
- for (const { target, bind, build, live: wasLive } of changed) {
903
- const { surface } = target;
904
- let version = 0;
905
- let live = false;
906
- await group(context, targetLabel(target, multi), async (note) => {
907
- const lines = [];
908
- const assets = requireAssets(build);
909
- lines.push(`${BIND_VERB[bind.source]} paywall ${bind.paywallId}`);
910
- lines.push(assets.length > 0 ? `Built ${pc.dim(`${kb(build.bytes)} html + ${weight(build.assetBytes ?? 0)} assets`)}` : `Built ${pc.dim(`${kb(build.bytes)} · ${build.snapshotId.slice(0, 8)}`)}`);
911
- note("Syncing assets");
912
- const synced = await timed(() => syncAssets({
913
- api: context.api,
914
- paywallId: bind.paywallId,
915
- assets
916
- }));
917
- if (assets.length > 0) {
918
- const noun = assets.length === 1 ? "asset" : "assets";
919
- lines.push(synced.value.uploaded > 0 ? `${assets.length} ${noun} ${pc.dim(`(${weight(synced.value.totalBytes)})`)}, ${synced.value.uploaded} uploaded ${synced.took}` : `Assets up to date ${pc.dim(`(${assets.length} ${noun})`)} ${synced.took}`);
920
- }
921
- note("Pushing");
922
- const push = await timed(() => pushPaywallVersion(context.api, bind.paywallId, {
923
- html: build.html,
924
- surface: surface.id,
925
- assets: synced.value.assets,
926
- products: versionProducts(build.products, target.platform),
927
- settings: build.settings,
928
- locales: build.locales
929
- }));
930
- version = push.value.version;
931
- writeSnapshot(project.superwallDir, surface.kind, surface.id, target.platform, build.snapshotId);
932
- lines.push(`${pushedLine({
933
- version,
934
- snapshotId: push.value.snapshot_id ?? build.snapshotId,
935
- live: wasLive,
936
- promoting: options.promote
937
- })} ${push.took}`);
938
- note("Pushing source");
939
- const pushed = await timed(() => {
940
- if (!source.ok) throw new Error(source.reason);
941
- return pushSource({
942
- api: context.api,
943
- paywallId: bind.paywallId,
944
- applicationId: bind.applicationId,
945
- version,
946
- files: source.files,
947
- framework: installed,
948
- surface: surface.id,
949
- kind: surface.kind,
950
- snapshotId: build.snapshotId,
951
- cli: VERSION,
952
- note: publishNote,
953
- external: [...build.externalSources ?? []].sort()
954
- });
955
- });
956
- const sha = pc.dim(pushed.value.commitSha.slice(0, 7));
957
- lines.push(`Source ${pushed.value.status === "unchanged" ? "unchanged" : "pushed"} ${sha} ${pushed.took}`);
958
- if (options.promote) {
959
- note("Promoting");
960
- const promo = await timed(() => promotePaywallVersion(context.api, bind.paywallId, { version }));
961
- lines.push(`${transition(wasLive, promo.value.version)} ${promo.took}`);
962
- live = true;
963
- }
964
- return lines;
965
- });
966
- outcomes.push({
967
- id: targetLabel(target, multi),
968
- version,
969
- live
970
- });
971
- }
972
- warnNotPortable(external);
973
- summary(outcomes, skipped, options.promote);
974
- }
975
-
976
- //#endregion
977
- export { requireApi as _, pushSource as a, requirePlatform as b, warnNotPortable as c, parsePlatformFlags as d, planTargets as f, LoginRequiredError as g, resolveBinding as h, pickApplicationOption as i, fetchProducts as l, wantedPlatforms as m, runPushPipeline as n, gitAvailable as o, targetLabel as p, timed as r, collectSourceFiles as s, group as t, projectForApplication as u, projectPackageName as v, resolveApps as x, writeProjectScaffold as y };