@workerbase/sdk
Advanced tools
Comparing version 0.1.3 to 0.1.4-1.0
@@ -11,10 +11,11 @@ import { Resources } from './resources'; | ||
} | ||
export interface Workerbase extends Resources { | ||
export interface WorkerbaseSdk extends Resources { | ||
_api: API; | ||
PACKAGE_VERSION: string; | ||
} | ||
export declare class Workerbase { | ||
export declare class WorkerbaseSdk { | ||
PACKAGE_VERSION: string; | ||
_api: API; | ||
constructor(config: AuthOptions); | ||
constructor(); | ||
auth(config?: AuthOptions): void; | ||
_setApiField(key: any, value: any): void; | ||
@@ -24,3 +25,3 @@ getApiField(key: any): string; | ||
} | ||
export declare const WorkerbaseFactory: (config: AuthOptions) => Workerbase; | ||
export default WorkerbaseFactory; | ||
export declare const Workerbase: WorkerbaseSdk; | ||
export default Workerbase; |
@@ -6,6 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WorkerbaseFactory = exports.Workerbase = void 0; | ||
exports.Workerbase = exports.WorkerbaseSdk = void 0; | ||
var resources_1 = __importDefault(require("./resources")); | ||
var Workerbase = /** @class */ (function () { | ||
function Workerbase(config) { | ||
var WorkerbaseSdk = /** @class */ (function () { | ||
function WorkerbaseSdk() { | ||
this.PACKAGE_VERSION = '1.0.0'; | ||
@@ -17,23 +17,25 @@ this._api = { | ||
}; | ||
if (config.token) { | ||
this._prepResources(); | ||
} | ||
WorkerbaseSdk.prototype.auth = function (config) { | ||
if (config === null || config === void 0 ? void 0 : config.token) { | ||
this._setApiField('accesstoken', config.token); | ||
} | ||
else if (!this._api.accesstoken) { | ||
throw new Error('No ACCESS_TOKEN environemnt or option found'); | ||
throw new Error('No WB_ACCESS_TOKEN in environment or option found'); | ||
} | ||
if (config.url) { | ||
if (config === null || config === void 0 ? void 0 : config.url) { | ||
this._setApiField('url', config.url); | ||
} | ||
else if (!this._api.url) { | ||
throw new Error('No WB_API_URL environemnt or option found'); | ||
throw new Error('No WB_API_URL in environment or option found'); | ||
} | ||
this._prepResources(); | ||
} | ||
Workerbase.prototype._setApiField = function (key, value) { | ||
}; | ||
WorkerbaseSdk.prototype._setApiField = function (key, value) { | ||
this._api[key] = value; | ||
}; | ||
Workerbase.prototype.getApiField = function (key) { | ||
WorkerbaseSdk.prototype.getApiField = function (key) { | ||
return this._api[key]; | ||
}; | ||
Workerbase.prototype._prepResources = function () { | ||
WorkerbaseSdk.prototype._prepResources = function () { | ||
var _this = this; | ||
@@ -44,11 +46,10 @@ Object.keys(resources_1.default).forEach(function (name) { | ||
}; | ||
return Workerbase; | ||
return WorkerbaseSdk; | ||
}()); | ||
exports.Workerbase = Workerbase; | ||
exports.WorkerbaseFactory = function (config) { | ||
return new Workerbase(config); | ||
}; | ||
exports.default = exports.WorkerbaseFactory; | ||
module.exports = exports.WorkerbaseFactory; | ||
module.exports.default = exports.WorkerbaseFactory; | ||
exports.WorkerbaseSdk = WorkerbaseSdk; | ||
exports.Workerbase = new WorkerbaseSdk(); | ||
exports.default = exports.Workerbase; | ||
module.exports = exports.Workerbase; | ||
module.exports.Workerbase = exports.Workerbase; | ||
module.exports.default = exports.Workerbase; | ||
//# sourceMappingURL=index.js.map |
@@ -12,7 +12,7 @@ import { DatabasesSDK } from './resources/Databases'; | ||
declare const _default: { | ||
databases: (workerbase: import(".").Workerbase, parentAPIPath?: string) => void; | ||
roles: (workerbase: import(".").Workerbase, parentAPIPath?: string) => void; | ||
skills: (workerbase: import(".").Workerbase, parentAPIPath?: string) => void; | ||
users: (workerbase: import(".").Workerbase, parentAPIPath?: string) => void; | ||
databases: (workerbase: import(".").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
roles: (workerbase: import(".").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
skills: (workerbase: import(".").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
users: (workerbase: import(".").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
}; | ||
export default _default; |
@@ -11,3 +11,3 @@ import { DatabaseItem, ItemPayload, DatabaseItemPOST } from '../types/databaseItems'; | ||
} | ||
declare const _default: (workerbase: import("..").Workerbase, parentAPIPath?: string) => void; | ||
declare const _default: (workerbase: import("..").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
export default _default; |
@@ -12,3 +12,3 @@ import { Database, DatabasePOST, DatabasePUT } from '../types/databases'; | ||
}>; | ||
declare const _default: (workerbase: import("..").Workerbase, parentAPIPath?: string) => void; | ||
declare const _default: (workerbase: import("..").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
export default _default; |
@@ -8,3 +8,3 @@ import { Role, RolePUT, RolePOST } from '../types/roles'; | ||
}>; | ||
declare const _default: (workerbase: import("..").Workerbase, parentAPIPath?: string) => void; | ||
declare const _default: (workerbase: import("..").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
export default _default; |
@@ -8,3 +8,3 @@ import { Skill, SkillPUT, SkillPOST } from '../types/skills'; | ||
}>; | ||
declare const _default: (workerbase: import("..").Workerbase, parentAPIPath?: string) => void; | ||
declare const _default: (workerbase: import("..").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
export default _default; |
@@ -8,3 +8,3 @@ import { User, UserPUT, UserPOST } from '../types/users'; | ||
}>; | ||
declare const _default: (workerbase: import("..").Workerbase, parentAPIPath?: string) => void; | ||
declare const _default: (workerbase: import("..").WorkerbaseSdk, parentAPIPath?: string) => void; | ||
export default _default; |
@@ -5,4 +5,4 @@ export interface ListOptions { | ||
sort?: string; | ||
order?: string; | ||
order?: 'desc' | 'asc'; | ||
fields?: string; | ||
} |
@@ -1,4 +0,4 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { API } from '..'; | ||
export declare const doRequest: (api: API, endpoint: string, options?: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any>>; | ||
export declare const doRequest: (api: API, endpoint: string, options?: AxiosRequestConfig) => Promise<AxiosResponse<any>>; | ||
export default doRequest; |
@@ -55,2 +55,3 @@ "use strict"; | ||
var axios_1 = __importDefault(require("axios")); | ||
var parseurl_1 = __importDefault(require("parseurl")); | ||
var apiVersion = 'v1'; | ||
@@ -60,3 +61,3 @@ exports.doRequest = function (api, endpoint, options) { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var response, err_1; | ||
var baseUrl, response, err_1; | ||
var _a, _b, _c, _d; | ||
@@ -66,8 +67,17 @@ return __generator(this, function (_e) { | ||
case 0: | ||
_e.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, axios_1.default(__assign({ url: api.url + "/api/" + apiVersion + "/" + endpoint, headers: __assign({ accesstoken: api.accesstoken, 'User-Agent': "workerbase-sdk (" + api.version + ")" }, options.headers), method: 'GET' }, options))]; | ||
if (!api.url) { | ||
throw new Error('No WB_API_URL in environment or option found'); | ||
} | ||
if (!api.accesstoken) { | ||
throw new Error('No WB_ACCESS_TOKEN in environment or option found'); | ||
} | ||
_e.label = 1; | ||
case 1: | ||
_e.trys.push([1, 3, , 4]); | ||
baseUrl = parseurl_1.default({ url: api.url }).href; | ||
return [4 /*yield*/, axios_1.default(__assign({ url: baseUrl + "api/" + apiVersion + "/" + endpoint, headers: __assign({ accesstoken: api.accesstoken, 'User-Agent': "workerbase-sdk (" + api.version + ")" }, options.headers), method: 'GET' }, options))]; | ||
case 2: | ||
response = _e.sent(); | ||
return [2 /*return*/, response]; | ||
case 2: | ||
case 3: | ||
err_1 = _e.sent(); | ||
@@ -77,3 +87,3 @@ throw new Error(((_a = err_1.response) === null || _a === void 0 ? void 0 : _a.status) + " " + (JSON.stringify((_c = (_b = err_1.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.errorMessage) || | ||
err_1.message)); | ||
case 3: return [2 /*return*/]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -80,0 +90,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { Workerbase, API } from '..'; | ||
import { WorkerbaseSdk, API } from '..'; | ||
import { ListOptions } from '../types/pagination'; | ||
@@ -36,4 +36,4 @@ export declare enum BasicMethods { | ||
}) => Function>; | ||
childApis?: Record<string, (workerbase: Workerbase, parentAPIPath?: string) => void>; | ||
childApis?: Record<string, (workerbase: WorkerbaseSdk, parentAPIPath?: string) => void>; | ||
transformData?: (data: Item['GET']) => TransformedItem; | ||
}): (workerbase: Workerbase, parentAPIPath?: string) => void; | ||
}): (workerbase: WorkerbaseSdk, parentAPIPath?: string) => void; |
{ | ||
"name": "@workerbase/sdk", | ||
"version": "0.1.3", | ||
"version": "0.1.4-1.0", | ||
"description": "", | ||
@@ -48,4 +48,5 @@ "scripts": { | ||
"dependencies": { | ||
"axios": "^0.19.2" | ||
"axios": "^0.19.2", | ||
"parseurl": "^1.3.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
48896
796
159
2
+ Addedparseurl@^1.3.3
+ Addedparseurl@1.3.3(transitive)