@veritree/services 2.25.1 → 2.26.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.25.1",
3
+ "version": "2.26.1",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -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,31 @@ 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
+ const config = getNuxtRuntimeConfig();
24
+
25
+ return config?.public?.API_VERITREE_VERSION ||
26
+ process?.env?.API_VERITREE_VERSION ||
27
+ "5.0.0";
28
+ }
29
+
5
30
  /**
6
31
  * Adds a version parameter to a URL if it does not already have one.
7
32
  * If an environment variable called API_VERITREE_VERSION is defined, its value is used as the version,
@@ -22,7 +47,7 @@ function addVersionParam(url) {
22
47
  }
23
48
 
24
49
  // Use environment variable if available, otherwise use default version
25
- const version = process.env.API_VERITREE_VERSION || "5.0.0";
50
+ const version = getVersion();
26
51
 
27
52
  // Append version parameter to URL
28
53
  const urlVersionParam = url.includes("?")
@@ -74,7 +99,13 @@ function getConfig(method, data, as) {
74
99
 
75
100
  export default class Api {
76
101
  constructor(resource) {
77
- this.baseUrl = process.env ? `${process.env.API_VERITREE_URL}/api` : null;
102
+ const nuxtConfig = getNuxtRuntimeConfig();
103
+ const url =
104
+ nuxtConfig?.public?.API_VERITREE_URL ||
105
+ process?.env?.API_VERITREE_URL ||
106
+ null;
107
+
108
+ this.baseUrl = url + "/api";
78
109
  this.resource = resource ? resource : "";
79
110
  this.orgId = null;
80
111
  this.orgType = null;
@@ -200,9 +231,17 @@ export default class Api {
200
231
  }
201
232
 
202
233
  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}`;
234
+ if (this.orgId) {
235
+ orgIdParam = `org_id=${this.orgId}`;
236
+ }
237
+
238
+ if (this.orgType) {
239
+ orgTypeParam = `&org_type=${this.orgType}`;
240
+ }
241
+
242
+ if (args && args.orgType) {
243
+ orgTypeParam = `&org_type=${args.orgType}`;
244
+ }
206
245
  }
207
246
 
208
247
  return `?${orgIdParam}${orgTypeParam}${createParamsStringFromArgs(args)}`;