@amplifyup/sdk 0.1.4 → 0.1.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.
@@ -240,14 +240,16 @@ function resolveAmplifyUpTarget(options) {
240
240
  if (isAmplifyUpTarget(envTarget)) {
241
241
  return normalizeAmplifyUpTarget(envTarget);
242
242
  }
243
- if (typeof window !== "undefined") {
244
- const host = window.location.hostname;
245
- if (host === "localhost" || host === "127.0.0.1") {
246
- return "local";
247
- }
248
- }
249
243
  return "production";
250
244
  }
245
+ function isRemoteOrchestratorUrl(orchestratorUrl) {
246
+ try {
247
+ const host = new URL(orchestratorUrl).hostname.toLowerCase();
248
+ return host !== "localhost" && host !== "127.0.0.1" && host !== "::1";
249
+ } catch {
250
+ return false;
251
+ }
252
+ }
251
253
  function localOrchestratorUrl() {
252
254
  const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
253
255
  return (fromEnv || "http://localhost:5001").replace(/\/$/, "");
@@ -403,6 +405,7 @@ var AmplifyUpSDK = class {
403
405
  */
404
406
  async init(config) {
405
407
  if (this.initialized && this.adapter?.isInitialized()) {
408
+ this.ensureWindowBridge();
406
409
  return;
407
410
  }
408
411
  if (this.initPromise) {
@@ -415,6 +418,32 @@ var AmplifyUpSDK = class {
415
418
  this.initPromise = null;
416
419
  }
417
420
  }
421
+ /** Attach console helpers to window (idempotent; survives Fast Refresh). */
422
+ ensureWindowBridge() {
423
+ if (typeof window === "undefined") return;
424
+ window.AmplifyUp = {
425
+ getInstanceId: () => this.getInstanceId(),
426
+ getUserId: () => this.getUserId(),
427
+ getTrackingId: () => this.getTrackingId(),
428
+ getTarget: () => this.getTarget(),
429
+ getDiagnostics: () => this.getDiagnostics(),
430
+ getStatus: () => {
431
+ console.log(this.getStatus());
432
+ return this.getDiagnostics();
433
+ },
434
+ testTracking: () => this.testTracking(),
435
+ verifyAWSConnection: () => {
436
+ const result = this.verifyAWSConnection();
437
+ console.log("AWS Connection Verification:", result.message);
438
+ console.log("Full details:", result);
439
+ return result;
440
+ },
441
+ isInitialized: () => this.isInitialized(),
442
+ page: (url, properties) => this.page(url, properties),
443
+ track: (eventName, properties) => this.track(eventName, properties),
444
+ identify: (userId, traits) => this.identify(userId, traits)
445
+ };
446
+ }
418
447
  async performInit(config) {
419
448
  if (!this.adapter) {
420
449
  this.adapter = new AWSAdapter();
@@ -430,6 +459,12 @@ var AmplifyUpSDK = class {
430
459
  const previewOverrides = readPreviewQueryOverrides();
431
460
  if (previewOverrides.orchestratorUrl) {
432
461
  this.orchestratorUrl = previewOverrides.orchestratorUrl;
462
+ if (isRemoteOrchestratorUrl(previewOverrides.orchestratorUrl)) {
463
+ const prodUrls = resolveAmplifyUpUrls("production");
464
+ this.target = "production";
465
+ this.apiGatewayUrl = prodUrls.apiGatewayUrl;
466
+ this.decisionApiUrl = prodUrls.decisionApiUrl;
467
+ }
433
468
  }
434
469
  this.config = {
435
470
  trackingId: previewOverrides.trackingId || config.trackingId,
@@ -447,34 +482,10 @@ var AmplifyUpSDK = class {
447
482
  };
448
483
  await this.adapter.init(adapterConfig);
449
484
  this.initialized = this.adapter.isInitialized();
450
- if (typeof window !== "undefined") {
451
- window.AmplifyUp = {
452
- getInstanceId: () => this.getInstanceId(),
453
- getUserId: () => this.getUserId(),
454
- getTrackingId: () => this.getTrackingId(),
455
- getTarget: () => this.getTarget(),
456
- getDiagnostics: () => this.getDiagnostics(),
457
- getStatus: () => {
458
- console.log(this.getStatus());
459
- return this.getDiagnostics();
460
- },
461
- testTracking: () => this.testTracking(),
462
- verifyAWSConnection: () => {
463
- const result = this.verifyAWSConnection();
464
- console.log("AWS Connection Verification:", result.message);
465
- console.log("Full details:", result);
466
- return result;
467
- },
468
- isInitialized: () => this.isInitialized(),
469
- // Re-export main tracking methods for convenience
470
- page: (url, properties) => this.page(url, properties),
471
- track: (eventName, properties) => this.track(eventName, properties),
472
- identify: (userId, traits) => this.identify(userId, traits)
473
- };
474
- if (this.config?.debug) {
475
- console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
476
- console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
477
- }
485
+ this.ensureWindowBridge();
486
+ if (this.config?.debug) {
487
+ console.log("AmplifyUp SDK: Diagnostic methods available on window.AmplifyUp");
488
+ console.log("Try: AmplifyUp.getStatus() or AmplifyUp.testTracking()");
478
489
  }
479
490
  this.clearTrackingIntervals();
480
491
  if (this.isPreviewMode()) {
@@ -1485,10 +1496,17 @@ Available Console Commands:
1485
1496
  }
1486
1497
  };
1487
1498
  var sdkInstance = null;
1499
+ if (typeof window !== "undefined" && window.__AMPLIFYUP_SDK__) {
1500
+ sdkInstance = window.__AMPLIFYUP_SDK__;
1501
+ }
1488
1502
  function getSDK(adapter) {
1489
1503
  if (!sdkInstance) {
1490
1504
  sdkInstance = new AmplifyUpSDK(adapter);
1505
+ if (typeof window !== "undefined") {
1506
+ window.__AMPLIFYUP_SDK__ = sdkInstance;
1507
+ }
1491
1508
  }
1509
+ sdkInstance.ensureWindowBridge();
1492
1510
  return sdkInstance;
1493
1511
  }
1494
1512
  var trackContentView = (contentId, contentType, properties) => getSDK().trackContentView(contentId, contentType, properties);