@daymaker/sdk 0.0.0-stage → 0.4.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.
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2026 Daymaker. All rights reserved.
2
+
3
+ Daymaker grants you a limited, non-exclusive, non-transferable, revocable
4
+ license to install, run and copy this software — including the npm packages
5
+ `@daymaker/sdk` and `@daymaker/mcp` — only to access Daymaker's services,
6
+ subject to the Daymaker Terms of Service at https://daymaker.com/terms.
7
+
8
+ You may include unmodified copies of the npm packages `@daymaker/sdk` and
9
+ `@daymaker/mcp` as dependencies of your own applications and services that
10
+ access Daymaker's services, and distribute them as part of those
11
+ applications.
12
+
13
+ You may not:
14
+
15
+ - redistribute this software on its own, or modified copies of it,
16
+ - sublicense, sell, rent or lease it,
17
+ - use it, or any output of it, to build or operate a service that
18
+ competes with Daymaker's services.
19
+
20
+ You may make the changes needed to run this software in your own
21
+ environment; those changes are covered by the same license and may not be
22
+ redistributed.
23
+
24
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27
+ DAYMAKER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @daymaker/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed TypeScript client for the [Daymaker API](https://daymaker.com/api/v2/docs): leads and research, gift ideas and picks, campaigns, sending, orders, the pipeline and signals.
4
+
5
+ ```bash
6
+ npm install @daymaker/sdk
7
+ export DAYMAKER_KEY=dmk_live_... # made in Daymaker under Settings, API and MCP
8
+ ```
9
+
10
+ ```ts
11
+ import { DaymakerClient } from "@daymaker/sdk";
12
+
13
+ const dm = new DaymakerClient(); // reads DAYMAKER_KEY
14
+
15
+ const me = await dm.getMe();
16
+ const { leads } = await dm.listLeads({ tab: "gift_ready", limit: 10 });
17
+ ```
18
+
19
+ A key acts as the person who made it: their role, their team, their credits and their limits, exactly as in the Daymaker app. Keep it on a server.
20
+
21
+ - One method per API operation (`dm.listLeads`, `dm.researchLead`, `dm.sendGiftLinks`, ...), with typed inputs and answers generated from the published contract.
22
+ - `dm.pages(...)` reads a list to the end.
23
+ - An `Idempotency-Key` on every write that takes one, reused across retries, so a retry never acts twice.
24
+ - Retries with backoff only where they are safe, and typed `DaymakerError`s that carry the API's `code`.
25
+
26
+ Needs Node 22 or newer. The package is an ES module.
27
+
28
+ - API reference: <https://daymaker.com/api/v2/docs>
29
+ - Contract: `GET https://daymaker.com/api/v2/openapi.json`
30
+ - Source, examples and full docs: <https://github.com/daymaker-hq/daymaker-for-agents>
31
+ - Issues: <https://github.com/daymaker-hq/daymaker-for-agents/issues>
32
+ - Terms: <https://daymaker.com/terms>. Privacy: <https://daymaker.com/privacy>.
33
+
34
+ License: proprietary and source-visible. See `LICENSE` in this package.
@@ -0,0 +1,75 @@
1
+ import { parseRetryAfter } from "./errors.js";
2
+ import { type OperationId } from "./generated/operations.js";
3
+ import type { DaymakerOperations, DaymakerResponse, OperationInput, OperationOutput, PagedOperationId, RequestOptions } from "./types.js";
4
+ export declare const DEFAULT_API_URL = "https://daymaker.com/api/v2";
5
+ export interface DaymakerClientOptions {
6
+ /** A `dmk_live_...` key, made in Daymaker under Settings, API and MCP. Defaults to `process.env.DAYMAKER_KEY`. */
7
+ apiKey?: string;
8
+ /** Base URL of the API. Defaults to `DAYMAKER_API_URL`, then https://daymaker.com/api/v2. An origin alone gets `/api/v2` added. */
9
+ baseUrl?: string;
10
+ /** Retries after a timeout, a network error, a 5xx or a short 429. Default 2. */
11
+ maxRetries?: number;
12
+ /** Per-attempt timeout. Default 120 s: a send to many people takes a while. */
13
+ timeoutMs?: number;
14
+ /** Longest `Retry-After` the client waits out before it gives the error to you. Default 30 s. */
15
+ maxRetryDelayMs?: number;
16
+ fetch?: typeof fetch;
17
+ userAgent?: string;
18
+ idempotencyKeyFactory?: () => string;
19
+ /** Test hook. */
20
+ sleep?: (ms: number) => Promise<void>;
21
+ }
22
+ export interface ResolvedUrls {
23
+ origin: string;
24
+ /** The API base, `<origin>/api/v2`. */
25
+ api: string;
26
+ openapi: string;
27
+ docs: string;
28
+ /** The hosted MCP server, `<origin>/mcp`. It takes a sign-in, not an API key. */
29
+ mcp: string;
30
+ }
31
+ /** Accepts an origin or `<origin>/api/v2`, and derives the rest. */
32
+ export declare function resolveUrls(base?: string): ResolvedUrls;
33
+ export interface DaymakerClient extends DaymakerOperations {
34
+ }
35
+ /**
36
+ * Typed client for the Daymaker API.
37
+ *
38
+ * ```ts
39
+ * const dm = new DaymakerClient({ apiKey: process.env.DAYMAKER_KEY });
40
+ * const me = await dm.getMe();
41
+ * const { leads } = await dm.listLeads({ tab: "gift_ready" });
42
+ * ```
43
+ *
44
+ * Every operation in the published contract is a method named by its
45
+ * `operationId`; `call(operationId, input)` and `request(...)` reach the same
46
+ * table generically. A key acts as the person who made it: their role, their
47
+ * team, their credits and their limits, exactly as in the Daymaker app.
48
+ */
49
+ export declare class DaymakerClient {
50
+ #private;
51
+ readonly urls: ResolvedUrls;
52
+ /** `test` for a staff `dmk_test_` key: read-only, it cannot change data, spend credits or send. */
53
+ readonly keyKind: "live" | "test" | "unknown";
54
+ private readonly opts;
55
+ constructor(options?: DaymakerClientOptions);
56
+ /** Calls one operation and returns its body. */
57
+ call<K extends OperationId>(operationId: K, input: OperationInput<K>, options?: RequestOptions): Promise<OperationOutput<K>>;
58
+ /**
59
+ * Reads a list page by page, following `next_offset` until the API says
60
+ * there is no next page. Yields each page's whole answer.
61
+ *
62
+ * ```ts
63
+ * for await (const page of dm.pages("listLeads", { tab: "researched", limit: 100 })) {
64
+ * for (const lead of page.leads ?? []) console.log(lead.name);
65
+ * }
66
+ * ```
67
+ */
68
+ pages<K extends PagedOperationId>(operationId: K, input: OperationInput<K>, options?: RequestOptions): AsyncGenerator<OperationOutput<K>, void, void>;
69
+ /** Calls one operation and returns the body with its status, request id and idempotency details. */
70
+ request<K extends OperationId>(operationId: K, input: OperationInput<K>, options?: RequestOptions): Promise<DaymakerResponse<OperationOutput<K>>>;
71
+ /** Milliseconds to wait before the same request goes again, or null when the failure is yours to see. */
72
+ private retryDelay;
73
+ private build;
74
+ }
75
+ export { parseRetryAfter };
package/dist/client.js ADDED
@@ -0,0 +1,322 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { CHECK_BEFORE_RETRY, DaymakerError, errorFromResponse, parseRetryAfter } from "./errors.js";
3
+ import { OPERATIONS } from "./generated/operations.js";
4
+ import { SDK_VERSION } from "./version.js";
5
+ export const DEFAULT_API_URL = "https://daymaker.com/api/v2";
6
+ /** Accepts an origin or `<origin>/api/v2`, and derives the rest. */
7
+ export function resolveUrls(base = DEFAULT_API_URL) {
8
+ let url;
9
+ try {
10
+ url = new URL(base.trim().replace(/\/+$/, ""));
11
+ }
12
+ catch {
13
+ throw new DaymakerError({ kind: "invalid_request", code: "invalid_base_url", message: `Not a URL: ${base}` });
14
+ }
15
+ const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
16
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
17
+ throw new DaymakerError({
18
+ kind: "invalid_request",
19
+ code: "invalid_base_url",
20
+ message: `The Daymaker API URL must be https (http only for this computer), so a key is never sent in the clear: ${base}`,
21
+ });
22
+ }
23
+ const prefix = url.pathname.replace(/\/api\/v2$/, "").replace(/\/+$/, "");
24
+ const origin = `${url.origin}${prefix}`;
25
+ return {
26
+ origin,
27
+ api: `${origin}/api/v2`,
28
+ openapi: `${origin}/api/v2/openapi.json`,
29
+ docs: `${origin}/api/v2/docs`,
30
+ mcp: `${origin}/mcp`,
31
+ };
32
+ }
33
+ const sleepReal = (ms) => new Promise((r) => setTimeout(r, ms));
34
+ const env = (name) => typeof process !== "undefined" ? process.env?.[name] || undefined : undefined;
35
+ /** Characters a header value can carry and a person can see: printable ASCII. */
36
+ const VISIBLE = /^[\x21-\x7e]+$/;
37
+ const VISIBLE_WITH_SPACES = /^[\x20-\x7e]+$/;
38
+ /**
39
+ * Typed client for the Daymaker API.
40
+ *
41
+ * ```ts
42
+ * const dm = new DaymakerClient({ apiKey: process.env.DAYMAKER_KEY });
43
+ * const me = await dm.getMe();
44
+ * const { leads } = await dm.listLeads({ tab: "gift_ready" });
45
+ * ```
46
+ *
47
+ * Every operation in the published contract is a method named by its
48
+ * `operationId`; `call(operationId, input)` and `request(...)` reach the same
49
+ * table generically. A key acts as the person who made it: their role, their
50
+ * team, their credits and their limits, exactly as in the Daymaker app.
51
+ */
52
+ export class DaymakerClient {
53
+ urls;
54
+ /** `test` for a staff `dmk_test_` key: read-only, it cannot change data, spend credits or send. */
55
+ keyKind;
56
+ // A real private field: the key never shows in console.log(client) or JSON.stringify(client).
57
+ #apiKey;
58
+ opts;
59
+ constructor(options = {}) {
60
+ const apiKey = (options.apiKey ?? env("DAYMAKER_KEY") ?? "").trim();
61
+ if (!apiKey) {
62
+ throw new DaymakerError({
63
+ kind: "invalid_request",
64
+ code: "missing_api_key",
65
+ message: "No Daymaker API key. Pass apiKey or set DAYMAKER_KEY to a dmk_live_ key, made in Daymaker under Settings, API and MCP.",
66
+ });
67
+ }
68
+ if (!VISIBLE.test(apiKey)) {
69
+ // Said without the key itself: an error message ends up in logs.
70
+ throw new DaymakerError({
71
+ kind: "invalid_request",
72
+ code: "invalid_api_key",
73
+ message: "The Daymaker API key has a space, a line break or another character a key never has. Copy it again from Settings, API and MCP.",
74
+ });
75
+ }
76
+ if (/^dm_(live|test)_/.test(apiKey)) {
77
+ throw new DaymakerError({
78
+ kind: "invalid_request",
79
+ code: "wrong_key_family",
80
+ message: "This is a Cold Caked Cake API key (dm_live_ or dm_test_). It belongs at https://daymaker.com/api/v1/partner. The Daymaker API takes dmk_live_ and dmk_test_ keys, made in Daymaker under Settings, API and MCP.",
81
+ });
82
+ }
83
+ this.#apiKey = apiKey;
84
+ this.keyKind = apiKey.startsWith("dmk_test_") ? "test" : apiKey.startsWith("dmk_live_") ? "live" : "unknown";
85
+ this.urls = resolveUrls(options.baseUrl ?? env("DAYMAKER_API_URL") ?? DEFAULT_API_URL);
86
+ this.opts = {
87
+ maxRetries: options.maxRetries ?? 2,
88
+ timeoutMs: options.timeoutMs ?? 120_000,
89
+ maxRetryDelayMs: options.maxRetryDelayMs ?? 30_000,
90
+ userAgent: options.userAgent ?? `daymaker-sdk-js/${SDK_VERSION}`,
91
+ fetch: options.fetch,
92
+ idempotencyKeyFactory: options.idempotencyKeyFactory,
93
+ sleep: options.sleep,
94
+ };
95
+ for (const id of Object.keys(OPERATIONS)) {
96
+ Object.defineProperty(this, id, {
97
+ value: (input, o) => this.call(id, (input ?? {}), o),
98
+ enumerable: false,
99
+ });
100
+ }
101
+ }
102
+ /** Calls one operation and returns its body. */
103
+ async call(operationId, input, options) {
104
+ return (await this.request(operationId, input, options)).data;
105
+ }
106
+ /**
107
+ * Reads a list page by page, following `next_offset` until the API says
108
+ * there is no next page. Yields each page's whole answer.
109
+ *
110
+ * ```ts
111
+ * for await (const page of dm.pages("listLeads", { tab: "researched", limit: 100 })) {
112
+ * for (const lead of page.leads ?? []) console.log(lead.name);
113
+ * }
114
+ * ```
115
+ */
116
+ async *pages(operationId, input, options) {
117
+ const spec = OPERATIONS[operationId];
118
+ if (!spec?.queryParams.some((q) => q.name === "offset")) {
119
+ throw new DaymakerError({ kind: "invalid_request", message: `${String(operationId)} is not a list with an offset` });
120
+ }
121
+ let offset = Number(input.offset ?? 0);
122
+ for (;;) {
123
+ const page = await this.call(operationId, { ...input, offset }, options);
124
+ yield page;
125
+ const next = page.next_offset;
126
+ // A next page that does not move forward would loop for ever.
127
+ if (typeof next !== "number" || next <= offset)
128
+ return;
129
+ offset = next;
130
+ }
131
+ }
132
+ /** Calls one operation and returns the body with its status, request id and idempotency details. */
133
+ async request(operationId, input, options = {}) {
134
+ const spec = OPERATIONS[operationId];
135
+ if (!spec) {
136
+ throw new DaymakerError({ kind: "invalid_request", message: `Unknown operation: ${String(operationId)}` });
137
+ }
138
+ const built = this.build(spec, { ...input }, options);
139
+ const maxRetries = Math.max(0, options.maxRetries ?? this.opts.maxRetries);
140
+ const doFetch = this.opts.fetch ?? globalThis.fetch;
141
+ const sleep = this.opts.sleep ?? sleepReal;
142
+ const ctx = { operationId: spec.operationId, idempotencyKey: built.idempotencyKey };
143
+ for (let attempt = 1;; attempt++) {
144
+ const timeout = AbortSignal.timeout(options.timeoutMs ?? this.opts.timeoutMs);
145
+ const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
146
+ let res;
147
+ let data;
148
+ try {
149
+ // A redirect would carry the body and the Idempotency-Key to an address nobody configured.
150
+ res = await doFetch(built.url, { method: spec.method, headers: built.headers, body: built.body, signal, redirect: "error" });
151
+ // Reading the body is part of the attempt: a connection that breaks after the headers of a
152
+ // 201 must fail like any other lost answer, with the key in the error and the same retry rule.
153
+ data = await readBody(res);
154
+ }
155
+ catch (cause) {
156
+ if (options.signal?.aborted)
157
+ throw cause;
158
+ const timedOut = timeout.aborted;
159
+ const err = new DaymakerError({
160
+ kind: timedOut ? "timeout" : "network",
161
+ code: timedOut ? "timeout" : "network_error",
162
+ message: timedOut
163
+ ? `${spec.method} ${spec.path} timed out after ${options.timeoutMs ?? this.opts.timeoutMs}ms`
164
+ : `${spec.method} ${spec.path} failed: ${cause instanceof Error ? cause.message : String(cause)}`,
165
+ cause,
166
+ attempts: attempt,
167
+ ...ctx,
168
+ });
169
+ if (spec.retrySafe && attempt <= maxRetries) {
170
+ await sleep(backoff(attempt));
171
+ continue;
172
+ }
173
+ throw err;
174
+ }
175
+ if (res.ok) {
176
+ // Every answer of this API is a JSON object. Anything else is another server talking
177
+ // (a proxy page, a wrong DAYMAKER_API_URL), and must not pass for a result.
178
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
179
+ throw new DaymakerError({
180
+ kind: "api",
181
+ status: res.status,
182
+ code: "invalid_response",
183
+ message: `${spec.method} ${spec.path} answered ${res.status} with something that is not a JSON object. Check the API address: ${this.urls.api}`,
184
+ requestId: res.headers.get("x-request-id"),
185
+ body: data,
186
+ attempts: attempt,
187
+ ...ctx,
188
+ });
189
+ }
190
+ return {
191
+ data: data,
192
+ status: res.status,
193
+ requestId: res.headers.get("x-request-id"),
194
+ idempotencyKey: built.idempotencyKey,
195
+ idempotentReplay: res.headers.get("idempotent-replay") === "true",
196
+ attempts: attempt,
197
+ headers: res.headers,
198
+ };
199
+ }
200
+ const err = errorFromResponse(res.status, data, res.headers, { ...ctx, attempts: attempt });
201
+ const wait = this.retryDelay(spec, err, attempt);
202
+ if (wait !== null && attempt <= maxRetries) {
203
+ await sleep(wait);
204
+ continue;
205
+ }
206
+ throw err;
207
+ }
208
+ }
209
+ /** Milliseconds to wait before the same request goes again, or null when the failure is yours to see. */
210
+ retryDelay(spec, err, attempt) {
211
+ const status = err.status ?? 0;
212
+ const withinCap = (ms) => (ms <= this.opts.maxRetryDelayMs ? ms : null);
213
+ // The request may have acted: the caller checks what was done before anything is sent again.
214
+ if (CHECK_BEFORE_RETRY.has(err.code))
215
+ return null;
216
+ // 429: refused before any work. Waited out only when the window is short;
217
+ // a day's limit says hours, so that one is the caller's to see.
218
+ if (status === 429)
219
+ return err.retryAfterMs === null ? null : withinCap(err.retryAfterMs);
220
+ // The first request with this Idempotency-Key is still running: the same key may go again.
221
+ if (err.code === "idempotency_in_flight")
222
+ return withinCap(err.retryAfterMs ?? backoff(attempt));
223
+ if (!spec.retrySafe)
224
+ return null;
225
+ if (status === 503 && err.retryAfterMs !== null)
226
+ return withinCap(err.retryAfterMs);
227
+ if (status === 500 || status === 502 || status === 503 || status === 504)
228
+ return backoff(attempt);
229
+ return null;
230
+ }
231
+ build(spec, input, options) {
232
+ const take = (k) => {
233
+ const v = input[k];
234
+ delete input[k];
235
+ return v;
236
+ };
237
+ const invalid = (message) => new DaymakerError({ kind: "invalid_request", code: "validation_error", message, operationId: spec.operationId });
238
+ // A blank key means "none given": a model fills optional strings with "". Sent as it is, the
239
+ // API would read an empty header as no key at all, and a retry could then act twice.
240
+ const blank = (v) => v === undefined || v === null || (typeof v === "string" && v.trim() === "");
241
+ const inputKey = take("idempotency_key");
242
+ const given = !blank(options.idempotencyKey) ? options.idempotencyKey : !blank(inputKey) ? inputKey : undefined;
243
+ let suppliedKey;
244
+ if (given !== undefined) {
245
+ if (spec.idempotency === "none")
246
+ throw invalid(`${spec.operationId} takes no Idempotency-Key`);
247
+ suppliedKey = String(given).trim();
248
+ if (suppliedKey.length > 255 || !VISIBLE_WITH_SPACES.test(suppliedKey)) {
249
+ throw invalid(`${spec.operationId}: idempotency_key must be 1 to 255 visible characters`);
250
+ }
251
+ }
252
+ let path = spec.path;
253
+ for (const name of spec.pathParams) {
254
+ const v = take(name);
255
+ if (v === undefined || v === null || v === "")
256
+ throw invalid(`${spec.operationId} needs \`${name}\``);
257
+ // "." and ".." would be folded away by URL rules and reach a different address.
258
+ if (/^\.{1,2}$/.test(String(v)))
259
+ throw invalid(`${spec.operationId}: \`${name}\` is not an id`);
260
+ path = path.replace(`{${name}}`, encodeURIComponent(String(v)));
261
+ }
262
+ const url = new URL(this.urls.api + path);
263
+ for (const q of spec.queryParams) {
264
+ const v = take(q.name);
265
+ if (v === undefined || v === null) {
266
+ if (q.required)
267
+ throw invalid(`${spec.operationId} needs \`${q.name}\``);
268
+ continue;
269
+ }
270
+ url.searchParams.set(q.name, String(v));
271
+ }
272
+ // Header names have no case. Going through Headers lets the client's own win over a caller's
273
+ // `Authorization` or `Content-Type` however it is spelt, instead of both being sent.
274
+ let h;
275
+ try {
276
+ h = new Headers(options.headers);
277
+ }
278
+ catch {
279
+ throw invalid(`${spec.operationId}: a header in the request options is not a valid header`);
280
+ }
281
+ h.delete("x-api-key");
282
+ h.set("accept", "application/json");
283
+ h.set("authorization", `Bearer ${this.#apiKey}`);
284
+ h.set("user-agent", this.opts.userAgent);
285
+ let body;
286
+ if (spec.hasBody) {
287
+ // The API refuses unknown body fields itself, at any depth, and says which.
288
+ body = JSON.stringify(input);
289
+ h.set("content-type", "application/json");
290
+ }
291
+ else {
292
+ h.delete("content-type");
293
+ const unknown = Object.keys(input).filter((k) => input[k] !== undefined);
294
+ if (unknown.length)
295
+ throw invalid(`${spec.operationId} has no field named ${unknown.map((k) => `\`${k}\``).join(", ")}`);
296
+ }
297
+ let idempotencyKey = null;
298
+ h.delete("idempotency-key");
299
+ if (spec.idempotency !== "none") {
300
+ idempotencyKey = suppliedKey ?? (this.opts.idempotencyKeyFactory ?? randomUUID)();
301
+ h.set("idempotency-key", idempotencyKey);
302
+ }
303
+ return { url: url.toString(), headers: Object.fromEntries(h.entries()), body, idempotencyKey };
304
+ }
305
+ }
306
+ function backoff(attempt) {
307
+ const cap = Math.min(8_000, 500 * 2 ** (attempt - 1));
308
+ return Math.round(cap / 2 + Math.random() * (cap / 2));
309
+ }
310
+ async function readBody(res) {
311
+ const text = await res.text();
312
+ if (!text)
313
+ return {};
314
+ try {
315
+ return JSON.parse(text);
316
+ }
317
+ catch {
318
+ return text;
319
+ }
320
+ }
321
+ export { parseRetryAfter };
322
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACpG,O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CAAC;QACzC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC5B,IAAI,IAAI,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;YAChC,cAAc,GAAG,WAAW,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,IAAI,UAAU,CAAC,EAAE,CAAC;YAClF,CAAC,CAAC,GAAG,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IACjG,CAAC;CACF;AAED,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,GAAa;IACnC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,62 @@
1
+ export type DaymakerErrorKind = "api" | "network" | "timeout" | "invalid_request";
2
+ export interface DaymakerFieldProblem {
3
+ field: string;
4
+ problem: string;
5
+ }
6
+ export interface DaymakerErrorInit {
7
+ kind: DaymakerErrorKind;
8
+ message: string;
9
+ code?: string;
10
+ status?: number;
11
+ requestId?: string | null;
12
+ fields?: DaymakerFieldProblem[];
13
+ details?: Record<string, unknown>;
14
+ retryAfterMs?: number | null;
15
+ body?: unknown;
16
+ operationId?: string;
17
+ idempotencyKey?: string | null;
18
+ attempts?: number;
19
+ cause?: unknown;
20
+ }
21
+ /**
22
+ * Answers that mean the request may have acted, so sending it again could act
23
+ * twice. Check what was done first (read the lead, the campaign or the
24
+ * orders); a new attempt then needs a new Idempotency-Key.
25
+ */
26
+ export declare const CHECK_BEFORE_RETRY: ReadonlySet<string>;
27
+ /**
28
+ * Every failure the SDK raises. `status` and `code` come straight from the
29
+ * API's `{ error: { code, message, request_id, ... } }` envelope; `details`
30
+ * is that whole `error` object, with the fields a code brings along
31
+ * (`new_quote` with `quote_changed`, `needs` with `insufficient_scope`,
32
+ * `purchase_id` with `in_progress`, `next`, and so on).
33
+ *
34
+ * Branch on `status` and `code`. `message` is for people and may change.
35
+ *
36
+ * When `idempotencyKey` is set and the error is a timeout, a network error or
37
+ * a 5xx, send the same call again with that key: Daymaker gives the first
38
+ * answer back instead of acting twice. The exceptions are the codes in
39
+ * `CHECK_BEFORE_RETRY`.
40
+ */
41
+ export declare class DaymakerError extends Error {
42
+ readonly name = "DaymakerError";
43
+ readonly kind: DaymakerErrorKind;
44
+ readonly code: string;
45
+ readonly status: number | undefined;
46
+ readonly requestId: string | null;
47
+ readonly fields: DaymakerFieldProblem[];
48
+ readonly details: Record<string, unknown>;
49
+ readonly retryAfterMs: number | null;
50
+ readonly body: unknown;
51
+ readonly operationId: string | undefined;
52
+ readonly idempotencyKey: string | null;
53
+ readonly attempts: number;
54
+ constructor(init: DaymakerErrorInit);
55
+ /** True when the request may have acted and must be checked before it is sent again. */
56
+ get checkBeforeRetry(): boolean;
57
+ toJSON(): Record<string, unknown>;
58
+ }
59
+ export declare function isDaymakerError(err: unknown): err is DaymakerError;
60
+ /** Parses `Retry-After` (seconds or an HTTP date) into milliseconds. */
61
+ export declare function parseRetryAfter(value: string | null, now?: number): number | null;
62
+ export declare function errorFromResponse(status: number, body: unknown, headers: Headers, extra: Pick<DaymakerErrorInit, "operationId" | "idempotencyKey" | "attempts">): DaymakerError;
package/dist/errors.js ADDED
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Answers that mean the request may have acted, so sending it again could act
3
+ * twice. Check what was done first (read the lead, the campaign or the
4
+ * orders); a new attempt then needs a new Idempotency-Key.
5
+ */
6
+ export const CHECK_BEFORE_RETRY = new Set(["outcome_unknown", "partially_done", "in_progress"]);
7
+ /**
8
+ * Every failure the SDK raises. `status` and `code` come straight from the
9
+ * API's `{ error: { code, message, request_id, ... } }` envelope; `details`
10
+ * is that whole `error` object, with the fields a code brings along
11
+ * (`new_quote` with `quote_changed`, `needs` with `insufficient_scope`,
12
+ * `purchase_id` with `in_progress`, `next`, and so on).
13
+ *
14
+ * Branch on `status` and `code`. `message` is for people and may change.
15
+ *
16
+ * When `idempotencyKey` is set and the error is a timeout, a network error or
17
+ * a 5xx, send the same call again with that key: Daymaker gives the first
18
+ * answer back instead of acting twice. The exceptions are the codes in
19
+ * `CHECK_BEFORE_RETRY`.
20
+ */
21
+ export class DaymakerError extends Error {
22
+ name = "DaymakerError";
23
+ kind;
24
+ code;
25
+ status;
26
+ requestId;
27
+ fields;
28
+ details;
29
+ retryAfterMs;
30
+ body;
31
+ operationId;
32
+ idempotencyKey;
33
+ attempts;
34
+ constructor(init) {
35
+ super(init.message, init.cause === undefined ? undefined : { cause: init.cause });
36
+ this.kind = init.kind;
37
+ this.code = init.code ?? (init.status ? `http_${init.status}` : init.kind);
38
+ this.status = init.status;
39
+ this.requestId = init.requestId ?? null;
40
+ this.fields = init.fields ?? [];
41
+ this.details = init.details ?? {};
42
+ this.retryAfterMs = init.retryAfterMs ?? null;
43
+ this.body = init.body;
44
+ this.operationId = init.operationId;
45
+ this.idempotencyKey = init.idempotencyKey ?? null;
46
+ this.attempts = init.attempts ?? 1;
47
+ }
48
+ /** True when the request may have acted and must be checked before it is sent again. */
49
+ get checkBeforeRetry() {
50
+ return CHECK_BEFORE_RETRY.has(this.code);
51
+ }
52
+ toJSON() {
53
+ return {
54
+ name: this.name,
55
+ kind: this.kind,
56
+ status: this.status ?? null,
57
+ code: this.code,
58
+ message: this.message,
59
+ request_id: this.requestId,
60
+ fields: this.fields.length ? this.fields : undefined,
61
+ details: Object.keys(this.details).length ? this.details : undefined,
62
+ retry_after_ms: this.retryAfterMs,
63
+ operation_id: this.operationId,
64
+ idempotency_key: this.idempotencyKey,
65
+ attempts: this.attempts,
66
+ };
67
+ }
68
+ }
69
+ export function isDaymakerError(err) {
70
+ return err instanceof DaymakerError;
71
+ }
72
+ /** Parses `Retry-After` (seconds or an HTTP date) into milliseconds. */
73
+ export function parseRetryAfter(value, now = Date.now()) {
74
+ if (!value)
75
+ return null;
76
+ const secs = Number(value);
77
+ if (Number.isFinite(secs))
78
+ return Math.max(0, secs * 1000);
79
+ const at = Date.parse(value);
80
+ return Number.isNaN(at) ? null : Math.max(0, at - now);
81
+ }
82
+ export function errorFromResponse(status, body, headers, extra) {
83
+ const env = body && typeof body === "object" && "error" in body && body.error && typeof body.error === "object"
84
+ ? body.error
85
+ : null;
86
+ const message = typeof env?.message === "string"
87
+ ? env.message
88
+ : typeof body === "string" && body.trim()
89
+ ? body.trim().slice(0, 500)
90
+ : `The Daymaker API answered HTTP ${status}`;
91
+ return new DaymakerError({
92
+ kind: "api",
93
+ status,
94
+ code: typeof env?.code === "string" ? env.code : undefined,
95
+ message,
96
+ requestId: (typeof env?.request_id === "string" ? env.request_id : null) ?? headers.get("x-request-id"),
97
+ fields: Array.isArray(env?.fields) ? env.fields : undefined,
98
+ details: env ?? undefined,
99
+ retryAfterMs: parseRetryAfter(headers.get("retry-after")),
100
+ body,
101
+ ...extra,
102
+ });
103
+ }
104
+ //# sourceMappingURL=errors.js.map