@superwall/cli 1.7.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/README.md +192 -52
  2. package/dist/{setup-Bxj22rYi.js → apple-CSzNTGHM.js} +82 -76
  3. package/dist/auth.d.ts +4 -19
  4. package/dist/auth.js +4 -2
  5. package/dist/{actions-B7ym3oVS.js → billing-C3Q8DBU2.js} +98 -28
  6. package/dist/{bind-YrJvuRF9.js → bind-BumHTi9O.js} +38 -33
  7. package/dist/{build-DLoCW5Ri.js → build-Bpviiclc.js} +20 -26
  8. package/dist/client-BL0f_yGf.js +176 -0
  9. package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
  10. package/dist/config-BO1Y87kV.js +105 -0
  11. package/dist/create-BSfvpWoD.js +19 -0
  12. package/dist/{create-pkANt1Gs.js → create-BUcVG4Ab.js} +195 -169
  13. package/dist/{notification-url-DuKF2659.js → create-CfK3PeKA.js} +235 -539
  14. package/dist/doctor-BWqIYcMn.js +83 -0
  15. package/dist/{drivers-Qx9LxmRN.js → drivers-CPhdPkW5.js} +185 -172
  16. package/dist/entry.d.ts +0 -5
  17. package/dist/entry.js +28072 -1134
  18. package/dist/environment-eBXjELoN.js +58 -0
  19. package/dist/{existing-AVEfZu2A.js → existing-BltvQiX5.js} +12 -6
  20. package/dist/held-CPve03KJ.js +16 -0
  21. package/dist/held-DgnTFMl3.js +1112 -0
  22. package/dist/input-vi0bou04.js +42 -0
  23. package/dist/{integrate-brmhPG-S.js → integrate-BRsqoe01.js} +277 -254
  24. package/dist/log-NVhVe_oe.js +62 -0
  25. package/dist/login-BCEH5q0U.js +53 -0
  26. package/dist/login-BPOONe7n.js +16 -0
  27. package/dist/{login-Do4wFuLv.js → login-BbTIrCFT.js} +118 -55
  28. package/dist/lookup-rr1AkCJA.js +71 -0
  29. package/dist/migrate-C9X2Vz81.js +274 -0
  30. package/dist/notification-url-CV86qiKP.js +100 -0
  31. package/dist/{open-studio-DOw-6ydc.js → open-CcpXotHG.js} +34 -43
  32. package/dist/org-BQQDo7wm.js +35 -0
  33. package/dist/output-Ggzq5_-t.js +122 -0
  34. package/dist/paths-CRlU72cq.js +29 -0
  35. package/dist/playbook-DVMXN7fh.js +53 -0
  36. package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
  37. package/dist/promote-Da8xctzy.js +91 -0
  38. package/dist/push-BV-grvQg.js +22 -0
  39. package/dist/push-D6R9icWN.js +495 -0
  40. package/dist/registry-BYVD-_h6.js +10385 -0
  41. package/dist/{reports-CfJqoava.js → reports-D_qbl7_u.js} +7 -6
  42. package/dist/{resources-Bf9O1JNM.js → resources-DLON3-61.js} +162 -55
  43. package/dist/{run-DsVZ5snL.js → run-Co-BwhOg.js} +16 -22
  44. package/dist/scan-B88OlWOt.js +4 -0
  45. package/dist/{scan-zKsddO72.js → scan-CKuk-_6W.js} +48 -37
  46. package/dist/scope-DV22_Ufm.js +198 -0
  47. package/dist/screenshot-file-tVBfUEIi.js +16 -0
  48. package/dist/{selection-CxZoX4NT.js → selection-C2_KbLuo.js} +100 -51
  49. package/dist/server-C4f6ccUr.js +22 -0
  50. package/dist/{dev-DmB3XqaJ.js → server-D0d2oP-5.js} +86 -94
  51. package/dist/session-B-Uz0cQ7.js +40 -0
  52. package/dist/session-BuvArt1j.js +6 -0
  53. package/dist/session-C4rbE3VS.js +796 -0
  54. package/dist/skills/animate-onboarding/SKILL.md +467 -0
  55. package/dist/skills/animate-onboarding/references/engine.md +494 -0
  56. package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
  57. package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
  58. package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
  59. package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
  60. package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  61. package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
  62. package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
  63. package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  64. package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
  65. package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
  66. package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
  67. package/dist/skills/animate-onboarding/references/performance.md +41 -0
  68. package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
  69. package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  70. package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  71. package/dist/skills/index.json +37 -0
  72. package/dist/skills/mobile-design/SKILL.md +447 -0
  73. package/dist/skills/mobile-design/references/responsive.md +162 -0
  74. package/dist/skills/onboarding-questions/SKILL.md +231 -0
  75. package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
  76. package/dist/skills/onboarding-questions/references/craft.md +142 -0
  77. package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
  78. package/dist/skills/superwall/SKILL.md +82 -9
  79. package/dist/skills/superwall/references/api.md +153 -37
  80. package/dist/skills/superwall/references/apple-setup.md +316 -0
  81. package/dist/skills/superwall/references/asc.md +74 -38
  82. package/dist/skills/superwall/references/data-analytics.md +55 -21
  83. package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
  84. package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
  85. package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
  86. package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
  87. package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
  88. package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
  89. package/dist/skills/superwall/workflows/placements/android.md +2 -2
  90. package/dist/skills/superwall/workflows/placements/expo.md +2 -2
  91. package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
  92. package/dist/skills/superwall/workflows/placements/ios.md +2 -2
  93. package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
  94. package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
  95. package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
  96. package/dist/skills/superwall/workflows/review/playbook.md +1 -1
  97. package/dist/skills/superwall-editor/SKILL.md +61 -0
  98. package/dist/skills/superwall-editor/references/cli.md +135 -0
  99. package/dist/skills/superwall-editor/references/design.md +51 -0
  100. package/dist/skills/superwall-editor/references/native-elements.md +171 -0
  101. package/dist/skills/superwall-editor/references/workflow.md +65 -0
  102. package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
  103. package/dist/skills/superwall-framework/SKILL.md +85 -31
  104. package/dist/skills/superwall-framework/references/cli.md +58 -27
  105. package/dist/skills/superwall-framework/references/examples.md +4 -3
  106. package/dist/skills/superwall-framework/references/layout.md +64 -9
  107. package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
  108. package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
  109. package/dist/skills/wwdc/SKILL.md +22 -0
  110. package/dist/skills/wwdc/references/docs.md +52 -0
  111. package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
  112. package/dist/skills-CLGJuMnF.js +14 -0
  113. package/dist/{skills-DPzlnfCK.js → skills-CZcpnEnG.js} +100 -122
  114. package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
  115. package/dist/spinner-C2U6QBJ9.js +294 -0
  116. package/dist/storage-6h9vyiAz.js +31 -0
  117. package/dist/storage-CerJ5KLP.d.ts +16 -0
  118. package/dist/storekit-CK9JmM2D.js +16 -0
  119. package/dist/storekit-CinJra3V.js +47 -0
  120. package/dist/telemetry-DKyDhURo.js +56 -0
  121. package/dist/theme-DUsCh-Vd.js +25 -0
  122. package/dist/timing-BVxPrYq3.js +5 -0
  123. package/dist/{token-C0it-Xh7.js → token-DaxQgQkv.js} +6 -38
  124. package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
  125. package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
  126. package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
  127. package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
  128. package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
  129. package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
  130. package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
  131. package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
  132. package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
  133. package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
  134. package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
  135. package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
  136. package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
  137. package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
  138. package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
  139. package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
  140. package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
  141. package/dist/tools-skills/mobile-design/SKILL.md +447 -0
  142. package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
  143. package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
  144. package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
  145. package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
  146. package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
  147. package/dist/tools-skills/superwall/SKILL.md +263 -0
  148. package/dist/tools-skills/superwall/references/api.md +303 -0
  149. package/dist/tools-skills/superwall/references/asa.md +166 -0
  150. package/dist/tools-skills/superwall/references/asc.md +95 -0
  151. package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
  152. package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
  153. package/dist/tools-skills/superwall/references/docs.md +51 -0
  154. package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
  155. package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
  156. package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
  157. package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
  158. package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
  159. package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
  160. package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
  161. package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
  162. package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
  163. package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
  164. package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
  165. package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
  166. package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
  167. package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
  168. package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
  169. package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
  170. package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
  171. package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
  172. package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
  173. package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
  174. package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
  175. package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
  176. package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
  177. package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
  178. package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
  179. package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
  180. package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
  181. package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
  182. package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
  183. package/dist/tools-skills/superwall-editor/references/design.md +51 -0
  184. package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
  185. package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
  186. package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
  187. package/dist/tools-skills/wwdc/SKILL.md +22 -0
  188. package/dist/tools-skills/wwdc/references/docs.md +52 -0
  189. package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
  190. package/dist/tools.d.ts +96 -0
  191. package/dist/tools.js +11360 -0
  192. package/dist/ui-D_qf3Gvw.js +53 -0
  193. package/dist/upgrade-DPo0a4Es.js +117 -0
  194. package/dist/upgrade-ffseQDMx.js +7 -0
  195. package/package.json +10 -5
  196. package/dist/api-CZzirVMj.js +0 -151
  197. package/dist/api-output-aJNw7Syy.js +0 -20
  198. package/dist/app-DH6U8yuI.js +0 -190
  199. package/dist/asa-C-sQzPPn.js +0 -1194
  200. package/dist/asc-1ZBJ6DwS.js +0 -778
  201. package/dist/auth-YRhlV3DE.js +0 -140
  202. package/dist/billing-CCYHdApx.js +0 -80
  203. package/dist/bundle-id-CKxl_026.js +0 -121
  204. package/dist/command-CMIz81Da.js +0 -301
  205. package/dist/dev-DZy6pOnB.js +0 -22
  206. package/dist/doctor-H-hf-Yww.js +0 -88
  207. package/dist/feedback-CKf-rpBW.js +0 -152
  208. package/dist/hosted-CXe9TrWx.js +0 -32
  209. package/dist/migrate-C9ERDR6y.js +0 -284
  210. package/dist/org-sj7uyvp-.js +0 -40
  211. package/dist/output-C4o2gJ1K.js +0 -146
  212. package/dist/params-l3CrvRtR.js +0 -51
  213. package/dist/pipeline-BqzqZhX1.js +0 -977
  214. package/dist/print-skill-ZojRSybs.js +0 -74
  215. package/dist/promote-BG8X4Nv_.js +0 -88
  216. package/dist/publish-sxLh-G4G.js +0 -35
  217. package/dist/push-bQ6Vxtg8.js +0 -35
  218. package/dist/query-_FbybaH-.js +0 -53
  219. package/dist/resource-CGIwSd29.js +0 -323
  220. package/dist/revenue-provider-ebsRINY8.js +0 -100
  221. package/dist/scope-BvzD-kO4.js +0 -223
  222. package/dist/skills-D_R-lEsK.js +0 -64
  223. package/dist/spinner-TWa0hia6.js +0 -18
  224. package/dist/storekit-Cj9Cpjcz.js +0 -29
  225. package/dist/telemetry-DeA1mvnT.js +0 -169
  226. package/dist/ui-Dy0b-9L8.js +0 -27738
  227. package/dist/update-B2fWIc4q.js +0 -59
  228. package/dist/upgrade-BmzkTKrh.js +0 -72
  229. /package/dist/{devtools-8EgLo86w.js → devtools-pBl_vt03.js} +0 -0
@@ -0,0 +1,796 @@
1
+ import { l as ENV_API_KEY, t as API_HOST, v as apiKeyFromEnv } from "./environment-eBXjELoN.js";
2
+ import { t as readSession } from "./storage-6h9vyiAz.js";
3
+ import { n as ApiUnreachableError, r as createSuperwallApi, t as ApiError } from "./client-BL0f_yGf.js";
4
+ import { n as ui } from "./ui-D_qf3Gvw.js";
5
+ import { O as isRecord, _ as mintSourceAccess, a as createHeadlessPaywall, d as listAppPaywalls, f as listApplications, u as linkSourceCommit, v as platformLabel } from "./resources-DLON3-61.js";
6
+ import { n as findApplication } from "./lookup-rr1AkCJA.js";
7
+ import { C as parseSources, D as writeBinding, E as writeApp, j as writeSources, w as readLock, x as formatSharedLock } from "./selection-C2_KbLuo.js";
8
+ import { n as performLoginWithUi } from "./login-BCEH5q0U.js";
9
+ import { execFile } from "node:child_process";
10
+ import * as fs from "node:fs";
11
+ import * as path from "node:path";
12
+ import { promisify } from "node:util";
13
+ import * as os$1 from "node:os";
14
+ import fg from "fast-glob";
15
+ import { setTimeout } from "node:timers/promises";
16
+ import { productVariables } from "@superwall/studio/products";
17
+
18
+ //#region src/core/paywalls/binding/apps.ts
19
+ const PLATFORMS = [
20
+ "ios",
21
+ "android",
22
+ "web"
23
+ ];
24
+ var AppBindingError = class extends Error {};
25
+ const platformOf = (app) => {
26
+ const normalized = (app.platform ?? "").toLowerCase();
27
+ return PLATFORMS.find((platform) => platform === normalized);
28
+ };
29
+ function requirePlatform(app) {
30
+ const platform = platformOf(app);
31
+ if (platform !== void 0) return platform;
32
+ 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.`);
33
+ }
34
+ const platformFor = (apps, value) => {
35
+ if (value in apps) return value;
36
+ return Object.entries(apps).find(([, id]) => id === value)?.[0];
37
+ };
38
+ function describePlatforms(apps) {
39
+ return Object.keys(apps).join(", ");
40
+ }
41
+ async function resolveApps(input) {
42
+ const { api, superwallDir } = input;
43
+ let cached;
44
+ const known = () => cached ??= listApplications(api);
45
+ const current = () => readLock(superwallDir).apps;
46
+ for (const platform of new Set(input.wanted ?? [])) {
47
+ if (!PLATFORMS.some((known$1) => known$1 === platform)) throw new AppBindingError(`"${platform}" is not a platform — use one of ${PLATFORMS.join(", ")}.`);
48
+ if (platform in current()) continue;
49
+ const bound = new Set(Object.values(current()));
50
+ const candidates = (await known()).filter((app) => !bound.has(String(app.id)) && platformOf(app) === platform);
51
+ const only = candidates.length === 1 ? candidates[0] : void 0;
52
+ if (only) {
53
+ writeApp(superwallDir, platform, String(only.id));
54
+ continue;
55
+ }
56
+ const picked = candidates.length > 1 && input.pickApplication ? await input.pickApplication(candidates, platform) : null;
57
+ if (picked) {
58
+ writeApp(superwallDir, platform, String(picked.id));
59
+ continue;
60
+ }
61
+ const label = platformLabel(platform);
62
+ 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).`);
63
+ }
64
+ if (Object.keys(current()).length > 0) return current();
65
+ const apps = await known();
66
+ if (apps.length === 1 && apps[0] !== void 0) {
67
+ writeApp(superwallDir, requirePlatform(apps[0]), String(apps[0].id));
68
+ return current();
69
+ }
70
+ if (apps.length > 1 && input.pickApplication) {
71
+ const picked = await input.pickApplication(apps);
72
+ if (picked) {
73
+ writeApp(superwallDir, requirePlatform(picked), String(picked.id));
74
+ return current();
75
+ }
76
+ }
77
+ 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.");
78
+ }
79
+
80
+ //#endregion
81
+ //#region src/core/paywalls/binding/binding.ts
82
+ var BindingError = class extends Error {};
83
+ const describe = (surface) => `${surface.kind} \`${surface.id}\``;
84
+ const humanize = (surfaceId) => surfaceId.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
85
+ async function resolveBinding(input) {
86
+ const { api, superwallDir, surface, app } = input;
87
+ const { platform, applicationId } = app;
88
+ const create = input.create ?? true;
89
+ const lock = readLock(superwallDir);
90
+ const section = surface.kind === "paywall" ? lock.paywalls : lock.funnels;
91
+ const locked = section[surface.id]?.[platform];
92
+ if (locked) return {
93
+ paywallId: locked.paywallId,
94
+ applicationId,
95
+ platform,
96
+ source: "lock"
97
+ };
98
+ const matches = (paywalls) => {
99
+ const headless = paywalls.filter((paywall) => paywall.metadata.headless === "true");
100
+ return headless.find((paywall) => paywall.metadata.headlessSurface === surface.id) ?? headless.find((paywall) => paywall.identifier === surface.id);
101
+ };
102
+ const match = matches(await listAppPaywalls(api, applicationId));
103
+ if (match) {
104
+ await requireAdoption(input.confirmAdopt, {
105
+ surface,
106
+ paywallId: match.id,
107
+ applicationId,
108
+ platform
109
+ });
110
+ writeBinding(superwallDir, surface.kind, surface.id, platform, { paywallId: match.id });
111
+ return {
112
+ paywallId: match.id,
113
+ applicationId,
114
+ platform,
115
+ source: "matched"
116
+ };
117
+ }
118
+ if (!create) throw new BindingError(`${describe(surface)} has never been pushed to \`${platform}\` — run \`superwall push\` first.`);
119
+ if (!input.renamesResolved) {
120
+ const onDisk = new Set(input.surfaces.filter((candidate) => candidate.kind === surface.kind).map((c) => c.id));
121
+ const orphans = Object.keys(section).filter((id) => !onDisk.has(id));
122
+ 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>\`.`);
123
+ }
124
+ const archived = matches(await listAppPaywalls(api, applicationId, { archived: true }));
125
+ 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.`);
126
+ const created = await createHeadlessPaywall(api, {
127
+ applicationId,
128
+ name: input.name?.trim() || humanize(surface.id),
129
+ identifier: surface.id
130
+ });
131
+ writeBinding(superwallDir, surface.kind, surface.id, platform, { paywallId: created.id });
132
+ return {
133
+ paywallId: created.id,
134
+ applicationId,
135
+ platform,
136
+ source: "created"
137
+ };
138
+ }
139
+ async function requireAdoption(confirm, candidate) {
140
+ if (confirm && await confirm(candidate)) return;
141
+ const { surface, paywallId, applicationId, platform } = candidate;
142
+ const lockLine = `"${surface.id}": { "${platform}": { "paywallId": "${paywallId}" } }`;
143
+ throw new BindingError([
144
+ `App ${applicationId} already has a paywall \`${surface.id}\` (${paywallId}) that superwall.lock doesn't bind, so nothing was pushed.`,
145
+ ` - It's yours: run \`superwall push\` interactively and confirm, or add ${lockLine} under "${surface.kind === "paywall" ? "paywalls" : "funnels"}" in superwall.lock.`,
146
+ ` - It isn't: rename the directory, and the next push creates a new paywall.`
147
+ ].join("\n"));
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/core/paywalls/binding/targets.ts
152
+ var TargetError = class extends Error {};
153
+ const surfaceKey = (surface) => `${surface.kind}/${surface.id}`;
154
+ const targetLabel = (target, multi) => multi ? `${target.surface.id} · ${target.platform}` : target.surface.id;
155
+ function wantedPlatforms(surfaces, declared) {
156
+ const wanted = /* @__PURE__ */ new Set();
157
+ for (const surface of surfaces) for (const platform of declared[surfaceKey(surface)] ?? []) wanted.add(platform);
158
+ return [...wanted];
159
+ }
160
+ function parsePlatformFlags(value) {
161
+ 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);
162
+ }
163
+ function planTargets(input) {
164
+ const { surfaces, declared, apps } = input;
165
+ const known = Object.keys(apps);
166
+ const only = (input.only ?? []).map((entry) => {
167
+ const platform = platformFor(apps, entry);
168
+ 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.`);
169
+ return platform;
170
+ });
171
+ const targets = [];
172
+ for (const surface of surfaces) {
173
+ const wanted = declared[surfaceKey(surface)];
174
+ let platforms;
175
+ if (wanted !== void 0) {
176
+ if (wanted.length === 0) throw new TargetError(`${surface.kind} \`${surface.id}\` declares \`platforms: []\` — list at least one, or remove the field.`);
177
+ 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.`);
178
+ platforms = [...new Set(wanted)];
179
+ } else if (known.length === 1 && known[0] !== void 0) platforms = [known[0]];
180
+ else if (known.length === 0) throw new TargetError("This project is not bound to an app yet — run `superwall push` to pick one.");
181
+ 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.`);
182
+ for (const platform of platforms) {
183
+ if (only.length > 0 && !only.includes(platform)) continue;
184
+ const applicationId = apps[platform];
185
+ if (applicationId === void 0) continue;
186
+ targets.push({
187
+ surface,
188
+ platform,
189
+ applicationId
190
+ });
191
+ }
192
+ }
193
+ if (targets.length === 0 && only.length > 0) throw new TargetError(`No paywall or funnel targets ${only.map((platform) => `\`${platform}\``).join(", ")}.`);
194
+ return targets;
195
+ }
196
+
197
+ //#endregion
198
+ //#region src/core/paywalls/products.ts
199
+ function storeOf(row) {
200
+ if (row.platform === "stripe") return "stripe";
201
+ if (row.store === "custom" || row.platform === "custom") return "custom";
202
+ if (row.store === "app_store") return "app-store";
203
+ if (row.store === "play_store") return "play-store";
204
+ }
205
+ async function listProjectCatalogue(api, projectId) {
206
+ const rows = await api.list(`/v2/products?project_id=${encodeURIComponent(projectId)}`);
207
+ const variables = /* @__PURE__ */ new Map();
208
+ const stores = /* @__PURE__ */ new Map();
209
+ for (const row of rows) {
210
+ if (!row.identifier) continue;
211
+ variables.set(row.identifier, productVariables(row));
212
+ const store = storeOf(row);
213
+ if (store === void 0) continue;
214
+ const known = stores.get(row.identifier) ?? [];
215
+ if (!known.includes(store)) stores.set(row.identifier, [...known, store]);
216
+ }
217
+ return {
218
+ variables: Object.fromEntries(variables),
219
+ stores: Object.fromEntries(stores)
220
+ };
221
+ }
222
+ async function listProjectProducts(api, projectId) {
223
+ return (await listProjectCatalogue(api, projectId)).variables;
224
+ }
225
+ async function listApplicationCatalogue(api, applicationId) {
226
+ const projectId = await projectForApplication(api, applicationId);
227
+ if (projectId === void 0) return {
228
+ variables: {},
229
+ stores: {}
230
+ };
231
+ return listProjectCatalogue(api, projectId);
232
+ }
233
+ async function projectForApplication(api, applicationId) {
234
+ const found = await findApplication(api, applicationId).catch(() => void 0);
235
+ return found ? String(found.project.id) : void 0;
236
+ }
237
+ var MissingProductError = class extends Error {};
238
+ function requireProducts(catalogue, surfaces) {
239
+ const gaps = surfaces.flatMap((surface) => Object.entries(surface.products ?? {}).filter(([, identifier]) => !Object.hasOwn(catalogue, identifier)).map(([reference, identifier]) => ` ${surface.id}: ${reference} → ${identifier}`));
240
+ if (gaps.length === 0) return;
241
+ throw new MissingProductError([
242
+ gaps.length === 1 ? "This product does not exist on Superwall:" : `These ${gaps.length} products do not exist on Superwall:`,
243
+ ...gaps,
244
+ "",
245
+ "Every variable on them would be undefined on device. Add them in the",
246
+ "dashboard, or point the config at products that exist."
247
+ ].join("\n"));
248
+ }
249
+
250
+ //#endregion
251
+ //#region src/core/paywalls/project/scaffold.ts
252
+ const REACT_VERSION = "19.1.0";
253
+ function projectPackageName(root) {
254
+ const name = path.basename(root).toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^[-._]+|[-._]+$/g, "");
255
+ return name === "" || name === "superwall" ? "superwall-project" : name;
256
+ }
257
+ function packageJson(name, frameworkVersion) {
258
+ return `${JSON.stringify({
259
+ name,
260
+ private: true,
261
+ type: "module",
262
+ scripts: {
263
+ dev: "superwall dev",
264
+ push: "superwall push",
265
+ promote: "superwall promote",
266
+ ship: "superwall publish"
267
+ },
268
+ dependencies: {
269
+ react: REACT_VERSION,
270
+ "react-dom": REACT_VERSION,
271
+ superwall: frameworkVersion === "unknown" ? "*" : `^${frameworkVersion}`
272
+ }
273
+ }, null, 2)}\n`;
274
+ }
275
+ const GITIGNORE = `node_modules/
276
+ .superwall
277
+ .env
278
+ `;
279
+ function writeIfAbsent(file, content) {
280
+ if (fs.existsSync(file)) return;
281
+ try {
282
+ fs.writeFileSync(file, content, { flag: "wx" });
283
+ } catch {
284
+ return;
285
+ }
286
+ }
287
+ function writeProjectScaffold(options) {
288
+ writeIfAbsent(path.join(options.superwallDir, "package.json"), packageJson(projectPackageName(options.root), options.frameworkVersion));
289
+ writeIfAbsent(path.join(options.superwallDir, ".gitignore"), GITIGNORE);
290
+ }
291
+
292
+ //#endregion
293
+ //#region src/core/paywalls/source/portability.ts
294
+ const SHOWN = 5;
295
+ function portabilityWarning(external) {
296
+ const names = [...new Set(external)].filter((entry) => entry.trim() !== "").sort();
297
+ if (names.length === 0) return void 0;
298
+ const shown = names.slice(0, SHOWN).join(", ");
299
+ const rest = names.length - SHOWN;
300
+ 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.`;
301
+ }
302
+ function warnNotPortable(external) {
303
+ const message = portabilityWarning(external);
304
+ if (message) ui.warn(message);
305
+ }
306
+
307
+ //#endregion
308
+ //#region src/core/paywalls/source/source.ts
309
+ const HARD_EXCLUDES = [
310
+ ".superwall/**",
311
+ "**/node_modules/**",
312
+ ".git/**",
313
+ "**/.env*",
314
+ "**/.DS_Store",
315
+ "**/.npmrc",
316
+ "**/.netrc",
317
+ "**/*.pem",
318
+ "**/*.p8",
319
+ "**/*.p12",
320
+ "**/*.key",
321
+ "**/*.keystore",
322
+ "**/*.jks",
323
+ "**/google-services.json",
324
+ "**/GoogleService-Info.plist"
325
+ ];
326
+ const LOCK_FILE = "superwall.lock";
327
+ const SOURCE_LIMIT_BYTES = 250 * 1024 * 1024;
328
+ const LARGEST_SHOWN = 3;
329
+ const megabytes = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
330
+ function gitignoreExcludes(superwallDir) {
331
+ let text;
332
+ try {
333
+ text = fs.readFileSync(path.join(superwallDir, ".gitignore"), "utf8");
334
+ } catch {
335
+ return [];
336
+ }
337
+ const excludes = [];
338
+ for (const raw of text.split("\n")) {
339
+ const line = raw.trim();
340
+ if (line === "" || line.startsWith("#") || line.startsWith("!")) continue;
341
+ const anchored = line.startsWith("/");
342
+ const body = (anchored ? line.slice(1) : line).replace(/\/+$/, "");
343
+ if (body === "") continue;
344
+ const base = anchored || body.includes("/") ? body : `**/${body}`;
345
+ excludes.push(base, `${base}/**`);
346
+ }
347
+ return excludes;
348
+ }
349
+ async function collectSourceFiles(superwallDir) {
350
+ const entries = await fg("**/*", {
351
+ cwd: superwallDir,
352
+ dot: true,
353
+ onlyFiles: true,
354
+ followSymbolicLinks: false,
355
+ ignore: [...HARD_EXCLUDES, ...gitignoreExcludes(superwallDir)]
356
+ });
357
+ if (entries.length === 0) return {
358
+ ok: false,
359
+ reason: `No source files found in ${superwallDir}.`
360
+ };
361
+ const sizes = entries.map((relative$1) => ({
362
+ path: relative$1,
363
+ bytes: fs.statSync(path.join(superwallDir, relative$1)).size
364
+ }));
365
+ const total = sizes.reduce((sum, entry) => sum + entry.bytes, 0);
366
+ if (total > SOURCE_LIMIT_BYTES) {
367
+ const largest = sizes.sort((a, b) => b.bytes - a.bytes).slice(0, LARGEST_SHOWN).map((entry) => `${entry.path} (${megabytes(entry.bytes)})`).join(", ");
368
+ return {
369
+ ok: false,
370
+ reason: `The source in ${superwallDir} is ${megabytes(total)}, over the ${SOURCE_LIMIT_BYTES / 1024 / 1024} MB limit. Largest: ${largest}. Add what doesn't belong to .gitignore, then push again.`
371
+ };
372
+ }
373
+ return {
374
+ ok: true,
375
+ files: entries.sort().map((relative$1) => ({
376
+ path: relative$1,
377
+ content: relative$1 === LOCK_FILE ? Buffer.from(formatSharedLock(superwallDir)) : fs.readFileSync(path.join(superwallDir, relative$1))
378
+ }))
379
+ };
380
+ }
381
+
382
+ //#endregion
383
+ //#region src/core/paywalls/source/base.ts
384
+ const LEGACY_FILE = path.join(".superwall", "source.json");
385
+ function readLegacyBases(superwallDir) {
386
+ const file = path.join(superwallDir, LEGACY_FILE);
387
+ if (!fs.existsSync(file)) return {};
388
+ let parsed;
389
+ try {
390
+ parsed = JSON.parse(fs.readFileSync(file, "utf8"));
391
+ } catch (error) {
392
+ const reason = error instanceof Error ? error.message : String(error);
393
+ throw new Error(`Can't read ${file} (${reason}) — fix or delete it, then push again.`);
394
+ }
395
+ if (!isRecord(parsed) || !isRecord(parsed.repos)) throw new Error(`${file} isn't a source sync record — fix or delete it, then push again.`);
396
+ return parseSources(parsed.repos);
397
+ }
398
+ function readSourceBase(superwallDir, repo) {
399
+ return readLock(superwallDir).sources?.[repo] ?? readLegacyBases(superwallDir)[repo];
400
+ }
401
+ function writeSourceBase(superwallDir, repo, commitSha) {
402
+ writeSources(superwallDir, {
403
+ ...readLegacyBases(superwallDir),
404
+ ...readLock(superwallDir).sources,
405
+ [repo]: commitSha
406
+ });
407
+ fs.rmSync(path.join(superwallDir, LEGACY_FILE), { force: true });
408
+ }
409
+
410
+ //#endregion
411
+ //#region src/core/paywalls/source/commit.ts
412
+ const buildCommitMessage = (input) => {
413
+ const surface = `${input.kind}/${input.surface}`;
414
+ const subject = `publish ${surface} v${input.version}`;
415
+ const external = (input.external ?? []).filter((entry) => entry.trim() !== "");
416
+ const trailers = [
417
+ `Superwall-Paywall: ${input.paywallId}`,
418
+ `Superwall-Application: ${input.applicationId}`,
419
+ `Superwall-Version: ${input.version}`,
420
+ `Superwall-Surface: ${surface}`,
421
+ `Superwall-Portable: ${external.length === 0}`
422
+ ];
423
+ if (external.length > 0) trailers.push(`Superwall-External: ${external.join(", ")}`);
424
+ if (input.snapshotSha) trailers.push(`Superwall-Snapshot: ${input.snapshotSha}`);
425
+ trailers.push(`Superwall-Framework: ${input.framework}`);
426
+ if (input.cli) trailers.push(`Superwall-Cli: ${input.cli}`);
427
+ const note = input.note?.replace(/\r\n?/g, "\n").trim();
428
+ return `${subject}\n${note ? `\n${note}\n` : ""}\n${trailers.join("\n")}\n`;
429
+ };
430
+ const tokenSecret = (token) => token.split("?")[0] ?? token;
431
+ const redact = (text, ...secrets) => {
432
+ let safe = text;
433
+ for (const secret of secrets) {
434
+ if (secret.length < 8) continue;
435
+ safe = safe.split(secret).join("***");
436
+ }
437
+ return safe;
438
+ };
439
+
440
+ //#endregion
441
+ //#region src/core/paywalls/source/git.ts
442
+ const run = promisify(execFile);
443
+ const AUTHOR = {
444
+ name: "Superwall",
445
+ email: "publish@superwall.com"
446
+ };
447
+ var GitError = class extends Error {};
448
+ const REPOSITORY_ENV = new Set([
449
+ "GIT_DIR",
450
+ "GIT_WORK_TREE",
451
+ "GIT_INDEX_FILE",
452
+ "GIT_OBJECT_DIRECTORY",
453
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
454
+ "GIT_COMMON_DIR",
455
+ "GIT_NAMESPACE",
456
+ "GIT_CONFIG_PARAMETERS"
457
+ ]);
458
+ const gitEnv = (token, extra = {}) => ({
459
+ ...Object.fromEntries(Object.entries(process.env).filter(([key]) => !REPOSITORY_ENV.has(key))),
460
+ GIT_CONFIG_COUNT: "1",
461
+ GIT_CONFIG_KEY_0: "http.extraHeader",
462
+ GIT_CONFIG_VALUE_0: `Authorization: Bearer ${tokenSecret(token)}`,
463
+ GIT_TERMINAL_PROMPT: "0",
464
+ ...extra
465
+ });
466
+ const GIT_TIMEOUT_MS = 300 * 1e3;
467
+ const ISOLATION = [
468
+ "-c",
469
+ "commit.gpgsign=false",
470
+ "-c",
471
+ "core.hooksPath=/dev/null",
472
+ "-c",
473
+ "core.autocrlf=false"
474
+ ];
475
+ async function git(args, options = {}) {
476
+ try {
477
+ const { stdout } = await run("git", [...ISOLATION, ...args], {
478
+ cwd: options.cwd,
479
+ env: options.env,
480
+ maxBuffer: 64 * 1024 * 1024,
481
+ timeout: GIT_TIMEOUT_MS
482
+ });
483
+ return stdout;
484
+ } catch (error) {
485
+ if (typeof error === "object" && error !== null && Reflect.get(error, "killed") === true) throw new GitError(`git ${args[0]} timed out after ${GIT_TIMEOUT_MS / 6e4} minutes.`);
486
+ const detail = typeof error === "object" && error !== null ? String(Reflect.get(error, "stderr") ?? Reflect.get(error, "message") ?? error) : String(error);
487
+ throw new GitError(redact(`git ${args[0]} failed: ${gitReason(detail)}`, ...options.secrets ?? []));
488
+ }
489
+ }
490
+ function gitReason(stderr) {
491
+ const lines = stderr.split("\n").map((line) => line.trim()).filter((line) => line !== "" && !line.startsWith("Command failed:"));
492
+ return (lines.find((line) => /^(fatal|error):/.test(line)) ?? lines[lines.length - 1] ?? "").replace(/^(fatal|error):\s*/, "") || "git reported no reason.";
493
+ }
494
+ async function gitAvailable() {
495
+ try {
496
+ await run("git", ["--version"]);
497
+ return true;
498
+ } catch {
499
+ return false;
500
+ }
501
+ }
502
+ const LARGE_FILE_BYTES = 50 * 1024 * 1024;
503
+ function materializeSourceTree(dir, files) {
504
+ for (const entry of fs.readdirSync(dir)) {
505
+ if (entry === ".git") continue;
506
+ fs.rmSync(path.join(dir, entry), {
507
+ recursive: true,
508
+ force: true
509
+ });
510
+ }
511
+ const write = (relative$1, data) => {
512
+ const file = path.join(dir, relative$1);
513
+ fs.mkdirSync(path.dirname(file), { recursive: true });
514
+ fs.writeFileSync(file, data);
515
+ };
516
+ const large = [];
517
+ for (const file of files) {
518
+ if (file.content.byteLength > LARGE_FILE_BYTES) large.push(file.path);
519
+ write(file.path, file.content);
520
+ }
521
+ 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.`);
522
+ }
523
+ const SHOWN_FILES = 5;
524
+ const listFiles = (files) => {
525
+ const shown = files.slice(0, SHOWN_FILES).join(", ");
526
+ const rest = files.length - SHOWN_FILES;
527
+ return rest > 0 ? `${shown} and ${rest} more` : shown;
528
+ };
529
+ var SourceConflictError = class extends Error {
530
+ constructor(files) {
531
+ super(`Someone else published changes to ${listFiles(files)} since this project last synced. Pull their commits into this project, then publish again — or rerun with --overwrite-source to replace their version with yours.`);
532
+ this.files = files;
533
+ }
534
+ };
535
+ var SourceDivergedError = class extends Error {
536
+ constructor(files) {
537
+ super(`The source repo differs from this project in ${listFiles(files)}, and superwall.lock records no sync point to merge from. Pull the latest superwall.lock, or rerun with --overwrite-source to replace the remote source with yours.`);
538
+ this.files = files;
539
+ }
540
+ };
541
+ const PUSH_ATTEMPTS = 3;
542
+ async function pushSourceTree(input) {
543
+ const { access } = input;
544
+ const secrets = [access.token, tokenSecret(access.token)];
545
+ const dir = fs.mkdtempSync(path.join(os$1.tmpdir(), "superwall-source-"));
546
+ const env = gitEnv(access.token);
547
+ const committing = gitEnv(access.token, {
548
+ GIT_AUTHOR_NAME: process.env.GIT_AUTHOR_NAME || AUTHOR.name,
549
+ GIT_AUTHOR_EMAIL: process.env.GIT_AUTHOR_EMAIL || AUTHOR.email,
550
+ GIT_COMMITTER_NAME: AUTHOR.name,
551
+ GIT_COMMITTER_EMAIL: AUTHOR.email
552
+ });
553
+ const run$1 = (args, options = {}) => git(args, {
554
+ cwd: dir,
555
+ env: options.env ?? env,
556
+ secrets
557
+ });
558
+ const revParse = (ref) => run$1([
559
+ "rev-parse",
560
+ "--verify",
561
+ "--quiet",
562
+ `${ref}^{commit}`
563
+ ]).then((out) => out.trim(), () => void 0);
564
+ try {
565
+ await cloneSource(access, dir, {
566
+ env,
567
+ secrets
568
+ });
569
+ const head = await revParse("HEAD");
570
+ const base = input.base && head && !input.overwrite ? await revParse(input.base) : void 0;
571
+ if (base && base !== head) await run$1([
572
+ "checkout",
573
+ "--quiet",
574
+ "--detach",
575
+ base
576
+ ]);
577
+ materializeSourceTree(dir, input.files);
578
+ await run$1(["add", "-A"]);
579
+ if ((await run$1(["status", "--porcelain"])).trim() === "") return {
580
+ commitSha: head ?? "",
581
+ status: "unchanged",
582
+ syncedTo: base ?? head
583
+ };
584
+ if (head && !base && !input.overwrite) throw new SourceDivergedError((await run$1([
585
+ "diff",
586
+ "--cached",
587
+ "--name-only",
588
+ "-z",
589
+ "HEAD"
590
+ ])).split("\0").filter(Boolean));
591
+ const messageFile = path.join(dir, ".git", "SUPERWALL_COMMITMSG");
592
+ fs.writeFileSync(messageFile, buildCommitMessage(input.message));
593
+ await run$1([
594
+ "commit",
595
+ "--quiet",
596
+ "--no-verify",
597
+ "-F",
598
+ messageFile
599
+ ], { env: committing });
600
+ const own = await revParse("HEAD");
601
+ if (!own) throw new Error("The source commit was not created.");
602
+ const isAncestor = (ancestor, of) => run$1([
603
+ "merge-base",
604
+ "--is-ancestor",
605
+ ancestor,
606
+ of
607
+ ]).then(() => true, () => false);
608
+ for (let attempt = 1;; attempt++) {
609
+ const upstream = base ? await revParse(`origin/${access.branch}`) : void 0;
610
+ if (upstream && upstream !== base) {
611
+ if (await isAncestor(own, upstream)) return {
612
+ commitSha: upstream,
613
+ status: "unchanged",
614
+ syncedTo: own
615
+ };
616
+ await run$1([
617
+ "reset",
618
+ "--quiet",
619
+ "--hard",
620
+ own
621
+ ]);
622
+ await mergeUpstream(`origin/${access.branch}`, messageFile, {
623
+ run: run$1,
624
+ committing
625
+ });
626
+ }
627
+ try {
628
+ await run$1([
629
+ "push",
630
+ "origin",
631
+ `HEAD:${access.branch}`
632
+ ]);
633
+ return {
634
+ commitSha: await revParse("HEAD") ?? own,
635
+ status: "committed",
636
+ syncedTo: own
637
+ };
638
+ } catch (error) {
639
+ if (!base || attempt >= PUSH_ATTEMPTS || !isRejected(error)) throw error;
640
+ await run$1([
641
+ "fetch",
642
+ "--quiet",
643
+ "origin",
644
+ access.branch
645
+ ]);
646
+ }
647
+ }
648
+ } finally {
649
+ fs.rmSync(dir, {
650
+ recursive: true,
651
+ force: true
652
+ });
653
+ }
654
+ }
655
+ const CLONE_ATTEMPTS = [
656
+ ["--filter=blob:none", "--branch"],
657
+ ["--branch"],
658
+ ["--filter=blob:none"],
659
+ []
660
+ ];
661
+ const CLONE_FALLBACK = /remote branch .* not found|filter/i;
662
+ async function cloneSource(access, dir, options) {
663
+ let first;
664
+ for (const flags of CLONE_ATTEMPTS) {
665
+ const branch = flags.includes("--branch") ? [access.branch] : [];
666
+ try {
667
+ await git([
668
+ "clone",
669
+ "--quiet",
670
+ ...flags,
671
+ ...branch,
672
+ access.remote,
673
+ dir
674
+ ], options);
675
+ return;
676
+ } catch (error) {
677
+ first ??= error;
678
+ if (!(error instanceof GitError) || !CLONE_FALLBACK.test(error.message)) throw error;
679
+ fs.rmSync(dir, {
680
+ recursive: true,
681
+ force: true
682
+ });
683
+ fs.mkdirSync(dir);
684
+ }
685
+ }
686
+ throw first;
687
+ }
688
+ async function mergeUpstream(upstream, messageFile, { run: run$1, committing }) {
689
+ try {
690
+ await run$1([
691
+ "merge",
692
+ "--quiet",
693
+ "--no-ff",
694
+ "-F",
695
+ messageFile,
696
+ upstream
697
+ ], { env: committing });
698
+ } catch (error) {
699
+ const conflicted = await run$1([
700
+ "diff",
701
+ "--name-only",
702
+ "--diff-filter=U"
703
+ ]).then((out) => out.split("\n").map((line) => line.trim()).filter(Boolean), () => []);
704
+ await run$1(["merge", "--abort"]).catch(() => void 0);
705
+ if (conflicted.length > 0) throw new SourceConflictError(conflicted);
706
+ throw error;
707
+ }
708
+ }
709
+ const isRejected = (error) => error instanceof GitError && /rejected|non-fast-forward|fetch first|stale info|failed to push some refs/i.test(error.message);
710
+
711
+ //#endregion
712
+ //#region src/core/paywalls/source/source-push.ts
713
+ var GitRequiredError = class extends Error {
714
+ constructor() {
715
+ super("superwall publish requires git for the source step — install git");
716
+ }
717
+ };
718
+ async function assertGit(hasGit = gitAvailable) {
719
+ if (!await hasGit()) throw new GitRequiredError();
720
+ }
721
+ async function pushSource(input) {
722
+ for (let attempt = 0;; attempt++) {
723
+ const access = await mintSourceAccess(input.api, input.paywallId);
724
+ const pushed = await pushSourceTree({
725
+ access,
726
+ base: readSourceBase(input.superwallDir, access.repo),
727
+ overwrite: input.overwrite,
728
+ files: input.files,
729
+ message: {
730
+ kind: input.kind,
731
+ surface: input.surface,
732
+ version: input.version,
733
+ paywallId: input.paywallId,
734
+ applicationId: input.applicationId,
735
+ snapshotSha: input.snapshotId,
736
+ framework: input.framework,
737
+ cli: input.cli,
738
+ note: input.note,
739
+ external: input.external
740
+ }
741
+ });
742
+ if (pushed.syncedTo) writeSourceBase(input.superwallDir, access.repo, pushed.syncedTo);
743
+ try {
744
+ await linkCommit(input, access, pushed.commitSha);
745
+ return pushed;
746
+ } catch (error) {
747
+ if (attempt === 0 && error instanceof ApiError && error.status === 409) continue;
748
+ throw error;
749
+ }
750
+ }
751
+ }
752
+ const LINK_ATTEMPTS = 2;
753
+ const LINK_RETRY_DELAY_MS = 300;
754
+ async function linkCommit(input, access, commitSha) {
755
+ for (let attempt = 1;; attempt++) try {
756
+ await linkSourceCommit(input.api, input.paywallId, input.version, {
757
+ commitSha,
758
+ tokenId: access.tokenId
759
+ });
760
+ return;
761
+ } catch (error) {
762
+ if (attempt >= LINK_ATTEMPTS || !isTransient(error)) throw error;
763
+ await setTimeout(LINK_RETRY_DELAY_MS);
764
+ }
765
+ }
766
+ const isTransient = (error) => error instanceof ApiUnreachableError || error instanceof ApiError && error.status >= 500;
767
+
768
+ //#endregion
769
+ //#region src/core/paywalls/project/session.ts
770
+ var LoginRequiredError = class extends Error {
771
+ constructor() {
772
+ super(`Pushing paywalls needs a Superwall account.
773
+ Interactively: run \`superwall login\`.
774
+ In CI or an agent: set ${ENV_API_KEY} to an org API key (sk_…).`);
775
+ this.name = "LoginRequiredError";
776
+ }
777
+ };
778
+ async function requireApi(interactive, login = performLoginWithUi) {
779
+ const apiKey = apiKeyFromEnv();
780
+ if (apiKey) return createSuperwallApi({
781
+ authMethod: "api_key",
782
+ apiKey,
783
+ host: process.env.SUPERWALL_API_HOST ?? API_HOST(),
784
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
785
+ });
786
+ const session = readSession();
787
+ if (session) return createSuperwallApi(session);
788
+ if (!interactive) throw new LoginRequiredError();
789
+ ui.info("You're not signed in to Superwall yet — let's fix that.");
790
+ const signedIn = await login();
791
+ if (!signedIn) throw new LoginRequiredError();
792
+ return createSuperwallApi(signedIn);
793
+ }
794
+
795
+ //#endregion
796
+ export { targetLabel as _, gitAvailable as a, requirePlatform as b, projectPackageName as c, listProjectCatalogue as d, listProjectProducts as f, planTargets as g, parsePlatformFlags as h, pushSource as i, writeProjectScaffold as l, requireProducts as m, requireApi as n, collectSourceFiles as o, projectForApplication as p, assertGit as r, warnNotPortable as s, LoginRequiredError as t, listApplicationCatalogue as u, wantedPlatforms as v, resolveApps as x, resolveBinding as y };