@reactionary/hcl 0.10.52 → 0.10.54
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.
|
@@ -11,8 +11,12 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
11
11
|
import {
|
|
12
12
|
Reactionary,
|
|
13
13
|
StoreCapability,
|
|
14
|
+
StoreQueryByIdSchema,
|
|
14
15
|
StoreQueryByProximitySchema,
|
|
16
|
+
StoreQueryForListSchema,
|
|
17
|
+
StorePaginatedResultSchema,
|
|
15
18
|
StoreSchema,
|
|
19
|
+
error,
|
|
16
20
|
success
|
|
17
21
|
} from "@reactionary/core";
|
|
18
22
|
import * as z from "zod";
|
|
@@ -45,9 +49,63 @@ class HclStoreCapability extends StoreCapability {
|
|
|
45
49
|
);
|
|
46
50
|
return success(stores);
|
|
47
51
|
}
|
|
52
|
+
async getById(payload) {
|
|
53
|
+
const response = await this.client.callGet(
|
|
54
|
+
this.getStoreByIdUrl(payload),
|
|
55
|
+
new URLSearchParams(),
|
|
56
|
+
{ allowUndefined: true }
|
|
57
|
+
);
|
|
58
|
+
const store = response?.PhysicalStore?.[0];
|
|
59
|
+
if (!store) {
|
|
60
|
+
return error({ type: "NotFound", identifier: payload.identifier });
|
|
61
|
+
}
|
|
62
|
+
return success(this.factory.parseStore(this.context, store));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A radius in kilometers that covers the entire globe from any origin: the
|
|
66
|
+
* maximum great-circle distance between two points on Earth is ~20,015 km.
|
|
67
|
+
*/
|
|
68
|
+
getGlobalRadiusKm() {
|
|
69
|
+
return 25e3;
|
|
70
|
+
}
|
|
71
|
+
async list(payload) {
|
|
72
|
+
const response = await this.client.callGet(
|
|
73
|
+
this.getStoreListUrl(payload),
|
|
74
|
+
this.getStoreListParams(payload),
|
|
75
|
+
{ allowUndefined: true }
|
|
76
|
+
);
|
|
77
|
+
const { pageNumber, pageSize } = payload.paginationOptions;
|
|
78
|
+
const physicalStores = response?.PhysicalStore ?? [];
|
|
79
|
+
const requestedPageStart = (pageNumber - 1) * pageSize;
|
|
80
|
+
const pageStores = physicalStores.length > pageSize ? physicalStores.slice(requestedPageStart, requestedPageStart + pageSize) : physicalStores;
|
|
81
|
+
const reportedTotal = Number(response?.recordSetTotal);
|
|
82
|
+
const totalCount = Number.isFinite(reportedTotal) ? reportedTotal : physicalStores.length;
|
|
83
|
+
return success({
|
|
84
|
+
pageNumber,
|
|
85
|
+
pageSize,
|
|
86
|
+
totalCount,
|
|
87
|
+
totalPages: Math.ceil(totalCount / pageSize),
|
|
88
|
+
items: pageStores.map((store) => this.factory.parseStore(this.context, store))
|
|
89
|
+
});
|
|
90
|
+
}
|
|
48
91
|
// ---------------------------------------------------------------------------
|
|
49
92
|
// Extension points
|
|
50
93
|
// ---------------------------------------------------------------------------
|
|
94
|
+
getStoreByIdUrl(payload) {
|
|
95
|
+
return `${this.client.transactionBaseUrl}/storelocator/byStoreId/${encodeURIComponent(payload.identifier.key)}`;
|
|
96
|
+
}
|
|
97
|
+
getStoreListUrl(_payload) {
|
|
98
|
+
return `${this.client.transactionBaseUrl}/storelocator/latitude/0/longitude/0`;
|
|
99
|
+
}
|
|
100
|
+
getStoreListParams(payload) {
|
|
101
|
+
const params = new URLSearchParams();
|
|
102
|
+
params.set("radius", String(this.getGlobalRadiusKm()));
|
|
103
|
+
params.set("radiusUOM", "km");
|
|
104
|
+
params.set("siteLevelStoreSearch", "false");
|
|
105
|
+
params.set("pageNumber", String(payload.paginationOptions.pageNumber));
|
|
106
|
+
params.set("pageSize", String(payload.paginationOptions.pageSize));
|
|
107
|
+
return params;
|
|
108
|
+
}
|
|
51
109
|
getStoreLocatorUrl(payload) {
|
|
52
110
|
return `${this.client.transactionBaseUrl}/storelocator/latitude/${payload.latitude}/longitude/${payload.longitude}`;
|
|
53
111
|
}
|
|
@@ -66,6 +124,18 @@ __decorateClass([
|
|
|
66
124
|
outputSchema: z.array(StoreSchema)
|
|
67
125
|
})
|
|
68
126
|
], HclStoreCapability.prototype, "queryByProximity", 1);
|
|
127
|
+
__decorateClass([
|
|
128
|
+
Reactionary({
|
|
129
|
+
inputSchema: StoreQueryByIdSchema,
|
|
130
|
+
outputSchema: StoreSchema
|
|
131
|
+
})
|
|
132
|
+
], HclStoreCapability.prototype, "getById", 1);
|
|
133
|
+
__decorateClass([
|
|
134
|
+
Reactionary({
|
|
135
|
+
inputSchema: StoreQueryForListSchema,
|
|
136
|
+
outputSchema: StorePaginatedResultSchema
|
|
137
|
+
})
|
|
138
|
+
], HclStoreCapability.prototype, "list", 1);
|
|
69
139
|
export {
|
|
70
140
|
HclStoreCapability
|
|
71
141
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/hcl",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.54",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/Solteq/reactionary.git"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@reactionary/core": "0.10.
|
|
12
|
+
"@reactionary/core": "0.10.54",
|
|
13
13
|
"debug": "^4.4.3",
|
|
14
14
|
"zod": "4.1.9"
|
|
15
15
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Cache, type RequestContext, type Result, StoreCapability, type StoreFactory, type StoreFactoryOutput, type StoreFactoryWithOutput, type StoreQueryByProximity } from '@reactionary/core';
|
|
1
|
+
import { type Cache, type NotFoundError, type RequestContext, type Result, StoreCapability, type StoreFactory, type StoreFactoryOutput, type StoreFactoryWithOutput, type StorePaginatedResult, type StoreQueryById, type StoreQueryByProximity, type StoreQueryForList } from '@reactionary/core';
|
|
2
2
|
import type { HclConfiguration } from '../schema/configuration.schema.js';
|
|
3
3
|
import type { HclClient } from '../core/client.js';
|
|
4
4
|
import type { HclStoreFactory } from '../factories/store/store.factory.js';
|
|
@@ -8,6 +8,16 @@ export declare class HclStoreCapability<TFactory extends StoreFactory = HclStore
|
|
|
8
8
|
protected readonly factory: StoreFactoryWithOutput<TFactory>;
|
|
9
9
|
constructor(cache: Cache, context: RequestContext, config: HclConfiguration, client: HclClient, factory: StoreFactoryWithOutput<TFactory>);
|
|
10
10
|
queryByProximity(payload: StoreQueryByProximity): Promise<Result<StoreFactoryOutput<TFactory>[]>>;
|
|
11
|
+
getById(payload: StoreQueryById): Promise<Result<StoreFactoryOutput<TFactory>, NotFoundError>>;
|
|
12
|
+
/**
|
|
13
|
+
* A radius in kilometers that covers the entire globe from any origin: the
|
|
14
|
+
* maximum great-circle distance between two points on Earth is ~20,015 km.
|
|
15
|
+
*/
|
|
16
|
+
protected getGlobalRadiusKm(): number;
|
|
17
|
+
list(payload: StoreQueryForList): Promise<Result<StorePaginatedResult>>;
|
|
18
|
+
protected getStoreByIdUrl(payload: StoreQueryById): string;
|
|
19
|
+
protected getStoreListUrl(_payload: StoreQueryForList): string;
|
|
20
|
+
protected getStoreListParams(payload: StoreQueryForList): URLSearchParams;
|
|
11
21
|
protected getStoreLocatorUrl(payload: StoreQueryByProximity): string;
|
|
12
22
|
protected getStoreLocatorParams(payload: StoreQueryByProximity): URLSearchParams;
|
|
13
23
|
}
|
package/src/test/test-utils.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare function createHclClient(contextOverrides?: Partial<RequestContex
|
|
|
6
6
|
productSearch?: true | undefined;
|
|
7
7
|
company?: false | undefined;
|
|
8
8
|
price?: false | undefined;
|
|
9
|
+
store?: false | undefined;
|
|
9
10
|
order?: false | undefined;
|
|
10
11
|
cart?: false | undefined;
|
|
11
12
|
checkout?: false | undefined;
|
|
@@ -13,10 +14,9 @@ export declare function createHclClient(contextOverrides?: Partial<RequestContex
|
|
|
13
14
|
profile?: false | undefined;
|
|
14
15
|
inventory?: false | undefined;
|
|
15
16
|
category?: true | undefined;
|
|
16
|
-
store?: false | undefined;
|
|
17
17
|
productList?: false | undefined;
|
|
18
18
|
orderSearch?: false | undefined;
|
|
19
|
-
}>, "product" | "productSearch" | "company" | "price" | "order" | "cart" | "checkout" | "identity" | "profile" | "inventory" | "category" | "
|
|
19
|
+
}>, "product" | "productSearch" | "company" | "price" | "store" | "order" | "cart" | "checkout" | "identity" | "profile" | "inventory" | "category" | "productList" | "orderSearch"> & {
|
|
20
20
|
product: import("../index.js").HclProductCapability<import("../index.js").HclProductFactory<import("zod").ZodObject<{
|
|
21
21
|
identifier: import("zod").ZodObject<{
|
|
22
22
|
key: import("zod").ZodString;
|