@reactionary/core 0.9.2 → 0.9.4

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,7 +11,8 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  };
12
12
  import { BaseCapability } from "./base.capability.js";
13
13
  import {
14
- AnalyticsMutationSchema
14
+ AnalyticsMutationSchema,
15
+ AnalyticsResultSchema
15
16
  } from "../schemas/index.js";
16
17
  import { Reactionary } from "../decorators/reactionary.decorator.js";
17
18
  class AnalyticsCapability extends BaseCapability {
@@ -21,31 +22,63 @@ class AnalyticsCapability extends BaseCapability {
21
22
  async track(event) {
22
23
  switch (event.event) {
23
24
  case "product-summary-view":
24
- await this.processProductSummaryView(event);
25
- break;
25
+ return this.processProductSummaryView(event);
26
26
  case "product-summary-click":
27
- await this.processProductSummaryClick(event);
28
- break;
27
+ return this.processProductSummaryClick(event);
29
28
  case "product-details-view":
30
- await this.processProductDetailsView(event);
31
- break;
29
+ return this.processProductDetailsView(event);
32
30
  case "product-cart-add":
33
- await this.processProductAddToCart(event);
34
- break;
31
+ return this.processProductAddToCart(event);
35
32
  case "purchase":
36
- await this.processPurchase(event);
37
- break;
33
+ return this.processPurchase(event);
34
+ default:
35
+ return this.ignored();
38
36
  }
39
37
  }
40
38
  async processProductSummaryView(_event) {
39
+ return this.ignored();
41
40
  }
42
41
  async processProductSummaryClick(_event) {
42
+ return this.ignored();
43
43
  }
44
44
  async processProductDetailsView(_event) {
45
+ return this.ignored();
45
46
  }
46
47
  async processProductAddToCart(_event) {
48
+ return this.ignored();
47
49
  }
48
50
  async processPurchase(_event) {
51
+ return this.ignored();
52
+ }
53
+ accepted() {
54
+ return {
55
+ outcomes: [
56
+ {
57
+ provider: this.getResourceName(),
58
+ outcome: "accepted"
59
+ }
60
+ ]
61
+ };
62
+ }
63
+ ignored() {
64
+ return {
65
+ outcomes: [
66
+ {
67
+ provider: this.getResourceName(),
68
+ outcome: "ignored"
69
+ }
70
+ ]
71
+ };
72
+ }
73
+ rejected() {
74
+ return {
75
+ outcomes: [
76
+ {
77
+ provider: this.getResourceName(),
78
+ outcome: "rejected"
79
+ }
80
+ ]
81
+ };
49
82
  }
50
83
  }
51
84
  class MulticastAnalyticsCapability extends AnalyticsCapability {
@@ -55,14 +88,20 @@ class MulticastAnalyticsCapability extends AnalyticsCapability {
55
88
  this.capabilities = capabilities;
56
89
  }
57
90
  async track(event) {
91
+ const tracks = [];
58
92
  for (const capability of this.capabilities) {
59
- capability.track(event);
93
+ tracks.push(capability.track(event));
60
94
  }
95
+ const results = await Promise.all(tracks);
96
+ return {
97
+ outcomes: results.flatMap((result) => result.outcomes)
98
+ };
61
99
  }
62
100
  }
63
101
  __decorateClass([
64
102
  Reactionary({
65
- inputSchema: AnalyticsMutationSchema
103
+ inputSchema: AnalyticsMutationSchema,
104
+ outputSchema: AnalyticsResultSchema
66
105
  })
67
106
  ], MulticastAnalyticsCapability.prototype, "track", 1);
68
107
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
@@ -1,5 +1,17 @@
1
+ import * as z from "zod";
1
2
  import { BaseModelSchema } from "./base.model.js";
2
3
  const AnalyticsEventSchema = BaseModelSchema.extend({});
4
+ const AnalyticsOutcomeSchema = z.enum(["accepted", "ignored", "rejected"]);
5
+ const AnalyticsProviderOutcomeSchema = z.object({
6
+ provider: z.string(),
7
+ outcome: AnalyticsOutcomeSchema
8
+ });
9
+ const AnalyticsResultSchema = BaseModelSchema.extend({
10
+ outcomes: z.array(AnalyticsProviderOutcomeSchema)
11
+ });
3
12
  export {
4
- AnalyticsEventSchema
13
+ AnalyticsEventSchema,
14
+ AnalyticsOutcomeSchema,
15
+ AnalyticsProviderOutcomeSchema,
16
+ AnalyticsResultSchema
5
17
  };
@@ -1,18 +1,21 @@
1
1
  import type { RequestContext } from '../schemas/session.schema.js';
2
2
  import { BaseCapability } from './base.capability.js';
3
3
  import type { Cache } from '../cache/cache.interface.js';
4
- import { type AnalyticsMutation, type AnalyticsMutationProductAddToCartEvent, type AnalyticsMutationProductDetailsViewEvent, type AnalyticsMutationProductSummaryClickEvent, type AnalyticsMutationProductSummaryViewEvent, type AnalyticsMutationPurchaseEvent } from '../schemas/index.js';
4
+ import { type AnalyticsMutation, type AnalyticsMutationProductAddToCartEvent, type AnalyticsMutationProductDetailsViewEvent, type AnalyticsMutationProductSummaryClickEvent, type AnalyticsMutationProductSummaryViewEvent, type AnalyticsMutationPurchaseEvent, type AnalyticsResult } from '../schemas/index.js';
5
5
  export declare abstract class AnalyticsCapability extends BaseCapability {
6
6
  protected getResourceName(): string;
7
- track(event: AnalyticsMutation): Promise<void>;
8
- protected processProductSummaryView(_event: AnalyticsMutationProductSummaryViewEvent): Promise<void>;
9
- protected processProductSummaryClick(_event: AnalyticsMutationProductSummaryClickEvent): Promise<void>;
10
- protected processProductDetailsView(_event: AnalyticsMutationProductDetailsViewEvent): Promise<void>;
11
- protected processProductAddToCart(_event: AnalyticsMutationProductAddToCartEvent): Promise<void>;
12
- protected processPurchase(_event: AnalyticsMutationPurchaseEvent): Promise<void>;
7
+ track(event: AnalyticsMutation): Promise<AnalyticsResult>;
8
+ protected processProductSummaryView(_event: AnalyticsMutationProductSummaryViewEvent): Promise<AnalyticsResult>;
9
+ protected processProductSummaryClick(_event: AnalyticsMutationProductSummaryClickEvent): Promise<AnalyticsResult>;
10
+ protected processProductDetailsView(_event: AnalyticsMutationProductDetailsViewEvent): Promise<AnalyticsResult>;
11
+ protected processProductAddToCart(_event: AnalyticsMutationProductAddToCartEvent): Promise<AnalyticsResult>;
12
+ protected processPurchase(_event: AnalyticsMutationPurchaseEvent): Promise<AnalyticsResult>;
13
+ protected accepted(): AnalyticsResult;
14
+ protected ignored(): AnalyticsResult;
15
+ protected rejected(): AnalyticsResult;
13
16
  }
14
17
  export declare class MulticastAnalyticsCapability extends AnalyticsCapability {
15
18
  protected capabilities: Array<AnalyticsCapability>;
16
19
  constructor(cache: Cache, requestContext: RequestContext, capabilities: Array<AnalyticsCapability>);
17
- track(event: AnalyticsMutation): Promise<void>;
20
+ track(event: AnalyticsMutation): Promise<AnalyticsResult>;
18
21
  }
@@ -1,4 +1,28 @@
1
- import type * as z from 'zod';
1
+ import * as z from 'zod';
2
2
  import type { InferType } from '../../zod-utils.js';
3
3
  export declare const AnalyticsEventSchema: z.ZodObject<{}, z.core.$loose>;
4
+ export declare const AnalyticsOutcomeSchema: z.ZodEnum<{
5
+ accepted: "accepted";
6
+ ignored: "ignored";
7
+ rejected: "rejected";
8
+ }>;
9
+ export declare const AnalyticsProviderOutcomeSchema: z.ZodObject<{
10
+ provider: z.ZodString;
11
+ outcome: z.ZodEnum<{
12
+ accepted: "accepted";
13
+ ignored: "ignored";
14
+ rejected: "rejected";
15
+ }>;
16
+ }, z.core.$strip>;
17
+ export declare const AnalyticsResultSchema: z.ZodObject<{
18
+ outcomes: z.ZodArray<z.ZodObject<{
19
+ provider: z.ZodString;
20
+ outcome: z.ZodEnum<{
21
+ accepted: "accepted";
22
+ ignored: "ignored";
23
+ rejected: "rejected";
24
+ }>;
25
+ }, z.core.$strip>>;
26
+ }, z.core.$loose>;
4
27
  export type AnalyticsEvent = InferType<typeof AnalyticsEventSchema>;
28
+ export type AnalyticsResult = InferType<typeof AnalyticsResultSchema>;
@@ -11,10 +11,10 @@ export declare const EmployeeInvitationSchema: z.ZodObject<{
11
11
  taxIdentifier: z.ZodString;
12
12
  }, z.core.$loose>;
13
13
  status: z.ZodEnum<{
14
- invited: "invited";
15
14
  accepted: "accepted";
16
- revoked: "revoked";
17
15
  rejected: "rejected";
16
+ invited: "invited";
17
+ revoked: "revoked";
18
18
  }>;
19
19
  email: z.ZodEmail;
20
20
  role: z.ZodEnum<{
@@ -32,10 +32,10 @@ export declare const EmployeeIssuedInvitationSchema: z.ZodObject<{
32
32
  taxIdentifier: z.ZodString;
33
33
  }, z.core.$loose>;
34
34
  status: z.ZodEnum<{
35
- invited: "invited";
36
35
  accepted: "accepted";
37
- revoked: "revoked";
38
36
  rejected: "rejected";
37
+ invited: "invited";
38
+ revoked: "revoked";
39
39
  }>;
40
40
  email: z.ZodEmail;
41
41
  role: z.ZodEnum<{
@@ -59,10 +59,10 @@ export declare const EmployeeInvitationPaginatedListSchema: z.ZodObject<{
59
59
  taxIdentifier: z.ZodString;
60
60
  }, z.core.$loose>;
61
61
  status: z.ZodEnum<{
62
- invited: "invited";
63
62
  accepted: "accepted";
64
- revoked: "revoked";
65
63
  rejected: "rejected";
64
+ invited: "invited";
65
+ revoked: "revoked";
66
66
  }>;
67
67
  email: z.ZodEmail;
68
68
  role: z.ZodEnum<{
@@ -27,10 +27,10 @@ export declare const EmployeeRoleSchema: z.ZodEnum<{
27
27
  * Status of an employee invitation in the system. This can be used to determine if the invitation is active and allowed to perform certain actions, or if it is pending approval or blocked due to violations of terms of service or other issues.
28
28
  */
29
29
  export declare const EmployeeInvitationStatusSchema: z.ZodEnum<{
30
- invited: "invited";
31
30
  accepted: "accepted";
32
- revoked: "revoked";
33
31
  rejected: "rejected";
32
+ invited: "invited";
33
+ revoked: "revoked";
34
34
  }>;
35
35
  /**
36
36
  * Status of a company in the system. This can be used to determine if the company is active and allowed to perform certain actions, or if it is pending approval or blocked due to violations of terms of service or other issues.