@ketch-sdk/ketch-data-layer 1.1.2 → 1.1.3
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/README.md +201 -0
- package/dist/listener/index.d.ts +3 -1
- package/dist/mapper/index.d.ts +3 -0
- package/dist/storage/index.d.ts +1 -2
- package/dist/storage/index.js +2 -4
- package/package.json +1 -1
- package/dist/storage/notifier.d.ts +0 -3
- package/dist/storage/notifier.js +0 -10
package/README.md
CHANGED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# ketch-data-layer
|
|
2
|
+
|
|
3
|
+
The `ketch-data-layer` library implements a [Watcher](#Watcher) and a set of [Fetcher](#Fetcher) and [Structure](#Structure)
|
|
4
|
+
implementations for fetching and structuring identities.
|
|
5
|
+
|
|
6
|
+
The following [Fetchers](#Fetcher) are implemented:
|
|
7
|
+
* cookie
|
|
8
|
+
* dataLayer
|
|
9
|
+
* localStorage
|
|
10
|
+
* managed
|
|
11
|
+
* queryString
|
|
12
|
+
* sessionStorage
|
|
13
|
+
* window
|
|
14
|
+
|
|
15
|
+
The following [Structures](#Structure) are implemented:
|
|
16
|
+
* json
|
|
17
|
+
* jwt
|
|
18
|
+
* queryString
|
|
19
|
+
* semicolon
|
|
20
|
+
* string
|
|
21
|
+
|
|
22
|
+
## Identity
|
|
23
|
+
|
|
24
|
+
An Identity can be described using the following interface:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
export interface Identity {
|
|
28
|
+
/**
|
|
29
|
+
* type is the location on the page from which to retrieve identity information
|
|
30
|
+
*/
|
|
31
|
+
type: IdentityType;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* variable is the name to look up the identity value in the specified location
|
|
35
|
+
*/
|
|
36
|
+
variable: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* format is the encoding of the value
|
|
40
|
+
*/
|
|
41
|
+
format: IdentityFormat;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* key is the identifier to find the identity within the value if the format is IDENTITY_FORMAT_STRING
|
|
45
|
+
* then key will be undefined
|
|
46
|
+
*/
|
|
47
|
+
key?: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* priority of the identity for consent conflict resolution
|
|
51
|
+
*/
|
|
52
|
+
priority?: number;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Priority is ignored by this library.
|
|
57
|
+
|
|
58
|
+
## Watcher
|
|
59
|
+
|
|
60
|
+
The primary class is the `Watcher` which contains a series of registered identities that it watches for changes to.
|
|
61
|
+
|
|
62
|
+
### Creating a Watcher
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const w = new Watcher(window, {interval, timeout})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Creates a new `Watcher` attached to the given `window`. The watcher will poll every `interval` until `timeout` seconds.
|
|
69
|
+
|
|
70
|
+
### Add an identity
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const name: string = ''
|
|
74
|
+
const identity: Identity | (() => Promise<string[]> = {}
|
|
75
|
+
w.add(name, identity)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Registers an identity with the given `name` using the provided `identity` configuration. There are two
|
|
79
|
+
types of configuration allowed. The first type is an instance of an `Identity` object. If given this,
|
|
80
|
+
the watcher selects from it's know library based on the specification in the `Identity`. The second option,
|
|
81
|
+
which is a function returning a Promise of string values, can be used if the required identity cannot be
|
|
82
|
+
described using `Identity`.
|
|
83
|
+
|
|
84
|
+
### Start watching
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
await w.start()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Starts the [Watcher](#Watcher) watching based on the `interval` and `timeout` provided in the constructor.
|
|
91
|
+
|
|
92
|
+
### Stop watching
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
w.stop()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Stops the [Watcher](#Watcher).
|
|
99
|
+
|
|
100
|
+
### Immediately notifying
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
await w.notify()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Immediately fetches and notifies about identities by emitting an `identities` event.
|
|
107
|
+
|
|
108
|
+
### Add a listener
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const listener: (...args: any[]) => void = () => {}
|
|
112
|
+
w.addListener('identities', listener)
|
|
113
|
+
w.on('identities', listener)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Add a listener function that gets called each time identities change. The argument to the listener
|
|
117
|
+
will be an `Identities` map.
|
|
118
|
+
|
|
119
|
+
### Add a one-time listener
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const listener: (...args: any[]) => void = () => {}
|
|
123
|
+
w.once('identities', listener)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Adds a one-time listener function. The argument to the listener
|
|
127
|
+
will be an `Identities` map.
|
|
128
|
+
|
|
129
|
+
### Remove a listener
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const listener: (...args: any[]) => void = () => {}
|
|
133
|
+
w.removeListener('identities', listener)
|
|
134
|
+
w.off('identities', listener)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Removes the given listener.
|
|
138
|
+
|
|
139
|
+
### Remove all listeners
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
w.removeAllListeners('identities')
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Removes all listeners.
|
|
146
|
+
|
|
147
|
+
## Fetcher
|
|
148
|
+
|
|
149
|
+
A `Fetcher` is a function with the following signature:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
type Fetcher = async (w: Window, name: string) => Promise<any[]>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The `w` parameter is the `Window` to attach to. The `name` is the name of the identity. The return
|
|
156
|
+
must be an array of discovered, structured identities. The structured identities will be destructured
|
|
157
|
+
using a [Structure](#Structure) function to provide the identity value.
|
|
158
|
+
|
|
159
|
+
## Structure
|
|
160
|
+
|
|
161
|
+
A `Structure` is a function with the following signature:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
type Mapper = {
|
|
165
|
+
[key: string]: string
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
type Structure = (value: any) => Mapper
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Given some structured value, the job of the `Structure` function is to return a key-value map representing the
|
|
172
|
+
values in that structure. If there is only a single identifiable value, then the key should be `value`.
|
|
173
|
+
|
|
174
|
+
## Cookie
|
|
175
|
+
|
|
176
|
+
This library also exposes some utility functions that may be useful outside of the library's core purpose.
|
|
177
|
+
|
|
178
|
+
### getCookie
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { getCookie } from '@ketch-sdk/ketch-data-layer/cookie'
|
|
182
|
+
|
|
183
|
+
const name: string = ''
|
|
184
|
+
const value = getCookie(window, name)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Retrieves the full raw value of the cookie with the given name.
|
|
188
|
+
|
|
189
|
+
### setCookie
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { setCookie } from '@ketch-sdk/ketch-data-layer/cookie'
|
|
193
|
+
|
|
194
|
+
const name: string = ''
|
|
195
|
+
const value: any = ''
|
|
196
|
+
const ttl: number = 2 // 2 days
|
|
197
|
+
setCookie(window, name, value, ttl)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Sets the value of the cookie with the given name. The TTL of the cookie is set to `ttl` days. Note that
|
|
201
|
+
long-lasting cookies are subject to [Intelligent Tracking Prevention](https://webkit.org/tracking-prevention-policy/) limitations.
|
package/dist/listener/index.d.ts
CHANGED
package/dist/mapper/index.d.ts
CHANGED
package/dist/storage/index.d.ts
CHANGED
package/dist/storage/index.js
CHANGED
|
@@ -3,9 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetcher = void 0;
|
|
7
7
|
const fetcher_1 = __importDefault(require("./fetcher"));
|
|
8
8
|
exports.fetcher = fetcher_1.default;
|
|
9
|
-
|
|
10
|
-
exports.notifier = notifier_1.default;
|
|
11
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmFnZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSx3REFBK0I7QUFHdEIsa0JBSEYsaUJBQU8sQ0FHRTtBQUZoQiwwREFBaUM7QUFFZixtQkFGWCxrQkFBUSxDQUVXIn0=
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmFnZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSx3REFBK0I7QUFFdEIsa0JBRkYsaUJBQU8sQ0FFRSJ9
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@ketch-sdk/ketch-data-layer", "version": "1.1.
|
|
1
|
+
{"name": "@ketch-sdk/ketch-data-layer", "version": "1.1.3", "description": "Ketch Data Layer interface", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": {"all": "npm run lint && npm run format-check && npm run test && npm run build && npm run docs", "build": "tsc -p .", "format": "prettier --write \"**/*.{ts,tsx,yml,yaml}\"", "format-check": "prettier --check '**/*.ts'", "lint": "eslint src/**/*.ts", "test": "jest --runInBand --passWithNoTests", "docs": "typedoc --githubPages true --excludeExternals --excludeInternal src/index.ts"}, "repository": {"type": "git", "url": "git+https://github.com/ketch-sdk/ketch-data-layer.git"}, "homepage": "https://github.com/ketch-sdk/ketch-data-layer", "bugs": {"url": "https://github.com/ketch-sdk/ketch-data-layer/issues"}, "keywords": ["Ketch", "dataLayer"], "author": "Ketch Kloud, Inc.", "license": "MIT", "devDependencies": {"@ketch-sdk/ketch-types": "^1.4.3", "@types/deep-equal": "^1.0.1", "@types/events": "^3.0.0", "@types/jest": "^29.2.5", "@types/node": "^18.11.18", "@types/uuid": "^9.0.0", "@typescript-eslint/eslint-plugin": "^5.48.1", "@typescript-eslint/parser": "^5.48.1", "eslint": "^8.31.0", "eslint-config-prettier": "^8.6.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jest": "^27.2.1", "eslint-plugin-prettier": "^4.2.1", "events": "^3.3.0", "jest": "^29.3.1", "jest-environment-jsdom": "^29.3.1", "jest-junit": "^15.0.0", "js-yaml": "^4.1.0", "prettier": "^2.8.2", "ts-jest": "^29.0.3", "typedoc": "^0.23.24", "typescript": "^4.9.4"}, "dependencies": {"deep-equal": "^2.2.0", "uuid": "^9.0.0"}, "files": ["dist/"]}
|
package/dist/storage/notifier.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (w, name, listener, _options) => {
|
|
4
|
-
w.addEventListener('storage', event => {
|
|
5
|
-
if (event.key === name) {
|
|
6
|
-
listener(name, event.newValue);
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90aWZpZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmFnZS9ub3RpZmllci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLGtCQUFlLENBQUMsQ0FBUyxFQUFFLElBQVksRUFBRSxRQUFrQixFQUFFLFFBQTBCLEVBQVEsRUFBRTtJQUMvRixDQUFDLENBQUMsZ0JBQWdCLENBQUMsU0FBUyxFQUFFLEtBQUssQ0FBQyxFQUFFO1FBQ3BDLElBQUksS0FBSyxDQUFDLEdBQUcsS0FBSyxJQUFJLEVBQUU7WUFDdEIsUUFBUSxDQUFDLElBQUksRUFBRSxLQUFLLENBQUMsUUFBUSxDQUFDLENBQUE7U0FDL0I7SUFDSCxDQUFDLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQSJ9
|