@reactionary/core 0.12.3 → 0.12.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.
- package/analytics/index.js +1 -0
- package/analytics/placed-order.js +15 -0
- package/capabilities/analytics.capability.js +4 -0
- package/package.json +1 -1
- package/schemas/mutations/analytics/events/commerce.mutation.js +3 -1
- package/src/analytics/index.d.ts +1 -0
- package/src/analytics/placed-order.d.ts +24 -0
- package/src/schemas/models/analytics/event.model.d.ts +6948 -2666
- package/src/schemas/mutations/analytics/events/commerce.mutation.d.ts +2143 -2
- package/src/schemas/mutations/analytics/events/index.d.ts +2143 -2
package/analytics/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function summarizePlacedOrder(payload) {
|
|
2
|
+
const { checkout, order } = payload;
|
|
3
|
+
const source = checkout ?? order;
|
|
4
|
+
if (!source) {
|
|
5
|
+
return void 0;
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
transactionId: order?.identifier.key ?? checkout?.resultingOrder?.key ?? source.identifier.key,
|
|
9
|
+
items: source.items,
|
|
10
|
+
price: source.price
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
summarizePlacedOrder
|
|
15
|
+
};
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
AnalyticsMutationProductSharedSchema,
|
|
51
51
|
AnalyticsMutationCustomSchema
|
|
52
52
|
} from "../schemas/index.js";
|
|
53
|
+
import { error } from "../schemas/result.js";
|
|
53
54
|
import { BaseCapability } from "./base.capability.js";
|
|
54
55
|
class AnalyticsCapability extends BaseCapability {
|
|
55
56
|
dispatcher;
|
|
@@ -126,6 +127,9 @@ class AnalyticsCapability extends BaseCapability {
|
|
|
126
127
|
return this.dispatcher.emit("payment-info-added", payload);
|
|
127
128
|
}
|
|
128
129
|
async orderPlaced(payload) {
|
|
130
|
+
if (!payload.checkout && !payload.order) {
|
|
131
|
+
return error({ type: "Generic", message: "orderPlaced needs a checkout (or the deprecated order)" });
|
|
132
|
+
}
|
|
129
133
|
return this.dispatcher.emit("order-placed", payload);
|
|
130
134
|
}
|
|
131
135
|
async quoteRequested(payload) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
import { AnalyticsCouponRejectionReasonSchema, AnalyticsStoreRefSchema } from "../../../models/analytics/event-parts.model.js";
|
|
3
3
|
import { CartItemSchema, CartSchema } from "../../../models/cart.model.js";
|
|
4
|
+
import { CheckoutSchema } from "../../../models/checkout.model.js";
|
|
4
5
|
import { CompanySchema } from "../../../models/company.model.js";
|
|
5
6
|
import { ProductVariantIdentifierSchema } from "../../../models/identifiers.model.js";
|
|
6
7
|
import { OrderSchema } from "../../../models/order.model.js";
|
|
@@ -50,7 +51,8 @@ const AnalyticsMutationPaymentInfoAddedSchema = AnalyticsEventMutationBaseSchema
|
|
|
50
51
|
paymentMethod: PaymentMethodSchema
|
|
51
52
|
});
|
|
52
53
|
const AnalyticsMutationOrderPlacedSchema = AnalyticsEventMutationBaseSchema.extend({
|
|
53
|
-
|
|
54
|
+
checkout: CheckoutSchema.optional().meta({ description: "The finalized checkout: what the customer placed. Preferred over order, as the order may not exist yet when the OMS is the order source. Either checkout or order is required." }),
|
|
55
|
+
order: OrderSchema.optional().meta({ description: "Deprecated: pass the checkout instead. Either checkout or order is required.", deprecated: true })
|
|
54
56
|
});
|
|
55
57
|
const AnalyticsMutationQuoteRequestedSchema = AnalyticsEventMutationBaseSchema.extend({
|
|
56
58
|
cart: CartSchema
|
package/src/analytics/index.d.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Checkout } from '../schemas/models/checkout.model.js';
|
|
2
|
+
import type { CostBreakDown, ItemCostBreakdown } from '../schemas/models/cost.model.js';
|
|
3
|
+
import type { ProductVariantIdentifier } from '../schemas/models/identifiers.model.js';
|
|
4
|
+
import type { Order } from '../schemas/models/order.model.js';
|
|
5
|
+
export interface PlacedOrderLine {
|
|
6
|
+
variant: ProductVariantIdentifier;
|
|
7
|
+
quantity: number;
|
|
8
|
+
price: ItemCostBreakdown;
|
|
9
|
+
}
|
|
10
|
+
/** What an analytics subscriber needs to report a purchase, whether it was given a checkout or an order. */
|
|
11
|
+
export interface PlacedOrderSummary {
|
|
12
|
+
/** The order key when it is known, otherwise the key of the checkout that created it. */
|
|
13
|
+
transactionId: string;
|
|
14
|
+
items: PlacedOrderLine[];
|
|
15
|
+
price: CostBreakDown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes an order-placed payload. The checkout is preferred, as it is what the customer placed; the order is
|
|
19
|
+
* the deprecated alternative. Returns undefined when the payload carries neither.
|
|
20
|
+
*/
|
|
21
|
+
export declare function summarizePlacedOrder(payload: {
|
|
22
|
+
checkout?: Checkout;
|
|
23
|
+
order?: Order;
|
|
24
|
+
}): PlacedOrderSummary | undefined;
|