Skip to content

Commit

Permalink
Merge pull request #107 from getlarge/fix-keto-relations-parser-updat…
Browse files Browse the repository at this point in the history
…e-invalid-conditions

fix(keto-relations-parser): update invalid conditions
  • Loading branch information
getlarge authored Oct 8, 2024
2 parents c7981c6 + 4864c5a commit b97ed54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 12 additions & 1 deletion packages/keto-cli/src/app/get-relations.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import {
IRelationTuple,
} from '@getlarge/keto-relations-parser';
import { Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Configuration, Relationship } from '@ory/client';
import { Command, CommandRunner, Option } from 'nest-commander';

import { OryKetoEnvironmentVariables } from './environment-variables';

interface CommandOptions
extends Pick<Configuration, 'basePath' | 'accessToken'> {
namespace: string;
Expand All @@ -22,7 +25,11 @@ export class GetRelationsCommand extends CommandRunner {
readonly logger = new Logger(GetRelationsCommand.name);

constructor(
private readonly oryRelationshipsService: OryRelationshipsService
private readonly oryRelationshipsService: OryRelationshipsService,
private readonly configService: ConfigService<
OryKetoEnvironmentVariables,
true
>
) {
super();
}
Expand All @@ -36,6 +43,10 @@ export class GetRelationsCommand extends CommandRunner {
subjectObject,
subjectRelation,
} = options;
/**
* Use the correct base path since the SDK assign the GET /relation-tuples endpoint to the admin API
*/
options.basePath ??= this.configService.get('ORY_KETO_PUBLIC_URL');
if (options.basePath || options.accessToken) {
this.oryRelationshipsService.config = new Configuration({
...this.oryRelationshipsService.config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export function createRelationQuery<
},
(v) => v === undefined || v === null
) as unknown as RelationQuery['subject_set'];
} else {
} else if (
typeof subjectIdOrSet === 'string' ||
typeof subjectIdOrSet === 'function'
) {
result.subject_id =
resolveTupleProperty('subjectIdOrSet', tuple, replacements) ?? '';
}
Expand Down Expand Up @@ -133,7 +136,10 @@ export function createFlattenRelationQuery<
result.subjectSetRelation =
resolveTupleProperty('subjectIdOrSet.relation', tuple, replacements) ??
'';
} else {
} else if (
typeof subjectIdOrSet === 'string' ||
typeof subjectIdOrSet === 'function'
) {
result.subjectId =
resolveTupleProperty('subjectIdOrSet', tuple, replacements) ?? '';
}
Expand Down Expand Up @@ -171,7 +177,7 @@ export function createRelationship<

if (typeof tuple.subjectIdOrSet === 'string') {
result.subject_id = tuple.subjectIdOrSet;
} else {
} else if (typeof tuple.subjectIdOrSet === 'object') {
result.subject_set = {
...tuple.subjectIdOrSet,
relation: tuple.subjectIdOrSet.relation ?? '',
Expand All @@ -192,7 +198,7 @@ export function createRelationship<

if (typeof tuple.subjectIdOrSet === 'function') {
result.subject_id = tuple.subjectIdOrSet(replacements);
} else {
} else if (typeof tuple.subjectIdOrSet === 'object') {
result.subject_set = {
namespace: tuple.subjectIdOrSet.namespace(replacements),
object: tuple.subjectIdOrSet.object(replacements),
Expand Down

0 comments on commit b97ed54

Please sign in to comment.