summary: Process the MyClient orders description: "# MyClient Order Pipeline" value: modules: - id: getMyClientProfileSecret value: type: rawscript content: > import * as wmill from "windmill-client" export async function main(profileName: string) { const data = await wmill.getVariable(`f/myclient_order_sync/myclient_profile_secrets-${profileName}`) return JSON.parse(data) // In subsequent scripts, you may refer to each row/value returned by the trigger script using // 'flow_input.iter.value' } language: bun input_transforms: profileName: expr: flow_input.myclientProfile type: javascript assets: [] - id: accessTokenResponse value: path: f/myclient_order_sync/accessTokenResponseV2 type: script is_trigger: false input_transforms: authVar: expr: results.getMyClientProfileSecret type: javascript profileName: expr: flow_input.myclientProfile type: javascript summary: Save MyClient Session token as bearer token and state - id: profileBranching value: type: branchone default: - id: purchaseOrders_ABC retry: constant: seconds: 5 attempts: 3 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/gqlQuery type: script is_trigger: false input_transforms: api: expr: "" type: static value: $res:f/myclient_order_sync/myclient-fetcher-ABC limit: expr: flow_input.limit type: javascript fromDate: expr: "try {\r return variable(`f/myclient_order_sync/last-fetched-po-date-${flow\ _input.myclientProfile}`);\r }catch(err){\r \ return null\r }" type: javascript poNumbers: expr: flow_input.poNumbers type: javascript sortOrder: type: static value: null hasResponse: expr: flow_input.hasResponse type: javascript continue_on_error: false branches: - expr: flow_input.myclientProfile === "CA" modules: - id: purchareOrders_CA retry: constant: seconds: 5 attempts: 3 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/gqlQuery type: script is_trigger: false input_transforms: api: type: static value: $res:f/myclient_order_sync/myclient-fetcher-CA limit: expr: flow_input.limit type: javascript fromDate: expr: "try {\r return variable(`f/myclient_order_sync/last-fetched-po-date-${\ flow_input.myclientProfile}`);\r }catch(err){\r \ return null\r }" type: javascript poNumbers: expr: flow_input.poNumbers type: javascript sortOrder: type: static value: null hasResponse: expr: flow_input.hasResponse type: javascript continue_on_error: false summary: MyClient Profile is Canada parallel: true skip_failure: true - expr: flow_input.myclientProfile === "GBA" modules: - id: purchaseOrders_GBA retry: constant: seconds: 5 attempts: 3 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/gqlQuery type: script is_trigger: false input_transforms: api: expr: "" type: static value: $res:f/myclient_order_sync/myclient-fetcher-GBA limit: expr: flow_input.limit type: javascript fromDate: expr: "try {\r return variable(`f/myclient_order_sync/last-fetched-po-date-${\ flow_input.myclientProfile}`);\r }catch(err){\r \ return null\r }" type: javascript poNumbers: expr: flow_input.poNumbers type: javascript sortOrder: type: static value: null hasResponse: expr: flow_input.hasResponse type: javascript continue_on_error: false summary: MyClient Profile is Profile2 parallel: true skip_failure: true summary: "" - id: purchaseOrderItem value: type: forloopflow modules: - id: lastFetchedPoDate value: lock: > { "dependencies": { "windmill-client": "latest" } } //bun.lock { "lockfileVersion": 1, "workspaces": { "": { "dependencies": { "windmill-client": "latest", }, }, }, "packages": { "windmill-client": ["windmill-client@1.496.3", "", {}, "sha512-DBmfcpHw4qRdkqLUPZQA82QERMAjdcPb7ff3KDzs8JNAA9b1v2NGlVqi8b12z0BqLVlJOwjVz3ngZr/8uQ+vWw=="], } } type: rawscript content: | import * as wmill from "windmill-client" export async function main(x: string) { return x } language: bun input_transforms: x: type: static assets: [] summary: Setting default variables and states for flow continue_on_error: false - id: stepA mock: enabled: false return_value: [] retry: constant: seconds: 10 attempts: 5 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/fetch-myclient-order-details type: script is_trigger: false input_transforms: database: type: static value: $res:f/myclient_order_sync/postgre_db_neondb partNumbers: expr: flow_input.iter.value.products.map((product) => product?.partNumber) type: javascript value: [] continue_on_error: false - id: supplier retry: constant: seconds: 10 attempts: 5 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/fetch-myorg-suppliers type: script is_trigger: false input_transforms: database: type: static value: $res:f/myclient_order_sync/postgre_db_neondb supplierNo: expr: Number(flow_input.iter.value.a.b.id) type: javascript timeout: 180 continue_on_error: false - id: items value: path: f/myclient_order_sync/format-line-Items type: script is_trigger: false input_transforms: products: expr: flow_input.iter.value.products type: javascript value: [] stop_after_if: expr: flow_input.iter.value.products.length === 0 error_message: null skip_if_stopped: false continue_on_error: false - id: orderMappingOutput value: path: f/myclient_order_sync/fetch-myclient-order-mapping type: script is_trigger: false input_transforms: region: expr: flow_input.iter.value.state type: javascript value: "" country: expr: flow_input.iter.value.country type: javascript value: "" database: type: static value: $res:f/myclient_order_sync/postgre_db_neondb continue_on_error: false - id: getCATaxCode value: path: f/myclient_order_sync/getCATaxCode type: script is_trigger: false input_transforms: countryCode: expr: flow_input.myclientProfile type: javascript provinceCode: expr: flow_input.iter.value.shipTo.state type: javascript continue_on_error: false - id: myorgOrderA value: path: f/myclient_order_sync/prepare-myorg-order-payload type: script is_trigger: false input_transforms: input: expr: results.stepA type: javascript value: [] continue_on_error: false - id: myorgOrderB value: path: f/myclient_order_sync/submit-myorg-itemsa-payload type: script is_trigger: false input_transforms: myorgOrder: expr: results.myorgOrderA type: javascript value: null supplier_token: expr: results.supplier[0].myorg_api_token type: javascript continue_on_error: false - id: myorgOrderC value: type: rawscript content: > //native //you can add proxy support using //proxy http(s)://host:port // native scripts are bun scripts that are executed on native workers and can be parallelized // only fetch is allowed, but imports will work as long as they also use only fetch and the standard lib //import * as wmill from "windmill-client" export async function main(example_input: number = 3) { // "3" is the default value of example_input, it can be overriden with code or using the UI const res = await fetch(`https://jsonplaceholder.typicode.com/todos/${example_input}`, { headers: { "Content-Type": "application/json" }, }); return res.json(); } language: bunnative input_transforms: example_input: type: static value: 3 assets: [] - id: transactionStatusBranching value: type: branchone default: - id: transactionStatus_ABC retry: constant: seconds: 5 attempts: 3 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/accept-myclient-order type: script is_trigger: false input_transforms: api: type: static value: $res:f/myclient_order_sync/myclient-fetcher-ABC poNumber: expr: flow_input.iter.value.poNumber type: javascript items: expr: results.items type: javascript shipSpeed: expr: flow_input.iter.value.shippingInfo.shipSpeed type: javascript continue_on_error: false branches: - expr: flow_input.myclientProfile === "CA" modules: - id: transactionStatus_CA retry: constant: seconds: 5 attempts: 3 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/accept-myclient-order type: script is_trigger: false input_transforms: api: type: static value: $res:f/myclient_order_sync/myclient-fetcher-CA poNumber: expr: flow_input.iter.value.poNumber type: javascript items: expr: results.items type: javascript shipSpeed: expr: flow_input.iter.value.shippingInfo.shipSpeed type: javascript continue_on_error: false summary: MyClient Profile is Profile1 parallel: true skip_failure: true - expr: flow_input.myclientProfile === "GBA" modules: - id: transactionStatus_GBA retry: constant: seconds: 5 attempts: 3 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/accept-myclient-order type: script is_trigger: false input_transforms: api: type: static value: $res:f/myclient_order_sync/myclient-fetcher-GBA poNumber: expr: flow_input.iter.value.poNumber type: javascript value: "" items: expr: results.items type: javascript shipSpeed: expr: flow_input.iter.value.shippingInfo.shipSpeed type: javascript value: null continue_on_error: false summary: MyClient Profile is Profile2 parallel: true skip_failure: true summary: "" - id: isOrderAccepted value: path: f/myclient_order_sync/process-myclient-order-details/isOrderAccepted type: script is_trigger: false input_transforms: expectedStatus: type: static value: NEW transactionStatus: expr: previous_result.status type: javascript summary: Sets flow and order state for myorgOrder continue_on_error: false - id: d retry: constant: seconds: 10 attempts: 5 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: lock: > { "dependencies": { "windmill-client": "latest" } } //bun.lock { "lockfileVersion": 1, "workspaces": { "": { "dependencies": { "windmill-client": "latest", }, }, }, "packages": { "windmill-client": ["windmill-client@1.492.1", "", {}, "sha512-UR4/XVZNBEdGq9Kaybre5fSHv61M9Sn3bDD+NqVqPkMPlV7lKLWD9vrmGtA898on7wMXvQ86JiAR7Ji4UbHm3A=="], } } type: rawscript content: | import * as wmill from "windmill-client" export async function main(x: string) { return x } language: bun input_transforms: x: type: static concurrency_time_window_s: 0 assets: [] summary: Submits successful order and details to myclient_order continue_on_error: false iterator: expr: "[]" type: javascript parallel: false parallelism: 10 skip_failures: false summary: null cache_ttl: 300 failure_module: id: failure retry: constant: seconds: 60 attempts: 5 exponential: seconds: 0 attempts: 0 multiplier: 1 random_factor: null value: path: f/myclient_order_sync/process-myclient-order-details/failure type: script is_trigger: false input_transforms: name: expr: error.name type: javascript message: expr: error.message type: javascript step_id: expr: error.step_id type: javascript profileName: expr: flow_input.myclientProfile type: javascript value: "" summary: "" continue_on_error: false schema: $schema: https://json-schema.org/draft/2020-12/schema properties: limit: default: 10 type: number description: Default = 10 placeholder: "10" hasResponse: default: false type: boolean description: Whether the purchase order is open poNumbers: default: null nullable: true type: string description: "> Note: Do not use. Although the script/flow does not use this input, its purpose is to ensure the query's input is null. This is to address the Windmill Input schema bug* where an empty input for arrays are `[]` and not `null`" disabled: true title: Purchase Order Number myclientProfile: type: string description: The MyClient Profile setup on the MyClient Partner Portal default: "" enum: - GBA - CA - ABC enumLabels: GBA: Profile2 CA: Profile1 ABC: Profile0 title: MyClient Profile ID nullable: false disableCreate: true required: - myclientProfile type: object order: - limit - hasResponse - poNumbers - myclientProfile