Skip to content

Commit

Permalink
Use Redacted values with libSQL (#4112)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim <hello@timsmart.co>
  • Loading branch information
thewilkybarkid and tim-smart authored Dec 18, 2024
1 parent 1b72560 commit 28de34a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
31 changes: 31 additions & 0 deletions .changeset/spicy-starfishes-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
"@effect/sql-libsql": minor
---

libSQL now requires redacted values instead of strings for:

- `authToken`
- `encryptionKey`

Before

```ts
import { LibsqlClient } from "@effect/sql-libsql"

LibsqlClient.layerConfig({
url: Config.string("LIBSQL_URL"),
authToken: Config.string("LIBSQL_AUTH_TOKEN")
})
```

After

```ts
import { LibsqlClient } from "@effect/sql-libsql"
import { Config } from "effect"

LibsqlClient.layerConfig({
url: Config.string("LIBSQL_URL"),
authToken: Config.redacted("LIBSQL_AUTH_TOKEN")
})
```
17 changes: 14 additions & 3 deletions packages/sql-libsql/src/LibsqlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
import * as Layer from "effect/Layer"
import * as Option from "effect/Option"
import * as Redacted from "effect/Redacted"
import * as Scope from "effect/Scope"

/**
Expand Down Expand Up @@ -82,9 +83,9 @@ export declare namespace LibsqlClientConfig {
*/
readonly url: string | URL
/** Authentication token for the database. */
readonly authToken?: string | undefined
readonly authToken?: Redacted.Redacted | undefined
/** Encryption key for the database. */
readonly encryptionKey?: string | undefined
readonly encryptionKey?: Redacted.Redacted | undefined
/** URL of a remote server to synchronize database with. */
readonly syncUrl?: string | URL | undefined
/** Sync interval in seconds. */
Expand Down Expand Up @@ -227,7 +228,17 @@ export const make = (
Effect.acquireRelease(
Effect.sync(() =>
Libsql.createClient(
{ ...options, url: options.url.toString(), syncUrl: options.syncUrl?.toString() } as Libsql.Config
{
...options,
authToken: Redacted.isRedacted(options.authToken)
? Redacted.value(options.authToken)
: options.authToken,
encryptionKey: Redacted.isRedacted(options.encryptionKey)
? Redacted.value(options.encryptionKey)
: options.encryptionKey,
url: options.url.toString(),
syncUrl: options.syncUrl?.toString()
} as Libsql.Config
)
),
(sdk) => Effect.sync(() => sdk.close())
Expand Down

0 comments on commit 28de34a

Please sign in to comment.