@scayle/storefront-core 8.1.5 → 8.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 8.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [Performance] Remove the 'autobinding' of the methods on the `Cached` instance. Instead the `execute` method only is bound when constructing the `RpcContext`. This simplifies the code and improves the performance of the `bootstrap` function. This change is internal to `storefront-core` and the API of `RpcContext` is unchanged.
8
+
3
9
  ## 8.1.5
4
10
 
5
11
  ### Patch Changes
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MINUTE = exports.Cached = void 0;
7
- var _autobind = require("../helpers/autobind.cjs");
8
7
  var _utils = require("../utils/index.cjs");
9
8
  var _hash = require("../utils/hash.cjs");
10
9
  var _constants = require("../constants/index.cjs");
@@ -24,7 +23,6 @@ class Cached {
24
23
  this.log = log.space("cached.init");
25
24
  this.prefix = prefix;
26
25
  this.enabled = enabled;
27
- (0, _autobind.autobind)(this);
28
26
  }
29
27
  get isCacheEnabled() {
30
28
  return this.enabled;
@@ -1,4 +1,3 @@
1
- import { autobind } from "../helpers/autobind.mjs";
2
1
  import { timeout } from "../utils/index.mjs";
3
2
  import { sha256 } from "../utils/hash.mjs";
4
3
  import { CACHE_TIMEOUT } from "../constants/index.mjs";
@@ -18,7 +17,6 @@ export class Cached {
18
17
  this.log = log.space("cached.init");
19
18
  this.prefix = prefix;
20
19
  this.enabled = enabled;
21
- autobind(this);
22
20
  }
23
21
  get isCacheEnabled() {
24
22
  return this.enabled;
@@ -36,17 +36,6 @@ Object.keys(_attributeHelpers).forEach(function (key) {
36
36
  }
37
37
  });
38
38
  });
39
- var _autobind = require("./autobind.cjs");
40
- Object.keys(_autobind).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _autobind[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _autobind[key];
47
- }
48
- });
49
- });
50
39
  var _basketHelpers = require("./basketHelpers.cjs");
51
40
  Object.keys(_basketHelpers).forEach(function (key) {
52
41
  if (key === "default" || key === "__esModule") return;
@@ -1,7 +1,6 @@
1
1
  export * from './advancedAttributeHelpers';
2
2
  export * from './arrayHelpers';
3
3
  export * from './attributeHelpers';
4
- export * from './autobind';
5
4
  export * from './basketHelpers';
6
5
  export * from './categoryHelper';
7
6
  export * from './filterHelper';
@@ -1,7 +1,6 @@
1
1
  export * from "./advancedAttributeHelpers.mjs";
2
2
  export * from "./arrayHelpers.mjs";
3
3
  export * from "./attributeHelpers.mjs";
4
- export * from "./autobind.mjs";
5
4
  export * from "./basketHelpers.mjs";
6
5
  export * from "./categoryHelper.mjs";
7
6
  export * from "./filterHelper.mjs";
@@ -37,7 +37,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
37
37
  carrier,
38
38
  basketId: context.basketKey,
39
39
  campaignKey: context.campaignKey
40
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.1.5"}`).setProtectedHeader({
40
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.2.0"}`).setProtectedHeader({
41
41
  alg: "HS256",
42
42
  typ: "JWT"
43
43
  }).sign(secret);
@@ -35,7 +35,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
35
35
  carrier,
36
36
  basketId: context.basketKey,
37
37
  campaignKey: context.campaignKey
38
- }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.1.5"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
38
+ }).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.2.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
39
39
  return {
40
40
  accessToken: refreshedAccessToken,
41
41
  checkoutJwt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "8.1.5",
3
+ "version": "8.2.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.autobind = autobind;
7
- const getAllProperties = obj => {
8
- const properties = /* @__PURE__ */new Set();
9
- if (!obj) {
10
- return properties;
11
- }
12
- do {
13
- for (const key of Reflect.ownKeys(obj)) {
14
- properties.add([obj, key]);
15
- }
16
- } while ((obj = Reflect.getPrototypeOf(obj)) && obj !== Object.prototype);
17
- return properties;
18
- };
19
- function autobind(self, {
20
- include,
21
- exclude
22
- } = {}) {
23
- const filter = key => {
24
- const match = pattern => typeof pattern === "string" ? key === pattern : pattern.test(key);
25
- if (include) {
26
- return include.some(match);
27
- }
28
- if (exclude) {
29
- return !exclude.some(match);
30
- }
31
- return true;
32
- };
33
- for (const it of getAllProperties(self.constructor.prototype)) {
34
- const [object, key] = it;
35
- if (key === "constructor" || !filter(key)) {
36
- continue;
37
- }
38
- const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
39
- if (descriptor && typeof descriptor.value === "function") {
40
- self[key] = self[key].bind(self);
41
- }
42
- }
43
- return self;
44
- }
@@ -1,39 +0,0 @@
1
- type Options = Partial<{
2
- readonly include: ReadonlyArray<string | RegExp>;
3
- readonly exclude: ReadonlyArray<string | RegExp>;
4
- }>;
5
- /**
6
- * Automatically bind methods to their class instance.
7
- * @param self - An object with methods to bind.
8
- * @example
9
- ```
10
- import { autobind } from '@scayle/storefront-core'
11
-
12
- class Unicorn {
13
- constructor(name) {
14
- this.name = name;
15
- autobind(this);
16
- }
17
-
18
- message() {
19
- return `${this.name} is awesome!`;
20
- }
21
- }
22
-
23
- const unicorn = new Unicorn('Rainbow');
24
-
25
- // Grab the method off the class instance
26
- const message = unicorn.message;
27
-
28
- // Still bound to the class instance
29
- message();
30
- // => 'Rainbow is awesome!'
31
-
32
- // Without `autobind(this)`, the above would have resulted in
33
-
34
- message();
35
- //=> Error: Cannot read property 'name' of undefined
36
- ```
37
- */
38
- export declare function autobind<SelfType extends Record<string, any>>(self: SelfType, { include, exclude }?: Options): SelfType;
39
- export {};
@@ -1,35 +0,0 @@
1
- const getAllProperties = (obj) => {
2
- const properties = /* @__PURE__ */ new Set();
3
- if (!obj) {
4
- return properties;
5
- }
6
- do {
7
- for (const key of Reflect.ownKeys(obj)) {
8
- properties.add([obj, key]);
9
- }
10
- } while ((obj = Reflect.getPrototypeOf(obj)) && obj !== Object.prototype);
11
- return properties;
12
- };
13
- export function autobind(self, { include, exclude } = {}) {
14
- const filter = (key) => {
15
- const match = (pattern) => typeof pattern === "string" ? key === pattern : pattern.test(key);
16
- if (include) {
17
- return include.some(match);
18
- }
19
- if (exclude) {
20
- return !exclude.some(match);
21
- }
22
- return true;
23
- };
24
- for (const it of getAllProperties(self.constructor.prototype)) {
25
- const [object, key] = it;
26
- if (key === "constructor" || !filter(key)) {
27
- continue;
28
- }
29
- const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
30
- if (descriptor && typeof descriptor.value === "function") {
31
- self[key] = self[key].bind(self);
32
- }
33
- }
34
- return self;
35
- }