@teleporthq/teleport-plugin-next-workflows 0.43.53 → 0.43.55

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.
Files changed (174) hide show
  1. package/__tests__/ai-chat-rag-sql-parameterization.test.ts +237 -0
  2. package/__tests__/ai-embedding-optional.test.ts +77 -0
  3. package/__tests__/ai-model-capabilities.test.ts +234 -0
  4. package/__tests__/ai-provider-coverage.test.ts +183 -0
  5. package/__tests__/cart-clear-db-mirror.test.ts +45 -0
  6. package/__tests__/cart-get-total-storefront-tax.test.ts +165 -0
  7. package/__tests__/cron-route-loop-templateparams.test.ts +15 -6
  8. package/__tests__/data-create-item-order-notification.test.ts +33 -0
  9. package/__tests__/ecommerce-customhandler-rewriter.test.ts +1 -1
  10. package/__tests__/internal-request-headers.test.ts +159 -0
  11. package/__tests__/order-details-route.test.ts +238 -0
  12. package/__tests__/resolve-config-template-params.test.ts +174 -0
  13. package/__tests__/utility-nodes.test.ts +27 -11
  14. package/dist/cjs/api-route-generator.d.ts.map +1 -1
  15. package/dist/cjs/api-route-generator.js +27 -15
  16. package/dist/cjs/api-route-generator.js.map +1 -1
  17. package/dist/cjs/ecommerce/order-details-route.d.ts +18 -0
  18. package/dist/cjs/ecommerce/order-details-route.d.ts.map +1 -0
  19. package/dist/cjs/ecommerce/order-details-route.js +172 -0
  20. package/dist/cjs/ecommerce/order-details-route.js.map +1 -0
  21. package/dist/cjs/ecommerce-customhandler-rewriter.d.ts +1 -1
  22. package/dist/cjs/ecommerce-customhandler-rewriter.d.ts.map +1 -1
  23. package/dist/cjs/ecommerce-customhandler-rewriter.js +20 -4
  24. package/dist/cjs/ecommerce-customhandler-rewriter.js.map +1 -1
  25. package/dist/cjs/executor-generator.d.ts.map +1 -1
  26. package/dist/cjs/executor-generator.js +69 -11
  27. package/dist/cjs/executor-generator.js.map +1 -1
  28. package/dist/cjs/nodes/ai/ai-custom-prompt.js +1 -1
  29. package/dist/cjs/nodes/ai/ai-custom-prompt.js.map +1 -1
  30. package/dist/cjs/nodes/ai/ai-detect-language.js +1 -1
  31. package/dist/cjs/nodes/ai/ai-detect-language.js.map +1 -1
  32. package/dist/cjs/nodes/ai/ai-generate-text-embedding.d.ts.map +1 -1
  33. package/dist/cjs/nodes/ai/ai-generate-text-embedding.js +47 -4
  34. package/dist/cjs/nodes/ai/ai-generate-text-embedding.js.map +1 -1
  35. package/dist/cjs/nodes/ai/ai-provider-utils.d.ts +2 -0
  36. package/dist/cjs/nodes/ai/ai-provider-utils.d.ts.map +1 -1
  37. package/dist/cjs/nodes/ai/ai-provider-utils.js +195 -106
  38. package/dist/cjs/nodes/ai/ai-provider-utils.js.map +1 -1
  39. package/dist/cjs/nodes/ai/ai-sentiment-analysis.js +1 -1
  40. package/dist/cjs/nodes/ai/ai-sentiment-analysis.js.map +1 -1
  41. package/dist/cjs/nodes/ai/ai-summarization.js +1 -1
  42. package/dist/cjs/nodes/ai/ai-summarization.js.map +1 -1
  43. package/dist/cjs/nodes/ai/ai-text-classifier.js +1 -1
  44. package/dist/cjs/nodes/ai/ai-text-classifier.js.map +1 -1
  45. package/dist/cjs/nodes/ai/ai-text-transform.js +1 -1
  46. package/dist/cjs/nodes/ai/ai-text-transform.js.map +1 -1
  47. package/dist/cjs/nodes/cart/cart-clear.d.ts.map +1 -1
  48. package/dist/cjs/nodes/cart/cart-clear.js +40 -0
  49. package/dist/cjs/nodes/cart/cart-clear.js.map +1 -1
  50. package/dist/cjs/nodes/cart/cart-get-total.d.ts.map +1 -1
  51. package/dist/cjs/nodes/cart/cart-get-total.js +56 -15
  52. package/dist/cjs/nodes/cart/cart-get-total.js.map +1 -1
  53. package/dist/cjs/nodes/data/data-count.d.ts.map +1 -1
  54. package/dist/cjs/nodes/data/data-count.js +6 -1
  55. package/dist/cjs/nodes/data/data-count.js.map +1 -1
  56. package/dist/cjs/nodes/data/data-create-item.d.ts.map +1 -1
  57. package/dist/cjs/nodes/data/data-create-item.js +45 -9
  58. package/dist/cjs/nodes/data/data-create-item.js.map +1 -1
  59. package/dist/cjs/nodes/data/data-delete-item.d.ts.map +1 -1
  60. package/dist/cjs/nodes/data/data-delete-item.js +7 -4
  61. package/dist/cjs/nodes/data/data-delete-item.js.map +1 -1
  62. package/dist/cjs/nodes/data/data-raw-query.d.ts.map +1 -1
  63. package/dist/cjs/nodes/data/data-raw-query.js +7 -1
  64. package/dist/cjs/nodes/data/data-raw-query.js.map +1 -1
  65. package/dist/cjs/nodes/data/data-select.d.ts.map +1 -1
  66. package/dist/cjs/nodes/data/data-select.js +6 -1
  67. package/dist/cjs/nodes/data/data-select.js.map +1 -1
  68. package/dist/cjs/nodes/data/data-update-item.d.ts.map +1 -1
  69. package/dist/cjs/nodes/data/data-update-item.js +7 -4
  70. package/dist/cjs/nodes/data/data-update-item.js.map +1 -1
  71. package/dist/cjs/nodes/utility/utility-hybrid-search.js +2 -2
  72. package/dist/cjs/nodes/utility/utility-hybrid-search.js.map +1 -1
  73. package/dist/cjs/nodes/utility/utility-semantic-search.js +1 -1
  74. package/dist/cjs/nodes/utility/utility-semantic-search.js.map +1 -1
  75. package/dist/cjs/nodes/utility/utility-similarity-scoring.d.ts.map +1 -1
  76. package/dist/cjs/nodes/utility/utility-similarity-scoring.js +49 -3
  77. package/dist/cjs/nodes/utility/utility-similarity-scoring.js.map +1 -1
  78. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  79. package/dist/cjs/workflow-project-plugin.d.ts.map +1 -1
  80. package/dist/cjs/workflow-project-plugin.js +10 -4
  81. package/dist/cjs/workflow-project-plugin.js.map +1 -1
  82. package/dist/esm/api-route-generator.d.ts.map +1 -1
  83. package/dist/esm/api-route-generator.js +27 -15
  84. package/dist/esm/api-route-generator.js.map +1 -1
  85. package/dist/esm/ecommerce/order-details-route.d.ts +18 -0
  86. package/dist/esm/ecommerce/order-details-route.d.ts.map +1 -0
  87. package/dist/esm/ecommerce/order-details-route.js +167 -0
  88. package/dist/esm/ecommerce/order-details-route.js.map +1 -0
  89. package/dist/esm/ecommerce-customhandler-rewriter.d.ts +1 -1
  90. package/dist/esm/ecommerce-customhandler-rewriter.d.ts.map +1 -1
  91. package/dist/esm/ecommerce-customhandler-rewriter.js +20 -4
  92. package/dist/esm/ecommerce-customhandler-rewriter.js.map +1 -1
  93. package/dist/esm/executor-generator.d.ts.map +1 -1
  94. package/dist/esm/executor-generator.js +69 -11
  95. package/dist/esm/executor-generator.js.map +1 -1
  96. package/dist/esm/nodes/ai/ai-custom-prompt.js +1 -1
  97. package/dist/esm/nodes/ai/ai-custom-prompt.js.map +1 -1
  98. package/dist/esm/nodes/ai/ai-detect-language.js +1 -1
  99. package/dist/esm/nodes/ai/ai-detect-language.js.map +1 -1
  100. package/dist/esm/nodes/ai/ai-generate-text-embedding.d.ts.map +1 -1
  101. package/dist/esm/nodes/ai/ai-generate-text-embedding.js +47 -4
  102. package/dist/esm/nodes/ai/ai-generate-text-embedding.js.map +1 -1
  103. package/dist/esm/nodes/ai/ai-provider-utils.d.ts +2 -0
  104. package/dist/esm/nodes/ai/ai-provider-utils.d.ts.map +1 -1
  105. package/dist/esm/nodes/ai/ai-provider-utils.js +194 -105
  106. package/dist/esm/nodes/ai/ai-provider-utils.js.map +1 -1
  107. package/dist/esm/nodes/ai/ai-sentiment-analysis.js +1 -1
  108. package/dist/esm/nodes/ai/ai-sentiment-analysis.js.map +1 -1
  109. package/dist/esm/nodes/ai/ai-summarization.js +1 -1
  110. package/dist/esm/nodes/ai/ai-summarization.js.map +1 -1
  111. package/dist/esm/nodes/ai/ai-text-classifier.js +1 -1
  112. package/dist/esm/nodes/ai/ai-text-classifier.js.map +1 -1
  113. package/dist/esm/nodes/ai/ai-text-transform.js +1 -1
  114. package/dist/esm/nodes/ai/ai-text-transform.js.map +1 -1
  115. package/dist/esm/nodes/cart/cart-clear.d.ts.map +1 -1
  116. package/dist/esm/nodes/cart/cart-clear.js +40 -0
  117. package/dist/esm/nodes/cart/cart-clear.js.map +1 -1
  118. package/dist/esm/nodes/cart/cart-get-total.d.ts.map +1 -1
  119. package/dist/esm/nodes/cart/cart-get-total.js +56 -15
  120. package/dist/esm/nodes/cart/cart-get-total.js.map +1 -1
  121. package/dist/esm/nodes/data/data-count.d.ts.map +1 -1
  122. package/dist/esm/nodes/data/data-count.js +6 -1
  123. package/dist/esm/nodes/data/data-count.js.map +1 -1
  124. package/dist/esm/nodes/data/data-create-item.d.ts.map +1 -1
  125. package/dist/esm/nodes/data/data-create-item.js +45 -9
  126. package/dist/esm/nodes/data/data-create-item.js.map +1 -1
  127. package/dist/esm/nodes/data/data-delete-item.d.ts.map +1 -1
  128. package/dist/esm/nodes/data/data-delete-item.js +7 -4
  129. package/dist/esm/nodes/data/data-delete-item.js.map +1 -1
  130. package/dist/esm/nodes/data/data-raw-query.d.ts.map +1 -1
  131. package/dist/esm/nodes/data/data-raw-query.js +7 -1
  132. package/dist/esm/nodes/data/data-raw-query.js.map +1 -1
  133. package/dist/esm/nodes/data/data-select.d.ts.map +1 -1
  134. package/dist/esm/nodes/data/data-select.js +6 -1
  135. package/dist/esm/nodes/data/data-select.js.map +1 -1
  136. package/dist/esm/nodes/data/data-update-item.d.ts.map +1 -1
  137. package/dist/esm/nodes/data/data-update-item.js +7 -4
  138. package/dist/esm/nodes/data/data-update-item.js.map +1 -1
  139. package/dist/esm/nodes/utility/utility-hybrid-search.js +2 -2
  140. package/dist/esm/nodes/utility/utility-hybrid-search.js.map +1 -1
  141. package/dist/esm/nodes/utility/utility-semantic-search.js +1 -1
  142. package/dist/esm/nodes/utility/utility-semantic-search.js.map +1 -1
  143. package/dist/esm/nodes/utility/utility-similarity-scoring.d.ts.map +1 -1
  144. package/dist/esm/nodes/utility/utility-similarity-scoring.js +49 -3
  145. package/dist/esm/nodes/utility/utility-similarity-scoring.js.map +1 -1
  146. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  147. package/dist/esm/workflow-project-plugin.d.ts.map +1 -1
  148. package/dist/esm/workflow-project-plugin.js +10 -4
  149. package/dist/esm/workflow-project-plugin.js.map +1 -1
  150. package/package.json +4 -4
  151. package/src/api-route-generator.ts +27 -15
  152. package/src/ecommerce/order-details-route.ts +195 -0
  153. package/src/ecommerce-customhandler-rewriter.ts +24 -4
  154. package/src/executor-generator.ts +69 -11
  155. package/src/nodes/ai/ai-custom-prompt.ts +2 -2
  156. package/src/nodes/ai/ai-detect-language.ts +2 -2
  157. package/src/nodes/ai/ai-generate-text-embedding.ts +49 -4
  158. package/src/nodes/ai/ai-provider-utils.ts +216 -106
  159. package/src/nodes/ai/ai-sentiment-analysis.ts +2 -2
  160. package/src/nodes/ai/ai-summarization.ts +2 -2
  161. package/src/nodes/ai/ai-text-classifier.ts +2 -2
  162. package/src/nodes/ai/ai-text-transform.ts +2 -2
  163. package/src/nodes/cart/cart-clear.ts +40 -0
  164. package/src/nodes/cart/cart-get-total.ts +61 -17
  165. package/src/nodes/data/data-count.ts +6 -1
  166. package/src/nodes/data/data-create-item.ts +45 -9
  167. package/src/nodes/data/data-delete-item.ts +6 -0
  168. package/src/nodes/data/data-raw-query.ts +8 -1
  169. package/src/nodes/data/data-select.ts +6 -1
  170. package/src/nodes/data/data-update-item.ts +6 -0
  171. package/src/nodes/utility/utility-hybrid-search.ts +2 -2
  172. package/src/nodes/utility/utility-semantic-search.ts +1 -1
  173. package/src/nodes/utility/utility-similarity-scoring.ts +56 -3
  174. package/src/workflow-project-plugin.ts +10 -4
@@ -4,19 +4,8 @@ async function cart_get_total() {
4
4
  try {
5
5
  const raw = localStorage.getItem('workflow_cart')
6
6
  const cart: any[] = raw ? JSON.parse(raw) : []
7
- let total = 0
8
- let itemCount = 0
9
-
10
- for (const item of cart) {
11
- const qty = item.quantity || 1
12
- const price = item.price || 0
13
- total += qty * price
14
- itemCount += qty
15
- }
16
-
17
- const rounded = Math.round(total * 100) / 100
18
7
 
19
- // Surface the runtime delivery config alongside the totals so the
8
+ // Surface the runtime delivery + tax config alongside the totals so the
20
9
  // place-order workflow's assemble script can compute shipping from
21
10
  // CURRENT settings instead of values baked at workflow-build time.
22
11
  // Without this, changing `Settings → Delivery → deliveryPrice` in the
@@ -30,6 +19,12 @@ async function cart_get_total() {
30
19
  freeDeliveryEnabled: boolean
31
20
  freeDeliveryThreshold: number
32
21
  } | null = null
22
+ // Percentage the storefront adds on top of the stored (net) product price.
23
+ // EcommerceProvider mirrors it here from the merchant's invoice settings —
24
+ // see `applyStorefrontTax` in `ecommerce-context-generator.ts`. Absent for
25
+ // storefronts exported before storefront tax existed, which correctly
26
+ // resolves to "no tax".
27
+ let storefrontTaxRate = 0
33
28
  try {
34
29
  const settingsRaw = localStorage.getItem('workflow_cart_settings')
35
30
  if (settingsRaw) {
@@ -41,20 +36,69 @@ async function cart_get_total() {
41
36
  freeDeliveryThreshold: Number(parsed.deliveryConfig.freeDeliveryThreshold) || 0,
42
37
  }
43
38
  }
39
+ if (parsed && typeof parsed === 'object' && parsed.taxConfig) {
40
+ const parsedRate = Number(parsed.taxConfig.storefrontTaxRate)
41
+ storefrontTaxRate = isFinite(parsedRate) && parsedRate > 0 ? parsedRate : 0
42
+ }
44
43
  }
45
44
  } catch (_settingsErr) {
46
- /* ignore — fall back to absent deliveryConfig */
45
+ /* ignore — fall back to absent deliveryConfig / no tax */
47
46
  }
48
47
 
48
+ const round = (n: number) => Math.round(n * 100) / 100
49
+ // Per-UNIT rounding, matching EcommerceProvider exactly, so the amount the
50
+ // buyer is charged is the number the cart page printed for them.
51
+ const grossUnitPrice = (price: number) =>
52
+ storefrontTaxRate > 0 ? round(price * (1 + storefrontTaxRate / 100)) : price
53
+
54
+ let net = 0
55
+ let gross = 0
56
+ let itemCount = 0
57
+
58
+ for (const item of cart) {
59
+ const qty = item.quantity || 1
60
+ const price = item.price || 0
61
+ net += qty * price
62
+ gross += qty * grossUnitPrice(price)
63
+ itemCount += qty
64
+ }
65
+
66
+ const roundedGross = round(gross)
67
+
49
68
  return {
50
- subtotal: rounded,
51
- tax: 0,
52
- total: rounded,
69
+ // NET goods total. Deliberately unchanged in meaning: two generations of
70
+ // baked place-order workflows read this field and add shipping to it to
71
+ // produce `teleport_orders.total_amount`. Making it gross here would make
72
+ // an OLD baked workflow write a taxed order total while still emitting
73
+ // untaxed payment line items — and Stripe Checkout totals the line items
74
+ // and ignores the top-level amount, so the buyer would be undercharged.
75
+ // Tax arrives additively instead, via `tax` below, which an old workflow
76
+ // simply never reads.
77
+ subtotal: round(net),
78
+ // The tax the storefront adds on top, derived as gross − net rather than
79
+ // recomputed from the rate, so `net line items + tax` reconciles to
80
+ // `total` to the cent. Payment providers that total a `line_items` array
81
+ // need this as its own line: the item lines carry NET prices, because
82
+ // `teleport_order_items` stores net and the invoice route adds VAT back
83
+ // on top of them (double-taxing every invoice otherwise).
84
+ tax: round(gross - net),
85
+ // Goods total the buyer actually owes, tax included and shipping
86
+ // excluded. Equals the Subtotal the cart page printed — same per-unit
87
+ // rounding, same source of truth.
88
+ total: roundedGross,
53
89
  itemCount,
54
90
  deliveryConfig,
91
+ taxConfig: { storefrontTaxRate },
55
92
  }
56
93
  } catch (_err) {
57
- return { subtotal: 0, tax: 0, total: 0, itemCount: 0, deliveryConfig: null }
94
+ return {
95
+ subtotal: 0,
96
+ tax: 0,
97
+ total: 0,
98
+ itemCount: 0,
99
+ deliveryConfig: null,
100
+ taxConfig: { storefrontTaxRate: 0 },
101
+ }
58
102
  }
59
103
  }
60
104
  export const cartGetTotal: NodeHandlerGenerator = {
@@ -5,6 +5,11 @@ async function data_count(config: any, context: any) {
5
5
  const tableName = config.tableName
6
6
  const filters = config.filters || []
7
7
  const baseUrl = (context && context.__baseUrl) || ''
8
+ // Credentials for calling this deployment's own API routes — see
9
+ // internalRequestHeaders in runtime-utils. Without them a deployment behind
10
+ // Vercel Deployment Protection 401s its own request and this node silently
11
+ // returns nothing.
12
+ const __internalHeaders = (context && context.__internalHeaders) || {}
8
13
 
9
14
  // Unresolved route-param sentinel in a filter (see resolveTemplateTokenString
10
15
  // in runtime-utils). DEGRADE: return count:0 WITHOUT an `error` so the executor
@@ -31,7 +36,7 @@ async function data_count(config: any, context: any) {
31
36
  try {
32
37
  const response = await fetch(baseUrl + '/api/data/' + dataSourceId + '/count', {
33
38
  method: 'POST',
34
- headers: { 'Content-Type': 'application/json' },
39
+ headers: { 'Content-Type': 'application/json', ...__internalHeaders },
35
40
  body: JSON.stringify({ tableName, filters }),
36
41
  })
37
42
 
@@ -5,6 +5,11 @@ async function data_create_item(config: any, context: any) {
5
5
  const tableName = config.tableName
6
6
  const columnMappings = config.columnMappings || {}
7
7
  const baseUrl = (context && context.__baseUrl) || ''
8
+ // Credentials for calling this deployment's own API routes — see
9
+ // internalRequestHeaders in runtime-utils. Without them a deployment behind
10
+ // Vercel Deployment Protection 401s its own request and this node silently
11
+ // returns nothing.
12
+ const __internalHeaders = (context && context.__internalHeaders) || {}
8
13
 
9
14
  // An unresolved route-param sentinel (see resolveTemplateTokenString in
10
15
  // runtime-utils) in a columnMapping degrades to null so the INSERT itself
@@ -67,7 +72,7 @@ async function data_create_item(config: any, context: any) {
67
72
  }
68
73
  const response = await fetch(baseUrl + '/api/data/' + dataSourceId + '/create', {
69
74
  method: 'POST',
70
- headers: { 'Content-Type': 'application/json' },
75
+ headers: { 'Content-Type': 'application/json', ...__internalHeaders },
71
76
  body: JSON.stringify(reqBody),
72
77
  })
73
78
 
@@ -87,7 +92,19 @@ async function data_create_item(config: any, context: any) {
87
92
  // requiring the AI to remember to add an explicit email-send
88
93
  // workflow node. The endpoint is a no-op when notifications
89
94
  // are not configured, so it is safe to call unconditionally.
90
- if (typeof tableName === 'string' && tableName === 'teleport_orders' && data && data.item) {
95
+ //
96
+ // ...unless the workflow that owns this INSERT already carries its own
97
+ // "Send Order-Notification Email" node. The builder sets
98
+ // `suppressOrderNotification: true` on this node in that case, because
99
+ // otherwise the merchant receives the SAME order twice: once from here
100
+ // and once from the workflow. The workflow node is the canonical sender —
101
+ // it runs AFTER `order_number` has been backfilled (this INSERT still
102
+ // sees NULL and falls back to the raw UUID) and it renders the merchant's
103
+ // builder template through the full filler, list blocks included. Absent
104
+ // flag ⇒ previous behaviour, so already-exported projects are unaffected.
105
+ const notifiesOnInsert = config.suppressOrderNotification !== true
106
+ const isOrderInsert = typeof tableName === 'string' && tableName === 'teleport_orders'
107
+ if (isOrderInsert && data && data.item && notifiesOnInsert) {
91
108
  const item: any = data.item
92
109
 
93
110
  // Best-effort: mark the buyer's active database cart as ordered. This is
@@ -99,7 +116,7 @@ async function data_create_item(config: any, context: any) {
99
116
  if (__orderOwnerId) {
100
117
  fetch(baseUrl + '/api/cart/mark-ordered', {
101
118
  method: 'POST',
102
- headers: { 'Content-Type': 'application/json' },
119
+ headers: { 'Content-Type': 'application/json', ...__internalHeaders },
103
120
  body: JSON.stringify({ anonymousUserId: __orderOwnerId }),
104
121
  }).catch(function () {})
105
122
  }
@@ -131,19 +148,38 @@ async function data_create_item(config: any, context: any) {
131
148
  }
132
149
  }
133
150
  }
134
- // Normalise items into the shape the email endpoint can render
135
- // (name, quantity, unit_price, total_price). Defensive about
136
- // every field — different cart sources spell them differently.
151
+ // Normalise items into the shape the email endpoint can render.
152
+ // Defensive about every field — different cart sources spell them
153
+ // differently.
154
+ //
155
+ // Each row carries BOTH spellings on purpose:
156
+ // - camelCase (`name`/`unitPrice`/`totalPrice`) for the endpoint's own
157
+ // `{{itemsList}}` <ul> builder, and
158
+ // - the snake_case array-mapper row keys (`product_name`, `quantity`,
159
+ // `unit_price`, `line_total`, `currency`, `image_url`) that a builder
160
+ // email template's `<!--tq:each items-->` row block binds to.
161
+ // One payload therefore feeds both renderers without either having to
162
+ // know which template style the merchant is on.
163
+ const orderCurrency = item.currency || ''
137
164
  const normalisedItems = cartItems.map(function (it: any) {
138
165
  const unitPrice = Number(it.unitPrice != null ? it.unitPrice : it.price) || 0
139
166
  const quantity = parseInt(it.quantity, 10)
140
167
  const qty = isFinite(quantity) && quantity > 0 ? quantity : 1
168
+ const lineTotal = Math.round(unitPrice * qty * 100) / 100
169
+ const displayName = it.name || it.productName || it.product_name || 'Item'
170
+ const imageUrl = it.image || it.image_url || it.imageUrl || it.thumbnail || ''
141
171
  return {
142
- name: it.name || it.productName || it.product_name || 'Item',
172
+ name: displayName,
143
173
  sku: it.sku || it.SKU || '',
144
174
  quantity: qty,
145
175
  unitPrice: Math.round(unitPrice * 100) / 100,
146
- totalPrice: Math.round(unitPrice * qty * 100) / 100,
176
+ totalPrice: lineTotal,
177
+ image: imageUrl,
178
+ product_name: displayName,
179
+ unit_price: unitPrice.toFixed(2),
180
+ line_total: lineTotal.toFixed(2),
181
+ currency: orderCurrency,
182
+ image_url: imageUrl,
147
183
  }
148
184
  })
149
185
 
@@ -194,7 +230,7 @@ async function data_create_item(config: any, context: any) {
194
230
  try {
195
231
  fetch(baseUrl + '/api/ecommerce/order-notification', {
196
232
  method: 'POST',
197
- headers: { 'Content-Type': 'application/json' },
233
+ headers: { 'Content-Type': 'application/json', ...__internalHeaders },
198
234
  body: JSON.stringify({
199
235
  orderId: item.id || '',
200
236
  // orderNumber is the human-friendly identifier (e.g. ORD-1234)
@@ -5,6 +5,11 @@ async function data_delete_item(config: any, context: any) {
5
5
  const tableName = config.tableName
6
6
  const filters = config.filters || []
7
7
  const baseUrl = (context && context.__baseUrl) || ''
8
+ // Credentials for calling this deployment's own API routes — see
9
+ // internalRequestHeaders in runtime-utils. Without them a deployment behind
10
+ // Vercel Deployment Protection 401s its own request and this node silently
11
+ // returns nothing.
12
+ const __internalHeaders = (context && context.__internalHeaders) || {}
8
13
  const __env = (globalThis as any).process && (globalThis as any).process.env
9
14
 
10
15
  // Unresolved route-param sentinel in a filter → validation error (see
@@ -47,6 +52,7 @@ async function data_delete_item(config: any, context: any) {
47
52
  // Trusted internal server-side call — lets the /api/data guard distinguish
48
53
  // this from a direct browser request (see assertSessionOwnsUsersRow).
49
54
  'x-internal-data-secret': (__env && __env.NEXTAUTH_SECRET) || '',
55
+ ...__internalHeaders,
50
56
  },
51
57
  body: JSON.stringify({ tableName, filters }),
52
58
  })
@@ -11,10 +11,17 @@ async function data_raw_query(config: any, context: any) {
11
11
  const params = Array.isArray(config.params) ? config.params : []
12
12
  const baseUrl = (context && context.__baseUrl) || ''
13
13
 
14
+ // Credentials for calling this deployment's own API routes. A deployment
15
+ // behind Vercel Deployment Protection answers its OWN request with 401
16
+ // "Protected deployment", which turns every data node into a silent
17
+ // `{ rows: [] }` — the page renders, but nothing reads or writes. See
18
+ // internalRequestHeaders in runtime-utils for what these carry.
19
+ const __internalHeaders = (context && context.__internalHeaders) || {}
20
+
14
21
  try {
15
22
  const response = await fetch(baseUrl + '/api/data/' + dataSourceId + '/raw-query', {
16
23
  method: 'POST',
17
- headers: { 'Content-Type': 'application/json' },
24
+ headers: { 'Content-Type': 'application/json', ...__internalHeaders },
18
25
  body: JSON.stringify({ query, params }),
19
26
  })
20
27
 
@@ -16,6 +16,11 @@ async function data_select(config: any, context: any) {
16
16
  ? config.rawQueryUserPartParams
17
17
  : []
18
18
  const baseUrl = (context && context.__baseUrl) || ''
19
+ // Credentials for calling this deployment's own API routes — see
20
+ // internalRequestHeaders in runtime-utils. Without them a deployment behind
21
+ // Vercel Deployment Protection 401s its own request and this node silently
22
+ // returns nothing.
23
+ const __internalHeaders = (context && context.__internalHeaders) || {}
19
24
 
20
25
  function isEmptyFilterValue(value: any) {
21
26
  if (value === undefined || value === null) return true
@@ -97,7 +102,7 @@ async function data_select(config: any, context: any) {
97
102
 
98
103
  const response = await fetch(baseUrl + '/api/data/' + dataSourceId + '/select', {
99
104
  method: 'POST',
100
- headers: { 'Content-Type': 'application/json' },
105
+ headers: { 'Content-Type': 'application/json', ...__internalHeaders },
101
106
  body: JSON.stringify(payload),
102
107
  })
103
108
 
@@ -6,6 +6,11 @@ async function data_update_item(config: any, context: any) {
6
6
  const filters = config.filters || []
7
7
  const columnMappings = config.columnMappings || {}
8
8
  const baseUrl = (context && context.__baseUrl) || ''
9
+ // Credentials for calling this deployment's own API routes — see
10
+ // internalRequestHeaders in runtime-utils. Without them a deployment behind
11
+ // Vercel Deployment Protection 401s its own request and this node silently
12
+ // returns nothing.
13
+ const __internalHeaders = (context && context.__internalHeaders) || {}
9
14
  const __env = (globalThis as any).process && (globalThis as any).process.env
10
15
 
11
16
  // Unresolved route-param sentinel (see resolveTemplateTokenString in
@@ -131,6 +136,7 @@ async function data_update_item(config: any, context: any) {
131
136
  // Trusted internal server-side call — lets the /api/data guard distinguish
132
137
  // this from a direct browser request (see assertSessionOwnsUsersRow).
133
138
  'x-internal-data-secret': (__env && __env.NEXTAUTH_SECRET) || '',
139
+ ...__internalHeaders,
134
140
  },
135
141
  body: JSON.stringify(reqBody),
136
142
  })
@@ -3,11 +3,11 @@ import { NodeHandlerGenerator, handlerToString } from '../types'
3
3
  async function utility_hybrid_search(config: any, context: Record<string, unknown>) {
4
4
  const query = config.query || ''
5
5
  const queryEmbedding = config.queryEmbedding || null
6
- const collection = config.collection || []
6
+ const collection = config.documents || []
7
7
  const fields = config.fields || []
8
8
  const embeddingField = config.embeddingField || 'embedding'
9
9
  const topK = config.topK !== undefined ? Number(config.topK) : 10
10
- const textWeight = config.textWeight !== undefined ? Number(config.textWeight) : 0.5
10
+ const textWeight = config.keywordWeight !== undefined ? Number(config.keywordWeight) : 0.5
11
11
  const semanticWeight = config.semanticWeight !== undefined ? Number(config.semanticWeight) : 0.5
12
12
  const fusionMethod = config.fusionMethod || 'rrf'
13
13
  const rrfK = config.rrfK !== undefined ? Number(config.rrfK) : 60
@@ -3,7 +3,7 @@ import { NodeHandlerGenerator, handlerToString } from '../types'
3
3
  async function utility_semantic_search(config: any, context: Record<string, unknown>) {
4
4
  const query = config.query || ''
5
5
  const queryEmbedding = config.queryEmbedding || null
6
- const collection = config.collection || []
6
+ const collection = config.documents || []
7
7
  const embeddingField = config.embeddingField || 'embedding'
8
8
  const topK = config.topK !== undefined ? Number(config.topK) : 10
9
9
  const threshold = config.threshold !== undefined ? Number(config.threshold) : 0
@@ -1,4 +1,7 @@
1
- import { NodeHandlerGenerator, handlerToString } from '../types'
1
+ import { NodeHandlerGenerator } from '../types'
2
+ import { generateAIProviderUtils, AI_PROVIDER_DEPENDENCIES } from '../ai/ai-provider-utils'
3
+
4
+ declare function __ai_resolveToken(token: any): string
2
5
 
3
6
  async function utility_similarity_scoring(config: any, context: Record<string, unknown>) {
4
7
  const text1 = config.text1 || ''
@@ -237,6 +240,50 @@ async function utility_similarity_scoring(config: any, context: Record<string, u
237
240
  score = jaro + prefix * 0.1 * (1 - jaro)
238
241
  break
239
242
  }
243
+ case 'semantic': {
244
+ // Embeds both texts and compares the vectors, which is what makes this
245
+ // mode "AI-powered" — the lexical algorithms above compare characters
246
+ // and cannot see that "car" and "automobile" mean the same thing.
247
+ // Embeddings go through OpenAI, matching `ai-generate-text-embedding`.
248
+ let apiKey
249
+ try {
250
+ apiKey = __ai_resolveToken(config.token)
251
+ } catch (tokenErr: any) {
252
+ return { score: 0, algorithm, error: tokenErr.message }
253
+ }
254
+
255
+ const __nodeRequire =
256
+ typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : require
257
+ const _mod = __nodeRequire('openai')
258
+ const OpenAI = _mod.default || _mod
259
+ const client = new OpenAI({ apiKey })
260
+
261
+ const response = await client.embeddings.create({
262
+ model: config.model || 'text-embedding-3-small',
263
+ input: [String(text1), String(text2)],
264
+ })
265
+
266
+ const vectors = (response.data || []).map(function (entry: any) {
267
+ return entry.embedding
268
+ })
269
+ if (vectors.length < 2 || !vectors[0] || !vectors[1]) {
270
+ return { score: 0, algorithm, error: 'No embeddings returned from API' }
271
+ }
272
+
273
+ let dot = 0
274
+ let magA = 0
275
+ let magB = 0
276
+ const len = Math.min(vectors[0].length, vectors[1].length)
277
+ for (let vi = 0; vi < len; vi++) {
278
+ dot += vectors[0][vi] * vectors[1][vi]
279
+ magA += vectors[0][vi] * vectors[0][vi]
280
+ magB += vectors[1][vi] * vectors[1][vi]
281
+ }
282
+ magA = Math.sqrt(magA)
283
+ magB = Math.sqrt(magB)
284
+ score = magA === 0 || magB === 0 ? 0 : dot / (magA * magB)
285
+ break
286
+ }
240
287
  default:
241
288
  return {
242
289
  score: 0,
@@ -244,7 +291,7 @@ async function utility_similarity_scoring(config: any, context: Record<string, u
244
291
  error:
245
292
  'Unknown algorithm: ' +
246
293
  algorithm +
247
- '. Supported: levenshtein, jaccard, cosine, dice, hamming, jaro-winkler',
294
+ '. Supported: levenshtein, jaccard, cosine, dice, hamming, jaro-winkler, semantic',
248
295
  }
249
296
  }
250
297
 
@@ -256,7 +303,13 @@ async function utility_similarity_scoring(config: any, context: Record<string, u
256
303
  export const utilitySimilarityScoring: NodeHandlerGenerator = {
257
304
  nodeType: 'utility-similarity-scoring',
258
305
  executionEnv: 'server',
306
+ // Only the `semantic` algorithm reaches out to a provider, and it uses
307
+ // OpenAI embeddings — the same model family the rest of the product indexes
308
+ // with. The other algorithms are pure string maths and need nothing.
309
+ dependencies: { openai: AI_PROVIDER_DEPENDENCIES.openai },
259
310
  generateHandler(): string {
260
- return handlerToString(utility_similarity_scoring)
311
+ // `__ai_resolveToken` turns a secret reference into the real key; it lives
312
+ // in the shared AI utils, so they have to be emitted alongside the handler.
313
+ return generateAIProviderUtils() + '\n\n' + utility_similarity_scoring.toString()
261
314
  },
262
315
  }
@@ -1368,10 +1368,16 @@ async function customNode_${safeId}(outerContext, parameters, nodeHandlers) {
1368
1368
  // seg.fireAndForget is static (EVERY node is a fire-and-forget data
1369
1369
  // node). A mixed segment stays blocking statically, but once branch
1370
1370
  // skipping has eliminated the awaited nodes at runtime, only
1371
- // fire-and-forget work remains — e.g. the resolve-user custom node's
1372
- // returning-guest branch, whose idempotent users-row re-ensure is
1373
- // fire-and-forget while the new-guest create (same segment, other
1374
- // branch) stays awaited. Upgrade exactly that case dynamically.
1371
+ // fire-and-forget work remains, and that case is upgraded here.
1372
+ //
1373
+ // What this does NOT decide is whether a node should have been
1374
+ // fire-and-forget in the first place. Not awaiting is safe when nothing
1375
+ // downstream reads the node's OUTPUT and nothing downstream depends on
1376
+ // the WRITE — and the second half is the one that gets missed. The
1377
+ // caller's next request is a separate round trip that can reach the
1378
+ // database first, so a row this segment was supposed to insert may not
1379
+ // exist yet when a later request references it under a foreign key.
1380
+ // Any write another request will point at must stay awaited.
1375
1381
  var __segLiveNodes = seg.nodes.filter(function(n) { return !(context.__skippedNodes && context.__skippedNodes[n.id]); });
1376
1382
  var __segIsFireAndForget = seg.fireAndForget ||
1377
1383
  (__segLiveNodes.length > 0 && __segLiveNodes.every(__utils.isFireAndForgetNode));