@foxy.io/sdk 1.9.0 → 2.0.0-beta.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/dist/cdn/FoxySDKCustomer.js +3 -3
- package/dist/cjs/core/API/CustomStorage.js +2 -0
- package/dist/cjs/core/MemoryStorage.js +8 -0
- package/dist/cjs/core/ScopedStorage.js +64 -0
- package/dist/cjs/core/index.js +5 -1
- package/dist/cjs/customer/API.js +32 -23
- package/dist/esm/core/API/CustomStorage.js +1 -0
- package/dist/esm/core/MemoryStorage.js +2 -0
- package/dist/esm/core/ScopedStorage.js +60 -0
- package/dist/esm/core/index.js +2 -0
- package/dist/esm/customer/API.js +32 -23
- package/dist/types/backend/API.d.ts +3 -2
- package/dist/types/backend/Graph/email_template.d.ts +2 -0
- package/dist/types/core/API/API.d.ts +9 -8
- package/dist/types/core/API/CustomStorage.d.ts +7 -0
- package/dist/types/core/API/Node.d.ts +5 -4
- package/dist/types/core/API/Response.d.ts +5 -4
- package/dist/types/core/MemoryStorage.d.ts +2 -0
- package/dist/types/core/ScopedStorage.d.ts +25 -0
- package/dist/types/core/index.d.ts +2 -0
- package/dist/types/customer/API.d.ts +8 -2
- package/dist/types/customer/types.d.ts +1 -4
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
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.MemoryStorage = void 0;
|
|
7
|
+
const fake_storage_1 = __importDefault(require("fake-storage"));
|
|
8
|
+
exports.MemoryStorage = fake_storage_1.default;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopedStorage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) wrapper
|
|
6
|
+
* working only with the items in the given scope.
|
|
7
|
+
*/
|
|
8
|
+
class ScopedStorage {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.__scope = options.scope;
|
|
11
|
+
this.__target = options.target;
|
|
12
|
+
}
|
|
13
|
+
key(index) {
|
|
14
|
+
const length = this.__target.length;
|
|
15
|
+
for (let scopedIndex = -1, targetIndex = 0; targetIndex < length; ++targetIndex) {
|
|
16
|
+
const key = this.__target.key(targetIndex);
|
|
17
|
+
if (key !== null && this.__isScopedKey(key)) {
|
|
18
|
+
++scopedIndex;
|
|
19
|
+
if (scopedIndex === index)
|
|
20
|
+
return this.__getUnscopedKey(key);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
getItem(key) {
|
|
26
|
+
return this.__target.getItem(this.__getScopedKey(key));
|
|
27
|
+
}
|
|
28
|
+
setItem(key, value, options) {
|
|
29
|
+
this.__target.setItem(this.__getScopedKey(key), value, options);
|
|
30
|
+
}
|
|
31
|
+
removeItem(key) {
|
|
32
|
+
this.__target.removeItem(this.__getScopedKey(key));
|
|
33
|
+
}
|
|
34
|
+
clear() {
|
|
35
|
+
for (let index = 0; index < this.__target.length;) {
|
|
36
|
+
const key = this.__target.key(index);
|
|
37
|
+
if (key !== null && this.__isScopedKey(key)) {
|
|
38
|
+
this.__target.removeItem(key);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
++index;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
get length() {
|
|
46
|
+
let sum = 0;
|
|
47
|
+
for (let index = 0; index < this.__target.length; ++index) {
|
|
48
|
+
const key = this.__target.key(index);
|
|
49
|
+
if (key !== null && this.__isScopedKey(key))
|
|
50
|
+
++sum;
|
|
51
|
+
}
|
|
52
|
+
return sum;
|
|
53
|
+
}
|
|
54
|
+
__isScopedKey(key) {
|
|
55
|
+
return key.startsWith(`${this.__scope}.`) && key.length > this.__scope.length + 1;
|
|
56
|
+
}
|
|
57
|
+
__getScopedKey(key) {
|
|
58
|
+
return `${this.__scope}.${key}`;
|
|
59
|
+
}
|
|
60
|
+
__getUnscopedKey(key) {
|
|
61
|
+
return key.substring(this.__scope.length + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ScopedStorage = ScopedStorage;
|
package/dist/cjs/core/index.js
CHANGED
|
@@ -19,10 +19,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.API = exports.Rumour = exports.BooleanSelector = exports.Nucleon = void 0;
|
|
22
|
+
exports.API = exports.Rumour = exports.ScopedStorage = exports.MemoryStorage = exports.BooleanSelector = exports.Nucleon = void 0;
|
|
23
23
|
exports.Nucleon = __importStar(require("./Nucleon/index.js"));
|
|
24
24
|
var BooleanSelector_js_1 = require("./BooleanSelector.js");
|
|
25
25
|
Object.defineProperty(exports, "BooleanSelector", { enumerable: true, get: function () { return BooleanSelector_js_1.BooleanSelector; } });
|
|
26
|
+
var MemoryStorage_js_1 = require("./MemoryStorage.js");
|
|
27
|
+
Object.defineProperty(exports, "MemoryStorage", { enumerable: true, get: function () { return MemoryStorage_js_1.MemoryStorage; } });
|
|
28
|
+
var ScopedStorage_js_1 = require("./ScopedStorage.js");
|
|
29
|
+
Object.defineProperty(exports, "ScopedStorage", { enumerable: true, get: function () { return ScopedStorage_js_1.ScopedStorage; } });
|
|
26
30
|
var index_js_1 = require("./Rumour/index.js");
|
|
27
31
|
Object.defineProperty(exports, "Rumour", { enumerable: true, get: function () { return index_js_1.Rumour; } });
|
|
28
32
|
var index_js_2 = require("./API/index.js");
|
package/dist/cjs/customer/API.js
CHANGED
|
@@ -57,9 +57,13 @@ class API extends Core.API {
|
|
|
57
57
|
method: 'POST',
|
|
58
58
|
});
|
|
59
59
|
if (response.ok) {
|
|
60
|
-
const session = yield response.json();
|
|
61
|
-
const
|
|
62
|
-
this.storage.setItem(API.
|
|
60
|
+
const session = (yield response.json());
|
|
61
|
+
const expires = new Date(Date.now() + session.expires_in);
|
|
62
|
+
this.storage.setItem(API.SESSION_TOKEN, session.session_token, { expires });
|
|
63
|
+
this.storage.setItem(API.EXPIRY, String(session.expires_in), { expires });
|
|
64
|
+
this.storage.setItem(API.JWT, session.jwt, { expires });
|
|
65
|
+
if (session.sso)
|
|
66
|
+
this.storage.setItem(API.SSO, session.sso, { expires });
|
|
63
67
|
}
|
|
64
68
|
else {
|
|
65
69
|
const code = response.status === 401 ? 'UNAUTHORIZED' : 'UNKNOWN';
|
|
@@ -96,38 +100,43 @@ class API extends Core.API {
|
|
|
96
100
|
});
|
|
97
101
|
}
|
|
98
102
|
__fetch(input, init) {
|
|
99
|
-
var _a;
|
|
100
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
|
|
104
|
+
const token = this.storage.getItem(API.SESSION_TOKEN);
|
|
102
105
|
const request = new cross_fetch_1.Request(input, init);
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
const now = Date.now();
|
|
106
|
-
if (expiresAt < now) {
|
|
107
|
-
this.console.info('Session has expired, signing out.');
|
|
108
|
-
this.storage.clear();
|
|
109
|
-
this.cache.clear();
|
|
110
|
-
session = null;
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
request.headers.set('Authorization', `Bearer ${session.session_token}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
106
|
+
if (typeof token === 'string')
|
|
107
|
+
request.headers.set('Authorization', `Bearer ${token}`);
|
|
116
108
|
request.headers.set('Content-Type', 'application/json');
|
|
117
109
|
request.headers.set('FOXY-API-VERSION', '1');
|
|
118
110
|
this.console.trace(`${request.method} ${request.url}`);
|
|
119
111
|
const response = yield cross_fetch_1.fetch(request);
|
|
120
|
-
if (
|
|
121
|
-
const
|
|
122
|
-
|
|
112
|
+
if (typeof token === 'string' && response.ok) {
|
|
113
|
+
const expiryAsString = this.storage.getItem(API.EXPIRY);
|
|
114
|
+
if (typeof expiryAsString === 'string') {
|
|
115
|
+
const expires = new Date(Date.now() + parseInt(expiryAsString));
|
|
116
|
+
const jwt = this.storage.getItem(API.JWT);
|
|
117
|
+
const sso = this.storage.getItem(API.SSO);
|
|
118
|
+
if (typeof token === 'string')
|
|
119
|
+
this.storage.setItem(API.SESSION_TOKEN, token, { expires });
|
|
120
|
+
if (typeof jwt === 'string')
|
|
121
|
+
this.storage.setItem(API.JWT, jwt, { expires });
|
|
122
|
+
if (typeof sso === 'string')
|
|
123
|
+
this.storage.setItem(API.SSO, sso, { expires });
|
|
124
|
+
this.storage.setItem(API.EXPIRY, expiryAsString, { expires });
|
|
125
|
+
}
|
|
123
126
|
}
|
|
124
127
|
return response;
|
|
125
128
|
});
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
exports.API = API;
|
|
129
|
-
/** Storage key for session
|
|
130
|
-
API.
|
|
132
|
+
/** Storage key for customer session token. */
|
|
133
|
+
API.SESSION_TOKEN = 'customer';
|
|
134
|
+
/** Storage key for max session lifetime value (ms, stored as string). */
|
|
135
|
+
API.EXPIRY = 'customer.expiry';
|
|
136
|
+
/** Storage key for JWT representing authenticated customer. */
|
|
137
|
+
API.JWT = 'customer.jwt';
|
|
138
|
+
/** Storage key for SSO URL. */
|
|
139
|
+
API.SSO = 'customer.sso';
|
|
131
140
|
/** Validators for the method arguments in this class (internal). */
|
|
132
141
|
API.v8n = Object.assign({}, Core.API.v8n, {
|
|
133
142
|
credentials: v8n_js_1.v8n().schema({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) wrapper
|
|
3
|
+
* working only with the items in the given scope.
|
|
4
|
+
*/
|
|
5
|
+
export class ScopedStorage {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.__scope = options.scope;
|
|
8
|
+
this.__target = options.target;
|
|
9
|
+
}
|
|
10
|
+
key(index) {
|
|
11
|
+
const length = this.__target.length;
|
|
12
|
+
for (let scopedIndex = -1, targetIndex = 0; targetIndex < length; ++targetIndex) {
|
|
13
|
+
const key = this.__target.key(targetIndex);
|
|
14
|
+
if (key !== null && this.__isScopedKey(key)) {
|
|
15
|
+
++scopedIndex;
|
|
16
|
+
if (scopedIndex === index)
|
|
17
|
+
return this.__getUnscopedKey(key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
getItem(key) {
|
|
23
|
+
return this.__target.getItem(this.__getScopedKey(key));
|
|
24
|
+
}
|
|
25
|
+
setItem(key, value, options) {
|
|
26
|
+
this.__target.setItem(this.__getScopedKey(key), value, options);
|
|
27
|
+
}
|
|
28
|
+
removeItem(key) {
|
|
29
|
+
this.__target.removeItem(this.__getScopedKey(key));
|
|
30
|
+
}
|
|
31
|
+
clear() {
|
|
32
|
+
for (let index = 0; index < this.__target.length;) {
|
|
33
|
+
const key = this.__target.key(index);
|
|
34
|
+
if (key !== null && this.__isScopedKey(key)) {
|
|
35
|
+
this.__target.removeItem(key);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
++index;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
get length() {
|
|
43
|
+
let sum = 0;
|
|
44
|
+
for (let index = 0; index < this.__target.length; ++index) {
|
|
45
|
+
const key = this.__target.key(index);
|
|
46
|
+
if (key !== null && this.__isScopedKey(key))
|
|
47
|
+
++sum;
|
|
48
|
+
}
|
|
49
|
+
return sum;
|
|
50
|
+
}
|
|
51
|
+
__isScopedKey(key) {
|
|
52
|
+
return key.startsWith(`${this.__scope}.`) && key.length > this.__scope.length + 1;
|
|
53
|
+
}
|
|
54
|
+
__getScopedKey(key) {
|
|
55
|
+
return `${this.__scope}.${key}`;
|
|
56
|
+
}
|
|
57
|
+
__getUnscopedKey(key) {
|
|
58
|
+
return key.substring(this.__scope.length + 1);
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/esm/core/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as Nucleon_1 from './Nucleon/index.js';
|
|
2
2
|
export { Nucleon_1 as Nucleon };
|
|
3
3
|
export { BooleanSelector } from './BooleanSelector.js';
|
|
4
|
+
export { MemoryStorage } from './MemoryStorage.js';
|
|
5
|
+
export { ScopedStorage } from './ScopedStorage.js';
|
|
4
6
|
export { Rumour } from './Rumour/index.js';
|
|
5
7
|
export { API } from './API/index.js';
|
package/dist/esm/customer/API.js
CHANGED
|
@@ -35,9 +35,13 @@ export class API extends Core.API {
|
|
|
35
35
|
method: 'POST',
|
|
36
36
|
});
|
|
37
37
|
if (response.ok) {
|
|
38
|
-
const session = yield response.json();
|
|
39
|
-
const
|
|
40
|
-
this.storage.setItem(API.
|
|
38
|
+
const session = (yield response.json());
|
|
39
|
+
const expires = new Date(Date.now() + session.expires_in);
|
|
40
|
+
this.storage.setItem(API.SESSION_TOKEN, session.session_token, { expires });
|
|
41
|
+
this.storage.setItem(API.EXPIRY, String(session.expires_in), { expires });
|
|
42
|
+
this.storage.setItem(API.JWT, session.jwt, { expires });
|
|
43
|
+
if (session.sso)
|
|
44
|
+
this.storage.setItem(API.SSO, session.sso, { expires });
|
|
41
45
|
}
|
|
42
46
|
else {
|
|
43
47
|
const code = response.status === 401 ? 'UNAUTHORIZED' : 'UNKNOWN';
|
|
@@ -74,37 +78,42 @@ export class API extends Core.API {
|
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
__fetch(input, init) {
|
|
77
|
-
var _a;
|
|
78
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
|
|
82
|
+
const token = this.storage.getItem(API.SESSION_TOKEN);
|
|
80
83
|
const request = new Request(input, init);
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
const now = Date.now();
|
|
84
|
-
if (expiresAt < now) {
|
|
85
|
-
this.console.info('Session has expired, signing out.');
|
|
86
|
-
this.storage.clear();
|
|
87
|
-
this.cache.clear();
|
|
88
|
-
session = null;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
request.headers.set('Authorization', `Bearer ${session.session_token}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
84
|
+
if (typeof token === 'string')
|
|
85
|
+
request.headers.set('Authorization', `Bearer ${token}`);
|
|
94
86
|
request.headers.set('Content-Type', 'application/json');
|
|
95
87
|
request.headers.set('FOXY-API-VERSION', '1');
|
|
96
88
|
this.console.trace(`${request.method} ${request.url}`);
|
|
97
89
|
const response = yield fetch(request);
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
100
|
-
|
|
90
|
+
if (typeof token === 'string' && response.ok) {
|
|
91
|
+
const expiryAsString = this.storage.getItem(API.EXPIRY);
|
|
92
|
+
if (typeof expiryAsString === 'string') {
|
|
93
|
+
const expires = new Date(Date.now() + parseInt(expiryAsString));
|
|
94
|
+
const jwt = this.storage.getItem(API.JWT);
|
|
95
|
+
const sso = this.storage.getItem(API.SSO);
|
|
96
|
+
if (typeof token === 'string')
|
|
97
|
+
this.storage.setItem(API.SESSION_TOKEN, token, { expires });
|
|
98
|
+
if (typeof jwt === 'string')
|
|
99
|
+
this.storage.setItem(API.JWT, jwt, { expires });
|
|
100
|
+
if (typeof sso === 'string')
|
|
101
|
+
this.storage.setItem(API.SSO, sso, { expires });
|
|
102
|
+
this.storage.setItem(API.EXPIRY, expiryAsString, { expires });
|
|
103
|
+
}
|
|
101
104
|
}
|
|
102
105
|
return response;
|
|
103
106
|
});
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
|
-
/** Storage key for session
|
|
107
|
-
API.
|
|
109
|
+
/** Storage key for customer session token. */
|
|
110
|
+
API.SESSION_TOKEN = 'customer';
|
|
111
|
+
/** Storage key for max session lifetime value (ms, stored as string). */
|
|
112
|
+
API.EXPIRY = 'customer.expiry';
|
|
113
|
+
/** Storage key for JWT representing authenticated customer. */
|
|
114
|
+
API.JWT = 'customer.jwt';
|
|
115
|
+
/** Storage key for SSO URL. */
|
|
116
|
+
API.SSO = 'customer.sso';
|
|
108
117
|
/** Validators for the method arguments in this class (internal). */
|
|
109
118
|
API.v8n = Object.assign({}, Core.API.v8n, {
|
|
110
119
|
credentials: v8n().schema({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Core from '../core/index.js';
|
|
2
|
+
import type { CustomStorage } from '../../src/core/API/CustomStorage';
|
|
2
3
|
import type { Graph } from './Graph';
|
|
3
4
|
import type { LogLevel } from 'consola';
|
|
4
5
|
/** In order to facilitate any major, unforeseen breaking changes in the future, we require each request to include API version. We hope to rarely (never?) change it but by requiring it up front, we can ensure what you get today is what you’ll get tomorrow. */
|
|
@@ -9,10 +10,10 @@ declare type BackendAPIInit = {
|
|
|
9
10
|
clientSecret: string;
|
|
10
11
|
clientId: string;
|
|
11
12
|
level?: LogLevel;
|
|
12
|
-
storage?:
|
|
13
|
+
storage?: CustomStorage;
|
|
13
14
|
version?: BackendAPIVersion;
|
|
14
15
|
base?: URL;
|
|
15
|
-
cache?:
|
|
16
|
+
cache?: CustomStorage;
|
|
16
17
|
};
|
|
17
18
|
declare type GrantOpts = ({
|
|
18
19
|
code: string;
|
|
@@ -20,6 +20,8 @@ export interface EmailTemplate extends Graph {
|
|
|
20
20
|
props: {
|
|
21
21
|
/** The description of your email template. */
|
|
22
22
|
description: string;
|
|
23
|
+
/** The subject template of your email. */
|
|
24
|
+
subject: string;
|
|
23
25
|
/** The content of your html email template. Leave blank to use the default responsive template. You can set the content directly or set the `content_html_url` to point to your template content online and then POST to the `cache` link relationship. */
|
|
24
26
|
content_html: string;
|
|
25
27
|
/** The URL of your html email template hosted on your own server online and publicly available for our server to cache. */
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Consola, LogLevel } from 'consola';
|
|
2
2
|
import { AuthError } from './AuthError.js';
|
|
3
|
+
import type { CustomStorage } from './CustomStorage';
|
|
3
4
|
import type { Graph } from '../Graph';
|
|
4
5
|
import { Node } from './Node.js';
|
|
5
6
|
/** API constructor parameters. */
|
|
6
7
|
declare type Init = {
|
|
7
8
|
/**
|
|
8
|
-
* Credentials storage implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
9
|
+
* Credentials storage implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
9
10
|
* Access tokens and other related info will be stored here. Defaults to in-memory storage.
|
|
10
11
|
*/
|
|
11
|
-
storage?:
|
|
12
|
+
storage?: CustomStorage;
|
|
12
13
|
/**
|
|
13
14
|
* Numeric [Consola](https://github.com/nuxt-contrib/consola) log level.
|
|
14
15
|
* If omitted, Consola defaults will be used.
|
|
@@ -20,10 +21,10 @@ declare type Init = {
|
|
|
20
21
|
*/
|
|
21
22
|
fetch?: Window['fetch'];
|
|
22
23
|
/**
|
|
23
|
-
* Resolver cache implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
24
|
+
* Resolver cache implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
24
25
|
* Every resolved path will be stored here for future use. Defaults to in-memory storage.
|
|
25
26
|
*/
|
|
26
|
-
cache?:
|
|
27
|
+
cache?: CustomStorage;
|
|
27
28
|
/**
|
|
28
29
|
* Bookmark [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) for this API.
|
|
29
30
|
* This is where the tree traversal begins. We also use this URL as a base for relative paths.
|
|
@@ -77,15 +78,15 @@ export declare class API<TGraph extends Graph> extends Node<TGraph> {
|
|
|
77
78
|
*/
|
|
78
79
|
readonly console: Consola;
|
|
79
80
|
/**
|
|
80
|
-
* Credentials storage implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
81
|
+
* Credentials storage implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
81
82
|
* Access tokens and other related info will be stored here. Clearing this storage will log you out.
|
|
82
83
|
*/
|
|
83
|
-
readonly storage:
|
|
84
|
+
readonly storage: CustomStorage;
|
|
84
85
|
/**
|
|
85
|
-
* Resolver cache implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
86
|
+
* Resolver cache implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
|
|
86
87
|
* Every resolved path will be stored here for future use. You can clear this cache by calling `clear()`.
|
|
87
88
|
*/
|
|
88
|
-
readonly cache:
|
|
89
|
+
readonly cache: CustomStorage;
|
|
89
90
|
/**
|
|
90
91
|
* Bookmark [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) for this API.
|
|
91
92
|
* This is where the tree traversal begins. We also use this URL as a base for relative paths.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { V8N } from '../v8n.js';
|
|
2
2
|
import { Consola } from 'consola';
|
|
3
|
+
import type { CustomStorage } from './CustomStorage';
|
|
3
4
|
import type { Graph } from '../Graph';
|
|
4
5
|
import type { Query } from '../Query';
|
|
5
6
|
import { ResolutionError } from './ResolutionError.js';
|
|
@@ -12,8 +13,8 @@ declare type NodeInit = {
|
|
|
12
13
|
path: CurieChain;
|
|
13
14
|
/** Custom Fetch API implementation for making authenticated requests. */
|
|
14
15
|
fetch: Window['fetch'];
|
|
15
|
-
/** Resolver cache implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
16
|
-
cache:
|
|
16
|
+
/** Resolver cache implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
17
|
+
cache: CustomStorage;
|
|
17
18
|
/** Shared [Consola](https://github.com/nuxt-contrib/consola) instance. */
|
|
18
19
|
console: Consola;
|
|
19
20
|
};
|
|
@@ -30,8 +31,8 @@ export declare class Node<TGraph extends Graph> {
|
|
|
30
31
|
protected readonly _console: Consola;
|
|
31
32
|
/** Custom Fetch API implementation for making authenticated requests. */
|
|
32
33
|
protected readonly _fetch: Window['fetch'];
|
|
33
|
-
/** Resolver cache implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
34
|
-
protected readonly _cache:
|
|
34
|
+
/** Resolver cache implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
35
|
+
protected readonly _cache: CustomStorage;
|
|
35
36
|
/** Path to this resource node as base URL followed by a list of curies. */
|
|
36
37
|
protected readonly _path: CurieChain;
|
|
37
38
|
constructor(init: NodeInit);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Consola } from 'consola';
|
|
2
|
+
import type { CustomStorage } from './CustomStorage';
|
|
2
3
|
import type { FollowableResource } from '../FollowableResource';
|
|
3
4
|
import { Response as GlobalThisResponse } from 'cross-fetch';
|
|
4
5
|
import type { Graph } from '../Graph';
|
|
@@ -7,8 +8,8 @@ import type { Query } from '../Query';
|
|
|
7
8
|
declare type Init = ConstructorParameters<typeof globalThis.Response>[1] & {
|
|
8
9
|
/** Custom Fetch API implementation for making authenticated requests. */
|
|
9
10
|
fetch: Window['fetch'];
|
|
10
|
-
/** Resolver cache implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
11
|
-
cache:
|
|
11
|
+
/** Resolver cache implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
12
|
+
cache: CustomStorage;
|
|
12
13
|
/** Shared [Consola](https://github.com/nuxt-contrib/consola) instance. */
|
|
13
14
|
console: Consola;
|
|
14
15
|
/** Response body. Streams aren't supported at the moment: https://github.com/github/fetch/issues/746#issuecomment-573701120. */
|
|
@@ -28,8 +29,8 @@ export declare class Response<TGraph extends Graph, TQuery extends Query<TGraph>
|
|
|
28
29
|
protected readonly _console: Consola;
|
|
29
30
|
/** Custom Fetch API implementation for making authenticated requests. */
|
|
30
31
|
protected readonly _fetch: Window['fetch'];
|
|
31
|
-
/** Resolver cache implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
32
|
-
protected readonly _cache:
|
|
32
|
+
/** Resolver cache implementing CustomStorage based on [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API). */
|
|
33
|
+
protected readonly _cache: CustomStorage;
|
|
33
34
|
constructor(init: Init);
|
|
34
35
|
/**
|
|
35
36
|
* Gets JSON data from the response body and generates
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CustomStorage, CustomStorageSetOptions } from './API/CustomStorage';
|
|
2
|
+
export interface ScopedStorageOptions {
|
|
3
|
+
/** Scope to prefix item names with, e.g. scoping `customer` with `fx` will create an item named `fx.customer` in the storage. */
|
|
4
|
+
scope: string;
|
|
5
|
+
/** Storage instance implementing [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) to operate on. */
|
|
6
|
+
target: CustomStorage;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) wrapper
|
|
10
|
+
* working only with the items in the given scope.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ScopedStorage implements CustomStorage {
|
|
13
|
+
private __scope;
|
|
14
|
+
private __target;
|
|
15
|
+
constructor(options: ScopedStorageOptions);
|
|
16
|
+
key(index: number): string | null;
|
|
17
|
+
getItem(key: string): string | null;
|
|
18
|
+
setItem(key: string, value: string, options?: CustomStorageSetOptions): void;
|
|
19
|
+
removeItem(key: string): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
get length(): number;
|
|
22
|
+
private __isScopedKey;
|
|
23
|
+
private __getScopedKey;
|
|
24
|
+
private __getUnscopedKey;
|
|
25
|
+
}
|
|
@@ -4,5 +4,7 @@ export type { Query } from './Query';
|
|
|
4
4
|
export type { Graph } from './Graph';
|
|
5
5
|
export * as Nucleon from './Nucleon/index.js';
|
|
6
6
|
export { BooleanSelector } from './BooleanSelector.js';
|
|
7
|
+
export { MemoryStorage } from './MemoryStorage.js';
|
|
8
|
+
export { ScopedStorage } from './ScopedStorage.js';
|
|
7
9
|
export { Rumour } from './Rumour/index.js';
|
|
8
10
|
export { API } from './API/index.js';
|
|
@@ -9,8 +9,14 @@ import type { Graph } from './Graph';
|
|
|
9
9
|
* You can use @foxy.io/sdk prior to 1.0.0-beta.15 or a custom API client until you transition.
|
|
10
10
|
*/
|
|
11
11
|
export declare class API extends Core.API<Graph> {
|
|
12
|
-
/** Storage key for session
|
|
13
|
-
static readonly
|
|
12
|
+
/** Storage key for customer session token. */
|
|
13
|
+
static readonly SESSION_TOKEN = "customer";
|
|
14
|
+
/** Storage key for max session lifetime value (ms, stored as string). */
|
|
15
|
+
static readonly EXPIRY = "customer.expiry";
|
|
16
|
+
/** Storage key for JWT representing authenticated customer. */
|
|
17
|
+
static readonly JWT = "customer.jwt";
|
|
18
|
+
/** Storage key for SSO URL. */
|
|
19
|
+
static readonly SSO = "customer.sso";
|
|
14
20
|
/** Validators for the method arguments in this class (internal). */
|
|
15
21
|
static readonly v8n: {
|
|
16
22
|
classConstructor: any;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foxy.io/sdk",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-beta.3",
|
|
5
5
|
"description": "Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
7
7
|
"module": "dist/esm/index.js",
|