postgrid-node 0.1.0-alpha.1
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 +19 -0
- package/LICENSE +201 -0
- package/README.md +346 -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 +914 -0
- package/core.js.map +1 -0
- package/core.mjs +882 -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 +144 -0
- package/index.d.ts +144 -0
- package/index.d.ts.map +1 -0
- package/index.js +161 -0
- package/index.js.map +1 -0
- package/index.mjs +118 -0
- package/index.mjs.map +1 -0
- package/package.json +124 -0
- package/pagination.d.ts +24 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +45 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +41 -0
- package/pagination.mjs.map +1 -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/bank-accounts.d.ts +285 -0
- package/resources/bank-accounts.d.ts.map +1 -0
- package/resources/bank-accounts.js +45 -0
- package/resources/bank-accounts.js.map +1 -0
- package/resources/bank-accounts.mjs +40 -0
- package/resources/bank-accounts.mjs.map +1 -0
- package/resources/boxes.d.ts +683 -0
- package/resources/boxes.d.ts.map +1 -0
- package/resources/boxes.js +54 -0
- package/resources/boxes.js.map +1 -0
- package/resources/boxes.mjs +49 -0
- package/resources/boxes.mjs.map +1 -0
- package/resources/campaigns.d.ts +644 -0
- package/resources/campaigns.d.ts.map +1 -0
- package/resources/campaigns.js +67 -0
- package/resources/campaigns.js.map +1 -0
- package/resources/campaigns.mjs +62 -0
- package/resources/campaigns.mjs.map +1 -0
- package/resources/cheques/cheques.d.ts +349 -0
- package/resources/cheques/cheques.d.ts.map +1 -0
- package/resources/cheques/cheques.js +95 -0
- package/resources/cheques/cheques.js.map +1 -0
- package/resources/cheques/cheques.mjs +67 -0
- package/resources/cheques/cheques.mjs.map +1 -0
- package/resources/cheques/index.d.ts +4 -0
- package/resources/cheques/index.d.ts.map +1 -0
- package/resources/cheques/index.js +12 -0
- package/resources/cheques/index.js.map +1 -0
- package/resources/cheques/index.mjs +5 -0
- package/resources/cheques/index.mjs.map +1 -0
- package/resources/cheques/url.d.ts +29 -0
- package/resources/cheques/url.d.ts.map +1 -0
- package/resources/cheques/url.js +20 -0
- package/resources/cheques/url.js.map +1 -0
- package/resources/cheques/url.mjs +16 -0
- package/resources/cheques/url.mjs.map +1 -0
- package/resources/cheques/with-deposit-ready-pdf.d.ts +13 -0
- package/resources/cheques/with-deposit-ready-pdf.d.ts.map +1 -0
- package/resources/cheques/with-deposit-ready-pdf.js +18 -0
- package/resources/cheques/with-deposit-ready-pdf.js.map +1 -0
- package/resources/cheques/with-deposit-ready-pdf.mjs +14 -0
- package/resources/cheques/with-deposit-ready-pdf.mjs.map +1 -0
- package/resources/contacts.d.ts +295 -0
- package/resources/contacts.d.ts.map +1 -0
- package/resources/contacts.js +52 -0
- package/resources/contacts.js.map +1 -0
- package/resources/contacts.mjs +47 -0
- package/resources/contacts.mjs.map +1 -0
- package/resources/index.d.ts +12 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +50 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +13 -0
- package/resources/index.mjs.map +1 -0
- package/resources/letters.d.ts +639 -0
- package/resources/letters.d.ts.map +1 -0
- package/resources/letters.js +55 -0
- package/resources/letters.js.map +1 -0
- package/resources/letters.mjs +50 -0
- package/resources/letters.mjs.map +1 -0
- package/resources/postcards.d.ts +346 -0
- package/resources/postcards.d.ts.map +1 -0
- package/resources/postcards.js +56 -0
- package/resources/postcards.js.map +1 -0
- package/resources/postcards.mjs +51 -0
- package/resources/postcards.mjs.map +1 -0
- package/resources/reports/exports.d.ts +207 -0
- package/resources/reports/exports.d.ts.map +1 -0
- package/resources/reports/exports.js +33 -0
- package/resources/reports/exports.js.map +1 -0
- package/resources/reports/exports.mjs +29 -0
- package/resources/reports/exports.mjs.map +1 -0
- package/resources/reports/index.d.ts +4 -0
- package/resources/reports/index.d.ts.map +1 -0
- package/resources/reports/index.js +12 -0
- package/resources/reports/index.js.map +1 -0
- package/resources/reports/index.mjs +5 -0
- package/resources/reports/index.mjs.map +1 -0
- package/resources/reports/reports.d.ts +245 -0
- package/resources/reports/reports.d.ts.map +1 -0
- package/resources/reports/reports.js +85 -0
- package/resources/reports/reports.js.map +1 -0
- package/resources/reports/reports.mjs +57 -0
- package/resources/reports/reports.mjs.map +1 -0
- package/resources/reports/samples.d.ts +81 -0
- package/resources/reports/samples.d.ts.map +1 -0
- package/resources/reports/samples.js +26 -0
- package/resources/reports/samples.js.map +1 -0
- package/resources/reports/samples.mjs +22 -0
- package/resources/reports/samples.mjs.map +1 -0
- package/resources/self-mailers.d.ts +622 -0
- package/resources/self-mailers.d.ts.map +1 -0
- package/resources/self-mailers.js +45 -0
- package/resources/self-mailers.js.map +1 -0
- package/resources/self-mailers.mjs +40 -0
- package/resources/self-mailers.mjs.map +1 -0
- package/resources/shared.d.ts +147 -0
- package/resources/shared.d.ts.map +1 -0
- package/resources/shared.js +4 -0
- package/resources/shared.js.map +1 -0
- package/resources/shared.mjs +3 -0
- package/resources/shared.mjs.map +1 -0
- package/resources/templates.d.ts +126 -0
- package/resources/templates.d.ts.map +1 -0
- package/resources/templates.js +46 -0
- package/resources/templates.js.map +1 -0
- package/resources/templates.mjs +41 -0
- package/resources/templates.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 +1208 -0
- package/src/error.ts +130 -0
- package/src/index.ts +428 -0
- package/src/lib/.keep +4 -0
- package/src/pagination.ts +69 -0
- package/src/resource.ts +11 -0
- package/src/resources/bank-accounts.ts +382 -0
- package/src/resources/boxes.ts +982 -0
- package/src/resources/campaigns.ts +853 -0
- package/src/resources/cheques/cheques.ts +493 -0
- package/src/resources/cheques/index.ts +12 -0
- package/src/resources/cheques/url.ts +37 -0
- package/src/resources/cheques/with-deposit-ready-pdf.ts +17 -0
- package/src/resources/contacts.ts +387 -0
- package/src/resources/index.ts +102 -0
- package/src/resources/letters.ts +870 -0
- package/src/resources/postcards.ts +548 -0
- package/src/resources/reports/exports.ts +272 -0
- package/src/resources/reports/index.ts +28 -0
- package/src/resources/reports/reports.ts +359 -0
- package/src/resources/reports/samples.ts +109 -0
- package/src/resources/self-mailers.ts +958 -0
- package/src/resources/shared.ts +182 -0
- package/src/resources/templates.ts +184 -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 PostGridError 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 PostGridError {
|
|
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,428 @@
|
|
|
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 Core from './core';
|
|
5
|
+
import * as Errors from './error';
|
|
6
|
+
import * as Pagination from './pagination';
|
|
7
|
+
import { type ListParams, ListResponse } from './pagination';
|
|
8
|
+
import * as Uploads from './uploads';
|
|
9
|
+
import * as API from './resources/index';
|
|
10
|
+
import {
|
|
11
|
+
BankAccount,
|
|
12
|
+
BankAccountCreateParams,
|
|
13
|
+
BankAccountDeleteResponse,
|
|
14
|
+
BankAccountList,
|
|
15
|
+
BankAccountListParams,
|
|
16
|
+
BankAccounts,
|
|
17
|
+
BankAccountsList,
|
|
18
|
+
} from './resources/bank-accounts';
|
|
19
|
+
import {
|
|
20
|
+
BoxCancelResponse,
|
|
21
|
+
BoxCreateParams,
|
|
22
|
+
BoxCreateResponse,
|
|
23
|
+
BoxListParams,
|
|
24
|
+
BoxListResponse,
|
|
25
|
+
BoxListResponsesList,
|
|
26
|
+
BoxRetrieveResponse,
|
|
27
|
+
Boxes,
|
|
28
|
+
} from './resources/boxes';
|
|
29
|
+
import {
|
|
30
|
+
CampaignCreateParams,
|
|
31
|
+
CampaignCreateResponse,
|
|
32
|
+
CampaignDeleteResponse,
|
|
33
|
+
CampaignListParams,
|
|
34
|
+
CampaignListResponse,
|
|
35
|
+
CampaignListResponsesList,
|
|
36
|
+
CampaignRetrieveResponse,
|
|
37
|
+
CampaignSendParams,
|
|
38
|
+
CampaignSendResponse,
|
|
39
|
+
CampaignUpdateParams,
|
|
40
|
+
CampaignUpdateResponse,
|
|
41
|
+
Campaigns,
|
|
42
|
+
} from './resources/campaigns';
|
|
43
|
+
import {
|
|
44
|
+
Contact,
|
|
45
|
+
ContactCreateParams,
|
|
46
|
+
ContactDeleteResponse,
|
|
47
|
+
ContactListParams,
|
|
48
|
+
Contacts,
|
|
49
|
+
ContactsList,
|
|
50
|
+
} from './resources/contacts';
|
|
51
|
+
import {
|
|
52
|
+
Letter,
|
|
53
|
+
LetterCreateParams,
|
|
54
|
+
LetterList,
|
|
55
|
+
LetterListParams,
|
|
56
|
+
LetterURLResponse,
|
|
57
|
+
Letters,
|
|
58
|
+
LettersList,
|
|
59
|
+
} from './resources/letters';
|
|
60
|
+
import {
|
|
61
|
+
Postcard,
|
|
62
|
+
PostcardCreateParams,
|
|
63
|
+
PostcardList,
|
|
64
|
+
PostcardListParams,
|
|
65
|
+
PostcardURLResponse,
|
|
66
|
+
Postcards,
|
|
67
|
+
PostcardsList,
|
|
68
|
+
} from './resources/postcards';
|
|
69
|
+
import {
|
|
70
|
+
SelfMailerCancelResponse,
|
|
71
|
+
SelfMailerCreateParams,
|
|
72
|
+
SelfMailerCreateResponse,
|
|
73
|
+
SelfMailerListParams,
|
|
74
|
+
SelfMailerListResponse,
|
|
75
|
+
SelfMailerListResponsesList,
|
|
76
|
+
SelfMailerRetrieveResponse,
|
|
77
|
+
SelfMailers,
|
|
78
|
+
} from './resources/self-mailers';
|
|
79
|
+
import {
|
|
80
|
+
Template,
|
|
81
|
+
TemplateCreateParams,
|
|
82
|
+
TemplateDeleteResponse,
|
|
83
|
+
TemplateList,
|
|
84
|
+
TemplateListParams,
|
|
85
|
+
TemplateUpdateParams,
|
|
86
|
+
Templates,
|
|
87
|
+
TemplatesList,
|
|
88
|
+
} from './resources/templates';
|
|
89
|
+
import {
|
|
90
|
+
Cheque,
|
|
91
|
+
ChequeCreateParams,
|
|
92
|
+
ChequeList,
|
|
93
|
+
ChequeListParams,
|
|
94
|
+
Cheques,
|
|
95
|
+
ChequesList,
|
|
96
|
+
} from './resources/cheques/cheques';
|
|
97
|
+
import {
|
|
98
|
+
ReportCreateParams,
|
|
99
|
+
ReportCreateResponse,
|
|
100
|
+
ReportDeleteResponse,
|
|
101
|
+
ReportListParams,
|
|
102
|
+
ReportListResponse,
|
|
103
|
+
ReportListResponsesList,
|
|
104
|
+
ReportRetrieveResponse,
|
|
105
|
+
ReportUpdateParams,
|
|
106
|
+
ReportUpdateResponse,
|
|
107
|
+
Reports,
|
|
108
|
+
} from './resources/reports/reports';
|
|
109
|
+
|
|
110
|
+
export interface ClientOptions {
|
|
111
|
+
/**
|
|
112
|
+
* Defaults to process.env['POSTGRID_API_KEY'].
|
|
113
|
+
*/
|
|
114
|
+
apiKey?: string | undefined;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
118
|
+
*
|
|
119
|
+
* Defaults to process.env['POSTGRID_BASE_URL'].
|
|
120
|
+
*/
|
|
121
|
+
baseURL?: string | null | undefined;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
125
|
+
* from the server before timing out a single request.
|
|
126
|
+
*
|
|
127
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
128
|
+
* much longer than this timeout before the promise succeeds or fails.
|
|
129
|
+
*/
|
|
130
|
+
timeout?: number | undefined;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* An HTTP agent used to manage HTTP(S) connections.
|
|
134
|
+
*
|
|
135
|
+
* If not provided, an agent will be constructed by default in the Node.js environment,
|
|
136
|
+
* otherwise no agent is used.
|
|
137
|
+
*/
|
|
138
|
+
httpAgent?: Agent | undefined;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Specify a custom `fetch` function implementation.
|
|
142
|
+
*
|
|
143
|
+
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
|
144
|
+
* defined globally.
|
|
145
|
+
*/
|
|
146
|
+
fetch?: Core.Fetch | undefined;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The maximum number of times that the client will retry a request in case of a
|
|
150
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
|
151
|
+
*
|
|
152
|
+
* @default 2
|
|
153
|
+
*/
|
|
154
|
+
maxRetries?: number | undefined;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Default headers to include with every request to the API.
|
|
158
|
+
*
|
|
159
|
+
* These can be removed in individual requests by explicitly setting the
|
|
160
|
+
* header to `undefined` or `null` in request options.
|
|
161
|
+
*/
|
|
162
|
+
defaultHeaders?: Core.Headers | undefined;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Default query parameters to include with every request to the API.
|
|
166
|
+
*
|
|
167
|
+
* These can be removed in individual requests by explicitly setting the
|
|
168
|
+
* param to `undefined` in request options.
|
|
169
|
+
*/
|
|
170
|
+
defaultQuery?: Core.DefaultQuery | undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* API Client for interfacing with the PostGrid API.
|
|
175
|
+
*/
|
|
176
|
+
export class PostGrid extends Core.APIClient {
|
|
177
|
+
apiKey: string;
|
|
178
|
+
|
|
179
|
+
private _options: ClientOptions;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* API Client for interfacing with the PostGrid API.
|
|
183
|
+
*
|
|
184
|
+
* @param {string | undefined} [opts.apiKey=process.env['POSTGRID_API_KEY'] ?? undefined]
|
|
185
|
+
* @param {string} [opts.baseURL=process.env['POSTGRID_BASE_URL'] ?? https://api.postgrid.com/print-mail/v1] - Override the default base URL for the API.
|
|
186
|
+
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
187
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
188
|
+
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
189
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
190
|
+
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
191
|
+
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
192
|
+
*/
|
|
193
|
+
constructor({
|
|
194
|
+
baseURL = Core.readEnv('POSTGRID_BASE_URL'),
|
|
195
|
+
apiKey = Core.readEnv('POSTGRID_API_KEY'),
|
|
196
|
+
...opts
|
|
197
|
+
}: ClientOptions = {}) {
|
|
198
|
+
if (apiKey === undefined) {
|
|
199
|
+
throw new Errors.PostGridError(
|
|
200
|
+
"The POSTGRID_API_KEY environment variable is missing or empty; either provide it, or instantiate the PostGrid client with an apiKey option, like new PostGrid({ apiKey: 'My API Key' }).",
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const options: ClientOptions = {
|
|
205
|
+
apiKey,
|
|
206
|
+
...opts,
|
|
207
|
+
baseURL: baseURL || `https://api.postgrid.com/print-mail/v1`,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
super({
|
|
211
|
+
baseURL: options.baseURL!,
|
|
212
|
+
timeout: options.timeout ?? 60000 /* 1 minute */,
|
|
213
|
+
httpAgent: options.httpAgent,
|
|
214
|
+
maxRetries: options.maxRetries,
|
|
215
|
+
fetch: options.fetch,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
this._options = options;
|
|
219
|
+
this.idempotencyHeader = 'Idempotency-Key';
|
|
220
|
+
|
|
221
|
+
this.apiKey = apiKey;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
contacts: API.Contacts = new API.Contacts(this);
|
|
225
|
+
templates: API.Templates = new API.Templates(this);
|
|
226
|
+
bankAccounts: API.BankAccounts = new API.BankAccounts(this);
|
|
227
|
+
cheques: API.Cheques = new API.Cheques(this);
|
|
228
|
+
letters: API.Letters = new API.Letters(this);
|
|
229
|
+
postcards: API.Postcards = new API.Postcards(this);
|
|
230
|
+
boxes: API.Boxes = new API.Boxes(this);
|
|
231
|
+
campaigns: API.Campaigns = new API.Campaigns(this);
|
|
232
|
+
reports: API.Reports = new API.Reports(this);
|
|
233
|
+
selfMailers: API.SelfMailers = new API.SelfMailers(this);
|
|
234
|
+
|
|
235
|
+
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
236
|
+
return this._options.defaultQuery;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
240
|
+
return {
|
|
241
|
+
...super.defaultHeaders(opts),
|
|
242
|
+
...this._options.defaultHeaders,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
247
|
+
return { 'X-API-Key': this.apiKey };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
static PostGrid = this;
|
|
251
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
252
|
+
|
|
253
|
+
static PostGridError = Errors.PostGridError;
|
|
254
|
+
static APIError = Errors.APIError;
|
|
255
|
+
static APIConnectionError = Errors.APIConnectionError;
|
|
256
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
257
|
+
static APIUserAbortError = Errors.APIUserAbortError;
|
|
258
|
+
static NotFoundError = Errors.NotFoundError;
|
|
259
|
+
static ConflictError = Errors.ConflictError;
|
|
260
|
+
static RateLimitError = Errors.RateLimitError;
|
|
261
|
+
static BadRequestError = Errors.BadRequestError;
|
|
262
|
+
static AuthenticationError = Errors.AuthenticationError;
|
|
263
|
+
static InternalServerError = Errors.InternalServerError;
|
|
264
|
+
static PermissionDeniedError = Errors.PermissionDeniedError;
|
|
265
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
|
266
|
+
|
|
267
|
+
static toFile = Uploads.toFile;
|
|
268
|
+
static fileFromPath = Uploads.fileFromPath;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
PostGrid.Contacts = Contacts;
|
|
272
|
+
PostGrid.ContactsList = ContactsList;
|
|
273
|
+
PostGrid.Templates = Templates;
|
|
274
|
+
PostGrid.TemplatesList = TemplatesList;
|
|
275
|
+
PostGrid.BankAccounts = BankAccounts;
|
|
276
|
+
PostGrid.BankAccountsList = BankAccountsList;
|
|
277
|
+
PostGrid.Cheques = Cheques;
|
|
278
|
+
PostGrid.ChequesList = ChequesList;
|
|
279
|
+
PostGrid.Letters = Letters;
|
|
280
|
+
PostGrid.LettersList = LettersList;
|
|
281
|
+
PostGrid.Postcards = Postcards;
|
|
282
|
+
PostGrid.PostcardsList = PostcardsList;
|
|
283
|
+
PostGrid.Boxes = Boxes;
|
|
284
|
+
PostGrid.BoxListResponsesList = BoxListResponsesList;
|
|
285
|
+
PostGrid.Campaigns = Campaigns;
|
|
286
|
+
PostGrid.CampaignListResponsesList = CampaignListResponsesList;
|
|
287
|
+
PostGrid.Reports = Reports;
|
|
288
|
+
PostGrid.ReportListResponsesList = ReportListResponsesList;
|
|
289
|
+
PostGrid.SelfMailers = SelfMailers;
|
|
290
|
+
PostGrid.SelfMailerListResponsesList = SelfMailerListResponsesList;
|
|
291
|
+
export declare namespace PostGrid {
|
|
292
|
+
export type RequestOptions = Core.RequestOptions;
|
|
293
|
+
|
|
294
|
+
export import List = Pagination.List;
|
|
295
|
+
export { type ListParams as ListParams, type ListResponse as ListResponse };
|
|
296
|
+
|
|
297
|
+
export {
|
|
298
|
+
Contacts as Contacts,
|
|
299
|
+
type Contact as Contact,
|
|
300
|
+
type ContactDeleteResponse as ContactDeleteResponse,
|
|
301
|
+
ContactsList as ContactsList,
|
|
302
|
+
type ContactCreateParams as ContactCreateParams,
|
|
303
|
+
type ContactListParams as ContactListParams,
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export {
|
|
307
|
+
Templates as Templates,
|
|
308
|
+
type Template as Template,
|
|
309
|
+
type TemplateList as TemplateList,
|
|
310
|
+
type TemplateDeleteResponse as TemplateDeleteResponse,
|
|
311
|
+
TemplatesList as TemplatesList,
|
|
312
|
+
type TemplateCreateParams as TemplateCreateParams,
|
|
313
|
+
type TemplateUpdateParams as TemplateUpdateParams,
|
|
314
|
+
type TemplateListParams as TemplateListParams,
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export {
|
|
318
|
+
BankAccounts as BankAccounts,
|
|
319
|
+
type BankAccount as BankAccount,
|
|
320
|
+
type BankAccountList as BankAccountList,
|
|
321
|
+
type BankAccountDeleteResponse as BankAccountDeleteResponse,
|
|
322
|
+
BankAccountsList as BankAccountsList,
|
|
323
|
+
type BankAccountCreateParams as BankAccountCreateParams,
|
|
324
|
+
type BankAccountListParams as BankAccountListParams,
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
export {
|
|
328
|
+
Cheques as Cheques,
|
|
329
|
+
type Cheque as Cheque,
|
|
330
|
+
type ChequeList as ChequeList,
|
|
331
|
+
ChequesList as ChequesList,
|
|
332
|
+
type ChequeCreateParams as ChequeCreateParams,
|
|
333
|
+
type ChequeListParams as ChequeListParams,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
export {
|
|
337
|
+
Letters as Letters,
|
|
338
|
+
type Letter as Letter,
|
|
339
|
+
type LetterList as LetterList,
|
|
340
|
+
type LetterURLResponse as LetterURLResponse,
|
|
341
|
+
LettersList as LettersList,
|
|
342
|
+
type LetterCreateParams as LetterCreateParams,
|
|
343
|
+
type LetterListParams as LetterListParams,
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
export {
|
|
347
|
+
Postcards as Postcards,
|
|
348
|
+
type Postcard as Postcard,
|
|
349
|
+
type PostcardList as PostcardList,
|
|
350
|
+
type PostcardURLResponse as PostcardURLResponse,
|
|
351
|
+
PostcardsList as PostcardsList,
|
|
352
|
+
type PostcardCreateParams as PostcardCreateParams,
|
|
353
|
+
type PostcardListParams as PostcardListParams,
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export {
|
|
357
|
+
Boxes as Boxes,
|
|
358
|
+
type BoxCreateResponse as BoxCreateResponse,
|
|
359
|
+
type BoxRetrieveResponse as BoxRetrieveResponse,
|
|
360
|
+
type BoxListResponse as BoxListResponse,
|
|
361
|
+
type BoxCancelResponse as BoxCancelResponse,
|
|
362
|
+
BoxListResponsesList as BoxListResponsesList,
|
|
363
|
+
type BoxCreateParams as BoxCreateParams,
|
|
364
|
+
type BoxListParams as BoxListParams,
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
export {
|
|
368
|
+
Campaigns as Campaigns,
|
|
369
|
+
type CampaignCreateResponse as CampaignCreateResponse,
|
|
370
|
+
type CampaignRetrieveResponse as CampaignRetrieveResponse,
|
|
371
|
+
type CampaignUpdateResponse as CampaignUpdateResponse,
|
|
372
|
+
type CampaignListResponse as CampaignListResponse,
|
|
373
|
+
type CampaignDeleteResponse as CampaignDeleteResponse,
|
|
374
|
+
type CampaignSendResponse as CampaignSendResponse,
|
|
375
|
+
CampaignListResponsesList as CampaignListResponsesList,
|
|
376
|
+
type CampaignCreateParams as CampaignCreateParams,
|
|
377
|
+
type CampaignUpdateParams as CampaignUpdateParams,
|
|
378
|
+
type CampaignListParams as CampaignListParams,
|
|
379
|
+
type CampaignSendParams as CampaignSendParams,
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export {
|
|
383
|
+
Reports as Reports,
|
|
384
|
+
type ReportCreateResponse as ReportCreateResponse,
|
|
385
|
+
type ReportRetrieveResponse as ReportRetrieveResponse,
|
|
386
|
+
type ReportUpdateResponse as ReportUpdateResponse,
|
|
387
|
+
type ReportListResponse as ReportListResponse,
|
|
388
|
+
type ReportDeleteResponse as ReportDeleteResponse,
|
|
389
|
+
ReportListResponsesList as ReportListResponsesList,
|
|
390
|
+
type ReportCreateParams as ReportCreateParams,
|
|
391
|
+
type ReportUpdateParams as ReportUpdateParams,
|
|
392
|
+
type ReportListParams as ReportListParams,
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
export {
|
|
396
|
+
SelfMailers as SelfMailers,
|
|
397
|
+
type SelfMailerCreateResponse as SelfMailerCreateResponse,
|
|
398
|
+
type SelfMailerRetrieveResponse as SelfMailerRetrieveResponse,
|
|
399
|
+
type SelfMailerListResponse as SelfMailerListResponse,
|
|
400
|
+
type SelfMailerCancelResponse as SelfMailerCancelResponse,
|
|
401
|
+
SelfMailerListResponsesList as SelfMailerListResponsesList,
|
|
402
|
+
type SelfMailerCreateParams as SelfMailerCreateParams,
|
|
403
|
+
type SelfMailerListParams as SelfMailerListParams,
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
export type Cancellation = API.Cancellation;
|
|
407
|
+
export type ContactCreateWithCompanyName = API.ContactCreateWithCompanyName;
|
|
408
|
+
export type ContactCreateWithFirstName = API.ContactCreateWithFirstName;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export { toFile, fileFromPath } from './uploads';
|
|
412
|
+
export {
|
|
413
|
+
PostGridError,
|
|
414
|
+
APIError,
|
|
415
|
+
APIConnectionError,
|
|
416
|
+
APIConnectionTimeoutError,
|
|
417
|
+
APIUserAbortError,
|
|
418
|
+
NotFoundError,
|
|
419
|
+
ConflictError,
|
|
420
|
+
RateLimitError,
|
|
421
|
+
BadRequestError,
|
|
422
|
+
AuthenticationError,
|
|
423
|
+
InternalServerError,
|
|
424
|
+
PermissionDeniedError,
|
|
425
|
+
UnprocessableEntityError,
|
|
426
|
+
} from './error';
|
|
427
|
+
|
|
428
|
+
export default PostGrid;
|
package/src/lib/.keep
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core';
|
|
4
|
+
|
|
5
|
+
export interface ListResponse<Item> {
|
|
6
|
+
data: Array<Item>;
|
|
7
|
+
|
|
8
|
+
totalCount: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ListParams {
|
|
12
|
+
/**
|
|
13
|
+
* The number of elements to skip.
|
|
14
|
+
*/
|
|
15
|
+
skip?: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The maximum number of elements to fetch.
|
|
19
|
+
*/
|
|
20
|
+
limit?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class List<Item> extends AbstractPage<Item> implements ListResponse<Item> {
|
|
24
|
+
data: Array<Item>;
|
|
25
|
+
|
|
26
|
+
totalCount: number;
|
|
27
|
+
|
|
28
|
+
constructor(client: APIClient, response: Response, body: ListResponse<Item>, options: FinalRequestOptions) {
|
|
29
|
+
super(client, response, body, options);
|
|
30
|
+
|
|
31
|
+
this.data = body.data || [];
|
|
32
|
+
this.totalCount = body.totalCount || 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getPaginatedItems(): Item[] {
|
|
36
|
+
return this.data ?? [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// @deprecated Please use `nextPageInfo()` instead
|
|
40
|
+
nextPageParams(): Partial<ListParams> | null {
|
|
41
|
+
const info = this.nextPageInfo();
|
|
42
|
+
if (!info) return null;
|
|
43
|
+
if ('params' in info) return info.params;
|
|
44
|
+
const params = Object.fromEntries(info.url.searchParams);
|
|
45
|
+
if (!Object.keys(params).length) return null;
|
|
46
|
+
return params;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
nextPageInfo(): PageInfo | null {
|
|
50
|
+
const offset = (this.options.query as ListParams).skip ?? 0;
|
|
51
|
+
if (!offset) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const length = this.getPaginatedItems().length;
|
|
56
|
+
const currentCount = offset + length;
|
|
57
|
+
|
|
58
|
+
const totalCount = this.totalCount;
|
|
59
|
+
if (!totalCount) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (currentCount < totalCount) {
|
|
64
|
+
return { params: { skip: currentCount } };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/resource.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import type { PostGrid } from './index';
|
|
4
|
+
|
|
5
|
+
export class APIResource {
|
|
6
|
+
protected _client: PostGrid;
|
|
7
|
+
|
|
8
|
+
constructor(client: PostGrid) {
|
|
9
|
+
this._client = client;
|
|
10
|
+
}
|
|
11
|
+
}
|