@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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -0
  3. package/dist/actions-MB-eBY64.js +140 -0
  4. package/dist/api-BF7-toqM.js +151 -0
  5. package/dist/api-output-B5hh0q4V.js +20 -0
  6. package/dist/app-K6j9Es7h.js +189 -0
  7. package/dist/asc-CArSwo5D.js +539 -0
  8. package/dist/asc-products-YQ6Oc6YO.js +93 -0
  9. package/dist/auth-CY2cO_NF.js +139 -0
  10. package/dist/auth.d.ts +30 -0
  11. package/dist/auth.js +4 -0
  12. package/dist/billing-DWyfEQ6l.js +80 -0
  13. package/dist/bind-hslFhcTR.js +213 -0
  14. package/dist/chunk-DQxbwPpZ.js +30 -0
  15. package/dist/command-Kwx4ekbo.js +283 -0
  16. package/dist/create-Bbi8BOO1.js +410 -0
  17. package/dist/dev-D0lQDCQI.js +397 -0
  18. package/dist/devtools-8EgLo86w.js +3638 -0
  19. package/dist/doctor-ByeRdMcl.js +88 -0
  20. package/dist/drivers-DVAZgone.js +413 -0
  21. package/dist/entry.d.ts +9 -0
  22. package/dist/entry.js +495 -0
  23. package/dist/existing-CcJrIIAU.js +88 -0
  24. package/dist/feedback-Z0Wk7VC5.js +73 -0
  25. package/dist/git-3OX9u3xE.js +433 -0
  26. package/dist/hosted-CHwaUqLd.js +32 -0
  27. package/dist/integrate-DqOAqK7J.js +863 -0
  28. package/dist/json-C3hPIMkI.js +7 -0
  29. package/dist/login-Dr8UN_Gx.js +290 -0
  30. package/dist/migrate-D92bJTg6.js +114 -0
  31. package/dist/org-B2gy9Pmu.js +40 -0
  32. package/dist/params-Bvq0iqQK.js +52 -0
  33. package/dist/pipeline-CHHIg6BU.js +1056 -0
  34. package/dist/print-skill-BnZAk7dV.js +74 -0
  35. package/dist/promote-CRe9170G.js +88 -0
  36. package/dist/publish-DsODvrOD.js +35 -0
  37. package/dist/push-BDkZUC0v.js +35 -0
  38. package/dist/query-DIllrSnk.js +53 -0
  39. package/dist/resource-CdP1MDla.js +483 -0
  40. package/dist/resources-CVrWwA1K.js +233 -0
  41. package/dist/run-cGGBUMs5.js +89 -0
  42. package/dist/scan-BQexuUPO.js +236 -0
  43. package/dist/skills-DhuUs28u.js +64 -0
  44. package/dist/skills-xrfXt9u0.js +205 -0
  45. package/dist/spawn-DSoTXy_j.js +69 -0
  46. package/dist/spinner-gOxIMz-V.js +18 -0
  47. package/dist/storekit-Ddvs4Ynw.js +29 -0
  48. package/dist/telemetry-CcfrtXdf.js +204 -0
  49. package/dist/token-DHRH8cxi.js +102 -0
  50. package/dist/ui-C4ncRJqd.js +27703 -0
  51. package/dist/update-BiVeR024.js +137 -0
  52. package/dist/upgrade-DYWspApv.js +72 -0
  53. package/package.json +87 -0
  54. package/prompts/actions/dashboard-setup.xml +10 -0
  55. package/prompts/actions/integrate.xml +5 -0
  56. package/prompts/actions/migrate.xml +11 -0
  57. package/prompts/actions/placements-implement.xml +20 -0
  58. package/prompts/actions/placements-review.xml +18 -0
  59. package/prompts/actions/review-fix.xml +18 -0
  60. package/prompts/actions/review.xml +18 -0
  61. package/prompts/commandments.xml +17 -0
  62. package/prompts/context.xml +9 -0
  63. package/skills/README.md +118 -0
  64. package/skills/superwall-dashboard/SKILL.md +81 -0
  65. package/skills/superwall-dashboard/references/setup.md +101 -0
  66. package/skills/superwall-integrate/SKILL.md +76 -0
  67. package/skills/superwall-integrate/references/expo.md +269 -0
  68. package/skills/superwall-integrate/references/flutter.md +285 -0
  69. package/skills/superwall-integrate/references/ios.md +314 -0
  70. package/skills/superwall-integrate/references/react-native.md +245 -0
  71. package/skills/superwall-migrate/SKILL.md +83 -0
  72. package/skills/superwall-migrate/references/adapty.md +229 -0
  73. package/skills/superwall-migrate/references/qonversion.md +227 -0
  74. package/skills/superwall-migrate/references/revenuecat.md +414 -0
  75. package/skills/superwall-placements/SKILL.md +73 -0
  76. package/skills/superwall-placements/references/expo.md +161 -0
  77. package/skills/superwall-placements/references/flutter.md +139 -0
  78. package/skills/superwall-placements/references/ios.md +165 -0
  79. package/skills/superwall-placements/references/react-native.md +145 -0
  80. package/skills/superwall-placements/references/strategy.md +221 -0
  81. package/skills/superwall-review/SKILL.md +75 -0
  82. package/skills/superwall-review/references/expo.md +100 -0
  83. package/skills/superwall-review/references/flutter.md +99 -0
  84. package/skills/superwall-review/references/ios.md +108 -0
  85. package/skills/superwall-review/references/react-native.md +100 -0
@@ -0,0 +1,397 @@
1
+ import { k as VERSION } from "./telemetry-CcfrtXdf.js";
2
+ import "./json-C3hPIMkI.js";
3
+ import "./update-BiVeR024.js";
4
+ import "./token-DHRH8cxi.js";
5
+ import { t as defineCommand } from "./command-Kwx4ekbo.js";
6
+ import { n as ui } from "./ui-C4ncRJqd.js";
7
+ import "./skills-xrfXt9u0.js";
8
+ import "./spawn-DSoTXy_j.js";
9
+ import "./login-Dr8UN_Gx.js";
10
+ import "./scan-BQexuUPO.js";
11
+ import "./hosted-CHwaUqLd.js";
12
+ import "./spinner-gOxIMz-V.js";
13
+ import { S as pushPaywallVersion, T as versionProducts, b as promotePaywallVersion, f as listApplications } from "./resources-CVrWwA1K.js";
14
+ import "./org-B2gy9Pmu.js";
15
+ import "./bind-hslFhcTR.js";
16
+ import { f as readLock, i as requireApi, o as writeProjectScaffold, u as resolveApps } from "./git-3OX9u3xE.js";
17
+ import "./actions-MB-eBY64.js";
18
+ import "./app-K6j9Es7h.js";
19
+ import { C as syncAssets, D as writeProjectTypes, E as collectProjectDeclarations, S as requireAssets, T as loadFramework, _ as planTargets, a as requireProject, b as resolveBinding, d as pushSource, f as collectSourceFiles, h as projectForApplication, i as projectDirs, m as fetchProducts, p as warnNotPortable, r as projectDir, t as LAYOUT_HINT, w as frameworkVersion, x as assetBaseUrl, y as wantedPlatforms } from "./pipeline-CHHIg6BU.js";
20
+ import pc from "picocolors";
21
+ import * as fs from "node:fs";
22
+ import * as path from "node:path";
23
+ import fg from "fast-glob";
24
+ import { renderUnicodeCompact } from "uqr";
25
+
26
+ //#region src/core/paywalls/project/scheme.ts
27
+ const IGNORED_SCHEMES = new Set([
28
+ "http",
29
+ "https",
30
+ "file",
31
+ "mailto",
32
+ "tel",
33
+ "sms"
34
+ ]);
35
+ const IGNORE = [
36
+ "**/node_modules/**",
37
+ "**/.git/**",
38
+ "**/Pods/**",
39
+ "**/build/**",
40
+ "**/DerivedData/**",
41
+ "**/.expo/**",
42
+ "**/dist/**"
43
+ ];
44
+ const usable = (value) => {
45
+ if (typeof value !== "string") return void 0;
46
+ const trimmed = value.trim();
47
+ if (trimmed === "" || IGNORED_SCHEMES.has(trimmed.toLowerCase())) return void 0;
48
+ return trimmed;
49
+ };
50
+ const schemeFromInfoPlist = (contents) => {
51
+ const block = /<key>CFBundleURLSchemes<\/key>\s*<array>([\s\S]*?)<\/array>/.exec(contents);
52
+ if (!block?.[1]) return void 0;
53
+ for (const match of block[1].matchAll(/<string>([^<]*)<\/string>/g)) {
54
+ const scheme = usable(match[1]);
55
+ if (scheme !== void 0) return scheme;
56
+ }
57
+ };
58
+ const schemeFromExpoConfig = (contents) => {
59
+ try {
60
+ const parsed = JSON.parse(contents);
61
+ if (typeof parsed !== "object" || parsed === null) return void 0;
62
+ const record = parsed;
63
+ const value = record.expo?.scheme ?? record.scheme;
64
+ if (typeof value === "string") return usable(value);
65
+ if (Array.isArray(value)) {
66
+ for (const entry of value) if (typeof entry === "string") {
67
+ const scheme = usable(entry);
68
+ if (scheme !== void 0) return scheme;
69
+ }
70
+ }
71
+ return;
72
+ } catch {
73
+ return;
74
+ }
75
+ };
76
+ const schemeFromAndroidManifest = (contents) => {
77
+ for (const match of contents.matchAll(/android:scheme="([^"]*)"/g)) {
78
+ const scheme = usable(match[1]);
79
+ if (scheme !== void 0) return scheme;
80
+ }
81
+ };
82
+ const allowsLocalNetworking = (contents) => {
83
+ const block = /<key>NSAppTransportSecurity<\/key>\s*<dict>([\s\S]*?)<\/dict>/.exec(contents);
84
+ if (!block?.[1]) return false;
85
+ const keys = block[1];
86
+ const enabled = (key) => (/* @__PURE__ */ new RegExp(`<key>${key}</key>\\s*<true\\s*/>`)).test(keys);
87
+ return enabled("NSAllowsArbitraryLoads") || enabled("NSAllowsLocalNetworking") && enabled("NSAllowsArbitraryLoadsInWebContent");
88
+ };
89
+ const detectAppTransportSecurity = async (roots) => {
90
+ const dirs = (typeof roots === "string" ? [roots] : roots).map((dir) => path.resolve(dir));
91
+ for (const dir of dirs) {
92
+ const files = await fg("**/Info.plist", {
93
+ cwd: dir,
94
+ absolute: true,
95
+ ignore: IGNORE,
96
+ deep: 6,
97
+ suppressErrors: true
98
+ });
99
+ for (const file of files.sort()) try {
100
+ const contents = fs.readFileSync(file, "utf8");
101
+ if (!contents.includes("CFBundleURLTypes") && !contents.includes("CFBundleIdentifier")) continue;
102
+ return {
103
+ plist: file,
104
+ allowed: allowsLocalNetworking(contents)
105
+ };
106
+ } catch {
107
+ continue;
108
+ }
109
+ }
110
+ };
111
+ const READERS = [
112
+ ["**/Info.plist", schemeFromInfoPlist],
113
+ ["**/app.json", schemeFromExpoConfig],
114
+ ["**/app.config.json", schemeFromExpoConfig],
115
+ ["**/AndroidManifest.xml", schemeFromAndroidManifest]
116
+ ];
117
+ const detectLocalScheme = async (roots) => {
118
+ const dirs = (typeof roots === "string" ? [roots] : roots).map((dir) => path.resolve(dir));
119
+ for (const [pattern, read] of READERS) for (const dir of dirs) {
120
+ const files = await fg(pattern, {
121
+ cwd: dir,
122
+ absolute: true,
123
+ ignore: IGNORE,
124
+ deep: 6,
125
+ suppressErrors: true
126
+ });
127
+ for (const file of files.sort()) try {
128
+ const scheme = read(fs.readFileSync(file, "utf8"));
129
+ if (scheme !== void 0) return scheme;
130
+ } catch {
131
+ continue;
132
+ }
133
+ }
134
+ };
135
+ const schemeSearchRoots = (project) => {
136
+ const root = path.resolve(project.root);
137
+ const superwallDir = path.resolve(project.superwallDir);
138
+ const roots = [root];
139
+ if (root === superwallDir) roots.push(path.dirname(root));
140
+ return roots;
141
+ };
142
+ const appScheme = async (roots, remote) => {
143
+ const fromDashboard = usable(await remote().catch(() => void 0));
144
+ if (fromDashboard !== void 0) return {
145
+ scheme: fromDashboard,
146
+ source: "dashboard"
147
+ };
148
+ const local = await detectLocalScheme(roots).catch(() => void 0);
149
+ return local === void 0 ? {} : {
150
+ scheme: local,
151
+ source: "app"
152
+ };
153
+ };
154
+
155
+ //#endregion
156
+ //#region src/commands/paywalls/studio-actions.ts
157
+ const reason = (error) => error instanceof Error ? error.message : String(error);
158
+ const firstApp = (apps) => apps.ios ?? Object.values(apps)[0];
159
+ function createStudioActions(framework, project) {
160
+ let api;
161
+ const ensureApi = async () => api ??= await requireApi(false);
162
+ const targetsFor = async (client, surface) => {
163
+ const declared = (await collectProjectDeclarations(framework, project.root)).platforms;
164
+ const apps = await resolveApps({
165
+ api: client,
166
+ superwallDir: project.superwallDir,
167
+ wanted: wantedPlatforms([surface], declared)
168
+ });
169
+ return planTargets({
170
+ surfaces: [surface],
171
+ declared,
172
+ apps
173
+ });
174
+ };
175
+ return {
176
+ async appScheme() {
177
+ const applicationId = firstApp(readLock(project.superwallDir).apps);
178
+ const roots = schemeSearchRoots(project);
179
+ const [resolved, transport] = await Promise.all([appScheme(roots, async () => {
180
+ if (applicationId === void 0) return void 0;
181
+ return (await listApplications(await ensureApi())).find((app) => String(app.id) === applicationId)?.apple_url_scheme;
182
+ }), detectAppTransportSecurity(roots)]);
183
+ return transport === void 0 || transport.allowed ? resolved : {
184
+ ...resolved,
185
+ blocksLocalNetworking: transport.plist
186
+ };
187
+ },
188
+ async samples() {
189
+ try {
190
+ const client = await ensureApi();
191
+ const applicationId = firstApp(await resolveApps({
192
+ api: client,
193
+ superwallDir: project.superwallDir
194
+ }));
195
+ if (applicationId === void 0) return { unreachable: "This project is not bound to an app yet." };
196
+ const query = `?application_id=${encodeURIComponent(applicationId)}`;
197
+ let unreachable;
198
+ const [device, user, products] = await Promise.all([
199
+ client.get(`/v2/users/device-properties-sample${query}`).catch(() => void 0),
200
+ client.get(`/v2/users/properties-sample${query}`).catch(() => void 0),
201
+ projectForApplication(client, applicationId).then((projectId) => projectId ? fetchProducts(client, projectId) : void 0).catch((error) => {
202
+ unreachable = reason(error);
203
+ })
204
+ ]);
205
+ return {
206
+ device: device?.properties,
207
+ user: user?.properties,
208
+ products,
209
+ live: {
210
+ device: device?.live === true,
211
+ user: user?.live === true
212
+ },
213
+ unreachable
214
+ };
215
+ } catch (error) {
216
+ return { unreachable: reason(error) };
217
+ }
218
+ },
219
+ async run(action, surface, onProgress = () => {}) {
220
+ const step = async (name, work) => {
221
+ onProgress(name, "start");
222
+ const value = await work();
223
+ onProgress(name, "done");
224
+ return value;
225
+ };
226
+ try {
227
+ const client = await ensureApi();
228
+ const targets = await step("link", () => targetsFor(client, surface));
229
+ const app = (target) => ({
230
+ platform: target.platform,
231
+ applicationId: target.applicationId
232
+ });
233
+ if (action === "promote") {
234
+ let version$1 = 0;
235
+ for (const target of targets) {
236
+ const binding = await resolveBinding({
237
+ api: client,
238
+ superwallDir: project.superwallDir,
239
+ surface,
240
+ app: app(target),
241
+ surfaces: project.surfaces,
242
+ create: false
243
+ });
244
+ version$1 = (await step("promote", () => promotePaywallVersion(client, binding.paywallId))).version;
245
+ }
246
+ return {
247
+ ok: true,
248
+ version: version$1,
249
+ live: true
250
+ };
251
+ }
252
+ const collected = await collectSourceFiles(project.superwallDir);
253
+ let version = 0;
254
+ const external = /* @__PURE__ */ new Set();
255
+ for (const target of targets) {
256
+ const built = await step("build", () => framework.buildSnapshot(project, surface, {
257
+ assetBaseUrl: assetBaseUrl(target.applicationId),
258
+ platform: target.platform
259
+ }));
260
+ const binding = await resolveBinding({
261
+ api: client,
262
+ superwallDir: project.superwallDir,
263
+ surface,
264
+ app: app(target),
265
+ name: built.name,
266
+ surfaces: project.surfaces
267
+ });
268
+ const assets = requireAssets(built);
269
+ const synced = await step("assets", () => syncAssets({
270
+ api: client,
271
+ paywallId: binding.paywallId,
272
+ assets
273
+ }));
274
+ const pushed = await step("push", () => pushPaywallVersion(client, binding.paywallId, {
275
+ html: built.html,
276
+ surface: surface.id,
277
+ assets: synced.assets,
278
+ products: versionProducts(built.products, target.platform),
279
+ settings: built.settings
280
+ }));
281
+ await step("source", async () => {
282
+ if (!collected.ok) throw new Error(collected.reason);
283
+ return pushSource({
284
+ api: client,
285
+ paywallId: binding.paywallId,
286
+ applicationId: binding.applicationId,
287
+ version: pushed.version,
288
+ files: collected.files,
289
+ framework: frameworkVersion(project.root),
290
+ surface: surface.id,
291
+ kind: surface.kind,
292
+ snapshotId: built.snapshotId,
293
+ cli: VERSION,
294
+ external: [...built.externalSources ?? []].sort()
295
+ });
296
+ });
297
+ for (const source of built.externalSources ?? []) external.add(source);
298
+ if (action === "publish") await step("promote", () => promotePaywallVersion(client, binding.paywallId, { version: pushed.version }));
299
+ version = pushed.version;
300
+ }
301
+ warnNotPortable(external);
302
+ return {
303
+ ok: true,
304
+ version,
305
+ live: action === "publish"
306
+ };
307
+ } catch (error) {
308
+ return {
309
+ ok: false,
310
+ error: reason(error)
311
+ };
312
+ }
313
+ },
314
+ async status(surface) {
315
+ try {
316
+ const lock = readLock(project.superwallDir);
317
+ const bindings = (surface.kind === "paywall" ? lock.paywalls : lock.funnels)[surface.id];
318
+ const bound = bindings === void 0 ? void 0 : Object.values(bindings)[0];
319
+ if (!bound) return {};
320
+ const paywall = await (await ensureApi()).get(`/v2/paywalls/${encodeURIComponent(bound.paywallId)}`);
321
+ return {
322
+ paywallId: bound.paywallId,
323
+ liveUrl: paywall.paywall_url ?? void 0,
324
+ active: paywall.status === "active",
325
+ updatedAt: paywall.updated_at,
326
+ identifier: paywall.identifier
327
+ };
328
+ } catch (error) {
329
+ return { unreachable: reason(error) };
330
+ }
331
+ }
332
+ };
333
+ }
334
+
335
+ //#endregion
336
+ //#region src/commands/paywalls/dev.ts
337
+ const runDev = defineCommand({
338
+ name: "dev",
339
+ output: "human",
340
+ async run(context) {
341
+ const dirs = projectDirs(context);
342
+ const dir = projectDir(context);
343
+ const framework = await loadFramework(dir);
344
+ const projects = dirs.length === 1 ? [requireProject(framework.discoverProject(dirs[0]), dirs[0])] : dirs.map((one) => framework.discoverProject(one)).filter((one) => Boolean(one.marker));
345
+ if (projects.length === 0) throw new Error(`No superwall projects found in ${dirs.length} ${dirs.length === 1 ? "directory" : "directories"}.\nExpected a package.json in each (or in superwall/) that depends on superwall.`);
346
+ for (const project$1 of projects) {
347
+ writeProjectTypes(project$1, (await collectProjectDeclarations(framework, project$1.root)).products);
348
+ writeProjectScaffold({
349
+ root: project$1.root,
350
+ superwallDir: project$1.superwallDir,
351
+ frameworkVersion: frameworkVersion(dir)
352
+ });
353
+ }
354
+ const project = projects[0];
355
+ if (!project) throw new Error("No project directories given.");
356
+ const requestedPort = Number(context.argv.port);
357
+ const host = String(context.argv.host);
358
+ const runtimeUrl = process.env.SUPERWALL_RUNTIME_URL?.replace(/\/+$/, "");
359
+ const studio = createStudioActions(framework, project);
360
+ const server = await framework.startPreviewServer(projects.map((one) => one.root), {
361
+ port: requestedPort,
362
+ host,
363
+ platformStylesheet: runtimeUrl ? `${runtimeUrl}/live.css` : void 0,
364
+ studio
365
+ });
366
+ const url = server.resolvedUrls?.local[0] ?? `http://localhost:${requestedPort}/`;
367
+ const actualPort = Number(new URL(url).port);
368
+ ui.intro(`Superwall ${pc.dim(`v${VERSION}`)}`);
369
+ if (actualPort !== requestedPort) ui.warn(`Port ${requestedPort} was in use — moved to ${actualPort}.`);
370
+ const many = projects.length > 1;
371
+ const slug = (root) => root.split("/").filter(Boolean).at(-1) ?? "";
372
+ const rows = projects.flatMap((one) => {
373
+ const prefix = many ? `${slug(one.root)}/` : "";
374
+ return [...many ? [pc.bold(slug(one.root))] : [], ...one.surfaces.map((surface) => `${many ? " " : ""}${surface.kind}/${pc.bold(surface.id)} ` + pc.dim(`${url}${prefix}${surface.kind}/${surface.id}`))];
375
+ });
376
+ ui.step([`Studio ${pc.green(url)}`, ...rows].join("\n"));
377
+ const network = server.resolvedUrls?.network[0];
378
+ if (network) {
379
+ const deviceUrl = `${network}device`;
380
+ ui.step([
381
+ `Device ${pc.green(deviceUrl)}`,
382
+ pc.dim("Scan on a phone on the same wifi to preview on device:"),
383
+ "",
384
+ ...renderUnicodeCompact(deviceUrl).split("\n")
385
+ ].join("\n"));
386
+ }
387
+ const scheme = await studio.appScheme?.().catch(() => void 0);
388
+ if (scheme?.blocksLocalNetworking !== void 0) ui.warn(`This app can't reach the dev server: App Transport Security blocks plain http.
389
+ Add to ${scheme.blocksLocalNetworking}:\n NSAppTransportSecurity → NSAllowsLocalNetworking = YES
390
+ → NSAllowsArbitraryLoadsInWebContent = YES`);
391
+ for (const diagnostic of projects.flatMap((one) => one.diagnostics)) ui.warn(diagnostic);
392
+ if (projects.every((one) => one.surfaces.length === 0)) ui.warn(`Nothing to preview — ${LAYOUT_HINT}.`);
393
+ }
394
+ });
395
+
396
+ //#endregion
397
+ export { runDev };