@postpeer/node 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/api-promise.d.mts +1 -0
- package/api-promise.d.mts.map +1 -1
- package/api-promise.d.ts +1 -0
- package/api-promise.d.ts.map +1 -1
- package/api-promise.js.map +1 -1
- package/api-promise.mjs +1 -0
- package/api-promise.mjs.map +1 -1
- package/client.d.mts +5 -5
- package/client.d.mts.map +1 -1
- package/client.d.ts +5 -5
- package/client.d.ts.map +1 -1
- package/client.js +75 -19
- package/client.js.map +1 -1
- package/client.mjs +77 -21
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts.map +1 -1
- package/core/api-promise.d.ts.map +1 -1
- package/core/api-promise.js.map +1 -1
- package/core/api-promise.mjs.map +1 -1
- package/core/error.d.mts.map +1 -1
- package/core/error.d.ts.map +1 -1
- package/core/error.js +2 -2
- package/core/error.js.map +1 -1
- package/core/error.mjs +2 -2
- package/core/error.mjs.map +1 -1
- package/core/resource.d.mts.map +1 -1
- package/core/resource.d.ts.map +1 -1
- package/core/uploads.d.mts.map +1 -1
- package/core/uploads.d.ts.map +1 -1
- package/core/uploads.mjs.map +1 -1
- package/error.d.mts +1 -0
- package/error.d.mts.map +1 -1
- package/error.d.ts +1 -0
- package/error.d.ts.map +1 -1
- package/error.js.map +1 -1
- package/error.mjs +1 -0
- package/error.mjs.map +1 -1
- package/index.d.mts +1 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/internal/builtin-types.d.mts +5 -5
- package/internal/builtin-types.d.mts.map +1 -1
- package/internal/builtin-types.d.ts +5 -5
- package/internal/builtin-types.d.ts.map +1 -1
- package/internal/detect-platform.d.mts.map +1 -1
- package/internal/detect-platform.d.ts.map +1 -1
- package/internal/detect-platform.js.map +1 -1
- package/internal/detect-platform.mjs.map +1 -1
- package/internal/errors.js +6 -5
- package/internal/errors.js.map +1 -1
- package/internal/errors.mjs +6 -5
- package/internal/errors.mjs.map +1 -1
- package/internal/headers.js +2 -2
- package/internal/headers.js.map +1 -1
- package/internal/headers.mjs +2 -2
- package/internal/headers.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +7 -1
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +7 -1
- package/internal/parse.mjs.map +1 -1
- package/internal/qs/formats.d.mts.map +1 -1
- package/internal/qs/formats.d.ts.map +1 -1
- package/internal/qs/index.d.mts +2 -2
- package/internal/qs/index.d.mts.map +1 -1
- package/internal/qs/index.d.ts +2 -2
- package/internal/qs/index.d.ts.map +1 -1
- package/internal/qs/index.mjs.map +1 -1
- package/internal/qs/stringify.d.mts.map +1 -1
- package/internal/qs/stringify.d.ts.map +1 -1
- package/internal/qs/stringify.mjs.map +1 -1
- package/internal/qs/utils.d.mts.map +1 -1
- package/internal/qs/utils.d.ts.map +1 -1
- package/internal/qs/utils.js +1 -2
- package/internal/qs/utils.js.map +1 -1
- package/internal/qs/utils.mjs +1 -2
- package/internal/qs/utils.mjs.map +1 -1
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs.map +1 -1
- package/internal/shim-types.d.mts.map +1 -1
- package/internal/shim-types.d.ts.map +1 -1
- package/internal/shims.d.mts +6 -0
- package/internal/shims.d.mts.map +1 -1
- package/internal/shims.d.ts +6 -0
- package/internal/shims.d.ts.map +1 -1
- package/internal/shims.js.map +1 -1
- package/internal/shims.mjs.map +1 -1
- package/internal/to-file.d.mts.map +1 -1
- package/internal/to-file.d.ts.map +1 -1
- package/internal/to-file.js.map +1 -1
- package/internal/to-file.mjs.map +1 -1
- package/internal/types.d.mts +17 -11
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +17 -11
- package/internal/types.d.ts.map +1 -1
- package/internal/uploads.d.mts.map +1 -1
- package/internal/uploads.d.ts.map +1 -1
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/base64.mjs.map +1 -1
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +11 -2
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +11 -2
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/path.mjs.map +1 -1
- package/internal/utils/query.js.map +1 -1
- package/internal/utils/query.mjs.map +1 -1
- package/internal/utils/uuid.d.mts.map +1 -1
- package/internal/utils/uuid.d.ts.map +1 -1
- package/internal/utils/uuid.js +2 -4
- package/internal/utils/uuid.js.map +1 -1
- package/internal/utils/uuid.mjs +2 -4
- package/internal/utils/uuid.mjs.map +1 -1
- package/internal/utils/values.mjs.map +1 -1
- package/internal/utils.d.mts.map +1 -1
- package/internal/utils.d.ts.map +1 -1
- package/internal/utils.mjs.map +1 -1
- package/package.json +1 -1
- package/resource.d.mts +1 -0
- package/resource.d.mts.map +1 -1
- package/resource.d.ts +1 -0
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs +1 -0
- package/resource.mjs.map +1 -1
- package/resources/connect/connect.d.mts +9 -4
- package/resources/connect/connect.d.mts.map +1 -1
- package/resources/connect/connect.d.ts +9 -4
- package/resources/connect/connect.d.ts.map +1 -1
- package/resources/connect/connect.js.map +1 -1
- package/resources/connect/connect.mjs +1 -1
- package/resources/connect/connect.mjs.map +1 -1
- package/resources/connect/index.d.mts +1 -1
- package/resources/connect/index.d.mts.map +1 -1
- package/resources/connect/index.d.ts +1 -1
- package/resources/connect/index.d.ts.map +1 -1
- package/resources/connect/index.js +0 -2
- package/resources/connect/index.js.map +1 -1
- package/resources/connect/index.mjs +1 -3
- package/resources/connect/index.mjs.map +1 -1
- package/resources/connect/integrations.d.mts +35 -4
- package/resources/connect/integrations.d.mts.map +1 -1
- package/resources/connect/integrations.d.ts +35 -4
- package/resources/connect/integrations.d.ts.map +1 -1
- package/resources/connect/integrations.js +3 -3
- package/resources/connect/integrations.js.map +1 -1
- package/resources/connect/integrations.mjs +3 -3
- package/resources/connect/integrations.mjs.map +1 -1
- package/resources/connect.d.mts.map +1 -1
- package/resources/connect.d.ts.map +1 -1
- package/resources/connect.mjs.map +1 -1
- package/resources/health.d.mts +1 -1
- package/resources/health.d.mts.map +1 -1
- package/resources/health.d.ts +1 -1
- package/resources/health.d.ts.map +1 -1
- package/resources/health.mjs.map +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +0 -5
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -6
- package/resources/index.mjs.map +1 -1
- package/resources/media.d.mts.map +1 -1
- package/resources/media.d.ts.map +1 -1
- package/resources/media.mjs.map +1 -1
- package/resources/platforms.d.mts +1 -1
- package/resources/platforms.d.mts.map +1 -1
- package/resources/platforms.d.ts +1 -1
- package/resources/platforms.d.ts.map +1 -1
- package/resources/platforms.mjs.map +1 -1
- package/resources/posts/index.d.mts +2 -2
- package/resources/posts/index.d.mts.map +1 -1
- package/resources/posts/index.d.ts +2 -2
- package/resources/posts/index.d.ts.map +1 -1
- package/resources/posts/index.js +0 -2
- package/resources/posts/index.js.map +1 -1
- package/resources/posts/index.mjs +2 -4
- package/resources/posts/index.mjs.map +1 -1
- package/resources/posts/posts.d.mts +36 -8
- package/resources/posts/posts.d.mts.map +1 -1
- package/resources/posts/posts.d.ts +36 -8
- package/resources/posts/posts.d.ts.map +1 -1
- package/resources/posts/posts.js.map +1 -1
- package/resources/posts/posts.mjs +1 -1
- package/resources/posts/posts.mjs.map +1 -1
- package/resources/posts/scheduled.d.mts +20 -4
- package/resources/posts/scheduled.d.mts.map +1 -1
- package/resources/posts/scheduled.d.ts +20 -4
- package/resources/posts/scheduled.d.ts.map +1 -1
- package/resources/posts/scheduled.js +4 -3
- package/resources/posts/scheduled.js.map +1 -1
- package/resources/posts/scheduled.mjs +4 -3
- package/resources/posts/scheduled.mjs.map +1 -1
- package/resources/posts.d.mts.map +1 -1
- package/resources/posts.d.ts.map +1 -1
- package/resources/posts.mjs.map +1 -1
- package/resources.d.mts.map +1 -1
- package/resources.d.ts.map +1 -1
- package/resources.mjs.map +1 -1
- package/src/api-promise.ts +1 -1
- package/src/client.ts +180 -79
- package/src/core/api-promise.ts +7 -2
- package/src/core/error.ts +22 -24
- package/src/error.ts +1 -1
- package/src/index.ts +15 -1
- package/src/internal/builtin-types.ts +14 -9
- package/src/internal/detect-platform.ts +5 -1
- package/src/internal/errors.ts +7 -7
- package/src/internal/headers.ts +2 -2
- package/src/internal/parse.ts +10 -2
- package/src/internal/qs/utils.ts +1 -4
- package/src/internal/request-options.ts +1 -5
- package/src/internal/shim-types.ts +2 -2
- package/src/internal/shims.ts +3 -1
- package/src/internal/to-file.ts +7 -7
- package/src/internal/types.ts +20 -16
- package/src/internal/utils/log.ts +32 -8
- package/src/internal/utils/query.ts +1 -1
- package/src/internal/utils/uuid.ts +3 -5
- package/src/resource.ts +1 -1
- package/src/resources/connect/connect.ts +29 -4
- package/src/resources/connect/index.ts +7 -2
- package/src/resources/connect/integrations.ts +66 -5
- package/src/resources/health.ts +1 -1
- package/src/resources/index.ts +14 -5
- package/src/resources/media.ts +1 -4
- package/src/resources/platforms.ts +11 -4
- package/src/resources/posts/index.ts +18 -2
- package/src/resources/posts/posts.ts +102 -10
- package/src/resources/posts/scheduled.ts +43 -6
- package/src/uploads.ts +1 -1
- package/src/version.ts +1 -1
- package/uploads.d.mts +1 -0
- package/uploads.d.mts.map +1 -1
- package/uploads.d.ts +1 -0
- package/uploads.d.ts.map +1 -1
- package/uploads.js.map +1 -1
- package/uploads.mjs +1 -0
- package/uploads.mjs.map +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled.d.ts","sourceRoot":"","sources":["../../src/resources/posts/scheduled.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scheduled.d.ts","sourceRoot":"","sources":["../../src/resources/posts/scheduled.ts"],"names":[],"mappings":"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"}
|
|
@@ -6,15 +6,16 @@ const resource_1 = require("../../core/resource.js");
|
|
|
6
6
|
const path_1 = require("../../internal/utils/path.js");
|
|
7
7
|
class Scheduled extends resource_1.APIResource {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Returns a paginated list of scheduled posts. Use `limit` + `offset` to page
|
|
10
|
+
* through the results.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* ```ts
|
|
13
14
|
* const scheduleds = await client.posts.scheduled.list();
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
|
-
list(options) {
|
|
17
|
-
return this._client.get('/v1/posts/scheduled/', options);
|
|
17
|
+
list(query = {}, options) {
|
|
18
|
+
return this._client.get('/v1/posts/scheduled/', { query, ...options });
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Cancel a scheduled post (moves it back to draft)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled.js","sourceRoot":"","sources":["../../src/resources/posts/scheduled.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,qDAAkD;AAGlD,uDAAiD;AAEjD,MAAa,SAAU,SAAQ,sBAAW;IACxC
|
|
1
|
+
{"version":3,"file":"scheduled.js","sourceRoot":"","sources":["../../src/resources/posts/scheduled.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,qDAAkD;AAGlD,uDAAiD;AAEjD,MAAa,SAAU,SAAQ,sBAAW;IACxC;;;;;;;;OAQG;IACH,IAAI,CACF,QAAgD,EAAE,EAClD,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAc,EAAE,OAAwB;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAA,WAAI,EAAA,uBAAuB,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;;;OAUG;IACH,UAAU,CACR,MAAc,EACd,IAA+B,EAC/B,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAA,WAAI,EAAA,uBAAuB,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACvF,CAAC;CACF;AAjDD,8BAiDC"}
|
|
@@ -3,15 +3,16 @@ import { APIResource } from "../../core/resource.mjs";
|
|
|
3
3
|
import { path } from "../../internal/utils/path.mjs";
|
|
4
4
|
export class Scheduled extends APIResource {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Returns a paginated list of scheduled posts. Use `limit` + `offset` to page
|
|
7
|
+
* through the results.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```ts
|
|
10
11
|
* const scheduleds = await client.posts.scheduled.list();
|
|
11
12
|
* ```
|
|
12
13
|
*/
|
|
13
|
-
list(options) {
|
|
14
|
-
return this._client.get('/v1/posts/scheduled/', options);
|
|
14
|
+
list(query = {}, options) {
|
|
15
|
+
return this._client.get('/v1/posts/scheduled/', { query, ...options });
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Cancel a scheduled post (moves it back to draft)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled.mjs","sourceRoot":"","sources":["../../src/resources/posts/scheduled.ts"],"names":[],"mappings":"AAAA,sFAAsF;
|
|
1
|
+
{"version":3,"file":"scheduled.mjs","sourceRoot":"","sources":["../../src/resources/posts/scheduled.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAGlD,OAAO,EAAE,IAAI,EAAE,sCAAkC;AAEjD,MAAM,OAAO,SAAU,SAAQ,WAAW;IACxC;;;;;;;;OAQG;IACH,IAAI,CACF,QAAgD,EAAE,EAClD,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAc,EAAE,OAAwB;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAA,uBAAuB,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;;;OAUG;IACH,UAAU,CACR,MAAc,EACd,IAA+B,EAC/B,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA,uBAAuB,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACvF,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posts.d.mts","sourceRoot":"","sources":["../src/resources/posts.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"posts.d.mts","sourceRoot":"","sources":["../src/resources/posts.ts"],"names":[],"mappings":"AAEA,kCAA8B"}
|
package/resources/posts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posts.d.ts","sourceRoot":"","sources":["../src/resources/posts.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"posts.d.ts","sourceRoot":"","sources":["../src/resources/posts.ts"],"names":[],"mappings":"AAEA,iCAA8B"}
|
package/resources/posts.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posts.mjs","sourceRoot":"","sources":["../src/resources/posts.ts"],"names":[],"mappings":"AAAA,sFAAsF"}
|
|
1
|
+
{"version":3,"file":"posts.mjs","sourceRoot":"","sources":["../src/resources/posts.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,kCAA8B"}
|
package/resources.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.mts","sourceRoot":"","sources":["src/resources.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"resources.d.mts","sourceRoot":"","sources":["src/resources.ts"],"names":[],"mappings":"AAAA,sCAAkC"}
|
package/resources.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["src/resources.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["src/resources.ts"],"names":[],"mappings":"AAAA,qCAAkC"}
|
package/resources.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.mjs","sourceRoot":"","sources":["src/resources.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"resources.mjs","sourceRoot":"","sources":["src/resources.ts"],"names":[],"mappings":"AAAA,sCAAkC"}
|
package/src/api-promise.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @deprecated Import from ./core/api-promise instead */
|
|
2
|
-
export * from
|
|
2
|
+
export * from './core/api-promise';
|
package/src/client.ts
CHANGED
|
@@ -21,12 +21,27 @@ import { Health, HealthCheckResponse, HealthVerifyAccessKeyResponse } from './re
|
|
|
21
21
|
import { Media, MediaUploadParams, MediaUploadResponse } from './resources/media';
|
|
22
22
|
import { PlatformListResponse, Platforms } from './resources/platforms';
|
|
23
23
|
import { Connect, ConnectGetOAuthURLParams, ConnectGetOAuthURLResponse } from './resources/connect/connect';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
PostCreateParams,
|
|
26
|
+
PostCreateResponse,
|
|
27
|
+
PostDeleteResponse,
|
|
28
|
+
PostListParams,
|
|
29
|
+
PostListResponse,
|
|
30
|
+
PostRetrieveResponse,
|
|
31
|
+
Posts,
|
|
32
|
+
Status,
|
|
33
|
+
} from './resources/posts/posts';
|
|
25
34
|
import { type Fetch } from './internal/builtin-types';
|
|
26
35
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
27
36
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
28
37
|
import { readEnv } from './internal/utils/env';
|
|
29
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
type LogLevel,
|
|
40
|
+
type Logger,
|
|
41
|
+
formatRequestDetails,
|
|
42
|
+
loggerFor,
|
|
43
|
+
parseLogLevel,
|
|
44
|
+
} from './internal/utils/log';
|
|
30
45
|
import { isEmptyObj } from './internal/utils/values';
|
|
31
46
|
|
|
32
47
|
export interface ClientOptions {
|
|
@@ -105,7 +120,7 @@ export interface ClientOptions {
|
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
/**
|
|
108
|
-
* API Client for interfacing with the Postpeer API.
|
|
123
|
+
* API Client for interfacing with the Postpeer API.
|
|
109
124
|
*/
|
|
110
125
|
export class Postpeer {
|
|
111
126
|
apiKey: string;
|
|
@@ -126,7 +141,7 @@ export class Postpeer {
|
|
|
126
141
|
* API Client for interfacing with the Postpeer API.
|
|
127
142
|
*
|
|
128
143
|
* @param {string | undefined} [opts.apiKey=process.env['POSTPEER_API_KEY'] ?? undefined]
|
|
129
|
-
* @param {string} [opts.baseURL=process.env['POSTPEER_BASE_URL'] ?? https://api.
|
|
144
|
+
* @param {string} [opts.baseURL=process.env['POSTPEER_BASE_URL'] ?? https://api.postpeer.dev] - Override the default base URL for the API.
|
|
130
145
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
131
146
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
132
147
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -141,14 +156,14 @@ export class Postpeer {
|
|
|
141
156
|
}: ClientOptions = {}) {
|
|
142
157
|
if (apiKey === undefined) {
|
|
143
158
|
throw new Errors.PostpeerError(
|
|
144
|
-
|
|
159
|
+
"The POSTPEER_API_KEY environment variable is missing or empty; either provide it, or instantiate the Postpeer client with an apiKey option, like new Postpeer({ apiKey: 'My API Key' }).",
|
|
145
160
|
);
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
const options: ClientOptions = {
|
|
149
164
|
apiKey,
|
|
150
165
|
...opts,
|
|
151
|
-
baseURL: baseURL || `https://api.
|
|
166
|
+
baseURL: baseURL || `https://api.postpeer.dev`,
|
|
152
167
|
};
|
|
153
168
|
|
|
154
169
|
this.baseURL = options.baseURL!;
|
|
@@ -157,12 +172,27 @@ export class Postpeer {
|
|
|
157
172
|
const defaultLogLevel = 'warn';
|
|
158
173
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
159
174
|
this.logLevel = defaultLogLevel;
|
|
160
|
-
this.logLevel =
|
|
175
|
+
this.logLevel =
|
|
176
|
+
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
177
|
+
parseLogLevel(readEnv('POSTPEER_LOG'), "process.env['POSTPEER_LOG']", this) ??
|
|
178
|
+
defaultLogLevel;
|
|
161
179
|
this.fetchOptions = options.fetchOptions;
|
|
162
180
|
this.maxRetries = options.maxRetries ?? 2;
|
|
163
181
|
this.fetch = options.fetch ?? Shims.getDefaultFetch();
|
|
164
182
|
this.#encoder = Opts.FallbackEncoder;
|
|
165
183
|
|
|
184
|
+
const customHeadersEnv = readEnv('POSTPEER_CUSTOM_HEADERS');
|
|
185
|
+
if (customHeadersEnv) {
|
|
186
|
+
const parsed: Record<string, string> = {};
|
|
187
|
+
for (const line of customHeadersEnv.split('\n')) {
|
|
188
|
+
const colon = line.indexOf(':');
|
|
189
|
+
if (colon >= 0) {
|
|
190
|
+
parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
|
|
194
|
+
}
|
|
195
|
+
|
|
166
196
|
this._options = options;
|
|
167
197
|
|
|
168
198
|
this.apiKey = apiKey;
|
|
@@ -182,7 +212,7 @@ export class Postpeer {
|
|
|
182
212
|
fetch: this.fetch,
|
|
183
213
|
fetchOptions: this.fetchOptions,
|
|
184
214
|
apiKey: this.apiKey,
|
|
185
|
-
...options
|
|
215
|
+
...options,
|
|
186
216
|
});
|
|
187
217
|
return client;
|
|
188
218
|
}
|
|
@@ -191,11 +221,11 @@ export class Postpeer {
|
|
|
191
221
|
* Check whether the base URL is set to its default.
|
|
192
222
|
*/
|
|
193
223
|
#baseURLOverridden(): boolean {
|
|
194
|
-
return this.baseURL !== 'https://api.
|
|
224
|
+
return this.baseURL !== 'https://api.postpeer.dev';
|
|
195
225
|
}
|
|
196
226
|
|
|
197
227
|
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
198
|
-
return this._options.defaultQuery
|
|
228
|
+
return this._options.defaultQuery;
|
|
199
229
|
}
|
|
200
230
|
|
|
201
231
|
protected validateHeaders({ values, nulls }: NullableHeaders) {
|
|
@@ -227,7 +257,11 @@ export class Postpeer {
|
|
|
227
257
|
return Errors.APIError.generate(status, error, message, headers);
|
|
228
258
|
}
|
|
229
259
|
|
|
230
|
-
buildURL(
|
|
260
|
+
buildURL(
|
|
261
|
+
path: string,
|
|
262
|
+
query: Record<string, unknown> | null | undefined,
|
|
263
|
+
defaultBaseURL?: string | undefined,
|
|
264
|
+
): string {
|
|
231
265
|
const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
|
|
232
266
|
const url =
|
|
233
267
|
isAbsoluteURL(path) ?
|
|
@@ -315,7 +349,9 @@ export class Postpeer {
|
|
|
315
349
|
|
|
316
350
|
await this.prepareOptions(options);
|
|
317
351
|
|
|
318
|
-
const { req, url, timeout } = await this.buildRequest(options, {
|
|
352
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
353
|
+
retryCount: maxRetries - retriesRemaining,
|
|
354
|
+
});
|
|
319
355
|
|
|
320
356
|
await this.prepareRequest(req, { url, options });
|
|
321
357
|
|
|
@@ -324,7 +360,16 @@ export class Postpeer {
|
|
|
324
360
|
const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
|
|
325
361
|
const startTime = Date.now();
|
|
326
362
|
|
|
327
|
-
loggerFor(this).debug(
|
|
363
|
+
loggerFor(this).debug(
|
|
364
|
+
`[${requestLogID}] sending request`,
|
|
365
|
+
formatRequestDetails({
|
|
366
|
+
retryOfRequestLogID,
|
|
367
|
+
method: options.method,
|
|
368
|
+
url,
|
|
369
|
+
options,
|
|
370
|
+
headers: req.headers,
|
|
371
|
+
}),
|
|
372
|
+
);
|
|
328
373
|
|
|
329
374
|
if (options.signal?.aborted) {
|
|
330
375
|
throw new Errors.APIUserAbortError();
|
|
@@ -343,21 +388,45 @@ export class Postpeer {
|
|
|
343
388
|
// deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
|
|
344
389
|
// undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
|
|
345
390
|
// others do not provide enough information to distinguish timeouts from other connection errors
|
|
346
|
-
const isTimeout =
|
|
391
|
+
const isTimeout =
|
|
392
|
+
isAbortError(response) ||
|
|
393
|
+
/timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
|
|
347
394
|
if (retriesRemaining) {
|
|
348
|
-
loggerFor(this).info(
|
|
349
|
-
|
|
395
|
+
loggerFor(this).info(
|
|
396
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,
|
|
397
|
+
);
|
|
398
|
+
loggerFor(this).debug(
|
|
399
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,
|
|
400
|
+
formatRequestDetails({
|
|
401
|
+
retryOfRequestLogID,
|
|
402
|
+
url,
|
|
403
|
+
durationMs: headersTime - startTime,
|
|
404
|
+
message: response.message,
|
|
405
|
+
}),
|
|
406
|
+
);
|
|
350
407
|
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
|
|
351
408
|
}
|
|
352
|
-
loggerFor(this).info(
|
|
353
|
-
|
|
409
|
+
loggerFor(this).info(
|
|
410
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,
|
|
411
|
+
);
|
|
412
|
+
loggerFor(this).debug(
|
|
413
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,
|
|
414
|
+
formatRequestDetails({
|
|
415
|
+
retryOfRequestLogID,
|
|
416
|
+
url,
|
|
417
|
+
durationMs: headersTime - startTime,
|
|
418
|
+
message: response.message,
|
|
419
|
+
}),
|
|
420
|
+
);
|
|
354
421
|
if (isTimeout) {
|
|
355
422
|
throw new Errors.APIConnectionTimeoutError();
|
|
356
423
|
}
|
|
357
424
|
throw new Errors.APIConnectionError({ cause: response });
|
|
358
425
|
}
|
|
359
426
|
|
|
360
|
-
const responseInfo = `[${requestLogID}${retryLogStr}] ${req.method} ${url} ${
|
|
427
|
+
const responseInfo = `[${requestLogID}${retryLogStr}] ${req.method} ${url} ${
|
|
428
|
+
response.ok ? 'succeeded' : 'failed'
|
|
429
|
+
} with status ${response.status} in ${headersTime - startTime}ms`;
|
|
361
430
|
|
|
362
431
|
if (!response.ok) {
|
|
363
432
|
const shouldRetry = await this.shouldRetry(response);
|
|
@@ -366,27 +435,60 @@ export class Postpeer {
|
|
|
366
435
|
|
|
367
436
|
// We don't need the body of this response.
|
|
368
437
|
await Shims.CancelReadableStream(response.body);
|
|
369
|
-
loggerFor(this).info(`${responseInfo} - ${retryMessage}`)
|
|
370
|
-
loggerFor(this).debug(
|
|
371
|
-
|
|
438
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
439
|
+
loggerFor(this).debug(
|
|
440
|
+
`[${requestLogID}] response error (${retryMessage})`,
|
|
441
|
+
formatRequestDetails({
|
|
442
|
+
retryOfRequestLogID,
|
|
443
|
+
url: response.url,
|
|
444
|
+
status: response.status,
|
|
445
|
+
headers: response.headers,
|
|
446
|
+
durationMs: headersTime - startTime,
|
|
447
|
+
}),
|
|
448
|
+
);
|
|
449
|
+
return this.retryRequest(
|
|
450
|
+
options,
|
|
451
|
+
retriesRemaining,
|
|
452
|
+
retryOfRequestLogID ?? requestLogID,
|
|
453
|
+
response.headers,
|
|
454
|
+
);
|
|
372
455
|
}
|
|
373
456
|
|
|
374
457
|
const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
|
|
375
458
|
|
|
376
|
-
loggerFor(this).info(`${responseInfo} - ${retryMessage}`)
|
|
459
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
377
460
|
|
|
378
461
|
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
379
462
|
const errJSON = safeJSON(errText) as any;
|
|
380
463
|
const errMessage = errJSON ? undefined : errText;
|
|
381
464
|
|
|
382
|
-
loggerFor(this).debug(
|
|
465
|
+
loggerFor(this).debug(
|
|
466
|
+
`[${requestLogID}] response error (${retryMessage})`,
|
|
467
|
+
formatRequestDetails({
|
|
468
|
+
retryOfRequestLogID,
|
|
469
|
+
url: response.url,
|
|
470
|
+
status: response.status,
|
|
471
|
+
headers: response.headers,
|
|
472
|
+
message: errMessage,
|
|
473
|
+
durationMs: Date.now() - startTime,
|
|
474
|
+
}),
|
|
475
|
+
);
|
|
383
476
|
|
|
384
477
|
const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
|
|
385
478
|
throw err;
|
|
386
479
|
}
|
|
387
480
|
|
|
388
|
-
loggerFor(this).info(responseInfo)
|
|
389
|
-
loggerFor(this).debug(
|
|
481
|
+
loggerFor(this).info(responseInfo);
|
|
482
|
+
loggerFor(this).debug(
|
|
483
|
+
`[${requestLogID}] response start`,
|
|
484
|
+
formatRequestDetails({
|
|
485
|
+
retryOfRequestLogID,
|
|
486
|
+
url: response.url,
|
|
487
|
+
status: response.status,
|
|
488
|
+
headers: response.headers,
|
|
489
|
+
durationMs: headersTime - startTime,
|
|
490
|
+
}),
|
|
491
|
+
);
|
|
390
492
|
|
|
391
493
|
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
|
392
494
|
}
|
|
@@ -403,7 +505,9 @@ export class Postpeer {
|
|
|
403
505
|
|
|
404
506
|
const timeout = setTimeout(abort, ms);
|
|
405
507
|
|
|
406
|
-
const isReadableBody =
|
|
508
|
+
const isReadableBody =
|
|
509
|
+
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
|
|
510
|
+
(typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
|
|
407
511
|
|
|
408
512
|
const fetchOptions: RequestInit = {
|
|
409
513
|
signal: controller.signal as any,
|
|
@@ -418,7 +522,6 @@ export class Postpeer {
|
|
|
418
522
|
}
|
|
419
523
|
|
|
420
524
|
try {
|
|
421
|
-
|
|
422
525
|
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
423
526
|
return await this.fetch.call(undefined, url, fetchOptions);
|
|
424
527
|
} finally {
|
|
@@ -519,11 +622,12 @@ export class Postpeer {
|
|
|
519
622
|
const req: FinalizedRequestInit = {
|
|
520
623
|
method,
|
|
521
624
|
headers: reqHeaders,
|
|
522
|
-
...(options.signal && { signal: options.signal}),
|
|
523
|
-
...((globalThis as any).ReadableStream &&
|
|
625
|
+
...(options.signal && { signal: options.signal }),
|
|
626
|
+
...((globalThis as any).ReadableStream &&
|
|
627
|
+
body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),
|
|
524
628
|
...(body && { body }),
|
|
525
|
-
...(this.fetchOptions as any ?? {}),
|
|
526
|
-
...(options.fetchOptions as any ?? {}),
|
|
629
|
+
...((this.fetchOptions as any) ?? {}),
|
|
630
|
+
...((options.fetchOptions as any) ?? {}),
|
|
527
631
|
};
|
|
528
632
|
|
|
529
633
|
return { req, url, timeout: options.timeout };
|
|
@@ -548,15 +652,17 @@ export class Postpeer {
|
|
|
548
652
|
|
|
549
653
|
const headers = buildHeaders([
|
|
550
654
|
idempotencyHeaders,
|
|
551
|
-
{
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
655
|
+
{
|
|
656
|
+
Accept: 'application/json',
|
|
657
|
+
'User-Agent': this.getUserAgent(),
|
|
658
|
+
'X-Stainless-Retry-Count': String(retryCount),
|
|
659
|
+
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
|
|
660
|
+
...getPlatformHeaders(),
|
|
661
|
+
},
|
|
556
662
|
await this.authHeaders(options),
|
|
557
663
|
this._options.defaultHeaders,
|
|
558
664
|
bodyHeaders,
|
|
559
|
-
options.headers
|
|
665
|
+
options.headers,
|
|
560
666
|
]);
|
|
561
667
|
|
|
562
668
|
this.validateHeaders(headers);
|
|
@@ -583,11 +689,9 @@ export class Postpeer {
|
|
|
583
689
|
ArrayBuffer.isView(body) ||
|
|
584
690
|
body instanceof ArrayBuffer ||
|
|
585
691
|
body instanceof DataView ||
|
|
586
|
-
(
|
|
587
|
-
typeof body === 'string' &&
|
|
692
|
+
(typeof body === 'string' &&
|
|
588
693
|
// Preserve legacy string encoding behavior for now
|
|
589
|
-
headers.values.has('content-type')
|
|
590
|
-
) ||
|
|
694
|
+
headers.values.has('content-type')) ||
|
|
591
695
|
// `Blob` is superset of `File`
|
|
592
696
|
((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||
|
|
593
697
|
// `FormData` -> `multipart/form-data`
|
|
@@ -618,7 +722,7 @@ export class Postpeer {
|
|
|
618
722
|
}
|
|
619
723
|
|
|
620
724
|
static Postpeer = this;
|
|
621
|
-
static DEFAULT_TIMEOUT = 60000 // 1 minute
|
|
725
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
622
726
|
|
|
623
727
|
static PostpeerError = Errors.PostpeerError;
|
|
624
728
|
static APIError = Errors.APIError;
|
|
@@ -650,39 +754,36 @@ Postpeer.Posts = Posts;
|
|
|
650
754
|
Postpeer.Media = Media;
|
|
651
755
|
|
|
652
756
|
export declare namespace Postpeer {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
export {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
export {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
type MediaUploadParams as MediaUploadParams
|
|
687
|
-
};
|
|
688
|
-
}
|
|
757
|
+
export type RequestOptions = Opts.RequestOptions;
|
|
758
|
+
|
|
759
|
+
export {
|
|
760
|
+
Health as Health,
|
|
761
|
+
type HealthCheckResponse as HealthCheckResponse,
|
|
762
|
+
type HealthVerifyAccessKeyResponse as HealthVerifyAccessKeyResponse,
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
export {
|
|
766
|
+
Connect as Connect,
|
|
767
|
+
type ConnectGetOAuthURLResponse as ConnectGetOAuthURLResponse,
|
|
768
|
+
type ConnectGetOAuthURLParams as ConnectGetOAuthURLParams,
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
export { Platforms as Platforms, type PlatformListResponse as PlatformListResponse };
|
|
772
|
+
|
|
773
|
+
export {
|
|
774
|
+
Posts as Posts,
|
|
775
|
+
type Status as Status,
|
|
776
|
+
type PostCreateResponse as PostCreateResponse,
|
|
777
|
+
type PostRetrieveResponse as PostRetrieveResponse,
|
|
778
|
+
type PostListResponse as PostListResponse,
|
|
779
|
+
type PostDeleteResponse as PostDeleteResponse,
|
|
780
|
+
type PostCreateParams as PostCreateParams,
|
|
781
|
+
type PostListParams as PostListParams,
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
export {
|
|
785
|
+
Media as Media,
|
|
786
|
+
type MediaUploadResponse as MediaUploadResponse,
|
|
787
|
+
type MediaUploadParams as MediaUploadParams,
|
|
788
|
+
};
|
|
789
|
+
}
|
package/src/core/api-promise.ts
CHANGED
|
@@ -16,7 +16,10 @@ export class APIPromise<T> extends Promise<T> {
|
|
|
16
16
|
constructor(
|
|
17
17
|
client: Postpeer,
|
|
18
18
|
private responsePromise: Promise<APIResponseProps>,
|
|
19
|
-
private parseResponse: (
|
|
19
|
+
private parseResponse: (
|
|
20
|
+
client: Postpeer,
|
|
21
|
+
props: APIResponseProps,
|
|
22
|
+
) => PromiseOrValue<T> = defaultParseResponse,
|
|
20
23
|
) {
|
|
21
24
|
super((resolve) => {
|
|
22
25
|
// this is maybe a bit weird but this has to be a no-op to not implicitly
|
|
@@ -28,7 +31,9 @@ export class APIPromise<T> extends Promise<T> {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
_thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
|
|
31
|
-
return new APIPromise(this.#client, this.responsePromise, async (client, props) =>
|
|
34
|
+
return new APIPromise(this.#client, this.responsePromise, async (client, props) =>
|
|
35
|
+
transform(await this.parseResponse(client, props), props),
|
|
36
|
+
);
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
/**
|
package/src/core/error.ts
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { castToError } from '../internal/errors';
|
|
4
4
|
|
|
5
|
-
export class PostpeerError extends Error {
|
|
6
|
-
}
|
|
5
|
+
export class PostpeerError extends Error {}
|
|
7
6
|
|
|
8
|
-
export class APIError<
|
|
7
|
+
export class APIError<
|
|
8
|
+
TStatus extends number | undefined = number | undefined,
|
|
9
|
+
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
|
+
TError extends Object | undefined = Object | undefined,
|
|
11
|
+
> extends PostpeerError {
|
|
9
12
|
/** HTTP status for the response that caused the error */
|
|
10
13
|
readonly status: TStatus;
|
|
11
14
|
/** HTTP headers for the response that caused the error */
|
|
@@ -13,9 +16,6 @@ export class APIError<TStatus extends number | undefined = number | undefined, T
|
|
|
13
16
|
/** JSON body of the response that caused the error */
|
|
14
17
|
readonly error: TError;
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
;
|
|
18
|
-
|
|
19
19
|
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
|
|
20
20
|
super(`${APIError.makeMessage(status, error, message)}`);
|
|
21
21
|
this.status = status;
|
|
@@ -26,7 +26,8 @@ export class APIError<TStatus extends number | undefined = number | undefined, T
|
|
|
26
26
|
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
27
27
|
const msg =
|
|
28
28
|
error?.message ?
|
|
29
|
-
typeof error.message === 'string' ?
|
|
29
|
+
typeof error.message === 'string' ?
|
|
30
|
+
error.message
|
|
30
31
|
: JSON.stringify(error.message)
|
|
31
32
|
: error ? JSON.stringify(error)
|
|
32
33
|
: message;
|
|
@@ -43,7 +44,12 @@ export class APIError<TStatus extends number | undefined = number | undefined, T
|
|
|
43
44
|
return '(no status code or body)';
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
static generate(
|
|
47
|
+
static generate(
|
|
48
|
+
status: number | undefined,
|
|
49
|
+
errorResponse: Object | undefined,
|
|
50
|
+
message: string | undefined,
|
|
51
|
+
headers: Headers | undefined,
|
|
52
|
+
): APIError {
|
|
47
53
|
if (!status || !headers) {
|
|
48
54
|
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
|
49
55
|
}
|
|
@@ -107,26 +113,18 @@ export class APIConnectionTimeoutError extends APIConnectionError {
|
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
115
|
|
|
110
|
-
export class BadRequestError extends APIError<400, Headers> {
|
|
111
|
-
}
|
|
116
|
+
export class BadRequestError extends APIError<400, Headers> {}
|
|
112
117
|
|
|
113
|
-
export class AuthenticationError extends APIError<401, Headers> {
|
|
114
|
-
}
|
|
118
|
+
export class AuthenticationError extends APIError<401, Headers> {}
|
|
115
119
|
|
|
116
|
-
export class PermissionDeniedError extends APIError<403, Headers> {
|
|
117
|
-
}
|
|
120
|
+
export class PermissionDeniedError extends APIError<403, Headers> {}
|
|
118
121
|
|
|
119
|
-
export class NotFoundError extends APIError<404, Headers> {
|
|
120
|
-
}
|
|
122
|
+
export class NotFoundError extends APIError<404, Headers> {}
|
|
121
123
|
|
|
122
|
-
export class ConflictError extends APIError<409, Headers> {
|
|
123
|
-
}
|
|
124
|
+
export class ConflictError extends APIError<409, Headers> {}
|
|
124
125
|
|
|
125
|
-
export class UnprocessableEntityError extends APIError<422, Headers> {
|
|
126
|
-
}
|
|
126
|
+
export class UnprocessableEntityError extends APIError<422, Headers> {}
|
|
127
127
|
|
|
128
|
-
export class RateLimitError extends APIError<429, Headers> {
|
|
129
|
-
}
|
|
128
|
+
export class RateLimitError extends APIError<429, Headers> {}
|
|
130
129
|
|
|
131
|
-
export class InternalServerError extends APIError<number, Headers> {
|
|
132
|
-
}
|
|
130
|
+
export class InternalServerError extends APIError<number, Headers> {}
|
package/src/error.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @deprecated Import from ./core/error instead */
|
|
2
|
-
export * from
|
|
2
|
+
export * from './core/error';
|