@superwall/cli 1.1.1 → 1.3.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +37 -4
  2. package/dist/{actions-I5gVO5jN.js → actions-DvHycH3X.js} +2 -2
  3. package/dist/{api-emImQnVy.js → api-B50i89j0.js} +9 -9
  4. package/dist/{api-output-B5hh0q4V.js → api-output-D9ggXQIr.js} +1 -1
  5. package/dist/{app-DE9lxNNV.js → app-FiC9SQVp.js} +11 -11
  6. package/dist/asa-B5hrBL3t.js +1194 -0
  7. package/dist/{asc-DYc_Yo9e.js → asc-CRtRYv17.js} +13 -13
  8. package/dist/{auth-Bir_Un8l.js → auth-CYognaF4.js} +10 -10
  9. package/dist/auth.js +2 -2
  10. package/dist/{billing-CW0diI2X.js → billing-CSOUhWso.js} +1 -1
  11. package/dist/{bind-DO11eXrR.js → bind-BbzBenoP.js} +4 -4
  12. package/dist/{command-CmJMNVVz.js → command-B7Te31wp.js} +96 -101
  13. package/dist/{create-CwDgWW16.js → create--Q8nPgoa.js} +18 -18
  14. package/dist/{dev-OnmMOsgK.js → dev-Dr6gXH-o.js} +37 -19
  15. package/dist/{doctor-CpYkDfdC.js → doctor-Cf0qNjbq.js} +10 -10
  16. package/dist/{drivers-Cweb9bWA.js → drivers-ItOmKzrw.js} +2 -2
  17. package/dist/entry.js +531 -279
  18. package/dist/{existing-p-hX-Nxc.js → existing-B-e22WOr.js} +2 -2
  19. package/dist/{feedback-CV4JnRuk.js → feedback-C3UtAxye.js} +9 -9
  20. package/dist/{git-BrTxQ7ui.js → git-2wRxiwOc.js} +10 -10
  21. package/dist/{hosted-CbNJSJAC.js → hosted-vk05ZF6w.js} +3 -3
  22. package/dist/{integrate-DOLvHr1D.js → integrate-Cv8r_i2l.js} +30 -29
  23. package/dist/{login-B7fSpJKc.js → login-DOES7Kup.js} +8 -7
  24. package/dist/{migrate-Bn5btm_H.js → migrate-C7R29RPH.js} +20 -20
  25. package/dist/{org-B2gy9Pmu.js → org-Cg25bcsj.js} +3 -3
  26. package/dist/output-D2Ax_hHL.js +123 -0
  27. package/dist/{params-Bvq0iqQK.js → params-B1zeElGa.js} +1 -2
  28. package/dist/{pipeline-COr4sB6U.js → pipeline-BVeUA6Ig.js} +106 -173
  29. package/dist/{print-skill-D0j2D6tw.js → print-skill-D-R81bno.js} +7 -7
  30. package/dist/{promote-UmKZySRx.js → promote-CV_Lsmqd.js} +18 -18
  31. package/dist/publish-CSnNvHHi.js +35 -0
  32. package/dist/push-sjnRI6iL.js +35 -0
  33. package/dist/{query-CbGfXmKu.js → query-CdcWSinl.js} +10 -10
  34. package/dist/{resource-m6yz1jwE.js → resource-PVg0uzSK.js} +14 -14
  35. package/dist/{resources-CVrWwA1K.js → resources-s64mBHaC.js} +1 -0
  36. package/dist/{run-BTLaOoKK.js → run-XIkrFIgw.js} +2 -2
  37. package/dist/{scan-BfoeYW1v.js → scan-Dk0ZlCY6.js} +2 -2
  38. package/dist/{skills-HlIKA9xR.js → skills-B-mR2CqM.js} +4 -3
  39. package/dist/{skills-C4Yzl64N.js → skills-CoEIW0mE.js} +8 -8
  40. package/dist/{spinner-gOxIMz-V.js → spinner-B9dT3DBY.js} +1 -1
  41. package/dist/{telemetry-CLi7mjDP.js → telemetry-yJs7t0rt.js} +6 -41
  42. package/dist/{token-DHRH8cxi.js → token-GcbyH6G8.js} +2 -2
  43. package/dist/{ui-C4ncRJqd.js → ui-Lqt_zFOr.js} +5 -1
  44. package/dist/update-B4hoLAN-.js +59 -0
  45. package/dist/{upgrade-Cbh-7q_o.js → upgrade-ByCYDXgb.js} +6 -6
  46. package/package.json +4 -3
  47. package/dist/json-C3hPIMkI.js +0 -7
  48. package/dist/publish-BVnG2UOU.js +0 -35
  49. package/dist/push-hHtVTZ1m.js +0 -35
  50. package/dist/update-CxP4fmMe.js +0 -137
  51. /package/dist/{asc-products-YQ6Oc6YO.js → asc-products-C6MvSy8H.js} +0 -0
  52. /package/dist/{storekit-Ddvs4Ynw.js → storekit-DPonXSwe.js} +0 -0
@@ -1,37 +1,12 @@
1
- import { t as formatJson } from "./json-C3hPIMkI.js";
1
+ import { g as VERSION, h as TELEMETRY_KEY, m as TELEMETRY_HOST, p as SUPERWALL_HOME, r as formatJson, v as isNonInteractive } from "./output-D2Ax_hHL.js";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { homedir } from "node:os";
5
5
  import { join } from "node:path";
6
6
 
7
- //#region package.json
8
- var version = "1.1.1";
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
7
  //#region src/core/state/config.ts
33
8
  function dir() {
34
- return join(homedir(), ".superwall");
9
+ return SUPERWALL_HOME() ?? join(homedir(), ".superwall");
35
10
  }
36
11
  function file() {
37
12
  return join(dir(), "config.json");
@@ -133,16 +108,6 @@ function setTelemetryNoticeShown() {
133
108
  write(config);
134
109
  }
135
110
 
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
111
  //#endregion
147
112
  //#region src/core/telemetry.ts
148
113
  const tags = {};
@@ -154,7 +119,7 @@ function isTelemetryEnabled(env, key) {
154
119
  return Boolean(key) && !env.DO_NOT_TRACK && !env.SUPERWALL_TELEMETRY_DISABLED && !env.NODE_TEST_CONTEXT;
155
120
  }
156
121
  function telemetryEnabled() {
157
- return isTelemetryEnabled(process.env, TELEMETRY_KEY);
122
+ return isTelemetryEnabled(process.env, TELEMETRY_KEY());
158
123
  }
159
124
  /**
160
125
  * Fully anonymous by design: distinct_id is a random persisted UUID never
@@ -163,7 +128,7 @@ function telemetryEnabled() {
163
128
  */
164
129
  function buildEvent(event, props, distinctId) {
165
130
  return {
166
- api_key: TELEMETRY_KEY,
131
+ api_key: TELEMETRY_KEY(),
167
132
  event,
168
133
  distinct_id: distinctId,
169
134
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -182,7 +147,7 @@ function track(event, props = {}) {
182
147
  if (!telemetryEnabled()) return;
183
148
  try {
184
149
  const payload = buildEvent(event, props, getAnonymousId());
185
- pending.push(fetch(`${TELEMETRY_HOST}/capture/`, {
150
+ pending.push(fetch(`${TELEMETRY_HOST()}/capture/`, {
186
151
  method: "POST",
187
152
  headers: { "content-type": "application/json" },
188
153
  body: JSON.stringify(payload),
@@ -201,4 +166,4 @@ function maybeShowTelemetryNotice(ui) {
201
166
  }
202
167
 
203
168
  //#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 };
169
+ export { getAnonymousId as a, getOnboardedOrg as c, getUpdateCheck as d, setDefaultApp as f, setUpdateCheck as g, setSkillsSync as h, track as i, getOnboardingIdempotencyKey as l, setOnboardedOrg as m, maybeShowTelemetryNotice as n, getDefaultApp as o, setOnboardedApp as p, setTelemetryTags as r, getOnboardedApp as s, flushTelemetry as t, getSkillsSync as u };
@@ -1,4 +1,4 @@
1
- import { t as formatJson } from "./json-C3hPIMkI.js";
1
+ import { p as SUPERWALL_HOME, r as formatJson } from "./output-D2Ax_hHL.js";
2
2
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { join } from "node:path";
@@ -14,7 +14,7 @@ var NotLoggedInError = class extends Error {
14
14
  //#endregion
15
15
  //#region src/core/auth/storage.ts
16
16
  function dir() {
17
- return join(homedir(), ".superwall");
17
+ return SUPERWALL_HOME() ?? join(homedir(), ".superwall");
18
18
  }
19
19
  function file() {
20
20
  return join(dir(), "auth.json");
@@ -27656,6 +27656,10 @@ function selectRenderer(opts) {
27656
27656
  active = mode === "rich" ? inkRenderer : mode === "json" ? silentRenderer : plainRenderer;
27657
27657
  return active;
27658
27658
  }
27659
+ function useRenderer(renderer$1) {
27660
+ active = renderer$1;
27661
+ return renderer$1;
27662
+ }
27659
27663
  const silentRenderer = {
27660
27664
  start: () => {},
27661
27665
  stop: () => {},
@@ -27700,4 +27704,4 @@ const ui = {
27700
27704
  };
27701
27705
 
27702
27706
  //#endregion
27703
- export { fg as a, THEME as i, ui as n, stripReport as r, selectRenderer as t };
27707
+ export { THEME as a, stripReport as i, ui as n, fg as o, useRenderer as r, selectRenderer as t };
@@ -0,0 +1,59 @@
1
+ import { g as VERSION } from "./output-D2Ax_hHL.js";
2
+ import { d as getUpdateCheck, g as setUpdateCheck } from "./telemetry-yJs7t0rt.js";
3
+ import pc from "picocolors";
4
+
5
+ //#region src/core/update.ts
6
+ const CHECK_INTERVAL_MS = 1440 * 60 * 1e3;
7
+ const REGISTRY_URL = "https://registry.npmjs.org/superwall/latest";
8
+ const pending = [];
9
+ function isNewerVersion(latest, current) {
10
+ const l = latest.split(".").map((n) => parseInt(n, 10));
11
+ const c = current.split(".").map((n) => parseInt(n, 10));
12
+ for (let i = 0; i < 3; i++) {
13
+ const a = l[i] ?? 0;
14
+ const b = c[i] ?? 0;
15
+ if (Number.isNaN(a) || Number.isNaN(b)) return false;
16
+ if (a !== b) return a > b;
17
+ }
18
+ return false;
19
+ }
20
+ async function fetchLatestVersion() {
21
+ try {
22
+ const res = await fetch(REGISTRY_URL, {
23
+ headers: { accept: "application/json" },
24
+ signal: AbortSignal.timeout(5e3)
25
+ });
26
+ if (!res.ok) return null;
27
+ const { version } = await res.json();
28
+ return version ?? null;
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+ function availableUpdate() {
34
+ const cached = getUpdateCheck();
35
+ return cached?.latest && isNewerVersion(cached.latest, VERSION) ? cached.latest : null;
36
+ }
37
+ function refreshUpdateCheck() {
38
+ if (process.env.NODE_TEST_CONTEXT) return;
39
+ const cached = getUpdateCheck();
40
+ if ((cached?.checkedAt ? Date.now() - Date.parse(cached.checkedAt) : Infinity) < CHECK_INTERVAL_MS) return;
41
+ pending.push(fetchLatestVersion().then((version) => {
42
+ if (version) setUpdateCheck({
43
+ latest: version,
44
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString()
45
+ });
46
+ }));
47
+ }
48
+ async function flushUpdateCheck(capMs = 2e3) {
49
+ if (pending.length === 0) return;
50
+ await Promise.race([Promise.allSettled(pending), new Promise((done) => setTimeout(done, capMs).unref())]);
51
+ }
52
+ function maybeNotifyUpdate(stream) {
53
+ const latest = availableUpdate();
54
+ if (!latest) return;
55
+ stream.write(`${pc.dim(`Update available ${VERSION} → ${latest} · run \`superwall upgrade\``)}\n`);
56
+ }
57
+
58
+ //#endregion
59
+ export { refreshUpdateCheck as a, maybeNotifyUpdate as i, flushUpdateCheck as n, isNewerVersion as r, fetchLatestVersion as t };
@@ -1,9 +1,9 @@
1
- import { k as VERSION, v as setUpdateCheck } from "./telemetry-CLi7mjDP.js";
2
- import "./json-C3hPIMkI.js";
3
- import { r as isNewerVersion, t as fetchLatestVersion } from "./update-CxP4fmMe.js";
4
- import "./token-DHRH8cxi.js";
5
- import { t as defineCommand } from "./command-CmJMNVVz.js";
6
- import "./ui-C4ncRJqd.js";
1
+ import { g as VERSION } from "./output-D2Ax_hHL.js";
2
+ import { g as setUpdateCheck } from "./telemetry-yJs7t0rt.js";
3
+ import { r as isNewerVersion, t as fetchLatestVersion } from "./update-B4hoLAN-.js";
4
+ import "./token-GcbyH6G8.js";
5
+ import { t as defineCommand } from "./command-B7Te31wp.js";
6
+ import "./ui-Lqt_zFOr.js";
7
7
  import { r as spawnStream } from "./spawn-DSoTXy_j.js";
8
8
 
9
9
  //#region src/commands/account/upgrade.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superwall/cli",
3
- "version": "1.1.1",
3
+ "version": "1.3.0-beta.3",
4
4
  "description": "The official CLI for managing Superwall from your terminal or coding agent.",
5
5
  "keywords": [
6
6
  "agent",
@@ -47,17 +47,18 @@
47
47
  "watch": "tsdown --watch",
48
48
  "regen:asc": "tsx scripts/regen-asc-index.ts",
49
49
  "dev": "bun bin.ts",
50
- "test": "tsx --test $(rg --files tests -g '*.test.ts')",
50
+ "test": "tsx --test --import ./tests/setup.ts $(rg --files tests -g '*.test.ts')",
51
51
  "link:global": "tsdown && bun link",
52
52
  "typecheck": "tsc --noEmit",
53
53
  "prepack": "bun run build",
54
54
  "prepublishOnly": "bun run typecheck && bun run test",
55
55
  "test:run": "tsx --test $(rg --files tests -g '*.test.ts')",
56
- "test:coverage": "tsx --test --experimental-test-coverage --test-coverage-lines=70 --test-coverage-branches=82 --test-coverage-functions=68 $(rg --files tests -g '*.test.ts')",
56
+ "test:coverage": "tsx --test --import ./tests/setup.ts --experimental-test-coverage --test-coverage-lines=85 --test-coverage-branches=88 --test-coverage-functions=85 $(rg --files tests -g '*.test.ts')",
57
57
  "clean": "rm -rf dist"
58
58
  },
59
59
  "dependencies": {
60
60
  "@anthropic-ai/claude-agent-sdk": "0.3.201",
61
+ "@superwall/studio": "1.3.0-beta.3",
61
62
  "ansi-escapes": "^7.3.0",
62
63
  "fast-glob": "^3.3.3",
63
64
  "ink": "^5.2.1",
@@ -1,7 +0,0 @@
1
- //#region src/util/json.ts
2
- function formatJson(value) {
3
- return JSON.stringify(value, null, 2);
4
- }
5
-
6
- //#endregion
7
- export { formatJson as t };
@@ -1,35 +0,0 @@
1
- import "./telemetry-CLi7mjDP.js";
2
- import "./json-C3hPIMkI.js";
3
- import "./update-CxP4fmMe.js";
4
- import "./token-DHRH8cxi.js";
5
- import { t as defineCommand } from "./command-CmJMNVVz.js";
6
- import "./ui-C4ncRJqd.js";
7
- import "./skills-HlIKA9xR.js";
8
- import "./spawn-DSoTXy_j.js";
9
- import "./login-B7fSpJKc.js";
10
- import "./scan-BfoeYW1v.js";
11
- import "./hosted-CbNJSJAC.js";
12
- import "./spinner-gOxIMz-V.js";
13
- import "./resources-CVrWwA1K.js";
14
- import "./org-B2gy9Pmu.js";
15
- import "./bind-DO11eXrR.js";
16
- import { i as requireApi } from "./git-BrTxQ7ui.js";
17
- import "./actions-I5gVO5jN.js";
18
- import "./app-DE9lxNNV.js";
19
- import { o as runPushPipeline } from "./pipeline-COr4sB6U.js";
20
-
21
- //#region src/commands/paywalls/publish.ts
22
- const runPublish = defineCommand({
23
- name: "publish",
24
- output: "human",
25
- async run(context) {
26
- const api = await requireApi(context.interactive);
27
- await runPushPipeline({
28
- ...context,
29
- api
30
- }, { promote: true });
31
- }
32
- });
33
-
34
- //#endregion
35
- export { runPublish };
@@ -1,35 +0,0 @@
1
- import "./telemetry-CLi7mjDP.js";
2
- import "./json-C3hPIMkI.js";
3
- import "./update-CxP4fmMe.js";
4
- import "./token-DHRH8cxi.js";
5
- import { t as defineCommand } from "./command-CmJMNVVz.js";
6
- import "./ui-C4ncRJqd.js";
7
- import "./skills-HlIKA9xR.js";
8
- import "./spawn-DSoTXy_j.js";
9
- import "./login-B7fSpJKc.js";
10
- import "./scan-BfoeYW1v.js";
11
- import "./hosted-CbNJSJAC.js";
12
- import "./spinner-gOxIMz-V.js";
13
- import "./resources-CVrWwA1K.js";
14
- import "./org-B2gy9Pmu.js";
15
- import "./bind-DO11eXrR.js";
16
- import { i as requireApi } from "./git-BrTxQ7ui.js";
17
- import "./actions-I5gVO5jN.js";
18
- import "./app-DE9lxNNV.js";
19
- import { o as runPushPipeline } from "./pipeline-COr4sB6U.js";
20
-
21
- //#region src/commands/paywalls/push.ts
22
- const runPush = defineCommand({
23
- name: "push",
24
- output: "human",
25
- async run(context) {
26
- const api = await requireApi(context.interactive);
27
- await runPushPipeline({
28
- ...context,
29
- api
30
- }, { promote: false });
31
- }
32
- });
33
-
34
- //#endregion
35
- export { runPush };
@@ -1,137 +0,0 @@
1
- import { k as VERSION, p as getUpdateCheck, v as setUpdateCheck } from "./telemetry-CLi7mjDP.js";
2
- import { t as formatJson } from "./json-C3hPIMkI.js";
3
- import pc from "picocolors";
4
- import { stripVTControlCharacters } from "node:util";
5
-
6
- //#region src/output.ts
7
- const blocks = {
8
- intro: (text) => ({
9
- kind: "intro",
10
- text
11
- }),
12
- step: (text) => ({
13
- kind: "step",
14
- text
15
- }),
16
- info: (text) => ({
17
- kind: "info",
18
- text
19
- }),
20
- success: (text) => ({
21
- kind: "success",
22
- text
23
- }),
24
- warning: (text) => ({
25
- kind: "warning",
26
- text
27
- }),
28
- report: (text) => ({
29
- kind: "report",
30
- text
31
- }),
32
- list: (value) => ({
33
- kind: "list",
34
- value
35
- }),
36
- nextSteps: (items) => ({
37
- kind: "nextSteps",
38
- items
39
- }),
40
- outro: (text) => ({
41
- kind: "outro",
42
- text
43
- })
44
- };
45
- function writeJson(stream, value) {
46
- stream.write(`${formatJson(value)}\n`);
47
- }
48
- function createCommandOutput(mode, renderer, streams = { stdout: process.stdout }) {
49
- return {
50
- mode,
51
- data(value) {
52
- if (mode === "json") writeJson(streams.stdout, value);
53
- else renderer.report(formatJson(value));
54
- },
55
- text(value) {
56
- if (mode === "json") throw new Error("This command must return structured JSON in --json mode.");
57
- const text = value.replace(/\n$/, "");
58
- renderer.report(mode === "text" ? stripVTControlCharacters(text) : text);
59
- },
60
- render(...blocks$1) {
61
- if (mode === "json") return;
62
- for (const block of blocks$1) renderBlock(renderer, block);
63
- }
64
- };
65
- }
66
- function renderBlock(renderer, block) {
67
- switch (block.kind) {
68
- case "intro": return renderer.intro(block.text);
69
- case "step": return renderer.step(block.text);
70
- case "info": return renderer.info(block.text);
71
- case "success": return renderer.success(block.text);
72
- case "warning": return renderer.warn(block.text);
73
- case "report": return renderer.report(block.text);
74
- case "list": return renderer.list(block.value);
75
- case "nextSteps":
76
- if (block.items.length) renderer.note(block.items.map((item, index) => `${index + 1}. ${item}`).join("\n"), "Next steps");
77
- return;
78
- case "outro": return renderer.outro(block.text);
79
- }
80
- }
81
-
82
- //#endregion
83
- //#region src/core/update.ts
84
- const CHECK_INTERVAL_MS = 1440 * 60 * 1e3;
85
- const REGISTRY_URL = "https://registry.npmjs.org/superwall/latest";
86
- const pending = [];
87
- function isNewerVersion(latest, current) {
88
- const l = latest.split(".").map((n) => parseInt(n, 10));
89
- const c = current.split(".").map((n) => parseInt(n, 10));
90
- for (let i = 0; i < 3; i++) {
91
- const a = l[i] ?? 0;
92
- const b = c[i] ?? 0;
93
- if (Number.isNaN(a) || Number.isNaN(b)) return false;
94
- if (a !== b) return a > b;
95
- }
96
- return false;
97
- }
98
- async function fetchLatestVersion() {
99
- try {
100
- const res = await fetch(REGISTRY_URL, {
101
- headers: { accept: "application/json" },
102
- signal: AbortSignal.timeout(5e3)
103
- });
104
- if (!res.ok) return null;
105
- const { version } = await res.json();
106
- return version ?? null;
107
- } catch {
108
- return null;
109
- }
110
- }
111
- function availableUpdate() {
112
- const cached = getUpdateCheck();
113
- return cached?.latest && isNewerVersion(cached.latest, VERSION) ? cached.latest : null;
114
- }
115
- function refreshUpdateCheck() {
116
- if (process.env.NODE_TEST_CONTEXT) return;
117
- const cached = getUpdateCheck();
118
- if ((cached?.checkedAt ? Date.now() - Date.parse(cached.checkedAt) : Infinity) < CHECK_INTERVAL_MS) return;
119
- pending.push(fetchLatestVersion().then((version) => {
120
- if (version) setUpdateCheck({
121
- latest: version,
122
- checkedAt: (/* @__PURE__ */ new Date()).toISOString()
123
- });
124
- }));
125
- }
126
- async function flushUpdateCheck(capMs = 2e3) {
127
- if (pending.length === 0) return;
128
- await Promise.race([Promise.allSettled(pending), new Promise((done) => setTimeout(done, capMs).unref())]);
129
- }
130
- function maybeNotifyUpdate(stream) {
131
- const latest = availableUpdate();
132
- if (!latest) return;
133
- stream.write(`${pc.dim(`Update available ${VERSION} → ${latest} · run \`superwall upgrade\``)}\n`);
134
- }
135
-
136
- //#endregion
137
- export { refreshUpdateCheck as a, writeJson as c, maybeNotifyUpdate as i, flushUpdateCheck as n, blocks as o, isNewerVersion as r, createCommandOutput as s, fetchLatestVersion as t };