lombongo-api-client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # lombongo-api-client
@@ -0,0 +1 @@
1
+ import s from"axios";class t{constructor(s){this.client=s}async createUser(s){const t=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",s,{},t)}async login(s){return this._loginFactory(s)}async _verifyToken(s){const t=this.client.lombongoIdBaseUrl;return this.client.request("post","/token",{token:s},{},t)}async _loginWithEmailAndPassword(s,t){const r=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{email:s,password:t},{},r)}async _loginWithUsernameAndPassword(s,t){const r=this.client.lombongoIdBaseUrl;return this.client.request("post","/users",{username:s,password:t},{},r)}_loginFactory(s){return s.email?this._loginWithEmailAndPassword(s.email,s.password):s.username?this._loginWithUsernameAndPassword(s.username,s.password):Promise.reject(new Error("Login credentials must include either an email or a username."))}}class r{constructor({baseUrl:s,token:r,lombongoIdBaseUrl:e}){this.baseUrl=s,this.token=r,this.lombongoIdBaseUrl=e,this.auth=new t(this)}static init(s){return r.instance?(s?.token&&(r.instance.token=s.token),s?.baseUrl&&(r.instance.baseUrl=s.baseUrl),s?.lombongoIdBaseUrl&&(r.instance.lombongoIdBaseUrl=s.lombongoIdBaseUrl),r.instance):(r.instance=new r(s),r.instance)}async request(t,r,e={},n={},i){const o=`${i||this.baseUrl}${r}`,a={...n,headers:{"Content-Type":"application/json",...this.token?{Authorization:`Bearer ${this.token}`}:{},...n.headers},method:t,url:o,...e&&{data:e}};return s(a)}setToken(s){this.token=s}}export{r as default};
@@ -0,0 +1,46 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+
3
+ type CreateUser = {
4
+ email: string;
5
+ password: string;
6
+ username: string;
7
+ fullname?: string;
8
+ };
9
+ type LoginParameter = {
10
+ email?: string;
11
+ password: string;
12
+ username?: string;
13
+ };
14
+ declare class Auth {
15
+ private client;
16
+ constructor(client: ApiClient);
17
+ createUser(user: CreateUser): Promise<object>;
18
+ login(credentials: LoginParameter): Promise<object>;
19
+ _verifyToken(token: string): Promise<object>;
20
+ _loginWithEmailAndPassword(email: string, password: string): Promise<object>;
21
+ _loginWithUsernameAndPassword(username: string, password: string): Promise<object>;
22
+ _loginFactory(credentials: LoginParameter): Promise<object>;
23
+ }
24
+
25
+ interface ApiClientOptions {
26
+ baseUrl: string;
27
+ lombongoIdBaseUrl: string;
28
+ token?: string;
29
+ }
30
+ interface CustomRequestInit extends Omit<AxiosRequestConfig, "headers"> {
31
+ headers?: Record<string, string>;
32
+ }
33
+ type Method = "get" | "post";
34
+ declare class ApiClient {
35
+ private static instance;
36
+ private token?;
37
+ baseUrl: string;
38
+ lombongoIdBaseUrl: string;
39
+ auth: Auth;
40
+ private constructor();
41
+ static init(options: ApiClientOptions): ApiClient;
42
+ request(method: Method, endpoint: string, body?: object, options?: CustomRequestInit, overrideBaseUrl?: string): Promise<object>;
43
+ setToken(token: string): void;
44
+ }
45
+
46
+ export { ApiClient as default };
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "lombongo-api-client",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "dist/esm/base.js",
7
+ "module": "dist/esm/base.js",
8
+ "types": "dist/types.d.ts",
9
+ "scripts": {
10
+ "test": "jest ",
11
+ "lint": "eslint .",
12
+ "lint-fix": "eslint . --fix",
13
+ "prettier": "prettier --write \"**/*.+(ts|js|json|css|md)\"",
14
+ "prettier-check": "prettier --check \"**/*.+(ts|js|json|css|md)\"",
15
+ "pretty": "npm run prettier && npm run lint-fix",
16
+ "type-check": "tsc -p tsconfig.json -noEmit",
17
+ "prepare": "npm run build",
18
+ "build": "rimraf ./dist && npm run type-check && rollup -c",
19
+ "build-dev": "ENV=DEV npm run build",
20
+ "build-prod": "ENV=PROD npm run build",
21
+ "watch": "rimraf ./dist && npm run type-check && ENV=DEV rollup -c -w",
22
+ "watch-cjs": "WATCH_MODE=CJS npm run watch",
23
+ "watch-esm": "WATCH_MODE=ESM npm run watch",
24
+ "watch-bundle": "WATCH_MODE=BUNDLE npm run watch",
25
+ "serve": "http-server --cors -a localhost ./dist/bundle"
26
+ },
27
+ "author": "",
28
+ "license": "ISC",
29
+ "dependencies": {
30
+ "@types/jest": "^29.5.12",
31
+ "axios": "^1.6.7",
32
+ "jest": "^29.7.0",
33
+ "ts-jest": "^29.1.2",
34
+ "ts-node": "^10.9.2"
35
+ },
36
+ "files": [
37
+ "dist/esm/*.js",
38
+ "dist/types.d.ts"
39
+ ],
40
+ "devDependencies": {
41
+ "@rollup/plugin-commonjs": "^25.0.7",
42
+ "@rollup/plugin-replace": "^5.0.5",
43
+ "@rollup/plugin-terser": "^0.4.4",
44
+ "@rollup/plugin-typescript": "^11.1.6",
45
+ "@typescript-eslint/eslint-plugin": "^7.7.0",
46
+ "@typescript-eslint/parser": "^7.7.0",
47
+ "esbuild": "^0.17.19",
48
+ "eslint": "^8.42.0",
49
+ "eslint-config-prettier": "^8.8.0",
50
+ "eslint-plugin-prettier": "^4.2.1",
51
+ "http-server": "^14.1.1",
52
+ "prettier": "^2.8.8",
53
+ "rollup": "^4.12.1",
54
+ "rollup-plugin-dts": "^6.1.0",
55
+ "rollup-plugin-esbuild": "^6.1.1",
56
+ "rollup-plugin-modify": "^3.0.0",
57
+ "rollup-plugin-terser": "^7.0.2",
58
+ "tslib": "^2.6.2",
59
+ "typescript": "^5.3.3"
60
+ }
61
+ }