1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports["default"] = void 0;
|
5 |
|
6 | var Cookies = _interopRequireWildcard(require("js-cookie"));
|
7 |
|
8 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
9 |
|
10 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
11 |
|
12 |
|
13 | var CookieStorage = function () {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function CookieStorage(data) {
|
24 | if (data.domain) {
|
25 | this.domain = data.domain;
|
26 | } else {
|
27 | throw new Error('The domain of cookieStorage can not be undefined.');
|
28 | }
|
29 |
|
30 | if (data.path) {
|
31 | this.path = data.path;
|
32 | } else {
|
33 | this.path = '/';
|
34 | }
|
35 |
|
36 | if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
|
37 | this.expires = data.expires;
|
38 | } else {
|
39 | this.expires = 365;
|
40 | }
|
41 |
|
42 | if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
|
43 | this.secure = data.secure;
|
44 | } else {
|
45 | this.secure = true;
|
46 | }
|
47 |
|
48 | if (Object.prototype.hasOwnProperty.call(data, 'sameSite')) {
|
49 | if (!['strict', 'lax', 'none'].includes(data.sameSite)) {
|
50 | throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');
|
51 | }
|
52 |
|
53 | if (data.sameSite === 'none' && !this.secure) {
|
54 | throw new Error('sameSite = None requires the Secure attribute in latest browser versions.');
|
55 | }
|
56 |
|
57 | this.sameSite = data.sameSite;
|
58 | } else {
|
59 | this.sameSite = null;
|
60 | }
|
61 | }
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | var _proto = CookieStorage.prototype;
|
71 |
|
72 | _proto.setItem = function setItem(key, value) {
|
73 | var options = {
|
74 | path: this.path,
|
75 | expires: this.expires,
|
76 | domain: this.domain,
|
77 | secure: this.secure
|
78 | };
|
79 |
|
80 | if (this.sameSite) {
|
81 | options.sameSite = this.sameSite;
|
82 | }
|
83 |
|
84 | Cookies.set(key, value, options);
|
85 | return Cookies.get(key);
|
86 | }
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | ;
|
94 |
|
95 | _proto.getItem = function getItem(key) {
|
96 | return Cookies.get(key);
|
97 | }
|
98 | |
99 |
|
100 |
|
101 |
|
102 |
|
103 | ;
|
104 |
|
105 | _proto.removeItem = function removeItem(key) {
|
106 | var options = {
|
107 | path: this.path,
|
108 | expires: this.expires,
|
109 | domain: this.domain,
|
110 | secure: this.secure
|
111 | };
|
112 |
|
113 | if (this.sameSite) {
|
114 | options.sameSite = this.sameSite;
|
115 | }
|
116 |
|
117 | return Cookies.remove(key, options);
|
118 | }
|
119 | |
120 |
|
121 |
|
122 |
|
123 | ;
|
124 |
|
125 | _proto.clear = function clear() {
|
126 | var cookies = Cookies.get();
|
127 | var index;
|
128 |
|
129 | for (index = 0; index < cookies.length; ++index) {
|
130 | Cookies.remove(cookies[index]);
|
131 | }
|
132 |
|
133 | return {};
|
134 | };
|
135 |
|
136 | return CookieStorage;
|
137 | }();
|
138 |
|
139 | exports["default"] = CookieStorage; |
\ | No newline at end of file |