@asgardeo/javascript 0.15.0 → 0.16.0

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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { HttpError, HttpRequestConfig, HttpResponse } from './models/http';
19
+ /**
20
+ * Abstract base class for HTTP clients. Owns all handler/callback state and
21
+ * the request lifecycle (pre-processing, transport, post-processing).
22
+ *
23
+ * Extend this class and implement `transport()` to plug in a custom HTTP transport.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * class MyHttpClient extends HttpClient {
28
+ * protected async transport<T>(config: HttpRequestConfig): Promise<HttpResponse<T>> {
29
+ * // custom fetch logic
30
+ * }
31
+ * }
32
+ * ```
33
+ */
34
+ export declare abstract class HttpClient {
35
+ private isHandlerEnabled;
36
+ private attachToken;
37
+ private static readonly DEFAULT_HANDLER_DISABLE_TIMEOUT;
38
+ private requestStartCallback;
39
+ private requestSuccessCallback;
40
+ private requestErrorCallback;
41
+ private requestFinishCallback;
42
+ constructor(isHandlerEnabled?: boolean, attachToken?: (request: HttpRequestConfig) => Promise<void>);
43
+ /**
44
+ * Implemented by subclasses. Performs the actual HTTP call with no handler
45
+ * logic applied — that is handled by `request()`.
46
+ */
47
+ protected abstract transport<T = any>(config: HttpRequestConfig): Promise<HttpResponse<T>>;
48
+ /**
49
+ * Public HTTP request entry point. Applies pre/post processing around `transport()`.
50
+ */
51
+ request<T = any>(config: HttpRequestConfig): Promise<HttpResponse<T>>;
52
+ enableHandler(): void;
53
+ disableHandler(): void;
54
+ disableHandlerWithTimeout(timeout?: number): void;
55
+ setHttpRequestStartCallback(cb: (req: HttpRequestConfig) => void): void;
56
+ setHttpRequestSuccessCallback(cb: (res: HttpResponse) => void): void;
57
+ setHttpRequestErrorCallback(cb: (err: HttpError) => void): void;
58
+ setHttpRequestFinishCallback(cb: () => void): void;
59
+ all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
60
+ spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
61
+ protected requestHandler(config: HttpRequestConfig): Promise<HttpRequestConfig>;
62
+ protected successHandler(response: HttpResponse): HttpResponse;
63
+ protected errorHandler(error: HttpError): void;
64
+ }
package/dist/cjs/index.js CHANGED
@@ -62,6 +62,7 @@ __export(index_exports, {
62
62
  FieldType: () => FieldType,
63
63
  FlowMetaType: () => FlowMetaType,
64
64
  FlowMode: () => FlowMode,
65
+ HttpClient: () => HttpClient,
65
66
  IsomorphicCrypto: () => IsomorphicCrypto,
66
67
  OIDCRequestConstants: () => OIDCRequestConstants_default,
67
68
  Platform: () => Platform,
@@ -5418,6 +5419,103 @@ var transformBrandingPreferenceToTheme = (brandingPreference, forceTheme) => {
5418
5419
  return createTheme_default(transformedConfig, activeThemeKey === "DARK");
5419
5420
  };
5420
5421
  var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTheme;
5422
+
5423
+ // src/HttpClient.ts
5424
+ var _HttpClient = class _HttpClient {
5425
+ constructor(isHandlerEnabled = true, attachToken = () => Promise.resolve()) {
5426
+ this.isHandlerEnabled = isHandlerEnabled;
5427
+ this.attachToken = attachToken;
5428
+ // eslint-disable-next-line class-methods-use-this
5429
+ __publicField(this, "requestStartCallback", () => null);
5430
+ // eslint-disable-next-line class-methods-use-this
5431
+ __publicField(this, "requestSuccessCallback", () => null);
5432
+ // eslint-disable-next-line class-methods-use-this
5433
+ __publicField(this, "requestErrorCallback", () => null);
5434
+ // eslint-disable-next-line class-methods-use-this
5435
+ __publicField(this, "requestFinishCallback", () => null);
5436
+ }
5437
+ /**
5438
+ * Public HTTP request entry point. Applies pre/post processing around `transport()`.
5439
+ */
5440
+ async request(config) {
5441
+ const processedConfig = await this.requestHandler(config);
5442
+ try {
5443
+ const response = await this.transport(processedConfig);
5444
+ return this.successHandler(response);
5445
+ } catch (error2) {
5446
+ this.errorHandler(error2);
5447
+ throw error2;
5448
+ }
5449
+ }
5450
+ enableHandler() {
5451
+ this.isHandlerEnabled = true;
5452
+ }
5453
+ disableHandler() {
5454
+ this.isHandlerEnabled = false;
5455
+ }
5456
+ disableHandlerWithTimeout(timeout = _HttpClient.DEFAULT_HANDLER_DISABLE_TIMEOUT) {
5457
+ this.isHandlerEnabled = false;
5458
+ setTimeout(() => {
5459
+ this.isHandlerEnabled = true;
5460
+ }, timeout);
5461
+ }
5462
+ setHttpRequestStartCallback(cb) {
5463
+ this.requestStartCallback = cb;
5464
+ }
5465
+ setHttpRequestSuccessCallback(cb) {
5466
+ this.requestSuccessCallback = cb;
5467
+ }
5468
+ setHttpRequestErrorCallback(cb) {
5469
+ this.requestErrorCallback = cb;
5470
+ }
5471
+ setHttpRequestFinishCallback(cb) {
5472
+ this.requestFinishCallback = cb;
5473
+ }
5474
+ // eslint-disable-next-line class-methods-use-this
5475
+ all(values) {
5476
+ return Promise.all(values);
5477
+ }
5478
+ // eslint-disable-next-line class-methods-use-this
5479
+ spread(callback) {
5480
+ return (array) => callback(...array);
5481
+ }
5482
+ async requestHandler(config) {
5483
+ await this.attachToken(config);
5484
+ if (config.shouldEncodeToFormData && config.data) {
5485
+ const formData = new FormData();
5486
+ Object.keys(config.data).forEach((key) => formData.append(key, config.data[key]));
5487
+ config.data = formData;
5488
+ }
5489
+ config.startTimeInMs = Date.now();
5490
+ if (this.isHandlerEnabled && typeof this.requestStartCallback === "function") {
5491
+ this.requestStartCallback(config);
5492
+ }
5493
+ return config;
5494
+ }
5495
+ successHandler(response) {
5496
+ if (this.isHandlerEnabled) {
5497
+ if (typeof this.requestSuccessCallback === "function") {
5498
+ this.requestSuccessCallback(response);
5499
+ }
5500
+ if (typeof this.requestFinishCallback === "function") {
5501
+ this.requestFinishCallback();
5502
+ }
5503
+ }
5504
+ return response;
5505
+ }
5506
+ errorHandler(error2) {
5507
+ if (this.isHandlerEnabled) {
5508
+ if (typeof this.requestErrorCallback === "function") {
5509
+ this.requestErrorCallback(error2);
5510
+ }
5511
+ if (typeof this.requestFinishCallback === "function") {
5512
+ this.requestFinishCallback();
5513
+ }
5514
+ }
5515
+ }
5516
+ };
5517
+ __publicField(_HttpClient, "DEFAULT_HANDLER_DISABLE_TIMEOUT", 1e3);
5518
+ var HttpClient = _HttpClient;
5421
5519
  // Annotate the CommonJS export names for ESM import in node:
5422
5520
  0 && (module.exports = {
5423
5521
  AgentConfig,
@@ -5451,6 +5549,7 @@ var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTh
5451
5549
  FieldType,
5452
5550
  FlowMetaType,
5453
5551
  FlowMode,
5552
+ HttpClient,
5454
5553
  IsomorphicCrypto,
5455
5554
  OIDCRequestConstants,
5456
5555
  Platform,