crexperium-sdk 1.2.4 → 1.2.6

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/client.d.ts CHANGED
@@ -5,6 +5,7 @@ import { SDKConfig } from './config';
5
5
  import { EventsResource } from './resources/events';
6
6
  import { ContactsResource } from './resources/contacts';
7
7
  import { DealsResource } from './resources/deals';
8
+ import { ExperimentsResource } from './resources/experiments';
8
9
  import { VisitorIdPlugin } from './plugins/visitor-id';
9
10
  import { DeviceInfoPlugin } from './plugins/device-info';
10
11
  import { SessionReplayPlugin } from './plugins/session-replay';
@@ -14,6 +15,7 @@ export declare class CRMClient {
14
15
  private _events;
15
16
  private _contacts;
16
17
  private _deals;
18
+ private _experiments;
17
19
  private plugins;
18
20
  private _visitorId?;
19
21
  private _deviceInfo?;
@@ -32,6 +34,10 @@ export declare class CRMClient {
32
34
  * Deals resource for managing deals
33
35
  */
34
36
  get deals(): DealsResource;
37
+ /**
38
+ * Experiments resource for A/B testing and feature flags
39
+ */
40
+ get experiments(): ExperimentsResource;
35
41
  /**
36
42
  * Visitor ID plugin (browser only)
37
43
  */
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { Config, SDKConfig } from './config';
7
7
  export { EventsResource } from './resources/events';
8
8
  export { ContactsResource } from './resources/contacts';
9
9
  export { DealsResource } from './resources/deals';
10
+ export { ExperimentsResource } from './resources/experiments';
10
11
  export * from './types';
11
12
  export * from './errors';
12
13
  export { VisitorIdPlugin, Plugin } from './plugins/visitor-id';
@@ -15,4 +16,4 @@ export { AutoPageViewPlugin } from './plugins/auto-page-view';
15
16
  export { SessionReplayPlugin } from './plugins/session-replay';
16
17
  export { DeviceInfo, getDeviceInfo, detectDeviceType, detectBrowser, detectOS } from './utils/device';
17
18
  export { isLocalStorageAvailable, getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem, generateUUID, } from './utils/storage';
18
- export declare const VERSION = "1.1.0";
19
+ export declare const VERSION = "1.2.5";
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ class Config {
18
18
  this.apiToken = options.apiToken;
19
19
  }
20
20
  // Set defaults
21
- this.baseUrl = options.baseUrl || 'https://crxperium.applikuapp.com';
21
+ this.baseUrl = options.baseUrl || 'https://budget-api-s366in24na-uc.a.run.app';
22
22
  this.timeout = options.timeout ?? 30000; // 30 seconds
23
23
  this.maxRetries = options.maxRetries ?? 3;
24
24
  this.retryDelay = options.retryDelay ?? 1000; // 1 second
@@ -604,6 +604,82 @@ class DealsResource extends BaseResource {
604
604
  }
605
605
  }
606
606
 
607
+ /**
608
+ * Experiments API Resource
609
+ * Handles A/B testing and feature flagging
610
+ */
611
+ class ExperimentsResource extends BaseResource {
612
+ /**
613
+ * Get an experiment by ID or key
614
+ */
615
+ async get(experimentIdOrKey) {
616
+ return this.http.get(`/api/v1/experiments/${experimentIdOrKey}/`);
617
+ }
618
+ /**
619
+ * Get a variant assignment for a visitor
620
+ * This is the main SDK method for A/B testing
621
+ *
622
+ * @param experimentKey - The unique key of the experiment
623
+ * @param visitorId - The unique identifier for the visitor
624
+ * @param context - Optional context data (user agent, device, etc.)
625
+ * @returns The assigned variant with its payload
626
+ *
627
+ * @example
628
+ * ```typescript
629
+ * const assignment = await client.experiments.assign('checkout_button_test', {
630
+ * visitor_id: 'visitor_123',
631
+ * context: {
632
+ * user_agent: navigator.userAgent,
633
+ * device_type: 'desktop',
634
+ * browser: 'chrome'
635
+ * }
636
+ * });
637
+ *
638
+ * // Use the variant payload
639
+ * const buttonColor = assignment.variant.payload.button_color;
640
+ * ```
641
+ */
642
+ async assign(experimentKey, input) {
643
+ return this.http.post(`/api/v1/experiments/${experimentKey}/assign/`, input);
644
+ }
645
+ /**
646
+ * Track a conversion for a visitor in an experiment
647
+ * Call this when a visitor completes the desired action
648
+ *
649
+ * @param experimentKey - The unique key of the experiment
650
+ * @param input - Conversion data including visitor_id
651
+ *
652
+ * @example
653
+ * ```typescript
654
+ * await client.experiments.trackConversion('checkout_button_test', {
655
+ * visitor_id: 'visitor_123',
656
+ * event_name: 'purchase',
657
+ * event_properties: {
658
+ * amount: 99.99,
659
+ * currency: 'USD'
660
+ * }
661
+ * });
662
+ * ```
663
+ */
664
+ async trackConversion(experimentKey, input) {
665
+ await this.http.post(`/api/v1/experiments/${experimentKey}/convert/`, input);
666
+ }
667
+ /**
668
+ * Get a variant assignment and automatically track the exposure
669
+ * This combines assign() and exposure tracking in one call
670
+ *
671
+ * @param experimentKey - The unique key of the experiment
672
+ * @param input - Assignment data including visitor_id
673
+ * @returns The assigned variant with its payload
674
+ */
675
+ async getVariant(experimentKey, input) {
676
+ const assignment = await this.assign(experimentKey, input);
677
+ // Exposure is automatically tracked by the backend on assign
678
+ // but we return the assignment for client use
679
+ return assignment;
680
+ }
681
+ }
682
+
607
683
  /**
608
684
  * Storage utilities for browser localStorage/cookies
609
685
  */
@@ -13769,6 +13845,7 @@ class CRMClient {
13769
13845
  this._events = new EventsResource(this.http);
13770
13846
  this._contacts = new ContactsResource(this.http);
13771
13847
  this._deals = new DealsResource(this.http);
13848
+ this._experiments = new ExperimentsResource(this.http);
13772
13849
  // Initialize browser plugins if in browser
13773
13850
  if (isBrowser) {
13774
13851
  this.initBrowserPlugins();
@@ -13792,6 +13869,12 @@ class CRMClient {
13792
13869
  get deals() {
13793
13870
  return this._deals;
13794
13871
  }
13872
+ /**
13873
+ * Experiments resource for A/B testing and feature flags
13874
+ */
13875
+ get experiments() {
13876
+ return this._experiments;
13877
+ }
13795
13878
  /**
13796
13879
  * Visitor ID plugin (browser only)
13797
13880
  */
@@ -13855,7 +13938,7 @@ class CRMClient {
13855
13938
  */
13856
13939
  // Main client
13857
13940
  // Version
13858
- const VERSION = '1.1.0';
13941
+ const VERSION = '1.2.5';
13859
13942
 
13860
13943
  exports.AuthenticationError = AuthenticationError;
13861
13944
  exports.AutoPageViewPlugin = AutoPageViewPlugin;
@@ -13866,6 +13949,7 @@ exports.ContactsResource = ContactsResource;
13866
13949
  exports.DealsResource = DealsResource;
13867
13950
  exports.DeviceInfoPlugin = DeviceInfoPlugin;
13868
13951
  exports.EventsResource = EventsResource;
13952
+ exports.ExperimentsResource = ExperimentsResource;
13869
13953
  exports.NetworkError = NetworkError;
13870
13954
  exports.RateLimitError = RateLimitError;
13871
13955
  exports.ResourceNotFoundError = ResourceNotFoundError;