@iankibetsh/vue-streamline 1.0.0 → 1.0.2

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.
@@ -0,0 +1,33 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-node@v4
16
+ with:
17
+ node-version: 20
18
+ - run: npm ci
19
+ # - run: npm test
20
+
21
+ publish-npm:
22
+ needs: build
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-node@v4
27
+ with:
28
+ node-version: 20
29
+ registry-url: https://registry.npmjs.org/
30
+ - run: npm ci
31
+ - run: npm publish
32
+ env:
33
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/README.md CHANGED
@@ -5,7 +5,7 @@ Vue library for streamlining laravel backend services with @iankibet/streamline
5
5
  ## Installation
6
6
 
7
7
  ```sh
8
- npm install @iankibet/vue-streamline
8
+ npm install @iankibetsh/vue-streamline
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -18,9 +18,33 @@ import {streamline} from '@iankibetsh/vue-streamline'
18
18
 
19
19
  ```js
20
20
  Vue.use(streamline, {
21
- ustreamlineHeaders: {
21
+ streamlineHeaders: {
22
22
  // Add any headers you want to send with the request
23
23
  },
24
24
  streamlineUrl: 'http://localhost:8000/api/streamline' // The url to the streamline route
25
25
  })
26
- ```
26
+ ```
27
+
28
+
29
+ ## usage in vue component
30
+
31
+ ```js
32
+ import { useStreamline } from '@iankibet/vue-streamline'
33
+
34
+
35
+ const {service:tasksService} = useStreamline('tasks')
36
+
37
+ // call the service methods
38
+
39
+ tasksServices.getTasks().then(response => {
40
+ console.log(response)
41
+ })
42
+ ```
43
+
44
+
45
+ ## Getting url to an action/method in the service
46
+
47
+ You can get the url to an action/method in the service by calling the getActionUrl method on the service object passing the action name and any parameters
48
+ ```js
49
+ tasksService.getActionUrl('getTasks', {page: 1})
50
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/vue-streamline",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Vue library for streamlining laravel backend services with @iankibet/streamline composer package",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/App.vue CHANGED
@@ -1,9 +1,24 @@
1
1
  <script setup>
2
+ import useStreamline from './composables/useStreamline.js'
3
+
4
+ const {service:paybillService} = useStreamline('mpesa/paybill')
5
+
6
+ const tryDelete = (id)=>{
7
+ paybillService.deletePaybill(id).then(res=>{
8
+ reload.value++
9
+ shRepo.showToast('Paybill deleted')
10
+ }).catch(err=>{
11
+ console.log(err)
12
+ })
13
+
14
+ }
2
15
  </script>
3
16
 
4
17
  <template>
5
18
  <div>
6
- <h1>Streamline Framework</h1>
19
+ <h1 @click="tryDelete(1)">Streamline Framework</h1>
20
+ {{ paybillService.getActionUrl('addPaybill',2,4) }}
21
+
7
22
  </div>
8
23
  </template>
9
24
 
@@ -19,25 +19,28 @@ const useStreamline = stream => {
19
19
  formData = args[0]
20
20
  return service
21
21
  }
22
- const config = {
23
- headers: {
24
- ...streamlineHeaders
25
- }
26
- }
27
22
  const axios = Axios.create({
28
23
  headers: {
29
- ...config.headers
24
+ ...streamlineHeaders
30
25
  }
31
26
  })
27
+
32
28
  window.streamlineAxios = axios
33
- return axios.post(streamlineUrl, {
29
+ const postBody = {
34
30
  action,
35
31
  stream,
36
32
  ...formData,
37
- params: {
38
- ...args
39
- }
40
- })
33
+ }
34
+ const getUrlMethods = ['getUrl','getFullUrl','getActionUrl']
35
+ if(getUrlMethods.includes(action)) {
36
+ // return string url with postBody as query params
37
+ // flatten params object
38
+ // params are from args 1, unset the first arg
39
+ postBody.params = args.slice(1)
40
+ return streamlineUrl + '?' + new URLSearchParams(postBody).toString()
41
+ }
42
+ postBody.params = args
43
+ return axios.post(streamlineUrl, postBody)
41
44
  }
42
45
  }
43
46
  })
package/src/main.js CHANGED
@@ -1,5 +1,16 @@
1
1
  import { createApp } from 'vue'
2
2
  import './style.css'
3
3
  import App from './App.vue'
4
+ import streamline from './plugins/streamline.js'
4
5
 
5
- createApp(App).mount('#app')
6
+ const streamlineHeaders = {
7
+ Authorization: 'Bearer '
8
+ }
9
+ const streamlineUrl = 'streamline'
10
+ const app = createApp(App)
11
+ app.use(streamline,{
12
+ streamlineHeaders,
13
+ streamlineUrl
14
+ })
15
+
16
+ app.mount('#app')