merchi_sdk_ts 1.0.69 → 1.0.71

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 CHANGED
@@ -1,22 +1,217 @@
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/`.
49
+
50
+ You can customize the API endpoint by setting:
51
+ - `process.env.MERCHI_BACKEND_URI` in your Node.js environment
52
+ - `window.merchiBackendUri` in the browser
53
+
54
+ ## Authentication
55
+
56
+ The SDK supports several authentication methods:
57
+
58
+ ```typescript
59
+ // Session token authentication (most common)
60
+ const merchi = new Merchi('your-session-token');
61
+
62
+ // Alternative methods
63
+ const merchi = new Merchi(
64
+ 'your-session-token', // Session token
65
+ 'your-client-token', // Client token
66
+ 'your-invoice-token', // Invoice token
67
+ 'your-cart-token' // Cart token
68
+ );
69
+
70
+ // The SDK will also attempt to read session_token from cookies
71
+ // if no token is provided
72
+ ```
73
+
74
+ ## Basic Usage
75
+
76
+ ### Entity Operations
77
+
78
+ Each entity supports standard CRUD operations:
79
+
80
+ ```typescript
81
+ // Fetch a single entity
82
+ Product.get(123).then(product => {
83
+ console.log(product);
84
+ });
85
+
86
+ // List entities with filtering
87
+ Product.list({
88
+ limit: 10,
89
+ offset: 0,
90
+ q: 'search-term'
91
+ }).then(response => {
92
+ console.log(response.items); // Array of products
93
+ console.log(response.metadata); // Metadata including count, limit, offset
94
+ });
95
+
96
+ // Create a new entity
97
+ const product = new Product();
98
+ product.name = 'New Product';
99
+ product.description = 'Product description';
100
+ product.create().then(newProduct => {
101
+ console.log(newProduct.id);
102
+ });
103
+
104
+ // Update an entity
105
+ product.name = 'Updated Product Name';
106
+ product.save().then(updatedProduct => {
107
+ console.log(updatedProduct);
108
+ });
109
+
110
+ // Delete an entity
111
+ product.delete().then(() => {
112
+ console.log('Product deleted');
113
+ });
114
+ ```
115
+
116
+ ### Embedding Related Entities
117
+
118
+ You can request related entities be included in responses:
119
+
120
+ ```typescript
121
+ Product.get(123, {
122
+ embed: {
123
+ domain: {},
124
+ variations: {
125
+ variationFields: {}
126
+ }
127
+ }
128
+ }).then(product => {
129
+ console.log(product.domain); // Domain entity is included
130
+ console.log(product.variations); // Variations are included
131
+ console.log(product.variations[0].variationFields); // Fields are included
132
+ });
133
+ ```
134
+
135
+ ## Available Entities
136
+
137
+ The SDK provides access to all Merchi entities, including but not limited to:
138
+
139
+ - User, Company, Domain
140
+ - Product, Category, Variation
141
+ - Cart, CartItem
142
+ - Job, Assignment, Invoice
143
+ - File, Draft, DraftTemplate
144
+ - Payment, Shipment
145
+ - And many more...
146
+
147
+ Each entity maps directly to the corresponding API endpoint and data structure.
148
+
149
+ ## Examples
150
+
151
+ ### Working with Products
152
+
153
+ ```typescript
154
+ import { Merchi, Product } from 'merchi_sdk_ts';
155
+
156
+ // Initialize Merchi
157
+ const merchi = new Merchi('your-session-token');
158
+
159
+ // Create a new product
160
+ const product = new Product();
161
+ product.name = 'Custom T-Shirt';
162
+ product.description = 'High-quality custom printed t-shirt';
163
+ product.public = true;
164
+
165
+ product.create().then(newProduct => {
166
+ console.log(`Created product with ID: ${newProduct.id}`);
167
+ });
168
+ ```
169
+
170
+ ### Managing a Cart
171
+
172
+ ```typescript
173
+ import { Merchi, Cart, CartItem } from 'merchi_sdk_ts';
174
+
175
+ // Initialize Merchi
176
+ const merchi = new Merchi('your-session-token');
177
+
178
+ // Create a new cart
179
+ const cart = new Cart();
180
+ cart.create().then(newCart => {
181
+ // Add an item to the cart
182
+ const cartItem = new CartItem();
183
+ cartItem.productId = 123;
184
+ cartItem.quantity = 2;
185
+ cartItem.cartId = newCart.id;
186
+
187
+ return cartItem.create();
188
+ }).then(newCartItem => {
189
+ console.log('Item added to cart!');
190
+ });
191
+ ```
192
+
193
+ ## TypeScript Support
194
+
195
+ This SDK is built with TypeScript and provides full type definitions for all entities and operations.
196
+
197
+ ```typescript
198
+ import { Product, EmbedDescriptor } from 'merchi_sdk_ts';
199
+
200
+ // TypeScript will provide intellisense for all properties
201
+ const product = new Product();
202
+ product.name = 'New Product';
203
+
204
+ // Type checking for embed options
205
+ const embedOptions: EmbedDescriptor = {
206
+ domain: {},
207
+ variations: {
208
+ variationFields: {}
209
+ }
210
+ };
211
+
212
+ Product.get(123, { embed: embedOptions });
213
+ ```
214
+
215
+ ## License
216
+
217
+ This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
@@ -116,6 +116,10 @@ var CartItem = /** @class */ (function (_super) {
116
116
  CartItem.property({ arrayType: 'DomainTag' }),
117
117
  __metadata("design:type", Array)
118
118
  ], CartItem.prototype, "tags", void 0);
119
+ __decorate([
120
+ CartItem.property({ arrayType: 'Draft' }),
121
+ __metadata("design:type", Array)
122
+ ], CartItem.prototype, "ownDrafts", void 0);
119
123
  return CartItem;
120
124
  }(Entity));
121
125
  export { CartItem };
@@ -550,6 +550,10 @@ var Product = /** @class */ (function (_super) {
550
550
  Product.property({ arrayType: 'DraftTemplate' }),
551
551
  __metadata("design:type", Array)
552
552
  ], Product.prototype, "draftTemplates", void 0);
553
+ __decorate([
554
+ Product.property({ arrayType: 'DraftPreview' }),
555
+ __metadata("design:type", Array)
556
+ ], Product.prototype, "draftPreviews", void 0);
553
557
  return Product;
554
558
  }(Entity));
555
559
  export { Product };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "merchi_sdk_ts",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:merchisdk/merchi_sdk_ts.git",
@@ -6,6 +6,7 @@ import { RequestOptions } from '../request.js';
6
6
  import { Variation } from './variation.js';
7
7
  import { VariationsGroup } from './variations_group.js';
8
8
  import { DomainTag } from './domain_tag.js';
9
+ import { Draft } from './draft.js';
9
10
 
10
11
  export class CartItem extends Entity {
11
12
  protected static resourceName = 'cart_items';
@@ -57,6 +58,9 @@ export class CartItem extends Entity {
57
58
  @CartItem.property({arrayType: 'DomainTag'})
58
59
  public tags?: DomainTag[];
59
60
 
61
+ @CartItem.property({arrayType: 'Draft'})
62
+ public ownDrafts?: Draft[];
63
+
60
64
  public requiresShipment = () => {
61
65
  if (this.product === undefined) {
62
66
  throw 'product is undefined, did you forget to embed it?';
@@ -7,6 +7,7 @@ import { CountryTax } from './country_tax.js';
7
7
  import { DiscountGroup } from './discount_group.js';
8
8
  import { Domain } from './domain.js';
9
9
  import { DomainTag } from './domain_tag.js';
10
+ import { DraftPreview } from './draft_preview.js';
10
11
  import { DraftTemplate } from './draft_template.js';
11
12
  import { Entity } from '../entity.js';
12
13
  import { MerchiFile } from './file.js';
@@ -310,6 +311,9 @@ export class Product extends Entity {
310
311
  @Product.property({arrayType: 'DraftTemplate'})
311
312
  public draftTemplates?: DraftTemplate[];
312
313
 
314
+ @Product.property({arrayType: 'DraftPreview'})
315
+ public draftPreviews?: DraftPreview[];
316
+
313
317
  public duplicate = () => {
314
318
  /* create a clone of this product on the backend, returning it. */
315
319
  const constructor = this.constructor as typeof Product;