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