@reactionary/fake 0.9.0 → 0.9.2
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/capabilities/feature-flag.capability.js +50 -0
- package/capabilities/index.js +2 -0
- package/capabilities/personalization-profile.capability.js +88 -0
- package/core/initialize.js +27 -1
- package/factories/feature-flag/feature-flag.factory.js +12 -0
- package/factories/index.js +2 -0
- package/factories/personalization-profile/personalization-profile.factory.js +12 -0
- package/package.json +2 -2
- package/schema/capabilities.schema.js +6 -2
- package/schema/configuration.schema.js +20 -1
- package/src/capabilities/feature-flag.capability.d.ts +12 -0
- package/src/capabilities/index.d.ts +2 -0
- package/src/capabilities/personalization-profile.capability.d.ts +10 -0
- package/src/core/initialize.types.d.ts +11 -1
- package/src/factories/feature-flag/feature-flag.factory.d.ts +7 -0
- package/src/factories/index.d.ts +2 -0
- package/src/factories/personalization-profile/personalization-profile.factory.d.ts +7 -0
- package/src/schema/capabilities.schema.d.ts +15 -1
- package/src/schema/configuration.schema.d.ts +24 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FeatureFlagCapability,
|
|
3
|
+
success
|
|
4
|
+
} from "@reactionary/core";
|
|
5
|
+
class FakeFeatureFlagCapability extends FeatureFlagCapability {
|
|
6
|
+
config;
|
|
7
|
+
factory;
|
|
8
|
+
flagDefinitions;
|
|
9
|
+
constructor(config, cache, context, factory) {
|
|
10
|
+
super(cache, context);
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.factory = factory;
|
|
13
|
+
this.flagDefinitions = new Map(config.featureFlags?.flags.map((f) => [f.key, f]) ?? []);
|
|
14
|
+
}
|
|
15
|
+
async getFlags(payload) {
|
|
16
|
+
const flags = payload.featureFlagIdentifiers.map((id) => {
|
|
17
|
+
const raw = this.evaluateFlag(id.key);
|
|
18
|
+
return this.factory.parseFeatureFlag(this.context, raw);
|
|
19
|
+
});
|
|
20
|
+
return success(flags);
|
|
21
|
+
}
|
|
22
|
+
evaluateFlag(key) {
|
|
23
|
+
const definition = this.flagDefinitions.get(key);
|
|
24
|
+
if (!definition) {
|
|
25
|
+
return {
|
|
26
|
+
identifier: { key },
|
|
27
|
+
type: "boolean",
|
|
28
|
+
enabled: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (definition.type === "boolean") {
|
|
32
|
+
return {
|
|
33
|
+
identifier: { key },
|
|
34
|
+
type: "boolean",
|
|
35
|
+
enabled: definition.enabled
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
identifier: { key },
|
|
40
|
+
type: "multivariate",
|
|
41
|
+
variants: definition.variants.map((name) => ({
|
|
42
|
+
name,
|
|
43
|
+
enabled: name === definition.enabledVariant
|
|
44
|
+
}))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
FakeFeatureFlagCapability
|
|
50
|
+
};
|
package/capabilities/index.js
CHANGED
|
@@ -2,8 +2,10 @@ export * from "./analytics.capability.js";
|
|
|
2
2
|
export * from "./cart.capability.js";
|
|
3
3
|
export * from "./category.capability.js";
|
|
4
4
|
export * from "./checkout.capability.js";
|
|
5
|
+
export * from "./feature-flag.capability.js";
|
|
5
6
|
export * from "./identity.capability.js";
|
|
6
7
|
export * from "./inventory.capability.js";
|
|
8
|
+
export * from "./personalization-profile.capability.js";
|
|
7
9
|
export * from "./order-search.capability.js";
|
|
8
10
|
export * from "./order.capability.js";
|
|
9
11
|
export * from "./price.capability.js";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
PersonalizationProfileCapability,
|
|
14
|
+
PersonalizationProfileQueryGetProfileSchema,
|
|
15
|
+
PersonalizationProfileSchema,
|
|
16
|
+
Reactionary,
|
|
17
|
+
success
|
|
18
|
+
} from "@reactionary/core";
|
|
19
|
+
import { calcSeed } from "../utilities/seed.js";
|
|
20
|
+
const SEGMENTS = ["Big Spender", "Tech Head", "Newbie", "Gift Giver"];
|
|
21
|
+
const BLURBS = [
|
|
22
|
+
"Loves hiking and outdoor gear but dislikes crowded malls and slow shipping times on weekend orders",
|
|
23
|
+
"Enjoys premium coffee and artisan food products while avoiding mass-produced snacks and cheap packaging materials",
|
|
24
|
+
"Passionate about smart home gadgets and wireless tech but frustrated by complicated setup processes and poor documentation",
|
|
25
|
+
"Prefers sustainable and eco-friendly brands over fast fashion and tends to research products thoroughly before buying",
|
|
26
|
+
"Avid reader who collects rare editions and dislikes digital-only content preferring tactile experiences with real pages",
|
|
27
|
+
"Fitness enthusiast who tracks every metric and avoids sugary supplements preferring clean ingredients and minimal branding",
|
|
28
|
+
"Enjoys cooking exotic cuisines at home and dislikes pre-packaged meal kits that lack authentic spices and herbs",
|
|
29
|
+
"Tech-savvy parent who values educational toys and screen-free activities but dislikes overly gendered product marketing campaigns"
|
|
30
|
+
];
|
|
31
|
+
class FakePersonalizationProfileCapability extends PersonalizationProfileCapability {
|
|
32
|
+
config;
|
|
33
|
+
factory;
|
|
34
|
+
constructor(config, cache, context, factory) {
|
|
35
|
+
super(cache, context);
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.factory = factory;
|
|
38
|
+
}
|
|
39
|
+
async getPersonalizationProfile(payload) {
|
|
40
|
+
const identity = payload.identity;
|
|
41
|
+
if (identity.type === "Registered") {
|
|
42
|
+
const userId = identity.id.userId;
|
|
43
|
+
const seed = calcSeed(userId);
|
|
44
|
+
const profileKey = hashToHex(seed);
|
|
45
|
+
const segmentCount = 2 + Math.abs(seed) % 3;
|
|
46
|
+
const segments = pickDeterministic(SEGMENTS, segmentCount, seed);
|
|
47
|
+
const blurbIdx = Math.abs(seed) % BLURBS.length;
|
|
48
|
+
const blurb = BLURBS[blurbIdx];
|
|
49
|
+
return success(this.factory.parsePersonalizationProfile(this.context, {
|
|
50
|
+
identifier: { key: profileKey },
|
|
51
|
+
segments,
|
|
52
|
+
blurb
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
const anonSeed = calcSeed(Date.now().toString() + Math.random().toString());
|
|
56
|
+
const anonKey = hashToHex(anonSeed);
|
|
57
|
+
return success(this.factory.parsePersonalizationProfile(this.context, {
|
|
58
|
+
identifier: { key: anonKey },
|
|
59
|
+
segments: [],
|
|
60
|
+
blurb: ""
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
__decorateClass([
|
|
65
|
+
Reactionary({
|
|
66
|
+
inputSchema: PersonalizationProfileQueryGetProfileSchema,
|
|
67
|
+
outputSchema: PersonalizationProfileSchema
|
|
68
|
+
})
|
|
69
|
+
], FakePersonalizationProfileCapability.prototype, "getPersonalizationProfile", 1);
|
|
70
|
+
function hashToHex(seed) {
|
|
71
|
+
const abs = Math.abs(seed) >>> 0;
|
|
72
|
+
return abs.toString(16).padStart(8, "0");
|
|
73
|
+
}
|
|
74
|
+
function pickDeterministic(items, count, seed) {
|
|
75
|
+
const picked = [];
|
|
76
|
+
const available = [...items];
|
|
77
|
+
let s = Math.abs(seed);
|
|
78
|
+
for (let i = 0; i < count && available.length > 0; i++) {
|
|
79
|
+
const idx = s % available.length;
|
|
80
|
+
picked.push(available[idx]);
|
|
81
|
+
available.splice(idx, 1);
|
|
82
|
+
s = Math.abs(calcSeed(s.toString()));
|
|
83
|
+
}
|
|
84
|
+
return picked;
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
FakePersonalizationProfileCapability
|
|
88
|
+
};
|
package/core/initialize.js
CHANGED
|
@@ -19,7 +19,9 @@ import {
|
|
|
19
19
|
ProductSearchResultSchema as CoreProductSearchResultSchema,
|
|
20
20
|
ProfileSchema as CoreProfileSchema,
|
|
21
21
|
ShippingMethodSchema as CoreShippingMethodSchema,
|
|
22
|
-
StoreSchema as CoreStoreSchema
|
|
22
|
+
StoreSchema as CoreStoreSchema,
|
|
23
|
+
FeatureFlagSchema as CoreFeatureFlagSchema,
|
|
24
|
+
PersonalizationProfileSchema as CorePersonalizationProfileSchema
|
|
23
25
|
} from "@reactionary/core";
|
|
24
26
|
import { FakeProductCapability } from "../capabilities/product.capability.js";
|
|
25
27
|
import { FakeProductSearchCapability } from "../capabilities/product-search.capability.js";
|
|
@@ -38,12 +40,16 @@ import { FakeOrderCapability } from "../capabilities/order.capability.js";
|
|
|
38
40
|
import { FakeProfileCapability } from "../capabilities/profile.capability.js";
|
|
39
41
|
import { FakeProductReviewsCapability } from "../capabilities/product-reviews.capability.js";
|
|
40
42
|
import { FakeProductAssociationsCapability } from "../capabilities/product-associations.capability.js";
|
|
43
|
+
import { FakeFeatureFlagCapability } from "../capabilities/feature-flag.capability.js";
|
|
44
|
+
import { FakePersonalizationProfileCapability } from "../capabilities/personalization-profile.capability.js";
|
|
41
45
|
import {
|
|
42
46
|
FakeCartFactory,
|
|
43
47
|
FakeCategoryFactory,
|
|
44
48
|
FakeCheckoutFactory,
|
|
49
|
+
FakeFeatureFlagFactory,
|
|
45
50
|
FakeIdentityFactory,
|
|
46
51
|
FakeInventoryFactory,
|
|
52
|
+
FakePersonalizationProfileFactory,
|
|
47
53
|
FakeOrderFactory,
|
|
48
54
|
FakeOrderSearchFactory,
|
|
49
55
|
FakePriceFactory,
|
|
@@ -232,6 +238,26 @@ function withFakeCapabilities(configuration, capabilities) {
|
|
|
232
238
|
buildCapabilityArgs
|
|
233
239
|
);
|
|
234
240
|
}
|
|
241
|
+
if (caps.featureFlag?.enabled) {
|
|
242
|
+
client.featureFlag = resolveCapabilityWithFactory(
|
|
243
|
+
capabilities.featureFlag,
|
|
244
|
+
{
|
|
245
|
+
factory: new FakeFeatureFlagFactory(CoreFeatureFlagSchema),
|
|
246
|
+
capability: (args) => new FakeFeatureFlagCapability(args.config, args.cache, args.context, args.factory)
|
|
247
|
+
},
|
|
248
|
+
buildCapabilityArgs
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
if (caps.personalizationProfile?.enabled) {
|
|
252
|
+
client.personalizationProfile = resolveCapabilityWithFactory(
|
|
253
|
+
capabilities.personalizationProfile,
|
|
254
|
+
{
|
|
255
|
+
factory: new FakePersonalizationProfileFactory(CorePersonalizationProfileSchema),
|
|
256
|
+
capability: (args) => new FakePersonalizationProfileCapability(args.config, args.cache, args.context, args.factory)
|
|
257
|
+
},
|
|
258
|
+
buildCapabilityArgs
|
|
259
|
+
);
|
|
260
|
+
}
|
|
235
261
|
return client;
|
|
236
262
|
};
|
|
237
263
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class FakeFeatureFlagFactory {
|
|
2
|
+
featureFlagSchema;
|
|
3
|
+
constructor(featureFlagSchema) {
|
|
4
|
+
this.featureFlagSchema = featureFlagSchema;
|
|
5
|
+
}
|
|
6
|
+
parseFeatureFlag(_context, data) {
|
|
7
|
+
return this.featureFlagSchema.parse(data);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
FakeFeatureFlagFactory
|
|
12
|
+
};
|
package/factories/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from "./cart/cart.factory.js";
|
|
2
2
|
export * from "./category/category.factory.js";
|
|
3
3
|
export * from "./checkout/checkout.factory.js";
|
|
4
|
+
export * from "./feature-flag/feature-flag.factory.js";
|
|
4
5
|
export * from "./identity/identity.factory.js";
|
|
5
6
|
export * from "./inventory/inventory.factory.js";
|
|
7
|
+
export * from "./personalization-profile/personalization-profile.factory.js";
|
|
6
8
|
export * from "./order-search/order-search.factory.js";
|
|
7
9
|
export * from "./order/order.factory.js";
|
|
8
10
|
export * from "./price/price.factory.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class FakePersonalizationProfileFactory {
|
|
2
|
+
personalizationProfileSchema;
|
|
3
|
+
constructor(personalizationProfileSchema) {
|
|
4
|
+
this.personalizationProfileSchema = personalizationProfileSchema;
|
|
5
|
+
}
|
|
6
|
+
parsePersonalizationProfile(_context, data) {
|
|
7
|
+
return this.personalizationProfileSchema.parse(data);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
FakePersonalizationProfileFactory
|
|
12
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/fake",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"vitest": "^4.0.9",
|
|
9
9
|
"@nx/vite": "22.4.5",
|
|
10
|
-
"@reactionary/core": "0.9.
|
|
10
|
+
"@reactionary/core": "0.9.2",
|
|
11
11
|
"zod": "4.1.9",
|
|
12
12
|
"@faker-js/faker": "^9.8.0"
|
|
13
13
|
},
|
|
@@ -19,7 +19,9 @@ const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
|
19
19
|
orderSearch: true,
|
|
20
20
|
profile: true,
|
|
21
21
|
productReviews: true,
|
|
22
|
-
productAssociations: true
|
|
22
|
+
productAssociations: true,
|
|
23
|
+
featureFlag: true,
|
|
24
|
+
personalizationProfile: true
|
|
23
25
|
}).extend({
|
|
24
26
|
product: OverridableCapabilitySchema.optional(),
|
|
25
27
|
productSearch: OverridableCapabilitySchema.optional(),
|
|
@@ -34,7 +36,9 @@ const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
|
34
36
|
orderSearch: OverridableCapabilitySchema.optional(),
|
|
35
37
|
profile: OverridableCapabilitySchema.optional(),
|
|
36
38
|
productReviews: OverridableCapabilitySchema.optional(),
|
|
37
|
-
productAssociations: OverridableCapabilitySchema.optional()
|
|
39
|
+
productAssociations: OverridableCapabilitySchema.optional(),
|
|
40
|
+
featureFlag: OverridableCapabilitySchema.optional(),
|
|
41
|
+
personalizationProfile: OverridableCapabilitySchema.optional()
|
|
38
42
|
}).partial();
|
|
39
43
|
export {
|
|
40
44
|
FakeCapabilitiesSchema
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
+
const BooleanFeatureFlagDefinitionSchema = z.looseObject({
|
|
3
|
+
key: z.string(),
|
|
4
|
+
type: z.literal("boolean"),
|
|
5
|
+
enabled: z.boolean()
|
|
6
|
+
});
|
|
7
|
+
const MultivariateFeatureFlagDefinitionSchema = z.looseObject({
|
|
8
|
+
key: z.string(),
|
|
9
|
+
type: z.literal("multivariate"),
|
|
10
|
+
variants: z.array(z.string()),
|
|
11
|
+
enabledVariant: z.string()
|
|
12
|
+
});
|
|
13
|
+
const FakeFeatureFlagDefinitionSchema = z.discriminatedUnion("type", [
|
|
14
|
+
BooleanFeatureFlagDefinitionSchema,
|
|
15
|
+
MultivariateFeatureFlagDefinitionSchema
|
|
16
|
+
]);
|
|
17
|
+
const FakeConfigurationFeatureFlagsSchema = z.looseObject({
|
|
18
|
+
flags: z.array(FakeFeatureFlagDefinitionSchema).default([])
|
|
19
|
+
});
|
|
2
20
|
const FakeConfigurationSchema = z.looseObject({
|
|
3
21
|
jitter: z.looseObject({
|
|
4
22
|
mean: z.number().min(0).max(1e4),
|
|
@@ -11,7 +29,8 @@ const FakeConfigurationSchema = z.looseObject({
|
|
|
11
29
|
product: z.number().min(0).max(1e4).default(1),
|
|
12
30
|
search: z.number().min(0).max(1e4).default(1),
|
|
13
31
|
category: z.number().min(0).max(1e4).default(1)
|
|
14
|
-
})
|
|
32
|
+
}),
|
|
33
|
+
featureFlags: FakeConfigurationFeatureFlagsSchema.optional()
|
|
15
34
|
});
|
|
16
35
|
export {
|
|
17
36
|
FakeConfigurationSchema
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Cache, FeatureFlagFactory, FeatureFlagFactoryOutput, FeatureFlagFactoryWithOutput, FeatureFlagQueryGetFlags, RequestContext, Result } from '@reactionary/core';
|
|
2
|
+
import { FeatureFlagCapability } from '@reactionary/core';
|
|
3
|
+
import type { FakeConfiguration, FakeFeatureFlagDefinition } from '../schema/configuration.schema.js';
|
|
4
|
+
import type { FakeFeatureFlagFactory } from '../factories/feature-flag/feature-flag.factory.js';
|
|
5
|
+
export declare class FakeFeatureFlagCapability<TFactory extends FeatureFlagFactory = FakeFeatureFlagFactory> extends FeatureFlagCapability<FeatureFlagFactoryOutput<TFactory>> {
|
|
6
|
+
protected config: FakeConfiguration;
|
|
7
|
+
protected factory: FeatureFlagFactoryWithOutput<TFactory>;
|
|
8
|
+
protected flagDefinitions: Map<string, FakeFeatureFlagDefinition>;
|
|
9
|
+
constructor(config: FakeConfiguration, cache: Cache, context: RequestContext, factory: FeatureFlagFactoryWithOutput<TFactory>);
|
|
10
|
+
getFlags(payload: FeatureFlagQueryGetFlags): Promise<Result<FeatureFlagFactoryOutput<TFactory>[]>>;
|
|
11
|
+
private evaluateFlag;
|
|
12
|
+
}
|
|
@@ -2,8 +2,10 @@ export * from './analytics.capability.js';
|
|
|
2
2
|
export * from './cart.capability.js';
|
|
3
3
|
export * from './category.capability.js';
|
|
4
4
|
export * from './checkout.capability.js';
|
|
5
|
+
export * from './feature-flag.capability.js';
|
|
5
6
|
export * from './identity.capability.js';
|
|
6
7
|
export * from './inventory.capability.js';
|
|
8
|
+
export * from './personalization-profile.capability.js';
|
|
7
9
|
export * from './order-search.capability.js';
|
|
8
10
|
export * from './order.capability.js';
|
|
9
11
|
export * from './price.capability.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Cache, PersonalizationProfileFactory, PersonalizationProfileFactoryOutput, PersonalizationProfileFactoryWithOutput, PersonalizationProfileQueryGetProfile, NotFoundError, RequestContext, Result } from '@reactionary/core';
|
|
2
|
+
import { PersonalizationProfileCapability } from '@reactionary/core';
|
|
3
|
+
import type { FakeConfiguration } from '../schema/configuration.schema.js';
|
|
4
|
+
import type { FakePersonalizationProfileFactory } from '../factories/personalization-profile/personalization-profile.factory.js';
|
|
5
|
+
export declare class FakePersonalizationProfileCapability<TFactory extends PersonalizationProfileFactory = FakePersonalizationProfileFactory> extends PersonalizationProfileCapability<PersonalizationProfileFactoryOutput<TFactory>> {
|
|
6
|
+
protected config: FakeConfiguration;
|
|
7
|
+
protected factory: PersonalizationProfileFactoryWithOutput<TFactory>;
|
|
8
|
+
constructor(config: FakeConfiguration, cache: Cache, context: RequestContext, factory: PersonalizationProfileFactoryWithOutput<TFactory>);
|
|
9
|
+
getPersonalizationProfile(payload: PersonalizationProfileQueryGetProfile): Promise<Result<PersonalizationProfileFactoryOutput<TFactory>, NotFoundError>>;
|
|
10
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CartFactory, CategoryFactory, CheckoutFactory, ClientFromCapabilities, IdentityFactory, InventoryFactory, OrderFactory, OrderSearchFactory, PriceFactory, ProductAssociationsFactory, ProductFactory, ProductReviewsFactory, ProductSearchFactory, ProfileFactory, StoreFactory } from '@reactionary/core';
|
|
1
|
+
import type { CartFactory, CategoryFactory, CheckoutFactory, ClientFromCapabilities, FeatureFlagFactory, IdentityFactory, InventoryFactory, PersonalizationProfileFactory, OrderFactory, OrderSearchFactory, PriceFactory, ProductAssociationsFactory, ProductFactory, ProductReviewsFactory, ProductSearchFactory, ProfileFactory, StoreFactory } from '@reactionary/core';
|
|
2
2
|
import type { FakeCapabilities } from '../schema/capabilities.schema.js';
|
|
3
3
|
import type { FakeCartFactory } from '../factories/cart/cart.factory.js';
|
|
4
4
|
import type { FakeCategoryFactory } from '../factories/category/category.factory.js';
|
|
@@ -14,6 +14,8 @@ import type { FakeProductReviewsFactory } from '../factories/product-reviews/pro
|
|
|
14
14
|
import type { FakeProductSearchFactory } from '../factories/product-search/product-search.factory.js';
|
|
15
15
|
import type { FakeProfileFactory } from '../factories/profile/profile.factory.js';
|
|
16
16
|
import type { FakeStoreFactory } from '../factories/store/store.factory.js';
|
|
17
|
+
import type { FakeFeatureFlagFactory } from '../factories/feature-flag/feature-flag.factory.js';
|
|
18
|
+
import type { FakePersonalizationProfileFactory } from '../factories/personalization-profile/personalization-profile.factory.js';
|
|
17
19
|
import type { FakeCartCapability } from '../capabilities/cart.capability.js';
|
|
18
20
|
import type { FakeCategoryCapability } from '../capabilities/category.capability.js';
|
|
19
21
|
import type { FakeCheckoutCapability } from '../capabilities/checkout.capability.js';
|
|
@@ -28,6 +30,8 @@ import type { FakeProductReviewsCapability } from '../capabilities/product-revie
|
|
|
28
30
|
import type { FakeProductSearchCapability } from '../capabilities/product-search.capability.js';
|
|
29
31
|
import type { FakeProfileCapability } from '../capabilities/profile.capability.js';
|
|
30
32
|
import type { FakeStoreCapability } from '../capabilities/store.capability.js';
|
|
33
|
+
import type { FakeFeatureFlagCapability } from '../capabilities/feature-flag.capability.js';
|
|
34
|
+
import type { FakePersonalizationProfileCapability } from '../capabilities/personalization-profile.capability.js';
|
|
31
35
|
type FakeCapabilityKey = keyof FakeCapabilities;
|
|
32
36
|
type EnabledCapability<TCapability> = TCapability extends {
|
|
33
37
|
enabled: true;
|
|
@@ -58,6 +62,8 @@ type FactoryContractMap = {
|
|
|
58
62
|
profile: ProfileFactory;
|
|
59
63
|
productReviews: ProductReviewsFactory;
|
|
60
64
|
productAssociations: ProductAssociationsFactory;
|
|
65
|
+
featureFlag: FeatureFlagFactory;
|
|
66
|
+
personalizationProfile: PersonalizationProfileFactory;
|
|
61
67
|
};
|
|
62
68
|
type DefaultFactoryMap = {
|
|
63
69
|
product: FakeProductFactory;
|
|
@@ -74,6 +80,8 @@ type DefaultFactoryMap = {
|
|
|
74
80
|
profile: FakeProfileFactory;
|
|
75
81
|
productReviews: FakeProductReviewsFactory;
|
|
76
82
|
productAssociations: FakeProductAssociationsFactory;
|
|
83
|
+
featureFlag: FakeFeatureFlagFactory;
|
|
84
|
+
personalizationProfile: FakePersonalizationProfileFactory;
|
|
77
85
|
};
|
|
78
86
|
type ResolvedFactoryMap<T extends FakeCapabilities> = {
|
|
79
87
|
[K in FakeCapabilityKey]: ExtractCapabilityFactory<T[K], FactoryContractMap[K], DefaultFactoryMap[K]>;
|
|
@@ -93,6 +101,8 @@ type DefaultCapabilityMap<T extends FakeCapabilities> = {
|
|
|
93
101
|
profile: FakeProfileCapability<ResolvedFactoryMap<T>['profile']>;
|
|
94
102
|
productReviews: FakeProductReviewsCapability<ResolvedFactoryMap<T>['productReviews']>;
|
|
95
103
|
productAssociations: FakeProductAssociationsCapability<ResolvedFactoryMap<T>['productAssociations']>;
|
|
104
|
+
featureFlag: FakeFeatureFlagCapability<ResolvedFactoryMap<T>['featureFlag']>;
|
|
105
|
+
personalizationProfile: FakePersonalizationProfileCapability<ResolvedFactoryMap<T>['personalizationProfile']>;
|
|
96
106
|
};
|
|
97
107
|
type CapabilityImplementationMap<T extends FakeCapabilities> = {
|
|
98
108
|
[K in FakeCapabilityKey]: ExtractCapabilityImplementation<T[K], DefaultCapabilityMap<T>[K]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyFeatureFlagSchema, FeatureFlagFactory, FeatureFlagSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakeFeatureFlagFactory<TFeatureFlagSchema extends AnyFeatureFlagSchema = typeof FeatureFlagSchema> implements FeatureFlagFactory<TFeatureFlagSchema> {
|
|
4
|
+
readonly featureFlagSchema: TFeatureFlagSchema;
|
|
5
|
+
constructor(featureFlagSchema: TFeatureFlagSchema);
|
|
6
|
+
parseFeatureFlag(_context: RequestContext, data: unknown): z.output<TFeatureFlagSchema>;
|
|
7
|
+
}
|
package/src/factories/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './cart/cart.factory.js';
|
|
2
2
|
export * from './category/category.factory.js';
|
|
3
3
|
export * from './checkout/checkout.factory.js';
|
|
4
|
+
export * from './feature-flag/feature-flag.factory.js';
|
|
4
5
|
export * from './identity/identity.factory.js';
|
|
5
6
|
export * from './inventory/inventory.factory.js';
|
|
7
|
+
export * from './personalization-profile/personalization-profile.factory.js';
|
|
6
8
|
export * from './order-search/order-search.factory.js';
|
|
7
9
|
export * from './order/order.factory.js';
|
|
8
10
|
export * from './price/price.factory.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyPersonalizationProfileSchema, PersonalizationProfileFactory, PersonalizationProfileSchema, RequestContext } from '@reactionary/core';
|
|
2
|
+
import type * as z from 'zod';
|
|
3
|
+
export declare class FakePersonalizationProfileFactory<TPersonalizationProfileSchema extends AnyPersonalizationProfileSchema = typeof PersonalizationProfileSchema> implements PersonalizationProfileFactory<TPersonalizationProfileSchema> {
|
|
4
|
+
readonly personalizationProfileSchema: TPersonalizationProfileSchema;
|
|
5
|
+
constructor(personalizationProfileSchema: TPersonalizationProfileSchema);
|
|
6
|
+
parsePersonalizationProfile(_context: RequestContext, data: unknown): z.output<TPersonalizationProfileSchema>;
|
|
7
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Cache, CartFactory, CartFactoryWithOutput, CartCapability, CategoryFactory, CategoryFactoryWithOutput, CategoryCapability, CheckoutFactory, CheckoutFactoryWithOutput, CheckoutCapability, IdentityFactory, IdentityFactoryWithOutput, IdentityCapability, InventoryFactory, InventoryFactoryWithOutput, InventoryCapability, OrderFactory, OrderFactoryWithOutput, OrderCapability, OrderSearchFactory, OrderSearchFactoryWithOutput, OrderSearchCapability, PriceFactory, PriceFactoryWithOutput, PriceCapability, ProductAssociationsFactory, ProductAssociationsFactoryWithOutput, ProductAssociationsCapability, ProductFactory, ProductFactoryWithOutput, ProductCapability, ProductReviewsFactory, ProductReviewsFactoryWithOutput, ProductReviewsCapability, ProductSearchFactory, ProductSearchFactoryWithOutput, ProductSearchCapability, ProfileFactory, ProfileFactoryWithOutput, ProfileCapability, RequestContext, StoreFactory, StoreFactoryWithOutput, StoreCapability } from '@reactionary/core';
|
|
1
|
+
import type { Cache, CartFactory, CartFactoryWithOutput, CartCapability, CategoryFactory, CategoryFactoryWithOutput, CategoryCapability, CheckoutFactory, CheckoutFactoryWithOutput, CheckoutCapability, FeatureFlagFactory, FeatureFlagFactoryWithOutput, FeatureFlagCapability, IdentityFactory, IdentityFactoryWithOutput, IdentityCapability, InventoryFactory, InventoryFactoryWithOutput, InventoryCapability, PersonalizationProfileFactory, PersonalizationProfileFactoryWithOutput, PersonalizationProfileCapability, OrderFactory, OrderFactoryWithOutput, OrderCapability, OrderSearchFactory, OrderSearchFactoryWithOutput, OrderSearchCapability, PriceFactory, PriceFactoryWithOutput, PriceCapability, ProductAssociationsFactory, ProductAssociationsFactoryWithOutput, ProductAssociationsCapability, ProductFactory, ProductFactoryWithOutput, ProductCapability, ProductReviewsFactory, ProductReviewsFactoryWithOutput, ProductReviewsCapability, ProductSearchFactory, ProductSearchFactoryWithOutput, ProductSearchCapability, ProfileFactory, ProfileFactoryWithOutput, ProfileCapability, RequestContext, StoreFactory, StoreFactoryWithOutput, StoreCapability } from '@reactionary/core';
|
|
2
2
|
import type { FakeConfiguration } from './configuration.schema.js';
|
|
3
3
|
import * as z from 'zod';
|
|
4
4
|
export declare const FakeCapabilitiesSchema: z.ZodObject<{
|
|
@@ -72,6 +72,16 @@ export declare const FakeCapabilitiesSchema: z.ZodObject<{
|
|
|
72
72
|
factory: z.ZodOptional<z.ZodUnknown>;
|
|
73
73
|
capability: z.ZodOptional<z.ZodUnknown>;
|
|
74
74
|
}, z.core.$loose>>>;
|
|
75
|
+
featureFlag: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
76
|
+
enabled: z.ZodBoolean;
|
|
77
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
78
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
79
|
+
}, z.core.$loose>>>;
|
|
80
|
+
personalizationProfile: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
81
|
+
enabled: z.ZodBoolean;
|
|
82
|
+
factory: z.ZodOptional<z.ZodUnknown>;
|
|
83
|
+
capability: z.ZodOptional<z.ZodUnknown>;
|
|
84
|
+
}, z.core.$loose>>>;
|
|
75
85
|
}, z.core.$loose>;
|
|
76
86
|
export interface FakeCapabilityFactoryArgs<TFactory> {
|
|
77
87
|
cache: Cache;
|
|
@@ -98,6 +108,8 @@ export type FakeOrderSearchCapabilityConfig = FakeCapabilityConfig<OrderSearchFa
|
|
|
98
108
|
export type FakeProfileCapabilityConfig = FakeCapabilityConfig<ProfileFactoryWithOutput<ProfileFactory>, ProfileCapability>;
|
|
99
109
|
export type FakeProductReviewsCapabilityConfig = FakeCapabilityConfig<ProductReviewsFactoryWithOutput<ProductReviewsFactory>, ProductReviewsCapability>;
|
|
100
110
|
export type FakeProductAssociationsCapabilityConfig = FakeCapabilityConfig<ProductAssociationsFactoryWithOutput<ProductAssociationsFactory>, ProductAssociationsCapability>;
|
|
111
|
+
export type FakeFeatureFlagCapabilityConfig = FakeCapabilityConfig<FeatureFlagFactoryWithOutput<FeatureFlagFactory>, FeatureFlagCapability>;
|
|
112
|
+
export type FakePersonalizationProfileCapabilityConfig = FakeCapabilityConfig<PersonalizationProfileFactoryWithOutput<PersonalizationProfileFactory>, PersonalizationProfileCapability>;
|
|
101
113
|
export type FakeCapabilities = {
|
|
102
114
|
product?: FakeProductCapabilityConfig;
|
|
103
115
|
productSearch?: FakeProductSearchCapabilityConfig;
|
|
@@ -113,5 +125,7 @@ export type FakeCapabilities = {
|
|
|
113
125
|
profile?: FakeProfileCapabilityConfig;
|
|
114
126
|
productReviews?: FakeProductReviewsCapabilityConfig;
|
|
115
127
|
productAssociations?: FakeProductAssociationsCapabilityConfig;
|
|
128
|
+
featureFlag?: FakeFeatureFlagCapabilityConfig;
|
|
129
|
+
personalizationProfile?: FakePersonalizationProfileCapabilityConfig;
|
|
116
130
|
};
|
|
117
131
|
export type ParsedFakeCapabilities = z.infer<typeof FakeCapabilitiesSchema>;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
+
declare const FakeFeatureFlagDefinitionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
key: z.ZodString;
|
|
4
|
+
type: z.ZodLiteral<"boolean">;
|
|
5
|
+
enabled: z.ZodBoolean;
|
|
6
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
7
|
+
key: z.ZodString;
|
|
8
|
+
type: z.ZodLiteral<"multivariate">;
|
|
9
|
+
variants: z.ZodArray<z.ZodString>;
|
|
10
|
+
enabledVariant: z.ZodString;
|
|
11
|
+
}, z.core.$loose>], "type">;
|
|
2
12
|
export declare const FakeConfigurationSchema: z.ZodObject<{
|
|
3
13
|
jitter: z.ZodDefault<z.ZodObject<{
|
|
4
14
|
mean: z.ZodNumber;
|
|
@@ -9,5 +19,19 @@ export declare const FakeConfigurationSchema: z.ZodObject<{
|
|
|
9
19
|
search: z.ZodDefault<z.ZodNumber>;
|
|
10
20
|
category: z.ZodDefault<z.ZodNumber>;
|
|
11
21
|
}, z.core.$loose>;
|
|
22
|
+
featureFlags: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
flags: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
24
|
+
key: z.ZodString;
|
|
25
|
+
type: z.ZodLiteral<"boolean">;
|
|
26
|
+
enabled: z.ZodBoolean;
|
|
27
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
28
|
+
key: z.ZodString;
|
|
29
|
+
type: z.ZodLiteral<"multivariate">;
|
|
30
|
+
variants: z.ZodArray<z.ZodString>;
|
|
31
|
+
enabledVariant: z.ZodString;
|
|
32
|
+
}, z.core.$loose>], "type">>>;
|
|
33
|
+
}, z.core.$loose>>;
|
|
12
34
|
}, z.core.$loose>;
|
|
13
35
|
export type FakeConfiguration = z.infer<typeof FakeConfigurationSchema>;
|
|
36
|
+
export type FakeFeatureFlagDefinition = z.infer<typeof FakeFeatureFlagDefinitionSchema>;
|
|
37
|
+
export {};
|