glitch-javascript-sdk 1.8.2 → 1.8.4
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 +50 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Titles.d.ts +10 -0
- package/dist/esm/index.js +50 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/package.json +1 -1
- package/src/api/Titles.ts +21 -0
- package/src/routes/TitlesRoute.ts +5 -0
- package/src/util/Session.ts +45 -22
package/dist/esm/api/Titles.d.ts
CHANGED
|
@@ -253,6 +253,16 @@ declare class Titles {
|
|
|
253
253
|
* @returns AxiosPromise
|
|
254
254
|
*/
|
|
255
255
|
static getUtmAnalytics<T>(title_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
256
|
+
/**
|
|
257
|
+
* Get the web tracking token used for websites.
|
|
258
|
+
*
|
|
259
|
+
* GET /titles/{title_id}/webTrackingToken
|
|
260
|
+
*
|
|
261
|
+
* @param title_id The UUID of the title
|
|
262
|
+
* @param params Optional query params:
|
|
263
|
+
* @returns AxiosPromise
|
|
264
|
+
*/
|
|
265
|
+
static getWebTrackingToken<T>(title_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
256
266
|
/**
|
|
257
267
|
* Analyze UTM data with optional group_by (source, campaign, medium, device_type, etc.)
|
|
258
268
|
*
|
package/dist/esm/index.js
CHANGED
|
@@ -10164,6 +10164,10 @@ var TitlesRoute = /** @class */ (function () {
|
|
|
10164
10164
|
url: "/titles/{title_id}/utm",
|
|
10165
10165
|
method: HTTP_METHODS.GET,
|
|
10166
10166
|
},
|
|
10167
|
+
getWebTrackingToken: {
|
|
10168
|
+
url: "/titles/{title_id}/webTrackingToken",
|
|
10169
|
+
method: HTTP_METHODS.GET,
|
|
10170
|
+
},
|
|
10167
10171
|
/**
|
|
10168
10172
|
* 3) Analyze UTM data with optional group_by / dimension-based aggregates
|
|
10169
10173
|
* GET /titles/{title_id}/utm/analysis
|
|
@@ -10503,6 +10507,18 @@ var Titles = /** @class */ (function () {
|
|
|
10503
10507
|
Titles.getUtmAnalytics = function (title_id, params) {
|
|
10504
10508
|
return Requests.processRoute(TitlesRoute.routes.getUtmAnalytics, {}, { title_id: title_id }, params);
|
|
10505
10509
|
};
|
|
10510
|
+
/**
|
|
10511
|
+
* Get the web tracking token used for websites.
|
|
10512
|
+
*
|
|
10513
|
+
* GET /titles/{title_id}/webTrackingToken
|
|
10514
|
+
*
|
|
10515
|
+
* @param title_id The UUID of the title
|
|
10516
|
+
* @param params Optional query params:
|
|
10517
|
+
* @returns AxiosPromise
|
|
10518
|
+
*/
|
|
10519
|
+
Titles.getWebTrackingToken = function (title_id, params) {
|
|
10520
|
+
return Requests.processRoute(TitlesRoute.routes.getWebTrackingToken, {}, { title_id: title_id }, params);
|
|
10521
|
+
};
|
|
10506
10522
|
/**
|
|
10507
10523
|
* Analyze UTM data with optional group_by (source, campaign, medium, device_type, etc.)
|
|
10508
10524
|
*
|
|
@@ -13298,9 +13314,10 @@ var Parser = /** @class */ (function () {
|
|
|
13298
13314
|
// Browser implementation using crypto-js
|
|
13299
13315
|
var BrowserCrypto = /** @class */ (function () {
|
|
13300
13316
|
function BrowserCrypto() {
|
|
13317
|
+
this.CryptoJS = require('crypto-js');
|
|
13301
13318
|
}
|
|
13302
13319
|
BrowserCrypto.prototype.createHmac = function (algorithm, secret) {
|
|
13303
|
-
var
|
|
13320
|
+
var _this = this;
|
|
13304
13321
|
var data = '';
|
|
13305
13322
|
var hmac = {
|
|
13306
13323
|
update: function (updateData) {
|
|
@@ -13311,38 +13328,58 @@ var BrowserCrypto = /** @class */ (function () {
|
|
|
13311
13328
|
if (encoding !== 'hex') {
|
|
13312
13329
|
throw new Error('Only hex encoding is supported in browser implementation');
|
|
13313
13330
|
}
|
|
13314
|
-
return CryptoJS.HmacSHA256(data, secret).toString(CryptoJS.enc.Hex);
|
|
13331
|
+
return _this.CryptoJS.HmacSHA256(data, secret).toString(_this.CryptoJS.enc.Hex);
|
|
13315
13332
|
}
|
|
13316
13333
|
};
|
|
13317
13334
|
return hmac;
|
|
13318
13335
|
};
|
|
13319
13336
|
return BrowserCrypto;
|
|
13320
13337
|
}());
|
|
13321
|
-
// Node.js implementation
|
|
13338
|
+
// Node.js implementation that maintains sync interface
|
|
13322
13339
|
var NodeCrypto = /** @class */ (function () {
|
|
13323
13340
|
function NodeCrypto() {
|
|
13324
|
-
|
|
13341
|
+
// Use dynamic import but handle it synchronously for interface compliance
|
|
13342
|
+
try {
|
|
13343
|
+
// This will throw in browser environments
|
|
13344
|
+
this.crypto = require('crypto');
|
|
13345
|
+
}
|
|
13346
|
+
catch (e) {
|
|
13347
|
+
this.crypto = undefined;
|
|
13348
|
+
}
|
|
13325
13349
|
}
|
|
13326
13350
|
NodeCrypto.prototype.createHmac = function (algorithm, secret) {
|
|
13351
|
+
if (!this.crypto) {
|
|
13352
|
+
throw new Error('Node.js crypto module not available');
|
|
13353
|
+
}
|
|
13327
13354
|
return this.crypto.createHmac(algorithm, secret);
|
|
13328
13355
|
};
|
|
13329
13356
|
return NodeCrypto;
|
|
13330
13357
|
}());
|
|
13331
13358
|
// Determine which crypto implementation to use
|
|
13332
13359
|
var getCrypto = function () {
|
|
13360
|
+
var _a;
|
|
13333
13361
|
try {
|
|
13334
|
-
// Check if we're in Node.js environment
|
|
13335
|
-
if (typeof process !== 'undefined' && process.versions
|
|
13336
|
-
|
|
13362
|
+
// Check if we're in Node.js environment and crypto is available
|
|
13363
|
+
if (typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
13364
|
+
var nodeCrypto = new NodeCrypto();
|
|
13365
|
+
// Verify crypto was actually loaded
|
|
13366
|
+
try {
|
|
13367
|
+
nodeCrypto.createHmac('sha256', 'test');
|
|
13368
|
+
return nodeCrypto;
|
|
13369
|
+
}
|
|
13370
|
+
catch (e) {
|
|
13371
|
+
console.warn('Node.js crypto not available, falling back to browser implementation');
|
|
13372
|
+
}
|
|
13337
13373
|
}
|
|
13338
|
-
// Fall back to browser implementation
|
|
13339
|
-
return new BrowserCrypto();
|
|
13340
13374
|
}
|
|
13341
13375
|
catch (e) {
|
|
13342
|
-
|
|
13376
|
+
console.warn('Node.js environment detection failed, falling back to browser implementation');
|
|
13343
13377
|
}
|
|
13378
|
+
// Fall back to browser implementation
|
|
13379
|
+
return new BrowserCrypto();
|
|
13344
13380
|
};
|
|
13345
|
-
|
|
13381
|
+
// Singleton crypto instance
|
|
13382
|
+
var cryptoInstance = getCrypto();
|
|
13346
13383
|
var Session = /** @class */ (function () {
|
|
13347
13384
|
function Session() {
|
|
13348
13385
|
}
|
|
@@ -13367,10 +13404,7 @@ var Session = /** @class */ (function () {
|
|
|
13367
13404
|
};
|
|
13368
13405
|
Session.hasJoinedCommunity = function () {
|
|
13369
13406
|
var community = Storage.get('community');
|
|
13370
|
-
|
|
13371
|
-
return false;
|
|
13372
|
-
}
|
|
13373
|
-
return (community === null || community === void 0 ? void 0 : community.me) ? true : false;
|
|
13407
|
+
return !!(community === null || community === void 0 ? void 0 : community.me);
|
|
13374
13408
|
};
|
|
13375
13409
|
Session.end = function () {
|
|
13376
13410
|
Storage.setAuthToken(null);
|
|
@@ -13404,7 +13438,7 @@ var Session = /** @class */ (function () {
|
|
|
13404
13438
|
if (!secret) {
|
|
13405
13439
|
throw new Error('secret is required');
|
|
13406
13440
|
}
|
|
13407
|
-
return
|
|
13441
|
+
return cryptoInstance
|
|
13408
13442
|
.createHmac('sha256', secret)
|
|
13409
13443
|
.update(titleId)
|
|
13410
13444
|
.digest('hex');
|