@superwall/cli 1.6.1 → 1.7.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 (65) hide show
  1. package/README.md +116 -3
  2. package/dist/{actions-BdZ-7BJd.js → actions-B7ym3oVS.js} +2 -2
  3. package/dist/{api-FjrCPu6r.js → api-CZzirVMj.js} +8 -8
  4. package/dist/{app-YeJj35Ia.js → app-DH6U8yuI.js} +11 -10
  5. package/dist/{asa-4nk7HHy8.js → asa-C-sQzPPn.js} +10 -10
  6. package/dist/{asc-2TZOQuK1.js → asc-1ZBJ6DwS.js} +282 -43
  7. package/dist/asc-Bf7zBbyS.js +65 -0
  8. package/dist/{asc-products-1e1DoGeL.js → asc-products-9JXtDxI4.js} +2 -35
  9. package/dist/{auth-QUYfKdwk.js → auth-YRhlV3DE.js} +11 -10
  10. package/dist/auth.js +2 -2
  11. package/dist/{billing-BK7bpv1t.js → billing-CCYHdApx.js} +1 -1
  12. package/dist/{bind-Ch4VR2EY.js → bind-YrJvuRF9.js} +3 -3
  13. package/dist/build-DLoCW5Ri.js +87 -0
  14. package/dist/bundle-id-CKxl_026.js +121 -0
  15. package/dist/{command-BJ_6850A.js → command-CMIz81Da.js} +5 -5
  16. package/dist/{create-vSQxQlEP.js → create-pkANt1Gs.js} +22 -21
  17. package/dist/dev-DZy6pOnB.js +22 -0
  18. package/dist/{dev-DEss5dwo.js → dev-DmB3XqaJ.js} +16 -8
  19. package/dist/{doctor-BYTfekBr.js → doctor-H-hf-Yww.js} +10 -10
  20. package/dist/{drivers-DGml3OlF.js → drivers-Qx9LxmRN.js} +2 -2
  21. package/dist/entry.js +453 -43
  22. package/dist/{existing-DgSo639M.js → existing-AVEfZu2A.js} +2 -2
  23. package/dist/feedback-CKf-rpBW.js +152 -0
  24. package/dist/{hosted-DqGp6oV2.js → hosted-CXe9TrWx.js} +2 -2
  25. package/dist/{integrate-Cl9eKHoF.js → integrate-brmhPG-S.js} +23 -22
  26. package/dist/{login-DS3MPeW2.js → login-Do4wFuLv.js} +31 -16
  27. package/dist/{migrate-WiTO71PE.js → migrate-C9ERDR6y.js} +24 -23
  28. package/dist/notification-url-DuKF2659.js +1273 -0
  29. package/dist/{open-studio-CbMUL5Va.js → open-studio-DOw-6ydc.js} +17 -14
  30. package/dist/{org-CV8c849b.js → org-sj7uyvp-.js} +2 -2
  31. package/dist/{output-XKuoEEjP.js → output-C4o2gJ1K.js} +12 -2
  32. package/dist/{pipeline-J9-nENTS.js → pipeline-BqzqZhX1.js} +10 -495
  33. package/dist/{print-skill-BOGm5Szi.js → print-skill-ZojRSybs.js} +7 -7
  34. package/dist/{promote-Ci085QxU.js → promote-BG8X4Nv_.js} +17 -16
  35. package/dist/publish-sxLh-G4G.js +35 -0
  36. package/dist/push-bQ6Vxtg8.js +35 -0
  37. package/dist/{query-BZStoGLM.js → query-_FbybaH-.js} +9 -9
  38. package/dist/{resource-ClLHSXi6.js → resource-CGIwSd29.js} +17 -177
  39. package/dist/revenue-provider-ebsRINY8.js +100 -0
  40. package/dist/{run-CiaWn78U.js → run-DsVZ5snL.js} +2 -2
  41. package/dist/{scan-DEgX5HxV.js → scan-zKsddO72.js} +1 -1
  42. package/dist/scope-BvzD-kO4.js +223 -0
  43. package/dist/selection-CxZoX4NT.js +496 -0
  44. package/dist/setup-Bxj22rYi.js +189 -0
  45. package/dist/skills/superwall-framework/SKILL.md +109 -36
  46. package/dist/skills/superwall-framework/references/cli.md +45 -5
  47. package/dist/skills/superwall-framework/references/mobile-design.md +60 -181
  48. package/dist/{skills-DsBAVRTE.js → skills-DPzlnfCK.js} +78 -9
  49. package/dist/{skills-DjPCmUMU.js → skills-D_R-lEsK.js} +8 -8
  50. package/dist/{spinner-DFctF_Jw.js → spinner-TWa0hia6.js} +1 -1
  51. package/dist/{telemetry-EzV7cA7s.js → telemetry-DeA1mvnT.js} +1 -1
  52. package/dist/{token-r5g876aI.js → token-C0it-Xh7.js} +1 -1
  53. package/dist/{ui-4gLyfrgl.js → ui-Dy0b-9L8.js} +4 -3
  54. package/dist/{update-Cz3Q3MFj.js → update-B2fWIc4q.js} +2 -2
  55. package/dist/{upgrade-BA_4sdnh.js → upgrade-BmzkTKrh.js} +6 -6
  56. package/package.json +2 -2
  57. package/dist/dev-B9qmPH1W.js +0 -21
  58. package/dist/feedback-4LsBpZZx.js +0 -73
  59. package/dist/publish--TV-j8Zd.js +0 -34
  60. package/dist/push-CpGetsJF.js +0 -34
  61. package/dist/skills/superwall-framework/references/responsive.md +0 -162
  62. /package/dist/{api-output-CEhN-U_N.js → api-output-aJNw7Syy.js} +0 -0
  63. /package/dist/{params-BxgTuCzr.js → params-l3CrvRtR.js} +0 -0
  64. /package/dist/{reports-C0xHCLnt.js → reports-CfJqoava.js} +0 -0
  65. /package/dist/{storekit-Dlpbq5Wv.js → storekit-Cj9Cpjcz.js} +0 -0
@@ -1,13 +1,13 @@
1
- import "./output-XKuoEEjP.js";
2
- import "./telemetry-EzV7cA7s.js";
3
- import "./update-Cz3Q3MFj.js";
4
- import "./token-r5g876aI.js";
5
- import { t as defineCommand } from "./command-BJ_6850A.js";
6
- import "./ui-4gLyfrgl.js";
7
- import "./spinner-DFctF_Jw.js";
1
+ import "./output-C4o2gJ1K.js";
2
+ import "./telemetry-DeA1mvnT.js";
3
+ import "./update-B2fWIc4q.js";
4
+ import "./token-C0it-Xh7.js";
5
+ import { t as defineCommand } from "./command-CMIz81Da.js";
6
+ import "./ui-Dy0b-9L8.js";
7
+ import "./spinner-TWa0hia6.js";
8
8
  import "./resources-Bf9O1JNM.js";
9
- import { t as requireOrg } from "./org-CV8c849b.js";
10
- import { t as apiCall } from "./api-output-CEhN-U_N.js";
9
+ import { t as requireOrg } from "./org-sj7uyvp-.js";
10
+ import { t as apiCall } from "./api-output-aJNw7Syy.js";
11
11
  import { readFileSync } from "node:fs";
12
12
 
13
13
  //#region src/commands/platform/query.ts
@@ -1,182 +1,21 @@
1
- import { r as formatJson, t as blocks } from "./output-XKuoEEjP.js";
2
- import { f as setDefaultApp, o as getDefaultApp } from "./telemetry-EzV7cA7s.js";
3
- import "./update-Cz3Q3MFj.js";
4
- import "./token-r5g876aI.js";
5
- import { r as ApiError, t as defineCommand } from "./command-BJ_6850A.js";
6
- import "./ui-4gLyfrgl.js";
7
- import { t as scanProject } from "./scan-DEgX5HxV.js";
8
- import { t as detectExisting } from "./existing-DgSo639M.js";
9
- import "./spinner-DFctF_Jw.js";
10
- import { E as titleCase, T as rowName, b as platformLabel, g as listResource, h as listProjects, i as createEntitlement, l as getPaywallApplicationId, m as listOrganizations, n as createApplication, o as createProduct, r as createCampaign, s as createProject, t as addPlacement, u as isAppScoped } from "./resources-Bf9O1JNM.js";
11
- import { t as requireOrg } from "./org-CV8c849b.js";
12
- import { t as platformForIntegration } from "./bind-Ch4VR2EY.js";
13
- import { t as apiCall } from "./api-output-CEhN-U_N.js";
14
- import { t as generateStoreKit } from "./storekit-Dlpbq5Wv.js";
15
- import * as path from "node:path";
16
- import * as fs from "node:fs";
1
+ import { r as formatJson, t as blocks } from "./output-C4o2gJ1K.js";
2
+ import { f as setDefaultApp, o as getDefaultApp } from "./telemetry-DeA1mvnT.js";
3
+ import "./update-B2fWIc4q.js";
4
+ import "./token-C0it-Xh7.js";
5
+ import { r as ApiError, t as defineCommand } from "./command-CMIz81Da.js";
6
+ import "./ui-Dy0b-9L8.js";
7
+ import { t as scanProject } from "./scan-zKsddO72.js";
8
+ import "./existing-AVEfZu2A.js";
9
+ import "./spinner-TWa0hia6.js";
10
+ import { E as titleCase, T as rowName, b as platformLabel, g as listResource, h as listProjects, i as createEntitlement, m as listOrganizations, n as createApplication, o as createProduct, r as createCampaign, s as createProject, t as addPlacement, u as isAppScoped } from "./resources-Bf9O1JNM.js";
11
+ import { t as requireOrg } from "./org-sj7uyvp-.js";
12
+ import { t as platformForIntegration } from "./bind-YrJvuRF9.js";
13
+ import { t as apiCall } from "./api-output-aJNw7Syy.js";
14
+ import { n as pickProject, r as pickScope, t as chooseApp } from "./scope-BvzD-kO4.js";
15
+ import { t as runBundleId } from "./bundle-id-CKxl_026.js";
16
+ import { t as generateStoreKit } from "./storekit-Cj9Cpjcz.js";
17
17
  import { writeFileSync } from "node:fs";
18
18
 
19
- //#region src/commands/resource/scope.ts
20
- async function detectLocal(installDir) {
21
- const detected = (await scanProject(installDir).catch(() => null))?.apps[0];
22
- if (!detected) return {};
23
- return {
24
- apiKey: detectExisting(detected).apiKey,
25
- name: detected.name
26
- };
27
- }
28
- function moveFirst(items, match) {
29
- const idx = items.findIndex(match);
30
- if (idx <= 0) return items;
31
- return [
32
- items[idx],
33
- ...items.slice(0, idx),
34
- ...items.slice(idx + 1)
35
- ];
36
- }
37
- function matchProject(projects, local) {
38
- if (local.apiKey) {
39
- const p = projects.find((project) => (project.applications ?? []).some((a) => a.public_api_key === local.apiKey));
40
- if (p) return {
41
- project: p,
42
- exact: true
43
- };
44
- }
45
- if (local.name) {
46
- const p = projects.find((project) => project.name === local.name || (project.applications ?? []).some((a) => a.name === local.name));
47
- if (p) return {
48
- project: p,
49
- exact: false
50
- };
51
- }
52
- return { exact: false };
53
- }
54
- function matchApp(apps, local) {
55
- if (local.apiKey) {
56
- const a = apps.find((app) => app.public_api_key === local.apiKey);
57
- if (a) return a;
58
- }
59
- if (local.name) return apps.find((app) => app.name === local.name);
60
- }
61
- function lockBoundPaywallId(installDir) {
62
- for (const file of [path.join(installDir, "superwall.lock"), path.join(installDir, "superwall", "superwall.lock")]) try {
63
- const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
64
- for (const entry of Object.values({
65
- ...parsed.paywalls,
66
- ...parsed.funnels
67
- })) {
68
- if (typeof entry?.paywallId === "string") return entry.paywallId;
69
- for (const binding of Object.values(entry ?? {})) {
70
- const paywallId = binding?.paywallId;
71
- if (typeof paywallId === "string") return paywallId;
72
- }
73
- }
74
- } catch {
75
- continue;
76
- }
77
- }
78
- async function lockBoundScope(context, api, projects) {
79
- if (context.argv.project || context.argv.app) return void 0;
80
- const paywallId = lockBoundPaywallId(context.installDir);
81
- if (!paywallId) return void 0;
82
- const applicationId = await getPaywallApplicationId(api, paywallId).catch(() => void 0);
83
- if (!applicationId) return void 0;
84
- const project = projects.find((candidate) => (candidate.applications ?? []).some((app$1) => String(app$1.id) === applicationId));
85
- const app = project?.applications?.find((candidate) => String(candidate.id) === applicationId);
86
- if (!project || !app) return void 0;
87
- context.ui.info(`Using \`${app.name ?? applicationId}\` - bound in superwall.lock.`);
88
- return {
89
- project,
90
- app
91
- };
92
- }
93
- async function pickScope(context, api, appScoped) {
94
- const projects = await apiCall(context, "Loading projects", () => listProjects(api));
95
- const bound = await lockBoundScope(context, api, projects);
96
- if (bound) return {
97
- projectId: String(bound.project.id),
98
- applicationId: appScoped ? String(bound.app.id) : void 0,
99
- projectName: bound.project.name,
100
- appName: appScoped ? bound.app.name : void 0,
101
- appPlatform: appScoped ? bound.app.platform : void 0,
102
- projectCount: projects.length,
103
- appCount: bound.project.applications?.length ?? 0
104
- };
105
- const project = await pickProject(context, projects);
106
- const projectId = String(project.id);
107
- const apps = project.applications ?? [];
108
- let app;
109
- if (appScoped) {
110
- const appFlag = context.argv.app;
111
- const remembered = apps.find((candidate) => String(candidate.id) === getDefaultApp(projectId));
112
- if (appFlag) {
113
- app = apps.find((candidate) => String(candidate.id) === appFlag || candidate.name === appFlag);
114
- if (!app) throw new Error(`No app ${appFlag} in ${project.name ?? projectId}.`);
115
- setDefaultApp(projectId, String(app.id));
116
- } else if (apps.length <= 1) app = apps[0];
117
- else if (!context.interactive) throw new Error(`Multiple apps found in ${project.name ?? projectId}. Pass --app <id>.`);
118
- else {
119
- app = await chooseApp(context, apps, remembered ?? apps[0]);
120
- setDefaultApp(projectId, String(app.id));
121
- }
122
- }
123
- return {
124
- projectId,
125
- applicationId: app ? String(app.id) : void 0,
126
- projectName: project.name,
127
- appName: app?.name,
128
- appPlatform: app?.platform,
129
- projectCount: projects.length,
130
- appCount: apps.length
131
- };
132
- }
133
- async function pickProject(context, projects) {
134
- const projectFlag = context.argv.project;
135
- if (projectFlag) {
136
- const p = projects.find((c) => String(c.id) === projectFlag);
137
- if (!p) throw new Error(`No project ${projectFlag} in this organization.`);
138
- return p;
139
- }
140
- if (projects.length === 0) throw new Error("No project found in this organization.");
141
- if (projects.length === 1) return projects[0];
142
- const { project: preferred, exact } = matchProject(projects, await detectLocal(context.installDir));
143
- if (exact && preferred) {
144
- context.ui.info(`Using \`${preferred.name}\` - detected in this directory.`);
145
- return preferred;
146
- }
147
- if (!context.interactive) throw new Error("Multiple projects found. Pass --project <id>.");
148
- return chooseProject(context, projects, preferred);
149
- }
150
- async function chooseProject(context, projects, preferred) {
151
- const ordered = preferred ? moveFirst(projects, (p) => String(p.id) === String(preferred.id)) : projects;
152
- const selection = await context.ui.select({
153
- message: "Which project?",
154
- options: ordered.map((project) => ({
155
- value: String(project.id),
156
- label: project.name ?? String(project.id)
157
- })),
158
- initialValue: preferred ? String(preferred.id) : void 0
159
- });
160
- if (selection === null) throw new Error("Cancelled.");
161
- return projects.find((project) => String(project.id) === selection);
162
- }
163
- async function chooseApp(context, apps, defaultApp) {
164
- const top = matchApp(apps, await detectLocal(context.installDir)) ?? defaultApp;
165
- const ordered = moveFirst(apps, (app) => String(app.id) === String(top.id));
166
- const selection = await context.ui.select({
167
- message: "Which app?",
168
- options: ordered.map((app) => ({
169
- value: String(app.id),
170
- label: app.name ?? String(app.id),
171
- hint: platformLabel(app.platform)
172
- })),
173
- initialValue: String(top.id)
174
- });
175
- if (selection === null) throw new Error("Cancelled.");
176
- return apps.find((app) => String(app.id) === selection) ?? top;
177
- }
178
-
179
- //#endregion
180
19
  //#region src/commands/resource/actions.ts
181
20
  async function addCampaignPlacement(context, api) {
182
21
  const { ui, json, dryRun, argv } = context;
@@ -471,6 +310,7 @@ function runResource(resource) {
471
310
  if (action === "list") return list(context, context.api, resource);
472
311
  if (action === "create") return create(context, context.api, resource);
473
312
  if (action === "use" && resource === "apps") return useApp(context, context.api);
313
+ if (action === "bundle-id" && resource === "apps") return runBundleId(context);
474
314
  if (action === "use" && resource === "orgs") return useOrg(context, context.api);
475
315
  if (action === "placement" && resource === "campaigns") return addCampaignPlacement(context, context.api);
476
316
  if (action === "storekit" && resource === "products") return writeStoreKit(context, context.api);
@@ -0,0 +1,100 @@
1
+ import "./output-C4o2gJ1K.js";
2
+ import "./telemetry-DeA1mvnT.js";
3
+ import "./update-B2fWIc4q.js";
4
+ import "./token-C0it-Xh7.js";
5
+ import { t as defineCommand } from "./command-CMIz81Da.js";
6
+ import "./ui-Dy0b-9L8.js";
7
+ import "./scan-zKsddO72.js";
8
+ import "./existing-AVEfZu2A.js";
9
+ import "./spinner-TWa0hia6.js";
10
+ import "./resources-Bf9O1JNM.js";
11
+ import { t as requireOrg } from "./org-sj7uyvp-.js";
12
+ import { n as emitJson, t as apiCall } from "./api-output-aJNw7Syy.js";
13
+ import { c as getIntegrations, p as setRevenueProvider, r as pickScope } from "./scope-BvzD-kO4.js";
14
+
15
+ //#region src/commands/platform/revenue-provider.ts
16
+ const PROVIDERS = ["open_revenue", "revenue_cat"];
17
+ const LABEL = {
18
+ open_revenue: "the app's store, sent straight to Superwall",
19
+ revenue_cat: "RevenueCat"
20
+ };
21
+ function sent(overview, provider) {
22
+ const events = overview.revenue_provider_events;
23
+ if (!events) return void 0;
24
+ const count = events[provider].events;
25
+ return `${provider} sent ${count} event${count === 1 ? "" : "s"} in the last ${events.window_days} days`;
26
+ }
27
+ const runRevenueProvider = defineCommand({
28
+ name: "revenue-provider",
29
+ auth: "required",
30
+ output: "both",
31
+ async run(ctx) {
32
+ const { api } = ctx;
33
+ const action = ctx.argv.action ?? "get";
34
+ if (action !== "get" && action !== "set") throw new Error(`Unknown "revenue-provider ${action}". Use get | set.`);
35
+ const wanted = PROVIDERS.find((provider) => provider === ctx.argv.value);
36
+ if (action === "set" && !wanted) throw new Error("Usage: superwall revenue-provider set <open_revenue | revenue_cat> --app <id>");
37
+ await requireOrg(api, ctx.interactive);
38
+ const scope = await pickScope(ctx, api, true);
39
+ const applicationId = scope.applicationId;
40
+ if (!applicationId) throw new Error("No app found in this project. Pass --app <id>.");
41
+ const name = scope.appName ?? applicationId;
42
+ const overview = await apiCall(ctx, "Loading revenue tracking", () => getIntegrations(api, applicationId));
43
+ const current = overview.revenue_provider;
44
+ const events = overview.revenue_provider_events ?? null;
45
+ if (action === "get" || !wanted) {
46
+ if (ctx.json) return emitJson(ctx, {
47
+ application_id: applicationId,
48
+ revenue_provider: current,
49
+ events
50
+ });
51
+ ctx.ui.step(current ? `\`${name}\` counts revenue from ${current} (${LABEL[current]})` : `\`${name}\` has no revenue provider chosen, so revenue from every source is counted`);
52
+ for (const provider of PROVIDERS) {
53
+ const line = sent(overview, provider);
54
+ if (line) ctx.ui.info(line);
55
+ }
56
+ return;
57
+ }
58
+ if (current === wanted) {
59
+ if (ctx.json) return emitJson(ctx, {
60
+ application_id: applicationId,
61
+ revenue_provider: current,
62
+ changed: false
63
+ });
64
+ ctx.ui.success(`\`${name}\` already counts revenue from ${wanted}.`);
65
+ return;
66
+ }
67
+ const consequence = [
68
+ `Every revenue figure in the dashboard for ${name} will count only events from ${wanted} (${LABEL[wanted]}).`,
69
+ current ? `Events from ${current} keep arriving and being stored, but stop being counted.` : "Events from the other source keep arriving and being stored, but stop being counted.",
70
+ ...PROVIDERS.map((provider) => sent(overview, provider)).filter((line) => line !== void 0).map((line) => `${line}.`)
71
+ ].join("\n");
72
+ if (ctx.dryRun) {
73
+ if (ctx.json) return emitJson(ctx, {
74
+ dryRun: true,
75
+ application_id: applicationId,
76
+ from: current,
77
+ to: wanted,
78
+ events
79
+ });
80
+ ctx.ui.info(`[dry-run] would change the revenue provider to ${wanted}.\n${consequence}`);
81
+ return;
82
+ }
83
+ if (ctx.argv.yes !== true) {
84
+ if (!ctx.interactive) throw new Error(`${consequence}\nNothing was changed. This is a person's decision: once they agree, run it again with --yes.`);
85
+ ctx.ui.warn(consequence);
86
+ if (!await ctx.ui.confirm({ message: `Count revenue from ${wanted}?` })) return void ctx.ui.warn("Cancelled. Nothing was changed.");
87
+ }
88
+ const saved = await apiCall(ctx, "Saving the revenue provider", () => setRevenueProvider(api, applicationId, wanted));
89
+ if (ctx.json) return emitJson(ctx, {
90
+ application_id: applicationId,
91
+ revenue_provider: saved,
92
+ changed: true,
93
+ previous: current
94
+ });
95
+ ctx.ui.success(`\`${name}\` now counts revenue from ${saved}.`);
96
+ }
97
+ });
98
+
99
+ //#endregion
100
+ export { runRevenueProvider };
@@ -1,5 +1,5 @@
1
- import { f as DASHBOARD_URL } from "./output-XKuoEEjP.js";
2
- import { s as packagedDir } from "./skills-DsBAVRTE.js";
1
+ import { f as DASHBOARD_URL } from "./output-C4o2gJ1K.js";
2
+ import { s as packagedDir } from "./skills-DPzlnfCK.js";
3
3
  import { join } from "node:path";
4
4
  import { readFileSync } from "node:fs";
5
5
  import { spawn } from "node:child_process";
@@ -1,4 +1,4 @@
1
- import { m as Integration } from "./output-XKuoEEjP.js";
1
+ import { g as Integration } from "./output-C4o2gJ1K.js";
2
2
  import { basename, dirname, join, relative, sep } from "node:path";
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import fg from "fast-glob";
@@ -0,0 +1,223 @@
1
+ import { f as setDefaultApp, o as getDefaultApp } from "./telemetry-DeA1mvnT.js";
2
+ import { r as ApiError } from "./command-CMIz81Da.js";
3
+ import { t as scanProject } from "./scan-zKsddO72.js";
4
+ import { t as detectExisting } from "./existing-AVEfZu2A.js";
5
+ import { b as platformLabel, h as listProjects, l as getPaywallApplicationId } from "./resources-Bf9O1JNM.js";
6
+ import { t as apiCall } from "./api-output-aJNw7Syy.js";
7
+ import * as path from "node:path";
8
+ import * as fs from "node:fs";
9
+
10
+ //#region src/core/api/integrations.ts
11
+ var RefusedByApi = class extends Error {};
12
+ const integrations = (applicationId) => `/internal/v2/applications/${applicationId}/integrations`;
13
+ async function supported(what, api, work) {
14
+ try {
15
+ return await work();
16
+ } catch (error) {
17
+ if (error instanceof ApiError && error.status === 404 && !error.envelope) throw new RefusedByApi(`The Superwall API at ${api.host} can't ${what} yet. Nothing was changed.`);
18
+ throw error;
19
+ }
20
+ }
21
+ function getIntegrations(api, applicationId) {
22
+ return api.get(`${integrations(applicationId)}/overview`);
23
+ }
24
+ async function setRevenueProvider(api, applicationId, provider) {
25
+ return (await api.patch(`${integrations(applicationId)}/revenue-provider`, { revenue_provider: provider })).revenue_provider;
26
+ }
27
+ function listKeySources(api, applicationId) {
28
+ return supported("list the keys on your other apps", api, () => api.get(`${integrations(applicationId)}/app-store-keys/copy-sources`));
29
+ }
30
+ function copyAppKey(api, applicationId, input) {
31
+ return supported("copy a key from another app", api, () => api.post(`${integrations(applicationId)}/app-store-keys/copy`, {
32
+ kind: input.kind,
33
+ source_application_id: input.from,
34
+ ...input.confirmed ? { confirmed: true } : {}
35
+ }));
36
+ }
37
+ function importAppKey(api, applicationId, kind) {
38
+ return supported("import a key your organization already has", api, () => api.post(`${integrations(applicationId)}/app-store-keys/import`, { kind }));
39
+ }
40
+ async function removeAppKey(api, applicationId, kind) {
41
+ await supported("remove an app's key", api, () => api.del(`${integrations(applicationId)}/app-store-keys/${kind}`));
42
+ }
43
+ const serverNotificationsPath = (app) => `/v2/projects/${app.projectId}/applications/${app.applicationId}/integrations/app-store-connect/notification-url/apple`;
44
+ function checkServerNotifications(api, app) {
45
+ return supported("read Apple's server notification URLs", api, () => api.get(serverNotificationsPath(app)));
46
+ }
47
+ function setServerNotifications(api, app, options) {
48
+ return supported("set Apple's server notification URLs", api, () => api.put(serverNotificationsPath(app), options.setRevenueProvider ? { set_revenue_provider: true } : {}));
49
+ }
50
+ function getBundleIdSuggestions(api, applicationId) {
51
+ return supported("suggest a bundle ID", api, () => api.get(`/internal/v2/applications/${applicationId}/bundle-id-suggestions`));
52
+ }
53
+ function saveBundleId(api, applicationId, input) {
54
+ return supported("save a bundle ID", api, () => api.post(`/internal/v2/applications/${applicationId}/bundle-id`, {
55
+ bundle_id: input.bundleId,
56
+ ...input.appStoreId ? { app_store_id: input.appStoreId } : {},
57
+ ...input.replace ? { replace: true } : {}
58
+ }));
59
+ }
60
+
61
+ //#endregion
62
+ //#region src/commands/resource/scope.ts
63
+ async function detectLocal(installDir) {
64
+ const detected = (await scanProject(installDir).catch(() => null))?.apps[0];
65
+ if (!detected) return {};
66
+ return {
67
+ apiKey: detectExisting(detected).apiKey,
68
+ name: detected.name
69
+ };
70
+ }
71
+ function moveFirst(items, match) {
72
+ const idx = items.findIndex(match);
73
+ if (idx <= 0) return items;
74
+ return [
75
+ items[idx],
76
+ ...items.slice(0, idx),
77
+ ...items.slice(idx + 1)
78
+ ];
79
+ }
80
+ function matchProject(projects, local) {
81
+ if (local.apiKey) {
82
+ const p = projects.find((project) => (project.applications ?? []).some((a) => a.public_api_key === local.apiKey));
83
+ if (p) return {
84
+ project: p,
85
+ exact: true
86
+ };
87
+ }
88
+ if (local.name) {
89
+ const p = projects.find((project) => project.name === local.name || (project.applications ?? []).some((a) => a.name === local.name));
90
+ if (p) return {
91
+ project: p,
92
+ exact: false
93
+ };
94
+ }
95
+ return { exact: false };
96
+ }
97
+ function matchApp(apps, local) {
98
+ if (local.apiKey) {
99
+ const a = apps.find((app) => app.public_api_key === local.apiKey);
100
+ if (a) return a;
101
+ }
102
+ if (local.name) return apps.find((app) => app.name === local.name);
103
+ }
104
+ function lockBoundPaywallId(installDir) {
105
+ for (const file of [path.join(installDir, "superwall.lock"), path.join(installDir, "superwall", "superwall.lock")]) try {
106
+ const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
107
+ for (const entry of Object.values({
108
+ ...parsed.paywalls,
109
+ ...parsed.funnels
110
+ })) {
111
+ if (typeof entry?.paywallId === "string") return entry.paywallId;
112
+ for (const binding of Object.values(entry ?? {})) {
113
+ const paywallId = binding?.paywallId;
114
+ if (typeof paywallId === "string") return paywallId;
115
+ }
116
+ }
117
+ } catch {
118
+ continue;
119
+ }
120
+ }
121
+ async function lockBoundScope(context, api, projects) {
122
+ if (context.argv.project || context.argv.app) return void 0;
123
+ const paywallId = lockBoundPaywallId(context.installDir);
124
+ if (!paywallId) return void 0;
125
+ const applicationId = await getPaywallApplicationId(api, paywallId).catch(() => void 0);
126
+ if (!applicationId) return void 0;
127
+ const project = projects.find((candidate) => (candidate.applications ?? []).some((app$1) => String(app$1.id) === applicationId));
128
+ const app = project?.applications?.find((candidate) => String(candidate.id) === applicationId);
129
+ if (!project || !app) return void 0;
130
+ context.ui.info(`Using \`${app.name ?? applicationId}\` - bound in superwall.lock.`);
131
+ return {
132
+ project,
133
+ app
134
+ };
135
+ }
136
+ async function pickScope(context, api, appScoped) {
137
+ const projects = await apiCall(context, "Loading projects", () => listProjects(api));
138
+ const bound = await lockBoundScope(context, api, projects);
139
+ if (bound) return {
140
+ projectId: String(bound.project.id),
141
+ applicationId: appScoped ? String(bound.app.id) : void 0,
142
+ projectName: bound.project.name,
143
+ appName: appScoped ? bound.app.name : void 0,
144
+ appPlatform: appScoped ? bound.app.platform : void 0,
145
+ projectCount: projects.length,
146
+ appCount: bound.project.applications?.length ?? 0
147
+ };
148
+ const project = await pickProject(context, projects);
149
+ const projectId = String(project.id);
150
+ const apps = project.applications ?? [];
151
+ let app;
152
+ if (appScoped) {
153
+ const appFlag = context.argv.app;
154
+ const remembered = apps.find((candidate) => String(candidate.id) === getDefaultApp(projectId));
155
+ if (appFlag) {
156
+ app = apps.find((candidate) => String(candidate.id) === appFlag || candidate.name === appFlag);
157
+ if (!app) throw new Error(`No app ${appFlag} in ${project.name ?? projectId}.`);
158
+ setDefaultApp(projectId, String(app.id));
159
+ } else if (apps.length <= 1) app = apps[0];
160
+ else if (!context.interactive) throw new Error(`Multiple apps found in ${project.name ?? projectId}. Pass --app <id>.`);
161
+ else {
162
+ app = await chooseApp(context, apps, remembered ?? apps[0]);
163
+ setDefaultApp(projectId, String(app.id));
164
+ }
165
+ }
166
+ return {
167
+ projectId,
168
+ applicationId: app ? String(app.id) : void 0,
169
+ projectName: project.name,
170
+ appName: app?.name,
171
+ appPlatform: app?.platform,
172
+ projectCount: projects.length,
173
+ appCount: apps.length
174
+ };
175
+ }
176
+ async function pickProject(context, projects) {
177
+ const projectFlag = context.argv.project;
178
+ if (projectFlag) {
179
+ const p = projects.find((c) => String(c.id) === projectFlag);
180
+ if (!p) throw new Error(`No project ${projectFlag} in this organization.`);
181
+ return p;
182
+ }
183
+ if (projects.length === 0) throw new Error("No project found in this organization.");
184
+ if (projects.length === 1) return projects[0];
185
+ const { project: preferred, exact } = matchProject(projects, await detectLocal(context.installDir));
186
+ if (exact && preferred) {
187
+ context.ui.info(`Using \`${preferred.name}\` - detected in this directory.`);
188
+ return preferred;
189
+ }
190
+ if (!context.interactive) throw new Error("Multiple projects found. Pass --project <id>.");
191
+ return chooseProject(context, projects, preferred);
192
+ }
193
+ async function chooseProject(context, projects, preferred) {
194
+ const ordered = preferred ? moveFirst(projects, (p) => String(p.id) === String(preferred.id)) : projects;
195
+ const selection = await context.ui.select({
196
+ message: "Which project?",
197
+ options: ordered.map((project) => ({
198
+ value: String(project.id),
199
+ label: project.name ?? String(project.id)
200
+ })),
201
+ initialValue: preferred ? String(preferred.id) : void 0
202
+ });
203
+ if (selection === null) throw new Error("Cancelled.");
204
+ return projects.find((project) => String(project.id) === selection);
205
+ }
206
+ async function chooseApp(context, apps, defaultApp) {
207
+ const top = matchApp(apps, await detectLocal(context.installDir)) ?? defaultApp;
208
+ const ordered = moveFirst(apps, (app) => String(app.id) === String(top.id));
209
+ const selection = await context.ui.select({
210
+ message: "Which app?",
211
+ options: ordered.map((app) => ({
212
+ value: String(app.id),
213
+ label: app.name ?? String(app.id),
214
+ hint: platformLabel(app.platform)
215
+ })),
216
+ initialValue: String(top.id)
217
+ });
218
+ if (selection === null) throw new Error("Cancelled.");
219
+ return apps.find((app) => String(app.id) === selection) ?? top;
220
+ }
221
+
222
+ //#endregion
223
+ export { checkServerNotifications as a, getIntegrations as c, removeAppKey as d, saveBundleId as f, RefusedByApi as i, importAppKey as l, setServerNotifications as m, pickProject as n, copyAppKey as o, setRevenueProvider as p, pickScope as r, getBundleIdSuggestions as s, chooseApp as t, listKeySources as u };