@deconscrew/forgefx-sdk-ts 1.0.0
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 +24 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.js +34 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/request.d.ts +8 -0
- package/dist/request.js +17 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# ForgeFX TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the ForgeFX / Outlaw Code Studio API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
npm install forgefx-sdk-ts
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
import { ForgeFXClient } from 'forgefx-sdk-ts';
|
|
12
|
+
|
|
13
|
+
const fx = new ForgeFXClient({ apiKey: process.env.FORGEFX_API_KEY! });
|
|
14
|
+
|
|
15
|
+
await fx.health();
|
|
16
|
+
await fx.validate('forgefx-vampire-framework');
|
|
17
|
+
|
|
18
|
+
## Node Requirement
|
|
19
|
+
|
|
20
|
+
Node.js 18 or newer (native fetch required).
|
|
21
|
+
|
|
22
|
+
## Version
|
|
23
|
+
|
|
24
|
+
1.0.0
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { apiRequest } from './request.js';
|
|
2
|
+
import { LicenseInvalidError } from './errors.js';
|
|
3
|
+
export class ForgeFXClient {
|
|
4
|
+
apiKey;
|
|
5
|
+
baseUrl;
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
if (!opts.apiKey) {
|
|
8
|
+
throw new Error('ForgeFXClient requires an apiKey');
|
|
9
|
+
}
|
|
10
|
+
this.apiKey = opts.apiKey;
|
|
11
|
+
this.baseUrl = (opts.baseUrl || 'https://api.outlawcodestudio.com')
|
|
12
|
+
.replace(/\/$/, '');
|
|
13
|
+
}
|
|
14
|
+
async health() {
|
|
15
|
+
return apiRequest({
|
|
16
|
+
baseUrl: this.baseUrl,
|
|
17
|
+
apiKey: this.apiKey,
|
|
18
|
+
path: '/health'
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async validate(product) {
|
|
22
|
+
const result = await apiRequest({
|
|
23
|
+
baseUrl: this.baseUrl,
|
|
24
|
+
apiKey: this.apiKey,
|
|
25
|
+
path: '/v1/validate',
|
|
26
|
+
method: 'POST',
|
|
27
|
+
body: { product }
|
|
28
|
+
});
|
|
29
|
+
if (!result.valid) {
|
|
30
|
+
throw new LicenseInvalidError(result.reason);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/errors.d.ts
ADDED
package/dist/errors.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class ForgeFXError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'ForgeFXError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class LicenseInvalidError extends ForgeFXError {
|
|
8
|
+
constructor(reason) {
|
|
9
|
+
super(reason || 'License invalid');
|
|
10
|
+
this.name = 'LicenseInvalidError';
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/request.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export async function apiRequest(opts) {
|
|
2
|
+
const url = `${opts.baseUrl}${opts.path}`;
|
|
3
|
+
const res = await fetch(url, {
|
|
4
|
+
method: opts.method || 'GET',
|
|
5
|
+
headers: {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
'X-API-Key': opts.apiKey
|
|
8
|
+
},
|
|
9
|
+
body: opts.body ? JSON.stringify(opts.body) : undefined
|
|
10
|
+
});
|
|
11
|
+
const text = await res.text();
|
|
12
|
+
const data = text ? JSON.parse(text) : null;
|
|
13
|
+
if (!res.ok) {
|
|
14
|
+
throw new Error(`ForgeFX request failed (${res.status})`);
|
|
15
|
+
}
|
|
16
|
+
return data;
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deconscrew/forgefx-sdk-ts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official TypeScript SDK for the ForgeFX / Outlaw Code Studio Licensing API",
|
|
5
|
+
"author": "Outlaw Code Studio",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/deconscrew/forgefx-sdk-ts"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"forgefx",
|
|
28
|
+
"outlaw-code-studio",
|
|
29
|
+
"licensing",
|
|
30
|
+
"sdk",
|
|
31
|
+
"typescript",
|
|
32
|
+
"api"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|