@ramathibodi/nuxt-commons 0.1.28 → 0.1.29

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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.28",
7
+ "version": "0.1.29",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.3",
10
10
  "unbuild": "2.0.0"
@@ -1,11 +1,10 @@
1
- import { trimEnd, trimStart } from "lodash-es";
2
- import { useRuntimeConfig, useAuthentication } from "#imports";
3
1
  import { ofetch } from "ofetch";
2
+ import { trimEnd, trimStart } from "lodash-es";
3
+ import { useAuthentication, useRuntimeConfig } from "#imports";
4
4
  export function useApi() {
5
5
  const config = useRuntimeConfig();
6
- const nuxtApp = useNuxtApp();
7
6
  function urlBuilder(url) {
8
- let returnUrl = "";
7
+ let returnUrl;
9
8
  if (Array.isArray(url)) {
10
9
  if (url[0].toLowerCase() == "agent") url[0] = config?.public.WS_AGENT || config?.public.WS_DEVICE;
11
10
  returnUrl = url.join("/");
@@ -15,26 +14,30 @@ export function useApi() {
15
14
  if (returnUrl.startsWith("http://") || returnUrl.startsWith("https://")) return returnUrl;
16
15
  else return trimEnd(config?.public.WS_API, "/") + "/" + trimStart(returnUrl, "/");
17
16
  }
18
- function optionBuilder(method, body, params, options) {
19
- let returnOption = {
20
- method,
21
- body,
22
- query: params
23
- };
17
+ function optionBuilder(method, body, params, options = {}) {
24
18
  const headers = {
25
19
  "Content-Type": "application/json",
26
20
  "Accept": "application/json"
27
21
  };
28
- if (useAuthentication().keycloak?.token) {
29
- headers["Authorization"] = `Bearer ${useAuthentication().keycloak.token}`;
30
- }
31
- if (options) {
32
- options = Object.assign(options, returnOption);
33
- if (options.headers) options.headers = Object.assign(options.headers, headers);
34
- else options.headers = headers;
22
+ const { token } = useAuthentication().keycloak || {};
23
+ if (token) {
24
+ headers["Authorization"] = `Bearer ${token}`;
35
25
  }
36
- returnOption = Object.assign(returnOption, options);
37
- return returnOption;
26
+ const baseOptions = {
27
+ method,
28
+ body,
29
+ query: params,
30
+ headers
31
+ };
32
+ const finalHeaders = {
33
+ ...headers,
34
+ ...options.headers || {}
35
+ };
36
+ Object.assign(baseOptions, options);
37
+ return {
38
+ ...baseOptions,
39
+ headers: finalHeaders
40
+ };
38
41
  }
39
42
  function get(url, body, params, options) {
40
43
  return ofetch(urlBuilder(url), optionBuilder("GET", body, params, options));
@@ -7,7 +7,7 @@ export function buildFields(operationFields, fields, depth = 0) {
7
7
  if (!fields || fields.length == 0) fields = [...operationFields.fields];
8
8
  if (fields.includes("*")) {
9
9
  operationFields.fields.forEach((field) => {
10
- if (!fields.includes(field)) fields.push(field);
10
+ if (!fields.includes(field) && !field.toLowerCase().endsWith("base64") && !field.toLowerCase().endsWith("base64string")) fields.push(field);
11
11
  });
12
12
  fields.splice(fields.indexOf("*"), 1);
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -114,5 +114,5 @@
114
114
  "vitest": "^1.6.0",
115
115
  "vue-tsc": "2.0.29"
116
116
  },
117
- "packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4"
117
+ "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228"
118
118
  }