@telia-ace/widget-services 1.0.1 → 1.0.5

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.
@@ -1,117 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- 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;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { lock, Logger } from '@telia-ace/widget-utilities';
38
- import { StorageCategory } from '.';
39
- import { StorageScope } from './types';
40
- import { createExpirationDate, createValue, getValue, processStore } from './utils';
41
- var LegacyStorage = /** @class */ (function () {
42
- function LegacyStorage() {
43
- this.memory = {
44
- tenant: {},
45
- implementation: {},
46
- widget: {},
47
- };
48
- }
49
- LegacyStorage.prototype.setItem = function (key, value, options) {
50
- if (options === void 0) { options = {}; }
51
- return __awaiter(this, void 0, void 0, function () {
52
- var _this = this;
53
- return __generator(this, function (_a) {
54
- return [2 /*return*/, lock(this)(function () {
55
- var processedStore = processStore(_this.memory, [StorageCategory.Necessary]);
56
- var _a = options.scope, scope = _a === void 0 ? StorageScope.Tenant : _a, expiration = options.expiration;
57
- processedStore[scope][key] = createValue(value, StorageCategory.Necessary, (expiration === null || expiration === void 0 ? void 0 : expiration.toISOString()) || createExpirationDate());
58
- _this.memory = processedStore;
59
- if (process.env.NODE_ENV !== 'production') {
60
- Logger.warn("StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value stored temporarily in memory.\n Key: ".concat(key, "\n Value: ").concat(JSON.stringify(value), "\n Options: ").concat(JSON.stringify(options), "\n Memory: ").concat(JSON.stringify(processedStore)));
61
- }
62
- })];
63
- });
64
- });
65
- };
66
- LegacyStorage.prototype.getItem = function (key) {
67
- return __awaiter(this, void 0, void 0, function () {
68
- var _this = this;
69
- return __generator(this, function (_a) {
70
- return [2 /*return*/, lock(this)(function () {
71
- var processedStore = processStore(_this.memory, [StorageCategory.Necessary]);
72
- if (process.env.NODE_ENV !== 'production') {
73
- Logger.warn("StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value fetched from legacy memory storage.\n Key: ".concat(key, "\n Memory: ").concat(JSON.stringify(processedStore)));
74
- }
75
- var value = getValue(processedStore, key);
76
- _this.memory = processedStore;
77
- return value;
78
- })];
79
- });
80
- });
81
- };
82
- LegacyStorage.prototype.removeItem = function (key) {
83
- return __awaiter(this, void 0, void 0, function () {
84
- var _this = this;
85
- return __generator(this, function (_a) {
86
- return [2 /*return*/, lock(this)(function () {
87
- var processedStore = processStore(_this.memory, [StorageCategory.Necessary]);
88
- delete processedStore.tenant[key];
89
- delete processedStore.implementation[key];
90
- delete processedStore.widget[key];
91
- _this.memory = processedStore;
92
- if (process.env.NODE_ENV !== 'production') {
93
- Logger.warn("StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value removed from memory.\n Key: ".concat(key, "\n Memory: ").concat(JSON.stringify(processedStore)));
94
- }
95
- })];
96
- });
97
- });
98
- };
99
- LegacyStorage.prototype.clear = function () {
100
- return __awaiter(this, void 0, void 0, function () {
101
- return __generator(this, function (_a) {
102
- return [2 /*return*/, Promise.resolve()];
103
- });
104
- });
105
- };
106
- return LegacyStorage;
107
- }());
108
- export { LegacyStorage };
109
- var LegacyStorageProvider = /** @class */ (function () {
110
- function LegacyStorageProvider() {
111
- this.cookies = new LegacyStorage();
112
- this.session = new LegacyStorage();
113
- this.local = new LegacyStorage();
114
- }
115
- return LegacyStorageProvider;
116
- }());
117
- export default LegacyStorageProvider;
@@ -1,71 +0,0 @@
1
- import { Logger } from '@telia-ace/widget-utilities';
2
- import { createConfigurationApi } from '@webprovisions/platform';
3
- import { createStorageWriter } from './storage';
4
- import { StorageCategory, StorageMedium, StorageScope } from './types';
5
- import { processStorage } from './utils';
6
- export default createConfigurationApi(function (builder) {
7
- builder.createCommand('storage', function (context) { return function (options) {
8
- if (options === void 0) { options = {}; }
9
- var consent = options.consent;
10
- if (typeof consent !== 'undefined') {
11
- if (typeof consent !== 'number' &&
12
- typeof consent !== 'string' &&
13
- !Array.isArray(consent)) {
14
- if (process.env.NODE_ENV !== 'production') {
15
- Logger.warn("storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.\n Passed consent: ".concat(JSON.stringify(consent)));
16
- }
17
- return;
18
- }
19
- if (Array.isArray(consent) &&
20
- !consent.every(function (c) { return typeof c === 'number' || typeof c === 'string'; })) {
21
- if (process.env.NODE_ENV !== 'production') {
22
- Logger.warn("storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.\n Passed consent: ".concat(JSON.stringify(consent)));
23
- }
24
- return;
25
- }
26
- var policy_1 = [
27
- StorageCategory.Necessary,
28
- StorageCategory.Functional,
29
- StorageCategory.Analytical,
30
- StorageCategory.Marketing,
31
- ].filter(function (category, index, array) {
32
- if (typeof consent === 'number') {
33
- // Passed consent is a category level (number)
34
- // Include the passed category level and all categories below it
35
- return consent > index;
36
- }
37
- else if (typeof consent === 'string') {
38
- // Passed consent is a category (string)
39
- // Include the passed category and all categories below its level
40
- return array.indexOf(consent) + 1 > index;
41
- }
42
- else if (Array.isArray(consent)) {
43
- // Passed consent is an array with category levels (number), categories (string) or both
44
- // Include all categories in passed array
45
- return (consent.findIndex(function (c) {
46
- return c === index + 1 || c === category;
47
- }) > -1);
48
- }
49
- else {
50
- return true;
51
- }
52
- });
53
- if (policy_1.indexOf(StorageCategory.Necessary) === -1) {
54
- if (process.env.NODE_ENV !== 'production') {
55
- Logger.warn("storagePolicyConfigurationApi: passed consent does not include category: '".concat(StorageCategory.Necessary, "'. Consent has to atleast include the '").concat(StorageCategory.Necessary, "' category.\n Passed consent: ").concat(JSON.stringify(consent)));
56
- }
57
- policy_1.unshift(StorageCategory.Necessary);
58
- }
59
- return createStorageWriter(context.container, 'storagePolicy', StorageCategory.Necessary, {
60
- medium: StorageMedium.Cookie,
61
- scope: StorageScope.Tenant,
62
- duration: { days: 365 },
63
- })
64
- .then(function (write) { return write(policy_1); })
65
- .then(function () {
66
- processStorage(context.container);
67
- context.events.dispatch('storage:policy-changed', policy_1);
68
- });
69
- }
70
- }; });
71
- });
@@ -1,60 +0,0 @@
1
- import { Logger } from '@telia-ace/widget-utilities';
2
- import { StorageMedium, StorageScope, } from './types';
3
- import { createEmptyStore, createValue, getApplicationStoreAsync, getCookieStoreAsync, getValue, isNotAllowedAsync, processStorage, setApplicationStoreAsync, setCookieStoreAsync, } from './utils';
4
- /**
5
- * Creates a writer to be used to write to cookie, local or session storage.
6
- * @param container Widget Container.
7
- * @param key Key to use when writing.
8
- * @param category StorageCategory to use when writing.
9
- * @param options StorageWriterOptions to use when writing default {scope: StorageScope.Widget, medium = StorageMedium.Session, duration = {days: 30}}.
10
- * @returns a function to be used to write a value to the storage using given settings.
11
- */
12
- export var createStorageWriter = function (container, key, category, options) {
13
- if (options === void 0) { options = {}; }
14
- return isNotAllowedAsync(container, category).then(function (notAllowed) {
15
- if (process.env.NODE_ENV !== 'production') {
16
- if (notAllowed) {
17
- Logger.warn("createStorageWriter: Attempted to create storage writer using unallowed category.\n Key: ".concat(key, "\n Category: ").concat(JSON.stringify(category), "\n Options: ").concat(JSON.stringify(options)));
18
- }
19
- }
20
- return function (value) {
21
- processStorage(container);
22
- return isNotAllowedAsync(container, category).then(function (notAllowed) {
23
- if (notAllowed) {
24
- if (process.env.NODE_ENV !== 'production') {
25
- Logger.warn("storageWriter: Attempted to write to storage using unallowed category.\n Key: ".concat(key, "\n Category: ").concat(JSON.stringify(category), "\n Value: ").concat(JSON.stringify(value), "\n Options: ").concat(JSON.stringify(options)));
26
- }
27
- return;
28
- }
29
- var _a = options.scope, scope = _a === void 0 ? StorageScope.Widget : _a, _b = options.medium, medium = _b === void 0 ? StorageMedium.Session : _b, _c = options.duration, duration = _c === void 0 ? { days: 30 } : _c;
30
- var store = createEmptyStore();
31
- store[scope][key] = createValue(value, category, duration);
32
- if (medium === StorageMedium.Cookie)
33
- return setCookieStoreAsync(container, store);
34
- else
35
- return setApplicationStoreAsync(container, medium, store);
36
- });
37
- };
38
- });
39
- };
40
- /**
41
- * Read the widget cookie, local or session storage.
42
- * @param container Widget Container.
43
- * @param key Key to read.
44
- * @param medium Storage medium to read from (default: session).
45
- * @returns the value stored with passed key.
46
- */
47
- export var readStorage = function (container, key, medium) {
48
- if (medium === void 0) { medium = StorageMedium.Session; }
49
- processStorage(container);
50
- if (typeof key === 'undefined') {
51
- if (process.env.NODE_ENV !== 'production') {
52
- Logger.warn('readStorage: Undefined key passed when reading storage. ', key, medium);
53
- }
54
- return Promise.resolve(undefined);
55
- }
56
- if (medium === StorageMedium.Cookie)
57
- return getCookieStoreAsync(container).then(function (store) { return getValue(store, key); });
58
- else
59
- return getApplicationStoreAsync(container, medium).then(function (store) { return getValue(store, key); });
60
- };
@@ -1,19 +0,0 @@
1
- export var StorageMedium;
2
- (function (StorageMedium) {
3
- StorageMedium["Cookie"] = "cookie";
4
- StorageMedium["Local"] = "local";
5
- StorageMedium["Session"] = "session";
6
- })(StorageMedium || (StorageMedium = {}));
7
- export var StorageScope;
8
- (function (StorageScope) {
9
- StorageScope["Tenant"] = "tenant";
10
- StorageScope["Implementation"] = "implementation";
11
- StorageScope["Widget"] = "widget";
12
- })(StorageScope || (StorageScope = {}));
13
- export var StorageCategory;
14
- (function (StorageCategory) {
15
- StorageCategory["Necessary"] = "necessary";
16
- StorageCategory["Functional"] = "functional";
17
- StorageCategory["Analytical"] = "analytical";
18
- StorageCategory["Marketing"] = "marketing";
19
- })(StorageCategory || (StorageCategory = {}));
@@ -1,36 +0,0 @@
1
- import { Container } from '@webprovisions/platform';
2
- import { Duration, StorageCategory, StorageMedium, Store, StoredValue } from './types';
3
- export declare const createEmptyStore: () => Store;
4
- export declare const isExpired: (isoDateString: string) => boolean;
5
- export declare const getValue: <Type>(store: Store, key: string) => Type | undefined;
6
- export declare const createValue: (value: any, category: StorageCategory, duration: Duration | string) => StoredValue;
7
- export declare const processStore: (store: Store, policy?: StorageCategory[] | undefined) => Store;
8
- /**
9
- * @param category Storage Category.
10
- * @param policy Current Storage Policy.
11
- * @returns true if not allowed, false if allowed.
12
- */
13
- export declare const isNotAllowedAsync: (container: Container, category?: StorageCategory | undefined) => Promise<boolean>;
14
- /**
15
- * @param category Storage Category.
16
- * @param policy Current Storage Policy.
17
- * @returns true if not allowed, false if allowed.
18
- */
19
- export declare const isNotAllowed: (policy?: StorageCategory[], category?: StorageCategory | undefined) => boolean;
20
- /**
21
- * Processes storage and removes items if they are expired or if
22
- * the storage policy is defined and the category of the stored
23
- * value is not allowed.
24
- * @param container Widget Container
25
- */
26
- export declare const processStorage: (container: Container) => void;
27
- /**
28
- * Creates an expiration date string with the passed options.
29
- * @param options Duration options.
30
- * @returns ISO formatted date string.
31
- */
32
- export declare const createExpirationDate: (options?: Duration) => string;
33
- export declare const getCookieStoreAsync: (container: Container) => Promise<Store>;
34
- export declare const setCookieStoreAsync: (container: Container, store: Store) => Promise<any>;
35
- export declare const getApplicationStoreAsync: (container: Container, type: StorageMedium.Local | StorageMedium.Session) => Promise<Store>;
36
- export declare const setApplicationStoreAsync: (container: Container, type: StorageMedium.Local | StorageMedium.Session, store: Store) => Promise<void>;
@@ -1,224 +0,0 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
10
- try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
- import { deepClone, hash, lock, mergeDeep } from '@telia-ace/widget-utilities';
18
- import { readStorage } from './storage';
19
- import { StorageCategory, StorageMedium, } from './types';
20
- var hasEntries = function (object) {
21
- return !!Object.entries(object).filter(function (_a) {
22
- var _b = __read(_a, 2), _ = _b[0], value = _b[1];
23
- return typeof value !== 'undefined';
24
- }).length;
25
- };
26
- var cleanUndefined = function (object) {
27
- return Object.entries(object)
28
- .filter(function (_a) {
29
- var _b = __read(_a, 2), _ = _b[0], value = _b[1];
30
- return typeof value !== 'undefined';
31
- })
32
- .forEach(function (_a) {
33
- var _b = __read(_a, 2), key = _b[0], value = _b[1].value;
34
- if (typeof value === 'undefined') {
35
- delete object[key];
36
- }
37
- });
38
- };
39
- var mergeAndClean = function (target, source) {
40
- var merged = mergeDeep(target, source);
41
- cleanUndefined(merged.tenant);
42
- cleanUndefined(merged.implementation);
43
- cleanUndefined(merged.widget);
44
- return merged;
45
- };
46
- var getLongestExpirationDate = function (store) {
47
- var expirationDates = Object.entries(store).reduce(function (acc, storeEntry) {
48
- var _a = __read(storeEntry, 2), _ = _a[0], container = _a[1];
49
- Object.entries(container).forEach(function (containerEntry) {
50
- var _a = __read(containerEntry, 2), _ = _a[0], expiration = _a[1].expiration;
51
- acc.push(expiration);
52
- });
53
- return acc;
54
- }, []);
55
- return (expirationDates
56
- .slice()
57
- .sort(function (a, b) { return new Date(b).valueOf() - new Date(a).valueOf(); })
58
- .shift() || createExpirationDate());
59
- };
60
- var createStorageKeys = function (container) {
61
- var _a = container.get('$widget'), widgetName = _a.name, _b = _a.implementation, implementationName = _b.name, tenantName = _b.tenant;
62
- return [
63
- "humany_".concat(tenantName),
64
- "humany_".concat(hash(tenantName + implementationName)),
65
- "humany_".concat(hash(tenantName + implementationName + widgetName)),
66
- ];
67
- };
68
- var getCookie = function (cookieName) {
69
- var regExp = new RegExp("(?:^|;)\\s?".concat(cookieName, "=(.*?)(?:;|$)"), 'i');
70
- var cookie = document.cookie.match(regExp);
71
- var value = cookie && cookie[1] && JSON.parse(cookie[1]);
72
- return value || undefined;
73
- };
74
- var setCookie = function (cookieName, value, expires) {
75
- var cookie = "".concat(cookieName, "=").concat(JSON.stringify(value).trim(), ";");
76
- var expiration = "expires=".concat(new Date(expires).toUTCString(), ";");
77
- var path = 'path=/';
78
- return (document.cookie = "".concat(cookie, " ").concat(expiration, " ").concat(path));
79
- };
80
- var getCookieStore = function (container) {
81
- var _a = __read(createStorageKeys(container), 3), tenantKey = _a[0], implementationKey = _a[1], widgetKey = _a[2];
82
- var tenant = getCookie(tenantKey) || {};
83
- var implementation = getCookie(implementationKey) || {};
84
- var widget = getCookie(widgetKey) || {};
85
- return {
86
- tenant: tenant,
87
- implementation: implementation,
88
- widget: widget,
89
- };
90
- };
91
- var setCookieStore = function (container, store) {
92
- var current = getCookieStore(container);
93
- var merged = mergeAndClean(current, store);
94
- var _a = __read(createStorageKeys(container), 3), tenantKey = _a[0], implementationKey = _a[1], widgetKey = _a[2];
95
- var tenant = merged.tenant, implementation = merged.implementation, widget = merged.widget;
96
- var expirationDate = getLongestExpirationDate(store);
97
- var deleteDate = createExpirationDate({ days: -1 });
98
- setCookie(tenantKey, tenant, hasEntries(tenant) ? expirationDate : deleteDate);
99
- setCookie(implementationKey, implementation, hasEntries(implementation) ? expirationDate : deleteDate);
100
- setCookie(widgetKey, widget, hasEntries(widget) ? expirationDate : deleteDate);
101
- };
102
- var getApplicationStore = function (container, storage) {
103
- var _a = __read(createStorageKeys(container), 3), tenantKey = _a[0], implementationKey = _a[1], widgetKey = _a[2];
104
- var tenant = storage.getItem(tenantKey) || '{}';
105
- var implementation = storage.getItem(implementationKey) || '{}';
106
- var widget = storage.getItem(widgetKey) || '{}';
107
- return {
108
- tenant: JSON.parse(tenant),
109
- implementation: JSON.parse(implementation),
110
- widget: JSON.parse(widget),
111
- };
112
- };
113
- var setApplicationStore = function (container, applicationStorage, store) {
114
- var current = getApplicationStore(container, applicationStorage);
115
- var merged = mergeAndClean(current, store);
116
- var _a = __read(createStorageKeys(container), 3), tenantKey = _a[0], implementationKey = _a[1], widgetKey = _a[2];
117
- var tenant = merged.tenant, implementation = merged.implementation, widget = merged.widget;
118
- hasEntries(tenant)
119
- ? applicationStorage.setItem(tenantKey, JSON.stringify(tenant))
120
- : applicationStorage.removeItem(tenantKey);
121
- hasEntries(implementation)
122
- ? applicationStorage.setItem(implementationKey, JSON.stringify(implementation))
123
- : applicationStorage.removeItem(implementationKey);
124
- hasEntries(widget)
125
- ? applicationStorage.setItem(widgetKey, JSON.stringify(widget))
126
- : applicationStorage.removeItem(widgetKey);
127
- };
128
- export var createEmptyStore = function () { return ({ tenant: {}, implementation: {}, widget: {} }); };
129
- export var isExpired = function (isoDateString) {
130
- return !!isoDateString && new Date() > new Date(isoDateString);
131
- };
132
- export var getValue = function (store, key) {
133
- var storedValue = store.widget[key] || store.implementation[key] || store.tenant[key];
134
- return storedValue === null || storedValue === void 0 ? void 0 : storedValue.value;
135
- };
136
- export var createValue = function (value, category, duration) {
137
- return {
138
- value: value,
139
- category: category,
140
- expiration: typeof duration === 'object' ? createExpirationDate(duration) : duration,
141
- };
142
- };
143
- export var processStore = function (store, policy) {
144
- var clone = deepClone(store);
145
- Object.entries(clone).forEach(function (_a) {
146
- var _b = __read(_a, 2), _ = _b[0], storageContainer = _b[1];
147
- Object.entries(storageContainer).forEach(function (_a) {
148
- var _b = __read(_a, 2), key = _b[0], storedValue = _b[1];
149
- var expiration = storedValue.expiration, category = storedValue.category;
150
- if (isExpired(expiration) || isNotAllowed(policy, category))
151
- storageContainer[key] = createValue(undefined, category, expiration);
152
- });
153
- });
154
- return clone;
155
- };
156
- /**
157
- * @param category Storage Category.
158
- * @param policy Current Storage Policy.
159
- * @returns true if not allowed, false if allowed.
160
- */
161
- export var isNotAllowedAsync = function (container, category) {
162
- return readStorage(container, 'storagePolicy', StorageMedium.Cookie).then(function (policy) {
163
- if (policy === void 0) { policy = [StorageCategory.Necessary]; }
164
- return !!category && policy.indexOf(category) === -1;
165
- });
166
- };
167
- /**
168
- * @param category Storage Category.
169
- * @param policy Current Storage Policy.
170
- * @returns true if not allowed, false if allowed.
171
- */
172
- export var isNotAllowed = function (policy, category) {
173
- if (policy === void 0) { policy = [StorageCategory.Necessary]; }
174
- return !!category && policy.indexOf(category) === -1;
175
- };
176
- /**
177
- * Processes storage and removes items if they are expired or if
178
- * the storage policy is defined and the category of the stored
179
- * value is not allowed.
180
- * @param container Widget Container
181
- */
182
- export var processStorage = function (container) {
183
- var cookieStore = getCookieStore(container);
184
- var localStore = getApplicationStore(container, window.localStorage);
185
- var sessionStore = getApplicationStore(container, sessionStorage);
186
- var policy = getValue(cookieStore, 'storagePolicy');
187
- var _a = __read([
188
- cookieStore,
189
- localStore,
190
- sessionStore,
191
- ].map(function (store) { return processStore(store, policy); }), 3), processedCookieStore = _a[0], processedLocalStore = _a[1], processedSessionStore = _a[2];
192
- setCookieStore(container, processedCookieStore);
193
- setApplicationStore(container, window.localStorage, processedLocalStore);
194
- setApplicationStore(container, window.sessionStorage, processedSessionStore);
195
- };
196
- /**
197
- * Creates an expiration date string with the passed options.
198
- * @param options Duration options.
199
- * @returns ISO formatted date string.
200
- */
201
- export var createExpirationDate = function (options) {
202
- if (options === void 0) { options = { days: 30 }; }
203
- var _a = options.days, days = _a === void 0 ? 0 : _a, _b = options.hours, hours = _b === void 0 ? 0 : _b, _c = options.minutes, minutes = _c === void 0 ? 0 : _c, _d = options.seconds, seconds = _d === void 0 ? 0 : _d;
204
- var date = new Date();
205
- date.setTime(date.getTime() + hours * 60 * 60 * 1000);
206
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
207
- date.setTime(date.getTime() + minutes * 60 * 1000);
208
- date.setTime(date.getTime() + seconds * 1000);
209
- return date.toISOString();
210
- };
211
- export var getCookieStoreAsync = function (container) {
212
- return lock(document)(function () { return getCookieStore(container); });
213
- };
214
- export var setCookieStoreAsync = function (container, store) {
215
- return lock(document)(function () { return setCookieStore(container, store); });
216
- };
217
- export var getApplicationStoreAsync = function (container, type) {
218
- var storage = type === StorageMedium.Local ? window.localStorage : window.sessionStorage;
219
- return lock(storage)(function () { return getApplicationStore(container, storage); });
220
- };
221
- export var setApplicationStoreAsync = function (container, type, store) {
222
- var storage = type === StorageMedium.Local ? window.localStorage : window.sessionStorage;
223
- return lock(storage)(function () { return setApplicationStore(container, storage, store); });
224
- };