glitch-javascript-sdk 1.8.2 → 1.8.3
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/cjs/index.js +34 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +34 -16
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/util/Session.ts +45 -22
package/dist/cjs/index.js
CHANGED
|
@@ -26482,9 +26482,10 @@ var Parser = /** @class */ (function () {
|
|
|
26482
26482
|
// Browser implementation using crypto-js
|
|
26483
26483
|
var BrowserCrypto = /** @class */ (function () {
|
|
26484
26484
|
function BrowserCrypto() {
|
|
26485
|
+
this.CryptoJS = require('crypto-js');
|
|
26485
26486
|
}
|
|
26486
26487
|
BrowserCrypto.prototype.createHmac = function (algorithm, secret) {
|
|
26487
|
-
var
|
|
26488
|
+
var _this = this;
|
|
26488
26489
|
var data = '';
|
|
26489
26490
|
var hmac = {
|
|
26490
26491
|
update: function (updateData) {
|
|
@@ -26495,38 +26496,58 @@ var BrowserCrypto = /** @class */ (function () {
|
|
|
26495
26496
|
if (encoding !== 'hex') {
|
|
26496
26497
|
throw new Error('Only hex encoding is supported in browser implementation');
|
|
26497
26498
|
}
|
|
26498
|
-
return CryptoJS.HmacSHA256(data, secret).toString(CryptoJS.enc.Hex);
|
|
26499
|
+
return _this.CryptoJS.HmacSHA256(data, secret).toString(_this.CryptoJS.enc.Hex);
|
|
26499
26500
|
}
|
|
26500
26501
|
};
|
|
26501
26502
|
return hmac;
|
|
26502
26503
|
};
|
|
26503
26504
|
return BrowserCrypto;
|
|
26504
26505
|
}());
|
|
26505
|
-
// Node.js implementation
|
|
26506
|
+
// Node.js implementation that maintains sync interface
|
|
26506
26507
|
var NodeCrypto = /** @class */ (function () {
|
|
26507
26508
|
function NodeCrypto() {
|
|
26508
|
-
|
|
26509
|
+
// Use dynamic import but handle it synchronously for interface compliance
|
|
26510
|
+
try {
|
|
26511
|
+
// This will throw in browser environments
|
|
26512
|
+
this.crypto = require('crypto');
|
|
26513
|
+
}
|
|
26514
|
+
catch (e) {
|
|
26515
|
+
this.crypto = undefined;
|
|
26516
|
+
}
|
|
26509
26517
|
}
|
|
26510
26518
|
NodeCrypto.prototype.createHmac = function (algorithm, secret) {
|
|
26519
|
+
if (!this.crypto) {
|
|
26520
|
+
throw new Error('Node.js crypto module not available');
|
|
26521
|
+
}
|
|
26511
26522
|
return this.crypto.createHmac(algorithm, secret);
|
|
26512
26523
|
};
|
|
26513
26524
|
return NodeCrypto;
|
|
26514
26525
|
}());
|
|
26515
26526
|
// Determine which crypto implementation to use
|
|
26516
26527
|
var getCrypto = function () {
|
|
26528
|
+
var _a;
|
|
26517
26529
|
try {
|
|
26518
|
-
// Check if we're in Node.js environment
|
|
26519
|
-
if (typeof process !== 'undefined' && process.versions
|
|
26520
|
-
|
|
26530
|
+
// Check if we're in Node.js environment and crypto is available
|
|
26531
|
+
if (typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
26532
|
+
var nodeCrypto = new NodeCrypto();
|
|
26533
|
+
// Verify crypto was actually loaded
|
|
26534
|
+
try {
|
|
26535
|
+
nodeCrypto.createHmac('sha256', 'test');
|
|
26536
|
+
return nodeCrypto;
|
|
26537
|
+
}
|
|
26538
|
+
catch (e) {
|
|
26539
|
+
console.warn('Node.js crypto not available, falling back to browser implementation');
|
|
26540
|
+
}
|
|
26521
26541
|
}
|
|
26522
|
-
// Fall back to browser implementation
|
|
26523
|
-
return new BrowserCrypto();
|
|
26524
26542
|
}
|
|
26525
26543
|
catch (e) {
|
|
26526
|
-
|
|
26544
|
+
console.warn('Node.js environment detection failed, falling back to browser implementation');
|
|
26527
26545
|
}
|
|
26546
|
+
// Fall back to browser implementation
|
|
26547
|
+
return new BrowserCrypto();
|
|
26528
26548
|
};
|
|
26529
|
-
|
|
26549
|
+
// Singleton crypto instance
|
|
26550
|
+
var cryptoInstance = getCrypto();
|
|
26530
26551
|
var Session = /** @class */ (function () {
|
|
26531
26552
|
function Session() {
|
|
26532
26553
|
}
|
|
@@ -26551,10 +26572,7 @@ var Session = /** @class */ (function () {
|
|
|
26551
26572
|
};
|
|
26552
26573
|
Session.hasJoinedCommunity = function () {
|
|
26553
26574
|
var community = Storage.get('community');
|
|
26554
|
-
|
|
26555
|
-
return false;
|
|
26556
|
-
}
|
|
26557
|
-
return (community === null || community === void 0 ? void 0 : community.me) ? true : false;
|
|
26575
|
+
return !!(community === null || community === void 0 ? void 0 : community.me);
|
|
26558
26576
|
};
|
|
26559
26577
|
Session.end = function () {
|
|
26560
26578
|
Storage.setAuthToken(null);
|
|
@@ -26588,7 +26606,7 @@ var Session = /** @class */ (function () {
|
|
|
26588
26606
|
if (!secret) {
|
|
26589
26607
|
throw new Error('secret is required');
|
|
26590
26608
|
}
|
|
26591
|
-
return
|
|
26609
|
+
return cryptoInstance
|
|
26592
26610
|
.createHmac('sha256', secret)
|
|
26593
26611
|
.update(titleId)
|
|
26594
26612
|
.digest('hex');
|