@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
|
@@ -502,6 +502,24 @@ async function getColumnTypes(client, tableName) {
|
|
|
502
502
|
} catch(e) { return {}; }
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
+
// Tables whose rows remember the language of the storefront they were
|
|
506
|
+
// written from, so the emails about them can be sent in it later (by a cron,
|
|
507
|
+
// a webhook, an admin action — none of which run in the buyer's language).
|
|
508
|
+
// The column is stamped ONLY when the table actually has it: a store
|
|
509
|
+
// provisioned before the column existed keeps inserting exactly as before.
|
|
510
|
+
var LOCALE_STAMPED_TABLES = { teleport_orders: 1 };
|
|
511
|
+
var LOCALE_COLUMN = 'locale';
|
|
512
|
+
|
|
513
|
+
function stampRequestLocale(tableName, entries, colTypes, requestLocale) {
|
|
514
|
+
if (!LOCALE_STAMPED_TABLES[tableName]) return entries;
|
|
515
|
+
if (typeof requestLocale !== 'string' || !requestLocale) return entries;
|
|
516
|
+
if (!colTypes[LOCALE_COLUMN]) return entries;
|
|
517
|
+
for (var i = 0; i < entries.length; i++) {
|
|
518
|
+
if (entries[i][0] === LOCALE_COLUMN) return entries;
|
|
519
|
+
}
|
|
520
|
+
return entries.concat([[LOCALE_COLUMN, requestLocale.slice(0, 10)]]);
|
|
521
|
+
}
|
|
522
|
+
|
|
505
523
|
async function handleCreate(client, body) {
|
|
506
524
|
var tableName = body.tableName;
|
|
507
525
|
var columnMappings = body.columnMappings || {};
|
|
@@ -528,6 +546,7 @@ async function handleCreate(client, body) {
|
|
|
528
546
|
}
|
|
529
547
|
|
|
530
548
|
var colTypes = await getColumnTypes(client, tableName);
|
|
549
|
+
entries = stampRequestLocale(tableName, entries, colTypes, body.__requestLocale);
|
|
531
550
|
|
|
532
551
|
var TEXT_TYPES = { 'character varying': 1, 'text': 1, 'char': 1, 'character': 1, 'varchar': 1, 'name': 1 };
|
|
533
552
|
var columns = entries.map(function(e) { return e[0]; });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-api-route-generator.js","sourceRoot":"","sources":["../../src/data-api-route-generator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,mDAA0D;AAC1D,uEAAoF;AAEpF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,uEAAuE;IACvE,0EAA0E;IAC1E,sCAAsC;IACtC,yBAAyB;CAC1B,CAAC,CAAA;AAEK,MAAM,iBAAiB,GAAG,CAAC,aAA0B,EAAW,EAAE;IACvE,KAAK,MAAM,EAAE,IAAI,aAAa,EAAE;QAC9B,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAC3B,OAAO,IAAI,CAAA;SACZ;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,iBAAiB,qBAO7B;AAqBM,MAAM,oBAAoB,GAAG,CAAC,UAA+B,EAAE,EAAU,EAAE;IAChF,MAAM,aAAa,GAAG,IAAA,wCAAwB,GAAE,CAAA;IAChD,MAAM,cAAc,GAAG,OAAO,CAAC,kBAAkB,IAAI,IAAI,CAAA;IACzD,MAAM,qBAAqB,GAAG,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAA;IAC7D,MAAM,iBAAiB,GACrB,OAAO,OAAO,CAAC,iBAAiB,KAAK,QAAQ,IAAI,OAAO,CAAC,iBAAiB,IAAI,CAAC;QAC7E,CAAC,CAAC,OAAO,CAAC,iBAAiB;QAC3B,CAAC,CAAC,CAAC,CAAA;IAEP,OAAO;EACP;IACA,mEAAmE;IACnE,4EAA4E;IAC5E,6EAA6E;IAC7E,qEAAqE;IACrE,cAAc,CAAC,CAAC,CAAC,IAAA,kEAAwC,GAAE,CAAC,CAAC,CAAC,EAChE,4BAA4B,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;mCACvB,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC;8BAC1C,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;EAC7D,aAAa
|
|
1
|
+
{"version":3,"file":"data-api-route-generator.js","sourceRoot":"","sources":["../../src/data-api-route-generator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,mDAA0D;AAC1D,uEAAoF;AAEpF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,uEAAuE;IACvE,0EAA0E;IAC1E,sCAAsC;IACtC,yBAAyB;CAC1B,CAAC,CAAA;AAEK,MAAM,iBAAiB,GAAG,CAAC,aAA0B,EAAW,EAAE;IACvE,KAAK,MAAM,EAAE,IAAI,aAAa,EAAE;QAC9B,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAC3B,OAAO,IAAI,CAAA;SACZ;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,iBAAiB,qBAO7B;AAqBM,MAAM,oBAAoB,GAAG,CAAC,UAA+B,EAAE,EAAU,EAAE;IAChF,MAAM,aAAa,GAAG,IAAA,wCAAwB,GAAE,CAAA;IAChD,MAAM,cAAc,GAAG,OAAO,CAAC,kBAAkB,IAAI,IAAI,CAAA;IACzD,MAAM,qBAAqB,GAAG,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAA;IAC7D,MAAM,iBAAiB,GACrB,OAAO,OAAO,CAAC,iBAAiB,KAAK,QAAQ,IAAI,OAAO,CAAC,iBAAiB,IAAI,CAAC;QAC7E,CAAC,CAAC,OAAO,CAAC,iBAAiB;QAC3B,CAAC,CAAC,CAAC,CAAA;IAEP,OAAO;EACP;IACA,mEAAmE;IACnE,4EAA4E;IAC5E,6EAA6E;IAC7E,qEAAqE;IACrE,cAAc,CAAC,CAAC,CAAC,IAAA,kEAAwC,GAAE,CAAC,CAAC,CAAC,EAChE,4BAA4B,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;mCACvB,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC;8BAC1C,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;EAC7D,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAs2Bd,CAAA;AACD,CAAC,CAAA;AA13BY,QAAA,oBAAoB,wBA03BhC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EmailLocaleConfig } from './email-locale-scope';
|
|
2
|
+
/**
|
|
3
|
+
* The locale helpers every generated email sender and every generated
|
|
4
|
+
* navigation runs. Emitted twice from this one source: as the standalone
|
|
5
|
+
* `utils/email/email-locale.js` module (the account routes, the invoice
|
|
6
|
+
* sender, the cart route and the cart provider use it) and inlined into the
|
|
7
|
+
* workflow runtime (`runtime-utils.js`), which is bundled for the browser as
|
|
8
|
+
* well and must not depend on a sibling file being resolvable.
|
|
9
|
+
*
|
|
10
|
+
* Every function is total: an unknown or missing locale resolves to the
|
|
11
|
+
* project's default language, so a sender can never pick a template that does
|
|
12
|
+
* not exist and a navigation can never be sent to a locale the app does not
|
|
13
|
+
* serve.
|
|
14
|
+
*/
|
|
15
|
+
export declare const generateEmailLocaleHelpersCode: (config: EmailLocaleConfig) => string;
|
|
16
|
+
/**
|
|
17
|
+
* The runtime-only helpers, on top of the shared ones: how a workflow run
|
|
18
|
+
* learns its locale and how an email node's config resolves the language it
|
|
19
|
+
* sends in. Inlined into \`runtime-utils.js\` right after
|
|
20
|
+
* \`generateEmailLocaleHelpersCode\`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const generateWorkflowLocaleHelpersCode: () => string;
|
|
23
|
+
/** `utils/email/email-locale.js` — the shared helpers as a CommonJS module. */
|
|
24
|
+
export declare const generateEmailLocaleModuleCode: (config: EmailLocaleConfig) => string;
|
|
25
|
+
//# sourceMappingURL=email-locale-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-locale-code.d.ts","sourceRoot":"","sources":["../../../src/email-locale/email-locale-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAIlB,MAAM,sBAAsB,CAAA;AAE7B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,8BAA8B,WAAY,iBAAiB,KAAG,MAmI1E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,QAAO,MAmDpD,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,6BAA6B,WAAY,iBAAiB,KAAG,MAuBzE,CAAA"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateEmailLocaleModuleCode = exports.generateWorkflowLocaleHelpersCode = exports.generateEmailLocaleHelpersCode = void 0;
|
|
4
|
+
const email_locale_scope_1 = require("./email-locale-scope");
|
|
5
|
+
/**
|
|
6
|
+
* The locale helpers every generated email sender and every generated
|
|
7
|
+
* navigation runs. Emitted twice from this one source: as the standalone
|
|
8
|
+
* `utils/email/email-locale.js` module (the account routes, the invoice
|
|
9
|
+
* sender, the cart route and the cart provider use it) and inlined into the
|
|
10
|
+
* workflow runtime (`runtime-utils.js`), which is bundled for the browser as
|
|
11
|
+
* well and must not depend on a sibling file being resolvable.
|
|
12
|
+
*
|
|
13
|
+
* Every function is total: an unknown or missing locale resolves to the
|
|
14
|
+
* project's default language, so a sender can never pick a template that does
|
|
15
|
+
* not exist and a navigation can never be sent to a locale the app does not
|
|
16
|
+
* serve.
|
|
17
|
+
*/
|
|
18
|
+
const generateEmailLocaleHelpersCode = (config) => `
|
|
19
|
+
var EMAIL_LOCALES = ${JSON.stringify(config.locales)};
|
|
20
|
+
var DEFAULT_EMAIL_LOCALE = ${JSON.stringify(config.defaultLocale)};
|
|
21
|
+
var EMAIL_LOCALE_HEADER = ${JSON.stringify(email_locale_scope_1.EMAIL_LOCALE_HEADER)};
|
|
22
|
+
var NEXT_LOCALE_COOKIE = ${JSON.stringify(email_locale_scope_1.NEXT_LOCALE_COOKIE)};
|
|
23
|
+
|
|
24
|
+
// The project locale a raw value names, or null. Case-insensitive so a
|
|
25
|
+
// visitor-supplied "ES" still matches, but always answers the canonical code.
|
|
26
|
+
function normalizeEmailLocale(value) {
|
|
27
|
+
if (typeof value !== 'string') return null;
|
|
28
|
+
var trimmed = value.trim();
|
|
29
|
+
if (!trimmed) return null;
|
|
30
|
+
var lower = trimmed.toLowerCase();
|
|
31
|
+
for (var i = 0; i < EMAIL_LOCALES.length; i++) {
|
|
32
|
+
if (String(EMAIL_LOCALES[i]).toLowerCase() === lower) return EMAIL_LOCALES[i];
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function readCookieValue(cookieHeader, name) {
|
|
38
|
+
if (typeof cookieHeader !== 'string' || !cookieHeader) return null;
|
|
39
|
+
var parts = cookieHeader.split(';');
|
|
40
|
+
for (var i = 0; i < parts.length; i++) {
|
|
41
|
+
var pair = parts[i].trim();
|
|
42
|
+
var eq = pair.indexOf('=');
|
|
43
|
+
if (eq === -1) continue;
|
|
44
|
+
if (pair.slice(0, eq).trim() !== name) continue;
|
|
45
|
+
try { return decodeURIComponent(pair.slice(eq + 1).trim()); } catch (e) { return pair.slice(eq + 1).trim(); }
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The locale prefix of a localized page path ("/es/checkout" → "es"). The
|
|
51
|
+
// default language is served unprefixed, which resolves to null here and to
|
|
52
|
+
// the default further down.
|
|
53
|
+
function localeFromPathname(pathname) {
|
|
54
|
+
if (typeof pathname !== 'string') return null;
|
|
55
|
+
var segments = pathname.split('/');
|
|
56
|
+
for (var i = 0; i < segments.length; i++) {
|
|
57
|
+
if (segments[i]) return normalizeEmailLocale(segments[i]);
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function firstHeaderValue(value) {
|
|
63
|
+
return Array.isArray(value) ? value[0] : value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The language of the page a request came from: the explicit header the
|
|
67
|
+
// generated client runtime sends, else the locale prefix of the referring page
|
|
68
|
+
// (the page the browser is actually on), else the Next.js locale cookie (a
|
|
69
|
+
// stored preference, which a request without a referer is all we have), else
|
|
70
|
+
// the default language.
|
|
71
|
+
function resolveRequestLocale(req) {
|
|
72
|
+
var headers = req && req.headers ? req.headers : null;
|
|
73
|
+
if (!headers) return DEFAULT_EMAIL_LOCALE;
|
|
74
|
+
var fromHeader = normalizeEmailLocale(firstHeaderValue(headers[EMAIL_LOCALE_HEADER]));
|
|
75
|
+
if (fromHeader) return fromHeader;
|
|
76
|
+
var referer = firstHeaderValue(headers.referer || headers.referrer);
|
|
77
|
+
if (typeof referer === 'string' && referer) {
|
|
78
|
+
try {
|
|
79
|
+
var fromReferer = localeFromPathname(new URL(referer).pathname);
|
|
80
|
+
if (fromReferer) return fromReferer;
|
|
81
|
+
} catch (e) { /* not an absolute URL — nothing to read */ }
|
|
82
|
+
}
|
|
83
|
+
var fromCookie = normalizeEmailLocale(readCookieValue(firstHeaderValue(headers.cookie), NEXT_LOCALE_COOKIE));
|
|
84
|
+
if (fromCookie) return fromCookie;
|
|
85
|
+
return DEFAULT_EMAIL_LOCALE;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The locale of the page the browser is on, read LIVE off the Next.js router.
|
|
89
|
+
// After a client-side language switch the page data
|
|
90
|
+
// (window.__NEXT_DATA__.locale) still names the locale the document was
|
|
91
|
+
// served in, while the router — and the <html lang> attribute it keeps in
|
|
92
|
+
// sync on every transition — already name the one the visitor switched to.
|
|
93
|
+
// Null outside a browser, or when no candidate is a project locale.
|
|
94
|
+
function getClientLocale() {
|
|
95
|
+
if (typeof window === 'undefined') return null;
|
|
96
|
+
var candidates = [];
|
|
97
|
+
try { candidates.push(window.next && window.next.router && window.next.router.locale); } catch (e) { /* router not mounted */ }
|
|
98
|
+
try { candidates.push(document.documentElement && document.documentElement.lang); } catch (e) { /* no document */ }
|
|
99
|
+
try { candidates.push(window.__NEXT_DATA__ && window.__NEXT_DATA__.locale); } catch (e) { /* no page data */ }
|
|
100
|
+
for (var i = 0; i < candidates.length; i++) {
|
|
101
|
+
var resolved = normalizeEmailLocale(candidates[i]);
|
|
102
|
+
if (resolved) return resolved;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// The href a navigation should use so the visitor stays in \`locale\`. Next.js
|
|
108
|
+
// serves the default language unprefixed and every other language under
|
|
109
|
+
// "/<locale>", so a site-relative page path gets that prefix. Left untouched:
|
|
110
|
+
// anything that is not a site-relative path (an external URL, a hash, a
|
|
111
|
+
// mailto:), an API route or a Next.js internal path (never localized), a file
|
|
112
|
+
// served from /public (not served under a locale prefix) and a path that
|
|
113
|
+
// already names a project locale. The default language, an unknown locale and
|
|
114
|
+
// a project without languages all leave the href as it is.
|
|
115
|
+
function localizeHref(href, locale) {
|
|
116
|
+
if (typeof href !== 'string' || href.charAt(0) !== '/' || href.charAt(1) === '/') return href;
|
|
117
|
+
var resolved = normalizeEmailLocale(locale);
|
|
118
|
+
if (!resolved || resolved === DEFAULT_EMAIL_LOCALE) return href;
|
|
119
|
+
var pathEnd = href.length;
|
|
120
|
+
var queryStart = href.indexOf('?');
|
|
121
|
+
if (queryStart !== -1) pathEnd = queryStart;
|
|
122
|
+
var hashStart = href.indexOf('#');
|
|
123
|
+
if (hashStart !== -1 && hashStart < pathEnd) pathEnd = hashStart;
|
|
124
|
+
var pathname = href.slice(0, pathEnd);
|
|
125
|
+
if (pathname === '/api' || pathname.indexOf('/api/') === 0) return href;
|
|
126
|
+
if (pathname.indexOf('/_next/') === 0) return href;
|
|
127
|
+
if (/\\.[A-Za-z0-9]{1,5}$/.test(pathname)) return href;
|
|
128
|
+
if (localeFromPathname(pathname)) return href;
|
|
129
|
+
return '/' + resolved + (pathname === '/' ? '' : pathname) + href.slice(pathEnd);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// The copy of a template that goes out in \`locale\`: its own body, its own
|
|
133
|
+
// subject when it has one (else the base subject), or the base copy for the
|
|
134
|
+
// default language and for any language that has no copy.
|
|
135
|
+
function pickLocalizedTemplate(base, localized, locale) {
|
|
136
|
+
var baseCopy = base || {};
|
|
137
|
+
var resolved = normalizeEmailLocale(locale) || DEFAULT_EMAIL_LOCALE;
|
|
138
|
+
var fallback = { subject: baseCopy.subject, body: baseCopy.body, locale: DEFAULT_EMAIL_LOCALE };
|
|
139
|
+
if (!resolved || resolved === DEFAULT_EMAIL_LOCALE) return fallback;
|
|
140
|
+
if (!localized || typeof localized !== 'object') return fallback;
|
|
141
|
+
var copy = localized[resolved];
|
|
142
|
+
if (!copy || typeof copy !== 'object' || typeof copy.body !== 'string' || !copy.body) return fallback;
|
|
143
|
+
return {
|
|
144
|
+
subject: typeof copy.subject === 'string' && copy.subject ? copy.subject : baseCopy.subject,
|
|
145
|
+
body: copy.body,
|
|
146
|
+
locale: resolved,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
`;
|
|
150
|
+
exports.generateEmailLocaleHelpersCode = generateEmailLocaleHelpersCode;
|
|
151
|
+
/**
|
|
152
|
+
* The runtime-only helpers, on top of the shared ones: how a workflow run
|
|
153
|
+
* learns its locale and how an email node's config resolves the language it
|
|
154
|
+
* sends in. Inlined into \`runtime-utils.js\` right after
|
|
155
|
+
* \`generateEmailLocaleHelpersCode\`.
|
|
156
|
+
*/
|
|
157
|
+
const generateWorkflowLocaleHelpersCode = () => `
|
|
158
|
+
// The locale a server route runs a segment in: the one the client runtime put
|
|
159
|
+
// on the context (validated — it crossed the network), else the request's.
|
|
160
|
+
function resolveWorkflowLocale(req, incomingContext) {
|
|
161
|
+
var fromContext = incomingContext ? normalizeEmailLocale(incomingContext[${JSON.stringify(email_locale_scope_1.WORKFLOW_CONTEXT_LOCALE_KEY)}]) : null;
|
|
162
|
+
return fromContext || resolveRequestLocale(req);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// The language an email node sends in. A config that BINDS the locale (the
|
|
166
|
+
// order's, the cart's) is authoritative even when the binding resolved to
|
|
167
|
+
// nothing — the request locale belongs to whoever triggered the workflow, which
|
|
168
|
+
// for an admin action is not the recipient. Otherwise the run's locale, then
|
|
169
|
+
// the default language.
|
|
170
|
+
function resolveEmailLocale(resolvedConfig, context) {
|
|
171
|
+
var config = resolvedConfig || {};
|
|
172
|
+
if (Object.prototype.hasOwnProperty.call(config, ${JSON.stringify(email_locale_scope_1.EMAIL_LOCALE_CONFIG_KEY)})) {
|
|
173
|
+
return normalizeEmailLocale(config[${JSON.stringify(email_locale_scope_1.EMAIL_LOCALE_CONFIG_KEY)}]) || DEFAULT_EMAIL_LOCALE;
|
|
174
|
+
}
|
|
175
|
+
var fromRun = context ? normalizeEmailLocale(context[${JSON.stringify(email_locale_scope_1.WORKFLOW_CONTEXT_LOCALE_KEY)}]) : null;
|
|
176
|
+
return fromRun || DEFAULT_EMAIL_LOCALE;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Swaps a component-bodied email node's body/subject for the copy of the
|
|
180
|
+
// language it sends in, then drops the per-language map and the binding so
|
|
181
|
+
// neither reaches a provider handler or the sent-email ledger. Runs BEFORE the
|
|
182
|
+
// {{token}} fill: the copies carry the same merge fields as the base body.
|
|
183
|
+
function applyLocalizedEmailTemplate(resolvedConfig, context) {
|
|
184
|
+
var localized = resolvedConfig[${JSON.stringify(email_locale_scope_1.LOCALIZED_TEMPLATES_CONFIG_KEY)}];
|
|
185
|
+
var hasLocalized = !!localized && typeof localized === 'object';
|
|
186
|
+
var hasBinding = Object.prototype.hasOwnProperty.call(resolvedConfig, ${JSON.stringify(email_locale_scope_1.EMAIL_LOCALE_CONFIG_KEY)});
|
|
187
|
+
if (!hasLocalized && !hasBinding) return;
|
|
188
|
+
if (hasLocalized) {
|
|
189
|
+
var picked = pickLocalizedTemplate(
|
|
190
|
+
{ subject: resolvedConfig.subject, body: resolvedConfig.body },
|
|
191
|
+
localized,
|
|
192
|
+
resolveEmailLocale(resolvedConfig, context)
|
|
193
|
+
);
|
|
194
|
+
if (typeof picked.body === 'string') resolvedConfig.body = picked.body;
|
|
195
|
+
if (typeof picked.subject === 'string') resolvedConfig.subject = picked.subject;
|
|
196
|
+
delete resolvedConfig[${JSON.stringify(email_locale_scope_1.LOCALIZED_TEMPLATES_CONFIG_KEY)}];
|
|
197
|
+
}
|
|
198
|
+
if (hasBinding) delete resolvedConfig[${JSON.stringify(email_locale_scope_1.EMAIL_LOCALE_CONFIG_KEY)}];
|
|
199
|
+
}
|
|
200
|
+
`;
|
|
201
|
+
exports.generateWorkflowLocaleHelpersCode = generateWorkflowLocaleHelpersCode;
|
|
202
|
+
/** `utils/email/email-locale.js` — the shared helpers as a CommonJS module. */
|
|
203
|
+
const generateEmailLocaleModuleCode = (config) => `/**
|
|
204
|
+
* Email locale resolution.
|
|
205
|
+
*
|
|
206
|
+
* A customer email goes out in the language of the page it was triggered from;
|
|
207
|
+
* the store owner's notifications always use the project's main language. This
|
|
208
|
+
* module answers "which locale?" for the senders that live outside the workflow
|
|
209
|
+
* runtime (the account routes, the invoice sender, the cart route) — the
|
|
210
|
+
* runtime carries the same helpers inline.
|
|
211
|
+
*
|
|
212
|
+
* Auto-generated. Edit the generator at
|
|
213
|
+
* teleport-plugin-next-workflows/src/email-locale/email-locale-code.ts.
|
|
214
|
+
*/
|
|
215
|
+
${(0, exports.generateEmailLocaleHelpersCode)(config)}
|
|
216
|
+
module.exports = {
|
|
217
|
+
EMAIL_LOCALES: EMAIL_LOCALES,
|
|
218
|
+
DEFAULT_EMAIL_LOCALE: DEFAULT_EMAIL_LOCALE,
|
|
219
|
+
EMAIL_LOCALE_HEADER: EMAIL_LOCALE_HEADER,
|
|
220
|
+
normalizeEmailLocale: normalizeEmailLocale,
|
|
221
|
+
resolveRequestLocale: resolveRequestLocale,
|
|
222
|
+
getClientLocale: getClientLocale,
|
|
223
|
+
localizeHref: localizeHref,
|
|
224
|
+
pickLocalizedTemplate: pickLocalizedTemplate,
|
|
225
|
+
};
|
|
226
|
+
`;
|
|
227
|
+
exports.generateEmailLocaleModuleCode = generateEmailLocaleModuleCode;
|
|
228
|
+
//# sourceMappingURL=email-locale-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-locale-code.js","sourceRoot":"","sources":["../../../src/email-locale/email-locale-code.ts"],"names":[],"mappings":";;;AAAA,6DAO6B;AAE7B;;;;;;;;;;;;GAYG;AACI,MAAM,8BAA8B,GAAG,CAAC,MAAyB,EAAU,EAAE,CAAC;sBAC/D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC;6BACvB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC;4BACrC,IAAI,CAAC,SAAS,CAAC,wCAAmB,CAAC;2BACpC,IAAI,CAAC,SAAS,CAAC,uCAAkB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+H5D,CAAA;AAnIY,QAAA,8BAA8B,kCAmI1C;AAED;;;;;GAKG;AACI,MAAM,iCAAiC,GAAG,GAAW,EAAE,CAAC;;;;6EAIc,IAAI,CAAC,SAAS,CACvF,gDAA2B,CAC5B;;;;;;;;;;;qDAWkD,IAAI,CAAC,SAAS,CAAC,4CAAuB,CAAC;yCACnD,IAAI,CAAC,SAAS,CACjD,4CAAuB,CACxB;;yDAEoD,IAAI,CAAC,SAAS,CACnE,gDAA2B,CAC5B;;;;;;;;;mCASgC,IAAI,CAAC,SAAS,CAAC,mDAA8B,CAAC;;0EAEP,IAAI,CAAC,SAAS,CACpF,4CAAuB,CACxB;;;;;;;;;;4BAUyB,IAAI,CAAC,SAAS,CAAC,mDAA8B,CAAC;;0CAEhC,IAAI,CAAC,SAAS,CAAC,4CAAuB,CAAC;;CAEhF,CAAA;AAnDY,QAAA,iCAAiC,qCAmD7C;AAED,+EAA+E;AACxE,MAAM,6BAA6B,GAAG,CAAC,MAAyB,EAAU,EAAE,CAAC;;;;;;;;;;;;EAYlF,IAAA,sCAA8B,EAAC,MAAM,CAAC;;;;;;;;;;;CAWvC,CAAA;AAvBY,QAAA,6BAA6B,iCAuBzC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ProjectUIDL } from '@teleporthq/teleport-types';
|
|
2
|
+
/**
|
|
3
|
+
* The vocabulary every generated email sender shares to decide WHICH language a
|
|
4
|
+
* customer email goes out in. The module itself is emitted by
|
|
5
|
+
* `ensureEmailLocaleModule` (see `index.ts`); this file only holds the names
|
|
6
|
+
* the route generators, the workflow runtime and the UIDL mapper agree on.
|
|
7
|
+
*/
|
|
8
|
+
export declare const EMAIL_LOCALE_FILE_KEY = "email-locale";
|
|
9
|
+
export declare const EMAIL_LOCALE_PATH: string[];
|
|
10
|
+
export declare const EMAIL_LOCALE_FILE_NAME = "email-locale";
|
|
11
|
+
/**
|
|
12
|
+
* Request header the generated client runtime sends with every call to the
|
|
13
|
+
* app's own API routes, carrying the locale of the page the visitor is on.
|
|
14
|
+
*/
|
|
15
|
+
export declare const EMAIL_LOCALE_HEADER = "x-teleport-locale";
|
|
16
|
+
/** The cookie Next.js reads for locale detection; honoured as a fallback. */
|
|
17
|
+
export declare const NEXT_LOCALE_COOKIE = "NEXT_LOCALE";
|
|
18
|
+
/**
|
|
19
|
+
* Export-only node config key written by the editor's domain→UIDL mapper on a
|
|
20
|
+
* component-bodied email node: the per-language copies of its body/subject,
|
|
21
|
+
* keyed by locale short code (main language excluded). Consumed by the runtime
|
|
22
|
+
* (`resolveConfig`) and never by a handler.
|
|
23
|
+
*/
|
|
24
|
+
export declare const LOCALIZED_TEMPLATES_CONFIG_KEY = "localizedTemplates";
|
|
25
|
+
/**
|
|
26
|
+
* Node config key that pins an email to a language independently of the
|
|
27
|
+
* request: a lifecycle email bound to the order's stored locale, a reminder
|
|
28
|
+
* bound to the cart's. When the key is present its resolved value is
|
|
29
|
+
* authoritative — an empty one means the default language, never the locale of
|
|
30
|
+
* whoever triggered the workflow (an admin shipping an order is not the buyer).
|
|
31
|
+
*/
|
|
32
|
+
export declare const EMAIL_LOCALE_CONFIG_KEY = "emailLocale";
|
|
33
|
+
/** Workflow-context key carrying the request locale through a run. */
|
|
34
|
+
export declare const WORKFLOW_CONTEXT_LOCALE_KEY = "__locale";
|
|
35
|
+
/**
|
|
36
|
+
* The locales the generated app serves, as the email senders need them: the
|
|
37
|
+
* full list to validate an incoming value against and the default to fall back
|
|
38
|
+
* to. A project without internationalization has no locales at all — every
|
|
39
|
+
* sender then keeps its single template and nothing is ever localized.
|
|
40
|
+
*/
|
|
41
|
+
export interface EmailLocaleConfig {
|
|
42
|
+
locales: string[];
|
|
43
|
+
defaultLocale: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const resolveEmailLocaleConfig: (uidl: ProjectUIDL) => EmailLocaleConfig;
|
|
46
|
+
//# sourceMappingURL=email-locale-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-locale-scope.d.ts","sourceRoot":"","sources":["../../../src/email-locale/email-locale-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD;;;;;GAKG;AAEH,eAAO,MAAM,qBAAqB,iBAAiB,CAAA;AACnD,eAAO,MAAM,iBAAiB,UAAqB,CAAA;AACnD,eAAO,MAAM,sBAAsB,iBAAiB,CAAA;AAEpD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,sBAAsB,CAAA;AAEtD,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,gBAAgB,CAAA;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,uBAAuB,CAAA;AAElE;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBAAgB,CAAA;AAEpD,sEAAsE;AACtE,eAAO,MAAM,2BAA2B,aAAa,CAAA;AAErD;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,eAAO,MAAM,wBAAwB,SAAU,WAAW,KAAG,iBAW5D,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEmailLocaleConfig = exports.WORKFLOW_CONTEXT_LOCALE_KEY = exports.EMAIL_LOCALE_CONFIG_KEY = exports.LOCALIZED_TEMPLATES_CONFIG_KEY = exports.NEXT_LOCALE_COOKIE = exports.EMAIL_LOCALE_HEADER = exports.EMAIL_LOCALE_FILE_NAME = exports.EMAIL_LOCALE_PATH = exports.EMAIL_LOCALE_FILE_KEY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The vocabulary every generated email sender shares to decide WHICH language a
|
|
6
|
+
* customer email goes out in. The module itself is emitted by
|
|
7
|
+
* `ensureEmailLocaleModule` (see `index.ts`); this file only holds the names
|
|
8
|
+
* the route generators, the workflow runtime and the UIDL mapper agree on.
|
|
9
|
+
*/
|
|
10
|
+
exports.EMAIL_LOCALE_FILE_KEY = 'email-locale';
|
|
11
|
+
exports.EMAIL_LOCALE_PATH = ['utils', 'email'];
|
|
12
|
+
exports.EMAIL_LOCALE_FILE_NAME = 'email-locale';
|
|
13
|
+
/**
|
|
14
|
+
* Request header the generated client runtime sends with every call to the
|
|
15
|
+
* app's own API routes, carrying the locale of the page the visitor is on.
|
|
16
|
+
*/
|
|
17
|
+
exports.EMAIL_LOCALE_HEADER = 'x-teleport-locale';
|
|
18
|
+
/** The cookie Next.js reads for locale detection; honoured as a fallback. */
|
|
19
|
+
exports.NEXT_LOCALE_COOKIE = 'NEXT_LOCALE';
|
|
20
|
+
/**
|
|
21
|
+
* Export-only node config key written by the editor's domain→UIDL mapper on a
|
|
22
|
+
* component-bodied email node: the per-language copies of its body/subject,
|
|
23
|
+
* keyed by locale short code (main language excluded). Consumed by the runtime
|
|
24
|
+
* (`resolveConfig`) and never by a handler.
|
|
25
|
+
*/
|
|
26
|
+
exports.LOCALIZED_TEMPLATES_CONFIG_KEY = 'localizedTemplates';
|
|
27
|
+
/**
|
|
28
|
+
* Node config key that pins an email to a language independently of the
|
|
29
|
+
* request: a lifecycle email bound to the order's stored locale, a reminder
|
|
30
|
+
* bound to the cart's. When the key is present its resolved value is
|
|
31
|
+
* authoritative — an empty one means the default language, never the locale of
|
|
32
|
+
* whoever triggered the workflow (an admin shipping an order is not the buyer).
|
|
33
|
+
*/
|
|
34
|
+
exports.EMAIL_LOCALE_CONFIG_KEY = 'emailLocale';
|
|
35
|
+
/** Workflow-context key carrying the request locale through a run. */
|
|
36
|
+
exports.WORKFLOW_CONTEXT_LOCALE_KEY = '__locale';
|
|
37
|
+
const resolveEmailLocaleConfig = (uidl) => {
|
|
38
|
+
var _a;
|
|
39
|
+
const i18n = uidl.internationalization;
|
|
40
|
+
if (!i18n) {
|
|
41
|
+
return { locales: [], defaultLocale: '' };
|
|
42
|
+
}
|
|
43
|
+
const defaultLocale = ((_a = i18n.main) === null || _a === void 0 ? void 0 : _a.locale) || '';
|
|
44
|
+
const locales = Object.keys(i18n.languages || {});
|
|
45
|
+
if (defaultLocale && locales.indexOf(defaultLocale) === -1) {
|
|
46
|
+
locales.unshift(defaultLocale);
|
|
47
|
+
}
|
|
48
|
+
return { locales, defaultLocale };
|
|
49
|
+
};
|
|
50
|
+
exports.resolveEmailLocaleConfig = resolveEmailLocaleConfig;
|
|
51
|
+
//# sourceMappingURL=email-locale-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-locale-scope.js","sourceRoot":"","sources":["../../../src/email-locale/email-locale-scope.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AAEU,QAAA,qBAAqB,GAAG,cAAc,CAAA;AACtC,QAAA,iBAAiB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACtC,QAAA,sBAAsB,GAAG,cAAc,CAAA;AAEpD;;;GAGG;AACU,QAAA,mBAAmB,GAAG,mBAAmB,CAAA;AAEtD,6EAA6E;AAChE,QAAA,kBAAkB,GAAG,aAAa,CAAA;AAE/C;;;;;GAKG;AACU,QAAA,8BAA8B,GAAG,oBAAoB,CAAA;AAElE;;;;;;GAMG;AACU,QAAA,uBAAuB,GAAG,aAAa,CAAA;AAEpD,sEAAsE;AACzD,QAAA,2BAA2B,GAAG,UAAU,CAAA;AAa9C,MAAM,wBAAwB,GAAG,CAAC,IAAiB,EAAqB,EAAE;;IAC/E,MAAM,IAAI,GAAG,IAAI,CAAC,oBAAoB,CAAA;IACtC,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,CAAA;KAC1C;IACD,MAAM,aAAa,GAAG,CAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,MAAM,KAAI,EAAE,CAAA;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;IACjD,IAAI,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE;QAC1D,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;KAC/B;IACD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAA;AACnC,CAAC,CAAA;AAXY,QAAA,wBAAwB,4BAWpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ProjectPluginStructure } from '@teleporthq/teleport-types';
|
|
2
|
+
export { EMAIL_LOCALE_CONFIG_KEY, EMAIL_LOCALE_HEADER, EmailLocaleConfig, LOCALIZED_TEMPLATES_CONFIG_KEY, WORKFLOW_CONTEXT_LOCALE_KEY, resolveEmailLocaleConfig, } from './email-locale-scope';
|
|
3
|
+
export { generateEmailLocaleHelpersCode, generateEmailLocaleModuleCode, generateWorkflowLocaleHelpersCode, } from './email-locale-code';
|
|
4
|
+
/**
|
|
5
|
+
* Writes `utils/email/email-locale.js` into the project, once. Like the
|
|
6
|
+
* sent-email ledger, every emitter of a send path that lives outside the
|
|
7
|
+
* workflow runtime calls this right where it emits the `require`, so the file
|
|
8
|
+
* exists exactly when something needs it, whichever plugin ran first.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ensureEmailLocaleModule: (structure: ProjectPluginStructure) => void;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/email-locale/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAS7E,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,8BAA8B,EAC9B,6BAA6B,EAC7B,iCAAiC,GAClC,MAAM,qBAAqB,CAAA;AAE5B;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,cAAe,sBAAsB,KAAG,IAgB3E,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureEmailLocaleModule = exports.generateWorkflowLocaleHelpersCode = exports.generateEmailLocaleModuleCode = exports.generateEmailLocaleHelpersCode = exports.resolveEmailLocaleConfig = exports.WORKFLOW_CONTEXT_LOCALE_KEY = exports.LOCALIZED_TEMPLATES_CONFIG_KEY = exports.EMAIL_LOCALE_HEADER = exports.EMAIL_LOCALE_CONFIG_KEY = void 0;
|
|
4
|
+
const teleport_types_1 = require("@teleporthq/teleport-types");
|
|
5
|
+
const email_locale_code_1 = require("./email-locale-code");
|
|
6
|
+
const email_locale_scope_1 = require("./email-locale-scope");
|
|
7
|
+
var email_locale_scope_2 = require("./email-locale-scope");
|
|
8
|
+
Object.defineProperty(exports, "EMAIL_LOCALE_CONFIG_KEY", { enumerable: true, get: function () { return email_locale_scope_2.EMAIL_LOCALE_CONFIG_KEY; } });
|
|
9
|
+
Object.defineProperty(exports, "EMAIL_LOCALE_HEADER", { enumerable: true, get: function () { return email_locale_scope_2.EMAIL_LOCALE_HEADER; } });
|
|
10
|
+
Object.defineProperty(exports, "LOCALIZED_TEMPLATES_CONFIG_KEY", { enumerable: true, get: function () { return email_locale_scope_2.LOCALIZED_TEMPLATES_CONFIG_KEY; } });
|
|
11
|
+
Object.defineProperty(exports, "WORKFLOW_CONTEXT_LOCALE_KEY", { enumerable: true, get: function () { return email_locale_scope_2.WORKFLOW_CONTEXT_LOCALE_KEY; } });
|
|
12
|
+
Object.defineProperty(exports, "resolveEmailLocaleConfig", { enumerable: true, get: function () { return email_locale_scope_2.resolveEmailLocaleConfig; } });
|
|
13
|
+
var email_locale_code_2 = require("./email-locale-code");
|
|
14
|
+
Object.defineProperty(exports, "generateEmailLocaleHelpersCode", { enumerable: true, get: function () { return email_locale_code_2.generateEmailLocaleHelpersCode; } });
|
|
15
|
+
Object.defineProperty(exports, "generateEmailLocaleModuleCode", { enumerable: true, get: function () { return email_locale_code_2.generateEmailLocaleModuleCode; } });
|
|
16
|
+
Object.defineProperty(exports, "generateWorkflowLocaleHelpersCode", { enumerable: true, get: function () { return email_locale_code_2.generateWorkflowLocaleHelpersCode; } });
|
|
17
|
+
/**
|
|
18
|
+
* Writes `utils/email/email-locale.js` into the project, once. Like the
|
|
19
|
+
* sent-email ledger, every emitter of a send path that lives outside the
|
|
20
|
+
* workflow runtime calls this right where it emits the `require`, so the file
|
|
21
|
+
* exists exactly when something needs it, whichever plugin ran first.
|
|
22
|
+
*/
|
|
23
|
+
const ensureEmailLocaleModule = (structure) => {
|
|
24
|
+
const { files, uidl } = structure;
|
|
25
|
+
if (files.has(email_locale_scope_1.EMAIL_LOCALE_FILE_KEY)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
files.set(email_locale_scope_1.EMAIL_LOCALE_FILE_KEY, {
|
|
29
|
+
path: email_locale_scope_1.EMAIL_LOCALE_PATH,
|
|
30
|
+
files: [
|
|
31
|
+
{
|
|
32
|
+
name: email_locale_scope_1.EMAIL_LOCALE_FILE_NAME,
|
|
33
|
+
fileType: teleport_types_1.FileType.JS,
|
|
34
|
+
content: (0, email_locale_code_1.generateEmailLocaleModuleCode)((0, email_locale_scope_1.resolveEmailLocaleConfig)(uidl)),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
exports.ensureEmailLocaleModule = ensureEmailLocaleModule;
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/email-locale/index.ts"],"names":[],"mappings":";;;AAAA,+DAA6E;AAC7E,2DAAmE;AACnE,6DAK6B;AAE7B,2DAO6B;AAN3B,6HAAA,uBAAuB,OAAA;AACvB,yHAAA,mBAAmB,OAAA;AAEnB,oIAAA,8BAA8B,OAAA;AAC9B,iIAAA,2BAA2B,OAAA;AAC3B,8HAAA,wBAAwB,OAAA;AAE1B,yDAI4B;AAH1B,mIAAA,8BAA8B,OAAA;AAC9B,kIAAA,6BAA6B,OAAA;AAC7B,sIAAA,iCAAiC,OAAA;AAGnC;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CAAC,SAAiC,EAAQ,EAAE;IACjF,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,CAAA;IACjC,IAAI,KAAK,CAAC,GAAG,CAAC,0CAAqB,CAAC,EAAE;QACpC,OAAM;KACP;IAED,KAAK,CAAC,GAAG,CAAC,0CAAqB,EAAE;QAC/B,IAAI,EAAE,sCAAiB;QACvB,KAAK,EAAE;YACL;gBACE,IAAI,EAAE,2CAAsB;gBAC5B,QAAQ,EAAE,yBAAQ,CAAC,EAAE;gBACrB,OAAO,EAAE,IAAA,iDAA6B,EAAC,IAAA,6CAAwB,EAAC,IAAI,CAAC,CAAC;aACvE;SACF;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAhBY,QAAA,uBAAuB,2BAgBnC"}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { EmailLocaleConfig } from './email-locale';
|
|
2
|
+
export interface SharedRuntimeUtilsOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The project's locales, baked in so the runtime can validate the locale a
|
|
5
|
+
* request or the browser reports and pick the matching copy of a localized
|
|
6
|
+
* email. Absent (a project without internationalization): no locale is ever
|
|
7
|
+
* recognised and every email keeps its single template.
|
|
8
|
+
*/
|
|
9
|
+
emailLocales?: EmailLocaleConfig;
|
|
10
|
+
}
|
|
11
|
+
export declare const generateSharedRuntimeUtilsCode: (options?: SharedRuntimeUtilsOptions) => string;
|
|
2
12
|
export declare const generateClientRuntimeCode: () => string;
|
|
3
13
|
export declare const generateServerRuntimeCode: () => string;
|
|
4
14
|
//# sourceMappingURL=executor-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor-generator.d.ts","sourceRoot":"","sources":["../../src/executor-generator.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,
|
|
1
|
+
{"version":3,"file":"executor-generator.d.ts","sourceRoot":"","sources":["../../src/executor-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAGlB,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAA;CACjC;AAID,eAAO,MAAM,8BAA8B,aAAa,yBAAyB,KAAQ,MA2zCxF,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAO,MA2lB5C,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAO,MAK5C,CAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateServerRuntimeCode = exports.generateClientRuntimeCode = exports.generateSharedRuntimeUtilsCode = void 0;
|
|
4
|
-
const
|
|
4
|
+
const email_locale_1 = require("./email-locale");
|
|
5
|
+
const NO_EMAIL_LOCALES = { locales: [], defaultLocale: '' };
|
|
6
|
+
const generateSharedRuntimeUtilsCode = (options = {}) => {
|
|
5
7
|
return `/**
|
|
6
8
|
* Workflow Runtime Utilities
|
|
7
9
|
*
|
|
@@ -11,7 +13,8 @@ const generateSharedRuntimeUtilsCode = () => {
|
|
|
11
13
|
* - executeNodes: Executes a sequence of workflow nodes
|
|
12
14
|
* - executeWorkflow: Main workflow execution entry point
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
${(0, email_locale_1.generateEmailLocaleHelpersCode)(options.emailLocales || NO_EMAIL_LOCALES)}
|
|
17
|
+
${(0, email_locale_1.generateWorkflowLocaleHelpersCode)()}
|
|
15
18
|
function resolveValue(value, context) {
|
|
16
19
|
if (value === null || value === undefined) return value;
|
|
17
20
|
if (Array.isArray(value)) {
|
|
@@ -525,6 +528,11 @@ function resolveConfig(config, context) {
|
|
|
525
528
|
//
|
|
526
529
|
// Runs after resolution on purpose: \`templateParams[].value\` is itself a
|
|
527
530
|
// workflow-context ref that the loop above has just resolved.
|
|
531
|
+
//
|
|
532
|
+
// The language is chosen first, for the same reason: a customer email carries
|
|
533
|
+
// one copy per project language, and the copy has to be picked before its
|
|
534
|
+
// tokens are filled.
|
|
535
|
+
applyLocalizedEmailTemplate(resolved, context);
|
|
528
536
|
if (Array.isArray(resolved.templateParams)) {
|
|
529
537
|
if (typeof resolved.body === 'string') {
|
|
530
538
|
resolved.body = applyTemplateParams(resolved.body, resolved.templateParams);
|
|
@@ -654,6 +662,12 @@ async function executeWorkflow(workflowConfig, triggerContext, nodeHandlers, opt
|
|
|
654
662
|
if (triggerContext && triggerContext.triggerElement) {
|
|
655
663
|
context.triggerElement = triggerContext.triggerElement;
|
|
656
664
|
}
|
|
665
|
+
// The language of the page this run started on, carried to every server
|
|
666
|
+
// segment (the context crosses whole) so a customer email can be sent in it.
|
|
667
|
+
var runLocale = getClientLocale();
|
|
668
|
+
if (runLocale) {
|
|
669
|
+
context.__locale = runLocale;
|
|
670
|
+
}
|
|
657
671
|
|
|
658
672
|
const callServerSegment = options.callServerSegment;
|
|
659
673
|
|
|
@@ -753,6 +767,15 @@ function isFireAndForgetNode(node) {
|
|
|
753
767
|
return !!node.config && node.config.awaitResult === false;
|
|
754
768
|
}
|
|
755
769
|
|
|
770
|
+
// A node the author marked \`continueOnError\`: a failed RESULT ({ success:
|
|
771
|
+
// false } / { error }) is published under the node's id like any other result
|
|
772
|
+
// instead of aborting the workflow, so a later if-statement can read
|
|
773
|
+
// \`success\` and warn. Only an explicit \`true\` opts in. A handler that THROWS
|
|
774
|
+
// still aborts — every provider handler reports failure as a result.
|
|
775
|
+
function continuesOnError(node) {
|
|
776
|
+
return !!(node && node.config && node.config.continueOnError === true);
|
|
777
|
+
}
|
|
778
|
+
|
|
756
779
|
// Starts a fire-and-forget node and returns a promise that ALWAYS resolves.
|
|
757
780
|
// The workflow has already moved on, so a failure here can neither abort it nor
|
|
758
781
|
// reach the error handler — it is reported to the console and swallowed, which
|
|
@@ -794,10 +817,13 @@ async function settlePendingNodePromises(context) {
|
|
|
794
817
|
for (var pass = 0; pass < 5; pass++) {
|
|
795
818
|
var pending = context.__pendingNodePromises;
|
|
796
819
|
if (!pending || pending.length === 0) return;
|
|
797
|
-
|
|
820
|
+
// Drained IN PLACE, never by swapping in a fresh array: a parallel branch
|
|
821
|
+
// that is still running holds a reference to this very array (its context
|
|
822
|
+
// is a shallow copy) and must keep landing on the queue the route drains.
|
|
823
|
+
var batch = pending.splice(0, pending.length);
|
|
798
824
|
// Every entry swallows its own rejection (see startFireAndForgetNode), so
|
|
799
825
|
// this can never reject.
|
|
800
|
-
await Promise.all(
|
|
826
|
+
await Promise.all(batch);
|
|
801
827
|
}
|
|
802
828
|
}
|
|
803
829
|
|
|
@@ -921,7 +947,7 @@ async function executeNodes(nodes, edges, context, nodeHandlers, workflowConfig,
|
|
|
921
947
|
await executeNodes(onStreamNodes, edges, context, nodeHandlers, workflowConfig, callServerSegment, executionId);
|
|
922
948
|
}
|
|
923
949
|
});
|
|
924
|
-
if (isFatalNodeResult(streamResult)) {
|
|
950
|
+
if (isFatalNodeResult(streamResult) && !continuesOnError(node)) {
|
|
925
951
|
throw new Error(fatalNodeResultMessage(streamResult));
|
|
926
952
|
}
|
|
927
953
|
context[node.id] = streamResult;
|
|
@@ -980,7 +1006,7 @@ async function executeNodes(nodes, edges, context, nodeHandlers, workflowConfig,
|
|
|
980
1006
|
throw earlyErr;
|
|
981
1007
|
}
|
|
982
1008
|
|
|
983
|
-
if (isFatalNodeResult(result)) {
|
|
1009
|
+
if (isFatalNodeResult(result) && !continuesOnError(node)) {
|
|
984
1010
|
throw new Error(fatalNodeResultMessage(result));
|
|
985
1011
|
}
|
|
986
1012
|
|
|
@@ -1279,6 +1305,13 @@ function internalRequestHeaders(req) {
|
|
|
1279
1305
|
|
|
1280
1306
|
module.exports = {
|
|
1281
1307
|
internalRequestHeaders,
|
|
1308
|
+
normalizeEmailLocale,
|
|
1309
|
+
resolveRequestLocale,
|
|
1310
|
+
resolveWorkflowLocale,
|
|
1311
|
+
resolveEmailLocale,
|
|
1312
|
+
getClientLocale,
|
|
1313
|
+
localizeHref,
|
|
1314
|
+
pickLocalizedTemplate,
|
|
1282
1315
|
resolveValue,
|
|
1283
1316
|
resolveSecret,
|
|
1284
1317
|
resolveConfig,
|
|
@@ -1302,6 +1335,7 @@ module.exports = {
|
|
|
1302
1335
|
isStreamingAINode,
|
|
1303
1336
|
isFatalNodeResult,
|
|
1304
1337
|
fatalNodeResultMessage,
|
|
1338
|
+
continuesOnError,
|
|
1305
1339
|
isFireAndForgetNode,
|
|
1306
1340
|
startFireAndForgetNode,
|
|
1307
1341
|
registerPendingNodePromise,
|
|
@@ -1548,6 +1582,11 @@ function buildContext(workflowConfig, triggerContext) {
|
|
|
1548
1582
|
if (triggerContext.__dynamicRouteParam) context.__dynamicRouteParam = triggerContext.__dynamicRouteParam;
|
|
1549
1583
|
if (triggerContext.triggerElement) context.triggerElement = triggerContext.triggerElement;
|
|
1550
1584
|
}
|
|
1585
|
+
// See executeWorkflow: the page's language travels with the run.
|
|
1586
|
+
var runLocale = utils.getClientLocale();
|
|
1587
|
+
if (runLocale) {
|
|
1588
|
+
context.__locale = runLocale;
|
|
1589
|
+
}
|
|
1551
1590
|
return context;
|
|
1552
1591
|
}
|
|
1553
1592
|
|
|
@@ -1875,7 +1914,10 @@ async function executeWorkflowWithSegments(workflowConfig, triggerContext, clien
|
|
|
1875
1914
|
if (__terminalResult) {
|
|
1876
1915
|
var __redirectUrl = __terminalResult.__redirectUrl;
|
|
1877
1916
|
if (typeof __redirectUrl === 'string' && __redirectUrl.length > 0 && typeof window !== 'undefined' && window.location) {
|
|
1878
|
-
|
|
1917
|
+
// A site-relative target keeps the visitor in the language of the
|
|
1918
|
+
// page the run started on (the provider's hosted page is absolute
|
|
1919
|
+
// and passes through untouched).
|
|
1920
|
+
window.location.href = utils.localizeHref(__redirectUrl, context.__locale);
|
|
1879
1921
|
}
|
|
1880
1922
|
break;
|
|
1881
1923
|
}
|