@l2-technology/sensei-client
Advanced tools
Comparing version 0.1.4 to 0.1.5
export interface SenseiClientConfig { | ||
basePath: string; | ||
macaroon?: string; | ||
token?: string; | ||
} | ||
@@ -23,2 +24,3 @@ export interface NodeStatus { | ||
macaroon: string; | ||
token: string; | ||
externalId: string; | ||
@@ -30,2 +32,3 @@ role: number; | ||
macaroon: string; | ||
token: string; | ||
alias: string; | ||
@@ -38,2 +41,19 @@ role: number; | ||
} | ||
export interface CreateAccessTokenParams { | ||
name: string; | ||
scope: string; | ||
expiresAt: number; | ||
singleUse: boolean; | ||
} | ||
export interface AccessToken { | ||
id: number; | ||
externalId: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
expiresAt: number; | ||
singleUse: boolean; | ||
name: string; | ||
token: string; | ||
scope: string; | ||
} | ||
export interface CreateNodeParams { | ||
@@ -94,2 +114,6 @@ username: string; | ||
} | ||
export interface GetAccessTokensResponse { | ||
tokens: AccessToken[]; | ||
pagination: PaginationResponse; | ||
} | ||
export interface GetChannelsResponse { | ||
@@ -165,6 +189,9 @@ channels: Channel[]; | ||
macaroon?: string; | ||
constructor({ basePath, macaroon }: SenseiClientConfig); | ||
token?: string; | ||
constructor({ basePath, macaroon, token }: SenseiClientConfig); | ||
setMacaroon(macaroon: string): void; | ||
setToken(token: string): void; | ||
request(input: RequestInfo, init: RequestInit): Promise<any>; | ||
post(url: string, body: Record<any, any>, additionalHeaders?: Record<any, any>): Promise<any>; | ||
delete(url: string, body: Record<any, any>, additionalHeaders?: Record<any, any>): Promise<any>; | ||
get(url: string): Promise<any>; | ||
@@ -177,2 +204,5 @@ getStatus(): Promise<NodeStatus>; | ||
stopAdmin(): Promise<void>; | ||
createAccessToken({ name, scope, singleUse, expiresAt }: CreateAccessTokenParams): Promise<AccessToken>; | ||
getAccessTokens({ page, searchTerm, take }: ListParams): Promise<GetAccessTokensResponse>; | ||
deleteAccessToken(id: number): Promise<void>; | ||
createNode({ username, alias, passphrase, start }: CreateNodeParams): Promise<NodeAuthInfo>; | ||
@@ -179,0 +209,0 @@ adminStartNode(pubkey: string, passphrase: string): Promise<NodeAuthInfo>; |
@@ -12,5 +12,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
class SenseiClient { | ||
constructor({ basePath, macaroon }) { | ||
constructor({ basePath, macaroon, token }) { | ||
this.basePath = basePath; | ||
this.macaroon = macaroon; | ||
this.token = token; | ||
} | ||
@@ -20,10 +21,16 @@ setMacaroon(macaroon) { | ||
} | ||
setToken(token) { | ||
this.token = token; | ||
} | ||
request(input, init) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!init.headers) { | ||
init.headers = {}; | ||
} | ||
if (this.macaroon && this.macaroon !== '') { | ||
if (!init.headers) { | ||
init.headers = {}; | ||
} | ||
init.headers = Object.assign(Object.assign({}, init.headers), { macaroon: this.macaroon }); | ||
} | ||
if (this.token && this.token !== '') { | ||
init.headers = Object.assign(Object.assign({}, init.headers), { token: this.token }); | ||
} | ||
return fetch(input, init) | ||
@@ -49,2 +56,10 @@ .then((res) => { | ||
} | ||
delete(url, body, additionalHeaders = {}) { | ||
return this.request(url, { | ||
method: 'DELETE', | ||
headers: Object.assign(Object.assign({}, additionalHeaders), { 'Content-Type': 'application/json' }), | ||
credentials: 'include', | ||
body: JSON.stringify(body), | ||
}); | ||
} | ||
get(url) { | ||
@@ -72,2 +87,3 @@ return this.request(url, { | ||
role: response.role, | ||
token: response.token, | ||
}; | ||
@@ -96,2 +112,37 @@ }); | ||
} | ||
createAccessToken({ name, scope, singleUse, expiresAt }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.post(`${this.basePath}/v1/tokens`, { | ||
name, | ||
scope, | ||
single_use: singleUse, | ||
expires_at: expiresAt, | ||
}); | ||
}); | ||
} | ||
getAccessTokens({ page, searchTerm, take }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { tokens, pagination } = yield this.get(`${this.basePath}/v1/tokens?page=${page}&take=${take}&query=${searchTerm}`); | ||
return { | ||
tokens: tokens.map((token) => { | ||
return { | ||
id: token.id, | ||
externalId: token.external_id, | ||
createdAt: token.created_at, | ||
updatedAt: token.updated_at, | ||
expiresAt: token.expires_at, | ||
singleUse: token.single_use, | ||
scope: token.scope, | ||
name: token.name, | ||
}; | ||
}), | ||
pagination, | ||
}; | ||
}); | ||
} | ||
deleteAccessToken(id) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.delete(`${this.basePath}/v1/tokens`, { id }); | ||
}); | ||
} | ||
createNode({ username, alias, passphrase, start }) { | ||
@@ -98,0 +149,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "@l2-technology/sensei-client", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "A javascript client for the Sensei HTTP API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
25558
620