@01.software/sdk 0.13.0 → 0.15.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/index.d.cts CHANGED
@@ -1,16 +1,17 @@
1
- import { O as Order, a as Cart, b as CartItem, P as Product, c as OrderItem$1, T as Transaction, d as Fulfillment, R as Return } from './payload-types-DqX4iuTW.cjs';
2
- export { D as Document, I as Image, e as Post, f as PostCategory, g as PostTag, h as ProductVariant, i as Tenant, V as Video } from './payload-types-DqX4iuTW.cjs';
1
+ import { O as Order, a as Cart, b as CartItem, P as Product, c as OrderItem$1, T as Transaction, d as Fulfillment, R as Return } from './payload-types-Cjbr7XZZ.cjs';
2
+ export { D as Document, I as Image, e as Post, f as PostCategory, g as PostTag, h as ProductVariant, i as Tenant, V as Video } from './payload-types-Cjbr7XZZ.cjs';
3
3
  import { Sort, Where } from 'payload';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
5
  import { QueryClient, InfiniteData } from '@tanstack/react-query';
6
6
  import { Metadata } from 'next';
7
- import { C as CollectionType } from './webhook-mXjcW86I.cjs';
8
- export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-mXjcW86I.cjs';
9
- import { P as PublicCollection } from './const-DqcpKgSA.cjs';
10
- export { a as COLLECTIONS, C as Collection } from './const-DqcpKgSA.cjs';
7
+ import { C as CollectionType } from './webhook-BVA28ptL.cjs';
8
+ export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-BVA28ptL.cjs';
9
+ import { P as PublicCollection } from './const-9RunqFfj.cjs';
10
+ export { a as COLLECTIONS, C as Collection } from './const-9RunqFfj.cjs';
11
11
  export { a as RealtimeConnection, R as RealtimeEvent, b as RealtimeListener } from './realtime-D7HtUpqt.cjs';
12
12
  export { b as IMAGE_SIZES, I as ImageData, a as ImagePalette, f as ImagePlaceholderOptions, d as getImageLqip, e as getImagePalette, h as getImagePlaceholderStyle, c as getImageSrcSet, g as getImageUrl } from './image-TT8lTsk5.cjs';
13
13
  export { e as VideoGifOptions, V as VideoThumbnailOptions, a as getVideoGif, c as getVideoMp4Url, d as getVideoStoryboard, b as getVideoStreamUrl, g as getVideoThumbnail } from './video-DbLL8yuc.cjs';
14
+ export { Analytics, AnalyticsConfig, createAnalytics } from './analytics.cjs';
14
15
 
15
16
  declare function resolveApiUrl(): string;
16
17
  interface ClientConfig {
package/dist/index.d.ts CHANGED
@@ -1,16 +1,17 @@
1
- import { O as Order, a as Cart, b as CartItem, P as Product, c as OrderItem$1, T as Transaction, d as Fulfillment, R as Return } from './payload-types-DqX4iuTW.js';
2
- export { D as Document, I as Image, e as Post, f as PostCategory, g as PostTag, h as ProductVariant, i as Tenant, V as Video } from './payload-types-DqX4iuTW.js';
1
+ import { O as Order, a as Cart, b as CartItem, P as Product, c as OrderItem$1, T as Transaction, d as Fulfillment, R as Return } from './payload-types-Cjbr7XZZ.js';
2
+ export { D as Document, I as Image, e as Post, f as PostCategory, g as PostTag, h as ProductVariant, i as Tenant, V as Video } from './payload-types-Cjbr7XZZ.js';
3
3
  import { Sort, Where } from 'payload';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
5
  import { QueryClient, InfiniteData } from '@tanstack/react-query';
6
6
  import { Metadata } from 'next';
7
- import { C as CollectionType } from './webhook-CX21PpBt.js';
8
- export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-CX21PpBt.js';
9
- import { P as PublicCollection } from './const-DSTPrI77.js';
10
- export { a as COLLECTIONS, C as Collection } from './const-DSTPrI77.js';
7
+ import { C as CollectionType } from './webhook-2zxdCwB4.js';
8
+ export { a as WebhookEvent, b as WebhookHandler, W as WebhookOperation, c as WebhookOptions, d as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-2zxdCwB4.js';
9
+ import { P as PublicCollection } from './const-ovU3MmND.js';
10
+ export { a as COLLECTIONS, C as Collection } from './const-ovU3MmND.js';
11
11
  export { a as RealtimeConnection, R as RealtimeEvent, b as RealtimeListener } from './realtime-D7HtUpqt.js';
12
12
  export { b as IMAGE_SIZES, I as ImageData, a as ImagePalette, f as ImagePlaceholderOptions, d as getImageLqip, e as getImagePalette, h as getImagePlaceholderStyle, c as getImageSrcSet, g as getImageUrl } from './image-TT8lTsk5.js';
13
13
  export { e as VideoGifOptions, V as VideoThumbnailOptions, a as getVideoGif, c as getVideoMp4Url, d as getVideoStoryboard, b as getVideoStreamUrl, g as getVideoThumbnail } from './video-DbLL8yuc.js';
14
+ export { Analytics, AnalyticsConfig, createAnalytics } from './analytics.js';
14
15
 
15
16
  declare function resolveApiUrl(): string;
16
17
  interface ClientConfig {
package/dist/index.js CHANGED
@@ -3035,6 +3035,178 @@ function getVideoStreamUrl(playbackId) {
3035
3035
  function getVideoMp4Url(playbackId, resolution = "high") {
3036
3036
  return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`;
3037
3037
  }
3038
+
3039
+ // src/analytics.ts
3040
+ function createAnalytics(config) {
3041
+ if (typeof window === "undefined") {
3042
+ return { pageview() {
3043
+ }, track() {
3044
+ }, destroy() {
3045
+ } };
3046
+ }
3047
+ const endpoint = config.endpoint ?? `${resolveApiUrl()}/api/analytics/collect`;
3048
+ const respectDnt = config.respectDnt !== false;
3049
+ function isDntActive() {
3050
+ if (!respectDnt) return false;
3051
+ const nav = navigator;
3052
+ return nav.doNotTrack === "1" || nav.globalPrivacyControl === true;
3053
+ }
3054
+ let lastPath = null;
3055
+ let lastAt = 0;
3056
+ const autoTrack = config.autoTrack !== false;
3057
+ const originalPushState = history.pushState;
3058
+ const originalReplaceState = history.replaceState;
3059
+ let destroyed = false;
3060
+ function newEventId() {
3061
+ return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : String(Date.now()) + String(Math.random());
3062
+ }
3063
+ function sendBeaconOrFetch(body) {
3064
+ try {
3065
+ if (typeof navigator.sendBeacon === "function") {
3066
+ const blob = new Blob([body], { type: "text/plain" });
3067
+ const sent = navigator.sendBeacon(endpoint, blob);
3068
+ if (sent) return;
3069
+ }
3070
+ fetch(endpoint, {
3071
+ method: "POST",
3072
+ keepalive: true,
3073
+ headers: { "Content-Type": "application/json" },
3074
+ body
3075
+ }).catch(() => {
3076
+ });
3077
+ } catch {
3078
+ }
3079
+ }
3080
+ function sendPageview(pathname) {
3081
+ if (isDntActive()) return;
3082
+ const doc = document;
3083
+ if (doc.prerendering === true || document.visibilityState === "prerender") return;
3084
+ const now = Date.now();
3085
+ if (pathname === lastPath && now - lastAt < 500) return;
3086
+ lastPath = pathname;
3087
+ lastAt = now;
3088
+ const body = JSON.stringify({
3089
+ publishableKey: config.publishableKey,
3090
+ pathname,
3091
+ referrer: document.referrer || "",
3092
+ eventId: newEventId(),
3093
+ eventTs: Date.now()
3094
+ });
3095
+ sendBeaconOrFetch(body);
3096
+ }
3097
+ function trackCurrentPath() {
3098
+ if (destroyed) return;
3099
+ sendPageview(location.pathname);
3100
+ }
3101
+ function patchedPushState(data, unused, url) {
3102
+ originalPushState.apply(this, [data, unused, url]);
3103
+ if (!destroyed) setTimeout(trackCurrentPath, 0);
3104
+ }
3105
+ function patchedReplaceState(data, unused, url) {
3106
+ originalReplaceState.apply(this, [data, unused, url]);
3107
+ if (!destroyed) setTimeout(trackCurrentPath, 0);
3108
+ }
3109
+ if (autoTrack) {
3110
+ history.pushState = patchedPushState;
3111
+ history.replaceState = patchedReplaceState;
3112
+ window.addEventListener("popstate", trackCurrentPath);
3113
+ if (document.readyState === "complete") {
3114
+ trackCurrentPath();
3115
+ } else {
3116
+ window.addEventListener("load", trackCurrentPath, { once: true });
3117
+ }
3118
+ }
3119
+ const isProduction = (() => {
3120
+ try {
3121
+ const hostname = location.hostname;
3122
+ return hostname !== "localhost" && hostname !== "127.0.0.1" && !hostname.endsWith(".local");
3123
+ } catch {
3124
+ return true;
3125
+ }
3126
+ })();
3127
+ const warnedReasons = /* @__PURE__ */ new Set();
3128
+ function devWarn(name, reason) {
3129
+ if (isProduction) return;
3130
+ if (warnedReasons.has(reason)) return;
3131
+ warnedReasons.add(reason);
3132
+ console.warn(`[01 analytics] dropped event ${name}: ${reason}`);
3133
+ }
3134
+ const EVENT_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_:-]{0,49}$/;
3135
+ const RESERVED_PREFIXES = ["__", "_pv_"];
3136
+ function validateEventName(name) {
3137
+ if (!name || typeof name !== "string") return "name-empty";
3138
+ for (const prefix of RESERVED_PREFIXES) {
3139
+ if (name.startsWith(prefix)) return "name-reserved";
3140
+ }
3141
+ if (!EVENT_NAME_RE.test(name)) return "name-regex";
3142
+ return null;
3143
+ }
3144
+ const PROP_KEY_RE = /^[a-zA-Z_][a-zA-Z0-9_]{0,31}$/;
3145
+ function validateEventProps(props) {
3146
+ if (props === void 0 || props === null) return null;
3147
+ if (typeof props !== "object" || Array.isArray(props)) return "props-value-type";
3148
+ const keys = Object.keys(props);
3149
+ if (keys.length > 10) return "props-too-many-keys";
3150
+ for (const k of keys) {
3151
+ const v = props[k];
3152
+ if (!PROP_KEY_RE.test(k)) return "props-key-regex";
3153
+ if (typeof v === "string") {
3154
+ if (v.length > 80) return "props-value-too-long";
3155
+ } else if (typeof v === "number") {
3156
+ if (!isFinite(v)) return "props-value-not-finite";
3157
+ } else if (typeof v === "boolean") {
3158
+ } else {
3159
+ return "props-value-type";
3160
+ }
3161
+ }
3162
+ return null;
3163
+ }
3164
+ return {
3165
+ pageview(path) {
3166
+ if (destroyed) return;
3167
+ sendPageview(path ?? location.pathname);
3168
+ },
3169
+ track(name, props) {
3170
+ if (destroyed) return;
3171
+ if (isDntActive()) return;
3172
+ const doc = document;
3173
+ if (doc.prerendering === true || document.visibilityState === "prerender") return;
3174
+ const nameErr = validateEventName(name);
3175
+ if (nameErr) {
3176
+ devWarn(name, nameErr);
3177
+ return;
3178
+ }
3179
+ if (props !== void 0) {
3180
+ const propsErr = validateEventProps(props);
3181
+ if (propsErr) {
3182
+ devWarn(name, propsErr);
3183
+ return;
3184
+ }
3185
+ }
3186
+ const body = JSON.stringify({
3187
+ publishableKey: config.publishableKey,
3188
+ pathname: location.pathname,
3189
+ referrer: document.referrer || "",
3190
+ eventId: newEventId(),
3191
+ eventName: name,
3192
+ eventProps: props,
3193
+ eventTs: Date.now()
3194
+ });
3195
+ sendBeaconOrFetch(body);
3196
+ },
3197
+ destroy() {
3198
+ if (destroyed) return;
3199
+ destroyed = true;
3200
+ if (autoTrack) {
3201
+ history.pushState = originalPushState;
3202
+ history.replaceState = originalReplaceState;
3203
+ window.removeEventListener("popstate", trackCurrentPath);
3204
+ }
3205
+ lastPath = null;
3206
+ lastAt = 0;
3207
+ }
3208
+ };
3209
+ }
3038
3210
  export {
3039
3211
  ApiError,
3040
3212
  AuthError,
@@ -3076,6 +3248,7 @@ export {
3076
3248
  buildProductListingProjection,
3077
3249
  buildProductOptionMatrix,
3078
3250
  collectionKeys,
3251
+ createAnalytics,
3079
3252
  createAuthError,
3080
3253
  createClient,
3081
3254
  createConflictError,