@upscopeio/react 2025.11.12 → 2025.12.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/index.d.ts CHANGED
@@ -1,20 +1,24 @@
1
1
  import { CobrowsingSdkConfiguration, Upscope } from "./sdk";
2
2
  import { SDKEvents } from "./sdk-types";
3
3
 
4
- type UpscopeProviderProps = {
5
- test?: boolean;
6
- enabled?: boolean;
7
- children: React.ReactNode;
8
- apiKey: string;
9
- } & Partial<Omit<CobrowsingSdkConfiguration, "apiKey" | "regionWhitelist">>;
10
-
11
4
  type UpscopeContext = {
12
- Upscope: Upscope | undefined;
13
- shortId: string | undefined;
14
5
  getLookupCode: () => Promise<string | undefined>;
15
- listen: (event: keyof SDKEvents, callback: (data: any) => void) => void;
16
- reset: () => void;
17
6
  isSharing: boolean;
7
+ listen: <T extends keyof SDKEvents>(
8
+ event: T,
9
+ callback: SDKEvents[T] extends undefined ? () => void : (...args: SDKEvents[T]) => void,
10
+ ) => void;
11
+ reset: () => void;
12
+ shortId: string | undefined;
13
+ Upscope: undefined | Upscope;
14
+ };
15
+
16
+ type UpscopeProviderProps = Partial<Omit<CobrowsingSdkConfiguration, "apiKey" | "regionWhitelist">> & {
17
+ apiKey: string;
18
+ children: React.ReactNode;
19
+ enabled?: boolean;
20
+ test?: boolean;
21
+ windowContext?: Window;
18
22
  };
19
23
 
20
24
  export function useUpscope(): UpscopeContext;
package/index.js CHANGED
@@ -238,10 +238,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
238
238
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
239
239
  import equal from "fast-deep-equal";
240
240
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
241
- import _Upscope from "./sdk.js";
241
+ import { upscopeFor } from "./sdk.js";
242
242
  var UpscopeContext = createContext({
243
- Upscope: undefined,
244
- shortId: undefined,
245
243
  getLookupCode: function getLookupCode() {
246
244
  return _asyncToGenerator(function() {
247
245
  return __generator(this, function(_state) {
@@ -252,18 +250,77 @@ var UpscopeContext = createContext({
252
250
  });
253
251
  })();
254
252
  },
253
+ isSharing: false,
255
254
  listen: function(event, callback) {},
256
255
  reset: function() {},
257
- isSharing: false
256
+ shortId: undefined,
257
+ Upscope: undefined
258
258
  });
259
- export function useUpscope() {
260
- return useContext(UpscopeContext);
259
+ export function Masked(param) {
260
+ var children = param.children;
261
+ var beforeRef = useRef(null);
262
+ var afterRef = useRef(null);
263
+ useEffect(function() {
264
+ if (beforeRef.current && afterRef.current) {
265
+ var nextSibling = beforeRef.current.nextSibling;
266
+ while(nextSibling && nextSibling !== afterRef.current){
267
+ nextSibling.dataset.upscopeMasked = "true";
268
+ nextSibling = nextSibling.nextSibling;
269
+ }
270
+ }
271
+ }, [
272
+ beforeRef,
273
+ afterRef,
274
+ children
275
+ ]);
276
+ return _jsxs(_Fragment, {
277
+ children: [
278
+ _jsx("script", {
279
+ ref: beforeRef
280
+ }),
281
+ children,
282
+ _jsx("script", {
283
+ ref: afterRef
284
+ })
285
+ ]
286
+ });
287
+ }
288
+ export function NoRemoteControl(param) {
289
+ var children = param.children;
290
+ var beforeRef = useRef(null);
291
+ var afterRef = useRef(null);
292
+ useEffect(function() {
293
+ if (beforeRef.current && afterRef.current) {
294
+ var nextSibling = beforeRef.current.nextSibling;
295
+ while(nextSibling && nextSibling !== afterRef.current){
296
+ nextSibling.dataset.upscopeNoRemoteControl = "true";
297
+ nextSibling = nextSibling.nextSibling;
298
+ }
299
+ }
300
+ }, [
301
+ beforeRef,
302
+ afterRef,
303
+ children
304
+ ]);
305
+ return _jsxs(_Fragment, {
306
+ children: [
307
+ _jsx("script", {
308
+ ref: beforeRef
309
+ }),
310
+ children,
311
+ _jsx("script", {
312
+ ref: afterRef
313
+ })
314
+ ]
315
+ });
261
316
  }
262
317
  export function UpscopeProvider(_param) {
263
- var children = _param.children, enabled = _param.enabled, test = _param.test, configProps = _objectWithoutProperties(_param, [
318
+ var _this = this;
319
+ var children = _param.children, enabled = _param.enabled, test = _param.test, windowContext = _param.windowContext, configProps = _objectWithoutProperties(_param, [
264
320
  "children",
265
321
  "enabled",
266
- "test"
322
+ "test",
323
+ "windowContext"
267
324
  ]);
268
325
  var Upscope = useMemo(function() {
269
326
  return function() {
@@ -271,10 +328,11 @@ export function UpscopeProvider(_param) {
271
328
  args[_key] = arguments[_key];
272
329
  }
273
330
  if (test) return; // Do not use Upscope SDK on test
274
- return _Upscope.apply(void 0, _toConsumableArray(args));
331
+ upscopeFor(windowContext !== null && windowContext !== void 0 ? windowContext : window).apply(_this, _toConsumableArray(args));
275
332
  };
276
333
  }, [
277
- test
334
+ test,
335
+ windowContext
278
336
  ]);
279
337
  var _useState = _slicedToArray(useState(false), 2), loaded = _useState[0], setLoaded = _useState[1];
280
338
  var _useState1 = _slicedToArray(useState(false), 2), sharing = _useState1[0], setSharing = _useState1[1];
@@ -352,7 +410,6 @@ export function UpscopeProvider(_param) {
352
410
  configProps
353
411
  ]);
354
412
  useEffect(function() {
355
- if (!loaded) return;
356
413
  Upscope("on", "sessionStart", function() {
357
414
  setSharing(true);
358
415
  });
@@ -363,17 +420,24 @@ export function UpscopeProvider(_param) {
363
420
  setSharing(false);
364
421
  });
365
422
  }, [
366
- loaded,
367
423
  Upscope
368
424
  ]);
369
- var getLookupCode = useCallback(function() {
370
- return new Promise(function(resolve) {
371
- if (!upscopeActive) return resolve(undefined);
372
- Upscope("getLookupCode", function(lookupCode) {
373
- resolve(lookupCode);
374
- });
425
+ var getLookupCode = useCallback(/*#__PURE__*/ _asyncToGenerator(function() {
426
+ return __generator(this, function(_state) {
427
+ return [
428
+ 2,
429
+ new Promise(function(resolve) {
430
+ if (!upscopeActive) {
431
+ resolve(undefined);
432
+ return;
433
+ }
434
+ Upscope("getLookupCode", function(lookupCode) {
435
+ resolve(lookupCode);
436
+ });
437
+ })
438
+ ];
375
439
  });
376
- }, [
440
+ }), [
377
441
  upscopeActive,
378
442
  Upscope
379
443
  ]);
@@ -389,73 +453,18 @@ export function UpscopeProvider(_param) {
389
453
  ]);
390
454
  return _jsx(UpscopeContext.Provider, {
391
455
  value: {
392
- Upscope: Upscope,
393
- shortId: shortId,
394
456
  getLookupCode: getLookupCode,
457
+ isSharing: sharing,
395
458
  listen: listen,
396
459
  reset: reset,
397
- isSharing: sharing
460
+ shortId: shortId,
461
+ Upscope: Upscope
398
462
  },
399
463
  children: children
400
464
  });
401
465
  }
402
- export function Masked(param) {
403
- var children = param.children;
404
- var beforeRef = useRef(null);
405
- var afterRef = useRef(null);
406
- useEffect(function() {
407
- if (beforeRef.current && afterRef.current) {
408
- var nextSibling = beforeRef.current.nextSibling;
409
- while(nextSibling && nextSibling !== afterRef.current){
410
- nextSibling.dataset.upscopeMasked = true;
411
- nextSibling = nextSibling.nextSibling;
412
- }
413
- }
414
- }, [
415
- beforeRef,
416
- afterRef,
417
- children
418
- ]);
419
- return _jsxs(_Fragment, {
420
- children: [
421
- _jsx("script", {
422
- ref: beforeRef
423
- }),
424
- children,
425
- _jsx("script", {
426
- ref: afterRef
427
- })
428
- ]
429
- });
430
- }
431
- export function NoRemoteControl(param) {
432
- var children = param.children;
433
- var beforeRef = useRef(null);
434
- var afterRef = useRef(null);
435
- useEffect(function() {
436
- if (beforeRef.current && afterRef.current) {
437
- var nextSibling = beforeRef.current.nextSibling;
438
- while(nextSibling && nextSibling !== afterRef.current){
439
- nextSibling.dataset.upscopeNoRemoteControl = true;
440
- nextSibling = nextSibling.nextSibling;
441
- }
442
- }
443
- }, [
444
- beforeRef,
445
- afterRef,
446
- children
447
- ]);
448
- return _jsxs(_Fragment, {
449
- children: [
450
- _jsx("script", {
451
- ref: beforeRef
452
- }),
453
- children,
454
- _jsx("script", {
455
- ref: afterRef
456
- })
457
- ]
458
- });
466
+ export function useUpscope() {
467
+ return useContext(UpscopeContext);
459
468
  }
460
469
 
461
470
 
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"names":[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,aAAa,GAAG,IAAI;gBACxC,cAAc,YAAY,WAAW;YACzC;QACJ,CAAC;IACL,GAAG;QAAC;QAAW;QAAU;KAAS;IAClC,OAAQ,MAAM,WAAW;QAAE,UAAU;YAAC,KAAK,UAAU;gBAAE,KAAK;YAAU;YAAI;YAAU,KAAK,UAAU;gBAAE,KAAK;YAAS;SAAG;IAAC;AAC3H,CAAC;AACD,OAAO,SAAS,gBAAgB,KAAY,EAAE;QAAd,AAAE,WAAF,MAAE;IAC9B,IAAM,YAAY,OAAO,IAAI;IAC7B,IAAM,WAAW,OAAO,IAAI;IAC5B,UAAU,WAAM;QACZ,IAAI,UAAU,OAAO,IAAI,SAAS,OAAO,EAAE;YACvC,IAAI,cAAc,UAAU,OAAO,CAAC,WAAW;YAC/C,MAAO,eAAe,gBAAgB,SAAS,OAAO,CAAE;gBACpD,YAAY,OAAO,CAAC,sBAAsB,GAAG,IAAI;gBACjD,cAAc,YAAY,WAAW;YACzC;QACJ,CAAC;IACL,GAAG;QAAC;QAAW;QAAU;KAAS;IAClC,OAAQ,MAAM,WAAW;QAAE,UAAU;YAAC,KAAK,UAAU;gBAAE,KAAK;YAAU;YAAI;YAAU,KAAK,UAAU;gBAAE,KAAK;YAAS;SAAG;IAAC;AAC3H,CAAC","file":"index.js","sourcesContent":["import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nimport equal from \"fast-deep-equal\";\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport _Upscope from \"./sdk.js\";\nconst UpscopeContext = createContext({\n Upscope: undefined,\n shortId: undefined,\n async getLookupCode() {\n return \"\";\n },\n listen: (event, callback) => { },\n reset: () => { },\n isSharing: false,\n});\nexport function useUpscope() {\n return useContext(UpscopeContext);\n}\nexport function UpscopeProvider({ children, enabled, test, ...configProps }) {\n const Upscope = useMemo(() => (...args) => {\n if (test)\n return; // Do not use Upscope SDK on test\n return _Upscope(...args);\n }, [test]);\n const [loaded, setLoaded] = useState(false);\n const [sharing, setSharing] = useState(false);\n const [shortId, setShortId] = useState(undefined);\n const [currentConfiguration, setCurrentConfiguration] = useState(undefined);\n const upscopeActive = enabled && loaded;\n const [pendingConfigurationUpdate, setPendingConfigurationUpdate] = useState(null);\n enabled ??= true;\n useEffect(() => {\n if (currentConfiguration === undefined || !upscopeActive) {\n setPendingConfigurationUpdate(null);\n return;\n }\n const config = Object.entries(configProps)\n .filter(([configName, configValue]) => configName !== \"regionWhitelist\" &&\n !equal(configValue, currentConfiguration[configName]))\n .reduce((config, [configName, configValue]) => {\n config[configName] = configValue;\n return config;\n }, {});\n setPendingConfigurationUpdate(Object.keys(config).length === 0 ? null : config);\n }, [currentConfiguration, configProps, upscopeActive]);\n useEffect(() => {\n if (!currentConfiguration)\n return;\n const isEnabledFirstTime = enabled && !loaded;\n const isDisabledAfterInit = !enabled && loaded;\n if (isEnabledFirstTime) {\n Upscope(\"init\", currentConfiguration);\n setLoaded(true);\n }\n else if (isDisabledAfterInit) {\n Upscope(\"reset\", false);\n }\n }, [enabled, loaded, currentConfiguration, Upscope]);\n useEffect(() => {\n if (upscopeActive) {\n Upscope(\"getShortId\", (shortId) => {\n setShortId(shortId);\n });\n }\n else {\n setShortId(undefined);\n }\n }, [upscopeActive, Upscope]);\n useEffect(() => {\n if (!upscopeActive || !pendingConfigurationUpdate || !currentConfiguration)\n return;\n Upscope(\"updateConnection\", pendingConfigurationUpdate);\n setPendingConfigurationUpdate(null);\n const newCurrentConfiguration = { ...currentConfiguration, ...pendingConfigurationUpdate };\n setCurrentConfiguration(newCurrentConfiguration);\n }, [upscopeActive, pendingConfigurationUpdate, currentConfiguration, Upscope]);\n useEffect(() => {\n if (currentConfiguration || !enabled)\n return;\n // Initialize configurations\n setCurrentConfiguration(configProps);\n }, [enabled, currentConfiguration, configProps]);\n useEffect(() => {\n if (!loaded)\n return;\n Upscope(\"on\", \"sessionStart\", () => {\n setSharing(true);\n });\n Upscope(\"on\", \"sessionContinue\", () => {\n setSharing(true);\n });\n Upscope(\"on\", \"sessionEnd\", () => {\n setSharing(false);\n });\n }, [loaded, Upscope]);\n const getLookupCode = useCallback(() => {\n return new Promise((resolve) => {\n if (!upscopeActive)\n return resolve(undefined);\n Upscope(\"getLookupCode\", (lookupCode) => {\n resolve(lookupCode);\n });\n });\n }, [upscopeActive, Upscope]);\n const listen = useCallback((event, callback) => {\n Upscope(\"on\", event, callback);\n }, [Upscope]);\n const reset = useCallback(() => {\n Upscope(\"reset\", true);\n }, [Upscope]);\n return (_jsx(UpscopeContext.Provider, { value: {\n Upscope,\n shortId,\n getLookupCode,\n listen,\n reset,\n isSharing: sharing,\n }, children: children }));\n}\nexport function Masked({ children }) {\n const beforeRef = useRef(null);\n const afterRef = useRef(null);\n useEffect(() => {\n if (beforeRef.current && afterRef.current) {\n let nextSibling = beforeRef.current.nextSibling;\n while (nextSibling && nextSibling !== afterRef.current) {\n nextSibling.dataset.upscopeMasked = true;\n nextSibling = nextSibling.nextSibling;\n }\n }\n }, [beforeRef, afterRef, children]);\n return (_jsxs(_Fragment, { children: [_jsx(\"script\", { ref: beforeRef }), children, _jsx(\"script\", { ref: afterRef })] }));\n}\nexport function NoRemoteControl({ children }) {\n const beforeRef = useRef(null);\n const afterRef = useRef(null);\n useEffect(() => {\n if (beforeRef.current && afterRef.current) {\n let nextSibling = beforeRef.current.nextSibling;\n while (nextSibling && nextSibling !== afterRef.current) {\n nextSibling.dataset.upscopeNoRemoteControl = true;\n nextSibling = nextSibling.nextSibling;\n }\n }\n }, [beforeRef, afterRef, children]);\n return (_jsxs(_Fragment, { children: [_jsx(\"script\", { ref: beforeRef }), children, _jsx(\"script\", { ref: afterRef })] }));\n}\n"]}
1
+ {"version":3,"sources":["index.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACA,QAAQ,MAAM,cAAc,WAAM;YAC9B,WAAW,KAAK;QACpB;IACJ,GAAG;QAAC;KAAQ;IACZ,IAAM,gBAAgB,0BAAY,kBAAA,WAAY;;YAC1C;;gBAAO,IAAI,QAAQ,SAAC,SAAY;oBAC5B,IAAI,CAAC,eAAe;wBAChB,QAAQ;wBACR;oBACJ,CAAC;oBACD,QAAQ,iBAAiB,SAAC,YAAe;wBACrC,QAAQ;oBACZ;gBACJ;;;IACJ,IAAG;QAAC;QAAe;KAAQ;IAC3B,IAAM,SAAS,YAAY,SAAC,OAAO,UAAa;QAC5C,QAAQ,MAAM,OAAO;IACzB,GAAG;QAAC;KAAQ;IACZ,IAAM,QAAQ,YAAY,WAAM;QAC5B,QAAQ,SAAS,IAAI;IACzB,GAAG;QAAC;KAAQ;IACZ,OAAQ,KAAK,eAAe,QAAQ,EAAE;QAAE,OAAO;YACvC,eAAA;YACA,WAAW;YACX,QAAA;YACA,OAAA;YACA,SAAA;YACA,SAAA;QACJ;QAAG,UAAU;IAAS;AAC9B,CAAC;AACD,OAAO,SAAS,aAAa;IACzB,OAAO,WAAW;AACtB,CAAC","file":"index.js","sourcesContent":["import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nimport equal from \"fast-deep-equal\";\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport { upscopeFor } from \"./sdk.js\";\nconst UpscopeContext = createContext({\n async getLookupCode() {\n return \"\";\n },\n isSharing: false,\n listen: (event, callback) => { },\n reset: () => { },\n shortId: undefined,\n Upscope: undefined,\n});\nexport function Masked({ children }) {\n const beforeRef = useRef(null);\n const afterRef = useRef(null);\n useEffect(() => {\n if (beforeRef.current && afterRef.current) {\n let { nextSibling } = beforeRef.current;\n while (nextSibling && nextSibling !== afterRef.current) {\n nextSibling.dataset.upscopeMasked = \"true\";\n nextSibling = nextSibling.nextSibling;\n }\n }\n }, [beforeRef, afterRef, children]);\n return (_jsxs(_Fragment, { children: [_jsx(\"script\", { ref: beforeRef }), children, _jsx(\"script\", { ref: afterRef })] }));\n}\nexport function NoRemoteControl({ children }) {\n const beforeRef = useRef(null);\n const afterRef = useRef(null);\n useEffect(() => {\n if (beforeRef.current && afterRef.current) {\n let { nextSibling } = beforeRef.current;\n while (nextSibling && nextSibling !== afterRef.current) {\n nextSibling.dataset.upscopeNoRemoteControl = \"true\";\n nextSibling = nextSibling.nextSibling;\n }\n }\n }, [beforeRef, afterRef, children]);\n return (_jsxs(_Fragment, { children: [_jsx(\"script\", { ref: beforeRef }), children, _jsx(\"script\", { ref: afterRef })] }));\n}\nexport function UpscopeProvider({ children, enabled, test, windowContext, ...configProps }) {\n const Upscope = useMemo(() => (...args) => {\n if (test)\n return; // Do not use Upscope SDK on test\n upscopeFor(windowContext ?? window)(...args);\n }, [test, windowContext]);\n const [loaded, setLoaded] = useState(false);\n const [sharing, setSharing] = useState(false);\n const [shortId, setShortId] = useState(undefined);\n const [currentConfiguration, setCurrentConfiguration] = useState(undefined);\n const upscopeActive = enabled && loaded;\n const [pendingConfigurationUpdate, setPendingConfigurationUpdate] = useState(null);\n enabled ??= true;\n useEffect(() => {\n if (currentConfiguration === undefined || !upscopeActive) {\n setPendingConfigurationUpdate(null);\n return;\n }\n const config = Object.entries(configProps)\n .filter(([configName, configValue]) => configName !== \"regionWhitelist\" &&\n !equal(configValue, currentConfiguration[configName]))\n .reduce((config, [configName, configValue]) => {\n config[configName] = configValue;\n return config;\n }, {});\n setPendingConfigurationUpdate(Object.keys(config).length === 0 ? null : config);\n }, [currentConfiguration, configProps, upscopeActive]);\n useEffect(() => {\n if (!currentConfiguration)\n return;\n const isEnabledFirstTime = enabled && !loaded;\n const isDisabledAfterInit = !enabled && loaded;\n if (isEnabledFirstTime) {\n Upscope(\"init\", currentConfiguration);\n setLoaded(true);\n }\n else if (isDisabledAfterInit) {\n Upscope(\"reset\", false);\n }\n }, [enabled, loaded, currentConfiguration, Upscope]);\n useEffect(() => {\n if (upscopeActive) {\n Upscope(\"getShortId\", (shortId) => {\n setShortId(shortId);\n });\n }\n else {\n setShortId(undefined);\n }\n }, [upscopeActive, Upscope]);\n useEffect(() => {\n if (!upscopeActive || !pendingConfigurationUpdate || !currentConfiguration)\n return;\n Upscope(\"updateConnection\", pendingConfigurationUpdate);\n setPendingConfigurationUpdate(null);\n const newCurrentConfiguration = { ...currentConfiguration, ...pendingConfigurationUpdate };\n setCurrentConfiguration(newCurrentConfiguration);\n }, [upscopeActive, pendingConfigurationUpdate, currentConfiguration, Upscope]);\n useEffect(() => {\n if (currentConfiguration || !enabled)\n return;\n // Initialize configurations\n setCurrentConfiguration(configProps);\n }, [enabled, currentConfiguration, configProps]);\n useEffect(() => {\n Upscope(\"on\", \"sessionStart\", () => {\n setSharing(true);\n });\n Upscope(\"on\", \"sessionContinue\", () => {\n setSharing(true);\n });\n Upscope(\"on\", \"sessionEnd\", () => {\n setSharing(false);\n });\n }, [Upscope]);\n const getLookupCode = useCallback(async () => {\n return new Promise((resolve) => {\n if (!upscopeActive) {\n resolve(undefined);\n return;\n }\n Upscope(\"getLookupCode\", (lookupCode) => {\n resolve(lookupCode);\n });\n });\n }, [upscopeActive, Upscope]);\n const listen = useCallback((event, callback) => {\n Upscope(\"on\", event, callback);\n }, [Upscope]);\n const reset = useCallback(() => {\n Upscope(\"reset\", true);\n }, [Upscope]);\n return (_jsx(UpscopeContext.Provider, { value: {\n getLookupCode,\n isSharing: sharing,\n listen,\n reset,\n shortId,\n Upscope,\n }, children: children }));\n}\nexport function useUpscope() {\n return useContext(UpscopeContext);\n}\n"]}
package/package.json CHANGED
@@ -9,5 +9,5 @@
9
9
  "react": ">=16.2.0",
10
10
  "react-dom": ">=16.2.0"
11
11
  },
12
- "version": "2025.11.12"
12
+ "version": "2025.12.6"
13
13
  }
package/sdk.js CHANGED
@@ -23,10 +23,11 @@ function _unsupportedIterableToArray(o, minLen) {
23
23
  if (n === "Map" || n === "Set") return Array.from(n);
24
24
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
25
25
  }
26
- var loaded = false;
27
- function loadSDK(apiKey) {
28
- if (typeof window.Upscope !== "undefined") {
29
- loaded = true;
26
+ var loadedWindows = new WeakSet();
27
+ var environment = window.__upscope__sdk__load__environment;
28
+ function loadSDK(w, apiKey) {
29
+ if (typeof w.Upscope !== "undefined") {
30
+ loadedWindows.add(w);
30
31
  return;
31
32
  }
32
33
  var i = function i1() {
@@ -37,30 +38,46 @@ function loadSDK(apiKey) {
37
38
  };
38
39
  i.q = [];
39
40
  // The real Upscope implementation is loaded below
40
- window.Upscope = i;
41
+ w.Upscope = i;
41
42
  var s = document.createElement("script");
42
43
  s.type = "text/javascript";
43
44
  s.async = true;
44
- s.src = "https://code.upscope.io/".concat(apiKey, ".js");
45
+ var _;
46
+ s.src = (_ = ({
47
+ development: "http://code.upscope.local/".concat(apiKey, ".js"),
48
+ production: "https://code.upscope.io/".concat(apiKey, ".js"),
49
+ staging: "https://code.upscope.xyz/".concat(apiKey, ".js")
50
+ })[environment !== null && environment !== void 0 ? environment : "production"]) !== null && _ !== void 0 ? _ : "https://code.upscope.io/".concat(apiKey, ".js");
45
51
  document.head.appendChild(s);
46
- loaded = true;
52
+ loadedWindows.add(w);
47
53
  }
48
- var _Upscope = function _Upscope() {
49
- for(var _len = arguments.length, instruction = new Array(_len), _key = 0; _key < _len; _key++){
50
- instruction[_key] = arguments[_key];
54
+ var ScopedUpscope = function ScopedUpscope(w) {
55
+ for(var _len = arguments.length, instruction = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
56
+ instruction[_key - 1] = arguments[_key];
51
57
  }
52
- var _window;
53
- if (!loaded) {
58
+ var _w;
59
+ if (!loadedWindows.has(w)) {
54
60
  if (instruction[0] === "init") {
55
61
  var config = instruction[1];
56
62
  if (!(config === null || config === void 0 ? void 0 : config.apiKey)) throw new Error("API key not specified");
57
- loadSDK(config.apiKey);
63
+ loadSDK(w, config.apiKey);
58
64
  } else {
59
65
  throw new Error("Upscope is not loaded");
60
66
  }
61
67
  }
62
- return (_window = window).Upscope.apply(_window, _toConsumableArray(instruction));
68
+ (_w = w).Upscope.apply(_w, _toConsumableArray(instruction));
63
69
  };
70
+ export var upscopeFor = function upscopeFor(w) {
71
+ return function() {
72
+ for(var _len = arguments.length, instruction = new Array(_len), _key = 0; _key < _len; _key++){
73
+ instruction[_key] = arguments[_key];
74
+ }
75
+ ScopedUpscope.apply(void 0, [
76
+ w
77
+ ].concat(_toConsumableArray(instruction)));
78
+ };
79
+ };
80
+ var _Upscope = upscopeFor(window);
64
81
  export default _Upscope;
65
82
 
66
83
 
package/sdk.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["sdk.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,SAAS,KAAK;AAClB,SAAS,QAAQ,MAAM,EAAE;IACrB,IAAI,OAAO,OAAO,OAAO,KAAK,aAAa;QACvC,SAAS,IAAI;QACb;IACJ,CAAC;IACD,IAAM,IAAI,SAAJ,KAAuB;QAAT,IAAA,IAAA,OAAA,UAAA,QAAA,AAAG,OAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA,OAAA;YAAG,KAAH,QAAA,SAAA,CAAA,KAAO;QAAD;QACtB,EAAE,CAAC,CAAC,IAAI,CAAC;IACb;IACA,EAAE,CAAC,GAAG,EAAE;IACR,kDAAkD;IAClD,OAAO,OAAO,GAAG;IACjB,IAAM,IAAI,SAAS,aAAa,CAAC;IACjC,EAAE,IAAI,GAAG;IACT,EAAE,KAAK,GAAG,IAAI;IACd,EAAE,GAAG,GAAG,AAAC,2BAAiC,OAAP,QAAO;IAC1C,SAAS,IAAI,CAAC,WAAW,CAAC;IAC1B,SAAS,IAAI;AACjB;AACA,IAAM,WAAW,SAAX,WAAqC;IAAhB,IAAA,IAAA,OAAA,UAAA,QAAA,AAAG,cAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA,OAAA;QAAG,YAAH,QAAA,SAAA,CAAA,KAAc;IAAD;QAY7B;IAXP,IAAI,CAAC,QAAQ;QACT,IAAI,WAAW,CAAC,EAAE,KAAK,QAAQ;YAC3B,IAAM,SAAS,WAAW,CAAC,EAAE;YAC7B,IAAI,CAAC,CAAA,mBAAA,oBAAA,KAAA,IAAA,OAAQ,MAAK,AAAC,GACf,MAAM,IAAI,MAAM,yBAAyB;YAC7C,QAAQ,OAAO,MAAM;QACzB,OACK;YACD,MAAM,IAAI,MAAM,yBAAyB;QAC7C,CAAC;IACL,CAAC;IACD,OAAO,CAAA,UAAA,QAAO,OAAO,CAAd,MAAA,SAAe,mBAAG;AAC7B;AACA,eAAe,SAAS","file":"sdk.js","sourcesContent":["let loaded = false;\nfunction loadSDK(apiKey) {\n if (typeof window.Upscope !== \"undefined\") {\n loaded = true;\n return;\n }\n const i = function (...args) {\n i.q.push(args);\n };\n i.q = [];\n // The real Upscope implementation is loaded below\n window.Upscope = i;\n const s = document.createElement(\"script\");\n s.type = \"text/javascript\";\n s.async = true;\n s.src = `https://code.upscope.io/${apiKey}.js`;\n document.head.appendChild(s);\n loaded = true;\n}\nconst _Upscope = function (...instruction) {\n if (!loaded) {\n if (instruction[0] === \"init\") {\n const config = instruction[1];\n if (!config?.apiKey)\n throw new Error(\"API key not specified\");\n loadSDK(config.apiKey);\n }\n else {\n throw new Error(\"Upscope is not loaded\");\n }\n }\n return window.Upscope(...instruction);\n};\nexport default _Upscope;\n"]}
1
+ {"version":3,"sources":["sdk.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,gBAAgB,IAAI;AAC1B,IAAM,cAAc,OAAO,iCAAiC;AAC5D,SAAS,QAAQ,CAAC,EAAE,MAAM,EAAE;IACxB,IAAI,OAAO,EAAE,OAAO,KAAK,aAAa;QAClC,cAAc,GAAG,CAAC;QAClB;IACJ,CAAC;IACD,IAAM,IAAI,SAAJ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KAAA,GAAE,OAAO,CAAT,MAAA,IAAU,mBAAG;AACjB;AACA,OAAO,IAAM,aAAa,SAAb,WAAuB,CAAC,EAAE;IACnC,OAAO,WAAoB;yCAAhB;YAAA;;QACP,cAAA,MAAA,KAAA,GAAA;YAAc;SAAkB,CAAhC,OAAiB,mBAAG;IACxB;AACJ,EAAE;AACF,IAAM,WAAW,WAAW;AAC5B,eAAe,SAAS","file":"sdk.js","sourcesContent":["const loadedWindows = new WeakSet();\nconst environment = window.__upscope__sdk__load__environment;\nfunction loadSDK(w, apiKey) {\n if (typeof w.Upscope !== \"undefined\") {\n loadedWindows.add(w);\n return;\n }\n const i = function (...args) {\n i.q.push(args);\n };\n i.q = [];\n // The real Upscope implementation is loaded below\n w.Upscope = i;\n const s = document.createElement(\"script\");\n s.type = \"text/javascript\";\n s.async = true;\n s.src =\n {\n development: `http://code.upscope.local/${apiKey}.js`,\n production: `https://code.upscope.io/${apiKey}.js`,\n staging: `https://code.upscope.xyz/${apiKey}.js`,\n }[environment ?? \"production\"] ?? `https://code.upscope.io/${apiKey}.js`;\n document.head.appendChild(s);\n loadedWindows.add(w);\n}\nconst ScopedUpscope = function (w, ...instruction) {\n if (!loadedWindows.has(w)) {\n if (instruction[0] === \"init\") {\n const config = instruction[1];\n if (!config?.apiKey)\n throw new Error(\"API key not specified\");\n loadSDK(w, config.apiKey);\n }\n else {\n throw new Error(\"Upscope is not loaded\");\n }\n }\n w.Upscope(...instruction);\n};\nexport const upscopeFor = function (w) {\n return (...instruction) => {\n ScopedUpscope(w, ...instruction);\n };\n};\nconst _Upscope = upscopeFor(window);\nexport default _Upscope;\n"]}