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/esm/index.js CHANGED
@@ -13298,9 +13298,10 @@ var Parser = /** @class */ (function () {
13298
13298
  // Browser implementation using crypto-js
13299
13299
  var BrowserCrypto = /** @class */ (function () {
13300
13300
  function BrowserCrypto() {
13301
+ this.CryptoJS = require('crypto-js');
13301
13302
  }
13302
13303
  BrowserCrypto.prototype.createHmac = function (algorithm, secret) {
13303
- var CryptoJS = require('crypto-js');
13304
+ var _this = this;
13304
13305
  var data = '';
13305
13306
  var hmac = {
13306
13307
  update: function (updateData) {
@@ -13311,38 +13312,58 @@ var BrowserCrypto = /** @class */ (function () {
13311
13312
  if (encoding !== 'hex') {
13312
13313
  throw new Error('Only hex encoding is supported in browser implementation');
13313
13314
  }
13314
- return CryptoJS.HmacSHA256(data, secret).toString(CryptoJS.enc.Hex);
13315
+ return _this.CryptoJS.HmacSHA256(data, secret).toString(_this.CryptoJS.enc.Hex);
13315
13316
  }
13316
13317
  };
13317
13318
  return hmac;
13318
13319
  };
13319
13320
  return BrowserCrypto;
13320
13321
  }());
13321
- // Node.js implementation using native crypto
13322
+ // Node.js implementation that maintains sync interface
13322
13323
  var NodeCrypto = /** @class */ (function () {
13323
13324
  function NodeCrypto() {
13324
- this.crypto = require('crypto');
13325
+ // Use dynamic import but handle it synchronously for interface compliance
13326
+ try {
13327
+ // This will throw in browser environments
13328
+ this.crypto = require('crypto');
13329
+ }
13330
+ catch (e) {
13331
+ this.crypto = undefined;
13332
+ }
13325
13333
  }
13326
13334
  NodeCrypto.prototype.createHmac = function (algorithm, secret) {
13335
+ if (!this.crypto) {
13336
+ throw new Error('Node.js crypto module not available');
13337
+ }
13327
13338
  return this.crypto.createHmac(algorithm, secret);
13328
13339
  };
13329
13340
  return NodeCrypto;
13330
13341
  }());
13331
13342
  // Determine which crypto implementation to use
13332
13343
  var getCrypto = function () {
13344
+ var _a;
13333
13345
  try {
13334
- // Check if we're in Node.js environment
13335
- if (typeof process !== 'undefined' && process.versions && process.versions.node) {
13336
- return new NodeCrypto();
13346
+ // Check if we're in Node.js environment and crypto is available
13347
+ if (typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
13348
+ var nodeCrypto = new NodeCrypto();
13349
+ // Verify crypto was actually loaded
13350
+ try {
13351
+ nodeCrypto.createHmac('sha256', 'test');
13352
+ return nodeCrypto;
13353
+ }
13354
+ catch (e) {
13355
+ console.warn('Node.js crypto not available, falling back to browser implementation');
13356
+ }
13337
13357
  }
13338
- // Fall back to browser implementation
13339
- return new BrowserCrypto();
13340
13358
  }
13341
13359
  catch (e) {
13342
- return new BrowserCrypto();
13360
+ console.warn('Node.js environment detection failed, falling back to browser implementation');
13343
13361
  }
13362
+ // Fall back to browser implementation
13363
+ return new BrowserCrypto();
13344
13364
  };
13345
- var crypto = getCrypto();
13365
+ // Singleton crypto instance
13366
+ var cryptoInstance = getCrypto();
13346
13367
  var Session = /** @class */ (function () {
13347
13368
  function Session() {
13348
13369
  }
@@ -13367,10 +13388,7 @@ var Session = /** @class */ (function () {
13367
13388
  };
13368
13389
  Session.hasJoinedCommunity = function () {
13369
13390
  var community = Storage.get('community');
13370
- if (!community) {
13371
- return false;
13372
- }
13373
- return (community === null || community === void 0 ? void 0 : community.me) ? true : false;
13391
+ return !!(community === null || community === void 0 ? void 0 : community.me);
13374
13392
  };
13375
13393
  Session.end = function () {
13376
13394
  Storage.setAuthToken(null);
@@ -13404,7 +13422,7 @@ var Session = /** @class */ (function () {
13404
13422
  if (!secret) {
13405
13423
  throw new Error('secret is required');
13406
13424
  }
13407
- return crypto
13425
+ return cryptoInstance
13408
13426
  .createHmac('sha256', secret)
13409
13427
  .update(titleId)
13410
13428
  .digest('hex');