@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.
- package/dist/HttpClient.d.ts +64 -0
- package/dist/cjs/index.js +99 -0
- package/dist/cjs/index.js.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +98 -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/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -112,3 +112,5 @@ export { default as transformBrandingPreferenceToTheme } from './utils/transform
|
|
|
112
112
|
export { default as logger, createLogger, createComponentLogger, createPackageLogger, createPackageComponentLogger, LogLevel, configure as configureLogger, debug, info, warn, error, } from './utils/logger';
|
|
113
113
|
export type { LoggerConfig } from './utils/logger';
|
|
114
114
|
export { default as StorageManager } from './StorageManager';
|
|
115
|
+
export { HttpClient } from './HttpClient';
|
|
116
|
+
export { HttpError, HttpRequestConfig, HttpResponse } from './models/http';
|
package/dist/index.js
CHANGED
|
@@ -5286,6 +5286,103 @@ var transformBrandingPreferenceToTheme = (brandingPreference, forceTheme) => {
|
|
|
5286
5286
|
return createTheme_default(transformedConfig, activeThemeKey === "DARK");
|
|
5287
5287
|
};
|
|
5288
5288
|
var transformBrandingPreferenceToTheme_default = transformBrandingPreferenceToTheme;
|
|
5289
|
+
|
|
5290
|
+
// src/HttpClient.ts
|
|
5291
|
+
var _HttpClient = class _HttpClient {
|
|
5292
|
+
constructor(isHandlerEnabled = true, attachToken = () => Promise.resolve()) {
|
|
5293
|
+
this.isHandlerEnabled = isHandlerEnabled;
|
|
5294
|
+
this.attachToken = attachToken;
|
|
5295
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5296
|
+
__publicField(this, "requestStartCallback", () => null);
|
|
5297
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5298
|
+
__publicField(this, "requestSuccessCallback", () => null);
|
|
5299
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5300
|
+
__publicField(this, "requestErrorCallback", () => null);
|
|
5301
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5302
|
+
__publicField(this, "requestFinishCallback", () => null);
|
|
5303
|
+
}
|
|
5304
|
+
/**
|
|
5305
|
+
* Public HTTP request entry point. Applies pre/post processing around `transport()`.
|
|
5306
|
+
*/
|
|
5307
|
+
async request(config) {
|
|
5308
|
+
const processedConfig = await this.requestHandler(config);
|
|
5309
|
+
try {
|
|
5310
|
+
const response = await this.transport(processedConfig);
|
|
5311
|
+
return this.successHandler(response);
|
|
5312
|
+
} catch (error2) {
|
|
5313
|
+
this.errorHandler(error2);
|
|
5314
|
+
throw error2;
|
|
5315
|
+
}
|
|
5316
|
+
}
|
|
5317
|
+
enableHandler() {
|
|
5318
|
+
this.isHandlerEnabled = true;
|
|
5319
|
+
}
|
|
5320
|
+
disableHandler() {
|
|
5321
|
+
this.isHandlerEnabled = false;
|
|
5322
|
+
}
|
|
5323
|
+
disableHandlerWithTimeout(timeout = _HttpClient.DEFAULT_HANDLER_DISABLE_TIMEOUT) {
|
|
5324
|
+
this.isHandlerEnabled = false;
|
|
5325
|
+
setTimeout(() => {
|
|
5326
|
+
this.isHandlerEnabled = true;
|
|
5327
|
+
}, timeout);
|
|
5328
|
+
}
|
|
5329
|
+
setHttpRequestStartCallback(cb) {
|
|
5330
|
+
this.requestStartCallback = cb;
|
|
5331
|
+
}
|
|
5332
|
+
setHttpRequestSuccessCallback(cb) {
|
|
5333
|
+
this.requestSuccessCallback = cb;
|
|
5334
|
+
}
|
|
5335
|
+
setHttpRequestErrorCallback(cb) {
|
|
5336
|
+
this.requestErrorCallback = cb;
|
|
5337
|
+
}
|
|
5338
|
+
setHttpRequestFinishCallback(cb) {
|
|
5339
|
+
this.requestFinishCallback = cb;
|
|
5340
|
+
}
|
|
5341
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5342
|
+
all(values) {
|
|
5343
|
+
return Promise.all(values);
|
|
5344
|
+
}
|
|
5345
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5346
|
+
spread(callback) {
|
|
5347
|
+
return (array) => callback(...array);
|
|
5348
|
+
}
|
|
5349
|
+
async requestHandler(config) {
|
|
5350
|
+
await this.attachToken(config);
|
|
5351
|
+
if (config.shouldEncodeToFormData && config.data) {
|
|
5352
|
+
const formData = new FormData();
|
|
5353
|
+
Object.keys(config.data).forEach((key) => formData.append(key, config.data[key]));
|
|
5354
|
+
config.data = formData;
|
|
5355
|
+
}
|
|
5356
|
+
config.startTimeInMs = Date.now();
|
|
5357
|
+
if (this.isHandlerEnabled && typeof this.requestStartCallback === "function") {
|
|
5358
|
+
this.requestStartCallback(config);
|
|
5359
|
+
}
|
|
5360
|
+
return config;
|
|
5361
|
+
}
|
|
5362
|
+
successHandler(response) {
|
|
5363
|
+
if (this.isHandlerEnabled) {
|
|
5364
|
+
if (typeof this.requestSuccessCallback === "function") {
|
|
5365
|
+
this.requestSuccessCallback(response);
|
|
5366
|
+
}
|
|
5367
|
+
if (typeof this.requestFinishCallback === "function") {
|
|
5368
|
+
this.requestFinishCallback();
|
|
5369
|
+
}
|
|
5370
|
+
}
|
|
5371
|
+
return response;
|
|
5372
|
+
}
|
|
5373
|
+
errorHandler(error2) {
|
|
5374
|
+
if (this.isHandlerEnabled) {
|
|
5375
|
+
if (typeof this.requestErrorCallback === "function") {
|
|
5376
|
+
this.requestErrorCallback(error2);
|
|
5377
|
+
}
|
|
5378
|
+
if (typeof this.requestFinishCallback === "function") {
|
|
5379
|
+
this.requestFinishCallback();
|
|
5380
|
+
}
|
|
5381
|
+
}
|
|
5382
|
+
}
|
|
5383
|
+
};
|
|
5384
|
+
__publicField(_HttpClient, "DEFAULT_HANDLER_DISABLE_TIMEOUT", 1e3);
|
|
5385
|
+
var HttpClient = _HttpClient;
|
|
5289
5386
|
export {
|
|
5290
5387
|
AgentConfig,
|
|
5291
5388
|
ApplicationNativeAuthenticationConstants_default as ApplicationNativeAuthenticationConstants,
|
|
@@ -5318,6 +5415,7 @@ export {
|
|
|
5318
5415
|
FieldType,
|
|
5319
5416
|
FlowMetaType,
|
|
5320
5417
|
FlowMode,
|
|
5418
|
+
HttpClient,
|
|
5321
5419
|
IsomorphicCrypto,
|
|
5322
5420
|
OIDCRequestConstants_default as OIDCRequestConstants,
|
|
5323
5421
|
Platform,
|