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