graphlit-client 1.0.20240418010 → 1.0.20240418012
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/client.js +26 -10
- package/package.json +1 -1
package/dist/client.js
CHANGED
@@ -37,19 +37,25 @@ const jose_1 = require("jose");
|
|
37
37
|
const core_1 = require("@apollo/client/core");
|
38
38
|
const Documents = __importStar(require("./generated/graphql-documents"));
|
39
39
|
const dotenv = __importStar(require("dotenv"));
|
40
|
-
// Initialize dotenv to use environment variables
|
41
|
-
if (process)
|
42
|
-
dotenv.config();
|
43
40
|
// Define the Graphlit class
|
44
41
|
class Graphlit {
|
45
42
|
constructor(organizationId, environmentId, jwtSecret, ownerId, apiUri, correlationId) {
|
46
|
-
var _a, _b, _c, _d;
|
47
43
|
this.apiUri = apiUri || "https://data-scus.graphlit.io/api/v1";
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
if (typeof process !== 'undefined') {
|
45
|
+
dotenv.config();
|
46
|
+
this.organizationId = organizationId || process.env.GRAPHLIT_ORGANIZATION_ID;
|
47
|
+
this.environmentId = environmentId || process.env.GRAPHLIT_ENVIRONMENT_ID;
|
48
|
+
this.jwtSecret = jwtSecret || process.env.GRAPHLIT_JWT_SECRET;
|
49
|
+
// optional: for multi-tenant support
|
50
|
+
this.ownerId = ownerId || process.env.GRAPHLIT_OWNER_ID;
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
this.organizationId = organizationId;
|
54
|
+
this.environmentId = environmentId;
|
55
|
+
this.jwtSecret = jwtSecret;
|
56
|
+
// optional: for multi-tenant support
|
57
|
+
this.ownerId = ownerId;
|
58
|
+
}
|
53
59
|
// optional: for billing correlation of multiple operations
|
54
60
|
this.correlationId = correlationId || undefined;
|
55
61
|
if (!this.organizationId) {
|
@@ -90,9 +96,19 @@ class Graphlit {
|
|
90
96
|
iss: "graphlit",
|
91
97
|
aud: "https://portal.graphlit.io",
|
92
98
|
};
|
99
|
+
function uint8ArrayToBase64(buffer) {
|
100
|
+
var binary = '';
|
101
|
+
var bytes = new Uint8Array(buffer);
|
102
|
+
var len = bytes.byteLength;
|
103
|
+
for (var i = 0; i < len; i++) {
|
104
|
+
binary += String.fromCharCode(bytes[i]);
|
105
|
+
}
|
106
|
+
return window.btoa(binary);
|
107
|
+
}
|
108
|
+
// NOTE: not using Buffer, so we don't require Node.js
|
93
109
|
const secretKeyJWK = yield (0, jose_1.importJWK)({
|
94
110
|
kty: 'oct',
|
95
|
-
k:
|
111
|
+
k: uint8ArrayToBase64(new TextEncoder().encode(this.jwtSecret)),
|
96
112
|
alg: 'HS256'
|
97
113
|
}, 'HS256');
|
98
114
|
this.token = yield new jose_1.SignJWT(payload)
|