@veritree/services 1.2.0 → 1.5.0-0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "1.2.0",
3
+ "version": "1.5.0-0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,5 +1,14 @@
1
1
  import Api from "../helpers/api";
2
+ import Relations from "../helpers/relations";
3
+ class ImagesApi extends Api {
4
+ constructor(resource) {
5
+ super(resource);
6
+ this.resource = "images";
7
+ }
2
8
 
3
- const resource = "images";
9
+ relation(prefix, id) {
10
+ return Relations(this, prefix, id);
11
+ }
12
+ }
4
13
 
5
- export const Images = new Api(resource);
14
+ export const Images = new ImagesApi();
@@ -8,13 +8,13 @@ import { getSession } from "./session";
8
8
  * @param {string} url
9
9
  * @returns {string} url
10
10
  */
11
- function addEnvelopeParam(url) {
11
+ function addVersionArg(url) {
12
12
  if (!url || url.includes("_result=1")) return url;
13
13
 
14
14
  const urlHasArgs = url.includes("?");
15
- const urlEvenlopeArg = urlHasArgs ? "&_result=1" : "?_result=1";
15
+ const urlVersionArg = urlHasArgs ? "&_v=5.0.0" : "?_v=5.0.0";
16
16
 
17
- return `${url}${urlEvenlopeArg}`;
17
+ return `${url}${urlVersionArg}`;
18
18
  }
19
19
 
20
20
  /**
@@ -90,8 +90,8 @@ export default class Api {
90
90
  * @param {object} data
91
91
  * @returns {promise}
92
92
  */
93
- async create(data) {
94
- return await this.post(null, data);
93
+ async create(data, args) {
94
+ return await this.post(null, data, args);
95
95
  }
96
96
 
97
97
  /**
@@ -101,8 +101,8 @@ export default class Api {
101
101
  * @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
102
102
  * @returns {promise}
103
103
  */
104
- async update(id, data, as = "put") {
105
- const url = `${this.getUrl(id)}${this.getUrlParams()}`;
104
+ async update(id, data, as = "put", args) {
105
+ const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
106
106
  return await this.post(url, data, as);
107
107
  }
108
108
 
@@ -113,8 +113,8 @@ export default class Api {
113
113
  * @param {string} as - 'put' // necessary for updates because of how Laravel handles PUT requests
114
114
  * @returns {promise}
115
115
  */
116
- async delete(id) {
117
- const url = `${this.getUrl(id)}${this.getUrlParams()}`;
116
+ async delete(id, args) {
117
+ const url = `${this.getUrl(id)}${this.getUrlParams(args)}`;
118
118
  return await this.post(url, null, "delete");
119
119
  }
120
120
 
@@ -183,7 +183,7 @@ export default class Api {
183
183
  * @returns {object} envelope
184
184
  */
185
185
  async unWrap(url, method = "get", data, as) {
186
- url = addEnvelopeParam(url);
186
+ url = addVersionArg(url);
187
187
  const config = getConfig(method, data, as);
188
188
  const response = await fetch(url, config);
189
189