@marteye/studiojs 1.1.36 → 1.1.38

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
@@ -60,6 +60,9 @@ function SimpleHttpClient(baseUrl, apiKey, fetch, defaultTimeout, debug = false)
60
60
  post: async (path, body) => {
61
61
  return request("POST", path, body);
62
62
  },
63
+ patch: async (path, body) => {
64
+ return request("PATCH", path, body);
65
+ },
63
66
  delete: async (path) => {
64
67
  return request("DELETE", path);
65
68
  },
@@ -67,7 +70,7 @@ function SimpleHttpClient(baseUrl, apiKey, fetch, defaultTimeout, debug = false)
67
70
  }
68
71
 
69
72
  // Path: studiojs/src/resources/markets.ts
70
- function create$g(_) {
73
+ function create$m(_) {
71
74
  const actions = {
72
75
  /***
73
76
  * This is used to construct the action from the request body
@@ -97,7 +100,7 @@ function create$g(_) {
97
100
  return actions;
98
101
  }
99
102
 
100
- function create$f(httpClient) {
103
+ function create$l(httpClient) {
101
104
  return {
102
105
  list: async (marketId) => {
103
106
  return httpClient.get(`/${marketId}/adjustments`);
@@ -105,13 +108,59 @@ function create$f(httpClient) {
105
108
  get: async (marketId, id) => {
106
109
  return httpClient.get(`/${marketId}/adjustments/${id}`);
107
110
  },
111
+ create: async (marketId, data) => {
112
+ return httpClient.post(`/${marketId}/adjustments`, data);
113
+ },
114
+ update: async (marketId, id, data) => {
115
+ return httpClient.post(`/${marketId}/adjustments/${id}`, data);
116
+ },
117
+ };
118
+ }
119
+
120
+ function create$k(httpClient) {
121
+ return {
122
+ /**
123
+ * Get the full cart for a customer including extras and uninvoiced lots
124
+ */
125
+ get: async (marketId, customerId) => {
126
+ return httpClient.get(`/${marketId}/carts/${customerId}`);
127
+ },
128
+ /**
129
+ * Add an extra product to the customer's cart
130
+ */
131
+ addExtra: async (marketId, customerId, data) => {
132
+ return httpClient.post(`/${marketId}/carts/${customerId}`, data);
133
+ },
134
+ /**
135
+ * Remove an extra from the customer's cart
136
+ */
137
+ removeExtra: async (marketId, customerId, itemId) => {
138
+ return httpClient.delete(`/${marketId}/carts/${customerId}/${itemId}`);
139
+ },
140
+ };
141
+ }
142
+
143
+ function create$j(httpClient) {
144
+ return {
145
+ list: async (marketId) => {
146
+ return httpClient.get(`/${marketId}/extras`);
147
+ },
148
+ get: async (marketId, id) => {
149
+ return httpClient.get(`/${marketId}/extras/${id}`);
150
+ },
151
+ create: async (marketId, data) => {
152
+ return httpClient.post(`/${marketId}/extras`, data);
153
+ },
154
+ update: async (marketId, id, data) => {
155
+ return httpClient.post(`/${marketId}/extras/${id}`, data);
156
+ },
108
157
  };
109
158
  }
110
159
 
111
160
  /***
112
161
  * Bidder applications
113
162
  */
114
- function create$e(httpClient) {
163
+ function create$i(httpClient) {
115
164
  let applications = {
116
165
  /**
117
166
  * List applications for a market with optional filtering
@@ -178,7 +227,7 @@ function create$e(httpClient) {
178
227
  }
179
228
 
180
229
  // Path: studiojs/src/resources/markets.ts
181
- function create$d(httpClient) {
230
+ function create$h(httpClient) {
182
231
  let customers = {
183
232
  list: async (marketId, lastId) => {
184
233
  let params = {};
@@ -196,6 +245,9 @@ function create$d(httpClient) {
196
245
  create: async (marketId, customerData) => {
197
246
  return httpClient.post(`/${marketId}/customers`, customerData);
198
247
  },
248
+ update: async (marketId, customerId, customerData) => {
249
+ return httpClient.post(`/${marketId}/customers/${customerId}`, customerData);
250
+ },
199
251
  /**
200
252
  * Get a customer by their account number
201
253
  * @param marketId - ID of the market the customer belongs to
@@ -5012,7 +5064,7 @@ const uploadSingleFile = async (input, token) => {
5012
5064
  };
5013
5065
 
5014
5066
  // Multipart Upload for Media to the MARTEYE Media Service
5015
- function create$c() {
5067
+ function create$g() {
5016
5068
  const files = {
5017
5069
  uploadSingleFile: async (input, token) => {
5018
5070
  return await uploadSingleFile(input, token);
@@ -5027,7 +5079,7 @@ function create$c() {
5027
5079
  return files;
5028
5080
  }
5029
5081
 
5030
- function create$b(httpClient) {
5082
+ function create$f(httpClient) {
5031
5083
  const invoices = {
5032
5084
  /**
5033
5085
  * List all invoices for a market with pagination
@@ -5055,7 +5107,7 @@ function create$b(httpClient) {
5055
5107
  return invoices;
5056
5108
  }
5057
5109
 
5058
- function create$a(httpClient) {
5110
+ function create$e(httpClient) {
5059
5111
  return {
5060
5112
  create: async (marketId, saleId, lotId, data) => {
5061
5113
  return httpClient.post(`/${marketId}/sales/${saleId}/lots/${lotId}/items`, data);
@@ -5072,7 +5124,7 @@ function create$a(httpClient) {
5072
5124
  /**
5073
5125
  * Defines the possible status values for a lot in a sale
5074
5126
  */
5075
- function create$9(httpClient) {
5127
+ function create$d(httpClient) {
5076
5128
  return {
5077
5129
  get: async (marketId, saleId, lotId) => {
5078
5130
  return httpClient.get(`/${marketId}/sales/${saleId}/lots/${lotId}`);
@@ -5092,7 +5144,7 @@ function create$9(httpClient) {
5092
5144
  };
5093
5145
  }
5094
5146
 
5095
- function create$8(httpClient) {
5147
+ function create$c(httpClient) {
5096
5148
  const markets = {
5097
5149
  get: async (marketId) => {
5098
5150
  return httpClient.get(`/${marketId}`);
@@ -5114,7 +5166,7 @@ function create$8(httpClient) {
5114
5166
  return markets;
5115
5167
  }
5116
5168
 
5117
- function create$7(httpClient) {
5169
+ function create$b(httpClient) {
5118
5170
  const payments = {
5119
5171
  /**
5120
5172
  * List all payments for a market with pagination
@@ -5142,7 +5194,7 @@ function create$7(httpClient) {
5142
5194
  return payments;
5143
5195
  }
5144
5196
 
5145
- function create$6(httpClient) {
5197
+ function create$a(httpClient) {
5146
5198
  const payouts = {
5147
5199
  /**
5148
5200
  * List all payouts for a market with pagination
@@ -5170,18 +5222,24 @@ function create$6(httpClient) {
5170
5222
  return payouts;
5171
5223
  }
5172
5224
 
5173
- function create$5(httpClient) {
5225
+ function create$9(httpClient) {
5174
5226
  return {
5175
5227
  list: async (marketId) => {
5176
- return httpClient.get(`/${marketId}/product_codes`);
5228
+ return httpClient.get(`/${marketId}/product-codes`);
5177
5229
  },
5178
5230
  get: async (marketId, id) => {
5179
- return httpClient.get(`/${marketId}/product_codes/${id}`);
5231
+ return httpClient.get(`/${marketId}/product-codes/${id}`);
5232
+ },
5233
+ create: async (marketId, data) => {
5234
+ return httpClient.post(`/${marketId}/product-codes`, data);
5235
+ },
5236
+ update: async (marketId, id, data) => {
5237
+ return httpClient.post(`/${marketId}/product-codes/${id}`, data);
5180
5238
  },
5181
5239
  };
5182
5240
  }
5183
5241
 
5184
- function create$4(httpClient) {
5242
+ function create$8(httpClient) {
5185
5243
  return {
5186
5244
  get: async (marketId, saleId) => {
5187
5245
  return httpClient.get(`/${marketId}/sales/${saleId}`);
@@ -5198,7 +5256,27 @@ function create$4(httpClient) {
5198
5256
  };
5199
5257
  }
5200
5258
 
5201
- function create$3(httpClient) {
5259
+ function create$7(httpClient) {
5260
+ return {
5261
+ list: async (marketId) => {
5262
+ return httpClient.get(`/${marketId}/sale-templates`);
5263
+ },
5264
+ get: async (marketId, templateId) => {
5265
+ return httpClient.get(`/${marketId}/sale-templates/${templateId}`);
5266
+ },
5267
+ create: async (marketId, body) => {
5268
+ return httpClient.post(`/${marketId}/sale-templates`, body);
5269
+ },
5270
+ update: async (marketId, templateId, body) => {
5271
+ return httpClient.post(`/${marketId}/sale-templates/${templateId}`, body);
5272
+ },
5273
+ delete: async (marketId, templateId) => {
5274
+ return httpClient.delete(`/${marketId}/sale-templates/${templateId}`);
5275
+ },
5276
+ };
5277
+ }
5278
+
5279
+ function create$6(httpClient) {
5202
5280
  let search = {
5203
5281
  /**
5204
5282
  * Search for documents within a market
@@ -5213,7 +5291,7 @@ function create$3(httpClient) {
5213
5291
  return search;
5214
5292
  }
5215
5293
 
5216
- function create$2(httpClient) {
5294
+ function create$5(httpClient) {
5217
5295
  return {
5218
5296
  get: async (marketId) => {
5219
5297
  return httpClient.get(`/${marketId}/settings`);
@@ -5221,7 +5299,7 @@ function create$2(httpClient) {
5221
5299
  };
5222
5300
  }
5223
5301
 
5224
- function create$1(httpClient) {
5302
+ function create$4(httpClient) {
5225
5303
  return {
5226
5304
  list: async (marketId) => {
5227
5305
  return httpClient.get(`/${marketId}/tax_rates`);
@@ -5233,7 +5311,7 @@ function create$1(httpClient) {
5233
5311
  }
5234
5312
 
5235
5313
  // Path: studiojs/src/resources/markets.ts
5236
- function create(_) {
5314
+ function create$3(_) {
5237
5315
  const webhooks = {
5238
5316
  /***
5239
5317
  * This is used to construct the webhook event from the request body
@@ -5268,25 +5346,78 @@ function create(_) {
5268
5346
  return webhooks;
5269
5347
  }
5270
5348
 
5349
+ function create$2(httpClient) {
5350
+ return {
5351
+ lookup: async (marketId, cph) => httpClient.get(`/${marketId}/cph`, { cph }),
5352
+ };
5353
+ }
5354
+
5355
+ function create$1(httpClient) {
5356
+ return {
5357
+ list: async (marketId, customerId, params) => {
5358
+ const query = {};
5359
+ if (params === null || params === void 0 ? void 0 : params.lastId)
5360
+ query.lastId = params.lastId;
5361
+ if (params === null || params === void 0 ? void 0 : params.limit)
5362
+ query.limit = params.limit;
5363
+ return httpClient.get(`/${marketId}/customers/${customerId}/contacts`, query);
5364
+ },
5365
+ get: async (marketId, customerId, contactId) => {
5366
+ return httpClient.get(`/${marketId}/customers/${customerId}/contacts/${contactId}`);
5367
+ },
5368
+ create: async (marketId, customerId, payload) => {
5369
+ return httpClient.post(`/${marketId}/customers/${customerId}/contacts`, payload);
5370
+ },
5371
+ update: async (marketId, customerId, contactId, payload) => {
5372
+ return httpClient.post(`/${marketId}/customers/${customerId}/contacts/${contactId}`, payload);
5373
+ },
5374
+ delete: async (marketId, customerId, contactId) => {
5375
+ return httpClient.delete(`/${marketId}/customers/${customerId}/contacts/${contactId}`);
5376
+ },
5377
+ };
5378
+ }
5379
+
5380
+ function create(httpClient) {
5381
+ let ledger = {
5382
+ /**
5383
+ * Get the current balance for a ledger account
5384
+ * @param marketId - ID of the market
5385
+ * @param account - Full account string (format: owner:accountType:accountName)
5386
+ * e.g. "customerId:asset:trade receivable" or "market:liability:trade payable"
5387
+ * @returns The current balance in cents
5388
+ */
5389
+ getBalance: async (marketId, account) => {
5390
+ return httpClient.get(`/${marketId}/ledger/balance`, { account });
5391
+ },
5392
+ };
5393
+ return ledger;
5394
+ }
5395
+
5271
5396
  function resources(httpClient) {
5272
5397
  return {
5273
- markets: create$8(httpClient),
5274
- sales: create$4(httpClient),
5275
- lots: create$9(httpClient),
5276
- lotitems: create$a(httpClient),
5277
- webhooks: create(),
5278
- actions: create$g(),
5279
- bidderApplications: create$e(httpClient),
5280
- settings: create$2(httpClient),
5281
- adjustments: create$f(httpClient),
5282
- productCodes: create$5(httpClient),
5283
- taxRates: create$1(httpClient),
5284
- customers: create$d(httpClient),
5285
- invoices: create$b(httpClient),
5286
- payments: create$7(httpClient),
5287
- payouts: create$6(httpClient),
5288
- search: create$3(httpClient),
5289
- files: create$c(),
5398
+ markets: create$c(httpClient),
5399
+ sales: create$8(httpClient),
5400
+ lots: create$d(httpClient),
5401
+ lotitems: create$e(httpClient),
5402
+ carts: create$k(httpClient),
5403
+ cph: create$2(httpClient),
5404
+ webhooks: create$3(),
5405
+ actions: create$m(),
5406
+ bidderApplications: create$i(httpClient),
5407
+ settings: create$5(httpClient),
5408
+ adjustments: create$l(httpClient),
5409
+ extras: create$j(httpClient),
5410
+ productCodes: create$9(httpClient),
5411
+ saleTemplates: create$7(httpClient),
5412
+ taxRates: create$4(httpClient),
5413
+ customers: create$h(httpClient),
5414
+ invoices: create$f(httpClient),
5415
+ payments: create$b(httpClient),
5416
+ payouts: create$a(httpClient),
5417
+ search: create$6(httpClient),
5418
+ files: create$g(),
5419
+ contacts: create$1(httpClient),
5420
+ ledger: create(httpClient),
5290
5421
  };
5291
5422
  }
5292
5423
 
@@ -5597,59 +5728,133 @@ EarTag.countryCodes = {
5597
5728
  BE: "056",
5598
5729
  };
5599
5730
 
5731
+ /**
5732
+ * Extract the smallest lot number for sorting purposes.
5733
+ * Handles formats:
5734
+ * - Simple: "7" -> 7
5735
+ * - Alpha suffix: "7A" -> 7
5736
+ * - Range: "7-9" -> 7
5737
+ * - Range with alpha: "7A-9A" -> 7
5738
+ * - With gaps: "7-8, 10" -> 7
5739
+ * - Complex: "7A-8A, 10B" -> 7
5740
+ */
5741
+ function extractMinLotNumber(lotNumber) {
5742
+ // Handle empty/null
5743
+ if (!lotNumber)
5744
+ return { num: null, alpha: "" };
5745
+ // Split by comma first (handles "7-8, 10" format), flexible with whitespace
5746
+ let segments = lotNumber.split(/\s*,\s*/);
5747
+ let minNum = null;
5748
+ let minAlpha = "";
5749
+ for (let segment of segments) {
5750
+ // Split by hyphen (handles "7-9" range format), flexible with whitespace
5751
+ let rangeParts = segment.split(/\s*-\s*/);
5752
+ for (let part of rangeParts) {
5753
+ // Extract number and alpha from each part (e.g., "7A" -> 7, "A")
5754
+ let match = part.trim().match(/^(\d+)(\D*)$/);
5755
+ if (match) {
5756
+ let num = parseInt(match[1], 10);
5757
+ let alpha = match[2] || "";
5758
+ if (minNum === null ||
5759
+ num < minNum ||
5760
+ (num === minNum && alpha < minAlpha)) {
5761
+ minNum = num;
5762
+ minAlpha = alpha;
5763
+ }
5764
+ }
5765
+ }
5766
+ }
5767
+ return { num: minNum, alpha: minAlpha };
5768
+ }
5600
5769
  function lotComparator(a, b) {
5601
- const aMatch = a.lotNumber.match(/^(\d+)(\D*)$/);
5602
- const bMatch = b.lotNumber.match(/^(\d+)(\D*)$/);
5603
- // If neither matches the pattern, fall back to string comparison
5604
- if (!aMatch && !bMatch) {
5770
+ let aMin = extractMinLotNumber(a.lotNumber);
5771
+ let bMin = extractMinLotNumber(b.lotNumber);
5772
+ // If neither has numbers, fall back to string comparison
5773
+ if (aMin.num === null && bMin.num === null) {
5605
5774
  return a.lotNumber.localeCompare(b.lotNumber);
5606
5775
  }
5607
- // If only one matches, the one with numbers comes after
5608
- if (!aMatch)
5776
+ // If only one has numbers, the one without comes first
5777
+ if (aMin.num === null)
5609
5778
  return -1;
5610
- if (!bMatch)
5779
+ if (bMin.num === null)
5611
5780
  return 1;
5612
- // Handle cases with numbers
5613
- const aNum = parseInt(aMatch[1], 10);
5614
- const bNum = parseInt(bMatch[1], 10);
5615
- // Compare numeric parts first
5616
- if (aNum !== bNum)
5617
- return aNum - bNum;
5618
- // Get alphabetic suffixes (or empty string if none)
5619
- const aAlpha = (aMatch === null || aMatch === void 0 ? void 0 : aMatch[2]) || "";
5620
- const bAlpha = (bMatch === null || bMatch === void 0 ? void 0 : bMatch[2]) || "";
5621
- // Compare by length first (shorter comes first)
5622
- if (aAlpha.length !== bAlpha.length)
5623
- return aAlpha.length - bAlpha.length;
5624
- // Then compare alphabetically
5625
- return aAlpha.localeCompare(bAlpha);
5781
+ // Compare numeric parts
5782
+ if (aMin.num !== bMin.num)
5783
+ return aMin.num - bMin.num;
5784
+ // Compare alpha suffixes by length then alphabetically
5785
+ if (aMin.alpha.length !== bMin.alpha.length) {
5786
+ return aMin.alpha.length - bMin.alpha.length;
5787
+ }
5788
+ return aMin.alpha.localeCompare(bMin.alpha);
5626
5789
  }
5627
5790
  function sortByLotNumber(lots) {
5628
5791
  return [...lots].sort(lotComparator);
5629
5792
  }
5630
5793
  /***
5631
- * Generate the next lot number in a sequence:
5794
+ * Generate the next lot number in a sequence.
5795
+ * Handles various formats:
5796
+ * - Simple: "7" -> "8"
5797
+ * - Alphanumeric: "7A" -> "7B"
5798
+ * - Range: "1-3" -> "4", "1 - 3" -> "4" (flexible whitespace)
5799
+ * - Range with alpha: "1-3A" -> "3B"
5800
+ * - Compound: "1-3, 10" -> "11", "1-5, 7-9" -> "10"
5632
5801
  */
5633
5802
  function nextLotNumber(previousLotNumber) {
5634
- const match = previousLotNumber.match(/^(\d+)(\D*)$/);
5635
- if (match) {
5636
- // Has numeric part
5637
- const numPart = parseInt(match[1], 10);
5638
- const alphaPart = match[2];
5639
- if (alphaPart === "") {
5640
- // Just a number: 1 -> 2
5641
- return (numPart + 1).toString();
5803
+ // Helper to compare alpha suffixes (longer = greater, then alphabetically)
5804
+ function isGreaterAlpha(a, b) {
5805
+ let aUpper = a.toUpperCase();
5806
+ let bUpper = b.toUpperCase();
5807
+ if (aUpper.length !== bUpper.length) {
5808
+ return aUpper.length > bUpper.length;
5809
+ }
5810
+ return aUpper > bUpper;
5811
+ }
5812
+ // Split by comma (handles "7-8, 10" format), flexible with whitespace
5813
+ let segments = previousLotNumber.split(/\s*,\s*/);
5814
+ let maxNum = null;
5815
+ let maxAlpha = "";
5816
+ for (let segment of segments) {
5817
+ // Check if segment is a range (contains hyphen with numbers on both sides)
5818
+ // Flexible with whitespace: "1-3", "1 - 3", "1- 3", "1 -3", "1 -3"
5819
+ let rangeMatch = segment.trim().match(/^(\d+)\s*-\s*(\d+)(\D*)$/);
5820
+ if (rangeMatch) {
5821
+ // Range format: take the end number
5822
+ let endNum = parseInt(rangeMatch[2], 10);
5823
+ let alphaPart = rangeMatch[3] || "";
5824
+ if (maxNum === null ||
5825
+ endNum > maxNum ||
5826
+ (endNum === maxNum && isGreaterAlpha(alphaPart, maxAlpha))) {
5827
+ maxNum = endNum;
5828
+ maxAlpha = alphaPart;
5829
+ }
5642
5830
  }
5643
5831
  else {
5644
- // Alphanumeric: increment the alpha part
5645
- const nextAlpha = incrementAlphaSequence(alphaPart);
5646
- return numPart + nextAlpha;
5832
+ // Single value: "7" or "7A"
5833
+ let singleMatch = segment.trim().match(/^(\d+)(\D*)$/);
5834
+ if (singleMatch) {
5835
+ let num = parseInt(singleMatch[1], 10);
5836
+ let alphaPart = singleMatch[2] || "";
5837
+ if (maxNum === null ||
5838
+ num > maxNum ||
5839
+ (num === maxNum && isGreaterAlpha(alphaPart, maxAlpha))) {
5840
+ maxNum = num;
5841
+ maxAlpha = alphaPart;
5842
+ }
5843
+ }
5647
5844
  }
5648
5845
  }
5649
- else {
5650
- // Pure alphabetic: A -> B, Z -> AA, etc.
5651
- return incrementAlphaSequence(previousLotNumber);
5846
+ // If we found numeric parts, increment
5847
+ if (maxNum !== null) {
5848
+ if (maxAlpha === "") {
5849
+ return (maxNum + 1).toString();
5850
+ }
5851
+ else {
5852
+ let nextAlpha = incrementAlphaSequence(maxAlpha);
5853
+ return maxNum + nextAlpha;
5854
+ }
5652
5855
  }
5856
+ // Fallback: treat as pure alphabetic (e.g., "A" -> "B")
5857
+ return incrementAlphaSequence(previousLotNumber);
5653
5858
  }
5654
5859
  function incrementAlphaSequence(alpha) {
5655
5860
  if (alpha === "") {