@relayapi/sdk 0.2.2
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/api-promise.d.ts +2 -0
- package/dist/api-promise.js +18 -0
- package/dist/client.d.ts +225 -0
- package/dist/client.js +552 -0
- package/dist/core/api-promise.d.ts +45 -0
- package/dist/core/api-promise.js +83 -0
- package/dist/core/error.d.ts +45 -0
- package/dist/core/error.js +112 -0
- package/dist/core/resource.d.ts +5 -0
- package/dist/core/resource.js +10 -0
- package/dist/core/uploads.d.ts +2 -0
- package/dist/core/uploads.js +5 -0
- package/dist/error.d.ts +2 -0
- package/dist/error.js +18 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +26 -0
- package/dist/internal/builtin-types.d.ts +72 -0
- package/dist/internal/builtin-types.js +3 -0
- package/dist/internal/detect-platform.d.ts +14 -0
- package/dist/internal/detect-platform.js +161 -0
- package/dist/internal/errors.d.ts +2 -0
- package/dist/internal/errors.js +40 -0
- package/dist/internal/headers.d.ts +19 -0
- package/dist/internal/headers.js +78 -0
- package/dist/internal/parse.d.ts +11 -0
- package/dist/internal/parse.js +39 -0
- package/dist/internal/request-options.d.ts +74 -0
- package/dist/internal/request-options.js +13 -0
- package/dist/internal/shim-types.d.ts +16 -0
- package/dist/internal/shim-types.js +3 -0
- package/dist/internal/shims.d.ts +23 -0
- package/dist/internal/shims.js +90 -0
- package/dist/internal/to-file.d.ts +44 -0
- package/dist/internal/to-file.js +90 -0
- package/dist/internal/types.d.ts +68 -0
- package/dist/internal/types.js +3 -0
- package/dist/internal/uploads.d.ts +41 -0
- package/dist/internal/uploads.js +140 -0
- package/dist/internal/utils/base64.d.ts +2 -0
- package/dist/internal/utils/base64.js +37 -0
- package/dist/internal/utils/bytes.d.ts +3 -0
- package/dist/internal/utils/bytes.js +30 -0
- package/dist/internal/utils/env.d.ts +8 -0
- package/dist/internal/utils/env.js +21 -0
- package/dist/internal/utils/log.d.ts +36 -0
- package/dist/internal/utils/log.js +84 -0
- package/dist/internal/utils/path.d.ts +14 -0
- package/dist/internal/utils/path.js +78 -0
- package/dist/internal/utils/query.d.ts +4 -0
- package/dist/internal/utils/query.js +22 -0
- package/dist/internal/utils/sleep.d.ts +1 -0
- package/dist/internal/utils/sleep.js +6 -0
- package/dist/internal/utils/uuid.d.ts +4 -0
- package/dist/internal/utils/uuid.js +18 -0
- package/dist/internal/utils/values.d.ts +17 -0
- package/dist/internal/utils/values.js +111 -0
- package/dist/internal/utils.d.ts +7 -0
- package/dist/internal/utils.js +24 -0
- package/dist/resource.d.ts +2 -0
- package/dist/resource.js +18 -0
- package/dist/resources/account-groups.d.ts +52 -0
- package/dist/resources/account-groups.js +37 -0
- package/dist/resources/accounts/accounts.d.ts +148 -0
- package/dist/resources/accounts/accounts.js +101 -0
- package/dist/resources/accounts/facebook-pages.d.ts +48 -0
- package/dist/resources/accounts/facebook-pages.js +21 -0
- package/dist/resources/accounts/gmb-locations.d.ts +48 -0
- package/dist/resources/accounts/gmb-locations.js +21 -0
- package/dist/resources/accounts/health.d.ts +49 -0
- package/dist/resources/accounts/health.js +21 -0
- package/dist/resources/accounts/index.d.ts +8 -0
- package/dist/resources/accounts/index.js +20 -0
- package/dist/resources/accounts/linkedin-organizations.d.ts +52 -0
- package/dist/resources/accounts/linkedin-organizations.js +21 -0
- package/dist/resources/accounts/pinterest-boards.d.ts +48 -0
- package/dist/resources/accounts/pinterest-boards.js +21 -0
- package/dist/resources/accounts/reddit-flairs.d.ts +27 -0
- package/dist/resources/accounts/reddit-flairs.js +15 -0
- package/dist/resources/accounts/reddit-subreddits.d.ts +48 -0
- package/dist/resources/accounts/reddit-subreddits.js +21 -0
- package/dist/resources/accounts.d.ts +1 -0
- package/dist/resources/accounts.js +18 -0
- package/dist/resources/analytics/analytics.d.ts +369 -0
- package/dist/resources/analytics/analytics.js +84 -0
- package/dist/resources/analytics/index.d.ts +2 -0
- package/dist/resources/analytics/index.js +8 -0
- package/dist/resources/analytics/youtube.d.ts +49 -0
- package/dist/resources/analytics/youtube.js +14 -0
- package/dist/resources/analytics.d.ts +1 -0
- package/dist/resources/analytics.js +18 -0
- package/dist/resources/api-keys.d.ts +110 -0
- package/dist/resources/api-keys.js +32 -0
- package/dist/resources/connect/connect.d.ts +188 -0
- package/dist/resources/connect/connect.js +97 -0
- package/dist/resources/connect/facebook/facebook.d.ts +9 -0
- package/dist/resources/connect/facebook/facebook.js +48 -0
- package/dist/resources/connect/facebook/index.d.ts +2 -0
- package/dist/resources/connect/facebook/index.js +8 -0
- package/dist/resources/connect/facebook/pages.d.ts +70 -0
- package/dist/resources/connect/facebook/pages.js +20 -0
- package/dist/resources/connect/facebook.d.ts +1 -0
- package/dist/resources/connect/facebook.js +18 -0
- package/dist/resources/connect/googlebusiness/googlebusiness.d.ts +9 -0
- package/dist/resources/connect/googlebusiness/googlebusiness.js +48 -0
- package/dist/resources/connect/googlebusiness/index.d.ts +2 -0
- package/dist/resources/connect/googlebusiness/index.js +8 -0
- package/dist/resources/connect/googlebusiness/locations.d.ts +70 -0
- package/dist/resources/connect/googlebusiness/locations.js +20 -0
- package/dist/resources/connect/googlebusiness.d.ts +1 -0
- package/dist/resources/connect/googlebusiness.js +18 -0
- package/dist/resources/connect/index.d.ts +8 -0
- package/dist/resources/connect/index.js +20 -0
- package/dist/resources/connect/linkedin/index.d.ts +2 -0
- package/dist/resources/connect/linkedin/index.js +8 -0
- package/dist/resources/connect/linkedin/linkedin.d.ts +9 -0
- package/dist/resources/connect/linkedin/linkedin.js +48 -0
- package/dist/resources/connect/linkedin/organizations.d.ts +85 -0
- package/dist/resources/connect/linkedin/organizations.js +20 -0
- package/dist/resources/connect/linkedin.d.ts +1 -0
- package/dist/resources/connect/linkedin.js +18 -0
- package/dist/resources/connect/pinterest/boards.d.ts +70 -0
- package/dist/resources/connect/pinterest/boards.js +20 -0
- package/dist/resources/connect/pinterest/index.d.ts +2 -0
- package/dist/resources/connect/pinterest/index.js +8 -0
- package/dist/resources/connect/pinterest/pinterest.d.ts +9 -0
- package/dist/resources/connect/pinterest/pinterest.js +48 -0
- package/dist/resources/connect/pinterest.d.ts +1 -0
- package/dist/resources/connect/pinterest.js +18 -0
- package/dist/resources/connect/snapchat/index.d.ts +2 -0
- package/dist/resources/connect/snapchat/index.js +8 -0
- package/dist/resources/connect/snapchat/profiles.d.ts +74 -0
- package/dist/resources/connect/snapchat/profiles.js +20 -0
- package/dist/resources/connect/snapchat/snapchat.d.ts +9 -0
- package/dist/resources/connect/snapchat/snapchat.js +48 -0
- package/dist/resources/connect/snapchat.d.ts +1 -0
- package/dist/resources/connect/snapchat.js +18 -0
- package/dist/resources/connect/telegram.d.ts +122 -0
- package/dist/resources/connect/telegram.js +26 -0
- package/dist/resources/connect/whatsapp.d.ts +92 -0
- package/dist/resources/connect/whatsapp.js +26 -0
- package/dist/resources/connect.d.ts +1 -0
- package/dist/resources/connect.js +18 -0
- package/dist/resources/connections.d.ts +55 -0
- package/dist/resources/connections.js +14 -0
- package/dist/resources/inbox/comments/comments.d.ts +220 -0
- package/dist/resources/inbox/comments/comments.js +83 -0
- package/dist/resources/inbox/comments/hide.d.ts +36 -0
- package/dist/resources/inbox/comments/hide.js +21 -0
- package/dist/resources/inbox/comments/index.d.ts +3 -0
- package/dist/resources/inbox/comments/index.js +10 -0
- package/dist/resources/inbox/comments/like.d.ts +36 -0
- package/dist/resources/inbox/comments/like.js +21 -0
- package/dist/resources/inbox/comments.d.ts +1 -0
- package/dist/resources/inbox/comments.js +18 -0
- package/dist/resources/inbox/inbox.d.ts +17 -0
- package/dist/resources/inbox/inbox.js +56 -0
- package/dist/resources/inbox/index.d.ts +4 -0
- package/dist/resources/inbox/index.js +12 -0
- package/dist/resources/inbox/messages.d.ts +205 -0
- package/dist/resources/inbox/messages.js +40 -0
- package/dist/resources/inbox/reviews/index.d.ts +2 -0
- package/dist/resources/inbox/reviews/index.js +8 -0
- package/dist/resources/inbox/reviews/reply.d.ts +38 -0
- package/dist/resources/inbox/reviews/reply.js +21 -0
- package/dist/resources/inbox/reviews/reviews.d.ts +76 -0
- package/dist/resources/inbox/reviews/reviews.js +54 -0
- package/dist/resources/inbox/reviews.d.ts +1 -0
- package/dist/resources/inbox/reviews.js +18 -0
- package/dist/resources/inbox.d.ts +1 -0
- package/dist/resources/inbox.js +18 -0
- package/dist/resources/index.d.ts +16 -0
- package/dist/resources/index.js +36 -0
- package/dist/resources/media.d.ts +177 -0
- package/dist/resources/media.js +51 -0
- package/dist/resources/posts/index.d.ts +2 -0
- package/dist/resources/posts/index.js +8 -0
- package/dist/resources/posts/logs.d.ts +134 -0
- package/dist/resources/posts/logs.js +31 -0
- package/dist/resources/posts/posts.d.ts +607 -0
- package/dist/resources/posts/posts.js +149 -0
- package/dist/resources/posts.d.ts +1 -0
- package/dist/resources/posts.js +18 -0
- package/dist/resources/queue/index.d.ts +2 -0
- package/dist/resources/queue/index.js +8 -0
- package/dist/resources/queue/queue.d.ts +42 -0
- package/dist/resources/queue/queue.js +60 -0
- package/dist/resources/queue/slots.d.ts +215 -0
- package/dist/resources/queue/slots.js +36 -0
- package/dist/resources/queue.d.ts +1 -0
- package/dist/resources/queue.js +18 -0
- package/dist/resources/reddit.d.ts +186 -0
- package/dist/resources/reddit.js +20 -0
- package/dist/resources/tools/index.d.ts +3 -0
- package/dist/resources/tools/index.js +10 -0
- package/dist/resources/tools/instagram.d.ts +41 -0
- package/dist/resources/tools/instagram.js +22 -0
- package/dist/resources/tools/tools.d.ts +13 -0
- package/dist/resources/tools/tools.js +52 -0
- package/dist/resources/tools/validate.d.ts +689 -0
- package/dist/resources/tools/validate.js +63 -0
- package/dist/resources/tools.d.ts +1 -0
- package/dist/resources/tools.js +18 -0
- package/dist/resources/twitter/bookmark.d.ts +48 -0
- package/dist/resources/twitter/bookmark.js +20 -0
- package/dist/resources/twitter/follow.d.ts +48 -0
- package/dist/resources/twitter/follow.js +20 -0
- package/dist/resources/twitter/index.d.ts +4 -0
- package/dist/resources/twitter/index.js +12 -0
- package/dist/resources/twitter/retweet.d.ts +48 -0
- package/dist/resources/twitter/retweet.js +20 -0
- package/dist/resources/twitter/twitter.d.ts +17 -0
- package/dist/resources/twitter/twitter.js +56 -0
- package/dist/resources/twitter.d.ts +1 -0
- package/dist/resources/twitter.js +18 -0
- package/dist/resources/usage.d.ts +97 -0
- package/dist/resources/usage.js +14 -0
- package/dist/resources/webhooks.d.ts +205 -0
- package/dist/resources/webhooks.js +50 -0
- package/dist/resources/whatsapp/broadcasts.d.ts +291 -0
- package/dist/resources/whatsapp/broadcasts.js +49 -0
- package/dist/resources/whatsapp/business-profile.d.ts +85 -0
- package/dist/resources/whatsapp/business-profile.js +20 -0
- package/dist/resources/whatsapp/contacts.d.ts +250 -0
- package/dist/resources/whatsapp/contacts.js +49 -0
- package/dist/resources/whatsapp/groups.d.ts +87 -0
- package/dist/resources/whatsapp/groups.js +31 -0
- package/dist/resources/whatsapp/index.d.ts +6 -0
- package/dist/resources/whatsapp/index.js +16 -0
- package/dist/resources/whatsapp/templates.d.ts +250 -0
- package/dist/resources/whatsapp/templates.js +39 -0
- package/dist/resources/whatsapp/whatsapp.d.ts +148 -0
- package/dist/resources/whatsapp/whatsapp.js +76 -0
- package/dist/resources/whatsapp.d.ts +1 -0
- package/dist/resources/whatsapp.js +18 -0
- package/dist/resources.d.ts +1 -0
- package/dist/resources.js +17 -0
- package/dist/uploads.d.ts +2 -0
- package/dist/uploads.js +18 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/package.json +28 -0
- package/src/index.ts +22 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare class RelayError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class APIError<TStatus extends number | undefined = number | undefined, THeaders extends Headers | undefined = Headers | undefined, TError extends Object | undefined = Object | undefined> extends RelayError {
|
|
4
|
+
/** HTTP status for the response that caused the error */
|
|
5
|
+
readonly status: TStatus;
|
|
6
|
+
/** HTTP headers for the response that caused the error */
|
|
7
|
+
readonly headers: THeaders;
|
|
8
|
+
/** JSON body of the response that caused the error */
|
|
9
|
+
readonly error: TError;
|
|
10
|
+
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders);
|
|
11
|
+
private static makeMessage;
|
|
12
|
+
static generate(status: number | undefined, errorResponse: Object | undefined, message: string | undefined, headers: Headers | undefined): APIError;
|
|
13
|
+
}
|
|
14
|
+
export declare class APIUserAbortError extends APIError<undefined, undefined, undefined> {
|
|
15
|
+
constructor({ message }?: {
|
|
16
|
+
message?: string;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export declare class APIConnectionError extends APIError<undefined, undefined, undefined> {
|
|
20
|
+
constructor({ message, cause }: {
|
|
21
|
+
message?: string | undefined;
|
|
22
|
+
cause?: Error | undefined;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export declare class APIConnectionTimeoutError extends APIConnectionError {
|
|
26
|
+
constructor({ message }?: {
|
|
27
|
+
message?: string;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export declare class BadRequestError extends APIError<400, Headers> {
|
|
31
|
+
}
|
|
32
|
+
export declare class AuthenticationError extends APIError<401, Headers> {
|
|
33
|
+
}
|
|
34
|
+
export declare class PermissionDeniedError extends APIError<403, Headers> {
|
|
35
|
+
}
|
|
36
|
+
export declare class NotFoundError extends APIError<404, Headers> {
|
|
37
|
+
}
|
|
38
|
+
export declare class ConflictError extends APIError<409, Headers> {
|
|
39
|
+
}
|
|
40
|
+
export declare class UnprocessableEntityError extends APIError<422, Headers> {
|
|
41
|
+
}
|
|
42
|
+
export declare class RateLimitError extends APIError<429, Headers> {
|
|
43
|
+
}
|
|
44
|
+
export declare class InternalServerError extends APIError<number, Headers> {
|
|
45
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIUserAbortError = exports.APIError = exports.RelayError = void 0;
|
|
5
|
+
const errors_1 = require("../internal/errors");
|
|
6
|
+
class RelayError extends Error {
|
|
7
|
+
}
|
|
8
|
+
exports.RelayError = RelayError;
|
|
9
|
+
class APIError extends RelayError {
|
|
10
|
+
constructor(status, error, message, headers) {
|
|
11
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.headers = headers;
|
|
14
|
+
this.error = error;
|
|
15
|
+
}
|
|
16
|
+
static makeMessage(status, error, message) {
|
|
17
|
+
const msg = error?.message ?
|
|
18
|
+
typeof error.message === 'string' ?
|
|
19
|
+
error.message
|
|
20
|
+
: JSON.stringify(error.message)
|
|
21
|
+
: error ? JSON.stringify(error)
|
|
22
|
+
: message;
|
|
23
|
+
if (status && msg) {
|
|
24
|
+
return `${status} ${msg}`;
|
|
25
|
+
}
|
|
26
|
+
if (status) {
|
|
27
|
+
return `${status} status code (no body)`;
|
|
28
|
+
}
|
|
29
|
+
if (msg) {
|
|
30
|
+
return msg;
|
|
31
|
+
}
|
|
32
|
+
return '(no status code or body)';
|
|
33
|
+
}
|
|
34
|
+
static generate(status, errorResponse, message, headers) {
|
|
35
|
+
if (!status || !headers) {
|
|
36
|
+
return new APIConnectionError({ message, cause: (0, errors_1.castToError)(errorResponse) });
|
|
37
|
+
}
|
|
38
|
+
const error = errorResponse;
|
|
39
|
+
if (status === 400) {
|
|
40
|
+
return new BadRequestError(status, error, message, headers);
|
|
41
|
+
}
|
|
42
|
+
if (status === 401) {
|
|
43
|
+
return new AuthenticationError(status, error, message, headers);
|
|
44
|
+
}
|
|
45
|
+
if (status === 403) {
|
|
46
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
47
|
+
}
|
|
48
|
+
if (status === 404) {
|
|
49
|
+
return new NotFoundError(status, error, message, headers);
|
|
50
|
+
}
|
|
51
|
+
if (status === 409) {
|
|
52
|
+
return new ConflictError(status, error, message, headers);
|
|
53
|
+
}
|
|
54
|
+
if (status === 422) {
|
|
55
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
56
|
+
}
|
|
57
|
+
if (status === 429) {
|
|
58
|
+
return new RateLimitError(status, error, message, headers);
|
|
59
|
+
}
|
|
60
|
+
if (status >= 500) {
|
|
61
|
+
return new InternalServerError(status, error, message, headers);
|
|
62
|
+
}
|
|
63
|
+
return new APIError(status, error, message, headers);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.APIError = APIError;
|
|
67
|
+
class APIUserAbortError extends APIError {
|
|
68
|
+
constructor({ message } = {}) {
|
|
69
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.APIUserAbortError = APIUserAbortError;
|
|
73
|
+
class APIConnectionError extends APIError {
|
|
74
|
+
constructor({ message, cause }) {
|
|
75
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
76
|
+
// in some environments the 'cause' property is already declared
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
if (cause)
|
|
79
|
+
this.cause = cause;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.APIConnectionError = APIConnectionError;
|
|
83
|
+
class APIConnectionTimeoutError extends APIConnectionError {
|
|
84
|
+
constructor({ message } = {}) {
|
|
85
|
+
super({ message: message ?? 'Request timed out.' });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.APIConnectionTimeoutError = APIConnectionTimeoutError;
|
|
89
|
+
class BadRequestError extends APIError {
|
|
90
|
+
}
|
|
91
|
+
exports.BadRequestError = BadRequestError;
|
|
92
|
+
class AuthenticationError extends APIError {
|
|
93
|
+
}
|
|
94
|
+
exports.AuthenticationError = AuthenticationError;
|
|
95
|
+
class PermissionDeniedError extends APIError {
|
|
96
|
+
}
|
|
97
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
98
|
+
class NotFoundError extends APIError {
|
|
99
|
+
}
|
|
100
|
+
exports.NotFoundError = NotFoundError;
|
|
101
|
+
class ConflictError extends APIError {
|
|
102
|
+
}
|
|
103
|
+
exports.ConflictError = ConflictError;
|
|
104
|
+
class UnprocessableEntityError extends APIError {
|
|
105
|
+
}
|
|
106
|
+
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
107
|
+
class RateLimitError extends APIError {
|
|
108
|
+
}
|
|
109
|
+
exports.RateLimitError = RateLimitError;
|
|
110
|
+
class InternalServerError extends APIError {
|
|
111
|
+
}
|
|
112
|
+
exports.InternalServerError = InternalServerError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.APIResource = void 0;
|
|
5
|
+
class APIResource {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this._client = client;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.APIResource = APIResource;
|
package/dist/error.d.ts
ADDED
package/dist/error.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/** @deprecated Import from ./core/error instead */
|
|
18
|
+
__exportStar(require("./core/error"), exports);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Relay as default } from './client';
|
|
2
|
+
export { type Uploadable, toFile } from './core/uploads';
|
|
3
|
+
export { APIPromise } from './core/api-promise';
|
|
4
|
+
export { Relay, type ClientOptions } from './client';
|
|
5
|
+
export { RelayError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from './core/error';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.RelayError = exports.Relay = exports.APIPromise = exports.toFile = exports.default = void 0;
|
|
5
|
+
var client_1 = require("./client");
|
|
6
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_1.Relay; } });
|
|
7
|
+
var uploads_1 = require("./core/uploads");
|
|
8
|
+
Object.defineProperty(exports, "toFile", { enumerable: true, get: function () { return uploads_1.toFile; } });
|
|
9
|
+
var api_promise_1 = require("./core/api-promise");
|
|
10
|
+
Object.defineProperty(exports, "APIPromise", { enumerable: true, get: function () { return api_promise_1.APIPromise; } });
|
|
11
|
+
var client_2 = require("./client");
|
|
12
|
+
Object.defineProperty(exports, "Relay", { enumerable: true, get: function () { return client_2.Relay; } });
|
|
13
|
+
var error_1 = require("./core/error");
|
|
14
|
+
Object.defineProperty(exports, "RelayError", { enumerable: true, get: function () { return error_1.RelayError; } });
|
|
15
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return error_1.APIError; } });
|
|
16
|
+
Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return error_1.APIConnectionError; } });
|
|
17
|
+
Object.defineProperty(exports, "APIConnectionTimeoutError", { enumerable: true, get: function () { return error_1.APIConnectionTimeoutError; } });
|
|
18
|
+
Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return error_1.APIUserAbortError; } });
|
|
19
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return error_1.NotFoundError; } });
|
|
20
|
+
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return error_1.ConflictError; } });
|
|
21
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_1.RateLimitError; } });
|
|
22
|
+
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return error_1.BadRequestError; } });
|
|
23
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return error_1.AuthenticationError; } });
|
|
24
|
+
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_1.InternalServerError; } });
|
|
25
|
+
Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return error_1.PermissionDeniedError; } });
|
|
26
|
+
Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return error_1.UnprocessableEntityError; } });
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
/**
|
|
3
|
+
* An alias to the builtin `RequestInit` type so we can
|
|
4
|
+
* easily alias it in import statements if there are name clashes.
|
|
5
|
+
*
|
|
6
|
+
* https://developer.mozilla.org/docs/Web/API/RequestInit
|
|
7
|
+
*/
|
|
8
|
+
type _RequestInit = RequestInit;
|
|
9
|
+
/**
|
|
10
|
+
* An alias to the builtin `Response` type so we can
|
|
11
|
+
* easily alias it in import statements if there are name clashes.
|
|
12
|
+
*
|
|
13
|
+
* https://developer.mozilla.org/docs/Web/API/Response
|
|
14
|
+
*/
|
|
15
|
+
type _Response = Response;
|
|
16
|
+
/**
|
|
17
|
+
* The type for the first argument to `fetch`.
|
|
18
|
+
*
|
|
19
|
+
* https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
|
|
20
|
+
*/
|
|
21
|
+
type _RequestInfo = Request | URL | string;
|
|
22
|
+
/**
|
|
23
|
+
* The type for constructing `RequestInit` Headers.
|
|
24
|
+
*
|
|
25
|
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
|
|
26
|
+
*/
|
|
27
|
+
type _HeadersInit = RequestInit['headers'];
|
|
28
|
+
/**
|
|
29
|
+
* The type for constructing `RequestInit` body.
|
|
30
|
+
*
|
|
31
|
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#body
|
|
32
|
+
*/
|
|
33
|
+
type _BodyInit = RequestInit['body'];
|
|
34
|
+
/**
|
|
35
|
+
* An alias to the builtin `Array<T>` type so we can
|
|
36
|
+
* easily alias it in import statements if there are name clashes.
|
|
37
|
+
*/
|
|
38
|
+
type _Array<T> = Array<T>;
|
|
39
|
+
/**
|
|
40
|
+
* An alias to the builtin `Record<K, T>` type so we can
|
|
41
|
+
* easily alias it in import statements if there are name clashes.
|
|
42
|
+
*/
|
|
43
|
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
|
44
|
+
export type { _Array as Array, _BodyInit as BodyInit, _HeadersInit as HeadersInit, _Record as Record, _RequestInfo as RequestInfo, _RequestInit as RequestInit, _Response as Response, };
|
|
45
|
+
/**
|
|
46
|
+
* A copy of the builtin `EndingType` type as it isn't fully supported in certain
|
|
47
|
+
* environments and attempting to reference the global version will error.
|
|
48
|
+
*
|
|
49
|
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
|
|
50
|
+
*/
|
|
51
|
+
type EndingType = 'native' | 'transparent';
|
|
52
|
+
/**
|
|
53
|
+
* A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
|
|
54
|
+
* environments and attempting to reference the global version will error.
|
|
55
|
+
*
|
|
56
|
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
|
|
57
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
|
|
58
|
+
*/
|
|
59
|
+
export interface BlobPropertyBag {
|
|
60
|
+
endings?: EndingType;
|
|
61
|
+
type?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
|
|
65
|
+
* environments and attempting to reference the global version will error.
|
|
66
|
+
*
|
|
67
|
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
|
|
68
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
|
|
69
|
+
*/
|
|
70
|
+
export interface FilePropertyBag extends BlobPropertyBag {
|
|
71
|
+
lastModified?: number;
|
|
72
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const isRunningInBrowser: () => boolean;
|
|
2
|
+
type Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';
|
|
3
|
+
type PlatformName = 'MacOS' | 'Linux' | 'Windows' | 'FreeBSD' | 'OpenBSD' | 'iOS' | 'Android' | `Other:${string}` | 'Unknown';
|
|
4
|
+
type Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';
|
|
5
|
+
type PlatformProperties = {
|
|
6
|
+
'X-Stainless-Lang': 'js';
|
|
7
|
+
'X-Stainless-Package-Version': string;
|
|
8
|
+
'X-Stainless-OS': PlatformName;
|
|
9
|
+
'X-Stainless-Arch': Arch;
|
|
10
|
+
'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';
|
|
11
|
+
'X-Stainless-Runtime-Version': string;
|
|
12
|
+
};
|
|
13
|
+
export declare const getPlatformHeaders: () => PlatformProperties;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getPlatformHeaders = exports.isRunningInBrowser = void 0;
|
|
5
|
+
const version_1 = require("../version");
|
|
6
|
+
const isRunningInBrowser = () => {
|
|
7
|
+
return (
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
typeof window !== 'undefined' &&
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
typeof window.document !== 'undefined' &&
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
typeof navigator !== 'undefined');
|
|
14
|
+
};
|
|
15
|
+
exports.isRunningInBrowser = isRunningInBrowser;
|
|
16
|
+
/**
|
|
17
|
+
* Note this does not detect 'browser'; for that, use getBrowserInfo().
|
|
18
|
+
*/
|
|
19
|
+
function getDetectedPlatform() {
|
|
20
|
+
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
|
21
|
+
return 'deno';
|
|
22
|
+
}
|
|
23
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
24
|
+
return 'edge';
|
|
25
|
+
}
|
|
26
|
+
if (Object.prototype.toString.call(typeof globalThis.process !== 'undefined' ? globalThis.process : 0) === '[object process]') {
|
|
27
|
+
return 'node';
|
|
28
|
+
}
|
|
29
|
+
return 'unknown';
|
|
30
|
+
}
|
|
31
|
+
const getPlatformProperties = () => {
|
|
32
|
+
const detectedPlatform = getDetectedPlatform();
|
|
33
|
+
if (detectedPlatform === 'deno') {
|
|
34
|
+
return {
|
|
35
|
+
'X-Stainless-Lang': 'js',
|
|
36
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
37
|
+
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
|
38
|
+
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
|
39
|
+
'X-Stainless-Runtime': 'deno',
|
|
40
|
+
'X-Stainless-Runtime-Version': typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
44
|
+
return {
|
|
45
|
+
'X-Stainless-Lang': 'js',
|
|
46
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
47
|
+
'X-Stainless-OS': 'Unknown',
|
|
48
|
+
'X-Stainless-Arch': `other:${EdgeRuntime}`,
|
|
49
|
+
'X-Stainless-Runtime': 'edge',
|
|
50
|
+
'X-Stainless-Runtime-Version': globalThis.process.version,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Check if Node.js
|
|
54
|
+
if (detectedPlatform === 'node') {
|
|
55
|
+
return {
|
|
56
|
+
'X-Stainless-Lang': 'js',
|
|
57
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
58
|
+
'X-Stainless-OS': normalizePlatform(globalThis.process.platform ?? 'unknown'),
|
|
59
|
+
'X-Stainless-Arch': normalizeArch(globalThis.process.arch ?? 'unknown'),
|
|
60
|
+
'X-Stainless-Runtime': 'node',
|
|
61
|
+
'X-Stainless-Runtime-Version': globalThis.process.version ?? 'unknown',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const browserInfo = getBrowserInfo();
|
|
65
|
+
if (browserInfo) {
|
|
66
|
+
return {
|
|
67
|
+
'X-Stainless-Lang': 'js',
|
|
68
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
69
|
+
'X-Stainless-OS': 'Unknown',
|
|
70
|
+
'X-Stainless-Arch': 'unknown',
|
|
71
|
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
|
72
|
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// TODO add support for Cloudflare workers, etc.
|
|
76
|
+
return {
|
|
77
|
+
'X-Stainless-Lang': 'js',
|
|
78
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
79
|
+
'X-Stainless-OS': 'Unknown',
|
|
80
|
+
'X-Stainless-Arch': 'unknown',
|
|
81
|
+
'X-Stainless-Runtime': 'unknown',
|
|
82
|
+
'X-Stainless-Runtime-Version': 'unknown',
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
|
86
|
+
function getBrowserInfo() {
|
|
87
|
+
if (typeof navigator === 'undefined' || !navigator) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
// NOTE: The order matters here!
|
|
91
|
+
const browserPatterns = [
|
|
92
|
+
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
93
|
+
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
94
|
+
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
95
|
+
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
96
|
+
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
97
|
+
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
98
|
+
];
|
|
99
|
+
// Find the FIRST matching browser
|
|
100
|
+
for (const { key, pattern } of browserPatterns) {
|
|
101
|
+
const match = pattern.exec(navigator.userAgent);
|
|
102
|
+
if (match) {
|
|
103
|
+
const major = match[1] || 0;
|
|
104
|
+
const minor = match[2] || 0;
|
|
105
|
+
const patch = match[3] || 0;
|
|
106
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const normalizeArch = (arch) => {
|
|
112
|
+
// Node docs:
|
|
113
|
+
// - https://nodejs.org/api/process.html#processarch
|
|
114
|
+
// Deno docs:
|
|
115
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
116
|
+
if (arch === 'x32')
|
|
117
|
+
return 'x32';
|
|
118
|
+
if (arch === 'x86_64' || arch === 'x64')
|
|
119
|
+
return 'x64';
|
|
120
|
+
if (arch === 'arm')
|
|
121
|
+
return 'arm';
|
|
122
|
+
if (arch === 'aarch64' || arch === 'arm64')
|
|
123
|
+
return 'arm64';
|
|
124
|
+
if (arch)
|
|
125
|
+
return `other:${arch}`;
|
|
126
|
+
return 'unknown';
|
|
127
|
+
};
|
|
128
|
+
const normalizePlatform = (platform) => {
|
|
129
|
+
// Node platforms:
|
|
130
|
+
// - https://nodejs.org/api/process.html#processplatform
|
|
131
|
+
// Deno platforms:
|
|
132
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
133
|
+
// - https://github.com/denoland/deno/issues/14799
|
|
134
|
+
platform = platform.toLowerCase();
|
|
135
|
+
// NOTE: this iOS check is untested and may not work
|
|
136
|
+
// Node does not work natively on IOS, there is a fork at
|
|
137
|
+
// https://github.com/nodejs-mobile/nodejs-mobile
|
|
138
|
+
// however it is unknown at the time of writing how to detect if it is running
|
|
139
|
+
if (platform.includes('ios'))
|
|
140
|
+
return 'iOS';
|
|
141
|
+
if (platform === 'android')
|
|
142
|
+
return 'Android';
|
|
143
|
+
if (platform === 'darwin')
|
|
144
|
+
return 'MacOS';
|
|
145
|
+
if (platform === 'win32')
|
|
146
|
+
return 'Windows';
|
|
147
|
+
if (platform === 'freebsd')
|
|
148
|
+
return 'FreeBSD';
|
|
149
|
+
if (platform === 'openbsd')
|
|
150
|
+
return 'OpenBSD';
|
|
151
|
+
if (platform === 'linux')
|
|
152
|
+
return 'Linux';
|
|
153
|
+
if (platform)
|
|
154
|
+
return `Other:${platform}`;
|
|
155
|
+
return 'Unknown';
|
|
156
|
+
};
|
|
157
|
+
let _platformHeaders;
|
|
158
|
+
const getPlatformHeaders = () => {
|
|
159
|
+
return (_platformHeaders ?? (_platformHeaders = getPlatformProperties()));
|
|
160
|
+
};
|
|
161
|
+
exports.getPlatformHeaders = getPlatformHeaders;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.castToError = void 0;
|
|
5
|
+
exports.isAbortError = isAbortError;
|
|
6
|
+
function isAbortError(err) {
|
|
7
|
+
return (typeof err === 'object' &&
|
|
8
|
+
err !== null &&
|
|
9
|
+
// Spec-compliant fetch implementations
|
|
10
|
+
(('name' in err && err.name === 'AbortError') ||
|
|
11
|
+
// Expo fetch
|
|
12
|
+
('message' in err && String(err.message).includes('FetchRequestCanceledException'))));
|
|
13
|
+
}
|
|
14
|
+
const castToError = (err) => {
|
|
15
|
+
if (err instanceof Error)
|
|
16
|
+
return err;
|
|
17
|
+
if (typeof err === 'object' && err !== null) {
|
|
18
|
+
try {
|
|
19
|
+
if (Object.prototype.toString.call(err) === '[object Error]') {
|
|
20
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
21
|
+
const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
|
|
22
|
+
if (err.stack)
|
|
23
|
+
error.stack = err.stack;
|
|
24
|
+
// @ts-ignore - not all envs have native support for cause yet
|
|
25
|
+
if (err.cause && !error.cause)
|
|
26
|
+
error.cause = err.cause;
|
|
27
|
+
if (err.name)
|
|
28
|
+
error.name = err.name;
|
|
29
|
+
return error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch { }
|
|
33
|
+
try {
|
|
34
|
+
return new Error(JSON.stringify(err));
|
|
35
|
+
}
|
|
36
|
+
catch { }
|
|
37
|
+
}
|
|
38
|
+
return new Error(err);
|
|
39
|
+
};
|
|
40
|
+
exports.castToError = castToError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type HeaderValue = string | undefined | null;
|
|
2
|
+
export type HeadersLike = Headers | readonly HeaderValue[][] | Record<string, HeaderValue | readonly HeaderValue[]> | undefined | null | NullableHeaders;
|
|
3
|
+
declare const brand_privateNullableHeaders: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* Users can pass explicit nulls to unset default headers. When we parse them
|
|
7
|
+
* into a standard headers type we need to preserve that information.
|
|
8
|
+
*/
|
|
9
|
+
export type NullableHeaders = {
|
|
10
|
+
/** Brand check, prevent users from creating a NullableHeaders. */
|
|
11
|
+
[brand_privateNullableHeaders]: true;
|
|
12
|
+
/** Parsed headers. */
|
|
13
|
+
values: Headers;
|
|
14
|
+
/** Set of lowercase header names explicitly set to null. */
|
|
15
|
+
nulls: Set<string>;
|
|
16
|
+
};
|
|
17
|
+
export declare const buildHeaders: (newHeaders: HeadersLike[]) => NullableHeaders;
|
|
18
|
+
export declare const isEmptyHeaders: (headers: HeadersLike) => boolean;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isEmptyHeaders = exports.buildHeaders = void 0;
|
|
5
|
+
const values_1 = require("./utils/values");
|
|
6
|
+
const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
|
|
7
|
+
function* iterateHeaders(headers) {
|
|
8
|
+
if (!headers)
|
|
9
|
+
return;
|
|
10
|
+
if (brand_privateNullableHeaders in headers) {
|
|
11
|
+
const { values, nulls } = headers;
|
|
12
|
+
yield* values.entries();
|
|
13
|
+
for (const name of nulls) {
|
|
14
|
+
yield [name, null];
|
|
15
|
+
}
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
let shouldClear = false;
|
|
19
|
+
let iter;
|
|
20
|
+
if (headers instanceof Headers) {
|
|
21
|
+
iter = headers.entries();
|
|
22
|
+
}
|
|
23
|
+
else if ((0, values_1.isReadonlyArray)(headers)) {
|
|
24
|
+
iter = headers;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
shouldClear = true;
|
|
28
|
+
iter = Object.entries(headers ?? {});
|
|
29
|
+
}
|
|
30
|
+
for (let row of iter) {
|
|
31
|
+
const name = row[0];
|
|
32
|
+
if (typeof name !== 'string')
|
|
33
|
+
throw new TypeError('expected header name to be a string');
|
|
34
|
+
const values = (0, values_1.isReadonlyArray)(row[1]) ? row[1] : [row[1]];
|
|
35
|
+
let didClear = false;
|
|
36
|
+
for (const value of values) {
|
|
37
|
+
if (value === undefined)
|
|
38
|
+
continue;
|
|
39
|
+
// Objects keys always overwrite older headers, they never append.
|
|
40
|
+
// Yield a null to clear the header before adding the new values.
|
|
41
|
+
if (shouldClear && !didClear) {
|
|
42
|
+
didClear = true;
|
|
43
|
+
yield [name, null];
|
|
44
|
+
}
|
|
45
|
+
yield [name, value];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const buildHeaders = (newHeaders) => {
|
|
50
|
+
const targetHeaders = new Headers();
|
|
51
|
+
const nullHeaders = new Set();
|
|
52
|
+
for (const headers of newHeaders) {
|
|
53
|
+
const seenHeaders = new Set();
|
|
54
|
+
for (const [name, value] of iterateHeaders(headers)) {
|
|
55
|
+
const lowerName = name.toLowerCase();
|
|
56
|
+
if (!seenHeaders.has(lowerName)) {
|
|
57
|
+
targetHeaders.delete(name);
|
|
58
|
+
seenHeaders.add(lowerName);
|
|
59
|
+
}
|
|
60
|
+
if (value === null) {
|
|
61
|
+
targetHeaders.delete(name);
|
|
62
|
+
nullHeaders.add(lowerName);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
targetHeaders.append(name, value);
|
|
66
|
+
nullHeaders.delete(lowerName);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
|
71
|
+
};
|
|
72
|
+
exports.buildHeaders = buildHeaders;
|
|
73
|
+
const isEmptyHeaders = (headers) => {
|
|
74
|
+
for (const _ of iterateHeaders(headers))
|
|
75
|
+
return false;
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
exports.isEmptyHeaders = isEmptyHeaders;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FinalRequestOptions } from './request-options';
|
|
2
|
+
import { type Relay } from '../client';
|
|
3
|
+
export type APIResponseProps = {
|
|
4
|
+
response: Response;
|
|
5
|
+
options: FinalRequestOptions;
|
|
6
|
+
controller: AbortController;
|
|
7
|
+
requestLogID: string;
|
|
8
|
+
retryOfRequestLogID: string | undefined;
|
|
9
|
+
startTime: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function defaultParseResponse<T>(client: Relay, props: APIResponseProps): Promise<T>;
|