@pikku/kysely 0.12.12 → 0.12.13

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/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.12.13
2
+
3
+ ### Patch Changes
4
+
5
+ - 909eb25: Add audit logging support for function invocations and database queries.
6
+
7
+ Introduces `AuditService` and `createAuditedKysely` — configurable audit capture with best-effort and transactional durability modes. Audit logs capture session metadata (user, org), RPC call details, and Kysely query operations (type, tables, changes). Audit context is scoped per-invocation so nested RPC calls are correctly attributed.
8
+
9
+ - Updated dependencies [909eb25]
10
+ - @pikku/core@0.12.26
11
+
1
12
  ## 0.12.12
2
13
 
3
14
  ### Patch Changes
@@ -20,10 +20,9 @@ export declare class KyselySecretService implements SecretService {
20
20
  init(): Promise<void>;
21
21
  private logAudit;
22
22
  private getKEK;
23
- getSecret(key: string): Promise<string>;
24
- getSecretJSON<R = {}>(key: string): Promise<R>;
23
+ getSecret<T = string>(key: string): Promise<T>;
25
24
  hasSecret(key: string): Promise<boolean>;
26
- setSecretJSON(key: string, value: unknown): Promise<void>;
25
+ setSecret(key: string, value: unknown): Promise<void>;
27
26
  deleteSecret(key: string): Promise<void>;
28
27
  rotateKEK(): Promise<number>;
29
28
  }
@@ -76,10 +76,6 @@ export class KyselySecretService {
76
76
  await this.logAudit(key, 'read');
77
77
  return result;
78
78
  }
79
- async getSecretJSON(key) {
80
- const raw = await this.getSecret(key);
81
- return JSON.parse(raw);
82
- }
83
79
  async hasSecret(key) {
84
80
  const row = await this.db
85
81
  .selectFrom('secrets')
@@ -88,9 +84,8 @@ export class KyselySecretService {
88
84
  .executeTakeFirst();
89
85
  return !!row;
90
86
  }
91
- async setSecretJSON(key, value) {
92
- const plaintext = JSON.stringify(value);
93
- const { ciphertext, wrappedDEK } = await envelopeEncrypt(this.key, plaintext);
87
+ async setSecret(key, value) {
88
+ const { ciphertext, wrappedDEK } = await envelopeEncrypt(this.key, value);
94
89
  const now = new Date().toISOString();
95
90
  await this.db
96
91
  .insertInto('secrets')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/kysely",
3
- "version": "0.12.12",
3
+ "version": "0.12.13",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/src/index.js",
@@ -20,7 +20,7 @@
20
20
  "prepublishOnly": "yarn build"
21
21
  },
22
22
  "peerDependencies": {
23
- "@pikku/core": "^0.12.24"
23
+ "@pikku/core": "^0.12.26"
24
24
  },
25
25
  "dependencies": {
26
26
  "kysely": "^0.28.12"
@@ -93,7 +93,7 @@ export class KyselySecretService implements SecretService {
93
93
  throw new Error(`No KEK available for key_version ${version}`)
94
94
  }
95
95
 
96
- async getSecret(key: string): Promise<string> {
96
+ async getSecret<T = string>(key: string): Promise<T> {
97
97
  const row = await this.db
98
98
  .selectFrom('secrets')
99
99
  .select(['ciphertext', 'wrappedDek', 'keyVersion'])
@@ -103,20 +103,11 @@ export class KyselySecretService implements SecretService {
103
103
  if (!row) throw new Error('Requested secret not found')
104
104
 
105
105
  const kek = this.getKEK(row.keyVersion)
106
- const result = await envelopeDecrypt<string>(
107
- kek,
108
- row.ciphertext,
109
- row.wrappedDek
110
- )
106
+ const result = await envelopeDecrypt<T>(kek, row.ciphertext, row.wrappedDek)
111
107
  await this.logAudit(key, 'read')
112
108
  return result
113
109
  }
114
110
 
115
- async getSecretJSON<R = {}>(key: string): Promise<R> {
116
- const raw = await this.getSecret(key)
117
- return JSON.parse(raw) as R
118
- }
119
-
120
111
  async hasSecret(key: string): Promise<boolean> {
121
112
  const row = await this.db
122
113
  .selectFrom('secrets')
@@ -126,12 +117,8 @@ export class KyselySecretService implements SecretService {
126
117
  return !!row
127
118
  }
128
119
 
129
- async setSecretJSON(key: string, value: unknown): Promise<void> {
130
- const plaintext = JSON.stringify(value)
131
- const { ciphertext, wrappedDEK } = await envelopeEncrypt(
132
- this.key,
133
- plaintext
134
- )
120
+ async setSecret(key: string, value: unknown): Promise<void> {
121
+ const { ciphertext, wrappedDEK } = await envelopeEncrypt(this.key, value)
135
122
  const now = new Date().toISOString()
136
123
 
137
124
  await this.db
@@ -128,7 +128,7 @@ function registerTests(
128
128
  auditReads: true,
129
129
  })
130
130
  await service.init()
131
- await service.setSecretJSON('audit-test', 'value')
131
+ await service.setSecret('audit-test', 'value')
132
132
  await service.getSecret('audit-test')
133
133
  await service.deleteSecret('audit-test')
134
134
 
@@ -152,7 +152,7 @@ function registerTests(
152
152
  auditReads: false,
153
153
  })
154
154
  await service.init()
155
- await service.setSecretJSON('no-read-audit', 'value')
155
+ await service.setSecret('no-read-audit', 'value')
156
156
  await service.getSecret('no-read-audit')
157
157
 
158
158
  const logs = await getDb()