@coffre/db 0.6.2 → 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.
Files changed (72) hide show
  1. package/dist/connect.d.ts +1 -1
  2. package/dist/{database-C63WjCrC.d.ts → database-BEnexh-3.d.ts} +1 -1
  3. package/dist/dialect.d.ts +1 -1
  4. package/dist/grants.d.ts +1 -1
  5. package/dist/hyperdrive.d.ts +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/log.d.ts +22 -1
  8. package/dist/log.js +37 -2
  9. package/dist/migrations/postgres/0004_environment_parents.sql +5 -0
  10. package/dist/migrations/postgres/0005_personal_tokens.sql +5 -0
  11. package/dist/migrations/postgres/0006_uploaded_keys.sql +2 -0
  12. package/dist/migrations/postgres/0007_personal_configs.sql +4 -0
  13. package/dist/migrations/postgres/0008_recipes.sql +19 -0
  14. package/dist/migrations/postgres/0009_handles.sql +3 -0
  15. package/dist/migrations/postgres/meta/0004_snapshot.json +2913 -0
  16. package/dist/migrations/postgres/meta/0005_snapshot.json +2929 -0
  17. package/dist/migrations/postgres/meta/0006_snapshot.json +2935 -0
  18. package/dist/migrations/postgres/meta/0007_snapshot.json +2967 -0
  19. package/dist/migrations/postgres/meta/0008_snapshot.json +2985 -0
  20. package/dist/migrations/postgres/meta/0009_snapshot.json +2985 -0
  21. package/dist/migrations/postgres/meta/_journal.json +42 -0
  22. package/dist/migrations/sqlite/0004_environment_parents.sql +3 -0
  23. package/dist/migrations/sqlite/0005_personal_tokens.sql +37 -0
  24. package/dist/migrations/sqlite/0006_uploaded_keys.sql +1 -0
  25. package/dist/migrations/sqlite/0007_personal_configs.sql +3 -0
  26. package/dist/migrations/sqlite/0008_recipes.sql +15 -0
  27. package/dist/migrations/sqlite/0009_handles.sql +36 -0
  28. package/dist/migrations/sqlite/meta/0004_snapshot.json +2641 -0
  29. package/dist/migrations/sqlite/meta/0005_snapshot.json +2656 -0
  30. package/dist/migrations/sqlite/meta/0006_snapshot.json +2663 -0
  31. package/dist/migrations/sqlite/meta/0007_snapshot.json +2683 -0
  32. package/dist/migrations/sqlite/meta/0008_snapshot.json +2704 -0
  33. package/dist/migrations/sqlite/meta/0009_snapshot.json +2704 -0
  34. package/dist/migrations/sqlite/meta/_journal.json +42 -0
  35. package/dist/portable.d.ts +2 -2
  36. package/dist/{schema-a7PkFgea.d.ts → schema-BZRkBJQZ.d.ts} +102 -0
  37. package/dist/schema-sqlite.d.ts +114 -0
  38. package/dist/schema-sqlite.js +20 -4
  39. package/dist/schema-version.d.ts +1 -1
  40. package/dist/schema-version.js +84 -0
  41. package/dist/schema.d.ts +1 -1
  42. package/dist/schema.js +20 -4
  43. package/package.json +2 -2
  44. package/src/log.ts +40 -1
  45. package/src/migrations/postgres/0004_environment_parents.sql +5 -0
  46. package/src/migrations/postgres/0005_personal_tokens.sql +5 -0
  47. package/src/migrations/postgres/0006_uploaded_keys.sql +2 -0
  48. package/src/migrations/postgres/0007_personal_configs.sql +4 -0
  49. package/src/migrations/postgres/0008_recipes.sql +19 -0
  50. package/src/migrations/postgres/0009_handles.sql +3 -0
  51. package/src/migrations/postgres/meta/0004_snapshot.json +2913 -0
  52. package/src/migrations/postgres/meta/0005_snapshot.json +2929 -0
  53. package/src/migrations/postgres/meta/0006_snapshot.json +2935 -0
  54. package/src/migrations/postgres/meta/0007_snapshot.json +2967 -0
  55. package/src/migrations/postgres/meta/0008_snapshot.json +2985 -0
  56. package/src/migrations/postgres/meta/0009_snapshot.json +2985 -0
  57. package/src/migrations/postgres/meta/_journal.json +42 -0
  58. package/src/migrations/sqlite/0004_environment_parents.sql +3 -0
  59. package/src/migrations/sqlite/0005_personal_tokens.sql +37 -0
  60. package/src/migrations/sqlite/0006_uploaded_keys.sql +1 -0
  61. package/src/migrations/sqlite/0007_personal_configs.sql +3 -0
  62. package/src/migrations/sqlite/0008_recipes.sql +15 -0
  63. package/src/migrations/sqlite/0009_handles.sql +36 -0
  64. package/src/migrations/sqlite/meta/0004_snapshot.json +2641 -0
  65. package/src/migrations/sqlite/meta/0005_snapshot.json +2656 -0
  66. package/src/migrations/sqlite/meta/0006_snapshot.json +2663 -0
  67. package/src/migrations/sqlite/meta/0007_snapshot.json +2683 -0
  68. package/src/migrations/sqlite/meta/0008_snapshot.json +2704 -0
  69. package/src/migrations/sqlite/meta/0009_snapshot.json +2704 -0
  70. package/src/migrations/sqlite/meta/_journal.json +42 -0
  71. package/src/schema.sqlite.ts +31 -3
  72. package/src/schema.ts +37 -3
@@ -29,6 +29,48 @@
29
29
  "when": 1791676486914,
30
30
  "tag": "0003_credential_scopes",
31
31
  "breakpoints": true
32
+ },
33
+ {
34
+ "idx": 4,
35
+ "version": "7",
36
+ "when": 1792244020330,
37
+ "tag": "0004_environment_parents",
38
+ "breakpoints": true
39
+ },
40
+ {
41
+ "idx": 5,
42
+ "version": "7",
43
+ "when": 1792250909587,
44
+ "tag": "0005_personal_tokens",
45
+ "breakpoints": true
46
+ },
47
+ {
48
+ "idx": 6,
49
+ "version": "7",
50
+ "when": 1792252693050,
51
+ "tag": "0006_uploaded_keys",
52
+ "breakpoints": true
53
+ },
54
+ {
55
+ "idx": 7,
56
+ "version": "7",
57
+ "when": 1792253794481,
58
+ "tag": "0007_personal_configs",
59
+ "breakpoints": true
60
+ },
61
+ {
62
+ "idx": 8,
63
+ "version": "7",
64
+ "when": 1792255559691,
65
+ "tag": "0008_recipes",
66
+ "breakpoints": true
67
+ },
68
+ {
69
+ "idx": 9,
70
+ "version": "7",
71
+ "when": 1792281879553,
72
+ "tag": "0009_handles",
73
+ "breakpoints": true
32
74
  }
33
75
  ]
34
76
  }
@@ -0,0 +1,3 @@
1
+ -- Added in place, not by rebuilding the table as drizzle-kit would: a migration runs in one transaction, where SQLite ignores `foreign_keys=OFF`, so dropping a table other rows reference fails. SQLite adds no table constraint to an existing table, so the parent's same-project rule (`environments_parent_in_project` on Postgres) is the app's here.
2
+ ALTER TABLE `environments` ADD `parent_id` text REFERENCES `environments`(`id`) ON DELETE no action CONSTRAINT "environments_parent_check" CHECK(`parent_id` IS NULL OR `parent_id` <> `id`);--> statement-breakpoint
3
+ CREATE INDEX `environments_parent_idx` ON `environments` (`parent_id`);
@@ -0,0 +1,37 @@
1
+ PRAGMA foreign_keys=OFF;--> statement-breakpoint
2
+ CREATE TABLE `__new_credentials` (
3
+ `id` text PRIMARY KEY NOT NULL,
4
+ `kind` text NOT NULL,
5
+ `auth_mac` blob NOT NULL,
6
+ `token_hash` blob NOT NULL,
7
+ `token_hint` text NOT NULL,
8
+ `generation` integer NOT NULL,
9
+ `principal` text NOT NULL,
10
+ `identity_id` text,
11
+ `scope` text,
12
+ `label` text,
13
+ `created_at` integer DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER)) NOT NULL,
14
+ `created_by` text NOT NULL,
15
+ `expires_at` integer NOT NULL,
16
+ `last_used_at` integer,
17
+ `last_used_ip` text,
18
+ `revoked_at` integer,
19
+ `revoked_by` text,
20
+ FOREIGN KEY (`principal`) REFERENCES `vault_members`(`principal`) ON UPDATE no action ON DELETE restrict,
21
+ FOREIGN KEY (`identity_id`,`principal`,`generation`) REFERENCES `identities`(`id`,`principal`,`generation`) ON UPDATE no action ON DELETE restrict,
22
+ CONSTRAINT "credentials_kind_check" CHECK("__new_credentials"."kind" IN ('browser', 'cli', 'service', 'personal')),
23
+ CONSTRAINT "credentials_principal_check" CHECK("__new_credentials"."principal" LIKE 'user:%' OR "__new_credentials"."principal" LIKE 'token:%'),
24
+ CONSTRAINT "credentials_kind_matches_principal" CHECK(("__new_credentials"."kind" = 'service') = ("__new_credentials"."principal" LIKE 'token:%')),
25
+ CONSTRAINT "credentials_token_hash_check" CHECK(octet_length("__new_credentials"."token_hash") = 32),
26
+ CONSTRAINT "credentials_auth_mac_check" CHECK(octet_length("__new_credentials"."auth_mac") = 32)
27
+ );
28
+ --> statement-breakpoint
29
+ INSERT INTO `__new_credentials`("id", "kind", "auth_mac", "token_hash", "token_hint", "generation", "principal", "identity_id", "scope", "label", "created_at", "created_by", "expires_at", "last_used_at", "last_used_ip", "revoked_at", "revoked_by") SELECT "id", "kind", "auth_mac", "token_hash", "token_hint", "generation", "principal", "identity_id", "scope", "label", "created_at", "created_by", "expires_at", "last_used_at", "last_used_ip", "revoked_at", "revoked_by" FROM `credentials`;--> statement-breakpoint
30
+ DROP TABLE `credentials`;--> statement-breakpoint
31
+ ALTER TABLE `__new_credentials` RENAME TO `credentials`;--> statement-breakpoint
32
+ PRAGMA foreign_keys=ON;--> statement-breakpoint
33
+ CREATE INDEX `credentials_principal_idx` ON `credentials` (`principal`,`generation`);--> statement-breakpoint
34
+ CREATE INDEX `credentials_live_idx` ON `credentials` (`principal`,`expires_at`) WHERE "credentials"."revoked_at" IS NULL;--> statement-breakpoint
35
+ CREATE INDEX `credentials_issued_by_idx` ON `credentials` (`principal`,`created_by`,`created_at`);--> statement-breakpoint
36
+ CREATE UNIQUE INDEX `credentials_token_hash_key` ON `credentials` (`token_hash`);--> statement-breakpoint
37
+ CREATE INDEX `audit_log_token_create_idx` ON `audit_log` (json_extract("metadata", '$.targetCredentialId')) WHERE "audit_log"."author" = 'app' AND "audit_log"."action" = 'token.create' AND "audit_log"."decision" = 'allow';
@@ -0,0 +1 @@
1
+ ALTER TABLE `service_bindings` ADD `jwks` text;
@@ -0,0 +1,3 @@
1
+ -- Added in place, not by rebuilding the table as drizzle-kit would: a migration runs in one transaction, where SQLite ignores `foreign_keys=OFF`, so dropping a table other rows reference fails (as 0004).
2
+ ALTER TABLE `environments` ADD `owner` text CONSTRAINT "environments_owner_check" CHECK(`owner` IS NULL OR (`parent_id` IS NOT NULL AND `owner` LIKE 'user:_%'));--> statement-breakpoint
3
+ CREATE UNIQUE INDEX `environments_parent_id_owner_key` ON `environments` (`parent_id`,`owner`) WHERE instr("environments"."slug", '~') = 0;
@@ -0,0 +1,15 @@
1
+ ALTER TABLE `secret_versions` ADD `recipe` text;--> statement-breakpoint
2
+ ALTER TABLE `secret_versions` ADD `pair_id` text;--> statement-breakpoint
3
+ ALTER TABLE `secret_versions` ADD `pair_half` text;--> statement-breakpoint
4
+ -- A version is still only ever erased: its recipe and its pair with it.
5
+ DROP TRIGGER `secret_versions_erase_only`;--> statement-breakpoint
6
+ CREATE TRIGGER `secret_versions_erase_only` BEFORE UPDATE ON `secret_versions`
7
+ WHEN length(NEW.`ciphertext`) <> 0 OR length(NEW.`wrapped_dek`) <> 0
8
+ OR NEW.`id` IS NOT OLD.`id` OR NEW.`secret_id` IS NOT OLD.`secret_id` OR NEW.`version` IS NOT OLD.`version`
9
+ OR NEW.`envelope_version` IS NOT OLD.`envelope_version` OR NEW.`iv` IS NOT OLD.`iv` OR NEW.`auth_tag` IS NOT OLD.`auth_tag`
10
+ OR NEW.`kek_provider` IS NOT OLD.`kek_provider` OR NEW.`kek_id` IS NOT OLD.`kek_id` OR NEW.`kek_version` IS NOT OLD.`kek_version`
11
+ OR NEW.`created_at` IS NOT OLD.`created_at` OR NEW.`created_by` IS NOT OLD.`created_by`
12
+ OR NEW.`recipe` IS NOT OLD.`recipe` OR NEW.`pair_id` IS NOT OLD.`pair_id` OR NEW.`pair_half` IS NOT OLD.`pair_half`
13
+ BEGIN
14
+ SELECT RAISE(ABORT, 'a secret version is only ever erased');
15
+ END;
@@ -0,0 +1,36 @@
1
+ PRAGMA foreign_keys=OFF;--> statement-breakpoint
2
+ CREATE TABLE `__new_credentials` (
3
+ `id` text PRIMARY KEY NOT NULL,
4
+ `kind` text NOT NULL,
5
+ `auth_mac` blob NOT NULL,
6
+ `token_hash` blob NOT NULL,
7
+ `token_hint` text NOT NULL,
8
+ `generation` integer NOT NULL,
9
+ `principal` text NOT NULL,
10
+ `identity_id` text,
11
+ `scope` text,
12
+ `label` text,
13
+ `created_at` integer DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER)) NOT NULL,
14
+ `created_by` text NOT NULL,
15
+ `expires_at` integer NOT NULL,
16
+ `last_used_at` integer,
17
+ `last_used_ip` text,
18
+ `revoked_at` integer,
19
+ `revoked_by` text,
20
+ FOREIGN KEY (`principal`) REFERENCES `vault_members`(`principal`) ON UPDATE no action ON DELETE restrict,
21
+ FOREIGN KEY (`identity_id`,`principal`,`generation`) REFERENCES `identities`(`id`,`principal`,`generation`) ON UPDATE no action ON DELETE restrict,
22
+ CONSTRAINT "credentials_kind_check" CHECK("__new_credentials"."kind" IN ('browser', 'cli', 'service', 'personal', 'handle')),
23
+ CONSTRAINT "credentials_principal_check" CHECK("__new_credentials"."principal" LIKE 'user:%' OR "__new_credentials"."principal" LIKE 'token:%'),
24
+ CONSTRAINT "credentials_kind_matches_principal" CHECK(("__new_credentials"."kind" = 'service') = ("__new_credentials"."principal" LIKE 'token:%')),
25
+ CONSTRAINT "credentials_token_hash_check" CHECK(octet_length("__new_credentials"."token_hash") = 32),
26
+ CONSTRAINT "credentials_auth_mac_check" CHECK(octet_length("__new_credentials"."auth_mac") = 32)
27
+ );
28
+ --> statement-breakpoint
29
+ INSERT INTO `__new_credentials`("id", "kind", "auth_mac", "token_hash", "token_hint", "generation", "principal", "identity_id", "scope", "label", "created_at", "created_by", "expires_at", "last_used_at", "last_used_ip", "revoked_at", "revoked_by") SELECT "id", "kind", "auth_mac", "token_hash", "token_hint", "generation", "principal", "identity_id", "scope", "label", "created_at", "created_by", "expires_at", "last_used_at", "last_used_ip", "revoked_at", "revoked_by" FROM `credentials`;--> statement-breakpoint
30
+ DROP TABLE `credentials`;--> statement-breakpoint
31
+ ALTER TABLE `__new_credentials` RENAME TO `credentials`;--> statement-breakpoint
32
+ PRAGMA foreign_keys=ON;--> statement-breakpoint
33
+ CREATE INDEX `credentials_principal_idx` ON `credentials` (`principal`,`generation`);--> statement-breakpoint
34
+ CREATE INDEX `credentials_live_idx` ON `credentials` (`principal`,`expires_at`) WHERE "credentials"."revoked_at" IS NULL;--> statement-breakpoint
35
+ CREATE INDEX `credentials_issued_by_idx` ON `credentials` (`principal`,`created_by`,`created_at`);--> statement-breakpoint
36
+ CREATE UNIQUE INDEX `credentials_token_hash_key` ON `credentials` (`token_hash`);