@ramathibodi/nuxt-commons 4.0.17 → 4.0.19

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.
Files changed (40) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/device/IdCardButton.d.vue.ts +2 -2
  3. package/dist/runtime/components/device/IdCardButton.vue.d.ts +2 -2
  4. package/dist/runtime/components/device/IdCardWebSocket.vue +7 -1
  5. package/dist/runtime/components/dialog/Confirm.d.vue.ts +1 -1
  6. package/dist/runtime/components/dialog/Confirm.vue.d.ts +1 -1
  7. package/dist/runtime/components/dialog/ImportResult.d.vue.ts +2 -2
  8. package/dist/runtime/components/dialog/ImportResult.vue.d.ts +2 -2
  9. package/dist/runtime/components/dialog/default/Confirm.d.vue.ts +2 -2
  10. package/dist/runtime/components/dialog/default/Confirm.vue.d.ts +2 -2
  11. package/dist/runtime/components/dialog/default/Notify.d.vue.ts +3 -3
  12. package/dist/runtime/components/dialog/default/Notify.vue.d.ts +3 -3
  13. package/dist/runtime/components/dialog/default/VerifyUser.d.vue.ts +2 -2
  14. package/dist/runtime/components/dialog/default/VerifyUser.vue.d.ts +2 -2
  15. package/dist/runtime/components/form/DateTime.d.vue.ts +1 -1
  16. package/dist/runtime/components/form/DateTime.vue.d.ts +1 -1
  17. package/dist/runtime/components/form/Login.d.vue.ts +1 -1
  18. package/dist/runtime/components/form/Login.vue.d.ts +1 -1
  19. package/dist/runtime/components/form/Pad.d.vue.ts +1 -1
  20. package/dist/runtime/components/form/Pad.vue.d.ts +1 -1
  21. package/dist/runtime/components/form/images/Capture.d.vue.ts +1 -1
  22. package/dist/runtime/components/form/images/Capture.vue.d.ts +1 -1
  23. package/dist/runtime/components/label/Field.d.vue.ts +1 -1
  24. package/dist/runtime/components/label/Field.vue.d.ts +1 -1
  25. package/dist/runtime/components/model/Table.vue +5 -0
  26. package/dist/runtime/components/model/iterator.vue +6 -0
  27. package/dist/runtime/composables/api.d.ts +14 -0
  28. package/dist/runtime/composables/api.js +18 -3
  29. package/dist/runtime/composables/apiModel.js +1 -0
  30. package/dist/runtime/composables/clientConfig.d.ts +17 -0
  31. package/dist/runtime/composables/clientConfig.js +18 -6
  32. package/dist/runtime/composables/document/templateInputTypes.js +1 -0
  33. package/dist/runtime/composables/graphqlModel.js +1 -0
  34. package/dist/runtime/composables/hostAgent.d.ts +40 -0
  35. package/dist/runtime/composables/hostAgent.js +56 -2
  36. package/dist/runtime/labs/Calendar.d.vue.ts +4 -4
  37. package/dist/runtime/labs/Calendar.vue.d.ts +4 -4
  38. package/dist/runtime/plugins/clientConfig.js +30 -17
  39. package/dist/runtime/types/clientConfig.d.ts +17 -4
  40. package/package.json +1 -1
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^4.3.1"
6
6
  },
7
- "version": "4.0.17",
7
+ "version": "4.0.19",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -17,16 +17,16 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
17
17
  reader: null;
18
18
  disableWhileLoading: boolean;
19
19
  }>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
- error: (err: unknown) => any;
21
20
  loading: (loading: boolean) => any;
21
+ error: (err: unknown) => any;
22
22
  read: (payload: PatientRegisterPayload) => any;
23
23
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
24
24
  withPhoto: boolean;
25
25
  reader: null;
26
26
  disableWhileLoading: boolean;
27
27
  }>>> & Readonly<{
28
- onError?: ((err: unknown) => any) | undefined;
29
28
  onLoading?: ((loading: boolean) => any) | undefined;
29
+ onError?: ((err: unknown) => any) | undefined;
30
30
  onRead?: ((payload: PatientRegisterPayload) => any) | undefined;
31
31
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
32
32
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
@@ -17,16 +17,16 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
17
17
  reader: null;
18
18
  disableWhileLoading: boolean;
19
19
  }>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
- error: (err: unknown) => any;
21
20
  loading: (loading: boolean) => any;
21
+ error: (err: unknown) => any;
22
22
  read: (payload: PatientRegisterPayload) => any;
23
23
  }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<Props>, {
24
24
  withPhoto: boolean;
25
25
  reader: null;
26
26
  disableWhileLoading: boolean;
27
27
  }>>> & Readonly<{
28
- onError?: ((err: unknown) => any) | undefined;
29
28
  onLoading?: ((loading: boolean) => any) | undefined;
29
+ onError?: ((err: unknown) => any) | undefined;
30
30
  onRead?: ((payload: PatientRegisterPayload) => any) | undefined;
31
31
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
32
32
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
@@ -94,7 +94,13 @@ const off = host.onIdCardWsEvent((ev) => {
94
94
  });
95
95
  onMounted(() => {
96
96
  mounted.value = true;
97
- if (props.autoConnect) connectAndSubscribe();
97
+ if (props.autoConnect) {
98
+ try {
99
+ connectAndSubscribe();
100
+ } catch (e) {
101
+ emit("error", e);
102
+ }
103
+ }
98
104
  });
99
105
  onBeforeUnmount(() => {
100
106
  mounted.value = false;
@@ -21,9 +21,9 @@ declare const __VLS_base: import("vue").DefineComponent<DialogProps, {}, {}, {},
21
21
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
22
22
  "onUpdate:result"?: ((value: boolean) => any) | undefined;
23
23
  }>, {
24
+ title: string;
24
25
  message: string;
25
26
  width: string;
26
- title: string;
27
27
  buttonTrueText: string;
28
28
  buttonFalseText: string;
29
29
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -21,9 +21,9 @@ declare const __VLS_base: import("vue").DefineComponent<DialogProps, {}, {}, {},
21
21
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
22
22
  "onUpdate:result"?: ((value: boolean) => any) | undefined;
23
23
  }>, {
24
+ title: string;
24
25
  message: string;
25
26
  width: string;
26
- title: string;
27
27
  buttonTrueText: string;
28
28
  buttonFalseText: string;
29
29
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -14,12 +14,12 @@ interface DialogImportResultProps {
14
14
  }
15
15
  declare const __VLS_export: import("vue").DefineComponent<DialogImportResultProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
16
16
  "update:modelValue": (value: boolean) => any;
17
- retry: (index: number) => any;
18
17
  "retry-all": () => any;
18
+ retry: (index: number) => any;
19
19
  }, string, import("vue").PublicProps, Readonly<DialogImportResultProps> & Readonly<{
20
20
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
21
- onRetry?: ((index: number) => any) | undefined;
22
21
  "onRetry-all"?: (() => any) | undefined;
22
+ onRetry?: ((index: number) => any) | undefined;
23
23
  }>, {
24
24
  title: string;
25
25
  isImporting: boolean;
@@ -14,12 +14,12 @@ interface DialogImportResultProps {
14
14
  }
15
15
  declare const __VLS_export: import("vue").DefineComponent<DialogImportResultProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
16
16
  "update:modelValue": (value: boolean) => any;
17
- retry: (index: number) => any;
18
17
  "retry-all": () => any;
18
+ retry: (index: number) => any;
19
19
  }, string, import("vue").PublicProps, Readonly<DialogImportResultProps> & Readonly<{
20
20
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
21
- onRetry?: ((index: number) => any) | undefined;
22
21
  "onRetry-all"?: (() => any) | undefined;
22
+ onRetry?: ((index: number) => any) | undefined;
23
23
  }>, {
24
24
  title: string;
25
25
  isImporting: boolean;
@@ -23,10 +23,10 @@ declare const __VLS_base: import("vue").DefineComponent<DialogProps, {}, {}, {},
23
23
  onResolve?: ((value: boolean) => any) | undefined;
24
24
  onReject?: ((value: any) => any) | undefined;
25
25
  }>, {
26
- message: string;
27
- width: string;
28
26
  title: string;
29
27
  type: "primary" | "success" | "warning" | "info" | "error";
28
+ message: string;
29
+ width: string;
30
30
  buttonTrueText: string;
31
31
  buttonFalseText: string;
32
32
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -23,10 +23,10 @@ declare const __VLS_base: import("vue").DefineComponent<DialogProps, {}, {}, {},
23
23
  onResolve?: ((value: boolean) => any) | undefined;
24
24
  onReject?: ((value: any) => any) | undefined;
25
25
  }>, {
26
- message: string;
27
- width: string;
28
26
  title: string;
29
27
  type: "primary" | "success" | "warning" | "info" | "error";
28
+ message: string;
29
+ width: string;
30
30
  buttonTrueText: string;
31
31
  buttonFalseText: string;
32
32
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -13,11 +13,11 @@ declare const __VLS_export: import("vue").DefineComponent<DialogProps, {}, {}, {
13
13
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
14
14
  onResolve?: ((value: boolean) => any) | undefined;
15
15
  }>, {
16
- message: string;
17
- width: string;
18
16
  title: string;
19
- type: "primary" | "success" | "warning" | "info" | "error";
20
17
  buttonText: string;
18
+ type: "primary" | "success" | "warning" | "info" | "error";
19
+ message: string;
20
+ width: string;
21
21
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
22
  declare const _default: typeof __VLS_export;
23
23
  export default _default;
@@ -13,11 +13,11 @@ declare const __VLS_export: import("vue").DefineComponent<DialogProps, {}, {}, {
13
13
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
14
14
  onResolve?: ((value: boolean) => any) | undefined;
15
15
  }>, {
16
- message: string;
17
- width: string;
18
16
  title: string;
19
- type: "primary" | "success" | "warning" | "info" | "error";
20
17
  buttonText: string;
18
+ type: "primary" | "success" | "warning" | "info" | "error";
19
+ message: string;
20
+ width: string;
21
21
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
22
  declare const _default: typeof __VLS_export;
23
23
  export default _default;
@@ -17,10 +17,10 @@ declare const __VLS_export: import("vue").DefineComponent<DialogProps, {}, {}, {
17
17
  onResolve?: ((value: string) => any) | undefined;
18
18
  onReject?: ((value: any) => any) | undefined;
19
19
  }>, {
20
- message: string;
21
- width: string;
22
20
  title: string;
23
21
  type: "primary" | "success" | "warning" | "info" | "error";
22
+ message: string;
23
+ width: string;
24
24
  confirmButtonText: string;
25
25
  cancelButtonText: string;
26
26
  fixedUsername: boolean | string;
@@ -17,10 +17,10 @@ declare const __VLS_export: import("vue").DefineComponent<DialogProps, {}, {}, {
17
17
  onResolve?: ((value: string) => any) | undefined;
18
18
  onReject?: ((value: any) => any) | undefined;
19
19
  }>, {
20
- message: string;
21
- width: string;
22
20
  title: string;
23
21
  type: "primary" | "success" | "warning" | "info" | "error";
22
+ message: string;
23
+ width: string;
24
24
  confirmButtonText: string;
25
25
  cancelButtonText: string;
26
26
  fixedUsername: boolean | string;
@@ -22,9 +22,9 @@ declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {},
22
22
  }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
23
23
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
24
24
  }>, {
25
- readonly: boolean;
26
25
  locale: "TH" | "EN";
27
26
  format: dateFormat | string;
27
+ readonly: boolean;
28
28
  dense: boolean;
29
29
  pickerOnly: boolean;
30
30
  defaultDate: boolean | string;
@@ -22,9 +22,9 @@ declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {},
22
22
  }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
23
23
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
24
24
  }>, {
25
- readonly: boolean;
26
25
  locale: "TH" | "EN";
27
26
  format: dateFormat | string;
27
+ readonly: boolean;
28
28
  dense: boolean;
29
29
  pickerOnly: boolean;
30
30
  defaultDate: boolean | string;
@@ -15,8 +15,8 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, i
15
15
  }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
16
16
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
17
17
  }>, {
18
- loading: boolean;
19
18
  title: string;
19
+ loading: boolean;
20
20
  errorMessages: string;
21
21
  hint: string;
22
22
  btnSubmit: string;
@@ -15,8 +15,8 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, i
15
15
  }, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
16
16
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
17
17
  }>, {
18
- loading: boolean;
19
18
  title: string;
19
+ loading: boolean;
20
20
  errorMessages: string;
21
21
  hint: string;
22
22
  btnSubmit: string;
@@ -681,9 +681,9 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
681
681
  }>, {
682
682
  disabled: boolean;
683
683
  readonly: boolean;
684
- parentTemplates: string | string[];
685
684
  isolated: boolean;
686
685
  decoration: object;
686
+ parentTemplates: string | string[];
687
687
  dirtyClass: string;
688
688
  dirtyOnCreate: boolean;
689
689
  sanitizeDelay: number;
@@ -681,9 +681,9 @@ declare const __VLS_base: import("vue").DefineComponent<Props, {
681
681
  }>, {
682
682
  disabled: boolean;
683
683
  readonly: boolean;
684
- parentTemplates: string | string[];
685
684
  isolated: boolean;
686
685
  decoration: object;
686
+ parentTemplates: string | string[];
687
687
  dirtyClass: string;
688
688
  dirtyOnCreate: boolean;
689
689
  sanitizeDelay: number;
@@ -78,10 +78,10 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
78
78
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
79
79
  "onUpdate:modelValue"?: ((value: string | undefined) => any) | undefined;
80
80
  }>, {
81
+ buttonText: string;
81
82
  disabled: boolean;
82
83
  maxWidth: string | number;
83
84
  readonly: boolean;
84
- buttonText: string;
85
85
  imageFormat: ImageFormat;
86
86
  autoStart: boolean;
87
87
  fileOnly: boolean;
@@ -78,10 +78,10 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
78
78
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
79
79
  "onUpdate:modelValue"?: ((value: string | undefined) => any) | undefined;
80
80
  }>, {
81
+ buttonText: string;
81
82
  disabled: boolean;
82
83
  maxWidth: string | number;
83
84
  readonly: boolean;
84
- buttonText: string;
85
85
  imageFormat: ImageFormat;
86
86
  autoStart: boolean;
87
87
  fileOnly: boolean;
@@ -22,8 +22,8 @@ type __VLS_Slots = {} & {
22
22
  };
23
23
  declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
24
24
  value: string | null;
25
- size: "large" | "medium";
26
25
  label: string;
26
+ size: "large" | "medium";
27
27
  horizontal: boolean;
28
28
  notFoundText: string;
29
29
  truncate: boolean;
@@ -22,8 +22,8 @@ type __VLS_Slots = {} & {
22
22
  };
23
23
  declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
24
24
  value: string | null;
25
- size: "large" | "medium";
26
25
  label: string;
26
+ size: "large" | "medium";
27
27
  horizontal: boolean;
28
28
  notFoundText: string;
29
29
  truncate: boolean;
@@ -74,6 +74,10 @@ usePerPagePreference(itemsPerPageInternal, {
74
74
  storageKey: props.perPageStorageKey ?? props.modelName,
75
75
  enabled: props.perPageStorageEnabled
76
76
  });
77
+ const pageInternal = ref(1);
78
+ watch([() => props.modelName, () => props.modelBy], () => {
79
+ pageInternal.value = 1;
80
+ }, { deep: true });
77
81
  const {
78
82
  items,
79
83
  itemsLength,
@@ -255,6 +259,7 @@ defineExpose({ reload, operation, items, autoRefresh, importProgress });
255
259
  v-if="canServerPageable && !useVirtual"
256
260
  v-bind="plainAttrs"
257
261
  v-model:items-per-page="itemsPerPageInternal"
262
+ v-model:page="pageInternal"
258
263
  color="primary"
259
264
  :items="items"
260
265
  :items-length="itemsLength"
@@ -162,6 +162,7 @@ const pageCount = computed(() => {
162
162
  else return Math.ceil(itemsLength.value / Number(itemsPerPageInternal.value));
163
163
  });
164
164
  const currentPage = ref(1);
165
+ const tablePageInternal = ref(1);
165
166
  watch([currentPage, itemsPerPageInternal, sortBy], () => {
166
167
  if (canServerPageable.value) {
167
168
  loadItems({
@@ -171,6 +172,10 @@ watch([currentPage, itemsPerPageInternal, sortBy], () => {
171
172
  });
172
173
  }
173
174
  }, { immediate: true });
175
+ watch([() => props.modelName, () => props.modelBy], () => {
176
+ currentPage.value = 1;
177
+ tablePageInternal.value = 1;
178
+ }, { deep: true });
174
179
  watch(
175
180
  [itemsLength, computedPreferTable, () => display.name?.value],
176
181
  ([len, prefer]) => {
@@ -392,6 +397,7 @@ defineExpose({ reload, operation, autoRefresh, importProgress });
392
397
  <v-data-table-server
393
398
  v-if="canServerPageable && !useVirtual"
394
399
  v-bind="plainAttrs"
400
+ v-model:page="tablePageInternal"
395
401
  color="primary"
396
402
  :items="items"
397
403
  :items-length="itemsLength"
@@ -56,6 +56,20 @@ export type CacheOption = boolean | number | {
56
56
  } | {
57
57
  ttlMs: number;
58
58
  };
59
+ /**
60
+ * Thrown by `urlBuilder` when an `['agent', ...]` url is requested but no host-agent
61
+ * base URL resolves. Callers get a typed, request-free failure instead of a silent
62
+ * misrouted call to `{WS_API}/undefined/...`.
63
+ */
64
+ export declare class AgentNotConfiguredError extends Error {
65
+ constructor(message?: string);
66
+ }
67
+ /**
68
+ * Single source of truth for "is a host agent reachable in principle".
69
+ * Returns the trimmed base URL, or null when the agent is not configured.
70
+ * `HOST_AGENT_ENABLED=false` is a hard kill switch: it wins over any base URL.
71
+ */
72
+ export declare function resolveAgentBase(publicConfig: Record<string, any>): string | null;
59
73
  /**
60
74
  * Per-call options accepted by useApi alongside Nuxt's UseFetchOptions.
61
75
  *
@@ -8,6 +8,18 @@ import { useAuthentication } from "../bridges/authentication.js";
8
8
  const DEFAULT_TTL_SECONDS_FOR_TRUE = 5 * 60;
9
9
  const CACHE_PREFIX = "api-cache-";
10
10
  const IDEMPOTENCY_HEADER_DEFAULT = "Idempotency-Key";
11
+ export class AgentNotConfiguredError extends Error {
12
+ constructor(message = "Host agent is not configured: set runtimeConfig.public.WS_AGENT (or WS_DEVICE), and do not set HOST_AGENT_ENABLED=false.") {
13
+ super(message);
14
+ this.name = "AgentNotConfiguredError";
15
+ Object.setPrototypeOf(this, AgentNotConfiguredError.prototype);
16
+ }
17
+ }
18
+ export function resolveAgentBase(publicConfig) {
19
+ if (publicConfig?.HOST_AGENT_ENABLED === false) return null;
20
+ const base = publicConfig?.WS_AGENT || publicConfig?.WS_DEVICE;
21
+ return base ? trimEnd(base, "/") : null;
22
+ }
11
23
  let _legacyHeuristicWarned = false;
12
24
  function warnLegacyHeuristic(value, resolvedSeconds) {
13
25
  if (_legacyHeuristicWarned) return;
@@ -68,10 +80,13 @@ export function useApi() {
68
80
  function urlBuilder(url) {
69
81
  let returnUrl;
70
82
  if (Array.isArray(url)) {
71
- if (url[0].toLowerCase() === "agent") {
72
- url[0] = config?.public.WS_AGENT || config?.public.WS_DEVICE;
83
+ const segments = [...url];
84
+ if (segments[0]?.toLowerCase() === "agent") {
85
+ const agentBase = resolveAgentBase(config?.public ?? {});
86
+ if (!agentBase) throw new AgentNotConfiguredError();
87
+ segments[0] = agentBase;
73
88
  }
74
- returnUrl = url.join("/");
89
+ returnUrl = segments.join("/");
75
90
  } else {
76
91
  returnUrl = url;
77
92
  }
@@ -165,6 +165,7 @@ export function useApiModel(props) {
165
165
  }
166
166
  }
167
167
  watchDebounced([() => props.modelName, () => props.modelBy, () => props.modelKey], () => {
168
+ if (currentOptions.value) currentOptions.value = { ...currentOptions.value, page: 1 };
168
169
  reload();
169
170
  }, { deep: true, debounce: 500, maxWait: 500 });
170
171
  onMounted(() => {
@@ -1,3 +1,8 @@
1
+ /**
2
+ * useClientConfig exposes runtime client configuration and resolves environment-driven settings for feature behavior.
3
+ * This doc block is consumed by vue-docgen for generated API documentation.
4
+ */
5
+ import type { Ref } from "vue";
1
6
  /** JSON-serializable config object (backend: Map<String, Object>) */
2
7
  export type ClientConfig = Record<string, any>;
3
8
  export interface ClientConfigOptions {
@@ -13,3 +18,15 @@ export interface ClientConfigService {
13
18
  fetchFromGraphql(): Promise<ClientConfig>;
14
19
  }
15
20
  export declare function createClientConfigService(opts?: ClientConfigOptions): ClientConfigService;
21
+ /**
22
+ * Access the app-wide client config provided by the `clientConfig` plugin.
23
+ *
24
+ * `config` is populated synchronously from the localStorage cache at plugin setup, then
25
+ * refreshed over GraphQL once the app is mounted AND an auth token exists. Apps whose
26
+ * `useAuthentication()` is not reactive must call `refresh()` themselves after login.
27
+ */
28
+ export declare function useClientConfig(): {
29
+ config: Ref<ClientConfig>;
30
+ refresh: () => Promise<ClientConfig>;
31
+ service: ClientConfigService;
32
+ };
@@ -1,5 +1,6 @@
1
1
  import ls from "localstorage-slim";
2
2
  import { Thumbmark } from "@thumbmarkjs/thumbmarkjs";
3
+ import { useNuxtApp } from "#imports";
3
4
  import { useGraphQlOperation } from "./graphqlOperation.js";
4
5
  import { useHostAgent } from "./hostAgent.js";
5
6
  function isPlainObject(v) {
@@ -49,13 +50,16 @@ export function createClientConfigService(opts = {}) {
49
50
  async fetchFromGraphql() {
50
51
  const thumbmark = await thumbmarkInstance.get();
51
52
  let computerName = thumbmark.thumbmark;
52
- try {
53
- const machineInfo = await useHostAgent().getMachineInfo();
54
- if (machineInfo?.computerName) {
55
- computerName = machineInfo.computerName;
53
+ const host = useHostAgent();
54
+ if (host.isConfigured() && await host.isAvailable()) {
55
+ try {
56
+ const machineInfo = await host.getMachineInfo();
57
+ if (machineInfo?.computerName) {
58
+ computerName = machineInfo.computerName;
59
+ }
60
+ } catch (err) {
61
+ console.debug("[client-config] machine info unavailable, using fingerprint:", err);
56
62
  }
57
- } catch (err) {
58
- console.warn("[client-config] getMachineInfo() failed, fallback to fingerprint:", err);
59
63
  }
60
64
  try {
61
65
  const result = await useGraphQlOperation(
@@ -77,3 +81,11 @@ export function createClientConfigService(opts = {}) {
77
81
  }
78
82
  };
79
83
  }
84
+ export function useClientConfig() {
85
+ const nuxtApp = useNuxtApp();
86
+ return {
87
+ config: nuxtApp.$clientConfig,
88
+ refresh: nuxtApp.$clientConfigRefresh,
89
+ service: nuxtApp.$clientConfigService
90
+ };
91
+ }
@@ -15,6 +15,7 @@ export const BUILT_IN_DOCUMENT_TEMPLATE_INPUT_TYPES = Object.freeze([
15
15
  { label: "Checkbox Group", value: "FormCheckboxGroup", requiresOptions: true, optionsAsChoice: true },
16
16
  { label: "Switch", value: "VSwitch" },
17
17
  { label: "File Upload", value: "FormFile", needsLabel: false, showsOptions: false },
18
+ { label: "Images Field", value: "FormImagesField", showsOptions: false },
18
19
  { label: "Signature Pad", value: "FormSignPad" },
19
20
  { label: "Table", value: "FormTable", requiresOptions: true, hasSpecificOptionEditor: true },
20
21
  { label: "Table Data", value: "FormTableData", requiresOptions: true, hasSpecificOptionEditor: true },
@@ -162,6 +162,7 @@ export function useGraphqlModel(props) {
162
162
  }
163
163
  }
164
164
  watchDebounced([() => props.modelName, () => props.modelBy, () => props.modelKey, canServerPageable], () => {
165
+ if (currentOptions.value) currentOptions.value = { ...currentOptions.value, page: 1 };
165
166
  reload();
166
167
  }, { deep: true, debounce: 500, maxWait: 500 });
167
168
  onMounted(() => {
@@ -31,6 +31,20 @@ export declare const PRINT_DATA_TYPE: {
31
31
  readonly Html: "Html";
32
32
  readonly Office: "Office";
33
33
  };
34
+ /**
35
+ * Timeout for the cheap, always-fast machine endpoints. Scanning and printing are
36
+ * legitimately slow and deliberately stay untimed.
37
+ */
38
+ export declare const AGENT_TIMEOUT_MS = 2000;
39
+ /**
40
+ * Thrown by `ensureAvailable()` when a host agent is configured but does not answer.
41
+ * `isAvailable()` never throws this — it returns `false`.
42
+ */
43
+ export declare class AgentUnavailableError extends Error {
44
+ constructor(message?: string);
45
+ }
46
+ /** Test-only hook: drop the memoized availability verdict. */
47
+ export declare function _resetHostAgentAvailability(): void;
34
48
  /**
35
49
  * =========================
36
50
  * REST DTOs
@@ -143,6 +157,27 @@ export interface MachineInfo {
143
157
  ipAddresses: string[];
144
158
  softwareVersion: string;
145
159
  }
160
+ /**
161
+ * Where the interactive session lives. `null` when no session was resolved.
162
+ */
163
+ export type LoggedOnUserSource = 'console' | 'remote' | null;
164
+ /**
165
+ * Response of `GET /machine/user`.
166
+ *
167
+ * The agent runs as a service, so the process identity is NOT the person at the
168
+ * keyboard; this is the resolved interactive desktop user.
169
+ *
170
+ * IMPORTANT: when there is no interactive session (headless host, or the machine is
171
+ * sitting at the logon screen) the agent returns **empty strings**, not nulls. Branch
172
+ * on `isResolved`, never on the truthiness of `userName`.
173
+ */
174
+ export interface LoggedOnUser {
175
+ login: string;
176
+ domain: string;
177
+ userName: string;
178
+ isResolved: boolean;
179
+ source: LoggedOnUserSource;
180
+ }
146
181
  /**
147
182
  * =========================
148
183
  * WS protocol types (exported for useHostAgentWs)
@@ -244,6 +279,10 @@ export declare function useHostAgent(): {
244
279
  readonly Html: "Html";
245
280
  readonly Office: "Office";
246
281
  };
282
+ isConfigured: () => boolean;
283
+ isAvailable: () => Promise<boolean>;
284
+ ensureAvailable: () => Promise<void>;
285
+ resetAvailability: () => void;
247
286
  getSettings: (cache?: boolean | number) => Promise<HostSettings>;
248
287
  updateSettings: (settings: HostSettings) => Promise<HostSettings>;
249
288
  getPrinters: (cache?: boolean | number) => Promise<DeviceNameList>;
@@ -252,6 +291,7 @@ export declare function useHostAgent(): {
252
291
  getIdCardInfoAndPhoto: (reader?: string) => Promise<PatientRegisterPayload>;
253
292
  getCitizenId: (reader?: string) => Promise<CitizenIdResult>;
254
293
  getMachineInfo: () => Promise<MachineInfo>;
294
+ getLoggedOnUser: () => Promise<LoggedOnUser>;
255
295
  print: (req: PrintRequest) => Promise<PrintAcceptedResponse>;
256
296
  scan: (req: ScanRequest) => Promise<ScanResult[]>;
257
297
  getLogFiles: (cache?: boolean | number) => Promise<LogFileList>;
@@ -1,11 +1,56 @@
1
- import { useApi } from "./api.js";
1
+ import { useApi, resolveAgentBase, AgentNotConfiguredError } from "./api.js";
2
+ import { useRuntimeConfig } from "#imports";
2
3
  export const DRIVER = { Wia: "Wia", Twain: "Twain", Sane: "Sane", Escl: "Escl" };
3
4
  export const PAPER_SOURCE = { Auto: "Auto", Flatbed: "Flatbed", Feeder: "Feeder", Duplex: "Duplex" };
4
5
  export const BIT_DEPTH = { Color: "Color", Grayscale: "Grayscale", BlackAndWhite: "BlackAndWhite" };
5
6
  export const PRINT_DATA_TYPE = { Pdf: "Pdf", Image: "Image", Text: "Text", Html: "Html", Office: "Office" };
7
+ export const AGENT_TIMEOUT_MS = 2e3;
8
+ const AGENT_PROBE_OPTIONS = { retry: 0, timeout: AGENT_TIMEOUT_MS };
9
+ export class AgentUnavailableError extends Error {
10
+ constructor(message = "Host agent is configured but not reachable.") {
11
+ super(message);
12
+ this.name = "AgentUnavailableError";
13
+ Object.setPrototypeOf(this, AgentUnavailableError.prototype);
14
+ }
15
+ }
16
+ const PROBE_TTL_MS_DEFAULT = 6e4;
17
+ let probeCache = null;
18
+ let probeInFlight = null;
19
+ export function _resetHostAgentAvailability() {
20
+ probeCache = null;
21
+ probeInFlight = null;
22
+ }
6
23
  export function useHostAgent() {
7
24
  const api = useApi();
8
25
  const base = ["agent"];
26
+ const config = useRuntimeConfig();
27
+ function isConfigured() {
28
+ return resolveAgentBase(config?.public ?? {}) !== null;
29
+ }
30
+ function isAvailable() {
31
+ if (!isConfigured()) return Promise.resolve(false);
32
+ const now = Date.now();
33
+ if (probeCache && probeCache.expiresAt > now) return Promise.resolve(probeCache.value);
34
+ if (probeInFlight) return probeInFlight;
35
+ const ttl = Number(config?.public?.HOST_AGENT_PROBE_TTL_MS ?? PROBE_TTL_MS_DEFAULT);
36
+ probeInFlight = api.getPromise([...base, "machine/info"], void 0, void 0, AGENT_PROBE_OPTIONS).then(() => {
37
+ probeCache = { value: true, expiresAt: Number.POSITIVE_INFINITY };
38
+ return true;
39
+ }).catch(() => {
40
+ probeCache = { value: false, expiresAt: Date.now() + ttl };
41
+ return false;
42
+ }).finally(() => {
43
+ probeInFlight = null;
44
+ });
45
+ return probeInFlight;
46
+ }
47
+ async function ensureAvailable() {
48
+ if (!isConfigured()) throw new AgentNotConfiguredError();
49
+ if (!await isAvailable()) throw new AgentUnavailableError();
50
+ }
51
+ function resetAvailability() {
52
+ _resetHostAgentAvailability();
53
+ }
9
54
  function getSettings(cache = false) {
10
55
  return api.getPromise([...base, "api/settings"], void 0, void 0, void 0, cache);
11
56
  }
@@ -32,7 +77,10 @@ export function useHostAgent() {
32
77
  return api.getPromise([...base, "idcard/citizenId"], void 0, reader ? { reader } : void 0);
33
78
  }
34
79
  function getMachineInfo() {
35
- return api.getPromise([...base, "machine/info"]);
80
+ return api.getPromise([...base, "machine/info"], void 0, void 0, AGENT_PROBE_OPTIONS);
81
+ }
82
+ function getLoggedOnUser() {
83
+ return api.getPromise([...base, "machine/user"], void 0, void 0, AGENT_PROBE_OPTIONS);
36
84
  }
37
85
  function print(req) {
38
86
  return api.postPromise([...base, "print"], req);
@@ -55,6 +103,11 @@ export function useHostAgent() {
55
103
  PAPER_SOURCE,
56
104
  BIT_DEPTH,
57
105
  PRINT_DATA_TYPE,
106
+ // availability
107
+ isConfigured,
108
+ isAvailable,
109
+ ensureAvailable,
110
+ resetAvailability,
58
111
  // REST
59
112
  getSettings,
60
113
  updateSettings,
@@ -64,6 +117,7 @@ export function useHostAgent() {
64
117
  getIdCardInfoAndPhoto,
65
118
  getCitizenId,
66
119
  getMachineInfo,
120
+ getLoggedOnUser,
67
121
  print,
68
122
  scan,
69
123
  getLogFiles,
@@ -18,18 +18,18 @@ interface CalendarProps {
18
18
  mode: 'dayGridMonth' | 'timeGridDay';
19
19
  }
20
20
  declare const __VLS_export: import("vue").DefineComponent<CalendarProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
21
- dialog: (...args: any[]) => void;
22
21
  select: (...args: any[]) => void;
22
+ dialog: (...args: any[]) => void;
23
23
  }, string, import("vue").PublicProps, Readonly<CalendarProps> & Readonly<{
24
- onDialog?: ((...args: any[]) => any) | undefined;
25
24
  onSelect?: ((...args: any[]) => any) | undefined;
25
+ onDialog?: ((...args: any[]) => any) | undefined;
26
26
  }>, {
27
- height: string | number;
28
- mode: "dayGridMonth" | "timeGridDay";
29
27
  locale: "th" | "en";
30
28
  toolBarLeft: string;
31
29
  toolBarCenter: string;
32
30
  toolBarRight: string;
31
+ height: string | number;
32
+ mode: "dayGridMonth" | "timeGridDay";
33
33
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
34
  declare const _default: typeof __VLS_export;
35
35
  export default _default;
@@ -18,18 +18,18 @@ interface CalendarProps {
18
18
  mode: 'dayGridMonth' | 'timeGridDay';
19
19
  }
20
20
  declare const __VLS_export: import("vue").DefineComponent<CalendarProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
21
- dialog: (...args: any[]) => void;
22
21
  select: (...args: any[]) => void;
22
+ dialog: (...args: any[]) => void;
23
23
  }, string, import("vue").PublicProps, Readonly<CalendarProps> & Readonly<{
24
- onDialog?: ((...args: any[]) => any) | undefined;
25
24
  onSelect?: ((...args: any[]) => any) | undefined;
25
+ onDialog?: ((...args: any[]) => any) | undefined;
26
26
  }>, {
27
- height: string | number;
28
- mode: "dayGridMonth" | "timeGridDay";
29
27
  locale: "th" | "en";
30
28
  toolBarLeft: string;
31
29
  toolBarCenter: string;
32
30
  toolBarRight: string;
31
+ height: string | number;
32
+ mode: "dayGridMonth" | "timeGridDay";
33
33
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
34
  declare const _default: typeof __VLS_export;
35
35
  export default _default;
@@ -1,22 +1,35 @@
1
- import { createClientConfigService } from "../composables/clientConfig.js";
2
1
  import { defineNuxtPlugin } from "nuxt/app";
3
- import { ref } from "vue";
4
- export default defineNuxtPlugin(async (nuxtApp) => {
5
- const clientConfigService = createClientConfigService({
6
- storageKey: "client_config"
7
- });
2
+ import { ref, watch } from "vue";
3
+ import { createClientConfigService } from "../composables/clientConfig.js";
4
+ import { useAuthentication } from "../bridges/authentication.js";
5
+ function readToken() {
6
+ const auth = useAuthentication();
7
+ return auth?.keycloak?.token || auth?.token;
8
+ }
9
+ export default defineNuxtPlugin((nuxtApp) => {
10
+ const clientConfigService = createClientConfigService({ storageKey: "client_config" });
8
11
  const clientConfig = ref(clientConfigService.get() ?? {});
9
- nuxtApp.provide("clientConfig", clientConfig);
10
- nuxtApp.provide("clientConfigRefresh", async () => {
11
- const loaded = await clientConfigService.load();
12
- clientConfig.value = loaded ?? {};
12
+ const refresh = async () => {
13
+ clientConfig.value = await clientConfigService.load() ?? {};
13
14
  return clientConfig.value;
15
+ };
16
+ nuxtApp.provide("clientConfig", clientConfig);
17
+ nuxtApp.provide("clientConfigService", clientConfigService);
18
+ nuxtApp.provide("clientConfigRefresh", refresh);
19
+ const load = () => {
20
+ void refresh().catch((err) => {
21
+ console.debug("[client-config] deferred load failed:", err);
22
+ });
23
+ };
24
+ nuxtApp.hook("app:mounted", () => {
25
+ if (readToken()) {
26
+ load();
27
+ return;
28
+ }
29
+ const stop = watch(readToken, (token) => {
30
+ if (!token) return;
31
+ stop();
32
+ load();
33
+ });
14
34
  });
15
- try {
16
- const loaded = await clientConfigService.load();
17
- clientConfig.value = loaded ?? {};
18
- } catch (e) {
19
- console.warn("[client-config] init load failed:", e?.message || e);
20
- clientConfig.value = clientConfigService.get() ?? {};
21
- }
22
35
  });
@@ -1,13 +1,26 @@
1
- import type { ClientConfig,ClientConfigService } from "../composables/clientConfig";
1
+ import type { Ref } from "vue";
2
+ import type { ClientConfig, ClientConfigService } from "../composables/clientConfig";
2
3
 
3
4
  declare module "#app" {
4
5
  interface NuxtApp {
5
- $clientConfig: ClientConfig;
6
+ /** Reactive app-wide client config. Hydrated from localStorage, refreshed after auth. */
7
+ $clientConfig: Ref<ClientConfig>;
8
+ /** The underlying service: get / set / clear / load / fetchFromGraphql. */
6
9
  $clientConfigService: ClientConfigService;
10
+ /** Force a GraphQL reload. Call this after login if your auth state is not reactive. */
11
+ $clientConfigRefresh: () => Promise<ClientConfig>;
7
12
  }
13
+ }
8
14
 
9
- interface RuntimeNuxtApp {
10
- $clientConfig: ClientConfig;
15
+ declare module "vue" {
16
+ interface ComponentCustomProperties {
17
+ /** Reactive app-wide client config. Hydrated from localStorage, refreshed after auth. */
18
+ $clientConfig: Ref<ClientConfig>;
19
+ /** The underlying service: get / set / clear / load / fetchFromGraphql. */
11
20
  $clientConfigService: ClientConfigService;
21
+ /** Force a GraphQL reload. Call this after login if your auth state is not reactive. */
22
+ $clientConfigRefresh: () => Promise<ClientConfig>;
12
23
  }
13
24
  }
25
+
26
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "4.0.17",
3
+ "version": "4.0.19",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",