@marteye/studiojs 1.1.47-beta.0 → 1.1.48-beta.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.esm.js CHANGED
@@ -51,7 +51,7 @@ function SimpleHttpClient(baseUrl, apiKey, fetch, defaultTimeout, debug = false)
51
51
  if (response.status === 404) {
52
52
  throw new Error(`${baseUrl}${path} not found`);
53
53
  }
54
- throw new Error(`Request failed with status ${response.status}: ${await response.text()}}`);
54
+ throw new Error(`Request failed with status ${response.status}: ${await response.text()}`);
55
55
  }
56
56
  return {
57
57
  get: async (path, queryParams) => {
@@ -73,7 +73,7 @@ function SimpleHttpClient(baseUrl, apiKey, fetch, defaultTimeout, debug = false)
73
73
  }
74
74
 
75
75
  // Path: studiojs/src/resources/markets.ts
76
- function create$q(_) {
76
+ function create$r(_) {
77
77
  const actions = {
78
78
  /***
79
79
  * This is used to construct the action from the request body
@@ -103,7 +103,7 @@ function create$q(_) {
103
103
  return actions;
104
104
  }
105
105
 
106
- function create$p(httpClient) {
106
+ function create$q(httpClient) {
107
107
  let activity = {
108
108
  /**
109
109
  * List activity logs for a market with pagination and filtering
@@ -155,7 +155,7 @@ function create$p(httpClient) {
155
155
  return activity;
156
156
  }
157
157
 
158
- function create$o(httpClient) {
158
+ function create$p(httpClient) {
159
159
  return {
160
160
  list: async (marketId) => {
161
161
  return httpClient.get(`/${marketId}/adjustments`);
@@ -172,7 +172,7 @@ function create$o(httpClient) {
172
172
  };
173
173
  }
174
174
 
175
- function create$n(httpClient) {
175
+ function create$o(httpClient) {
176
176
  return {
177
177
  /**
178
178
  * Get the full cart for a customer including extras and uninvoiced lots
@@ -195,7 +195,7 @@ function create$n(httpClient) {
195
195
  };
196
196
  }
197
197
 
198
- function create$m(httpClient) {
198
+ function create$n(httpClient) {
199
199
  return {
200
200
  list: async (marketId) => {
201
201
  return httpClient.get(`/${marketId}/extras`);
@@ -215,7 +215,7 @@ function create$m(httpClient) {
215
215
  /***
216
216
  * Bidder applications
217
217
  */
218
- function create$l(httpClient) {
218
+ function create$m(httpClient) {
219
219
  let applications = {
220
220
  /**
221
221
  * List applications for a market with optional filtering
@@ -298,6 +298,13 @@ function create$l(httpClient) {
298
298
  return applications;
299
299
  }
300
300
 
301
+ function create$l(httpClient) {
302
+ return {
303
+ send: async (marketId, data) => httpClient.post(`/${marketId}/broadcast/send`, data),
304
+ get: async (marketId, type, taskId) => httpClient.get(`/${marketId}/broadcast/${type}/${taskId}`),
305
+ };
306
+ }
307
+
301
308
  // Path: studiojs/src/resources/markets.ts
302
309
  function create$k(httpClient) {
303
310
  let customers = {
@@ -761,31 +768,25 @@ function buildExcludeFilters(filters) {
761
768
  excludeFilters.push(`productCode = "${filters.excludedProductCodes[0]}"`);
762
769
  }
763
770
  else {
764
- excludeFilters.push(`(${filters.excludedProductCodes
771
+ excludeFilters.push(filters.excludedProductCodes
765
772
  .map((code) => `productCode = "${code}"`)
766
- .join(" OR ")})`);
773
+ .join(" OR "));
767
774
  }
768
775
  }
769
776
  return excludeFilters;
770
777
  }
771
778
  function buildFilterExpression(filters) {
772
- let clauses = [];
779
+ let fixedClauses = [];
780
+ let alternativeGroups = [];
773
781
  if (filters.dateStart)
774
- clauses.push(`saleDate >= "${filters.dateStart}"`);
782
+ fixedClauses.push(`saleDate >= "${filters.dateStart}"`);
775
783
  if (filters.dateEnd)
776
- clauses.push(`saleDate <= "${filters.dateEnd}"`);
784
+ fixedClauses.push(`saleDate <= "${filters.dateEnd}"`);
777
785
  if (filters.productCodes && filters.productCodes.length > 0) {
778
- if (filters.productCodes.length === 1) {
779
- clauses.push(`productCode = "${filters.productCodes[0]}"`);
780
- }
781
- else {
782
- clauses.push(`(${filters.productCodes
783
- .map((code) => `productCode = "${code}"`)
784
- .join(" OR ")})`);
785
- }
786
+ alternativeGroups.push(filters.productCodes.map((code) => `productCode = "${code}"`));
786
787
  }
787
788
  if (filters.boughtOnlineOnly) {
788
- clauses.push(`@boughtOnline = true`);
789
+ fixedClauses.push(`@boughtOnline = true`);
789
790
  }
790
791
  let breedClauses = [];
791
792
  for (let breed of filters.cattleBreeds || []) {
@@ -794,13 +795,18 @@ function buildFilterExpression(filters) {
794
795
  for (let breed of filters.sheepBreeds || []) {
795
796
  breedClauses.push(`breedOfSheep = "${breed}"`);
796
797
  }
797
- if (breedClauses.length === 1) {
798
- clauses.push(breedClauses[0]);
798
+ if (breedClauses.length > 0) {
799
+ alternativeGroups.push(breedClauses);
799
800
  }
800
- else if (breedClauses.length > 1) {
801
- clauses.push(`(${breedClauses.join(" OR ")})`);
801
+ let expandedBranches = alternativeGroups.reduce((branches, alternatives) => branches.flatMap((branch) => alternatives.map((alternative) => [...branch, alternative])), [[]]);
802
+ let expressions = expandedBranches
803
+ .map((branch) => [...fixedClauses, ...branch].filter(Boolean))
804
+ .filter((branch) => branch.length > 0)
805
+ .map((branch) => branch.join(" AND "));
806
+ if (expressions.length === 0) {
807
+ return undefined;
802
808
  }
803
- return clauses.length > 0 ? clauses.join(" AND ") : undefined;
809
+ return expressions.join(" OR ");
804
810
  }
805
811
  async function resolveList(customerLists, marketId, listIdOrSlug, options) {
806
812
  let identifierType = (options === null || options === void 0 ? void 0 : options.identifierType) || "auto";
@@ -5956,6 +5962,43 @@ function create$a(httpClient) {
5956
5962
  }
5957
5963
 
5958
5964
  function create$9(httpClient) {
5965
+ let reports = {
5966
+ getDebtOperationalOverview: async (marketId, options) => {
5967
+ let queryParams = {};
5968
+ if ((options === null || options === void 0 ? void 0 : options.comparisonDays) !== undefined) {
5969
+ queryParams.comparisonDays = options.comparisonDays;
5970
+ }
5971
+ return httpClient.get(`/${marketId}/debt/operational-overview`, queryParams);
5972
+ },
5973
+ getDebtBehavior: async (marketId, options) => {
5974
+ let overview = await reports.getDebtOperationalOverview(marketId, options);
5975
+ return {
5976
+ customers: overview.customers.map((customer) => ({
5977
+ customerId: customer.customerId,
5978
+ displayName: customer.displayName,
5979
+ accountNumber: customer.accountNumber,
5980
+ balanceInCents: customer.balanceInCents,
5981
+ balanceXDaysAgoInCents: customer.balanceXDaysAgoInCents,
5982
+ balanceChangeInCents: customer.balanceChangeInCents,
5983
+ balanceChangePercent: customer.balanceChangePercent,
5984
+ paymentBehavior: customer.paymentBehavior,
5985
+ warningSignCodes: customer.warningSignCodes,
5986
+ warningSignLabels: customer.warningSignLabels,
5987
+ })),
5988
+ };
5989
+ },
5990
+ getDebtProduct: async (marketId, options) => {
5991
+ let queryParams = {};
5992
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
5993
+ queryParams.limit = options.limit;
5994
+ }
5995
+ return httpClient.get(`/${marketId}/debt/outstanding-by-product`, queryParams);
5996
+ },
5997
+ };
5998
+ return reports;
5999
+ }
6000
+
6001
+ function create$8(httpClient) {
5959
6002
  return {
5960
6003
  get: async (marketId, saleId, options) => {
5961
6004
  return httpClient.get(`/${marketId}/sales/${saleId}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -5972,7 +6015,7 @@ function create$9(httpClient) {
5972
6015
  };
5973
6016
  }
5974
6017
 
5975
- function create$8(httpClient) {
6018
+ function create$7(httpClient) {
5976
6019
  return {
5977
6020
  list: async (marketId) => {
5978
6021
  return httpClient.get(`/${marketId}/sale-templates`);
@@ -5992,7 +6035,7 @@ function create$8(httpClient) {
5992
6035
  };
5993
6036
  }
5994
6037
 
5995
- function create$7(httpClient) {
6038
+ function create$6(httpClient) {
5996
6039
  let search = {
5997
6040
  /**
5998
6041
  * Search for documents within a market
@@ -6007,7 +6050,7 @@ function create$7(httpClient) {
6007
6050
  return search;
6008
6051
  }
6009
6052
 
6010
- function create$6(httpClient) {
6053
+ function create$5(httpClient) {
6011
6054
  return {
6012
6055
  get: async (marketId, options) => {
6013
6056
  return httpClient.get(`/${marketId}/settings`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -6015,60 +6058,13 @@ function create$6(httpClient) {
6015
6058
  };
6016
6059
  }
6017
6060
 
6018
- function create$5(httpClient) {
6019
- return {
6020
- list: async (marketId) => {
6021
- return httpClient.get(`/${marketId}/tax_rates`);
6022
- },
6023
- get: async (marketId, id) => {
6024
- return httpClient.get(`/${marketId}/tax_rates/${id}`);
6025
- },
6026
- };
6027
- }
6028
-
6029
- // Path: studiojs/src/resources/markets.ts
6030
- function create$4(_) {
6031
- const webhooks = {
6032
- /***
6033
- * This is used to construct the webhook event from the request body
6034
- * @param body the request body
6035
- * @param signature the signature of the request taken from the header
6036
- * @param endpointSecret the pre-shared secret
6037
- * @returns the webhook event
6038
- */
6039
- constructEvent: async (bodyAsBuffer, signature, endpointSecret) => {
6040
- if (!endpointSecret) {
6041
- throw new Error("Endpoint secret is required");
6042
- }
6043
- if (!signature) {
6044
- throw new Error("Signature is required");
6045
- }
6046
- let bodyText = bodyAsBuffer.toString();
6047
- let expectedSignature = createHmac("sha256", endpointSecret)
6048
- .update(bodyText)
6049
- .digest("hex");
6050
- if (signature !== expectedSignature) {
6051
- console.error(`Unable to construct event. Signature mismatch.`, signature, "!=", expectedSignature);
6052
- throw new Error(`Unable to construct event. Signature mismatch.`);
6053
- }
6054
- try {
6055
- return JSON.parse(bodyText);
6056
- }
6057
- catch (e) {
6058
- throw new Error(`Unable to construct event. ${e}`);
6059
- }
6060
- },
6061
- };
6062
- return webhooks;
6063
- }
6064
-
6065
- function create$3(httpClient) {
6061
+ function create$4(httpClient) {
6066
6062
  return {
6067
6063
  lookup: async (marketId, cph) => httpClient.get(`/${marketId}/cph`, { cph }),
6068
6064
  };
6069
6065
  }
6070
6066
 
6071
- function create$2(httpClient) {
6067
+ function create$3(httpClient) {
6072
6068
  return {
6073
6069
  list: async (marketId, customerId, params) => {
6074
6070
  const query = {};
@@ -6093,7 +6089,7 @@ function create$2(httpClient) {
6093
6089
  };
6094
6090
  }
6095
6091
 
6096
- function create$1(httpClient) {
6092
+ function create$2(httpClient) {
6097
6093
  let ledger = {
6098
6094
  /**
6099
6095
  * Get the current balance for a ledger account
@@ -6154,42 +6150,83 @@ function create$1(httpClient) {
6154
6150
  return ledger;
6155
6151
  }
6156
6152
 
6157
- function create(httpClient) {
6153
+ function create$1(httpClient) {
6158
6154
  return {
6159
- sendSMS: async (marketId, data) => httpClient.post(`/${marketId}/sms/send`, data),
6160
- getSMS: async (marketId, smsId) => httpClient.get(`/${marketId}/sms/${smsId}`),
6155
+ list: async (marketId) => {
6156
+ return httpClient.get(`/${marketId}/tax_rates`);
6157
+ },
6158
+ get: async (marketId, id) => {
6159
+ return httpClient.get(`/${marketId}/tax_rates/${id}`);
6160
+ },
6161
6161
  };
6162
6162
  }
6163
6163
 
6164
+ // Path: studiojs/src/resources/markets.ts
6165
+ function create(_) {
6166
+ const webhooks = {
6167
+ /***
6168
+ * This is used to construct the webhook event from the request body
6169
+ * @param body the request body
6170
+ * @param signature the signature of the request taken from the header
6171
+ * @param endpointSecret the pre-shared secret
6172
+ * @returns the webhook event
6173
+ */
6174
+ constructEvent: async (bodyAsBuffer, signature, endpointSecret) => {
6175
+ if (!endpointSecret) {
6176
+ throw new Error("Endpoint secret is required");
6177
+ }
6178
+ if (!signature) {
6179
+ throw new Error("Signature is required");
6180
+ }
6181
+ let bodyText = bodyAsBuffer.toString();
6182
+ let expectedSignature = createHmac("sha256", endpointSecret)
6183
+ .update(bodyText)
6184
+ .digest("hex");
6185
+ if (signature !== expectedSignature) {
6186
+ console.error(`Unable to construct event. Signature mismatch.`, signature, "!=", expectedSignature);
6187
+ throw new Error(`Unable to construct event. Signature mismatch.`);
6188
+ }
6189
+ try {
6190
+ return JSON.parse(bodyText);
6191
+ }
6192
+ catch (e) {
6193
+ throw new Error(`Unable to construct event. ${e}`);
6194
+ }
6195
+ },
6196
+ };
6197
+ return webhooks;
6198
+ }
6199
+
6164
6200
  function resources(httpClient) {
6165
6201
  return {
6166
- activity: create$p(httpClient),
6202
+ activity: create$q(httpClient),
6203
+ broadcast: create$l(httpClient),
6167
6204
  markets: create$e(httpClient),
6168
6205
  members: create$d(httpClient),
6169
- sales: create$9(httpClient),
6206
+ sales: create$8(httpClient),
6170
6207
  lots: create$f(httpClient),
6171
6208
  lotitems: create$g(httpClient),
6172
- carts: create$n(httpClient),
6173
- cph: create$3(httpClient),
6174
- webhooks: create$4(),
6175
- actions: create$q(),
6176
- bidderApplications: create$l(httpClient),
6177
- settings: create$6(httpClient),
6178
- adjustments: create$o(httpClient),
6179
- extras: create$m(httpClient),
6209
+ carts: create$o(httpClient),
6210
+ cph: create$4(httpClient),
6211
+ webhooks: create(),
6212
+ actions: create$r(),
6213
+ bidderApplications: create$m(httpClient),
6214
+ settings: create$5(httpClient),
6215
+ adjustments: create$p(httpClient),
6216
+ extras: create$n(httpClient),
6180
6217
  productCodes: create$a(httpClient),
6181
- saleTemplates: create$8(httpClient),
6182
- taxRates: create$5(httpClient),
6218
+ saleTemplates: create$7(httpClient),
6219
+ taxRates: create$1(httpClient),
6183
6220
  customers: create$k(httpClient),
6184
6221
  customerLists: create$j(httpClient),
6185
6222
  invoices: create$h(httpClient),
6186
6223
  payments: create$c(httpClient),
6187
6224
  payouts: create$b(httpClient),
6188
- search: create$7(httpClient),
6225
+ reports: create$9(httpClient),
6226
+ search: create$6(httpClient),
6189
6227
  files: create$i(),
6190
- contacts: create$2(httpClient),
6191
- ledger: create$1(httpClient),
6192
- sms: create(httpClient),
6228
+ contacts: create$3(httpClient),
6229
+ ledger: create$2(httpClient),
6193
6230
  };
6194
6231
  }
6195
6232