@teleporthq/teleport-plugin-next-workflows 0.43.65 → 0.43.67
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/__tests__/_helpers/bind-workflow-utils.ts +30 -0
- package/__tests__/_helpers/run-generated-middleware.ts +11 -2
- package/__tests__/admin-form-row-hydration.test.ts +55 -0
- package/__tests__/cart-clear-db-mirror.test.ts +12 -0
- package/__tests__/cart-get-total-regional-pricing.test.ts +166 -0
- package/__tests__/client-config-redaction.test.ts +53 -0
- package/__tests__/continue-on-error.test.ts +119 -0
- package/__tests__/email-locale-module.test.ts +323 -0
- package/__tests__/email-locale-senders.test.ts +268 -0
- package/__tests__/invoice-delivery-fee.test.ts +104 -0
- package/__tests__/invoice-regional-tax.test.ts +126 -0
- package/__tests__/locale-aware-redirects.test.ts +355 -0
- package/__tests__/navigation-go-to-page.test.ts +43 -0
- package/__tests__/node-handler-file-inline-map.test.ts +29 -3
- package/__tests__/payment-redirect-and-order-notification.test.ts +6 -0
- package/__tests__/paypal-webhook-order-notification.test.ts +41 -0
- package/__tests__/resolve-config-localized-templates.test.ts +262 -0
- package/__tests__/sent-email-log-module.test.ts +381 -0
- package/__tests__/sent-email-log-wiring.test.ts +267 -0
- package/dist/cjs/account-delete-route-generator.d.ts +20 -0
- package/dist/cjs/account-delete-route-generator.d.ts.map +1 -1
- package/dist/cjs/account-delete-route-generator.js +29 -26
- package/dist/cjs/account-delete-route-generator.js.map +1 -1
- package/dist/cjs/api-route-generator.d.ts.map +1 -1
- package/dist/cjs/api-route-generator.js +57 -11
- package/dist/cjs/api-route-generator.js.map +1 -1
- package/dist/cjs/auth-generator.d.ts +2 -1
- package/dist/cjs/auth-generator.d.ts.map +1 -1
- package/dist/cjs/auth-generator.js +55 -18
- package/dist/cjs/auth-generator.js.map +1 -1
- package/dist/cjs/data-api-route-generator.d.ts.map +1 -1
- package/dist/cjs/data-api-route-generator.js +19 -0
- package/dist/cjs/data-api-route-generator.js.map +1 -1
- package/dist/cjs/email-locale/email-locale-code.d.ts +25 -0
- package/dist/cjs/email-locale/email-locale-code.d.ts.map +1 -0
- package/dist/cjs/email-locale/email-locale-code.js +228 -0
- package/dist/cjs/email-locale/email-locale-code.js.map +1 -0
- package/dist/cjs/email-locale/email-locale-scope.d.ts +46 -0
- package/dist/cjs/email-locale/email-locale-scope.d.ts.map +1 -0
- package/dist/cjs/email-locale/email-locale-scope.js +51 -0
- package/dist/cjs/email-locale/email-locale-scope.js.map +1 -0
- package/dist/cjs/email-locale/index.d.ts +11 -0
- package/dist/cjs/email-locale/index.d.ts.map +1 -0
- package/dist/cjs/email-locale/index.js +40 -0
- package/dist/cjs/email-locale/index.js.map +1 -0
- package/dist/cjs/executor-generator.d.ts +11 -1
- package/dist/cjs/executor-generator.d.ts.map +1 -1
- package/dist/cjs/executor-generator.js +49 -7
- package/dist/cjs/executor-generator.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/invoice/api-routes-code.d.ts.map +1 -1
- package/dist/cjs/invoice/api-routes-code.js +55 -6
- package/dist/cjs/invoice/api-routes-code.js.map +1 -1
- package/dist/cjs/invoice/email-sender-code.d.ts.map +1 -1
- package/dist/cjs/invoice/email-sender-code.js +72 -31
- package/dist/cjs/invoice/email-sender-code.js.map +1 -1
- package/dist/cjs/invoice/index.d.ts +1 -4
- package/dist/cjs/invoice/index.d.ts.map +1 -1
- package/dist/cjs/invoice/index.js +8 -19
- package/dist/cjs/invoice/index.js.map +1 -1
- package/dist/cjs/invoice/invoice-html-code.d.ts.map +1 -1
- package/dist/cjs/invoice/invoice-html-code.js +31 -8
- package/dist/cjs/invoice/invoice-html-code.js.map +1 -1
- package/dist/cjs/invoice/regional-invoice-tax-code.d.ts +25 -0
- package/dist/cjs/invoice/regional-invoice-tax-code.d.ts.map +1 -0
- package/dist/cjs/invoice/regional-invoice-tax-code.js +116 -0
- package/dist/cjs/invoice/regional-invoice-tax-code.js.map +1 -0
- package/dist/cjs/invoice/resolve-data-source.d.ts +6 -0
- package/dist/cjs/invoice/resolve-data-source.d.ts.map +1 -0
- package/dist/cjs/invoice/resolve-data-source.js +23 -0
- package/dist/cjs/invoice/resolve-data-source.js.map +1 -0
- package/dist/cjs/nodes/account/account-delete-current.d.ts.map +1 -1
- package/dist/cjs/nodes/account/account-delete-current.js +10 -3
- package/dist/cjs/nodes/account/account-delete-current.js.map +1 -1
- package/dist/cjs/nodes/account/account-login.d.ts.map +1 -1
- package/dist/cjs/nodes/account/account-login.js +3 -1
- package/dist/cjs/nodes/account/account-login.js.map +1 -1
- package/dist/cjs/nodes/account/account-logout.d.ts.map +1 -1
- package/dist/cjs/nodes/account/account-logout.js +4 -2
- package/dist/cjs/nodes/account/account-logout.js.map +1 -1
- package/dist/cjs/nodes/account/account-signup.d.ts.map +1 -1
- package/dist/cjs/nodes/account/account-signup.js +12 -2
- package/dist/cjs/nodes/account/account-signup.js.map +1 -1
- package/dist/cjs/nodes/account/account-social-login.d.ts.map +1 -1
- package/dist/cjs/nodes/account/account-social-login.js +4 -2
- package/dist/cjs/nodes/account/account-social-login.js.map +1 -1
- package/dist/cjs/nodes/cart/cart-clear.d.ts.map +1 -1
- package/dist/cjs/nodes/cart/cart-clear.js +6 -0
- package/dist/cjs/nodes/cart/cart-clear.js.map +1 -1
- package/dist/cjs/nodes/cart/cart-get-total.d.ts.map +1 -1
- package/dist/cjs/nodes/cart/cart-get-total.js +81 -5
- package/dist/cjs/nodes/cart/cart-get-total.js.map +1 -1
- package/dist/cjs/nodes/data/data-create-item.d.ts.map +1 -1
- package/dist/cjs/nodes/data/data-create-item.js +16 -0
- package/dist/cjs/nodes/data/data-create-item.js.map +1 -1
- package/dist/cjs/nodes/ecommerce/ecommerce-generate-invoice.d.ts.map +1 -1
- package/dist/cjs/nodes/ecommerce/ecommerce-generate-invoice.js +6 -0
- package/dist/cjs/nodes/ecommerce/ecommerce-generate-invoice.js.map +1 -1
- package/dist/cjs/nodes/navigation/navigation-go-to-page.d.ts.map +1 -1
- package/dist/cjs/nodes/navigation/navigation-go-to-page.js +4 -1
- package/dist/cjs/nodes/navigation/navigation-go-to-page.js.map +1 -1
- package/dist/cjs/nodes/navigation/navigation-navigate-to-url.d.ts.map +1 -1
- package/dist/cjs/nodes/navigation/navigation-navigate-to-url.js +5 -2
- package/dist/cjs/nodes/navigation/navigation-navigate-to-url.js.map +1 -1
- package/dist/cjs/nodes/payment/payment-charge-user.d.ts.map +1 -1
- package/dist/cjs/nodes/payment/payment-charge-user.js +7 -2
- package/dist/cjs/nodes/payment/payment-charge-user.js.map +1 -1
- package/dist/cjs/segment-splitter.d.ts +1 -1
- package/dist/cjs/segment-splitter.d.ts.map +1 -1
- package/dist/cjs/segment-splitter.js +29 -2
- package/dist/cjs/segment-splitter.js.map +1 -1
- package/dist/cjs/sent-email-log/index.d.ts +16 -0
- package/dist/cjs/sent-email-log/index.d.ts.map +1 -0
- package/dist/cjs/sent-email-log/index.js +53 -0
- package/dist/cjs/sent-email-log/index.js.map +1 -0
- package/dist/cjs/sent-email-log/sent-email-log-code.d.ts +4 -0
- package/dist/cjs/sent-email-log/sent-email-log-code.d.ts.map +1 -0
- package/dist/cjs/sent-email-log/sent-email-log-code.js +415 -0
- package/dist/cjs/sent-email-log/sent-email-log-code.js.map +1 -0
- package/dist/cjs/sent-email-log/sent-email-log-scope.d.ts +21 -0
- package/dist/cjs/sent-email-log/sent-email-log-scope.d.ts.map +1 -0
- package/dist/cjs/sent-email-log/sent-email-log-scope.js +36 -0
- package/dist/cjs/sent-email-log/sent-email-log-scope.js.map +1 -0
- package/dist/cjs/transactional-email-code.d.ts +39 -1
- package/dist/cjs/transactional-email-code.d.ts.map +1 -1
- package/dist/cjs/transactional-email-code.js +86 -12
- package/dist/cjs/transactional-email-code.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/webhook-generator.d.ts.map +1 -1
- package/dist/cjs/webhook-generator.js +9 -2
- package/dist/cjs/webhook-generator.js.map +1 -1
- package/dist/cjs/workflow-component-plugin.js +4 -3
- package/dist/cjs/workflow-component-plugin.js.map +1 -1
- package/dist/cjs/workflow-project-plugin.d.ts.map +1 -1
- package/dist/cjs/workflow-project-plugin.js +31 -3
- package/dist/cjs/workflow-project-plugin.js.map +1 -1
- package/dist/cjs/workflow-utils-alias.d.ts +21 -0
- package/dist/cjs/workflow-utils-alias.d.ts.map +1 -0
- package/dist/cjs/workflow-utils-alias.js +27 -0
- package/dist/cjs/workflow-utils-alias.js.map +1 -0
- package/dist/esm/account-delete-route-generator.d.ts +20 -0
- package/dist/esm/account-delete-route-generator.d.ts.map +1 -1
- package/dist/esm/account-delete-route-generator.js +30 -27
- package/dist/esm/account-delete-route-generator.js.map +1 -1
- package/dist/esm/api-route-generator.d.ts.map +1 -1
- package/dist/esm/api-route-generator.js +57 -11
- package/dist/esm/api-route-generator.js.map +1 -1
- package/dist/esm/auth-generator.d.ts +2 -1
- package/dist/esm/auth-generator.d.ts.map +1 -1
- package/dist/esm/auth-generator.js +56 -19
- package/dist/esm/auth-generator.js.map +1 -1
- package/dist/esm/data-api-route-generator.d.ts.map +1 -1
- package/dist/esm/data-api-route-generator.js +19 -0
- package/dist/esm/data-api-route-generator.js.map +1 -1
- package/dist/esm/email-locale/email-locale-code.d.ts +25 -0
- package/dist/esm/email-locale/email-locale-code.d.ts.map +1 -0
- package/dist/esm/email-locale/email-locale-code.js +222 -0
- package/dist/esm/email-locale/email-locale-code.js.map +1 -0
- package/dist/esm/email-locale/email-locale-scope.d.ts +46 -0
- package/dist/esm/email-locale/email-locale-scope.d.ts.map +1 -0
- package/dist/esm/email-locale/email-locale-scope.js +47 -0
- package/dist/esm/email-locale/email-locale-scope.js.map +1 -0
- package/dist/esm/email-locale/index.d.ts +11 -0
- package/dist/esm/email-locale/index.d.ts.map +1 -0
- package/dist/esm/email-locale/index.js +28 -0
- package/dist/esm/email-locale/index.js.map +1 -0
- package/dist/esm/executor-generator.d.ts +11 -1
- package/dist/esm/executor-generator.d.ts.map +1 -1
- package/dist/esm/executor-generator.js +49 -7
- package/dist/esm/executor-generator.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/invoice/api-routes-code.d.ts.map +1 -1
- package/dist/esm/invoice/api-routes-code.js +55 -6
- package/dist/esm/invoice/api-routes-code.js.map +1 -1
- package/dist/esm/invoice/email-sender-code.d.ts.map +1 -1
- package/dist/esm/invoice/email-sender-code.js +72 -31
- package/dist/esm/invoice/email-sender-code.js.map +1 -1
- package/dist/esm/invoice/index.d.ts +1 -4
- package/dist/esm/invoice/index.d.ts.map +1 -1
- package/dist/esm/invoice/index.js +7 -18
- package/dist/esm/invoice/index.js.map +1 -1
- package/dist/esm/invoice/invoice-html-code.d.ts.map +1 -1
- package/dist/esm/invoice/invoice-html-code.js +31 -8
- package/dist/esm/invoice/invoice-html-code.js.map +1 -1
- package/dist/esm/invoice/regional-invoice-tax-code.d.ts +25 -0
- package/dist/esm/invoice/regional-invoice-tax-code.d.ts.map +1 -0
- package/dist/esm/invoice/regional-invoice-tax-code.js +113 -0
- package/dist/esm/invoice/regional-invoice-tax-code.js.map +1 -0
- package/dist/esm/invoice/resolve-data-source.d.ts +6 -0
- package/dist/esm/invoice/resolve-data-source.d.ts.map +1 -0
- package/dist/esm/invoice/resolve-data-source.js +19 -0
- package/dist/esm/invoice/resolve-data-source.js.map +1 -0
- package/dist/esm/nodes/account/account-delete-current.d.ts.map +1 -1
- package/dist/esm/nodes/account/account-delete-current.js +10 -3
- package/dist/esm/nodes/account/account-delete-current.js.map +1 -1
- package/dist/esm/nodes/account/account-login.d.ts.map +1 -1
- package/dist/esm/nodes/account/account-login.js +3 -1
- package/dist/esm/nodes/account/account-login.js.map +1 -1
- package/dist/esm/nodes/account/account-logout.d.ts.map +1 -1
- package/dist/esm/nodes/account/account-logout.js +4 -2
- package/dist/esm/nodes/account/account-logout.js.map +1 -1
- package/dist/esm/nodes/account/account-signup.d.ts.map +1 -1
- package/dist/esm/nodes/account/account-signup.js +12 -2
- package/dist/esm/nodes/account/account-signup.js.map +1 -1
- package/dist/esm/nodes/account/account-social-login.d.ts.map +1 -1
- package/dist/esm/nodes/account/account-social-login.js +4 -2
- package/dist/esm/nodes/account/account-social-login.js.map +1 -1
- package/dist/esm/nodes/cart/cart-clear.d.ts.map +1 -1
- package/dist/esm/nodes/cart/cart-clear.js +6 -0
- package/dist/esm/nodes/cart/cart-clear.js.map +1 -1
- package/dist/esm/nodes/cart/cart-get-total.d.ts.map +1 -1
- package/dist/esm/nodes/cart/cart-get-total.js +81 -5
- package/dist/esm/nodes/cart/cart-get-total.js.map +1 -1
- package/dist/esm/nodes/data/data-create-item.d.ts.map +1 -1
- package/dist/esm/nodes/data/data-create-item.js +16 -0
- package/dist/esm/nodes/data/data-create-item.js.map +1 -1
- package/dist/esm/nodes/ecommerce/ecommerce-generate-invoice.d.ts.map +1 -1
- package/dist/esm/nodes/ecommerce/ecommerce-generate-invoice.js +6 -0
- package/dist/esm/nodes/ecommerce/ecommerce-generate-invoice.js.map +1 -1
- package/dist/esm/nodes/navigation/navigation-go-to-page.d.ts.map +1 -1
- package/dist/esm/nodes/navigation/navigation-go-to-page.js +4 -1
- package/dist/esm/nodes/navigation/navigation-go-to-page.js.map +1 -1
- package/dist/esm/nodes/navigation/navigation-navigate-to-url.d.ts.map +1 -1
- package/dist/esm/nodes/navigation/navigation-navigate-to-url.js +5 -2
- package/dist/esm/nodes/navigation/navigation-navigate-to-url.js.map +1 -1
- package/dist/esm/nodes/payment/payment-charge-user.d.ts.map +1 -1
- package/dist/esm/nodes/payment/payment-charge-user.js +7 -2
- package/dist/esm/nodes/payment/payment-charge-user.js.map +1 -1
- package/dist/esm/segment-splitter.d.ts +1 -1
- package/dist/esm/segment-splitter.d.ts.map +1 -1
- package/dist/esm/segment-splitter.js +29 -2
- package/dist/esm/segment-splitter.js.map +1 -1
- package/dist/esm/sent-email-log/index.d.ts +16 -0
- package/dist/esm/sent-email-log/index.d.ts.map +1 -0
- package/dist/esm/sent-email-log/index.js +45 -0
- package/dist/esm/sent-email-log/index.js.map +1 -0
- package/dist/esm/sent-email-log/sent-email-log-code.d.ts +4 -0
- package/dist/esm/sent-email-log/sent-email-log-code.d.ts.map +1 -0
- package/dist/esm/sent-email-log/sent-email-log-code.js +411 -0
- package/dist/esm/sent-email-log/sent-email-log-code.js.map +1 -0
- package/dist/esm/sent-email-log/sent-email-log-scope.d.ts +21 -0
- package/dist/esm/sent-email-log/sent-email-log-scope.d.ts.map +1 -0
- package/dist/esm/sent-email-log/sent-email-log-scope.js +31 -0
- package/dist/esm/sent-email-log/sent-email-log-scope.js.map +1 -0
- package/dist/esm/transactional-email-code.d.ts +39 -1
- package/dist/esm/transactional-email-code.d.ts.map +1 -1
- package/dist/esm/transactional-email-code.js +81 -10
- package/dist/esm/transactional-email-code.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/webhook-generator.d.ts.map +1 -1
- package/dist/esm/webhook-generator.js +9 -2
- package/dist/esm/webhook-generator.js.map +1 -1
- package/dist/esm/workflow-component-plugin.js +4 -3
- package/dist/esm/workflow-component-plugin.js.map +1 -1
- package/dist/esm/workflow-project-plugin.d.ts.map +1 -1
- package/dist/esm/workflow-project-plugin.js +32 -4
- package/dist/esm/workflow-project-plugin.js.map +1 -1
- package/dist/esm/workflow-utils-alias.d.ts +21 -0
- package/dist/esm/workflow-utils-alias.d.ts.map +1 -0
- package/dist/esm/workflow-utils-alias.js +21 -0
- package/dist/esm/workflow-utils-alias.js.map +1 -0
- package/package.json +4 -4
- package/src/account-delete-route-generator.ts +36 -7
- package/src/api-route-generator.ts +64 -11
- package/src/auth-generator.ts +63 -18
- package/src/data-api-route-generator.ts +19 -0
- package/src/email-locale/email-locale-code.ts +239 -0
- package/src/email-locale/email-locale-scope.ts +65 -0
- package/src/email-locale/index.ts +46 -0
- package/src/executor-generator.ts +65 -7
- package/src/index.ts +8 -0
- package/src/invoice/api-routes-code.ts +65 -6
- package/src/invoice/email-sender-code.ts +72 -31
- package/src/invoice/index.ts +7 -23
- package/src/invoice/invoice-html-code.ts +31 -8
- package/src/invoice/regional-invoice-tax-code.ts +112 -0
- package/src/invoice/resolve-data-source.ts +25 -0
- package/src/nodes/account/account-delete-current.ts +10 -3
- package/src/nodes/account/account-login.ts +3 -1
- package/src/nodes/account/account-logout.ts +4 -2
- package/src/nodes/account/account-signup.ts +12 -2
- package/src/nodes/account/account-social-login.ts +7 -2
- package/src/nodes/cart/cart-clear.ts +6 -0
- package/src/nodes/cart/cart-get-total.ts +94 -5
- package/src/nodes/data/data-create-item.ts +16 -0
- package/src/nodes/ecommerce/ecommerce-generate-invoice.ts +6 -0
- package/src/nodes/navigation/navigation-go-to-page.ts +5 -1
- package/src/nodes/navigation/navigation-navigate-to-url.ts +6 -2
- package/src/nodes/payment/payment-charge-user.ts +13 -2
- package/src/nodes/workflow-utils-global.d.ts +12 -0
- package/src/segment-splitter.ts +33 -2
- package/src/sent-email-log/index.ts +57 -0
- package/src/sent-email-log/sent-email-log-code.ts +419 -0
- package/src/sent-email-log/sent-email-log-scope.ts +36 -0
- package/src/transactional-email-code.ts +112 -4
- package/src/webhook-generator.ts +11 -2
- package/src/workflow-component-plugin.ts +4 -3
- package/src/workflow-project-plugin.ts +36 -4
- package/src/workflow-utils-alias.ts +26 -0
|
@@ -302,6 +302,7 @@ function buildInvoiceDataScope(invoiceData) {
|
|
|
302
302
|
discountAmount: formatCurrencyValue(invoiceData.discountAmount, sym),
|
|
303
303
|
shippingAmount: formatCurrencyValue(shippingAmountNumber, sym),
|
|
304
304
|
hasShipping: shippingAmountNumber > 0 ? 'true' : 'false',
|
|
305
|
+
hasTax: Number(invoiceData.taxAmount) > 0 ? 'true' : 'false',
|
|
305
306
|
total: formatCurrencyValue(invoiceData.total, sym),
|
|
306
307
|
currency: invoiceData.currency || 'USD',
|
|
307
308
|
currencySymbol: sym,
|
|
@@ -348,13 +349,18 @@ function buildInvoiceDataScope(invoiceData) {
|
|
|
348
349
|
var lineStored = Number(it.totalPrice || it.total_price);
|
|
349
350
|
if (!isFinite(lineStored) || lineStored === 0) lineStored = qty * unitStored;
|
|
350
351
|
|
|
351
|
-
|
|
352
|
-
|
|
352
|
+
// A line on an order priced by region carries its own rate and inclusion
|
|
353
|
+
// mode (a food line at 7% beside a tools line at 19%); every other line is
|
|
354
|
+
// taxed at the invoice's single rate.
|
|
355
|
+
var lineRate = typeof it.taxIncluded === 'boolean' ? Number(it.taxRate) || 0 : taxRate;
|
|
356
|
+
var lineIncluded = typeof it.taxIncluded === 'boolean' ? it.taxIncluded : taxIncluded;
|
|
357
|
+
var unitNet = computeNetFromGrossValue(unitStored, lineRate, lineIncluded);
|
|
358
|
+
var lineNet = computeNetFromGrossValue(lineStored, lineRate, lineIncluded);
|
|
353
359
|
// Per-unit VAT mirrors the GUI helper: derived from the NET unit
|
|
354
360
|
// price at the configured rate (rather than dividing line VAT by qty,
|
|
355
361
|
// which yields odd values when qty is 0 or missing).
|
|
356
|
-
var unitVat = computeLineVatAmountValue(unitStored,
|
|
357
|
-
var lineVat = computeLineVatAmountValue(lineStored,
|
|
362
|
+
var unitVat = computeLineVatAmountValue(unitStored, lineRate, lineIncluded);
|
|
363
|
+
var lineVat = computeLineVatAmountValue(lineStored, lineRate, lineIncluded);
|
|
358
364
|
var unitGross = unitNet + unitVat;
|
|
359
365
|
var lineGross = lineNet + lineVat;
|
|
360
366
|
|
|
@@ -392,6 +398,9 @@ function buildInvoiceDataScope(invoiceData) {
|
|
|
392
398
|
lineTotalNet: formatCurrencyValue(lineNet, sym),
|
|
393
399
|
lineTotalGross: formatCurrencyValue(lineGross, sym),
|
|
394
400
|
lineVatAmount: formatCurrencyValue(lineVat, sym),
|
|
401
|
+
// The rate this line was taxed at ("20%"): its own on an order priced by
|
|
402
|
+
// region, the invoice's single rate otherwise. Bound by the VAT % column.
|
|
403
|
+
lineVatRate: (lineRate > 0 ? Math.round(lineRate * 100) / 100 : 0) + '%',
|
|
395
404
|
sku: it.sku || '',
|
|
396
405
|
itemTaxRate: it.taxRate != null ? String(it.taxRate) : (taxRate > 0 ? String(taxRate) : ''),
|
|
397
406
|
itemTaxAmount: it.taxAmount != null ? formatCurrencyValue(it.taxAmount, sym) : formatCurrencyValue(lineVat, sym),
|
|
@@ -562,13 +571,20 @@ function resolveReferenceValue(ref, scope) {
|
|
|
562
571
|
}
|
|
563
572
|
|
|
564
573
|
function matchConditionOperation(val, op, operand) {
|
|
574
|
+
// The editor stores every operand as a STRING ('true', '0'), while
|
|
575
|
+
// \`resolveReferenceValue\` hands back a typed value for \`expr\` references
|
|
576
|
+
// (it turns 'true' into boolean true). A strict \`===\` across those two
|
|
577
|
+
// shapes never matches — that is how the template's Delivery row, gated on
|
|
578
|
+
// \`Invoice.hasShipping = 'true'\`, stayed hidden on every invoice with a
|
|
579
|
+
// fee — so mixed-type equality compares the string forms instead.
|
|
580
|
+
var sameType = typeof val === typeof operand;
|
|
565
581
|
switch (op) {
|
|
566
582
|
case '=':
|
|
567
583
|
case '===':
|
|
568
|
-
return val === operand;
|
|
584
|
+
return sameType ? val === operand : String(val) === String(operand);
|
|
569
585
|
case '!=':
|
|
570
586
|
case '!==':
|
|
571
|
-
return val !== operand;
|
|
587
|
+
return sameType ? val !== operand : String(val) !== String(operand);
|
|
572
588
|
case '>': return Number(val) > Number(operand);
|
|
573
589
|
case '<': return Number(val) < Number(operand);
|
|
574
590
|
case '>=': return Number(val) >= Number(operand);
|
|
@@ -913,18 +929,25 @@ function buildFallbackInvoiceHtml(scope) {
|
|
|
913
929
|
'<th style="text-align:left;border-bottom:2px solid #333;padding:6px;">Item</th>' +
|
|
914
930
|
'<th style="text-align:right;border-bottom:2px solid #333;padding:6px;">Qty</th>' +
|
|
915
931
|
'<th style="text-align:right;border-bottom:2px solid #333;padding:6px;">Unit Price</th>' +
|
|
932
|
+
'<th style="text-align:right;border-bottom:2px solid #333;padding:6px;">VAT %</th>' +
|
|
933
|
+
'<th style="text-align:right;border-bottom:2px solid #333;padding:6px;">VAT</th>' +
|
|
916
934
|
'<th style="text-align:right;border-bottom:2px solid #333;padding:6px;">Total</th>' +
|
|
917
935
|
'</tr></thead><tbody>');
|
|
918
936
|
products.forEach(function (p) {
|
|
919
937
|
parts.push('<tr>' +
|
|
920
938
|
'<td style="border-bottom:1px solid #eee;padding:6px;">' + (p.variantSwatchesHtml || '') + escapeHtml(p.name) + '</td>' +
|
|
921
939
|
'<td style="border-bottom:1px solid #eee;padding:6px;text-align:right;">' + escapeHtml(p.quantity) + '</td>' +
|
|
922
|
-
'<td style="border-bottom:1px solid #eee;padding:6px;text-align:right;">' + escapeHtml(p.
|
|
923
|
-
'<td style="border-bottom:1px solid #eee;padding:6px;text-align:right;">' + escapeHtml(p.
|
|
940
|
+
'<td style="border-bottom:1px solid #eee;padding:6px;text-align:right;">' + escapeHtml(p.unitPriceNet) + '</td>' +
|
|
941
|
+
'<td style="border-bottom:1px solid #eee;padding:6px;text-align:right;">' + escapeHtml(p.lineVatRate) + '</td>' +
|
|
942
|
+
'<td style="border-bottom:1px solid #eee;padding:6px;text-align:right;">' + escapeHtml(p.lineVatAmount) + '</td>' +
|
|
943
|
+
'<td style="border-bottom:1px solid #eee;padding:6px;text-align:right;">' + escapeHtml(p.lineTotalGross) + '</td>' +
|
|
924
944
|
'</tr>');
|
|
925
945
|
});
|
|
926
946
|
parts.push('</tbody></table>');
|
|
927
947
|
var totalsRows = '<div style="display:flex;justify-content:space-between;margin-bottom:4px;"><span>Subtotal</span><span>' + escapeHtml(inv.subtotal) + '</span></div>';
|
|
948
|
+
if (inv.hasTax === 'true') {
|
|
949
|
+
totalsRows += '<div style="display:flex;justify-content:space-between;margin-bottom:4px;"><span>VAT</span><span>' + escapeHtml(inv.taxAmount) + '</span></div>';
|
|
950
|
+
}
|
|
928
951
|
if (inv.hasShipping === 'true') {
|
|
929
952
|
totalsRows += '<div style="display:flex;justify-content:space-between;margin-bottom:4px;"><span>Delivery</span><span>' + escapeHtml(inv.shippingAmount) + '</span></div>';
|
|
930
953
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invoice VAT for an order placed on a store with shipping zones and tax
|
|
3
|
+
* jurisdictions, as source for the generated `/api/invoices/generate` route.
|
|
4
|
+
*
|
|
5
|
+
* Such an order does not have ONE rate: a German food line at 7% can sit beside
|
|
6
|
+
* a tools line at 19%, a French order's prices may include VAT while the store
|
|
7
|
+
* default adds it on top, and the delivery fee may be taxed. The store's
|
|
8
|
+
* baked `DEFAULT_TAX_RATE` / `TAX_INCLUDED_IN_PRICE` describe none of that, so
|
|
9
|
+
* the place-order workflow records what was actually charged in
|
|
10
|
+
* `teleport_orders.tax_breakdown`, and this prices the invoice from it.
|
|
11
|
+
*
|
|
12
|
+
* Totals reconcile with `teleport_orders.total_amount` by construction:
|
|
13
|
+
* `goods (gross) + shipping_amount (gross) - discount_amount`. The discount is
|
|
14
|
+
* taken off the goods first and only then off the shipping, exactly as the
|
|
15
|
+
* payment line items split it, and each part's tax shrinks in proportion.
|
|
16
|
+
*
|
|
17
|
+
* The printed rows add up too: `subtotal` (goods, net) + `taxAmount` (goods
|
|
18
|
+
* AND shipping tax) + `shippingNet` = `total`. Delivery is therefore shown net
|
|
19
|
+
* of its tax, or its tax would be counted twice.
|
|
20
|
+
*
|
|
21
|
+
* An order without a breakdown — every order placed before regions existed —
|
|
22
|
+
* returns null and keeps the single-rate arithmetic it was always invoiced with.
|
|
23
|
+
*/
|
|
24
|
+
export const REGIONAL_INVOICE_TAX_CODE = `
|
|
25
|
+
function parseOrderTaxBreakdown(raw) {
|
|
26
|
+
if (!raw) return null;
|
|
27
|
+
var parsed = raw;
|
|
28
|
+
if (typeof raw === 'string') {
|
|
29
|
+
try {
|
|
30
|
+
parsed = JSON.parse(raw);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.lines)) return null;
|
|
36
|
+
return parsed;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function regionalInvoiceRound(value, decimals) {
|
|
40
|
+
var factor = decimals === 0 ? 1 : 100;
|
|
41
|
+
var n = Number(value);
|
|
42
|
+
return Math.round((isFinite(n) ? n : 0) * factor) / factor;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// items: the invoice lines as the route normalised them (productId, variantId,
|
|
46
|
+
// quantity, unitPrice, totalPrice — all stored, i.e. NET where tax is added on
|
|
47
|
+
// top and GROSS where it is included).
|
|
48
|
+
function resolveRegionalInvoiceTax(breakdown, items, discountAmount, shippingAmount) {
|
|
49
|
+
var decimals = breakdown.taxDecimals === 0 ? 0 : 2;
|
|
50
|
+
var standardRate = Number(breakdown.taxRate);
|
|
51
|
+
if (!isFinite(standardRate) || standardRate < 0) standardRate = 0;
|
|
52
|
+
var standardIncluded = breakdown.taxIncluded === true;
|
|
53
|
+
var claimed = [];
|
|
54
|
+
var itemTax = [];
|
|
55
|
+
var goodsGross = 0;
|
|
56
|
+
var goodsTax = 0;
|
|
57
|
+
for (var i = 0; i < items.length; i++) {
|
|
58
|
+
var item = items[i];
|
|
59
|
+
var match = null;
|
|
60
|
+
for (var l = 0; l < breakdown.lines.length; l++) {
|
|
61
|
+
var line = breakdown.lines[l];
|
|
62
|
+
if (!line || claimed.indexOf(l) !== -1) continue;
|
|
63
|
+
if (
|
|
64
|
+
String(line.productId || '') === String(item.productId || '') &&
|
|
65
|
+
String(line.variantId || '') === String(item.variantId || '')
|
|
66
|
+
) {
|
|
67
|
+
match = line;
|
|
68
|
+
claimed.push(l);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
var matchedRate = match ? Number(match.taxRate) : NaN;
|
|
73
|
+
var rate = isFinite(matchedRate) && matchedRate >= 0 ? matchedRate : standardRate;
|
|
74
|
+
var included = match ? match.taxIncluded === true : standardIncluded;
|
|
75
|
+
var quantity = Number(item.quantity) || 1;
|
|
76
|
+
var stored = Number(item.totalPrice) || 0;
|
|
77
|
+
var lineGross = !included && rate > 0
|
|
78
|
+
? regionalInvoiceRound(
|
|
79
|
+
regionalInvoiceRound((Number(item.unitPrice) || 0) * (1 + rate / 100), decimals) * quantity,
|
|
80
|
+
decimals
|
|
81
|
+
)
|
|
82
|
+
: stored;
|
|
83
|
+
var lineTax = included
|
|
84
|
+
? (rate > 0 ? stored - stored / (1 + rate / 100) : 0)
|
|
85
|
+
: lineGross - stored;
|
|
86
|
+
goodsGross += lineGross;
|
|
87
|
+
goodsTax += lineTax;
|
|
88
|
+
itemTax.push({ rate: rate, included: included, amount: regionalInvoiceRound(lineTax, decimals) });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var discount = discountAmount > 0 ? discountAmount : 0;
|
|
92
|
+
var shipping = shippingAmount > 0 ? shippingAmount : 0;
|
|
93
|
+
var goodsAfter = Math.max(0, goodsGross - discount);
|
|
94
|
+
var goodsShare = goodsGross > 0 ? goodsAfter / goodsGross : 0;
|
|
95
|
+
var shippingAfter = Math.max(0, shipping - Math.max(0, discount - goodsGross));
|
|
96
|
+
var shippingShare = shipping > 0 ? shippingAfter / shipping : 0;
|
|
97
|
+
var shippingTax = Number(breakdown.shippingTax);
|
|
98
|
+
if (!isFinite(shippingTax) || shippingTax < 0) shippingTax = 0;
|
|
99
|
+
var allocatedGoodsTax = goodsTax * goodsShare;
|
|
100
|
+
var allocatedShippingTax = shippingTax * shippingShare;
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
taxRate: standardRate,
|
|
104
|
+
taxIncluded: standardIncluded,
|
|
105
|
+
subtotal: goodsAfter - allocatedGoodsTax,
|
|
106
|
+
taxAmount: allocatedGoodsTax + allocatedShippingTax,
|
|
107
|
+
shippingNet: shippingAfter - allocatedShippingTax,
|
|
108
|
+
total: goodsAfter + shippingAfter,
|
|
109
|
+
itemTax: itemTax,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
`
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DataSourceType, ProjectPluginStructure } from '@teleporthq/teleport-types'
|
|
2
|
+
|
|
3
|
+
export const resolveInvoiceDataSource = (
|
|
4
|
+
structure: ProjectPluginStructure
|
|
5
|
+
): { dataSourceType: DataSourceType | null; dataSourceConfig: Record<string, unknown> | null } => {
|
|
6
|
+
const { uidl } = structure
|
|
7
|
+
|
|
8
|
+
if (!uidl.dataSources) {
|
|
9
|
+
return { dataSourceType: null, dataSourceConfig: null }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (uidl.authentication?.dataSourceId) {
|
|
13
|
+
const ds = uidl.dataSources[uidl.authentication.dataSourceId]
|
|
14
|
+
if (ds) {
|
|
15
|
+
return { dataSourceType: ds.type, dataSourceConfig: ds.config }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const dsEntries = Object.values(uidl.dataSources)
|
|
20
|
+
if (dsEntries.length > 0) {
|
|
21
|
+
return { dataSourceType: dsEntries[0].type, dataSourceConfig: dsEntries[0].config }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { dataSourceType: null, dataSourceConfig: null }
|
|
25
|
+
}
|
|
@@ -11,10 +11,16 @@ async function account_delete_current(config: any, context: Record<string, unkno
|
|
|
11
11
|
const baseUrl = (context && (context as any).__baseUrl) || ''
|
|
12
12
|
|
|
13
13
|
// The route resolves the current user from the NextAuth session cookie, which
|
|
14
|
-
// the browser sends automatically with this same-origin request.
|
|
14
|
+
// the browser sends automatically with this same-origin request. The page's
|
|
15
|
+
// language rides along (see buildContext) so the farewell email is sent in it.
|
|
16
|
+
const deleteHeaders: any = { 'Content-Type': 'application/json' }
|
|
17
|
+
const runLocale = context && (context as any).__locale
|
|
18
|
+
if (typeof runLocale === 'string' && runLocale) {
|
|
19
|
+
deleteHeaders['x-teleport-locale'] = runLocale
|
|
20
|
+
}
|
|
15
21
|
const response = await fetch(baseUrl + '/api/account/delete-current', {
|
|
16
22
|
method: 'POST',
|
|
17
|
-
headers:
|
|
23
|
+
headers: deleteHeaders,
|
|
18
24
|
body: '{}',
|
|
19
25
|
})
|
|
20
26
|
|
|
@@ -64,7 +70,8 @@ async function account_delete_current(config: any, context: Record<string, unkno
|
|
|
64
70
|
win.document.body.appendChild(el)
|
|
65
71
|
} catch (_e) {}
|
|
66
72
|
|
|
67
|
-
|
|
73
|
+
// The configured page, in the language the visitor was browsing in.
|
|
74
|
+
const redirectTo = __workflowUtils.localizeHref((config && config.redirectTo) || '/', runLocale)
|
|
68
75
|
window.setTimeout(function () {
|
|
69
76
|
window.location.href = redirectTo
|
|
70
77
|
}, 1500)
|
|
@@ -64,7 +64,9 @@ async function account_login(config: any, context: Record<string, unknown>) {
|
|
|
64
64
|
} catch (_e) {}
|
|
65
65
|
}
|
|
66
66
|
window.dispatchEvent(new CustomEvent('teleport:auth-user-changed', { detail: { user } }))
|
|
67
|
-
|
|
67
|
+
// Home page of the language the visitor signed in from (see buildContext
|
|
68
|
+
// for how the run learns it).
|
|
69
|
+
window.location.href = __workflowUtils.localizeHref('/', context && (context as any).__locale)
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
// Contract exposes user fields flat (id, email, name, ...) plus `user`/`success`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeHandlerGenerator, handlerToString } from '../types'
|
|
2
2
|
|
|
3
|
-
async function account_logout(_config: unknown,
|
|
3
|
+
async function account_logout(_config: unknown, context: Record<string, unknown>) {
|
|
4
4
|
// Read signOut off the window bridge session-provider.js publishes instead of
|
|
5
5
|
// `require('next-auth/react')` — see the account-login handler for the full
|
|
6
6
|
// rationale (avoids the dangling-module "reading 'call'" crash that a
|
|
@@ -19,7 +19,9 @@ async function account_logout(_config: unknown, _context: Record<string, unknown
|
|
|
19
19
|
window.localStorage.removeItem('teleport_auth_user')
|
|
20
20
|
} catch (_e) {}
|
|
21
21
|
window.dispatchEvent(new CustomEvent('teleport:auth-user-changed', { detail: { user: null } }))
|
|
22
|
-
|
|
22
|
+
// Home page of the language the visitor signed out from (see buildContext
|
|
23
|
+
// for how the run learns it).
|
|
24
|
+
window.location.href = __workflowUtils.localizeHref('/', context && (context as any).__locale)
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
return { success: true }
|
|
@@ -29,6 +29,7 @@ async function account_signup(config: any, context: Record<string, unknown>) {
|
|
|
29
29
|
bodyComponentId: true,
|
|
30
30
|
bodyTemplatePurpose: true,
|
|
31
31
|
templateParams: true,
|
|
32
|
+
localizedTemplates: true,
|
|
32
33
|
}
|
|
33
34
|
const configKeys = Object.keys(config)
|
|
34
35
|
for (let i = 0; i < configKeys.length; i++) {
|
|
@@ -38,9 +39,17 @@ async function account_signup(config: any, context: Record<string, unknown>) {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const baseUrl = (context && (context as any).__baseUrl) || ''
|
|
42
|
+
// The language of the page the visitor signs up from, so the route sends
|
|
43
|
+
// the welcome email in it. The runtime puts it on the context (see
|
|
44
|
+
// buildContext); the route falls back to the request when it is absent.
|
|
45
|
+
const signupHeaders: any = { 'Content-Type': 'application/json' }
|
|
46
|
+
const runLocale = context && (context as any).__locale
|
|
47
|
+
if (typeof runLocale === 'string' && runLocale) {
|
|
48
|
+
signupHeaders['x-teleport-locale'] = runLocale
|
|
49
|
+
}
|
|
41
50
|
const response = await fetch(baseUrl + '/api/auth/signup', {
|
|
42
51
|
method: 'POST',
|
|
43
|
-
headers:
|
|
52
|
+
headers: signupHeaders,
|
|
44
53
|
body: JSON.stringify(bodyObj),
|
|
45
54
|
})
|
|
46
55
|
|
|
@@ -89,7 +98,8 @@ async function account_signup(config: any, context: Record<string, unknown>) {
|
|
|
89
98
|
} catch (_e) {}
|
|
90
99
|
}
|
|
91
100
|
window.dispatchEvent(new CustomEvent('teleport:auth-user-changed', { detail: { user } }))
|
|
92
|
-
|
|
101
|
+
// Home page of the language the visitor signed up from.
|
|
102
|
+
window.location.href = __workflowUtils.localizeHref('/', runLocale)
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
// Contract exposes user fields flat (id, email, name, ...) plus `user`/`success`.
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { NodeHandlerGenerator, handlerToString } from '../types'
|
|
2
2
|
|
|
3
|
-
async function account_social_login(config: any,
|
|
3
|
+
async function account_social_login(config: any, context: Record<string, unknown>) {
|
|
4
4
|
const provider = config.provider
|
|
5
5
|
|
|
6
6
|
if (!provider) {
|
|
7
7
|
throw new Error('Provider is required')
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// Where the provider sends the visitor back to, in the language they started
|
|
11
|
+
// the sign-in from (see buildContext for how the run learns it).
|
|
12
|
+
const callbackUrl = __workflowUtils.localizeHref(
|
|
13
|
+
config.callbackUrl || '/',
|
|
14
|
+
context && (context as any).__locale
|
|
15
|
+
)
|
|
11
16
|
|
|
12
17
|
// Read signIn off the window bridge session-provider.js publishes instead of
|
|
13
18
|
// `require('next-auth/react')` — see the account-login handler for the full
|
|
@@ -38,6 +38,11 @@ async function cart_clear() {
|
|
|
38
38
|
// An applied voucher belongs to the cart that is being emptied — after
|
|
39
39
|
// a completed checkout it must not carry over to the next order.
|
|
40
40
|
localStorage.removeItem('workflow_voucher')
|
|
41
|
+
// So is the shipping method picked for it: the next order starts from
|
|
42
|
+
// the cheapest rate again instead of a choice made weeks ago. Literal
|
|
43
|
+
// key — a serialized handler cannot import
|
|
44
|
+
// `RegionalPricing.SHIPPING_RATE_STORAGE_KEY`.
|
|
45
|
+
localStorage.removeItem('workflow_shipping_rate')
|
|
41
46
|
const sessionId = localStorage.getItem('workflow_cart_session_id') || null
|
|
42
47
|
fetch('/api/cart/sync', {
|
|
43
48
|
method: 'POST',
|
|
@@ -49,6 +54,7 @@ async function cart_clear() {
|
|
|
49
54
|
}
|
|
50
55
|
window.dispatchEvent(new CustomEvent('teleport:cart-changed'))
|
|
51
56
|
window.dispatchEvent(new CustomEvent('teleport:voucher-changed'))
|
|
57
|
+
window.dispatchEvent(new CustomEvent('teleport:shipping-rate-changed'))
|
|
52
58
|
}
|
|
53
59
|
return { success: true }
|
|
54
60
|
} catch (err: unknown) {
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { RegionalPricing } from '@teleporthq/teleport-shared'
|
|
1
2
|
import { NodeHandlerGenerator, handlerToString } from '../types'
|
|
2
3
|
|
|
4
|
+
// AMBIENT, not imported: the handler ships as a serialized function with no
|
|
5
|
+
// module scope, and the shared regional-pricing helpers are spliced into its
|
|
6
|
+
// body by `generateHandler` below. See `commerce-tracking.ts` for why an import
|
|
7
|
+
// would compile to a module reference that throws in the browser.
|
|
8
|
+
declare function __rpQuote(input: Record<string, unknown>): any
|
|
9
|
+
declare function __rpNormalizeConfig(rows: unknown): Record<string, unknown>
|
|
10
|
+
declare function __rpReadCheckoutDestination(countryCodes: unknown): Record<string, string> | null
|
|
11
|
+
|
|
3
12
|
async function cart_get_total() {
|
|
4
13
|
try {
|
|
5
14
|
const raw = localStorage.getItem('workflow_cart')
|
|
@@ -42,6 +51,10 @@ async function cart_get_total() {
|
|
|
42
51
|
// applied. Absent on a storefront exported before vouchers existed, which
|
|
43
52
|
// correctly resolves to "no voucher".
|
|
44
53
|
let voucher: Record<string, unknown> | null = null
|
|
54
|
+
// Shipping zones + tax jurisdictions: the rows and store defaults the
|
|
55
|
+
// provider priced the page from, mirrored for exactly this moment. Present
|
|
56
|
+
// only on a store with regional pricing.
|
|
57
|
+
let regionalSnapshot: Record<string, any> | null = null
|
|
45
58
|
try {
|
|
46
59
|
const voucherRaw = localStorage.getItem('workflow_voucher')
|
|
47
60
|
if (voucherRaw) {
|
|
@@ -72,6 +85,14 @@ async function cart_get_total() {
|
|
|
72
85
|
deliveryConfig.storePickupEnabled = parsed.deliveryConfig.storePickupEnabled
|
|
73
86
|
}
|
|
74
87
|
}
|
|
88
|
+
if (
|
|
89
|
+
parsed &&
|
|
90
|
+
typeof parsed === 'object' &&
|
|
91
|
+
parsed.regional &&
|
|
92
|
+
typeof parsed.regional === 'object'
|
|
93
|
+
) {
|
|
94
|
+
regionalSnapshot = parsed.regional
|
|
95
|
+
}
|
|
75
96
|
if (parsed && typeof parsed === 'object' && parsed.taxConfig) {
|
|
76
97
|
const parsedRate = Number(parsed.taxConfig.storefrontTaxRate)
|
|
77
98
|
storefrontTaxRate = isFinite(parsedRate) && parsedRate > 0 ? parsedRate : 0
|
|
@@ -110,9 +131,61 @@ async function cart_get_total() {
|
|
|
110
131
|
}
|
|
111
132
|
}
|
|
112
133
|
|
|
113
|
-
|
|
134
|
+
let roundedGross = round(gross)
|
|
135
|
+
let tax = round(gross - net)
|
|
114
136
|
|
|
115
|
-
|
|
137
|
+
// Re-priced HERE, at submit, for the address on the checkout form right
|
|
138
|
+
// now — with the same rule and the same rows the provider displayed from —
|
|
139
|
+
// rather than trusting a figure computed before the buyer's last edit.
|
|
140
|
+
let regional: Record<string, unknown> | null = null
|
|
141
|
+
if (regionalSnapshot) {
|
|
142
|
+
const store =
|
|
143
|
+
regionalSnapshot.store && typeof regionalSnapshot.store === 'object'
|
|
144
|
+
? regionalSnapshot.store
|
|
145
|
+
: {}
|
|
146
|
+
const destination = __rpReadCheckoutDestination(regionalSnapshot.countryCodes)
|
|
147
|
+
let selectedRateId: string | null = null
|
|
148
|
+
try {
|
|
149
|
+
selectedRateId = localStorage.getItem('workflow_shipping_rate') || null
|
|
150
|
+
} catch (_rateErr) {
|
|
151
|
+
selectedRateId = null
|
|
152
|
+
}
|
|
153
|
+
const quote = __rpQuote({
|
|
154
|
+
// Null while the provider is still loading the rows: the store's single
|
|
155
|
+
// flat fee and default rate, which is also what the page is showing.
|
|
156
|
+
config: regionalSnapshot.rows ? __rpNormalizeConfig(regionalSnapshot.rows) : null,
|
|
157
|
+
store,
|
|
158
|
+
items: cart,
|
|
159
|
+
destination,
|
|
160
|
+
// Priced as a delivery; the place-order workflow knows whether the
|
|
161
|
+
// buyer picked store pickup and drops the shipping figures then.
|
|
162
|
+
fulfillment: store.deliveryEnabled === true ? 'delivery' : 'pickup',
|
|
163
|
+
selectedRateId,
|
|
164
|
+
currency: regionalSnapshot.currency,
|
|
165
|
+
})
|
|
166
|
+
tax = quote.goodsTax
|
|
167
|
+
roundedGross = quote.goodsGross
|
|
168
|
+
regional = {
|
|
169
|
+
status: quote.status,
|
|
170
|
+
destination: quote.destination,
|
|
171
|
+
zoneName: quote.zone ? quote.zone.name : '',
|
|
172
|
+
rateName: quote.rateName,
|
|
173
|
+
codAvailable: quote.codAvailable,
|
|
174
|
+
goodsNet: quote.goodsNet,
|
|
175
|
+
goodsTax: quote.goodsTax,
|
|
176
|
+
goodsGross: quote.goodsGross,
|
|
177
|
+
shippingNet: quote.shippingNet,
|
|
178
|
+
shippingTax: quote.shippingTax,
|
|
179
|
+
shippingGross: quote.shippingGross,
|
|
180
|
+
taxRate: quote.taxRate,
|
|
181
|
+
taxIncluded: quote.taxIncluded,
|
|
182
|
+
taxDecimals: quote.taxDecimals,
|
|
183
|
+
breakdown: quote.breakdown,
|
|
184
|
+
lines: quote.lines,
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const result: Record<string, unknown> = {
|
|
116
189
|
// NET goods total. Deliberately unchanged in meaning: two generations of
|
|
117
190
|
// baked place-order workflows read this field and add shipping to it to
|
|
118
191
|
// produce `teleport_orders.total_amount`. Making it gross here would make
|
|
@@ -127,8 +200,9 @@ async function cart_get_total() {
|
|
|
127
200
|
// `total` to the cent. Payment providers that total a `line_items` array
|
|
128
201
|
// need this as its own line: the item lines carry NET prices, because
|
|
129
202
|
// `teleport_order_items` stores net and the invoice route adds VAT back
|
|
130
|
-
// on top of them (double-taxing every invoice otherwise).
|
|
131
|
-
|
|
203
|
+
// on top of them (double-taxing every invoice otherwise). On a store with
|
|
204
|
+
// regional pricing it is the destination's added tax, same definition.
|
|
205
|
+
tax,
|
|
132
206
|
// Goods total the buyer actually owes, tax included and shipping
|
|
133
207
|
// excluded. Equals the Subtotal the cart page printed — same per-unit
|
|
134
208
|
// rounding, same source of truth.
|
|
@@ -141,6 +215,12 @@ async function cart_get_total() {
|
|
|
141
215
|
taxConfig: { storefrontTaxRate },
|
|
142
216
|
voucher,
|
|
143
217
|
}
|
|
218
|
+
// Absent on a store without regional pricing, which is what tells the
|
|
219
|
+
// place-order workflow to price shipping from `deliveryConfig` as before.
|
|
220
|
+
if (regional) {
|
|
221
|
+
result.regional = regional
|
|
222
|
+
}
|
|
223
|
+
return result
|
|
144
224
|
} catch (_err) {
|
|
145
225
|
return {
|
|
146
226
|
subtotal: 0,
|
|
@@ -158,6 +238,15 @@ export const cartGetTotal: NodeHandlerGenerator = {
|
|
|
158
238
|
nodeType: 'cart-get-total',
|
|
159
239
|
executionEnv: 'client',
|
|
160
240
|
generateHandler(): string {
|
|
161
|
-
|
|
241
|
+
// Spliced INTO the function body rather than appended after it, so the
|
|
242
|
+
// emitted handler stays one function expression — the shape every caller
|
|
243
|
+
// (and every test that evaluates it) expects.
|
|
244
|
+
const source = handlerToString(cart_get_total)
|
|
245
|
+
const bodyStart = source.indexOf('{') + 1
|
|
246
|
+
return (
|
|
247
|
+
source.slice(0, bodyStart) +
|
|
248
|
+
RegionalPricing.generateRegionalPricingHelperCode() +
|
|
249
|
+
source.slice(bodyStart)
|
|
250
|
+
)
|
|
162
251
|
},
|
|
163
252
|
}
|
|
@@ -113,6 +113,14 @@ async function data_create_item(config: any, context: any) {
|
|
|
113
113
|
if (config.onConflictDoNothing === true) {
|
|
114
114
|
reqBody.onConflictDoNothing = true
|
|
115
115
|
}
|
|
116
|
+
// The language of the storefront the run started on. The data-api stamps
|
|
117
|
+
// it onto an order row (`teleport_orders.locale`) so every later email
|
|
118
|
+
// about that order — the invoice, a shipping update sent by the admin —
|
|
119
|
+
// goes out in the buyer's language, not in whoever triggers it.
|
|
120
|
+
const __runLocale = context && context.__locale
|
|
121
|
+
if (typeof __runLocale === 'string' && __runLocale) {
|
|
122
|
+
reqBody.__requestLocale = __runLocale
|
|
123
|
+
}
|
|
116
124
|
const response = await fetch(baseUrl + '/api/data/' + dataSourceId + '/create', {
|
|
117
125
|
method: 'POST',
|
|
118
126
|
headers: { 'Content-Type': 'application/json', ...__internalHeaders },
|
|
@@ -203,6 +211,9 @@ async function data_create_item(config: any, context: any) {
|
|
|
203
211
|
// email template's `<!--tq:each items-->` row block binds to.
|
|
204
212
|
// One payload therefore feeds both renderers without either having to
|
|
205
213
|
// know which template style the merchant is on.
|
|
214
|
+
//
|
|
215
|
+
// The product + variant ids ride along so the endpoint can price each
|
|
216
|
+
// line at the rate the order's tax breakdown recorded for it.
|
|
206
217
|
const orderCurrency = item.currency || ''
|
|
207
218
|
const normalisedItems = cartItems.map(function (it: any) {
|
|
208
219
|
const unitPrice = Number(it.unitPrice != null ? it.unitPrice : it.price) || 0
|
|
@@ -223,6 +234,8 @@ async function data_create_item(config: any, context: any) {
|
|
|
223
234
|
line_total: lineTotal.toFixed(2),
|
|
224
235
|
currency: orderCurrency,
|
|
225
236
|
image_url: imageUrl,
|
|
237
|
+
product_id: it.productId || it.product_id || '',
|
|
238
|
+
variant_id: it.variantId || it.variant_id || '',
|
|
226
239
|
}
|
|
227
240
|
})
|
|
228
241
|
|
|
@@ -289,6 +302,9 @@ async function data_create_item(config: any, context: any) {
|
|
|
289
302
|
shippingAddress,
|
|
290
303
|
items: normalisedItems,
|
|
291
304
|
orderDate: item.created_at || item.placed_at || '',
|
|
305
|
+
// The rate each line was charged at, on an order priced by region
|
|
306
|
+
// (the column is on the row this INSERT just wrote); null otherwise.
|
|
307
|
+
taxBreakdown: item.tax_breakdown || null,
|
|
292
308
|
}),
|
|
293
309
|
}).catch(function () {
|
|
294
310
|
/* notifications must never break checkout */
|
|
@@ -27,6 +27,12 @@ async function ecommerce_generate_invoice(config: any, context: any) {
|
|
|
27
27
|
if (config.overrideTaxRate !== undefined && config.overrideTaxRate !== null) {
|
|
28
28
|
payload.overrideTaxRate = Number(config.overrideTaxRate)
|
|
29
29
|
}
|
|
30
|
+
// The language of the storefront this run started on. The route prefers
|
|
31
|
+
// the locale stamped on the order and only reads this when there is none.
|
|
32
|
+
const runLocale = context && context.__locale
|
|
33
|
+
if (typeof runLocale === 'string' && runLocale) {
|
|
34
|
+
payload.locale = runLocale
|
|
35
|
+
}
|
|
30
36
|
|
|
31
37
|
const targetUrl = baseUrl + '/api/invoices/generate'
|
|
32
38
|
console.info('[invoice-node] POST ' + targetUrl + ' payload=' + JSON.stringify(payload))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeHandlerGenerator, handlerToString } from '../types'
|
|
2
2
|
|
|
3
|
-
async function navigation_go_to_page(config: any,
|
|
3
|
+
async function navigation_go_to_page(config: any, context: Record<string, unknown>) {
|
|
4
4
|
// The shared workflow runtime (`resolveConfig`) has already resolved any
|
|
5
5
|
// `{ type: 'workflowContext', ... }` references inside `differentiator`,
|
|
6
6
|
// `queryParams[].key` and `queryParams[].value`, so by this point those
|
|
@@ -78,6 +78,10 @@ async function navigation_go_to_page(config: any, _context: Record<string, unkno
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// The page in the language the visitor is browsing in (see buildContext for
|
|
82
|
+
// how the run learns it); the default language keeps the bare route.
|
|
83
|
+
url = __workflowUtils.localizeHref(url, context && (context as any).__locale)
|
|
84
|
+
|
|
81
85
|
if (openInNewTab) {
|
|
82
86
|
window.open(url, '_blank')
|
|
83
87
|
} else {
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { NodeHandlerGenerator, handlerToString } from '../types'
|
|
2
2
|
|
|
3
3
|
async function navigation_navigate_to_url(config: any, context: Record<string, unknown>) {
|
|
4
|
-
const url = config.url
|
|
5
4
|
const openInNewTab = config.openInNewTab
|
|
6
5
|
|
|
7
|
-
if (!url) {
|
|
6
|
+
if (!config.url) {
|
|
8
7
|
return { __terminal: true }
|
|
9
8
|
}
|
|
10
9
|
|
|
10
|
+
// A site-relative page path stays in the language the visitor is browsing in
|
|
11
|
+
// (see buildContext for how the run learns it); an external URL, an API
|
|
12
|
+
// route or a file passes through untouched.
|
|
13
|
+
const url = __workflowUtils.localizeHref(config.url, context && (context as any).__locale)
|
|
14
|
+
|
|
11
15
|
if (openInNewTab) {
|
|
12
16
|
window.open(url, '_blank')
|
|
13
17
|
} else {
|
|
@@ -69,8 +69,19 @@ async function payment_charge_user(config: any, _context: Record<string, unknown
|
|
|
69
69
|
const amount = config.amount
|
|
70
70
|
const currency = config.currency || 'usd'
|
|
71
71
|
const baseUrl = String((_context && (_context.__baseUrl as string)) || '')
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
// The buyer comes back from the provider's hosted page to the language they
|
|
73
|
+
// checked out in: a site-relative return path gets the run's locale prefix
|
|
74
|
+
// (the segment route reads it off the client context) before it is
|
|
75
|
+
// absolutized; an external override passes through untouched.
|
|
76
|
+
const runLocale = _context && _context.__locale
|
|
77
|
+
const successUrl = toAbsoluteUrl(
|
|
78
|
+
__workflowUtils.localizeHref(config.successUrl || '', runLocale),
|
|
79
|
+
baseUrl
|
|
80
|
+
)
|
|
81
|
+
const cancelUrl = toAbsoluteUrl(
|
|
82
|
+
__workflowUtils.localizeHref(config.cancelUrl || '', runLocale),
|
|
83
|
+
baseUrl
|
|
84
|
+
)
|
|
74
85
|
const description = config.description || 'Payment'
|
|
75
86
|
const lineItems = config.lineItems
|
|
76
87
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The shared workflow runtime, as every file that inlines node handlers binds
|
|
2
|
+
// it before the first handler (see `workflow-utils-alias.ts`). Declared here
|
|
3
|
+
// so the handler sources type-check against it; only the helpers a handler
|
|
4
|
+
// actually calls are listed.
|
|
5
|
+
declare const __workflowUtils: {
|
|
6
|
+
/**
|
|
7
|
+
* The href a navigation should use so the visitor stays in `locale` (a
|
|
8
|
+
* site-relative page path gets the "/<locale>" prefix Next.js serves the
|
|
9
|
+
* non-default languages under; everything else passes through untouched).
|
|
10
|
+
*/
|
|
11
|
+
localizeHref(href: string, locale: unknown): string
|
|
12
|
+
}
|