chargefy-js 1.1.6 → 1.1.7
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/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +3 -0
- package/dist/namespaces/checkouts.d.ts +3 -0
- package/dist/namespaces/checkouts.d.ts.map +1 -1
- package/dist/namespaces/checkouts.js +11 -0
- package/package.json +1 -1
- package/src/core.ts +5 -0
- package/src/namespaces/checkouts.ts +16 -0
package/dist/core.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface ChargefyCoreOptions {
|
|
|
20
20
|
serverURL?: string;
|
|
21
21
|
/** Request timeout in milliseconds. Default: 30000. */
|
|
22
22
|
timeout?: number;
|
|
23
|
+
/** Extra headers sent with every request (e.g. X-Chargefy-Source: embed). */
|
|
24
|
+
headers?: Record<string, string>;
|
|
23
25
|
}
|
|
24
26
|
export type APIError = ResourceNotFound | ExpiredCheckoutError | HTTPValidationError | PaymentError | NotOpenCheckout | AlreadyActiveSubscriptionError | PaymentNotReady | SDKError | UnexpectedClientError | InvalidRequestError | RequestAbortedError | RequestTimeoutError | ConnectionError;
|
|
25
27
|
interface RequestOptions {
|
|
@@ -36,6 +38,7 @@ export declare class ChargefyCore {
|
|
|
36
38
|
readonly serverURL: string;
|
|
37
39
|
readonly accessToken: string | undefined;
|
|
38
40
|
readonly timeout: number;
|
|
41
|
+
readonly headers: Record<string, string>;
|
|
39
42
|
constructor(options?: ChargefyCoreOptions);
|
|
40
43
|
request<T>(options: RequestOptions): Promise<Result<T, APIError>>;
|
|
41
44
|
}
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EACL,eAAe,EACf,mBAAmB,E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IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;gBAE5B,OAAO,GAAE,mBAAwB;IAiBvC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;CAgExE"}
|
package/dist/core.js
CHANGED
|
@@ -9,6 +9,7 @@ export class ChargefyCore {
|
|
|
9
9
|
serverURL;
|
|
10
10
|
accessToken;
|
|
11
11
|
timeout;
|
|
12
|
+
headers;
|
|
12
13
|
constructor(options = {}) {
|
|
13
14
|
if (options.serverURL) {
|
|
14
15
|
this.serverURL = options.serverURL.replace(/\/$/, '');
|
|
@@ -26,6 +27,7 @@ export class ChargefyCore {
|
|
|
26
27
|
}
|
|
27
28
|
this.accessToken = options.accessToken;
|
|
28
29
|
this.timeout = options.timeout ?? 30000;
|
|
30
|
+
this.headers = options.headers ?? {};
|
|
29
31
|
}
|
|
30
32
|
async request(options) {
|
|
31
33
|
const { method, path, body, bodyIsFormData, query, auth = true } = options;
|
|
@@ -48,6 +50,7 @@ export class ChargefyCore {
|
|
|
48
50
|
if (auth && this.accessToken) {
|
|
49
51
|
headers['Authorization'] = `Bearer ${this.accessToken}`;
|
|
50
52
|
}
|
|
53
|
+
Object.assign(headers, this.headers);
|
|
51
54
|
const controller = new AbortController();
|
|
52
55
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
53
56
|
try {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChargefyCore, APIError } from '../core';
|
|
2
2
|
import type { Result } from '../types/fp';
|
|
3
3
|
import type { Checkout, CheckoutConfirmed, CreateCheckoutRequest, UpdateCheckoutRequest, ConfirmCheckoutRequest, GeneratePixRequest } from '../models/checkout';
|
|
4
|
+
import type { CheckoutUpdatePublic } from '../models/components/checkoutupdatepublic';
|
|
4
5
|
export declare class Checkouts {
|
|
5
6
|
private readonly core;
|
|
6
7
|
constructor(core: ChargefyCore);
|
|
@@ -10,6 +11,8 @@ export declare class Checkouts {
|
|
|
10
11
|
get(id: string): Promise<Result<Checkout, APIError>>;
|
|
11
12
|
/** Get a checkout by its client secret. */
|
|
12
13
|
getByClientSecret(clientSecret: string): Promise<Result<Checkout, APIError>>;
|
|
14
|
+
/** Update customer info on an open checkout by client secret (public, no auth). */
|
|
15
|
+
updateByClientSecret(clientSecret: string, data: CheckoutUpdatePublic): Promise<Result<Checkout, APIError>>;
|
|
13
16
|
/** Update customer info on an open checkout. */
|
|
14
17
|
update(body: UpdateCheckoutRequest): Promise<Result<Checkout, APIError>>;
|
|
15
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkouts.d.ts","sourceRoot":"","sources":["../../src/namespaces/checkouts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EACV,QAAQ,EACR,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"checkouts.d.ts","sourceRoot":"","sources":["../../src/namespaces/checkouts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EACV,QAAQ,EACR,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAGrF,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,YAAY;IAE/C,qCAAqC;IACrC,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAoBxE,4BAA4B;IAC5B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAOpD,2CAA2C;IAC3C,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAQ5E,mFAAmF;IACnF,oBAAoB,CAClB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,oBAAoB,GACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAUtC,gDAAgD;IAChD,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAcxE;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IAuBnF;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;CAcpF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transformToSnakeCase } from '../utils/transformers';
|
|
1
2
|
export class Checkouts {
|
|
2
3
|
core;
|
|
3
4
|
constructor(core) {
|
|
@@ -46,6 +47,16 @@ export class Checkouts {
|
|
|
46
47
|
auth: false,
|
|
47
48
|
});
|
|
48
49
|
}
|
|
50
|
+
/** Update customer info on an open checkout by client secret (public, no auth). */
|
|
51
|
+
updateByClientSecret(clientSecret, data) {
|
|
52
|
+
const payload = transformToSnakeCase(data);
|
|
53
|
+
return this.core.request({
|
|
54
|
+
method: 'PATCH',
|
|
55
|
+
path: `/v1/checkouts/client/${clientSecret}`,
|
|
56
|
+
body: payload,
|
|
57
|
+
auth: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
49
60
|
/** Update customer info on an open checkout. */
|
|
50
61
|
update(body) {
|
|
51
62
|
const { id, ...rest } = body;
|
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface ChargefyCoreOptions {
|
|
|
31
31
|
serverURL?: string
|
|
32
32
|
/** Request timeout in milliseconds. Default: 30000. */
|
|
33
33
|
timeout?: number
|
|
34
|
+
/** Extra headers sent with every request (e.g. X-Chargefy-Source: embed). */
|
|
35
|
+
headers?: Record<string, string>
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export type APIError =
|
|
@@ -63,6 +65,7 @@ export class ChargefyCore {
|
|
|
63
65
|
readonly serverURL: string
|
|
64
66
|
readonly accessToken: string | undefined
|
|
65
67
|
readonly timeout: number
|
|
68
|
+
readonly headers: Record<string, string>
|
|
66
69
|
|
|
67
70
|
constructor(options: ChargefyCoreOptions = {}) {
|
|
68
71
|
if (options.serverURL) {
|
|
@@ -78,6 +81,7 @@ export class ChargefyCore {
|
|
|
78
81
|
}
|
|
79
82
|
this.accessToken = options.accessToken
|
|
80
83
|
this.timeout = options.timeout ?? 30000
|
|
84
|
+
this.headers = options.headers ?? {}
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
async request<T>(options: RequestOptions): Promise<Result<T, APIError>> {
|
|
@@ -103,6 +107,7 @@ export class ChargefyCore {
|
|
|
103
107
|
if (auth && this.accessToken) {
|
|
104
108
|
headers['Authorization'] = `Bearer ${this.accessToken}`
|
|
105
109
|
}
|
|
110
|
+
Object.assign(headers, this.headers)
|
|
106
111
|
|
|
107
112
|
const controller = new AbortController()
|
|
108
113
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout)
|
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
ConfirmCheckoutRequest,
|
|
9
9
|
GeneratePixRequest,
|
|
10
10
|
} from '../models/checkout'
|
|
11
|
+
import type { CheckoutUpdatePublic } from '../models/components/checkoutupdatepublic'
|
|
12
|
+
import { transformToSnakeCase } from '../utils/transformers'
|
|
11
13
|
|
|
12
14
|
export class Checkouts {
|
|
13
15
|
constructor(private readonly core: ChargefyCore) {}
|
|
@@ -50,6 +52,20 @@ export class Checkouts {
|
|
|
50
52
|
})
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
/** Update customer info on an open checkout by client secret (public, no auth). */
|
|
56
|
+
updateByClientSecret(
|
|
57
|
+
clientSecret: string,
|
|
58
|
+
data: CheckoutUpdatePublic
|
|
59
|
+
): Promise<Result<Checkout, APIError>> {
|
|
60
|
+
const payload = transformToSnakeCase(data) as Record<string, unknown>
|
|
61
|
+
return this.core.request<Checkout>({
|
|
62
|
+
method: 'PATCH',
|
|
63
|
+
path: `/v1/checkouts/client/${clientSecret}`,
|
|
64
|
+
body: payload,
|
|
65
|
+
auth: false,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
/** Update customer info on an open checkout. */
|
|
54
70
|
update(body: UpdateCheckoutRequest): Promise<Result<Checkout, APIError>> {
|
|
55
71
|
const { id, ...rest } = body
|