@shushed/helpers 0.0.224 → 0.0.225

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.
@@ -567,7 +567,7 @@ class EnvEngine extends runtime_1.default {
567
567
  batchSize: 1,
568
568
  subscriptionFilter: null,
569
569
  batchWindowSeconds: 10,
570
- }, Object.fromEntries(Object.entries(rnPartialConfig).filter(x => !(x === null || x === undefined))));
570
+ }, Object.fromEntries(Object.entries(rnPartialConfig).filter(([x]) => !(x === null || x === undefined))));
571
571
  return rnConfig;
572
572
  }
573
573
  createOrUpdateRespectfulNudge(subscriptionName, rnPartialConfig) {
@@ -3,11 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SitooOrderItemType = exports.SitooPaymentState = exports.SitooOrderType = exports.SitooOrderState = void 0;
6
7
  const crypto_1 = __importDefault(require("crypto"));
7
8
  const lodash_groupby_1 = __importDefault(require("lodash.groupby"));
8
9
  const env_1 = __importDefault(require("./env"));
9
10
  const SITOO_TR_TYPE_MANUAL_IN = 10;
10
11
  const SITOO_TR_TYPE_MANUAL_OUT = 20;
12
+ var SitooOrderState;
13
+ (function (SitooOrderState) {
14
+ SitooOrderState[SitooOrderState["Abandoned"] = -1] = "Abandoned";
15
+ SitooOrderState[SitooOrderState["Open"] = 0] = "Open";
16
+ SitooOrderState[SitooOrderState["Closed"] = 10] = "Closed";
17
+ SitooOrderState[SitooOrderState["Cancelled"] = 20] = "Cancelled";
18
+ })(SitooOrderState || (exports.SitooOrderState = SitooOrderState = {}));
19
+ var SitooOrderType;
20
+ (function (SitooOrderType) {
21
+ SitooOrderType[SitooOrderType["Order"] = 10] = "Order";
22
+ SitooOrderType[SitooOrderType["Booking"] = 100] = "Booking";
23
+ SitooOrderType[SitooOrderType["POSParked"] = 110] = "POSParked";
24
+ })(SitooOrderType || (exports.SitooOrderType = SitooOrderType = {}));
25
+ var SitooPaymentState;
26
+ (function (SitooPaymentState) {
27
+ SitooPaymentState[SitooPaymentState["None"] = 0] = "None";
28
+ SitooPaymentState[SitooPaymentState["Pending"] = 10] = "Pending";
29
+ SitooPaymentState[SitooPaymentState["Reserved"] = 15] = "Reserved";
30
+ SitooPaymentState[SitooPaymentState["Successful"] = 20] = "Successful";
31
+ SitooPaymentState[SitooPaymentState["Cancelled"] = 30] = "Cancelled";
32
+ SitooPaymentState[SitooPaymentState["Failed"] = 40] = "Failed";
33
+ })(SitooPaymentState || (exports.SitooPaymentState = SitooPaymentState = {}));
34
+ var SitooOrderItemType;
35
+ (function (SitooOrderItemType) {
36
+ SitooOrderItemType[SitooOrderItemType["Product"] = 10] = "Product";
37
+ SitooOrderItemType[SitooOrderItemType["Discount"] = 20] = "Discount";
38
+ })(SitooOrderItemType || (exports.SitooOrderItemType = SitooOrderItemType = {}));
11
39
  const BATCH_SIZE = 900;
12
40
  class SitooHelper extends env_1.default {
13
41
  opts;
@@ -21,6 +49,48 @@ class SitooHelper extends env_1.default {
21
49
  this.baseUrl = opts.sitooBaseUrl.replace(/\/$/, '');
22
50
  this.siteId = opts.sitooSiteId;
23
51
  }
52
+ async getAllOrders(options) {
53
+ const allOrders = [];
54
+ const pageSize = 100;
55
+ let start = 0;
56
+ let hasMore = true;
57
+ while (hasMore) {
58
+ const queryParams = new URLSearchParams();
59
+ queryParams.set('num', pageSize.toString());
60
+ queryParams.set('start', start.toString());
61
+ queryParams.set('sort', 'orderid');
62
+ if (options?.fromTimestamp !== undefined) {
63
+ queryParams.set('orderdatefrom', options.fromTimestamp.toString());
64
+ }
65
+ if (options?.untilTimestamp !== undefined) {
66
+ queryParams.set('orderdateto', options.untilTimestamp.toString());
67
+ }
68
+ if (options?.filterByState !== undefined) {
69
+ queryParams.set('orderstate', options.filterByState.toString());
70
+ }
71
+ const url = `${this.baseUrl}/sites/${this.siteId}/orders.json?${queryParams.toString()}`;
72
+ const response = await fetch(url, {
73
+ method: 'GET',
74
+ headers: {
75
+ 'Authorization': `Basic ${this.opts.accessToken}`,
76
+ 'Content-Type': 'application/json',
77
+ },
78
+ });
79
+ if (!response.ok) {
80
+ const errorText = await response.text().catch(() => 'Unknown error');
81
+ throw new Error(`Sitoo API error: ${response.status} ${response.statusText} - ${errorText}`);
82
+ }
83
+ const envelope = await response.json();
84
+ allOrders.push(...envelope.items);
85
+ if (envelope.items.length < pageSize) {
86
+ hasMore = false;
87
+ }
88
+ else {
89
+ start += envelope.items.length;
90
+ }
91
+ }
92
+ return allOrders;
93
+ }
24
94
  async getSitooWarehouses() {
25
95
  const url = `${this.baseUrl}/sites/${this.siteId}/warehouses.json`;
26
96
  const response = await fetch(url, {
@@ -1,5 +1,139 @@
1
1
  import EnvEngine from './env';
2
2
  import Runtime from './runtime';
3
+ export declare enum SitooOrderState {
4
+ Abandoned = -1,
5
+ Open = 0,
6
+ Closed = 10,
7
+ Cancelled = 20
8
+ }
9
+ export declare enum SitooOrderType {
10
+ Order = 10,
11
+ Booking = 100,
12
+ POSParked = 110
13
+ }
14
+ export declare enum SitooPaymentState {
15
+ None = 0,
16
+ Pending = 10,
17
+ Reserved = 15,
18
+ Successful = 20,
19
+ Cancelled = 30,
20
+ Failed = 40
21
+ }
22
+ export declare enum SitooOrderItemType {
23
+ Product = 10,
24
+ Discount = 20
25
+ }
26
+ export interface SitooMoney {
27
+ value: string;
28
+ decimalplaces: number;
29
+ currency: string;
30
+ }
31
+ export interface SitooOrderItemSalesTax {
32
+ name: string;
33
+ code?: string;
34
+ externalid?: string | null;
35
+ groupregion?: string | null;
36
+ moneytotal: SitooMoney;
37
+ moneytax: SitooMoney;
38
+ decimaltaxvalue: string;
39
+ }
40
+ export interface SitooOrderItem {
41
+ orderitemid: number;
42
+ orderitemtype: SitooOrderItemType;
43
+ productid?: number;
44
+ productname: string;
45
+ sku?: string;
46
+ productattributes?: string;
47
+ externalid?: string | null;
48
+ externalidaliased?: string | null;
49
+ unitlabel?: string;
50
+ decimalunitquantity?: string;
51
+ quantity: number;
52
+ decimalquantity?: string;
53
+ moneyrowprice: SitooMoney;
54
+ moneyrowdiscount?: SitooMoney;
55
+ moneyrow: SitooMoney;
56
+ vatvalue?: number;
57
+ deliveryinfo?: string | null;
58
+ salestaxes?: SitooOrderItemSalesTax[];
59
+ additionaldata?: Record<string, string>;
60
+ }
61
+ export interface SitooOrderPayment {
62
+ name: string;
63
+ moneyamount: SitooMoney;
64
+ externalid?: string | null;
65
+ reftype?: string | null;
66
+ refid?: string | null;
67
+ cardissuer?: string | null;
68
+ additionaldata?: Record<string, string>;
69
+ reservedpaymentid?: string | null;
70
+ }
71
+ export interface SitooOrderReservedPayment {
72
+ id: string;
73
+ name: string;
74
+ moneyreserved: SitooMoney;
75
+ externalid?: string | null;
76
+ reftype?: string | null;
77
+ refid?: string | null;
78
+ cardissuer?: string | null;
79
+ additionaldata?: Record<string, string>;
80
+ }
81
+ export interface SitooOrder {
82
+ orderid: number;
83
+ orderstate: SitooOrderState;
84
+ ordertype: SitooOrderType;
85
+ paymentstate: SitooPaymentState;
86
+ datecreated: number;
87
+ datemodified?: number;
88
+ orderdate?: number;
89
+ ordertypename?: string;
90
+ registerid?: string;
91
+ warehouseid?: number;
92
+ storeid?: number;
93
+ email?: string | null;
94
+ namefirst?: string;
95
+ namelast?: string;
96
+ company?: string;
97
+ phone?: string | null;
98
+ personalid?: string;
99
+ externalid?: string | null;
100
+ comment?: string | null;
101
+ commentinternal?: string | null;
102
+ currencycode?: string;
103
+ moneytotal: SitooMoney;
104
+ moneytotaldiscount?: SitooMoney;
105
+ moneyrounding?: SitooMoney;
106
+ moneytotalpayments?: SitooMoney;
107
+ moneytotalreservedpayments?: SitooMoney;
108
+ orderitems?: SitooOrderItem[];
109
+ payments?: SitooOrderPayment[];
110
+ reservedpayments?: SitooOrderReservedPayment[];
111
+ additionaldata?: Record<string, string>;
112
+ address?: string;
113
+ address2?: string;
114
+ zip?: string;
115
+ city?: string;
116
+ state?: string;
117
+ countryid?: string;
118
+ invoicenamefirst?: string;
119
+ invoicenamelast?: string;
120
+ invoicecompany?: string;
121
+ invoiceaddress?: string;
122
+ invoiceaddress2?: string;
123
+ invoicezip?: string;
124
+ invoicecity?: string;
125
+ invoicestate?: string;
126
+ invoicecountryid?: string;
127
+ }
128
+ export interface GetAllOrdersOptions {
129
+ fromTimestamp?: number;
130
+ untilTimestamp?: number;
131
+ filterByState?: SitooOrderState;
132
+ }
133
+ export interface SitooOrdersEnvelope {
134
+ totalcount: number;
135
+ items: SitooOrder[];
136
+ }
3
137
  export interface UnitCost {
4
138
  value: number;
5
139
  decimal_places: number;
@@ -102,6 +236,7 @@ export default class SitooHelper extends EnvEngine {
102
236
  sitooBaseUrl: string;
103
237
  sitooSiteId: number;
104
238
  });
239
+ getAllOrders(options?: GetAllOrdersOptions): Promise<SitooOrder[]>;
105
240
  getSitooWarehouses(): Promise<{
106
241
  nameToId: Record<string, number>;
107
242
  warehouses: Record<number, BasicSitooWarehouse>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.224",
3
+ "version": "0.0.225",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",