@asgardeo/javascript 0.15.0 → 0.16.1

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,
@@ -3529,6 +3530,7 @@ var EmbeddedFlowComponentType2 = /* @__PURE__ */ ((EmbeddedFlowComponentType3) =
3529
3530
  EmbeddedFlowComponentType3["Action"] = "ACTION";
3530
3531
  EmbeddedFlowComponentType3["Block"] = "BLOCK";
3531
3532
  EmbeddedFlowComponentType3["Consent"] = "CONSENT";
3533
+ EmbeddedFlowComponentType3["CopyableText"] = "COPYABLE_TEXT";
3532
3534
  EmbeddedFlowComponentType3["Divider"] = "DIVIDER";
3533
3535
  EmbeddedFlowComponentType3["EmailInput"] = "EMAIL_INPUT";
3534
3536
  EmbeddedFlowComponentType3["Icon"] = "ICON";
@@ -5418,6 +5420,103 @@ var transformBrandingPreferenceToTheme = (brandingPreference, forceTheme) => {
5418
5420
  return createTheme_default(transformedConfig, activeThemeKey === "DARK");
5419
5421
  };
5420
5422
  var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTheme;
5423
+
5424
+ // src/HttpClient.ts
5425
+ var _HttpClient = class _HttpClient {
5426
+ constructor(isHandlerEnabled = true, attachToken = () => Promise.resolve()) {
5427
+ this.isHandlerEnabled = isHandlerEnabled;
5428
+ this.attachToken = attachToken;
5429
+ // eslint-disable-next-line class-methods-use-this
5430
+ __publicField(this, "requestStartCallback", () => null);
5431
+ // eslint-disable-next-line class-methods-use-this
5432
+ __publicField(this, "requestSuccessCallback", () => null);
5433
+ // eslint-disable-next-line class-methods-use-this
5434
+ __publicField(this, "requestErrorCallback", () => null);
5435
+ // eslint-disable-next-line class-methods-use-this
5436
+ __publicField(this, "requestFinishCallback", () => null);
5437
+ }
5438
+ /**
5439
+ * Public HTTP request entry point. Applies pre/post processing around `transport()`.
5440
+ */
5441
+ async request(config) {
5442
+ const processedConfig = await this.requestHandler(config);
5443
+ try {
5444
+ const response = await this.transport(processedConfig);
5445
+ return this.successHandler(response);
5446
+ } catch (error2) {
5447
+ this.errorHandler(error2);
5448
+ throw error2;
5449
+ }
5450
+ }
5451
+ enableHandler() {
5452
+ this.isHandlerEnabled = true;
5453
+ }
5454
+ disableHandler() {
5455
+ this.isHandlerEnabled = false;
5456
+ }
5457
+ disableHandlerWithTimeout(timeout = _HttpClient.DEFAULT_HANDLER_DISABLE_TIMEOUT) {
5458
+ this.isHandlerEnabled = false;
5459
+ setTimeout(() => {
5460
+ this.isHandlerEnabled = true;
5461
+ }, timeout);
5462
+ }
5463
+ setHttpRequestStartCallback(cb) {
5464
+ this.requestStartCallback = cb;
5465
+ }
5466
+ setHttpRequestSuccessCallback(cb) {
5467
+ this.requestSuccessCallback = cb;
5468
+ }
5469
+ setHttpRequestErrorCallback(cb) {
5470
+ this.requestErrorCallback = cb;
5471
+ }
5472
+ setHttpRequestFinishCallback(cb) {
5473
+ this.requestFinishCallback = cb;
5474
+ }
5475
+ // eslint-disable-next-line class-methods-use-this
5476
+ all(values) {
5477
+ return Promise.all(values);
5478
+ }
5479
+ // eslint-disable-next-line class-methods-use-this
5480
+ spread(callback) {
5481
+ return (array) => callback(...array);
5482
+ }
5483
+ async requestHandler(config) {
5484
+ await this.attachToken(config);
5485
+ if (config.shouldEncodeToFormData && config.data) {
5486
+ const formData = new FormData();
5487
+ Object.keys(config.data).forEach((key) => formData.append(key, config.data[key]));
5488
+ config.data = formData;
5489
+ }
5490
+ config.startTimeInMs = Date.now();
5491
+ if (this.isHandlerEnabled && typeof this.requestStartCallback === "function") {
5492
+ this.requestStartCallback(config);
5493
+ }
5494
+ return config;
5495
+ }
5496
+ successHandler(response) {
5497
+ if (this.isHandlerEnabled) {
5498
+ if (typeof this.requestSuccessCallback === "function") {
5499
+ this.requestSuccessCallback(response);
5500
+ }
5501
+ if (typeof this.requestFinishCallback === "function") {
5502
+ this.requestFinishCallback();
5503
+ }
5504
+ }
5505
+ return response;
5506
+ }
5507
+ errorHandler(error2) {
5508
+ if (this.isHandlerEnabled) {
5509
+ if (typeof this.requestErrorCallback === "function") {
5510
+ this.requestErrorCallback(error2);
5511
+ }
5512
+ if (typeof this.requestFinishCallback === "function") {
5513
+ this.requestFinishCallback();
5514
+ }
5515
+ }
5516
+ }
5517
+ };
5518
+ __publicField(_HttpClient, "DEFAULT_HANDLER_DISABLE_TIMEOUT", 1e3);
5519
+ var HttpClient = _HttpClient;
5421
5520
  // Annotate the CommonJS export names for ESM import in node:
5422
5521
  0 && (module.exports = {
5423
5522
  AgentConfig,
@@ -5451,6 +5550,7 @@ var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTh
5451
5550
  FieldType,
5452
5551
  FlowMetaType,
5453
5552
  FlowMode,
5553
+ HttpClient,
5454
5554
  IsomorphicCrypto,
5455
5555
  OIDCRequestConstants,
5456
5556
  Platform,