@asgardeo/javascript 0.14.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.
- package/dist/HttpClient.d.ts +64 -0
- package/dist/cjs/index.js +124 -0
- package/dist/cjs/index.js.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +123 -0
- package/dist/index.js.map +4 -4
- package/dist/models/config.d.ts +15 -1
- package/dist/models/http.d.ts +45 -0
- package/dist/theme/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -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,
|
|
@@ -3891,11 +3892,13 @@ var lightTheme = {
|
|
|
3891
3892
|
error: {
|
|
3892
3893
|
contrastText: "#d52828",
|
|
3893
3894
|
dark: "#b71c1c",
|
|
3895
|
+
light: "#fef2f2",
|
|
3894
3896
|
main: "#d32f2f"
|
|
3895
3897
|
},
|
|
3896
3898
|
info: {
|
|
3897
3899
|
contrastText: "#43aeda",
|
|
3898
3900
|
dark: "#01579b",
|
|
3901
|
+
light: "#eff6ff",
|
|
3899
3902
|
main: "#bbebff"
|
|
3900
3903
|
},
|
|
3901
3904
|
primary: {
|
|
@@ -3906,11 +3909,13 @@ var lightTheme = {
|
|
|
3906
3909
|
secondary: {
|
|
3907
3910
|
contrastText: "#ffffff",
|
|
3908
3911
|
dark: "#212121",
|
|
3912
|
+
light: "#f3f4f6",
|
|
3909
3913
|
main: "#424242"
|
|
3910
3914
|
},
|
|
3911
3915
|
success: {
|
|
3912
3916
|
contrastText: "#00a807",
|
|
3913
3917
|
dark: "#388e3c",
|
|
3918
|
+
light: "#f0fdf4",
|
|
3914
3919
|
main: "#4caf50"
|
|
3915
3920
|
},
|
|
3916
3921
|
text: {
|
|
@@ -3921,6 +3926,7 @@ var lightTheme = {
|
|
|
3921
3926
|
warning: {
|
|
3922
3927
|
contrastText: "#be7100",
|
|
3923
3928
|
dark: "#f57c00",
|
|
3929
|
+
light: "#fffbeb",
|
|
3924
3930
|
main: "#ff9800"
|
|
3925
3931
|
}
|
|
3926
3932
|
},
|
|
@@ -4000,11 +4006,13 @@ var darkTheme = {
|
|
|
4000
4006
|
error: {
|
|
4001
4007
|
contrastText: "#d52828",
|
|
4002
4008
|
dark: "#b71c1c",
|
|
4009
|
+
light: "#2d1515",
|
|
4003
4010
|
main: "#d32f2f"
|
|
4004
4011
|
},
|
|
4005
4012
|
info: {
|
|
4006
4013
|
contrastText: "#43aeda",
|
|
4007
4014
|
dark: "#01579b",
|
|
4015
|
+
light: "#0f1f35",
|
|
4008
4016
|
main: "#bbebff"
|
|
4009
4017
|
},
|
|
4010
4018
|
primary: {
|
|
@@ -4015,11 +4023,13 @@ var darkTheme = {
|
|
|
4015
4023
|
secondary: {
|
|
4016
4024
|
contrastText: "#ffffff",
|
|
4017
4025
|
dark: "#212121",
|
|
4026
|
+
light: "#2a2a2a",
|
|
4018
4027
|
main: "#8b8b8b"
|
|
4019
4028
|
},
|
|
4020
4029
|
success: {
|
|
4021
4030
|
contrastText: "#00a807",
|
|
4022
4031
|
dark: "#388e3c",
|
|
4032
|
+
light: "#132d1a",
|
|
4023
4033
|
main: "#4caf50"
|
|
4024
4034
|
},
|
|
4025
4035
|
text: {
|
|
@@ -4030,6 +4040,7 @@ var darkTheme = {
|
|
|
4030
4040
|
warning: {
|
|
4031
4041
|
contrastText: "#be7100",
|
|
4032
4042
|
dark: "#f57c00",
|
|
4043
|
+
light: "#2d2310",
|
|
4033
4044
|
main: "#ff9800"
|
|
4034
4045
|
}
|
|
4035
4046
|
},
|
|
@@ -4124,6 +4135,9 @@ var toCssVariables = (theme) => {
|
|
|
4124
4135
|
if (theme.colors?.secondary?.contrastText) {
|
|
4125
4136
|
cssVars[`--${prefix}-color-secondary-contrastText`] = theme.colors.secondary.contrastText;
|
|
4126
4137
|
}
|
|
4138
|
+
if (theme.colors?.secondary?.light) {
|
|
4139
|
+
cssVars[`--${prefix}-color-secondary-light`] = theme.colors.secondary.light;
|
|
4140
|
+
}
|
|
4127
4141
|
if (theme.colors?.background?.surface) {
|
|
4128
4142
|
cssVars[`--${prefix}-color-background-surface`] = theme.colors.background.surface;
|
|
4129
4143
|
}
|
|
@@ -4139,24 +4153,36 @@ var toCssVariables = (theme) => {
|
|
|
4139
4153
|
if (theme.colors?.error?.contrastText) {
|
|
4140
4154
|
cssVars[`--${prefix}-color-error-contrastText`] = theme.colors.error.contrastText;
|
|
4141
4155
|
}
|
|
4156
|
+
if (theme.colors?.error?.light) {
|
|
4157
|
+
cssVars[`--${prefix}-color-error-light`] = theme.colors.error.light;
|
|
4158
|
+
}
|
|
4142
4159
|
if (theme.colors?.success?.main) {
|
|
4143
4160
|
cssVars[`--${prefix}-color-success-main`] = theme.colors.success.main;
|
|
4144
4161
|
}
|
|
4145
4162
|
if (theme.colors?.success?.contrastText) {
|
|
4146
4163
|
cssVars[`--${prefix}-color-success-contrastText`] = theme.colors.success.contrastText;
|
|
4147
4164
|
}
|
|
4165
|
+
if (theme.colors?.success?.light) {
|
|
4166
|
+
cssVars[`--${prefix}-color-success-light`] = theme.colors.success.light;
|
|
4167
|
+
}
|
|
4148
4168
|
if (theme.colors?.warning?.main) {
|
|
4149
4169
|
cssVars[`--${prefix}-color-warning-main`] = theme.colors.warning.main;
|
|
4150
4170
|
}
|
|
4151
4171
|
if (theme.colors?.warning?.contrastText) {
|
|
4152
4172
|
cssVars[`--${prefix}-color-warning-contrastText`] = theme.colors.warning.contrastText;
|
|
4153
4173
|
}
|
|
4174
|
+
if (theme.colors?.warning?.light) {
|
|
4175
|
+
cssVars[`--${prefix}-color-warning-light`] = theme.colors.warning.light;
|
|
4176
|
+
}
|
|
4154
4177
|
if (theme.colors?.info?.main) {
|
|
4155
4178
|
cssVars[`--${prefix}-color-info-main`] = theme.colors.info.main;
|
|
4156
4179
|
}
|
|
4157
4180
|
if (theme.colors?.info?.contrastText) {
|
|
4158
4181
|
cssVars[`--${prefix}-color-info-contrastText`] = theme.colors.info.contrastText;
|
|
4159
4182
|
}
|
|
4183
|
+
if (theme.colors?.info?.light) {
|
|
4184
|
+
cssVars[`--${prefix}-color-info-light`] = theme.colors.info.light;
|
|
4185
|
+
}
|
|
4160
4186
|
if (theme.colors?.text?.primary) {
|
|
4161
4187
|
cssVars[`--${prefix}-color-text-primary`] = theme.colors.text.primary;
|
|
4162
4188
|
}
|
|
@@ -5393,6 +5419,103 @@ var transformBrandingPreferenceToTheme = (brandingPreference, forceTheme) => {
|
|
|
5393
5419
|
return createTheme_default(transformedConfig, activeThemeKey === "DARK");
|
|
5394
5420
|
};
|
|
5395
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;
|
|
5396
5519
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5397
5520
|
0 && (module.exports = {
|
|
5398
5521
|
AgentConfig,
|
|
@@ -5426,6 +5549,7 @@ var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTh
|
|
|
5426
5549
|
FieldType,
|
|
5427
5550
|
FlowMetaType,
|
|
5428
5551
|
FlowMode,
|
|
5552
|
+
HttpClient,
|
|
5429
5553
|
IsomorphicCrypto,
|
|
5430
5554
|
OIDCRequestConstants,
|
|
5431
5555
|
Platform,
|