1+ import crypto from 'node:crypto' ;
12import { expandReferences } from '@openfn/language-common/util' ;
23import * as util from './Utils.js' ;
3- import { getItemsQueryString , insertOutboundShipmentQuery , upsertOutboundShipmentQuery } from './queries.js'
4- import { v4 as uuidv4 } from 'uuid' ;
4+ import {
5+ getItemsQueryString ,
6+ insertOutboundShipmentQuery ,
7+ upsertOutboundShipmentQuery ,
8+ } from './queries.js' ;
59
610/**
711 * State object
@@ -12,7 +16,6 @@ import { v4 as uuidv4 } from 'uuid';
1216 * @private
1317 **/
1418
15-
1619/**
1720 * @typedef {Object } RequestBody
1821 * @property {string } query - The GraphQL query string
@@ -25,7 +28,6 @@ import { v4 as uuidv4 } from 'uuid';
2528 * @property {string } storeId - The msupply store id the list is being fetched from
2629 */
2730
28-
2931/**
3032 * @typedef {Object } InsertOutboundShipmentvariables
3133 * @property {string } otherPartyId - The recieving party id
@@ -38,7 +40,6 @@ import { v4 as uuidv4 } from 'uuid';
3840 * @property {string } storeId - The id of the store the shipment is being made from
3941 */
4042
41-
4243/**
4344 * Get the list of items in the catalogue
4445 * @public
@@ -59,15 +60,14 @@ export function getItemsWithStats(variables) {
5960 let opts = {
6061 body : {
6162 query : getItemsQueryString ,
62- variables : resolvedVariables
63+ variables : resolvedVariables ,
6364 } ,
64- }
65+ } ;
6566 const response = await util . request ( state , opts ) ;
66- return util . prepareNextState ( state , response )
67- }
67+ return util . prepareNextState ( state , response ) ;
68+ } ;
6869}
6970
70-
7171/**
7272 * Create an outbound shipment.
7373 * @public
@@ -89,14 +89,14 @@ export function insertOutboundShipment(variables) {
8989 body : {
9090 query : insertOutboundShipmentQuery ,
9191 variables : {
92- id : uuidv4 ( ) ,
93- ...resolvedVariables
94- }
92+ id : crypto . randomUUID ( ) ,
93+ ...resolvedVariables ,
94+ } ,
9595 } ,
96- }
96+ } ;
9797 const response = await util . request ( state , opts ) ;
98- return util . prepareNextState ( state , response )
99- }
98+ return util . prepareNextState ( state , response ) ;
99+ } ;
100100}
101101
102102/**
@@ -126,16 +126,15 @@ export function upsertOutboundShipment(variables) {
126126 let opts = {
127127 body : {
128128 query : upsertOutboundShipmentQuery ,
129- variables : resolvedVariables
129+ variables : resolvedVariables ,
130130 } ,
131- }
131+ } ;
132132
133133 const response = await util . request ( state , opts ) ;
134- return util . prepareNextState ( state , response )
135- }
134+ return util . prepareNextState ( state , response ) ;
135+ } ;
136136}
137137
138-
139138/**
140139 * Make a generic GraphQL request
141140 * @public
@@ -153,18 +152,19 @@ export function upsertOutboundShipment(variables) {
153152 */
154153export function query ( query , variables = { } ) {
155154 return async state => {
156- const [ resolvedQuery , resolvedVariables ] = expandReferences ( state , query , variables ) ;
157-
158- const response = await util . request (
155+ const [ resolvedQuery , resolvedVariables ] = expandReferences (
159156 state ,
160- {
161- body : {
162- query : resolvedQuery ,
163- variables : resolvedVariables ,
164- } ,
165- }
157+ query ,
158+ variables ,
166159 ) ;
167160
161+ const response = await util . request ( state , {
162+ body : {
163+ query : resolvedQuery ,
164+ variables : resolvedVariables ,
165+ } ,
166+ } ) ;
167+
168168 return util . prepareNextState ( state , response ) ;
169169 } ;
170170}
0 commit comments