refactor: (wip) add utilities folder, CSUtil class
parent
d926a4aba1
commit
cbfa49070b
|
@ -0,0 +1,46 @@
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
interface CSDAccountStatusBasic {
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
found?: boolean,
|
||||||
|
readonly tier: number,
|
||||||
|
readonly totalReferrals?: number,
|
||||||
|
readonly createdAt?: Date,
|
||||||
|
readonly warns?: Date[],
|
||||||
|
readonly locks?: Date[],
|
||||||
|
readonly deletes?: Date[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class CloudServicesUtil {
|
||||||
|
/**
|
||||||
|
* This function calls an internal CSD API to upgrade the member's Tier to T2 from T1.
|
||||||
|
* @param userID The member's ID
|
||||||
|
* @param authorization The authorization key | Client#config.internalKey
|
||||||
|
* @returns HTTP Status Code
|
||||||
|
*/
|
||||||
|
static async upgradeT2(userID: string, authorization: string) {
|
||||||
|
const response = await axios.get(`https://api.cloud.libraryofcode.org/wh/t2?userID=${userID}&auth=${authorization}`);
|
||||||
|
return response.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function calls an internal CSD API to downgrade the member's Tier to T1 from T2.
|
||||||
|
* Do not call this API to downgrade from T3 to T1, the function call will silently fail.
|
||||||
|
* @param userID The member's ID
|
||||||
|
* @param authorization The authorization key | Client#config.internalKey
|
||||||
|
* @returns HTTP Status Code
|
||||||
|
*/
|
||||||
|
static async downgradeT2(userID: string, authorization: string) {
|
||||||
|
const response = await axios.get(`https://api.cloud.libraryofcode.org/wh/t2-rm?userID=${userID}&auth=${authorization}`);
|
||||||
|
return response.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async fetchAccountStatus(userID: string, authorization: string) {
|
||||||
|
const response = (await axios.get<CSDAccountStatusBasic>(`https://api.cloud.libraryofcode.org/wh/score?id=${userID}&authorization=${authorization}`)).data;
|
||||||
|
if (!response.found) return null;
|
||||||
|
delete response.found;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
export { default as CloudServicesUtil } from './CloudServices';
|
|
@ -47,7 +47,7 @@
|
||||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
// "types": [], /* Type declaration files to be included in compilation. */
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||||
|
|
||||||
/* Experimental Options */
|
/* Experimental Options */
|
||||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue