@dotdev/apparel21-sdk
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -5,2 +5,11 @@ # Changelog | ||
### [0.0.23](https://gitlab.com/dotdevv/packages/apparel21-sdk/compare/v0.0.22...v0.0.23) (2021-08-26) | ||
### Features | ||
- add colour reference support for api versions prior to 2021.2 ([3b20089](https://gitlab.com/dotdevv/packages/apparel21-sdk/commit/3b20089716629a65a59aa60edbcc389152c34e7d)) | ||
- store client version as a proper semver with comparison methods ([3b87d6c](https://gitlab.com/dotdevv/packages/apparel21-sdk/commit/3b87d6c8cfff0927b51015b39e0d801a572d4016)) | ||
- update client version param to be the actual api version ([cb0d86f](https://gitlab.com/dotdevv/packages/apparel21-sdk/commit/cb0d86f4b7991c309c1ee737d7c32b88397db773)) | ||
- update product module to use an abstract, for access to client params ([a37037e](https://gitlab.com/dotdevv/packages/apparel21-sdk/commit/a37037e7b3f880ebf112e1d8a35bdfee8cdfb7a8)) | ||
### [0.0.22](https://gitlab.com/dotdevv/packages/apparel21-sdk/compare/v0.0.21...v0.0.22) (2021-08-26) | ||
@@ -7,0 +16,0 @@ |
@@ -0,1 +1,2 @@ | ||
import semver from 'semver'; | ||
import { AP21Config, RequestFunction } from './common/types'; | ||
@@ -21,3 +22,3 @@ import { Products } from './modules/Products'; | ||
countryCode: string; | ||
version: string; | ||
version: semver.SemVer; | ||
products: Products; | ||
@@ -60,2 +61,7 @@ persons: Persons; | ||
}>; | ||
coerceVersion(version: string): semver.SemVer; | ||
versionGte(version: string): boolean; | ||
versionGt(version: string): boolean; | ||
versionLte(version: string): boolean; | ||
versionLt(version: string): boolean; | ||
} |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.AP21 = void 0; | ||
const semver_1 = __importDefault(require("semver")); | ||
const request_1 = require("./utils/request"); | ||
@@ -49,3 +50,3 @@ const xmlParser_1 = require("./utils/xmlParser"); | ||
'Content-type': 'text/xml', | ||
...(uri !== '/' && { Accept: this.version }), | ||
...(uri !== '/' && { Accept: 'version_4.0' }), | ||
}; | ||
@@ -101,4 +102,5 @@ try { | ||
this.countryCode = countryCode; | ||
this.version = version || 'version_4.0'; | ||
this.products = new Products_1.Products({ request: this.request }); | ||
this.version = this.coerceVersion(version); | ||
this.products = new Products_1.Products(this); | ||
// @todo update these modules to use the new abstact module | ||
this.persons = new Persons_1.Persons({ request: this.request }); | ||
@@ -113,4 +115,28 @@ this.freestock = new FreeStock_1.FreeStock({ request: this.request }); | ||
} | ||
// coerced an AP21 API version into a valid semver for comparisons, e.g. 2021.2 = 2021.2.0 | ||
coerceVersion(version) { | ||
const coercedVersion = semver_1.default.coerce(version); | ||
if (!coercedVersion) { | ||
throw new Error(`apparel21 api version ${version} could not be coerced into a valid semantic version`); | ||
} | ||
return coercedVersion; | ||
} | ||
// return true if the current client version if greater than or equal to the given version | ||
versionGte(version) { | ||
return semver_1.default.gte(this.version, this.coerceVersion(version)); | ||
} | ||
// return true if the current client version if greater than the given version | ||
versionGt(version) { | ||
return semver_1.default.gt(this.version, this.coerceVersion(version)); | ||
} | ||
// return true if the current client version if less than or equal to the given version | ||
versionLte(version) { | ||
return semver_1.default.lte(this.version, this.coerceVersion(version)); | ||
} | ||
// return true if the current client version if less than the given version | ||
versionLt(version) { | ||
return semver_1.default.lt(this.version, this.coerceVersion(version)); | ||
} | ||
} | ||
exports.AP21 = AP21; | ||
//# sourceMappingURL=AP21.js.map |
@@ -1,13 +0,5 @@ | ||
import { Product, ProductSimple, ProductNote, ProductColourNote, RequestFunction } from '../common/types'; | ||
export declare class Products { | ||
private request; | ||
import { Module } from './Module'; | ||
import { Product, ProductSimple, ProductNote, ProductColourNote } from '../common/types'; | ||
export declare class Products extends Module { | ||
/** | ||
* Creates new Products instance to interface with AP21 Products endpoints | ||
* | ||
* @property {RequestFunction} request: Request function to send requests to AP21 | ||
*/ | ||
constructor({ request }: { | ||
request: RequestFunction; | ||
}); | ||
/** | ||
* Return a list of all products based on the Product Reference Id. The query parameter | ||
@@ -14,0 +6,0 @@ * is plugged in from the reference tree as described in Navigation tree. This is a detailed view of products. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Products = void 0; | ||
const Module_1 = require("./Module"); | ||
const products_1 = require("../utils/products"); | ||
class Products { | ||
/** | ||
* Creates new Products instance to interface with AP21 Products endpoints | ||
* | ||
* @property {RequestFunction} request: Request function to send requests to AP21 | ||
*/ | ||
constructor({ request }) { | ||
class Products extends Module_1.Module { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
@@ -77,2 +74,17 @@ * Return a list of all products based on the Product Reference Id. The query parameter | ||
Product.notes = notes; | ||
// api versions prior to 2021.2 do not include colour references in the product payload, even when | ||
// ClrRefs is set to true, in this case, we need to individually request references for each of | ||
// the colours, which is really slow but unavoidable | ||
if (this.client.versionLt('2021.2')) { | ||
Product.Clrs[0].Clr = await Promise.all(Product.Clrs[0].Clr.map(async (colour) => { | ||
const colourId = parseInt(colour.Id[0]); | ||
const { ProductColourReferences } = await this.request({ | ||
uri: `/ProductColourReferences/${colourId}`, | ||
}); | ||
return { | ||
...colour, | ||
References: ProductColourReferences?.References ?? [], | ||
}; | ||
})); | ||
} | ||
return products_1.formatProducts([Product])[0]; | ||
@@ -117,3 +129,2 @@ }; | ||
}; | ||
this.request = request; | ||
} | ||
@@ -120,0 +131,0 @@ } |
{ | ||
"name": "@dotdev/apparel21-sdk", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"license": "UNLICENSED", | ||
@@ -43,2 +43,3 @@ "description": "Apparel21 Interface Library", | ||
"currency.js": "^2.0.4", | ||
"semver": "^6.3.0", | ||
"ssl-root-cas": "^1.3.1", | ||
@@ -56,2 +57,3 @@ "xml2js": "^0.4.23", | ||
"@types/node": "^13.13.9", | ||
"@types/semver": "^7.3.8", | ||
"@types/xml2js": "^0.4.5", | ||
@@ -58,0 +60,0 @@ "dotenv": "^8.2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
208024
102
3320
6
18
+ Addedsemver@^6.3.0
+ Addedsemver@6.3.1(transitive)