@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/index.cjs CHANGED
@@ -45,6 +45,7 @@ __export(index_exports, {
45
45
  TotpVerification: () => TotpVerification,
46
46
  UserProfile: () => UserProfile,
47
47
  api: () => CfgAccountsApi,
48
+ auth: () => auth,
48
49
  defaultLogger: () => defaultLogger,
49
50
  dispatchValidationError: () => dispatchValidationError,
50
51
  formatZodError: () => formatZodError,
@@ -404,14 +405,14 @@ var defaultPathSerializer = /* @__PURE__ */ __name(({ path, url: _url }) => {
404
405
  return url;
405
406
  }, "defaultPathSerializer");
406
407
  var getUrl = /* @__PURE__ */ __name(({
407
- baseUrl: baseUrl2,
408
+ baseUrl,
408
409
  path,
409
410
  query,
410
411
  querySerializer,
411
412
  url: _url
412
413
  }) => {
413
414
  const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
414
- let url = (baseUrl2 ?? "") + pathUrl;
415
+ let url = (baseUrl ?? "") + pathUrl;
415
416
  if (path) {
416
417
  url = defaultPathSerializer({ path, url });
417
418
  }
@@ -442,15 +443,15 @@ function getValidRequestBody(options) {
442
443
  __name(getValidRequestBody, "getValidRequestBody");
443
444
 
444
445
  // src/_api/generated/core/auth.gen.ts
445
- var getAuthToken = /* @__PURE__ */ __name(async (auth, callback) => {
446
- const token = typeof callback === "function" ? await callback(auth) : callback;
446
+ var getAuthToken = /* @__PURE__ */ __name(async (auth2, callback) => {
447
+ const token = typeof callback === "function" ? await callback(auth2) : callback;
447
448
  if (!token) {
448
449
  return;
449
450
  }
450
- if (auth.scheme === "bearer") {
451
+ if (auth2.scheme === "bearer") {
451
452
  return `Bearer ${token}`;
452
453
  }
453
- if (auth.scheme === "basic") {
454
+ if (auth2.scheme === "basic") {
454
455
  return `Basic ${btoa(token)}`;
455
456
  }
456
457
  return token;
@@ -539,16 +540,16 @@ var setAuthParams = /* @__PURE__ */ __name(async ({
539
540
  security,
540
541
  ...options
541
542
  }) => {
542
- for (const auth of security) {
543
- if (checkForExistence(options, auth.name)) {
543
+ for (const auth2 of security) {
544
+ if (checkForExistence(options, auth2.name)) {
544
545
  continue;
545
546
  }
546
- const token = await getAuthToken(auth, options.auth);
547
+ const token = await getAuthToken(auth2, options.auth);
547
548
  if (!token) {
548
549
  continue;
549
550
  }
550
- const name = auth.name ?? "Authorization";
551
- switch (auth.in) {
551
+ const name = auth2.name ?? "Authorization";
552
+ switch (auth2.in) {
552
553
  case "query":
553
554
  if (!options.query) {
554
555
  options.query = {};
@@ -876,95 +877,206 @@ var createClient = /* @__PURE__ */ __name((config = {}) => {
876
877
  // src/_api/generated/client.gen.ts
877
878
  var client = createClient(createConfig({ baseUrl: "http://localhost:8000" }));
878
879
 
879
- // src/_api/generated/helpers/storage.ts
880
- var LocalStorageAdapter = class {
881
- static {
882
- __name(this, "LocalStorageAdapter");
883
- }
884
- getItem(key) {
885
- if (typeof window === "undefined") return null;
880
+ // src/_api/generated/helpers/auth.ts
881
+ var ACCESS_KEY = "cfg.access_token";
882
+ var REFRESH_KEY = "cfg.refresh_token";
883
+ var API_KEY_KEY = "cfg.api_key";
884
+ var isBrowser = typeof window !== "undefined";
885
+ var localStorageBackend = {
886
+ get(key) {
887
+ if (!isBrowser) return null;
886
888
  try {
887
889
  return window.localStorage.getItem(key);
888
890
  } catch {
889
891
  return null;
890
892
  }
891
- }
892
- setItem(key, value) {
893
- if (typeof window === "undefined") return;
893
+ },
894
+ set(key, value) {
895
+ if (!isBrowser) return;
894
896
  try {
895
- window.localStorage.setItem(key, value);
897
+ if (value === null) window.localStorage.removeItem(key);
898
+ else window.localStorage.setItem(key, value);
896
899
  } catch {
897
900
  }
898
901
  }
899
- removeItem(key) {
900
- if (typeof window === "undefined") return;
902
+ };
903
+ var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
904
+ var cookieBackend = {
905
+ get(key) {
906
+ if (!isBrowser) return null;
901
907
  try {
902
- window.localStorage.removeItem(key);
908
+ const re = new RegExp(`(?:^|;\\s*)${encodeURIComponent(key)}=([^;]*)`);
909
+ const m = document.cookie.match(re);
910
+ return m ? decodeURIComponent(m[1]) : null;
903
911
  } catch {
912
+ return null;
904
913
  }
905
- }
906
- clear() {
907
- if (typeof window === "undefined") return;
914
+ },
915
+ set(key, value) {
916
+ if (!isBrowser) return;
908
917
  try {
909
- window.localStorage.clear();
918
+ const k = encodeURIComponent(key);
919
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
920
+ if (value === null) {
921
+ document.cookie = `${k}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
922
+ } else {
923
+ const v = encodeURIComponent(value);
924
+ document.cookie = `${k}=${v}; Path=/; Max-Age=${COOKIE_MAX_AGE}; SameSite=Lax${secure}`;
925
+ }
910
926
  } catch {
911
927
  }
912
928
  }
913
929
  };
914
- var MemoryStorageAdapter = class {
915
- static {
916
- __name(this, "MemoryStorageAdapter");
917
- }
918
- store = /* @__PURE__ */ new Map();
919
- getItem(key) {
920
- return this.store.get(key) ?? null;
921
- }
922
- setItem(key, value) {
923
- this.store.set(key, value);
924
- }
925
- removeItem(key) {
926
- this.store.delete(key);
927
- }
928
- clear() {
929
- this.store.clear();
930
- }
931
- };
932
- var CookieStorageAdapter = class {
933
- constructor(opts = {}) {
934
- this.opts = opts;
935
- }
936
- static {
937
- __name(this, "CookieStorageAdapter");
930
+ var _storage = localStorageBackend;
931
+ var _storageMode = "localStorage";
932
+ function detectLocale() {
933
+ try {
934
+ if (typeof document !== "undefined") {
935
+ const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
936
+ if (m) return decodeURIComponent(m[1]);
937
+ }
938
+ if (typeof navigator !== "undefined" && navigator.language) {
939
+ return navigator.language;
940
+ }
941
+ } catch {
938
942
  }
939
- getItem(key) {
940
- if (typeof document === "undefined") return null;
941
- const prefix = `${encodeURIComponent(key)}=`;
942
- for (const part of document.cookie.split("; ")) {
943
- if (part.startsWith(prefix)) {
944
- return decodeURIComponent(part.slice(prefix.length));
945
- }
943
+ return null;
944
+ }
945
+ __name(detectLocale, "detectLocale");
946
+ function defaultBaseUrl() {
947
+ try {
948
+ if (typeof process !== "undefined" && process.env) {
949
+ if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
950
+ return process.env.NEXT_PUBLIC_API_URL || "";
946
951
  }
947
- return null;
952
+ } catch {
948
953
  }
949
- setItem(key, value) {
950
- if (typeof document === "undefined") return;
951
- const parts = [
952
- `${encodeURIComponent(key)}=${encodeURIComponent(value)}`,
953
- `Path=${this.opts.path ?? "/"}`
954
- ];
955
- if (this.opts.domain) parts.push(`Domain=${this.opts.domain}`);
956
- if (this.opts.secure) parts.push("Secure");
957
- if (this.opts.sameSite) parts.push(`SameSite=${this.opts.sameSite}`);
958
- if (this.opts.maxAgeSeconds != null) {
959
- parts.push(`Max-Age=${this.opts.maxAgeSeconds}`);
954
+ return "";
955
+ }
956
+ __name(defaultBaseUrl, "defaultBaseUrl");
957
+ function defaultApiKey() {
958
+ try {
959
+ if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
960
+ return process.env.NEXT_PUBLIC_API_KEY;
960
961
  }
961
- document.cookie = parts.join("; ");
962
+ } catch {
962
963
  }
963
- removeItem(key) {
964
- if (typeof document === "undefined") return;
965
- document.cookie = `${encodeURIComponent(key)}=; Max-Age=0; Path=${this.opts.path ?? "/"}`;
964
+ return null;
965
+ }
966
+ __name(defaultApiKey, "defaultApiKey");
967
+ var _localeOverride = null;
968
+ var _apiKeyOverride = null;
969
+ var _baseUrlOverride = null;
970
+ var _withCredentials = true;
971
+ var _onUnauthorized = null;
972
+ var auth = {
973
+ // ── Storage mode ──────────────────────────────────────────────────
974
+ getStorageMode() {
975
+ return _storageMode;
976
+ },
977
+ /**
978
+ * Switch the storage backend. Existing values in the *previous*
979
+ * backend are NOT migrated — set fresh values after switching.
980
+ */
981
+ setStorageMode(mode) {
982
+ _storageMode = mode;
983
+ _storage = mode === "cookie" ? cookieBackend : localStorageBackend;
984
+ },
985
+ // ── Bearer token ──────────────────────────────────────────────────
986
+ getToken() {
987
+ return _storage.get(ACCESS_KEY);
988
+ },
989
+ setToken(token) {
990
+ _storage.set(ACCESS_KEY, token);
991
+ },
992
+ getRefreshToken() {
993
+ return _storage.get(REFRESH_KEY);
994
+ },
995
+ setRefreshToken(token) {
996
+ _storage.set(REFRESH_KEY, token);
997
+ },
998
+ clearTokens() {
999
+ _storage.set(ACCESS_KEY, null);
1000
+ _storage.set(REFRESH_KEY, null);
1001
+ },
1002
+ isAuthenticated() {
1003
+ return _storage.get(ACCESS_KEY) !== null;
1004
+ },
1005
+ // ── API key ───────────────────────────────────────────────────────
1006
+ /** In-memory API key. Falls back to storage, then NEXT_PUBLIC_API_KEY. */
1007
+ getApiKey() {
1008
+ return _apiKeyOverride ?? _storage.get(API_KEY_KEY) ?? defaultApiKey();
1009
+ },
1010
+ /** In-memory only (cleared on reload). */
1011
+ setApiKey(key) {
1012
+ _apiKeyOverride = key;
1013
+ },
1014
+ /** Persist to active storage backend (localStorage or cookie). */
1015
+ setApiKeyPersist(key) {
1016
+ _apiKeyOverride = key;
1017
+ _storage.set(API_KEY_KEY, key);
1018
+ },
1019
+ clearApiKey() {
1020
+ _apiKeyOverride = null;
1021
+ _storage.set(API_KEY_KEY, null);
1022
+ },
1023
+ // ── Locale ────────────────────────────────────────────────────────
1024
+ /** Override locale → falls back to NEXT_LOCALE cookie / navigator.language. */
1025
+ getLocale() {
1026
+ return _localeOverride ?? detectLocale();
1027
+ },
1028
+ setLocale(locale) {
1029
+ _localeOverride = locale;
1030
+ },
1031
+ // ── Base URL ──────────────────────────────────────────────────────
1032
+ getBaseUrl() {
1033
+ const url = _baseUrlOverride ?? defaultBaseUrl();
1034
+ return url.replace(/\/$/, "");
1035
+ },
1036
+ setBaseUrl(url) {
1037
+ _baseUrlOverride = url ? url.replace(/\/$/, "") : null;
1038
+ client.setConfig({ baseUrl: this.getBaseUrl() });
1039
+ },
1040
+ // ── Credentials toggle (Django session/CSRF cross-origin) ─────────
1041
+ getWithCredentials() {
1042
+ return _withCredentials;
1043
+ },
1044
+ setWithCredentials(value) {
1045
+ _withCredentials = value;
1046
+ client.setConfig({ credentials: value ? "include" : "same-origin" });
1047
+ },
1048
+ // ── 401 handler ───────────────────────────────────────────────────
1049
+ /**
1050
+ * Register a callback fired on every 401 response. Use this to wire
1051
+ * a token-refresh flow or a forced logout. Setting `null` removes
1052
+ * the handler.
1053
+ */
1054
+ onUnauthorized(cb) {
1055
+ _onUnauthorized = cb;
966
1056
  }
967
1057
  };
1058
+ client.setConfig({
1059
+ baseUrl: auth.getBaseUrl(),
1060
+ credentials: _withCredentials ? "include" : "same-origin"
1061
+ });
1062
+ client.interceptors.request.use((request) => {
1063
+ const token = auth.getToken();
1064
+ if (token) request.headers.set("Authorization", `Bearer ${token}`);
1065
+ const locale = auth.getLocale();
1066
+ if (locale) request.headers.set("Accept-Language", locale);
1067
+ const apiKey = auth.getApiKey();
1068
+ if (apiKey) request.headers.set("X-API-Key", apiKey);
1069
+ return request;
1070
+ });
1071
+ client.interceptors.response.use((response) => {
1072
+ if (response.status === 401 && _onUnauthorized) {
1073
+ try {
1074
+ _onUnauthorized(response);
1075
+ } catch {
1076
+ }
1077
+ }
1078
+ return response;
1079
+ });
968
1080
 
969
1081
  // src/_api/generated/helpers/logger.ts
970
1082
  var import_consola = require("consola");
@@ -1061,90 +1173,146 @@ var APILogger = class {
1061
1173
  var defaultLogger = new APILogger();
1062
1174
 
1063
1175
  // src/_api/generated/_cfg_accounts/api.ts
1064
- var ACCESS_KEY = "cfg.access_token";
1065
- var REFRESH_KEY = "cfg.refresh_token";
1066
- function detectLocale() {
1067
- try {
1068
- if (typeof document !== "undefined") {
1069
- const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
1070
- if (m) return decodeURIComponent(m[1]);
1071
- }
1072
- if (typeof navigator !== "undefined" && navigator.language) {
1073
- return navigator.language;
1074
- }
1075
- } catch {
1076
- }
1077
- return null;
1078
- }
1079
- __name(detectLocale, "detectLocale");
1080
1176
  var API = class {
1081
1177
  static {
1082
1178
  __name(this, "API");
1083
1179
  }
1084
- baseUrl;
1085
- storage;
1086
- locale;
1087
- apiKey;
1088
1180
  logger;
1089
- constructor(baseUrl2, opts = {}) {
1090
- this.baseUrl = baseUrl2.replace(/\/$/, "");
1091
- this.storage = opts.storage ?? new LocalStorageAdapter();
1181
+ constructor(_baseUrl, opts = {}) {
1092
1182
  this.logger = new APILogger(opts.logger);
1093
- this.locale = opts.locale ?? null;
1094
- this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
1095
- const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
1096
- client.setConfig({ baseUrl: this.baseUrl, credentials });
1097
- client.interceptors.request.use((request) => {
1098
- const access = this.getToken();
1099
- if (access) request.headers.set("Authorization", `Bearer ${access}`);
1100
- const locale = this.locale ?? detectLocale();
1101
- if (locale) request.headers.set("Accept-Language", locale);
1102
- if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
1103
- return request;
1104
- });
1183
+ if (_baseUrl) auth.setBaseUrl(_baseUrl);
1184
+ if (opts.locale !== void 0) auth.setLocale(opts.locale);
1185
+ if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
1186
+ if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
1105
1187
  }
1106
1188
  // ── Base URL ────────────────────────────────────────────────────────────
1107
1189
  getBaseUrl() {
1108
- return this.baseUrl;
1190
+ return auth.getBaseUrl();
1109
1191
  }
1110
1192
  setBaseUrl(url) {
1111
- this.baseUrl = url.replace(/\/$/, "");
1112
- client.setConfig({ baseUrl: this.baseUrl });
1193
+ auth.setBaseUrl(url);
1113
1194
  }
1114
1195
  // ── Tokens ──────────────────────────────────────────────────────────────
1115
1196
  getToken() {
1116
- return this.storage.getItem(ACCESS_KEY);
1197
+ return auth.getToken();
1117
1198
  }
1118
1199
  setToken(token) {
1119
- if (token) this.storage.setItem(ACCESS_KEY, token);
1120
- else this.storage.removeItem(ACCESS_KEY);
1200
+ auth.setToken(token);
1121
1201
  }
1122
1202
  getRefreshToken() {
1123
- return this.storage.getItem(REFRESH_KEY);
1203
+ return auth.getRefreshToken();
1124
1204
  }
1125
1205
  setRefreshToken(token) {
1126
- if (token) this.storage.setItem(REFRESH_KEY, token);
1127
- else this.storage.removeItem(REFRESH_KEY);
1206
+ auth.setRefreshToken(token);
1128
1207
  }
1129
1208
  clearToken() {
1130
- this.storage.removeItem(ACCESS_KEY);
1131
- this.storage.removeItem(REFRESH_KEY);
1209
+ auth.clearTokens();
1132
1210
  }
1133
1211
  isAuthenticated() {
1134
- return this.getToken() !== null;
1212
+ return auth.isAuthenticated();
1135
1213
  }
1136
1214
  // ── Locale / API key ────────────────────────────────────────────────────
1137
1215
  getLocale() {
1138
- return this.locale ?? detectLocale();
1216
+ return auth.getLocale();
1139
1217
  }
1140
1218
  setLocale(locale) {
1141
- this.locale = locale;
1219
+ auth.setLocale(locale);
1142
1220
  }
1143
1221
  getApiKey() {
1144
- return this.apiKey;
1222
+ return auth.getApiKey();
1145
1223
  }
1146
1224
  setApiKey(key) {
1147
- this.apiKey = key;
1225
+ auth.setApiKey(key);
1226
+ }
1227
+ };
1228
+
1229
+ // src/_api/generated/helpers/storage.ts
1230
+ var LocalStorageAdapter = class {
1231
+ static {
1232
+ __name(this, "LocalStorageAdapter");
1233
+ }
1234
+ getItem(key) {
1235
+ if (typeof window === "undefined") return null;
1236
+ try {
1237
+ return window.localStorage.getItem(key);
1238
+ } catch {
1239
+ return null;
1240
+ }
1241
+ }
1242
+ setItem(key, value) {
1243
+ if (typeof window === "undefined") return;
1244
+ try {
1245
+ window.localStorage.setItem(key, value);
1246
+ } catch {
1247
+ }
1248
+ }
1249
+ removeItem(key) {
1250
+ if (typeof window === "undefined") return;
1251
+ try {
1252
+ window.localStorage.removeItem(key);
1253
+ } catch {
1254
+ }
1255
+ }
1256
+ clear() {
1257
+ if (typeof window === "undefined") return;
1258
+ try {
1259
+ window.localStorage.clear();
1260
+ } catch {
1261
+ }
1262
+ }
1263
+ };
1264
+ var MemoryStorageAdapter = class {
1265
+ static {
1266
+ __name(this, "MemoryStorageAdapter");
1267
+ }
1268
+ store = /* @__PURE__ */ new Map();
1269
+ getItem(key) {
1270
+ return this.store.get(key) ?? null;
1271
+ }
1272
+ setItem(key, value) {
1273
+ this.store.set(key, value);
1274
+ }
1275
+ removeItem(key) {
1276
+ this.store.delete(key);
1277
+ }
1278
+ clear() {
1279
+ this.store.clear();
1280
+ }
1281
+ };
1282
+ var CookieStorageAdapter = class {
1283
+ constructor(opts = {}) {
1284
+ this.opts = opts;
1285
+ }
1286
+ static {
1287
+ __name(this, "CookieStorageAdapter");
1288
+ }
1289
+ getItem(key) {
1290
+ if (typeof document === "undefined") return null;
1291
+ const prefix = `${encodeURIComponent(key)}=`;
1292
+ for (const part of document.cookie.split("; ")) {
1293
+ if (part.startsWith(prefix)) {
1294
+ return decodeURIComponent(part.slice(prefix.length));
1295
+ }
1296
+ }
1297
+ return null;
1298
+ }
1299
+ setItem(key, value) {
1300
+ if (typeof document === "undefined") return;
1301
+ const parts = [
1302
+ `${encodeURIComponent(key)}=${encodeURIComponent(value)}`,
1303
+ `Path=${this.opts.path ?? "/"}`
1304
+ ];
1305
+ if (this.opts.domain) parts.push(`Domain=${this.opts.domain}`);
1306
+ if (this.opts.secure) parts.push("Secure");
1307
+ if (this.opts.sameSite) parts.push(`SameSite=${this.opts.sameSite}`);
1308
+ if (this.opts.maxAgeSeconds != null) {
1309
+ parts.push(`Max-Age=${this.opts.maxAgeSeconds}`);
1310
+ }
1311
+ document.cookie = parts.join("; ");
1312
+ }
1313
+ removeItem(key) {
1314
+ if (typeof document === "undefined") return;
1315
+ document.cookie = `${encodeURIComponent(key)}=; Max-Age=0; Path=${this.opts.path ?? "/"}`;
1148
1316
  }
1149
1317
  };
1150
1318
 
@@ -1257,187 +1425,117 @@ function formatZodError(error) {
1257
1425
  __name(formatZodError, "formatZodError");
1258
1426
 
1259
1427
  // src/_api/generated/_cfg_centrifugo/api.ts
1260
- var ACCESS_KEY2 = "cfg.access_token";
1261
- var REFRESH_KEY2 = "cfg.refresh_token";
1262
- function detectLocale2() {
1263
- try {
1264
- if (typeof document !== "undefined") {
1265
- const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
1266
- if (m) return decodeURIComponent(m[1]);
1267
- }
1268
- if (typeof navigator !== "undefined" && navigator.language) {
1269
- return navigator.language;
1270
- }
1271
- } catch {
1272
- }
1273
- return null;
1274
- }
1275
- __name(detectLocale2, "detectLocale");
1276
1428
  var API2 = class {
1277
1429
  static {
1278
1430
  __name(this, "API");
1279
1431
  }
1280
- baseUrl;
1281
- storage;
1282
- locale;
1283
- apiKey;
1284
1432
  logger;
1285
- constructor(baseUrl2, opts = {}) {
1286
- this.baseUrl = baseUrl2.replace(/\/$/, "");
1287
- this.storage = opts.storage ?? new LocalStorageAdapter();
1433
+ constructor(_baseUrl, opts = {}) {
1288
1434
  this.logger = new APILogger(opts.logger);
1289
- this.locale = opts.locale ?? null;
1290
- this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
1291
- const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
1292
- client.setConfig({ baseUrl: this.baseUrl, credentials });
1293
- client.interceptors.request.use((request) => {
1294
- const access = this.getToken();
1295
- if (access) request.headers.set("Authorization", `Bearer ${access}`);
1296
- const locale = this.locale ?? detectLocale2();
1297
- if (locale) request.headers.set("Accept-Language", locale);
1298
- if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
1299
- return request;
1300
- });
1435
+ if (_baseUrl) auth.setBaseUrl(_baseUrl);
1436
+ if (opts.locale !== void 0) auth.setLocale(opts.locale);
1437
+ if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
1438
+ if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
1301
1439
  }
1302
1440
  // ── Base URL ────────────────────────────────────────────────────────────
1303
1441
  getBaseUrl() {
1304
- return this.baseUrl;
1442
+ return auth.getBaseUrl();
1305
1443
  }
1306
1444
  setBaseUrl(url) {
1307
- this.baseUrl = url.replace(/\/$/, "");
1308
- client.setConfig({ baseUrl: this.baseUrl });
1445
+ auth.setBaseUrl(url);
1309
1446
  }
1310
1447
  // ── Tokens ──────────────────────────────────────────────────────────────
1311
1448
  getToken() {
1312
- return this.storage.getItem(ACCESS_KEY2);
1449
+ return auth.getToken();
1313
1450
  }
1314
1451
  setToken(token) {
1315
- if (token) this.storage.setItem(ACCESS_KEY2, token);
1316
- else this.storage.removeItem(ACCESS_KEY2);
1452
+ auth.setToken(token);
1317
1453
  }
1318
1454
  getRefreshToken() {
1319
- return this.storage.getItem(REFRESH_KEY2);
1455
+ return auth.getRefreshToken();
1320
1456
  }
1321
1457
  setRefreshToken(token) {
1322
- if (token) this.storage.setItem(REFRESH_KEY2, token);
1323
- else this.storage.removeItem(REFRESH_KEY2);
1458
+ auth.setRefreshToken(token);
1324
1459
  }
1325
1460
  clearToken() {
1326
- this.storage.removeItem(ACCESS_KEY2);
1327
- this.storage.removeItem(REFRESH_KEY2);
1461
+ auth.clearTokens();
1328
1462
  }
1329
1463
  isAuthenticated() {
1330
- return this.getToken() !== null;
1464
+ return auth.isAuthenticated();
1331
1465
  }
1332
1466
  // ── Locale / API key ────────────────────────────────────────────────────
1333
1467
  getLocale() {
1334
- return this.locale ?? detectLocale2();
1468
+ return auth.getLocale();
1335
1469
  }
1336
1470
  setLocale(locale) {
1337
- this.locale = locale;
1471
+ auth.setLocale(locale);
1338
1472
  }
1339
1473
  getApiKey() {
1340
- return this.apiKey;
1474
+ return auth.getApiKey();
1341
1475
  }
1342
1476
  setApiKey(key) {
1343
- this.apiKey = key;
1477
+ auth.setApiKey(key);
1344
1478
  }
1345
1479
  };
1346
1480
 
1347
1481
  // src/_api/generated/_cfg_totp/api.ts
1348
- var ACCESS_KEY3 = "cfg.access_token";
1349
- var REFRESH_KEY3 = "cfg.refresh_token";
1350
- function detectLocale3() {
1351
- try {
1352
- if (typeof document !== "undefined") {
1353
- const m = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
1354
- if (m) return decodeURIComponent(m[1]);
1355
- }
1356
- if (typeof navigator !== "undefined" && navigator.language) {
1357
- return navigator.language;
1358
- }
1359
- } catch {
1360
- }
1361
- return null;
1362
- }
1363
- __name(detectLocale3, "detectLocale");
1364
1482
  var API3 = class {
1365
1483
  static {
1366
1484
  __name(this, "API");
1367
1485
  }
1368
- baseUrl;
1369
- storage;
1370
- locale;
1371
- apiKey;
1372
1486
  logger;
1373
- constructor(baseUrl2, opts = {}) {
1374
- this.baseUrl = baseUrl2.replace(/\/$/, "");
1375
- this.storage = opts.storage ?? new LocalStorageAdapter();
1487
+ constructor(_baseUrl, opts = {}) {
1376
1488
  this.logger = new APILogger(opts.logger);
1377
- this.locale = opts.locale ?? null;
1378
- this.apiKey = opts.apiKey ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_API_KEY ?? null : null);
1379
- const credentials = opts.withCredentials ?? true ? "include" : "same-origin";
1380
- client.setConfig({ baseUrl: this.baseUrl, credentials });
1381
- client.interceptors.request.use((request) => {
1382
- const access = this.getToken();
1383
- if (access) request.headers.set("Authorization", `Bearer ${access}`);
1384
- const locale = this.locale ?? detectLocale3();
1385
- if (locale) request.headers.set("Accept-Language", locale);
1386
- if (this.apiKey) request.headers.set("X-API-Key", this.apiKey);
1387
- return request;
1388
- });
1489
+ if (_baseUrl) auth.setBaseUrl(_baseUrl);
1490
+ if (opts.locale !== void 0) auth.setLocale(opts.locale);
1491
+ if (opts.apiKey !== void 0) auth.setApiKey(opts.apiKey);
1492
+ if (opts.withCredentials !== void 0) auth.setWithCredentials(opts.withCredentials);
1389
1493
  }
1390
1494
  // ── Base URL ────────────────────────────────────────────────────────────
1391
1495
  getBaseUrl() {
1392
- return this.baseUrl;
1496
+ return auth.getBaseUrl();
1393
1497
  }
1394
1498
  setBaseUrl(url) {
1395
- this.baseUrl = url.replace(/\/$/, "");
1396
- client.setConfig({ baseUrl: this.baseUrl });
1499
+ auth.setBaseUrl(url);
1397
1500
  }
1398
1501
  // ── Tokens ──────────────────────────────────────────────────────────────
1399
1502
  getToken() {
1400
- return this.storage.getItem(ACCESS_KEY3);
1503
+ return auth.getToken();
1401
1504
  }
1402
1505
  setToken(token) {
1403
- if (token) this.storage.setItem(ACCESS_KEY3, token);
1404
- else this.storage.removeItem(ACCESS_KEY3);
1506
+ auth.setToken(token);
1405
1507
  }
1406
1508
  getRefreshToken() {
1407
- return this.storage.getItem(REFRESH_KEY3);
1509
+ return auth.getRefreshToken();
1408
1510
  }
1409
1511
  setRefreshToken(token) {
1410
- if (token) this.storage.setItem(REFRESH_KEY3, token);
1411
- else this.storage.removeItem(REFRESH_KEY3);
1512
+ auth.setRefreshToken(token);
1412
1513
  }
1413
1514
  clearToken() {
1414
- this.storage.removeItem(ACCESS_KEY3);
1415
- this.storage.removeItem(REFRESH_KEY3);
1515
+ auth.clearTokens();
1416
1516
  }
1417
1517
  isAuthenticated() {
1418
- return this.getToken() !== null;
1518
+ return auth.isAuthenticated();
1419
1519
  }
1420
1520
  // ── Locale / API key ────────────────────────────────────────────────────
1421
1521
  getLocale() {
1422
- return this.locale ?? detectLocale3();
1522
+ return auth.getLocale();
1423
1523
  }
1424
1524
  setLocale(locale) {
1425
- this.locale = locale;
1525
+ auth.setLocale(locale);
1426
1526
  }
1427
1527
  getApiKey() {
1428
- return this.apiKey;
1528
+ return auth.getApiKey();
1429
1529
  }
1430
1530
  setApiKey(key) {
1431
- this.apiKey = key;
1531
+ auth.setApiKey(key);
1432
1532
  }
1433
1533
  };
1434
1534
 
1435
1535
  // src/_api/generated/index.ts
1436
- var isStaticBuild = process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
1437
- var baseUrl = isStaticBuild ? "" : process.env.NEXT_PUBLIC_API_URL || "";
1438
- var CfgAccountsApi = new API(baseUrl, { storage: new LocalStorageAdapter() });
1439
- var CfgCentrifugoApi = new API2(baseUrl, { storage: new LocalStorageAdapter() });
1440
- var CfgTotpApi = new API3(baseUrl, { storage: new LocalStorageAdapter() });
1536
+ var CfgAccountsApi = new API();
1537
+ var CfgCentrifugoApi = new API2();
1538
+ var CfgTotpApi = new API3();
1441
1539
 
1442
1540
  // src/_api/generated/sdk.gen.ts
1443
1541
  var Cfg = class {