@communecter/cocolight-api-client 1.0.155 → 1.0.156
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/1035.cocolight-api-client.browser.js +1 -1
- package/dist/1035.cocolight-api-client.cjs +1 -1
- package/dist/1483.cocolight-api-client.browser.js +1 -1
- package/dist/1483.cocolight-api-client.cjs +1 -1
- package/dist/1491.cocolight-api-client.browser.js +1 -1
- package/dist/1491.cocolight-api-client.cjs +1 -1
- package/dist/1494.cocolight-api-client.browser.js +1 -1
- package/dist/1494.cocolight-api-client.cjs +1 -1
- package/dist/1641.cocolight-api-client.browser.js +1 -1
- package/dist/1641.cocolight-api-client.cjs +1 -1
- package/dist/1678.cocolight-api-client.browser.js +1 -1
- package/dist/1678.cocolight-api-client.cjs +1 -1
- package/dist/2041.cocolight-api-client.browser.js +1 -1
- package/dist/2041.cocolight-api-client.cjs +1 -1
- package/dist/2302.cocolight-api-client.browser.js +1 -1
- package/dist/2302.cocolight-api-client.cjs +1 -1
- package/dist/2313.cocolight-api-client.browser.js +1 -1
- package/dist/2313.cocolight-api-client.cjs +1 -1
- package/dist/2379.cocolight-api-client.browser.js +1 -1
- package/dist/2379.cocolight-api-client.cjs +1 -1
- package/dist/2439.cocolight-api-client.browser.js +1 -1
- package/dist/2439.cocolight-api-client.cjs +1 -1
- package/dist/2594.cocolight-api-client.browser.js +1 -1
- package/dist/2594.cocolight-api-client.cjs +1 -1
- package/dist/2766.cocolight-api-client.browser.js +1 -1
- package/dist/2766.cocolight-api-client.cjs +1 -1
- package/dist/2812.cocolight-api-client.browser.js +1 -1
- package/dist/2812.cocolight-api-client.cjs +1 -1
- package/dist/2918.cocolight-api-client.browser.js +1 -1
- package/dist/2918.cocolight-api-client.cjs +1 -1
- package/dist/3028.cocolight-api-client.browser.js +1 -1
- package/dist/3028.cocolight-api-client.cjs +1 -1
- package/dist/3330.cocolight-api-client.browser.js +1 -1
- package/dist/3330.cocolight-api-client.cjs +1 -1
- package/dist/3371.cocolight-api-client.browser.js +1 -1
- package/dist/3371.cocolight-api-client.cjs +1 -1
- package/dist/3401.cocolight-api-client.browser.js +1 -1
- package/dist/3401.cocolight-api-client.cjs +1 -1
- package/dist/3516.cocolight-api-client.browser.js +1 -1
- package/dist/3516.cocolight-api-client.cjs +1 -1
- package/dist/3593.cocolight-api-client.browser.js +1 -1
- package/dist/3593.cocolight-api-client.cjs +1 -1
- package/dist/3764.cocolight-api-client.browser.js +1 -1
- package/dist/3764.cocolight-api-client.cjs +1 -1
- package/dist/3873.cocolight-api-client.browser.js +1 -1
- package/dist/3873.cocolight-api-client.cjs +1 -1
- package/dist/3911.cocolight-api-client.browser.js +1 -1
- package/dist/3911.cocolight-api-client.cjs +1 -1
- package/dist/4031.cocolight-api-client.browser.js +1 -1
- package/dist/4031.cocolight-api-client.cjs +1 -1
- package/dist/4152.cocolight-api-client.browser.js +1 -1
- package/dist/4152.cocolight-api-client.cjs +1 -1
- package/dist/4203.cocolight-api-client.browser.js +1 -1
- package/dist/4203.cocolight-api-client.cjs +1 -1
- package/dist/424.cocolight-api-client.browser.js +1 -1
- package/dist/424.cocolight-api-client.cjs +1 -1
- package/dist/435.cocolight-api-client.browser.js +1 -1
- package/dist/435.cocolight-api-client.cjs +1 -1
- package/dist/4402.cocolight-api-client.browser.js +1 -1
- package/dist/4402.cocolight-api-client.cjs +1 -1
- package/dist/4425.cocolight-api-client.browser.js +1 -1
- package/dist/4425.cocolight-api-client.cjs +1 -1
- package/dist/4472.cocolight-api-client.browser.js +1 -1
- package/dist/4472.cocolight-api-client.cjs +1 -1
- package/dist/4914.cocolight-api-client.browser.js +1 -1
- package/dist/4914.cocolight-api-client.cjs +1 -1
- package/dist/4959.cocolight-api-client.browser.js +1 -1
- package/dist/4959.cocolight-api-client.cjs +1 -1
- package/dist/5100.cocolight-api-client.browser.js +1 -1
- package/dist/5100.cocolight-api-client.cjs +1 -1
- package/dist/5111.cocolight-api-client.browser.js +1 -1
- package/dist/5111.cocolight-api-client.cjs +1 -1
- package/dist/5286.cocolight-api-client.browser.js +1 -1
- package/dist/5286.cocolight-api-client.cjs +1 -1
- package/dist/5380.cocolight-api-client.browser.js +1 -1
- package/dist/5380.cocolight-api-client.cjs +1 -1
- package/dist/5383.cocolight-api-client.browser.js +1 -1
- package/dist/5383.cocolight-api-client.cjs +1 -1
- package/dist/5480.cocolight-api-client.browser.js +1 -1
- package/dist/5480.cocolight-api-client.cjs +1 -1
- package/dist/5541.cocolight-api-client.browser.js +1 -1
- package/dist/5541.cocolight-api-client.cjs +1 -1
- package/dist/5839.cocolight-api-client.browser.js +1 -1
- package/dist/5839.cocolight-api-client.cjs +1 -1
- package/dist/5862.cocolight-api-client.browser.js +1 -1
- package/dist/5862.cocolight-api-client.cjs +1 -1
- package/dist/5869.cocolight-api-client.browser.js +1 -1
- package/dist/5869.cocolight-api-client.cjs +1 -1
- package/dist/588.cocolight-api-client.browser.js +1 -1
- package/dist/588.cocolight-api-client.cjs +1 -1
- package/dist/601.cocolight-api-client.browser.js +1 -1
- package/dist/601.cocolight-api-client.cjs +1 -1
- package/dist/6012.cocolight-api-client.browser.js +1 -1
- package/dist/6012.cocolight-api-client.cjs +1 -1
- package/dist/6200.cocolight-api-client.browser.js +1 -1
- package/dist/6200.cocolight-api-client.cjs +1 -1
- package/dist/6369.cocolight-api-client.browser.js +1 -1
- package/dist/6369.cocolight-api-client.cjs +1 -1
- package/dist/7009.cocolight-api-client.browser.js +1 -1
- package/dist/7009.cocolight-api-client.cjs +1 -1
- package/dist/725.cocolight-api-client.browser.js +1 -1
- package/dist/725.cocolight-api-client.cjs +1 -1
- package/dist/7320.cocolight-api-client.browser.js +1 -1
- package/dist/7339.cocolight-api-client.browser.js +1 -1
- package/dist/7339.cocolight-api-client.cjs +1 -1
- package/dist/7398.cocolight-api-client.browser.js +1 -1
- package/dist/7398.cocolight-api-client.cjs +1 -1
- package/dist/7888.cocolight-api-client.browser.js +1 -1
- package/dist/7888.cocolight-api-client.cjs +1 -1
- package/dist/7975.cocolight-api-client.browser.js +1 -1
- package/dist/7975.cocolight-api-client.cjs +1 -1
- package/dist/809.cocolight-api-client.browser.js +1 -1
- package/dist/809.cocolight-api-client.cjs +1 -1
- package/dist/8300.cocolight-api-client.browser.js +1 -1
- package/dist/8300.cocolight-api-client.cjs +1 -1
- package/dist/8317.cocolight-api-client.browser.js +1 -1
- package/dist/8317.cocolight-api-client.cjs +1 -1
- package/dist/8525.cocolight-api-client.browser.js +1 -1
- package/dist/8525.cocolight-api-client.cjs +1 -1
- package/dist/8894.cocolight-api-client.browser.js +1 -1
- package/dist/8894.cocolight-api-client.cjs +1 -1
- package/dist/9301.cocolight-api-client.browser.js +1 -1
- package/dist/9301.cocolight-api-client.cjs +1 -1
- package/dist/9438.cocolight-api-client.browser.js +1 -1
- package/dist/9438.cocolight-api-client.cjs +1 -1
- package/dist/9478.cocolight-api-client.browser.js +1 -1
- package/dist/9478.cocolight-api-client.cjs +1 -1
- package/dist/9568.cocolight-api-client.browser.js +1 -1
- package/dist/9568.cocolight-api-client.cjs +1 -1
- package/dist/cocolight-api-client.browser.js +6 -6
- package/dist/cocolight-api-client.cjs +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 +7 -17
- package/types/Api.d.ts +1 -0
- package/types/ApiClient.d.ts +10 -1
- package/types/api/BaseEntity.d.ts +2 -0
- package/types/utils/OfflineClientManager.d.ts +8 -0
- package/dist/1035.cocolight-api-client.mjs.js +0 -1
- package/dist/1483.cocolight-api-client.mjs.js +0 -1
- package/dist/1491.cocolight-api-client.mjs.js +0 -1
- package/dist/1494.cocolight-api-client.mjs.js +0 -1
- package/dist/1641.cocolight-api-client.mjs.js +0 -1
- package/dist/1678.cocolight-api-client.mjs.js +0 -1
- package/dist/2041.cocolight-api-client.mjs.js +0 -1
- package/dist/2302.cocolight-api-client.mjs.js +0 -1
- package/dist/2313.cocolight-api-client.mjs.js +0 -1
- package/dist/2379.cocolight-api-client.mjs.js +0 -1
- package/dist/2439.cocolight-api-client.mjs.js +0 -1
- package/dist/2594.cocolight-api-client.mjs.js +0 -1
- package/dist/2766.cocolight-api-client.mjs.js +0 -1
- package/dist/2812.cocolight-api-client.mjs.js +0 -1
- package/dist/2918.cocolight-api-client.mjs.js +0 -1
- package/dist/3028.cocolight-api-client.mjs.js +0 -1
- package/dist/3330.cocolight-api-client.mjs.js +0 -1
- package/dist/3371.cocolight-api-client.mjs.js +0 -1
- package/dist/3401.cocolight-api-client.mjs.js +0 -1
- package/dist/3516.cocolight-api-client.mjs.js +0 -1
- package/dist/3593.cocolight-api-client.mjs.js +0 -1
- package/dist/3764.cocolight-api-client.mjs.js +0 -1
- package/dist/3873.cocolight-api-client.mjs.js +0 -1
- package/dist/3911.cocolight-api-client.mjs.js +0 -1
- package/dist/4031.cocolight-api-client.mjs.js +0 -1
- package/dist/4152.cocolight-api-client.mjs.js +0 -1
- package/dist/4203.cocolight-api-client.mjs.js +0 -1
- package/dist/424.cocolight-api-client.mjs.js +0 -1
- package/dist/435.cocolight-api-client.mjs.js +0 -1
- package/dist/4402.cocolight-api-client.mjs.js +0 -1
- package/dist/4425.cocolight-api-client.mjs.js +0 -1
- package/dist/4472.cocolight-api-client.mjs.js +0 -1
- package/dist/4914.cocolight-api-client.mjs.js +0 -1
- package/dist/4959.cocolight-api-client.mjs.js +0 -1
- package/dist/5100.cocolight-api-client.mjs.js +0 -1
- package/dist/5111.cocolight-api-client.mjs.js +0 -1
- package/dist/5286.cocolight-api-client.mjs.js +0 -1
- package/dist/5380.cocolight-api-client.mjs.js +0 -1
- package/dist/5383.cocolight-api-client.mjs.js +0 -1
- package/dist/5480.cocolight-api-client.mjs.js +0 -1
- package/dist/5541.cocolight-api-client.mjs.js +0 -1
- package/dist/5839.cocolight-api-client.mjs.js +0 -1
- package/dist/5862.cocolight-api-client.mjs.js +0 -1
- package/dist/5869.cocolight-api-client.mjs.js +0 -1
- package/dist/588.cocolight-api-client.mjs.js +0 -1
- package/dist/601.cocolight-api-client.mjs.js +0 -1
- package/dist/6012.cocolight-api-client.mjs.js +0 -1
- package/dist/6200.cocolight-api-client.mjs.js +0 -1
- package/dist/6369.cocolight-api-client.mjs.js +0 -1
- package/dist/7009.cocolight-api-client.mjs.js +0 -1
- package/dist/725.cocolight-api-client.mjs.js +0 -1
- package/dist/7339.cocolight-api-client.mjs.js +0 -1
- package/dist/7398.cocolight-api-client.mjs.js +0 -1
- package/dist/7888.cocolight-api-client.mjs.js +0 -1
- package/dist/7975.cocolight-api-client.mjs.js +0 -1
- package/dist/809.cocolight-api-client.mjs.js +0 -1
- package/dist/8300.cocolight-api-client.mjs.js +0 -1
- package/dist/8317.cocolight-api-client.mjs.js +0 -1
- package/dist/8525.cocolight-api-client.mjs.js +0 -1
- package/dist/8894.cocolight-api-client.mjs.js +0 -1
- package/dist/9301.cocolight-api-client.mjs.js +0 -1
- package/dist/9438.cocolight-api-client.mjs.js +0 -1
- package/dist/9478.cocolight-api-client.mjs.js +0 -1
- package/dist/9568.cocolight-api-client.mjs.js +0 -1
- package/dist/cocolight-api-client.mjs.js +0 -1
- package/src/Api.ts +0 -348
- package/src/ApiClient.ts +0 -1994
- package/src/EJSONType.ts +0 -103
- package/src/api/Action.ts +0 -665
- package/src/api/Answer.ts +0 -1392
- package/src/api/Badge.ts +0 -143
- package/src/api/BaseEntity.ts +0 -6384
- package/src/api/Classified.ts +0 -175
- package/src/api/Comment.ts +0 -280
- package/src/api/EndpointApi.ts +0 -2270
- package/src/api/EndpointApi.types.ts +0 -6566
- package/src/api/EntityRegistry.ts +0 -324
- package/src/api/Event.ts +0 -360
- package/src/api/Form.ts +0 -282
- package/src/api/News.ts +0 -547
- package/src/api/Notifications.ts +0 -196
- package/src/api/Organization.ts +0 -771
- package/src/api/Poi.ts +0 -242
- package/src/api/Project.ts +0 -545
- package/src/api/User.ts +0 -1889
- package/src/api/UserApi.ts +0 -192
- package/src/api/serverDataType/Action.ts +0 -177
- package/src/api/serverDataType/Answer.ts +0 -106
- package/src/api/serverDataType/Classified.ts +0 -152
- package/src/api/serverDataType/Comment.ts +0 -88
- package/src/api/serverDataType/Country.ts +0 -1
- package/src/api/serverDataType/Event.ts +0 -112
- package/src/api/serverDataType/Form.ts +0 -157
- package/src/api/serverDataType/News.ts +0 -138
- package/src/api/serverDataType/Notification.ts +0 -81
- package/src/api/serverDataType/Organization.ts +0 -111
- package/src/api/serverDataType/Poi.ts +0 -75
- package/src/api/serverDataType/Project.ts +0 -115
- package/src/api/serverDataType/User.ts +0 -112
- package/src/api/serverDataType/Zone.ts +0 -33
- package/src/api/serverDataType/common.ts +0 -84
- package/src/costum/normalize.ts +0 -7
- package/src/costum/registry.ts +0 -138
- package/src/costum/runtime-map.ts +0 -221
- package/src/costum/runtime.ts +0 -274
- package/src/costum/schemas/CercleTravailleursSociauxLiberauxLaPlumeSociale.ts +0 -19
- package/src/costum/schemas/FabEn.ts +0 -19
- package/src/costum/schemas/LivingLabInnovationSocialeBraspanon.ts +0 -19
- package/src/costum/schemas/alfph.ts +0 -27
- package/src/costum/schemas/campagne.ts +0 -19
- package/src/costum/schemas/chtitube.ts +0 -19
- package/src/costum/schemas/circuitCourt.ts +0 -19
- package/src/costum/schemas/cmcasHauteBretagne.ts +0 -19
- package/src/costum/schemas/coFinancementTierslieux.ts +0 -27
- package/src/costum/schemas/coeurNumerique.ts +0 -19
- package/src/costum/schemas/communLundi.ts +0 -19
- package/src/costum/schemas/cressReunion.ts +0 -35
- package/src/costum/schemas/cressReunionNetwork.ts +0 -35
- package/src/costum/schemas/ctenat.ts +0 -43
- package/src/costum/schemas/cyberReunion.ts +0 -19
- package/src/costum/schemas/ekisphere.ts +0 -35
- package/src/costum/schemas/equipementsSportifs974.ts +0 -19
- package/src/costum/schemas/federationDesCae.ts +0 -19
- package/src/costum/schemas/formationGenerique.ts +0 -35
- package/src/costum/schemas/franceTierslieux.ts +0 -19
- package/src/costum/schemas/hinaura.ts +0 -27
- package/src/costum/schemas/hubmayotte.ts +0 -19
- package/src/costum/schemas/hubnouvellecaledonie.ts +0 -19
- package/src/costum/schemas/hubpolynesiefrancaise.ts +0 -19
- package/src/costum/schemas/hubreunion.ts +0 -19
- package/src/costum/schemas/hubterritoires.ts +0 -19
- package/src/costum/schemas/hubwallisetfutuna.ts +0 -19
- package/src/costum/schemas/hva.ts +0 -27
- package/src/costum/schemas/ibv2.ts +0 -19
- package/src/costum/schemas/institutBleu.ts +0 -19
- package/src/costum/schemas/journalInsoumisChambery.ts +0 -27
- package/src/costum/schemas/kpacite.ts +0 -19
- package/src/costum/schemas/laCompagnieDesTierslieux.ts +0 -43
- package/src/costum/schemas/laMaisonDesFaiseurs.ts +0 -19
- package/src/costum/schemas/laReunionPourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/laSemaineDesTierslieux.ts +0 -19
- package/src/costum/schemas/labEnCommuns.ts +0 -19
- package/src/costum/schemas/lakou.ts +0 -27
- package/src/costum/schemas/lesCommunsDesTierslieux.ts +0 -19
- package/src/costum/schemas/mayottePourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/meir.ts +0 -27
- package/src/costum/schemas/navigatorDesTierslieux.ts +0 -19
- package/src/costum/schemas/notragora.ts +0 -27
- package/src/costum/schemas/nouvellecaledoniePourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/openAtlas.ts +0 -19
- package/src/costum/schemas/polynesieFrancaisePourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/schemas/prdr.ts +0 -19
- package/src/costum/schemas/reseauTierslieux.ts +0 -19
- package/src/costum/schemas/rfflabs.ts +0 -19
- package/src/costum/schemas/ries.ts +0 -19
- package/src/costum/schemas/siteDuPactePourLaTransition.ts +0 -27
- package/src/costum/schemas/sportSanteBienetre.ts +0 -43
- package/src/costum/schemas/suppa.ts +0 -19
- package/src/costum/schemas/terramies.ts +0 -19
- package/src/costum/schemas/testeTplFormation.ts +0 -35
- package/src/costum/schemas/tierslieuxbelgique.ts +0 -19
- package/src/costum/schemas/tierslieuxorg1.ts +0 -35
- package/src/costum/schemas/transiter.ts +0 -35
- package/src/costum/schemas/vhelioPeiTour2025.ts +0 -19
- package/src/costum/schemas/wallisetfutunaPourUnNumeriqueInclusif.ts +0 -19
- package/src/costum/symbol.ts +0 -26
- package/src/costum/types.ts +0 -895
- package/src/endpoints.module.ts +0 -4253
- package/src/error.ts +0 -86
- package/src/forms/entityForm.ts +0 -142
- package/src/index.ts +0 -161
- package/src/mixin/UserMixin.ts +0 -4
- package/src/types/api-responses.ts +0 -217
- package/src/types/entities.ts +0 -58
- package/src/types/error-guards.ts +0 -230
- package/src/types/index.ts +0 -41
- package/src/types/payloads.ts +0 -21
- package/src/types/transforms.ts +0 -119
- package/src/utils/FileOfflineStorageStrategy.node.ts +0 -50
- package/src/utils/FileStorageStrategy.node.ts +0 -63
- package/src/utils/MultiServerFileStorageStrategy.node.ts +0 -67
- package/src/utils/MultiServerTokenStorageStrategy.ts +0 -139
- package/src/utils/OfflineClientManager.ts +0 -216
- package/src/utils/OfflineQueueStorageStrategy.ts +0 -47
- package/src/utils/TokenStorage.ts +0 -77
- package/src/utils/compat.ts +0 -12
- package/src/utils/createDefaultMultiServerTokenStorageStrategy.ts +0 -35
- package/src/utils/createDefaultOfflineStrategy.ts +0 -34
- package/src/utils/createDefaultTokenStorageStrategy.ts +0 -33
- package/src/utils/reactive.ts +0 -243
- package/src/utils/stream-utils.node.ts +0 -12
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { TokenStorageStrategy } from "./TokenStorage.js";
|
|
2
|
-
|
|
3
|
-
export abstract class MultiServerTokenStorageStrategy extends TokenStorageStrategy {
|
|
4
|
-
protected _currentBaseURL: string | null = null;
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
use(baseURL: string): void {
|
|
11
|
-
if (!baseURL) throw new Error("baseURL est requis");
|
|
12
|
-
this._currentBaseURL = baseURL.replace(/\/+$/, "");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
protected _ensureContext(): void {
|
|
16
|
-
if (!this._currentBaseURL) throw new Error("baseURL non défini. Appelez use(baseURL)");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
protected _requireBaseURL(): string {
|
|
20
|
-
this._ensureContext();
|
|
21
|
-
return this._currentBaseURL!;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
abstract getServers(): string[];
|
|
25
|
-
abstract exportAll(): Record<string, { accessToken?: string | null; refreshToken?: string | null }>;
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class MultiServerMemoryStorageStrategy extends MultiServerTokenStorageStrategy {
|
|
30
|
-
private _storage = new Map<string, { accessToken?: string | null; refreshToken?: string | null }>();
|
|
31
|
-
|
|
32
|
-
constructor() {
|
|
33
|
-
super();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getAccessToken(): string | null {
|
|
37
|
-
const base = this._requireBaseURL();
|
|
38
|
-
return this._storage.get(base)?.accessToken ?? null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
setAccessToken(token: string | null): void {
|
|
42
|
-
const base = this._requireBaseURL();
|
|
43
|
-
const current = this._storage.get(base) || {};
|
|
44
|
-
this._storage.set(base, { ...current, accessToken: token });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getRefreshToken(): string | null {
|
|
48
|
-
const base = this._requireBaseURL();
|
|
49
|
-
return this._storage.get(base)?.refreshToken ?? null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setRefreshToken(token: string | null): void {
|
|
53
|
-
const base = this._requireBaseURL();
|
|
54
|
-
const current = this._storage.get(base) || {};
|
|
55
|
-
this._storage.set(base, { ...current, refreshToken: token });
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
clear(): void {
|
|
59
|
-
const base = this._requireBaseURL();
|
|
60
|
-
this._storage.delete(base);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
getServers(): string[] {
|
|
64
|
-
return Array.from(this._storage.keys());
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
exportAll(): Record<string, { accessToken?: string | null; refreshToken?: string | null }> {
|
|
68
|
-
return Object.fromEntries(this._storage.entries());
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export class MultiServerLocalStorageStrategy extends MultiServerTokenStorageStrategy {
|
|
73
|
-
public readonly prefix: string;
|
|
74
|
-
|
|
75
|
-
constructor(prefix: string = "cocolight") {
|
|
76
|
-
super();
|
|
77
|
-
this.prefix = prefix;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private _key(baseURL: string): string {
|
|
81
|
-
return `${this.prefix}_tokens_${baseURL}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private _getData(): any {
|
|
85
|
-
this._ensureContext();
|
|
86
|
-
if (typeof localStorage === "undefined") return {};
|
|
87
|
-
const raw = localStorage.getItem(this._key(this._currentBaseURL!));
|
|
88
|
-
return raw ? JSON.parse(raw) : {};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private _setData(data: any): void {
|
|
92
|
-
if (typeof localStorage === "undefined") return;
|
|
93
|
-
localStorage.setItem(this._key(this._currentBaseURL!), JSON.stringify(data));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
getAccessToken(): string | null {
|
|
97
|
-
return this._getData().accessToken ?? null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setAccessToken(token: string | null): void {
|
|
101
|
-
const data = this._getData();
|
|
102
|
-
data.accessToken = token;
|
|
103
|
-
this._setData(data);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
getRefreshToken(): string | null {
|
|
107
|
-
return this._getData().refreshToken ?? null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setRefreshToken(token: string | null): void {
|
|
111
|
-
const data = this._getData();
|
|
112
|
-
data.refreshToken = token;
|
|
113
|
-
this._setData(data);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
clear(): void {
|
|
117
|
-
if (typeof localStorage === "undefined") return;
|
|
118
|
-
localStorage.removeItem(this._key(this._currentBaseURL!));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getServers(): string[] {
|
|
122
|
-
if (typeof localStorage === "undefined") return [];
|
|
123
|
-
const keys = Object.keys(localStorage);
|
|
124
|
-
return keys
|
|
125
|
-
.filter(k => k.startsWith(`${this.prefix}_tokens_`))
|
|
126
|
-
.map(k => k.replace(`${this.prefix}_tokens_`, ""));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
exportAll(): Record<string, { accessToken?: string | null; refreshToken?: string | null }> {
|
|
130
|
-
const result: Record<string, { accessToken?: string | null; refreshToken?: string | null }> = {};
|
|
131
|
-
|
|
132
|
-
for (const baseURL of this.getServers()) {
|
|
133
|
-
const key = this._key(baseURL);
|
|
134
|
-
const raw = typeof localStorage !== "undefined" ? localStorage.getItem(key) : null;
|
|
135
|
-
if (raw) result[baseURL] = JSON.parse(raw);
|
|
136
|
-
}
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// OfflineClientManager.ts
|
|
2
|
-
import ApiClient from "../ApiClient.js";
|
|
3
|
-
import { createDefaultOfflineStrategy } from "./createDefaultOfflineStrategy.js";
|
|
4
|
-
import { OfflineQueueStorageStrategy } from "./OfflineQueueStorageStrategy.js";
|
|
5
|
-
|
|
6
|
-
type OfflineQueueStorageStrategyAction = import("./OfflineQueueStorageStrategy.js").OfflineQueueStorageStrategy<OfflineAction>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Métadonnées nécessaires pour rejouer une action offline sur le bon serveur.
|
|
10
|
-
*/
|
|
11
|
-
interface OfflineActionMeta {
|
|
12
|
-
baseURL: string;
|
|
13
|
-
accessToken?: string | null;
|
|
14
|
-
refreshToken?: string | null;
|
|
15
|
-
timestamp: number; // Epoch ms de l'enfilement.
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Options passées à l'appel de l'endpoint lors du replay.
|
|
20
|
-
*/
|
|
21
|
-
interface OfflineActionOptions {
|
|
22
|
-
transformResponseData?: boolean | ((...args: any[]) => any);
|
|
23
|
-
validateResponseSchema?: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Élément de la file d'attente offline.
|
|
28
|
-
*/
|
|
29
|
-
export interface OfflineAction {
|
|
30
|
-
constant: string; // Nom de l'endpoint à appeler.
|
|
31
|
-
data: unknown; // Payload d'entrée (forme dépendante de l'endpoint).
|
|
32
|
-
options?: OfflineActionOptions;
|
|
33
|
-
meta: OfflineActionMeta;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Options d'attache du gestionnaire offline.
|
|
38
|
-
*/
|
|
39
|
-
interface AttachOptions {
|
|
40
|
-
offlineStorageStrategy?: "auto" | "memory" | "localStorage" | "file";
|
|
41
|
-
disableOfflineMonitoring?: boolean;
|
|
42
|
-
interval?: number; // Intervalle de ping réseau (ms), relayé à startOfflineMonitoring.
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class OfflineClientManager {
|
|
46
|
-
private _clients: Map<string, any>;
|
|
47
|
-
private _client: any;
|
|
48
|
-
private _offlineMode: boolean | undefined;
|
|
49
|
-
private _pingInterval: ReturnType<typeof setInterval> | undefined;
|
|
50
|
-
private _offlineQueueStorage: OfflineQueueStorageStrategyAction | undefined;
|
|
51
|
-
private _offlineQueue: OfflineAction[];
|
|
52
|
-
private _monitoringStarted: boolean | undefined;
|
|
53
|
-
|
|
54
|
-
constructor(apiClient: any) {
|
|
55
|
-
if (!apiClient || !(apiClient instanceof ApiClient)) {
|
|
56
|
-
throw new Error("[OfflineClientManager] apiClient doit être une instance de ApiClient");
|
|
57
|
-
}
|
|
58
|
-
this._clients = new Map();
|
|
59
|
-
this._client = apiClient;
|
|
60
|
-
this._offlineMode = undefined;
|
|
61
|
-
this._pingInterval = undefined;
|
|
62
|
-
this._offlineQueueStorage = undefined;
|
|
63
|
-
this._offlineQueue = [];
|
|
64
|
-
this._monitoringStarted = undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static async attachTo(apiClient: any, options: AttachOptions = {}): Promise<any> {
|
|
68
|
-
apiClient._offlineClientManager = new OfflineClientManager(apiClient);
|
|
69
|
-
const strategy = await createDefaultOfflineStrategy(options?.offlineStorageStrategy || "auto");
|
|
70
|
-
await apiClient._offlineClientManager._initOfflineQueue(strategy);
|
|
71
|
-
if (!options?.disableOfflineMonitoring) {
|
|
72
|
-
apiClient._offlineClientManager.startOfflineMonitoring(options);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async getClient(meta: OfflineActionMeta): Promise<any> {
|
|
77
|
-
const key = `${meta.baseURL}|${meta.accessToken}`;
|
|
78
|
-
if (this._clients.has(key)) return this._clients.get(key);
|
|
79
|
-
|
|
80
|
-
const client = new ApiClient({
|
|
81
|
-
baseURL: meta.baseURL,
|
|
82
|
-
accessToken: meta.accessToken,
|
|
83
|
-
refreshToken: meta.refreshToken,
|
|
84
|
-
debug: this._client._debug,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
this._clients.set(key, client);
|
|
88
|
-
return client;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async replayAction(action: OfflineAction): Promise<any> {
|
|
92
|
-
const client = await this.getClient(action.meta);
|
|
93
|
-
try {
|
|
94
|
-
const result = await client.callEndpoint(
|
|
95
|
-
action.constant,
|
|
96
|
-
action.data,
|
|
97
|
-
action.options?.transformResponseData ?? true,
|
|
98
|
-
action.options?.validateResponseSchema ?? true
|
|
99
|
-
);
|
|
100
|
-
this._client._logger.info(`[OfflineReplay] Succès ${action.constant} sur ${action.meta.baseURL}`);
|
|
101
|
-
return result;
|
|
102
|
-
} catch (err) {
|
|
103
|
-
this._client._logger.error(`[OfflineReplay] Échec ${action.constant}`, (err as Error).message);
|
|
104
|
-
throw err;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
startOfflineMonitoring({ interval = 30000, disableOfflineMonitoring = false }: Pick<AttachOptions, "interval" | "disableOfflineMonitoring"> = {}) {
|
|
109
|
-
if (disableOfflineMonitoring || this._monitoringStarted) return;
|
|
110
|
-
|
|
111
|
-
this._monitoringStarted = true;
|
|
112
|
-
this._offlineMode = typeof window !== "undefined" && typeof navigator !== "undefined" && !navigator.onLine;
|
|
113
|
-
|
|
114
|
-
if (typeof window !== "undefined") {
|
|
115
|
-
window.addEventListener("online", () => this.setOfflineMode(false));
|
|
116
|
-
window.addEventListener("offline", () => this.setOfflineMode(true));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this._pingInterval = setInterval(async () => {
|
|
120
|
-
const wasOffline = this._offlineMode;
|
|
121
|
-
try {
|
|
122
|
-
await this._client._client.head("/api/cocolight/infoserver", { timeout: 5000 });
|
|
123
|
-
if (wasOffline) this.setOfflineMode(false);
|
|
124
|
-
|
|
125
|
-
} catch {
|
|
126
|
-
this._client._logger.error("[OfflineMonitor] ping() échoué → passage en offline");
|
|
127
|
-
this.setOfflineMode(true);
|
|
128
|
-
}
|
|
129
|
-
}, interval);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
setOfflineMode(isOffline: boolean) {
|
|
133
|
-
if (this._offlineMode === isOffline) return;
|
|
134
|
-
this._offlineMode = isOffline;
|
|
135
|
-
if (typeof this._client.emit === "function") {
|
|
136
|
-
this._client.emit("offlineModeChanged", isOffline);
|
|
137
|
-
}
|
|
138
|
-
this._client._logger.info(`[ApiClient] Mode offline : ${isOffline} (set depuis monitoring)`);
|
|
139
|
-
|
|
140
|
-
if (!isOffline && typeof this._replayOfflineQueue === "function") {
|
|
141
|
-
this._replayOfflineQueue();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
isOffline(): boolean {
|
|
146
|
-
return !!this._offlineMode;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async _enqueueOfflineAction({ constant, data, options = {} }: { constant: string; data: unknown; options?: OfflineActionOptions }): Promise<any> {
|
|
150
|
-
if (!this._offlineQueueStorage) {
|
|
151
|
-
throw new Error("[OfflineClientManager] _offlineQueueStorage non initialisé");
|
|
152
|
-
}
|
|
153
|
-
const hasToken = this._client.getToken() || this._client.getRefreshToken();
|
|
154
|
-
const endpoint = this._client._endpoints.find((e: any) => e.constant === constant);
|
|
155
|
-
const authPolicy = endpoint?.authPolicy || (endpoint?.auth === "none" ? "none" : "required");
|
|
156
|
-
if (authPolicy === "required" && !hasToken) {
|
|
157
|
-
this._client._logger.warn(`[Offline] Action ignorée : token requis mais absent (${constant})`);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const action: OfflineAction = {
|
|
162
|
-
constant,
|
|
163
|
-
data,
|
|
164
|
-
options,
|
|
165
|
-
meta: {
|
|
166
|
-
baseURL: this._client._baseURL,
|
|
167
|
-
accessToken: this._client.getToken(),
|
|
168
|
-
refreshToken: this._client.getRefreshToken(),
|
|
169
|
-
timestamp: Date.now()
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
this._offlineQueue.push(action);
|
|
174
|
-
await this._offlineQueueStorage.saveQueue(this._offlineQueue);
|
|
175
|
-
this._client._logger.info(`[Offline] Action mise en file : ${constant}`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async _replayOfflineQueue(): Promise<any> {
|
|
179
|
-
if (!this._offlineQueueStorage) {
|
|
180
|
-
throw new Error("[OfflineClientManager] _offlineQueueStorage non initialisé");
|
|
181
|
-
}
|
|
182
|
-
const queueCopy = [...this._offlineQueue];
|
|
183
|
-
this._offlineQueue = [];
|
|
184
|
-
await this._offlineQueueStorage.saveQueue([]);
|
|
185
|
-
|
|
186
|
-
for (const action of queueCopy) {
|
|
187
|
-
const endpoint = this._client._endpoints.find((e: any) => e.constant === action.constant);
|
|
188
|
-
const authPolicy = endpoint?.authPolicy || (endpoint?.auth === "none" ? "none" : "required");
|
|
189
|
-
const hasToken = action.meta.accessToken || action.meta.refreshToken;
|
|
190
|
-
|
|
191
|
-
if (authPolicy === "required" && !hasToken) {
|
|
192
|
-
this._client._logger.warn(`[Offline] Rejetée : token requis manquant (${action.constant})`);
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
try {
|
|
197
|
-
await this.replayAction(action);
|
|
198
|
-
} catch (e) {
|
|
199
|
-
this._client._logger.error("[Offline] Relecture échouée :", (e as Error).message);
|
|
200
|
-
this._offlineQueue.push(action); // requeue si erreur
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
await this._offlineQueueStorage.saveQueue(this._offlineQueue);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async _initOfflineQueue(storageStrategy: OfflineQueueStorageStrategyAction): Promise<any> {
|
|
208
|
-
if(!storageStrategy || !(storageStrategy instanceof OfflineQueueStorageStrategy)) {
|
|
209
|
-
throw new Error("[OfflineClientManager] storageStrategy doit être une instance de OfflineQueueStorageStrategy");
|
|
210
|
-
}
|
|
211
|
-
this._offlineQueueStorage = storageStrategy;
|
|
212
|
-
this._offlineQueue = await storageStrategy.loadQueue();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export default OfflineClientManager;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export abstract class OfflineQueueStorageStrategy<T = any> {
|
|
2
|
-
abstract loadQueue(): Promise<T[]>;
|
|
3
|
-
abstract saveQueue(queue: T[]): Promise<void>;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export class MemoryOfflineStorage<T = any> extends OfflineQueueStorageStrategy<T> {
|
|
7
|
-
private _queue: T[] = [];
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async loadQueue(): Promise<T[]> {
|
|
14
|
-
return this._queue;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async saveQueue(queue: T[]): Promise<void> {
|
|
18
|
-
this._queue = [...queue];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class LocalStorageOfflineStorage<T = any> extends OfflineQueueStorageStrategy<T> {
|
|
23
|
-
public readonly key: string;
|
|
24
|
-
|
|
25
|
-
constructor(key: string = "cocolight-api-offline-queue") {
|
|
26
|
-
super();
|
|
27
|
-
this.key = key;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async loadQueue(): Promise<T[]> {
|
|
31
|
-
try {
|
|
32
|
-
const raw = localStorage.getItem(this.key);
|
|
33
|
-
const parsed: T[] | null = raw ? JSON.parse(raw) : null;
|
|
34
|
-
return parsed ?? [];
|
|
35
|
-
} catch {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async saveQueue(queue: T[]): Promise<void> {
|
|
41
|
-
try {
|
|
42
|
-
localStorage.setItem(this.key, JSON.stringify(queue));
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.warn("[Offline] Échec du stockage localStorage", e);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export abstract class TokenStorageStrategy {
|
|
2
|
-
abstract getAccessToken(): string | null;
|
|
3
|
-
abstract setAccessToken(token: string | null): void;
|
|
4
|
-
abstract getRefreshToken(): string | null;
|
|
5
|
-
abstract setRefreshToken(token: string | null): void;
|
|
6
|
-
abstract clear(): void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class MemoryStorageStrategy extends TokenStorageStrategy {
|
|
10
|
-
private _accessToken: string | null = null;
|
|
11
|
-
private _refreshToken: string | null = null;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
super();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getAccessToken(): string | null {
|
|
18
|
-
return this._accessToken;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
setAccessToken(token: string | null): void {
|
|
22
|
-
this._accessToken = token;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
getRefreshToken(): string | null {
|
|
26
|
-
return this._refreshToken;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setRefreshToken(token: string | null): void {
|
|
30
|
-
this._refreshToken = token;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
clear(): void {
|
|
34
|
-
this._accessToken = null;
|
|
35
|
-
this._refreshToken = null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class LocalStorageStrategy extends TokenStorageStrategy {
|
|
40
|
-
public readonly prefix: string;
|
|
41
|
-
|
|
42
|
-
constructor(prefix: string = "cocolight") {
|
|
43
|
-
super();
|
|
44
|
-
this.prefix = prefix;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getAccessToken(): string | null {
|
|
48
|
-
return typeof localStorage !== "undefined"
|
|
49
|
-
? localStorage.getItem(`${this.prefix}_accessToken`)
|
|
50
|
-
: null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
setAccessToken(token: string | null): void {
|
|
54
|
-
if (typeof localStorage !== "undefined") {
|
|
55
|
-
localStorage.setItem(`${this.prefix}_accessToken`, token ?? "");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getRefreshToken(): string | null {
|
|
60
|
-
return typeof localStorage !== "undefined"
|
|
61
|
-
? localStorage.getItem(`${this.prefix}_refreshToken`)
|
|
62
|
-
: null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
setRefreshToken(token: string | null): void {
|
|
66
|
-
if (typeof localStorage !== "undefined") {
|
|
67
|
-
localStorage.setItem(`${this.prefix}_refreshToken`, token ?? "");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
clear(): void {
|
|
72
|
-
if (typeof localStorage !== "undefined") {
|
|
73
|
-
localStorage.removeItem(`${this.prefix}_accessToken`);
|
|
74
|
-
localStorage.removeItem(`${this.prefix}_refreshToken`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/utils/compat.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// utils/compat.ts - Compatibility layer for default imports
|
|
2
|
-
const _def = <T>(m: T & { default?: any }): any => (m && m.default) ? m.default : m;
|
|
3
|
-
|
|
4
|
-
import * as AjvNS from "ajv";
|
|
5
|
-
import * as addFormatsNS from "ajv-formats";
|
|
6
|
-
import * as EJSONNS from "ejson";
|
|
7
|
-
import * as pinoNS from "pino";
|
|
8
|
-
|
|
9
|
-
export const Ajv = _def(AjvNS); // constructible
|
|
10
|
-
export const addFormats = _def(addFormatsNS); // callable
|
|
11
|
-
export const pino = _def(pinoNS); // callable
|
|
12
|
-
export const EJSON = _def(EJSONNS); // default safe
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MultiServerMemoryStorageStrategy,
|
|
3
|
-
MultiServerLocalStorageStrategy,
|
|
4
|
-
type MultiServerTokenStorageStrategy,
|
|
5
|
-
} from "./MultiServerTokenStorageStrategy.js";
|
|
6
|
-
|
|
7
|
-
export async function createDefaultMultiServerTokenStorageStrategy(
|
|
8
|
-
strategyType: "memory" | "localStorage" | "file" | "auto" = "auto"
|
|
9
|
-
): Promise<MultiServerTokenStorageStrategy> {
|
|
10
|
-
if (strategyType === "memory") {
|
|
11
|
-
return new MultiServerMemoryStorageStrategy();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (strategyType === "localStorage") {
|
|
15
|
-
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
16
|
-
return new MultiServerLocalStorageStrategy();
|
|
17
|
-
}
|
|
18
|
-
throw new Error("localStorage n'est pas disponible dans cet environnement.");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (strategyType === "file") {
|
|
22
|
-
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
23
|
-
throw new Error("Le stockage fichier n'est pas disponible côté navigateur.");
|
|
24
|
-
}
|
|
25
|
-
const { MultiServerFileStorageStrategy } = await import("./MultiServerFileStorageStrategy.node.js");
|
|
26
|
-
return new MultiServerFileStorageStrategy();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// auto
|
|
30
|
-
if (typeof window !== "undefined" && typeof window.localStorage !== "undefined") {
|
|
31
|
-
return new MultiServerLocalStorageStrategy();
|
|
32
|
-
}
|
|
33
|
-
const { MultiServerFileStorageStrategy } = await import("./MultiServerFileStorageStrategy.node.js");
|
|
34
|
-
return new MultiServerFileStorageStrategy();
|
|
35
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { LocalStorageOfflineStorage, MemoryOfflineStorage, type OfflineQueueStorageStrategy } from "./OfflineQueueStorageStrategy.js";
|
|
2
|
-
|
|
3
|
-
export async function createDefaultOfflineStrategy<T = any>(
|
|
4
|
-
offlineStorageStrategy: "auto" | "memory" | "localStorage" | "file" = "auto"
|
|
5
|
-
): Promise<OfflineQueueStorageStrategy<T>> {
|
|
6
|
-
if (offlineStorageStrategy === "memory") {
|
|
7
|
-
return new MemoryOfflineStorage();
|
|
8
|
-
}
|
|
9
|
-
if (offlineStorageStrategy === "localStorage") {
|
|
10
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
11
|
-
return new LocalStorageOfflineStorage();
|
|
12
|
-
} else {
|
|
13
|
-
throw new Error("localStorage is not available in this environment.");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (offlineStorageStrategy === "file") {
|
|
17
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
18
|
-
throw new Error("file storage is not available in this environment.");
|
|
19
|
-
}
|
|
20
|
-
const { FileOfflineStorage } = await import("./FileOfflineStorageStrategy.node.js");
|
|
21
|
-
return new FileOfflineStorage();
|
|
22
|
-
}
|
|
23
|
-
if (offlineStorageStrategy === "auto") {
|
|
24
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
25
|
-
return new LocalStorageOfflineStorage();
|
|
26
|
-
} else {
|
|
27
|
-
const { FileOfflineStorage } = await import("./FileOfflineStorageStrategy.node.js");
|
|
28
|
-
return new FileOfflineStorage();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Handle unexpected strategy values
|
|
33
|
-
throw new Error(`Unsupported offline storage strategy: ${offlineStorageStrategy}`);
|
|
34
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { LocalStorageStrategy, MemoryStorageStrategy } from "./TokenStorage.js";
|
|
2
|
-
|
|
3
|
-
import type { TokenStorageStrategy } from "./TokenStorage.js";
|
|
4
|
-
|
|
5
|
-
export async function createDefaultTokenStorageStrategy(
|
|
6
|
-
tokenStorageStrategy: "memory" | "localStorage" | "file" | "auto" = "auto"
|
|
7
|
-
): Promise<TokenStorageStrategy> {
|
|
8
|
-
if (tokenStorageStrategy === "memory") {
|
|
9
|
-
return new MemoryStorageStrategy();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (tokenStorageStrategy === "localStorage") {
|
|
13
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
14
|
-
return new LocalStorageStrategy();
|
|
15
|
-
}
|
|
16
|
-
throw new Error("localStorage is not available in this environment.");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (tokenStorageStrategy === "file") {
|
|
20
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
21
|
-
throw new Error("file storage is not available in this environment.");
|
|
22
|
-
}
|
|
23
|
-
const { FileStorageStrategy } = await import("./FileStorageStrategy.node.js");
|
|
24
|
-
return new FileStorageStrategy();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 'auto'
|
|
28
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
29
|
-
return new LocalStorageStrategy();
|
|
30
|
-
}
|
|
31
|
-
const { FileStorageStrategy } = await import("./FileStorageStrategy.node.js");
|
|
32
|
-
return new FileStorageStrategy();
|
|
33
|
-
}
|