@cimplify/sdk 0.76.0 → 0.79.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/dist/advanced.d.mts +3 -3
- package/dist/advanced.d.ts +3 -3
- package/dist/{chunk-QS4XDVHI.js → chunk-5BPBDWAA.js} +94 -0
- package/dist/{chunk-J7L5LHGK.mjs → chunk-BNA4GW4D.mjs} +34 -11
- package/dist/{chunk-BYWJSPT4.mjs → chunk-FURKCWVG.mjs} +6 -3
- package/dist/{chunk-H337NF4O.mjs → chunk-LBFTEXGD.mjs} +94 -1
- package/dist/{chunk-OGQFDCZM.js → chunk-OSTOGR4F.js} +34 -11
- package/dist/{chunk-Y64AIRGW.js → chunk-T7ALPOK7.js} +8 -5
- package/dist/{client-D7MP5Zi7.d.ts → client-BAzvXSLJ.d.ts} +2 -2
- package/dist/{client-DDWRDb9m.d.mts → client-Byysg2IX.d.mts} +2 -2
- package/dist/{client-CBQJQn7E.d.mts → client-Cn5trGYV.d.ts} +41 -4
- package/dist/{client-ciWgfgLw.d.ts → client-D16qfHAB.d.mts} +41 -4
- package/dist/{index-lt-fe29V.d.mts → index-Bu76UyFz.d.mts} +3 -3
- package/dist/{index-DTGS0QC1.d.ts → index-Moe4cGMB.d.ts} +3 -3
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +13 -9
- package/dist/index.mjs +1 -1
- package/dist/mock/cli.mjs +34 -11
- package/dist/mock/library.js +34 -11
- package/dist/mock/library.mjs +34 -11
- package/dist/mock/msw.js +34 -11
- package/dist/mock/msw.mjs +34 -11
- package/dist/{payment-C-2gApyQ.d.mts → payment-B7qzWdaJ.d.mts} +1 -1
- package/dist/{payment-CfemTORM.d.ts → payment-mVIJIJcq.d.ts} +1 -1
- package/dist/{price-CZBQw-Rh.d.mts → price-BfOaGqjx.d.mts} +1 -1
- package/dist/{price-DNeyoO7y.d.ts → price-CS1IsORZ.d.ts} +1 -1
- package/dist/{product-_GFoaPHU.d.mts → product-BgFOFmQw.d.mts} +7 -0
- package/dist/{product-_GFoaPHU.d.ts → product-BgFOFmQw.d.ts} +7 -0
- package/dist/react.d.mts +18 -5
- package/dist/react.d.ts +18 -5
- package/dist/react.js +22 -3
- package/dist/react.mjs +21 -3
- package/dist/server-BXT62nBC.d.mts +1186 -0
- package/dist/server-BXT62nBC.d.ts +1186 -0
- package/dist/{server-G8I4JtqK.d.mts → server-CGO4zneR.d.mts} +1 -1
- package/dist/{server-1hXIXH2k.d.ts → server-Daq42vK7.d.ts} +1 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +2 -2
- package/dist/server.mjs +1 -1
- package/dist/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +2 -2
- package/dist/testing/msw.mjs +1 -1
- package/dist/testing/suite.d.mts +6 -6
- package/dist/testing/suite.d.ts +6 -6
- package/dist/testing/suite.js +22 -22
- package/dist/testing/suite.mjs +3 -3
- package/dist/testing.d.mts +20 -5
- package/dist/testing.d.ts +20 -5
- package/dist/testing.js +78 -78
- package/dist/testing.mjs +4 -4
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/package.json +1 -1
package/dist/advanced.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { k as AuthService, C as BusinessService, P as CartOperations, Q as CatalogueQueries, a9 as CheckoutOperations, a9 as CheckoutService, af as CimplifyElement, ag as CimplifyElements, aF as ELEMENT_TYPES, aG as EVENT_TYPES, aJ as ElementEventType, aK as ElementOptions, aL as ElementType, aT as ElementsOptions, a$ as FetchQuoteInput, b7 as FxService, ba as GetProductsOptions, bd as InventoryService, bk as LinkService, bo as LiteService, bv as MESSAGE_TYPES, bY as OrderQueries, cf as PriceQuote, cl as QuoteBundleSelectionInput, cm as QuoteCompositeSelectionInput, cn as QuoteDynamicBuckets, co as QuoteStatus, cp as QuoteUiMessage, cr as RefreshQuoteInput, cs as RefreshQuoteResult, cT as SchedulingService,
|
|
2
|
-
import './product-
|
|
3
|
-
import './payment-
|
|
1
|
+
export { k as AuthService, C as BusinessService, P as CartOperations, Q as CatalogueQueries, a9 as CheckoutOperations, a9 as CheckoutService, af as CimplifyElement, ag as CimplifyElements, aF as ELEMENT_TYPES, aG as EVENT_TYPES, aJ as ElementEventType, aK as ElementOptions, aL as ElementType, aT as ElementsOptions, a$ as FetchQuoteInput, b7 as FxService, ba as GetProductsOptions, bd as InventoryService, bk as LinkService, bo as LiteService, bv as MESSAGE_TYPES, bY as OrderQueries, cf as PriceQuote, cl as QuoteBundleSelectionInput, cm as QuoteCompositeSelectionInput, cn as QuoteDynamicBuckets, co as QuoteStatus, cp as QuoteUiMessage, cr as RefreshQuoteInput, cs as RefreshQuoteResult, cT as SchedulingService, dy as createElements } from './client-D16qfHAB.mjs';
|
|
2
|
+
import './product-BgFOFmQw.mjs';
|
|
3
|
+
import './payment-B7qzWdaJ.mjs';
|
|
4
4
|
|
|
5
5
|
declare function generateIdempotencyKey(prefix?: string): string;
|
|
6
6
|
|
package/dist/advanced.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { k as AuthService, C as BusinessService, P as CartOperations, Q as CatalogueQueries, a9 as CheckoutOperations, a9 as CheckoutService, af as CimplifyElement, ag as CimplifyElements, aF as ELEMENT_TYPES, aG as EVENT_TYPES, aJ as ElementEventType, aK as ElementOptions, aL as ElementType, aT as ElementsOptions, a$ as FetchQuoteInput, b7 as FxService, ba as GetProductsOptions, bd as InventoryService, bk as LinkService, bo as LiteService, bv as MESSAGE_TYPES, bY as OrderQueries, cf as PriceQuote, cl as QuoteBundleSelectionInput, cm as QuoteCompositeSelectionInput, cn as QuoteDynamicBuckets, co as QuoteStatus, cp as QuoteUiMessage, cr as RefreshQuoteInput, cs as RefreshQuoteResult, cT as SchedulingService,
|
|
2
|
-
import './product-
|
|
3
|
-
import './payment-
|
|
1
|
+
export { k as AuthService, C as BusinessService, P as CartOperations, Q as CatalogueQueries, a9 as CheckoutOperations, a9 as CheckoutService, af as CimplifyElement, ag as CimplifyElements, aF as ELEMENT_TYPES, aG as EVENT_TYPES, aJ as ElementEventType, aK as ElementOptions, aL as ElementType, aT as ElementsOptions, a$ as FetchQuoteInput, b7 as FxService, ba as GetProductsOptions, bd as InventoryService, bk as LinkService, bo as LiteService, bv as MESSAGE_TYPES, bY as OrderQueries, cf as PriceQuote, cl as QuoteBundleSelectionInput, cm as QuoteCompositeSelectionInput, cn as QuoteDynamicBuckets, co as QuoteStatus, cp as QuoteUiMessage, cr as RefreshQuoteInput, cs as RefreshQuoteResult, cT as SchedulingService, dy as createElements } from './client-Cn5trGYV.js';
|
|
2
|
+
import './product-BgFOFmQw.js';
|
|
3
|
+
import './payment-mVIJIJcq.js';
|
|
4
4
|
|
|
5
5
|
declare function generateIdempotencyKey(prefix?: string): string;
|
|
6
6
|
|
|
@@ -3,11 +3,77 @@
|
|
|
3
3
|
var chunkCV5QMDQS_js = require('./chunk-CV5QMDQS.js');
|
|
4
4
|
var chunkXA3ZNR75_js = require('./chunk-XA3ZNR75.js');
|
|
5
5
|
|
|
6
|
+
// src/store-credit.ts
|
|
7
|
+
var StoreCreditQueries = class {
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The shopper's available store-credit balance, in the business's default
|
|
13
|
+
* currency. Requires a signed-in customer; returns an error otherwise.
|
|
14
|
+
*/
|
|
15
|
+
async balance() {
|
|
16
|
+
return chunkCV5QMDQS_js.safe(this.client.get("/api/v1/store-credit/balance"));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
6
20
|
// src/activity.ts
|
|
21
|
+
var VISITOR_ID_STORAGE_KEY = "cimplify_visitor_id";
|
|
22
|
+
var SESSION_STARTED_STORAGE_KEY = "cimplify_session_started_at";
|
|
7
23
|
var ActivityService = class {
|
|
8
24
|
constructor(client) {
|
|
9
25
|
this.client = client;
|
|
10
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Record session start (landing, referrer, UTM, device). Fire-and-forget,
|
|
29
|
+
* at most once per tab session; called automatically by the track* methods.
|
|
30
|
+
*/
|
|
31
|
+
startSession() {
|
|
32
|
+
if (typeof window === "undefined") return;
|
|
33
|
+
let alreadyStarted = null;
|
|
34
|
+
try {
|
|
35
|
+
alreadyStarted = sessionStorage.getItem(SESSION_STARTED_STORAGE_KEY);
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
if (alreadyStarted) return;
|
|
39
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
40
|
+
try {
|
|
41
|
+
sessionStorage.setItem(SESSION_STARTED_STORAGE_KEY, startedAt);
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
this.client.post("/api/v1/activity/session", this.buildSessionPayload(startedAt)).catch(() => {
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
buildSessionPayload(startedAt) {
|
|
48
|
+
const params = new URLSearchParams(window.location.search);
|
|
49
|
+
const utm = (key) => params.get(`utm_${key}`) || void 0;
|
|
50
|
+
const { visitorId, isNewVisitor } = resolveVisitor();
|
|
51
|
+
let timezone;
|
|
52
|
+
try {
|
|
53
|
+
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
started_at: startedAt,
|
|
58
|
+
landing_page: window.location.pathname,
|
|
59
|
+
landing_url: window.location.href,
|
|
60
|
+
referrer_url: document.referrer || void 0,
|
|
61
|
+
utm_source: utm("source"),
|
|
62
|
+
utm_medium: utm("medium"),
|
|
63
|
+
utm_campaign: utm("campaign"),
|
|
64
|
+
utm_term: utm("term"),
|
|
65
|
+
utm_content: utm("content"),
|
|
66
|
+
screen_width: window.screen?.width,
|
|
67
|
+
screen_height: window.screen?.height,
|
|
68
|
+
viewport_width: window.innerWidth,
|
|
69
|
+
viewport_height: window.innerHeight,
|
|
70
|
+
pixel_density: window.devicePixelRatio,
|
|
71
|
+
language: navigator.language,
|
|
72
|
+
timezone,
|
|
73
|
+
fingerprint: visitorId,
|
|
74
|
+
is_new_visitor: isNewVisitor
|
|
75
|
+
};
|
|
76
|
+
}
|
|
11
77
|
trackProductView(productId, options = {}) {
|
|
12
78
|
const event = {
|
|
13
79
|
type: "product_view",
|
|
@@ -45,6 +111,7 @@ var ActivityService = class {
|
|
|
45
111
|
);
|
|
46
112
|
}
|
|
47
113
|
sendEvents(events) {
|
|
114
|
+
this.startSession();
|
|
48
115
|
this.client.post("/api/v1/activity/events", { events }).catch(() => {
|
|
49
116
|
});
|
|
50
117
|
}
|
|
@@ -55,6 +122,19 @@ function currentPath() {
|
|
|
55
122
|
}
|
|
56
123
|
return void 0;
|
|
57
124
|
}
|
|
125
|
+
function resolveVisitor() {
|
|
126
|
+
try {
|
|
127
|
+
const existing = localStorage.getItem(VISITOR_ID_STORAGE_KEY);
|
|
128
|
+
if (existing) {
|
|
129
|
+
return { visitorId: existing, isNewVisitor: false };
|
|
130
|
+
}
|
|
131
|
+
const visitorId = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `v_${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
132
|
+
localStorage.setItem(VISITOR_ID_STORAGE_KEY, visitorId);
|
|
133
|
+
return { visitorId, isNewVisitor: true };
|
|
134
|
+
} catch {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
58
138
|
|
|
59
139
|
// src/subscriptions.ts
|
|
60
140
|
var SubscriptionService = class {
|
|
@@ -567,6 +647,13 @@ var CimplifyClient = class {
|
|
|
567
647
|
if (this.sessionToken) {
|
|
568
648
|
headers[SESSION_TOKEN_HEADER] = this.sessionToken;
|
|
569
649
|
}
|
|
650
|
+
if (typeof window !== "undefined") {
|
|
651
|
+
headers["X-Storefront-Host"] = window.location.host;
|
|
652
|
+
const preview = new URLSearchParams(window.location.search).get("preview");
|
|
653
|
+
if (preview) {
|
|
654
|
+
headers["X-Storefront-Preview"] = preview;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
570
657
|
return headers;
|
|
571
658
|
}
|
|
572
659
|
async resilientFetch(url, options) {
|
|
@@ -836,6 +923,12 @@ var CimplifyClient = class {
|
|
|
836
923
|
}
|
|
837
924
|
return this._orders;
|
|
838
925
|
}
|
|
926
|
+
get storeCredit() {
|
|
927
|
+
if (!this._storeCredit) {
|
|
928
|
+
this._storeCredit = new StoreCreditQueries(this);
|
|
929
|
+
}
|
|
930
|
+
return this._storeCredit;
|
|
931
|
+
}
|
|
839
932
|
get subscriptions() {
|
|
840
933
|
if (!this._subscriptions) {
|
|
841
934
|
this._subscriptions = new SubscriptionService(this);
|
|
@@ -938,6 +1031,7 @@ exports.ActivityService = ActivityService;
|
|
|
938
1031
|
exports.CimplifyClient = CimplifyClient;
|
|
939
1032
|
exports.DeliveryService = DeliveryService;
|
|
940
1033
|
exports.PlacesService = PlacesService;
|
|
1034
|
+
exports.StoreCreditQueries = StoreCreditQueries;
|
|
941
1035
|
exports.SubscriptionService = SubscriptionService;
|
|
942
1036
|
exports.SupportService = SupportService;
|
|
943
1037
|
exports.UploadService = UploadService;
|
|
@@ -2446,6 +2446,14 @@ function buildV1(deps) {
|
|
|
2446
2446
|
const body = await c.req.json().catch(() => ({}));
|
|
2447
2447
|
return tryRoute(c, () => deps.uploads.confirm(body));
|
|
2448
2448
|
});
|
|
2449
|
+
app.get(
|
|
2450
|
+
"/store-credit/balance",
|
|
2451
|
+
(c) => c.json({ data: { balance: "0.00", currency: "USD" } })
|
|
2452
|
+
);
|
|
2453
|
+
app.post("/activity/session", async (c) => {
|
|
2454
|
+
await c.req.json().catch(() => ({}));
|
|
2455
|
+
return c.json({ data: { recorded: true } });
|
|
2456
|
+
});
|
|
2449
2457
|
app.post("/activity/events", async (c) => {
|
|
2450
2458
|
const body = await c.req.json().catch(() => ({}));
|
|
2451
2459
|
return tryRoute(c, () => deps.activity.recordEvents(deps.defaultBusinessId, c.var.session.id, body.events ?? []));
|
|
@@ -4454,17 +4462,27 @@ function recalculateTotals(opts) {
|
|
|
4454
4462
|
const lineTotal = multiply(add(item.price, item.add_ons_price), item.quantity);
|
|
4455
4463
|
subtotal = add(subtotal, lineTotal);
|
|
4456
4464
|
}
|
|
4457
|
-
const
|
|
4458
|
-
const
|
|
4459
|
-
const
|
|
4460
|
-
const
|
|
4461
|
-
const
|
|
4465
|
+
const subtotalNum = parseFloat(subtotal);
|
|
4466
|
+
const rawDiscount = opts.appliedCouponCodes.includes("WELCOME10") ? parseFloat(percent(subtotal, 10)) : 0;
|
|
4467
|
+
const cappedDiscount = Math.min(rawDiscount, subtotalNum);
|
|
4468
|
+
const taxable = Math.max(subtotalNum - cappedDiscount, 0);
|
|
4469
|
+
const service = 0;
|
|
4470
|
+
const rate2 = opts.taxRatePct / 100;
|
|
4471
|
+
let tax;
|
|
4472
|
+
let total;
|
|
4473
|
+
if (opts.taxInclusive) {
|
|
4474
|
+
tax = 0;
|
|
4475
|
+
total = subtotalNum + service - cappedDiscount;
|
|
4476
|
+
} else {
|
|
4477
|
+
tax = (taxable + service) * rate2;
|
|
4478
|
+
total = subtotalNum + service + tax - cappedDiscount;
|
|
4479
|
+
}
|
|
4462
4480
|
return {
|
|
4463
4481
|
subtotal,
|
|
4464
|
-
total_discounts:
|
|
4465
|
-
tax_amount: tax,
|
|
4466
|
-
service_charge: service,
|
|
4467
|
-
total_price: total
|
|
4482
|
+
total_discounts: money(cappedDiscount),
|
|
4483
|
+
tax_amount: money(tax),
|
|
4484
|
+
service_charge: money(service),
|
|
4485
|
+
total_price: money(total)
|
|
4468
4486
|
};
|
|
4469
4487
|
}
|
|
4470
4488
|
function computeLineKey(opts) {
|
|
@@ -4597,7 +4615,10 @@ function toUICart(registry, cart) {
|
|
|
4597
4615
|
total_price: cart.total_price,
|
|
4598
4616
|
currency: cart.currency,
|
|
4599
4617
|
tax_rate: cart.tax_rate,
|
|
4600
|
-
service_charge_rate: cart.service_charge_rate
|
|
4618
|
+
service_charge_rate: cart.service_charge_rate,
|
|
4619
|
+
tax_inclusive: false,
|
|
4620
|
+
deposit_required: false,
|
|
4621
|
+
deposit_amount: "0.00"
|
|
4601
4622
|
},
|
|
4602
4623
|
customer_info: {
|
|
4603
4624
|
name: cart.customer_name,
|
|
@@ -4616,6 +4637,7 @@ function toUICart(registry, cart) {
|
|
|
4616
4637
|
|
|
4617
4638
|
// src/mock/domain/cart/index.ts
|
|
4618
4639
|
var CART_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
4640
|
+
var TAX_RATE_PCT = 0;
|
|
4619
4641
|
var ZERO2 = "0.00";
|
|
4620
4642
|
function createCartService(opts) {
|
|
4621
4643
|
const { registry, clock, ids, bus, inventory } = opts;
|
|
@@ -4657,7 +4679,8 @@ function createCartService(opts) {
|
|
|
4657
4679
|
const recalc = (cart) => {
|
|
4658
4680
|
const totals = recalculateTotals({
|
|
4659
4681
|
items: cart.items,
|
|
4660
|
-
appliedCouponCodes: cart.applied_discount_codes
|
|
4682
|
+
appliedCouponCodes: cart.applied_discount_codes,
|
|
4683
|
+
taxRatePct: TAX_RATE_PCT});
|
|
4661
4684
|
const updated = {
|
|
4662
4685
|
...cart,
|
|
4663
4686
|
...totals,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createMockApp } from './chunk-
|
|
2
|
-
import { createCimplifyClient } from './chunk-
|
|
1
|
+
import { createMockApp } from './chunk-BNA4GW4D.mjs';
|
|
2
|
+
import { createCimplifyClient } from './chunk-LBFTEXGD.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
var cimplifyRegistry = z.registry();
|
|
@@ -480,7 +480,10 @@ var CartPricingSchema = registerSchema(
|
|
|
480
480
|
total_price: MoneySchema,
|
|
481
481
|
currency: CurrencyCodeSchema,
|
|
482
482
|
tax_rate: MoneySchema.optional(),
|
|
483
|
-
service_charge_rate: MoneySchema.optional()
|
|
483
|
+
service_charge_rate: MoneySchema.optional(),
|
|
484
|
+
tax_inclusive: z.boolean(),
|
|
485
|
+
deposit_required: z.boolean(),
|
|
486
|
+
deposit_amount: MoneySchema
|
|
484
487
|
}),
|
|
485
488
|
{
|
|
486
489
|
id: "CartPricing",
|
|
@@ -1,11 +1,77 @@
|
|
|
1
1
|
import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-3BKMNVTR.mjs';
|
|
2
2
|
import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-AMZXALF6.mjs';
|
|
3
3
|
|
|
4
|
+
// src/store-credit.ts
|
|
5
|
+
var StoreCreditQueries = class {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The shopper's available store-credit balance, in the business's default
|
|
11
|
+
* currency. Requires a signed-in customer; returns an error otherwise.
|
|
12
|
+
*/
|
|
13
|
+
async balance() {
|
|
14
|
+
return safe(this.client.get("/api/v1/store-credit/balance"));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
4
18
|
// src/activity.ts
|
|
19
|
+
var VISITOR_ID_STORAGE_KEY = "cimplify_visitor_id";
|
|
20
|
+
var SESSION_STARTED_STORAGE_KEY = "cimplify_session_started_at";
|
|
5
21
|
var ActivityService = class {
|
|
6
22
|
constructor(client) {
|
|
7
23
|
this.client = client;
|
|
8
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Record session start (landing, referrer, UTM, device). Fire-and-forget,
|
|
27
|
+
* at most once per tab session; called automatically by the track* methods.
|
|
28
|
+
*/
|
|
29
|
+
startSession() {
|
|
30
|
+
if (typeof window === "undefined") return;
|
|
31
|
+
let alreadyStarted = null;
|
|
32
|
+
try {
|
|
33
|
+
alreadyStarted = sessionStorage.getItem(SESSION_STARTED_STORAGE_KEY);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
if (alreadyStarted) return;
|
|
37
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
38
|
+
try {
|
|
39
|
+
sessionStorage.setItem(SESSION_STARTED_STORAGE_KEY, startedAt);
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
this.client.post("/api/v1/activity/session", this.buildSessionPayload(startedAt)).catch(() => {
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
buildSessionPayload(startedAt) {
|
|
46
|
+
const params = new URLSearchParams(window.location.search);
|
|
47
|
+
const utm = (key) => params.get(`utm_${key}`) || void 0;
|
|
48
|
+
const { visitorId, isNewVisitor } = resolveVisitor();
|
|
49
|
+
let timezone;
|
|
50
|
+
try {
|
|
51
|
+
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
started_at: startedAt,
|
|
56
|
+
landing_page: window.location.pathname,
|
|
57
|
+
landing_url: window.location.href,
|
|
58
|
+
referrer_url: document.referrer || void 0,
|
|
59
|
+
utm_source: utm("source"),
|
|
60
|
+
utm_medium: utm("medium"),
|
|
61
|
+
utm_campaign: utm("campaign"),
|
|
62
|
+
utm_term: utm("term"),
|
|
63
|
+
utm_content: utm("content"),
|
|
64
|
+
screen_width: window.screen?.width,
|
|
65
|
+
screen_height: window.screen?.height,
|
|
66
|
+
viewport_width: window.innerWidth,
|
|
67
|
+
viewport_height: window.innerHeight,
|
|
68
|
+
pixel_density: window.devicePixelRatio,
|
|
69
|
+
language: navigator.language,
|
|
70
|
+
timezone,
|
|
71
|
+
fingerprint: visitorId,
|
|
72
|
+
is_new_visitor: isNewVisitor
|
|
73
|
+
};
|
|
74
|
+
}
|
|
9
75
|
trackProductView(productId, options = {}) {
|
|
10
76
|
const event = {
|
|
11
77
|
type: "product_view",
|
|
@@ -43,6 +109,7 @@ var ActivityService = class {
|
|
|
43
109
|
);
|
|
44
110
|
}
|
|
45
111
|
sendEvents(events) {
|
|
112
|
+
this.startSession();
|
|
46
113
|
this.client.post("/api/v1/activity/events", { events }).catch(() => {
|
|
47
114
|
});
|
|
48
115
|
}
|
|
@@ -53,6 +120,19 @@ function currentPath() {
|
|
|
53
120
|
}
|
|
54
121
|
return void 0;
|
|
55
122
|
}
|
|
123
|
+
function resolveVisitor() {
|
|
124
|
+
try {
|
|
125
|
+
const existing = localStorage.getItem(VISITOR_ID_STORAGE_KEY);
|
|
126
|
+
if (existing) {
|
|
127
|
+
return { visitorId: existing, isNewVisitor: false };
|
|
128
|
+
}
|
|
129
|
+
const visitorId = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `v_${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
130
|
+
localStorage.setItem(VISITOR_ID_STORAGE_KEY, visitorId);
|
|
131
|
+
return { visitorId, isNewVisitor: true };
|
|
132
|
+
} catch {
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
56
136
|
|
|
57
137
|
// src/subscriptions.ts
|
|
58
138
|
var SubscriptionService = class {
|
|
@@ -565,6 +645,13 @@ var CimplifyClient = class {
|
|
|
565
645
|
if (this.sessionToken) {
|
|
566
646
|
headers[SESSION_TOKEN_HEADER] = this.sessionToken;
|
|
567
647
|
}
|
|
648
|
+
if (typeof window !== "undefined") {
|
|
649
|
+
headers["X-Storefront-Host"] = window.location.host;
|
|
650
|
+
const preview = new URLSearchParams(window.location.search).get("preview");
|
|
651
|
+
if (preview) {
|
|
652
|
+
headers["X-Storefront-Preview"] = preview;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
568
655
|
return headers;
|
|
569
656
|
}
|
|
570
657
|
async resilientFetch(url, options) {
|
|
@@ -834,6 +921,12 @@ var CimplifyClient = class {
|
|
|
834
921
|
}
|
|
835
922
|
return this._orders;
|
|
836
923
|
}
|
|
924
|
+
get storeCredit() {
|
|
925
|
+
if (!this._storeCredit) {
|
|
926
|
+
this._storeCredit = new StoreCreditQueries(this);
|
|
927
|
+
}
|
|
928
|
+
return this._storeCredit;
|
|
929
|
+
}
|
|
837
930
|
get subscriptions() {
|
|
838
931
|
if (!this._subscriptions) {
|
|
839
932
|
this._subscriptions = new SubscriptionService(this);
|
|
@@ -932,4 +1025,4 @@ function createCimplifyClient(config = {}) {
|
|
|
932
1025
|
return new CimplifyClient(config);
|
|
933
1026
|
}
|
|
934
1027
|
|
|
935
|
-
export { ActivityService, CimplifyClient, DeliveryService, PlacesService, SubscriptionService, SupportService, UploadService, createCimplifyClient };
|
|
1028
|
+
export { ActivityService, CimplifyClient, DeliveryService, PlacesService, StoreCreditQueries, SubscriptionService, SupportService, UploadService, createCimplifyClient };
|
|
@@ -2448,6 +2448,14 @@ function buildV1(deps) {
|
|
|
2448
2448
|
const body = await c.req.json().catch(() => ({}));
|
|
2449
2449
|
return tryRoute(c, () => deps.uploads.confirm(body));
|
|
2450
2450
|
});
|
|
2451
|
+
app.get(
|
|
2452
|
+
"/store-credit/balance",
|
|
2453
|
+
(c) => c.json({ data: { balance: "0.00", currency: "USD" } })
|
|
2454
|
+
);
|
|
2455
|
+
app.post("/activity/session", async (c) => {
|
|
2456
|
+
await c.req.json().catch(() => ({}));
|
|
2457
|
+
return c.json({ data: { recorded: true } });
|
|
2458
|
+
});
|
|
2451
2459
|
app.post("/activity/events", async (c) => {
|
|
2452
2460
|
const body = await c.req.json().catch(() => ({}));
|
|
2453
2461
|
return tryRoute(c, () => deps.activity.recordEvents(deps.defaultBusinessId, c.var.session.id, body.events ?? []));
|
|
@@ -4456,17 +4464,27 @@ function recalculateTotals(opts) {
|
|
|
4456
4464
|
const lineTotal = multiply(add(item.price, item.add_ons_price), item.quantity);
|
|
4457
4465
|
subtotal = add(subtotal, lineTotal);
|
|
4458
4466
|
}
|
|
4459
|
-
const
|
|
4460
|
-
const
|
|
4461
|
-
const
|
|
4462
|
-
const
|
|
4463
|
-
const
|
|
4467
|
+
const subtotalNum = parseFloat(subtotal);
|
|
4468
|
+
const rawDiscount = opts.appliedCouponCodes.includes("WELCOME10") ? parseFloat(percent(subtotal, 10)) : 0;
|
|
4469
|
+
const cappedDiscount = Math.min(rawDiscount, subtotalNum);
|
|
4470
|
+
const taxable = Math.max(subtotalNum - cappedDiscount, 0);
|
|
4471
|
+
const service = 0;
|
|
4472
|
+
const rate2 = opts.taxRatePct / 100;
|
|
4473
|
+
let tax;
|
|
4474
|
+
let total;
|
|
4475
|
+
if (opts.taxInclusive) {
|
|
4476
|
+
tax = 0;
|
|
4477
|
+
total = subtotalNum + service - cappedDiscount;
|
|
4478
|
+
} else {
|
|
4479
|
+
tax = (taxable + service) * rate2;
|
|
4480
|
+
total = subtotalNum + service + tax - cappedDiscount;
|
|
4481
|
+
}
|
|
4464
4482
|
return {
|
|
4465
4483
|
subtotal,
|
|
4466
|
-
total_discounts:
|
|
4467
|
-
tax_amount: tax,
|
|
4468
|
-
service_charge: service,
|
|
4469
|
-
total_price: total
|
|
4484
|
+
total_discounts: money(cappedDiscount),
|
|
4485
|
+
tax_amount: money(tax),
|
|
4486
|
+
service_charge: money(service),
|
|
4487
|
+
total_price: money(total)
|
|
4470
4488
|
};
|
|
4471
4489
|
}
|
|
4472
4490
|
function computeLineKey(opts) {
|
|
@@ -4599,7 +4617,10 @@ function toUICart(registry, cart) {
|
|
|
4599
4617
|
total_price: cart.total_price,
|
|
4600
4618
|
currency: cart.currency,
|
|
4601
4619
|
tax_rate: cart.tax_rate,
|
|
4602
|
-
service_charge_rate: cart.service_charge_rate
|
|
4620
|
+
service_charge_rate: cart.service_charge_rate,
|
|
4621
|
+
tax_inclusive: false,
|
|
4622
|
+
deposit_required: false,
|
|
4623
|
+
deposit_amount: "0.00"
|
|
4603
4624
|
},
|
|
4604
4625
|
customer_info: {
|
|
4605
4626
|
name: cart.customer_name,
|
|
@@ -4618,6 +4639,7 @@ function toUICart(registry, cart) {
|
|
|
4618
4639
|
|
|
4619
4640
|
// src/mock/domain/cart/index.ts
|
|
4620
4641
|
var CART_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
4642
|
+
var TAX_RATE_PCT = 0;
|
|
4621
4643
|
var ZERO2 = "0.00";
|
|
4622
4644
|
function createCartService(opts) {
|
|
4623
4645
|
const { registry, clock, ids, bus, inventory } = opts;
|
|
@@ -4659,7 +4681,8 @@ function createCartService(opts) {
|
|
|
4659
4681
|
const recalc = (cart) => {
|
|
4660
4682
|
const totals = recalculateTotals({
|
|
4661
4683
|
items: cart.items,
|
|
4662
|
-
appliedCouponCodes: cart.applied_discount_codes
|
|
4684
|
+
appliedCouponCodes: cart.applied_discount_codes,
|
|
4685
|
+
taxRatePct: TAX_RATE_PCT});
|
|
4663
4686
|
const updated = {
|
|
4664
4687
|
...cart,
|
|
4665
4688
|
...totals,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkOSTOGR4F_js = require('./chunk-OSTOGR4F.js');
|
|
4
|
+
var chunk5BPBDWAA_js = require('./chunk-5BPBDWAA.js');
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
|
|
7
7
|
var cimplifyRegistry = zod.z.registry();
|
|
@@ -482,7 +482,10 @@ var CartPricingSchema = registerSchema(
|
|
|
482
482
|
total_price: MoneySchema,
|
|
483
483
|
currency: CurrencyCodeSchema,
|
|
484
484
|
tax_rate: MoneySchema.optional(),
|
|
485
|
-
service_charge_rate: MoneySchema.optional()
|
|
485
|
+
service_charge_rate: MoneySchema.optional(),
|
|
486
|
+
tax_inclusive: zod.z.boolean(),
|
|
487
|
+
deposit_required: zod.z.boolean(),
|
|
488
|
+
deposit_amount: MoneySchema
|
|
486
489
|
}),
|
|
487
490
|
{
|
|
488
491
|
id: "CartPricing",
|
|
@@ -595,7 +598,7 @@ async function toForwardedRequest(input, init) {
|
|
|
595
598
|
};
|
|
596
599
|
}
|
|
597
600
|
function createTestClient(options = {}) {
|
|
598
|
-
const mock =
|
|
601
|
+
const mock = chunkOSTOGR4F_js.createMockApp(options);
|
|
599
602
|
let sessionToken;
|
|
600
603
|
const fetchImpl = async (input, init) => {
|
|
601
604
|
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
@@ -614,7 +617,7 @@ function createTestClient(options = {}) {
|
|
|
614
617
|
if (echoed) sessionToken = echoed;
|
|
615
618
|
return res;
|
|
616
619
|
};
|
|
617
|
-
const client =
|
|
620
|
+
const client = chunk5BPBDWAA_js.createCimplifyClient({
|
|
618
621
|
baseUrl: TEST_BASE_URL,
|
|
619
622
|
// Link mock lives at /v1/link on the same Hono app, so point the SDK's
|
|
620
623
|
// separate Link transport at the same TEST_BASE_URL.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ad as CimplifyClient } from './client-
|
|
2
|
-
import { A as AppHandle, C as CreateAppOptions } from './server-
|
|
1
|
+
import { ad as CimplifyClient } from './client-Cn5trGYV.js';
|
|
2
|
+
import { A as AppHandle, C as CreateAppOptions } from './server-Daq42vK7.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Test client + fixtures.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ad as CimplifyClient } from './client-
|
|
2
|
-
import { A as AppHandle, C as CreateAppOptions } from './server-
|
|
1
|
+
import { ad as CimplifyClient } from './client-D16qfHAB.mjs';
|
|
2
|
+
import { A as AppHandle, C as CreateAppOptions } from './server-CGO4zneR.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Test client + fixtures.
|