@secondlayer/shared 1.0.0 → 2.0.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/secrets.d.ts +5 -0
- package/dist/src/crypto/secrets.js +69 -0
- package/dist/src/crypto/secrets.js.map +10 -0
- package/dist/src/db/index.d.ts +91 -6
- package/dist/src/db/index.js +53 -29
- 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 +59 -2
- package/dist/src/db/queries/integrity.d.ts +59 -2
- package/dist/src/db/queries/marketplace.d.ts +59 -2
- package/dist/src/db/queries/marketplace.js +6 -9
- package/dist/src/db/queries/marketplace.js.map +3 -3
- package/dist/src/db/queries/projects.d.ts +59 -2
- package/dist/src/db/queries/projects.js.map +2 -2
- package/dist/src/db/queries/subgraph-gaps.d.ts +59 -2
- package/dist/src/db/queries/subgraphs.d.ts +63 -5
- package/dist/src/db/queries/subgraphs.js +3 -9
- package/dist/src/db/queries/subgraphs.js.map +4 -4
- package/dist/src/db/queries/tenants.d.ts +493 -0
- package/dist/src/db/queries/tenants.js +194 -0
- package/dist/src/db/queries/tenants.js.map +11 -0
- package/dist/src/db/queries/usage.d.ts +59 -2
- package/dist/src/db/queries/usage.js +3 -3
- package/dist/src/db/queries/usage.js.map +3 -3
- package/dist/src/db/queries/workflows.d.ts +59 -2
- package/dist/src/db/queries/workflows.js +31 -3
- package/dist/src/db/queries/workflows.js.map +4 -4
- package/dist/src/db/schema.d.ts +69 -3
- package/dist/src/env.d.ts +10 -0
- package/dist/src/env.js +3 -1
- package/dist/src/env.js.map +3 -3
- package/dist/src/errors.d.ts +17 -3
- package/dist/src/errors.js +34 -3
- package/dist/src/errors.js.map +3 -3
- package/dist/src/index.d.ts +117 -8
- package/dist/src/index.js +88 -31
- package/dist/src/index.js.map +6 -6
- package/dist/src/logger.js +3 -1
- package/dist/src/logger.js.map +3 -3
- package/dist/src/mode.d.ts +30 -0
- package/dist/src/mode.js +43 -0
- package/dist/src/mode.js.map +10 -0
- package/dist/src/node/archive-client.js +3 -1
- package/dist/src/node/archive-client.js.map +3 -3
- package/dist/src/node/hiro-client.js +3 -1
- package/dist/src/node/hiro-client.js.map +3 -3
- package/dist/src/node/local-client.d.ts +59 -2
- package/dist/src/pricing.d.ts +28 -0
- package/dist/src/pricing.js +47 -0
- package/dist/src/pricing.js.map +10 -0
- package/dist/src/queue/listener.d.ts +11 -2
- package/dist/src/queue/listener.js +11 -12
- package/dist/src/queue/listener.js.map +3 -3
- package/dist/src/types.d.ts +10 -0
- package/migrations/0033_workflow_steps_memo_key.ts +54 -0
- package/migrations/0034_workflow_signer_secrets.ts +42 -0
- package/migrations/0035_workflow_budgets.ts +53 -0
- package/migrations/0036_tx_confirmed_notify.ts +36 -0
- package/migrations/0037_nullable_api_key.ts +35 -0
- package/migrations/0038_drop_workflow_tables.ts +46 -0
- package/migrations/0039_tenants.ts +66 -0
- package/migrations/0040_tenant_key_generations.ts +29 -0
- package/migrations/0041_subgraphs_drop_api_key_id.ts +49 -0
- package/migrations/0042_tenant_project_id.ts +25 -0
- package/package.json +18 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Post-cutover cleanup: drop `subgraphs.api_key_id` and the partial unique
|
|
5
|
+
* index that went with nullable-api-key-id handling. Every subgraph lives in
|
|
6
|
+
* a tenant DB now; tenants authenticate via JWT (TENANT_JWT_SECRET), not
|
|
7
|
+
* per-account API keys — so this column has been dead weight since migration
|
|
8
|
+
* 0037 made it nullable.
|
|
9
|
+
*
|
|
10
|
+
* Runs against BOTH the platform DB and every tenant DB (migrations share
|
|
11
|
+
* the same list). The platform DB's `subgraphs` table is manually dropped
|
|
12
|
+
* as a one-off operation AFTER this migration (see Phase 2 cutover notes).
|
|
13
|
+
*
|
|
14
|
+
* Restores the simple `UNIQUE (name)` constraint the table started with —
|
|
15
|
+
* tenant subgraphs were always name-unique within a tenant.
|
|
16
|
+
*/
|
|
17
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
18
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
19
|
+
|
|
20
|
+
await sql`DROP INDEX IF EXISTS subgraphs_name_unique_no_key`.execute(db);
|
|
21
|
+
await sql`ALTER TABLE subgraphs DROP COLUMN IF EXISTS api_key_id`.execute(db);
|
|
22
|
+
// Re-add the simple name-unique constraint if it's not already there
|
|
23
|
+
// (noop if it was never dropped in a prior migration).
|
|
24
|
+
await sql`
|
|
25
|
+
DO $$
|
|
26
|
+
BEGIN
|
|
27
|
+
IF NOT EXISTS (
|
|
28
|
+
SELECT 1 FROM pg_constraint
|
|
29
|
+
WHERE conname = 'subgraphs_name_unique'
|
|
30
|
+
) THEN
|
|
31
|
+
ALTER TABLE subgraphs ADD CONSTRAINT subgraphs_name_unique UNIQUE (name);
|
|
32
|
+
END IF;
|
|
33
|
+
END$$
|
|
34
|
+
`.execute(db);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
38
|
+
await sql`ALTER TABLE subgraphs DROP CONSTRAINT IF EXISTS subgraphs_name_unique`.execute(
|
|
39
|
+
db,
|
|
40
|
+
);
|
|
41
|
+
await sql`ALTER TABLE subgraphs ADD COLUMN IF NOT EXISTS api_key_id text`.execute(
|
|
42
|
+
db,
|
|
43
|
+
);
|
|
44
|
+
await sql`
|
|
45
|
+
CREATE UNIQUE INDEX IF NOT EXISTS subgraphs_name_unique_no_key
|
|
46
|
+
ON subgraphs (name)
|
|
47
|
+
WHERE api_key_id IS NULL
|
|
48
|
+
`.execute(db);
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Kysely, sql } from "kysely";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Link tenants to projects (1:1 enforced at application layer today;
|
|
5
|
+
* schema supports 1:N for future branching).
|
|
6
|
+
*
|
|
7
|
+
* `ON DELETE SET NULL` so a project delete doesn't cascade into tenant
|
|
8
|
+
* teardown — the tenant row stays (with project_id = NULL) until explicit
|
|
9
|
+
* teardown via the provisioner.
|
|
10
|
+
*/
|
|
11
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
12
|
+
await sql`SET lock_timeout = '30s'`.execute(db);
|
|
13
|
+
await sql`
|
|
14
|
+
ALTER TABLE tenants
|
|
15
|
+
ADD COLUMN project_id uuid REFERENCES projects(id) ON DELETE SET NULL
|
|
16
|
+
`.execute(db);
|
|
17
|
+
await sql`CREATE INDEX IF NOT EXISTS tenants_project_idx ON tenants (project_id)`.execute(
|
|
18
|
+
db,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
23
|
+
await sql`DROP INDEX IF EXISTS tenants_project_idx`.execute(db);
|
|
24
|
+
await sql`ALTER TABLE tenants DROP COLUMN IF EXISTS project_id`.execute(db);
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secondlayer/shared",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
"types": "./dist/src/db/queries/workflows.d.ts",
|
|
74
74
|
"import": "./dist/src/db/queries/workflows.js"
|
|
75
75
|
},
|
|
76
|
+
"./db/queries/tenants": {
|
|
77
|
+
"types": "./dist/src/db/queries/tenants.d.ts",
|
|
78
|
+
"import": "./dist/src/db/queries/tenants.js"
|
|
79
|
+
},
|
|
76
80
|
"./db/queries/marketplace": {
|
|
77
81
|
"types": "./dist/src/db/queries/marketplace.d.ts",
|
|
78
82
|
"import": "./dist/src/db/queries/marketplace.js"
|
|
@@ -89,6 +93,10 @@
|
|
|
89
93
|
"types": "./dist/src/env.d.ts",
|
|
90
94
|
"import": "./dist/src/env.js"
|
|
91
95
|
},
|
|
96
|
+
"./mode": {
|
|
97
|
+
"types": "./dist/src/mode.d.ts",
|
|
98
|
+
"import": "./dist/src/mode.js"
|
|
99
|
+
},
|
|
92
100
|
"./logger": {
|
|
93
101
|
"types": "./dist/src/logger.d.ts",
|
|
94
102
|
"import": "./dist/src/logger.js"
|
|
@@ -101,6 +109,10 @@
|
|
|
101
109
|
"types": "./dist/src/constants.d.ts",
|
|
102
110
|
"import": "./dist/src/constants.js"
|
|
103
111
|
},
|
|
112
|
+
"./pricing": {
|
|
113
|
+
"types": "./dist/src/pricing.d.ts",
|
|
114
|
+
"import": "./dist/src/pricing.js"
|
|
115
|
+
},
|
|
104
116
|
"./crypto": {
|
|
105
117
|
"types": "./dist/src/crypto/hmac.d.ts",
|
|
106
118
|
"import": "./dist/src/crypto/hmac.js"
|
|
@@ -109,6 +121,10 @@
|
|
|
109
121
|
"types": "./dist/src/crypto/hmac.d.ts",
|
|
110
122
|
"import": "./dist/src/crypto/hmac.js"
|
|
111
123
|
},
|
|
124
|
+
"./crypto/secrets": {
|
|
125
|
+
"types": "./dist/src/crypto/secrets.d.ts",
|
|
126
|
+
"import": "./dist/src/crypto/secrets.js"
|
|
127
|
+
},
|
|
112
128
|
"./node": {
|
|
113
129
|
"types": "./dist/src/node/client.d.ts",
|
|
114
130
|
"import": "./dist/src/node/client.js"
|
|
@@ -148,7 +164,7 @@
|
|
|
148
164
|
"prepublishOnly": "bun run build"
|
|
149
165
|
},
|
|
150
166
|
"dependencies": {
|
|
151
|
-
"@secondlayer/stacks": "^0.
|
|
167
|
+
"@secondlayer/stacks": "^0.3.0",
|
|
152
168
|
"kysely": "0.28.15",
|
|
153
169
|
"kysely-postgres-js": "3.0.0",
|
|
154
170
|
"postgres": "^3.4.6",
|