@shwfed/nuxt 0.1.31 → 0.1.32
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,7 +1,16 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
|
|
3
3
|
interface ModuleOptions {
|
|
4
|
-
|
|
4
|
+
apis: Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* DSL
|
|
7
|
+
*/
|
|
8
|
+
headers?: string;
|
|
9
|
+
/**
|
|
10
|
+
* DSL
|
|
11
|
+
*/
|
|
12
|
+
baseURL: string;
|
|
13
|
+
}>;
|
|
5
14
|
}
|
|
6
15
|
declare module 'nuxt/schema' {
|
|
7
16
|
interface PublicRuntimeConfig {
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -18,6 +18,7 @@ const module$1 = defineNuxtModule({
|
|
|
18
18
|
addPlugin(resolver.resolve("runtime/plugins/i18n/index"));
|
|
19
19
|
addPlugin(resolver.resolve("runtime/plugins/cel/index"));
|
|
20
20
|
addPlugin(resolver.resolve("runtime/plugins/markdown/index"));
|
|
21
|
+
addPlugin(resolver.resolve("runtime/plugins/api/index"));
|
|
21
22
|
addPlugin({
|
|
22
23
|
src: resolver.resolve("runtime/plugins/toast/index"),
|
|
23
24
|
mode: "client"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const _default: import("#app").Plugin<{
|
|
2
|
+
api: import("nitropack").$Fetch<unknown, import("nitropack").NitroFetchRequest>;
|
|
3
|
+
}> & import("#app").ObjectPlugin<{
|
|
4
|
+
api: import("nitropack").$Fetch<unknown, import("nitropack").NitroFetchRequest>;
|
|
5
|
+
}>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useNuxtApp } from "#app";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
export default defineNuxtPlugin({
|
|
4
|
+
name: "shwfed-nuxt:api",
|
|
5
|
+
dependsOn: ["shwfed-nuxt:cel"],
|
|
6
|
+
setup: (nuxt) => {
|
|
7
|
+
const { $dsl } = useNuxtApp();
|
|
8
|
+
const api = $fetch.create({
|
|
9
|
+
onRequest: ({
|
|
10
|
+
options
|
|
11
|
+
}) => {
|
|
12
|
+
if (options.baseURL === "/") {
|
|
13
|
+
try {
|
|
14
|
+
const baseURL = $dsl.evaluate`${nuxt.$config.public.shwfed.apis.baseURL}`();
|
|
15
|
+
if (typeof baseURL === "string") {
|
|
16
|
+
options.baseURL = baseURL;
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (nuxt.$config.public.shwfed.apis.headers) {
|
|
22
|
+
try {
|
|
23
|
+
const headers = $dsl.evaluate`${nuxt.$config.public.shwfed.apis.headers}`();
|
|
24
|
+
for (const [key, value] of Object.entries(z.record(z.string(), z.string()).parse(headers))) {
|
|
25
|
+
options.headers.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
provide: {
|
|
34
|
+
api
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Environment, EvaluationError } from "@marcbachmann/cel-js";
|
|
1
|
+
import { Environment, EvaluationError, Optional } from "@marcbachmann/cel-js";
|
|
2
2
|
import { startOfDay, startOfWeek, startOfYear, startOfMonth, endOfDay, endOfWeek, endOfYear, endOfMonth, addYears, addMonths, addDays, addWeeks, setDate, setMonth, setYear, formatDate, isBefore, isAfter, isEqual } from "date-fns";
|
|
3
3
|
import { TZDate } from "@date-fns/tz";
|
|
4
4
|
import { BigNumber } from "bignumber.js";
|
|
@@ -86,6 +86,17 @@ export function createEnvironment(_) {
|
|
|
86
86
|
return number.toLocaleString(navigator.language, options);
|
|
87
87
|
}).registerFunction("int.toLocaleString(dyn): string", (number, options) => {
|
|
88
88
|
return number.toLocaleString(navigator.language, options);
|
|
89
|
+
}).registerFunction("parseJSON(string): dyn", (string) => {
|
|
90
|
+
return JSON.parse(string);
|
|
91
|
+
}).registerFunction("session(string): optional<string>", (key) => {
|
|
92
|
+
if (typeof window === "undefined") return Optional.none();
|
|
93
|
+
try {
|
|
94
|
+
const value = window.sessionStorage.getItem(key);
|
|
95
|
+
if (value === null) return Optional.none();
|
|
96
|
+
return Optional.of(value);
|
|
97
|
+
} catch {
|
|
98
|
+
return Optional.none();
|
|
99
|
+
}
|
|
89
100
|
});
|
|
90
101
|
return env;
|
|
91
102
|
}
|