@resenty/widget 0.0.0
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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/chunks/chat-CJ6R7eoG.js +592 -0
- package/dist/chunks/chat-CZS20945.js +54622 -0
- package/dist/chunks/core-Cpyk9a29.js +214 -0
- package/dist/chunks/index-Df7cNTmq.js +348 -0
- package/dist/chunks/query-common-D_G8O-M_.js +7754 -0
- package/dist/chunks/react-dom-B4CdVWWC.js +1176 -0
- package/dist/chunks/react-root-BBU2MuNT.js +5 -0
- package/dist/chunks/react-root-ChAKSfvh.js +18956 -0
- package/dist/chunks/rolldown-runtime-B_fQOXul.js +11 -0
- package/dist/chunks/schemas-B2StEWw-.js +4326 -0
- package/dist/chunks/ui-common-DfZ7eP4u.js +2372 -0
- package/dist/chunks/ui-f9sPMhJV.js +135 -0
- package/dist/chunks/vendor-CAJw9nfJ.js +68985 -0
- package/dist/resenty.js +676 -0
- package/dist/styles/resenty.css +2 -0
- package/package.json +94 -0
package/dist/resenty.js
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import { A as Subscribable, C as resolveStaleTime, E as skipToken, M as client, _ as matchMutation, a as Mutation, b as partialMatchKey, h as hashQueryKeyByOptions, i as string, j as Client, k as focusManager, l as onlineManager, m as hashKey, n as object, p as functionalUpdate, r as record, s as Query, u as notifyManager, v as matchQuery, y as noop } from "./chunks/schemas-B2StEWw-.js";
|
|
2
|
+
var DefaultMessages = Object.freeze({
|
|
3
|
+
MissingWidgetIdErrorMessage: "Missing widgetId. You can get your key at https://app.resenty.com/widget.",
|
|
4
|
+
NotInBrowserErrorMessage: "Widget can only be used in a browser for the time being."
|
|
5
|
+
}), ResentyError = class extends Error {
|
|
6
|
+
constructor(_) {
|
|
7
|
+
super(_), this.name = "ResentyError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function buildErrorThrower({ packageName: _ }) {
|
|
11
|
+
let K = _;
|
|
12
|
+
function q(_) {
|
|
13
|
+
return `${K}: ${_}`;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
setPackageName({ packageName: _ }) {
|
|
17
|
+
return typeof _ == "string" && (K = _), this;
|
|
18
|
+
},
|
|
19
|
+
throwMissingWidgetIdError() {
|
|
20
|
+
return this.throw(DefaultMessages.MissingWidgetIdErrorMessage);
|
|
21
|
+
},
|
|
22
|
+
throwNotInBrowserError() {
|
|
23
|
+
return this.throw(DefaultMessages.NotInBrowserErrorMessage);
|
|
24
|
+
},
|
|
25
|
+
throw(_) {
|
|
26
|
+
throw new ResentyError(q(_));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function mitt(_) {
|
|
31
|
+
return _ ||= /* @__PURE__ */ new Map(), {
|
|
32
|
+
all: _,
|
|
33
|
+
on(K, q) {
|
|
34
|
+
let J = _.get(K);
|
|
35
|
+
J ? J.push(q) : _.set(K, [q]);
|
|
36
|
+
},
|
|
37
|
+
off(K, q) {
|
|
38
|
+
let J = _.get(K);
|
|
39
|
+
J && (q ? J.splice(J.indexOf(q) >>> 0, 1) : _.set(K, []));
|
|
40
|
+
},
|
|
41
|
+
emit(K, q) {
|
|
42
|
+
let J = _.get(K);
|
|
43
|
+
J && J.slice().map((_) => {
|
|
44
|
+
_(q);
|
|
45
|
+
}), J = _.get("*"), J && J.slice().map((_) => {
|
|
46
|
+
_(K, q);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const createEventEmitter = () => mitt();
|
|
52
|
+
function isPrimitive(_) {
|
|
53
|
+
return _ == null || typeof _ != "object" && typeof _ != "function";
|
|
54
|
+
}
|
|
55
|
+
function isTypedArray(_) {
|
|
56
|
+
return ArrayBuffer.isView(_) && !(_ instanceof DataView);
|
|
57
|
+
}
|
|
58
|
+
function clone(_) {
|
|
59
|
+
if (isPrimitive(_)) return _;
|
|
60
|
+
if (Array.isArray(_) || isTypedArray(_) || _ instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && _ instanceof SharedArrayBuffer) return _.slice(0);
|
|
61
|
+
let K = Object.getPrototypeOf(_);
|
|
62
|
+
if (K == null) return Object.assign(Object.create(K), _);
|
|
63
|
+
let q = K.constructor;
|
|
64
|
+
if (_ instanceof Date || _ instanceof Map || _ instanceof Set) return new q(_);
|
|
65
|
+
if (_ instanceof RegExp) {
|
|
66
|
+
let K = new q(_);
|
|
67
|
+
return K.lastIndex = _.lastIndex, K;
|
|
68
|
+
}
|
|
69
|
+
if (_ instanceof DataView) return new q(_.buffer.slice(0));
|
|
70
|
+
if (_ instanceof Error) {
|
|
71
|
+
let K;
|
|
72
|
+
return K = _ instanceof AggregateError ? new q(_.errors, _.message, { cause: _.cause }) : new q(_.message, { cause: _.cause }), K.stack = _.stack, Object.assign(K, _), K;
|
|
73
|
+
}
|
|
74
|
+
if (typeof File < "u" && _ instanceof File) return new q([_], _.name, {
|
|
75
|
+
type: _.type,
|
|
76
|
+
lastModified: _.lastModified
|
|
77
|
+
});
|
|
78
|
+
if (typeof _ == "object") {
|
|
79
|
+
let q = Object.create(K);
|
|
80
|
+
return Object.assign(q, _);
|
|
81
|
+
}
|
|
82
|
+
return _;
|
|
83
|
+
}
|
|
84
|
+
function isPlainObject(_) {
|
|
85
|
+
if (!_ || typeof _ != "object") return !1;
|
|
86
|
+
let K = Object.getPrototypeOf(_);
|
|
87
|
+
return K === null || K === Object.prototype || Object.getPrototypeOf(K) === null ? Object.prototype.toString.call(_) === "[object Object]" : !1;
|
|
88
|
+
}
|
|
89
|
+
function isUnsafeProperty(_) {
|
|
90
|
+
return _ === "__proto__";
|
|
91
|
+
}
|
|
92
|
+
function merge(_, K) {
|
|
93
|
+
let q = Object.keys(K);
|
|
94
|
+
for (let J = 0; J < q.length; J++) {
|
|
95
|
+
let Y = q[J];
|
|
96
|
+
if (isUnsafeProperty(Y)) continue;
|
|
97
|
+
let X = K[Y], Z = _[Y];
|
|
98
|
+
isMergeableValue(X) && isMergeableValue(Z) ? _[Y] = merge(Z, X) : Array.isArray(X) ? _[Y] = merge([], X) : isPlainObject(X) ? _[Y] = merge({}, X) : (Z === void 0 || X !== void 0) && (_[Y] = X);
|
|
99
|
+
}
|
|
100
|
+
return _;
|
|
101
|
+
}
|
|
102
|
+
function isMergeableValue(_) {
|
|
103
|
+
return isPlainObject(_) || Array.isArray(_);
|
|
104
|
+
}
|
|
105
|
+
function mergeWith(_, K, q) {
|
|
106
|
+
let J = Object.keys(K);
|
|
107
|
+
for (let Y = 0; Y < J.length; Y++) {
|
|
108
|
+
let X = J[Y];
|
|
109
|
+
if (isUnsafeProperty(X)) continue;
|
|
110
|
+
let Z = K[X], Q = _[X], $ = q(Q, Z, X, _, K);
|
|
111
|
+
$ === void 0 ? Array.isArray(Z) ? Array.isArray(Q) ? _[X] = mergeWith(Q, Z, q) : _[X] = mergeWith([], Z, q) : isPlainObject(Z) ? isPlainObject(Q) ? _[X] = mergeWith(Q, Z, q) : _[X] = mergeWith({}, Z, q) : (Q === void 0 || Z !== void 0) && (_[X] = Z) : _[X] = $;
|
|
112
|
+
}
|
|
113
|
+
return _;
|
|
114
|
+
}
|
|
115
|
+
function toMerged(_, K) {
|
|
116
|
+
return mergeWith(clone(_), K, function _(K, q) {
|
|
117
|
+
if (Array.isArray(q)) return mergeWith(Array.isArray(K) ? clone(K) : [], q, _);
|
|
118
|
+
if (isPlainObject(q)) return isPlainObject(K) ? mergeWith(clone(K), q, _) : mergeWith({}, q, _);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
var DEFAULT_TRIGGER_VISIBILITY = !0;
|
|
122
|
+
const DEFAULT_PUBLIC_OPTIONS = {
|
|
123
|
+
baseUrl: "https://api.resenty.com/__internal",
|
|
124
|
+
showTrigger: DEFAULT_TRIGGER_VISIBILITY,
|
|
125
|
+
appearance: {
|
|
126
|
+
theme: "light",
|
|
127
|
+
chat: {}
|
|
128
|
+
}
|
|
129
|
+
}, resolveShowTrigger = (_) => _.appearance?.chat?.showTrigger ?? _.showTrigger ?? DEFAULT_TRIGGER_VISIBILITY, normalizeOptions = (_) => {
|
|
130
|
+
let K = resolveShowTrigger(_);
|
|
131
|
+
return {
|
|
132
|
+
appId: _.appId,
|
|
133
|
+
baseUrl: _.baseUrl ?? DEFAULT_PUBLIC_OPTIONS.baseUrl,
|
|
134
|
+
customer: _.customer,
|
|
135
|
+
userJwt: _.userJwt,
|
|
136
|
+
appearance: {
|
|
137
|
+
theme: _.appearance?.theme ?? "light",
|
|
138
|
+
chat: { showTrigger: K }
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
function isBrowser() {
|
|
143
|
+
return typeof window < "u";
|
|
144
|
+
}
|
|
145
|
+
new RegExp((/* @__PURE__ */ "bot.spider.crawl.APIs-Google.AdsBot.Googlebot.mediapartners.Google Favicon.FeedFetcher.Google-Read-Aloud.DuplexWeb-Google.googleweblight.bing.yandex.baidu.duckduck.yahoo.ecosia.ia_archiver.facebook.instagram.pinterest.reddit.slack.twitter.whatsapp.youtube.semrush".split(".")).join("|"), "i");
|
|
146
|
+
var DEFAULTS = {
|
|
147
|
+
baseMs: 500,
|
|
148
|
+
factor: 2,
|
|
149
|
+
shouldRetry: () => !0,
|
|
150
|
+
onRetry: () => {}
|
|
151
|
+
};
|
|
152
|
+
function sleep(_) {
|
|
153
|
+
return new Promise((K) => setTimeout(K, _));
|
|
154
|
+
}
|
|
155
|
+
async function withRetry(_, K) {
|
|
156
|
+
let q = {
|
|
157
|
+
...DEFAULTS,
|
|
158
|
+
...K
|
|
159
|
+
}, J;
|
|
160
|
+
for (let Y = 0; Y < q.attempts; Y++) try {
|
|
161
|
+
return await _(Y);
|
|
162
|
+
} catch (_) {
|
|
163
|
+
if (J = _, Y === q.attempts - 1 || !q.shouldRetry(_, Y)) throw _;
|
|
164
|
+
let X = K.computeDelay ? K.computeDelay(Y, q) : q.baseMs * q.factor ** Y;
|
|
165
|
+
q.onRetry(_, Y, X), await sleep(X);
|
|
166
|
+
}
|
|
167
|
+
throw J;
|
|
168
|
+
}
|
|
169
|
+
var MutationCache = class extends Subscribable {
|
|
170
|
+
constructor(_ = {}) {
|
|
171
|
+
super(), this.config = _, this.#e = /* @__PURE__ */ new Set(), this.#t = /* @__PURE__ */ new Map(), this.#n = 0;
|
|
172
|
+
}
|
|
173
|
+
#e;
|
|
174
|
+
#t;
|
|
175
|
+
#n;
|
|
176
|
+
build(_, K, q) {
|
|
177
|
+
let J = new Mutation({
|
|
178
|
+
client: _,
|
|
179
|
+
mutationCache: this,
|
|
180
|
+
mutationId: ++this.#n,
|
|
181
|
+
options: _.defaultMutationOptions(K),
|
|
182
|
+
state: q
|
|
183
|
+
});
|
|
184
|
+
return this.add(J), J;
|
|
185
|
+
}
|
|
186
|
+
add(_) {
|
|
187
|
+
this.#e.add(_);
|
|
188
|
+
let K = scopeFor(_);
|
|
189
|
+
if (typeof K == "string") {
|
|
190
|
+
let q = this.#t.get(K);
|
|
191
|
+
q ? q.push(_) : this.#t.set(K, [_]);
|
|
192
|
+
}
|
|
193
|
+
this.notify({
|
|
194
|
+
type: "added",
|
|
195
|
+
mutation: _
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
remove(_) {
|
|
199
|
+
if (this.#e.delete(_)) {
|
|
200
|
+
let K = scopeFor(_);
|
|
201
|
+
if (typeof K == "string") {
|
|
202
|
+
let q = this.#t.get(K);
|
|
203
|
+
if (q) if (q.length > 1) {
|
|
204
|
+
let K = q.indexOf(_);
|
|
205
|
+
K !== -1 && q.splice(K, 1);
|
|
206
|
+
} else q[0] === _ && this.#t.delete(K);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
this.notify({
|
|
210
|
+
type: "removed",
|
|
211
|
+
mutation: _
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
canRun(_) {
|
|
215
|
+
let K = scopeFor(_);
|
|
216
|
+
if (typeof K == "string") {
|
|
217
|
+
let q = this.#t.get(K)?.find((_) => _.state.status === "pending");
|
|
218
|
+
return !q || q === _;
|
|
219
|
+
} else return !0;
|
|
220
|
+
}
|
|
221
|
+
runNext(_) {
|
|
222
|
+
let K = scopeFor(_);
|
|
223
|
+
return typeof K == "string" ? (this.#t.get(K)?.find((K) => K !== _ && K.state.isPaused))?.continue() ?? Promise.resolve() : Promise.resolve();
|
|
224
|
+
}
|
|
225
|
+
clear() {
|
|
226
|
+
notifyManager.batch(() => {
|
|
227
|
+
this.#e.forEach((_) => {
|
|
228
|
+
this.notify({
|
|
229
|
+
type: "removed",
|
|
230
|
+
mutation: _
|
|
231
|
+
});
|
|
232
|
+
}), this.#e.clear(), this.#t.clear();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getAll() {
|
|
236
|
+
return Array.from(this.#e);
|
|
237
|
+
}
|
|
238
|
+
find(_) {
|
|
239
|
+
let K = {
|
|
240
|
+
exact: !0,
|
|
241
|
+
..._
|
|
242
|
+
};
|
|
243
|
+
return this.getAll().find((_) => matchMutation(K, _));
|
|
244
|
+
}
|
|
245
|
+
findAll(_ = {}) {
|
|
246
|
+
return this.getAll().filter((K) => matchMutation(_, K));
|
|
247
|
+
}
|
|
248
|
+
notify(_) {
|
|
249
|
+
notifyManager.batch(() => {
|
|
250
|
+
this.listeners.forEach((K) => {
|
|
251
|
+
K(_);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
resumePausedMutations() {
|
|
256
|
+
let _ = this.getAll().filter((_) => _.state.isPaused);
|
|
257
|
+
return notifyManager.batch(() => Promise.all(_.map((_) => _.continue().catch(noop))));
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
function scopeFor(_) {
|
|
261
|
+
return _.options.scope?.id;
|
|
262
|
+
}
|
|
263
|
+
var QueryCache = class extends Subscribable {
|
|
264
|
+
constructor(_ = {}) {
|
|
265
|
+
super(), this.config = _, this.#e = /* @__PURE__ */ new Map();
|
|
266
|
+
}
|
|
267
|
+
#e;
|
|
268
|
+
build(_, K, q) {
|
|
269
|
+
let J = K.queryKey, Y = K.queryHash ?? hashQueryKeyByOptions(J, K), X = this.get(Y);
|
|
270
|
+
return X || (X = new Query({
|
|
271
|
+
client: _,
|
|
272
|
+
queryKey: J,
|
|
273
|
+
queryHash: Y,
|
|
274
|
+
options: _.defaultQueryOptions(K),
|
|
275
|
+
state: q,
|
|
276
|
+
defaultOptions: _.getQueryDefaults(J)
|
|
277
|
+
}), this.add(X)), X;
|
|
278
|
+
}
|
|
279
|
+
add(_) {
|
|
280
|
+
this.#e.has(_.queryHash) || (this.#e.set(_.queryHash, _), this.notify({
|
|
281
|
+
type: "added",
|
|
282
|
+
query: _
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
remove(_) {
|
|
286
|
+
let K = this.#e.get(_.queryHash);
|
|
287
|
+
K && (_.destroy(), K === _ && this.#e.delete(_.queryHash), this.notify({
|
|
288
|
+
type: "removed",
|
|
289
|
+
query: _
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
clear() {
|
|
293
|
+
notifyManager.batch(() => {
|
|
294
|
+
this.getAll().forEach((_) => {
|
|
295
|
+
this.remove(_);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
get(_) {
|
|
300
|
+
return this.#e.get(_);
|
|
301
|
+
}
|
|
302
|
+
getAll() {
|
|
303
|
+
return [...this.#e.values()];
|
|
304
|
+
}
|
|
305
|
+
find(_) {
|
|
306
|
+
let K = {
|
|
307
|
+
exact: !0,
|
|
308
|
+
..._
|
|
309
|
+
};
|
|
310
|
+
return this.getAll().find((_) => matchQuery(K, _));
|
|
311
|
+
}
|
|
312
|
+
findAll(_ = {}) {
|
|
313
|
+
let K = this.getAll();
|
|
314
|
+
return Object.keys(_).length > 0 ? K.filter((K) => matchQuery(_, K)) : K;
|
|
315
|
+
}
|
|
316
|
+
notify(_) {
|
|
317
|
+
notifyManager.batch(() => {
|
|
318
|
+
this.listeners.forEach((K) => {
|
|
319
|
+
K(_);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
onFocus() {
|
|
324
|
+
notifyManager.batch(() => {
|
|
325
|
+
this.getAll().forEach((_) => {
|
|
326
|
+
_.onFocus();
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
onOnline() {
|
|
331
|
+
notifyManager.batch(() => {
|
|
332
|
+
this.getAll().forEach((_) => {
|
|
333
|
+
_.onOnline();
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}, QueryClient = class {
|
|
338
|
+
#e;
|
|
339
|
+
#t;
|
|
340
|
+
#n;
|
|
341
|
+
#r;
|
|
342
|
+
#i;
|
|
343
|
+
#a;
|
|
344
|
+
#o;
|
|
345
|
+
#s;
|
|
346
|
+
constructor(_ = {}) {
|
|
347
|
+
this.#e = _.queryCache || new QueryCache(), this.#t = _.mutationCache || new MutationCache(), this.#n = _.defaultOptions || {}, this.#r = /* @__PURE__ */ new Map(), this.#i = /* @__PURE__ */ new Map(), this.#a = 0;
|
|
348
|
+
}
|
|
349
|
+
mount() {
|
|
350
|
+
this.#a++, this.#a === 1 && (this.#o = focusManager.subscribe(async (_) => {
|
|
351
|
+
_ && (await this.resumePausedMutations(), this.#e.onFocus());
|
|
352
|
+
}), this.#s = onlineManager.subscribe(async (_) => {
|
|
353
|
+
_ && (await this.resumePausedMutations(), this.#e.onOnline());
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
unmount() {
|
|
357
|
+
this.#a--, this.#a === 0 && (this.#o?.(), this.#o = void 0, this.#s?.(), this.#s = void 0);
|
|
358
|
+
}
|
|
359
|
+
isFetching(_) {
|
|
360
|
+
return this.#e.findAll({
|
|
361
|
+
..._,
|
|
362
|
+
fetchStatus: "fetching"
|
|
363
|
+
}).length;
|
|
364
|
+
}
|
|
365
|
+
isMutating(_) {
|
|
366
|
+
return this.#t.findAll({
|
|
367
|
+
..._,
|
|
368
|
+
status: "pending"
|
|
369
|
+
}).length;
|
|
370
|
+
}
|
|
371
|
+
getQueryData(_) {
|
|
372
|
+
let K = this.defaultQueryOptions({ queryKey: _ });
|
|
373
|
+
return this.#e.get(K.queryHash)?.state.data;
|
|
374
|
+
}
|
|
375
|
+
ensureQueryData(_) {
|
|
376
|
+
let q = this.defaultQueryOptions(_), J = this.#e.build(this, q), Y = J.state.data;
|
|
377
|
+
return Y === void 0 ? this.fetchQuery(_) : (_.revalidateIfStale && J.isStaleByTime(resolveStaleTime(q.staleTime, J)) && this.prefetchQuery(q), Promise.resolve(Y));
|
|
378
|
+
}
|
|
379
|
+
getQueriesData(_) {
|
|
380
|
+
return this.#e.findAll(_).map(({ queryKey: _, state: K }) => [_, K.data]);
|
|
381
|
+
}
|
|
382
|
+
setQueryData(_, K, q) {
|
|
383
|
+
let J = this.defaultQueryOptions({ queryKey: _ }), Y = this.#e.get(J.queryHash)?.state.data, X = functionalUpdate(K, Y);
|
|
384
|
+
if (X !== void 0) return this.#e.build(this, J).setData(X, {
|
|
385
|
+
...q,
|
|
386
|
+
manual: !0
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
setQueriesData(_, K, q) {
|
|
390
|
+
return notifyManager.batch(() => this.#e.findAll(_).map(({ queryKey: _ }) => [_, this.setQueryData(_, K, q)]));
|
|
391
|
+
}
|
|
392
|
+
getQueryState(_) {
|
|
393
|
+
let K = this.defaultQueryOptions({ queryKey: _ });
|
|
394
|
+
return this.#e.get(K.queryHash)?.state;
|
|
395
|
+
}
|
|
396
|
+
removeQueries(_) {
|
|
397
|
+
let K = this.#e;
|
|
398
|
+
notifyManager.batch(() => {
|
|
399
|
+
K.findAll(_).forEach((_) => {
|
|
400
|
+
K.remove(_);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
resetQueries(_, K) {
|
|
405
|
+
let q = this.#e;
|
|
406
|
+
return notifyManager.batch(() => (q.findAll(_).forEach((_) => {
|
|
407
|
+
_.reset();
|
|
408
|
+
}), this.refetchQueries({
|
|
409
|
+
type: "active",
|
|
410
|
+
..._
|
|
411
|
+
}, K)));
|
|
412
|
+
}
|
|
413
|
+
cancelQueries(_, K = {}) {
|
|
414
|
+
let q = {
|
|
415
|
+
revert: !0,
|
|
416
|
+
...K
|
|
417
|
+
}, J = notifyManager.batch(() => this.#e.findAll(_).map((_) => _.cancel(q)));
|
|
418
|
+
return Promise.all(J).then(noop).catch(noop);
|
|
419
|
+
}
|
|
420
|
+
invalidateQueries(_, K = {}) {
|
|
421
|
+
return notifyManager.batch(() => (this.#e.findAll(_).forEach((_) => {
|
|
422
|
+
_.invalidate();
|
|
423
|
+
}), _?.refetchType === "none" ? Promise.resolve() : this.refetchQueries({
|
|
424
|
+
..._,
|
|
425
|
+
type: _?.refetchType ?? _?.type ?? "active"
|
|
426
|
+
}, K)));
|
|
427
|
+
}
|
|
428
|
+
refetchQueries(_, K = {}) {
|
|
429
|
+
let q = {
|
|
430
|
+
...K,
|
|
431
|
+
cancelRefetch: K.cancelRefetch ?? !0
|
|
432
|
+
}, J = notifyManager.batch(() => this.#e.findAll(_).filter((_) => !_.isDisabled() && !_.isStatic()).map((_) => {
|
|
433
|
+
let K = _.fetch(void 0, q);
|
|
434
|
+
return q.throwOnError || (K = K.catch(noop)), _.state.fetchStatus === "paused" ? Promise.resolve() : K;
|
|
435
|
+
}));
|
|
436
|
+
return Promise.all(J).then(noop);
|
|
437
|
+
}
|
|
438
|
+
fetchQuery(_) {
|
|
439
|
+
let q = this.defaultQueryOptions(_);
|
|
440
|
+
q.retry === void 0 && (q.retry = !1);
|
|
441
|
+
let J = this.#e.build(this, q);
|
|
442
|
+
return J.isStaleByTime(resolveStaleTime(q.staleTime, J)) ? J.fetch(q) : Promise.resolve(J.state.data);
|
|
443
|
+
}
|
|
444
|
+
prefetchQuery(_) {
|
|
445
|
+
return this.fetchQuery(_).then(noop).catch(noop);
|
|
446
|
+
}
|
|
447
|
+
fetchInfiniteQuery(_) {
|
|
448
|
+
return _._type = "infinite", this.fetchQuery(_);
|
|
449
|
+
}
|
|
450
|
+
prefetchInfiniteQuery(_) {
|
|
451
|
+
return this.fetchInfiniteQuery(_).then(noop).catch(noop);
|
|
452
|
+
}
|
|
453
|
+
ensureInfiniteQueryData(_) {
|
|
454
|
+
return _._type = "infinite", this.ensureQueryData(_);
|
|
455
|
+
}
|
|
456
|
+
resumePausedMutations() {
|
|
457
|
+
return onlineManager.isOnline() ? this.#t.resumePausedMutations() : Promise.resolve();
|
|
458
|
+
}
|
|
459
|
+
getQueryCache() {
|
|
460
|
+
return this.#e;
|
|
461
|
+
}
|
|
462
|
+
getMutationCache() {
|
|
463
|
+
return this.#t;
|
|
464
|
+
}
|
|
465
|
+
getDefaultOptions() {
|
|
466
|
+
return this.#n;
|
|
467
|
+
}
|
|
468
|
+
setDefaultOptions(_) {
|
|
469
|
+
this.#n = _;
|
|
470
|
+
}
|
|
471
|
+
setQueryDefaults(_, K) {
|
|
472
|
+
this.#r.set(hashKey(_), {
|
|
473
|
+
queryKey: _,
|
|
474
|
+
defaultOptions: K
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
getQueryDefaults(_) {
|
|
478
|
+
let K = [...this.#r.values()], q = {};
|
|
479
|
+
return K.forEach((K) => {
|
|
480
|
+
partialMatchKey(_, K.queryKey) && Object.assign(q, K.defaultOptions);
|
|
481
|
+
}), q;
|
|
482
|
+
}
|
|
483
|
+
setMutationDefaults(_, K) {
|
|
484
|
+
this.#i.set(hashKey(_), {
|
|
485
|
+
mutationKey: _,
|
|
486
|
+
defaultOptions: K
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
getMutationDefaults(_) {
|
|
490
|
+
let K = [...this.#i.values()], q = {};
|
|
491
|
+
return K.forEach((K) => {
|
|
492
|
+
partialMatchKey(_, K.mutationKey) && Object.assign(q, K.defaultOptions);
|
|
493
|
+
}), q;
|
|
494
|
+
}
|
|
495
|
+
defaultQueryOptions(_) {
|
|
496
|
+
if (_._defaulted) return _;
|
|
497
|
+
let K = {
|
|
498
|
+
...this.#n.queries,
|
|
499
|
+
...this.getQueryDefaults(_.queryKey),
|
|
500
|
+
..._,
|
|
501
|
+
_defaulted: !0
|
|
502
|
+
};
|
|
503
|
+
return K.queryHash ||= hashQueryKeyByOptions(K.queryKey, K), K.refetchOnReconnect === void 0 && (K.refetchOnReconnect = K.networkMode !== "always"), K.throwOnError === void 0 && (K.throwOnError = !!K.suspense), !K.networkMode && K.persister && (K.networkMode = "offlineFirst"), K.queryFn === skipToken && (K.enabled = !1), K;
|
|
504
|
+
}
|
|
505
|
+
defaultMutationOptions(_) {
|
|
506
|
+
return _?._defaulted ? _ : {
|
|
507
|
+
...this.#n.mutations,
|
|
508
|
+
..._?.mutationKey && this.getMutationDefaults(_.mutationKey),
|
|
509
|
+
..._,
|
|
510
|
+
_defaulted: !0
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
clear() {
|
|
514
|
+
this.#e.clear(), this.#t.clear();
|
|
515
|
+
}
|
|
516
|
+
}, errorThrower$1 = buildErrorThrower({ packageName: "💬 Resenty" }), createResentyUI = null;
|
|
517
|
+
const configureResentyUI = (_) => {
|
|
518
|
+
createResentyUI = _;
|
|
519
|
+
};
|
|
520
|
+
var persistedStateSchema = object({ state: record(string(), object({ sessionId: string() })).optional() });
|
|
521
|
+
function buildState(_, K) {
|
|
522
|
+
return { state: { [_]: { sessionId: K } } };
|
|
523
|
+
}
|
|
524
|
+
const SESSION_STORAGE_KEY = "resenty:session";
|
|
525
|
+
var SESSION_RETRY_ATTEMPTS = 3, SESSION_RETRY_BASE_MS = 500, SESSION_CREATE_PATH = "/widget/sessions", Resenty = class {
|
|
526
|
+
constructor() {
|
|
527
|
+
this.options = normalizeOptions(DEFAULT_PUBLIC_OPTIONS), this.resolvedOptions = normalizeOptions(DEFAULT_PUBLIC_OPTIONS), this.events = createEventEmitter(), this.queryClient = new QueryClient({ defaultOptions: { queries: {
|
|
528
|
+
refetchOnWindowFocus: !1,
|
|
529
|
+
refetchOnReconnect: !1,
|
|
530
|
+
throwOnError: !1
|
|
531
|
+
} } });
|
|
532
|
+
}
|
|
533
|
+
#e;
|
|
534
|
+
#t;
|
|
535
|
+
#n = null;
|
|
536
|
+
get session() {
|
|
537
|
+
return this.#e;
|
|
538
|
+
}
|
|
539
|
+
load(_, K) {
|
|
540
|
+
if (_ || errorThrower$1.throwMissingWidgetIdError(), this.appId = _, this.options = this.buildOptions({ ...K }), this.setAccessors(this.options), this.client = new Client({ client: this.createClient(this.options.baseUrl) }), isBrowser()) {
|
|
541
|
+
let K = this.getState();
|
|
542
|
+
K.state?.[_] && (this.#e = K.state?.[_]?.sessionId);
|
|
543
|
+
}
|
|
544
|
+
client.interceptors.request.use(async (_) => {
|
|
545
|
+
if (_.headers.set("x-resenty-widget-id", this.appId), isSessionCreationRequest(_)) return _;
|
|
546
|
+
let K = await this.ensureSession();
|
|
547
|
+
return K && _.headers.set("x-resenty-widget-client-session-id", K), _;
|
|
548
|
+
}), this.ensureSession(), this.#n = createResentyUI?.(this) ?? null;
|
|
549
|
+
}
|
|
550
|
+
async ensureSession(_) {
|
|
551
|
+
if (this.session && !_) return this.session;
|
|
552
|
+
if (this.#t && !_) return this.#t;
|
|
553
|
+
let K = this.bootstrapSession();
|
|
554
|
+
this.#t = K;
|
|
555
|
+
try {
|
|
556
|
+
return await K;
|
|
557
|
+
} finally {
|
|
558
|
+
this.#t === K && (this.#t = void 0);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
async bootstrapSession() {
|
|
562
|
+
let _ = this.resolvedOptions.userJwt, K = _ ? { body: { user_jwt: _ } } : void 0;
|
|
563
|
+
try {
|
|
564
|
+
return this.#e = await withRetry(async () => {
|
|
565
|
+
let _ = await this.client?.widget.sessions.createSession(K);
|
|
566
|
+
if (!_ || _.error) throw Error(_?.error?.message ?? "Session creation failed");
|
|
567
|
+
return _.data?.client_session_id;
|
|
568
|
+
}, {
|
|
569
|
+
attempts: SESSION_RETRY_ATTEMPTS,
|
|
570
|
+
baseMs: SESSION_RETRY_BASE_MS
|
|
571
|
+
}) ?? void 0, isBrowser() && this.#e && this.saveState(), this.#e;
|
|
572
|
+
} catch (_) {
|
|
573
|
+
console.warn("[Resenty] Failed to establish a session after retries", _);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
createClient(_) {
|
|
578
|
+
return client.setConfig({ baseUrl: _ }), client;
|
|
579
|
+
}
|
|
580
|
+
setAccessors(_) {
|
|
581
|
+
this.customer = _.customer, this.resolvedOptions = normalizeOptions(_);
|
|
582
|
+
}
|
|
583
|
+
updateCustomer(_) {
|
|
584
|
+
this.options = this.buildOptions({ customer: _ }), this.setAccessors(this.options);
|
|
585
|
+
}
|
|
586
|
+
update(_) {
|
|
587
|
+
let K = this.resolvedOptions.userJwt;
|
|
588
|
+
this.options = this.buildOptions(_), this.setAccessors(this.options), _.userJwt && _.userJwt !== K && this.ensureSession(!0);
|
|
589
|
+
}
|
|
590
|
+
buildOptions(_) {
|
|
591
|
+
return normalizeOptions(toMerged(this.options, _));
|
|
592
|
+
}
|
|
593
|
+
openChat() {
|
|
594
|
+
this.#n && this.events.emit("chat:toggle");
|
|
595
|
+
}
|
|
596
|
+
mountChat(_) {
|
|
597
|
+
this.#n && this.#n.ensureMounted({ preloadHint: "chat" }).then((K) => {
|
|
598
|
+
K.mountComponent({
|
|
599
|
+
name: "chat",
|
|
600
|
+
node: _,
|
|
601
|
+
props: {}
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
saveState() {
|
|
606
|
+
let _ = this.getState();
|
|
607
|
+
localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(merge(_, buildState(this.appId, this.session))));
|
|
608
|
+
}
|
|
609
|
+
getState() {
|
|
610
|
+
let _ = localStorage.getItem(SESSION_STORAGE_KEY);
|
|
611
|
+
if (!_) return {};
|
|
612
|
+
try {
|
|
613
|
+
let K = persistedStateSchema.safeParse(JSON.parse(_));
|
|
614
|
+
return K.success ? K.data : {};
|
|
615
|
+
} catch {
|
|
616
|
+
return {};
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
function isSessionCreationRequest(_) {
|
|
621
|
+
if (_.method !== "POST") return !1;
|
|
622
|
+
try {
|
|
623
|
+
return new URL(_.url).pathname.endsWith(SESSION_CREATE_PATH);
|
|
624
|
+
} catch {
|
|
625
|
+
return !1;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
var COMMANDS = {
|
|
629
|
+
identify: (_, [K]) => _.updateCustomer(K),
|
|
630
|
+
update: (_, [K]) => _.update(K),
|
|
631
|
+
openChat: (_) => _.openChat(),
|
|
632
|
+
mountChat: (_, [K]) => _.mountChat(K),
|
|
633
|
+
on: (_, [K, q]) => _.events.on(K, q)
|
|
634
|
+
};
|
|
635
|
+
function createCallableProxy(_) {
|
|
636
|
+
let K = function(K, ...q) {
|
|
637
|
+
let J = COMMANDS[K];
|
|
638
|
+
if (!J) {
|
|
639
|
+
console.warn(`[Resenty] Unknown command "${K}"`);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
J(_, q);
|
|
643
|
+
};
|
|
644
|
+
return K.instance = _, K;
|
|
645
|
+
}
|
|
646
|
+
function replayQueue(_, K) {
|
|
647
|
+
for (let [q, ...J] of K) _(q, ...J);
|
|
648
|
+
}
|
|
649
|
+
var errorThrower = buildErrorThrower({ packageName: "💬 Resenty" }), loaderWindow = window;
|
|
650
|
+
async function bootstrap() {
|
|
651
|
+
let _ = loaderWindow.resentyOptions ?? {};
|
|
652
|
+
_.appId || errorThrower.throwMissingWidgetIdError();
|
|
653
|
+
let { ResentyUI: K } = await import("./chunks/ui-f9sPMhJV.js");
|
|
654
|
+
configureResentyUI((_) => new K(_));
|
|
655
|
+
let q = new Resenty();
|
|
656
|
+
q.load(_.appId, _);
|
|
657
|
+
let J = loaderWindow.Resenty, Y = J && "q" in J && Array.isArray(J.q) ? J.q : [], X = createCallableProxy(q), Z = function(_, ...K) {
|
|
658
|
+
if (_ === "mountChat" && typeof K[0] == "string") {
|
|
659
|
+
let _ = document.querySelector(K[0]);
|
|
660
|
+
if (!_) {
|
|
661
|
+
console.warn(`[Resenty] mountChat: no element matches "${K[0]}"`);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
X("mountChat", _);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
X(_, ...K);
|
|
668
|
+
};
|
|
669
|
+
if (Z.instance = X.instance, loaderWindow.Resenty = Z, replayQueue(Z, Y), _.appearance?.chat?.showTrigger !== !1) {
|
|
670
|
+
let _ = document.createElement("div");
|
|
671
|
+
_.id = "resenty-host", document.body ? (document.body.appendChild(_), q.mountChat(_)) : window.addEventListener("DOMContentLoaded", () => {
|
|
672
|
+
document.body.appendChild(_), q.mountChat(_);
|
|
673
|
+
}, { once: !0 });
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
bootstrap();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
@import "./global/preflight.css";.resenty-namespace{--resenty-background:#fff;--resenty-foreground:#000;--resenty-border:#e0e0e0;--resenty-border-radius:.5rem;--resenty-border-width:1px;--resenty-border-style:solid;--resenty-border-color:#e0e0e0}.resenty-namespace .resenty-isolation-wrapper{isolation:isolate}.resenty-namespace .resenty-frame-container{z-index:2147483000;isolation:isolate;opacity:0;pointer-events:none;--screen-height:max(0px, calc(100dvh - 125px));--screen-width:max(0px, calc(100dvw - 24px));--height:min(780px, var(--screen-height), var(--content-height,900px));--width:min(420px, var(--screen-width));width:var(--width);height:var(--height);border-radius:16px;transition:opacity .4s cubic-bezier(.82,.6,.5,1.14);position:fixed;bottom:80px;right:25px;overflow:hidden;box-shadow:0 2px 2px -1px #0000001a,0 1px #191c2105,0 0 0 1px #191c2114}.resenty-namespace .resenty-frame-container[data-open=true]{opacity:1;pointer-events:auto}.resenty-namespace .resenty-frame-container[data-resize-transition=true]{transition:opacity .4s cubic-bezier(.82,.6,.5,1.14),width .18s,height .18s,bottom .18s}.resenty-namespace .resenty-frame-container[data-expanded=true]{--height:max(0px, calc(100dvh - 92px));--width:min(492px, var(--screen-width));max-height:var(--height);bottom:80px}.resenty-namespace .resenty-frame-container[data-expanded=true][data-no-trigger]{--height:max(0px, calc(100dvh - 24px));bottom:8px}.resenty-namespace .resenty-frame-container[data-no-trigger]{bottom:8px;right:10px}.resenty-namespace .resenty-frame-container>iframe{border:none;width:100%;height:100%}.resenty-namespace .resenty-launcher-container{z-index:2147483000;-webkit-user-select:none;user-select:none;border-radius:50%;width:48px;height:48px;position:fixed;bottom:20px;right:20px;overflow:hidden;box-shadow:0 1px #11111a1a,0 8px 24px #11111a1a,0 16px 48px #11111a1a}.resenty-namespace .resenty-launcher-container:hover{transform:scale(1.1)}.resenty-namespace .resenty-launcher-container>iframe{border:none;border-radius:50%;width:48px;height:48px;position:absolute;overflow:hidden}.resenty-namespace .resenty-trigger-wrapper{z-index:2147483000;-webkit-user-select:none;user-select:none;border-radius:50%;width:48px;height:48px;position:fixed;bottom:20px;right:20px;overflow:hidden;box-shadow:0 1px #11111a1a,0 8px 24px #11111a1a,0 16px 48px #11111a1a}.resenty-namespace .resenty-trigger-button{cursor:pointer;border:none;border-radius:50%;justify-content:center;align-items:center;width:48px;height:48px;animation:.4s cubic-bezier(.34,1.56,.64,1) both resenty-trigger-enter;display:flex;overflow:hidden;box-shadow:0 1px #11111a1a,0 8px 24px #11111a1a,0 16px 48px #11111a1a}.resenty-namespace .resenty-trigger-button>svg{transition:transform .3s cubic-bezier(.34,1.56,.64,1),opacity .3s}.resenty-namespace .resenty-trigger-button[data-open=false]>svg,.resenty-namespace .resenty-trigger-button[data-open=true]>svg{animation:.3s cubic-bezier(.34,1.56,.64,1) both resenty-icon-in}@keyframes resenty-icon-in{0%{opacity:0;transform:scale(0)rotate(-180deg)}to{opacity:1;transform:scale(1)rotate(0)}}@keyframes resenty-trigger-enter{0%{opacity:0;transform:scale(0)translateY(16px)rotate(-180deg)}to{opacity:1;transform:scale(1)translateY(0)rotate(0)}}
|
|
2
|
+
/*$vite$:1*/
|