@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,863 @@
|
|
|
1
|
+
import { C as DASHBOARD_URL, a as apiKeyFromEnv, k as VERSION, l as getOnboardedApp, r as setTelemetryTags } from "./telemetry-CcfrtXdf.js";
|
|
2
|
+
import { t as formatJson } from "./json-C3hPIMkI.js";
|
|
3
|
+
import { o as blocks } from "./update-BiVeR024.js";
|
|
4
|
+
import { i as loadSession } from "./token-DHRH8cxi.js";
|
|
5
|
+
import { r as SuperwallApi, t as defineCommand } from "./command-Kwx4ekbo.js";
|
|
6
|
+
import { n as ui, r as stripReport } from "./ui-C4ncRJqd.js";
|
|
7
|
+
import { n as ensureSkillsCurrent } from "./skills-xrfXt9u0.js";
|
|
8
|
+
import "./spawn-DSoTXy_j.js";
|
|
9
|
+
import "./login-Dr8UN_Gx.js";
|
|
10
|
+
import { i as SUPPORTED_LABEL, t as scanProject } from "./scan-BQexuUPO.js";
|
|
11
|
+
import { t as detectDrivers } from "./drivers-DVAZgone.js";
|
|
12
|
+
import "./hosted-CHwaUqLd.js";
|
|
13
|
+
import { t as detectExisting } from "./existing-CcJrIIAU.js";
|
|
14
|
+
import { t as withSpinner } from "./spinner-gOxIMz-V.js";
|
|
15
|
+
import { C as rowName, f as listApplications, h as listResource, o as createProduct, y as platformLabel } from "./resources-CVrWwA1K.js";
|
|
16
|
+
import "./org-B2gy9Pmu.js";
|
|
17
|
+
import { n as resolveAppBinding, r as resolveScopeFromKey, t as platformForIntegration } from "./bind-hslFhcTR.js";
|
|
18
|
+
import { r as actionById } from "./actions-MB-eBY64.js";
|
|
19
|
+
import { a as recoverUnmatchedScope, i as pickApp, n as ensureAgentDriverReady, o as stage, r as performLoginWithUi, t as chooseAction } from "./app-K6j9Es7h.js";
|
|
20
|
+
import { c as listAscConfigs, i as listAscApps, n as fetchUnimportedAscProducts, o as createAscConfig, r as findAscAppId, t as ascTypeDisplay } from "./asc-products-YQ6Oc6YO.js";
|
|
21
|
+
import { t as generateStoreKit } from "./storekit-Ddvs4Ynw.js";
|
|
22
|
+
import { i as saveReport, n as buildCopyPrompt, r as loadReport, t as runAction } from "./run-cGGBUMs5.js";
|
|
23
|
+
import { t as detectBilling } from "./billing-DWyfEQ6l.js";
|
|
24
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
25
|
+
import { homedir } from "node:os";
|
|
26
|
+
import { basename, join } from "node:path";
|
|
27
|
+
import { spawn } from "node:child_process";
|
|
28
|
+
import fg from "fast-glob";
|
|
29
|
+
|
|
30
|
+
//#region src/core/account/index.ts
|
|
31
|
+
async function resolveAccount(opts) {
|
|
32
|
+
const projectKey = opts.existing.apiKey;
|
|
33
|
+
const flagKey = opts.argv.apiKey ?? apiKeyFromEnv();
|
|
34
|
+
if (projectKey) {
|
|
35
|
+
if (!opts.interactive || flagKey === projectKey) return { apiKey: projectKey };
|
|
36
|
+
const use = await opts.ui.confirm({ message: `This project already has a Superwall key (${projectKey}). Use this app?` });
|
|
37
|
+
if (use === null) return null;
|
|
38
|
+
if (use) return { apiKey: projectKey };
|
|
39
|
+
}
|
|
40
|
+
if (flagKey) return { apiKey: flagKey };
|
|
41
|
+
throw new Error(opts.interactive ? "Couldn't connect your app - re-run and complete the browser login." : "No public API key found. Pass --api-key or set SUPERWALL_API_KEY.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/core/api/discover.ts
|
|
46
|
+
async function discoverPublicApiKey(api, opts = {}) {
|
|
47
|
+
const apps = (await listApplications(api)).filter((a) => a.public_api_key);
|
|
48
|
+
if (apps.length === 0) return null;
|
|
49
|
+
if (opts.bundleId) {
|
|
50
|
+
const match = apps.find((a) => a.bundle_id === opts.bundleId);
|
|
51
|
+
if (match?.public_api_key) return {
|
|
52
|
+
apiKey: match.public_api_key,
|
|
53
|
+
app: match
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (apps.length === 1) {
|
|
57
|
+
const only = apps[0];
|
|
58
|
+
return {
|
|
59
|
+
apiKey: only.public_api_key,
|
|
60
|
+
app: only
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (opts.onMany) {
|
|
64
|
+
const picked = await opts.onMany(apps);
|
|
65
|
+
if (picked?.public_api_key) return {
|
|
66
|
+
apiKey: picked.public_api_key,
|
|
67
|
+
app: picked
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/core/dashboard/stages.ts
|
|
75
|
+
const SKIP = "__skip__";
|
|
76
|
+
function count(n, noun) {
|
|
77
|
+
return `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
78
|
+
}
|
|
79
|
+
async function runProductsStage(ctx) {
|
|
80
|
+
const { api, scope } = ctx;
|
|
81
|
+
const [products, ascConfigs] = await withSpinner("Checking products", async () => [await listResource(api, "products", scope), await listAscConfigs(api).catch(() => [])]);
|
|
82
|
+
const teamId = ascConfigs[0] ? String(ascConfigs[0].team_id ?? ascConfigs[0].id ?? "") : void 0;
|
|
83
|
+
const storeKitFiles = await findStoreKitFiles(ctx.projectDir);
|
|
84
|
+
if (products.length > 0) ui.success(`${count(products.length, "product")} already in Superwall.`);
|
|
85
|
+
else ui.info("No products in Superwall yet.");
|
|
86
|
+
for (;;) {
|
|
87
|
+
const how = await ui.select({
|
|
88
|
+
message: "How do you want to add products?",
|
|
89
|
+
options: [
|
|
90
|
+
{
|
|
91
|
+
value: "asc",
|
|
92
|
+
label: "Import from App Store Connect",
|
|
93
|
+
hint: teamId ? "Connected" : "Connect your account"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
value: "storekit",
|
|
97
|
+
label: "Import from a StoreKit file",
|
|
98
|
+
hint: storeKitFiles.length ? basename(storeKitFiles[0]) : "No StoreKit file found",
|
|
99
|
+
disabled: storeKitFiles.length === 0
|
|
100
|
+
},
|
|
101
|
+
...products.length > 0 ? [{
|
|
102
|
+
value: "export",
|
|
103
|
+
label: "Generate a .storekit file",
|
|
104
|
+
hint: "For Xcode testing"
|
|
105
|
+
}] : [],
|
|
106
|
+
{
|
|
107
|
+
value: SKIP,
|
|
108
|
+
label: "Skip for now"
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
initialValue: "asc",
|
|
112
|
+
footer: "esc to skip",
|
|
113
|
+
transient: true
|
|
114
|
+
});
|
|
115
|
+
if (how === null || how === SKIP) return;
|
|
116
|
+
let result = "done";
|
|
117
|
+
if (how === "asc") result = await ascFlow(ctx, products, teamId);
|
|
118
|
+
else if (how === "storekit") result = await importFromStoreKit(ctx, products, storeKitFiles);
|
|
119
|
+
else if (how === "export") writeStoreKit(products);
|
|
120
|
+
if (result === "back") continue;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function ascFlow(ctx, products, teamId) {
|
|
125
|
+
let team = teamId;
|
|
126
|
+
if (!team) {
|
|
127
|
+
const connected = await connectAppStoreConnect(ctx);
|
|
128
|
+
if (connected === "back") return "back";
|
|
129
|
+
team = connected;
|
|
130
|
+
}
|
|
131
|
+
return importFromAsc(ctx, team, products);
|
|
132
|
+
}
|
|
133
|
+
async function findStoreKitFiles(dir) {
|
|
134
|
+
if (!dir) return [];
|
|
135
|
+
try {
|
|
136
|
+
return await fg("**/*.storekit", {
|
|
137
|
+
cwd: dir,
|
|
138
|
+
absolute: true,
|
|
139
|
+
deep: 6,
|
|
140
|
+
suppressErrors: true,
|
|
141
|
+
ignore: [
|
|
142
|
+
"**/node_modules/**",
|
|
143
|
+
"**/Pods/**",
|
|
144
|
+
"**/build/**",
|
|
145
|
+
"**/DerivedData/**",
|
|
146
|
+
"**/.git/**"
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
} catch {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function importFromStoreKit(ctx, existingProducts, files) {
|
|
154
|
+
const { api, scope } = ctx;
|
|
155
|
+
let path = files[0];
|
|
156
|
+
if (files.length > 1) {
|
|
157
|
+
const sel = await ui.select({
|
|
158
|
+
message: "Which StoreKit file?",
|
|
159
|
+
options: files.map((f) => ({
|
|
160
|
+
value: f,
|
|
161
|
+
label: basename(f),
|
|
162
|
+
hint: f
|
|
163
|
+
})),
|
|
164
|
+
footer: "esc to go back",
|
|
165
|
+
transient: true
|
|
166
|
+
});
|
|
167
|
+
if (sel === null) return "back";
|
|
168
|
+
path = sel;
|
|
169
|
+
}
|
|
170
|
+
let ids;
|
|
171
|
+
try {
|
|
172
|
+
ids = storeKitProductIds(JSON.parse(readFileSync(path, "utf8")));
|
|
173
|
+
} catch {
|
|
174
|
+
ui.error(`Couldn't read \`${basename(path)}\` as a StoreKit file.`);
|
|
175
|
+
return "done";
|
|
176
|
+
}
|
|
177
|
+
if (ids.length === 0) {
|
|
178
|
+
ui.warn("No products found in that StoreKit file.");
|
|
179
|
+
return "done";
|
|
180
|
+
}
|
|
181
|
+
const existing = existingIdSet(existingProducts);
|
|
182
|
+
const toImport = ids.filter((id) => !existing.has(id));
|
|
183
|
+
if (toImport.length === 0) {
|
|
184
|
+
ui.success("Those StoreKit products are already in Superwall.");
|
|
185
|
+
return "done";
|
|
186
|
+
}
|
|
187
|
+
const picked = await ui.multiselect({
|
|
188
|
+
message: `${count(toImport.length, "product")} in the StoreKit file`,
|
|
189
|
+
options: toImport.map((id) => ({
|
|
190
|
+
value: id,
|
|
191
|
+
label: id
|
|
192
|
+
})),
|
|
193
|
+
initialValues: toImport
|
|
194
|
+
});
|
|
195
|
+
if (!picked || picked.length === 0) return "done";
|
|
196
|
+
let imported = 0;
|
|
197
|
+
for (const id of picked) {
|
|
198
|
+
await withSpinner(`Importing ${id}`, () => createProduct(api, scope, id));
|
|
199
|
+
imported++;
|
|
200
|
+
}
|
|
201
|
+
ui.success(`Imported ${count(imported, "product")} from the StoreKit file.`);
|
|
202
|
+
return "done";
|
|
203
|
+
}
|
|
204
|
+
function storeKitProductIds(json) {
|
|
205
|
+
const ids = /* @__PURE__ */ new Set();
|
|
206
|
+
const add = (arr) => {
|
|
207
|
+
if (Array.isArray(arr)) {
|
|
208
|
+
for (const p of arr) if (p?.productID) ids.add(String(p.productID));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const j = json ?? {};
|
|
212
|
+
add(j.products);
|
|
213
|
+
add(j.nonRenewingSubscriptions);
|
|
214
|
+
for (const g of j.subscriptionGroups ?? []) add(g?.subscriptions);
|
|
215
|
+
return [...ids];
|
|
216
|
+
}
|
|
217
|
+
function existingIdSet(products) {
|
|
218
|
+
return new Set(products.map((p) => {
|
|
219
|
+
const r = p;
|
|
220
|
+
return String(r.identifier ?? r.product_identifier ?? rowName(p));
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
async function connectAppStoreConnect(ctx) {
|
|
224
|
+
const { api } = ctx;
|
|
225
|
+
ui.note([
|
|
226
|
+
"Create an App Store Connect API key so Superwall can pull your products:",
|
|
227
|
+
"",
|
|
228
|
+
"1. Open App Store Connect → **Users and Access** → **Integrations** → **App Store Connect API**.",
|
|
229
|
+
"2. Create a key with the **App Manager** role (or higher).",
|
|
230
|
+
"3. Note the **Issuer ID** and download the **.p8** file."
|
|
231
|
+
].join("\n"), "Connect App Store Connect");
|
|
232
|
+
let privateKey;
|
|
233
|
+
let keyFilePath;
|
|
234
|
+
for (;;) {
|
|
235
|
+
const raw = await ui.text({
|
|
236
|
+
message: "Path to the .p8 key file",
|
|
237
|
+
placeholder: "~/Downloads/AuthKey_ABC123DEFG.p8",
|
|
238
|
+
validate: required,
|
|
239
|
+
footer: "esc to go back",
|
|
240
|
+
transient: true
|
|
241
|
+
});
|
|
242
|
+
if (raw === null) return "back";
|
|
243
|
+
keyFilePath = cleanPath(raw);
|
|
244
|
+
try {
|
|
245
|
+
privateKey = readFileSync(keyFilePath, "utf8");
|
|
246
|
+
break;
|
|
247
|
+
} catch {
|
|
248
|
+
ui.error(`Couldn't read \`${keyFilePath}\` - check the path and try again.`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
let keyId;
|
|
252
|
+
const fromName = keyIdFromFilename(keyFilePath);
|
|
253
|
+
if (fromName) keyId = fromName;
|
|
254
|
+
else {
|
|
255
|
+
const entered = await ui.text({
|
|
256
|
+
message: "Key ID",
|
|
257
|
+
placeholder: "ABC123DEFG",
|
|
258
|
+
validate: required,
|
|
259
|
+
footer: "esc to go back",
|
|
260
|
+
transient: true
|
|
261
|
+
});
|
|
262
|
+
if (entered === null) return "back";
|
|
263
|
+
keyId = entered.trim();
|
|
264
|
+
}
|
|
265
|
+
for (;;) {
|
|
266
|
+
const issuerId = await ui.text({
|
|
267
|
+
message: "Issuer ID",
|
|
268
|
+
placeholder: "57246542-96fe-1a63-e053-0824d011072a",
|
|
269
|
+
validate: required,
|
|
270
|
+
footer: "esc to go back",
|
|
271
|
+
transient: true
|
|
272
|
+
});
|
|
273
|
+
if (issuerId === null) return "back";
|
|
274
|
+
try {
|
|
275
|
+
const config = await withSpinner("Connecting App Store Connect", () => createAscConfig(api, {
|
|
276
|
+
keyId,
|
|
277
|
+
issuerId: issuerId.trim(),
|
|
278
|
+
privateKey,
|
|
279
|
+
accountName: ctx.appName || "App Store Connect"
|
|
280
|
+
}));
|
|
281
|
+
const teamId = String(config.team_id ?? config.id ?? "");
|
|
282
|
+
ui.success(`App Store Connect connected${teamId ? ` (team ${teamId})` : ""}.`);
|
|
283
|
+
return teamId || "back";
|
|
284
|
+
} catch {
|
|
285
|
+
ui.error("Couldn't verify that key. Check the Issuer ID and that the .p8 matches the Key ID, then try again.");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function keyIdFromFilename(path) {
|
|
290
|
+
return basename(path).match(/AuthKey_([A-Za-z0-9]+)\.p8$/i)?.[1];
|
|
291
|
+
}
|
|
292
|
+
async function importFromAsc(ctx, teamId, existingProducts) {
|
|
293
|
+
const { api, scope, bundleId } = ctx;
|
|
294
|
+
let ascAppId = bundleId ? await withSpinner("Finding your app in App Store Connect", () => findAscAppId(api, teamId, bundleId)) : void 0;
|
|
295
|
+
if (!ascAppId) {
|
|
296
|
+
const apps = await withSpinner("Loading App Store Connect apps", () => listAscApps(api, teamId));
|
|
297
|
+
if (apps.length === 0) {
|
|
298
|
+
ui.info("No apps in your App Store Connect account yet - skipping product import.");
|
|
299
|
+
return "done";
|
|
300
|
+
}
|
|
301
|
+
const sel = await ui.select({
|
|
302
|
+
message: bundleId ? `No App Store Connect app matches \`${bundleId}\`. Pick one:` : "Which App Store Connect app?",
|
|
303
|
+
options: apps.map((a) => ({
|
|
304
|
+
value: a.id,
|
|
305
|
+
label: a.name ?? a.id,
|
|
306
|
+
hint: a.bundleId
|
|
307
|
+
})),
|
|
308
|
+
footer: "esc to go back",
|
|
309
|
+
transient: true
|
|
310
|
+
});
|
|
311
|
+
if (sel === null) return "back";
|
|
312
|
+
ascAppId = sel;
|
|
313
|
+
}
|
|
314
|
+
const unimported = await withSpinner("Loading products from App Store Connect", () => fetchUnimportedAscProducts(api, teamId, ascAppId, existingIdSet(existingProducts)));
|
|
315
|
+
if (unimported.length === 0) {
|
|
316
|
+
ui.success("All App Store Connect products are already imported.");
|
|
317
|
+
return "done";
|
|
318
|
+
}
|
|
319
|
+
const picked = await ui.multiselect({
|
|
320
|
+
message: `${count(unimported.length, "product")} to import from App Store Connect`,
|
|
321
|
+
options: unimported.map((p) => ({
|
|
322
|
+
value: p.productId,
|
|
323
|
+
label: p.productId,
|
|
324
|
+
hint: [ascTypeDisplay(p.type), p.subscriptionPeriod].filter(Boolean).join(" · ")
|
|
325
|
+
})),
|
|
326
|
+
initialValues: unimported.map((p) => p.productId)
|
|
327
|
+
});
|
|
328
|
+
if (!picked || picked.length === 0) return "done";
|
|
329
|
+
const byId = new Map(unimported.map((p) => [p.productId, p]));
|
|
330
|
+
let imported = 0;
|
|
331
|
+
for (const id of picked) {
|
|
332
|
+
const p = byId.get(id);
|
|
333
|
+
await withSpinner(`Importing ${id}`, () => createProduct(api, scope, id, { name: p?.referenceName || void 0 }));
|
|
334
|
+
imported++;
|
|
335
|
+
}
|
|
336
|
+
ui.success(`Imported ${count(imported, "product")} from App Store Connect.`);
|
|
337
|
+
return "done";
|
|
338
|
+
}
|
|
339
|
+
function required(v) {
|
|
340
|
+
return v?.trim() ? void 0 : "Required";
|
|
341
|
+
}
|
|
342
|
+
function expandHome(p) {
|
|
343
|
+
return p.startsWith("~") ? join(homedir(), p.slice(1)) : p;
|
|
344
|
+
}
|
|
345
|
+
function cleanPath(input) {
|
|
346
|
+
let s = input.trim();
|
|
347
|
+
if (s.length >= 2 && (s[0] === "'" && s.endsWith("'") || s[0] === "\"" && s.endsWith("\""))) s = s.slice(1, -1);
|
|
348
|
+
s = s.replace(/\\ /g, " ");
|
|
349
|
+
return expandHome(s.trim());
|
|
350
|
+
}
|
|
351
|
+
function runPaywallStage() {
|
|
352
|
+
ui.note([
|
|
353
|
+
"Build your paywall as code, or design it in the editor:",
|
|
354
|
+
"",
|
|
355
|
+
" superwall create scaffold a superwall/ directory, then superwall publish",
|
|
356
|
+
` ${DASHBOARD_URL}`,
|
|
357
|
+
"",
|
|
358
|
+
"Your agent also has the `superwall-editor` skill - ask it to build or edit a",
|
|
359
|
+
"paywall in the editor from the CLI."
|
|
360
|
+
].join("\n"), "Paywall");
|
|
361
|
+
}
|
|
362
|
+
async function runVerifyStage(ctx) {
|
|
363
|
+
const { api, scope } = ctx;
|
|
364
|
+
const [products, campaigns] = await withSpinner("Verifying setup", async () => [await listResource(api, "products", scope), await listResource(api, "campaigns", scope)]);
|
|
365
|
+
line(products.length > 0, `Products in Superwall: ${products.length}`);
|
|
366
|
+
line(campaigns.length > 0, `Campaigns: ${campaigns.length}`);
|
|
367
|
+
ui.note([
|
|
368
|
+
"To verify end to end:",
|
|
369
|
+
"1. Run the app on a device/simulator.",
|
|
370
|
+
"2. Hit the feature gate where you register the placement.",
|
|
371
|
+
"3. Confirm the paywall presents and a test purchase completes."
|
|
372
|
+
].join("\n"), "Next");
|
|
373
|
+
}
|
|
374
|
+
function line(ok, text) {
|
|
375
|
+
if (ok) ui.success(text);
|
|
376
|
+
else ui.warn(text);
|
|
377
|
+
}
|
|
378
|
+
function writeStoreKit(products) {
|
|
379
|
+
const out = "Superwall.storekit";
|
|
380
|
+
writeFileSync(out, `${formatJson(generateStoreKit(products))}\n`);
|
|
381
|
+
ui.success(`Wrote \`${out}\` with ${count(products.length, "product")}.`);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/core/agent/fallback.ts
|
|
386
|
+
async function runFallback(installDir) {
|
|
387
|
+
const scan = await scanProject(installDir);
|
|
388
|
+
const top = scan.apps[0];
|
|
389
|
+
if (!top) {
|
|
390
|
+
if (scan.unsupported.length) throw new Error("Detected a web app. This command supports mobile apps.");
|
|
391
|
+
throw new Error(`No ${SUPPORTED_LABEL} app found here.`);
|
|
392
|
+
}
|
|
393
|
+
ui.info(`Detected ${top.framework.name}${top.details ? ` · ${top.details}` : ""}`);
|
|
394
|
+
ui.note([
|
|
395
|
+
`1. Install the SDK: ${top.framework.sdkPackage}`,
|
|
396
|
+
`2. Configure Superwall with your public API key at app launch.`,
|
|
397
|
+
`3. Register one placement: register("campaign_trigger").`,
|
|
398
|
+
``,
|
|
399
|
+
`Full guide: ${top.framework.docsUrl}`
|
|
400
|
+
].join("\n"), "Manual setup");
|
|
401
|
+
ui.note([
|
|
402
|
+
"For automated setup, install an agent and run `superwall integrate` again:",
|
|
403
|
+
"Claude Code: npm install --global @anthropic-ai/claude-code",
|
|
404
|
+
"Codex: npm install --global @openai/codex"
|
|
405
|
+
].join("\n"), "Automated setup");
|
|
406
|
+
ui.outro("Re-run `superwall integrate` after installing an agent.");
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/util/clipboard.ts
|
|
411
|
+
async function copyToClipboard(text) {
|
|
412
|
+
const cmd = clipboardCommand();
|
|
413
|
+
if (!cmd) return false;
|
|
414
|
+
return new Promise((resolve$1) => {
|
|
415
|
+
try {
|
|
416
|
+
const child = spawn(cmd.command, cmd.args, { stdio: [
|
|
417
|
+
"pipe",
|
|
418
|
+
"ignore",
|
|
419
|
+
"ignore"
|
|
420
|
+
] });
|
|
421
|
+
child.on("error", () => resolve$1(false));
|
|
422
|
+
child.on("close", (code) => resolve$1(code === 0));
|
|
423
|
+
child.stdin.write(text);
|
|
424
|
+
child.stdin.end();
|
|
425
|
+
} catch {
|
|
426
|
+
resolve$1(false);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
function clipboardCommand() {
|
|
431
|
+
switch (process.platform) {
|
|
432
|
+
case "darwin": return {
|
|
433
|
+
command: "pbcopy",
|
|
434
|
+
args: []
|
|
435
|
+
};
|
|
436
|
+
case "win32": return {
|
|
437
|
+
command: "clip",
|
|
438
|
+
args: []
|
|
439
|
+
};
|
|
440
|
+
default: return {
|
|
441
|
+
command: "xclip",
|
|
442
|
+
args: ["-selection", "clipboard"]
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/commands/workflow/integrate/agent.ts
|
|
449
|
+
async function copyIntegrationPrompt(context) {
|
|
450
|
+
const prompt = buildCopyPrompt(actionById.integrate, context);
|
|
451
|
+
if (await copyToClipboard(prompt)) ui.note("Paste it into Claude Code, Codex, Cursor, or another coding agent.", "Integration prompt copied to clipboard");
|
|
452
|
+
else ui.note(prompt, "Integration prompt (copy it manually)");
|
|
453
|
+
}
|
|
454
|
+
async function runActionWithUI(driver, fallbackDrivers, action, context) {
|
|
455
|
+
const spin = ui.spinner();
|
|
456
|
+
spin.start(action.runningLabel);
|
|
457
|
+
const result = await runAction({
|
|
458
|
+
driver,
|
|
459
|
+
fallbackDrivers,
|
|
460
|
+
action,
|
|
461
|
+
ctx: context,
|
|
462
|
+
onEvent: (event) => {
|
|
463
|
+
if (event.type === "status") spin.message(event.text);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
if (!result.ok) {
|
|
467
|
+
spin.stop("The agent stopped before finishing.");
|
|
468
|
+
if (result.finalText) ui.report(stripReport(result.finalText).slice(0, 1500));
|
|
469
|
+
throw new Error(`${action.title} did not complete.`);
|
|
470
|
+
}
|
|
471
|
+
spin.stop(action.successLabel);
|
|
472
|
+
if (action.outputMode === "report" && result.finalText) {
|
|
473
|
+
const report = stripReport(result.finalText);
|
|
474
|
+
saveReport(context.app.path, action.id, report);
|
|
475
|
+
ui.report(report);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function printPlan(agent, action, context) {
|
|
479
|
+
ui.note([
|
|
480
|
+
`Agent: ${agent}`,
|
|
481
|
+
`Action: ${action.title}`,
|
|
482
|
+
`App: ${context.app.name} (${context.app.framework.name}${context.app.details ? `, ${context.app.details}` : ""})`,
|
|
483
|
+
`Path: ${context.app.path}`,
|
|
484
|
+
`Key: ${context.apiKey || "(none)"}`,
|
|
485
|
+
`Mode: ${action.capabilities.filesystem === "read" ? "read-only" : "read-write"} · ${action.outputMode}`,
|
|
486
|
+
`Prior: ${context.priorReport ? "review report found" : "none"}`
|
|
487
|
+
].join("\n"), "Plan");
|
|
488
|
+
}
|
|
489
|
+
function finish(context, action) {
|
|
490
|
+
const finalBlocks = [blocks.nextSteps({
|
|
491
|
+
integrate: ["Set up the dashboard (campaign + paywall) so the placement presents something.", "Verify on device for placement 'campaign_trigger'."],
|
|
492
|
+
"placements-implement": ["Set up the dashboard so the new placements present paywalls."],
|
|
493
|
+
"dashboard-setup": ["Design the paywall and attach products in the dashboard.", "Verify on device."]
|
|
494
|
+
}[action.id] ?? [])];
|
|
495
|
+
if (action.id !== "review" && action.id !== "review-fix") finalBlocks.push(blocks.outro(`Done. ${DASHBOARD_URL}`));
|
|
496
|
+
context.output.render(...finalBlocks);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
//#endregion
|
|
500
|
+
//#region src/commands/workflow/integrate/campaigns.ts
|
|
501
|
+
async function runCampaignsAndPlacements(driver, fallbackDrivers, actionContext, stageContext, ensureAgentReady) {
|
|
502
|
+
const { api, scope } = stageContext;
|
|
503
|
+
const campaigns = await withSpinner("Checking campaigns", () => listResource(api, "campaigns", scope));
|
|
504
|
+
if (campaigns.length) ui.list({ items: campaigns.map((campaign) => {
|
|
505
|
+
const placements = placementsOf(campaign);
|
|
506
|
+
return {
|
|
507
|
+
label: rowName(campaign),
|
|
508
|
+
meta: String(campaign.id ?? ""),
|
|
509
|
+
children: placements.length ? placements.map((placement) => ({
|
|
510
|
+
label: placement.event_name ?? "",
|
|
511
|
+
badge: placement.enabled === false ? "off" : void 0
|
|
512
|
+
})) : [{ label: "no placements yet" }]
|
|
513
|
+
};
|
|
514
|
+
}) });
|
|
515
|
+
else ui.info("No campaigns yet.");
|
|
516
|
+
if (!await ui.confirm({ message: "Review your placements & campaigns now?" })) return;
|
|
517
|
+
const context = {
|
|
518
|
+
...actionContext,
|
|
519
|
+
campaigns: campaignSummary(campaigns)
|
|
520
|
+
};
|
|
521
|
+
if (!await ensureAgentReady()) return;
|
|
522
|
+
await runActionWithUI(driver, fallbackDrivers, actionById["placements-review"], context);
|
|
523
|
+
if (await ui.confirm({ message: "Apply the suggested changes?" })) {
|
|
524
|
+
if (!await ensureAgentReady()) return;
|
|
525
|
+
await runActionWithUI(driver, fallbackDrivers, actionById["placements-implement"], {
|
|
526
|
+
...context,
|
|
527
|
+
priorReport: loadReport(actionContext.app.path, "placements-review")
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (await ui.confirm({ message: "Create campaigns so these placements can present paywalls?" })) {
|
|
531
|
+
if (!await ensureAgentReady()) return;
|
|
532
|
+
await runActionWithUI(driver, fallbackDrivers, actionById["dashboard-setup"], {
|
|
533
|
+
...context,
|
|
534
|
+
campaigns: campaignSummary(await listResource(api, "campaigns", scope).catch(() => campaigns))
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function placementsOf(campaign) {
|
|
539
|
+
return campaign.placements ?? [];
|
|
540
|
+
}
|
|
541
|
+
function campaignSummary(campaigns) {
|
|
542
|
+
if (!campaigns.length) return "No campaigns exist yet - the app will likely need at least one.";
|
|
543
|
+
return campaigns.map((campaign) => {
|
|
544
|
+
const names = placementsOf(campaign).map((placement) => placement.event_name).filter(Boolean).join(", ");
|
|
545
|
+
return `- ${rowName(campaign)}: ${names || "(no placements)"}`;
|
|
546
|
+
}).join("\n");
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/commands/workflow/integrate.ts
|
|
551
|
+
const runIntegrate = defineCommand({
|
|
552
|
+
name: "integrate",
|
|
553
|
+
auth: "optional",
|
|
554
|
+
telemetry: "workflow",
|
|
555
|
+
run: runPipeline
|
|
556
|
+
});
|
|
557
|
+
function runActionCommand(action) {
|
|
558
|
+
return defineCommand({
|
|
559
|
+
name: action,
|
|
560
|
+
auth: "optional",
|
|
561
|
+
telemetry: "workflow",
|
|
562
|
+
run: (ctx) => runFlow(ctx, action)
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
async function runPipeline(ctx) {
|
|
566
|
+
const { installDir, dryRun, argv } = ctx;
|
|
567
|
+
ui.intro(`Superwall v${VERSION}`);
|
|
568
|
+
const drivers = await withSpinner("Checking your setup", () => detectDrivers());
|
|
569
|
+
if (drivers.length === 0) {
|
|
570
|
+
ui.warn("No coding agent found.");
|
|
571
|
+
await runFallback(installDir);
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const wanted = argv.driver;
|
|
575
|
+
const picked = wanted ? drivers.find((d) => d.driver.id === wanted) : drivers[0];
|
|
576
|
+
if (wanted && !picked) throw new Error(`Driver "${wanted}" not available. Detected: ${drivers.map((d) => d.driver.id).join(", ") || "none"}.`);
|
|
577
|
+
const driver = picked.driver;
|
|
578
|
+
const fallbackDrivers = wanted ? [] : drivers.filter((candidate) => candidate !== picked).map((candidate) => candidate.driver);
|
|
579
|
+
const app = await pickApp(installDir, ctx.interactive);
|
|
580
|
+
if (!app) return;
|
|
581
|
+
setTelemetryTags({
|
|
582
|
+
driver: driver.id,
|
|
583
|
+
framework: app.framework.integration
|
|
584
|
+
});
|
|
585
|
+
const existing = detectExisting(app);
|
|
586
|
+
if (existing.fullyIntegrated) ui.success(`Superwall is already set up in \`${app.name}\`.`);
|
|
587
|
+
else if (existing.sdkInstalled) ui.info(`Partial Superwall setup found in \`${app.name}\`.`);
|
|
588
|
+
if (detectBilling(app).revenueCat && ctx.interactive) {
|
|
589
|
+
const intent = await ui.select({
|
|
590
|
+
message: "You're using `RevenueCat`. What do you want Superwall for?",
|
|
591
|
+
options: [
|
|
592
|
+
{
|
|
593
|
+
value: "paywalls",
|
|
594
|
+
label: "Paywalls only - keep RevenueCat for billing"
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
value: "migrate",
|
|
598
|
+
label: "Fully migrate to Superwall"
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
value: "later",
|
|
602
|
+
label: "Decide later"
|
|
603
|
+
}
|
|
604
|
+
],
|
|
605
|
+
initialValue: "paywalls"
|
|
606
|
+
});
|
|
607
|
+
if (intent === null) return;
|
|
608
|
+
ui.info(`RevenueCat: \`${intent}\``);
|
|
609
|
+
}
|
|
610
|
+
let session = loadSession();
|
|
611
|
+
if (session?.apiKey) process.env.SUPERWALL_API_KEY = session.apiKey;
|
|
612
|
+
let scopePromise = null;
|
|
613
|
+
if (session && existing.apiKey) scopePromise = resolveScopeFromKey(SuperwallApi.fromSession(), existing.apiKey).catch(() => null);
|
|
614
|
+
const provisionedRef = { current: null };
|
|
615
|
+
const ensureLogin = async () => {
|
|
616
|
+
if (session) return true;
|
|
617
|
+
if (!ctx.interactive || dryRun) return false;
|
|
618
|
+
const signedIn = await performLoginWithUi(app, (result) => {
|
|
619
|
+
provisionedRef.current = result;
|
|
620
|
+
});
|
|
621
|
+
if (!signedIn) return false;
|
|
622
|
+
session = signedIn;
|
|
623
|
+
if (session.apiKey) process.env.SUPERWALL_API_KEY = session.apiKey;
|
|
624
|
+
return true;
|
|
625
|
+
};
|
|
626
|
+
let apiKey = existing.apiKey ?? "";
|
|
627
|
+
const flagKey = argv.apiKey ?? apiKeyFromEnv();
|
|
628
|
+
let scope = null;
|
|
629
|
+
let bundleId;
|
|
630
|
+
if (!apiKey && !flagKey) {
|
|
631
|
+
const remembered = getOnboardedApp(app.path);
|
|
632
|
+
if (remembered) {
|
|
633
|
+
apiKey = remembered.publicApiKey;
|
|
634
|
+
if (remembered.projectId && remembered.applicationId) scope = {
|
|
635
|
+
projectId: remembered.projectId,
|
|
636
|
+
applicationId: remembered.applicationId,
|
|
637
|
+
appName: app.name
|
|
638
|
+
};
|
|
639
|
+
ui.info(`Using \`${app.name}\` - created during onboarding.`);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (!apiKey && !flagKey) {
|
|
643
|
+
if (!ctx.interactive) {
|
|
644
|
+
if (session) {
|
|
645
|
+
const disc = await withSpinner("Finding your app", () => discoverPublicApiKey(SuperwallApi.fromSession()));
|
|
646
|
+
if (disc) {
|
|
647
|
+
apiKey = disc.apiKey;
|
|
648
|
+
ui.info(`Using app \`${disc.app.name ?? disc.app.bundle_id ?? disc.app.id}\``);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
} else if (await ensureLogin()) {
|
|
652
|
+
const provisioned = provisionedRef.current;
|
|
653
|
+
if (provisioned?.publicApiKey) {
|
|
654
|
+
apiKey = provisioned.publicApiKey;
|
|
655
|
+
if (provisioned.projectId && provisioned.applicationId) scope = {
|
|
656
|
+
projectId: provisioned.projectId,
|
|
657
|
+
applicationId: provisioned.applicationId,
|
|
658
|
+
appName: app.name
|
|
659
|
+
};
|
|
660
|
+
ui.success(`Created \`${app.name}\` in Superwall`);
|
|
661
|
+
} else try {
|
|
662
|
+
const bound = await resolveAppBinding(SuperwallApi.fromSession(), {
|
|
663
|
+
platform: platformForIntegration(app.integration),
|
|
664
|
+
appName: app.name
|
|
665
|
+
});
|
|
666
|
+
if (!bound) return void ui.warn("Cancelled.");
|
|
667
|
+
apiKey = bound.apiKey;
|
|
668
|
+
scope = {
|
|
669
|
+
projectId: bound.projectId,
|
|
670
|
+
applicationId: bound.applicationId,
|
|
671
|
+
appName: app.name
|
|
672
|
+
};
|
|
673
|
+
bundleId = bound.app.bundle_id;
|
|
674
|
+
ui.success(`Using \`${bound.app.name ?? bound.app.id}\` (${platformLabel(bound.app.platform)})`);
|
|
675
|
+
} catch (e) {
|
|
676
|
+
ui.warn(e.message);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (!apiKey) {
|
|
681
|
+
const account = await resolveAccount({
|
|
682
|
+
existing,
|
|
683
|
+
argv,
|
|
684
|
+
interactive: ctx.interactive,
|
|
685
|
+
ui: ctx.ui
|
|
686
|
+
});
|
|
687
|
+
if (!account) return void ui.warn("Cancelled.");
|
|
688
|
+
apiKey = account.apiKey;
|
|
689
|
+
}
|
|
690
|
+
const ctxAction = {
|
|
691
|
+
app,
|
|
692
|
+
apiKey,
|
|
693
|
+
existing
|
|
694
|
+
};
|
|
695
|
+
const ensureAgentReady = () => ensureAgentDriverReady(driver, ensureLogin, dryRun);
|
|
696
|
+
ui.step("Step 1 · Integrate the SDK");
|
|
697
|
+
if (existing.fullyIntegrated) {
|
|
698
|
+
ui.info("SDK already integrated - skipped.");
|
|
699
|
+
if (!dryRun) await ensureSkillsCurrent();
|
|
700
|
+
} else if (!dryRun) {
|
|
701
|
+
const how = !ctx.interactive ? "now" : await ui.select({
|
|
702
|
+
message: `Integrate the Superwall SDK into \`${app.name}\`?`,
|
|
703
|
+
options: [{
|
|
704
|
+
value: "now",
|
|
705
|
+
label: "Integrate for me"
|
|
706
|
+
}, {
|
|
707
|
+
value: "copy",
|
|
708
|
+
label: "Copy the prompt",
|
|
709
|
+
hint: "Run it in your own agent"
|
|
710
|
+
}],
|
|
711
|
+
initialValue: "now"
|
|
712
|
+
});
|
|
713
|
+
if (how === null) return void ui.warn("Cancelled.");
|
|
714
|
+
if (how === "copy") {
|
|
715
|
+
await copyIntegrationPrompt(ctxAction);
|
|
716
|
+
ui.outro("Paste it into your agent, then run `superwall integrate` to continue.");
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (!await ensureAgentReady()) {
|
|
720
|
+
if (ctx.interactive) {
|
|
721
|
+
await copyIntegrationPrompt(ctxAction);
|
|
722
|
+
ui.outro("Paste it into your agent, or run `superwall login` and try again.");
|
|
723
|
+
}
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
await runActionWithUI(driver, fallbackDrivers, actionById["integrate"], ctxAction);
|
|
727
|
+
await ensureSkillsCurrent(true);
|
|
728
|
+
}
|
|
729
|
+
const canResolveHeadless = !ctx.interactive && !!apiKey && !!loadSession();
|
|
730
|
+
if (!dryRun && !ctx.interactive && !loadSession()) {
|
|
731
|
+
ui.warn("You aren't logged in — headless mode cannot run the placements/campaigns stages. Run `superwall login` first. The SDK code changes (if any) were applied, but the integration is INCOMPLETE.");
|
|
732
|
+
process.exitCode = 1;
|
|
733
|
+
}
|
|
734
|
+
if (!dryRun && !scope && (canResolveHeadless || ctx.interactive && await ensureLogin())) {
|
|
735
|
+
const resolved = await withSpinner("Finding this app in Superwall", () => scopePromise ? scopePromise : resolveScopeFromKey(SuperwallApi.fromSession(), apiKey).catch(() => null));
|
|
736
|
+
if (resolved) {
|
|
737
|
+
scope = resolved;
|
|
738
|
+
bundleId = resolved.bundleId;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (!scope && !dryRun && ctx.interactive && apiKey && await ensureLogin()) {
|
|
742
|
+
const recovered = await recoverUnmatchedScope(app, apiKey);
|
|
743
|
+
if (recovered) {
|
|
744
|
+
scope = recovered.scope;
|
|
745
|
+
bundleId = recovered.bundleId;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (scope) {
|
|
749
|
+
const stageCtx = {
|
|
750
|
+
api: SuperwallApi.fromSession(),
|
|
751
|
+
scope,
|
|
752
|
+
appName: app.name,
|
|
753
|
+
bundleId,
|
|
754
|
+
projectDir: app.path
|
|
755
|
+
};
|
|
756
|
+
await stage("Step 2 · Products", () => runProductsStage(stageCtx));
|
|
757
|
+
await stage("Step 3 · Campaigns & Placements", () => runCampaignsAndPlacements(driver, fallbackDrivers, ctxAction, stageCtx, ensureAgentReady));
|
|
758
|
+
await stage("Step 4 · Paywall", () => runPaywallStage());
|
|
759
|
+
await stage("Step 5 · Verify", () => runVerifyStage(stageCtx));
|
|
760
|
+
} else if (!dryRun && ctx.interactive) {
|
|
761
|
+
ui.error("Couldn't connect this app to Superwall - set it up in the dashboard, or re-run to try again.");
|
|
762
|
+
process.exitCode = 1;
|
|
763
|
+
}
|
|
764
|
+
ui.outro(`Done. ${DASHBOARD_URL}`);
|
|
765
|
+
}
|
|
766
|
+
async function runFlow(ctx, forced) {
|
|
767
|
+
const { installDir, dryRun, argv } = ctx;
|
|
768
|
+
ui.intro(`Superwall v${VERSION}`);
|
|
769
|
+
const drivers = await withSpinner("Checking your setup", () => detectDrivers());
|
|
770
|
+
if (drivers.length === 0) {
|
|
771
|
+
ui.warn("No coding agent found.");
|
|
772
|
+
await runFallback(installDir);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const driver = drivers[0];
|
|
776
|
+
const fallbackDrivers = drivers.slice(1).map((candidate) => candidate.driver);
|
|
777
|
+
let session = loadSession();
|
|
778
|
+
const app = await pickApp(installDir, ctx.interactive);
|
|
779
|
+
if (!app) return void ui.warn("Cancelled.");
|
|
780
|
+
const provisionedRef = { current: null };
|
|
781
|
+
const ensureLogin = async () => {
|
|
782
|
+
if (session) return true;
|
|
783
|
+
if (!ctx.interactive || dryRun) return false;
|
|
784
|
+
const signedIn = await performLoginWithUi(app, (result) => {
|
|
785
|
+
provisionedRef.current = result;
|
|
786
|
+
});
|
|
787
|
+
if (!signedIn) return false;
|
|
788
|
+
session = signedIn;
|
|
789
|
+
if (session.apiKey) process.env.SUPERWALL_API_KEY = session.apiKey;
|
|
790
|
+
return true;
|
|
791
|
+
};
|
|
792
|
+
setTelemetryTags({
|
|
793
|
+
driver: driver.driver.id,
|
|
794
|
+
framework: app.framework.integration
|
|
795
|
+
});
|
|
796
|
+
const existing = detectExisting(app);
|
|
797
|
+
if (existing.fullyIntegrated) ui.success(`Superwall is already set up in \`${app.name}\`.`);
|
|
798
|
+
else if (existing.sdkInstalled) ui.info(`Partial Superwall setup found in \`${app.name}\`.`);
|
|
799
|
+
const choice = await chooseAction(forced, existing, app, ctx.interactive);
|
|
800
|
+
if (!choice) return;
|
|
801
|
+
const action = actionById[choice];
|
|
802
|
+
if (action.requiresOrgKey && !process.env.SUPERWALL_API_KEY && !loadSession()) {
|
|
803
|
+
ui.warn("That needs an authenticated session - run `superwall login` first (or set SUPERWALL_API_KEY).");
|
|
804
|
+
ui.outro("");
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
let apiKey = existing.apiKey ?? "";
|
|
808
|
+
if (action.id === "integrate" || action.id === "dashboard-setup") {
|
|
809
|
+
const flagKey = argv.apiKey ?? apiKeyFromEnv();
|
|
810
|
+
if (!apiKey && !flagKey) {
|
|
811
|
+
const remembered = getOnboardedApp(app.path);
|
|
812
|
+
if (remembered) {
|
|
813
|
+
apiKey = remembered.publicApiKey;
|
|
814
|
+
ui.info(`Using \`${app.name}\` - created during onboarding.`);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (!apiKey && !flagKey && ctx.interactive && await ensureLogin()) if (provisionedRef.current?.publicApiKey) {
|
|
818
|
+
apiKey = provisionedRef.current.publicApiKey;
|
|
819
|
+
ui.success(`Created \`${app.name}\` in Superwall`);
|
|
820
|
+
} else try {
|
|
821
|
+
const bound = await resolveAppBinding(SuperwallApi.fromSession(), {
|
|
822
|
+
platform: platformForIntegration(app.integration),
|
|
823
|
+
appName: app.name
|
|
824
|
+
});
|
|
825
|
+
if (!bound) return void ui.warn("Cancelled.");
|
|
826
|
+
apiKey = bound.apiKey;
|
|
827
|
+
} catch (e) {
|
|
828
|
+
ui.warn(e.message);
|
|
829
|
+
}
|
|
830
|
+
if (!apiKey) {
|
|
831
|
+
const account = await resolveAccount({
|
|
832
|
+
existing,
|
|
833
|
+
argv,
|
|
834
|
+
interactive: ctx.interactive,
|
|
835
|
+
ui: ctx.ui
|
|
836
|
+
});
|
|
837
|
+
if (!account) return void ui.warn("Cancelled.");
|
|
838
|
+
apiKey = account.apiKey;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
const priorReport = action.id === "review-fix" ? loadReport(app.path, "review") : action.id === "placements-implement" ? loadReport(app.path, "placements-review") : void 0;
|
|
842
|
+
const actionCtx = {
|
|
843
|
+
app,
|
|
844
|
+
apiKey,
|
|
845
|
+
existing,
|
|
846
|
+
priorReport
|
|
847
|
+
};
|
|
848
|
+
if (dryRun) {
|
|
849
|
+
printPlan(driver.info.displayName, action, actionCtx);
|
|
850
|
+
ui.outro("Dry run - no changes made.");
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
if (action.id === "integrate" && existing.fullyIntegrated) ui.note("SDK + configure() already present - no code changes made.", "Already integrated");
|
|
854
|
+
else {
|
|
855
|
+
if (!await ensureAgentDriverReady(driver.driver, ensureLogin, dryRun)) return;
|
|
856
|
+
await runActionWithUI(driver.driver, fallbackDrivers, action, actionCtx);
|
|
857
|
+
}
|
|
858
|
+
await ensureSkillsCurrent(action.id === "integrate" && !existing.fullyIntegrated);
|
|
859
|
+
finish(ctx, action);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
//#endregion
|
|
863
|
+
export { runActionCommand, runIntegrate };
|