Skip to content

Commit

Permalink
feat: Remove poet-js & add WorkAttributes Interface (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwicks31 authored Oct 15, 2018
1 parent 1d0c945 commit e685362
Show file tree
Hide file tree
Showing 20 changed files with 2,358 additions and 3,130 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
.vscode
Docker/data
coverage
dist
node_modules
rules
screenshots
Expand Down
58 changes: 58 additions & 0 deletions dist/Frost.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Method, Network } from './utils/utils';
export interface Configuration {
readonly host: string;
readonly email?: string;
readonly password?: string;
readonly timeout?: number;
}
export interface ClaimAttributes {
readonly [key: string]: string;
}
export interface WorkAttributes extends ClaimAttributes {
readonly name: string;
readonly datePublished: string;
readonly dateCreated: string;
readonly author: string;
readonly tags?: string;
readonly content: string;
}
export declare const getOptions: (method: Method, headers?: {}, body?: object) => RequestInit;
export declare class Frost {
private readonly email;
private readonly password;
private readonly host;
private readonly timeout;
constructor(config: Configuration);
timeoutPromise(): Promise<Response>;
create(email?: string, password?: string): Promise<{
readonly token: string;
}>;
login(email?: string, password?: string): Promise<{
readonly token: string;
}>;
sendEmailVerifyAccount(token: string): Promise<string>;
verifyAccount(token: string): Promise<{
readonly token: string;
}>;
sendEmailForgotPassword(email?: string): Promise<string>;
changePassword(token: string, password: string, oldPassword: string): Promise<string>;
changePasswordWithToken(token: string, password: string): Promise<{
readonly token: string;
}>;
createWork(token: string, work: WorkAttributes): Promise<{
readonly workId: string;
}>;
getWork(token: string, workId: string): Promise<WorkAttributes>;
getWorks(token: string): Promise<ReadonlyArray<WorkAttributes>>;
getApiTokens(token: string): Promise<{
readonly apiTokens: ReadonlyArray<string>;
}>;
removeApiToken(token: string, tokenId: string): Promise<string>;
createApiToken(token: string, network?: Network): Promise<{
readonly apiToken: string;
}>;
getProfile(token: string): Promise<{
readonly createdAt: number;
readonly verified: boolean;
}>;
}
298 changes: 298 additions & 0 deletions dist/Frost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fetch = require("isomorphic-fetch");
const utils_1 = require("./utils/utils");
exports.getOptions = (method, headers = {}, body) => (Object.assign({ method, headers: new Headers(Object.assign({ 'Content-Type': 'application/json' }, headers)) }, (body && !utils_1.isEmptyObject(body) ? { body: utils_1.StringifySecure(body) } : {})));
class Frost {
constructor(config) {
this.email = config.email;
this.password = config.password;
this.host = config.host;
this.timeout = config.timeout || 10;
}
timeoutPromise() {
return new Promise((resolve, reject) => {
setTimeout(() => reject('That last request took too long. Please try again in a few seconds.'), 1000 * this.timeout);
});
}
create(email, password) {
const options = {
method: utils_1.Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
}),
body: utils_1.StringifySecure({
email: email || this.email,
password: password || this.password,
}),
};
const request = fetch(`${this.host}${utils_1.Path.ACCOUNTS}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
login(email, password) {
if (!this.host)
throw new Error('Should set the host url');
const options = {
method: utils_1.Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
}),
body: utils_1.StringifySecure({
email: email || this.email,
password: password || this.password,
}),
};
const request = fetch(`${this.host}${utils_1.Path.LOGIN}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
sendEmailVerifyAccount(token) {
const options = {
method: utils_1.Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
};
const request = fetch(`${this.host}${utils_1.Path.ACCOUNTS_VERIFY}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.text();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
verifyAccount(token) {
const options = {
method: utils_1.Method.GET,
headers: new Headers({
'Content-Type': 'application/json',
}),
};
const request = fetch(`${this.host}${utils_1.Path.ACCOUNTS_VERIFY}/${token}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
sendEmailForgotPassword(email) {
const options = {
method: utils_1.Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
}),
body: utils_1.StringifySecure({
email: email || this.email,
}),
};
const request = fetch(`${this.host}${utils_1.Path.PASSWORD_RESET}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.text();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
changePassword(token, password, oldPassword) {
const options = {
method: utils_1.Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
body: utils_1.StringifySecure({
password,
oldPassword,
}),
};
const request = fetch(`${this.host}${utils_1.Path.PASSWORD_CHANGE}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.text();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
changePasswordWithToken(token, password) {
const options = {
method: utils_1.Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
body: utils_1.StringifySecure({
password,
}),
};
const request = fetch(`${this.host}${utils_1.Path.PASSWORD_CHANGE_TOKEN}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
createWork(token, work) {
const options = {
method: utils_1.Method.POST,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
body: utils_1.StringifySecure(work),
};
const request = fetch(`${this.host}${utils_1.Path.WORKS}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
getWork(token, workId) {
const options = {
method: utils_1.Method.GET,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
};
const request = fetch(`${this.host}${utils_1.Path.WORKS}/${workId}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
getWorks(token) {
const options = {
method: utils_1.Method.GET,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
};
const request = fetch(`${this.host}${utils_1.Path.WORKS}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
getApiTokens(token) {
const options = {
method: utils_1.Method.GET,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
};
const request = fetch(`${this.host}${utils_1.Path.TOKENS}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
removeApiToken(token, tokenId) {
return __awaiter(this, void 0, void 0, function* () {
const options = {
method: utils_1.Method.DEL,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
};
const request = fetch(`${this.host}${utils_1.Path.TOKENS}/${tokenId}`, options);
const response = yield Promise.race([request, this.timeoutPromise()]);
if (response.ok)
return yield response.text();
throw yield response.text();
});
}
createApiToken(token, network) {
return __awaiter(this, void 0, void 0, function* () {
const options = exports.getOptions(utils_1.Method.POST, { token }, { network });
const request = fetch(`${this.host}${utils_1.Path.TOKENS}`, options);
const response = yield Promise.race([request, this.timeoutPromise()]);
if (response.ok)
return yield response.json();
throw yield response.text();
});
}
getProfile(token) {
const options = {
method: utils_1.Method.GET,
headers: new Headers({
'Content-Type': 'application/json',
token,
}),
};
const request = fetch(`${this.host}${utils_1.Path.ACCOUNTS_PROFILE}`, options);
return Promise.race([request, this.timeoutPromise()])
.then((value) => __awaiter(this, void 0, void 0, function* () {
if (value.ok)
return yield value.json();
throw yield value.text();
}))
.catch(e => {
throw e;
});
}
}
exports.Frost = Frost;
1 change: 1 addition & 0 deletions dist/Frost.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
Loading

0 comments on commit e685362

Please sign in to comment.