@prismatic-io/components-woo-commerce 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2162 @@
1
+ let _prismatic_io_spectral = require("@prismatic-io/spectral");
2
+ let _prismatic_io_spectral_http = require("@prismatic-io/spectral/http");
3
+ let url = require("url");
4
+ //#region src/connections.ts
5
+ const basic = (0, _prismatic_io_spectral.connection)({
6
+ key: "Basic",
7
+ display: {
8
+ description: "Authenticate requests to Woo Commerce with values obtained from your wordpress site.",
9
+ label: "WooCommerce Basic Auth"
10
+ },
11
+ inputs: {
12
+ username: {
13
+ label: "Consumer Key",
14
+ placeholder: "Consumer Key",
15
+ type: "string",
16
+ required: true,
17
+ shown: true
18
+ },
19
+ password: {
20
+ label: "Consumer Secret",
21
+ placeholder: "Consumer Secret",
22
+ type: "password",
23
+ required: true,
24
+ shown: true
25
+ },
26
+ domain: {
27
+ label: "Domain",
28
+ placeholder: "Domain",
29
+ type: "string",
30
+ example: "www.mySite.com",
31
+ comments: "Provide a string value for the domain of your wordpress site.",
32
+ required: true,
33
+ shown: true
34
+ }
35
+ }
36
+ });
37
+ var connections_default = [basic];
38
+ //#endregion
39
+ //#region src/constants.ts
40
+ const WATERMARK_SKEW_MARGIN_MS = 6e4;
41
+ const WATERMARK_RESOURCES = [
42
+ "orders",
43
+ "products",
44
+ "coupons"
45
+ ];
46
+ const RESOURCE_ENDPOINT_MAP = {
47
+ orders: "/orders",
48
+ customers: "/customers",
49
+ products: "/products",
50
+ coupons: "/coupons"
51
+ };
52
+ //#endregion
53
+ //#region src/util.ts
54
+ const validateConnection = (connection) => {
55
+ if (![basic.key].includes(connection.key)) throw new _prismatic_io_spectral.ConnectionError(connection, `Unsupported connection: ${connection?.key}.`);
56
+ };
57
+ const getBaseUrl = (connection) => {
58
+ return `https://${cleanDomain(_prismatic_io_spectral.util.types.toString(connection.fields.domain))}/wp-json/wc/v3`;
59
+ };
60
+ const cleanDomain = (domain) => {
61
+ if (domain.startsWith("https://")) {
62
+ const { host } = new url.URL(domain);
63
+ return host;
64
+ }
65
+ const { host } = new url.URL(`https://${domain}`);
66
+ return host;
67
+ };
68
+ const getAuthorization = (connection) => {
69
+ if (connection.key === basic.key) return `Basic ${Buffer.from(`${_prismatic_io_spectral.util.types.toString(connection?.fields.username)}:${_prismatic_io_spectral.util.types.toString(connection?.fields.password)}`).toString("base64")}`;
70
+ return `Bearer ${_prismatic_io_spectral.util.types.toString(connection?.token?.access_token)}`;
71
+ };
72
+ const cleanStringInput = (value) => value ? _prismatic_io_spectral.util.types.toString(value) : void 0;
73
+ const cleanKeyValPairListInput = (value) => {
74
+ const data = _prismatic_io_spectral.util.types.keyValPairListToObject(value);
75
+ if (Object.keys(data).length === 0) return {};
76
+ return data;
77
+ };
78
+ const paginateRecords = async (httpClient, url$1, params, fetchAll = false) => {
79
+ const records = [];
80
+ if (fetchAll) {
81
+ const { data, headers } = await httpClient.get(url$1, { params: {
82
+ ...params,
83
+ page: 1
84
+ } });
85
+ records.push(...data);
86
+ const nextPage = headers["x-wp-totalpages"] || headers["X-WP-TotalPages"];
87
+ if (nextPage) {
88
+ const nextPageNumber = _prismatic_io_spectral.util.types.toNumber(nextPage);
89
+ const pages = await Promise.all(Array.from({ length: nextPageNumber - 1 }, (_, i) => httpClient.get(url$1, { params: {
90
+ ...params,
91
+ page: i + 2
92
+ } })));
93
+ records.push(...pages.flatMap((page) => page.data));
94
+ }
95
+ return {
96
+ data: records,
97
+ headers
98
+ };
99
+ }
100
+ const { data, headers } = await httpClient.get(url$1, { params });
101
+ return {
102
+ data,
103
+ headers
104
+ };
105
+ };
106
+ const SECOND_MS = 1e3;
107
+ const POLL_LABEL = "New Records";
108
+ const toIso = (epochMs) => new Date(epochMs).toISOString();
109
+ const truncateToSecond = (iso) => toIso(Math.floor(new Date(iso).getTime() / SECOND_MS) * SECOND_MS);
110
+ const resolveSafeHorizon = (now) => truncateToSecond(toIso(new Date(now).getTime() - WATERMARK_SKEW_MARGIN_MS));
111
+ const toWooDate = (epochMs) => toIso(epochMs).slice(0, 19);
112
+ const fetchWooPage = (client, endpoint) => async ({ afterMs, beforeMs, exclude }) => {
113
+ const { data } = await client.get(endpoint, { params: {
114
+ after: toWooDate(afterMs),
115
+ before: toWooDate(beforeMs),
116
+ dates_are_gmt: true,
117
+ ...exclude.length > 0 ? { exclude: exclude.join(",") } : {},
118
+ per_page: 100,
119
+ page: 1,
120
+ orderby: "date",
121
+ order: "asc"
122
+ } });
123
+ return data;
124
+ };
125
+ const createdSecond = (record) => {
126
+ const gmt = record.date_created_gmt;
127
+ if (typeof gmt !== "string") return null;
128
+ const at = new Date(/Z$|[+-]\d{2}:\d{2}$/.test(gmt) ? gmt : `${gmt}Z`);
129
+ return Number.isNaN(at.getTime()) ? null : Math.floor(at.getTime() / SECOND_MS) * SECOND_MS;
130
+ };
131
+ const sameCursor = (left, right) => JSON.stringify(left) === JSON.stringify(right);
132
+ const noProgress = (cursor) => /* @__PURE__ */ new Error(`${POLL_LABEL} made no progress: a full page of 100 records came back at ${cursor.watermark} and the cursor did not move, so every later request would return the same page. The cursor is left where it was.`);
133
+ const normalRound = async (fetchPage, cursor, horizon) => {
134
+ const watermarkMs = Date.parse(cursor.watermark);
135
+ const horizonMs = Date.parse(horizon);
136
+ if (watermarkMs > horizonMs) return {
137
+ delivered: [],
138
+ cursor,
139
+ drained: true
140
+ };
141
+ const batch = await fetchPage({
142
+ afterMs: watermarkMs - SECOND_MS,
143
+ beforeMs: horizonMs + SECOND_MS,
144
+ exclude: []
145
+ });
146
+ const boundary = new Set(cursor.boundaryIds);
147
+ const delivered = [];
148
+ let latestMs = watermarkMs;
149
+ let latestIds = [];
150
+ for (const record of batch) {
151
+ const at = createdSecond(record);
152
+ if (at === null) {
153
+ delivered.push(record);
154
+ continue;
155
+ }
156
+ if (at < watermarkMs) continue;
157
+ if (!(at === watermarkMs && boundary.has(record.id))) delivered.push(record);
158
+ if (at > latestMs) {
159
+ latestMs = at;
160
+ latestIds = [record.id];
161
+ } else if (at === latestMs) latestIds.push(record.id);
162
+ }
163
+ const stuck = latestMs === watermarkMs;
164
+ const next = stuck ? {
165
+ watermark: cursor.watermark,
166
+ boundaryIds: [.../* @__PURE__ */ new Set([...cursor.boundaryIds, ...latestIds])]
167
+ } : {
168
+ watermark: toIso(latestMs),
169
+ boundaryIds: latestIds
170
+ };
171
+ if (batch.length < 100) return {
172
+ delivered,
173
+ cursor: next,
174
+ drained: true
175
+ };
176
+ if (stuck && latestIds.length === 0) throw noProgress(cursor);
177
+ return {
178
+ delivered,
179
+ cursor: stuck ? {
180
+ ...next,
181
+ tieGroup: {}
182
+ } : next,
183
+ drained: false
184
+ };
185
+ };
186
+ const tieRound = async (fetchPage, cursor, horizon) => {
187
+ if (cursor.boundaryIds.length > 200) throw new Error(`${POLL_LABEL} cannot drain the records created at ${cursor.watermark}: ${cursor.boundaryIds.length} are already delivered and WooCommerce documents no way to page inside one second, so the exclude list would pass its cap of 200. The cursor stays at ${cursor.watermark}, nothing is lost, and every later poll stops here until a maintainer acts.`);
188
+ const watermarkMs = Date.parse(cursor.watermark);
189
+ const batch = await fetchPage({
190
+ afterMs: watermarkMs - SECOND_MS,
191
+ beforeMs: watermarkMs + SECOND_MS,
192
+ exclude: cursor.boundaryIds
193
+ });
194
+ const boundary = new Set(cursor.boundaryIds);
195
+ const delivered = [];
196
+ let pastWindow = false;
197
+ for (const record of batch) {
198
+ const at = createdSecond(record);
199
+ if (at !== null && at > watermarkMs) pastWindow = true;
200
+ if (at !== null && at !== watermarkMs || boundary.has(record.id)) continue;
201
+ delivered.push(record);
202
+ boundary.add(record.id);
203
+ }
204
+ if (batch.length >= 100 && !pastWindow) {
205
+ const next = {
206
+ watermark: cursor.watermark,
207
+ boundaryIds: [...boundary],
208
+ tieGroup: {}
209
+ };
210
+ if (sameCursor(next, cursor)) throw noProgress(cursor);
211
+ return {
212
+ delivered,
213
+ cursor: next,
214
+ drained: false
215
+ };
216
+ }
217
+ if (watermarkMs < Date.parse(horizon)) return {
218
+ delivered,
219
+ cursor: {
220
+ watermark: toIso(watermarkMs + SECOND_MS),
221
+ boundaryIds: []
222
+ },
223
+ drained: false
224
+ };
225
+ return {
226
+ delivered,
227
+ cursor: {
228
+ watermark: cursor.watermark,
229
+ boundaryIds: [...boundary]
230
+ },
231
+ drained: true
232
+ };
233
+ };
234
+ const drainWatermark = async (fetchPage, start, horizon, maxPages) => {
235
+ const records = [];
236
+ let cursor = start;
237
+ for (let page = 0; page < maxPages; page++) {
238
+ const round = cursor.tieGroup ? await tieRound(fetchPage, cursor, horizon) : await normalRound(fetchPage, cursor, horizon);
239
+ records.push(...round.delivered);
240
+ cursor = round.cursor;
241
+ if (round.drained) return {
242
+ records,
243
+ cursor,
244
+ drained: true
245
+ };
246
+ }
247
+ return {
248
+ records,
249
+ cursor,
250
+ drained: false
251
+ };
252
+ };
253
+ const resolveStartCursor = (state, incoming, lookBackDate, now) => incoming ?? state?.cursor ?? {
254
+ watermark: truncateToSecond(state?.lastPolledAt || lookBackDate || now),
255
+ boundaryIds: state?.lastPolledAt ? state.boundaryIds ?? [] : []
256
+ };
257
+ const nextPollingState = (state, start, result) => {
258
+ if (result.drained) return {
259
+ lastPolledAt: result.cursor.watermark,
260
+ boundaryIds: result.cursor.boundaryIds
261
+ };
262
+ return {
263
+ lastPolledAt: state?.lastPolledAt ?? start.watermark,
264
+ ...state?.lastPolledAt && state.boundaryIds ? { boundaryIds: state.boundaryIds } : {},
265
+ cursor: result.cursor
266
+ };
267
+ };
268
+ const pollWatermark = async (client, endpoint, input) => {
269
+ const start = resolveStartCursor(input.state, input.incoming, input.lookBackDate, input.now);
270
+ const result = await drainWatermark(fetchWooPage(client, endpoint), start, resolveSafeHorizon(input.now), input.batching ? 1 : 10);
271
+ return {
272
+ result,
273
+ nextState: nextPollingState(input.state, start, result)
274
+ };
275
+ };
276
+ const fetchCustomersSince = async (client, endpoint, state, lookBackDate, now) => {
277
+ const window = resolvePollWindow(state, lookBackDate, now);
278
+ const { data } = await paginateRecords(client, endpoint, {
279
+ after: window.after,
280
+ per_page: 100,
281
+ orderby: "date",
282
+ order: "asc"
283
+ }, true);
284
+ return trimToWindow(data, window);
285
+ };
286
+ const LOOK_BACK_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
287
+ const INITIAL_SYNC_SEED_MARGIN_MS = 1440 * 60 * 1e3;
288
+ const lookBackDateClean = (value) => {
289
+ const raw = _prismatic_io_spectral.util.types.toString(value).trim();
290
+ if (raw === "") return "";
291
+ const match = raw.match(LOOK_BACK_DATE_PATTERN);
292
+ if (!match) throw new Error(`Look-back Date must be a date in YYYY-MM-DD format. Received: ${raw}`);
293
+ const [, yearStr, monthStr, dayStr] = match;
294
+ const year = _prismatic_io_spectral.util.types.toNumber(yearStr);
295
+ const month = _prismatic_io_spectral.util.types.toNumber(monthStr);
296
+ const day = _prismatic_io_spectral.util.types.toNumber(dayStr);
297
+ const parsed = new Date(Date.UTC(year, month - 1, day));
298
+ if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) throw new Error(`Look-back Date must be a date in YYYY-MM-DD format. Received: ${raw}`);
299
+ if (parsed.getTime() > Date.now()) throw new Error(`Look-back Date cannot be a future date. Received: ${raw}`);
300
+ return parsed.toISOString();
301
+ };
302
+ const resolvePollWindow = (state, lookBackDate, now) => {
303
+ if (state?.lastPolledAt) return { after: state.lastPolledAt };
304
+ if (lookBackDate) return {
305
+ after: (/* @__PURE__ */ new Date(new Date(lookBackDate).getTime() - INITIAL_SYNC_SEED_MARGIN_MS)).toISOString(),
306
+ notBefore: lookBackDate
307
+ };
308
+ return { after: now };
309
+ };
310
+ const trimToWindow = (records, window) => {
311
+ if (!window.notBefore) return records;
312
+ const notBefore = new Date(window.notBefore).getTime();
313
+ return records.filter((record) => {
314
+ const gmt = record.date_created_gmt;
315
+ if (typeof gmt !== "string") return true;
316
+ const createdAt = new Date(/Z$|[+-]\d{2}:\d{2}$/.test(gmt) ? gmt : `${gmt}Z`).getTime();
317
+ return Number.isNaN(createdAt) || createdAt >= notBefore;
318
+ });
319
+ };
320
+ const resolvePollingRecordChanges = (data) => {
321
+ const changesObject = data ?? {
322
+ created: [],
323
+ updated: []
324
+ };
325
+ return [...(changesObject.created ?? []).map((record) => ({
326
+ changeType: "created",
327
+ record
328
+ })), ...(changesObject.updated ?? []).map((record) => ({
329
+ changeType: "updated",
330
+ record
331
+ }))];
332
+ };
333
+ //#endregion
334
+ //#region src/client.ts
335
+ const getClient = (connection, debug = false) => {
336
+ validateConnection(connection);
337
+ return (0, _prismatic_io_spectral_http.createClient)({
338
+ baseUrl: getBaseUrl(connection),
339
+ headers: {
340
+ Authorization: getAuthorization(connection),
341
+ Accepts: "application/json",
342
+ "Content-type": "application/json"
343
+ },
344
+ debug
345
+ });
346
+ };
347
+ //#endregion
348
+ //#region src/errors.ts
349
+ const handleErrors$1 = async (response) => {
350
+ try {
351
+ const { data, headers } = await response;
352
+ return {
353
+ data,
354
+ headers
355
+ };
356
+ } catch (e) {
357
+ const error = e;
358
+ throw new Error(`Your action failed with Status: ${error?.response?.data.data.status} code: ${error?.response?.data?.code} message: ${error?.response?.data?.message}`);
359
+ }
360
+ };
361
+ //#endregion
362
+ //#region src/inputs.ts
363
+ const connectionInput = (0, _prismatic_io_spectral.input)({
364
+ label: "Connection",
365
+ type: "connection",
366
+ comments: "The connection to be used.",
367
+ required: true
368
+ });
369
+ const resultsPerPage = (0, _prismatic_io_spectral.input)({
370
+ label: "Results Per Page",
371
+ type: "string",
372
+ comments: "Provide an integer for the amount of items to be returned.",
373
+ required: false,
374
+ placeholder: "Enter a number",
375
+ example: "100",
376
+ clean: cleanStringInput
377
+ });
378
+ const page = (0, _prismatic_io_spectral.input)({
379
+ label: "Page Number",
380
+ type: "string",
381
+ comments: "Provide an integer for the page number.",
382
+ required: false,
383
+ placeholder: "Enter a page number",
384
+ example: "1",
385
+ clean: cleanStringInput
386
+ });
387
+ const offset = (0, _prismatic_io_spectral.input)({
388
+ label: "Page Offset",
389
+ type: "string",
390
+ comments: "Provide an integer for the page offset since the first page.",
391
+ required: false,
392
+ placeholder: "Enter an offset",
393
+ example: "0",
394
+ clean: cleanStringInput
395
+ });
396
+ const customerId = (0, _prismatic_io_spectral.input)({
397
+ label: "Customer",
398
+ type: "string",
399
+ comments: "Provide a unique identifier for the desired customer. This value should be an id",
400
+ required: true,
401
+ placeholder: "Enter a customer ID",
402
+ example: "someone@example.com",
403
+ clean: _prismatic_io_spectral.util.types.toString,
404
+ dataSource: "selectCustomer"
405
+ });
406
+ const email = (0, _prismatic_io_spectral.input)({
407
+ label: "Email Address",
408
+ type: "string",
409
+ comments: "Provide a valid email address.",
410
+ required: true,
411
+ placeholder: "Enter an email address",
412
+ example: "john.doe@example.com",
413
+ clean: _prismatic_io_spectral.util.types.toString
414
+ });
415
+ const firstName = (0, _prismatic_io_spectral.input)({
416
+ label: "First Name",
417
+ type: "string",
418
+ comments: "Provide a string value for the first name.",
419
+ required: false,
420
+ placeholder: "Enter a first name",
421
+ example: "John"
422
+ });
423
+ const lastName = (0, _prismatic_io_spectral.input)({
424
+ label: "Last Name",
425
+ type: "string",
426
+ comments: "Provide a string value for the last name.",
427
+ required: false,
428
+ placeholder: "Enter a last name",
429
+ example: "Doe"
430
+ });
431
+ const username = (0, _prismatic_io_spectral.input)({
432
+ label: "Username",
433
+ type: "string",
434
+ comments: "Provide a string value for the username.",
435
+ required: false,
436
+ placeholder: "Enter a username",
437
+ example: "john.doe"
438
+ });
439
+ const company = (0, _prismatic_io_spectral.input)({
440
+ label: "Company",
441
+ type: "string",
442
+ comments: "Provide a string value for the company name.",
443
+ required: false,
444
+ placeholder: "Enter a company name",
445
+ example: "Acme Inc."
446
+ });
447
+ const billingAddress1 = (0, _prismatic_io_spectral.input)({
448
+ label: "Billing Address 1",
449
+ type: "string",
450
+ comments: "Provide a string value for the address 1 of the billing address.",
451
+ required: false,
452
+ placeholder: "Enter an address",
453
+ example: "123 Main Street"
454
+ });
455
+ const billingAddress2 = (0, _prismatic_io_spectral.input)({
456
+ label: "Billing Address 2",
457
+ type: "string",
458
+ comments: "Provide a string value for the address 2 of the billing address.",
459
+ required: false,
460
+ placeholder: "Enter additional address information",
461
+ example: "Suite 100"
462
+ });
463
+ const city = (0, _prismatic_io_spectral.input)({
464
+ label: "Billing City",
465
+ type: "string",
466
+ comments: "Provide a string value for the city of the billing address.",
467
+ required: false,
468
+ placeholder: "Enter a city",
469
+ example: "San Francisco"
470
+ });
471
+ const state = (0, _prismatic_io_spectral.input)({
472
+ label: "State",
473
+ type: "string",
474
+ comments: "Provide a string value for the state of the billing address.",
475
+ required: false,
476
+ placeholder: "Enter a state",
477
+ example: "CA"
478
+ });
479
+ const postalcode = (0, _prismatic_io_spectral.input)({
480
+ label: "Postal Code",
481
+ type: "string",
482
+ comments: "Provide a string value for the postal code of the billing address.",
483
+ required: false,
484
+ placeholder: "Enter a postal code",
485
+ example: "94103"
486
+ });
487
+ const country = (0, _prismatic_io_spectral.input)({
488
+ label: "Country",
489
+ type: "string",
490
+ comments: "Provide a string value for the country of the billing address.",
491
+ required: false,
492
+ placeholder: "Enter a country code",
493
+ example: "US"
494
+ });
495
+ const phone = (0, _prismatic_io_spectral.input)({
496
+ label: "Phone",
497
+ type: "string",
498
+ comments: "Provide a string value for the phone number of the billing address.",
499
+ required: false,
500
+ placeholder: "Enter a phone number",
501
+ example: "+1-555-123-4567"
502
+ });
503
+ const shippingAddress1 = (0, _prismatic_io_spectral.input)({
504
+ label: "Shipping Address 1",
505
+ type: "string",
506
+ comments: "Provide a string value for the address 1 of the shipping address.",
507
+ required: false,
508
+ placeholder: "Enter an address",
509
+ example: "123 Main Street"
510
+ });
511
+ const shippingAddress2 = (0, _prismatic_io_spectral.input)({
512
+ label: "Shipping Address 2",
513
+ type: "string",
514
+ comments: "Provide a string value for the address 2 of the shipping address.",
515
+ required: false,
516
+ placeholder: "Enter additional address information",
517
+ example: "Suite 100"
518
+ });
519
+ const productId = (0, _prismatic_io_spectral.input)({
520
+ label: "Product Id",
521
+ type: "string",
522
+ comments: "Provide a unique identifier of the given product.",
523
+ required: true,
524
+ placeholder: "Enter a product ID",
525
+ example: "100",
526
+ dataSource: "selectProduct"
527
+ });
528
+ const productName = (0, _prismatic_io_spectral.input)({
529
+ label: "Product Name",
530
+ type: "string",
531
+ comments: "Provide a string value for the name of the product.",
532
+ required: false,
533
+ placeholder: "Enter a product name",
534
+ example: "Software Subscription"
535
+ });
536
+ const productType = (0, _prismatic_io_spectral.input)({
537
+ label: "Product Type",
538
+ type: "string",
539
+ comments: "Provide a string value for the type of the product.",
540
+ required: false,
541
+ placeholder: "Enter a product type",
542
+ example: "simple"
543
+ });
544
+ const price = (0, _prismatic_io_spectral.input)({
545
+ label: "Price",
546
+ type: "string",
547
+ comments: "Provide a number for the price of the product.",
548
+ required: false,
549
+ placeholder: "Enter a price",
550
+ example: "19.99"
551
+ });
552
+ const description = (0, _prismatic_io_spectral.input)({
553
+ label: "Description",
554
+ type: "string",
555
+ comments: "Provide a description for the product.",
556
+ required: false,
557
+ placeholder: "Enter a product description",
558
+ example: "This is a high quality product with excellent features."
559
+ });
560
+ const summary = (0, _prismatic_io_spectral.input)({
561
+ label: "Summary",
562
+ type: "string",
563
+ comments: "Provide a short summary for the product details.",
564
+ required: false,
565
+ placeholder: "Enter a product summary",
566
+ example: "High quality product with great value."
567
+ });
568
+ const values = (0, _prismatic_io_spectral.input)({
569
+ label: "Optional Values",
570
+ type: "string",
571
+ collection: "keyvaluelist",
572
+ comments: "For each item, provide an optional key value pair to be injected into the request body.",
573
+ required: false
574
+ });
575
+ const categories = (0, _prismatic_io_spectral.input)({
576
+ label: "Categories",
577
+ type: "code",
578
+ comments: "For each item, provide an id of a category that the product belongs to.",
579
+ required: false,
580
+ language: "json",
581
+ placeholder: "Enter category IDs",
582
+ example: `[
583
+ {
584
+ "id": 9
585
+ },
586
+ {
587
+ "id": 14
588
+ }
589
+ ]`
590
+ });
591
+ const images = (0, _prismatic_io_spectral.input)({
592
+ label: "Images",
593
+ type: "code",
594
+ language: "json",
595
+ comments: "For each item, provide a link to the image stored in your media library",
596
+ required: false,
597
+ placeholder: "Enter image URLs",
598
+ example: `[
599
+ {
600
+ "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
601
+ },
602
+ {
603
+ "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
604
+ }
605
+ ]`
606
+ });
607
+ const period = (0, _prismatic_io_spectral.input)({
608
+ label: "Period",
609
+ type: "string",
610
+ comments: "Provide a value for the sales period. Default is today's date.",
611
+ required: false,
612
+ model: [
613
+ {
614
+ label: "Week",
615
+ value: "week"
616
+ },
617
+ {
618
+ label: "Month",
619
+ value: "month"
620
+ },
621
+ {
622
+ label: "Last Month",
623
+ value: "last_month"
624
+ },
625
+ {
626
+ label: "Year",
627
+ value: "year"
628
+ }
629
+ ]
630
+ });
631
+ const minDate = (0, _prismatic_io_spectral.input)({
632
+ label: "Start Date",
633
+ type: "string",
634
+ comments: "Return sales for a specific start date, the date need to be in the YYYY-MM-DD format.",
635
+ required: false,
636
+ placeholder: "Enter a date (YYYY-MM-DD)",
637
+ example: "2024-01-15"
638
+ });
639
+ const maxDate = (0, _prismatic_io_spectral.input)({
640
+ label: "End Date",
641
+ type: "string",
642
+ comments: "Return sales for a specific end date, the date need to be in the YYYY-MM-DD format.",
643
+ required: false,
644
+ placeholder: "Enter a date (YYYY-MM-DD)",
645
+ example: "2024-12-31"
646
+ });
647
+ const search = (0, _prismatic_io_spectral.input)({
648
+ label: "Search",
649
+ type: "string",
650
+ comments: "Search for a specific string.",
651
+ required: false,
652
+ placeholder: "Enter a search term",
653
+ example: "Product name",
654
+ clean: cleanStringInput
655
+ });
656
+ const before = (0, _prismatic_io_spectral.input)({
657
+ label: "Before",
658
+ type: "string",
659
+ comments: "Limit response to resources published before a given ISO8601 compliant date.",
660
+ required: false,
661
+ placeholder: "Enter an ISO8601 date",
662
+ example: "2024-01-15T10:30:00Z",
663
+ clean: cleanStringInput
664
+ });
665
+ const after = (0, _prismatic_io_spectral.input)({
666
+ label: "After",
667
+ type: "string",
668
+ comments: "Limit response to resources published after a given ISO8601 compliant date.",
669
+ required: false,
670
+ placeholder: "Enter an ISO8601 date",
671
+ example: "2024-01-15T10:30:00Z",
672
+ clean: cleanStringInput
673
+ });
674
+ const orderId = (0, _prismatic_io_spectral.input)({
675
+ label: "Order Id",
676
+ type: "string",
677
+ comments: "Provide the unique identifier of the order.",
678
+ required: true,
679
+ placeholder: "Enter an order ID",
680
+ example: "100",
681
+ dataSource: "selectOrder"
682
+ });
683
+ const paymentMethod = (0, _prismatic_io_spectral.input)({
684
+ label: "Payment Method Key",
685
+ type: "string",
686
+ comments: "Provide the unique identifier of the payment method.",
687
+ required: false,
688
+ placeholder: "Enter a payment method key",
689
+ example: "bacs"
690
+ });
691
+ const paymentMethodTitle = (0, _prismatic_io_spectral.input)({
692
+ label: "Payment Method Title",
693
+ type: "string",
694
+ comments: "Provide the display title of the payment method.",
695
+ required: false,
696
+ placeholder: "Enter a payment method title",
697
+ example: "Direct Bank Transfer"
698
+ });
699
+ const isPaid = (0, _prismatic_io_spectral.input)({
700
+ label: "Is Paid",
701
+ type: "boolean",
702
+ comments: "Determines if the order has been paid for.",
703
+ required: true
704
+ });
705
+ const lineItems = (0, _prismatic_io_spectral.input)({
706
+ label: "Line Items",
707
+ type: "code",
708
+ language: "json",
709
+ comments: "Provide a JSON array, with objects each specifying details of the line item.",
710
+ required: false,
711
+ placeholder: "Enter line items",
712
+ example: `[
713
+ {
714
+ "product_id": 93,
715
+ "quantity": 2
716
+ },
717
+ {
718
+ "product_id": 22,
719
+ "variation_id": 23,
720
+ "quantity": 1
721
+ }
722
+ ]`
723
+ });
724
+ const shippingLines = (0, _prismatic_io_spectral.input)({
725
+ label: "Shipping Lines",
726
+ type: "code",
727
+ comments: "Provide a JSON array, with objects each specifying shipping details",
728
+ required: false,
729
+ language: "json",
730
+ placeholder: "Enter shipping details",
731
+ example: `[
732
+ {
733
+ "method_id": "flat_rate",
734
+ "method_title": "Flat Rate",
735
+ "total": "10.00"
736
+ }
737
+ ]`
738
+ });
739
+ const categoryName = (0, _prismatic_io_spectral.input)({
740
+ label: "Category Name",
741
+ type: "string",
742
+ comments: "Provide a name for the category.",
743
+ required: true,
744
+ placeholder: "Enter a category name",
745
+ example: "Electronics"
746
+ });
747
+ const categoryId = (0, _prismatic_io_spectral.input)({
748
+ label: "Category Id",
749
+ type: "string",
750
+ comments: "Provide a unique identifier of an existing category.",
751
+ required: true,
752
+ placeholder: "Enter a category ID",
753
+ example: "100",
754
+ dataSource: "selectProductCategory"
755
+ });
756
+ const refundId = (0, _prismatic_io_spectral.input)({
757
+ label: "Refund Id",
758
+ type: "string",
759
+ comments: "Provide a unique identifier of an existing refund.",
760
+ required: true,
761
+ placeholder: "Enter a refund ID",
762
+ example: "100",
763
+ dataSource: "selectRefund"
764
+ });
765
+ const imageLink = (0, _prismatic_io_spectral.input)({
766
+ label: "Image Link",
767
+ type: "string",
768
+ comments: "Provide a link to an image to represent your category.",
769
+ required: false,
770
+ placeholder: "Enter an image URL",
771
+ example: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
772
+ });
773
+ const refundAmount = (0, _prismatic_io_spectral.input)({
774
+ label: "Refund Amount",
775
+ type: "string",
776
+ comments: "Provide a value for the refund amount.",
777
+ required: false,
778
+ placeholder: "Enter a refund amount",
779
+ example: "10.00"
780
+ });
781
+ const params = (0, _prismatic_io_spectral.input)({
782
+ label: "Extra Parameters",
783
+ type: "string",
784
+ collection: "keyvaluelist",
785
+ comments: "Extra parameters to be passed to the request.",
786
+ required: false,
787
+ clean: cleanKeyValPairListInput
788
+ });
789
+ const fetchAll = (0, _prismatic_io_spectral.input)({
790
+ label: "Fetch All",
791
+ type: "boolean",
792
+ comments: "If true, all pages will be fetched.",
793
+ required: false,
794
+ default: "false",
795
+ clean: _prismatic_io_spectral.util.types.toBool
796
+ });
797
+ const resourceType = (0, _prismatic_io_spectral.input)({
798
+ label: "Resource Type",
799
+ type: "string",
800
+ comments: "Select the WooCommerce resource type to poll for new records.",
801
+ required: true,
802
+ model: [
803
+ {
804
+ label: "Orders",
805
+ value: "orders"
806
+ },
807
+ {
808
+ label: "Customers",
809
+ value: "customers"
810
+ },
811
+ {
812
+ label: "Products",
813
+ value: "products"
814
+ },
815
+ {
816
+ label: "Coupons",
817
+ value: "coupons"
818
+ }
819
+ ]
820
+ });
821
+ const lookBackDate = (0, _prismatic_io_spectral.input)({
822
+ label: "Look-back Date",
823
+ placeholder: "Enter look-back date (YYYY-MM-DD)",
824
+ type: "string",
825
+ required: false,
826
+ comments: "The date the initial sync starts from, in YYYY-MM-DD format. Cannot be a future date. Leave empty to start from the first recurrence with no backfill. When set, the initial sync seeds each record created on or after this date once.",
827
+ example: "2026-01-01",
828
+ clean: lookBackDateClean
829
+ });
830
+ //#endregion
831
+ //#region src/actions/categories.ts
832
+ const listProductCategories = (0, _prismatic_io_spectral.action)({
833
+ display: {
834
+ label: "List Product Categories",
835
+ description: "Returns a list of all product categories"
836
+ },
837
+ inputs: {
838
+ connection: connectionInput,
839
+ fetchAll,
840
+ resultsPerPage,
841
+ page,
842
+ offset,
843
+ search,
844
+ before,
845
+ after,
846
+ params
847
+ },
848
+ perform: async ({ debug: { enabled: debug } }, { after, before, connection, page, resultsPerPage, offset, search, params, fetchAll }) => {
849
+ return { data: await paginateRecords(getClient(connection, debug), "/products/categories", {
850
+ per_page: resultsPerPage,
851
+ page,
852
+ offset,
853
+ search,
854
+ before,
855
+ after,
856
+ ...params
857
+ }, fetchAll) };
858
+ }
859
+ });
860
+ const getProductCategory = (0, _prismatic_io_spectral.action)({
861
+ display: {
862
+ label: "Get Product Category",
863
+ description: "Returns the information and metadata of the product category"
864
+ },
865
+ inputs: {
866
+ connection: connectionInput,
867
+ categoryId
868
+ },
869
+ perform: async ({ debug: { enabled: debug } }, params) => {
870
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/products/categories/${params.categoryId}`)) };
871
+ }
872
+ });
873
+ const deleteProductCategory = (0, _prismatic_io_spectral.action)({
874
+ display: {
875
+ label: "Delete Product Category",
876
+ description: "Delete Product Category"
877
+ },
878
+ inputs: {
879
+ connection: connectionInput,
880
+ categoryId
881
+ },
882
+ perform: async ({ debug: { enabled: debug } }, params) => {
883
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/products/categories/${params.categoryId}`)) };
884
+ }
885
+ });
886
+ const createProductCategory = (0, _prismatic_io_spectral.action)({
887
+ display: {
888
+ label: "Create Product Category",
889
+ description: "Create a new product category record"
890
+ },
891
+ inputs: {
892
+ connection: connectionInput,
893
+ categoryName,
894
+ imageLink,
895
+ description
896
+ },
897
+ perform: async ({ debug: { enabled: debug } }, params) => {
898
+ return { data: await handleErrors$1(getClient(params.connection, debug).post(`/products/categories`, {
899
+ name: _prismatic_io_spectral.util.types.toString(params.categoryName),
900
+ description: _prismatic_io_spectral.util.types.toString(params.description),
901
+ image: { src: _prismatic_io_spectral.util.types.toString(params.imageLink) || void 0 }
902
+ })) };
903
+ }
904
+ });
905
+ //#endregion
906
+ //#region src/examplePayloads.ts
907
+ const listProductsExamplePayload = { data: {
908
+ data: [{
909
+ id: 794,
910
+ name: "Premium Quality",
911
+ slug: "premium-quality-19",
912
+ permalink: "https://example.com/product/premium-quality-19/",
913
+ date_created: "2017-03-23T17:01:14",
914
+ date_created_gmt: "2017-03-23T20:01:14",
915
+ date_modified: "2017-03-23T17:01:14",
916
+ date_modified_gmt: "2017-03-23T20:01:14",
917
+ type: "simple",
918
+ status: "publish",
919
+ featured: false,
920
+ catalog_visibility: "visible",
921
+ description: "",
922
+ short_description: "",
923
+ sku: "",
924
+ price: "21.99",
925
+ regular_price: "21.99",
926
+ sale_price: "",
927
+ on_sale: false,
928
+ purchasable: true,
929
+ total_sales: 0,
930
+ virtual: false,
931
+ downloadable: false,
932
+ downloads: [],
933
+ tax_status: "taxable",
934
+ manage_stock: false,
935
+ stock_quantity: null,
936
+ stock_status: "instock",
937
+ categories: [{
938
+ id: 9,
939
+ name: "Clothing",
940
+ slug: "clothing"
941
+ }],
942
+ images: [{
943
+ id: 792,
944
+ date_created: "2017-03-23T14:01:13",
945
+ date_created_gmt: "2017-03-23T20:01:13",
946
+ date_modified: "2017-03-23T14:01:13",
947
+ date_modified_gmt: "2017-03-23T20:01:13",
948
+ src: "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg",
949
+ name: "",
950
+ alt: ""
951
+ }],
952
+ attributes: [],
953
+ meta_data: []
954
+ }],
955
+ headers: {
956
+ server: "nginx",
957
+ "x-wp-total": 2,
958
+ "x-wp-totalpages": 2,
959
+ link: "<https://example.com/wp-json/wc/v3/products?per_page=1&page=2>; rel=\"next\""
960
+ }
961
+ } };
962
+ const listOrdersExamplePayload = { data: {
963
+ data: [{
964
+ id: 727,
965
+ parent_id: 0,
966
+ number: "727",
967
+ order_key: "wc_order_58d2d042d1d",
968
+ created_via: "rest-api",
969
+ version: "3.0.0",
970
+ status: "processing",
971
+ currency: "USD",
972
+ date_created: "2017-03-22T16:28:02",
973
+ date_created_gmt: "2017-03-22T19:28:02",
974
+ date_modified: "2017-03-22T16:28:08",
975
+ date_modified_gmt: "2017-03-22T19:28:08",
976
+ discount_total: "0.00",
977
+ discount_tax: "0.00",
978
+ shipping_total: "10.00",
979
+ shipping_tax: "0.00",
980
+ cart_tax: "1.35",
981
+ total: "29.35",
982
+ total_tax: "1.35",
983
+ prices_include_tax: false,
984
+ customer_id: 0,
985
+ customer_note: "",
986
+ billing: {
987
+ first_name: "John",
988
+ last_name: "Doe",
989
+ company: "",
990
+ address_1: "969 Market",
991
+ address_2: "",
992
+ city: "San Francisco",
993
+ state: "CA",
994
+ postcode: "94103",
995
+ country: "US",
996
+ email: "john.doe@example.com",
997
+ phone: "(555) 555-5555"
998
+ },
999
+ shipping: {
1000
+ first_name: "John",
1001
+ last_name: "Doe",
1002
+ company: "",
1003
+ address_1: "969 Market",
1004
+ address_2: "",
1005
+ city: "San Francisco",
1006
+ state: "CA",
1007
+ postcode: "94103",
1008
+ country: "US"
1009
+ },
1010
+ payment_method: "bacs",
1011
+ payment_method_title: "Direct Bank Transfer",
1012
+ line_items: [{
1013
+ id: 315,
1014
+ name: "Woo Single #1",
1015
+ product_id: 93,
1016
+ variation_id: 0,
1017
+ quantity: 2,
1018
+ tax_class: "",
1019
+ subtotal: "6.00",
1020
+ total: "6.00",
1021
+ total_tax: "0.45",
1022
+ sku: "",
1023
+ price: 3
1024
+ }],
1025
+ shipping_lines: [{
1026
+ id: 317,
1027
+ method_title: "Flat Rate",
1028
+ method_id: "flat_rate",
1029
+ total: "10.00",
1030
+ total_tax: "0.00"
1031
+ }],
1032
+ fee_lines: [],
1033
+ coupon_lines: [],
1034
+ refunds: [],
1035
+ meta_data: []
1036
+ }],
1037
+ headers: {
1038
+ server: "nginx",
1039
+ "x-wp-total": 2,
1040
+ "x-wp-totalpages": 2,
1041
+ link: "<https://example.com/wp-json/wc/v3/orders?per_page=1&page=2>; rel=\"next\""
1042
+ }
1043
+ } };
1044
+ //#endregion
1045
+ //#region src/actions/customers.ts
1046
+ const listCustomers = (0, _prismatic_io_spectral.action)({
1047
+ display: {
1048
+ label: "List Customers",
1049
+ description: "Returns a list of all active customers"
1050
+ },
1051
+ inputs: {
1052
+ connection: connectionInput,
1053
+ fetchAll,
1054
+ resultsPerPage,
1055
+ page,
1056
+ offset,
1057
+ search,
1058
+ before,
1059
+ after,
1060
+ params
1061
+ },
1062
+ perform: async ({ debug: { enabled: debug } }, { after, before, connection, page, resultsPerPage, offset, search, params, fetchAll }) => {
1063
+ return { data: await paginateRecords(getClient(connection, debug), "/customers", {
1064
+ per_page: resultsPerPage,
1065
+ page,
1066
+ offset,
1067
+ search,
1068
+ before,
1069
+ after,
1070
+ ...params
1071
+ }, fetchAll) };
1072
+ },
1073
+ examplePayload: { data: {
1074
+ data: [{
1075
+ id: 25,
1076
+ date_created: "2017-03-21T16:09:28",
1077
+ date_created_gmt: "2017-03-21T19:09:28",
1078
+ date_modified: "2017-03-21T16:09:30",
1079
+ date_modified_gmt: "2017-03-21T19:09:30",
1080
+ email: "john.doe@example.com",
1081
+ first_name: "John",
1082
+ last_name: "Doe",
1083
+ role: "customer",
1084
+ username: "john.doe",
1085
+ billing: {
1086
+ first_name: "John",
1087
+ last_name: "Doe",
1088
+ company: "",
1089
+ address_1: "969 Market",
1090
+ address_2: "",
1091
+ city: "San Francisco",
1092
+ state: "CA",
1093
+ postcode: "94103",
1094
+ country: "US",
1095
+ email: "john.doe@example.com",
1096
+ phone: "(555) 555-5555"
1097
+ },
1098
+ shipping: {
1099
+ first_name: "John",
1100
+ last_name: "Doe",
1101
+ company: "",
1102
+ address_1: "969 Market",
1103
+ address_2: "",
1104
+ city: "San Francisco",
1105
+ state: "CA",
1106
+ postcode: "94103",
1107
+ country: "US"
1108
+ },
1109
+ is_paying_customer: false,
1110
+ avatar_url: "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96",
1111
+ meta_data: []
1112
+ }],
1113
+ headers: {
1114
+ server: "nginx",
1115
+ "x-wp-total": 2,
1116
+ "x-wp-totalpages": 2,
1117
+ link: "<https://example.com/wp-json/wc/v3/customers?per_page=1&page=2>; rel=\"next\""
1118
+ }
1119
+ } }
1120
+ });
1121
+ const getCustomer = (0, _prismatic_io_spectral.action)({
1122
+ display: {
1123
+ label: "Get Customer",
1124
+ description: "Returns the information and metadata of the given user"
1125
+ },
1126
+ inputs: {
1127
+ connection: connectionInput,
1128
+ customerId
1129
+ },
1130
+ perform: async ({ debug: { enabled: debug } }, params) => {
1131
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/customers/${params.customerId}`)) };
1132
+ }
1133
+ });
1134
+ const deleteCustomer = (0, _prismatic_io_spectral.action)({
1135
+ display: {
1136
+ label: "Delete Customer",
1137
+ description: "Delete the information and metadata of the given user"
1138
+ },
1139
+ inputs: {
1140
+ connection: connectionInput,
1141
+ customerId
1142
+ },
1143
+ perform: async ({ debug: { enabled: debug } }, params) => {
1144
+ return { data: await handleErrors$1(getClient(params.connection, debug).delete(`/customers/${params.customerId}`)) };
1145
+ }
1146
+ });
1147
+ const createCustomer = (0, _prismatic_io_spectral.action)({
1148
+ display: {
1149
+ label: "Create Customer",
1150
+ description: "Create a new customer record"
1151
+ },
1152
+ inputs: {
1153
+ connection: connectionInput,
1154
+ email,
1155
+ phone,
1156
+ username,
1157
+ firstName,
1158
+ lastName,
1159
+ company,
1160
+ billingAddress1,
1161
+ billingAddress2,
1162
+ city,
1163
+ state,
1164
+ country,
1165
+ postalcode,
1166
+ shippingAddress1,
1167
+ shippingAddress2,
1168
+ shippingCity: {
1169
+ ...city,
1170
+ label: "Shipping City"
1171
+ },
1172
+ shippingState: {
1173
+ ...state,
1174
+ label: "Shipping State"
1175
+ },
1176
+ shippingCountry: {
1177
+ ...country,
1178
+ label: "Shipping Country"
1179
+ },
1180
+ shippingPostalCode: {
1181
+ ...postalcode,
1182
+ label: "Shipping Postal Code"
1183
+ },
1184
+ values
1185
+ },
1186
+ perform: async ({ debug: { enabled: debug } }, params) => {
1187
+ const client = getClient(params.connection, debug);
1188
+ const request = {
1189
+ ..._prismatic_io_spectral.util.types.keyValPairListToObject(params.values),
1190
+ email: _prismatic_io_spectral.util.types.toString(params.email) || void 0,
1191
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1192
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1193
+ username: _prismatic_io_spectral.util.types.toString(params.username) || void 0,
1194
+ billing: {
1195
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1196
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1197
+ company: _prismatic_io_spectral.util.types.toString(params.company) || void 0,
1198
+ address_1: _prismatic_io_spectral.util.types.toString(params.billingAddress1) || void 0,
1199
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1200
+ city: _prismatic_io_spectral.util.types.toString(params.city) || void 0,
1201
+ state: _prismatic_io_spectral.util.types.toString(params.state) || void 0,
1202
+ postcode: _prismatic_io_spectral.util.types.toString(params.postalcode) || void 0,
1203
+ country: _prismatic_io_spectral.util.types.toString(params.country) || void 0,
1204
+ email: _prismatic_io_spectral.util.types.toString(params.email) || void 0,
1205
+ phone: _prismatic_io_spectral.util.types.toString(params.phone) || void 0
1206
+ },
1207
+ shipping: {
1208
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1209
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1210
+ company: _prismatic_io_spectral.util.types.toString(params.company) || void 0,
1211
+ address_1: _prismatic_io_spectral.util.types.toString(params.shippingAddress1) || void 0,
1212
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1213
+ city: _prismatic_io_spectral.util.types.toString(params.shippingCity) || void 0,
1214
+ state: _prismatic_io_spectral.util.types.toString(params.shippingState) || void 0,
1215
+ postcode: _prismatic_io_spectral.util.types.toString(params.shippingPostalCode) || void 0,
1216
+ country: _prismatic_io_spectral.util.types.toString(params.shippingCountry) || void 0
1217
+ }
1218
+ };
1219
+ return { data: await handleErrors$1(client.post(`/customers`, request)) };
1220
+ }
1221
+ });
1222
+ const updateCustomer = (0, _prismatic_io_spectral.action)({
1223
+ display: {
1224
+ label: "Update Customer",
1225
+ description: "Update an existing customer record"
1226
+ },
1227
+ inputs: {
1228
+ connection: connectionInput,
1229
+ customerId,
1230
+ email: {
1231
+ ...email,
1232
+ required: false
1233
+ },
1234
+ phone,
1235
+ username,
1236
+ firstName,
1237
+ lastName,
1238
+ company,
1239
+ billingAddress1,
1240
+ billingAddress2,
1241
+ billingCity: {
1242
+ ...city,
1243
+ label: "Billing City"
1244
+ },
1245
+ billingState: {
1246
+ ...state,
1247
+ label: "Billing State"
1248
+ },
1249
+ billingPostalCode: {
1250
+ ...postalcode,
1251
+ label: "Billing Postal Code"
1252
+ },
1253
+ billingCountry: {
1254
+ ...country,
1255
+ label: "Billing Country"
1256
+ },
1257
+ shippingAddress1,
1258
+ shippingAddress2,
1259
+ shippingCity: {
1260
+ ...city,
1261
+ label: "Shipping City"
1262
+ },
1263
+ shippingState: {
1264
+ ...state,
1265
+ label: "Shipping State"
1266
+ },
1267
+ shippingCountry: {
1268
+ ...country,
1269
+ label: "Shipping Country"
1270
+ },
1271
+ shippingPostalCode: {
1272
+ ...postalcode,
1273
+ label: "Shipping Postal Code"
1274
+ }
1275
+ },
1276
+ perform: async ({ debug: { enabled: debug } }, params) => {
1277
+ const client = getClient(params.connection, debug);
1278
+ const request = {
1279
+ email: _prismatic_io_spectral.util.types.toString(params.email) || void 0,
1280
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1281
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1282
+ username: _prismatic_io_spectral.util.types.toString(params.username) || void 0,
1283
+ billing: {
1284
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1285
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1286
+ company: _prismatic_io_spectral.util.types.toString(params.company) || void 0,
1287
+ address_1: _prismatic_io_spectral.util.types.toString(params.billingAddress1) || void 0,
1288
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1289
+ city: _prismatic_io_spectral.util.types.toString(params.billingCity) || void 0,
1290
+ state: _prismatic_io_spectral.util.types.toString(params.billingState) || void 0,
1291
+ postcode: _prismatic_io_spectral.util.types.toString(params.billingPostalCode) || void 0,
1292
+ country: _prismatic_io_spectral.util.types.toString(params.billingCountry) || void 0,
1293
+ email: _prismatic_io_spectral.util.types.toString(params.email) || void 0,
1294
+ phone: _prismatic_io_spectral.util.types.toString(params.phone) || void 0
1295
+ },
1296
+ shipping: {
1297
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1298
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1299
+ company: _prismatic_io_spectral.util.types.toString(params.company) || void 0,
1300
+ address_1: _prismatic_io_spectral.util.types.toString(params.shippingAddress1) || void 0,
1301
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1302
+ city: _prismatic_io_spectral.util.types.toString(params.shippingCity) || void 0,
1303
+ state: _prismatic_io_spectral.util.types.toString(params.shippingState) || void 0,
1304
+ postcode: _prismatic_io_spectral.util.types.toString(params.shippingPostalCode) || void 0,
1305
+ country: _prismatic_io_spectral.util.types.toString(params.shippingCountry) || void 0
1306
+ }
1307
+ };
1308
+ return { data: await handleErrors$1(client.put(`/customers/${params.customerId}`, request)) };
1309
+ }
1310
+ });
1311
+ //#endregion
1312
+ //#region src/actions/orders.ts
1313
+ const createOrder = (0, _prismatic_io_spectral.action)({
1314
+ display: {
1315
+ label: "Create Order",
1316
+ description: "Create a new order record"
1317
+ },
1318
+ inputs: {
1319
+ connection: connectionInput,
1320
+ lineItems,
1321
+ shippingLines,
1322
+ paymentMethod,
1323
+ paymentMethodTitle,
1324
+ isPaid,
1325
+ email: {
1326
+ ...email,
1327
+ required: false
1328
+ },
1329
+ phone,
1330
+ firstName,
1331
+ lastName,
1332
+ billingAddress1,
1333
+ billingAddress2,
1334
+ billingCity: {
1335
+ ...city,
1336
+ label: "Billing City"
1337
+ },
1338
+ billingState: {
1339
+ ...state,
1340
+ label: "Billing State"
1341
+ },
1342
+ billingPostalCode: {
1343
+ ...postalcode,
1344
+ label: "Billing Postal Code"
1345
+ },
1346
+ billingCountry: {
1347
+ ...country,
1348
+ label: "Billing Country"
1349
+ },
1350
+ shippingAddress1,
1351
+ shippingAddress2,
1352
+ shippingCity: {
1353
+ ...city,
1354
+ label: "Shipping City"
1355
+ },
1356
+ shippingState: {
1357
+ ...state,
1358
+ label: "Shipping State"
1359
+ },
1360
+ shippingCountry: {
1361
+ ...country,
1362
+ label: "Shipping Country"
1363
+ },
1364
+ shippingPostalCode: {
1365
+ ...postalcode,
1366
+ label: "Shipping Postal Code"
1367
+ },
1368
+ values
1369
+ },
1370
+ perform: async ({ debug: { enabled: debug } }, params) => {
1371
+ return { data: await handleErrors$1(getClient(params.connection, debug).post(`/orders`, {
1372
+ ..._prismatic_io_spectral.util.types.keyValPairListToObject(params.values),
1373
+ payment_method: _prismatic_io_spectral.util.types.toString(params.paymentMethod) || void 0,
1374
+ payment_method_title: _prismatic_io_spectral.util.types.toString(params.paymentMethodTitle) || void 0,
1375
+ set_paid: _prismatic_io_spectral.util.types.toBool(params.isPaid),
1376
+ billing: {
1377
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1378
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1379
+ address_1: _prismatic_io_spectral.util.types.toString(params.billingAddress1) || void 0,
1380
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1381
+ city: _prismatic_io_spectral.util.types.toString(params.billingCity) || void 0,
1382
+ state: _prismatic_io_spectral.util.types.toString(params.billingState) || void 0,
1383
+ postcode: _prismatic_io_spectral.util.types.toString(params.billingPostalCode) || void 0,
1384
+ country: _prismatic_io_spectral.util.types.toString(params.billingCountry) || void 0,
1385
+ email: _prismatic_io_spectral.util.types.toString(params.email) || void 0,
1386
+ phone: _prismatic_io_spectral.util.types.toString(params.phone) || void 0
1387
+ },
1388
+ shipping: {
1389
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1390
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1391
+ address_1: _prismatic_io_spectral.util.types.toString(params.shippingAddress1) || void 0,
1392
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1393
+ city: _prismatic_io_spectral.util.types.toString(params.shippingCity) || void 0,
1394
+ state: _prismatic_io_spectral.util.types.toString(params.shippingState) || void 0,
1395
+ postcode: _prismatic_io_spectral.util.types.toString(params.shippingPostalCode) || void 0,
1396
+ country: _prismatic_io_spectral.util.types.toString(params.shippingCountry) || void 0
1397
+ },
1398
+ line_items: _prismatic_io_spectral.util.types.toString(params.lineItems) ? JSON.parse(_prismatic_io_spectral.util.types.toString(params.lineItems)) : [],
1399
+ shipping_lines: _prismatic_io_spectral.util.types.toString(params.shippingLines) ? JSON.parse(_prismatic_io_spectral.util.types.toString(params.shippingLines)) : []
1400
+ })) };
1401
+ }
1402
+ });
1403
+ (0, _prismatic_io_spectral.action)({
1404
+ display: {
1405
+ label: "Update Order",
1406
+ description: "Update an existing order record"
1407
+ },
1408
+ inputs: {
1409
+ connection: connectionInput,
1410
+ orderId,
1411
+ lineItems,
1412
+ shippingLines,
1413
+ paymentMethod,
1414
+ paymentMethodTitle,
1415
+ isPaid,
1416
+ email: {
1417
+ ...email,
1418
+ required: false
1419
+ },
1420
+ phone,
1421
+ firstName,
1422
+ lastName,
1423
+ billingAddress1,
1424
+ billingAddress2,
1425
+ billingCity: {
1426
+ ...city,
1427
+ label: "Billing City"
1428
+ },
1429
+ billingState: {
1430
+ ...state,
1431
+ label: "Billing State"
1432
+ },
1433
+ billingPostalCode: {
1434
+ ...postalcode,
1435
+ label: "Billing Postal Code"
1436
+ },
1437
+ billingCountry: {
1438
+ ...country,
1439
+ label: "Billing Country"
1440
+ },
1441
+ shippingAddress1,
1442
+ shippingAddress2,
1443
+ shippingCity: {
1444
+ ...city,
1445
+ label: "Shipping City"
1446
+ },
1447
+ shippingState: {
1448
+ ...state,
1449
+ label: "Shipping State"
1450
+ },
1451
+ shippingCountry: {
1452
+ ...country,
1453
+ label: "Shipping Country"
1454
+ },
1455
+ shippingPostalCode: {
1456
+ ...postalcode,
1457
+ label: "Shipping Postal Code"
1458
+ },
1459
+ values
1460
+ },
1461
+ perform: async ({ debug: { enabled: debug } }, params) => {
1462
+ return { data: await handleErrors$1(getClient(params.connection, debug).post(`/orders/${params.orderId}`, {
1463
+ ..._prismatic_io_spectral.util.types.keyValPairListToObject(params.values),
1464
+ payment_method: _prismatic_io_spectral.util.types.toString(params.paymentMethod) || void 0,
1465
+ payment_method_title: _prismatic_io_spectral.util.types.toString(params.paymentMethodTitle) || void 0,
1466
+ set_paid: _prismatic_io_spectral.util.types.toBool(params.isPaid),
1467
+ billing: {
1468
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1469
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1470
+ address_1: _prismatic_io_spectral.util.types.toString(params.billingAddress1) || void 0,
1471
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1472
+ city: _prismatic_io_spectral.util.types.toString(params.billingCity) || void 0,
1473
+ state: _prismatic_io_spectral.util.types.toString(params.billingState) || void 0,
1474
+ postcode: _prismatic_io_spectral.util.types.toString(params.billingPostalCode) || void 0,
1475
+ country: _prismatic_io_spectral.util.types.toString(params.billingCountry) || void 0,
1476
+ email: _prismatic_io_spectral.util.types.toString(params.email) || void 0,
1477
+ phone: _prismatic_io_spectral.util.types.toString(params.phone) || void 0
1478
+ },
1479
+ shipping: {
1480
+ first_name: _prismatic_io_spectral.util.types.toString(params.firstName) || void 0,
1481
+ last_name: _prismatic_io_spectral.util.types.toString(params.lastName) || void 0,
1482
+ address_1: _prismatic_io_spectral.util.types.toString(params.shippingAddress1) || void 0,
1483
+ address_2: _prismatic_io_spectral.util.types.toString(params.billingAddress2) || void 0,
1484
+ city: _prismatic_io_spectral.util.types.toString(params.shippingCity) || void 0,
1485
+ state: _prismatic_io_spectral.util.types.toString(params.shippingState) || void 0,
1486
+ postcode: _prismatic_io_spectral.util.types.toString(params.shippingPostalCode) || void 0,
1487
+ country: _prismatic_io_spectral.util.types.toString(params.shippingCountry) || void 0
1488
+ },
1489
+ line_items: _prismatic_io_spectral.util.types.toString(params.lineItems) ? JSON.parse(_prismatic_io_spectral.util.types.toString(params.lineItems)) : void 0,
1490
+ shipping_lines: _prismatic_io_spectral.util.types.toString(params.shippingLines) ? JSON.parse(_prismatic_io_spectral.util.types.toString(params.shippingLines)) : void 0
1491
+ })) };
1492
+ }
1493
+ });
1494
+ const listOrders = (0, _prismatic_io_spectral.action)({
1495
+ display: {
1496
+ label: "List Orders",
1497
+ description: "Returns a list of all orders"
1498
+ },
1499
+ inputs: {
1500
+ connection: connectionInput,
1501
+ resultsPerPage,
1502
+ page,
1503
+ offset,
1504
+ search,
1505
+ before,
1506
+ after,
1507
+ params,
1508
+ fetchAll
1509
+ },
1510
+ perform: async ({ debug: { enabled: debug } }, { after, before, connection, page, resultsPerPage, offset, search, params, fetchAll }) => {
1511
+ return { data: await paginateRecords(getClient(connection, debug), "/orders", {
1512
+ per_page: resultsPerPage,
1513
+ page,
1514
+ offset,
1515
+ search,
1516
+ before,
1517
+ after,
1518
+ ...params
1519
+ }, fetchAll) };
1520
+ },
1521
+ examplePayload: listOrdersExamplePayload
1522
+ });
1523
+ const getOrder = (0, _prismatic_io_spectral.action)({
1524
+ display: {
1525
+ label: "Get Order",
1526
+ description: "Returns the information and metadata of an order"
1527
+ },
1528
+ inputs: {
1529
+ connection: connectionInput,
1530
+ orderId
1531
+ },
1532
+ perform: async ({ debug: { enabled: debug } }, params) => {
1533
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/orders/${params.orderId}`)) };
1534
+ }
1535
+ });
1536
+ const deleteOrder = (0, _prismatic_io_spectral.action)({
1537
+ display: {
1538
+ label: "Delete Order",
1539
+ description: "Delete the information and metadata of an order"
1540
+ },
1541
+ inputs: {
1542
+ connection: connectionInput,
1543
+ orderId
1544
+ },
1545
+ perform: async ({ debug: { enabled: debug } }, params) => {
1546
+ return { data: await handleErrors$1(getClient(params.connection, debug).delete(`/orders/${params.orderId}`)) };
1547
+ }
1548
+ });
1549
+ //#endregion
1550
+ //#region src/actions/products.ts
1551
+ const createProduct = (0, _prismatic_io_spectral.action)({
1552
+ display: {
1553
+ label: "Create Product",
1554
+ description: "Create a new product record"
1555
+ },
1556
+ inputs: {
1557
+ connection: connectionInput,
1558
+ productName,
1559
+ productType,
1560
+ price,
1561
+ description,
1562
+ summary,
1563
+ categories,
1564
+ images,
1565
+ values
1566
+ },
1567
+ perform: async ({ debug: { enabled: debug } }, params) => {
1568
+ return { data: await handleErrors$1(getClient(params.connection, debug).post(`/products`, {
1569
+ ..._prismatic_io_spectral.util.types.keyValPairListToObject(params.values),
1570
+ name: _prismatic_io_spectral.util.types.toString(params.productName) || void 0,
1571
+ type: _prismatic_io_spectral.util.types.toString(params.productType) || void 0,
1572
+ regular_price: _prismatic_io_spectral.util.types.toString(params.price) || void 0,
1573
+ description: _prismatic_io_spectral.util.types.toString(params.description) || void 0,
1574
+ short_description: _prismatic_io_spectral.util.types.toString(params.summary) || void 0,
1575
+ categories: JSON.parse(_prismatic_io_spectral.util.types.toString(params.categories)) || [],
1576
+ images: JSON.parse(_prismatic_io_spectral.util.types.toString(params.images)) || []
1577
+ })) };
1578
+ }
1579
+ });
1580
+ const updateProduct = (0, _prismatic_io_spectral.action)({
1581
+ display: {
1582
+ label: "Update Product",
1583
+ description: "Create a new product record"
1584
+ },
1585
+ inputs: {
1586
+ connection: connectionInput,
1587
+ productId,
1588
+ productName,
1589
+ productType,
1590
+ price,
1591
+ description,
1592
+ summary,
1593
+ categories,
1594
+ images,
1595
+ values
1596
+ },
1597
+ perform: async ({ debug: { enabled: debug } }, params) => {
1598
+ return { data: await handleErrors$1(getClient(params.connection, debug).put(`/products/${params.productId}`, {
1599
+ ..._prismatic_io_spectral.util.types.keyValPairListToObject(params.values),
1600
+ name: _prismatic_io_spectral.util.types.toString(params.productName) || void 0,
1601
+ type: _prismatic_io_spectral.util.types.toString(params.productType) || void 0,
1602
+ regular_price: _prismatic_io_spectral.util.types.toNumber(params.price) || void 0,
1603
+ description: _prismatic_io_spectral.util.types.toString(params.description) || void 0,
1604
+ short_description: _prismatic_io_spectral.util.types.toString(params.summary) || void 0,
1605
+ categories: _prismatic_io_spectral.util.types.toString(params.categories) ? JSON.parse(_prismatic_io_spectral.util.types.toString(params.categories)) : void 0,
1606
+ images: _prismatic_io_spectral.util.types.toString(params.images) ? JSON.parse(_prismatic_io_spectral.util.types.toString(params.images)) : void 0
1607
+ })) };
1608
+ }
1609
+ });
1610
+ const listProducts = (0, _prismatic_io_spectral.action)({
1611
+ display: {
1612
+ label: "List Products",
1613
+ description: "Returns a list of all active products"
1614
+ },
1615
+ inputs: {
1616
+ connection: connectionInput,
1617
+ resultsPerPage,
1618
+ page,
1619
+ offset,
1620
+ search,
1621
+ before,
1622
+ after,
1623
+ params,
1624
+ fetchAll
1625
+ },
1626
+ perform: async ({ debug: { enabled: debug } }, { after, before, connection, page, resultsPerPage, offset, search, params, fetchAll }) => {
1627
+ return { data: await paginateRecords(getClient(connection, debug), "/products", {
1628
+ per_page: resultsPerPage,
1629
+ page,
1630
+ offset,
1631
+ search,
1632
+ before,
1633
+ after,
1634
+ ...params
1635
+ }, fetchAll) };
1636
+ },
1637
+ examplePayload: listProductsExamplePayload
1638
+ });
1639
+ const getProduct = (0, _prismatic_io_spectral.action)({
1640
+ display: {
1641
+ label: "Get Product",
1642
+ description: "Returns the information and metadata of a given product"
1643
+ },
1644
+ inputs: {
1645
+ connection: connectionInput,
1646
+ productId
1647
+ },
1648
+ perform: async ({ debug: { enabled: debug } }, params) => {
1649
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/products/${params.productId}`)) };
1650
+ }
1651
+ });
1652
+ const deleteProduct = (0, _prismatic_io_spectral.action)({
1653
+ display: {
1654
+ label: "Delete Product",
1655
+ description: "Delete the information and metadata of a given product"
1656
+ },
1657
+ inputs: {
1658
+ connection: connectionInput,
1659
+ productId
1660
+ },
1661
+ perform: async ({ debug: { enabled: debug } }, params) => {
1662
+ return { data: await handleErrors$1(getClient(params.connection, debug).delete(`/products/${params.productId}`)) };
1663
+ }
1664
+ });
1665
+ //#endregion
1666
+ //#region src/actions/rawRequest.ts
1667
+ const { debugRequest: _, ...rawRequestInputs } = _prismatic_io_spectral_http.inputs;
1668
+ const rawRequest = (0, _prismatic_io_spectral.action)({
1669
+ display: {
1670
+ label: "Raw Request",
1671
+ description: "Send raw HTTP request to WooCommerce"
1672
+ },
1673
+ perform: async (context, { connection, ...rawRequestInputs }) => {
1674
+ const baseUrl = getBaseUrl(connection);
1675
+ const headers = { Authorization: getAuthorization(connection) };
1676
+ const { data } = await (0, _prismatic_io_spectral_http.sendRawRequest)(baseUrl, {
1677
+ ...rawRequestInputs,
1678
+ debugRequest: context.debug.enabled
1679
+ }, headers);
1680
+ return { data };
1681
+ },
1682
+ inputs: {
1683
+ connection: connectionInput,
1684
+ ...rawRequestInputs,
1685
+ url: {
1686
+ ...rawRequestInputs.url,
1687
+ comments: "Input the path only (/reports), The base URL is already included (https://{input_domain}/wp-json/wc/v3). For example, to connect to https://{input_domain}/wp-json/wc/v3/reports, only /reports is entered in this field.",
1688
+ example: "/reports"
1689
+ }
1690
+ }
1691
+ });
1692
+ //#endregion
1693
+ //#region src/actions/refunds.ts
1694
+ const listRefunds = (0, _prismatic_io_spectral.action)({
1695
+ display: {
1696
+ label: "List Refunds",
1697
+ description: "Returns a list of all refunds on an existing order"
1698
+ },
1699
+ inputs: {
1700
+ connection: connectionInput,
1701
+ orderId,
1702
+ resultsPerPage,
1703
+ page,
1704
+ offset,
1705
+ search,
1706
+ before,
1707
+ after,
1708
+ params,
1709
+ fetchAll
1710
+ },
1711
+ perform: async ({ debug: { enabled: debug } }, { after, before, connection, page, resultsPerPage, offset, search, params, fetchAll }) => {
1712
+ return { data: await paginateRecords(getClient(connection, debug), `/orders/${orderId}/refunds`, {
1713
+ per_page: resultsPerPage,
1714
+ page,
1715
+ offset,
1716
+ search,
1717
+ before,
1718
+ after,
1719
+ ...params
1720
+ }, fetchAll) };
1721
+ }
1722
+ });
1723
+ const getRefund = (0, _prismatic_io_spectral.action)({
1724
+ display: {
1725
+ label: "Get Refund",
1726
+ description: "Returns the information and metadata of a refund"
1727
+ },
1728
+ inputs: {
1729
+ connection: connectionInput,
1730
+ orderId,
1731
+ refundId
1732
+ },
1733
+ perform: async ({ debug: { enabled: debug } }, params) => {
1734
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/orders/${params.orderId}/refunds/${params.refundId}`)) };
1735
+ }
1736
+ });
1737
+ const deleteRefund = (0, _prismatic_io_spectral.action)({
1738
+ display: {
1739
+ label: "Delete Refund",
1740
+ description: "Delete the information and metadata of a refund"
1741
+ },
1742
+ inputs: {
1743
+ connection: connectionInput,
1744
+ orderId,
1745
+ refundId
1746
+ },
1747
+ perform: async ({ debug: { enabled: debug } }, params) => {
1748
+ return { data: await handleErrors$1(getClient(params.connection, debug).delete(`/orders/${params.orderId}/refunds/${params.refundId}`, { params: { force: "true" } })) };
1749
+ }
1750
+ });
1751
+ const createRefund = (0, _prismatic_io_spectral.action)({
1752
+ display: {
1753
+ label: "Create Refund",
1754
+ description: "Create a refund on an existing order"
1755
+ },
1756
+ inputs: {
1757
+ connection: connectionInput,
1758
+ orderId,
1759
+ refundAmount,
1760
+ lineItems: {
1761
+ ...lineItems,
1762
+ example: `[
1763
+ {
1764
+ "id": "111",
1765
+ "refund_total": 10,
1766
+ "refund_tax": [
1767
+ {
1768
+ "id": "222",
1769
+ "refund_total": 20
1770
+ }
1771
+ ]
1772
+ }
1773
+ ]`
1774
+ }
1775
+ },
1776
+ perform: async ({ debug: { enabled: debug } }, params) => {
1777
+ return { data: await handleErrors$1(getClient(params.connection, debug).post(`/orders/${params.orderId}/refunds`, {
1778
+ amount: _prismatic_io_spectral.util.types.toString(params.refundAmount),
1779
+ line_items: _prismatic_io_spectral.util.types.toString(params.lineItems) ? JSON.parse(_prismatic_io_spectral.util.types.toString(params.lineItems)) : void 0
1780
+ })) };
1781
+ }
1782
+ });
1783
+ //#endregion
1784
+ //#region src/actions/reports.ts
1785
+ const listReports = (0, _prismatic_io_spectral.action)({
1786
+ display: {
1787
+ label: "List Reports",
1788
+ description: "Returns a list of all reports"
1789
+ },
1790
+ inputs: {
1791
+ connection: connectionInput,
1792
+ fetchAll,
1793
+ after,
1794
+ before,
1795
+ page,
1796
+ resultsPerPage,
1797
+ offset,
1798
+ search,
1799
+ params
1800
+ },
1801
+ perform: async ({ debug: { enabled: debug } }, { after, before, connection, page, resultsPerPage, offset, search, params, fetchAll }) => {
1802
+ return { data: await paginateRecords(getClient(connection, debug), "/reports", {
1803
+ per_page: resultsPerPage,
1804
+ page,
1805
+ offset,
1806
+ after,
1807
+ before,
1808
+ search,
1809
+ ...params
1810
+ }, fetchAll) };
1811
+ }
1812
+ });
1813
+ const getSalesReport = (0, _prismatic_io_spectral.action)({
1814
+ display: {
1815
+ label: "Get Sales Report",
1816
+ description: "Returns the information and metadata of a Sales Report"
1817
+ },
1818
+ inputs: {
1819
+ connection: connectionInput,
1820
+ period,
1821
+ minDate,
1822
+ maxDate
1823
+ },
1824
+ perform: async ({ debug: { enabled: debug } }, params) => {
1825
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/reports/sales`, { params: {
1826
+ period: _prismatic_io_spectral.util.types.toString(params.period) || void 0,
1827
+ date_min: _prismatic_io_spectral.util.types.toString(params.minDate) || void 0,
1828
+ date_max: _prismatic_io_spectral.util.types.toString(params.maxDate) || void 0
1829
+ } })) };
1830
+ }
1831
+ });
1832
+ const getTopSellersReport = (0, _prismatic_io_spectral.action)({
1833
+ display: {
1834
+ label: "Get Top Sellers Report",
1835
+ description: "Returns the information and metadata of a Sales Report"
1836
+ },
1837
+ inputs: {
1838
+ connection: connectionInput,
1839
+ period,
1840
+ minDate,
1841
+ maxDate
1842
+ },
1843
+ perform: async ({ debug: { enabled: debug } }, params) => {
1844
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/reports/top_sellers`, { params: {
1845
+ period: _prismatic_io_spectral.util.types.toString(params.period) || void 0,
1846
+ date_min: _prismatic_io_spectral.util.types.toString(params.minDate) || void 0,
1847
+ date_max: _prismatic_io_spectral.util.types.toString(params.maxDate) || void 0
1848
+ } })) };
1849
+ }
1850
+ });
1851
+ const getCouponTotalsReport = (0, _prismatic_io_spectral.action)({
1852
+ display: {
1853
+ label: "Get Coupon Totals Report",
1854
+ description: "Returns the information and metadata of a Coupon Totals Report"
1855
+ },
1856
+ inputs: {
1857
+ connection: connectionInput,
1858
+ period,
1859
+ minDate,
1860
+ maxDate
1861
+ },
1862
+ perform: async ({ debug: { enabled: debug } }, params) => {
1863
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/reports/coupons/totals`)) };
1864
+ }
1865
+ });
1866
+ const getCustomerTotalsReport = (0, _prismatic_io_spectral.action)({
1867
+ display: {
1868
+ label: "Get Customer Totals Report",
1869
+ description: "Returns the information and metadata of a Customer Totals Report"
1870
+ },
1871
+ inputs: {
1872
+ connection: connectionInput,
1873
+ period,
1874
+ maxDate,
1875
+ minDate
1876
+ },
1877
+ perform: async ({ debug: { enabled: debug } }, params) => {
1878
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/reports/customers/totals`)) };
1879
+ }
1880
+ });
1881
+ const getOrderTotalsReport = (0, _prismatic_io_spectral.action)({
1882
+ display: {
1883
+ label: "Get Order Totals Report",
1884
+ description: "Returns the information and metadata of a Order Totals Report"
1885
+ },
1886
+ inputs: { connection: connectionInput },
1887
+ perform: async ({ debug: { enabled: debug } }, params) => {
1888
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/reports/orders/totals`)) };
1889
+ }
1890
+ });
1891
+ const getProductTotalsReport = (0, _prismatic_io_spectral.action)({
1892
+ display: {
1893
+ label: "Get Product Totals Report",
1894
+ description: "Returns the information and metadata of a Product Totals Report"
1895
+ },
1896
+ inputs: { connection: connectionInput },
1897
+ perform: async ({ debug: { enabled: debug } }, params) => {
1898
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/reports/products/totals`)) };
1899
+ }
1900
+ });
1901
+ const getReviewTotalsReport = (0, _prismatic_io_spectral.action)({
1902
+ display: {
1903
+ label: "Get Review Totals Report",
1904
+ description: "Returns the information and metadata of a Review Totals Report"
1905
+ },
1906
+ inputs: { connection: connectionInput },
1907
+ perform: async ({ debug: { enabled: debug } }, params) => {
1908
+ return { data: await handleErrors$1(getClient(params.connection, debug).get(`/reports/reviews/totals`)) };
1909
+ }
1910
+ });
1911
+ //#endregion
1912
+ //#region src/datasources/selectCustomer.ts
1913
+ const selectCustomer = (0, _prismatic_io_spectral.dataSource)({
1914
+ display: {
1915
+ label: "Select Customer",
1916
+ description: "Select a customer from a list of WooCommerce customers."
1917
+ },
1918
+ dataSourceType: "picklist",
1919
+ inputs: {
1920
+ connection: connectionInput,
1921
+ resultsPerPage,
1922
+ search,
1923
+ before,
1924
+ after
1925
+ },
1926
+ perform: async (context, { connection, resultsPerPage, search, before, after }) => {
1927
+ const { data } = await paginateRecords(getClient(connection, false), "/customers", {
1928
+ per_page: resultsPerPage,
1929
+ search,
1930
+ before,
1931
+ after
1932
+ }, true);
1933
+ return { result: data.map(({ id, first_name, last_name, email }) => ({
1934
+ label: `${first_name} ${last_name} - ${email}`,
1935
+ key: _prismatic_io_spectral.util.types.toString(id)
1936
+ })) };
1937
+ }
1938
+ });
1939
+ //#endregion
1940
+ //#region src/datasources/index.ts
1941
+ var datasources_default = {
1942
+ selectOrder: (0, _prismatic_io_spectral.dataSource)({
1943
+ display: {
1944
+ label: "Select Order",
1945
+ description: "Select an order from a list of WooCommerce orders."
1946
+ },
1947
+ dataSourceType: "picklist",
1948
+ perform: async (context, { connection, resultsPerPage, search, before, after }) => {
1949
+ const { data } = await paginateRecords(getClient(connection, false), "/orders", {
1950
+ per_page: resultsPerPage,
1951
+ search,
1952
+ before,
1953
+ after
1954
+ }, true);
1955
+ return { result: data.map(({ id, total, order_key }) => ({
1956
+ label: `${order_key} - ${total}`,
1957
+ key: _prismatic_io_spectral.util.types.toString(id)
1958
+ })) };
1959
+ },
1960
+ inputs: {
1961
+ connection: connectionInput,
1962
+ resultsPerPage,
1963
+ search,
1964
+ before,
1965
+ after
1966
+ }
1967
+ }),
1968
+ selectCustomer,
1969
+ selectProduct: (0, _prismatic_io_spectral.dataSource)({
1970
+ display: {
1971
+ label: "Select Product",
1972
+ description: "Select a product from a list of WooCommerce products."
1973
+ },
1974
+ dataSourceType: "picklist",
1975
+ inputs: {
1976
+ connection: connectionInput,
1977
+ resultsPerPage,
1978
+ search,
1979
+ before,
1980
+ after
1981
+ },
1982
+ perform: async (context, { connection, resultsPerPage, search, before, after }) => {
1983
+ const { data } = await paginateRecords(getClient(connection, false), "/products", {
1984
+ per_page: resultsPerPage,
1985
+ search,
1986
+ before,
1987
+ after
1988
+ }, true);
1989
+ return { result: data.map(({ id, name }) => ({
1990
+ label: name,
1991
+ key: _prismatic_io_spectral.util.types.toString(id)
1992
+ })) };
1993
+ }
1994
+ }),
1995
+ selectProductCategory: (0, _prismatic_io_spectral.dataSource)({
1996
+ display: {
1997
+ label: "Select Product Category",
1998
+ description: "Select a product category from a list of WooCommerce product categories."
1999
+ },
2000
+ dataSourceType: "picklist",
2001
+ inputs: {
2002
+ connection: connectionInput,
2003
+ resultsPerPage,
2004
+ search,
2005
+ before,
2006
+ after
2007
+ },
2008
+ perform: async (context, { connection, resultsPerPage, search, before, after }) => {
2009
+ const { data } = await paginateRecords(getClient(connection, false), "/products/categories", {
2010
+ per_page: resultsPerPage,
2011
+ search,
2012
+ before,
2013
+ after
2014
+ }, true);
2015
+ return { result: data.map(({ id, name }) => ({
2016
+ label: name,
2017
+ key: _prismatic_io_spectral.util.types.toString(id)
2018
+ })) };
2019
+ }
2020
+ }),
2021
+ selectRefund: (0, _prismatic_io_spectral.dataSource)({
2022
+ display: {
2023
+ label: "Select Refund",
2024
+ description: "Select a refund from a list of WooCommerce refunds."
2025
+ },
2026
+ dataSourceType: "picklist",
2027
+ inputs: {
2028
+ connection: connectionInput,
2029
+ resultsPerPage,
2030
+ search,
2031
+ before,
2032
+ after
2033
+ },
2034
+ perform: async (context, { connection, resultsPerPage, search, before, after }) => {
2035
+ const { data } = await paginateRecords(getClient(connection, false), "/refunds", {
2036
+ per_page: resultsPerPage,
2037
+ search,
2038
+ before,
2039
+ after
2040
+ }, true);
2041
+ return { result: data.map(({ id, amount, reason, refunded_by, parent_id }) => ({
2042
+ label: `${amount} - ${reason} - ${refunded_by} - ${parent_id}`,
2043
+ key: _prismatic_io_spectral.util.types.toString(id)
2044
+ })) };
2045
+ }
2046
+ })
2047
+ };
2048
+ //#endregion
2049
+ //#region src/triggers/index.ts
2050
+ var triggers_default = { pollNewRecordsTrigger: (0, _prismatic_io_spectral.pollingTrigger)({
2051
+ display: {
2052
+ label: "New Records",
2053
+ description: "Retrieves existing and ongoing records for a specified WooCommerce resource type. Load history once, check for changes on a schedule, or both."
2054
+ },
2055
+ inputs: {
2056
+ connection: connectionInput,
2057
+ resourceType,
2058
+ lookBackDate
2059
+ },
2060
+ triggerResolverSupport: "valid",
2061
+ batchConfig: { batchSize: 50 },
2062
+ triggerResolver: {
2063
+ resolveItems: (_context, { payload }) => resolvePollingRecordChanges(payload.body.data),
2064
+ getNextPaginationState: (_context, { payload }) => payload.paginationState ?? null
2065
+ },
2066
+ perform: async (context, payload, params) => {
2067
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2068
+ const state = context.polling.getState();
2069
+ const client = getClient(params.connection, context.debug.enabled);
2070
+ const resource = _prismatic_io_spectral.util.types.toString(params.resourceType);
2071
+ const endpoint = RESOURCE_ENDPOINT_MAP[resource];
2072
+ if (!WATERMARK_RESOURCES.includes(resource)) {
2073
+ const created = await fetchCustomersSince(client, endpoint, state, params.lookBackDate, now);
2074
+ context.polling.setState({ lastPolledAt: now });
2075
+ return {
2076
+ payload: {
2077
+ ...payload,
2078
+ body: { data: {
2079
+ created,
2080
+ updated: []
2081
+ } }
2082
+ },
2083
+ polledNoChanges: !payload.paginationState && created.length === 0
2084
+ };
2085
+ }
2086
+ const incoming = payload.paginationState;
2087
+ const { result, nextState } = await pollWatermark(client, endpoint, {
2088
+ state,
2089
+ incoming,
2090
+ lookBackDate: params.lookBackDate,
2091
+ now,
2092
+ batching: context.batch?.enabled === true
2093
+ });
2094
+ context.polling.setState(nextState);
2095
+ return {
2096
+ payload: {
2097
+ ...payload,
2098
+ paginationState: result.drained ? void 0 : result.cursor,
2099
+ body: { data: {
2100
+ created: result.records,
2101
+ updated: []
2102
+ } }
2103
+ },
2104
+ polledNoChanges: result.drained && !incoming && result.records.length === 0
2105
+ };
2106
+ }
2107
+ }) };
2108
+ //#endregion
2109
+ //#region src/index.ts
2110
+ var src_default = (0, _prismatic_io_spectral.component)({
2111
+ key: "woo-commerce",
2112
+ public: true,
2113
+ documentationUrl: "https://prismatic.io/docs/components/woo-commerce/",
2114
+ display: {
2115
+ label: "WooCommerce",
2116
+ category: "Application Connectors",
2117
+ description: "Easily manage your customers, orders, and products in your WooCommerce platform",
2118
+ iconPath: "icon.png"
2119
+ },
2120
+ actions: {
2121
+ listCustomers,
2122
+ createCustomer,
2123
+ deleteCustomer,
2124
+ getCustomer,
2125
+ updateCustomer,
2126
+ rawRequest,
2127
+ createProduct,
2128
+ deleteProduct,
2129
+ getProduct,
2130
+ listProducts,
2131
+ updateProduct,
2132
+ getCouponTotalsReport,
2133
+ getCustomerTotalsReport,
2134
+ getOrderTotalsReport,
2135
+ getProductTotalsReport,
2136
+ getReviewTotalsReport,
2137
+ getSalesReport,
2138
+ getTopSellersReport,
2139
+ listReports,
2140
+ deleteOrder,
2141
+ getOrder,
2142
+ listOrders,
2143
+ getRefund,
2144
+ listRefunds,
2145
+ createOrder,
2146
+ createProductCategory,
2147
+ deleteProductCategory,
2148
+ getProductCategory,
2149
+ listProductCategories,
2150
+ createRefund,
2151
+ deleteRefund
2152
+ },
2153
+ dataSources: datasources_default,
2154
+ triggers: triggers_default,
2155
+ hooks: { error: _prismatic_io_spectral_http.handleErrors },
2156
+ connections: connections_default
2157
+ });
2158
+ //#endregion
2159
+ //#region npm-dist/.entry.ts
2160
+ var _entry_default = (0, _prismatic_io_spectral.callableComponent)(src_default);
2161
+ //#endregion
2162
+ module.exports = _entry_default;