Skip to content

Commit 307b75f

Browse files
committed
Initial commit
0 parents  commit 307b75f

20 files changed

+2508
-0
lines changed

.babelrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [ "@babel/preset-env" ],
3+
"plugins": [
4+
"@babel/plugin-proposal-object-rest-spread",
5+
"@babel/plugin-proposal-class-properties"
6+
]
7+
}

.eslintrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const eslintConfig = {
2+
parser: '@babel/eslint-parser',
3+
extends: ['prettier'],
4+
plugins: ['prettier'],
5+
env: {
6+
browser: true,
7+
},
8+
}
9+
10+
module.exports = eslintConfig

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.provisioned
2+
ansible/group_vars/all
3+
ansible/inventory/inventory
4+
ansible/roles/*
5+
ansible/site.yml
6+
!ansible/roles/.keep
7+
!ansible/roles/freenit
8+
build/
9+
cbsd.conf
10+
site.retry
11+
project.mk
12+
vars.mk
13+
14+
node_modules
15+
dist
16+
stats.html

.prettierrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
semi: false,
3+
singleQuote: true,
4+
}

LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BSD 2-Clause License
2+
3+
Copyright (c) 2021, Freenit
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SERVICE = axios
2+
REGGAE_PATH := /usr/local/share/reggae
3+
4+
.include <${REGGAE_PATH}/mk/service.mk>

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# axios

ansible/group_vars/.keep

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

ansible/inventory/.keep

Whitespace-only changes.

ansible/roles/.keep

Whitespace-only changes.

ansible/roles/freenit/tasks/main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: install freenit packages
3+
with_items: "{{ freenit_packages }}"
4+
package:
5+
name: "{{ item.name }}"

ansible/roles/freenit/vars/main.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
freenit_packages:
3+
- name: node
4+
- name: yarn

bin/test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/bin/sh

lib.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import axios from 'axios'
2+
3+
class Auth {
4+
constructor(api) {
5+
this.api = api
6+
}
7+
8+
login = async (email, password) => {
9+
const formData = new FormData()
10+
formData.append('username', email)
11+
formData.append('password', password)
12+
return await this.api.post('/auth/login', formData)
13+
}
14+
15+
logout = async () => await this.api.post('/auth/logout', {})
16+
}
17+
18+
class Me {
19+
constructor(api) {
20+
this.api = api
21+
}
22+
23+
get = async () => await this.api.get('/users/me')
24+
patch = async (data) => await this.api.patch('/users/me', data)
25+
}
26+
27+
class User {
28+
constructor(api) {
29+
this.api = api
30+
}
31+
32+
getList = async (Page = 0, PerPage = 10) =>
33+
await this.api.get('/users', {
34+
headers: { Page, PerPage },
35+
})
36+
37+
get = async (id) => await this.api.get(`/users/${id}`)
38+
patch = async (id, data) => await this.api.patch(`/users/${id}`, data)
39+
delete = async (id) => await this.api.delete(`/users/${id}`)
40+
}
41+
42+
export class API {
43+
constructor(prefix = '/api/v0', config = {}) {
44+
this.api = axios.create({
45+
baseURL: prefix,
46+
withCredentials: true,
47+
...config,
48+
})
49+
this.auth = new Auth(this)
50+
this.me = new Me(this)
51+
this.user = new User(this)
52+
}
53+
54+
get = async (...args) => {
55+
try {
56+
const response = await this.api.get(...args)
57+
return { ...response.data, ok: true }
58+
} catch (error) {
59+
return { ...error, ok: false }
60+
}
61+
}
62+
63+
patch = async (...args) => {
64+
try {
65+
const response = await this.api.patch(...args)
66+
return { ...response.data, ok: true }
67+
} catch (error) {
68+
return { ...error, ok: false }
69+
}
70+
}
71+
72+
post = async (...args) => {
73+
try {
74+
const response = await this.api.post(...args)
75+
return { ...response.data, ok: true }
76+
} catch (error) {
77+
return { ...error, ok: false }
78+
}
79+
}
80+
81+
delete = async (...args) => {
82+
try {
83+
const response = await this.api.delete(...args)
84+
return { ...response.data, ok: true }
85+
} catch (error) {
86+
return { ...error, ok: false }
87+
}
88+
}
89+
90+
errors = (response) => {
91+
const res = response.response
92+
const data = res && res.data && typeof res.data !== 'string' ? res.data : {}
93+
if (!data.message) {
94+
if (data.msg) {
95+
data.message = data.msg
96+
} else if (data.statusText) {
97+
data.message = data.statusText
98+
} else if (data.status) {
99+
data.message = data.status
100+
} else if (res.statusText) {
101+
data.message = res.statusText
102+
} else if (res.status) {
103+
data.message = res.status
104+
}
105+
}
106+
if (data.errors) {
107+
Object.getOwnPropertyNames(data.errors).forEach((property) => {
108+
if (property !== 'message') {
109+
data.errors[property] = data.errors[property].join(' ')
110+
}
111+
})
112+
}
113+
return data
114+
}
115+
}

package.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@freenit-framework/axios",
3+
"version": "0.0.27",
4+
"description": "Axios integration for Freenit",
5+
"main": "dist/index.cjs.js",
6+
"module": "dist/index.esm.js",
7+
"repository": "https://github.com/freenit-framework/axios.git",
8+
"author": "Goran Mekić <meka@tilda.center>",
9+
"license": "BSD-2-Clause",
10+
"private": false,
11+
"files": [
12+
"/dist"
13+
],
14+
"scripts": {
15+
"build": "rollup -c"
16+
},
17+
"dependencies": {
18+
"axios": "^0.22.0"
19+
},
20+
"devDependencies": {
21+
"@babel/core": "^7.15.8",
22+
"@babel/eslint-parser": "^7.15.8",
23+
"@babel/plugin-proposal-class-properties": "^7.14.5",
24+
"@babel/plugin-proposal-object-rest-spread": "^7.15.6",
25+
"@babel/preset-env": "^7.15.8",
26+
"@rollup/plugin-babel": "^5.3.0",
27+
"@rollup/plugin-commonjs": "^21.0.0",
28+
"@rollup/plugin-image": "^2.1.1",
29+
"@rollup/plugin-json": "^4.1.0",
30+
"@rollup/plugin-node-resolve": "^13.0.5",
31+
"eslint": "^8.0.0",
32+
"eslint-config-prettier": "^8.3.0",
33+
"eslint-plugin-prettier": "^4.0.0",
34+
"prettier": "^2.4.1",
35+
"rollup": "^2.58.0",
36+
"rollup-plugin-peer-deps-external": "^2.2.4",
37+
"rollup-plugin-terser": "^7.0.2",
38+
"rollup-plugin-visualizer": "^5.5.2"
39+
}
40+
}

provisioners.mk

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.include <${REGGAE_PATH}/mk/ansible.mk>

requirements.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- onelove-roles.freebsd-common

rollup.config.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import commonjs from '@rollup/plugin-commonjs'
2+
import { babel } from '@rollup/plugin-babel'
3+
import external from 'rollup-plugin-peer-deps-external'
4+
import resolve from '@rollup/plugin-node-resolve'
5+
import image from '@rollup/plugin-image'
6+
import visualizer from 'rollup-plugin-visualizer'
7+
import json from '@rollup/plugin-json'
8+
import { terser } from 'rollup-plugin-terser'
9+
import pkg from './package.json'
10+
11+
export default {
12+
input: './lib.js',
13+
output: [
14+
{
15+
file: pkg.main,
16+
format: 'cjs',
17+
sourcemap: true,
18+
},
19+
{
20+
file: pkg.module,
21+
format: 'esm',
22+
sourcemap: true,
23+
},
24+
],
25+
plugins: [
26+
json(),
27+
external(),
28+
resolve({ preferBuiltins: true }),
29+
terser(),
30+
commonjs({ ignoreDynamicRequires: true }),
31+
babel({ babelHelpers: 'bundled' }),
32+
image(),
33+
visualizer(),
34+
],
35+
}

templates/site.yml.tpl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- mode: ansible -*-
2+
# vi: set ft=ansible :
3+
4+
---
5+
- name: SERVICE provisioning
6+
hosts: SERVICE
7+
roles:
8+
- onelove-roles.freebsd-common
9+
- freenit

0 commit comments

Comments
 (0)