@siteping/cli 0.4.2 → 0.4.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/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,15 +18470,17 @@ 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" },
18482
+ urlPattern: { type: "String", optional: true },
18483
+ screenshotUrl: { type: "String", optional: true, nativeType: "Text" },
18455
18484
  viewport: { type: "String" },
18456
18485
  userAgent: { type: "String" },
18457
18486
  authorName: { type: "String" },
@@ -18459,12 +18488,17 @@ var SITEPING_MODELS = {
18459
18488
  clientId: { type: "String", isUnique: true },
18460
18489
  resolvedAt: { type: "DateTime", optional: true },
18461
18490
  createdAt: { type: "DateTime", default: "now()" },
18491
+ updatedAt: { type: "DateTime", isUpdatedAt: true },
18462
18492
  annotations: {
18463
18493
  type: "SitepingAnnotation",
18464
18494
  relation: { kind: "1-to-many", model: "SitepingAnnotation" }
18465
18495
  }
18466
18496
  },
18467
- indexes: [{ fields: ["projectName"] }]
18497
+ indexes: [
18498
+ { fields: ["projectName"] },
18499
+ { fields: ["projectName", "status", "createdAt"] },
18500
+ { fields: ["projectName", "url"] }
18501
+ ]
18468
18502
  },
18469
18503
  SitepingAnnotation: {
18470
18504
  fields: {
@@ -18480,15 +18514,16 @@ var SITEPING_MODELS = {
18480
18514
  onDelete: "Cascade"
18481
18515
  }
18482
18516
  },
18483
- cssSelector: { type: "String" },
18484
- xpath: { type: "String" },
18485
- textSnippet: { type: "String" },
18517
+ cssSelector: { type: "String", nativeType: "Text" },
18518
+ xpath: { type: "String", nativeType: "Text" },
18519
+ textSnippet: { type: "String", nativeType: "Text" },
18486
18520
  elementTag: { type: "String" },
18487
18521
  elementId: { type: "String", optional: true },
18488
- textPrefix: { type: "String" },
18489
- textSuffix: { type: "String" },
18522
+ textPrefix: { type: "String", nativeType: "Text" },
18523
+ textSuffix: { type: "String", nativeType: "Text" },
18490
18524
  fingerprint: { type: "String" },
18491
- neighborText: { type: "String" },
18525
+ neighborText: { type: "String", nativeType: "Text" },
18526
+ anchorKey: { type: "String", optional: true },
18492
18527
  xPct: { type: "Float" },
18493
18528
  yPct: { type: "Float" },
18494
18529
  wPct: { type: "Float" },
@@ -18503,12 +18538,13 @@ var SITEPING_MODELS = {
18503
18538
  indexes: [{ fields: ["feedbackId"] }]
18504
18539
  }
18505
18540
  };
18541
+ var SITEPING_MODELS = Object.freeze(_SITEPING_MODELS);
18506
18542
 
18507
18543
  // src/generators/prisma.ts
18508
18544
  var DEFAULT_SCHEMA_PATH = "prisma/schema.prisma";
18509
18545
  function syncPrismaModels(schemaPath = DEFAULT_SCHEMA_PATH) {
18510
18546
  if (!existsSync(schemaPath)) {
18511
- throw new Error(`Fichier schema introuvable : ${schemaPath}`);
18547
+ throw new Error(`Schema file not found: ${schemaPath}`);
18512
18548
  }
18513
18549
  const source = readFileSync(schemaPath, "utf-8");
18514
18550
  const schema = getSchema(source);
@@ -18570,7 +18606,7 @@ function syncPrismaModels(schemaPath = DEFAULT_SCHEMA_PATH) {
18570
18606
  }
18571
18607
  if (fieldsToAdd.length > 0) {
18572
18608
  const createdAtIdx = existingModel.properties.findIndex(
18573
- (p2) => p2.type === "field" && p2.name === "createdAt"
18609
+ (p3) => p3.type === "field" && p3.name === "createdAt"
18574
18610
  );
18575
18611
  if (createdAtIdx >= 0) {
18576
18612
  existingModel.properties.splice(createdAtIdx, 0, ...fieldsToAdd);
@@ -18594,7 +18630,15 @@ function syncPrismaModels(schemaPath = DEFAULT_SCHEMA_PATH) {
18594
18630
  }
18595
18631
  if (addedModels.length > 0 || changes.length > 0) {
18596
18632
  const output = printSchema(schema);
18597
- writeFileSync(schemaPath, output, "utf-8");
18633
+ try {
18634
+ writeFileSync(schemaPath, output, "utf-8");
18635
+ } catch (error) {
18636
+ const code = error.code;
18637
+ if (code === "EACCES" || code === "EPERM") {
18638
+ throw new Error(`Permission denied: cannot write to ${schemaPath}. Check file permissions.`);
18639
+ }
18640
+ throw error;
18641
+ }
18598
18642
  }
18599
18643
  return { schemaPath, addedModels, changes };
18600
18644
  }
@@ -18602,10 +18646,11 @@ function fieldsMatch(existing, expected) {
18602
18646
  if (existing.fieldType !== expected.fieldType) return false;
18603
18647
  if ((existing.optional ?? false) !== (expected.optional ?? false)) return false;
18604
18648
  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();
18649
+ const attrKey = (a2) => a2.group ? `${a2.group}.${a2.name}` : a2.name;
18650
+ const existingAttrs = (existing.attributes ?? []).map(attrKey).sort();
18651
+ const expectedAttrs = (expected.attributes ?? []).map(attrKey).sort();
18607
18652
  if (existingAttrs.length !== expectedAttrs.length) return false;
18608
- return existingAttrs.every((name, i) => name === expectedAttrs[i]);
18653
+ return existingAttrs.every((key, i) => key === expectedAttrs[i]);
18609
18654
  }
18610
18655
  function describeChange(existing, expected) {
18611
18656
  const parts = [];
@@ -18613,17 +18658,18 @@ function describeChange(existing, expected) {
18613
18658
  parts.push(`${existing.fieldType} \u2192 ${expected.fieldType}`);
18614
18659
  }
18615
18660
  if ((existing.optional ?? false) !== (expected.optional ?? false)) {
18616
- parts.push(expected.optional ? "requis \u2192 optionnel" : "optionnel \u2192 requis");
18661
+ parts.push(expected.optional ? "required \u2192 optional" : "optional \u2192 required");
18617
18662
  }
18618
- const existingAttrs = new Set((existing.attributes ?? []).map((a2) => a2.name));
18619
- const expectedAttrs = new Set((expected.attributes ?? []).map((a2) => a2.name));
18663
+ const attrKey = (a2) => a2.group ? `${a2.group}.${a2.name}` : a2.name;
18664
+ const existingAttrs = new Set((existing.attributes ?? []).map(attrKey));
18665
+ const expectedAttrs = new Set((expected.attributes ?? []).map(attrKey));
18620
18666
  for (const attr of expectedAttrs) {
18621
18667
  if (!existingAttrs.has(attr)) parts.push(`+@${attr}`);
18622
18668
  }
18623
18669
  for (const attr of existingAttrs) {
18624
18670
  if (!expectedAttrs.has(attr)) parts.push(`-@${attr}`);
18625
18671
  }
18626
- return parts.join(", ") || "attributs modifi\xE9s";
18672
+ return parts.join(", ") || "attributes changed";
18627
18673
  }
18628
18674
  function formatFieldSignature(def) {
18629
18675
  let sig = def.type;
@@ -18668,6 +18714,12 @@ function buildField(name, def) {
18668
18714
  ]
18669
18715
  });
18670
18716
  }
18717
+ if (def.nativeType) {
18718
+ field.attributes.push({ type: "attribute", name: def.nativeType, kind: "field", group: "db" });
18719
+ }
18720
+ if (def.isUpdatedAt) {
18721
+ field.attributes.push({ type: "attribute", name: "updatedAt", kind: "field" });
18722
+ }
18671
18723
  if (def.isUnique) {
18672
18724
  field.attributes.push({ type: "attribute", name: "unique", kind: "field" });
18673
18725
  }
@@ -18715,9 +18767,9 @@ function buildBlockIndex(idx) {
18715
18767
  }
18716
18768
  function hasBlockIndex(model, idx) {
18717
18769
  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;
18770
+ return model.properties.some((p3) => {
18771
+ if (p3.type !== "attribute" || p3.name !== "index") return false;
18772
+ const attr = p3;
18721
18773
  const firstArg = attr.args?.[0];
18722
18774
  if (!firstArg || firstArg.type !== "attributeArgument") return false;
18723
18775
  const val = firstArg.value;
@@ -18734,19 +18786,32 @@ import { dirname, join } from "path";
18734
18786
  var ROUTE_TEMPLATE = `import { createSitepingHandler } from "@siteping/adapter-prisma";
18735
18787
  import { prisma } from "@/lib/prisma";
18736
18788
 
18737
- export const { GET, POST, PATCH, DELETE } = createSitepingHandler({ prisma });
18789
+ export const { GET, POST, PATCH, DELETE, OPTIONS } = createSitepingHandler({
18790
+ prisma,
18791
+ // Uncomment to require authentication:
18792
+ // apiKey: process.env.SITEPING_API_KEY,
18793
+ // allowedOrigins: ["https://your-site.com"],
18794
+ });
18738
18795
  `;
18739
18796
  function generateRoute(basePath = process.cwd()) {
18740
18797
  const appDir = existsSync2(join(basePath, "src", "app")) ? join(basePath, "src", "app") : join(basePath, "app");
18741
18798
  if (!existsSync2(appDir)) {
18742
- throw new Error("Impossible de trouver le dossier app/. \xCAtes-vous dans un projet Next.js App Router ?");
18799
+ throw new Error("Cannot find the app/ directory. Are you in a Next.js App Router project?");
18743
18800
  }
18744
18801
  const routePath = join(appDir, "api", "siteping", "route.ts");
18745
18802
  if (existsSync2(routePath)) {
18746
18803
  return { created: false, path: routePath };
18747
18804
  }
18748
- mkdirSync(dirname(routePath), { recursive: true });
18749
- writeFileSync2(routePath, ROUTE_TEMPLATE, "utf-8");
18805
+ try {
18806
+ mkdirSync(dirname(routePath), { recursive: true });
18807
+ writeFileSync2(routePath, ROUTE_TEMPLATE, "utf-8");
18808
+ } catch (error) {
18809
+ const code = error.code;
18810
+ if (code === "EACCES" || code === "EPERM") {
18811
+ throw new Error(`Permission denied: cannot write to ${routePath}. Check file permissions.`);
18812
+ }
18813
+ throw error;
18814
+ }
18750
18815
  return { created: true, path: routePath };
18751
18816
  }
18752
18817
 
@@ -18759,81 +18824,85 @@ function findPrismaSchema(cwd) {
18759
18824
  join2(cwd, "schema.prisma"),
18760
18825
  join2(cwd, "prisma", "schema", "schema.prisma")
18761
18826
  ];
18762
- return candidates.find((p2) => existsSync3(p2)) ?? null;
18827
+ return candidates.find((p3) => existsSync3(p3)) ?? null;
18763
18828
  }
18764
18829
 
18765
18830
  // src/commands/init.ts
18766
18831
  async function initCommand() {
18767
- we("siteping \u2014 Configuration");
18832
+ p2.intro("siteping \u2014 Setup");
18768
18833
  const cwd = process.cwd();
18769
18834
  const schemaPath = findPrismaSchema(cwd);
18770
18835
  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 ?"
18836
+ p2.log.info(`Prisma schema found: ${schemaPath}`);
18837
+ const shouldSync = await p2.confirm({
18838
+ message: "Sync Siteping models to your Prisma schema?"
18774
18839
  });
18775
- if (BD(shouldSync)) {
18776
- ve("Annul\xE9.");
18840
+ if (p2.isCancel(shouldSync)) {
18841
+ p2.cancel("Cancelled.");
18777
18842
  process.exit(0);
18778
18843
  }
18779
18844
  if (shouldSync) {
18780
18845
  try {
18781
18846
  const { addedModels, changes } = syncPrismaModels(schemaPath);
18782
18847
  if (addedModels.length > 0) {
18783
- v2.success(`Mod\xE8les cr\xE9\xE9s : ${addedModels.join(", ")}`);
18848
+ p2.log.success(`Models synced: ${addedModels.join(", ")}`);
18784
18849
  }
18785
18850
  for (const change of changes) {
18786
18851
  if (change.action === "added") {
18787
- v2.success(`${change.model}.${change.field} \u2014 ajout\xE9 (${change.detail})`);
18852
+ p2.log.success(`${change.model}.${change.field} \u2014 added (${change.detail})`);
18788
18853
  } else {
18789
- v2.success(`${change.model}.${change.field} \u2014 mis \xE0 jour (${change.detail})`);
18854
+ p2.log.success(`${change.model}.${change.field} \u2014 updated (${change.detail})`);
18790
18855
  }
18791
18856
  }
18792
18857
  if (addedModels.length === 0 && changes.length === 0) {
18793
- v2.info("Le schema est d\xE9j\xE0 \xE0 jour.");
18858
+ p2.log.info("Schema is already up to date.");
18794
18859
  }
18795
18860
  } catch (error) {
18796
- v2.error(`Erreur : ${error instanceof Error ? error.message : String(error)}`);
18861
+ p2.log.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
18862
+ p2.outro("Fix the errors above and re-run `siteping init`.");
18863
+ process.exit(1);
18797
18864
  }
18798
18865
  }
18799
18866
  } 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");
18867
+ p2.log.warn("No schema.prisma file found. You will need to add the models manually.");
18868
+ p2.log.info("See the documentation: https://github.com/NeosiaNexus/SitePing#prisma-schema-1");
18802
18869
  }
18803
- const shouldRoute = await me({
18804
- message: "G\xE9n\xE9rer la route API Next.js App Router ?"
18870
+ const shouldRoute = await p2.confirm({
18871
+ message: "Generate the Next.js App Router API route?"
18805
18872
  });
18806
- if (BD(shouldRoute)) {
18807
- ve("Annul\xE9.");
18873
+ if (p2.isCancel(shouldRoute)) {
18874
+ p2.cancel("Cancelled.");
18808
18875
  process.exit(0);
18809
18876
  }
18810
18877
  if (shouldRoute) {
18811
18878
  try {
18812
18879
  const { created, path } = generateRoute(cwd);
18813
18880
  if (created) {
18814
- v2.success(`Route cr\xE9\xE9e : ${path}`);
18881
+ p2.log.success(`Route created: ${path}`);
18815
18882
  } else {
18816
- v2.info(`La route existe d\xE9j\xE0 : ${path}`);
18883
+ p2.log.info(`Route already exists: ${path}`);
18817
18884
  }
18818
18885
  } catch (error) {
18819
- v2.error(`Erreur : ${error instanceof Error ? error.message : String(error)}`);
18886
+ p2.log.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
18887
+ p2.outro("Fix the errors above and re-run `siteping init`.");
18888
+ process.exit(1);
18820
18889
  }
18821
18890
  }
18822
- ye(
18891
+ p2.note(
18823
18892
  [
18824
- "1. Ex\xE9cutez : npx prisma db push",
18825
- "2. Ajoutez le widget dans votre layout :",
18893
+ "1. Run: npx prisma db push",
18894
+ "2. Add the widget to your layout:",
18826
18895
  "",
18827
18896
  ' import { initSiteping } from "@siteping/widget"',
18828
18897
  "",
18829
18898
  " initSiteping({",
18830
18899
  ' endpoint: "/api/siteping",',
18831
- ' projectName: "mon-projet",',
18900
+ ' projectName: "my-project",',
18832
18901
  " })"
18833
18902
  ].join("\n"),
18834
- "Prochaines \xE9tapes"
18903
+ "Next steps"
18835
18904
  );
18836
- fe("Configuration termin\xE9e !");
18905
+ p2.outro("Setup complete!");
18837
18906
  }
18838
18907
 
18839
18908
  // src/commands/status.ts
@@ -18941,35 +19010,33 @@ function pad(label, width) {
18941
19010
  }
18942
19011
  function statusCommand(options) {
18943
19012
  const cwd = process.cwd();
18944
- we("siteping \u2014 Diagnostic");
19013
+ we("siteping \u2014 Status");
18945
19014
  const schemaPath = options.schema ?? findPrismaSchema(cwd);
18946
19015
  const schemaResult = checkSchema(schemaPath);
18947
19016
  if (!schemaResult.found) {
18948
- v2.error(`${pad("Prisma schema", 25)}\u2717 Non trouv\xE9`);
19017
+ v2.error(`${pad("Prisma schema", 25)}Not found`);
18949
19018
  } else {
18950
19019
  const issues = [
18951
- ...schemaResult.missingModels.map((m3) => `mod\xE8le ${m3}`),
19020
+ ...schemaResult.missingModels.map((m3) => `model ${m3}`),
18952
19021
  ...schemaResult.missingFields,
18953
19022
  ...schemaResult.outdatedFields
18954
19023
  ];
18955
19024
  if (issues.length === 0) {
18956
- v2.success(`${pad("Prisma schema", 25)}\u2713 \xC0 jour`);
19025
+ v2.success(`${pad("Prisma schema", 25)}Up to date`);
18957
19026
  } else {
18958
19027
  const missingCount = schemaResult.missingModels.length + schemaResult.missingFields.length;
18959
19028
  const outdatedCount = schemaResult.outdatedFields.length;
18960
19029
  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(", ")})`);
19030
+ if (missingCount > 0) parts.push(`${missingCount} missing field${missingCount > 1 ? "s" : ""}`);
19031
+ if (outdatedCount > 0) parts.push(`${outdatedCount} outdated field${outdatedCount > 1 ? "s" : ""}`);
19032
+ v2.warn(`${pad("Prisma schema", 25)}${parts.join(", ")} (${issues.join(", ")})`);
18966
19033
  }
18967
19034
  }
18968
19035
  const routePath = findApiRoute(cwd);
18969
19036
  if (routePath) {
18970
- v2.success(`${pad("Route API", 25)}\u2713 ${relative(cwd, routePath)}`);
19037
+ v2.success(`${pad("API route", 25)}${relative(cwd, routePath)}`);
18971
19038
  } else {
18972
- v2.error(`${pad("Route API", 25)}\u2717 Non trouv\xE9e`);
19039
+ v2.error(`${pad("API route", 25)}Not found`);
18973
19040
  }
18974
19041
  const pkg = readPackageJson(cwd);
18975
19042
  if (pkg) {
@@ -18977,27 +19044,28 @@ function statusCommand(options) {
18977
19044
  const devDeps = pkg.devDependencies ?? {};
18978
19045
  const version = deps["@siteping/widget"] ?? devDeps["@siteping/widget"];
18979
19046
  if (version) {
18980
- v2.success(`${pad("Package", 25)}\u2713 @siteping/widget@${version}`);
19047
+ v2.success(`${pad("Package", 25)}@siteping/widget@${version}`);
18981
19048
  } else {
18982
- v2.error(`${pad("Package", 25)}\u2717 @siteping/widget non trouv\xE9 dans package.json`);
19049
+ v2.error(`${pad("Package", 25)}@siteping/widget not found in package.json`);
18983
19050
  }
18984
19051
  } else {
18985
- v2.error(`${pad("Package", 25)}\u2717 package.json non trouv\xE9`);
19052
+ v2.error(`${pad("Package", 25)}package.json not found`);
18986
19053
  }
18987
19054
  const widgetFile = findWidgetUsage(cwd);
18988
19055
  if (widgetFile) {
18989
- v2.success(`${pad("Widget int\xE9gr\xE9", 25)}\u2713 trouv\xE9 dans ${relative(cwd, widgetFile)}`);
19056
+ v2.success(`${pad("Widget integration", 25)}found in ${relative(cwd, widgetFile)}`);
18990
19057
  } else {
18991
- v2.warn(`${pad("Widget int\xE9gr\xE9", 25)}\u26A0 initSiteping non trouv\xE9 dans les sources`);
19058
+ v2.warn(`${pad("Widget integration", 25)}initSiteping not found in source files`);
18992
19059
  }
18993
19060
  const hasError = !schemaResult.found || !routePath || !pkg || pkg && !(pkg.dependencies?.["@siteping/widget"] ?? pkg.devDependencies?.["@siteping/widget"]);
18994
19061
  const hasWarning = schemaResult.missingModels.length > 0 || schemaResult.missingFields.length > 0 || schemaResult.outdatedFields.length > 0 || !widgetFile;
18995
19062
  if (hasError) {
18996
- fe("Des \xE9l\xE9ments sont manquants \u2014 lancez `siteping init` pour configurer.");
19063
+ fe("Some items are missing \u2014 run `siteping init` to set up.");
19064
+ process.exit(1);
18997
19065
  } else if (hasWarning) {
18998
- fe("Quelques ajustements n\xE9cessaires \u2014 lancez `siteping sync` pour mettre \xE0 jour.");
19066
+ fe("Some adjustments needed \u2014 run `siteping sync` to update.");
18999
19067
  } else {
19000
- fe("Tout est configur\xE9 !");
19068
+ fe("Everything is set up!");
19001
19069
  }
19002
19070
  }
19003
19071
 
@@ -19007,44 +19075,44 @@ function syncCommand(options) {
19007
19075
  const cwd = process.cwd();
19008
19076
  const schemaPath = options.schema ?? findPrismaSchema(cwd);
19009
19077
  if (!schemaPath) {
19010
- v2.error("Aucun fichier schema.prisma trouv\xE9.");
19011
- v2.info("Sp\xE9cifiez le chemin avec --schema <path>");
19078
+ v2.error("No schema.prisma file found.");
19079
+ v2.info("Specify the path with --schema <path>");
19012
19080
  process.exit(1);
19013
19081
  }
19014
19082
  if (!existsSync5(schemaPath)) {
19015
- v2.error(`Fichier introuvable : ${schemaPath}`);
19083
+ v2.error(`File not found: ${schemaPath}`);
19016
19084
  process.exit(1);
19017
19085
  }
19018
19086
  try {
19019
19087
  const { addedModels, changes } = syncPrismaModels(schemaPath);
19020
19088
  if (addedModels.length === 0 && changes.length === 0) {
19021
- v2.info("\u2713 Le schema est d\xE9j\xE0 \xE0 jour.");
19089
+ v2.info("Schema is already up to date.");
19022
19090
  return;
19023
19091
  }
19024
19092
  if (addedModels.length > 0) {
19025
- v2.success(`Mod\xE8les cr\xE9\xE9s : ${addedModels.join(", ")}`);
19093
+ v2.success(`Models synced: ${addedModels.join(", ")}`);
19026
19094
  }
19027
19095
  for (const change of changes) {
19028
19096
  const icon = change.action === "added" ? "+" : "~";
19029
19097
  v2.success(
19030
- `${icon} ${change.model}.${change.field} \u2014 ${change.action === "added" ? "ajout\xE9" : "mis \xE0 jour"} (${change.detail})`
19098
+ `${icon} ${change.model}.${change.field} \u2014 ${change.action === "added" ? "added" : "updated"} (${change.detail})`
19031
19099
  );
19032
19100
  }
19033
- v2.info("N'oubliez pas : npx prisma db push");
19101
+ v2.info("Don't forget to run: npx prisma db push");
19034
19102
  } catch (error) {
19035
- v2.error(`Erreur : ${error instanceof Error ? error.message : String(error)}`);
19103
+ v2.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
19036
19104
  process.exit(1);
19037
19105
  }
19038
19106
  }
19039
19107
 
19040
19108
  // src/index.ts
19041
- var program2 = new Command().name("siteping").description("CLI pour configurer @siteping/*").version("0.4.2");
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(
19109
+ var program2 = new Command().name("siteping").description("CLI to configure @siteping/* in your project").version("0.4.4");
19110
+ program2.command("init").description("Set up the Prisma schema and API route in your project").action(initCommand).addHelpText("after", "\n Examples:\n $ siteping init");
19111
+ 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");
19112
+ 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");
19113
+ 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
19114
  "after",
19047
- "\n Examples:\n $ siteping doctor\n $ siteping doctor --url https://staging.example.com --path /api/feedback"
19115
+ "\n Examples:\n $ siteping doctor\n $ siteping doctor --url https://staging.example.com --endpoint /api/feedback"
19048
19116
  );
19049
19117
  program2.parse();
19050
19118
  //# sourceMappingURL=index.js.map