@shwfed/nuxt 0.6.0 → 0.6.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/dist/module.d.mts CHANGED
@@ -1,5 +1,18 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
+ type Wrap<T> = T extends object ? Readonly<{
4
+ [P in keyof T]?: Wrap<T[P]>;
5
+ }> : T;
6
+ type Config = Wrap<{
7
+ api: {
8
+ /**
9
+ * 配置 API 请求额外头
10
+ *
11
+ * @type DSL - Record<string, string>
12
+ */
13
+ header: string;
14
+ };
15
+ }>;
3
16
  interface Env {
4
17
  git: Readonly<{
5
18
  commit?: string;
@@ -16,6 +29,7 @@ interface Env {
16
29
  headers: Readonly<{
17
30
  token?: string;
18
31
  }>;
32
+ config?: Config;
19
33
  }
20
34
  declare module 'nuxt/schema' {
21
35
  interface PublicRuntimeConfig {
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "configKey": "@shwfed/nuxt",
4
- "version": "0.6.0",
3
+ "configKey": "shwfed",
4
+ "version": "0.6.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -5,7 +5,8 @@ import defu from 'defu';
5
5
 
6
6
  const module$1 = defineNuxtModule({
7
7
  meta: {
8
- name: "@shwfed/nuxt"
8
+ name: "@shwfed/nuxt",
9
+ configKey: "shwfed"
9
10
  },
10
11
  setup(options, nuxt) {
11
12
  const resolver = createResolver(import.meta.url);
@@ -24,7 +25,8 @@ const module$1 = defineNuxtModule({
24
25
  },
25
26
  headers: {
26
27
  token: process.env.NUXT_PUBLIC_TOKEN_HEADER_NAME
27
- }
28
+ },
29
+ config: options
28
30
  });
29
31
  nuxt.options.runtimeConfig.public.shwfed = resolvedConfig;
30
32
  nuxt.options.css ||= [];
@@ -1,10 +1,13 @@
1
- import { defineNuxtPlugin, useRuntimeConfig } from "#app";
1
+ import { defineNuxtPlugin, useNuxtApp, useRuntimeConfig } from "#app";
2
2
  import { useNavigatorLanguage } from "@vueuse/core";
3
+ import z from "zod";
3
4
  export default defineNuxtPlugin({
4
5
  name: "shwfed-nuxt:api",
6
+ dependsOn: ["shwfed-nuxt:cel"],
5
7
  setup: () => {
6
8
  const locale = useNavigatorLanguage();
7
9
  const config = useRuntimeConfig().public.shwfed;
10
+ const { $dsl } = useNuxtApp();
8
11
  const api = $fetch.create({
9
12
  baseURL: config.api.host,
10
13
  onRequest: ({
@@ -13,7 +16,18 @@ export default defineNuxtPlugin({
13
16
  if (locale.isSupported && locale.language.value) {
14
17
  options.headers.set("Accept-Language", locale.language.value);
15
18
  }
16
- const name = config.headers.token ?? "Authorization";
19
+ if (typeof config.config?.api?.header === "string") {
20
+ try {
21
+ for (const [key, value] of Object.entries(
22
+ z.record(z.string(), z.string()).parse($dsl.evaluate`${config.config.api.header}`())
23
+ )) {
24
+ options.headers.set(key, value);
25
+ }
26
+ } catch (e) {
27
+ console.error(e);
28
+ }
29
+ }
30
+ const name = config.headers.token || "Authorization";
17
31
  options.headers.set(name, sessionStorage.getItem("token") ?? "");
18
32
  }
19
33
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",