@cipherstash/stack 0.1.0 → 0.2.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 (40) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +10 -12
  3. package/dist/bin/stash.js +27 -12
  4. package/dist/bin/stash.js.map +1 -1
  5. package/dist/{chunk-SJ7JO4ME.js → chunk-5G4F4JJG.js} +1 -1
  6. package/dist/{chunk-SJ7JO4ME.js.map → chunk-5G4F4JJG.js.map} +1 -1
  7. package/dist/{chunk-2GZMIJFO.js → chunk-LHZ6KZIG.js} +29 -14
  8. package/dist/chunk-LHZ6KZIG.js.map +1 -0
  9. package/dist/{client-DtGq9dJp.d.ts → client-BV9pXC-d.d.ts} +30 -15
  10. package/dist/{client-BxJG56Ey.d.cts → client-D-ZH8SB2.d.cts} +30 -15
  11. package/dist/client.d.cts +2 -2
  12. package/dist/client.d.ts +2 -2
  13. package/dist/drizzle/index.cjs.map +1 -1
  14. package/dist/drizzle/index.d.cts +2 -2
  15. package/dist/drizzle/index.d.ts +2 -2
  16. package/dist/drizzle/index.js +1 -1
  17. package/dist/dynamodb/index.d.cts +2 -2
  18. package/dist/dynamodb/index.d.ts +2 -2
  19. package/dist/index.cjs +27 -12
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +3 -3
  22. package/dist/index.d.ts +3 -3
  23. package/dist/index.js +2 -2
  24. package/dist/schema/index.d.cts +1 -1
  25. package/dist/schema/index.d.ts +1 -1
  26. package/dist/secrets/index.cjs +27 -12
  27. package/dist/secrets/index.cjs.map +1 -1
  28. package/dist/secrets/index.d.cts +1 -1
  29. package/dist/secrets/index.d.ts +1 -1
  30. package/dist/secrets/index.js +2 -2
  31. package/dist/supabase/index.d.cts +2 -2
  32. package/dist/supabase/index.d.ts +2 -2
  33. package/dist/{types-public-BCj1L4fi.d.ts → types-public-Dfg-hkuQ.d.cts} +35 -11
  34. package/dist/{types-public-BCj1L4fi.d.cts → types-public-Dfg-hkuQ.d.ts} +35 -11
  35. package/dist/types-public.cjs.map +1 -1
  36. package/dist/types-public.d.cts +1 -1
  37. package/dist/types-public.d.ts +1 -1
  38. package/dist/types-public.js +1 -1
  39. package/package.json +1 -1
  40. package/dist/chunk-2GZMIJFO.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @cipherstash/stack
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 68c8199: Improved typing for model interfaces and full bun support.
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -139,29 +139,27 @@ const decrypted = await client.decrypt(encrypted.data)
139
139
 
140
140
  Encrypt or decrypt an entire object. Only fields matching your schema are encrypted; other fields pass through unchanged.
141
141
 
142
+ The return type is **schema-aware**: fields matching the table schema are typed as `Encrypted`, while other fields retain their original types. For best results, let TypeScript infer the type parameters from the arguments:
143
+
142
144
  ```typescript
145
+ type User = { id: string; email: string; createdAt: Date }
146
+
143
147
  const user = {
144
148
  id: "user_123",
145
149
  email: "alice@example.com", // defined in schema -> encrypted
146
150
  createdAt: new Date(), // not in schema -> unchanged
147
151
  }
148
152
 
149
- // Encrypt a model
153
+ // Let TypeScript infer the return type from the schema
150
154
  const encryptedResult = await client.encryptModel(user, users)
155
+ // encryptedResult.data.email -> Encrypted
156
+ // encryptedResult.data.id -> string
157
+ // encryptedResult.data.createdAt -> Date
151
158
 
152
159
  // Decrypt a model
153
160
  const decryptedResult = await client.decryptModel(encryptedResult.data)
154
161
  ```
155
162
 
156
- Type-safe generics are supported:
157
-
158
- ```typescript
159
- type User = { id: string; email: string; createdAt: Date }
160
-
161
- const result = await client.encryptModel<User>(user, users)
162
- const back = await client.decryptModel<User>(result.data)
163
- ```
164
-
165
163
  ### Bulk Operations
166
164
 
167
165
  All bulk methods make a single call to ZeroKMS regardless of the number of records, while still using a unique key per value.
@@ -592,11 +590,11 @@ function Encryption(config: EncryptionClientConfig): Promise<EncryptionClient>
592
590
  | `decrypt` | `(encryptedData)` | `DecryptOperation` (thenable) |
593
591
  | `encryptQuery` | `(plaintext, { column, table, queryType?, returnType? })` | `EncryptQueryOperation` (thenable) |
594
592
  | `encryptQuery` | `(terms: ScalarQueryTerm[])` | `BatchEncryptQueryOperation` (thenable) |
595
- | `encryptModel` | `(model, table)` | `EncryptModelOperation<T>` (thenable) |
593
+ | `encryptModel` | `(model, table)` | `EncryptModelOperation<EncryptedFromSchema<T, S>>` (thenable) |
596
594
  | `decryptModel` | `(encryptedModel)` | `DecryptModelOperation<T>` (thenable) |
597
595
  | `bulkEncrypt` | `(plaintexts, { column, table })` | `BulkEncryptOperation` (thenable) |
598
596
  | `bulkDecrypt` | `(encryptedPayloads)` | `BulkDecryptOperation` (thenable) |
599
- | `bulkEncryptModels` | `(models, table)` | `BulkEncryptModelsOperation<T>` (thenable) |
597
+ | `bulkEncryptModels` | `(models, table)` | `BulkEncryptModelsOperation<EncryptedFromSchema<T, S>>` (thenable) |
600
598
  | `bulkDecryptModels` | `(encryptedModels)` | `BulkDecryptModelsOperation<T>` (thenable) |
601
599
 
602
600
  All operations are thenable (awaitable) and support `.withLockContext(lockContext)` for identity-aware encryption.
package/dist/bin/stash.js CHANGED
@@ -3937,10 +3937,10 @@ var EncryptionClient = class {
3937
3937
  this.client = await newClient({
3938
3938
  encryptConfig: validated,
3939
3939
  clientOpts: {
3940
- workspaceCrn: config3.workspaceCrn,
3941
- accessKey: config3.accessKey,
3942
- clientId: config3.clientId,
3943
- clientKey: config3.clientKey,
3940
+ workspaceCrn: config3.workspaceCrn ?? process.env.CS_WORKSPACE_CRN,
3941
+ accessKey: config3.accessKey ?? process.env.CS_CLIENT_ACCESS_KEY,
3942
+ clientId: config3.clientId ?? process.env.CS_CLIENT_ID,
3943
+ clientKey: config3.clientKey ?? process.env.CS_CLIENT_KEY,
3944
3944
  keyset: toFfiKeysetIdentifier(config3.keyset)
3945
3945
  }
3946
3946
  });
@@ -4090,10 +4090,16 @@ var EncryptionClient = class {
4090
4090
  * All other fields are passed through unchanged. Returns a thenable operation
4091
4091
  * that supports `.withLockContext()` for identity-aware encryption.
4092
4092
  *
4093
+ * The return type is **schema-aware**: fields matching the table schema are
4094
+ * typed as `Encrypted`, while other fields retain their original types. For
4095
+ * best results, let TypeScript infer the type parameters from the arguments
4096
+ * rather than providing an explicit type argument.
4097
+ *
4093
4098
  * @param input - The model object with plaintext values to encrypt.
4094
4099
  * @param table - The table schema defining which fields to encrypt.
4095
- * @returns An `EncryptModelOperation<T>` that can be awaited to get a `Result`
4096
- * containing the model with encrypted fields, or an `EncryptionError`.
4100
+ * @returns An `EncryptModelOperation` that can be awaited to get a `Result`
4101
+ * containing the model with schema-defined fields typed as `Encrypted`,
4102
+ * or an `EncryptionError`.
4097
4103
  *
4098
4104
  * @example
4099
4105
  * ```typescript
@@ -4108,7 +4114,9 @@ var EncryptionClient = class {
4108
4114
  *
4109
4115
  * const client = await Encryption({ schemas: [usersSchema] })
4110
4116
  *
4111
- * const result = await client.encryptModel<User>(
4117
+ * // Let TypeScript infer the return type from the schema.
4118
+ * // result.data.email is typed as `Encrypted`, result.data.id stays `string`.
4119
+ * const result = await client.encryptModel(
4112
4120
  * { id: "user_123", email: "alice@example.com", createdAt: new Date() },
4113
4121
  * usersSchema,
4114
4122
  * )
@@ -4116,8 +4124,8 @@ var EncryptionClient = class {
4116
4124
  * if (result.failure) {
4117
4125
  * console.error(result.failure.message)
4118
4126
  * } else {
4119
- * // result.data.id is unchanged, result.data.email is encrypted
4120
- * console.log(result.data)
4127
+ * console.log(result.data.id) // string
4128
+ * console.log(result.data.email) // Encrypted
4121
4129
  * }
4122
4130
  * ```
4123
4131
  */
@@ -4162,10 +4170,15 @@ var EncryptionClient = class {
4162
4170
  * while still using a unique key for each encrypted value. Only fields
4163
4171
  * matching the table schema are encrypted; other fields pass through unchanged.
4164
4172
  *
4173
+ * The return type is **schema-aware**: fields matching the table schema are
4174
+ * typed as `Encrypted`, while other fields retain their original types. For
4175
+ * best results, let TypeScript infer the type parameters from the arguments.
4176
+ *
4165
4177
  * @param input - An array of model objects with plaintext values to encrypt.
4166
4178
  * @param table - The table schema defining which fields to encrypt.
4167
- * @returns A `BulkEncryptModelsOperation<T>` that can be awaited to get a `Result`
4168
- * containing an array of models with encrypted fields, or an `EncryptionError`.
4179
+ * @returns A `BulkEncryptModelsOperation` that can be awaited to get a `Result`
4180
+ * containing an array of models with schema-defined fields typed as `Encrypted`,
4181
+ * or an `EncryptionError`.
4169
4182
  *
4170
4183
  * @example
4171
4184
  * ```typescript
@@ -4180,7 +4193,9 @@ var EncryptionClient = class {
4180
4193
  *
4181
4194
  * const client = await Encryption({ schemas: [usersSchema] })
4182
4195
  *
4183
- * const result = await client.bulkEncryptModels<User>(
4196
+ * // Let TypeScript infer the return type from the schema.
4197
+ * // Each item's email is typed as `Encrypted`, id stays `string`.
4198
+ * const result = await client.bulkEncryptModels(
4184
4199
  * [
4185
4200
  * { id: "1", email: "alice@example.com" },
4186
4201
  * { id: "2", email: "bob@example.com" },