@memberstack/dom 1.0.0-beta.17 → 1.0.0-beta.20

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.
Files changed (49) hide show
  1. package/{dist → lib}/auth/persistence/index.d.ts +1 -1
  2. package/lib/auth/persistence/index.js +13 -0
  3. package/{dist → lib}/auth/persistence/local.d.ts +5 -5
  4. package/lib/auth/persistence/local.js +20 -0
  5. package/{dist → lib}/auth/persistence/methods.d.ts +13 -13
  6. package/lib/auth/persistence/methods.js +87 -0
  7. package/{dist → lib}/auth/persistence/session.d.ts +5 -5
  8. package/lib/auth/persistence/session.js +20 -0
  9. package/{dist → lib}/constants/cookies.d.ts +3 -3
  10. package/lib/constants/cookies.js +7 -0
  11. package/{dist → lib}/constants/endpoint.d.ts +4 -4
  12. package/lib/constants/endpoint.js +7 -0
  13. package/{dist → lib}/constants/storage.d.ts +1 -1
  14. package/lib/constants/storage.js +4 -0
  15. package/lib/constants/window.d.ts +3 -0
  16. package/lib/constants/window.js +6 -0
  17. package/lib/index.d.ts +5 -0
  18. package/lib/index.js +7 -0
  19. package/lib/methods/client.d.ts +36 -0
  20. package/lib/methods/client.js +23 -0
  21. package/{dist → lib}/methods/dom/index.d.ts +2 -2
  22. package/lib/methods/dom/index.js +9 -0
  23. package/lib/methods/dom/methods.d.ts +31 -0
  24. package/lib/methods/dom/methods.js +45 -0
  25. package/lib/methods/dom/script.d.ts +3 -0
  26. package/lib/methods/dom/script.js +40 -0
  27. package/lib/methods/index.d.ts +12 -0
  28. package/lib/methods/index.js +35 -0
  29. package/{dist → lib}/utils/cookies.d.ts +2 -2
  30. package/lib/utils/cookies.js +19 -0
  31. package/lib/utils/interceptor.d.ts +4 -0
  32. package/lib/utils/interceptor.js +18 -0
  33. package/{dist → lib}/utils/proxy.d.ts +2 -2
  34. package/lib/utils/proxy.js +62 -0
  35. package/package.json +6 -18
  36. package/dist/constants/window.d.ts +0 -4
  37. package/dist/dom.cjs.development.js +0 -1262
  38. package/dist/dom.cjs.development.js.map +0 -1
  39. package/dist/dom.cjs.production.min.js +0 -2
  40. package/dist/dom.cjs.production.min.js.map +0 -1
  41. package/dist/dom.esm.js +0 -1259
  42. package/dist/dom.esm.js.map +0 -1
  43. package/dist/index.d.ts +0 -3
  44. package/dist/index.js +0 -8
  45. package/dist/methods/client.d.ts +0 -644
  46. package/dist/methods/dom/methods.d.ts +0 -17
  47. package/dist/methods/dom/script.d.ts +0 -3
  48. package/dist/methods/index.d.ts +0 -25
  49. package/dist/utils/interceptor.d.ts +0 -3
package/dist/dom.esm.js DELETED
@@ -1,1259 +0,0 @@
1
- import Cookie from 'js-cookie';
2
- import msClient from '@memberstack/client';
3
- import { RequestInterceptor } from 'node-request-interceptor';
4
- import withDefaultInterceptors from 'node-request-interceptor/lib/presets/default';
5
-
6
- var PERSISTED_MEMBER_KEY = "_ms-mem";
7
-
8
- var localStoragePersistence = {
9
- setMember: function setMember(member) {
10
- var _localStorage, _localStorage2;
11
-
12
- (_localStorage = localStorage) == null ? void 0 : _localStorage.setItem(PERSISTED_MEMBER_KEY, JSON.stringify(member));
13
- return JSON.parse((_localStorage2 = localStorage) == null ? void 0 : _localStorage2.getItem(PERSISTED_MEMBER_KEY));
14
- },
15
- getMember: function getMember() {
16
- var _localStorage3, _localStorage4;
17
-
18
- var persistedMember = (_localStorage3 = localStorage) == null ? void 0 : _localStorage3.getItem(PERSISTED_MEMBER_KEY);
19
-
20
- if (!persistedMember || !Object.keys(persistedMember).length) {
21
- return null;
22
- }
23
-
24
- return JSON.parse((_localStorage4 = localStorage) == null ? void 0 : _localStorage4.getItem(PERSISTED_MEMBER_KEY));
25
- },
26
- unsetMember: function unsetMember() {
27
- var _localStorage5;
28
-
29
- (_localStorage5 = localStorage) == null ? void 0 : _localStorage5.removeItem(PERSISTED_MEMBER_KEY);
30
- }
31
- };
32
-
33
- var sessionStoragePersistence = {
34
- setMember: function setMember(member) {
35
- var _sessionStorage, _sessionStorage2;
36
-
37
- (_sessionStorage = sessionStorage) == null ? void 0 : _sessionStorage.setItem(PERSISTED_MEMBER_KEY, JSON.stringify(member));
38
- return JSON.parse((_sessionStorage2 = sessionStorage) == null ? void 0 : _sessionStorage2.getItem(PERSISTED_MEMBER_KEY));
39
- },
40
- getMember: function getMember() {
41
- var _sessionStorage3, _sessionStorage4;
42
-
43
- var persistedMember = (_sessionStorage3 = sessionStorage) == null ? void 0 : _sessionStorage3.getItem(PERSISTED_MEMBER_KEY);
44
-
45
- if (!persistedMember || !Object.keys(persistedMember).length) {
46
- return null;
47
- }
48
-
49
- return JSON.parse((_sessionStorage4 = sessionStorage) == null ? void 0 : _sessionStorage4.getItem(PERSISTED_MEMBER_KEY));
50
- },
51
- unsetMember: function unsetMember() {
52
- var _sessionStorage5;
53
-
54
- (_sessionStorage5 = sessionStorage) == null ? void 0 : _sessionStorage5.removeItem(PERSISTED_MEMBER_KEY);
55
- }
56
- };
57
-
58
- var Persistence;
59
-
60
- (function (Persistence) {
61
- Persistence["SESSION"] = "SESSION";
62
- Persistence["LOCAL"] = "LOCAL";
63
- })(Persistence || (Persistence = {}));
64
-
65
- var createObservable = function createObservable() {
66
- var observer = new Map();
67
- return {
68
- subscribe: function subscribe(key, fn) {
69
- if (typeof fn !== "function") return;
70
- return observer.set(key, fn);
71
- },
72
- unsubscribe: function unsubscribe(key) {
73
- return observer["delete"](key);
74
- },
75
- notify: function notify(data) {
76
- return [].concat(observer.values()).forEach(function (fn) {
77
- return fn(data);
78
- });
79
- }
80
- };
81
- };
82
-
83
- var observable = /*#__PURE__*/createObservable();
84
-
85
- var getPersistence = function getPersistence(persistence) {
86
- if (persistence === Persistence.LOCAL) {
87
- return localStoragePersistence;
88
- }
89
-
90
- if (persistence === Persistence.SESSION) {
91
- return sessionStoragePersistence;
92
- }
93
- };
94
-
95
- var setPersistedMember = function setPersistedMember(member, persistence) {
96
- if (member) {
97
- var _getPersistence;
98
-
99
- (_getPersistence = getPersistence(persistence)) == null ? void 0 : _getPersistence.setMember(member);
100
- observable.notify(member);
101
- }
102
- };
103
- var getPersistedMember = function getPersistedMember(persistence) {
104
- var _getPersistence2;
105
-
106
- return (_getPersistence2 = getPersistence(persistence)) == null ? void 0 : _getPersistence2.getMember();
107
- };
108
- var unsetPersistedMember = function unsetPersistedMember(persistence) {
109
- var _getPersistence3;
110
-
111
- (_getPersistence3 = getPersistence(persistence)) == null ? void 0 : _getPersistence3.unsetMember();
112
- observable.notify(null);
113
- };
114
- var onAuthChange = function onAuthChange(cb) {
115
- var id = Math.floor(Math.random() * 1000);
116
- observable.subscribe(id, cb);
117
- return {
118
- unsubscribe: function unsubscribe() {
119
- return observable.unsubscribe(id);
120
- }
121
- };
122
- };
123
-
124
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
125
- try {
126
- var info = gen[key](arg);
127
- var value = info.value;
128
- } catch (error) {
129
- reject(error);
130
- return;
131
- }
132
-
133
- if (info.done) {
134
- resolve(value);
135
- } else {
136
- Promise.resolve(value).then(_next, _throw);
137
- }
138
- }
139
-
140
- function _asyncToGenerator(fn) {
141
- return function () {
142
- var self = this,
143
- args = arguments;
144
- return new Promise(function (resolve, reject) {
145
- var gen = fn.apply(self, args);
146
-
147
- function _next(value) {
148
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
149
- }
150
-
151
- function _throw(err) {
152
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
153
- }
154
-
155
- _next(undefined);
156
- });
157
- };
158
- }
159
-
160
- function _extends() {
161
- _extends = Object.assign || function (target) {
162
- for (var i = 1; i < arguments.length; i++) {
163
- var source = arguments[i];
164
-
165
- for (var key in source) {
166
- if (Object.prototype.hasOwnProperty.call(source, key)) {
167
- target[key] = source[key];
168
- }
169
- }
170
- }
171
-
172
- return target;
173
- };
174
-
175
- return _extends.apply(this, arguments);
176
- }
177
-
178
- function _objectWithoutPropertiesLoose(source, excluded) {
179
- if (source == null) return {};
180
- var target = {};
181
- var sourceKeys = Object.keys(source);
182
- var key, i;
183
-
184
- for (i = 0; i < sourceKeys.length; i++) {
185
- key = sourceKeys[i];
186
- if (excluded.indexOf(key) >= 0) continue;
187
- target[key] = source[key];
188
- }
189
-
190
- return target;
191
- }
192
-
193
- function createCommonjsModule(fn, module) {
194
- return module = { exports: {} }, fn(module, module.exports), module.exports;
195
- }
196
-
197
- var runtime_1 = createCommonjsModule(function (module) {
198
- /**
199
- * Copyright (c) 2014-present, Facebook, Inc.
200
- *
201
- * This source code is licensed under the MIT license found in the
202
- * LICENSE file in the root directory of this source tree.
203
- */
204
-
205
- var runtime = (function (exports) {
206
-
207
- var Op = Object.prototype;
208
- var hasOwn = Op.hasOwnProperty;
209
- var undefined$1; // More compressible than void 0.
210
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
211
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
212
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
213
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
214
-
215
- function define(obj, key, value) {
216
- Object.defineProperty(obj, key, {
217
- value: value,
218
- enumerable: true,
219
- configurable: true,
220
- writable: true
221
- });
222
- return obj[key];
223
- }
224
- try {
225
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
226
- define({}, "");
227
- } catch (err) {
228
- define = function(obj, key, value) {
229
- return obj[key] = value;
230
- };
231
- }
232
-
233
- function wrap(innerFn, outerFn, self, tryLocsList) {
234
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
235
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
236
- var generator = Object.create(protoGenerator.prototype);
237
- var context = new Context(tryLocsList || []);
238
-
239
- // The ._invoke method unifies the implementations of the .next,
240
- // .throw, and .return methods.
241
- generator._invoke = makeInvokeMethod(innerFn, self, context);
242
-
243
- return generator;
244
- }
245
- exports.wrap = wrap;
246
-
247
- // Try/catch helper to minimize deoptimizations. Returns a completion
248
- // record like context.tryEntries[i].completion. This interface could
249
- // have been (and was previously) designed to take a closure to be
250
- // invoked without arguments, but in all the cases we care about we
251
- // already have an existing method we want to call, so there's no need
252
- // to create a new function object. We can even get away with assuming
253
- // the method takes exactly one argument, since that happens to be true
254
- // in every case, so we don't have to touch the arguments object. The
255
- // only additional allocation required is the completion record, which
256
- // has a stable shape and so hopefully should be cheap to allocate.
257
- function tryCatch(fn, obj, arg) {
258
- try {
259
- return { type: "normal", arg: fn.call(obj, arg) };
260
- } catch (err) {
261
- return { type: "throw", arg: err };
262
- }
263
- }
264
-
265
- var GenStateSuspendedStart = "suspendedStart";
266
- var GenStateSuspendedYield = "suspendedYield";
267
- var GenStateExecuting = "executing";
268
- var GenStateCompleted = "completed";
269
-
270
- // Returning this object from the innerFn has the same effect as
271
- // breaking out of the dispatch switch statement.
272
- var ContinueSentinel = {};
273
-
274
- // Dummy constructor functions that we use as the .constructor and
275
- // .constructor.prototype properties for functions that return Generator
276
- // objects. For full spec compliance, you may wish to configure your
277
- // minifier not to mangle the names of these two functions.
278
- function Generator() {}
279
- function GeneratorFunction() {}
280
- function GeneratorFunctionPrototype() {}
281
-
282
- // This is a polyfill for %IteratorPrototype% for environments that
283
- // don't natively support it.
284
- var IteratorPrototype = {};
285
- define(IteratorPrototype, iteratorSymbol, function () {
286
- return this;
287
- });
288
-
289
- var getProto = Object.getPrototypeOf;
290
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
291
- if (NativeIteratorPrototype &&
292
- NativeIteratorPrototype !== Op &&
293
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
294
- // This environment has a native %IteratorPrototype%; use it instead
295
- // of the polyfill.
296
- IteratorPrototype = NativeIteratorPrototype;
297
- }
298
-
299
- var Gp = GeneratorFunctionPrototype.prototype =
300
- Generator.prototype = Object.create(IteratorPrototype);
301
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
302
- define(Gp, "constructor", GeneratorFunctionPrototype);
303
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
304
- GeneratorFunction.displayName = define(
305
- GeneratorFunctionPrototype,
306
- toStringTagSymbol,
307
- "GeneratorFunction"
308
- );
309
-
310
- // Helper for defining the .next, .throw, and .return methods of the
311
- // Iterator interface in terms of a single ._invoke method.
312
- function defineIteratorMethods(prototype) {
313
- ["next", "throw", "return"].forEach(function(method) {
314
- define(prototype, method, function(arg) {
315
- return this._invoke(method, arg);
316
- });
317
- });
318
- }
319
-
320
- exports.isGeneratorFunction = function(genFun) {
321
- var ctor = typeof genFun === "function" && genFun.constructor;
322
- return ctor
323
- ? ctor === GeneratorFunction ||
324
- // For the native GeneratorFunction constructor, the best we can
325
- // do is to check its .name property.
326
- (ctor.displayName || ctor.name) === "GeneratorFunction"
327
- : false;
328
- };
329
-
330
- exports.mark = function(genFun) {
331
- if (Object.setPrototypeOf) {
332
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
333
- } else {
334
- genFun.__proto__ = GeneratorFunctionPrototype;
335
- define(genFun, toStringTagSymbol, "GeneratorFunction");
336
- }
337
- genFun.prototype = Object.create(Gp);
338
- return genFun;
339
- };
340
-
341
- // Within the body of any async function, `await x` is transformed to
342
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
343
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
344
- // meant to be awaited.
345
- exports.awrap = function(arg) {
346
- return { __await: arg };
347
- };
348
-
349
- function AsyncIterator(generator, PromiseImpl) {
350
- function invoke(method, arg, resolve, reject) {
351
- var record = tryCatch(generator[method], generator, arg);
352
- if (record.type === "throw") {
353
- reject(record.arg);
354
- } else {
355
- var result = record.arg;
356
- var value = result.value;
357
- if (value &&
358
- typeof value === "object" &&
359
- hasOwn.call(value, "__await")) {
360
- return PromiseImpl.resolve(value.__await).then(function(value) {
361
- invoke("next", value, resolve, reject);
362
- }, function(err) {
363
- invoke("throw", err, resolve, reject);
364
- });
365
- }
366
-
367
- return PromiseImpl.resolve(value).then(function(unwrapped) {
368
- // When a yielded Promise is resolved, its final value becomes
369
- // the .value of the Promise<{value,done}> result for the
370
- // current iteration.
371
- result.value = unwrapped;
372
- resolve(result);
373
- }, function(error) {
374
- // If a rejected Promise was yielded, throw the rejection back
375
- // into the async generator function so it can be handled there.
376
- return invoke("throw", error, resolve, reject);
377
- });
378
- }
379
- }
380
-
381
- var previousPromise;
382
-
383
- function enqueue(method, arg) {
384
- function callInvokeWithMethodAndArg() {
385
- return new PromiseImpl(function(resolve, reject) {
386
- invoke(method, arg, resolve, reject);
387
- });
388
- }
389
-
390
- return previousPromise =
391
- // If enqueue has been called before, then we want to wait until
392
- // all previous Promises have been resolved before calling invoke,
393
- // so that results are always delivered in the correct order. If
394
- // enqueue has not been called before, then it is important to
395
- // call invoke immediately, without waiting on a callback to fire,
396
- // so that the async generator function has the opportunity to do
397
- // any necessary setup in a predictable way. This predictability
398
- // is why the Promise constructor synchronously invokes its
399
- // executor callback, and why async functions synchronously
400
- // execute code before the first await. Since we implement simple
401
- // async functions in terms of async generators, it is especially
402
- // important to get this right, even though it requires care.
403
- previousPromise ? previousPromise.then(
404
- callInvokeWithMethodAndArg,
405
- // Avoid propagating failures to Promises returned by later
406
- // invocations of the iterator.
407
- callInvokeWithMethodAndArg
408
- ) : callInvokeWithMethodAndArg();
409
- }
410
-
411
- // Define the unified helper method that is used to implement .next,
412
- // .throw, and .return (see defineIteratorMethods).
413
- this._invoke = enqueue;
414
- }
415
-
416
- defineIteratorMethods(AsyncIterator.prototype);
417
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
418
- return this;
419
- });
420
- exports.AsyncIterator = AsyncIterator;
421
-
422
- // Note that simple async functions are implemented on top of
423
- // AsyncIterator objects; they just return a Promise for the value of
424
- // the final result produced by the iterator.
425
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
426
- if (PromiseImpl === void 0) PromiseImpl = Promise;
427
-
428
- var iter = new AsyncIterator(
429
- wrap(innerFn, outerFn, self, tryLocsList),
430
- PromiseImpl
431
- );
432
-
433
- return exports.isGeneratorFunction(outerFn)
434
- ? iter // If outerFn is a generator, return the full iterator.
435
- : iter.next().then(function(result) {
436
- return result.done ? result.value : iter.next();
437
- });
438
- };
439
-
440
- function makeInvokeMethod(innerFn, self, context) {
441
- var state = GenStateSuspendedStart;
442
-
443
- return function invoke(method, arg) {
444
- if (state === GenStateExecuting) {
445
- throw new Error("Generator is already running");
446
- }
447
-
448
- if (state === GenStateCompleted) {
449
- if (method === "throw") {
450
- throw arg;
451
- }
452
-
453
- // Be forgiving, per 25.3.3.3.3 of the spec:
454
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
455
- return doneResult();
456
- }
457
-
458
- context.method = method;
459
- context.arg = arg;
460
-
461
- while (true) {
462
- var delegate = context.delegate;
463
- if (delegate) {
464
- var delegateResult = maybeInvokeDelegate(delegate, context);
465
- if (delegateResult) {
466
- if (delegateResult === ContinueSentinel) continue;
467
- return delegateResult;
468
- }
469
- }
470
-
471
- if (context.method === "next") {
472
- // Setting context._sent for legacy support of Babel's
473
- // function.sent implementation.
474
- context.sent = context._sent = context.arg;
475
-
476
- } else if (context.method === "throw") {
477
- if (state === GenStateSuspendedStart) {
478
- state = GenStateCompleted;
479
- throw context.arg;
480
- }
481
-
482
- context.dispatchException(context.arg);
483
-
484
- } else if (context.method === "return") {
485
- context.abrupt("return", context.arg);
486
- }
487
-
488
- state = GenStateExecuting;
489
-
490
- var record = tryCatch(innerFn, self, context);
491
- if (record.type === "normal") {
492
- // If an exception is thrown from innerFn, we leave state ===
493
- // GenStateExecuting and loop back for another invocation.
494
- state = context.done
495
- ? GenStateCompleted
496
- : GenStateSuspendedYield;
497
-
498
- if (record.arg === ContinueSentinel) {
499
- continue;
500
- }
501
-
502
- return {
503
- value: record.arg,
504
- done: context.done
505
- };
506
-
507
- } else if (record.type === "throw") {
508
- state = GenStateCompleted;
509
- // Dispatch the exception by looping back around to the
510
- // context.dispatchException(context.arg) call above.
511
- context.method = "throw";
512
- context.arg = record.arg;
513
- }
514
- }
515
- };
516
- }
517
-
518
- // Call delegate.iterator[context.method](context.arg) and handle the
519
- // result, either by returning a { value, done } result from the
520
- // delegate iterator, or by modifying context.method and context.arg,
521
- // setting context.delegate to null, and returning the ContinueSentinel.
522
- function maybeInvokeDelegate(delegate, context) {
523
- var method = delegate.iterator[context.method];
524
- if (method === undefined$1) {
525
- // A .throw or .return when the delegate iterator has no .throw
526
- // method always terminates the yield* loop.
527
- context.delegate = null;
528
-
529
- if (context.method === "throw") {
530
- // Note: ["return"] must be used for ES3 parsing compatibility.
531
- if (delegate.iterator["return"]) {
532
- // If the delegate iterator has a return method, give it a
533
- // chance to clean up.
534
- context.method = "return";
535
- context.arg = undefined$1;
536
- maybeInvokeDelegate(delegate, context);
537
-
538
- if (context.method === "throw") {
539
- // If maybeInvokeDelegate(context) changed context.method from
540
- // "return" to "throw", let that override the TypeError below.
541
- return ContinueSentinel;
542
- }
543
- }
544
-
545
- context.method = "throw";
546
- context.arg = new TypeError(
547
- "The iterator does not provide a 'throw' method");
548
- }
549
-
550
- return ContinueSentinel;
551
- }
552
-
553
- var record = tryCatch(method, delegate.iterator, context.arg);
554
-
555
- if (record.type === "throw") {
556
- context.method = "throw";
557
- context.arg = record.arg;
558
- context.delegate = null;
559
- return ContinueSentinel;
560
- }
561
-
562
- var info = record.arg;
563
-
564
- if (! info) {
565
- context.method = "throw";
566
- context.arg = new TypeError("iterator result is not an object");
567
- context.delegate = null;
568
- return ContinueSentinel;
569
- }
570
-
571
- if (info.done) {
572
- // Assign the result of the finished delegate to the temporary
573
- // variable specified by delegate.resultName (see delegateYield).
574
- context[delegate.resultName] = info.value;
575
-
576
- // Resume execution at the desired location (see delegateYield).
577
- context.next = delegate.nextLoc;
578
-
579
- // If context.method was "throw" but the delegate handled the
580
- // exception, let the outer generator proceed normally. If
581
- // context.method was "next", forget context.arg since it has been
582
- // "consumed" by the delegate iterator. If context.method was
583
- // "return", allow the original .return call to continue in the
584
- // outer generator.
585
- if (context.method !== "return") {
586
- context.method = "next";
587
- context.arg = undefined$1;
588
- }
589
-
590
- } else {
591
- // Re-yield the result returned by the delegate method.
592
- return info;
593
- }
594
-
595
- // The delegate iterator is finished, so forget it and continue with
596
- // the outer generator.
597
- context.delegate = null;
598
- return ContinueSentinel;
599
- }
600
-
601
- // Define Generator.prototype.{next,throw,return} in terms of the
602
- // unified ._invoke helper method.
603
- defineIteratorMethods(Gp);
604
-
605
- define(Gp, toStringTagSymbol, "Generator");
606
-
607
- // A Generator should always return itself as the iterator object when the
608
- // @@iterator function is called on it. Some browsers' implementations of the
609
- // iterator prototype chain incorrectly implement this, causing the Generator
610
- // object to not be returned from this call. This ensures that doesn't happen.
611
- // See https://github.com/facebook/regenerator/issues/274 for more details.
612
- define(Gp, iteratorSymbol, function() {
613
- return this;
614
- });
615
-
616
- define(Gp, "toString", function() {
617
- return "[object Generator]";
618
- });
619
-
620
- function pushTryEntry(locs) {
621
- var entry = { tryLoc: locs[0] };
622
-
623
- if (1 in locs) {
624
- entry.catchLoc = locs[1];
625
- }
626
-
627
- if (2 in locs) {
628
- entry.finallyLoc = locs[2];
629
- entry.afterLoc = locs[3];
630
- }
631
-
632
- this.tryEntries.push(entry);
633
- }
634
-
635
- function resetTryEntry(entry) {
636
- var record = entry.completion || {};
637
- record.type = "normal";
638
- delete record.arg;
639
- entry.completion = record;
640
- }
641
-
642
- function Context(tryLocsList) {
643
- // The root entry object (effectively a try statement without a catch
644
- // or a finally block) gives us a place to store values thrown from
645
- // locations where there is no enclosing try statement.
646
- this.tryEntries = [{ tryLoc: "root" }];
647
- tryLocsList.forEach(pushTryEntry, this);
648
- this.reset(true);
649
- }
650
-
651
- exports.keys = function(object) {
652
- var keys = [];
653
- for (var key in object) {
654
- keys.push(key);
655
- }
656
- keys.reverse();
657
-
658
- // Rather than returning an object with a next method, we keep
659
- // things simple and return the next function itself.
660
- return function next() {
661
- while (keys.length) {
662
- var key = keys.pop();
663
- if (key in object) {
664
- next.value = key;
665
- next.done = false;
666
- return next;
667
- }
668
- }
669
-
670
- // To avoid creating an additional object, we just hang the .value
671
- // and .done properties off the next function object itself. This
672
- // also ensures that the minifier will not anonymize the function.
673
- next.done = true;
674
- return next;
675
- };
676
- };
677
-
678
- function values(iterable) {
679
- if (iterable) {
680
- var iteratorMethod = iterable[iteratorSymbol];
681
- if (iteratorMethod) {
682
- return iteratorMethod.call(iterable);
683
- }
684
-
685
- if (typeof iterable.next === "function") {
686
- return iterable;
687
- }
688
-
689
- if (!isNaN(iterable.length)) {
690
- var i = -1, next = function next() {
691
- while (++i < iterable.length) {
692
- if (hasOwn.call(iterable, i)) {
693
- next.value = iterable[i];
694
- next.done = false;
695
- return next;
696
- }
697
- }
698
-
699
- next.value = undefined$1;
700
- next.done = true;
701
-
702
- return next;
703
- };
704
-
705
- return next.next = next;
706
- }
707
- }
708
-
709
- // Return an iterator with no values.
710
- return { next: doneResult };
711
- }
712
- exports.values = values;
713
-
714
- function doneResult() {
715
- return { value: undefined$1, done: true };
716
- }
717
-
718
- Context.prototype = {
719
- constructor: Context,
720
-
721
- reset: function(skipTempReset) {
722
- this.prev = 0;
723
- this.next = 0;
724
- // Resetting context._sent for legacy support of Babel's
725
- // function.sent implementation.
726
- this.sent = this._sent = undefined$1;
727
- this.done = false;
728
- this.delegate = null;
729
-
730
- this.method = "next";
731
- this.arg = undefined$1;
732
-
733
- this.tryEntries.forEach(resetTryEntry);
734
-
735
- if (!skipTempReset) {
736
- for (var name in this) {
737
- // Not sure about the optimal order of these conditions:
738
- if (name.charAt(0) === "t" &&
739
- hasOwn.call(this, name) &&
740
- !isNaN(+name.slice(1))) {
741
- this[name] = undefined$1;
742
- }
743
- }
744
- }
745
- },
746
-
747
- stop: function() {
748
- this.done = true;
749
-
750
- var rootEntry = this.tryEntries[0];
751
- var rootRecord = rootEntry.completion;
752
- if (rootRecord.type === "throw") {
753
- throw rootRecord.arg;
754
- }
755
-
756
- return this.rval;
757
- },
758
-
759
- dispatchException: function(exception) {
760
- if (this.done) {
761
- throw exception;
762
- }
763
-
764
- var context = this;
765
- function handle(loc, caught) {
766
- record.type = "throw";
767
- record.arg = exception;
768
- context.next = loc;
769
-
770
- if (caught) {
771
- // If the dispatched exception was caught by a catch block,
772
- // then let that catch block handle the exception normally.
773
- context.method = "next";
774
- context.arg = undefined$1;
775
- }
776
-
777
- return !! caught;
778
- }
779
-
780
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
781
- var entry = this.tryEntries[i];
782
- var record = entry.completion;
783
-
784
- if (entry.tryLoc === "root") {
785
- // Exception thrown outside of any try block that could handle
786
- // it, so set the completion value of the entire function to
787
- // throw the exception.
788
- return handle("end");
789
- }
790
-
791
- if (entry.tryLoc <= this.prev) {
792
- var hasCatch = hasOwn.call(entry, "catchLoc");
793
- var hasFinally = hasOwn.call(entry, "finallyLoc");
794
-
795
- if (hasCatch && hasFinally) {
796
- if (this.prev < entry.catchLoc) {
797
- return handle(entry.catchLoc, true);
798
- } else if (this.prev < entry.finallyLoc) {
799
- return handle(entry.finallyLoc);
800
- }
801
-
802
- } else if (hasCatch) {
803
- if (this.prev < entry.catchLoc) {
804
- return handle(entry.catchLoc, true);
805
- }
806
-
807
- } else if (hasFinally) {
808
- if (this.prev < entry.finallyLoc) {
809
- return handle(entry.finallyLoc);
810
- }
811
-
812
- } else {
813
- throw new Error("try statement without catch or finally");
814
- }
815
- }
816
- }
817
- },
818
-
819
- abrupt: function(type, arg) {
820
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
821
- var entry = this.tryEntries[i];
822
- if (entry.tryLoc <= this.prev &&
823
- hasOwn.call(entry, "finallyLoc") &&
824
- this.prev < entry.finallyLoc) {
825
- var finallyEntry = entry;
826
- break;
827
- }
828
- }
829
-
830
- if (finallyEntry &&
831
- (type === "break" ||
832
- type === "continue") &&
833
- finallyEntry.tryLoc <= arg &&
834
- arg <= finallyEntry.finallyLoc) {
835
- // Ignore the finally entry if control is not jumping to a
836
- // location outside the try/catch block.
837
- finallyEntry = null;
838
- }
839
-
840
- var record = finallyEntry ? finallyEntry.completion : {};
841
- record.type = type;
842
- record.arg = arg;
843
-
844
- if (finallyEntry) {
845
- this.method = "next";
846
- this.next = finallyEntry.finallyLoc;
847
- return ContinueSentinel;
848
- }
849
-
850
- return this.complete(record);
851
- },
852
-
853
- complete: function(record, afterLoc) {
854
- if (record.type === "throw") {
855
- throw record.arg;
856
- }
857
-
858
- if (record.type === "break" ||
859
- record.type === "continue") {
860
- this.next = record.arg;
861
- } else if (record.type === "return") {
862
- this.rval = this.arg = record.arg;
863
- this.method = "return";
864
- this.next = "end";
865
- } else if (record.type === "normal" && afterLoc) {
866
- this.next = afterLoc;
867
- }
868
-
869
- return ContinueSentinel;
870
- },
871
-
872
- finish: function(finallyLoc) {
873
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
874
- var entry = this.tryEntries[i];
875
- if (entry.finallyLoc === finallyLoc) {
876
- this.complete(entry.completion, entry.afterLoc);
877
- resetTryEntry(entry);
878
- return ContinueSentinel;
879
- }
880
- }
881
- },
882
-
883
- "catch": function(tryLoc) {
884
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
885
- var entry = this.tryEntries[i];
886
- if (entry.tryLoc === tryLoc) {
887
- var record = entry.completion;
888
- if (record.type === "throw") {
889
- var thrown = record.arg;
890
- resetTryEntry(entry);
891
- }
892
- return thrown;
893
- }
894
- }
895
-
896
- // The context.catch method must only be called with a location
897
- // argument that corresponds to a known catch block.
898
- throw new Error("illegal catch attempt");
899
- },
900
-
901
- delegateYield: function(iterable, resultName, nextLoc) {
902
- this.delegate = {
903
- iterator: values(iterable),
904
- resultName: resultName,
905
- nextLoc: nextLoc
906
- };
907
-
908
- if (this.method === "next") {
909
- // Deliberately forget the last sent value so that we don't
910
- // accidentally pass it on to the delegate.
911
- this.arg = undefined$1;
912
- }
913
-
914
- return ContinueSentinel;
915
- }
916
- };
917
-
918
- // Regardless of whether this script is executing as a CommonJS module
919
- // or not, return the runtime object so that we can declare the variable
920
- // regeneratorRuntime in the outer scope, which allows this module to be
921
- // injected easily by `bin/regenerator --include-runtime script.js`.
922
- return exports;
923
-
924
- }(
925
- // If this script is executing as a CommonJS module, use module.exports
926
- // as the regeneratorRuntime namespace. Otherwise create a new empty
927
- // object. Either way, the resulting object will be used to initialize
928
- // the regeneratorRuntime variable at the top of this file.
929
- module.exports
930
- ));
931
-
932
- try {
933
- regeneratorRuntime = runtime;
934
- } catch (accidentalStrictMode) {
935
- // This module should not be running in strict mode, so the above
936
- // assignment should always work unless something is misconfigured. Just
937
- // in case runtime.js accidentally runs in strict mode, in modern engines
938
- // we can explicitly access globalThis. In older engines we can escape
939
- // strict mode using a global Function call. This could conceivably fail
940
- // if a Content Security Policy forbids using Function, but in that case
941
- // the proper solution is to fix the accidental strict mode problem. If
942
- // you've misconfigured your bundler to force strict mode and applied a
943
- // CSP to forbid Function, and you're not willing to fix either of those
944
- // problems, please detail your unique predicament in a GitHub issue.
945
- if (typeof globalThis === "object") {
946
- globalThis.regeneratorRuntime = runtime;
947
- } else {
948
- Function("r", "regeneratorRuntime = r")(runtime);
949
- }
950
- }
951
- });
952
-
953
- var handleResponse = function handleResponse(fn, props) {
954
- return function () {
955
- var result = fn.apply(void 0, arguments);
956
-
957
- if (result != null && result.then) {
958
- return result.then(function (res) {
959
- var _res$data, _res$data3, _res$data3$id;
960
-
961
- if (res != null && (_res$data = res.data) != null && _res$data.member) {
962
- var _res$data2;
963
-
964
- setPersistedMember((_res$data2 = res.data) == null ? void 0 : _res$data2.member, props.persistence);
965
- }
966
-
967
- if (res != null && (_res$data3 = res.data) != null && (_res$data3$id = _res$data3.id) != null && _res$data3$id.startsWith("mem_")) {
968
- setPersistedMember(res.data, props.persistence);
969
- }
970
-
971
- return res;
972
- });
973
- }
974
-
975
- return result;
976
- };
977
- };
978
-
979
- var handler = function handler(props) {
980
- return {
981
- get: function get(target, prop, receiver) {
982
- if (prop === "getCurrentMember") {
983
- var persistedMember = getPersistedMember(props.persistence);
984
-
985
- if (persistedMember) {
986
- return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
987
- return runtime_1.wrap(function _callee$(_context) {
988
- while (1) {
989
- switch (_context.prev = _context.next) {
990
- case 0:
991
- return _context.abrupt("return", {
992
- data: persistedMember
993
- });
994
-
995
- case 1:
996
- case "end":
997
- return _context.stop();
998
- }
999
- }
1000
- }, _callee);
1001
- }));
1002
- }
1003
- }
1004
-
1005
- return handleResponse(Reflect.get(target, prop, receiver), props);
1006
- }
1007
- };
1008
- };
1009
-
1010
- var Proxy$1 = (function (target, props) {
1011
- return new Proxy(target, handler(props));
1012
- });
1013
-
1014
- var Window = {
1015
- MSDOM: "__MSDOM",
1016
- APP_ID: "__MS-APPID"
1017
- };
1018
-
1019
- var endpoints = {
1020
- parentOrigin: "https://ui.memberstack.com",
1021
- loaderScript: "https://ui.memberstack.com/loader.cjs.production.min.js"
1022
- };
1023
-
1024
- var MemberCookies;
1025
-
1026
- (function (MemberCookies) {
1027
- MemberCookies["AUTH"] = "_ms-mid";
1028
- })(MemberCookies || (MemberCookies = {}));
1029
-
1030
- var setMemberCookie = function setMemberCookie(token, expires) {
1031
- Cookie.set(MemberCookies.AUTH, token, {
1032
- expires: expires || new Date(Date.now() + 604800000),
1033
- sameSite: "strict"
1034
- });
1035
- };
1036
- var getMemberCookie = function getMemberCookie() {
1037
- return Cookie.get(MemberCookies.AUTH);
1038
- };
1039
-
1040
- var isBrowser = typeof window !== "undefined";
1041
-
1042
- var isInitialized = function isInitialized() {
1043
- var _window;
1044
-
1045
- if (!isBrowser) return;
1046
-
1047
- if (!((_window = window) != null && _window[Window.MSDOM])) {
1048
- console.warn("Memberstack has not been initialized yet.");
1049
- return false;
1050
- }
1051
-
1052
- return true;
1053
- };
1054
-
1055
- var hasIFrame = function hasIFrame() {
1056
- var initialized = isInitialized();
1057
- if (!initialized) return false;
1058
- var iframe = document.querySelector("iframe[id=\"_ms-iframe\"]");
1059
-
1060
- if (!iframe) {
1061
- console.warn("iFrame has not been loaded yet.");
1062
- return false;
1063
- }
1064
-
1065
- return true;
1066
- };
1067
-
1068
- var load = function load(props) {
1069
- if (isInitialized()) {
1070
- var _window$Window$MSDOM;
1071
-
1072
- (_window$Window$MSDOM = window[Window.MSDOM]) == null ? void 0 : _window$Window$MSDOM.load({
1073
- publicKey: props.publicKey
1074
- });
1075
- }
1076
- };
1077
- var openModal = function openModal(props) {
1078
- if (hasIFrame()) {
1079
- var _window$Window$MSDOM2;
1080
-
1081
- (_window$Window$MSDOM2 = window[Window.MSDOM]) == null ? void 0 : _window$Window$MSDOM2.show(props.type, props.params);
1082
- window.addEventListener("message", function (e) {
1083
- if (e.origin === endpoints.parentOrigin) {
1084
- var _e$data, _e$data$data, _e$data3, _e$data3$data, _e$data3$data$tokens, _props$options, _e$data4;
1085
-
1086
- if (e.data.type === "CLOSE") {
1087
- return hideModal();
1088
- }
1089
-
1090
- if ((_e$data = e.data) != null && (_e$data$data = _e$data.data) != null && _e$data$data.member) {
1091
- var _e$data2;
1092
-
1093
- setPersistedMember((_e$data2 = e.data) == null ? void 0 : _e$data2.data.member, props.persistence);
1094
- }
1095
-
1096
- if (props.useCookie && (_e$data3 = e.data) != null && (_e$data3$data = _e$data3.data) != null && (_e$data3$data$tokens = _e$data3$data.tokens) != null && _e$data3$data$tokens.accessToken) {
1097
- setMemberCookie(e.data.data.tokens.accessToken);
1098
- }
1099
-
1100
- (_props$options = props.options) == null ? void 0 : _props$options.onCompleted == null ? void 0 : _props$options.onCompleted((_e$data4 = e.data) == null ? void 0 : _e$data4.data);
1101
- }
1102
- });
1103
- }
1104
- };
1105
- var hideModal = function hideModal() {
1106
- if (hasIFrame()) {
1107
- var _window$Window$MSDOM3;
1108
-
1109
- (_window$Window$MSDOM3 = window[Window.MSDOM]) == null ? void 0 : _window$Window$MSDOM3.hide();
1110
- }
1111
- };
1112
-
1113
- var isBrowser$1 = typeof window !== "undefined";
1114
- var SCRIPT_URL = endpoints.loaderScript;
1115
- var SCRIPT_URL_REGEX = /*#__PURE__*/new RegExp(SCRIPT_URL);
1116
-
1117
- var getScript = function getScript() {
1118
- var existingScript = document.querySelector("script[src^=\"" + SCRIPT_URL + "\"]");
1119
-
1120
- if (existingScript && SCRIPT_URL_REGEX.test(existingScript.src)) {
1121
- return existingScript;
1122
- }
1123
-
1124
- var script = document.createElement("script");
1125
- script.src = SCRIPT_URL;
1126
- script.defer = true;
1127
- script.crossOrigin = "true";
1128
-
1129
- if (!document.body) {
1130
- throw new Error("Memberstack requires a <body> element.");
1131
- }
1132
-
1133
- document.body.appendChild(script);
1134
- return script;
1135
- };
1136
-
1137
- function initialize(_x) {
1138
- return _initialize.apply(this, arguments);
1139
- }
1140
-
1141
- function _initialize() {
1142
- _initialize = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(props) {
1143
- var script;
1144
- return runtime_1.wrap(function _callee$(_context) {
1145
- while (1) {
1146
- switch (_context.prev = _context.next) {
1147
- case 0:
1148
- if (isBrowser$1) {
1149
- _context.next = 2;
1150
- break;
1151
- }
1152
-
1153
- return _context.abrupt("return", null);
1154
-
1155
- case 2:
1156
- script = getScript();
1157
- script.addEventListener("load", function () {
1158
- if (window[Window.MSDOM]) {
1159
- window[Window.MSDOM].load({
1160
- publicKey: props.publicKey
1161
- });
1162
- console.info("\x1b[36m%s\x1b[0m", "Memberstack has been initialized.");
1163
- } else {
1164
- console.warn("Could not initialize Memberstack.");
1165
- }
1166
- });
1167
-
1168
- case 4:
1169
- case "end":
1170
- return _context.stop();
1171
- }
1172
- }
1173
- }, _callee);
1174
- }));
1175
- return _initialize.apply(this, arguments);
1176
- }
1177
-
1178
- var initClient = function initClient(props) {
1179
- return msClient.init(_extends({
1180
- token: getMemberCookie()
1181
- }, props));
1182
- };
1183
-
1184
- var interceptor = /*#__PURE__*/new RequestInterceptor(withDefaultInterceptors);
1185
- var initializeInterceptors = function initializeInterceptors(_ref) {
1186
- var persistence = _ref.persistence;
1187
- interceptor.on("response", function (req, response) {
1188
- if (response != null && response.headers["ms-mid"]) {
1189
- if ((response == null ? void 0 : response.headers["ms-mid"]) === "null") {
1190
- setMemberCookie("", -1);
1191
-
1192
- if (getPersistedMember(persistence)) {
1193
- unsetPersistedMember(persistence);
1194
- }
1195
- } else {
1196
- setMemberCookie(response.headers["ms-mid"]);
1197
- }
1198
- }
1199
- });
1200
- };
1201
-
1202
- var _excluded = ["useCookie", "persistence"];
1203
-
1204
- var DOMMethods = function DOMMethods(_ref) {
1205
- var _ref$useCookie = _ref.useCookie,
1206
- useCookie = _ref$useCookie === void 0 ? true : _ref$useCookie,
1207
- _ref$persistence = _ref.persistence,
1208
- persistence = _ref$persistence === void 0 ? Persistence.LOCAL : _ref$persistence,
1209
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
1210
-
1211
- return {
1212
- load: function load$1() {
1213
- return load({
1214
- publicKey: props.publicKey
1215
- });
1216
- },
1217
- hideModal: hideModal,
1218
- onAuthChange: onAuthChange,
1219
- openModal: function openModal$1(type, params, options) {
1220
- return openModal(_extends({
1221
- type: type,
1222
- params: params,
1223
- options: options,
1224
- useCookie: useCookie,
1225
- persistence: persistence
1226
- }, props));
1227
- }
1228
- };
1229
- };
1230
-
1231
- var withScript = function withScript(fn) {
1232
- return function (props) {
1233
- var config = _extends({
1234
- persistence: Persistence.LOCAL,
1235
- useCookie: true
1236
- }, props);
1237
-
1238
- initialize({
1239
- publicKey: props.publicKey
1240
- });
1241
- initializeInterceptors({
1242
- persistence: config.persistence
1243
- });
1244
- return fn(config);
1245
- };
1246
- };
1247
-
1248
- var init = /*#__PURE__*/withScript(function (props) {
1249
- var client = Proxy$1(initClient(props), props);
1250
- var methods = DOMMethods(props);
1251
- return Object.assign(client, methods);
1252
- });
1253
- var Methods = {
1254
- init: init
1255
- };
1256
-
1257
- export default Methods;
1258
- export { Persistence };
1259
- //# sourceMappingURL=dom.esm.js.map