@upscopeio/react 2025.9.2 → 2025.10.2
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 +3 -1
- package/index.js +144 -38
- package/index.js.map +1 -1
- package/package.json +4 -2
- package/sdk.d.ts +1 -0
package/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CobrowsingSdkConfiguration, Upscope } from "./sdk";
|
|
2
|
+
import { SDKEvents } from "./sdk-types";
|
|
2
3
|
|
|
3
4
|
type UpscopeProviderProps = {
|
|
5
|
+
test?: boolean;
|
|
4
6
|
enabled?: boolean;
|
|
5
7
|
children: React.ReactNode;
|
|
6
8
|
apiKey: string;
|
|
7
|
-
} & Partial<Omit<CobrowsingSdkConfiguration, "apiKey">>;
|
|
9
|
+
} & Partial<Omit<CobrowsingSdkConfiguration, "apiKey" | "regionWhitelist">>;
|
|
8
10
|
|
|
9
11
|
type UpscopeContext = {
|
|
10
12
|
Upscope: Upscope | undefined;
|
package/index.js
CHANGED
|
@@ -6,6 +6,9 @@ function _arrayLikeToArray(arr, len) {
|
|
|
6
6
|
function _arrayWithHoles(arr) {
|
|
7
7
|
if (Array.isArray(arr)) return arr;
|
|
8
8
|
}
|
|
9
|
+
function _arrayWithoutHoles(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
11
|
+
}
|
|
9
12
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
13
|
try {
|
|
11
14
|
var info = gen[key](arg);
|
|
@@ -35,6 +38,22 @@ function _asyncToGenerator(fn) {
|
|
|
35
38
|
});
|
|
36
39
|
};
|
|
37
40
|
}
|
|
41
|
+
function _defineProperty(obj, key, value) {
|
|
42
|
+
if (key in obj) {
|
|
43
|
+
Object.defineProperty(obj, key, {
|
|
44
|
+
value: value,
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
obj[key] = value;
|
|
51
|
+
}
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
function _iterableToArray(iter) {
|
|
55
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
56
|
+
}
|
|
38
57
|
function _iterableToArrayLimit(arr, i) {
|
|
39
58
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
59
|
if (_i == null) return;
|
|
@@ -62,6 +81,24 @@ function _iterableToArrayLimit(arr, i) {
|
|
|
62
81
|
function _nonIterableRest() {
|
|
63
82
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
83
|
}
|
|
84
|
+
function _nonIterableSpread() {
|
|
85
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
86
|
+
}
|
|
87
|
+
function _objectSpread(target) {
|
|
88
|
+
for(var i = 1; i < arguments.length; i++){
|
|
89
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
90
|
+
var ownKeys = Object.keys(source);
|
|
91
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
92
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
93
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
ownKeys.forEach(function(key) {
|
|
97
|
+
_defineProperty(target, key, source[key]);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return target;
|
|
101
|
+
}
|
|
65
102
|
function _objectWithoutProperties(source, excluded) {
|
|
66
103
|
if (source == null) return {};
|
|
67
104
|
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
@@ -92,6 +129,9 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
92
129
|
function _slicedToArray(arr, i) {
|
|
93
130
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
94
131
|
}
|
|
132
|
+
function _toConsumableArray(arr) {
|
|
133
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
134
|
+
}
|
|
95
135
|
function _unsupportedIterableToArray(o, minLen) {
|
|
96
136
|
if (!o) return;
|
|
97
137
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -196,8 +236,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
196
236
|
}
|
|
197
237
|
};
|
|
198
238
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
199
|
-
import
|
|
200
|
-
import
|
|
239
|
+
import equal from "fast-deep-equal";
|
|
240
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
241
|
+
import _Upscope from "./sdk.js";
|
|
201
242
|
var UpscopeContext = createContext({
|
|
202
243
|
Upscope: undefined,
|
|
203
244
|
shortId: undefined,
|
|
@@ -219,67 +260,132 @@ export function useUpscope() {
|
|
|
219
260
|
return useContext(UpscopeContext);
|
|
220
261
|
}
|
|
221
262
|
export function UpscopeProvider(_param) {
|
|
222
|
-
var
|
|
223
|
-
return new Promise(function(resolve) {
|
|
224
|
-
if (!loaded || !enabled) return resolve(undefined);
|
|
225
|
-
Upscope("getLookupCode", function(lookupCode) {
|
|
226
|
-
resolve(lookupCode);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
var listen = function listen(event, callback) {
|
|
231
|
-
Upscope("on", event, callback);
|
|
232
|
-
};
|
|
233
|
-
var reset = function reset() {
|
|
234
|
-
Upscope("reset", true);
|
|
235
|
-
};
|
|
236
|
-
var children = _param.children, enabled = _param.enabled, config = _objectWithoutProperties(_param, [
|
|
263
|
+
var children = _param.children, enabled = _param.enabled, test = _param.test, configProps = _objectWithoutProperties(_param, [
|
|
237
264
|
"children",
|
|
238
|
-
"enabled"
|
|
265
|
+
"enabled",
|
|
266
|
+
"test"
|
|
267
|
+
]);
|
|
268
|
+
var Upscope = useMemo(function() {
|
|
269
|
+
return function() {
|
|
270
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
271
|
+
args[_key] = arguments[_key];
|
|
272
|
+
}
|
|
273
|
+
if (test) return; // Do not use Upscope SDK on test
|
|
274
|
+
return _Upscope.apply(void 0, _toConsumableArray(args));
|
|
275
|
+
};
|
|
276
|
+
}, [
|
|
277
|
+
test
|
|
239
278
|
]);
|
|
240
279
|
var _useState = _slicedToArray(useState(false), 2), loaded = _useState[0], setLoaded = _useState[1];
|
|
241
280
|
var _useState1 = _slicedToArray(useState(false), 2), sharing = _useState1[0], setSharing = _useState1[1];
|
|
242
281
|
var _useState2 = _slicedToArray(useState(undefined), 2), shortId = _useState2[0], setShortId = _useState2[1];
|
|
282
|
+
var _useState3 = _slicedToArray(useState(undefined), 2), currentConfiguration = _useState3[0], setCurrentConfiguration = _useState3[1];
|
|
283
|
+
var upscopeActive = enabled && loaded;
|
|
284
|
+
var _useState4 = _slicedToArray(useState(null), 2), pendingConfigurationUpdate = _useState4[0], setPendingConfigurationUpdate = _useState4[1];
|
|
243
285
|
enabled !== null && enabled !== void 0 ? enabled : enabled = true;
|
|
244
286
|
useEffect(function() {
|
|
245
|
-
if (
|
|
287
|
+
if (currentConfiguration === undefined || !upscopeActive) {
|
|
288
|
+
setPendingConfigurationUpdate(null);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
var config = Object.entries(configProps).filter(function(param) {
|
|
292
|
+
var _$_param = _slicedToArray(param, 2), configName = _$_param[0], configValue = _$_param[1];
|
|
293
|
+
return configName !== "regionWhitelist" && !equal(configValue, currentConfiguration[configName]);
|
|
294
|
+
}).reduce(function(config, param) {
|
|
295
|
+
var _$_param = _slicedToArray(param, 2), configName = _$_param[0], configValue = _$_param[1];
|
|
296
|
+
config[configName] = configValue;
|
|
297
|
+
return config;
|
|
298
|
+
}, {});
|
|
299
|
+
setPendingConfigurationUpdate(Object.keys(config).length === 0 ? null : config);
|
|
300
|
+
}, [
|
|
301
|
+
currentConfiguration,
|
|
302
|
+
configProps,
|
|
303
|
+
upscopeActive
|
|
304
|
+
]);
|
|
305
|
+
useEffect(function() {
|
|
306
|
+
if (!currentConfiguration) return;
|
|
307
|
+
var isEnabledFirstTime = enabled && !loaded;
|
|
308
|
+
var isDisabledAfterInit = !enabled && loaded;
|
|
309
|
+
if (isEnabledFirstTime) {
|
|
310
|
+
Upscope("init", currentConfiguration);
|
|
246
311
|
setLoaded(true);
|
|
247
|
-
|
|
248
|
-
} else if (!enabled && loaded) {
|
|
312
|
+
} else if (isDisabledAfterInit) {
|
|
249
313
|
Upscope("reset", false);
|
|
250
|
-
setShortId(undefined);
|
|
251
314
|
}
|
|
252
315
|
}, [
|
|
253
316
|
enabled,
|
|
254
317
|
loaded,
|
|
255
|
-
|
|
318
|
+
currentConfiguration,
|
|
319
|
+
Upscope
|
|
256
320
|
]);
|
|
257
321
|
useEffect(function() {
|
|
258
|
-
if (
|
|
259
|
-
Upscope("updateConnection", config);
|
|
322
|
+
if (upscopeActive) {
|
|
260
323
|
Upscope("getShortId", function(shortId) {
|
|
261
324
|
setShortId(shortId);
|
|
262
325
|
});
|
|
326
|
+
} else {
|
|
327
|
+
setShortId(undefined);
|
|
263
328
|
}
|
|
329
|
+
}, [
|
|
330
|
+
upscopeActive,
|
|
331
|
+
Upscope
|
|
332
|
+
]);
|
|
333
|
+
useEffect(function() {
|
|
334
|
+
if (!upscopeActive || !pendingConfigurationUpdate || !currentConfiguration) return;
|
|
335
|
+
Upscope("updateConnection", pendingConfigurationUpdate);
|
|
336
|
+
setPendingConfigurationUpdate(null);
|
|
337
|
+
var newCurrentConfiguration = _objectSpread({}, currentConfiguration, pendingConfigurationUpdate);
|
|
338
|
+
setCurrentConfiguration(newCurrentConfiguration);
|
|
339
|
+
}, [
|
|
340
|
+
upscopeActive,
|
|
341
|
+
pendingConfigurationUpdate,
|
|
342
|
+
currentConfiguration,
|
|
343
|
+
Upscope
|
|
344
|
+
]);
|
|
345
|
+
useEffect(function() {
|
|
346
|
+
if (currentConfiguration || !enabled) return;
|
|
347
|
+
// Initialize configurations
|
|
348
|
+
setCurrentConfiguration(configProps);
|
|
264
349
|
}, [
|
|
265
350
|
enabled,
|
|
266
|
-
|
|
267
|
-
|
|
351
|
+
currentConfiguration,
|
|
352
|
+
configProps
|
|
268
353
|
]);
|
|
269
354
|
useEffect(function() {
|
|
270
|
-
if (loaded)
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
355
|
+
if (!loaded) return;
|
|
356
|
+
Upscope("on", "sessionStart", function() {
|
|
357
|
+
setSharing(true);
|
|
358
|
+
});
|
|
359
|
+
Upscope("on", "sessionContinue", function() {
|
|
360
|
+
setSharing(true);
|
|
361
|
+
});
|
|
362
|
+
Upscope("on", "sessionEnd", function() {
|
|
363
|
+
setSharing(false);
|
|
364
|
+
});
|
|
365
|
+
}, [
|
|
366
|
+
loaded,
|
|
367
|
+
Upscope
|
|
368
|
+
]);
|
|
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);
|
|
279
374
|
});
|
|
280
|
-
}
|
|
375
|
+
});
|
|
376
|
+
}, [
|
|
377
|
+
upscopeActive,
|
|
378
|
+
Upscope
|
|
379
|
+
]);
|
|
380
|
+
var listen = useCallback(function(event, callback) {
|
|
381
|
+
Upscope("on", event, callback);
|
|
382
|
+
}, [
|
|
383
|
+
Upscope
|
|
384
|
+
]);
|
|
385
|
+
var reset = useCallback(function() {
|
|
386
|
+
Upscope("reset", true);
|
|
281
387
|
}, [
|
|
282
|
-
|
|
388
|
+
Upscope
|
|
283
389
|
]);
|
|
284
390
|
return _jsx(UpscopeContext.Provider, {
|
|
285
391
|
value: {
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"sources":["index.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAO,IAAI,EAAE,YAAY,SAAS,EAAE,QAAQ,KAAK,QAAQ,oBAAoB;AACtF,OAAO,WAAW,kBAAkB;AACpC,SAAS,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,QAAQ,QAAQ;AACrG,OAAO,cAAc,WAAW;AAChC,IAAM,iBAAiB,cAAc;IACjC,SAAS;IACT,SAAS;IACH,eAAN,SAAM;eAAgB,kBAAA,WAAA;;gBAClB;;oBAAO;;;QACX;;IACA,QAAQ,SAAC,OAAO,UAAa,CAAE;IAC/B,OAAO,WAAM,CAAE;IACf,WAAW,KAAK;AACpB;AACA,OAAO,SAAS,aAAa;IACzB,OAAO,WAAW;AACtB,CAAC;AACD,OAAO,SAAS,gBAAgB,QAA6C;QAA3C,WAAF,OAAE,UAAU,UAAZ,OAAY,SAAS,OAArB,OAAqB,MAAS,uCAA9B;QAAE;QAAU;QAAS;;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G,UAAU;IAAS;AAC9B,CAAC;AACD,OAAO,SAAS,OAAO,KAAY,EAAE;QAAd,AAAE,WAAF,MAAE;IACrB,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,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"]}
|
package/package.json
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
"name": "@upscopeio/react",
|
|
3
3
|
"main": "index.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"dependencies": {
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"fast-deep-equal": "^3.1.3"
|
|
7
|
+
},
|
|
6
8
|
"peerDependencies": {
|
|
7
9
|
"react": ">=16.2.0",
|
|
8
10
|
"react-dom": ">=16.2.0"
|
|
9
11
|
},
|
|
10
|
-
"version": "2025.
|
|
12
|
+
"version": "2025.10.2"
|
|
11
13
|
}
|
package/sdk.d.ts
CHANGED
|
@@ -192,6 +192,7 @@ type Instruction =
|
|
|
192
192
|
userAgentFeedback?: string;
|
|
193
193
|
},
|
|
194
194
|
]
|
|
195
|
+
| ["expectDisconnect", Partial<SessionClientMessage["expectDisconnect"]>]
|
|
195
196
|
| ["getPublicLink", { agentId: string; agentName: string }, (publicLink: string) => void]
|
|
196
197
|
| ["updateConnection", Partial<CobrowsingSdkConfiguration>];
|
|
197
198
|
|