@tagadapay/headless-sdk 1.8.0-rc.0 → 1.9.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/README.md +216 -1
- package/dist/core/client.d.ts +68 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +73 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/errors.d.ts +53 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +58 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/helpers/autocomplete.d.ts +89 -0
- package/dist/core/helpers/autocomplete.d.ts.map +1 -0
- package/dist/core/helpers/autocomplete.js +186 -0
- package/dist/core/helpers/autocomplete.js.map +1 -0
- package/dist/core/helpers/countries.d.ts +45 -0
- package/dist/core/helpers/countries.d.ts.map +1 -0
- package/dist/core/helpers/countries.js +65 -0
- package/dist/core/helpers/countries.js.map +1 -0
- package/dist/core/helpers/currency.d.ts +26 -0
- package/dist/core/helpers/currency.d.ts.map +1 -0
- package/dist/core/helpers/currency.js +72 -0
- package/dist/core/helpers/currency.js.map +1 -0
- package/dist/core/helpers/index.d.ts +6 -0
- package/dist/core/helpers/index.d.ts.map +1 -0
- package/dist/core/helpers/index.js +6 -0
- package/dist/core/helpers/index.js.map +1 -0
- package/dist/core/helpers/iso3166.d.ts +28 -0
- package/dist/core/helpers/iso3166.d.ts.map +1 -0
- package/dist/core/helpers/iso3166.js +84 -0
- package/dist/core/helpers/iso3166.js.map +1 -0
- package/dist/core/helpers/walletContact.d.ts +67 -0
- package/dist/core/helpers/walletContact.d.ts.map +1 -0
- package/dist/core/helpers/walletContact.js +71 -0
- package/dist/core/helpers/walletContact.js.map +1 -0
- package/dist/core/http.d.ts +27 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +125 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/modules/catalog.d.ts +27 -0
- package/dist/core/modules/catalog.d.ts.map +1 -0
- package/dist/core/modules/catalog.js +38 -0
- package/dist/core/modules/catalog.js.map +1 -0
- package/dist/core/modules/checkout.d.ts +268 -0
- package/dist/core/modules/checkout.d.ts.map +1 -0
- package/dist/core/modules/checkout.js +470 -0
- package/dist/core/modules/checkout.js.map +1 -0
- package/dist/core/modules/customer.d.ts +33 -0
- package/dist/core/modules/customer.d.ts.map +1 -0
- package/dist/core/modules/customer.js +53 -0
- package/dist/core/modules/customer.js.map +1 -0
- package/dist/core/modules/funnel.d.ts +38 -0
- package/dist/core/modules/funnel.d.ts.map +1 -0
- package/dist/core/modules/funnel.js +143 -0
- package/dist/core/modules/funnel.js.map +1 -0
- package/dist/core/modules/offers.d.ts +137 -0
- package/dist/core/modules/offers.d.ts.map +1 -0
- package/dist/core/modules/offers.js +141 -0
- package/dist/core/modules/offers.js.map +1 -0
- package/dist/core/modules/payment.d.ts +353 -0
- package/dist/core/modules/payment.d.ts.map +1 -0
- package/dist/core/modules/payment.js +784 -0
- package/dist/core/modules/payment.js.map +1 -0
- package/dist/core/modules/rx.d.ts +162 -0
- package/dist/core/modules/rx.d.ts.map +1 -0
- package/dist/core/modules/rx.js +46 -0
- package/dist/core/modules/rx.js.map +1 -0
- package/dist/core/types.d.ts +532 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/react/hooks/useCatalog.d.ts +25 -0
- package/dist/react/hooks/useCatalog.d.ts.map +1 -0
- package/dist/react/hooks/useCatalog.js +58 -0
- package/dist/react/hooks/useCatalog.js.map +1 -0
- package/dist/react/hooks/useCheckout.d.ts +58 -0
- package/dist/react/hooks/useCheckout.d.ts.map +1 -0
- package/dist/react/hooks/useCheckout.js +177 -0
- package/dist/react/hooks/useCheckout.js.map +1 -0
- package/dist/react/hooks/useCustomer.d.ts +28 -0
- package/dist/react/hooks/useCustomer.d.ts.map +1 -0
- package/dist/react/hooks/useCustomer.js +77 -0
- package/dist/react/hooks/useCustomer.js.map +1 -0
- package/dist/react/hooks/useGoogleAutocomplete.d.ts +26 -0
- package/dist/react/hooks/useGoogleAutocomplete.d.ts.map +1 -0
- package/dist/react/hooks/useGoogleAutocomplete.js +70 -0
- package/dist/react/hooks/useGoogleAutocomplete.js.map +1 -0
- package/dist/react/hooks/useISOData.d.ts +23 -0
- package/dist/react/hooks/useISOData.d.ts.map +1 -0
- package/dist/react/hooks/useISOData.js +63 -0
- package/dist/react/hooks/useISOData.js.map +1 -0
- package/dist/react/hooks/useOffers.d.ts +134 -0
- package/dist/react/hooks/useOffers.d.ts.map +1 -0
- package/dist/react/hooks/useOffers.js +171 -0
- package/dist/react/hooks/useOffers.js.map +1 -0
- package/dist/react/hooks/usePayment.d.ts +117 -0
- package/dist/react/hooks/usePayment.d.ts.map +1 -0
- package/dist/react/hooks/usePayment.js +233 -0
- package/dist/react/hooks/usePayment.js.map +1 -0
- package/dist/react/hooks/useRx.d.ts +64 -0
- package/dist/react/hooks/useRx.d.ts.map +1 -0
- package/dist/react/hooks/useRx.js +145 -0
- package/dist/react/hooks/useRx.js.map +1 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +12 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/internal/redirectGuard.d.ts +9 -0
- package/dist/react/internal/redirectGuard.d.ts.map +1 -0
- package/dist/react/internal/redirectGuard.js +25 -0
- package/dist/react/internal/redirectGuard.js.map +1 -0
- package/dist/react/provider.d.ts +31 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/provider.js +32 -0
- package/dist/react/provider.js.map +1 -0
- package/dist/stripe/StripeExpressButton.d.ts +30 -0
- package/dist/stripe/StripeExpressButton.d.ts.map +1 -0
- package/dist/stripe/StripeExpressButton.js +32 -0
- package/dist/stripe/StripeExpressButton.js.map +1 -0
- package/dist/stripe/StripeExpressCheckout.d.ts +109 -0
- package/dist/stripe/StripeExpressCheckout.d.ts.map +1 -0
- package/dist/stripe/StripeExpressCheckout.js +242 -0
- package/dist/stripe/StripeExpressCheckout.js.map +1 -0
- package/dist/stripe/index.d.ts +8 -0
- package/dist/stripe/index.d.ts.map +1 -0
- package/dist/stripe/index.js +15 -0
- package/dist/stripe/index.js.map +1 -0
- package/dist/stripe/useStripeExpress.d.ts +54 -0
- package/dist/stripe/useStripeExpress.d.ts.map +1 -0
- package/dist/stripe/useStripeExpress.js +125 -0
- package/dist/stripe/useStripeExpress.js.map +1 -0
- package/dist/tagada-headless-react.min.js +8 -0
- package/dist/tagada-headless-react.min.js.map +7 -0
- package/dist/tagada-headless.js +2423 -0
- package/dist/tagada-headless.min.js +8 -0
- package/dist/tagada-headless.min.js.map +7 -0
- package/package.json +79 -73
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Address } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A contact as Apple Pay hands it to `onpaymentauthorized`
|
|
4
|
+
* (`event.payment.billingContact` / `event.payment.shippingContact`).
|
|
5
|
+
*
|
|
6
|
+
* Apple only fills the fields the payment request asked for, so an integration
|
|
7
|
+
* that omits `requiredBillingContactFields` / `requiredShippingContactFields`
|
|
8
|
+
* receives nothing here — see `applePayContactToAddress`.
|
|
9
|
+
*/
|
|
10
|
+
export interface ApplePayContact {
|
|
11
|
+
givenName?: string;
|
|
12
|
+
familyName?: string;
|
|
13
|
+
addressLines?: string[];
|
|
14
|
+
locality?: string;
|
|
15
|
+
administrativeArea?: string;
|
|
16
|
+
postalCode?: string;
|
|
17
|
+
countryCode?: string;
|
|
18
|
+
emailAddress?: string;
|
|
19
|
+
phoneNumber?: string;
|
|
20
|
+
}
|
|
21
|
+
/** A Google Pay address (`paymentData.shippingAddress`, or `billingAddress`). */
|
|
22
|
+
export interface GooglePayContact {
|
|
23
|
+
name?: string;
|
|
24
|
+
address1?: string;
|
|
25
|
+
address2?: string;
|
|
26
|
+
address3?: string;
|
|
27
|
+
locality?: string;
|
|
28
|
+
administrativeArea?: string;
|
|
29
|
+
postalCode?: string;
|
|
30
|
+
countryCode?: string;
|
|
31
|
+
phoneNumber?: string;
|
|
32
|
+
emailAddress?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A contact as Stripe's Express Checkout Element reports it on `confirm`
|
|
36
|
+
* (`event.billingDetails`, `event.shippingAddress`).
|
|
37
|
+
*/
|
|
38
|
+
export interface StripeContact {
|
|
39
|
+
name?: string;
|
|
40
|
+
email?: string;
|
|
41
|
+
phone?: string;
|
|
42
|
+
address?: {
|
|
43
|
+
line1?: string;
|
|
44
|
+
line2?: string;
|
|
45
|
+
city?: string;
|
|
46
|
+
state?: string;
|
|
47
|
+
postal_code?: string;
|
|
48
|
+
country?: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Map an Apple Pay contact onto an SDK `Address`.
|
|
53
|
+
*
|
|
54
|
+
* Returns `undefined` when the contact has no usable postal address, so a
|
|
55
|
+
* caller can never overwrite a real address with an empty shell — Apple sends
|
|
56
|
+
* a name-and-email-only contact whenever the payment request did not ask for
|
|
57
|
+
* `postalAddress` (#TAG-1989).
|
|
58
|
+
*/
|
|
59
|
+
export declare function applePayContactToAddress(contact?: ApplePayContact | null): Address | undefined;
|
|
60
|
+
/** Map a Google Pay address onto an SDK `Address`. Same contract as above. */
|
|
61
|
+
export declare function googlePayContactToAddress(contact?: GooglePayContact | null): Address | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Map a Stripe Express Checkout contact onto an SDK `Address`. Same contract as
|
|
64
|
+
* the wallet mappers above: no street line or no country means `undefined`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function stripeContactToAddress(contact?: StripeContact | null): Address | undefined;
|
|
67
|
+
//# sourceMappingURL=walletContact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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AE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,OAAO,GAAG,SAAS,CAgB9F;AAED,8EAA8E;AAC9E,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,GAAG,OAAO,GAAG,SAAS,CAkBhG;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,GAAG,SAAS,CAkB1F"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map an Apple Pay contact onto an SDK `Address`.
|
|
3
|
+
*
|
|
4
|
+
* Returns `undefined` when the contact has no usable postal address, so a
|
|
5
|
+
* caller can never overwrite a real address with an empty shell — Apple sends
|
|
6
|
+
* a name-and-email-only contact whenever the payment request did not ask for
|
|
7
|
+
* `postalAddress` (#TAG-1989).
|
|
8
|
+
*/
|
|
9
|
+
export function applePayContactToAddress(contact) {
|
|
10
|
+
if (!contact)
|
|
11
|
+
return undefined;
|
|
12
|
+
const address = {
|
|
13
|
+
firstName: contact.givenName,
|
|
14
|
+
lastName: contact.familyName,
|
|
15
|
+
line1: contact.addressLines?.[0],
|
|
16
|
+
line2: contact.addressLines?.[1],
|
|
17
|
+
city: contact.locality,
|
|
18
|
+
state: contact.administrativeArea,
|
|
19
|
+
postalCode: contact.postalCode,
|
|
20
|
+
country: contact.countryCode,
|
|
21
|
+
phone: contact.phoneNumber,
|
|
22
|
+
};
|
|
23
|
+
return isUsable(address) ? address : undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Map a Google Pay address onto an SDK `Address`. Same contract as above. */
|
|
26
|
+
export function googlePayContactToAddress(contact) {
|
|
27
|
+
if (!contact)
|
|
28
|
+
return undefined;
|
|
29
|
+
const [firstName, ...rest] = (contact.name ?? '').trim().split(/\s+/);
|
|
30
|
+
const address = {
|
|
31
|
+
firstName: firstName || undefined,
|
|
32
|
+
lastName: rest.length ? rest.join(' ') : undefined,
|
|
33
|
+
line1: contact.address1,
|
|
34
|
+
line2: [contact.address2, contact.address3].filter(Boolean).join(' ') || undefined,
|
|
35
|
+
city: contact.locality,
|
|
36
|
+
state: contact.administrativeArea,
|
|
37
|
+
postalCode: contact.postalCode,
|
|
38
|
+
country: contact.countryCode,
|
|
39
|
+
phone: contact.phoneNumber,
|
|
40
|
+
};
|
|
41
|
+
return isUsable(address) ? address : undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Map a Stripe Express Checkout contact onto an SDK `Address`. Same contract as
|
|
45
|
+
* the wallet mappers above: no street line or no country means `undefined`.
|
|
46
|
+
*/
|
|
47
|
+
export function stripeContactToAddress(contact) {
|
|
48
|
+
if (!contact?.address)
|
|
49
|
+
return undefined;
|
|
50
|
+
const [firstName, ...rest] = (contact.name ?? '').trim().split(/\s+/);
|
|
51
|
+
const address = {
|
|
52
|
+
firstName: firstName || undefined,
|
|
53
|
+
lastName: rest.length ? rest.join(' ') : undefined,
|
|
54
|
+
line1: contact.address.line1,
|
|
55
|
+
line2: contact.address.line2,
|
|
56
|
+
city: contact.address.city,
|
|
57
|
+
state: contact.address.state,
|
|
58
|
+
postalCode: contact.address.postal_code,
|
|
59
|
+
country: contact.address.country,
|
|
60
|
+
phone: contact.phone,
|
|
61
|
+
};
|
|
62
|
+
return isUsable(address) ? address : undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A street line and a country are the minimum a parcel — and every carrier
|
|
66
|
+
* integration — needs. Anything less is a contact, not an address.
|
|
67
|
+
*/
|
|
68
|
+
function isUsable(address) {
|
|
69
|
+
return Boolean(address.line1?.trim() && address.country?.trim());
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=walletContact.js.map
|
|
@@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CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAS,QAAQ,CAAC,OAAgB;IAChC,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Environment, HttpRequestOptions } from './types.js';
|
|
2
|
+
export interface HttpClientConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
timeout: number;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
getToken?: () => string | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Lightweight HTTP client built on native fetch.
|
|
10
|
+
* Zero dependencies -- works in browser, edge runtimes, and Node 18+.
|
|
11
|
+
*/
|
|
12
|
+
export declare class HttpClient {
|
|
13
|
+
readonly baseUrl: string;
|
|
14
|
+
private timeout;
|
|
15
|
+
private apiKey?;
|
|
16
|
+
private getToken?;
|
|
17
|
+
constructor(config: HttpClientConfig);
|
|
18
|
+
static resolveBaseUrl(environment: Environment, override?: string): string;
|
|
19
|
+
request<T = unknown>(path: string, options?: HttpRequestOptions): Promise<T>;
|
|
20
|
+
get<T = unknown>(path: string, options?: HttpRequestOptions): Promise<T>;
|
|
21
|
+
post<T = unknown>(path: string, body?: unknown, options?: HttpRequestOptions): Promise<T>;
|
|
22
|
+
patch<T = unknown>(path: string, body?: unknown, options?: HttpRequestOptions): Promise<T>;
|
|
23
|
+
put<T = unknown>(path: string, body?: unknown, options?: HttpRequestOptions): Promise<T>;
|
|
24
|
+
delete<T = unknown>(path: string, options?: HttpRequestOptions): Promise<T>;
|
|
25
|
+
private handleErrorResponse;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sour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,OAAO,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAIxF,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;YAI7D,mBAAmB;CA4ClC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { TagadaError, TagadaAuthError, TagadaValidationError, TagadaNotFoundError, TagadaRateLimitError, TagadaNetworkError, } from './errors.js';
|
|
2
|
+
const BASE_URLS = {
|
|
3
|
+
production: 'https://api.tagada.io',
|
|
4
|
+
development: 'https://api.tagada.dev',
|
|
5
|
+
local: 'http://localhost:3000',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Lightweight HTTP client built on native fetch.
|
|
9
|
+
* Zero dependencies -- works in browser, edge runtimes, and Node 18+.
|
|
10
|
+
*/
|
|
11
|
+
export class HttpClient {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
14
|
+
this.timeout = config.timeout;
|
|
15
|
+
this.apiKey = config.apiKey;
|
|
16
|
+
this.getToken = config.getToken;
|
|
17
|
+
}
|
|
18
|
+
static resolveBaseUrl(environment, override) {
|
|
19
|
+
return override ?? BASE_URLS[environment] ?? BASE_URLS.production;
|
|
20
|
+
}
|
|
21
|
+
async request(path, options = {}) {
|
|
22
|
+
const { method = 'GET', body, headers = {}, params, token, signal } = options;
|
|
23
|
+
let url = `${this.baseUrl}${path}`;
|
|
24
|
+
if (params) {
|
|
25
|
+
const qs = new URLSearchParams();
|
|
26
|
+
for (const [k, v] of Object.entries(params)) {
|
|
27
|
+
if (v !== undefined)
|
|
28
|
+
qs.set(k, String(v));
|
|
29
|
+
}
|
|
30
|
+
const str = qs.toString();
|
|
31
|
+
if (str)
|
|
32
|
+
url += `?${str}`;
|
|
33
|
+
}
|
|
34
|
+
const reqHeaders = {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
...headers,
|
|
37
|
+
};
|
|
38
|
+
const authToken = token ?? this.apiKey ?? this.getToken?.();
|
|
39
|
+
if (authToken) {
|
|
40
|
+
reqHeaders['x-cms-token'] = authToken;
|
|
41
|
+
}
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch(url, {
|
|
46
|
+
method,
|
|
47
|
+
headers: reqHeaders,
|
|
48
|
+
body: body != null ? JSON.stringify(body) : undefined,
|
|
49
|
+
signal: signal ?? controller.signal,
|
|
50
|
+
});
|
|
51
|
+
clearTimeout(timeoutId);
|
|
52
|
+
if (res.ok) {
|
|
53
|
+
const text = await res.text();
|
|
54
|
+
return text ? JSON.parse(text) : {};
|
|
55
|
+
}
|
|
56
|
+
await this.handleErrorResponse(res, path);
|
|
57
|
+
throw new TagadaError('Unexpected error', 'unknown', res.status);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
if (err instanceof TagadaError)
|
|
62
|
+
throw err;
|
|
63
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
64
|
+
throw new TagadaNetworkError(`Request to ${path} timed out after ${this.timeout}ms.`);
|
|
65
|
+
}
|
|
66
|
+
throw new TagadaNetworkError(err instanceof Error ? err.message : 'Network request failed.');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
get(path, options) {
|
|
70
|
+
return this.request(path, { ...options, method: 'GET' });
|
|
71
|
+
}
|
|
72
|
+
post(path, body, options) {
|
|
73
|
+
return this.request(path, { ...options, method: 'POST', body });
|
|
74
|
+
}
|
|
75
|
+
patch(path, body, options) {
|
|
76
|
+
return this.request(path, { ...options, method: 'PATCH', body });
|
|
77
|
+
}
|
|
78
|
+
put(path, body, options) {
|
|
79
|
+
return this.request(path, { ...options, method: 'PUT', body });
|
|
80
|
+
}
|
|
81
|
+
delete(path, options) {
|
|
82
|
+
return this.request(path, { ...options, method: 'DELETE' });
|
|
83
|
+
}
|
|
84
|
+
async handleErrorResponse(res, path) {
|
|
85
|
+
let parsed = {};
|
|
86
|
+
try {
|
|
87
|
+
parsed = (await res.json());
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// response isn't JSON
|
|
91
|
+
}
|
|
92
|
+
// Server actions answer `{ code, data }`, where `data` carries the
|
|
93
|
+
// customer-facing message and an application error code — `Error.message`
|
|
94
|
+
// is non-enumerable, so it cannot travel at the top level (#TAG-1989).
|
|
95
|
+
// Without this the buyer sees "Request failed: 422 …" instead of the
|
|
96
|
+
// reason, and the code the storefront should branch on is thrown away.
|
|
97
|
+
const data = (parsed.data ?? {});
|
|
98
|
+
const msg = parsed.message ??
|
|
99
|
+
parsed.error ??
|
|
100
|
+
(typeof data.message === 'string' ? data.message : undefined) ??
|
|
101
|
+
(typeof parsed.data === 'string' ? parsed.data : undefined) ??
|
|
102
|
+
`Request failed: ${res.status} ${res.statusText} on ${path}`;
|
|
103
|
+
const appCode = typeof data.code === 'string' ? data.code : undefined;
|
|
104
|
+
switch (res.status) {
|
|
105
|
+
case 401:
|
|
106
|
+
case 403:
|
|
107
|
+
throw new TagadaAuthError(msg);
|
|
108
|
+
case 404:
|
|
109
|
+
throw new TagadaNotFoundError(path, '');
|
|
110
|
+
case 422: {
|
|
111
|
+
const fieldErrors = Array.isArray(parsed.errors)
|
|
112
|
+
? parsed.errors
|
|
113
|
+
: [];
|
|
114
|
+
throw new TagadaValidationError(msg, fieldErrors, appCode, parsed);
|
|
115
|
+
}
|
|
116
|
+
case 429: {
|
|
117
|
+
const retryAfter = Number(res.headers.get('Retry-After') ?? '1') * 1000;
|
|
118
|
+
throw new TagadaRateLimitError(retryAfter);
|
|
119
|
+
}
|
|
120
|
+
default:
|
|
121
|
+
throw new TagadaError(msg, 'api_error', res.status, parsed);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124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nB,KAAK,GAAG,CAAC;YACT,KAAK,GAAG;gBACN,MAAM,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;YACjC,KAAK,GAAG;gBACN,MAAM,IAAI,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1C,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;oBAC9C,CAAC,CAAE,MAAM,CAAC,MAAoD;oBAC9D,CAAC,CAAC,EAAE,CAAC;gBACP,MAAM,IAAI,qBAAqB,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;YACrE,CAAC;YACD,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC;gBACxE,MAAM,IAAI,oBAAoB,CAAC,UAAU,CAAC,CAAC;YAC7C,CAAC;YACD;gBACE,MAAM,IAAI,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { HeadlessClient, createHeadlessClient } from './client.js';
|
|
2
|
+
export { CheckoutModule } from './modules/checkout.js';
|
|
3
|
+
export { PaymentModule } from './modules/payment.js';
|
|
4
|
+
export { OffersModule } from './modules/offers.js';
|
|
5
|
+
export { CustomerModule } from './modules/customer.js';
|
|
6
|
+
export { CatalogModule } from './modules/catalog.js';
|
|
7
|
+
export { FunnelModule } from './modules/funnel.js';
|
|
8
|
+
export { RxModule } from './modules/rx.js';
|
|
9
|
+
export type { RxCaseStatus, RxRequiredForProduct, RxStorefrontPatient, RxIntakeAnswer, RxClinicalQuestion, RxQuestionsForProduct, RxSubmitCaseInput, RxSubmitCaseResult, RxCaseSummary, } from './modules/rx.js';
|
|
10
|
+
export { HttpClient } from './http.js';
|
|
11
|
+
export { TagadaError, TagadaAuthError, TagadaValidationError, TagadaNotFoundError, TagadaRateLimitError, TagadaPaymentError, TagadaNetworkError, } from './errors.js';
|
|
12
|
+
export { GoogleAutocompleteCore, loadGoogleMapsScript, ISODataCore, AVAILABLE_LANGUAGES, CurrencyUtils, formatMoney, ensureGeoDataLoaded, getCountries, getStatesForCountry, isLanguageLoaded, } from './helpers/index.js';
|
|
13
|
+
export type { GooglePrediction, GooglePlaceDetails, ExtractedAddress, FormattedAddress, SupportedLanguage, ISOCountry, ISORegion, Country, State, Currency, } from './helpers/index.js';
|
|
14
|
+
export type { Environment, HeadlessConfig, HttpRequestOptions, LineItem, CheckoutSession, CheckoutLineItem, CheckoutTotals, CheckoutCustomer, Address, ShippingRate, PaymentMethodConfig, PaymentSetupConfig, ExpressMethod, ExpressMethods, StoreConfig, PayResult, PayOptions, PayDirectOptions, ProcessPaymentOptions, ProcessPaymentResult, CreateInstrumentOptions, PaymentInstrument, ThreedsSession, PaymentStatus, Offer, OfferLineItem, OfferPreview, OfferPreviewItem, OfferPayResult, Customer, Order, OrderItem, Subscription, CatalogProduct, CatalogVariant, CatalogPrice, CurrencyOption, FunnelNavigateInput, FunnelNavigateResult, } from './types.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;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ACT,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { HeadlessClient, createHeadlessClient } from './client.js';
|
|
2
|
+
export { CheckoutModule } from './modules/checkout.js';
|
|
3
|
+
export { PaymentModule } from './modules/payment.js';
|
|
4
|
+
export { OffersModule } from './modules/offers.js';
|
|
5
|
+
export { CustomerModule } from './modules/customer.js';
|
|
6
|
+
export { CatalogModule } from './modules/catalog.js';
|
|
7
|
+
export { FunnelModule } from './modules/funnel.js';
|
|
8
|
+
export { RxModule } from './modules/rx.js';
|
|
9
|
+
export { HttpClient } from './http.js';
|
|
10
|
+
export { TagadaError, TagadaAuthError, TagadaValidationError, TagadaNotFoundError, TagadaRateLimitError, TagadaPaymentError, TagadaNetworkError, } from './errors.js';
|
|
11
|
+
// Helpers: Google Autocomplete, ISO countries/regions, currency formatting
|
|
12
|
+
export { GoogleAutocompleteCore, loadGoogleMapsScript, ISODataCore, AVAILABLE_LANGUAGES, CurrencyUtils, formatMoney, ensureGeoDataLoaded, getCountries, getStatesForCountry, isLanguageLoaded, } from './helpers/index.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAa3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,2EAA2E;AAC3E,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { CatalogProduct } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Fetches the product catalog for a store.
|
|
5
|
+
*
|
|
6
|
+
* Uses the public `/api/v1/products` endpoint (no auth required).
|
|
7
|
+
*/
|
|
8
|
+
export declare class CatalogModule {
|
|
9
|
+
private readonly http;
|
|
10
|
+
private readonly storeId;
|
|
11
|
+
constructor(http: HttpClient, storeId: string);
|
|
12
|
+
/**
|
|
13
|
+
* List all active products for the store, including variants and prices.
|
|
14
|
+
*
|
|
15
|
+
* @param opts.productIds Optional filter to specific product IDs.
|
|
16
|
+
* @param opts.variantIds Optional filter to products containing these variant IDs.
|
|
17
|
+
*/
|
|
18
|
+
getProducts(opts?: {
|
|
19
|
+
productIds?: string[];
|
|
20
|
+
variantIds?: string[];
|
|
21
|
+
}): Promise<CatalogProduct[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a single product by ID.
|
|
24
|
+
*/
|
|
25
|
+
getProduct(productId: string): Promise<CatalogProduct | null>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/core/modules/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;GAIG;AACH,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM;IAGlC;;;;;OAKG;IACG,WAAW,CAAC,IAAI,CAAC,EAAE;QACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAiB7B;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;CAIpE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches the product catalog for a store.
|
|
3
|
+
*
|
|
4
|
+
* Uses the public `/api/v1/products` endpoint (no auth required).
|
|
5
|
+
*/
|
|
6
|
+
export class CatalogModule {
|
|
7
|
+
constructor(http, storeId) {
|
|
8
|
+
this.http = http;
|
|
9
|
+
this.storeId = storeId;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* List all active products for the store, including variants and prices.
|
|
13
|
+
*
|
|
14
|
+
* @param opts.productIds Optional filter to specific product IDs.
|
|
15
|
+
* @param opts.variantIds Optional filter to products containing these variant IDs.
|
|
16
|
+
*/
|
|
17
|
+
async getProducts(opts) {
|
|
18
|
+
const body = {
|
|
19
|
+
storeId: this.storeId,
|
|
20
|
+
includeVariants: true,
|
|
21
|
+
includePrices: true,
|
|
22
|
+
};
|
|
23
|
+
if (opts?.productIds?.length)
|
|
24
|
+
body.productIds = opts.productIds;
|
|
25
|
+
if (opts?.variantIds?.length)
|
|
26
|
+
body.variantIds = opts.variantIds;
|
|
27
|
+
const res = await this.http.post('/api/v1/products', body);
|
|
28
|
+
return res.items ?? [];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get a single product by ID.
|
|
32
|
+
*/
|
|
33
|
+
async getProduct(productId) {
|
|
34
|
+
const items = await this.getProducts({ productIds: [productId] });
|
|
35
|
+
return items[0] ?? null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/core/modules/catalog.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACxB,YACmB,IAAgB,EAChB,OAAe;QADf,SAAI,GAAJ,IAAI,CAAY;QAChB,YAAO,GAAP,OAAO,CAAQ;IAC/B,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CAAC,IAGjB;QACC,MAAM,IAAI,GAA4B;YACpC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI;YACrB,aAAa,EAAE,IAAI;SACpB,CAAC;QACF,IAAI,IAAI,EAAE,UAAU,EAAE,MAAM;YAAE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAChE,IAAI,IAAI,EAAE,UAAU,EAAE,MAAM;YAAE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAEhE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAC9B,kBAAkB,EAClB,IAAI,CACL,CAAC;QAEF,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,SAAiB;QAChC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAClE,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC1B,CAAC;CACF"}
|