@secondlayer/shared 15.3.3 → 15.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/src/archive/range-digest.d.ts +7 -0
  2. package/dist/src/archive/semantic-digest-builder.d.ts +7 -0
  3. package/dist/src/classify/index.js +16 -2
  4. package/dist/src/classify/index.js.map +3 -3
  5. package/dist/src/coverage/index.d.ts +15 -1
  6. package/dist/src/coverage/index.js +57 -2
  7. package/dist/src/coverage/index.js.map +4 -4
  8. package/dist/src/crypto/secondlayer-webhook.js +16 -2
  9. package/dist/src/crypto/secondlayer-webhook.js.map +3 -3
  10. package/dist/src/crypto/secrets.d.ts +8 -2
  11. package/dist/src/crypto/secrets.js +21 -7
  12. package/dist/src/crypto/secrets.js.map +3 -3
  13. package/dist/src/db/index.d.ts +15 -1
  14. package/dist/src/db/index.js +29 -7
  15. package/dist/src/db/index.js.map +5 -5
  16. package/dist/src/db/queries/chain-reorgs.d.ts +7 -0
  17. package/dist/src/db/queries/chain-reorgs.js +27 -7
  18. package/dist/src/db/queries/chain-reorgs.js.map +5 -5
  19. package/dist/src/db/queries/contracts.d.ts +21 -1
  20. package/dist/src/db/queries/contracts.js +23 -1
  21. package/dist/src/db/queries/contracts.js.map +4 -4
  22. package/dist/src/db/queries/instance.d.ts +33 -5
  23. package/dist/src/db/queries/instance.js +224 -14
  24. package/dist/src/db/queries/instance.js.map +6 -5
  25. package/dist/src/db/queries/integrity.d.ts +84 -1
  26. package/dist/src/db/queries/integrity.js +430 -15
  27. package/dist/src/db/queries/integrity.js.map +8 -6
  28. package/dist/src/db/queries/subgraph-gaps.d.ts +18 -6
  29. package/dist/src/db/queries/subgraph-gaps.js +81 -14
  30. package/dist/src/db/queries/subgraph-gaps.js.map +3 -3
  31. package/dist/src/db/queries/subgraph-operations.d.ts +10 -1
  32. package/dist/src/db/queries/subgraph-operations.js +9 -5
  33. package/dist/src/db/queries/subgraph-operations.js.map +3 -3
  34. package/dist/src/db/queries/subgraphs.d.ts +11 -4
  35. package/dist/src/db/queries/subgraphs.js +13 -6
  36. package/dist/src/db/queries/subgraphs.js.map +4 -4
  37. package/dist/src/db/queries/sync-scope.d.ts +7 -0
  38. package/dist/src/db/queries/webhook-replays.d.ts +7 -0
  39. package/dist/src/db/queries/webhook-replays.js +20 -7
  40. package/dist/src/db/queries/webhook-replays.js.map +3 -3
  41. package/dist/src/db/queries/webhooks.d.ts +7 -0
  42. package/dist/src/db/queries/webhooks.js +20 -7
  43. package/dist/src/db/queries/webhooks.js.map +3 -3
  44. package/dist/src/db/schema.d.ts +7 -0
  45. package/dist/src/db/schema.js.map +2 -2
  46. package/dist/src/email/index.js +16 -2
  47. package/dist/src/email/index.js.map +3 -3
  48. package/dist/src/env.d.ts +8 -1
  49. package/dist/src/env.js +18 -3
  50. package/dist/src/env.js.map +3 -3
  51. package/dist/src/index.d.ts +59 -1
  52. package/dist/src/index.js +71 -8
  53. package/dist/src/index.js.map +8 -8
  54. package/dist/src/insights/index.d.ts +7 -0
  55. package/dist/src/insights/index.js +16 -2
  56. package/dist/src/insights/index.js.map +3 -3
  57. package/dist/src/leader.js +915 -27
  58. package/dist/src/leader.js.map +13 -6
  59. package/dist/src/logger.js +16 -2
  60. package/dist/src/logger.js.map +3 -3
  61. package/dist/src/node/local-client.d.ts +7 -0
  62. package/dist/src/node/tx-summary.js +16 -2
  63. package/dist/src/node/tx-summary.js.map +3 -3
  64. package/dist/src/queue/listener.js +27 -7
  65. package/dist/src/queue/listener.js.map +5 -5
  66. package/dist/src/schemas/index.js +2 -2
  67. package/dist/src/schemas/index.js.map +3 -3
  68. package/dist/src/schemas/subgraphs.js +2 -2
  69. package/dist/src/schemas/subgraphs.js.map +3 -3
  70. package/dist/src/types.d.ts +3 -0
  71. package/migrations/0197_subgraph_last_block_hash.ts +67 -0
  72. package/migrations/0198_blocks_event_count.ts +24 -0
  73. package/migrations/0199_transactions_height_tx_index_uniq.ts +77 -0
  74. package/migrations/0200_subgraphs_schema_name_unique.ts +39 -0
  75. package/migrations/0201_subgraph_gaps_range_check.ts +47 -0
  76. package/migrations/0202_instances_secrets_key_canary.ts +36 -0
  77. package/package.json +2 -2
@@ -0,0 +1,36 @@
1
+ import { type Kysely, sql } from "kysely";
2
+ import { onControlPlane } from "../src/db/migration-role.ts";
3
+
4
+ /**
5
+ * The instance row remembers a canary sealed under `SECONDLAYER_SECRETS_KEY`,
6
+ * so a self-hosted boot can tell the key it was handed from the one that
7
+ * encrypted this database's webhook signing secrets. NULL until the first
8
+ * boot that has the key writes it. Skipped when the table is absent (not
9
+ * every database carries it).
10
+ */
11
+ async function tableExists(db: Kysely<unknown>, table: string) {
12
+ const { rows } = await sql<{ exists: boolean }>`
13
+ SELECT to_regclass(${`public.${table}`}) IS NOT NULL AS exists
14
+ `.execute(db);
15
+ return rows[0]?.exists === true;
16
+ }
17
+
18
+ export async function up(db: Kysely<unknown>): Promise<void> {
19
+ await sql`SET lock_timeout = '30s'`.execute(db);
20
+ await onControlPlane(async () => {
21
+ if (!(await tableExists(db, "instances"))) return;
22
+ await sql`ALTER TABLE instances ADD COLUMN IF NOT EXISTS secrets_key_canary TEXT`.execute(
23
+ db,
24
+ );
25
+ });
26
+ }
27
+
28
+ export async function down(db: Kysely<unknown>): Promise<void> {
29
+ await sql`SET lock_timeout = '30s'`.execute(db);
30
+ await onControlPlane(async () => {
31
+ if (!(await tableExists(db, "instances"))) return;
32
+ await sql`ALTER TABLE instances DROP COLUMN IF EXISTS secrets_key_canary`.execute(
33
+ db,
34
+ );
35
+ });
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "15.3.3",
3
+ "version": "15.4.0",
4
4
  "description": "Internal building blocks shared across Secondlayer packages.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -273,7 +273,7 @@
273
273
  "prepublishOnly": "bun run build"
274
274
  },
275
275
  "dependencies": {
276
- "@secondlayer/stacks": "^6.5.4",
276
+ "@secondlayer/stacks": "^6.6.1",
277
277
  "kysely": "0.28.17",
278
278
  "kysely-postgres-js": "3.0.0",
279
279
  "postgres": "^3.4.6",