@snagsolutions/sdk 0.1.0-alpha.10
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 +125 -0
- package/LICENSE +201 -0
- package/README.md +297 -0
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/_shims/auto/runtime-bun.d.ts +5 -0
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/_shims/auto/types.js +3 -0
- package/_shims/auto/types.mjs +3 -0
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +241 -0
- package/core.d.ts.map +1 -0
- package/core.js +908 -0
- package/core.js.map +1 -0
- package/core.mjs +876 -0
- package/core.mjs.map +1 -0
- package/error.d.ts +47 -0
- package/error.d.ts.map +1 -0
- package/error.js +113 -0
- package/error.js.map +1 -0
- package/error.mjs +97 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +126 -0
- package/index.d.ts +126 -0
- package/index.d.ts.map +1 -0
- package/index.js +141 -0
- package/index.js.map +1 -0
- package/index.mjs +98 -0
- package/index.mjs.map +1 -0
- package/internal/qs/formats.d.ts +6 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +11 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +8 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +280 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +276 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.ts +14 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +229 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/package.json +103 -0
- package/resource.d.ts +6 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +11 -0
- package/resource.js.map +1 -0
- package/resource.mjs +7 -0
- package/resource.mjs.map +1 -0
- package/resources/assets.d.ts +50 -0
- package/resources/assets.d.ts.map +1 -0
- package/resources/assets.js +17 -0
- package/resources/assets.js.map +1 -0
- package/resources/assets.mjs +13 -0
- package/resources/assets.mjs.map +1 -0
- package/resources/auction-bids.d.ts +81 -0
- package/resources/auction-bids.d.ts.map +1 -0
- package/resources/auction-bids.js +30 -0
- package/resources/auction-bids.js.map +1 -0
- package/resources/auction-bids.mjs +26 -0
- package/resources/auction-bids.mjs.map +1 -0
- package/resources/drip/drip.d.ts +14 -0
- package/resources/drip/drip.d.ts.map +1 -0
- package/resources/drip/drip.js +43 -0
- package/resources/drip/drip.js.map +1 -0
- package/resources/drip/drip.mjs +16 -0
- package/resources/drip/drip.mjs.map +1 -0
- package/resources/drip/index.d.ts +4 -0
- package/resources/drip/index.d.ts.map +1 -0
- package/resources/drip/index.js +11 -0
- package/resources/drip/index.js.map +1 -0
- package/resources/drip/index.mjs +5 -0
- package/resources/drip/index.mjs.map +1 -0
- package/resources/drip/quests.d.ts +168 -0
- package/resources/drip/quests.d.ts.map +1 -0
- package/resources/drip/quests.js +17 -0
- package/resources/drip/quests.js.map +1 -0
- package/resources/drip/quests.mjs +13 -0
- package/resources/drip/quests.mjs.map +1 -0
- package/resources/drip/status.d.ts +26 -0
- package/resources/drip/status.d.ts.map +1 -0
- package/resources/drip/status.js +16 -0
- package/resources/drip/status.js.map +1 -0
- package/resources/drip/status.mjs +12 -0
- package/resources/drip/status.mjs.map +1 -0
- package/resources/index.d.ts +7 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +17 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +8 -0
- package/resources/index.mjs.map +1 -0
- package/resources/loyalty/accounts.d.ts +157 -0
- package/resources/loyalty/accounts.d.ts.map +1 -0
- package/resources/loyalty/accounts.js +16 -0
- package/resources/loyalty/accounts.js.map +1 -0
- package/resources/loyalty/accounts.mjs +12 -0
- package/resources/loyalty/accounts.mjs.map +1 -0
- package/resources/loyalty/badges.d.ts +299 -0
- package/resources/loyalty/badges.d.ts.map +1 -0
- package/resources/loyalty/badges.js +46 -0
- package/resources/loyalty/badges.js.map +1 -0
- package/resources/loyalty/badges.mjs +42 -0
- package/resources/loyalty/badges.mjs.map +1 -0
- package/resources/loyalty/currencies.d.ts +252 -0
- package/resources/loyalty/currencies.d.ts.map +1 -0
- package/resources/loyalty/currencies.js +21 -0
- package/resources/loyalty/currencies.js.map +1 -0
- package/resources/loyalty/currencies.mjs +17 -0
- package/resources/loyalty/currencies.mjs.map +1 -0
- package/resources/loyalty/index.d.ts +9 -0
- package/resources/loyalty/index.d.ts.map +1 -0
- package/resources/loyalty/index.js +21 -0
- package/resources/loyalty/index.js.map +1 -0
- package/resources/loyalty/index.mjs +10 -0
- package/resources/loyalty/index.mjs.map +1 -0
- package/resources/loyalty/loyalty.d.ts +34 -0
- package/resources/loyalty/loyalty.d.ts.map +1 -0
- package/resources/loyalty/loyalty.js +63 -0
- package/resources/loyalty/loyalty.js.map +1 -0
- package/resources/loyalty/loyalty.mjs +36 -0
- package/resources/loyalty/loyalty.mjs.map +1 -0
- package/resources/loyalty/multipliers.d.ts +129 -0
- package/resources/loyalty/multipliers.d.ts.map +1 -0
- package/resources/loyalty/multipliers.js +34 -0
- package/resources/loyalty/multipliers.js.map +1 -0
- package/resources/loyalty/multipliers.mjs +30 -0
- package/resources/loyalty/multipliers.mjs.map +1 -0
- package/resources/loyalty/rule-edits.d.ts +330 -0
- package/resources/loyalty/rule-edits.d.ts.map +1 -0
- package/resources/loyalty/rule-edits.js +21 -0
- package/resources/loyalty/rule-edits.js.map +1 -0
- package/resources/loyalty/rule-edits.mjs +17 -0
- package/resources/loyalty/rule-edits.mjs.map +1 -0
- package/resources/loyalty/rules.d.ts +2430 -0
- package/resources/loyalty/rules.d.ts.map +1 -0
- package/resources/loyalty/rules.js +46 -0
- package/resources/loyalty/rules.js.map +1 -0
- package/resources/loyalty/rules.mjs +42 -0
- package/resources/loyalty/rules.mjs.map +1 -0
- package/resources/loyalty/transaction-entries.d.ts +175 -0
- package/resources/loyalty/transaction-entries.d.ts.map +1 -0
- package/resources/loyalty/transaction-entries.js +16 -0
- package/resources/loyalty/transaction-entries.js.map +1 -0
- package/resources/loyalty/transaction-entries.mjs +12 -0
- package/resources/loyalty/transaction-entries.mjs.map +1 -0
- package/resources/users/index.d.ts +4 -0
- package/resources/users/index.d.ts.map +1 -0
- package/resources/users/index.js +11 -0
- package/resources/users/index.js.map +1 -0
- package/resources/users/index.mjs +5 -0
- package/resources/users/index.mjs.map +1 -0
- package/resources/users/metadatas.d.ts +64 -0
- package/resources/users/metadatas.d.ts.map +1 -0
- package/resources/users/metadatas.js +16 -0
- package/resources/users/metadatas.js.map +1 -0
- package/resources/users/metadatas.mjs +12 -0
- package/resources/users/metadatas.mjs.map +1 -0
- package/resources/users/users.d.ts +14 -0
- package/resources/users/users.d.ts.map +1 -0
- package/resources/users/users.js +43 -0
- package/resources/users/users.js.map +1 -0
- package/resources/users/users.mjs +16 -0
- package/resources/users/users.mjs.map +1 -0
- package/resources/users/wallets.d.ts +193 -0
- package/resources/users/wallets.d.ts.map +1 -0
- package/resources/users/wallets.js +28 -0
- package/resources/users/wallets.js.map +1 -0
- package/resources/users/wallets.mjs +24 -0
- package/resources/users/wallets.mjs.map +1 -0
- package/resources/websites.d.ts +203 -0
- package/resources/websites.d.ts.map +1 -0
- package/resources/websites.js +22 -0
- package/resources/websites.js.map +1 -0
- package/resources/websites.mjs +18 -0
- package/resources/websites.mjs.map +1 -0
- package/shims/node.d.ts +30 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +1201 -0
- package/src/error.ts +130 -0
- package/src/index.ts +235 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +9 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +388 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/lib/.keep +4 -0
- package/src/resource.ts +11 -0
- package/src/resources/assets.ts +71 -0
- package/src/resources/auction-bids.ts +123 -0
- package/src/resources/drip/drip.ts +25 -0
- package/src/resources/drip/index.ts +5 -0
- package/src/resources/drip/quests.ts +210 -0
- package/src/resources/drip/status.ts +33 -0
- package/src/resources/index.ts +14 -0
- package/src/resources/loyalty/accounts.ts +199 -0
- package/src/resources/loyalty/badges.ts +435 -0
- package/src/resources/loyalty/currencies.ts +321 -0
- package/src/resources/loyalty/index.ts +61 -0
- package/src/resources/loyalty/loyalty.ts +159 -0
- package/src/resources/loyalty/multipliers.ts +238 -0
- package/src/resources/loyalty/rule-edits.ts +421 -0
- package/src/resources/loyalty/rules.ts +3513 -0
- package/src/resources/loyalty/transaction-entries.ts +229 -0
- package/src/resources/users/index.ts +12 -0
- package/src/resources/users/metadatas.ts +103 -0
- package/src/resources/users/users.ts +39 -0
- package/src/resources/users/wallets.ts +271 -0
- package/src/resources/websites.ts +259 -0
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +255 -0
- package/src/version.ts +1 -0
- package/uploads.d.ts +75 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +171 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +158 -0
- package/uploads.mjs.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
package/src/error.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { castToError, Headers } from './core';
|
|
4
|
+
|
|
5
|
+
export class SnagSolutionsError extends Error {}
|
|
6
|
+
|
|
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 SnagSolutionsError {
|
|
12
|
+
/** HTTP status for the response that caused the error */
|
|
13
|
+
readonly status: TStatus;
|
|
14
|
+
/** HTTP headers for the response that caused the error */
|
|
15
|
+
readonly headers: THeaders;
|
|
16
|
+
/** JSON body of the response that caused the error */
|
|
17
|
+
readonly error: TError;
|
|
18
|
+
|
|
19
|
+
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
|
|
20
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.headers = headers;
|
|
23
|
+
this.error = error;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
27
|
+
const msg =
|
|
28
|
+
error?.message ?
|
|
29
|
+
typeof error.message === 'string' ?
|
|
30
|
+
error.message
|
|
31
|
+
: JSON.stringify(error.message)
|
|
32
|
+
: error ? JSON.stringify(error)
|
|
33
|
+
: message;
|
|
34
|
+
|
|
35
|
+
if (status && msg) {
|
|
36
|
+
return `${status} ${msg}`;
|
|
37
|
+
}
|
|
38
|
+
if (status) {
|
|
39
|
+
return `${status} status code (no body)`;
|
|
40
|
+
}
|
|
41
|
+
if (msg) {
|
|
42
|
+
return msg;
|
|
43
|
+
}
|
|
44
|
+
return '(no status code or body)';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static generate(
|
|
48
|
+
status: number | undefined,
|
|
49
|
+
errorResponse: Object | undefined,
|
|
50
|
+
message: string | undefined,
|
|
51
|
+
headers: Headers | undefined,
|
|
52
|
+
): APIError {
|
|
53
|
+
if (!status || !headers) {
|
|
54
|
+
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const error = errorResponse as Record<string, any>;
|
|
58
|
+
|
|
59
|
+
if (status === 400) {
|
|
60
|
+
return new BadRequestError(status, error, message, headers);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (status === 401) {
|
|
64
|
+
return new AuthenticationError(status, error, message, headers);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (status === 403) {
|
|
68
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (status === 404) {
|
|
72
|
+
return new NotFoundError(status, error, message, headers);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (status === 409) {
|
|
76
|
+
return new ConflictError(status, error, message, headers);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (status === 422) {
|
|
80
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (status === 429) {
|
|
84
|
+
return new RateLimitError(status, error, message, headers);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (status >= 500) {
|
|
88
|
+
return new InternalServerError(status, error, message, headers);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new APIError(status, error, message, headers);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
|
|
96
|
+
constructor({ message }: { message?: string } = {}) {
|
|
97
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export class APIConnectionError extends APIError<undefined, undefined, undefined> {
|
|
102
|
+
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
|
|
103
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
104
|
+
// in some environments the 'cause' property is already declared
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
if (cause) this.cause = cause;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
111
|
+
constructor({ message }: { message?: string } = {}) {
|
|
112
|
+
super({ message: message ?? 'Request timed out.' });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class BadRequestError extends APIError<400, Headers> {}
|
|
117
|
+
|
|
118
|
+
export class AuthenticationError extends APIError<401, Headers> {}
|
|
119
|
+
|
|
120
|
+
export class PermissionDeniedError extends APIError<403, Headers> {}
|
|
121
|
+
|
|
122
|
+
export class NotFoundError extends APIError<404, Headers> {}
|
|
123
|
+
|
|
124
|
+
export class ConflictError extends APIError<409, Headers> {}
|
|
125
|
+
|
|
126
|
+
export class UnprocessableEntityError extends APIError<422, Headers> {}
|
|
127
|
+
|
|
128
|
+
export class RateLimitError extends APIError<429, Headers> {}
|
|
129
|
+
|
|
130
|
+
export class InternalServerError extends APIError<number, Headers> {}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { type Agent } from './_shims/index';
|
|
4
|
+
import * as qs from './internal/qs';
|
|
5
|
+
import * as Core from './core';
|
|
6
|
+
import * as Errors from './error';
|
|
7
|
+
import * as Uploads from './uploads';
|
|
8
|
+
import * as API from './resources/index';
|
|
9
|
+
import { AssetCreateParams, AssetCreateResponse, Assets } from './resources/assets';
|
|
10
|
+
import { AuctionBidCreateParams, AuctionBidListParams, AuctionBids } from './resources/auction-bids';
|
|
11
|
+
import {
|
|
12
|
+
WebsiteCreateParams,
|
|
13
|
+
WebsiteCreateResponse,
|
|
14
|
+
WebsiteListParams,
|
|
15
|
+
WebsiteListResponse,
|
|
16
|
+
Websites,
|
|
17
|
+
} from './resources/websites';
|
|
18
|
+
import { Drip } from './resources/drip/drip';
|
|
19
|
+
import { Loyalty } from './resources/loyalty/loyalty';
|
|
20
|
+
import { Users } from './resources/users/users';
|
|
21
|
+
|
|
22
|
+
export interface ClientOptions {
|
|
23
|
+
/**
|
|
24
|
+
* API key required to authenticate with the Snag Solutions API.
|
|
25
|
+
*/
|
|
26
|
+
apiKey?: string | undefined;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
30
|
+
*
|
|
31
|
+
* Defaults to process.env['SNAG_SOLUTIONS_BASE_URL'].
|
|
32
|
+
*/
|
|
33
|
+
baseURL?: string | null | undefined;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
37
|
+
* from the server before timing out a single request.
|
|
38
|
+
*
|
|
39
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
40
|
+
* much longer than this timeout before the promise succeeds or fails.
|
|
41
|
+
*/
|
|
42
|
+
timeout?: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An HTTP agent used to manage HTTP(S) connections.
|
|
46
|
+
*
|
|
47
|
+
* If not provided, an agent will be constructed by default in the Node.js environment,
|
|
48
|
+
* otherwise no agent is used.
|
|
49
|
+
*/
|
|
50
|
+
httpAgent?: Agent;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Specify a custom `fetch` function implementation.
|
|
54
|
+
*
|
|
55
|
+
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
|
56
|
+
* defined globally.
|
|
57
|
+
*/
|
|
58
|
+
fetch?: Core.Fetch | undefined;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The maximum number of times that the client will retry a request in case of a
|
|
62
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
|
63
|
+
*
|
|
64
|
+
* @default 2
|
|
65
|
+
*/
|
|
66
|
+
maxRetries?: number;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Default headers to include with every request to the API.
|
|
70
|
+
*
|
|
71
|
+
* These can be removed in individual requests by explicitly setting the
|
|
72
|
+
* header to `undefined` or `null` in request options.
|
|
73
|
+
*/
|
|
74
|
+
defaultHeaders?: Core.Headers;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Default query parameters to include with every request to the API.
|
|
78
|
+
*
|
|
79
|
+
* These can be removed in individual requests by explicitly setting the
|
|
80
|
+
* param to `undefined` in request options.
|
|
81
|
+
*/
|
|
82
|
+
defaultQuery?: Core.DefaultQuery;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* API Client for interfacing with the Snag Solutions API.
|
|
87
|
+
*/
|
|
88
|
+
export class SnagSolutions extends Core.APIClient {
|
|
89
|
+
apiKey: string;
|
|
90
|
+
|
|
91
|
+
private _options: ClientOptions;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* API Client for interfacing with the Snag Solutions API.
|
|
95
|
+
*
|
|
96
|
+
* @param {string | undefined} [opts.apiKey=process.env['X_API_KEY'] ?? undefined]
|
|
97
|
+
* @param {string} [opts.baseURL=process.env['SNAG_SOLUTIONS_BASE_URL'] ?? https://admin.snagsolutions.io/] - Override the default base URL for the API.
|
|
98
|
+
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
99
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
100
|
+
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
101
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
102
|
+
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
103
|
+
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
104
|
+
*/
|
|
105
|
+
constructor({
|
|
106
|
+
baseURL = Core.readEnv('SNAG_SOLUTIONS_BASE_URL'),
|
|
107
|
+
apiKey = Core.readEnv('X_API_KEY'),
|
|
108
|
+
...opts
|
|
109
|
+
}: ClientOptions = {}) {
|
|
110
|
+
if (apiKey === undefined) {
|
|
111
|
+
throw new Errors.SnagSolutionsError(
|
|
112
|
+
"The X_API_KEY environment variable is missing or empty; either provide it, or instantiate the SnagSolutions client with an apiKey option, like new SnagSolutions({ apiKey: 'My API Key' }).",
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const options: ClientOptions = {
|
|
117
|
+
apiKey,
|
|
118
|
+
...opts,
|
|
119
|
+
baseURL: baseURL || `https://admin.snagsolutions.io/`,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
super({
|
|
123
|
+
baseURL: options.baseURL!,
|
|
124
|
+
timeout: options.timeout ?? 60000 /* 1 minute */,
|
|
125
|
+
httpAgent: options.httpAgent,
|
|
126
|
+
maxRetries: options.maxRetries,
|
|
127
|
+
fetch: options.fetch,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
this._options = options;
|
|
131
|
+
|
|
132
|
+
this.apiKey = apiKey;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
assets: API.Assets = new API.Assets(this);
|
|
136
|
+
users: API.Users = new API.Users(this);
|
|
137
|
+
loyalty: API.Loyalty = new API.Loyalty(this);
|
|
138
|
+
auctionBids: API.AuctionBids = new API.AuctionBids(this);
|
|
139
|
+
websites: API.Websites = new API.Websites(this);
|
|
140
|
+
drip: API.Drip = new API.Drip(this);
|
|
141
|
+
|
|
142
|
+
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
143
|
+
return this._options.defaultQuery;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
147
|
+
return {
|
|
148
|
+
...super.defaultHeaders(opts),
|
|
149
|
+
...this._options.defaultHeaders,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
154
|
+
return { 'X-API-KEY': this.apiKey };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
protected override stringifyQuery(query: Record<string, unknown>): string {
|
|
158
|
+
return qs.stringify(query, { arrayFormat: 'comma' });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static SnagSolutions = this;
|
|
162
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
163
|
+
|
|
164
|
+
static SnagSolutionsError = Errors.SnagSolutionsError;
|
|
165
|
+
static APIError = Errors.APIError;
|
|
166
|
+
static APIConnectionError = Errors.APIConnectionError;
|
|
167
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
168
|
+
static APIUserAbortError = Errors.APIUserAbortError;
|
|
169
|
+
static NotFoundError = Errors.NotFoundError;
|
|
170
|
+
static ConflictError = Errors.ConflictError;
|
|
171
|
+
static RateLimitError = Errors.RateLimitError;
|
|
172
|
+
static BadRequestError = Errors.BadRequestError;
|
|
173
|
+
static AuthenticationError = Errors.AuthenticationError;
|
|
174
|
+
static InternalServerError = Errors.InternalServerError;
|
|
175
|
+
static PermissionDeniedError = Errors.PermissionDeniedError;
|
|
176
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
|
177
|
+
|
|
178
|
+
static toFile = Uploads.toFile;
|
|
179
|
+
static fileFromPath = Uploads.fileFromPath;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
SnagSolutions.Assets = Assets;
|
|
183
|
+
SnagSolutions.Users = Users;
|
|
184
|
+
SnagSolutions.Loyalty = Loyalty;
|
|
185
|
+
SnagSolutions.AuctionBids = AuctionBids;
|
|
186
|
+
SnagSolutions.Websites = Websites;
|
|
187
|
+
SnagSolutions.Drip = Drip;
|
|
188
|
+
export declare namespace SnagSolutions {
|
|
189
|
+
export type RequestOptions = Core.RequestOptions;
|
|
190
|
+
|
|
191
|
+
export {
|
|
192
|
+
Assets as Assets,
|
|
193
|
+
type AssetCreateResponse as AssetCreateResponse,
|
|
194
|
+
type AssetCreateParams as AssetCreateParams,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export { Users as Users };
|
|
198
|
+
|
|
199
|
+
export { Loyalty as Loyalty };
|
|
200
|
+
|
|
201
|
+
export {
|
|
202
|
+
AuctionBids as AuctionBids,
|
|
203
|
+
type AuctionBidCreateParams as AuctionBidCreateParams,
|
|
204
|
+
type AuctionBidListParams as AuctionBidListParams,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export {
|
|
208
|
+
Websites as Websites,
|
|
209
|
+
type WebsiteCreateResponse as WebsiteCreateResponse,
|
|
210
|
+
type WebsiteListResponse as WebsiteListResponse,
|
|
211
|
+
type WebsiteCreateParams as WebsiteCreateParams,
|
|
212
|
+
type WebsiteListParams as WebsiteListParams,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export { Drip as Drip };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { toFile, fileFromPath } from './uploads';
|
|
219
|
+
export {
|
|
220
|
+
SnagSolutionsError,
|
|
221
|
+
APIError,
|
|
222
|
+
APIConnectionError,
|
|
223
|
+
APIConnectionTimeoutError,
|
|
224
|
+
APIUserAbortError,
|
|
225
|
+
NotFoundError,
|
|
226
|
+
ConflictError,
|
|
227
|
+
RateLimitError,
|
|
228
|
+
BadRequestError,
|
|
229
|
+
AuthenticationError,
|
|
230
|
+
InternalServerError,
|
|
231
|
+
PermissionDeniedError,
|
|
232
|
+
UnprocessableEntityError,
|
|
233
|
+
} from './error';
|
|
234
|
+
|
|
235
|
+
export default SnagSolutions;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/puruvj/neoqs/graphs/contributors) All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
10
|
+
|
|
11
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Format } from './types';
|
|
2
|
+
|
|
3
|
+
export const default_format: Format = 'RFC3986';
|
|
4
|
+
export const formatters: Record<Format, (str: PropertyKey) => string> = {
|
|
5
|
+
RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),
|
|
6
|
+
RFC3986: (v: PropertyKey) => String(v),
|
|
7
|
+
};
|
|
8
|
+
export const RFC1738 = 'RFC1738';
|
|
9
|
+
export const RFC3986 = 'RFC3986';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default_format, formatters, RFC1738, RFC3986 } from './formats';
|
|
2
|
+
|
|
3
|
+
const formats = {
|
|
4
|
+
formatters,
|
|
5
|
+
RFC1738,
|
|
6
|
+
RFC3986,
|
|
7
|
+
default: default_format,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { stringify } from './stringify';
|
|
11
|
+
export { formats };
|
|
12
|
+
|
|
13
|
+
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types';
|