@markupai/api 0.2.0 → 1.0.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/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/errors/TooManyRequestsError.d.ts +9 -0
- package/dist/cjs/api/errors/TooManyRequestsError.js +52 -0
- package/dist/cjs/api/errors/index.d.ts +1 -0
- package/dist/cjs/api/errors/index.js +1 -0
- package/dist/cjs/api/resources/styleChecks/client/Client.d.ts +1 -0
- package/dist/cjs/api/resources/styleChecks/client/Client.js +3 -0
- package/dist/cjs/api/resources/styleRewrites/client/Client.d.ts +1 -0
- package/dist/cjs/api/resources/styleRewrites/client/Client.js +3 -0
- package/dist/cjs/api/resources/styleSuggestions/client/Client.d.ts +1 -0
- package/dist/cjs/api/resources/styleSuggestions/client/Client.js +3 -0
- package/dist/cjs/api/types/StyleGuideResponse.d.ts +2 -2
- package/dist/cjs/api/types/StyleGuides.d.ts +1 -2
- package/dist/cjs/api/types/StyleGuides.js +0 -1
- package/dist/cjs/core/auth/index.d.ts +2 -2
- package/dist/cjs/core/fetcher/EndpointMetadata.d.ts +13 -0
- package/dist/cjs/core/fetcher/EndpointMetadata.js +2 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +12 -0
- package/dist/cjs/core/fetcher/EndpointSupplier.js +22 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -2
- package/dist/cjs/core/fetcher/Fetcher.js +3 -2
- package/dist/cjs/core/fetcher/index.d.ts +2 -0
- package/dist/cjs/core/fetcher/index.js +3 -1
- package/dist/cjs/core/fetcher/requestWithRetries.js +44 -8
- package/dist/cjs/core/file/exports.d.ts +1 -1
- package/dist/cjs/core/headers.d.ts +2 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/errors/TooManyRequestsError.d.mts +9 -0
- package/dist/esm/api/errors/TooManyRequestsError.mjs +15 -0
- package/dist/esm/api/errors/index.d.mts +1 -0
- package/dist/esm/api/errors/index.mjs +1 -0
- package/dist/esm/api/resources/styleChecks/client/Client.d.mts +1 -0
- package/dist/esm/api/resources/styleChecks/client/Client.mjs +3 -0
- package/dist/esm/api/resources/styleRewrites/client/Client.d.mts +1 -0
- package/dist/esm/api/resources/styleRewrites/client/Client.mjs +3 -0
- package/dist/esm/api/resources/styleSuggestions/client/Client.d.mts +1 -0
- package/dist/esm/api/resources/styleSuggestions/client/Client.mjs +3 -0
- package/dist/esm/api/types/StyleGuideResponse.d.mts +2 -2
- package/dist/esm/api/types/StyleGuides.d.mts +1 -2
- package/dist/esm/api/types/StyleGuides.mjs +0 -1
- package/dist/esm/core/auth/index.d.mts +2 -2
- package/dist/esm/core/fetcher/EndpointMetadata.d.mts +13 -0
- package/dist/esm/core/fetcher/EndpointMetadata.mjs +1 -0
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +12 -0
- package/dist/esm/core/fetcher/EndpointSupplier.mjs +19 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +4 -2
- package/dist/esm/core/fetcher/Fetcher.mjs +3 -2
- package/dist/esm/core/fetcher/index.d.mts +2 -0
- package/dist/esm/core/fetcher/index.mjs +1 -0
- package/dist/esm/core/fetcher/requestWithRetries.mjs +44 -8
- package/dist/esm/core/file/exports.d.mts +1 -1
- package/dist/esm/core/headers.d.mts +2 -3
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +8 -13
package/dist/cjs/Client.js
CHANGED
|
@@ -48,8 +48,8 @@ class MarkupAIClient {
|
|
|
48
48
|
this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
|
|
49
49
|
"X-Fern-Language": "JavaScript",
|
|
50
50
|
"X-Fern-SDK-Name": "@markupai/api",
|
|
51
|
-
"X-Fern-SDK-Version": "0.
|
|
52
|
-
"User-Agent": "@markupai/api/0.
|
|
51
|
+
"X-Fern-SDK-Version": "1.0.0",
|
|
52
|
+
"User-Agent": "@markupai/api/1.0.0",
|
|
53
53
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
54
54
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
55
55
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
import * as errors from "../../errors/index.js";
|
|
5
|
+
import * as MarkupAI from "../index.js";
|
|
6
|
+
import * as core from "../../core/index.js";
|
|
7
|
+
export declare class TooManyRequestsError extends errors.MarkupAIError {
|
|
8
|
+
constructor(body: MarkupAI.ErrorResponse, rawResponse?: core.RawResponse);
|
|
9
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.TooManyRequestsError = void 0;
|
|
40
|
+
const errors = __importStar(require("../../errors/index.js"));
|
|
41
|
+
class TooManyRequestsError extends errors.MarkupAIError {
|
|
42
|
+
constructor(body, rawResponse) {
|
|
43
|
+
super({
|
|
44
|
+
message: "TooManyRequestsError",
|
|
45
|
+
statusCode: 429,
|
|
46
|
+
body: body,
|
|
47
|
+
rawResponse: rawResponse,
|
|
48
|
+
});
|
|
49
|
+
Object.setPrototypeOf(this, TooManyRequestsError.prototype);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.TooManyRequestsError = TooManyRequestsError;
|
|
@@ -20,3 +20,4 @@ __exportStar(require("./UnprocessableEntityError.js"), exports);
|
|
|
20
20
|
__exportStar(require("./InternalServerError.js"), exports);
|
|
21
21
|
__exportStar(require("./ContentTooLargeError.js"), exports);
|
|
22
22
|
__exportStar(require("./NotFoundError.js"), exports);
|
|
23
|
+
__exportStar(require("./TooManyRequestsError.js"), exports);
|
|
@@ -43,6 +43,7 @@ export declare class StyleChecks {
|
|
|
43
43
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
44
44
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
45
45
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
46
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
46
47
|
* @throws {@link MarkupAI.InternalServerError}
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
@@ -68,6 +68,7 @@ class StyleChecks {
|
|
|
68
68
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
69
69
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
70
70
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
71
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
71
72
|
* @throws {@link MarkupAI.InternalServerError}
|
|
72
73
|
*
|
|
73
74
|
* @example
|
|
@@ -121,6 +122,8 @@ class StyleChecks {
|
|
|
121
122
|
throw new MarkupAI.ContentTooLargeError(_response.error.body, _response.rawResponse);
|
|
122
123
|
case 422:
|
|
123
124
|
throw new MarkupAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
125
|
+
case 429:
|
|
126
|
+
throw new MarkupAI.TooManyRequestsError(_response.error.body, _response.rawResponse);
|
|
124
127
|
case 500:
|
|
125
128
|
throw new MarkupAI.InternalServerError(_response.error.body, _response.rawResponse);
|
|
126
129
|
default:
|
|
@@ -43,6 +43,7 @@ export declare class StyleRewrites {
|
|
|
43
43
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
44
44
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
45
45
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
46
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
46
47
|
* @throws {@link MarkupAI.InternalServerError}
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
@@ -68,6 +68,7 @@ class StyleRewrites {
|
|
|
68
68
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
69
69
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
70
70
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
71
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
71
72
|
* @throws {@link MarkupAI.InternalServerError}
|
|
72
73
|
*
|
|
73
74
|
* @example
|
|
@@ -121,6 +122,8 @@ class StyleRewrites {
|
|
|
121
122
|
throw new MarkupAI.ContentTooLargeError(_response.error.body, _response.rawResponse);
|
|
122
123
|
case 422:
|
|
123
124
|
throw new MarkupAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
125
|
+
case 429:
|
|
126
|
+
throw new MarkupAI.TooManyRequestsError(_response.error.body, _response.rawResponse);
|
|
124
127
|
case 500:
|
|
125
128
|
throw new MarkupAI.InternalServerError(_response.error.body, _response.rawResponse);
|
|
126
129
|
default:
|
|
@@ -43,6 +43,7 @@ export declare class StyleSuggestions {
|
|
|
43
43
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
44
44
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
45
45
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
46
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
46
47
|
* @throws {@link MarkupAI.InternalServerError}
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
@@ -68,6 +68,7 @@ class StyleSuggestions {
|
|
|
68
68
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
69
69
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
70
70
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
71
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
71
72
|
* @throws {@link MarkupAI.InternalServerError}
|
|
72
73
|
*
|
|
73
74
|
* @example
|
|
@@ -121,6 +122,8 @@ class StyleSuggestions {
|
|
|
121
122
|
throw new MarkupAI.ContentTooLargeError(_response.error.body, _response.rawResponse);
|
|
122
123
|
case 422:
|
|
123
124
|
throw new MarkupAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
125
|
+
case 429:
|
|
126
|
+
throw new MarkupAI.TooManyRequestsError(_response.error.body, _response.rawResponse);
|
|
124
127
|
case 500:
|
|
125
128
|
throw new MarkupAI.InternalServerError(_response.error.body, _response.rawResponse);
|
|
126
129
|
default:
|
|
@@ -16,6 +16,6 @@ export interface StyleGuideResponse {
|
|
|
16
16
|
updated_at?: string;
|
|
17
17
|
/** The ID of the user who last updated the style guide. If null, the style guide has never been updated. */
|
|
18
18
|
updated_by?: string;
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/** User-friendly summary of the style guide's contents and characteristics */
|
|
20
|
+
summary?: string;
|
|
21
21
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
*/
|
|
4
|
-
export type StyleGuides = "ap" | "chicago" | "microsoft" | "
|
|
4
|
+
export type StyleGuides = "ap" | "chicago" | "microsoft" | "style_brand_importer";
|
|
5
5
|
export declare const StyleGuides: {
|
|
6
6
|
readonly Ap: "ap";
|
|
7
7
|
readonly Chicago: "chicago";
|
|
8
8
|
readonly Microsoft: "microsoft";
|
|
9
|
-
readonly Demo: "demo";
|
|
10
9
|
readonly StyleBrandImporter: "style_brand_importer";
|
|
11
10
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AuthProvider } from "./AuthProvider.js";
|
|
2
|
-
export {
|
|
1
|
+
export type { AuthProvider } from "./AuthProvider.js";
|
|
2
|
+
export type { AuthRequest } from "./AuthRequest.js";
|
|
3
3
|
export { BasicAuth } from "./BasicAuth.js";
|
|
4
4
|
export { BearerToken } from "./BearerToken.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SecuritySchemeKey = string;
|
|
2
|
+
/**
|
|
3
|
+
* A collection of security schemes, where the key is the name of the security scheme and the value is the list of scopes required for that scheme.
|
|
4
|
+
* All schemes in the collection must be satisfied for authentication to be successful.
|
|
5
|
+
*/
|
|
6
|
+
export type SecuritySchemeCollection = Record<SecuritySchemeKey, AuthScope[]>;
|
|
7
|
+
export type AuthScope = string;
|
|
8
|
+
export type EndpointMetadata = {
|
|
9
|
+
/**
|
|
10
|
+
* An array of security scheme collections. Each collection represents an alternative way to authenticate.
|
|
11
|
+
*/
|
|
12
|
+
security?: SecuritySchemeCollection[];
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EndpointMetadata } from "./EndpointMetadata.js";
|
|
2
|
+
import { Supplier } from "./Supplier.js";
|
|
3
|
+
type EndpointSupplierFn<T> = (arg: {
|
|
4
|
+
endpointMetadata: EndpointMetadata;
|
|
5
|
+
}) => T | Promise<T>;
|
|
6
|
+
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
7
|
+
export declare const EndpointSupplier: {
|
|
8
|
+
get: <T>(supplier: EndpointSupplier<T>, arg: {
|
|
9
|
+
endpointMetadata: EndpointMetadata;
|
|
10
|
+
}) => Promise<T>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EndpointSupplier = void 0;
|
|
13
|
+
exports.EndpointSupplier = {
|
|
14
|
+
get: (supplier, arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
if (typeof supplier === "function") {
|
|
16
|
+
return supplier(arg);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return supplier;
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { APIResponse } from "./APIResponse.js";
|
|
2
|
-
import {
|
|
2
|
+
import { EndpointMetadata } from "./EndpointMetadata.js";
|
|
3
|
+
import { EndpointSupplier } from "./EndpointSupplier.js";
|
|
3
4
|
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
4
5
|
export declare namespace Fetcher {
|
|
5
6
|
interface Args {
|
|
6
7
|
url: string;
|
|
7
8
|
method: string;
|
|
8
9
|
contentType?: string;
|
|
9
|
-
headers?: Record<string, string |
|
|
10
|
+
headers?: Record<string, string | EndpointSupplier<string | null | undefined> | null | undefined>;
|
|
10
11
|
queryParameters?: Record<string, unknown>;
|
|
11
12
|
body?: unknown;
|
|
12
13
|
timeoutMs?: number;
|
|
@@ -16,6 +17,7 @@ export declare namespace Fetcher {
|
|
|
16
17
|
requestType?: "json" | "file" | "bytes";
|
|
17
18
|
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
18
19
|
duplex?: "half";
|
|
20
|
+
endpointMetadata?: EndpointMetadata;
|
|
19
21
|
}
|
|
20
22
|
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
21
23
|
interface FailedStatusCodeError {
|
|
@@ -13,6 +13,7 @@ exports.fetcher = void 0;
|
|
|
13
13
|
exports.fetcherImpl = fetcherImpl;
|
|
14
14
|
const json_js_1 = require("../json.js");
|
|
15
15
|
const createRequestUrl_js_1 = require("./createRequestUrl.js");
|
|
16
|
+
const EndpointSupplier_js_1 = require("./EndpointSupplier.js");
|
|
16
17
|
const getErrorResponseBody_js_1 = require("./getErrorResponseBody.js");
|
|
17
18
|
const getFetchFn_js_1 = require("./getFetchFn.js");
|
|
18
19
|
const getRequestBody_js_1 = require("./getRequestBody.js");
|
|
@@ -20,9 +21,9 @@ const getResponseBody_js_1 = require("./getResponseBody.js");
|
|
|
20
21
|
const makeRequest_js_1 = require("./makeRequest.js");
|
|
21
22
|
const RawResponse_js_1 = require("./RawResponse.js");
|
|
22
23
|
const requestWithRetries_js_1 = require("./requestWithRetries.js");
|
|
23
|
-
const Supplier_js_1 = require("./Supplier.js");
|
|
24
24
|
function getHeaders(args) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
26
27
|
const newHeaders = {};
|
|
27
28
|
if (args.body !== undefined && args.contentType != null) {
|
|
28
29
|
newHeaders["Content-Type"] = args.contentType;
|
|
@@ -31,7 +32,7 @@ function getHeaders(args) {
|
|
|
31
32
|
return newHeaders;
|
|
32
33
|
}
|
|
33
34
|
for (const [key, value] of Object.entries(args.headers)) {
|
|
34
|
-
const result = yield
|
|
35
|
+
const result = yield EndpointSupplier_js_1.EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
|
|
35
36
|
if (typeof result === "string") {
|
|
36
37
|
newHeaders[key] = result;
|
|
37
38
|
continue;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type { APIResponse } from "./APIResponse.js";
|
|
2
2
|
export type { BinaryResponse } from "./BinaryResponse.js";
|
|
3
|
+
export type { EndpointMetadata } from "./EndpointMetadata.js";
|
|
4
|
+
export { EndpointSupplier } from "./EndpointSupplier.js";
|
|
3
5
|
export type { Fetcher, FetchFunction } from "./Fetcher.js";
|
|
4
6
|
export { fetcher } from "./Fetcher.js";
|
|
5
7
|
export { getHeader } from "./getHeader.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Supplier = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.HttpResponsePromise = exports.getHeader = exports.fetcher = void 0;
|
|
3
|
+
exports.Supplier = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.HttpResponsePromise = exports.getHeader = exports.fetcher = exports.EndpointSupplier = void 0;
|
|
4
|
+
var EndpointSupplier_js_1 = require("./EndpointSupplier.js");
|
|
5
|
+
Object.defineProperty(exports, "EndpointSupplier", { enumerable: true, get: function () { return EndpointSupplier_js_1.EndpointSupplier; } });
|
|
4
6
|
var Fetcher_js_1 = require("./Fetcher.js");
|
|
5
7
|
Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return Fetcher_js_1.fetcher; } });
|
|
6
8
|
var getHeader_js_1 = require("./getHeader.js");
|
|
@@ -14,21 +14,57 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
|
|
|
14
14
|
const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
15
15
|
const DEFAULT_MAX_RETRIES = 2;
|
|
16
16
|
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
17
|
-
function
|
|
18
|
-
// Generate a random value between
|
|
19
|
-
const jitterMultiplier = 1 +
|
|
17
|
+
function addPositiveJitter(delay) {
|
|
18
|
+
// Generate a random value between 0 and +JITTER_FACTOR
|
|
19
|
+
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
20
20
|
return delay * jitterMultiplier;
|
|
21
21
|
}
|
|
22
|
+
function addSymmetricJitter(delay) {
|
|
23
|
+
// Generate a random value in a JITTER_FACTOR-sized percentage range around delay
|
|
24
|
+
const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
|
|
25
|
+
return delay * jitterMultiplier;
|
|
26
|
+
}
|
|
27
|
+
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
28
|
+
// Check for Retry-After header first (RFC 7231), with no jitter
|
|
29
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
30
|
+
if (retryAfter) {
|
|
31
|
+
// Parse as number of seconds...
|
|
32
|
+
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
33
|
+
if (!isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
34
|
+
return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
|
|
35
|
+
}
|
|
36
|
+
// ...or as an HTTP date; both are valid
|
|
37
|
+
const retryAfterDate = new Date(retryAfter);
|
|
38
|
+
if (!isNaN(retryAfterDate.getTime())) {
|
|
39
|
+
const delay = retryAfterDate.getTime() - Date.now();
|
|
40
|
+
if (delay > 0) {
|
|
41
|
+
return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Then check for industry-standard X-RateLimit-Reset header, with positive jitter
|
|
46
|
+
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
47
|
+
if (rateLimitReset) {
|
|
48
|
+
const resetTime = parseInt(rateLimitReset, 10);
|
|
49
|
+
if (!isNaN(resetTime)) {
|
|
50
|
+
// Assume Unix timestamp in epoch seconds
|
|
51
|
+
const delay = resetTime * 1000 - Date.now();
|
|
52
|
+
if (delay > 0) {
|
|
53
|
+
return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Fall back to exponential backoff, with symmetric jitter
|
|
58
|
+
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
59
|
+
}
|
|
22
60
|
function requestWithRetries(requestFn_1) {
|
|
23
61
|
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
24
62
|
let response = yield requestFn();
|
|
25
63
|
for (let i = 0; i < maxRetries; ++i) {
|
|
26
64
|
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const delayWithJitter = addJitter(baseDelay);
|
|
31
|
-
yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
|
|
65
|
+
// Get delay with appropriate jitter applied
|
|
66
|
+
const delay = getRetryDelayFromHeaders(response, i);
|
|
67
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
32
68
|
response = yield requestFn();
|
|
33
69
|
}
|
|
34
70
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Uploadable } from "./types.js";
|
|
1
|
+
export type { Uploadable } from "./types.js";
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
|
|
1
|
+
export declare function mergeHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, string | THeaderValue>;
|
|
2
|
+
export declare function mergeOnlyDefinedHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, THeaderValue>;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.0";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/Client.mjs
CHANGED
|
@@ -12,8 +12,8 @@ export class MarkupAIClient {
|
|
|
12
12
|
this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
|
|
13
13
|
"X-Fern-Language": "JavaScript",
|
|
14
14
|
"X-Fern-SDK-Name": "@markupai/api",
|
|
15
|
-
"X-Fern-SDK-Version": "0.
|
|
16
|
-
"User-Agent": "@markupai/api/0.
|
|
15
|
+
"X-Fern-SDK-Version": "1.0.0",
|
|
16
|
+
"User-Agent": "@markupai/api/1.0.0",
|
|
17
17
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
18
18
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
19
19
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
import * as errors from "../../errors/index.mjs";
|
|
5
|
+
import * as MarkupAI from "../index.mjs";
|
|
6
|
+
import * as core from "../../core/index.mjs";
|
|
7
|
+
export declare class TooManyRequestsError extends errors.MarkupAIError {
|
|
8
|
+
constructor(body: MarkupAI.ErrorResponse, rawResponse?: core.RawResponse);
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
*/
|
|
4
|
+
import * as errors from "../../errors/index.mjs";
|
|
5
|
+
export class TooManyRequestsError extends errors.MarkupAIError {
|
|
6
|
+
constructor(body, rawResponse) {
|
|
7
|
+
super({
|
|
8
|
+
message: "TooManyRequestsError",
|
|
9
|
+
statusCode: 429,
|
|
10
|
+
body: body,
|
|
11
|
+
rawResponse: rawResponse,
|
|
12
|
+
});
|
|
13
|
+
Object.setPrototypeOf(this, TooManyRequestsError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -43,6 +43,7 @@ export declare class StyleChecks {
|
|
|
43
43
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
44
44
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
45
45
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
46
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
46
47
|
* @throws {@link MarkupAI.InternalServerError}
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
@@ -32,6 +32,7 @@ export class StyleChecks {
|
|
|
32
32
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
33
33
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
34
34
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
35
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
35
36
|
* @throws {@link MarkupAI.InternalServerError}
|
|
36
37
|
*
|
|
37
38
|
* @example
|
|
@@ -85,6 +86,8 @@ export class StyleChecks {
|
|
|
85
86
|
throw new MarkupAI.ContentTooLargeError(_response.error.body, _response.rawResponse);
|
|
86
87
|
case 422:
|
|
87
88
|
throw new MarkupAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
89
|
+
case 429:
|
|
90
|
+
throw new MarkupAI.TooManyRequestsError(_response.error.body, _response.rawResponse);
|
|
88
91
|
case 500:
|
|
89
92
|
throw new MarkupAI.InternalServerError(_response.error.body, _response.rawResponse);
|
|
90
93
|
default:
|
|
@@ -43,6 +43,7 @@ export declare class StyleRewrites {
|
|
|
43
43
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
44
44
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
45
45
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
46
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
46
47
|
* @throws {@link MarkupAI.InternalServerError}
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
@@ -32,6 +32,7 @@ export class StyleRewrites {
|
|
|
32
32
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
33
33
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
34
34
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
35
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
35
36
|
* @throws {@link MarkupAI.InternalServerError}
|
|
36
37
|
*
|
|
37
38
|
* @example
|
|
@@ -85,6 +86,8 @@ export class StyleRewrites {
|
|
|
85
86
|
throw new MarkupAI.ContentTooLargeError(_response.error.body, _response.rawResponse);
|
|
86
87
|
case 422:
|
|
87
88
|
throw new MarkupAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
89
|
+
case 429:
|
|
90
|
+
throw new MarkupAI.TooManyRequestsError(_response.error.body, _response.rawResponse);
|
|
88
91
|
case 500:
|
|
89
92
|
throw new MarkupAI.InternalServerError(_response.error.body, _response.rawResponse);
|
|
90
93
|
default:
|
|
@@ -43,6 +43,7 @@ export declare class StyleSuggestions {
|
|
|
43
43
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
44
44
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
45
45
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
46
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
46
47
|
* @throws {@link MarkupAI.InternalServerError}
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
@@ -32,6 +32,7 @@ export class StyleSuggestions {
|
|
|
32
32
|
* @throws {@link MarkupAI.ForbiddenError}
|
|
33
33
|
* @throws {@link MarkupAI.ContentTooLargeError}
|
|
34
34
|
* @throws {@link MarkupAI.UnprocessableEntityError}
|
|
35
|
+
* @throws {@link MarkupAI.TooManyRequestsError}
|
|
35
36
|
* @throws {@link MarkupAI.InternalServerError}
|
|
36
37
|
*
|
|
37
38
|
* @example
|
|
@@ -85,6 +86,8 @@ export class StyleSuggestions {
|
|
|
85
86
|
throw new MarkupAI.ContentTooLargeError(_response.error.body, _response.rawResponse);
|
|
86
87
|
case 422:
|
|
87
88
|
throw new MarkupAI.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
89
|
+
case 429:
|
|
90
|
+
throw new MarkupAI.TooManyRequestsError(_response.error.body, _response.rawResponse);
|
|
88
91
|
case 500:
|
|
89
92
|
throw new MarkupAI.InternalServerError(_response.error.body, _response.rawResponse);
|
|
90
93
|
default:
|
|
@@ -16,6 +16,6 @@ export interface StyleGuideResponse {
|
|
|
16
16
|
updated_at?: string;
|
|
17
17
|
/** The ID of the user who last updated the style guide. If null, the style guide has never been updated. */
|
|
18
18
|
updated_by?: string;
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/** User-friendly summary of the style guide's contents and characteristics */
|
|
20
|
+
summary?: string;
|
|
21
21
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
*/
|
|
4
|
-
export type StyleGuides = "ap" | "chicago" | "microsoft" | "
|
|
4
|
+
export type StyleGuides = "ap" | "chicago" | "microsoft" | "style_brand_importer";
|
|
5
5
|
export declare const StyleGuides: {
|
|
6
6
|
readonly Ap: "ap";
|
|
7
7
|
readonly Chicago: "chicago";
|
|
8
8
|
readonly Microsoft: "microsoft";
|
|
9
|
-
readonly Demo: "demo";
|
|
10
9
|
readonly StyleBrandImporter: "style_brand_importer";
|
|
11
10
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AuthProvider } from "./AuthProvider.mjs";
|
|
2
|
-
export {
|
|
1
|
+
export type { AuthProvider } from "./AuthProvider.mjs";
|
|
2
|
+
export type { AuthRequest } from "./AuthRequest.mjs";
|
|
3
3
|
export { BasicAuth } from "./BasicAuth.mjs";
|
|
4
4
|
export { BearerToken } from "./BearerToken.mjs";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SecuritySchemeKey = string;
|
|
2
|
+
/**
|
|
3
|
+
* A collection of security schemes, where the key is the name of the security scheme and the value is the list of scopes required for that scheme.
|
|
4
|
+
* All schemes in the collection must be satisfied for authentication to be successful.
|
|
5
|
+
*/
|
|
6
|
+
export type SecuritySchemeCollection = Record<SecuritySchemeKey, AuthScope[]>;
|
|
7
|
+
export type AuthScope = string;
|
|
8
|
+
export type EndpointMetadata = {
|
|
9
|
+
/**
|
|
10
|
+
* An array of security scheme collections. Each collection represents an alternative way to authenticate.
|
|
11
|
+
*/
|
|
12
|
+
security?: SecuritySchemeCollection[];
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
2
|
+
import { Supplier } from "./Supplier.mjs";
|
|
3
|
+
type EndpointSupplierFn<T> = (arg: {
|
|
4
|
+
endpointMetadata: EndpointMetadata;
|
|
5
|
+
}) => T | Promise<T>;
|
|
6
|
+
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
7
|
+
export declare const EndpointSupplier: {
|
|
8
|
+
get: <T>(supplier: EndpointSupplier<T>, arg: {
|
|
9
|
+
endpointMetadata: EndpointMetadata;
|
|
10
|
+
}) => Promise<T>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const EndpointSupplier = {
|
|
11
|
+
get: (supplier, arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
if (typeof supplier === "function") {
|
|
13
|
+
return supplier(arg);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return supplier;
|
|
17
|
+
}
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { APIResponse } from "./APIResponse.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
3
|
+
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
3
4
|
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
4
5
|
export declare namespace Fetcher {
|
|
5
6
|
interface Args {
|
|
6
7
|
url: string;
|
|
7
8
|
method: string;
|
|
8
9
|
contentType?: string;
|
|
9
|
-
headers?: Record<string, string |
|
|
10
|
+
headers?: Record<string, string | EndpointSupplier<string | null | undefined> | null | undefined>;
|
|
10
11
|
queryParameters?: Record<string, unknown>;
|
|
11
12
|
body?: unknown;
|
|
12
13
|
timeoutMs?: number;
|
|
@@ -16,6 +17,7 @@ export declare namespace Fetcher {
|
|
|
16
17
|
requestType?: "json" | "file" | "bytes";
|
|
17
18
|
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
18
19
|
duplex?: "half";
|
|
20
|
+
endpointMetadata?: EndpointMetadata;
|
|
19
21
|
}
|
|
20
22
|
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
21
23
|
interface FailedStatusCodeError {
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { toJson } from "../json.mjs";
|
|
11
11
|
import { createRequestUrl } from "./createRequestUrl.mjs";
|
|
12
|
+
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
12
13
|
import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
|
|
13
14
|
import { getFetchFn } from "./getFetchFn.mjs";
|
|
14
15
|
import { getRequestBody } from "./getRequestBody.mjs";
|
|
@@ -16,9 +17,9 @@ import { getResponseBody } from "./getResponseBody.mjs";
|
|
|
16
17
|
import { makeRequest } from "./makeRequest.mjs";
|
|
17
18
|
import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
18
19
|
import { requestWithRetries } from "./requestWithRetries.mjs";
|
|
19
|
-
import { Supplier } from "./Supplier.mjs";
|
|
20
20
|
function getHeaders(args) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
var _a;
|
|
22
23
|
const newHeaders = {};
|
|
23
24
|
if (args.body !== undefined && args.contentType != null) {
|
|
24
25
|
newHeaders["Content-Type"] = args.contentType;
|
|
@@ -27,7 +28,7 @@ function getHeaders(args) {
|
|
|
27
28
|
return newHeaders;
|
|
28
29
|
}
|
|
29
30
|
for (const [key, value] of Object.entries(args.headers)) {
|
|
30
|
-
const result = yield
|
|
31
|
+
const result = yield EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
|
|
31
32
|
if (typeof result === "string") {
|
|
32
33
|
newHeaders[key] = result;
|
|
33
34
|
continue;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type { APIResponse } from "./APIResponse.mjs";
|
|
2
2
|
export type { BinaryResponse } from "./BinaryResponse.mjs";
|
|
3
|
+
export type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
4
|
+
export { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
3
5
|
export type { Fetcher, FetchFunction } from "./Fetcher.mjs";
|
|
4
6
|
export { fetcher } from "./Fetcher.mjs";
|
|
5
7
|
export { getHeader } from "./getHeader.mjs";
|
|
@@ -11,21 +11,57 @@ const INITIAL_RETRY_DELAY = 1000; // in milliseconds
|
|
|
11
11
|
const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
12
12
|
const DEFAULT_MAX_RETRIES = 2;
|
|
13
13
|
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
14
|
-
function
|
|
15
|
-
// Generate a random value between
|
|
16
|
-
const jitterMultiplier = 1 +
|
|
14
|
+
function addPositiveJitter(delay) {
|
|
15
|
+
// Generate a random value between 0 and +JITTER_FACTOR
|
|
16
|
+
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
17
17
|
return delay * jitterMultiplier;
|
|
18
18
|
}
|
|
19
|
+
function addSymmetricJitter(delay) {
|
|
20
|
+
// Generate a random value in a JITTER_FACTOR-sized percentage range around delay
|
|
21
|
+
const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
|
|
22
|
+
return delay * jitterMultiplier;
|
|
23
|
+
}
|
|
24
|
+
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
25
|
+
// Check for Retry-After header first (RFC 7231), with no jitter
|
|
26
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
27
|
+
if (retryAfter) {
|
|
28
|
+
// Parse as number of seconds...
|
|
29
|
+
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
30
|
+
if (!isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
31
|
+
return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
|
|
32
|
+
}
|
|
33
|
+
// ...or as an HTTP date; both are valid
|
|
34
|
+
const retryAfterDate = new Date(retryAfter);
|
|
35
|
+
if (!isNaN(retryAfterDate.getTime())) {
|
|
36
|
+
const delay = retryAfterDate.getTime() - Date.now();
|
|
37
|
+
if (delay > 0) {
|
|
38
|
+
return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Then check for industry-standard X-RateLimit-Reset header, with positive jitter
|
|
43
|
+
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
44
|
+
if (rateLimitReset) {
|
|
45
|
+
const resetTime = parseInt(rateLimitReset, 10);
|
|
46
|
+
if (!isNaN(resetTime)) {
|
|
47
|
+
// Assume Unix timestamp in epoch seconds
|
|
48
|
+
const delay = resetTime * 1000 - Date.now();
|
|
49
|
+
if (delay > 0) {
|
|
50
|
+
return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Fall back to exponential backoff, with symmetric jitter
|
|
55
|
+
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
56
|
+
}
|
|
19
57
|
export function requestWithRetries(requestFn_1) {
|
|
20
58
|
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
21
59
|
let response = yield requestFn();
|
|
22
60
|
for (let i = 0; i < maxRetries; ++i) {
|
|
23
61
|
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
24
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const delayWithJitter = addJitter(baseDelay);
|
|
28
|
-
yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
|
|
62
|
+
// Get delay with appropriate jitter applied
|
|
63
|
+
const delay = getRetryDelayFromHeaders(response, i);
|
|
64
|
+
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
29
65
|
response = yield requestFn();
|
|
30
66
|
}
|
|
31
67
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Uploadable } from "./types.mjs";
|
|
1
|
+
export type { Uploadable } from "./types.mjs";
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
|
|
1
|
+
export declare function mergeHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, string | THeaderValue>;
|
|
2
|
+
export declare function mergeOnlyDefinedHeaders<THeaderValue>(...headersArray: (Record<string, THeaderValue> | null | undefined)[]): Record<string, THeaderValue>;
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.0";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "1.0.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markupai/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": "github:markupai/markup-ai-typescript-sdk",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,23 +31,18 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"format": "prettier . --write --ignore-unknown",
|
|
34
|
-
"build": "
|
|
34
|
+
"build": "pnpm build:cjs && pnpm build:esm",
|
|
35
35
|
"build:cjs": "tsc --project ./tsconfig.cjs.json",
|
|
36
36
|
"build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
|
|
37
|
-
"test": "
|
|
38
|
-
"test:unit": "
|
|
39
|
-
"test:
|
|
40
|
-
"test:wire": "jest --selectProjects wire"
|
|
37
|
+
"test": "vitest",
|
|
38
|
+
"test:unit": "vitest --project unit",
|
|
39
|
+
"test:wire": "vitest --project wire"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"webpack": "^5.97.1",
|
|
44
43
|
"ts-loader": "^9.5.1",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"@types/jest": "^29.5.14",
|
|
48
|
-
"ts-jest": "^29.3.4",
|
|
49
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
50
|
-
"msw": "^2.8.4",
|
|
44
|
+
"vitest": "^3.2.4",
|
|
45
|
+
"msw": "2.11.2",
|
|
51
46
|
"@types/node": "^18.19.70",
|
|
52
47
|
"prettier": "^3.4.2",
|
|
53
48
|
"typescript": "~5.7.2"
|
|
@@ -58,7 +53,7 @@
|
|
|
58
53
|
"path": false,
|
|
59
54
|
"stream": false
|
|
60
55
|
},
|
|
61
|
-
"packageManager": "
|
|
56
|
+
"packageManager": "pnpm@10.14.0",
|
|
62
57
|
"engines": {
|
|
63
58
|
"node": ">=18.0.0"
|
|
64
59
|
},
|