@sentientui/cli 0.2.2 → 0.2.4

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Carlos Sánchez Campos / SentientUI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -8,7 +8,7 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __getProtoOf = Object.getPrototypeOf;
9
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
10
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
12
  var __spreadValues = (a, b) => {
13
13
  for (var prop in b || (b = {}))
14
14
  if (__hasOwnProp.call(b, prop))
@@ -20,11 +20,15 @@ var __spreadValues = (a, b) => {
20
20
  }
21
21
  return a;
22
22
  };
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
23
27
  var __copyProps = (to, from, except, desc) => {
24
28
  if (from && typeof from === "object" || typeof from === "function") {
25
- for (let key2 of __getOwnPropNames(from))
26
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
27
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
32
  }
29
33
  return to;
30
34
  };
@@ -36,6 +40,23 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
36
40
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
41
  mod
38
42
  ));
43
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
44
+
45
+ // src/index.ts
46
+ var index_exports = {};
47
+ __export(index_exports, {
48
+ main: () => main,
49
+ parseArgs: () => parseArgs
50
+ });
51
+ module.exports = __toCommonJS(index_exports);
52
+
53
+ // ../../node_modules/.pnpm/tsup@8.5.1_jiti@1.21.7_postcss@8.5.14_tsx@4.22.1_typescript@5.9.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
54
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
55
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
56
+
57
+ // src/index.ts
58
+ var import_node_fs4 = require("fs");
59
+ var import_node_url = require("url");
39
60
 
40
61
  // src/init.ts
41
62
  var import_node_child_process = require("child_process");
@@ -88,15 +109,25 @@ function installCommand(pm, pkgName) {
88
109
  var import_node_fs2 = require("fs");
89
110
  var import_node_path2 = __toESM(require("path"), 1);
90
111
  function envVarName(framework) {
91
- return framework === "vite" ? "VITE_SENTIENT_API_KEY" : "NEXT_PUBLIC_SENTIENT_API_KEY";
112
+ switch (framework) {
113
+ case "cra":
114
+ return "REACT_APP_SENTIENT_API_KEY";
115
+ case "vite":
116
+ case "remix":
117
+ return "VITE_SENTIENT_API_KEY";
118
+ case "next-app":
119
+ case "next-pages":
120
+ case "unknown":
121
+ return "NEXT_PUBLIC_SENTIENT_API_KEY";
122
+ }
92
123
  }
93
- function writeEnvFile(cwd, framework, key2) {
124
+ function writeEnvFile(cwd, framework, key) {
94
125
  const varName = envVarName(framework);
95
126
  const file = import_node_path2.default.join(cwd, ".env.local");
96
127
  const block = [
97
128
  "",
98
129
  "# SentientUI \u2014 leave empty for local mode (decisions are simulated on-device; nothing is sent)",
99
- `${varName}=${key2 != null ? key2 : ""}`,
130
+ `${varName}=${key != null ? key : ""}`,
100
131
  ""
101
132
  ].join("\n");
102
133
  if (!(0, import_node_fs2.existsSync)(file)) {
@@ -205,7 +236,7 @@ createRoot(document.getElementById('root')!).render(
205
236
  import { AdaptiveProvider } from '@sentientui/react';
206
237
 
207
238
  // inside the Layout/App component body:
208
- <AdaptiveProvider apiKey="" context="landing">
239
+ <AdaptiveProvider apiKey={import.meta.env.${envVar} ?? ''} context="landing">
209
240
  <Outlet />
210
241
  </AdaptiveProvider>`;
211
242
  case "cra":
@@ -236,11 +267,33 @@ function finale(framework) {
236
267
  return `open http://localhost:${port}?sentient_persona=buyer`;
237
268
  }
238
269
 
270
+ // src/validate-key.ts
271
+ function isPublishableKey(key) {
272
+ return key.startsWith("pk_");
273
+ }
274
+ function warnIfNotPublishableKey(key, log = (line) => console.warn(line)) {
275
+ if (!key || isPublishableKey(key)) return false;
276
+ const looksSecret = key.startsWith("sk_");
277
+ log("");
278
+ log("\u26A0 ============================ SECURITY WARNING ============================");
279
+ log(`\u26A0 The key you passed ("${key.slice(0, 6)}\u2026") is NOT a publishable pk_ key.`);
280
+ if (looksSecret) {
281
+ log("\u26A0 It looks like a SECRET server key (sk_\u2026). Do NOT ship it to the browser.");
282
+ }
283
+ log("\u26A0 This CLI writes the key into a CLIENT-exposed env var, so it is bundled");
284
+ log("\u26A0 into your site and visible to every visitor. Only publishable pk_ keys");
285
+ log("\u26A0 belong in client env. Get your pk_ key from the SentientUI dashboard.");
286
+ log("\u26A0 =======================================================================");
287
+ log("");
288
+ return true;
289
+ }
290
+
239
291
  // src/init.ts
240
292
  function runInit(opts) {
241
293
  var _a, _b, _c;
242
294
  const log = (_a = opts.log) != null ? _a : ((line) => console.log(line));
243
- const exec = (_b = opts.exec) != null ? _b : ((command2, cwd) => (0, import_node_child_process.execSync)(command2, { cwd, stdio: "inherit" }));
295
+ const exec = (_b = opts.exec) != null ? _b : ((command, cwd) => (0, import_node_child_process.execSync)(command, { cwd, stdio: "inherit" }));
296
+ warnIfNotPublishableKey(opts.key, log);
244
297
  const framework = detectFramework(opts.cwd);
245
298
  log(`[sentientui] detected framework: ${framework}`);
246
299
  if (framework === "unknown") {
@@ -270,25 +323,47 @@ function runInit(opts) {
270
323
  // src/index.ts
271
324
  function parseArgs(argv) {
272
325
  const args = [...argv];
273
- const command2 = args.shift();
274
- let key2;
326
+ const command = args.shift();
327
+ let key;
275
328
  for (let i = 0; i < args.length; i++) {
276
- if (args[i] === "--key") {
277
- key2 = args[i + 1];
329
+ const arg = args[i];
330
+ if (arg === "--key") {
331
+ key = args[i + 1];
278
332
  i++;
333
+ } else if (arg.startsWith("--key=")) {
334
+ key = arg.slice("--key=".length);
335
+ }
336
+ }
337
+ return { command, key };
338
+ }
339
+ function main(argv) {
340
+ const { command, key } = parseArgs(argv);
341
+ if (command === "init") {
342
+ try {
343
+ runInit({ cwd: process.cwd(), key });
344
+ } catch (err) {
345
+ console.error(`[sentientui] init failed: ${String(err)}`);
346
+ process.exit(1);
279
347
  }
348
+ } else {
349
+ console.log("Usage: npx @sentientui/cli init [--key pk_...] [--yes]");
350
+ process.exit(command ? 1 : 0);
280
351
  }
281
- return { command: command2, key: key2 };
282
352
  }
283
- var { command, key } = parseArgs(process.argv.slice(2));
284
- if (command === "init") {
353
+ function isRunAsScript() {
285
354
  try {
286
- runInit({ cwd: process.cwd(), key });
287
- } catch (err) {
288
- console.error(`[sentientui] init failed: ${String(err)}`);
289
- process.exit(1);
355
+ const entry = process.argv[1];
356
+ if (!entry) return false;
357
+ return (0, import_node_fs4.realpathSync)((0, import_node_url.fileURLToPath)(importMetaUrl)) === (0, import_node_fs4.realpathSync)(entry);
358
+ } catch (e) {
359
+ return false;
290
360
  }
291
- } else {
292
- console.log("Usage: npx @sentientui/cli init [--key pk_...] [--yes]");
293
- process.exit(command ? 1 : 0);
294
361
  }
362
+ if (isRunAsScript()) {
363
+ main(process.argv.slice(2));
364
+ }
365
+ // Annotate the CommonJS export names for ESM import in node:
366
+ 0 && (module.exports = {
367
+ main,
368
+ parseArgs
369
+ });
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
- var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __spreadValues = (a, b) => {
8
8
  for (var prop in b || (b = {}))
9
9
  if (__hasOwnProp.call(b, prop))
@@ -16,6 +16,10 @@ var __spreadValues = (a, b) => {
16
16
  return a;
17
17
  };
18
18
 
19
+ // src/index.ts
20
+ import { realpathSync } from "fs";
21
+ import { fileURLToPath } from "url";
22
+
19
23
  // src/init.ts
20
24
  import { execSync } from "child_process";
21
25
 
@@ -67,15 +71,25 @@ function installCommand(pm, pkgName) {
67
71
  import { existsSync as existsSync2, readFileSync as readFileSync2, appendFileSync, writeFileSync } from "fs";
68
72
  import path2 from "path";
69
73
  function envVarName(framework) {
70
- return framework === "vite" ? "VITE_SENTIENT_API_KEY" : "NEXT_PUBLIC_SENTIENT_API_KEY";
74
+ switch (framework) {
75
+ case "cra":
76
+ return "REACT_APP_SENTIENT_API_KEY";
77
+ case "vite":
78
+ case "remix":
79
+ return "VITE_SENTIENT_API_KEY";
80
+ case "next-app":
81
+ case "next-pages":
82
+ case "unknown":
83
+ return "NEXT_PUBLIC_SENTIENT_API_KEY";
84
+ }
71
85
  }
72
- function writeEnvFile(cwd, framework, key2) {
86
+ function writeEnvFile(cwd, framework, key) {
73
87
  const varName = envVarName(framework);
74
88
  const file = path2.join(cwd, ".env.local");
75
89
  const block = [
76
90
  "",
77
91
  "# SentientUI \u2014 leave empty for local mode (decisions are simulated on-device; nothing is sent)",
78
- `${varName}=${key2 != null ? key2 : ""}`,
92
+ `${varName}=${key != null ? key : ""}`,
79
93
  ""
80
94
  ].join("\n");
81
95
  if (!existsSync2(file)) {
@@ -184,7 +198,7 @@ createRoot(document.getElementById('root')!).render(
184
198
  import { AdaptiveProvider } from '@sentientui/react';
185
199
 
186
200
  // inside the Layout/App component body:
187
- <AdaptiveProvider apiKey="" context="landing">
201
+ <AdaptiveProvider apiKey={import.meta.env.${envVar} ?? ''} context="landing">
188
202
  <Outlet />
189
203
  </AdaptiveProvider>`;
190
204
  case "cra":
@@ -215,11 +229,33 @@ function finale(framework) {
215
229
  return `open http://localhost:${port}?sentient_persona=buyer`;
216
230
  }
217
231
 
232
+ // src/validate-key.ts
233
+ function isPublishableKey(key) {
234
+ return key.startsWith("pk_");
235
+ }
236
+ function warnIfNotPublishableKey(key, log = (line) => console.warn(line)) {
237
+ if (!key || isPublishableKey(key)) return false;
238
+ const looksSecret = key.startsWith("sk_");
239
+ log("");
240
+ log("\u26A0 ============================ SECURITY WARNING ============================");
241
+ log(`\u26A0 The key you passed ("${key.slice(0, 6)}\u2026") is NOT a publishable pk_ key.`);
242
+ if (looksSecret) {
243
+ log("\u26A0 It looks like a SECRET server key (sk_\u2026). Do NOT ship it to the browser.");
244
+ }
245
+ log("\u26A0 This CLI writes the key into a CLIENT-exposed env var, so it is bundled");
246
+ log("\u26A0 into your site and visible to every visitor. Only publishable pk_ keys");
247
+ log("\u26A0 belong in client env. Get your pk_ key from the SentientUI dashboard.");
248
+ log("\u26A0 =======================================================================");
249
+ log("");
250
+ return true;
251
+ }
252
+
218
253
  // src/init.ts
219
254
  function runInit(opts) {
220
255
  var _a, _b, _c;
221
256
  const log = (_a = opts.log) != null ? _a : ((line) => console.log(line));
222
- const exec = (_b = opts.exec) != null ? _b : ((command2, cwd) => execSync(command2, { cwd, stdio: "inherit" }));
257
+ const exec = (_b = opts.exec) != null ? _b : ((command, cwd) => execSync(command, { cwd, stdio: "inherit" }));
258
+ warnIfNotPublishableKey(opts.key, log);
223
259
  const framework = detectFramework(opts.cwd);
224
260
  log(`[sentientui] detected framework: ${framework}`);
225
261
  if (framework === "unknown") {
@@ -247,27 +283,49 @@ function runInit(opts) {
247
283
  }
248
284
 
249
285
  // src/index.ts
286
+ var import_meta = {};
250
287
  function parseArgs(argv) {
251
288
  const args = [...argv];
252
- const command2 = args.shift();
253
- let key2;
289
+ const command = args.shift();
290
+ let key;
254
291
  for (let i = 0; i < args.length; i++) {
255
- if (args[i] === "--key") {
256
- key2 = args[i + 1];
292
+ const arg = args[i];
293
+ if (arg === "--key") {
294
+ key = args[i + 1];
257
295
  i++;
296
+ } else if (arg.startsWith("--key=")) {
297
+ key = arg.slice("--key=".length);
258
298
  }
259
299
  }
260
- return { command: command2, key: key2 };
300
+ return { command, key };
261
301
  }
262
- var { command, key } = parseArgs(process.argv.slice(2));
263
- if (command === "init") {
302
+ function main(argv) {
303
+ const { command, key } = parseArgs(argv);
304
+ if (command === "init") {
305
+ try {
306
+ runInit({ cwd: process.cwd(), key });
307
+ } catch (err) {
308
+ console.error(`[sentientui] init failed: ${String(err)}`);
309
+ process.exit(1);
310
+ }
311
+ } else {
312
+ console.log("Usage: npx @sentientui/cli init [--key pk_...] [--yes]");
313
+ process.exit(command ? 1 : 0);
314
+ }
315
+ }
316
+ function isRunAsScript() {
264
317
  try {
265
- runInit({ cwd: process.cwd(), key });
266
- } catch (err) {
267
- console.error(`[sentientui] init failed: ${String(err)}`);
268
- process.exit(1);
318
+ const entry = process.argv[1];
319
+ if (!entry) return false;
320
+ return realpathSync(fileURLToPath(import_meta.url)) === realpathSync(entry);
321
+ } catch (e) {
322
+ return false;
269
323
  }
270
- } else {
271
- console.log("Usage: npx @sentientui/cli init [--key pk_...] [--yes]");
272
- process.exit(command ? 1 : 0);
273
324
  }
325
+ if (isRunAsScript()) {
326
+ main(process.argv.slice(2));
327
+ }
328
+ export {
329
+ main,
330
+ parseArgs
331
+ };
package/package.json CHANGED
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "name": "@sentientui/cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "SentientUI CLI — `npx @sentientui/cli init` sets up adaptive UI in an existing React app (installs the SDK, writes env config, scaffolds an example, and prints the wrap instructions)",
5
+ "license": "MIT",
6
+ "homepage": "https://sentient-ui.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/casancam/SentientUI.git",
10
+ "directory": "packages/cli"
11
+ },
12
+ "keywords": [
13
+ "cli",
14
+ "sentientui",
15
+ "sentient-ui",
16
+ "personalization",
17
+ "react",
18
+ "scaffolding",
19
+ "conversion-optimization"
20
+ ],
5
21
  "type": "module",
6
22
  "bin": {
7
23
  "sentientui": "./dist/index.js"
@@ -25,6 +41,7 @@
25
41
  "build": "tsup",
26
42
  "test": "vitest run",
27
43
  "typecheck": "tsc --noEmit",
28
- "dev": "tsx src/index.ts"
44
+ "dev": "tsx src/index.ts",
45
+ "lint": "eslint src"
29
46
  }
30
47
  }