@upscopeio/react 1.0.5 → 2.2.138

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/README.md ADDED
@@ -0,0 +1 @@
1
+ # Upscope for React
package/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { CobrowsingSdkConfiguration, Upscope } from "./sdk";
2
+
3
+ type UpscopeProviderProps = {
4
+ enabled?: boolean;
5
+ children: React.ReactNode;
6
+ } & CobrowsingSdkConfiguration;
7
+
8
+ type UpscopeContext = {
9
+ Upscope: Upscope | undefined;
10
+ shortId: string | undefined;
11
+ getLookupCode: () => Promise<string | undefined>;
12
+ listen: (event: keyof SDKEvents, callback: (data: any) => void) => void;
13
+ reset: () => void;
14
+ isSharing: boolean;
15
+ };
16
+
17
+ export function useUpscope(): UpscopeContext;
18
+
19
+ export const UpscopeProvider: React.FC<UpscopeProviderProps>;
20
+ export const Masked: React.FC<{ children: React.ReactNode }>;
21
+ export const NoRemoteControl: React.FC<{ children: React.ReactNode }>;
package/index.js CHANGED
@@ -1,43 +1,359 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import UpscopeSDK from "@upscopeio/sdk";
3
- import { useEffect } from "react";
4
- const Upscope = function ({ children, ...props }) {
5
- const keys = Object.keys(props).sort((a, b) => a.localeCompare(b));
6
- const values = keys.map((key) => props[key]);
7
- useEffect(() => {
8
- const initiated = sessionStorage.getItem("upscope__initiated") === "true";
9
- if (initiated) {
10
- UpscopeSDK("updateConnection", props);
11
- }
12
- else {
13
- UpscopeSDK("init", props);
14
- sessionStorage.setItem("upscope__initiated", "true");
15
- }
16
- }, values);
17
- return children;
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _asyncToGenerator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _iterableToArrayLimit(arr, i) {
39
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
+ if (_i == null) return;
41
+ var _arr = [];
42
+ var _n = true;
43
+ var _d = false;
44
+ var _s, _e;
45
+ try {
46
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
47
+ _arr.push(_s.value);
48
+ if (i && _arr.length === i) break;
49
+ }
50
+ } catch (err) {
51
+ _d = true;
52
+ _e = err;
53
+ } finally{
54
+ try {
55
+ if (!_n && _i["return"] != null) _i["return"]();
56
+ } finally{
57
+ if (_d) throw _e;
58
+ }
59
+ }
60
+ return _arr;
61
+ }
62
+ function _nonIterableRest() {
63
+ 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
+ }
65
+ function _objectWithoutProperties(source, excluded) {
66
+ if (source == null) return {};
67
+ var target = _objectWithoutPropertiesLoose(source, excluded);
68
+ var key, i;
69
+ if (Object.getOwnPropertySymbols) {
70
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
71
+ for(i = 0; i < sourceSymbolKeys.length; i++){
72
+ key = sourceSymbolKeys[i];
73
+ if (excluded.indexOf(key) >= 0) continue;
74
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
75
+ target[key] = source[key];
76
+ }
77
+ }
78
+ return target;
79
+ }
80
+ function _objectWithoutPropertiesLoose(source, excluded) {
81
+ if (source == null) return {};
82
+ var target = {};
83
+ var sourceKeys = Object.keys(source);
84
+ var key, i;
85
+ for(i = 0; i < sourceKeys.length; i++){
86
+ key = sourceKeys[i];
87
+ if (excluded.indexOf(key) >= 0) continue;
88
+ target[key] = source[key];
89
+ }
90
+ return target;
91
+ }
92
+ function _slicedToArray(arr, i) {
93
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
94
+ }
95
+ function _unsupportedIterableToArray(o, minLen) {
96
+ if (!o) return;
97
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
98
+ var n = Object.prototype.toString.call(o).slice(8, -1);
99
+ if (n === "Object" && o.constructor) n = o.constructor.name;
100
+ if (n === "Map" || n === "Set") return Array.from(n);
101
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
102
+ }
103
+ var __generator = this && this.__generator || function(thisArg, body) {
104
+ var f, y, t, g, _ = {
105
+ label: 0,
106
+ sent: function() {
107
+ if (t[0] & 1) throw t[1];
108
+ return t[1];
109
+ },
110
+ trys: [],
111
+ ops: []
112
+ };
113
+ return g = {
114
+ next: verb(0),
115
+ "throw": verb(1),
116
+ "return": verb(2)
117
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
118
+ return this;
119
+ }), g;
120
+ function verb(n) {
121
+ return function(v) {
122
+ return step([
123
+ n,
124
+ v
125
+ ]);
126
+ };
127
+ }
128
+ function step(op) {
129
+ if (f) throw new TypeError("Generator is already executing.");
130
+ while(_)try {
131
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
132
+ if (y = 0, t) op = [
133
+ op[0] & 2,
134
+ t.value
135
+ ];
136
+ switch(op[0]){
137
+ case 0:
138
+ case 1:
139
+ t = op;
140
+ break;
141
+ case 4:
142
+ _.label++;
143
+ return {
144
+ value: op[1],
145
+ done: false
146
+ };
147
+ case 5:
148
+ _.label++;
149
+ y = op[1];
150
+ op = [
151
+ 0
152
+ ];
153
+ continue;
154
+ case 7:
155
+ op = _.ops.pop();
156
+ _.trys.pop();
157
+ continue;
158
+ default:
159
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
160
+ _ = 0;
161
+ continue;
162
+ }
163
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
164
+ _.label = op[1];
165
+ break;
166
+ }
167
+ if (op[0] === 6 && _.label < t[1]) {
168
+ _.label = t[1];
169
+ t = op;
170
+ break;
171
+ }
172
+ if (t && _.label < t[2]) {
173
+ _.label = t[2];
174
+ _.ops.push(op);
175
+ break;
176
+ }
177
+ if (t[2]) _.ops.pop();
178
+ _.trys.pop();
179
+ continue;
180
+ }
181
+ op = body.call(thisArg, _);
182
+ } catch (e) {
183
+ op = [
184
+ 6,
185
+ e
186
+ ];
187
+ y = 0;
188
+ } finally{
189
+ f = t = 0;
190
+ }
191
+ if (op[0] & 5) throw op[1];
192
+ return {
193
+ value: op[0] ? op[1] : void 0,
194
+ done: true
195
+ };
196
+ }
18
197
  };
19
- export default Upscope;
20
- export function Masked({ children }) {
21
- useEffect(() => {
22
- if (children) {
23
- children.__upscopeMasked = true;
24
- // @ts-ignore
25
- for (const child of children) {
26
- child.__upscopeMasked = true;
198
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
199
+ import { useEffect, useState, createContext, useContext, useRef } from "react";
200
+ import Upscope from "./sdk";
201
+ var UpscopeContext = createContext({
202
+ Upscope: undefined,
203
+ shortId: undefined,
204
+ getLookupCode: function getLookupCode() {
205
+ return _asyncToGenerator(function() {
206
+ return __generator(this, function(_state) {
207
+ return [
208
+ 2,
209
+ ""
210
+ ];
211
+ });
212
+ })();
213
+ },
214
+ listen: function(event, callback) {},
215
+ reset: function() {},
216
+ isSharing: false
217
+ });
218
+ export function useUpscope() {
219
+ return useContext(UpscopeContext);
220
+ }
221
+ export function UpscopeProvider(_param) {
222
+ var getLookupCode = function getLookupCode() {
223
+ return new Promise(function(resolve) {
224
+ if (!loaded || !enabled) {
225
+ return resolve(undefined);
226
+ }
227
+ Upscope("getLookupCode", function(lookupCode) {
228
+ resolve(lookupCode);
229
+ });
230
+ });
231
+ };
232
+ var listen = function listen(event, callback) {
233
+ Upscope("on", event, callback);
234
+ };
235
+ var reset = function reset() {
236
+ Upscope("reset", true);
237
+ };
238
+ var children = _param.children, enabled = _param.enabled, config = _objectWithoutProperties(_param, [
239
+ "children",
240
+ "enabled"
241
+ ]);
242
+ var _useState = _slicedToArray(useState(false), 2), loaded = _useState[0], setLoaded = _useState[1];
243
+ var _useState1 = _slicedToArray(useState(false), 2), sharing = _useState1[0], setSharing = _useState1[1];
244
+ var _useState2 = _slicedToArray(useState(undefined), 2), shortId = _useState2[0], setShortId = _useState2[1];
245
+ useEffect(function() {
246
+ if (enabled && !loaded) {
247
+ setLoaded(true);
248
+ Upscope("init", config);
249
+ Upscope("getShortId", function(shortId) {
250
+ setShortId(shortId);
251
+ });
252
+ } else if (!enabled && loaded) {
253
+ Upscope("reset", false);
254
+ setShortId(undefined);
255
+ } else if (enabled && loaded) {
256
+ Upscope("getShortId", function(shortId) {
257
+ setShortId(shortId);
258
+ });
259
+ }
260
+ }, [
261
+ enabled
262
+ ]);
263
+ useEffect(function() {
264
+ if (enabled && loaded) {
265
+ Upscope("updateConnection", config);
266
+ }
267
+ }, [
268
+ enabled,
269
+ loaded,
270
+ config
271
+ ]);
272
+ useEffect(function() {
273
+ if (loaded) {
274
+ Upscope("on", "sessionStart", function() {
275
+ setSharing(true);
276
+ });
277
+ Upscope("on", "sessionContinue", function() {
278
+ setSharing(true);
279
+ });
280
+ Upscope("on", "sessionEnd", function() {
281
+ setSharing(false);
282
+ });
283
+ }
284
+ }, [
285
+ loaded
286
+ ]);
287
+ return _jsx(UpscopeContext.Provider, {
288
+ value: {
289
+ Upscope: Upscope,
290
+ shortId: shortId,
291
+ getLookupCode: getLookupCode,
292
+ listen: listen,
293
+ reset: reset,
294
+ isSharing: sharing
295
+ },
296
+ children: children
297
+ });
298
+ }
299
+ export function Masked(param) {
300
+ var children = param.children;
301
+ var beforeRef = useRef(null);
302
+ var afterRef = useRef(null);
303
+ useEffect(function() {
304
+ if (beforeRef.current && afterRef.current) {
305
+ var nextSibling = beforeRef.current.nextSibling;
306
+ while(nextSibling && nextSibling !== afterRef.current){
307
+ nextSibling.dataset.upscopeMasked = true;
308
+ nextSibling = nextSibling.nextSibling;
27
309
  }
28
310
  }
29
- }, [children]);
30
- return _jsx(_Fragment, { children: children });
311
+ }, [
312
+ beforeRef,
313
+ afterRef,
314
+ children
315
+ ]);
316
+ return _jsxs(_Fragment, {
317
+ children: [
318
+ _jsx("script", {
319
+ ref: beforeRef
320
+ }),
321
+ children,
322
+ _jsx("script", {
323
+ ref: afterRef
324
+ })
325
+ ]
326
+ });
31
327
  }
32
- export function NoRemoteControl({ children }) {
33
- useEffect(() => {
34
- if (children) {
35
- children.__upscopeNoRemoteControl = true;
36
- // @ts-ignore
37
- for (const child of children) {
38
- child.__upscopeNoRemoteControl = true;
328
+ export function NoRemoteControl(param) {
329
+ var children = param.children;
330
+ var beforeRef = useRef(null);
331
+ var afterRef = useRef(null);
332
+ useEffect(function() {
333
+ if (beforeRef.current && afterRef.current) {
334
+ var nextSibling = beforeRef.current.nextSibling;
335
+ while(nextSibling && nextSibling !== afterRef.current){
336
+ nextSibling.dataset.upscopeNoRemoteControl = true;
337
+ nextSibling = nextSibling.nextSibling;
39
338
  }
40
339
  }
41
- }, [children]);
42
- return _jsx(_Fragment, { children: children });
340
+ }, [
341
+ beforeRef,
342
+ afterRef,
343
+ children
344
+ ]);
345
+ return _jsxs(_Fragment, {
346
+ children: [
347
+ _jsx("script", {
348
+ ref: beforeRef
349
+ }),
350
+ children,
351
+ _jsx("script", {
352
+ ref: afterRef
353
+ })
354
+ ]
355
+ });
43
356
  }
357
+
358
+
359
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.js"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nimport { useEffect, useState, createContext, useContext, useRef } from \"react\";\nimport Upscope from \"./sdk\";\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, ...config }) {\n const [loaded, setLoaded] = useState(false);\n const [sharing, setSharing] = useState(false);\n const [shortId, setShortId] = useState(undefined);\n useEffect(() => {\n if (enabled && !loaded) {\n setLoaded(true);\n Upscope(\"init\", config);\n Upscope(\"getShortId\", (shortId) => {\n setShortId(shortId);\n });\n }\n else if (!enabled && loaded) {\n Upscope(\"reset\", false);\n setShortId(undefined);\n }\n else if (enabled && loaded) {\n Upscope(\"getShortId\", (shortId) => {\n setShortId(shortId);\n });\n }\n }, [enabled]);\n useEffect(() => {\n if (enabled && loaded) {\n Upscope(\"updateConnection\", config);\n }\n }, [enabled, loaded, config]);\n useEffect(() => {\n if (loaded) {\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 }\n }, [loaded]);\n function getLookupCode() {\n return new Promise((resolve) => {\n if (!loaded || !enabled) {\n return resolve(undefined);\n }\n Upscope(\"getLookupCode\", (lookupCode) => {\n resolve(lookupCode);\n });\n });\n }\n function listen(event, callback) {\n Upscope(\"on\", event, callback);\n }\n function reset() {\n Upscope(\"reset\", true);\n }\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
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "@upscopeio/react",
3
3
  "main": "index.js",
4
- "dependencies": {
5
- "@upscopeio/sdk": "1.0.5",
6
- "react": "^18.2.0"
4
+ "type": "module",
5
+ "dependencies": {},
6
+ "peerDependencies": {
7
+ "react": "^16.2.0",
8
+ "react-dom": "^16.2.0"
7
9
  },
8
- "devDependencies": {
9
- "@types/react": "^18.2.14",
10
- "typescript": "^5.1.6"
11
- },
12
- "version": "1.0.5"
10
+ "version": "2.2.138"
13
11
  }
package/sdk.d.ts ADDED
@@ -0,0 +1,159 @@
1
+ type SubmitRating = {
2
+ userSessionRating?: number;
3
+ userAgentRating?: number;
4
+ userAgentFeedback?: string;
5
+ };
6
+
7
+ type CobrowsingSdkConfiguration = {
8
+ jsConfiguration?: boolean;
9
+ uniqueId?: null | string;
10
+ identities?: null | string | string[];
11
+ tags?: null | string | string[];
12
+ integrationIds?: null | string | string[];
13
+ agentPrompt?: string;
14
+ callName?: string;
15
+
16
+ // Automatic
17
+ version: string;
18
+ apiKey: string;
19
+ beta: boolean;
20
+ region: string | null;
21
+ readonly regionWhitelist: string[] | null;
22
+ dataEndpoint: string;
23
+ pageviewsEndpoint: string;
24
+ phoneEndpoint: string;
25
+ javascriptEndpoint: string;
26
+ storageImplementation: null | Storage;
27
+ proxyRedirectEndpoint: string;
28
+ requireAuthorizationForSession: boolean;
29
+ integrateWithLivechat: boolean;
30
+ liveChatRewrite: boolean;
31
+ grabIdentityFromLivechat: boolean;
32
+ showUpscopeLink: boolean;
33
+ cursorColor: string;
34
+ enlargeCursor: boolean;
35
+ showTerminateButton: boolean;
36
+ screenWakeLock: boolean;
37
+ useFingerprinting: boolean;
38
+ autoconnect: boolean;
39
+ trackConsole: boolean;
40
+ allowRemoteConsole: boolean;
41
+ allowRemoteClick: boolean;
42
+ allowRemoteScroll: boolean;
43
+ allowRemoteType: boolean;
44
+ allowAgentRedirect: boolean;
45
+ rewriteExternalLinks: boolean;
46
+ collectHistory: boolean;
47
+ consoleAllowed: boolean;
48
+ drawingsTtlMs: number;
49
+ enableLookupCodeOnKey: boolean;
50
+ lookupCodeKey: number;
51
+ lookupCodeKeyRepetitions: number;
52
+ lookupCodeKeyTitle: string;
53
+ lookupCodeKeyMessage: string;
54
+ lookupCodeElement: null | HTMLElement | string;
55
+ injectLookupCodeButton: boolean;
56
+ lookupCodeButtonPages: string[];
57
+ lookupCodeButtonStyle: string;
58
+ disconnectAfterSeconds: number;
59
+ proxyAssets: string[];
60
+ maskedElements: string[];
61
+ domChangesDelay: number;
62
+ ignoreBrowserSupport: boolean;
63
+ enableCanvases: boolean;
64
+ customCallController: null | ((callback: (accepted: boolean) => void) => void);
65
+ callPromptText: string;
66
+ callRingtone: string;
67
+ authorizationPromptTitle: string;
68
+ authorizationPromptMessage: string;
69
+ endOfScreenshareMessage: null | string;
70
+ callWaitMessage: string;
71
+ translationsYes: string;
72
+ translationsNo: string;
73
+ translationsOk: string;
74
+ translationsStopSession: string;
75
+ agentRequestButtonStyle: string;
76
+ agentRequestButtonTitle: string;
77
+ agentRequestButtonSubtitle: string;
78
+ agentRequestButtonRequestingTitle: string;
79
+ agentRequestButtonRequestingSubtitle: string;
80
+ agentRequestResultTitle: string;
81
+ agentRequestNotAvailableText: string;
82
+ agentRequestAcceptedText: string;
83
+ showAgentRequestButton: "always" | "when_available" | "never"; // One of: always / when_available / never
84
+ agentRequestButtonPages: string[];
85
+ callPopupFailedTitle: string;
86
+ callPopupFailedMessage: string;
87
+ callPopupNoInputTitle: string;
88
+ callPopupNoInputMessage: string;
89
+ callPopupNoOutputTitle: string;
90
+ callPopupNoOutputMessage: string;
91
+ callAudioAuthorizationFailedTitle: string;
92
+ callAudioAuthorizationFailedMessage: string;
93
+ unavailableAgentRequestRedirectImmediately: boolean;
94
+ unavailableAgentRequestRedirectTo: null | string;
95
+ fromProxy: boolean;
96
+ sfdcFieldLabel: string;
97
+ sfdcFieldId: string;
98
+ baseProxyUrl: string;
99
+ proxyDomain: string;
100
+ needsProxy: (url: string) => boolean;
101
+ onSessionRequest: (cb: (accepted: boolean) => void, requestingAgent: string | null) => void;
102
+ onSessionStart: () => void;
103
+ onSessionEnd: () => void;
104
+ onWaitingForCall: () => void;
105
+ onSessionContinue: () => void;
106
+ onConnection: null | (() => void);
107
+ maskElementMiddleware: (element: HTMLElement) => boolean;
108
+ noRemoteElements: string[];
109
+ allowRemoteMiddleware: (element: HTMLElement) => boolean;
110
+ styleSheetContentFromRules: (stylesheet: HTMLLinkElement | HTMLStyleElement) => boolean;
111
+ };
112
+
113
+ type SDKEvents = {
114
+ connection: undefined;
115
+ waitingForCall: undefined;
116
+ sessionStart: undefined;
117
+ callStart: undefined;
118
+ callAccepted: undefined;
119
+ agentRequestUpdate: ["pending" | "unavailable" | "canceled" | "accepted"];
120
+ newObserver: [string];
121
+ observerGone: [string];
122
+ agentsAvailable: undefined;
123
+ sessionContinue: undefined;
124
+ sessionEnd: undefined;
125
+ callEnd: undefined;
126
+ connectionReset: undefined;
127
+ sessionRequest: undefined;
128
+ };
129
+
130
+ type Instruction =
131
+ | ["init", Partial<CobrowsingSdkConfiguration>]
132
+ | ["reset"]
133
+ | ["connect"]
134
+ | ["cancelRequestAgent"]
135
+ | ["getShortId", (shortId: string) => void]
136
+ | ["getUserId", (shortId: string) => void] // Legacy version of getShortId
137
+ | ["getLookupCode", (code: string) => void]
138
+ | ["getWatchLink", (link: string) => void]
139
+ | ["logEvent", "success" | "error" | "info" | "warn" | "contact", string]
140
+ | ["newPageview"]
141
+ | ["on", ...(keyof SDKEvents)[], (event: any) => void]
142
+ | ["requestAgent"]
143
+ | ["reset", boolean]
144
+ | ["redirect", string]
145
+ | ["saveHistory"]
146
+ | ["stopSession"]
147
+ | [
148
+ "submitRating",
149
+ {
150
+ userSessionRating?: number;
151
+ userAgentRating?: number;
152
+ userAgentFeedback?: string;
153
+ },
154
+ ]
155
+ | ["updateConnection", Partial<CobrowsingSdkConfiguration>];
156
+
157
+ type Upscope = (...instruction: Instruction) => void;
158
+
159
+ export default function Upscope(...instruction: Instruction): void;
package/sdk.js ADDED
@@ -0,0 +1,71 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function _iterableToArray(iter) {
10
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
11
+ }
12
+ function _nonIterableSpread() {
13
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
14
+ }
15
+ function _toConsumableArray(arr) {
16
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
17
+ }
18
+ function _unsupportedIterableToArray(o, minLen) {
19
+ if (!o) return;
20
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
21
+ var n = Object.prototype.toString.call(o).slice(8, -1);
22
+ if (n === "Object" && o.constructor) n = o.constructor.name;
23
+ if (n === "Map" || n === "Set") return Array.from(n);
24
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
25
+ }
26
+ var loaded = false;
27
+ function loadSDK(apiKey) {
28
+ var _x_parentNode;
29
+ if (typeof window.Upscope !== "undefined") {
30
+ loaded = true;
31
+ return;
32
+ }
33
+ var i = function i1() {
34
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
35
+ args[_key] = arguments[_key];
36
+ }
37
+ i.q.push(args);
38
+ };
39
+ i.q = [];
40
+ // The real Upscope implementation is loaded below
41
+ window.Upscope = i;
42
+ var s = document.createElement("script");
43
+ s.type = "text/javascript";
44
+ s.async = true;
45
+ s.src = "https://code.upscope.io/".concat(apiKey, ".js");
46
+ var x = document.getElementsByTagName("script")[0];
47
+ (_x_parentNode = x.parentNode) === null || _x_parentNode === void 0 ? void 0 : _x_parentNode.insertBefore(s, x);
48
+ loaded = true;
49
+ }
50
+ var _Upscope = function _Upscope() {
51
+ for(var _len = arguments.length, instruction = new Array(_len), _key = 0; _key < _len; _key++){
52
+ instruction[_key] = arguments[_key];
53
+ }
54
+ var _window;
55
+ if (!loaded) {
56
+ if (instruction[0] === "init") {
57
+ var config = instruction[1];
58
+ if (!(config === null || config === void 0 ? void 0 : config.apiKey)) {
59
+ throw new Error("API key not specified");
60
+ }
61
+ loadSDK(config.apiKey);
62
+ } else {
63
+ throw new Error("Upscope is not loaded");
64
+ }
65
+ }
66
+ return (_window = window).Upscope.apply(_window, _toConsumableArray(instruction));
67
+ };
68
+ export default _Upscope;
69
+
70
+
71
+ //# sourceMappingURL=sdk.js.map
package/sdk.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["sdk.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,SAAS,KAAK;AAClB,SAAS,QAAQ,MAAM,EAAE;QAgBrB;IAfA,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,IAAM,IAAI,SAAS,oBAAoB,CAAC,SAAS,CAAC,EAAE;IACpD,CAAA,gBAAA,EAAE,UAAU,cAAZ,2BAAA,KAAA,IAAA,cAAc,aAAa,GAAG;IAC9B,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;QAa7B;IAZP,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,GAAE;gBACjB,MAAM,IAAI,MAAM,yBAAyB;YAC7C,CAAC;YACD,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 const x = document.getElementsByTagName(\"script\")[0];\n x.parentNode?.insertBefore(s, x);\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 }\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"]}
package/index.tsx DELETED
@@ -1,58 +0,0 @@
1
- import type { CobrowsingSdkConfiguration, Upscope } from "@upscopeio/sdk";
2
- import type { ReactNode } from "react";
3
- import UpscopeSDK from "@upscopeio/sdk";
4
- import React, { useEffect } from "react";
5
-
6
- type Child = ReactNode & {
7
- __upscopeMasked?: boolean;
8
- __upscopeNoRemoteControl?: boolean;
9
- };
10
-
11
- type Children = { children: Child };
12
-
13
- type Props = Children & Partial<CobrowsingSdkConfiguration>;
14
-
15
- const Upscope: React.FC<Props> = function ({ children, ...props }: Props) {
16
- const keys = Object.keys(props).sort((a, b) => a.localeCompare(b)) as (keyof CobrowsingSdkConfiguration)[];
17
- const values: unknown[] = keys.map((key: keyof CobrowsingSdkConfiguration) => props[key] as unknown);
18
-
19
- useEffect(() => {
20
- const initiated = sessionStorage.getItem("upscope__initiated") === "true";
21
-
22
- if (initiated) {
23
- (UpscopeSDK as Upscope)("updateConnection", props);
24
- } else {
25
- (UpscopeSDK as Upscope)("init", props);
26
- sessionStorage.setItem("upscope__initiated", "true");
27
- }
28
- }, values);
29
-
30
- return children;
31
- };
32
- export default Upscope;
33
-
34
- export function Masked({ children }: Children): ReactNode {
35
- useEffect(() => {
36
- if (children) {
37
- children.__upscopeMasked = true;
38
- // @ts-ignore
39
- for (const child of children) {
40
- (child as Child).__upscopeMasked = true;
41
- }
42
- }
43
- }, [children]);
44
- return <>{children}</>;
45
- }
46
-
47
- export function NoRemoteControl({ children }: Children): ReactNode {
48
- useEffect(() => {
49
- if (children) {
50
- children.__upscopeNoRemoteControl = true;
51
- // @ts-ignore
52
- for (const child of children) {
53
- (child as Child).__upscopeNoRemoteControl = true;
54
- }
55
- }
56
- }, [children]);
57
- return <>{children}</>;
58
- }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "jsx": "react-jsx",
5
- "module": "esnext",
6
- "esModuleInterop": true,
7
- "forceConsistentCasingInFileNames": true,
8
- "moduleResolution": "node",
9
- "strict": true,
10
- "skipLibCheck": true
11
- }
12
- }