@telia-ace/widget-services 1.0.1 → 1.0.2

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 CHANGED
@@ -1,6 +1,6 @@
1
- Copyright © 2021, Telia Company AB. All rights reserved.
2
-
3
- THIS PACKAGE AND CONTAINING SOFTWARE IS PART OF
4
- THE HUMANY SERVICE. BY USING THIS SOFTWARE YOU
5
- AGREE TO THE FOLLOWING TERMS AND CONDITIONS:
1
+ Copyright © 2021, Telia Company AB. All rights reserved.
2
+
3
+ THIS PACKAGE AND CONTAINING SOFTWARE IS PART OF
4
+ THE HUMANY SERVICE. BY USING THIS SOFTWARE YOU
5
+ AGREE TO THE FOLLOWING TERMS AND CONDITIONS:
6
6
  http://www.humany.com/legal
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # `@telia-ace/widget-services`
2
-
3
- Services for ACE Widgets.
1
+ # `@telia-ace/widget-services`
2
+
3
+ Services for ACE Widgets.
@@ -5,7 +5,7 @@ import { StorageCategory, StorageMedium, StorageWriter, StorageWriterOptions } f
5
5
  * @param container Widget Container.
6
6
  * @param key Key to use when writing.
7
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}}.
8
+ * @param options StorageWriterOptions to use when writing default {scope: StorageScope.Widget, medium = StorageMedium.Session, duration = infinite }.
9
9
  * @returns a function to be used to write a value to the storage using given settings.
10
10
  */
11
11
  export declare const createStorageWriter: (container: Container, key: string, category: StorageCategory, options?: StorageWriterOptions) => Promise<StorageWriter>;
@@ -9,7 +9,7 @@ var utils_1 = require("./utils");
9
9
  * @param container Widget Container.
10
10
  * @param key Key to use when writing.
11
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}}.
12
+ * @param options StorageWriterOptions to use when writing default {scope: StorageScope.Widget, medium = StorageMedium.Session, duration = infinite }.
13
13
  * @returns a function to be used to write a value to the storage using given settings.
14
14
  */
15
15
  var createStorageWriter = function (container, key, category, options) {
@@ -29,7 +29,7 @@ var createStorageWriter = function (container, key, category, options) {
29
29
  }
30
30
  return;
31
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;
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, duration = options.duration;
33
33
  var store = (0, utils_1.createEmptyStore)();
34
34
  store[scope][key] = (0, utils_1.createValue)(value, category, duration);
35
35
  if (medium === types_1.StorageMedium.Cookie)
@@ -18,7 +18,7 @@ export declare type StorageContainer = {
18
18
  };
19
19
  export declare type StoredValue = {
20
20
  value: any;
21
- expiration: string;
21
+ expiration?: string;
22
22
  category: StorageCategory;
23
23
  };
24
24
  export declare enum StorageCategory {
@@ -1,9 +1,9 @@
1
1
  import { Container } from '@webprovisions/platform';
2
2
  import { Duration, StorageCategory, StorageMedium, Store, StoredValue } from './types';
3
3
  export declare const createEmptyStore: () => Store;
4
- export declare const isExpired: (isoDateString: string) => boolean;
4
+ export declare const isExpired: (isoDateString?: string | undefined) => boolean;
5
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;
6
+ export declare const createValue: (value: any, category: StorageCategory, duration?: string | Duration | undefined) => StoredValue;
7
7
  export declare const processStore: (store: Store, policy?: StorageCategory[] | undefined) => Store;
8
8
  /**
9
9
  * @param category Storage Category.
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __read = (this && this.__read) || function (o, n) {
3
14
  var m = typeof Symbol === "function" && o[Symbol.iterator];
4
15
  if (!m) return o;
@@ -40,7 +51,11 @@ var cleanUndefined = function (object) {
40
51
  });
41
52
  };
42
53
  var mergeAndClean = function (target, source) {
43
- var merged = (0, widget_utilities_1.mergeDeep)(target, source);
54
+ var merged = {
55
+ tenant: __assign(__assign({}, target.tenant), source.tenant),
56
+ implementation: __assign(__assign({}, target.implementation), source.implementation),
57
+ widget: __assign(__assign({}, target.widget), source.widget)
58
+ };
44
59
  cleanUndefined(merged.tenant);
45
60
  cleanUndefined(merged.implementation);
46
61
  cleanUndefined(merged.widget);
@@ -51,7 +66,8 @@ var getLongestExpirationDate = function (store) {
51
66
  var _a = __read(storeEntry, 2), _ = _a[0], container = _a[1];
52
67
  Object.entries(container).forEach(function (containerEntry) {
53
68
  var _a = __read(containerEntry, 2), _ = _a[0], expiration = _a[1].expiration;
54
- acc.push(expiration);
69
+ if (expiration)
70
+ acc.push(expiration);
55
71
  });
56
72
  return acc;
57
73
  }, []);
@@ -131,6 +147,8 @@ var setApplicationStore = function (container, applicationStorage, store) {
131
147
  var createEmptyStore = function () { return ({ tenant: {}, implementation: {}, widget: {} }); };
132
148
  exports.createEmptyStore = createEmptyStore;
133
149
  var isExpired = function (isoDateString) {
150
+ if (!isoDateString)
151
+ return false;
134
152
  return !!isoDateString && new Date() > new Date(isoDateString);
135
153
  };
136
154
  exports.isExpired = isExpired;
@@ -140,10 +158,16 @@ var getValue = function (store, key) {
140
158
  };
141
159
  exports.getValue = getValue;
142
160
  var createValue = function (value, category, duration) {
161
+ if (duration) {
162
+ return {
163
+ value: value,
164
+ category: category,
165
+ expiration: typeof duration === 'object' ? (0, exports.createExpirationDate)(duration) : duration,
166
+ };
167
+ }
143
168
  return {
144
169
  value: value,
145
170
  category: category,
146
- expiration: typeof duration === 'object' ? (0, exports.createExpirationDate)(duration) : duration,
147
171
  };
148
172
  };
149
173
  exports.createValue = createValue;
@@ -5,7 +5,7 @@ import { StorageCategory, StorageMedium, StorageWriter, StorageWriterOptions } f
5
5
  * @param container Widget Container.
6
6
  * @param key Key to use when writing.
7
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}}.
8
+ * @param options StorageWriterOptions to use when writing default {scope: StorageScope.Widget, medium = StorageMedium.Session, duration = infinite }.
9
9
  * @returns a function to be used to write a value to the storage using given settings.
10
10
  */
11
11
  export declare const createStorageWriter: (container: Container, key: string, category: StorageCategory, options?: StorageWriterOptions) => Promise<StorageWriter>;
@@ -6,7 +6,7 @@ import { createEmptyStore, createValue, getApplicationStoreAsync, getCookieStore
6
6
  * @param container Widget Container.
7
7
  * @param key Key to use when writing.
8
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}}.
9
+ * @param options StorageWriterOptions to use when writing default {scope: StorageScope.Widget, medium = StorageMedium.Session, duration = infinite }.
10
10
  * @returns a function to be used to write a value to the storage using given settings.
11
11
  */
12
12
  export var createStorageWriter = function (container, key, category, options) {
@@ -26,7 +26,7 @@ export var createStorageWriter = function (container, key, category, options) {
26
26
  }
27
27
  return;
28
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;
29
+ var _a = options.scope, scope = _a === void 0 ? StorageScope.Widget : _a, _b = options.medium, medium = _b === void 0 ? StorageMedium.Session : _b, duration = options.duration;
30
30
  var store = createEmptyStore();
31
31
  store[scope][key] = createValue(value, category, duration);
32
32
  if (medium === StorageMedium.Cookie)
@@ -18,7 +18,7 @@ export declare type StorageContainer = {
18
18
  };
19
19
  export declare type StoredValue = {
20
20
  value: any;
21
- expiration: string;
21
+ expiration?: string;
22
22
  category: StorageCategory;
23
23
  };
24
24
  export declare enum StorageCategory {
@@ -1,9 +1,9 @@
1
1
  import { Container } from '@webprovisions/platform';
2
2
  import { Duration, StorageCategory, StorageMedium, Store, StoredValue } from './types';
3
3
  export declare const createEmptyStore: () => Store;
4
- export declare const isExpired: (isoDateString: string) => boolean;
4
+ export declare const isExpired: (isoDateString?: string | undefined) => boolean;
5
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;
6
+ export declare const createValue: (value: any, category: StorageCategory, duration?: string | Duration | undefined) => StoredValue;
7
7
  export declare const processStore: (store: Store, policy?: StorageCategory[] | undefined) => Store;
8
8
  /**
9
9
  * @param category Storage Category.
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __read = (this && this.__read) || function (o, n) {
2
13
  var m = typeof Symbol === "function" && o[Symbol.iterator];
3
14
  if (!m) return o;
@@ -14,7 +25,7 @@ var __read = (this && this.__read) || function (o, n) {
14
25
  }
15
26
  return ar;
16
27
  };
17
- import { deepClone, hash, lock, mergeDeep } from '@telia-ace/widget-utilities';
28
+ import { deepClone, hash, lock } from '@telia-ace/widget-utilities';
18
29
  import { readStorage } from './storage';
19
30
  import { StorageCategory, StorageMedium, } from './types';
20
31
  var hasEntries = function (object) {
@@ -37,7 +48,11 @@ var cleanUndefined = function (object) {
37
48
  });
38
49
  };
39
50
  var mergeAndClean = function (target, source) {
40
- var merged = mergeDeep(target, source);
51
+ var merged = {
52
+ tenant: __assign(__assign({}, target.tenant), source.tenant),
53
+ implementation: __assign(__assign({}, target.implementation), source.implementation),
54
+ widget: __assign(__assign({}, target.widget), source.widget)
55
+ };
41
56
  cleanUndefined(merged.tenant);
42
57
  cleanUndefined(merged.implementation);
43
58
  cleanUndefined(merged.widget);
@@ -48,7 +63,8 @@ var getLongestExpirationDate = function (store) {
48
63
  var _a = __read(storeEntry, 2), _ = _a[0], container = _a[1];
49
64
  Object.entries(container).forEach(function (containerEntry) {
50
65
  var _a = __read(containerEntry, 2), _ = _a[0], expiration = _a[1].expiration;
51
- acc.push(expiration);
66
+ if (expiration)
67
+ acc.push(expiration);
52
68
  });
53
69
  return acc;
54
70
  }, []);
@@ -127,6 +143,8 @@ var setApplicationStore = function (container, applicationStorage, store) {
127
143
  };
128
144
  export var createEmptyStore = function () { return ({ tenant: {}, implementation: {}, widget: {} }); };
129
145
  export var isExpired = function (isoDateString) {
146
+ if (!isoDateString)
147
+ return false;
130
148
  return !!isoDateString && new Date() > new Date(isoDateString);
131
149
  };
132
150
  export var getValue = function (store, key) {
@@ -134,10 +152,16 @@ export var getValue = function (store, key) {
134
152
  return storedValue === null || storedValue === void 0 ? void 0 : storedValue.value;
135
153
  };
136
154
  export var createValue = function (value, category, duration) {
155
+ if (duration) {
156
+ return {
157
+ value: value,
158
+ category: category,
159
+ expiration: typeof duration === 'object' ? createExpirationDate(duration) : duration,
160
+ };
161
+ }
137
162
  return {
138
163
  value: value,
139
164
  category: category,
140
- expiration: typeof duration === 'object' ? createExpirationDate(duration) : duration,
141
165
  };
142
166
  };
143
167
  export var processStore = function (store, policy) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-services",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Services for ACE Widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",
@@ -30,5 +30,5 @@
30
30
  "devDependencies": {
31
31
  "@webprovisions/platform": "^1.1.2"
32
32
  },
33
- "gitHead": "988b0637c7ecce474bf92cb793007f9f5b5fcd13"
33
+ "gitHead": "be897e98ff1107e9f7ccf62c3a79d331ad0a03a6"
34
34
  }