@communecter/cocolight-api-client 1.0.54 → 1.0.56
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/401.cocolight-api-client.browser.js +1 -0
- package/dist/401.cocolight-api-client.cjs +1 -0
- package/dist/401.cocolight-api-client.mjs.js +1 -0
- package/dist/588.cocolight-api-client.browser.js +1 -0
- package/dist/588.cocolight-api-client.cjs +1 -0
- package/dist/588.cocolight-api-client.mjs.js +1 -0
- package/dist/593.cocolight-api-client.browser.js +1 -0
- package/dist/593.cocolight-api-client.cjs +1 -0
- package/dist/593.cocolight-api-client.mjs.js +1 -0
- package/dist/839.cocolight-api-client.browser.js +1 -0
- package/dist/839.cocolight-api-client.cjs +1 -0
- package/dist/839.cocolight-api-client.mjs.js +1 -0
- package/dist/cocolight-api-client.browser.js +3 -3
- package/dist/cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.mjs.js +1 -1
- package/dist/cocolight-api-client.vite.mjs.js +1 -1
- package/dist/cocolight-api-client.vite.mjs.js.map +1 -1
- package/package.json +29 -17
- package/src/{Api.js → Api.ts} +85 -95
- package/src/{ApiClient.js → ApiClient.ts} +436 -247
- package/src/EJSONType.ts +103 -0
- package/src/api/{Badge.js → Badge.ts} +56 -45
- package/src/api/BaseEntity.ts +3890 -0
- package/src/api/Comment.ts +200 -0
- package/src/api/{EndpointApi.js → EndpointApi.ts} +363 -297
- package/src/api/EndpointApi.types.ts +4609 -0
- package/src/api/EntityRegistry.ts +203 -0
- package/src/api/Event.ts +332 -0
- package/src/api/News.ts +331 -0
- package/src/api/{Organization.js → Organization.ts} +155 -119
- package/src/api/{Poi.js → Poi.ts} +68 -60
- package/src/api/{Project.js → Project.ts} +150 -127
- package/src/api/{User.js → User.ts} +321 -256
- package/src/api/UserApi.ts +148 -0
- package/src/api/serverDataType/Comment.ts +88 -0
- package/src/api/serverDataType/Event.ts +80 -0
- package/src/api/serverDataType/News.ts +138 -0
- package/src/api/serverDataType/Organization.ts +80 -0
- package/src/api/serverDataType/Project.ts +71 -0
- package/src/api/serverDataType/User.ts +103 -0
- package/src/api/serverDataType/common.ts +80 -0
- package/src/endpoints.module.ts +2621 -0
- package/src/error.ts +86 -0
- package/src/index.ts +86 -0
- package/src/mixin/UserMixin.ts +4 -0
- package/src/types/api-responses.ts +217 -0
- package/src/types/entities.ts +22 -0
- package/src/types/error-guards.ts +230 -0
- package/src/types/index.ts +39 -0
- package/src/types/payloads.ts +21 -0
- package/src/types/transforms.ts +110 -0
- package/src/utils/{FileOfflineStorageStrategy.node.js → FileOfflineStorageStrategy.node.ts} +15 -12
- package/src/utils/{FileStorageStrategy.node.js → FileStorageStrategy.node.ts} +16 -39
- package/src/utils/MultiServerFileStorageStrategy.node.ts +67 -0
- package/src/utils/MultiServerTokenStorageStrategy.ts +139 -0
- package/src/utils/{OfflineClientManager.js → OfflineClientManager.ts} +82 -86
- package/src/utils/OfflineQueueStorageStrategy.ts +47 -0
- package/src/utils/TokenStorage.ts +77 -0
- package/src/utils/compat.ts +12 -0
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.ts +35 -0
- package/src/utils/{createDefaultOfflineStrategy.js → createDefaultOfflineStrategy.ts} +8 -3
- package/src/utils/createDefaultTokenStorageStrategy.ts +33 -0
- package/src/utils/{reactive.js → reactive.ts} +49 -40
- package/src/utils/stream-utils.node.ts +12 -0
- package/types/Api.d.ts +38 -82
- package/types/Api.d.ts.map +1 -0
- package/types/ApiClient.d.ts +244 -184
- package/types/ApiClient.d.ts.map +1 -0
- package/types/EJSONType.d.ts +48 -22
- package/types/EJSONType.d.ts.map +1 -0
- package/types/api/Badge.d.ts +20 -20
- package/types/api/Badge.d.ts.map +1 -0
- package/types/api/BaseEntity.d.ts +751 -446
- package/types/api/BaseEntity.d.ts.map +1 -0
- package/types/api/Comment.d.ts +36 -0
- package/types/api/EndpointApi.d.ts +347 -295
- package/types/api/EndpointApi.d.ts.map +1 -0
- package/types/api/EndpointApi.types.d.ts +3914 -4133
- package/types/api/EntityRegistry.d.ts +18 -16
- package/types/api/EntityRegistry.d.ts.map +1 -0
- package/types/api/Event.d.ts +119 -35
- package/types/api/Event.d.ts.map +1 -0
- package/types/api/News.d.ts +52 -20
- package/types/api/News.d.ts.map +1 -0
- package/types/api/Organization.d.ts +165 -49
- package/types/api/Organization.d.ts.map +1 -0
- package/types/api/Poi.d.ts +51 -22
- package/types/api/Poi.d.ts.map +1 -0
- package/types/api/Project.d.ts +151 -52
- package/types/api/Project.d.ts.map +1 -0
- package/types/api/User.d.ts +222 -93
- package/types/api/User.d.ts.map +1 -0
- package/types/api/UserApi.d.ts +60 -9
- package/types/api/UserApi.d.ts.map +1 -0
- package/types/api/serverDataType/Comment.d.ts +83 -0
- package/types/api/serverDataType/Event.d.ts +67 -0
- package/types/api/serverDataType/News.d.ts +130 -0
- package/types/api/serverDataType/Organization.d.ts +65 -0
- package/types/api/serverDataType/Organization.d.ts.map +1 -0
- package/types/api/serverDataType/Project.d.ts +58 -0
- package/types/api/serverDataType/Project.d.ts.map +1 -0
- package/types/api/serverDataType/User.d.ts +86 -0
- package/types/api/serverDataType/User.d.ts.map +1 -0
- package/types/api/serverDataType/common.d.ts +71 -0
- package/types/api/serverDataType/common.d.ts.map +1 -0
- package/types/endpoints.module.d.ts +6922 -1215
- package/types/endpoints.module.d.ts.map +1 -0
- package/types/error.d.ts +25 -51
- package/types/error.d.ts.map +1 -0
- package/types/index.d.ts +55 -48
- package/types/index.d.ts.map +1 -0
- package/types/mixin/UserMixin.d.ts +1 -1
- package/types/mixin/UserMixin.d.ts.map +1 -0
- package/types/types/api-responses.d.ts +190 -0
- package/types/types/api-responses.d.ts.map +1 -0
- package/types/types/entities.d.ts +17 -0
- package/types/types/entities.d.ts.map +1 -0
- package/types/types/error-guards.d.ts +99 -0
- package/types/types/error-guards.d.ts.map +1 -0
- package/types/types/index.d.ts +7 -0
- package/types/types/payloads.d.ts +17 -0
- package/types/types/payloads.d.ts.map +1 -0
- package/types/types/transforms.d.ts +79 -0
- package/types/types/transforms.d.ts.map +1 -0
- package/types/utils/FileOfflineStorageStrategy.node.d.ts +10 -9
- package/types/utils/FileOfflineStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/FileStorageStrategy.node.d.ts +9 -20
- package/types/utils/FileStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/MultiServerFileStorageStrategy.node.d.ts +13 -18
- package/types/utils/MultiServerFileStorageStrategy.node.d.ts.map +1 -0
- package/types/utils/MultiServerTokenStorageStrategy.d.ts +30 -51
- package/types/utils/MultiServerTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/OfflineClientManager.d.ts +52 -88
- package/types/utils/OfflineClientManager.d.ts.map +1 -0
- package/types/utils/OfflineQueueStorageStrategy.d.ts +12 -9
- package/types/utils/OfflineQueueStorageStrategy.d.ts.map +1 -0
- package/types/utils/TokenStorage.d.ts +20 -70
- package/types/utils/TokenStorage.d.ts.map +1 -0
- package/types/utils/compat.d.ts +4 -0
- package/types/utils/compat.d.ts.map +1 -0
- package/types/utils/createDefaultMultiServerTokenStorageStrategy.d.ts +2 -11
- package/types/utils/createDefaultMultiServerTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/createDefaultOfflineStrategy.d.ts +2 -3
- package/types/utils/createDefaultOfflineStrategy.d.ts.map +1 -0
- package/types/utils/createDefaultTokenStorageStrategy.d.ts +2 -12
- package/types/utils/createDefaultTokenStorageStrategy.d.ts.map +1 -0
- package/types/utils/reactive.d.ts +10 -16
- package/types/utils/reactive.d.ts.map +1 -0
- package/types/utils/stream-utils.node.d.ts +3 -2
- package/types/utils/stream-utils.node.d.ts.map +1 -0
- package/dist/123.cocolight-api-client.browser.js +0 -1
- package/dist/123.cocolight-api-client.cjs +0 -1
- package/dist/22.cocolight-api-client.mjs.js +0 -1
- package/dist/339.cocolight-api-client.mjs.js +0 -1
- package/dist/394.cocolight-api-client.browser.js +0 -1
- package/dist/394.cocolight-api-client.cjs +0 -1
- package/dist/405.cocolight-api-client.browser.js +0 -1
- package/dist/405.cocolight-api-client.cjs +0 -1
- package/dist/774.cocolight-api-client.mjs.js +0 -1
- package/dist/790.cocolight-api-client.mjs.js +0 -1
- package/dist/931.cocolight-api-client.browser.js +0 -1
- package/dist/931.cocolight-api-client.cjs +0 -1
- package/src/EJSONType.js +0 -53
- package/src/api/BaseEntity.js +0 -2828
- package/src/api/EntityRegistry.js +0 -152
- package/src/api/Event.js +0 -226
- package/src/api/News.js +0 -244
- package/src/api/UserApi.js +0 -81
- package/src/endpoints.module.js +0 -5
- package/src/error.js +0 -121
- package/src/index.js +0 -97
- package/src/mixin/UserMixin.js +0 -8
- package/src/utils/MultiServerFileStorageStrategy.node.js +0 -87
- package/src/utils/MultiServerTokenStorageStrategy.js +0 -188
- package/src/utils/OfflineQueueStorageStrategy.js +0 -51
- package/src/utils/TokenStorage.js +0 -153
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.js +0 -51
- package/src/utils/createDefaultTokenStorageStrategy.js +0 -49
- package/src/utils/stream-utils.node.js +0 -10
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import os from "os";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
import { MultiServerTokenStorageStrategy } from "./MultiServerTokenStorageStrategy.js";
|
|
6
|
-
|
|
7
|
-
/** @typedef {import("./MultiServerTokenStorageStrategy.js").MultiServerTokenStorageStrategy} MultiServerTokenStorageStrategy */
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Stockage fichier (Node uniquement) multi-serveurs.
|
|
11
|
-
* @implements {MultiServerTokenStorageStrategy}
|
|
12
|
-
*/
|
|
13
|
-
export class MultiServerFileStorageStrategy extends MultiServerTokenStorageStrategy {
|
|
14
|
-
/**
|
|
15
|
-
* @param {string} [filename="tokens.json"]
|
|
16
|
-
* @param {string} [dir=path.join(os.homedir(), ".config", "cocolight")]
|
|
17
|
-
*/
|
|
18
|
-
constructor(filename = "tokens.json", dir = path.join(os.homedir(), ".config", "cocolight")) {
|
|
19
|
-
super();
|
|
20
|
-
/** @type {string} */
|
|
21
|
-
this.filePath = path.join(dir, filename);
|
|
22
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** @private */
|
|
26
|
-
_readFile() {
|
|
27
|
-
if (!fs.existsSync(this.filePath)) return {};
|
|
28
|
-
try {
|
|
29
|
-
return JSON.parse(fs.readFileSync(this.filePath, "utf8"));
|
|
30
|
-
} catch {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** @private
|
|
36
|
-
* @param {Record<string, {accessToken?: string|null, refreshToken?: string|null}>} data
|
|
37
|
-
*/
|
|
38
|
-
_writeFile(data) {
|
|
39
|
-
fs.writeFileSync(this.filePath, JSON.stringify(data, null, 2), "utf8");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** @returns {string|null} */
|
|
43
|
-
getAccessToken() {
|
|
44
|
-
this._ensureContext();
|
|
45
|
-
return this._readFile()[this._currentBaseURL]?.accessToken ?? null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** @param {string|null} token */
|
|
49
|
-
setAccessToken(token) {
|
|
50
|
-
this._ensureContext();
|
|
51
|
-
const all = this._readFile();
|
|
52
|
-
all[this._currentBaseURL] = { ...(all[this._currentBaseURL] || {}), accessToken: token };
|
|
53
|
-
this._writeFile(all);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** @returns {string|null} */
|
|
57
|
-
getRefreshToken() {
|
|
58
|
-
this._ensureContext();
|
|
59
|
-
return this._readFile()[this._currentBaseURL]?.refreshToken ?? null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** @param {string|null} token */
|
|
63
|
-
setRefreshToken(token) {
|
|
64
|
-
this._ensureContext();
|
|
65
|
-
const all = this._readFile();
|
|
66
|
-
all[this._currentBaseURL] = { ...(all[this._currentBaseURL] || {}), refreshToken: token };
|
|
67
|
-
this._writeFile(all);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** @returns {void} */
|
|
71
|
-
clear() {
|
|
72
|
-
this._ensureContext();
|
|
73
|
-
const all = this._readFile();
|
|
74
|
-
delete all[this._currentBaseURL];
|
|
75
|
-
this._writeFile(all);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** @returns {string[]} */
|
|
79
|
-
getServers() {
|
|
80
|
-
return Object.keys(this._readFile());
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** @returns {Record<string, {accessToken?: string|null, refreshToken?: string|null}>} */
|
|
84
|
-
exportAll() {
|
|
85
|
-
return this._readFile();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { TokenStorageStrategy } from "./TokenStorage.js";
|
|
2
|
-
|
|
3
|
-
/** @typedef {import("./TokenStorage.js").TokenStorageStrategy} TokenStorageStrategy */
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Stratégie de stockage multi-serveurs (abstraite).
|
|
7
|
-
* Permet de sélectionner un `baseURL` courant via `use()` puis d'opérer get/set/clear dessus.
|
|
8
|
-
* @abstract
|
|
9
|
-
* @extends TokenStorageStrategy
|
|
10
|
-
*/
|
|
11
|
-
export class MultiServerTokenStorageStrategy extends TokenStorageStrategy {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
/** @type {string|null} */
|
|
15
|
-
this._currentBaseURL = null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Sélectionne le serveur courant (normalise en supprimant les `/` finaux).
|
|
20
|
-
* @param {string} baseURL
|
|
21
|
-
* @returns {void}
|
|
22
|
-
*/
|
|
23
|
-
use(baseURL) {
|
|
24
|
-
if (!baseURL) throw new Error("baseURL est requis");
|
|
25
|
-
this._currentBaseURL = baseURL.replace(/\/+$/, "");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** @private */
|
|
29
|
-
_ensureContext() {
|
|
30
|
-
if (!this._currentBaseURL) throw new Error("baseURL non défini. Appelez use(baseURL)");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Retourne la liste des serveurs connus.
|
|
35
|
-
* @abstract
|
|
36
|
-
* @returns {string[]}
|
|
37
|
-
*/
|
|
38
|
-
getServers() {
|
|
39
|
-
throw new Error("getServers() doit être implémenté");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Exporte toutes les données stockées (par baseURL).
|
|
44
|
-
* @abstract
|
|
45
|
-
* @returns {Record<string, {accessToken?: string|null, refreshToken?: string|null}>}
|
|
46
|
-
*/
|
|
47
|
-
exportAll() {
|
|
48
|
-
throw new Error("exportAll() doit être implémenté");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Stockage en mémoire (multi-serveurs).
|
|
54
|
-
* @implements {MultiServerTokenStorageStrategy}
|
|
55
|
-
*/
|
|
56
|
-
export class MultiServerMemoryStorageStrategy extends MultiServerTokenStorageStrategy {
|
|
57
|
-
constructor() {
|
|
58
|
-
super();
|
|
59
|
-
/** @type {Map<string, {accessToken?: string|null, refreshToken?: string|null}>} */
|
|
60
|
-
this._storage = new Map();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** @returns {string|null} */
|
|
64
|
-
getAccessToken() {
|
|
65
|
-
this._ensureContext();
|
|
66
|
-
return this._storage.get(this._currentBaseURL)?.accessToken ?? null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** @param {string|null} token */
|
|
70
|
-
setAccessToken(token) {
|
|
71
|
-
this._ensureContext();
|
|
72
|
-
const current = this._storage.get(this._currentBaseURL) || {};
|
|
73
|
-
this._storage.set(this._currentBaseURL, { ...current, accessToken: token });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @returns {string|null} */
|
|
77
|
-
getRefreshToken() {
|
|
78
|
-
this._ensureContext();
|
|
79
|
-
return this._storage.get(this._currentBaseURL)?.refreshToken ?? null;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** @param {string|null} token */
|
|
83
|
-
setRefreshToken(token) {
|
|
84
|
-
this._ensureContext();
|
|
85
|
-
const current = this._storage.get(this._currentBaseURL) || {};
|
|
86
|
-
this._storage.set(this._currentBaseURL, { ...current, refreshToken: token });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** @returns {void} */
|
|
90
|
-
clear() {
|
|
91
|
-
this._ensureContext();
|
|
92
|
-
this._storage.delete(this._currentBaseURL);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** @returns {string[]} */
|
|
96
|
-
getServers() {
|
|
97
|
-
return [...this._storage.keys()];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** @returns {Record<string, {accessToken?: string|null, refreshToken?: string|null}>} */
|
|
101
|
-
exportAll() {
|
|
102
|
-
return Object.fromEntries(this._storage.entries());
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Stockage navigateur (localStorage) multi-serveurs.
|
|
108
|
-
* @implements {MultiServerTokenStorageStrategy}
|
|
109
|
-
*/
|
|
110
|
-
export class MultiServerLocalStorageStrategy extends MultiServerTokenStorageStrategy {
|
|
111
|
-
/**
|
|
112
|
-
* @param {string} [prefix="cocolight"]
|
|
113
|
-
*/
|
|
114
|
-
constructor(prefix = "cocolight") {
|
|
115
|
-
super();
|
|
116
|
-
/** @type {string} */
|
|
117
|
-
this.prefix = prefix;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** @private */
|
|
121
|
-
_key(baseURL) {
|
|
122
|
-
return `${this.prefix}_tokens_${baseURL}`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** @private */
|
|
126
|
-
_getData() {
|
|
127
|
-
this._ensureContext();
|
|
128
|
-
if (typeof localStorage === "undefined") return {};
|
|
129
|
-
const raw = localStorage.getItem(this._key(this._currentBaseURL));
|
|
130
|
-
return raw ? JSON.parse(raw) : {};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** @private */
|
|
134
|
-
_setData(data) {
|
|
135
|
-
if (typeof localStorage === "undefined") return;
|
|
136
|
-
localStorage.setItem(this._key(this._currentBaseURL), JSON.stringify(data));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** @returns {string|null} */
|
|
140
|
-
getAccessToken() {
|
|
141
|
-
return this._getData().accessToken ?? null;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** @param {string|null} token */
|
|
145
|
-
setAccessToken(token) {
|
|
146
|
-
const data = this._getData();
|
|
147
|
-
data.accessToken = token;
|
|
148
|
-
this._setData(data);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** @returns {string|null} */
|
|
152
|
-
getRefreshToken() {
|
|
153
|
-
return this._getData().refreshToken ?? null;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** @param {string|null} token */
|
|
157
|
-
setRefreshToken(token) {
|
|
158
|
-
const data = this._getData();
|
|
159
|
-
data.refreshToken = token;
|
|
160
|
-
this._setData(data);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** @returns {void} */
|
|
164
|
-
clear() {
|
|
165
|
-
if (typeof localStorage === "undefined") return;
|
|
166
|
-
localStorage.removeItem(this._key(this._currentBaseURL));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** @returns {string[]} */
|
|
170
|
-
getServers() {
|
|
171
|
-
if (typeof localStorage === "undefined") return [];
|
|
172
|
-
const keys = Object.keys(localStorage);
|
|
173
|
-
return keys
|
|
174
|
-
.filter(k => k.startsWith(`${this.prefix}_tokens_`))
|
|
175
|
-
.map(k => k.replace(`${this.prefix}_tokens_`, ""));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** @returns {Record<string, {accessToken?: string|null, refreshToken?: string|null}>} */
|
|
179
|
-
exportAll() {
|
|
180
|
-
const result = {};
|
|
181
|
-
for (const baseURL of this.getServers()) {
|
|
182
|
-
const key = this._key(baseURL);
|
|
183
|
-
const raw = typeof localStorage !== "undefined" ? localStorage.getItem(key) : null;
|
|
184
|
-
if (raw) result[baseURL] = JSON.parse(raw);
|
|
185
|
-
}
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// OfflineQueueStorageStrategy.js
|
|
2
|
-
|
|
3
|
-
export class OfflineQueueStorageStrategy {
|
|
4
|
-
async loadQueue() {
|
|
5
|
-
throw new Error("loadQueue() doit être implémenté");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line no-unused-vars
|
|
9
|
-
async saveQueue(queue) {
|
|
10
|
-
throw new Error("saveQueue(queue) doit être implémenté");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class MemoryOfflineStorage extends OfflineQueueStorageStrategy {
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
17
|
-
this._queue = [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async loadQueue() {
|
|
21
|
-
return this._queue;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async saveQueue(queue) {
|
|
25
|
-
this._queue = [...queue];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class LocalStorageOfflineStorage extends OfflineQueueStorageStrategy {
|
|
30
|
-
constructor(key = "cocolight-api-offline-queue") {
|
|
31
|
-
super();
|
|
32
|
-
this.key = key;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async loadQueue() {
|
|
36
|
-
try {
|
|
37
|
-
const raw = localStorage.getItem(this.key);
|
|
38
|
-
return raw ? JSON.parse(raw) : [];
|
|
39
|
-
} catch {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async saveQueue(queue) {
|
|
45
|
-
try {
|
|
46
|
-
localStorage.setItem(this.key, JSON.stringify(queue));
|
|
47
|
-
} catch (e) {
|
|
48
|
-
console.warn("[Offline] Échec du stockage localStorage", e);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stratégie abstraite de stockage des tokens d'accès et de rafraîchissement.
|
|
3
|
-
*
|
|
4
|
-
* @interface
|
|
5
|
-
*/
|
|
6
|
-
export class TokenStorageStrategy {
|
|
7
|
-
/**
|
|
8
|
-
* Récupère le token d'accès actuellement stocké.
|
|
9
|
-
*
|
|
10
|
-
* @abstract
|
|
11
|
-
* @returns {string|null} Le token d'accès, ou `null` si non défini.
|
|
12
|
-
*/
|
|
13
|
-
getAccessToken() {
|
|
14
|
-
throw new Error("getAccessToken() doit être implémenté");
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Définit le token d'accès.
|
|
19
|
-
*
|
|
20
|
-
* @abstract
|
|
21
|
-
* @param {string} token - Le token d'accès à stocker.
|
|
22
|
-
* @returns {void}
|
|
23
|
-
*/
|
|
24
|
-
// eslint-disable-next-line no-unused-vars
|
|
25
|
-
setAccessToken(token) {
|
|
26
|
-
throw new Error("setAccessToken() doit être implémenté");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Récupère le token de rafraîchissement actuellement stocké.
|
|
31
|
-
*
|
|
32
|
-
* @abstract
|
|
33
|
-
* @returns {string|null} Le token de rafraîchissement, ou `null` si non défini.
|
|
34
|
-
*/
|
|
35
|
-
getRefreshToken() {
|
|
36
|
-
throw new Error("getRefreshToken() doit être implémenté");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Définit le token de rafraîchissement.
|
|
41
|
-
*
|
|
42
|
-
* @abstract
|
|
43
|
-
* @param {string} token - Le token de rafraîchissement à stocker.
|
|
44
|
-
* @returns {void}
|
|
45
|
-
*/
|
|
46
|
-
// eslint-disable-next-line no-unused-vars
|
|
47
|
-
setRefreshToken(token) {
|
|
48
|
-
throw new Error("setRefreshToken() doit être implémenté");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Supprime les tokens stockés.
|
|
53
|
-
*
|
|
54
|
-
* @abstract
|
|
55
|
-
* @returns {void}
|
|
56
|
-
*/
|
|
57
|
-
clear() {
|
|
58
|
-
throw new Error("clear() doit être implémenté");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Stratégie de stockage des tokens uniquement en mémoire (volatile).
|
|
64
|
-
*
|
|
65
|
-
* @implements {TokenStorageStrategy}
|
|
66
|
-
*/
|
|
67
|
-
export class MemoryStorageStrategy extends TokenStorageStrategy {
|
|
68
|
-
constructor() {
|
|
69
|
-
super();
|
|
70
|
-
/** @type {string|null} */
|
|
71
|
-
this._accessToken = null;
|
|
72
|
-
/** @type {string|null} */
|
|
73
|
-
this._refreshToken = null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** @inheritdoc */
|
|
77
|
-
getAccessToken() {
|
|
78
|
-
return this._accessToken;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @inheritdoc */
|
|
82
|
-
setAccessToken(token) {
|
|
83
|
-
this._accessToken = token;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** @inheritdoc */
|
|
87
|
-
getRefreshToken() {
|
|
88
|
-
return this._refreshToken;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** @inheritdoc */
|
|
92
|
-
setRefreshToken(token) {
|
|
93
|
-
this._refreshToken = token;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** @inheritdoc */
|
|
97
|
-
clear() {
|
|
98
|
-
this._accessToken = null;
|
|
99
|
-
this._refreshToken = null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Stratégie de stockage des tokens via `localStorage` (persistance navigateur).
|
|
105
|
-
*
|
|
106
|
-
* @implements {TokenStorageStrategy}
|
|
107
|
-
*/
|
|
108
|
-
export class LocalStorageStrategy extends TokenStorageStrategy {
|
|
109
|
-
/**
|
|
110
|
-
* @param {string} [prefix="cocolight"] - Préfixe utilisé pour les clés dans `localStorage`.
|
|
111
|
-
*/
|
|
112
|
-
constructor(prefix = "cocolight") {
|
|
113
|
-
super();
|
|
114
|
-
/** @type {string} */
|
|
115
|
-
this.prefix = prefix;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** @inheritdoc */
|
|
119
|
-
getAccessToken() {
|
|
120
|
-
return typeof localStorage !== "undefined"
|
|
121
|
-
? localStorage.getItem(`${this.prefix}_accessToken`)
|
|
122
|
-
: null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** @inheritdoc */
|
|
126
|
-
setAccessToken(token) {
|
|
127
|
-
if (typeof localStorage !== "undefined") {
|
|
128
|
-
localStorage.setItem(`${this.prefix}_accessToken`, token);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** @inheritdoc */
|
|
133
|
-
getRefreshToken() {
|
|
134
|
-
return typeof localStorage !== "undefined"
|
|
135
|
-
? localStorage.getItem(`${this.prefix}_refreshToken`)
|
|
136
|
-
: null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** @inheritdoc */
|
|
140
|
-
setRefreshToken(token) {
|
|
141
|
-
if (typeof localStorage !== "undefined") {
|
|
142
|
-
localStorage.setItem(`${this.prefix}_refreshToken`, token);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** @inheritdoc */
|
|
147
|
-
clear() {
|
|
148
|
-
if (typeof localStorage !== "undefined") {
|
|
149
|
-
localStorage.removeItem(`${this.prefix}_accessToken`);
|
|
150
|
-
localStorage.removeItem(`${this.prefix}_refreshToken`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MultiServerMemoryStorageStrategy,
|
|
3
|
-
MultiServerLocalStorageStrategy,
|
|
4
|
-
} from "./MultiServerTokenStorageStrategy.js";
|
|
5
|
-
|
|
6
|
-
/** @typedef {import("./MultiServerTokenStorageStrategy.js").MultiServerTokenStorageStrategy} MultiServerTokenStorageStrategy */
|
|
7
|
-
/** @typedef {import("./MultiServerFileStorageStrategy.node.js").MultiServerFileStorageStrategy} MultiServerFileStorageStrategy */
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Crée une stratégie multi-serveurs adaptée à l’environnement.
|
|
11
|
-
*
|
|
12
|
-
* @param {'memory'|'localStorage'|'file'|'auto'} [strategyType="auto"]
|
|
13
|
-
* @returns {Promise<MultiServerTokenStorageStrategy>}
|
|
14
|
-
*/
|
|
15
|
-
export async function createDefaultMultiServerTokenStorageStrategy(strategyType = "auto") {
|
|
16
|
-
if (strategyType === "memory") {
|
|
17
|
-
/** @type {MultiServerTokenStorageStrategy} */
|
|
18
|
-
const s = new MultiServerMemoryStorageStrategy();
|
|
19
|
-
return s;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (strategyType === "localStorage") {
|
|
23
|
-
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
24
|
-
/** @type {MultiServerTokenStorageStrategy} */
|
|
25
|
-
const s = new MultiServerLocalStorageStrategy();
|
|
26
|
-
return s;
|
|
27
|
-
}
|
|
28
|
-
throw new Error("localStorage n’est pas disponible dans cet environnement.");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (strategyType === "file") {
|
|
32
|
-
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
33
|
-
throw new Error("Le stockage fichier n’est pas disponible côté navigateur.");
|
|
34
|
-
}
|
|
35
|
-
const { MultiServerFileStorageStrategy } = await import("./MultiServerFileStorageStrategy.node.js");
|
|
36
|
-
/** @type {MultiServerTokenStorageStrategy} */
|
|
37
|
-
const s = new MultiServerFileStorageStrategy();
|
|
38
|
-
return s;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// auto
|
|
42
|
-
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
43
|
-
/** @type {MultiServerTokenStorageStrategy} */
|
|
44
|
-
const s = new MultiServerLocalStorageStrategy();
|
|
45
|
-
return s;
|
|
46
|
-
}
|
|
47
|
-
const { MultiServerFileStorageStrategy } = await import("./MultiServerFileStorageStrategy.node.js");
|
|
48
|
-
/** @type {MultiServerTokenStorageStrategy} */
|
|
49
|
-
const s = new MultiServerFileStorageStrategy();
|
|
50
|
-
return s;
|
|
51
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { LocalStorageStrategy, MemoryStorageStrategy } from "./TokenStorage.js";
|
|
2
|
-
|
|
3
|
-
/** @typedef {import("./TokenStorage.js").TokenStorageStrategy} TokenStorageStrategy */
|
|
4
|
-
/** @typedef {import("./FileStorageStrategy.node.js").FileStorageStrategy} FileStorageStrategy */
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Crée une stratégie de stockage de jetons par défaut en fonction de l'option fournie.
|
|
8
|
-
*
|
|
9
|
-
* @param {'memory'|'localStorage'|'file'|'auto'} [tokenStorageStrategy='auto'] - Stratégie souhaitée.
|
|
10
|
-
* @returns {Promise<TokenStorageStrategy>} Une promesse résolue avec la stratégie sélectionnée.
|
|
11
|
-
* @throws {Error} Lève une erreur si la stratégie choisie n'est pas disponible.
|
|
12
|
-
*/
|
|
13
|
-
export async function createDefaultTokenStorageStrategy(tokenStorageStrategy = "auto") {
|
|
14
|
-
if (tokenStorageStrategy === "memory") {
|
|
15
|
-
/** @type {TokenStorageStrategy} */
|
|
16
|
-
const storage = new MemoryStorageStrategy();
|
|
17
|
-
return storage;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (tokenStorageStrategy === "localStorage") {
|
|
21
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
22
|
-
/** @type {TokenStorageStrategy} */
|
|
23
|
-
const storage = new LocalStorageStrategy();
|
|
24
|
-
return storage;
|
|
25
|
-
}
|
|
26
|
-
throw new Error("localStorage is not available in this environment.");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (tokenStorageStrategy === "file") {
|
|
30
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
31
|
-
throw new Error("file storage is not available in this environment.");
|
|
32
|
-
}
|
|
33
|
-
const { FileStorageStrategy } = await import("./FileStorageStrategy.node.js");
|
|
34
|
-
/** @type {TokenStorageStrategy} */
|
|
35
|
-
const storage = new FileStorageStrategy();
|
|
36
|
-
return storage;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 'auto'
|
|
40
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
41
|
-
/** @type {TokenStorageStrategy} */
|
|
42
|
-
const storage = new LocalStorageStrategy();
|
|
43
|
-
return storage;
|
|
44
|
-
}
|
|
45
|
-
const { FileStorageStrategy } = await import("./FileStorageStrategy.node.js");
|
|
46
|
-
/** @type {TokenStorageStrategy} */
|
|
47
|
-
const storage = new FileStorageStrategy();
|
|
48
|
-
return storage;
|
|
49
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// utils/stream-utils.node.js
|
|
2
|
-
export async function bufferToReadable(buffer) {
|
|
3
|
-
const { Readable } = await import("stream");
|
|
4
|
-
return Readable.from(buffer);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export async function createPassThrough() {
|
|
8
|
-
const { PassThrough } = await import("stream");
|
|
9
|
-
return new PassThrough();
|
|
10
|
-
}
|