@scayle/storefront-core 8.7.0 → 8.8.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 +12 -0
- package/dist/api/customer.d.ts +73 -0
- package/dist/api/customer.mjs +59 -0
- package/dist/api/oauth.d.ts +62 -12
- package/dist/api/oauth.mjs +51 -15
- package/dist/cache/cache.d.ts +47 -0
- package/dist/cache/cached.d.ts +93 -0
- package/dist/cache/cached.mjs +62 -0
- package/dist/cache/providers/unstorage.d.ts +64 -0
- package/dist/cache/providers/unstorage.mjs +64 -0
- package/dist/constants/cache.d.ts +4 -0
- package/dist/constants/hash.d.ts +4 -0
- package/dist/constants/hash.mjs +1 -0
- package/dist/constants/httpStatus.d.ts +12 -2
- package/dist/constants/httpStatus.mjs +2 -2
- package/dist/constants/product.d.ts +3 -0
- package/dist/constants/promotion.d.ts +6 -0
- package/dist/constants/sorting.d.ts +6 -0
- package/dist/constants/withParameters.d.ts +28 -0
- package/dist/errors/errorResponse.d.ts +37 -0
- package/dist/errors/errorResponse.mjs +14 -0
- package/dist/helpers/filterHelper.mjs +1 -1
- package/dist/index.d.ts +48 -0
- package/dist/rpc/methods/basket/basket.mjs +9 -4
- package/dist/rpc/methods/campaign.d.ts +13 -0
- package/dist/rpc/methods/campaign.mjs +23 -0
- package/dist/rpc/methods/checkout/checkout.mjs +4 -2
- package/dist/rpc/methods/index.d.ts +1 -0
- package/dist/rpc/methods/index.mjs +1 -0
- package/dist/rpc/methods/products.d.ts +4 -4
- package/dist/rpc/methods/products.mjs +19 -7
- package/dist/rpc/methods/variants.d.ts +1 -1
- package/dist/rpc/methods/variants.mjs +4 -1
- package/dist/rpc/methods/wishlist.mjs +7 -3
- package/dist/types/api/context.d.ts +3 -0
- package/dist/utils/basket.d.ts +23 -0
- package/dist/utils/campaign.d.ts +23 -0
- package/dist/utils/campaign.mjs +17 -0
- package/dist/utils/fetch.d.ts +21 -2
- package/dist/utils/hash.d.ts +67 -0
- package/dist/utils/hash.mjs +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +1 -0
- package/dist/utils/keys.d.ts +38 -0
- package/dist/utils/log.d.ts +77 -8
- package/dist/utils/log.mjs +61 -6
- package/dist/utils/response.d.ts +8 -3
- package/dist/utils/sapi.d.ts +10 -2
- package/dist/utils/timeout.d.ts +18 -0
- package/dist/utils/user.d.ts +22 -0
- package/dist/utils/user.mjs +5 -2
- package/package.json +1 -1
package/dist/cache/cached.d.ts
CHANGED
|
@@ -1,25 +1,118 @@
|
|
|
1
1
|
import type { Log } from '../utils';
|
|
2
2
|
import type { Cache as CacheInterface } from './cache';
|
|
3
|
+
/**
|
|
4
|
+
* Number of seconds in a minute, used for calculating cache TTL.
|
|
5
|
+
*/
|
|
3
6
|
export declare const MINUTE = 60;
|
|
7
|
+
/**
|
|
8
|
+
* Options for configuring the caching behavior.
|
|
9
|
+
*/
|
|
4
10
|
export type CacheOptions = Partial<{
|
|
11
|
+
/**
|
|
12
|
+
* The TTL (Time-To-Live) of the cache entry in seconds.
|
|
13
|
+
* Defaults to one hour if not set.
|
|
14
|
+
*/
|
|
5
15
|
ttl: number;
|
|
16
|
+
/**
|
|
17
|
+
* Custom cache key. If not provided, one will be generated automatically.
|
|
18
|
+
*/
|
|
6
19
|
cacheKey: string;
|
|
20
|
+
/**
|
|
21
|
+
* Prefix for the generated cache key. Defaults to the function name.
|
|
22
|
+
*/
|
|
7
23
|
cacheKeyPrefix: string;
|
|
24
|
+
/**
|
|
25
|
+
* Timeout in milliseconds for cache operations (get and set).
|
|
26
|
+
*/
|
|
8
27
|
timeout: number;
|
|
9
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Type representing an asynchronous function.
|
|
31
|
+
*
|
|
32
|
+
* @template TArgs The type of the function's arguments.
|
|
33
|
+
* @template TResult The return type of the function.
|
|
34
|
+
*/
|
|
10
35
|
type Fn<TArgs extends unknown[], TResult> = (...args: TArgs) => Promise<TResult>;
|
|
36
|
+
/**
|
|
37
|
+
* A class for caching the results of asynchronous function calls.
|
|
38
|
+
*/
|
|
11
39
|
export declare class Cached {
|
|
12
40
|
private cache;
|
|
13
41
|
private log;
|
|
14
42
|
private prefix;
|
|
15
43
|
private enabled;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new Cached instance.
|
|
46
|
+
*
|
|
47
|
+
* @param cache The cache implementation to use.
|
|
48
|
+
* @param log The logger instance.
|
|
49
|
+
* @param prefix An optional prefix for cache keys.
|
|
50
|
+
* @param enabled Whether caching is enabled.
|
|
51
|
+
*
|
|
52
|
+
* @throws {Error} If the cache is not initialized.
|
|
53
|
+
*/
|
|
16
54
|
constructor(cache: CacheInterface, log: Log, prefix: string | number | undefined, enabled: boolean);
|
|
55
|
+
/**
|
|
56
|
+
* Whether caching is enabled.
|
|
57
|
+
*/
|
|
17
58
|
get isCacheEnabled(): boolean | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Executes a function and caches its result.
|
|
61
|
+
*
|
|
62
|
+
* @param fn The asynchronous function to execute.
|
|
63
|
+
* @param options Optional cache options.
|
|
64
|
+
*
|
|
65
|
+
* @returns A wrapped function that handles caching.
|
|
66
|
+
*
|
|
67
|
+
* @template TArgs The type of the function's arguments.
|
|
68
|
+
* @template TResult The return type of the function.
|
|
69
|
+
*/
|
|
18
70
|
execute<TArgs extends unknown[], TResult>(fn: Fn<TArgs, TResult>, options?: CacheOptions): Awaited<Fn<TArgs, TResult>>;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves a cached value from the cache.
|
|
73
|
+
*
|
|
74
|
+
* @param cacheKey The key of the cached value.
|
|
75
|
+
* @param options Optional cache options.
|
|
76
|
+
*
|
|
77
|
+
* @returns A promise that resolves with the cached value or undefined if not found or caching is disabled.
|
|
78
|
+
*
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
19
81
|
private getCacheValue;
|
|
82
|
+
/**
|
|
83
|
+
* Sets a value in the cache.
|
|
84
|
+
*
|
|
85
|
+
* @param cacheKey The key to store the value under.
|
|
86
|
+
* @param value The value to store in the cache.
|
|
87
|
+
* @param options Optional cache options.
|
|
88
|
+
*
|
|
89
|
+
* @returns A promise that resolves when the value is set or undefined if caching is disabled.
|
|
90
|
+
*
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
20
93
|
private setCacheValue;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a cache key from the given parameters and prefix.
|
|
96
|
+
*
|
|
97
|
+
* @param params The parameters to use for generating the key.
|
|
98
|
+
* @param prefix An optional prefix for the key.
|
|
99
|
+
*
|
|
100
|
+
* @returns The generated cache key.
|
|
101
|
+
*
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
21
104
|
private createCacheKey;
|
|
105
|
+
/**
|
|
106
|
+
* Handles errors during cache operations.
|
|
107
|
+
*
|
|
108
|
+
* @param error The error that occurred.
|
|
109
|
+
*
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
22
112
|
private handleError;
|
|
23
113
|
}
|
|
24
114
|
export type { Cache as CacheInterface } from './cache';
|
|
115
|
+
/**
|
|
116
|
+
* Type representing the `execute` method of the `Cached` class.
|
|
117
|
+
*/
|
|
25
118
|
export type CachedType = Cached['execute'];
|
package/dist/cache/cached.mjs
CHANGED
|
@@ -8,6 +8,16 @@ export class Cached {
|
|
|
8
8
|
log;
|
|
9
9
|
prefix;
|
|
10
10
|
enabled;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Cached instance.
|
|
13
|
+
*
|
|
14
|
+
* @param cache The cache implementation to use.
|
|
15
|
+
* @param log The logger instance.
|
|
16
|
+
* @param prefix An optional prefix for cache keys.
|
|
17
|
+
* @param enabled Whether caching is enabled.
|
|
18
|
+
*
|
|
19
|
+
* @throws {Error} If the cache is not initialized.
|
|
20
|
+
*/
|
|
11
21
|
constructor(cache, log, prefix = "", enabled) {
|
|
12
22
|
if (!cache) {
|
|
13
23
|
log.error(CACHE_NOT_INITIALIZED_MSG);
|
|
@@ -18,9 +28,23 @@ export class Cached {
|
|
|
18
28
|
this.prefix = prefix;
|
|
19
29
|
this.enabled = enabled;
|
|
20
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether caching is enabled.
|
|
33
|
+
*/
|
|
21
34
|
get isCacheEnabled() {
|
|
22
35
|
return this.enabled;
|
|
23
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Executes a function and caches its result.
|
|
39
|
+
*
|
|
40
|
+
* @param fn The asynchronous function to execute.
|
|
41
|
+
* @param options Optional cache options.
|
|
42
|
+
*
|
|
43
|
+
* @returns A wrapped function that handles caching.
|
|
44
|
+
*
|
|
45
|
+
* @template TArgs The type of the function's arguments.
|
|
46
|
+
* @template TResult The return type of the function.
|
|
47
|
+
*/
|
|
24
48
|
execute(fn, options) {
|
|
25
49
|
return async (...args) => {
|
|
26
50
|
const prefix = options?.cacheKeyPrefix ?? fn.name;
|
|
@@ -53,6 +77,16 @@ export class Cached {
|
|
|
53
77
|
return response;
|
|
54
78
|
};
|
|
55
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves a cached value from the cache.
|
|
82
|
+
*
|
|
83
|
+
* @param cacheKey The key of the cached value.
|
|
84
|
+
* @param options Optional cache options.
|
|
85
|
+
*
|
|
86
|
+
* @returns A promise that resolves with the cached value or undefined if not found or caching is disabled.
|
|
87
|
+
*
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
56
90
|
async getCacheValue(cacheKey, options) {
|
|
57
91
|
if (!this.isCacheEnabled) {
|
|
58
92
|
return;
|
|
@@ -65,6 +99,17 @@ export class Cached {
|
|
|
65
99
|
return data;
|
|
66
100
|
}
|
|
67
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Sets a value in the cache.
|
|
104
|
+
*
|
|
105
|
+
* @param cacheKey The key to store the value under.
|
|
106
|
+
* @param value The value to store in the cache.
|
|
107
|
+
* @param options Optional cache options.
|
|
108
|
+
*
|
|
109
|
+
* @returns A promise that resolves when the value is set or undefined if caching is disabled.
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
68
113
|
async setCacheValue(cacheKey, value, options) {
|
|
69
114
|
if (!this.isCacheEnabled) {
|
|
70
115
|
return;
|
|
@@ -74,9 +119,26 @@ export class Cached {
|
|
|
74
119
|
await timeout(CACHE_TIMEOUT, this.cache.set(cacheKey, value, ttl));
|
|
75
120
|
}
|
|
76
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates a cache key from the given parameters and prefix.
|
|
124
|
+
*
|
|
125
|
+
* @param params The parameters to use for generating the key.
|
|
126
|
+
* @param prefix An optional prefix for the key.
|
|
127
|
+
*
|
|
128
|
+
* @returns The generated cache key.
|
|
129
|
+
*
|
|
130
|
+
* @private
|
|
131
|
+
*/
|
|
77
132
|
async createCacheKey(params, prefix = "") {
|
|
78
133
|
return [prefix, await sha256(JSON.stringify(params))].join(":");
|
|
79
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Handles errors during cache operations.
|
|
137
|
+
*
|
|
138
|
+
* @param error The error that occurred.
|
|
139
|
+
*
|
|
140
|
+
* @private
|
|
141
|
+
*/
|
|
80
142
|
handleError(error) {
|
|
81
143
|
if (error.message === "timeout") {
|
|
82
144
|
return this.log.error("Cache timeout");
|
|
@@ -1,16 +1,80 @@
|
|
|
1
1
|
import type { Storage } from 'unstorage';
|
|
2
2
|
import type { Cache as CacheInterface } from '../cache';
|
|
3
3
|
export declare class UnstorageCache implements CacheInterface {
|
|
4
|
+
/**
|
|
5
|
+
* The underlying Unstorage storage instance.
|
|
6
|
+
*/
|
|
4
7
|
storage: Storage;
|
|
8
|
+
/**
|
|
9
|
+
* Key prefix used for namespacing cache entries.
|
|
10
|
+
*/
|
|
5
11
|
prefix: string;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new UnstorageCache instance.
|
|
14
|
+
*
|
|
15
|
+
* @param storage The Unstorage storage instance.
|
|
16
|
+
* @param prefix Optional key prefix for namespacing. Defaults to an empty string.
|
|
17
|
+
*/
|
|
6
18
|
constructor(storage: Storage, prefix?: string);
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves a cached value by key.
|
|
21
|
+
*
|
|
22
|
+
* @param key The cache key.
|
|
23
|
+
* @returns The cached value or null if not found.
|
|
24
|
+
*/
|
|
7
25
|
get(key: string): Promise<any | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a key exists in the cache.
|
|
28
|
+
*
|
|
29
|
+
* @param key The cache key.
|
|
30
|
+
* @returns True if the key exists, false otherwise.
|
|
31
|
+
*/
|
|
8
32
|
has(key: string): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Purges cache entries associated with the given tags.
|
|
35
|
+
*
|
|
36
|
+
* @param tags An array of tags to purge.
|
|
37
|
+
*/
|
|
9
38
|
purgeTags(tags: string[]): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Purges cache entries associated with a specific tag.
|
|
41
|
+
*
|
|
42
|
+
* @param tag The tag to purge.
|
|
43
|
+
*/
|
|
10
44
|
purgeTag(tag: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Purges cache entries by their keys.
|
|
47
|
+
*
|
|
48
|
+
* @param keys An array of keys to purge.
|
|
49
|
+
*/
|
|
11
50
|
purgeKeys(keys: string[]): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Purges all cache entries.
|
|
53
|
+
*/
|
|
12
54
|
purgeAll(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Sets a value in the cache.
|
|
57
|
+
*
|
|
58
|
+
* @param key The cache key.
|
|
59
|
+
* @param value The value to cache.
|
|
60
|
+
* @param ttl Time-to-live in milliseconds.
|
|
61
|
+
* @param tags Optional tags to associate with the cache entry.
|
|
62
|
+
*/
|
|
13
63
|
set(key: string, value: any, ttl: number, tags?: string[]): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Adds a key to a tag's list of associated keys.
|
|
66
|
+
*
|
|
67
|
+
* @param tag The tag.
|
|
68
|
+
* @param key The key to add.
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
14
71
|
private addKeyToTag;
|
|
72
|
+
/**
|
|
73
|
+
* Generates a namespaced key.
|
|
74
|
+
*
|
|
75
|
+
* @param key The key to namespace.
|
|
76
|
+
* @returns The namespaced key.
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
15
79
|
private getKey;
|
|
16
80
|
}
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
export class UnstorageCache {
|
|
2
|
+
/**
|
|
3
|
+
* The underlying Unstorage storage instance.
|
|
4
|
+
*/
|
|
2
5
|
storage;
|
|
6
|
+
/**
|
|
7
|
+
* Key prefix used for namespacing cache entries.
|
|
8
|
+
*/
|
|
3
9
|
prefix;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new UnstorageCache instance.
|
|
12
|
+
*
|
|
13
|
+
* @param storage The Unstorage storage instance.
|
|
14
|
+
* @param prefix Optional key prefix for namespacing. Defaults to an empty string.
|
|
15
|
+
*/
|
|
4
16
|
constructor(storage, prefix = "") {
|
|
5
17
|
this.storage = storage;
|
|
6
18
|
this.prefix = prefix;
|
|
7
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves a cached value by key.
|
|
22
|
+
*
|
|
23
|
+
* @param key The cache key.
|
|
24
|
+
* @returns The cached value or null if not found.
|
|
25
|
+
*/
|
|
8
26
|
async get(key) {
|
|
9
27
|
const value = await this.storage.getItem(this.getKey(key));
|
|
10
28
|
if (value === null) {
|
|
@@ -12,36 +30,82 @@ export class UnstorageCache {
|
|
|
12
30
|
}
|
|
13
31
|
return value;
|
|
14
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a key exists in the cache.
|
|
35
|
+
*
|
|
36
|
+
* @param key The cache key.
|
|
37
|
+
* @returns True if the key exists, false otherwise.
|
|
38
|
+
*/
|
|
15
39
|
async has(key) {
|
|
16
40
|
return await this.storage.hasItem(this.getKey(key));
|
|
17
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Purges cache entries associated with the given tags.
|
|
44
|
+
*
|
|
45
|
+
* @param tags An array of tags to purge.
|
|
46
|
+
*/
|
|
18
47
|
async purgeTags(tags) {
|
|
19
48
|
await Promise.all(tags.map((tag) => this.purgeTag(tag)));
|
|
20
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Purges cache entries associated with a specific tag.
|
|
52
|
+
*
|
|
53
|
+
* @param tag The tag to purge.
|
|
54
|
+
*/
|
|
21
55
|
async purgeTag(tag) {
|
|
22
56
|
const keys = await this.storage.getItem(this.getKey(`tag:${tag}`));
|
|
23
57
|
await this.purgeKeys(keys ?? []);
|
|
24
58
|
await this.storage.removeItem(this.getKey(`tag:${tag}`));
|
|
25
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Purges cache entries by their keys.
|
|
62
|
+
*
|
|
63
|
+
* @param keys An array of keys to purge.
|
|
64
|
+
*/
|
|
26
65
|
async purgeKeys(keys) {
|
|
27
66
|
await Promise.all(keys.map((k) => this.storage.removeItem(k)));
|
|
28
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Purges all cache entries.
|
|
70
|
+
*/
|
|
29
71
|
async purgeAll() {
|
|
30
72
|
const keys = await this.storage.getKeys(this.prefix);
|
|
31
73
|
await Promise.all(keys.map((k) => this.storage.removeItem(k)));
|
|
32
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets a value in the cache.
|
|
77
|
+
*
|
|
78
|
+
* @param key The cache key.
|
|
79
|
+
* @param value The value to cache.
|
|
80
|
+
* @param ttl Time-to-live in milliseconds.
|
|
81
|
+
* @param tags Optional tags to associate with the cache entry.
|
|
82
|
+
*/
|
|
33
83
|
async set(key, value, ttl, tags = []) {
|
|
34
84
|
await this.storage.setItem(this.getKey(key), value, { ttl });
|
|
35
85
|
await Promise.all(
|
|
36
86
|
tags.map((tag) => this.addKeyToTag(tag, this.getKey(key)))
|
|
37
87
|
);
|
|
38
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Adds a key to a tag's list of associated keys.
|
|
91
|
+
*
|
|
92
|
+
* @param tag The tag.
|
|
93
|
+
* @param key The key to add.
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
39
96
|
async addKeyToTag(tag, key) {
|
|
40
97
|
const keys = await this.storage.getItem(tag);
|
|
41
98
|
const set = new Set(keys ?? []);
|
|
42
99
|
set.add(key);
|
|
43
100
|
await this.storage.setItem(this.getKey(`tag:${tag}`), Array.from(set));
|
|
44
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Generates a namespaced key.
|
|
104
|
+
*
|
|
105
|
+
* @param key The key to namespace.
|
|
106
|
+
* @returns The namespaced key.
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
45
109
|
getKey(key) {
|
|
46
110
|
return [this.prefix, key].join(":");
|
|
47
111
|
}
|
package/dist/constants/hash.d.ts
CHANGED
package/dist/constants/hash.mjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { ValuesType } from 'utility-types';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Status Codes. See {@link HttpStatusMessage} for the corresponding status text.
|
|
4
|
+
*
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
|
|
6
|
+
*/
|
|
2
7
|
declare const HttpStatusCode: {
|
|
3
8
|
/**
|
|
4
9
|
* The server has received the request headers and the client should proceed to send the request body
|
|
@@ -85,7 +90,7 @@ declare const HttpStatusCode: {
|
|
|
85
90
|
* The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
|
|
86
91
|
* (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
|
|
87
92
|
* with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
|
|
88
|
-
* to distinguish between the two
|
|
93
|
+
* to distinguish between the two behaviors. However, some Web applications and frameworks
|
|
89
94
|
* use the 302 status code as if it were the 303.
|
|
90
95
|
*/
|
|
91
96
|
readonly FOUND: 302;
|
|
@@ -313,6 +318,11 @@ declare const HttpStatusCode: {
|
|
|
313
318
|
*/
|
|
314
319
|
readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
|
|
315
320
|
};
|
|
321
|
+
/**
|
|
322
|
+
* HTTP Status Messages corresponding to the {@link HttpStatusCode} codes.
|
|
323
|
+
*
|
|
324
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
|
|
325
|
+
*/
|
|
316
326
|
declare const HttpStatusMessage: {
|
|
317
327
|
/**
|
|
318
328
|
* The server has received the request headers and the client should proceed to send the request body
|
|
@@ -399,7 +409,7 @@ declare const HttpStatusMessage: {
|
|
|
399
409
|
* The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
|
|
400
410
|
* (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
|
|
401
411
|
* with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
|
|
402
|
-
* to distinguish between the two
|
|
412
|
+
* to distinguish between the two behaviors. However, some Web applications and frameworks
|
|
403
413
|
* use the 302 status code as if it were the 303.
|
|
404
414
|
*/
|
|
405
415
|
readonly FOUND: "FOUND";
|
|
@@ -84,7 +84,7 @@ const HttpStatusCode = {
|
|
|
84
84
|
* The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
|
|
85
85
|
* (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
|
|
86
86
|
* with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
|
|
87
|
-
* to distinguish between the two
|
|
87
|
+
* to distinguish between the two behaviors. However, some Web applications and frameworks
|
|
88
88
|
* use the 302 status code as if it were the 303.
|
|
89
89
|
*/
|
|
90
90
|
FOUND: 302,
|
|
@@ -398,7 +398,7 @@ const HttpStatusMessage = {
|
|
|
398
398
|
* The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
|
|
399
399
|
* (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
|
|
400
400
|
* with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
|
|
401
|
-
* to distinguish between the two
|
|
401
|
+
* to distinguish between the two behaviors. However, some Web applications and frameworks
|
|
402
402
|
* use the 302 status code as if it were the 303.
|
|
403
403
|
*/
|
|
404
404
|
FOUND: "FOUND",
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ValuesType } from 'utility-types';
|
|
2
|
+
/**
|
|
3
|
+
* Enumeration of sort options by internal name.
|
|
4
|
+
*/
|
|
2
5
|
declare const SortName: {
|
|
3
6
|
readonly TOPSELLER: "topseller";
|
|
4
7
|
readonly DATE_NEWEST: "date_newest";
|
|
@@ -7,6 +10,9 @@ declare const SortName: {
|
|
|
7
10
|
readonly REDUCTION_DESC: "reduction_desc";
|
|
8
11
|
readonly REDUCTION_ASC: "reduction_asc";
|
|
9
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Enumeration of sort options as used in query parameters.
|
|
15
|
+
*/
|
|
10
16
|
declare const SortQuery: {
|
|
11
17
|
readonly TOPSELLER: "topseller";
|
|
12
18
|
readonly DATE_NEWEST: "date-newest";
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { BasketWith, ProductWith, SearchWith, WishlistWith } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Default `with` parameters for product listings.
|
|
4
|
+
* Requests all available attributes, advanced attributes, variants, images,
|
|
5
|
+
* category properties, and price range information.
|
|
6
|
+
*/
|
|
2
7
|
declare const DEFAULT_WITH_LISTING: {
|
|
3
8
|
items: {
|
|
4
9
|
product: {
|
|
@@ -19,9 +24,32 @@ declare const DEFAULT_WITH_LISTING: {
|
|
|
19
24
|
};
|
|
20
25
|
};
|
|
21
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Minimum required `with` parameters for search requests.
|
|
29
|
+
* Includes essential product attributes, variant attributes, and category properties.
|
|
30
|
+
*/
|
|
22
31
|
declare const MIN_WITH_PARAMS_SEARCH: SearchWith;
|
|
32
|
+
/**
|
|
33
|
+
* Minimum required `with` parameters for single product requests.
|
|
34
|
+
* Includes essential product attributes, variant attributes, images,
|
|
35
|
+
* category properties, and sibling information.
|
|
36
|
+
*/
|
|
23
37
|
declare const MIN_WITH_PARAMS_PRODUCT: ProductWith;
|
|
38
|
+
/**
|
|
39
|
+
* Minimum required `with` parameters for basket requests.
|
|
40
|
+
* Includes essential product and variant information, images, categories,
|
|
41
|
+
* price range, and lowest prior price.
|
|
42
|
+
*/
|
|
24
43
|
declare const MIN_WITH_PARAMS_BASKET: BasketWith;
|
|
44
|
+
/**
|
|
45
|
+
* Minimum required `with` parameters for wishlist requests.
|
|
46
|
+
* Includes essential product and variant attributes, images, categories,
|
|
47
|
+
* price range, and lowest prior price.
|
|
48
|
+
*/
|
|
25
49
|
declare const MIN_WITH_PARAMS_WISHLIST: WishlistWith;
|
|
50
|
+
/**
|
|
51
|
+
* Minimum required `with` parameters for variant requests.
|
|
52
|
+
* Includes size-related attributes.
|
|
53
|
+
*/
|
|
26
54
|
declare const MIN_WITH_PARAMS_VARIANT: ProductWith;
|
|
27
55
|
export { DEFAULT_WITH_LISTING, MIN_WITH_PARAMS_BASKET, MIN_WITH_PARAMS_SEARCH, MIN_WITH_PARAMS_PRODUCT, MIN_WITH_PARAMS_WISHLIST, MIN_WITH_PARAMS_VARIANT, };
|
|
@@ -1,12 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface representing details of an error response. Conforms to RFC 7807.
|
|
3
|
+
*
|
|
4
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7807
|
|
5
|
+
*/
|
|
1
6
|
interface ErrorResponseDetails {
|
|
7
|
+
/**
|
|
8
|
+
* A human-readable explanation specific to this occurrence of the problem.
|
|
9
|
+
*/
|
|
2
10
|
detail?: string;
|
|
11
|
+
/**
|
|
12
|
+
* A URI reference that identifies the specific occurrence of the problem.
|
|
13
|
+
*/
|
|
3
14
|
instance?: string;
|
|
15
|
+
/**
|
|
16
|
+
* A URI reference that identifies the general problem type.
|
|
17
|
+
*/
|
|
4
18
|
type?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Allows for additional properties as needed.
|
|
21
|
+
*/
|
|
5
22
|
[s: string]: unknown | undefined;
|
|
6
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Error response based on RFC 9457 (Problem Details for HTTP APIs).
|
|
26
|
+
* Extends the standard Response object to include structured error information.
|
|
27
|
+
*
|
|
28
|
+
* @see https://datatracker.ietf.org/doc/html/rfc9457
|
|
29
|
+
*/
|
|
7
30
|
export declare class ErrorResponse extends Response {
|
|
31
|
+
/**
|
|
32
|
+
* A short, human-readable summary of the problem type. SHOULD NOT change from occurrence to occurrence of the problem.
|
|
33
|
+
*/
|
|
8
34
|
title: string;
|
|
35
|
+
/**
|
|
36
|
+
* Additional details about the error.
|
|
37
|
+
*/
|
|
9
38
|
details?: ErrorResponseDetails;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new ErrorResponse.
|
|
41
|
+
*
|
|
42
|
+
* @param statusCode The HTTP status code.
|
|
43
|
+
* @param statusMessage The HTTP status message.
|
|
44
|
+
* @param title A short, human-readable summary of the problem type.
|
|
45
|
+
* @param detail Optional details about the error.
|
|
46
|
+
*/
|
|
10
47
|
constructor(statusCode: number, statusMessage: string, title: string, detail?: ErrorResponseDetails);
|
|
11
48
|
}
|
|
12
49
|
export {};
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
export class ErrorResponse extends Response {
|
|
2
|
+
/**
|
|
3
|
+
* A short, human-readable summary of the problem type. SHOULD NOT change from occurrence to occurrence of the problem.
|
|
4
|
+
*/
|
|
2
5
|
title;
|
|
6
|
+
/**
|
|
7
|
+
* Additional details about the error.
|
|
8
|
+
*/
|
|
3
9
|
details;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new ErrorResponse.
|
|
12
|
+
*
|
|
13
|
+
* @param statusCode The HTTP status code.
|
|
14
|
+
* @param statusMessage The HTTP status message.
|
|
15
|
+
* @param title A short, human-readable summary of the problem type.
|
|
16
|
+
* @param detail Optional details about the error.
|
|
17
|
+
*/
|
|
4
18
|
constructor(statusCode, statusMessage, title, detail) {
|
|
5
19
|
const response = {
|
|
6
20
|
title,
|