@genn-inc/cluebase-frontend-sdk 0.0.9 → 0.0.11

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 +1 @@
1
- export declare const SDK_VERSION: "0.0.9";
1
+ export declare const SDK_VERSION: "0.0.11";
@@ -1,3 +1,3 @@
1
1
  // This file is generated by scripts/generate-version-module.mjs.
2
2
  // Do NOT edit by hand. The source of truth is `package.json` `version`.
3
- export const SDK_VERSION = "0.0.9";
3
+ export const SDK_VERSION = "0.0.11";
@@ -8,7 +8,7 @@ import { BatchTransport } from "../exporter/batch.js";
8
8
  import { IngestClient } from "../exporter/client.js";
9
9
  import { DiagnosticStore } from "../exporter/diagnostics.js";
10
10
  import { detectWholeValuePII, hashIdentityValue, isDeniedKey, } from "../exporter/sanitize.js";
11
- import { initSdkCoreWasm } from "../exporter/sdk-core-wasm.js";
11
+ import { initSdkCoreWasm, isSdkCoreWasmReady } from "../exporter/sdk-core-wasm.js";
12
12
  import { InternalMetricsStore } from "../internal/metrics.js";
13
13
  import { isConfigValid, resolveConfig, validateConfig } from "./config.js";
14
14
  import { DEFAULT_BATCH_FLUSH_THRESHOLD_BYTES, DEFAULT_CONSENT, DEFAULT_MAX_BATCH_QUEUE_BYTES, DEFAULT_MAX_BATCH_QUEUE_ITEMS, SDK_VERSION, } from "./constants.js";
@@ -127,16 +127,54 @@ class CluebaseBrowserSdkImpl {
127
127
  this.lifecycleDedup.clear();
128
128
  this.config = resolved;
129
129
  this.initSignature = nextSignature;
130
- this.identityManager = new IdentityManager();
131
- this.sessionManager = new SessionManager();
132
- this.tabManager = new TabManager();
133
- this.organizationManager = new OrganizationManager();
134
- this.traceManager = new TraceManager();
135
- this.traceManager.enableAsyncContext();
136
- this.environmentManager = new EnvironmentManager({
130
+ const identityManager = new IdentityManager();
131
+ const sessionManager = new SessionManager();
132
+ const tabManager = new TabManager();
133
+ const organizationManager = new OrganizationManager();
134
+ const traceManager = new TraceManager();
135
+ traceManager.enableAsyncContext();
136
+ const environmentManager = new EnvironmentManager({
137
137
  frontendRelease: resolved.release.frontendRelease,
138
138
  contextTraitsProvider: resolved.contextTraitsProvider,
139
139
  });
140
+ this.identityManager = identityManager;
141
+ this.sessionManager = sessionManager;
142
+ this.tabManager = tabManager;
143
+ this.organizationManager = organizationManager;
144
+ this.traceManager = traceManager;
145
+ this.environmentManager = environmentManager;
146
+ const managers = {
147
+ identityManager,
148
+ sessionManager,
149
+ tabManager,
150
+ organizationManager,
151
+ traceManager,
152
+ environmentManager,
153
+ };
154
+ if (isSdkCoreWasmReady()) {
155
+ this.completeInitAfterWasmReady(resolved, managers);
156
+ }
157
+ else {
158
+ void initSdkCoreWasm()
159
+ .then(() => {
160
+ if (this.initSignature !== nextSignature)
161
+ return;
162
+ this.completeInitAfterWasmReady(resolved, managers);
163
+ })
164
+ .catch((error) => {
165
+ reportSdkError("init sdk core wasm", error);
166
+ if (this.initSignature === nextSignature) {
167
+ this.handleInitFailure(error);
168
+ }
169
+ });
170
+ }
171
+ }
172
+ catch (error) {
173
+ this.handleInitFailure(error);
174
+ }
175
+ }
176
+ completeInitAfterWasmReady(resolved, managers) {
177
+ try {
140
178
  const effectiveBatch = resolved.batch;
141
179
  const ingestClient = new IngestClient({
142
180
  endpoint: resolved.endpoint,
@@ -172,12 +210,12 @@ class CluebaseBrowserSdkImpl {
172
210
  this.transport.start();
173
211
  this.eventPipeline.configure({
174
212
  config: resolved,
175
- identityManager: this.identityManager,
176
- sessionManager: this.sessionManager,
177
- tabManager: this.tabManager,
178
- organizationManager: this.organizationManager,
179
- environmentManager: this.environmentManager,
180
- traceManager: this.traceManager,
213
+ identityManager: managers.identityManager,
214
+ sessionManager: managers.sessionManager,
215
+ tabManager: managers.tabManager,
216
+ organizationManager: managers.organizationManager,
217
+ environmentManager: managers.environmentManager,
218
+ traceManager: managers.traceManager,
181
219
  transport: this.transport,
182
220
  internalMetrics: this.internalMetrics,
183
221
  logger: this.logger,
@@ -186,9 +224,6 @@ class CluebaseBrowserSdkImpl {
186
224
  if (this.consent !== "denied") {
187
225
  this.warmupBrowserToken(ingestClient);
188
226
  }
189
- void initSdkCoreWasm().catch((error) => {
190
- reportSdkError("init sdk core wasm", error);
191
- });
192
227
  this.tracerProvider = createCluebaseOtelPipeline({
193
228
  resolved,
194
229
  getTransport: () => this.transport,
@@ -197,7 +232,7 @@ class CluebaseBrowserSdkImpl {
197
232
  });
198
233
  this.initialized = true;
199
234
  this.refreshSessionCaptureEligibility();
200
- const sessionLifecycle = this.sessionManager.ensureActiveSession(Date.now());
235
+ const sessionLifecycle = managers.sessionManager.ensureActiveSession(Date.now());
201
236
  if (sessionLifecycle.started) {
202
237
  this.enqueueRawEvent({
203
238
  type: "session_started",
@@ -218,23 +253,26 @@ class CluebaseBrowserSdkImpl {
218
253
  this.installUnloadHandlers();
219
254
  }
220
255
  catch (error) {
221
- const errorDetails = getSdkErrorDetails(error);
222
- this.logger.error("Cluebase Frontend SDK init failed", {
223
- error_code: "sdk_operation_failed",
224
- ...errorDetails,
256
+ this.handleInitFailure(error);
257
+ }
258
+ }
259
+ handleInitFailure(error) {
260
+ const errorDetails = getSdkErrorDetails(error);
261
+ this.logger.error("Cluebase Frontend SDK init failed", {
262
+ error_code: "sdk_operation_failed",
263
+ ...errorDetails,
264
+ });
265
+ reportSdkError("init", error);
266
+ this.warnPublicDrop("init", "sdk_operation_failed");
267
+ try {
268
+ this.shutdown();
269
+ }
270
+ catch (cleanupError) {
271
+ this.logger.error("Cluebase Frontend SDK init cleanup failed", {
272
+ error_code: "sdk_cleanup_failed",
273
+ ...getSdkErrorDetails(cleanupError),
225
274
  });
226
- reportSdkError("init", error);
227
- this.warnPublicDrop("init", "sdk_operation_failed");
228
- try {
229
- this.shutdown();
230
- }
231
- catch (cleanupError) {
232
- this.logger.error("Cluebase Frontend SDK init cleanup failed", {
233
- error_code: "sdk_cleanup_failed",
234
- ...getSdkErrorDetails(cleanupError),
235
- });
236
- reportSdkError("init cleanup", cleanupError);
237
- }
275
+ reportSdkError("init cleanup", cleanupError);
238
276
  }
239
277
  }
240
278
  identify(userId, traits) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genn-inc/cluebase-frontend-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/genn-inc/cluebase.git"