@tagadapay/headless-sdk 1.16.0 → 1.18.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 +22 -0
- package/dist/core/client.d.ts +5 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +6 -1
- package/dist/core/client.js.map +1 -1
- package/dist/core/http.d.ts +2 -0
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/http.js +21 -5
- package/dist/core/http.js.map +1 -1
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/modules/checkout.d.ts.map +1 -1
- package/dist/core/modules/checkout.js +12 -0
- package/dist/core/modules/checkout.js.map +1 -1
- package/dist/core/modules/commerce.d.ts +4 -0
- package/dist/core/modules/commerce.d.ts.map +1 -0
- package/dist/core/modules/commerce.js +5 -0
- package/dist/core/modules/commerce.js.map +1 -0
- package/dist/core/modules/customer.d.ts +73 -5
- package/dist/core/modules/customer.d.ts.map +1 -1
- package/dist/core/modules/customer.js +110 -19
- package/dist/core/modules/customer.js.map +1 -1
- package/dist/core/modules/experiments.d.ts +21 -0
- package/dist/core/modules/experiments.d.ts.map +1 -0
- package/dist/core/modules/experiments.js +85 -0
- package/dist/core/modules/experiments.js.map +1 -0
- package/dist/core/modules/funnel.d.ts +2 -1
- package/dist/core/modules/funnel.d.ts.map +1 -1
- package/dist/core/modules/funnel.js +6 -1
- package/dist/core/modules/funnel.js.map +1 -1
- package/dist/core/modules/lazyCommerce.d.ts +16 -0
- package/dist/core/modules/lazyCommerce.d.ts.map +1 -0
- package/dist/core/modules/lazyCommerce.js +20 -0
- package/dist/core/modules/lazyCommerce.js.map +1 -0
- package/dist/core/modules/offers.d.ts +30 -5
- package/dist/core/modules/offers.d.ts.map +1 -1
- package/dist/core/modules/offers.js +66 -7
- package/dist/core/modules/offers.js.map +1 -1
- package/dist/core/modules/portal/index.d.ts +102 -0
- package/dist/core/modules/portal/index.d.ts.map +1 -0
- package/dist/core/modules/portal/index.js +166 -0
- package/dist/core/modules/portal/index.js.map +1 -0
- package/dist/core/modules/portal/types.d.ts +617 -0
- package/dist/core/modules/portal/types.d.ts.map +1 -0
- package/dist/core/modules/portal/types.js +11 -0
- package/dist/core/modules/portal/types.js.map +1 -0
- package/dist/core/modules/track.d.ts +8 -0
- package/dist/core/modules/track.d.ts.map +1 -1
- package/dist/core/modules/track.js +49 -8
- package/dist/core/modules/track.js.map +1 -1
- package/dist/core/types.d.ts +11 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +0 -3
- package/dist/core/types.js.map +1 -1
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/pixels/pixelTracker.d.ts.map +1 -1
- package/dist/pixels/pixelTracker.js +4 -2
- package/dist/pixels/pixelTracker.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/provider.d.ts +13 -2
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +35 -7
- package/dist/react/provider.js.map +1 -1
- package/dist/tagada-headless-commerce.min.js +8 -0
- package/dist/tagada-headless-commerce.min.js.map +7 -0
- package/dist/tagada-headless-react.min.js +2 -2
- package/dist/tagada-headless-react.min.js.map +4 -4
- package/dist/tagada-headless.js +299 -288
- package/dist/tagada-headless.min.js +2 -2
- package/dist/tagada-headless.min.js.map +4 -4
- package/dist/tagada-pixels.min.js +2 -2
- package/dist/tagada-pixels.min.js.map +3 -3
- package/dist/tgd/contract/attribution.d.ts +28 -0
- package/dist/tgd/contract/attribution.d.ts.map +1 -0
- package/dist/tgd/contract/attribution.js +44 -0
- package/dist/tgd/contract/attribution.js.map +1 -0
- package/dist/tgd/contract/browser-api.d.ts +57 -0
- package/dist/tgd/contract/browser-api.d.ts.map +1 -0
- package/dist/tgd/contract/browser-api.js +2 -0
- package/dist/tgd/contract/browser-api.js.map +1 -0
- package/dist/tgd/contract/canvas.d.ts +120 -0
- package/dist/tgd/contract/canvas.d.ts.map +1 -0
- package/dist/tgd/contract/canvas.js +12 -0
- package/dist/tgd/contract/canvas.js.map +1 -0
- package/dist/tgd/contract/dedup-keys.d.ts +24 -0
- package/dist/tgd/contract/dedup-keys.d.ts.map +1 -0
- package/dist/tgd/contract/dedup-keys.js +23 -0
- package/dist/tgd/contract/dedup-keys.js.map +1 -0
- package/dist/tgd/contract/destination-names.d.ts +4 -0
- package/dist/tgd/contract/destination-names.d.ts.map +1 -0
- package/dist/tgd/contract/destination-names.js +66 -0
- package/dist/tgd/contract/destination-names.js.map +1 -0
- package/dist/tgd/contract/destinations.d.ts +124 -0
- package/dist/tgd/contract/destinations.d.ts.map +1 -0
- package/dist/tgd/contract/destinations.js +63 -0
- package/dist/tgd/contract/destinations.js.map +1 -0
- package/dist/tgd/contract/envelope.d.ts +203 -0
- package/dist/tgd/contract/envelope.d.ts.map +1 -0
- package/dist/tgd/contract/envelope.js +103 -0
- package/dist/tgd/contract/envelope.js.map +1 -0
- package/dist/tgd/contract/experiments.d.ts +87 -0
- package/dist/tgd/contract/experiments.d.ts.map +1 -0
- package/dist/tgd/contract/experiments.js +2 -0
- package/dist/tgd/contract/experiments.js.map +1 -0
- package/dist/tgd/contract/index.d.ts +20 -0
- package/dist/tgd/contract/index.d.ts.map +1 -0
- package/dist/tgd/contract/index.js +20 -0
- package/dist/tgd/contract/index.js.map +1 -0
- package/dist/tgd/contract/is-test.d.ts +2 -0
- package/dist/tgd/contract/is-test.d.ts.map +1 -0
- package/dist/tgd/contract/is-test.js +3 -0
- package/dist/tgd/contract/is-test.js.map +1 -0
- package/dist/tgd/contract/junk-ids.d.ts +4 -0
- package/dist/tgd/contract/junk-ids.d.ts.map +1 -0
- package/dist/tgd/contract/junk-ids.js +7 -0
- package/dist/tgd/contract/junk-ids.js.map +1 -0
- package/dist/tgd/contract/limits.d.ts +19 -0
- package/dist/tgd/contract/limits.d.ts.map +1 -0
- package/dist/tgd/contract/limits.js +20 -0
- package/dist/tgd/contract/limits.js.map +1 -0
- package/dist/tgd/contract/names.d.ts +13 -0
- package/dist/tgd/contract/names.d.ts.map +1 -0
- package/dist/tgd/contract/names.js +15 -0
- package/dist/tgd/contract/names.js.map +1 -0
- package/dist/tgd/contract/registry.d.ts +116 -0
- package/dist/tgd/contract/registry.d.ts.map +1 -0
- package/dist/tgd/contract/registry.js +59 -0
- package/dist/tgd/contract/registry.js.map +1 -0
- package/dist/tgd/contract/signed-ids.d.ts +33 -0
- package/dist/tgd/contract/signed-ids.d.ts.map +1 -0
- package/dist/tgd/contract/signed-ids.js +26 -0
- package/dist/tgd/contract/signed-ids.js.map +1 -0
- package/dist/tgd/contract/snapshots.d.ts +69 -0
- package/dist/tgd/contract/snapshots.d.ts.map +1 -0
- package/dist/tgd/contract/snapshots.js +2 -0
- package/dist/tgd/contract/snapshots.js.map +1 -0
- package/dist/tgd/contract/time.d.ts +9 -0
- package/dist/tgd/contract/time.d.ts.map +1 -0
- package/dist/tgd/contract/time.js +9 -0
- package/dist/tgd/contract/time.js.map +1 -0
- package/dist/tgd/contract/unions.d.ts +21 -0
- package/dist/tgd/contract/unions.d.ts.map +1 -0
- package/dist/tgd/contract/unions.js +17 -0
- package/dist/tgd/contract/unions.js.map +1 -0
- package/dist/tgd/contract/unit.d.ts +12 -0
- package/dist/tgd/contract/unit.d.ts.map +1 -0
- package/dist/tgd/contract/unit.js +18 -0
- package/dist/tgd/contract/unit.js.map +1 -0
- package/dist/tgd/contract/wire.d.ts +59 -0
- package/dist/tgd/contract/wire.d.ts.map +1 -0
- package/dist/tgd/contract/wire.js +2 -0
- package/dist/tgd/contract/wire.js.map +1 -0
- package/package.json +6 -3
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { TagadaError, TagadaNotFoundError } from '../errors.js';
|
|
2
|
+
function toSubscription(row, storeId) {
|
|
3
|
+
return {
|
|
4
|
+
...row,
|
|
5
|
+
storeId,
|
|
6
|
+
amount: row.priceCurrencyOptions?.[row.currency]?.amount ?? 0,
|
|
7
|
+
interval: row.priceInterval ?? '',
|
|
8
|
+
intervalCount: row.priceIntervalCount ?? 1,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* Customer data -- profile, orders, subscriptions.
|
|
3
13
|
*
|
|
@@ -13,24 +23,39 @@ export class CustomerModule {
|
|
|
13
23
|
const res = await this.http.get(`/api/v1/customers/${customerId}`, { params: { storeId: this.storeId } });
|
|
14
24
|
return res.customer;
|
|
15
25
|
}
|
|
16
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Not available: no route finds a customer by email for a storefront session. The only email
|
|
28
|
+
* search (`POST /api/v1/customers/search`) needs a secret API key of the whole account, which a
|
|
29
|
+
* storefront must never ship. Always rejects with a `TagadaError` of code `not_supported`, without
|
|
30
|
+
* sending a request. For the logged-in customer use `portal.getMe()` (Subscriptions V3 stores) or
|
|
31
|
+
* `getProfile(customerId)`.
|
|
32
|
+
*
|
|
33
|
+
* @deprecated There is no API route behind it.
|
|
34
|
+
*/
|
|
17
35
|
async getByEmail(email) {
|
|
18
|
-
|
|
19
|
-
const res = await this.http.get('/api/v1/customers/by-email', { params: { email, storeId: this.storeId } });
|
|
20
|
-
return res.customer;
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
36
|
+
throw new TagadaError('customer.getByEmail is not available: no API route finds a customer by email for a storefront session.', 'not_supported');
|
|
25
37
|
}
|
|
26
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Update the customer's email (`POST /api/v1/customers/:id`, the checkout's email step): the
|
|
40
|
+
* route stores the email only. A portal customer's name and phone go through `portal.updateProfile`.
|
|
41
|
+
*/
|
|
27
42
|
async updateProfile(customerId, data) {
|
|
28
|
-
|
|
29
|
-
return
|
|
43
|
+
await this.http.post(`/api/v1/customers/${customerId}`, { customerId, data: { email: data.email } });
|
|
44
|
+
return this.getProfile(customerId);
|
|
30
45
|
}
|
|
31
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* The customer's orders on this store, newest first (`GET /api/v1/orders/customer/:customerId`).
|
|
48
|
+
* Needs a session of that customer: the checkout session, or a portal login
|
|
49
|
+
* (`portal.verifyCode`). Another customer's id rejects with `TagadaNotFoundError`. The route sends
|
|
50
|
+
* every order at once: `limit` and `offset` slice them here, `total` counts them all.
|
|
51
|
+
*/
|
|
32
52
|
async getOrders(customerId, opts) {
|
|
33
|
-
|
|
53
|
+
const { orders } = await this.http.get(`/api/v1/orders/customer/${customerId}`, {
|
|
54
|
+
params: { storeId: this.storeId },
|
|
55
|
+
});
|
|
56
|
+
const start = opts?.offset ?? 0;
|
|
57
|
+
const end = opts?.limit === undefined ? undefined : start + opts.limit;
|
|
58
|
+
return { orders: orders.slice(start, end), total: orders.length };
|
|
34
59
|
}
|
|
35
60
|
/**
|
|
36
61
|
* Get a single order by ID.
|
|
@@ -73,15 +98,81 @@ export class CustomerModule {
|
|
|
73
98
|
}
|
|
74
99
|
return order;
|
|
75
100
|
}
|
|
76
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* The customer's subscriptions on this store, newest first (`GET /api/v1/subscriptions`). The
|
|
103
|
+
* route answers for the customer of the session: the checkout session, or a portal login
|
|
104
|
+
* (`portal.verifyCode`), which a Subscriptions V3 store requires. Another customer's id gets `[]`.
|
|
105
|
+
* Only the 20 most recent come back: the route's page size cannot travel in a query string.
|
|
106
|
+
*/
|
|
77
107
|
async getSubscriptions(customerId) {
|
|
78
|
-
const
|
|
79
|
-
return
|
|
108
|
+
const { items } = await this.http.get('/api/v1/subscriptions');
|
|
109
|
+
return items.filter((row) => row.customerId === customerId).map((row) => toSubscription(row, this.storeId));
|
|
80
110
|
}
|
|
81
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* One subscription of the session's customer. No route reads a subscription by id: this picks it
|
|
113
|
+
* from `getSubscriptions`' route, so it needs the same session and finds only the 20 most recent.
|
|
114
|
+
* Rejects with `TagadaNotFoundError` when it is not among them.
|
|
115
|
+
*/
|
|
82
116
|
async getSubscription(subscriptionId) {
|
|
83
|
-
const
|
|
84
|
-
|
|
117
|
+
const { items } = await this.http.get('/api/v1/subscriptions');
|
|
118
|
+
const row = items.find((item) => item.id === subscriptionId);
|
|
119
|
+
if (!row)
|
|
120
|
+
throw new TagadaNotFoundError('Subscription', subscriptionId);
|
|
121
|
+
return toSubscription(row, this.storeId);
|
|
122
|
+
}
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
// Subscription actions of the logged-in customer (customer portal session).
|
|
125
|
+
// Each one is refused when the store turned that action off.
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
/** Pause billing. `resumeAt` (ISO date) resumes it on that day. */
|
|
128
|
+
async pauseSubscription(subscriptionId, opts) {
|
|
129
|
+
await this.http.post('/api/v1/subscriptions/pause', { subscriptionId, resumeAt: opts?.resumeAt });
|
|
130
|
+
}
|
|
131
|
+
/** Resume a paused subscription, or one scheduled for cancellation. */
|
|
132
|
+
async resumeSubscription(subscriptionId) {
|
|
133
|
+
await this.http.post('/api/v1/subscriptions/resume', { subscriptionId });
|
|
134
|
+
}
|
|
135
|
+
/** Defer the next charge by one billing period. */
|
|
136
|
+
async skipSubscription(subscriptionId) {
|
|
137
|
+
await this.http.post('/api/v1/subscriptions/skip', { subscriptionId });
|
|
138
|
+
}
|
|
139
|
+
/** Move the next billing date (ISO date, within a year). */
|
|
140
|
+
async rescheduleSubscription(subscriptionId, nextBillingDate) {
|
|
141
|
+
await this.http.post('/api/v1/subscriptions/reschedule', { subscriptionId, nextBillingDate });
|
|
142
|
+
}
|
|
143
|
+
/** Change how many units each delivery bills for. */
|
|
144
|
+
async updateSubscriptionQuantity(subscriptionId, quantity) {
|
|
145
|
+
await this.http.post('/api/v1/subscriptions/quantity', { subscriptionId, quantity });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Move to another frequency of the same product: a recurring price id, or `{ optionId }` (a
|
|
149
|
+
* purchase option of the product, priced for the subscription's variant).
|
|
150
|
+
*/
|
|
151
|
+
async changeSubscriptionFrequency(subscriptionId, target) {
|
|
152
|
+
const body = typeof target === 'string' ? { priceId: target } : target;
|
|
153
|
+
await this.http.post('/api/v1/subscriptions/frequency', { subscriptionId, ...body });
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Swap the product a subscription bills for: at one of its recurring prices, or at one of its
|
|
157
|
+
* purchase options (`variantId` defaults to the product's default variant).
|
|
158
|
+
*/
|
|
159
|
+
async swapSubscriptionProduct(subscriptionId, target) {
|
|
160
|
+
await this.http.post('/api/v1/subscriptions/swap-product', { subscriptionId, ...target });
|
|
161
|
+
}
|
|
162
|
+
/** Attach a newly tokenized card to a subscription. */
|
|
163
|
+
async updateSubscriptionPaymentMethod(subscriptionId, tagadaToken) {
|
|
164
|
+
await this.http.post('/api/v1/subscriptions/payment-method', { subscriptionId, tagadaToken });
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Cancel a subscription, at the end of the paid period by default. Refused with HTTP 403 when the
|
|
168
|
+
* store does not offer it for this product, or before the subscription's minimum paid orders
|
|
169
|
+
* (error `name` `MINIMUM_ORDERS_NOT_REACHED`).
|
|
170
|
+
*/
|
|
171
|
+
async cancelSubscription(subscriptionId, opts) {
|
|
172
|
+
await this.http.post('/api/v1/subscriptions/cancel', {
|
|
173
|
+
subscriptionId,
|
|
174
|
+
cancelAtPeriodEnd: opts?.cancelAtPeriodEnd ?? true,
|
|
175
|
+
});
|
|
85
176
|
}
|
|
86
177
|
}
|
|
87
178
|
//# sourceMappingURL=customer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../../src/core/modules/customer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../../src/core/modules/customer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,W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CAAiC,EAAE,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IACvF,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,uBAAuB,CAC3B,cAAsB,EACtB,MAA4G;QAE5G,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAoC,EAAE,EAAE,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED,uDAAuD;IACvD,KAAK,CAAC,+BAA+B,CAAC,cAAsB,EAAE,WAAmB;QAC/E,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,sCAAsC,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;IAChG,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,kBAAkB,CAAC,cAAsB,EAAE,IAAsC;QACrF,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,8BAA8B,EAAE;YACnD,cAAc;YACd,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,IAAI,IAAI;SACnD,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { JsonValue, TgdBootstrap, TgdPublicApi } from '../../tgd/contract/index.js';
|
|
2
|
+
/** Lazy facade. Only the shared tgd runtime evaluates assignments and emits exposures. */
|
|
3
|
+
export declare class ExperimentsModule {
|
|
4
|
+
private readonly core;
|
|
5
|
+
private readonly bootstrap?;
|
|
6
|
+
private runtime;
|
|
7
|
+
private loading;
|
|
8
|
+
private settled;
|
|
9
|
+
private readonly reads;
|
|
10
|
+
private readonly subscribers;
|
|
11
|
+
constructor(core: () => Promise<TgdPublicApi | null>, bootstrap?: TgdBootstrap | undefined);
|
|
12
|
+
private variant;
|
|
13
|
+
private start;
|
|
14
|
+
private read;
|
|
15
|
+
getVariant(key: string): string | null;
|
|
16
|
+
getPayload(key: string): JsonValue | null;
|
|
17
|
+
isEnabled(flagKey: string): boolean;
|
|
18
|
+
onVariant(key: string, cb: (variant: string | null) => void): void;
|
|
19
|
+
ready(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=experiments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experiments.d.ts","sourceRoot":"","sources":["../../../src/core/modules/experiments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAIzF,0FAA0F;AAC1F,qBAAa,iBAAiB;IAOhB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAsC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IANlG,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;gBAEnB,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,EAAmB,SAAS,CAAC,EAAE,YAAY,YAAA;IAEhH,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,KAAK;IAkBb,OAAO,CAAC,IAAI;IAKZ,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMtC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAMzC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAMnC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAOlE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CACvB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Lazy facade. Only the shared tgd runtime evaluates assignments and emits exposures. */
|
|
2
|
+
export class ExperimentsModule {
|
|
3
|
+
constructor(core, bootstrap) {
|
|
4
|
+
this.core = core;
|
|
5
|
+
this.bootstrap = bootstrap;
|
|
6
|
+
this.runtime = null;
|
|
7
|
+
this.loading = null;
|
|
8
|
+
this.settled = false;
|
|
9
|
+
this.reads = new Set();
|
|
10
|
+
this.subscribers = [];
|
|
11
|
+
}
|
|
12
|
+
variant(key) {
|
|
13
|
+
return this.bootstrap?.experiments[key]?.arm ?? this.bootstrap?.flags[key]?.variant ?? null;
|
|
14
|
+
}
|
|
15
|
+
start() {
|
|
16
|
+
if (typeof window === 'undefined')
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
this.loading ?? (this.loading = (async () => {
|
|
19
|
+
try {
|
|
20
|
+
this.runtime = await this.core();
|
|
21
|
+
}
|
|
22
|
+
catch { /* Fall back to bootstrap. */ }
|
|
23
|
+
this.settled = true;
|
|
24
|
+
const runtime = this.runtime;
|
|
25
|
+
for (const key of this.reads) {
|
|
26
|
+
try {
|
|
27
|
+
runtime?.getVariant(key);
|
|
28
|
+
}
|
|
29
|
+
catch { /* Runtime failures cannot interrupt the merchant. */ }
|
|
30
|
+
}
|
|
31
|
+
this.reads.clear();
|
|
32
|
+
for (const { key, cb } of this.subscribers.splice(0)) {
|
|
33
|
+
try {
|
|
34
|
+
if (runtime)
|
|
35
|
+
runtime.onVariant(key, cb);
|
|
36
|
+
else
|
|
37
|
+
cb(this.variant(key));
|
|
38
|
+
}
|
|
39
|
+
catch { /* Isolate subscribers. */ }
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
await runtime?.ready();
|
|
43
|
+
}
|
|
44
|
+
catch { /* Offline assignment is a settled facade. */ }
|
|
45
|
+
})());
|
|
46
|
+
return this.loading;
|
|
47
|
+
}
|
|
48
|
+
read(key) {
|
|
49
|
+
if (!this.settled)
|
|
50
|
+
this.reads.add(key);
|
|
51
|
+
void this.start();
|
|
52
|
+
}
|
|
53
|
+
getVariant(key) {
|
|
54
|
+
if (this.runtime)
|
|
55
|
+
return this.runtime.getVariant(key);
|
|
56
|
+
this.read(key);
|
|
57
|
+
return this.variant(key);
|
|
58
|
+
}
|
|
59
|
+
getPayload(key) {
|
|
60
|
+
if (this.runtime)
|
|
61
|
+
return this.runtime.getPayload(key);
|
|
62
|
+
this.read(key);
|
|
63
|
+
return this.bootstrap?.experiments[key]?.payload ?? this.bootstrap?.flags[key]?.payload ?? null;
|
|
64
|
+
}
|
|
65
|
+
isEnabled(flagKey) {
|
|
66
|
+
if (this.runtime)
|
|
67
|
+
return this.runtime.isEnabled(flagKey);
|
|
68
|
+
this.read(flagKey);
|
|
69
|
+
return this.bootstrap?.flags[flagKey]?.enabled ?? false;
|
|
70
|
+
}
|
|
71
|
+
onVariant(key, cb) {
|
|
72
|
+
if (this.runtime) {
|
|
73
|
+
this.runtime.onVariant(key, cb);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (this.settled) {
|
|
77
|
+
cb(this.variant(key));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.subscribers.push({ key, cb });
|
|
81
|
+
void this.start();
|
|
82
|
+
}
|
|
83
|
+
ready() { return this.start(); }
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=experiments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experiments.js","sourceRoot":"","sources":["../../../src/core/modules/experiments.ts"],"names":[],"mappings":"AAIA,0FAA0F;AAC1F,MAAM,OAAO,iBAAiB;IAO5B,YAA6B,IAAwC,EAAmB,SAAwB;QAAnF,SAAI,GAAJ,IAAI,CAAoC;QAAmB,cAAS,GAAT,SAAS,CAAe;QANxG,YAAO,GAAwB,IAAI,CAAC;QACpC,YAAO,GAAyB,IAAI,CAAC;QACrC,YAAO,GAAG,KAAK,CAAC;QACP,UAAK,GAAG,IAAI,GAAG,EAAU,CAAC;QAC1B,gBAAW,GAAiB,EAAE,CAAC;IAEmE,CAAC;IAE5G,OAAO,CAAC,GAAW;QACzB,OAAO,IAAI,CAAC,S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,SAAS,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QAC9D,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QACpD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;QACnC,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,KAAK,KAAoB,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAChD"}
|
|
@@ -26,10 +26,11 @@ export declare class FunnelModule {
|
|
|
26
26
|
private readonly storeId;
|
|
27
27
|
private readonly checkout;
|
|
28
28
|
private readonly accountId;
|
|
29
|
+
private readonly onFunnelSession?;
|
|
29
30
|
private _cmsToken;
|
|
30
31
|
private _cmsSessionId;
|
|
31
32
|
private _cmsCustomerId;
|
|
32
|
-
constructor(http: HttpClient, storeId: string, checkout: CheckoutModule, accountId: string | undefined);
|
|
33
|
+
constructor(http: HttpClient, storeId: string, checkout: CheckoutModule, accountId: string | undefined, onFunnelSession?: ((funnelSessionId: string) => void) | undefined);
|
|
33
34
|
navigate(input: FunnelNavigateInput): Promise<FunnelNavigateResult>;
|
|
34
35
|
private ensureCmsSession;
|
|
35
36
|
private initializeFunnel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"funnel.d.ts","sourceRoot":"","sources":["../../../src/core/modules/funnel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAEV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY;IAMrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;
|
|
1
|
+
{"version":3,"file":"funnel.d.ts","sourceRoot":"","sources":["../../../src/core/modules/funnel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAEV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY;IAMrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;IATnC,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,cAAc,CAAqB;gBAGxB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,eAAe,CAAC,GAAE,CAAC,eAAe,EAAE,MAAM,KAAK,IAAI,aAAA;IAGhE,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;YA8C3D,gBAAgB;YA+BhB,gBAAgB;YA0BhB,WAAW;CAyD1B"}
|
|
@@ -20,11 +20,12 @@ import { TagadaError } from '../errors.js';
|
|
|
20
20
|
* `session.customer.email`, and the promotion code from `session.promotionCode`.
|
|
21
21
|
*/
|
|
22
22
|
export class FunnelModule {
|
|
23
|
-
constructor(http, storeId, checkout, accountId) {
|
|
23
|
+
constructor(http, storeId, checkout, accountId, onFunnelSession) {
|
|
24
24
|
this.http = http;
|
|
25
25
|
this.storeId = storeId;
|
|
26
26
|
this.checkout = checkout;
|
|
27
27
|
this.accountId = accountId;
|
|
28
|
+
this.onFunnelSession = onFunnelSession;
|
|
28
29
|
}
|
|
29
30
|
async navigate(input) {
|
|
30
31
|
const session = this.checkout.getCurrentSession();
|
|
@@ -43,6 +44,10 @@ export class FunnelModule {
|
|
|
43
44
|
accountId,
|
|
44
45
|
currentUrl,
|
|
45
46
|
});
|
|
47
|
+
try {
|
|
48
|
+
this.onFunnelSession?.(funnelSessionId);
|
|
49
|
+
}
|
|
50
|
+
catch { /* Tracking cannot interrupt navigation. */ }
|
|
46
51
|
const url = await this.runNavigate({
|
|
47
52
|
funnelSessionId,
|
|
48
53
|
stepId: input.stepId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"funnel.js","sourceRoot":"","sources":["../../../src/core/modules/funnel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAS3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,YAAY;IAKvB,YACmB,IAAgB,EAChB,OAAe,EACf,QAAwB,EACxB,SAA6B;
|
|
1
|
+
{"version":3,"file":"funnel.js","sourceRoot":"","sources":["../../../src/core/modules/funnel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAS3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,YAAY;IAKvB,YACmB,IAAgB,EAChB,OAAe,EACf,QAAwB,EACxB,SAA6B,EAC7B,eAAmD;QAJnD,SAAI,GAAJ,IAAI,CAAY;QAChB,YAAO,GAAP,OAAO,CAAQ;QACf,aAAQ,GAAR,QAAQ,CAAgB;QACxB,cAAS,GAAT,SAAS,CAAoB;QAC7B,oBAAe,GAAf,eAAe,CAAoC;IACnE,CAAC;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B,aAAa,EAAE,KAAK;YACpB,KAAK,EAAE;gBACL,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE;oBACJ,YAAY,EAAE;wBACZ,SAAS,EAAE,OAAO,CAAC,EAAE;wBACrB,SAAS;wBACT,QAAQ;wBACR,SAAS,EAAE,KAAK,CAAC,SAAS;wBAC1B,OAAO,EAAE,IAAI,CAAC,OAAO;wBACrB,QAAQ,EAAE,KAAK,CAAC,QAAQ;wBACxB,aAAa;wBACb,mEAAmE;wBACnE,kEAAkE;wBAClE,+DAA+D;wBAC/D,yCAAyC;wBACzC,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;qBACzC;iBACF;aACF;SACF,EACD,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAC1B,CAAC;QAEF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC;IACxB,CAAC;CACF;AAED,SAAS,aAAa;IACpB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC,QAAQ,CAAC;IACtF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB;IACvB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC,SAAS,CAAC;IACxF,OAAO,wBAAwB,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CustomerPortalModule } from './portal/index.js';
|
|
2
|
+
import type { CustomerModule } from './customer.js';
|
|
3
|
+
import type { OffersModule } from './offers.js';
|
|
4
|
+
type Commerce = {
|
|
5
|
+
CustomerPortalModule: typeof CustomerPortalModule;
|
|
6
|
+
OffersModule: typeof OffersModule;
|
|
7
|
+
CustomerModule: typeof CustomerModule;
|
|
8
|
+
};
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
TagadaHeadlessCommerce?: Commerce;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare function loadCommerce(): Promise<Commerce>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=lazyCommerce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyCommerce.d.ts","sourceRoot":"","sources":["../../../src/core/modules/lazyCommerce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,KAAK,QAAQ,GAAG;IAAE,oBAAoB,EAAE,OAAO,oBAAoB,CAAC;IAAC,YAAY,EAAE,OAAO,YAAY,CAAC;IAAC,cAAc,EAAE,OAAO,cAAc,CAAA;CAAE,CAAC;AAChJ,OAAO,CAAC,MAAM,CAAC;IAAE,UAAU,MAAM;QAAG,sBAAsB,CAAC,EAAE,QAAQ,CAAA;KAAE;CAAE;AAKzE,wBAAgB,YAAY,IAAI,OAAO,CAAC,QAAQ,CAAC,CAWhD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const script = typeof document === 'undefined' ? null : document.currentScript;
|
|
2
|
+
const url = script?.src ? new URL('tagada-headless-commerce.min.js', script.src).href : __TGD_COMMERCE_CDN__;
|
|
3
|
+
let loading;
|
|
4
|
+
export function loadCommerce() {
|
|
5
|
+
if (window.TagadaHeadlessCommerce)
|
|
6
|
+
return Promise.resolve(window.TagadaHeadlessCommerce);
|
|
7
|
+
if (!loading)
|
|
8
|
+
loading = new Promise((resolve, reject) => {
|
|
9
|
+
const element = document.createElement('script');
|
|
10
|
+
element.src = url;
|
|
11
|
+
element.async = true;
|
|
12
|
+
if (script?.nonce)
|
|
13
|
+
element.nonce = script.nonce;
|
|
14
|
+
element.addEventListener('load', () => window.TagadaHeadlessCommerce ? resolve(window.TagadaHeadlessCommerce) : reject(new Error('Commerce bundle did not initialize')));
|
|
15
|
+
element.addEventListener('error', () => { element.remove(); reject(new Error('Unable to load commerce bundle')); });
|
|
16
|
+
document.head.appendChild(element);
|
|
17
|
+
}).catch(error => { loading = undefined; throw error; });
|
|
18
|
+
return loading;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=lazyCommerce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyCommerce.js","sourceRoot":"","sources":["../../../src/core/modules/lazyCommerce.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAyC,CAAC;AAC3G,MAAM,GAAG,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,iCAAiC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC;AAC7G,IAAI,OAAsC,CAAC;AAE3C,MAAM,UAAU,YAAY;IAC1B,IAAI,MAAM,CAAC,sBAAsB;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACzF,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAChE,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YACjD,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;YAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YACxC,IAAI,MAAM,EAAE,KAAK;gBAAE,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YAChD,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC,CAAC;YACzK,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACpH,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -11,8 +11,7 @@ import type { PaymentModule } from './payment.js';
|
|
|
11
11
|
* POST /api/v1/offers/:offerId/pay-preview — pay a previewed offer (one-click)
|
|
12
12
|
* POST /api/v1/checkout-sessions/:id/toggle-order-bump — toggle order bump
|
|
13
13
|
* GET /api/v1/post-purchase/:orderId/offers — post-purchase offers for an order
|
|
14
|
-
*
|
|
15
|
-
* POST /api/v1/orders/:orderId/post-purchase-offers/:offerId/decline — decline
|
|
14
|
+
* Post-purchase acceptance uses pay-preview; declining is a local decision.
|
|
16
15
|
*/
|
|
17
16
|
export declare class OffersModule {
|
|
18
17
|
private readonly http;
|
|
@@ -26,7 +25,13 @@ export declare class OffersModule {
|
|
|
26
25
|
type?: 'upsell' | 'orderbump';
|
|
27
26
|
ids?: string[];
|
|
28
27
|
}): Promise<Offer[]>;
|
|
29
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Preview offer pricing. Returns line items with amounts and totals.
|
|
30
|
+
*
|
|
31
|
+
* A Studio offer block is previewed under `blockoffer:<blockId>` and read from
|
|
32
|
+
* the step its funnel session stands on: pass that session's id
|
|
33
|
+
* (see {@link enterFunnelStep}).
|
|
34
|
+
*/
|
|
30
35
|
previewOffer(opts: {
|
|
31
36
|
offerId: string;
|
|
32
37
|
currency?: string;
|
|
@@ -36,7 +41,25 @@ export declare class OffersModule {
|
|
|
36
41
|
variantId: string;
|
|
37
42
|
quantity: number;
|
|
38
43
|
}>;
|
|
44
|
+
funnelSessionId?: string;
|
|
39
45
|
}): Promise<OfferPreview>;
|
|
46
|
+
/**
|
|
47
|
+
* Put the buyer on a step of a funnel, for pages the funnel does not serve
|
|
48
|
+
* itself: its offer blocks are then previewed and accepted as
|
|
49
|
+
* `blockoffer:<blockId>` with the returned `funnelSessionId`. Uses the
|
|
50
|
+
* checkout session's token, so the funnel session is the paying customer's.
|
|
51
|
+
* Pass `checkoutToken` at checkout to link that checkout to the funnel
|
|
52
|
+
* session, and `funnelSessionId` to move an open session to another step.
|
|
53
|
+
*/
|
|
54
|
+
enterFunnelStep(opts: {
|
|
55
|
+
funnelId: string;
|
|
56
|
+
stepId: string;
|
|
57
|
+
accountId: string;
|
|
58
|
+
funnelSessionId?: string;
|
|
59
|
+
checkoutToken?: string;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
funnelSessionId: string;
|
|
62
|
+
}>;
|
|
40
63
|
/**
|
|
41
64
|
* Pay a previously previewed offer (one-click charge).
|
|
42
65
|
* Used after a main order so the stored payment instrument is reused.
|
|
@@ -57,6 +80,7 @@ export declare class OffersModule {
|
|
|
57
80
|
}>;
|
|
58
81
|
returnUrl?: string;
|
|
59
82
|
paymentInstrumentId?: string;
|
|
83
|
+
funnelSessionId?: string;
|
|
60
84
|
}): Promise<OfferPayResult>;
|
|
61
85
|
/**
|
|
62
86
|
* One-click upsell with full lifecycle handling.
|
|
@@ -104,6 +128,7 @@ export declare class OffersModule {
|
|
|
104
128
|
}>;
|
|
105
129
|
returnUrl?: string;
|
|
106
130
|
paymentInstrumentId?: string;
|
|
131
|
+
funnelSessionId?: string;
|
|
107
132
|
}): Promise<ProcessPaymentResult>;
|
|
108
133
|
/** Toggle an order bump on/off within a checkout session. */
|
|
109
134
|
toggleOrderBump(opts: {
|
|
@@ -113,7 +138,7 @@ export declare class OffersModule {
|
|
|
113
138
|
}): Promise<unknown>;
|
|
114
139
|
/** List post-purchase offers for an order. */
|
|
115
140
|
listPostPurchaseOffers(orderId: string): Promise<Offer[]>;
|
|
116
|
-
/** Accept a post-purchase offer. */
|
|
141
|
+
/** Accept a post-purchase offer. Only a confirmed charge returns success. */
|
|
117
142
|
acceptPostPurchaseOffer(opts: {
|
|
118
143
|
orderId: string;
|
|
119
144
|
offerId: string;
|
|
@@ -125,7 +150,7 @@ export declare class OffersModule {
|
|
|
125
150
|
success: boolean;
|
|
126
151
|
error?: string;
|
|
127
152
|
}>;
|
|
128
|
-
/** Decline
|
|
153
|
+
/** Decline locally; the backend has no persisted refusal and no charge is made. */
|
|
129
154
|
declinePostPurchaseOffer(opts: {
|
|
130
155
|
orderId: string;
|
|
131
156
|
offerId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offers.d.ts","sourceRoot":"","sources":["../../../src/core/modules/offers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"offers.d.ts","sourceRoot":"","sources":["../../../src/core/modules/offers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,O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AM,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,CAAC;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACxD,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAqCjD,mFAAmF;IAC7E,wBAAwB,CAAC,IAAI,EAAE;QACnC,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAGlD"}
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
* POST /api/v1/offers/:offerId/pay-preview — pay a previewed offer (one-click)
|
|
9
9
|
* POST /api/v1/checkout-sessions/:id/toggle-order-bump — toggle order bump
|
|
10
10
|
* GET /api/v1/post-purchase/:orderId/offers — post-purchase offers for an order
|
|
11
|
-
*
|
|
12
|
-
* POST /api/v1/orders/:orderId/post-purchase-offers/:offerId/decline — decline
|
|
11
|
+
* Post-purchase acceptance uses pay-preview; declining is a local decision.
|
|
13
12
|
*/
|
|
14
13
|
export class OffersModule {
|
|
15
14
|
constructor(http, storeId, payment) {
|
|
@@ -42,13 +41,41 @@ export class OffersModule {
|
|
|
42
41
|
// ---------------------------------------------------------------------------
|
|
43
42
|
// Preview & pay (one-click upsell flow from plugin-sdk)
|
|
44
43
|
// ---------------------------------------------------------------------------
|
|
45
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Preview offer pricing. Returns line items with amounts and totals.
|
|
46
|
+
*
|
|
47
|
+
* A Studio offer block is previewed under `blockoffer:<blockId>` and read from
|
|
48
|
+
* the step its funnel session stands on: pass that session's id
|
|
49
|
+
* (see {@link enterFunnelStep}).
|
|
50
|
+
*/
|
|
46
51
|
async previewOffer(opts) {
|
|
47
52
|
return this.http.post(`/api/v1/offers/${opts.offerId}/preview`, {
|
|
48
53
|
offerId: opts.offerId,
|
|
49
54
|
currency: opts.currency ?? '',
|
|
50
55
|
lineItems: opts.lineItems,
|
|
56
|
+
funnelSessionId: opts.funnelSessionId,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Put the buyer on a step of a funnel, for pages the funnel does not serve
|
|
61
|
+
* itself: its offer blocks are then previewed and accepted as
|
|
62
|
+
* `blockoffer:<blockId>` with the returned `funnelSessionId`. Uses the
|
|
63
|
+
* checkout session's token, so the funnel session is the paying customer's.
|
|
64
|
+
* Pass `checkoutToken` at checkout to link that checkout to the funnel
|
|
65
|
+
* session, and `funnelSessionId` to move an open session to another step.
|
|
66
|
+
*/
|
|
67
|
+
async enterFunnelStep(opts) {
|
|
68
|
+
const here = typeof window !== 'undefined' ? window.location.origin : 'http://localhost';
|
|
69
|
+
const res = await this.http.post('/api/v1/funnel/initialize', {
|
|
70
|
+
// Placeholder ids: the server takes the customer and the CMS session from the token.
|
|
71
|
+
cmsSession: { customerId: 'anon_placeholder', sessionId: 'anon_placeholder', storeId: this.storeId, accountId: opts.accountId },
|
|
72
|
+
funnelId: opts.funnelId,
|
|
73
|
+
funnelStepId: opts.stepId,
|
|
74
|
+
existingSessionId: opts.funnelSessionId,
|
|
75
|
+
currentUrl: opts.checkoutToken ? `${here}/?checkoutToken=${encodeURIComponent(opts.checkoutToken)}` : undefined,
|
|
76
|
+
draft: false,
|
|
51
77
|
});
|
|
78
|
+
return { funnelSessionId: res.context.sessionId };
|
|
52
79
|
}
|
|
53
80
|
/**
|
|
54
81
|
* Pay a previously previewed offer (one-click charge).
|
|
@@ -66,6 +93,7 @@ export class OffersModule {
|
|
|
66
93
|
returnUrl: opts.returnUrl ?? (typeof window !== 'undefined' ? window.location.href : ''),
|
|
67
94
|
mainOrderId: opts.mainOrderId,
|
|
68
95
|
paymentInstrumentId: opts.paymentInstrumentId,
|
|
96
|
+
funnelSessionId: opts.funnelSessionId,
|
|
69
97
|
});
|
|
70
98
|
}
|
|
71
99
|
/**
|
|
@@ -129,13 +157,44 @@ export class OffersModule {
|
|
|
129
157
|
const res = await this.http.get(`/api/v1/post-purchase/${orderId}/offers`);
|
|
130
158
|
return Array.isArray(res) ? res : [];
|
|
131
159
|
}
|
|
132
|
-
/** Accept a post-purchase offer. */
|
|
160
|
+
/** Accept a post-purchase offer. Only a confirmed charge returns success. */
|
|
133
161
|
async acceptPostPurchaseOffer(opts) {
|
|
134
|
-
|
|
162
|
+
// The server matches overrides by line-item/product ID, not variant alone.
|
|
163
|
+
// Resolve against this offer's quote so an unrelated variant cannot silently
|
|
164
|
+
// fall back to charging the offer's default selection.
|
|
165
|
+
let lineItems;
|
|
166
|
+
if (opts.items?.length) {
|
|
167
|
+
const quote = await this.http.post(`/api/v1/offers/${opts.offerId}/preview`, { offerId: opts.offerId, currency: '' });
|
|
168
|
+
lineItems = [];
|
|
169
|
+
for (const item of opts.items) {
|
|
170
|
+
const matches = quote.lineItems.filter(line => line.variantId === item.variantId ||
|
|
171
|
+
quote.preview.options[line.productId]?.some(variant => variant.id === item.variantId));
|
|
172
|
+
if (matches.length !== 1 || lineItems.some(line => line.lineItemId === matches[0].lineItemId)) {
|
|
173
|
+
return { success: false, error: 'Invalid selection' };
|
|
174
|
+
}
|
|
175
|
+
lineItems.push({ ...item, lineItemId: matches[0].lineItemId, productId: matches[0].productId });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const result = await this.payPreviewedOffer({
|
|
179
|
+
offerId: opts.offerId,
|
|
180
|
+
mainOrderId: opts.orderId,
|
|
181
|
+
lineItems,
|
|
182
|
+
});
|
|
183
|
+
if (result.payment.status === 'succeeded')
|
|
184
|
+
return { success: true };
|
|
185
|
+
return {
|
|
186
|
+
success: false,
|
|
187
|
+
error: result.payment.status === 'pending'
|
|
188
|
+
? 'Payment pending'
|
|
189
|
+
: result.payment.status === 'requires_action' ||
|
|
190
|
+
(result.payment.requireAction && result.payment.requireAction !== 'none')
|
|
191
|
+
? 'Payment requires authentication'
|
|
192
|
+
: result.payment.requireActionData?.message || 'Payment declined',
|
|
193
|
+
};
|
|
135
194
|
}
|
|
136
|
-
/** Decline
|
|
195
|
+
/** Decline locally; the backend has no persisted refusal and no charge is made. */
|
|
137
196
|
async declinePostPurchaseOffer(opts) {
|
|
138
|
-
return
|
|
197
|
+
return { success: true };
|
|
139
198
|
}
|
|
140
199
|
}
|
|
141
200
|
//# sourceMappingURL=offers.js.map
|