@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
120 lines (116 loc) • 3.52 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 2.0.0
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
'use strict';
const abstractB24 = require('../core/abstract-b24.cjs');
const v2 = require('../core/http/v2.cjs');
const v3 = require('../core/http/v3.cjs');
const auth = require('./auth.cjs');
const versionManager = require('../core/version-manager.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class B24OAuth extends abstractB24.AbstractB24 {
static {
__name(this, "B24OAuth");
}
#authOAuthManager;
// region Init ////
constructor(authOptions, oAuthSecret, options) {
super();
this.#authOAuthManager = new auth.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 v2.HttpV2(this.#authOAuthManager, this._getHttpOptions(), options?.restrictionParams);
this._httpV2.setClientSideWarning(true, warningText);
this._httpV3 = new v3.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.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.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 ////
}
exports.B24OAuth = B24OAuth;
//# sourceMappingURL=b24.cjs.map