Skip to content

Commit

Permalink
chore!: exported type TypeDefinitions is now `WriteAuthorizationMod…
Browse files Browse the repository at this point in the history
…elRequest`

- BREAKING: exported type `TypeDefinitions` is now `WriteAuthorizationModelRequest`
    This is only a breaking change on the SDK, not the API. It was changed to conform to the proto changes in [openfga/api](openfga/api#27).
    It makes the type name more consistent and less confusing (normally people would incorrectly assume TypeDefinitions = TypeDefinition[]).
- chore(deps): upgrade dependencies
  • Loading branch information
adriantam committed Sep 29, 2022
1 parent 53c5348 commit 65be2bc
Show file tree
Hide file tree
Showing 8 changed files with 1,284 additions and 1,140 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## v0.1.0

### [0.1.0](https://github.com/openfga/js-sdk/compare/v0.0.2...v0.1.0) (2022-09-29)

- BREAKING: exported type `TypeDefinitions` is now `WriteAuthorizationModelRequest`
This is only a breaking change on the SDK, not the API. It was changed to conform to the proto changes in [openfga/api](https://github.com/openfga/api/pull/27).
It makes the type name more consistent and less confusing (normally people would incorrectly assume TypeDefinitions = TypeDefinition[]).
- chore(deps): upgrade dependencies

## v0.0.2

### [0.0.2](https://github.com/openfga/js-sdk/compare/v0.0.1...v0.0.2) (2022-08-15)
Expand Down
80 changes: 55 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ This is an autogenerated JavaScript SDK for OpenFGA. It provides a wrapper aroun

OpenFGA is designed to make it easy for application builders to model their permission layer, and to add and integrate fine-grained authorization into their applications. OpenFGA’s design is optimized for reliability and low latency at a high scale.

It allows in-memory data storage for quick development, as well as pluggable database modules - with initial support for PostgreSQL.

It offers an [HTTP API](https://openfga.dev/api/service) and has SDKs for programming languages including [Node.js/JavaScript](https://github.com/openfga/js-sdk), [GoLang](https://github.com/openfga/go-sdk) and [.NET](https://github.com/openfga/dotnet-sdk).

More SDKs and integrations such as Rego are planned for the future.

## Resources

Expand Down Expand Up @@ -232,7 +227,7 @@ const { authorization_model_ids: authorizationModelIds } = await openFga.readAut
```javascript
const result = await openFga.check({
tuple_key: {
user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "admin",
object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
},
Expand All @@ -250,7 +245,7 @@ const result = await openFga.check({
```javascript
await openFga.write({
writes: {
tuple_keys: [{ user: "anne", relation: "viewer", object: "document:roadmap" }],
tuple_keys: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }],
},
});

Expand All @@ -265,7 +260,7 @@ await openFga.write({
```javascript
await openFga.write({
deletes: {
tuple_keys: [{ user: "anne", relation: "viewer", object: "document:roadmap" }],
tuple_keys: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }],
},
});

Expand All @@ -285,7 +280,7 @@ const { tree } = await openFga.expand({
},
});

// tree = { root: { name: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6#admin", leaf: { users: { users: ["anne", "beth"] } } } }
// tree = { root: { name: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6#admin", leaf: { users: { users: ["user:81684243-9356-4421-8fbf-a4f8d36aa31b", "user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"] } } } }
```

#### Read Tuples
Expand All @@ -298,7 +293,7 @@ const { tree } = await openFga.expand({
// Find if a relationship tuple stating that a certain user is an admin on a certain workspace
const body = {
tuple_key: {
user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "admin",
object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
},
Expand All @@ -307,15 +302,15 @@ const body = {
// Find all relationship tuples where a certain user has a relationship as any relation to a certain workspace
const body = {
tuple_key: {
user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
},
};

// Find all relationship tuples where a certain user is an admin on any workspace
const body = {
tuple_key: {
user: "81684243-9356-4421-8fbf-a4f8d36aa31b",
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "admin",
object: "workspace:",
},
Expand Down Expand Up @@ -362,13 +357,13 @@ const response = await openFga.readChanges(type, pageSize, continuationToken);
```javascript
const response = await openFgaApi.listObjects({
authorization_model_id: "01GAHCE4YVKPQEKZQHT2R89MQV",
user: "anne",
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "can_read",
type: "document",
contextual_tuples: {
tuple_keys:
[{
user: "anne",
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "editor",
object: "folder:product"
}, {
Expand Down Expand Up @@ -576,7 +571,7 @@ const response = await openFgaApi.listObjects({

| Name | Type | Description | Notes |
| ------------- | ------------- | ------------- | ------------- |
| **typeDefinitions** | [**TypeDefinitions**](#TypeDefinitions) | | |
| **body** | [**WriteAuthorizationModelRequest**](#WriteAuthorizationModelRequest) | | |

##### Return type

Expand Down Expand Up @@ -605,6 +600,7 @@ const response = await openFgaApi.listObjects({
- [ListObjectsRequest](#ListObjectsRequest)
- [ListObjectsResponse](#ListObjectsResponse)
- [ListStoresResponse](#ListStoresResponse)
- [Metadata](#Metadata)
- [Node](#Node)
- [Nodes](#Nodes)
- [NotFoundErrorCode](#NotFoundErrorCode)
Expand All @@ -616,6 +612,8 @@ const response = await openFgaApi.listObjects({
- [ReadChangesResponse](#ReadChangesResponse)
- [ReadRequest](#ReadRequest)
- [ReadResponse](#ReadResponse)
- [RelationMetadata](#RelationMetadata)
- [RelationReference](#RelationReference)
- [Status](#Status)
- [Store](#Store)
- [Tuple](#Tuple)
Expand All @@ -625,7 +623,6 @@ const response = await openFgaApi.listObjects({
- [TupleOperation](#TupleOperation)
- [TupleToUserset](#TupleToUserset)
- [TypeDefinition](#TypeDefinition)
- [TypeDefinitions](#TypeDefinitions)
- [Users](#Users)
- [Userset](#Userset)
- [UsersetTree](#UsersetTree)
Expand All @@ -634,6 +631,7 @@ const response = await openFgaApi.listObjects({
- [Usersets](#Usersets)
- [ValidationErrorMessageResponse](#ValidationErrorMessageResponse)
- [WriteAssertionsRequest](#WriteAssertionsRequest)
- [WriteAuthorizationModelRequest](#WriteAuthorizationModelRequest)
- [WriteAuthorizationModelResponse](#WriteAuthorizationModelResponse)
- [WriteRequest](#WriteRequest)

Expand Down Expand Up @@ -662,6 +660,7 @@ Name | Type | Description | Notes
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **string** | | [optional] [default to undefined]
**schema_version** | **string** | | [optional] [default to undefined]
**type_definitions** | [**TypeDefinition**[]](#TypeDefinition) | | [optional] [default to undefined]

#### CheckRequest
Expand Down Expand Up @@ -825,6 +824,10 @@ Name | Type | Description | Notes

* `DuplicateContextualTuple` (value: `'duplicate_contextual_tuple'`)

* `InvalidAuthorizationModel` (value: `'invalid_authorization_model'`)

* `UnsupportedSchemaVersion` (value: `'unsupported_schema_version'`)


#### ExpandRequest

Expand Down Expand Up @@ -930,6 +933,14 @@ Name | Type | Description | Notes
**stores** | [**Store**[]](#Store) | | [optional] [default to undefined]
**continuation_token** | **string** | | [optional] [default to undefined]

#### Metadata

##### Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**relations** | [**Record<string, RelationMetadata**>](#RelationMetadata) | | [optional] [default to undefined]

#### Node

##### Properties
Expand Down Expand Up @@ -1037,6 +1048,23 @@ Name | Type | Description | Notes
**tuples** | [**Tuple**[]](#Tuple) | | [optional] [default to undefined]
**continuation_token** | **string** | | [optional] [default to undefined]

#### RelationMetadata

##### Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**directly_related_user_types** | [**RelationReference**[]](#RelationReference) | | [optional] [default to undefined]

#### RelationReference

##### Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**type** | **string** | | [default to undefined]
**relation** | **string** | | [optional] [default to undefined]

#### Status

##### Properties
Expand Down Expand Up @@ -1122,15 +1150,8 @@ Name | Type | Description | Notes
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**type** | **string** | | [default to undefined]
**relations** | [**Record<string, Userset**>](#Userset) | | [default to undefined]

#### TypeDefinitions

##### Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**type_definitions** | [**TypeDefinition**[]](#TypeDefinition) | | [optional] [default to undefined]
**relations** | [**Record<string, Userset**>](#Userset) | | [optional] [default to undefined]
**metadata** | [**Metadata**](#Metadata) | | [optional] [default to undefined]

#### Users

Expand Down Expand Up @@ -1204,6 +1225,15 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**assertions** | [**Assertion**[]](#Assertion) | | [default to undefined]

#### WriteAuthorizationModelRequest

##### Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**type_definitions** | [**TypeDefinition**[]](#TypeDefinition) | | [optional] [default to undefined]
**schema_version** | **string** | | [optional] [default to undefined]

#### WriteAuthorizationModelResponse

##### Properties
Expand Down
33 changes: 18 additions & 15 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
ListObjectsRequest,
ListObjectsResponse,
ListStoresResponse,
Metadata,
Node,
Nodes,
NotFoundErrorCode,
Expand All @@ -63,6 +64,8 @@ import {
ReadChangesResponse,
ReadRequest,
ReadResponse,
RelationMetadata,
RelationReference,
Status,
Store,
Tuple,
Expand All @@ -72,7 +75,6 @@ import {
TupleOperation,
TupleToUserset,
TypeDefinition,
TypeDefinitions,
Users,
Userset,
UsersetTree,
Expand All @@ -81,6 +83,7 @@ import {
Usersets,
ValidationErrorMessageResponse,
WriteAssertionsRequest,
WriteAuthorizationModelRequest,
WriteAuthorizationModelResponse,
WriteRequest,
} from "./apiModel";
Expand Down Expand Up @@ -641,13 +644,13 @@ export const OpenFgaApiAxiosParamCreator = function (configuration: Configuratio
/**
* The POST authorization-model API will update the authorization model for a certain store. Path parameter `store_id` and `type_definitions` array in the body are required. Each item in the `type_definitions` array is a type definition as specified in the field `type_definition`. The response will return the authorization model\'s ID in the `id` field. ## Example To update the authorization model with a single `document` authorization model, call POST authorization-models API with the body: ```json { \"type_definitions\":[ { \"type\":\"document\", \"relations\":{ \"reader\":{ \"union\":{ \"child\":[ { \"this\":{} }, { \"computedUserset\":{ \"object\":\"\", \"relation\":\"writer\" } } ] } }, \"writer\":{ \"this\":{} } } } ] } ``` OpenFGA\'s response will include the version id for this authorization model, which will look like ``` {\"authorization_model_id\": \"01G50QVV17PECNVAHX1GG4Y5NC\"} ```
* @summary Create a new authorization model
* @param {TypeDefinitions} typeDefinitions
* @param {WriteAuthorizationModelRequest} body
* @param {*} [options] Override http request option.
* @throws { FgaError }
*/
writeAuthorizationModel: async (typeDefinitions: TypeDefinitions, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'typeDefinitions' is not null or undefined
assertParamExists("writeAuthorizationModel", "typeDefinitions", typeDefinitions);
writeAuthorizationModel: async (body: WriteAuthorizationModelRequest, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'body' is not null or undefined
assertParamExists("writeAuthorizationModel", "body", body);
assertParamExists("Configuration", "storeId", configuration.storeId);
const localVarPath = "/stores/{store_id}/authorization-models"
.replace(`{${"store_id"}}`, encodeURIComponent(String(configuration.storeId)))
Expand All @@ -670,7 +673,7 @@ export const OpenFgaApiAxiosParamCreator = function (configuration: Configuratio
setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
const headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(typeDefinitions, localVarRequestOptions, configuration);
localVarRequestOptions.data = serializeDataIfNeeded(body, localVarRequestOptions, configuration);

return {
url: toPathString(localVarUrlObj),
Expand Down Expand Up @@ -847,12 +850,12 @@ export const OpenFgaApiFp = function(configuration: Configuration) {
/**
* The POST authorization-model API will update the authorization model for a certain store. Path parameter `store_id` and `type_definitions` array in the body are required. Each item in the `type_definitions` array is a type definition as specified in the field `type_definition`. The response will return the authorization model\'s ID in the `id` field. ## Example To update the authorization model with a single `document` authorization model, call POST authorization-models API with the body: ```json { \"type_definitions\":[ { \"type\":\"document\", \"relations\":{ \"reader\":{ \"union\":{ \"child\":[ { \"this\":{} }, { \"computedUserset\":{ \"object\":\"\", \"relation\":\"writer\" } } ] } }, \"writer\":{ \"this\":{} } } } ] } ``` OpenFGA\'s response will include the version id for this authorization model, which will look like ``` {\"authorization_model_id\": \"01G50QVV17PECNVAHX1GG4Y5NC\"} ```
* @summary Create a new authorization model
* @param {TypeDefinitions} typeDefinitions
* @param {WriteAuthorizationModelRequest} body
* @param {*} [options] Override http request option.
* @throws { FgaError }
*/
async writeAuthorizationModel(typeDefinitions: TypeDefinitions, options?: any): Promise<(axios?: AxiosStatic) => PromiseResult<WriteAuthorizationModelResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.writeAuthorizationModel(typeDefinitions, options);
async writeAuthorizationModel(body: WriteAuthorizationModelRequest, options?: any): Promise<(axios?: AxiosStatic) => PromiseResult<WriteAuthorizationModelResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.writeAuthorizationModel(body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration);
},
};
Expand Down Expand Up @@ -1011,12 +1014,12 @@ export const OpenFgaApiFactory = function (configuration: Configuration, axios?:
/**
* The POST authorization-model API will update the authorization model for a certain store. Path parameter `store_id` and `type_definitions` array in the body are required. Each item in the `type_definitions` array is a type definition as specified in the field `type_definition`. The response will return the authorization model\'s ID in the `id` field. ## Example To update the authorization model with a single `document` authorization model, call POST authorization-models API with the body: ```json { \"type_definitions\":[ { \"type\":\"document\", \"relations\":{ \"reader\":{ \"union\":{ \"child\":[ { \"this\":{} }, { \"computedUserset\":{ \"object\":\"\", \"relation\":\"writer\" } } ] } }, \"writer\":{ \"this\":{} } } } ] } ``` OpenFGA\'s response will include the version id for this authorization model, which will look like ``` {\"authorization_model_id\": \"01G50QVV17PECNVAHX1GG4Y5NC\"} ```
* @summary Create a new authorization model
* @param {TypeDefinitions} typeDefinitions
* @param {WriteAuthorizationModelRequest} body
* @param {*} [options] Override http request option.
* @throws { FgaError }
*/
writeAuthorizationModel(typeDefinitions: TypeDefinitions, options?: any): PromiseResult<WriteAuthorizationModelResponse> {
return localVarFp.writeAuthorizationModel(typeDefinitions, options).then((request) => request(axios));
writeAuthorizationModel(body: WriteAuthorizationModelRequest, options?: any): PromiseResult<WriteAuthorizationModelResponse> {
return localVarFp.writeAuthorizationModel(body, options).then((request) => request(axios));
},
};
};
Expand Down Expand Up @@ -1202,13 +1205,13 @@ export class OpenFgaApi extends BaseAPI {
/**
* The POST authorization-model API will update the authorization model for a certain store. Path parameter `store_id` and `type_definitions` array in the body are required. Each item in the `type_definitions` array is a type definition as specified in the field `type_definition`. The response will return the authorization model\'s ID in the `id` field. ## Example To update the authorization model with a single `document` authorization model, call POST authorization-models API with the body: ```json { \"type_definitions\":[ { \"type\":\"document\", \"relations\":{ \"reader\":{ \"union\":{ \"child\":[ { \"this\":{} }, { \"computedUserset\":{ \"object\":\"\", \"relation\":\"writer\" } } ] } }, \"writer\":{ \"this\":{} } } } ] } ``` OpenFGA\'s response will include the version id for this authorization model, which will look like ``` {\"authorization_model_id\": \"01G50QVV17PECNVAHX1GG4Y5NC\"} ```
* @summary Create a new authorization model
* @param {TypeDefinitions} typeDefinitions
* @param {WriteAuthorizationModelRequest} body
* @param {*} [options] Override http request option.
* @throws { FgaError }
* @memberof OpenFgaApi
*/
public writeAuthorizationModel(typeDefinitions: TypeDefinitions, options?: any) {
return OpenFgaApiFp(this.configuration).writeAuthorizationModel(typeDefinitions, options).then((request) => request(this.axios));
public writeAuthorizationModel(body: WriteAuthorizationModelRequest, options?: any) {
return OpenFgaApiFp(this.configuration).writeAuthorizationModel(body, options).then((request) => request(this.axios));
}
}

Expand Down
Loading

0 comments on commit 65be2bc

Please sign in to comment.