@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
118 lines (115 loc) • 3.46 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 1.0.1
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
import { AbstractB24 } from '../core/abstract-b24.mjs';
import { HttpV2 } from '../core/http/v2.mjs';
import { HttpV3 } from '../core/http/v3.mjs';
import { AuthOAuthManager } from './auth.mjs';
import { versionManager } from '../core/version-manager.mjs';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class B24OAuth extends AbstractB24 {
static {
__name(this, "B24OAuth");
}
#authOAuthManager;
// region Init ////
constructor(authOptions, oAuthSecret, options) {
super();
this.#authOAuthManager = new AuthOAuthManager(
authOptions,
oAuthSecret
);
const warningText = "The B24OAuth object is intended exclusively for use on the server.\nA webhook contains a secret access key, which MUST NOT be used in client-side code (browser, mobile app).";
this._httpV2 = new HttpV2(this.#authOAuthManager, this._getHttpOptions(), options?.restrictionParams);
this._httpV2.setClientSideWarning(true, warningText);
this._httpV3 = new HttpV3(this.#authOAuthManager, this._getHttpOptions(), options?.restrictionParams);
this._httpV3.setClientSideWarning(true, warningText);
this._isInit = true;
}
/**
* Used to initialize information about the current user.
*
* @todo test this
*/
async initIsAdmin(requestId) {
const method = "profile";
this._ensureInitialized();
try {
const version = versionManager.automaticallyObtainApiVersion(method);
const client = this.getHttpClient(version);
return this.#authOAuthManager.initIsAdmin(client, requestId);
} catch {
return;
}
}
/**
* Sets an asynchronous Callback to receive updated authorization data
* @param cb
*/
setCallbackRefreshAuth(cb) {
this._ensureInitialized();
this.#authOAuthManager.setCallbackRefreshAuth(cb);
}
/**
* Removes Callback to receive updated authorization data
*/
removeCallbackRefreshAuth() {
this._ensureInitialized();
this.#authOAuthManager.removeCallbackRefreshAuth();
}
/**
* Sets an asynchronous function for custom get new refresh token
* @param cb
*/
setCustomRefreshAuth(cb) {
this._ensureInitialized();
this.#authOAuthManager.setCustomRefreshAuth(cb);
}
/**
* Removes function for custom get new refresh token
*/
removeCustomRefreshAuth() {
this._ensureInitialized();
this.#authOAuthManager.removeCustomRefreshAuth();
}
// endregion ////
// region Core ////
/**
* Disables warning about client-side query execution
*/
offClientSideWarning() {
versionManager.getAllApiVersions().forEach((version) => {
this.getHttpClient(version).setClientSideWarning(false, "");
});
}
// endregion ////
get auth() {
return this.#authOAuthManager;
}
// region Get ////
/**
* @inheritDoc
*/
getTargetOrigin() {
this._ensureInitialized();
return this.#authOAuthManager.getTargetOrigin();
}
/**
* @inheritDoc
*/
getTargetOriginWithPath() {
this._ensureInitialized();
return this.#authOAuthManager.getTargetOriginWithPath();
}
// endregion ////
// region Tools ////
// endregion ////
}
export { B24OAuth };
//# sourceMappingURL=b24.mjs.map