@merkaly/nuxt 0.1.16 → 0.1.17
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.json +1 -1
- package/dist/module.mjs +6 -57
- package/dist/runtime/composables/useApi.d.ts +1 -1
- package/dist/runtime/plugins/api.global.js +1 -1
- package/dist/runtime/plugins/auth0.client.js +2 -10
- package/dist/runtime/types/nuxt.d.ts +1 -2
- package/dist/runtime/utils/withAdapter.d.ts +1 -0
- package/package.json +17 -16
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,64 +1,9 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, useLogger, addPlugin, addRouteMiddleware, addImportsDir, addComponentsDir } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, useLogger, addPlugin, addRouteMiddleware, addImportsDir, addComponentsDir, addTypeTemplate } from '@nuxt/kit';
|
|
2
2
|
import { createJiti } from 'jiti';
|
|
3
|
+
import { defu } from 'defu';
|
|
3
4
|
import { existsSync } from 'node:fs';
|
|
4
5
|
import svgLoader from 'vite-svg-loader';
|
|
5
6
|
|
|
6
|
-
function isPlainObject(value) {
|
|
7
|
-
if (value === null || typeof value !== "object") {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const prototype = Object.getPrototypeOf(value);
|
|
11
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (Symbol.iterator in value) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
if (Symbol.toStringTag in value) {
|
|
18
|
-
return Object.prototype.toString.call(value) === "[object Module]";
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
24
|
-
if (!isPlainObject(defaults)) {
|
|
25
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
26
|
-
}
|
|
27
|
-
const object = Object.assign({}, defaults);
|
|
28
|
-
for (const key in baseObject) {
|
|
29
|
-
if (key === "__proto__" || key === "constructor") {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
const value = baseObject[key];
|
|
33
|
-
if (value === null || value === void 0) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
40
|
-
object[key] = [...value, ...object[key]];
|
|
41
|
-
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
42
|
-
object[key] = _defu(
|
|
43
|
-
value,
|
|
44
|
-
object[key],
|
|
45
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
46
|
-
merger
|
|
47
|
-
);
|
|
48
|
-
} else {
|
|
49
|
-
object[key] = value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return object;
|
|
53
|
-
}
|
|
54
|
-
function createDefu(merger) {
|
|
55
|
-
return (...arguments_) => (
|
|
56
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
57
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
const defu = createDefu();
|
|
61
|
-
|
|
62
7
|
const module = defineNuxtModule({
|
|
63
8
|
defaults: {
|
|
64
9
|
auth0: {
|
|
@@ -125,6 +70,10 @@ const module = defineNuxtModule({
|
|
|
125
70
|
prefix: "MK"
|
|
126
71
|
});
|
|
127
72
|
nuxt.options["vite"] = defu(nuxt.options["vite"] || {}, { plugins: [svgLoader()] });
|
|
73
|
+
addTypeTemplate({
|
|
74
|
+
filename: "types/merkaly.d.ts",
|
|
75
|
+
src: moduleResolver.resolve("./runtime/types/nuxt.d.ts")
|
|
76
|
+
});
|
|
128
77
|
}
|
|
129
78
|
});
|
|
130
79
|
|
|
@@ -6,7 +6,7 @@ export interface ComposableOptions<TData = unknown, TMeta = Record<string, unkno
|
|
|
6
6
|
}
|
|
7
7
|
export interface UseApiReturn<TData, TMeta, TParams> {
|
|
8
8
|
abort: () => void;
|
|
9
|
-
data: Ref<TData
|
|
9
|
+
data: Ref<TData>;
|
|
10
10
|
error: Ref<Error | undefined>;
|
|
11
11
|
execute: (args?: Partial<TParams>) => Promise<void>;
|
|
12
12
|
loading: Ref<boolean>;
|
|
@@ -3,7 +3,7 @@ import { useAuth } from "#imports";
|
|
|
3
3
|
export default defineNuxtPlugin(({ provide }) => provide("api", async (url, options = {}) => {
|
|
4
4
|
const { public: $config } = useRuntimeConfig();
|
|
5
5
|
const { tenant, token } = useAuth();
|
|
6
|
-
$fetch(url, {
|
|
6
|
+
await $fetch(url, {
|
|
7
7
|
// Determine the base URL
|
|
8
8
|
baseURL: new URL(options.prefix || $config.merkaly.api.prefix || "/", $config.merkaly.api.url).href,
|
|
9
9
|
body: options?.body,
|
|
@@ -3,7 +3,7 @@ import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
|
|
|
3
3
|
import { navigateTo } from "#app";
|
|
4
4
|
import { defu } from "defu";
|
|
5
5
|
import { useAuth } from "../composables/useAuth.js";
|
|
6
|
-
export default defineNuxtPlugin(async (
|
|
6
|
+
export default defineNuxtPlugin(async ({ callHook, hook }) => {
|
|
7
7
|
const { public: $config } = useRuntimeConfig();
|
|
8
8
|
const auth0 = await createAuth0Client({
|
|
9
9
|
cacheLocation: "localstorage",
|
|
@@ -29,14 +29,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
29
29
|
returnTo: URL.canParse($config.merkaly.auth0.logoutUrl) ? $config.merkaly.auth0.logoutUrl : location.origin.concat($config.merkaly.auth0.logoutUrl)
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
Promise.allSettled([auth0.getUser(), auth0.getTokenSilently()]).then((
|
|
33
|
-
const rejected = results.filter((r) => r.status === "rejected");
|
|
34
|
-
if (rejected.length > 0) {
|
|
35
|
-
return nuxtApp.callHook("merkaly:auth:error", { errors: rejected.map((r) => r.reason) });
|
|
36
|
-
}
|
|
37
|
-
if (user.value) {
|
|
38
|
-
return nuxtApp.callHook("merkaly:auth:success", { user: user.value, token: token.value });
|
|
39
|
-
}
|
|
40
|
-
}).finally(() => isLoading.value = false);
|
|
32
|
+
hook("app:created", () => Promise.allSettled([auth0.getUser(), auth0.getTokenSilently()]).then(() => callHook("merkaly:auth", user.value)).finally(() => isLoading.value = false));
|
|
41
33
|
return { provide: { auth0 } };
|
|
42
34
|
});
|
|
@@ -8,8 +8,7 @@ declare module '#app' {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface RuntimeNuxtHooks {
|
|
11
|
-
'merkaly:auth
|
|
12
|
-
'merkaly:auth:error': (payload: { errors: unknown[] }) => void | Promise<void>;
|
|
11
|
+
'merkaly:auth': (user: User | null) => void | Promise<void>;
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
|
|
@@ -6,6 +6,7 @@ export interface AdapterOptions {
|
|
|
6
6
|
params: object;
|
|
7
7
|
}
|
|
8
8
|
export interface AdapterArgs<TData, TMeta, TParams> extends HooksOptions<TData, TMeta, TParams> {
|
|
9
|
+
immediate?: boolean;
|
|
9
10
|
params?: Partial<TParams>;
|
|
10
11
|
}
|
|
11
12
|
type AdapterCallback<T extends AdapterOptions> = (args: T['params']) => AdapterArgs<T['data'], T['meta'], T['params']>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkaly/nuxt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/merkaly-io/nuxt.git"
|
|
@@ -27,20 +27,6 @@
|
|
|
27
27
|
"files": [
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "nuxt-module-build build",
|
|
32
|
-
"build:stub": "nuxt-module-build build --stub",
|
|
33
|
-
"dev": "pnpm dev:prepare && cd playground && pnpm storybook",
|
|
34
|
-
"dev:build": "nuxi build playground",
|
|
35
|
-
"dev:prepare": "pnpm build:stub && nuxi prepare playground",
|
|
36
|
-
"lint": "eslint .",
|
|
37
|
-
"prepack": "pnpm build",
|
|
38
|
-
"prepare": "nuxt-module-build prepare",
|
|
39
|
-
"release": "pnpm lint && pnpm test && pnpm build && changelogen --release && npm publish --access public && git push --follow-tags",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
|
|
42
|
-
"test:watch": "vitest watch"
|
|
43
|
-
},
|
|
44
30
|
"dependencies": {
|
|
45
31
|
"@auth0/auth0-spa-js": "^2.11.0",
|
|
46
32
|
"@bootstrap-vue-next/nuxt": "^0.42.0",
|
|
@@ -78,7 +64,22 @@
|
|
|
78
64
|
"vitest": "^4.0.6",
|
|
79
65
|
"vue-tsc": "^3.2.1"
|
|
80
66
|
},
|
|
67
|
+
"optionalDependencies": {
|
|
68
|
+
"defu": "^6.1.4"
|
|
69
|
+
},
|
|
81
70
|
"engines": {
|
|
82
71
|
"node": ">=20.0.0"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "nuxt-module-build build",
|
|
75
|
+
"build:stub": "nuxt-module-build build --stub",
|
|
76
|
+
"dev": "pnpm dev:prepare && cd playground && pnpm storybook",
|
|
77
|
+
"dev:build": "nuxi build playground",
|
|
78
|
+
"dev:prepare": "pnpm build:stub && nuxi prepare playground",
|
|
79
|
+
"lint": "eslint .",
|
|
80
|
+
"release": "pnpm lint && pnpm test && pnpm build && changelogen --release && npm publish --access public && git push --follow-tags",
|
|
81
|
+
"test": "vitest run",
|
|
82
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
|
|
83
|
+
"test:watch": "vitest watch"
|
|
83
84
|
}
|
|
84
|
-
}
|
|
85
|
+
}
|