@reduck-ai/sdk 1.1.21 → 2.0.1

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 (57) hide show
  1. package/README.md +102 -204
  2. package/dist/client.d.ts +11 -20
  3. package/dist/client.js +19 -107
  4. package/dist/generated/client/client.gen.d.ts +2 -0
  5. package/dist/generated/client/client.gen.js +216 -0
  6. package/dist/generated/client/index.d.ts +10 -0
  7. package/dist/generated/client/index.js +6 -0
  8. package/dist/generated/client/types.gen.d.ts +120 -0
  9. package/dist/generated/client/types.gen.js +2 -0
  10. package/dist/generated/client/utils.gen.d.ts +37 -0
  11. package/dist/generated/client/utils.gen.js +228 -0
  12. package/dist/generated/client.gen.d.ts +12 -0
  13. package/dist/generated/client.gen.js +3 -0
  14. package/dist/generated/core/auth.gen.d.ts +25 -0
  15. package/dist/generated/core/auth.gen.js +14 -0
  16. package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
  17. package/dist/generated/core/bodySerializer.gen.js +57 -0
  18. package/dist/generated/core/params.gen.d.ts +43 -0
  19. package/dist/generated/core/params.gen.js +109 -0
  20. package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
  21. package/dist/generated/core/pathSerializer.gen.js +106 -0
  22. package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
  23. package/dist/generated/core/queryKeySerializer.gen.js +92 -0
  24. package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
  25. package/dist/generated/core/serverSentEvents.gen.js +132 -0
  26. package/dist/generated/core/types.gen.d.ts +83 -0
  27. package/dist/generated/core/types.gen.js +2 -0
  28. package/dist/generated/core/utils.gen.d.ts +19 -0
  29. package/dist/generated/core/utils.gen.js +87 -0
  30. package/dist/generated/index.d.ts +2 -0
  31. package/dist/generated/index.js +3 -0
  32. package/dist/generated/sdk.gen.d.ts +471 -0
  33. package/dist/generated/sdk.gen.js +862 -0
  34. package/dist/generated/types.gen.d.ts +5489 -0
  35. package/dist/generated/types.gen.js +56 -0
  36. package/dist/index.d.ts +3 -5
  37. package/dist/index.js +4 -4
  38. package/openapi.json +16668 -0
  39. package/package.json +23 -25
  40. package/dist/build-env.generated.d.ts +0 -3
  41. package/dist/build-env.generated.js +0 -4
  42. package/dist/device.d.ts +0 -3
  43. package/dist/device.js +0 -7
  44. package/dist/errors.d.ts +0 -9
  45. package/dist/errors.js +0 -21
  46. package/dist/method.d.ts +0 -3
  47. package/dist/method.js +0 -23
  48. package/dist/run.d.ts +0 -12
  49. package/dist/run.js +0 -73
  50. package/dist/schemas.d.ts +0 -597
  51. package/dist/schemas.js +0 -106
  52. package/dist/session.d.ts +0 -3
  53. package/dist/session.js +0 -14
  54. package/dist/site.d.ts +0 -3
  55. package/dist/site.js +0 -21
  56. package/dist/types.d.ts +0 -43
  57. package/dist/types.js +0 -8
package/README.md CHANGED
@@ -4,7 +4,11 @@
4
4
 
5
5
  # @reduck-ai/sdk
6
6
 
7
- TypeScript SDK for [Reduck](https://reduck.ai) — run browser automations programmatically.
7
+ [![npm](https://img.shields.io/npm/v/@reduck-ai/sdk.svg?style=flat-square)](https://www.npmjs.com/package/@reduck-ai/sdk)
8
+
9
+ TypeScript SDK for [Reduck](https://reduck.ai). Use it to manage your browser
10
+ scripts, devices and runs from your code. Each function and type is generated
11
+ from the [OpenAPI specification](https://reduck.ai/api/openapi.json) of reduck.ai.
8
12
 
9
13
  ## Installation
10
14
 
@@ -15,228 +19,122 @@ npm install @reduck-ai/sdk
15
19
  ## Quick Start
16
20
 
17
21
  ```typescript
18
- import { ReduckClient } from "@reduck-ai/sdk"
19
-
20
- const client = new ReduckClient({ apiKey: "your-api-key" })
21
-
22
- const devices = await client.listDevices()
23
- const run = client.run("Go to google.com and search for 'reduck ai'", {
24
- deviceId: devices[0].id,
25
- })
26
-
27
- for await (const event of run) {
28
- if (event.type === "run_requested") console.log("started:", event.run_id)
29
- if (event.type === "progress") console.log(event.text)
30
- if (event.type === "done") {
31
- console.log(event.success ? "Done" : "Failed", event.output)
32
- if (event.extractions) console.log("records:", event.extractions)
33
- }
34
- }
35
-
36
- // Site discovery
37
- const sites = await client.searchSites("messaging")
38
- const site = await client.getSite("linkedin.com")
39
- ```
40
-
41
- ## Authentication
42
-
43
- ```typescript
44
- // API key (recommended for server-side)
45
- const client = new ReduckClient({ apiKey: "<your-api-key>" })
46
-
47
- // OAuth token (for user-facing apps)
48
- const client = new ReduckClient({ oauthToken: "<your-oauth-token>" })
49
- ```
50
-
51
- Generate an API key from your [Reduck dashboard](https://reduck.ai).
52
-
53
- ## API
54
-
55
- ### `new ReduckClient(options)`
56
-
57
- | Option | Type | Description |
58
- |---|---|---|
59
- | `apiKey` | `string` | API key authentication |
60
- | `oauthToken` | `string` | OAuth bearer token authentication |
61
- | `runnerBaseUrl` | `string` | Override runner base URL (default: hosted) |
62
- | `appBaseUrl` | `string` | Override app base URL (default: hosted) |
63
- | `headers` | `Record<string, string>` | Extra headers to send on every request |
64
-
65
- One of `apiKey` or `oauthToken` is required.
66
-
67
- ### `client.run(query, options)`
68
-
69
- Starts an automation and returns a `Run` — an `AsyncIterable<RunEvent>` that streams events in real-time via WebSocket. The first event yielded is `run_requested` (synchronously after the server accepts the run, before WebSocket events flow).
70
-
71
- When invoking a typed method, pass `query: ""` and set `method` + `methodArgs`.
72
-
73
- | Option | Type | Description |
74
- |---|---|---|
75
- | `deviceId` | `string` | Target device ID (required) |
76
- | `method` | `string` | Invoke a typed method `<host>/<slug>` (mutually exclusive with `outputSchema`) |
77
- | `methodArgs` | `Record<string, string>` | Arguments rendered into the method's `prompt_template`. Requires `method` |
78
- | `mount` | `string[]` | Local file paths to upload and make available to `click_upload` |
79
- | `pasteSlots` | `Record<string, string>` | Named slots inserted via `paste(slot=...)` |
80
- | `outputSchema` | `object` | Inline vision extractor JSON schema (mutually exclusive with `method`) |
81
- | `slug` | `string` | Custom extractor slug for inline `outputSchema` (default: `summary`) |
82
-
83
- ### `run.id`
84
-
85
- `Promise<string>` — resolves to the run ID once the server accepts the run.
86
-
87
- ### `run.cancel()`
88
-
89
- Cancels the running automation.
90
-
91
- ### `client.listDevices()`
92
-
93
- Returns `Promise<Device[]>` — all devices for the authenticated user.
94
-
95
- ```typescript
96
- interface Device {
97
- id: string
98
- name: string | null
99
- browser: string | null
100
- os: string | null
101
- reachable: boolean
102
- created_at: string
103
- }
104
- ```
105
-
106
- ### `client.listRuns(page?)`
107
-
108
- Returns `Promise<RunsPage>` — a paginated list of runs.
109
-
110
- ```typescript
111
- interface RunsPage {
112
- data: RunRecord[]
113
- hasNextPage: boolean
114
- }
22
+ import { createReduckClient, createScript, listScripts } from "@reduck-ai/sdk";
23
+
24
+ const client = createReduckClient({ apiKey: process.env.REDUCK_API_KEY! });
25
+
26
+ // Every function takes { client, path?, query?, body? } and returns { data, error }.
27
+ const { data: scripts } = await listScripts({
28
+ client,
29
+ path: { handle: "@username" },
30
+ query: { q: "linkedin" }
31
+ });
32
+
33
+ const { data: script, error } = await createScript({
34
+ client,
35
+ path: { handle: "@username" },
36
+ body: {
37
+ slug: "linkedin-jobs",
38
+ host: "linkedin.com",
39
+ description: "Pull job posts",
40
+ content: "await page.goto('https://linkedin.com/jobs')",
41
+ input_schema: {},
42
+ output_schema: {},
43
+ side_effects: "none"
44
+ }
45
+ });
46
+ if (error) throw new Error(error.error);
115
47
  ```
116
48
 
117
- ### `client.getRun(runId)`
49
+ Inputs and responses are fully typed and autocomplete in your editor.
118
50
 
119
- Returns `Promise<RunRecord>` — a single run by ID.
120
-
121
- ```typescript
122
- interface RunRecord {
123
- id: string
124
- started_at: string
125
- finished_at: string | null
126
- result: {
127
- success?: boolean
128
- cancelled?: boolean
129
- output?: string
130
- error?: { code: string; message: string } | null
131
- final_url?: string
132
- extractions?: SlugExtraction[]
133
- downloads?: DownloadedFile[]
134
- } | null
135
- resolved: {
136
- url?: string
137
- prompt?: string
138
- } | null
139
- }
140
- ```
141
-
142
- ### `client.interrupt(runId)`
143
-
144
- Interrupts a run by ID.
51
+ ## Authentication
145
52
 
146
- ### Site discovery
53
+ `createReduckClient` takes one credential: `apiKey` or `oauthToken`.
147
54
 
148
55
  ```typescript
149
- // Sites whose host matches the query
150
- const sites = await client.searchSites("messaging")
151
-
152
- // Full surface of a host
153
- const site = await client.getSite("linkedin.com")
56
+ const client = createReduckClient({ apiKey: "<your-api-key>" }); // server-side
57
+ const client = createReduckClient({ oauthToken: "<your-oauth-token>" }); // user-facing apps
154
58
  ```
155
59
 
156
- `Site` shape:
60
+ Create an API key at [reduck.ai/api-keys](https://reduck.ai/api-keys).
157
61
 
158
- ```typescript
159
- interface Site {
160
- host: string
161
- notes: string
162
- methods: Method[]
163
- }
62
+ An `oauthToken` must be an access token **issued for this API**: request it with
63
+ `resource=https://reduck.ai` (RFC 8707), and make sure it carries the scopes the
64
+ endpoints you call need: `script:read` / `script:write`, `run:read`,
65
+ `device:read` / `device:write`, `app:read`, `profile`. The API refuses a token
66
+ issued for a different Reduck resource, such as the MCP server: an access token
67
+ is only valid at the resource it names.
164
68
 
165
- interface Method {
166
- method_slug: string
167
- description: string
168
- args: Record<string, unknown> // JSON Schema for method args
169
- output_schema: Record<string, unknown> | null
170
- }
171
- ```
69
+ ## Options
172
70
 
173
- ## Events
71
+ | Option | Default | Description |
72
+ | --------- | ------------------- | ------------------------------------------------- |
73
+ | `baseUrl` | `https://reduck.ai` | The origin of the API. The paths include `/api`. |
74
+ | `headers` | none | More headers to send with each request. |
174
75
 
175
- The `run` async iterable yields these events. Every event carries `run_id` and `device_id` for correlation.
76
+ ## API
176
77
 
177
- | Type | Extra fields | Description |
178
- |---|---|---|
179
- | `run_requested` | `query?`, `args` | Server accepted the run; emitted before WebSocket connection |
180
- | `run_started` | `timestamp` | Agent loop has started |
181
- | `progress` | `text`, `timestamp` | Step-by-step progress update |
182
- | `assistant` | `text`, `timestamp` | Assistant reasoning between tool calls |
183
- | `turn_completed` | `timestamp` | Agent turn (one LLM call) completed |
184
- | `run_completed` | `timestamp` | Agent loop finished |
185
- | `done` | `success`, `output?`, `final_url?`, `extractions?`, `downloads?` | Agent called `done` — final result with collected data |
186
- | `failure` | `error` | Run failed |
187
- | `cancel` | — | Run was cancelled |
78
+ Pass the returned `client` to any function. List endpoints return
79
+ `{ data, has_next_page }` and take `query: { page?, page_size?, … }`; the rest take
80
+ `path` and/or `body`.
81
+
82
+ | Function | Args (besides `client`) |
83
+ | --------------------------- | ------------------------------------------------------------------------- |
84
+ | `getMe` | none |
85
+ | `listDevices` | none |
86
+ | `listRuns` | `query: { page?, page_size? }` |
87
+ | `getRun` | `path: { run_id }` |
88
+ | `listAllScripts` | `query: { host?, q?, visibility?, archived? }` |
89
+ | `listScripts` | `path: { handle }`, `query: { host?, slug?, visibility?, archived?, q? }` |
90
+ | `getScript` | `path: { handle, host, slug }` |
91
+ | `createScript` | `path: { handle }`, `body` |
92
+ | `patchScript` | `path: { handle, host, slug }`, `body: { name?, description? }` |
93
+ | `publishScript` | `path: { handle, host, slug }` |
94
+ | `unpublishScript` | `path: { handle, host, slug }` |
95
+ | `archiveScript` | `path: { handle, host, slug }` |
96
+ | `restoreScript` | `path: { handle, host, slug }` |
97
+ | `listScriptVersions` | `path: { handle, host, slug }`, `query` |
98
+ | `createDraftScriptVersion` | `path: { handle, host, slug }`, `body` |
99
+ | `getScriptVersion` | `path: { handle, host, slug, version_id }` |
100
+ | `listScriptTransferTargets` | `path: { handle, host, slug }` |
101
+ | `transferScript` | `path: { handle, host, slug }`, `body: { target }` |
102
+
103
+ `handle` is `@username` for a personal scope or a project slug. The table shows
104
+ the frequent functions. Your editor shows all of them, or see
105
+ [openapi.json](https://reduck.ai/api/openapi.json).
106
+
107
+ ## Errors
108
+
109
+ Functions do not throw by default: they return `{ data, error }`. On a failed
110
+ request, `data` is undefined and `error` holds the error that the server sent:
111
+
112
+ - `status`: the HTTP status of the response.
113
+ - `code`: identifies the error. Use this value in your code. New values can be
114
+ added: for a value that you do not know, use the status.
115
+ - `error`: describes the error for a person. The text can change: do not use
116
+ it in your code.
117
+ - `variables`: for a request body that is not valid, the errors of each field.
118
+
119
+ After a check of `error.status`, the type of `error.code` has only the codes that
120
+ the function can answer with that status.
188
121
 
189
122
  ```typescript
190
- type RunEventBase = { run_id: string; device_id: string }
191
-
192
- type RunEvent =
193
- | (RunEventBase & { type: "run_requested"; query?: string; args: RunRequestedArgs })
194
- | (RunEventBase & { type: "run_started"; timestamp: number })
195
- | (RunEventBase & { type: "progress"; text: string; timestamp: number })
196
- | (RunEventBase & { type: "assistant"; text: string; timestamp: number })
197
- | (RunEventBase & { type: "turn_completed"; timestamp: number })
198
- | (RunEventBase & { type: "run_completed"; timestamp: number })
199
- | (RunEventBase & {
200
- type: "done"
201
- success: boolean
202
- output?: string
203
- final_url?: string
204
- extractions?: SlugExtraction[]
205
- downloads?: DownloadedFile[]
206
- })
207
- | (RunEventBase & { type: "failure"; error: string })
208
- | (RunEventBase & { type: "cancel" })
209
-
210
- interface SlugExtraction {
211
- host: string
212
- slug: string
213
- records: object[]
214
- output_schema: object
215
- }
216
-
217
- interface DownloadedFile {
218
- filename: string
219
- path?: string // full path on the runner — re-usable as `mount` in a follow-up run
220
- mimetype?: string
221
- url?: string | null
123
+ const { data, error } = await getScript({
124
+ client,
125
+ path: { handle, host, slug }
126
+ });
127
+ if (error) {
128
+ if (error.code === "not_found") return null;
129
+ console.error(error.error); // or per-field error.variables
130
+ return;
222
131
  }
223
132
  ```
224
133
 
225
- `final_url`, `extractions`, and `downloads` on the `done` event are present only when the run produced them. `downloads[].path` can be reused as `mount` in a follow-up `client.run(...)` to chain workflows.
226
-
227
- ## Schemas as JSON Schema
228
-
229
- All public shapes are also exposed as Zod schemas via the `schemas` namespace:
230
-
231
- ```typescript
232
- import { schemas } from "@reduck-ai/sdk"
233
-
234
- schemas.RunEventSchema.parse(json) // validate at runtime
235
- schemas.RunResultSchema // the final `done` event shape
236
- schemas.SiteSchema, schemas.MethodSchema, schemas.DeviceSchema, ...
237
- ```
134
+ ## Versions
238
135
 
239
- The `reduck schema <name>` CLI command emits these as JSON Schema (draft-7) for non-TS consumers.
136
+ The package follows [semantic versioning](https://semver.org). A change to the
137
+ API that can break your code gives a major version.
240
138
 
241
139
  ## License
242
140
 
package/dist/client.d.ts CHANGED
@@ -1,20 +1,11 @@
1
- import { type Device, type ListMethodsOptions, type ListSitesOptions, type Method, type MethodsPage, type ReduckClientOptions, type RunOptions, type RunRecord, type RunsPage, type Site, type SitesPage } from "./types.js";
2
- import { Run } from "./run.js";
3
- export declare class ReduckClient {
4
- private readonly _runnerBaseUrl;
5
- private readonly _appBaseUrl;
6
- private readonly _headers;
7
- constructor(opts: ReduckClientOptions);
8
- run(query: string, { mount, deviceId, method, methodArgs, pasteSlots, outputSchema, slug }: RunOptions): Run;
9
- listDevices(): Promise<Device[]>;
10
- listRuns(page?: number): Promise<RunsPage>;
11
- getRun(runId: string): Promise<RunRecord>;
12
- listSites(options?: ListSitesOptions): Promise<SitesPage>;
13
- getSite(host: string): Promise<Site>;
14
- listMethods(options?: ListMethodsOptions): Promise<MethodsPage>;
15
- getMethod(host: string, slug: string): Promise<Method>;
16
- interrupt(runId: string): Promise<void>;
17
- private _createRun;
18
- private _mount;
19
- private _pasteFiles;
20
- }
1
+ export declare const DEFAULT_BASE_URL = "https://reduck.ai";
2
+ export type ReduckCredentials = {
3
+ oauthToken: string;
4
+ } | {
5
+ apiKey: string;
6
+ };
7
+ export declare function credentialHeaders(cred: ReduckCredentials | {}): Record<string, string>;
8
+ export declare function createReduckClient(opts?: (ReduckCredentials | {}) & {
9
+ baseUrl?: string;
10
+ headers?: Record<string, string>;
11
+ }): import("./generated/client/types.gen.js").Client;
package/dist/client.js CHANGED
@@ -1,108 +1,20 @@
1
- import { cp, mkdir } from "node:fs/promises";
2
- import { basename, join } from "node:path";
3
- import { homedir } from "node:os";
4
- import { ReduckError } from "./errors.js";
5
- import { authHeader } from "./types.js";
6
- import { Run } from "./run.js";
7
- import { fetchDevices } from "./device.js";
8
- import { fetchRun, fetchRuns } from "./session.js";
9
- import { fetchSite, fetchSites } from "./site.js";
10
- import { fetchMethod, fetchMethods } from "./method.js";
11
- import { RUNNER_URL, APP_URL } from "./build-env.generated.js";
12
- export class ReduckClient {
13
- _runnerBaseUrl;
14
- _appBaseUrl;
15
- _headers;
16
- constructor(opts) {
17
- this._runnerBaseUrl = (opts.runnerBaseUrl ?? RUNNER_URL).replace(/\/$/, "");
18
- this._appBaseUrl = (opts.appBaseUrl ?? APP_URL).replace(/\/$/, "");
19
- this._headers = { ...opts.headers, ...authHeader(opts) };
20
- }
21
- run(query, { mount, deviceId, method, methodArgs, pasteSlots, outputSchema, slug }) {
22
- if (!deviceId)
23
- throw new ReduckError("deviceId is required to start a run", { code: "MISSING_DEVICE" });
24
- const requestedPromise = this._createRun(deviceId, query, mount, method, methodArgs, pasteSlots, outputSchema, slug);
25
- const wsBase = this._runnerBaseUrl
26
- .replace("https://", "wss://")
27
- .replace("http://", "ws://");
28
- return new Run(requestedPromise, wsBase, this._headers);
29
- }
30
- async listDevices() {
31
- return fetchDevices(this._appBaseUrl, this._headers);
32
- }
33
- async listRuns(page = 0) {
34
- return fetchRuns(this._appBaseUrl, this._headers, page);
35
- }
36
- async getRun(runId) {
37
- return fetchRun(this._appBaseUrl, this._headers, runId);
38
- }
39
- async listSites(options = {}) {
40
- return fetchSites(this._appBaseUrl, this._headers, options);
41
- }
42
- async getSite(host) {
43
- return fetchSite(this._appBaseUrl, this._headers, host);
44
- }
45
- async listMethods(options = {}) {
46
- return fetchMethods(this._appBaseUrl, this._headers, options);
47
- }
48
- async getMethod(host, slug) {
49
- return fetchMethod(this._appBaseUrl, this._headers, host, slug);
50
- }
51
- async interrupt(runId) {
52
- await fetch(`${this._runnerBaseUrl}/run/${runId}/cancel`, {
53
- method: "POST",
54
- headers: this._headers,
55
- });
56
- }
57
- async _createRun(deviceId, query, mount, method, methodArgs, pasteSlots, outputSchema, slug) {
58
- const mountedPaths = mount?.length ? await this._mount(mount) : undefined;
59
- const stagedPaste = pasteSlots ? await this._pasteFiles(pasteSlots) : undefined;
60
- const res = await fetch(`${this._runnerBaseUrl}/query`, {
61
- method: "POST",
62
- headers: {
63
- "Content-Type": "application/json",
64
- ...this._headers,
65
- },
66
- body: JSON.stringify({
67
- query,
68
- device_id: deviceId,
69
- ...(mountedPaths?.length ? { mount: mountedPaths } : {}),
70
- ...(method ? { method } : {}),
71
- ...(methodArgs && Object.keys(methodArgs).length ? { method_args: methodArgs } : {}),
72
- ...(stagedPaste && Object.keys(stagedPaste).length ? { paste_slots: stagedPaste } : {}),
73
- ...(outputSchema ? { output_schema: outputSchema, slug: slug ?? "summary" } : {}),
74
- }),
75
- });
76
- if (!res.ok) {
77
- const detail = await res.json().then((d) => d?.error).catch(() => undefined);
78
- throw ReduckError.fromResponse("POST /query", res.status, detail);
79
- }
80
- return (await res.json());
81
- }
82
- async _mount(paths) {
83
- const destDir = join(homedir(), "Downloads", ".reduck");
84
- await mkdir(destDir, { recursive: true });
85
- return Promise.all(paths.map(async (p) => {
86
- const dest = join(destDir, basename(p));
87
- await cp(p, dest);
88
- return dest;
89
- }));
90
- }
91
- async _pasteFiles(slots) {
92
- const destDir = join(homedir(), "Downloads", ".reduck", "paste");
93
- await mkdir(destDir, { recursive: true });
94
- const result = {};
95
- await Promise.all(Object.entries(slots).map(async ([key, val]) => {
96
- if (val.startsWith("@")) {
97
- const src = val.slice(1);
98
- const dest = join(destDir, basename(src));
99
- await cp(src, dest);
100
- result[key] = dest;
101
- }
102
- else {
103
- result[key] = val;
104
- }
105
- }));
106
- return result;
107
- }
1
+ import { createClient, createConfig } from "./generated/client/index.js";
2
+ export const DEFAULT_BASE_URL = "https://reduck.ai";
3
+ // The single place a credential becomes headers, so a caller reaching an endpoint the generated
4
+ // client does not cover still authenticates identically.
5
+ export function credentialHeaders(cred) {
6
+ if ("oauthToken" in cred)
7
+ return { Authorization: `Bearer ${cred.oauthToken.trim()}` };
8
+ if ("apiKey" in cred)
9
+ return { "X-API-Key": cred.apiKey.trim() };
10
+ return {};
11
+ }
12
+ // Returns a client preconfigured with the API base URL and the auth header. Pass it to any
13
+ // generated function: getScript({ client, path: { handle, host, slug } }).
14
+ // Omit credentials for unauthenticated access to public routes.
15
+ export function createReduckClient(opts = {}) {
16
+ return createClient(createConfig({
17
+ baseUrl: (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, ""),
18
+ headers: { ...credentialHeaders(opts), ...opts.headers }
19
+ }));
108
20
  }
@@ -0,0 +1,2 @@
1
+ import type { Client, Config } from './types.gen.js';
2
+ export declare const createClient: (config?: Config) => Client;