eclesiar-sdk 1.1.0 → 1.1.3
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/ApiError.d.ts +10 -0
- package/dist/ApiError.js +17 -0
- package/dist/_.d.ts +25 -0
- package/dist/_.js +71 -0
- package/dist/api/accounts/getAccount.d.ts +4 -0
- package/dist/api/accounts/getAccount.js +5 -0
- package/dist/api/accounts/getMyEquipment.d.ts +4 -0
- package/dist/api/accounts/getMyEquipment.js +5 -0
- package/{src/api/accounts/index.ts → dist/api/accounts/index.d.ts} +2 -10
- package/dist/api/accounts/index.js +7 -0
- package/dist/api/accounts/types.d.ts +7 -0
- package/dist/api/accounts/types.js +1 -0
- package/dist/api/countries/getCountries.d.ts +2 -0
- package/dist/api/countries/getCountries.js +4 -0
- package/dist/api/countries/getCountryRegions.d.ts +6 -0
- package/dist/api/countries/getCountryRegions.js +5 -0
- package/{src/api/countries/index.ts → dist/api/countries/index.d.ts} +2 -10
- package/dist/api/countries/index.js +7 -0
- package/dist/api/countries/types.d.ts +7 -0
- package/dist/api/countries/types.js +1 -0
- package/{src/api/index.ts → dist/api/index.d.ts} +1 -2
- package/dist/api/index.js +6 -0
- package/dist/api/market/getAuctionBid.d.ts +5 -0
- package/dist/api/market/getAuctionBid.js +8 -0
- package/dist/api/market/getAuctions.d.ts +5 -0
- package/dist/api/market/getAuctions.js +8 -0
- package/dist/api/market/getCoinOffers.d.ts +6 -0
- package/dist/api/market/getCoinOffers.js +9 -0
- package/dist/api/market/getItemOffers.d.ts +6 -0
- package/dist/api/market/getItemOffers.js +9 -0
- package/dist/api/market/getJobs.d.ts +7 -0
- package/dist/api/market/getJobs.js +8 -0
- package/dist/api/market/index.d.ts +9 -0
- package/{src/api/market/index.ts → dist/api/market/index.js} +3 -13
- package/dist/api/market/types.d.ts +25 -0
- package/dist/api/market/types.js +1 -0
- package/dist/api/server/getEquipments.d.ts +4 -0
- package/dist/api/server/getEquipments.js +5 -0
- package/dist/api/server/getItems.d.ts +4 -0
- package/dist/api/server/getItems.js +5 -0
- package/dist/api/server/getStatus.d.ts +2 -0
- package/dist/api/server/getStatus.js +4 -0
- package/{src/api/server/index.ts → dist/api/server/index.d.ts} +2 -12
- package/dist/api/server/index.js +9 -0
- package/dist/api/server/types.d.ts +10 -0
- package/dist/api/server/types.js +1 -0
- package/dist/api/statistics/getStatistics.d.ts +6 -0
- package/dist/api/statistics/getStatistics.js +5 -0
- package/{src/api/statistics/index.ts → dist/api/statistics/index.d.ts} +2 -9
- package/dist/api/statistics/index.js +5 -0
- package/dist/api/statistics/types.d.ts +6 -0
- package/dist/api/statistics/types.js +1 -0
- package/dist/api/wars/getWarRoundHits.d.ts +7 -0
- package/dist/api/wars/getWarRoundHits.js +8 -0
- package/dist/api/wars/getWarRounds.d.ts +6 -0
- package/dist/api/wars/getWarRounds.js +5 -0
- package/dist/api/wars/getWars.d.ts +2 -0
- package/dist/api/wars/getWars.js +11 -0
- package/{src/api/wars/index.ts → dist/api/wars/index.d.ts} +2 -13
- package/dist/api/wars/index.js +9 -0
- package/dist/api/wars/types.d.ts +10 -0
- package/dist/api/wars/types.js +1 -0
- package/dist/client copy.d.ts +25 -0
- package/dist/client copy.js +71 -0
- package/dist/client.d.ts +17 -0
- package/dist/client.js +33 -0
- package/dist/config/index.d.ts +23 -0
- package/dist/config/index.js +54 -0
- package/dist/config/initConfigFile.d.ts +1 -0
- package/dist/config/initConfigFile.js +120 -0
- package/dist/config/types/configSchema.d.ts +19 -0
- package/dist/config/types/configSchema.js +14 -0
- package/dist/config/types/types.d.ts +19 -0
- package/dist/config/types/types.js +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +46 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/{src/types/accounts.ts → dist/types/accounts.d.ts} +3 -4
- package/dist/types/accounts.js +1 -0
- package/{src/types/country.ts → dist/types/country.d.ts} +11 -15
- package/dist/types/country.js +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +6 -0
- package/dist/types/market.d.ts +52 -0
- package/dist/types/market.js +1 -0
- package/{src/types/server.ts → dist/types/server.d.ts} +5 -7
- package/dist/types/server.js +1 -0
- package/dist/types/statistics.d.ts +10 -0
- package/dist/types/statistics.js +1 -0
- package/dist/types/wars.d.ts +52 -0
- package/dist/types/wars.js +1 -0
- package/package.json +4 -1
- package/src/api/accounts/getAccount.ts +0 -9
- package/src/api/accounts/getMyEquipment.ts +0 -9
- package/src/api/accounts/types.ts +0 -6
- package/src/api/countries/getCountries.ts +0 -7
- package/src/api/countries/getCountryRegions.ts +0 -13
- package/src/api/countries/types.ts +0 -6
- package/src/api/market/getAuctionBid.ts +0 -14
- package/src/api/market/getAuctions.ts +0 -13
- package/src/api/market/getCoinOffers.ts +0 -20
- package/src/api/market/getItemOffers.ts +0 -20
- package/src/api/market/getJobs.ts +0 -19
- package/src/api/market/types.ts +0 -9
- package/src/api/server/getEquipments.ts +0 -9
- package/src/api/server/getItems.ts +0 -9
- package/src/api/server/getStatus.ts +0 -6
- package/src/api/server/types.ts +0 -6
- package/src/api/statistics/getStatistics.ts +0 -14
- package/src/api/statistics/types.ts +0 -5
- package/src/api/wars/getWarRoundHits.ts +0 -19
- package/src/api/wars/getWarRounds.ts +0 -11
- package/src/api/wars/getWars.ts +0 -28
- package/src/api/wars/types.ts +0 -7
- package/src/client.ts +0 -68
- package/src/index.ts +0 -10
- package/src/types/index.ts +0 -6
- package/src/types/market.ts +0 -57
- package/src/types/statistics.ts +0 -25
- package/src/types/wars.ts +0 -51
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getWars } from './getWars';
|
|
2
|
+
import { getWarRounds } from './getWarRounds';
|
|
3
|
+
import { getWarRoundHits } from './getWarRoundHits';
|
|
4
|
+
export const warsApi = {
|
|
5
|
+
getWars,
|
|
6
|
+
getWarRounds,
|
|
7
|
+
getWarRoundHits,
|
|
8
|
+
};
|
|
9
|
+
export { getWars, getWarRounds, getWarRoundHits, };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WarRound, WarHit, War, GetWarsParams } from "../../types";
|
|
2
|
+
export interface WarsApi {
|
|
3
|
+
getWars(params: GetWarsParams): Promise<War[]>;
|
|
4
|
+
getWarRounds({ war_id }: {
|
|
5
|
+
war_id: number;
|
|
6
|
+
}): Promise<WarRound[]>;
|
|
7
|
+
getWarRoundHits({ war_round_id }: {
|
|
8
|
+
war_round_id: number;
|
|
9
|
+
}): Promise<WarHit[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AccountsApi } from './api/accounts/types';
|
|
2
|
+
import type { CountriesApi } from './api/countries/types';
|
|
3
|
+
import type { MarketApi } from './api/market/types';
|
|
4
|
+
import type { ServerApi } from './api/server/types';
|
|
5
|
+
import type { StatisticsApi } from './api/statistics/types';
|
|
6
|
+
import type { WarsApi } from './api/wars/types';
|
|
7
|
+
export declare function setToken(token: string): void;
|
|
8
|
+
export interface SdkClient {
|
|
9
|
+
accounts: AccountsApi;
|
|
10
|
+
countries: CountriesApi;
|
|
11
|
+
market: MarketApi;
|
|
12
|
+
server: ServerApi;
|
|
13
|
+
statistics: StatisticsApi;
|
|
14
|
+
wars: WarsApi;
|
|
15
|
+
config: {
|
|
16
|
+
token: string | null;
|
|
17
|
+
baseUrl: 'https://api.eclesiar.com' | 'https://tests.eclesiar.com';
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare const apiClient: SdkClient;
|
|
21
|
+
export declare function updateConfig(newConfig: {
|
|
22
|
+
token?: string;
|
|
23
|
+
baseUrl?: 'https://api.eclesiar.com' | 'https://tests.eclesiar.com';
|
|
24
|
+
}): SdkClient | undefined;
|
|
25
|
+
export declare function apiFetch<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { accountsApi } from './api/accounts';
|
|
2
|
+
import { countriesApi } from './api/countries';
|
|
3
|
+
import { marketApi } from './api/market';
|
|
4
|
+
import { serverApi } from './api/server';
|
|
5
|
+
import { statisticsApi } from './api/statistics';
|
|
6
|
+
import { warsApi } from './api/wars';
|
|
7
|
+
import { ApiError } from './ApiError';
|
|
8
|
+
let BASE_URL = 'https://api.eclesiar.com';
|
|
9
|
+
export function setToken(token) {
|
|
10
|
+
updateConfig({ token });
|
|
11
|
+
}
|
|
12
|
+
export const apiClient = {
|
|
13
|
+
accounts: accountsApi,
|
|
14
|
+
countries: countriesApi,
|
|
15
|
+
market: marketApi,
|
|
16
|
+
server: serverApi,
|
|
17
|
+
statistics: statisticsApi,
|
|
18
|
+
wars: warsApi,
|
|
19
|
+
config: {
|
|
20
|
+
token: null,
|
|
21
|
+
baseUrl: BASE_URL,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export function updateConfig(newConfig) {
|
|
25
|
+
if (newConfig.token) {
|
|
26
|
+
apiClient.config.token = newConfig.token;
|
|
27
|
+
}
|
|
28
|
+
if (newConfig.baseUrl) {
|
|
29
|
+
apiClient.config.baseUrl = newConfig.baseUrl;
|
|
30
|
+
}
|
|
31
|
+
if (apiClient.config.token && apiClient.config.baseUrl) {
|
|
32
|
+
return apiClient;
|
|
33
|
+
}
|
|
34
|
+
if (!apiClient.config.token && !apiClient.config.baseUrl) {
|
|
35
|
+
throw new Error('Config not complete: missing token and baseUrl.');
|
|
36
|
+
}
|
|
37
|
+
else if (!apiClient.config.token) {
|
|
38
|
+
throw new Error('Config not complete: missing token.');
|
|
39
|
+
}
|
|
40
|
+
else if (!apiClient.config.baseUrl) {
|
|
41
|
+
throw new Error('Config not complete: missing baseUrl.');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function apiFetch(endpoint, options = {}) {
|
|
45
|
+
if (!apiClient.config.token) {
|
|
46
|
+
throw new Error('No token provided');
|
|
47
|
+
}
|
|
48
|
+
if (!apiClient.config.baseUrl) {
|
|
49
|
+
throw new Error('No baseUrl provided');
|
|
50
|
+
}
|
|
51
|
+
const res = await fetch(`${apiClient.config.baseUrl}${endpoint}`, {
|
|
52
|
+
...options,
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: `Bearer ${apiClient.config.token}`,
|
|
55
|
+
...(options.headers || {}),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
throw new ApiError(res.status, res.statusText, endpoint, await res.json());
|
|
60
|
+
}
|
|
61
|
+
const json = await res.json();
|
|
62
|
+
// This is a bit of a ugly fix. API returns undefined for no results instead of an empty array.
|
|
63
|
+
// Didnt wanna throw an error for this, so i just cast it to an empty array.
|
|
64
|
+
// Keep in mind, this api might change in the future, so this might break
|
|
65
|
+
// Also, this does not seem to be making a difference in out of bounds params, and things thats not found
|
|
66
|
+
if (json.code === 200 && json.data === undefined) {
|
|
67
|
+
json.data = [];
|
|
68
|
+
}
|
|
69
|
+
console.log({ 'API FROM SERVER:': json });
|
|
70
|
+
return json.data;
|
|
71
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AccountsApi } from './api/accounts/types';
|
|
2
|
+
import type { CountriesApi } from './api/countries/types';
|
|
3
|
+
import type { MarketApi } from './api/market/types';
|
|
4
|
+
import type { ServerApi } from './api/server/types';
|
|
5
|
+
import type { StatisticsApi } from './api/statistics/types';
|
|
6
|
+
import type { WarsApi } from './api/wars/types';
|
|
7
|
+
export declare function setToken(newToken: string): void;
|
|
8
|
+
export declare function apiFetch<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
9
|
+
export interface SdkClient {
|
|
10
|
+
accounts: AccountsApi;
|
|
11
|
+
countries: CountriesApi;
|
|
12
|
+
market: MarketApi;
|
|
13
|
+
server: ServerApi;
|
|
14
|
+
statistics: StatisticsApi;
|
|
15
|
+
wars: WarsApi;
|
|
16
|
+
}
|
|
17
|
+
export declare const apiClient: SdkClient;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { accountsApi } from './api/accounts';
|
|
2
|
+
import { countriesApi } from './api/countries';
|
|
3
|
+
import { marketApi } from './api/market';
|
|
4
|
+
import { serverApi } from './api/server';
|
|
5
|
+
import { statisticsApi } from './api/statistics';
|
|
6
|
+
import { warsApi } from './api/wars';
|
|
7
|
+
const BASE_URL = 'https://api.eclesiar.com';
|
|
8
|
+
let token = '';
|
|
9
|
+
export function setToken(newToken) {
|
|
10
|
+
token = newToken;
|
|
11
|
+
}
|
|
12
|
+
export async function apiFetch(endpoint, options = {}) {
|
|
13
|
+
const res = await fetch(`${BASE_URL}${endpoint}`, {
|
|
14
|
+
...options,
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: `Bearer ${token}`,
|
|
17
|
+
...(options.headers || {}),
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
if (!res.ok) {
|
|
21
|
+
throw new Error(`API Error: ${res.status} ${res.statusText} ${endpoint}`);
|
|
22
|
+
}
|
|
23
|
+
const json = await res.json();
|
|
24
|
+
return json.data;
|
|
25
|
+
}
|
|
26
|
+
export const apiClient = {
|
|
27
|
+
accounts: accountsApi,
|
|
28
|
+
countries: countriesApi,
|
|
29
|
+
market: marketApi,
|
|
30
|
+
server: serverApi,
|
|
31
|
+
statistics: statisticsApi,
|
|
32
|
+
wars: warsApi,
|
|
33
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EnvConfig } from "./types/types";
|
|
2
|
+
type KeysWithFallbackValue = "hideTokenOnAllEnvs" | "defaultEnv" | "environments";
|
|
3
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
4
|
+
type RequiredConfig = Optional<EnvConfig, KeysWithFallbackValue>;
|
|
5
|
+
/**
|
|
6
|
+
* Defines the configuration for the SDK.
|
|
7
|
+
*
|
|
8
|
+
* This function merges user-provided configuration with defaults.
|
|
9
|
+
* It ensures that required fields are populated and applies fallback behavior,
|
|
10
|
+
* especially for token visibility.
|
|
11
|
+
*
|
|
12
|
+
* ### Token Visibility Behavior:
|
|
13
|
+
* - If `hideTokenOnAllEnvs` is set to `true`, then `hideToken: true` will be
|
|
14
|
+
* **enforced on all environments**, overriding any `hideToken` values defined
|
|
15
|
+
* in the environment-specific configuration.
|
|
16
|
+
* - If `hideTokenOnAllEnvs` is `false`, each environment's own `hideToken` setting
|
|
17
|
+
* will be respected as provided.
|
|
18
|
+
*
|
|
19
|
+
* @param {RequiredConfig} config - Partial user configuration.
|
|
20
|
+
* @returns {EnvConfig} Fully resolved configuration with all necessary defaults applied.
|
|
21
|
+
*/
|
|
22
|
+
export declare function defineConfig(config: RequiredConfig): EnvConfig;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default configuration used if certain values are not explicitly provided
|
|
3
|
+
* by the user when calling `defineConfig`.
|
|
4
|
+
*/
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
hideTokenOnAllEnvs: true,
|
|
7
|
+
defaultEnv: "prod",
|
|
8
|
+
environments: {
|
|
9
|
+
prod: {
|
|
10
|
+
baseUrl: "https://api.eclesiar.com",
|
|
11
|
+
token: null,
|
|
12
|
+
hideToken: true,
|
|
13
|
+
},
|
|
14
|
+
test: {
|
|
15
|
+
baseUrl: "https://tests-api.eclesiar.com",
|
|
16
|
+
token: null,
|
|
17
|
+
hideToken: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Defines the configuration for the SDK.
|
|
23
|
+
*
|
|
24
|
+
* This function merges user-provided configuration with defaults.
|
|
25
|
+
* It ensures that required fields are populated and applies fallback behavior,
|
|
26
|
+
* especially for token visibility.
|
|
27
|
+
*
|
|
28
|
+
* ### Token Visibility Behavior:
|
|
29
|
+
* - If `hideTokenOnAllEnvs` is set to `true`, then `hideToken: true` will be
|
|
30
|
+
* **enforced on all environments**, overriding any `hideToken` values defined
|
|
31
|
+
* in the environment-specific configuration.
|
|
32
|
+
* - If `hideTokenOnAllEnvs` is `false`, each environment's own `hideToken` setting
|
|
33
|
+
* will be respected as provided.
|
|
34
|
+
*
|
|
35
|
+
* @param {RequiredConfig} config - Partial user configuration.
|
|
36
|
+
* @returns {EnvConfig} Fully resolved configuration with all necessary defaults applied.
|
|
37
|
+
*/
|
|
38
|
+
export function defineConfig(config) {
|
|
39
|
+
const merged = {
|
|
40
|
+
...defaultConfig,
|
|
41
|
+
...config,
|
|
42
|
+
environments: {
|
|
43
|
+
...defaultConfig.environments,
|
|
44
|
+
...config.environments,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
if (merged.hideTokenOnAllEnvs) {
|
|
48
|
+
for (const env of Object.values(merged.environments)) {
|
|
49
|
+
env.hideToken = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return merged;
|
|
53
|
+
}
|
|
54
|
+
// export const config = defineConfig(defaultConfig);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
/**
|
|
5
|
+
* Initializes an interactive CLI session to generate `.eclesiar.config.ts`
|
|
6
|
+
* and optionally a `.env` file with placeholder or user-provided API tokens.
|
|
7
|
+
*/
|
|
8
|
+
async function initInteractiveConfig() {
|
|
9
|
+
const targetPath = path.resolve(process.cwd(), '.eclesiar.config.ts');
|
|
10
|
+
const envPath = path.resolve(process.cwd(), '.env');
|
|
11
|
+
// Check if config already exists
|
|
12
|
+
if (fs.existsSync(targetPath)) {
|
|
13
|
+
const { overwrite } = await prompts({
|
|
14
|
+
type: 'confirm',
|
|
15
|
+
name: 'overwrite',
|
|
16
|
+
message: '.eclesiar.config.ts already exists. Overwrite?',
|
|
17
|
+
initial: false,
|
|
18
|
+
});
|
|
19
|
+
if (!overwrite) {
|
|
20
|
+
console.log('❌ Aborted.');
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Prompt for config options
|
|
25
|
+
const response = await prompts([
|
|
26
|
+
{
|
|
27
|
+
type: 'select',
|
|
28
|
+
name: 'defaultEnv',
|
|
29
|
+
message: 'Select default environment:',
|
|
30
|
+
choices: [
|
|
31
|
+
{ title: 'Production', value: 'prod' },
|
|
32
|
+
{ title: 'Test', value: 'test' },
|
|
33
|
+
],
|
|
34
|
+
initial: 0,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'confirm',
|
|
38
|
+
name: 'hideTokenOnAllEnvs',
|
|
39
|
+
message: 'Hide API tokens by default?',
|
|
40
|
+
initial: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 'confirm',
|
|
44
|
+
name: 'generateEnv',
|
|
45
|
+
message: 'Generate a .env file with placeholder keys?',
|
|
46
|
+
initial: true,
|
|
47
|
+
}
|
|
48
|
+
]);
|
|
49
|
+
// Defaults for token values
|
|
50
|
+
let prodToken = '';
|
|
51
|
+
let testToken = '';
|
|
52
|
+
// If .env generation selected, prompt for optional token values
|
|
53
|
+
if (response.generateEnv) {
|
|
54
|
+
console.log('\n🔐 Enter API tokens for autofill (leave blank to use placeholders):');
|
|
55
|
+
const tokenResponse = await prompts([
|
|
56
|
+
{
|
|
57
|
+
type: 'text',
|
|
58
|
+
name: 'prodToken',
|
|
59
|
+
message: 'Production token:',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'text',
|
|
63
|
+
name: 'testToken',
|
|
64
|
+
message: 'Test token:',
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
prodToken = tokenResponse.prodToken?.trim() || '';
|
|
68
|
+
testToken = tokenResponse.testToken?.trim() || '';
|
|
69
|
+
}
|
|
70
|
+
// Generate config file content
|
|
71
|
+
const configContent = `import { defineConfig } from 'eclesiar-sdk';
|
|
72
|
+
|
|
73
|
+
export default defineConfig({
|
|
74
|
+
hideTokenOnAllEnvs: ${response.hideTokenOnAllEnvs},
|
|
75
|
+
defaultEnv: '${response.defaultEnv}',
|
|
76
|
+
environments: {
|
|
77
|
+
prod: {
|
|
78
|
+
baseUrl: 'https://api.eclesiar.com',
|
|
79
|
+
token: ${response.generateEnv ? `'${prodToken}'` : 'process.env.ECLESIAR_PROD_TOKEN'} || null,
|
|
80
|
+
hideToken: ${response.hideTokenOnAllEnvs},
|
|
81
|
+
},
|
|
82
|
+
test: {
|
|
83
|
+
baseUrl: 'https://tests-api.eclesiar.com',
|
|
84
|
+
token: ${response.generateEnv ? `'${testToken}'` : 'process.env.ECLESIAR_TEST_TOKEN'} || null,
|
|
85
|
+
hideToken: ${response.hideTokenOnAllEnvs},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
`;
|
|
90
|
+
fs.writeFileSync(targetPath, configContent);
|
|
91
|
+
console.log(`✅ Created: ${targetPath}`);
|
|
92
|
+
// Optionally write .env file
|
|
93
|
+
if (response.generateEnv && !fs.existsSync(envPath)) {
|
|
94
|
+
const envTemplate = `# Eclesiar API Tokens
|
|
95
|
+
ECLESIAR_PROD_TOKEN=${prodToken || 'your-prod-token-here'}
|
|
96
|
+
ECLESIAR_TEST_TOKEN=${testToken || 'your-test-token-here'}
|
|
97
|
+
`;
|
|
98
|
+
fs.writeFileSync(envPath, envTemplate);
|
|
99
|
+
console.log(`✅ Created: ${envPath}`);
|
|
100
|
+
console.log('⚠️ Reminder: Do not commit .env files to version control!');
|
|
101
|
+
const isGitignoreExists = fs.existsSync('.gitignore');
|
|
102
|
+
if (!isGitignoreExists) {
|
|
103
|
+
fs.writeFileSync('.gitignore', '.env');
|
|
104
|
+
console.log('✅ Created: .gitignore');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (fs.existsSync(envPath)) {
|
|
108
|
+
console.log('⚠️ Skipped .env generation: file already exists.');
|
|
109
|
+
}
|
|
110
|
+
console.log('\n🎉 Configuration complete.\n');
|
|
111
|
+
process.exit(0);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks for the `--create-config-file` flag and runs the interactive config init.
|
|
115
|
+
*/
|
|
116
|
+
async function handleCreateConfigFlag() {
|
|
117
|
+
if (process.argv.includes('--create-config-file')) {
|
|
118
|
+
await initInteractiveConfig();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const EnvConfigSchema: z.ZodObject<{
|
|
3
|
+
defaultEnv: z.ZodUnion<readonly [z.ZodLiteral<"prod">, z.ZodLiteral<"test">]>;
|
|
4
|
+
hideTokenOnAllEnvs: z.ZodBoolean;
|
|
5
|
+
environments: z.ZodObject<{
|
|
6
|
+
prod: z.ZodObject<{
|
|
7
|
+
baseUrl: z.ZodString;
|
|
8
|
+
token: z.ZodOptional<z.ZodString>;
|
|
9
|
+
hideToken: z.ZodBoolean;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
test: z.ZodObject<{
|
|
12
|
+
baseUrl: z.ZodString;
|
|
13
|
+
token: z.ZodOptional<z.ZodString>;
|
|
14
|
+
hideToken: z.ZodBoolean;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export type EnvConfig = z.infer<typeof EnvConfigSchema>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const EnvironmentSchema = z.object({
|
|
3
|
+
baseUrl: z.string().url(),
|
|
4
|
+
token: z.string().optional(),
|
|
5
|
+
hideToken: z.boolean(),
|
|
6
|
+
});
|
|
7
|
+
const EnvConfigSchema = z.object({
|
|
8
|
+
defaultEnv: z.union([z.literal("prod"), z.literal("test")]),
|
|
9
|
+
hideTokenOnAllEnvs: z.boolean(),
|
|
10
|
+
environments: z.object({
|
|
11
|
+
prod: EnvironmentSchema,
|
|
12
|
+
test: EnvironmentSchema,
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface EnvConfig {
|
|
2
|
+
environments: Enviroments;
|
|
3
|
+
defaultEnv: 'prod' | 'test';
|
|
4
|
+
hideTokenOnAllEnvs?: boolean;
|
|
5
|
+
}
|
|
6
|
+
type Enviroments = {
|
|
7
|
+
prod: {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
token: string | null;
|
|
10
|
+
hideToken?: boolean;
|
|
11
|
+
};
|
|
12
|
+
test: {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
token: string | null;
|
|
15
|
+
hideToken?: boolean;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type Enviroment = Enviroments['prod'] | Enviroments['test'];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const config: Promise<{
|
|
2
|
+
defaultEnv: "prod" | "test";
|
|
3
|
+
hideTokenOnAllEnvs: boolean;
|
|
4
|
+
environments: {
|
|
5
|
+
prod: {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
hideToken: boolean;
|
|
8
|
+
token?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
test: {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
hideToken: boolean;
|
|
13
|
+
token?: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}>;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
const defaultConfig = {
|
|
4
|
+
environments: {
|
|
5
|
+
prod: {
|
|
6
|
+
baseUrl: 'https://api.eclesiar.com',
|
|
7
|
+
token: undefined,
|
|
8
|
+
hideToken: true,
|
|
9
|
+
},
|
|
10
|
+
test: {
|
|
11
|
+
baseUrl: 'https://tests-api.eclesiar.com',
|
|
12
|
+
token: undefined,
|
|
13
|
+
hideToken: true,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
defaultEnv: 'prod',
|
|
17
|
+
hideTokenOnAllEnvs: true,
|
|
18
|
+
};
|
|
19
|
+
async function loadConfig() {
|
|
20
|
+
const envPath = process.env.ECLESIAR_CONFIG;
|
|
21
|
+
const probable_paths = [
|
|
22
|
+
'./.eclesiar.config.ts',
|
|
23
|
+
'./eclesiar.config.js',
|
|
24
|
+
'./eclesiar.config.ts'
|
|
25
|
+
];
|
|
26
|
+
let configPath = path.resolve(process.cwd() || envPath || probable_paths.find((p) => fs.existsSync(p)) || '');
|
|
27
|
+
if (!configPath.endsWith('.ts') && !configPath.endsWith('.js')) {
|
|
28
|
+
console.warn(`[Eclesiar SDK] Config file must end with .ts or .js: ${configPath}`);
|
|
29
|
+
return defaultConfig;
|
|
30
|
+
}
|
|
31
|
+
if (!fs.existsSync(configPath) || !fs.lstatSync(configPath).isFile()) {
|
|
32
|
+
console.warn(`[Eclesiar SDK] Config file not found: ${configPath}`);
|
|
33
|
+
return defaultConfig;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const module = await import(configPath);
|
|
37
|
+
console.log(`[Eclesiar SDK] Using config file: ${configPath}`);
|
|
38
|
+
return module.default || module;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.warn(`[Eclesiar SDK] Failed to import config file: ${configPath}`);
|
|
42
|
+
console.warn(err);
|
|
43
|
+
return defaultConfig;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const config = loadConfig();
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { apiClient, setToken } from './client';
|
|
@@ -8,10 +8,9 @@ export type AccountData = {
|
|
|
8
8
|
total_mined_gold: number;
|
|
9
9
|
total_builder_progress: number;
|
|
10
10
|
day_of_birth: number;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type EquipmentItem = {
|
|
11
|
+
};
|
|
12
|
+
export type EquipmentItem = {
|
|
14
13
|
id: number;
|
|
15
14
|
equipment_id: number;
|
|
16
15
|
is_equipped: boolean;
|
|
17
|
-
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
export type Currency = {
|
|
2
2
|
id: number;
|
|
3
3
|
name: string;
|
|
4
|
-
symbol: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type Nation = {
|
|
4
|
+
symbol: string;
|
|
5
|
+
};
|
|
6
|
+
export type Nation = {
|
|
8
7
|
id: number;
|
|
9
8
|
name: string;
|
|
10
9
|
avatar: string;
|
|
11
10
|
currency: Currency;
|
|
12
11
|
is_availible: boolean;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type: string;
|
|
12
|
+
};
|
|
13
|
+
export interface RegionBonus {
|
|
14
|
+
type: string;
|
|
17
15
|
value: number;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export type RegionFactories = {
|
|
16
|
+
}
|
|
17
|
+
export type RegionFactories = {
|
|
21
18
|
food: number;
|
|
22
19
|
weapon: number;
|
|
23
20
|
oil: number;
|
|
@@ -26,9 +23,8 @@ export type Currency = {
|
|
|
26
23
|
aircraft: number;
|
|
27
24
|
titanium: number;
|
|
28
25
|
tickets: number;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export type Region = {
|
|
26
|
+
};
|
|
27
|
+
export type Region = {
|
|
32
28
|
id: number;
|
|
33
29
|
name: string;
|
|
34
30
|
type: number;
|
|
@@ -39,4 +35,4 @@ export type Currency = {
|
|
|
39
35
|
pollution: number;
|
|
40
36
|
factories: RegionFactories;
|
|
41
37
|
bonus: RegionBonus[];
|
|
42
|
-
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface ApiResponse<T> {
|
|
2
|
+
code: number;
|
|
3
|
+
description: string;
|
|
4
|
+
data: T;
|
|
5
|
+
}
|
|
6
|
+
export interface MarketCoinOffer {
|
|
7
|
+
amount: number;
|
|
8
|
+
rate: number;
|
|
9
|
+
owner: {
|
|
10
|
+
id: number;
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface MarketItemOffer {
|
|
15
|
+
amount: number;
|
|
16
|
+
rate: number;
|
|
17
|
+
owner: {
|
|
18
|
+
id: number;
|
|
19
|
+
type: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface MarketJobOffer {
|
|
23
|
+
value: number;
|
|
24
|
+
amount: number;
|
|
25
|
+
economic_skill: number;
|
|
26
|
+
currency_id: number;
|
|
27
|
+
business_id: number;
|
|
28
|
+
}
|
|
29
|
+
export interface MarketAuction {
|
|
30
|
+
id: number;
|
|
31
|
+
item: {
|
|
32
|
+
id: number;
|
|
33
|
+
type: string;
|
|
34
|
+
};
|
|
35
|
+
owner: {
|
|
36
|
+
id: number;
|
|
37
|
+
type: string;
|
|
38
|
+
};
|
|
39
|
+
initial_bid: number;
|
|
40
|
+
created_at: string;
|
|
41
|
+
end_at: string;
|
|
42
|
+
status: number;
|
|
43
|
+
}
|
|
44
|
+
export interface MarketAuctionBid {
|
|
45
|
+
id: number;
|
|
46
|
+
bid: number;
|
|
47
|
+
created_at: string;
|
|
48
|
+
owner: {
|
|
49
|
+
id: number;
|
|
50
|
+
type: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|