Skip to content

Commit 774b89f

Browse files
committed
Adopt trusted npm publishing and expand README examples
1 parent d9f3b78 commit 774b89f

4 files changed

Lines changed: 47 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Set up Node.js
2525
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
2626
with:
27-
node-version: 20
27+
node-version: 24
2828
cache: npm
2929
registry-url: https://registry.npmjs.org
3030

@@ -41,7 +41,7 @@ jobs:
4141
run: npm pack
4242

4343
- name: Verify npm publish dry-run
44-
run: npm publish --dry-run --access public
44+
run: npm publish --dry-run
4545

4646
publish:
4747
if: github.event_name == 'push'
@@ -56,7 +56,7 @@ jobs:
5656
- name: Set up Node.js
5757
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
5858
with:
59-
node-version: 20
59+
node-version: 24
6060
cache: npm
6161
registry-url: https://registry.npmjs.org
6262

@@ -70,6 +70,4 @@ jobs:
7070
npm run build
7171
7272
- name: Publish to npm with provenance
73-
run: npm publish --provenance --access public
74-
env:
75-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73+
run: npm publish

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ const api = createClient({
3434
const user = await api.get<{ id: string; name: string }>('/users/123')
3535
```
3636

37+
### JSON request bodies
38+
39+
```ts
40+
import { createClient } from '@gavoryn/clearfetch'
41+
42+
const api = createClient({
43+
baseURL: 'https://api.example.com',
44+
})
45+
46+
const created = await api.post<{ id: string }>('/users', {
47+
json: {
48+
name: 'Ada Lovelace',
49+
role: 'admin',
50+
},
51+
})
52+
```
53+
54+
If `json` is provided, clearfetch:
55+
56+
- serializes the value with `JSON.stringify()`
57+
- sets `Content-Type: application/json` if it is not already present
58+
- rejects the request with `ConfigError` if `body` is also provided
59+
60+
Use `body` directly only when you want to send a raw payload such as `FormData`, `URLSearchParams`, or pre-serialized text.
61+
3762
### Extended client defaults
3863

3964
```ts
@@ -124,6 +149,8 @@ try {
124149
- `beforeRequest` may mutate headers, but hook option metadata is read-only.
125150
- Retry support is opt-in and conservative by default.
126151
- Retry support does not allow streaming request bodies.
152+
- The `json` helper serializes request bodies and sets `Content-Type: application/json` when absent.
153+
- `body` and `json` cannot be used together.
127154
- The package performs no telemetry or hidden network activity beyond the caller's request.
128155

129156
## Supported runtimes
@@ -148,6 +175,7 @@ The package is ESM-only and does not target legacy runtimes or polyfill-driven e
148175
- CI also runs a lightweight browser-like test path using `happy-dom` on Node.js `20`.
149176
- Dependency review is configured for pull requests and manual validation, but requires the relevant GitHub security features to be enabled on the repository.
150177
- The release workflow supports a non-publishing dry-run path via manual dispatch.
178+
- npm publishing now uses npm trusted publishing from GitHub Actions instead of a long-lived publish token.
151179
- Normal releases are expected to publish from GitHub Actions, not from local machines.
152180
- Release and repository protection policy is documented in [RELEASE.md](./RELEASE.md).
153181

@@ -170,4 +198,4 @@ The public package surface is intentionally narrow:
170198

171199
## Status
172200

173-
`clearfetch` is ready for its initial `1.0.0` release as `@gavoryn/clearfetch`. Project goals and behavior are documented in `PURPOSE.md` and `DESIGN.md`.
201+
`clearfetch` is published as `@gavoryn/clearfetch`. Project goals and behavior are documented in `PURPOSE.md` and `DESIGN.md`.

RELEASE.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,29 @@ Release tags should be annotated and should be signed when practical.
4545

4646
If signed tags are not yet mandatory for every maintainer environment, they should still be treated as the target policy for official releases.
4747

48-
## npm account and token requirements
48+
## npm account and trusted publishing requirements
4949

5050
The npm account used to administer the package should require 2FA.
5151

52-
Publishing from CI should use an npm automation token stored as the `NPM_TOKEN` GitHub Actions secret for the `npm` environment. That token should have the minimum scope necessary for publishing this package.
52+
Publishing from CI should use npm trusted publishing through GitHub Actions OIDC, not a long-lived write token.
53+
54+
The npm package settings for `@gavoryn/clearfetch` should define a trusted publisher with:
55+
56+
- organization or user: `bmurdock`
57+
- repository: `clearfetch`
58+
- workflow filename: `release.yml`
59+
- environment name: `npm`
5360

5461
## GitHub Actions configuration
5562

5663
The release workflow assumes:
5764

5865
- GitHub Actions is enabled for the repository
5966
- an environment named `npm` exists
60-
- the `npm` environment contains an `NPM_TOKEN` secret
67+
- the npm package has a matching trusted publisher configured on npmjs.com
6168
- maintainers review changes to workflow files with the same care as runtime code
6269

63-
The release workflow uses `id-token: write` so npm provenance can be attached during publish.
70+
The release workflow uses `id-token: write` so npm can exchange the workflow identity for publish access. When trusted publishing is configured, npm also generates provenance automatically for public packages from public repositories.
6471

6572
## Runtime and security expectations
6673

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
},
4141
"homepage": "https://github.com/bmurdock/clearfetch#readme",
4242
"license": "MIT",
43+
"publishConfig": {
44+
"access": "public"
45+
},
4346
"devDependencies": {
4447
"@types/node": "^24.5.2",
4548
"happy-dom": "^20.8.9",

0 commit comments

Comments
 (0)