Skip to content

Commit b97ed54

Browse files
authored
Merge pull request #107 from getlarge/fix-keto-relations-parser-update-invalid-conditions
fix(keto-relations-parser): update invalid conditions
2 parents c7981c6 + 4864c5a commit b97ed54

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

packages/keto-cli/src/app/get-relations.command.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import {
44
IRelationTuple,
55
} from '@getlarge/keto-relations-parser';
66
import { Logger } from '@nestjs/common';
7+
import { ConfigService } from '@nestjs/config';
78
import { Configuration, Relationship } from '@ory/client';
89
import { Command, CommandRunner, Option } from 'nest-commander';
910

11+
import { OryKetoEnvironmentVariables } from './environment-variables';
12+
1013
interface CommandOptions
1114
extends Pick<Configuration, 'basePath' | 'accessToken'> {
1215
namespace: string;
@@ -22,7 +25,11 @@ export class GetRelationsCommand extends CommandRunner {
2225
readonly logger = new Logger(GetRelationsCommand.name);
2326

2427
constructor(
25-
private readonly oryRelationshipsService: OryRelationshipsService
28+
private readonly oryRelationshipsService: OryRelationshipsService,
29+
private readonly configService: ConfigService<
30+
OryKetoEnvironmentVariables,
31+
true
32+
>
2633
) {
2734
super();
2835
}
@@ -36,6 +43,10 @@ export class GetRelationsCommand extends CommandRunner {
3643
subjectObject,
3744
subjectRelation,
3845
} = options;
46+
/**
47+
* Use the correct base path since the SDK assign the GET /relation-tuples endpoint to the admin API
48+
*/
49+
options.basePath ??= this.configService.get('ORY_KETO_PUBLIC_URL');
3950
if (options.basePath || options.accessToken) {
4051
this.oryRelationshipsService.config = new Configuration({
4152
...this.oryRelationshipsService.config,

packages/keto-relations-parser/src/lib/keto-converters/tuple-to-relationships-parameters.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export function createRelationQuery<
9191
},
9292
(v) => v === undefined || v === null
9393
) as unknown as RelationQuery['subject_set'];
94-
} else {
94+
} else if (
95+
typeof subjectIdOrSet === 'string' ||
96+
typeof subjectIdOrSet === 'function'
97+
) {
9598
result.subject_id =
9699
resolveTupleProperty('subjectIdOrSet', tuple, replacements) ?? '';
97100
}
@@ -133,7 +136,10 @@ export function createFlattenRelationQuery<
133136
result.subjectSetRelation =
134137
resolveTupleProperty('subjectIdOrSet.relation', tuple, replacements) ??
135138
'';
136-
} else {
139+
} else if (
140+
typeof subjectIdOrSet === 'string' ||
141+
typeof subjectIdOrSet === 'function'
142+
) {
137143
result.subjectId =
138144
resolveTupleProperty('subjectIdOrSet', tuple, replacements) ?? '';
139145
}
@@ -171,7 +177,7 @@ export function createRelationship<
171177

172178
if (typeof tuple.subjectIdOrSet === 'string') {
173179
result.subject_id = tuple.subjectIdOrSet;
174-
} else {
180+
} else if (typeof tuple.subjectIdOrSet === 'object') {
175181
result.subject_set = {
176182
...tuple.subjectIdOrSet,
177183
relation: tuple.subjectIdOrSet.relation ?? '',
@@ -192,7 +198,7 @@ export function createRelationship<
192198

193199
if (typeof tuple.subjectIdOrSet === 'function') {
194200
result.subject_id = tuple.subjectIdOrSet(replacements);
195-
} else {
201+
} else if (typeof tuple.subjectIdOrSet === 'object') {
196202
result.subject_set = {
197203
namespace: tuple.subjectIdOrSet.namespace(replacements),
198204
object: tuple.subjectIdOrSet.object(replacements),

0 commit comments

Comments
 (0)