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/index.d.ts
CHANGED
|
@@ -3293,6 +3293,16 @@ declare class Titles {
|
|
|
3293
3293
|
* @returns AxiosPromise
|
|
3294
3294
|
*/
|
|
3295
3295
|
static getUtmAnalytics<T>(title_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
3296
|
+
/**
|
|
3297
|
+
* Get the web tracking token used for websites.
|
|
3298
|
+
*
|
|
3299
|
+
* GET /titles/{title_id}/webTrackingToken
|
|
3300
|
+
*
|
|
3301
|
+
* @param title_id The UUID of the title
|
|
3302
|
+
* @param params Optional query params:
|
|
3303
|
+
* @returns AxiosPromise
|
|
3304
|
+
*/
|
|
3305
|
+
static getWebTrackingToken<T>(title_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
3296
3306
|
/**
|
|
3297
3307
|
* Analyze UTM data with optional group_by (source, campaign, medium, device_type, etc.)
|
|
3298
3308
|
*
|
package/package.json
CHANGED
package/src/api/Titles.ts
CHANGED
|
@@ -449,6 +449,27 @@ class Titles {
|
|
|
449
449
|
);
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
+
/**
|
|
453
|
+
* Get the web tracking token used for websites.
|
|
454
|
+
*
|
|
455
|
+
* GET /titles/{title_id}/webTrackingToken
|
|
456
|
+
*
|
|
457
|
+
* @param title_id The UUID of the title
|
|
458
|
+
* @param params Optional query params:
|
|
459
|
+
* @returns AxiosPromise
|
|
460
|
+
*/
|
|
461
|
+
public static getWebTrackingToken<T>(
|
|
462
|
+
title_id: string,
|
|
463
|
+
params?: Record<string, any>
|
|
464
|
+
): AxiosPromise<Response<T>> {
|
|
465
|
+
return Requests.processRoute(
|
|
466
|
+
TitlesRoute.routes.getWebTrackingToken,
|
|
467
|
+
{},
|
|
468
|
+
{ title_id },
|
|
469
|
+
params
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
452
473
|
/**
|
|
453
474
|
* Analyze UTM data with optional group_by (source, campaign, medium, device_type, etc.)
|
|
454
475
|
*
|
|
@@ -62,6 +62,11 @@ class TitlesRoute {
|
|
|
62
62
|
method: HTTP_METHODS.GET,
|
|
63
63
|
},
|
|
64
64
|
|
|
65
|
+
getWebTrackingToken: {
|
|
66
|
+
url: "/titles/{title_id}/webTrackingToken",
|
|
67
|
+
method: HTTP_METHODS.GET,
|
|
68
|
+
},
|
|
69
|
+
|
|
65
70
|
/**
|
|
66
71
|
* 3) Analyze UTM data with optional group_by / dimension-based aggregates
|
|
67
72
|
* GET /titles/{title_id}/utm/analysis
|
package/src/util/Session.ts
CHANGED
|
@@ -13,9 +13,13 @@ interface CryptoInterface {
|
|
|
13
13
|
|
|
14
14
|
// Browser implementation using crypto-js
|
|
15
15
|
class BrowserCrypto implements CryptoInterface {
|
|
16
|
+
private CryptoJS: any;
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
this.CryptoJS = require('crypto-js');
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
createHmac(algorithm: string, secret: string): HmacInterface {
|
|
17
|
-
const CryptoJS = require('crypto-js');
|
|
18
|
-
|
|
19
23
|
let data = '';
|
|
20
24
|
|
|
21
25
|
const hmac: HmacInterface = {
|
|
@@ -27,7 +31,7 @@ class BrowserCrypto implements CryptoInterface {
|
|
|
27
31
|
if (encoding !== 'hex') {
|
|
28
32
|
throw new Error('Only hex encoding is supported in browser implementation');
|
|
29
33
|
}
|
|
30
|
-
return CryptoJS.HmacSHA256(data, secret).toString(CryptoJS.enc.Hex);
|
|
34
|
+
return this.CryptoJS.HmacSHA256(data, secret).toString(this.CryptoJS.enc.Hex);
|
|
31
35
|
}
|
|
32
36
|
};
|
|
33
37
|
|
|
@@ -35,15 +39,24 @@ class BrowserCrypto implements CryptoInterface {
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
// Node.js implementation
|
|
42
|
+
// Node.js implementation that maintains sync interface
|
|
39
43
|
class NodeCrypto implements CryptoInterface {
|
|
40
|
-
private crypto
|
|
44
|
+
private crypto?: typeof import('crypto');
|
|
41
45
|
|
|
42
46
|
constructor() {
|
|
43
|
-
|
|
47
|
+
// Use dynamic import but handle it synchronously for interface compliance
|
|
48
|
+
try {
|
|
49
|
+
// This will throw in browser environments
|
|
50
|
+
this.crypto = require('crypto');
|
|
51
|
+
} catch (e) {
|
|
52
|
+
this.crypto = undefined;
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
createHmac(algorithm: string, secret: string): HmacInterface {
|
|
57
|
+
if (!this.crypto) {
|
|
58
|
+
throw new Error('Node.js crypto module not available');
|
|
59
|
+
}
|
|
47
60
|
return this.crypto.createHmac(algorithm, secret);
|
|
48
61
|
}
|
|
49
62
|
}
|
|
@@ -51,18 +64,26 @@ class NodeCrypto implements CryptoInterface {
|
|
|
51
64
|
// Determine which crypto implementation to use
|
|
52
65
|
const getCrypto = (): CryptoInterface => {
|
|
53
66
|
try {
|
|
54
|
-
// Check if we're in Node.js environment
|
|
55
|
-
if (typeof process !== 'undefined' && process.versions
|
|
56
|
-
|
|
67
|
+
// Check if we're in Node.js environment and crypto is available
|
|
68
|
+
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
69
|
+
const nodeCrypto = new NodeCrypto();
|
|
70
|
+
// Verify crypto was actually loaded
|
|
71
|
+
try {
|
|
72
|
+
nodeCrypto.createHmac('sha256', 'test');
|
|
73
|
+
return nodeCrypto;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.warn('Node.js crypto not available, falling back to browser implementation');
|
|
76
|
+
}
|
|
57
77
|
}
|
|
58
|
-
// Fall back to browser implementation
|
|
59
|
-
return new BrowserCrypto();
|
|
60
78
|
} catch (e) {
|
|
61
|
-
|
|
79
|
+
console.warn('Node.js environment detection failed, falling back to browser implementation');
|
|
62
80
|
}
|
|
81
|
+
// Fall back to browser implementation
|
|
82
|
+
return new BrowserCrypto();
|
|
63
83
|
};
|
|
64
84
|
|
|
65
|
-
|
|
85
|
+
// Singleton crypto instance
|
|
86
|
+
const cryptoInstance: CryptoInterface = getCrypto();
|
|
66
87
|
|
|
67
88
|
class Session {
|
|
68
89
|
private static _id_key = 'user_id';
|
|
@@ -96,14 +117,9 @@ class Session {
|
|
|
96
117
|
return Storage.get(Session._email_key);
|
|
97
118
|
}
|
|
98
119
|
|
|
99
|
-
public static hasJoinedCommunity() {
|
|
120
|
+
public static hasJoinedCommunity(): boolean {
|
|
100
121
|
const community = Storage.get('community');
|
|
101
|
-
|
|
102
|
-
if (!community) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return (community?.me) ? true : false;
|
|
122
|
+
return !!community?.me;
|
|
107
123
|
}
|
|
108
124
|
|
|
109
125
|
public static end(): void {
|
|
@@ -115,7 +131,14 @@ class Session {
|
|
|
115
131
|
Storage.set(Session._username_key, null);
|
|
116
132
|
}
|
|
117
133
|
|
|
118
|
-
public static processAuthentication(data: {
|
|
134
|
+
public static processAuthentication(data: {
|
|
135
|
+
token: { access_token: string },
|
|
136
|
+
id: string,
|
|
137
|
+
first_name: string,
|
|
138
|
+
last_name: string,
|
|
139
|
+
email: string,
|
|
140
|
+
username: string
|
|
141
|
+
}): void {
|
|
119
142
|
Storage.setAuthToken(data.token.access_token);
|
|
120
143
|
Storage.set(Session._id_key, data.id);
|
|
121
144
|
Storage.set(Session._first_name_key, data.first_name);
|
|
@@ -142,7 +165,7 @@ class Session {
|
|
|
142
165
|
throw new Error('secret is required');
|
|
143
166
|
}
|
|
144
167
|
|
|
145
|
-
return
|
|
168
|
+
return cryptoInstance
|
|
146
169
|
.createHmac('sha256', secret)
|
|
147
170
|
.update(titleId)
|
|
148
171
|
.digest('hex');
|