@superwall/cli 1.6.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -34
- package/dist/apple-CkKlHBZ9.js +195 -0
- package/dist/auth.d.ts +4 -19
- package/dist/auth.js +4 -2
- package/dist/{actions-H7f6knyY.js → billing-XCZU_T46.js} +98 -28
- package/dist/{bind-BIzaGq8K.js → bind-drne__Ys.js} +38 -33
- package/dist/{build-B7BS1rF2.js → build-Gpdq5QXP.js} +20 -26
- package/dist/client-BZ1UbpXz.js +66 -0
- package/dist/client-DP6Rc0t_.js +176 -0
- package/dist/config-BO1Y87kV.js +105 -0
- package/dist/create-BBrtgUgS.js +969 -0
- package/dist/{create-CwnnNqv4.js → create-Cwc3SRWJ.js} +194 -168
- package/dist/create-Yvf2gStM.js +19 -0
- package/dist/doctor-C9ldpPFC.js +83 -0
- package/dist/{drivers-6RMOPIdn.js → drivers-DNrx4LWA.js} +185 -172
- package/dist/entry.d.ts +0 -5
- package/dist/entry.js +28083 -801
- package/dist/environment-DF1qKlny.js +58 -0
- package/dist/{existing-DHpPn1y6.js → existing-78LWSsqS.js} +12 -6
- package/dist/held-Cy8Wl4D1.js +1112 -0
- package/dist/held-Ddw1XSsr.js +16 -0
- package/dist/input-vi0bou04.js +42 -0
- package/dist/{integrate-BR2LR-EK.js → integrate-DcJhpXy8.js} +277 -253
- package/dist/kinds-GFXB3sYu.js +11 -0
- package/dist/log-NVhVe_oe.js +62 -0
- package/dist/login-B2TsCE2H.js +53 -0
- package/dist/login-BoBe8Psl.js +16 -0
- package/dist/{login-Bhxgqwtm.js → login-D0lh3_JI.js} +144 -66
- package/dist/lookup-D-nmmAbw.js +71 -0
- package/dist/migrate-Cfec564E.js +274 -0
- package/dist/notification-url-YDbq6FMA.js +100 -0
- package/dist/{open-studio-BnVD6tJ9.js → open-Ba2vBl1_.js} +34 -43
- package/dist/org-D0g_q3mv.js +35 -0
- package/dist/output-Ggzq5_-t.js +122 -0
- package/dist/paths-DxSLdpOI.js +29 -0
- package/dist/playbook-DIeb7hne.js +53 -0
- package/dist/{asc-products-Dvcyef3_.js → products-DH_fK9tY.js} +6 -39
- package/dist/promote-COD4fYdz.js +91 -0
- package/dist/push-CncywhkQ.js +482 -0
- package/dist/push-CtD4FZQV.js +22 -0
- package/dist/registry-DSrosOYs.js +10228 -0
- package/dist/{reports-DqMs9xNR.js → reports-DdPq4blM.js} +7 -6
- package/dist/{resources-Bf9O1JNM.js → resources-Dqr01Dep.js} +150 -55
- package/dist/{run-D-NbZLpj.js → run-C9qg_QlC.js} +16 -22
- package/dist/scan-Cv5uOwVY.js +4 -0
- package/dist/{scan-BmAW413l.js → scan-DLrsrFS9.js} +48 -37
- package/dist/scope-V336uz8j.js +198 -0
- package/dist/screenshot-file-0UETadF8.js +16 -0
- package/dist/{selection-BGi6GyxC.js → selection-Rdw-ZUoG.js} +94 -51
- package/dist/send-BxD9yf6F.js +150 -0
- package/dist/{dev-CgGAb5Al.js → server-D0tGG8C4.js} +82 -87
- package/dist/server-z1LH94R_.js +22 -0
- package/dist/session-1AV_Bs_d.js +6 -0
- package/dist/session-CFAmMhem.js +40 -0
- package/dist/session-D_nEWKXT.js +768 -0
- package/dist/skills/animate-onboarding/SKILL.md +467 -0
- package/dist/skills/animate-onboarding/references/engine.md +494 -0
- package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
- package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
- package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
- package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
- package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
- package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
- package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
- package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
- package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
- package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
- package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
- package/dist/skills/animate-onboarding/references/performance.md +41 -0
- package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
- package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
- package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
- package/dist/skills/index.json +37 -0
- package/dist/skills/mobile-design/SKILL.md +447 -0
- package/dist/skills/mobile-design/references/responsive.md +162 -0
- package/dist/skills/onboarding-questions/SKILL.md +231 -0
- package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
- package/dist/skills/onboarding-questions/references/craft.md +142 -0
- package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
- package/dist/skills/superwall/SKILL.md +82 -9
- package/dist/skills/superwall/references/api.md +153 -37
- package/dist/skills/superwall/references/apple-setup.md +316 -0
- package/dist/skills/superwall/references/asc.md +74 -38
- package/dist/skills/superwall/references/data-analytics.md +55 -21
- package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
- package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
- package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
- package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
- package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
- package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
- package/dist/skills/superwall/workflows/placements/android.md +2 -2
- package/dist/skills/superwall/workflows/placements/expo.md +2 -2
- package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
- package/dist/skills/superwall/workflows/placements/ios.md +2 -2
- package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
- package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
- package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
- package/dist/skills/superwall/workflows/review/playbook.md +1 -1
- package/dist/skills/superwall-editor/SKILL.md +61 -0
- package/dist/skills/superwall-editor/references/cli.md +135 -0
- package/dist/skills/superwall-editor/references/design.md +51 -0
- package/dist/skills/superwall-editor/references/native-elements.md +171 -0
- package/dist/skills/superwall-editor/references/workflow.md +65 -0
- package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
- package/dist/skills/superwall-framework/SKILL.md +78 -28
- package/dist/skills/superwall-framework/references/cli.md +58 -28
- package/dist/skills/superwall-framework/references/examples.md +4 -3
- package/dist/skills/superwall-framework/references/layout.md +30 -8
- package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
- package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
- package/dist/skills/wwdc/SKILL.md +22 -0
- package/dist/skills/wwdc/references/docs.md +52 -0
- package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
- package/dist/{skills-AxAf7bDB.js → skills-BvFOa4y6.js} +99 -122
- package/dist/skills-DMG4bpKk.js +14 -0
- package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
- package/dist/spinner-CneRK5rk.js +294 -0
- package/dist/storage-DYvmIOHa.d.ts +16 -0
- package/dist/storage-s2Dnz-yl.js +31 -0
- package/dist/storekit-DafAnGkM.js +16 -0
- package/dist/storekit-yY_kS2iR.js +47 -0
- package/dist/telemetry-DtG92m5O.js +56 -0
- package/dist/theme-DUsCh-Vd.js +25 -0
- package/dist/timing-BVxPrYq3.js +5 -0
- package/dist/{token-BGAVPSQc.js → token-DzRh7dI1.js} +6 -38
- package/dist/tools.d.ts +96 -0
- package/dist/tools.js +11178 -0
- package/dist/ui-D_qf3Gvw.js +53 -0
- package/dist/upgrade-Bt4Ouw1y.js +117 -0
- package/dist/upgrade-Cqy5orjb.js +7 -0
- package/package.json +10 -5
- package/dist/api-Dv3LyZ5m.js +0 -151
- package/dist/api-output-aJNw7Syy.js +0 -20
- package/dist/app-mJC5NDtW.js +0 -189
- package/dist/asa-D6H7Pjae.js +0 -1194
- package/dist/asc-xCin0akG.js +0 -539
- package/dist/auth-ZlLL-Gko.js +0 -139
- package/dist/billing-C8kBge_S.js +0 -80
- package/dist/command-3fGYyC8r.js +0 -301
- package/dist/dev-Dx99K183.js +0 -22
- package/dist/doctor-CyUvut31.js +0 -88
- package/dist/feedback-RKyGuQ8_.js +0 -152
- package/dist/hosted-BeGVAntr.js +0 -32
- package/dist/migrate-C-4ISELN.js +0 -284
- package/dist/org-CQduIOic.js +0 -40
- package/dist/output-C-4UKMot.js +0 -136
- package/dist/params-l3CrvRtR.js +0 -51
- package/dist/pipeline-CHX0Syre.js +0 -977
- package/dist/print-skill-BiZLdCKv.js +0 -74
- package/dist/promote-Pgpz-3xl.js +0 -88
- package/dist/publish-BPeuc3lq.js +0 -35
- package/dist/push-DcSQ4odB.js +0 -35
- package/dist/query-CWLaZkdm.js +0 -53
- package/dist/resource-jwASPCrw.js +0 -483
- package/dist/skills-FK5aDuNV.js +0 -64
- package/dist/spinner-DFctF_Jw.js +0 -18
- package/dist/storekit-CC4gnTI6.js +0 -29
- package/dist/telemetry-Ch9cCTI-.js +0 -169
- package/dist/ui-4gLyfrgl.js +0 -27737
- package/dist/update-DIXbL-H9.js +0 -59
- package/dist/upgrade-De7JMI1g.js +0 -72
- /package/dist/{devtools-8EgLo86w.js → devtools-ByZ6XYnn.js} +0 -0
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
import { l as ENV_API_KEY, t as API_HOST, v as apiKeyFromEnv } from "./environment-DF1qKlny.js";
|
|
2
|
+
import { t as readSession } from "./storage-s2Dnz-yl.js";
|
|
3
|
+
import { n as ApiUnreachableError, r as createSuperwallApi, t as ApiError } from "./client-DP6Rc0t_.js";
|
|
4
|
+
import { n as ui } from "./ui-D_qf3Gvw.js";
|
|
5
|
+
import { E as isRecord, _ as mintSourceAccess, a as createHeadlessPaywall, d as listAppPaywalls, f as listApplications, u as linkSourceCommit, v as platformLabel } from "./resources-Dqr01Dep.js";
|
|
6
|
+
import { n as findApplication } from "./lookup-D-nmmAbw.js";
|
|
7
|
+
import { A as writeSources, C as readLock, E as writeBinding, S as parseSources, T as writeApp, b as formatSharedLock } from "./selection-Rdw-ZUoG.js";
|
|
8
|
+
import { n as performLoginWithUi } from "./login-B2TsCE2H.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
|
+
async function listProjectProducts(api, projectId) {
|
|
200
|
+
const rows = await api.list(`/v2/products?project_id=${encodeURIComponent(projectId)}`);
|
|
201
|
+
const catalogue = {};
|
|
202
|
+
for (const row of rows) if (row.identifier) catalogue[row.identifier] = productVariables(row);
|
|
203
|
+
return catalogue;
|
|
204
|
+
}
|
|
205
|
+
async function projectForApplication(api, applicationId) {
|
|
206
|
+
const found = await findApplication(api, applicationId).catch(() => void 0);
|
|
207
|
+
return found ? String(found.project.id) : void 0;
|
|
208
|
+
}
|
|
209
|
+
var MissingProductError = class extends Error {};
|
|
210
|
+
function requireProducts(catalogue, surfaces) {
|
|
211
|
+
const gaps = surfaces.flatMap((surface) => Object.entries(surface.products ?? {}).filter(([, identifier]) => catalogue[identifier] === void 0).map(([reference, identifier]) => ` ${surface.id}: ${reference} → ${identifier}`));
|
|
212
|
+
if (gaps.length === 0) return;
|
|
213
|
+
throw new MissingProductError([
|
|
214
|
+
gaps.length === 1 ? "This product does not exist on Superwall:" : `These ${gaps.length} products do not exist on Superwall:`,
|
|
215
|
+
...gaps,
|
|
216
|
+
"",
|
|
217
|
+
"Every variable on them would be undefined on device. Add them in the",
|
|
218
|
+
"dashboard, or point the config at products that exist."
|
|
219
|
+
].join("\n"));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/core/paywalls/project/scaffold.ts
|
|
224
|
+
const REACT_VERSION = "19.1.0";
|
|
225
|
+
function projectPackageName(root) {
|
|
226
|
+
const name = path.basename(root).toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^[-._]+|[-._]+$/g, "");
|
|
227
|
+
return name === "" || name === "superwall" ? "superwall-project" : name;
|
|
228
|
+
}
|
|
229
|
+
function packageJson(name, frameworkVersion) {
|
|
230
|
+
return `${JSON.stringify({
|
|
231
|
+
name,
|
|
232
|
+
private: true,
|
|
233
|
+
type: "module",
|
|
234
|
+
scripts: {
|
|
235
|
+
dev: "superwall dev",
|
|
236
|
+
push: "superwall push",
|
|
237
|
+
promote: "superwall promote",
|
|
238
|
+
ship: "superwall publish"
|
|
239
|
+
},
|
|
240
|
+
dependencies: {
|
|
241
|
+
react: REACT_VERSION,
|
|
242
|
+
"react-dom": REACT_VERSION,
|
|
243
|
+
superwall: frameworkVersion === "unknown" ? "*" : `^${frameworkVersion}`
|
|
244
|
+
}
|
|
245
|
+
}, null, 2)}\n`;
|
|
246
|
+
}
|
|
247
|
+
const GITIGNORE = `node_modules/
|
|
248
|
+
.superwall
|
|
249
|
+
.env
|
|
250
|
+
`;
|
|
251
|
+
function writeIfAbsent(file, content) {
|
|
252
|
+
if (fs.existsSync(file)) return;
|
|
253
|
+
try {
|
|
254
|
+
fs.writeFileSync(file, content, { flag: "wx" });
|
|
255
|
+
} catch {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function writeProjectScaffold(options) {
|
|
260
|
+
writeIfAbsent(path.join(options.superwallDir, "package.json"), packageJson(projectPackageName(options.root), options.frameworkVersion));
|
|
261
|
+
writeIfAbsent(path.join(options.superwallDir, ".gitignore"), GITIGNORE);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/core/paywalls/source/portability.ts
|
|
266
|
+
const SHOWN = 5;
|
|
267
|
+
function portabilityWarning(external) {
|
|
268
|
+
const names = [...new Set(external)].filter((entry) => entry.trim() !== "").sort();
|
|
269
|
+
if (names.length === 0) return void 0;
|
|
270
|
+
const shown = names.slice(0, SHOWN).join(", ");
|
|
271
|
+
const rest = names.length - SHOWN;
|
|
272
|
+
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.`;
|
|
273
|
+
}
|
|
274
|
+
function warnNotPortable(external) {
|
|
275
|
+
const message = portabilityWarning(external);
|
|
276
|
+
if (message) ui.warn(message);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/core/paywalls/source/source.ts
|
|
281
|
+
const HARD_EXCLUDES = [
|
|
282
|
+
".superwall/**",
|
|
283
|
+
"**/node_modules/**",
|
|
284
|
+
".git/**",
|
|
285
|
+
"**/.env*",
|
|
286
|
+
"**/.DS_Store",
|
|
287
|
+
"**/.npmrc",
|
|
288
|
+
"**/.netrc",
|
|
289
|
+
"**/*.pem",
|
|
290
|
+
"**/*.p8",
|
|
291
|
+
"**/*.p12",
|
|
292
|
+
"**/*.key",
|
|
293
|
+
"**/*.keystore",
|
|
294
|
+
"**/*.jks",
|
|
295
|
+
"**/google-services.json",
|
|
296
|
+
"**/GoogleService-Info.plist"
|
|
297
|
+
];
|
|
298
|
+
const LOCK_FILE = "superwall.lock";
|
|
299
|
+
const SOURCE_LIMIT_BYTES = 250 * 1024 * 1024;
|
|
300
|
+
const LARGEST_SHOWN = 3;
|
|
301
|
+
const megabytes = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
302
|
+
function gitignoreExcludes(superwallDir) {
|
|
303
|
+
let text;
|
|
304
|
+
try {
|
|
305
|
+
text = fs.readFileSync(path.join(superwallDir, ".gitignore"), "utf8");
|
|
306
|
+
} catch {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
const excludes = [];
|
|
310
|
+
for (const raw of text.split("\n")) {
|
|
311
|
+
const line = raw.trim();
|
|
312
|
+
if (line === "" || line.startsWith("#") || line.startsWith("!")) continue;
|
|
313
|
+
const anchored = line.startsWith("/");
|
|
314
|
+
const body = (anchored ? line.slice(1) : line).replace(/\/+$/, "");
|
|
315
|
+
if (body === "") continue;
|
|
316
|
+
const base = anchored || body.includes("/") ? body : `**/${body}`;
|
|
317
|
+
excludes.push(base, `${base}/**`);
|
|
318
|
+
}
|
|
319
|
+
return excludes;
|
|
320
|
+
}
|
|
321
|
+
async function collectSourceFiles(superwallDir) {
|
|
322
|
+
const entries = await fg("**/*", {
|
|
323
|
+
cwd: superwallDir,
|
|
324
|
+
dot: true,
|
|
325
|
+
onlyFiles: true,
|
|
326
|
+
followSymbolicLinks: false,
|
|
327
|
+
ignore: [...HARD_EXCLUDES, ...gitignoreExcludes(superwallDir)]
|
|
328
|
+
});
|
|
329
|
+
if (entries.length === 0) return {
|
|
330
|
+
ok: false,
|
|
331
|
+
reason: `No source files found in ${superwallDir}.`
|
|
332
|
+
};
|
|
333
|
+
const sizes = entries.map((relative$1) => ({
|
|
334
|
+
path: relative$1,
|
|
335
|
+
bytes: fs.statSync(path.join(superwallDir, relative$1)).size
|
|
336
|
+
}));
|
|
337
|
+
const total = sizes.reduce((sum, entry) => sum + entry.bytes, 0);
|
|
338
|
+
if (total > SOURCE_LIMIT_BYTES) {
|
|
339
|
+
const largest = sizes.sort((a, b) => b.bytes - a.bytes).slice(0, LARGEST_SHOWN).map((entry) => `${entry.path} (${megabytes(entry.bytes)})`).join(", ");
|
|
340
|
+
return {
|
|
341
|
+
ok: false,
|
|
342
|
+
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.`
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
ok: true,
|
|
347
|
+
files: entries.sort().map((relative$1) => ({
|
|
348
|
+
path: relative$1,
|
|
349
|
+
content: relative$1 === LOCK_FILE ? Buffer.from(formatSharedLock(superwallDir)) : fs.readFileSync(path.join(superwallDir, relative$1))
|
|
350
|
+
}))
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/core/paywalls/source/base.ts
|
|
356
|
+
const LEGACY_FILE = path.join(".superwall", "source.json");
|
|
357
|
+
function readLegacyBases(superwallDir) {
|
|
358
|
+
const file = path.join(superwallDir, LEGACY_FILE);
|
|
359
|
+
if (!fs.existsSync(file)) return {};
|
|
360
|
+
let parsed;
|
|
361
|
+
try {
|
|
362
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
363
|
+
} catch (error) {
|
|
364
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
365
|
+
throw new Error(`Can't read ${file} (${reason}) — fix or delete it, then push again.`);
|
|
366
|
+
}
|
|
367
|
+
if (!isRecord(parsed) || !isRecord(parsed.repos)) throw new Error(`${file} isn't a source sync record — fix or delete it, then push again.`);
|
|
368
|
+
return parseSources(parsed.repos);
|
|
369
|
+
}
|
|
370
|
+
function readSourceBase(superwallDir, repo) {
|
|
371
|
+
return readLock(superwallDir).sources?.[repo] ?? readLegacyBases(superwallDir)[repo];
|
|
372
|
+
}
|
|
373
|
+
function writeSourceBase(superwallDir, repo, commitSha) {
|
|
374
|
+
writeSources(superwallDir, {
|
|
375
|
+
...readLegacyBases(superwallDir),
|
|
376
|
+
...readLock(superwallDir).sources,
|
|
377
|
+
[repo]: commitSha
|
|
378
|
+
});
|
|
379
|
+
fs.rmSync(path.join(superwallDir, LEGACY_FILE), { force: true });
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/core/paywalls/source/commit.ts
|
|
384
|
+
const buildCommitMessage = (input) => {
|
|
385
|
+
const surface = `${input.kind}/${input.surface}`;
|
|
386
|
+
const subject = `publish ${surface} v${input.version}`;
|
|
387
|
+
const external = (input.external ?? []).filter((entry) => entry.trim() !== "");
|
|
388
|
+
const trailers = [
|
|
389
|
+
`Superwall-Paywall: ${input.paywallId}`,
|
|
390
|
+
`Superwall-Application: ${input.applicationId}`,
|
|
391
|
+
`Superwall-Version: ${input.version}`,
|
|
392
|
+
`Superwall-Surface: ${surface}`,
|
|
393
|
+
`Superwall-Portable: ${external.length === 0}`
|
|
394
|
+
];
|
|
395
|
+
if (external.length > 0) trailers.push(`Superwall-External: ${external.join(", ")}`);
|
|
396
|
+
if (input.snapshotSha) trailers.push(`Superwall-Snapshot: ${input.snapshotSha}`);
|
|
397
|
+
trailers.push(`Superwall-Framework: ${input.framework}`);
|
|
398
|
+
if (input.cli) trailers.push(`Superwall-Cli: ${input.cli}`);
|
|
399
|
+
const note = input.note?.replace(/\r\n?/g, "\n").trim();
|
|
400
|
+
return `${subject}\n${note ? `\n${note}\n` : ""}\n${trailers.join("\n")}\n`;
|
|
401
|
+
};
|
|
402
|
+
const tokenSecret = (token) => token.split("?")[0] ?? token;
|
|
403
|
+
const redact = (text, ...secrets) => {
|
|
404
|
+
let safe = text;
|
|
405
|
+
for (const secret of secrets) {
|
|
406
|
+
if (secret.length < 8) continue;
|
|
407
|
+
safe = safe.split(secret).join("***");
|
|
408
|
+
}
|
|
409
|
+
return safe;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/core/paywalls/source/git.ts
|
|
414
|
+
const run = promisify(execFile);
|
|
415
|
+
const AUTHOR = {
|
|
416
|
+
name: "Superwall",
|
|
417
|
+
email: "publish@superwall.com"
|
|
418
|
+
};
|
|
419
|
+
var GitError = class extends Error {};
|
|
420
|
+
const REPOSITORY_ENV = new Set([
|
|
421
|
+
"GIT_DIR",
|
|
422
|
+
"GIT_WORK_TREE",
|
|
423
|
+
"GIT_INDEX_FILE",
|
|
424
|
+
"GIT_OBJECT_DIRECTORY",
|
|
425
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
426
|
+
"GIT_COMMON_DIR",
|
|
427
|
+
"GIT_NAMESPACE",
|
|
428
|
+
"GIT_CONFIG_PARAMETERS"
|
|
429
|
+
]);
|
|
430
|
+
const gitEnv = (token, extra = {}) => ({
|
|
431
|
+
...Object.fromEntries(Object.entries(process.env).filter(([key]) => !REPOSITORY_ENV.has(key))),
|
|
432
|
+
GIT_CONFIG_COUNT: "1",
|
|
433
|
+
GIT_CONFIG_KEY_0: "http.extraHeader",
|
|
434
|
+
GIT_CONFIG_VALUE_0: `Authorization: Bearer ${tokenSecret(token)}`,
|
|
435
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
436
|
+
...extra
|
|
437
|
+
});
|
|
438
|
+
const GIT_TIMEOUT_MS = 300 * 1e3;
|
|
439
|
+
const ISOLATION = [
|
|
440
|
+
"-c",
|
|
441
|
+
"commit.gpgsign=false",
|
|
442
|
+
"-c",
|
|
443
|
+
"core.hooksPath=/dev/null",
|
|
444
|
+
"-c",
|
|
445
|
+
"core.autocrlf=false"
|
|
446
|
+
];
|
|
447
|
+
async function git(args, options = {}) {
|
|
448
|
+
try {
|
|
449
|
+
const { stdout } = await run("git", [...ISOLATION, ...args], {
|
|
450
|
+
cwd: options.cwd,
|
|
451
|
+
env: options.env,
|
|
452
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
453
|
+
timeout: GIT_TIMEOUT_MS
|
|
454
|
+
});
|
|
455
|
+
return stdout;
|
|
456
|
+
} catch (error) {
|
|
457
|
+
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.`);
|
|
458
|
+
const detail = typeof error === "object" && error !== null ? String(Reflect.get(error, "stderr") ?? Reflect.get(error, "message") ?? error) : String(error);
|
|
459
|
+
throw new GitError(redact(`git ${args[0]} failed: ${gitReason(detail)}`, ...options.secrets ?? []));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function gitReason(stderr) {
|
|
463
|
+
const lines = stderr.split("\n").map((line) => line.trim()).filter((line) => line !== "" && !line.startsWith("Command failed:"));
|
|
464
|
+
return (lines.find((line) => /^(fatal|error):/.test(line)) ?? lines[lines.length - 1] ?? "").replace(/^(fatal|error):\s*/, "") || "git reported no reason.";
|
|
465
|
+
}
|
|
466
|
+
async function gitAvailable() {
|
|
467
|
+
try {
|
|
468
|
+
await run("git", ["--version"]);
|
|
469
|
+
return true;
|
|
470
|
+
} catch {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const LARGE_FILE_BYTES = 50 * 1024 * 1024;
|
|
475
|
+
function materializeSourceTree(dir, files) {
|
|
476
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
477
|
+
if (entry === ".git") continue;
|
|
478
|
+
fs.rmSync(path.join(dir, entry), {
|
|
479
|
+
recursive: true,
|
|
480
|
+
force: true
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
const write = (relative$1, data) => {
|
|
484
|
+
const file = path.join(dir, relative$1);
|
|
485
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
486
|
+
fs.writeFileSync(file, data);
|
|
487
|
+
};
|
|
488
|
+
const large = [];
|
|
489
|
+
for (const file of files) {
|
|
490
|
+
if (file.content.byteLength > LARGE_FILE_BYTES) large.push(file.path);
|
|
491
|
+
write(file.path, file.content);
|
|
492
|
+
}
|
|
493
|
+
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.`);
|
|
494
|
+
}
|
|
495
|
+
const SHOWN_FILES = 5;
|
|
496
|
+
const listFiles = (files) => {
|
|
497
|
+
const shown = files.slice(0, SHOWN_FILES).join(", ");
|
|
498
|
+
const rest = files.length - SHOWN_FILES;
|
|
499
|
+
return rest > 0 ? `${shown} and ${rest} more` : shown;
|
|
500
|
+
};
|
|
501
|
+
var SourceConflictError = class extends Error {
|
|
502
|
+
constructor(files) {
|
|
503
|
+
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.`);
|
|
504
|
+
this.files = files;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
var SourceDivergedError = class extends Error {
|
|
508
|
+
constructor(files) {
|
|
509
|
+
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.`);
|
|
510
|
+
this.files = files;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
const PUSH_ATTEMPTS = 3;
|
|
514
|
+
async function pushSourceTree(input) {
|
|
515
|
+
const { access } = input;
|
|
516
|
+
const secrets = [access.token, tokenSecret(access.token)];
|
|
517
|
+
const dir = fs.mkdtempSync(path.join(os$1.tmpdir(), "superwall-source-"));
|
|
518
|
+
const env = gitEnv(access.token);
|
|
519
|
+
const committing = gitEnv(access.token, {
|
|
520
|
+
GIT_AUTHOR_NAME: process.env.GIT_AUTHOR_NAME || AUTHOR.name,
|
|
521
|
+
GIT_AUTHOR_EMAIL: process.env.GIT_AUTHOR_EMAIL || AUTHOR.email,
|
|
522
|
+
GIT_COMMITTER_NAME: AUTHOR.name,
|
|
523
|
+
GIT_COMMITTER_EMAIL: AUTHOR.email
|
|
524
|
+
});
|
|
525
|
+
const run$1 = (args, options = {}) => git(args, {
|
|
526
|
+
cwd: dir,
|
|
527
|
+
env: options.env ?? env,
|
|
528
|
+
secrets
|
|
529
|
+
});
|
|
530
|
+
const revParse = (ref) => run$1([
|
|
531
|
+
"rev-parse",
|
|
532
|
+
"--verify",
|
|
533
|
+
"--quiet",
|
|
534
|
+
`${ref}^{commit}`
|
|
535
|
+
]).then((out) => out.trim(), () => void 0);
|
|
536
|
+
try {
|
|
537
|
+
await cloneSource(access, dir, {
|
|
538
|
+
env,
|
|
539
|
+
secrets
|
|
540
|
+
});
|
|
541
|
+
const head = await revParse("HEAD");
|
|
542
|
+
const base = input.base && head && !input.overwrite ? await revParse(input.base) : void 0;
|
|
543
|
+
if (base && base !== head) await run$1([
|
|
544
|
+
"checkout",
|
|
545
|
+
"--quiet",
|
|
546
|
+
"--detach",
|
|
547
|
+
base
|
|
548
|
+
]);
|
|
549
|
+
materializeSourceTree(dir, input.files);
|
|
550
|
+
await run$1(["add", "-A"]);
|
|
551
|
+
if ((await run$1(["status", "--porcelain"])).trim() === "") return {
|
|
552
|
+
commitSha: head ?? "",
|
|
553
|
+
status: "unchanged",
|
|
554
|
+
syncedTo: base ?? head
|
|
555
|
+
};
|
|
556
|
+
if (head && !base && !input.overwrite) throw new SourceDivergedError((await run$1([
|
|
557
|
+
"diff",
|
|
558
|
+
"--cached",
|
|
559
|
+
"--name-only",
|
|
560
|
+
"-z",
|
|
561
|
+
"HEAD"
|
|
562
|
+
])).split("\0").filter(Boolean));
|
|
563
|
+
const messageFile = path.join(dir, ".git", "SUPERWALL_COMMITMSG");
|
|
564
|
+
fs.writeFileSync(messageFile, buildCommitMessage(input.message));
|
|
565
|
+
await run$1([
|
|
566
|
+
"commit",
|
|
567
|
+
"--quiet",
|
|
568
|
+
"--no-verify",
|
|
569
|
+
"-F",
|
|
570
|
+
messageFile
|
|
571
|
+
], { env: committing });
|
|
572
|
+
const own = await revParse("HEAD");
|
|
573
|
+
if (!own) throw new Error("The source commit was not created.");
|
|
574
|
+
const isAncestor = (ancestor, of) => run$1([
|
|
575
|
+
"merge-base",
|
|
576
|
+
"--is-ancestor",
|
|
577
|
+
ancestor,
|
|
578
|
+
of
|
|
579
|
+
]).then(() => true, () => false);
|
|
580
|
+
for (let attempt = 1;; attempt++) {
|
|
581
|
+
const upstream = base ? await revParse(`origin/${access.branch}`) : void 0;
|
|
582
|
+
if (upstream && upstream !== base) {
|
|
583
|
+
if (await isAncestor(own, upstream)) return {
|
|
584
|
+
commitSha: upstream,
|
|
585
|
+
status: "unchanged",
|
|
586
|
+
syncedTo: own
|
|
587
|
+
};
|
|
588
|
+
await run$1([
|
|
589
|
+
"reset",
|
|
590
|
+
"--quiet",
|
|
591
|
+
"--hard",
|
|
592
|
+
own
|
|
593
|
+
]);
|
|
594
|
+
await mergeUpstream(`origin/${access.branch}`, messageFile, {
|
|
595
|
+
run: run$1,
|
|
596
|
+
committing
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
await run$1([
|
|
601
|
+
"push",
|
|
602
|
+
"origin",
|
|
603
|
+
`HEAD:${access.branch}`
|
|
604
|
+
]);
|
|
605
|
+
return {
|
|
606
|
+
commitSha: await revParse("HEAD") ?? own,
|
|
607
|
+
status: "committed",
|
|
608
|
+
syncedTo: own
|
|
609
|
+
};
|
|
610
|
+
} catch (error) {
|
|
611
|
+
if (!base || attempt >= PUSH_ATTEMPTS || !isRejected(error)) throw error;
|
|
612
|
+
await run$1([
|
|
613
|
+
"fetch",
|
|
614
|
+
"--quiet",
|
|
615
|
+
"origin",
|
|
616
|
+
access.branch
|
|
617
|
+
]);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
} finally {
|
|
621
|
+
fs.rmSync(dir, {
|
|
622
|
+
recursive: true,
|
|
623
|
+
force: true
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const CLONE_ATTEMPTS = [
|
|
628
|
+
["--filter=blob:none", "--branch"],
|
|
629
|
+
["--branch"],
|
|
630
|
+
["--filter=blob:none"],
|
|
631
|
+
[]
|
|
632
|
+
];
|
|
633
|
+
const CLONE_FALLBACK = /remote branch .* not found|filter/i;
|
|
634
|
+
async function cloneSource(access, dir, options) {
|
|
635
|
+
let first;
|
|
636
|
+
for (const flags of CLONE_ATTEMPTS) {
|
|
637
|
+
const branch = flags.includes("--branch") ? [access.branch] : [];
|
|
638
|
+
try {
|
|
639
|
+
await git([
|
|
640
|
+
"clone",
|
|
641
|
+
"--quiet",
|
|
642
|
+
...flags,
|
|
643
|
+
...branch,
|
|
644
|
+
access.remote,
|
|
645
|
+
dir
|
|
646
|
+
], options);
|
|
647
|
+
return;
|
|
648
|
+
} catch (error) {
|
|
649
|
+
first ??= error;
|
|
650
|
+
if (!(error instanceof GitError) || !CLONE_FALLBACK.test(error.message)) throw error;
|
|
651
|
+
fs.rmSync(dir, {
|
|
652
|
+
recursive: true,
|
|
653
|
+
force: true
|
|
654
|
+
});
|
|
655
|
+
fs.mkdirSync(dir);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
throw first;
|
|
659
|
+
}
|
|
660
|
+
async function mergeUpstream(upstream, messageFile, { run: run$1, committing }) {
|
|
661
|
+
try {
|
|
662
|
+
await run$1([
|
|
663
|
+
"merge",
|
|
664
|
+
"--quiet",
|
|
665
|
+
"--no-ff",
|
|
666
|
+
"-F",
|
|
667
|
+
messageFile,
|
|
668
|
+
upstream
|
|
669
|
+
], { env: committing });
|
|
670
|
+
} catch (error) {
|
|
671
|
+
const conflicted = await run$1([
|
|
672
|
+
"diff",
|
|
673
|
+
"--name-only",
|
|
674
|
+
"--diff-filter=U"
|
|
675
|
+
]).then((out) => out.split("\n").map((line) => line.trim()).filter(Boolean), () => []);
|
|
676
|
+
await run$1(["merge", "--abort"]).catch(() => void 0);
|
|
677
|
+
if (conflicted.length > 0) throw new SourceConflictError(conflicted);
|
|
678
|
+
throw error;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
const isRejected = (error) => error instanceof GitError && /rejected|non-fast-forward|fetch first|stale info|failed to push some refs/i.test(error.message);
|
|
682
|
+
|
|
683
|
+
//#endregion
|
|
684
|
+
//#region src/core/paywalls/source/source-push.ts
|
|
685
|
+
var GitRequiredError = class extends Error {
|
|
686
|
+
constructor() {
|
|
687
|
+
super("superwall publish requires git for the source step — install git");
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
async function assertGit(hasGit = gitAvailable) {
|
|
691
|
+
if (!await hasGit()) throw new GitRequiredError();
|
|
692
|
+
}
|
|
693
|
+
async function pushSource(input) {
|
|
694
|
+
for (let attempt = 0;; attempt++) {
|
|
695
|
+
const access = await mintSourceAccess(input.api, input.paywallId);
|
|
696
|
+
const pushed = await pushSourceTree({
|
|
697
|
+
access,
|
|
698
|
+
base: readSourceBase(input.superwallDir, access.repo),
|
|
699
|
+
overwrite: input.overwrite,
|
|
700
|
+
files: input.files,
|
|
701
|
+
message: {
|
|
702
|
+
kind: input.kind,
|
|
703
|
+
surface: input.surface,
|
|
704
|
+
version: input.version,
|
|
705
|
+
paywallId: input.paywallId,
|
|
706
|
+
applicationId: input.applicationId,
|
|
707
|
+
snapshotSha: input.snapshotId,
|
|
708
|
+
framework: input.framework,
|
|
709
|
+
cli: input.cli,
|
|
710
|
+
note: input.note,
|
|
711
|
+
external: input.external
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
if (pushed.syncedTo) writeSourceBase(input.superwallDir, access.repo, pushed.syncedTo);
|
|
715
|
+
try {
|
|
716
|
+
await linkCommit(input, access, pushed.commitSha);
|
|
717
|
+
return pushed;
|
|
718
|
+
} catch (error) {
|
|
719
|
+
if (attempt === 0 && error instanceof ApiError && error.status === 409) continue;
|
|
720
|
+
throw error;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
const LINK_ATTEMPTS = 2;
|
|
725
|
+
const LINK_RETRY_DELAY_MS = 300;
|
|
726
|
+
async function linkCommit(input, access, commitSha) {
|
|
727
|
+
for (let attempt = 1;; attempt++) try {
|
|
728
|
+
await linkSourceCommit(input.api, input.paywallId, input.version, {
|
|
729
|
+
commitSha,
|
|
730
|
+
tokenId: access.tokenId
|
|
731
|
+
});
|
|
732
|
+
return;
|
|
733
|
+
} catch (error) {
|
|
734
|
+
if (attempt >= LINK_ATTEMPTS || !isTransient(error)) throw error;
|
|
735
|
+
await setTimeout(LINK_RETRY_DELAY_MS);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
const isTransient = (error) => error instanceof ApiUnreachableError || error instanceof ApiError && error.status >= 500;
|
|
739
|
+
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/core/paywalls/project/session.ts
|
|
742
|
+
var LoginRequiredError = class extends Error {
|
|
743
|
+
constructor() {
|
|
744
|
+
super(`Pushing paywalls needs a Superwall account.
|
|
745
|
+
Interactively: run \`superwall login\`.
|
|
746
|
+
In CI or an agent: set ${ENV_API_KEY} to an org API key (sk_…).`);
|
|
747
|
+
this.name = "LoginRequiredError";
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
async function requireApi(interactive, login = performLoginWithUi) {
|
|
751
|
+
const apiKey = apiKeyFromEnv();
|
|
752
|
+
if (apiKey) return createSuperwallApi({
|
|
753
|
+
authMethod: "api_key",
|
|
754
|
+
apiKey,
|
|
755
|
+
host: process.env.SUPERWALL_API_HOST ?? API_HOST(),
|
|
756
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
757
|
+
});
|
|
758
|
+
const session = readSession();
|
|
759
|
+
if (session) return createSuperwallApi(session);
|
|
760
|
+
if (!interactive) throw new LoginRequiredError();
|
|
761
|
+
ui.info("You're not signed in to Superwall yet — let's fix that.");
|
|
762
|
+
const signedIn = await login();
|
|
763
|
+
if (!signedIn) throw new LoginRequiredError();
|
|
764
|
+
return createSuperwallApi(signedIn);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
//#endregion
|
|
768
|
+
export { resolveBinding as _, gitAvailable as a, projectPackageName as c, projectForApplication as d, requireProducts as f, wantedPlatforms as g, targetLabel as h, pushSource as i, writeProjectScaffold as l, planTargets as m, requireApi as n, collectSourceFiles as o, parsePlatformFlags as p, assertGit as r, warnNotPortable as s, LoginRequiredError as t, listProjectProducts as u, requirePlatform as v, resolveApps as y };
|