From e2b63733baff534d910f55e128791f6535117c0f Mon Sep 17 00:00:00 2001 From: Andres Aguiar Date: Thu, 2 Apr 2026 07:00:33 -0400 Subject: [PATCH 1/3] fix: improved contextual tuples layout for check/batch check --- .../SnippetViewer/BatchCheckRequestViewer.tsx | 15 ++++++--- .../Docs/SnippetViewer/CheckRequestViewer.tsx | 33 +++++++++++++++---- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx b/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx index 467ff38c9b..9ace76070f 100644 --- a/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx +++ b/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx @@ -398,11 +398,18 @@ Reply:${checks }, "correlation_id": "${check.correlation_id}"${ check.contextualTuples - ? `,"contextual_tuples":{"tuple_keys":[${check.contextualTuples - .map((tuple) => `{"user":"${tuple.user}","relation":"${tuple.relation}","object":"${tuple.object}"}`) - .join(',')}]}` + ? `, + "contextual_tuples": { + "tuple_keys": [${check.contextualTuples + .map( + (tuple) => ` + {"user": "${tuple.user}", "relation": "${tuple.relation}", "object": "${tuple.object}"}`, + ) + .join(',')} + ] + }` : '' - }${check.context ? `,"context":${JSON.stringify(check.context)}}` : ''} + }${check.context ? `,\n "context": ${JSON.stringify(check.context)}` : ''} }, `, ) diff --git a/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx b/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx index 324534e45f..f6c9e38ba4 100644 --- a/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx +++ b/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx @@ -73,15 +73,28 @@ ${ .join('') : '' } - -d '{${modelId ? `"authorization_model_id": "${modelId}", ` : ''}"tuple_key":{"user":"${user}","relation":"${relation}","object":"${object}"}${ + -d '{${modelId ? `\n "authorization_model_id": "${modelId}",` : ''} + "tuple_key": { + "user": "${user}", + "relation": "${relation}", + "object": "${object}" + }${ contextualTuples - ? `,"contextual_tuples":{"tuple_keys":[${contextualTuples - .map((tuple) => `{"user":"${tuple.user}","relation":"${tuple.relation}","object":"${tuple.object}"}`) - .join(',')}]}` + ? `, + "contextual_tuples": { + "tuple_keys": [${contextualTuples + .map( + (tuple) => ` + {"user": "${tuple.user}", "relation": "${tuple.relation}", "object": "${tuple.object}"}`, + ) + .join(',')} + ] + }` : '' - }${context ? `,"context":${JSON.stringify(context)}}` : '}'}' + }${context ? `,\n "context": ${JSON.stringify(context)}` : ''} + }' -# Response: {"allowed":${allowed}}`; +# Response: {"allowed": ${allowed}}`; case SupportedLanguage.JS_SDK: return ` @@ -93,7 +106,13 @@ const { allowed } = await fgaClient.check({ !contextualTuples ? `` : ` - contextualTuples: [\n ${contextualTuples.map((tuple) => `${JSON.stringify(tuple)}`).join(',')} + contextualTuples: [ + ${contextualTuples + .map( + (tuple) => + `{\n user: '${tuple.user}',\n relation: '${tuple.relation}',\n object: '${tuple.object}',\n }`, + ) + .join(',\n ')} ],` }${!context ? `\n }` : `\n context: ${JSON.stringify(context)}\n }`}, {${ modelId ? `\n authorizationModelId: '${modelId}',` : '' From cd2d55fa465320bac9999f39a4150c5c2e06b9f2 Mon Sep 17 00:00:00 2001 From: Andres Aguiar Date: Thu, 2 Apr 2026 07:09:34 -0400 Subject: [PATCH 2/3] fix: formatting --- .../SnippetViewer/BatchCheckRequestViewer.tsx | 8 ++++---- .../Docs/SnippetViewer/CheckRequestViewer.tsx | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx b/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx index 9ace76070f..be42a33802 100644 --- a/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx +++ b/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx @@ -401,11 +401,11 @@ Reply:${checks ? `, "contextual_tuples": { "tuple_keys": [${check.contextualTuples - .map( - (tuple) => ` + .map( + (tuple) => ` {"user": "${tuple.user}", "relation": "${tuple.relation}", "object": "${tuple.object}"}`, - ) - .join(',')} + ) + .join(',')} ] }` : '' diff --git a/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx b/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx index f6c9e38ba4..e39ff745b8 100644 --- a/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx +++ b/src/components/Docs/SnippetViewer/CheckRequestViewer.tsx @@ -79,19 +79,19 @@ ${ "relation": "${relation}", "object": "${object}" }${ - contextualTuples - ? `, + contextualTuples + ? `, "contextual_tuples": { "tuple_keys": [${contextualTuples - .map( - (tuple) => ` + .map( + (tuple) => ` {"user": "${tuple.user}", "relation": "${tuple.relation}", "object": "${tuple.object}"}`, - ) - .join(',')} + ) + .join(',')} ] }` - : '' - }${context ? `,\n "context": ${JSON.stringify(context)}` : ''} + : '' + }${context ? `,\n "context": ${JSON.stringify(context)}` : ''} }' # Response: {"allowed": ${allowed}}`; From 908ca263608a5eda558ece1e0b14d8551d6ea811 Mon Sep 17 00:00:00 2001 From: Andres Aguiar Date: Thu, 2 Apr 2026 09:36:31 -0400 Subject: [PATCH 3/3] chore: address feedback --- .../Docs/SnippetViewer/BatchCheckRequestViewer.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx b/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx index be42a33802..a4f760d844 100644 --- a/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx +++ b/src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx @@ -390,11 +390,11 @@ Reply:${checks "checks": [ ${checks .map( - (check) => ` { + (check, index) => ` { "tuple_key": { "user":"${check.user}", "relation":"${check.relation}", - "object":"${check.object}", + "object":"${check.object}" }, "correlation_id": "${check.correlation_id}"${ check.contextualTuples @@ -410,10 +410,12 @@ Reply:${checks }` : '' }${check.context ? `,\n "context": ${JSON.stringify(check.context)}` : ''} - }, + }${index < checks.length - 1 ? ',' : ''} `, ) .join('')} + ] +}' # Response: {