@teardown/react-native 2.0.28 → 2.0.30

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.
@@ -1,8 +1,11 @@
1
1
  import { ApiClient } from "./clients/api";
2
2
  import { DeviceClient, type DeviceClientOptions } from "./clients/device/device.client";
3
+ import { EventsClient } from "./clients/events";
3
4
  import { ForceUpdateClient, type ForceUpdateClientOptions } from "./clients/force-update";
4
5
  import { IdentityClient } from "./clients/identity";
5
6
  import { type Logger, LoggingClient, type LogLevel } from "./clients/logging";
7
+ import type { NotificationAdapter } from "./clients/notifications/adapters/notifications.adapter-interface";
8
+ import { NotificationsClient } from "./clients/notifications/notifications.client";
6
9
  import { type StorageAdapter, StorageClient } from "./clients/storage";
7
10
  import { UtilsClient } from "./clients/utils/utils.client";
8
11
 
@@ -10,10 +13,15 @@ export type TeardownCoreOptions = {
10
13
  org_id: string;
11
14
  project_id: string;
12
15
  api_key: string;
13
- // environment_slug: string; // TODO: add this back in
16
+ /** Environment slug (e.g. "production", "staging", "development") */
17
+ environment_slug?: string;
18
+ /** Custom ingest API URL for local/staging environments */
19
+ ingestUrl?: string;
14
20
  storageAdapter: StorageAdapter;
15
21
  deviceAdapter: DeviceClientOptions["adapter"];
16
22
  forceUpdate?: ForceUpdateClientOptions;
23
+ /** Optional notification adapter for push notification support */
24
+ notificationAdapter?: NotificationAdapter;
17
25
  };
18
26
 
19
27
  export class TeardownCore {
@@ -23,8 +31,10 @@ export class TeardownCore {
23
31
  public readonly api: ApiClient;
24
32
  private readonly storage: StorageClient;
25
33
  public readonly device: DeviceClient;
34
+ public readonly events: EventsClient;
26
35
  public readonly identity: IdentityClient;
27
36
  public readonly forceUpdate: ForceUpdateClient;
37
+ public readonly notifications?: NotificationsClient;
28
38
 
29
39
  constructor(private readonly options: TeardownCoreOptions) {
30
40
  this.options = options;
@@ -46,12 +56,32 @@ export class TeardownCore {
46
56
  org_id: this.options.org_id,
47
57
  project_id: this.options.project_id,
48
58
  api_key: this.options.api_key,
49
- environment_slug: "production",
59
+ environment_slug: this.options.environment_slug ?? "production",
60
+ ingestUrl: this.options.ingestUrl,
50
61
  });
51
62
  this.device = new DeviceClient(this.logging, this.utils, this.storage, {
52
63
  adapter: this.options.deviceAdapter,
53
64
  });
54
- this.identity = new IdentityClient(this.logging, this.utils, this.storage, this.api, this.device);
65
+
66
+ // Create events client after device (needs device for deviceId)
67
+ this.events = new EventsClient(this.logging, this.api, this.device);
68
+
69
+ // Create notifications client before identity so it can be passed in
70
+ if (this.options.notificationAdapter) {
71
+ this.notifications = new NotificationsClient(this.logging, this.storage, {
72
+ adapter: this.options.notificationAdapter,
73
+ });
74
+ }
75
+
76
+ this.identity = new IdentityClient(
77
+ this.logging,
78
+ this.utils,
79
+ this.storage,
80
+ this.api,
81
+ this.device,
82
+ this.events,
83
+ this.notifications
84
+ );
55
85
  this.forceUpdate = new ForceUpdateClient(this.logging, this.storage, this.identity, this.options.forceUpdate);
56
86
 
57
87
  void this.initialize()
@@ -67,10 +97,19 @@ export class TeardownCore {
67
97
  // Wait for all storage hydration to complete
68
98
  this.logger.debug("Waiting for storage to be ready");
69
99
  await this.storage.whenReady();
100
+
101
+ // Initialize notifications first so token is available for identify
102
+ if (this.notifications) {
103
+ this.logger.debug("Initializing notifications");
104
+ await this.notifications.initialize();
105
+ this.logger.debug("Notifications initialized");
106
+ }
107
+
70
108
  // Initialize identity (loads from storage, then identifies if needed)
71
109
  this.logger.debug("Initializing identity");
72
110
  await this.identity.initialize();
73
111
  this.logger.debug("Identity initialized");
112
+
74
113
  // Then initialize force update (subscribes to identity events)
75
114
  this.logger.debug("Initializing force update");
76
115
  this.forceUpdate.initialize();