@bitrix24/b24jssdk 0.4.0 → 0.4.2
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/esm/index.d.mts +110 -1
- package/dist/esm/index.d.ts +110 -1
- package/dist/esm/index.mjs +174 -100
- package/dist/esm/index.mjs.map +1 -1
- package/dist/umd/index.js +173 -71
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.min.js +16 -16
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
package/dist/umd/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @version @bitrix24/b24jssdk v0.4.
|
|
2
|
+
* @version @bitrix24/b24jssdk v0.4.2
|
|
3
3
|
* @copyright (c) 2025 Bitrix24
|
|
4
4
|
* @licence MIT
|
|
5
5
|
* @links https://github.com/bitrix24/b24jssdk - GitHub
|
|
@@ -8538,80 +8538,44 @@
|
|
|
8538
8538
|
}
|
|
8539
8539
|
}
|
|
8540
8540
|
|
|
8541
|
-
const _state = {};
|
|
8542
|
-
function initRng() {
|
|
8543
|
-
const crypto = window.crypto || window.msCrypto;
|
|
8544
|
-
if (!crypto?.getRandomValues) {
|
|
8545
|
-
throw new Error("Web Crypto API not available");
|
|
8546
|
-
}
|
|
8547
|
-
return {
|
|
8548
|
-
rng: () => {
|
|
8549
|
-
const rnds8 = new Uint8Array(16);
|
|
8550
|
-
return crypto.getRandomValues(rnds8);
|
|
8551
|
-
}
|
|
8552
|
-
};
|
|
8553
|
-
}
|
|
8554
8541
|
const byteToHex = [];
|
|
8555
8542
|
for (let i = 0; i < 256; ++i) {
|
|
8556
8543
|
byteToHex.push((i + 256).toString(16).slice(1));
|
|
8557
8544
|
}
|
|
8558
|
-
function
|
|
8559
|
-
|
|
8560
|
-
|
|
8561
|
-
|
|
8562
|
-
|
|
8563
|
-
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
}
|
|
8572
|
-
function v7Bytes(randoms, msecs, seq, buf, offset = 0) {
|
|
8573
|
-
if (!buf) {
|
|
8574
|
-
buf = new Uint8Array(16);
|
|
8575
|
-
offset = 0;
|
|
8576
|
-
}
|
|
8577
|
-
msecs ??= Date.now();
|
|
8578
|
-
seq ??= randoms[6] * 127 << 24 | randoms[7] << 16 | randoms[8] << 8 | randoms[9];
|
|
8579
|
-
buf[offset++] = msecs / 1099511627776 & 255;
|
|
8580
|
-
buf[offset++] = msecs / 4294967296 & 255;
|
|
8581
|
-
buf[offset++] = msecs / 16777216 & 255;
|
|
8582
|
-
buf[offset++] = msecs / 65536 & 255;
|
|
8583
|
-
buf[offset++] = msecs / 256 & 255;
|
|
8584
|
-
buf[offset++] = msecs & 255;
|
|
8585
|
-
buf[offset++] = 112 | seq >>> 28 & 15;
|
|
8586
|
-
buf[offset++] = seq >>> 20 & 255;
|
|
8587
|
-
buf[offset++] = 128 | seq >>> 14 & 63;
|
|
8588
|
-
buf[offset++] = seq >>> 6 & 255;
|
|
8589
|
-
buf[offset++] = seq << 2 & 255 | randoms[10] & 3;
|
|
8590
|
-
buf[offset++] = randoms[11];
|
|
8591
|
-
buf[offset++] = randoms[12];
|
|
8592
|
-
buf[offset++] = randoms[13];
|
|
8593
|
-
buf[offset++] = randoms[14];
|
|
8594
|
-
buf[offset++] = randoms[15];
|
|
8595
|
-
return buf;
|
|
8596
|
-
}
|
|
8597
|
-
function unsafeStringify(arr, offset = 0) {
|
|
8598
|
-
return (byteToHex[arr[offset]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
8545
|
+
function sfc32(a, b, c, d) {
|
|
8546
|
+
return () => {
|
|
8547
|
+
a |= 0;
|
|
8548
|
+
b |= 0;
|
|
8549
|
+
c |= 0;
|
|
8550
|
+
d |= 0;
|
|
8551
|
+
const t = (a + b | 0) + d | 0;
|
|
8552
|
+
d = d + 1 | 0;
|
|
8553
|
+
a = b ^ b >>> 9;
|
|
8554
|
+
b = c + (c << 3) | 0;
|
|
8555
|
+
c = (c << 21 | c >>> 11) + t | 0;
|
|
8556
|
+
return t >>> 0;
|
|
8557
|
+
};
|
|
8599
8558
|
}
|
|
8600
8559
|
function uuidv7() {
|
|
8601
|
-
const
|
|
8602
|
-
const
|
|
8603
|
-
const
|
|
8604
|
-
const
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
);
|
|
8614
|
-
|
|
8560
|
+
const bytes = new Uint8Array(16);
|
|
8561
|
+
const timestamp = BigInt(Date.now());
|
|
8562
|
+
const perf = BigInt(Math.floor(performance.now() * 1e3) % 65535);
|
|
8563
|
+
const combinedTime = timestamp << 16n | perf;
|
|
8564
|
+
bytes[0] = Number(combinedTime >> 40n & 0xffn);
|
|
8565
|
+
bytes[1] = Number(combinedTime >> 32n & 0xffn);
|
|
8566
|
+
bytes[2] = Number(combinedTime >> 24n & 0xffn);
|
|
8567
|
+
bytes[3] = Number(combinedTime >> 16n & 0xffn);
|
|
8568
|
+
bytes[4] = Number(combinedTime >> 8n & 0xffn);
|
|
8569
|
+
bytes[5] = Number(combinedTime & 0xffn);
|
|
8570
|
+
const seed = (Math.random() * 4294967295 ^ Date.now() ^ performance.now()) >>> 0;
|
|
8571
|
+
const rand = sfc32(2654435769, 608135816, 3084996962, seed);
|
|
8572
|
+
const randView = new DataView(bytes.buffer);
|
|
8573
|
+
randView.setUint32(6, rand());
|
|
8574
|
+
randView.setUint32(10, rand());
|
|
8575
|
+
randView.setUint16(14, rand());
|
|
8576
|
+
bytes[6] = 112 | bytes[6] & 15;
|
|
8577
|
+
bytes[8] = 128 | bytes[8] & 63;
|
|
8578
|
+
return (byteToHex[bytes[0]] + byteToHex[bytes[1]] + byteToHex[bytes[2]] + byteToHex[bytes[3]] + "-" + byteToHex[bytes[4]] + byteToHex[bytes[5]] + "-" + byteToHex[bytes[6]] + byteToHex[bytes[7]] + "-" + byteToHex[bytes[8]] + byteToHex[bytes[9]] + "-" + byteToHex[bytes[10]] + byteToHex[bytes[11]] + byteToHex[bytes[12]] + byteToHex[bytes[13]] + byteToHex[bytes[14]] + byteToHex[bytes[15]]).toLowerCase();
|
|
8615
8579
|
}
|
|
8616
8580
|
|
|
8617
8581
|
const reEscape = /[&<>'"]/g;
|
|
@@ -14090,7 +14054,7 @@ ${this.stack}`;
|
|
|
14090
14054
|
#clientSideWarningMessage = "";
|
|
14091
14055
|
constructor(baseURL, authActions, options) {
|
|
14092
14056
|
const defaultHeaders = {
|
|
14093
|
-
// 'X-Sdk': 'b24-js-sdk-v-0.4.
|
|
14057
|
+
// 'X-Sdk': 'b24-js-sdk-v-0.4.2'
|
|
14094
14058
|
};
|
|
14095
14059
|
this.#clientAxios = axios.create({
|
|
14096
14060
|
baseURL,
|
|
@@ -14518,7 +14482,7 @@ ${this.stack}`;
|
|
|
14518
14482
|
const baseUrl = `${encodeURIComponent(method)}.json`;
|
|
14519
14483
|
const queryParams = new URLSearchParams({
|
|
14520
14484
|
[this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
|
|
14521
|
-
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.
|
|
14485
|
+
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.2",
|
|
14522
14486
|
[this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
|
|
14523
14487
|
});
|
|
14524
14488
|
return `${baseUrl}?${queryParams.toString()}`;
|
|
@@ -16734,6 +16698,142 @@ ${this.stack}`;
|
|
|
16734
16698
|
// endregion ////
|
|
16735
16699
|
}
|
|
16736
16700
|
|
|
16701
|
+
class AuthOAuthManager {
|
|
16702
|
+
#authOptions;
|
|
16703
|
+
#oAuthSecret;
|
|
16704
|
+
#authExpires = 0;
|
|
16705
|
+
#domain;
|
|
16706
|
+
#b24Target;
|
|
16707
|
+
#b24TargetRest;
|
|
16708
|
+
// 'https://oauth.bitrix.info' ////
|
|
16709
|
+
#oAuthTarget;
|
|
16710
|
+
#isAdmin = null;
|
|
16711
|
+
constructor(b24OAuthParams, oAuthSecret) {
|
|
16712
|
+
this.#authOptions = Object.assign({}, b24OAuthParams);
|
|
16713
|
+
this.#oAuthSecret = Object.freeze(Object.assign({}, oAuthSecret));
|
|
16714
|
+
this.#domain = this.#authOptions.domain.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
16715
|
+
this.#b24TargetRest = this.#authOptions.clientEndpoint;
|
|
16716
|
+
this.#b24Target = this.#b24TargetRest.replace("/rest", "");
|
|
16717
|
+
this.#oAuthTarget = this.#authOptions.serverEndpoint.replace("/rest/", "");
|
|
16718
|
+
this.#authExpires = this.#authOptions.expires * 1e3;
|
|
16719
|
+
}
|
|
16720
|
+
/**
|
|
16721
|
+
* Returns authorization data
|
|
16722
|
+
* @see Http.#prepareParams
|
|
16723
|
+
*/
|
|
16724
|
+
getAuthData() {
|
|
16725
|
+
return this.#authExpires > Date.now() ? {
|
|
16726
|
+
access_token: this.#authOptions.accessToken,
|
|
16727
|
+
refresh_token: this.#authOptions.refreshToken,
|
|
16728
|
+
expires_in: this.#authOptions.expiresIn,
|
|
16729
|
+
domain: this.#domain,
|
|
16730
|
+
member_id: this.#authOptions.memberId
|
|
16731
|
+
} : false;
|
|
16732
|
+
}
|
|
16733
|
+
/**
|
|
16734
|
+
* Updates authorization data
|
|
16735
|
+
*/
|
|
16736
|
+
async refreshAuth() {
|
|
16737
|
+
try {
|
|
16738
|
+
const response = await fetch(`${this.#oAuthTarget}/oauth/token/`, {
|
|
16739
|
+
method: "POST",
|
|
16740
|
+
headers: {
|
|
16741
|
+
"Content-Type": "application/json"
|
|
16742
|
+
},
|
|
16743
|
+
body: JSON.stringify({
|
|
16744
|
+
params: {
|
|
16745
|
+
client_id: this.#oAuthSecret.clientId,
|
|
16746
|
+
grant_type: "refresh_token",
|
|
16747
|
+
client_secret: this.#oAuthSecret.clientSecret,
|
|
16748
|
+
refresh_token: this.#authOptions.refreshToken
|
|
16749
|
+
}
|
|
16750
|
+
})
|
|
16751
|
+
});
|
|
16752
|
+
if (!response.ok) {
|
|
16753
|
+
throw new Error(`Token update error: ${response.statusText}`);
|
|
16754
|
+
}
|
|
16755
|
+
const data = await response.json();
|
|
16756
|
+
if (data.error) {
|
|
16757
|
+
throw new Error(`Token update error: ${data.error}`);
|
|
16758
|
+
}
|
|
16759
|
+
this.#authOptions.accessToken = data.access_token;
|
|
16760
|
+
this.#authOptions.refreshToken = data.refresh_token;
|
|
16761
|
+
this.#authExpires = data.expires * 1e3;
|
|
16762
|
+
} catch (error) {
|
|
16763
|
+
throw new Error(`Token update error: ${error instanceof Error ? error.message : error}`);
|
|
16764
|
+
}
|
|
16765
|
+
return this.getAuthData();
|
|
16766
|
+
}
|
|
16767
|
+
getUniq(prefix) {
|
|
16768
|
+
return [prefix, this.#authOptions.memberId || ""].join("_");
|
|
16769
|
+
}
|
|
16770
|
+
/**
|
|
16771
|
+
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
16772
|
+
*/
|
|
16773
|
+
getTargetOrigin() {
|
|
16774
|
+
return `${this.#b24Target}`;
|
|
16775
|
+
}
|
|
16776
|
+
/**
|
|
16777
|
+
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest )
|
|
16778
|
+
*/
|
|
16779
|
+
getTargetOriginWithPath() {
|
|
16780
|
+
return `${this.#b24TargetRest}`;
|
|
16781
|
+
}
|
|
16782
|
+
/**
|
|
16783
|
+
* Determines whether the current user has administrator rights
|
|
16784
|
+
*/
|
|
16785
|
+
get isAdmin() {
|
|
16786
|
+
if (null === this.#isAdmin) {
|
|
16787
|
+
throw new Error("isAdmin not init. You need call B24OAuth::initIsAdmin().");
|
|
16788
|
+
}
|
|
16789
|
+
return this.#isAdmin;
|
|
16790
|
+
}
|
|
16791
|
+
async initIsAdmin(http) {
|
|
16792
|
+
const response = await http.call("profile", {}, 0);
|
|
16793
|
+
if (!response.isSuccess) {
|
|
16794
|
+
throw new Error(response.getErrorMessages().join(";"));
|
|
16795
|
+
}
|
|
16796
|
+
const data = response.getData().result;
|
|
16797
|
+
if (data?.ADMIN) {
|
|
16798
|
+
this.#isAdmin = true;
|
|
16799
|
+
}
|
|
16800
|
+
}
|
|
16801
|
+
}
|
|
16802
|
+
|
|
16803
|
+
class B24OAuth extends AbstractB24 {
|
|
16804
|
+
#authOAuthManager;
|
|
16805
|
+
constructor(authOptions, oAuthSecret) {
|
|
16806
|
+
super();
|
|
16807
|
+
this.#authOAuthManager = new AuthOAuthManager(authOptions, oAuthSecret);
|
|
16808
|
+
this._http = new Http(
|
|
16809
|
+
this.#authOAuthManager.getTargetOriginWithPath(),
|
|
16810
|
+
this.#authOAuthManager,
|
|
16811
|
+
this._getHttpOptions()
|
|
16812
|
+
);
|
|
16813
|
+
this._isInit = true;
|
|
16814
|
+
}
|
|
16815
|
+
async initIsAdmin() {
|
|
16816
|
+
if (!this._http) {
|
|
16817
|
+
throw new Error("Http Not init");
|
|
16818
|
+
}
|
|
16819
|
+
return this.#authOAuthManager.initIsAdmin(this._http);
|
|
16820
|
+
}
|
|
16821
|
+
setLogger(logger) {
|
|
16822
|
+
super.setLogger(logger);
|
|
16823
|
+
}
|
|
16824
|
+
get auth() {
|
|
16825
|
+
return this.#authOAuthManager;
|
|
16826
|
+
}
|
|
16827
|
+
getTargetOrigin() {
|
|
16828
|
+
this._ensureInitialized();
|
|
16829
|
+
return this.#authOAuthManager.getTargetOrigin();
|
|
16830
|
+
}
|
|
16831
|
+
getTargetOriginWithPath() {
|
|
16832
|
+
this._ensureInitialized();
|
|
16833
|
+
return this.#authOAuthManager.getTargetOriginWithPath();
|
|
16834
|
+
}
|
|
16835
|
+
}
|
|
16836
|
+
|
|
16737
16837
|
class UnhandledMatchError extends Error {
|
|
16738
16838
|
constructor(value, ...args) {
|
|
16739
16839
|
super(...args);
|
|
@@ -26204,9 +26304,11 @@ Data string: ${pullEvent}
|
|
|
26204
26304
|
exports.AppFrame = AppFrame;
|
|
26205
26305
|
exports.AuthHookManager = AuthHookManager;
|
|
26206
26306
|
exports.AuthManager = AuthManager;
|
|
26307
|
+
exports.AuthOAuthManager = AuthOAuthManager;
|
|
26207
26308
|
exports.B24Frame = B24Frame;
|
|
26208
26309
|
exports.B24Hook = B24Hook;
|
|
26209
26310
|
exports.B24LangList = B24LangList;
|
|
26311
|
+
exports.B24OAuth = B24OAuth;
|
|
26210
26312
|
exports.B24PullClientManager = PullClient;
|
|
26211
26313
|
exports.Browser = Browser;
|
|
26212
26314
|
exports.CatalogProductImageType = CatalogProductImageType;
|