@openapi-flow/n8n 0.2.0 → 0.3.1

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 (141) hide show
  1. package/README.md +29 -1
  2. package/dist/nodes/inputs/compile-template-input-validators.d.ts +3 -0
  3. package/dist/nodes/inputs/compile-template-input-validators.js +26 -0
  4. package/dist/nodes/inputs/create-template-input-nodes.d.ts +4 -0
  5. package/dist/nodes/inputs/create-template-input-nodes.js +61 -0
  6. package/dist/nodes/native/arrays/create-bound-native-array-capability.d.ts +4 -0
  7. package/dist/nodes/native/arrays/create-bound-native-array-capability.js +81 -0
  8. package/dist/nodes/native/arrays/create-native-array-capability.d.ts +1 -0
  9. package/dist/nodes/native/arrays/create-native-array-capability.js +7 -59
  10. package/dist/nodes/native/arrays/native-array-definition.d.ts +2 -0
  11. package/dist/nodes/native/arrays/native-array-definition.js +27 -0
  12. package/dist/nodes/native/common/create-material-planning-capability.d.ts +4 -0
  13. package/dist/nodes/native/common/create-material-planning-capability.js +14 -0
  14. package/dist/nodes/native/common/define-material-bound-capability.d.ts +4 -0
  15. package/dist/nodes/native/common/define-material-bound-capability.js +33 -0
  16. package/dist/nodes/native/common/resolve-native-runtime-source.d.ts +3 -0
  17. package/dist/nodes/native/common/resolve-native-runtime-source.js +15 -0
  18. package/dist/nodes/native/common/response-reference-bindings.d.ts +4 -0
  19. package/dist/nodes/native/common/response-reference-bindings.js +15 -0
  20. package/dist/nodes/native/create-exclusive-branch-merge-capability.js +10 -0
  21. package/dist/nodes/native/create-json-output-capability.js +14 -4
  22. package/dist/nodes/native/create-native-capabilities.js +13 -12
  23. package/dist/nodes/native/create-pass-through-capability.js +2 -0
  24. package/dist/nodes/native/create-response-array-capability.js +13 -8
  25. package/dist/nodes/native/create-response-collection-capability.js +10 -8
  26. package/dist/nodes/native/if-capability.js +6 -2
  27. package/dist/nodes/native/inputs/native-input-runtime.bundle.js +24 -0
  28. package/dist/nodes/native/inputs/prepend-native-parameter-guard.d.ts +4 -0
  29. package/dist/nodes/native/inputs/prepend-native-parameter-guard.js +52 -0
  30. package/dist/nodes/native/item-join/create-bound-item-join-capability.d.ts +3 -0
  31. package/dist/nodes/native/item-join/create-bound-item-join-capability.js +169 -0
  32. package/dist/nodes/native/item-join/create-item-join-capability.d.ts +2 -1
  33. package/dist/nodes/native/item-join/create-item-join-capability.js +8 -151
  34. package/dist/nodes/native/item-join/item-join-definition.d.ts +2 -0
  35. package/dist/nodes/native/item-join/item-join-definition.js +33 -0
  36. package/dist/nodes/native/merge-append-capability.js +2 -0
  37. package/dist/nodes/native/registry/native-feature-definitions.d.ts +4 -0
  38. package/dist/nodes/native/registry/native-feature-definitions.js +93 -0
  39. package/dist/nodes/native/registry/native-feature-material-requirements.d.ts +3 -0
  40. package/dist/nodes/native/registry/native-feature-material-requirements.js +10 -0
  41. package/dist/nodes/native/registry/resolve-n8n-native-features.d.ts +3 -0
  42. package/dist/nodes/native/registry/resolve-n8n-native-features.js +6 -0
  43. package/dist/nodes/native/registry/resolve-n8n-native-planning-features.d.ts +3 -0
  44. package/dist/nodes/native/registry/resolve-n8n-native-planning-features.js +5 -0
  45. package/dist/nodes/native/registry/resolve-native-feature-registry.d.ts +3 -0
  46. package/dist/nodes/native/registry/resolve-native-feature-registry.js +99 -0
  47. package/dist/nodes/native/registry/validate-native-feature-context.d.ts +2 -0
  48. package/dist/nodes/native/registry/validate-native-feature-context.js +46 -0
  49. package/dist/nodes/native/response-array-definition.d.ts +2 -0
  50. package/dist/nodes/native/response-array-definition.js +27 -0
  51. package/dist/nodes/native/response-assertion-capability.js +5 -1
  52. package/dist/nodes/native/response-check-code.d.ts +1 -1
  53. package/dist/nodes/native/response-check-code.js +13 -7
  54. package/dist/nodes/native/response-checks/create-response-check-reader.d.ts +1 -1
  55. package/dist/nodes/native/response-checks/create-response-check-reader.js +2 -2
  56. package/dist/nodes/native/response-collection-definition.d.ts +2 -0
  57. package/dist/nodes/native/response-collection-definition.js +27 -0
  58. package/dist/nodes/native/stop-and-error-capability.js +28 -14
  59. package/dist/nodes/request/bindings/compile-request-validator.d.ts +1 -1
  60. package/dist/nodes/request/bindings/compile-request-validator.js +2 -2
  61. package/dist/nodes/request/bindings/create-bound-request-fragment.js +8 -3
  62. package/dist/nodes/request/bindings/create-output-item-reader-code.d.ts +2 -0
  63. package/dist/nodes/request/bindings/create-output-item-reader-code.js +7 -0
  64. package/dist/nodes/request/bindings/create-output-reader-code.d.ts +1 -1
  65. package/dist/nodes/request/bindings/create-output-reader-code.js +4 -4
  66. package/dist/nodes/request/create-http-request-node.js +23 -44
  67. package/dist/nodes/request/finalize-http-request-fragment.d.ts +3 -0
  68. package/dist/nodes/request/finalize-http-request-fragment.js +22 -0
  69. package/dist/nodes/request/resolve-http-request-node-configuration.d.ts +4 -0
  70. package/dist/nodes/request/resolve-http-request-node-configuration.js +41 -0
  71. package/dist/nodes/request/response/create-http-response-decoder.js +2 -1
  72. package/dist/nodes/request/response/http-response-node-name.d.ts +2 -0
  73. package/dist/nodes/request/response/http-response-node-name.js +4 -0
  74. package/dist/nodes/request/response/response-runtime.bundle.js +1 -1
  75. package/dist/nodes/request/runtime/materialize-http-request.d.ts +2 -1
  76. package/dist/nodes/request/runtime/materialize-http-request.js +21 -3
  77. package/dist/nodes/request/runtime/request-runtime.bundle.js +1 -1
  78. package/dist/public-api.d.ts +13 -0
  79. package/dist/public-api.js +9 -0
  80. package/dist/schemas/native-feature-registry-schema.d.ts +17 -0
  81. package/dist/schemas/native-feature-registry-schema.js +8 -0
  82. package/dist/schemas/native-runtime-input-schema.d.ts +5 -0
  83. package/dist/schemas/native-runtime-input-schema.js +5 -0
  84. package/dist/schemas/template-deployment-selection-schema.d.ts +3 -0
  85. package/dist/schemas/template-deployment-selection-schema.js +10 -0
  86. package/dist/schemas/workflow-input-value-map-schema.d.ts +5 -0
  87. package/dist/schemas/workflow-input-value-map-schema.js +5 -0
  88. package/dist/schemas/workflow-template-schema.d.ts +11 -0
  89. package/dist/schemas/workflow-template-schema.js +10 -0
  90. package/dist/types/native-capability.d.ts +10 -1
  91. package/dist/types/native-feature-registry.d.ts +70 -0
  92. package/dist/types/native-feature-registry.js +14 -0
  93. package/dist/types/native-material-binding.d.ts +56 -0
  94. package/dist/types/native-material-binding.js +1 -0
  95. package/dist/types/native-runtime-parameters.d.ts +55 -0
  96. package/dist/types/native-runtime-parameters.js +1 -0
  97. package/dist/types/output-binding-source.d.ts +5 -0
  98. package/dist/types/request-materialization.d.ts +9 -1
  99. package/dist/types/request-node-configuration.d.ts +13 -0
  100. package/dist/types/request-node-configuration.js +1 -0
  101. package/dist/types/response-check-compilation.d.ts +1 -1
  102. package/dist/types/reviewable-workflow.d.ts +2 -0
  103. package/dist/types/workflow-compilation.d.ts +3 -0
  104. package/dist/types/workflow-template.d.ts +121 -0
  105. package/dist/types/workflow-template.js +1 -0
  106. package/dist/workflow/batch/compile-batched-n8n-workflow.js +22 -4
  107. package/dist/workflow/build-n8n-workflow.js +3 -6
  108. package/dist/workflow/compile-native-material-fragments.d.ts +3 -0
  109. package/dist/workflow/compile-native-material-fragments.js +76 -0
  110. package/dist/workflow/compile-native-workflow-nodes.js +22 -23
  111. package/dist/workflow/compile-planned-n8n-workflow.js +28 -3
  112. package/dist/workflow/compile-reviewable-n8n-workflow.js +31 -3
  113. package/dist/workflow/compile-validated-workflow-fragments.js +14 -14
  114. package/dist/workflow/compile-workflow-material-fragments.d.ts +4 -0
  115. package/dist/workflow/compile-workflow-material-fragments.js +18 -0
  116. package/dist/workflow/create-n8n-native-output-sources.js +53 -12
  117. package/dist/workflow/entrypoint/manual-trigger.d.ts +4 -0
  118. package/dist/workflow/entrypoint/manual-trigger.js +16 -0
  119. package/dist/workflow/find-singleton-api-responses.d.ts +3 -0
  120. package/dist/workflow/find-singleton-api-responses.js +22 -0
  121. package/dist/workflow/inputs/compile-native-runtime-inputs.d.ts +5 -0
  122. package/dist/workflow/inputs/compile-native-runtime-inputs.js +129 -0
  123. package/dist/workflow/inputs/create-runtime-input-native-capabilities.d.ts +4 -0
  124. package/dist/workflow/inputs/create-runtime-input-native-capabilities.js +36 -0
  125. package/dist/workflow/resolve-n8n-native-materials.d.ts +2 -0
  126. package/dist/workflow/resolve-n8n-native-materials.js +16 -0
  127. package/dist/workflow/templates/compile-n8n-workflow-template.d.ts +3 -0
  128. package/dist/workflow/templates/compile-n8n-workflow-template.js +211 -0
  129. package/dist/workflow/templates/create-template-artifact-mapping.d.ts +2 -0
  130. package/dist/workflow/templates/create-template-artifact-mapping.js +58 -0
  131. package/dist/workflow/templates/create-template-gap-regions.d.ts +5 -0
  132. package/dist/workflow/templates/create-template-gap-regions.js +22 -0
  133. package/dist/workflow/templates/create-workflow-template-guide.d.ts +3 -0
  134. package/dist/workflow/templates/create-workflow-template-guide.js +44 -0
  135. package/dist/workflow/templates/prepare-template-api-fragments.d.ts +3 -0
  136. package/dist/workflow/templates/prepare-template-api-fragments.js +74 -0
  137. package/dist/workflow/templates/select-n8n-template-deployments.d.ts +3 -0
  138. package/dist/workflow/templates/select-n8n-template-deployments.js +12 -0
  139. package/dist/workflow/templates/workflow-template-identities.d.ts +5 -0
  140. package/dist/workflow/templates/workflow-template-identities.js +5 -0
  141. package/package.json +9 -4
@@ -1,7 +1,9 @@
1
+ import { defineMaterialBoundCapability } from './common/define-material-bound-capability.js';
1
2
  import { node } from '@n8n/workflow-sdk';
2
3
  import { readFileSync } from 'node:fs';
3
4
  import { createResponseValueSchema } from '@openapi-flow/core';
4
5
  import { createResponseCollectionParametersSchema } from '../../schemas/response-collection-schema.js';
6
+ import { responseCollectionDefinition } from './response-collection-definition.js';
5
7
  import { createOutputReaderCode } from '../request/bindings/create-output-reader-code.js';
6
8
  import { javascriptJsonLiteral } from '../../utils/javascript-json-literal.js';
7
9
  export function createResponseCollectionCapability(input) {
@@ -20,12 +22,14 @@ export function createResponseCollectionCapability(input) {
20
22
  createResponseValueSchema(material.operation, parameters.pointer);
21
23
  return material;
22
24
  }
23
- return {
24
- name: 'collect-api-responses',
25
- description: 'Collect unchanged item-linked API response values from one incoming stream into {items: values} using n8n Aggregate. Validates each full OAS response first. Preserves null, nested arrays, duplicates and received order. Not a branch join. Empty streams do not trigger this node or create an artificial result.',
25
+ return defineMaterialBoundCapability({
26
+ ...responseCollectionDefinition,
26
27
  parametersSchema,
27
- inputPorts: () => ['main'],
28
- outputPorts: () => ['main'],
28
+ materialSources: {
29
+ apiMaterials: structuredClone(input.materials),
30
+ nativeOutputs: [],
31
+ },
32
+ bindMaterialContracts: (sources) => createResponseCollectionCapability({ materials: sources.apiMaterials }),
29
33
  responseReferences: (values) => {
30
34
  const parameters = parametersSchema.parse(values);
31
35
  source(parameters);
@@ -37,8 +41,6 @@ export function createResponseCollectionCapability(input) {
37
41
  },
38
42
  ];
39
43
  },
40
- waitsForAllInputs: false,
41
- exclusiveOutputPorts: false,
42
44
  outputSchema: (values) => {
43
45
  const parameters = parametersSchema.parse(values);
44
46
  return {
@@ -128,5 +130,5 @@ export function createResponseCollectionCapability(input) {
128
130
  ],
129
131
  };
130
132
  },
131
- };
133
+ });
132
134
  }
@@ -3,6 +3,7 @@ import { ifParametersSchema } from '../../schemas/native-capability-schemas.js';
3
3
  import { createIfPlanningParametersSchema } from '../../schemas/create-native-comparison-planning-schema.js';
4
4
  import { createNativeFragment } from './common/create-native-fragment.js';
5
5
  import { responseReferences } from './common/response-references.js';
6
+ import { responseReferenceBindings } from './common/response-reference-bindings.js';
6
7
  import { conditionExpression } from './response-check-code.js';
7
8
  import { createResponseCheckReader } from './response-checks/create-response-check-reader.js';
8
9
  import { createResponseCheckGuard } from './response-checks/create-response-check-guard.js';
@@ -11,19 +12,22 @@ export function createIfCapability(input = {}) {
11
12
  name: 'if',
12
13
  description: 'n8n IF: main input; true and false OUTPUT PORTS are mutually exclusive. Multiple edges from the SAME port all execute (fan-out) and can be joined. Type-strict declarative conditions.',
13
14
  parametersSchema: ifParametersSchema,
15
+ parameterReferenceSources: ['response'],
14
16
  createPlanningParametersSchema: createIfPlanningParametersSchema,
15
17
  inputPorts: () => ['main'],
16
18
  outputPorts: () => ['true', 'false'],
17
19
  responseReferences: (parameters) => responseReferences(ifParametersSchema.parse(parameters).conditions),
20
+ parameterReferenceBindings: (parameters) => responseReferenceBindings(ifParametersSchema.parse(parameters).conditions, '/conditions'),
18
21
  waitsForAllInputs: false,
19
22
  exclusiveOutputPorts: true,
20
- compile: ({ planned, apiNodeNames, apiResponseContracts, position }) => {
23
+ compile: ({ planned, apiNodeNames, apiResponseContracts, singletonApiResponseIds, position, }) => {
21
24
  const parameters = ifParametersSchema.parse(planned.parameters);
22
25
  const reader = createResponseCheckReader({
23
26
  nodeId: planned.id,
24
27
  checks: parameters.conditions,
25
28
  apiNodeNames,
26
29
  apiResponseContracts,
30
+ singletonApiResponseIds,
27
31
  linked: input.itemMode === 'linked',
28
32
  });
29
33
  const fragment = createNativeFragment(node({
@@ -43,7 +47,7 @@ export function createIfCapability(input = {}) {
43
47
  },
44
48
  conditions: parameters.conditions.map((check, index) => ({
45
49
  id: `${planned.id}-${index}`,
46
- leftValue: conditionExpression(check, apiNodeNames, input.itemMode === 'linked'),
50
+ leftValue: conditionExpression(check, apiNodeNames, input.itemMode === 'linked', singletonApiResponseIds),
47
51
  rightValue: true,
48
52
  operator: { type: 'boolean', operation: 'equals' },
49
53
  })),
@@ -0,0 +1,24 @@
1
+ /*! MIT License
2
+
3
+ Copyright (c) 2026 carefreelife98
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+ */
23
+ var OpenApiFlowNativeInputRuntime;
24
+ (()=>{function f(e){if(e==="")return[];if(!e.startsWith("/")||/~(?![01])/u.test(e))throw new Error(`Invalid JSON Pointer: ${e}`);return e.slice(1).split("/").map(i=>i.replaceAll("~1","/").replaceAll("~0","~"))}function l(e){if(Array.isArray(e))return e.map(l);if(e===null||typeof e!="object")return e;let i=Object.create(null);for(let[c,r]of Object.entries(e))i[c]=l(r);return i}function y(e){let i=f(e.pointer);if(!i.length)throw new Error(`${e.source} must identify a JSON field`);let c=l(e.values),r=c;for(let[o,t]of i.entries()){if(Array.isArray(r)&&(!/^(0|[1-9][0-9]*)$/.test(t)||Number(t)>r.length))throw new Error(`${e.source} ${e.pointer} requires an explicit complete array prefix`);if(o===i.length-1){if(Object.hasOwn(r,t))throw new Error(`${e.source} conflicts with existing value at ${e.pointer}`);Reflect.set(r,t,l(e.value))}else{if(!Object.hasOwn(r,t)){let a="/"+i.slice(0,o+1).map(s=>s.replaceAll("~","~0").replaceAll("/","~1")).join("/");Reflect.set(r,t,e.containerKind(a)==="array"?[]:Object.create(null))}let n=Reflect.get(r,t);if(n===null||typeof n!="object")throw new Error(`${e.source} traverses non-container ${e.pointer}`);r=n}}return JSON.parse(JSON.stringify(c))}function d(e,i){let c=l(e.parameters),r=[...e.inputs].sort((o,t)=>{let n=f(o.targetPointer),a=f(t.targetPointer);for(let s=0;s<Math.min(n.length,a.length);s++)if(n[s]!==a[s])return/^(0|[1-9][0-9]*)$/.test(n[s])&&/^(0|[1-9][0-9]*)$/.test(a[s])?Number(n[s])-Number(a[s]):n[s].localeCompare(a[s]);return n.length-a.length});for(let o of r){if(!Object.hasOwn(i,o.id))throw new Error(`Missing native runtime input ${o.id} for ${e.nodeId}${o.targetPointer}`);let t=i[o.id];if(o.targetPointer===""){if(r.length!==1||Object.keys(c).length||t===null||typeof t!="object"||Array.isArray(t))throw new Error(`Native runtime input ${e.nodeId} must be an exclusive JSON parameter object`);c=l(t)}else c=y({values:c,pointer:o.targetPointer,value:t,source:`Native runtime input ${e.nodeId}`,containerKind(n){if(!Object.hasOwn(o.containerKinds,n))throw new Error(`Native runtime input ${e.nodeId} has no declared container at ${n}`);return o.containerKinds[n]}})}return c}OpenApiFlowNativeInputRuntime={materializeNativeRuntimeParameters:d};})();
@@ -0,0 +1,4 @@
1
+ import type { PrependNativeParameterGuardInput } from '../../../types/native-runtime-parameters.js';
2
+ import type { N8nNodeFragment } from '../../../types/node-fragment.js';
3
+ /** Validate the unchanged declared parameter object again immediately before the native node. */
4
+ export declare function prependNativeParameterGuard({ input, capability, fragment, }: PrependNativeParameterGuardInput): N8nNodeFragment;
@@ -0,0 +1,52 @@
1
+ import { node } from '@n8n/workflow-sdk';
2
+ import { readFileSync } from 'node:fs';
3
+ import { isDeepStrictEqual } from 'node:util';
4
+ import { createNativeRuntimeParameterMaterializations } from '@openapi-flow/core';
5
+ import { compileStandaloneValidator } from '../../common/validation/compile-standalone-validator.js';
6
+ import { javascriptJsonLiteral } from '../../../utils/javascript-json-literal.js';
7
+ /** Validate the unchanged declared parameter object again immediately before the native node. */
8
+ export function prependNativeParameterGuard({ input, capability, fragment, }) {
9
+ const configuration = input.runtimeInput;
10
+ if (!configuration ||
11
+ typeof configuration.inputNodeName !== 'string' ||
12
+ !configuration.inputNodeName.trim() ||
13
+ !Number.isSafeInteger(configuration.revision) ||
14
+ configuration.revision < 0)
15
+ throw new Error(`node ${input.planned.id}: runtime parameters require an explicit template input source and revision`);
16
+ const [materialization] = createNativeRuntimeParameterMaterializations({
17
+ nativeNodes: [input.planned],
18
+ capabilities: [capability],
19
+ });
20
+ if (!materialization ||
21
+ !isDeepStrictEqual(materialization, configuration.materialization))
22
+ throw new Error(`node ${input.planned.id}: runtime parameter slot differs from its original capability contract`);
23
+ const validator = compileStandaloneValidator({
24
+ schema: materialization.schema,
25
+ globalName: 'OpenApiFlowNativeParametersValidator',
26
+ });
27
+ const runtime = readFileSync(new URL('./native-input-runtime.bundle.js', import.meta.url), 'utf8');
28
+ const read = `const configurations=$(${javascriptJsonLiteral(configuration.inputNodeName)}).all();if(configurations.length!==1)throw new Error('Native runtime input requires exactly one configuration item');const payload=configurations[0].json;if(!payload||payload.revision!==${configuration.revision})throw new Error('Missing or stale native input revision');if(!payload.values||typeof payload.values!=='object')throw new Error('Missing native runtime input values');const parameters=OpenApiFlowNativeInputRuntime.materializeNativeRuntimeParameters(${javascriptJsonLiteral(materialization)},payload.values);if(!OpenApiFlowNativeParametersValidator(parameters))throw new Error('Native runtime input violates original schema for '+${javascriptJsonLiteral(materialization.nodeId)}+': '+JSON.stringify(OpenApiFlowNativeParametersValidator.errors));`;
29
+ const guard = node({
30
+ type: 'n8n-nodes-base.code',
31
+ version: 2,
32
+ config: {
33
+ id: `${input.planned.id}-parameters`,
34
+ name: `Parameters ${input.planned.id}`,
35
+ position: [input.position[0] - 220, input.position[1]],
36
+ parameters: {
37
+ mode: 'runOnceForAllItems',
38
+ language: 'javaScript',
39
+ jsCode: `${runtime}\n${validator}\n${read}\nreturn $input.all().map((_,index)=>({json:parameters,pairedItem:{item:index}}));`,
40
+ },
41
+ },
42
+ });
43
+ return {
44
+ ...fragment,
45
+ entry: guard,
46
+ nodes: [guard, ...fragment.nodes],
47
+ internalEdges: [
48
+ { from: guard.id, output: 0, to: fragment.entry.id, input: 0 },
49
+ ...(fragment.internalEdges === undefined ? [] : fragment.internalEdges),
50
+ ],
51
+ };
52
+ }
@@ -0,0 +1,3 @@
1
+ import type { N8nNativeCapability } from '../../../types/native-capability.js';
2
+ import type { BoundItemJoinCapabilityInput } from '../../../types/native-material-binding.js';
3
+ export declare function createBoundItemJoinCapability({ materials, scopes, runtime: sourceBinding, }: BoundItemJoinCapabilityInput): N8nNativeCapability;
@@ -0,0 +1,169 @@
1
+ import { defineMaterialBoundCapability } from '../common/define-material-bound-capability.js';
2
+ import { node } from '@n8n/workflow-sdk';
3
+ import { readFileSync } from 'node:fs';
4
+ import { createResponseValueSchema, validateNativeOutputContracts, } from '@openapi-flow/core';
5
+ import { resolveNativeRuntimeSource } from '../common/resolve-native-runtime-source.js';
6
+ import { createItemJoinParametersSchema } from '../../../schemas/item-join-schema.js';
7
+ import { itemJoinDefinition } from './item-join-definition.js';
8
+ import { javascriptJsonLiteral } from '../../../utils/javascript-json-literal.js';
9
+ import { createItemJoinReaderCode } from './create-item-join-reader-code.js';
10
+ export function createBoundItemJoinCapability({ materials, scopes, runtime: sourceBinding, }) {
11
+ const apis = new Map(materials.map((material) => [material.callId, material]));
12
+ validateNativeOutputContracts(scopes);
13
+ const scopeContracts = scopes.map(({ nodeId, schema }) => ({
14
+ nodeId,
15
+ schema,
16
+ }));
17
+ const scopeById = new Map(scopeContracts.map((scope) => [scope.nodeId, scope]));
18
+ if (apis.size !== materials.length ||
19
+ materials.some((material) => !material.callId.trim()))
20
+ throw new Error('item join materials require unique non-empty callIds');
21
+ if (scopeById.size !== scopes.length ||
22
+ scopes.some((scope) => !scope.nodeId.trim()))
23
+ throw new Error('item join scopes require unique non-empty contract identities');
24
+ const parametersSchema = createItemJoinParametersSchema([...scopeById.keys()], [...apis.keys()]);
25
+ return defineMaterialBoundCapability({
26
+ ...itemJoinDefinition,
27
+ parametersSchema,
28
+ materialSources: {
29
+ apiMaterials: structuredClone(materials),
30
+ nativeOutputs: structuredClone(scopeContracts),
31
+ },
32
+ bindMaterialContracts: (sources) => createBoundItemJoinCapability({
33
+ materials: sources.apiMaterials,
34
+ scopes: sources.nativeOutputs,
35
+ runtime: { kind: 'compiled' },
36
+ }),
37
+ responseReferences: (values) => parametersSchema.parse(values).sourceCallIds.map((nodeId) => ({
38
+ source: 'response',
39
+ nodeId,
40
+ pointer: '',
41
+ })),
42
+ nodeOutputReferences: (values) => [
43
+ {
44
+ source: 'node-output',
45
+ nodeId: parametersSchema.parse(values).scopeNodeId,
46
+ pointer: '',
47
+ },
48
+ ],
49
+ inputReferences: (values) => {
50
+ const parameters = parametersSchema.parse(values);
51
+ return Object.fromEntries(parameters.sourceCallIds.map((nodeId, i) => [
52
+ `input${i + 1}`,
53
+ [
54
+ { source: 'response', nodeId, pointer: '' },
55
+ {
56
+ source: 'node-output',
57
+ nodeId: parameters.scopeNodeId,
58
+ pointer: '',
59
+ },
60
+ ],
61
+ ]));
62
+ },
63
+ outputSchema: (values) => {
64
+ const parameters = parametersSchema.parse(values);
65
+ return {
66
+ type: 'object',
67
+ required: ['responses'],
68
+ additionalProperties: false,
69
+ properties: {
70
+ responses: {
71
+ type: 'object',
72
+ additionalProperties: false,
73
+ required: parameters.sourceCallIds,
74
+ properties: Object.fromEntries(parameters.sourceCallIds.map((id) => [
75
+ id,
76
+ createResponseValueSchema(apis.get(id).operation, ''),
77
+ ])),
78
+ },
79
+ },
80
+ };
81
+ },
82
+ compile: ({ planned, position, apiNodeNames, nativeOutputSources }) => {
83
+ const parameters = parametersSchema.parse(planned.parameters);
84
+ const scope = resolveNativeRuntimeSource({
85
+ binding: sourceBinding,
86
+ contract: scopeById.get(parameters.scopeNodeId),
87
+ compiledSources: nativeOutputSources,
88
+ consumerId: planned.id,
89
+ });
90
+ const bindingSources = [
91
+ { ...scope, kind: 'native-json' },
92
+ ...parameters.sourceCallIds.map((id) => {
93
+ if (!Object.hasOwn(apiNodeNames, id) || !apiNodeNames[id].trim())
94
+ throw new Error(`item join apiNodeNames is missing ${id}`);
95
+ return {
96
+ kind: 'api-response',
97
+ nodeId: id,
98
+ nodeName: apiNodeNames[id],
99
+ operation: apis.get(id).operation,
100
+ };
101
+ }),
102
+ ];
103
+ const readers = parameters.sourceCallIds.map((id, index) => node({
104
+ type: 'n8n-nodes-base.code',
105
+ version: 2,
106
+ config: {
107
+ id: `${planned.id}-read-${index}`,
108
+ name: `Read branch ${index + 1} ${planned.id}`,
109
+ position: [position[0], position[1] + index * 180],
110
+ parameters: {
111
+ mode: 'runOnceForAllItems',
112
+ jsCode: createItemJoinReaderCode({
113
+ scope,
114
+ sourceCallId: id,
115
+ sources: [bindingSources[0], bindingSources[index + 1]],
116
+ }),
117
+ },
118
+ },
119
+ }));
120
+ const merge = node({
121
+ type: 'n8n-nodes-base.merge',
122
+ version: 3.2,
123
+ config: {
124
+ id: `${planned.id}-wait`,
125
+ name: `Wait branches ${planned.id}`,
126
+ position: [position[0] + 220, position[1]],
127
+ parameters: { mode: 'append', numberInputs: readers.length },
128
+ },
129
+ });
130
+ const runtime = readFileSync(new URL('./runtime/item-join-runtime.bundle.js', import.meta.url), 'utf8');
131
+ const joined = node({
132
+ type: 'n8n-nodes-base.code',
133
+ version: 2,
134
+ config: {
135
+ id: planned.id,
136
+ name: planned.id,
137
+ position: [position[0] + 440, position[1]],
138
+ parameters: {
139
+ mode: 'runOnceForAllItems',
140
+ jsCode: `${runtime}\nreturn OpenApiFlowItemJoinRuntime.joinApiItems({items:$input.all(),sourceCallIds:${javascriptJsonLiteral(parameters.sourceCallIds)}});`,
141
+ },
142
+ },
143
+ });
144
+ return {
145
+ nodeId: planned.id,
146
+ joinsInputItemsByAncestry: { scopeNodeId: parameters.scopeNodeId },
147
+ nodes: [...readers, merge, joined],
148
+ entry: readers[0],
149
+ exit: joined,
150
+ inputPorts: Object.fromEntries(itemJoinDefinition.inputPorts(parameters).map((port) => [port, 0])),
151
+ inputEndpoints: Object.fromEntries(readers.map((reader, i) => [
152
+ `input${i + 1}`,
153
+ { nodeId: reader.id, input: 0 },
154
+ ])),
155
+ outputPorts: { main: 0 },
156
+ bindingSources,
157
+ internalEdges: [
158
+ ...readers.map((reader, index) => ({
159
+ from: reader.id,
160
+ output: 0,
161
+ to: merge.id,
162
+ input: index,
163
+ })),
164
+ { from: merge.id, output: 0, to: joined.id, input: 0 },
165
+ ],
166
+ };
167
+ },
168
+ });
169
+ }
@@ -1,3 +1,4 @@
1
1
  import type { N8nNativeCapability } from '../../../types/native-capability.js';
2
2
  import type { CreateItemJoinCapabilityInput } from '../../../types/item-join.js';
3
- export declare function createItemJoinCapability({ materials, scopes, }: CreateItemJoinCapabilityInput): N8nNativeCapability;
3
+ /** Preserve explicitly supplied original runtime names; later revisions bind contracts and SDK names separately. */
4
+ export declare function createItemJoinCapability(input: CreateItemJoinCapabilityInput): N8nNativeCapability;
@@ -1,153 +1,10 @@
1
- import { node } from '@n8n/workflow-sdk';
2
- import { readFileSync } from 'node:fs';
3
- import { createResponseValueSchema } from '@openapi-flow/core';
4
- import { createItemJoinParametersSchema } from '../../../schemas/item-join-schema.js';
5
- import { javascriptJsonLiteral } from '../../../utils/javascript-json-literal.js';
6
- import { createItemJoinReaderCode } from './create-item-join-reader-code.js';
7
- export function createItemJoinCapability({ materials, scopes, }) {
8
- const apis = new Map(materials.map((material) => [material.callId, material]));
9
- const scopeById = new Map(scopes.map((scope) => [scope.nodeId, scope]));
10
- if (apis.size !== materials.length ||
11
- materials.some((material) => !material.callId.trim()))
12
- throw new Error('item join materials require unique non-empty callIds');
13
- if (scopeById.size !== scopes.length ||
14
- scopes.some((scope) => !scope.nodeId.trim() || !scope.nodeName.trim()))
1
+ import { createBoundItemJoinCapability } from './create-bound-item-join-capability.js';
2
+ /** Preserve explicitly supplied original runtime names; later revisions bind contracts and SDK names separately. */
3
+ export function createItemJoinCapability(input) {
4
+ if (input.scopes.some((scope) => typeof scope.nodeName !== 'string' || !scope.nodeName.trim()))
15
5
  throw new Error('item join scopes require unique non-empty identities and compiled names');
16
- const parametersSchema = createItemJoinParametersSchema([...scopeById.keys()], [...apis.keys()]);
17
- const ports = (count) => Array.from({ length: count }, (_, i) => `input${i + 1}`);
18
- return {
19
- name: 'join-api-items',
20
- description: 'Join API branches by their shared native scope item ancestry. Each participating item requires exactly one full OAS-valid response per API. Different orders and duplicate JSON values are safe. Missing/duplicate branch responses fail; no business-ID matching, index zip, Cartesian product or value conversion. Output {responses: {callId: unchangedBody}}.',
21
- parametersSchema,
22
- inputPorts: (values) => ports(parametersSchema.parse(values).sourceCallIds.length),
23
- outputPorts: () => ['main'],
24
- responseReferences: (values) => parametersSchema.parse(values).sourceCallIds.map((nodeId) => ({
25
- source: 'response',
26
- nodeId,
27
- pointer: '',
28
- })),
29
- nodeOutputReferences: (values) => [
30
- {
31
- source: 'node-output',
32
- nodeId: parametersSchema.parse(values).scopeNodeId,
33
- pointer: '',
34
- },
35
- ],
36
- inputReferences: (values) => {
37
- const parameters = parametersSchema.parse(values);
38
- return Object.fromEntries(parameters.sourceCallIds.map((nodeId, i) => [
39
- `input${i + 1}`,
40
- [
41
- { source: 'response', nodeId, pointer: '' },
42
- {
43
- source: 'node-output',
44
- nodeId: parameters.scopeNodeId,
45
- pointer: '',
46
- },
47
- ],
48
- ]));
49
- },
50
- waitsForAllInputs: true,
51
- exclusiveOutputPorts: false,
52
- outputSchema: (values) => {
53
- const parameters = parametersSchema.parse(values);
54
- return {
55
- type: 'object',
56
- required: ['responses'],
57
- additionalProperties: false,
58
- properties: {
59
- responses: {
60
- type: 'object',
61
- additionalProperties: false,
62
- required: parameters.sourceCallIds,
63
- properties: Object.fromEntries(parameters.sourceCallIds.map((id) => [
64
- id,
65
- createResponseValueSchema(apis.get(id).operation, ''),
66
- ])),
67
- },
68
- },
69
- };
70
- },
71
- compile: ({ planned, position, apiNodeNames }) => {
72
- const parameters = parametersSchema.parse(planned.parameters);
73
- const scope = scopeById.get(parameters.scopeNodeId);
74
- const bindingSources = [
75
- { ...scope, kind: 'native-json' },
76
- ...parameters.sourceCallIds.map((id) => {
77
- if (!Object.hasOwn(apiNodeNames, id) || !apiNodeNames[id].trim())
78
- throw new Error(`item join apiNodeNames is missing ${id}`);
79
- return {
80
- kind: 'api-response',
81
- nodeId: id,
82
- nodeName: apiNodeNames[id],
83
- operation: apis.get(id).operation,
84
- };
85
- }),
86
- ];
87
- const readers = parameters.sourceCallIds.map((id, index) => node({
88
- type: 'n8n-nodes-base.code',
89
- version: 2,
90
- config: {
91
- id: `${planned.id}-read-${index}`,
92
- name: `Read branch ${index + 1} ${planned.id}`,
93
- position: [position[0], position[1] + index * 180],
94
- parameters: {
95
- mode: 'runOnceForAllItems',
96
- jsCode: createItemJoinReaderCode({
97
- scope,
98
- sourceCallId: id,
99
- sources: [bindingSources[0], bindingSources[index + 1]],
100
- }),
101
- },
102
- },
103
- }));
104
- const merge = node({
105
- type: 'n8n-nodes-base.merge',
106
- version: 3.2,
107
- config: {
108
- id: `${planned.id}-wait`,
109
- name: `Wait branches ${planned.id}`,
110
- position: [position[0] + 220, position[1]],
111
- parameters: { mode: 'append', numberInputs: readers.length },
112
- },
113
- });
114
- const runtime = readFileSync(new URL('./runtime/item-join-runtime.bundle.js', import.meta.url), 'utf8');
115
- const joined = node({
116
- type: 'n8n-nodes-base.code',
117
- version: 2,
118
- config: {
119
- id: planned.id,
120
- name: planned.id,
121
- position: [position[0] + 440, position[1]],
122
- parameters: {
123
- mode: 'runOnceForAllItems',
124
- jsCode: `${runtime}\nreturn OpenApiFlowItemJoinRuntime.joinApiItems({items:$input.all(),sourceCallIds:${javascriptJsonLiteral(parameters.sourceCallIds)}});`,
125
- },
126
- },
127
- });
128
- return {
129
- nodeId: planned.id,
130
- joinsInputItemsByAncestry: { scopeNodeId: parameters.scopeNodeId },
131
- nodes: [...readers, merge, joined],
132
- entry: readers[0],
133
- exit: joined,
134
- inputPorts: Object.fromEntries(ports(readers.length).map((port) => [port, 0])),
135
- inputEndpoints: Object.fromEntries(readers.map((reader, i) => [
136
- `input${i + 1}`,
137
- { nodeId: reader.id, input: 0 },
138
- ])),
139
- outputPorts: { main: 0 },
140
- bindingSources,
141
- internalEdges: [
142
- ...readers.map((reader, index) => ({
143
- from: reader.id,
144
- output: 0,
145
- to: merge.id,
146
- input: index,
147
- })),
148
- { from: merge.id, output: 0, to: joined.id, input: 0 },
149
- ],
150
- };
151
- },
152
- };
6
+ return createBoundItemJoinCapability({
7
+ ...input,
8
+ runtime: { kind: 'provided', sources: input.scopes },
9
+ });
153
10
  }
@@ -0,0 +1,2 @@
1
+ import type { NativeMaterialFeatureDefinition } from '../../../types/native-material-binding.js';
2
+ export declare const itemJoinDefinition: NativeMaterialFeatureDefinition;
@@ -0,0 +1,33 @@
1
+ import { itemJoinParametersSchema } from '../../../schemas/item-join-schema.js';
2
+ export const itemJoinDefinition = {
3
+ name: 'join-api-items',
4
+ materialRequirements: [
5
+ { field: 'apiMaterials', minimumItems: 2 },
6
+ { field: 'nativeOutputs', minimumItems: 1 },
7
+ ],
8
+ description: 'Join API branches by their shared native scope item ancestry. Each participating item requires exactly one full OAS-valid response per API. Different orders and duplicate JSON values are safe. Missing/duplicate branch responses fail; no business-ID matching, index zip, Cartesian product or value conversion. Output {responses: {callId: unchangedBody}}.',
9
+ parametersSchema: itemJoinParametersSchema,
10
+ parameterReferenceSources: ['response', 'node-output'],
11
+ inputPorts: (values) => Array.from({ length: itemJoinParametersSchema.parse(values).sourceCallIds.length }, (_, index) => `input${index + 1}`),
12
+ outputPorts: () => ['main'],
13
+ referenceStructureSchema: itemJoinParametersSchema,
14
+ parameterReferenceBindings: (values) => {
15
+ const parameters = itemJoinParametersSchema.parse(values);
16
+ return [
17
+ ...parameters.sourceCallIds.map((nodeId, index) => ({
18
+ nodeIdPointer: `/sourceCallIds/${index}`,
19
+ reference: { source: 'response', nodeId, pointer: '' },
20
+ })),
21
+ {
22
+ nodeIdPointer: '/scopeNodeId',
23
+ reference: {
24
+ source: 'node-output',
25
+ nodeId: parameters.scopeNodeId,
26
+ pointer: '',
27
+ },
28
+ },
29
+ ];
30
+ },
31
+ waitsForAllInputs: true,
32
+ exclusiveOutputPorts: false,
33
+ };
@@ -6,9 +6,11 @@ export function createMergeAppendCapability() {
6
6
  name: 'merge-append',
7
7
  description: 'n8n Merge append: input1..inputN; main output. Waits for all independent incoming branches.',
8
8
  parametersSchema: mergeParametersSchema,
9
+ parameterReferenceSources: [],
9
10
  inputPorts: (parameters) => Array.from({ length: mergeParametersSchema.parse(parameters).numberInputs }, (_, index) => `input${index + 1}`),
10
11
  outputPorts: () => ['main'],
11
12
  responseReferences: () => [],
13
+ parameterReferenceBindings: () => [],
12
14
  waitsForAllInputs: true,
13
15
  exclusiveOutputPorts: false,
14
16
  compile: ({ planned, position }) => {
@@ -0,0 +1,4 @@
1
+ import { N8nNativeFeature } from '../../../types/native-feature-registry.js';
2
+ import type { N8nNativeFeatureDefinition } from '../../../types/native-feature-registry.js';
3
+ /** Material prerequisites belong to their actual factories, not model prompts. */
4
+ export declare const nativeFeatureDefinitions: Record<N8nNativeFeature, N8nNativeFeatureDefinition>;