@surgeapi/node 0.25.4 → 0.25.6
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 +14 -1
- package/api/errors/ConflictError.d.ts +2 -1
- package/api/errors/ConflictError.js +2 -1
- package/api/errors/UnprocessableEntityError.d.ts +2 -1
- package/api/errors/UnprocessableEntityError.js +2 -1
- package/api/resources/accounts/client/Client.d.ts +4 -2
- package/api/resources/accounts/client/Client.js +17 -5
- package/api/resources/blasts/client/Client.d.ts +2 -1
- package/api/resources/blasts/client/Client.js +9 -3
- package/api/resources/contacts/client/Client.d.ts +6 -3
- package/api/resources/contacts/client/Client.js +24 -6
- package/api/resources/messages/client/Client.d.ts +2 -1
- package/api/resources/messages/client/Client.js +8 -2
- package/api/resources/phoneNumbers/client/Client.d.ts +2 -1
- package/api/resources/phoneNumbers/client/Client.js +8 -2
- package/api/resources/users/client/Client.d.ts +4 -2
- package/api/resources/users/client/Client.js +16 -4
- package/api/resources/verifications/client/Client.d.ts +4 -2
- package/api/resources/verifications/client/Client.js +18 -6
- package/core/fetcher/APIResponse.d.ts +10 -0
- package/core/fetcher/Fetcher.js +7 -0
- package/core/fetcher/Headers.d.ts +2 -0
- package/core/fetcher/Headers.js +84 -0
- package/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/core/fetcher/HttpResponsePromise.js +103 -0
- package/core/fetcher/RawResponse.d.ts +29 -0
- package/core/fetcher/RawResponse.js +44 -0
- package/core/fetcher/index.d.ts +3 -0
- package/core/fetcher/index.js +7 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +1 -1
- package/dist/api/errors/ConflictError.d.ts +2 -1
- package/dist/api/errors/ConflictError.js +2 -1
- package/dist/api/errors/UnprocessableEntityError.d.ts +2 -1
- package/dist/api/errors/UnprocessableEntityError.js +2 -1
- package/dist/api/resources/accounts/client/Client.d.ts +4 -2
- package/dist/api/resources/accounts/client/Client.js +17 -5
- package/dist/api/resources/blasts/client/Client.d.ts +2 -1
- package/dist/api/resources/blasts/client/Client.js +9 -3
- package/dist/api/resources/contacts/client/Client.d.ts +6 -3
- package/dist/api/resources/contacts/client/Client.js +24 -6
- package/dist/api/resources/messages/client/Client.d.ts +2 -1
- package/dist/api/resources/messages/client/Client.js +8 -2
- package/dist/api/resources/phoneNumbers/client/Client.d.ts +2 -1
- package/dist/api/resources/phoneNumbers/client/Client.js +8 -2
- package/dist/api/resources/users/client/Client.d.ts +4 -2
- package/dist/api/resources/users/client/Client.js +16 -4
- package/dist/api/resources/verifications/client/Client.d.ts +4 -2
- package/dist/api/resources/verifications/client/Client.js +18 -6
- package/dist/core/fetcher/APIResponse.d.ts +10 -0
- package/dist/core/fetcher/Fetcher.js +7 -0
- package/dist/core/fetcher/Headers.d.ts +2 -0
- package/dist/core/fetcher/Headers.js +84 -0
- package/dist/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/core/fetcher/HttpResponsePromise.js +103 -0
- package/dist/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/core/fetcher/RawResponse.js +44 -0
- package/dist/core/fetcher/index.d.ts +3 -0
- package/dist/core/fetcher/index.js +7 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/errors/SurgeError.d.ts +4 -1
- package/dist/errors/SurgeError.js +4 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/errors/SurgeError.d.ts +4 -1
- package/errors/SurgeError.js +4 -7
- package/package.json +3 -2
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -37,7 +37,8 @@ export declare class Verifications {
|
|
|
37
37
|
* phone_number: "+18015551234"
|
|
38
38
|
* })
|
|
39
39
|
*/
|
|
40
|
-
create(request: Surge.VerificationRequest, requestOptions?: Verifications.RequestOptions):
|
|
40
|
+
create(request: Surge.VerificationRequest, requestOptions?: Verifications.RequestOptions): core.HttpResponsePromise<Surge.Verification>;
|
|
41
|
+
private __create;
|
|
41
42
|
/**
|
|
42
43
|
* Checks the code against a verification.
|
|
43
44
|
*
|
|
@@ -53,6 +54,7 @@ export declare class Verifications {
|
|
|
53
54
|
* code: "123456"
|
|
54
55
|
* })
|
|
55
56
|
*/
|
|
56
|
-
check(id: string, request: Surge.VerificationCheckRequest, requestOptions?: Verifications.RequestOptions):
|
|
57
|
+
check(id: string, request: Surge.VerificationCheckRequest, requestOptions?: Verifications.RequestOptions): core.HttpResponsePromise<Surge.VerificationCheckOkResponse>;
|
|
58
|
+
private __check;
|
|
57
59
|
protected _getAuthorizationHeader(): Promise<string>;
|
|
58
60
|
}
|
|
@@ -70,12 +70,15 @@ class Verifications {
|
|
|
70
70
|
* })
|
|
71
71
|
*/
|
|
72
72
|
create(request, requestOptions) {
|
|
73
|
+
return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions));
|
|
74
|
+
}
|
|
75
|
+
__create(request, requestOptions) {
|
|
73
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
77
|
var _a, _b, _c;
|
|
75
78
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
76
79
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.SurgeEnvironment.Default, "verifications"),
|
|
77
80
|
method: "POST",
|
|
78
|
-
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@surgeapi/node", "X-Fern-SDK-Version": "0.25.
|
|
81
|
+
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@surgeapi/node", "X-Fern-SDK-Version": "0.25.6", "User-Agent": "@surgeapi/node/0.25.6", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
79
82
|
contentType: "application/json",
|
|
80
83
|
requestType: "json",
|
|
81
84
|
body: request,
|
|
@@ -84,12 +87,13 @@ class Verifications {
|
|
|
84
87
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
85
88
|
});
|
|
86
89
|
if (_response.ok) {
|
|
87
|
-
return _response.body;
|
|
90
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
88
91
|
}
|
|
89
92
|
if (_response.error.reason === "status-code") {
|
|
90
93
|
throw new errors.SurgeError({
|
|
91
94
|
statusCode: _response.error.statusCode,
|
|
92
95
|
body: _response.error.body,
|
|
96
|
+
rawResponse: _response.rawResponse,
|
|
93
97
|
});
|
|
94
98
|
}
|
|
95
99
|
switch (_response.error.reason) {
|
|
@@ -97,12 +101,14 @@ class Verifications {
|
|
|
97
101
|
throw new errors.SurgeError({
|
|
98
102
|
statusCode: _response.error.statusCode,
|
|
99
103
|
body: _response.error.rawBody,
|
|
104
|
+
rawResponse: _response.rawResponse,
|
|
100
105
|
});
|
|
101
106
|
case "timeout":
|
|
102
107
|
throw new errors.SurgeTimeoutError("Timeout exceeded when calling POST /verifications.");
|
|
103
108
|
case "unknown":
|
|
104
109
|
throw new errors.SurgeError({
|
|
105
110
|
message: _response.error.errorMessage,
|
|
111
|
+
rawResponse: _response.rawResponse,
|
|
106
112
|
});
|
|
107
113
|
}
|
|
108
114
|
});
|
|
@@ -123,12 +129,15 @@ class Verifications {
|
|
|
123
129
|
* })
|
|
124
130
|
*/
|
|
125
131
|
check(id, request, requestOptions) {
|
|
132
|
+
return core.HttpResponsePromise.fromPromise(this.__check(id, request, requestOptions));
|
|
133
|
+
}
|
|
134
|
+
__check(id, request, requestOptions) {
|
|
126
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
136
|
var _a, _b, _c;
|
|
128
137
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
129
138
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.SurgeEnvironment.Default, `verifications/${encodeURIComponent(id)}/checks`),
|
|
130
139
|
method: "POST",
|
|
131
|
-
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@surgeapi/node", "X-Fern-SDK-Version": "0.25.
|
|
140
|
+
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@surgeapi/node", "X-Fern-SDK-Version": "0.25.6", "User-Agent": "@surgeapi/node/0.25.6", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
132
141
|
contentType: "application/json",
|
|
133
142
|
requestType: "json",
|
|
134
143
|
body: request,
|
|
@@ -137,18 +146,19 @@ class Verifications {
|
|
|
137
146
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
138
147
|
});
|
|
139
148
|
if (_response.ok) {
|
|
140
|
-
return _response.body;
|
|
149
|
+
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
141
150
|
}
|
|
142
151
|
if (_response.error.reason === "status-code") {
|
|
143
152
|
switch (_response.error.statusCode) {
|
|
144
153
|
case 409:
|
|
145
|
-
throw new Surge.ConflictError(_response.error.body);
|
|
154
|
+
throw new Surge.ConflictError(_response.error.body, _response.rawResponse);
|
|
146
155
|
case 422:
|
|
147
|
-
throw new Surge.UnprocessableEntityError(_response.error.body);
|
|
156
|
+
throw new Surge.UnprocessableEntityError(_response.error.body, _response.rawResponse);
|
|
148
157
|
default:
|
|
149
158
|
throw new errors.SurgeError({
|
|
150
159
|
statusCode: _response.error.statusCode,
|
|
151
160
|
body: _response.error.body,
|
|
161
|
+
rawResponse: _response.rawResponse,
|
|
152
162
|
});
|
|
153
163
|
}
|
|
154
164
|
}
|
|
@@ -157,12 +167,14 @@ class Verifications {
|
|
|
157
167
|
throw new errors.SurgeError({
|
|
158
168
|
statusCode: _response.error.statusCode,
|
|
159
169
|
body: _response.error.rawBody,
|
|
170
|
+
rawResponse: _response.rawResponse,
|
|
160
171
|
});
|
|
161
172
|
case "timeout":
|
|
162
173
|
throw new errors.SurgeTimeoutError("Timeout exceeded when calling POST /verifications/{id}/checks.");
|
|
163
174
|
case "unknown":
|
|
164
175
|
throw new errors.SurgeError({
|
|
165
176
|
message: _response.error.errorMessage,
|
|
177
|
+
rawResponse: _response.rawResponse,
|
|
166
178
|
});
|
|
167
179
|
}
|
|
168
180
|
});
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import { RawResponse } from "./RawResponse";
|
|
2
|
+
/**
|
|
3
|
+
* The response of an API call.
|
|
4
|
+
* It is a successful response or a failed response.
|
|
5
|
+
*/
|
|
1
6
|
export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | FailedResponse<Failure>;
|
|
2
7
|
export interface SuccessfulResponse<T> {
|
|
3
8
|
ok: true;
|
|
4
9
|
body: T;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `rawResponse` instead
|
|
12
|
+
*/
|
|
5
13
|
headers?: Record<string, any>;
|
|
14
|
+
rawResponse: RawResponse;
|
|
6
15
|
}
|
|
7
16
|
export interface FailedResponse<T> {
|
|
8
17
|
ok: false;
|
|
9
18
|
error: T;
|
|
19
|
+
rawResponse: RawResponse;
|
|
10
20
|
}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.fetcher = void 0;
|
|
13
13
|
exports.fetcherImpl = fetcherImpl;
|
|
14
14
|
const json_1 = require("../json");
|
|
15
|
+
const RawResponse_1 = require("./RawResponse");
|
|
15
16
|
const createRequestUrl_1 = require("./createRequestUrl");
|
|
16
17
|
const getFetchFn_1 = require("./getFetchFn");
|
|
17
18
|
const getRequestBody_1 = require("./getRequestBody");
|
|
@@ -47,6 +48,7 @@ function fetcherImpl(args) {
|
|
|
47
48
|
ok: true,
|
|
48
49
|
body: responseBody,
|
|
49
50
|
headers: response.headers,
|
|
51
|
+
rawResponse: (0, RawResponse_1.toRawResponse)(response),
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
else {
|
|
@@ -57,6 +59,7 @@ function fetcherImpl(args) {
|
|
|
57
59
|
statusCode: response.status,
|
|
58
60
|
body: responseBody,
|
|
59
61
|
},
|
|
62
|
+
rawResponse: (0, RawResponse_1.toRawResponse)(response),
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
65
|
}
|
|
@@ -68,6 +71,7 @@ function fetcherImpl(args) {
|
|
|
68
71
|
reason: "unknown",
|
|
69
72
|
errorMessage: "The user aborted a request",
|
|
70
73
|
},
|
|
74
|
+
rawResponse: RawResponse_1.abortRawResponse,
|
|
71
75
|
};
|
|
72
76
|
}
|
|
73
77
|
else if (error instanceof Error && error.name === "AbortError") {
|
|
@@ -76,6 +80,7 @@ function fetcherImpl(args) {
|
|
|
76
80
|
error: {
|
|
77
81
|
reason: "timeout",
|
|
78
82
|
},
|
|
83
|
+
rawResponse: RawResponse_1.abortRawResponse,
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
else if (error instanceof Error) {
|
|
@@ -85,6 +90,7 @@ function fetcherImpl(args) {
|
|
|
85
90
|
reason: "unknown",
|
|
86
91
|
errorMessage: error.message,
|
|
87
92
|
},
|
|
93
|
+
rawResponse: RawResponse_1.unknownRawResponse,
|
|
88
94
|
};
|
|
89
95
|
}
|
|
90
96
|
return {
|
|
@@ -93,6 +99,7 @@ function fetcherImpl(args) {
|
|
|
93
99
|
reason: "unknown",
|
|
94
100
|
errorMessage: (0, json_1.toJson)(error),
|
|
95
101
|
},
|
|
102
|
+
rawResponse: RawResponse_1.unknownRawResponse,
|
|
96
103
|
};
|
|
97
104
|
}
|
|
98
105
|
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Headers = void 0;
|
|
4
|
+
let Headers;
|
|
5
|
+
if (typeof globalThis.Headers !== "undefined") {
|
|
6
|
+
exports.Headers = Headers = globalThis.Headers;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
exports.Headers = Headers = class Headers {
|
|
10
|
+
constructor(init) {
|
|
11
|
+
this.headers = new Map();
|
|
12
|
+
if (init) {
|
|
13
|
+
if (init instanceof Headers) {
|
|
14
|
+
init.forEach((value, key) => this.append(key, value));
|
|
15
|
+
}
|
|
16
|
+
else if (Array.isArray(init)) {
|
|
17
|
+
for (const [key, value] of init) {
|
|
18
|
+
if (typeof key === "string" && typeof value === "string") {
|
|
19
|
+
this.append(key, value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new TypeError("Each header entry must be a [string, string] tuple");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
for (const [key, value] of Object.entries(init)) {
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
this.append(key, value);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new TypeError("Header values must be strings");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
append(name, value) {
|
|
39
|
+
const key = name.toLowerCase();
|
|
40
|
+
const existing = this.headers.get(key) || [];
|
|
41
|
+
this.headers.set(key, [...existing, value]);
|
|
42
|
+
}
|
|
43
|
+
delete(name) {
|
|
44
|
+
const key = name.toLowerCase();
|
|
45
|
+
this.headers.delete(key);
|
|
46
|
+
}
|
|
47
|
+
get(name) {
|
|
48
|
+
const key = name.toLowerCase();
|
|
49
|
+
const values = this.headers.get(key);
|
|
50
|
+
return values ? values.join(", ") : null;
|
|
51
|
+
}
|
|
52
|
+
has(name) {
|
|
53
|
+
const key = name.toLowerCase();
|
|
54
|
+
return this.headers.has(key);
|
|
55
|
+
}
|
|
56
|
+
set(name, value) {
|
|
57
|
+
const key = name.toLowerCase();
|
|
58
|
+
this.headers.set(key, [value]);
|
|
59
|
+
}
|
|
60
|
+
forEach(callbackfn, thisArg) {
|
|
61
|
+
const boundCallback = thisArg ? callbackfn.bind(thisArg) : callbackfn;
|
|
62
|
+
this.headers.forEach((values, key) => boundCallback(values.join(", "), key, this));
|
|
63
|
+
}
|
|
64
|
+
getSetCookie() {
|
|
65
|
+
return this.headers.get("set-cookie") || [];
|
|
66
|
+
}
|
|
67
|
+
*entries() {
|
|
68
|
+
for (const [key, values] of this.headers.entries()) {
|
|
69
|
+
yield [key, values.join(", ")];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
*keys() {
|
|
73
|
+
yield* this.headers.keys();
|
|
74
|
+
}
|
|
75
|
+
*values() {
|
|
76
|
+
for (const values of this.headers.values()) {
|
|
77
|
+
yield values.join(", ");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
[Symbol.iterator]() {
|
|
81
|
+
return this.entries();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { WithRawResponse } from "./RawResponse";
|
|
2
|
+
/**
|
|
3
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpResponsePromise<T> extends Promise<T> {
|
|
6
|
+
private innerPromise;
|
|
7
|
+
private unwrappedPromise;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
11
|
+
*
|
|
12
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
13
|
+
* @param args - Arguments to pass to the function.
|
|
14
|
+
* @returns An `HttpResponsePromise` instance.
|
|
15
|
+
*/
|
|
16
|
+
static fromFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T>(fn: F, ...args: Parameters<F>): HttpResponsePromise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
19
|
+
*
|
|
20
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
21
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
22
|
+
*/
|
|
23
|
+
static interceptFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T = Awaited<ReturnType<F>>["data"]>(fn: F): (...args: Parameters<F>) => HttpResponsePromise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
26
|
+
*
|
|
27
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
28
|
+
* @returns An `HttpResponsePromise` instance.
|
|
29
|
+
*/
|
|
30
|
+
static fromPromise<T>(promise: Promise<WithRawResponse<T>>): HttpResponsePromise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
33
|
+
*
|
|
34
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
35
|
+
* @returns An `HttpResponsePromise` instance.
|
|
36
|
+
*/
|
|
37
|
+
static fromExecutor<T>(executor: (resolve: (value: WithRawResponse<T>) => void, reject: (reason?: unknown) => void) => void): HttpResponsePromise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
40
|
+
*
|
|
41
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
42
|
+
* @returns An `HttpResponsePromise` instance.
|
|
43
|
+
*/
|
|
44
|
+
static fromResult<T>(result: WithRawResponse<T>): HttpResponsePromise<T>;
|
|
45
|
+
private unwrap;
|
|
46
|
+
/** @inheritdoc */
|
|
47
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
finally(onfinally?: (() => void) | null): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the data and raw response.
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
56
|
+
*/
|
|
57
|
+
withRawResponse(): Promise<WithRawResponse<T>>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.HttpResponsePromise = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
15
|
+
*/
|
|
16
|
+
class HttpResponsePromise extends Promise {
|
|
17
|
+
constructor(promise) {
|
|
18
|
+
// Initialize with a no-op to avoid premature parsing
|
|
19
|
+
super((resolve) => {
|
|
20
|
+
resolve(undefined);
|
|
21
|
+
});
|
|
22
|
+
this.innerPromise = promise;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
26
|
+
*
|
|
27
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
28
|
+
* @param args - Arguments to pass to the function.
|
|
29
|
+
* @returns An `HttpResponsePromise` instance.
|
|
30
|
+
*/
|
|
31
|
+
static fromFunction(fn, ...args) {
|
|
32
|
+
return new HttpResponsePromise(fn(...args));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
36
|
+
*
|
|
37
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
38
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
39
|
+
*/
|
|
40
|
+
static interceptFunction(fn) {
|
|
41
|
+
return (...args) => {
|
|
42
|
+
return HttpResponsePromise.fromPromise(fn(...args));
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
47
|
+
*
|
|
48
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
49
|
+
* @returns An `HttpResponsePromise` instance.
|
|
50
|
+
*/
|
|
51
|
+
static fromPromise(promise) {
|
|
52
|
+
return new HttpResponsePromise(promise);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
56
|
+
*
|
|
57
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
58
|
+
* @returns An `HttpResponsePromise` instance.
|
|
59
|
+
*/
|
|
60
|
+
static fromExecutor(executor) {
|
|
61
|
+
const promise = new Promise(executor);
|
|
62
|
+
return new HttpResponsePromise(promise);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
66
|
+
*
|
|
67
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
68
|
+
* @returns An `HttpResponsePromise` instance.
|
|
69
|
+
*/
|
|
70
|
+
static fromResult(result) {
|
|
71
|
+
const promise = Promise.resolve(result);
|
|
72
|
+
return new HttpResponsePromise(promise);
|
|
73
|
+
}
|
|
74
|
+
unwrap() {
|
|
75
|
+
if (!this.unwrappedPromise) {
|
|
76
|
+
this.unwrappedPromise = this.innerPromise.then(({ data }) => data);
|
|
77
|
+
}
|
|
78
|
+
return this.unwrappedPromise;
|
|
79
|
+
}
|
|
80
|
+
/** @inheritdoc */
|
|
81
|
+
then(onfulfilled, onrejected) {
|
|
82
|
+
return this.unwrap().then(onfulfilled, onrejected);
|
|
83
|
+
}
|
|
84
|
+
/** @inheritdoc */
|
|
85
|
+
catch(onrejected) {
|
|
86
|
+
return this.unwrap().catch(onrejected);
|
|
87
|
+
}
|
|
88
|
+
/** @inheritdoc */
|
|
89
|
+
finally(onfinally) {
|
|
90
|
+
return this.unwrap().finally(onfinally);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves the data and raw response.
|
|
94
|
+
*
|
|
95
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
96
|
+
*/
|
|
97
|
+
withRawResponse() {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
return yield this.innerPromise;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.HttpResponsePromise = HttpResponsePromise;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw response from the fetch call excluding the body.
|
|
3
|
+
*/
|
|
4
|
+
export type RawResponse = Omit<{
|
|
5
|
+
[K in keyof Response as Response[K] extends Function ? never : K]: Response[K];
|
|
6
|
+
}, "ok" | "body" | "bodyUsed">;
|
|
7
|
+
/**
|
|
8
|
+
* A raw response indicating that the request was aborted.
|
|
9
|
+
*/
|
|
10
|
+
export declare const abortRawResponse: RawResponse;
|
|
11
|
+
/**
|
|
12
|
+
* A raw response indicating an unknown error.
|
|
13
|
+
*/
|
|
14
|
+
export declare const unknownRawResponse: RawResponse;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
|
|
17
|
+
* excluding the `body` and `bodyUsed` fields.
|
|
18
|
+
*
|
|
19
|
+
* @param response - The `RawResponse` object to convert.
|
|
20
|
+
* @returns A `RawResponse` object containing the extracted properties of the input response.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toRawResponse(response: Response): RawResponse;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a `RawResponse` from a standard `Response` object.
|
|
25
|
+
*/
|
|
26
|
+
export interface WithRawResponse<T> {
|
|
27
|
+
readonly data: T;
|
|
28
|
+
readonly rawResponse: RawResponse;
|
|
29
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unknownRawResponse = exports.abortRawResponse = void 0;
|
|
4
|
+
exports.toRawResponse = toRawResponse;
|
|
5
|
+
const Headers_1 = require("./Headers");
|
|
6
|
+
/**
|
|
7
|
+
* A raw response indicating that the request was aborted.
|
|
8
|
+
*/
|
|
9
|
+
exports.abortRawResponse = {
|
|
10
|
+
headers: new Headers_1.Headers(),
|
|
11
|
+
redirected: false,
|
|
12
|
+
status: 499,
|
|
13
|
+
statusText: "Client Closed Request",
|
|
14
|
+
type: "error",
|
|
15
|
+
url: "",
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A raw response indicating an unknown error.
|
|
19
|
+
*/
|
|
20
|
+
exports.unknownRawResponse = {
|
|
21
|
+
headers: new Headers_1.Headers(),
|
|
22
|
+
redirected: false,
|
|
23
|
+
status: 0,
|
|
24
|
+
statusText: "Unknown Error",
|
|
25
|
+
type: "error",
|
|
26
|
+
url: "",
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
|
|
30
|
+
* excluding the `body` and `bodyUsed` fields.
|
|
31
|
+
*
|
|
32
|
+
* @param response - The `RawResponse` object to convert.
|
|
33
|
+
* @returns A `RawResponse` object containing the extracted properties of the input response.
|
|
34
|
+
*/
|
|
35
|
+
function toRawResponse(response) {
|
|
36
|
+
return {
|
|
37
|
+
headers: response.headers,
|
|
38
|
+
redirected: response.redirected,
|
|
39
|
+
status: response.status,
|
|
40
|
+
statusText: response.statusText,
|
|
41
|
+
type: response.type,
|
|
42
|
+
url: response.url,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -3,3 +3,6 @@ export { fetcher } from "./Fetcher";
|
|
|
3
3
|
export type { Fetcher, FetchFunction } from "./Fetcher";
|
|
4
4
|
export { getHeader } from "./getHeader";
|
|
5
5
|
export { Supplier } from "./Supplier";
|
|
6
|
+
export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse";
|
|
7
|
+
export type { RawResponse, WithRawResponse } from "./RawResponse";
|
|
8
|
+
export { HttpResponsePromise } from "./HttpResponsePromise";
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Supplier = exports.getHeader = exports.fetcher = void 0;
|
|
3
|
+
exports.HttpResponsePromise = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.Supplier = exports.getHeader = exports.fetcher = void 0;
|
|
4
4
|
var Fetcher_1 = require("./Fetcher");
|
|
5
5
|
Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return Fetcher_1.fetcher; } });
|
|
6
6
|
var getHeader_1 = require("./getHeader");
|
|
7
7
|
Object.defineProperty(exports, "getHeader", { enumerable: true, get: function () { return getHeader_1.getHeader; } });
|
|
8
8
|
var Supplier_1 = require("./Supplier");
|
|
9
9
|
Object.defineProperty(exports, "Supplier", { enumerable: true, get: function () { return Supplier_1.Supplier; } });
|
|
10
|
+
var RawResponse_1 = require("./RawResponse");
|
|
11
|
+
Object.defineProperty(exports, "abortRawResponse", { enumerable: true, get: function () { return RawResponse_1.abortRawResponse; } });
|
|
12
|
+
Object.defineProperty(exports, "toRawResponse", { enumerable: true, get: function () { return RawResponse_1.toRawResponse; } });
|
|
13
|
+
Object.defineProperty(exports, "unknownRawResponse", { enumerable: true, get: function () { return RawResponse_1.unknownRawResponse; } });
|
|
14
|
+
var HttpResponsePromise_1 = require("./HttpResponsePromise");
|
|
15
|
+
Object.defineProperty(exports, "HttpResponsePromise", { enumerable: true, get: function () { return HttpResponsePromise_1.HttpResponsePromise; } });
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./fetcher"), exports);
|
|
18
|
-
__exportStar(require("./auth"), exports);
|
|
19
18
|
__exportStar(require("./runtime"), exports);
|
|
19
|
+
__exportStar(require("./auth"), exports);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
*/
|
|
4
|
+
import * as core from "../core";
|
|
4
5
|
export declare class SurgeError extends Error {
|
|
5
6
|
readonly statusCode?: number;
|
|
6
7
|
readonly body?: unknown;
|
|
7
|
-
|
|
8
|
+
readonly rawResponse?: core.RawResponse;
|
|
9
|
+
constructor({ message, statusCode, body, rawResponse, }: {
|
|
8
10
|
message?: string;
|
|
9
11
|
statusCode?: number;
|
|
10
12
|
body?: unknown;
|
|
13
|
+
rawResponse?: core.RawResponse;
|
|
11
14
|
});
|
|
12
15
|
}
|
|
@@ -6,15 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.SurgeError = void 0;
|
|
7
7
|
const json_1 = require("../core/json");
|
|
8
8
|
class SurgeError extends Error {
|
|
9
|
-
constructor({ message, statusCode, body }) {
|
|
9
|
+
constructor({ message, statusCode, body, rawResponse, }) {
|
|
10
10
|
super(buildMessage({ message, statusCode, body }));
|
|
11
11
|
Object.setPrototypeOf(this, SurgeError.prototype);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (body !== undefined) {
|
|
16
|
-
this.body = body;
|
|
17
|
-
}
|
|
12
|
+
this.statusCode = statusCode;
|
|
13
|
+
this.body = body;
|
|
14
|
+
this.rawResponse = rawResponse;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
17
|
exports.SurgeError = SurgeError;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.25.
|
|
1
|
+
export declare const SDK_VERSION = "0.25.6";
|
package/dist/version.js
CHANGED
package/errors/SurgeError.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
*/
|
|
4
|
+
import * as core from "../core";
|
|
4
5
|
export declare class SurgeError extends Error {
|
|
5
6
|
readonly statusCode?: number;
|
|
6
7
|
readonly body?: unknown;
|
|
7
|
-
|
|
8
|
+
readonly rawResponse?: core.RawResponse;
|
|
9
|
+
constructor({ message, statusCode, body, rawResponse, }: {
|
|
8
10
|
message?: string;
|
|
9
11
|
statusCode?: number;
|
|
10
12
|
body?: unknown;
|
|
13
|
+
rawResponse?: core.RawResponse;
|
|
11
14
|
});
|
|
12
15
|
}
|
package/errors/SurgeError.js
CHANGED
|
@@ -6,15 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.SurgeError = void 0;
|
|
7
7
|
const json_1 = require("../core/json");
|
|
8
8
|
class SurgeError extends Error {
|
|
9
|
-
constructor({ message, statusCode, body }) {
|
|
9
|
+
constructor({ message, statusCode, body, rawResponse, }) {
|
|
10
10
|
super(buildMessage({ message, statusCode, body }));
|
|
11
11
|
Object.setPrototypeOf(this, SurgeError.prototype);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (body !== undefined) {
|
|
16
|
-
this.body = body;
|
|
17
|
-
}
|
|
12
|
+
this.statusCode = statusCode;
|
|
13
|
+
this.body = body;
|
|
14
|
+
this.rawResponse = rawResponse;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
17
|
exports.SurgeError = SurgeError;
|