@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,283 @@
1
+ import { i as track, n as maybeShowTelemetryNotice, o as isNonInteractive, y as API_HOST } from "./telemetry-CcfrtXdf.js";
2
+ import { a as refreshUpdateCheck, c as writeJson, i as maybeNotifyUpdate, s as createCommandOutput } from "./update-BiVeR024.js";
3
+ import { a as saveSession, i as loadSession, n as resolveAuthToken, o as NotLoggedInError } from "./token-DHRH8cxi.js";
4
+ import { t as selectRenderer } from "./ui-C4ncRJqd.js";
5
+ import pc from "picocolors";
6
+ import { resolve } from "node:path";
7
+
8
+ //#region src/core/api/client.ts
9
+ const BODY_SNIPPET = 200;
10
+ function parseErrorEnvelope(body) {
11
+ let parsed;
12
+ try {
13
+ parsed = JSON.parse(body);
14
+ } catch {
15
+ return;
16
+ }
17
+ if (typeof parsed !== "object" || parsed === null) return void 0;
18
+ const text = (key) => {
19
+ const value = Reflect.get(parsed, key);
20
+ return typeof value === "string" && value !== "" ? value : void 0;
21
+ };
22
+ const message = text("message");
23
+ if (message === void 0) return void 0;
24
+ return {
25
+ message,
26
+ detail: {
27
+ type: text("type"),
28
+ code: text("code"),
29
+ param: text("param"),
30
+ docUrl: text("doc_url"),
31
+ resourceType: text("resource_type"),
32
+ resourceId: text("resource_id")
33
+ }
34
+ };
35
+ }
36
+ var ApiError = class extends Error {
37
+ detail;
38
+ request;
39
+ envelope;
40
+ hint;
41
+ constructor(request, status, body) {
42
+ const envelope = body === void 0 ? void 0 : parseErrorEnvelope(body);
43
+ const snippet = body?.trim().slice(0, BODY_SNIPPET);
44
+ super(envelope?.message ?? (snippet ? `HTTP ${status} — ${snippet}` : `HTTP ${status}`));
45
+ this.status = status;
46
+ this.body = body;
47
+ this.detail = envelope?.detail ?? {};
48
+ this.request = request;
49
+ this.envelope = envelope !== void 0;
50
+ }
51
+ };
52
+ var ApiUnreachableError = class extends Error {
53
+ constructor(host, cause) {
54
+ const local = /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])/.test(host);
55
+ super(`Couldn't reach the Superwall API at ${host}.\n` + (local ? " That's a local address — start the API, or unset SUPERWALL_API_HOST to use production." : " Check your network or proxy, then try again."));
56
+ this.name = "ApiUnreachableError";
57
+ this.cause = cause;
58
+ }
59
+ };
60
+ var SuperwallApi = class SuperwallApi {
61
+ constructor(session) {
62
+ this.session = session;
63
+ }
64
+ static of(session) {
65
+ return new SuperwallApi(session);
66
+ }
67
+ static fromSession() {
68
+ const session = loadSession();
69
+ if (!session) throw new NotLoggedInError();
70
+ return new SuperwallApi(session);
71
+ }
72
+ get org() {
73
+ const override = process.env.SUPERWALL_ORG_ID;
74
+ return {
75
+ id: override ?? this.session.orgId,
76
+ name: override ? void 0 : this.session.orgName,
77
+ count: this.session.orgCount ?? 1
78
+ };
79
+ }
80
+ get userEmail() {
81
+ return this.session.userEmail;
82
+ }
83
+ setOrg(org) {
84
+ this.session = {
85
+ ...this.session,
86
+ orgId: org.id,
87
+ orgName: org.name
88
+ };
89
+ saveSession(this.session);
90
+ }
91
+ get host() {
92
+ return process.env.SUPERWALL_API_HOST ?? this.session.host ?? API_HOST;
93
+ }
94
+ base() {
95
+ return this.host;
96
+ }
97
+ async request(method, path, body) {
98
+ const { token, session } = await resolveAuthToken(this.session);
99
+ this.session = session;
100
+ const res = await this.fetch(`${this.base()}${path}`, {
101
+ method,
102
+ headers: {
103
+ authorization: `Bearer ${token}`,
104
+ accept: "application/json",
105
+ ...body ? { "content-type": "application/json" } : {}
106
+ },
107
+ ...body ? { body: JSON.stringify(body) } : {}
108
+ });
109
+ if (!res.ok) {
110
+ const text = await res.text().catch(() => "");
111
+ throw new ApiError(`${method} ${path}`, res.status, text);
112
+ }
113
+ if (res.status === 204) return void 0;
114
+ return await res.json();
115
+ }
116
+ async fetch(url, init) {
117
+ try {
118
+ return await fetch(url, init);
119
+ } catch (error) {
120
+ throw new ApiUnreachableError(this.base(), error);
121
+ }
122
+ }
123
+ get(path) {
124
+ return this.request("GET", path);
125
+ }
126
+ post(path, body) {
127
+ return this.request("POST", path, body);
128
+ }
129
+ patch(path, body) {
130
+ return this.request("PATCH", path, body);
131
+ }
132
+ del(path) {
133
+ return this.request("DELETE", path);
134
+ }
135
+ async postText(path, body) {
136
+ const { token, session } = await resolveAuthToken(this.session);
137
+ this.session = session;
138
+ const res = await this.fetch(`${this.base()}${path}`, {
139
+ method: "POST",
140
+ headers: {
141
+ authorization: `Bearer ${token}`,
142
+ accept: "text/plain",
143
+ "content-type": "text/plain; charset=utf-8"
144
+ },
145
+ body
146
+ });
147
+ if (!res.ok) {
148
+ const text = await res.text().catch(() => "");
149
+ throw new ApiError(`POST ${path}`, res.status, text);
150
+ }
151
+ return res.text();
152
+ }
153
+ async list(path) {
154
+ const out = [];
155
+ let after;
156
+ for (let i = 0; i < 50; i++) {
157
+ const url = `${path}${path.includes("?") ? "&" : "?"}limit=100${after ? `&starting_after=${after}` : ""}`;
158
+ const page = await this.get(url);
159
+ out.push(...page.data);
160
+ if (!page.has_more || page.data.length === 0) break;
161
+ const last = page.data[page.data.length - 1];
162
+ if (last?.id == null) break;
163
+ after = String(last.id);
164
+ }
165
+ return out;
166
+ }
167
+ };
168
+
169
+ //#endregion
170
+ //#region src/command.ts
171
+ function defineCommand(definition) {
172
+ const command = (argv) => executeCommand(definition, argv);
173
+ command.definition = definition;
174
+ return command;
175
+ }
176
+ async function executeCommand(definition, argv, runtime = {}) {
177
+ const json = Boolean(argv.json);
178
+ const environmentNonInteractive = runtime.nonInteractive ?? isNonInteractive();
179
+ const explicitNonInteractive = argv.interactive === false;
180
+ const outputMode = json ? "json" : environmentNonInteractive ? "text" : "rich";
181
+ const interactive = definition.interaction !== "none" && !json && !explicitNonInteractive && !environmentNonInteractive;
182
+ const installDir = resolve(argv.installDir ?? process.cwd());
183
+ const ui = runtime.renderer?.(outputMode) ?? selectRenderer({ mode: outputMode });
184
+ const stdout = runtime.stdout ?? process.stdout;
185
+ const output = createCommandOutput(outputMode, ui, { stdout });
186
+ if (json && definition.output !== "json" && definition.output !== "both") {
187
+ writeJson(stdout, { error: {
188
+ code: "json_not_supported",
189
+ message: `${definition.name} does not support --json.`
190
+ } });
191
+ process.exitCode = 1;
192
+ return;
193
+ }
194
+ const tracked = definition.telemetry === "workflow" && !argv.dryRun;
195
+ const startedAt = Date.now();
196
+ ui.start();
197
+ if (tracked) {
198
+ if (outputMode === "rich") maybeShowTelemetryNotice(ui);
199
+ track("workflow started", { workflow: definition.name });
200
+ }
201
+ try {
202
+ const api = resolveApi(definition.auth ?? "none", runtime.api ?? SuperwallApi.fromSession);
203
+ const context = {
204
+ argv,
205
+ ui,
206
+ output,
207
+ outputMode,
208
+ interactive,
209
+ installDir,
210
+ json,
211
+ dryRun: Boolean(argv.dryRun),
212
+ ...api ? { api } : {}
213
+ };
214
+ await definition.run(context);
215
+ if (tracked) track("workflow finished", {
216
+ workflow: definition.name,
217
+ status: "success",
218
+ duration_ms: Date.now() - startedAt
219
+ });
220
+ } catch (error) {
221
+ reportError(ui, outputMode, stdout, error);
222
+ process.exitCode = 1;
223
+ if (tracked) track("workflow finished", {
224
+ workflow: definition.name,
225
+ status: "error",
226
+ error_code: normalizeError(error).code,
227
+ duration_ms: Date.now() - startedAt
228
+ });
229
+ } finally {
230
+ if (outputMode !== "json") refreshUpdateCheck();
231
+ if (outputMode === "rich" && runtime.waitForPaint !== false) await new Promise((done) => setTimeout(done, 50));
232
+ ui.stop();
233
+ if (outputMode !== "json" && definition.name !== "upgrade") maybeNotifyUpdate(stdout);
234
+ }
235
+ }
236
+ function resolveApi(policy, factory) {
237
+ if (policy === "required") return factory();
238
+ if (policy === "optional") try {
239
+ return factory();
240
+ } catch (error) {
241
+ if (error instanceof NotLoggedInError) return void 0;
242
+ throw error;
243
+ }
244
+ }
245
+ function reportError(ui, mode, stdout, error) {
246
+ const { code, message, status } = normalizeError(error);
247
+ if (mode === "json") {
248
+ writeJson(stdout, { error: {
249
+ code,
250
+ message,
251
+ ...status === void 0 ? {} : { status }
252
+ } });
253
+ return;
254
+ }
255
+ ui.error([message, ...errorAside(error)].join("\n"));
256
+ }
257
+ function errorAside(error) {
258
+ const aside = [];
259
+ if (error instanceof ApiError) {
260
+ if (error.hint) aside.push(error.hint);
261
+ if (error.detail.docUrl) aside.push(error.detail.docUrl);
262
+ if (!error.envelope) aside.push(error.request);
263
+ }
264
+ return aside.map((line) => pc.dim(line));
265
+ }
266
+ function normalizeError(error) {
267
+ if (error instanceof NotLoggedInError) return {
268
+ code: "not_logged_in",
269
+ message: "You aren't logged in. Run `superwall login` first."
270
+ };
271
+ if (error instanceof ApiError) return {
272
+ code: "api_error",
273
+ message: error.message,
274
+ status: error.status
275
+ };
276
+ return {
277
+ code: "command_error",
278
+ message: error instanceof Error ? error.message : String(error)
279
+ };
280
+ }
281
+
282
+ //#endregion
283
+ export { ApiError as n, SuperwallApi as r, defineCommand as t };