Skip to content

Commit 314fc4b

Browse files
committed
fix(verify): harden sdk verification flow
Add a public Effect live layer and update docs/examples to use it. Make the consumer live test hermetic, run live helpers against dist, tighten operation error matching, and move unit test coverage scripts to the warning-free Vitest path.
1 parent 07c7bb4 commit 314fc4b

15 files changed

Lines changed: 325 additions & 98 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
- `vp install`
2020
- `vp check .`
2121
- `vp pack`
22-
- `vp test run --passWithNoTests`
23-
- `vp test run --coverage --passWithNoTests`
22+
- `vp run test`
23+
- `vp run coverage`
2424
- `vp run test:live`
2525
- `vp run verify`
2626
- `vp run bootstrap:tokens`

README.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const duration = secondsToReadableDuration(444);
7171

7272
```ts
7373
import { Effect } from "effect";
74-
import { createPutioSdkEffectClient, makePutioSdkLayer } from "@putdotio/sdk";
74+
import { createPutioSdkEffectClient, makePutioSdkLiveLayer } from "@putdotio/sdk";
7575

7676
const sdk = createPutioSdkEffectClient();
7777

@@ -80,17 +80,14 @@ const program = sdk.files
8080
per_page: 20,
8181
total: 1,
8282
})
83-
.pipe(
84-
Effect.provide(
85-
makePutioSdkLayer({
86-
accessToken: process.env.PUTIO_TOKEN!,
87-
}),
88-
),
89-
);
83+
.pipe(Effect.provide(makePutioSdkLiveLayer({ accessToken: process.env.PUTIO_TOKEN! })));
9084

9185
const result = await Effect.runPromise(program);
9286
```
9387

88+
`makePutioSdkLiveLayer(...)` provides both the SDK config and the default fetch-backed `HttpClient`.
89+
Use `makePutioSdkLayer(...)` only when you want to supply your own `HttpClient` service.
90+
9491
## Side-By-Side Usage
9592

9693
Both client styles expose the same domain surface:
@@ -161,6 +158,7 @@ The package is designed around standard Web APIs. Host runtimes should provide:
161158
- `URL` and `URLSearchParams`
162159
- `AbortController`
163160
- `FormData`
161+
- `btoa` for username/password auth flows such as `auth.login(...)`
164162

165163
For upload flows, the host should also provide file-compatible inputs such as `File` or `Blob`.
166164

@@ -203,7 +201,7 @@ Effect consumers keep errors in the typed error channel instead of throwing:
203201

204202
```ts
205203
import { Effect } from "effect";
206-
import { createPutioSdkEffectClient, makePutioSdkLayer } from "@putdotio/sdk";
204+
import { createPutioSdkEffectClient, makePutioSdkLiveLayer } from "@putdotio/sdk";
207205

208206
const sdk = createPutioSdkEffectClient();
209207

@@ -220,11 +218,7 @@ const handled = sdk.files
220218

221219
return Effect.fail(error);
222220
}),
223-
Effect.provide(
224-
makePutioSdkLayer({
225-
accessToken: process.env.PUTIO_TOKEN!,
226-
}),
227-
),
221+
Effect.provide(makePutioSdkLiveLayer({ accessToken: process.env.PUTIO_TOKEN! })),
228222
);
229223
```
230224

@@ -269,10 +263,10 @@ The Effect client also works well when you want the canonical typed API:
269263
```ts
270264
import { useQuery } from "@tanstack/react-query";
271265
import { Effect } from "effect";
272-
import { createPutioSdkEffectClient, makePutioSdkLayer } from "@putdotio/sdk";
266+
import { createPutioSdkEffectClient, makePutioSdkLiveLayer } from "@putdotio/sdk";
273267

274268
const sdk = createPutioSdkEffectClient();
275-
const sdkLayer = makePutioSdkLayer({
269+
const sdkLayer = makePutioSdkLiveLayer({
276270
accessToken: token,
277271
});
278272

docs/TESTING.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The live verification layer lives in:
2222
- `test/live/domains/*.ts`
2323
- `test/live/support/*`
2424

25+
Live tests execute the built SDK from `dist/**`, so direct live targets should always run after `vp pack`.
26+
2527
## Local Checks
2628

2729
Default test runs intentionally exclude `test/live/**`.
@@ -32,8 +34,8 @@ Run:
3234
vp install
3335
vp check .
3436
vp pack
35-
vp test run --passWithNoTests
36-
vp test run --coverage --passWithNoTests
37+
vp run test
38+
vp run coverage
3739
```
3840

3941
The local suite focuses on the shared runtime in `src/core`.
@@ -61,31 +63,37 @@ Example env file:
6163

6264
- `.env.example`
6365

64-
Expected variables:
66+
Bootstrap-first variables:
6567

66-
- `PUTIO_TOKEN_FIRST_PARTY`
67-
- `PUTIO_TOKEN_THIRD_PARTY`
68-
- `PUTIO_CLIENT_ID`
68+
- `PUTIO_TEST_USERNAME`
69+
- `PUTIO_TEST_PASSWORD`
6970
- `PUTIO_CLIENT_ID_FIRST_PARTY`
7071
- `PUTIO_CLIENT_SECRET_FIRST_PARTY`
7172

7273
Optional credential-fixture variables:
7374

74-
- `PUTIO_TEST_USERNAME`
75-
- `PUTIO_TEST_PASSWORD`
7675
- `PUTIO_TEST_TOTP_REFERENCE`
7776
- `PUTIO_TEST_TOTP`
7877
- `PUTIO_TEST_SECONDARY_USERNAME`
7978
- `PUTIO_TEST_SECONDARY_PASSWORD`
8079
- `PUTIO_TEST_SECONDARY_TOTP_REFERENCE`
8180
- `PUTIO_TEST_SECONDARY_TOTP`
81+
- `PUTIO_CLIENT_ID_THIRD_PARTY`
8282
- `PUTIO_1PASSWORD_RUNTIME_ITEM_ID`
8383

84-
If the explicit token vars are missing, the live harness can still hydrate them from:
84+
Optional direct runtime variables:
85+
86+
- `PUTIO_TOKEN_FIRST_PARTY`
87+
- `PUTIO_TOKEN_THIRD_PARTY`
88+
- `PUTIO_CLIENT_ID`
89+
90+
If direct token vars are missing, the live harness can still hydrate them from:
8591

8692
1. legacy local aliases
8793
2. a runtime-token 1Password item when `OP_SERVICE_ACCOUNT_TOKEN` and `PUTIO_1PASSWORD_RUNTIME_ITEM_ID` are set
8894

95+
See `.env.example` for the current bootstrap-oriented layout and supported optional aliases.
96+
8997
Never print token values in command output, docs, comments, or commits.
9098

9199
## Live Commands
@@ -113,8 +121,8 @@ Run a credentialed live target with 1Password:
113121

114122
```bash
115123
export OP_SERVICE_ACCOUNT_TOKEN="$OP_SERVICE_ACCOUNT_PUTIO_FRONTEND_CI"
116-
op run --env-file=.env.example -- \
117-
vp pack && vp test run --config vitest.live.config.ts test/live/auth-credentials.test.ts
124+
op run --env-file=.env.example -- sh -lc \
125+
'vp pack && vp test run --config vitest.live.config.ts test/live/auth-credentials.test.ts'
118126
```
119127

120128
## Consumer Verification

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@
3636
"build": "vp pack",
3737
"check": "vp check .",
3838
"clean": "rm -rf .live-build .turbo coverage dist",
39-
"coverage": "vp test run --coverage --passWithNoTests",
39+
"coverage": "vitest run --coverage --passWithNoTests",
4040
"dev": "vp pack --watch",
4141
"prepack": "vp pack",
42-
"test": "vp test run --passWithNoTests",
42+
"test": "vitest run --passWithNoTests",
4343
"test:live": "vp pack && vp test run --config vitest.live.config.ts",
44-
"verify": "vp check . && vp pack && vp test run --passWithNoTests && vp test run --coverage --passWithNoTests"
44+
"verify": "vp check . && vp pack && vitest run --passWithNoTests && vitest run --coverage --passWithNoTests"
4545
},
4646
"dependencies": {
4747
"@effect/platform": "0.94.5",
4848
"effect": "3.19.19"
4949
},
5050
"devDependencies": {
5151
"@types/node": "^24.0.0",
52-
"@vitest/coverage-v8": "^4.1.0",
52+
"@vitest/coverage-v8": "4.1.0",
5353
"typescript": "^5.9.3",
5454
"vite-plus": "^0.1.11",
55-
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
55+
"vitest": "4.1.0"
5656
},
5757
"engines": {
5858
"node": ">=24.14.0 <25"

0 commit comments

Comments
 (0)