@replohq/sdk 1.22.0 → 2.0.0
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/_vendor/replo-utils/lib/json.mjs +4 -5
- package/_vendor/replo-utils/lib/misc.mjs +4 -3
- package/_vendor/replo-utils/lib/object.d.ts +16 -1
- package/_vendor/replo-utils/lib/object.mjs +3 -4
- package/_vendor/schemas/contentEntry.mjs +3 -3
- package/_vendor/schemas/contentManifest.mjs +6 -6
- package/_vendor/schemas/errors.d.ts +3 -43
- package/_vendor/schemas/{money.d.ts → moneyFormat.d.ts} +1 -8
- package/_vendor/schemas/{money.mjs → moneyFormat.mjs} +5 -16
- package/_vendor/schemas/reploError.d.ts +43 -0
- package/_vendor/schemas/routing/locale.mjs +6 -4
- package/_vendor/schemas/routing/rules.mjs +6 -4
- package/analytics/analytics-sink.d.ts +126 -14
- package/analytics/combine-sinks.js +36 -13
- package/analytics/hooks/use-product-viewed-analytics.d.ts +1 -17
- package/analytics/hooks/use-product-viewed-analytics.js +5 -14
- package/analytics/legacy-checkout.d.ts +2 -0
- package/analytics/legacy-checkout.js +26 -0
- package/analytics/sinks/converge-event-mapper.d.ts +10 -11
- package/analytics/sinks/converge-event-mapper.js +50 -133
- package/analytics/sinks/converge-sink.d.ts +8 -7
- package/analytics/sinks/converge-sink.js +21 -3
- package/analytics/sinks/elevar-sink.d.ts +9 -7
- package/analytics/sinks/elevar-sink.js +37 -128
- package/analytics/sinks/ga4-sink.d.ts +9 -8
- package/analytics/sinks/ga4-sink.js +9 -8
- package/analytics/sinks/intelligems-sink.d.ts +9 -8
- package/analytics/sinks/intelligems-sink.js +3 -1
- package/analytics/sinks/meta-sink.d.ts +5 -4
- package/analytics/sinks/meta-sink.js +7 -3
- package/analytics/sinks/northbeam-sink.d.ts +1 -0
- package/analytics/sinks/northbeam-sink.js +2 -0
- package/analytics/sinks/pinterest-sink.d.ts +7 -6
- package/analytics/sinks/pinterest-sink.js +14 -20
- package/analytics/sinks/reddit-sink.d.ts +8 -7
- package/analytics/sinks/reddit-sink.js +13 -20
- package/analytics/sinks/replo-sink.d.ts +21 -9
- package/analytics/sinks/replo-sink.js +37 -39
- package/analytics/sinks/snapchat-sink.d.ts +6 -5
- package/analytics/sinks/snapchat-sink.js +8 -8
- package/analytics/sinks/tiktok-sink.d.ts +8 -7
- package/analytics/sinks/tiktok-sink.js +10 -15
- package/analytics/sinks/window-sink.d.ts +11 -9
- package/analytics/sinks/window-sink.js +5 -1
- package/analytics/sinks/x-sink.d.ts +5 -4
- package/analytics/sinks/x-sink.js +19 -50
- package/analytics/test-fixtures.d.ts +5 -0
- package/analytics/test-fixtures.js +18 -0
- package/analytics/utils/analytics-products.d.ts +0 -30
- package/analytics/utils/analytics-products.js +1 -51
- package/analytics/utils/collection-analytics.d.ts +2 -15
- package/analytics/utils/collection-analytics.js +14 -18
- package/analytics/utils/product-analytics.d.ts +23 -0
- package/analytics/utils/product-analytics.js +21 -0
- package/cart/hooks/use-add-to-cart.js +1 -1
- package/cart/utils/cart-analytics.d.ts +3 -23
- package/cart/utils/cart-analytics.js +1 -1
- package/cart/utils/cart-utils.js +1 -1
- package/cart/utils/variant-to-cart-line.js +1 -1
- package/chunk-CKRRL66R.mjs +28 -0
- package/{chunk-VVB7BEDE.mjs → chunk-O4QBR4QC.mjs} +9 -4
- package/{chunk-EUIVDITZ.mjs → chunk-OPKMOW43.mjs} +1 -1
- package/{chunk-C37TXOGI.mjs → chunk-PSYP2DYM.mjs} +1 -1
- package/{chunk-ACQS4AG5.mjs → chunk-TTEBDCWT.mjs} +272 -109
- package/{chunk-HFKL4ZR5.mjs → chunk-XGXJOHUY.mjs} +2 -1
- package/{chunk-AQG3256R.mjs → chunk-XSMYSAKY.mjs} +0 -26
- package/{chunk-SSBIMQES.mjs → chunk-XWWFRIXV.mjs} +36 -99
- package/chunk-ZPDXVFCR.mjs +66 -0
- package/hooks/use-formatted-price.js +1 -1
- package/lib/buildMetadata.js +3 -3
- package/loaders/collection-loader.js +8 -6
- package/loaders/collection-products-loader.js +8 -6
- package/loaders/contentful-entries-loader.js +5 -3
- package/loaders/contentful-entry-loader.js +5 -3
- package/loaders/integration-loader-schemas.d.ts +260 -0
- package/loaders/integration-loader-schemas.js +55 -0
- package/loaders/invoke-loader.d.ts +5 -0
- package/loaders/invoke-loader.js +1 -1
- package/loaders/judgeme-review-aggregate-loader.d.ts +1 -1
- package/loaders/judgeme-review-aggregate-loader.js +10 -6
- package/loaders/judgeme-reviews-loader.d.ts +1 -1
- package/loaders/judgeme-reviews-loader.js +5 -3
- package/loaders/kaching-bundles-loader.js +5 -3
- package/loaders/levanta-product-loader.js +8 -6
- package/loaders/loox-review-aggregate-loader.d.ts +1 -1
- package/loaders/loox-review-aggregate-loader.js +10 -6
- package/loaders/loox-reviews-loader.d.ts +1 -1
- package/loaders/loox-reviews-loader.js +8 -6
- package/loaders/metaobject-loader.js +5 -3
- package/loaders/metaobjects-loader.js +5 -3
- package/loaders/okendo-review-aggregate-loader.d.ts +2 -7
- package/loaders/okendo-review-aggregate-loader.js +8 -12
- package/loaders/okendo-reviews-loader.d.ts +2 -42
- package/loaders/okendo-reviews-loader.js +5 -8
- package/loaders/product-loader.js +5 -3
- package/loaders/rebuy-recommendations-loader.d.ts +2 -167
- package/loaders/rebuy-recommendations-loader.js +8 -10
- package/loaders/reviews-io-review-aggregate-loader.d.ts +1 -1
- package/loaders/reviews-io-review-aggregate-loader.js +5 -3
- package/loaders/reviews-io-reviews-loader.d.ts +1 -1
- package/loaders/reviews-io-reviews-loader.js +7 -3
- package/loaders/shopify-integration-details-loader.js +10 -6
- package/loaders/smile-earning-rules-loader.d.ts +2 -8
- package/loaders/smile-earning-rules-loader.js +8 -16
- package/loaders/smile-rewards-loader.d.ts +2 -8
- package/loaders/smile-rewards-loader.js +8 -16
- package/loaders/smile-vip-tiers-loader.d.ts +2 -7
- package/loaders/smile-vip-tiers-loader.js +8 -15
- package/loaders/statsig-experiment-loader.js +5 -3
- package/loaders/yotpo-review-aggregate-loader.d.ts +1 -1
- package/loaders/yotpo-review-aggregate-loader.js +10 -6
- package/loaders/yotpo-reviews-loader.d.ts +1 -1
- package/loaders/yotpo-reviews-loader.js +5 -3
- package/money.d.ts +1 -1
- package/money.js +1 -1
- package/package.json +8 -4
- package/chunk-CQYCPDPI.mjs +0 -166
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { jsonStringifyOrNull, omitJsonObjectFieldsOrNull, parseJsonOrNull } from '../../../chunk-
|
|
2
|
-
import '../../../chunk-
|
|
3
|
-
import '../../../chunk-
|
|
4
|
-
import '../../../chunk-
|
|
5
|
-
import '../../../chunk-SSBIMQES.mjs';
|
|
1
|
+
export { jsonStringifyOrNull, omitJsonObjectFieldsOrNull, parseJsonOrNull } from '../../../chunk-PSYP2DYM.mjs';
|
|
2
|
+
import '../../../chunk-O4QBR4QC.mjs';
|
|
3
|
+
import '../../../chunk-OPKMOW43.mjs';
|
|
4
|
+
import '../../../chunk-ZPDXVFCR.mjs';
|
|
6
5
|
import '../../../chunk-UJCSKKID.mjs';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isNotNullish, isNullish, isPrimitive, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, sleepWithSignal, warning } from '../../../chunk-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isNotNullish, isNullish, isPrimitive, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, sleepWithSignal, warning } from '../../../chunk-XGXJOHUY.mjs';
|
|
2
|
+
export { isFunction_default as isFunction } from '../../../chunk-XWWFRIXV.mjs';
|
|
3
|
+
export { isNumber_default as isNumber, isString_default as isString } from '../../../chunk-OPKMOW43.mjs';
|
|
4
|
+
import '../../../chunk-ZPDXVFCR.mjs';
|
|
4
5
|
import '../../../chunk-UJCSKKID.mjs';
|
|
@@ -26,6 +26,21 @@ export declare const deepEqual: typeof dequalLite;
|
|
|
26
26
|
* @returns A new object without the specified keys
|
|
27
27
|
*/
|
|
28
28
|
export declare function omit<ObjectType extends Record<string, any>, KeyType extends keyof ObjectType>(obj: ObjectType, keysToOmit: KeyType[]): Omit<ObjectType, KeyType>;
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* `ObjectType` with every key that can hold `undefined` made optional and
|
|
31
|
+
* `undefined` removed from its value type. Keys that can't be `undefined`
|
|
32
|
+
* stay required.
|
|
33
|
+
*/
|
|
34
|
+
export type WithoutUndefined<ObjectType> = {
|
|
35
|
+
[Key in keyof ObjectType as undefined extends ObjectType[Key] ? never : Key]: ObjectType[Key];
|
|
36
|
+
} & {
|
|
37
|
+
[Key in keyof ObjectType as undefined extends ObjectType[Key] ? Key : never]?: Exclude<ObjectType[Key], undefined>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Copies `data` without its `undefined`-valued own keys. A plain loop rather
|
|
41
|
+
* than lodash `pickBy`: this ships in the published SDK, and `pickBy` drags in
|
|
42
|
+
* lodash's iteratee-shorthand machinery (~6 KB gzipped) for a one-line check.
|
|
43
|
+
*/
|
|
44
|
+
export declare function filterUndefined<ObjectType extends Record<string, unknown>>(data: ObjectType): WithoutUndefined<ObjectType>;
|
|
30
45
|
export declare function toNullableIfDefined<ValueType>(value: ValueType | undefined): ValueType | null | undefined;
|
|
31
46
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { deepEqual, filterUndefined, forEachPrimitiveValue, omit, shallowEqual, toNullableIfDefined } from '../../../chunk-
|
|
2
|
-
import '../../../chunk-
|
|
3
|
-
import '../../../chunk-
|
|
4
|
-
import '../../../chunk-SSBIMQES.mjs';
|
|
1
|
+
export { deepEqual, filterUndefined, forEachPrimitiveValue, omit, shallowEqual, toNullableIfDefined } from '../../../chunk-O4QBR4QC.mjs';
|
|
2
|
+
import '../../../chunk-OPKMOW43.mjs';
|
|
3
|
+
import '../../../chunk-ZPDXVFCR.mjs';
|
|
5
4
|
import '../../../chunk-UJCSKKID.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CONTENT_MANAGED_ENTRY_VALUE_KEYS, contentEntryFrontmatterSchema, convertLegacyContentEntryDocument, getContentEntryFieldValidationIssues, getContentRenderableEntryValues, parseContentEntryDocument, serializeContentEntryDocument } from '../../chunk-
|
|
1
|
+
export { CONTENT_MANAGED_ENTRY_VALUE_KEYS, contentEntryFrontmatterSchema, convertLegacyContentEntryDocument, getContentEntryFieldValidationIssues, getContentRenderableEntryValues, parseContentEntryDocument, serializeContentEntryDocument } from '../../chunk-TTEBDCWT.mjs';
|
|
2
2
|
import '../../chunk-RQ76VK3L.mjs';
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
3
|
+
import '../../chunk-XWWFRIXV.mjs';
|
|
4
|
+
import '../../chunk-ZPDXVFCR.mjs';
|
|
5
5
|
import '../../chunk-UJCSKKID.mjs';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { parseContentEntryDocument, getContentRenderableEntryValues, getContentEntryFieldValidationIssues } from '../../chunk-
|
|
1
|
+
import { parseContentEntryDocument, getContentRenderableEntryValues, getContentEntryFieldValidationIssues } from '../../chunk-TTEBDCWT.mjs';
|
|
2
2
|
import { isValidContentSlug, CONTENT_COLLECTION_SCHEMA_FILENAME, CONTENT_ENTRY_FILE_EXTENSION, contentCollectionFileSchema, CONTENT_ENTRY_PUBLISHED_FILE_EXTENSION } from '../../chunk-RQ76VK3L.mjs';
|
|
3
|
-
import
|
|
4
|
-
import '../../chunk-
|
|
5
|
-
import '../../chunk-
|
|
6
|
-
import '../../chunk-
|
|
7
|
-
import '../../chunk-
|
|
3
|
+
import '../../chunk-XWWFRIXV.mjs';
|
|
4
|
+
import { parseJsonOrNull } from '../../chunk-PSYP2DYM.mjs';
|
|
5
|
+
import '../../chunk-O4QBR4QC.mjs';
|
|
6
|
+
import '../../chunk-OPKMOW43.mjs';
|
|
7
|
+
import '../../chunk-ZPDXVFCR.mjs';
|
|
8
8
|
import '../../chunk-UJCSKKID.mjs';
|
|
9
9
|
import * as z from 'zod';
|
|
10
10
|
|
|
@@ -1,48 +1,8 @@
|
|
|
1
1
|
import type { ErrorUserFacingDetails, ErrorUserFacingDetailsWithMessage } from "./generated/errors";
|
|
2
|
+
import type { ReploErrorConfig } from "./reploError";
|
|
2
3
|
import * as z from "zod";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export type ReploErrorConfig = {
|
|
7
|
-
/**
|
|
8
|
-
* Message of the error, used only internally. If not provided, defaults to
|
|
9
|
-
* the error's class name
|
|
10
|
-
*/
|
|
11
|
-
message?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Any additional data about the error, e.g. ids of content that was trying
|
|
14
|
-
* to be accessed, contextual variables, etc. This is included when the error
|
|
15
|
-
* is logged to Sentry, etc
|
|
16
|
-
*/
|
|
17
|
-
additionalData?: Record<string, unknown>;
|
|
18
|
-
/** Meta details for error reporting */
|
|
19
|
-
errorReportingDetails?: {
|
|
20
|
-
/**
|
|
21
|
-
* If true, tells Sentry that it should group this error differently when
|
|
22
|
-
* it happens on different endpoints ("transactions" in Sentry are endpoints)
|
|
23
|
-
*/
|
|
24
|
-
includeTransactionInFingerprint?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* If provided, these get added to the Sentry fingerprint for this error. Useful
|
|
27
|
-
* for when you want to modify the grouping of an error, especially for reusing
|
|
28
|
-
* errors in different places.
|
|
29
|
-
*/
|
|
30
|
-
customFingerprint?: string[];
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Original cause of the error (useful for if you need to catch and re-throw errors
|
|
34
|
-
* with more context). Will be reported in stacktraces, sentry, etc.
|
|
35
|
-
*/
|
|
36
|
-
cause?: unknown;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Base error that all errors in Replo inherit from
|
|
40
|
-
*/
|
|
41
|
-
export declare abstract class ReploError extends Error {
|
|
42
|
-
config: ReploErrorConfig;
|
|
43
|
-
id: string;
|
|
44
|
-
constructor(config: ReploErrorConfig);
|
|
45
|
-
}
|
|
4
|
+
import { ReploError } from "./reploError";
|
|
5
|
+
export { ReploError, type ReploErrorConfig } from "./reploError";
|
|
46
6
|
/**
|
|
47
7
|
* Wraps an error so `async-retry` stops immediately instead of scheduling
|
|
48
8
|
* another attempt: the library rejects with any thrown error carrying a truthy
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ReploError } from "./errors";
|
|
1
|
+
import { ReploError } from "./reploError";
|
|
3
2
|
export declare class InvalidAmountError extends ReploError {
|
|
4
3
|
}
|
|
5
4
|
export declare class UnsupportedCurrencyError extends ReploError {
|
|
@@ -52,9 +51,3 @@ export declare function formatAmount({ amount, currencyCode, locale, }: {
|
|
|
52
51
|
currencyCode: string;
|
|
53
52
|
locale?: string;
|
|
54
53
|
}): string;
|
|
55
|
-
export declare const amountSchema: z.ZodNumber;
|
|
56
|
-
/** An amount in minor units paired with its ISO 4217 currency code. */
|
|
57
|
-
export declare const amountWithCurrencyCodeSchema: z.ZodObject<{
|
|
58
|
-
amount: z.ZodNumber;
|
|
59
|
-
currencyCode: z.ZodString;
|
|
60
|
-
}, z.core.$strip>;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { ReploError } from '../../chunk-
|
|
2
|
-
import '../../chunk-HFKL4ZR5.mjs';
|
|
3
|
-
import '../../chunk-EUIVDITZ.mjs';
|
|
4
|
-
import '../../chunk-SSBIMQES.mjs';
|
|
1
|
+
import { ReploError } from '../../chunk-CKRRL66R.mjs';
|
|
5
2
|
import { __commonJS, __toESM } from '../../chunk-UJCSKKID.mjs';
|
|
6
|
-
import * as z from 'zod';
|
|
7
3
|
|
|
8
4
|
var require_first_match = __commonJS({
|
|
9
5
|
"../../node_modules/.pnpm/first-match@0.0.1/node_modules/first-match/index.js"(exports, module) {
|
|
@@ -1816,9 +1812,9 @@ var require_currency_codes = __commonJS({
|
|
|
1816
1812
|
}) || []).indexOf(country2) > -1;
|
|
1817
1813
|
});
|
|
1818
1814
|
};
|
|
1819
|
-
var
|
|
1815
|
+
var number = function(number2) {
|
|
1820
1816
|
return first(data, function(c) {
|
|
1821
|
-
return c.number === String(
|
|
1817
|
+
return c.number === String(number2);
|
|
1822
1818
|
});
|
|
1823
1819
|
};
|
|
1824
1820
|
var codes = function() {
|
|
@@ -1846,7 +1842,7 @@ var require_currency_codes = __commonJS({
|
|
|
1846
1842
|
};
|
|
1847
1843
|
exports.code = code;
|
|
1848
1844
|
exports.country = country;
|
|
1849
|
-
exports.number =
|
|
1845
|
+
exports.number = number;
|
|
1850
1846
|
exports.codes = codes;
|
|
1851
1847
|
exports.numbers = numbers;
|
|
1852
1848
|
exports.countries = countries;
|
|
@@ -1926,12 +1922,5 @@ function formatAmount({
|
|
|
1926
1922
|
currency: currencyCode.toUpperCase()
|
|
1927
1923
|
}).format(fromMinorUnitsToMajorUnits({ amount, currencyCode }));
|
|
1928
1924
|
}
|
|
1929
|
-
var amountSchema = z.number().int().describe(
|
|
1930
|
-
"Integer amount in the currency's minor units (Stripe convention): 1999 = $19.99 USD, 1999 = \xA51999 JPY, 1999 = 1.999 KWD"
|
|
1931
|
-
);
|
|
1932
|
-
var amountWithCurrencyCodeSchema = z.object({
|
|
1933
|
-
amount: amountSchema,
|
|
1934
|
-
currencyCode: z.string()
|
|
1935
|
-
});
|
|
1936
1925
|
|
|
1937
|
-
export { InvalidAmountError, UnsupportedCurrencyError,
|
|
1926
|
+
export { InvalidAmountError, UnsupportedCurrencyError, formatAmount, fromMajorUnitsToMinorUnits, fromMinorUnitsToMajorUnits, fromMinorUnitsToMajorUnitsString, parseDecimalToMinorUnits };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config to use for any standard error we throw in Replo
|
|
3
|
+
*/
|
|
4
|
+
export type ReploErrorConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* Message of the error, used only internally. If not provided, defaults to
|
|
7
|
+
* the error's class name
|
|
8
|
+
*/
|
|
9
|
+
message?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Any additional data about the error, e.g. ids of content that was trying
|
|
12
|
+
* to be accessed, contextual variables, etc. This is included when the error
|
|
13
|
+
* is logged to Sentry, etc
|
|
14
|
+
*/
|
|
15
|
+
additionalData?: Record<string, unknown>;
|
|
16
|
+
/** Meta details for error reporting */
|
|
17
|
+
errorReportingDetails?: {
|
|
18
|
+
/**
|
|
19
|
+
* If true, tells Sentry that it should group this error differently when
|
|
20
|
+
* it happens on different endpoints ("transactions" in Sentry are endpoints)
|
|
21
|
+
*/
|
|
22
|
+
includeTransactionInFingerprint?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* If provided, these get added to the Sentry fingerprint for this error. Useful
|
|
25
|
+
* for when you want to modify the grouping of an error, especially for reusing
|
|
26
|
+
* errors in different places.
|
|
27
|
+
*/
|
|
28
|
+
customFingerprint?: string[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Original cause of the error (useful for if you need to catch and re-throw errors
|
|
32
|
+
* with more context). Will be reported in stacktraces, sentry, etc.
|
|
33
|
+
*/
|
|
34
|
+
cause?: unknown;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Base error that all errors in Replo inherit from
|
|
38
|
+
*/
|
|
39
|
+
export declare abstract class ReploError extends Error {
|
|
40
|
+
config: ReploErrorConfig;
|
|
41
|
+
id: string;
|
|
42
|
+
constructor(config: ReploErrorConfig);
|
|
43
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '../../../chunk-
|
|
3
|
-
import '../../../chunk-
|
|
4
|
-
import '../../../chunk-
|
|
1
|
+
import '../../../chunk-XSMYSAKY.mjs';
|
|
2
|
+
import { ReploError } from '../../../chunk-CKRRL66R.mjs';
|
|
3
|
+
import '../../../chunk-XGXJOHUY.mjs';
|
|
4
|
+
import '../../../chunk-XWWFRIXV.mjs';
|
|
5
|
+
import '../../../chunk-OPKMOW43.mjs';
|
|
6
|
+
import '../../../chunk-ZPDXVFCR.mjs';
|
|
5
7
|
import '../../../chunk-UJCSKKID.mjs';
|
|
6
8
|
import * as z from 'zod';
|
|
7
9
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { getParamSegment, getRouteParams, hasRouteParam, matchSource } from '../../../chunk-VPEVERWE.mjs';
|
|
2
|
-
import
|
|
3
|
-
import '../../../chunk-
|
|
4
|
-
import '../../../chunk-
|
|
5
|
-
import '../../../chunk-
|
|
2
|
+
import '../../../chunk-XSMYSAKY.mjs';
|
|
3
|
+
import { ReploError } from '../../../chunk-CKRRL66R.mjs';
|
|
4
|
+
import '../../../chunk-XGXJOHUY.mjs';
|
|
5
|
+
import '../../../chunk-XWWFRIXV.mjs';
|
|
6
|
+
import '../../../chunk-OPKMOW43.mjs';
|
|
7
|
+
import '../../../chunk-ZPDXVFCR.mjs';
|
|
6
8
|
import '../../../chunk-UJCSKKID.mjs';
|
|
7
9
|
import * as z from 'zod';
|
|
8
10
|
|
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
import type { PageMetadata } from "./utils/navigation-tracker";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* One product line on a product, cart, collection or checkout event. Prices
|
|
4
|
+
* are decimal major units (19.99), never integer minor units.
|
|
5
|
+
*/
|
|
6
|
+
export type AnalyticsProductLine = {
|
|
7
|
+
productId: string;
|
|
8
|
+
productTitle?: string;
|
|
9
|
+
variantId?: string;
|
|
10
|
+
variantTitle?: string;
|
|
11
|
+
/** May be empty when the variant has no SKU. */
|
|
12
|
+
variantSku?: string;
|
|
13
|
+
price?: number;
|
|
14
|
+
currency?: string;
|
|
15
|
+
quantity?: number;
|
|
16
|
+
};
|
|
17
|
+
/** Sent by `useProductViewedAnalytics`. */
|
|
18
|
+
export type ProductViewedData = Omit<AnalyticsProductLine, "quantity"> & {
|
|
19
|
+
productSlug?: string;
|
|
20
|
+
productDescription?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Sent by the cart provider for each added or removed line. */
|
|
23
|
+
export type CartLineData = AnalyticsProductLine & {
|
|
24
|
+
quantity: number;
|
|
25
|
+
};
|
|
26
|
+
/** Sent by the cart provider when the cart opens. */
|
|
27
|
+
export type CartViewedData = {
|
|
28
|
+
itemCount: number;
|
|
29
|
+
subtotal: number;
|
|
30
|
+
currency?: string;
|
|
31
|
+
lineItems: CartLineData[];
|
|
32
|
+
};
|
|
33
|
+
/** The cart a shopper takes to checkout, with its order total. */
|
|
34
|
+
export type CheckoutStartedData = CartViewedData & {
|
|
35
|
+
total: number;
|
|
36
|
+
};
|
|
37
|
+
/** Sent by `useCollectionViewedAnalytics`. */
|
|
38
|
+
export type CollectionViewedData = {
|
|
39
|
+
collectionId: string;
|
|
40
|
+
collectionTitle?: string;
|
|
41
|
+
collectionHandle?: string;
|
|
42
|
+
currency?: string;
|
|
43
|
+
products: AnalyticsProductLine[];
|
|
44
|
+
};
|
|
45
|
+
export type AnalyticsProperty = string | number | boolean | null | AnalyticsProperty[] | {
|
|
46
|
+
[key: string]: AnalyticsProperty;
|
|
47
|
+
};
|
|
48
|
+
/** A site-defined click; its properties are forwarded as-is. */
|
|
49
|
+
export type ClickData = Record<string, AnalyticsProperty>;
|
|
50
|
+
/** Order amounts are decimal major units, like `PurchasePayload.amount`. */
|
|
51
|
+
export type PurchaseData = {
|
|
52
|
+
orderId?: string;
|
|
53
|
+
lineItems?: CartLineData[];
|
|
54
|
+
/** Units in the order, when the caller has a count but no lines. */
|
|
55
|
+
itemCount?: number;
|
|
56
|
+
totalTax?: number;
|
|
57
|
+
totalShipping?: number;
|
|
58
|
+
totalDiscount?: number;
|
|
59
|
+
discountCodes?: string[];
|
|
60
|
+
};
|
|
61
|
+
export type ProductViewedPayload = {
|
|
62
|
+
data: ProductViewedData;
|
|
63
|
+
};
|
|
64
|
+
export type CartLineEventPayload = {
|
|
65
|
+
data: CartLineData;
|
|
66
|
+
};
|
|
67
|
+
export type CartViewedPayload = {
|
|
68
|
+
data: CartViewedData;
|
|
69
|
+
};
|
|
70
|
+
export type CheckoutStartedPayload = {
|
|
71
|
+
data: CheckoutStartedData;
|
|
72
|
+
};
|
|
73
|
+
export type CollectionViewedPayload = {
|
|
74
|
+
data: CollectionViewedData;
|
|
75
|
+
};
|
|
76
|
+
export type ClickPayload = {
|
|
77
|
+
data: ClickData;
|
|
4
78
|
};
|
|
5
79
|
export type PurchasePayload = {
|
|
6
80
|
/**
|
|
@@ -11,25 +85,63 @@ export type PurchasePayload = {
|
|
|
11
85
|
*/
|
|
12
86
|
amount: number;
|
|
13
87
|
currency: string;
|
|
14
|
-
data:
|
|
88
|
+
data: PurchaseData;
|
|
15
89
|
};
|
|
16
|
-
|
|
17
|
-
|
|
90
|
+
/** A money amount as older starter carts built it. */
|
|
91
|
+
export type LegacyMoney = {
|
|
92
|
+
amount: number;
|
|
93
|
+
currencyCode: string;
|
|
94
|
+
};
|
|
95
|
+
/** A checkout line as older starter carts built it. */
|
|
96
|
+
export type LegacyCheckoutLineItem = {
|
|
97
|
+
id: string;
|
|
98
|
+
quantity: number;
|
|
99
|
+
title: string;
|
|
100
|
+
variant: {
|
|
101
|
+
id: string;
|
|
102
|
+
title: string;
|
|
103
|
+
price: LegacyMoney;
|
|
104
|
+
product: {
|
|
105
|
+
id: string;
|
|
106
|
+
title: string;
|
|
107
|
+
url?: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
finalLinePrice?: LegacyMoney;
|
|
111
|
+
};
|
|
112
|
+
/** The nested checkout payload older starter carts send. */
|
|
113
|
+
export type LegacyCheckoutStartedData = {
|
|
114
|
+
currencyCode: string;
|
|
115
|
+
totalPrice: LegacyMoney;
|
|
116
|
+
subtotalPrice: LegacyMoney;
|
|
117
|
+
lineItems: LegacyCheckoutLineItem[];
|
|
118
|
+
};
|
|
119
|
+
export type LegacyCheckoutStartedPayload = {
|
|
120
|
+
data: LegacyCheckoutStartedData;
|
|
18
121
|
};
|
|
19
122
|
export interface CustomEventPayload {
|
|
20
123
|
event: string;
|
|
21
124
|
properties?: Record<string, AnalyticsProperty>;
|
|
22
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* What `useAnalytics()` returns, and what every sink implements, including
|
|
128
|
+
* sinks registered with `useAnalyticsSink`. Each event takes its typed payload;
|
|
129
|
+
* a sink with no use for an event implements it as a no-op.
|
|
130
|
+
*/
|
|
23
131
|
export interface AnalyticsSink {
|
|
24
|
-
/**
|
|
25
|
-
customEvent
|
|
132
|
+
/** An explicit business goal, such as a completed quiz. */
|
|
133
|
+
customEvent(payload: CustomEventPayload): Promise<void>;
|
|
26
134
|
pageView(metadata?: PageMetadata): Promise<void>;
|
|
27
135
|
purchase(payload: PurchasePayload): Promise<void>;
|
|
28
|
-
click(payload:
|
|
29
|
-
productViewed(payload:
|
|
30
|
-
addToCart(payload:
|
|
31
|
-
removeFromCart(payload:
|
|
32
|
-
viewCart(payload:
|
|
33
|
-
|
|
34
|
-
|
|
136
|
+
click(payload: ClickPayload): Promise<void>;
|
|
137
|
+
productViewed(payload: ProductViewedPayload): Promise<void>;
|
|
138
|
+
addToCart(payload: CartLineEventPayload): Promise<void>;
|
|
139
|
+
removeFromCart(payload: CartLineEventPayload): Promise<void>;
|
|
140
|
+
viewCart(payload: CartViewedPayload): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Also takes the nested payload older starter carts send; the built-in
|
|
143
|
+
* sinks convert it to `CheckoutStartedData`.
|
|
144
|
+
*/
|
|
145
|
+
startCheckout(payload: CheckoutStartedPayload | LegacyCheckoutStartedPayload): Promise<void>;
|
|
146
|
+
viewCollection(payload: CollectionViewedPayload): Promise<void>;
|
|
35
147
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { logAnalyticsActivity } from "./utils/analytics-log";
|
|
2
2
|
function combineSinks(sinks) {
|
|
3
|
-
const broadcast = async (method,
|
|
3
|
+
const broadcast = async (method, send) => {
|
|
4
4
|
if (typeof window !== "undefined") {
|
|
5
5
|
logAnalyticsActivity({
|
|
6
6
|
kind: "broadcast",
|
|
@@ -11,8 +11,7 @@ function combineSinks(sinks) {
|
|
|
11
11
|
await Promise.all(
|
|
12
12
|
sinks.map(async (sink) => {
|
|
13
13
|
try {
|
|
14
|
-
|
|
15
|
-
await sinkMethod?.apply(sink, args);
|
|
14
|
+
await send(sink);
|
|
16
15
|
} catch {
|
|
17
16
|
if (typeof window !== "undefined") {
|
|
18
17
|
console.warn("[analytics] sink error", { method });
|
|
@@ -22,16 +21,40 @@ function combineSinks(sinks) {
|
|
|
22
21
|
);
|
|
23
22
|
};
|
|
24
23
|
return {
|
|
25
|
-
customEvent: (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
customEvent: (payload) => {
|
|
25
|
+
return broadcast("customEvent", (sink) => sink.customEvent(payload));
|
|
26
|
+
},
|
|
27
|
+
pageView: (metadata) => {
|
|
28
|
+
return broadcast("pageView", (sink) => sink.pageView(metadata));
|
|
29
|
+
},
|
|
30
|
+
purchase: (payload) => {
|
|
31
|
+
return broadcast("purchase", (sink) => sink.purchase(payload));
|
|
32
|
+
},
|
|
33
|
+
click: (payload) => {
|
|
34
|
+
return broadcast("click", (sink) => sink.click(payload));
|
|
35
|
+
},
|
|
36
|
+
productViewed: (payload) => {
|
|
37
|
+
return broadcast("productViewed", (sink) => sink.productViewed(payload));
|
|
38
|
+
},
|
|
39
|
+
addToCart: (payload) => {
|
|
40
|
+
return broadcast("addToCart", (sink) => sink.addToCart(payload));
|
|
41
|
+
},
|
|
42
|
+
removeFromCart: (payload) => {
|
|
43
|
+
return broadcast("removeFromCart", (sink) => {
|
|
44
|
+
return sink.removeFromCart(payload);
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
viewCart: (payload) => {
|
|
48
|
+
return broadcast("viewCart", (sink) => sink.viewCart(payload));
|
|
49
|
+
},
|
|
50
|
+
startCheckout: (payload) => {
|
|
51
|
+
return broadcast("startCheckout", (sink) => sink.startCheckout(payload));
|
|
52
|
+
},
|
|
53
|
+
viewCollection: (payload) => {
|
|
54
|
+
return broadcast("viewCollection", (sink) => {
|
|
55
|
+
return sink.viewCollection(payload);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
35
58
|
};
|
|
36
59
|
}
|
|
37
60
|
export {
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
id: string;
|
|
3
|
-
title: string;
|
|
4
|
-
slug?: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
}
|
|
7
|
-
interface AnalyticsProductVariant {
|
|
8
|
-
id: string;
|
|
9
|
-
title?: string;
|
|
10
|
-
sku?: string;
|
|
11
|
-
price?: number | {
|
|
12
|
-
amount: number | string;
|
|
13
|
-
currencyCode: string;
|
|
14
|
-
};
|
|
15
|
-
currency?: string;
|
|
16
|
-
priceCurrencyCode?: string | null;
|
|
17
|
-
}
|
|
1
|
+
import type { AnalyticsProduct, AnalyticsProductVariant } from "../utils/product-analytics";
|
|
18
2
|
interface UseProductViewedAnalyticsProps {
|
|
19
3
|
product: AnalyticsProduct | null;
|
|
20
4
|
selectedVariant?: AnalyticsProductVariant | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
3
|
import { useAnalytics } from "../analytics-provider";
|
|
4
|
+
import { buildProductViewedAnalyticsData } from "../utils/product-analytics";
|
|
4
5
|
function useProductViewedAnalytics({
|
|
5
6
|
product,
|
|
6
7
|
selectedVariant
|
|
@@ -12,21 +13,11 @@ function useProductViewedAnalytics({
|
|
|
12
13
|
const trackingKey = `${product.id}-${selectedVariant.id}`;
|
|
13
14
|
if (lastTrackedRef.current !== trackingKey) {
|
|
14
15
|
lastTrackedRef.current = trackingKey;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
data: {
|
|
19
|
-
productId: product.id,
|
|
20
|
-
productTitle: product.title,
|
|
21
|
-
productSlug: product.slug,
|
|
22
|
-
productDescription: product.description,
|
|
23
|
-
variantId: selectedVariant.id ?? "",
|
|
24
|
-
variantTitle: selectedVariant.title ?? "",
|
|
25
|
-
variantSku: selectedVariant.sku ?? "",
|
|
26
|
-
price,
|
|
27
|
-
currency
|
|
28
|
-
}
|
|
16
|
+
const data = buildProductViewedAnalyticsData({
|
|
17
|
+
product,
|
|
18
|
+
selectedVariant
|
|
29
19
|
});
|
|
20
|
+
void analytics.productViewed({ data });
|
|
30
21
|
}
|
|
31
22
|
}
|
|
32
23
|
}, [analytics, product, selectedVariant]);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function toCheckoutStartedData(data) {
|
|
2
|
+
if ("total" in data) {
|
|
3
|
+
return data;
|
|
4
|
+
}
|
|
5
|
+
const lineItems = data.lineItems.map((line) => {
|
|
6
|
+
return {
|
|
7
|
+
productId: line.variant.product.id,
|
|
8
|
+
productTitle: line.variant.product.title,
|
|
9
|
+
variantId: line.variant.id,
|
|
10
|
+
variantTitle: line.variant.title,
|
|
11
|
+
price: line.variant.price.amount,
|
|
12
|
+
currency: line.variant.price.currencyCode,
|
|
13
|
+
quantity: line.quantity
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
itemCount: lineItems.reduce((sum, line) => sum + line.quantity, 0),
|
|
18
|
+
subtotal: data.subtotalPrice.amount,
|
|
19
|
+
total: data.totalPrice.amount,
|
|
20
|
+
currency: data.currencyCode,
|
|
21
|
+
lineItems
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
toCheckoutStartedData
|
|
26
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { PurchasePayload } from "../analytics-sink";
|
|
2
|
-
type AnalyticsRecord = Record<string, unknown>;
|
|
1
|
+
import type { CartLineData, CollectionViewedData, ProductViewedData, PurchasePayload } from "../analytics-sink";
|
|
3
2
|
export type ConvergeProductProperties = {
|
|
4
3
|
product_id: string;
|
|
5
4
|
name: string;
|
|
@@ -8,9 +7,6 @@ export type ConvergeProductProperties = {
|
|
|
8
7
|
variant_id?: string;
|
|
9
8
|
sku?: string;
|
|
10
9
|
variant_name?: string;
|
|
11
|
-
vendor?: string;
|
|
12
|
-
url?: string;
|
|
13
|
-
image_url?: string;
|
|
14
10
|
};
|
|
15
11
|
type ConvergeCartItem = ConvergeProductProperties & {
|
|
16
12
|
quantity: number;
|
|
@@ -22,7 +18,7 @@ export type ConvergeCartProperties = {
|
|
|
22
18
|
currency: string;
|
|
23
19
|
items?: ConvergeCartItem[];
|
|
24
20
|
total_discount?: number;
|
|
25
|
-
coupon?: string
|
|
21
|
+
coupon?: string[];
|
|
26
22
|
};
|
|
27
23
|
export type ConvergeOrderProperties = ConvergeCartProperties & {
|
|
28
24
|
id: string;
|
|
@@ -30,12 +26,15 @@ export type ConvergeOrderProperties = ConvergeCartProperties & {
|
|
|
30
26
|
export type ConvergeCollectionProperties = {
|
|
31
27
|
id: string;
|
|
32
28
|
name: string;
|
|
33
|
-
description?: string;
|
|
34
29
|
items?: ConvergeProductProperties[];
|
|
35
30
|
};
|
|
36
|
-
export declare function mapConvergeProduct(data:
|
|
37
|
-
export declare function mapConvergeCartItem(data:
|
|
38
|
-
export declare function mapConvergeCollection(data:
|
|
39
|
-
export declare function mapConvergeCart(
|
|
31
|
+
export declare function mapConvergeProduct(data: ProductViewedData): ConvergeProductProperties | null;
|
|
32
|
+
export declare function mapConvergeCartItem(data: CartLineData): ConvergeCartItem | null;
|
|
33
|
+
export declare function mapConvergeCollection(data: CollectionViewedData): ConvergeCollectionProperties | null;
|
|
34
|
+
export declare function mapConvergeCart({ totalPrice, currency, lineItems, }: {
|
|
35
|
+
totalPrice: number;
|
|
36
|
+
currency: string | undefined;
|
|
37
|
+
lineItems: CartLineData[];
|
|
38
|
+
}): ConvergeCartProperties | null;
|
|
40
39
|
export declare function mapConvergeOrder({ amount, currency, data, }: PurchasePayload): ConvergeOrderProperties | null;
|
|
41
40
|
export {};
|