merchi_sdk_ts 1.1.0 → 1.2.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.
Files changed (76) hide show
  1. package/README.md +230 -8
  2. package/dist/constants/discount_types.js +2 -0
  3. package/dist/constants/job_types.js +2 -1
  4. package/dist/constants/product_types.js +1 -0
  5. package/dist/entities/assignment.js +4 -0
  6. package/dist/entities/automatic_payment_relationship.js +4 -0
  7. package/dist/entities/cart.js +4 -0
  8. package/dist/entities/cart_item.js +8 -0
  9. package/dist/entities/category.js +16 -0
  10. package/dist/entities/discount.js +12 -0
  11. package/dist/entities/discount_group.js +20 -0
  12. package/dist/entities/domain.js +16 -0
  13. package/dist/entities/draft.js +4 -37
  14. package/dist/entities/draft.test.js +0 -13
  15. package/dist/entities/draft_preview.js +74 -0
  16. package/dist/entities/draft_preview.test.js +36 -0
  17. package/dist/entities/draft_preview_layer.js +54 -0
  18. package/dist/entities/draft_preview_layer.test.js +6 -0
  19. package/dist/entities/draft_template.js +16 -0
  20. package/dist/entities/file.js +0 -4
  21. package/dist/entities/inventory.js +4 -0
  22. package/dist/entities/inventory_group.js +69 -0
  23. package/dist/entities/inventory_group.test.js +6 -0
  24. package/dist/entities/invoice.js +4 -0
  25. package/dist/entities/item.js +19 -4
  26. package/dist/entities/job.js +25 -1
  27. package/dist/entities/product.js +16 -0
  28. package/dist/entities/product.test.js +19 -3
  29. package/dist/entities/user.js +8 -0
  30. package/dist/entities/variation_field.js +13 -0
  31. package/dist/entities/variation_fields_option.js +4 -0
  32. package/dist/entity.js +19 -0
  33. package/dist/index.js +1 -2
  34. package/dist/merchi.js +37 -5
  35. package/dist/request.js +32 -17
  36. package/dist/request.test.js +4 -4
  37. package/dist/util/query_string.js +8 -6
  38. package/package.json +1 -1
  39. package/src/constants/discount_types.ts +2 -0
  40. package/src/constants/job_types.ts +2 -1
  41. package/src/constants/product_types.ts +1 -0
  42. package/src/entities/assignment.ts +3 -0
  43. package/src/entities/automatic_payment_relationship.ts +3 -0
  44. package/src/entities/cart.ts +4 -0
  45. package/src/entities/cart_item.ts +8 -0
  46. package/src/entities/category.ts +13 -0
  47. package/src/entities/discount.ts +9 -0
  48. package/src/entities/discount_group.ts +15 -0
  49. package/src/entities/domain.ts +13 -0
  50. package/src/entities/draft.test.ts +0 -14
  51. package/src/entities/draft.ts +4 -16
  52. package/src/entities/draft_preview.test.ts +42 -0
  53. package/src/entities/draft_preview.ts +37 -0
  54. package/src/entities/draft_preview_layer.test.ts +7 -0
  55. package/src/entities/draft_preview_layer.ts +21 -0
  56. package/src/entities/draft_template.ts +15 -0
  57. package/src/entities/file.ts +0 -4
  58. package/src/entities/inventory.ts +4 -0
  59. package/src/entities/inventory_group.test.ts +7 -0
  60. package/src/entities/inventory_group.ts +36 -0
  61. package/src/entities/invoice.ts +3 -0
  62. package/src/entities/item.ts +18 -3
  63. package/src/entities/job.ts +20 -1
  64. package/src/entities/product.test.ts +24 -4
  65. package/src/entities/product.ts +14 -0
  66. package/src/entities/user.ts +6 -0
  67. package/src/entities/variation_field.ts +10 -0
  68. package/src/entities/variation_fields_option.ts +3 -0
  69. package/src/entity.ts +28 -0
  70. package/src/index.ts +0 -2
  71. package/src/merchi.ts +46 -6
  72. package/src/request.test.ts +4 -4
  73. package/src/request.ts +41 -14
  74. package/src/util/query_string.ts +8 -6
  75. package/src/entities/backup.test.ts +0 -7
  76. package/src/entities/backup.ts +0 -14
package/README.md CHANGED
@@ -1,22 +1,244 @@
1
- # merchi_cart
2
- Merchi's cart
1
+ # Merchi TypeScript SDK
3
2
 
3
+ A TypeScript SDK for interacting with the Merchi API.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/merchi_sdk_ts.svg)](https://www.npmjs.com/package/merchi_sdk_ts)
6
+ [![License: GPL-3.0](https://img.shields.io/badge/License-GPL%203.0-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
4
7
 
5
8
  ## Table of Contents
6
9
 
7
10
  - [Installation](#installation)
8
- - [Usage](#usage)
11
+ - [Quick Start](#quick-start)
12
+ - [Configuration](#configuration)
13
+ - [Authentication](#authentication)
14
+ - [Basic Usage](#basic-usage)
15
+ - [Entity Operations](#entity-operations)
16
+ - [Embedding Related Entities](#embedding-related-entities)
17
+ - [Available Entities](#available-entities)
18
+ - [Examples](#examples)
19
+ - [TypeScript Support](#typescript-support)
20
+ - [License](#license)
9
21
 
10
22
  ## Installation
11
23
 
12
24
  ```bash
25
+ # Using npm
13
26
  npm install merchi_sdk_ts
14
27
 
15
- or
16
-
28
+ # Using yarn
17
29
  yarn add merchi_sdk_ts
18
30
  ```
19
31
 
20
- ### Usage
21
- The sdk by default is set up to make request to the Merchi production server 'https://api.merchi.co/'.
22
- You can set the API URI by setting `process.env.MERCHI_BACKEND_URI` in your environment or `window.merchiBackendUri` on the client.
32
+ ## Quick Start
33
+
34
+ ```typescript
35
+ import { Merchi, Product } from 'merchi_sdk_ts';
36
+
37
+ // Initialize the SDK
38
+ const merchi = new Merchi();
39
+
40
+ // Fetch a product by ID
41
+ Product.get(123).then(product => {
42
+ console.log(product.name);
43
+ });
44
+ ```
45
+
46
+ ## Configuration
47
+
48
+ The SDK by default is set up to make requests to the Merchi production server at `https://api.merchi.co/v6/`.
49
+
50
+ You can customize the API endpoint by:
51
+
52
+ 1. Setting `process.env.MERCHI_BACKEND_URI` in your Node.js environment.
53
+ 2. Setting `window.merchiBackendUri` in the browser.
54
+ 3. Passing the `backendUri` directly to the `Merchi` constructor (highest precedence).
55
+
56
+ The SDK will look for these in the order of 3, 2, 1, and finally use the default production URL if none are found.
57
+ The API version (e.g., `/v6/`) will be appended automatically if not included in your custom URI, assuming the URI ends with the base domain (e.g. `https://custom.merchi.co`). If your custom URI already includes a path (e.g., `https://custom.merchi.co/api/`), ensure it ends with a trailing slash for the version to be appended correctly (e.g., `https://custom.merchi.co/api/v6/`).
58
+
59
+ **Example: Passing `backendUri` to the constructor**
60
+
61
+ ```typescript
62
+ import { Merchi } from 'merchi_sdk_ts';
63
+
64
+ // Initialize the SDK with a custom backend URI
65
+ // This URI should be the base path to your Merchi backend instance.
66
+ // The API version (e.g., /v6/) will be appended.
67
+ const customBackend = 'https://my-custom-merchi-instance.com/';
68
+ const merchi = new Merchi(undefined, undefined, undefined, undefined, customBackend);
69
+
70
+ // If your custom URI already includes a specific path and you want to control the full endpoint:
71
+ const specificCustomBackend = 'https://my-custom-merchi-instance.com/api/custom_version/';
72
+ const merchiSpecific = new Merchi(undefined, undefined, undefined, undefined, specificCustomBackend);
73
+
74
+ // Now, all API calls made using this 'merchi' or 'merchiSpecific' instance
75
+ // will be directed to your specified backend.
76
+ // For example:
77
+ // merchi.Product.get(1) will call https://my-custom-merchi-instance.com/v6/products/1/
78
+ // merchiSpecific.Product.get(1) will call https://my-custom-merchi-instance.com/api/custom_version/products/1/
79
+ ```
80
+
81
+ ## Authentication
82
+
83
+ The SDK supports several authentication methods:
84
+
85
+ ```typescript
86
+ // Session token authentication (most common)
87
+ const merchi = new Merchi('your-session-token');
88
+
89
+ // Alternative methods
90
+ const merchi = new Merchi(
91
+ 'your-session-token', // Session token
92
+ 'your-client-token', // Client token
93
+ 'your-invoice-token', // Invoice token
94
+ 'your-cart-token' // Cart token
95
+ );
96
+
97
+ // The SDK will also attempt to read session_token from cookies
98
+ // if no token is provided
99
+ ```
100
+
101
+ ## Basic Usage
102
+
103
+ ### Entity Operations
104
+
105
+ Each entity supports standard CRUD operations:
106
+
107
+ ```typescript
108
+ // Fetch a single entity
109
+ Product.get(123).then(product => {
110
+ console.log(product);
111
+ });
112
+
113
+ // List entities with filtering
114
+ Product.list({
115
+ limit: 10,
116
+ offset: 0,
117
+ q: 'search-term'
118
+ }).then(response => {
119
+ console.log(response.items); // Array of products
120
+ console.log(response.metadata); // Metadata including count, limit, offset
121
+ });
122
+
123
+ // Create a new entity
124
+ const product = new Product();
125
+ product.name = 'New Product';
126
+ product.description = 'Product description';
127
+ product.create().then(newProduct => {
128
+ console.log(newProduct.id);
129
+ });
130
+
131
+ // Update an entity
132
+ product.name = 'Updated Product Name';
133
+ product.save().then(updatedProduct => {
134
+ console.log(updatedProduct);
135
+ });
136
+
137
+ // Delete an entity
138
+ product.delete().then(() => {
139
+ console.log('Product deleted');
140
+ });
141
+ ```
142
+
143
+ ### Embedding Related Entities
144
+
145
+ You can request related entities be included in responses:
146
+
147
+ ```typescript
148
+ Product.get(123, {
149
+ embed: {
150
+ domain: {},
151
+ variations: {
152
+ variationFields: {}
153
+ }
154
+ }
155
+ }).then(product => {
156
+ console.log(product.domain); // Domain entity is included
157
+ console.log(product.variations); // Variations are included
158
+ console.log(product.variations[0].variationFields); // Fields are included
159
+ });
160
+ ```
161
+
162
+ ## Available Entities
163
+
164
+ The SDK provides access to all Merchi entities, including but not limited to:
165
+
166
+ - User, Company, Domain
167
+ - Product, Category, Variation
168
+ - Cart, CartItem
169
+ - Job, Assignment, Invoice
170
+ - File, Draft, DraftTemplate
171
+ - Payment, Shipment
172
+ - And many more...
173
+
174
+ Each entity maps directly to the corresponding API endpoint and data structure.
175
+
176
+ ## Examples
177
+
178
+ ### Working with Products
179
+
180
+ ```typescript
181
+ import { Merchi, Product } from 'merchi_sdk_ts';
182
+
183
+ // Initialize Merchi
184
+ const merchi = new Merchi('your-session-token');
185
+
186
+ // Create a new product
187
+ const product = new Product();
188
+ product.name = 'Custom T-Shirt';
189
+ product.description = 'High-quality custom printed t-shirt';
190
+ product.public = true;
191
+
192
+ product.create().then(newProduct => {
193
+ console.log(`Created product with ID: ${newProduct.id}`);
194
+ });
195
+ ```
196
+
197
+ ### Managing a Cart
198
+
199
+ ```typescript
200
+ import { Merchi, Cart, CartItem } from 'merchi_sdk_ts';
201
+
202
+ // Initialize Merchi
203
+ const merchi = new Merchi('your-session-token');
204
+
205
+ // Create a new cart
206
+ const cart = new Cart();
207
+ cart.create().then(newCart => {
208
+ // Add an item to the cart
209
+ const cartItem = new CartItem();
210
+ cartItem.productId = 123;
211
+ cartItem.quantity = 2;
212
+ cartItem.cartId = newCart.id;
213
+
214
+ return cartItem.create();
215
+ }).then(newCartItem => {
216
+ console.log('Item added to cart!');
217
+ });
218
+ ```
219
+
220
+ ## TypeScript Support
221
+
222
+ This SDK is built with TypeScript and provides full type definitions for all entities and operations.
223
+
224
+ ```typescript
225
+ import { Product, EmbedDescriptor } from 'merchi_sdk_ts';
226
+
227
+ // TypeScript will provide intellisense for all properties
228
+ const product = new Product();
229
+ product.name = 'New Product';
230
+
231
+ // Type checking for embed options
232
+ const embedOptions: EmbedDescriptor = {
233
+ domain: {},
234
+ variations: {
235
+ variationFields: {}
236
+ }
237
+ };
238
+
239
+ Product.get(123, { embed: embedOptions });
240
+ ```
241
+
242
+ ## License
243
+
244
+ This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
@@ -1,4 +1,6 @@
1
1
  export var DiscountType;
2
2
  (function (DiscountType) {
3
3
  DiscountType[DiscountType["VOLUMETRIC"] = 0] = "VOLUMETRIC";
4
+ DiscountType[DiscountType["CODE"] = 1] = "CODE";
5
+ DiscountType[DiscountType["FREE_SHIPPING"] = 2] = "FREE_SHIPPING";
4
6
  })(DiscountType || (DiscountType = {}));
@@ -12,5 +12,6 @@ export var JobType;
12
12
  JobType[JobType["SUPPLIER_FULFILLMENT_RESELL"] = 9] = "SUPPLIER_FULFILLMENT_RESELL";
13
13
  JobType[JobType["SUPPLIER_FULFILLMENT_INVENTORY"] = 10] = "SUPPLIER_FULFILLMENT_INVENTORY";
14
14
  JobType[JobType["SUPPLIER_FULFILLMENT_INVENTORY_GROUP_BUY"] = 11] = "SUPPLIER_FULFILLMENT_INVENTORY_GROUP_BUY";
15
- JobType[JobType["SUPPLY_CHAIN_CREATION"] = 12] = "SUPPLY_CHAIN_CREATION"; // USED TO ID JOBS WHICH ARE TO CREATE A NEW SUPPLY CHAIN
15
+ JobType[JobType["SUPPLY_CHAIN_CREATION"] = 12] = "SUPPLY_CHAIN_CREATION";
16
+ JobType[JobType["LEAD"] = 13] = "LEAD"; // USED WITH LEAD FORMS
16
17
  })(JobType || (JobType = {}));
@@ -23,4 +23,5 @@ export var ProductType;
23
23
  ProductType[ProductType["SELLER_FILE_DOWNLOAD"] = 20] = "SELLER_FILE_DOWNLOAD";
24
24
  ProductType[ProductType["SUPPLIER_MOD_SUPPLY_CHAIN_REQUEST"] = 21] = "SUPPLIER_MOD_SUPPLY_CHAIN_REQUEST";
25
25
  ProductType[ProductType["SUPPLIER_SUPPLY_CHAIN_REQUEST"] = 22] = "SUPPLIER_SUPPLY_CHAIN_REQUEST";
26
+ ProductType[ProductType["LEAD_FORM"] = 23] = "LEAD_FORM";
26
27
  })(ProductType || (ProductType = {}));
@@ -102,6 +102,10 @@ var Assignment = /** @class */ (function (_super) {
102
102
  Assignment.property({ type: Quote }),
103
103
  __metadata("design:type", Object)
104
104
  ], Assignment.prototype, "quote", void 0);
105
+ __decorate([
106
+ Assignment.property(),
107
+ __metadata("design:type", Number)
108
+ ], Assignment.prototype, "quoteTotalCost", void 0);
105
109
  __decorate([
106
110
  Assignment.property({ arrayType: 'ProductionComment' }),
107
111
  __metadata("design:type", Array)
@@ -44,6 +44,10 @@ var AutomaticPaymentRelationship = /** @class */ (function (_super) {
44
44
  AutomaticPaymentRelationship.property(),
45
45
  __metadata("design:type", Date)
46
46
  ], AutomaticPaymentRelationship.prototype, "creationDate", void 0);
47
+ __decorate([
48
+ AutomaticPaymentRelationship.property(),
49
+ __metadata("design:type", Boolean)
50
+ ], AutomaticPaymentRelationship.prototype, "allowPostPayment", void 0);
47
51
  __decorate([
48
52
  AutomaticPaymentRelationship.property({ type: Company }),
49
53
  __metadata("design:type", Company)
@@ -144,6 +144,10 @@ var Cart = /** @class */ (function (_super) {
144
144
  Cart.property({ type: Address }),
145
145
  __metadata("design:type", Object)
146
146
  ], Cart.prototype, "receiverAddress", void 0);
147
+ __decorate([
148
+ Cart.property({ arrayType: 'Item' }),
149
+ __metadata("design:type", Array)
150
+ ], Cart.prototype, "discountItems", void 0);
147
151
  __decorate([
148
152
  Cart.property({ arrayType: 'CartItem' }),
149
153
  __metadata("design:type", Array)
@@ -112,6 +112,14 @@ var CartItem = /** @class */ (function (_super) {
112
112
  CartItem.property({ arrayType: 'Variation' }),
113
113
  __metadata("design:type", Array)
114
114
  ], CartItem.prototype, "variations", void 0);
115
+ __decorate([
116
+ CartItem.property({ arrayType: 'DomainTag' }),
117
+ __metadata("design:type", Array)
118
+ ], CartItem.prototype, "tags", void 0);
119
+ __decorate([
120
+ CartItem.property({ arrayType: 'Draft' }),
121
+ __metadata("design:type", Array)
122
+ ], CartItem.prototype, "ownDrafts", void 0);
115
123
  return CartItem;
116
124
  }(Entity));
117
125
  export { CartItem };
@@ -56,6 +56,10 @@ var Category = /** @class */ (function (_super) {
56
56
  Category.property(),
57
57
  __metadata("design:type", Boolean)
58
58
  ], Category.prototype, "showPublicSupplierResell", void 0);
59
+ __decorate([
60
+ Category.property(),
61
+ __metadata("design:type", Number)
62
+ ], Category.prototype, "descendant", void 0);
59
63
  __decorate([
60
64
  Category.property(),
61
65
  __metadata("design:type", Domain)
@@ -68,6 +72,18 @@ var Category = /** @class */ (function (_super) {
68
72
  Category.property({ arrayType: 'User' }),
69
73
  __metadata("design:type", Array)
70
74
  ], Category.prototype, "users", void 0);
75
+ __decorate([
76
+ Category.property({ arrayType: 'Category' }),
77
+ __metadata("design:type", Array)
78
+ ], Category.prototype, "subcategories", void 0);
79
+ __decorate([
80
+ Category.property({ type: 'Category' }),
81
+ __metadata("design:type", Category)
82
+ ], Category.prototype, "parent", void 0);
83
+ __decorate([
84
+ Category.property({ type: 'MerchiFile' }),
85
+ __metadata("design:type", Object)
86
+ ], Category.prototype, "image", void 0);
71
87
  return Category;
72
88
  }(Entity));
73
89
  export { Category };
@@ -59,6 +59,18 @@ var Discount = /** @class */ (function (_super) {
59
59
  Discount.property(),
60
60
  __metadata("design:type", Number)
61
61
  ], Discount.prototype, "amount", void 0);
62
+ __decorate([
63
+ Discount.property(),
64
+ __metadata("design:type", Number)
65
+ ], Discount.prototype, "usageLimit", void 0);
66
+ __decorate([
67
+ Discount.property(),
68
+ __metadata("design:type", Boolean)
69
+ ], Discount.prototype, "isPercentage", void 0);
70
+ __decorate([
71
+ Discount.property(),
72
+ __metadata("design:type", String)
73
+ ], Discount.prototype, "code", void 0);
62
74
  __decorate([
63
75
  Discount.property({ type: DiscountGroup }),
64
76
  __metadata("design:type", Object)
@@ -35,10 +35,22 @@ var DiscountGroup = /** @class */ (function (_super) {
35
35
  DiscountGroup.property({ type: Date }),
36
36
  __metadata("design:type", Object)
37
37
  ], DiscountGroup.prototype, "archived", void 0);
38
+ __decorate([
39
+ DiscountGroup.property({ type: Date }),
40
+ __metadata("design:type", Object)
41
+ ], DiscountGroup.prototype, "created", void 0);
38
42
  __decorate([
39
43
  DiscountGroup.property(),
40
44
  __metadata("design:type", Number)
41
45
  ], DiscountGroup.prototype, "id", void 0);
46
+ __decorate([
47
+ DiscountGroup.property({ type: Date }),
48
+ __metadata("design:type", Object)
49
+ ], DiscountGroup.prototype, "dateStart", void 0);
50
+ __decorate([
51
+ DiscountGroup.property({ type: Date }),
52
+ __metadata("design:type", Object)
53
+ ], DiscountGroup.prototype, "dateEnd", void 0);
42
54
  __decorate([
43
55
  DiscountGroup.property(),
44
56
  __metadata("design:type", Number)
@@ -51,10 +63,18 @@ var DiscountGroup = /** @class */ (function (_super) {
51
63
  DiscountGroup.property(),
52
64
  __metadata("design:type", String)
53
65
  ], DiscountGroup.prototype, "name", void 0);
66
+ __decorate([
67
+ DiscountGroup.property(),
68
+ __metadata("design:type", Boolean)
69
+ ], DiscountGroup.prototype, "groupRestricted", void 0);
54
70
  __decorate([
55
71
  DiscountGroup.property({ type: 'Product' }),
56
72
  __metadata("design:type", Object)
57
73
  ], DiscountGroup.prototype, "product", void 0);
74
+ __decorate([
75
+ DiscountGroup.property({ type: 'Domain' }),
76
+ __metadata("design:type", Object)
77
+ ], DiscountGroup.prototype, "domain", void 0);
58
78
  return DiscountGroup;
59
79
  }(Entity));
60
80
  export { DiscountGroup };
@@ -85,6 +85,10 @@ var Domain = /** @class */ (function (_super) {
85
85
  Domain.property(),
86
86
  __metadata("design:type", Boolean)
87
87
  ], Domain.prototype, "isMaster", void 0);
88
+ __decorate([
89
+ Domain.property(),
90
+ __metadata("design:type", Boolean)
91
+ ], Domain.prototype, "deploymentOnline", void 0);
88
92
  __decorate([
89
93
  Domain.property(),
90
94
  __metadata("design:type", Boolean)
@@ -173,6 +177,10 @@ var Domain = /** @class */ (function (_super) {
173
177
  Domain.property({ type: String }),
174
178
  __metadata("design:type", Object)
175
179
  ], Domain.prototype, "webflowApiKey", void 0);
180
+ __decorate([
181
+ Domain.property({ type: String }),
182
+ __metadata("design:type", String)
183
+ ], Domain.prototype, "telegramChatId", void 0);
176
184
  __decorate([
177
185
  Domain.property({ type: String }),
178
186
  __metadata("design:type", Object)
@@ -193,6 +201,10 @@ var Domain = /** @class */ (function (_super) {
193
201
  Domain.property({ type: String }),
194
202
  __metadata("design:type", String)
195
203
  ], Domain.prototype, "unltdAiApiSecretKey", void 0);
204
+ __decorate([
205
+ Domain.property({ type: String }),
206
+ __metadata("design:type", String)
207
+ ], Domain.prototype, "scalablePressApiKey", void 0);
196
208
  __decorate([
197
209
  Domain.property({ type: String }),
198
210
  __metadata("design:type", Object)
@@ -253,6 +265,10 @@ var Domain = /** @class */ (function (_super) {
253
265
  Domain.property({ type: MerchiFile }),
254
266
  __metadata("design:type", Object)
255
267
  ], Domain.prototype, "favicon", void 0);
268
+ __decorate([
269
+ Domain.property({ arrayType: 'ShipmentMethod' }),
270
+ __metadata("design:type", Array)
271
+ ], Domain.prototype, "shipmentMethods", void 0);
256
272
  __decorate([
257
273
  Domain.property(),
258
274
  __metadata("design:type", Theme)
@@ -22,17 +22,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
22
22
  var __metadata = (this && this.__metadata) || function (k, v) {
23
23
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
24
  };
25
- var __values = (this && this.__values) || function(o) {
26
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
27
- if (m) return m.call(o);
28
- if (o && typeof o.length === "number") return {
29
- next: function () {
30
- if (o && i >= o.length) o = void 0;
31
- return { value: o && o[i++], done: !o };
32
- }
33
- };
34
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
35
- };
36
25
  import { Entity } from '../entity.js';
37
26
  import { Job } from './job.js';
38
27
  import { User } from './user.js';
@@ -40,32 +29,6 @@ var Draft = /** @class */ (function (_super) {
40
29
  __extends(Draft, _super);
41
30
  function Draft() {
42
31
  var _this = _super !== null && _super.apply(this, arguments) || this;
43
- _this.wereChangesRequested = function () {
44
- var e_1, _a;
45
- /* true if any comment is/was a change request comment. */
46
- if (_this.comments === undefined) {
47
- throw 'comments is undefined. did you forget to embed it?';
48
- }
49
- try {
50
- for (var _b = __values(_this.comments), _c = _b.next(); !_c.done; _c = _b.next()) {
51
- var comment = _c.value;
52
- if (comment.changeRequest === undefined) {
53
- throw 'changeRequest is undefined.';
54
- }
55
- if (comment.changeRequest) {
56
- return true;
57
- }
58
- }
59
- }
60
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
61
- finally {
62
- try {
63
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
64
- }
65
- finally { if (e_1) throw e_1.error; }
66
- }
67
- return false;
68
- };
69
32
  _this.commentsYoungestToEldest = function () {
70
33
  if (_this.comments === undefined) {
71
34
  throw 'comments is undefined. did you forget to embed it?';
@@ -118,6 +81,10 @@ var Draft = /** @class */ (function (_super) {
118
81
  Draft.property({ arrayType: 'DraftComment' }),
119
82
  __metadata("design:type", Array)
120
83
  ], Draft.prototype, "comments", void 0);
84
+ __decorate([
85
+ Draft.property({ arrayType: 'DraftTemplate' }),
86
+ __metadata("design:type", Array)
87
+ ], Draft.prototype, "draftTemplates", void 0);
121
88
  __decorate([
122
89
  Draft.property(),
123
90
  __metadata("design:type", Number)
@@ -4,19 +4,6 @@ test('can make Draft', function () {
4
4
  var draft = new merchi.Draft();
5
5
  expect(draft).toBeTruthy();
6
6
  });
7
- test('wereChangesRequested', function () {
8
- var merchi = new Merchi();
9
- var draft = new merchi.Draft();
10
- expect(draft.wereChangesRequested).toThrow();
11
- draft.comments = [];
12
- expect(draft.wereChangesRequested()).toBe(false);
13
- draft.comments = [new merchi.DraftComment()];
14
- expect(draft.wereChangesRequested).toThrow();
15
- draft.comments[0].changeRequest = false;
16
- expect(draft.wereChangesRequested()).toBe(false);
17
- draft.comments[0].changeRequest = true;
18
- expect(draft.wereChangesRequested()).toBe(true);
19
- });
20
7
  test('commentsYoungestToEldest', function () {
21
8
  var merchi = new Merchi();
22
9
  var draft = new merchi.Draft();
@@ -0,0 +1,74 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
21
+ };
22
+ var __metadata = (this && this.__metadata) || function (k, v) {
23
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
+ };
25
+ import { Entity } from '../entity.js';
26
+ import { MerchiFile } from './file.js';
27
+ import { Product } from './product.js';
28
+ var DraftPreview = /** @class */ (function (_super) {
29
+ __extends(DraftPreview, _super);
30
+ function DraftPreview() {
31
+ return _super !== null && _super.apply(this, arguments) || this;
32
+ }
33
+ DraftPreview.resourceName = 'draft_previews';
34
+ DraftPreview.singularName = 'draftPreview';
35
+ DraftPreview.pluralName = 'draftPreviews';
36
+ __decorate([
37
+ DraftPreview.property(),
38
+ __metadata("design:type", Number)
39
+ ], DraftPreview.prototype, "id", void 0);
40
+ __decorate([
41
+ DraftPreview.property({ type: MerchiFile }),
42
+ __metadata("design:type", MerchiFile)
43
+ ], DraftPreview.prototype, "file", void 0);
44
+ __decorate([
45
+ DraftPreview.property({ type: Product }),
46
+ __metadata("design:type", Product)
47
+ ], DraftPreview.prototype, "product", void 0);
48
+ __decorate([
49
+ DraftPreview.property({ type: String }),
50
+ __metadata("design:type", Object)
51
+ ], DraftPreview.prototype, "description", void 0);
52
+ __decorate([
53
+ DraftPreview.property({ type: String }),
54
+ __metadata("design:type", Object)
55
+ ], DraftPreview.prototype, "name", void 0);
56
+ __decorate([
57
+ DraftPreview.property({ type: Date }),
58
+ __metadata("design:type", Object)
59
+ ], DraftPreview.prototype, "date", void 0);
60
+ __decorate([
61
+ DraftPreview.property(),
62
+ __metadata("design:type", Number)
63
+ ], DraftPreview.prototype, "height", void 0);
64
+ __decorate([
65
+ DraftPreview.property(),
66
+ __metadata("design:type", Number)
67
+ ], DraftPreview.prototype, "width", void 0);
68
+ __decorate([
69
+ DraftPreview.property({ arrayType: 'DraftPreviewLayer' }),
70
+ __metadata("design:type", Array)
71
+ ], DraftPreview.prototype, "draftPreviewLayers", void 0);
72
+ return DraftPreview;
73
+ }(Entity));
74
+ export { DraftPreview };
@@ -0,0 +1,36 @@
1
+ import { setup, mockFetch } from '../test_util.js';
2
+ import { DraftPreview } from './draft_preview.js';
3
+ setup();
4
+ test('can create draft preview from json', function () {
5
+ var mockData = {
6
+ draft_preview: {
7
+ id: 1,
8
+ name: 'Test Preview',
9
+ description: 'Test Description',
10
+ date: '2024-03-26T10:00:00Z',
11
+ height: 800,
12
+ width: 600
13
+ }
14
+ };
15
+ var draftPreview = new DraftPreview();
16
+ draftPreview.fromJson(mockData.draft_preview);
17
+ expect(draftPreview.id).toBe(1);
18
+ expect(draftPreview.name).toBe('Test Preview');
19
+ expect(draftPreview.description).toBe('Test Description');
20
+ expect(draftPreview.date).toBeInstanceOf(Date);
21
+ expect(draftPreview.height).toBe(800);
22
+ expect(draftPreview.width).toBe(600);
23
+ });
24
+ test('can fetch draft preview from server', function () {
25
+ var mockData = {
26
+ draft_preview: {
27
+ id: 1,
28
+ name: 'Test Preview'
29
+ }
30
+ };
31
+ mockFetch(true, mockData, 200);
32
+ return DraftPreview.get(1).then(function (draftPreview) {
33
+ expect(draftPreview.id).toBe(1);
34
+ expect(draftPreview.name).toBe('Test Preview');
35
+ });
36
+ });