@superwall/cli 1.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.
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/actions-MB-eBY64.js +140 -0
- package/dist/api-BF7-toqM.js +151 -0
- package/dist/api-output-B5hh0q4V.js +20 -0
- package/dist/app-K6j9Es7h.js +189 -0
- package/dist/asc-CArSwo5D.js +539 -0
- package/dist/asc-products-YQ6Oc6YO.js +93 -0
- package/dist/auth-CY2cO_NF.js +139 -0
- package/dist/auth.d.ts +30 -0
- package/dist/auth.js +4 -0
- package/dist/billing-DWyfEQ6l.js +80 -0
- package/dist/bind-hslFhcTR.js +213 -0
- package/dist/chunk-DQxbwPpZ.js +30 -0
- package/dist/command-Kwx4ekbo.js +283 -0
- package/dist/create-Bbi8BOO1.js +410 -0
- package/dist/dev-D0lQDCQI.js +397 -0
- package/dist/devtools-8EgLo86w.js +3638 -0
- package/dist/doctor-ByeRdMcl.js +88 -0
- package/dist/drivers-DVAZgone.js +413 -0
- package/dist/entry.d.ts +9 -0
- package/dist/entry.js +495 -0
- package/dist/existing-CcJrIIAU.js +88 -0
- package/dist/feedback-Z0Wk7VC5.js +73 -0
- package/dist/git-3OX9u3xE.js +433 -0
- package/dist/hosted-CHwaUqLd.js +32 -0
- package/dist/integrate-DqOAqK7J.js +863 -0
- package/dist/json-C3hPIMkI.js +7 -0
- package/dist/login-Dr8UN_Gx.js +290 -0
- package/dist/migrate-D92bJTg6.js +114 -0
- package/dist/org-B2gy9Pmu.js +40 -0
- package/dist/params-Bvq0iqQK.js +52 -0
- package/dist/pipeline-CHHIg6BU.js +1056 -0
- package/dist/print-skill-BnZAk7dV.js +74 -0
- package/dist/promote-CRe9170G.js +88 -0
- package/dist/publish-DsODvrOD.js +35 -0
- package/dist/push-BDkZUC0v.js +35 -0
- package/dist/query-DIllrSnk.js +53 -0
- package/dist/resource-CdP1MDla.js +483 -0
- package/dist/resources-CVrWwA1K.js +233 -0
- package/dist/run-cGGBUMs5.js +89 -0
- package/dist/scan-BQexuUPO.js +236 -0
- package/dist/skills-DhuUs28u.js +64 -0
- package/dist/skills-xrfXt9u0.js +205 -0
- package/dist/spawn-DSoTXy_j.js +69 -0
- package/dist/spinner-gOxIMz-V.js +18 -0
- package/dist/storekit-Ddvs4Ynw.js +29 -0
- package/dist/telemetry-CcfrtXdf.js +204 -0
- package/dist/token-DHRH8cxi.js +102 -0
- package/dist/ui-C4ncRJqd.js +27703 -0
- package/dist/update-BiVeR024.js +137 -0
- package/dist/upgrade-DYWspApv.js +72 -0
- package/package.json +87 -0
- package/prompts/actions/dashboard-setup.xml +10 -0
- package/prompts/actions/integrate.xml +5 -0
- package/prompts/actions/migrate.xml +11 -0
- package/prompts/actions/placements-implement.xml +20 -0
- package/prompts/actions/placements-review.xml +18 -0
- package/prompts/actions/review-fix.xml +18 -0
- package/prompts/actions/review.xml +18 -0
- package/prompts/commandments.xml +17 -0
- package/prompts/context.xml +9 -0
- package/skills/README.md +118 -0
- package/skills/superwall-dashboard/SKILL.md +81 -0
- package/skills/superwall-dashboard/references/setup.md +101 -0
- package/skills/superwall-integrate/SKILL.md +76 -0
- package/skills/superwall-integrate/references/expo.md +269 -0
- package/skills/superwall-integrate/references/flutter.md +285 -0
- package/skills/superwall-integrate/references/ios.md +314 -0
- package/skills/superwall-integrate/references/react-native.md +245 -0
- package/skills/superwall-migrate/SKILL.md +83 -0
- package/skills/superwall-migrate/references/adapty.md +229 -0
- package/skills/superwall-migrate/references/qonversion.md +227 -0
- package/skills/superwall-migrate/references/revenuecat.md +414 -0
- package/skills/superwall-placements/SKILL.md +73 -0
- package/skills/superwall-placements/references/expo.md +161 -0
- package/skills/superwall-placements/references/flutter.md +139 -0
- package/skills/superwall-placements/references/ios.md +165 -0
- package/skills/superwall-placements/references/react-native.md +145 -0
- package/skills/superwall-placements/references/strategy.md +221 -0
- package/skills/superwall-review/SKILL.md +75 -0
- package/skills/superwall-review/references/expo.md +100 -0
- package/skills/superwall-review/references/flutter.md +99 -0
- package/skills/superwall-review/references/ios.md +108 -0
- package/skills/superwall-review/references/react-native.md +100 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { a as apiKeyFromEnv, w as ENV_API_KEY, y as API_HOST } from "./telemetry-CcfrtXdf.js";
|
|
2
|
+
import { i as loadSession } from "./token-DHRH8cxi.js";
|
|
3
|
+
import { r as SuperwallApi } from "./command-Kwx4ekbo.js";
|
|
4
|
+
import { n as ui } from "./ui-C4ncRJqd.js";
|
|
5
|
+
import { f as listApplications, y as platformLabel } from "./resources-CVrWwA1K.js";
|
|
6
|
+
import { r as performLoginWithUi } from "./app-K6j9Es7h.js";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as os$1 from "node:os";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
import { execFile } from "node:child_process";
|
|
12
|
+
|
|
13
|
+
//#region src/core/paywalls/project/lock.ts
|
|
14
|
+
const EXPLAINER = "Commit this file: it binds each paywall to its dashboard entry, per app, so every machine and CI push to the same place. Managed by the Superwall CLI.";
|
|
15
|
+
const emptyLock = () => ({
|
|
16
|
+
version: 1,
|
|
17
|
+
apps: {},
|
|
18
|
+
paywalls: {},
|
|
19
|
+
funnels: {}
|
|
20
|
+
});
|
|
21
|
+
const lockPath = (superwallDir) => path.join(superwallDir, "superwall.lock");
|
|
22
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
const readBinding = (value) => {
|
|
24
|
+
if (!isRecord(value) || typeof value.paywallId !== "string") return void 0;
|
|
25
|
+
return typeof value.snapshot === "string" ? {
|
|
26
|
+
paywallId: value.paywallId,
|
|
27
|
+
snapshot: value.snapshot
|
|
28
|
+
} : { paywallId: value.paywallId };
|
|
29
|
+
};
|
|
30
|
+
const readSection = (value) => {
|
|
31
|
+
const section = {};
|
|
32
|
+
if (!isRecord(value)) return section;
|
|
33
|
+
for (const [surfaceId, entry] of Object.entries(value)) {
|
|
34
|
+
if (!isRecord(entry)) continue;
|
|
35
|
+
const bindings = {};
|
|
36
|
+
for (const [platform, candidate] of Object.entries(entry)) {
|
|
37
|
+
const binding = readBinding(candidate);
|
|
38
|
+
if (binding) bindings[platform] = binding;
|
|
39
|
+
}
|
|
40
|
+
if (Object.keys(bindings).length > 0) section[surfaceId] = bindings;
|
|
41
|
+
}
|
|
42
|
+
return section;
|
|
43
|
+
};
|
|
44
|
+
function readLock(superwallDir) {
|
|
45
|
+
const file = lockPath(superwallDir);
|
|
46
|
+
if (!fs.existsSync(file)) return emptyLock();
|
|
47
|
+
try {
|
|
48
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
49
|
+
if (!isRecord(parsed) || parsed.version !== 1) return emptyLock();
|
|
50
|
+
const lock = emptyLock();
|
|
51
|
+
if (isRecord(parsed.apps)) {
|
|
52
|
+
for (const [platform, id] of Object.entries(parsed.apps)) if (typeof id === "string") lock.apps[platform] = id;
|
|
53
|
+
}
|
|
54
|
+
lock.paywalls = readSection(parsed.paywalls);
|
|
55
|
+
lock.funnels = readSection(parsed.funnels);
|
|
56
|
+
return lock;
|
|
57
|
+
} catch {}
|
|
58
|
+
return emptyLock();
|
|
59
|
+
}
|
|
60
|
+
function writeLock(superwallDir, lock) {
|
|
61
|
+
const annotated = {
|
|
62
|
+
"//": EXPLAINER,
|
|
63
|
+
version: lock.version,
|
|
64
|
+
apps: lock.apps,
|
|
65
|
+
paywalls: lock.paywalls,
|
|
66
|
+
funnels: lock.funnels
|
|
67
|
+
};
|
|
68
|
+
fs.writeFileSync(lockPath(superwallDir), `${JSON.stringify(annotated, null, 2)}\n`);
|
|
69
|
+
}
|
|
70
|
+
const sectionOf = (lock, kind) => kind === "paywall" ? lock.paywalls : lock.funnels;
|
|
71
|
+
function writeApp(superwallDir, platform, applicationId) {
|
|
72
|
+
const lock = readLock(superwallDir);
|
|
73
|
+
lock.apps[platform] = applicationId;
|
|
74
|
+
writeLock(superwallDir, lock);
|
|
75
|
+
}
|
|
76
|
+
function writeBinding(superwallDir, kind, surfaceId, platform, binding) {
|
|
77
|
+
const lock = readLock(superwallDir);
|
|
78
|
+
const section = sectionOf(lock, kind);
|
|
79
|
+
section[surfaceId] = {
|
|
80
|
+
...section[surfaceId],
|
|
81
|
+
[platform]: binding
|
|
82
|
+
};
|
|
83
|
+
writeLock(superwallDir, lock);
|
|
84
|
+
}
|
|
85
|
+
function writeBindings(superwallDir, kind, surfaceId, bindings) {
|
|
86
|
+
const lock = readLock(superwallDir);
|
|
87
|
+
sectionOf(lock, kind)[surfaceId] = { ...bindings };
|
|
88
|
+
writeLock(superwallDir, lock);
|
|
89
|
+
}
|
|
90
|
+
function writeSnapshot(superwallDir, kind, surfaceId, platform, snapshot) {
|
|
91
|
+
const lock = readLock(superwallDir);
|
|
92
|
+
const section = sectionOf(lock, kind);
|
|
93
|
+
const binding = section[surfaceId]?.[platform];
|
|
94
|
+
if (!binding || binding.snapshot === snapshot) return;
|
|
95
|
+
section[surfaceId] = {
|
|
96
|
+
...section[surfaceId],
|
|
97
|
+
[platform]: {
|
|
98
|
+
...binding,
|
|
99
|
+
snapshot
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
writeLock(superwallDir, lock);
|
|
103
|
+
}
|
|
104
|
+
function removeBinding(superwallDir, kind, surfaceId) {
|
|
105
|
+
const lock = readLock(superwallDir);
|
|
106
|
+
const section = sectionOf(lock, kind);
|
|
107
|
+
if (!(surfaceId in section)) return false;
|
|
108
|
+
delete section[surfaceId];
|
|
109
|
+
writeLock(superwallDir, lock);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
const describeBindings = (bindings) => {
|
|
113
|
+
const entries = Object.entries(bindings);
|
|
114
|
+
if (entries.length === 1 && entries[0] !== void 0) return `paywall ${entries[0][1].paywallId}`;
|
|
115
|
+
return `paywalls ${entries.map(([platform, binding]) => `${binding.paywallId} (${platform})`).join(", ")}`;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/core/paywalls/binding/apps.ts
|
|
120
|
+
const PLATFORMS = [
|
|
121
|
+
"ios",
|
|
122
|
+
"android",
|
|
123
|
+
"web"
|
|
124
|
+
];
|
|
125
|
+
var AppBindingError = class extends Error {};
|
|
126
|
+
const platformOf = (app) => {
|
|
127
|
+
const normalized = (app.platform ?? "").toLowerCase();
|
|
128
|
+
return PLATFORMS.find((platform) => platform === normalized);
|
|
129
|
+
};
|
|
130
|
+
function requirePlatform(app) {
|
|
131
|
+
const platform = platformOf(app);
|
|
132
|
+
if (platform !== void 0) return platform;
|
|
133
|
+
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.`);
|
|
134
|
+
}
|
|
135
|
+
const platformFor = (apps, value) => {
|
|
136
|
+
if (value in apps) return value;
|
|
137
|
+
return Object.entries(apps).find(([, id]) => id === value)?.[0];
|
|
138
|
+
};
|
|
139
|
+
function describePlatforms(apps) {
|
|
140
|
+
return Object.keys(apps).join(", ");
|
|
141
|
+
}
|
|
142
|
+
async function resolveApps(input) {
|
|
143
|
+
const { api, superwallDir } = input;
|
|
144
|
+
let cached;
|
|
145
|
+
const known = () => cached ??= listApplications(api);
|
|
146
|
+
const current = () => readLock(superwallDir).apps;
|
|
147
|
+
for (const platform of new Set(input.wanted ?? [])) {
|
|
148
|
+
if (!PLATFORMS.some((known$1) => known$1 === platform)) throw new AppBindingError(`"${platform}" is not a platform — use one of ${PLATFORMS.join(", ")}.`);
|
|
149
|
+
if (platform in current()) continue;
|
|
150
|
+
const bound = new Set(Object.values(current()));
|
|
151
|
+
const candidates = (await known()).filter((app) => !bound.has(String(app.id)) && platformOf(app) === platform);
|
|
152
|
+
const only = candidates.length === 1 ? candidates[0] : void 0;
|
|
153
|
+
if (only) {
|
|
154
|
+
writeApp(superwallDir, platform, String(only.id));
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const picked = candidates.length > 1 && input.pickApplication ? await input.pickApplication(candidates, platform) : null;
|
|
158
|
+
if (picked) {
|
|
159
|
+
writeApp(superwallDir, platform, String(picked.id));
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const label = platformLabel(platform);
|
|
163
|
+
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).`);
|
|
164
|
+
}
|
|
165
|
+
if (Object.keys(current()).length > 0) return current();
|
|
166
|
+
const apps = await known();
|
|
167
|
+
if (apps.length === 1 && apps[0] !== void 0) {
|
|
168
|
+
writeApp(superwallDir, requirePlatform(apps[0]), String(apps[0].id));
|
|
169
|
+
return current();
|
|
170
|
+
}
|
|
171
|
+
if (apps.length > 1 && input.pickApplication) {
|
|
172
|
+
const picked = await input.pickApplication(apps);
|
|
173
|
+
if (picked) {
|
|
174
|
+
writeApp(superwallDir, requirePlatform(picked), String(picked.id));
|
|
175
|
+
return current();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
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.");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/core/paywalls/project/scaffold.ts
|
|
183
|
+
const REACT_VERSION = "19.1.0";
|
|
184
|
+
function projectPackageName(root) {
|
|
185
|
+
const name = path.basename(root).toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^[-._]+|[-._]+$/g, "");
|
|
186
|
+
return name === "" || name === "superwall" ? "superwall-project" : name;
|
|
187
|
+
}
|
|
188
|
+
function packageJson(name, frameworkVersion) {
|
|
189
|
+
return `${JSON.stringify({
|
|
190
|
+
name,
|
|
191
|
+
private: true,
|
|
192
|
+
type: "module",
|
|
193
|
+
scripts: {
|
|
194
|
+
dev: "superwall dev",
|
|
195
|
+
push: "superwall push",
|
|
196
|
+
promote: "superwall promote",
|
|
197
|
+
ship: "superwall publish"
|
|
198
|
+
},
|
|
199
|
+
dependencies: {
|
|
200
|
+
react: REACT_VERSION,
|
|
201
|
+
"react-dom": REACT_VERSION,
|
|
202
|
+
superwall: frameworkVersion === "unknown" ? "*" : `^${frameworkVersion}`
|
|
203
|
+
}
|
|
204
|
+
}, null, 2)}\n`;
|
|
205
|
+
}
|
|
206
|
+
const GITIGNORE = `node_modules/
|
|
207
|
+
.superwall
|
|
208
|
+
.env
|
|
209
|
+
`;
|
|
210
|
+
function writeIfAbsent(file, content) {
|
|
211
|
+
if (fs.existsSync(file)) return;
|
|
212
|
+
try {
|
|
213
|
+
fs.writeFileSync(file, content, { flag: "wx" });
|
|
214
|
+
} catch {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function writeProjectScaffold(options) {
|
|
219
|
+
writeIfAbsent(path.join(options.superwallDir, "package.json"), packageJson(projectPackageName(options.root), options.frameworkVersion));
|
|
220
|
+
writeIfAbsent(path.join(options.superwallDir, ".gitignore"), GITIGNORE);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/core/paywalls/project/session.ts
|
|
225
|
+
var LoginRequiredError = class extends Error {
|
|
226
|
+
constructor() {
|
|
227
|
+
super(`Pushing paywalls needs a Superwall account.
|
|
228
|
+
Interactively: run \`superwall login\`.
|
|
229
|
+
In CI or an agent: set ${ENV_API_KEY} to an org API key (sk_…).`);
|
|
230
|
+
this.name = "LoginRequiredError";
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
async function requireApi(interactive) {
|
|
234
|
+
const apiKey = apiKeyFromEnv();
|
|
235
|
+
if (apiKey) return SuperwallApi.of({
|
|
236
|
+
authMethod: "api_key",
|
|
237
|
+
apiKey,
|
|
238
|
+
host: process.env.SUPERWALL_API_HOST ?? API_HOST,
|
|
239
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
240
|
+
});
|
|
241
|
+
const session = loadSession();
|
|
242
|
+
if (session) return SuperwallApi.of(session);
|
|
243
|
+
if (!interactive) throw new LoginRequiredError();
|
|
244
|
+
ui.info("You're not signed in to Superwall yet — let's fix that.");
|
|
245
|
+
const signedIn = await performLoginWithUi();
|
|
246
|
+
if (!signedIn) throw new LoginRequiredError();
|
|
247
|
+
return SuperwallApi.of(signedIn);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/core/paywalls/source/commit.ts
|
|
252
|
+
const buildCommitMessage = (input) => {
|
|
253
|
+
const surface = `${input.kind}/${input.surface}`;
|
|
254
|
+
const subject = `publish ${surface} v${input.version}`;
|
|
255
|
+
const external = (input.external ?? []).filter((entry) => entry.trim() !== "");
|
|
256
|
+
const trailers = [
|
|
257
|
+
`Superwall-Paywall: ${input.paywallId}`,
|
|
258
|
+
`Superwall-Application: ${input.applicationId}`,
|
|
259
|
+
`Superwall-Version: ${input.version}`,
|
|
260
|
+
`Superwall-Surface: ${surface}`,
|
|
261
|
+
`Superwall-Portable: ${external.length === 0}`
|
|
262
|
+
];
|
|
263
|
+
if (external.length > 0) trailers.push(`Superwall-External: ${external.join(", ")}`);
|
|
264
|
+
if (input.snapshotSha) trailers.push(`Superwall-Snapshot: ${input.snapshotSha}`);
|
|
265
|
+
trailers.push(`Superwall-Framework: ${input.framework}`);
|
|
266
|
+
if (input.cli) trailers.push(`Superwall-Cli: ${input.cli}`);
|
|
267
|
+
const note = input.note?.replace(/\r\n?/g, "\n").trim();
|
|
268
|
+
return `${subject}\n${note ? `\n${note}\n` : ""}\n${trailers.join("\n")}\n`;
|
|
269
|
+
};
|
|
270
|
+
const tokenSecret = (token) => token.split("?")[0] ?? token;
|
|
271
|
+
const redact = (text, ...secrets) => {
|
|
272
|
+
let safe = text;
|
|
273
|
+
for (const secret of secrets) {
|
|
274
|
+
if (secret.length < 8) continue;
|
|
275
|
+
safe = safe.split(secret).join("***");
|
|
276
|
+
}
|
|
277
|
+
return safe;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/core/paywalls/source/git.ts
|
|
282
|
+
const run = promisify(execFile);
|
|
283
|
+
const AUTHOR = {
|
|
284
|
+
name: "Superwall",
|
|
285
|
+
email: "publish@superwall.com"
|
|
286
|
+
};
|
|
287
|
+
var GitError = class extends Error {};
|
|
288
|
+
const gitEnv = (token, extra = {}) => ({
|
|
289
|
+
...process.env,
|
|
290
|
+
GIT_CONFIG_COUNT: "1",
|
|
291
|
+
GIT_CONFIG_KEY_0: "http.extraHeader",
|
|
292
|
+
GIT_CONFIG_VALUE_0: `Authorization: Bearer ${tokenSecret(token)}`,
|
|
293
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
294
|
+
...extra
|
|
295
|
+
});
|
|
296
|
+
async function git(args, options = {}) {
|
|
297
|
+
try {
|
|
298
|
+
const { stdout } = await run("git", args, {
|
|
299
|
+
cwd: options.cwd,
|
|
300
|
+
env: options.env,
|
|
301
|
+
maxBuffer: 64 * 1024 * 1024
|
|
302
|
+
});
|
|
303
|
+
return stdout;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
const detail = typeof error === "object" && error !== null ? String(Reflect.get(error, "stderr") ?? Reflect.get(error, "message") ?? error) : String(error);
|
|
306
|
+
throw new GitError(redact(`git ${args[0]} failed: ${gitReason(detail)}`, ...options.secrets ?? []));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function gitReason(stderr) {
|
|
310
|
+
const lines = stderr.split("\n").map((line) => line.trim()).filter((line) => line !== "" && !line.startsWith("Command failed:"));
|
|
311
|
+
return (lines.find((line) => /^(fatal|error):/.test(line)) ?? lines[lines.length - 1] ?? "").replace(/^(fatal|error):\s*/, "") || "git reported no reason.";
|
|
312
|
+
}
|
|
313
|
+
async function gitAvailable() {
|
|
314
|
+
try {
|
|
315
|
+
await run("git", ["--version"]);
|
|
316
|
+
return true;
|
|
317
|
+
} catch {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const LARGE_FILE_BYTES = 50 * 1024 * 1024;
|
|
322
|
+
function materializeSourceTree(dir, files) {
|
|
323
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
324
|
+
if (entry === ".git") continue;
|
|
325
|
+
fs.rmSync(path.join(dir, entry), {
|
|
326
|
+
recursive: true,
|
|
327
|
+
force: true
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
const write = (relative$1, data) => {
|
|
331
|
+
const file = path.join(dir, relative$1);
|
|
332
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
333
|
+
fs.writeFileSync(file, data);
|
|
334
|
+
};
|
|
335
|
+
const large = [];
|
|
336
|
+
for (const file of files) {
|
|
337
|
+
if (file.content.byteLength > LARGE_FILE_BYTES) large.push(file.path);
|
|
338
|
+
write(file.path, file.content);
|
|
339
|
+
}
|
|
340
|
+
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.`);
|
|
341
|
+
}
|
|
342
|
+
async function pushSourceTree(input) {
|
|
343
|
+
const { access } = input;
|
|
344
|
+
const secrets = [access.token, tokenSecret(access.token)];
|
|
345
|
+
const dir = fs.mkdtempSync(path.join(os$1.tmpdir(), "superwall-source-"));
|
|
346
|
+
const env = gitEnv(access.token);
|
|
347
|
+
try {
|
|
348
|
+
await git([
|
|
349
|
+
"clone",
|
|
350
|
+
"--depth",
|
|
351
|
+
"1",
|
|
352
|
+
"--branch",
|
|
353
|
+
access.branch,
|
|
354
|
+
access.remote,
|
|
355
|
+
dir
|
|
356
|
+
], {
|
|
357
|
+
env,
|
|
358
|
+
secrets
|
|
359
|
+
}).catch(async (error) => {
|
|
360
|
+
await git([
|
|
361
|
+
"clone",
|
|
362
|
+
"--depth",
|
|
363
|
+
"1",
|
|
364
|
+
access.remote,
|
|
365
|
+
dir
|
|
366
|
+
], {
|
|
367
|
+
env,
|
|
368
|
+
secrets
|
|
369
|
+
}).catch(() => {
|
|
370
|
+
throw error;
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
materializeSourceTree(dir, input.files);
|
|
374
|
+
await git(["add", "-A"], {
|
|
375
|
+
cwd: dir,
|
|
376
|
+
env,
|
|
377
|
+
secrets
|
|
378
|
+
});
|
|
379
|
+
if ((await git(["status", "--porcelain"], {
|
|
380
|
+
cwd: dir,
|
|
381
|
+
env,
|
|
382
|
+
secrets
|
|
383
|
+
})).trim() === "") return {
|
|
384
|
+
commitSha: (await git(["rev-parse", "HEAD"], {
|
|
385
|
+
cwd: dir,
|
|
386
|
+
env,
|
|
387
|
+
secrets
|
|
388
|
+
})).trim(),
|
|
389
|
+
status: "unchanged"
|
|
390
|
+
};
|
|
391
|
+
const messageFile = path.join(dir, ".git", "SUPERWALL_COMMITMSG");
|
|
392
|
+
fs.writeFileSync(messageFile, buildCommitMessage(input.message));
|
|
393
|
+
await git([
|
|
394
|
+
"commit",
|
|
395
|
+
"-F",
|
|
396
|
+
messageFile
|
|
397
|
+
], {
|
|
398
|
+
cwd: dir,
|
|
399
|
+
env: gitEnv(access.token, {
|
|
400
|
+
GIT_AUTHOR_NAME: AUTHOR.name,
|
|
401
|
+
GIT_AUTHOR_EMAIL: AUTHOR.email,
|
|
402
|
+
GIT_COMMITTER_NAME: AUTHOR.name,
|
|
403
|
+
GIT_COMMITTER_EMAIL: AUTHOR.email
|
|
404
|
+
}),
|
|
405
|
+
secrets
|
|
406
|
+
});
|
|
407
|
+
await git([
|
|
408
|
+
"push",
|
|
409
|
+
"origin",
|
|
410
|
+
`HEAD:${access.branch}`
|
|
411
|
+
], {
|
|
412
|
+
cwd: dir,
|
|
413
|
+
env,
|
|
414
|
+
secrets
|
|
415
|
+
});
|
|
416
|
+
return {
|
|
417
|
+
commitSha: (await git(["rev-parse", "HEAD"], {
|
|
418
|
+
cwd: dir,
|
|
419
|
+
env,
|
|
420
|
+
secrets
|
|
421
|
+
})).trim(),
|
|
422
|
+
status: "committed"
|
|
423
|
+
};
|
|
424
|
+
} finally {
|
|
425
|
+
fs.rmSync(dir, {
|
|
426
|
+
recursive: true,
|
|
427
|
+
force: true
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
//#endregion
|
|
433
|
+
export { writeSnapshot as _, projectPackageName as a, platformFor as c, describeBindings as d, readLock as f, writeBindings as g, writeBinding as h, requireApi as i, requirePlatform as l, writeApp as m, pushSourceTree as n, writeProjectScaffold as o, removeBinding as p, LoginRequiredError as r, describePlatforms as s, gitAvailable as t, resolveApps as u };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { y as API_HOST } from "./telemetry-CcfrtXdf.js";
|
|
2
|
+
import { i as loadSession, t as getOAuthAccessToken } from "./token-DHRH8cxi.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/agent/hosted.ts
|
|
5
|
+
const STATUS_PATH = "/v2/cli-agent/status";
|
|
6
|
+
const ANTHROPIC_PROXY_PATH = "/v2/cli-agent/anthropic";
|
|
7
|
+
function baseUrl() {
|
|
8
|
+
return loadSession()?.host || API_HOST;
|
|
9
|
+
}
|
|
10
|
+
function getHostedAnthropicBaseUrl() {
|
|
11
|
+
return `${baseUrl()}${ANTHROPIC_PROXY_PATH}`;
|
|
12
|
+
}
|
|
13
|
+
async function getHostedAuthToken() {
|
|
14
|
+
return getOAuthAccessToken();
|
|
15
|
+
}
|
|
16
|
+
async function getHostedStatus() {
|
|
17
|
+
const token = await getOAuthAccessToken();
|
|
18
|
+
if (!token) return null;
|
|
19
|
+
try {
|
|
20
|
+
const res = await fetch(`${baseUrl()}${STATUS_PATH}`, { headers: {
|
|
21
|
+
authorization: `Bearer ${token}`,
|
|
22
|
+
accept: "application/json"
|
|
23
|
+
} });
|
|
24
|
+
if (!res.ok) return null;
|
|
25
|
+
return await res.json();
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { getHostedAuthToken as n, getHostedStatus as r, getHostedAnthropicBaseUrl as t };
|