pcific 0.0.0-stage → 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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/SKILL.md +127 -0
  4. package/dist/api/catalog.js +637 -0
  5. package/dist/api/run.js +960 -0
  6. package/dist/api/search.js +171 -0
  7. package/dist/api/shortcuts.js +799 -0
  8. package/dist/bin.js +648 -0
  9. package/dist/commands/auth.js +513 -0
  10. package/dist/commands/doctor.js +410 -0
  11. package/dist/commands/init.js +306 -0
  12. package/dist/commands/sync.js +214 -0
  13. package/dist/detect.js +214 -0
  14. package/dist/env.js +339 -0
  15. package/dist/goLive.js +629 -0
  16. package/dist/keyLink.js +305 -0
  17. package/dist/mcp/server.js +206 -0
  18. package/dist/mcp/tools.js +689 -0
  19. package/dist/python/template.js +793 -0
  20. package/dist/schema/discover.js +324 -0
  21. package/dist/schema/helpers.js +396 -0
  22. package/dist/schema/prismaToJsonSchema.js +197 -0
  23. package/dist/schema/push.js +570 -0
  24. package/dist/schema/tsToJsonSchema.js +405 -0
  25. package/dist/schema/zodToJsonSchema.js +442 -0
  26. package/dist/templates/openapi.json +1 -0
  27. package/dist/templates/sdk/auth.ts +139 -0
  28. package/dist/templates/sdk/client.ts +1059 -0
  29. package/dist/templates/sdk/errors.ts +76 -0
  30. package/dist/templates/sdk/generated-types.ts +5746 -0
  31. package/dist/templates/sdk/http.ts +359 -0
  32. package/dist/templates/sdk/index.ts +84 -0
  33. package/dist/templates/sdk/json.ts +24 -0
  34. package/dist/templates/sdk/kit.ts +516 -0
  35. package/dist/templates/sdk/multipart.ts +99 -0
  36. package/dist/templates/sdk/sse.ts +131 -0
  37. package/dist/templates/sdk/verify.ts +766 -0
  38. package/dist/templates/sdk-js/auth.d.ts +20 -0
  39. package/dist/templates/sdk-js/auth.js +85 -0
  40. package/dist/templates/sdk-js/client.d.ts +324 -0
  41. package/dist/templates/sdk-js/client.js +607 -0
  42. package/dist/templates/sdk-js/errors.d.ts +51 -0
  43. package/dist/templates/sdk-js/errors.js +48 -0
  44. package/dist/templates/sdk-js/generated-types.d.ts +5736 -0
  45. package/dist/templates/sdk-js/generated-types.js +5 -0
  46. package/dist/templates/sdk-js/http.d.ts +50 -0
  47. package/dist/templates/sdk-js/http.js +263 -0
  48. package/dist/templates/sdk-js/index.d.ts +9 -0
  49. package/dist/templates/sdk-js/index.js +7 -0
  50. package/dist/templates/sdk-js/json.d.ts +11 -0
  51. package/dist/templates/sdk-js/json.js +16 -0
  52. package/dist/templates/sdk-js/kit.d.ts +220 -0
  53. package/dist/templates/sdk-js/kit.js +208 -0
  54. package/dist/templates/sdk-js/multipart.d.ts +23 -0
  55. package/dist/templates/sdk-js/multipart.js +61 -0
  56. package/dist/templates/sdk-js/sse.d.ts +12 -0
  57. package/dist/templates/sdk-js/sse.js +99 -0
  58. package/dist/templates/sdk-js/verify.d.ts +114 -0
  59. package/dist/templates/sdk-js/verify.js +506 -0
  60. package/dist/templates.js +925 -0
  61. package/dist/ui.js +399 -0
  62. package/dist/webhooks/events.js +171 -0
  63. package/dist/webhooks/listen.js +772 -0
  64. package/package.json +32 -4
package/dist/goLive.js ADDED
@@ -0,0 +1,629 @@
1
+ import { execFile } from "node:child_process";
2
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { isJsonNumber, isJsonObject, isJsonString } from "./api/catalog.js";
5
+ import { BaseUrlError, DEFAULT_BASE_URL, callPcificTestApi, formatApiError, isStreamTty, normalizeBaseUrl, parseDotEnv, redactSecrets, resolveTestKey, } from "./api/run.js";
6
+ function writeOut(stream, text) {
7
+ stream.write(`${redactSecrets(text)}\n`);
8
+ }
9
+ const SHELL_META_PATTERN = /[\r\n"'&|<>^%!]/;
10
+ export function validateBrowserUrl(rawUrl) {
11
+ if (!rawUrl || SHELL_META_PATTERN.test(rawUrl)) {
12
+ return null;
13
+ }
14
+ let parsed;
15
+ try {
16
+ parsed = new URL(rawUrl);
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
22
+ return null;
23
+ }
24
+ if (SHELL_META_PATTERN.test(parsed.toString())) {
25
+ return null;
26
+ }
27
+ return parsed;
28
+ }
29
+ export function defaultOpenBrowser(url) {
30
+ const parsed = validateBrowserUrl(url);
31
+ if (!parsed) {
32
+ return Promise.resolve(false);
33
+ }
34
+ const safeUrl = parsed.toString();
35
+ return new Promise((resolve) => {
36
+ const platform = process.platform;
37
+ let command;
38
+ let args;
39
+ if (platform === "darwin") {
40
+ command = "open";
41
+ args = [safeUrl];
42
+ }
43
+ else if (platform === "win32") {
44
+ command = "powershell.exe";
45
+ args = ["-NoProfile", "-NonInteractive", "-Command", "Start-Process", "--", safeUrl];
46
+ }
47
+ else {
48
+ command = "xdg-open";
49
+ args = [safeUrl];
50
+ }
51
+ try {
52
+ const child = execFile(command, args, { timeout: 5000 }, (err) => {
53
+ resolve(!err);
54
+ });
55
+ child.unref();
56
+ }
57
+ catch {
58
+ resolve(false);
59
+ }
60
+ });
61
+ }
62
+ function isHeadlessEnv(env, stdout, hasCustomOpener) {
63
+ if (env.CI === "true" || env.CI === "1") {
64
+ return true;
65
+ }
66
+ if (hasCustomOpener) {
67
+ return false;
68
+ }
69
+ if (!isStreamTty(stdout)) {
70
+ return true;
71
+ }
72
+ if (process.platform === "linux" && !env.DISPLAY && !env.WAYLAND_DISPLAY) {
73
+ return true;
74
+ }
75
+ return false;
76
+ }
77
+ const IGNORED_DIRS = new Set([
78
+ "node_modules",
79
+ ".git",
80
+ "dist",
81
+ "build",
82
+ ".next",
83
+ ".nuxt",
84
+ ".output",
85
+ ".svelte-kit",
86
+ ".vercel",
87
+ "coverage",
88
+ "target",
89
+ "__pycache__",
90
+ ".venv",
91
+ "venv",
92
+ ]);
93
+ const CODE_EXTENSIONS = new Set([
94
+ ".ts",
95
+ ".tsx",
96
+ ".js",
97
+ ".jsx",
98
+ ".mjs",
99
+ ".cjs",
100
+ ".py",
101
+ ".go",
102
+ ".rs",
103
+ ".rb",
104
+ ".php",
105
+ ".astro",
106
+ ".svelte",
107
+ ".vue",
108
+ ]);
109
+ function scanLocalCodebase(cwd) {
110
+ const gitignorePath = path.join(cwd, ".gitignore");
111
+ let gitignoreExists = false;
112
+ let gitignoreHasEnv = false;
113
+ if (existsSync(gitignorePath)) {
114
+ gitignoreExists = true;
115
+ const content = readFileSync(gitignorePath, "utf8");
116
+ gitignoreHasEnv = content.split(/\r?\n/).some((line) => {
117
+ const trimmed = line.trim();
118
+ if (!trimmed || trimmed.startsWith("#")) {
119
+ return false;
120
+ }
121
+ return (trimmed === ".env" ||
122
+ trimmed === "/.env" ||
123
+ trimmed === ".env*" ||
124
+ trimmed === ".env.*" ||
125
+ trimmed === "*.env");
126
+ });
127
+ }
128
+ let localEnvHasLiveKey = false;
129
+ const liveKeyFiles = [];
130
+ for (const filename of [".env", ".env.local"]) {
131
+ const envPath = path.join(cwd, filename);
132
+ if (existsSync(envPath)) {
133
+ const parsed = parseDotEnv(readFileSync(envPath, "utf8"));
134
+ const liveVal = parsed.get("PCIFIC_LIVE_KEY")?.trim() ?? "";
135
+ if (liveVal && !liveVal.startsWith("<")) {
136
+ localEnvHasLiveKey = true;
137
+ liveKeyFiles.push(filename);
138
+ }
139
+ }
140
+ }
141
+ let usesPcificMode = false;
142
+ let usesPcificLiveKey = false;
143
+ let filesScanned = 0;
144
+ const maxFiles = 200;
145
+ function walk(dir, depth) {
146
+ if (depth > 5 || filesScanned >= maxFiles || (usesPcificMode && usesPcificLiveKey)) {
147
+ return;
148
+ }
149
+ let entries;
150
+ try {
151
+ entries = readdirSync(dir, { withFileTypes: true });
152
+ }
153
+ catch {
154
+ return;
155
+ }
156
+ for (const entry of entries) {
157
+ if (filesScanned >= maxFiles || (usesPcificMode && usesPcificLiveKey)) {
158
+ return;
159
+ }
160
+ if (entry.isDirectory()) {
161
+ if (!IGNORED_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
162
+ walk(path.join(dir, entry.name), depth + 1);
163
+ }
164
+ continue;
165
+ }
166
+ if (!entry.isFile()) {
167
+ continue;
168
+ }
169
+ const ext = path.extname(entry.name).toLowerCase();
170
+ if (!CODE_EXTENSIONS.has(ext)) {
171
+ continue;
172
+ }
173
+ filesScanned += 1;
174
+ try {
175
+ const text = readFileSync(path.join(dir, entry.name), "utf8");
176
+ if (text.includes("PCIFIC_MODE")) {
177
+ usesPcificMode = true;
178
+ }
179
+ if (text.includes("PCIFIC_LIVE_KEY")) {
180
+ usesPcificLiveKey = true;
181
+ }
182
+ }
183
+ catch {
184
+ // Ignore unreadable files.
185
+ }
186
+ }
187
+ }
188
+ walk(cwd, 0);
189
+ return {
190
+ gitignoreExists,
191
+ gitignoreHasEnv,
192
+ localEnvHasLiveKey,
193
+ liveKeyFiles,
194
+ usesPcificMode,
195
+ usesPcificLiveKey,
196
+ filesScanned,
197
+ };
198
+ }
199
+ const GO_LIVE_HELP = [
200
+ "Usage: pcific go-live [--no-open] [--base-url <url>] [--json] [--plain]",
201
+ "",
202
+ "Run a production readiness preflight check with your test key, open the PCIFIC",
203
+ "dashboard Keys page for the human owner to create a live key, and print copy-ready",
204
+ "production environment variables and secret commands.",
205
+ "",
206
+ "Never accepts or touches a live API key locally.",
207
+ ].join("\n");
208
+ export async function runGoLiveCommand(args, options = {}) {
209
+ const cwd = options.cwd ?? process.cwd();
210
+ const stdout = options.stdout ?? process.stdout;
211
+ const stderr = options.stderr ?? process.stderr;
212
+ let jsonFlag = Boolean(options.json) || args.includes("--json");
213
+ let plainFlag = Boolean(options.plain) || args.includes("--plain");
214
+ let noOpenFlag = false;
215
+ let baseUrlFlag;
216
+ for (let i = 0; i < args.length; i += 1) {
217
+ const arg = args[i];
218
+ if (arg === "--help" || arg === "-h") {
219
+ writeOut(stdout, GO_LIVE_HELP);
220
+ return 0;
221
+ }
222
+ if (arg === "--json") {
223
+ jsonFlag = true;
224
+ continue;
225
+ }
226
+ if (arg === "--plain") {
227
+ plainFlag = true;
228
+ continue;
229
+ }
230
+ if (arg === "--no-open") {
231
+ noOpenFlag = true;
232
+ continue;
233
+ }
234
+ if (arg === "--base-url" || arg.startsWith("--base-url=")) {
235
+ const value = arg.startsWith("--base-url=") ? arg.slice("--base-url=".length) : args[i + 1];
236
+ if (!value || (!arg.startsWith("--base-url=") && value.startsWith("-"))) {
237
+ const err = {
238
+ ok: false,
239
+ code: "MISSING_FLAG_VALUE",
240
+ error: "Missing value for --base-url.",
241
+ tryThis: "Pass a URL, for example --base-url https://business.pcific.ai",
242
+ };
243
+ if (jsonFlag) {
244
+ writeOut(stderr, JSON.stringify(err));
245
+ }
246
+ else {
247
+ writeOut(stderr, `Error [${err.code}]: ${err.error}`);
248
+ writeOut(stderr, `Try this: ${err.tryThis}`);
249
+ }
250
+ return 1;
251
+ }
252
+ if (!arg.startsWith("--base-url=")) {
253
+ i += 1;
254
+ }
255
+ baseUrlFlag = value;
256
+ continue;
257
+ }
258
+ const err = {
259
+ ok: false,
260
+ code: "UNKNOWN_FLAG",
261
+ error: `Unknown argument "${arg}" for pcific go-live.`,
262
+ tryThis: "Run pcific go-live --help to see supported options.",
263
+ };
264
+ if (jsonFlag) {
265
+ writeOut(stderr, JSON.stringify(err));
266
+ }
267
+ else {
268
+ writeOut(stderr, `Error [${err.code}]: ${err.error}`);
269
+ writeOut(stderr, `Try this: ${err.tryThis}`);
270
+ }
271
+ return 1;
272
+ }
273
+ const keyResult = resolveTestKey(cwd, options.env);
274
+ if (!keyResult.ok) {
275
+ if (jsonFlag) {
276
+ writeOut(stderr, JSON.stringify(keyResult));
277
+ }
278
+ else {
279
+ writeOut(stderr, `Error [${keyResult.code}]: ${keyResult.error}`);
280
+ writeOut(stderr, `Try this: ${keyResult.tryThis}`);
281
+ }
282
+ return 1;
283
+ }
284
+ let baseUrl;
285
+ try {
286
+ baseUrl = normalizeBaseUrl(baseUrlFlag ?? options.baseUrl ?? keyResult.baseUrl ?? DEFAULT_BASE_URL);
287
+ }
288
+ catch (err) {
289
+ if (err instanceof BaseUrlError) {
290
+ if (jsonFlag) {
291
+ writeOut(stderr, JSON.stringify({
292
+ ok: false,
293
+ code: err.code,
294
+ error: err.message,
295
+ tryThis: err.tryThis,
296
+ }));
297
+ }
298
+ else {
299
+ writeOut(stderr, `Error [${err.code}]: ${err.message}`);
300
+ writeOut(stderr, `Try this: ${err.tryThis}`);
301
+ }
302
+ return 1;
303
+ }
304
+ throw err;
305
+ }
306
+ const dashboardKeysUrl = `${baseUrl}/dashboard/keys`;
307
+ const checks = [];
308
+ let marketplaceId = keyResult.marketplaceId;
309
+ let marketplaceName;
310
+ let keyFailed = false;
311
+ try {
312
+ const keyRes = await callPcificTestApi({
313
+ method: "GET",
314
+ path: "/api/v1/key",
315
+ baseUrl,
316
+ apiKey: keyResult.apiKey,
317
+ fetchFn: options.fetch,
318
+ });
319
+ if (!keyRes.ok) {
320
+ keyFailed = true;
321
+ const err = keyRes.error ?? formatApiError(keyRes.status, keyRes.body, keyRes.requestId);
322
+ checks.push({
323
+ id: "test-key",
324
+ label: "Test API key & shop identity",
325
+ status: "fail",
326
+ detail: `${err.code}: ${err.error}`,
327
+ tryThis: err.tryThis,
328
+ });
329
+ }
330
+ else {
331
+ const body = isJsonObject(keyRes.body) ? keyRes.body : {};
332
+ const mp = isJsonObject(body.marketplace) ? body.marketplace : undefined;
333
+ if (mp && isJsonString(mp.id) && mp.id) {
334
+ marketplaceId = mp.id;
335
+ }
336
+ if (mp && isJsonString(mp.name) && mp.name) {
337
+ marketplaceName = mp.name;
338
+ }
339
+ const shopLabel = marketplaceName
340
+ ? `${marketplaceName} (${marketplaceId ?? "id unknown"})`
341
+ : marketplaceId
342
+ ? `shop ${marketplaceId}`
343
+ : "whole-business key (all shops)";
344
+ checks.push({
345
+ id: "test-key",
346
+ label: "Test API key & shop identity",
347
+ status: "pass",
348
+ detail: `Valid test key (${String(body.prefix ?? "pcific_test_***")}) for ${shopLabel}.`,
349
+ });
350
+ }
351
+ }
352
+ catch (err) {
353
+ keyFailed = true;
354
+ checks.push({
355
+ id: "test-key",
356
+ label: "Test API key & shop identity",
357
+ status: "fail",
358
+ detail: `Network error calling /api/v1/key: ${err instanceof Error ? err.message : String(err)}`,
359
+ tryThis: `Check your connection to ${baseUrl} and re-run \`pcific go-live\`.`,
360
+ });
361
+ }
362
+ if (!keyFailed) {
363
+ try {
364
+ const catRes = await callPcificTestApi({
365
+ method: "GET",
366
+ path: "/api/v1/catalogue/status",
367
+ baseUrl,
368
+ apiKey: keyResult.apiKey,
369
+ query: marketplaceId ? [["marketplaceId", marketplaceId]] : [],
370
+ fetchFn: options.fetch,
371
+ });
372
+ if (!catRes.ok) {
373
+ const err = catRes.error ?? formatApiError(catRes.status, catRes.body, catRes.requestId);
374
+ checks.push({
375
+ id: "catalogue",
376
+ label: "Published listing schema",
377
+ status: "warn",
378
+ detail: `Could not verify catalogue status (${err.code}: ${err.error}).`,
379
+ tryThis: "Run `npx pcific schema push --publish` if you use Orbit or Safeguard.",
380
+ });
381
+ }
382
+ else {
383
+ const body = isJsonObject(catRes.body) ? catRes.body : {};
384
+ const catalogue = isJsonObject(body.catalogue) ? body.catalogue : {};
385
+ const status = isJsonString(catalogue.status) ? catalogue.status : "none";
386
+ const version = catalogue.version;
387
+ const entryCount = isJsonNumber(catalogue.entryCount) ? catalogue.entryCount : 0;
388
+ if (status === "published" && version !== null && version !== undefined) {
389
+ checks.push({
390
+ id: "catalogue",
391
+ label: "Published listing schema",
392
+ status: "pass",
393
+ detail: `Published schema v${String(version)} active with ${entryCount} categor${entryCount === 1 ? "y" : "ies"}.`,
394
+ });
395
+ }
396
+ else {
397
+ checks.push({
398
+ id: "catalogue",
399
+ label: "Published listing schema",
400
+ status: "warn",
401
+ detail: "No listing schema version has been published yet.",
402
+ tryThis: "Run `npx pcific schema push --publish` before switching Orbit or Safeguard live.",
403
+ });
404
+ }
405
+ }
406
+ }
407
+ catch (err) {
408
+ checks.push({
409
+ id: "catalogue",
410
+ label: "Published listing schema",
411
+ status: "warn",
412
+ detail: `Could not reach /api/v1/catalogue/status: ${err instanceof Error ? err.message : String(err)}`,
413
+ tryThis: "Run `npx pcific schema push --publish` to verify your listing schema.",
414
+ });
415
+ }
416
+ try {
417
+ const whRes = await callPcificTestApi({
418
+ method: "GET",
419
+ path: "/api/v1/webhooks",
420
+ baseUrl,
421
+ apiKey: keyResult.apiKey,
422
+ query: marketplaceId ? [["marketplaceId", marketplaceId]] : [],
423
+ fetchFn: options.fetch,
424
+ });
425
+ if (!whRes.ok) {
426
+ checks.push({
427
+ id: "webhooks",
428
+ label: "Webhook endpoints",
429
+ status: "info",
430
+ detail: `Skipped (HTTP ${whRes.status}; optional unless you receive async events).`,
431
+ tryThis: "Create live webhook receivers in Dashboard > Webhooks if you use async notifications.",
432
+ });
433
+ }
434
+ else {
435
+ const body = isJsonObject(whRes.body) ? whRes.body : {};
436
+ const endpoints = Array.isArray(body.endpoints) ? body.endpoints : [];
437
+ const liveCount = endpoints.filter((ep) => isJsonObject(ep) && ep.test === false).length;
438
+ const testCount = endpoints.filter((ep) => isJsonObject(ep) && ep.test === true).length;
439
+ if (liveCount > 0) {
440
+ checks.push({
441
+ id: "webhooks",
442
+ label: "Webhook endpoints",
443
+ status: "pass",
444
+ detail: `${liveCount} live endpoint${liveCount === 1 ? "" : "s"} and ${testCount} test endpoint${testCount === 1 ? "" : "s"} configured.`,
445
+ });
446
+ }
447
+ else if (testCount > 0) {
448
+ checks.push({
449
+ id: "webhooks",
450
+ label: "Webhook endpoints",
451
+ status: "info",
452
+ detail: `${testCount} test endpoint${testCount === 1 ? "" : "s"} configured, 0 live endpoints (optional; polling also works).`,
453
+ tryThis: "Add your production HTTPS receiver in Dashboard > Webhooks if you rely on webhooks.",
454
+ });
455
+ }
456
+ else {
457
+ checks.push({
458
+ id: "webhooks",
459
+ label: "Webhook endpoints",
460
+ status: "info",
461
+ detail: "No webhook endpoints configured yet (optional; polling remains available).",
462
+ });
463
+ }
464
+ }
465
+ }
466
+ catch {
467
+ checks.push({
468
+ id: "webhooks",
469
+ label: "Webhook endpoints",
470
+ status: "info",
471
+ detail: "Could not check webhooks (optional; verify in Dashboard > Webhooks if needed).",
472
+ });
473
+ }
474
+ }
475
+ const scan = scanLocalCodebase(cwd);
476
+ if (scan.gitignoreHasEnv) {
477
+ checks.push({
478
+ id: "gitignore",
479
+ label: ".gitignore protects .env",
480
+ status: "pass",
481
+ detail: ".gitignore excludes .env so secrets are not committed.",
482
+ });
483
+ }
484
+ else {
485
+ checks.push({
486
+ id: "gitignore",
487
+ label: ".gitignore protects .env",
488
+ status: "warn",
489
+ detail: scan.gitignoreExists
490
+ ? ".gitignore does not list .env."
491
+ : "No .gitignore file found in this directory.",
492
+ tryThis: "Add `.env` to `.gitignore` so API keys are never committed to git.",
493
+ });
494
+ }
495
+ if (scan.localEnvHasLiveKey) {
496
+ const filesLabel = scan.liveKeyFiles.length > 0 ? scan.liveKeyFiles.join(" and ") : ".env";
497
+ checks.push({
498
+ id: "local-live-key",
499
+ label: "No live key in local .env",
500
+ status: "warn",
501
+ detail: `PCIFIC_LIVE_KEY appears to be set in your local ${filesLabel} file.`,
502
+ tryThis: `Remove PCIFIC_LIVE_KEY from local ${filesLabel} and store it only in your hosting provider's production secrets.`,
503
+ });
504
+ }
505
+ else {
506
+ checks.push({
507
+ id: "local-live-key",
508
+ label: "No live key in local .env",
509
+ status: "pass",
510
+ detail: "Local .env and .env.local stay test-key-only.",
511
+ });
512
+ }
513
+ if (scan.usesPcificMode && scan.usesPcificLiveKey) {
514
+ checks.push({
515
+ id: "codebase-key-selection",
516
+ label: "Codebase key selection (PCIFIC_MODE / PCIFIC_LIVE_KEY)",
517
+ status: "pass",
518
+ detail: `Found PCIFIC_MODE and PCIFIC_LIVE_KEY references in your codebase (${scan.filesScanned} files checked).`,
519
+ });
520
+ }
521
+ else {
522
+ const missing = [];
523
+ if (!scan.usesPcificMode) {
524
+ missing.push("PCIFIC_MODE");
525
+ }
526
+ if (!scan.usesPcificLiveKey) {
527
+ missing.push("PCIFIC_LIVE_KEY");
528
+ }
529
+ checks.push({
530
+ id: "codebase-key-selection",
531
+ label: "Codebase key selection (PCIFIC_MODE / PCIFIC_LIVE_KEY)",
532
+ status: "warn",
533
+ detail: `Did not find ${missing.join(" and ")} in scanned source files (${scan.filesScanned} files checked).`,
534
+ tryThis: "Select between PCIFIC_TEST_KEY and PCIFIC_LIVE_KEY using PCIFIC_MODE (defaulting to test outside production).",
535
+ });
536
+ }
537
+ const runtimeEnv = options.env ?? process.env;
538
+ const shouldOpenBrowser = !keyFailed &&
539
+ !noOpenFlag &&
540
+ !jsonFlag &&
541
+ !plainFlag &&
542
+ !isHeadlessEnv(runtimeEnv, stdout, Boolean(options.openBrowser));
543
+ let browserOpened = false;
544
+ if (shouldOpenBrowser) {
545
+ const opener = options.openBrowser ?? defaultOpenBrowser;
546
+ browserOpened = await opener(dashboardKeysUrl);
547
+ }
548
+ const envVars = {
549
+ PCIFIC_MODE: "live",
550
+ PCIFIC_LIVE_KEY: "<paste from dashboard>",
551
+ };
552
+ if (marketplaceId) {
553
+ envVars.PCIFIC_MARKETPLACE_ID = marketplaceId;
554
+ }
555
+ const mpVercel = marketplaceId
556
+ ? `\n vercel env add PCIFIC_MARKETPLACE_ID production # ${marketplaceId}`
557
+ : "";
558
+ const mpWrangler = marketplaceId
559
+ ? `\n wrangler secret put PCIFIC_MARKETPLACE_ID # ${marketplaceId}`
560
+ : "";
561
+ const mpFly = marketplaceId ? ` PCIFIC_MARKETPLACE_ID="${marketplaceId}"` : "";
562
+ const mpRailway = marketplaceId ? ` --set "PCIFIC_MARKETPLACE_ID=${marketplaceId}"` : "";
563
+ const hostCommands = {
564
+ vercel: `vercel env add PCIFIC_MODE production # live\n vercel env add PCIFIC_LIVE_KEY production${mpVercel}`,
565
+ cloudflareWorkers: `wrangler secret put PCIFIC_MODE # live\n wrangler secret put PCIFIC_LIVE_KEY${mpWrangler}`,
566
+ fly: `fly secrets set PCIFIC_MODE=live PCIFIC_LIVE_KEY="<paste from dashboard>"${mpFly}`,
567
+ railway: `railway variables --set "PCIFIC_MODE=live" --set "PCIFIC_LIVE_KEY=<paste from dashboard>"${mpRailway}`,
568
+ };
569
+ const ready = !checks.some((check) => check.status === "fail");
570
+ if (jsonFlag) {
571
+ let marketplace = null;
572
+ if (marketplaceId) {
573
+ marketplace = { id: marketplaceId };
574
+ if (marketplaceName) {
575
+ marketplace.name = marketplaceName;
576
+ }
577
+ }
578
+ writeOut(stdout, JSON.stringify({
579
+ ready,
580
+ checks,
581
+ marketplace,
582
+ dashboardUrl: dashboardKeysUrl,
583
+ browserOpened,
584
+ envVars,
585
+ hostCommands,
586
+ }));
587
+ return keyFailed ? 1 : 0;
588
+ }
589
+ writeOut(stdout, "PCIFIC Go-Live Preflight");
590
+ writeOut(stdout, "");
591
+ for (const check of checks) {
592
+ const tag = check.status === "pass"
593
+ ? "[PASS]"
594
+ : check.status === "warn"
595
+ ? "[WARN]"
596
+ : check.status === "fail"
597
+ ? "[FAIL]"
598
+ : "[INFO]";
599
+ writeOut(stdout, `${tag} ${check.label}: ${check.detail}`);
600
+ if (check.tryThis) {
601
+ writeOut(stdout, ` Next: ${check.tryThis}`);
602
+ }
603
+ }
604
+ if (keyFailed) {
605
+ return 1;
606
+ }
607
+ writeOut(stdout, "");
608
+ writeOut(stdout, "Create your live key in the PCIFIC dashboard (keep it out of AI chat and local .env):");
609
+ writeOut(stdout, ` ${dashboardKeysUrl}`);
610
+ if (browserOpened) {
611
+ writeOut(stdout, " Opened in your browser.");
612
+ }
613
+ writeOut(stdout, "");
614
+ writeOut(stdout, "Production environment variables:");
615
+ for (const [key, value] of Object.entries(envVars)) {
616
+ writeOut(stdout, ` ${key}=${value}`);
617
+ }
618
+ writeOut(stdout, "");
619
+ writeOut(stdout, "Set production secrets in your host:");
620
+ writeOut(stdout, " Vercel:");
621
+ writeOut(stdout, ` ${hostCommands.vercel}`);
622
+ writeOut(stdout, " Cloudflare Workers:");
623
+ writeOut(stdout, ` ${hostCommands.cloudflareWorkers}`);
624
+ writeOut(stdout, " Fly.io:");
625
+ writeOut(stdout, ` ${hostCommands.fly}`);
626
+ writeOut(stdout, " Railway:");
627
+ writeOut(stdout, ` ${hostCommands.railway}`);
628
+ return 0;
629
+ }