@openfn/language-msupply 1.0.0

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/dist/index.js ADDED
@@ -0,0 +1,580 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/Adaptor.js
8
+ var Adaptor_exports = {};
9
+ __export(Adaptor_exports, {
10
+ combine: () => combine,
11
+ cursor: () => cursor,
12
+ dataPath: () => dataPath,
13
+ dataValue: () => dataValue,
14
+ dateFns: () => dateFns,
15
+ each: () => each,
16
+ field: () => field,
17
+ fields: () => fields,
18
+ fn: () => fn,
19
+ fnIf: () => fnIf,
20
+ getItemsWithStats: () => getItemsWithStats,
21
+ group: () => group,
22
+ insertOutboundShipment: () => insertOutboundShipment,
23
+ lastReferenceValue: () => lastReferenceValue,
24
+ merge: () => merge,
25
+ query: () => query,
26
+ scrubEmojis: () => scrubEmojis,
27
+ sourceValue: () => sourceValue,
28
+ upsertOutboundShipment: () => upsertOutboundShipment,
29
+ util: () => util
30
+ });
31
+ import { expandReferences } from "@openfn/language-common/util";
32
+
33
+ // src/Utils.js
34
+ import { composeNextState } from "@openfn/language-common";
35
+ import {
36
+ request as commonRequest,
37
+ logResponse
38
+ } from "@openfn/language-common/util";
39
+ var bearerToken = "";
40
+ var prepareNextState = (state, response) => {
41
+ const { body, ...responseWithoutBody } = response;
42
+ if (!state.references) {
43
+ state.references = [];
44
+ }
45
+ return {
46
+ ...composeNextState(state, response.body),
47
+ response: responseWithoutBody
48
+ };
49
+ };
50
+ var login = async (state) => {
51
+ const { username, password, baseUrl } = state.configuration;
52
+ const opts = {
53
+ headers: {
54
+ "content-type": "application/json"
55
+ },
56
+ baseUrl,
57
+ body: {
58
+ query: `
59
+ query AuthToken ($username: String!, $password: String!) {
60
+ authToken(username: $username, password: $password) {
61
+ ... on AuthToken {
62
+ token
63
+ }
64
+ }
65
+ }
66
+ `,
67
+ variables: {
68
+ username,
69
+ password
70
+ }
71
+ }
72
+ };
73
+ const { body } = await commonRequest("POST", "graphql", opts);
74
+ bearerToken = body.data.authToken.token;
75
+ return body.data.authToken.token;
76
+ };
77
+ var request = async (state, options) => {
78
+ const { baseUrl, token = "" } = state.configuration;
79
+ if (token) {
80
+ bearerToken = token;
81
+ }
82
+ const errors = {
83
+ 404: "Page not found"
84
+ };
85
+ let opts = {
86
+ parseAs: "json",
87
+ errors,
88
+ baseUrl,
89
+ ...options,
90
+ headers: {
91
+ "content-type": "application/json",
92
+ ...options.headers
93
+ }
94
+ };
95
+ if (!bearerToken)
96
+ await login(state);
97
+ opts.headers = { ...opts.headers, "Authorization": `Bearer ${bearerToken}` };
98
+ return commonRequest("POST", "graphql", opts).then(logResponse);
99
+ };
100
+
101
+ // src/queries.js
102
+ var getItemsQueryString = `
103
+ query itemsWithStats($storeId: String!, $key: ItemSortFieldInput!, $isDesc: Boolean, $filter: ItemFilterInput, $first: Int, $offset: Int) {
104
+ items(storeId: $storeId, sort: {key: $key, desc: $isDesc}, filter: $filter, page: {first: $first, offset: $offset}) {
105
+ ... on ItemConnector {
106
+ __typename
107
+ nodes {
108
+ code
109
+ id
110
+ name
111
+ unitName
112
+ defaultPackSize
113
+ availableStockOnHand(storeId: $storeId)
114
+ stats(storeId: $storeId) {
115
+ averageMonthlyConsumption
116
+ availableStockOnHand
117
+ availableMonthsOfStockOnHand
118
+ monthsOfStockOnHand
119
+ totalConsumption
120
+ stockOnHand
121
+ }
122
+ }
123
+ totalCount
124
+ }
125
+ }
126
+ }`;
127
+ var insertOutboundShipmentQuery = `mutation insertOutboundShipment($id: String!, $otherPartyId: String!, $storeId: String!) {
128
+ insertOutboundShipment(
129
+ storeId: $storeId
130
+ input: {id: $id, otherPartyId: $otherPartyId}
131
+ ) {
132
+ __typename
133
+ ... on InvoiceNode {
134
+ id
135
+ invoiceNumber
136
+ }
137
+ ... on InsertOutboundShipmentError {
138
+ __typename
139
+ error {
140
+ description
141
+ ... on OtherPartyNotACustomer {
142
+ __typename
143
+ description
144
+ }
145
+ ... on OtherPartyNotVisible {
146
+ __typename
147
+ description
148
+ }
149
+ description
150
+ }
151
+ }
152
+ ... on NodeError {
153
+ __typename
154
+ error {
155
+ description
156
+ ... on DatabaseError {
157
+ __typename
158
+ description
159
+ fullError
160
+ }
161
+ ... on RecordNotFound {
162
+ __typename
163
+ description
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }`;
169
+ var upsertOutboundShipmentQuery = `mutation upsertOutboundShipment($storeId: String!, $input: BatchOutboundShipmentInput!) {
170
+ batchOutboundShipment(storeId: $storeId, input: $input) {
171
+ __typename
172
+ insertOutboundShipmentUnallocatedLines {
173
+ id
174
+ response {
175
+ ... on InsertOutboundShipmentUnallocatedLineError {
176
+ __typename
177
+ error {
178
+ description
179
+ }
180
+ }
181
+ ... on InvoiceLineNode {
182
+ id
183
+ }
184
+ }
185
+ }
186
+ deleteOutboundShipmentLines {
187
+ id
188
+ response {
189
+ ... on DeleteOutboundShipmentLineError {
190
+ __typename
191
+ error {
192
+ description
193
+ ... on RecordNotFound {
194
+ __typename
195
+ description
196
+ }
197
+ ... on CannotEditInvoice {
198
+ __typename
199
+ description
200
+ }
201
+ ... on ForeignKeyError {
202
+ __typename
203
+ description
204
+ key
205
+ }
206
+ }
207
+ }
208
+ ... on DeleteResponse {
209
+ id
210
+ }
211
+ }
212
+ }
213
+ deleteOutboundShipmentServiceLines {
214
+ id
215
+ response {
216
+ ... on DeleteResponse {
217
+ id
218
+ }
219
+ ... on DeleteOutboundShipmentServiceLineError {
220
+ __typename
221
+ error {
222
+ description
223
+ ... on RecordNotFound {
224
+ __typename
225
+ description
226
+ }
227
+ ... on CannotEditInvoice {
228
+ __typename
229
+ description
230
+ }
231
+ ... on ForeignKeyError {
232
+ __typename
233
+ description
234
+ key
235
+ }
236
+ }
237
+ }
238
+ }
239
+ }
240
+ deleteOutboundShipmentUnallocatedLines {
241
+ id
242
+ response {
243
+ ... on DeleteResponse {
244
+ id
245
+ }
246
+ ... on DeleteOutboundShipmentUnallocatedLineError {
247
+ __typename
248
+ error {
249
+ description
250
+ ... on RecordNotFound {
251
+ __typename
252
+ description
253
+ }
254
+ }
255
+ }
256
+ }
257
+ }
258
+ deleteOutboundShipments {
259
+ id
260
+ response {
261
+ ... on DeleteResponse {
262
+ id
263
+ }
264
+ ... on DeleteOutboundShipmentError {
265
+ __typename
266
+ error {
267
+ description
268
+ ... on RecordNotFound {
269
+ __typename
270
+ description
271
+ }
272
+ ... on CannotDeleteInvoiceWithLines {
273
+ __typename
274
+ description
275
+ }
276
+ ... on CannotEditInvoice {
277
+ __typename
278
+ description
279
+ }
280
+ }
281
+ }
282
+ }
283
+ }
284
+ insertOutboundShipmentLines {
285
+ id
286
+ response {
287
+ ... on InsertOutboundShipmentLineError {
288
+ __typename
289
+ error {
290
+ description
291
+ }
292
+ }
293
+ }
294
+ }
295
+ insertOutboundShipmentServiceLines {
296
+ id
297
+ response {
298
+ ... on InsertOutboundShipmentServiceLineError {
299
+ __typename
300
+ error {
301
+ description
302
+ }
303
+ }
304
+ }
305
+ }
306
+ insertOutboundShipments {
307
+ id
308
+ response {
309
+ ... on InsertOutboundShipmentError {
310
+ __typename
311
+ error {
312
+ description
313
+ }
314
+ }
315
+ ... on NodeError {
316
+ __typename
317
+ error {
318
+ description
319
+ ... on RecordNotFound {
320
+ __typename
321
+ description
322
+ }
323
+ ... on DatabaseError {
324
+ __typename
325
+ description
326
+ fullError
327
+ }
328
+ }
329
+ }
330
+ }
331
+ }
332
+ updateOutboundShipmentLines {
333
+ id
334
+ response {
335
+ ... on UpdateOutboundShipmentLineError {
336
+ __typename
337
+ error {
338
+ description
339
+ ... on RecordNotFound {
340
+ __typename
341
+ description
342
+ }
343
+ ... on CannotEditInvoice {
344
+ __typename
345
+ description
346
+ }
347
+ ... on ForeignKeyError {
348
+ __typename
349
+ description
350
+ key
351
+ }
352
+ ... on LocationIsOnHold {
353
+ __typename
354
+ description
355
+ }
356
+ ... on LocationNotFound {
357
+ __typename
358
+ description
359
+ }
360
+ ... on NotEnoughStockForReduction {
361
+ __typename
362
+ batch {
363
+ ... on NodeError {
364
+ __typename
365
+ error {
366
+ description
367
+ ... on RecordNotFound {
368
+ __typename
369
+ description
370
+ }
371
+ ... on DatabaseError {
372
+ __typename
373
+ description
374
+ fullError
375
+ }
376
+ }
377
+ }
378
+ }
379
+ }
380
+ ... on StockLineAlreadyExistsInInvoice {
381
+ __typename
382
+ description
383
+ }
384
+ ... on StockLineIsOnHold {
385
+ __typename
386
+ description
387
+ }
388
+ }
389
+ }
390
+ }
391
+ }
392
+ updateOutboundShipmentServiceLines {
393
+ id
394
+ response {
395
+ ... on UpdateOutboundShipmentServiceLineError {
396
+ __typename
397
+ error {
398
+ description
399
+ ... on RecordNotFound {
400
+ __typename
401
+ description
402
+ }
403
+ ... on CannotEditInvoice {
404
+ __typename
405
+ description
406
+ }
407
+ ... on ForeignKeyError {
408
+ __typename
409
+ description
410
+ key
411
+ }
412
+ }
413
+ }
414
+ }
415
+ }
416
+ updateOutboundShipmentUnallocatedLines {
417
+ id
418
+ response {
419
+ ... on UpdateOutboundShipmentUnallocatedLineError {
420
+ __typename
421
+ error {
422
+ description
423
+ ... on RecordNotFound {
424
+ __typename
425
+ description
426
+ }
427
+ }
428
+ }
429
+ }
430
+ }
431
+ updateOutboundShipments {
432
+ id
433
+ response {
434
+ ... on UpdateOutboundShipmentError {
435
+ __typename
436
+ error {
437
+ description
438
+ }
439
+ }
440
+ ... on NodeError {
441
+ __typename
442
+ error {
443
+ description
444
+ }
445
+ }
446
+ }
447
+ }
448
+ allocateOutboundShipmentUnallocatedLines {
449
+ id
450
+ response {
451
+ ... on AllocateOutboundShipmentUnallocatedLineError {
452
+ __typename
453
+ error {
454
+ description
455
+ ... on RecordNotFound {
456
+ __typename
457
+ description
458
+ }
459
+ }
460
+ }
461
+ ... on AllocateOutboundShipmentUnallocatedLineNode {
462
+ __typename
463
+ deletes {
464
+ id
465
+ }
466
+ inserts {
467
+ totalCount
468
+ }
469
+ updates {
470
+ totalCount
471
+ }
472
+ }
473
+ }
474
+ }
475
+ }
476
+ }`;
477
+
478
+ // src/Adaptor.js
479
+ import { v4 as uuidv4 } from "uuid";
480
+ import {
481
+ combine,
482
+ cursor,
483
+ dataPath,
484
+ dataValue,
485
+ dateFns,
486
+ each,
487
+ field,
488
+ fields,
489
+ fn,
490
+ fnIf,
491
+ group,
492
+ lastReferenceValue,
493
+ merge,
494
+ scrubEmojis,
495
+ sourceValue,
496
+ util
497
+ } from "@openfn/language-common";
498
+ function getItemsWithStats(variables) {
499
+ return async (state) => {
500
+ const [resolvedVariables] = expandReferences(state, variables);
501
+ let opts = {
502
+ body: {
503
+ query: getItemsQueryString,
504
+ variables: resolvedVariables
505
+ }
506
+ };
507
+ const response = await request(state, opts);
508
+ return prepareNextState(state, response);
509
+ };
510
+ }
511
+ function insertOutboundShipment(variables) {
512
+ return async (state) => {
513
+ const [resolvedVariables] = expandReferences(state, variables);
514
+ let opts = {
515
+ body: {
516
+ query: insertOutboundShipmentQuery,
517
+ variables: {
518
+ id: uuidv4(),
519
+ ...resolvedVariables
520
+ }
521
+ }
522
+ };
523
+ const response = await request(state, opts);
524
+ return prepareNextState(state, response);
525
+ };
526
+ }
527
+ function upsertOutboundShipment(variables) {
528
+ return async (state) => {
529
+ const [resolvedVariables] = expandReferences(state, variables);
530
+ let opts = {
531
+ body: {
532
+ query: upsertOutboundShipmentQuery,
533
+ variables: resolvedVariables
534
+ }
535
+ };
536
+ const response = await request(state, opts);
537
+ return prepareNextState(state, response);
538
+ };
539
+ }
540
+ function query(query2, variables = {}) {
541
+ return async (state) => {
542
+ const [resolvedQuery, resolvedVariables] = expandReferences(state, query2, variables);
543
+ const response = await request(
544
+ state,
545
+ {
546
+ body: {
547
+ query: resolvedQuery,
548
+ variables: resolvedVariables
549
+ }
550
+ }
551
+ );
552
+ return prepareNextState(state, response);
553
+ };
554
+ }
555
+
556
+ // src/index.js
557
+ var src_default = Adaptor_exports;
558
+ export {
559
+ combine,
560
+ cursor,
561
+ dataPath,
562
+ dataValue,
563
+ dateFns,
564
+ src_default as default,
565
+ each,
566
+ field,
567
+ fields,
568
+ fn,
569
+ fnIf,
570
+ getItemsWithStats,
571
+ group,
572
+ insertOutboundShipment,
573
+ lastReferenceValue,
574
+ merge,
575
+ query,
576
+ scrubEmojis,
577
+ sourceValue,
578
+ upsertOutboundShipment,
579
+ util
580
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@openfn/language-msupply",
3
+ "version": "1.0.0",
4
+ "description": "OpenFn msupply adaptor",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./types/index.d.ts",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "author": "Open Function Group",
15
+ "license": "LGPLv3",
16
+ "files": [
17
+ "dist/",
18
+ "types/",
19
+ "ast.json",
20
+ "configuration-schema.json"
21
+ ],
22
+ "dependencies": {
23
+ "uuid": "^11.1.0",
24
+ "@openfn/language-common": "2.3.2"
25
+ },
26
+ "devDependencies": {
27
+ "assertion-error": "2.0.0",
28
+ "chai": "4.3.6",
29
+ "deep-eql": "4.1.1",
30
+ "esno": "^0.16.3",
31
+ "mocha": "^10.7.3",
32
+ "rimraf": "3.0.2",
33
+ "undici": "^5.22.1"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/openfn/adaptors.git"
38
+ },
39
+ "types": "types/index.d.ts",
40
+ "main": "dist/index.cjs",
41
+ "scripts": {
42
+ "build": "pnpm clean && build-adaptor msupply",
43
+ "test": "mocha --experimental-specifier-resolution=node --no-warnings",
44
+ "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
45
+ "clean": "rimraf dist types docs",
46
+ "pack": "pnpm pack --pack-destination ../../dist",
47
+ "lint": "eslint src"
48
+ }
49
+ }