@vite-hub/auth 0.4.0 → 0.5.0

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.
Files changed (66) hide show
  1. package/README.md +31 -7
  2. package/dist/{abilities-CbmTAoS_.d.ts → abilities-9jC7iuN0.d.ts} +2 -2
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/{ability-error-DcgChwCN.d.ts → ability-error-DUWJ6Q1W.d.ts} +1 -1
  5. package/dist/{ability-error-IeZQBr_-.js → ability-error-DmnUGicq.js} +1 -1
  6. package/dist/access-pages-FNQTyGRD.js +96 -0
  7. package/dist/agent.js +3 -3
  8. package/dist/{auth-instance-CmDogt4D.js → auth-instance-zYMjldPG.js} +227 -25
  9. package/dist/{cli-ubYJpAL_.d.ts → cli-NCtitmny.d.ts} +1 -0
  10. package/dist/cli.d.ts +1 -1
  11. package/dist/cli.js +1 -1
  12. package/dist/{console-runtime-_LrpyCYY.js → console-runtime-CuXRDhGy.js} +67 -33
  13. package/dist/{console-runtime-D2ai-Et5.d.ts → console-runtime-Dqidb3zF.d.ts} +13 -11
  14. package/dist/console-runtime.d.ts +2 -2
  15. package/dist/console-runtime.js +1 -1
  16. package/dist/console.d.ts +1 -1
  17. package/dist/{database-options-DpOVjUti.js → database-options-CcjUG-us.js} +1 -1
  18. package/dist/{database-schema-options-Sk-1Bvyu.js → database-schema-options-CTKCAfqW.js} +1 -1
  19. package/dist/database.d.ts +1 -1
  20. package/dist/database.js +4 -4
  21. package/dist/{definition-BCaLA9kW.js → definition-BFT9T6In.js} +12 -4
  22. package/dist/{error-diagnostics-Dymr-S_n.js → error-diagnostics-uEbxSY2G.js} +8 -2
  23. package/dist/{events-DCfuicoo.js → events-DJmO9a9I.js} +1 -1
  24. package/dist/forward.js +1 -1
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +4 -3
  27. package/dist/internal/server.d.ts +4 -4
  28. package/dist/internal/server.js +4 -4
  29. package/dist/{invariant-D8_xBqmZ.js → invariant-DolT9EEx.js} +1 -1
  30. package/dist/{mcp-token-CpxLyl_p.js → mcp-token-BhonlK9C.js} +2 -2
  31. package/dist/mcp.js +1 -1
  32. package/dist/{members-DdlsS8kJ.js → members-Cl3hFRjk.js} +3 -3
  33. package/dist/nitro-kit-32CVgbWS.js +44 -0
  34. package/dist/nuxt.d.ts +32 -19
  35. package/dist/nuxt.js +337 -16
  36. package/dist/own-access-C8pwo_Kn.js +31 -0
  37. package/dist/own-access-CdgEICjO.d.ts +20 -0
  38. package/dist/presets.js +1 -1
  39. package/dist/runtime/console.d.ts +1 -1
  40. package/dist/runtime/console.js +2 -2
  41. package/dist/runtime/empty-abilities.d.ts +1 -1
  42. package/dist/runtime/empty-definition.d.ts +1 -1
  43. package/dist/runtime/server.d.ts +3 -2
  44. package/dist/runtime/server.js +23 -14
  45. package/dist/runtime/vue-nuxt.js +70 -28
  46. package/dist/schema.d.ts +71 -19
  47. package/dist/schema.js +5 -3
  48. package/dist/{server-C8TlOrSy.d.ts → server-B-zNtSvm.d.ts} +9 -10
  49. package/dist/{server-BM-RSf1T.d.ts → server-Ci2i6p1S.d.ts} +7 -6
  50. package/dist/{server-BG_MFd4q.js → server-CyqLFm3L.js} +45 -25
  51. package/dist/server.d.ts +2 -2
  52. package/dist/server.js +2 -2
  53. package/dist/{session-cookies-DVzjOKc7.js → session-cookies-CZmZS5QF.js} +2 -2
  54. package/dist/{set-cookie-DmqWq6kj.js → set-cookie-DWIyCCJO.js} +1 -1
  55. package/dist/{table-specs-DbXyaXWs.d.ts → table-specs-BhWz_U0M.d.ts} +255 -1
  56. package/dist/{table-specs-CURphR3n.js → table-specs-D0VLp1U4.js} +43 -43
  57. package/dist/test.d.ts +1 -1
  58. package/dist/test.js +2 -2
  59. package/dist/{types-CruflEFI.d.ts → types-gl-myjZc.d.ts} +51 -4
  60. package/dist/{vite-Dy0Xhq4H.js → vite-QKjsPLwP.js} +349 -120
  61. package/dist/vite.d.ts +6 -2
  62. package/dist/vite.js +1 -1
  63. package/dist/vue.d.ts +17 -68
  64. package/dist/vue.js +22 -69
  65. package/package.json +13 -9
  66. package/dist/shared-DRtfuFsV.js +0 -12
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { C as AuthOptions, H as ResolvedAuthViteConfig } from "./types-CruflEFI.js";
3
- import { n as ViteHubCliPluginMetadata } from "./cli-ubYJpAL_.js";
2
+ import { U as ResolvedAuthViteConfig, w as AuthOptions } from "./types-gl-myjZc.js";
3
+ import { n as ViteHubCliPluginMetadata } from "./cli-NCtitmny.js";
4
4
  import { Plugin } from "vite";
5
5
  //#region ../internal/src/inspect.d.ts
6
6
  interface ViteHubDefinitionField {
@@ -52,6 +52,8 @@ interface ViteHubResourceSummary {
52
52
  owner: string;
53
53
  /** Absent when no id is known yet. */
54
54
  source?: ViteHubResourceIdSource;
55
+ /** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
56
+ standalone?: boolean;
55
57
  }
56
58
  interface ViteHubInspectionContributor {
57
59
  definitions?: readonly ViteHubDefinitionInspector[];
@@ -112,6 +114,8 @@ interface ContributionContext {
112
114
  projectRoot: string;
113
115
  /** Server directories that the host forwards, for example Nuxt's `serverDir` and the server directories of layers. */
114
116
  serverDirs?: readonly string[];
117
+ /** The flat list of Vite plugins, so a factory can read what sibling plugins declare. */
118
+ plugins?: readonly unknown[];
115
119
  }
116
120
  //#endregion
117
121
  //#region src/vite.d.ts
package/dist/vite.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as AUTH_VITE_PLUGIN_NAME, c as writeNuxtAuthDefinition, i as AUTH_SERVER_ID, l as resolveAuthViteConfig, n as AUTH_CLIENT_ID, o as createAuthNitroConfig, r as AUTH_DEFINITION_ID, s as hubAuth, t as AUTH_ABILITIES_ID } from "./vite-Dy0Xhq4H.js";
1
+ import { a as AUTH_VITE_PLUGIN_NAME, c as writeNuxtAuthDefinition, i as AUTH_SERVER_ID, l as resolveAuthViteConfig, n as AUTH_CLIENT_ID, o as createAuthNitroConfig, r as AUTH_DEFINITION_ID, s as hubAuth, t as AUTH_ABILITIES_ID } from "./vite-QKjsPLwP.js";
2
2
  export { AUTH_ABILITIES_ID, AUTH_CLIENT_ID, AUTH_DEFINITION_ID, AUTH_SERVER_ID, AUTH_VITE_PLUGIN_NAME, createAuthNitroConfig, hubAuth, resolveAuthViteConfig, writeNuxtAuthDefinition };
package/dist/vue.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { g as AuthDefinition, x as AuthFor } from "./types-CruflEFI.js";
3
- import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-CbmTAoS_.js";
4
- import { n as AbilityErrorData } from "./ability-error-DcgChwCN.js";
2
+ import { S as AuthFor, _ as AuthDefinition } from "./types-gl-myjZc.js";
3
+ import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-9jC7iuN0.js";
4
+ import { n as AbilityErrorData } from "./ability-error-DUWJ6Q1W.js";
5
5
  import { BetterAuthClientOptions } from "better-auth";
6
6
  import { ComputedRef, VNode } from "vue";
7
7
  import { inferAdditionalFields } from "better-auth/client/plugins";
@@ -181,7 +181,7 @@ type ServerFieldsClient<TOptions> = TOptions extends BetterAuthClientOptions ? V
181
181
  * Auth Definition's `basePath` below the `app.baseURL` of the page, also when `NUXT_APP_BASE_URL` sets it at runtime.
182
182
  */
183
183
  export declare const authClient: RegisteredAuthClient;
184
- /** Provide the app's configured client to Auth composables and `<Can>` in descendant components. */
184
+ /** Provide the app's configured client to Auth composables and `<AuthPermission>` in descendant components. */
185
185
  export declare function provideAuthClient(client: AuthClientLike): void;
186
186
  export declare function useAuthClient(): typeof authClient;
187
187
  type ClientSession<Client extends AuthClientLike> = Client["$Infer"]["Session"];
@@ -271,79 +271,28 @@ export interface Ability {
271
271
  * await authorize("posts.edit", loadedPost)
272
272
  */
273
273
  export declare function useAbility(client?: AuthClientLike): Ability;
274
- /**
275
- * How `<Can>` passes the arguments of a rule: no prop for a rule without arguments, `with` for a rule with one
276
- * (required or optional), and `args` with the list for every other rule, such as two arguments, a default after the
277
- * first, or a rest parameter.
278
- */
279
- type CanArguments<Args extends unknown[]> = Args extends [] ? {
280
- with?: never;
281
- args?: never;
282
- } : number extends Args["length"] ? {
283
- with?: never;
284
- args: Args;
285
- } : Exclude<Args["length"], 0> extends 1 ? (0 extends Args["length"] ? {
286
- with?: Args[0];
287
- args?: never;
274
+ /** The rule arguments use the same tuple as the server check. */
275
+ type PermissionArguments<Args extends unknown[]> = [] extends Args ? {
276
+ args?: Args;
288
277
  } : {
289
- with: Args[0];
290
- args?: never;
291
- }) : {
292
- with?: never;
293
278
  args: Args;
294
279
  };
295
- /**
296
- * The props of `<Can>`: a rule name in `do`, its arguments in `with` or `args`, and `pending` to show nothing while
297
- * the data for the arguments loads.
298
- */
299
- export type CanProps<Name extends AbilityName> = {
300
- do: Name;
280
+ export type AuthPermissionProps<Name extends AbilityName> = {
281
+ check: Name;
301
282
  pending?: boolean;
302
- } & CanArguments<AbilityArgs<Name>>;
303
- /** The slots of `<Can>`: the default slot when the rule allows, `#denied` with the refusal when it refuses. */
304
- export interface CanSlots<Name extends AbilityName> {
283
+ } & PermissionArguments<AbilityArgs<Name>>;
284
+ export interface AuthPermissionSlots<Name extends AbilityName> {
305
285
  default?: () => VNode[];
286
+ allowed?: () => VNode[];
306
287
  denied?: (refusal: AbilityRefusal<Name>) => VNode[];
307
288
  }
308
- /** The type that vue-tsc reads for a generic component, so `do` checks the name and `with`, `args` and `#denied` follow it. */
309
- export type CanComponent = <const Name extends AbilityName>(props: CanProps<Name>) => VNode & {
289
+ export type AuthPermissionComponent = <const Name extends AbilityName>(props: AuthPermissionProps<Name>) => VNode & {
310
290
  __ctx?: {
311
- props: CanProps<Name>;
312
- slots: CanSlots<Name>;
291
+ props: AuthPermissionProps<Name>;
292
+ slots: AuthPermissionSlots<Name>;
313
293
  };
314
294
  };
315
- /**
316
- * Shows its content when a rule from `shared/abilities.ts` allows the visitor, the `#denied` slot with the refusal when
317
- * it refuses, and nothing while the session is unknown or `pending` is `true`.
318
- *
319
- * @example
320
- * <Can do="posts.edit" :with="post">
321
- * <button>Edit</button>
322
- * <template #denied="{ code }">{{ code }}</template>
323
- * </Can>
324
- * <Can do="posts.move" :args="[from, to]">Move</Can>
325
- */
326
- export declare const Can: CanComponent;
327
- /** The slot of `<Cannot>`: its content, with the refusal, when the rule refuses. */
328
- export interface CannotSlots<Name extends AbilityName> {
329
- default?: (refusal: AbilityRefusal<Name>) => VNode[];
330
- }
331
- /** The type that vue-tsc reads for `<Cannot>`: the props of `<Can>`, and the refusal in the default slot. */
332
- export type CannotComponent = <const Name extends AbilityName>(props: CanProps<Name>) => VNode & {
333
- __ctx?: {
334
- props: CanProps<Name>;
335
- slots: CannotSlots<Name>;
336
- };
337
- };
338
- /**
339
- * The mirror of `<Can>`: shows its content, with the refusal, only when a rule from `shared/abilities.ts` refuses the
340
- * visitor. It shows nothing when the rule allows, while the session is unknown, or while `pending` is `true`.
341
- *
342
- * @example
343
- * <Cannot do="billing.upgrade" v-slot="{ code, details }">
344
- * <UpgradeHint :code="code" :limit="details.limit" />
345
- * </Cannot>
346
- */
347
- export declare const Cannot: CannotComponent;
295
+ /** Render the allowed or denied slot. The default slot is shorthand for allowed. */
296
+ export declare const AuthPermission: AuthPermissionComponent;
348
297
  //#endregion
349
298
  export type { RequestFetch, VueAuthClient };
package/dist/vue.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { i as resolveAuthMountPath } from "./application-path-DuTpfGFj.js";
2
- import { n as checkAbility, t as AbilityError } from "./ability-error-IeZQBr_-.js";
2
+ import { n as checkAbility, t as AbilityError } from "./ability-error-DmnUGicq.js";
3
3
  import { a as setRequestFetchResolver, i as setNuxtErrorFactory, n as setDefaultAuthBasePath, o as setSessionSeedResolver, r as setNuxtAppResolver, s as setSignOutHandler, t as authNuxtBridge } from "./nuxt-bridge-Cl988STZ.js";
4
4
  import abilities from "#vitehub/auth/abilities";
5
5
  import { computed, defineComponent, effectScope, getCurrentInstance, getCurrentScope, inject, onScopeDispose, onServerPrefetch, provide, shallowRef, watch } from "vue";
@@ -405,7 +405,7 @@ const authClient = createLazyAuthClient(async () => {
405
405
  const { default: options } = await import("#vitehub/auth/client");
406
406
  return withDefaultBasePath(options);
407
407
  });
408
- /** Provide the app's configured client to Auth composables and `<Can>` in descendant components. */
408
+ /** Provide the app's configured client to Auth composables and `<AuthPermission>` in descendant components. */
409
409
  function provideAuthClient(client) {
410
410
  provide(authClientKey, client);
411
411
  }
@@ -574,54 +574,30 @@ function useAbility(client = useAuthClient()) {
574
574
  ready: computed(() => !state.value.isPending)
575
575
  };
576
576
  }
577
- /** The runtime props of `<Can>` and `<Cannot>`. */
578
- const abilityProps = {
579
- do: {
580
- type: String,
581
- required: true
582
- },
583
- with: {
584
- type: null,
585
- default: void 0
586
- },
587
- args: {
588
- type: Array,
589
- default: void 0
577
+ /** Render the allowed or denied slot. The default slot is shorthand for allowed. */
578
+ const AuthPermission = defineComponent({
579
+ name: "AuthPermission",
580
+ props: {
581
+ check: {
582
+ type: String,
583
+ required: true
584
+ },
585
+ args: {
586
+ type: Array,
587
+ default: () => []
588
+ },
589
+ pending: {
590
+ type: Boolean,
591
+ default: false
592
+ }
590
593
  },
591
- pending: {
592
- type: Boolean,
593
- default: false
594
- }
595
- };
596
- /** The refusal of the rule that the props name. It follows the session, and is `undefined` while `pending` is `true`. */
597
- function usePropsRefusal(props) {
598
- const state = sessionState();
599
- return computed(() => {
600
- if (props.pending) return void 0;
601
- const args = props.args ?? (props.with === void 0 ? [] : [props.with]);
602
- return abilityRefusal(state.value, props.do, args);
603
- });
604
- }
605
- /**
606
- * Shows its content when a rule from `shared/abilities.ts` allows the visitor, the `#denied` slot with the refusal when
607
- * it refuses, and nothing while the session is unknown or `pending` is `true`.
608
- *
609
- * @example
610
- * <Can do="posts.edit" :with="post">
611
- * <button>Edit</button>
612
- * <template #denied="{ code }">{{ code }}</template>
613
- * </Can>
614
- * <Can do="posts.move" :args="[from, to]">Move</Can>
615
- */
616
- const Can = defineComponent({
617
- name: "Can",
618
- props: abilityProps,
619
594
  setup(props, { slots }) {
620
- const refusal = usePropsRefusal(props);
595
+ const state = sessionState();
596
+ const refusal = computed(() => props.pending ? void 0 : abilityRefusal(state.value, props.check, props.args));
621
597
  return () => {
622
598
  const value = refusal.value;
623
599
  if (value === void 0) return null;
624
- if (value === null) return slots.default?.();
600
+ if (value === null) return (slots.allowed ?? slots.default)?.();
625
601
  return slots.denied?.({
626
602
  code: value.code,
627
603
  details: value.details
@@ -629,28 +605,5 @@ const Can = defineComponent({
629
605
  };
630
606
  }
631
607
  });
632
- /**
633
- * The mirror of `<Can>`: shows its content, with the refusal, only when a rule from `shared/abilities.ts` refuses the
634
- * visitor. It shows nothing when the rule allows, while the session is unknown, or while `pending` is `true`.
635
- *
636
- * @example
637
- * <Cannot do="billing.upgrade" v-slot="{ code, details }">
638
- * <UpgradeHint :code="code" :limit="details.limit" />
639
- * </Cannot>
640
- */
641
- const Cannot = defineComponent({
642
- name: "Cannot",
643
- props: abilityProps,
644
- setup(props, { slots }) {
645
- const refusal = usePropsRefusal(props);
646
- return () => {
647
- const value = refusal.value;
648
- return value ? slots.default?.({
649
- code: value.code,
650
- details: value.details
651
- }) : null;
652
- };
653
- }
654
- });
655
608
  //#endregion
656
- export { Can, Cannot, authClient, createAuthClient, defineAuthClient, loadAuthClient, onSignOut, provideAuthClient, setDefaultAuthBasePath, setNuxtAppResolver, setNuxtErrorFactory, setRequestFetchResolver, setSessionSeedResolver, setSignOutHandler, useAbility, useAuthClient, useUserSession };
609
+ export { AuthPermission, authClient, createAuthClient, defineAuthClient, loadAuthClient, onSignOut, provideAuthClient, setDefaultAuthBasePath, setNuxtAppResolver, setNuxtErrorFactory, setRequestFetchResolver, setSessionSeedResolver, setSignOutHandler, useAbility, useAuthClient, useUserSession };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/auth",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Better Auth-powered authentication primitives and Vite integration for ViteHub.",
5
5
  "keywords": [
6
6
  "auth",
@@ -144,14 +144,17 @@
144
144
  "dependencies": {
145
145
  "@noble/hashes": "^2.2.0",
146
146
  "@types/node": "^24.19.1",
147
- "@vite-hub/env": "0.4.0",
148
- "@vite-hub/runtime": "0.4.0",
149
- "@vite-hub/web-container": "0.4.0",
147
+ "@vite-hub/env": "0.5.0",
148
+ "@vite-hub/runtime": "0.5.0",
149
+ "@vite-hub/web-container": "0.5.0",
150
150
  "better-auth": "^1.7.15",
151
151
  "h3": "^2.0.8",
152
152
  "nostics": "1.4.0",
153
153
  "rou3": "^1.0.0",
154
- "valibot": "^1.5.0"
154
+ "scule": "^1.3.0",
155
+ "unrouting": "^0.3.2",
156
+ "valibot": "^1.5.0",
157
+ "vue-router": "^5.4.0"
155
158
  },
156
159
  "devDependencies": {
157
160
  "@better-auth/api-key": "1.7.15",
@@ -162,10 +165,11 @@
162
165
  "@types/json-schema": "^7.0.15",
163
166
  "@types/mdast": "^4.0.4",
164
167
  "@types/node": "^24.19.1",
165
- "@vite-hub/agent": "0.4.0",
166
- "@vite-hub/database": "0.4.0",
168
+ "@vite-hub/agent": "0.5.0",
169
+ "@vite-hub/database": "0.5.0",
167
170
  "@vite-hub/internal": "0.0.1",
168
171
  "bun-types": "^1.4.3",
172
+ "evlog": "2.33.1",
169
173
  "happy-dom": "20.14.5",
170
174
  "miniflare": "4.20260730.0",
171
175
  "nitro": "^3.0.261103-rc",
@@ -184,8 +188,8 @@
184
188
  "@better-auth/oauth-provider": "^1.7.15",
185
189
  "@types/json-schema": "^7.0.15",
186
190
  "@types/mdast": "^4.0.4",
187
- "@vite-hub/agent": "0.4.0",
188
- "@vite-hub/database": "0.4.0",
191
+ "@vite-hub/agent": "0.5.0",
192
+ "@vite-hub/database": "0.5.0",
189
193
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
190
194
  "vite": ">=8.0.0",
191
195
  "vue": "^3.5.0",
@@ -1,12 +0,0 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
2
- //#region src/shared.ts
3
- const defaultAuthBasePath = "/api/auth";
4
- function normalizeAuthBasePath(value) {
5
- const path = value?.trim() || defaultAuthBasePath;
6
- if (!path.startsWith("/")) throw authErrorDiagnostics.AUTH_R0013({ message: "`defineAuth()` basePath must start with `/`." });
7
- const normalized = path.replace(/\/+$/g, "");
8
- if (!normalized) throw authErrorDiagnostics.AUTH_R0013({ message: "`defineAuth()` basePath must resolve to a non-empty path." });
9
- return normalized;
10
- }
11
- //#endregion
12
- export { normalizeAuthBasePath as t };