@amplifyup/sdk 0.1.3 → 0.1.5

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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-Xv9P55Dj.mjs';
2
- export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-Xv9P55Dj.mjs';
1
+ import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-B2Swk8BW.mjs';
2
+ export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-B2Swk8BW.mjs';
3
3
 
4
4
  /**
5
5
  * AmplifyUp Tracking SDK
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-Xv9P55Dj.js';
2
- export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-Xv9P55Dj.js';
1
+ import { C as CDPAdapter, A as AmplifyUpConfig, E as EventProperties, I as IdentifyTraits, a as AmplifyUpTarget, b as EventTrackingConfig$1 } from './types-B2Swk8BW.js';
2
+ export { P as PageConfig, Z as ZoneConfig, i as isAmplifyUpTarget, n as normalizeAmplifyUpTarget, r as resolveAmplifyUpTarget, c as resolveAmplifyUpUrls } from './types-B2Swk8BW.js';
3
3
 
4
4
  /**
5
5
  * AmplifyUp Tracking SDK
package/dist/index.js CHANGED
@@ -234,14 +234,16 @@ function resolveAmplifyUpTarget(options) {
234
234
  if (isAmplifyUpTarget(envTarget)) {
235
235
  return normalizeAmplifyUpTarget(envTarget);
236
236
  }
237
- if (typeof window !== "undefined") {
238
- const host = window.location.hostname;
239
- if (host === "localhost" || host === "127.0.0.1") {
240
- return "local";
241
- }
242
- }
243
237
  return "production";
244
238
  }
239
+ function isRemoteOrchestratorUrl(orchestratorUrl) {
240
+ try {
241
+ const host = new URL(orchestratorUrl).hostname.toLowerCase();
242
+ return host !== "localhost" && host !== "127.0.0.1" && host !== "::1";
243
+ } catch {
244
+ return false;
245
+ }
246
+ }
245
247
  function localOrchestratorUrl() {
246
248
  const fromEnv = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_ORCHESTRATOR_URL : void 0;
247
249
  return (fromEnv || "http://localhost:5001").replace(/\/$/, "");
@@ -276,6 +278,26 @@ function resolveAmplifyUpUrls(target) {
276
278
  }
277
279
 
278
280
  // src/index.ts
281
+ function readPreviewQueryOverrides() {
282
+ if (typeof window === "undefined") return {};
283
+ const params = new URLSearchParams(window.location.search);
284
+ if (params.get("preview") !== "true" && params.get("visualEditor") !== "true") {
285
+ return {};
286
+ }
287
+ const overrides = {};
288
+ const orchestratorFromQuery = params.get("orchestratorUrl");
289
+ if (orchestratorFromQuery) {
290
+ try {
291
+ overrides.orchestratorUrl = new URL(orchestratorFromQuery).origin.replace(/\/$/, "");
292
+ } catch {
293
+ }
294
+ }
295
+ const trackingFromQuery = params.get("trackingId");
296
+ if (trackingFromQuery) {
297
+ overrides.trackingId = trackingFromQuery;
298
+ }
299
+ return overrides;
300
+ }
279
301
  var AmplifyUpSDK = class {
280
302
  constructor(adapter) {
281
303
  this.config = null;
@@ -401,8 +423,18 @@ var AmplifyUpSDK = class {
401
423
  this.apiGatewayUrl = urls.apiGatewayUrl;
402
424
  this.orchestratorUrl = urls.orchestratorUrl;
403
425
  this.decisionApiUrl = urls.decisionApiUrl;
426
+ const previewOverrides = readPreviewQueryOverrides();
427
+ if (previewOverrides.orchestratorUrl) {
428
+ this.orchestratorUrl = previewOverrides.orchestratorUrl;
429
+ if (isRemoteOrchestratorUrl(previewOverrides.orchestratorUrl)) {
430
+ const prodUrls = resolveAmplifyUpUrls("production");
431
+ this.target = "production";
432
+ this.apiGatewayUrl = prodUrls.apiGatewayUrl;
433
+ this.decisionApiUrl = prodUrls.decisionApiUrl;
434
+ }
435
+ }
404
436
  this.config = {
405
- trackingId: config.trackingId,
437
+ trackingId: previewOverrides.trackingId || config.trackingId,
406
438
  debug: config.debug ?? true,
407
439
  // Enable debug by default
408
440
  target: this.target,