pukaad-ui-lib 1.271.0 → 1.271.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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
3
  "configKey": "pukaadUI",
4
- "version": "1.271.0",
4
+ "version": "1.271.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -5,7 +5,6 @@ declare const __VLS_export: import("vue").DefineComponent<PickerOptionMenuUserPr
5
5
  "blog-unpin": () => any;
6
6
  "blog-pin": () => any;
7
7
  "blog-delete": () => any;
8
- "profile-name-updated": (name: string) => any;
9
8
  "profile-edit": () => any;
10
9
  "profile-share": () => any;
11
10
  "profile-follower-delete": () => any;
@@ -18,13 +17,13 @@ declare const __VLS_export: import("vue").DefineComponent<PickerOptionMenuUserPr
18
17
  "review-edit": () => any;
19
18
  "review-delete": () => any;
20
19
  archive: () => any;
20
+ "profile-name-updated": (name: string) => any;
21
21
  }, string, import("vue").PublicProps, Readonly<PickerOptionMenuUserProps> & Readonly<{
22
22
  "onBlog-edit"?: (() => any) | undefined;
23
23
  "onReport-announce"?: (() => any) | undefined;
24
24
  "onBlog-unpin"?: (() => any) | undefined;
25
25
  "onBlog-pin"?: (() => any) | undefined;
26
26
  "onBlog-delete"?: (() => any) | undefined;
27
- "onProfile-name-updated"?: ((name: string) => any) | undefined;
28
27
  "onProfile-edit"?: (() => any) | undefined;
29
28
  "onProfile-share"?: (() => any) | undefined;
30
29
  "onProfile-follower-delete"?: (() => any) | undefined;
@@ -37,6 +36,7 @@ declare const __VLS_export: import("vue").DefineComponent<PickerOptionMenuUserPr
37
36
  "onReview-edit"?: (() => any) | undefined;
38
37
  "onReview-delete"?: (() => any) | undefined;
39
38
  onArchive?: (() => any) | undefined;
39
+ "onProfile-name-updated"?: ((name: string) => any) | undefined;
40
40
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
41
41
  declare const _default: typeof __VLS_export;
42
42
  export default _default;
@@ -5,7 +5,6 @@ declare const __VLS_export: import("vue").DefineComponent<PickerOptionMenuUserPr
5
5
  "blog-unpin": () => any;
6
6
  "blog-pin": () => any;
7
7
  "blog-delete": () => any;
8
- "profile-name-updated": (name: string) => any;
9
8
  "profile-edit": () => any;
10
9
  "profile-share": () => any;
11
10
  "profile-follower-delete": () => any;
@@ -18,13 +17,13 @@ declare const __VLS_export: import("vue").DefineComponent<PickerOptionMenuUserPr
18
17
  "review-edit": () => any;
19
18
  "review-delete": () => any;
20
19
  archive: () => any;
20
+ "profile-name-updated": (name: string) => any;
21
21
  }, string, import("vue").PublicProps, Readonly<PickerOptionMenuUserProps> & Readonly<{
22
22
  "onBlog-edit"?: (() => any) | undefined;
23
23
  "onReport-announce"?: (() => any) | undefined;
24
24
  "onBlog-unpin"?: (() => any) | undefined;
25
25
  "onBlog-pin"?: (() => any) | undefined;
26
26
  "onBlog-delete"?: (() => any) | undefined;
27
- "onProfile-name-updated"?: ((name: string) => any) | undefined;
28
27
  "onProfile-edit"?: (() => any) | undefined;
29
28
  "onProfile-share"?: (() => any) | undefined;
30
29
  "onProfile-follower-delete"?: (() => any) | undefined;
@@ -37,6 +36,7 @@ declare const __VLS_export: import("vue").DefineComponent<PickerOptionMenuUserPr
37
36
  "onReview-edit"?: (() => any) | undefined;
38
37
  "onReview-delete"?: (() => any) | undefined;
39
38
  onArchive?: (() => any) | undefined;
39
+ "onProfile-name-updated"?: ((name: string) => any) | undefined;
40
40
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
41
41
  declare const _default: typeof __VLS_export;
42
42
  export default _default;
@@ -1,8 +1,73 @@
1
- import { useRuntimeConfig, useCookie } from "nuxt/app";
1
+ import { useRuntimeConfig, useCookie, useRequestURL, useState } from "nuxt/app";
2
2
  import { $fetch } from "ofetch";
3
+ const provinceIdByHostCache = /* @__PURE__ */ new Map();
4
+ const provinceIdByHostPromise = /* @__PURE__ */ new Map();
5
+ const normalizeDomain = (value) => {
6
+ const input = value.trim().toLowerCase();
7
+ if (!input) return "";
8
+ try {
9
+ return new URL(input.includes("://") ? input : `https://${input}`).hostname;
10
+ } catch {
11
+ return input.split("/")[0]?.split(":")[0] || "";
12
+ }
13
+ };
14
+ const getCurrentHost = () => {
15
+ if (typeof window !== "undefined") {
16
+ return normalizeDomain(window.location.hostname);
17
+ }
18
+ try {
19
+ return normalizeDomain(useRequestURL().hostname);
20
+ } catch {
21
+ return "";
22
+ }
23
+ };
24
+ const resolveProvinceIdByHost = async (host, baseURL) => {
25
+ if (!host) return null;
26
+ if (provinceIdByHostCache.has(host)) {
27
+ return provinceIdByHostCache.get(host) ?? null;
28
+ }
29
+ const activePromise = provinceIdByHostPromise.get(host);
30
+ if (activePromise) return activePromise;
31
+ const promise = (async () => {
32
+ const response = await $fetch("/api/master/address/provinces", {
33
+ baseURL,
34
+ query: { page_size: 100 }
35
+ });
36
+ const provinces = response.data ?? [];
37
+ const province = provinces.find((item) => {
38
+ return normalizeDomain(String(item.domain || "")) === host;
39
+ });
40
+ const provinceId = province?.id ? String(province.id) : null;
41
+ provinceIdByHostCache.set(host, provinceId);
42
+ return provinceId;
43
+ })();
44
+ provinceIdByHostPromise.set(host, promise);
45
+ try {
46
+ return await promise;
47
+ } catch {
48
+ provinceIdByHostCache.set(host, null);
49
+ return null;
50
+ } finally {
51
+ provinceIdByHostPromise.delete(host);
52
+ }
53
+ };
54
+ const resolveProvinceId = async (provinceIdState, host, baseURL, configProvinceId) => {
55
+ if (provinceIdState.value) {
56
+ return String(provinceIdState.value);
57
+ }
58
+ const provinceIdByHost = await resolveProvinceIdByHost(host, baseURL);
59
+ if (provinceIdByHost) {
60
+ provinceIdState.value = provinceIdByHost;
61
+ return provinceIdByHost;
62
+ }
63
+ return configProvinceId ? String(configProvinceId) : "";
64
+ };
3
65
  export const useApi = () => {
4
66
  const config = useRuntimeConfig();
5
67
  const baseURL = config.public.BASE_URL_API;
68
+ const provinceIdState = useState("pukaad:province-id", () => null);
69
+ const currentHost = getCurrentHost();
70
+ const configProvinceId = config.public.APP_PROVINCE_ID;
6
71
  const { APP_TYPE } = config.public;
7
72
  const secId = useCookie(
8
73
  APP_TYPE === "OFFICE" ? "OFFICE_SEC_ID" : "SEC_ID"
@@ -13,13 +78,18 @@ export const useApi = () => {
13
78
  Accept: "application/json"
14
79
  },
15
80
  // Interceptors
16
- onRequest({ request, options }) {
81
+ async onRequest({ options }) {
17
82
  const headers = new Headers(options.headers);
18
83
  const token = secId.value;
19
84
  if (token) {
20
85
  headers.set("Authorization", `Bearer ${token}`);
21
86
  }
22
- const provinceId = config.public.APP_PROVINCE_ID;
87
+ const provinceId = await resolveProvinceId(
88
+ provinceIdState,
89
+ currentHost,
90
+ baseURL,
91
+ configProvinceId
92
+ );
23
93
  if (provinceId) {
24
94
  headers.set("X-Province-ID", provinceId);
25
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pukaad-ui-lib",
3
- "version": "1.271.0",
3
+ "version": "1.271.2",
4
4
  "description": "pukaad-ui for MeMSG",
5
5
  "repository": {
6
6
  "type": "git",