@scayle/storefront-core 7.69.3 → 8.0.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/dist/cache/cached.cjs +1 -1
  3. package/dist/cache/cached.d.ts +1 -1
  4. package/dist/cache/cached.mjs +1 -1
  5. package/dist/constants/basket.cjs +15 -1
  6. package/dist/constants/basket.d.ts +16 -0
  7. package/dist/constants/basket.mjs +14 -0
  8. package/dist/errors/errorResponse.d.ts +1 -1
  9. package/dist/errors/index.cjs +0 -22
  10. package/dist/errors/index.d.ts +0 -2
  11. package/dist/errors/index.mjs +0 -2
  12. package/dist/helpers/productHelpers.cjs +1 -35
  13. package/dist/helpers/productHelpers.d.ts +0 -8
  14. package/dist/helpers/productHelpers.mjs +0 -27
  15. package/dist/rpc/methods/basket/basket.cjs +33 -9
  16. package/dist/rpc/methods/basket/basket.d.ts +20 -4
  17. package/dist/rpc/methods/basket/basket.mjs +32 -14
  18. package/dist/rpc/methods/cbd.d.ts +1 -1
  19. package/dist/rpc/methods/checkout/checkout.cjs +1 -1
  20. package/dist/rpc/methods/checkout/checkout.mjs +1 -1
  21. package/dist/rpc/methods/checkout/order.d.ts +1 -1
  22. package/dist/rpc/methods/oauth/idp.cjs +1 -2
  23. package/dist/rpc/methods/oauth/idp.d.ts +1 -1
  24. package/dist/rpc/methods/oauth/idp.mjs +1 -2
  25. package/dist/rpc/methods/search.cjs +1 -32
  26. package/dist/rpc/methods/search.d.ts +0 -10
  27. package/dist/rpc/methods/search.mjs +0 -22
  28. package/dist/rpc/methods/user.cjs +3 -15
  29. package/dist/rpc/methods/user.d.ts +1 -1
  30. package/dist/rpc/methods/user.mjs +2 -15
  31. package/dist/server.cjs +1 -24
  32. package/dist/server.d.ts +0 -3
  33. package/dist/server.mjs +0 -2
  34. package/dist/types/api/auth.d.ts +0 -9
  35. package/dist/types/api/context.d.ts +0 -12
  36. package/dist/types/user.d.ts +0 -4
  37. package/dist/utils/basket.cjs +14 -0
  38. package/dist/utils/basket.d.ts +2 -0
  39. package/dist/utils/basket.mjs +12 -0
  40. package/dist/utils/index.cjs +11 -0
  41. package/dist/utils/index.d.ts +1 -0
  42. package/dist/utils/index.mjs +1 -0
  43. package/dist/utils/keys.cjs +3 -3
  44. package/dist/utils/keys.mjs +3 -3
  45. package/package.json +6 -9
  46. package/dist/bapi/init.cjs +0 -19
  47. package/dist/bapi/init.d.ts +0 -15
  48. package/dist/bapi/init.mjs +0 -12
  49. package/dist/cache/providers/redis.cjs +0 -94
  50. package/dist/cache/providers/redis.d.ts +0 -28
  51. package/dist/cache/providers/redis.mjs +0 -86
  52. package/dist/errors/BAPIError.cjs +0 -18
  53. package/dist/errors/BAPIError.d.ts +0 -8
  54. package/dist/errors/BAPIError.mjs +0 -11
  55. package/dist/errors/baseError.cjs +0 -17
  56. package/dist/errors/baseError.d.ts +0 -5
  57. package/dist/errors/baseError.mjs +0 -10
  58. package/dist/utils/compression.cjs +0 -25
  59. package/dist/utils/compression.d.ts +0 -2
  60. package/dist/utils/compression.mjs +0 -17
@@ -1,15 +0,0 @@
1
- import { StorefrontAPIClient } from '@scayle/storefront-api';
2
- interface StorefrontAPIConfig {
3
- host: string;
4
- shopId: number;
5
- authentication: 'token';
6
- token: string;
7
- additionalHeaders: HeadersInit;
8
- }
9
- /**
10
- * Create a new Storefront API Client.
11
- *
12
- * @deprecated
13
- */
14
- export declare const init: (config: StorefrontAPIConfig) => StorefrontAPIClient;
15
- export {};
@@ -1,12 +0,0 @@
1
- import { StorefrontAPIClient } from "@scayle/storefront-api";
2
- export const init = (config) => {
3
- return new StorefrontAPIClient({
4
- host: config.host,
5
- shopId: config.shopId,
6
- auth: {
7
- type: config.authentication,
8
- token: config.token
9
- },
10
- additionalHeaders: config.additionalHeaders
11
- });
12
- };
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createClient = exports.RedisCache = void 0;
7
- var _redis = require("redis");
8
- var _compression = require("../../utils/compression.cjs");
9
- const connections = {};
10
- const createClient = async (options, log) => {
11
- log = log.space("redis.createClient");
12
- const connectionIndex = [options.host, options.database].join("_");
13
- let client;
14
- if (connections[connectionIndex] !== void 0) {
15
- client = connections[connectionIndex];
16
- } else {
17
- client = connections[connectionIndex] = (0, _redis.createClient)({
18
- ...options,
19
- ...(options && "username" in options && {
20
- username: options.username
21
- }),
22
- socket: {
23
- host: options.host,
24
- port: options.port,
25
- ...(options.sslTransit === true ? {
26
- tls: true,
27
- checkServerIdentity: () => void 0
28
- } : {
29
- tls: false
30
- })
31
- }
32
- });
33
- client.on("error", error => {
34
- log.error("Redis connection error", error);
35
- });
36
- await client.connect();
37
- }
38
- return client;
39
- };
40
- exports.createClient = createClient;
41
- class RedisCache {
42
- client;
43
- prefix;
44
- constructor(client, prefix = "") {
45
- this.client = client;
46
- this.prefix = prefix;
47
- }
48
- async get(key) {
49
- const value = await this.client.get(this.getKey(key));
50
- if (value === null) {
51
- return null;
52
- }
53
- return this.deserialize(value);
54
- }
55
- async has(key) {
56
- return (await this.client.exists(this.getKey(key))) !== 0;
57
- }
58
- async purgeTags(tags) {
59
- await Promise.all(tags.map(tag => this.purgeTag(tag)));
60
- }
61
- async purgeTag(tag) {
62
- const keys = await this.client.sMembers(this.getKey(`tag:${tag}`));
63
- await this.client.del(keys);
64
- await this.client.del(this.getKey(`tag:${tag}`));
65
- }
66
- async purgeKeys(keys) {
67
- await this.client.del(keys);
68
- }
69
- async purgeAll() {
70
- await this.client.flushDb();
71
- }
72
- async set(key, value, ttl, tags = []) {
73
- const _value = await this.serialize(value);
74
- await this.client.set(this.getKey(key), _value, {
75
- EX: ttl
76
- });
77
- await Promise.all(tags.map(tag => this.addKeyToTag(tag, this.getKey(key))));
78
- }
79
- async addKeyToTag(tag, key) {
80
- await this.client.sAdd(this.getKey(`tag:${tag}`), key);
81
- }
82
- getKey(key) {
83
- return [this.prefix, key].join(":");
84
- }
85
- async deserialize(value) {
86
- const data = await (0, _compression.decompress)(value);
87
- return JSON.parse(data);
88
- }
89
- async serialize(value) {
90
- const data = JSON.stringify(value);
91
- return await (0, _compression.compress)(data);
92
- }
93
- }
94
- exports.RedisCache = RedisCache;
@@ -1,28 +0,0 @@
1
- import { type RedisClientType } from 'redis';
2
- import type { Log } from '../../utils';
3
- import type { Cache as CacheInterface } from '../../cache/cache';
4
- export interface RedisOptions {
5
- username?: string;
6
- password?: string;
7
- host?: string;
8
- port?: number;
9
- database?: number;
10
- sslTransit?: boolean;
11
- }
12
- export declare const createClient: (options: RedisOptions, log: Log) => Promise<RedisClientType>;
13
- export declare class RedisCache implements CacheInterface {
14
- client: RedisClientType;
15
- prefix: string;
16
- constructor(client: RedisClientType, prefix?: string);
17
- get(key: string): Promise<any>;
18
- has(key: string): Promise<boolean>;
19
- purgeTags(tags: string[]): Promise<void>;
20
- purgeTag(tag: string): Promise<void>;
21
- purgeKeys(keys: string[]): Promise<void>;
22
- purgeAll(): Promise<void>;
23
- set(key: string, value: any, ttl: number, tags?: string[]): Promise<void>;
24
- private addKeyToTag;
25
- private getKey;
26
- private deserialize;
27
- private serialize;
28
- }
@@ -1,86 +0,0 @@
1
- import { createClient as createRedisClient } from "redis";
2
- import { compress, decompress } from "../../utils/compression.mjs";
3
- const connections = {};
4
- export const createClient = async (options, log) => {
5
- log = log.space("redis.createClient");
6
- const connectionIndex = [options.host, options.database].join("_");
7
- let client;
8
- if (connections[connectionIndex] !== void 0) {
9
- client = connections[connectionIndex];
10
- } else {
11
- client = connections[connectionIndex] = createRedisClient({
12
- ...options,
13
- ...options && "username" in options && { username: options.username },
14
- socket: {
15
- host: options.host,
16
- port: options.port,
17
- ...options.sslTransit === true ? {
18
- tls: true,
19
- checkServerIdentity: () => void 0
20
- } : {
21
- tls: false
22
- }
23
- }
24
- });
25
- client.on("error", (error) => {
26
- log.error("Redis connection error", error);
27
- });
28
- await client.connect();
29
- }
30
- return client;
31
- };
32
- export class RedisCache {
33
- client;
34
- prefix;
35
- constructor(client, prefix = "") {
36
- this.client = client;
37
- this.prefix = prefix;
38
- }
39
- async get(key) {
40
- const value = await this.client.get(this.getKey(key));
41
- if (value === null) {
42
- return null;
43
- }
44
- return this.deserialize(value);
45
- }
46
- async has(key) {
47
- return await this.client.exists(this.getKey(key)) !== 0;
48
- }
49
- async purgeTags(tags) {
50
- await Promise.all(tags.map((tag) => this.purgeTag(tag)));
51
- }
52
- async purgeTag(tag) {
53
- const keys = await this.client.sMembers(this.getKey(`tag:${tag}`));
54
- await this.client.del(keys);
55
- await this.client.del(this.getKey(`tag:${tag}`));
56
- }
57
- async purgeKeys(keys) {
58
- await this.client.del(keys);
59
- }
60
- async purgeAll() {
61
- await this.client.flushDb();
62
- }
63
- async set(key, value, ttl, tags = []) {
64
- const _value = await this.serialize(value);
65
- await this.client.set(this.getKey(key), _value, {
66
- EX: ttl
67
- });
68
- await Promise.all(
69
- tags.map((tag) => this.addKeyToTag(tag, this.getKey(key)))
70
- );
71
- }
72
- async addKeyToTag(tag, key) {
73
- await this.client.sAdd(this.getKey(`tag:${tag}`), key);
74
- }
75
- getKey(key) {
76
- return [this.prefix, key].join(":");
77
- }
78
- async deserialize(value) {
79
- const data = await decompress(value);
80
- return JSON.parse(data);
81
- }
82
- async serialize(value) {
83
- const data = JSON.stringify(value);
84
- return await compress(data);
85
- }
86
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BAPIFetchError = exports.BAPIError = void 0;
7
- var _storefrontApi = require("@scayle/storefront-api");
8
- var _constants = require("../constants/index.cjs");
9
- var _baseError = require("./baseError.cjs");
10
- class BAPIError extends _baseError.BaseError {
11
- url;
12
- constructor(name = _constants.HttpStatusMessage.INTERNAL_SERVER_ERROR, statusCode = _constants.HttpStatusCode.INTERNAL_SERVER_ERROR, description = "BAPI Error", url) {
13
- super(name, statusCode, description);
14
- this.url = url;
15
- }
16
- }
17
- exports.BAPIError = BAPIError;
18
- const BAPIFetchError = exports.BAPIFetchError = _storefrontApi.FetchError;
@@ -1,8 +0,0 @@
1
- import { FetchError } from '@scayle/storefront-api';
2
- import { HttpStatusCode, HttpStatusMessage } from '../constants';
3
- import { BaseError } from './baseError';
4
- export declare class BAPIError extends BaseError {
5
- url?: string;
6
- constructor(name?: HttpStatusMessage | string, statusCode?: HttpStatusCode, description?: string, url?: string);
7
- }
8
- export declare const BAPIFetchError: typeof FetchError;
@@ -1,11 +0,0 @@
1
- import { FetchError } from "@scayle/storefront-api";
2
- import { HttpStatusCode, HttpStatusMessage } from "../constants/index.mjs";
3
- import { BaseError } from "./baseError.mjs";
4
- export class BAPIError extends BaseError {
5
- url;
6
- constructor(name = HttpStatusMessage.INTERNAL_SERVER_ERROR, statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR, description = "BAPI Error", url) {
7
- super(name, statusCode, description);
8
- this.url = url;
9
- }
10
- }
11
- export const BAPIFetchError = FetchError;
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BaseError = void 0;
7
- class BaseError extends Error {
8
- statusCode;
9
- constructor(name, statusCode, description) {
10
- super(description);
11
- Object.setPrototypeOf(this, new.target.prototype);
12
- this.name = name;
13
- this.statusCode = statusCode;
14
- Error.captureStackTrace(this);
15
- }
16
- }
17
- exports.BaseError = BaseError;
@@ -1,5 +0,0 @@
1
- import type { HttpStatusCode } from '../constants';
2
- export declare class BaseError extends Error {
3
- statusCode: HttpStatusCode;
4
- constructor(name: string, statusCode: HttpStatusCode, description: string);
5
- }
@@ -1,10 +0,0 @@
1
- export class BaseError extends Error {
2
- statusCode;
3
- constructor(name, statusCode, description) {
4
- super(description);
5
- Object.setPrototypeOf(this, new.target.prototype);
6
- this.name = name;
7
- this.statusCode = statusCode;
8
- Error.captureStackTrace(this);
9
- }
10
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.decompress = exports.compress = void 0;
7
- var _util = require("util");
8
- var _zlib = require("zlib");
9
- var _nodeBuffer = require("node:buffer");
10
- const asyncDeflate = (0, _util.promisify)(_zlib.gzip);
11
- const asyncUnzip = (0, _util.promisify)(_zlib.gunzip);
12
- const compress = async data => {
13
- const buffer = await asyncDeflate(data);
14
- return buffer.toString("base64");
15
- };
16
- exports.compress = compress;
17
- const decompress = async data => {
18
- try {
19
- const buffer = _nodeBuffer.Buffer.from(data, "base64");
20
- return (await asyncUnzip(buffer)).toString();
21
- } catch {
22
- return data;
23
- }
24
- };
25
- exports.decompress = decompress;
@@ -1,2 +0,0 @@
1
- export declare const compress: (data: string) => Promise<string>;
2
- export declare const decompress: (data: string) => Promise<string>;
@@ -1,17 +0,0 @@
1
- import { promisify } from "util";
2
- import { gunzip, gzip } from "zlib";
3
- import { Buffer } from "node:buffer";
4
- const asyncDeflate = promisify(gzip);
5
- const asyncUnzip = promisify(gunzip);
6
- export const compress = async (data) => {
7
- const buffer = await asyncDeflate(data);
8
- return buffer.toString("base64");
9
- };
10
- export const decompress = async (data) => {
11
- try {
12
- const buffer = Buffer.from(data, "base64");
13
- return (await asyncUnzip(buffer)).toString();
14
- } catch {
15
- return data;
16
- }
17
- };