wombo-dream-api
Version:
Unofficial API for Wombo Dream
72 lines (62 loc) • 2.46 kB
text/typescript
import { DEFAULT_AUTHENTIFICATION_KEY } from '.';
import GoogleAuthentifier from './GoogleAuthentifier';
import { AuthorisationCache, CredentialsBody } from './types';
const randomMax = 1000000;
const randomMin = 1000000;
const createRandomUsername = (): string => {
return '' + Math.floor(Math.random() * randomMax) + randomMin;
};
const createRandomCredentials = (): CredentialsBody => {
const randomIdentifier = Math.floor(Math.random() * randomMax) + randomMin;
return {
email: `test-mail-${randomIdentifier}@test.com`,
password: 'SomeStrongPassword763908_',
};
};
const createRandomAuthorisationCache = (): AuthorisationCache => {
return {
token: 'some-token',
expirationDate: new Date(),
refreshToken: 'some-refresh-token',
};
};
const createAnonymousAuthentifier = async (): Promise<GoogleAuthentifier> => {
return new GoogleAuthentifier(DEFAULT_AUTHENTIFICATION_KEY);
};
const createAnonymousValidAuthentifier =
async (): Promise<GoogleAuthentifier> => {
const authentifier = new GoogleAuthentifier(DEFAULT_AUTHENTIFICATION_KEY);
await authentifier.signUp();
return authentifier;
};
const createValidAuthentifier = async (): Promise<GoogleAuthentifier> => {
const credentials = createRandomCredentials();
const authentifier = new GoogleAuthentifier(
DEFAULT_AUTHENTIFICATION_KEY,
credentials
);
await authentifier.signUp(credentials);
return authentifier;
};
const jpegImage = Buffer.from([
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01,
0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc2,
0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x11, 0x00, 0xff, 0xc4,
0x00, 0x14, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01,
0x00, 0x01, 0x3f, 0x10,
]);
export {
createRandomCredentials,
createRandomUsername,
createRandomAuthorisationCache,
createAnonymousAuthentifier,
createAnonymousValidAuthentifier,
createValidAuthentifier,
jpegImage,
};