@marteye/studiojs 1.0.0 → 1.1.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.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # MartEye Studio JavaScript SDK (@marteye/studiojs)
2
+
3
+ This library is a JavaScript SDK that allows you to easily integrate with MartEye Studio's API. It provides methods to interact with various resources, manage data, and leverage the powerful features offered by MartEye Studio.
4
+
5
+ ## Installation
6
+
7
+ You can install the library using npm or yarn:
8
+
9
+ Using npm:
10
+
11
+ ```bash
12
+ npm install @marteye/studiojs
13
+ ```
14
+
15
+ Using yarn:
16
+
17
+ ```bash
18
+ yarn add @marteye/studiojs
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Importing the Library
24
+
25
+ Using ES Modules:
26
+
27
+ ```javascript
28
+ import StudioJS from "@marteye/studiojs";
29
+ ```
30
+
31
+ Or using CommonJS:
32
+
33
+ ```javascript
34
+ let StudioJS = require("@marteye/studiojs");
35
+ ```
36
+
37
+ ### Initializing the SDK
38
+
39
+ Before using the library, initialize it with your API key. For more information on obtaining an API key, please contact your MartEye representative.
40
+
41
+ ```javascript
42
+ let studioClient = StudioJS.init({
43
+ apiKey: "YOUR_API_KEY_HERE",
44
+ });
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ Contributions are welcome! Please open an issue or submit a pull request if you have suggestions or improvements.
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,64 @@
1
+ import { WebhookEventName } from "./types";
2
+ /**
3
+ * Headers used by Studio to identify webhook and action requests
4
+ */
5
+ export declare const StudioHeaders: {
6
+ marketId: string;
7
+ webhookId: string;
8
+ action: string;
9
+ apiKey: string;
10
+ signature: string;
11
+ };
12
+ export interface StudioManifest {
13
+ id: string;
14
+ name: string;
15
+ version: string;
16
+ description: string;
17
+ icon: string;
18
+ author: string;
19
+ actions: {
20
+ name: string;
21
+ url: string;
22
+ }[];
23
+ webhooks: {
24
+ url: string;
25
+ triggers: WebhookEventName[];
26
+ }[];
27
+ parameterConfig: {
28
+ id: string;
29
+ type: "string" | "number" | "boolean" | "string[]" | "password";
30
+ label: string;
31
+ description?: string;
32
+ required?: boolean;
33
+ defaultValue?: string | number | boolean | string[];
34
+ }[];
35
+ }
36
+ /***
37
+ * Creates an app manifest used to describe the app to Studio
38
+ *
39
+ * @param appConfig
40
+ * @returns
41
+ */
42
+ export declare function createAppManifest(appConfig: {
43
+ id: string;
44
+ name: string;
45
+ version: string;
46
+ description: string;
47
+ icon: string;
48
+ author: string;
49
+ }): {
50
+ addWebhook: (url: string, triggers: WebhookEventName[]) => void;
51
+ addConfig: (config: {
52
+ id: string;
53
+ type: "string" | "number" | "boolean" | "string[]" | "password";
54
+ label: string;
55
+ description?: string;
56
+ required?: boolean;
57
+ defaultValue?: string | number | boolean | string[];
58
+ }) => void;
59
+ addAction: (action: {
60
+ name: string;
61
+ url: string;
62
+ }) => void;
63
+ readonly manifest: StudioManifest;
64
+ };
@@ -0,0 +1,477 @@
1
+ type Timestamp = string;
2
+ type SuperType = "Sheep" | "Goats" | "Cattle" | "Pigs" | "Horses" | "Deer" | "Poultry" | "Machinery" | "Antiques" | "Other";
3
+ type Currency = "GBP" | "EUR" | "USD";
4
+ type SupportedCountryCode = "GB-ENG" | "GB-SCT" | "GB-WLS" | "GB-NIR" | "IE";
5
+ type CurrenciesWithGuinea = Currency | "GUINEA-GBP";
6
+ type UnitOfSale = "Per KG" | "Per Item" | "Per Lot" | "Per 1000KG";
7
+ interface Market {
8
+ id: string;
9
+ createdAt: Timestamp;
10
+ updatedAt: Timestamp;
11
+ name: string;
12
+ description: string;
13
+ logo: string;
14
+ primaryColour: string;
15
+ secondaryColour: string;
16
+ countryCode: SupportedCountryCode;
17
+ address: Address;
18
+ telephone?: string;
19
+ vatNumber?: string;
20
+ email?: string;
21
+ movementLocationNumbers?: {
22
+ number: string;
23
+ type: "CPH" | "Herd Number" | "Flock Number" | "Other";
24
+ createdAt: Timestamp;
25
+ }[];
26
+ paymentInstructions?: string;
27
+ }
28
+ type AttributeValueType = string | number | boolean | Timestamp | Media;
29
+ interface Sale {
30
+ id: string;
31
+ createdAt: Timestamp;
32
+ updatedAt: Timestamp;
33
+ updatedBy?: string | null;
34
+ startsAt: Timestamp;
35
+ closedAt?: Timestamp | null;
36
+ marketId: string;
37
+ name: string;
38
+ recurring?: null | "Weekly" | "Bi-weekly" | "Monthly";
39
+ defaultProductCode: string;
40
+ /**
41
+ * Default attributes values for any new lot item
42
+ */
43
+ attributeDefaults?: {
44
+ [attributekey: string]: AttributeValueType;
45
+ };
46
+ /**
47
+ * the codes that are allowed for the sale
48
+ */
49
+ availableProductCodes: string[];
50
+ /**
51
+ * the supertypes from the product codes. e..g Cattle, Sheep, Pigs etc
52
+ */
53
+ superTypes: SuperType[];
54
+ attributeSet: AttributeDefinition[];
55
+ attributeSetByProductCode: {
56
+ [code: string]: string[];
57
+ };
58
+ currentLotGroup?: string | null;
59
+ nextLotGroup?: string | null;
60
+ /**
61
+ * Auto queue the next lot when the current lot is sold in rostrum
62
+ */
63
+ autoQueue?: boolean;
64
+ /**
65
+ * The sale profile ID to use for this sale. Which is used to find settings specific devices and printers etc.
66
+ */
67
+ saleProfileId?: string | null;
68
+ /**
69
+ * Show the display board
70
+ */
71
+ displayBoard?: boolean;
72
+ martEyeId?: string | null;
73
+ marteyeSettings?: MartEyeTimedSaleSettings | MartEyeLiveSaleSettings | null;
74
+ }
75
+ interface MartEyeLiveSaleSettings {
76
+ description?: string;
77
+ image?: string;
78
+ logo?: string;
79
+ type: "LIVE";
80
+ location?: string | null;
81
+ descriptionLines?: string[];
82
+ descriptionLink?: string;
83
+ deposit?: number;
84
+ hidePrices?: boolean;
85
+ hideReplay?: boolean;
86
+ labels?: string[];
87
+ tags?: string[];
88
+ }
89
+ interface MartEyeTimedSaleSettings {
90
+ description?: string;
91
+ image?: string;
92
+ logo?: string;
93
+ type: "TIMED";
94
+ /**
95
+ * The location of the sale. This could be a physical location Ring 1 / Ring 2 / Farm Address etc
96
+ */
97
+ location?: string | null;
98
+ details?: {
99
+ markdownBase64: string;
100
+ title: string;
101
+ }[];
102
+ cover?: string;
103
+ primaryColour?: string;
104
+ secondaryColour?: string;
105
+ foregroundColour?: string;
106
+ extensionTime: number;
107
+ incrementLadder: IncrementLadder;
108
+ hideNav?: boolean;
109
+ signInOverrideLink?: string;
110
+ published?: boolean;
111
+ pin?: boolean;
112
+ labels?: string[];
113
+ deposit?: number;
114
+ cascade?: boolean;
115
+ reportEmail?: string;
116
+ }
117
+ type IncrementLadder = IncrementLadderItem[];
118
+ interface IncrementLadderItem {
119
+ max: number;
120
+ increment: number;
121
+ }
122
+ type LotSaleStatus = "Sold" | "Unsold" | "Rerun" | "Resold" | null;
123
+ interface Lot {
124
+ id: string;
125
+ saleId: string;
126
+ marketId: string;
127
+ createdAt: Timestamp;
128
+ updatedAt: Timestamp;
129
+ updatedBy?: string | null;
130
+ productCode: string;
131
+ superType?: SuperType;
132
+ isLivestock?: boolean;
133
+ attributes: {
134
+ [key: string]: AttributeValueType;
135
+ };
136
+ loadingAttributes?: {
137
+ [attributePath: string]: {
138
+ id: string;
139
+ startAt: Timestamp;
140
+ path: string;
141
+ };
142
+ };
143
+ itemMap: {
144
+ [itemId: string]: LotItem;
145
+ };
146
+ sellerCasual?: string | null;
147
+ sellerCustomerId: string | null;
148
+ seller?: ShortCustomerDetails;
149
+ lotNumber?: string | null;
150
+ index: number;
151
+ group?: string;
152
+ remarks?: string;
153
+ notes?: string;
154
+ currency: CurrenciesWithGuinea;
155
+ unitOfSale: UnitOfSale;
156
+ unitPriceInCents?: number;
157
+ buyerCasual?: string | null;
158
+ buyerCustomerId: string | null;
159
+ buyer?: ShortCustomerDetails | null;
160
+ startedAt?: Timestamp;
161
+ endedAt?: Timestamp;
162
+ sellerInvoiceId: string | null;
163
+ sellerInvoiceNumber?: number | undefined | null;
164
+ buyerInvoiceId: string | null;
165
+ buyerInvoiceNumber?: number | undefined | null;
166
+ voidedSellerInvoiceIds?: string[];
167
+ voidedBuyerInvoiceIds?: string[];
168
+ saleStatus?: LotSaleStatus;
169
+ void?: boolean;
170
+ originalLot?: string;
171
+ metadata: {
172
+ [key: string]: any;
173
+ };
174
+ generated?: LotGeneratedValues;
175
+ issues?: {
176
+ [issueId: string]: LotIssue;
177
+ };
178
+ resolvedIssues?: {
179
+ [issueId: string]: LotIssue;
180
+ };
181
+ /***
182
+ * Default values for any new lot item
183
+ */
184
+ itemAttributeDefaults?: {
185
+ [attributekey: string]: AttributeValueType;
186
+ };
187
+ }
188
+ type LotIssueCode = "unknown-attribute" | "validation-error" | "staff-flagged";
189
+ interface LotIssue {
190
+ id: string;
191
+ itemId?: string | null;
192
+ path?: string | null;
193
+ code: LotIssueCode;
194
+ description: string;
195
+ severity: "error" | "warning" | "info";
196
+ createdAt: Timestamp;
197
+ createdBy: string;
198
+ blockCheckout: boolean;
199
+ }
200
+ interface LotGeneratedValues {
201
+ totalValueInCents?: number | null;
202
+ description?: string | null;
203
+ pricePerKiloInCents?: number | null;
204
+ averageWeightKg?: number | null;
205
+ pricePerItemInCents?: number | null;
206
+ countOfItems?: number | null;
207
+ }
208
+ interface ShortCustomerDetails {
209
+ isSet: boolean;
210
+ id?: string;
211
+ copiedInAt?: Timestamp;
212
+ accountNumber?: string;
213
+ bidderNumber?: number | null;
214
+ displayName?: string;
215
+ avatar?: string | null;
216
+ }
217
+ interface LotItem {
218
+ id: string;
219
+ createdAt: Timestamp;
220
+ updatedAt: Timestamp;
221
+ updatedBy?: string | null;
222
+ index: number;
223
+ attributes: {
224
+ [key: string]: AttributeValueType;
225
+ };
226
+ notes: {
227
+ id: string;
228
+ text: string;
229
+ createdAt: Timestamp;
230
+ }[];
231
+ metadata: {
232
+ [key: string]: string | number | boolean | Timestamp | Media;
233
+ };
234
+ }
235
+ interface Address {
236
+ id: string;
237
+ nickname?: string;
238
+ company?: string;
239
+ firstName?: string;
240
+ lastName?: string;
241
+ address1: string;
242
+ address2?: string;
243
+ city: string;
244
+ province?: string;
245
+ zip: string;
246
+ country: string;
247
+ }
248
+ interface ImageThumbnail {
249
+ url: string;
250
+ width: number;
251
+ height: number;
252
+ }
253
+ interface Media {
254
+ id: string;
255
+ url: string;
256
+ type: "image/jpeg" | "image/png" | "video/mp4" | "application/pdf";
257
+ filename: string;
258
+ thumbnails?: {
259
+ small?: ImageThumbnail;
260
+ medium?: ImageThumbnail;
261
+ large?: ImageThumbnail;
262
+ };
263
+ }
264
+ type WebhookEventName = "market.updated" | "sale.created" | "sale.updated" | "sale.deleted" | "lot.created" | "lot.updated" | "lot.deleted" | "lot.media.created" | "lot.media.deleted" | "invoice.created" | "invoice.updated" | "invoice.deleted" | "payment.created" | "payment.updated" | "payment.deleted" | "payout.created" | "payout.updated" | "payout.deleted" | "customer.created" | "customer.updated" | "customer.deleted" | "member.created" | "member.updated" | "member.deleted";
265
+ type SupportedAttributeTypes = "string" | "number" | "boolean" | "date" | "datetime" | "time";
266
+ interface AttributeDefinition {
267
+ id: string;
268
+ name: string;
269
+ shortName?: string;
270
+ description?: string;
271
+ applyTo: string[];
272
+ level: "item" | "lot";
273
+ readonly?: boolean;
274
+ lotDetailFlyoutGroup?: string;
275
+ buyerCheckoutGroup?: string;
276
+ sellerCheckoutGroup?: string;
277
+ buyerCustomerAttribute?: boolean;
278
+ sellerCustomerAttribute?: boolean;
279
+ defaultHiddenOnSaleSheet?: boolean;
280
+ prefillableFromPreviousLot?: boolean;
281
+ hidden?: boolean;
282
+ showInSellerDetailsPanel?: boolean;
283
+ displayTemplate?: string;
284
+ displayTemplateMultiValue?: string;
285
+ type: SupportedAttributeTypes;
286
+ requiredPreSale: boolean;
287
+ requiredToCheckout: boolean;
288
+ minValue?: number;
289
+ maxValue?: number;
290
+ minLength?: number;
291
+ maxLength?: number;
292
+ regexPattern?: string;
293
+ minDateExpression?: string;
294
+ maxDateExpression?: string;
295
+ allowedValues?: string[];
296
+ }
297
+
298
+ declare function Studio(apiKey: string, baseUrl?: string, defaultTimeout?: number, debug?: boolean): {
299
+ isDebugMode: boolean;
300
+ markets: {
301
+ get: (marketId: string) => Promise<Market>;
302
+ };
303
+ sales: {
304
+ get: (marketId: string, saleId: string) => Promise<Sale>;
305
+ list: (marketId: string, opts: {
306
+ start?: string | undefined;
307
+ end?: string | undefined;
308
+ }) => Promise<{
309
+ start: string;
310
+ end: string;
311
+ sales: Sale[];
312
+ }>;
313
+ update: (marketId: string, saleId: string, data: {
314
+ name?: string | undefined;
315
+ recurring?: "Weekly" | "Bi-weekly" | "Monthly" | null | undefined;
316
+ defaultProductCode?: string | undefined;
317
+ attributeDefaults?: Record<string, any> | undefined;
318
+ martEyeId?: string | null | undefined;
319
+ marteyeSettings?: {
320
+ description?: string | undefined;
321
+ image?: string | undefined;
322
+ logo?: string | undefined;
323
+ type: "LIVE" | "TIMED";
324
+ location?: string | null | undefined;
325
+ descriptionLines?: string[] | undefined;
326
+ descriptionLink?: string | undefined;
327
+ deposit?: number | undefined;
328
+ hidePrices?: boolean | undefined;
329
+ hideReplay?: boolean | undefined;
330
+ labels?: string[] | undefined;
331
+ tags?: string[] | undefined;
332
+ details?: {
333
+ markdownBase64: string;
334
+ title: string;
335
+ }[] | undefined;
336
+ cover?: string | undefined;
337
+ primaryColour?: string | undefined;
338
+ secondaryColour?: string | undefined;
339
+ foregroundColour?: string | undefined;
340
+ extensionTime?: number | undefined;
341
+ incrementLadder?: {
342
+ max: number;
343
+ increment: number;
344
+ }[] | undefined;
345
+ hideNav?: boolean | undefined;
346
+ signInOverrideLink?: string | undefined;
347
+ published?: boolean | undefined;
348
+ pin?: boolean | undefined;
349
+ cascade?: boolean | undefined;
350
+ reportEmail?: string | undefined;
351
+ } | null | undefined;
352
+ }) => Promise<Sale>;
353
+ };
354
+ lots: {
355
+ get: (marketId: string, saleId: string, lotId: string) => Promise<Lot>;
356
+ list: (marketId: string, saleId: string) => Promise<Lot[]>;
357
+ create: (marketId: string, saleId: string, data: {
358
+ index?: number | undefined;
359
+ lotNumber?: string | undefined;
360
+ group?: string | undefined;
361
+ productCode?: string | undefined;
362
+ sellerCustomerId?: string | undefined;
363
+ attributes?: Record<string, any> | undefined;
364
+ metadata?: Record<string, any> | undefined;
365
+ buyerCustomerId?: string | undefined;
366
+ unitPriceInCents?: number | undefined;
367
+ startedAt?: string | undefined;
368
+ endedAt?: string | undefined;
369
+ previousLotNumber?: string | undefined;
370
+ }) => Promise<Lot>;
371
+ update: (marketId: string, saleId: string, lotId: string, data: {
372
+ productCode?: string | undefined;
373
+ attributes?: Record<string, any> | undefined;
374
+ sellerCasual?: string | null | undefined;
375
+ sellerCustomerId?: string | null | undefined;
376
+ lotNumber?: string | null | undefined;
377
+ remarks?: string | undefined;
378
+ notes?: string | undefined;
379
+ unitOfSale?: "Per KG" | "Per Item" | "Per Lot" | "Per 1000KG" | undefined;
380
+ unitPriceInCents?: number | undefined;
381
+ buyerCasual?: string | null | undefined;
382
+ buyerCustomerId?: string | null | undefined;
383
+ startedAt?: string | null | undefined;
384
+ endedAt?: string | null | undefined;
385
+ saleStatus?: "Sold" | "Unsold" | "Rerun" | "Resold" | null | undefined;
386
+ metadata?: Record<string, any> | undefined;
387
+ }) => Promise<Lot>;
388
+ delete: (marketId: string, saleId: string, lotId: string) => Promise<unknown>;
389
+ };
390
+ lotitems: {
391
+ create: (marketId: string, saleId: string, lotId: string, data: {
392
+ attributes?: Record<string, any> | undefined;
393
+ notes?: {
394
+ text: string;
395
+ }[] | undefined;
396
+ metadata?: Record<string, any> | undefined;
397
+ }) => Promise<LotItem>;
398
+ update: (marketId: string, saleId: string, lotId: string, itemId: string, data: {
399
+ attributes?: Record<string, any> | undefined;
400
+ index?: number | undefined;
401
+ metadata?: Record<string, any> | undefined;
402
+ }) => Promise<LotItem>;
403
+ delete: (marketId: string, saleId: string, lotId: string, itemId: string) => Promise<unknown>;
404
+ };
405
+ webhooks: {
406
+ constructEvent: (bodyAsBuffer: Buffer, signature: string, endpointSecret: string) => Promise<any>;
407
+ };
408
+ actions: {
409
+ constructAction: (bodyAsBuffer: Buffer, signature: string, endpointSecret: string) => Promise<any>;
410
+ };
411
+ };
412
+
413
+ /**
414
+ * Headers used by Studio to identify webhook and action requests
415
+ */
416
+ declare const StudioHeaders: {
417
+ marketId: string;
418
+ webhookId: string;
419
+ action: string;
420
+ apiKey: string;
421
+ signature: string;
422
+ };
423
+ interface StudioManifest {
424
+ id: string;
425
+ name: string;
426
+ version: string;
427
+ description: string;
428
+ icon: string;
429
+ author: string;
430
+ actions: {
431
+ name: string;
432
+ url: string;
433
+ }[];
434
+ webhooks: {
435
+ url: string;
436
+ triggers: WebhookEventName[];
437
+ }[];
438
+ parameterConfig: {
439
+ id: string;
440
+ type: "string" | "number" | "boolean" | "string[]" | "password";
441
+ label: string;
442
+ description?: string;
443
+ required?: boolean;
444
+ defaultValue?: string | number | boolean | string[];
445
+ }[];
446
+ }
447
+ /***
448
+ * Creates an app manifest used to describe the app to Studio
449
+ *
450
+ * @param appConfig
451
+ * @returns
452
+ */
453
+ declare function createAppManifest(appConfig: {
454
+ id: string;
455
+ name: string;
456
+ version: string;
457
+ description: string;
458
+ icon: string;
459
+ author: string;
460
+ }): {
461
+ addWebhook: (url: string, triggers: WebhookEventName[]) => void;
462
+ addConfig: (config: {
463
+ id: string;
464
+ type: "string" | "number" | "boolean" | "string[]" | "password";
465
+ label: string;
466
+ description?: string;
467
+ required?: boolean;
468
+ defaultValue?: string | number | boolean | string[];
469
+ }) => void;
470
+ addAction: (action: {
471
+ name: string;
472
+ url: string;
473
+ }) => void;
474
+ readonly manifest: StudioManifest;
475
+ };
476
+
477
+ export { Studio, StudioHeaders, type StudioManifest, createAppManifest, Studio as default };