@attlaz/client 1.131.0 → 1.132.0

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.
@@ -13,4 +13,11 @@ export declare class CatalogProductEndpoint extends Endpoint {
13
13
  getByCatalog(catalogId: CatalogId | string, pagination?: CursorPagination | null): Promise<CollectionResult<CatalogProduct>>;
14
14
  /** The product with this catalog identifier, or null. */
15
15
  getByIdentifier(catalogId: CatalogId | string, identifier: string): Promise<CatalogProduct | null>;
16
+ /**
17
+ * Assign a vendor product to the catalog. The API refuses an identifier the catalog already has
18
+ * ("already exist"), so an import that lost the answer to an earlier create reads it back instead.
19
+ */
20
+ create(product: CatalogProduct): Promise<CatalogProduct>;
21
+ /** Update what the catalog itself holds about the product — today only the cost price. */
22
+ update(product: CatalogProduct): Promise<void>;
16
23
  }
@@ -22,4 +22,25 @@ export class CatalogProductEndpoint extends Endpoint {
22
22
  const products = result.getData();
23
23
  return products.length > 0 ? products[0] : null;
24
24
  }
25
+ /**
26
+ * Assign a vendor product to the catalog. The API refuses an identifier the catalog already has
27
+ * ("already exist"), so an import that lost the answer to an earlier create reads it back instead.
28
+ */
29
+ async create(product) {
30
+ if (product.vendorProductId === null) {
31
+ throw new Error('Unable to create catalog product `' + product.identifier + '`: it has no vendor product');
32
+ }
33
+ const result = await this.requestObject(path('/catalogs/:catalogId/products', { catalogId: product.catalogId.toString() }), { _formatted: true, identifier: product.identifier, vendor_product: product.vendorProductId, cost_price: product.costPrice }, CatalogProduct.parse, 'POST');
34
+ const created = result.getData();
35
+ if (created === null) {
36
+ throw new Error('Unable to create catalog product `' + product.identifier + '`: the API returned nothing');
37
+ }
38
+ return created;
39
+ }
40
+ /** Update what the catalog itself holds about the product — today only the cost price. */
41
+ async update(product) {
42
+ // Already in wire shape, as in VendorProductEndpoint.update.
43
+ const operations = Object.assign([{ op: 'add', path: 'cost_price', value: product.costPrice }], { _formatted: true });
44
+ await this.requestObject(path('/catalogs/:catalogId/products/:catalogProductId', { catalogId: product.catalogId.toString(), catalogProductId: product.id }), operations, (raw) => raw, 'PATCH');
45
+ }
25
46
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.130.0";
1
+ export declare const VERSION = "1.132.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.130.0";
1
+ export const VERSION = "1.132.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attlaz/client",
3
- "version": "1.131.0",
3
+ "version": "1.132.0",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",