@siteping/cli 0.4.1 → 0.4.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.
package/dist/index.js CHANGED
@@ -3391,10 +3391,10 @@ var require_src = __commonJS({
3391
3391
  var require_picocolors = __commonJS({
3392
3392
  "../../node_modules/.bun/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports2, module2) {
3393
3393
  "use strict";
3394
- var p2 = process || {};
3395
- var argv = p2.argv || [];
3396
- var env = p2.env || {};
3397
- var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p2.platform === "win32" || (p2.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
3394
+ var p3 = process || {};
3395
+ var argv = p3.argv || [];
3396
+ var env = p3.env || {};
3397
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p3.platform === "win32" || (p3.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
3398
3398
  var formatter = (open, close, replace = open) => (input) => {
3399
3399
  let string = "" + input, index = string.indexOf(close, open.length);
3400
3400
  return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
@@ -7024,7 +7024,7 @@ var require_model = __commonJS({
7024
7024
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
7025
7025
  d3.__proto__ = b3;
7026
7026
  } || function(d3, b3) {
7027
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
7027
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
7028
7028
  };
7029
7029
  return extendStatics(d2, b2);
7030
7030
  };
@@ -8099,7 +8099,7 @@ var require_follow = __commonJS({
8099
8099
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
8100
8100
  d3.__proto__ = b3;
8101
8101
  } || function(d3, b3) {
8102
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
8102
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
8103
8103
  };
8104
8104
  return extendStatics(d2, b2);
8105
8105
  };
@@ -9458,7 +9458,7 @@ var require_reg_exp = __commonJS({
9458
9458
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
9459
9459
  d3.__proto__ = b3;
9460
9460
  } || function(d3, b3) {
9461
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
9461
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
9462
9462
  };
9463
9463
  return extendStatics(d2, b2);
9464
9464
  };
@@ -9709,7 +9709,7 @@ var require_lexer = __commonJS({
9709
9709
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
9710
9710
  d3.__proto__ = b3;
9711
9711
  } || function(d3, b3) {
9712
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
9712
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
9713
9713
  };
9714
9714
  return extendStatics(d2, b2);
9715
9715
  };
@@ -11507,7 +11507,7 @@ var require_resolver = __commonJS({
11507
11507
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
11508
11508
  d3.__proto__ = b3;
11509
11509
  } || function(d3, b3) {
11510
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
11510
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
11511
11511
  };
11512
11512
  return extendStatics(d2, b2);
11513
11513
  };
@@ -11684,7 +11684,7 @@ var require_interpreter = __commonJS({
11684
11684
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
11685
11685
  d3.__proto__ = b3;
11686
11686
  } || function(d3, b3) {
11687
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
11687
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
11688
11688
  };
11689
11689
  return extendStatics(d2, b2);
11690
11690
  };
@@ -12199,7 +12199,7 @@ var require_lookahead = __commonJS({
12199
12199
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
12200
12200
  d3.__proto__ = b3;
12201
12201
  } || function(d3, b3) {
12202
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
12202
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
12203
12203
  };
12204
12204
  return extendStatics(d2, b2);
12205
12205
  };
@@ -12645,7 +12645,7 @@ var require_checks = __commonJS({
12645
12645
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
12646
12646
  d3.__proto__ = b3;
12647
12647
  } || function(d3, b3) {
12648
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
12648
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
12649
12649
  };
12650
12650
  return extendStatics(d2, b2);
12651
12651
  };
@@ -12663,8 +12663,8 @@ var require_checks = __commonJS({
12663
12663
  __assign = Object.assign || function(t) {
12664
12664
  for (var s, i = 1, n = arguments.length; i < n; i++) {
12665
12665
  s = arguments[i];
12666
- for (var p2 in s) if (Object.prototype.hasOwnProperty.call(s, p2))
12667
- t[p2] = s[p2];
12666
+ for (var p3 in s) if (Object.prototype.hasOwnProperty.call(s, p3))
12667
+ t[p3] = s[p3];
12668
12668
  }
12669
12669
  return t;
12670
12670
  };
@@ -13190,7 +13190,7 @@ var require_exceptions_public = __commonJS({
13190
13190
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
13191
13191
  d3.__proto__ = b3;
13192
13192
  } || function(d3, b3) {
13193
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
13193
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
13194
13194
  };
13195
13195
  return extendStatics(d2, b2);
13196
13196
  };
@@ -13310,7 +13310,7 @@ var require_recoverable = __commonJS({
13310
13310
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
13311
13311
  d3.__proto__ = b3;
13312
13312
  } || function(d3, b3) {
13313
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
13313
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
13314
13314
  };
13315
13315
  return extendStatics(d2, b2);
13316
13316
  };
@@ -13708,7 +13708,7 @@ var require_looksahead = __commonJS({
13708
13708
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
13709
13709
  d3.__proto__ = b3;
13710
13710
  } || function(d3, b3) {
13711
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
13711
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
13712
13712
  };
13713
13713
  return extendStatics(d2, b2);
13714
13714
  };
@@ -15625,7 +15625,7 @@ var require_parser = __commonJS({
15625
15625
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
15626
15626
  d3.__proto__ = b3;
15627
15627
  } || function(d3, b3) {
15628
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
15628
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
15629
15629
  };
15630
15630
  return extendStatics(d2, b2);
15631
15631
  };
@@ -15868,7 +15868,7 @@ var require_model2 = __commonJS({
15868
15868
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d3, b3) {
15869
15869
  d3.__proto__ = b3;
15870
15870
  } || function(d3, b3) {
15871
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d3[p2] = b3[p2];
15871
+ for (var p3 in b3) if (Object.prototype.hasOwnProperty.call(b3, p3)) d3[p3] = b3[p3];
15872
15872
  };
15873
15873
  return extendStatics(d2, b2);
15874
15874
  };
@@ -16222,8 +16222,8 @@ var require_api3 = __commonJS({
16222
16222
  __assign = Object.assign || function(t) {
16223
16223
  for (var s, i = 1, n = arguments.length; i < n; i++) {
16224
16224
  s = arguments[i];
16225
- for (var p2 in s) if (Object.prototype.hasOwnProperty.call(s, p2))
16226
- t[p2] = s[p2];
16225
+ for (var p3 in s) if (Object.prototype.hasOwnProperty.call(s, p3))
16226
+ t[p3] = s[p3];
16227
16227
  }
16228
16228
  return t;
16229
16229
  };
@@ -16834,8 +16834,8 @@ var oD = (t, u2, F = {}) => {
16834
16834
  F.trim !== false && (C[C.length - 1] = C[C.length - 1].trimStart());
16835
16835
  let n = A(C[C.length - 1]);
16836
16836
  if (E2 !== 0 && (n >= u2 && (F.wordWrap === false || F.trim === false) && (C.push(""), n = 0), (n > 0 || F.trim === false) && (C[C.length - 1] += " ", n++)), F.hard && D[E2] > u2) {
16837
- const B2 = u2 - n, p2 = 1 + Math.floor((D[E2] - B2 - 1) / u2);
16838
- Math.floor((D[E2] - 1) / u2) < p2 && C.push(""), _(C, a2, u2);
16837
+ const B2 = u2 - n, p3 = 1 + Math.floor((D[E2] - B2 - 1) / u2);
16838
+ Math.floor((D[E2] - 1) / u2) < p3 && C.push(""), _(C, a2, u2);
16839
16839
  continue;
16840
16840
  }
16841
16841
  if (n + D[E2] > u2 && n > 0 && D[E2] > 0) {
@@ -16858,8 +16858,8 @@ var oD = (t, u2, F = {}) => {
16858
16858
  if (e2 += a2, v.has(a2)) {
16859
16859
  const { groups: B2 } = new RegExp(`(?:\\${W}(?<code>\\d+)m|\\${y}(?<uri>.*)${w})`).exec(o.slice(E2).join("")) || { groups: {} };
16860
16860
  if (B2.code !== void 0) {
16861
- const p2 = Number.parseFloat(B2.code);
16862
- s = p2 === CD ? void 0 : p2;
16861
+ const p3 = Number.parseFloat(B2.code);
16862
+ s = p3 === CD ? void 0 : p3;
16863
16863
  } else B2.uri !== void 0 && (i = B2.uri.length === 0 ? void 0 : B2.uri);
16864
16864
  }
16865
16865
  const n = iD.codes.get(Number(s));
@@ -17221,58 +17221,85 @@ var L2 = () => {
17221
17221
  } };
17222
17222
  };
17223
17223
 
17224
+ // src/prompts.ts
17225
+ var p2 = {
17226
+ cancel: ve,
17227
+ confirm: me,
17228
+ intro: we,
17229
+ isCancel: BD,
17230
+ log: v2,
17231
+ note: ye,
17232
+ outro: fe,
17233
+ spinner: L2,
17234
+ text: ue
17235
+ };
17236
+
17224
17237
  // src/commands/doctor.ts
17225
17238
  async function doctorCommand(options) {
17226
- we("siteping \u2014 Diagnostic r\xE9seau");
17227
- const url = options.url ?? await ue({
17228
- message: "URL du serveur de d\xE9veloppement",
17239
+ p2.intro("siteping \u2014 Network diagnostics");
17240
+ const url = options.url ?? await p2.text({
17241
+ message: "Development server URL",
17229
17242
  placeholder: "http://localhost:3000",
17230
17243
  defaultValue: "http://localhost:3000"
17231
17244
  });
17232
- if (BD(url)) {
17233
- ve("Annul\xE9.");
17245
+ if (p2.isCancel(url)) {
17246
+ p2.cancel("Cancelled.");
17234
17247
  process.exit(0);
17235
17248
  }
17236
- const endpoint = options.endpoint ?? await ue({
17237
- message: "Chemin de l'endpoint API",
17249
+ if (!/^https?:\/\//.test(url)) {
17250
+ p2.log.error("URL must start with http:// or https://");
17251
+ process.exit(1);
17252
+ }
17253
+ const endpoint = options.endpoint ?? await p2.text({
17254
+ message: "API endpoint path",
17238
17255
  placeholder: "/api/siteping",
17239
17256
  defaultValue: "/api/siteping"
17240
17257
  });
17241
- if (BD(endpoint)) {
17242
- ve("Annul\xE9.");
17258
+ if (p2.isCancel(endpoint)) {
17259
+ p2.cancel("Cancelled.");
17243
17260
  process.exit(0);
17244
17261
  }
17245
- const fullUrl = `${url}${endpoint}?projectName=__siteping_health_check__`;
17246
- const spinner = L2();
17247
- spinner.start(`Test de connexion \xE0 ${url}${endpoint}`);
17262
+ const projectName = "__siteping_health_check__";
17263
+ const fullUrl = new URL(`${endpoint}?projectName=${encodeURIComponent(projectName)}`, url).toString();
17264
+ const spinner = p2.spinner();
17265
+ spinner.start(`Testing connection to ${url}${endpoint}`);
17248
17266
  try {
17249
17267
  const start = performance.now();
17250
- const response = await fetch(fullUrl);
17268
+ const response = await fetch(fullUrl, { signal: AbortSignal.timeout(1e4) });
17251
17269
  const elapsed = Math.round(performance.now() - start);
17252
17270
  if (response.ok) {
17253
- const data = await response.json();
17254
- spinner.stop(`Connexion r\xE9ussie (${elapsed}ms)`);
17271
+ let data;
17272
+ try {
17273
+ data = await response.json();
17274
+ } catch {
17275
+ data = null;
17276
+ }
17277
+ spinner.stop(`Connection successful (${elapsed}ms)`);
17255
17278
  if (data && typeof data.total === "number") {
17256
- v2.success(`API fonctionnelle \u2014 ${data.total} feedback(s) trouv\xE9(s)`);
17279
+ p2.log.success(`API is working \u2014 ${data.total} feedback(s) found`);
17257
17280
  } else {
17258
- v2.warn("R\xE9ponse inattendue \u2014 v\xE9rifiez que l'endpoint utilise createSitepingHandler()");
17281
+ p2.log.warn("Unexpected response \u2014 make sure the endpoint uses createSitepingHandler()");
17259
17282
  }
17260
17283
  } else {
17261
- spinner.stop(`Erreur HTTP ${response.status} (${elapsed}ms)`);
17284
+ spinner.stop(`HTTP error ${response.status} (${elapsed}ms)`);
17262
17285
  const text = await response.text().catch(() => "");
17263
- v2.error(`Le serveur a r\xE9pondu : ${response.status} ${response.statusText}`);
17264
- if (text) v2.info(text.slice(0, 200));
17286
+ p2.log.error(`Server responded with: ${response.status} ${response.statusText}`);
17287
+ if (text) p2.log.info(text.slice(0, 200));
17288
+ process.exit(1);
17265
17289
  }
17266
17290
  } catch (error) {
17267
- spinner.stop("Connexion \xE9chou\xE9e");
17268
- if (error instanceof TypeError && String(error).includes("fetch")) {
17269
- v2.error("Impossible de se connecter \u2014 le serveur est-il lanc\xE9 ?");
17270
- v2.info(`V\xE9rifiez que ${url} est accessible`);
17291
+ spinner.stop("Connection failed");
17292
+ if (error instanceof DOMException && error.name === "TimeoutError") {
17293
+ p2.log.error("Request timed out after 10 seconds");
17294
+ } else if (error instanceof TypeError && String(error).includes("fetch")) {
17295
+ p2.log.error("Unable to connect \u2014 is the server running?");
17296
+ p2.log.info(`Check that ${url} is reachable`);
17271
17297
  } else {
17272
- v2.error(`Erreur : ${error instanceof Error ? error.message : String(error)}`);
17298
+ p2.log.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
17273
17299
  }
17300
+ process.exit(1);
17274
17301
  }
17275
- fe("Diagnostic termin\xE9");
17302
+ p2.outro("Diagnostics complete");
17276
17303
  }
17277
17304
 
17278
17305
  // src/generators/prisma.ts
@@ -17328,12 +17355,12 @@ function _inheritsLoose(subClass, superClass) {
17328
17355
  subClass.prototype.constructor = subClass;
17329
17356
  _setPrototypeOf(subClass, superClass);
17330
17357
  }
17331
- function _setPrototypeOf(o, p2) {
17332
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p3) {
17333
- o2.__proto__ = p3;
17358
+ function _setPrototypeOf(o, p3) {
17359
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p4) {
17360
+ o2.__proto__ = p4;
17334
17361
  return o2;
17335
17362
  };
17336
- return _setPrototypeOf(o, p2);
17363
+ return _setPrototypeOf(o, p3);
17337
17364
  }
17338
17365
  var Identifier = /* @__PURE__ */ createToken({
17339
17366
  name: "Identifier",
@@ -18443,13 +18470,13 @@ function computePropertyFormatting(list) {
18443
18470
  }
18444
18471
 
18445
18472
  // ../core/src/schema.ts
18446
- var SITEPING_MODELS = {
18473
+ var _SITEPING_MODELS = {
18447
18474
  SitepingFeedback: {
18448
18475
  fields: {
18449
18476
  id: { type: "String", isId: true, default: "cuid()" },
18450
18477
  projectName: { type: "String" },
18451
18478
  type: { type: "String" },
18452
- message: { type: "String" },
18479
+ message: { type: "String", nativeType: "Text" },
18453
18480
  status: { type: "String", default: '"open"' },
18454
18481
  url: { type: "String" },
18455
18482
  viewport: { type: "String" },
@@ -18459,12 +18486,13 @@ var SITEPING_MODELS = {
18459
18486
  clientId: { type: "String", isUnique: true },
18460
18487
  resolvedAt: { type: "DateTime", optional: true },
18461
18488
  createdAt: { type: "DateTime", default: "now()" },
18489
+ updatedAt: { type: "DateTime", isUpdatedAt: true },
18462
18490
  annotations: {
18463
18491
  type: "SitepingAnnotation",
18464
18492
  relation: { kind: "1-to-many", model: "SitepingAnnotation" }
18465
18493
  }
18466
18494
  },
18467
- indexes: [{ fields: ["projectName"] }]
18495
+ indexes: [{ fields: ["projectName"] }, { fields: ["projectName", "status", "createdAt"] }]
18468
18496
  },
18469
18497
  SitepingAnnotation: {
18470
18498
  fields: {
@@ -18480,15 +18508,15 @@ var SITEPING_MODELS = {
18480
18508
  onDelete: "Cascade"
18481
18509
  }
18482
18510
  },
18483
- cssSelector: { type: "String" },
18484
- xpath: { type: "String" },
18485
- textSnippet: { type: "String" },
18511
+ cssSelector: { type: "String", nativeType: "Text" },
18512
+ xpath: { type: "String", nativeType: "Text" },
18513
+ textSnippet: { type: "String", nativeType: "Text" },
18486
18514
  elementTag: { type: "String" },
18487
18515
  elementId: { type: "String", optional: true },
18488
- textPrefix: { type: "String" },
18489
- textSuffix: { type: "String" },
18516
+ textPrefix: { type: "String", nativeType: "Text" },
18517
+ textSuffix: { type: "String", nativeType: "Text" },
18490
18518
  fingerprint: { type: "String" },
18491
- neighborText: { type: "String" },
18519
+ neighborText: { type: "String", nativeType: "Text" },
18492
18520
  xPct: { type: "Float" },
18493
18521
  yPct: { type: "Float" },
18494
18522
  wPct: { type: "Float" },
@@ -18503,12 +18531,13 @@ var SITEPING_MODELS = {
18503
18531
  indexes: [{ fields: ["feedbackId"] }]
18504
18532
  }
18505
18533
  };
18534
+ var SITEPING_MODELS = Object.freeze(_SITEPING_MODELS);
18506
18535
 
18507
18536
  // src/generators/prisma.ts
18508
18537
  var DEFAULT_SCHEMA_PATH = "prisma/schema.prisma";
18509
18538
  function syncPrismaModels(schemaPath = DEFAULT_SCHEMA_PATH) {
18510
18539
  if (!existsSync(schemaPath)) {
18511
- throw new Error(`Fichier schema introuvable : ${schemaPath}`);
18540
+ throw new Error(`Schema file not found: ${schemaPath}`);
18512
18541
  }
18513
18542
  const source = readFileSync(schemaPath, "utf-8");
18514
18543
  const schema = getSchema(source);
@@ -18570,7 +18599,7 @@ function syncPrismaModels(schemaPath = DEFAULT_SCHEMA_PATH) {
18570
18599
  }
18571
18600
  if (fieldsToAdd.length > 0) {
18572
18601
  const createdAtIdx = existingModel.properties.findIndex(
18573
- (p2) => p2.type === "field" && p2.name === "createdAt"
18602
+ (p3) => p3.type === "field" && p3.name === "createdAt"
18574
18603
  );
18575
18604
  if (createdAtIdx >= 0) {
18576
18605
  existingModel.properties.splice(createdAtIdx, 0, ...fieldsToAdd);
@@ -18594,7 +18623,15 @@ function syncPrismaModels(schemaPath = DEFAULT_SCHEMA_PATH) {
18594
18623
  }
18595
18624
  if (addedModels.length > 0 || changes.length > 0) {
18596
18625
  const output = printSchema(schema);
18597
- writeFileSync(schemaPath, output, "utf-8");
18626
+ try {
18627
+ writeFileSync(schemaPath, output, "utf-8");
18628
+ } catch (error) {
18629
+ const code = error.code;
18630
+ if (code === "EACCES" || code === "EPERM") {
18631
+ throw new Error(`Permission denied: cannot write to ${schemaPath}. Check file permissions.`);
18632
+ }
18633
+ throw error;
18634
+ }
18598
18635
  }
18599
18636
  return { schemaPath, addedModels, changes };
18600
18637
  }
@@ -18602,10 +18639,11 @@ function fieldsMatch(existing, expected) {
18602
18639
  if (existing.fieldType !== expected.fieldType) return false;
18603
18640
  if ((existing.optional ?? false) !== (expected.optional ?? false)) return false;
18604
18641
  if ((existing.array ?? false) !== (expected.array ?? false)) return false;
18605
- const existingAttrs = (existing.attributes ?? []).map((a2) => a2.name).sort();
18606
- const expectedAttrs = (expected.attributes ?? []).map((a2) => a2.name).sort();
18642
+ const attrKey = (a2) => a2.group ? `${a2.group}.${a2.name}` : a2.name;
18643
+ const existingAttrs = (existing.attributes ?? []).map(attrKey).sort();
18644
+ const expectedAttrs = (expected.attributes ?? []).map(attrKey).sort();
18607
18645
  if (existingAttrs.length !== expectedAttrs.length) return false;
18608
- return existingAttrs.every((name, i) => name === expectedAttrs[i]);
18646
+ return existingAttrs.every((key, i) => key === expectedAttrs[i]);
18609
18647
  }
18610
18648
  function describeChange(existing, expected) {
18611
18649
  const parts = [];
@@ -18613,17 +18651,18 @@ function describeChange(existing, expected) {
18613
18651
  parts.push(`${existing.fieldType} \u2192 ${expected.fieldType}`);
18614
18652
  }
18615
18653
  if ((existing.optional ?? false) !== (expected.optional ?? false)) {
18616
- parts.push(expected.optional ? "requis \u2192 optionnel" : "optionnel \u2192 requis");
18654
+ parts.push(expected.optional ? "required \u2192 optional" : "optional \u2192 required");
18617
18655
  }
18618
- const existingAttrs = new Set((existing.attributes ?? []).map((a2) => a2.name));
18619
- const expectedAttrs = new Set((expected.attributes ?? []).map((a2) => a2.name));
18656
+ const attrKey = (a2) => a2.group ? `${a2.group}.${a2.name}` : a2.name;
18657
+ const existingAttrs = new Set((existing.attributes ?? []).map(attrKey));
18658
+ const expectedAttrs = new Set((expected.attributes ?? []).map(attrKey));
18620
18659
  for (const attr of expectedAttrs) {
18621
18660
  if (!existingAttrs.has(attr)) parts.push(`+@${attr}`);
18622
18661
  }
18623
18662
  for (const attr of existingAttrs) {
18624
18663
  if (!expectedAttrs.has(attr)) parts.push(`-@${attr}`);
18625
18664
  }
18626
- return parts.join(", ") || "attributs modifi\xE9s";
18665
+ return parts.join(", ") || "attributes changed";
18627
18666
  }
18628
18667
  function formatFieldSignature(def) {
18629
18668
  let sig = def.type;
@@ -18668,6 +18707,12 @@ function buildField(name, def) {
18668
18707
  ]
18669
18708
  });
18670
18709
  }
18710
+ if (def.nativeType) {
18711
+ field.attributes.push({ type: "attribute", name: def.nativeType, kind: "field", group: "db" });
18712
+ }
18713
+ if (def.isUpdatedAt) {
18714
+ field.attributes.push({ type: "attribute", name: "updatedAt", kind: "field" });
18715
+ }
18671
18716
  if (def.isUnique) {
18672
18717
  field.attributes.push({ type: "attribute", name: "unique", kind: "field" });
18673
18718
  }
@@ -18715,9 +18760,9 @@ function buildBlockIndex(idx) {
18715
18760
  }
18716
18761
  function hasBlockIndex(model, idx) {
18717
18762
  const key = idx.fields.join(",");
18718
- return model.properties.some((p2) => {
18719
- if (p2.type !== "attribute" || p2.name !== "index") return false;
18720
- const attr = p2;
18763
+ return model.properties.some((p3) => {
18764
+ if (p3.type !== "attribute" || p3.name !== "index") return false;
18765
+ const attr = p3;
18721
18766
  const firstArg = attr.args?.[0];
18722
18767
  if (!firstArg || firstArg.type !== "attributeArgument") return false;
18723
18768
  const val = firstArg.value;
@@ -18734,19 +18779,32 @@ import { dirname, join } from "path";
18734
18779
  var ROUTE_TEMPLATE = `import { createSitepingHandler } from "@siteping/adapter-prisma";
18735
18780
  import { prisma } from "@/lib/prisma";
18736
18781
 
18737
- export const { GET, POST, PATCH, DELETE } = createSitepingHandler({ prisma });
18782
+ export const { GET, POST, PATCH, DELETE, OPTIONS } = createSitepingHandler({
18783
+ prisma,
18784
+ // Uncomment to require authentication:
18785
+ // apiKey: process.env.SITEPING_API_KEY,
18786
+ // allowedOrigins: ["https://your-site.com"],
18787
+ });
18738
18788
  `;
18739
18789
  function generateRoute(basePath = process.cwd()) {
18740
18790
  const appDir = existsSync2(join(basePath, "src", "app")) ? join(basePath, "src", "app") : join(basePath, "app");
18741
18791
  if (!existsSync2(appDir)) {
18742
- throw new Error("Impossible de trouver le dossier app/. \xCAtes-vous dans un projet Next.js App Router ?");
18792
+ throw new Error("Cannot find the app/ directory. Are you in a Next.js App Router project?");
18743
18793
  }
18744
18794
  const routePath = join(appDir, "api", "siteping", "route.ts");
18745
18795
  if (existsSync2(routePath)) {
18746
18796
  return { created: false, path: routePath };
18747
18797
  }
18748
- mkdirSync(dirname(routePath), { recursive: true });
18749
- writeFileSync2(routePath, ROUTE_TEMPLATE, "utf-8");
18798
+ try {
18799
+ mkdirSync(dirname(routePath), { recursive: true });
18800
+ writeFileSync2(routePath, ROUTE_TEMPLATE, "utf-8");
18801
+ } catch (error) {
18802
+ const code = error.code;
18803
+ if (code === "EACCES" || code === "EPERM") {
18804
+ throw new Error(`Permission denied: cannot write to ${routePath}. Check file permissions.`);
18805
+ }
18806
+ throw error;
18807
+ }
18750
18808
  return { created: true, path: routePath };
18751
18809
  }
18752
18810
 
@@ -18759,81 +18817,85 @@ function findPrismaSchema(cwd) {
18759
18817
  join2(cwd, "schema.prisma"),
18760
18818
  join2(cwd, "prisma", "schema", "schema.prisma")
18761
18819
  ];
18762
- return candidates.find((p2) => existsSync3(p2)) ?? null;
18820
+ return candidates.find((p3) => existsSync3(p3)) ?? null;
18763
18821
  }
18764
18822
 
18765
18823
  // src/commands/init.ts
18766
18824
  async function initCommand() {
18767
- we("siteping \u2014 Configuration");
18825
+ p2.intro("siteping \u2014 Setup");
18768
18826
  const cwd = process.cwd();
18769
18827
  const schemaPath = findPrismaSchema(cwd);
18770
18828
  if (schemaPath) {
18771
- v2.info(`Schema Prisma trouv\xE9 : ${schemaPath}`);
18772
- const shouldSync = await me({
18773
- message: "Synchroniser les mod\xE8les Siteping dans le schema Prisma ?"
18829
+ p2.log.info(`Prisma schema found: ${schemaPath}`);
18830
+ const shouldSync = await p2.confirm({
18831
+ message: "Sync Siteping models to your Prisma schema?"
18774
18832
  });
18775
- if (BD(shouldSync)) {
18776
- ve("Annul\xE9.");
18833
+ if (p2.isCancel(shouldSync)) {
18834
+ p2.cancel("Cancelled.");
18777
18835
  process.exit(0);
18778
18836
  }
18779
18837
  if (shouldSync) {
18780
18838
  try {
18781
18839
  const { addedModels, changes } = syncPrismaModels(schemaPath);
18782
18840
  if (addedModels.length > 0) {
18783
- v2.success(`Mod\xE8les cr\xE9\xE9s : ${addedModels.join(", ")}`);
18841
+ p2.log.success(`Models synced: ${addedModels.join(", ")}`);
18784
18842
  }
18785
18843
  for (const change of changes) {
18786
18844
  if (change.action === "added") {
18787
- v2.success(`${change.model}.${change.field} \u2014 ajout\xE9 (${change.detail})`);
18845
+ p2.log.success(`${change.model}.${change.field} \u2014 added (${change.detail})`);
18788
18846
  } else {
18789
- v2.success(`${change.model}.${change.field} \u2014 mis \xE0 jour (${change.detail})`);
18847
+ p2.log.success(`${change.model}.${change.field} \u2014 updated (${change.detail})`);
18790
18848
  }
18791
18849
  }
18792
18850
  if (addedModels.length === 0 && changes.length === 0) {
18793
- v2.info("Le schema est d\xE9j\xE0 \xE0 jour.");
18851
+ p2.log.info("Schema is already up to date.");
18794
18852
  }
18795
18853
  } catch (error) {
18796
- v2.error(`Erreur : ${error instanceof Error ? error.message : String(error)}`);
18854
+ p2.log.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
18855
+ p2.outro("Fix the errors above and re-run `siteping init`.");
18856
+ process.exit(1);
18797
18857
  }
18798
18858
  }
18799
18859
  } else {
18800
- v2.warn("Aucun fichier schema.prisma trouv\xE9. Vous devrez ajouter les mod\xE8les manuellement.");
18801
- v2.info("Consultez la documentation : https://github.com/NeosiaNexus/SitePing#prisma-schema-1");
18860
+ p2.log.warn("No schema.prisma file found. You will need to add the models manually.");
18861
+ p2.log.info("See the documentation: https://github.com/NeosiaNexus/SitePing#prisma-schema-1");
18802
18862
  }
18803
- const shouldRoute = await me({
18804
- message: "G\xE9n\xE9rer la route API Next.js App Router ?"
18863
+ const shouldRoute = await p2.confirm({
18864
+ message: "Generate the Next.js App Router API route?"
18805
18865
  });
18806
- if (BD(shouldRoute)) {
18807
- ve("Annul\xE9.");
18866
+ if (p2.isCancel(shouldRoute)) {
18867
+ p2.cancel("Cancelled.");
18808
18868
  process.exit(0);
18809
18869
  }
18810
18870
  if (shouldRoute) {
18811
18871
  try {
18812
18872
  const { created, path } = generateRoute(cwd);
18813
18873
  if (created) {
18814
- v2.success(`Route cr\xE9\xE9e : ${path}`);
18874
+ p2.log.success(`Route created: ${path}`);
18815
18875
  } else {
18816
- v2.info(`La route existe d\xE9j\xE0 : ${path}`);
18876
+ p2.log.info(`Route already exists: ${path}`);
18817
18877
  }
18818
18878
  } catch (error) {
18819
- v2.error(`Erreur : ${error instanceof Error ? error.message : String(error)}`);
18879
+ p2.log.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
18880
+ p2.outro("Fix the errors above and re-run `siteping init`.");
18881
+ process.exit(1);
18820
18882
  }
18821
18883
  }
18822
- ye(
18884
+ p2.note(
18823
18885
  [
18824
- "1. Ex\xE9cutez : npx prisma db push",
18825
- "2. Ajoutez le widget dans votre layout :",
18886
+ "1. Run: npx prisma db push",
18887
+ "2. Add the widget to your layout:",
18826
18888
  "",
18827
18889
  ' import { initSiteping } from "@siteping/widget"',
18828
18890
  "",
18829
18891
  " initSiteping({",
18830
18892
  ' endpoint: "/api/siteping",',
18831
- ' projectName: "mon-projet",',
18893
+ ' projectName: "my-project",',
18832
18894
  " })"
18833
18895
  ].join("\n"),
18834
- "Prochaines \xE9tapes"
18896
+ "Next steps"
18835
18897
  );
18836
- fe("Configuration termin\xE9e !");
18898
+ p2.outro("Setup complete!");
18837
18899
  }
18838
18900
 
18839
18901
  // src/commands/status.ts
@@ -18941,35 +19003,33 @@ function pad(label, width) {
18941
19003
  }
18942
19004
  function statusCommand(options) {
18943
19005
  const cwd = process.cwd();
18944
- we("siteping \u2014 Diagnostic");
19006
+ we("siteping \u2014 Status");
18945
19007
  const schemaPath = options.schema ?? findPrismaSchema(cwd);
18946
19008
  const schemaResult = checkSchema(schemaPath);
18947
19009
  if (!schemaResult.found) {
18948
- v2.error(`${pad("Prisma schema", 25)}\u2717 Non trouv\xE9`);
19010
+ v2.error(`${pad("Prisma schema", 25)}Not found`);
18949
19011
  } else {
18950
19012
  const issues = [
18951
- ...schemaResult.missingModels.map((m3) => `mod\xE8le ${m3}`),
19013
+ ...schemaResult.missingModels.map((m3) => `model ${m3}`),
18952
19014
  ...schemaResult.missingFields,
18953
19015
  ...schemaResult.outdatedFields
18954
19016
  ];
18955
19017
  if (issues.length === 0) {
18956
- v2.success(`${pad("Prisma schema", 25)}\u2713 \xC0 jour`);
19018
+ v2.success(`${pad("Prisma schema", 25)}Up to date`);
18957
19019
  } else {
18958
19020
  const missingCount = schemaResult.missingModels.length + schemaResult.missingFields.length;
18959
19021
  const outdatedCount = schemaResult.outdatedFields.length;
18960
19022
  const parts = [];
18961
- if (missingCount > 0)
18962
- parts.push(`${missingCount} champ${missingCount > 1 ? "s" : ""} manquant${missingCount > 1 ? "s" : ""}`);
18963
- if (outdatedCount > 0)
18964
- parts.push(`${outdatedCount} champ${outdatedCount > 1 ? "s" : ""} obsol\xE8te${outdatedCount > 1 ? "s" : ""}`);
18965
- v2.warn(`${pad("Prisma schema", 25)}\u26A0 ${parts.join(", ")} (${issues.join(", ")})`);
19023
+ if (missingCount > 0) parts.push(`${missingCount} missing field${missingCount > 1 ? "s" : ""}`);
19024
+ if (outdatedCount > 0) parts.push(`${outdatedCount} outdated field${outdatedCount > 1 ? "s" : ""}`);
19025
+ v2.warn(`${pad("Prisma schema", 25)}${parts.join(", ")} (${issues.join(", ")})`);
18966
19026
  }
18967
19027
  }
18968
19028
  const routePath = findApiRoute(cwd);
18969
19029
  if (routePath) {
18970
- v2.success(`${pad("Route API", 25)}\u2713 ${relative(cwd, routePath)}`);
19030
+ v2.success(`${pad("API route", 25)}${relative(cwd, routePath)}`);
18971
19031
  } else {
18972
- v2.error(`${pad("Route API", 25)}\u2717 Non trouv\xE9e`);
19032
+ v2.error(`${pad("API route", 25)}Not found`);
18973
19033
  }
18974
19034
  const pkg = readPackageJson(cwd);
18975
19035
  if (pkg) {
@@ -18977,27 +19037,28 @@ function statusCommand(options) {
18977
19037
  const devDeps = pkg.devDependencies ?? {};
18978
19038
  const version = deps["@siteping/widget"] ?? devDeps["@siteping/widget"];
18979
19039
  if (version) {
18980
- v2.success(`${pad("Package", 25)}\u2713 @siteping/widget@${version}`);
19040
+ v2.success(`${pad("Package", 25)}@siteping/widget@${version}`);
18981
19041
  } else {
18982
- v2.error(`${pad("Package", 25)}\u2717 @siteping/widget non trouv\xE9 dans package.json`);
19042
+ v2.error(`${pad("Package", 25)}@siteping/widget not found in package.json`);
18983
19043
  }
18984
19044
  } else {
18985
- v2.error(`${pad("Package", 25)}\u2717 package.json non trouv\xE9`);
19045
+ v2.error(`${pad("Package", 25)}package.json not found`);
18986
19046
  }
18987
19047
  const widgetFile = findWidgetUsage(cwd);
18988
19048
  if (widgetFile) {
18989
- v2.success(`${pad("Widget int\xE9gr\xE9", 25)}\u2713 trouv\xE9 dans ${relative(cwd, widgetFile)}`);
19049
+ v2.success(`${pad("Widget integration", 25)}found in ${relative(cwd, widgetFile)}`);
18990
19050
  } else {
18991
- v2.warn(`${pad("Widget int\xE9gr\xE9", 25)}\u26A0 initSiteping non trouv\xE9 dans les sources`);
19051
+ v2.warn(`${pad("Widget integration", 25)}initSiteping not found in source files`);
18992
19052
  }
18993
19053
  const hasError = !schemaResult.found || !routePath || !pkg || pkg && !(pkg.dependencies?.["@siteping/widget"] ?? pkg.devDependencies?.["@siteping/widget"]);
18994
19054
  const hasWarning = schemaResult.missingModels.length > 0 || schemaResult.missingFields.length > 0 || schemaResult.outdatedFields.length > 0 || !widgetFile;
18995
19055
  if (hasError) {
18996
- fe("Des \xE9l\xE9ments sont manquants \u2014 lancez `siteping init` pour configurer.");
19056
+ fe("Some items are missing \u2014 run `siteping init` to set up.");
19057
+ process.exit(1);
18997
19058
  } else if (hasWarning) {
18998
- fe("Quelques ajustements n\xE9cessaires \u2014 lancez `siteping sync` pour mettre \xE0 jour.");
19059
+ fe("Some adjustments needed \u2014 run `siteping sync` to update.");
18999
19060
  } else {
19000
- fe("Tout est configur\xE9 !");
19061
+ fe("Everything is set up!");
19001
19062
  }
19002
19063
  }
19003
19064
 
@@ -19007,44 +19068,44 @@ function syncCommand(options) {
19007
19068
  const cwd = process.cwd();
19008
19069
  const schemaPath = options.schema ?? findPrismaSchema(cwd);
19009
19070
  if (!schemaPath) {
19010
- v2.error("Aucun fichier schema.prisma trouv\xE9.");
19011
- v2.info("Sp\xE9cifiez le chemin avec --schema <path>");
19071
+ v2.error("No schema.prisma file found.");
19072
+ v2.info("Specify the path with --schema <path>");
19012
19073
  process.exit(1);
19013
19074
  }
19014
19075
  if (!existsSync5(schemaPath)) {
19015
- v2.error(`Fichier introuvable : ${schemaPath}`);
19076
+ v2.error(`File not found: ${schemaPath}`);
19016
19077
  process.exit(1);
19017
19078
  }
19018
19079
  try {
19019
19080
  const { addedModels, changes } = syncPrismaModels(schemaPath);
19020
19081
  if (addedModels.length === 0 && changes.length === 0) {
19021
- v2.info("\u2713 Le schema est d\xE9j\xE0 \xE0 jour.");
19082
+ v2.info("Schema is already up to date.");
19022
19083
  return;
19023
19084
  }
19024
19085
  if (addedModels.length > 0) {
19025
- v2.success(`Mod\xE8les cr\xE9\xE9s : ${addedModels.join(", ")}`);
19086
+ v2.success(`Models synced: ${addedModels.join(", ")}`);
19026
19087
  }
19027
19088
  for (const change of changes) {
19028
19089
  const icon = change.action === "added" ? "+" : "~";
19029
19090
  v2.success(
19030
- `${icon} ${change.model}.${change.field} \u2014 ${change.action === "added" ? "ajout\xE9" : "mis \xE0 jour"} (${change.detail})`
19091
+ `${icon} ${change.model}.${change.field} \u2014 ${change.action === "added" ? "added" : "updated"} (${change.detail})`
19031
19092
  );
19032
19093
  }
19033
- v2.info("N'oubliez pas : npx prisma db push");
19094
+ v2.info("Don't forget to run: npx prisma db push");
19034
19095
  } catch (error) {
19035
- v2.error(`Erreur : ${error instanceof Error ? error.message : String(error)}`);
19096
+ v2.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
19036
19097
  process.exit(1);
19037
19098
  }
19038
19099
  }
19039
19100
 
19040
19101
  // src/index.ts
19041
- var program2 = new Command().name("siteping").description("CLI pour configurer @siteping/*").version("0.4.1");
19042
- program2.command("init").description("Configure le schema Prisma et la route API dans votre projet").action(initCommand).addHelpText("after", "\n Examples:\n $ siteping init\n $ siteping init --schema prisma/schema.prisma");
19043
- program2.command("sync").description("Synchronise le schema Prisma (non-interactif, CI-friendly)").option("--schema <path>", "Chemin vers le fichier schema.prisma").action(syncCommand).addHelpText("after", "\n Examples:\n $ siteping sync\n $ siteping sync --schema prisma/schema.prisma");
19044
- program2.command("status").description("Diagnostic complet de l'int\xE9gration Siteping").option("--schema <path>", "Chemin vers le fichier schema.prisma").action(statusCommand);
19045
- program2.command("doctor").description("Test de connexion \xE0 l'API Siteping").option("--url <url>", "URL du serveur (d\xE9faut: http://localhost:3000)").option("--endpoint <path>", "Chemin de l'endpoint (d\xE9faut: /api/siteping)").action(doctorCommand).addHelpText(
19102
+ var program2 = new Command().name("siteping").description("CLI to configure @siteping/* in your project").version("0.4.3");
19103
+ program2.command("init").description("Set up the Prisma schema and API route in your project").action(initCommand).addHelpText("after", "\n Examples:\n $ siteping init");
19104
+ program2.command("sync").description("Sync the Prisma schema (non-interactive, CI-friendly)").option("--schema <path>", "Path to the schema.prisma file").action(syncCommand).addHelpText("after", "\n Examples:\n $ siteping sync\n $ siteping sync --schema prisma/schema.prisma");
19105
+ program2.command("status").description("Full diagnostic of the Siteping integration").option("--schema <path>", "Path to the schema.prisma file").action(statusCommand).addHelpText("after", "\n Examples:\n $ siteping status\n $ siteping status --schema prisma/schema.prisma");
19106
+ program2.command("doctor").description("Test the connection to the Siteping API").option("--url <url>", "Server URL (default: http://localhost:3000)").option("--endpoint <path>", "Endpoint path (default: /api/siteping)").action(doctorCommand).addHelpText(
19046
19107
  "after",
19047
- "\n Examples:\n $ siteping doctor\n $ siteping doctor --url https://staging.example.com --path /api/feedback"
19108
+ "\n Examples:\n $ siteping doctor\n $ siteping doctor --url https://staging.example.com --endpoint /api/feedback"
19048
19109
  );
19049
19110
  program2.parse();
19050
19111
  //# sourceMappingURL=index.js.map