@superwall/cli 1.7.0 → 2.0.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/README.md +192 -52
- package/dist/{setup-Bxj22rYi.js → apple-CkKlHBZ9.js} +82 -76
- package/dist/auth.d.ts +4 -19
- package/dist/auth.js +4 -2
- package/dist/{actions-B7ym3oVS.js → billing-XCZU_T46.js} +98 -28
- package/dist/{bind-YrJvuRF9.js → bind-drne__Ys.js} +38 -33
- package/dist/{build-DLoCW5Ri.js → build-Gpdq5QXP.js} +20 -26
- package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
- package/dist/client-DP6Rc0t_.js +176 -0
- package/dist/config-BO1Y87kV.js +105 -0
- package/dist/{notification-url-DuKF2659.js → create-BBrtgUgS.js} +235 -539
- package/dist/{create-pkANt1Gs.js → create-Cwc3SRWJ.js} +194 -168
- package/dist/create-Yvf2gStM.js +19 -0
- package/dist/doctor-C9ldpPFC.js +83 -0
- package/dist/{drivers-Qx9LxmRN.js → drivers-DNrx4LWA.js} +185 -172
- package/dist/entry.d.ts +0 -5
- package/dist/entry.js +28073 -1134
- package/dist/environment-DF1qKlny.js +58 -0
- package/dist/{existing-AVEfZu2A.js → existing-78LWSsqS.js} +12 -6
- package/dist/held-Cy8Wl4D1.js +1112 -0
- package/dist/held-Ddw1XSsr.js +16 -0
- package/dist/input-vi0bou04.js +42 -0
- package/dist/{integrate-brmhPG-S.js → integrate-DcJhpXy8.js} +277 -254
- package/dist/kinds-GFXB3sYu.js +11 -0
- package/dist/log-NVhVe_oe.js +62 -0
- package/dist/login-B2TsCE2H.js +53 -0
- package/dist/login-BoBe8Psl.js +16 -0
- package/dist/{login-Do4wFuLv.js → login-D0lh3_JI.js} +118 -55
- package/dist/lookup-D-nmmAbw.js +71 -0
- package/dist/migrate-Cfec564E.js +274 -0
- package/dist/notification-url-YDbq6FMA.js +100 -0
- package/dist/{open-studio-DOw-6ydc.js → open-Ba2vBl1_.js} +34 -43
- package/dist/org-D0g_q3mv.js +35 -0
- package/dist/output-Ggzq5_-t.js +122 -0
- package/dist/paths-DxSLdpOI.js +29 -0
- package/dist/playbook-DIeb7hne.js +53 -0
- package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
- package/dist/promote-COD4fYdz.js +91 -0
- package/dist/push-CncywhkQ.js +482 -0
- package/dist/push-CtD4FZQV.js +22 -0
- package/dist/registry-DSrosOYs.js +10228 -0
- package/dist/{reports-CfJqoava.js → reports-DdPq4blM.js} +7 -6
- package/dist/{resources-Bf9O1JNM.js → resources-Dqr01Dep.js} +150 -55
- package/dist/{run-DsVZ5snL.js → run-C9qg_QlC.js} +16 -22
- package/dist/scan-Cv5uOwVY.js +4 -0
- package/dist/{scan-zKsddO72.js → scan-DLrsrFS9.js} +48 -37
- package/dist/scope-V336uz8j.js +198 -0
- package/dist/screenshot-file-0UETadF8.js +16 -0
- package/dist/{selection-CxZoX4NT.js → selection-Rdw-ZUoG.js} +94 -51
- package/dist/send-BxD9yf6F.js +150 -0
- package/dist/{dev-DmB3XqaJ.js → server-D0tGG8C4.js} +82 -92
- package/dist/server-z1LH94R_.js +22 -0
- package/dist/session-1AV_Bs_d.js +6 -0
- package/dist/session-CFAmMhem.js +40 -0
- package/dist/session-D_nEWKXT.js +768 -0
- package/dist/skills/animate-onboarding/SKILL.md +467 -0
- package/dist/skills/animate-onboarding/references/engine.md +494 -0
- package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
- package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
- package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
- package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
- package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
- package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
- package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
- package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
- package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
- package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
- package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
- package/dist/skills/animate-onboarding/references/performance.md +41 -0
- package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
- package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
- package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
- package/dist/skills/index.json +37 -0
- package/dist/skills/mobile-design/SKILL.md +447 -0
- package/dist/skills/mobile-design/references/responsive.md +162 -0
- package/dist/skills/onboarding-questions/SKILL.md +231 -0
- package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
- package/dist/skills/onboarding-questions/references/craft.md +142 -0
- package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
- package/dist/skills/superwall/SKILL.md +82 -9
- package/dist/skills/superwall/references/api.md +153 -37
- package/dist/skills/superwall/references/apple-setup.md +316 -0
- package/dist/skills/superwall/references/asc.md +74 -38
- package/dist/skills/superwall/references/data-analytics.md +55 -21
- package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
- package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
- package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
- package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
- package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
- package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
- package/dist/skills/superwall/workflows/placements/android.md +2 -2
- package/dist/skills/superwall/workflows/placements/expo.md +2 -2
- package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
- package/dist/skills/superwall/workflows/placements/ios.md +2 -2
- package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
- package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
- package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
- package/dist/skills/superwall/workflows/review/playbook.md +1 -1
- package/dist/skills/superwall-editor/SKILL.md +61 -0
- package/dist/skills/superwall-editor/references/cli.md +135 -0
- package/dist/skills/superwall-editor/references/design.md +51 -0
- package/dist/skills/superwall-editor/references/native-elements.md +171 -0
- package/dist/skills/superwall-editor/references/workflow.md +65 -0
- package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
- package/dist/skills/superwall-framework/SKILL.md +78 -28
- package/dist/skills/superwall-framework/references/cli.md +58 -28
- package/dist/skills/superwall-framework/references/examples.md +4 -3
- package/dist/skills/superwall-framework/references/layout.md +30 -8
- package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
- package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
- package/dist/skills/wwdc/SKILL.md +22 -0
- package/dist/skills/wwdc/references/docs.md +52 -0
- package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
- package/dist/{skills-DPzlnfCK.js → skills-BvFOa4y6.js} +99 -122
- package/dist/skills-DMG4bpKk.js +14 -0
- package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
- package/dist/spinner-CneRK5rk.js +294 -0
- package/dist/storage-DYvmIOHa.d.ts +16 -0
- package/dist/storage-s2Dnz-yl.js +31 -0
- package/dist/storekit-DafAnGkM.js +16 -0
- package/dist/storekit-yY_kS2iR.js +47 -0
- package/dist/telemetry-DtG92m5O.js +56 -0
- package/dist/theme-DUsCh-Vd.js +25 -0
- package/dist/timing-BVxPrYq3.js +5 -0
- package/dist/{token-C0it-Xh7.js → token-DzRh7dI1.js} +6 -38
- package/dist/tools.d.ts +96 -0
- package/dist/tools.js +11178 -0
- package/dist/ui-D_qf3Gvw.js +53 -0
- package/dist/upgrade-Bt4Ouw1y.js +117 -0
- package/dist/upgrade-Cqy5orjb.js +7 -0
- package/package.json +10 -5
- package/dist/api-CZzirVMj.js +0 -151
- package/dist/api-output-aJNw7Syy.js +0 -20
- package/dist/app-DH6U8yuI.js +0 -190
- package/dist/asa-C-sQzPPn.js +0 -1194
- package/dist/asc-1ZBJ6DwS.js +0 -778
- package/dist/auth-YRhlV3DE.js +0 -140
- package/dist/billing-CCYHdApx.js +0 -80
- package/dist/bundle-id-CKxl_026.js +0 -121
- package/dist/command-CMIz81Da.js +0 -301
- package/dist/dev-DZy6pOnB.js +0 -22
- package/dist/doctor-H-hf-Yww.js +0 -88
- package/dist/feedback-CKf-rpBW.js +0 -152
- package/dist/hosted-CXe9TrWx.js +0 -32
- package/dist/migrate-C9ERDR6y.js +0 -284
- package/dist/org-sj7uyvp-.js +0 -40
- package/dist/output-C4o2gJ1K.js +0 -146
- package/dist/params-l3CrvRtR.js +0 -51
- package/dist/pipeline-BqzqZhX1.js +0 -977
- package/dist/print-skill-ZojRSybs.js +0 -74
- package/dist/promote-BG8X4Nv_.js +0 -88
- package/dist/publish-sxLh-G4G.js +0 -35
- package/dist/push-bQ6Vxtg8.js +0 -35
- package/dist/query-_FbybaH-.js +0 -53
- package/dist/resource-CGIwSd29.js +0 -323
- package/dist/revenue-provider-ebsRINY8.js +0 -100
- package/dist/scope-BvzD-kO4.js +0 -223
- package/dist/skills-D_R-lEsK.js +0 -64
- package/dist/spinner-TWa0hia6.js +0 -18
- package/dist/storekit-Cj9Cpjcz.js +0 -29
- package/dist/telemetry-DeA1mvnT.js +0 -169
- package/dist/ui-Dy0b-9L8.js +0 -27738
- package/dist/update-B2fWIc4q.js +0 -59
- package/dist/upgrade-BmzkTKrh.js +0 -72
- /package/dist/{devtools-8EgLo86w.js → devtools-ByZ6XYnn.js} +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { n as fg, t as THEME } from "./theme-DUsCh-Vd.js";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
import { link } from "ansi-escapes";
|
|
4
|
+
import wrapAnsi from "wrap-ansi";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
//#region src/ui/log.ts
|
|
8
|
+
function brand(text) {
|
|
9
|
+
return fg(THEME.primary, text);
|
|
10
|
+
}
|
|
11
|
+
function stripReport(raw) {
|
|
12
|
+
const lines = raw.replace(/\r/g, "").split("\n").filter((l) => !/^\s*\[STATUS\]/i.test(l));
|
|
13
|
+
while (lines[0]?.trim() === "") lines.shift();
|
|
14
|
+
while (lines.at(-1)?.trim() === "") lines.pop();
|
|
15
|
+
return lines.join("\n");
|
|
16
|
+
}
|
|
17
|
+
function styleMarkdown(text) {
|
|
18
|
+
return text.split("\n").map((line) => styleMarkdownLine(line)).join("\n");
|
|
19
|
+
}
|
|
20
|
+
function styleMarkdownLine(line, opts = {}) {
|
|
21
|
+
const heading = line.match(/^\s*(#{1,6})\s+(.*)$/)?.[2];
|
|
22
|
+
if (heading !== void 0) return brand(pc.bold(styleInline(heading, opts.hyperlinks ?? false)));
|
|
23
|
+
return styleInline(line, opts.hyperlinks ?? false);
|
|
24
|
+
}
|
|
25
|
+
function wrapReportLine(line, columns) {
|
|
26
|
+
const prefix = line.match(/^(\s*(?:(?:[-*+])|(?:\d+[.)]))\s+)/)?.[1] ?? "";
|
|
27
|
+
const content = prefix ? line.slice(prefix.length) : line;
|
|
28
|
+
const width = Math.max(12, columns - prefix.length);
|
|
29
|
+
return wrapAnsi(styleMarkdownLine(content, { hyperlinks: true }), width, {
|
|
30
|
+
hard: true,
|
|
31
|
+
trim: false
|
|
32
|
+
}).split("\n").map((part, index) => `${index === 0 ? prefix : " ".repeat(prefix.length)}${part}`);
|
|
33
|
+
}
|
|
34
|
+
function styleInline(line, hyperlinks) {
|
|
35
|
+
const re = /\[([^\]]+)]\(([^)]+)\)|\*\*(.+?)\*\*|`([^`]+)`|(https?:\/\/[^\s]+)/g;
|
|
36
|
+
let out = "";
|
|
37
|
+
let last = 0;
|
|
38
|
+
let match;
|
|
39
|
+
while (match = re.exec(line)) {
|
|
40
|
+
out += line.slice(last, match.index);
|
|
41
|
+
if (match[1] != null && match[2] != null) {
|
|
42
|
+
const label = match[1];
|
|
43
|
+
const target = match[2];
|
|
44
|
+
out += hyperlinks ? link(brand(pc.underline(label)), terminalLinkTarget(target)) : `${label} (${target})`;
|
|
45
|
+
} else if (match[3] != null) out += pc.bold(match[3]);
|
|
46
|
+
else if (match[4] != null) out += brand(match[4]);
|
|
47
|
+
else if (match[5] != null) out += hyperlinks ? link(brand(pc.underline(match[5])), match[5]) : match[5];
|
|
48
|
+
last = re.lastIndex;
|
|
49
|
+
}
|
|
50
|
+
out += line.slice(last);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function terminalLinkTarget(target) {
|
|
54
|
+
const local = target.match(/^(\/.*?)(?::(\d+))?$/);
|
|
55
|
+
const file = local?.[1];
|
|
56
|
+
if (file === void 0) return target;
|
|
57
|
+
const url = pathToFileURL(file).href;
|
|
58
|
+
return local?.[2] ? `${url}#L${local[2]}` : url;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { styleMarkdown as n, wrapReportLine as r, stripReport as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { n as ui } from "./ui-D_qf3Gvw.js";
|
|
2
|
+
import { a as onboardingHooks, r as BROWSER_UNAVAILABLE, t as performLogin } from "./login-D0lh3_JI.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/workflows/login.ts
|
|
5
|
+
async function performLoginWithUi(app, onProvisioned) {
|
|
6
|
+
const spin = ui.spinner();
|
|
7
|
+
const hooks = onboardingHooks(app);
|
|
8
|
+
try {
|
|
9
|
+
const session = await performLogin({
|
|
10
|
+
onVerify: ({ url, userCode, browserOpened }) => {
|
|
11
|
+
ui.info(`Approve this login in your browser · code \`${userCode}\`\n${url}`);
|
|
12
|
+
if (!browserOpened) ui.warn(BROWSER_UNAVAILABLE);
|
|
13
|
+
spin.start("Waiting for you to approve in the browser");
|
|
14
|
+
},
|
|
15
|
+
onStatus: (message) => spin.message(message),
|
|
16
|
+
onOnboard: async () => {
|
|
17
|
+
const setup = await hooks.onOnboard();
|
|
18
|
+
if (setup) spin.start("Creating your account");
|
|
19
|
+
return setup;
|
|
20
|
+
},
|
|
21
|
+
onProvisioned: (result) => {
|
|
22
|
+
hooks.onProvisioned(result);
|
|
23
|
+
onProvisioned?.(result);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
spin.stop(`Logged in as \`${session.userEmail ?? "you"}\``);
|
|
27
|
+
return session;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
spin.stop("Login failed");
|
|
30
|
+
ui.warn(error instanceof Error ? error.message : String(error));
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function createLoginGate(app, options) {
|
|
35
|
+
let session = options.session;
|
|
36
|
+
let provisioned = null;
|
|
37
|
+
return {
|
|
38
|
+
ensure: async () => {
|
|
39
|
+
if (session) return true;
|
|
40
|
+
if (!options.interactive || options.dryRun) return false;
|
|
41
|
+
const signedIn = await performLoginWithUi(app, (result) => {
|
|
42
|
+
provisioned = result;
|
|
43
|
+
});
|
|
44
|
+
if (!signedIn) return false;
|
|
45
|
+
session = signedIn;
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
48
|
+
provisioned: () => provisioned
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { performLoginWithUi as n, createLoginGate as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./token-DzRh7dI1.js";
|
|
2
|
+
import "./output-Ggzq5_-t.js";
|
|
3
|
+
import "./environment-DF1qKlny.js";
|
|
4
|
+
import "./storage-s2Dnz-yl.js";
|
|
5
|
+
import "./client-DP6Rc0t_.js";
|
|
6
|
+
import "./config-BO1Y87kV.js";
|
|
7
|
+
import "./telemetry-DtG92m5O.js";
|
|
8
|
+
import "./spawn-DmmmHIP-.js";
|
|
9
|
+
import "./spinner-CneRK5rk.js";
|
|
10
|
+
import "./ui-D_qf3Gvw.js";
|
|
11
|
+
import "./scan-DLrsrFS9.js";
|
|
12
|
+
import "./paths-DxSLdpOI.js";
|
|
13
|
+
import { n as runLogin, t as performLogin } from "./login-D0lh3_JI.js";
|
|
14
|
+
import "./skills-BvFOa4y6.js";
|
|
15
|
+
|
|
16
|
+
export { performLogin, runLogin };
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import {
|
|
1
|
+
import { f as Integration, i as AUTH_HOST, p as OAUTH_SCOPE, s as CLI_CLIENT_ID, t as API_HOST } from "./environment-DF1qKlny.js";
|
|
2
|
+
import { i as serializeSession, o as writeSession } from "./storage-s2Dnz-yl.js";
|
|
3
|
+
import { a as readOnboardingIdempotencyKey, d as writeOnboardedApp, f as writeOnboardedOrg, i as readOnboardedOrg } from "./config-BO1Y87kV.js";
|
|
4
|
+
import { r as track } from "./telemetry-DtG92m5O.js";
|
|
5
|
+
import { n as ui } from "./ui-D_qf3Gvw.js";
|
|
6
|
+
import { t as scanProject } from "./scan-DLrsrFS9.js";
|
|
7
|
+
import { s as ensureSkillsCurrent } from "./skills-BvFOa4y6.js";
|
|
5
8
|
import { spawn } from "node:child_process";
|
|
9
|
+
import { setTimeout } from "node:timers/promises";
|
|
6
10
|
|
|
7
11
|
//#region src/core/account/onboarding.ts
|
|
12
|
+
function resolveOnboardPlatform(integration) {
|
|
13
|
+
switch (integration) {
|
|
14
|
+
case Integration.swift: return "ios";
|
|
15
|
+
case Integration.android: return "android";
|
|
16
|
+
case Integration.web: return "web";
|
|
17
|
+
default: return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
8
20
|
function onboardingHooks(app) {
|
|
9
21
|
const ref = { current: null };
|
|
10
|
-
const platform = app?.integration
|
|
22
|
+
const platform = resolveOnboardPlatform(app?.integration);
|
|
11
23
|
return {
|
|
12
24
|
onOnboard: async () => {
|
|
13
25
|
let onboardApp;
|
|
@@ -34,7 +46,7 @@ function onboardingHooks(app) {
|
|
|
34
46
|
},
|
|
35
47
|
onProvisioned: (result) => {
|
|
36
48
|
ref.current = result;
|
|
37
|
-
if (app && result.publicApiKey)
|
|
49
|
+
if (app && result.publicApiKey) writeOnboardedApp(app.path, {
|
|
38
50
|
publicApiKey: result.publicApiKey,
|
|
39
51
|
projectId: result.projectId,
|
|
40
52
|
applicationId: result.applicationId
|
|
@@ -45,7 +57,7 @@ function onboardingHooks(app) {
|
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
//#endregion
|
|
48
|
-
//#region src/core/
|
|
60
|
+
//#region src/core/account/browser.ts
|
|
49
61
|
const BROWSER_UNAVAILABLE = "Couldn't open a browser here. Open the URL above to approve the login.";
|
|
50
62
|
function hasDisplay(env, platform) {
|
|
51
63
|
if (platform !== "linux") return true;
|
|
@@ -77,9 +89,8 @@ function openBrowser(url, deps = {}) {
|
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
//#endregion
|
|
80
|
-
//#region src/core/
|
|
92
|
+
//#region src/core/account/login.ts
|
|
81
93
|
const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
82
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
83
94
|
async function performLogin(opts = {}) {
|
|
84
95
|
const issuer = opts.issuer ?? AUTH_HOST();
|
|
85
96
|
const apiHost = opts.apiHost ?? API_HOST();
|
|
@@ -96,42 +107,35 @@ async function performLogin(opts = {}) {
|
|
|
96
107
|
});
|
|
97
108
|
const { accessToken, refreshToken, expiresIn, idToken } = await pollForToken(disc.token_endpoint, clientId, dev, opts.onStatus);
|
|
98
109
|
let apiToken = accessToken;
|
|
99
|
-
if (idToken) await
|
|
100
|
-
const me = await
|
|
101
|
-
let
|
|
110
|
+
if (idToken) await findJson(`${apiHost}/v2/me`, idToken).catch(() => null);
|
|
111
|
+
const me = await findJson(`${apiHost}/v2/me`, apiToken).catch(() => null);
|
|
112
|
+
let hasOrg = false;
|
|
102
113
|
try {
|
|
103
|
-
|
|
114
|
+
hasOrg = ((await findJson(`${apiHost}/v2/me/organizations`, apiToken)).data ?? []).length > 0;
|
|
104
115
|
} catch {
|
|
105
|
-
|
|
116
|
+
hasOrg = false;
|
|
106
117
|
}
|
|
107
|
-
const uniqueOrgs = [...new Map(orgList.map((o) => [String(o.id), o])).values()];
|
|
108
|
-
let org;
|
|
109
118
|
let createdNewOrg = false;
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
name: org.name
|
|
131
|
-
});
|
|
132
|
-
createdNewOrg = true;
|
|
133
|
-
} else throw new Error("Your account has no organization yet - run `superwall login` interactively to create one.");
|
|
134
|
-
} else if (uniqueOrgs.length === 1) org = uniqueOrgs[0];
|
|
119
|
+
if (!hasOrg && !readOnboardedOrg()) {
|
|
120
|
+
if (!opts.onOnboard) throw new Error("Your account has no organization yet - run `superwall login` interactively to create one.");
|
|
121
|
+
const setup = await opts.onOnboard();
|
|
122
|
+
if (!setup) throw new Error("Cancelled.");
|
|
123
|
+
opts.onStatus?.("Creating your account…");
|
|
124
|
+
let org;
|
|
125
|
+
if (setup.app) {
|
|
126
|
+
const provisioned = await provisionAccount(apiHost, apiToken, setup.orgName, setup.app);
|
|
127
|
+
if (provisioned.orgId) org = {
|
|
128
|
+
id: provisioned.orgId,
|
|
129
|
+
name: setup.orgName
|
|
130
|
+
};
|
|
131
|
+
opts.onProvisioned?.(provisioned);
|
|
132
|
+
} else org = await createOrganization(apiHost, apiToken, setup.orgName);
|
|
133
|
+
if (org) writeOnboardedOrg({
|
|
134
|
+
id: String(org.id),
|
|
135
|
+
name: org.name
|
|
136
|
+
});
|
|
137
|
+
createdNewOrg = true;
|
|
138
|
+
}
|
|
135
139
|
if (createdNewOrg && refreshToken) {
|
|
136
140
|
opts.onStatus?.("Activating your organization…");
|
|
137
141
|
const fresh = await refreshAccessToken(disc.token_endpoint, clientId, refreshToken);
|
|
@@ -139,9 +143,6 @@ async function performLogin(opts = {}) {
|
|
|
139
143
|
}
|
|
140
144
|
const session = {
|
|
141
145
|
authMethod: "oauth",
|
|
142
|
-
orgId: org ? String(org.id) : void 0,
|
|
143
|
-
orgName: org?.name,
|
|
144
|
-
orgCount: createdNewOrg ? 1 : uniqueOrgs.length,
|
|
145
146
|
userEmail: me?.email,
|
|
146
147
|
host: apiHost,
|
|
147
148
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -151,7 +152,7 @@ async function performLogin(opts = {}) {
|
|
|
151
152
|
tokenEndpoint: disc.token_endpoint,
|
|
152
153
|
oauthClientId: clientId
|
|
153
154
|
};
|
|
154
|
-
|
|
155
|
+
writeSession(session);
|
|
155
156
|
return session;
|
|
156
157
|
}
|
|
157
158
|
async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
|
|
@@ -159,7 +160,7 @@ async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
|
|
|
159
160
|
if (!key) throw new Error("An API key is required.");
|
|
160
161
|
let org = {};
|
|
161
162
|
try {
|
|
162
|
-
const first = (await
|
|
163
|
+
const first = (await findJson(`${apiHost}/v2/me/organizations`, key)).data?.[0];
|
|
163
164
|
if (first) org = {
|
|
164
165
|
id: String(first.id),
|
|
165
166
|
name: first.name
|
|
@@ -170,12 +171,11 @@ async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
|
|
|
170
171
|
const session = {
|
|
171
172
|
authMethod: "api_key",
|
|
172
173
|
apiKey: key,
|
|
173
|
-
orgId: org.id,
|
|
174
174
|
orgName: org.name,
|
|
175
175
|
host: apiHost,
|
|
176
176
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
177
177
|
};
|
|
178
|
-
|
|
178
|
+
writeSession(session);
|
|
179
179
|
return session;
|
|
180
180
|
}
|
|
181
181
|
async function discover(issuer) {
|
|
@@ -202,7 +202,7 @@ async function pollForToken(tokenEndpoint, clientId, dev, onStatus) {
|
|
|
202
202
|
const deadline = Date.now() + (dev.expires_in ?? 600) * 1e3;
|
|
203
203
|
let interval = dev.interval ?? 5;
|
|
204
204
|
while (Date.now() < deadline) {
|
|
205
|
-
await
|
|
205
|
+
await setTimeout(interval * 1e3);
|
|
206
206
|
const r = await fetch(tokenEndpoint, {
|
|
207
207
|
method: "POST",
|
|
208
208
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
@@ -240,11 +240,10 @@ async function createOrganization(apiHost, token, name) {
|
|
|
240
240
|
name: created.name
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
|
-
async function provisionAccount(apiHost, token,
|
|
244
|
-
const app = setup.app;
|
|
243
|
+
async function provisionAccount(apiHost, token, orgName, app) {
|
|
245
244
|
const res = await postJson(`${apiHost}/internal/v2/onboarding/provision`, token, {
|
|
246
|
-
idempotency_key:
|
|
247
|
-
organization: { name:
|
|
245
|
+
idempotency_key: readOnboardingIdempotencyKey(),
|
|
246
|
+
organization: { name: orgName },
|
|
248
247
|
applications: [{
|
|
249
248
|
name: app.name,
|
|
250
249
|
platform: app.platform,
|
|
@@ -277,7 +276,7 @@ async function refreshAccessToken(tokenEndpoint, clientId, refreshToken) {
|
|
|
277
276
|
return null;
|
|
278
277
|
}
|
|
279
278
|
}
|
|
280
|
-
async function
|
|
279
|
+
async function findJson(url, accessToken) {
|
|
281
280
|
const r = await fetch(url, { headers: {
|
|
282
281
|
authorization: `Bearer ${accessToken}`,
|
|
283
282
|
accept: "application/json"
|
|
@@ -301,6 +300,70 @@ async function postJson(url, accessToken, body) {
|
|
|
301
300
|
}
|
|
302
301
|
return r.json();
|
|
303
302
|
}
|
|
303
|
+
async function runLogin(ctx, { flags, openBrowser: openBrowser$1 }) {
|
|
304
|
+
const { ui: ui$1 } = ctx;
|
|
305
|
+
ui$1.intro("Superwall login");
|
|
306
|
+
const apiKeyArg = flags.apiKey;
|
|
307
|
+
if (apiKeyArg) {
|
|
308
|
+
const spin$1 = ui$1.spinner();
|
|
309
|
+
spin$1.start("Verifying your API key");
|
|
310
|
+
try {
|
|
311
|
+
const session = await loginWithApiKey(apiKeyArg);
|
|
312
|
+
spin$1.stop("Logged in");
|
|
313
|
+
track("login finished", {
|
|
314
|
+
status: "success",
|
|
315
|
+
method: "api_key"
|
|
316
|
+
});
|
|
317
|
+
if (ctx.json) return ctx.output.data(serializeSession(session));
|
|
318
|
+
ui$1.success(`Logged in with an API key${session.orgName ? ` · \`${session.orgName}\`` : ""}.`);
|
|
319
|
+
ui$1.outro("You're all set - run `superwall integrate` to set up your app.");
|
|
320
|
+
} catch (e) {
|
|
321
|
+
spin$1.stop("Login failed");
|
|
322
|
+
track("login finished", {
|
|
323
|
+
status: "error",
|
|
324
|
+
method: "api_key"
|
|
325
|
+
});
|
|
326
|
+
throw e;
|
|
327
|
+
}
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (!ctx.interactive) throw new Error("Browser login requires an interactive terminal. Use `superwall login --api-key <key>`.");
|
|
331
|
+
const hooks = onboardingHooks((await scanProject(ctx.installDir).catch(() => null))?.apps[0]);
|
|
332
|
+
const spin = ui$1.spinner();
|
|
333
|
+
try {
|
|
334
|
+
const session = await performLogin({
|
|
335
|
+
issuer: flags.host,
|
|
336
|
+
clientId: flags.clientId,
|
|
337
|
+
openBrowser: openBrowser$1,
|
|
338
|
+
onVerify: ({ url, userCode, browserOpened }) => {
|
|
339
|
+
ui$1.info(`Approve this login in your browser · code \`${userCode}\`\n${url}`);
|
|
340
|
+
if (!browserOpened) ui$1.warn(BROWSER_UNAVAILABLE);
|
|
341
|
+
spin.start("Waiting for you to approve in the browser");
|
|
342
|
+
},
|
|
343
|
+
onStatus: (m) => spin.message(m),
|
|
344
|
+
onOnboard: async () => {
|
|
345
|
+
const setup = await hooks.onOnboard();
|
|
346
|
+
if (setup) spin.start("Creating your account");
|
|
347
|
+
return setup;
|
|
348
|
+
},
|
|
349
|
+
onProvisioned: hooks.onProvisioned
|
|
350
|
+
});
|
|
351
|
+
spin.stop(`Logged in as \`${session.userEmail ?? "you"}\``);
|
|
352
|
+
track("login finished", {
|
|
353
|
+
status: "success",
|
|
354
|
+
method: "oauth"
|
|
355
|
+
});
|
|
356
|
+
if (!ctx.json) await ensureSkillsCurrent(false, "login").catch(() => {});
|
|
357
|
+
ui$1.outro(hooks.provisioned()?.publicApiKey ? "Your app is ready - run `superwall integrate` to set up the SDK." : "You're all set - run `superwall integrate` to set up your app.");
|
|
358
|
+
} catch (e) {
|
|
359
|
+
spin.stop("Login failed");
|
|
360
|
+
track("login finished", {
|
|
361
|
+
status: "error",
|
|
362
|
+
method: "oauth"
|
|
363
|
+
});
|
|
364
|
+
throw e;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
304
367
|
|
|
305
368
|
//#endregion
|
|
306
|
-
export { onboardingHooks as a, openBrowser as i,
|
|
369
|
+
export { onboardingHooks as a, openBrowser as i, runLogin as n, BROWSER_UNAVAILABLE as r, performLogin as t };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { t as ApiError } from "./client-DP6Rc0t_.js";
|
|
2
|
+
import { F as rememberOrg, N as orgProjects, p as listProjects } from "./resources-Dqr01Dep.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/api/lookup.ts
|
|
5
|
+
const DASHBOARD_PATH = /^\/(\d+)(?:\/(\d+))?(?:\/|$)/;
|
|
6
|
+
function parseDashboardUrl(value) {
|
|
7
|
+
let url;
|
|
8
|
+
try {
|
|
9
|
+
url = new URL(value);
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!/(^|\.)superwall\.com$/.test(url.hostname)) return void 0;
|
|
14
|
+
const match = DASHBOARD_PATH.exec(url.pathname);
|
|
15
|
+
if (!match) return void 0;
|
|
16
|
+
return {
|
|
17
|
+
orgId: match[1],
|
|
18
|
+
applicationId: match[2]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function notFound(error) {
|
|
22
|
+
return error instanceof ApiError && (error.status === 404 || error.status === 403);
|
|
23
|
+
}
|
|
24
|
+
async function findProject(api, projectId, known) {
|
|
25
|
+
const local = known?.find((project) => String(project.id) === projectId);
|
|
26
|
+
if (local) return local;
|
|
27
|
+
try {
|
|
28
|
+
const project = await api.get(`/v2/projects/${encodeURIComponent(projectId)}`);
|
|
29
|
+
rememberOrg(project);
|
|
30
|
+
return project;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (notFound(error)) return void 0;
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const selectFromProjects = (projects, matches) => {
|
|
37
|
+
for (const project of projects) {
|
|
38
|
+
const app = project.applications?.find(matches);
|
|
39
|
+
if (app) return {
|
|
40
|
+
project,
|
|
41
|
+
app
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
async function findApplication(api, ref, known) {
|
|
46
|
+
const dashboard = parseDashboardUrl(ref);
|
|
47
|
+
const id = dashboard?.applicationId ?? ref;
|
|
48
|
+
const byId = (app) => String(app.id) === id;
|
|
49
|
+
const local = selectFromProjects(known ?? await listProjects(api), (app) => byId(app) || app.name === ref);
|
|
50
|
+
if (local) return local;
|
|
51
|
+
if (!/^\d+$/.test(id)) return void 0;
|
|
52
|
+
const [paywall] = await api.get(`/v2/paywalls?application_id=${encodeURIComponent(id)}&limit=1`).then((page) => page.data ?? []).catch((error) => {
|
|
53
|
+
if (notFound(error)) return [];
|
|
54
|
+
throw error;
|
|
55
|
+
});
|
|
56
|
+
if (paywall?.project_id !== void 0) {
|
|
57
|
+
const project = await findProject(api, String(paywall.project_id));
|
|
58
|
+
const found$1 = project && selectFromProjects([project], byId);
|
|
59
|
+
if (found$1) return found$1;
|
|
60
|
+
}
|
|
61
|
+
if (!dashboard?.orgId) return void 0;
|
|
62
|
+
const found = selectFromProjects(await orgProjects(api, dashboard.orgId), byId);
|
|
63
|
+
if (found) rememberOrg(found.project);
|
|
64
|
+
return found;
|
|
65
|
+
}
|
|
66
|
+
function appNotFound(ref) {
|
|
67
|
+
return /* @__PURE__ */ new Error(`No app ${ref} that this account can open. Pass its dashboard link instead — https://app.superwall.com/<org>/<app>/… names the organization, which finds apps that have no paywalls yet.`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { findApplication as n, findProject as r, appNotFound as t };
|