@postpeer/node 0.6.0 → 0.8.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 +5 -101
- package/README.md +91 -317
- package/dist/index.cjs +1709 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3484 -0
- package/dist/index.d.ts +3484 -0
- package/dist/index.js +1690 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -131
- package/api-promise.d.mts +0 -2
- package/api-promise.d.mts.map +0 -1
- package/api-promise.d.ts +0 -2
- package/api-promise.d.ts.map +0 -1
- package/api-promise.js +0 -6
- package/api-promise.js.map +0 -1
- package/api-promise.mjs +0 -2
- package/api-promise.mjs.map +0 -1
- package/client.d.mts +0 -190
- package/client.d.mts.map +0 -1
- package/client.d.ts +0 -190
- package/client.d.ts.map +0 -1
- package/client.js +0 -485
- package/client.js.map +0 -1
- package/client.mjs +0 -481
- package/client.mjs.map +0 -1
- package/core/api-promise.d.mts +0 -46
- package/core/api-promise.d.mts.map +0 -1
- package/core/api-promise.d.ts +0 -46
- package/core/api-promise.d.ts.map +0 -1
- package/core/api-promise.js +0 -74
- package/core/api-promise.js.map +0 -1
- package/core/api-promise.mjs +0 -70
- package/core/api-promise.mjs.map +0 -1
- package/core/error.d.mts +0 -46
- package/core/error.d.mts.map +0 -1
- package/core/error.d.ts +0 -46
- package/core/error.d.ts.map +0 -1
- package/core/error.js +0 -113
- package/core/error.js.map +0 -1
- package/core/error.mjs +0 -97
- package/core/error.mjs.map +0 -1
- package/core/resource.d.mts +0 -6
- package/core/resource.d.mts.map +0 -1
- package/core/resource.d.ts +0 -6
- package/core/resource.d.ts.map +0 -1
- package/core/resource.js +0 -11
- package/core/resource.js.map +0 -1
- package/core/resource.mjs +0 -7
- package/core/resource.mjs.map +0 -1
- package/core/uploads.d.mts +0 -3
- package/core/uploads.d.mts.map +0 -1
- package/core/uploads.d.ts +0 -3
- package/core/uploads.d.ts.map +0 -1
- package/core/uploads.js +0 -6
- package/core/uploads.js.map +0 -1
- package/core/uploads.mjs +0 -2
- package/core/uploads.mjs.map +0 -1
- package/error.d.mts +0 -2
- package/error.d.mts.map +0 -1
- package/error.d.ts +0 -2
- package/error.d.ts.map +0 -1
- package/error.js +0 -6
- package/error.js.map +0 -1
- package/error.mjs +0 -2
- package/error.mjs.map +0 -1
- package/index.d.mts +0 -6
- package/index.d.mts.map +0 -1
- package/index.d.ts +0 -6
- package/index.d.ts.map +0 -1
- package/index.js +0 -30
- package/index.js.map +0 -1
- package/index.mjs +0 -7
- package/index.mjs.map +0 -1
- package/internal/builtin-types.d.mts +0 -73
- package/internal/builtin-types.d.mts.map +0 -1
- package/internal/builtin-types.d.ts +0 -73
- package/internal/builtin-types.d.ts.map +0 -1
- package/internal/builtin-types.js +0 -4
- package/internal/builtin-types.js.map +0 -1
- package/internal/builtin-types.mjs +0 -3
- package/internal/builtin-types.mjs.map +0 -1
- package/internal/detect-platform.d.mts +0 -15
- package/internal/detect-platform.d.mts.map +0 -1
- package/internal/detect-platform.d.ts +0 -15
- package/internal/detect-platform.d.ts.map +0 -1
- package/internal/detect-platform.js +0 -162
- package/internal/detect-platform.js.map +0 -1
- package/internal/detect-platform.mjs +0 -157
- package/internal/detect-platform.mjs.map +0 -1
- package/internal/errors.d.mts +0 -3
- package/internal/errors.d.mts.map +0 -1
- package/internal/errors.d.ts +0 -3
- package/internal/errors.d.ts.map +0 -1
- package/internal/errors.js +0 -41
- package/internal/errors.js.map +0 -1
- package/internal/errors.mjs +0 -36
- package/internal/errors.mjs.map +0 -1
- package/internal/headers.d.mts +0 -20
- package/internal/headers.d.mts.map +0 -1
- package/internal/headers.d.ts +0 -20
- package/internal/headers.d.ts.map +0 -1
- package/internal/headers.js +0 -79
- package/internal/headers.js.map +0 -1
- package/internal/headers.mjs +0 -74
- package/internal/headers.mjs.map +0 -1
- package/internal/parse.d.mts +0 -12
- package/internal/parse.d.mts.map +0 -1
- package/internal/parse.d.ts +0 -12
- package/internal/parse.d.ts.map +0 -1
- package/internal/parse.js +0 -40
- package/internal/parse.js.map +0 -1
- package/internal/parse.mjs +0 -37
- package/internal/parse.mjs.map +0 -1
- package/internal/qs/formats.d.mts +0 -7
- package/internal/qs/formats.d.mts.map +0 -1
- package/internal/qs/formats.d.ts +0 -7
- package/internal/qs/formats.d.ts.map +0 -1
- package/internal/qs/formats.js +0 -13
- package/internal/qs/formats.js.map +0 -1
- package/internal/qs/formats.mjs +0 -9
- package/internal/qs/formats.mjs.map +0 -1
- package/internal/qs/index.d.mts +0 -10
- package/internal/qs/index.d.mts.map +0 -1
- package/internal/qs/index.d.ts +0 -10
- package/internal/qs/index.d.ts.map +0 -1
- package/internal/qs/index.js +0 -14
- package/internal/qs/index.js.map +0 -1
- package/internal/qs/index.mjs +0 -10
- package/internal/qs/index.mjs.map +0 -1
- package/internal/qs/stringify.d.mts +0 -3
- package/internal/qs/stringify.d.mts.map +0 -1
- package/internal/qs/stringify.d.ts +0 -3
- package/internal/qs/stringify.d.ts.map +0 -1
- package/internal/qs/stringify.js +0 -277
- package/internal/qs/stringify.js.map +0 -1
- package/internal/qs/stringify.mjs +0 -274
- package/internal/qs/stringify.mjs.map +0 -1
- package/internal/qs/types.d.mts +0 -57
- package/internal/qs/types.d.mts.map +0 -1
- package/internal/qs/types.d.ts +0 -57
- package/internal/qs/types.d.ts.map +0 -1
- package/internal/qs/types.js +0 -3
- package/internal/qs/types.js.map +0 -1
- package/internal/qs/types.mjs +0 -2
- package/internal/qs/types.mjs.map +0 -1
- package/internal/qs/utils.d.mts +0 -15
- package/internal/qs/utils.d.mts.map +0 -1
- package/internal/qs/utils.d.ts +0 -15
- package/internal/qs/utils.d.ts.map +0 -1
- package/internal/qs/utils.js +0 -230
- package/internal/qs/utils.js.map +0 -1
- package/internal/qs/utils.mjs +0 -217
- package/internal/qs/utils.mjs.map +0 -1
- package/internal/request-options.d.mts +0 -75
- package/internal/request-options.d.mts.map +0 -1
- package/internal/request-options.d.ts +0 -75
- package/internal/request-options.d.ts.map +0 -1
- package/internal/request-options.js +0 -14
- package/internal/request-options.js.map +0 -1
- package/internal/request-options.mjs +0 -10
- package/internal/request-options.mjs.map +0 -1
- package/internal/shim-types.d.mts +0 -17
- package/internal/shim-types.d.mts.map +0 -1
- package/internal/shim-types.d.ts +0 -17
- package/internal/shim-types.d.ts.map +0 -1
- package/internal/shim-types.js +0 -4
- package/internal/shim-types.js.map +0 -1
- package/internal/shim-types.mjs +0 -3
- package/internal/shim-types.mjs.map +0 -1
- package/internal/shims.d.mts +0 -20
- package/internal/shims.d.mts.map +0 -1
- package/internal/shims.d.ts +0 -20
- package/internal/shims.d.ts.map +0 -1
- package/internal/shims.js +0 -92
- package/internal/shims.js.map +0 -1
- package/internal/shims.mjs +0 -85
- package/internal/shims.mjs.map +0 -1
- package/internal/to-file.d.mts +0 -45
- package/internal/to-file.d.mts.map +0 -1
- package/internal/to-file.d.ts +0 -45
- package/internal/to-file.d.ts.map +0 -1
- package/internal/to-file.js +0 -91
- package/internal/to-file.js.map +0 -1
- package/internal/to-file.mjs +0 -88
- package/internal/to-file.mjs.map +0 -1
- package/internal/tslib.js +0 -81
- package/internal/tslib.mjs +0 -17
- package/internal/types.d.mts +0 -69
- package/internal/types.d.mts.map +0 -1
- package/internal/types.d.ts +0 -69
- package/internal/types.d.ts.map +0 -1
- package/internal/types.js +0 -4
- package/internal/types.js.map +0 -1
- package/internal/types.mjs +0 -3
- package/internal/types.mjs.map +0 -1
- package/internal/uploads.d.mts +0 -42
- package/internal/uploads.d.mts.map +0 -1
- package/internal/uploads.d.ts +0 -42
- package/internal/uploads.d.ts.map +0 -1
- package/internal/uploads.js +0 -141
- package/internal/uploads.js.map +0 -1
- package/internal/uploads.mjs +0 -131
- package/internal/uploads.mjs.map +0 -1
- package/internal/utils/base64.d.mts +0 -3
- package/internal/utils/base64.d.mts.map +0 -1
- package/internal/utils/base64.d.ts +0 -3
- package/internal/utils/base64.d.ts.map +0 -1
- package/internal/utils/base64.js +0 -38
- package/internal/utils/base64.js.map +0 -1
- package/internal/utils/base64.mjs +0 -33
- package/internal/utils/base64.mjs.map +0 -1
- package/internal/utils/bytes.d.mts +0 -4
- package/internal/utils/bytes.d.mts.map +0 -1
- package/internal/utils/bytes.d.ts +0 -4
- package/internal/utils/bytes.d.ts.map +0 -1
- package/internal/utils/bytes.js +0 -31
- package/internal/utils/bytes.js.map +0 -1
- package/internal/utils/bytes.mjs +0 -26
- package/internal/utils/bytes.mjs.map +0 -1
- package/internal/utils/env.d.mts +0 -9
- package/internal/utils/env.d.mts.map +0 -1
- package/internal/utils/env.d.ts +0 -9
- package/internal/utils/env.d.ts.map +0 -1
- package/internal/utils/env.js +0 -22
- package/internal/utils/env.js.map +0 -1
- package/internal/utils/env.mjs +0 -18
- package/internal/utils/env.mjs.map +0 -1
- package/internal/utils/log.d.mts +0 -37
- package/internal/utils/log.d.mts.map +0 -1
- package/internal/utils/log.d.ts +0 -37
- package/internal/utils/log.d.ts.map +0 -1
- package/internal/utils/log.js +0 -86
- package/internal/utils/log.js.map +0 -1
- package/internal/utils/log.mjs +0 -80
- package/internal/utils/log.mjs.map +0 -1
- package/internal/utils/path.d.mts +0 -15
- package/internal/utils/path.d.mts.map +0 -1
- package/internal/utils/path.d.ts +0 -15
- package/internal/utils/path.d.ts.map +0 -1
- package/internal/utils/path.js +0 -79
- package/internal/utils/path.js.map +0 -1
- package/internal/utils/path.mjs +0 -74
- package/internal/utils/path.mjs.map +0 -1
- package/internal/utils/query.d.mts +0 -2
- package/internal/utils/query.d.mts.map +0 -1
- package/internal/utils/query.d.ts +0 -2
- package/internal/utils/query.d.ts.map +0 -1
- package/internal/utils/query.js +0 -10
- package/internal/utils/query.js.map +0 -1
- package/internal/utils/query.mjs +0 -6
- package/internal/utils/query.mjs.map +0 -1
- package/internal/utils/sleep.d.mts +0 -2
- package/internal/utils/sleep.d.mts.map +0 -1
- package/internal/utils/sleep.d.ts +0 -2
- package/internal/utils/sleep.d.ts.map +0 -1
- package/internal/utils/sleep.js +0 -7
- package/internal/utils/sleep.js.map +0 -1
- package/internal/utils/sleep.mjs +0 -3
- package/internal/utils/sleep.mjs.map +0 -1
- package/internal/utils/uuid.d.mts +0 -5
- package/internal/utils/uuid.d.mts.map +0 -1
- package/internal/utils/uuid.d.ts +0 -5
- package/internal/utils/uuid.d.ts.map +0 -1
- package/internal/utils/uuid.js +0 -19
- package/internal/utils/uuid.js.map +0 -1
- package/internal/utils/uuid.mjs +0 -15
- package/internal/utils/uuid.mjs.map +0 -1
- package/internal/utils/values.d.mts +0 -18
- package/internal/utils/values.d.mts.map +0 -1
- package/internal/utils/values.d.ts +0 -18
- package/internal/utils/values.d.ts.map +0 -1
- package/internal/utils/values.js +0 -112
- package/internal/utils/values.js.map +0 -1
- package/internal/utils/values.mjs +0 -94
- package/internal/utils/values.mjs.map +0 -1
- package/internal/utils.d.mts +0 -8
- package/internal/utils.d.mts.map +0 -1
- package/internal/utils.d.ts +0 -8
- package/internal/utils.d.ts.map +0 -1
- package/internal/utils.js +0 -12
- package/internal/utils.js.map +0 -1
- package/internal/utils.mjs +0 -9
- package/internal/utils.mjs.map +0 -1
- package/resource.d.mts +0 -2
- package/resource.d.mts.map +0 -1
- package/resource.d.ts +0 -2
- package/resource.d.ts.map +0 -1
- package/resource.js +0 -6
- package/resource.js.map +0 -1
- package/resource.mjs +0 -2
- package/resource.mjs.map +0 -1
- package/resources/connect/connect.d.mts +0 -26
- package/resources/connect/connect.d.mts.map +0 -1
- package/resources/connect/connect.d.ts +0 -26
- package/resources/connect/connect.d.ts.map +0 -1
- package/resources/connect/connect.js +0 -24
- package/resources/connect/connect.js.map +0 -1
- package/resources/connect/connect.mjs +0 -19
- package/resources/connect/connect.mjs.map +0 -1
- package/resources/connect/index.d.mts +0 -3
- package/resources/connect/index.d.mts.map +0 -1
- package/resources/connect/index.d.ts +0 -3
- package/resources/connect/index.d.ts.map +0 -1
- package/resources/connect/index.js +0 -9
- package/resources/connect/index.js.map +0 -1
- package/resources/connect/index.mjs +0 -4
- package/resources/connect/index.mjs.map +0 -1
- package/resources/connect/integrations.d.mts +0 -64
- package/resources/connect/integrations.d.mts.map +0 -1
- package/resources/connect/integrations.d.ts +0 -64
- package/resources/connect/integrations.d.ts.map +0 -1
- package/resources/connect/integrations.js +0 -22
- package/resources/connect/integrations.js.map +0 -1
- package/resources/connect/integrations.mjs +0 -18
- package/resources/connect/integrations.mjs.map +0 -1
- package/resources/connect.d.mts +0 -2
- package/resources/connect.d.mts.map +0 -1
- package/resources/connect.d.ts +0 -2
- package/resources/connect.d.ts.map +0 -1
- package/resources/connect.js +0 -6
- package/resources/connect.js.map +0 -1
- package/resources/connect.mjs +0 -3
- package/resources/connect.mjs.map +0 -1
- package/resources/health.d.mts +0 -23
- package/resources/health.d.mts.map +0 -1
- package/resources/health.d.ts +0 -23
- package/resources/health.d.ts.map +0 -1
- package/resources/health.js +0 -21
- package/resources/health.js.map +0 -1
- package/resources/health.mjs +0 -17
- package/resources/health.mjs.map +0 -1
- package/resources/index.d.mts +0 -6
- package/resources/index.d.mts.map +0 -1
- package/resources/index.d.ts +0 -6
- package/resources/index.d.ts.map +0 -1
- package/resources/index.js +0 -15
- package/resources/index.js.map +0 -1
- package/resources/index.mjs +0 -7
- package/resources/index.mjs.map +0 -1
- package/resources/media.d.mts +0 -27
- package/resources/media.d.mts.map +0 -1
- package/resources/media.d.ts +0 -27
- package/resources/media.d.ts.map +0 -1
- package/resources/media.js +0 -15
- package/resources/media.js.map +0 -1
- package/resources/media.mjs +0 -11
- package/resources/media.mjs.map +0 -1
- package/resources/platforms.d.mts +0 -22
- package/resources/platforms.d.mts.map +0 -1
- package/resources/platforms.d.ts +0 -22
- package/resources/platforms.d.ts.map +0 -1
- package/resources/platforms.js +0 -15
- package/resources/platforms.js.map +0 -1
- package/resources/platforms.mjs +0 -11
- package/resources/platforms.mjs.map +0 -1
- package/resources/posts/index.d.mts +0 -3
- package/resources/posts/index.d.mts.map +0 -1
- package/resources/posts/index.d.ts +0 -3
- package/resources/posts/index.d.ts.map +0 -1
- package/resources/posts/index.js +0 -9
- package/resources/posts/index.js.map +0 -1
- package/resources/posts/index.mjs +0 -4
- package/resources/posts/index.mjs.map +0 -1
- package/resources/posts/posts.d.mts +0 -279
- package/resources/posts/posts.d.mts.map +0 -1
- package/resources/posts/posts.d.ts +0 -279
- package/resources/posts/posts.d.ts.map +0 -1
- package/resources/posts/posts.js +0 -69
- package/resources/posts/posts.js.map +0 -1
- package/resources/posts/posts.mjs +0 -64
- package/resources/posts/posts.mjs.map +0 -1
- package/resources/posts/scheduled.d.mts +0 -105
- package/resources/posts/scheduled.d.mts.map +0 -1
- package/resources/posts/scheduled.d.ts +0 -105
- package/resources/posts/scheduled.d.ts.map +0 -1
- package/resources/posts/scheduled.js +0 -48
- package/resources/posts/scheduled.js.map +0 -1
- package/resources/posts/scheduled.mjs +0 -44
- package/resources/posts/scheduled.mjs.map +0 -1
- package/resources/posts.d.mts +0 -2
- package/resources/posts.d.mts.map +0 -1
- package/resources/posts.d.ts +0 -2
- package/resources/posts.d.ts.map +0 -1
- package/resources/posts.js +0 -6
- package/resources/posts.js.map +0 -1
- package/resources/posts.mjs +0 -3
- package/resources/posts.mjs.map +0 -1
- package/resources.d.mts +0 -2
- package/resources.d.mts.map +0 -1
- package/resources.d.ts +0 -2
- package/resources.d.ts.map +0 -1
- package/resources.js +0 -5
- package/resources.js.map +0 -1
- package/resources.mjs +0 -2
- package/resources.mjs.map +0 -1
- package/src/api-promise.ts +0 -2
- package/src/client.ts +0 -789
- package/src/core/README.md +0 -3
- package/src/core/api-promise.ts +0 -92
- package/src/core/error.ts +0 -130
- package/src/core/resource.ts +0 -11
- package/src/core/uploads.ts +0 -2
- package/src/error.ts +0 -2
- package/src/index.ts +0 -22
- package/src/internal/README.md +0 -3
- package/src/internal/builtin-types.ts +0 -93
- package/src/internal/detect-platform.ts +0 -196
- package/src/internal/errors.ts +0 -33
- package/src/internal/headers.ts +0 -97
- package/src/internal/parse.ts +0 -56
- package/src/internal/qs/LICENSE.md +0 -13
- package/src/internal/qs/README.md +0 -3
- package/src/internal/qs/formats.ts +0 -10
- package/src/internal/qs/index.ts +0 -13
- package/src/internal/qs/stringify.ts +0 -385
- package/src/internal/qs/types.ts +0 -71
- package/src/internal/qs/utils.ts +0 -265
- package/src/internal/request-options.ts +0 -91
- package/src/internal/shim-types.ts +0 -26
- package/src/internal/shims.ts +0 -107
- package/src/internal/to-file.ts +0 -154
- package/src/internal/types.ts +0 -93
- package/src/internal/uploads.ts +0 -187
- package/src/internal/utils/base64.ts +0 -40
- package/src/internal/utils/bytes.ts +0 -32
- package/src/internal/utils/env.ts +0 -18
- package/src/internal/utils/log.ts +0 -127
- package/src/internal/utils/path.ts +0 -88
- package/src/internal/utils/query.ts +0 -7
- package/src/internal/utils/sleep.ts +0 -3
- package/src/internal/utils/uuid.ts +0 -17
- package/src/internal/utils/values.ts +0 -105
- package/src/internal/utils.ts +0 -9
- package/src/lib/.keep +0 -4
- package/src/resource.ts +0 -2
- package/src/resources/connect/connect.ts +0 -55
- package/src/resources/connect/index.ts +0 -9
- package/src/resources/connect/integrations.ts +0 -96
- package/src/resources/connect.ts +0 -3
- package/src/resources/health.ts +0 -36
- package/src/resources/index.ts +0 -16
- package/src/resources/media.ts +0 -38
- package/src/resources/platforms.ts +0 -30
- package/src/resources/posts/index.ts +0 -19
- package/src/resources/posts/posts.ts +0 -399
- package/src/resources/posts/scheduled.ts +0 -147
- package/src/resources/posts.ts +0 -3
- package/src/resources.ts +0 -1
- package/src/tsconfig.json +0 -11
- package/src/uploads.ts +0 -2
- package/src/version.ts +0 -1
- package/uploads.d.mts +0 -2
- package/uploads.d.mts.map +0 -1
- package/uploads.d.ts +0 -2
- package/uploads.d.ts.map +0 -1
- package/uploads.js +0 -6
- package/uploads.js.map +0 -1
- package/uploads.mjs +0 -2
- package/uploads.mjs.map +0 -1
- package/version.d.mts +0 -2
- package/version.d.mts.map +0 -1
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js +0 -5
- package/version.js.map +0 -1
- package/version.mjs +0 -2
- package/version.mjs.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1709 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
|
|
8
|
+
// src/generated/core/bodySerializer.gen.ts
|
|
9
|
+
var jsonBodySerializer = {
|
|
10
|
+
bodySerializer: /* @__PURE__ */ __name((body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value), "bodySerializer")
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/generated/core/serverSentEvents.gen.ts
|
|
14
|
+
function createSseClient({
|
|
15
|
+
onRequest,
|
|
16
|
+
onSseError,
|
|
17
|
+
onSseEvent,
|
|
18
|
+
responseTransformer,
|
|
19
|
+
responseValidator,
|
|
20
|
+
sseDefaultRetryDelay,
|
|
21
|
+
sseMaxRetryAttempts,
|
|
22
|
+
sseMaxRetryDelay,
|
|
23
|
+
sseSleepFn,
|
|
24
|
+
url,
|
|
25
|
+
...options
|
|
26
|
+
}) {
|
|
27
|
+
let lastEventId;
|
|
28
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
29
|
+
const createStream = /* @__PURE__ */ __name(async function* () {
|
|
30
|
+
let retryDelay2 = sseDefaultRetryDelay ?? 3e3;
|
|
31
|
+
let attempt = 0;
|
|
32
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
33
|
+
while (true) {
|
|
34
|
+
if (signal.aborted) break;
|
|
35
|
+
attempt++;
|
|
36
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
37
|
+
if (lastEventId !== void 0) {
|
|
38
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const requestInit = {
|
|
42
|
+
redirect: "follow",
|
|
43
|
+
...options,
|
|
44
|
+
body: options.serializedBody,
|
|
45
|
+
headers,
|
|
46
|
+
signal
|
|
47
|
+
};
|
|
48
|
+
let request = new Request(url, requestInit);
|
|
49
|
+
if (onRequest) {
|
|
50
|
+
request = await onRequest(url, requestInit);
|
|
51
|
+
}
|
|
52
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
53
|
+
const response = await _fetch(request);
|
|
54
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
55
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
56
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
57
|
+
let buffer = "";
|
|
58
|
+
const abortHandler = /* @__PURE__ */ __name(() => {
|
|
59
|
+
try {
|
|
60
|
+
reader.cancel();
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}, "abortHandler");
|
|
64
|
+
signal.addEventListener("abort", abortHandler);
|
|
65
|
+
try {
|
|
66
|
+
while (true) {
|
|
67
|
+
const { done, value } = await reader.read();
|
|
68
|
+
if (done) break;
|
|
69
|
+
buffer += value;
|
|
70
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
71
|
+
const chunks = buffer.split("\n\n");
|
|
72
|
+
buffer = chunks.pop() ?? "";
|
|
73
|
+
for (const chunk of chunks) {
|
|
74
|
+
const lines = chunk.split("\n");
|
|
75
|
+
const dataLines = [];
|
|
76
|
+
let eventName;
|
|
77
|
+
for (const line of lines) {
|
|
78
|
+
if (line.startsWith("data:")) {
|
|
79
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
80
|
+
} else if (line.startsWith("event:")) {
|
|
81
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
82
|
+
} else if (line.startsWith("id:")) {
|
|
83
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
84
|
+
} else if (line.startsWith("retry:")) {
|
|
85
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
86
|
+
if (!Number.isNaN(parsed)) {
|
|
87
|
+
retryDelay2 = parsed;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let data;
|
|
92
|
+
let parsedJson = false;
|
|
93
|
+
if (dataLines.length) {
|
|
94
|
+
const rawData = dataLines.join("\n");
|
|
95
|
+
try {
|
|
96
|
+
data = JSON.parse(rawData);
|
|
97
|
+
parsedJson = true;
|
|
98
|
+
} catch {
|
|
99
|
+
data = rawData;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (parsedJson) {
|
|
103
|
+
if (responseValidator) {
|
|
104
|
+
await responseValidator(data);
|
|
105
|
+
}
|
|
106
|
+
if (responseTransformer) {
|
|
107
|
+
data = await responseTransformer(data);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
onSseEvent?.({
|
|
111
|
+
data,
|
|
112
|
+
event: eventName,
|
|
113
|
+
id: lastEventId,
|
|
114
|
+
retry: retryDelay2
|
|
115
|
+
});
|
|
116
|
+
if (dataLines.length) {
|
|
117
|
+
yield data;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
signal.removeEventListener("abort", abortHandler);
|
|
123
|
+
reader.releaseLock();
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
} catch (error) {
|
|
127
|
+
onSseError?.(error);
|
|
128
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
const backoff = Math.min(retryDelay2 * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
132
|
+
await sleep(backoff);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}, "createStream");
|
|
136
|
+
const stream = createStream();
|
|
137
|
+
return { stream };
|
|
138
|
+
}
|
|
139
|
+
__name(createSseClient, "createSseClient");
|
|
140
|
+
|
|
141
|
+
// src/generated/core/pathSerializer.gen.ts
|
|
142
|
+
var separatorArrayExplode = /* @__PURE__ */ __name((style) => {
|
|
143
|
+
switch (style) {
|
|
144
|
+
case "label":
|
|
145
|
+
return ".";
|
|
146
|
+
case "matrix":
|
|
147
|
+
return ";";
|
|
148
|
+
case "simple":
|
|
149
|
+
return ",";
|
|
150
|
+
default:
|
|
151
|
+
return "&";
|
|
152
|
+
}
|
|
153
|
+
}, "separatorArrayExplode");
|
|
154
|
+
var separatorArrayNoExplode = /* @__PURE__ */ __name((style) => {
|
|
155
|
+
switch (style) {
|
|
156
|
+
case "form":
|
|
157
|
+
return ",";
|
|
158
|
+
case "pipeDelimited":
|
|
159
|
+
return "|";
|
|
160
|
+
case "spaceDelimited":
|
|
161
|
+
return "%20";
|
|
162
|
+
default:
|
|
163
|
+
return ",";
|
|
164
|
+
}
|
|
165
|
+
}, "separatorArrayNoExplode");
|
|
166
|
+
var separatorObjectExplode = /* @__PURE__ */ __name((style) => {
|
|
167
|
+
switch (style) {
|
|
168
|
+
case "label":
|
|
169
|
+
return ".";
|
|
170
|
+
case "matrix":
|
|
171
|
+
return ";";
|
|
172
|
+
case "simple":
|
|
173
|
+
return ",";
|
|
174
|
+
default:
|
|
175
|
+
return "&";
|
|
176
|
+
}
|
|
177
|
+
}, "separatorObjectExplode");
|
|
178
|
+
var serializeArrayParam = /* @__PURE__ */ __name(({
|
|
179
|
+
allowReserved,
|
|
180
|
+
explode,
|
|
181
|
+
name,
|
|
182
|
+
style,
|
|
183
|
+
value
|
|
184
|
+
}) => {
|
|
185
|
+
if (!explode) {
|
|
186
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
187
|
+
switch (style) {
|
|
188
|
+
case "label":
|
|
189
|
+
return `.${joinedValues2}`;
|
|
190
|
+
case "matrix":
|
|
191
|
+
return `;${name}=${joinedValues2}`;
|
|
192
|
+
case "simple":
|
|
193
|
+
return joinedValues2;
|
|
194
|
+
default:
|
|
195
|
+
return `${name}=${joinedValues2}`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const separator = separatorArrayExplode(style);
|
|
199
|
+
const joinedValues = value.map((v) => {
|
|
200
|
+
if (style === "label" || style === "simple") {
|
|
201
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
202
|
+
}
|
|
203
|
+
return serializePrimitiveParam({
|
|
204
|
+
allowReserved,
|
|
205
|
+
name,
|
|
206
|
+
value: v
|
|
207
|
+
});
|
|
208
|
+
}).join(separator);
|
|
209
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
210
|
+
}, "serializeArrayParam");
|
|
211
|
+
var serializePrimitiveParam = /* @__PURE__ */ __name(({
|
|
212
|
+
allowReserved,
|
|
213
|
+
name,
|
|
214
|
+
value
|
|
215
|
+
}) => {
|
|
216
|
+
if (value === void 0 || value === null) {
|
|
217
|
+
return "";
|
|
218
|
+
}
|
|
219
|
+
if (typeof value === "object") {
|
|
220
|
+
throw new Error(
|
|
221
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
225
|
+
}, "serializePrimitiveParam");
|
|
226
|
+
var serializeObjectParam = /* @__PURE__ */ __name(({
|
|
227
|
+
allowReserved,
|
|
228
|
+
explode,
|
|
229
|
+
name,
|
|
230
|
+
style,
|
|
231
|
+
value,
|
|
232
|
+
valueOnly
|
|
233
|
+
}) => {
|
|
234
|
+
if (value instanceof Date) {
|
|
235
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
236
|
+
}
|
|
237
|
+
if (style !== "deepObject" && !explode) {
|
|
238
|
+
let values = [];
|
|
239
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
240
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
241
|
+
});
|
|
242
|
+
const joinedValues2 = values.join(",");
|
|
243
|
+
switch (style) {
|
|
244
|
+
case "form":
|
|
245
|
+
return `${name}=${joinedValues2}`;
|
|
246
|
+
case "label":
|
|
247
|
+
return `.${joinedValues2}`;
|
|
248
|
+
case "matrix":
|
|
249
|
+
return `;${name}=${joinedValues2}`;
|
|
250
|
+
default:
|
|
251
|
+
return joinedValues2;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const separator = separatorObjectExplode(style);
|
|
255
|
+
const joinedValues = Object.entries(value).map(
|
|
256
|
+
([key, v]) => serializePrimitiveParam({
|
|
257
|
+
allowReserved,
|
|
258
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
259
|
+
value: v
|
|
260
|
+
})
|
|
261
|
+
).join(separator);
|
|
262
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
263
|
+
}, "serializeObjectParam");
|
|
264
|
+
|
|
265
|
+
// src/generated/core/utils.gen.ts
|
|
266
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
267
|
+
var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
|
|
268
|
+
let url = _url;
|
|
269
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
270
|
+
if (matches) {
|
|
271
|
+
for (const match of matches) {
|
|
272
|
+
let explode = false;
|
|
273
|
+
let name = match.substring(1, match.length - 1);
|
|
274
|
+
let style = "simple";
|
|
275
|
+
if (name.endsWith("*")) {
|
|
276
|
+
explode = true;
|
|
277
|
+
name = name.substring(0, name.length - 1);
|
|
278
|
+
}
|
|
279
|
+
if (name.startsWith(".")) {
|
|
280
|
+
name = name.substring(1);
|
|
281
|
+
style = "label";
|
|
282
|
+
} else if (name.startsWith(";")) {
|
|
283
|
+
name = name.substring(1);
|
|
284
|
+
style = "matrix";
|
|
285
|
+
}
|
|
286
|
+
const value = path[name];
|
|
287
|
+
if (value === void 0 || value === null) {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (Array.isArray(value)) {
|
|
291
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (typeof value === "object") {
|
|
295
|
+
url = url.replace(
|
|
296
|
+
match,
|
|
297
|
+
serializeObjectParam({
|
|
298
|
+
explode,
|
|
299
|
+
name,
|
|
300
|
+
style,
|
|
301
|
+
value,
|
|
302
|
+
valueOnly: true
|
|
303
|
+
})
|
|
304
|
+
);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (style === "matrix") {
|
|
308
|
+
url = url.replace(
|
|
309
|
+
match,
|
|
310
|
+
`;${serializePrimitiveParam({
|
|
311
|
+
name,
|
|
312
|
+
value
|
|
313
|
+
})}`
|
|
314
|
+
);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const replaceValue = encodeURIComponent(
|
|
318
|
+
style === "label" ? `.${value}` : value
|
|
319
|
+
);
|
|
320
|
+
url = url.replace(match, replaceValue);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return url;
|
|
324
|
+
}, "defaultPathSerializer");
|
|
325
|
+
var getUrl = /* @__PURE__ */ __name(({
|
|
326
|
+
baseUrl,
|
|
327
|
+
path,
|
|
328
|
+
query,
|
|
329
|
+
querySerializer,
|
|
330
|
+
url: _url
|
|
331
|
+
}) => {
|
|
332
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
333
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
334
|
+
if (path) {
|
|
335
|
+
url = defaultPathSerializer({ path, url });
|
|
336
|
+
}
|
|
337
|
+
let search = query ? querySerializer(query) : "";
|
|
338
|
+
if (search.startsWith("?")) {
|
|
339
|
+
search = search.substring(1);
|
|
340
|
+
}
|
|
341
|
+
if (search) {
|
|
342
|
+
url += `?${search}`;
|
|
343
|
+
}
|
|
344
|
+
return url;
|
|
345
|
+
}, "getUrl");
|
|
346
|
+
function getValidRequestBody(options) {
|
|
347
|
+
const hasBody = options.body !== void 0;
|
|
348
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
349
|
+
if (isSerializedBody) {
|
|
350
|
+
if ("serializedBody" in options) {
|
|
351
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
352
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
353
|
+
}
|
|
354
|
+
return options.body !== "" ? options.body : null;
|
|
355
|
+
}
|
|
356
|
+
if (hasBody) {
|
|
357
|
+
return options.body;
|
|
358
|
+
}
|
|
359
|
+
return void 0;
|
|
360
|
+
}
|
|
361
|
+
__name(getValidRequestBody, "getValidRequestBody");
|
|
362
|
+
|
|
363
|
+
// src/generated/core/auth.gen.ts
|
|
364
|
+
var getAuthToken = /* @__PURE__ */ __name(async (auth, callback) => {
|
|
365
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
366
|
+
if (!token) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (auth.scheme === "bearer") {
|
|
370
|
+
return `Bearer ${token}`;
|
|
371
|
+
}
|
|
372
|
+
if (auth.scheme === "basic") {
|
|
373
|
+
return `Basic ${btoa(token)}`;
|
|
374
|
+
}
|
|
375
|
+
return token;
|
|
376
|
+
}, "getAuthToken");
|
|
377
|
+
|
|
378
|
+
// src/generated/client/utils.gen.ts
|
|
379
|
+
var createQuerySerializer = /* @__PURE__ */ __name(({
|
|
380
|
+
parameters = {},
|
|
381
|
+
...args
|
|
382
|
+
} = {}) => {
|
|
383
|
+
const querySerializer = /* @__PURE__ */ __name((queryParams) => {
|
|
384
|
+
const search = [];
|
|
385
|
+
if (queryParams && typeof queryParams === "object") {
|
|
386
|
+
for (const name in queryParams) {
|
|
387
|
+
const value = queryParams[name];
|
|
388
|
+
if (value === void 0 || value === null) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const options = parameters[name] || args;
|
|
392
|
+
if (Array.isArray(value)) {
|
|
393
|
+
const serializedArray = serializeArrayParam({
|
|
394
|
+
allowReserved: options.allowReserved,
|
|
395
|
+
explode: true,
|
|
396
|
+
name,
|
|
397
|
+
style: "form",
|
|
398
|
+
value,
|
|
399
|
+
...options.array
|
|
400
|
+
});
|
|
401
|
+
if (serializedArray) search.push(serializedArray);
|
|
402
|
+
} else if (typeof value === "object") {
|
|
403
|
+
const serializedObject = serializeObjectParam({
|
|
404
|
+
allowReserved: options.allowReserved,
|
|
405
|
+
explode: true,
|
|
406
|
+
name,
|
|
407
|
+
style: "deepObject",
|
|
408
|
+
value,
|
|
409
|
+
...options.object
|
|
410
|
+
});
|
|
411
|
+
if (serializedObject) search.push(serializedObject);
|
|
412
|
+
} else {
|
|
413
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
414
|
+
allowReserved: options.allowReserved,
|
|
415
|
+
name,
|
|
416
|
+
value
|
|
417
|
+
});
|
|
418
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return search.join("&");
|
|
423
|
+
}, "querySerializer");
|
|
424
|
+
return querySerializer;
|
|
425
|
+
}, "createQuerySerializer");
|
|
426
|
+
var getParseAs = /* @__PURE__ */ __name((contentType) => {
|
|
427
|
+
if (!contentType) {
|
|
428
|
+
return "stream";
|
|
429
|
+
}
|
|
430
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
431
|
+
if (!cleanContent) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
435
|
+
return "json";
|
|
436
|
+
}
|
|
437
|
+
if (cleanContent === "multipart/form-data") {
|
|
438
|
+
return "formData";
|
|
439
|
+
}
|
|
440
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
441
|
+
return "blob";
|
|
442
|
+
}
|
|
443
|
+
if (cleanContent.startsWith("text/")) {
|
|
444
|
+
return "text";
|
|
445
|
+
}
|
|
446
|
+
return;
|
|
447
|
+
}, "getParseAs");
|
|
448
|
+
var checkForExistence = /* @__PURE__ */ __name((options, name) => {
|
|
449
|
+
if (!name) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
return false;
|
|
456
|
+
}, "checkForExistence");
|
|
457
|
+
async function setAuthParams(options) {
|
|
458
|
+
for (const auth of options.security ?? []) {
|
|
459
|
+
if (checkForExistence(options, auth.name)) {
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
const token = await getAuthToken(auth, options.auth);
|
|
463
|
+
if (!token) {
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const name = auth.name ?? "Authorization";
|
|
467
|
+
switch (auth.in) {
|
|
468
|
+
case "query":
|
|
469
|
+
if (!options.query) {
|
|
470
|
+
options.query = {};
|
|
471
|
+
}
|
|
472
|
+
options.query[name] = token;
|
|
473
|
+
break;
|
|
474
|
+
case "cookie":
|
|
475
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
476
|
+
break;
|
|
477
|
+
case "header":
|
|
478
|
+
default:
|
|
479
|
+
options.headers.set(name, token);
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
__name(setAuthParams, "setAuthParams");
|
|
485
|
+
var buildUrl = /* @__PURE__ */ __name((options) => getUrl({
|
|
486
|
+
baseUrl: options.baseUrl,
|
|
487
|
+
path: options.path,
|
|
488
|
+
query: options.query,
|
|
489
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
490
|
+
url: options.url
|
|
491
|
+
}), "buildUrl");
|
|
492
|
+
var mergeConfigs = /* @__PURE__ */ __name((a, b) => {
|
|
493
|
+
const config = { ...a, ...b };
|
|
494
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
495
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
496
|
+
}
|
|
497
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
498
|
+
return config;
|
|
499
|
+
}, "mergeConfigs");
|
|
500
|
+
var headersEntries = /* @__PURE__ */ __name((headers) => {
|
|
501
|
+
const entries = [];
|
|
502
|
+
headers.forEach((value, key) => {
|
|
503
|
+
entries.push([key, value]);
|
|
504
|
+
});
|
|
505
|
+
return entries;
|
|
506
|
+
}, "headersEntries");
|
|
507
|
+
var mergeHeaders = /* @__PURE__ */ __name((...headers) => {
|
|
508
|
+
const mergedHeaders = new Headers();
|
|
509
|
+
for (const header of headers) {
|
|
510
|
+
if (!header) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
514
|
+
for (const [key, value] of iterator) {
|
|
515
|
+
if (value === null) {
|
|
516
|
+
mergedHeaders.delete(key);
|
|
517
|
+
} else if (Array.isArray(value)) {
|
|
518
|
+
for (const v of value) {
|
|
519
|
+
mergedHeaders.append(key, v);
|
|
520
|
+
}
|
|
521
|
+
} else if (value !== void 0) {
|
|
522
|
+
mergedHeaders.set(
|
|
523
|
+
key,
|
|
524
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return mergedHeaders;
|
|
530
|
+
}, "mergeHeaders");
|
|
531
|
+
var Interceptors = class {
|
|
532
|
+
static {
|
|
533
|
+
__name(this, "Interceptors");
|
|
534
|
+
}
|
|
535
|
+
fns = [];
|
|
536
|
+
clear() {
|
|
537
|
+
this.fns = [];
|
|
538
|
+
}
|
|
539
|
+
eject(id) {
|
|
540
|
+
const index = this.getInterceptorIndex(id);
|
|
541
|
+
if (this.fns[index]) {
|
|
542
|
+
this.fns[index] = null;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
exists(id) {
|
|
546
|
+
const index = this.getInterceptorIndex(id);
|
|
547
|
+
return Boolean(this.fns[index]);
|
|
548
|
+
}
|
|
549
|
+
getInterceptorIndex(id) {
|
|
550
|
+
if (typeof id === "number") {
|
|
551
|
+
return this.fns[id] ? id : -1;
|
|
552
|
+
}
|
|
553
|
+
return this.fns.indexOf(id);
|
|
554
|
+
}
|
|
555
|
+
update(id, fn) {
|
|
556
|
+
const index = this.getInterceptorIndex(id);
|
|
557
|
+
if (this.fns[index]) {
|
|
558
|
+
this.fns[index] = fn;
|
|
559
|
+
return id;
|
|
560
|
+
}
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
use(fn) {
|
|
564
|
+
this.fns.push(fn);
|
|
565
|
+
return this.fns.length - 1;
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
var createInterceptors = /* @__PURE__ */ __name(() => ({
|
|
569
|
+
error: new Interceptors(),
|
|
570
|
+
request: new Interceptors(),
|
|
571
|
+
response: new Interceptors()
|
|
572
|
+
}), "createInterceptors");
|
|
573
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
574
|
+
allowReserved: false,
|
|
575
|
+
array: {
|
|
576
|
+
explode: true,
|
|
577
|
+
style: "form"
|
|
578
|
+
},
|
|
579
|
+
object: {
|
|
580
|
+
explode: true,
|
|
581
|
+
style: "deepObject"
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
var defaultHeaders = {
|
|
585
|
+
"Content-Type": "application/json"
|
|
586
|
+
};
|
|
587
|
+
var createConfig = /* @__PURE__ */ __name((override = {}) => ({
|
|
588
|
+
...jsonBodySerializer,
|
|
589
|
+
headers: defaultHeaders,
|
|
590
|
+
parseAs: "auto",
|
|
591
|
+
querySerializer: defaultQuerySerializer,
|
|
592
|
+
...override
|
|
593
|
+
}), "createConfig");
|
|
594
|
+
|
|
595
|
+
// src/generated/client/client.gen.ts
|
|
596
|
+
var createClient = /* @__PURE__ */ __name((config = {}) => {
|
|
597
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
598
|
+
const getConfig = /* @__PURE__ */ __name(() => ({ ..._config }), "getConfig");
|
|
599
|
+
const setConfig = /* @__PURE__ */ __name((config2) => {
|
|
600
|
+
_config = mergeConfigs(_config, config2);
|
|
601
|
+
return getConfig();
|
|
602
|
+
}, "setConfig");
|
|
603
|
+
const interceptors = createInterceptors();
|
|
604
|
+
const beforeRequest = /* @__PURE__ */ __name(async (options) => {
|
|
605
|
+
const opts = {
|
|
606
|
+
..._config,
|
|
607
|
+
...options,
|
|
608
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
609
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
610
|
+
serializedBody: void 0
|
|
611
|
+
};
|
|
612
|
+
if (opts.security) {
|
|
613
|
+
await setAuthParams(opts);
|
|
614
|
+
}
|
|
615
|
+
if (opts.requestValidator) {
|
|
616
|
+
await opts.requestValidator(opts);
|
|
617
|
+
}
|
|
618
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
619
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
620
|
+
}
|
|
621
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
622
|
+
opts.headers.delete("Content-Type");
|
|
623
|
+
}
|
|
624
|
+
const resolvedOpts = opts;
|
|
625
|
+
const url = buildUrl(resolvedOpts);
|
|
626
|
+
return { opts: resolvedOpts, url };
|
|
627
|
+
}, "beforeRequest");
|
|
628
|
+
const request = /* @__PURE__ */ __name(async (options) => {
|
|
629
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
630
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
631
|
+
let request2;
|
|
632
|
+
let response;
|
|
633
|
+
try {
|
|
634
|
+
const { opts, url } = await beforeRequest(options);
|
|
635
|
+
const requestInit = {
|
|
636
|
+
redirect: "follow",
|
|
637
|
+
...opts,
|
|
638
|
+
body: getValidRequestBody(opts)
|
|
639
|
+
};
|
|
640
|
+
request2 = new Request(url, requestInit);
|
|
641
|
+
for (const fn of interceptors.request.fns) {
|
|
642
|
+
if (fn) {
|
|
643
|
+
request2 = await fn(request2, opts);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
const _fetch = opts.fetch;
|
|
647
|
+
response = await _fetch(request2);
|
|
648
|
+
for (const fn of interceptors.response.fns) {
|
|
649
|
+
if (fn) {
|
|
650
|
+
response = await fn(response, request2, opts);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const result = {
|
|
654
|
+
request: request2,
|
|
655
|
+
response
|
|
656
|
+
};
|
|
657
|
+
if (response.ok) {
|
|
658
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
659
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
660
|
+
let emptyData;
|
|
661
|
+
switch (parseAs) {
|
|
662
|
+
case "arrayBuffer":
|
|
663
|
+
case "blob":
|
|
664
|
+
case "text":
|
|
665
|
+
emptyData = await response[parseAs]();
|
|
666
|
+
break;
|
|
667
|
+
case "formData":
|
|
668
|
+
emptyData = new FormData();
|
|
669
|
+
break;
|
|
670
|
+
case "stream":
|
|
671
|
+
emptyData = response.body;
|
|
672
|
+
break;
|
|
673
|
+
case "json":
|
|
674
|
+
default:
|
|
675
|
+
emptyData = {};
|
|
676
|
+
break;
|
|
677
|
+
}
|
|
678
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
679
|
+
data: emptyData,
|
|
680
|
+
...result
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
let data;
|
|
684
|
+
switch (parseAs) {
|
|
685
|
+
case "arrayBuffer":
|
|
686
|
+
case "blob":
|
|
687
|
+
case "formData":
|
|
688
|
+
case "text":
|
|
689
|
+
data = await response[parseAs]();
|
|
690
|
+
break;
|
|
691
|
+
case "json": {
|
|
692
|
+
const text = await response.text();
|
|
693
|
+
data = text ? JSON.parse(text) : {};
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
case "stream":
|
|
697
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
698
|
+
data: response.body,
|
|
699
|
+
...result
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
if (parseAs === "json") {
|
|
703
|
+
if (opts.responseValidator) {
|
|
704
|
+
await opts.responseValidator(data);
|
|
705
|
+
}
|
|
706
|
+
if (opts.responseTransformer) {
|
|
707
|
+
data = await opts.responseTransformer(data);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return opts.responseStyle === "data" ? data : {
|
|
711
|
+
data,
|
|
712
|
+
...result
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
const textError = await response.text();
|
|
716
|
+
let jsonError;
|
|
717
|
+
try {
|
|
718
|
+
jsonError = JSON.parse(textError);
|
|
719
|
+
} catch {
|
|
720
|
+
}
|
|
721
|
+
throw jsonError ?? textError;
|
|
722
|
+
} catch (error) {
|
|
723
|
+
let finalError = error;
|
|
724
|
+
for (const fn of interceptors.error.fns) {
|
|
725
|
+
if (fn) {
|
|
726
|
+
finalError = await fn(finalError, response, request2, options);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
finalError = finalError || {};
|
|
730
|
+
if (throwOnError) {
|
|
731
|
+
throw finalError;
|
|
732
|
+
}
|
|
733
|
+
return responseStyle === "data" ? void 0 : {
|
|
734
|
+
error: finalError,
|
|
735
|
+
request: request2,
|
|
736
|
+
response
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
}, "request");
|
|
740
|
+
const makeMethodFn = /* @__PURE__ */ __name((method) => (options) => request({ ...options, method }), "makeMethodFn");
|
|
741
|
+
const makeSseFn = /* @__PURE__ */ __name((method) => async (options) => {
|
|
742
|
+
const { opts, url } = await beforeRequest(options);
|
|
743
|
+
return createSseClient({
|
|
744
|
+
...opts,
|
|
745
|
+
body: opts.body,
|
|
746
|
+
method,
|
|
747
|
+
onRequest: /* @__PURE__ */ __name(async (url2, init) => {
|
|
748
|
+
let request2 = new Request(url2, init);
|
|
749
|
+
for (const fn of interceptors.request.fns) {
|
|
750
|
+
if (fn) {
|
|
751
|
+
request2 = await fn(request2, opts);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return request2;
|
|
755
|
+
}, "onRequest"),
|
|
756
|
+
serializedBody: getValidRequestBody(opts),
|
|
757
|
+
url
|
|
758
|
+
});
|
|
759
|
+
}, "makeSseFn");
|
|
760
|
+
const _buildUrl = /* @__PURE__ */ __name((options) => buildUrl({ ..._config, ...options }), "_buildUrl");
|
|
761
|
+
return {
|
|
762
|
+
buildUrl: _buildUrl,
|
|
763
|
+
connect: makeMethodFn("CONNECT"),
|
|
764
|
+
delete: makeMethodFn("DELETE"),
|
|
765
|
+
get: makeMethodFn("GET"),
|
|
766
|
+
getConfig,
|
|
767
|
+
head: makeMethodFn("HEAD"),
|
|
768
|
+
interceptors,
|
|
769
|
+
options: makeMethodFn("OPTIONS"),
|
|
770
|
+
patch: makeMethodFn("PATCH"),
|
|
771
|
+
post: makeMethodFn("POST"),
|
|
772
|
+
put: makeMethodFn("PUT"),
|
|
773
|
+
request,
|
|
774
|
+
setConfig,
|
|
775
|
+
sse: {
|
|
776
|
+
connect: makeSseFn("CONNECT"),
|
|
777
|
+
delete: makeSseFn("DELETE"),
|
|
778
|
+
get: makeSseFn("GET"),
|
|
779
|
+
head: makeSseFn("HEAD"),
|
|
780
|
+
options: makeSseFn("OPTIONS"),
|
|
781
|
+
patch: makeSseFn("PATCH"),
|
|
782
|
+
post: makeSseFn("POST"),
|
|
783
|
+
put: makeSseFn("PUT"),
|
|
784
|
+
trace: makeSseFn("TRACE")
|
|
785
|
+
},
|
|
786
|
+
trace: makeMethodFn("TRACE")
|
|
787
|
+
};
|
|
788
|
+
}, "createClient");
|
|
789
|
+
|
|
790
|
+
// src/generated/client.gen.ts
|
|
791
|
+
var client = createClient(createConfig({ baseUrl: "https://api.postpeer.dev" }));
|
|
792
|
+
|
|
793
|
+
// src/generated/sdk.gen.ts
|
|
794
|
+
var HeyApiClient = class {
|
|
795
|
+
static {
|
|
796
|
+
__name(this, "HeyApiClient");
|
|
797
|
+
}
|
|
798
|
+
client;
|
|
799
|
+
constructor(args) {
|
|
800
|
+
this.client = args?.client ?? client;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
var HeyApiRegistry = class {
|
|
804
|
+
static {
|
|
805
|
+
__name(this, "HeyApiRegistry");
|
|
806
|
+
}
|
|
807
|
+
defaultKey = "default";
|
|
808
|
+
instances = /* @__PURE__ */ new Map();
|
|
809
|
+
get(key) {
|
|
810
|
+
const instance = this.instances.get(key ?? this.defaultKey);
|
|
811
|
+
if (!instance) {
|
|
812
|
+
throw new Error(`No SDK client found. Create one with "new PostPeerApi()" to fix this error.`);
|
|
813
|
+
}
|
|
814
|
+
return instance;
|
|
815
|
+
}
|
|
816
|
+
set(value, key) {
|
|
817
|
+
this.instances.set(key ?? this.defaultKey, value);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
var Health = class extends HeyApiClient {
|
|
821
|
+
static {
|
|
822
|
+
__name(this, "Health");
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Health check
|
|
826
|
+
*/
|
|
827
|
+
check(options) {
|
|
828
|
+
return (options?.client ?? this.client).get({ url: "/v1/health", ...options });
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Verify that the provided access key is valid
|
|
832
|
+
*/
|
|
833
|
+
verifyAccessKey(options) {
|
|
834
|
+
return (options?.client ?? this.client).get({
|
|
835
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
836
|
+
url: "/v1/health/auth",
|
|
837
|
+
...options
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
var Linkedin = class extends HeyApiClient {
|
|
842
|
+
static {
|
|
843
|
+
__name(this, "Linkedin");
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Get pending LinkedIn account choices for headless mode
|
|
847
|
+
*
|
|
848
|
+
* Use only when starting LinkedIn OAuth with headless=true and the callback redirects to your redirectUri with status=selection_required and selectionToken. Returns the personal profile and organization pages available for the user to choose from.
|
|
849
|
+
*/
|
|
850
|
+
getSelection(options) {
|
|
851
|
+
return (options.client ?? this.client).get({ url: "/v1/connect/linkedin/selection/{token}", ...options });
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Save selected LinkedIn accounts for headless mode
|
|
855
|
+
*
|
|
856
|
+
* Use only after GET /v1/connect/linkedin/selection/:token in a headless LinkedIn connect flow. Saves the selected personal profile and/or organization pages, then invalidates the one-time selection token.
|
|
857
|
+
*/
|
|
858
|
+
submitSelection(options) {
|
|
859
|
+
return (options.client ?? this.client).post({
|
|
860
|
+
url: "/v1/connect/linkedin/selection/{token}",
|
|
861
|
+
...options,
|
|
862
|
+
headers: {
|
|
863
|
+
"Content-Type": "application/json",
|
|
864
|
+
...options.headers
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
var Integrations = class extends HeyApiClient {
|
|
870
|
+
static {
|
|
871
|
+
__name(this, "Integrations");
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* List integrations connected to this project
|
|
875
|
+
*/
|
|
876
|
+
list(options) {
|
|
877
|
+
return (options?.client ?? this.client).get({
|
|
878
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
879
|
+
url: "/v1/connect/integrations",
|
|
880
|
+
...options
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Disconnect a platform integration
|
|
885
|
+
*/
|
|
886
|
+
disconnect(options) {
|
|
887
|
+
return (options.client ?? this.client).delete({
|
|
888
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
889
|
+
url: "/v1/connect/integrations/{id}",
|
|
890
|
+
...options
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
var Connect = class extends HeyApiClient {
|
|
895
|
+
static {
|
|
896
|
+
__name(this, "Connect");
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Get OAuth URL for a platform
|
|
900
|
+
*
|
|
901
|
+
* Initiates an OAuth connection flow. By default, PostPeer hosts any required account selection UI and then returns the user to redirectUri. For LinkedIn custom account-selection UI, pass headless=true; if selection is required, the callback redirects to redirectUri with status=selection_required, platform=linkedin, and selectionToken.
|
|
902
|
+
*/
|
|
903
|
+
getOAuthUrl(options) {
|
|
904
|
+
return (options.client ?? this.client).get({
|
|
905
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
906
|
+
url: "/v1/connect/{platform}",
|
|
907
|
+
...options
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Connect a Bluesky account via app password
|
|
912
|
+
*
|
|
913
|
+
* Bluesky has no OAuth redirect. Have the user generate an app password at https://bsky.app/settings/app-passwords, then submit it here.
|
|
914
|
+
*/
|
|
915
|
+
bluesky(options) {
|
|
916
|
+
return (options.client ?? this.client).post({
|
|
917
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
918
|
+
url: "/v1/connect/bluesky/auth",
|
|
919
|
+
...options,
|
|
920
|
+
headers: {
|
|
921
|
+
"Content-Type": "application/json",
|
|
922
|
+
...options.headers
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
_linkedin;
|
|
927
|
+
get linkedin() {
|
|
928
|
+
return this._linkedin ??= new Linkedin({ client: this.client });
|
|
929
|
+
}
|
|
930
|
+
_integrations;
|
|
931
|
+
get integrations() {
|
|
932
|
+
return this._integrations ??= new Integrations({ client: this.client });
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
var Profiles = class extends HeyApiClient {
|
|
936
|
+
static {
|
|
937
|
+
__name(this, "Profiles");
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* List profiles for this project
|
|
941
|
+
*/
|
|
942
|
+
list(options) {
|
|
943
|
+
return (options?.client ?? this.client).get({
|
|
944
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
945
|
+
url: "/v1/profiles/",
|
|
946
|
+
...options
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Create a profile
|
|
951
|
+
*
|
|
952
|
+
* Profiles group integrations under a label. Pass the returned `id` as `profileId` when calling /v1/connect/:platform to bind the resulting integration to this profile.
|
|
953
|
+
*/
|
|
954
|
+
create(options) {
|
|
955
|
+
return (options.client ?? this.client).post({
|
|
956
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
957
|
+
url: "/v1/profiles/",
|
|
958
|
+
...options,
|
|
959
|
+
headers: {
|
|
960
|
+
"Content-Type": "application/json",
|
|
961
|
+
...options.headers
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Delete a profile
|
|
967
|
+
*
|
|
968
|
+
* Soft-deletes the profile. Existing integrations bound to it keep their profileId — they are not orphaned, but listing /v1/profiles will no longer surface this row.
|
|
969
|
+
*/
|
|
970
|
+
delete(options) {
|
|
971
|
+
return (options.client ?? this.client).delete({
|
|
972
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
973
|
+
url: "/v1/profiles/{id}",
|
|
974
|
+
...options
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Get a single profile
|
|
979
|
+
*/
|
|
980
|
+
get(options) {
|
|
981
|
+
return (options.client ?? this.client).get({
|
|
982
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
983
|
+
url: "/v1/profiles/{id}",
|
|
984
|
+
...options
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Update a profile
|
|
989
|
+
*/
|
|
990
|
+
update(options) {
|
|
991
|
+
return (options.client ?? this.client).patch({
|
|
992
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
993
|
+
url: "/v1/profiles/{id}",
|
|
994
|
+
...options,
|
|
995
|
+
headers: {
|
|
996
|
+
"Content-Type": "application/json",
|
|
997
|
+
...options.headers
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
var Apps = class extends HeyApiClient {
|
|
1003
|
+
static {
|
|
1004
|
+
__name(this, "Apps");
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* List registered OAuth apps for this project
|
|
1008
|
+
*/
|
|
1009
|
+
list(options) {
|
|
1010
|
+
return (options?.client ?? this.client).get({
|
|
1011
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1012
|
+
url: "/v1/apps/",
|
|
1013
|
+
...options
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Register your own OAuth app (Bring Your Own Keys)
|
|
1018
|
+
*
|
|
1019
|
+
* Store the client credentials of your own OAuth app for a platform. Pass the returned `id` as `appId` when calling /v1/connect/:platform to connect accounts under it.
|
|
1020
|
+
*/
|
|
1021
|
+
create(options) {
|
|
1022
|
+
return (options.client ?? this.client).post({
|
|
1023
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1024
|
+
url: "/v1/apps/",
|
|
1025
|
+
...options,
|
|
1026
|
+
headers: {
|
|
1027
|
+
"Content-Type": "application/json",
|
|
1028
|
+
...options.headers
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Delete an OAuth app
|
|
1034
|
+
*
|
|
1035
|
+
* Deletes the app. Blocked with 409 while active integrations are still connected under it — those integrations rely on the app for token refresh. Disconnect or reconnect them first.
|
|
1036
|
+
*/
|
|
1037
|
+
delete(options) {
|
|
1038
|
+
return (options.client ?? this.client).delete({
|
|
1039
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1040
|
+
url: "/v1/apps/{id}",
|
|
1041
|
+
...options
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Get a single OAuth app
|
|
1046
|
+
*/
|
|
1047
|
+
get(options) {
|
|
1048
|
+
return (options.client ?? this.client).get({
|
|
1049
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1050
|
+
url: "/v1/apps/{id}",
|
|
1051
|
+
...options
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Update an OAuth app
|
|
1056
|
+
*
|
|
1057
|
+
* Change the name, image, or rotate the client secret. The clientId and platform are immutable: a refresh token is bound to the clientId that issued it, so changing the app would brick existing integrations — create a new OAuth app and reconnect instead.
|
|
1058
|
+
*/
|
|
1059
|
+
update(options) {
|
|
1060
|
+
return (options.client ?? this.client).patch({
|
|
1061
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1062
|
+
url: "/v1/apps/{id}",
|
|
1063
|
+
...options,
|
|
1064
|
+
headers: {
|
|
1065
|
+
"Content-Type": "application/json",
|
|
1066
|
+
...options.headers
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
var Notifications = class extends HeyApiClient {
|
|
1072
|
+
static {
|
|
1073
|
+
__name(this, "Notifications");
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Test a notification destination before saving it
|
|
1077
|
+
*/
|
|
1078
|
+
test(options) {
|
|
1079
|
+
return (options.client ?? this.client).post({
|
|
1080
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1081
|
+
url: "/v1/notifications/test",
|
|
1082
|
+
...options,
|
|
1083
|
+
headers: {
|
|
1084
|
+
"Content-Type": "application/json",
|
|
1085
|
+
...options.headers
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* List notification subscriptions
|
|
1091
|
+
*/
|
|
1092
|
+
list(options) {
|
|
1093
|
+
return (options?.client ?? this.client).get({
|
|
1094
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1095
|
+
url: "/v1/notifications/",
|
|
1096
|
+
...options
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Create a notification subscription
|
|
1101
|
+
*/
|
|
1102
|
+
create(options) {
|
|
1103
|
+
return (options.client ?? this.client).post({
|
|
1104
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1105
|
+
url: "/v1/notifications/",
|
|
1106
|
+
...options,
|
|
1107
|
+
headers: {
|
|
1108
|
+
"Content-Type": "application/json",
|
|
1109
|
+
...options.headers
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Delete a notification subscription
|
|
1115
|
+
*/
|
|
1116
|
+
delete(options) {
|
|
1117
|
+
return (options.client ?? this.client).delete({
|
|
1118
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1119
|
+
url: "/v1/notifications/{id}",
|
|
1120
|
+
...options
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Get a notification subscription
|
|
1125
|
+
*/
|
|
1126
|
+
get(options) {
|
|
1127
|
+
return (options.client ?? this.client).get({
|
|
1128
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1129
|
+
url: "/v1/notifications/{id}",
|
|
1130
|
+
...options
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Update a notification subscription
|
|
1135
|
+
*/
|
|
1136
|
+
update(options) {
|
|
1137
|
+
return (options.client ?? this.client).patch({
|
|
1138
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1139
|
+
url: "/v1/notifications/{id}",
|
|
1140
|
+
...options,
|
|
1141
|
+
headers: {
|
|
1142
|
+
"Content-Type": "application/json",
|
|
1143
|
+
...options.headers
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
var Platforms = class extends HeyApiClient {
|
|
1149
|
+
static {
|
|
1150
|
+
__name(this, "Platforms");
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* List available platforms and their status
|
|
1154
|
+
*/
|
|
1155
|
+
list(options) {
|
|
1156
|
+
return (options?.client ?? this.client).get({
|
|
1157
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1158
|
+
url: "/v1/platforms",
|
|
1159
|
+
...options
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
var Scheduled = class extends HeyApiClient {
|
|
1164
|
+
static {
|
|
1165
|
+
__name(this, "Scheduled");
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* List all scheduled posts
|
|
1169
|
+
*
|
|
1170
|
+
* Returns a paginated list of scheduled posts. Use `limit` + `offset` to page through the results.
|
|
1171
|
+
*/
|
|
1172
|
+
list(options) {
|
|
1173
|
+
return (options?.client ?? this.client).get({
|
|
1174
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1175
|
+
url: "/v1/posts/scheduled/",
|
|
1176
|
+
...options
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Cancel a scheduled post (moves it back to draft)
|
|
1181
|
+
*/
|
|
1182
|
+
cancel(options) {
|
|
1183
|
+
return (options.client ?? this.client).delete({
|
|
1184
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1185
|
+
url: "/v1/posts/scheduled/{postId}",
|
|
1186
|
+
...options
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Reschedule a post to a new time
|
|
1191
|
+
*/
|
|
1192
|
+
reschedule(options) {
|
|
1193
|
+
return (options.client ?? this.client).patch({
|
|
1194
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1195
|
+
url: "/v1/posts/scheduled/{postId}",
|
|
1196
|
+
...options,
|
|
1197
|
+
headers: {
|
|
1198
|
+
"Content-Type": "application/json",
|
|
1199
|
+
...options.headers
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
var Posts = class extends HeyApiClient {
|
|
1205
|
+
static {
|
|
1206
|
+
__name(this, "Posts");
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* List all posts for the project
|
|
1210
|
+
*
|
|
1211
|
+
* Returns a paginated list of posts. Filter by status, platform (OR logic), and date ranges. Published posts include platformPostUrl per platform.
|
|
1212
|
+
*/
|
|
1213
|
+
list(options) {
|
|
1214
|
+
return (options?.client ?? this.client).get({
|
|
1215
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1216
|
+
url: "/v1/posts/",
|
|
1217
|
+
...options
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Publish a post to one or more social media platforms
|
|
1222
|
+
*/
|
|
1223
|
+
create(options) {
|
|
1224
|
+
return (options.client ?? this.client).post({
|
|
1225
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1226
|
+
url: "/v1/posts/",
|
|
1227
|
+
...options,
|
|
1228
|
+
headers: {
|
|
1229
|
+
"Content-Type": "application/json",
|
|
1230
|
+
...options.headers
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Delete a post by ID
|
|
1236
|
+
*/
|
|
1237
|
+
delete(options) {
|
|
1238
|
+
return (options.client ?? this.client).delete({
|
|
1239
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1240
|
+
url: "/v1/posts/{postId}",
|
|
1241
|
+
...options
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Get a single post by ID
|
|
1246
|
+
*/
|
|
1247
|
+
get(options) {
|
|
1248
|
+
return (options.client ?? this.client).get({
|
|
1249
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1250
|
+
url: "/v1/posts/{postId}",
|
|
1251
|
+
...options
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
_scheduled;
|
|
1255
|
+
get scheduled() {
|
|
1256
|
+
return this._scheduled ??= new Scheduled({ client: this.client });
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
var Media = class extends HeyApiClient {
|
|
1260
|
+
static {
|
|
1261
|
+
__name(this, "Media");
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Get a presigned S3 URL to upload a media file
|
|
1265
|
+
*/
|
|
1266
|
+
upload(options) {
|
|
1267
|
+
return (options.client ?? this.client).post({
|
|
1268
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1269
|
+
url: "/v1/media/upload",
|
|
1270
|
+
...options,
|
|
1271
|
+
headers: {
|
|
1272
|
+
"Content-Type": "application/json",
|
|
1273
|
+
...options.headers
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
var Analytics = class extends HeyApiClient {
|
|
1279
|
+
static {
|
|
1280
|
+
__name(this, "Analytics");
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Get post analytics
|
|
1284
|
+
*
|
|
1285
|
+
* With postId, returns analytics for a single post. Without postId, returns a paginated list of published posts with analytics. Accepts both PostPeer post IDs and external platform post IDs (auto-resolved). fromDate defaults to 90 days ago if omitted, max range 366 days. Each call costs 1 credit.
|
|
1286
|
+
*/
|
|
1287
|
+
get(options) {
|
|
1288
|
+
return (options?.client ?? this.client).get({
|
|
1289
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1290
|
+
url: "/v1/analytics/",
|
|
1291
|
+
...options
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
var Usage = class extends HeyApiClient {
|
|
1296
|
+
static {
|
|
1297
|
+
__name(this, "Usage");
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Get credit usage
|
|
1301
|
+
*
|
|
1302
|
+
* Returns credit usage history for the project. Without filters, returns project-level totals. Add `profileId` to scope to a specific profile, or `integrationId` to scope to a specific connected account. Use `from`/`to` (YYYY-MM) to slice the history. Each entry contains the monthly credit count and a per-platform breakdown.
|
|
1303
|
+
*/
|
|
1304
|
+
get(options) {
|
|
1305
|
+
return (options?.client ?? this.client).get({
|
|
1306
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1307
|
+
url: "/v1/usage/",
|
|
1308
|
+
...options
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
var Pinterest = class extends HeyApiClient {
|
|
1313
|
+
static {
|
|
1314
|
+
__name(this, "Pinterest");
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* List Pinterest boards for a connected account
|
|
1318
|
+
*/
|
|
1319
|
+
getBoards(options) {
|
|
1320
|
+
return (options?.client ?? this.client).get({
|
|
1321
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1322
|
+
url: "/v1/pinterest/boards",
|
|
1323
|
+
...options
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
var Tiktok = class extends HeyApiClient {
|
|
1328
|
+
static {
|
|
1329
|
+
__name(this, "Tiktok");
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Fetch TikTok creator info for a connected account
|
|
1333
|
+
*
|
|
1334
|
+
* Proxies TikTok's /v2/post/publish/creator_info/query/ endpoint. Use the returned `privacyLevelOptions`, `commentDisabled`, `duetDisabled`, `stitchDisabled`, and `maxVideoPostDurationSec` to build a compliant "Post to TikTok" UX.
|
|
1335
|
+
*/
|
|
1336
|
+
getCreatorInfo(options) {
|
|
1337
|
+
return (options?.client ?? this.client).get({
|
|
1338
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1339
|
+
url: "/v1/tiktok/creator-info",
|
|
1340
|
+
...options
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
var Ai = class extends HeyApiClient {
|
|
1345
|
+
static {
|
|
1346
|
+
__name(this, "Ai");
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Generate a social media caption from a description
|
|
1350
|
+
*
|
|
1351
|
+
* Generates a caption tailored to the platforms you'll post to. Costs 2 credits per successful generation. Failed calls do not deduct credits.
|
|
1352
|
+
*/
|
|
1353
|
+
write(options) {
|
|
1354
|
+
return (options.client ?? this.client).post({
|
|
1355
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1356
|
+
url: "/v1/ai/write",
|
|
1357
|
+
...options,
|
|
1358
|
+
headers: {
|
|
1359
|
+
"Content-Type": "application/json",
|
|
1360
|
+
...options.headers
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Generate a social media image from a description
|
|
1366
|
+
*
|
|
1367
|
+
* Generates a square or vertical image suitable for social media. Costs 10 credits per successful generation. Failed calls do not deduct credits.
|
|
1368
|
+
*/
|
|
1369
|
+
generateImage(options) {
|
|
1370
|
+
return (options.client ?? this.client).post({
|
|
1371
|
+
security: [{ name: "x-access-key", type: "apiKey" }],
|
|
1372
|
+
url: "/v1/ai/image",
|
|
1373
|
+
...options,
|
|
1374
|
+
headers: {
|
|
1375
|
+
"Content-Type": "application/json",
|
|
1376
|
+
...options.headers
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
var PostPeerApi = class _PostPeerApi extends HeyApiClient {
|
|
1382
|
+
static {
|
|
1383
|
+
__name(this, "PostPeerApi");
|
|
1384
|
+
}
|
|
1385
|
+
static __registry = new HeyApiRegistry();
|
|
1386
|
+
constructor(args) {
|
|
1387
|
+
super(args);
|
|
1388
|
+
_PostPeerApi.__registry.set(this, args?.key);
|
|
1389
|
+
}
|
|
1390
|
+
_health;
|
|
1391
|
+
get health() {
|
|
1392
|
+
return this._health ??= new Health({ client: this.client });
|
|
1393
|
+
}
|
|
1394
|
+
_connect;
|
|
1395
|
+
get connect() {
|
|
1396
|
+
return this._connect ??= new Connect({ client: this.client });
|
|
1397
|
+
}
|
|
1398
|
+
_profiles;
|
|
1399
|
+
get profiles() {
|
|
1400
|
+
return this._profiles ??= new Profiles({ client: this.client });
|
|
1401
|
+
}
|
|
1402
|
+
_apps;
|
|
1403
|
+
get apps() {
|
|
1404
|
+
return this._apps ??= new Apps({ client: this.client });
|
|
1405
|
+
}
|
|
1406
|
+
_notifications;
|
|
1407
|
+
get notifications() {
|
|
1408
|
+
return this._notifications ??= new Notifications({ client: this.client });
|
|
1409
|
+
}
|
|
1410
|
+
_platforms;
|
|
1411
|
+
get platforms() {
|
|
1412
|
+
return this._platforms ??= new Platforms({ client: this.client });
|
|
1413
|
+
}
|
|
1414
|
+
_posts;
|
|
1415
|
+
get posts() {
|
|
1416
|
+
return this._posts ??= new Posts({ client: this.client });
|
|
1417
|
+
}
|
|
1418
|
+
_media;
|
|
1419
|
+
get media() {
|
|
1420
|
+
return this._media ??= new Media({ client: this.client });
|
|
1421
|
+
}
|
|
1422
|
+
_analytics;
|
|
1423
|
+
get analytics() {
|
|
1424
|
+
return this._analytics ??= new Analytics({ client: this.client });
|
|
1425
|
+
}
|
|
1426
|
+
_usage;
|
|
1427
|
+
get usage() {
|
|
1428
|
+
return this._usage ??= new Usage({ client: this.client });
|
|
1429
|
+
}
|
|
1430
|
+
_pinterest;
|
|
1431
|
+
get pinterest() {
|
|
1432
|
+
return this._pinterest ??= new Pinterest({ client: this.client });
|
|
1433
|
+
}
|
|
1434
|
+
_tiktok;
|
|
1435
|
+
get tiktok() {
|
|
1436
|
+
return this._tiktok ??= new Tiktok({ client: this.client });
|
|
1437
|
+
}
|
|
1438
|
+
_ai;
|
|
1439
|
+
get ai() {
|
|
1440
|
+
return this._ai ??= new Ai({ client: this.client });
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
|
|
1444
|
+
// src/errors.ts
|
|
1445
|
+
var PostPeerError = class extends Error {
|
|
1446
|
+
static {
|
|
1447
|
+
__name(this, "PostPeerError");
|
|
1448
|
+
}
|
|
1449
|
+
constructor(message, options) {
|
|
1450
|
+
super(message, options);
|
|
1451
|
+
this.name = "PostPeerError";
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
var APIError = class extends PostPeerError {
|
|
1455
|
+
static {
|
|
1456
|
+
__name(this, "APIError");
|
|
1457
|
+
}
|
|
1458
|
+
status;
|
|
1459
|
+
code;
|
|
1460
|
+
details;
|
|
1461
|
+
requestId;
|
|
1462
|
+
headers;
|
|
1463
|
+
constructor(status, message, options = {}) {
|
|
1464
|
+
super(message, { cause: options.cause });
|
|
1465
|
+
this.name = "APIError";
|
|
1466
|
+
this.status = status;
|
|
1467
|
+
this.code = options.code;
|
|
1468
|
+
this.details = options.details;
|
|
1469
|
+
this.headers = options.headers ?? new Headers();
|
|
1470
|
+
this.requestId = options.requestId;
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
var BadRequestError = class extends APIError {
|
|
1474
|
+
static {
|
|
1475
|
+
__name(this, "BadRequestError");
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
var AuthenticationError = class extends APIError {
|
|
1479
|
+
static {
|
|
1480
|
+
__name(this, "AuthenticationError");
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
var PermissionDeniedError = class extends APIError {
|
|
1484
|
+
static {
|
|
1485
|
+
__name(this, "PermissionDeniedError");
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
var NotFoundError = class extends APIError {
|
|
1489
|
+
static {
|
|
1490
|
+
__name(this, "NotFoundError");
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
var ConflictError = class extends APIError {
|
|
1494
|
+
static {
|
|
1495
|
+
__name(this, "ConflictError");
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
var UnprocessableEntityError = class extends APIError {
|
|
1499
|
+
static {
|
|
1500
|
+
__name(this, "UnprocessableEntityError");
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
var RateLimitError = class extends APIError {
|
|
1504
|
+
static {
|
|
1505
|
+
__name(this, "RateLimitError");
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1508
|
+
var InternalServerError = class extends APIError {
|
|
1509
|
+
static {
|
|
1510
|
+
__name(this, "InternalServerError");
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
var APIConnectionError = class extends PostPeerError {
|
|
1514
|
+
static {
|
|
1515
|
+
__name(this, "APIConnectionError");
|
|
1516
|
+
}
|
|
1517
|
+
constructor(message = "Connection failed.", options) {
|
|
1518
|
+
super(message, options);
|
|
1519
|
+
this.name = "APIConnectionError";
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
var APIConnectionTimeoutError = class extends APIConnectionError {
|
|
1523
|
+
static {
|
|
1524
|
+
__name(this, "APIConnectionTimeoutError");
|
|
1525
|
+
}
|
|
1526
|
+
constructor(options) {
|
|
1527
|
+
super("Request timed out.", options);
|
|
1528
|
+
this.name = "APIConnectionTimeoutError";
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
var APIUserAbortError = class extends APIConnectionError {
|
|
1532
|
+
static {
|
|
1533
|
+
__name(this, "APIUserAbortError");
|
|
1534
|
+
}
|
|
1535
|
+
constructor(options) {
|
|
1536
|
+
super("Request was aborted.", options);
|
|
1537
|
+
this.name = "APIUserAbortError";
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
var errorMessage = /* @__PURE__ */ __name((body, response) => {
|
|
1541
|
+
if (typeof body === "string" && body) return body;
|
|
1542
|
+
if (body && typeof body === "object") {
|
|
1543
|
+
const value = body;
|
|
1544
|
+
if (typeof value["message"] === "string") return value["message"];
|
|
1545
|
+
if (typeof value["error"] === "string") return value["error"];
|
|
1546
|
+
}
|
|
1547
|
+
return response.statusText || `Request failed with status ${response.status}.`;
|
|
1548
|
+
}, "errorMessage");
|
|
1549
|
+
var errorCode = /* @__PURE__ */ __name((body) => {
|
|
1550
|
+
if (!body || typeof body !== "object") return void 0;
|
|
1551
|
+
const code = body["code"];
|
|
1552
|
+
return typeof code === "string" ? code : void 0;
|
|
1553
|
+
}, "errorCode");
|
|
1554
|
+
var createAPIError = /* @__PURE__ */ __name((response, body) => {
|
|
1555
|
+
const options = {
|
|
1556
|
+
code: errorCode(body),
|
|
1557
|
+
details: body,
|
|
1558
|
+
headers: response.headers,
|
|
1559
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
1560
|
+
};
|
|
1561
|
+
const message = errorMessage(body, response);
|
|
1562
|
+
switch (response.status) {
|
|
1563
|
+
case 400:
|
|
1564
|
+
return new BadRequestError(response.status, message, options);
|
|
1565
|
+
case 401:
|
|
1566
|
+
return new AuthenticationError(response.status, message, options);
|
|
1567
|
+
case 403:
|
|
1568
|
+
return new PermissionDeniedError(response.status, message, options);
|
|
1569
|
+
case 404:
|
|
1570
|
+
return new NotFoundError(response.status, message, options);
|
|
1571
|
+
case 409:
|
|
1572
|
+
return new ConflictError(response.status, message, options);
|
|
1573
|
+
case 422:
|
|
1574
|
+
return new UnprocessableEntityError(response.status, message, options);
|
|
1575
|
+
case 429:
|
|
1576
|
+
return new RateLimitError(response.status, message, options);
|
|
1577
|
+
default:
|
|
1578
|
+
return response.status >= 500 ? new InternalServerError(response.status, message, options) : new APIError(response.status, message, options);
|
|
1579
|
+
}
|
|
1580
|
+
}, "createAPIError");
|
|
1581
|
+
|
|
1582
|
+
// src/version.ts
|
|
1583
|
+
var VERSION = "0.8.0";
|
|
1584
|
+
|
|
1585
|
+
// src/client.ts
|
|
1586
|
+
var DEFAULT_BASE_URL = "https://api.postpeer.dev";
|
|
1587
|
+
var DEFAULT_TIMEOUT = 6e4;
|
|
1588
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
1589
|
+
var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 409, 429]);
|
|
1590
|
+
var isRetryableResponse = /* @__PURE__ */ __name((response) => RETRYABLE_STATUS_CODES.has(response.status) || response.status >= 500, "isRetryableResponse");
|
|
1591
|
+
var retryDelay = /* @__PURE__ */ __name((attempt) => new Promise((resolve) => setTimeout(resolve, Math.min(250 * 2 ** attempt, 2e3))), "retryDelay");
|
|
1592
|
+
var validateNonNegativeInteger = /* @__PURE__ */ __name((name, value) => {
|
|
1593
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
1594
|
+
throw new PostPeerError(`${name} must be a non-negative integer.`);
|
|
1595
|
+
}
|
|
1596
|
+
}, "validateNonNegativeInteger");
|
|
1597
|
+
var createPostPeerFetch = /* @__PURE__ */ __name(({
|
|
1598
|
+
fetchImplementation,
|
|
1599
|
+
maxRetries,
|
|
1600
|
+
timeout
|
|
1601
|
+
}) => {
|
|
1602
|
+
return async (input, init) => {
|
|
1603
|
+
const template = input instanceof Request ? input : new Request(input, init);
|
|
1604
|
+
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
1605
|
+
const timeoutController = new AbortController();
|
|
1606
|
+
const timer = setTimeout(
|
|
1607
|
+
() => timeoutController.abort(new DOMException("Request timed out", "TimeoutError")),
|
|
1608
|
+
timeout
|
|
1609
|
+
);
|
|
1610
|
+
const signal = AbortSignal.any([template.signal, timeoutController.signal]);
|
|
1611
|
+
try {
|
|
1612
|
+
const response = await fetchImplementation(new Request(template.clone(), { signal }));
|
|
1613
|
+
if (attempt < maxRetries && isRetryableResponse(response)) {
|
|
1614
|
+
await retryDelay(attempt);
|
|
1615
|
+
continue;
|
|
1616
|
+
}
|
|
1617
|
+
return response;
|
|
1618
|
+
} catch (error) {
|
|
1619
|
+
if (template.signal.aborted) {
|
|
1620
|
+
throw new APIUserAbortError({ cause: error });
|
|
1621
|
+
}
|
|
1622
|
+
if (timeoutController.signal.aborted) {
|
|
1623
|
+
throw new APIConnectionTimeoutError({ cause: error });
|
|
1624
|
+
}
|
|
1625
|
+
if (attempt >= maxRetries) {
|
|
1626
|
+
throw new APIConnectionError("Connection failed.", { cause: error });
|
|
1627
|
+
}
|
|
1628
|
+
await retryDelay(attempt);
|
|
1629
|
+
} finally {
|
|
1630
|
+
clearTimeout(timer);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
throw new APIConnectionError("Connection failed.");
|
|
1634
|
+
};
|
|
1635
|
+
}, "createPostPeerFetch");
|
|
1636
|
+
var PostPeer = class _PostPeer extends PostPeerApi {
|
|
1637
|
+
static {
|
|
1638
|
+
__name(this, "PostPeer");
|
|
1639
|
+
}
|
|
1640
|
+
static DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
|
1641
|
+
static DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES;
|
|
1642
|
+
apiKey;
|
|
1643
|
+
baseURL;
|
|
1644
|
+
timeout;
|
|
1645
|
+
maxRetries;
|
|
1646
|
+
rawClient;
|
|
1647
|
+
#options;
|
|
1648
|
+
constructor(options = {}) {
|
|
1649
|
+
const apiKey = options.apiKey ?? process.env["POSTPEER_API_KEY"];
|
|
1650
|
+
if (!apiKey) {
|
|
1651
|
+
throw new PostPeerError(
|
|
1652
|
+
"The POSTPEER_API_KEY environment variable is missing or empty. Set it or pass new PostPeer({ apiKey: 'your-key' })."
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
const baseURL = options.baseURL ?? DEFAULT_BASE_URL;
|
|
1656
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
1657
|
+
const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1658
|
+
validateNonNegativeInteger("timeout", timeout);
|
|
1659
|
+
validateNonNegativeInteger("maxRetries", maxRetries);
|
|
1660
|
+
const fetchImplementation = options.fetch ?? globalThis.fetch;
|
|
1661
|
+
if (!fetchImplementation) {
|
|
1662
|
+
throw new PostPeerError("No Fetch API implementation is available. Pass one with the fetch option.");
|
|
1663
|
+
}
|
|
1664
|
+
const client2 = createClient({
|
|
1665
|
+
auth: apiKey,
|
|
1666
|
+
baseUrl: baseURL,
|
|
1667
|
+
fetch: createPostPeerFetch({ fetchImplementation, maxRetries, timeout }),
|
|
1668
|
+
headers: {
|
|
1669
|
+
"User-Agent": `postpeer-node/${VERSION}`,
|
|
1670
|
+
...options.defaultHeaders
|
|
1671
|
+
},
|
|
1672
|
+
throwOnError: true
|
|
1673
|
+
});
|
|
1674
|
+
client2.interceptors.error.use((error, response) => {
|
|
1675
|
+
if (error instanceof PostPeerError) return error;
|
|
1676
|
+
if (!response) return new APIConnectionError("Connection failed.", { cause: error });
|
|
1677
|
+
return createAPIError(response, error);
|
|
1678
|
+
});
|
|
1679
|
+
super({ client: client2 });
|
|
1680
|
+
this.apiKey = apiKey;
|
|
1681
|
+
this.baseURL = baseURL;
|
|
1682
|
+
this.timeout = timeout;
|
|
1683
|
+
this.maxRetries = maxRetries;
|
|
1684
|
+
this.rawClient = client2;
|
|
1685
|
+
this.#options = { ...options, apiKey, baseURL, timeout, maxRetries };
|
|
1686
|
+
}
|
|
1687
|
+
withOptions(options) {
|
|
1688
|
+
return new _PostPeer({ ...this.#options, ...options });
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
|
|
1692
|
+
exports.APIConnectionError = APIConnectionError;
|
|
1693
|
+
exports.APIConnectionTimeoutError = APIConnectionTimeoutError;
|
|
1694
|
+
exports.APIError = APIError;
|
|
1695
|
+
exports.APIUserAbortError = APIUserAbortError;
|
|
1696
|
+
exports.AuthenticationError = AuthenticationError;
|
|
1697
|
+
exports.BadRequestError = BadRequestError;
|
|
1698
|
+
exports.ConflictError = ConflictError;
|
|
1699
|
+
exports.InternalServerError = InternalServerError;
|
|
1700
|
+
exports.NotFoundError = NotFoundError;
|
|
1701
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
1702
|
+
exports.PostPeer = PostPeer;
|
|
1703
|
+
exports.PostPeerError = PostPeerError;
|
|
1704
|
+
exports.RateLimitError = RateLimitError;
|
|
1705
|
+
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
1706
|
+
exports.VERSION = VERSION;
|
|
1707
|
+
exports.default = PostPeer;
|
|
1708
|
+
//# sourceMappingURL=index.cjs.map
|
|
1709
|
+
//# sourceMappingURL=index.cjs.map
|