@reactionary/core 0.0.42 → 0.0.48
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/cache/memory-cache.js +39 -0
- package/cache/noop-cache.js +3 -13
- package/cache/redis-cache.js +16 -32
- package/decorators/reactionary.decorator.js +57 -4
- package/index.js +2 -1
- package/initialization.js +43 -0
- package/package.json +4 -2
- package/providers/base.provider.js +29 -12
- package/providers/index.js +2 -0
- package/providers/profile.provider.js +9 -0
- package/providers/store.provider.js +9 -0
- package/schemas/capabilities.schema.js +2 -1
- package/schemas/models/identifiers.model.js +12 -6
- package/schemas/models/identity.model.js +15 -16
- package/schemas/models/index.js +1 -0
- package/schemas/models/profile.model.js +3 -2
- package/schemas/models/shipping-method.model.js +2 -2
- package/schemas/models/store.model.js +11 -0
- package/schemas/mutations/cart.mutation.js +2 -2
- package/schemas/mutations/identity.mutation.js +6 -1
- package/schemas/mutations/index.js +1 -0
- package/schemas/mutations/profile.mutation.js +9 -0
- package/schemas/queries/index.js +2 -0
- package/schemas/queries/inventory.query.js +3 -5
- package/schemas/queries/profile.query.js +5 -0
- package/schemas/queries/store.query.js +11 -0
- package/schemas/session.schema.js +22 -8
- package/src/cache/cache.interface.d.ts +13 -20
- package/src/cache/memory-cache.d.ts +18 -0
- package/src/cache/noop-cache.d.ts +5 -11
- package/src/cache/redis-cache.d.ts +5 -11
- package/src/client/client-builder.d.ts +2 -2
- package/src/client/client.d.ts +10 -10
- package/src/decorators/reactionary.decorator.d.ts +34 -1
- package/src/index.d.ts +2 -1
- package/src/initialization.d.ts +2 -0
- package/src/providers/analytics.provider.d.ts +1 -1
- package/src/providers/base.provider.d.ts +12 -9
- package/src/providers/cart-payment.provider.d.ts +7 -7
- package/src/providers/cart.provider.d.ts +17 -17
- package/src/providers/category.provider.d.ts +9 -9
- package/src/providers/identity.provider.d.ts +8 -7
- package/src/providers/index.d.ts +2 -0
- package/src/providers/inventory.provider.d.ts +4 -4
- package/src/providers/price.provider.d.ts +6 -6
- package/src/providers/product.provider.d.ts +5 -5
- package/src/providers/profile.provider.d.ts +10 -0
- package/src/providers/search.provider.d.ts +4 -4
- package/src/providers/store.provider.d.ts +8 -0
- package/src/schemas/capabilities.schema.d.ts +1 -0
- package/src/schemas/models/analytics.model.d.ts +1 -1
- package/src/schemas/models/cart.model.d.ts +14 -0
- package/src/schemas/models/identifiers.model.d.ts +10 -6
- package/src/schemas/models/identity.model.d.ts +72 -27
- package/src/schemas/models/index.d.ts +1 -0
- package/src/schemas/models/inventory.model.d.ts +1 -1
- package/src/schemas/models/profile.model.d.ts +35 -0
- package/src/schemas/models/store.model.d.ts +18 -0
- package/src/schemas/mutations/cart-payment.mutation.d.ts +1 -1
- package/src/schemas/mutations/cart.mutation.d.ts +14 -0
- package/src/schemas/mutations/identity.mutation.d.ts +5 -0
- package/src/schemas/mutations/index.d.ts +1 -0
- package/src/schemas/mutations/profile.mutation.d.ts +6 -0
- package/src/schemas/queries/cart.query.d.ts +1 -1
- package/src/schemas/queries/identity.query.d.ts +1 -1
- package/src/schemas/queries/index.d.ts +2 -0
- package/src/schemas/queries/inventory.query.d.ts +6 -15
- package/src/schemas/queries/price.query.d.ts +1 -1
- package/src/schemas/queries/profile.query.d.ts +3 -0
- package/src/schemas/queries/search.query.d.ts +1 -1
- package/src/schemas/queries/store.query.d.ts +8 -0
- package/src/schemas/session.schema.d.ts +53 -21
- package/cache/cache-evaluation.interface.js +0 -0
- package/src/cache/cache-evaluation.interface.d.ts +0 -17
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class MemoryCache {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.entries = new Array();
|
|
4
|
+
}
|
|
5
|
+
async get(key, schema) {
|
|
6
|
+
const c = this.entries.find((x) => x.key === key);
|
|
7
|
+
if (!c) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const parsed = schema.parse(c.value);
|
|
11
|
+
parsed.meta.cache.hit = true;
|
|
12
|
+
return parsed;
|
|
13
|
+
}
|
|
14
|
+
async put(key, value, options) {
|
|
15
|
+
this.entries.push({
|
|
16
|
+
key,
|
|
17
|
+
value,
|
|
18
|
+
options
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
async invalidate(dependencyIds) {
|
|
23
|
+
let index = 0;
|
|
24
|
+
for (const entry of this.entries) {
|
|
25
|
+
for (const entryDependency of entry.options.dependencyIds) {
|
|
26
|
+
if (dependencyIds.indexOf(entryDependency) > -1) {
|
|
27
|
+
this.entries.splice(index, 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
index++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async clear() {
|
|
34
|
+
this.entries = [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
MemoryCache
|
|
39
|
+
};
|
package/cache/noop-cache.js
CHANGED
|
@@ -2,25 +2,15 @@ class NoOpCache {
|
|
|
2
2
|
async get(_key, _schema) {
|
|
3
3
|
return null;
|
|
4
4
|
}
|
|
5
|
-
async put(_key, _value,
|
|
5
|
+
async put(_key, _value, options) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
async
|
|
8
|
+
async invalidate(dependencyIds) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
async
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
async clear(_pattern) {
|
|
11
|
+
async clear() {
|
|
15
12
|
return;
|
|
16
13
|
}
|
|
17
|
-
async getStats() {
|
|
18
|
-
return {
|
|
19
|
-
hits: 0,
|
|
20
|
-
misses: 0,
|
|
21
|
-
size: 0
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
14
|
}
|
|
25
15
|
export {
|
|
26
16
|
NoOpCache
|
package/cache/redis-cache.js
CHANGED
|
@@ -14,45 +14,29 @@ class RedisCache {
|
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
-
async put(key, value,
|
|
17
|
+
async put(key, value, options) {
|
|
18
18
|
if (!key) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (const key of keyArray) {
|
|
27
|
-
if (key.includes("*")) {
|
|
28
|
-
const matchingKeys = await this.redis.keys(key);
|
|
29
|
-
if (matchingKeys.length > 0) {
|
|
30
|
-
await this.redis.del(...matchingKeys);
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
await this.redis.del(key);
|
|
34
|
-
}
|
|
21
|
+
const serialized = JSON.stringify(value);
|
|
22
|
+
const multi = this.redis.multi();
|
|
23
|
+
multi.set(key, serialized, { ex: options.ttlSeconds });
|
|
24
|
+
for (const depId of options.dependencyIds) {
|
|
25
|
+
multi.sadd(`dep:${depId}`, key);
|
|
35
26
|
}
|
|
27
|
+
await multi.exec();
|
|
36
28
|
}
|
|
37
|
-
async
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
await this.redis.del(
|
|
29
|
+
async invalidate(dependencyIds) {
|
|
30
|
+
for (const id of dependencyIds) {
|
|
31
|
+
const depKey = `dep:${id}`;
|
|
32
|
+
const keys = await this.redis.smembers(depKey);
|
|
33
|
+
if (keys.length > 0) {
|
|
34
|
+
await this.redis.del(...keys);
|
|
35
|
+
}
|
|
36
|
+
await this.redis.del(depKey);
|
|
45
37
|
}
|
|
46
38
|
}
|
|
47
|
-
async
|
|
48
|
-
const keys = await this.redis.keys("*");
|
|
49
|
-
return {
|
|
50
|
-
hits: 0,
|
|
51
|
-
// Would need to track this separately
|
|
52
|
-
misses: 0,
|
|
53
|
-
// Would need to track this separately
|
|
54
|
-
size: keys.length
|
|
55
|
-
};
|
|
39
|
+
async clear() {
|
|
56
40
|
}
|
|
57
41
|
}
|
|
58
42
|
export {
|
|
@@ -1,13 +1,66 @@
|
|
|
1
|
+
import { getTracer, SpanKind } from "@reactionary/otel";
|
|
2
|
+
class ReactionaryDecoratorOptions {
|
|
3
|
+
constructor() {
|
|
4
|
+
/**
|
|
5
|
+
* Whether or not the query is eligible for caching. Queries that depend
|
|
6
|
+
* heavily on personalization, for example, are likely to be a poor fit
|
|
7
|
+
* for caching.
|
|
8
|
+
*/
|
|
9
|
+
this.cache = false;
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not the cache entry should be variable based on the locale
|
|
12
|
+
* of the context in which it is querried.
|
|
13
|
+
*/
|
|
14
|
+
this.localeDependentCaching = false;
|
|
15
|
+
/**
|
|
16
|
+
* Whether or not the cache entry should be variable based on the currency
|
|
17
|
+
* of the context in which it is querried.
|
|
18
|
+
*/
|
|
19
|
+
this.currencyDependentCaching = false;
|
|
20
|
+
/**
|
|
21
|
+
* The number of seconds which a cache entry should be considered valid for the
|
|
22
|
+
* given query.
|
|
23
|
+
*/
|
|
24
|
+
this.cacheTimeToLiveInSeconds = 60;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
;
|
|
1
28
|
function Reactionary(options) {
|
|
2
29
|
return function(target, propertyKey, descriptor) {
|
|
3
30
|
const original = descriptor.value;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
31
|
+
const scope = `${target.constructor.name}.${propertyKey.toString()}`;
|
|
32
|
+
const configuration = { ...new ReactionaryDecoratorOptions(), ...options };
|
|
33
|
+
if (!original) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"@Reactionary decorator may only be applied to methods on classes extending BaseProvider."
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
descriptor.value = async function(...args) {
|
|
39
|
+
const tracer = getTracer();
|
|
40
|
+
return tracer.startActiveSpan(
|
|
41
|
+
propertyKey.toString(),
|
|
42
|
+
{ kind: SpanKind.SERVER },
|
|
43
|
+
async (span) => {
|
|
44
|
+
const cacheKey = this.generateCacheKeyForQuery(scope, args[0]);
|
|
45
|
+
const fromCache = await this.cache.get(cacheKey, this.schema);
|
|
46
|
+
let result = fromCache;
|
|
47
|
+
if (!result) {
|
|
48
|
+
result = await original.apply(this, args);
|
|
49
|
+
const dependencyIds = this.generateDependencyIdsForModel(result);
|
|
50
|
+
this.cache.put(cacheKey, result, {
|
|
51
|
+
ttlSeconds: configuration.cacheTimeToLiveInSeconds,
|
|
52
|
+
dependencyIds
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
span.end();
|
|
56
|
+
return this.assert(result);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
7
59
|
};
|
|
8
60
|
return descriptor;
|
|
9
61
|
};
|
|
10
62
|
}
|
|
11
63
|
export {
|
|
12
|
-
Reactionary
|
|
64
|
+
Reactionary,
|
|
65
|
+
ReactionaryDecoratorOptions
|
|
13
66
|
};
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./cache/cache.interface";
|
|
2
|
-
export * from "./cache/cache-evaluation.interface";
|
|
3
2
|
export * from "./cache/redis-cache";
|
|
3
|
+
export * from "./cache/memory-cache";
|
|
4
4
|
export * from "./cache/noop-cache";
|
|
5
5
|
export * from "./client/client";
|
|
6
6
|
export * from "./client/client-builder";
|
|
@@ -11,3 +11,4 @@ export * from "./schemas/session.schema";
|
|
|
11
11
|
export * from "./schemas/models/";
|
|
12
12
|
export * from "./schemas/mutations/";
|
|
13
13
|
export * from "./schemas/queries";
|
|
14
|
+
export * from "./initialization";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function createInitialRequestContext() {
|
|
2
|
+
return {
|
|
3
|
+
id: "",
|
|
4
|
+
identity: {
|
|
5
|
+
type: "Anonymous",
|
|
6
|
+
meta: {
|
|
7
|
+
cache: { hit: false, key: "" },
|
|
8
|
+
placeholder: false
|
|
9
|
+
},
|
|
10
|
+
id: { userId: "anonymous" },
|
|
11
|
+
token: void 0,
|
|
12
|
+
issued: /* @__PURE__ */ new Date(),
|
|
13
|
+
expiry: new Date((/* @__PURE__ */ new Date()).getTime() + 3600 * 1e3),
|
|
14
|
+
logonId: "",
|
|
15
|
+
createdAt: "",
|
|
16
|
+
updatedAt: "",
|
|
17
|
+
keyring: [],
|
|
18
|
+
currentService: void 0
|
|
19
|
+
},
|
|
20
|
+
languageContext: {
|
|
21
|
+
locale: "en-US",
|
|
22
|
+
currencyCode: "USD"
|
|
23
|
+
},
|
|
24
|
+
storeIdentifier: {
|
|
25
|
+
key: "the-good-store"
|
|
26
|
+
},
|
|
27
|
+
taxJurisdiction: {
|
|
28
|
+
countryCode: "US",
|
|
29
|
+
stateCode: "",
|
|
30
|
+
countyCode: "",
|
|
31
|
+
cityCode: ""
|
|
32
|
+
},
|
|
33
|
+
session: {},
|
|
34
|
+
correlationId: "",
|
|
35
|
+
isBot: false,
|
|
36
|
+
clientIp: "",
|
|
37
|
+
userAgent: "",
|
|
38
|
+
referrer: ""
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
createInitialRequestContext
|
|
43
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"zod": "4.1.9",
|
|
8
|
-
"@upstash/redis": "^1.34.9"
|
|
8
|
+
"@upstash/redis": "^1.34.9",
|
|
9
|
+
"@reactionary/otel": "0.0.48",
|
|
10
|
+
"node-object-hash": "^3.1.1"
|
|
9
11
|
}
|
|
10
12
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createPaginatedResponseSchema
|
|
3
|
+
} from "../schemas/models/base.model";
|
|
4
|
+
import { hasher } from "node-object-hash";
|
|
2
5
|
class BaseProvider {
|
|
3
6
|
constructor(schema, cache) {
|
|
4
7
|
this.schema = schema;
|
|
@@ -21,26 +24,40 @@ class BaseProvider {
|
|
|
21
24
|
* Handler for parsing a response from a remote provider and converting it
|
|
22
25
|
* into the typed domain model.
|
|
23
26
|
*/
|
|
24
|
-
parseSingle(_body,
|
|
27
|
+
parseSingle(_body, reqCtx) {
|
|
25
28
|
const model = this.newModel();
|
|
26
29
|
return this.assert(model);
|
|
27
30
|
}
|
|
28
|
-
parsePaginatedResult(_body,
|
|
31
|
+
parsePaginatedResult(_body, reqCtx) {
|
|
29
32
|
return createPaginatedResponseSchema(this.schema).parse({});
|
|
30
33
|
}
|
|
31
|
-
|
|
34
|
+
generateDependencyIdsForModel(model) {
|
|
35
|
+
const identifier = model?.identifier;
|
|
36
|
+
if (!identifier) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const h = hasher({ sort: true, coerce: false });
|
|
40
|
+
const hash = h.hash(identifier);
|
|
41
|
+
return [hash];
|
|
42
|
+
}
|
|
43
|
+
generateCacheKeyForQuery(scope, query) {
|
|
44
|
+
const h = hasher({ sort: true, coerce: false });
|
|
45
|
+
const queryHash = h.hash(query);
|
|
46
|
+
return `${scope}:${queryHash}`;
|
|
47
|
+
}
|
|
48
|
+
generateCacheKeyPaginatedResult(resultSetName, res, reqCtx) {
|
|
32
49
|
const type = this.getResourceName();
|
|
33
|
-
const langPart =
|
|
34
|
-
const currencyPart =
|
|
35
|
-
const storePart =
|
|
50
|
+
const langPart = reqCtx.languageContext.locale;
|
|
51
|
+
const currencyPart = reqCtx.languageContext.currencyCode || "default";
|
|
52
|
+
const storePart = reqCtx.storeIdentifier?.key || "default";
|
|
36
53
|
return `${type}-${resultSetName}-paginated|pageNumber:${res.pageNumber}|pageSize:${res.pageSize}|store:${storePart}|lang:${langPart}|currency:${currencyPart}`;
|
|
37
54
|
}
|
|
38
|
-
generateCacheKeySingle(identifier,
|
|
55
|
+
generateCacheKeySingle(identifier, reqCtx) {
|
|
39
56
|
const type = this.getResourceName();
|
|
40
|
-
const idPart = Object.entries(identifier).map(([k, v]) => `${k}:${v
|
|
41
|
-
const langPart =
|
|
42
|
-
const currencyPart =
|
|
43
|
-
const storePart =
|
|
57
|
+
const idPart = Object.entries(identifier).map(([k, v]) => `${k}:${v}`).join("#");
|
|
58
|
+
const langPart = reqCtx.languageContext.locale;
|
|
59
|
+
const currencyPart = reqCtx.languageContext.currencyCode || "default";
|
|
60
|
+
const storePart = reqCtx.storeIdentifier?.key || "default";
|
|
44
61
|
return `${type}-${idPart}|store:${storePart}|lang:${langPart}|currency:${currencyPart}`;
|
|
45
62
|
}
|
|
46
63
|
}
|
package/providers/index.js
CHANGED
|
@@ -30,6 +30,9 @@ const PriceIdentifierSchema = z.looseObject({
|
|
|
30
30
|
const CategoryIdentifierSchema = z.looseObject({
|
|
31
31
|
key: z.string().default("").nonoptional()
|
|
32
32
|
});
|
|
33
|
+
const StoreIdentifierSchema = z.looseObject({
|
|
34
|
+
key: z.string().default("").optional()
|
|
35
|
+
});
|
|
33
36
|
const OrderIdentifierSchema = z.looseObject({
|
|
34
37
|
key: z.string().default("").nonoptional()
|
|
35
38
|
});
|
|
@@ -39,17 +42,19 @@ const OrderItemIdentifierSchema = z.looseObject({
|
|
|
39
42
|
const WebStoreIdentifierSchema = z.looseObject({
|
|
40
43
|
key: z.string().default("").nonoptional()
|
|
41
44
|
});
|
|
42
|
-
const
|
|
43
|
-
key: z.string().default("
|
|
45
|
+
const FulfillmentCenterIdentifierSchema = z.looseObject({
|
|
46
|
+
key: z.string().default("").nonoptional()
|
|
44
47
|
});
|
|
45
48
|
const InventoryIdentifierSchema = z.looseObject({
|
|
46
49
|
sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
|
|
47
|
-
|
|
50
|
+
fulfillmentCenter: FulfillmentCenterIdentifierSchema.default(
|
|
51
|
+
() => FulfillmentCenterIdentifierSchema.parse({})
|
|
52
|
+
)
|
|
48
53
|
});
|
|
49
54
|
const IdentityIdentifierSchema = z.looseObject({
|
|
50
55
|
userId: z.string().default("").nonoptional()
|
|
51
56
|
});
|
|
52
|
-
const
|
|
57
|
+
const ShippingMethodIdentifierSchema = z.looseObject({
|
|
53
58
|
key: z.string().default("").nonoptional()
|
|
54
59
|
});
|
|
55
60
|
const PaymentMethodIdentifierSchema = z.looseObject({
|
|
@@ -70,8 +75,8 @@ export {
|
|
|
70
75
|
CategoryIdentifierSchema,
|
|
71
76
|
FacetIdentifierSchema,
|
|
72
77
|
FacetValueIdentifierSchema,
|
|
78
|
+
FulfillmentCenterIdentifierSchema,
|
|
73
79
|
IdentityIdentifierSchema,
|
|
74
|
-
InventoryChannelIdentifierSchema,
|
|
75
80
|
InventoryIdentifierSchema,
|
|
76
81
|
OrderIdentifierSchema,
|
|
77
82
|
OrderItemIdentifierSchema,
|
|
@@ -81,6 +86,7 @@ export {
|
|
|
81
86
|
ProductIdentifierSchema,
|
|
82
87
|
SKUIdentifierSchema,
|
|
83
88
|
SearchIdentifierSchema,
|
|
84
|
-
|
|
89
|
+
ShippingMethodIdentifierSchema,
|
|
90
|
+
StoreIdentifierSchema,
|
|
85
91
|
WebStoreIdentifierSchema
|
|
86
92
|
};
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseModelSchema } from "./base.model";
|
|
3
3
|
import { IdentityIdentifierSchema } from "./identifiers.model";
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const AnonymousIdentitySchema = BaseModelSchema.extend({
|
|
5
|
+
type: z.literal("Anonymous")
|
|
6
|
+
});
|
|
7
|
+
const GuestIdentitySchema = BaseModelSchema.extend({
|
|
8
|
+
id: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
|
|
9
|
+
type: z.literal("Guest"),
|
|
10
|
+
token: z.string().optional(),
|
|
11
|
+
refresh_token: z.string().optional(),
|
|
9
12
|
expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
|
|
10
13
|
});
|
|
11
|
-
const
|
|
14
|
+
const RegisteredIdentitySchema = BaseModelSchema.extend({
|
|
12
15
|
id: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
|
|
13
|
-
type:
|
|
16
|
+
type: z.literal("Registered"),
|
|
14
17
|
logonId: z.string().default(""),
|
|
15
|
-
createdAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
|
|
16
|
-
updatedAt: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString()),
|
|
17
|
-
// Tokens for various services
|
|
18
|
-
keyring: z.array(ServiceTokenSchema).default(() => []),
|
|
19
|
-
// Deprecated - use serviceTokens map instead
|
|
20
|
-
currentService: z.string().optional(),
|
|
21
18
|
token: z.string().optional(),
|
|
22
|
-
|
|
19
|
+
refresh_token: z.string().optional(),
|
|
23
20
|
expiry: z.coerce.date().default(/* @__PURE__ */ new Date())
|
|
24
21
|
});
|
|
22
|
+
const IdentitySchema = z.discriminatedUnion("type", [AnonymousIdentitySchema, GuestIdentitySchema, RegisteredIdentitySchema]);
|
|
25
23
|
export {
|
|
24
|
+
AnonymousIdentitySchema,
|
|
25
|
+
GuestIdentitySchema,
|
|
26
26
|
IdentitySchema,
|
|
27
|
-
|
|
28
|
-
ServiceTokenSchema
|
|
27
|
+
RegisteredIdentitySchema
|
|
29
28
|
};
|
package/schemas/models/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
2
|
import { AddressIdentifierSchema, IdentityIdentifierSchema } from "./identifiers.model";
|
|
3
|
-
|
|
3
|
+
import { BaseModelSchema } from "./base.model";
|
|
4
|
+
const AddressSchema = BaseModelSchema.extend({
|
|
4
5
|
identifier: AddressIdentifierSchema.default(() => AddressIdentifierSchema.parse({})),
|
|
5
6
|
firstName: z.string().default(""),
|
|
6
7
|
lastName: z.string().default(""),
|
|
@@ -11,7 +12,7 @@ const AddressSchema = z.looseObject({
|
|
|
11
12
|
postalCode: z.string().default(""),
|
|
12
13
|
countryCode: z.string().default("US")
|
|
13
14
|
});
|
|
14
|
-
const ProfileSchema =
|
|
15
|
+
const ProfileSchema = BaseModelSchema.extend({
|
|
15
16
|
identifier: IdentityIdentifierSchema.default(() => IdentityIdentifierSchema.parse({})),
|
|
16
17
|
email: z.string().email().default(""),
|
|
17
18
|
phone: z.string().default(""),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { ShippingMethodIdentifierSchema } from "./identifiers.model";
|
|
3
3
|
import { MonetaryAmountSchema } from "./price.model";
|
|
4
4
|
import { ImageSchema } from "./base.model";
|
|
5
5
|
const ShippingMethodSchema = z.looseObject({
|
|
6
|
-
identifier:
|
|
6
|
+
identifier: ShippingMethodIdentifierSchema.default(() => ShippingMethodIdentifierSchema.parse({})),
|
|
7
7
|
name: z.string().default(""),
|
|
8
8
|
description: z.string().default(""),
|
|
9
9
|
logo: ImageSchema.optional(),
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BaseModelSchema } from "./base.model";
|
|
3
|
+
import { FulfillmentCenterIdentifierSchema, StoreIdentifierSchema } from "./identifiers.model";
|
|
4
|
+
const StoreSchema = BaseModelSchema.extend({
|
|
5
|
+
identifier: StoreIdentifierSchema.default(() => StoreIdentifierSchema.parse({})),
|
|
6
|
+
name: z.string().default(""),
|
|
7
|
+
fulfillmentCenter: FulfillmentCenterIdentifierSchema.default(() => FulfillmentCenterIdentifierSchema.parse({}))
|
|
8
|
+
});
|
|
9
|
+
export {
|
|
10
|
+
StoreSchema
|
|
11
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { BaseMutationSchema } from "./base.mutation";
|
|
3
|
-
import { CartIdentifierSchema, CartItemIdentifierSchema, PaymentMethodIdentifierSchema,
|
|
3
|
+
import { CartIdentifierSchema, CartItemIdentifierSchema, PaymentMethodIdentifierSchema, ShippingMethodIdentifierSchema, SKUIdentifierSchema } from "../models/identifiers.model";
|
|
4
4
|
import { AddressSchema } from "../models/profile.model";
|
|
5
5
|
import { CurrencySchema } from "../models/currency.model";
|
|
6
6
|
import { MonetaryAmountSchema } from "../models/price.model";
|
|
@@ -23,7 +23,7 @@ const CartMutationDeleteCartSchema = BaseMutationSchema.extend({
|
|
|
23
23
|
});
|
|
24
24
|
const CartMutationSetShippingInfoSchema = BaseMutationSchema.extend({
|
|
25
25
|
cart: CartIdentifierSchema.required(),
|
|
26
|
-
shippingMethod:
|
|
26
|
+
shippingMethod: ShippingMethodIdentifierSchema.optional(),
|
|
27
27
|
shippingAddress: AddressSchema.optional()
|
|
28
28
|
});
|
|
29
29
|
const CartMutationSetBillingAddressSchema = BaseMutationSchema.extend({
|
|
@@ -5,7 +5,12 @@ const IdentityMutationLoginSchema = BaseMutationSchema.extend({
|
|
|
5
5
|
password: z.string()
|
|
6
6
|
});
|
|
7
7
|
const IdentityMutationLogoutSchema = BaseMutationSchema.extend({});
|
|
8
|
+
const IdentityMutationRegisterSchema = BaseMutationSchema.extend({
|
|
9
|
+
username: z.string(),
|
|
10
|
+
password: z.string()
|
|
11
|
+
});
|
|
8
12
|
export {
|
|
9
13
|
IdentityMutationLoginSchema,
|
|
10
|
-
IdentityMutationLogoutSchema
|
|
14
|
+
IdentityMutationLogoutSchema,
|
|
15
|
+
IdentityMutationRegisterSchema
|
|
11
16
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BaseMutationSchema } from "./base.mutation";
|
|
3
|
+
const ProfileMutationUpdateSchema = BaseMutationSchema.extend({
|
|
4
|
+
email: z.email().default("base@example.com"),
|
|
5
|
+
phone: z.string().default("")
|
|
6
|
+
});
|
|
7
|
+
export {
|
|
8
|
+
ProfileMutationUpdateSchema
|
|
9
|
+
};
|
package/schemas/queries/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { BaseQuerySchema } from "./base.query";
|
|
3
|
-
import { ProductIdentifierSchema } from "../models/identifiers.model";
|
|
2
|
+
import { FulfillmentCenterIdentifierSchema, ProductIdentifierSchema } from "../models/identifiers.model";
|
|
4
3
|
const InventoryQueryBySKUSchema = BaseQuerySchema.extend({
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
sku: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})).nonoptional(),
|
|
5
|
+
fulfilmentCenter: FulfillmentCenterIdentifierSchema.default(() => FulfillmentCenterIdentifierSchema.parse({})).nonoptional()
|
|
7
6
|
});
|
|
8
|
-
;
|
|
9
7
|
export {
|
|
10
8
|
InventoryQueryBySKUSchema
|
|
11
9
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BaseQuerySchema } from "./base.query";
|
|
3
|
+
const StoreQueryByProximitySchema = BaseQuerySchema.extend({
|
|
4
|
+
longitude: z.number().default(0),
|
|
5
|
+
latitude: z.number().default(0),
|
|
6
|
+
distance: z.number().default(0),
|
|
7
|
+
limit: z.number().default(10)
|
|
8
|
+
});
|
|
9
|
+
export {
|
|
10
|
+
StoreQueryByProximitySchema
|
|
11
|
+
};
|