@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,205 @@
|
|
|
1
|
+
import { _ as setSkillsSync, f as getSkillsSync, i as track, k as VERSION } from "./telemetry-CcfrtXdf.js";
|
|
2
|
+
import { n as ui } from "./ui-C4ncRJqd.js";
|
|
3
|
+
import { r as spawnStream } from "./spawn-DSoTXy_j.js";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
//#region src/util/assets.ts
|
|
9
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
let root;
|
|
11
|
+
/** The package root: nearest ancestor with a package.json (repo in dev, install dir in prod). */
|
|
12
|
+
function packageRoot() {
|
|
13
|
+
if (root) return root;
|
|
14
|
+
let dir = moduleDir;
|
|
15
|
+
while (!existsSync(join(dir, "package.json"))) {
|
|
16
|
+
const parent = dirname(dir);
|
|
17
|
+
if (parent === dir) break;
|
|
18
|
+
dir = parent;
|
|
19
|
+
}
|
|
20
|
+
return root = dir;
|
|
21
|
+
}
|
|
22
|
+
/** Locate a directory shipped with the package. */
|
|
23
|
+
function packagedDir(name) {
|
|
24
|
+
return join(packageRoot(), name) + "/";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/core/agent/skills.ts
|
|
29
|
+
const cache = /* @__PURE__ */ new Map();
|
|
30
|
+
function bundledSkillsDir() {
|
|
31
|
+
return packagedDir("skills").replace(/\/$/, "");
|
|
32
|
+
}
|
|
33
|
+
/** SKILL.md body, plus references/<name>.md for each given reference (framework/provider depth). */
|
|
34
|
+
function loadBundledSkill(id, reference) {
|
|
35
|
+
const refs = (Array.isArray(reference) ? reference : [reference]).filter((r) => !!r);
|
|
36
|
+
const key = refs.length ? `${id}#${refs.join("+")}` : id;
|
|
37
|
+
const cached = cache.get(key);
|
|
38
|
+
if (cached !== void 0) return cached;
|
|
39
|
+
const body = [readSkillFile(`${id}/SKILL.md`), ...refs.map((r) => readSkillFile(`${id}/references/${r}.md`))].filter(Boolean).join("\n\n");
|
|
40
|
+
cache.set(key, body);
|
|
41
|
+
return body;
|
|
42
|
+
}
|
|
43
|
+
function readSkillFile(rel) {
|
|
44
|
+
try {
|
|
45
|
+
return stripFrontmatter(readFileSync(`${packagedDir("skills")}${rel}`, "utf8")).trim();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error(`Bundled skill asset is missing: ${rel}`, { cause: error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function stripFrontmatter(md) {
|
|
51
|
+
const lines = md.split("\n");
|
|
52
|
+
if (lines[0]?.trim() === "---") {
|
|
53
|
+
const end = lines.indexOf("---", 1);
|
|
54
|
+
if (end > 0) return lines.slice(end + 1).join("\n");
|
|
55
|
+
}
|
|
56
|
+
return md;
|
|
57
|
+
}
|
|
58
|
+
const SUPERWALL_SKILLS_SOURCE = "superwall/skills";
|
|
59
|
+
const KNOWN_SKILLS = [{
|
|
60
|
+
name: "superwall",
|
|
61
|
+
summary: "Resources, ClickHouse SQL analytics, docs, SDK triage, and dashboard links"
|
|
62
|
+
}, {
|
|
63
|
+
name: "superwall-editor",
|
|
64
|
+
summary: "Build and edit live paywalls, onboarding, and web2app flows from the CLI"
|
|
65
|
+
}];
|
|
66
|
+
async function fetchPublicSkills() {
|
|
67
|
+
try {
|
|
68
|
+
const res = await fetch(`https://api.github.com/repos/${SUPERWALL_SKILLS_SOURCE}/contents/skills`, {
|
|
69
|
+
headers: { accept: "application/vnd.github+json" },
|
|
70
|
+
signal: AbortSignal.timeout(6e3)
|
|
71
|
+
});
|
|
72
|
+
if (!res.ok) return KNOWN_SKILLS;
|
|
73
|
+
const dirs = (await res.json()).filter((e) => e.type === "dir").map((e) => e.name);
|
|
74
|
+
if (dirs.length === 0) return KNOWN_SKILLS;
|
|
75
|
+
return (await Promise.all(dirs.map(async (name) => ({
|
|
76
|
+
name,
|
|
77
|
+
summary: await fetchSkillSummary(name)
|
|
78
|
+
})))).sort((a, b) => a.name === "superwall" ? -1 : b.name === "superwall" ? 1 : a.name.localeCompare(b.name));
|
|
79
|
+
} catch {
|
|
80
|
+
return KNOWN_SKILLS;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function fetchSkillSummary(name) {
|
|
84
|
+
try {
|
|
85
|
+
const res = await fetch(`https://raw.githubusercontent.com/${SUPERWALL_SKILLS_SOURCE}/main/skills/${name}/SKILL.md`, { signal: AbortSignal.timeout(6e3) });
|
|
86
|
+
if (!res.ok) return "";
|
|
87
|
+
const description = ((await res.text()).match(/^description:\s*(.+)$/m)?.[1] ?? "").trim().replace(/^["']|["'`]+$/g, "");
|
|
88
|
+
const firstSentence = description.split(/(?<=\.)\s/)[0] ?? description;
|
|
89
|
+
return firstSentence.length > 64 ? `${firstSentence.slice(0, 61)}...` : firstSentence;
|
|
90
|
+
} catch {
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function installPublicSkills(opts = {}) {
|
|
95
|
+
const args = [
|
|
96
|
+
"-y",
|
|
97
|
+
"skills@latest",
|
|
98
|
+
"add",
|
|
99
|
+
SUPERWALL_SKILLS_SOURCE,
|
|
100
|
+
"--global",
|
|
101
|
+
"--yes"
|
|
102
|
+
];
|
|
103
|
+
if (opts.skills?.length) args.push("--skill", ...opts.skills);
|
|
104
|
+
else args.push("--skill", "*");
|
|
105
|
+
return runInstall(args, opts);
|
|
106
|
+
}
|
|
107
|
+
async function installBundledSkills(opts = {}) {
|
|
108
|
+
return runInstall([
|
|
109
|
+
"-y",
|
|
110
|
+
"skills@latest",
|
|
111
|
+
"add",
|
|
112
|
+
bundledSkillsDir(),
|
|
113
|
+
"--global",
|
|
114
|
+
"--yes",
|
|
115
|
+
"--copy"
|
|
116
|
+
], opts);
|
|
117
|
+
}
|
|
118
|
+
async function runInstall(args, opts) {
|
|
119
|
+
const command = `npx ${args.join(" ")}`;
|
|
120
|
+
if (opts.dryRun) return {
|
|
121
|
+
ok: true,
|
|
122
|
+
command
|
|
123
|
+
};
|
|
124
|
+
const { code } = await spawnStream({
|
|
125
|
+
bin: "npx",
|
|
126
|
+
args,
|
|
127
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
128
|
+
onStdoutLine: (line) => opts.onProgress?.(line),
|
|
129
|
+
onStderrLine: (line) => opts.onProgress?.(line)
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
ok: code === 0,
|
|
133
|
+
command
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const SHA_CHECK_INTERVAL_MS = 1440 * 60 * 1e3;
|
|
137
|
+
function checkSkillsSync(sync, cliVersion, now) {
|
|
138
|
+
if (!sync || sync.cliVersion !== cliVersion) return "stale";
|
|
139
|
+
const syncedAt = Date.parse(sync.syncedAt);
|
|
140
|
+
if (!Number.isFinite(syncedAt)) return "stale";
|
|
141
|
+
return now - syncedAt > SHA_CHECK_INTERVAL_MS ? "verify" : "fresh";
|
|
142
|
+
}
|
|
143
|
+
async function fetchSourceSha() {
|
|
144
|
+
try {
|
|
145
|
+
const res = await fetch(`https://api.github.com/repos/${SUPERWALL_SKILLS_SOURCE}/commits/main`, {
|
|
146
|
+
headers: { accept: "application/vnd.github+json" },
|
|
147
|
+
signal: AbortSignal.timeout(6e3)
|
|
148
|
+
});
|
|
149
|
+
if (!res.ok) return null;
|
|
150
|
+
const { sha } = await res.json();
|
|
151
|
+
return sha ?? null;
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function skillsOutOfDate() {
|
|
157
|
+
const sync = getSkillsSync();
|
|
158
|
+
const check = checkSkillsSync(sync, VERSION, Date.now());
|
|
159
|
+
if (check === "stale") return true;
|
|
160
|
+
if (check === "fresh" || !sync) return false;
|
|
161
|
+
const head = await fetchSourceSha();
|
|
162
|
+
if (!head) return false;
|
|
163
|
+
if (head !== sync.sourceSha) return true;
|
|
164
|
+
setSkillsSync({
|
|
165
|
+
...sync,
|
|
166
|
+
syncedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
167
|
+
});
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
async function syncSkills(opts = {}) {
|
|
171
|
+
const pub = await installPublicSkills(opts);
|
|
172
|
+
const bundled = await installBundledSkills(opts);
|
|
173
|
+
const ok = pub.ok && bundled.ok;
|
|
174
|
+
if (!opts.dryRun) {
|
|
175
|
+
track("skills synced", {
|
|
176
|
+
trigger: opts.trigger ?? "manual",
|
|
177
|
+
ok
|
|
178
|
+
});
|
|
179
|
+
if (ok) setSkillsSync({
|
|
180
|
+
cliVersion: VERSION,
|
|
181
|
+
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
182
|
+
sourceSha: await fetchSourceSha() ?? void 0
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
ok,
|
|
187
|
+
commands: [pub.command, bundled.command]
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Install or refresh the skills with a spinner. `required` always installs and
|
|
192
|
+
* throws on failure (fresh integrations must ship with skills); otherwise this
|
|
193
|
+
* is a quiet refresh that no-ops when the last sync is current.
|
|
194
|
+
*/
|
|
195
|
+
async function ensureSkillsCurrent(required = false, trigger = "workflow") {
|
|
196
|
+
if (!required && !await skillsOutOfDate()) return;
|
|
197
|
+
const spin = ui.spinner();
|
|
198
|
+
spin.start(required ? "Installing Superwall skills for your agent" : "Updating Superwall skills");
|
|
199
|
+
const { ok } = await syncSkills({ trigger });
|
|
200
|
+
spin.stop(ok ? required ? "Superwall skills installed" : "Superwall skills up to date" : "Skill install skipped");
|
|
201
|
+
if (required && !ok) throw new Error("The integration completed, but the Superwall skills could not be installed.");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//#endregion
|
|
205
|
+
export { skillsOutOfDate as a, loadBundledSkill as i, ensureSkillsCurrent as n, syncSkills as o, fetchPublicSkills as r, packagedDir as s, SUPERWALL_SKILLS_SOURCE as t };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { promisify } from "node:util";
|
|
2
|
+
import { appendFileSync } from "node:fs";
|
|
3
|
+
import { execFile, spawn } from "node:child_process";
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
|
|
6
|
+
//#region src/core/agent/drivers/spawn.ts
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
const TRANSCRIPT = process.env.SW_BENCH_TRANSCRIPT;
|
|
9
|
+
function sink(line) {
|
|
10
|
+
if (!TRANSCRIPT) return;
|
|
11
|
+
try {
|
|
12
|
+
appendFileSync(TRANSCRIPT, line + "\n");
|
|
13
|
+
} catch {}
|
|
14
|
+
}
|
|
15
|
+
async function readVersion(bin) {
|
|
16
|
+
try {
|
|
17
|
+
const { stdout } = await execFileAsync(bin, ["--version"], { timeout: 5e3 });
|
|
18
|
+
return stdout.trim().split("\n")[0];
|
|
19
|
+
} catch {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function onPath(bin) {
|
|
24
|
+
const probe = process.platform === "win32" ? "where" : "command";
|
|
25
|
+
const args = process.platform === "win32" ? [bin] : ["-v", bin];
|
|
26
|
+
try {
|
|
27
|
+
await execFileAsync(probe, args, {
|
|
28
|
+
timeout: 5e3,
|
|
29
|
+
shell: process.platform !== "win32"
|
|
30
|
+
});
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function spawnStream(opts) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const child = spawn(opts.bin, opts.args, {
|
|
39
|
+
cwd: opts.cwd,
|
|
40
|
+
env: opts.env ?? process.env,
|
|
41
|
+
signal: opts.signal,
|
|
42
|
+
stdio: [
|
|
43
|
+
"ignore",
|
|
44
|
+
"pipe",
|
|
45
|
+
"pipe"
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
createInterface({ input: child.stdout }).on("line", (line) => {
|
|
49
|
+
if (line.length) {
|
|
50
|
+
sink(line);
|
|
51
|
+
opts.onStdoutLine(line);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (opts.onStderrLine && child.stderr) createInterface({ input: child.stderr }).on("line", (line) => {
|
|
55
|
+
if (line.length) opts.onStderrLine(line);
|
|
56
|
+
});
|
|
57
|
+
child.on("error", (e) => {
|
|
58
|
+
if (e.name === "AbortError") {
|
|
59
|
+
resolve({ code: null });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
reject(e);
|
|
63
|
+
});
|
|
64
|
+
child.on("close", (code) => resolve({ code }));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { readVersion as n, spawnStream as r, onPath as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { n as ui } from "./ui-C4ncRJqd.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ui/spinner.ts
|
|
4
|
+
async function withSpinner(label, work) {
|
|
5
|
+
const spin = ui.spinner();
|
|
6
|
+
spin.start(label);
|
|
7
|
+
try {
|
|
8
|
+
const result = await work();
|
|
9
|
+
spin.stop(label);
|
|
10
|
+
return result;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
spin.stop("Failed");
|
|
13
|
+
throw e;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { withSpinner as t };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/core/dashboard/storekit.ts
|
|
2
|
+
function generateStoreKit(products) {
|
|
3
|
+
return {
|
|
4
|
+
identifier: "SUPERWALL",
|
|
5
|
+
nonRenewingSubscriptions: [],
|
|
6
|
+
products: products.map((p) => String(p.identifier ?? p.product_identifier ?? p.name ?? "")).filter(Boolean).map((id, i) => ({
|
|
7
|
+
displayPrice: "9.99",
|
|
8
|
+
familyShareable: false,
|
|
9
|
+
internalID: String(1e3 + i),
|
|
10
|
+
localizations: [{
|
|
11
|
+
description: id,
|
|
12
|
+
displayName: id,
|
|
13
|
+
locale: "en_US"
|
|
14
|
+
}],
|
|
15
|
+
productID: id,
|
|
16
|
+
referenceName: id,
|
|
17
|
+
type: "NonConsumable"
|
|
18
|
+
})),
|
|
19
|
+
settings: { _applicationInternalID: "SUPERWALL" },
|
|
20
|
+
subscriptionGroups: [],
|
|
21
|
+
version: {
|
|
22
|
+
major: 3,
|
|
23
|
+
minor: 0
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { generateStoreKit as t };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { t as formatJson } from "./json-C3hPIMkI.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
//#region package.json
|
|
8
|
+
var version = "1.1.0";
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/constants.ts
|
|
12
|
+
const VERSION = version;
|
|
13
|
+
const DASHBOARD_URL = "https://superwall.com/dashboard";
|
|
14
|
+
const ENV_API_KEY = "SUPERWALL_API_KEY";
|
|
15
|
+
const AUTH_HOST = process.env.SUPERWALL_AUTH_HOST ?? "https://auth.superwall.com";
|
|
16
|
+
const ASSET_HOST = process.env.SUPERWALL_ASSET_HOST ?? "https://user-content.superwalleditor.com/user-content/hl";
|
|
17
|
+
const API_HOST = process.env.SUPERWALL_API_HOST ?? "https://api.superwall.com";
|
|
18
|
+
const CLI_CLIENT_ID = process.env.SUPERWALL_CLI_CLIENT_ID ?? "client_01KWEWM154D2T28NZAS02B8MWT";
|
|
19
|
+
const OAUTH_SCOPE = "openid profile email offline_access";
|
|
20
|
+
const TELEMETRY_HOST = process.env.SUPERWALL_TELEMETRY_HOST ?? "https://us.i.posthog.com";
|
|
21
|
+
const TELEMETRY_KEY = process.env.SUPERWALL_TELEMETRY_KEY ?? "phc_obWpK8cuSfhNkZUKmDByATHp928RHPRD5DoMEDreAHS6";
|
|
22
|
+
let Integration = /* @__PURE__ */ function(Integration$1) {
|
|
23
|
+
Integration$1["swift"] = "swift";
|
|
24
|
+
Integration$1["expo"] = "expo";
|
|
25
|
+
Integration$1["reactNative"] = "react-native";
|
|
26
|
+
Integration$1["flutter"] = "flutter";
|
|
27
|
+
Integration$1["web"] = "web";
|
|
28
|
+
return Integration$1;
|
|
29
|
+
}({});
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/core/state/config.ts
|
|
33
|
+
function dir() {
|
|
34
|
+
return join(homedir(), ".superwall");
|
|
35
|
+
}
|
|
36
|
+
function file() {
|
|
37
|
+
return join(dir(), "config.json");
|
|
38
|
+
}
|
|
39
|
+
function read() {
|
|
40
|
+
try {
|
|
41
|
+
return existsSync(file()) ? JSON.parse(readFileSync(file(), "utf8")) : {};
|
|
42
|
+
} catch {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function write(config) {
|
|
47
|
+
mkdirSync(dir(), {
|
|
48
|
+
recursive: true,
|
|
49
|
+
mode: 448
|
|
50
|
+
});
|
|
51
|
+
writeFileSync(file(), `${formatJson(config)}\n`, { mode: 384 });
|
|
52
|
+
}
|
|
53
|
+
function getDefaultApp(projectId) {
|
|
54
|
+
return read().defaultApp?.[projectId];
|
|
55
|
+
}
|
|
56
|
+
function setDefaultApp(projectId, applicationId) {
|
|
57
|
+
const config = read();
|
|
58
|
+
config.defaultApp = {
|
|
59
|
+
...config.defaultApp ?? {},
|
|
60
|
+
[projectId]: applicationId
|
|
61
|
+
};
|
|
62
|
+
write(config);
|
|
63
|
+
}
|
|
64
|
+
function getSkillsSync() {
|
|
65
|
+
return read().skillsSync;
|
|
66
|
+
}
|
|
67
|
+
function setSkillsSync(sync) {
|
|
68
|
+
const config = read();
|
|
69
|
+
config.skillsSync = sync;
|
|
70
|
+
write(config);
|
|
71
|
+
}
|
|
72
|
+
function getAnonymousId() {
|
|
73
|
+
const config = read();
|
|
74
|
+
if (config.telemetry?.anonymousId) return config.telemetry.anonymousId;
|
|
75
|
+
const anonymousId = randomUUID();
|
|
76
|
+
config.telemetry = {
|
|
77
|
+
...config.telemetry,
|
|
78
|
+
anonymousId
|
|
79
|
+
};
|
|
80
|
+
write(config);
|
|
81
|
+
return anonymousId;
|
|
82
|
+
}
|
|
83
|
+
function getOnboardedOrg() {
|
|
84
|
+
return read().onboarded?.org;
|
|
85
|
+
}
|
|
86
|
+
function setOnboardedOrg(org) {
|
|
87
|
+
const config = read();
|
|
88
|
+
config.onboarded = {
|
|
89
|
+
...config.onboarded,
|
|
90
|
+
org
|
|
91
|
+
};
|
|
92
|
+
write(config);
|
|
93
|
+
}
|
|
94
|
+
function getOnboardedApp(appPath) {
|
|
95
|
+
return read().onboarded?.apps?.[appPath];
|
|
96
|
+
}
|
|
97
|
+
function setOnboardedApp(appPath, app) {
|
|
98
|
+
const config = read();
|
|
99
|
+
config.onboarded = {
|
|
100
|
+
...config.onboarded,
|
|
101
|
+
apps: {
|
|
102
|
+
...config.onboarded?.apps,
|
|
103
|
+
[appPath]: app
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
write(config);
|
|
107
|
+
}
|
|
108
|
+
function getUpdateCheck() {
|
|
109
|
+
return read().updateCheck;
|
|
110
|
+
}
|
|
111
|
+
function setUpdateCheck(check) {
|
|
112
|
+
const config = read();
|
|
113
|
+
config.updateCheck = check;
|
|
114
|
+
write(config);
|
|
115
|
+
}
|
|
116
|
+
function getOnboardingIdempotencyKey() {
|
|
117
|
+
const config = read();
|
|
118
|
+
if (config.onboardingIdempotencyKey) return config.onboardingIdempotencyKey;
|
|
119
|
+
const key = randomUUID();
|
|
120
|
+
config.onboardingIdempotencyKey = key;
|
|
121
|
+
write(config);
|
|
122
|
+
return key;
|
|
123
|
+
}
|
|
124
|
+
function telemetryNoticeShown() {
|
|
125
|
+
return Boolean(read().telemetry?.noticeShown);
|
|
126
|
+
}
|
|
127
|
+
function setTelemetryNoticeShown() {
|
|
128
|
+
const config = read();
|
|
129
|
+
config.telemetry = {
|
|
130
|
+
...config.telemetry,
|
|
131
|
+
noticeShown: true
|
|
132
|
+
};
|
|
133
|
+
write(config);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/util/env.ts
|
|
138
|
+
function apiKeyFromEnv() {
|
|
139
|
+
const v = process.env[ENV_API_KEY];
|
|
140
|
+
return v && v.trim() ? v.trim() : void 0;
|
|
141
|
+
}
|
|
142
|
+
function isNonInteractive() {
|
|
143
|
+
return !process.stdout.isTTY || !process.stdin.isTTY || process.env.CI === "true";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/core/telemetry.ts
|
|
148
|
+
const tags = {};
|
|
149
|
+
const pending = [];
|
|
150
|
+
function setTelemetryTags(next) {
|
|
151
|
+
Object.assign(tags, next);
|
|
152
|
+
}
|
|
153
|
+
function isTelemetryEnabled(env, key) {
|
|
154
|
+
return Boolean(key) && !env.DO_NOT_TRACK && !env.SUPERWALL_TELEMETRY_DISABLED && !env.NODE_TEST_CONTEXT;
|
|
155
|
+
}
|
|
156
|
+
function telemetryEnabled() {
|
|
157
|
+
return isTelemetryEnabled(process.env, TELEMETRY_KEY);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Fully anonymous by design: distinct_id is a random persisted UUID never
|
|
161
|
+
* linked to the logged-in account, properties are enums/booleans/numbers only
|
|
162
|
+
* (no names, paths, or messages), and person profiles are disabled.
|
|
163
|
+
*/
|
|
164
|
+
function buildEvent(event, props, distinctId) {
|
|
165
|
+
return {
|
|
166
|
+
api_key: TELEMETRY_KEY,
|
|
167
|
+
event,
|
|
168
|
+
distinct_id: distinctId,
|
|
169
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
170
|
+
properties: {
|
|
171
|
+
$process_person_profile: false,
|
|
172
|
+
cli_version: VERSION,
|
|
173
|
+
platform: process.platform,
|
|
174
|
+
ci: process.env.CI === "true",
|
|
175
|
+
interactive: !isNonInteractive(),
|
|
176
|
+
...tags,
|
|
177
|
+
...props
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function track(event, props = {}) {
|
|
182
|
+
if (!telemetryEnabled()) return;
|
|
183
|
+
try {
|
|
184
|
+
const payload = buildEvent(event, props, getAnonymousId());
|
|
185
|
+
pending.push(fetch(`${TELEMETRY_HOST}/capture/`, {
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers: { "content-type": "application/json" },
|
|
188
|
+
body: JSON.stringify(payload),
|
|
189
|
+
signal: AbortSignal.timeout(1500)
|
|
190
|
+
}).catch(() => {}));
|
|
191
|
+
} catch {}
|
|
192
|
+
}
|
|
193
|
+
async function flushTelemetry(capMs = 2e3) {
|
|
194
|
+
if (pending.length === 0) return;
|
|
195
|
+
await Promise.race([Promise.allSettled(pending), new Promise((done) => setTimeout(done, capMs).unref())]);
|
|
196
|
+
}
|
|
197
|
+
function maybeShowTelemetryNotice(ui) {
|
|
198
|
+
if (!telemetryEnabled() || telemetryNoticeShown()) return;
|
|
199
|
+
setTelemetryNoticeShown();
|
|
200
|
+
ui.info("The CLI collects anonymous usage data - no personal data, ever (see the README). Opt out with `SUPERWALL_TELEMETRY_DISABLED=1`.");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
export { DASHBOARD_URL as C, TELEMETRY_HOST as D, OAUTH_SCOPE as E, TELEMETRY_KEY as O, CLI_CLIENT_ID as S, Integration as T, setSkillsSync as _, apiKeyFromEnv as a, ASSET_HOST as b, getDefaultApp as c, getOnboardingIdempotencyKey as d, getSkillsSync as f, setOnboardedOrg as g, setOnboardedApp as h, track as i, VERSION as k, getOnboardedApp as l, setDefaultApp as m, maybeShowTelemetryNotice as n, isNonInteractive as o, getUpdateCheck as p, setTelemetryTags as r, getAnonymousId as s, flushTelemetry as t, getOnboardedOrg as u, setUpdateCheck as v, ENV_API_KEY as w, AUTH_HOST as x, API_HOST as y };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { t as formatJson } from "./json-C3hPIMkI.js";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
//#region src/core/auth/errors.ts
|
|
7
|
+
var NotLoggedInError = class extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("You aren't logged in. Run `superwall login` first.");
|
|
10
|
+
this.name = "NotLoggedInError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/core/auth/storage.ts
|
|
16
|
+
function dir() {
|
|
17
|
+
return join(homedir(), ".superwall");
|
|
18
|
+
}
|
|
19
|
+
function file() {
|
|
20
|
+
return join(dir(), "auth.json");
|
|
21
|
+
}
|
|
22
|
+
function saveSession(session) {
|
|
23
|
+
mkdirSync(dir(), {
|
|
24
|
+
recursive: true,
|
|
25
|
+
mode: 448
|
|
26
|
+
});
|
|
27
|
+
writeFileSync(file(), `${formatJson(session)}\n`, { mode: 384 });
|
|
28
|
+
}
|
|
29
|
+
function loadSession() {
|
|
30
|
+
try {
|
|
31
|
+
if (!existsSync(file())) return null;
|
|
32
|
+
return JSON.parse(readFileSync(file(), "utf8"));
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function clearSession() {
|
|
38
|
+
try {
|
|
39
|
+
rmSync(file(), { force: true });
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/core/auth/token.ts
|
|
45
|
+
const EXPIRY_SKEW_MS = 6e4;
|
|
46
|
+
function accessTokenIsFresh(session) {
|
|
47
|
+
return session.accessTokenExpiresAt !== void 0 && session.accessTokenExpiresAt - EXPIRY_SKEW_MS > Date.now();
|
|
48
|
+
}
|
|
49
|
+
async function refreshAccessToken(session) {
|
|
50
|
+
if (!session.refreshToken || !session.tokenEndpoint || !session.oauthClientId) return null;
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(session.tokenEndpoint, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
55
|
+
body: new URLSearchParams({
|
|
56
|
+
grant_type: "refresh_token",
|
|
57
|
+
refresh_token: session.refreshToken,
|
|
58
|
+
client_id: session.oauthClientId
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
if (!res.ok) return null;
|
|
62
|
+
const d = await res.json();
|
|
63
|
+
if (!d.access_token) return null;
|
|
64
|
+
const updated = {
|
|
65
|
+
...session,
|
|
66
|
+
accessToken: d.access_token,
|
|
67
|
+
refreshToken: d.refresh_token ?? session.refreshToken,
|
|
68
|
+
accessTokenExpiresAt: d.expires_in ? Date.now() + d.expires_in * 1e3 : void 0
|
|
69
|
+
};
|
|
70
|
+
saveSession(updated);
|
|
71
|
+
return updated;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function getOAuthAccessToken() {
|
|
77
|
+
const session = loadSession();
|
|
78
|
+
if (!session?.accessToken || !session.refreshToken) return null;
|
|
79
|
+
if (accessTokenIsFresh(session)) return session.accessToken;
|
|
80
|
+
return (await refreshAccessToken(session))?.accessToken ?? null;
|
|
81
|
+
}
|
|
82
|
+
async function resolveAuthToken(session) {
|
|
83
|
+
if (session.accessToken && session.refreshToken) {
|
|
84
|
+
if (accessTokenIsFresh(session)) return {
|
|
85
|
+
token: session.accessToken,
|
|
86
|
+
session
|
|
87
|
+
};
|
|
88
|
+
const refreshed = await refreshAccessToken(session);
|
|
89
|
+
if (refreshed) return {
|
|
90
|
+
token: refreshed.accessToken,
|
|
91
|
+
session: refreshed
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (session.apiKey) return {
|
|
95
|
+
token: session.apiKey,
|
|
96
|
+
session
|
|
97
|
+
};
|
|
98
|
+
throw new NotLoggedInError();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
export { saveSession as a, loadSession as i, resolveAuthToken as n, NotLoggedInError as o, clearSession as r, getOAuthAccessToken as t };
|