@djangocfg/api 2.1.331 → 2.1.332
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/auth-server.cjs +250 -189
- package/dist/auth-server.cjs.map +1 -1
- package/dist/auth-server.mjs +250 -189
- package/dist/auth-server.mjs.map +1 -1
- package/dist/auth.cjs +249 -188
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +249 -188
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +248 -187
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +24 -49
- package/dist/clients.d.ts +24 -49
- package/dist/clients.mjs +248 -187
- package/dist/clients.mjs.map +1 -1
- package/dist/index.cjs +332 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +689 -653
- package/dist/index.d.ts +689 -653
- package/dist/index.mjs +332 -234
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/_cfg_accounts/api.ts +29 -82
- package/src/_api/generated/_cfg_accounts/index.ts +4 -4
- package/src/_api/generated/_cfg_centrifugo/api.ts +29 -82
- package/src/_api/generated/_cfg_centrifugo/index.ts +4 -4
- package/src/_api/generated/_cfg_totp/api.ts +29 -82
- package/src/_api/generated/_cfg_totp/index.ts +4 -4
- package/src/_api/generated/client.gen.ts +3 -0
- package/src/_api/generated/helpers/auth.ts +223 -0
- package/src/_api/generated/helpers/index.ts +1 -0
- package/src/_api/generated/index.ts +17 -13
package/dist/index.mjs
CHANGED
|
@@ -353,14 +353,14 @@ var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
|
|
|
353
353
|
return url;
|
|
354
354
|
}, "defaultPathSerializer");
|
|
355
355
|
var getUrl = /* @__PURE__ */ __name(({
|
|
356
|
-
baseUrl
|
|
356
|
+
baseUrl,
|
|
357
357
|
path,
|
|
358
358
|
query,
|
|
359
359
|
querySerializer,
|
|
360
360
|
url: _url
|
|
361
361
|
}) => {
|
|
362
362
|
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
363
|
-
let url = (
|
|
363
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
364
364
|
if (path) {
|
|
365
365
|
url = defaultPathSerializer({ path, url });
|
|
366
366
|
}
|
|
@@ -391,15 +391,15 @@ function getValidRequestBody(options) {
|
|
|
391
391
|
__name(getValidRequestBody, "getValidRequestBody");
|
|
392
392
|
|
|
393
393
|
// src/_api/generated/core/auth.gen.ts
|
|
394
|
-
var getAuthToken = /* @__PURE__ */ __name(async (
|
|
395
|
-
const token = typeof callback === "function" ? await callback(
|
|
394
|
+
var getAuthToken = /* @__PURE__ */ __name(async (auth2, callback) => {
|
|
395
|
+
const token = typeof callback === "function" ? await callback(auth2) : callback;
|
|
396
396
|
if (!token) {
|
|
397
397
|
return;
|
|
398
398
|
}
|
|
399
|
-
if (
|
|
399
|
+
if (auth2.scheme === "bearer") {
|
|
400
400
|
return `Bearer ${token}`;
|
|
401
401
|
}
|
|
402
|
-
if (
|
|
402
|
+
if (auth2.scheme === "basic") {
|
|
403
403
|
return `Basic ${btoa(token)}`;
|
|
404
404
|
}
|
|
405
405
|
return token;
|
|
@@ -488,16 +488,16 @@ var setAuthParams = /* @__PURE__ */ __name(async ({
|
|
|
488
488
|
security,
|
|
489
489
|
...options
|
|
490
490
|
}) => {
|
|
491
|
-
for (const
|
|
492
|
-
if (checkForExistence(options,
|
|
491
|
+
for (const auth2 of security) {
|
|
492
|
+
if (checkForExistence(options, auth2.name)) {
|
|
493
493
|
continue;
|
|
494
494
|
}
|
|
495
|
-
const token = await getAuthToken(
|
|
495
|
+
const token = await getAuthToken(auth2, options.auth);
|
|
496
496
|
if (!token) {
|
|
497
497
|
continue;
|
|
498
498
|
}
|
|
499
|
-
const name =
|
|
500
|
-
switch (
|
|
499
|
+
const name = auth2.name ?? "Authorization";
|
|
500
|
+
switch (auth2.in) {
|
|
501
501
|
case "query":
|
|
502
502
|
if (!options.query) {
|
|
503
503
|
options.query = {};
|
|
@@ -825,95 +825,206 @@ var createClient = /* @__PURE__ */ __name((config = {}) => {
|
|
|
825
825
|
// src/_api/generated/client.gen.ts
|
|
826
826
|
var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
|
|
827
827
|
|
|
828
|
-
// src/_api/generated/helpers/
|
|
829
|
-
var
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
828
|
+
// src/_api/generated/helpers/auth.ts
|
|
829
|
+
var ACCESS_KEY = "cfg.access_token";
|
|
830
|
+
var REFRESH_KEY = "cfg.refresh_token";
|
|
831
|
+
var API_KEY_KEY = "cfg.api_key";
|
|
832
|
+
var isBrowser = typeof window !== "undefined";
|
|
833
|
+
var localStorageBackend = {
|
|
834
|
+
get(key) {
|
|
835
|
+
if (!isBrowser) return null;
|
|
835
836
|
try {
|
|
836
837
|
return window.localStorage.getItem(key);
|
|
837
838
|
} catch {
|
|
838
839
|
return null;
|
|
839
840
|
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
if (
|
|
841
|
+
},
|
|
842
|
+
set(key, value) {
|
|
843
|
+
if (!isBrowser) return;
|
|
843
844
|
try {
|
|
844
|
-
window.localStorage.
|
|
845
|
+
if (value === null) window.localStorage.removeItem(key);
|
|
846
|
+
else window.localStorage.setItem(key, value);
|
|
845
847
|
} catch {
|
|
846
848
|
}
|
|
847
849
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
+
};
|
|
851
|
+
var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
|
|
852
|
+
var cookieBackend = {
|
|
853
|
+
get(key) {
|
|
854
|
+
if (!isBrowser) return null;
|
|
850
855
|
try {
|
|
851
|
-
|
|
856
|
+
const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
|
|
857
|
+
const m = document.cookie.match(re);
|
|
858
|
+
return m ? decodeURIComponent(m[1]) : null;
|
|
852
859
|
} catch {
|
|
860
|
+
return null;
|
|
853
861
|
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
if (
|
|
862
|
+
},
|
|
863
|
+
set(key, value) {
|
|
864
|
+
if (!isBrowser) return;
|
|
857
865
|
try {
|
|
858
|
-
|
|
866
|
+
const k = encodeURIComponent(key);
|
|
867
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
868
|
+
if (value === null) {
|
|
869
|
+
document.cookie = `${k}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
870
|
+
} else {
|
|
871
|
+
const v = encodeURIComponent(value);
|
|
872
|
+
document.cookie = `${k}=${v}; Path=/; Max-Age=${COOKIE_MAX_AGE}; SameSite=Lax${secure}`;
|
|
873
|
+
}
|
|
859
874
|
} catch {
|
|
860
875
|
}
|
|
861
876
|
}
|
|
862
877
|
};
|
|
863
|
-
var
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
this.store.delete(key);
|
|
876
|
-
}
|
|
877
|
-
clear() {
|
|
878
|
-
this.store.clear();
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
var CookieStorageAdapter = class {
|
|
882
|
-
constructor(opts = {}) {
|
|
883
|
-
this.opts = opts;
|
|
884
|
-
}
|
|
885
|
-
static {
|
|
886
|
-
__name(this, "CookieStorageAdapter");
|
|
878
|
+
var _storage = localStorageBackend;
|
|
879
|
+
var _storageMode = "localStorage";
|
|
880
|
+
function detectLocale() {
|
|
881
|
+
try {
|
|
882
|
+
if (typeof document !== "undefined") {
|
|
883
|
+
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
884
|
+
if (m) return decodeURIComponent(m[1]);
|
|
885
|
+
}
|
|
886
|
+
if (typeof navigator !== "undefined" && navigator.language) {
|
|
887
|
+
return navigator.language;
|
|
888
|
+
}
|
|
889
|
+
} catch {
|
|
887
890
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
891
|
+
return null;
|
|
892
|
+
}
|
|
893
|
+
__name(detectLocale, "detectLocale");
|
|
894
|
+
function defaultBaseUrl() {
|
|
895
|
+
try {
|
|
896
|
+
if (typeof process !== "undefined" && process.env) {
|
|
897
|
+
if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
|
|
898
|
+
return process.env.NEXT_PUBLIC_API_URL || "";
|
|
895
899
|
}
|
|
896
|
-
|
|
900
|
+
} catch {
|
|
897
901
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
if (this.opts.secure) parts.push("Secure");
|
|
906
|
-
if (this.opts.sameSite) parts.push(`SameSite=${this.opts.sameSite}`);
|
|
907
|
-
if (this.opts.maxAgeSeconds != null) {
|
|
908
|
-
parts.push(`Max-Age=${this.opts.maxAgeSeconds}`);
|
|
902
|
+
return "";
|
|
903
|
+
}
|
|
904
|
+
__name(defaultBaseUrl, "defaultBaseUrl");
|
|
905
|
+
function defaultApiKey() {
|
|
906
|
+
try {
|
|
907
|
+
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
|
|
908
|
+
return process.env.NEXT_PUBLIC_API_KEY;
|
|
909
909
|
}
|
|
910
|
-
|
|
910
|
+
} catch {
|
|
911
911
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
__name(defaultApiKey, "defaultApiKey");
|
|
915
|
+
var _localeOverride = null;
|
|
916
|
+
var _apiKeyOverride = null;
|
|
917
|
+
var _baseUrlOverride = null;
|
|
918
|
+
var _withCredentials = true;
|
|
919
|
+
var _onUnauthorized = null;
|
|
920
|
+
var auth = {
|
|
921
|
+
// ── Storage mode ──────────────────────────────────────────────────
|
|
922
|
+
getStorageMode() {
|
|
923
|
+
return _storageMode;
|
|
924
|
+
},
|
|
925
|
+
/**
|
|
926
|
+
* Switch the storage backend. Existing values in the *previous*
|
|
927
|
+
* backend are NOT migrated — set fresh values after switching.
|
|
928
|
+
*/
|
|
929
|
+
setStorageMode(mode) {
|
|
930
|
+
_storageMode = mode;
|
|
931
|
+
_storage = mode === "cookie" ? cookieBackend : localStorageBackend;
|
|
932
|
+
},
|
|
933
|
+
// ── Bearer token ──────────────────────────────────────────────────
|
|
934
|
+
getToken() {
|
|
935
|
+
return _storage.get(ACCESS_KEY);
|
|
936
|
+
},
|
|
937
|
+
setToken(token) {
|
|
938
|
+
_storage.set(ACCESS_KEY, token);
|
|
939
|
+
},
|
|
940
|
+
getRefreshToken() {
|
|
941
|
+
return _storage.get(REFRESH_KEY);
|
|
942
|
+
},
|
|
943
|
+
setRefreshToken(token) {
|
|
944
|
+
_storage.set(REFRESH_KEY, token);
|
|
945
|
+
},
|
|
946
|
+
clearTokens() {
|
|
947
|
+
_storage.set(ACCESS_KEY, null);
|
|
948
|
+
_storage.set(REFRESH_KEY, null);
|
|
949
|
+
},
|
|
950
|
+
isAuthenticated() {
|
|
951
|
+
return _storage.get(ACCESS_KEY) !== null;
|
|
952
|
+
},
|
|
953
|
+
// ── API key ───────────────────────────────────────────────────────
|
|
954
|
+
/** In-memory API key. Falls back to storage, then NEXT_PUBLIC_API_KEY. */
|
|
955
|
+
getApiKey() {
|
|
956
|
+
return _apiKeyOverride ?? _storage.get(API_KEY_KEY) ?? defaultApiKey();
|
|
957
|
+
},
|
|
958
|
+
/** In-memory only (cleared on reload). */
|
|
959
|
+
setApiKey(key) {
|
|
960
|
+
_apiKeyOverride = key;
|
|
961
|
+
},
|
|
962
|
+
/** Persist to active storage backend (localStorage or cookie). */
|
|
963
|
+
setApiKeyPersist(key) {
|
|
964
|
+
_apiKeyOverride = key;
|
|
965
|
+
_storage.set(API_KEY_KEY, key);
|
|
966
|
+
},
|
|
967
|
+
clearApiKey() {
|
|
968
|
+
_apiKeyOverride = null;
|
|
969
|
+
_storage.set(API_KEY_KEY, null);
|
|
970
|
+
},
|
|
971
|
+
// ── Locale ────────────────────────────────────────────────────────
|
|
972
|
+
/** Override locale → falls back to NEXT_LOCALE cookie / navigator.language. */
|
|
973
|
+
getLocale() {
|
|
974
|
+
return _localeOverride ?? detectLocale();
|
|
975
|
+
},
|
|
976
|
+
setLocale(locale) {
|
|
977
|
+
_localeOverride = locale;
|
|
978
|
+
},
|
|
979
|
+
// ── Base URL ──────────────────────────────────────────────────────
|
|
980
|
+
getBaseUrl() {
|
|
981
|
+
const url = _baseUrlOverride ?? defaultBaseUrl();
|
|
982
|
+
return url.replace(/\/$/, "");
|
|
983
|
+
},
|
|
984
|
+
setBaseUrl(url) {
|
|
985
|
+
_baseUrlOverride = url ? url.replace(/\/$/, "") : null;
|
|
986
|
+
client.setConfig({ baseUrl: this.getBaseUrl() });
|
|
987
|
+
},
|
|
988
|
+
// ── Credentials toggle (Django session/CSRF cross-origin) ─────────
|
|
989
|
+
getWithCredentials() {
|
|
990
|
+
return _withCredentials;
|
|
991
|
+
},
|
|
992
|
+
setWithCredentials(value) {
|
|
993
|
+
_withCredentials = value;
|
|
994
|
+
client.setConfig({ credentials: value ? "include" : "same-origin" });
|
|
995
|
+
},
|
|
996
|
+
// ── 401 handler ───────────────────────────────────────────────────
|
|
997
|
+
/**
|
|
998
|
+
* Register a callback fired on every 401 response. Use this to wire
|
|
999
|
+
* a token-refresh flow or a forced logout. Setting `null` removes
|
|
1000
|
+
* the handler.
|
|
1001
|
+
*/
|
|
1002
|
+
onUnauthorized(cb) {
|
|
1003
|
+
_onUnauthorized = cb;
|
|
915
1004
|
}
|
|
916
1005
|
};
|
|
1006
|
+
client.setConfig({
|
|
1007
|
+
baseUrl: auth.getBaseUrl(),
|
|
1008
|
+
credentials: _withCredentials ? "include" : "same-origin"
|
|
1009
|
+
});
|
|
1010
|
+
client.interceptors.request.use((request) => {
|
|
1011
|
+
const token = auth.getToken();
|
|
1012
|
+
if (token) request.headers.set("Authorization", `Bearer ${token}`);
|
|
1013
|
+
const locale = auth.getLocale();
|
|
1014
|
+
if (locale) request.headers.set("Accept-Language", locale);
|
|
1015
|
+
const apiKey = auth.getApiKey();
|
|
1016
|
+
if (apiKey) request.headers.set("X-API-Key", apiKey);
|
|
1017
|
+
return request;
|
|
1018
|
+
});
|
|
1019
|
+
client.interceptors.response.use((response) => {
|
|
1020
|
+
if (response.status === 401 && _onUnauthorized) {
|
|
1021
|
+
try {
|
|
1022
|
+
_onUnauthorized(response);
|
|
1023
|
+
} catch {
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
return response;
|
|
1027
|
+
});
|
|
917
1028
|
|
|
918
1029
|
// src/_api/generated/helpers/logger.ts
|
|
919
1030
|
import { createConsola } from "consola";
|
|
@@ -1010,90 +1121,146 @@ var APILogger = class {
|
|
|
1010
1121
|
var defaultLogger = new APILogger();
|
|
1011
1122
|
|
|
1012
1123
|
// src/_api/generated/_cfg_accounts/api.ts
|
|
1013
|
-
var ACCESS_KEY = "cfg.access_token";
|
|
1014
|
-
var REFRESH_KEY = "cfg.refresh_token";
|
|
1015
|
-
function detectLocale() {
|
|
1016
|
-
try {
|
|
1017
|
-
if (typeof document !== "undefined") {
|
|
1018
|
-
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
1019
|
-
if (m) return decodeURIComponent(m[1]);
|
|
1020
|
-
}
|
|
1021
|
-
if (typeof navigator !== "undefined" && navigator.language) {
|
|
1022
|
-
return navigator.language;
|
|
1023
|
-
}
|
|
1024
|
-
} catch {
|
|
1025
|
-
}
|
|
1026
|
-
return null;
|
|
1027
|
-
}
|
|
1028
|
-
__name(detectLocale, "detectLocale");
|
|
1029
1124
|
var API = class {
|
|
1030
1125
|
static {
|
|
1031
1126
|
__name(this, "API");
|
|
1032
1127
|
}
|
|
1033
|
-
baseUrl;
|
|
1034
|
-
storage;
|
|
1035
|
-
locale;
|
|
1036
|
-
apiKey;
|
|
1037
1128
|
logger;
|
|
1038
|
-
constructor(
|
|
1039
|
-
this.baseUrl = baseUrl2.replace(/\/$/, "");
|
|
1040
|
-
this.storage = opts.storage ?? new LocalStorageAdapter();
|
|
1129
|
+
constructor(_baseUrl, opts = {}) {
|
|
1041
1130
|
this.logger = new APILogger(opts.logger);
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
client.interceptors.request.use((request) => {
|
|
1047
|
-
const access = this.getToken();
|
|
1048
|
-
if (access) request.headers.set("Authorization", `Bearer ${access}`);
|
|
1049
|
-
const locale = this.locale ?? detectLocale();
|
|
1050
|
-
if (locale) request.headers.set("Accept-Language", locale);
|
|
1051
|
-
if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
|
|
1052
|
-
return request;
|
|
1053
|
-
});
|
|
1131
|
+
if (_baseUrl) auth.setBaseUrl(_baseUrl);
|
|
1132
|
+
if (opts.locale !== void 0) auth.setLocale(opts.locale);
|
|
1133
|
+
if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
|
|
1134
|
+
if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
|
|
1054
1135
|
}
|
|
1055
1136
|
// ── Base URL ────────────────────────────────────────────────────────────
|
|
1056
1137
|
getBaseUrl() {
|
|
1057
|
-
return
|
|
1138
|
+
return auth.getBaseUrl();
|
|
1058
1139
|
}
|
|
1059
1140
|
setBaseUrl(url) {
|
|
1060
|
-
|
|
1061
|
-
client.setConfig({ baseUrl: this.baseUrl });
|
|
1141
|
+
auth.setBaseUrl(url);
|
|
1062
1142
|
}
|
|
1063
1143
|
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
1064
1144
|
getToken() {
|
|
1065
|
-
return
|
|
1145
|
+
return auth.getToken();
|
|
1066
1146
|
}
|
|
1067
1147
|
setToken(token) {
|
|
1068
|
-
|
|
1069
|
-
else this.storage.removeItem(ACCESS_KEY);
|
|
1148
|
+
auth.setToken(token);
|
|
1070
1149
|
}
|
|
1071
1150
|
getRefreshToken() {
|
|
1072
|
-
return
|
|
1151
|
+
return auth.getRefreshToken();
|
|
1073
1152
|
}
|
|
1074
1153
|
setRefreshToken(token) {
|
|
1075
|
-
|
|
1076
|
-
else this.storage.removeItem(REFRESH_KEY);
|
|
1154
|
+
auth.setRefreshToken(token);
|
|
1077
1155
|
}
|
|
1078
1156
|
clearToken() {
|
|
1079
|
-
|
|
1080
|
-
this.storage.removeItem(REFRESH_KEY);
|
|
1157
|
+
auth.clearTokens();
|
|
1081
1158
|
}
|
|
1082
1159
|
isAuthenticated() {
|
|
1083
|
-
return
|
|
1160
|
+
return auth.isAuthenticated();
|
|
1084
1161
|
}
|
|
1085
1162
|
// ── Locale / API key ────────────────────────────────────────────────────
|
|
1086
1163
|
getLocale() {
|
|
1087
|
-
return
|
|
1164
|
+
return auth.getLocale();
|
|
1088
1165
|
}
|
|
1089
1166
|
setLocale(locale) {
|
|
1090
|
-
|
|
1167
|
+
auth.setLocale(locale);
|
|
1091
1168
|
}
|
|
1092
1169
|
getApiKey() {
|
|
1093
|
-
return
|
|
1170
|
+
return auth.getApiKey();
|
|
1094
1171
|
}
|
|
1095
1172
|
setApiKey(key) {
|
|
1096
|
-
|
|
1173
|
+
auth.setApiKey(key);
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
// src/_api/generated/helpers/storage.ts
|
|
1178
|
+
var LocalStorageAdapter = class {
|
|
1179
|
+
static {
|
|
1180
|
+
__name(this, "LocalStorageAdapter");
|
|
1181
|
+
}
|
|
1182
|
+
getItem(key) {
|
|
1183
|
+
if (typeof window === "undefined") return null;
|
|
1184
|
+
try {
|
|
1185
|
+
return window.localStorage.getItem(key);
|
|
1186
|
+
} catch {
|
|
1187
|
+
return null;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
setItem(key, value) {
|
|
1191
|
+
if (typeof window === "undefined") return;
|
|
1192
|
+
try {
|
|
1193
|
+
window.localStorage.setItem(key, value);
|
|
1194
|
+
} catch {
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
removeItem(key) {
|
|
1198
|
+
if (typeof window === "undefined") return;
|
|
1199
|
+
try {
|
|
1200
|
+
window.localStorage.removeItem(key);
|
|
1201
|
+
} catch {
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
clear() {
|
|
1205
|
+
if (typeof window === "undefined") return;
|
|
1206
|
+
try {
|
|
1207
|
+
window.localStorage.clear();
|
|
1208
|
+
} catch {
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
var MemoryStorageAdapter = class {
|
|
1213
|
+
static {
|
|
1214
|
+
__name(this, "MemoryStorageAdapter");
|
|
1215
|
+
}
|
|
1216
|
+
store = /* @__PURE__ */ new Map();
|
|
1217
|
+
getItem(key) {
|
|
1218
|
+
return this.store.get(key) ?? null;
|
|
1219
|
+
}
|
|
1220
|
+
setItem(key, value) {
|
|
1221
|
+
this.store.set(key, value);
|
|
1222
|
+
}
|
|
1223
|
+
removeItem(key) {
|
|
1224
|
+
this.store.delete(key);
|
|
1225
|
+
}
|
|
1226
|
+
clear() {
|
|
1227
|
+
this.store.clear();
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
var CookieStorageAdapter = class {
|
|
1231
|
+
constructor(opts = {}) {
|
|
1232
|
+
this.opts = opts;
|
|
1233
|
+
}
|
|
1234
|
+
static {
|
|
1235
|
+
__name(this, "CookieStorageAdapter");
|
|
1236
|
+
}
|
|
1237
|
+
getItem(key) {
|
|
1238
|
+
if (typeof document === "undefined") return null;
|
|
1239
|
+
const prefix = `${encodeURIComponent(key)}=`;
|
|
1240
|
+
for (const part of document.cookie.split("; ")) {
|
|
1241
|
+
if (part.startsWith(prefix)) {
|
|
1242
|
+
return decodeURIComponent(part.slice(prefix.length));
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1247
|
+
setItem(key, value) {
|
|
1248
|
+
if (typeof document === "undefined") return;
|
|
1249
|
+
const parts = [
|
|
1250
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`,
|
|
1251
|
+
`Path=${this.opts.path ?? "/"}`
|
|
1252
|
+
];
|
|
1253
|
+
if (this.opts.domain) parts.push(`Domain=${this.opts.domain}`);
|
|
1254
|
+
if (this.opts.secure) parts.push("Secure");
|
|
1255
|
+
if (this.opts.sameSite) parts.push(`SameSite=${this.opts.sameSite}`);
|
|
1256
|
+
if (this.opts.maxAgeSeconds != null) {
|
|
1257
|
+
parts.push(`Max-Age=${this.opts.maxAgeSeconds}`);
|
|
1258
|
+
}
|
|
1259
|
+
document.cookie = parts.join("; ");
|
|
1260
|
+
}
|
|
1261
|
+
removeItem(key) {
|
|
1262
|
+
if (typeof document === "undefined") return;
|
|
1263
|
+
document.cookie = `${encodeURIComponent(key)}=; Max-Age=0; Path=${this.opts.path ?? "/"}`;
|
|
1097
1264
|
}
|
|
1098
1265
|
};
|
|
1099
1266
|
|
|
@@ -1206,187 +1373,117 @@ function formatZodError(error) {
|
|
|
1206
1373
|
__name(formatZodError, "formatZodError");
|
|
1207
1374
|
|
|
1208
1375
|
// src/_api/generated/_cfg_centrifugo/api.ts
|
|
1209
|
-
var ACCESS_KEY2 = "cfg.access_token";
|
|
1210
|
-
var REFRESH_KEY2 = "cfg.refresh_token";
|
|
1211
|
-
function detectLocale2() {
|
|
1212
|
-
try {
|
|
1213
|
-
if (typeof document !== "undefined") {
|
|
1214
|
-
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
1215
|
-
if (m) return decodeURIComponent(m[1]);
|
|
1216
|
-
}
|
|
1217
|
-
if (typeof navigator !== "undefined" && navigator.language) {
|
|
1218
|
-
return navigator.language;
|
|
1219
|
-
}
|
|
1220
|
-
} catch {
|
|
1221
|
-
}
|
|
1222
|
-
return null;
|
|
1223
|
-
}
|
|
1224
|
-
__name(detectLocale2, "detectLocale");
|
|
1225
1376
|
var API2 = class {
|
|
1226
1377
|
static {
|
|
1227
1378
|
__name(this, "API");
|
|
1228
1379
|
}
|
|
1229
|
-
baseUrl;
|
|
1230
|
-
storage;
|
|
1231
|
-
locale;
|
|
1232
|
-
apiKey;
|
|
1233
1380
|
logger;
|
|
1234
|
-
constructor(
|
|
1235
|
-
this.baseUrl = baseUrl2.replace(/\/$/, "");
|
|
1236
|
-
this.storage = opts.storage ?? new LocalStorageAdapter();
|
|
1381
|
+
constructor(_baseUrl, opts = {}) {
|
|
1237
1382
|
this.logger = new APILogger(opts.logger);
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
client.interceptors.request.use((request) => {
|
|
1243
|
-
const access = this.getToken();
|
|
1244
|
-
if (access) request.headers.set("Authorization", `Bearer ${access}`);
|
|
1245
|
-
const locale = this.locale ?? detectLocale2();
|
|
1246
|
-
if (locale) request.headers.set("Accept-Language", locale);
|
|
1247
|
-
if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
|
|
1248
|
-
return request;
|
|
1249
|
-
});
|
|
1383
|
+
if (_baseUrl) auth.setBaseUrl(_baseUrl);
|
|
1384
|
+
if (opts.locale !== void 0) auth.setLocale(opts.locale);
|
|
1385
|
+
if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
|
|
1386
|
+
if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
|
|
1250
1387
|
}
|
|
1251
1388
|
// ── Base URL ────────────────────────────────────────────────────────────
|
|
1252
1389
|
getBaseUrl() {
|
|
1253
|
-
return
|
|
1390
|
+
return auth.getBaseUrl();
|
|
1254
1391
|
}
|
|
1255
1392
|
setBaseUrl(url) {
|
|
1256
|
-
|
|
1257
|
-
client.setConfig({ baseUrl: this.baseUrl });
|
|
1393
|
+
auth.setBaseUrl(url);
|
|
1258
1394
|
}
|
|
1259
1395
|
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
1260
1396
|
getToken() {
|
|
1261
|
-
return
|
|
1397
|
+
return auth.getToken();
|
|
1262
1398
|
}
|
|
1263
1399
|
setToken(token) {
|
|
1264
|
-
|
|
1265
|
-
else this.storage.removeItem(ACCESS_KEY2);
|
|
1400
|
+
auth.setToken(token);
|
|
1266
1401
|
}
|
|
1267
1402
|
getRefreshToken() {
|
|
1268
|
-
return
|
|
1403
|
+
return auth.getRefreshToken();
|
|
1269
1404
|
}
|
|
1270
1405
|
setRefreshToken(token) {
|
|
1271
|
-
|
|
1272
|
-
else this.storage.removeItem(REFRESH_KEY2);
|
|
1406
|
+
auth.setRefreshToken(token);
|
|
1273
1407
|
}
|
|
1274
1408
|
clearToken() {
|
|
1275
|
-
|
|
1276
|
-
this.storage.removeItem(REFRESH_KEY2);
|
|
1409
|
+
auth.clearTokens();
|
|
1277
1410
|
}
|
|
1278
1411
|
isAuthenticated() {
|
|
1279
|
-
return
|
|
1412
|
+
return auth.isAuthenticated();
|
|
1280
1413
|
}
|
|
1281
1414
|
// ── Locale / API key ────────────────────────────────────────────────────
|
|
1282
1415
|
getLocale() {
|
|
1283
|
-
return
|
|
1416
|
+
return auth.getLocale();
|
|
1284
1417
|
}
|
|
1285
1418
|
setLocale(locale) {
|
|
1286
|
-
|
|
1419
|
+
auth.setLocale(locale);
|
|
1287
1420
|
}
|
|
1288
1421
|
getApiKey() {
|
|
1289
|
-
return
|
|
1422
|
+
return auth.getApiKey();
|
|
1290
1423
|
}
|
|
1291
1424
|
setApiKey(key) {
|
|
1292
|
-
|
|
1425
|
+
auth.setApiKey(key);
|
|
1293
1426
|
}
|
|
1294
1427
|
};
|
|
1295
1428
|
|
|
1296
1429
|
// src/_api/generated/_cfg_totp/api.ts
|
|
1297
|
-
var ACCESS_KEY3 = "cfg.access_token";
|
|
1298
|
-
var REFRESH_KEY3 = "cfg.refresh_token";
|
|
1299
|
-
function detectLocale3() {
|
|
1300
|
-
try {
|
|
1301
|
-
if (typeof document !== "undefined") {
|
|
1302
|
-
const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
|
|
1303
|
-
if (m) return decodeURIComponent(m[1]);
|
|
1304
|
-
}
|
|
1305
|
-
if (typeof navigator !== "undefined" && navigator.language) {
|
|
1306
|
-
return navigator.language;
|
|
1307
|
-
}
|
|
1308
|
-
} catch {
|
|
1309
|
-
}
|
|
1310
|
-
return null;
|
|
1311
|
-
}
|
|
1312
|
-
__name(detectLocale3, "detectLocale");
|
|
1313
1430
|
var API3 = class {
|
|
1314
1431
|
static {
|
|
1315
1432
|
__name(this, "API");
|
|
1316
1433
|
}
|
|
1317
|
-
baseUrl;
|
|
1318
|
-
storage;
|
|
1319
|
-
locale;
|
|
1320
|
-
apiKey;
|
|
1321
1434
|
logger;
|
|
1322
|
-
constructor(
|
|
1323
|
-
this.baseUrl = baseUrl2.replace(/\/$/, "");
|
|
1324
|
-
this.storage = opts.storage ?? new LocalStorageAdapter();
|
|
1435
|
+
constructor(_baseUrl, opts = {}) {
|
|
1325
1436
|
this.logger = new APILogger(opts.logger);
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
client.interceptors.request.use((request) => {
|
|
1331
|
-
const access = this.getToken();
|
|
1332
|
-
if (access) request.headers.set("Authorization", `Bearer ${access}`);
|
|
1333
|
-
const locale = this.locale ?? detectLocale3();
|
|
1334
|
-
if (locale) request.headers.set("Accept-Language", locale);
|
|
1335
|
-
if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
|
|
1336
|
-
return request;
|
|
1337
|
-
});
|
|
1437
|
+
if (_baseUrl) auth.setBaseUrl(_baseUrl);
|
|
1438
|
+
if (opts.locale !== void 0) auth.setLocale(opts.locale);
|
|
1439
|
+
if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
|
|
1440
|
+
if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
|
|
1338
1441
|
}
|
|
1339
1442
|
// ── Base URL ────────────────────────────────────────────────────────────
|
|
1340
1443
|
getBaseUrl() {
|
|
1341
|
-
return
|
|
1444
|
+
return auth.getBaseUrl();
|
|
1342
1445
|
}
|
|
1343
1446
|
setBaseUrl(url) {
|
|
1344
|
-
|
|
1345
|
-
client.setConfig({ baseUrl: this.baseUrl });
|
|
1447
|
+
auth.setBaseUrl(url);
|
|
1346
1448
|
}
|
|
1347
1449
|
// ── Tokens ──────────────────────────────────────────────────────────────
|
|
1348
1450
|
getToken() {
|
|
1349
|
-
return
|
|
1451
|
+
return auth.getToken();
|
|
1350
1452
|
}
|
|
1351
1453
|
setToken(token) {
|
|
1352
|
-
|
|
1353
|
-
else this.storage.removeItem(ACCESS_KEY3);
|
|
1454
|
+
auth.setToken(token);
|
|
1354
1455
|
}
|
|
1355
1456
|
getRefreshToken() {
|
|
1356
|
-
return
|
|
1457
|
+
return auth.getRefreshToken();
|
|
1357
1458
|
}
|
|
1358
1459
|
setRefreshToken(token) {
|
|
1359
|
-
|
|
1360
|
-
else this.storage.removeItem(REFRESH_KEY3);
|
|
1460
|
+
auth.setRefreshToken(token);
|
|
1361
1461
|
}
|
|
1362
1462
|
clearToken() {
|
|
1363
|
-
|
|
1364
|
-
this.storage.removeItem(REFRESH_KEY3);
|
|
1463
|
+
auth.clearTokens();
|
|
1365
1464
|
}
|
|
1366
1465
|
isAuthenticated() {
|
|
1367
|
-
return
|
|
1466
|
+
return auth.isAuthenticated();
|
|
1368
1467
|
}
|
|
1369
1468
|
// ── Locale / API key ────────────────────────────────────────────────────
|
|
1370
1469
|
getLocale() {
|
|
1371
|
-
return
|
|
1470
|
+
return auth.getLocale();
|
|
1372
1471
|
}
|
|
1373
1472
|
setLocale(locale) {
|
|
1374
|
-
|
|
1473
|
+
auth.setLocale(locale);
|
|
1375
1474
|
}
|
|
1376
1475
|
getApiKey() {
|
|
1377
|
-
return
|
|
1476
|
+
return auth.getApiKey();
|
|
1378
1477
|
}
|
|
1379
1478
|
setApiKey(key) {
|
|
1380
|
-
|
|
1479
|
+
auth.setApiKey(key);
|
|
1381
1480
|
}
|
|
1382
1481
|
};
|
|
1383
1482
|
|
|
1384
1483
|
// src/_api/generated/index.ts
|
|
1385
|
-
var
|
|
1386
|
-
var
|
|
1387
|
-
var
|
|
1388
|
-
var CfgCentrifugoApi = new API2(baseUrl, { storage: new LocalStorageAdapter() });
|
|
1389
|
-
var CfgTotpApi = new API3(baseUrl, { storage: new LocalStorageAdapter() });
|
|
1484
|
+
var CfgAccountsApi = new API();
|
|
1485
|
+
var CfgCentrifugoApi = new API2();
|
|
1486
|
+
var CfgTotpApi = new API3();
|
|
1390
1487
|
|
|
1391
1488
|
// src/_api/generated/sdk.gen.ts
|
|
1392
1489
|
var Cfg = class {
|
|
@@ -2610,6 +2707,7 @@ export {
|
|
|
2610
2707
|
TotpVerification,
|
|
2611
2708
|
UserProfile,
|
|
2612
2709
|
CfgAccountsApi as api,
|
|
2710
|
+
auth,
|
|
2613
2711
|
defaultLogger,
|
|
2614
2712
|
dispatchValidationError,
|
|
2615
2713
|
formatZodError,
|