@sekyuriti/attest 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/attest.js +48 -5
  2. package/package.json +1 -1
package/bin/attest.js CHANGED
@@ -18,6 +18,7 @@ const c = {
18
18
  white: "\x1b[37m",
19
19
  gray: "\x1b[90m",
20
20
  green: "\x1b[32m",
21
+ yellow: "\x1b[33m",
21
22
  inverse: "\x1b[7m",
22
23
  };
23
24
 
@@ -353,11 +354,26 @@ ATTEST_SECRET_KEY=${apiKey}
353
354
  // Check if there's already an import statement
354
355
  const hasImports = /import\s/.test(middlewareContent);
355
356
  if (hasImports) {
356
- // Add after last import
357
- middlewareContent = middlewareContent.replace(
358
- /(import[^;]+;[\s\S]*?)\n\n/,
359
- `$1\n${attestImport}\n`
360
- );
357
+ // Find all import lines and add after the last one
358
+ const lines = middlewareContent.split('\n');
359
+ let lastImportIndex = -1;
360
+
361
+ for (let i = 0; i < lines.length; i++) {
362
+ // Match import statements (including multiline imports)
363
+ if (lines[i].trim().startsWith('import ') ||
364
+ (lines[i].includes(' from ') && lines[i].includes(';'))) {
365
+ lastImportIndex = i;
366
+ }
367
+ }
368
+
369
+ if (lastImportIndex !== -1) {
370
+ // Insert after the last import line
371
+ lines.splice(lastImportIndex + 1, 0, attestImport.trim());
372
+ middlewareContent = lines.join('\n');
373
+ } else {
374
+ // Fallback: add at beginning
375
+ middlewareContent = attestImport + middlewareContent;
376
+ }
361
377
  } else {
362
378
  // Add at the beginning
363
379
  middlewareContent = attestImport + "\n" + middlewareContent;
@@ -472,6 +488,33 @@ export const config = {
472
488
  log(` ${c.bold}✓${c.reset} ${step}`);
473
489
  }
474
490
 
491
+ // Verify script endpoint is reachable
492
+ log("");
493
+ log(" Verifying endpoint...");
494
+
495
+ try {
496
+ const scriptUrl = `https://sekyuriti.build/api/v2/attest/script/${publicKey}`;
497
+ const response = await fetch(scriptUrl, { method: "HEAD" });
498
+
499
+ if (response.ok) {
500
+ log(` ${c.bold}✓${c.reset} Script endpoint verified`);
501
+ } else if (response.status === 404) {
502
+ log(` ${c.yellow}⚠${c.reset} Script endpoint returned 404`);
503
+ log("");
504
+ log(" This may indicate:");
505
+ log(" • The project hasn't been fully provisioned yet");
506
+ log(" • ATTEST is not enabled for this project");
507
+ log("");
508
+ log(" Enable ATTEST in your project dashboard:");
509
+ log(" https://sekyuriti.build/dashboard");
510
+ } else {
511
+ log(` ${c.yellow}⚠${c.reset} Script endpoint returned ${response.status}`);
512
+ }
513
+ } catch (err) {
514
+ log(` ${c.yellow}⚠${c.reset} Could not verify endpoint (${err.message})`);
515
+ log(" Check your network connection and try again.");
516
+ }
517
+
475
518
  log("");
476
519
  log(" Documentation: https://sekyuriti.build/docs/attest");
477
520
  log("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sekyuriti/attest",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "API protection middleware for Next.js - verify requests with ATTEST",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",