graphlit-client 1.0.20240418014 → 1.0.20240418016
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/README.md +3 -2
- package/dist/client.d.ts +0 -1
- package/dist/client.js +25 -51
- package/package.json +13 -2
package/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Node.js Client for Graphlit Platform
|
2
2
|
## Overview
|
3
3
|
|
4
|
-
The Graphlit Client for
|
4
|
+
The Graphlit Client for Node.js enables straightforward interactions with the Graphlit API, allowing developers to execute GraphQL queries and mutations against the Graphlit service. This document outlines the setup process and provides a basic example of using the client.
|
5
5
|
|
6
6
|
## Prerequisites
|
7
7
|
|
8
8
|
Before you begin, ensure you have the following:
|
9
9
|
|
10
|
+
- Node.js installed on your system (recommended version 14.x or higher).
|
10
11
|
- An active account on the [Graphlit Platform](https://portal.graphlit.dev) with access to the API settings dashboard.
|
11
12
|
|
12
13
|
## Installation
|
package/dist/client.d.ts
CHANGED
@@ -10,7 +10,6 @@ declare class Graphlit {
|
|
10
10
|
private correlationId;
|
11
11
|
private token;
|
12
12
|
constructor(organizationId?: string, environmentId?: string, jwtSecret?: string, ownerId?: string, apiUri?: string, correlationId?: string);
|
13
|
-
private initializeJWT;
|
14
13
|
createAlert(alert: Types.AlertInput): Promise<Types.Alert>;
|
15
14
|
updateAlert(alert: Types.AlertUpdateInput): Promise<Types.Alert>;
|
16
15
|
deleteAlert(id: string): Promise<Types.Alert>;
|
package/dist/client.js
CHANGED
@@ -33,7 +33,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
33
33
|
};
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
35
35
|
exports.Types = exports.Graphlit = void 0;
|
36
|
-
const
|
36
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
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"));
|
@@ -67,57 +67,31 @@ class Graphlit {
|
|
67
67
|
if (!this.jwtSecret) {
|
68
68
|
throw new Error("Graphlit environment JWT secret is required.");
|
69
69
|
}
|
70
|
-
this.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
});
|
89
|
-
}
|
90
|
-
initializeJWT() {
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
92
|
-
if (!this.jwtSecret)
|
93
|
-
return;
|
94
|
-
const expiration = Math.floor(Date.now() / 1000) + (60 * 60); // one hour from now
|
95
|
-
const payload = {
|
96
|
-
"https://graphlit.io/jwt/claims": Object.assign(Object.assign({ "x-graphlit-environment-id": this.environmentId, "x-graphlit-organization-id": this.organizationId }, (this.ownerId && { "x-graphlit-owner-id": this.ownerId })), { "x-graphlit-role": "Owner" }),
|
97
|
-
exp: expiration,
|
98
|
-
iss: "graphlit",
|
99
|
-
aud: "https://portal.graphlit.io",
|
100
|
-
};
|
101
|
-
function uint8ArrayToBase64(buffer) {
|
102
|
-
var binary = '';
|
103
|
-
var bytes = new Uint8Array(buffer);
|
104
|
-
var len = bytes.byteLength;
|
105
|
-
for (var i = 0; i < len; i++) {
|
106
|
-
binary += String.fromCharCode(bytes[i]);
|
70
|
+
if (!this.jwtSecret) {
|
71
|
+
throw new Error("JWT secret is required.");
|
72
|
+
}
|
73
|
+
const expiration = Math.floor(Date.now() / 1000) + (60 * 60); // one hour from now
|
74
|
+
const payload = {
|
75
|
+
"https://graphlit.io/jwt/claims": Object.assign(Object.assign({ "x-graphlit-environment-id": this.environmentId, "x-graphlit-organization-id": this.organizationId }, (this.ownerId && { "x-graphlit-owner-id": this.ownerId })), { "x-graphlit-role": "Owner" }),
|
76
|
+
exp: expiration,
|
77
|
+
iss: "graphlit",
|
78
|
+
aud: "https://portal.graphlit.io",
|
79
|
+
};
|
80
|
+
this.token = jwt.sign(payload, this.jwtSecret, { algorithm: 'HS256' });
|
81
|
+
const httpLink = (0, core_1.createHttpLink)({
|
82
|
+
uri: this.apiUri,
|
83
|
+
});
|
84
|
+
const authLink = new core_1.ApolloLink((operation, forward) => {
|
85
|
+
operation.setContext({
|
86
|
+
headers: {
|
87
|
+
Authorization: this.token ? `Bearer ${this.token}` : "",
|
107
88
|
}
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
alg: 'HS256'
|
115
|
-
}, 'HS256');
|
116
|
-
this.token = yield new jose_1.SignJWT(payload)
|
117
|
-
.setProtectedHeader({ alg: 'HS256' })
|
118
|
-
.setIssuedAt()
|
119
|
-
.setExpirationTime('1h')
|
120
|
-
.sign(secretKeyJWK);
|
89
|
+
});
|
90
|
+
return forward(operation);
|
91
|
+
});
|
92
|
+
this.client = new core_1.ApolloClient({
|
93
|
+
link: authLink.concat(httpLink),
|
94
|
+
cache: new core_1.InMemoryCache(),
|
121
95
|
});
|
122
96
|
}
|
123
97
|
createAlert(alert) {
|
package/package.json
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "graphlit-client",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.20240418016",
|
4
4
|
"description": "Graphlit API TypeScript Client",
|
5
5
|
"main": "dist/client.js",
|
6
6
|
"types": "dist/client.d.ts",
|
7
|
+
"repository": {
|
8
|
+
"type": "git",
|
9
|
+
"url": "https://github.com/graphlit/graphlit-client-typescript"
|
10
|
+
},
|
11
|
+
"contributors": [
|
12
|
+
"Kirk Marple (https://github.com/kirk-marple)"
|
13
|
+
],
|
14
|
+
"engines": {
|
15
|
+
"node": ">=14.0.0"
|
16
|
+
},
|
7
17
|
"scripts": {
|
8
18
|
"generate": "graphql-codegen --config codegen.yml",
|
9
19
|
"build": "tsc -p tsconfig.json"
|
@@ -27,10 +37,11 @@
|
|
27
37
|
"@graphql-codegen/typescript": "^4.0.6",
|
28
38
|
"@graphql-codegen/typescript-operations": "^4.2.0",
|
29
39
|
"graphql": "^16.8.1",
|
30
|
-
"
|
40
|
+
"jsonwebtoken": "^9.0.2"
|
31
41
|
},
|
32
42
|
"devDependencies": {
|
33
43
|
"@graphql-codegen/typescript-document-nodes": "^4.0.6",
|
44
|
+
"@types/jsonwebtoken": "^9.0.6",
|
34
45
|
"typescript": "^5.4.5"
|
35
46
|
}
|
36
47
|
}
|