@shware/analytics 11.13.3 → 11.14.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/README.md CHANGED
@@ -149,6 +149,20 @@ function Button() {
149
149
  }
150
150
  ```
151
151
 
152
+ ### Tracking an occurrence once (`trackOnce`)
153
+
154
+ A payment result page can be reloaded or reopened from history, and a store transaction can be delivered again; each would report the same `purchase` again. `trackOnce` takes the key that identifies the occurrence and tracks it at most once per key:
155
+
156
+ ```ts
157
+ import { trackOnce } from '@shware/analytics';
158
+
159
+ trackOnce('purchase', properties, { key: checkoutSessionId });
160
+ ```
161
+
162
+ - `key` is required and never derived from the properties; the same key under another event name is a different occurrence. `ttl` (ms, 90 days by default) is how long a sent key is remembered, up to the 20 latest keys per event.
163
+ - The key is stored in the `storage` given to `setupAnalytics` only once the event has been sent, so a failed send is tried again by the next call; within one page a queued key is not queued twice. The record is plain JSON under `track_once.<event>`, e.g. `{"v":1,"entries":[["cs_test_a1B2c3",1799236800000]]}`; a storage that needs escaping (a cookie) escapes it itself.
164
+ - If the storage cannot be read or written the event is tracked anyway: a rare duplicate beats a lost conversion. Deduplication is per device, so exact figures such as revenue belong to server-side records.
165
+
152
166
  ## Page views
153
167
 
154
168
  `page_view` fires on a path or query change, never on a hash change — GA4's enhanced measurement,
package/dist/index.cjs CHANGED
@@ -2,13 +2,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_setup_index = require("./setup/index.cjs");
3
3
  const require_visitor_id = require("./visitor/id.cjs");
4
4
  const require_track_index = require("./track/index.cjs");
5
+ const require_track_once = require("./track/once.cjs");
5
6
  const require_visitor_index = require("./visitor/index.cjs");
6
7
  const require_feedback_index = require("./feedback/index.cjs");
7
8
  const require_link_index = require("./link/index.cjs");
8
9
  const require_schema_index = require("./schema/index.cjs");
9
10
  const require_bot_index = require("./bot/index.cjs");
10
- const require_utils_stripe = require("./utils/stripe.cjs");
11
+ require("./utils/stripe.cjs");
11
12
  const require_hooks_use_track_impression = require("./hooks/use-track-impression.cjs");
13
+ let _shware_utils = require("@shware/utils");
12
14
  exports.ALL_ENVIRONMENTS = require_schema_index.ALL_ENVIRONMENTS;
13
15
  exports.ALL_PLATFORMS = require_schema_index.ALL_PLATFORMS;
14
16
  exports.BOT_CATEGORIES = require_bot_index.BOT_CATEGORIES;
@@ -26,9 +28,15 @@ exports.sendFeedback = require_feedback_index.sendFeedback;
26
28
  exports.sendPendingEvents = require_track_index.sendPendingEvents;
27
29
  exports.setVisitor = require_visitor_index.setVisitor;
28
30
  exports.setupAnalytics = require_setup_index.setupAnalytics;
29
- exports.stripeMinorUnits = require_utils_stripe.stripeMinorUnits;
31
+ Object.defineProperty(exports, "stripeMinorUnits", {
32
+ enumerable: true,
33
+ get: function() {
34
+ return _shware_utils.stripeMinorUnits;
35
+ }
36
+ });
30
37
  exports.track = require_track_index.track;
31
38
  exports.trackAsync = require_track_index.trackAsync;
39
+ exports.trackOnce = require_track_once.trackOnce;
32
40
  exports.updateVisitorSchema = require_schema_index.updateVisitorSchema;
33
41
  exports.useTrackImpression = require_hooks_use_track_impression.useTrackImpression;
34
42
  exports.visitorId = require_visitor_id.visitorId;
package/dist/index.d.cts CHANGED
@@ -6,8 +6,9 @@ import { useTrackImpression } from "./hooks/use-track-impression.cjs";
6
6
  import { VisitorProperties } from "./visitor/types.cjs";
7
7
  import { setupAnalytics } from "./setup/index.cjs";
8
8
  import { sendBeacon, sendPendingEvents, track, trackAsync } from "./track/index.cjs";
9
+ import { TrackOnceOptions, trackOnce } from "./track/once.cjs";
9
10
  import { visitorId } from "./visitor/id.cjs";
10
11
  import { IDENTIFY_EVENT, setVisitor } from "./visitor/index.cjs";
11
12
  import { Link, createLink, getLink } from "./link/index.cjs";
12
13
  import { stripeMinorUnits } from "./utils/stripe.cjs";
13
- export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, BOT_CATEGORIES, type Bot, type BotCategory, type CreateFeedbackDTO, type CreateLinkDTO, type CreateTrackEventDTO, type CreateVisitorDTO, type CustomEventProperties, type Environment, IDENTIFY_EVENT, type Link, NOT_A_BOT, type Platform, type TrackProperties, type TrackTags, type UTMParams, type UpdateVisitorDTO, type UserProvidedData, type VisitorProperties, botOf, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, sendBeacon, sendFeedback, sendPendingEvents, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, updateVisitorSchema, useTrackImpression, visitorId };
14
+ export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, BOT_CATEGORIES, type Bot, type BotCategory, type CreateFeedbackDTO, type CreateLinkDTO, type CreateTrackEventDTO, type CreateVisitorDTO, type CustomEventProperties, type Environment, IDENTIFY_EVENT, type Link, NOT_A_BOT, type Platform, type TrackOnceOptions, type TrackProperties, type TrackTags, type UTMParams, type UpdateVisitorDTO, type UserProvidedData, type VisitorProperties, botOf, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, sendBeacon, sendFeedback, sendPendingEvents, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, trackOnce, updateVisitorSchema, useTrackImpression, visitorId };
package/dist/index.d.mts CHANGED
@@ -6,8 +6,9 @@ import { useTrackImpression } from "./hooks/use-track-impression.mjs";
6
6
  import { VisitorProperties } from "./visitor/types.mjs";
7
7
  import { setupAnalytics } from "./setup/index.mjs";
8
8
  import { sendBeacon, sendPendingEvents, track, trackAsync } from "./track/index.mjs";
9
+ import { TrackOnceOptions, trackOnce } from "./track/once.mjs";
9
10
  import { visitorId } from "./visitor/id.mjs";
10
11
  import { IDENTIFY_EVENT, setVisitor } from "./visitor/index.mjs";
11
12
  import { Link, createLink, getLink } from "./link/index.mjs";
12
13
  import { stripeMinorUnits } from "./utils/stripe.mjs";
13
- export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, BOT_CATEGORIES, type Bot, type BotCategory, type CreateFeedbackDTO, type CreateLinkDTO, type CreateTrackEventDTO, type CreateVisitorDTO, type CustomEventProperties, type Environment, IDENTIFY_EVENT, type Link, NOT_A_BOT, type Platform, type TrackProperties, type TrackTags, type UTMParams, type UpdateVisitorDTO, type UserProvidedData, type VisitorProperties, botOf, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, sendBeacon, sendFeedback, sendPendingEvents, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, updateVisitorSchema, useTrackImpression, visitorId };
14
+ export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, BOT_CATEGORIES, type Bot, type BotCategory, type CreateFeedbackDTO, type CreateLinkDTO, type CreateTrackEventDTO, type CreateVisitorDTO, type CustomEventProperties, type Environment, IDENTIFY_EVENT, type Link, NOT_A_BOT, type Platform, type TrackOnceOptions, type TrackProperties, type TrackTags, type UTMParams, type UpdateVisitorDTO, type UserProvidedData, type VisitorProperties, botOf, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, sendBeacon, sendFeedback, sendPendingEvents, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, trackOnce, updateVisitorSchema, useTrackImpression, visitorId };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { setupAnalytics } from "./setup/index.mjs";
2
2
  import { visitorId } from "./visitor/id.mjs";
3
3
  import { sendBeacon, sendPendingEvents, track, trackAsync } from "./track/index.mjs";
4
+ import { trackOnce } from "./track/once.mjs";
4
5
  import { IDENTIFY_EVENT, setVisitor } from "./visitor/index.mjs";
5
6
  import { sendFeedback } from "./feedback/index.mjs";
6
7
  import { createLink, getLink } from "./link/index.mjs";
@@ -8,4 +9,4 @@ import { ALL_ENVIRONMENTS, ALL_PLATFORMS, createFeedbackSchema, createLinkSchema
8
9
  import { BOT_CATEGORIES, NOT_A_BOT, botOf } from "./bot/index.mjs";
9
10
  import { stripeMinorUnits } from "./utils/stripe.mjs";
10
11
  import { useTrackImpression } from "./hooks/use-track-impression.mjs";
11
- export { ALL_ENVIRONMENTS, ALL_PLATFORMS, BOT_CATEGORIES, IDENTIFY_EVENT, NOT_A_BOT, botOf, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, sendBeacon, sendFeedback, sendPendingEvents, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, updateVisitorSchema, useTrackImpression, visitorId };
12
+ export { ALL_ENVIRONMENTS, ALL_PLATFORMS, BOT_CATEGORIES, IDENTIFY_EVENT, NOT_A_BOT, botOf, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, sendBeacon, sendFeedback, sendPendingEvents, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, trackOnce, updateVisitorSchema, useTrackImpression, visitorId };
@@ -0,0 +1,111 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_setup_index = require("../setup/index.cjs");
3
+ const require_track_index = require("./index.cjs");
4
+ //#region src/track/once.ts
5
+ const DEFAULT_TTL = 7776e6;
6
+ /**
7
+ * `{"v":1,"entries":[[key, expiresAt], …]}`, oldest first. Entries are tuples in an array rather
8
+ * than an object keyed by `key`: an object would move integer-like keys ("123") to the front and
9
+ * lose the order the oldest are dropped by. Escaping the value for the medium is the storage's
10
+ * job, so this is plain JSON.
11
+ */
12
+ const VERSION = 1;
13
+ function storageKey(name) {
14
+ return `track_once.${name}`;
15
+ }
16
+ /** The stored entries, or none for a record that is missing, of another version or malformed. */
17
+ function read(name) {
18
+ const raw = require_setup_index.config.storage.getItem(storageKey(name));
19
+ if (!raw) return [];
20
+ let record;
21
+ try {
22
+ record = JSON.parse(raw);
23
+ } catch {
24
+ return [];
25
+ }
26
+ if (typeof record !== "object" || record === null) return [];
27
+ const { v, entries } = record;
28
+ if (v !== VERSION || !Array.isArray(entries)) return [];
29
+ return entries.flatMap((entry) => {
30
+ if (!Array.isArray(entry)) return [];
31
+ const [key, expiresAt] = entry;
32
+ if (typeof key !== "string" || typeof expiresAt !== "number") return [];
33
+ return [{
34
+ key,
35
+ expiresAt
36
+ }];
37
+ });
38
+ }
39
+ function write(name, entries) {
40
+ const record = {
41
+ v: VERSION,
42
+ entries: entries.slice(-20).map((entry) => [entry.key, entry.expiresAt])
43
+ };
44
+ require_setup_index.config.storage.setItem(storageKey(name), JSON.stringify(record));
45
+ }
46
+ function live(entries, now) {
47
+ return entries.filter((entry) => entry.expiresAt > now);
48
+ }
49
+ /** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */
50
+ const pending = /* @__PURE__ */ new Map();
51
+ function isPending(name, key) {
52
+ return pending.get(name)?.has(key) ?? false;
53
+ }
54
+ function markPending(name, key) {
55
+ const keys = pending.get(name);
56
+ if (keys) keys.add(key);
57
+ else pending.set(name, /* @__PURE__ */ new Set([key]));
58
+ }
59
+ function clearPending(name, key) {
60
+ const keys = pending.get(name);
61
+ if (!keys) return;
62
+ keys.delete(key);
63
+ if (keys.size === 0) pending.delete(name);
64
+ }
65
+ /**
66
+ * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a
67
+ * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
68
+ * was queued.
69
+ *
70
+ * The key is remembered in `config.storage` only once the event has been sent (`onSucceed`), so a
71
+ * send that fails is tried again by the next call instead of being lost; within one page a key
72
+ * already queued is not queued twice. When the storage cannot be read or written the event is
73
+ * tracked anyway: a rare duplicate is better than a lost conversion.
74
+ *
75
+ * Deduplication is per device and storage. A second device still reports its own occurrence, so
76
+ * figures that must be exact (revenue) belong to server-side records.
77
+ */
78
+ function trackOnce(name, properties, { key, ttl = DEFAULT_TTL, ...options }) {
79
+ if (isPending(name, key)) return false;
80
+ const now = Date.now();
81
+ try {
82
+ if (live(read(name), now).some((entry) => entry.key === key)) return false;
83
+ } catch (e) {
84
+ if (e instanceof Error) console.log(e.message);
85
+ }
86
+ markPending(name, key);
87
+ require_track_index.track(name, properties, {
88
+ ...options,
89
+ onSucceed: (response) => {
90
+ clearPending(name, key);
91
+ try {
92
+ write(name, [...live(read(name), Date.now()).filter((entry) => entry.key !== key), {
93
+ key,
94
+ expiresAt: Date.now() + ttl
95
+ }]);
96
+ } catch (e) {
97
+ if (e instanceof Error) console.log(e.message);
98
+ }
99
+ options.onSucceed?.(response);
100
+ },
101
+ onError: (error) => {
102
+ clearPending(name, key);
103
+ options.onError?.(error);
104
+ }
105
+ });
106
+ return true;
107
+ }
108
+ //#endregion
109
+ exports.trackOnce = trackOnce;
110
+
111
+ //# sourceMappingURL=once.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once.cjs","names":["config"],"sources":["../../src/track/once.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport { type TrackOptions, track } from './index';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport interface TrackOnceOptions extends TrackOptions {\n /**\n * What makes this occurrence the same one again: a checkout session id for `purchase`, an order\n * id, a transaction id. Required, never derived from the properties, so the caller decides what\n * \"once\" means. The same key under another event name is a different occurrence.\n */\n key: string;\n /** How long a sent key is remembered, in milliseconds. 90 days by default. */\n ttl?: number;\n}\n\nconst DEFAULT_TTL = 90 * 24 * 60 * 60 * 1000;\n/** Keys remembered per event name; the oldest are forgotten first. */\nconst MAX_ENTRIES = 20;\n\n/**\n * `{\"v\":1,\"entries\":[[key, expiresAt], …]}`, oldest first. Entries are tuples in an array rather\n * than an object keyed by `key`: an object would move integer-like keys (\"123\") to the front and\n * lose the order the oldest are dropped by. Escaping the value for the medium is the storage's\n * job, so this is plain JSON.\n */\nconst VERSION = 1;\n\ntype Entry = { key: string; expiresAt: number };\n\nfunction storageKey(name: string) {\n return `track_once.${name}`;\n}\n\n/** The stored entries, or none for a record that is missing, of another version or malformed. */\nfunction read(name: string): Entry[] {\n const raw = config.storage.getItem(storageKey(name));\n if (!raw) return [];\n let record: unknown;\n try {\n record = JSON.parse(raw);\n } catch {\n return [];\n }\n if (typeof record !== 'object' || record === null) return [];\n const { v, entries } = record as { v?: unknown; entries?: unknown };\n if (v !== VERSION || !Array.isArray(entries)) return [];\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, expiresAt] = entry as unknown[];\n if (typeof key !== 'string' || typeof expiresAt !== 'number') return [];\n return [{ key, expiresAt }];\n });\n}\n\nfunction write(name: string, entries: Entry[]) {\n const record = {\n v: VERSION,\n entries: entries.slice(-MAX_ENTRIES).map((entry) => [entry.key, entry.expiresAt]),\n };\n config.storage.setItem(storageKey(name), JSON.stringify(record));\n}\n\nfunction live(entries: Entry[], now: number) {\n return entries.filter((entry) => entry.expiresAt > now);\n}\n\n/** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */\nconst pending = new Map<string, Set<string>>();\n\nfunction isPending(name: string, key: string) {\n return pending.get(name)?.has(key) ?? false;\n}\n\nfunction markPending(name: string, key: string) {\n const keys = pending.get(name);\n if (keys) keys.add(key);\n else pending.set(name, new Set([key]));\n}\n\nfunction clearPending(name: string, key: string) {\n const keys = pending.get(name);\n if (!keys) return;\n keys.delete(key);\n if (keys.size === 0) pending.delete(name);\n}\n\n/**\n * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a\n * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event\n * was queued.\n *\n * The key is remembered in `config.storage` only once the event has been sent (`onSucceed`), so a\n * send that fails is tried again by the next call instead of being lost; within one page a key\n * already queued is not queued twice. When the storage cannot be read or written the event is\n * tracked anyway: a rare duplicate is better than a lost conversion.\n *\n * Deduplication is per device and storage. A second device still reports its own occurrence, so\n * figures that must be exact (revenue) belong to server-side records.\n */\nexport function trackOnce<T extends EventName = EventName>(\n name: TrackName<T>,\n properties: TrackProperties<T> | undefined,\n { key, ttl = DEFAULT_TTL, ...options }: TrackOnceOptions\n): boolean {\n if (isPending(name, key)) return false;\n\n const now = Date.now();\n try {\n if (live(read(name), now).some((entry) => entry.key === key)) return false;\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n\n markPending(name, key);\n track(name, properties, {\n ...options,\n onSucceed: (response) => {\n clearPending(name, key);\n try {\n const entries = live(read(name), Date.now()).filter((entry) => entry.key !== key);\n write(name, [...entries, { key, expiresAt: Date.now() + ttl }]);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n options.onSucceed?.(response);\n },\n onError: (error) => {\n // Not sent: forget it here so a later call can try again.\n clearPending(name, key);\n options.onError?.(error);\n },\n });\n return true;\n}\n"],"mappings":";;;;AAeA,MAAM,cAAc;;;;;;;AAUpB,MAAM,UAAU;AAIhB,SAAS,WAAW,MAAc;CAChC,OAAO,cAAc;AACvB;;AAGA,SAAS,KAAK,MAAuB;CACnC,MAAM,MAAMA,oBAAAA,OAAO,QAAQ,QAAQ,WAAW,IAAI,CAAC;CACnD,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,QAAQ;EACN,OAAO,CAAC;CACV;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO,CAAC;CAC3D,MAAM,EAAE,GAAG,YAAY;CACvB,IAAI,MAAM,WAAW,CAAC,MAAM,QAAQ,OAAO,GAAG,OAAO,CAAC;CACtD,OAAO,QAAQ,SAAS,UAAmB;EACzC,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;EACnC,MAAM,CAAC,KAAK,aAAa;EACzB,IAAI,OAAO,QAAQ,YAAY,OAAO,cAAc,UAAU,OAAO,CAAC;EACtE,OAAO,CAAC;GAAE;GAAK;EAAU,CAAC;CAC5B,CAAC;AACH;AAEA,SAAS,MAAM,MAAc,SAAkB;CAC7C,MAAM,SAAS;EACb,GAAG;EACH,SAAS,QAAQ,MAAM,GAAY,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,KAAK,MAAM,SAAS,CAAC;CAClF;CACA,oBAAA,OAAO,QAAQ,QAAQ,WAAW,IAAI,GAAG,KAAK,UAAU,MAAM,CAAC;AACjE;AAEA,SAAS,KAAK,SAAkB,KAAa;CAC3C,OAAO,QAAQ,QAAQ,UAAU,MAAM,YAAY,GAAG;AACxD;;AAGA,MAAM,0BAAU,IAAI,IAAyB;AAE7C,SAAS,UAAU,MAAc,KAAa;CAC5C,OAAO,QAAQ,IAAI,IAAI,CAAC,EAAE,IAAI,GAAG,KAAK;AACxC;AAEA,SAAS,YAAY,MAAc,KAAa;CAC9C,MAAM,OAAO,QAAQ,IAAI,IAAI;CAC7B,IAAI,MAAM,KAAK,IAAI,GAAG;MACjB,QAAQ,IAAI,sBAAM,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;AACvC;AAEA,SAAS,aAAa,MAAc,KAAa;CAC/C,MAAM,OAAO,QAAQ,IAAI,IAAI;CAC7B,IAAI,CAAC,MAAM;CACX,KAAK,OAAO,GAAG;CACf,IAAI,KAAK,SAAS,GAAG,QAAQ,OAAO,IAAI;AAC1C;;;;;;;;;;;;;;AAeA,SAAgB,UACd,MACA,YACA,EAAE,KAAK,MAAM,aAAa,GAAG,WACpB;CACT,IAAI,UAAU,MAAM,GAAG,GAAG,OAAO;CAEjC,MAAM,MAAM,KAAK,IAAI;CACrB,IAAI;EACF,IAAI,KAAK,KAAK,IAAI,GAAG,GAAG,CAAC,CAAC,MAAM,UAAU,MAAM,QAAQ,GAAG,GAAG,OAAO;CACvE,SAAS,GAAY;EACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;CAC/C;CAEA,YAAY,MAAM,GAAG;CACrB,oBAAA,MAAM,MAAM,YAAY;EACtB,GAAG;EACH,YAAY,aAAa;GACvB,aAAa,MAAM,GAAG;GACtB,IAAI;IAEF,MAAM,MAAM,CAAC,GADG,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,UAAU,MAAM,QAAQ,GACvD,GAAG;KAAE;KAAK,WAAW,KAAK,IAAI,IAAI;IAAI,CAAC,CAAC;GAChE,SAAS,GAAY;IACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;GAC/C;GACA,QAAQ,YAAY,QAAQ;EAC9B;EACA,UAAU,UAAU;GAElB,aAAa,MAAM,GAAG;GACtB,QAAQ,UAAU,KAAK;EACzB;CACF,CAAC;CACD,OAAO;AACT"}
@@ -0,0 +1,29 @@
1
+ import { EventName, TrackName, TrackProperties } from "./types.cjs";
2
+ import { TrackOptions } from "./index.cjs";
3
+ //#region src/track/once.d.ts
4
+ export interface TrackOnceOptions extends TrackOptions {
5
+ /**
6
+ * What makes this occurrence the same one again: a checkout session id for `purchase`, an order
7
+ * id, a transaction id. Required, never derived from the properties, so the caller decides what
8
+ * "once" means. The same key under another event name is a different occurrence.
9
+ */
10
+ key: string;
11
+ /** How long a sent key is remembered, in milliseconds. 90 days by default. */
12
+ ttl?: number;
13
+ }
14
+ /**
15
+ * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a
16
+ * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
17
+ * was queued.
18
+ *
19
+ * The key is remembered in `config.storage` only once the event has been sent (`onSucceed`), so a
20
+ * send that fails is tried again by the next call instead of being lost; within one page a key
21
+ * already queued is not queued twice. When the storage cannot be read or written the event is
22
+ * tracked anyway: a rare duplicate is better than a lost conversion.
23
+ *
24
+ * Deduplication is per device and storage. A second device still reports its own occurrence, so
25
+ * figures that must be exact (revenue) belong to server-side records.
26
+ */
27
+ export declare function trackOnce<T extends EventName = EventName>(name: TrackName<T>, properties: TrackProperties<T> | undefined, { key, ttl, ...options }: TrackOnceOptions): boolean;
28
+ //#endregion
29
+ //# sourceMappingURL=once.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once.d.cts","names":[],"sources":["../../src/track/once.ts"],"mappings":";;;iBAIiB,yBAAyB;;;;;;EAMxC;;EAEA;;;;;;;;;;;;;;;wBAuFc,UAAU,UAAU,YAAY,WAC9C,MAAM,UAAU,IAChB,YAAY,gBAAgB,kBAC1B,KAAK,QAAsB,WAAW"}
@@ -0,0 +1,29 @@
1
+ import { EventName, TrackName, TrackProperties } from "./types.mjs";
2
+ import { TrackOptions } from "./index.mjs";
3
+ //#region src/track/once.d.ts
4
+ export interface TrackOnceOptions extends TrackOptions {
5
+ /**
6
+ * What makes this occurrence the same one again: a checkout session id for `purchase`, an order
7
+ * id, a transaction id. Required, never derived from the properties, so the caller decides what
8
+ * "once" means. The same key under another event name is a different occurrence.
9
+ */
10
+ key: string;
11
+ /** How long a sent key is remembered, in milliseconds. 90 days by default. */
12
+ ttl?: number;
13
+ }
14
+ /**
15
+ * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a
16
+ * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
17
+ * was queued.
18
+ *
19
+ * The key is remembered in `config.storage` only once the event has been sent (`onSucceed`), so a
20
+ * send that fails is tried again by the next call instead of being lost; within one page a key
21
+ * already queued is not queued twice. When the storage cannot be read or written the event is
22
+ * tracked anyway: a rare duplicate is better than a lost conversion.
23
+ *
24
+ * Deduplication is per device and storage. A second device still reports its own occurrence, so
25
+ * figures that must be exact (revenue) belong to server-side records.
26
+ */
27
+ export declare function trackOnce<T extends EventName = EventName>(name: TrackName<T>, properties: TrackProperties<T> | undefined, { key, ttl, ...options }: TrackOnceOptions): boolean;
28
+ //#endregion
29
+ //# sourceMappingURL=once.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once.d.mts","names":[],"sources":["../../src/track/once.ts"],"mappings":";;;iBAIiB,yBAAyB;;;;;;EAMxC;;EAEA;;;;;;;;;;;;;;;wBAuFc,UAAU,UAAU,YAAY,WAC9C,MAAM,UAAU,IAChB,YAAY,gBAAgB,kBAC1B,KAAK,QAAsB,WAAW"}
@@ -0,0 +1,110 @@
1
+ import { config } from "../setup/index.mjs";
2
+ import { track } from "./index.mjs";
3
+ //#region src/track/once.ts
4
+ const DEFAULT_TTL = 7776e6;
5
+ /**
6
+ * `{"v":1,"entries":[[key, expiresAt], …]}`, oldest first. Entries are tuples in an array rather
7
+ * than an object keyed by `key`: an object would move integer-like keys ("123") to the front and
8
+ * lose the order the oldest are dropped by. Escaping the value for the medium is the storage's
9
+ * job, so this is plain JSON.
10
+ */
11
+ const VERSION = 1;
12
+ function storageKey(name) {
13
+ return `track_once.${name}`;
14
+ }
15
+ /** The stored entries, or none for a record that is missing, of another version or malformed. */
16
+ function read(name) {
17
+ const raw = config.storage.getItem(storageKey(name));
18
+ if (!raw) return [];
19
+ let record;
20
+ try {
21
+ record = JSON.parse(raw);
22
+ } catch {
23
+ return [];
24
+ }
25
+ if (typeof record !== "object" || record === null) return [];
26
+ const { v, entries } = record;
27
+ if (v !== VERSION || !Array.isArray(entries)) return [];
28
+ return entries.flatMap((entry) => {
29
+ if (!Array.isArray(entry)) return [];
30
+ const [key, expiresAt] = entry;
31
+ if (typeof key !== "string" || typeof expiresAt !== "number") return [];
32
+ return [{
33
+ key,
34
+ expiresAt
35
+ }];
36
+ });
37
+ }
38
+ function write(name, entries) {
39
+ const record = {
40
+ v: VERSION,
41
+ entries: entries.slice(-20).map((entry) => [entry.key, entry.expiresAt])
42
+ };
43
+ config.storage.setItem(storageKey(name), JSON.stringify(record));
44
+ }
45
+ function live(entries, now) {
46
+ return entries.filter((entry) => entry.expiresAt > now);
47
+ }
48
+ /** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */
49
+ const pending = /* @__PURE__ */ new Map();
50
+ function isPending(name, key) {
51
+ return pending.get(name)?.has(key) ?? false;
52
+ }
53
+ function markPending(name, key) {
54
+ const keys = pending.get(name);
55
+ if (keys) keys.add(key);
56
+ else pending.set(name, /* @__PURE__ */ new Set([key]));
57
+ }
58
+ function clearPending(name, key) {
59
+ const keys = pending.get(name);
60
+ if (!keys) return;
61
+ keys.delete(key);
62
+ if (keys.size === 0) pending.delete(name);
63
+ }
64
+ /**
65
+ * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a
66
+ * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event
67
+ * was queued.
68
+ *
69
+ * The key is remembered in `config.storage` only once the event has been sent (`onSucceed`), so a
70
+ * send that fails is tried again by the next call instead of being lost; within one page a key
71
+ * already queued is not queued twice. When the storage cannot be read or written the event is
72
+ * tracked anyway: a rare duplicate is better than a lost conversion.
73
+ *
74
+ * Deduplication is per device and storage. A second device still reports its own occurrence, so
75
+ * figures that must be exact (revenue) belong to server-side records.
76
+ */
77
+ function trackOnce(name, properties, { key, ttl = DEFAULT_TTL, ...options }) {
78
+ if (isPending(name, key)) return false;
79
+ const now = Date.now();
80
+ try {
81
+ if (live(read(name), now).some((entry) => entry.key === key)) return false;
82
+ } catch (e) {
83
+ if (e instanceof Error) console.log(e.message);
84
+ }
85
+ markPending(name, key);
86
+ track(name, properties, {
87
+ ...options,
88
+ onSucceed: (response) => {
89
+ clearPending(name, key);
90
+ try {
91
+ write(name, [...live(read(name), Date.now()).filter((entry) => entry.key !== key), {
92
+ key,
93
+ expiresAt: Date.now() + ttl
94
+ }]);
95
+ } catch (e) {
96
+ if (e instanceof Error) console.log(e.message);
97
+ }
98
+ options.onSucceed?.(response);
99
+ },
100
+ onError: (error) => {
101
+ clearPending(name, key);
102
+ options.onError?.(error);
103
+ }
104
+ });
105
+ return true;
106
+ }
107
+ //#endregion
108
+ export { trackOnce };
109
+
110
+ //# sourceMappingURL=once.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once.mjs","names":[],"sources":["../../src/track/once.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport { type TrackOptions, track } from './index';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport interface TrackOnceOptions extends TrackOptions {\n /**\n * What makes this occurrence the same one again: a checkout session id for `purchase`, an order\n * id, a transaction id. Required, never derived from the properties, so the caller decides what\n * \"once\" means. The same key under another event name is a different occurrence.\n */\n key: string;\n /** How long a sent key is remembered, in milliseconds. 90 days by default. */\n ttl?: number;\n}\n\nconst DEFAULT_TTL = 90 * 24 * 60 * 60 * 1000;\n/** Keys remembered per event name; the oldest are forgotten first. */\nconst MAX_ENTRIES = 20;\n\n/**\n * `{\"v\":1,\"entries\":[[key, expiresAt], …]}`, oldest first. Entries are tuples in an array rather\n * than an object keyed by `key`: an object would move integer-like keys (\"123\") to the front and\n * lose the order the oldest are dropped by. Escaping the value for the medium is the storage's\n * job, so this is plain JSON.\n */\nconst VERSION = 1;\n\ntype Entry = { key: string; expiresAt: number };\n\nfunction storageKey(name: string) {\n return `track_once.${name}`;\n}\n\n/** The stored entries, or none for a record that is missing, of another version or malformed. */\nfunction read(name: string): Entry[] {\n const raw = config.storage.getItem(storageKey(name));\n if (!raw) return [];\n let record: unknown;\n try {\n record = JSON.parse(raw);\n } catch {\n return [];\n }\n if (typeof record !== 'object' || record === null) return [];\n const { v, entries } = record as { v?: unknown; entries?: unknown };\n if (v !== VERSION || !Array.isArray(entries)) return [];\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, expiresAt] = entry as unknown[];\n if (typeof key !== 'string' || typeof expiresAt !== 'number') return [];\n return [{ key, expiresAt }];\n });\n}\n\nfunction write(name: string, entries: Entry[]) {\n const record = {\n v: VERSION,\n entries: entries.slice(-MAX_ENTRIES).map((entry) => [entry.key, entry.expiresAt]),\n };\n config.storage.setItem(storageKey(name), JSON.stringify(record));\n}\n\nfunction live(entries: Entry[], now: number) {\n return entries.filter((entry) => entry.expiresAt > now);\n}\n\n/** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */\nconst pending = new Map<string, Set<string>>();\n\nfunction isPending(name: string, key: string) {\n return pending.get(name)?.has(key) ?? false;\n}\n\nfunction markPending(name: string, key: string) {\n const keys = pending.get(name);\n if (keys) keys.add(key);\n else pending.set(name, new Set([key]));\n}\n\nfunction clearPending(name: string, key: string) {\n const keys = pending.get(name);\n if (!keys) return;\n keys.delete(key);\n if (keys.size === 0) pending.delete(name);\n}\n\n/**\n * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a\n * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event\n * was queued.\n *\n * The key is remembered in `config.storage` only once the event has been sent (`onSucceed`), so a\n * send that fails is tried again by the next call instead of being lost; within one page a key\n * already queued is not queued twice. When the storage cannot be read or written the event is\n * tracked anyway: a rare duplicate is better than a lost conversion.\n *\n * Deduplication is per device and storage. A second device still reports its own occurrence, so\n * figures that must be exact (revenue) belong to server-side records.\n */\nexport function trackOnce<T extends EventName = EventName>(\n name: TrackName<T>,\n properties: TrackProperties<T> | undefined,\n { key, ttl = DEFAULT_TTL, ...options }: TrackOnceOptions\n): boolean {\n if (isPending(name, key)) return false;\n\n const now = Date.now();\n try {\n if (live(read(name), now).some((entry) => entry.key === key)) return false;\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n\n markPending(name, key);\n track(name, properties, {\n ...options,\n onSucceed: (response) => {\n clearPending(name, key);\n try {\n const entries = live(read(name), Date.now()).filter((entry) => entry.key !== key);\n write(name, [...entries, { key, expiresAt: Date.now() + ttl }]);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n options.onSucceed?.(response);\n },\n onError: (error) => {\n // Not sent: forget it here so a later call can try again.\n clearPending(name, key);\n options.onError?.(error);\n },\n });\n return true;\n}\n"],"mappings":";;;AAeA,MAAM,cAAc;;;;;;;AAUpB,MAAM,UAAU;AAIhB,SAAS,WAAW,MAAc;CAChC,OAAO,cAAc;AACvB;;AAGA,SAAS,KAAK,MAAuB;CACnC,MAAM,MAAM,OAAO,QAAQ,QAAQ,WAAW,IAAI,CAAC;CACnD,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,QAAQ;EACN,OAAO,CAAC;CACV;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO,CAAC;CAC3D,MAAM,EAAE,GAAG,YAAY;CACvB,IAAI,MAAM,WAAW,CAAC,MAAM,QAAQ,OAAO,GAAG,OAAO,CAAC;CACtD,OAAO,QAAQ,SAAS,UAAmB;EACzC,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;EACnC,MAAM,CAAC,KAAK,aAAa;EACzB,IAAI,OAAO,QAAQ,YAAY,OAAO,cAAc,UAAU,OAAO,CAAC;EACtE,OAAO,CAAC;GAAE;GAAK;EAAU,CAAC;CAC5B,CAAC;AACH;AAEA,SAAS,MAAM,MAAc,SAAkB;CAC7C,MAAM,SAAS;EACb,GAAG;EACH,SAAS,QAAQ,MAAM,GAAY,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,KAAK,MAAM,SAAS,CAAC;CAClF;CACA,OAAO,QAAQ,QAAQ,WAAW,IAAI,GAAG,KAAK,UAAU,MAAM,CAAC;AACjE;AAEA,SAAS,KAAK,SAAkB,KAAa;CAC3C,OAAO,QAAQ,QAAQ,UAAU,MAAM,YAAY,GAAG;AACxD;;AAGA,MAAM,0BAAU,IAAI,IAAyB;AAE7C,SAAS,UAAU,MAAc,KAAa;CAC5C,OAAO,QAAQ,IAAI,IAAI,CAAC,EAAE,IAAI,GAAG,KAAK;AACxC;AAEA,SAAS,YAAY,MAAc,KAAa;CAC9C,MAAM,OAAO,QAAQ,IAAI,IAAI;CAC7B,IAAI,MAAM,KAAK,IAAI,GAAG;MACjB,QAAQ,IAAI,sBAAM,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;AACvC;AAEA,SAAS,aAAa,MAAc,KAAa;CAC/C,MAAM,OAAO,QAAQ,IAAI,IAAI;CAC7B,IAAI,CAAC,MAAM;CACX,KAAK,OAAO,GAAG;CACf,IAAI,KAAK,SAAS,GAAG,QAAQ,OAAO,IAAI;AAC1C;;;;;;;;;;;;;;AAeA,SAAgB,UACd,MACA,YACA,EAAE,KAAK,MAAM,aAAa,GAAG,WACpB;CACT,IAAI,UAAU,MAAM,GAAG,GAAG,OAAO;CAEjC,MAAM,MAAM,KAAK,IAAI;CACrB,IAAI;EACF,IAAI,KAAK,KAAK,IAAI,GAAG,GAAG,CAAC,CAAC,MAAM,UAAU,MAAM,QAAQ,GAAG,GAAG,OAAO;CACvE,SAAS,GAAY;EACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;CAC/C;CAEA,YAAY,MAAM,GAAG;CACrB,MAAM,MAAM,YAAY;EACtB,GAAG;EACH,YAAY,aAAa;GACvB,aAAa,MAAM,GAAG;GACtB,IAAI;IAEF,MAAM,MAAM,CAAC,GADG,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,UAAU,MAAM,QAAQ,GACvD,GAAG;KAAE;KAAK,WAAW,KAAK,IAAI,IAAI;IAAI,CAAC,CAAC;GAChE,SAAS,GAAY;IACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;GAC/C;GACA,QAAQ,YAAY,QAAQ;EAC9B;EACA,UAAU,UAAU;GAElB,aAAa,MAAM,GAAG;GACtB,QAAQ,UAAU,KAAK;EACzB;CACF,CAAC;CACD,OAAO;AACT"}
@@ -1,29 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/utils/stripe.ts
3
- const ZERO_DECIMAL_CURRENCIES = [
4
- "BIF",
5
- "CLP",
6
- "DJF",
7
- "GNF",
8
- "JPY",
9
- "KMF",
10
- "KRW",
11
- "MGA",
12
- "PYG",
13
- "RWF",
14
- "UGX",
15
- "VND",
16
- "VUV",
17
- "XAF",
18
- "XOF",
19
- "XPF"
20
- ];
21
- /** reference: https://docs.stripe.com/currencies#zero-decimal */
22
- function stripeMinorUnits(currency) {
23
- return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;
24
- }
25
- //#endregion
26
- exports.ZERO_DECIMAL_CURRENCIES = ZERO_DECIMAL_CURRENCIES;
27
- exports.stripeMinorUnits = stripeMinorUnits;
28
-
29
- //# sourceMappingURL=stripe.cjs.map
2
+ let _shware_utils = require("@shware/utils");
3
+ Object.defineProperty(exports, "ZERO_DECIMAL_CURRENCIES", {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _shware_utils.ZERO_DECIMAL_CURRENCIES;
7
+ }
8
+ });
9
+ Object.defineProperty(exports, "stripeMinorUnits", {
10
+ enumerable: true,
11
+ get: function() {
12
+ return _shware_utils.stripeMinorUnits;
13
+ }
14
+ });
@@ -1,6 +1,2 @@
1
- //#region src/utils/stripe.d.ts
2
- export declare const ZERO_DECIMAL_CURRENCIES: string[];
3
- /** reference: https://docs.stripe.com/currencies#zero-decimal */
4
- export declare function stripeMinorUnits(currency: string): 1 | 100;
5
- //#endregion
6
- //# sourceMappingURL=stripe.d.cts.map
1
+ import { ZERO_DECIMAL_CURRENCIES, stripeMinorUnits } from "@shware/utils";
2
+ export { ZERO_DECIMAL_CURRENCIES, stripeMinorUnits };
@@ -1,6 +1,2 @@
1
- //#region src/utils/stripe.d.ts
2
- export declare const ZERO_DECIMAL_CURRENCIES: string[];
3
- /** reference: https://docs.stripe.com/currencies#zero-decimal */
4
- export declare function stripeMinorUnits(currency: string): 1 | 100;
5
- //#endregion
6
- //# sourceMappingURL=stripe.d.mts.map
1
+ import { ZERO_DECIMAL_CURRENCIES, stripeMinorUnits } from "@shware/utils";
2
+ export { ZERO_DECIMAL_CURRENCIES, stripeMinorUnits };
@@ -1,27 +1 @@
1
- //#region src/utils/stripe.ts
2
- const ZERO_DECIMAL_CURRENCIES = [
3
- "BIF",
4
- "CLP",
5
- "DJF",
6
- "GNF",
7
- "JPY",
8
- "KMF",
9
- "KRW",
10
- "MGA",
11
- "PYG",
12
- "RWF",
13
- "UGX",
14
- "VND",
15
- "VUV",
16
- "XAF",
17
- "XOF",
18
- "XPF"
19
- ];
20
- /** reference: https://docs.stripe.com/currencies#zero-decimal */
21
- function stripeMinorUnits(currency) {
22
- return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;
23
- }
24
- //#endregion
25
- export { ZERO_DECIMAL_CURRENCIES, stripeMinorUnits };
26
-
27
- //# sourceMappingURL=stripe.mjs.map
1
+ export { ZERO_DECIMAL_CURRENCIES, stripeMinorUnits } from "@shware/utils";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "11.13.3",
3
+ "version": "11.14.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -156,7 +156,7 @@
156
156
  "access": "public"
157
157
  },
158
158
  "dependencies": {
159
- "@shware/utils": "^1.7.0",
159
+ "@shware/utils": "^1.8.0",
160
160
  "capi-param-builder-nodejs": "~1.3.2",
161
161
  "cookie": "^2.0.1",
162
162
  "uuid": "^14.0.3",
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripe.cjs","names":[],"sources":["../../src/utils/stripe.ts"],"sourcesContent":["export const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\n/** reference: https://docs.stripe.com/currencies#zero-decimal */\nexport function stripeMinorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n"],"mappings":";;AAAA,MAAa,0BAA0B;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAgB,iBAAiB,UAAkB;CACjD,OAAO,wBAAwB,SAAS,SAAS,YAAY,CAAC,IAAI,IAAI;AACxE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripe.d.cts","names":[],"sources":["../../src/utils/stripe.ts"],"mappings":";qBAAa;;wBAoBG,iBAAiB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripe.d.mts","names":[],"sources":["../../src/utils/stripe.ts"],"mappings":";qBAAa;;wBAoBG,iBAAiB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripe.mjs","names":[],"sources":["../../src/utils/stripe.ts"],"sourcesContent":["export const ZERO_DECIMAL_CURRENCIES = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n];\n\n/** reference: https://docs.stripe.com/currencies#zero-decimal */\nexport function stripeMinorUnits(currency: string) {\n return ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) ? 1 : 100;\n}\n"],"mappings":";AAAA,MAAa,0BAA0B;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAgB,iBAAiB,UAAkB;CACjD,OAAO,wBAAwB,SAAS,SAAS,YAAY,CAAC,IAAI,IAAI;AACxE"}