@djangocfg/api 2.1.139 → 2.1.143

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.
Files changed (55) hide show
  1. package/dist/auth-server.cjs +2 -199
  2. package/dist/auth-server.cjs.map +1 -1
  3. package/dist/auth-server.mjs +2 -199
  4. package/dist/auth-server.mjs.map +1 -1
  5. package/dist/auth.cjs +11 -836
  6. package/dist/auth.cjs.map +1 -1
  7. package/dist/auth.mjs +11 -836
  8. package/dist/auth.mjs.map +1 -1
  9. package/dist/clients.cjs +40 -1077
  10. package/dist/clients.cjs.map +1 -1
  11. package/dist/clients.d.cts +209 -754
  12. package/dist/clients.d.ts +209 -754
  13. package/dist/clients.mjs +40 -1077
  14. package/dist/clients.mjs.map +1 -1
  15. package/dist/index.cjs +0 -1198
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +229 -1211
  18. package/dist/index.d.ts +229 -1211
  19. package/dist/index.mjs +0 -1198
  20. package/dist/index.mjs.map +1 -1
  21. package/package.json +2 -2
  22. package/src/auth/hooks/useAuthForm.ts +1 -1
  23. package/src/auth/hooks/useAuthGuard.ts +1 -2
  24. package/src/auth/hooks/useAutoAuth.ts +1 -2
  25. package/src/auth/hooks/useDeleteAccount.ts +1 -1
  26. package/src/auth/hooks/useGithubAuth.ts +1 -2
  27. package/src/auth/hooks/useTokenRefresh.ts +1 -0
  28. package/src/auth/hooks/useTwoFactor.ts +1 -2
  29. package/src/clients.ts +2 -12
  30. package/src/index.ts +0 -6
  31. package/src/generated/cfg_webpush/CLAUDE.md +0 -63
  32. package/src/generated/cfg_webpush/_utils/fetchers/index.ts +0 -29
  33. package/src/generated/cfg_webpush/_utils/fetchers/webpush__web_push.ts +0 -211
  34. package/src/generated/cfg_webpush/_utils/hooks/index.ts +0 -29
  35. package/src/generated/cfg_webpush/_utils/hooks/webpush__web_push.ts +0 -79
  36. package/src/generated/cfg_webpush/_utils/schemas/SendPushRequestRequest.schema.ts +0 -22
  37. package/src/generated/cfg_webpush/_utils/schemas/SendPushResponse.schema.ts +0 -20
  38. package/src/generated/cfg_webpush/_utils/schemas/SubscribeRequestRequest.schema.ts +0 -20
  39. package/src/generated/cfg_webpush/_utils/schemas/SubscribeResponse.schema.ts +0 -21
  40. package/src/generated/cfg_webpush/_utils/schemas/VapidPublicKeyResponse.schema.ts +0 -19
  41. package/src/generated/cfg_webpush/_utils/schemas/index.ts +0 -24
  42. package/src/generated/cfg_webpush/api-instance.ts +0 -180
  43. package/src/generated/cfg_webpush/client.ts +0 -322
  44. package/src/generated/cfg_webpush/errors.ts +0 -117
  45. package/src/generated/cfg_webpush/http.ts +0 -110
  46. package/src/generated/cfg_webpush/index.ts +0 -275
  47. package/src/generated/cfg_webpush/logger.ts +0 -260
  48. package/src/generated/cfg_webpush/retry.ts +0 -176
  49. package/src/generated/cfg_webpush/schema.json +0 -302
  50. package/src/generated/cfg_webpush/storage.ts +0 -162
  51. package/src/generated/cfg_webpush/validation-events.ts +0 -134
  52. package/src/generated/cfg_webpush/webpush__web_push/client.ts +0 -45
  53. package/src/generated/cfg_webpush/webpush__web_push/index.ts +0 -3
  54. package/src/generated/cfg_webpush/webpush__web_push/models.ts +0 -65
  55. package/src/hooks/webpush.ts +0 -12
package/dist/auth.mjs CHANGED
@@ -4062,826 +4062,6 @@ var API3 = class {
4062
4062
  }
4063
4063
  };
4064
4064
 
4065
- // src/generated/cfg_webpush/webpush__web_push/client.ts
4066
- var WebPush = class {
4067
- static {
4068
- __name(this, "WebPush");
4069
- }
4070
- constructor(client) {
4071
- this.client = client;
4072
- }
4073
- /**
4074
- * Send push notification
4075
- *
4076
- * Send push notification to all active subscriptions for the authenticated
4077
- * user.
4078
- */
4079
- async webpushSendCreate(data) {
4080
- const response = await this.client.request("POST", "/cfg/webpush/send/", { body: data });
4081
- return response;
4082
- }
4083
- /**
4084
- * Subscribe to push notifications
4085
- *
4086
- * Save push subscription from browser for the authenticated user.
4087
- */
4088
- async webpushSubscribeCreate(data) {
4089
- const response = await this.client.request("POST", "/cfg/webpush/subscribe/", { body: data });
4090
- return response;
4091
- }
4092
- /**
4093
- * Get VAPID public key
4094
- *
4095
- * Get VAPID public key for client subscription.
4096
- */
4097
- async webpushVapidRetrieve() {
4098
- const response = await this.client.request("GET", "/cfg/webpush/vapid/");
4099
- return response;
4100
- }
4101
- };
4102
-
4103
- // src/generated/cfg_webpush/http.ts
4104
- var FetchAdapter4 = class {
4105
- static {
4106
- __name(this, "FetchAdapter");
4107
- }
4108
- async request(request) {
4109
- const { method, url, headers, body, params, formData, binaryBody } = request;
4110
- let finalUrl = url;
4111
- if (params) {
4112
- const searchParams = new URLSearchParams();
4113
- Object.entries(params).forEach(([key, value]) => {
4114
- if (value !== null && value !== void 0) {
4115
- searchParams.append(key, String(value));
4116
- }
4117
- });
4118
- const queryString = searchParams.toString();
4119
- if (queryString) {
4120
- finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
4121
- }
4122
- }
4123
- const finalHeaders = { ...headers };
4124
- let requestBody;
4125
- if (formData) {
4126
- requestBody = formData;
4127
- } else if (binaryBody) {
4128
- finalHeaders["Content-Type"] = "application/octet-stream";
4129
- requestBody = binaryBody;
4130
- } else if (body) {
4131
- finalHeaders["Content-Type"] = "application/json";
4132
- requestBody = JSON.stringify(body);
4133
- }
4134
- const response = await fetch(finalUrl, {
4135
- method,
4136
- headers: finalHeaders,
4137
- body: requestBody,
4138
- credentials: "include"
4139
- // Include Django session cookies
4140
- });
4141
- let data = null;
4142
- const contentType = response.headers.get("content-type");
4143
- if (response.status !== 204 && contentType?.includes("application/json")) {
4144
- data = await response.json();
4145
- } else if (response.status !== 204) {
4146
- data = await response.text();
4147
- }
4148
- const responseHeaders = {};
4149
- response.headers.forEach((value, key) => {
4150
- responseHeaders[key] = value;
4151
- });
4152
- return {
4153
- data,
4154
- status: response.status,
4155
- statusText: response.statusText,
4156
- headers: responseHeaders
4157
- };
4158
- }
4159
- };
4160
-
4161
- // src/generated/cfg_webpush/errors.ts
4162
- var APIError4 = class extends Error {
4163
- constructor(statusCode, statusText, response, url, message) {
4164
- super(message || `HTTP ${statusCode}: ${statusText}`);
4165
- this.statusCode = statusCode;
4166
- this.statusText = statusText;
4167
- this.response = response;
4168
- this.url = url;
4169
- this.name = "APIError";
4170
- }
4171
- static {
4172
- __name(this, "APIError");
4173
- }
4174
- /**
4175
- * Get error details from response.
4176
- * DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
4177
- */
4178
- get details() {
4179
- if (typeof this.response === "object" && this.response !== null) {
4180
- return this.response;
4181
- }
4182
- return null;
4183
- }
4184
- /**
4185
- * Get field-specific validation errors from DRF.
4186
- * Returns: { "field_name": ["error1", "error2"], ... }
4187
- */
4188
- get fieldErrors() {
4189
- const details = this.details;
4190
- if (!details) return null;
4191
- const fieldErrors = {};
4192
- for (const [key, value] of Object.entries(details)) {
4193
- if (Array.isArray(value)) {
4194
- fieldErrors[key] = value;
4195
- }
4196
- }
4197
- return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
4198
- }
4199
- /**
4200
- * Get single error message from DRF.
4201
- * Checks for "detail", "message", or first field error.
4202
- */
4203
- get errorMessage() {
4204
- const details = this.details;
4205
- if (!details) return this.message;
4206
- if (details.detail) {
4207
- return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
4208
- }
4209
- if (details.message) {
4210
- return String(details.message);
4211
- }
4212
- const fieldErrors = this.fieldErrors;
4213
- if (fieldErrors) {
4214
- const firstField = Object.keys(fieldErrors)[0];
4215
- if (firstField) {
4216
- return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
4217
- }
4218
- }
4219
- return this.message;
4220
- }
4221
- // Helper methods for common HTTP status codes
4222
- get isValidationError() {
4223
- return this.statusCode === 400;
4224
- }
4225
- get isAuthError() {
4226
- return this.statusCode === 401;
4227
- }
4228
- get isPermissionError() {
4229
- return this.statusCode === 403;
4230
- }
4231
- get isNotFoundError() {
4232
- return this.statusCode === 404;
4233
- }
4234
- get isServerError() {
4235
- return this.statusCode >= 500 && this.statusCode < 600;
4236
- }
4237
- };
4238
- var NetworkError4 = class extends Error {
4239
- constructor(message, url, originalError) {
4240
- super(message);
4241
- this.url = url;
4242
- this.originalError = originalError;
4243
- this.name = "NetworkError";
4244
- }
4245
- static {
4246
- __name(this, "NetworkError");
4247
- }
4248
- };
4249
-
4250
- // src/generated/cfg_webpush/logger.ts
4251
- import { createConsola as createConsola5 } from "consola";
4252
- var DEFAULT_CONFIG4 = {
4253
- enabled: process.env.NODE_ENV !== "production",
4254
- logRequests: true,
4255
- logResponses: true,
4256
- logErrors: true,
4257
- logBodies: true,
4258
- logHeaders: false
4259
- };
4260
- var SENSITIVE_HEADERS4 = [
4261
- "authorization",
4262
- "cookie",
4263
- "set-cookie",
4264
- "x-api-key",
4265
- "x-csrf-token"
4266
- ];
4267
- var APILogger4 = class {
4268
- static {
4269
- __name(this, "APILogger");
4270
- }
4271
- constructor(config = {}) {
4272
- this.config = { ...DEFAULT_CONFIG4, ...config };
4273
- this.consola = config.consola || createConsola5({
4274
- level: this.config.enabled ? 4 : 0
4275
- });
4276
- }
4277
- /**
4278
- * Enable logging
4279
- */
4280
- enable() {
4281
- this.config.enabled = true;
4282
- }
4283
- /**
4284
- * Disable logging
4285
- */
4286
- disable() {
4287
- this.config.enabled = false;
4288
- }
4289
- /**
4290
- * Update configuration
4291
- */
4292
- setConfig(config) {
4293
- this.config = { ...this.config, ...config };
4294
- }
4295
- /**
4296
- * Filter sensitive headers
4297
- */
4298
- filterHeaders(headers) {
4299
- if (!headers) return {};
4300
- const filtered = {};
4301
- Object.keys(headers).forEach((key) => {
4302
- const lowerKey = key.toLowerCase();
4303
- if (SENSITIVE_HEADERS4.includes(lowerKey)) {
4304
- filtered[key] = "***";
4305
- } else {
4306
- filtered[key] = headers[key] || "";
4307
- }
4308
- });
4309
- return filtered;
4310
- }
4311
- /**
4312
- * Log request
4313
- */
4314
- logRequest(request) {
4315
- if (!this.config.enabled || !this.config.logRequests) return;
4316
- const { method, url, headers, body } = request;
4317
- this.consola.start(`${method} ${url}`);
4318
- if (this.config.logHeaders && headers) {
4319
- this.consola.debug("Headers:", this.filterHeaders(headers));
4320
- }
4321
- if (this.config.logBodies && body) {
4322
- this.consola.debug("Body:", body);
4323
- }
4324
- }
4325
- /**
4326
- * Log response
4327
- */
4328
- logResponse(request, response) {
4329
- if (!this.config.enabled || !this.config.logResponses) return;
4330
- const { method, url } = request;
4331
- const { status, statusText, data, duration } = response;
4332
- const statusColor = status >= 500 ? "red" : status >= 400 ? "yellow" : status >= 300 ? "cyan" : "green";
4333
- this.consola.success(
4334
- `${method} ${url} ${status} ${statusText} (${duration}ms)`
4335
- );
4336
- if (this.config.logBodies && data) {
4337
- this.consola.debug("Response:", data);
4338
- }
4339
- }
4340
- /**
4341
- * Log error
4342
- */
4343
- logError(request, error) {
4344
- if (!this.config.enabled || !this.config.logErrors) return;
4345
- const { method, url } = request;
4346
- const { message, statusCode, fieldErrors, duration } = error;
4347
- this.consola.error(
4348
- `${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
4349
- );
4350
- this.consola.error("Message:", message);
4351
- if (fieldErrors && Object.keys(fieldErrors).length > 0) {
4352
- this.consola.error("Field Errors:");
4353
- Object.entries(fieldErrors).forEach(([field, errors]) => {
4354
- errors.forEach((err) => {
4355
- this.consola.error(` \u2022 ${field}: ${err}`);
4356
- });
4357
- });
4358
- }
4359
- }
4360
- /**
4361
- * Log general info
4362
- */
4363
- info(message, ...args) {
4364
- if (!this.config.enabled) return;
4365
- this.consola.info(message, ...args);
4366
- }
4367
- /**
4368
- * Log warning
4369
- */
4370
- warn(message, ...args) {
4371
- if (!this.config.enabled) return;
4372
- this.consola.warn(message, ...args);
4373
- }
4374
- /**
4375
- * Log error
4376
- */
4377
- error(message, ...args) {
4378
- if (!this.config.enabled) return;
4379
- this.consola.error(message, ...args);
4380
- }
4381
- /**
4382
- * Log debug
4383
- */
4384
- debug(message, ...args) {
4385
- if (!this.config.enabled) return;
4386
- this.consola.debug(message, ...args);
4387
- }
4388
- /**
4389
- * Log success
4390
- */
4391
- success(message, ...args) {
4392
- if (!this.config.enabled) return;
4393
- this.consola.success(message, ...args);
4394
- }
4395
- /**
4396
- * Create a sub-logger with prefix
4397
- */
4398
- withTag(tag) {
4399
- return this.consola.withTag(tag);
4400
- }
4401
- };
4402
- var defaultLogger4 = new APILogger4();
4403
-
4404
- // src/generated/cfg_webpush/retry.ts
4405
- import pRetry4, { AbortError as AbortError4 } from "p-retry";
4406
- var DEFAULT_RETRY_CONFIG4 = {
4407
- retries: 3,
4408
- factor: 2,
4409
- minTimeout: 1e3,
4410
- maxTimeout: 6e4,
4411
- randomize: true,
4412
- onFailedAttempt: /* @__PURE__ */ __name(() => {
4413
- }, "onFailedAttempt")
4414
- };
4415
- function shouldRetry4(error) {
4416
- if (error instanceof NetworkError4) {
4417
- return true;
4418
- }
4419
- if (error instanceof APIError4) {
4420
- const status = error.statusCode;
4421
- if (status >= 500 && status < 600) {
4422
- return true;
4423
- }
4424
- if (status === 429) {
4425
- return true;
4426
- }
4427
- return false;
4428
- }
4429
- return true;
4430
- }
4431
- __name(shouldRetry4, "shouldRetry");
4432
- async function withRetry4(fn, config) {
4433
- const finalConfig = { ...DEFAULT_RETRY_CONFIG4, ...config };
4434
- return pRetry4(
4435
- async () => {
4436
- try {
4437
- return await fn();
4438
- } catch (error) {
4439
- if (!shouldRetry4(error)) {
4440
- throw new AbortError4(error);
4441
- }
4442
- throw error;
4443
- }
4444
- },
4445
- {
4446
- retries: finalConfig.retries,
4447
- factor: finalConfig.factor,
4448
- minTimeout: finalConfig.minTimeout,
4449
- maxTimeout: finalConfig.maxTimeout,
4450
- randomize: finalConfig.randomize,
4451
- onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
4452
- const pRetryError = error;
4453
- finalConfig.onFailedAttempt({
4454
- error: pRetryError,
4455
- attemptNumber: pRetryError.attemptNumber,
4456
- retriesLeft: pRetryError.retriesLeft
4457
- });
4458
- } : void 0
4459
- }
4460
- );
4461
- }
4462
- __name(withRetry4, "withRetry");
4463
-
4464
- // src/generated/cfg_webpush/client.ts
4465
- var APIClient4 = class {
4466
- constructor(baseUrl, options) {
4467
- this.logger = null;
4468
- this.retryConfig = null;
4469
- this.tokenGetter = null;
4470
- this.baseUrl = baseUrl.replace(/\/$/, "");
4471
- this.httpClient = options?.httpClient || new FetchAdapter4();
4472
- this.tokenGetter = options?.tokenGetter || null;
4473
- if (options?.loggerConfig !== void 0) {
4474
- this.logger = new APILogger4(options.loggerConfig);
4475
- }
4476
- if (options?.retryConfig !== void 0) {
4477
- this.retryConfig = options.retryConfig;
4478
- }
4479
- this.web_push = new WebPush(this);
4480
- }
4481
- static {
4482
- __name(this, "APIClient");
4483
- }
4484
- /**
4485
- * Get CSRF token from cookies (for SessionAuthentication).
4486
- *
4487
- * Returns null if cookie doesn't exist (JWT-only auth).
4488
- */
4489
- getCsrfToken() {
4490
- const name = "csrftoken";
4491
- const value = `; ${document.cookie}`;
4492
- const parts = value.split(`; ${name}=`);
4493
- if (parts.length === 2) {
4494
- return parts.pop()?.split(";").shift() || null;
4495
- }
4496
- return null;
4497
- }
4498
- /**
4499
- * Get the base URL for building streaming/download URLs.
4500
- */
4501
- getBaseUrl() {
4502
- return this.baseUrl;
4503
- }
4504
- /**
4505
- * Get JWT token for URL authentication (used in streaming endpoints).
4506
- * Returns null if no token getter is configured or no token is available.
4507
- */
4508
- getToken() {
4509
- return this.tokenGetter ? this.tokenGetter() : null;
4510
- }
4511
- /**
4512
- * Make HTTP request with Django CSRF and session handling.
4513
- * Automatically retries on network errors and 5xx server errors.
4514
- */
4515
- async request(method, path, options) {
4516
- if (this.retryConfig) {
4517
- return withRetry4(() => this._makeRequest(method, path, options), {
4518
- ...this.retryConfig,
4519
- onFailedAttempt: /* @__PURE__ */ __name((info) => {
4520
- if (this.logger) {
4521
- this.logger.warn(
4522
- `Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
4523
- );
4524
- }
4525
- this.retryConfig?.onFailedAttempt?.(info);
4526
- }, "onFailedAttempt")
4527
- });
4528
- }
4529
- return this._makeRequest(method, path, options);
4530
- }
4531
- /**
4532
- * Internal request method (without retry wrapper).
4533
- * Used by request() method with optional retry logic.
4534
- */
4535
- async _makeRequest(method, path, options) {
4536
- const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
4537
- const startTime = Date.now();
4538
- const headers = {
4539
- ...options?.headers || {}
4540
- };
4541
- if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
4542
- headers["Content-Type"] = "application/json";
4543
- }
4544
- if (this.logger) {
4545
- this.logger.logRequest({
4546
- method,
4547
- url,
4548
- headers,
4549
- body: options?.formData || options?.body,
4550
- timestamp: startTime
4551
- });
4552
- }
4553
- try {
4554
- const response = await this.httpClient.request({
4555
- method,
4556
- url,
4557
- headers,
4558
- params: options?.params,
4559
- body: options?.body,
4560
- formData: options?.formData,
4561
- binaryBody: options?.binaryBody
4562
- });
4563
- const duration = Date.now() - startTime;
4564
- if (response.status >= 400) {
4565
- const error = new APIError4(
4566
- response.status,
4567
- response.statusText,
4568
- response.data,
4569
- url
4570
- );
4571
- if (this.logger) {
4572
- this.logger.logError(
4573
- {
4574
- method,
4575
- url,
4576
- headers,
4577
- body: options?.formData || options?.body,
4578
- timestamp: startTime
4579
- },
4580
- {
4581
- message: error.message,
4582
- statusCode: response.status,
4583
- duration,
4584
- timestamp: Date.now()
4585
- }
4586
- );
4587
- }
4588
- throw error;
4589
- }
4590
- if (this.logger) {
4591
- this.logger.logResponse(
4592
- {
4593
- method,
4594
- url,
4595
- headers,
4596
- body: options?.formData || options?.body,
4597
- timestamp: startTime
4598
- },
4599
- {
4600
- status: response.status,
4601
- statusText: response.statusText,
4602
- data: response.data,
4603
- duration,
4604
- timestamp: Date.now()
4605
- }
4606
- );
4607
- }
4608
- return response.data;
4609
- } catch (error) {
4610
- const duration = Date.now() - startTime;
4611
- if (error instanceof APIError4) {
4612
- throw error;
4613
- }
4614
- const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
4615
- if (this.logger) {
4616
- if (isCORSError) {
4617
- this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
4618
- this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
4619
- this.logger.error(` \u2192 Configure security_domains parameter on the server`);
4620
- } else {
4621
- this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
4622
- this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
4623
- }
4624
- }
4625
- if (typeof window !== "undefined") {
4626
- try {
4627
- if (isCORSError) {
4628
- window.dispatchEvent(new CustomEvent("cors-error", {
4629
- detail: {
4630
- url,
4631
- method,
4632
- error: error instanceof Error ? error.message : String(error),
4633
- timestamp: /* @__PURE__ */ new Date()
4634
- },
4635
- bubbles: true,
4636
- cancelable: false
4637
- }));
4638
- } else {
4639
- window.dispatchEvent(new CustomEvent("network-error", {
4640
- detail: {
4641
- url,
4642
- method,
4643
- error: error instanceof Error ? error.message : String(error),
4644
- timestamp: /* @__PURE__ */ new Date()
4645
- },
4646
- bubbles: true,
4647
- cancelable: false
4648
- }));
4649
- }
4650
- } catch (eventError) {
4651
- }
4652
- }
4653
- const networkError = error instanceof Error ? new NetworkError4(error.message, url, error) : new NetworkError4("Unknown error", url);
4654
- if (this.logger) {
4655
- this.logger.logError(
4656
- {
4657
- method,
4658
- url,
4659
- headers,
4660
- body: options?.formData || options?.body,
4661
- timestamp: startTime
4662
- },
4663
- {
4664
- message: networkError.message,
4665
- duration,
4666
- timestamp: Date.now()
4667
- }
4668
- );
4669
- }
4670
- throw networkError;
4671
- }
4672
- }
4673
- };
4674
-
4675
- // src/generated/cfg_webpush/storage.ts
4676
- var LocalStorageAdapter4 = class {
4677
- static {
4678
- __name(this, "LocalStorageAdapter");
4679
- }
4680
- constructor(logger2) {
4681
- this.logger = logger2;
4682
- }
4683
- getItem(key) {
4684
- try {
4685
- if (typeof window !== "undefined" && window.localStorage) {
4686
- const value = localStorage.getItem(key);
4687
- this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
4688
- return value;
4689
- }
4690
- this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
4691
- } catch (error) {
4692
- this.logger?.error("LocalStorage.getItem failed:", error);
4693
- }
4694
- return null;
4695
- }
4696
- setItem(key, value) {
4697
- try {
4698
- if (typeof window !== "undefined" && window.localStorage) {
4699
- localStorage.setItem(key, value);
4700
- this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
4701
- } else {
4702
- this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
4703
- }
4704
- } catch (error) {
4705
- this.logger?.error("LocalStorage.setItem failed:", error);
4706
- }
4707
- }
4708
- removeItem(key) {
4709
- try {
4710
- if (typeof window !== "undefined" && window.localStorage) {
4711
- localStorage.removeItem(key);
4712
- this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
4713
- } else {
4714
- this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
4715
- }
4716
- } catch (error) {
4717
- this.logger?.error("LocalStorage.removeItem failed:", error);
4718
- }
4719
- }
4720
- };
4721
-
4722
- // src/generated/cfg_webpush/_utils/schemas/SendPushRequestRequest.schema.ts
4723
- import { z as z72 } from "zod";
4724
- var SendPushRequestRequestSchema = z72.object({
4725
- title: z72.string().min(1).max(255),
4726
- body: z72.string().min(1),
4727
- icon: z72.union([z72.url(), z72.literal("")]).nullable().optional(),
4728
- url: z72.union([z72.url(), z72.literal("")]).nullable().optional()
4729
- });
4730
-
4731
- // src/generated/cfg_webpush/_utils/schemas/SendPushResponse.schema.ts
4732
- import { z as z73 } from "zod";
4733
- var SendPushResponseSchema = z73.object({
4734
- success: z73.boolean(),
4735
- sent_to: z73.int()
4736
- });
4737
-
4738
- // src/generated/cfg_webpush/_utils/schemas/SubscribeRequestRequest.schema.ts
4739
- import { z as z74 } from "zod";
4740
- var SubscribeRequestRequestSchema = z74.object({
4741
- endpoint: z74.union([z74.url(), z74.literal("")]),
4742
- keys: z74.record(z74.string(), z74.string().min(1))
4743
- });
4744
-
4745
- // src/generated/cfg_webpush/_utils/schemas/SubscribeResponse.schema.ts
4746
- import { z as z75 } from "zod";
4747
- var SubscribeResponseSchema = z75.object({
4748
- success: z75.boolean(),
4749
- subscription_id: z75.int(),
4750
- created: z75.boolean()
4751
- });
4752
-
4753
- // src/generated/cfg_webpush/_utils/schemas/VapidPublicKeyResponse.schema.ts
4754
- import { z as z76 } from "zod";
4755
- var VapidPublicKeyResponseSchema = z76.object({
4756
- publicKey: z76.string()
4757
- });
4758
-
4759
- // src/generated/cfg_webpush/_utils/fetchers/webpush__web_push.ts
4760
- import { consola as consola13 } from "consola";
4761
-
4762
- // src/generated/cfg_webpush/index.ts
4763
- var TOKEN_KEY4 = "auth_token";
4764
- var REFRESH_TOKEN_KEY4 = "refresh_token";
4765
- var API4 = class {
4766
- constructor(baseUrl, options) {
4767
- this._token = null;
4768
- this._refreshToken = null;
4769
- this.baseUrl = baseUrl;
4770
- this.options = options;
4771
- const logger2 = options?.loggerConfig ? new APILogger4(options.loggerConfig) : void 0;
4772
- this.storage = options?.storage || new LocalStorageAdapter4(logger2);
4773
- this._loadTokensFromStorage();
4774
- this._client = new APIClient4(this.baseUrl, {
4775
- retryConfig: this.options?.retryConfig,
4776
- loggerConfig: this.options?.loggerConfig,
4777
- tokenGetter: /* @__PURE__ */ __name(() => this.getToken(), "tokenGetter")
4778
- });
4779
- this._injectAuthHeader();
4780
- this.web_push = this._client.web_push;
4781
- }
4782
- static {
4783
- __name(this, "API");
4784
- }
4785
- _loadTokensFromStorage() {
4786
- this._token = this.storage.getItem(TOKEN_KEY4);
4787
- this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY4);
4788
- }
4789
- _reinitClients() {
4790
- this._client = new APIClient4(this.baseUrl, {
4791
- retryConfig: this.options?.retryConfig,
4792
- loggerConfig: this.options?.loggerConfig,
4793
- tokenGetter: /* @__PURE__ */ __name(() => this.getToken(), "tokenGetter")
4794
- });
4795
- this._injectAuthHeader();
4796
- this.web_push = this._client.web_push;
4797
- }
4798
- _injectAuthHeader() {
4799
- const originalRequest = this._client.request.bind(this._client);
4800
- this._client.request = async (method, path, options) => {
4801
- const token = this.getToken();
4802
- const mergedOptions = {
4803
- ...options,
4804
- headers: {
4805
- ...options?.headers || {},
4806
- ...token ? { "Authorization": `Bearer ${token}` } : {}
4807
- }
4808
- };
4809
- return originalRequest(method, path, mergedOptions);
4810
- };
4811
- }
4812
- /**
4813
- * Get current JWT token
4814
- */
4815
- getToken() {
4816
- return this.storage.getItem(TOKEN_KEY4);
4817
- }
4818
- /**
4819
- * Get current refresh token
4820
- */
4821
- getRefreshToken() {
4822
- return this.storage.getItem(REFRESH_TOKEN_KEY4);
4823
- }
4824
- /**
4825
- * Set JWT token and refresh token
4826
- * @param token - JWT access token
4827
- * @param refreshToken - JWT refresh token (optional)
4828
- */
4829
- setToken(token, refreshToken) {
4830
- this._token = token;
4831
- this.storage.setItem(TOKEN_KEY4, token);
4832
- if (refreshToken) {
4833
- this._refreshToken = refreshToken;
4834
- this.storage.setItem(REFRESH_TOKEN_KEY4, refreshToken);
4835
- }
4836
- this._reinitClients();
4837
- }
4838
- /**
4839
- * Clear all tokens
4840
- */
4841
- clearTokens() {
4842
- this._token = null;
4843
- this._refreshToken = null;
4844
- this.storage.removeItem(TOKEN_KEY4);
4845
- this.storage.removeItem(REFRESH_TOKEN_KEY4);
4846
- this._reinitClients();
4847
- }
4848
- /**
4849
- * Check if user is authenticated
4850
- */
4851
- isAuthenticated() {
4852
- return !!this.getToken();
4853
- }
4854
- /**
4855
- * Update base URL and reinitialize clients
4856
- * @param url - New base URL
4857
- */
4858
- setBaseUrl(url) {
4859
- this.baseUrl = url;
4860
- this._reinitClients();
4861
- }
4862
- /**
4863
- * Get current base URL
4864
- */
4865
- getBaseUrl() {
4866
- return this.baseUrl;
4867
- }
4868
- /**
4869
- * Get OpenAPI schema path
4870
- * @returns Path to the OpenAPI schema JSON file
4871
- *
4872
- * Note: The OpenAPI schema is available in the schema.json file.
4873
- * You can load it dynamically using:
4874
- * ```typescript
4875
- * const schema = await fetch('./schema.json').then(r => r.json());
4876
- * // or using fs in Node.js:
4877
- * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
4878
- * ```
4879
- */
4880
- getSchemaPath() {
4881
- return "./schema.json";
4882
- }
4883
- };
4884
-
4885
4065
  // src/generated/cfg_accounts/_utils/hooks/accounts__auth.ts
4886
4066
  import { useSWRConfig } from "swr";
4887
4067
  function useCreateAccountsTokenRefreshCreate() {
@@ -4950,38 +4130,34 @@ function useCreateAccountsOtpVerifyCreate() {
4950
4130
  }
4951
4131
  __name(useCreateAccountsOtpVerifyCreate, "useCreateAccountsOtpVerifyCreate");
4952
4132
 
4953
- // src/generated/cfg_webpush/_utils/hooks/webpush__web_push.ts
4954
- import useSWR3 from "swr";
4955
- import { useSWRConfig as useSWRConfig5 } from "swr";
4956
-
4957
4133
  // src/generated/cfg_centrifugo/_utils/hooks/centrifugo__centrifugo_admin_api.ts
4958
- import { useSWRConfig as useSWRConfig6 } from "swr";
4134
+ import { useSWRConfig as useSWRConfig5 } from "swr";
4959
4135
 
4960
4136
  // src/generated/cfg_centrifugo/_utils/hooks/centrifugo__centrifugo_auth.ts
4961
- import useSWR4 from "swr";
4137
+ import useSWR3 from "swr";
4962
4138
 
4963
4139
  // src/generated/cfg_centrifugo/_utils/hooks/centrifugo__centrifugo_monitoring.ts
4964
- import useSWR5 from "swr";
4140
+ import useSWR4 from "swr";
4965
4141
 
4966
4142
  // src/generated/cfg_centrifugo/_utils/hooks/centrifugo__centrifugo_testing.ts
4967
- import { useSWRConfig as useSWRConfig7 } from "swr";
4143
+ import { useSWRConfig as useSWRConfig6 } from "swr";
4968
4144
 
4969
4145
  // src/generated/cfg_totp/_utils/hooks/totp__backup_codes.ts
4970
- import useSWR6 from "swr";
4971
- import { useSWRConfig as useSWRConfig8 } from "swr";
4146
+ import useSWR5 from "swr";
4147
+ import { useSWRConfig as useSWRConfig7 } from "swr";
4972
4148
 
4973
4149
  // src/generated/cfg_totp/_utils/hooks/totp__totp_management.ts
4974
- import useSWR7 from "swr";
4975
- import { useSWRConfig as useSWRConfig9 } from "swr";
4150
+ import useSWR6 from "swr";
4151
+ import { useSWRConfig as useSWRConfig8 } from "swr";
4976
4152
 
4977
4153
  // src/generated/cfg_totp/_utils/hooks/totp__totp_setup.ts
4978
- import { useSWRConfig as useSWRConfig10 } from "swr";
4154
+ import { useSWRConfig as useSWRConfig9 } from "swr";
4979
4155
 
4980
4156
  // src/generated/cfg_totp/_utils/hooks/totp__totp_verification.ts
4981
- import { useSWRConfig as useSWRConfig11 } from "swr";
4157
+ import { useSWRConfig as useSWRConfig10 } from "swr";
4982
4158
 
4983
4159
  // src/generated/cfg_totp/_utils/hooks/totp.ts
4984
- import { useSWRConfig as useSWRConfig12 } from "swr";
4160
+ import { useSWRConfig as useSWRConfig11 } from "swr";
4985
4161
 
4986
4162
  // src/clients.ts
4987
4163
  var isStaticBuild2 = process.env.NEXT_PUBLIC_STATIC_BUILD === "true";
@@ -4989,7 +4165,6 @@ var apiUrl = isStaticBuild2 ? "" : process.env.NEXT_PUBLIC_API_URL || "";
4989
4165
  var storage = new LocalStorageAdapter();
4990
4166
  var apiAccounts = new API(apiUrl, { storage });
4991
4167
  var apiTotp = new API3(apiUrl, { storage });
4992
- var apiWebPush = new API4(apiUrl, { storage });
4993
4168
  var apiCentrifugo = new API2(apiUrl, { storage });
4994
4169
 
4995
4170
  // src/auth/utils/analytics.ts