@secondlayer/shared 0.7.0 → 0.8.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.
- package/dist/src/crypto/hmac.js +2 -2
- package/dist/src/crypto/hmac.js.map +3 -3
- package/dist/src/db/index.d.ts +18 -3
- package/dist/src/db/index.js +6 -2
- package/dist/src/db/index.js.map +4 -4
- package/dist/src/db/jsonb.js.map +2 -2
- package/dist/src/db/queries/accounts.d.ts +16 -3
- package/dist/src/db/queries/accounts.js +6 -3
- package/dist/src/db/queries/accounts.js.map +3 -3
- package/dist/src/db/queries/integrity.d.ts +15 -2
- package/dist/src/db/queries/integrity.js.map +2 -2
- package/dist/src/db/queries/metrics.d.ts +15 -2
- package/dist/src/db/queries/metrics.js.map +2 -2
- package/dist/src/db/queries/subgraph-gaps.d.ts +305 -0
- package/dist/src/db/queries/subgraph-gaps.js +103 -0
- package/dist/src/db/queries/subgraph-gaps.js.map +10 -0
- package/dist/src/db/queries/subgraphs.d.ts +15 -2
- package/dist/src/db/queries/subgraphs.js +2 -2
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/usage.d.ts +23 -3
- package/dist/src/db/queries/usage.js +35 -3
- package/dist/src/db/queries/usage.js.map +4 -4
- package/dist/src/db/schema.d.ts +18 -3
- package/dist/src/env.js.map +2 -2
- package/dist/src/errors.d.ts +17 -4
- package/dist/src/errors.js +14 -2
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index.d.ts +78 -6
- package/dist/src/index.js +26 -8
- package/dist/src/index.js.map +12 -12
- package/dist/src/lib/plans.js.map +2 -2
- package/dist/src/logger.js.map +3 -3
- package/dist/src/node/archive-client.js +22 -6
- package/dist/src/node/archive-client.js.map +5 -5
- package/dist/src/node/client.js.map +2 -2
- package/dist/src/node/hiro-client.js +47 -11
- package/dist/src/node/hiro-client.js.map +5 -5
- package/dist/src/node/hiro-pg-client.js +131 -26
- package/dist/src/node/hiro-pg-client.js.map +3 -3
- package/dist/src/node/local-client.d.ts +15 -2
- package/dist/src/node/local-client.js.map +2 -2
- package/dist/src/queue/index.js +8 -4
- package/dist/src/queue/index.js.map +5 -5
- package/dist/src/queue/listener.js.map +2 -2
- package/dist/src/queue/recovery.js +6 -2
- package/dist/src/queue/recovery.js.map +5 -5
- package/dist/src/schemas/filters.js +2 -2
- package/dist/src/schemas/filters.js.map +3 -3
- package/dist/src/schemas/index.d.ts +45 -1
- package/dist/src/schemas/index.js +5 -3
- package/dist/src/schemas/index.js.map +5 -5
- package/dist/src/schemas/subgraphs.d.ts +45 -1
- package/dist/src/schemas/subgraphs.js.map +2 -2
- package/dist/src/types.d.ts +1 -1
- package/migrations/0001_initial.ts +295 -159
- package/migrations/0002_api_keys.ts +44 -28
- package/migrations/0003_tenant_isolation.ts +116 -107
- package/migrations/0004_accounts_and_usage.ts +81 -75
- package/migrations/0005_sessions.ts +33 -33
- package/migrations/0006_tx_index.ts +6 -2
- package/migrations/0007_contracts.ts +38 -24
- package/migrations/0008_drop_contracts.ts +33 -19
- package/migrations/0009_waitlist.ts +12 -12
- package/migrations/0010_waitlist_status.ts +5 -5
- package/migrations/0011_account_insights.ts +52 -52
- package/migrations/0012_view_health_snapshots.ts +21 -21
- package/migrations/0013_view_processing_stats.ts +32 -32
- package/migrations/0014_view_table_snapshots.ts +24 -24
- package/migrations/0015_rename_views_to_subgraphs.ts +137 -75
- package/migrations/0016_rename_webhook_to_endpoint.ts +12 -4
- package/migrations/0017_security_hardening.ts +32 -0
- package/migrations/0018_subgraph_gaps.ts +39 -0
- package/package.json +147 -143
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
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(
|
|
6
|
+
db,
|
|
7
|
+
);
|
|
8
|
+
|
|
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);
|
|
12
|
+
|
|
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
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function down(db: Kysely<any>): Promise<void> {
|
|
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
|
+
);
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
2
|
+
"name": "@secondlayer/shared",
|
|
3
|
+
"version": "0.8.0",
|
|
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
|
}
|