peekable 0.1.5 → 0.2.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.
@@ -21,10 +21,14 @@ export function errorPayload(err) {
21
21
  }
22
22
  export function getErrorMessage(err) {
23
23
  if (err instanceof CommandFailure) {
24
- if (err.cause instanceof Error)
25
- return err.cause.message;
24
+ if (err.cause !== undefined)
25
+ return getErrorMessage(err.cause);
26
26
  return err.message;
27
27
  }
28
+ if (err instanceof ApiError && err.details.code === "trial_expired") {
29
+ const upgradeUrl = typeof err.details.upgrade_url === "string" ? err.details.upgrade_url : null;
30
+ return `Your Peekable trial has ended. Run \`peekable upgrade\` to keep pushing.${upgradeUrl ? ` Upgrade: ${upgradeUrl}` : ""}`;
31
+ }
28
32
  if (err instanceof Error)
29
33
  return err.message;
30
34
  return String(err);
@@ -15,6 +15,8 @@ export interface DoctorReport {
15
15
  identity: DoctorStatus;
16
16
  identityName?: string | null;
17
17
  identityEmail?: string | null;
18
+ planState?: string | null;
19
+ daysRemaining?: number | null;
18
20
  activeSessions: number | null;
19
21
  maxActiveSessions: number | null;
20
22
  activeSessionUnlimited?: boolean;
@@ -83,6 +83,8 @@ export async function runDoctor(opts = {}) {
83
83
  maxActiveSessions: null,
84
84
  activeSessionUnlimited: false,
85
85
  testPush: "skipped",
86
+ planState: null,
87
+ daysRemaining: null,
86
88
  errors: [],
87
89
  };
88
90
  if (!config) {
@@ -117,6 +119,8 @@ export async function runDoctor(opts = {}) {
117
119
  const anyMe = me;
118
120
  report.identityName = typeof anyMe.name === "string" ? anyMe.name : null;
119
121
  report.identityEmail = typeof anyMe.email === "string" ? anyMe.email : null;
122
+ report.planState = typeof anyMe.plan_state === "string" ? anyMe.plan_state : null;
123
+ report.daysRemaining = typeof anyMe.days_remaining === "number" ? anyMe.days_remaining : null;
120
124
  }
121
125
  }
122
126
  catch (err) {
@@ -125,7 +129,10 @@ export async function runDoctor(opts = {}) {
125
129
  }
126
130
  if (opts.testPush && report.auth === "ok") {
127
131
  try {
128
- const session = await api(config, "POST", "/sessions", { name: "__peekable_doctor__" });
132
+ const session = await api(config, "POST", "/sessions", {
133
+ name: "__peekable_doctor__",
134
+ diagnostic: true,
135
+ });
129
136
  try {
130
137
  await api(config, "POST", `/sessions/${session.id}/push`, {
131
138
  html: "<html><body><p>Peekable doctor test</p></body></html>",
@@ -173,6 +180,7 @@ export function formatDoctorReport(report) {
173
180
  `Server: ${formatServer(report)}`,
174
181
  `Auth: ${formatAuth(report.auth)}`,
175
182
  `Identity: ${formatIdentity(report)}`,
183
+ `Plan: ${formatPlan(report)}`,
176
184
  `Active sessions: ${formatQuota(report.activeSessions, report.maxActiveSessions, report.activeSessionUnlimited)}`,
177
185
  `Test push: ${report.testPush}`,
178
186
  ];
@@ -189,6 +197,19 @@ export function formatDoctorReport(report) {
189
197
  }
190
198
  return lines.join("\n");
191
199
  }
200
+ function formatPlan(report) {
201
+ if (report.planState === "trial_registered")
202
+ return "trial — not activated";
203
+ if (report.planState === "trial_active") {
204
+ const days = report.daysRemaining ?? 0;
205
+ return `trial (${days} ${days === 1 ? "day" : "days"} left)`;
206
+ }
207
+ if (report.planState === "trial_expired")
208
+ return "trial expired — run `peekable upgrade`";
209
+ if (report.planState === "paid")
210
+ return "paid";
211
+ return "free";
212
+ }
192
213
  function formatServer(report) {
193
214
  if (!report.serverUrl)
194
215
  return "not configured";
@@ -87,7 +87,7 @@ export const initCommand = new Command("init")
87
87
  Object.assign(result, installLocalAgentSkills(skillSource, opts.json));
88
88
  // 3. Test push
89
89
  try {
90
- const session = await api(config, "POST", "/sessions", { name: "__share_init_test__" });
90
+ const session = await api(config, "POST", "/sessions", { name: "__share_init_test__", init: true });
91
91
  await api(config, "POST", `/sessions/${session.id}/push`, {
92
92
  html: "<html><body><p>Share init test</p></body></html>",
93
93
  });
@@ -43,13 +43,26 @@ export const registerCommand = new Command("register")
43
43
  name: opts.name,
44
44
  });
45
45
  if (opts.json) {
46
- console.log(JSON.stringify({ api_key: data.api_key, url: opts.url, name: opts.name }));
46
+ console.log(JSON.stringify({
47
+ api_key: data.api_key,
48
+ url: opts.url,
49
+ name: opts.name,
50
+ plan_state: data.plan_state ?? null,
51
+ trial_ends_at: data.trial_ends_at ?? null,
52
+ days_remaining: data.days_remaining ?? null,
53
+ invite_source: data.invite_source ?? null,
54
+ }));
47
55
  }
48
56
  else {
49
57
  console.log(`Registered as ${opts.name}.`);
50
58
  console.log(`API key saved to ~/.peekable/config.json`);
51
59
  console.log("Peekable CLI sends anonymous usage/failure telemetry to improve reliability. Opt out: PEEKABLE_NO_TELEMETRY=1");
52
- console.log(`\nNext step: run \`peekable init\` to complete setup.`);
60
+ if (data.invite_source === "trial") {
61
+ console.log("Trial ready — 7 days start when you push your first real share. Run `peekable init`.");
62
+ }
63
+ else {
64
+ console.log(`\nNext step: run \`peekable init\` to complete setup.`);
65
+ }
53
66
  }
54
67
  }
55
68
  catch (err) {
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const upgradeCommand: Command;
@@ -0,0 +1,63 @@
1
+ import { spawn } from "node:child_process";
2
+ import { Command } from "commander";
3
+ import { api, ApiError } from "../api.js";
4
+ import { CommandFailure, printCommandError } from "../command-error.js";
5
+ import { requireConfig } from "../config.js";
6
+ import { runWithTelemetry } from "../telemetry.js";
7
+ export const upgradeCommand = new Command("upgrade")
8
+ .description("Upgrade a Peekable trial through Stripe Checkout")
9
+ .option("--json", "Output JSON")
10
+ .action(async (opts) => {
11
+ await runWithTelemetry("upgrade", async () => {
12
+ const config = requireConfig();
13
+ try {
14
+ const data = await api(config, "POST", "/billing/checkout", {});
15
+ const url = checkoutUrl(data?.url);
16
+ if (!url)
17
+ throw new Error("Checkout did not return a valid URL.");
18
+ if (opts.json) {
19
+ console.log(JSON.stringify({ url, sessionId: data.sessionId ?? null }));
20
+ }
21
+ else {
22
+ console.log("Complete your Peekable upgrade in Stripe Checkout:");
23
+ console.log(url);
24
+ openBrowserBestEffort(url);
25
+ }
26
+ }
27
+ catch (err) {
28
+ if (!opts.json
29
+ && err instanceof ApiError
30
+ && (err.details.code === "billing_account_exists"
31
+ || err.details.code === "billing_account_requires_support")) {
32
+ console.error("Email support@peekable.fyi from your registered account email for help.");
33
+ }
34
+ printCommandError("Upgrade failed", err, opts.json);
35
+ throw new CommandFailure("Upgrade failed", { cause: err });
36
+ }
37
+ });
38
+ });
39
+ function checkoutUrl(value) {
40
+ if (typeof value !== "string")
41
+ return null;
42
+ try {
43
+ const url = new URL(value);
44
+ return url.protocol === "https:" || url.protocol === "http:" ? url.toString() : null;
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ }
50
+ function openBrowserBestEffort(url) {
51
+ try {
52
+ const child = process.platform === "darwin"
53
+ ? spawn("open", [url], { detached: true, stdio: "ignore" })
54
+ : process.platform === "win32"
55
+ ? spawn("cmd", ["/c", "start", "", url], { detached: true, stdio: "ignore" })
56
+ : spawn("xdg-open", [url], { detached: true, stdio: "ignore" });
57
+ child.on("error", () => undefined);
58
+ child.unref();
59
+ }
60
+ catch {
61
+ // The URL remains printed for humans and coding agents to relay.
62
+ }
63
+ }
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import { pushUrlCommand } from "./commands/push-url.js";
14
14
  import { doctorCommand } from "./commands/doctor.js";
15
15
  import { uninstallCommand } from "./commands/uninstall.js";
16
16
  import { reportCommand } from "./commands/report.js";
17
+ import { upgradeCommand } from "./commands/upgrade.js";
17
18
  import { CLI_VERSION } from "./version.js";
18
19
  import { CommandFailure } from "./command-error.js";
19
20
  import { ConfigError } from "./config.js";
@@ -36,6 +37,7 @@ program.addCommand(proxyCommand);
36
37
  program.addCommand(doctorCommand);
37
38
  program.addCommand(uninstallCommand);
38
39
  program.addCommand(reportCommand);
40
+ program.addCommand(upgradeCommand);
39
41
  program.addHelpText("afterAll", `
40
42
  Telemetry:
41
43
  Peekable CLI sends anonymous usage/failure telemetry to improve reliability.
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const CLI_VERSION = "0.1.5";
1
+ export declare const CLI_VERSION = "0.2.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.1.5";
1
+ export const CLI_VERSION = "0.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peekable",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Share HTML mockups with collaborators — CLI for peekable-server",
6
6
  "bin": {