brainerce 2.0.2 → 2.1.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 +439 -55
- package/dist/index.d.mts +667 -165
- package/dist/index.d.ts +667 -165
- package/dist/index.js +273 -129
- package/dist/index.mjs +273 -129
- package/package.json +84 -84
package/dist/index.js
CHANGED
|
@@ -204,7 +204,7 @@ function isDevGuardsEnabled() {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
// src/version.ts
|
|
207
|
-
var SDK_VERSION = "2.0.
|
|
207
|
+
var SDK_VERSION = "2.0.3";
|
|
208
208
|
|
|
209
209
|
// src/client.ts
|
|
210
210
|
var DEFAULT_BASE_URL = "https://api.brainerce.com";
|
|
@@ -1221,6 +1221,45 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
1221
1221
|
getStoreDirection(locale) {
|
|
1222
1222
|
return getDirectionForLocale(locale ?? this.locale);
|
|
1223
1223
|
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Get what the merchant actually configured on this sales channel: store
|
|
1226
|
+
* identity and multi-language setup, the channel's own settings (low-stock
|
|
1227
|
+
* warning and threshold, reservation strategy and timeout, birthday and
|
|
1228
|
+
* email-verification requirements, granted scopes) and which optional
|
|
1229
|
+
* features are switched on (payment providers, social login, coupons,
|
|
1230
|
+
* discount rules, shipping zones, downloadables, content, loyalty).
|
|
1231
|
+
*
|
|
1232
|
+
* Read this instead of hardcoding. A storefront with a hardcoded low-stock
|
|
1233
|
+
* threshold shows the wrong badge on every store whose merchant chose a
|
|
1234
|
+
* different one, and a storefront that renders a feature nobody enabled
|
|
1235
|
+
* ships a control that silently does nothing.
|
|
1236
|
+
*
|
|
1237
|
+
* Only available in vibe-coded mode (`salesChannelId`). The payload belongs
|
|
1238
|
+
* to one sales channel: `storeId` mode has no channel to read it from, and
|
|
1239
|
+
* an `apiKey` addresses the store rather than any single channel.
|
|
1240
|
+
*
|
|
1241
|
+
* Call it once for the whole app and share the result. It is per channel,
|
|
1242
|
+
* not per product, so fetching it on every page is wasted work.
|
|
1243
|
+
*
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```typescript
|
|
1246
|
+
* const caps = await client.getStoreCapabilities();
|
|
1247
|
+
*
|
|
1248
|
+
* // Low stock: honour the switch before the number.
|
|
1249
|
+
* const threshold = caps.connection.lowStockWarning
|
|
1250
|
+
* ? caps.connection.lowStockThreshold
|
|
1251
|
+
* : 0;
|
|
1252
|
+
*
|
|
1253
|
+
* if (caps.features.hasCoupons) renderCouponInput();
|
|
1254
|
+
* if (caps.store.i18n?.enabled) renderLocaleSwitcher(caps.store.i18n.supportedLocales);
|
|
1255
|
+
* ```
|
|
1256
|
+
*/
|
|
1257
|
+
async getStoreCapabilities() {
|
|
1258
|
+
if (this.isVibeCodedMode()) {
|
|
1259
|
+
return this.vibeCodedRequest("GET", "/capabilities");
|
|
1260
|
+
}
|
|
1261
|
+
throw new BrainerceError("getStoreCapabilities is only available in vibe-coded mode", 400);
|
|
1262
|
+
}
|
|
1224
1263
|
// -------------------- Analytics --------------------
|
|
1225
1264
|
/**
|
|
1226
1265
|
* Send a storefront analytics beacon (pageview or engagement).
|
|
@@ -3048,14 +3087,20 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
3048
3087
|
});
|
|
3049
3088
|
}
|
|
3050
3089
|
/**
|
|
3051
|
-
* Get platform capabilities for coupon features.
|
|
3052
|
-
*
|
|
3090
|
+
* Get platform capabilities for coupon features, keyed by platform.
|
|
3091
|
+
*
|
|
3092
|
+
* ⛔ **Returns an empty object today.** Platform coupon capabilities moved
|
|
3093
|
+
* into the standalone connector apps and are not re-exposed here yet, so the
|
|
3094
|
+
* endpoint answers `{}` for every store. Treat a missing key as "unknown",
|
|
3095
|
+
* never as "the platform lacks the feature", and do not index into a platform
|
|
3096
|
+
* key without checking it exists first — there are none to find.
|
|
3053
3097
|
*
|
|
3054
3098
|
* @example
|
|
3055
3099
|
* ```typescript
|
|
3056
3100
|
* const capabilities = await client.getCouponPlatformCapabilities();
|
|
3057
|
-
*
|
|
3058
|
-
*
|
|
3101
|
+
* const meta = capabilities['GOOGLE'];
|
|
3102
|
+
* if (meta && !meta.supportsProducts) {
|
|
3103
|
+
* console.log('This platform cannot target individual products');
|
|
3059
3104
|
* }
|
|
3060
3105
|
* ```
|
|
3061
3106
|
*/
|
|
@@ -3181,7 +3226,7 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
3181
3226
|
);
|
|
3182
3227
|
}
|
|
3183
3228
|
console.warn(
|
|
3184
|
-
`BrainerceClient.${methodName}: passing \`storeId\` is deprecated \u2014 it is now derived from the SDK config. Remove the leading argument; this overload will be removed in
|
|
3229
|
+
`BrainerceClient.${methodName}: passing \`storeId\` is deprecated \u2014 it is now derived from the SDK config. Remove the leading argument; this overload will be removed in a future major version.`
|
|
3185
3230
|
);
|
|
3186
3231
|
}
|
|
3187
3232
|
/**
|
|
@@ -5676,6 +5721,164 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
5676
5721
|
"checkout"
|
|
5677
5722
|
);
|
|
5678
5723
|
}
|
|
5724
|
+
/**
|
|
5725
|
+
* Apply a gift card to a checkout.
|
|
5726
|
+
*
|
|
5727
|
+
* Merchants issue cards from the dashboard, so live codes exist and this field
|
|
5728
|
+
* is worth building. There is still no way for a shopper to BUY a gift card —
|
|
5729
|
+
* no product type, no purchase flow — so every card in circulation was issued
|
|
5730
|
+
* by hand.
|
|
5731
|
+
*
|
|
5732
|
+
* Redemption is deliberately NOT gated on the store's gift-card switch: a
|
|
5733
|
+
* store that turned the feature off still owes every card already in a
|
|
5734
|
+
* customer's hand, so the field keeps working. Build it unconditionally.
|
|
5735
|
+
*
|
|
5736
|
+
* A gift card is a **means of payment, not a discount**. The order total does
|
|
5737
|
+
* not change and tax stays calculated on the full value; what changes is
|
|
5738
|
+
* `providerAmountDue`, the amount the payment provider will be charged.
|
|
5739
|
+
*
|
|
5740
|
+
* Render it as its own line — "Gift card −₪54.50" beside the total — and NOT
|
|
5741
|
+
* by adding it to `discountAmount`. A shopper who sees stored value folded
|
|
5742
|
+
* into a discount is being shown the wrong thing, and so is their receipt.
|
|
5743
|
+
*
|
|
5744
|
+
* Only as much of the card as the order still owes is applied, so a card
|
|
5745
|
+
* larger than the basket leaves a balance on it for next time, and a smaller
|
|
5746
|
+
* one leaves an amount for the provider to charge.
|
|
5747
|
+
*
|
|
5748
|
+
* @example
|
|
5749
|
+
* const { amountApplied, providerAmountDue, tenderId } =
|
|
5750
|
+
* await client.applyGiftCard('checkout_123', 'A1B2-C3D4-E5F6-G7H8-J9K0');
|
|
5751
|
+
* // total is unchanged; charge the provider providerAmountDue
|
|
5752
|
+
*/
|
|
5753
|
+
async applyGiftCard(checkoutId, code) {
|
|
5754
|
+
if (this.isVibeCodedMode()) {
|
|
5755
|
+
return this.vibeCodedRequest(
|
|
5756
|
+
"POST",
|
|
5757
|
+
`/checkout/${encodePathSegment(checkoutId)}/gift-card`,
|
|
5758
|
+
{ code }
|
|
5759
|
+
);
|
|
5760
|
+
}
|
|
5761
|
+
if (this.storeId && !this.apiKey) {
|
|
5762
|
+
return this.storefrontRequest(
|
|
5763
|
+
"POST",
|
|
5764
|
+
`/checkout/${encodePathSegment(checkoutId)}/gift-card`,
|
|
5765
|
+
{ code }
|
|
5766
|
+
);
|
|
5767
|
+
}
|
|
5768
|
+
return this.adminRequest(
|
|
5769
|
+
"POST",
|
|
5770
|
+
`/api/v1/checkout/${encodePathSegment(checkoutId)}/gift-card`,
|
|
5771
|
+
{ code }
|
|
5772
|
+
);
|
|
5773
|
+
}
|
|
5774
|
+
/**
|
|
5775
|
+
* Remove a previously applied gift card from a checkout.
|
|
5776
|
+
*
|
|
5777
|
+
* Takes the `tenderId` returned by {@link applyGiftCard}, not the code — a
|
|
5778
|
+
* checkout can carry more than one card, and the code is never echoed back.
|
|
5779
|
+
*
|
|
5780
|
+
* The held value goes straight back to the card. Nothing was ever debited
|
|
5781
|
+
* while it was applied, so removing costs the shopper nothing.
|
|
5782
|
+
*/
|
|
5783
|
+
async removeGiftCard(checkoutId, tenderId) {
|
|
5784
|
+
const path = `/checkout/${encodePathSegment(checkoutId)}/gift-card/${encodePathSegment(tenderId)}`;
|
|
5785
|
+
if (this.isVibeCodedMode()) {
|
|
5786
|
+
return this.vibeCodedRequest("DELETE", path);
|
|
5787
|
+
}
|
|
5788
|
+
if (this.storeId && !this.apiKey) {
|
|
5789
|
+
return this.storefrontRequest("DELETE", path);
|
|
5790
|
+
}
|
|
5791
|
+
return this.adminRequest("DELETE", `/api/v1${path}`);
|
|
5792
|
+
}
|
|
5793
|
+
/**
|
|
5794
|
+
* Check what is left on a gift card.
|
|
5795
|
+
*
|
|
5796
|
+
* Rate limited, and deliberately uninformative: a code that does not exist,
|
|
5797
|
+
* one that has been disabled and one that has expired all return the SAME
|
|
5798
|
+
* response — `{ balance: '0.00', usable: false }` — and take the same time to
|
|
5799
|
+
* do it. Do not build UI that tries to tell those apart, because the API will
|
|
5800
|
+
* not tell you, by design: a gift-card code is bearer value, and an endpoint
|
|
5801
|
+
* that confirmed which codes were real would be a free way to find them.
|
|
5802
|
+
*
|
|
5803
|
+
* Show "we cannot use this code" and let the shopper re-enter it.
|
|
5804
|
+
*/
|
|
5805
|
+
async checkGiftCardBalance(code) {
|
|
5806
|
+
if (this.isVibeCodedMode()) {
|
|
5807
|
+
return this.vibeCodedRequest("POST", "/gift-cards/balance", { code });
|
|
5808
|
+
}
|
|
5809
|
+
if (this.storeId && !this.apiKey) {
|
|
5810
|
+
return this.storefrontRequest("POST", "/gift-cards/balance", { code });
|
|
5811
|
+
}
|
|
5812
|
+
return this.adminRequest("POST", "/api/v1/gift-cards/balance", { code });
|
|
5813
|
+
}
|
|
5814
|
+
// ==========================================================================
|
|
5815
|
+
// Donations
|
|
5816
|
+
// ==========================================================================
|
|
5817
|
+
/**
|
|
5818
|
+
* Start a donation.
|
|
5819
|
+
*
|
|
5820
|
+
* A donation does not go through the cart. There is no line item, no
|
|
5821
|
+
* quantity, no shipping and no order — a donor names an amount and pays it,
|
|
5822
|
+
* which is a different shape of transaction from a purchase. Do not model a
|
|
5823
|
+
* donation as a product; if you already have, the amount is the giveaway:
|
|
5824
|
+
* you cannot let a donor type one.
|
|
5825
|
+
*
|
|
5826
|
+
* ⛔ A successful return is NOT a completed gift. You get back a PENDING
|
|
5827
|
+
* donation and a provider intent to complete, exactly as with a checkout.
|
|
5828
|
+
* The gift is only real once the provider's webhook confirms it, which is
|
|
5829
|
+
* when the donation reads back as `PAID`. Show a thank-you that reflects
|
|
5830
|
+
* that, and never send a receipt off the back of this call.
|
|
5831
|
+
*
|
|
5832
|
+
* Requires donations to be switched on for the store; a store that has not
|
|
5833
|
+
* turned them on is rejected rather than silently accepting money.
|
|
5834
|
+
*
|
|
5835
|
+
* ```ts
|
|
5836
|
+
* const donation = await brainerce.createDonation({
|
|
5837
|
+
* amount: 180,
|
|
5838
|
+
* feeCoverAmount: 6.3, // offered as a checkbox; most donors accept
|
|
5839
|
+
* donorEmail: 'sarah@example.com',
|
|
5840
|
+
* donorName: 'Sarah Cohen',
|
|
5841
|
+
* tributeType: 'IN_MEMORY',
|
|
5842
|
+
* tributeName: 'Avraham Cohen',
|
|
5843
|
+
* returnPath: '/thank-you',
|
|
5844
|
+
* });
|
|
5845
|
+
* // → complete donation.payment with your provider, then poll getDonation()
|
|
5846
|
+
* ```
|
|
5847
|
+
*/
|
|
5848
|
+
async createDonation(input) {
|
|
5849
|
+
if (this.isVibeCodedMode()) {
|
|
5850
|
+
return this.vibeCodedRequest("POST", "/donations", input);
|
|
5851
|
+
}
|
|
5852
|
+
if (this.storeId && !this.apiKey) {
|
|
5853
|
+
return this.storefrontRequest("POST", "/donations", input);
|
|
5854
|
+
}
|
|
5855
|
+
throw new Error(
|
|
5856
|
+
"createDonation is a storefront call. Initialise the SDK with a salesChannelId or storeId \u2014 an admin apiKey cannot start a donation."
|
|
5857
|
+
);
|
|
5858
|
+
}
|
|
5859
|
+
/**
|
|
5860
|
+
* Read a donation back — for a thank-you page, and to see whether it is paid.
|
|
5861
|
+
*
|
|
5862
|
+
* Rate limited to 5 requests a minute, because an id that either resolves or
|
|
5863
|
+
* 404s is a way to enumerate them. Poll it a handful of times after the donor
|
|
5864
|
+
* returns from the provider; do not put it behind a 1-second interval.
|
|
5865
|
+
*
|
|
5866
|
+
* The payload is narrow on purpose: no failure reason, and `donorName` comes
|
|
5867
|
+
* back `null` whenever the gift was marked anonymous — so you can render this
|
|
5868
|
+
* straight onto a public page without leaking anything.
|
|
5869
|
+
*/
|
|
5870
|
+
async getDonation(donationId) {
|
|
5871
|
+
const path = `/donations/${encodePathSegment(donationId)}`;
|
|
5872
|
+
if (this.isVibeCodedMode()) {
|
|
5873
|
+
return this.vibeCodedRequest("GET", path);
|
|
5874
|
+
}
|
|
5875
|
+
if (this.storeId && !this.apiKey) {
|
|
5876
|
+
return this.storefrontRequest("GET", path);
|
|
5877
|
+
}
|
|
5878
|
+
throw new Error(
|
|
5879
|
+
"getDonation is a storefront call. Initialise the SDK with a salesChannelId or storeId."
|
|
5880
|
+
);
|
|
5881
|
+
}
|
|
5679
5882
|
/**
|
|
5680
5883
|
* Set customer information on checkout
|
|
5681
5884
|
*
|
|
@@ -8027,119 +8230,6 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
8027
8230
|
}
|
|
8028
8231
|
return this.storefrontRequest("GET", "/customers/me/cart");
|
|
8029
8232
|
}
|
|
8030
|
-
// -------------------- Custom API Integrations --------------------
|
|
8031
|
-
// These methods require Admin mode (apiKey)
|
|
8032
|
-
/**
|
|
8033
|
-
* Get all Custom API integrations for a store
|
|
8034
|
-
* Requires Admin mode (apiKey)
|
|
8035
|
-
*
|
|
8036
|
-
* @example
|
|
8037
|
-
* ```typescript
|
|
8038
|
-
* const integrations = await client.getCustomApiIntegrations();
|
|
8039
|
-
* integrations.forEach(api => {
|
|
8040
|
-
* console.log(`${api.name}: ${api.status}`);
|
|
8041
|
-
* });
|
|
8042
|
-
* ```
|
|
8043
|
-
*/
|
|
8044
|
-
async getCustomApiIntegrations() {
|
|
8045
|
-
return this.adminRequest("GET", "/api/v1/custom-api");
|
|
8046
|
-
}
|
|
8047
|
-
/**
|
|
8048
|
-
* Get a single Custom API integration by ID
|
|
8049
|
-
* Requires Admin mode (apiKey)
|
|
8050
|
-
*
|
|
8051
|
-
* @example
|
|
8052
|
-
* ```typescript
|
|
8053
|
-
* const api = await client.getCustomApiIntegration('api_123');
|
|
8054
|
-
* console.log(`API: ${api.name}, URL: ${api.baseUrl}`);
|
|
8055
|
-
* ```
|
|
8056
|
-
*/
|
|
8057
|
-
async getCustomApiIntegration(integrationId) {
|
|
8058
|
-
return this.adminRequest(
|
|
8059
|
-
"GET",
|
|
8060
|
-
`/api/v1/custom-api/${encodePathSegment(integrationId)}`
|
|
8061
|
-
);
|
|
8062
|
-
}
|
|
8063
|
-
/**
|
|
8064
|
-
* Create a new Custom API integration
|
|
8065
|
-
* Requires Admin mode (apiKey)
|
|
8066
|
-
*
|
|
8067
|
-
* @example
|
|
8068
|
-
* ```typescript
|
|
8069
|
-
* const api = await client.createCustomApiIntegration({
|
|
8070
|
-
* name: 'My External API',
|
|
8071
|
-
* baseUrl: 'https://api.example.com',
|
|
8072
|
-
* authType: 'api_key',
|
|
8073
|
-
* credentials: {
|
|
8074
|
-
* apiKey: 'sk_123...',
|
|
8075
|
-
* headerName: 'X-API-Key',
|
|
8076
|
-
* },
|
|
8077
|
-
* syncDirection: 'bidirectional',
|
|
8078
|
-
* syncConfig: {
|
|
8079
|
-
* products: true,
|
|
8080
|
-
* orders: true,
|
|
8081
|
-
* inventory: true,
|
|
8082
|
-
* },
|
|
8083
|
-
* });
|
|
8084
|
-
* ```
|
|
8085
|
-
*/
|
|
8086
|
-
async createCustomApiIntegration(data) {
|
|
8087
|
-
return this.adminRequest("POST", "/api/v1/custom-api", data);
|
|
8088
|
-
}
|
|
8089
|
-
/**
|
|
8090
|
-
* Update a Custom API integration
|
|
8091
|
-
* Requires Admin mode (apiKey)
|
|
8092
|
-
*
|
|
8093
|
-
* @example
|
|
8094
|
-
* ```typescript
|
|
8095
|
-
* const api = await client.updateCustomApiIntegration('api_123', {
|
|
8096
|
-
* enabled: false,
|
|
8097
|
-
* syncConfig: { products: true, orders: false, inventory: true },
|
|
8098
|
-
* });
|
|
8099
|
-
* ```
|
|
8100
|
-
*/
|
|
8101
|
-
async updateCustomApiIntegration(integrationId, data) {
|
|
8102
|
-
return this.adminRequest(
|
|
8103
|
-
"PATCH",
|
|
8104
|
-
`/api/v1/custom-api/${encodePathSegment(integrationId)}`,
|
|
8105
|
-
data
|
|
8106
|
-
);
|
|
8107
|
-
}
|
|
8108
|
-
/**
|
|
8109
|
-
* Delete a Custom API integration
|
|
8110
|
-
* Requires Admin mode (apiKey)
|
|
8111
|
-
*
|
|
8112
|
-
* @example
|
|
8113
|
-
* ```typescript
|
|
8114
|
-
* await client.deleteCustomApiIntegration('api_123');
|
|
8115
|
-
* ```
|
|
8116
|
-
*/
|
|
8117
|
-
async deleteCustomApiIntegration(integrationId) {
|
|
8118
|
-
await this.adminRequest(
|
|
8119
|
-
"DELETE",
|
|
8120
|
-
`/api/v1/custom-api/${encodePathSegment(integrationId)}`
|
|
8121
|
-
);
|
|
8122
|
-
}
|
|
8123
|
-
/**
|
|
8124
|
-
* Test connection to a Custom API
|
|
8125
|
-
* Requires Admin mode (apiKey)
|
|
8126
|
-
*
|
|
8127
|
-
* @example
|
|
8128
|
-
* ```typescript
|
|
8129
|
-
* const result = await client.testCustomApiConnection('api_123');
|
|
8130
|
-
* if (result.success) {
|
|
8131
|
-
* console.log(`Connection OK, latency: ${result.latency}ms`);
|
|
8132
|
-
* } else {
|
|
8133
|
-
* console.error(`Connection failed: ${result.error}`);
|
|
8134
|
-
* }
|
|
8135
|
-
* ```
|
|
8136
|
-
*/
|
|
8137
|
-
async testCustomApiConnection(integrationId) {
|
|
8138
|
-
return this.adminRequest(
|
|
8139
|
-
"POST",
|
|
8140
|
-
`/api/v1/custom-api/${encodePathSegment(integrationId)}/test`
|
|
8141
|
-
);
|
|
8142
|
-
}
|
|
8143
8233
|
// -------------------- Inventory Reservations --------------------
|
|
8144
8234
|
// These methods are only available in vibe-coded mode when reservation strategy
|
|
8145
8235
|
// is set to ON_CART or ON_CHECKOUT
|
|
@@ -8779,12 +8869,18 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
8779
8869
|
* ```typescript
|
|
8780
8870
|
* const rate = await client.createZoneShippingRate('zone_123', {
|
|
8781
8871
|
* name: 'Standard Shipping',
|
|
8782
|
-
* type: '
|
|
8783
|
-
*
|
|
8784
|
-
*
|
|
8785
|
-
*
|
|
8872
|
+
* type: 'FLAT_RATE',
|
|
8873
|
+
* rateConfig: { amount: 5.99 },
|
|
8874
|
+
* minDeliveryDays: 3,
|
|
8875
|
+
* maxDeliveryDays: 5,
|
|
8786
8876
|
* });
|
|
8787
8877
|
* ```
|
|
8878
|
+
*
|
|
8879
|
+
* The price lives in `rateConfig`, whose shape follows `type` — `FLAT_RATE`
|
|
8880
|
+
* takes `{ amount }`, `WEIGHT_BASED` and `PRICE_BASED` take tier arrays, and
|
|
8881
|
+
* `FREE` and `LOCAL_PICKUP` take none. Unknown top-level properties are
|
|
8882
|
+
* rejected outright rather than ignored, so a stray `price` or
|
|
8883
|
+
* `estimatedDays` fails the whole call with 400.
|
|
8788
8884
|
*/
|
|
8789
8885
|
async createZoneShippingRate(zoneId, data) {
|
|
8790
8886
|
return this.adminRequest(
|
|
@@ -8985,6 +9081,10 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
8985
9081
|
*
|
|
8986
9082
|
* Returns `appliesTax=false` when tax is disabled, the country is missing,
|
|
8987
9083
|
* or no active rate covers it.
|
|
9084
|
+
*
|
|
9085
|
+
* The preview has no province, so it only sees country-level rates: a
|
|
9086
|
+
* Canadian estimate shows the federal GST alone and the provincial PST/QST
|
|
9087
|
+
* joins it at checkout. Render `note` so the buyer is not surprised.
|
|
8988
9088
|
*/
|
|
8989
9089
|
async estimateTax(params) {
|
|
8990
9090
|
const query = params.country ? { country: params.country, subtotal: params.subtotal } : { subtotal: params.subtotal };
|
|
@@ -9055,10 +9155,46 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
9055
9155
|
/**
|
|
9056
9156
|
* Get all tax rates for the store
|
|
9057
9157
|
* Requires Admin mode (apiKey)
|
|
9158
|
+
*
|
|
9159
|
+
* A jurisdiction can need more than one rate. Canada is the common case: a
|
|
9160
|
+
* country-level `GST` row plus a province-level `PST`/`QST` row, both with
|
|
9161
|
+
* `stackable: true`, which the checkout charges together. Provinces on HST
|
|
9162
|
+
* carry a single combined row with `stackable: false`.
|
|
9058
9163
|
*/
|
|
9059
9164
|
async getTaxRates() {
|
|
9060
9165
|
return this.adminRequest("GET", "/api/v1/tax/rates");
|
|
9061
9166
|
}
|
|
9167
|
+
/**
|
|
9168
|
+
* List the country tax presets available to apply.
|
|
9169
|
+
* Requires Admin mode (apiKey)
|
|
9170
|
+
*/
|
|
9171
|
+
async getTaxPresets() {
|
|
9172
|
+
return this.adminRequest("GET", "/api/v1/tax/presets");
|
|
9173
|
+
}
|
|
9174
|
+
/**
|
|
9175
|
+
* Apply a country's whole tax table in one call, instead of creating a rate
|
|
9176
|
+
* per province by hand. Requires Admin mode (apiKey).
|
|
9177
|
+
*
|
|
9178
|
+
* `CA` writes ten rates: federal GST 5% country-wide, one combined HST row
|
|
9179
|
+
* each for ON/NB/NL/NS/PE, and PST/RST/QST for BC/SK/MB/QC charged on top of
|
|
9180
|
+
* the GST. Alberta and the territories need no row — the GST covers them.
|
|
9181
|
+
*
|
|
9182
|
+
* Throws 409 when the store already has rates for that country; delete those
|
|
9183
|
+
* first if you meant to replace them. Rates land in the Standard tax class.
|
|
9184
|
+
*
|
|
9185
|
+
* Brainerce does not register the store for GST/HST and does not file returns.
|
|
9186
|
+
*
|
|
9187
|
+
* @example
|
|
9188
|
+
* ```typescript
|
|
9189
|
+
* const { created } = await client.applyTaxPreset('CA'); // created === 10
|
|
9190
|
+
* ```
|
|
9191
|
+
*/
|
|
9192
|
+
async applyTaxPreset(presetKey) {
|
|
9193
|
+
return this.adminRequest(
|
|
9194
|
+
"POST",
|
|
9195
|
+
`/api/v1/tax/presets/${encodePathSegment(presetKey)}/apply`
|
|
9196
|
+
);
|
|
9197
|
+
}
|
|
9062
9198
|
/**
|
|
9063
9199
|
* Get a single tax rate by ID
|
|
9064
9200
|
* Requires Admin mode (apiKey)
|
|
@@ -10486,9 +10622,7 @@ function validateDateAvailabilityConfig(config, fieldType, surface = "checkout")
|
|
|
10486
10622
|
(k) => config[k] !== void 0
|
|
10487
10623
|
);
|
|
10488
10624
|
if (relativeKeys.length > 0) {
|
|
10489
|
-
errors.push(
|
|
10490
|
-
`${relativeKeys.join("/")} only apply to checkout fields, not ${surface} fields`
|
|
10491
|
-
);
|
|
10625
|
+
errors.push(`${relativeKeys.join("/")} only apply to checkout fields, not ${surface} fields`);
|
|
10492
10626
|
}
|
|
10493
10627
|
}
|
|
10494
10628
|
if (config.blockedWeekdays) {
|
|
@@ -10511,7 +10645,9 @@ function validateDateAvailabilityConfig(config, fieldType, surface = "checkout")
|
|
|
10511
10645
|
const windowsByWeekday = /* @__PURE__ */ new Map();
|
|
10512
10646
|
for (const w of config.businessHours) {
|
|
10513
10647
|
if (!Number.isInteger(w.weekday) || w.weekday < 0 || w.weekday > 6) {
|
|
10514
|
-
errors.push(
|
|
10648
|
+
errors.push(
|
|
10649
|
+
`businessHours.weekday must be an integer 0-6, got ${JSON.stringify(w.weekday)}`
|
|
10650
|
+
);
|
|
10515
10651
|
continue;
|
|
10516
10652
|
}
|
|
10517
10653
|
const openValid = TIME_RE.test(w.open);
|
|
@@ -10623,7 +10759,8 @@ function addCalendarDays(dateYYYYMMDD, days) {
|
|
|
10623
10759
|
function parseDateFieldValue(raw, fieldType, timezone) {
|
|
10624
10760
|
const str = raw instanceof Date ? Number.isNaN(raw.getTime()) ? "" : raw.toISOString() : typeof raw === "string" ? raw.trim() : "";
|
|
10625
10761
|
const expected = fieldType === "DATE" ? "expected a calendar date in YYYY-MM-DD format" : "expected an ISO-8601 date/time such as 2026-08-13T13:00:00+03:00";
|
|
10626
|
-
if (!str)
|
|
10762
|
+
if (!str)
|
|
10763
|
+
return { status: "invalid", reason: `"${String(raw)}" is not a valid date \u2014 ${expected}` };
|
|
10627
10764
|
const dateOnly = DATE_ONLY_RE.exec(str);
|
|
10628
10765
|
const dateTime = dateOnly ? null : DATE_TIME_RE.exec(str);
|
|
10629
10766
|
const match = dateOnly ?? dateTime;
|
|
@@ -10712,7 +10849,14 @@ function timezoneOffsetMs(utcMillis, timezone) {
|
|
|
10712
10849
|
}
|
|
10713
10850
|
const get = (type) => Number(parts.find((p) => p.type === type)?.value ?? "0");
|
|
10714
10851
|
const hour = get("hour") === 24 ? 0 : get("hour");
|
|
10715
|
-
const asIfUtc = Date.UTC(
|
|
10852
|
+
const asIfUtc = Date.UTC(
|
|
10853
|
+
get("year"),
|
|
10854
|
+
get("month") - 1,
|
|
10855
|
+
get("day"),
|
|
10856
|
+
hour,
|
|
10857
|
+
get("minute"),
|
|
10858
|
+
get("second")
|
|
10859
|
+
);
|
|
10716
10860
|
return asIfUtc - Math.floor(utcMillis / 1e3) * 1e3;
|
|
10717
10861
|
}
|
|
10718
10862
|
function isCalendarDateAllowed(dateYYYYMMDD, config, clock) {
|