@shwfed/nuxt 0.1.68 → 0.1.69

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
@@ -101,6 +101,12 @@ interface ModuleOptions {
101
101
  * - `{ type: 'route', to: string }`
102
102
  * - `{ type: 'external', href: string }`
103
103
  * - `{ type: 'logout' }`
104
+ * - `{ type: 'request', url: string, method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', body?: unknown, query?: Record<string, unknown>, headers?: Record<string, string> }`
105
+ *
106
+ * 示例:
107
+ * - 维护任务:`{ type: 'request', url: '/maintenance/run', method: 'POST' }`
108
+ * - 清理缓存:`{ type: 'request', url: '/cache/clear', method: 'POST', body: { scope: 'all' } }`
109
+ * - 重建索引:`{ type: 'request', url: '/search/reindex', method: 'POST', query: { async: true }, headers: { 'X-Command-Source': 'palette' } }`
104
110
  *
105
111
  * @type DSL
106
112
  */
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
3
  "configKey": "shwfed",
4
- "version": "0.1.68",
4
+ "version": "0.1.69",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -20,7 +20,7 @@ import { commandActionSchema, executeCommandAction } from "../utils/command";
20
20
  import { createPaletteItemValue, normalizeCommandsForPalette, splitNavigationForPalette } from "../utils/command-palette";
21
21
  import { isRouteActive, normalizeRoutePath } from "../utils/route";
22
22
  import { applyRootNavigationFallback } from "../utils/sidebar-fallback";
23
- const { $dsl, $logout, $md } = useNuxtApp();
23
+ const { $dsl, $logout, $md, $api, $toast } = useNuxtApp();
24
24
  const { t } = useI18n();
25
25
  const route = useRoute();
26
26
  const { tabs, active, tabList, activateTab, closeTab } = useNavigationTabs();
@@ -179,9 +179,10 @@ const profileCommands = computed(() => {
179
179
  return [];
180
180
  }
181
181
  });
182
- const executeCommandEffect = (effect) => {
182
+ const executeCommandEffect = async (effect) => {
183
183
  if (effect === void 0)
184
184
  return false;
185
+ let action;
185
186
  try {
186
187
  let result;
187
188
  try {
@@ -189,30 +190,40 @@ const executeCommandEffect = (effect) => {
189
190
  } catch {
190
191
  result = $dsl.evaluate`${normalizeEffectExpression(effect)}`();
191
192
  }
192
- const action = commandActionSchema.parse(result);
193
- executeCommandAction(action, {
194
- logout: $logout
193
+ action = commandActionSchema.parse(result);
194
+ await executeCommandAction(action, {
195
+ logout: $logout,
196
+ request: async (requestAction) => $api(requestAction.url, {
197
+ method: requestAction.method,
198
+ body: requestAction.body,
199
+ query: requestAction.query,
200
+ headers: requestAction.headers
201
+ })
195
202
  });
196
203
  return true;
197
- } catch {
204
+ } catch (error) {
205
+ if (action?.type === "request") {
206
+ const message = error instanceof Error && error.message.length > 0 ? error.message : "Request failed";
207
+ $toast.error(message);
208
+ }
198
209
  return false;
199
210
  }
200
211
  };
201
- const executeProfileCommand = (effect) => {
202
- if (effect === void 0 || executeCommandEffect(effect))
212
+ const executeProfileCommand = async (effect) => {
213
+ if (effect === void 0 || await executeCommandEffect(effect))
203
214
  ui.isProfileDropdownOpen = false;
204
215
  };
205
216
  const paletteNavigation = computed(() => splitNavigationForPalette(navigations.value));
206
217
  const favoriteRoutesForPalette = computed(() => paletteNavigation.value.favoriteRoutes);
207
218
  const navigationForPalette = computed(() => paletteNavigation.value.navigationEntries);
208
219
  const commandForPalette = computed(() => normalizeCommandsForPalette(profileCommands.value));
209
- const executePaletteItem = (item) => {
220
+ const executePaletteItem = async (item) => {
210
221
  if (item.type === "route") {
211
222
  activateTab(item.route);
212
223
  ui.isCommandPaletteOpen = false;
213
224
  return;
214
225
  }
215
- if (item.effect !== void 0 && !executeCommandEffect(item.effect))
226
+ if (item.effect !== void 0 && !await executeCommandEffect(item.effect))
216
227
  return;
217
228
  ui.isCommandPaletteOpen = false;
218
229
  };
@@ -7,9 +7,25 @@ export declare const commandActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
7
7
  href: z.ZodString;
8
8
  }, z.core.$strip>, z.ZodObject<{
9
9
  type: z.ZodLiteral<"logout">;
10
+ }, z.core.$strip>, z.ZodObject<{
11
+ type: z.ZodLiteral<"request">;
12
+ url: z.ZodString;
13
+ method: z.ZodOptional<z.ZodEnum<{
14
+ GET: "GET";
15
+ POST: "POST";
16
+ PUT: "PUT";
17
+ PATCH: "PATCH";
18
+ DELETE: "DELETE";
19
+ }>>;
20
+ body: z.ZodOptional<z.ZodUnknown>;
21
+ query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
22
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
10
23
  }, z.core.$strip>], "type">;
11
24
  export type CommandAction = z.infer<typeof commandActionSchema>;
12
25
  export type ExecuteCommandActionOptions = {
13
26
  logout: () => void;
27
+ request: (action: Extract<CommandAction, {
28
+ type: 'request';
29
+ }>) => Promise<unknown>;
14
30
  };
15
- export declare const executeCommandAction: (action: CommandAction, options: ExecuteCommandActionOptions) => void;
31
+ export declare const executeCommandAction: (action: CommandAction, options: ExecuteCommandActionOptions) => Promise<void>;
@@ -1,5 +1,6 @@
1
1
  import { navigateTo } from "#app";
2
2
  import { z } from "zod";
3
+ const requestMethodSchema = z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]);
3
4
  export const commandActionSchema = z.discriminatedUnion("type", [
4
5
  z.object({
5
6
  type: z.literal("route"),
@@ -11,9 +12,17 @@ export const commandActionSchema = z.discriminatedUnion("type", [
11
12
  }),
12
13
  z.object({
13
14
  type: z.literal("logout")
15
+ }),
16
+ z.object({
17
+ type: z.literal("request"),
18
+ url: z.string(),
19
+ method: requestMethodSchema.optional(),
20
+ body: z.unknown().optional(),
21
+ query: z.record(z.string(), z.unknown()).optional(),
22
+ headers: z.record(z.string(), z.string()).optional()
14
23
  })
15
24
  ]);
16
- export const executeCommandAction = (action, options) => {
25
+ export const executeCommandAction = async (action, options) => {
17
26
  switch (action.type) {
18
27
  case "route":
19
28
  navigateTo(action.to);
@@ -24,5 +33,8 @@ export const executeCommandAction = (action, options) => {
24
33
  case "logout":
25
34
  options.logout();
26
35
  return;
36
+ case "request":
37
+ await options.request(action);
38
+ return;
27
39
  }
28
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.1.68",
3
+ "version": "0.1.69",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",