@fanfare-io/fanfare-sdk-contracts 0.1.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/dist/beacon.js ADDED
@@ -0,0 +1,269 @@
1
+ import * as e from "valibot";
2
+ import { RFM_SEGMENT_KEYS as u, BeaconEventNames as g, BeaconEventName as v } from "./beacon-names.js";
3
+ const t = v, C = 50, P = 64, _ = 2048, E = 256, N = 50, T = /^\d{1,12}(\.\d{1,8})?$/, b = e.picklist(u), a = e.pipe(
4
+ e.string(),
5
+ e.maxLength(_, "validation.beacon.string.maxLength")
6
+ ), o = e.pipe(
7
+ e.string(),
8
+ e.maxLength(E, "validation.beacon.string.maxLength")
9
+ ), c = e.pipe(
10
+ e.string(),
11
+ e.regex(T, "validation.number"),
12
+ e.maxLength(E, "validation.beacon.money.maxLength")
13
+ ), l = e.pipe(
14
+ e.string(),
15
+ e.isoTimestamp(),
16
+ e.maxLength(64, "validation.beacon.timestamp.maxLength")
17
+ ), m = e.pipe(
18
+ e.string(),
19
+ e.regex(/^\d+$/),
20
+ e.maxLength(32, "validation.beacon.timestampNs.maxLength")
21
+ ), i = e.pipe(
22
+ e.number(),
23
+ e.check(Number.isFinite, "validation.beacon.number.finite")
24
+ ), I = e.pipe(
25
+ e.record(
26
+ e.pipe(e.string(), e.maxLength(P, "validation.beacon.propertyKey.maxLength")),
27
+ e.union([a, i, e.boolean(), e.null()])
28
+ ),
29
+ e.maxEntries(C, "validation.beacon.eventProperties.maxEntries")
30
+ ), s = {
31
+ postalCode: e.optional(o),
32
+ timezone: e.optional(o),
33
+ botScore: e.optional(i),
34
+ geoLat: e.optional(i),
35
+ geoLng: e.optional(i)
36
+ }, O = e.object({
37
+ organizationId: o,
38
+ consumerId: e.optional(o),
39
+ eventId: o,
40
+ eventName: e.picklist(g),
41
+ eventTimestamp: l,
42
+ eventTimestampNs: e.optional(m),
43
+ receivedTimestamp: e.optional(l),
44
+ receivedTimestampNs: e.optional(m),
45
+ segments: e.optional(
46
+ e.object({
47
+ rfm: e.optional(b)
48
+ })
49
+ ),
50
+ userId: e.optional(o),
51
+ anonymousId: e.optional(o),
52
+ sessionId: e.optional(o),
53
+ platform: e.optional(o),
54
+ appVersion: e.optional(o),
55
+ deviceType: e.optional(o),
56
+ osName: e.optional(o),
57
+ osVersion: e.optional(o),
58
+ browserName: e.optional(o),
59
+ browserVersion: e.optional(o),
60
+ userAgent: e.optional(a),
61
+ ipAddress: e.optional(o),
62
+ geoCountry: e.optional(o),
63
+ geoRegion: e.optional(o),
64
+ geoCity: e.optional(o),
65
+ geoLatitude: e.optional(i),
66
+ geoLongitude: e.optional(i),
67
+ pageUrl: e.optional(a),
68
+ pagePath: e.optional(a),
69
+ pageTitle: e.optional(a),
70
+ screenName: e.optional(a),
71
+ referrerUrl: e.optional(a),
72
+ referringDomain: e.optional(a),
73
+ utmSource: e.optional(o),
74
+ utmMedium: e.optional(o),
75
+ utmCampaign: e.optional(o),
76
+ utmTerm: e.optional(o),
77
+ utmContent: e.optional(o),
78
+ eventSchemaVersion: e.optional(o),
79
+ eventProperties: e.optional(I),
80
+ beaconRequestId: e.optional(o)
81
+ }), A = e.strictObject({
82
+ ...s,
83
+ pageType: e.optional(o)
84
+ }), S = e.strictObject({
85
+ ...s,
86
+ productId: e.optional(o),
87
+ listName: e.optional(o),
88
+ position: e.optional(i)
89
+ }), M = S, R = e.strictObject({
90
+ ...s,
91
+ productId: e.optional(o),
92
+ sku: e.optional(o),
93
+ productName: e.optional(a),
94
+ category: e.optional(o),
95
+ brand: e.optional(o),
96
+ variant: e.optional(o),
97
+ price: e.optional(c),
98
+ currency: e.optional(o)
99
+ }), d = e.strictObject({
100
+ ...s,
101
+ cartId: e.optional(o),
102
+ productId: e.optional(o),
103
+ sku: e.optional(o),
104
+ productName: e.optional(a),
105
+ category: e.optional(o),
106
+ variant: e.optional(o),
107
+ price: e.optional(c),
108
+ quantity: e.optional(i),
109
+ currency: e.optional(o)
110
+ }), y = d, B = e.strictObject({
111
+ ...s,
112
+ cartId: e.optional(o),
113
+ cartTotal: e.optional(c),
114
+ itemCount: e.optional(i),
115
+ currency: e.optional(o)
116
+ }), L = e.strictObject({
117
+ ...s,
118
+ cartId: e.optional(o),
119
+ cartTotal: e.optional(c),
120
+ itemCount: e.optional(i),
121
+ currency: e.optional(o),
122
+ couponCodeApplied: e.optional(o)
123
+ }), x = e.strictObject({
124
+ productId: e.optional(o),
125
+ sku: e.optional(o),
126
+ productName: e.optional(a),
127
+ category: e.optional(o),
128
+ variant: e.optional(o),
129
+ price: e.optional(c),
130
+ quantity: e.optional(i)
131
+ }), V = e.strictObject({
132
+ ...s,
133
+ orderId: e.optional(o),
134
+ transactionId: e.optional(o),
135
+ totalRevenue: e.optional(c),
136
+ subtotal: e.optional(c),
137
+ tax: e.optional(c),
138
+ shippingCost: e.optional(c),
139
+ currency: e.optional(o),
140
+ couponCodeUsed: e.optional(o),
141
+ discountAmount: e.optional(c),
142
+ products: e.optional(
143
+ e.pipe(
144
+ e.array(x),
145
+ e.maxLength(N, "validation.beacon.purchaseProducts.maxLength")
146
+ )
147
+ )
148
+ }), D = e.strictObject({
149
+ ...s,
150
+ searchQuery: e.optional(a),
151
+ resultsCount: e.optional(i)
152
+ }), j = e.strictObject({
153
+ ...s,
154
+ experienceId: e.optional(o),
155
+ sequenceId: e.optional(o),
156
+ locationId: e.optional(o),
157
+ qrPayload: e.optional(a)
158
+ }), G = e.picklist(["email", "sms"]), r = e.strictObject({
159
+ ...s,
160
+ channel: e.optional(G),
161
+ messageId: e.optional(o),
162
+ template: e.optional(o),
163
+ priority: e.optional(o),
164
+ consumerId: e.optional(o)
165
+ }), U = e.strictObject({
166
+ ...r.entries,
167
+ bounceType: e.optional(o)
168
+ }), k = e.strictObject({
169
+ ...r.entries,
170
+ complaintType: e.optional(o)
171
+ }), f = e.strictObject({
172
+ ...r.entries,
173
+ retryCount: e.optional(i)
174
+ }), n = (p, h) => e.object({
175
+ ...O.entries,
176
+ eventName: e.literal(p),
177
+ eventProperties: e.optional(h)
178
+ }), w = n(t.PAGE_VIEW, A), F = n(
179
+ t.PRODUCT_IMPRESSION,
180
+ S
181
+ ), H = n(t.PRODUCT_CLICK, M), K = n(t.PRODUCT_VIEW, R), X = n(t.ADD_TO_CART, d), q = n(t.REMOVE_FROM_CART, y), Y = n(t.VIEW_CART, B), Q = n(t.BEGIN_CHECKOUT, L), z = n(t.PURCHASE, V), W = n(
182
+ t.SEARCH_SUBMITTED,
183
+ D
184
+ ), $ = n(t.QR_SCANNED, j), J = n(t.MESSAGE_SENT, r), Z = n(t.MESSAGE_DELIVERED, r), ee = n(t.MESSAGE_BOUNCED, U), oe = n(
185
+ t.MESSAGE_COMPLAINED,
186
+ k
187
+ ), te = n(t.MESSAGE_CLICKED, r), ne = n(t.MESSAGE_OPENED, r), ae = n(t.MESSAGE_READ, r), ie = n(t.MESSAGE_FAILED, f), ce = e.union([
188
+ w,
189
+ F,
190
+ H,
191
+ K,
192
+ X,
193
+ q,
194
+ Y,
195
+ Q,
196
+ z,
197
+ W,
198
+ $,
199
+ J,
200
+ Z,
201
+ ee,
202
+ oe,
203
+ te,
204
+ ne,
205
+ ae,
206
+ ie
207
+ ]);
208
+ function re(p) {
209
+ return e.parse(ce, JSON.parse(p));
210
+ }
211
+ export {
212
+ X as AddToCartEventSchema,
213
+ d as AddToCartPropertiesSchema,
214
+ C as BEACON_EVENT_PROPERTIES_MAX_ENTRIES,
215
+ P as BEACON_EVENT_PROPERTY_KEY_MAX_LENGTH,
216
+ _ as BEACON_EVENT_PROPERTY_STRING_MAX_LENGTH,
217
+ N as BEACON_EVENT_PURCHASE_PRODUCTS_MAX_ITEMS,
218
+ E as BEACON_EVENT_SHORT_STRING_MAX_LENGTH,
219
+ O as BeaconEventCoreSchema,
220
+ s as BeaconEventEnrichmentPropertiesSchemaEntries,
221
+ a as BeaconEventLongStringSchema,
222
+ c as BeaconEventMoneyStringSchema,
223
+ t as BeaconEventName,
224
+ g as BeaconEventNames,
225
+ m as BeaconEventNanosecondsStringSchema,
226
+ i as BeaconEventNumberSchema,
227
+ I as BeaconEventPropertiesSchema,
228
+ ce as BeaconEventSchema,
229
+ o as BeaconEventShortStringSchema,
230
+ l as BeaconEventTimestampStringSchema,
231
+ Q as BeginCheckoutEventSchema,
232
+ L as BeginCheckoutPropertiesSchema,
233
+ T as MONETARY_AMOUNT_REGEX,
234
+ ee as MessageBouncedEventSchema,
235
+ U as MessageBouncedPropertiesSchema,
236
+ G as MessageChannelSchema,
237
+ te as MessageClickedEventSchema,
238
+ oe as MessageComplainedEventSchema,
239
+ k as MessageComplainedPropertiesSchema,
240
+ Z as MessageDeliveredEventSchema,
241
+ r as MessageEventPropertiesSchema,
242
+ ie as MessageFailedEventSchema,
243
+ f as MessageFailedPropertiesSchema,
244
+ ne as MessageOpenedEventSchema,
245
+ ae as MessageReadEventSchema,
246
+ J as MessageSentEventSchema,
247
+ w as PageViewEventSchema,
248
+ A as PageViewPropertiesSchema,
249
+ H as ProductClickEventSchema,
250
+ M as ProductClickPropertiesSchema,
251
+ F as ProductImpressionEventSchema,
252
+ S as ProductImpressionPropertiesSchema,
253
+ K as ProductViewEventSchema,
254
+ R as ProductViewPropertiesSchema,
255
+ z as PurchaseEventSchema,
256
+ x as PurchaseProductSchema,
257
+ V as PurchasePropertiesSchema,
258
+ $ as QRScannedEventSchema,
259
+ j as QRScannedPropertiesSchema,
260
+ u as RFM_SEGMENT_KEYS,
261
+ q as RemoveFromCartEventSchema,
262
+ y as RemoveFromCartPropertiesSchema,
263
+ b as RfmSegmentKeySchema,
264
+ W as SearchSubmittedEventSchema,
265
+ D as SearchSubmittedPropertiesSchema,
266
+ Y as ViewCartEventSchema,
267
+ B as ViewCartPropertiesSchema,
268
+ re as deserializeBeaconEvent
269
+ };
@@ -0,0 +1,36 @@
1
+ import { InferOutput } from 'valibot';
2
+ import * as v from "valibot";
3
+ export declare const ChallengeProvider: {
4
+ readonly TURNSTILE: "turnstile";
5
+ };
6
+ export declare const ChallengeProviders: readonly ["turnstile"];
7
+ export type ChallengeProvider = (typeof ChallengeProviders)[number];
8
+ export declare const ChallengeProviderSchema: v.PicklistSchema<readonly ["turnstile"], undefined>;
9
+ export declare const ChallengeType: {
10
+ readonly TURNSTILE_INVISIBLE: "turnstile_invisible";
11
+ readonly TURNSTILE_MANAGED: "turnstile_managed";
12
+ readonly TURNSTILE_INTERACTIVE: "turnstile_interactive";
13
+ };
14
+ export declare const ChallengeTypes: readonly ["turnstile_invisible", "turnstile_managed", "turnstile_interactive"];
15
+ export type ChallengeType = (typeof ChallengeTypes)[number];
16
+ export declare const ChallengeTypeSchema: v.PicklistSchema<readonly ["turnstile_invisible", "turnstile_managed", "turnstile_interactive"], undefined>;
17
+ export declare const ChallengePurpose: {
18
+ readonly EXPERIENCE_ENTRY: "experience_entry";
19
+ };
20
+ export declare const ChallengePurposes: readonly ["experience_entry"];
21
+ export type ChallengePurpose = (typeof ChallengePurposes)[number];
22
+ export declare const ChallengePurposeSchema: v.PicklistSchema<readonly ["experience_entry"], undefined>;
23
+ export declare const RoutingChallengeSchema: v.ObjectSchema<{
24
+ readonly id: v.StringSchema<undefined>;
25
+ readonly provider: v.LiteralSchema<"turnstile", undefined>;
26
+ readonly type: v.PicklistSchema<readonly ["turnstile_invisible", "turnstile_managed", "turnstile_interactive"], undefined>;
27
+ readonly iframeUrl: v.StringSchema<undefined>;
28
+ readonly expiresAt: v.StringSchema<undefined>;
29
+ }, undefined>;
30
+ export type RoutingChallenge = InferOutput<typeof RoutingChallengeSchema>;
31
+ export declare const BotMitigationStateSchema: v.ObjectSchema<{
32
+ readonly attemptsRemaining: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
33
+ readonly blockedUntil: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
34
+ readonly message: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
35
+ }, undefined>;
36
+ export type BotMitigationState = InferOutput<typeof BotMitigationStateSchema>;
@@ -0,0 +1,37 @@
1
+ import * as e from "valibot";
2
+ const n = {
3
+ TURNSTILE: "turnstile"
4
+ }, i = [n.TURNSTILE], a = e.picklist(i), t = {
5
+ TURNSTILE_INVISIBLE: "turnstile_invisible",
6
+ TURNSTILE_MANAGED: "turnstile_managed",
7
+ TURNSTILE_INTERACTIVE: "turnstile_interactive"
8
+ }, l = [
9
+ t.TURNSTILE_INVISIBLE,
10
+ t.TURNSTILE_MANAGED,
11
+ t.TURNSTILE_INTERACTIVE
12
+ ], s = e.picklist(l), o = {
13
+ EXPERIENCE_ENTRY: "experience_entry"
14
+ }, r = [o.EXPERIENCE_ENTRY], E = e.picklist(r), T = e.object({
15
+ id: e.string(),
16
+ provider: e.literal(n.TURNSTILE),
17
+ type: s,
18
+ iframeUrl: e.string(),
19
+ expiresAt: e.string()
20
+ }), c = e.object({
21
+ attemptsRemaining: e.optional(e.number()),
22
+ blockedUntil: e.optional(e.string()),
23
+ message: e.optional(e.string())
24
+ });
25
+ export {
26
+ c as BotMitigationStateSchema,
27
+ n as ChallengeProvider,
28
+ a as ChallengeProviderSchema,
29
+ i as ChallengeProviders,
30
+ o as ChallengePurpose,
31
+ E as ChallengePurposeSchema,
32
+ r as ChallengePurposes,
33
+ t as ChallengeType,
34
+ s as ChallengeTypeSchema,
35
+ l as ChallengeTypes,
36
+ T as RoutingChallengeSchema
37
+ };