@reactionary/core 0.10.52 → 0.10.53

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.
@@ -156,6 +156,20 @@ function Reactionary(options) {
156
156
  return descriptor;
157
157
  };
158
158
  }
159
+ function applyReactionary(capabilityClass, methodName, options) {
160
+ const target = capabilityClass.prototype;
161
+ const descriptor = Object.getOwnPropertyDescriptor(target, methodName);
162
+ if (!descriptor) {
163
+ throw new Error(
164
+ `applyReactionary: "${methodName}" is not declared on ${target.constructor.name} itself.`
165
+ );
166
+ }
167
+ Object.defineProperty(
168
+ target,
169
+ methodName,
170
+ Reactionary(options)(target, methodName, descriptor)
171
+ );
172
+ }
159
173
  function validateInput(input, schema) {
160
174
  if (!schema) {
161
175
  return success(input);
@@ -221,6 +235,7 @@ function errorToString(err) {
221
235
  export {
222
236
  Reactionary,
223
237
  ReactionaryDecoratorOptions,
238
+ applyReactionary,
224
239
  errorToString,
225
240
  getTracer,
226
241
  traceSpan,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.10.52",
3
+ "version": "0.10.53",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
@@ -15,6 +15,8 @@ const AddressSchema = BaseModelSchema.extend({
15
15
  const ProfileSchema = BaseModelSchema.extend({
16
16
  identifier: IdentityIdentifierSchema,
17
17
  email: z.email(),
18
+ firstName: z.string().optional(),
19
+ lastName: z.string().optional(),
18
20
  phone: z.string(),
19
21
  emailVerified: z.boolean(),
20
22
  phoneVerified: z.boolean(),
@@ -5,7 +5,9 @@ import { AddressSchema } from "../models/profile.model.js";
5
5
  const ProfileMutationUpdateSchema = BaseMutationSchema.extend({
6
6
  identifier: IdentityIdentifierSchema,
7
7
  email: z.email().meta({ description: "The main contact email of the profile" }),
8
- phone: z.string().meta({ description: "The main phone number of the profile" })
8
+ phone: z.string().meta({ description: "The main phone number of the profile" }),
9
+ firstName: z.string().optional().meta({ description: "The first name of the profile holder. Left unchanged when omitted" }),
10
+ lastName: z.string().optional().meta({ description: "The last name of the profile holder. Left unchanged when omitted" })
9
11
  });
10
12
  const ProfileMutationAddShippingAddressSchema = BaseMutationSchema.extend({
11
13
  identifier: IdentityIdentifierSchema,
@@ -52,6 +52,39 @@ export declare class ReactionaryDecoratorOptions {
52
52
  * capabilities.
53
53
  */
54
54
  export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseCapability, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
55
+ /**
56
+ * The names of the operations on a capability — its async, `Result`-returning
57
+ * methods — which are the only members `@Reactionary` is meant for.
58
+ */
59
+ export type ReactionaryOperationName<T> = {
60
+ [K in keyof T]-?: T[K] extends (...args: never[]) => Promise<Result<unknown>> ? K : never;
61
+ }[keyof T] & string;
62
+ /**
63
+ * Applies `@Reactionary` to a method without decorator syntax, for consumers
64
+ * that don't enable `experimentalDecorators`.
65
+ *
66
+ * `@Reactionary` wraps the concrete method it is declared on, so a subclass
67
+ * overriding a decorated operation silently loses tracing, metrics, input /
68
+ * output validation, caching and the conversion of thrown errors into a
69
+ * `Generic` error result. Call this once after the subclass declaration to
70
+ * restore them on the override:
71
+ *
72
+ * ```ts
73
+ * class MyProductCapability extends MagentoProductCapability {
74
+ * public override async getById(payload: ProductQueryById) { ... }
75
+ * }
76
+ * applyReactionary(MyProductCapability, 'getById', {
77
+ * inputSchema: ProductQueryByIdSchema,
78
+ * outputSchema: MyProductSchema,
79
+ * });
80
+ * ```
81
+ *
82
+ * It must be applied on the class that declares the override: if the method
83
+ * is only inherited by `capabilityClass`, an error is thrown.
84
+ */
85
+ export declare function applyReactionary<T extends BaseCapability>(capabilityClass: {
86
+ prototype: T;
87
+ }, methodName: ReactionaryOperationName<T>, options: Partial<ReactionaryDecoratorOptions>): void;
55
88
  /**
56
89
  * Utility function to handle input validation.
57
90
  */
@@ -18,6 +18,8 @@ export declare const ProfileSchema: z.ZodObject<{
18
18
  userId: z.ZodString;
19
19
  }, z.core.$loose>;
20
20
  email: z.ZodEmail;
21
+ firstName: z.ZodOptional<z.ZodString>;
22
+ lastName: z.ZodOptional<z.ZodString>;
21
23
  phone: z.ZodString;
22
24
  emailVerified: z.ZodBoolean;
23
25
  phoneVerified: z.ZodBoolean;
@@ -6,6 +6,8 @@ export declare const ProfileMutationUpdateSchema: z.ZodObject<{
6
6
  }, z.core.$loose>;
7
7
  email: z.ZodEmail;
8
8
  phone: z.ZodString;
9
+ firstName: z.ZodOptional<z.ZodString>;
10
+ lastName: z.ZodOptional<z.ZodString>;
9
11
  }, z.core.$loose>;
10
12
  export declare const ProfileMutationAddShippingAddressSchema: z.ZodObject<{
11
13
  identifier: z.ZodObject<{
@@ -18,6 +18,8 @@ export declare const PersonalizationProfileQueryGetProfileSchema: import("zod").
18
18
  userId: import("zod").ZodString;
19
19
  }, import("zod/v4/core").$loose>;
20
20
  email: import("zod").ZodEmail;
21
+ firstName: import("zod").ZodOptional<import("zod").ZodString>;
22
+ lastName: import("zod").ZodOptional<import("zod").ZodString>;
21
23
  phone: import("zod").ZodString;
22
24
  emailVerified: import("zod").ZodBoolean;
23
25
  phoneVerified: import("zod").ZodBoolean;