@superwall/cli 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/actions-MB-eBY64.js +140 -0
- package/dist/api-BF7-toqM.js +151 -0
- package/dist/api-output-B5hh0q4V.js +20 -0
- package/dist/app-K6j9Es7h.js +189 -0
- package/dist/asc-CArSwo5D.js +539 -0
- package/dist/asc-products-YQ6Oc6YO.js +93 -0
- package/dist/auth-CY2cO_NF.js +139 -0
- package/dist/auth.d.ts +30 -0
- package/dist/auth.js +4 -0
- package/dist/billing-DWyfEQ6l.js +80 -0
- package/dist/bind-hslFhcTR.js +213 -0
- package/dist/chunk-DQxbwPpZ.js +30 -0
- package/dist/command-Kwx4ekbo.js +283 -0
- package/dist/create-Bbi8BOO1.js +410 -0
- package/dist/dev-D0lQDCQI.js +397 -0
- package/dist/devtools-8EgLo86w.js +3638 -0
- package/dist/doctor-ByeRdMcl.js +88 -0
- package/dist/drivers-DVAZgone.js +413 -0
- package/dist/entry.d.ts +9 -0
- package/dist/entry.js +495 -0
- package/dist/existing-CcJrIIAU.js +88 -0
- package/dist/feedback-Z0Wk7VC5.js +73 -0
- package/dist/git-3OX9u3xE.js +433 -0
- package/dist/hosted-CHwaUqLd.js +32 -0
- package/dist/integrate-DqOAqK7J.js +863 -0
- package/dist/json-C3hPIMkI.js +7 -0
- package/dist/login-Dr8UN_Gx.js +290 -0
- package/dist/migrate-D92bJTg6.js +114 -0
- package/dist/org-B2gy9Pmu.js +40 -0
- package/dist/params-Bvq0iqQK.js +52 -0
- package/dist/pipeline-CHHIg6BU.js +1056 -0
- package/dist/print-skill-BnZAk7dV.js +74 -0
- package/dist/promote-CRe9170G.js +88 -0
- package/dist/publish-DsODvrOD.js +35 -0
- package/dist/push-BDkZUC0v.js +35 -0
- package/dist/query-DIllrSnk.js +53 -0
- package/dist/resource-CdP1MDla.js +483 -0
- package/dist/resources-CVrWwA1K.js +233 -0
- package/dist/run-cGGBUMs5.js +89 -0
- package/dist/scan-BQexuUPO.js +236 -0
- package/dist/skills-DhuUs28u.js +64 -0
- package/dist/skills-xrfXt9u0.js +205 -0
- package/dist/spawn-DSoTXy_j.js +69 -0
- package/dist/spinner-gOxIMz-V.js +18 -0
- package/dist/storekit-Ddvs4Ynw.js +29 -0
- package/dist/telemetry-CcfrtXdf.js +204 -0
- package/dist/token-DHRH8cxi.js +102 -0
- package/dist/ui-C4ncRJqd.js +27703 -0
- package/dist/update-BiVeR024.js +137 -0
- package/dist/upgrade-DYWspApv.js +72 -0
- package/package.json +87 -0
- package/prompts/actions/dashboard-setup.xml +10 -0
- package/prompts/actions/integrate.xml +5 -0
- package/prompts/actions/migrate.xml +11 -0
- package/prompts/actions/placements-implement.xml +20 -0
- package/prompts/actions/placements-review.xml +18 -0
- package/prompts/actions/review-fix.xml +18 -0
- package/prompts/actions/review.xml +18 -0
- package/prompts/commandments.xml +17 -0
- package/prompts/context.xml +9 -0
- package/skills/README.md +118 -0
- package/skills/superwall-dashboard/SKILL.md +81 -0
- package/skills/superwall-dashboard/references/setup.md +101 -0
- package/skills/superwall-integrate/SKILL.md +76 -0
- package/skills/superwall-integrate/references/expo.md +269 -0
- package/skills/superwall-integrate/references/flutter.md +285 -0
- package/skills/superwall-integrate/references/ios.md +314 -0
- package/skills/superwall-integrate/references/react-native.md +245 -0
- package/skills/superwall-migrate/SKILL.md +83 -0
- package/skills/superwall-migrate/references/adapty.md +229 -0
- package/skills/superwall-migrate/references/qonversion.md +227 -0
- package/skills/superwall-migrate/references/revenuecat.md +414 -0
- package/skills/superwall-placements/SKILL.md +73 -0
- package/skills/superwall-placements/references/expo.md +161 -0
- package/skills/superwall-placements/references/flutter.md +139 -0
- package/skills/superwall-placements/references/ios.md +165 -0
- package/skills/superwall-placements/references/react-native.md +145 -0
- package/skills/superwall-placements/references/strategy.md +221 -0
- package/skills/superwall-review/SKILL.md +75 -0
- package/skills/superwall-review/references/expo.md +100 -0
- package/skills/superwall-review/references/flutter.md +99 -0
- package/skills/superwall-review/references/ios.md +108 -0
- package/skills/superwall-review/references/react-native.md +100 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { i as track, y as API_HOST } from "./telemetry-CcfrtXdf.js";
|
|
2
|
+
import "./json-C3hPIMkI.js";
|
|
3
|
+
import "./update-BiVeR024.js";
|
|
4
|
+
import { i as loadSession, r as clearSession } from "./token-DHRH8cxi.js";
|
|
5
|
+
import { t as defineCommand } from "./command-Kwx4ekbo.js";
|
|
6
|
+
import "./ui-C4ncRJqd.js";
|
|
7
|
+
import { n as ensureSkillsCurrent } from "./skills-xrfXt9u0.js";
|
|
8
|
+
import "./spawn-DSoTXy_j.js";
|
|
9
|
+
import { n as performLogin, r as onboardingHooks, t as loginWithApiKey } from "./login-Dr8UN_Gx.js";
|
|
10
|
+
import { t as scanProject } from "./scan-BQexuUPO.js";
|
|
11
|
+
|
|
12
|
+
//#region src/commands/account/auth.ts
|
|
13
|
+
const runLogin = defineCommand({
|
|
14
|
+
name: "login",
|
|
15
|
+
output: "both",
|
|
16
|
+
async run(ctx) {
|
|
17
|
+
const { ui } = ctx;
|
|
18
|
+
ui.intro("Superwall login");
|
|
19
|
+
const apiKeyArg = ctx.argv.apiKey;
|
|
20
|
+
if (apiKeyArg) {
|
|
21
|
+
const spin$1 = ui.spinner();
|
|
22
|
+
spin$1.start("Verifying your API key");
|
|
23
|
+
try {
|
|
24
|
+
const session = await loginWithApiKey(apiKeyArg);
|
|
25
|
+
spin$1.stop("Logged in");
|
|
26
|
+
track("login finished", {
|
|
27
|
+
status: "success",
|
|
28
|
+
method: "api_key"
|
|
29
|
+
});
|
|
30
|
+
if (ctx.json) return ctx.output.data(sessionOutput(session));
|
|
31
|
+
ui.success(`Logged in with an API key${session.orgName ? ` · \`${session.orgName}\`` : ""}.`);
|
|
32
|
+
ui.outro("You're all set - run `superwall integrate` to set up your app.");
|
|
33
|
+
} catch (e) {
|
|
34
|
+
spin$1.stop("Login failed");
|
|
35
|
+
track("login finished", {
|
|
36
|
+
status: "error",
|
|
37
|
+
method: "api_key"
|
|
38
|
+
});
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!ctx.interactive) throw new Error("Browser login requires an interactive terminal. Use `superwall login --api-key <key>`.");
|
|
44
|
+
const hooks = onboardingHooks((await scanProject(ctx.installDir).catch(() => null))?.apps[0]);
|
|
45
|
+
const spin = ui.spinner();
|
|
46
|
+
try {
|
|
47
|
+
const session = await performLogin({
|
|
48
|
+
issuer: ctx.argv.host,
|
|
49
|
+
clientId: ctx.argv.clientId,
|
|
50
|
+
onVerify: ({ url, userCode }) => {
|
|
51
|
+
ui.info(`Approve this login in your browser · code \`${userCode}\`\n${url}`);
|
|
52
|
+
spin.start("Waiting for you to approve in the browser");
|
|
53
|
+
},
|
|
54
|
+
onStatus: (m) => spin.message(m),
|
|
55
|
+
onOnboard: async () => {
|
|
56
|
+
const setup = await hooks.onOnboard();
|
|
57
|
+
if (setup) spin.start("Creating your account");
|
|
58
|
+
return setup;
|
|
59
|
+
},
|
|
60
|
+
onProvisioned: hooks.onProvisioned
|
|
61
|
+
});
|
|
62
|
+
spin.stop(`Logged in as \`${session.userEmail ?? "you"}\`${session.orgName ? ` · \`${session.orgName}\`` : ""}`);
|
|
63
|
+
track("login finished", {
|
|
64
|
+
status: "success",
|
|
65
|
+
method: "oauth"
|
|
66
|
+
});
|
|
67
|
+
if (!ctx.json) await ensureSkillsCurrent(false, "login").catch(() => {});
|
|
68
|
+
ui.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.");
|
|
69
|
+
} catch (e) {
|
|
70
|
+
spin.stop("Login failed");
|
|
71
|
+
track("login finished", {
|
|
72
|
+
status: "error",
|
|
73
|
+
method: "oauth"
|
|
74
|
+
});
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const runLogout = defineCommand({
|
|
80
|
+
name: "logout",
|
|
81
|
+
output: "both",
|
|
82
|
+
async run(ctx) {
|
|
83
|
+
const s = loadSession();
|
|
84
|
+
if (ctx.json) {
|
|
85
|
+
clearSession();
|
|
86
|
+
return ctx.output.data({
|
|
87
|
+
loggedOut: Boolean(s),
|
|
88
|
+
account: s ? sessionOutput(s) : null
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (!s) return void ctx.ui.error("You aren't logged in yet.");
|
|
92
|
+
if (ctx.interactive) {
|
|
93
|
+
if (!await ctx.ui.confirm({ message: `Log out of Superwall${s.userEmail ? ` (\`${s.userEmail}\`)` : ""}?` })) return void ctx.ui.outro("Staying logged in.");
|
|
94
|
+
}
|
|
95
|
+
clearSession();
|
|
96
|
+
ctx.ui.success(`Logged out${s.userEmail ? ` (${s.userEmail})` : ""}.`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const runWhoami = defineCommand({
|
|
100
|
+
name: "whoami",
|
|
101
|
+
output: "both",
|
|
102
|
+
run(ctx) {
|
|
103
|
+
const s = loadSession();
|
|
104
|
+
if (!s) {
|
|
105
|
+
if (ctx.json) return ctx.output.data({ authenticated: false });
|
|
106
|
+
ctx.ui.error("You aren't logged in yet. Run `superwall login` to sign in.");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (ctx.json) return ctx.output.data(sessionOutput(s));
|
|
110
|
+
const credential = s.apiKey ? `API key sk_…${s.apiKey.slice(-4)}` : s.accessToken ? "OAuth session" : " - ";
|
|
111
|
+
ctx.ui.list({ items: [{
|
|
112
|
+
label: s.userEmail ?? "Logged in",
|
|
113
|
+
meta: s.orgName ? `· ${s.orgName}` : void 0,
|
|
114
|
+
children: [{
|
|
115
|
+
label: credential,
|
|
116
|
+
meta: effectiveHost(s)
|
|
117
|
+
}]
|
|
118
|
+
}] });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
function effectiveHost(session) {
|
|
122
|
+
return process.env.SUPERWALL_API_HOST ?? session.host ?? API_HOST;
|
|
123
|
+
}
|
|
124
|
+
function sessionOutput(session) {
|
|
125
|
+
return {
|
|
126
|
+
authenticated: true,
|
|
127
|
+
user: { email: session.userEmail ?? null },
|
|
128
|
+
organization: {
|
|
129
|
+
id: session.orgId ?? null,
|
|
130
|
+
name: session.orgName ?? null,
|
|
131
|
+
count: session.orgCount ?? 1
|
|
132
|
+
},
|
|
133
|
+
credential: { type: session.apiKey ? "api_key" : session.accessToken ? "oauth" : "unknown" },
|
|
134
|
+
host: effectiveHost(session)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
export { runLogin, runLogout, runWhoami };
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/core/auth/storage.d.ts
|
|
2
|
+
interface Session {
|
|
3
|
+
authMethod?: "oauth" | "api_key";
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
orgId?: string;
|
|
6
|
+
orgName?: string;
|
|
7
|
+
orgCount?: number;
|
|
8
|
+
userEmail?: string;
|
|
9
|
+
host: string;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
accessToken?: string;
|
|
12
|
+
refreshToken?: string;
|
|
13
|
+
accessTokenExpiresAt?: number;
|
|
14
|
+
tokenEndpoint?: string;
|
|
15
|
+
oauthClientId?: string;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/core/auth/errors.d.ts
|
|
19
|
+
declare class NotLoggedInError extends Error {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/core/auth/token.d.ts
|
|
24
|
+
declare function getOAuthAccessToken(): Promise<string | null>;
|
|
25
|
+
declare function resolveAuthToken(session: Session): Promise<{
|
|
26
|
+
token: string;
|
|
27
|
+
session: Session;
|
|
28
|
+
}>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { NotLoggedInError, getOAuthAccessToken, resolveAuthToken };
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { n as allDeps, r as readPackageJson } from "./scan-BQexuUPO.js";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import fg from "fast-glob";
|
|
4
|
+
|
|
5
|
+
//#region src/core/project/billing.ts
|
|
6
|
+
const IGNORE = [
|
|
7
|
+
"**/node_modules/**",
|
|
8
|
+
"**/.git/**",
|
|
9
|
+
"**/Pods/**",
|
|
10
|
+
"**/build/**",
|
|
11
|
+
"**/.build/**",
|
|
12
|
+
"**/dist/**"
|
|
13
|
+
];
|
|
14
|
+
function detectBilling(app) {
|
|
15
|
+
const deps = allDeps(readPackageJson(app.path));
|
|
16
|
+
const inDeps = (names) => names.some((n) => n in deps);
|
|
17
|
+
let revenueCat = inDeps([
|
|
18
|
+
"react-native-purchases",
|
|
19
|
+
"@revenuecat/purchases-js",
|
|
20
|
+
"purchases-capacitor",
|
|
21
|
+
"purchases_flutter"
|
|
22
|
+
]);
|
|
23
|
+
let adapty = inDeps(["react-native-adapty", "adapty_flutter"]);
|
|
24
|
+
let qonversion = inDeps(["react-native-qonversion", "qonversion_flutter"]);
|
|
25
|
+
const manifests = fg.sync([
|
|
26
|
+
"**/Package.resolved",
|
|
27
|
+
"**/Package.swift",
|
|
28
|
+
"**/Project.swift",
|
|
29
|
+
"**/Podfile",
|
|
30
|
+
"**/Podfile.lock",
|
|
31
|
+
"**/project.pbxproj",
|
|
32
|
+
"**/*.gradle",
|
|
33
|
+
"**/*.gradle.kts",
|
|
34
|
+
"**/pubspec.yaml",
|
|
35
|
+
"**/pubspec.lock"
|
|
36
|
+
], {
|
|
37
|
+
cwd: app.path,
|
|
38
|
+
ignore: IGNORE,
|
|
39
|
+
absolute: true,
|
|
40
|
+
deep: 5
|
|
41
|
+
});
|
|
42
|
+
for (const f of manifests) {
|
|
43
|
+
let c;
|
|
44
|
+
try {
|
|
45
|
+
c = readFileSync(f, "utf8");
|
|
46
|
+
} catch {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (/RevenueCat|\bPurchases\b/i.test(c)) revenueCat = true;
|
|
50
|
+
if (/Adapty/i.test(c)) adapty = true;
|
|
51
|
+
if (/Qonversion/i.test(c)) qonversion = true;
|
|
52
|
+
}
|
|
53
|
+
if (!revenueCat || !adapty || !qonversion) {
|
|
54
|
+
const sources = fg.sync(["**/*.swift", "**/*.kt"], {
|
|
55
|
+
cwd: app.path,
|
|
56
|
+
ignore: IGNORE,
|
|
57
|
+
absolute: true,
|
|
58
|
+
deep: 6
|
|
59
|
+
}).slice(0, 600);
|
|
60
|
+
for (const f of sources) {
|
|
61
|
+
let c;
|
|
62
|
+
try {
|
|
63
|
+
c = readFileSync(f, "utf8");
|
|
64
|
+
} catch {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (/import RevenueCat|com\.revenuecat/.test(c)) revenueCat = true;
|
|
68
|
+
if (/import Adapty|com\.adapty/.test(c)) adapty = true;
|
|
69
|
+
if (/import Qonversion|com\.qonversion/.test(c)) qonversion = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
revenueCat,
|
|
74
|
+
adapty,
|
|
75
|
+
qonversion
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { detectBilling as t };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { T as Integration } from "./telemetry-CcfrtXdf.js";
|
|
2
|
+
import { n as ui } from "./ui-C4ncRJqd.js";
|
|
3
|
+
import { m as listProjects, n as createApplication, s as createProject, y as platformLabel } from "./resources-CVrWwA1K.js";
|
|
4
|
+
import { t as requireOrg } from "./org-B2gy9Pmu.js";
|
|
5
|
+
|
|
6
|
+
//#region src/core/account/bind.ts
|
|
7
|
+
const NEW = "__new__";
|
|
8
|
+
const NEW_PROJECT = "__new_project__";
|
|
9
|
+
const BACK = "esc back";
|
|
10
|
+
const CANCEL = "esc cancel";
|
|
11
|
+
function platformForIntegration(integration) {
|
|
12
|
+
switch (integration) {
|
|
13
|
+
case Integration.swift: return "ios";
|
|
14
|
+
case Integration.flutter: return "flutter";
|
|
15
|
+
case Integration.expo:
|
|
16
|
+
case Integration.reactNative: return "react_native";
|
|
17
|
+
case Integration.web: return "web";
|
|
18
|
+
default: return "ios";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function resolveAppBinding(api, opts) {
|
|
22
|
+
const projects = await loading("Loading your projects", () => listProjects(api));
|
|
23
|
+
let lastProjectId;
|
|
24
|
+
for (;;) {
|
|
25
|
+
const project = await pickProject(api, projects, opts.appName, lastProjectId);
|
|
26
|
+
if (project === "cancel") return null;
|
|
27
|
+
lastProjectId = String(project.id);
|
|
28
|
+
const app = await pickApp(api, project, opts);
|
|
29
|
+
if (app === "back") continue;
|
|
30
|
+
if (!app.public_api_key) {
|
|
31
|
+
ui.warn(`\`${app.name ?? app.id}\` has no SDK key yet - pick another or add a new app.`);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
apiKey: app.public_api_key,
|
|
36
|
+
app,
|
|
37
|
+
projectId: String(project.id),
|
|
38
|
+
applicationId: String(app.id)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function resolveScopeFromKey(api, publicApiKey) {
|
|
43
|
+
if (!publicApiKey) return null;
|
|
44
|
+
const projects = await listProjects(api);
|
|
45
|
+
for (const project of projects) {
|
|
46
|
+
const app = (project.applications ?? []).find((a) => a.public_api_key === publicApiKey);
|
|
47
|
+
if (app) return {
|
|
48
|
+
projectId: String(project.id),
|
|
49
|
+
applicationId: String(app.id),
|
|
50
|
+
appName: app.name,
|
|
51
|
+
bundleId: app.bundle_id
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
async function pickProject(api, projects, defaultName, preselect) {
|
|
57
|
+
for (;;) {
|
|
58
|
+
if (projects.length === 0) {
|
|
59
|
+
const created = await createProjectFlow(api, defaultName);
|
|
60
|
+
return created === "back" ? "cancel" : created;
|
|
61
|
+
}
|
|
62
|
+
const sel = await ui.select({
|
|
63
|
+
message: "Which Superwall project?",
|
|
64
|
+
options: [...projects.map((p) => ({
|
|
65
|
+
value: String(p.id),
|
|
66
|
+
label: p.name ?? String(p.id),
|
|
67
|
+
hint: appCountHint(p)
|
|
68
|
+
})), {
|
|
69
|
+
value: NEW,
|
|
70
|
+
label: "+ Create a new project"
|
|
71
|
+
}],
|
|
72
|
+
initialValue: preselect ?? String(projects[0].id),
|
|
73
|
+
footer: CANCEL,
|
|
74
|
+
transient: true
|
|
75
|
+
});
|
|
76
|
+
if (sel === null) return "cancel";
|
|
77
|
+
if (sel === NEW) {
|
|
78
|
+
const created = await createProjectFlow(api, defaultName);
|
|
79
|
+
if (created === "back") continue;
|
|
80
|
+
return created;
|
|
81
|
+
}
|
|
82
|
+
return projects.find((p) => String(p.id) === sel);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function pickApp(api, project, opts) {
|
|
86
|
+
for (;;) {
|
|
87
|
+
const apps = project.applications ?? [];
|
|
88
|
+
const label = platformLabel(opts.platform);
|
|
89
|
+
if (apps.length === 0) {
|
|
90
|
+
if (await ui.select({
|
|
91
|
+
message: `No apps in \`${project.name ?? "this project"}\` yet.`,
|
|
92
|
+
options: [{
|
|
93
|
+
value: NEW,
|
|
94
|
+
label: `+ Create a new ${label} app`,
|
|
95
|
+
hint: opts.appName
|
|
96
|
+
}],
|
|
97
|
+
initialValue: NEW,
|
|
98
|
+
footer: BACK,
|
|
99
|
+
transient: true
|
|
100
|
+
}) === null) return "back";
|
|
101
|
+
const created = await createAppFlow(api, project, opts);
|
|
102
|
+
if (created === "back") continue;
|
|
103
|
+
return created;
|
|
104
|
+
}
|
|
105
|
+
const platformTaken = apps.some((a) => a.platform === opts.platform);
|
|
106
|
+
const match = apps.find((a) => a.platform === opts.platform) ?? apps[0];
|
|
107
|
+
const options = apps.map((a) => ({
|
|
108
|
+
value: String(a.id),
|
|
109
|
+
label: a.name ?? String(a.id),
|
|
110
|
+
hint: [platformLabel(a.platform), a.bundle_id].filter(Boolean).join(" · "),
|
|
111
|
+
disabled: a.platform !== opts.platform
|
|
112
|
+
}));
|
|
113
|
+
options.push(platformTaken ? {
|
|
114
|
+
value: NEW_PROJECT,
|
|
115
|
+
label: `+ New project with its own ${label} app`
|
|
116
|
+
} : {
|
|
117
|
+
value: NEW,
|
|
118
|
+
label: `+ Add a new ${label} app`
|
|
119
|
+
});
|
|
120
|
+
const sel = await ui.select({
|
|
121
|
+
message: `Which app in \`${project.name ?? "this project"}\`?`,
|
|
122
|
+
options,
|
|
123
|
+
initialValue: String(match.id),
|
|
124
|
+
footer: BACK,
|
|
125
|
+
transient: true
|
|
126
|
+
});
|
|
127
|
+
if (sel === null) return "back";
|
|
128
|
+
if (sel === NEW) {
|
|
129
|
+
const created = await createAppFlow(api, project, opts);
|
|
130
|
+
if (created === "back") continue;
|
|
131
|
+
return created;
|
|
132
|
+
}
|
|
133
|
+
if (sel === NEW_PROJECT) {
|
|
134
|
+
const fresh = await createProjectFlow(api, opts.appName);
|
|
135
|
+
if (fresh === "back") continue;
|
|
136
|
+
const created = await createAppFlow(api, fresh, opts);
|
|
137
|
+
if (created === "back") continue;
|
|
138
|
+
return created;
|
|
139
|
+
}
|
|
140
|
+
return apps.find((a) => String(a.id) === sel);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function createProjectFlow(api, defaultName) {
|
|
144
|
+
await requireOrg(api, true);
|
|
145
|
+
const name = await ui.text({
|
|
146
|
+
message: "Name your new project",
|
|
147
|
+
placeholder: defaultName,
|
|
148
|
+
validate: (v) => v?.trim() ? void 0 : "Required",
|
|
149
|
+
footer: BACK,
|
|
150
|
+
transient: true
|
|
151
|
+
});
|
|
152
|
+
if (name === null) return "back";
|
|
153
|
+
const created = await loading("Creating project", () => createProject(api, name.trim()));
|
|
154
|
+
ui.success(`Created project \`${created.name ?? name.trim()}\``);
|
|
155
|
+
return {
|
|
156
|
+
id: created.id,
|
|
157
|
+
name: created.name ?? name.trim(),
|
|
158
|
+
applications: []
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
async function createAppFlow(api, project, opts) {
|
|
162
|
+
const label = platformLabel(opts.platform);
|
|
163
|
+
for (;;) {
|
|
164
|
+
const name = await ui.text({
|
|
165
|
+
message: `Name the ${label} app`,
|
|
166
|
+
placeholder: opts.appName,
|
|
167
|
+
initialValue: opts.appName,
|
|
168
|
+
validate: (v) => v?.trim() ? void 0 : "Required",
|
|
169
|
+
footer: BACK,
|
|
170
|
+
transient: true
|
|
171
|
+
});
|
|
172
|
+
if (name === null) return "back";
|
|
173
|
+
const bundle = await ui.text({
|
|
174
|
+
message: "Bundle id / package name (optional)",
|
|
175
|
+
placeholder: opts.bundleId ?? "com.company.app",
|
|
176
|
+
footer: "enter to skip · esc back",
|
|
177
|
+
transient: true
|
|
178
|
+
});
|
|
179
|
+
if (bundle === null) continue;
|
|
180
|
+
const bundleId = bundle.trim() || opts.bundleId;
|
|
181
|
+
const parent = await loading(`Adding the ${label} app`, () => createApplication(api, { projectId: String(project.id) }, {
|
|
182
|
+
name: name.trim(),
|
|
183
|
+
platform: opts.platform,
|
|
184
|
+
bundleId
|
|
185
|
+
}));
|
|
186
|
+
const created = parent.applications?.find((a) => a.name === name.trim() && a.platform === opts.platform) ?? parent.applications?.find((a) => a.platform === opts.platform) ?? parent.applications?.at(-1);
|
|
187
|
+
if (!created) {
|
|
188
|
+
ui.warn("The app was created but its key didn't come back - try again.");
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
ui.success(`Added ${label} app \`${created.name ?? name.trim()}\``);
|
|
192
|
+
return created;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function appCountHint(p) {
|
|
196
|
+
const n = (p.applications ?? []).length;
|
|
197
|
+
return `${n} app${n === 1 ? "" : "s"}`;
|
|
198
|
+
}
|
|
199
|
+
async function loading(label, work) {
|
|
200
|
+
const spin = ui.spinner();
|
|
201
|
+
spin.start(label);
|
|
202
|
+
try {
|
|
203
|
+
const result = await work();
|
|
204
|
+
spin.stop(label);
|
|
205
|
+
return result;
|
|
206
|
+
} catch (e) {
|
|
207
|
+
spin.stop("Failed");
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
export { resolveAppBinding as n, resolveScopeFromKey as r, platformForIntegration as t };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJS = (cb, mod) => function() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { __require as n, __toESM as r, __commonJS as t };
|