@coffre/db 0.8.2 → 0.10.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 (65) hide show
  1. package/dist/connect.d.ts +1 -1
  2. package/dist/{database-BEnexh-3.d.ts → database-BFnO2b2P.d.ts} +1 -1
  3. package/dist/dialect.d.ts +1 -1
  4. package/dist/grants.d.ts +2 -2
  5. package/dist/hyperdrive.d.ts +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/log.d.ts +7 -1
  8. package/dist/log.js +11 -1
  9. package/dist/migrations/postgres/0010_handle_places.sql +2 -0
  10. package/dist/migrations/postgres/0011_plain_values.sql +19 -0
  11. package/dist/migrations/postgres/0012_sensitive_values.sql +18 -0
  12. package/dist/migrations/postgres/0013_contributor_role.sql +5 -0
  13. package/dist/migrations/postgres/0014_custom_roles.sql +4 -0
  14. package/dist/migrations/postgres/meta/0010_snapshot.json +2991 -0
  15. package/dist/migrations/postgres/meta/0011_snapshot.json +2997 -0
  16. package/dist/migrations/postgres/meta/0012_snapshot.json +3004 -0
  17. package/dist/migrations/postgres/meta/0013_snapshot.json +3004 -0
  18. package/dist/migrations/postgres/meta/0014_snapshot.json +3000 -0
  19. package/dist/migrations/postgres/meta/_journal.json +35 -0
  20. package/dist/migrations/sqlite/0010_handle_places.sql +2 -0
  21. package/dist/migrations/sqlite/0011_plain_values.sql +14 -0
  22. package/dist/migrations/sqlite/0012_sensitive_values.sql +15 -0
  23. package/dist/migrations/sqlite/0013_contributor_role.sql +28 -0
  24. package/dist/migrations/sqlite/0014_custom_roles.sql +27 -0
  25. package/dist/migrations/sqlite/meta/0010_snapshot.json +2711 -0
  26. package/dist/migrations/sqlite/meta/0011_snapshot.json +2718 -0
  27. package/dist/migrations/sqlite/meta/0012_snapshot.json +2726 -0
  28. package/dist/migrations/sqlite/meta/0013_snapshot.json +2726 -0
  29. package/dist/migrations/sqlite/meta/0014_snapshot.json +2722 -0
  30. package/dist/migrations/sqlite/meta/_journal.json +35 -0
  31. package/dist/portable.d.ts +2 -2
  32. package/dist/{schema-BZRkBJQZ.d.ts → schema-NBVA9q-s.d.ts} +51 -0
  33. package/dist/schema-sqlite.d.ts +55 -0
  34. package/dist/schema-sqlite.js +5 -6
  35. package/dist/schema-version.d.ts +1 -1
  36. package/dist/schema-version.js +70 -0
  37. package/dist/schema.d.ts +1 -1
  38. package/dist/schema.js +5 -7
  39. package/package.json +2 -2
  40. package/src/grants.ts +3 -2
  41. package/src/log.ts +16 -0
  42. package/src/migrations/postgres/0010_handle_places.sql +2 -0
  43. package/src/migrations/postgres/0011_plain_values.sql +19 -0
  44. package/src/migrations/postgres/0012_sensitive_values.sql +18 -0
  45. package/src/migrations/postgres/0013_contributor_role.sql +5 -0
  46. package/src/migrations/postgres/0014_custom_roles.sql +4 -0
  47. package/src/migrations/postgres/meta/0010_snapshot.json +2991 -0
  48. package/src/migrations/postgres/meta/0011_snapshot.json +2997 -0
  49. package/src/migrations/postgres/meta/0012_snapshot.json +3004 -0
  50. package/src/migrations/postgres/meta/0013_snapshot.json +3004 -0
  51. package/src/migrations/postgres/meta/0014_snapshot.json +3000 -0
  52. package/src/migrations/postgres/meta/_journal.json +35 -0
  53. package/src/migrations/sqlite/0010_handle_places.sql +2 -0
  54. package/src/migrations/sqlite/0011_plain_values.sql +14 -0
  55. package/src/migrations/sqlite/0012_sensitive_values.sql +15 -0
  56. package/src/migrations/sqlite/0013_contributor_role.sql +28 -0
  57. package/src/migrations/sqlite/0014_custom_roles.sql +27 -0
  58. package/src/migrations/sqlite/meta/0010_snapshot.json +2711 -0
  59. package/src/migrations/sqlite/meta/0011_snapshot.json +2718 -0
  60. package/src/migrations/sqlite/meta/0012_snapshot.json +2726 -0
  61. package/src/migrations/sqlite/meta/0013_snapshot.json +2726 -0
  62. package/src/migrations/sqlite/meta/0014_snapshot.json +2722 -0
  63. package/src/migrations/sqlite/meta/_journal.json +35 -0
  64. package/src/schema.sqlite.ts +15 -9
  65. package/src/schema.ts +15 -10
@@ -71,6 +71,41 @@
71
71
  "when": 1792281880190,
72
72
  "tag": "0009_handles",
73
73
  "breakpoints": true
74
+ },
75
+ {
76
+ "idx": 10,
77
+ "version": "6",
78
+ "when": 1792315000277,
79
+ "tag": "0010_handle_places",
80
+ "breakpoints": true
81
+ },
82
+ {
83
+ "idx": 11,
84
+ "version": "6",
85
+ "when": 1792317461299,
86
+ "tag": "0011_plain_values",
87
+ "breakpoints": true
88
+ },
89
+ {
90
+ "idx": 12,
91
+ "version": "6",
92
+ "when": 1792340920098,
93
+ "tag": "0012_sensitive_values",
94
+ "breakpoints": true
95
+ },
96
+ {
97
+ "idx": 13,
98
+ "version": "6",
99
+ "when": 1792343374795,
100
+ "tag": "0013_contributor_role",
101
+ "breakpoints": true
102
+ },
103
+ {
104
+ "idx": 14,
105
+ "version": "6",
106
+ "when": 1792345777255,
107
+ "tag": "0014_custom_roles",
108
+ "breakpoints": true
74
109
  }
75
110
  ]
76
111
  }
@@ -1,4 +1,3 @@
1
- import { assignableToEnvironment, ROLE_NAMES } from '@coffre/core/access';
2
1
  import { sql } from 'drizzle-orm';
3
2
  import {
4
3
  blob,
@@ -177,6 +176,16 @@ export const secretVersions = sqliteTable(
177
176
  // and each says which half it holds: 'private' or 'public'.
178
177
  pairId: text('pair_id'),
179
178
  pairHalf: text('pair_half'),
179
+ // The value itself, for a plain one: a key marked not secret, an account's
180
+ // id, which whoever lists the environment sees and a read serves without
181
+ // the vault. Null for a secret. Its ciphertext is kept as any version's,
182
+ // for what opens values through the vault (a reference, a fork's copy).
183
+ plaintext: text(),
184
+ // A sensitive value: never handed back to a person, Owners included, only
185
+ // used for them through the credential proxy, or read by a service
186
+ // account. Its data key's wrap binds it, so the vault opens a version
187
+ // flipped back as nothing. Never plain too.
188
+ sensitive: flag('sensitive').notNull().default(false),
180
189
  },
181
190
  (table) => [
182
191
  unique('secret_versions_secret_id_version_key').on(table.secretId, table.version),
@@ -216,9 +225,6 @@ export const dismissedKeys = sqliteTable(
216
225
  ],
217
226
  );
218
227
 
219
- const ROLES = sql.raw(ROLE_NAMES.map((role) => `'${role}'`).join(', '));
220
- const ENVIRONMENT_ROLES = sql.raw(ROLE_NAMES.filter(assignableToEnvironment).map((role) => `'${role}'`).join(', '));
221
-
222
228
  export const vaultMembers = sqliteTable(
223
229
  'vault_members',
224
230
  {
@@ -270,11 +276,9 @@ export const vaultGrants = sqliteTable(
270
276
  sql`((${table.projectId} IS NULL) <> (${table.environmentId} IS NULL) AND ${table.environmentSlug} IS NULL) OR (${table.projectId} IS NULL AND ${table.environmentId} IS NULL)`,
271
277
  ),
272
278
  check('vault_grants_environment_slug_check', sql`${table.environmentSlug} IS NULL OR (${isSlug(table.environmentSlug, 63)})`),
273
- check('vault_grants_role_check', sql`${table.role} IN (${ROLES})`),
274
- check(
275
- 'vault_grants_environment_role_check',
276
- sql`(${table.environmentId} IS NULL AND ${table.environmentSlug} IS NULL) OR ${table.role} IN (${ENVIRONMENT_ROLES})`,
277
- ),
279
+ // A role's id, one that ships or one an Owner made (`ROLE_ID`): which the instance's policy defines, and which of them an
280
+ // environment may be granted, the vault decides, as the policy is now (docs/design/roles.md).
281
+ check('vault_grants_role_check', sql`length(${table.role}) BETWEEN 2 AND 32 AND ${table.role} GLOB '[a-z]*' AND ${table.role} NOT GLOB '*[^a-z0-9-]*'`),
278
282
  unique('vault_grants_on_project').on(table.principal, table.projectId),
279
283
  unique('vault_grants_on_environment').on(table.principal, table.environmentId),
280
284
  unique('vault_grants_on_environment_slug').on(table.principal, table.environmentSlug),
@@ -671,6 +675,8 @@ export const credentials = sqliteTable(
671
675
  identityId: text('identity_id'),
672
676
  // What a service or personal token reaches (`CredentialScope`), JSON: null for a session, one a binding issued (its binding's), or one of 0.4 the app has not sealed yet.
673
677
  scope: text(),
678
+ // The environments a handle was made for, by id, each with whether it was asked for as `@me`, JSON: null for any other credential, or a handle of 0.8.
679
+ places: text(),
674
680
  label: text(),
675
681
  createdAt: createdAt(),
676
682
  createdBy: text('created_by').notNull(),
package/src/schema.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { assignableToEnvironment, ROLE_NAMES } from '@coffre/core/access';
2
1
  import { sql } from 'drizzle-orm';
3
2
  import {
4
3
  bigint,
@@ -171,6 +170,16 @@ export const secretVersions = pgTable(
171
170
  // and each says which half it holds: 'private' or 'public'.
172
171
  pairId: uuid('pair_id'),
173
172
  pairHalf: text('pair_half'),
173
+ // The value itself, for a plain one: a key marked not secret, an account's
174
+ // id, which whoever lists the environment sees and a read serves without
175
+ // the vault. Null for a secret. Its ciphertext is kept as any version's,
176
+ // for what opens values through the vault (a reference, a fork's copy).
177
+ plaintext: text(),
178
+ // A sensitive value: never handed back to a person, Owners included, only
179
+ // used for them through the credential proxy, or read by a service
180
+ // account. Its data key's wrap binds it, so the vault opens a version
181
+ // flipped back as nothing. Never plain too.
182
+ sensitive: boolean().notNull().default(false),
174
183
  },
175
184
  (table) => [
176
185
  unique('secret_versions_secret_id_version_key').on(table.secretId, table.version),
@@ -214,10 +223,6 @@ export const dismissedKeys = pgTable(
214
223
  ],
215
224
  );
216
225
 
217
- /** The role catalogue, as SQL: every role, and those an environment may be granted. */
218
- const ROLES = sql.raw(ROLE_NAMES.map((role) => `'${role}'`).join(', '));
219
- const ENVIRONMENT_ROLES = sql.raw(ROLE_NAMES.filter(assignableToEnvironment).map((role) => `'${role}'`).join(', '));
220
-
221
226
  /**
222
227
  * The vault's member directory: everyone it has admitted, written by the
223
228
  * vault alone, read by both. A principal with no row is no member.
@@ -289,11 +294,9 @@ export const vaultGrants = pgTable(
289
294
  sql`((${table.projectId} IS NULL) <> (${table.environmentId} IS NULL) AND ${table.environmentSlug} IS NULL) OR (${table.projectId} IS NULL AND ${table.environmentId} IS NULL)`,
290
295
  ),
291
296
  check('vault_grants_environment_slug_check', sql`${table.environmentSlug} IS NULL OR ${table.environmentSlug} ~ '^[a-z0-9][a-z0-9-]{0,62}$'`),
292
- check('vault_grants_role_check', sql`${table.role} IN (${ROLES})`),
293
- check(
294
- 'vault_grants_environment_role_check',
295
- sql`(${table.environmentId} IS NULL AND ${table.environmentSlug} IS NULL) OR ${table.role} IN (${ENVIRONMENT_ROLES})`,
296
- ),
297
+ // A role's id, one that ships or one an Owner made (`ROLE_ID`): which the instance's policy defines, and which of them an
298
+ // environment may be granted, the vault decides, as the policy is now (docs/design/roles.md).
299
+ check('vault_grants_role_check', sql`${table.role} ~ '^[a-z][a-z0-9-]{1,31}$'`),
297
300
  unique('vault_grants_on_project').on(table.principal, table.projectId),
298
301
  unique('vault_grants_on_environment').on(table.principal, table.environmentId),
299
302
  unique('vault_grants_on_environment_slug').on(table.principal, table.environmentSlug),
@@ -745,6 +748,8 @@ export const credentials = pgTable(
745
748
  identityId: uuid('identity_id'),
746
749
  // What a service or personal token reaches (`CredentialScope`), JSON: null for a session, one a binding issued (its binding's), or one of 0.4 the app has not sealed yet.
747
750
  scope: text(),
751
+ // The environments a handle was made for, by id, each with whether it was asked for as `@me`, JSON: null for any other credential, or a handle of 0.8.
752
+ places: text(),
748
753
  label: text(),
749
754
  createdAt: createdAt(),
750
755
  createdBy: text('created_by').notNull(),