@secondlayer/shared 0.7.1 → 0.8.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 (69) hide show
  1. package/dist/src/crypto/hmac.js +2 -2
  2. package/dist/src/crypto/hmac.js.map +3 -3
  3. package/dist/src/db/index.d.ts +15 -1
  4. package/dist/src/db/index.js +5 -3
  5. package/dist/src/db/index.js.map +4 -4
  6. package/dist/src/db/jsonb.js.map +2 -2
  7. package/dist/src/db/queries/accounts.d.ts +12 -0
  8. package/dist/src/db/queries/accounts.js.map +2 -2
  9. package/dist/src/db/queries/integrity.d.ts +12 -0
  10. package/dist/src/db/queries/integrity.js.map +2 -2
  11. package/dist/src/db/queries/metrics.d.ts +12 -0
  12. package/dist/src/db/queries/metrics.js.map +2 -2
  13. package/dist/src/db/queries/subgraph-gaps.d.ts +305 -0
  14. package/dist/src/db/queries/subgraph-gaps.js +103 -0
  15. package/dist/src/db/queries/subgraph-gaps.js.map +10 -0
  16. package/dist/src/db/queries/subgraphs.d.ts +13 -0
  17. package/dist/src/db/queries/subgraphs.js +4 -2
  18. package/dist/src/db/queries/subgraphs.js.map +4 -4
  19. package/dist/src/db/queries/usage.d.ts +12 -0
  20. package/dist/src/db/queries/usage.js +13 -3
  21. package/dist/src/db/queries/usage.js.map +4 -4
  22. package/dist/src/db/schema.d.ts +15 -1
  23. package/dist/src/env.js.map +2 -2
  24. package/dist/src/errors.js.map +2 -2
  25. package/dist/src/index.d.ts +59 -1
  26. package/dist/src/index.js +12 -8
  27. package/dist/src/index.js.map +12 -12
  28. package/dist/src/lib/plans.js.map +2 -2
  29. package/dist/src/logger.js.map +3 -3
  30. package/dist/src/node/archive-client.js +22 -6
  31. package/dist/src/node/archive-client.js.map +5 -5
  32. package/dist/src/node/client.js.map +2 -2
  33. package/dist/src/node/hiro-client.js +47 -11
  34. package/dist/src/node/hiro-client.js.map +5 -5
  35. package/dist/src/node/hiro-pg-client.js +131 -26
  36. package/dist/src/node/hiro-pg-client.js.map +3 -3
  37. package/dist/src/node/local-client.d.ts +12 -0
  38. package/dist/src/node/local-client.js.map +2 -2
  39. package/dist/src/queue/index.js +7 -5
  40. package/dist/src/queue/index.js.map +5 -5
  41. package/dist/src/queue/listener.js.map +2 -2
  42. package/dist/src/queue/recovery.js +5 -3
  43. package/dist/src/queue/recovery.js.map +5 -5
  44. package/dist/src/schemas/filters.js +2 -2
  45. package/dist/src/schemas/filters.js.map +3 -3
  46. package/dist/src/schemas/index.d.ts +45 -1
  47. package/dist/src/schemas/index.js +5 -3
  48. package/dist/src/schemas/index.js.map +5 -5
  49. package/dist/src/schemas/subgraphs.d.ts +45 -1
  50. package/dist/src/schemas/subgraphs.js.map +2 -2
  51. package/migrations/0001_initial.ts +295 -159
  52. package/migrations/0002_api_keys.ts +44 -28
  53. package/migrations/0003_tenant_isolation.ts +116 -107
  54. package/migrations/0004_accounts_and_usage.ts +81 -75
  55. package/migrations/0005_sessions.ts +33 -33
  56. package/migrations/0006_tx_index.ts +6 -2
  57. package/migrations/0007_contracts.ts +38 -24
  58. package/migrations/0008_drop_contracts.ts +33 -19
  59. package/migrations/0009_waitlist.ts +12 -12
  60. package/migrations/0010_waitlist_status.ts +5 -5
  61. package/migrations/0011_account_insights.ts +52 -52
  62. package/migrations/0012_view_health_snapshots.ts +21 -21
  63. package/migrations/0013_view_processing_stats.ts +32 -32
  64. package/migrations/0014_view_table_snapshots.ts +24 -24
  65. package/migrations/0015_rename_views_to_subgraphs.ts +137 -75
  66. package/migrations/0016_rename_webhook_to_endpoint.ts +12 -4
  67. package/migrations/0017_security_hardening.ts +23 -11
  68. package/migrations/0018_subgraph_gaps.ts +39 -0
  69. package/package.json +147 -143
@@ -1,20 +1,32 @@
1
1
  import { type Kysely, sql } from "kysely";
2
2
 
3
3
  export async function up(db: Kysely<any>): Promise<void> {
4
- // Magic link: add failed attempt tracking
5
- await sql`ALTER TABLE "magic_links" ADD COLUMN "failed_attempts" integer NOT NULL DEFAULT 0`.execute(db);
4
+ // Magic link: add failed attempt tracking
5
+ await sql`ALTER TABLE "magic_links" ADD COLUMN "failed_attempts" integer NOT NULL DEFAULT 0`.execute(
6
+ db,
7
+ );
6
8
 
7
- // Ownership: clean up any NULL api_key_id rows
8
- await sql`DELETE FROM "streams" WHERE "api_key_id" IS NULL`.execute(db);
9
- await sql`DELETE FROM "subgraphs" WHERE "api_key_id" IS NULL`.execute(db);
9
+ // Ownership: clean up any NULL api_key_id rows
10
+ await sql`DELETE FROM "streams" WHERE "api_key_id" IS NULL`.execute(db);
11
+ await sql`DELETE FROM "subgraphs" WHERE "api_key_id" IS NULL`.execute(db);
10
12
 
11
- // Ownership: enforce NOT NULL going forward
12
- await sql`ALTER TABLE "streams" ALTER COLUMN "api_key_id" SET NOT NULL`.execute(db);
13
- await sql`ALTER TABLE "subgraphs" ALTER COLUMN "api_key_id" SET NOT NULL`.execute(db);
13
+ // Ownership: enforce NOT NULL going forward
14
+ await sql`ALTER TABLE "streams" ALTER COLUMN "api_key_id" SET NOT NULL`.execute(
15
+ db,
16
+ );
17
+ await sql`ALTER TABLE "subgraphs" ALTER COLUMN "api_key_id" SET NOT NULL`.execute(
18
+ db,
19
+ );
14
20
  }
15
21
 
16
22
  export async function down(db: Kysely<any>): Promise<void> {
17
- await sql`ALTER TABLE "magic_links" DROP COLUMN "failed_attempts"`.execute(db);
18
- await sql`ALTER TABLE "streams" ALTER COLUMN "api_key_id" DROP NOT NULL`.execute(db);
19
- await sql`ALTER TABLE "subgraphs" ALTER COLUMN "api_key_id" DROP NOT NULL`.execute(db);
23
+ await sql`ALTER TABLE "magic_links" DROP COLUMN "failed_attempts"`.execute(
24
+ db,
25
+ );
26
+ await sql`ALTER TABLE "streams" ALTER COLUMN "api_key_id" DROP NOT NULL`.execute(
27
+ db,
28
+ );
29
+ await sql`ALTER TABLE "subgraphs" ALTER COLUMN "api_key_id" DROP NOT NULL`.execute(
30
+ db,
31
+ );
20
32
  }
@@ -0,0 +1,39 @@
1
+ import { type Kysely, sql } from "kysely";
2
+
3
+ export async function up(db: Kysely<any>): Promise<void> {
4
+ // Add start_block to subgraphs (the intended first block from definition)
5
+ await sql`ALTER TABLE "subgraphs" ADD COLUMN "start_block" bigint NOT NULL DEFAULT 0`.execute(
6
+ db,
7
+ );
8
+
9
+ // Backfill: existing subgraphs that have processed blocks started from 1
10
+ await sql`UPDATE "subgraphs" SET "start_block" = 1 WHERE "last_processed_block" > 0`.execute(
11
+ db,
12
+ );
13
+
14
+ // Subgraph gap tracking
15
+ await sql`
16
+ CREATE TABLE "subgraph_gaps" (
17
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
18
+ "subgraph_id" uuid NOT NULL REFERENCES "subgraphs"("id") ON DELETE CASCADE,
19
+ "subgraph_name" text NOT NULL,
20
+ "gap_start" bigint NOT NULL,
21
+ "gap_end" bigint NOT NULL,
22
+ "reason" text NOT NULL,
23
+ "detected_at" timestamptz NOT NULL DEFAULT now(),
24
+ "resolved_at" timestamptz
25
+ )
26
+ `.execute(db);
27
+
28
+ await sql`CREATE INDEX "subgraph_gaps_subgraph_resolved_idx" ON "subgraph_gaps" ("subgraph_id", "resolved_at")`.execute(
29
+ db,
30
+ );
31
+ await sql`CREATE INDEX "subgraph_gaps_name_idx" ON "subgraph_gaps" ("subgraph_name")`.execute(
32
+ db,
33
+ );
34
+ }
35
+
36
+ export async function down(db: Kysely<any>): Promise<void> {
37
+ await sql`DROP TABLE IF EXISTS "subgraph_gaps"`.execute(db);
38
+ await sql`ALTER TABLE "subgraphs" DROP COLUMN "start_block"`.execute(db);
39
+ }
package/package.json CHANGED
@@ -1,145 +1,149 @@
1
1
  {
2
- "name": "@secondlayer/shared",
3
- "version": "0.7.1",
4
- "type": "module",
5
- "main": "./dist/src/index.js",
6
- "types": "./dist/src/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/src/index.d.ts",
10
- "import": "./dist/src/index.js"
11
- },
12
- "./db": {
13
- "types": "./dist/src/db/index.d.ts",
14
- "import": "./dist/src/db/index.js"
15
- },
16
- "./db/queries/integrity": {
17
- "types": "./dist/src/db/queries/integrity.d.ts",
18
- "import": "./dist/src/db/queries/integrity.js"
19
- },
20
- "./db/queries/metrics": {
21
- "types": "./dist/src/db/queries/metrics.d.ts",
22
- "import": "./dist/src/db/queries/metrics.js"
23
- },
24
- "./db/queries/accounts": {
25
- "types": "./dist/src/db/queries/accounts.d.ts",
26
- "import": "./dist/src/db/queries/accounts.js"
27
- },
28
- "./db/queries/usage": {
29
- "types": "./dist/src/db/queries/usage.d.ts",
30
- "import": "./dist/src/db/queries/usage.js"
31
- },
32
- "./db/queries/subgraphs": {
33
- "types": "./dist/src/db/queries/subgraphs.d.ts",
34
- "import": "./dist/src/db/queries/subgraphs.js"
35
- },
36
- "./db/jsonb": {
37
- "types": "./dist/src/db/jsonb.d.ts",
38
- "import": "./dist/src/db/jsonb.js"
39
- },
40
- "./db/schema": {
41
- "types": "./dist/src/db/schema.d.ts",
42
- "import": "./dist/src/db/schema.js"
43
- },
44
- "./lib/plans": {
45
- "types": "./dist/src/lib/plans.d.ts",
46
- "import": "./dist/src/lib/plans.js"
47
- },
48
- "./queue": {
49
- "types": "./dist/src/queue/index.d.ts",
50
- "import": "./dist/src/queue/index.js"
51
- },
52
- "./queue/listener": {
53
- "types": "./dist/src/queue/listener.d.ts",
54
- "import": "./dist/src/queue/listener.js"
55
- },
56
- "./queue/recovery": {
57
- "types": "./dist/src/queue/recovery.d.ts",
58
- "import": "./dist/src/queue/recovery.js"
59
- },
60
- "./schemas": {
61
- "types": "./dist/src/schemas/index.d.ts",
62
- "import": "./dist/src/schemas/index.js"
63
- },
64
- "./schemas/filters": {
65
- "types": "./dist/src/schemas/filters.d.ts",
66
- "import": "./dist/src/schemas/filters.js"
67
- },
68
- "./schemas/subgraphs": {
69
- "types": "./dist/src/schemas/subgraphs.d.ts",
70
- "import": "./dist/src/schemas/subgraphs.js"
71
- },
72
- "./types": {
73
- "types": "./dist/src/types.d.ts",
74
- "import": "./dist/src/types.js"
75
- },
76
- "./env": {
77
- "types": "./dist/src/env.d.ts",
78
- "import": "./dist/src/env.js"
79
- },
80
- "./logger": {
81
- "types": "./dist/src/logger.d.ts",
82
- "import": "./dist/src/logger.js"
83
- },
84
- "./errors": {
85
- "types": "./dist/src/errors.d.ts",
86
- "import": "./dist/src/errors.js"
87
- },
88
- "./crypto": {
89
- "types": "./dist/src/crypto/hmac.d.ts",
90
- "import": "./dist/src/crypto/hmac.js"
91
- },
92
- "./crypto/hmac": {
93
- "types": "./dist/src/crypto/hmac.d.ts",
94
- "import": "./dist/src/crypto/hmac.js"
95
- },
96
- "./node": {
97
- "types": "./dist/src/node/client.d.ts",
98
- "import": "./dist/src/node/client.js"
99
- },
100
- "./node/hiro-client": {
101
- "types": "./dist/src/node/hiro-client.d.ts",
102
- "import": "./dist/src/node/hiro-client.js"
103
- },
104
- "./node/local-client": {
105
- "types": "./dist/src/node/local-client.d.ts",
106
- "import": "./dist/src/node/local-client.js"
107
- },
108
- "./node/hiro-pg-client": {
109
- "types": "./dist/src/node/hiro-pg-client.d.ts",
110
- "import": "./dist/src/node/hiro-pg-client.js"
111
- },
112
- "./node/client": {
113
- "types": "./dist/src/node/client.d.ts",
114
- "import": "./dist/src/node/client.js"
115
- },
116
- "./node/archive-client": {
117
- "types": "./dist/src/node/archive-client.d.ts",
118
- "import": "./dist/src/node/archive-client.js"
119
- }
120
- },
121
- "files": [
122
- "dist",
123
- "migrations"
124
- ],
125
- "scripts": {
126
- "build": "bunup",
127
- "dev": "bunup --watch",
128
- "test": "bun test",
129
- "typecheck": "tsc --noEmit",
130
- "migrate": "bun run src/db/migrate.ts",
131
- "seed": "DATABASE_URL=${DATABASE_URL:-postgresql://ryanwaits@127.0.0.1:5432/streams_dev} bun run src/db/seed.ts",
132
- "prepublishOnly": "bun run build"
133
- },
134
- "dependencies": {
135
- "@secondlayer/stacks": "^0.2.2",
136
- "kysely": "0.28.10",
137
- "kysely-postgres-js": "3.0.0",
138
- "postgres": "^3.4.6",
139
- "zod": "^4.3.6"
140
- },
141
- "devDependencies": {
142
- "@types/bun": "latest",
143
- "typescript": "^5"
144
- }
2
+ "name": "@secondlayer/shared",
3
+ "version": "0.8.1",
4
+ "type": "module",
5
+ "main": "./dist/src/index.js",
6
+ "types": "./dist/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/src/index.d.ts",
10
+ "import": "./dist/src/index.js"
11
+ },
12
+ "./db": {
13
+ "types": "./dist/src/db/index.d.ts",
14
+ "import": "./dist/src/db/index.js"
15
+ },
16
+ "./db/queries/integrity": {
17
+ "types": "./dist/src/db/queries/integrity.d.ts",
18
+ "import": "./dist/src/db/queries/integrity.js"
19
+ },
20
+ "./db/queries/metrics": {
21
+ "types": "./dist/src/db/queries/metrics.d.ts",
22
+ "import": "./dist/src/db/queries/metrics.js"
23
+ },
24
+ "./db/queries/accounts": {
25
+ "types": "./dist/src/db/queries/accounts.d.ts",
26
+ "import": "./dist/src/db/queries/accounts.js"
27
+ },
28
+ "./db/queries/usage": {
29
+ "types": "./dist/src/db/queries/usage.d.ts",
30
+ "import": "./dist/src/db/queries/usage.js"
31
+ },
32
+ "./db/queries/subgraphs": {
33
+ "types": "./dist/src/db/queries/subgraphs.d.ts",
34
+ "import": "./dist/src/db/queries/subgraphs.js"
35
+ },
36
+ "./db/queries/subgraph-gaps": {
37
+ "types": "./dist/src/db/queries/subgraph-gaps.d.ts",
38
+ "import": "./dist/src/db/queries/subgraph-gaps.js"
39
+ },
40
+ "./db/jsonb": {
41
+ "types": "./dist/src/db/jsonb.d.ts",
42
+ "import": "./dist/src/db/jsonb.js"
43
+ },
44
+ "./db/schema": {
45
+ "types": "./dist/src/db/schema.d.ts",
46
+ "import": "./dist/src/db/schema.js"
47
+ },
48
+ "./lib/plans": {
49
+ "types": "./dist/src/lib/plans.d.ts",
50
+ "import": "./dist/src/lib/plans.js"
51
+ },
52
+ "./queue": {
53
+ "types": "./dist/src/queue/index.d.ts",
54
+ "import": "./dist/src/queue/index.js"
55
+ },
56
+ "./queue/listener": {
57
+ "types": "./dist/src/queue/listener.d.ts",
58
+ "import": "./dist/src/queue/listener.js"
59
+ },
60
+ "./queue/recovery": {
61
+ "types": "./dist/src/queue/recovery.d.ts",
62
+ "import": "./dist/src/queue/recovery.js"
63
+ },
64
+ "./schemas": {
65
+ "types": "./dist/src/schemas/index.d.ts",
66
+ "import": "./dist/src/schemas/index.js"
67
+ },
68
+ "./schemas/filters": {
69
+ "types": "./dist/src/schemas/filters.d.ts",
70
+ "import": "./dist/src/schemas/filters.js"
71
+ },
72
+ "./schemas/subgraphs": {
73
+ "types": "./dist/src/schemas/subgraphs.d.ts",
74
+ "import": "./dist/src/schemas/subgraphs.js"
75
+ },
76
+ "./types": {
77
+ "types": "./dist/src/types.d.ts",
78
+ "import": "./dist/src/types.js"
79
+ },
80
+ "./env": {
81
+ "types": "./dist/src/env.d.ts",
82
+ "import": "./dist/src/env.js"
83
+ },
84
+ "./logger": {
85
+ "types": "./dist/src/logger.d.ts",
86
+ "import": "./dist/src/logger.js"
87
+ },
88
+ "./errors": {
89
+ "types": "./dist/src/errors.d.ts",
90
+ "import": "./dist/src/errors.js"
91
+ },
92
+ "./crypto": {
93
+ "types": "./dist/src/crypto/hmac.d.ts",
94
+ "import": "./dist/src/crypto/hmac.js"
95
+ },
96
+ "./crypto/hmac": {
97
+ "types": "./dist/src/crypto/hmac.d.ts",
98
+ "import": "./dist/src/crypto/hmac.js"
99
+ },
100
+ "./node": {
101
+ "types": "./dist/src/node/client.d.ts",
102
+ "import": "./dist/src/node/client.js"
103
+ },
104
+ "./node/hiro-client": {
105
+ "types": "./dist/src/node/hiro-client.d.ts",
106
+ "import": "./dist/src/node/hiro-client.js"
107
+ },
108
+ "./node/local-client": {
109
+ "types": "./dist/src/node/local-client.d.ts",
110
+ "import": "./dist/src/node/local-client.js"
111
+ },
112
+ "./node/hiro-pg-client": {
113
+ "types": "./dist/src/node/hiro-pg-client.d.ts",
114
+ "import": "./dist/src/node/hiro-pg-client.js"
115
+ },
116
+ "./node/client": {
117
+ "types": "./dist/src/node/client.d.ts",
118
+ "import": "./dist/src/node/client.js"
119
+ },
120
+ "./node/archive-client": {
121
+ "types": "./dist/src/node/archive-client.d.ts",
122
+ "import": "./dist/src/node/archive-client.js"
123
+ }
124
+ },
125
+ "files": [
126
+ "dist",
127
+ "migrations"
128
+ ],
129
+ "scripts": {
130
+ "build": "bunup",
131
+ "dev": "bunup --watch",
132
+ "test": "bun test",
133
+ "typecheck": "tsc --noEmit",
134
+ "migrate": "bun run src/db/migrate.ts",
135
+ "seed": "DATABASE_URL=${DATABASE_URL:-postgresql://ryanwaits@127.0.0.1:5432/streams_dev} bun run src/db/seed.ts",
136
+ "prepublishOnly": "bun run build"
137
+ },
138
+ "dependencies": {
139
+ "@secondlayer/stacks": "^0.2.2",
140
+ "kysely": "0.28.10",
141
+ "kysely-postgres-js": "3.0.0",
142
+ "postgres": "^3.4.6",
143
+ "zod": "^4.3.6"
144
+ },
145
+ "devDependencies": {
146
+ "@types/bun": "latest",
147
+ "typescript": "^5"
148
+ }
145
149
  }