@veritree/services 2.25.0 → 2.26.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": "2.25.0",
3
+ "version": "2.26.0",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -5,6 +5,16 @@ class EvidenceApi extends Api {
5
5
  super(resource);
6
6
  this.resource = "evidence";
7
7
  }
8
+
9
+ async image(imageId, params) {
10
+ let url = `${this.getUrl()}/image/${imageId}${this.getUrlParams(params)}`
11
+ return await this.get(url);
12
+ }
13
+
14
+ async attachment(attachementId, params) {
15
+ let url = `${this.getUrl()}/attachment/${attachementId}${this.getUrlParams(params)}`
16
+ return await this.get(url);
17
+ }
8
18
  }
9
19
 
10
20
  export const Evidence = new EvidenceApi();
@@ -43,9 +43,9 @@ class SubsitesApi extends Api {
43
43
  };
44
44
  }
45
45
 
46
- stats(subsite, args) {
46
+ stats(subsiteId, args) {
47
47
  const all = async () => {
48
- const url = `${this.getUrl()}/${subsite}/stats${this.getUrlParams(args)}`;
48
+ const url = `${this.getUrl()}/${subsiteId}/stats${this.getUrlParams(args)}`;
49
49
  return await this.get(url);
50
50
  };
51
51
 
@@ -2,6 +2,29 @@ import { getCookie } from "./cookies";
2
2
  import { createParamsStringFromArgs } from "../utils/args";
3
3
  import { getSession } from "./session";
4
4
 
5
+ /**
6
+ * Returns the runtime configuration object for Nuxt 3.
7
+ *
8
+ * Note:
9
+ * This function should only be used with Nuxt 3.
10
+ * For Nuxt 2, the environment variables will work as expected.
11
+ *
12
+ * @returns {Object|null} - The runtime configuration object, or null if it's not available.
13
+ */
14
+ function getNuxtRuntimeConfig() {
15
+ if (typeof useRuntimeConfig === "function") {
16
+ return useRuntimeConfig();
17
+ } else {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ function getVersion() {
23
+ return getNuxtRuntimeConfig()?.public?.API_VERITREE_VERSION ||
24
+ process?.env?.API_VERITREE_VERSION ||
25
+ "5.0.0";
26
+ }
27
+
5
28
  /**
6
29
  * Adds a version parameter to a URL if it does not already have one.
7
30
  * If an environment variable called API_VERITREE_VERSION is defined, its value is used as the version,
@@ -22,7 +45,7 @@ function addVersionParam(url) {
22
45
  }
23
46
 
24
47
  // Use environment variable if available, otherwise use default version
25
- const version = process.env.API_VERITREE_VERSION || "5.0.0";
48
+ const version = getVersion();
26
49
 
27
50
  // Append version parameter to URL
28
51
  const urlVersionParam = url.includes("?")
@@ -74,7 +97,13 @@ function getConfig(method, data, as) {
74
97
 
75
98
  export default class Api {
76
99
  constructor(resource) {
77
- this.baseUrl = process.env ? `${process.env.API_VERITREE_URL}/api` : null;
100
+ const nuxtConfig = getNuxtRuntimeConfig();
101
+ const url =
102
+ nuxtConfig?.public?.API_VERITREE_URL ||
103
+ process?.env?.API_VERITREE_URL ||
104
+ null;
105
+
106
+ this.baseUrl = url + "/api";
78
107
  this.resource = resource ? resource : "";
79
108
  this.orgId = null;
80
109
  this.orgType = null;
@@ -200,9 +229,17 @@ export default class Api {
200
229
  }
201
230
 
202
231
  if (!isOrgLess && !isOrgAs) {
203
- if (this.orgId) orgIdParam = `org_id=${this.orgId}`;
204
- if (this.orgType) orgTypeParam = `&org_type=${this.orgType}`;
205
- if (args && args.orgType) orgTypeParam = `&org_type=${args.orgType}`;
232
+ if (this.orgId) {
233
+ orgIdParam = `org_id=${this.orgId}`;
234
+ }
235
+
236
+ if (this.orgType) {
237
+ orgTypeParam = `&org_type=${this.orgType}`;
238
+ }
239
+
240
+ if (args && args.orgType) {
241
+ orgTypeParam = `&org_type=${args.orgType}`;
242
+ }
206
243
  }
207
244
 
208
245
  return `?${orgIdParam}${orgTypeParam}${createParamsStringFromArgs(args)}`;