@fanfare-io/fanfare-sdk-core 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.
Files changed (170) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +44 -0
  3. package/dist/adapters/google-analytics.d.ts +12 -0
  4. package/dist/adapters/google-analytics.js +1 -0
  5. package/dist/adapters/index.d.ts +9 -0
  6. package/dist/adapters/index.js +1 -0
  7. package/dist/adapters/types.d.ts +9 -0
  8. package/dist/appointments/appointment.module.d.ts +32 -0
  9. package/dist/appointments/appointment.module.js +1 -0
  10. package/dist/appointments/index.d.ts +2 -0
  11. package/dist/appointments/public.d.ts +1 -0
  12. package/dist/appointments/public.js +1 -0
  13. package/dist/appointments/types.d.ts +47 -0
  14. package/dist/auctions/auction.module.d.ts +58 -0
  15. package/dist/auctions/auction.module.js +1 -0
  16. package/dist/auctions/index.d.ts +5 -0
  17. package/dist/auctions/public.d.ts +5 -0
  18. package/dist/auctions/public.js +1 -0
  19. package/dist/auctions/types.d.ts +97 -0
  20. package/dist/auth/auth.module.d.ts +71 -0
  21. package/dist/auth/auth.module.js +1 -0
  22. package/dist/auth/index.d.ts +1 -0
  23. package/dist/auth/index.js +1 -0
  24. package/dist/auth/types.d.ts +112 -0
  25. package/dist/beacon/batching.d.ts +52 -0
  26. package/dist/beacon/batching.js +1 -0
  27. package/dist/beacon/beacon.module.d.ts +58 -0
  28. package/dist/beacon/beacon.module.js +1 -0
  29. package/dist/beacon/enrichment.d.ts +16 -0
  30. package/dist/beacon/enrichment.js +1 -0
  31. package/dist/beacon/index.d.ts +12 -0
  32. package/dist/beacon/public.d.ts +9 -0
  33. package/dist/beacon/public.js +1 -0
  34. package/dist/beacon/types.d.ts +103 -0
  35. package/dist/beacon/validation.d.ts +24 -0
  36. package/dist/beacon/validation.js +1 -0
  37. package/dist/challenges/challenge.module.d.ts +9 -0
  38. package/dist/challenges/challenge.module.js +1 -0
  39. package/dist/challenges/index.d.ts +3 -0
  40. package/dist/challenges/public.d.ts +9 -0
  41. package/dist/challenges/public.js +1 -0
  42. package/dist/challenges/types.d.ts +33 -0
  43. package/dist/config/index.d.ts +44 -0
  44. package/dist/config/index.js +1 -0
  45. package/dist/core/client.d.ts +15 -0
  46. package/dist/core/client.js +2 -0
  47. package/dist/core/errors.d.ts +175 -0
  48. package/dist/core/errors.js +1 -0
  49. package/dist/core/http.d.ts +87 -0
  50. package/dist/core/http.js +1 -0
  51. package/dist/core/logger.d.ts +46 -0
  52. package/dist/core/logger.js +1 -0
  53. package/dist/core/money.d.ts +10 -0
  54. package/dist/core/money.js +1 -0
  55. package/dist/core/parse-response.d.ts +62 -0
  56. package/dist/core/parse-response.js +1 -0
  57. package/dist/core/utils.d.ts +67 -0
  58. package/dist/core/utils.js +1 -0
  59. package/dist/draws/draw.module.d.ts +40 -0
  60. package/dist/draws/draw.module.js +1 -0
  61. package/dist/draws/index.d.ts +5 -0
  62. package/dist/draws/public.d.ts +6 -0
  63. package/dist/draws/public.js +1 -0
  64. package/dist/draws/types.d.ts +90 -0
  65. package/dist/draws/types.js +1 -0
  66. package/dist/errors.d.ts +5 -0
  67. package/dist/errors.js +1 -0
  68. package/dist/events.d.ts +5 -0
  69. package/dist/events.js +1 -0
  70. package/dist/experiences/distribution-monitor.runtime.d.ts +12 -0
  71. package/dist/experiences/distribution-monitor.runtime.js +1 -0
  72. package/dist/experiences/distribution-monitor.types.d.ts +62 -0
  73. package/dist/experiences/experience.module.d.ts +88 -0
  74. package/dist/experiences/experience.module.js +1 -0
  75. package/dist/experiences/index.d.ts +3 -0
  76. package/dist/experiences/index.js +1 -0
  77. package/dist/experiences/journey-contract.fixtures.d.ts +9 -0
  78. package/dist/experiences/journey-view.d.ts +22 -0
  79. package/dist/experiences/journey-view.js +1 -0
  80. package/dist/experiences/journey.d.ts +89 -0
  81. package/dist/experiences/journey.js +1 -0
  82. package/dist/experiences/journey.machine.d.ts +79 -0
  83. package/dist/experiences/journey.machine.js +1 -0
  84. package/dist/experiences/journey.types.d.ts +395 -0
  85. package/dist/experiences/public.d.ts +13 -0
  86. package/dist/experiences/public.js +1 -0
  87. package/dist/experiences/types.d.ts +161 -0
  88. package/dist/handoff/handoff.module.d.ts +184 -0
  89. package/dist/handoff/handoff.module.js +1 -0
  90. package/dist/handoff/index.d.ts +5 -0
  91. package/dist/handoff/index.js +1 -0
  92. package/dist/index.d.ts +11 -0
  93. package/dist/index.js +1 -0
  94. package/dist/internals.d.ts +11 -0
  95. package/dist/internals.js +1 -0
  96. package/dist/queues/index.d.ts +5 -0
  97. package/dist/queues/index.js +1 -0
  98. package/dist/queues/qualitative-bucket.d.ts +12 -0
  99. package/dist/queues/qualitative-bucket.js +1 -0
  100. package/dist/queues/queue.module.d.ts +42 -0
  101. package/dist/queues/queue.module.js +1 -0
  102. package/dist/queues/types.d.ts +112 -0
  103. package/dist/queues/types.js +1 -0
  104. package/dist/security/admission-proof.d.ts +15 -0
  105. package/dist/security/admission-proof.js +1 -0
  106. package/dist/state/capability-token-registry.d.ts +44 -0
  107. package/dist/state/capability-token-registry.js +1 -0
  108. package/dist/state/events.d.ts +342 -0
  109. package/dist/state/events.js +1 -0
  110. package/dist/state/store.d.ts +48 -0
  111. package/dist/state/store.js +1 -0
  112. package/dist/sync/broadcast-transport.d.ts +19 -0
  113. package/dist/sync/broadcast-transport.js +1 -0
  114. package/dist/sync/cross-tab-coordinator.d.ts +44 -0
  115. package/dist/sync/cross-tab-coordinator.js +1 -0
  116. package/dist/sync/index.d.ts +8 -0
  117. package/dist/sync/localstorage-transport.d.ts +32 -0
  118. package/dist/sync/localstorage-transport.js +1 -0
  119. package/dist/sync/protocol-transport.d.ts +51 -0
  120. package/dist/sync/protocol-transport.js +1 -0
  121. package/dist/sync/protocol.d.ts +254 -0
  122. package/dist/sync/protocol.js +1 -0
  123. package/dist/sync/recovery.d.ts +68 -0
  124. package/dist/sync/transport-factory.d.ts +16 -0
  125. package/dist/sync/transport-factory.js +1 -0
  126. package/dist/sync/transport-interface.d.ts +33 -0
  127. package/dist/sync/transport.d.ts +49 -0
  128. package/dist/sync/transport.js +1 -0
  129. package/dist/test-utils/harness-scenarios.d.ts +71 -0
  130. package/dist/test-utils/harness-scenarios.js +1 -0
  131. package/dist/test-utils/index.d.ts +12 -0
  132. package/dist/test-utils/index.js +1 -0
  133. package/dist/test-utils/mock-journey.d.ts +63 -0
  134. package/dist/test-utils/mock-journey.js +1 -0
  135. package/dist/test-utils/mock-sdk-vitest.d.ts +80 -0
  136. package/dist/test-utils/mock-sdk-vitest.js +1 -0
  137. package/dist/test-utils/mock-sdk.d.ts +22 -0
  138. package/dist/test-utils/mock-sdk.js +1 -0
  139. package/dist/test-utils/mock-server.d.ts +105 -0
  140. package/dist/test-utils/mock-server.js +1 -0
  141. package/dist/test-utils/sdk-factory.d.ts +3 -0
  142. package/dist/test-utils/sdk-factory.js +1 -0
  143. package/dist/test-utils/verification-scenarios.d.ts +43 -0
  144. package/dist/test-utils/verification-scenarios.js +1 -0
  145. package/dist/test-utils/verification-state.d.ts +1 -0
  146. package/dist/test-utils/verification-state.js +1 -0
  147. package/dist/theme.d.ts +8 -0
  148. package/dist/theme.js +1 -0
  149. package/dist/timed-releases/index.d.ts +6 -0
  150. package/dist/timed-releases/public.d.ts +6 -0
  151. package/dist/timed-releases/public.js +1 -0
  152. package/dist/timed-releases/timed-release.module.d.ts +31 -0
  153. package/dist/timed-releases/timed-release.module.js +1 -0
  154. package/dist/timed-releases/types.d.ts +70 -0
  155. package/dist/timed-releases/types.js +1 -0
  156. package/dist/types/distribution-type.d.ts +45 -0
  157. package/dist/types/index.d.ts +178 -0
  158. package/dist/utils/fingerprint.module.d.ts +27 -0
  159. package/dist/utils/fingerprint.module.js +1 -0
  160. package/dist/utils/index.d.ts +4 -0
  161. package/dist/version.d.ts +5 -0
  162. package/dist/version.js +1 -0
  163. package/dist/waitlists/index.d.ts +2 -0
  164. package/dist/waitlists/public.d.ts +6 -0
  165. package/dist/waitlists/public.js +1 -0
  166. package/dist/waitlists/types.d.ts +50 -0
  167. package/dist/waitlists/types.js +1 -0
  168. package/dist/waitlists/waitlist.module.d.ts +17 -0
  169. package/dist/waitlists/waitlist.module.js +1 -0
  170. package/package.json +205 -0
@@ -0,0 +1,178 @@
1
+ import { CDPAdapter, CDPAdapterConfig } from '../adapters/types';
2
+ import { AppointmentModule } from '../appointments/types';
3
+ import { AuctionModule } from '../auctions/types';
4
+ import { AuthModule } from '../auth/types';
5
+ import { BeaconConfig, BeaconModule } from '../beacon';
6
+ import { ChallengeModule } from '../challenges/types';
7
+ import { DrawModule } from '../draws/types';
8
+ import { DistributionMonitor } from '../experiences/distribution-monitor.types';
9
+ import { JourneyHandle } from '../experiences/journey.types';
10
+ import { ConsumerMe, ExperienceModule, ResumeJourneysResult } from '../experiences/types';
11
+ import { QueueModule } from '../queues/types';
12
+ import { SDKEvents } from '../state/events';
13
+ import { TimedReleaseModule } from '../timed-releases/types';
14
+ import { WaitlistModule } from '../waitlists/types';
15
+ /**
16
+ * SDK configuration options
17
+ */
18
+ export interface FanfareConfig {
19
+ /**
20
+ * Your Fanfare organization ID
21
+ */
22
+ organizationId: string;
23
+ /**
24
+ * Your publishable API key
25
+ */
26
+ publishableKey: string;
27
+ /**
28
+ * API environment
29
+ * @default "production"
30
+ */
31
+ environment?: "production" | "development";
32
+ /**
33
+ * Custom API URL (overrides environment)
34
+ */
35
+ apiUrl?: string;
36
+ /**
37
+ * Cookie behavior for SDK fetches.
38
+ *
39
+ * Defaults to `"include"` so the SDK can use HttpOnly refresh-token
40
+ * cookies for cross-origin consumer API calls.
41
+ *
42
+ * Set to `"same-origin"` when the SDK runs behind a same-origin proxy, or
43
+ * `"omit"` for a strictly token-based deployment that should never send
44
+ * cookies.
45
+ *
46
+ * @default "include"
47
+ */
48
+ credentials?: RequestCredentials;
49
+ /**
50
+ * Enable debug mode
51
+ * @default false
52
+ */
53
+ debug?: boolean;
54
+ /**
55
+ * Authentication configuration
56
+ */
57
+ auth?: {
58
+ /**
59
+ * Whether to persist sessions in storage
60
+ * @default true
61
+ */
62
+ persistSession?: boolean;
63
+ /**
64
+ * Session duration in seconds
65
+ * @default 3600 (1 hour)
66
+ */
67
+ sessionDuration?: number;
68
+ };
69
+ /**
70
+ * Logging configuration
71
+ */
72
+ logging?: {
73
+ /**
74
+ * Log level
75
+ * @default "error"
76
+ */
77
+ level?: "error" | "warn" | "info" | "debug" | "metrics";
78
+ };
79
+ /**
80
+ * Inter-tab synchronization configuration
81
+ */
82
+ sync?: boolean | {
83
+ /**
84
+ * Whether sync is enabled
85
+ * @default true
86
+ */
87
+ enabled?: boolean;
88
+ /**
89
+ * Custom channel name for BroadcastChannel
90
+ * @default "fanfare-sdk-sync"
91
+ */
92
+ channelName?: string;
93
+ };
94
+ /**
95
+ * Feature flags for optional functionality
96
+ */
97
+ features?: {
98
+ /**
99
+ * Enable browser fingerprinting for device identification
100
+ * Can be disabled for privacy compliance or troubleshooting
101
+ * @default true
102
+ */
103
+ fingerprinting?: boolean;
104
+ };
105
+ /**
106
+ * Beacon event tracking configuration
107
+ */
108
+ beacon?: BeaconConfig;
109
+ }
110
+ /**
111
+ * Journey registry and resurrection APIs.
112
+ */
113
+ export interface JourneysModule {
114
+ /**
115
+ * Create (or retrieve) a journey handle for the given experience.
116
+ * Restores any locally persisted journey snapshot for that experience.
117
+ */
118
+ get(experienceId: string): JourneyHandle;
119
+ /**
120
+ * List experience IDs with known journey state or active handles.
121
+ */
122
+ list(): string[];
123
+ /**
124
+ * Reconcile journeys from local durable state and `/consumers/me`.
125
+ */
126
+ resumeAll(me?: ConsumerMe): Promise<ResumeJourneysResult>;
127
+ }
128
+ /**
129
+ * Main public SDK interface.
130
+ */
131
+ export interface FanfareSDK {
132
+ /**
133
+ * Authentication module
134
+ */
135
+ readonly auth: AuthModule;
136
+ /**
137
+ * Challenge module - bot prevention / human verification
138
+ */
139
+ readonly challenges: ChallengeModule;
140
+ /**
141
+ * Journey registry and resurrection APIs
142
+ */
143
+ readonly journeys: JourneysModule;
144
+ /**
145
+ * Beacon event tracking module - client-side analytics
146
+ */
147
+ readonly beacon: BeaconModule;
148
+ readonly appointments: AppointmentModule;
149
+ /**
150
+ * Register a CDP adapter (e.g. Google Analytics)
151
+ */
152
+ use(adapter: CDPAdapter, config?: CDPAdapterConfig): void;
153
+ /**
154
+ * Subscribe to SDK events
155
+ */
156
+ on<K extends keyof SDKEvents>(event: K, handler: (data: SDKEvents[K]) => void): () => void;
157
+ /**
158
+ * Clean up and destroy SDK instance
159
+ */
160
+ destroy(): Promise<void>;
161
+ }
162
+ /**
163
+ * Internal browser runtime surface used by the journey state machine and first-party adapters.
164
+ * Not re-exported from the package root.
165
+ */
166
+ export interface InternalFanfareSDK extends FanfareSDK {
167
+ readonly queues: QueueModule & DistributionMonitor;
168
+ readonly draws: DrawModule & DistributionMonitor;
169
+ readonly auctions: AuctionModule & DistributionMonitor;
170
+ readonly appointments: AppointmentModule & DistributionMonitor;
171
+ readonly waitlists: WaitlistModule;
172
+ readonly timedReleases: TimedReleaseModule & DistributionMonitor;
173
+ readonly experiences: ExperienceModule & {
174
+ get(experienceId: string): Promise<import('../experiences/types').ExperienceDetails>;
175
+ createJourney(experienceId: string): JourneyHandle;
176
+ resumeJourneysFromMe(me?: ConsumerMe): Promise<ResumeJourneysResult>;
177
+ };
178
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Browser fingerprinting module for Fanfare SDK
3
+ * Generates a unique fingerprint based on various browser characteristics
4
+ */
5
+ /**
6
+ * Browser fingerprint interface containing various identifying components
7
+ */
8
+ export interface BrowserFingerprint {
9
+ canvas: string;
10
+ webgl: string;
11
+ timezone: string;
12
+ userAgent: string;
13
+ screenResolution: string;
14
+ language: string;
15
+ hash: string;
16
+ }
17
+ /**
18
+ * Generate a browser fingerprint with multiple identifying components
19
+ * @returns Promise resolving to BrowserFingerprint object
20
+ */
21
+ export declare function generateFingerprint(): Promise<BrowserFingerprint>;
22
+ /**
23
+ * Generate a synchronous browser fingerprint (without async hash)
24
+ * Uses simple hash instead of crypto.subtle
25
+ * @returns BrowserFingerprint object with simple hash
26
+ */
27
+ export declare function generateFingerprintSync(): BrowserFingerprint;
@@ -0,0 +1 @@
1
+ import{isBrowser as t}from"../core/utils.js";function e(){if(!t())return"";try{const t=document.createElement("canvas"),e=t.getContext("2d");return e?(t.width=200,t.height=50,e.font="14px Arial",e.textBaseline="top",e.fillText("Fanfare SDK 🎫",2,2),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillRect(100,5,50,20),t.toDataURL()):""}catch{return""}}function n(){if(!t())return"";try{const t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"";const n=e.getExtension("WEBGL_debug_renderer_info");if(!n)return"";const r=e.getParameter(n.UNMASKED_VENDOR_WEBGL);return`${r}~${e.getParameter(n.UNMASKED_RENDERER_WEBGL)}`}catch{return""}}function r(){if(!t())return"";try{return Intl.DateTimeFormat().resolvedOptions().timeZone||""}catch{return""}}function i(){if(!t())return"";try{return navigator.userAgent||""}catch{return""}}function o(){if(!t())return"";try{if(!window.screen)return"";const t=window.screen.width,e=window.screen.height,n=window.screen.colorDepth;return void 0===t||void 0===e||void 0===n?"":`${t}x${e}x${n}`}catch{return""}}function c(){if(!t())return"";try{return navigator.language||""}catch{return""}}async function u(e){if(!t()||!window.crypto?.subtle)return a(JSON.stringify(e));try{const t=JSON.stringify(e),n=(new TextEncoder).encode(t);return function(t){const e=new Uint8Array(t),n=[];for(let r=0;r<e.length;r++){const t=e[r].toString(16);n.push(1===t.length?"0"+t:t)}return n.join("")}(await crypto.subtle.digest("SHA-256",n))}catch{return a(JSON.stringify(e))}}function a(t){let e=0;for(let n=0;n<t.length;n++){e=(e<<5)-e+t.charCodeAt(n),e&=e}return Math.abs(e).toString(16)}async function s(){const t={canvas:e(),webgl:n(),timezone:r(),userAgent:i(),screenResolution:o(),language:c()},a=await u(t);return{...t,hash:a}}function g(){const t={canvas:e(),webgl:n(),timezone:r(),userAgent:i(),screenResolution:o(),language:c()},u=a(JSON.stringify(t));return{...t,hash:u}}export{s as generateFingerprint,g as generateFingerprintSync};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Utils module exports
3
+ */
4
+ export * from './fingerprint.module';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * SDK version
3
+ * This is automatically updated during the build process
4
+ */
5
+ export declare const version = "0.1.0";
@@ -0,0 +1 @@
1
+ const o="0.1.0";export{o as version};
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export { WaitlistManagementModule } from './waitlist.module';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Public waitlist surface. The runtime `WaitlistManagementModule` from `./types`
3
+ * is internal and not exported here.
4
+ */
5
+ export { WaitlistClosedError } from './types';
6
+ export type { WaitlistEntry, WaitlistStatus } from './types';
@@ -0,0 +1 @@
1
+ import{WaitlistClosedError as o}from"./types.js";export{o as WaitlistClosedError};
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Waitlist Module Types
3
+ * Simple notification signup system - NOT flow control or position tracking
4
+ */
5
+ /**
6
+ * API response when checking waitlist status
7
+ */
8
+ export interface WaitlistStatus {
9
+ waitlistId: string;
10
+ sequenceId?: string;
11
+ isEntered: boolean;
12
+ enteredAt?: string;
13
+ }
14
+ /**
15
+ * API response when entering a waitlist
16
+ */
17
+ export interface WaitlistEntry {
18
+ id: string;
19
+ waitlistId: string;
20
+ sequenceId: string;
21
+ consumerId: string;
22
+ enteredAt: string;
23
+ }
24
+ /**
25
+ * Error thrown when waitlist is closed
26
+ */
27
+ export declare class WaitlistClosedError extends Error {
28
+ constructor(message: string);
29
+ }
30
+ /**
31
+ * Waitlist module interface
32
+ */
33
+ export interface WaitlistModule {
34
+ /**
35
+ * Enter a waitlist for notifications
36
+ */
37
+ enter(waitlistId: string, options?: import('../core/http').RequestOptions): Promise<WaitlistEntry>;
38
+ /**
39
+ * Leave a specific waitlist
40
+ */
41
+ leave(waitlistId: string, options?: import('../core/http').RequestOptions): Promise<void>;
42
+ /**
43
+ * Check if user is on a waitlist
44
+ */
45
+ getStatus(waitlistId: string): Promise<WaitlistStatus>;
46
+ /**
47
+ * Cleanup
48
+ */
49
+ destroy(): void;
50
+ }
@@ -0,0 +1 @@
1
+ class r extends Error{constructor(r){super(r),this.name="WaitlistClosedError"}}export{r as WaitlistClosedError};
@@ -0,0 +1,17 @@
1
+ import { HttpClient } from '../core/http';
2
+ import { WaitlistEntry, WaitlistModule, WaitlistStatus } from './types';
3
+ /**
4
+ * Waitlist Management Module
5
+ * Simple notification signup system - NOT flow control or position tracking
6
+ */
7
+ export declare class WaitlistManagementModule implements WaitlistModule {
8
+ private readonly http;
9
+ private readonly logger;
10
+ private get store();
11
+ private readonly events;
12
+ constructor(http: HttpClient);
13
+ enter(waitlistId: string, options?: import('../core/http').RequestOptions): Promise<WaitlistEntry>;
14
+ leave(waitlistId: string, options?: import('../core/http').RequestOptions): Promise<void>;
15
+ getStatus(waitlistId: string): Promise<WaitlistStatus>;
16
+ destroy(): void;
17
+ }
@@ -0,0 +1 @@
1
+ import{createError as t}from"../core/errors.js";import{getLogger as e}from"../core/logger.js";import{generateId as s}from"../core/utils.js";import{getEventBus as i}from"../state/events.js";import{getSDKStore as r}from"../state/store.js";import{WaitlistClosedError as o}from"./types.js";class a{constructor(t){this.logger=e(),this.events=i(),this.http=t}get store(){return r()}async enter(e,i){try{if(!this.store.session)throw t.unauthorized("Not authenticated. Call auth.guest() or auth.login() first");this.logger.info("Entering waitlist",{waitlistId:e});const s=await this.http.post(`/waitlists/${e}/enter`,void 0,i);return this.events.emit("waitlist:entered",{waitlistId:e,sequenceId:s.sequenceId,enteredAt:s.enteredAt}),s}catch(r){if(r&&"object"==typeof r&&"message"in r){const t=r.message.toLowerCase();if(t.includes("already on list")||t.includes("already entered")||t.includes("already joined")){this.logger.info("Waitlist entry already exists",{waitlistId:e});const t=await this.getStatus(e);return{id:s(),waitlistId:e,sequenceId:t.sequenceId??"",consumerId:this.store.session?.consumerId||"unknown",enteredAt:t.enteredAt||/* @__PURE__ */(new Date).toISOString()}}if(t.includes("waitlist closed")||t.includes("not accepting")){const t=new o("Waitlist is no longer accepting entries");throw this.logger.error("Waitlist closed",{waitlistId:e}),this.events.emit("waitlist:error",{waitlistId:e,error:t.message}),t}}throw this.logger.error("Failed to enter waitlist",{waitlistId:e,error:r}),this.events.emit("waitlist:error",{waitlistId:e,error:r instanceof Error?r.message:"Unknown error"}),r}}async leave(t,e){try{this.logger.info("Leaving waitlist",{waitlistId:t}),await this.http.delete(`/waitlists/${t}/leave`,e),this.events.emit("waitlist:left",{waitlistId:t})}catch(s){throw this.logger.error("Failed to leave waitlist",{waitlistId:t,error:s}),this.events.emit("waitlist:error",{waitlistId:t,error:s instanceof Error?s.message:"Unknown error"}),s}}async getStatus(t){try{return await this.http.get(`/waitlists/${t}/status`)}catch(e){if(e&&"object"==typeof e&&"status"in e&&404===e.status)return{waitlistId:t,isEntered:!1};throw this.logger.error("Failed to get waitlist status",{waitlistId:t,error:e}),this.events.emit("waitlist:error",{waitlistId:t,error:e instanceof Error?e.message:"Unknown error"}),e}}destroy(){this.logger.debug("WaitlistManagementModule destroyed")}}export{a as WaitlistManagementModule};
package/package.json ADDED
@@ -0,0 +1,205 @@
1
+ {
2
+ "name": "@fanfare-io/fanfare-sdk-core",
3
+ "version": "0.1.0",
4
+ "description": "Official Fanfare Browser SDK for queue, draw, auction, and appointment experiences",
5
+ "publishConfig": {
6
+ "registry": "https://registry.npmjs.org",
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/fanfare-io/fanfare-sdk.git"
12
+ },
13
+ "homepage": "https://docs.fanfare.io/sdk/core/quickstart",
14
+ "bugs": {
15
+ "url": "https://github.com/fanfare-io/fanfare-sdk/issues"
16
+ },
17
+ "type": "module",
18
+ "files": [
19
+ "dist/",
20
+ "!dist/**/*.map",
21
+ "!dist/**/*.tsbuildinfo",
22
+ "!dist/stats.html",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "module": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ },
33
+ "./config": {
34
+ "types": "./dist/config/index.d.ts",
35
+ "import": "./dist/config/index.js"
36
+ },
37
+ "./auth": {
38
+ "types": "./dist/auth/index.d.ts",
39
+ "import": "./dist/auth/index.js"
40
+ },
41
+ "./queues": {
42
+ "types": "./dist/queues/index.d.ts",
43
+ "import": "./dist/queues/index.js"
44
+ },
45
+ "./adapters": {
46
+ "types": "./dist/adapters/index.d.ts",
47
+ "import": "./dist/adapters/index.js"
48
+ },
49
+ "./experiences": {
50
+ "types": "./dist/experiences/public.d.ts",
51
+ "import": "./dist/experiences/public.js"
52
+ },
53
+ "./challenges": {
54
+ "types": "./dist/challenges/public.d.ts",
55
+ "import": "./dist/challenges/public.js"
56
+ },
57
+ "./appointments": {
58
+ "types": "./dist/appointments/public.d.ts",
59
+ "import": "./dist/appointments/public.js"
60
+ },
61
+ "./beacon": {
62
+ "types": "./dist/beacon/public.d.ts",
63
+ "import": "./dist/beacon/public.js"
64
+ },
65
+ "./theme": {
66
+ "types": "./dist/theme.d.ts",
67
+ "import": "./dist/theme.js"
68
+ },
69
+ "./events": {
70
+ "types": "./dist/events.d.ts",
71
+ "import": "./dist/events.js"
72
+ },
73
+ "./internals": {
74
+ "types": "./dist/internals.d.ts",
75
+ "import": "./dist/internals.js"
76
+ },
77
+ "./test-utils": {
78
+ "types": "./dist/test-utils/index.d.ts",
79
+ "import": "./dist/test-utils/index.js"
80
+ },
81
+ "./test-utils/vitest": {
82
+ "types": "./dist/test-utils/mock-sdk-vitest.d.ts",
83
+ "import": "./dist/test-utils/mock-sdk-vitest.js"
84
+ },
85
+ "./errors": {
86
+ "types": "./dist/errors.d.ts",
87
+ "import": "./dist/errors.js"
88
+ },
89
+ "./handoff": {
90
+ "types": "./dist/handoff/index.d.ts",
91
+ "import": "./dist/handoff/index.js"
92
+ },
93
+ "./draws": {
94
+ "types": "./dist/draws/public.d.ts",
95
+ "import": "./dist/draws/public.js"
96
+ },
97
+ "./auctions": {
98
+ "types": "./dist/auctions/public.d.ts",
99
+ "import": "./dist/auctions/public.js"
100
+ },
101
+ "./waitlists": {
102
+ "types": "./dist/waitlists/public.d.ts",
103
+ "import": "./dist/waitlists/public.js"
104
+ },
105
+ "./timed-releases": {
106
+ "types": "./dist/timed-releases/public.d.ts",
107
+ "import": "./dist/timed-releases/public.js"
108
+ },
109
+ "./package.json": "./package.json"
110
+ },
111
+ "dependencies": {
112
+ "big.js": "^7.0.1",
113
+ "nanostores": "^1.1.0",
114
+ "uuid": "^14.0.0",
115
+ "wretch": "^2.11.0",
116
+ "zustand": "^5.0.6",
117
+ "@fanfare-io/fanfare-sdk-contracts": "0.1.0"
118
+ },
119
+ "peerDependencies": {
120
+ "valibot": "^1.1.0",
121
+ "vitest": ">=3"
122
+ },
123
+ "peerDependenciesMeta": {
124
+ "vitest": {
125
+ "optional": true
126
+ }
127
+ },
128
+ "devDependencies": {
129
+ "@chromatic-com/storybook": "^5.0.1",
130
+ "@size-limit/preset-small-lib": "^11.1.8",
131
+ "@storybook/addon-docs": "^10.2.16",
132
+ "@storybook/addon-onboarding": "^10.2.16",
133
+ "@storybook/addon-vitest": "^10.2.16",
134
+ "@storybook/react-vite": "^10.2.16",
135
+ "@types/big.js": "^6.2.2",
136
+ "@types/node": "^24.1.0",
137
+ "@types/react": "^19.1.12",
138
+ "@types/react-dom": "^19.1.9",
139
+ "@types/uuid": "^10.0.0",
140
+ "@vitest/browser": "^3.2.4",
141
+ "@vitest/ui": "^3.2.4",
142
+ "jsdom": "^26.1.0",
143
+ "playwright": "^1.51.1",
144
+ "prettier": "^3.5.3",
145
+ "prettier-plugin-organize-imports": "^4.1.0",
146
+ "react": "^19.1.1",
147
+ "react-dom": "^19.1.1",
148
+ "rimraf": "^6.0.1",
149
+ "rollup-plugin-visualizer": "^5.14.0",
150
+ "size-limit": "^11.1.8",
151
+ "storybook": "^10.2.16",
152
+ "terser": "^5.46.1",
153
+ "typescript": "^5.9.2",
154
+ "valibot": "^1.1.0",
155
+ "vite": "^7.3.1",
156
+ "vite-bundle-visualizer": "^1.0.0",
157
+ "vite-plugin-dts": "^4.5.4",
158
+ "vite-tsconfig-paths": "^5.1.4",
159
+ "vitest": "^3.2.4",
160
+ "@fanfare-io/shared-models": "0.1.0"
161
+ },
162
+ "sideEffects": false,
163
+ "keywords": [
164
+ "fanfare",
165
+ "queue",
166
+ "waitlist",
167
+ "ecommerce",
168
+ "sdk",
169
+ "browser",
170
+ "typescript"
171
+ ],
172
+ "license": "Apache-2.0",
173
+ "size-limit": [
174
+ {
175
+ "name": "Core + Queues",
176
+ "path": "dist/index.js",
177
+ "limit": "42 KB"
178
+ }
179
+ ],
180
+ "scripts": {
181
+ "build": "vite build && pnpm size",
182
+ "build:deps": "vite build --emptyOutDir false",
183
+ "build:incremental": "vite build --emptyOutDir false",
184
+ "build:dist": "rimraf dist && vite build",
185
+ "build:strict": "pnpm typecheck && pnpm build",
186
+ "build-storybook": "storybook build",
187
+ "dev": "vite build --watch",
188
+ "fmt": "prettier src --write",
189
+ "lint": "oxlint src",
190
+ "lint:fix": "oxlint --fix src",
191
+ "prebuild": "rimraf dist",
192
+ "prebuild-storybook": "pnpm typecheck",
193
+ "size": "size-limit",
194
+ "storybook": "storybook dev -p 6007 --no-open",
195
+ "build:test-deps": "pnpm --filter @fanfare-io/fanfare-sdk-contracts run build:incremental",
196
+ "test": "pnpm build:test-deps && vitest run",
197
+ "test:debug": "NODE_OPTIONS='--expose-gc' vitest run --reporter=verbose",
198
+ "test:ci": "pnpm build:test-deps && vitest run --reporter=verbose --coverage",
199
+ "test:watch": "vitest",
200
+ "test:unit": "pnpm build:test-deps && vitest run .unit.test.ts --passWithNoTests",
201
+ "test:integration": "pnpm build:test-deps && vitest run .integration.test.ts --passWithNoTests",
202
+ "test:contract": "pnpm build:test-deps && vitest run .contract.test.ts --passWithNoTests",
203
+ "typecheck": "tsc --noEmit"
204
+ }
205
+ }