Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions docs/content/getting-started/update-tuples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,23 @@ For example, if you want to ensure `user:anne` has `reader` access to `document:
object: 'document:Z'
},
]}
writeOptions={{
on_duplicate: 'ignore',
conflictOptions={{
onDuplicateWrites: 'ignore',
}}
skipSetup={true}
allowedLanguages={[
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
/>

:::caution
At the moment, this feature is only available on the API (v1.10.0). Supported SDKs will follow shortly after.
At the moment, this feature requires [OpenFGA v1.10.0](https://github.com/openfga/openfga/releases/tag/v1.10.0)+. All latest releases of the SDKs support this.
:::

Similarly, you can use `on_missing: "ignore"` when deleting tuples that might not exist.
Expand All @@ -281,13 +287,19 @@ Similarly, you can use `on_missing: "ignore"` when deleting tuples that might no
object: 'document:Z'
},
]}
deleteOptions={{
on_missing: 'ignore',
conflictOptions={{
onMissingDeletes: 'ignore',
}}
expectedResponse={{
data: {},
}}
allowedLanguages={[
SupportedLanguage.JS_SDK,
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
/>
Expand Down
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const config = {
: 'https://raw.githubusercontent.com/openfga/api/main/docs/openapiv2/apidocs.swagger.json',

// Customization for product information
/* eslint-disable max-len */
description: `OpenFGA is an open source Fine-Grained Authorization solution based on Google's Zanzibar.`,
productName: `OpenFGA`,
// link to product description section (relative to baseURL)
Expand Down
2 changes: 0 additions & 2 deletions src/components/Docs/AuthorizationModel/SyntaxTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { AuthorizationModel, TypeDefinition } from '@openfga/sdk';
import { transformer } from '@openfga/syntax-transformer';
import { constants } from '@openfga/frontend-utils';
Expand Down
5 changes: 1 addition & 4 deletions src/components/Docs/SnippetViewer/CheckRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ ${

# Response: {"allowed":${allowed}}`;
case SupportedLanguage.CURL:
/* eslint-disable max-len */
return `curl -X POST $FGA_API_URL/stores/$FGA_STORE_ID/check \\
-H "Authorization: Bearer $FGA_API_TOKEN" \\ # Not needed if service does not require authorization
-H "content-type: application/json" \\${
Expand All @@ -83,7 +82,7 @@ ${
}${context ? `,"context":${JSON.stringify(context)}}` : '}'}'

# Response: {"allowed":${allowed}}`;
/* eslint-enable max-len */

case SupportedLanguage.JS_SDK:
return `
// Run a check
Expand All @@ -109,7 +108,6 @@ const { allowed } = await fgaClient.check({

// allowed = ${allowed}`;
case SupportedLanguage.GO_SDK:
/* eslint-disable no-tabs */
return `
options := ClientCheckOptions{${
modelId
Expand Down Expand Up @@ -314,7 +312,6 @@ var response = fgaClient.check(body, options).get();
default:
assertNever(lang);
}
/* eslint-enable no-tabs */
}

export function CheckRequestViewer(opts: CheckRequestViewerOpts): JSX.Element {
Expand Down
4 changes: 0 additions & 4 deletions src/components/Docs/SnippetViewer/ExpandRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ function expandRequestViewer(lang: SupportedLanguage, opts: ExpandRequestViewerO
const modelId = opts.authorizationModelId ? opts.authorizationModelId : DefaultAuthorizationModelId;
switch (lang) {
case SupportedLanguage.CLI:
// eslint-disable-next-line max-len
return `fga query expand --store-id=\${FGA_STORE_ID} --model-id=${modelId} ${opts.relation} ${opts.object}

# Response: {"tree": ...}`;
case SupportedLanguage.CURL:
// eslint-disable-next-line max-len
return `curl -X POST $FGA_API_URL/stores/$FGA_STORE_ID/expand \\
-H "Authorization: Bearer $FGA_API_TOKEN" \\ # Not needed if service does not require authorization
-H "content-type: application/json" \\
Expand All @@ -38,7 +36,6 @@ const { tree } = await fgaClient.expand({
// tree = ...`;

case SupportedLanguage.GO_SDK:
/* eslint-disable no-tabs */
return `
options := ClientExpandOptions{
AuthorizationModelId: PtrString("${modelId}"),
Expand All @@ -54,7 +51,6 @@ data, err := fgaClient.Expand(context.Background()).

// data = { tree: ...}`;

/* eslint-enable no-tabs */
case SupportedLanguage.DOTNET_SDK:
return `
var options = new ClientCheckOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function listObjectsRequestViewer(lang: SupportedLanguage, opts: ListObjectsRequ

# Response: {"objects": [${expectedResults.map((r) => `"${r}"`).join(', ')}]}`;
case SupportedLanguage.CURL:
/* eslint-disable max-len */
return `curl -X POST $FGA_API_URL/stores/$FGA_STORE_ID/list-objects \\
-H "Authorization: Bearer $FGA_API_TOKEN" \\ # Not needed if service does not require authorization
-H "content-type: application/json" \\
Expand Down Expand Up @@ -66,7 +65,7 @@ function listObjectsRequestViewer(lang: SupportedLanguage, opts: ListObjectsRequ


# Response: {"objects": [${expectedResults.map((r) => `"${r}"`).join(', ')}]}`;
/* eslint-enable max-len */

case SupportedLanguage.JS_SDK:
return `const response = await fgaClient.listObjects({
user: "${user}",
Expand Down Expand Up @@ -97,7 +96,6 @@ function listObjectsRequestViewer(lang: SupportedLanguage, opts: ListObjectsRequ
});
// response.objects = [${expectedResults.map((r) => `"${r}"`).join(', ')}]`;
case SupportedLanguage.GO_SDK:
/* eslint-disable no-tabs */
return `options := ClientListObjectsOptions{
AuthorizationModelId: PtrString("${modelId}"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function listUsersRequestViewer(lang: SupportedLanguage, opts: ListUsersRequestV

# Response: ${response}`;
case SupportedLanguage.CURL:
/* eslint-disable max-len */
return `curl -X POST $FGA_API_URL/stores/$FGA_STORE_ID/list-users \\
-H "Authorization: Bearer $FGA_API_TOKEN" \\ # Not needed if service does not require authorization
-H "content-type: application/json" \\
Expand Down Expand Up @@ -91,7 +90,7 @@ function listUsersRequestViewer(lang: SupportedLanguage, opts: ListUsersRequestV


# Response: ${response}`;
/* eslint-enable max-len */

case SupportedLanguage.JS_SDK:
return `const response = await fgaClient.listUsers({
object: {
Expand Down Expand Up @@ -132,7 +131,6 @@ function listUsersRequestViewer(lang: SupportedLanguage, opts: ListUsersRequestV
});
// response.users = [${expectedResults.users.map((u) => JSON.stringify(u)).join(',')}]`;
case SupportedLanguage.GO_SDK:
/* eslint-disable no-tabs */
return `options := ClientListUsersOptions{
AuthorizationModelId: PtrString("${modelId}"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ function readChangesRequestViewer(lang: SupportedLanguage, opts: ReadChangesRequ
const tokenString = `${
'var continuationToken = "' + (opts.continuationToken ? opts.continuationToken : '') + '";\n'
}`;
// eslint-disable-next-line max-len

const pageSizeString = `${'var pageSize = ' + (opts.pageSize ? opts.pageSize : '') + ';\n'}`;
return `${typeString}${tokenString}${pageSizeString}
await fgaClient.readChanges({ type }, { pageSize, continuationToken });`;
}

case SupportedLanguage.GO_SDK: {
// eslint-disable-next-line max-len
return `options := ClientReadChangesOptions{${
opts.pageSize ? `\n\tPageSize: PtrInt32(${opts.pageSize}),\n` : ''
}${opts.continuationToken ? `\n\tContinuationToken: PtrString("${opts.continuationToken}"),\n` : ''}}
Expand Down
6 changes: 0 additions & 6 deletions src/components/Docs/SnippetViewer/ReadRequestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function readRequestViewer(lang: SupportedLanguage, opts: ReadRequestViewerOpts)
? opts.tuples
.map(
({ user, relation, object }) =>
// eslint-disable-next-line max-len
`{"key": {"user":"${user}","relation":"${relation}","object":"${object}"}, "timestamp": "2021-10-06T15:32:11.128Z"}`,
)
.join(',')
Expand All @@ -47,7 +46,6 @@ function readRequestViewer(lang: SupportedLanguage, opts: ReadRequestViewerOpts)
-d '{"tuple_key":{${requestTuples}}}`
: '';

// eslint-disable-next-line max-len
return `curl -X POST $FGA_API_URL/stores/$FGA_STORE_ID/read \\
-H "Authorization: Bearer $FGA_API_TOKEN" \\ # Not needed if service does not require authorization
-H "content-type: application/json" ${requestTuplePayload}'
Expand Down Expand Up @@ -78,7 +76,6 @@ const { tuples } = await fgaClient.read({
`\tObject: PtrString("${opts.object}"),\n`
: '';

/* eslint-disable no-tabs */
return `options := ClientReadOptions{}
body := ClientReadRequest{
${requestTuples}
Expand All @@ -99,7 +96,6 @@ data, err := fgaClient.Read(context.Background()).
` Object = "${opts.object}",`
: '';

/* eslint-disable no-tabs */
return `var options = new ClientReadOptions {}
var body = new ClientReadRequest() {
${requestTuples}
Expand Down Expand Up @@ -140,7 +136,6 @@ response = await fga_client.read(body, options)
? opts.tuples
.map(
({ user, relation, object }) =>
// eslint-disable-next-line max-len
`{"key": {"user":"${user}","relation":"${relation}","object":"${object}"}, "timestamp": "2021-10-06T15:32:11.128Z"}`,
)
.join(',')
Expand Down Expand Up @@ -172,7 +167,6 @@ var response = fgaClient.read(body).get();
default:
assertNever(lang);
}
/* eslint-enable no-tabs */
}

export function ReadRequestViewer(opts: ReadRequestViewerOpts): JSX.Element {
Expand Down
6 changes: 1 addition & 5 deletions src/components/Docs/SnippetViewer/SdkSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function importSdkStatement(lang: SupportedLanguage, languageMappings: La
return getMapping(lang, languageMappings).importStatement;
}

/* eslint-disable max-len */
export function sdkSetupHeader(lang: SupportedLanguage, languageMappings: LanguageMappings) {
switch (lang) {
case SupportedLanguage.CURL:
Expand All @@ -50,7 +49,6 @@ const fgaClient = new ${languageMappings['js'].apiName}({
});`;

case SupportedLanguage.GO_SDK:
/* eslint-disable no-tabs */
return `import (
"os"

Expand All @@ -70,7 +68,6 @@ func main() {
}
}`;

/* eslint-enable no-tabs */
case SupportedLanguage.DOTNET_SDK:
return `// import the SDK
${importSdkStatement(lang, languageMappings)}
Expand All @@ -89,7 +86,7 @@ class Example {
var fgaClient = new ${languageMappings['js'].apiName}(configuration);
}
}`;
/* eslint-enable no-tabs */

case SupportedLanguage.PYTHON_SDK:
return `
${importSdkStatement(lang, languageMappings)}
Expand Down Expand Up @@ -131,7 +128,6 @@ public class Example {
}
}

/* eslint-enable max-len */
export function SdkSetupHeader({ lang }: { lang: SupportedLanguage }): JSX.Element {
const { siteConfig } = useDocusaurusContext();
const configuredLanguage = siteConfig.customFields.languageMapping as LanguageMappings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const { authorization_model_id: id } = await fgaClient.writeAuthorizationModel($
}

function writeAuthZModelViewerGo(authorizationModel: AuthorizationModel): string {
/* eslint-disable no-tabs */
return `
var writeAuthorizationModelRequestString = ${JSON.stringify(JSON.stringify(authorizationModel))}
var body WriteAuthorizationModelRequest
Expand Down
Loading
Loading