@merkaly/nuxt 0.1.9 → 0.1.11

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,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { ClientAuthorizationParams } from '@auth0/auth0-spa-js';
3
+ export { AdapterArgs, AdapterOptions } from '../dist/runtime/utils/withAdapter.js';
4
+ export { ApiOptions, HooksOptions, ParamsOptions, RefOptions } from '../dist/runtime/plugins/api.global.js';
3
5
 
4
6
  interface MerkalyModuleOptions {
5
7
  auth0: {
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.1.9",
7
+ "version": "0.1.11",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -103,7 +103,7 @@ const module = defineNuxtModule({
103
103
  const bootstrapConfigPath = rootResolver.resolve("bootstrap.config.ts");
104
104
  let BootstrapConfig;
105
105
  if (existsSync(bootstrapConfigPath)) {
106
- BootstrapConfig = await import(bootstrapConfigPath) || {};
106
+ await import(bootstrapConfigPath).then((result) => BootstrapConfig = result.default).catch(() => BootstrapConfig = {});
107
107
  }
108
108
  if (!BootstrapConfig) {
109
109
  BootstrapConfig = {};
@@ -1,18 +1,17 @@
1
+ import type { Ref } from 'vue';
1
2
  import type { ApiOptions } from '../plugins/api.global.js';
2
- export interface ComposableOptions extends ApiOptions {
3
+ export interface ComposableOptions<TData = unknown, TMeta = Record<string, unknown>> extends ApiOptions<TData, TMeta> {
3
4
  immediate?: boolean;
4
5
  uri: string;
5
6
  }
6
- export type CallbackArgs<T extends object> = (args: T) => ComposableOptions;
7
- declare function useApi<D extends object>(callback: CallbackArgs<D>): {
8
- abort: {
9
- (reason?: any): void;
10
- (reason?: any): void;
11
- };
12
- data: import("vue").Ref<unknown, unknown>;
13
- error: import("vue").Ref<Error | undefined, Error | undefined>;
14
- execute: (args?: Partial<D>) => any;
15
- loading: import("vue").Ref<boolean, boolean>;
16
- meta: import("vue").Ref<{}, {}>;
17
- };
7
+ export interface UseApiReturn<TData, TMeta, TParams> {
8
+ abort: () => void;
9
+ data: Ref<TData | undefined>;
10
+ error: Ref<Error | undefined>;
11
+ execute: (args?: Partial<TParams>) => Promise<void>;
12
+ loading: Ref<boolean>;
13
+ meta: Ref<TMeta>;
14
+ params: TParams;
15
+ }
16
+ declare function useApi<TData = unknown, TMeta = Record<string, unknown>, TParams extends object = object>(callback: (params: TParams) => ComposableOptions<TData, TMeta>): UseApiReturn<TData, TMeta, TParams>;
18
17
  export { useApi };
@@ -14,10 +14,12 @@ function useApi(callback) {
14
14
  const data = ref(initialOptions.default?.());
15
15
  const meta = ref({});
16
16
  const error = ref();
17
- const execute = (args = {}) => {
18
- Object.assign(params, args);
17
+ const execute = async (args = {}) => {
18
+ Object.keys(args).forEach((key) => {
19
+ params[key] = args[key];
20
+ });
19
21
  const currentOptions = getOptions(params);
20
- return $api(currentOptions.uri, {
22
+ await $api(currentOptions.uri, {
21
23
  ...currentOptions,
22
24
  controller,
23
25
  data,
@@ -31,12 +33,13 @@ function useApi(callback) {
31
33
  void execute();
32
34
  }
33
35
  return {
34
- abort: controller.abort,
36
+ abort: () => controller.abort(),
35
37
  data,
36
38
  error,
37
39
  execute,
38
40
  loading,
39
- meta
41
+ meta,
42
+ params
40
43
  };
41
44
  }
42
45
  export { useApi };
@@ -9,9 +9,9 @@ type OnResponseArgs = {
9
9
  response: FetchResponse<unknown>;
10
10
  request: RequestInfo;
11
11
  };
12
- type OnSuccessArgs = {
13
- data: unknown;
14
- meta: Record<string, unknown>;
12
+ type OnSuccessArgs<TData = unknown, TMeta = Record<string, unknown>> = {
13
+ data: TData;
14
+ meta: TMeta;
15
15
  headers: FetchOptions['headers'];
16
16
  };
17
17
  type OnCompleteArgs = {
@@ -24,13 +24,13 @@ export interface RefOptions {
24
24
  loading?: Ref<boolean>;
25
25
  meta?: Ref<Record<string, unknown>>;
26
26
  }
27
- export interface HooksOptions {
27
+ export interface HooksOptions<TData = unknown, TMeta = Record<string, unknown>> {
28
28
  onBeforeSend?(args: OnBeforeSendArgs): Promise<unknown> | unknown;
29
29
  onComplete?(args: OnCompleteArgs): Promise<unknown> | unknown;
30
30
  onError?(reason: Error): Promise<unknown> | unknown;
31
31
  onFatal?(reason: Error): Promise<unknown> | unknown;
32
32
  onResponse?(args: OnResponseArgs): Promise<unknown> | unknown;
33
- onSuccess?(args: OnSuccessArgs): Promise<unknown> | unknown;
33
+ onSuccess?(args: OnSuccessArgs<TData, TMeta>): Promise<unknown> | unknown;
34
34
  }
35
35
  export interface ParamsOptions {
36
36
  body?: FetchOptions['body'];
@@ -42,6 +42,6 @@ export interface ParamsOptions {
42
42
  query?: FetchOptions['query'];
43
43
  timeout?: FetchOptions['timeout'];
44
44
  }
45
- export type ApiOptions = ParamsOptions & HooksOptions & RefOptions;
45
+ export type ApiOptions<TData = unknown, TMeta = Record<string, unknown>> = ParamsOptions & HooksOptions<TData, TMeta> & RefOptions;
46
46
  declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
47
47
  export default _default;
@@ -4,13 +4,13 @@ import type { ApiOptions } from '../plugins/api.global';
4
4
  declare module '#app' {
5
5
  interface NuxtApp {
6
6
  $auth0: Auth0Client;
7
- $api: (url: string, options?: ApiOptions) => Promise<unknown>;
7
+ $api: (url: string, options?: ApiOptions) => Promise<void>;
8
8
  }
9
9
  }
10
10
 
11
11
  declare module 'vue' {
12
12
  interface ComponentCustomProperties {
13
13
  $auth0: Auth0Client;
14
- $api: (url: string, options?: ApiOptions) => Promise<unknown>;
14
+ $api: (url: string, options?: ApiOptions) => Promise<void>;
15
15
  }
16
16
  }
@@ -1,22 +1,13 @@
1
- import type { ComposableOptions } from '../composables/useApi.js';
1
+ import type { ComposableOptions, UseApiReturn } from '../composables/useApi.js';
2
2
  import type { HooksOptions } from '../plugins/api.global.js';
3
- type ReturnParams<T extends AdapterOptions> = () => {
4
- params?: T['params'];
5
- } & HooksOptions;
6
3
  export interface AdapterOptions {
7
4
  data: unknown;
8
- meta: Record<string, object>;
5
+ meta: Record<string, unknown>;
9
6
  params: object;
10
7
  }
11
- export declare const withAdapter: <T extends AdapterOptions>(callback: (params: T["params"]) => ComposableOptions) => (args?: ReturnParams<T>) => {
12
- abort: {
13
- (reason?: any): void;
14
- (reason?: any): void;
15
- };
16
- data: import("vue").Ref<unknown, unknown>;
17
- error: import("vue").Ref<Error | undefined, Error | undefined>;
18
- execute: (args?: Partial<T["params"]>) => any;
19
- loading: import("vue").Ref<boolean, boolean>;
20
- meta: import("vue").Ref<{}, {}>;
21
- };
8
+ export interface AdapterArgs<TData, TMeta, TParams> extends HooksOptions<TData, TMeta> {
9
+ params?: Partial<TParams>;
10
+ }
11
+ type AdapterCallback<T extends AdapterOptions> = (args: T['params']) => AdapterArgs<T['data'], T['meta'], T['params']>;
12
+ export declare const withAdapter: <T extends AdapterOptions>(callback: (params: T["params"]) => ComposableOptions<T["data"], T["meta"]>) => (args?: AdapterCallback<T>) => UseApiReturn<T["data"], T["meta"], T["params"]>;
22
13
  export {};
@@ -1,9 +1,11 @@
1
1
  import { useApi } from "../composables/useApi.js";
2
2
  import { defu } from "defu";
3
- export const withAdapter = (callback) => (args) => useApi((executionParams) => {
4
- const initialConfig = args?.() || {};
5
- const { params: initialParams = {}, ...hooks } = initialConfig;
6
- const mergedParams = defu(executionParams, initialParams);
7
- const adapterResult = callback(mergedParams);
8
- return defu(hooks, adapterResult);
9
- });
3
+ export const withAdapter = (callback) => (args) => {
4
+ return useApi((executionParams) => {
5
+ const config = args?.(executionParams) || {};
6
+ const { params: initialParams = {}, ...hooks } = config;
7
+ const mergedParams = defu(executionParams, initialParams);
8
+ const adapterResult = callback(mergedParams);
9
+ return defu(hooks, adapterResult);
10
+ });
11
+ };
package/dist/types.d.mts CHANGED
@@ -4,6 +4,10 @@ import type { default as Module } from './module.mjs'
4
4
 
5
5
  export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
6
 
7
+ export { type AdapterArgs, type AdapterOptions } from '../dist/runtime/utils/withAdapter.js'
8
+
9
+ export { type ApiOptions, type HooksOptions, type ParamsOptions, type RefOptions } from '../dist/runtime/plugins/api.global.js'
10
+
7
11
  export { default } from './module.mjs'
8
12
 
9
13
  export { type MerkalyModuleOptions } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkaly/nuxt",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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",
@@ -80,5 +66,17 @@
80
66
  },
81
67
  "engines": {
82
68
  "node": ">=20.0.0"
69
+ },
70
+ "scripts": {
71
+ "build": "nuxt-module-build build",
72
+ "build:stub": "nuxt-module-build build --stub",
73
+ "dev": "pnpm dev:prepare && cd playground && pnpm storybook",
74
+ "dev:build": "nuxi build playground",
75
+ "dev:prepare": "pnpm build:stub && nuxi prepare playground",
76
+ "lint": "eslint .",
77
+ "release": "pnpm lint && pnpm test && pnpm build && changelogen --release && npm publish --access public && git push --follow-tags",
78
+ "test": "vitest run",
79
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
80
+ "test:watch": "vitest watch"
83
81
  }
84
- }
82
+ }