@shwfed/nuxt 0.11.6 → 0.11.7

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.d.mts CHANGED
@@ -12,6 +12,12 @@ type Config = Wrap<{
12
12
  * @type DSL - Record<string, string>
13
13
  */
14
14
  header: string;
15
+ /**
16
+ * 配置 API 响应是否表示 token 已过期
17
+ *
18
+ * @type DSL - bool
19
+ */
20
+ expired: string;
15
21
  };
16
22
  }>;
17
23
  interface Env {
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
3
  "configKey": "shwfed",
4
- "version": "0.11.6",
4
+ "version": "0.11.7",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,4 +1,5 @@
1
1
  import { Effect } from 'effect';
2
+ import type { OverlayBodyRender } from '../composables/useOverlay.js';
2
3
  import type { ButtonConfigInput } from './ui/buttons/schema.js';
3
4
  export { ButtonActionC, ButtonBodyC, ButtonBodyInputC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './ui/buttons/schema.js';
4
5
  export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, } from './ui/buttons/schema.js';
@@ -151,7 +152,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
151
152
  style?: string | undefined;
152
153
  }>) => any) | undefined;
153
154
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
154
- [x: string]: ((props: any) => any) | undefined;
155
+ [name: string]: OverlayBodyRender;
155
156
  }>;
156
157
  type __VLS_WithSlots<T, S> = T & {
157
158
  new (): {
@@ -9,6 +9,7 @@ const props = defineProps({
9
9
  config: { type: null, required: false }
10
10
  });
11
11
  const emit = defineEmits(["update:config"]);
12
+ const slots = defineSlots();
12
13
  const defaultConfig = createButtonConfig({
13
14
  gap: 12,
14
15
  groups: []
@@ -53,7 +54,7 @@ export { ButtonActionService, currentButtonAction } from "../composables/useButt
53
54
  @update:config="handleConfigUpdate"
54
55
  >
55
56
  <template
56
- v-for="(_, slotName) in $slots"
57
+ v-for="(_, slotName) in slots"
57
58
  #[slotName]="slotProps"
58
59
  >
59
60
  <slot
@@ -1,4 +1,5 @@
1
1
  import { Effect } from 'effect';
2
+ import type { OverlayBodyRender } from '../composables/useOverlay.js';
2
3
  import type { ButtonConfigInput } from './ui/buttons/schema.js';
3
4
  export { ButtonActionC, ButtonBodyC, ButtonBodyInputC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './ui/buttons/schema.js';
4
5
  export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, } from './ui/buttons/schema.js';
@@ -151,7 +152,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
151
152
  style?: string | undefined;
152
153
  }>) => any) | undefined;
153
154
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
154
- [x: string]: ((props: any) => any) | undefined;
155
+ [name: string]: OverlayBodyRender;
155
156
  }>;
156
157
  type __VLS_WithSlots<T, S> = T & {
157
158
  new (): {
@@ -1,4 +1,5 @@
1
1
  import { Effect } from 'effect';
2
+ import { type OverlayBodyRender } from '../../../composables/useOverlay.js';
2
3
  import { type ButtonConfigInput } from './schema.js';
3
4
  export { ButtonActionC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC } from './schema.js';
4
5
  export { ButtonBodyC, ButtonBodyInputC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './schema.js';
@@ -7,7 +8,7 @@ export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonCon
7
8
  export type { ButtonActionEffect, ButtonActionEffectFactory, ButtonActionRuntime } from '../../../composables/useButtonAction.js';
8
9
  declare const _default: typeof __VLS_export;
9
10
  export default _default;
10
- declare const __VLS_export: import("vue").DefineComponent<{
11
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
11
12
  config: Effect.Effect<ButtonConfigInput | undefined>;
12
13
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
13
14
  "update:config": (args_0: Readonly<{
@@ -151,4 +152,11 @@ declare const __VLS_export: import("vue").DefineComponent<{
151
152
  gap?: number | undefined;
152
153
  style?: string | undefined;
153
154
  }>) => any) | undefined;
154
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
155
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
156
+ [name: string]: OverlayBodyRender;
157
+ }>;
158
+ type __VLS_WithSlots<T, S> = T & {
159
+ new (): {
160
+ $slots: S;
161
+ };
162
+ };
@@ -1,6 +1,6 @@
1
1
  <script setup>
2
2
  import { useNuxtApp } from "#app";
3
- import { useAttrs, computed, onBeforeUnmount, ref, useSlots, watch } from "vue";
3
+ import { useAttrs, computed, onBeforeUnmount, ref, watch } from "vue";
4
4
  import { computedAsync } from "@vueuse/core";
5
5
  import { Icon } from "@iconify/vue";
6
6
  import { Effect } from "effect";
@@ -9,7 +9,10 @@ import { useCheating } from "#imports";
9
9
  import {
10
10
  ButtonActionService
11
11
  } from "../../../composables/useButtonAction";
12
- import { provideOverlay, useOverlay } from "../../../composables/useOverlay";
12
+ import {
13
+ provideOverlay,
14
+ useOverlay
15
+ } from "../../../composables/useOverlay";
13
16
  import { getLocalizedText, hasVisibleLocaleValue } from "../../../utils/coders";
14
17
  import { cn } from "../../../utils/cn";
15
18
  import ButtonConfiguratorDialog from "../button-configurator/ButtonConfiguratorDialog.vue";
@@ -35,7 +38,7 @@ const defaultConfig = createButtonConfig({
35
38
  });
36
39
  const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
37
40
  const attrs = useAttrs();
38
- const slots = useSlots();
41
+ const slots = defineSlots();
39
42
  const { locale, t } = useI18n();
40
43
  const { $dsl } = useNuxtApp();
41
44
  const overlay = useOverlay();
@@ -1,4 +1,5 @@
1
1
  import { Effect } from 'effect';
2
+ import { type OverlayBodyRender } from '../../../composables/useOverlay.js';
2
3
  import { type ButtonConfigInput } from './schema.js';
3
4
  export { ButtonActionC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC } from './schema.js';
4
5
  export { ButtonBodyC, ButtonBodyInputC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './schema.js';
@@ -7,7 +8,7 @@ export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonCon
7
8
  export type { ButtonActionEffect, ButtonActionEffectFactory, ButtonActionRuntime } from '../../../composables/useButtonAction.js';
8
9
  declare const _default: typeof __VLS_export;
9
10
  export default _default;
10
- declare const __VLS_export: import("vue").DefineComponent<{
11
+ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
11
12
  config: Effect.Effect<ButtonConfigInput | undefined>;
12
13
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
13
14
  "update:config": (args_0: Readonly<{
@@ -151,4 +152,11 @@ declare const __VLS_export: import("vue").DefineComponent<{
151
152
  gap?: number | undefined;
152
153
  style?: string | undefined;
153
154
  }>) => any) | undefined;
154
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
155
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
156
+ [name: string]: OverlayBodyRender;
157
+ }>;
158
+ type __VLS_WithSlots<T, S> = T & {
159
+ new (): {
160
+ $slots: S;
161
+ };
162
+ };
@@ -1,6 +1,8 @@
1
1
  import { defineNuxtPlugin, useNuxtApp, useRuntimeConfig } from "#app";
2
2
  import { useNavigatorLanguage } from "@vueuse/core";
3
3
  import z from "zod";
4
+ let isRedirectingAfterTokenExpiry = false;
5
+ const processedResponses = /* @__PURE__ */ new WeakSet();
4
6
  export default defineNuxtPlugin({
5
7
  name: "shwfed-nuxt:api",
6
8
  dependsOn: ["shwfed-nuxt:cel"],
@@ -8,6 +10,34 @@ export default defineNuxtPlugin({
8
10
  const locale = useNavigatorLanguage();
9
11
  const config = useRuntimeConfig().public.shwfed;
10
12
  const { $dsl } = useNuxtApp();
13
+ function handleExpiredResponse(response) {
14
+ if (processedResponses.has(response)) {
15
+ return;
16
+ }
17
+ processedResponses.add(response);
18
+ if (typeof config.config?.api?.expired !== "string") {
19
+ return;
20
+ }
21
+ try {
22
+ const isExpired = z.boolean().parse($dsl.evaluate`${config.config.api.expired}`({
23
+ status: BigInt(response.status),
24
+ ok: response.ok,
25
+ data: response._data ?? null
26
+ }));
27
+ if (!isExpired || isRedirectingAfterTokenExpiry) {
28
+ return;
29
+ }
30
+ isRedirectingAfterTokenExpiry = true;
31
+ sessionStorage.removeItem("token");
32
+ if (config.api.logout) {
33
+ window.location.href = config.api.logout;
34
+ return;
35
+ }
36
+ console.warn("[shwfed-nuxt:api] token expired but no logout url configured");
37
+ } catch (e) {
38
+ console.error(e);
39
+ }
40
+ }
11
41
  const api = $fetch.create({
12
42
  baseURL: config.api.host,
13
43
  onRequest: ({
@@ -29,6 +59,12 @@ export default defineNuxtPlugin({
29
59
  }
30
60
  const name = config.headers.token || "Authorization";
31
61
  options.headers.set(name, sessionStorage.getItem("token") ?? "");
62
+ },
63
+ onResponse: ({ response }) => {
64
+ handleExpiredResponse(response);
65
+ },
66
+ onResponseError: ({ response }) => {
67
+ handleExpiredResponse(response);
32
68
  }
33
69
  });
34
70
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.11.6",
3
+ "version": "0.11.7",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",