artifacts-api-client 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/LICENSE.md +21 -0
- package/README.md +72 -0
- package/dist/api/artifacts-accounts.api.d.ts +8 -0
- package/dist/api/artifacts-accounts.api.js +16 -0
- package/dist/api/artifacts-characters.api.d.ts +12 -0
- package/dist/api/artifacts-characters.api.js +24 -0
- package/dist/api/artifacts-events.api.d.ts +8 -0
- package/dist/api/artifacts-events.api.js +16 -0
- package/dist/api/artifacts-grand-exchange.api.d.ts +10 -0
- package/dist/api/artifacts-grand-exchange.api.js +20 -0
- package/dist/api/artifacts-items.api.d.ts +10 -0
- package/dist/api/artifacts-items.api.js +20 -0
- package/dist/api/artifacts-maps.api.d.ts +10 -0
- package/dist/api/artifacts-maps.api.js +22 -0
- package/dist/api/artifacts-monsters.api.d.ts +10 -0
- package/dist/api/artifacts-monsters.api.js +20 -0
- package/dist/api/artifacts-my-account.api.d.ts +12 -0
- package/dist/api/artifacts-my-account.api.js +27 -0
- package/dist/api/artifacts-my-characters.api.d.ts +46 -0
- package/dist/api/artifacts-my-characters.api.js +98 -0
- package/dist/api/artifacts-resources.api.d.ts +10 -0
- package/dist/api/artifacts-resources.api.js +20 -0
- package/dist/api/artifacts-token.api.d.ts +11 -0
- package/dist/api/artifacts-token.api.js +23 -0
- package/dist/api/artifacts.api.d.ts +32 -0
- package/dist/api/artifacts.api.js +54 -0
- package/dist/errors/artifacts.error.d.ts +13 -0
- package/dist/errors/artifacts.error.js +16 -0
- package/dist/http-client/artifacts.http-client.d.ts +10 -0
- package/dist/http-client/artifacts.http-client.js +66 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/types/api-schema.types.d.ts +4442 -0
- package/dist/types/api-schema.types.js +6 -0
- package/dist/types/artifacts-api.types.d.ts +4 -0
- package/dist/types/artifacts-api.types.js +2 -0
- package/dist/types/artifacts-http-client.types.d.ts +17 -0
- package/dist/types/artifacts-http-client.types.js +2 -0
- package/dist/utils/toBase64.d.ts +1 -0
- package/dist/utils/toBase64.js +8 -0
- package/package.json +40 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArtifactsApi = void 0;
|
|
4
|
+
const artifacts_http_client_1 = require("../http-client/artifacts.http-client");
|
|
5
|
+
const artifacts_my_characters_api_1 = require("./artifacts-my-characters.api");
|
|
6
|
+
const artifacts_characters_api_1 = require("./artifacts-characters.api");
|
|
7
|
+
const artifacts_my_account_api_1 = require("./artifacts-my-account.api");
|
|
8
|
+
const artifacts_maps_api_1 = require("./artifacts-maps.api");
|
|
9
|
+
const artifacts_items_api_1 = require("./artifacts-items.api");
|
|
10
|
+
const artifacts_monsters_api_1 = require("./artifacts-monsters.api");
|
|
11
|
+
const artifacts_resources_api_1 = require("./artifacts-resources.api");
|
|
12
|
+
const artifacts_events_api_1 = require("./artifacts-events.api");
|
|
13
|
+
const artifacts_grand_exchange_api_1 = require("./artifacts-grand-exchange.api");
|
|
14
|
+
const artifacts_accounts_api_1 = require("./artifacts-accounts.api");
|
|
15
|
+
const artifacts_token_api_1 = require("./artifacts-token.api");
|
|
16
|
+
class ArtifactsApi {
|
|
17
|
+
httpClient;
|
|
18
|
+
myCharacters;
|
|
19
|
+
myAccount;
|
|
20
|
+
characters;
|
|
21
|
+
accounts;
|
|
22
|
+
maps;
|
|
23
|
+
items;
|
|
24
|
+
monsters;
|
|
25
|
+
resources;
|
|
26
|
+
events;
|
|
27
|
+
grandExchange;
|
|
28
|
+
token;
|
|
29
|
+
constructor(httpClient) {
|
|
30
|
+
this.httpClient = httpClient;
|
|
31
|
+
this.myCharacters = new artifacts_my_characters_api_1.ArtifactsMyCharactersApi(httpClient);
|
|
32
|
+
this.characters = new artifacts_characters_api_1.ArtifactsCharactersApi(httpClient);
|
|
33
|
+
this.myAccount = new artifacts_my_account_api_1.ArtifactsMyAccountApi(httpClient);
|
|
34
|
+
this.maps = new artifacts_maps_api_1.ArtifactsMapsApi(httpClient);
|
|
35
|
+
this.items = new artifacts_items_api_1.ArtifactsItemsApi(httpClient);
|
|
36
|
+
this.monsters = new artifacts_monsters_api_1.ArtifactsMonstersApi(httpClient);
|
|
37
|
+
this.resources = new artifacts_resources_api_1.ArtifactsResourcesApi(httpClient);
|
|
38
|
+
this.events = new artifacts_events_api_1.ArtifactsEventsApi(httpClient);
|
|
39
|
+
this.grandExchange = new artifacts_grand_exchange_api_1.ArtifactsGrandExchangeApi(httpClient);
|
|
40
|
+
this.accounts = new artifacts_accounts_api_1.ArtifactsAccountsApi(httpClient);
|
|
41
|
+
this.token = new artifacts_token_api_1.ArtifactsTokenApi(httpClient);
|
|
42
|
+
}
|
|
43
|
+
static create(params = {}) {
|
|
44
|
+
const httpClient = new artifacts_http_client_1.ArtifactsHttpClient(params.baseUrl ?? 'https://api.artifactsmmo.com', params.token ?? '');
|
|
45
|
+
return new ArtifactsApi(httpClient);
|
|
46
|
+
}
|
|
47
|
+
getStatus() {
|
|
48
|
+
return this.httpClient.get('/');
|
|
49
|
+
}
|
|
50
|
+
setToken(token) {
|
|
51
|
+
this.httpClient.setToken(token);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ArtifactsApi = ArtifactsApi;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class ArtifactsError extends Error {
|
|
2
|
+
readonly code: number;
|
|
3
|
+
readonly data?: object;
|
|
4
|
+
constructor(code: number, message: string, data?: object);
|
|
5
|
+
static isHttpArtifactsError(obj: unknown): obj is HttpArtifactsError;
|
|
6
|
+
}
|
|
7
|
+
export type HttpArtifactsError = {
|
|
8
|
+
error: {
|
|
9
|
+
code: number;
|
|
10
|
+
message: string;
|
|
11
|
+
data: object;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArtifactsError = void 0;
|
|
4
|
+
class ArtifactsError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
data;
|
|
7
|
+
constructor(code, message, data) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
static isHttpArtifactsError(obj) {
|
|
13
|
+
return typeof obj === 'object' && obj !== null && 'error' in obj;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ArtifactsError = ArtifactsError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GetRequestParams, PostRequestParams } from '../types/artifacts-http-client.types';
|
|
2
|
+
export declare class ArtifactsHttpClient {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private token;
|
|
5
|
+
constructor(baseUrl: string, token: string);
|
|
6
|
+
setToken(token: string): void;
|
|
7
|
+
post<R>(path: string, params?: PostRequestParams): Promise<R>;
|
|
8
|
+
get<R>(path: string, params?: GetRequestParams): Promise<R>;
|
|
9
|
+
private request;
|
|
10
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArtifactsHttpClient = void 0;
|
|
4
|
+
const artifacts_error_1 = require("../errors/artifacts.error");
|
|
5
|
+
class ArtifactsHttpClient {
|
|
6
|
+
baseUrl;
|
|
7
|
+
token;
|
|
8
|
+
constructor(baseUrl, token) {
|
|
9
|
+
this.baseUrl = baseUrl;
|
|
10
|
+
this.token = token;
|
|
11
|
+
}
|
|
12
|
+
setToken(token) {
|
|
13
|
+
this.token = token;
|
|
14
|
+
}
|
|
15
|
+
async post(path, params = {}) {
|
|
16
|
+
return this.request({
|
|
17
|
+
method: 'POST',
|
|
18
|
+
path,
|
|
19
|
+
body: params.body,
|
|
20
|
+
isSecure: params.isSecure,
|
|
21
|
+
headers: params.headers,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async get(path, params = {}) {
|
|
25
|
+
return this.request({
|
|
26
|
+
method: 'GET',
|
|
27
|
+
path,
|
|
28
|
+
query: params.query,
|
|
29
|
+
isSecure: params.isSecure,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async request(params = {}) {
|
|
33
|
+
const urlParams = new URLSearchParams(params.query);
|
|
34
|
+
const url = new URL(params.path ?? '', this.baseUrl);
|
|
35
|
+
url.search = urlParams.toString();
|
|
36
|
+
const method = params.method ?? 'GET';
|
|
37
|
+
const headers = {
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
};
|
|
40
|
+
if (method === 'POST') {
|
|
41
|
+
headers['Content-Type'] = 'application/json';
|
|
42
|
+
}
|
|
43
|
+
if (params.isSecure) {
|
|
44
|
+
headers['Authorization'] = `Bearer ${this.token}`;
|
|
45
|
+
}
|
|
46
|
+
if (params.headers) {
|
|
47
|
+
Object.assign(headers, params.headers);
|
|
48
|
+
}
|
|
49
|
+
let body;
|
|
50
|
+
if (method !== 'GET') {
|
|
51
|
+
body = JSON.stringify(params.body);
|
|
52
|
+
}
|
|
53
|
+
const response = await fetch(url.toString(), {
|
|
54
|
+
method,
|
|
55
|
+
headers,
|
|
56
|
+
body,
|
|
57
|
+
});
|
|
58
|
+
const result = await response.json();
|
|
59
|
+
if (artifacts_error_1.ArtifactsError.isHttpArtifactsError(result)) {
|
|
60
|
+
const { error } = result;
|
|
61
|
+
throw new artifacts_error_1.ArtifactsError(error.code, error.message, error.data);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ArtifactsHttpClient = ArtifactsHttpClient;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArtifactsError = exports.ArtifactsApi = void 0;
|
|
4
|
+
var artifacts_api_1 = require("./api/artifacts.api");
|
|
5
|
+
Object.defineProperty(exports, "ArtifactsApi", { enumerable: true, get: function () { return artifacts_api_1.ArtifactsApi; } });
|
|
6
|
+
var artifacts_error_1 = require("./errors/artifacts.error");
|
|
7
|
+
Object.defineProperty(exports, "ArtifactsError", { enumerable: true, get: function () { return artifacts_error_1.ArtifactsError; } });
|