@atls/nestjs-keto 0.0.9 → 0.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+
2
+
3
+ ## [0.0.11](https://github.com/atls/nestjs/compare/@atls/nestjs-keto@0.0.10...@atls/nestjs-keto@0.0.11) (2026-01-08)
4
+
5
+
6
+
7
+
8
+
9
+
10
+ ## 0.0.9 (2025-12-31)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+
16
+ * **packages:** linter errors ([204ce22](https://github.com/atls/nestjs/commit/204ce229e375b09ffd69d93e47c08bd1d1fbea1b))
17
+ * **packages:** tests ([ae0f308](https://github.com/atls/nestjs/commit/ae0f308e695cfe39b4e2d38b6a33be4f7e5a8821))
18
+
19
+ ### Features
20
+
21
+
22
+ * **batch-queue:** init ([6ecbffa](https://github.com/atls/nestjs/commit/6ecbffa3fc54f9bb33ac1ae57b274772b99c8e9d))
23
+ * **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
24
+
25
+
@@ -1,2 +1,2 @@
1
1
  import { GUARDED_BY_METADATA_KEY } from './guarded-by-keto.constants.js';
2
- export const getGuardingRelationTuple = (reflector, handler) => reflector.get(GUARDED_BY_METADATA_KEY, handler) ?? null;
2
+ export const getGuardingRelationTuple = (reflector, handler) => reflector.get(GUARDED_BY_METADATA_KEY, handler);
@@ -1,5 +1,5 @@
1
1
  import type { CustomDecorator } from '@nestjs/common';
2
2
  import type { Reflector } from '@nestjs/core';
3
- export type GetGuardingRelationTuple = (reflector: Reflector, handler: Parameters<Reflector['get']>[1]) => ReplaceGenerator | string;
3
+ export type GetGuardingRelationTuple = (reflector: Reflector, handler: Parameters<Reflector['get']>[1]) => ReplaceGenerator | string | undefined;
4
4
  export type ReplaceGenerator = (value: string) => string;
5
5
  export type GuardedByKetoFunction = (relationTuple: ReplaceGenerator | string) => CustomDecorator<symbol>;
@@ -32,7 +32,7 @@ let KetoGuard = class KetoGuard {
32
32
  if (!userId)
33
33
  return false;
34
34
  const relationTuple = getGuardingRelationTuple(this.reflector, context.getHandler());
35
- if (relationTuple === null)
35
+ if (!relationTuple)
36
36
  return false;
37
37
  const converter = new RelationTupleConverter(relationTuple, userId);
38
38
  const tuple = converter.run();
@@ -44,14 +44,22 @@ let KetoGuard = class KetoGuard {
44
44
  }
45
45
  getUserId(ctx) {
46
46
  const contextType = ctx.getType();
47
- let metadata;
48
47
  switch (contextType) {
49
- case 'graphql':
50
- metadata = GqlExecutionContext.create(ctx).getContext();
51
- return metadata.user;
52
- default:
53
- metadata = ctx.switchToHttp().getRequest();
54
- return metadata.get('x_user') ?? metadata.get('x-user');
48
+ case 'graphql': {
49
+ const graphqlContext = GqlExecutionContext.create(ctx).getContext();
50
+ return graphqlContext.user ?? null;
51
+ }
52
+ default: {
53
+ const request = ctx.switchToHttp().getRequest();
54
+ const headerValue = request.get?.('x_user') ??
55
+ request.get?.('x-user') ??
56
+ request.headers?.x_user ??
57
+ request.headers?.['x-user'];
58
+ if (Array.isArray(headerValue)) {
59
+ return headerValue[0] ?? null;
60
+ }
61
+ return headerValue ?? null;
62
+ }
55
63
  }
56
64
  }
57
65
  };
@@ -1,5 +1,7 @@
1
1
  import type { Type } from '@nestjs/common/interfaces';
2
2
  import type { ModuleMetadata } from '@nestjs/common/interfaces';
3
+ import type { InjectionToken } from '@nestjs/common/interfaces';
4
+ import type { OptionalFactoryDependency } from '@nestjs/common/interfaces';
3
5
  import type { ConfigurationParameters } from '@ory/keto-client';
4
6
  import type { SubjectSet } from '@ory/keto-client';
5
7
  export interface KetoModuleOptions extends ConfigurationParameters {
@@ -11,8 +13,8 @@ export interface KetoOptionsFactory {
11
13
  export interface KetoModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
12
14
  useExisting?: Type<KetoOptionsFactory>;
13
15
  useClass?: Type<KetoOptionsFactory>;
14
- useFactory?: (...args: Array<any>) => KetoModuleOptions | Promise<KetoModuleOptions>;
15
- inject?: Array<any>;
16
+ useFactory?: (...args: Array<unknown>) => KetoModuleOptions | Promise<KetoModuleOptions>;
17
+ inject?: Array<InjectionToken | OptionalFactoryDependency>;
16
18
  global?: boolean;
17
19
  }
18
20
  export type RelationShipTuple = RelationShipTupleWithId | RelationShipTupleWithSet;
@@ -14,7 +14,7 @@ let KetoModule = KetoModule_1 = class KetoModule {
14
14
  const optionsProvider = createKetoConfigurationProvider(options);
15
15
  const exportsProvider = createKetoExportsProvider();
16
16
  return {
17
- global: options?.global ?? true,
17
+ global: options.global ?? true,
18
18
  module: KetoModule_1,
19
19
  providers: [...optionsProvider, ...exportsProvider],
20
20
  exports: exportsProvider,
@@ -23,7 +23,7 @@ let KetoModule = KetoModule_1 = class KetoModule {
23
23
  static registerAsync(options) {
24
24
  const exportsProvider = createKetoExportsProvider();
25
25
  return {
26
- global: options?.global ?? true,
26
+ global: options.global ?? true,
27
27
  module: KetoModule_1,
28
28
  imports: options.imports || [],
29
29
  providers: [...this.createAsyncProviders(options), ...exportsProvider],
@@ -34,6 +34,9 @@ let KetoModule = KetoModule_1 = class KetoModule {
34
34
  if (options.useExisting || options.useFactory) {
35
35
  return [this.createAsyncOptionsProvider(options)];
36
36
  }
37
+ if (!options.useClass) {
38
+ throw new Error('KetoModule requires useClass when useExisting/useFactory not provided');
39
+ }
37
40
  return [
38
41
  this.createAsyncOptionsProvider(options),
39
42
  {
@@ -50,10 +53,14 @@ let KetoModule = KetoModule_1 = class KetoModule {
50
53
  inject: options.inject || [],
51
54
  };
52
55
  }
56
+ const injectTarget = options.useExisting ?? options.useClass;
57
+ if (!injectTarget) {
58
+ throw new Error('KetoModule requires useExisting, useClass, or useFactory');
59
+ }
53
60
  return {
54
61
  provide: KETO_MODULE_CONFIGURATION,
55
62
  useFactory: async (optionsFactory) => optionsFactory.createKetoOptions(),
56
- inject: [options.useExisting || options.useClass],
63
+ inject: [injectTarget],
57
64
  };
58
65
  }
59
66
  };
@@ -1,4 +1,4 @@
1
- import { ConfigurationParameters } from '@ory/keto-client';
1
+ import type { ConfigurationParameters } from '@ory/keto-client';
2
2
  import { Configuration } from '@ory/keto-client';
3
3
  export declare class KetoConfigurationService extends Configuration {
4
4
  private readonly options;
@@ -23,7 +23,7 @@ let KetoReadClientService = class KetoReadClientService {
23
23
  async validateRelationTuple(request) {
24
24
  try {
25
25
  let data;
26
- if (request.subject_id !== undefined) {
26
+ if ('subject_id' in request) {
27
27
  const req = request;
28
28
  data = {
29
29
  relation: req.relation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atls/nestjs-keto",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "license": "BSD-3-Clause",
5
5
  "type": "module",
6
6
  "exports": {