@coffre/db 0.9.0 → 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.
- package/dist/connect.d.ts +1 -1
- package/dist/{database-hd1hAll-.d.ts → database-BFnO2b2P.d.ts} +1 -1
- package/dist/dialect.d.ts +1 -1
- package/dist/grants.d.ts +2 -2
- package/dist/hyperdrive.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/log.d.ts +7 -1
- package/dist/log.js +11 -1
- package/dist/migrations/postgres/0012_sensitive_values.sql +18 -0
- package/dist/migrations/postgres/0013_contributor_role.sql +5 -0
- package/dist/migrations/postgres/0014_custom_roles.sql +4 -0
- package/dist/migrations/postgres/meta/0012_snapshot.json +3004 -0
- package/dist/migrations/postgres/meta/0013_snapshot.json +3004 -0
- package/dist/migrations/postgres/meta/0014_snapshot.json +3000 -0
- package/dist/migrations/postgres/meta/_journal.json +21 -0
- package/dist/migrations/sqlite/0012_sensitive_values.sql +15 -0
- package/dist/migrations/sqlite/0013_contributor_role.sql +28 -0
- package/dist/migrations/sqlite/0014_custom_roles.sql +27 -0
- package/dist/migrations/sqlite/meta/0012_snapshot.json +2726 -0
- package/dist/migrations/sqlite/meta/0013_snapshot.json +2726 -0
- package/dist/migrations/sqlite/meta/0014_snapshot.json +2722 -0
- package/dist/migrations/sqlite/meta/_journal.json +21 -0
- package/dist/portable.d.ts +2 -2
- package/dist/{schema-CCYKTG-E.d.ts → schema-NBVA9q-s.d.ts} +17 -0
- package/dist/schema-sqlite.d.ts +17 -0
- package/dist/schema-sqlite.js +3 -6
- package/dist/schema-version.d.ts +1 -1
- package/dist/schema-version.js +42 -0
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +3 -7
- package/package.json +2 -2
- package/src/grants.ts +3 -2
- package/src/log.ts +16 -0
- package/src/migrations/postgres/0012_sensitive_values.sql +18 -0
- package/src/migrations/postgres/0013_contributor_role.sql +5 -0
- package/src/migrations/postgres/0014_custom_roles.sql +4 -0
- package/src/migrations/postgres/meta/0012_snapshot.json +3004 -0
- package/src/migrations/postgres/meta/0013_snapshot.json +3004 -0
- package/src/migrations/postgres/meta/0014_snapshot.json +3000 -0
- package/src/migrations/postgres/meta/_journal.json +21 -0
- package/src/migrations/sqlite/0012_sensitive_values.sql +15 -0
- package/src/migrations/sqlite/0013_contributor_role.sql +28 -0
- package/src/migrations/sqlite/0014_custom_roles.sql +27 -0
- package/src/migrations/sqlite/meta/0012_snapshot.json +2726 -0
- package/src/migrations/sqlite/meta/0013_snapshot.json +2726 -0
- package/src/migrations/sqlite/meta/0014_snapshot.json +2722 -0
- package/src/migrations/sqlite/meta/_journal.json +21 -0
- package/src/schema.sqlite.ts +8 -9
- package/src/schema.ts +8 -10
package/dist/connect.d.ts
CHANGED
package/dist/dialect.d.ts
CHANGED
package/dist/grants.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as Queryable } from "./database-
|
|
1
|
+
import { i as Queryable } from "./database-BFnO2b2P.js";
|
|
2
2
|
import { Authenticity, Newest } from "./log.js";
|
|
3
|
-
import { Conversion, ConversionInput, InstanceRole, Scope } from "@coffre/core/access";
|
|
4
3
|
import { StoredEntry } from "@coffre/core/audit";
|
|
4
|
+
import { Conversion, ConversionInput, InstanceRole, Scope } from "@coffre/core/access";
|
|
5
5
|
//#region src/grants.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* One grant, as `vault_grants` holds it: on a project (`environmentId`
|
package/dist/hyperdrive.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { m as schema_d_exports } from "./schema-
|
|
2
|
-
import { a as Transaction, c as tablesOf, i as Queryable, n as PoolLike, o as createDatabase, r as QueryOutsideTransaction, s as own, t as Database } from "./database-
|
|
1
|
+
import { m as schema_d_exports } from "./schema-NBVA9q-s.js";
|
|
2
|
+
import { a as Transaction, c as tablesOf, i as Queryable, n as PoolLike, o as createDatabase, r as QueryOutsideTransaction, s as own, t as Database } from "./database-BFnO2b2P.js";
|
|
3
3
|
export { Database, PoolLike, QueryOutsideTransaction, Queryable, Transaction, createDatabase, own, schema_d_exports as schema, tablesOf };
|
package/dist/log.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Transaction, i as Queryable } from "./database-
|
|
1
|
+
import { a as Transaction, i as Queryable } from "./database-BFnO2b2P.js";
|
|
2
2
|
import { SQL } from "drizzle-orm";
|
|
3
3
|
import { LogKey, StoredEntry } from "@coffre/core/audit";
|
|
4
4
|
//#region src/log.d.ts
|
|
@@ -473,6 +473,12 @@ export type Authenticity = {
|
|
|
473
473
|
};
|
|
474
474
|
/** Up to `limit` of the entries in the vault's name, allowed, of one `action`, before `before` (the newest when undefined), newest first. */
|
|
475
475
|
export declare function newestVaultEntries(db: Queryable, action: string, limit: number, before?: bigint): Promise<StoredEntry[]>;
|
|
476
|
+
/**
|
|
477
|
+
* The number of the newest entry in the vault's name, allowed, of one
|
|
478
|
+
* `action`, or null for none: whether one was appended since, and nothing
|
|
479
|
+
* of what it says, so its MAC is not checked. One indexed read.
|
|
480
|
+
*/
|
|
481
|
+
export declare function newestVaultSeq(db: Queryable, action: string): Promise<bigint | null>;
|
|
476
482
|
/** How many entries in its name the vault reads back, a page at a time, for its own newest of a kind (`newestAuthentic`). */
|
|
477
483
|
export declare const LOOK_BACK: {
|
|
478
484
|
page: number;
|
package/dist/log.js
CHANGED
|
@@ -203,6 +203,16 @@ async function newestVaultEntries(db, action, limit, before) {
|
|
|
203
203
|
const { auditLog } = tablesOf(db);
|
|
204
204
|
return await db.select(entryColumns(db)).from(auditLog).where(and(eq(auditLog.author, "vault"), eq(auditLog.action, action), eq(auditLog.decision, "allow"), before === void 0 ? void 0 : lt(auditLog.seq, before))).orderBy(desc(auditLog.seq)).limit(limit);
|
|
205
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* The number of the newest entry in the vault's name, allowed, of one
|
|
208
|
+
* `action`, or null for none: whether one was appended since, and nothing
|
|
209
|
+
* of what it says, so its MAC is not checked. One indexed read.
|
|
210
|
+
*/
|
|
211
|
+
async function newestVaultSeq(db, action) {
|
|
212
|
+
const { auditLog } = tablesOf(db);
|
|
213
|
+
const [row] = await db.select({ seq: auditLog.seq }).from(auditLog).where(and(eq(auditLog.author, "vault"), eq(auditLog.action, action), eq(auditLog.decision, "allow"))).orderBy(desc(auditLog.seq)).limit(1);
|
|
214
|
+
return row?.seq ?? null;
|
|
215
|
+
}
|
|
206
216
|
/** How many entries in its name the vault reads back, a page at a time, for its own newest of a kind (`newestAuthentic`). */
|
|
207
217
|
const LOOK_BACK = {
|
|
208
218
|
page: 32,
|
|
@@ -229,4 +239,4 @@ async function newestAuthentic(page, check) {
|
|
|
229
239
|
return "unreached";
|
|
230
240
|
}
|
|
231
241
|
//#endregion
|
|
232
|
-
export { BATCH_BYTES, LOOK_BACK, LogHeadMismatch, LogRewound, appendEntries, entryColumns, forgetLogHeads, lockLogHead, newestAuthentic, newestVaultEntries, withinBytes };
|
|
242
|
+
export { BATCH_BYTES, LOOK_BACK, LogHeadMismatch, LogRewound, appendEntries, entryColumns, forgetLogHeads, lockLogHead, newestAuthentic, newestVaultEntries, newestVaultSeq, withinBytes };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- Sensitive values (0.10): a version never handed back to a person, which the vault's wrap of its data key binds. Defaults to false, so the release before writes on as it did.
|
|
2
|
+
ALTER TABLE "secret_versions" ADD COLUMN "sensitive" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
|
3
|
+
-- A version is still only ever erased: its sensitivity with the rest of it.
|
|
4
|
+
CREATE OR REPLACE FUNCTION secret_versions_erase_only() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
5
|
+
BEGIN
|
|
6
|
+
IF octet_length(NEW.ciphertext) <> 0 OR octet_length(NEW.wrapped_dek) <> 0 OR NEW.plaintext IS NOT NULL
|
|
7
|
+
OR (NEW.id, NEW.secret_id, NEW.version, NEW.envelope_version, NEW.iv, NEW.auth_tag,
|
|
8
|
+
NEW.kek_provider, NEW.kek_id, NEW.kek_version, NEW.created_at, NEW.created_by,
|
|
9
|
+
NEW.recipe, NEW.pair_id, NEW.pair_half, NEW.sensitive)
|
|
10
|
+
IS DISTINCT FROM
|
|
11
|
+
(OLD.id, OLD.secret_id, OLD.version, OLD.envelope_version, OLD.iv, OLD.auth_tag,
|
|
12
|
+
OLD.kek_provider, OLD.kek_id, OLD.kek_version, OLD.created_at, OLD.created_by,
|
|
13
|
+
OLD.recipe, OLD.pair_id, OLD.pair_half, OLD.sensitive) THEN
|
|
14
|
+
RAISE EXCEPTION 'a secret version is only ever erased' USING ERRCODE = 'insufficient_privilege';
|
|
15
|
+
END IF;
|
|
16
|
+
RETURN NEW;
|
|
17
|
+
END
|
|
18
|
+
$$;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- The Contributor role (0.10): use and write, never read. The role checks widen to it, which the release before never grants.
|
|
2
|
+
ALTER TABLE "vault_grants" DROP CONSTRAINT "vault_grants_role_check";--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "vault_grants" DROP CONSTRAINT "vault_grants_environment_role_check";--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "vault_grants" ADD CONSTRAINT "vault_grants_role_check" CHECK ("vault_grants"."role" IN ('viewer', 'contributor', 'developer', 'maintainer', 'access-manager', 'auditor', 'owner'));--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "vault_grants" ADD CONSTRAINT "vault_grants_environment_role_check" CHECK (("vault_grants"."environment_id" IS NULL AND "vault_grants"."environment_slug" IS NULL) OR "vault_grants"."role" IN ('viewer', 'contributor', 'developer', 'auditor'));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- Roles an Owner makes (0.10): a grant names a role by its id, which the vault's policy defines; which of them an environment may be granted, the vault decides. The checks widen: the release before grants only the roles it ships.
|
|
2
|
+
ALTER TABLE "vault_grants" DROP CONSTRAINT "vault_grants_environment_role_check";--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "vault_grants" DROP CONSTRAINT "vault_grants_role_check";--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "vault_grants" ADD CONSTRAINT "vault_grants_role_check" CHECK ("vault_grants"."role" ~ '^[a-z][a-z0-9-]{1,31}$');
|