@credal/sdk 0.0.27 → 0.0.28
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/api/resources/copilots/client/Client.d.ts +18 -9
- package/api/resources/copilots/client/Client.js +121 -52
- package/api/resources/documentCatalog/client/Client.d.ts +6 -3
- package/api/resources/documentCatalog/client/Client.js +40 -16
- package/api/resources/documentCollections/client/Client.d.ts +12 -6
- package/api/resources/documentCollections/client/Client.js +80 -32
- package/api/resources/permissionsService/client/Client.d.ts +6 -3
- package/api/resources/permissionsService/client/Client.js +48 -21
- package/api/resources/search/client/Client.d.ts +2 -1
- package/api/resources/search/client/Client.js +16 -7
- package/api/resources/users/client/Client.d.ts +2 -1
- package/api/resources/users/client/Client.js +8 -2
- 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/resources/copilots/client/Client.d.ts +18 -9
- package/dist/api/resources/copilots/client/Client.js +121 -52
- package/dist/api/resources/documentCatalog/client/Client.d.ts +6 -3
- package/dist/api/resources/documentCatalog/client/Client.js +40 -16
- package/dist/api/resources/documentCollections/client/Client.d.ts +12 -6
- package/dist/api/resources/documentCollections/client/Client.js +80 -32
- package/dist/api/resources/permissionsService/client/Client.d.ts +6 -3
- package/dist/api/resources/permissionsService/client/Client.js +48 -21
- package/dist/api/resources/search/client/Client.d.ts +2 -1
- package/dist/api/resources/search/client/Client.js +16 -7
- package/dist/api/resources/users/client/Client.d.ts +2 -1
- package/dist/api/resources/users/client/Client.js +8 -2
- 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/CredalError.d.ts +4 -1
- package/dist/errors/CredalError.js +4 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/errors/CredalError.d.ts +4 -1
- package/errors/CredalError.js +4 -7
- package/package.json +3 -2
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -75,12 +75,15 @@ class PermissionsService {
|
|
|
75
75
|
* })
|
|
76
76
|
*/
|
|
77
77
|
checkResourceAuthorizationForUser(request, requestOptions) {
|
|
78
|
+
return core.HttpResponsePromise.fromPromise(this.__checkResourceAuthorizationForUser(request, requestOptions));
|
|
79
|
+
}
|
|
80
|
+
__checkResourceAuthorizationForUser(request, requestOptions) {
|
|
78
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
82
|
var _a, _b, _c;
|
|
80
83
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
81
84
|
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.CredalEnvironment.Production, "/v0/permissions/checkResourceAuthorizationForUser"),
|
|
82
85
|
method: "POST",
|
|
83
|
-
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.
|
|
86
|
+
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.28", "User-Agent": "@credal/sdk/0.0.28", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
84
87
|
contentType: "application/json",
|
|
85
88
|
requestType: "json",
|
|
86
89
|
body: serializers.CheckResourceAuthorizationForUserRequest.jsonOrThrow(request, {
|
|
@@ -91,17 +94,21 @@ class PermissionsService {
|
|
|
91
94
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
92
95
|
});
|
|
93
96
|
if (_response.ok) {
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
return {
|
|
98
|
+
data: serializers.CheckResourceAuthorizationResponse.parseOrThrow(_response.body, {
|
|
99
|
+
unrecognizedObjectKeys: "passthrough",
|
|
100
|
+
allowUnrecognizedUnionMembers: true,
|
|
101
|
+
allowUnrecognizedEnumValues: true,
|
|
102
|
+
breadcrumbsPrefix: ["response"],
|
|
103
|
+
}),
|
|
104
|
+
rawResponse: _response.rawResponse,
|
|
105
|
+
};
|
|
100
106
|
}
|
|
101
107
|
if (_response.error.reason === "status-code") {
|
|
102
108
|
throw new errors.CredalError({
|
|
103
109
|
statusCode: _response.error.statusCode,
|
|
104
110
|
body: _response.error.body,
|
|
111
|
+
rawResponse: _response.rawResponse,
|
|
105
112
|
});
|
|
106
113
|
}
|
|
107
114
|
switch (_response.error.reason) {
|
|
@@ -109,12 +116,14 @@ class PermissionsService {
|
|
|
109
116
|
throw new errors.CredalError({
|
|
110
117
|
statusCode: _response.error.statusCode,
|
|
111
118
|
body: _response.error.rawBody,
|
|
119
|
+
rawResponse: _response.rawResponse,
|
|
112
120
|
});
|
|
113
121
|
case "timeout":
|
|
114
122
|
throw new errors.CredalTimeoutError("Timeout exceeded when calling POST /v0/permissions/checkResourceAuthorizationForUser.");
|
|
115
123
|
case "unknown":
|
|
116
124
|
throw new errors.CredalError({
|
|
117
125
|
message: _response.error.errorMessage,
|
|
126
|
+
rawResponse: _response.rawResponse,
|
|
118
127
|
});
|
|
119
128
|
}
|
|
120
129
|
});
|
|
@@ -139,12 +148,15 @@ class PermissionsService {
|
|
|
139
148
|
* })
|
|
140
149
|
*/
|
|
141
150
|
checkBulkResourcesAuthorizationForUser(request, requestOptions) {
|
|
151
|
+
return core.HttpResponsePromise.fromPromise(this.__checkBulkResourcesAuthorizationForUser(request, requestOptions));
|
|
152
|
+
}
|
|
153
|
+
__checkBulkResourcesAuthorizationForUser(request, requestOptions) {
|
|
142
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
155
|
var _a, _b, _c;
|
|
144
156
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
145
157
|
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.CredalEnvironment.Production, "/v0/permissions/checkBulkResourcesAuthorizationForUser"),
|
|
146
158
|
method: "POST",
|
|
147
|
-
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.
|
|
159
|
+
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.28", "User-Agent": "@credal/sdk/0.0.28", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
148
160
|
contentType: "application/json",
|
|
149
161
|
requestType: "json",
|
|
150
162
|
body: serializers.CheckBulkResourcesAuthorizationForUserRequest.jsonOrThrow(request, {
|
|
@@ -155,17 +167,21 @@ class PermissionsService {
|
|
|
155
167
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
156
168
|
});
|
|
157
169
|
if (_response.ok) {
|
|
158
|
-
return
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
return {
|
|
171
|
+
data: serializers.CheckBulkResourcesAuthorizationResponse.parseOrThrow(_response.body, {
|
|
172
|
+
unrecognizedObjectKeys: "passthrough",
|
|
173
|
+
allowUnrecognizedUnionMembers: true,
|
|
174
|
+
allowUnrecognizedEnumValues: true,
|
|
175
|
+
breadcrumbsPrefix: ["response"],
|
|
176
|
+
}),
|
|
177
|
+
rawResponse: _response.rawResponse,
|
|
178
|
+
};
|
|
164
179
|
}
|
|
165
180
|
if (_response.error.reason === "status-code") {
|
|
166
181
|
throw new errors.CredalError({
|
|
167
182
|
statusCode: _response.error.statusCode,
|
|
168
183
|
body: _response.error.body,
|
|
184
|
+
rawResponse: _response.rawResponse,
|
|
169
185
|
});
|
|
170
186
|
}
|
|
171
187
|
switch (_response.error.reason) {
|
|
@@ -173,12 +189,14 @@ class PermissionsService {
|
|
|
173
189
|
throw new errors.CredalError({
|
|
174
190
|
statusCode: _response.error.statusCode,
|
|
175
191
|
body: _response.error.rawBody,
|
|
192
|
+
rawResponse: _response.rawResponse,
|
|
176
193
|
});
|
|
177
194
|
case "timeout":
|
|
178
195
|
throw new errors.CredalTimeoutError("Timeout exceeded when calling POST /v0/permissions/checkBulkResourcesAuthorizationForUser.");
|
|
179
196
|
case "unknown":
|
|
180
197
|
throw new errors.CredalError({
|
|
181
198
|
message: _response.error.errorMessage,
|
|
199
|
+
rawResponse: _response.rawResponse,
|
|
182
200
|
});
|
|
183
201
|
}
|
|
184
202
|
});
|
|
@@ -195,12 +213,15 @@ class PermissionsService {
|
|
|
195
213
|
* })
|
|
196
214
|
*/
|
|
197
215
|
listCachedAuthorizedResourcesForUser(request, requestOptions) {
|
|
216
|
+
return core.HttpResponsePromise.fromPromise(this.__listCachedAuthorizedResourcesForUser(request, requestOptions));
|
|
217
|
+
}
|
|
218
|
+
__listCachedAuthorizedResourcesForUser(request, requestOptions) {
|
|
198
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
220
|
var _a, _b, _c;
|
|
200
221
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
201
222
|
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.CredalEnvironment.Production, "/v0/permissions/listCachedAuthorizedResourcesForUser"),
|
|
202
223
|
method: "POST",
|
|
203
|
-
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.
|
|
224
|
+
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.28", "User-Agent": "@credal/sdk/0.0.28", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
204
225
|
contentType: "application/json",
|
|
205
226
|
requestType: "json",
|
|
206
227
|
body: serializers.ListCachedAuthorizedResourcesForUserRequest.jsonOrThrow(request, {
|
|
@@ -211,17 +232,21 @@ class PermissionsService {
|
|
|
211
232
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
212
233
|
});
|
|
213
234
|
if (_response.ok) {
|
|
214
|
-
return
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
235
|
+
return {
|
|
236
|
+
data: serializers.AuthorizedResourceListPage.parseOrThrow(_response.body, {
|
|
237
|
+
unrecognizedObjectKeys: "passthrough",
|
|
238
|
+
allowUnrecognizedUnionMembers: true,
|
|
239
|
+
allowUnrecognizedEnumValues: true,
|
|
240
|
+
breadcrumbsPrefix: ["response"],
|
|
241
|
+
}),
|
|
242
|
+
rawResponse: _response.rawResponse,
|
|
243
|
+
};
|
|
220
244
|
}
|
|
221
245
|
if (_response.error.reason === "status-code") {
|
|
222
246
|
throw new errors.CredalError({
|
|
223
247
|
statusCode: _response.error.statusCode,
|
|
224
248
|
body: _response.error.body,
|
|
249
|
+
rawResponse: _response.rawResponse,
|
|
225
250
|
});
|
|
226
251
|
}
|
|
227
252
|
switch (_response.error.reason) {
|
|
@@ -229,12 +254,14 @@ class PermissionsService {
|
|
|
229
254
|
throw new errors.CredalError({
|
|
230
255
|
statusCode: _response.error.statusCode,
|
|
231
256
|
body: _response.error.rawBody,
|
|
257
|
+
rawResponse: _response.rawResponse,
|
|
232
258
|
});
|
|
233
259
|
case "timeout":
|
|
234
260
|
throw new errors.CredalTimeoutError("Timeout exceeded when calling POST /v0/permissions/listCachedAuthorizedResourcesForUser.");
|
|
235
261
|
case "unknown":
|
|
236
262
|
throw new errors.CredalError({
|
|
237
263
|
message: _response.error.errorMessage,
|
|
264
|
+
rawResponse: _response.rawResponse,
|
|
238
265
|
});
|
|
239
266
|
}
|
|
240
267
|
});
|
|
@@ -52,6 +52,7 @@ export declare class Search {
|
|
|
52
52
|
* }
|
|
53
53
|
* })
|
|
54
54
|
*/
|
|
55
|
-
searchDocumentCollection(request: Credal.SearchDocumentCollectionRequest, requestOptions?: Search.RequestOptions):
|
|
55
|
+
searchDocumentCollection(request: Credal.SearchDocumentCollectionRequest, requestOptions?: Search.RequestOptions): core.HttpResponsePromise<Credal.SearchDocumentCollectionResponse>;
|
|
56
|
+
private __searchDocumentCollection;
|
|
56
57
|
protected _getAuthorizationHeader(): Promise<string>;
|
|
57
58
|
}
|
|
@@ -85,12 +85,15 @@ class Search {
|
|
|
85
85
|
* })
|
|
86
86
|
*/
|
|
87
87
|
searchDocumentCollection(request, requestOptions) {
|
|
88
|
+
return core.HttpResponsePromise.fromPromise(this.__searchDocumentCollection(request, requestOptions));
|
|
89
|
+
}
|
|
90
|
+
__searchDocumentCollection(request, requestOptions) {
|
|
88
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
92
|
var _a, _b, _c;
|
|
90
93
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
91
94
|
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.CredalEnvironment.Production, "/v0/search/searchDocumentCollection"),
|
|
92
95
|
method: "POST",
|
|
93
|
-
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.
|
|
96
|
+
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.28", "User-Agent": "@credal/sdk/0.0.28", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
94
97
|
contentType: "application/json",
|
|
95
98
|
requestType: "json",
|
|
96
99
|
body: serializers.SearchDocumentCollectionRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
|
|
@@ -99,17 +102,21 @@ class Search {
|
|
|
99
102
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
100
103
|
});
|
|
101
104
|
if (_response.ok) {
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
return {
|
|
106
|
+
data: serializers.SearchDocumentCollectionResponse.parseOrThrow(_response.body, {
|
|
107
|
+
unrecognizedObjectKeys: "passthrough",
|
|
108
|
+
allowUnrecognizedUnionMembers: true,
|
|
109
|
+
allowUnrecognizedEnumValues: true,
|
|
110
|
+
breadcrumbsPrefix: ["response"],
|
|
111
|
+
}),
|
|
112
|
+
rawResponse: _response.rawResponse,
|
|
113
|
+
};
|
|
108
114
|
}
|
|
109
115
|
if (_response.error.reason === "status-code") {
|
|
110
116
|
throw new errors.CredalError({
|
|
111
117
|
statusCode: _response.error.statusCode,
|
|
112
118
|
body: _response.error.body,
|
|
119
|
+
rawResponse: _response.rawResponse,
|
|
113
120
|
});
|
|
114
121
|
}
|
|
115
122
|
switch (_response.error.reason) {
|
|
@@ -117,12 +124,14 @@ class Search {
|
|
|
117
124
|
throw new errors.CredalError({
|
|
118
125
|
statusCode: _response.error.statusCode,
|
|
119
126
|
body: _response.error.rawBody,
|
|
127
|
+
rawResponse: _response.rawResponse,
|
|
120
128
|
});
|
|
121
129
|
case "timeout":
|
|
122
130
|
throw new errors.CredalTimeoutError("Timeout exceeded when calling POST /v0/search/searchDocumentCollection.");
|
|
123
131
|
case "unknown":
|
|
124
132
|
throw new errors.CredalError({
|
|
125
133
|
message: _response.error.errorMessage,
|
|
134
|
+
rawResponse: _response.rawResponse,
|
|
126
135
|
});
|
|
127
136
|
}
|
|
128
137
|
});
|
|
@@ -47,6 +47,7 @@ export declare class Users {
|
|
|
47
47
|
* userEmail: "jack@credal.ai"
|
|
48
48
|
* }])
|
|
49
49
|
*/
|
|
50
|
-
metadata(request: Credal.UserMetadataPatch[], requestOptions?: Users.RequestOptions):
|
|
50
|
+
metadata(request: Credal.UserMetadataPatch[], requestOptions?: Users.RequestOptions): core.HttpResponsePromise<void>;
|
|
51
|
+
private __metadata;
|
|
51
52
|
protected _getAuthorizationHeader(): Promise<string>;
|
|
52
53
|
}
|
|
@@ -80,12 +80,15 @@ class Users {
|
|
|
80
80
|
* }])
|
|
81
81
|
*/
|
|
82
82
|
metadata(request, requestOptions) {
|
|
83
|
+
return core.HttpResponsePromise.fromPromise(this.__metadata(request, requestOptions));
|
|
84
|
+
}
|
|
85
|
+
__metadata(request, requestOptions) {
|
|
83
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
87
|
var _a, _b, _c;
|
|
85
88
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
86
89
|
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.CredalEnvironment.Production, "/v0/users/metadata"),
|
|
87
90
|
method: "PATCH",
|
|
88
|
-
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.
|
|
91
|
+
headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@credal/sdk", "X-Fern-SDK-Version": "0.0.28", "User-Agent": "@credal/sdk/0.0.28", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
89
92
|
contentType: "application/json",
|
|
90
93
|
requestType: "json",
|
|
91
94
|
body: serializers.users.metadata.Request.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
|
|
@@ -94,12 +97,13 @@ class Users {
|
|
|
94
97
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
95
98
|
});
|
|
96
99
|
if (_response.ok) {
|
|
97
|
-
return;
|
|
100
|
+
return { data: undefined, rawResponse: _response.rawResponse };
|
|
98
101
|
}
|
|
99
102
|
if (_response.error.reason === "status-code") {
|
|
100
103
|
throw new errors.CredalError({
|
|
101
104
|
statusCode: _response.error.statusCode,
|
|
102
105
|
body: _response.error.body,
|
|
106
|
+
rawResponse: _response.rawResponse,
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
switch (_response.error.reason) {
|
|
@@ -107,12 +111,14 @@ class Users {
|
|
|
107
111
|
throw new errors.CredalError({
|
|
108
112
|
statusCode: _response.error.statusCode,
|
|
109
113
|
body: _response.error.rawBody,
|
|
114
|
+
rawResponse: _response.rawResponse,
|
|
110
115
|
});
|
|
111
116
|
case "timeout":
|
|
112
117
|
throw new errors.CredalTimeoutError("Timeout exceeded when calling PATCH /v0/users/metadata.");
|
|
113
118
|
case "unknown":
|
|
114
119
|
throw new errors.CredalError({
|
|
115
120
|
message: _response.error.errorMessage,
|
|
121
|
+
rawResponse: _response.rawResponse,
|
|
116
122
|
});
|
|
117
123
|
}
|
|
118
124
|
});
|
|
@@ -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;
|