@fluentcommerce/fc-connect-sdk 0.1.54 → 0.1.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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/clients/fluent-client.js +13 -6
- package/dist/cjs/utils/pagination-helpers.js +38 -2
- package/dist/cjs/versori/fluent-versori-client.js +11 -5
- package/dist/esm/clients/fluent-client.js +13 -6
- package/dist/esm/utils/pagination-helpers.js +38 -2
- package/dist/esm/versori/fluent-versori-client.js +11 -5
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/docs/00-START-HERE/EXPORT-VALIDATION.md +158 -158
- package/docs/00-START-HERE/cli-analyze-source-structure-guide.md +655 -655
- package/docs/00-START-HERE/cli-documentation-index.md +202 -202
- package/docs/00-START-HERE/cli-quick-reference.md +252 -252
- package/docs/00-START-HERE/decision-tree.md +552 -552
- package/docs/00-START-HERE/getting-started.md +1070 -1070
- package/docs/00-START-HERE/mapper-quick-decision-guide.md +235 -235
- package/docs/00-START-HERE/readme.md +237 -237
- package/docs/00-START-HERE/retailerid-configuration.md +404 -404
- package/docs/00-START-HERE/sdk-philosophy.md +794 -794
- package/docs/00-START-HERE/troubleshooting-quick-reference.md +1086 -1086
- package/docs/01-TEMPLATES/faq.md +686 -686
- package/docs/01-TEMPLATES/patterns/pattern-templates-guide.md +68 -68
- package/docs/01-TEMPLATES/patterns/patterns-csv-schema-validation-and-rejection-report.md +233 -233
- package/docs/01-TEMPLATES/patterns/patterns-custom-resolvers.md +407 -407
- package/docs/01-TEMPLATES/patterns/patterns-error-handling-retry.md +511 -511
- package/docs/01-TEMPLATES/patterns/patterns-field-mapping-universal.md +701 -701
- package/docs/01-TEMPLATES/patterns/patterns-large-file-splitting.md +1430 -1430
- package/docs/01-TEMPLATES/patterns/patterns-master-data-etl.md +2399 -2399
- package/docs/01-TEMPLATES/patterns/patterns-pagination-streaming.md +447 -447
- package/docs/01-TEMPLATES/patterns/patterns-state-duplicate-prevention.md +385 -385
- package/docs/01-TEMPLATES/readme.md +957 -957
- package/docs/01-TEMPLATES/standalone/standalone-asn-inbound-processing.md +1209 -1209
- package/docs/01-TEMPLATES/standalone/standalone-graphql-query-export.md +1140 -1140
- package/docs/01-TEMPLATES/standalone/standalone-graphql-to-parquet-partitioned-s3.md +432 -432
- package/docs/01-TEMPLATES/standalone/standalone-multi-channel-inventory-sync.md +1185 -1185
- package/docs/01-TEMPLATES/standalone/standalone-multi-source-aggregation.md +1462 -1462
- package/docs/01-TEMPLATES/standalone/standalone-s3-csv-batch-api.md +1390 -1390
- package/docs/01-TEMPLATES/standalone/standalone-s3-csv-inventory-to-batch.md +330 -330
- package/docs/01-TEMPLATES/standalone/standalone-scripts-guide.md +87 -87
- package/docs/01-TEMPLATES/standalone/standalone-sftp-xml-graphql.md +1444 -1444
- package/docs/01-TEMPLATES/standalone/standalone-webhook-payload-processing.md +688 -688
- package/docs/01-TEMPLATES/versori/business-examples/business-examples-dropship-order-routing.md +193 -193
- package/docs/01-TEMPLATES/versori/business-examples/business-examples-graphql-parquet-extraction.md +518 -518
- package/docs/01-TEMPLATES/versori/business-examples/business-examples-inter-location-transfers.md +2162 -2162
- package/docs/01-TEMPLATES/versori/business-examples/business-examples-pre-order-allocation.md +2226 -2226
- package/docs/01-TEMPLATES/versori/business-examples/business-scenarios-guide.md +87 -87
- package/docs/01-TEMPLATES/versori/patterns/versori-patterns-connection-validation-pattern.md +656 -656
- package/docs/01-TEMPLATES/versori/patterns/versori-patterns-dual-workflow-connector.md +835 -835
- package/docs/01-TEMPLATES/versori/patterns/versori-patterns-guide.md +108 -108
- package/docs/01-TEMPLATES/versori/patterns/versori-patterns-kv-state-management.md +1533 -1533
- package/docs/01-TEMPLATES/versori/patterns/versori-patterns-xml-response-patterns.md +1160 -1160
- package/docs/01-TEMPLATES/versori/versori-platform-guide.md +201 -201
- package/docs/01-TEMPLATES/versori/webhooks/template-webhook-asn-purchase-order.md +1906 -1906
- package/docs/01-TEMPLATES/versori/webhooks/template-webhook-dropship-routing.md +1074 -1074
- package/docs/01-TEMPLATES/versori/webhooks/template-webhook-flash-sale-reserve.md +1395 -1395
- package/docs/01-TEMPLATES/versori/webhooks/template-webhook-generic-xml-order.md +888 -888
- package/docs/01-TEMPLATES/versori/webhooks/template-webhook-payment-gateway-integration.md +2478 -2478
- package/docs/01-TEMPLATES/versori/webhooks/template-webhook-rma-returns-comprehensive.md +2240 -2240
- package/docs/01-TEMPLATES/versori/webhooks/template-webhook-xml-order-ingestion.md +2029 -2029
- package/docs/01-TEMPLATES/versori/webhooks/webhook-templates-guide.md +140 -140
- package/docs/01-TEMPLATES/versori/workflows/_examples/sample-data/inventory-mapping.json +20 -20
- package/docs/01-TEMPLATES/versori/workflows/_examples/sample-data/products_2025-01-22.csv +11 -11
- package/docs/01-TEMPLATES/versori/workflows/_examples/sample-data/sample-data-guide.md +34 -34
- package/docs/01-TEMPLATES/versori/workflows/_examples/workflow-examples-guide.md +36 -36
- package/docs/01-TEMPLATES/versori/workflows/extraction/extraction-modes-guide.md +1038 -1038
- package/docs/01-TEMPLATES/versori/workflows/extraction/extraction-workflows-guide.md +138 -138
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/graphql-extraction-guide.md +63 -63
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-fulfillments-to-sftp-csv.md +2062 -2062
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-fulfillments-to-sftp-xml.md +2294 -2294
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-inventory-positions-to-s3-csv.md +2461 -2461
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-inventory-positions-to-sftp-xml.md +2529 -2529
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-inventory-quantities-to-s3-csv.md +2464 -2464
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-inventory-quantities-to-s3-json.md +1959 -1959
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-orders-to-s3-csv.md +1953 -1953
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-orders-to-sftp-xml.md +2541 -2541
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-products-to-s3-json.md +2384 -2384
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-products-to-sftp-xml.md +2445 -2445
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-virtual-positions-to-s3-csv.md +2355 -2355
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-virtual-positions-to-s3-json.md +2042 -2042
- package/docs/01-TEMPLATES/versori/workflows/extraction/graphql-queries/template-extraction-virtual-positions-to-sftp-xml.md +2726 -2726
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/batch-api-guide.md +206 -206
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-cycle-count-reconciliation.md +2030 -2030
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-multi-channel-inventory-sync.md +1882 -1882
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-s3-csv-inventory-batch.md +2827 -2827
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-s3-json-inventory-batch.md +1952 -1952
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-s3-xml-inventory-batch.md +3289 -3289
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-sftp-csv-inventory-batch.md +3064 -3064
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-sftp-json-inventory-batch.md +3238 -3238
- package/docs/01-TEMPLATES/versori/workflows/ingestion/batch-api/template-ingestion-sftp-xml-inventory-batch.md +2977 -2977
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/event-api-guide.md +321 -321
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-payload-json-order-cancel-event.md +959 -959
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-payload-xml-order-cancel-event.md +1170 -1170
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-s3-csv-product-event.md +2312 -2312
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-s3-json-product-event.md +2999 -2999
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-s3-parquet-product-event.md +2836 -2836
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-s3-xml-product-event.md +2395 -2395
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-sftp-csv-product-event.md +2295 -2295
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-sftp-json-product-event.md +2602 -2602
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-sftp-parquet-product-event.md +2589 -2589
- package/docs/01-TEMPLATES/versori/workflows/ingestion/event-api/template-ingestion-sftp-xml-product-event.md +3578 -3578
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/graphql-mutations-guide.md +93 -93
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-payload-json-order-update-graphql.md +1260 -1260
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-payload-xml-order-update-graphql.md +1472 -1472
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-s3-csv-control-graphql.md +2417 -2417
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-s3-csv-location-graphql.md +2811 -2811
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-s3-csv-price-graphql.md +2619 -2619
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-s3-json-location-graphql.md +2807 -2807
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-s3-xml-location-graphql.md +2373 -2373
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-sftp-csv-control-graphql.md +2740 -2740
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-sftp-csv-location-graphql.md +2760 -2760
- package/docs/01-TEMPLATES/versori/workflows/ingestion/graphql-mutations/template-ingestion-sftp-json-location-graphql.md +1710 -1710
- package/docs/01-TEMPLATES/versori/workflows/ingestion/ingestion-workflows-guide.md +136 -136
- package/docs/01-TEMPLATES/versori/workflows/rubix-webhooks/rubix-webhooks-guide.md +520 -520
- package/docs/01-TEMPLATES/versori/workflows/rubix-webhooks/template-webhook-rubix-fulfilment-to-sftp-xml-inline.md +1418 -1418
- package/docs/01-TEMPLATES/versori/workflows/rubix-webhooks/template-webhook-rubix-fulfilment-to-sftp-xml-universal-mapper.md +1785 -1785
- package/docs/01-TEMPLATES/versori/workflows/rubix-webhooks/template-webhook-rubix-order-attribute-update.md +824 -824
- package/docs/01-TEMPLATES/versori/workflows/workflows-overview-guide.md +646 -646
- package/docs/02-CORE-GUIDES/advanced-services/advanced-services-batch-archival.md +724 -724
- package/docs/02-CORE-GUIDES/advanced-services/advanced-services-job-tracker.md +627 -627
- package/docs/02-CORE-GUIDES/advanced-services/advanced-services-partial-batch-recovery.md +561 -561
- package/docs/02-CORE-GUIDES/advanced-services/advanced-services-quick-reference.md +367 -367
- package/docs/02-CORE-GUIDES/advanced-services/advanced-services-readme.md +407 -407
- package/docs/02-CORE-GUIDES/advanced-services/readme.md +49 -49
- package/docs/02-CORE-GUIDES/api-reference/api-reference-quick-reference.md +548 -548
- package/docs/02-CORE-GUIDES/api-reference/event-api-input-output-reference.md +702 -1171
- package/docs/02-CORE-GUIDES/api-reference/examples/client-initialization.ts +286 -286
- package/docs/02-CORE-GUIDES/api-reference/graphql-error-classification.md +337 -337
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-01-client-api.md +399 -520
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-03-authentication.md +199 -199
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-04-graphql-mapping.md +925 -925
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-05-services.md +1198 -1198
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-06-data-sources.md +1083 -1083
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-07-parsers.md +1097 -1097
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-08-pagination.md +513 -513
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-08-types.md +545 -597
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-09-error-handling.md +527 -527
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-09-webhook-validation.md +514 -514
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-10-extraction.md +557 -557
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-10-utilities.md +412 -412
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-11-cli-tools.md +423 -423
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-11-error-handling.md +716 -716
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-12-analyze-source-structure.md +518 -518
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-12-partial-responses.md +212 -212
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-12-testing.md +300 -300
- package/docs/02-CORE-GUIDES/api-reference/modules/api-reference-13-resolver-builder.md +322 -322
- package/docs/02-CORE-GUIDES/api-reference/readme.md +279 -279
- package/docs/02-CORE-GUIDES/auto-pagination/auto-pagination-quick-reference.md +351 -351
- package/docs/02-CORE-GUIDES/auto-pagination/auto-pagination-readme.md +277 -277
- package/docs/02-CORE-GUIDES/auto-pagination/examples/auto-pagination-readme.md +178 -178
- package/docs/02-CORE-GUIDES/auto-pagination/examples/common-patterns.ts +351 -351
- package/docs/02-CORE-GUIDES/auto-pagination/examples/paginate-products.ts +384 -384
- package/docs/02-CORE-GUIDES/auto-pagination/examples/paginate-virtual-positions.ts +308 -308
- package/docs/02-CORE-GUIDES/auto-pagination/modules/auto-pagination-01-foundations.md +470 -470
- package/docs/02-CORE-GUIDES/auto-pagination/modules/auto-pagination-02-quick-start.md +713 -713
- package/docs/02-CORE-GUIDES/auto-pagination/modules/auto-pagination-03-configuration.md +754 -754
- package/docs/02-CORE-GUIDES/auto-pagination/modules/auto-pagination-04-advanced-patterns.md +732 -732
- package/docs/02-CORE-GUIDES/auto-pagination/modules/auto-pagination-05-sdk-integration.md +847 -847
- package/docs/02-CORE-GUIDES/auto-pagination/modules/auto-pagination-06-troubleshooting.md +359 -359
- package/docs/02-CORE-GUIDES/auto-pagination/modules/auto-pagination-07-api-reference.md +462 -462
- package/docs/02-CORE-GUIDES/auto-pagination/readme.md +54 -54
- package/docs/02-CORE-GUIDES/data-sources/data-sources-file-operations-error-handling.md +1487 -1487
- package/docs/02-CORE-GUIDES/data-sources/data-sources-quick-reference.md +836 -836
- package/docs/02-CORE-GUIDES/data-sources/data-sources-readme.md +276 -276
- package/docs/02-CORE-GUIDES/data-sources/data-sources-sftp-credential-access-security.md +553 -553
- package/docs/02-CORE-GUIDES/data-sources/examples/common-patterns.ts +409 -409
- package/docs/02-CORE-GUIDES/data-sources/examples/data-sources-readme.md +178 -178
- package/docs/02-CORE-GUIDES/data-sources/examples/s3-operations.ts +308 -308
- package/docs/02-CORE-GUIDES/data-sources/examples/sftp-operations.ts +371 -371
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-01-foundations.md +735 -735
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-02-s3-operations.md +1302 -1302
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-03-sftp-operations.md +1379 -1379
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-04-file-patterns.md +941 -941
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-05-advanced-topics.md +813 -813
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-06-integration-patterns.md +486 -486
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-07-troubleshooting.md +387 -387
- package/docs/02-CORE-GUIDES/data-sources/modules/data-sources-08-api-reference.md +417 -417
- package/docs/02-CORE-GUIDES/data-sources/readme.md +77 -77
- package/docs/02-CORE-GUIDES/error-handling-guide.md +936 -936
- package/docs/02-CORE-GUIDES/extraction/examples/02-core-guides-extraction-readme.md +116 -116
- package/docs/02-CORE-GUIDES/extraction/examples/common-patterns.ts +428 -428
- package/docs/02-CORE-GUIDES/extraction/examples/extract-inventory-basic.ts +187 -187
- package/docs/02-CORE-GUIDES/extraction/extraction-quick-reference.md +596 -596
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-01-foundations.md +514 -514
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-02-basic-extraction.md +823 -823
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-03-parquet-processing.md +507 -507
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-04-data-enrichment.md +546 -546
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-05-transformation.md +494 -494
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-06-export-formats.md +458 -458
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-06-performance.md +138 -138
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-07-api-reference.md +148 -148
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-07-optimization.md +692 -692
- package/docs/02-CORE-GUIDES/extraction/modules/02-core-guides-extraction-08-extraction-orchestrator.md +1008 -1008
- package/docs/02-CORE-GUIDES/extraction/readme.md +151 -151
- package/docs/02-CORE-GUIDES/ingestion/examples/_simple-kv-store.ts +40 -40
- package/docs/02-CORE-GUIDES/ingestion/examples/error-recovery.ts +728 -728
- package/docs/02-CORE-GUIDES/ingestion/examples/event-driven.ts +501 -501
- package/docs/02-CORE-GUIDES/ingestion/examples/local-file-ingestion.ts +88 -88
- package/docs/02-CORE-GUIDES/ingestion/examples/parquet-ingestion.ts +117 -117
- package/docs/02-CORE-GUIDES/ingestion/examples/performance-optimized.ts +647 -647
- package/docs/02-CORE-GUIDES/ingestion/examples/s3-csv-ingestion.ts +169 -169
- package/docs/02-CORE-GUIDES/ingestion/examples/sftp-csv-ingestion.ts +134 -134
- package/docs/02-CORE-GUIDES/ingestion/ingestion-quick-reference.md +546 -546
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-01-introduction.md +626 -626
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-02-quick-start.md +658 -658
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-03-data-sources.md +1052 -1052
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-04-field-mapping.md +763 -763
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-05-advanced-parsers.md +676 -676
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-06-batch-api.md +1295 -1295
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-07-api-reference.md +138 -138
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-07-state-management.md +1037 -1037
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-08-performance-optimization.md +1349 -1349
- package/docs/02-CORE-GUIDES/ingestion/modules/02-core-guides-ingestion-09-best-practices.md +1893 -1893
- package/docs/02-CORE-GUIDES/ingestion/readme.md +160 -160
- package/docs/02-CORE-GUIDES/logging-guide.md +585 -585
- package/docs/02-CORE-GUIDES/mapping/error-handling-patterns.md +401 -401
- package/docs/02-CORE-GUIDES/mapping/examples/02-core-guides-mapping-readme.md +128 -128
- package/docs/02-CORE-GUIDES/mapping/examples/common-patterns.ts +273 -273
- package/docs/02-CORE-GUIDES/mapping/examples/csv-location-ingestion.json +36 -36
- package/docs/02-CORE-GUIDES/mapping/examples/csv-mapping.ts +242 -242
- package/docs/02-CORE-GUIDES/mapping/examples/graphql-to-parquet-extraction.json +36 -36
- package/docs/02-CORE-GUIDES/mapping/examples/json-mapping.ts +213 -213
- package/docs/02-CORE-GUIDES/mapping/examples/json-product-to-mutation.json +48 -48
- package/docs/02-CORE-GUIDES/mapping/examples/xml-mapping.ts +291 -291
- package/docs/02-CORE-GUIDES/mapping/examples/xml-order-to-mutation.json +45 -45
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/graphql-mutation-mapping-quick-reference.md +463 -463
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/graphql-mutation-mapping-readme.md +227 -227
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-01-introduction.md +222 -222
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-02-quick-start.md +351 -351
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-03-schema-validation.md +569 -569
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-04-mapping-patterns.md +471 -471
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-05-configuration-reference.md +611 -611
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-06-advanced-xpath.md +148 -148
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-06-path-syntax.md +464 -464
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-07-api-reference.md +94 -94
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-07-array-handling.md +307 -307
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-08-custom-resolvers.md +544 -544
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-09-advanced-patterns.md +427 -427
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-10-hooks-and-variables.md +336 -336
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-11-error-handling.md +488 -488
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-12-arguments-vs-nodes.md +383 -383
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/modules/graphql-mutation-mapping-13-best-practices.md +477 -477
- package/docs/02-CORE-GUIDES/mapping/graphql-mutation-mapping/readme.md +62 -62
- package/docs/02-CORE-GUIDES/mapping/mapping-format-decision-tree.md +480 -480
- package/docs/02-CORE-GUIDES/mapping/mapping-graphql-alias-batching-guide.md +820 -820
- package/docs/02-CORE-GUIDES/mapping/mapping-javascript-objects.md +2369 -2369
- package/docs/02-CORE-GUIDES/mapping/mapping-mapper-comparison-guide.md +682 -682
- package/docs/02-CORE-GUIDES/mapping/modules/02-core-guides-mapping-07-api-reference.md +1327 -1327
- package/docs/02-CORE-GUIDES/mapping/modules/02-core-guides-mapping-08-error-handling.md +1142 -1142
- package/docs/02-CORE-GUIDES/mapping/modules/mapping-04-use-cases.md +891 -891
- package/docs/02-CORE-GUIDES/mapping/modules/mapping-06-helpers-resolvers.md +1126 -1126
- package/docs/02-CORE-GUIDES/mapping/modules/mapping-06-sdk-resolvers.md +199 -199
- package/docs/02-CORE-GUIDES/mapping/modules/mapping-07-api-reference.md +1319 -1319
- package/docs/02-CORE-GUIDES/mapping/readme.md +178 -178
- package/docs/02-CORE-GUIDES/mapping/resolver-registration.md +410 -410
- package/docs/02-CORE-GUIDES/mapping/resolvers/examples/common-patterns.ts +226 -226
- package/docs/02-CORE-GUIDES/mapping/resolvers/examples/custom-resolvers.ts +227 -227
- package/docs/02-CORE-GUIDES/mapping/resolvers/examples/sdk-resolvers-usage.ts +203 -203
- package/docs/02-CORE-GUIDES/mapping/resolvers/mapping-resolvers-readme.md +274 -274
- package/docs/02-CORE-GUIDES/mapping/resolvers/mapping-resolvers-resolver-api-reference.md +679 -679
- package/docs/02-CORE-GUIDES/mapping/resolvers/mapping-resolvers-resolver-cookbook.md +826 -826
- package/docs/02-CORE-GUIDES/mapping/resolvers/mapping-resolvers-resolver-guide.md +1330 -1330
- package/docs/02-CORE-GUIDES/mapping/resolvers/mapping-resolvers-resolver-helpers-reference.md +1437 -1437
- package/docs/02-CORE-GUIDES/mapping/resolvers/mapping-resolvers-resolver-parameters-reference.md +553 -553
- package/docs/02-CORE-GUIDES/mapping/resolvers/mapping-resolvers-resolver-troubleshooting.md +854 -854
- package/docs/02-CORE-GUIDES/mapping/resolvers/readme.md +75 -75
- package/docs/02-CORE-GUIDES/parsers/examples/02-core-guides-parsers-readme.md +161 -161
- package/docs/02-CORE-GUIDES/parsers/examples/csv-parser-examples.ts +110 -110
- package/docs/02-CORE-GUIDES/parsers/examples/json-parser-examples.ts +33 -33
- package/docs/02-CORE-GUIDES/parsers/examples/parquet-parser-examples.ts +47 -47
- package/docs/02-CORE-GUIDES/parsers/examples/xml-parser-examples.ts +38 -38
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-01-foundations.md +355 -355
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-02-csv-parser.md +772 -772
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-03-json-parser.md +789 -789
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-04-xml-parser.md +857 -857
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-05-parquet-parser.md +603 -603
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-06-integration-patterns.md +702 -702
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-06-streaming.md +121 -121
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-07-api-reference.md +89 -89
- package/docs/02-CORE-GUIDES/parsers/modules/02-core-guides-parsers-07-troubleshooting.md +727 -727
- package/docs/02-CORE-GUIDES/parsers/parsers-quick-reference.md +482 -482
- package/docs/02-CORE-GUIDES/parsers/parsers-readme.md +258 -258
- package/docs/02-CORE-GUIDES/parsers/readme.md +65 -65
- package/docs/02-CORE-GUIDES/readme.md +194 -194
- package/docs/02-CORE-GUIDES/webhook-validation/examples/basic-validation.ts +108 -108
- package/docs/02-CORE-GUIDES/webhook-validation/examples/common-patterns.ts +316 -316
- package/docs/02-CORE-GUIDES/webhook-validation/examples/webhook-validation-readme.md +61 -61
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-01-foundations.md +440 -440
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-02-quick-start.md +525 -525
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-03-versori-integration.md +741 -741
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-04-platform-integration.md +629 -629
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-05-configuration.md +535 -535
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-06-error-handling.md +611 -611
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-06-troubleshooting.md +124 -124
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-07-api-reference.md +511 -511
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-08-rubix-webhooks.md +590 -590
- package/docs/02-CORE-GUIDES/webhook-validation/modules/webhook-validation-09-rubix-event-vs-http-call.md +432 -432
- package/docs/02-CORE-GUIDES/webhook-validation/readme.md +239 -239
- package/docs/02-CORE-GUIDES/webhook-validation/webhook-validation-quick-reference.md +392 -392
- package/docs/03-PATTERN-GUIDES/connector-scenarios/connector-scenarios-quick-reference.md +498 -498
- package/docs/03-PATTERN-GUIDES/connector-scenarios/connector-scenarios-readme.md +313 -313
- package/docs/03-PATTERN-GUIDES/connector-scenarios/examples/common-patterns.ts +612 -612
- package/docs/03-PATTERN-GUIDES/connector-scenarios/examples/connector-scenarios-readme.md +253 -253
- package/docs/03-PATTERN-GUIDES/connector-scenarios/modules/connector-scenarios-01-foundations.md +452 -452
- package/docs/03-PATTERN-GUIDES/connector-scenarios/modules/connector-scenarios-02-simple-scenarios.md +681 -681
- package/docs/03-PATTERN-GUIDES/connector-scenarios/modules/connector-scenarios-03-intermediate-scenarios.md +637 -637
- package/docs/03-PATTERN-GUIDES/connector-scenarios/modules/connector-scenarios-04-advanced-scenarios.md +650 -650
- package/docs/03-PATTERN-GUIDES/connector-scenarios/modules/connector-scenarios-05-bidirectional-sync.md +233 -233
- package/docs/03-PATTERN-GUIDES/connector-scenarios/modules/connector-scenarios-06-production-patterns.md +442 -442
- package/docs/03-PATTERN-GUIDES/connector-scenarios/modules/connector-scenarios-07-reference.md +445 -445
- package/docs/03-PATTERN-GUIDES/connector-scenarios/readme.md +31 -31
- package/docs/03-PATTERN-GUIDES/enterprise-integration-patterns.md +1528 -1528
- package/docs/03-PATTERN-GUIDES/error-handling/comprehensive-error-handling-guide.md +1437 -1437
- package/docs/03-PATTERN-GUIDES/error-handling/error-handling-quick-reference.md +390 -390
- package/docs/03-PATTERN-GUIDES/error-handling/examples/common-patterns.ts +438 -438
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-01-foundations.md +362 -362
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-02-error-types.md +850 -850
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-03-utf8-handling.md +456 -456
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-04-error-scenarios.md +658 -658
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-05-calling-patterns.md +671 -671
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-06-retry-strategies.md +1034 -1034
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-07-monitoring.md +653 -653
- package/docs/03-PATTERN-GUIDES/error-handling/modules/error-handling-08-api-reference.md +847 -847
- package/docs/03-PATTERN-GUIDES/error-handling/readme.md +36 -36
- package/docs/03-PATTERN-GUIDES/examples/__tests__/readme.md +40 -40
- package/docs/03-PATTERN-GUIDES/examples/__tests__/resolver-examples.test.js +282 -282
- package/docs/03-PATTERN-GUIDES/examples/test-data/03-pattern-guides-readme.md +110 -110
- package/docs/03-PATTERN-GUIDES/examples/test-data/canonical-inventory.json +123 -123
- package/docs/03-PATTERN-GUIDES/examples/test-data/canonical-order.json +171 -171
- package/docs/03-PATTERN-GUIDES/examples/test-data/readme.md +28 -28
- package/docs/03-PATTERN-GUIDES/extraction/extraction-readme.md +15 -15
- package/docs/03-PATTERN-GUIDES/extraction/readme.md +25 -25
- package/docs/03-PATTERN-GUIDES/file-operations/examples/common-patterns.ts +407 -407
- package/docs/03-PATTERN-GUIDES/file-operations/examples/file-operations-readme.md +142 -142
- package/docs/03-PATTERN-GUIDES/file-operations/file-operations-quick-reference.md +462 -462
- package/docs/03-PATTERN-GUIDES/file-operations/file-operations-readme.md +379 -379
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-01-foundations.md +430 -430
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-02-quick-start.md +484 -484
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-03-s3-operations.md +507 -507
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-04-sftp-operations.md +963 -963
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-05-streaming-performance.md +503 -503
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-06-archive-patterns.md +386 -386
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-06-error-handling.md +117 -117
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-07-api-reference.md +78 -78
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-07-testing-troubleshooting.md +567 -567
- package/docs/03-PATTERN-GUIDES/file-operations/modules/file-operations-08-api-reference.md +1055 -1055
- package/docs/03-PATTERN-GUIDES/file-operations/readme.md +32 -32
- package/docs/03-PATTERN-GUIDES/ingestion/ingestion-readme.md +15 -15
- package/docs/03-PATTERN-GUIDES/ingestion/readme.md +25 -25
- package/docs/03-PATTERN-GUIDES/integration-patterns/examples/batch-processing.ts +130 -130
- package/docs/03-PATTERN-GUIDES/integration-patterns/examples/common-patterns.ts +360 -360
- package/docs/03-PATTERN-GUIDES/integration-patterns/examples/delta-sync.ts +130 -130
- package/docs/03-PATTERN-GUIDES/integration-patterns/examples/integration-patterns-readme.md +100 -100
- package/docs/03-PATTERN-GUIDES/integration-patterns/examples/real-time-webhook.ts +398 -398
- package/docs/03-PATTERN-GUIDES/integration-patterns/integration-patterns-quick-reference.md +962 -962
- package/docs/03-PATTERN-GUIDES/integration-patterns/integration-patterns-readme.md +134 -134
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-01-real-time-processing.md +991 -991
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-02-batch-processing.md +1547 -1547
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-03-delta-sync.md +1108 -1108
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-04-webhook-patterns.md +1181 -1181
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-05-error-handling.md +1061 -1061
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-06-advanced-integration-services.md +1547 -1547
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-06-performance.md +109 -109
- package/docs/03-PATTERN-GUIDES/integration-patterns/modules/integration-patterns-07-api-reference.md +34 -34
- package/docs/03-PATTERN-GUIDES/integration-patterns/readme.md +30 -30
- package/docs/03-PATTERN-GUIDES/logging-minimal-mode.md +128 -128
- package/docs/03-PATTERN-GUIDES/multiple-connections/examples/common-patterns.ts +380 -380
- package/docs/03-PATTERN-GUIDES/multiple-connections/examples/multiple-connections-readme.md +139 -139
- package/docs/03-PATTERN-GUIDES/multiple-connections/examples/parallel-root-connections.ts +149 -149
- package/docs/03-PATTERN-GUIDES/multiple-connections/examples/real-world-scenarios.ts +405 -405
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-01-foundations.md +378 -378
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-02-quick-start.md +566 -566
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-03-targeting-connections.md +659 -659
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-04-parallel-queries.md +656 -656
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-05-best-practices.md +624 -624
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-06-api-reference.md +824 -824
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-06-versori.md +119 -119
- package/docs/03-PATTERN-GUIDES/multiple-connections/modules/multiple-connections-07-api-reference.md +87 -87
- package/docs/03-PATTERN-GUIDES/multiple-connections/multiple-connections-quick-reference.md +353 -353
- package/docs/03-PATTERN-GUIDES/multiple-connections/multiple-connections-readme.md +270 -270
- package/docs/03-PATTERN-GUIDES/multiple-connections/readme.md +30 -30
- package/docs/03-PATTERN-GUIDES/pagination/pagination-readme.md +14 -14
- package/docs/03-PATTERN-GUIDES/pagination/readme.md +24 -24
- package/docs/03-PATTERN-GUIDES/parquet/examples/common-patterns.ts +180 -180
- package/docs/03-PATTERN-GUIDES/parquet/examples/read-parquet.ts +48 -48
- package/docs/03-PATTERN-GUIDES/parquet/examples/write-parquet.ts +65 -65
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-01-introduction.md +393 -393
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-02-quick-start.md +572 -572
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-03-reading-parquet.md +525 -525
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-04-writing-parquet.md +554 -554
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-05-graphql-extraction.md +405 -405
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-06-performance.md +104 -104
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-06-s3-integration.md +511 -511
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-07-api-reference.md +90 -90
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-07-performance-optimization.md +525 -525
- package/docs/03-PATTERN-GUIDES/parquet/modules/03-pattern-guides-parquet-08-best-practices.md +712 -712
- package/docs/03-PATTERN-GUIDES/parquet/parquet-quick-reference.md +683 -683
- package/docs/03-PATTERN-GUIDES/parquet/parquet-readme.md +248 -248
- package/docs/03-PATTERN-GUIDES/parquet/readme.md +32 -32
- package/docs/03-PATTERN-GUIDES/parsers/parsers-readme.md +12 -12
- package/docs/03-PATTERN-GUIDES/parsers/readme.md +24 -24
- package/docs/03-PATTERN-GUIDES/readme.md +159 -159
- package/docs/03-PATTERN-GUIDES/webhooks/readme.md +24 -24
- package/docs/03-PATTERN-GUIDES/webhooks/webhooks-readme.md +8 -8
- package/docs/04-REFERENCE/architecture/architecture-01-overview.md +427 -427
- package/docs/04-REFERENCE/architecture/architecture-02-client-architecture.md +424 -424
- package/docs/04-REFERENCE/architecture/architecture-03-data-flow.md +690 -690
- package/docs/04-REFERENCE/architecture/architecture-04-service-layer.md +834 -834
- package/docs/04-REFERENCE/architecture/architecture-05-integration-architecture.md +655 -655
- package/docs/04-REFERENCE/architecture/architecture-06-state-management.md +653 -653
- package/docs/04-REFERENCE/architecture/architecture-adding-new-data-sources.md +686 -686
- package/docs/04-REFERENCE/architecture/readme.md +279 -279
- package/docs/04-REFERENCE/platforms/deno/readme.md +117 -117
- package/docs/04-REFERENCE/platforms/nodejs/readme.md +146 -146
- package/docs/04-REFERENCE/platforms/readme.md +135 -135
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-01-introduction.md +398 -398
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-02-quick-start.md +560 -560
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-03-authentication.md +757 -757
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-04-workflows.md +2476 -2476
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-05-connections.md +1167 -1167
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-06-kv-storage.md +990 -990
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-06-state-management.md +121 -121
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-07-api-reference.md +68 -68
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-07-deployment.md +731 -731
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-08-best-practices.md +1111 -1111
- package/docs/04-REFERENCE/platforms/versori/modules/platforms-versori-09-signature-reference.md +766 -766
- package/docs/04-REFERENCE/platforms/versori/platforms-versori-readme.md +299 -299
- package/docs/04-REFERENCE/platforms/versori/platforms-versori-s3-sftp-configuration-guide.md +1425 -1425
- package/docs/04-REFERENCE/platforms/versori/platforms-versori-webhook-api-key-security.md +816 -816
- package/docs/04-REFERENCE/platforms/versori/platforms-versori-webhook-connection-security.md +681 -681
- package/docs/04-REFERENCE/platforms/versori/platforms-versori-workflow-task-types.md +708 -708
- package/docs/04-REFERENCE/platforms/versori/readme.md +108 -108
- package/docs/04-REFERENCE/readme.md +148 -148
- package/docs/04-REFERENCE/resolver-signature/examples/advanced-resolvers.ts +482 -482
- package/docs/04-REFERENCE/resolver-signature/examples/async-resolvers.ts +496 -496
- package/docs/04-REFERENCE/resolver-signature/examples/basic-resolvers.ts +343 -343
- package/docs/04-REFERENCE/resolver-signature/examples/resolver-signature-readme.md +188 -188
- package/docs/04-REFERENCE/resolver-signature/examples/testing-resolvers.ts +463 -463
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-01-foundations.md +286 -286
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-02-parameter-reference.md +643 -643
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-03-basic-examples.md +521 -521
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-04-advanced-patterns.md +739 -739
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-05-sdk-resolvers.md +531 -531
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-06-migration-guide.md +650 -650
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-06-testing.md +125 -125
- package/docs/04-REFERENCE/resolver-signature/modules/resolver-signature-07-api-reference.md +794 -794
- package/docs/04-REFERENCE/resolver-signature/readme.md +64 -64
- package/docs/04-REFERENCE/resolver-signature/resolver-signature-quick-reference.md +270 -270
- package/docs/04-REFERENCE/resolver-signature/resolver-signature-readme.md +351 -351
- package/docs/04-REFERENCE/schema/fluent-commerce-schema.json +764 -764
- package/docs/04-REFERENCE/schema/readme.md +141 -141
- package/docs/04-REFERENCE/testing/examples/04-reference-testing-readme.md +158 -158
- package/docs/04-REFERENCE/testing/examples/fluent-testing.ts +62 -62
- package/docs/04-REFERENCE/testing/examples/health-check.ts +155 -155
- package/docs/04-REFERENCE/testing/examples/integration-test.ts +119 -119
- package/docs/04-REFERENCE/testing/examples/performance-test.ts +183 -183
- package/docs/04-REFERENCE/testing/examples/s3-testing.ts +127 -127
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-01-foundations.md +267 -267
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-02-s3-testing.md +599 -599
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-03-fluent-testing.md +589 -589
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-04-integration-testing.md +699 -699
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-05-debugging.md +478 -478
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-06-cicd-integration.md +463 -463
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-06-preflight-validation.md +131 -131
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-07-best-practices.md +499 -499
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-07-coverage-ci.md +165 -165
- package/docs/04-REFERENCE/testing/modules/04-reference-testing-08-api-reference.md +634 -634
- package/docs/04-REFERENCE/testing/readme.md +86 -86
- package/docs/04-REFERENCE/testing/testing-quick-reference.md +667 -667
- package/docs/04-REFERENCE/testing/testing-readme.md +286 -286
- package/docs/04-REFERENCE/troubleshooting/readme.md +144 -144
- package/docs/04-REFERENCE/troubleshooting/troubleshooting-deno-sftp-compatibility.md +392 -392
- package/docs/template-loading-matrix.md +242 -242
- package/package.json +5 -3
- package/docs/02-CORE-GUIDES/api-reference/cli-profile-integration.md +0 -377
|
@@ -1,1785 +1,1785 @@
|
|
|
1
|
-
---
|
|
2
|
-
template_id: tpl-webhook-rubix-fulfilment-export-universal-mapper
|
|
3
|
-
canonical_filename: template-webhook-rubix-fulfilment-to-sftp-xml-universal-mapper.md
|
|
4
|
-
version: 2.0.0
|
|
5
|
-
sdk_version: ^0.1.39
|
|
6
|
-
runtime: versori
|
|
7
|
-
direction: webhook
|
|
8
|
-
source: fluent-rubix-workflow
|
|
9
|
-
destination: sftp-xml
|
|
10
|
-
entity: fulfilment
|
|
11
|
-
format: xml
|
|
12
|
-
logging: versori
|
|
13
|
-
status: stable
|
|
14
|
-
pattern: universal-mapper
|
|
15
|
-
features:
|
|
16
|
-
- webhook-validation
|
|
17
|
-
- fire-and-forget
|
|
18
|
-
- background-processing
|
|
19
|
-
- xml-export
|
|
20
|
-
- sftp-integration
|
|
21
|
-
- graphql-queries
|
|
22
|
-
- universal-mapper
|
|
23
|
-
- external-mapping
|
|
24
|
-
- custom-resolvers
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
# Template: Rubix Fulfilment Webhook → SFTP XML Export (UniversalMapper Pattern)
|
|
28
|
-
|
|
29
|
-
**Template Version:** 2.0.0
|
|
30
|
-
**SDK Version:** `^0.1.39` - `npm install @fluentcommerce/fc-connect-sdk@^0.1.39`
|
|
31
|
-
**Last Updated:** 2025-01-25
|
|
32
|
-
**Deployment Target:** Versori Platform
|
|
33
|
-
**Mapping Pattern:** 🟢 **UNIVERSALMAPPER** (External JSON mapping + Custom resolvers)
|
|
34
|
-
|
|
35
|
-
> **📖 Pattern Selection Guide:**
|
|
36
|
-
> - **Use THIS template (UniversalMapper)** for: Reusable configs, multi-environment deployments, complex transformations, external mapping management
|
|
37
|
-
> - **Use Inline version** for: Simple webhooks, tightly-coupled 3PL schemas, fast debugging
|
|
38
|
-
> - **See also:** [template-webhook-rubix-fulfilment-to-sftp-xml-inline.md](./template-webhook-rubix-fulfilment-to-sftp-xml-inline.md)
|
|
39
|
-
|
|
40
|
-
**🆕 Version 2.0.0 - Production Ready:**
|
|
41
|
-
- ✅ **Fulfilment-specific template** - Focused on 3PL/WMS integration
|
|
42
|
-
- ✅ **Production-ready modular structure** - Separate workflows, services, config, resolvers, types
|
|
43
|
-
- ✅ **GraphQL fulfilment queries** - Fetch fulfilment + line items + order details
|
|
44
|
-
- ✅ **Automatic pagination** - Handles fulfilments with 100+ items (up to 1000)
|
|
45
|
-
- ✅ **External JSON mapping** - `config/fulfilment-xml-mapping.json` for XML structure
|
|
46
|
-
- ✅ **UniversalMapper** - Transforms GraphQL data to XML structure with custom resolvers
|
|
47
|
-
- ✅ **Custom resolvers** - Handle complex transformations (date formatting, nested data)
|
|
48
|
-
- ✅ **XML generation** - Safe XML with automatic escaping via XMLBuilder
|
|
49
|
-
- ✅ **SFTP upload** - Connection pooling with proper dispose()
|
|
50
|
-
- ✅ **Critical fixes applied** - retailerId validation, SFTP options parameter, pagination
|
|
51
|
-
- ✅ **Comprehensive documentation** - Testing, troubleshooting, monitoring
|
|
52
|
-
|
|
53
|
-
**When to Use This Pattern:**
|
|
54
|
-
- ✅ Complex XML structures (>20 fields)
|
|
55
|
-
- ✅ XML structure changes frequently
|
|
56
|
-
- ✅ Need environment-specific configurations
|
|
57
|
-
- ✅ Multi-environment deployments (dev/staging/prod)
|
|
58
|
-
- ✅ Reusable mapping configurations
|
|
59
|
-
- ✅ Complex transformations requiring custom resolvers
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
## Overview
|
|
64
|
-
|
|
65
|
-
Receive fulfilment webhooks from Rubix workflows, query fulfilment details, transform with UniversalMapper, generate XML, and upload to 3PL/WMS SFTP server.
|
|
66
|
-
|
|
67
|
-
**Pattern:**
|
|
68
|
-
1. Validate webhook signature (~10-50ms)
|
|
69
|
-
2. Return HTTP 200 OK immediately (fast acknowledgment)
|
|
70
|
-
3. Background: Query fulfilment details → UniversalMapper transformation → Generate XML → Upload to SFTP (~2-5s)
|
|
71
|
-
|
|
72
|
-
**Business Use Case:**
|
|
73
|
-
- Rubix workflow sends webhook when fulfilment is created/updated
|
|
74
|
-
- Handler queries fulfilment details (items, order, addresses)
|
|
75
|
-
- UniversalMapper transforms GraphQL data using external JSON mapping
|
|
76
|
-
- Custom resolvers handle complex transformations (dates, addresses, names)
|
|
77
|
-
- Generates XML fulfillment notification for 3PL/WMS
|
|
78
|
-
- Uploads to partner SFTP server for warehouse processing
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## STEP 1: Understand This Template
|
|
83
|
-
|
|
84
|
-
### What This Template Does
|
|
85
|
-
|
|
86
|
-
**Core Functionality:**
|
|
87
|
-
- Receives FULFILMENT webhooks from Fluent Commerce Rubix workflows
|
|
88
|
-
- Validates webhook signature for security
|
|
89
|
-
- Returns fast HTTP 200 OK response (<100ms)
|
|
90
|
-
- Background: Queries fulfilment via GraphQL → UniversalMapper transformation → XML generation → Uploads to SFTP
|
|
91
|
-
|
|
92
|
-
**Key SDK Components:**
|
|
93
|
-
- `WebhookValidationService` - Signature validation with RSA/HMAC support
|
|
94
|
-
- `createClient()` - Universal client factory (auto-detects Versori context)
|
|
95
|
-
- `client.graphql()` - Query fulfilment details with automatic pagination
|
|
96
|
-
- `UniversalMapper` - Transform GraphQL data to XML structure using external JSON mapping
|
|
97
|
-
- `XMLBuilder` - Safe XML generation with automatic escaping (after UniversalMapper)
|
|
98
|
-
- `SftpDataSource` - SFTP operations with connection pooling
|
|
99
|
-
- `ctx.credentials().getAccessToken()` - Retrieve SFTP credentials from Versori connection vault
|
|
100
|
-
- Native Versori `log` - Structured logging from context
|
|
101
|
-
|
|
102
|
-
**Pagination Support:**
|
|
103
|
-
- Automatically handles fulfilments with 100+ line items
|
|
104
|
-
- Uses two-query pattern: fulfilment details + paginated items
|
|
105
|
-
- SDK auto-pagination: `pagination: { maxPages: 10 }` supports up to 1000 items
|
|
106
|
-
- Logs pagination usage for monitoring
|
|
107
|
-
|
|
108
|
-
**Critical Patterns:**
|
|
109
|
-
- **Sync + Fire-and-Forget**: Fast validation, background processing
|
|
110
|
-
- **Signature Validation**: Always validate `fluent-signature` or `flex.signature` headers
|
|
111
|
-
- **Background Promises**: Use `.then().catch()` for error handling
|
|
112
|
-
- **SFTP Credentials**: Retrieve from Versori connection vault (not activation variables)
|
|
113
|
-
- **SFTP Cleanup**: Always call `dispose()` in finally blocks
|
|
114
|
-
- **RetailerId Validation**: Check before `setRetailerId()` to prevent 401 errors
|
|
115
|
-
- **External Mapping**: XML structure defined in JSON config file (not inline)
|
|
116
|
-
- **Custom Resolvers**: Complex transformations separated into resolver functions
|
|
117
|
-
|
|
118
|
-
### When to Use This Template
|
|
119
|
-
|
|
120
|
-
✅ **USE THIS TEMPLATE FOR:**
|
|
121
|
-
- Fulfilment created/updated webhooks from Rubix workflows
|
|
122
|
-
- Export fulfilment details to 3PL/WMS via SFTP
|
|
123
|
-
- Need XML format for warehouse management systems
|
|
124
|
-
- Require signature validation for security
|
|
125
|
-
- Need fast webhook acknowledgment + async processing
|
|
126
|
-
- **Complex XML structures** requiring external configuration
|
|
127
|
-
- **Multi-environment deployments** with different XML schemas
|
|
128
|
-
- **Frequent XML structure changes** without code modifications
|
|
129
|
-
|
|
130
|
-
❌ **DON'T USE FOR:**
|
|
131
|
-
- Order webhooks (use order attribute update template)
|
|
132
|
-
- Inventory webhooks (use inventory templates)
|
|
133
|
-
- CSV/JSON exports (use format-specific templates)
|
|
134
|
-
- Synchronous processing required (use standard http workflow)
|
|
135
|
-
- **Simple XML structures** (<20 fields) - use inline mapping template instead
|
|
136
|
-
|
|
137
|
-
### Business Use Cases
|
|
138
|
-
|
|
139
|
-
**Use Case: 3PL Warehouse Fulfillment Notification**
|
|
140
|
-
- Rubix workflow sends webhook when fulfilment moves to "ALLOCATED" status
|
|
141
|
-
- Handler queries fulfilment details (items, quantities, order info)
|
|
142
|
-
- UniversalMapper transforms data using external JSON mapping config
|
|
143
|
-
- Custom resolvers format dates, addresses, and customer names
|
|
144
|
-
- Generates XML fulfillment order for warehouse system
|
|
145
|
-
- Uploads to 3PL SFTP server for pick/pack/ship processing
|
|
146
|
-
- 3PL system imports XML and creates warehouse tasks
|
|
147
|
-
|
|
148
|
-
**Why UniversalMapper Pattern:**
|
|
149
|
-
- XML structure can be updated without code changes (edit JSON config)
|
|
150
|
-
- Different XML schemas per environment (dev/staging/prod configs)
|
|
151
|
-
- Complex transformations handled by reusable custom resolvers
|
|
152
|
-
- Mapping configuration can be versioned and tested independently
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
## STEP 2: Implementation Prompt for Claude Code
|
|
157
|
-
|
|
158
|
-
**Copy this prompt and send to Claude Code to generate the complete implementation:**
|
|
159
|
-
|
|
160
|
-
```
|
|
161
|
-
Create a Versori webhook handler for Fluent Commerce Rubix FULFILMENT events with signature validation, GraphQL queries, UniversalMapper transformation, XML generation, and SFTP upload.
|
|
162
|
-
|
|
163
|
-
REQUIREMENTS:
|
|
164
|
-
1. Runtime: Versori Platform (HTTP webhook)
|
|
165
|
-
2. Source: Rubix SendWebhook action (FULFILMENT entity type only)
|
|
166
|
-
3. Destination: SFTP XML export to 3PL/WMS partner
|
|
167
|
-
4. Format: XML with fulfilment details, line items, order info
|
|
168
|
-
5. Entity: FULFILMENT
|
|
169
|
-
|
|
170
|
-
KEY FEATURES:
|
|
171
|
-
- Webhook signature validation using WebhookValidationService
|
|
172
|
-
- Sync mode + fire-and-forget pattern for fast response
|
|
173
|
-
- Background processing: GraphQL query → UniversalMapper transformation → XML generation → SFTP upload
|
|
174
|
-
- **Automatic pagination** - Handles fulfilments with 100+ items (up to 1000 items)
|
|
175
|
-
- Two-query pattern: Fulfilment details + paginated items query
|
|
176
|
-
- **External JSON mapping** - `config/fulfilment-xml-mapping.json` for XML structure
|
|
177
|
-
- **UniversalMapper** - Transforms GraphQL data to XML structure with custom resolvers
|
|
178
|
-
- **Custom resolvers** - Handle complex transformations (date formatting, nested data)
|
|
179
|
-
- Modular architecture (workflows/, services/, config/, resolvers/, types/)
|
|
180
|
-
- Native Versori logging (no LoggingService)
|
|
181
|
-
- SFTP cleanup with dispose() in finally blocks
|
|
182
|
-
- Comprehensive error handling with SDK error types
|
|
183
|
-
- RetailerId validation before setRetailerId()
|
|
184
|
-
|
|
185
|
-
CRITICAL REQUIREMENTS:
|
|
186
|
-
1. Webhook Mode: response: { mode: 'sync' }
|
|
187
|
-
2. Signature Validation: WebhookValidationService with strictValidation: true
|
|
188
|
-
3. RetailerId Validation: Check exists before client.setRetailerId()
|
|
189
|
-
4. Background Processing: Fire-and-forget pattern (no await on background promise)
|
|
190
|
-
5. GraphQL Queries: Two separate queries (fulfilment + items with pagination)
|
|
191
|
-
6. Pagination: Use SDK automatic pagination with maxPages: 10, first: 100
|
|
192
|
-
7. **External Mapping**: Use `config/fulfilment-xml-mapping.json` (NOT inline mapping)
|
|
193
|
-
8. **UniversalMapper**: Transform GraphQL data to XML structure using mapping config
|
|
194
|
-
9. **Custom Resolvers**: Use resolvers/fulfilment-resolvers.ts for complex transformations
|
|
195
|
-
10. XML Generation: Use XMLBuilder with automatic escaping (after UniversalMapper)
|
|
196
|
-
11. SFTP Upload: Include options parameter { overwrite: true, createDirectories: true }
|
|
197
|
-
12. SFTP Cleanup: Always dispose() in finally block
|
|
198
|
-
13. Error Handling: Import and handle DataSourceError, AuthenticationError, GraphQLError
|
|
199
|
-
14. Type Safety: Use Logger, VersoriContext types (not any)
|
|
200
|
-
|
|
201
|
-
SDK METHODS TO USE:
|
|
202
|
-
- import { Buffer } from 'node:buffer' (CRITICAL for Versori/Deno)
|
|
203
|
-
- createClient({ ...ctx, log })
|
|
204
|
-
- await client.setRetailerId(retailerId) (with validation first!)
|
|
205
|
-
- new WebhookValidationService({ strictValidation: true }, log)
|
|
206
|
-
- await validator.validateWebhook(rawBody, headers, publicKey)
|
|
207
|
-
- await client.graphql({ query, variables, pagination: { maxPages: 10 } })
|
|
208
|
-
- import mappingConfig from '../config/fulfilment-xml-mapping.json' with { type: 'json' }
|
|
209
|
-
- new UniversalMapper(mappingConfig, { customResolvers })
|
|
210
|
-
- await mapper.map(fulfilmentData) - Transform GraphQL data to XML structure
|
|
211
|
-
- new XMLBuilder({ prettyPrint: true, xmlDeclaration: true, encoding: 'UTF-8' })
|
|
212
|
-
- xmlBuilder.build(mappedData, 'FulfilmentExport')
|
|
213
|
-
- await ctx.credentials().getAccessToken('sftp_export_server') - Retrieve SFTP credentials from connection vault
|
|
214
|
-
- Buffer.from(accessToken, 'base64').toString('utf-8') - Decode Basic Auth credentials
|
|
215
|
-
- new SftpDataSource(config, log) - config includes connectionId: 'sftp_export_server'
|
|
216
|
-
- await sftp.uploadFile(remotePath, buffer, { overwrite: true, createDirectories: true })
|
|
217
|
-
- await sftp.dispose() (CRITICAL in finally block)
|
|
218
|
-
|
|
219
|
-
FORBIDDEN PATTERNS:
|
|
220
|
-
- ❌ LoggingService (use native log from context)
|
|
221
|
-
- ❌ await on background processing (use fire-and-forget)
|
|
222
|
-
- ❌ Inline mapping config (use external JSON file)
|
|
223
|
-
- ❌ Manual object construction for XML (use UniversalMapper)
|
|
224
|
-
- ❌ Missing dispose() for SFTP
|
|
225
|
-
- ❌ Missing options parameter in uploadFile()
|
|
226
|
-
- ❌ Missing retailerId validation before setRetailerId()
|
|
227
|
-
- ❌ Storing SFTP credentials in activation variables (use Versori connection vault)
|
|
228
|
-
- ❌ Using 'any' type (use Logger, VersoriContext from SDK)
|
|
229
|
-
- ❌ Direct FluentClient instantiation (use createClient factory)
|
|
230
|
-
- ❌ Generic error handling (use SDK error types)
|
|
231
|
-
|
|
232
|
-
GRAPHQL QUERY STRUCTURE:
|
|
233
|
-
|
|
234
|
-
**Single Query with Nested Items (Schema-Validated)**
|
|
235
|
-
```graphql
|
|
236
|
-
query GetFulfilment($id: ID!, $first: Int!, $after: String) {
|
|
237
|
-
fulfilment(id: $id) {
|
|
238
|
-
id
|
|
239
|
-
ref
|
|
240
|
-
status
|
|
241
|
-
deliveryType
|
|
242
|
-
order {
|
|
243
|
-
id
|
|
244
|
-
ref
|
|
245
|
-
customer { firstName, lastName, email }
|
|
246
|
-
}
|
|
247
|
-
toAddress {
|
|
248
|
-
name, street, street2, city, state, postcode, country
|
|
249
|
-
}
|
|
250
|
-
fromAddress {
|
|
251
|
-
name, street, street2, city, state, postcode, country
|
|
252
|
-
}
|
|
253
|
-
items(first: $first, after: $after) {
|
|
254
|
-
edges {
|
|
255
|
-
node {
|
|
256
|
-
id
|
|
257
|
-
ref
|
|
258
|
-
requestedQuantity
|
|
259
|
-
filledQuantity
|
|
260
|
-
rejectedQuantity
|
|
261
|
-
orderItem {
|
|
262
|
-
id
|
|
263
|
-
ref
|
|
264
|
-
productRef
|
|
265
|
-
product { name }
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
cursor
|
|
269
|
-
}
|
|
270
|
-
pageInfo {
|
|
271
|
-
hasNextPage
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
createdOn
|
|
275
|
-
updatedOn
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
**Why Single Query?**
|
|
281
|
-
- Items are nested under the fulfilment type in Fluent Commerce schema
|
|
282
|
-
- Single query with `connectionPath: 'fulfilment.items'` for SDK pagination
|
|
283
|
-
- SDK automatically handles pagination with `pagination: { maxPages: 10 }` config
|
|
284
|
-
- More efficient than two separate queries (reduces GraphQL roundtrips)
|
|
285
|
-
|
|
286
|
-
XML OUTPUT STRUCTURE:
|
|
287
|
-
<FulfilmentExport>
|
|
288
|
-
<Fulfilment ref="FF-001" status="ALLOCATED">
|
|
289
|
-
<OrderRef>ORD-123</OrderRef>
|
|
290
|
-
<DeliveryType>STANDARD</DeliveryType>
|
|
291
|
-
<Customer>
|
|
292
|
-
<FirstName>John</FirstName>
|
|
293
|
-
<LastName>Smith</LastName>
|
|
294
|
-
<Email>john@example.com</Email>
|
|
295
|
-
</Customer>
|
|
296
|
-
<ToAddress>
|
|
297
|
-
<Name>John Smith</Name>
|
|
298
|
-
<Street>123 Main St</Street>
|
|
299
|
-
<City>New York</City>
|
|
300
|
-
<State>NY</State>
|
|
301
|
-
<Postcode>10001</Postcode>
|
|
302
|
-
<Country>US</Country>
|
|
303
|
-
</ToAddress>
|
|
304
|
-
<FromAddress>
|
|
305
|
-
<Name>Warehouse</Name>
|
|
306
|
-
<Street>456 Warehouse St</Street>
|
|
307
|
-
<City>Chicago</City>
|
|
308
|
-
<State>IL</State>
|
|
309
|
-
<Postcode>60601</Postcode>
|
|
310
|
-
<Country>US</Country>
|
|
311
|
-
</FromAddress>
|
|
312
|
-
<Items>
|
|
313
|
-
<Item ref="FFI-001">
|
|
314
|
-
<ProductRef>SKU-001</ProductRef>
|
|
315
|
-
<ProductName>Widget</ProductName>
|
|
316
|
-
<RequestedQuantity>2</RequestedQuantity>
|
|
317
|
-
<FilledQuantity>2</FilledQuantity>
|
|
318
|
-
<RejectedQuantity>0</RejectedQuantity>
|
|
319
|
-
</Item>
|
|
320
|
-
</Items>
|
|
321
|
-
<CreatedOn>2025-01-25T10:00:00Z</CreatedOn>
|
|
322
|
-
<UpdatedOn>2025-01-25T11:00:00Z</UpdatedOn>
|
|
323
|
-
</Fulfilment>
|
|
324
|
-
</FulfilmentExport>
|
|
325
|
-
|
|
326
|
-
GENERATE:
|
|
327
|
-
1. package.json with dependencies
|
|
328
|
-
2. index.ts (entry point - exports workflow)
|
|
329
|
-
3. src/workflows/webhook/fulfilment-export-handler.ts (webhook entry)
|
|
330
|
-
4. src/services/fulfilment-query.service.ts (GraphQL queries)
|
|
331
|
-
5. src/services/xml-export.service.ts (UniversalMapper + XMLBuilder + SFTP upload)
|
|
332
|
-
6. src/resolvers/fulfilment-resolvers.ts (Custom resolvers for XML transformations)
|
|
333
|
-
7. src/config/fulfilment-xml-mapping.json (External JSON mapping configuration)
|
|
334
|
-
8. src/types/fulfilment.types.ts (TypeScript interfaces)
|
|
335
|
-
9. readme.md with setup instructions
|
|
336
|
-
|
|
337
|
-
Ensure all code is production-ready with proper error handling, signature validation, SFTP cleanup, UniversalMapper transformation, external JSON mapping, custom resolvers, and type safety.
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
---
|
|
341
|
-
|
|
342
|
-
## STEP 3: Detailed Flow Documentation
|
|
343
|
-
|
|
344
|
-
### Complete Processing Flow
|
|
345
|
-
|
|
346
|
-
```
|
|
347
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
348
|
-
│ 1. RUBIX WEBHOOK RECEIVED │
|
|
349
|
-
│ POST https://{workspace}.versori.run/rubix-fulfilment │
|
|
350
|
-
│ Headers: fluent-signature │
|
|
351
|
-
│ Body: { entityRef: "FF-001", entityType: "FULFILMENT" } │
|
|
352
|
-
└────────────────────┬────────────────────────────────────────┘
|
|
353
|
-
│
|
|
354
|
-
▼
|
|
355
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
356
|
-
│ 2. SIGNATURE VALIDATION (Synchronous, ~10-50ms) │
|
|
357
|
-
│ - Extract rawBody and headers │
|
|
358
|
-
│ - Get fluentPublicKey from activation │
|
|
359
|
-
│ - WebhookValidationService.validateWebhook() │
|
|
360
|
-
│ - Return 400 if invalid │
|
|
361
|
-
└────────────────────┬────────────────────────────────────────┘
|
|
362
|
-
│
|
|
363
|
-
▼
|
|
364
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
365
|
-
│ 3. PAYLOAD VALIDATION (Synchronous, ~5ms) │
|
|
366
|
-
│ - Check entityRef exists │
|
|
367
|
-
│ - Check entityType === 'FULFILMENT' │
|
|
368
|
-
│ - Check retailerId exists │
|
|
369
|
-
│ - Return 400 if missing required fields │
|
|
370
|
-
└────────────────────┬────────────────────────────────────────┘
|
|
371
|
-
│
|
|
372
|
-
▼
|
|
373
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
374
|
-
│ 4. HTTP 200 OK RESPONSE (Total: ~50ms) │
|
|
375
|
-
│ - Return success immediately │
|
|
376
|
-
│ - Background promise continues (fire-and-forget) │
|
|
377
|
-
└────────────────────┬────────────────────────────────────────┘
|
|
378
|
-
│
|
|
379
|
-
▼ (Background - doesn't block response)
|
|
380
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
381
|
-
│ 5. BACKGROUND PROCESSING (~2-5 seconds) │
|
|
382
|
-
│ ┌─────────────────────────────────────────────────────┐ │
|
|
383
|
-
│ │ 5a. Initialize Fluent Client (~100ms) │ │
|
|
384
|
-
│ │ - createClient({ ...ctx, log }) │ │
|
|
385
|
-
│ │ - Validate retailerId exists │ │
|
|
386
|
-
│ │ - client.setRetailerId(retailerId) │ │
|
|
387
|
-
│ └─────────────────────────────────────────────────────┘ │
|
|
388
|
-
│ ┌─────────────────────────────────────────────────────┐ │
|
|
389
|
-
│ │ 5b. Query Fulfilment Details (~500-1500ms) │ │
|
|
390
|
-
│ │ - GraphQL query with nested fields │ │
|
|
391
|
-
│ │ - Fulfilment + items + order + addresses │ │
|
|
392
|
-
│ │ - Handle GraphQLError if query fails │ │
|
|
393
|
-
│ └─────────────────────────────────────────────────────┘ │
|
|
394
|
-
│ ┌─────────────────────────────────────────────────────┐ │
|
|
395
|
-
│ │ 5c. Transform with UniversalMapper (~100-200ms) │ │
|
|
396
|
-
│ │ - Load mapping config from JSON │ │
|
|
397
|
-
│ │ - Apply SDK resolvers (trim, uppercase) │ │
|
|
398
|
-
│ │ - Apply custom resolvers (date formatting) │ │
|
|
399
|
-
│ │ - Transform GraphQL data to XML structure │ │
|
|
400
|
-
│ └─────────────────────────────────────────────────────┘ │
|
|
401
|
-
│ ┌─────────────────────────────────────────────────────┐ │
|
|
402
|
-
│ │ 5d. Generate XML (~50ms) │ │
|
|
403
|
-
│ │ - XMLBuilder with mapped data │ │
|
|
404
|
-
│ │ - XMLBuilder handles escaping automatically │ │
|
|
405
|
-
│ │ - Create Buffer from XML string │ │
|
|
406
|
-
│ └─────────────────────────────────────────────────────┘ │
|
|
407
|
-
│ ┌─────────────────────────────────────────────────────┐ │
|
|
408
|
-
│ │ 5e. Upload to SFTP (~500-2000ms) │ │
|
|
409
|
-
│ │ - Initialize SftpDataSource │ │
|
|
410
|
-
│ │ - Upload with options parameter │ │
|
|
411
|
-
│ │ - Handle DataSourceError if upload fails │ │
|
|
412
|
-
│ │ - ALWAYS dispose() in finally block │ │
|
|
413
|
-
│ └─────────────────────────────────────────────────────┘ │
|
|
414
|
-
│ ┌─────────────────────────────────────────────────────┐ │
|
|
415
|
-
│ │ 5f. Log Completion │ │
|
|
416
|
-
│ │ - Success: Log fulfilment ref and duration │ │
|
|
417
|
-
│ │ - Failure: Log error with category │ │
|
|
418
|
-
│ └─────────────────────────────────────────────────────┘ │
|
|
419
|
-
└─────────────────────────────────────────────────────────────┘
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
### Response Timing
|
|
423
|
-
|
|
424
|
-
| Stage | Timing | Blocking |
|
|
425
|
-
|-------|--------|----------|
|
|
426
|
-
| **Signature Validation** | ~10-50ms | ✅ Yes (blocks response) |
|
|
427
|
-
| **Payload Validation** | ~5ms | ✅ Yes (blocks response) |
|
|
428
|
-
| **HTTP 200 Response** | ~50-100ms | ✅ Fast acknowledgment |
|
|
429
|
-
| **GraphQL Query** | ~500-1500ms | ❌ No (background) |
|
|
430
|
-
| **UniversalMapper Transformation** | ~100-200ms | ❌ No (background) |
|
|
431
|
-
| **XML Generation** | ~50ms | ❌ No (background) |
|
|
432
|
-
| **SFTP Upload** | ~500-2000ms | ❌ No (background) |
|
|
433
|
-
| **Total Background** | ~2000-5000ms | ❌ Fire-and-forget |
|
|
434
|
-
|
|
435
|
-
---
|
|
436
|
-
|
|
437
|
-
## STEP 4: Production Modular Structure
|
|
438
|
-
|
|
439
|
-
### Complete Project Structure
|
|
440
|
-
|
|
441
|
-
```
|
|
442
|
-
rubix-fulfilment-export/
|
|
443
|
-
├── package.json # Dependencies and Versori config
|
|
444
|
-
├── tsconfig.json # TypeScript configuration
|
|
445
|
-
├── readme.md # Setup and deployment instructions
|
|
446
|
-
├── index.ts # Entry point - exports workflow
|
|
447
|
-
└── src/
|
|
448
|
-
├── workflows/
|
|
449
|
-
│ └── webhook/
|
|
450
|
-
│ └── fulfilment-export-handler.ts # Webhook entry point
|
|
451
|
-
│
|
|
452
|
-
├── services/
|
|
453
|
-
│ ├── fulfilment-query.service.ts # GraphQL queries
|
|
454
|
-
│ └── xml-export.service.ts # UniversalMapper + XMLBuilder + SFTP upload
|
|
455
|
-
│
|
|
456
|
-
├── resolvers/
|
|
457
|
-
│ └── fulfilment-resolvers.ts # Custom resolvers for XML transformations
|
|
458
|
-
│
|
|
459
|
-
├── config/
|
|
460
|
-
│ └── fulfilment-xml-mapping.json # External JSON mapping configuration
|
|
461
|
-
│
|
|
462
|
-
└── types/
|
|
463
|
-
└── fulfilment.types.ts # TypeScript interfaces
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
**Why This Structure?**
|
|
467
|
-
- ✅ **Clear separation**: Webhook handlers vs business logic
|
|
468
|
-
- ✅ **Reusable services**: Query and export logic can be unit tested
|
|
469
|
-
- ✅ **External config**: XML mapping changes don't require code changes
|
|
470
|
-
- ✅ **Custom resolvers**: Complex transformations separated from mapping config
|
|
471
|
-
- ✅ **Type safety**: TypeScript interfaces for better IDE support
|
|
472
|
-
- ✅ **Scalable**: Easy to add more fulfilment webhooks or modify XML structure
|
|
473
|
-
- ✅ **Testable**: Services can be mocked and tested independently
|
|
474
|
-
- ✅ **Environment-specific**: Different mapping configs per environment
|
|
475
|
-
|
|
476
|
-
---
|
|
477
|
-
|
|
478
|
-
## SDK Imports (Verified - Versori Optimized)
|
|
479
|
-
|
|
480
|
-
```typescript
|
|
481
|
-
// CRITICAL: Buffer import required for Versori/Deno runtime
|
|
482
|
-
import { Buffer } from 'node:buffer';
|
|
483
|
-
|
|
484
|
-
// FC Connect SDK imports
|
|
485
|
-
import {
|
|
486
|
-
createClient,
|
|
487
|
-
WebhookValidationService,
|
|
488
|
-
UniversalMapper,
|
|
489
|
-
XMLBuilder,
|
|
490
|
-
SftpDataSource,
|
|
491
|
-
DataSourceError,
|
|
492
|
-
AuthenticationError,
|
|
493
|
-
GraphQLError,
|
|
494
|
-
type Logger,
|
|
495
|
-
type VersoriContext,
|
|
496
|
-
} from '@fluentcommerce/fc-connect-sdk';
|
|
497
|
-
|
|
498
|
-
// Versori platform imports
|
|
499
|
-
import { webhook } from '@versori/run';
|
|
500
|
-
import type { Context } from '@versori/run';
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
---
|
|
504
|
-
|
|
505
|
-
## Configuration
|
|
506
|
-
|
|
507
|
-
### Activation Variables
|
|
508
|
-
|
|
509
|
-
```json
|
|
510
|
-
{
|
|
511
|
-
"fluentPublicKey": "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----",
|
|
512
|
-
"sftpHost": "sftp.3pl-partner.com",
|
|
513
|
-
"sftpPort": 22,
|
|
514
|
-
"sftpRemotePath": "/incoming/fulfilments/"
|
|
515
|
-
}
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
> **Important:** `sftpUsername` and `sftpPassword` are **NOT** stored in activation variables. They are securely retrieved from the `sftp_export_server` connection vault at runtime. See the SFTP Credential Management section below for details.
|
|
519
|
-
|
|
520
|
-
### Connections
|
|
521
|
-
|
|
522
|
-
| Connection | Description | Required |
|
|
523
|
-
|------------|-------------|----------|
|
|
524
|
-
| `fluent_commerce` | OAuth2 connection to Fluent Commerce | Yes |
|
|
525
|
-
| `sftp_export_server` | Basic Auth connection for SFTP credentials (username/password) | Yes |
|
|
526
|
-
|
|
527
|
-
## SFTP Credential Management
|
|
528
|
-
|
|
529
|
-
Fetch credentials securely from Versori connection vault using `ctx.credentials().getAccessToken()`:
|
|
530
|
-
|
|
531
|
-
**Benefits:**
|
|
532
|
-
- ✅ Credentials stored securely in Versori vault
|
|
533
|
-
- ✅ Centralized management - update in one place
|
|
534
|
-
- ✅ Access control enforced by platform
|
|
535
|
-
- ✅ No credentials in activation variables
|
|
536
|
-
- ✅ Explicit error handling with validation
|
|
537
|
-
|
|
538
|
-
### Setup Steps
|
|
539
|
-
|
|
540
|
-
1. In Versori Dashboard → Connections → Add Connection
|
|
541
|
-
2. Name: `sftp_export_server`
|
|
542
|
-
3. Type: Basic Auth
|
|
543
|
-
4. Enter SFTP username and password
|
|
544
|
-
5. Save connection
|
|
545
|
-
6. Reference in code: `ctx.credentials().getAccessToken('sftp_export_server')`
|
|
546
|
-
|
|
547
|
-
---
|
|
548
|
-
|
|
549
|
-
## Complete Working Code
|
|
550
|
-
|
|
551
|
-
### 1. Entry Point (index.ts)
|
|
552
|
-
|
|
553
|
-
```typescript
|
|
554
|
-
/**
|
|
555
|
-
* Entry point - Export webhook workflow for Versori platform
|
|
556
|
-
*/
|
|
557
|
-
|
|
558
|
-
export { rubixFulfilmentExportHandler } from './src/workflows/webhook/fulfilment-export-handler';
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
### 2. Webhook Handler (src/workflows/webhook/fulfilment-export-handler.ts)
|
|
562
|
-
|
|
563
|
-
```typescript
|
|
564
|
-
/**
|
|
565
|
-
* Rubix Fulfilment Webhook Handler → SFTP XML Export
|
|
566
|
-
*
|
|
567
|
-
* Direction: Fluent Rubix Workflow (FULFILMENT) → Versori → GraphQL → UniversalMapper → XML → SFTP
|
|
568
|
-
*/
|
|
569
|
-
|
|
570
|
-
import { Buffer } from 'node:buffer';
|
|
571
|
-
import { webhook } from '@versori/run';
|
|
572
|
-
import type { Context } from '@versori/run';
|
|
573
|
-
import {
|
|
574
|
-
WebhookValidationService,
|
|
575
|
-
type Logger,
|
|
576
|
-
} from '@fluentcommerce/fc-connect-sdk';
|
|
577
|
-
import { processFulfilmentExport } from '../../services/fulfilment-query.service';
|
|
578
|
-
|
|
579
|
-
export const rubixFulfilmentExportHandler = webhook('rubix-fulfilment', {
|
|
580
|
-
response: { mode: 'sync' }, // ✅ Sync mode: response sent when handler returns
|
|
581
|
-
}, async (ctx: Context<any>) => {
|
|
582
|
-
const { log, activation } = ctx;
|
|
583
|
-
|
|
584
|
-
log.info('🚀 [WEBHOOK] Received Rubix fulfilment webhook', {
|
|
585
|
-
timestamp: new Date().toISOString(),
|
|
586
|
-
correlationId: activation?.id,
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
// ========================================
|
|
590
|
-
// STEP 1: VALIDATE SIGNATURE (Synchronous)
|
|
591
|
-
// ========================================
|
|
592
|
-
|
|
593
|
-
const publicKey = activation.getVariable('fluentPublicKey');
|
|
594
|
-
if (!publicKey) {
|
|
595
|
-
log.error('❌ [WEBHOOK] Missing fluentPublicKey configuration');
|
|
596
|
-
return {
|
|
597
|
-
status: 500,
|
|
598
|
-
body: {
|
|
599
|
-
success: false,
|
|
600
|
-
error: 'Missing fluentPublicKey configuration',
|
|
601
|
-
recommendation: 'Configure fluentPublicKey in activation variables',
|
|
602
|
-
},
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
// Extract raw body (Versori provides parsed data in ctx.data)
|
|
607
|
-
const rawBody = typeof ctx.data === 'string' ? ctx.data : JSON.stringify(ctx.data);
|
|
608
|
-
|
|
609
|
-
// Extract headers from request (ctx.request() is a function call)
|
|
610
|
-
const req = ctx.request?.() || {};
|
|
611
|
-
const headersObj = req.headers || {};
|
|
612
|
-
const headers = headersObj instanceof Headers
|
|
613
|
-
? Object.fromEntries(headersObj.entries())
|
|
614
|
-
: headersObj;
|
|
615
|
-
|
|
616
|
-
log.info('🔍 [WEBHOOK] Validating webhook signature');
|
|
617
|
-
|
|
618
|
-
const validator = new WebhookValidationService({ strictValidation: true }, log as Logger);
|
|
619
|
-
const result = await validator.validateWebhook(rawBody, headers, publicKey);
|
|
620
|
-
|
|
621
|
-
if (!result.isValid) {
|
|
622
|
-
log.error('❌ [WEBHOOK] Invalid webhook signature', {
|
|
623
|
-
error: result.error,
|
|
624
|
-
algorithm: result.algorithm,
|
|
625
|
-
});
|
|
626
|
-
return {
|
|
627
|
-
status: 401,
|
|
628
|
-
body: {
|
|
629
|
-
success: false,
|
|
630
|
-
error: 'Invalid webhook signature',
|
|
631
|
-
recommendation: 'Verify fluentPublicKey matches Fluent environment',
|
|
632
|
-
},
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
log.info('✅ [WEBHOOK] Signature validated successfully', {
|
|
637
|
-
algorithm: result.algorithm,
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
// ========================================
|
|
641
|
-
// STEP 2: VALIDATE PAYLOAD (Synchronous)
|
|
642
|
-
// ========================================
|
|
643
|
-
|
|
644
|
-
const payload = typeof ctx.data === 'string' ? JSON.parse(ctx.data) : ctx.data;
|
|
645
|
-
const { entityRef, entityType, retailerId } = payload;
|
|
646
|
-
|
|
647
|
-
if (!entityRef) {
|
|
648
|
-
log.error('❌ [WEBHOOK] Missing entityRef in payload', { payload });
|
|
649
|
-
return {
|
|
650
|
-
status: 400,
|
|
651
|
-
body: {
|
|
652
|
-
success: false,
|
|
653
|
-
error: 'Missing entityRef in payload',
|
|
654
|
-
recommendation: 'Ensure Rubix SendWebhook includes fulfilment ref',
|
|
655
|
-
},
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
if (entityType !== 'FULFILMENT') {
|
|
660
|
-
log.error('❌ [WEBHOOK] Invalid entity type', { entityType, expected: 'FULFILMENT' });
|
|
661
|
-
return {
|
|
662
|
-
status: 400,
|
|
663
|
-
body: {
|
|
664
|
-
success: false,
|
|
665
|
-
error: `Invalid entity type: ${entityType}. Expected: FULFILMENT`,
|
|
666
|
-
recommendation: 'Use order-attribute-update template for ORDER webhooks',
|
|
667
|
-
},
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
if (!retailerId) {
|
|
672
|
-
log.error('❌ [WEBHOOK] Missing retailerId in payload', { payload });
|
|
673
|
-
return {
|
|
674
|
-
status: 400,
|
|
675
|
-
body: {
|
|
676
|
-
success: false,
|
|
677
|
-
error: 'Missing retailerId in payload',
|
|
678
|
-
recommendation: 'Ensure Rubix SendWebhook includes retailerId',
|
|
679
|
-
},
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
log.info('✅ [WEBHOOK] Validation passed, starting background processing', {
|
|
684
|
-
entityRef,
|
|
685
|
-
entityType,
|
|
686
|
-
retailerId,
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
// ========================================
|
|
690
|
-
// STEP 3: FIRE-AND-FORGET BACKGROUND PROCESSING
|
|
691
|
-
// ========================================
|
|
692
|
-
|
|
693
|
-
// ✅ Fire-and-forget: Start background processing WITHOUT await
|
|
694
|
-
// The promise continues execution after we return the response
|
|
695
|
-
processFulfilmentExport(ctx, payload)
|
|
696
|
-
.then(() => {
|
|
697
|
-
log.info('✅ [BACKGROUND] Fulfilment exported successfully', {
|
|
698
|
-
fulfilmentRef: entityRef,
|
|
699
|
-
});
|
|
700
|
-
})
|
|
701
|
-
.catch((error: unknown) => {
|
|
702
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
703
|
-
log.error('❌ [BACKGROUND] Fulfilment export failed', {
|
|
704
|
-
fulfilmentRef: entityRef,
|
|
705
|
-
error: errorMessage,
|
|
706
|
-
stack: error instanceof Error ? error.stack : undefined,
|
|
707
|
-
errorType: error instanceof Error ? error.constructor.name : typeof error,
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
// Return immediately (response sent with this return value)
|
|
712
|
-
return {
|
|
713
|
-
status: 200,
|
|
714
|
-
body: {
|
|
715
|
-
success: true,
|
|
716
|
-
entityType,
|
|
717
|
-
fulfilmentRef: entityRef,
|
|
718
|
-
message: 'Webhook validated and export started in background',
|
|
719
|
-
timestamp: new Date().toISOString(),
|
|
720
|
-
correlationId: activation?.id,
|
|
721
|
-
},
|
|
722
|
-
};
|
|
723
|
-
});
|
|
724
|
-
```
|
|
725
|
-
|
|
726
|
-
### 3. Fulfilment Query Service (src/services/fulfilment-query.service.ts)
|
|
727
|
-
|
|
728
|
-
```typescript
|
|
729
|
-
/**
|
|
730
|
-
* Fulfilment Query Service
|
|
731
|
-
*
|
|
732
|
-
* Handles GraphQL queries for fulfilment details and orchestrates XML export
|
|
733
|
-
*/
|
|
734
|
-
|
|
735
|
-
import {
|
|
736
|
-
createClient,
|
|
737
|
-
DataSourceError,
|
|
738
|
-
AuthenticationError,
|
|
739
|
-
GraphQLError,
|
|
740
|
-
type Logger,
|
|
741
|
-
type VersoriContext,
|
|
742
|
-
} from '@fluentcommerce/fc-connect-sdk';
|
|
743
|
-
import { exportFulfilmentToSFTP } from './xml-export.service';
|
|
744
|
-
import type { RubixFulfilmentPayload, FulfilmentData } from '../types/fulfilment.types';
|
|
745
|
-
|
|
746
|
-
// Single query with nested items (schema-validated structure)
|
|
747
|
-
const FULFILMENT_QUERY = `
|
|
748
|
-
query GetFulfilment($id: ID!, $first: Int!, $after: String) {
|
|
749
|
-
fulfilment(id: $id) {
|
|
750
|
-
id
|
|
751
|
-
ref
|
|
752
|
-
status
|
|
753
|
-
deliveryType
|
|
754
|
-
order {
|
|
755
|
-
id
|
|
756
|
-
ref
|
|
757
|
-
customer {
|
|
758
|
-
firstName
|
|
759
|
-
lastName
|
|
760
|
-
email
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
toAddress {
|
|
764
|
-
name
|
|
765
|
-
street
|
|
766
|
-
street2
|
|
767
|
-
city
|
|
768
|
-
state
|
|
769
|
-
postcode
|
|
770
|
-
country
|
|
771
|
-
}
|
|
772
|
-
fromAddress {
|
|
773
|
-
name
|
|
774
|
-
street
|
|
775
|
-
street2
|
|
776
|
-
city
|
|
777
|
-
state
|
|
778
|
-
postcode
|
|
779
|
-
country
|
|
780
|
-
}
|
|
781
|
-
items(first: $first, after: $after) {
|
|
782
|
-
edges {
|
|
783
|
-
node {
|
|
784
|
-
id
|
|
785
|
-
ref
|
|
786
|
-
requestedQuantity
|
|
787
|
-
filledQuantity
|
|
788
|
-
rejectedQuantity
|
|
789
|
-
orderItem {
|
|
790
|
-
id
|
|
791
|
-
ref
|
|
792
|
-
productRef
|
|
793
|
-
product {
|
|
794
|
-
name
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
cursor
|
|
799
|
-
}
|
|
800
|
-
pageInfo {
|
|
801
|
-
hasNextPage
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
createdOn
|
|
805
|
-
updatedOn
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
`;
|
|
809
|
-
|
|
810
|
-
export async function processFulfilmentExport(
|
|
811
|
-
ctx: VersoriContext,
|
|
812
|
-
payload: RubixFulfilmentPayload
|
|
813
|
-
): Promise<void> {
|
|
814
|
-
const log = ctx.log as Logger;
|
|
815
|
-
const { entityRef, retailerId } = payload;
|
|
816
|
-
|
|
817
|
-
const processingStartTime = Date.now();
|
|
818
|
-
|
|
819
|
-
log.info('🔄 [BACKGROUND] Starting fulfilment export', {
|
|
820
|
-
timestamp: new Date().toISOString(),
|
|
821
|
-
fulfilmentRef: entityRef,
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
try {
|
|
825
|
-
// ========================================
|
|
826
|
-
// STEP 1: VALIDATE RETAILER ID
|
|
827
|
-
// ========================================
|
|
828
|
-
|
|
829
|
-
if (!retailerId) {
|
|
830
|
-
log.error('❌ [BACKGROUND] Missing retailerId in payload', {
|
|
831
|
-
fulfilmentRef: entityRef,
|
|
832
|
-
});
|
|
833
|
-
throw new Error('retailerId is required for GraphQL operations');
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
// ========================================
|
|
837
|
-
// STEP 2: INITIALIZE FLUENT CLIENT
|
|
838
|
-
// ========================================
|
|
839
|
-
|
|
840
|
-
const client = await createClient({ ...ctx, log });
|
|
841
|
-
await client.setRetailerId(retailerId);
|
|
842
|
-
|
|
843
|
-
// ========================================
|
|
844
|
-
// STEP 3: QUERY FULFILMENT WITH NESTED ITEMS
|
|
845
|
-
// ========================================
|
|
846
|
-
|
|
847
|
-
log.info('🔍 [BACKGROUND] Querying fulfilment with items', { fulfilmentRef: entityRef });
|
|
848
|
-
|
|
849
|
-
const result = await client.graphql({
|
|
850
|
-
query: FULFILMENT_QUERY,
|
|
851
|
-
variables: {
|
|
852
|
-
id: entityRef, // ✅ Use 'id' parameter (schema-validated)
|
|
853
|
-
first: 100,
|
|
854
|
-
},
|
|
855
|
-
pagination: {
|
|
856
|
-
connectionPath: 'fulfilment.items', // ✅ Nested connection pagination
|
|
857
|
-
maxPages: 10, // Handles up to 1000 items (100 per page × 10 pages)
|
|
858
|
-
},
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
const fulfilmentData = result.data?.fulfilment as FulfilmentData | null;
|
|
862
|
-
|
|
863
|
-
if (!fulfilmentData) {
|
|
864
|
-
log.error('❌ [BACKGROUND] Fulfilment not found', { fulfilmentRef: entityRef });
|
|
865
|
-
throw new Error(`Fulfilment not found: ${entityRef}`);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
const itemCount = fulfilmentData.items?.edges?.length || 0;
|
|
869
|
-
|
|
870
|
-
log.info('✅ [BACKGROUND] Fulfilment and items queried successfully', {
|
|
871
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
872
|
-
status: fulfilmentData.status,
|
|
873
|
-
itemCount,
|
|
874
|
-
orderRef: fulfilmentData.order?.ref,
|
|
875
|
-
paginationUsed: result.metadata?.totalPages > 1,
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
// ========================================
|
|
879
|
-
// STEP 4: EXPORT TO SFTP
|
|
880
|
-
// ========================================
|
|
881
|
-
|
|
882
|
-
await exportFulfilmentToSFTP(ctx, fulfilmentData, log);
|
|
883
|
-
|
|
884
|
-
const duration = Date.now() - processingStartTime;
|
|
885
|
-
log.info('✅ [BACKGROUND] Fulfilment export completed', {
|
|
886
|
-
fulfilmentRef: entityRef,
|
|
887
|
-
duration: `${duration}ms`,
|
|
888
|
-
});
|
|
889
|
-
} catch (error: unknown) {
|
|
890
|
-
let errorMessage = 'Unknown error';
|
|
891
|
-
let recommendation: string | undefined;
|
|
892
|
-
let errorCategory = 'UNKNOWN';
|
|
893
|
-
|
|
894
|
-
if (error instanceof GraphQLError) {
|
|
895
|
-
errorMessage = error.message;
|
|
896
|
-
recommendation = 'Review GraphQL query syntax and field permissions';
|
|
897
|
-
errorCategory = 'GRAPHQL';
|
|
898
|
-
} else if (error instanceof AuthenticationError) {
|
|
899
|
-
errorMessage = error.message;
|
|
900
|
-
recommendation = 'Verify Fluent Commerce credentials and retailerId';
|
|
901
|
-
errorCategory = 'AUTHENTICATION';
|
|
902
|
-
} else if (error instanceof DataSourceError) {
|
|
903
|
-
errorMessage = error.message;
|
|
904
|
-
recommendation = 'Check SFTP configuration and connectivity';
|
|
905
|
-
errorCategory = 'DATA_SOURCE';
|
|
906
|
-
} else if (error instanceof Error) {
|
|
907
|
-
errorMessage = error.message;
|
|
908
|
-
} else {
|
|
909
|
-
errorMessage = String(error);
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
log.error('❌ [BACKGROUND] Fulfilment export failed', {
|
|
913
|
-
fulfilmentRef: entityRef,
|
|
914
|
-
error: errorMessage,
|
|
915
|
-
errorCategory,
|
|
916
|
-
recommendation,
|
|
917
|
-
stack: error instanceof Error ? error.stack : undefined,
|
|
918
|
-
errorType: error instanceof Error ? error.constructor.name : typeof error,
|
|
919
|
-
});
|
|
920
|
-
|
|
921
|
-
throw error;
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
```
|
|
925
|
-
|
|
926
|
-
### 4. XML Export Service (src/services/xml-export.service.ts)
|
|
927
|
-
|
|
928
|
-
```typescript
|
|
929
|
-
/**
|
|
930
|
-
* XML Export Service
|
|
931
|
-
*
|
|
932
|
-
* Handles XML generation and SFTP upload for fulfilment exports
|
|
933
|
-
* Uses UniversalMapper with external JSON mapping configuration
|
|
934
|
-
*/
|
|
935
|
-
|
|
936
|
-
import { Buffer } from 'node:buffer';
|
|
937
|
-
import {
|
|
938
|
-
UniversalMapper,
|
|
939
|
-
XMLBuilder,
|
|
940
|
-
SftpDataSource,
|
|
941
|
-
type Logger,
|
|
942
|
-
type VersoriContext,
|
|
943
|
-
} from '@fluentcommerce/fc-connect-sdk';
|
|
944
|
-
import type { FulfilmentData } from '../types/fulfilment.types';
|
|
945
|
-
import mappingConfig from '../config/fulfilment-xml-mapping.json' with { type: 'json' };
|
|
946
|
-
import { customResolvers } from '../resolvers/fulfilment-resolvers';
|
|
947
|
-
|
|
948
|
-
export async function exportFulfilmentToSFTP(
|
|
949
|
-
ctx: VersoriContext,
|
|
950
|
-
fulfilmentData: FulfilmentData,
|
|
951
|
-
log: Logger
|
|
952
|
-
): Promise<void> {
|
|
953
|
-
const { activation } = ctx;
|
|
954
|
-
|
|
955
|
-
log.info('📝 [BACKGROUND] Generating XML for fulfilment', {
|
|
956
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
// ========================================
|
|
960
|
-
// STEP 1: TRANSFORM DATA WITH UNIVERSALMAPPER
|
|
961
|
-
// ========================================
|
|
962
|
-
|
|
963
|
-
log.info('🔄 [BACKGROUND] Transforming fulfilment data with UniversalMapper', {
|
|
964
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
965
|
-
});
|
|
966
|
-
|
|
967
|
-
const mapper = new UniversalMapper(mappingConfig, {
|
|
968
|
-
customResolvers,
|
|
969
|
-
});
|
|
970
|
-
|
|
971
|
-
const mappingResult = await mapper.map(fulfilmentData);
|
|
972
|
-
|
|
973
|
-
if (!mappingResult.success) {
|
|
974
|
-
log.error('❌ [BACKGROUND] Mapping failed', {
|
|
975
|
-
errors: mappingResult.errors,
|
|
976
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
977
|
-
});
|
|
978
|
-
throw new Error(`Mapping failed: ${mappingResult.errors?.join(', ')}`);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
const mappedData = mappingResult.data;
|
|
982
|
-
|
|
983
|
-
log.info('✅ [BACKGROUND] Data transformed successfully', {
|
|
984
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
985
|
-
fieldCount: Object.keys(mappedData).length,
|
|
986
|
-
});
|
|
987
|
-
|
|
988
|
-
// ========================================
|
|
989
|
-
// STEP 2: GENERATE XML WITH XMLBUILDER
|
|
990
|
-
// ========================================
|
|
991
|
-
|
|
992
|
-
const xmlBuilder = new XMLBuilder({
|
|
993
|
-
prettyPrint: true,
|
|
994
|
-
xmlDeclaration: true,
|
|
995
|
-
encoding: 'UTF-8',
|
|
996
|
-
});
|
|
997
|
-
|
|
998
|
-
const xmlString = xmlBuilder.build(mappedData, 'FulfilmentExport');
|
|
999
|
-
const xmlBuffer = Buffer.from(xmlString, 'utf8');
|
|
1000
|
-
|
|
1001
|
-
log.info('✅ [BACKGROUND] XML generated successfully', {
|
|
1002
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
1003
|
-
xmlSizeBytes: xmlBuffer.length,
|
|
1004
|
-
xmlSizeKB: Math.round(xmlBuffer.length / 1024),
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
// ========================================
|
|
1008
|
-
// STEP 3: UPLOAD TO SFTP
|
|
1009
|
-
// ========================================
|
|
1010
|
-
|
|
1011
|
-
log.info('📤 [BACKGROUND] Preparing SFTP upload', {
|
|
1012
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
1013
|
-
});
|
|
1014
|
-
|
|
1015
|
-
// ========================================
|
|
1016
|
-
// SFTP CREDENTIAL RETRIEVAL
|
|
1017
|
-
// ========================================
|
|
1018
|
-
|
|
1019
|
-
/**
|
|
1020
|
-
* Retrieve SFTP credentials from connection configuration
|
|
1021
|
-
*
|
|
1022
|
-
* Connection Name: 'sftp_export_server' (must match the connection name in Versori UI)
|
|
1023
|
-
* Auth Type: Basic Authentication (username + password)
|
|
1024
|
-
*/
|
|
1025
|
-
log.info('🔐 [BACKGROUND] Retrieving SFTP credentials from connection configuration');
|
|
1026
|
-
|
|
1027
|
-
let sftpUsername: string;
|
|
1028
|
-
let sftpPassword: string;
|
|
1029
|
-
|
|
1030
|
-
try {
|
|
1031
|
-
// Retrieve credentials from the 'sftp_export_server' connection
|
|
1032
|
-
const sftpCred = await ctx.credentials().getAccessToken('sftp_export_server');
|
|
1033
|
-
|
|
1034
|
-
if (!sftpCred?.accessToken) {
|
|
1035
|
-
throw new Error('No SFTP credentials found in connection configuration');
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
// Decode base64 accessToken to get "username:password"
|
|
1039
|
-
const rawBasicAuth = Buffer.from(sftpCred.accessToken, 'base64').toString('utf-8');
|
|
1040
|
-
|
|
1041
|
-
// Split on ':' to extract username and password
|
|
1042
|
-
const parts = rawBasicAuth.split(':');
|
|
1043
|
-
|
|
1044
|
-
if (parts.length !== 2) {
|
|
1045
|
-
throw new Error('Invalid SFTP credential format - expected username:password');
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
sftpUsername = parts[0];
|
|
1049
|
-
sftpPassword = parts[1];
|
|
1050
|
-
|
|
1051
|
-
log.info('✅ [BACKGROUND] SFTP credentials retrieved successfully', {
|
|
1052
|
-
hasUsername: !!sftpUsername,
|
|
1053
|
-
hasPassword: !!sftpPassword,
|
|
1054
|
-
usernameLength: sftpUsername.length,
|
|
1055
|
-
passwordLength: sftpPassword.length,
|
|
1056
|
-
});
|
|
1057
|
-
} catch (error: any) {
|
|
1058
|
-
log.error('❌ [BACKGROUND] Failed to retrieve SFTP credentials', {
|
|
1059
|
-
message: error instanceof Error ? error.message : String(error),
|
|
1060
|
-
stack: error instanceof Error ? error.stack : undefined,
|
|
1061
|
-
errorType: error instanceof Error ? error.constructor.name : 'Error',
|
|
1062
|
-
recommendation: 'Please ensure the SFTP connection "sftp_export_server" is configured in the Connections section with Basic Authentication (username and password)',
|
|
1063
|
-
});
|
|
1064
|
-
throw new Error(
|
|
1065
|
-
`Failed to retrieve SFTP credentials from connection configuration: ${error instanceof Error ? error.message : String(error)}. ` +
|
|
1066
|
-
'Please ensure the SFTP connection is configured in the Connections section with Basic Authentication (username and password)'
|
|
1067
|
-
);
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
// Get SFTP configuration from activation variables
|
|
1071
|
-
const sftpHost = activation.getVariable('sftpHost');
|
|
1072
|
-
const sftpPort = parseInt(activation.getVariable('sftpPort') || '22', 10);
|
|
1073
|
-
const sftpRemotePath = activation.getVariable('sftpRemotePath') || '/incoming/fulfilments/';
|
|
1074
|
-
|
|
1075
|
-
if (!sftpHost) {
|
|
1076
|
-
log.error('⚠️ [BACKGROUND] SFTP configuration missing', {
|
|
1077
|
-
recommendation: 'Configure sftpHost activation variable',
|
|
1078
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
1079
|
-
});
|
|
1080
|
-
throw new Error('SFTP configuration missing: sftpHost is required');
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
const sftpConfig = {
|
|
1084
|
-
type: 'SFTP_XML' as const,
|
|
1085
|
-
connectionId: 'sftp_export_server',
|
|
1086
|
-
name: 'Fulfilment XML Export',
|
|
1087
|
-
settings: {
|
|
1088
|
-
host: sftpHost,
|
|
1089
|
-
port: sftpPort,
|
|
1090
|
-
username: sftpUsername,
|
|
1091
|
-
password: sftpPassword,
|
|
1092
|
-
},
|
|
1093
|
-
};
|
|
1094
|
-
|
|
1095
|
-
const sftp = new SftpDataSource(sftpConfig, log);
|
|
1096
|
-
|
|
1097
|
-
try {
|
|
1098
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
1099
|
-
const fileName = `fulfilment-${fulfilmentData.ref}-${timestamp}.xml`;
|
|
1100
|
-
const remoteFilePath = `${sftpRemotePath}${fileName}`;
|
|
1101
|
-
|
|
1102
|
-
// ✅ CRITICAL FIX: Include options parameter
|
|
1103
|
-
await sftp.uploadFile(remoteFilePath, xmlBuffer, {
|
|
1104
|
-
overwrite: true,
|
|
1105
|
-
createDirectories: true,
|
|
1106
|
-
});
|
|
1107
|
-
|
|
1108
|
-
log.info('✅ [BACKGROUND] Fulfilment XML exported to SFTP', {
|
|
1109
|
-
fulfilmentRef: fulfilmentData.ref,
|
|
1110
|
-
remoteFilePath,
|
|
1111
|
-
status: fulfilmentData.status,
|
|
1112
|
-
fileSizeKB: Math.round(xmlBuffer.length / 1024),
|
|
1113
|
-
});
|
|
1114
|
-
} finally {
|
|
1115
|
-
// ✅ CRITICAL: Always dispose SFTP connection
|
|
1116
|
-
await sftp.dispose();
|
|
1117
|
-
log.info('🔌 [BACKGROUND] SFTP connection disposed');
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
```
|
|
1121
|
-
|
|
1122
|
-
### 5. Mapping Configuration (src/config/fulfilment-xml-mapping.json)
|
|
1123
|
-
|
|
1124
|
-
**IMPORTANT: Array Mapping Patterns**
|
|
1125
|
-
|
|
1126
|
-
The SDK supports **two patterns** for GraphQL edges/nodes arrays. Here's exactly what happens with each:
|
|
1127
|
-
|
|
1128
|
-
## Step-by-Step: What Each Pattern Does
|
|
1129
|
-
|
|
1130
|
-
### Input Data (GraphQL Response)
|
|
1131
|
-
```javascript
|
|
1132
|
-
{
|
|
1133
|
-
items: {
|
|
1134
|
-
edges: [
|
|
1135
|
-
{ node: { ref: "FFI-001", requestedQuantity: 2, orderItem: { productRef: "SKU-001" } } },
|
|
1136
|
-
{ node: { ref: "FFI-002", requestedQuantity: 1, orderItem: { productRef: "SKU-002" } } }
|
|
1137
|
-
]
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
```
|
|
1141
|
-
|
|
1142
|
-
---
|
|
1143
|
-
|
|
1144
|
-
### Pattern 1: `source: "items.edges[*].node"` + `Item` wrapper
|
|
1145
|
-
|
|
1146
|
-
**Config:**
|
|
1147
|
-
```json
|
|
1148
|
-
"Items": {
|
|
1149
|
-
"source": "items.edges[*].node",
|
|
1150
|
-
"isArray": true,
|
|
1151
|
-
"fields": {
|
|
1152
|
-
"Item": {
|
|
1153
|
-
"fields": {
|
|
1154
|
-
"@ref": { "source": "ref" },
|
|
1155
|
-
"ProductRef": { "source": "orderItem.productRef" }
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
```
|
|
1161
|
-
|
|
1162
|
-
**Step 1:** SDK extracts `items.edges[*].node`
|
|
1163
|
-
- Splits on `[*]` → `arrayPath="items.edges"`, `nodePath="node"`
|
|
1164
|
-
- Gets `items.edges` array: `[{ node: {...} }, { node: {...} }]`
|
|
1165
|
-
- Extracts `.node` from each → `[{ ref: "FFI-001", ... }, { ref: "FFI-002", ... }]`
|
|
1166
|
-
|
|
1167
|
-
**Step 2:** For each node, maps nested `Item` fields
|
|
1168
|
-
- Node 1: `{ ref: "FFI-001", orderItem: { productRef: "SKU-001" } }`
|
|
1169
|
-
- Maps `"@ref": { "source": "ref" }` → extracts `node.ref` = `"FFI-001"`
|
|
1170
|
-
- Maps `"ProductRef": { "source": "orderItem.productRef" }` → extracts `node.orderItem.productRef` = `"SKU-001"`
|
|
1171
|
-
- Result: `{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } }`
|
|
1172
|
-
|
|
1173
|
-
**Step 3:** Final mapped data
|
|
1174
|
-
```javascript
|
|
1175
|
-
{
|
|
1176
|
-
Items: [
|
|
1177
|
-
{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } },
|
|
1178
|
-
{ Item: { "@ref": "FFI-002", "ProductRef": "SKU-002" } }
|
|
1179
|
-
]
|
|
1180
|
-
}
|
|
1181
|
-
```
|
|
1182
|
-
|
|
1183
|
-
**Step 4:** XMLBuilder output
|
|
1184
|
-
```xml
|
|
1185
|
-
<Items>
|
|
1186
|
-
<Item ref="FFI-001">
|
|
1187
|
-
<ProductRef>SKU-001</ProductRef>
|
|
1188
|
-
</Item>
|
|
1189
|
-
<Item ref="FFI-002">
|
|
1190
|
-
<ProductRef>SKU-002</ProductRef>
|
|
1191
|
-
</Item>
|
|
1192
|
-
</Items>
|
|
1193
|
-
```
|
|
1194
|
-
|
|
1195
|
-
---
|
|
1196
|
-
|
|
1197
|
-
### Pattern 2: `source: "items.edges"` + `Item` wrapper
|
|
1198
|
-
|
|
1199
|
-
**Config:**
|
|
1200
|
-
```json
|
|
1201
|
-
"Items": {
|
|
1202
|
-
"source": "items.edges",
|
|
1203
|
-
"isArray": true,
|
|
1204
|
-
"fields": {
|
|
1205
|
-
"Item": {
|
|
1206
|
-
"fields": {
|
|
1207
|
-
"@ref": { "source": "node.ref" },
|
|
1208
|
-
"ProductRef": { "source": "node.orderItem.productRef" }
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
```
|
|
1214
|
-
|
|
1215
|
-
**Step 1:** SDK extracts `items.edges`
|
|
1216
|
-
- Gets array directly: `[{ node: {...} }, { node: {...} }]` (edges array)
|
|
1217
|
-
|
|
1218
|
-
**Step 2:** For each edge, maps nested `Item` fields
|
|
1219
|
-
- Edge 1: `{ node: { ref: "FFI-001", orderItem: { productRef: "SKU-001" } } }`
|
|
1220
|
-
- Maps `"@ref": { "source": "node.ref" }` → extracts `edge.node.ref` = `"FFI-001"`
|
|
1221
|
-
- Maps `"ProductRef": { "source": "node.orderItem.productRef" }` → extracts `edge.node.orderItem.productRef` = `"SKU-001"`
|
|
1222
|
-
- Result: `{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } }`
|
|
1223
|
-
|
|
1224
|
-
**Step 3:** Final mapped data (IDENTICAL to Pattern 1)
|
|
1225
|
-
```javascript
|
|
1226
|
-
{
|
|
1227
|
-
Items: [
|
|
1228
|
-
{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } },
|
|
1229
|
-
{ Item: { "@ref": "FFI-002", "ProductRef": "SKU-002" } }
|
|
1230
|
-
]
|
|
1231
|
-
}
|
|
1232
|
-
```
|
|
1233
|
-
|
|
1234
|
-
**Step 4:** XMLBuilder output (IDENTICAL to Pattern 1)
|
|
1235
|
-
```xml
|
|
1236
|
-
<Items>
|
|
1237
|
-
<Item ref="FFI-001">
|
|
1238
|
-
<ProductRef>SKU-001</ProductRef>
|
|
1239
|
-
</Item>
|
|
1240
|
-
<Item ref="FFI-002">
|
|
1241
|
-
<ProductRef>SKU-002</ProductRef>
|
|
1242
|
-
</Item>
|
|
1243
|
-
</Items>
|
|
1244
|
-
```
|
|
1245
|
-
|
|
1246
|
-
---
|
|
1247
|
-
|
|
1248
|
-
## Key Differences
|
|
1249
|
-
|
|
1250
|
-
| Aspect | Pattern 1 (`edges[*].node`) | Pattern 2 (`edges`) |
|
|
1251
|
-
|--------|----------------------------|---------------------|
|
|
1252
|
-
| **What SDK extracts** | Nodes directly: `[{ ref: "..." }, ...]` | Edges: `[{ node: {...} }, ...]` |
|
|
1253
|
-
| **Field paths** | `"ref"` (direct) | `"node.ref"` (need prefix) |
|
|
1254
|
-
| **Mapped data** | ✅ Same | ✅ Same |
|
|
1255
|
-
| **XML output** | ✅ Same (with `Item` wrapper) | ✅ Same (with `Item` wrapper) |
|
|
1256
|
-
| **Without `Item` wrapper** | ❌ Wrong XML | ❌ Wrong XML |
|
|
1257
|
-
|
|
1258
|
-
## Why Both Work
|
|
1259
|
-
|
|
1260
|
-
**Both patterns produce identical results** because:
|
|
1261
|
-
1. Pattern 1 extracts nodes first, then maps fields from nodes
|
|
1262
|
-
2. Pattern 2 extracts edges, then maps fields from `edge.node`
|
|
1263
|
-
3. Both end up with the same mapped data structure
|
|
1264
|
-
4. XMLBuilder converts the same structure to identical XML
|
|
1265
|
-
|
|
1266
|
-
**The `Item` wrapper is required** for both patterns to create `<Item>` elements instead of flat `<@ref>` elements.
|
|
1267
|
-
|
|
1268
|
-
**Recommendation:** Use Pattern 1 (`edges[*].node`) - cleaner field paths, less typing.
|
|
1269
|
-
|
|
1270
|
-
---
|
|
1271
|
-
|
|
1272
|
-
**Full Mapping Configuration:**
|
|
1273
|
-
|
|
1274
|
-
```json
|
|
1275
|
-
{
|
|
1276
|
-
"name": "fulfilment-xml-mapping",
|
|
1277
|
-
"version": "1.0.0",
|
|
1278
|
-
"description": "Fluent Fulfilment → XML Export Mapping for 3PL/WMS",
|
|
1279
|
-
"fields": {
|
|
1280
|
-
"Fulfilment": {
|
|
1281
|
-
"fields": {
|
|
1282
|
-
"@ref": {
|
|
1283
|
-
"source": "ref",
|
|
1284
|
-
"required": true,
|
|
1285
|
-
"resolver": "sdk.trim"
|
|
1286
|
-
},
|
|
1287
|
-
"@status": {
|
|
1288
|
-
"source": "status",
|
|
1289
|
-
"required": true,
|
|
1290
|
-
"resolver": "sdk.uppercase"
|
|
1291
|
-
},
|
|
1292
|
-
"OrderRef": {
|
|
1293
|
-
"source": "order.ref",
|
|
1294
|
-
"required": true,
|
|
1295
|
-
"resolver": "sdk.trim"
|
|
1296
|
-
},
|
|
1297
|
-
"DeliveryType": {
|
|
1298
|
-
"source": "deliveryType",
|
|
1299
|
-
"required": false,
|
|
1300
|
-
"resolver": "sdk.trim"
|
|
1301
|
-
},
|
|
1302
|
-
"Customer": {
|
|
1303
|
-
"source": "order.customer",
|
|
1304
|
-
"fields": {
|
|
1305
|
-
"FirstName": {
|
|
1306
|
-
"source": "firstName",
|
|
1307
|
-
"required": false,
|
|
1308
|
-
"resolver": "sdk.trim"
|
|
1309
|
-
},
|
|
1310
|
-
"LastName": {
|
|
1311
|
-
"source": "lastName",
|
|
1312
|
-
"required": false,
|
|
1313
|
-
"resolver": "sdk.trim"
|
|
1314
|
-
},
|
|
1315
|
-
"Email": {
|
|
1316
|
-
"source": "email",
|
|
1317
|
-
"required": false,
|
|
1318
|
-
"resolver": "sdk.trim"
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
},
|
|
1322
|
-
"ToAddress": {
|
|
1323
|
-
"source": "toAddress",
|
|
1324
|
-
"fields": {
|
|
1325
|
-
"Name": { "source": "name", "required": false, "resolver": "sdk.trim" },
|
|
1326
|
-
"Street": { "source": "street", "required": false, "resolver": "sdk.trim" },
|
|
1327
|
-
"Street2": { "source": "street2", "required": false, "resolver": "sdk.trim" },
|
|
1328
|
-
"City": { "source": "city", "required": false, "resolver": "sdk.trim" },
|
|
1329
|
-
"State": { "source": "state", "required": false, "resolver": "sdk.trim" },
|
|
1330
|
-
"Postcode": { "source": "postcode", "required": false, "resolver": "sdk.trim" },
|
|
1331
|
-
"Country": { "source": "country", "required": false, "resolver": "sdk.trim" }
|
|
1332
|
-
}
|
|
1333
|
-
},
|
|
1334
|
-
"FromAddress": {
|
|
1335
|
-
"source": "fromAddress",
|
|
1336
|
-
"fields": {
|
|
1337
|
-
"Name": { "source": "name", "required": false, "resolver": "sdk.trim" },
|
|
1338
|
-
"Street": { "source": "street", "required": false, "resolver": "sdk.trim" },
|
|
1339
|
-
"Street2": { "source": "street2", "required": false, "resolver": "sdk.trim" },
|
|
1340
|
-
"City": { "source": "city", "required": false, "resolver": "sdk.trim" },
|
|
1341
|
-
"State": { "source": "state", "required": false, "resolver": "sdk.trim" },
|
|
1342
|
-
"Postcode": { "source": "postcode", "required": false, "resolver": "sdk.trim" },
|
|
1343
|
-
"Country": { "source": "country", "required": false, "resolver": "sdk.trim" }
|
|
1344
|
-
}
|
|
1345
|
-
},
|
|
1346
|
-
"Items": {
|
|
1347
|
-
"source": "items.edges[*].node",
|
|
1348
|
-
"isArray": true,
|
|
1349
|
-
"fields": {
|
|
1350
|
-
"Item": {
|
|
1351
|
-
"fields": {
|
|
1352
|
-
"@ref": {
|
|
1353
|
-
"source": "ref",
|
|
1354
|
-
"required": true,
|
|
1355
|
-
"resolver": "sdk.trim"
|
|
1356
|
-
},
|
|
1357
|
-
"ProductRef": {
|
|
1358
|
-
"source": "orderItem.productRef",
|
|
1359
|
-
"required": false,
|
|
1360
|
-
"resolver": "sdk.trim"
|
|
1361
|
-
},
|
|
1362
|
-
"ProductName": {
|
|
1363
|
-
"source": "orderItem.product.name",
|
|
1364
|
-
"required": false,
|
|
1365
|
-
"resolver": "sdk.trim"
|
|
1366
|
-
},
|
|
1367
|
-
"RequestedQuantity": {
|
|
1368
|
-
"source": "requestedQuantity",
|
|
1369
|
-
"required": false,
|
|
1370
|
-
"resolver": "sdk.parseInt"
|
|
1371
|
-
},
|
|
1372
|
-
"FilledQuantity": {
|
|
1373
|
-
"source": "filledQuantity",
|
|
1374
|
-
"required": true,
|
|
1375
|
-
"resolver": "sdk.parseInt"
|
|
1376
|
-
},
|
|
1377
|
-
"RejectedQuantity": {
|
|
1378
|
-
"source": "rejectedQuantity",
|
|
1379
|
-
"required": true,
|
|
1380
|
-
"resolver": "sdk.parseInt"
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
},
|
|
1386
|
-
"CreatedOn": {
|
|
1387
|
-
"source": "createdOn",
|
|
1388
|
-
"required": true,
|
|
1389
|
-
"resolver": "custom.formatISO8601"
|
|
1390
|
-
},
|
|
1391
|
-
"UpdatedOn": {
|
|
1392
|
-
"source": "updatedOn",
|
|
1393
|
-
"required": true,
|
|
1394
|
-
"resolver": "custom.formatISO8601"
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
```
|
|
1401
|
-
|
|
1402
|
-
### 6. Custom Resolvers (src/resolvers/fulfilment-resolvers.ts)
|
|
1403
|
-
|
|
1404
|
-
```typescript
|
|
1405
|
-
/**
|
|
1406
|
-
* Custom Resolvers for Fulfilment XML Mapping
|
|
1407
|
-
*
|
|
1408
|
-
* Handles complex transformations that SDK resolvers don't cover
|
|
1409
|
-
*/
|
|
1410
|
-
|
|
1411
|
-
export const customResolvers = {
|
|
1412
|
-
/**
|
|
1413
|
-
* Format ISO 8601 date string (ensures consistent format)
|
|
1414
|
-
*
|
|
1415
|
-
* Resolver signature: (value, sourceData, config, helpers) => any | Promise<any>
|
|
1416
|
-
*/
|
|
1417
|
-
'custom.formatISO8601': (
|
|
1418
|
-
value: any,
|
|
1419
|
-
sourceData: any,
|
|
1420
|
-
config: any,
|
|
1421
|
-
helpers: any
|
|
1422
|
-
): string => {
|
|
1423
|
-
if (!value) return '';
|
|
1424
|
-
|
|
1425
|
-
if (value instanceof Date) {
|
|
1426
|
-
return value.toISOString();
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
if (typeof value === 'string') {
|
|
1430
|
-
// If already ISO format, return as-is
|
|
1431
|
-
if (value.includes('T') && value.includes('Z')) {
|
|
1432
|
-
return value;
|
|
1433
|
-
}
|
|
1434
|
-
// Try to parse and format
|
|
1435
|
-
const date = new Date(value);
|
|
1436
|
-
if (!isNaN(date.getTime())) {
|
|
1437
|
-
return date.toISOString();
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
return String(value || '');
|
|
1442
|
-
},
|
|
1443
|
-
|
|
1444
|
-
/**
|
|
1445
|
-
* Format address line (handles missing fields gracefully)
|
|
1446
|
-
*/
|
|
1447
|
-
'custom.formatAddressLine': (address: any): string => {
|
|
1448
|
-
if (!address) return '';
|
|
1449
|
-
|
|
1450
|
-
const parts = [
|
|
1451
|
-
address.street1,
|
|
1452
|
-
address.street2,
|
|
1453
|
-
address.city,
|
|
1454
|
-
address.state,
|
|
1455
|
-
address.postcode,
|
|
1456
|
-
address.country,
|
|
1457
|
-
].filter(Boolean);
|
|
1458
|
-
|
|
1459
|
-
return parts.join(', ');
|
|
1460
|
-
},
|
|
1461
|
-
|
|
1462
|
-
/**
|
|
1463
|
-
* Format customer full name
|
|
1464
|
-
*/
|
|
1465
|
-
'custom.formatCustomerName': (customer: any): string => {
|
|
1466
|
-
if (!customer) return '';
|
|
1467
|
-
|
|
1468
|
-
const parts = [customer.firstName, customer.lastName].filter(Boolean);
|
|
1469
|
-
return parts.join(' ') || '';
|
|
1470
|
-
},
|
|
1471
|
-
};
|
|
1472
|
-
```
|
|
1473
|
-
|
|
1474
|
-
### 7. Type Definitions (src/types/fulfilment.types.ts)
|
|
1475
|
-
|
|
1476
|
-
```typescript
|
|
1477
|
-
/**
|
|
1478
|
-
* Type definitions for Rubix fulfilment webhooks and GraphQL responses
|
|
1479
|
-
*/
|
|
1480
|
-
|
|
1481
|
-
export interface RubixFulfilmentPayload {
|
|
1482
|
-
id: string;
|
|
1483
|
-
name: string;
|
|
1484
|
-
accountId: string;
|
|
1485
|
-
retailerId: string;
|
|
1486
|
-
entityRef: string;
|
|
1487
|
-
entityType: 'FULFILMENT';
|
|
1488
|
-
entityStatus?: string;
|
|
1489
|
-
type: 'NORMAL' | string;
|
|
1490
|
-
rootEntityId?: string;
|
|
1491
|
-
rootEntityType?: string;
|
|
1492
|
-
rootEntityRef?: string;
|
|
1493
|
-
attributes?: Record<string, any>;
|
|
1494
|
-
context?: Record<string, any>;
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
export interface FulfilmentData {
|
|
1498
|
-
id: string;
|
|
1499
|
-
ref: string;
|
|
1500
|
-
status: string;
|
|
1501
|
-
deliveryType: string;
|
|
1502
|
-
order?: {
|
|
1503
|
-
id: string;
|
|
1504
|
-
ref: string;
|
|
1505
|
-
customer?: {
|
|
1506
|
-
firstName: string;
|
|
1507
|
-
lastName: string;
|
|
1508
|
-
email: string;
|
|
1509
|
-
};
|
|
1510
|
-
};
|
|
1511
|
-
items?: {
|
|
1512
|
-
edges?: Array<{
|
|
1513
|
-
node: {
|
|
1514
|
-
id: string;
|
|
1515
|
-
ref: string;
|
|
1516
|
-
requestedQuantity?: number;
|
|
1517
|
-
filledQuantity: number;
|
|
1518
|
-
rejectedQuantity: number;
|
|
1519
|
-
orderItem?: {
|
|
1520
|
-
id: string;
|
|
1521
|
-
ref: string;
|
|
1522
|
-
productRef: string;
|
|
1523
|
-
product?: {
|
|
1524
|
-
name: string;
|
|
1525
|
-
};
|
|
1526
|
-
};
|
|
1527
|
-
};
|
|
1528
|
-
}>;
|
|
1529
|
-
};
|
|
1530
|
-
toAddress?: {
|
|
1531
|
-
name?: string;
|
|
1532
|
-
street?: string;
|
|
1533
|
-
street2?: string;
|
|
1534
|
-
city?: string;
|
|
1535
|
-
state?: string;
|
|
1536
|
-
postcode?: string;
|
|
1537
|
-
country?: string;
|
|
1538
|
-
};
|
|
1539
|
-
fromAddress?: {
|
|
1540
|
-
name?: string;
|
|
1541
|
-
street?: string;
|
|
1542
|
-
street2?: string;
|
|
1543
|
-
city?: string;
|
|
1544
|
-
state?: string;
|
|
1545
|
-
postcode?: string;
|
|
1546
|
-
country?: string;
|
|
1547
|
-
};
|
|
1548
|
-
createdOn: string;
|
|
1549
|
-
updatedOn: string;
|
|
1550
|
-
}
|
|
1551
|
-
```
|
|
1552
|
-
|
|
1553
|
-
### 8. Package Configuration (package.json)
|
|
1554
|
-
|
|
1555
|
-
```json
|
|
1556
|
-
{
|
|
1557
|
-
"name": "rubix-fulfilment-export",
|
|
1558
|
-
"version": "2.0.0",
|
|
1559
|
-
"description": "Rubix fulfilment webhook handler with SFTP XML export (UniversalMapper pattern)",
|
|
1560
|
-
"type": "module",
|
|
1561
|
-
"main": "index.ts",
|
|
1562
|
-
"scripts": {
|
|
1563
|
-
"dev": "versori dev",
|
|
1564
|
-
"build": "versori build",
|
|
1565
|
-
"deploy": "versori deploy",
|
|
1566
|
-
"test": "jest",
|
|
1567
|
-
"lint": "eslint src/**/*.ts"
|
|
1568
|
-
},
|
|
1569
|
-
"dependencies": {
|
|
1570
|
-
"@fluentcommerce/fc-connect-sdk": "^0.1.39",
|
|
1571
|
-
"@versori/run": "latest"
|
|
1572
|
-
},
|
|
1573
|
-
"devDependencies": {
|
|
1574
|
-
"@types/node": "^20.0.0",
|
|
1575
|
-
"typescript": "^5.0.0",
|
|
1576
|
-
"jest": "^29.0.0",
|
|
1577
|
-
"@types/jest": "^29.0.0",
|
|
1578
|
-
"eslint": "^8.0.0"
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
```
|
|
1582
|
-
|
|
1583
|
-
---
|
|
1584
|
-
|
|
1585
|
-
## Key Patterns Explained
|
|
1586
|
-
|
|
1587
|
-
### Pattern 1: External JSON Mapping Configuration
|
|
1588
|
-
|
|
1589
|
-
```typescript
|
|
1590
|
-
// ✅ CORRECT - External JSON mapping
|
|
1591
|
-
import mappingConfig from '../config/fulfilment-xml-mapping.json' with { type: 'json' };
|
|
1592
|
-
const mapper = new UniversalMapper(mappingConfig, { customResolvers });
|
|
1593
|
-
const result = await mapper.map(fulfilmentData);
|
|
1594
|
-
|
|
1595
|
-
// ❌ WRONG - Inline mapping (use inline template instead)
|
|
1596
|
-
const xmlData = {
|
|
1597
|
-
Fulfilment: {
|
|
1598
|
-
'@ref': fulfilmentData.ref,
|
|
1599
|
-
// ... 50+ lines of inline mapping
|
|
1600
|
-
}
|
|
1601
|
-
};
|
|
1602
|
-
```
|
|
1603
|
-
|
|
1604
|
-
**Why:** External JSON allows XML structure changes without code modifications, supports environment-specific configs, and enables independent testing.
|
|
1605
|
-
|
|
1606
|
-
### Pattern 2: Custom Resolvers for Complex Transformations
|
|
1607
|
-
|
|
1608
|
-
```typescript
|
|
1609
|
-
// ✅ CORRECT - Custom resolver for date formatting
|
|
1610
|
-
export const customResolvers = {
|
|
1611
|
-
'custom.formatISO8601': (value: string | Date | null | undefined): string => {
|
|
1612
|
-
if (value instanceof Date) return value.toISOString();
|
|
1613
|
-
// ... handle string dates
|
|
1614
|
-
},
|
|
1615
|
-
};
|
|
1616
|
-
|
|
1617
|
-
// In mapping config:
|
|
1618
|
-
{
|
|
1619
|
-
"CreatedOn": {
|
|
1620
|
-
"source": "createdOn",
|
|
1621
|
-
"resolver": "custom.formatISO8601"
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
// ❌ WRONG - Inline transformation logic
|
|
1626
|
-
const createdOn = new Date(fulfilmentData.createdOn).toISOString();
|
|
1627
|
-
```
|
|
1628
|
-
|
|
1629
|
-
**Why:** Custom resolvers are reusable, testable, and keep mapping config clean.
|
|
1630
|
-
|
|
1631
|
-
### Pattern 3: UniversalMapper Before XMLBuilder
|
|
1632
|
-
|
|
1633
|
-
```typescript
|
|
1634
|
-
// ✅ CORRECT - Transform first, then build XML
|
|
1635
|
-
const mapper = new UniversalMapper(mappingConfig, { customResolvers });
|
|
1636
|
-
const mappingResult = await mapper.map(fulfilmentData);
|
|
1637
|
-
const xmlString = xmlBuilder.build(mappingResult.data, 'FulfilmentExport');
|
|
1638
|
-
|
|
1639
|
-
// ❌ WRONG - Build XML directly from GraphQL data
|
|
1640
|
-
const xmlString = xmlBuilder.build(fulfilmentData, 'FulfilmentExport');
|
|
1641
|
-
```
|
|
1642
|
-
|
|
1643
|
-
**Why:** UniversalMapper handles transformations, validations, and field mapping before XML generation.
|
|
1644
|
-
|
|
1645
|
-
---
|
|
1646
|
-
|
|
1647
|
-
## Testing
|
|
1648
|
-
|
|
1649
|
-
### 1. Unit Tests
|
|
1650
|
-
|
|
1651
|
-
```typescript
|
|
1652
|
-
// src/services/__tests__/xml-export.test.ts
|
|
1653
|
-
import { exportFulfilmentToSFTP } from '../xml-export.service';
|
|
1654
|
-
import mappingConfig from '../../config/fulfilment-xml-mapping.json' with { type: 'json' };
|
|
1655
|
-
|
|
1656
|
-
describe('XML Export Service', () => {
|
|
1657
|
-
test('should transform fulfilment data with UniversalMapper', async () => {
|
|
1658
|
-
const mockFulfilmentData = {
|
|
1659
|
-
ref: 'FF-001',
|
|
1660
|
-
status: 'ALLOCATED',
|
|
1661
|
-
// ... test data
|
|
1662
|
-
};
|
|
1663
|
-
|
|
1664
|
-
// Verify mapping config is loaded
|
|
1665
|
-
expect(mappingConfig).toBeDefined();
|
|
1666
|
-
expect(mappingConfig.fields.Fulfilment).toBeDefined();
|
|
1667
|
-
});
|
|
1668
|
-
});
|
|
1669
|
-
```
|
|
1670
|
-
|
|
1671
|
-
### 2. Mapping Config Validation
|
|
1672
|
-
|
|
1673
|
-
```typescript
|
|
1674
|
-
// src/config/__tests__/mapping-config.test.ts
|
|
1675
|
-
import mappingConfig from '../fulfilment-xml-mapping.json' with { type: 'json' };
|
|
1676
|
-
|
|
1677
|
-
describe('Mapping Configuration', () => {
|
|
1678
|
-
test('should have valid structure', () => {
|
|
1679
|
-
expect(mappingConfig.name).toBe('fulfilment-xml-mapping');
|
|
1680
|
-
expect(mappingConfig.fields).toBeDefined();
|
|
1681
|
-
expect(mappingConfig.fields.Fulfilment).toBeDefined();
|
|
1682
|
-
});
|
|
1683
|
-
|
|
1684
|
-
test('should use custom resolvers for dates', () => {
|
|
1685
|
-
const createdOnField = mappingConfig.fields.Fulfilment.fields.CreatedOn;
|
|
1686
|
-
expect(createdOnField.resolver).toBe('custom.formatISO8601');
|
|
1687
|
-
});
|
|
1688
|
-
});
|
|
1689
|
-
```
|
|
1690
|
-
|
|
1691
|
-
---
|
|
1692
|
-
|
|
1693
|
-
## Production Checklist
|
|
1694
|
-
|
|
1695
|
-
- [ ] Configure `fluentPublicKey` activation variable
|
|
1696
|
-
- [ ] Configure Fluent Commerce connection in Versori
|
|
1697
|
-
- [ ] Configure `sftp_export_server` connection in Versori (Basic Auth with username/password)
|
|
1698
|
-
- [ ] Set SFTP activation variables (host, port, remotePath)
|
|
1699
|
-
- [ ] Verify SFTP remote path exists and is writable
|
|
1700
|
-
- [ ] Create Rubix workflow with SendWebhook action (FULFILMENT events)
|
|
1701
|
-
- [ ] Build Event payload with entityRef, entityType, retailerId
|
|
1702
|
-
- [ ] **Review and customize `config/fulfilment-xml-mapping.json`** for your 3PL schema
|
|
1703
|
-
- [ ] **Add custom resolvers** if needed for complex transformations
|
|
1704
|
-
- [ ] Test webhook signature validation
|
|
1705
|
-
- [ ] Test GraphQL query with real fulfilment ref
|
|
1706
|
-
- [ ] **Test UniversalMapper transformation** with sample data
|
|
1707
|
-
- [ ] **Test with large fulfilment (>100 items)** - Verify pagination works correctly
|
|
1708
|
-
- [ ] Test XML generation with special characters
|
|
1709
|
-
- [ ] Test SFTP upload and verify file on server
|
|
1710
|
-
- [ ] Test error scenarios (invalid signature, missing retailerId, SFTP failure)
|
|
1711
|
-
- [ ] Monitor response times (<100ms for validation)
|
|
1712
|
-
- [ ] Set up alerts for webhook/export failures
|
|
1713
|
-
- [ ] Document 3PL partner SFTP requirements
|
|
1714
|
-
- [ ] Test SFTP connection cleanup (check logs for dispose)
|
|
1715
|
-
- [ ] Verify pagination logs show correct item counts
|
|
1716
|
-
- [ ] **Version control mapping config** (track changes to XML structure)
|
|
1717
|
-
|
|
1718
|
-
---
|
|
1719
|
-
|
|
1720
|
-
## Troubleshooting Guide
|
|
1721
|
-
|
|
1722
|
-
| Issue | Cause | Solution |
|
|
1723
|
-
|-------|-------|----------|
|
|
1724
|
-
| "Invalid webhook signature" | Wrong public key | Verify fluentPublicKey matches Fluent environment |
|
|
1725
|
-
| "Missing retailerId" | Rubix payload incomplete | Add retailerId to Rubix Event payload builder |
|
|
1726
|
-
| "Fulfilment not found" | Invalid ref or permissions | Verify fulfilment exists and user has query permissions |
|
|
1727
|
-
| "Mapping failed" | Invalid mapping config | Validate JSON syntax and field paths in mapping config |
|
|
1728
|
-
| "Custom resolver not found" | Resolver not registered | Ensure customResolvers object includes all resolvers used in mapping |
|
|
1729
|
-
| "SFTP upload failed" | Connection/credentials | Test SFTP manually, verify credentials in connection and path |
|
|
1730
|
-
| "Failed to retrieve SFTP credentials" | Connection not configured | Ensure `sftp_export_server` connection exists with Basic Auth |
|
|
1731
|
-
| "SFTP connection pool exhausted" | Missing dispose() | Verify dispose() is in finally block |
|
|
1732
|
-
| "GraphQL query timeout" | Large dataset | Check pagination logs - pagination handles up to 1000 items |
|
|
1733
|
-
| "Missing items in XML" | Fulfilment >1000 items | Increase maxPages limit or implement chunked export |
|
|
1734
|
-
| "XML structure mismatch" | Mapping config outdated | Update `config/fulfilment-xml-mapping.json` to match 3PL schema |
|
|
1735
|
-
|
|
1736
|
-
---
|
|
1737
|
-
|
|
1738
|
-
## Monitoring & Alerting
|
|
1739
|
-
|
|
1740
|
-
### Success Response
|
|
1741
|
-
|
|
1742
|
-
```json
|
|
1743
|
-
{
|
|
1744
|
-
"success": true,
|
|
1745
|
-
"entityType": "FULFILMENT",
|
|
1746
|
-
"fulfilmentRef": "FF-001",
|
|
1747
|
-
"message": "Webhook validated and export started in background",
|
|
1748
|
-
"timestamp": "2025-01-25T14:30:00.000Z",
|
|
1749
|
-
"correlationId": "act_123",
|
|
1750
|
-
"processingMode": "async"
|
|
1751
|
-
}
|
|
1752
|
-
```
|
|
1753
|
-
|
|
1754
|
-
### Key Metrics
|
|
1755
|
-
|
|
1756
|
-
```typescript
|
|
1757
|
-
const METRICS = {
|
|
1758
|
-
signatureValidationMs: 45,
|
|
1759
|
-
totalResponseTimeMs: 50,
|
|
1760
|
-
graphqlQueryMs: 1200,
|
|
1761
|
-
universalMapperMs: 150,
|
|
1762
|
-
xmlGenerationMs: 50,
|
|
1763
|
-
sftpUploadMs: 980,
|
|
1764
|
-
totalBackgroundMs: 2380,
|
|
1765
|
-
};
|
|
1766
|
-
```
|
|
1767
|
-
|
|
1768
|
-
---
|
|
1769
|
-
|
|
1770
|
-
## Related Documentation
|
|
1771
|
-
|
|
1772
|
-
- [Inline Mapping Template](./template-webhook-rubix-fulfilment-to-sftp-xml-inline.md) - For simple XML structures
|
|
1773
|
-
- [Order Attribute Update Template](./template-webhook-rubix-order-attribute-update.md) - For ORDER webhooks
|
|
1774
|
-
- [Webhook Validation Guide](../../../../02-CORE-GUIDES/webhook-validation/)
|
|
1775
|
-
- [UniversalMapper Guide](../../../../02-CORE-GUIDES/mapping/universal-mapper.md)
|
|
1776
|
-
- [Versori Platform Guide](../../../../04-REFERENCE/platforms/versori/)
|
|
1777
|
-
- [SFTP Data Sources Guide](../../../../02-CORE-GUIDES/data-sources/)
|
|
1778
|
-
|
|
1779
|
-
---
|
|
1780
|
-
|
|
1781
|
-
**Pattern**: Fulfilment webhook → GraphQL query → UniversalMapper transformation → XML generation → SFTP upload
|
|
1782
|
-
**✅ Production-Ready**: Comprehensive template with external mapping, custom resolvers, and all critical fixes applied
|
|
1783
|
-
**Key Learning**: External JSON mapping enables XML structure changes without code modifications, custom resolvers handle complex transformations
|
|
1784
|
-
**Critical**: SFTP dispose() in finally block, retailerId validation, fire-and-forget pattern, UniversalMapper before XMLBuilder
|
|
1785
|
-
|
|
1
|
+
---
|
|
2
|
+
template_id: tpl-webhook-rubix-fulfilment-export-universal-mapper
|
|
3
|
+
canonical_filename: template-webhook-rubix-fulfilment-to-sftp-xml-universal-mapper.md
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
sdk_version: ^0.1.39
|
|
6
|
+
runtime: versori
|
|
7
|
+
direction: webhook
|
|
8
|
+
source: fluent-rubix-workflow
|
|
9
|
+
destination: sftp-xml
|
|
10
|
+
entity: fulfilment
|
|
11
|
+
format: xml
|
|
12
|
+
logging: versori
|
|
13
|
+
status: stable
|
|
14
|
+
pattern: universal-mapper
|
|
15
|
+
features:
|
|
16
|
+
- webhook-validation
|
|
17
|
+
- fire-and-forget
|
|
18
|
+
- background-processing
|
|
19
|
+
- xml-export
|
|
20
|
+
- sftp-integration
|
|
21
|
+
- graphql-queries
|
|
22
|
+
- universal-mapper
|
|
23
|
+
- external-mapping
|
|
24
|
+
- custom-resolvers
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
# Template: Rubix Fulfilment Webhook → SFTP XML Export (UniversalMapper Pattern)
|
|
28
|
+
|
|
29
|
+
**Template Version:** 2.0.0
|
|
30
|
+
**SDK Version:** `^0.1.39` - `npm install @fluentcommerce/fc-connect-sdk@^0.1.39`
|
|
31
|
+
**Last Updated:** 2025-01-25
|
|
32
|
+
**Deployment Target:** Versori Platform
|
|
33
|
+
**Mapping Pattern:** 🟢 **UNIVERSALMAPPER** (External JSON mapping + Custom resolvers)
|
|
34
|
+
|
|
35
|
+
> **📖 Pattern Selection Guide:**
|
|
36
|
+
> - **Use THIS template (UniversalMapper)** for: Reusable configs, multi-environment deployments, complex transformations, external mapping management
|
|
37
|
+
> - **Use Inline version** for: Simple webhooks, tightly-coupled 3PL schemas, fast debugging
|
|
38
|
+
> - **See also:** [template-webhook-rubix-fulfilment-to-sftp-xml-inline.md](./template-webhook-rubix-fulfilment-to-sftp-xml-inline.md)
|
|
39
|
+
|
|
40
|
+
**🆕 Version 2.0.0 - Production Ready:**
|
|
41
|
+
- ✅ **Fulfilment-specific template** - Focused on 3PL/WMS integration
|
|
42
|
+
- ✅ **Production-ready modular structure** - Separate workflows, services, config, resolvers, types
|
|
43
|
+
- ✅ **GraphQL fulfilment queries** - Fetch fulfilment + line items + order details
|
|
44
|
+
- ✅ **Automatic pagination** - Handles fulfilments with 100+ items (up to 1000)
|
|
45
|
+
- ✅ **External JSON mapping** - `config/fulfilment-xml-mapping.json` for XML structure
|
|
46
|
+
- ✅ **UniversalMapper** - Transforms GraphQL data to XML structure with custom resolvers
|
|
47
|
+
- ✅ **Custom resolvers** - Handle complex transformations (date formatting, nested data)
|
|
48
|
+
- ✅ **XML generation** - Safe XML with automatic escaping via XMLBuilder
|
|
49
|
+
- ✅ **SFTP upload** - Connection pooling with proper dispose()
|
|
50
|
+
- ✅ **Critical fixes applied** - retailerId validation, SFTP options parameter, pagination
|
|
51
|
+
- ✅ **Comprehensive documentation** - Testing, troubleshooting, monitoring
|
|
52
|
+
|
|
53
|
+
**When to Use This Pattern:**
|
|
54
|
+
- ✅ Complex XML structures (>20 fields)
|
|
55
|
+
- ✅ XML structure changes frequently
|
|
56
|
+
- ✅ Need environment-specific configurations
|
|
57
|
+
- ✅ Multi-environment deployments (dev/staging/prod)
|
|
58
|
+
- ✅ Reusable mapping configurations
|
|
59
|
+
- ✅ Complex transformations requiring custom resolvers
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Overview
|
|
64
|
+
|
|
65
|
+
Receive fulfilment webhooks from Rubix workflows, query fulfilment details, transform with UniversalMapper, generate XML, and upload to 3PL/WMS SFTP server.
|
|
66
|
+
|
|
67
|
+
**Pattern:**
|
|
68
|
+
1. Validate webhook signature (~10-50ms)
|
|
69
|
+
2. Return HTTP 200 OK immediately (fast acknowledgment)
|
|
70
|
+
3. Background: Query fulfilment details → UniversalMapper transformation → Generate XML → Upload to SFTP (~2-5s)
|
|
71
|
+
|
|
72
|
+
**Business Use Case:**
|
|
73
|
+
- Rubix workflow sends webhook when fulfilment is created/updated
|
|
74
|
+
- Handler queries fulfilment details (items, order, addresses)
|
|
75
|
+
- UniversalMapper transforms GraphQL data using external JSON mapping
|
|
76
|
+
- Custom resolvers handle complex transformations (dates, addresses, names)
|
|
77
|
+
- Generates XML fulfillment notification for 3PL/WMS
|
|
78
|
+
- Uploads to partner SFTP server for warehouse processing
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## STEP 1: Understand This Template
|
|
83
|
+
|
|
84
|
+
### What This Template Does
|
|
85
|
+
|
|
86
|
+
**Core Functionality:**
|
|
87
|
+
- Receives FULFILMENT webhooks from Fluent Commerce Rubix workflows
|
|
88
|
+
- Validates webhook signature for security
|
|
89
|
+
- Returns fast HTTP 200 OK response (<100ms)
|
|
90
|
+
- Background: Queries fulfilment via GraphQL → UniversalMapper transformation → XML generation → Uploads to SFTP
|
|
91
|
+
|
|
92
|
+
**Key SDK Components:**
|
|
93
|
+
- `WebhookValidationService` - Signature validation with RSA/HMAC support
|
|
94
|
+
- `createClient()` - Universal client factory (auto-detects Versori context)
|
|
95
|
+
- `client.graphql()` - Query fulfilment details with automatic pagination
|
|
96
|
+
- `UniversalMapper` - Transform GraphQL data to XML structure using external JSON mapping
|
|
97
|
+
- `XMLBuilder` - Safe XML generation with automatic escaping (after UniversalMapper)
|
|
98
|
+
- `SftpDataSource` - SFTP operations with connection pooling
|
|
99
|
+
- `ctx.credentials().getAccessToken()` - Retrieve SFTP credentials from Versori connection vault
|
|
100
|
+
- Native Versori `log` - Structured logging from context
|
|
101
|
+
|
|
102
|
+
**Pagination Support:**
|
|
103
|
+
- Automatically handles fulfilments with 100+ line items
|
|
104
|
+
- Uses two-query pattern: fulfilment details + paginated items
|
|
105
|
+
- SDK auto-pagination: `pagination: { maxPages: 10 }` supports up to 1000 items
|
|
106
|
+
- Logs pagination usage for monitoring
|
|
107
|
+
|
|
108
|
+
**Critical Patterns:**
|
|
109
|
+
- **Sync + Fire-and-Forget**: Fast validation, background processing
|
|
110
|
+
- **Signature Validation**: Always validate `fluent-signature` or `flex.signature` headers
|
|
111
|
+
- **Background Promises**: Use `.then().catch()` for error handling
|
|
112
|
+
- **SFTP Credentials**: Retrieve from Versori connection vault (not activation variables)
|
|
113
|
+
- **SFTP Cleanup**: Always call `dispose()` in finally blocks
|
|
114
|
+
- **RetailerId Validation**: Check before `setRetailerId()` to prevent 401 errors
|
|
115
|
+
- **External Mapping**: XML structure defined in JSON config file (not inline)
|
|
116
|
+
- **Custom Resolvers**: Complex transformations separated into resolver functions
|
|
117
|
+
|
|
118
|
+
### When to Use This Template
|
|
119
|
+
|
|
120
|
+
✅ **USE THIS TEMPLATE FOR:**
|
|
121
|
+
- Fulfilment created/updated webhooks from Rubix workflows
|
|
122
|
+
- Export fulfilment details to 3PL/WMS via SFTP
|
|
123
|
+
- Need XML format for warehouse management systems
|
|
124
|
+
- Require signature validation for security
|
|
125
|
+
- Need fast webhook acknowledgment + async processing
|
|
126
|
+
- **Complex XML structures** requiring external configuration
|
|
127
|
+
- **Multi-environment deployments** with different XML schemas
|
|
128
|
+
- **Frequent XML structure changes** without code modifications
|
|
129
|
+
|
|
130
|
+
❌ **DON'T USE FOR:**
|
|
131
|
+
- Order webhooks (use order attribute update template)
|
|
132
|
+
- Inventory webhooks (use inventory templates)
|
|
133
|
+
- CSV/JSON exports (use format-specific templates)
|
|
134
|
+
- Synchronous processing required (use standard http workflow)
|
|
135
|
+
- **Simple XML structures** (<20 fields) - use inline mapping template instead
|
|
136
|
+
|
|
137
|
+
### Business Use Cases
|
|
138
|
+
|
|
139
|
+
**Use Case: 3PL Warehouse Fulfillment Notification**
|
|
140
|
+
- Rubix workflow sends webhook when fulfilment moves to "ALLOCATED" status
|
|
141
|
+
- Handler queries fulfilment details (items, quantities, order info)
|
|
142
|
+
- UniversalMapper transforms data using external JSON mapping config
|
|
143
|
+
- Custom resolvers format dates, addresses, and customer names
|
|
144
|
+
- Generates XML fulfillment order for warehouse system
|
|
145
|
+
- Uploads to 3PL SFTP server for pick/pack/ship processing
|
|
146
|
+
- 3PL system imports XML and creates warehouse tasks
|
|
147
|
+
|
|
148
|
+
**Why UniversalMapper Pattern:**
|
|
149
|
+
- XML structure can be updated without code changes (edit JSON config)
|
|
150
|
+
- Different XML schemas per environment (dev/staging/prod configs)
|
|
151
|
+
- Complex transformations handled by reusable custom resolvers
|
|
152
|
+
- Mapping configuration can be versioned and tested independently
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## STEP 2: Implementation Prompt for Claude Code
|
|
157
|
+
|
|
158
|
+
**Copy this prompt and send to Claude Code to generate the complete implementation:**
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
Create a Versori webhook handler for Fluent Commerce Rubix FULFILMENT events with signature validation, GraphQL queries, UniversalMapper transformation, XML generation, and SFTP upload.
|
|
162
|
+
|
|
163
|
+
REQUIREMENTS:
|
|
164
|
+
1. Runtime: Versori Platform (HTTP webhook)
|
|
165
|
+
2. Source: Rubix SendWebhook action (FULFILMENT entity type only)
|
|
166
|
+
3. Destination: SFTP XML export to 3PL/WMS partner
|
|
167
|
+
4. Format: XML with fulfilment details, line items, order info
|
|
168
|
+
5. Entity: FULFILMENT
|
|
169
|
+
|
|
170
|
+
KEY FEATURES:
|
|
171
|
+
- Webhook signature validation using WebhookValidationService
|
|
172
|
+
- Sync mode + fire-and-forget pattern for fast response
|
|
173
|
+
- Background processing: GraphQL query → UniversalMapper transformation → XML generation → SFTP upload
|
|
174
|
+
- **Automatic pagination** - Handles fulfilments with 100+ items (up to 1000 items)
|
|
175
|
+
- Two-query pattern: Fulfilment details + paginated items query
|
|
176
|
+
- **External JSON mapping** - `config/fulfilment-xml-mapping.json` for XML structure
|
|
177
|
+
- **UniversalMapper** - Transforms GraphQL data to XML structure with custom resolvers
|
|
178
|
+
- **Custom resolvers** - Handle complex transformations (date formatting, nested data)
|
|
179
|
+
- Modular architecture (workflows/, services/, config/, resolvers/, types/)
|
|
180
|
+
- Native Versori logging (no LoggingService)
|
|
181
|
+
- SFTP cleanup with dispose() in finally blocks
|
|
182
|
+
- Comprehensive error handling with SDK error types
|
|
183
|
+
- RetailerId validation before setRetailerId()
|
|
184
|
+
|
|
185
|
+
CRITICAL REQUIREMENTS:
|
|
186
|
+
1. Webhook Mode: response: { mode: 'sync' }
|
|
187
|
+
2. Signature Validation: WebhookValidationService with strictValidation: true
|
|
188
|
+
3. RetailerId Validation: Check exists before client.setRetailerId()
|
|
189
|
+
4. Background Processing: Fire-and-forget pattern (no await on background promise)
|
|
190
|
+
5. GraphQL Queries: Two separate queries (fulfilment + items with pagination)
|
|
191
|
+
6. Pagination: Use SDK automatic pagination with maxPages: 10, first: 100
|
|
192
|
+
7. **External Mapping**: Use `config/fulfilment-xml-mapping.json` (NOT inline mapping)
|
|
193
|
+
8. **UniversalMapper**: Transform GraphQL data to XML structure using mapping config
|
|
194
|
+
9. **Custom Resolvers**: Use resolvers/fulfilment-resolvers.ts for complex transformations
|
|
195
|
+
10. XML Generation: Use XMLBuilder with automatic escaping (after UniversalMapper)
|
|
196
|
+
11. SFTP Upload: Include options parameter { overwrite: true, createDirectories: true }
|
|
197
|
+
12. SFTP Cleanup: Always dispose() in finally block
|
|
198
|
+
13. Error Handling: Import and handle DataSourceError, AuthenticationError, GraphQLError
|
|
199
|
+
14. Type Safety: Use Logger, VersoriContext types (not any)
|
|
200
|
+
|
|
201
|
+
SDK METHODS TO USE:
|
|
202
|
+
- import { Buffer } from 'node:buffer' (CRITICAL for Versori/Deno)
|
|
203
|
+
- createClient({ ...ctx, log })
|
|
204
|
+
- await client.setRetailerId(retailerId) (with validation first!)
|
|
205
|
+
- new WebhookValidationService({ strictValidation: true }, log)
|
|
206
|
+
- await validator.validateWebhook(rawBody, headers, publicKey)
|
|
207
|
+
- await client.graphql({ query, variables, pagination: { maxPages: 10 } })
|
|
208
|
+
- import mappingConfig from '../config/fulfilment-xml-mapping.json' with { type: 'json' }
|
|
209
|
+
- new UniversalMapper(mappingConfig, { customResolvers })
|
|
210
|
+
- await mapper.map(fulfilmentData) - Transform GraphQL data to XML structure
|
|
211
|
+
- new XMLBuilder({ prettyPrint: true, xmlDeclaration: true, encoding: 'UTF-8' })
|
|
212
|
+
- xmlBuilder.build(mappedData, 'FulfilmentExport')
|
|
213
|
+
- await ctx.credentials().getAccessToken('sftp_export_server') - Retrieve SFTP credentials from connection vault
|
|
214
|
+
- Buffer.from(accessToken, 'base64').toString('utf-8') - Decode Basic Auth credentials
|
|
215
|
+
- new SftpDataSource(config, log) - config includes connectionId: 'sftp_export_server'
|
|
216
|
+
- await sftp.uploadFile(remotePath, buffer, { overwrite: true, createDirectories: true })
|
|
217
|
+
- await sftp.dispose() (CRITICAL in finally block)
|
|
218
|
+
|
|
219
|
+
FORBIDDEN PATTERNS:
|
|
220
|
+
- ❌ LoggingService (use native log from context)
|
|
221
|
+
- ❌ await on background processing (use fire-and-forget)
|
|
222
|
+
- ❌ Inline mapping config (use external JSON file)
|
|
223
|
+
- ❌ Manual object construction for XML (use UniversalMapper)
|
|
224
|
+
- ❌ Missing dispose() for SFTP
|
|
225
|
+
- ❌ Missing options parameter in uploadFile()
|
|
226
|
+
- ❌ Missing retailerId validation before setRetailerId()
|
|
227
|
+
- ❌ Storing SFTP credentials in activation variables (use Versori connection vault)
|
|
228
|
+
- ❌ Using 'any' type (use Logger, VersoriContext from SDK)
|
|
229
|
+
- ❌ Direct FluentClient instantiation (use createClient factory)
|
|
230
|
+
- ❌ Generic error handling (use SDK error types)
|
|
231
|
+
|
|
232
|
+
GRAPHQL QUERY STRUCTURE:
|
|
233
|
+
|
|
234
|
+
**Single Query with Nested Items (Schema-Validated)**
|
|
235
|
+
```graphql
|
|
236
|
+
query GetFulfilment($id: ID!, $first: Int!, $after: String) {
|
|
237
|
+
fulfilment(id: $id) {
|
|
238
|
+
id
|
|
239
|
+
ref
|
|
240
|
+
status
|
|
241
|
+
deliveryType
|
|
242
|
+
order {
|
|
243
|
+
id
|
|
244
|
+
ref
|
|
245
|
+
customer { firstName, lastName, email }
|
|
246
|
+
}
|
|
247
|
+
toAddress {
|
|
248
|
+
name, street, street2, city, state, postcode, country
|
|
249
|
+
}
|
|
250
|
+
fromAddress {
|
|
251
|
+
name, street, street2, city, state, postcode, country
|
|
252
|
+
}
|
|
253
|
+
items(first: $first, after: $after) {
|
|
254
|
+
edges {
|
|
255
|
+
node {
|
|
256
|
+
id
|
|
257
|
+
ref
|
|
258
|
+
requestedQuantity
|
|
259
|
+
filledQuantity
|
|
260
|
+
rejectedQuantity
|
|
261
|
+
orderItem {
|
|
262
|
+
id
|
|
263
|
+
ref
|
|
264
|
+
productRef
|
|
265
|
+
product { name }
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
cursor
|
|
269
|
+
}
|
|
270
|
+
pageInfo {
|
|
271
|
+
hasNextPage
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
createdOn
|
|
275
|
+
updatedOn
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Why Single Query?**
|
|
281
|
+
- Items are nested under the fulfilment type in Fluent Commerce schema
|
|
282
|
+
- Single query with `connectionPath: 'fulfilment.items'` for SDK pagination
|
|
283
|
+
- SDK automatically handles pagination with `pagination: { maxPages: 10 }` config
|
|
284
|
+
- More efficient than two separate queries (reduces GraphQL roundtrips)
|
|
285
|
+
|
|
286
|
+
XML OUTPUT STRUCTURE:
|
|
287
|
+
<FulfilmentExport>
|
|
288
|
+
<Fulfilment ref="FF-001" status="ALLOCATED">
|
|
289
|
+
<OrderRef>ORD-123</OrderRef>
|
|
290
|
+
<DeliveryType>STANDARD</DeliveryType>
|
|
291
|
+
<Customer>
|
|
292
|
+
<FirstName>John</FirstName>
|
|
293
|
+
<LastName>Smith</LastName>
|
|
294
|
+
<Email>john@example.com</Email>
|
|
295
|
+
</Customer>
|
|
296
|
+
<ToAddress>
|
|
297
|
+
<Name>John Smith</Name>
|
|
298
|
+
<Street>123 Main St</Street>
|
|
299
|
+
<City>New York</City>
|
|
300
|
+
<State>NY</State>
|
|
301
|
+
<Postcode>10001</Postcode>
|
|
302
|
+
<Country>US</Country>
|
|
303
|
+
</ToAddress>
|
|
304
|
+
<FromAddress>
|
|
305
|
+
<Name>Warehouse</Name>
|
|
306
|
+
<Street>456 Warehouse St</Street>
|
|
307
|
+
<City>Chicago</City>
|
|
308
|
+
<State>IL</State>
|
|
309
|
+
<Postcode>60601</Postcode>
|
|
310
|
+
<Country>US</Country>
|
|
311
|
+
</FromAddress>
|
|
312
|
+
<Items>
|
|
313
|
+
<Item ref="FFI-001">
|
|
314
|
+
<ProductRef>SKU-001</ProductRef>
|
|
315
|
+
<ProductName>Widget</ProductName>
|
|
316
|
+
<RequestedQuantity>2</RequestedQuantity>
|
|
317
|
+
<FilledQuantity>2</FilledQuantity>
|
|
318
|
+
<RejectedQuantity>0</RejectedQuantity>
|
|
319
|
+
</Item>
|
|
320
|
+
</Items>
|
|
321
|
+
<CreatedOn>2025-01-25T10:00:00Z</CreatedOn>
|
|
322
|
+
<UpdatedOn>2025-01-25T11:00:00Z</UpdatedOn>
|
|
323
|
+
</Fulfilment>
|
|
324
|
+
</FulfilmentExport>
|
|
325
|
+
|
|
326
|
+
GENERATE:
|
|
327
|
+
1. package.json with dependencies
|
|
328
|
+
2. index.ts (entry point - exports workflow)
|
|
329
|
+
3. src/workflows/webhook/fulfilment-export-handler.ts (webhook entry)
|
|
330
|
+
4. src/services/fulfilment-query.service.ts (GraphQL queries)
|
|
331
|
+
5. src/services/xml-export.service.ts (UniversalMapper + XMLBuilder + SFTP upload)
|
|
332
|
+
6. src/resolvers/fulfilment-resolvers.ts (Custom resolvers for XML transformations)
|
|
333
|
+
7. src/config/fulfilment-xml-mapping.json (External JSON mapping configuration)
|
|
334
|
+
8. src/types/fulfilment.types.ts (TypeScript interfaces)
|
|
335
|
+
9. readme.md with setup instructions
|
|
336
|
+
|
|
337
|
+
Ensure all code is production-ready with proper error handling, signature validation, SFTP cleanup, UniversalMapper transformation, external JSON mapping, custom resolvers, and type safety.
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## STEP 3: Detailed Flow Documentation
|
|
343
|
+
|
|
344
|
+
### Complete Processing Flow
|
|
345
|
+
|
|
346
|
+
```
|
|
347
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
348
|
+
│ 1. RUBIX WEBHOOK RECEIVED │
|
|
349
|
+
│ POST https://{workspace}.versori.run/rubix-fulfilment │
|
|
350
|
+
│ Headers: fluent-signature │
|
|
351
|
+
│ Body: { entityRef: "FF-001", entityType: "FULFILMENT" } │
|
|
352
|
+
└────────────────────┬────────────────────────────────────────┘
|
|
353
|
+
│
|
|
354
|
+
▼
|
|
355
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
356
|
+
│ 2. SIGNATURE VALIDATION (Synchronous, ~10-50ms) │
|
|
357
|
+
│ - Extract rawBody and headers │
|
|
358
|
+
│ - Get fluentPublicKey from activation │
|
|
359
|
+
│ - WebhookValidationService.validateWebhook() │
|
|
360
|
+
│ - Return 400 if invalid │
|
|
361
|
+
└────────────────────┬────────────────────────────────────────┘
|
|
362
|
+
│
|
|
363
|
+
▼
|
|
364
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
365
|
+
│ 3. PAYLOAD VALIDATION (Synchronous, ~5ms) │
|
|
366
|
+
│ - Check entityRef exists │
|
|
367
|
+
│ - Check entityType === 'FULFILMENT' │
|
|
368
|
+
│ - Check retailerId exists │
|
|
369
|
+
│ - Return 400 if missing required fields │
|
|
370
|
+
└────────────────────┬────────────────────────────────────────┘
|
|
371
|
+
│
|
|
372
|
+
▼
|
|
373
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
374
|
+
│ 4. HTTP 200 OK RESPONSE (Total: ~50ms) │
|
|
375
|
+
│ - Return success immediately │
|
|
376
|
+
│ - Background promise continues (fire-and-forget) │
|
|
377
|
+
└────────────────────┬────────────────────────────────────────┘
|
|
378
|
+
│
|
|
379
|
+
▼ (Background - doesn't block response)
|
|
380
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
381
|
+
│ 5. BACKGROUND PROCESSING (~2-5 seconds) │
|
|
382
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
383
|
+
│ │ 5a. Initialize Fluent Client (~100ms) │ │
|
|
384
|
+
│ │ - createClient({ ...ctx, log }) │ │
|
|
385
|
+
│ │ - Validate retailerId exists │ │
|
|
386
|
+
│ │ - client.setRetailerId(retailerId) │ │
|
|
387
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
388
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
389
|
+
│ │ 5b. Query Fulfilment Details (~500-1500ms) │ │
|
|
390
|
+
│ │ - GraphQL query with nested fields │ │
|
|
391
|
+
│ │ - Fulfilment + items + order + addresses │ │
|
|
392
|
+
│ │ - Handle GraphQLError if query fails │ │
|
|
393
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
394
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
395
|
+
│ │ 5c. Transform with UniversalMapper (~100-200ms) │ │
|
|
396
|
+
│ │ - Load mapping config from JSON │ │
|
|
397
|
+
│ │ - Apply SDK resolvers (trim, uppercase) │ │
|
|
398
|
+
│ │ - Apply custom resolvers (date formatting) │ │
|
|
399
|
+
│ │ - Transform GraphQL data to XML structure │ │
|
|
400
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
401
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
402
|
+
│ │ 5d. Generate XML (~50ms) │ │
|
|
403
|
+
│ │ - XMLBuilder with mapped data │ │
|
|
404
|
+
│ │ - XMLBuilder handles escaping automatically │ │
|
|
405
|
+
│ │ - Create Buffer from XML string │ │
|
|
406
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
407
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
408
|
+
│ │ 5e. Upload to SFTP (~500-2000ms) │ │
|
|
409
|
+
│ │ - Initialize SftpDataSource │ │
|
|
410
|
+
│ │ - Upload with options parameter │ │
|
|
411
|
+
│ │ - Handle DataSourceError if upload fails │ │
|
|
412
|
+
│ │ - ALWAYS dispose() in finally block │ │
|
|
413
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
414
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
415
|
+
│ │ 5f. Log Completion │ │
|
|
416
|
+
│ │ - Success: Log fulfilment ref and duration │ │
|
|
417
|
+
│ │ - Failure: Log error with category │ │
|
|
418
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
419
|
+
└─────────────────────────────────────────────────────────────┘
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Response Timing
|
|
423
|
+
|
|
424
|
+
| Stage | Timing | Blocking |
|
|
425
|
+
|-------|--------|----------|
|
|
426
|
+
| **Signature Validation** | ~10-50ms | ✅ Yes (blocks response) |
|
|
427
|
+
| **Payload Validation** | ~5ms | ✅ Yes (blocks response) |
|
|
428
|
+
| **HTTP 200 Response** | ~50-100ms | ✅ Fast acknowledgment |
|
|
429
|
+
| **GraphQL Query** | ~500-1500ms | ❌ No (background) |
|
|
430
|
+
| **UniversalMapper Transformation** | ~100-200ms | ❌ No (background) |
|
|
431
|
+
| **XML Generation** | ~50ms | ❌ No (background) |
|
|
432
|
+
| **SFTP Upload** | ~500-2000ms | ❌ No (background) |
|
|
433
|
+
| **Total Background** | ~2000-5000ms | ❌ Fire-and-forget |
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## STEP 4: Production Modular Structure
|
|
438
|
+
|
|
439
|
+
### Complete Project Structure
|
|
440
|
+
|
|
441
|
+
```
|
|
442
|
+
rubix-fulfilment-export/
|
|
443
|
+
├── package.json # Dependencies and Versori config
|
|
444
|
+
├── tsconfig.json # TypeScript configuration
|
|
445
|
+
├── readme.md # Setup and deployment instructions
|
|
446
|
+
├── index.ts # Entry point - exports workflow
|
|
447
|
+
└── src/
|
|
448
|
+
├── workflows/
|
|
449
|
+
│ └── webhook/
|
|
450
|
+
│ └── fulfilment-export-handler.ts # Webhook entry point
|
|
451
|
+
│
|
|
452
|
+
├── services/
|
|
453
|
+
│ ├── fulfilment-query.service.ts # GraphQL queries
|
|
454
|
+
│ └── xml-export.service.ts # UniversalMapper + XMLBuilder + SFTP upload
|
|
455
|
+
│
|
|
456
|
+
├── resolvers/
|
|
457
|
+
│ └── fulfilment-resolvers.ts # Custom resolvers for XML transformations
|
|
458
|
+
│
|
|
459
|
+
├── config/
|
|
460
|
+
│ └── fulfilment-xml-mapping.json # External JSON mapping configuration
|
|
461
|
+
│
|
|
462
|
+
└── types/
|
|
463
|
+
└── fulfilment.types.ts # TypeScript interfaces
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
**Why This Structure?**
|
|
467
|
+
- ✅ **Clear separation**: Webhook handlers vs business logic
|
|
468
|
+
- ✅ **Reusable services**: Query and export logic can be unit tested
|
|
469
|
+
- ✅ **External config**: XML mapping changes don't require code changes
|
|
470
|
+
- ✅ **Custom resolvers**: Complex transformations separated from mapping config
|
|
471
|
+
- ✅ **Type safety**: TypeScript interfaces for better IDE support
|
|
472
|
+
- ✅ **Scalable**: Easy to add more fulfilment webhooks or modify XML structure
|
|
473
|
+
- ✅ **Testable**: Services can be mocked and tested independently
|
|
474
|
+
- ✅ **Environment-specific**: Different mapping configs per environment
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
## SDK Imports (Verified - Versori Optimized)
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
// CRITICAL: Buffer import required for Versori/Deno runtime
|
|
482
|
+
import { Buffer } from 'node:buffer';
|
|
483
|
+
|
|
484
|
+
// FC Connect SDK imports
|
|
485
|
+
import {
|
|
486
|
+
createClient,
|
|
487
|
+
WebhookValidationService,
|
|
488
|
+
UniversalMapper,
|
|
489
|
+
XMLBuilder,
|
|
490
|
+
SftpDataSource,
|
|
491
|
+
DataSourceError,
|
|
492
|
+
AuthenticationError,
|
|
493
|
+
GraphQLError,
|
|
494
|
+
type Logger,
|
|
495
|
+
type VersoriContext,
|
|
496
|
+
} from '@fluentcommerce/fc-connect-sdk';
|
|
497
|
+
|
|
498
|
+
// Versori platform imports
|
|
499
|
+
import { webhook } from '@versori/run';
|
|
500
|
+
import type { Context } from '@versori/run';
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
---
|
|
504
|
+
|
|
505
|
+
## Configuration
|
|
506
|
+
|
|
507
|
+
### Activation Variables
|
|
508
|
+
|
|
509
|
+
```json
|
|
510
|
+
{
|
|
511
|
+
"fluentPublicKey": "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----",
|
|
512
|
+
"sftpHost": "sftp.3pl-partner.com",
|
|
513
|
+
"sftpPort": 22,
|
|
514
|
+
"sftpRemotePath": "/incoming/fulfilments/"
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
> **Important:** `sftpUsername` and `sftpPassword` are **NOT** stored in activation variables. They are securely retrieved from the `sftp_export_server` connection vault at runtime. See the SFTP Credential Management section below for details.
|
|
519
|
+
|
|
520
|
+
### Connections
|
|
521
|
+
|
|
522
|
+
| Connection | Description | Required |
|
|
523
|
+
|------------|-------------|----------|
|
|
524
|
+
| `fluent_commerce` | OAuth2 connection to Fluent Commerce | Yes |
|
|
525
|
+
| `sftp_export_server` | Basic Auth connection for SFTP credentials (username/password) | Yes |
|
|
526
|
+
|
|
527
|
+
## SFTP Credential Management
|
|
528
|
+
|
|
529
|
+
Fetch credentials securely from Versori connection vault using `ctx.credentials().getAccessToken()`:
|
|
530
|
+
|
|
531
|
+
**Benefits:**
|
|
532
|
+
- ✅ Credentials stored securely in Versori vault
|
|
533
|
+
- ✅ Centralized management - update in one place
|
|
534
|
+
- ✅ Access control enforced by platform
|
|
535
|
+
- ✅ No credentials in activation variables
|
|
536
|
+
- ✅ Explicit error handling with validation
|
|
537
|
+
|
|
538
|
+
### Setup Steps
|
|
539
|
+
|
|
540
|
+
1. In Versori Dashboard → Connections → Add Connection
|
|
541
|
+
2. Name: `sftp_export_server`
|
|
542
|
+
3. Type: Basic Auth
|
|
543
|
+
4. Enter SFTP username and password
|
|
544
|
+
5. Save connection
|
|
545
|
+
6. Reference in code: `ctx.credentials().getAccessToken('sftp_export_server')`
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
## Complete Working Code
|
|
550
|
+
|
|
551
|
+
### 1. Entry Point (index.ts)
|
|
552
|
+
|
|
553
|
+
```typescript
|
|
554
|
+
/**
|
|
555
|
+
* Entry point - Export webhook workflow for Versori platform
|
|
556
|
+
*/
|
|
557
|
+
|
|
558
|
+
export { rubixFulfilmentExportHandler } from './src/workflows/webhook/fulfilment-export-handler';
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### 2. Webhook Handler (src/workflows/webhook/fulfilment-export-handler.ts)
|
|
562
|
+
|
|
563
|
+
```typescript
|
|
564
|
+
/**
|
|
565
|
+
* Rubix Fulfilment Webhook Handler → SFTP XML Export
|
|
566
|
+
*
|
|
567
|
+
* Direction: Fluent Rubix Workflow (FULFILMENT) → Versori → GraphQL → UniversalMapper → XML → SFTP
|
|
568
|
+
*/
|
|
569
|
+
|
|
570
|
+
import { Buffer } from 'node:buffer';
|
|
571
|
+
import { webhook } from '@versori/run';
|
|
572
|
+
import type { Context } from '@versori/run';
|
|
573
|
+
import {
|
|
574
|
+
WebhookValidationService,
|
|
575
|
+
type Logger,
|
|
576
|
+
} from '@fluentcommerce/fc-connect-sdk';
|
|
577
|
+
import { processFulfilmentExport } from '../../services/fulfilment-query.service';
|
|
578
|
+
|
|
579
|
+
export const rubixFulfilmentExportHandler = webhook('rubix-fulfilment', {
|
|
580
|
+
response: { mode: 'sync' }, // ✅ Sync mode: response sent when handler returns
|
|
581
|
+
}, async (ctx: Context<any>) => {
|
|
582
|
+
const { log, activation } = ctx;
|
|
583
|
+
|
|
584
|
+
log.info('🚀 [WEBHOOK] Received Rubix fulfilment webhook', {
|
|
585
|
+
timestamp: new Date().toISOString(),
|
|
586
|
+
correlationId: activation?.id,
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// ========================================
|
|
590
|
+
// STEP 1: VALIDATE SIGNATURE (Synchronous)
|
|
591
|
+
// ========================================
|
|
592
|
+
|
|
593
|
+
const publicKey = activation.getVariable('fluentPublicKey');
|
|
594
|
+
if (!publicKey) {
|
|
595
|
+
log.error('❌ [WEBHOOK] Missing fluentPublicKey configuration');
|
|
596
|
+
return {
|
|
597
|
+
status: 500,
|
|
598
|
+
body: {
|
|
599
|
+
success: false,
|
|
600
|
+
error: 'Missing fluentPublicKey configuration',
|
|
601
|
+
recommendation: 'Configure fluentPublicKey in activation variables',
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Extract raw body (Versori provides parsed data in ctx.data)
|
|
607
|
+
const rawBody = typeof ctx.data === 'string' ? ctx.data : JSON.stringify(ctx.data);
|
|
608
|
+
|
|
609
|
+
// Extract headers from request (ctx.request() is a function call)
|
|
610
|
+
const req = ctx.request?.() || {};
|
|
611
|
+
const headersObj = req.headers || {};
|
|
612
|
+
const headers = headersObj instanceof Headers
|
|
613
|
+
? Object.fromEntries(headersObj.entries())
|
|
614
|
+
: headersObj;
|
|
615
|
+
|
|
616
|
+
log.info('🔍 [WEBHOOK] Validating webhook signature');
|
|
617
|
+
|
|
618
|
+
const validator = new WebhookValidationService({ strictValidation: true }, log as Logger);
|
|
619
|
+
const result = await validator.validateWebhook(rawBody, headers, publicKey);
|
|
620
|
+
|
|
621
|
+
if (!result.isValid) {
|
|
622
|
+
log.error('❌ [WEBHOOK] Invalid webhook signature', {
|
|
623
|
+
error: result.error,
|
|
624
|
+
algorithm: result.algorithm,
|
|
625
|
+
});
|
|
626
|
+
return {
|
|
627
|
+
status: 401,
|
|
628
|
+
body: {
|
|
629
|
+
success: false,
|
|
630
|
+
error: 'Invalid webhook signature',
|
|
631
|
+
recommendation: 'Verify fluentPublicKey matches Fluent environment',
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
log.info('✅ [WEBHOOK] Signature validated successfully', {
|
|
637
|
+
algorithm: result.algorithm,
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// ========================================
|
|
641
|
+
// STEP 2: VALIDATE PAYLOAD (Synchronous)
|
|
642
|
+
// ========================================
|
|
643
|
+
|
|
644
|
+
const payload = typeof ctx.data === 'string' ? JSON.parse(ctx.data) : ctx.data;
|
|
645
|
+
const { entityRef, entityType, retailerId } = payload;
|
|
646
|
+
|
|
647
|
+
if (!entityRef) {
|
|
648
|
+
log.error('❌ [WEBHOOK] Missing entityRef in payload', { payload });
|
|
649
|
+
return {
|
|
650
|
+
status: 400,
|
|
651
|
+
body: {
|
|
652
|
+
success: false,
|
|
653
|
+
error: 'Missing entityRef in payload',
|
|
654
|
+
recommendation: 'Ensure Rubix SendWebhook includes fulfilment ref',
|
|
655
|
+
},
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
if (entityType !== 'FULFILMENT') {
|
|
660
|
+
log.error('❌ [WEBHOOK] Invalid entity type', { entityType, expected: 'FULFILMENT' });
|
|
661
|
+
return {
|
|
662
|
+
status: 400,
|
|
663
|
+
body: {
|
|
664
|
+
success: false,
|
|
665
|
+
error: `Invalid entity type: ${entityType}. Expected: FULFILMENT`,
|
|
666
|
+
recommendation: 'Use order-attribute-update template for ORDER webhooks',
|
|
667
|
+
},
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (!retailerId) {
|
|
672
|
+
log.error('❌ [WEBHOOK] Missing retailerId in payload', { payload });
|
|
673
|
+
return {
|
|
674
|
+
status: 400,
|
|
675
|
+
body: {
|
|
676
|
+
success: false,
|
|
677
|
+
error: 'Missing retailerId in payload',
|
|
678
|
+
recommendation: 'Ensure Rubix SendWebhook includes retailerId',
|
|
679
|
+
},
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
log.info('✅ [WEBHOOK] Validation passed, starting background processing', {
|
|
684
|
+
entityRef,
|
|
685
|
+
entityType,
|
|
686
|
+
retailerId,
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
// ========================================
|
|
690
|
+
// STEP 3: FIRE-AND-FORGET BACKGROUND PROCESSING
|
|
691
|
+
// ========================================
|
|
692
|
+
|
|
693
|
+
// ✅ Fire-and-forget: Start background processing WITHOUT await
|
|
694
|
+
// The promise continues execution after we return the response
|
|
695
|
+
processFulfilmentExport(ctx, payload)
|
|
696
|
+
.then(() => {
|
|
697
|
+
log.info('✅ [BACKGROUND] Fulfilment exported successfully', {
|
|
698
|
+
fulfilmentRef: entityRef,
|
|
699
|
+
});
|
|
700
|
+
})
|
|
701
|
+
.catch((error: unknown) => {
|
|
702
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
703
|
+
log.error('❌ [BACKGROUND] Fulfilment export failed', {
|
|
704
|
+
fulfilmentRef: entityRef,
|
|
705
|
+
error: errorMessage,
|
|
706
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
707
|
+
errorType: error instanceof Error ? error.constructor.name : typeof error,
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// Return immediately (response sent with this return value)
|
|
712
|
+
return {
|
|
713
|
+
status: 200,
|
|
714
|
+
body: {
|
|
715
|
+
success: true,
|
|
716
|
+
entityType,
|
|
717
|
+
fulfilmentRef: entityRef,
|
|
718
|
+
message: 'Webhook validated and export started in background',
|
|
719
|
+
timestamp: new Date().toISOString(),
|
|
720
|
+
correlationId: activation?.id,
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
});
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### 3. Fulfilment Query Service (src/services/fulfilment-query.service.ts)
|
|
727
|
+
|
|
728
|
+
```typescript
|
|
729
|
+
/**
|
|
730
|
+
* Fulfilment Query Service
|
|
731
|
+
*
|
|
732
|
+
* Handles GraphQL queries for fulfilment details and orchestrates XML export
|
|
733
|
+
*/
|
|
734
|
+
|
|
735
|
+
import {
|
|
736
|
+
createClient,
|
|
737
|
+
DataSourceError,
|
|
738
|
+
AuthenticationError,
|
|
739
|
+
GraphQLError,
|
|
740
|
+
type Logger,
|
|
741
|
+
type VersoriContext,
|
|
742
|
+
} from '@fluentcommerce/fc-connect-sdk';
|
|
743
|
+
import { exportFulfilmentToSFTP } from './xml-export.service';
|
|
744
|
+
import type { RubixFulfilmentPayload, FulfilmentData } from '../types/fulfilment.types';
|
|
745
|
+
|
|
746
|
+
// Single query with nested items (schema-validated structure)
|
|
747
|
+
const FULFILMENT_QUERY = `
|
|
748
|
+
query GetFulfilment($id: ID!, $first: Int!, $after: String) {
|
|
749
|
+
fulfilment(id: $id) {
|
|
750
|
+
id
|
|
751
|
+
ref
|
|
752
|
+
status
|
|
753
|
+
deliveryType
|
|
754
|
+
order {
|
|
755
|
+
id
|
|
756
|
+
ref
|
|
757
|
+
customer {
|
|
758
|
+
firstName
|
|
759
|
+
lastName
|
|
760
|
+
email
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
toAddress {
|
|
764
|
+
name
|
|
765
|
+
street
|
|
766
|
+
street2
|
|
767
|
+
city
|
|
768
|
+
state
|
|
769
|
+
postcode
|
|
770
|
+
country
|
|
771
|
+
}
|
|
772
|
+
fromAddress {
|
|
773
|
+
name
|
|
774
|
+
street
|
|
775
|
+
street2
|
|
776
|
+
city
|
|
777
|
+
state
|
|
778
|
+
postcode
|
|
779
|
+
country
|
|
780
|
+
}
|
|
781
|
+
items(first: $first, after: $after) {
|
|
782
|
+
edges {
|
|
783
|
+
node {
|
|
784
|
+
id
|
|
785
|
+
ref
|
|
786
|
+
requestedQuantity
|
|
787
|
+
filledQuantity
|
|
788
|
+
rejectedQuantity
|
|
789
|
+
orderItem {
|
|
790
|
+
id
|
|
791
|
+
ref
|
|
792
|
+
productRef
|
|
793
|
+
product {
|
|
794
|
+
name
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
cursor
|
|
799
|
+
}
|
|
800
|
+
pageInfo {
|
|
801
|
+
hasNextPage
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
createdOn
|
|
805
|
+
updatedOn
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
`;
|
|
809
|
+
|
|
810
|
+
export async function processFulfilmentExport(
|
|
811
|
+
ctx: VersoriContext,
|
|
812
|
+
payload: RubixFulfilmentPayload
|
|
813
|
+
): Promise<void> {
|
|
814
|
+
const log = ctx.log as Logger;
|
|
815
|
+
const { entityRef, retailerId } = payload;
|
|
816
|
+
|
|
817
|
+
const processingStartTime = Date.now();
|
|
818
|
+
|
|
819
|
+
log.info('🔄 [BACKGROUND] Starting fulfilment export', {
|
|
820
|
+
timestamp: new Date().toISOString(),
|
|
821
|
+
fulfilmentRef: entityRef,
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
try {
|
|
825
|
+
// ========================================
|
|
826
|
+
// STEP 1: VALIDATE RETAILER ID
|
|
827
|
+
// ========================================
|
|
828
|
+
|
|
829
|
+
if (!retailerId) {
|
|
830
|
+
log.error('❌ [BACKGROUND] Missing retailerId in payload', {
|
|
831
|
+
fulfilmentRef: entityRef,
|
|
832
|
+
});
|
|
833
|
+
throw new Error('retailerId is required for GraphQL operations');
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// ========================================
|
|
837
|
+
// STEP 2: INITIALIZE FLUENT CLIENT
|
|
838
|
+
// ========================================
|
|
839
|
+
|
|
840
|
+
const client = await createClient({ ...ctx, log });
|
|
841
|
+
await client.setRetailerId(retailerId);
|
|
842
|
+
|
|
843
|
+
// ========================================
|
|
844
|
+
// STEP 3: QUERY FULFILMENT WITH NESTED ITEMS
|
|
845
|
+
// ========================================
|
|
846
|
+
|
|
847
|
+
log.info('🔍 [BACKGROUND] Querying fulfilment with items', { fulfilmentRef: entityRef });
|
|
848
|
+
|
|
849
|
+
const result = await client.graphql({
|
|
850
|
+
query: FULFILMENT_QUERY,
|
|
851
|
+
variables: {
|
|
852
|
+
id: entityRef, // ✅ Use 'id' parameter (schema-validated)
|
|
853
|
+
first: 100,
|
|
854
|
+
},
|
|
855
|
+
pagination: {
|
|
856
|
+
connectionPath: 'fulfilment.items', // ✅ Nested connection pagination
|
|
857
|
+
maxPages: 10, // Handles up to 1000 items (100 per page × 10 pages)
|
|
858
|
+
},
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
const fulfilmentData = result.data?.fulfilment as FulfilmentData | null;
|
|
862
|
+
|
|
863
|
+
if (!fulfilmentData) {
|
|
864
|
+
log.error('❌ [BACKGROUND] Fulfilment not found', { fulfilmentRef: entityRef });
|
|
865
|
+
throw new Error(`Fulfilment not found: ${entityRef}`);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
const itemCount = fulfilmentData.items?.edges?.length || 0;
|
|
869
|
+
|
|
870
|
+
log.info('✅ [BACKGROUND] Fulfilment and items queried successfully', {
|
|
871
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
872
|
+
status: fulfilmentData.status,
|
|
873
|
+
itemCount,
|
|
874
|
+
orderRef: fulfilmentData.order?.ref,
|
|
875
|
+
paginationUsed: result.metadata?.totalPages > 1,
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
// ========================================
|
|
879
|
+
// STEP 4: EXPORT TO SFTP
|
|
880
|
+
// ========================================
|
|
881
|
+
|
|
882
|
+
await exportFulfilmentToSFTP(ctx, fulfilmentData, log);
|
|
883
|
+
|
|
884
|
+
const duration = Date.now() - processingStartTime;
|
|
885
|
+
log.info('✅ [BACKGROUND] Fulfilment export completed', {
|
|
886
|
+
fulfilmentRef: entityRef,
|
|
887
|
+
duration: `${duration}ms`,
|
|
888
|
+
});
|
|
889
|
+
} catch (error: unknown) {
|
|
890
|
+
let errorMessage = 'Unknown error';
|
|
891
|
+
let recommendation: string | undefined;
|
|
892
|
+
let errorCategory = 'UNKNOWN';
|
|
893
|
+
|
|
894
|
+
if (error instanceof GraphQLError) {
|
|
895
|
+
errorMessage = error.message;
|
|
896
|
+
recommendation = 'Review GraphQL query syntax and field permissions';
|
|
897
|
+
errorCategory = 'GRAPHQL';
|
|
898
|
+
} else if (error instanceof AuthenticationError) {
|
|
899
|
+
errorMessage = error.message;
|
|
900
|
+
recommendation = 'Verify Fluent Commerce credentials and retailerId';
|
|
901
|
+
errorCategory = 'AUTHENTICATION';
|
|
902
|
+
} else if (error instanceof DataSourceError) {
|
|
903
|
+
errorMessage = error.message;
|
|
904
|
+
recommendation = 'Check SFTP configuration and connectivity';
|
|
905
|
+
errorCategory = 'DATA_SOURCE';
|
|
906
|
+
} else if (error instanceof Error) {
|
|
907
|
+
errorMessage = error.message;
|
|
908
|
+
} else {
|
|
909
|
+
errorMessage = String(error);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
log.error('❌ [BACKGROUND] Fulfilment export failed', {
|
|
913
|
+
fulfilmentRef: entityRef,
|
|
914
|
+
error: errorMessage,
|
|
915
|
+
errorCategory,
|
|
916
|
+
recommendation,
|
|
917
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
918
|
+
errorType: error instanceof Error ? error.constructor.name : typeof error,
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
throw error;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
### 4. XML Export Service (src/services/xml-export.service.ts)
|
|
927
|
+
|
|
928
|
+
```typescript
|
|
929
|
+
/**
|
|
930
|
+
* XML Export Service
|
|
931
|
+
*
|
|
932
|
+
* Handles XML generation and SFTP upload for fulfilment exports
|
|
933
|
+
* Uses UniversalMapper with external JSON mapping configuration
|
|
934
|
+
*/
|
|
935
|
+
|
|
936
|
+
import { Buffer } from 'node:buffer';
|
|
937
|
+
import {
|
|
938
|
+
UniversalMapper,
|
|
939
|
+
XMLBuilder,
|
|
940
|
+
SftpDataSource,
|
|
941
|
+
type Logger,
|
|
942
|
+
type VersoriContext,
|
|
943
|
+
} from '@fluentcommerce/fc-connect-sdk';
|
|
944
|
+
import type { FulfilmentData } from '../types/fulfilment.types';
|
|
945
|
+
import mappingConfig from '../config/fulfilment-xml-mapping.json' with { type: 'json' };
|
|
946
|
+
import { customResolvers } from '../resolvers/fulfilment-resolvers';
|
|
947
|
+
|
|
948
|
+
export async function exportFulfilmentToSFTP(
|
|
949
|
+
ctx: VersoriContext,
|
|
950
|
+
fulfilmentData: FulfilmentData,
|
|
951
|
+
log: Logger
|
|
952
|
+
): Promise<void> {
|
|
953
|
+
const { activation } = ctx;
|
|
954
|
+
|
|
955
|
+
log.info('📝 [BACKGROUND] Generating XML for fulfilment', {
|
|
956
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
// ========================================
|
|
960
|
+
// STEP 1: TRANSFORM DATA WITH UNIVERSALMAPPER
|
|
961
|
+
// ========================================
|
|
962
|
+
|
|
963
|
+
log.info('🔄 [BACKGROUND] Transforming fulfilment data with UniversalMapper', {
|
|
964
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
const mapper = new UniversalMapper(mappingConfig, {
|
|
968
|
+
customResolvers,
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
const mappingResult = await mapper.map(fulfilmentData);
|
|
972
|
+
|
|
973
|
+
if (!mappingResult.success) {
|
|
974
|
+
log.error('❌ [BACKGROUND] Mapping failed', {
|
|
975
|
+
errors: mappingResult.errors,
|
|
976
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
977
|
+
});
|
|
978
|
+
throw new Error(`Mapping failed: ${mappingResult.errors?.join(', ')}`);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
const mappedData = mappingResult.data;
|
|
982
|
+
|
|
983
|
+
log.info('✅ [BACKGROUND] Data transformed successfully', {
|
|
984
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
985
|
+
fieldCount: Object.keys(mappedData).length,
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
// ========================================
|
|
989
|
+
// STEP 2: GENERATE XML WITH XMLBUILDER
|
|
990
|
+
// ========================================
|
|
991
|
+
|
|
992
|
+
const xmlBuilder = new XMLBuilder({
|
|
993
|
+
prettyPrint: true,
|
|
994
|
+
xmlDeclaration: true,
|
|
995
|
+
encoding: 'UTF-8',
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
const xmlString = xmlBuilder.build(mappedData, 'FulfilmentExport');
|
|
999
|
+
const xmlBuffer = Buffer.from(xmlString, 'utf8');
|
|
1000
|
+
|
|
1001
|
+
log.info('✅ [BACKGROUND] XML generated successfully', {
|
|
1002
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
1003
|
+
xmlSizeBytes: xmlBuffer.length,
|
|
1004
|
+
xmlSizeKB: Math.round(xmlBuffer.length / 1024),
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
// ========================================
|
|
1008
|
+
// STEP 3: UPLOAD TO SFTP
|
|
1009
|
+
// ========================================
|
|
1010
|
+
|
|
1011
|
+
log.info('📤 [BACKGROUND] Preparing SFTP upload', {
|
|
1012
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
// ========================================
|
|
1016
|
+
// SFTP CREDENTIAL RETRIEVAL
|
|
1017
|
+
// ========================================
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* Retrieve SFTP credentials from connection configuration
|
|
1021
|
+
*
|
|
1022
|
+
* Connection Name: 'sftp_export_server' (must match the connection name in Versori UI)
|
|
1023
|
+
* Auth Type: Basic Authentication (username + password)
|
|
1024
|
+
*/
|
|
1025
|
+
log.info('🔐 [BACKGROUND] Retrieving SFTP credentials from connection configuration');
|
|
1026
|
+
|
|
1027
|
+
let sftpUsername: string;
|
|
1028
|
+
let sftpPassword: string;
|
|
1029
|
+
|
|
1030
|
+
try {
|
|
1031
|
+
// Retrieve credentials from the 'sftp_export_server' connection
|
|
1032
|
+
const sftpCred = await ctx.credentials().getAccessToken('sftp_export_server');
|
|
1033
|
+
|
|
1034
|
+
if (!sftpCred?.accessToken) {
|
|
1035
|
+
throw new Error('No SFTP credentials found in connection configuration');
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// Decode base64 accessToken to get "username:password"
|
|
1039
|
+
const rawBasicAuth = Buffer.from(sftpCred.accessToken, 'base64').toString('utf-8');
|
|
1040
|
+
|
|
1041
|
+
// Split on ':' to extract username and password
|
|
1042
|
+
const parts = rawBasicAuth.split(':');
|
|
1043
|
+
|
|
1044
|
+
if (parts.length !== 2) {
|
|
1045
|
+
throw new Error('Invalid SFTP credential format - expected username:password');
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
sftpUsername = parts[0];
|
|
1049
|
+
sftpPassword = parts[1];
|
|
1050
|
+
|
|
1051
|
+
log.info('✅ [BACKGROUND] SFTP credentials retrieved successfully', {
|
|
1052
|
+
hasUsername: !!sftpUsername,
|
|
1053
|
+
hasPassword: !!sftpPassword,
|
|
1054
|
+
usernameLength: sftpUsername.length,
|
|
1055
|
+
passwordLength: sftpPassword.length,
|
|
1056
|
+
});
|
|
1057
|
+
} catch (error: any) {
|
|
1058
|
+
log.error('❌ [BACKGROUND] Failed to retrieve SFTP credentials', {
|
|
1059
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1060
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
1061
|
+
errorType: error instanceof Error ? error.constructor.name : 'Error',
|
|
1062
|
+
recommendation: 'Please ensure the SFTP connection "sftp_export_server" is configured in the Connections section with Basic Authentication (username and password)',
|
|
1063
|
+
});
|
|
1064
|
+
throw new Error(
|
|
1065
|
+
`Failed to retrieve SFTP credentials from connection configuration: ${error instanceof Error ? error.message : String(error)}. ` +
|
|
1066
|
+
'Please ensure the SFTP connection is configured in the Connections section with Basic Authentication (username and password)'
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// Get SFTP configuration from activation variables
|
|
1071
|
+
const sftpHost = activation.getVariable('sftpHost');
|
|
1072
|
+
const sftpPort = parseInt(activation.getVariable('sftpPort') || '22', 10);
|
|
1073
|
+
const sftpRemotePath = activation.getVariable('sftpRemotePath') || '/incoming/fulfilments/';
|
|
1074
|
+
|
|
1075
|
+
if (!sftpHost) {
|
|
1076
|
+
log.error('⚠️ [BACKGROUND] SFTP configuration missing', {
|
|
1077
|
+
recommendation: 'Configure sftpHost activation variable',
|
|
1078
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
1079
|
+
});
|
|
1080
|
+
throw new Error('SFTP configuration missing: sftpHost is required');
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
const sftpConfig = {
|
|
1084
|
+
type: 'SFTP_XML' as const,
|
|
1085
|
+
connectionId: 'sftp_export_server',
|
|
1086
|
+
name: 'Fulfilment XML Export',
|
|
1087
|
+
settings: {
|
|
1088
|
+
host: sftpHost,
|
|
1089
|
+
port: sftpPort,
|
|
1090
|
+
username: sftpUsername,
|
|
1091
|
+
password: sftpPassword,
|
|
1092
|
+
},
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
const sftp = new SftpDataSource(sftpConfig, log);
|
|
1096
|
+
|
|
1097
|
+
try {
|
|
1098
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
1099
|
+
const fileName = `fulfilment-${fulfilmentData.ref}-${timestamp}.xml`;
|
|
1100
|
+
const remoteFilePath = `${sftpRemotePath}${fileName}`;
|
|
1101
|
+
|
|
1102
|
+
// ✅ CRITICAL FIX: Include options parameter
|
|
1103
|
+
await sftp.uploadFile(remoteFilePath, xmlBuffer, {
|
|
1104
|
+
overwrite: true,
|
|
1105
|
+
createDirectories: true,
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
log.info('✅ [BACKGROUND] Fulfilment XML exported to SFTP', {
|
|
1109
|
+
fulfilmentRef: fulfilmentData.ref,
|
|
1110
|
+
remoteFilePath,
|
|
1111
|
+
status: fulfilmentData.status,
|
|
1112
|
+
fileSizeKB: Math.round(xmlBuffer.length / 1024),
|
|
1113
|
+
});
|
|
1114
|
+
} finally {
|
|
1115
|
+
// ✅ CRITICAL: Always dispose SFTP connection
|
|
1116
|
+
await sftp.dispose();
|
|
1117
|
+
log.info('🔌 [BACKGROUND] SFTP connection disposed');
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1122
|
+
### 5. Mapping Configuration (src/config/fulfilment-xml-mapping.json)
|
|
1123
|
+
|
|
1124
|
+
**IMPORTANT: Array Mapping Patterns**
|
|
1125
|
+
|
|
1126
|
+
The SDK supports **two patterns** for GraphQL edges/nodes arrays. Here's exactly what happens with each:
|
|
1127
|
+
|
|
1128
|
+
## Step-by-Step: What Each Pattern Does
|
|
1129
|
+
|
|
1130
|
+
### Input Data (GraphQL Response)
|
|
1131
|
+
```javascript
|
|
1132
|
+
{
|
|
1133
|
+
items: {
|
|
1134
|
+
edges: [
|
|
1135
|
+
{ node: { ref: "FFI-001", requestedQuantity: 2, orderItem: { productRef: "SKU-001" } } },
|
|
1136
|
+
{ node: { ref: "FFI-002", requestedQuantity: 1, orderItem: { productRef: "SKU-002" } } }
|
|
1137
|
+
]
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
---
|
|
1143
|
+
|
|
1144
|
+
### Pattern 1: `source: "items.edges[*].node"` + `Item` wrapper
|
|
1145
|
+
|
|
1146
|
+
**Config:**
|
|
1147
|
+
```json
|
|
1148
|
+
"Items": {
|
|
1149
|
+
"source": "items.edges[*].node",
|
|
1150
|
+
"isArray": true,
|
|
1151
|
+
"fields": {
|
|
1152
|
+
"Item": {
|
|
1153
|
+
"fields": {
|
|
1154
|
+
"@ref": { "source": "ref" },
|
|
1155
|
+
"ProductRef": { "source": "orderItem.productRef" }
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
```
|
|
1161
|
+
|
|
1162
|
+
**Step 1:** SDK extracts `items.edges[*].node`
|
|
1163
|
+
- Splits on `[*]` → `arrayPath="items.edges"`, `nodePath="node"`
|
|
1164
|
+
- Gets `items.edges` array: `[{ node: {...} }, { node: {...} }]`
|
|
1165
|
+
- Extracts `.node` from each → `[{ ref: "FFI-001", ... }, { ref: "FFI-002", ... }]`
|
|
1166
|
+
|
|
1167
|
+
**Step 2:** For each node, maps nested `Item` fields
|
|
1168
|
+
- Node 1: `{ ref: "FFI-001", orderItem: { productRef: "SKU-001" } }`
|
|
1169
|
+
- Maps `"@ref": { "source": "ref" }` → extracts `node.ref` = `"FFI-001"`
|
|
1170
|
+
- Maps `"ProductRef": { "source": "orderItem.productRef" }` → extracts `node.orderItem.productRef` = `"SKU-001"`
|
|
1171
|
+
- Result: `{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } }`
|
|
1172
|
+
|
|
1173
|
+
**Step 3:** Final mapped data
|
|
1174
|
+
```javascript
|
|
1175
|
+
{
|
|
1176
|
+
Items: [
|
|
1177
|
+
{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } },
|
|
1178
|
+
{ Item: { "@ref": "FFI-002", "ProductRef": "SKU-002" } }
|
|
1179
|
+
]
|
|
1180
|
+
}
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
**Step 4:** XMLBuilder output
|
|
1184
|
+
```xml
|
|
1185
|
+
<Items>
|
|
1186
|
+
<Item ref="FFI-001">
|
|
1187
|
+
<ProductRef>SKU-001</ProductRef>
|
|
1188
|
+
</Item>
|
|
1189
|
+
<Item ref="FFI-002">
|
|
1190
|
+
<ProductRef>SKU-002</ProductRef>
|
|
1191
|
+
</Item>
|
|
1192
|
+
</Items>
|
|
1193
|
+
```
|
|
1194
|
+
|
|
1195
|
+
---
|
|
1196
|
+
|
|
1197
|
+
### Pattern 2: `source: "items.edges"` + `Item` wrapper
|
|
1198
|
+
|
|
1199
|
+
**Config:**
|
|
1200
|
+
```json
|
|
1201
|
+
"Items": {
|
|
1202
|
+
"source": "items.edges",
|
|
1203
|
+
"isArray": true,
|
|
1204
|
+
"fields": {
|
|
1205
|
+
"Item": {
|
|
1206
|
+
"fields": {
|
|
1207
|
+
"@ref": { "source": "node.ref" },
|
|
1208
|
+
"ProductRef": { "source": "node.orderItem.productRef" }
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
```
|
|
1214
|
+
|
|
1215
|
+
**Step 1:** SDK extracts `items.edges`
|
|
1216
|
+
- Gets array directly: `[{ node: {...} }, { node: {...} }]` (edges array)
|
|
1217
|
+
|
|
1218
|
+
**Step 2:** For each edge, maps nested `Item` fields
|
|
1219
|
+
- Edge 1: `{ node: { ref: "FFI-001", orderItem: { productRef: "SKU-001" } } }`
|
|
1220
|
+
- Maps `"@ref": { "source": "node.ref" }` → extracts `edge.node.ref` = `"FFI-001"`
|
|
1221
|
+
- Maps `"ProductRef": { "source": "node.orderItem.productRef" }` → extracts `edge.node.orderItem.productRef` = `"SKU-001"`
|
|
1222
|
+
- Result: `{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } }`
|
|
1223
|
+
|
|
1224
|
+
**Step 3:** Final mapped data (IDENTICAL to Pattern 1)
|
|
1225
|
+
```javascript
|
|
1226
|
+
{
|
|
1227
|
+
Items: [
|
|
1228
|
+
{ Item: { "@ref": "FFI-001", "ProductRef": "SKU-001" } },
|
|
1229
|
+
{ Item: { "@ref": "FFI-002", "ProductRef": "SKU-002" } }
|
|
1230
|
+
]
|
|
1231
|
+
}
|
|
1232
|
+
```
|
|
1233
|
+
|
|
1234
|
+
**Step 4:** XMLBuilder output (IDENTICAL to Pattern 1)
|
|
1235
|
+
```xml
|
|
1236
|
+
<Items>
|
|
1237
|
+
<Item ref="FFI-001">
|
|
1238
|
+
<ProductRef>SKU-001</ProductRef>
|
|
1239
|
+
</Item>
|
|
1240
|
+
<Item ref="FFI-002">
|
|
1241
|
+
<ProductRef>SKU-002</ProductRef>
|
|
1242
|
+
</Item>
|
|
1243
|
+
</Items>
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
---
|
|
1247
|
+
|
|
1248
|
+
## Key Differences
|
|
1249
|
+
|
|
1250
|
+
| Aspect | Pattern 1 (`edges[*].node`) | Pattern 2 (`edges`) |
|
|
1251
|
+
|--------|----------------------------|---------------------|
|
|
1252
|
+
| **What SDK extracts** | Nodes directly: `[{ ref: "..." }, ...]` | Edges: `[{ node: {...} }, ...]` |
|
|
1253
|
+
| **Field paths** | `"ref"` (direct) | `"node.ref"` (need prefix) |
|
|
1254
|
+
| **Mapped data** | ✅ Same | ✅ Same |
|
|
1255
|
+
| **XML output** | ✅ Same (with `Item` wrapper) | ✅ Same (with `Item` wrapper) |
|
|
1256
|
+
| **Without `Item` wrapper** | ❌ Wrong XML | ❌ Wrong XML |
|
|
1257
|
+
|
|
1258
|
+
## Why Both Work
|
|
1259
|
+
|
|
1260
|
+
**Both patterns produce identical results** because:
|
|
1261
|
+
1. Pattern 1 extracts nodes first, then maps fields from nodes
|
|
1262
|
+
2. Pattern 2 extracts edges, then maps fields from `edge.node`
|
|
1263
|
+
3. Both end up with the same mapped data structure
|
|
1264
|
+
4. XMLBuilder converts the same structure to identical XML
|
|
1265
|
+
|
|
1266
|
+
**The `Item` wrapper is required** for both patterns to create `<Item>` elements instead of flat `<@ref>` elements.
|
|
1267
|
+
|
|
1268
|
+
**Recommendation:** Use Pattern 1 (`edges[*].node`) - cleaner field paths, less typing.
|
|
1269
|
+
|
|
1270
|
+
---
|
|
1271
|
+
|
|
1272
|
+
**Full Mapping Configuration:**
|
|
1273
|
+
|
|
1274
|
+
```json
|
|
1275
|
+
{
|
|
1276
|
+
"name": "fulfilment-xml-mapping",
|
|
1277
|
+
"version": "1.0.0",
|
|
1278
|
+
"description": "Fluent Fulfilment → XML Export Mapping for 3PL/WMS",
|
|
1279
|
+
"fields": {
|
|
1280
|
+
"Fulfilment": {
|
|
1281
|
+
"fields": {
|
|
1282
|
+
"@ref": {
|
|
1283
|
+
"source": "ref",
|
|
1284
|
+
"required": true,
|
|
1285
|
+
"resolver": "sdk.trim"
|
|
1286
|
+
},
|
|
1287
|
+
"@status": {
|
|
1288
|
+
"source": "status",
|
|
1289
|
+
"required": true,
|
|
1290
|
+
"resolver": "sdk.uppercase"
|
|
1291
|
+
},
|
|
1292
|
+
"OrderRef": {
|
|
1293
|
+
"source": "order.ref",
|
|
1294
|
+
"required": true,
|
|
1295
|
+
"resolver": "sdk.trim"
|
|
1296
|
+
},
|
|
1297
|
+
"DeliveryType": {
|
|
1298
|
+
"source": "deliveryType",
|
|
1299
|
+
"required": false,
|
|
1300
|
+
"resolver": "sdk.trim"
|
|
1301
|
+
},
|
|
1302
|
+
"Customer": {
|
|
1303
|
+
"source": "order.customer",
|
|
1304
|
+
"fields": {
|
|
1305
|
+
"FirstName": {
|
|
1306
|
+
"source": "firstName",
|
|
1307
|
+
"required": false,
|
|
1308
|
+
"resolver": "sdk.trim"
|
|
1309
|
+
},
|
|
1310
|
+
"LastName": {
|
|
1311
|
+
"source": "lastName",
|
|
1312
|
+
"required": false,
|
|
1313
|
+
"resolver": "sdk.trim"
|
|
1314
|
+
},
|
|
1315
|
+
"Email": {
|
|
1316
|
+
"source": "email",
|
|
1317
|
+
"required": false,
|
|
1318
|
+
"resolver": "sdk.trim"
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
},
|
|
1322
|
+
"ToAddress": {
|
|
1323
|
+
"source": "toAddress",
|
|
1324
|
+
"fields": {
|
|
1325
|
+
"Name": { "source": "name", "required": false, "resolver": "sdk.trim" },
|
|
1326
|
+
"Street": { "source": "street", "required": false, "resolver": "sdk.trim" },
|
|
1327
|
+
"Street2": { "source": "street2", "required": false, "resolver": "sdk.trim" },
|
|
1328
|
+
"City": { "source": "city", "required": false, "resolver": "sdk.trim" },
|
|
1329
|
+
"State": { "source": "state", "required": false, "resolver": "sdk.trim" },
|
|
1330
|
+
"Postcode": { "source": "postcode", "required": false, "resolver": "sdk.trim" },
|
|
1331
|
+
"Country": { "source": "country", "required": false, "resolver": "sdk.trim" }
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
"FromAddress": {
|
|
1335
|
+
"source": "fromAddress",
|
|
1336
|
+
"fields": {
|
|
1337
|
+
"Name": { "source": "name", "required": false, "resolver": "sdk.trim" },
|
|
1338
|
+
"Street": { "source": "street", "required": false, "resolver": "sdk.trim" },
|
|
1339
|
+
"Street2": { "source": "street2", "required": false, "resolver": "sdk.trim" },
|
|
1340
|
+
"City": { "source": "city", "required": false, "resolver": "sdk.trim" },
|
|
1341
|
+
"State": { "source": "state", "required": false, "resolver": "sdk.trim" },
|
|
1342
|
+
"Postcode": { "source": "postcode", "required": false, "resolver": "sdk.trim" },
|
|
1343
|
+
"Country": { "source": "country", "required": false, "resolver": "sdk.trim" }
|
|
1344
|
+
}
|
|
1345
|
+
},
|
|
1346
|
+
"Items": {
|
|
1347
|
+
"source": "items.edges[*].node",
|
|
1348
|
+
"isArray": true,
|
|
1349
|
+
"fields": {
|
|
1350
|
+
"Item": {
|
|
1351
|
+
"fields": {
|
|
1352
|
+
"@ref": {
|
|
1353
|
+
"source": "ref",
|
|
1354
|
+
"required": true,
|
|
1355
|
+
"resolver": "sdk.trim"
|
|
1356
|
+
},
|
|
1357
|
+
"ProductRef": {
|
|
1358
|
+
"source": "orderItem.productRef",
|
|
1359
|
+
"required": false,
|
|
1360
|
+
"resolver": "sdk.trim"
|
|
1361
|
+
},
|
|
1362
|
+
"ProductName": {
|
|
1363
|
+
"source": "orderItem.product.name",
|
|
1364
|
+
"required": false,
|
|
1365
|
+
"resolver": "sdk.trim"
|
|
1366
|
+
},
|
|
1367
|
+
"RequestedQuantity": {
|
|
1368
|
+
"source": "requestedQuantity",
|
|
1369
|
+
"required": false,
|
|
1370
|
+
"resolver": "sdk.parseInt"
|
|
1371
|
+
},
|
|
1372
|
+
"FilledQuantity": {
|
|
1373
|
+
"source": "filledQuantity",
|
|
1374
|
+
"required": true,
|
|
1375
|
+
"resolver": "sdk.parseInt"
|
|
1376
|
+
},
|
|
1377
|
+
"RejectedQuantity": {
|
|
1378
|
+
"source": "rejectedQuantity",
|
|
1379
|
+
"required": true,
|
|
1380
|
+
"resolver": "sdk.parseInt"
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
"CreatedOn": {
|
|
1387
|
+
"source": "createdOn",
|
|
1388
|
+
"required": true,
|
|
1389
|
+
"resolver": "custom.formatISO8601"
|
|
1390
|
+
},
|
|
1391
|
+
"UpdatedOn": {
|
|
1392
|
+
"source": "updatedOn",
|
|
1393
|
+
"required": true,
|
|
1394
|
+
"resolver": "custom.formatISO8601"
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
```
|
|
1401
|
+
|
|
1402
|
+
### 6. Custom Resolvers (src/resolvers/fulfilment-resolvers.ts)
|
|
1403
|
+
|
|
1404
|
+
```typescript
|
|
1405
|
+
/**
|
|
1406
|
+
* Custom Resolvers for Fulfilment XML Mapping
|
|
1407
|
+
*
|
|
1408
|
+
* Handles complex transformations that SDK resolvers don't cover
|
|
1409
|
+
*/
|
|
1410
|
+
|
|
1411
|
+
export const customResolvers = {
|
|
1412
|
+
/**
|
|
1413
|
+
* Format ISO 8601 date string (ensures consistent format)
|
|
1414
|
+
*
|
|
1415
|
+
* Resolver signature: (value, sourceData, config, helpers) => any | Promise<any>
|
|
1416
|
+
*/
|
|
1417
|
+
'custom.formatISO8601': (
|
|
1418
|
+
value: any,
|
|
1419
|
+
sourceData: any,
|
|
1420
|
+
config: any,
|
|
1421
|
+
helpers: any
|
|
1422
|
+
): string => {
|
|
1423
|
+
if (!value) return '';
|
|
1424
|
+
|
|
1425
|
+
if (value instanceof Date) {
|
|
1426
|
+
return value.toISOString();
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
if (typeof value === 'string') {
|
|
1430
|
+
// If already ISO format, return as-is
|
|
1431
|
+
if (value.includes('T') && value.includes('Z')) {
|
|
1432
|
+
return value;
|
|
1433
|
+
}
|
|
1434
|
+
// Try to parse and format
|
|
1435
|
+
const date = new Date(value);
|
|
1436
|
+
if (!isNaN(date.getTime())) {
|
|
1437
|
+
return date.toISOString();
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
return String(value || '');
|
|
1442
|
+
},
|
|
1443
|
+
|
|
1444
|
+
/**
|
|
1445
|
+
* Format address line (handles missing fields gracefully)
|
|
1446
|
+
*/
|
|
1447
|
+
'custom.formatAddressLine': (address: any): string => {
|
|
1448
|
+
if (!address) return '';
|
|
1449
|
+
|
|
1450
|
+
const parts = [
|
|
1451
|
+
address.street1,
|
|
1452
|
+
address.street2,
|
|
1453
|
+
address.city,
|
|
1454
|
+
address.state,
|
|
1455
|
+
address.postcode,
|
|
1456
|
+
address.country,
|
|
1457
|
+
].filter(Boolean);
|
|
1458
|
+
|
|
1459
|
+
return parts.join(', ');
|
|
1460
|
+
},
|
|
1461
|
+
|
|
1462
|
+
/**
|
|
1463
|
+
* Format customer full name
|
|
1464
|
+
*/
|
|
1465
|
+
'custom.formatCustomerName': (customer: any): string => {
|
|
1466
|
+
if (!customer) return '';
|
|
1467
|
+
|
|
1468
|
+
const parts = [customer.firstName, customer.lastName].filter(Boolean);
|
|
1469
|
+
return parts.join(' ') || '';
|
|
1470
|
+
},
|
|
1471
|
+
};
|
|
1472
|
+
```
|
|
1473
|
+
|
|
1474
|
+
### 7. Type Definitions (src/types/fulfilment.types.ts)
|
|
1475
|
+
|
|
1476
|
+
```typescript
|
|
1477
|
+
/**
|
|
1478
|
+
* Type definitions for Rubix fulfilment webhooks and GraphQL responses
|
|
1479
|
+
*/
|
|
1480
|
+
|
|
1481
|
+
export interface RubixFulfilmentPayload {
|
|
1482
|
+
id: string;
|
|
1483
|
+
name: string;
|
|
1484
|
+
accountId: string;
|
|
1485
|
+
retailerId: string;
|
|
1486
|
+
entityRef: string;
|
|
1487
|
+
entityType: 'FULFILMENT';
|
|
1488
|
+
entityStatus?: string;
|
|
1489
|
+
type: 'NORMAL' | string;
|
|
1490
|
+
rootEntityId?: string;
|
|
1491
|
+
rootEntityType?: string;
|
|
1492
|
+
rootEntityRef?: string;
|
|
1493
|
+
attributes?: Record<string, any>;
|
|
1494
|
+
context?: Record<string, any>;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
export interface FulfilmentData {
|
|
1498
|
+
id: string;
|
|
1499
|
+
ref: string;
|
|
1500
|
+
status: string;
|
|
1501
|
+
deliveryType: string;
|
|
1502
|
+
order?: {
|
|
1503
|
+
id: string;
|
|
1504
|
+
ref: string;
|
|
1505
|
+
customer?: {
|
|
1506
|
+
firstName: string;
|
|
1507
|
+
lastName: string;
|
|
1508
|
+
email: string;
|
|
1509
|
+
};
|
|
1510
|
+
};
|
|
1511
|
+
items?: {
|
|
1512
|
+
edges?: Array<{
|
|
1513
|
+
node: {
|
|
1514
|
+
id: string;
|
|
1515
|
+
ref: string;
|
|
1516
|
+
requestedQuantity?: number;
|
|
1517
|
+
filledQuantity: number;
|
|
1518
|
+
rejectedQuantity: number;
|
|
1519
|
+
orderItem?: {
|
|
1520
|
+
id: string;
|
|
1521
|
+
ref: string;
|
|
1522
|
+
productRef: string;
|
|
1523
|
+
product?: {
|
|
1524
|
+
name: string;
|
|
1525
|
+
};
|
|
1526
|
+
};
|
|
1527
|
+
};
|
|
1528
|
+
}>;
|
|
1529
|
+
};
|
|
1530
|
+
toAddress?: {
|
|
1531
|
+
name?: string;
|
|
1532
|
+
street?: string;
|
|
1533
|
+
street2?: string;
|
|
1534
|
+
city?: string;
|
|
1535
|
+
state?: string;
|
|
1536
|
+
postcode?: string;
|
|
1537
|
+
country?: string;
|
|
1538
|
+
};
|
|
1539
|
+
fromAddress?: {
|
|
1540
|
+
name?: string;
|
|
1541
|
+
street?: string;
|
|
1542
|
+
street2?: string;
|
|
1543
|
+
city?: string;
|
|
1544
|
+
state?: string;
|
|
1545
|
+
postcode?: string;
|
|
1546
|
+
country?: string;
|
|
1547
|
+
};
|
|
1548
|
+
createdOn: string;
|
|
1549
|
+
updatedOn: string;
|
|
1550
|
+
}
|
|
1551
|
+
```
|
|
1552
|
+
|
|
1553
|
+
### 8. Package Configuration (package.json)
|
|
1554
|
+
|
|
1555
|
+
```json
|
|
1556
|
+
{
|
|
1557
|
+
"name": "rubix-fulfilment-export",
|
|
1558
|
+
"version": "2.0.0",
|
|
1559
|
+
"description": "Rubix fulfilment webhook handler with SFTP XML export (UniversalMapper pattern)",
|
|
1560
|
+
"type": "module",
|
|
1561
|
+
"main": "index.ts",
|
|
1562
|
+
"scripts": {
|
|
1563
|
+
"dev": "versori dev",
|
|
1564
|
+
"build": "versori build",
|
|
1565
|
+
"deploy": "versori deploy",
|
|
1566
|
+
"test": "jest",
|
|
1567
|
+
"lint": "eslint src/**/*.ts"
|
|
1568
|
+
},
|
|
1569
|
+
"dependencies": {
|
|
1570
|
+
"@fluentcommerce/fc-connect-sdk": "^0.1.39",
|
|
1571
|
+
"@versori/run": "latest"
|
|
1572
|
+
},
|
|
1573
|
+
"devDependencies": {
|
|
1574
|
+
"@types/node": "^20.0.0",
|
|
1575
|
+
"typescript": "^5.0.0",
|
|
1576
|
+
"jest": "^29.0.0",
|
|
1577
|
+
"@types/jest": "^29.0.0",
|
|
1578
|
+
"eslint": "^8.0.0"
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
```
|
|
1582
|
+
|
|
1583
|
+
---
|
|
1584
|
+
|
|
1585
|
+
## Key Patterns Explained
|
|
1586
|
+
|
|
1587
|
+
### Pattern 1: External JSON Mapping Configuration
|
|
1588
|
+
|
|
1589
|
+
```typescript
|
|
1590
|
+
// ✅ CORRECT - External JSON mapping
|
|
1591
|
+
import mappingConfig from '../config/fulfilment-xml-mapping.json' with { type: 'json' };
|
|
1592
|
+
const mapper = new UniversalMapper(mappingConfig, { customResolvers });
|
|
1593
|
+
const result = await mapper.map(fulfilmentData);
|
|
1594
|
+
|
|
1595
|
+
// ❌ WRONG - Inline mapping (use inline template instead)
|
|
1596
|
+
const xmlData = {
|
|
1597
|
+
Fulfilment: {
|
|
1598
|
+
'@ref': fulfilmentData.ref,
|
|
1599
|
+
// ... 50+ lines of inline mapping
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
```
|
|
1603
|
+
|
|
1604
|
+
**Why:** External JSON allows XML structure changes without code modifications, supports environment-specific configs, and enables independent testing.
|
|
1605
|
+
|
|
1606
|
+
### Pattern 2: Custom Resolvers for Complex Transformations
|
|
1607
|
+
|
|
1608
|
+
```typescript
|
|
1609
|
+
// ✅ CORRECT - Custom resolver for date formatting
|
|
1610
|
+
export const customResolvers = {
|
|
1611
|
+
'custom.formatISO8601': (value: string | Date | null | undefined): string => {
|
|
1612
|
+
if (value instanceof Date) return value.toISOString();
|
|
1613
|
+
// ... handle string dates
|
|
1614
|
+
},
|
|
1615
|
+
};
|
|
1616
|
+
|
|
1617
|
+
// In mapping config:
|
|
1618
|
+
{
|
|
1619
|
+
"CreatedOn": {
|
|
1620
|
+
"source": "createdOn",
|
|
1621
|
+
"resolver": "custom.formatISO8601"
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// ❌ WRONG - Inline transformation logic
|
|
1626
|
+
const createdOn = new Date(fulfilmentData.createdOn).toISOString();
|
|
1627
|
+
```
|
|
1628
|
+
|
|
1629
|
+
**Why:** Custom resolvers are reusable, testable, and keep mapping config clean.
|
|
1630
|
+
|
|
1631
|
+
### Pattern 3: UniversalMapper Before XMLBuilder
|
|
1632
|
+
|
|
1633
|
+
```typescript
|
|
1634
|
+
// ✅ CORRECT - Transform first, then build XML
|
|
1635
|
+
const mapper = new UniversalMapper(mappingConfig, { customResolvers });
|
|
1636
|
+
const mappingResult = await mapper.map(fulfilmentData);
|
|
1637
|
+
const xmlString = xmlBuilder.build(mappingResult.data, 'FulfilmentExport');
|
|
1638
|
+
|
|
1639
|
+
// ❌ WRONG - Build XML directly from GraphQL data
|
|
1640
|
+
const xmlString = xmlBuilder.build(fulfilmentData, 'FulfilmentExport');
|
|
1641
|
+
```
|
|
1642
|
+
|
|
1643
|
+
**Why:** UniversalMapper handles transformations, validations, and field mapping before XML generation.
|
|
1644
|
+
|
|
1645
|
+
---
|
|
1646
|
+
|
|
1647
|
+
## Testing
|
|
1648
|
+
|
|
1649
|
+
### 1. Unit Tests
|
|
1650
|
+
|
|
1651
|
+
```typescript
|
|
1652
|
+
// src/services/__tests__/xml-export.test.ts
|
|
1653
|
+
import { exportFulfilmentToSFTP } from '../xml-export.service';
|
|
1654
|
+
import mappingConfig from '../../config/fulfilment-xml-mapping.json' with { type: 'json' };
|
|
1655
|
+
|
|
1656
|
+
describe('XML Export Service', () => {
|
|
1657
|
+
test('should transform fulfilment data with UniversalMapper', async () => {
|
|
1658
|
+
const mockFulfilmentData = {
|
|
1659
|
+
ref: 'FF-001',
|
|
1660
|
+
status: 'ALLOCATED',
|
|
1661
|
+
// ... test data
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
// Verify mapping config is loaded
|
|
1665
|
+
expect(mappingConfig).toBeDefined();
|
|
1666
|
+
expect(mappingConfig.fields.Fulfilment).toBeDefined();
|
|
1667
|
+
});
|
|
1668
|
+
});
|
|
1669
|
+
```
|
|
1670
|
+
|
|
1671
|
+
### 2. Mapping Config Validation
|
|
1672
|
+
|
|
1673
|
+
```typescript
|
|
1674
|
+
// src/config/__tests__/mapping-config.test.ts
|
|
1675
|
+
import mappingConfig from '../fulfilment-xml-mapping.json' with { type: 'json' };
|
|
1676
|
+
|
|
1677
|
+
describe('Mapping Configuration', () => {
|
|
1678
|
+
test('should have valid structure', () => {
|
|
1679
|
+
expect(mappingConfig.name).toBe('fulfilment-xml-mapping');
|
|
1680
|
+
expect(mappingConfig.fields).toBeDefined();
|
|
1681
|
+
expect(mappingConfig.fields.Fulfilment).toBeDefined();
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
test('should use custom resolvers for dates', () => {
|
|
1685
|
+
const createdOnField = mappingConfig.fields.Fulfilment.fields.CreatedOn;
|
|
1686
|
+
expect(createdOnField.resolver).toBe('custom.formatISO8601');
|
|
1687
|
+
});
|
|
1688
|
+
});
|
|
1689
|
+
```
|
|
1690
|
+
|
|
1691
|
+
---
|
|
1692
|
+
|
|
1693
|
+
## Production Checklist
|
|
1694
|
+
|
|
1695
|
+
- [ ] Configure `fluentPublicKey` activation variable
|
|
1696
|
+
- [ ] Configure Fluent Commerce connection in Versori
|
|
1697
|
+
- [ ] Configure `sftp_export_server` connection in Versori (Basic Auth with username/password)
|
|
1698
|
+
- [ ] Set SFTP activation variables (host, port, remotePath)
|
|
1699
|
+
- [ ] Verify SFTP remote path exists and is writable
|
|
1700
|
+
- [ ] Create Rubix workflow with SendWebhook action (FULFILMENT events)
|
|
1701
|
+
- [ ] Build Event payload with entityRef, entityType, retailerId
|
|
1702
|
+
- [ ] **Review and customize `config/fulfilment-xml-mapping.json`** for your 3PL schema
|
|
1703
|
+
- [ ] **Add custom resolvers** if needed for complex transformations
|
|
1704
|
+
- [ ] Test webhook signature validation
|
|
1705
|
+
- [ ] Test GraphQL query with real fulfilment ref
|
|
1706
|
+
- [ ] **Test UniversalMapper transformation** with sample data
|
|
1707
|
+
- [ ] **Test with large fulfilment (>100 items)** - Verify pagination works correctly
|
|
1708
|
+
- [ ] Test XML generation with special characters
|
|
1709
|
+
- [ ] Test SFTP upload and verify file on server
|
|
1710
|
+
- [ ] Test error scenarios (invalid signature, missing retailerId, SFTP failure)
|
|
1711
|
+
- [ ] Monitor response times (<100ms for validation)
|
|
1712
|
+
- [ ] Set up alerts for webhook/export failures
|
|
1713
|
+
- [ ] Document 3PL partner SFTP requirements
|
|
1714
|
+
- [ ] Test SFTP connection cleanup (check logs for dispose)
|
|
1715
|
+
- [ ] Verify pagination logs show correct item counts
|
|
1716
|
+
- [ ] **Version control mapping config** (track changes to XML structure)
|
|
1717
|
+
|
|
1718
|
+
---
|
|
1719
|
+
|
|
1720
|
+
## Troubleshooting Guide
|
|
1721
|
+
|
|
1722
|
+
| Issue | Cause | Solution |
|
|
1723
|
+
|-------|-------|----------|
|
|
1724
|
+
| "Invalid webhook signature" | Wrong public key | Verify fluentPublicKey matches Fluent environment |
|
|
1725
|
+
| "Missing retailerId" | Rubix payload incomplete | Add retailerId to Rubix Event payload builder |
|
|
1726
|
+
| "Fulfilment not found" | Invalid ref or permissions | Verify fulfilment exists and user has query permissions |
|
|
1727
|
+
| "Mapping failed" | Invalid mapping config | Validate JSON syntax and field paths in mapping config |
|
|
1728
|
+
| "Custom resolver not found" | Resolver not registered | Ensure customResolvers object includes all resolvers used in mapping |
|
|
1729
|
+
| "SFTP upload failed" | Connection/credentials | Test SFTP manually, verify credentials in connection and path |
|
|
1730
|
+
| "Failed to retrieve SFTP credentials" | Connection not configured | Ensure `sftp_export_server` connection exists with Basic Auth |
|
|
1731
|
+
| "SFTP connection pool exhausted" | Missing dispose() | Verify dispose() is in finally block |
|
|
1732
|
+
| "GraphQL query timeout" | Large dataset | Check pagination logs - pagination handles up to 1000 items |
|
|
1733
|
+
| "Missing items in XML" | Fulfilment >1000 items | Increase maxPages limit or implement chunked export |
|
|
1734
|
+
| "XML structure mismatch" | Mapping config outdated | Update `config/fulfilment-xml-mapping.json` to match 3PL schema |
|
|
1735
|
+
|
|
1736
|
+
---
|
|
1737
|
+
|
|
1738
|
+
## Monitoring & Alerting
|
|
1739
|
+
|
|
1740
|
+
### Success Response
|
|
1741
|
+
|
|
1742
|
+
```json
|
|
1743
|
+
{
|
|
1744
|
+
"success": true,
|
|
1745
|
+
"entityType": "FULFILMENT",
|
|
1746
|
+
"fulfilmentRef": "FF-001",
|
|
1747
|
+
"message": "Webhook validated and export started in background",
|
|
1748
|
+
"timestamp": "2025-01-25T14:30:00.000Z",
|
|
1749
|
+
"correlationId": "act_123",
|
|
1750
|
+
"processingMode": "async"
|
|
1751
|
+
}
|
|
1752
|
+
```
|
|
1753
|
+
|
|
1754
|
+
### Key Metrics
|
|
1755
|
+
|
|
1756
|
+
```typescript
|
|
1757
|
+
const METRICS = {
|
|
1758
|
+
signatureValidationMs: 45,
|
|
1759
|
+
totalResponseTimeMs: 50,
|
|
1760
|
+
graphqlQueryMs: 1200,
|
|
1761
|
+
universalMapperMs: 150,
|
|
1762
|
+
xmlGenerationMs: 50,
|
|
1763
|
+
sftpUploadMs: 980,
|
|
1764
|
+
totalBackgroundMs: 2380,
|
|
1765
|
+
};
|
|
1766
|
+
```
|
|
1767
|
+
|
|
1768
|
+
---
|
|
1769
|
+
|
|
1770
|
+
## Related Documentation
|
|
1771
|
+
|
|
1772
|
+
- [Inline Mapping Template](./template-webhook-rubix-fulfilment-to-sftp-xml-inline.md) - For simple XML structures
|
|
1773
|
+
- [Order Attribute Update Template](./template-webhook-rubix-order-attribute-update.md) - For ORDER webhooks
|
|
1774
|
+
- [Webhook Validation Guide](../../../../02-CORE-GUIDES/webhook-validation/)
|
|
1775
|
+
- [UniversalMapper Guide](../../../../02-CORE-GUIDES/mapping/universal-mapper.md)
|
|
1776
|
+
- [Versori Platform Guide](../../../../04-REFERENCE/platforms/versori/)
|
|
1777
|
+
- [SFTP Data Sources Guide](../../../../02-CORE-GUIDES/data-sources/)
|
|
1778
|
+
|
|
1779
|
+
---
|
|
1780
|
+
|
|
1781
|
+
**Pattern**: Fulfilment webhook → GraphQL query → UniversalMapper transformation → XML generation → SFTP upload
|
|
1782
|
+
**✅ Production-Ready**: Comprehensive template with external mapping, custom resolvers, and all critical fixes applied
|
|
1783
|
+
**Key Learning**: External JSON mapping enables XML structure changes without code modifications, custom resolvers handle complex transformations
|
|
1784
|
+
**Critical**: SFTP dispose() in finally block, retailerId validation, fire-and-forget pattern, UniversalMapper before XMLBuilder
|
|
1785
|
+
|