refactor: (wip) add utilities folder, CSUtil class

master
Matthew 2021-09-17 19:42:19 -04:00
parent d926a4aba1
commit cbfa49070b
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
3 changed files with 111 additions and 64 deletions

46
src/util/CloudServices.ts Normal file
View File

@ -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;
}
}

1
src/util/index.ts Normal file
View File

@ -0,0 +1 @@
export { default as CloudServicesUtil } from './CloudServices';

View File

@ -47,7 +47,7 @@
// "typeRoots": [], /* List of folders to include type definitions from. */
// "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. */
"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. */
// "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. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
}
}