@typeship-ax/mcp 0.6.0 → 0.8.0
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/README.md +1 -1
- package/api.json +5597 -3010
- package/api.md +433 -54
- package/dist/core/http.d.ts +6 -92
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/http.js +70 -209
- package/dist/core/pagination.d.ts.map +1 -1
- package/dist/core/pagination.js +6 -34
- package/dist/dates.d.ts +0 -2
- package/dist/dates.d.ts.map +1 -1
- package/dist/dates.js +0 -1
- package/dist/docs.d.ts +11 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +114 -0
- package/dist/errors.d.ts +27 -27
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -7
- package/dist/index.d.ts +19 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -13
- package/dist/mcp-protocol.d.ts +19 -24
- package/dist/mcp-protocol.d.ts.map +1 -1
- package/dist/mcp-protocol.js +160 -124
- package/dist/mcp.js +16 -19
- package/dist/ops.d.ts +5 -0
- package/dist/ops.d.ts.map +1 -1
- package/dist/ops.js +31 -17
- package/dist/resources/account.d.ts +2 -2
- package/dist/resources/account.d.ts.map +1 -1
- package/dist/resources/api-keys.d.ts +10 -5
- package/dist/resources/api-keys.d.ts.map +1 -1
- package/dist/resources/api-keys.js +3 -1
- package/dist/resources/definition-revisions.d.ts +58 -0
- package/dist/resources/definition-revisions.d.ts.map +1 -0
- package/dist/resources/definition-revisions.js +110 -0
- package/dist/resources/definitions.d.ts +24 -0
- package/dist/resources/definitions.d.ts.map +1 -0
- package/dist/resources/definitions.js +51 -0
- package/dist/resources/generate.d.ts +5 -5
- package/dist/resources/generate.d.ts.map +1 -1
- package/dist/resources/generate.js +3 -3
- package/dist/resources/generations.d.ts +3 -3
- package/dist/resources/generations.d.ts.map +1 -1
- package/dist/resources/generations.js +1 -1
- package/dist/resources/projects.d.ts +66 -26
- package/dist/resources/projects.d.ts.map +1 -1
- package/dist/resources/projects.js +87 -13
- package/dist/resources/targets.d.ts +86 -0
- package/dist/resources/targets.d.ts.map +1 -0
- package/dist/resources/targets.js +184 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +119 -62
- package/dist/types.d.ts +1761 -222
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -3
- package/package.json +1 -1
- package/src/core/http.ts +75 -293
- package/src/core/pagination.ts +6 -30
- package/src/dates.ts +0 -1
- package/src/docs.ts +101 -0
- package/src/errors.ts +30 -30
- package/src/index.ts +23 -13
- package/src/mcp-protocol.ts +170 -120
- package/src/mcp.ts +22 -22
- package/src/ops.ts +43 -17
- package/src/resources/account.ts +3 -3
- package/src/resources/api-keys.ts +22 -7
- package/src/resources/definition-revisions.ts +198 -0
- package/src/resources/definitions.ts +97 -0
- package/src/resources/generate.ts +6 -6
- package/src/resources/generations.ts +4 -4
- package/src/resources/projects.ts +182 -37
- package/src/resources/targets.ts +346 -0
- package/src/schemas.ts +119 -62
- package/src/types.ts +1947 -281
- package/dist/resources/spec-revisions.d.ts +0 -47
- package/dist/resources/spec-revisions.d.ts.map +0 -1
- package/dist/resources/spec-revisions.js +0 -90
- package/src/resources/spec-revisions.ts +0 -150
package/dist/core/http.d.ts
CHANGED
|
@@ -15,7 +15,12 @@ export interface RequestOptions {
|
|
|
15
15
|
export interface ResponseMeta {
|
|
16
16
|
status: number;
|
|
17
17
|
headers: Headers;
|
|
18
|
-
/**
|
|
18
|
+
/** Parsed wire body before it is narrowed to the generated response type.
|
|
19
|
+
* Use this escape hatch for additive fields or variants introduced after
|
|
20
|
+
* this generator edition. */
|
|
21
|
+
rawBody?: unknown;
|
|
22
|
+
/** Request identifier from the JSON response body, or from headers for
|
|
23
|
+
* raw and bodyless responses. */
|
|
19
24
|
requestId?: string;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
@@ -32,15 +37,6 @@ export interface RequestContext {
|
|
|
32
37
|
/** 0 on the first try, increments per retry. */
|
|
33
38
|
attempt: number;
|
|
34
39
|
}
|
|
35
|
-
/** One server-sent event from a text/event-stream response. */
|
|
36
|
-
export interface SseEvent {
|
|
37
|
-
/** The `event:` field; undefined for unnamed events. */
|
|
38
|
-
event?: string;
|
|
39
|
-
/** The `id:` field, when the server sends one. */
|
|
40
|
-
id?: string;
|
|
41
|
-
/** Concatenated `data:` lines. Parse as JSON if your API sends JSON. */
|
|
42
|
-
data: string;
|
|
43
|
-
}
|
|
44
40
|
/**
|
|
45
41
|
* Every SDK call returns a discriminated result instead of throwing.
|
|
46
42
|
* Narrow on `ok` and the error side is a typed union of the documented
|
|
@@ -68,62 +64,6 @@ export declare class ApiError<S extends number = number, B = unknown> extends Er
|
|
|
68
64
|
export declare class UnexpectedApiError extends ApiError<number, unknown> {
|
|
69
65
|
constructor(status: number, body: unknown, response: ResponseMeta);
|
|
70
66
|
}
|
|
71
|
-
/** A 200 response whose GraphQL payload carried errors. */
|
|
72
|
-
export declare class GraphQLRequestError extends Error {
|
|
73
|
-
/** The raw errors array from the GraphQL response. */
|
|
74
|
-
readonly errors: {
|
|
75
|
-
message?: string;
|
|
76
|
-
path?: unknown[];
|
|
77
|
-
extensions?: unknown;
|
|
78
|
-
}[];
|
|
79
|
-
readonly response: ResponseMeta;
|
|
80
|
-
constructor(errors: unknown[], response: ResponseMeta);
|
|
81
|
-
}
|
|
82
|
-
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
83
|
-
type Unwrap<T> = NonNullable<T> extends readonly (infer U)[] ? Unwrap<U> : NonNullable<T>;
|
|
84
|
-
type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
|
|
85
|
-
type TypeNameOf<T> = T extends {
|
|
86
|
-
__typename?: infer N;
|
|
87
|
-
} ? Extract<N, string> : never;
|
|
88
|
-
type Prettify<T> = {
|
|
89
|
-
[K in keyof T]: T[K];
|
|
90
|
-
} & {};
|
|
91
|
-
/**
|
|
92
|
-
* A selection over a GraphQL result type `T`: `true` picks a leaf field, a
|
|
93
|
-
* nested object picks inside an object field, and `on` picks per concrete
|
|
94
|
-
* type when `T` is a union or interface (`{ on: { Transaction: { amount: true } } }`).
|
|
95
|
-
* Keys are checked against the schema, so a typo is a compile error.
|
|
96
|
-
*/
|
|
97
|
-
export type Selection<T> = Unwrap<T> extends Primitive ? never : SelectionObject<Unwrap<T>>;
|
|
98
|
-
type FieldSelection<V> = Unwrap<V> extends Primitive ? true : SelectionObject<Unwrap<V>>;
|
|
99
|
-
type SelectionObject<T> = {
|
|
100
|
-
[K in Extract<keyof T, string> as K extends "__typename" ? never : K]?: FieldSelection<T[K]>;
|
|
101
|
-
} & {
|
|
102
|
-
__typename?: true;
|
|
103
|
-
} & (IsUnion<T> extends true ? {
|
|
104
|
-
on?: {
|
|
105
|
-
[N in TypeNameOf<T>]?: SelectionObject<Extract<T, {
|
|
106
|
-
__typename?: N;
|
|
107
|
-
}>>;
|
|
108
|
-
};
|
|
109
|
-
} : {
|
|
110
|
-
on?: never;
|
|
111
|
-
});
|
|
112
|
-
/** The result type a {@link Selection} `S` produces from result type `T`:
|
|
113
|
-
* exactly the fields picked, nullability and lists preserved, union members
|
|
114
|
-
* narrowed by `__typename`. */
|
|
115
|
-
export type Selected<T, S> = T extends readonly (infer U)[] ? Selected<U, S>[] : T extends Primitive ? T : S extends object ? Prettify<SelectedMember<T, S>> : never;
|
|
116
|
-
type SelectedMember<T, S> = (S extends {
|
|
117
|
-
on?: infer O;
|
|
118
|
-
} ? O extends object ? TypeNameOf<T> extends keyof O ? PickSelected<T, NonNullable<O[TypeNameOf<T>]>> : {} : {} : {}) & PickSelected<T, S>;
|
|
119
|
-
type PickSelected<T, S> = {
|
|
120
|
-
-readonly [K in keyof S as K extends "on" ? never : K extends keyof T ? (S[K] extends true | object ? K : never) : never]-?: K extends "__typename" ? NonNullable<T[K & keyof T]> : S[K] extends true ? Exclude<T[K & keyof T], undefined> : Selected<Exclude<T[K & keyof T], undefined>, S[K]>;
|
|
121
|
-
};
|
|
122
|
-
/** A selection object or a raw selection set (`"{ id name }"`). */
|
|
123
|
-
export type SelectionInput = string | Record<string, unknown>;
|
|
124
|
-
/** Serialize a selection object to a GraphQL selection set. Strings pass
|
|
125
|
-
* through untouched. */
|
|
126
|
-
export declare function selectionToString(selection: SelectionInput): string;
|
|
127
67
|
export interface Violation {
|
|
128
68
|
path: string;
|
|
129
69
|
message: string;
|
|
@@ -159,14 +99,9 @@ export interface CoreRequest {
|
|
|
159
99
|
errors?: Record<string, ErrorCtor>;
|
|
160
100
|
/** Idempotent requests are retried automatically. */
|
|
161
101
|
idempotent?: boolean;
|
|
162
|
-
/** Success body is text/event-stream: yield SseEvents instead of parsing. */
|
|
163
|
-
stream?: boolean;
|
|
164
102
|
/** Header name auto-filled with one UUID per call (stable across retries)
|
|
165
103
|
* when the caller doesn't supply a value. */
|
|
166
104
|
idempotencyKey?: string;
|
|
167
|
-
/** GraphQL: unwrap body.data[field] and turn body.errors into a
|
|
168
|
-
* GraphQLRequestError. */
|
|
169
|
-
graphqlField?: string;
|
|
170
105
|
/** Key into the schemas table for optional runtime validation. */
|
|
171
106
|
schemaKey?: string;
|
|
172
107
|
/** Operation-level retry policy (x-typeship-retries), merged over the
|
|
@@ -277,27 +212,6 @@ export declare class HttpCore {
|
|
|
277
212
|
export declare function formatDebugEvent(name: string, event: DebugEvent): string;
|
|
278
213
|
/** Wrap a bearer credential (static or callback) as an Authorization value. */
|
|
279
214
|
export declare function bearerAuth(token: AuthValue): AuthValue;
|
|
280
|
-
export interface ClientCredentialsConfig {
|
|
281
|
-
clientId: string;
|
|
282
|
-
clientSecret: string;
|
|
283
|
-
tokenUrl: string;
|
|
284
|
-
scopes?: string[];
|
|
285
|
-
/** Extra token-request parameters, e.g. the "audience" some
|
|
286
|
-
* authorization servers require for API-valid access tokens. */
|
|
287
|
-
tokenParams?: Record<string, string>;
|
|
288
|
-
/** How credentials reach the token endpoint. Default "post"
|
|
289
|
-
* (client_secret_post, form fields); "basic" sends an Authorization
|
|
290
|
-
* header (client_secret_basic). */
|
|
291
|
-
authMethod?: "post" | "basic";
|
|
292
|
-
fetchImpl?: typeof fetch;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* OAuth2 client-credentials token source: fetches from the token URL,
|
|
296
|
-
* caches until expiry (60s early refresh), and shares one in-flight
|
|
297
|
-
* request across concurrent callers. Returned function plugs in as an
|
|
298
|
-
* Authorization AuthValue, resolved before every attempt.
|
|
299
|
-
*/
|
|
300
|
-
export declare function oauthClientCredentials(config: ClientCredentialsConfig): () => Promise<string>;
|
|
301
215
|
export declare function toBase64(input: string): string;
|
|
302
216
|
export {};
|
|
303
217
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/core/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/core/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/core/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,yEAAyE;IACzE,SAA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,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0BD,qBAAa,QAAQ;IACnB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,6DAA6D;IAC7D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAW;IAC5C;iDAC6C;IAC7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;gBAG9B,MAAM,EAAE,UAAU;IAa9B,kEAAkE;IAClE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI5B,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAqJjD,IAAI;IAmDlB;;;;;;;;;;;;OAYG;YACW,eAAe;YA+Cf,QAAQ;CAiBvB;AAOD,wEAAwE;AACxE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAOxE;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAKtD;AA+GD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI9C"}
|
package/dist/core/http.js
CHANGED
|
@@ -29,43 +29,6 @@ export class UnexpectedApiError extends ApiError {
|
|
|
29
29
|
super("Unexpected HTTP status " + status, status, body, response);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
/** A 200 response whose GraphQL payload carried errors. */
|
|
33
|
-
export class GraphQLRequestError extends Error {
|
|
34
|
-
/** The raw errors array from the GraphQL response. */
|
|
35
|
-
errors;
|
|
36
|
-
response;
|
|
37
|
-
constructor(errors, response) {
|
|
38
|
-
const first = errors[0]?.message;
|
|
39
|
-
super(first ?? "GraphQL request returned errors");
|
|
40
|
-
this.name = "GraphQLRequestError";
|
|
41
|
-
this.errors = errors;
|
|
42
|
-
this.response = response;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/** Serialize a selection object to a GraphQL selection set. Strings pass
|
|
46
|
-
* through untouched. */
|
|
47
|
-
export function selectionToString(selection) {
|
|
48
|
-
if (typeof selection === "string")
|
|
49
|
-
return selection;
|
|
50
|
-
const parts = [];
|
|
51
|
-
for (const [key, value] of Object.entries(selection)) {
|
|
52
|
-
if (!value)
|
|
53
|
-
continue;
|
|
54
|
-
if (key === "on" && typeof value === "object") {
|
|
55
|
-
for (const [typeName, sub] of Object.entries(value)) {
|
|
56
|
-
if (sub && typeof sub === "object")
|
|
57
|
-
parts.push("... on " + typeName + " " + selectionToString(sub));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else if (value === true) {
|
|
61
|
-
parts.push(key);
|
|
62
|
-
}
|
|
63
|
-
else if (typeof value === "object") {
|
|
64
|
-
parts.push(key + " " + selectionToString(value));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return "{ " + (parts.length > 0 ? parts.join(" ") : "__typename") + " }";
|
|
68
|
-
}
|
|
69
32
|
/** Request or response data did not match the spec's schema (opt-in via the
|
|
70
33
|
* client's validate option). Never thrown: returned as the error side of
|
|
71
34
|
* ApiResult, like every other failure. */
|
|
@@ -299,16 +262,19 @@ export class HttpCore {
|
|
|
299
262
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
300
263
|
let response;
|
|
301
264
|
const attemptStarted = Date.now();
|
|
265
|
+
const emitResponseDebug = (value, body) => this.config.debug?.({
|
|
266
|
+
method: req.method,
|
|
267
|
+
path: req.path,
|
|
268
|
+
status: value.status,
|
|
269
|
+
durationMs: Date.now() - attemptStarted,
|
|
270
|
+
attempt: attempt + 1,
|
|
271
|
+
requestId: requestIdFromBody(body) ??
|
|
272
|
+
value.headers.get("request-id") ??
|
|
273
|
+
value.headers.get("x-request-id") ??
|
|
274
|
+
undefined,
|
|
275
|
+
});
|
|
302
276
|
try {
|
|
303
277
|
response = await this.send(req, timeoutMs, attempt, autoIdempotencyKey);
|
|
304
|
-
this.config.debug?.({
|
|
305
|
-
method: req.method,
|
|
306
|
-
path: req.path,
|
|
307
|
-
status: response.status,
|
|
308
|
-
durationMs: Date.now() - attemptStarted,
|
|
309
|
-
attempt: attempt + 1,
|
|
310
|
-
requestId: response.headers.get("x-request-id") ?? response.headers.get("request-id") ?? undefined,
|
|
311
|
-
});
|
|
312
278
|
}
|
|
313
279
|
catch (cause) {
|
|
314
280
|
lastError = cause;
|
|
@@ -328,21 +294,23 @@ export class HttpCore {
|
|
|
328
294
|
return { ok: false, error };
|
|
329
295
|
}
|
|
330
296
|
if (response.ok) {
|
|
331
|
-
if (req.stream) {
|
|
332
|
-
return { ok: true, data: sseEvents(response), response: meta(response) };
|
|
333
|
-
}
|
|
334
297
|
let data;
|
|
335
298
|
try {
|
|
336
299
|
data = (await parseBody(response, req.method));
|
|
337
300
|
}
|
|
338
301
|
catch (cause) {
|
|
302
|
+
emitResponseDebug(response);
|
|
339
303
|
const error = new TransportError("The response body read was aborted before completing", cause);
|
|
340
304
|
await this.config.onError?.(error, { method: req.method, path: req.path });
|
|
341
305
|
return { ok: false, error, response: meta(response) };
|
|
342
306
|
}
|
|
343
|
-
|
|
307
|
+
emitResponseDebug(response, data);
|
|
308
|
+
const responseMeta = meta(response, data);
|
|
309
|
+
let responseData = data;
|
|
310
|
+
let shouldValidateResponse = responseData !== undefined;
|
|
311
|
+
if (opSchemas?.res && this.config.validate.responses && shouldValidateResponse) {
|
|
344
312
|
const violations = [];
|
|
345
|
-
validateAgainstSchema(
|
|
313
|
+
validateAgainstSchema(responseData, opSchemas.res, "response", violations, this.config.schemaDefs);
|
|
346
314
|
if (violations.length > 0) {
|
|
347
315
|
const validationError = new ValidationError("response", violations);
|
|
348
316
|
if (this.config.validate.mode === "warn") {
|
|
@@ -351,28 +319,27 @@ export class HttpCore {
|
|
|
351
319
|
else {
|
|
352
320
|
const error = validationError;
|
|
353
321
|
await this.config.onError?.(error, { method: req.method, path: req.path });
|
|
354
|
-
return { ok: false, error, response:
|
|
322
|
+
return { ok: false, error, response: responseMeta };
|
|
355
323
|
}
|
|
356
324
|
}
|
|
357
325
|
}
|
|
358
|
-
|
|
359
|
-
const payload = data;
|
|
360
|
-
const responseMeta = meta(response);
|
|
361
|
-
if (Array.isArray(payload?.errors) && payload.errors.length > 0) {
|
|
362
|
-
const gqlError = new GraphQLRequestError(payload.errors, responseMeta);
|
|
363
|
-
await this.config.onError?.(gqlError, { method: req.method, path: req.path });
|
|
364
|
-
return { ok: false, error: gqlError, response: responseMeta };
|
|
365
|
-
}
|
|
366
|
-
return { ok: true, data: payload?.data?.[req.graphqlField], response: responseMeta };
|
|
367
|
-
}
|
|
368
|
-
return { ok: true, data, response: meta(response) };
|
|
326
|
+
return { ok: true, data, response: responseMeta };
|
|
369
327
|
}
|
|
370
328
|
// 429 is safe to retry regardless of idempotency; other retryable
|
|
371
329
|
// statuses only when the verb is idempotent.
|
|
372
330
|
const retryableStatus = retryableStatuses.has(response.status) &&
|
|
373
331
|
(retryAllowed || response.status === 429);
|
|
374
332
|
if (attempt < maxRetries && retryableStatus) {
|
|
375
|
-
|
|
333
|
+
const delay = retryAfterMs(response) ?? backoff(attempt, policy);
|
|
334
|
+
let retryBody;
|
|
335
|
+
try {
|
|
336
|
+
retryBody = await parseBody(response, req.method);
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
retryBody = undefined;
|
|
340
|
+
}
|
|
341
|
+
emitResponseDebug(response, retryBody);
|
|
342
|
+
await sleep(delay);
|
|
376
343
|
continue;
|
|
377
344
|
}
|
|
378
345
|
let body;
|
|
@@ -382,7 +349,8 @@ export class HttpCore {
|
|
|
382
349
|
catch {
|
|
383
350
|
body = undefined; // error responses keep their status even if the body read aborts
|
|
384
351
|
}
|
|
385
|
-
|
|
352
|
+
emitResponseDebug(response, body);
|
|
353
|
+
const responseMeta = meta(response, body);
|
|
386
354
|
const Ctor = req.errors?.[String(response.status)] ??
|
|
387
355
|
req.errors?.[String(Math.floor(response.status / 100)) + "XX"] ??
|
|
388
356
|
req.errors?.["default"];
|
|
@@ -421,26 +389,14 @@ export class HttpCore {
|
|
|
421
389
|
attempt,
|
|
422
390
|
};
|
|
423
391
|
await this.config.onRequest?.(context);
|
|
424
|
-
// Streaming responses are exempt from the attempt timeout once headers
|
|
425
|
-
// arrive (an event stream may stay open far longer than timeoutMs);
|
|
426
|
-
// everything else keeps the timeout armed through the body read, so a
|
|
427
|
-
// stalled body aborts instead of hanging.
|
|
428
392
|
const signals = [];
|
|
429
|
-
|
|
430
|
-
if (req.stream) {
|
|
431
|
-
const headersTimeout = new AbortController();
|
|
432
|
-
const timer = setTimeout(() => headersTimeout.abort(new DOMException("Timed out waiting for response headers", "TimeoutError")), timeoutMs);
|
|
433
|
-
timer.unref?.();
|
|
434
|
-
clearStreamTimeout = () => clearTimeout(timer);
|
|
435
|
-
signals.push(headersTimeout.signal);
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
393
|
+
{
|
|
438
394
|
signals.push(AbortSignal.timeout(timeoutMs));
|
|
439
395
|
}
|
|
440
396
|
if (req.options?.signal)
|
|
441
397
|
signals.push(req.options.signal);
|
|
442
398
|
try {
|
|
443
|
-
const signal =
|
|
399
|
+
const signal = composeSignals(signals);
|
|
444
400
|
const response = this.manualRedirects
|
|
445
401
|
? await this.followRedirects(context, body, signal)
|
|
446
402
|
: await this.config.fetch(context.url, {
|
|
@@ -453,7 +409,6 @@ export class HttpCore {
|
|
|
453
409
|
return response;
|
|
454
410
|
}
|
|
455
411
|
finally {
|
|
456
|
-
clearStreamTimeout?.();
|
|
457
412
|
}
|
|
458
413
|
}
|
|
459
414
|
/**
|
|
@@ -538,64 +493,6 @@ export class HttpCore {
|
|
|
538
493
|
async function resolveAuthValue(value) {
|
|
539
494
|
return typeof value === "function" ? await value() : value;
|
|
540
495
|
}
|
|
541
|
-
/** Parse a text/event-stream body into SseEvents, lazily. */
|
|
542
|
-
async function* sseEvents(response) {
|
|
543
|
-
if (!response.body)
|
|
544
|
-
return;
|
|
545
|
-
const reader = response.body.getReader();
|
|
546
|
-
const decoder = new TextDecoder();
|
|
547
|
-
let buffer = "";
|
|
548
|
-
let dataLines = [];
|
|
549
|
-
let eventName;
|
|
550
|
-
let eventId;
|
|
551
|
-
const flush = () => {
|
|
552
|
-
if (dataLines.length === 0)
|
|
553
|
-
return undefined;
|
|
554
|
-
const event = { data: dataLines.join("\n") };
|
|
555
|
-
if (eventName !== undefined)
|
|
556
|
-
event.event = eventName;
|
|
557
|
-
if (eventId !== undefined)
|
|
558
|
-
event.id = eventId;
|
|
559
|
-
dataLines = [];
|
|
560
|
-
eventName = undefined;
|
|
561
|
-
return event;
|
|
562
|
-
};
|
|
563
|
-
try {
|
|
564
|
-
while (true) {
|
|
565
|
-
const { done, value } = await reader.read();
|
|
566
|
-
if (done)
|
|
567
|
-
break;
|
|
568
|
-
buffer += decoder.decode(value, { stream: true });
|
|
569
|
-
let newline;
|
|
570
|
-
while ((newline = buffer.indexOf("\n")) !== -1) {
|
|
571
|
-
const hasCr = newline > 0 && buffer[newline - 1] === "\r";
|
|
572
|
-
const line = buffer.slice(0, hasCr ? newline - 1 : newline);
|
|
573
|
-
buffer = buffer.slice(newline + 1);
|
|
574
|
-
if (line === "") {
|
|
575
|
-
const event = flush();
|
|
576
|
-
if (event)
|
|
577
|
-
yield event;
|
|
578
|
-
}
|
|
579
|
-
else if (line.startsWith("data:")) {
|
|
580
|
-
dataLines.push(line.slice(5).replace(/^ /, ""));
|
|
581
|
-
}
|
|
582
|
-
else if (line.startsWith("event:")) {
|
|
583
|
-
eventName = line.slice(6).replace(/^ /, "");
|
|
584
|
-
}
|
|
585
|
-
else if (line.startsWith("id:")) {
|
|
586
|
-
eventId = line.slice(3).replace(/^ /, "");
|
|
587
|
-
}
|
|
588
|
-
// comments (":") and "retry:" are intentionally ignored
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
const last = flush();
|
|
592
|
-
if (last)
|
|
593
|
-
yield last;
|
|
594
|
-
}
|
|
595
|
-
finally {
|
|
596
|
-
reader.releaseLock();
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
496
|
/** Default rendering for debug events (the boolean debug:true sink). */
|
|
600
497
|
export function formatDebugEvent(name, event) {
|
|
601
498
|
return name + " " + event.method + " " + event.path +
|
|
@@ -612,54 +509,6 @@ export function bearerAuth(token) {
|
|
|
612
509
|
}
|
|
613
510
|
return "Bearer " + token;
|
|
614
511
|
}
|
|
615
|
-
/**
|
|
616
|
-
* OAuth2 client-credentials token source: fetches from the token URL,
|
|
617
|
-
* caches until expiry (60s early refresh), and shares one in-flight
|
|
618
|
-
* request across concurrent callers. Returned function plugs in as an
|
|
619
|
-
* Authorization AuthValue, resolved before every attempt.
|
|
620
|
-
*/
|
|
621
|
-
export function oauthClientCredentials(config) {
|
|
622
|
-
let token;
|
|
623
|
-
let expiresAt = 0;
|
|
624
|
-
let inflight;
|
|
625
|
-
const fetchImpl = config.fetchImpl ?? fetch;
|
|
626
|
-
async function fetchToken() {
|
|
627
|
-
const params = new URLSearchParams({ grant_type: "client_credentials" });
|
|
628
|
-
if (config.scopes !== undefined && config.scopes.length > 0) {
|
|
629
|
-
params.set("scope", config.scopes.join(" "));
|
|
630
|
-
}
|
|
631
|
-
for (const [key, value] of Object.entries(config.tokenParams ?? {})) {
|
|
632
|
-
params.set(key, value);
|
|
633
|
-
}
|
|
634
|
-
const headers = {
|
|
635
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
636
|
-
Accept: "application/json",
|
|
637
|
-
};
|
|
638
|
-
if (config.authMethod === "basic") {
|
|
639
|
-
headers["Authorization"] = "Basic " + toBase64(config.clientId + ":" + config.clientSecret);
|
|
640
|
-
}
|
|
641
|
-
else {
|
|
642
|
-
params.set("client_id", config.clientId);
|
|
643
|
-
params.set("client_secret", config.clientSecret);
|
|
644
|
-
}
|
|
645
|
-
const response = await fetchImpl(config.tokenUrl, { method: "POST", headers, body: params.toString() });
|
|
646
|
-
const body = (await response.json().catch(() => null));
|
|
647
|
-
if (!response.ok || typeof body?.access_token !== "string") {
|
|
648
|
-
throw new TransportError("OAuth token request failed (HTTP " + response.status + (body?.error ? ": " + body.error : "") + ")", body);
|
|
649
|
-
}
|
|
650
|
-
token = body.access_token;
|
|
651
|
-
expiresAt = body.expires_in !== undefined
|
|
652
|
-
? Date.now() + body.expires_in * 1000 - 60_000
|
|
653
|
-
: Number.MAX_SAFE_INTEGER;
|
|
654
|
-
return token;
|
|
655
|
-
}
|
|
656
|
-
return async () => {
|
|
657
|
-
if (token !== undefined && Date.now() < expiresAt)
|
|
658
|
-
return "Bearer " + token;
|
|
659
|
-
inflight ??= fetchToken().finally(() => { inflight = undefined; });
|
|
660
|
-
return "Bearer " + (await inflight);
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
512
|
/**
|
|
664
513
|
* Bracket-style deep encoding shared by query strings and form bodies:
|
|
665
514
|
* { created: { gte: 5 } } -> created[gte]=5, { items: [{ id: "x" }] } ->
|
|
@@ -686,29 +535,8 @@ function serializeBody(req) {
|
|
|
686
535
|
switch (req.bodyKind ?? "json") {
|
|
687
536
|
case "json":
|
|
688
537
|
return { body: JSON.stringify(req.body), contentType: "application/json" };
|
|
689
|
-
case "form": {
|
|
690
|
-
const params = new URLSearchParams();
|
|
691
|
-
for (const [k, v] of Object.entries(req.body)) {
|
|
692
|
-
appendDeep(params, k, v);
|
|
693
|
-
}
|
|
694
|
-
// URLSearchParams sets its own content type with the charset suffix.
|
|
695
|
-
return { body: params };
|
|
696
|
-
}
|
|
697
|
-
case "multipart": {
|
|
698
|
-
const form = new FormData();
|
|
699
|
-
for (const [k, v] of Object.entries(req.body)) {
|
|
700
|
-
if (v === undefined || v === null)
|
|
701
|
-
continue;
|
|
702
|
-
form.append(k, v instanceof Blob ? v : typeof v === "object" ? JSON.stringify(v) : String(v));
|
|
703
|
-
}
|
|
704
|
-
// Let fetch set the boundary header.
|
|
705
|
-
return { body: form };
|
|
706
|
-
}
|
|
707
|
-
case "text":
|
|
708
|
-
return { body: String(req.body), contentType: "text/plain" };
|
|
709
|
-
case "binary":
|
|
710
|
-
return { body: req.body };
|
|
711
538
|
}
|
|
539
|
+
throw new Error("Unsupported request body kind: " + String(req.bodyKind));
|
|
712
540
|
}
|
|
713
541
|
async function parseBody(response, method) {
|
|
714
542
|
if (method === "HEAD" || response.status === 204 || response.status === 205)
|
|
@@ -731,15 +559,48 @@ async function parseBody(response, method) {
|
|
|
731
559
|
return undefined;
|
|
732
560
|
}
|
|
733
561
|
}
|
|
734
|
-
function
|
|
562
|
+
function requestIdFromBody(body) {
|
|
563
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
564
|
+
return undefined;
|
|
565
|
+
const value = body.request_id ?? body.requestId;
|
|
566
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
567
|
+
}
|
|
568
|
+
function meta(response, body) {
|
|
735
569
|
return {
|
|
736
570
|
status: response.status,
|
|
737
571
|
headers: response.headers,
|
|
738
|
-
|
|
572
|
+
...(body !== undefined ? { rawBody: body } : {}),
|
|
573
|
+
requestId: requestIdFromBody(body) ??
|
|
739
574
|
response.headers.get("request-id") ??
|
|
575
|
+
response.headers.get("x-request-id") ??
|
|
740
576
|
undefined,
|
|
741
577
|
};
|
|
742
578
|
}
|
|
579
|
+
/** AbortSignal.any reached Node in 18.17. Keep the package's Node 18 floor
|
|
580
|
+
* honest for earlier 18.x releases and for web runtimes without it. */
|
|
581
|
+
function composeSignals(signals) {
|
|
582
|
+
const nativeAny = AbortSignal.any;
|
|
583
|
+
if (nativeAny)
|
|
584
|
+
return nativeAny.call(AbortSignal, signals);
|
|
585
|
+
const controller = new AbortController();
|
|
586
|
+
const listeners = new Map();
|
|
587
|
+
const abortFrom = (signal) => {
|
|
588
|
+
for (const [item, listener] of listeners)
|
|
589
|
+
item.removeEventListener("abort", listener);
|
|
590
|
+
listeners.clear();
|
|
591
|
+
controller.abort(signal.reason);
|
|
592
|
+
};
|
|
593
|
+
for (const signal of signals) {
|
|
594
|
+
if (signal.aborted) {
|
|
595
|
+
abortFrom(signal);
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
const listener = () => abortFrom(signal);
|
|
599
|
+
listeners.set(signal, listener);
|
|
600
|
+
signal.addEventListener("abort", listener, { once: true });
|
|
601
|
+
}
|
|
602
|
+
return controller.signal;
|
|
603
|
+
}
|
|
743
604
|
function retryAfterMs(response) {
|
|
744
605
|
const header = response.headers.get("retry-after");
|
|
745
606
|
if (!header)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/core/pagination.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,QAAQ,EACR,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,QAAQ,GAAG,kBAAkB,GAAG,MAAM,GAAG,QAAQ,CAAC;IACzD,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC,IAAI,CACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC3B,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE1C,qBAAa,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,O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SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAIvD,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK,EAC/C,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,EACnF,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,GAC9D,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAIZ,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC;CAOtE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,CAAC,EAC9B,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,UAAU,GACjB,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAgBtB"}
|
package/dist/core/pagination.js
CHANGED
|
@@ -37,30 +37,12 @@ export class Page {
|
|
|
37
37
|
const next = getPath(this.body, config.nextCursorField);
|
|
38
38
|
if (next === undefined || next === null || next === "")
|
|
39
39
|
return null;
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
case "cursorFromLastId": {
|
|
43
|
-
if (items.length === 0)
|
|
44
|
-
return null;
|
|
45
|
-
const last = items[items.length - 1];
|
|
46
|
-
const id = last?.[config.idField ?? "id"];
|
|
47
|
-
if (id === undefined || id === null)
|
|
48
|
-
return null;
|
|
49
|
-
return { ...params, [config.cursorParam]: id };
|
|
50
|
-
}
|
|
51
|
-
case "page": {
|
|
52
|
-
if (!this.looksLikeMore(items))
|
|
40
|
+
if (next === params[config.cursorParam])
|
|
53
41
|
return null;
|
|
54
|
-
|
|
55
|
-
return { ...params, [config.pageParam]: current + 1 };
|
|
56
|
-
}
|
|
57
|
-
case "offset": {
|
|
58
|
-
if (!this.looksLikeMore(items))
|
|
59
|
-
return null;
|
|
60
|
-
const current = Number(params[config.offsetParam] ?? 0);
|
|
61
|
-
return { ...params, [config.offsetParam]: current + items.length };
|
|
42
|
+
return { ...params, [config.cursorParam]: next };
|
|
62
43
|
}
|
|
63
44
|
}
|
|
45
|
+
return null;
|
|
64
46
|
}
|
|
65
47
|
/** Fetch the next page, or null when this is the last one. Throws the typed error on failure. */
|
|
66
48
|
async getNextPage() {
|
|
@@ -116,17 +98,9 @@ export class PagePromise {
|
|
|
116
98
|
}
|
|
117
99
|
}
|
|
118
100
|
export function paginate(core, req, config) {
|
|
119
|
-
const isGraphql =
|
|
101
|
+
const isGraphql = false;
|
|
120
102
|
const fetchPage = async (params) => {
|
|
121
|
-
|
|
122
|
-
? {
|
|
123
|
-
...req,
|
|
124
|
-
body: {
|
|
125
|
-
...req.body,
|
|
126
|
-
variables: { ...(req.body?.variables ?? {}), ...params },
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
: { ...req, query: params };
|
|
103
|
+
let nextReq = { ...req, query: params };
|
|
130
104
|
const result = await core.request(nextReq);
|
|
131
105
|
if (!result.ok)
|
|
132
106
|
return result;
|
|
@@ -134,9 +108,7 @@ export function paginate(core, req, config) {
|
|
|
134
108
|
return { ok: true, data: page, response: result.response };
|
|
135
109
|
};
|
|
136
110
|
const initial = {};
|
|
137
|
-
|
|
138
|
-
? (req.body?.variables ?? {})
|
|
139
|
-
: (req.query ?? {});
|
|
111
|
+
let seed = req.query ?? {};
|
|
140
112
|
for (const [k, v] of Object.entries(seed)) {
|
|
141
113
|
if (v !== undefined)
|
|
142
114
|
initial[k] = v;
|
package/dist/dates.d.ts
CHANGED
|
@@ -15,8 +15,6 @@
|
|
|
15
15
|
* validates absolute values. Zero dependencies.
|
|
16
16
|
*/
|
|
17
17
|
export type DateKind = "date" | "date-time";
|
|
18
|
-
/** The forms a date-shaped argument accepts, for descriptions and help. */
|
|
19
|
-
export declare const RELATIVE_DATE_HINT = "Accepts ISO 8601 or a relative form: -P7D, -7d, 7 days ago, today, now.";
|
|
20
18
|
/**
|
|
21
19
|
* Resolve a relative date expression. `null` means "not a relative form,
|
|
22
20
|
* pass the value through"; `{ error }` means it looked relative but is
|
package/dist/dates.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../src/dates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAiD5C;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,GAAE,IAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAmC/H;AAcD,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAE3D"}
|
package/dist/dates.js
CHANGED
|
@@ -24,7 +24,6 @@ const UNIT_MS = {
|
|
|
24
24
|
const CALENDAR_UNITS = new Set(["mo", "month", "y", "yr", "year"]);
|
|
25
25
|
const HINT = "Use a signed form: -7d or -P7D for seven days ago, +7d or +P7D for seven days ahead; or an absolute ISO 8601 value.";
|
|
26
26
|
/** The forms a date-shaped argument accepts, for descriptions and help. */
|
|
27
|
-
export const RELATIVE_DATE_HINT = "Accepts ISO 8601 or a relative form: -P7D, -7d, 7 days ago, today, now.";
|
|
28
27
|
function shift(base, amount, unit) {
|
|
29
28
|
const d = new Date(base.getTime());
|
|
30
29
|
if (CALENDAR_UNITS.has(unit)) {
|