@elevenback/mdb-client
Advanced tools
Comparing version 0.1.1 to 0.2.0
type Options = { | ||
apiOrigin: string; | ||
apiOrigin?: string; | ||
token: string; | ||
}; | ||
declare class APIClient { | ||
private apiOrigin; | ||
constructor(options?: Options); | ||
private token; | ||
constructor(options: Options); | ||
getAtomValue(atomId: string): Promise<string>; | ||
updateAtomValue(atomId: string, value: string): Promise<void>; | ||
} | ||
declare function initMDBClient(options?: Options): APIClient; | ||
declare function initMDBClient(options: Options): APIClient; | ||
export default initMDBClient; |
@@ -10,8 +10,16 @@ "use strict"; | ||
this.apiOrigin = 'https://api.example.com'; | ||
this.token = ''; | ||
if (options === null || options === void 0 ? void 0 : options.apiOrigin) { | ||
this.apiOrigin = options.apiOrigin; | ||
} | ||
if (!options.token) { | ||
this.token = options.token; | ||
} | ||
} | ||
async getAtomValue(atomId) { | ||
const { data: { value } } = await axios_1.default.get(`${this.apiOrigin}/atom/${atomId}`); | ||
const { data: { value }, } = await axios_1.default.get(`${this.apiOrigin}/atom/${atomId}`, { | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
}); | ||
return value; | ||
@@ -22,2 +30,6 @@ } | ||
value, | ||
}, { | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
}); | ||
@@ -24,0 +36,0 @@ return; |
type Options = { | ||
apiOrigin: string; | ||
apiOrigin?: string; | ||
token: string; | ||
}; | ||
declare class APIClient { | ||
private apiOrigin; | ||
constructor(options?: Options); | ||
private token; | ||
constructor(options: Options); | ||
getAtomValue(atomId: string): Promise<string>; | ||
updateAtomValue(atomId: string, value: string): Promise<void>; | ||
} | ||
declare function initMDBClient(options?: Options): APIClient; | ||
declare function initMDBClient(options: Options): APIClient; | ||
export default initMDBClient; |
@@ -14,9 +14,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.apiOrigin = 'https://api.example.com'; | ||
this.token = ''; | ||
if (options === null || options === void 0 ? void 0 : options.apiOrigin) { | ||
this.apiOrigin = options.apiOrigin; | ||
} | ||
if (!options.token) { | ||
this.token = options.token; | ||
} | ||
} | ||
getAtomValue(atomId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data: { value } } = yield axios.get(`${this.apiOrigin}/atom/${atomId}`); | ||
const { data: { value }, } = yield axios.get(`${this.apiOrigin}/atom/${atomId}`, { | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
}); | ||
return value; | ||
@@ -29,2 +37,6 @@ }); | ||
value, | ||
}, { | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
}); | ||
@@ -31,0 +43,0 @@ return; |
{ | ||
"name": "@elevenback/mdb-client", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"main": "./dist/cjs/index.js", | ||
@@ -10,6 +10,8 @@ "module": "./dist/esm/index.js", | ||
"build:cjs": "tsc -p tsconfig.cjs.json", | ||
"build:esm": "tsc" | ||
"build:esm": "tsc", | ||
"format": "rome format ./src/ --write" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.3.5" | ||
"axios": "^1.3.5", | ||
"rome": "^0.10.1" | ||
}, | ||
@@ -16,0 +18,0 @@ "devDependencies": { |
import axios from 'axios'; | ||
type Options = { | ||
apiOrigin: string; | ||
} | ||
apiOrigin?: string; | ||
token: string; | ||
}; | ||
class APIClient { | ||
private apiOrigin: string = 'https://api.example.com'; | ||
constructor(options?: Options) { | ||
private token: string = ''; | ||
constructor(options: Options) { | ||
if (options?.apiOrigin) { | ||
this.apiOrigin = options.apiOrigin; | ||
} | ||
if (!options.token) { | ||
this.token = options.token; | ||
} | ||
} | ||
async getAtomValue(atomId: string) { | ||
const { data: { value } } = await axios.get<{ value: string }>(`${this.apiOrigin}/atom/${atomId}`); | ||
const { | ||
data: { value }, | ||
} = await axios.get<{ value: string }>(`${this.apiOrigin}/atom/${atomId}`, { | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
}); | ||
return value; | ||
@@ -21,5 +32,13 @@ } | ||
async updateAtomValue(atomId: string, value: string): Promise<void> { | ||
await axios.put<undefined>(`${this.apiOrigin}/atom/${atomId}`, { | ||
value, | ||
}); | ||
await axios.put<undefined>( | ||
`${this.apiOrigin}/atom/${atomId}`, | ||
{ | ||
value, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
}, | ||
); | ||
return; | ||
@@ -29,3 +48,3 @@ } | ||
function initMDBClient(options?: Options) { | ||
function initMDBClient(options: Options) { | ||
return new APIClient(options); | ||
@@ -32,0 +51,0 @@ } |
7828
10
241
2
+ Addedrome@^0.10.1
+ Added@rometools/cli-darwin-arm64@0.10.1(transitive)
+ Added@rometools/cli-darwin-x64@0.10.1(transitive)
+ Added@rometools/cli-linux-arm64@0.10.1(transitive)
+ Added@rometools/cli-linux-x64@0.10.1(transitive)
+ Added@rometools/cli-win32-arm64@0.10.1(transitive)
+ Added@rometools/cli-win32-x64@0.10.1(transitive)
+ Addedrome@0.10.1(transitive)