@superwall/cli 1.6.2 → 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 +281 -34
- package/dist/apple-CkKlHBZ9.js +195 -0
- package/dist/auth.d.ts +4 -19
- package/dist/auth.js +4 -2
- package/dist/{actions-H7f6knyY.js → billing-XCZU_T46.js} +98 -28
- package/dist/{bind-BIzaGq8K.js → bind-drne__Ys.js} +38 -33
- package/dist/{build-B7BS1rF2.js → build-Gpdq5QXP.js} +20 -26
- package/dist/client-BZ1UbpXz.js +66 -0
- package/dist/client-DP6Rc0t_.js +176 -0
- package/dist/config-BO1Y87kV.js +105 -0
- package/dist/create-BBrtgUgS.js +969 -0
- package/dist/{create-CwnnNqv4.js → create-Cwc3SRWJ.js} +194 -168
- package/dist/create-Yvf2gStM.js +19 -0
- package/dist/doctor-C9ldpPFC.js +83 -0
- package/dist/{drivers-6RMOPIdn.js → drivers-DNrx4LWA.js} +185 -172
- package/dist/entry.d.ts +0 -5
- package/dist/entry.js +28083 -801
- package/dist/environment-DF1qKlny.js +58 -0
- package/dist/{existing-DHpPn1y6.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-BR2LR-EK.js → integrate-DcJhpXy8.js} +277 -253
- 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-Bhxgqwtm.js → login-D0lh3_JI.js} +144 -66
- 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-BnVD6tJ9.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-Dvcyef3_.js → products-DH_fK9tY.js} +6 -39
- 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-DqMs9xNR.js → reports-DdPq4blM.js} +7 -6
- package/dist/{resources-Bf9O1JNM.js → resources-Dqr01Dep.js} +150 -55
- package/dist/{run-D-NbZLpj.js → run-C9qg_QlC.js} +16 -22
- package/dist/scan-Cv5uOwVY.js +4 -0
- package/dist/{scan-BmAW413l.js → scan-DLrsrFS9.js} +48 -37
- package/dist/scope-V336uz8j.js +198 -0
- package/dist/screenshot-file-0UETadF8.js +16 -0
- package/dist/{selection-BGi6GyxC.js → selection-Rdw-ZUoG.js} +94 -51
- package/dist/send-BxD9yf6F.js +150 -0
- package/dist/{dev-CgGAb5Al.js → server-D0tGG8C4.js} +82 -87
- 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-AxAf7bDB.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-BGAVPSQc.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-Dv3LyZ5m.js +0 -151
- package/dist/api-output-aJNw7Syy.js +0 -20
- package/dist/app-mJC5NDtW.js +0 -189
- package/dist/asa-D6H7Pjae.js +0 -1194
- package/dist/asc-xCin0akG.js +0 -539
- package/dist/auth-ZlLL-Gko.js +0 -139
- package/dist/billing-C8kBge_S.js +0 -80
- package/dist/command-3fGYyC8r.js +0 -301
- package/dist/dev-Dx99K183.js +0 -22
- package/dist/doctor-CyUvut31.js +0 -88
- package/dist/feedback-RKyGuQ8_.js +0 -152
- package/dist/hosted-BeGVAntr.js +0 -32
- package/dist/migrate-C-4ISELN.js +0 -284
- package/dist/org-CQduIOic.js +0 -40
- package/dist/output-C-4UKMot.js +0 -136
- package/dist/params-l3CrvRtR.js +0 -51
- package/dist/pipeline-CHX0Syre.js +0 -977
- package/dist/print-skill-BiZLdCKv.js +0 -74
- package/dist/promote-Pgpz-3xl.js +0 -88
- package/dist/publish-BPeuc3lq.js +0 -35
- package/dist/push-DcSQ4odB.js +0 -35
- package/dist/query-CWLaZkdm.js +0 -53
- package/dist/resource-jwASPCrw.js +0 -483
- package/dist/skills-FK5aDuNV.js +0 -64
- package/dist/spinner-DFctF_Jw.js +0 -18
- package/dist/storekit-CC4gnTI6.js +0 -29
- package/dist/telemetry-Ch9cCTI-.js +0 -169
- package/dist/ui-4gLyfrgl.js +0 -27737
- package/dist/update-DIXbL-H9.js +0 -59
- package/dist/upgrade-De7JMI1g.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,27 +57,40 @@ function onboardingHooks(app) {
|
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
//#endregion
|
|
48
|
-
//#region src/core/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
//#region src/core/account/browser.ts
|
|
61
|
+
const BROWSER_UNAVAILABLE = "Couldn't open a browser here. Open the URL above to approve the login.";
|
|
62
|
+
function hasDisplay(env, platform) {
|
|
63
|
+
if (platform !== "linux") return true;
|
|
64
|
+
return Boolean(env.DISPLAY || env.WAYLAND_DISPLAY || env.WSL_DISTRO_NAME);
|
|
65
|
+
}
|
|
66
|
+
function openBrowser(url, deps = {}) {
|
|
67
|
+
const platform = deps.platform ?? process.platform;
|
|
68
|
+
if (!hasDisplay(deps.env ?? process.env, platform)) return Promise.resolve(false);
|
|
69
|
+
const cmd = platform === "darwin" ? "open" : platform === "win32" ? "cmd" : "xdg-open";
|
|
70
|
+
const args = platform === "win32" ? [
|
|
52
71
|
"/c",
|
|
53
72
|
"start",
|
|
54
73
|
"",
|
|
55
74
|
url
|
|
56
75
|
] : [url];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
76
|
+
return new Promise((resolve) => {
|
|
77
|
+
try {
|
|
78
|
+
const child = (deps.spawn ?? spawn)(cmd, args, {
|
|
79
|
+
stdio: "ignore",
|
|
80
|
+
detached: true
|
|
81
|
+
});
|
|
82
|
+
child.once("error", () => resolve(false));
|
|
83
|
+
child.once("spawn", () => resolve(true));
|
|
84
|
+
child.unref();
|
|
85
|
+
} catch {
|
|
86
|
+
resolve(false);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
63
89
|
}
|
|
64
90
|
|
|
65
91
|
//#endregion
|
|
66
|
-
//#region src/core/
|
|
92
|
+
//#region src/core/account/login.ts
|
|
67
93
|
const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
68
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
69
94
|
async function performLogin(opts = {}) {
|
|
70
95
|
const issuer = opts.issuer ?? AUTH_HOST();
|
|
71
96
|
const apiHost = opts.apiHost ?? API_HOST();
|
|
@@ -74,49 +99,43 @@ async function performLogin(opts = {}) {
|
|
|
74
99
|
if (!disc.device_authorization_endpoint) throw new Error("auth.superwall.com does not advertise a device-authorization endpoint.");
|
|
75
100
|
const dev = await startDeviceAuth(disc.device_authorization_endpoint, clientId);
|
|
76
101
|
const url = dev.verification_uri_complete ?? dev.verification_uri;
|
|
102
|
+
const browserOpened = await (opts.openBrowser ?? openBrowser)(url);
|
|
77
103
|
opts.onVerify?.({
|
|
78
104
|
url,
|
|
79
|
-
userCode: dev.user_code
|
|
105
|
+
userCode: dev.user_code,
|
|
106
|
+
browserOpened
|
|
80
107
|
});
|
|
81
|
-
openBrowser(url);
|
|
82
108
|
const { accessToken, refreshToken, expiresIn, idToken } = await pollForToken(disc.token_endpoint, clientId, dev, opts.onStatus);
|
|
83
109
|
let apiToken = accessToken;
|
|
84
|
-
if (idToken) await
|
|
85
|
-
const me = await
|
|
86
|
-
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;
|
|
87
113
|
try {
|
|
88
|
-
|
|
114
|
+
hasOrg = ((await findJson(`${apiHost}/v2/me/organizations`, apiToken)).data ?? []).length > 0;
|
|
89
115
|
} catch {
|
|
90
|
-
|
|
116
|
+
hasOrg = false;
|
|
91
117
|
}
|
|
92
|
-
const uniqueOrgs = [...new Map(orgList.map((o) => [String(o.id), o])).values()];
|
|
93
|
-
let org;
|
|
94
118
|
let createdNewOrg = false;
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
name: org.name
|
|
116
|
-
});
|
|
117
|
-
createdNewOrg = true;
|
|
118
|
-
} else throw new Error("Your account has no organization yet - run `superwall login` interactively to create one.");
|
|
119
|
-
} 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
|
+
}
|
|
120
139
|
if (createdNewOrg && refreshToken) {
|
|
121
140
|
opts.onStatus?.("Activating your organization…");
|
|
122
141
|
const fresh = await refreshAccessToken(disc.token_endpoint, clientId, refreshToken);
|
|
@@ -124,9 +143,6 @@ async function performLogin(opts = {}) {
|
|
|
124
143
|
}
|
|
125
144
|
const session = {
|
|
126
145
|
authMethod: "oauth",
|
|
127
|
-
orgId: org ? String(org.id) : void 0,
|
|
128
|
-
orgName: org?.name,
|
|
129
|
-
orgCount: createdNewOrg ? 1 : uniqueOrgs.length,
|
|
130
146
|
userEmail: me?.email,
|
|
131
147
|
host: apiHost,
|
|
132
148
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -136,7 +152,7 @@ async function performLogin(opts = {}) {
|
|
|
136
152
|
tokenEndpoint: disc.token_endpoint,
|
|
137
153
|
oauthClientId: clientId
|
|
138
154
|
};
|
|
139
|
-
|
|
155
|
+
writeSession(session);
|
|
140
156
|
return session;
|
|
141
157
|
}
|
|
142
158
|
async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
|
|
@@ -144,7 +160,7 @@ async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
|
|
|
144
160
|
if (!key) throw new Error("An API key is required.");
|
|
145
161
|
let org = {};
|
|
146
162
|
try {
|
|
147
|
-
const first = (await
|
|
163
|
+
const first = (await findJson(`${apiHost}/v2/me/organizations`, key)).data?.[0];
|
|
148
164
|
if (first) org = {
|
|
149
165
|
id: String(first.id),
|
|
150
166
|
name: first.name
|
|
@@ -155,12 +171,11 @@ async function loginWithApiKey(apiKey, apiHost = API_HOST()) {
|
|
|
155
171
|
const session = {
|
|
156
172
|
authMethod: "api_key",
|
|
157
173
|
apiKey: key,
|
|
158
|
-
orgId: org.id,
|
|
159
174
|
orgName: org.name,
|
|
160
175
|
host: apiHost,
|
|
161
176
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
162
177
|
};
|
|
163
|
-
|
|
178
|
+
writeSession(session);
|
|
164
179
|
return session;
|
|
165
180
|
}
|
|
166
181
|
async function discover(issuer) {
|
|
@@ -187,7 +202,7 @@ async function pollForToken(tokenEndpoint, clientId, dev, onStatus) {
|
|
|
187
202
|
const deadline = Date.now() + (dev.expires_in ?? 600) * 1e3;
|
|
188
203
|
let interval = dev.interval ?? 5;
|
|
189
204
|
while (Date.now() < deadline) {
|
|
190
|
-
await
|
|
205
|
+
await setTimeout(interval * 1e3);
|
|
191
206
|
const r = await fetch(tokenEndpoint, {
|
|
192
207
|
method: "POST",
|
|
193
208
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
@@ -225,11 +240,10 @@ async function createOrganization(apiHost, token, name) {
|
|
|
225
240
|
name: created.name
|
|
226
241
|
};
|
|
227
242
|
}
|
|
228
|
-
async function provisionAccount(apiHost, token,
|
|
229
|
-
const app = setup.app;
|
|
243
|
+
async function provisionAccount(apiHost, token, orgName, app) {
|
|
230
244
|
const res = await postJson(`${apiHost}/internal/v2/onboarding/provision`, token, {
|
|
231
|
-
idempotency_key:
|
|
232
|
-
organization: { name:
|
|
245
|
+
idempotency_key: readOnboardingIdempotencyKey(),
|
|
246
|
+
organization: { name: orgName },
|
|
233
247
|
applications: [{
|
|
234
248
|
name: app.name,
|
|
235
249
|
platform: app.platform,
|
|
@@ -262,7 +276,7 @@ async function refreshAccessToken(tokenEndpoint, clientId, refreshToken) {
|
|
|
262
276
|
return null;
|
|
263
277
|
}
|
|
264
278
|
}
|
|
265
|
-
async function
|
|
279
|
+
async function findJson(url, accessToken) {
|
|
266
280
|
const r = await fetch(url, { headers: {
|
|
267
281
|
authorization: `Bearer ${accessToken}`,
|
|
268
282
|
accept: "application/json"
|
|
@@ -286,6 +300,70 @@ async function postJson(url, accessToken, body) {
|
|
|
286
300
|
}
|
|
287
301
|
return r.json();
|
|
288
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
|
+
}
|
|
289
367
|
|
|
290
368
|
//#endregion
|
|
291
|
-
export { onboardingHooks 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 };
|