Skip to content

Commit bab0fb7

Browse files
committed
refactor: client is turned back to generated sdk
1 parent daec471 commit bab0fb7

6 files changed

Lines changed: 128 additions & 301 deletions

File tree

README.md

Lines changed: 50 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ This client makes it easy to interact with [Permify](https://github.com/Permify/
1616
Use npm to install:
1717

1818
```shell
19-
npm config set @buf:registry https://buf.build/gen/npm/v1/
2019
npm install @permify/permify-node
2120
```
2221

2322
Use yarn to install (Please be aware that Yarn versions greater than v1.10.0 and less than v2 are not supported):
2423

2524
```shell
26-
yarn config set npmScopes.buf.npmRegistryServer https://buf.build/gen/npm/v1/
2725
yarn add @permify/permify-node
2826
```
2927

@@ -34,18 +32,16 @@ yarn add @permify/permify-node
3432
```typescript
3533
import * as permify from "@permify/permify-node";
3634

37-
38-
const request = new permify.grpc.payload.TenantCreateRequest();
39-
request.setId("t1");
40-
request.setName("Tenant 1");
41-
4235
const client = permify.grpc.newClient({
4336
endpoint: "localhost:3478",
4437
cert: undefined,
4538
insecure: true
4639
});
4740

48-
client.tenancy.create(request).then((response) => {
41+
client.tenancy.create({
42+
id: "t1",
43+
name: "Tenant 1"
44+
}).then((response) => {
4945
console.log(response);
5046
// handle response
5147
})
@@ -62,7 +58,6 @@ const client = permify.grpc.newClient({
6258
insecure: true
6359
});
6460

65-
// Define the schema
6661
let schema = `
6762
entity user {}
6863
@@ -73,13 +68,11 @@ let schema = `
7368
}
7469
`;
7570

76-
// Create and set the SchemaWriteRequest
77-
let schemaWriteRequest = new permify.grpc.payload.SchemaWriteRequest();
78-
schemaWriteRequest.setTenantId("t1");
79-
schemaWriteRequest.setSchema(schema);
80-
8171
// Write the schema
82-
client.schema.write(schemaWriteRequest).then((response) => {
72+
client.tenancy.create({
73+
tenantId: "t1",
74+
schema: schema
75+
}).then((response) => {
8376
// handle response
8477
})
8578
```
@@ -95,14 +88,12 @@ const client = permify.grpc.newClient({
9588
insecure: true
9689
});
9790

98-
// Create and set the RelationshipWriteRequest
99-
let relationshipWriteRequest = new permify.grpc.payload.SchemaWriteRequest();
100-
relationshipWriteRequest.setTenantId("t1");
101-
relationshipWriteRequest.setMetadata(new permify.grpc.payload.SchemaWriteRequestMetadata());
102-
103-
// Create the tuple list
104-
let tupleList = [];
105-
let tuples = [{
91+
client.relationship.write({
92+
tenantId: "t1",
93+
metadata: {
94+
schemaVersion: ""
95+
},
96+
tuples: [{
10697
entity: {
10798
type: "document",
10899
id: "1"
@@ -112,29 +103,8 @@ let tuples = [{
112103
type: "user",
113104
id: "1"
114105
}
115-
}];
116-
117-
tuples.forEach(t => {
118-
let tuple = new permify.grpc.payload.Tuple();
119-
120-
let entity = new permify.grpc.payload.Entity();
121-
entity.setType(t.entity.type);
122-
entity.setId(t.entity.id);
123-
124-
let subject = new permify.grpc.payload.Subject();
125-
subject.setType(t.subject.type);
126-
subject.setId(t.subject.id);
127-
128-
tuple.setEntity(entity);
129-
tuple.setRelation(t.relation);
130-
tuple.setSubject(subject);
131-
132-
tupleList.push(tuple);
133-
});
134-
135-
relationshipWriteRequest.setTuplesList(tupleList);
136-
137-
client.relationship.write(relationshipWriteRequest).then((response) => {
106+
}]
107+
}).then((response) => {
138108
// handle response
139109
})
140110
```
@@ -150,34 +120,29 @@ const client = permify.grpc.newClient({
150120
insecure: true
151121
});
152122

153-
// Create and set the PermissionCheckRequest
154-
let permissionCheckRequest = new permify.grpc.payload.PermissionCheckRequest();
155-
permissionCheckRequest.setTenantId("t1");
156-
permissionCheckRequest.setMetadata(new permify.grpc.payload.PermissionCheckRequestMetadata());
157-
158-
// Set the entity details
159-
let permissionCheckRequestEntity = new permify.grpc.payload.Entity();
160-
permissionCheckRequestEntity.setType("document");
161-
permissionCheckRequestEntity.setId("1");
162-
permissionCheckRequest.setEntity(permissionCheckRequestEntity);
163-
164-
// Set the permission to check
165-
permissionCheckRequest.setPermission("view");
166-
167-
// Set the subject details
168-
let permissionCheckRequestSubject = new permify.grpc.payload.Subject();
169-
permissionCheckRequestSubject.setType("user");
170-
permissionCheckRequestSubject.setId("3");
171-
permissionCheckRequest.setSubject(permissionCheckRequestSubject);
172-
173-
// Perform the permission check
174-
client.permission.check(permissionCheckRequest).then((response: permify.grpc.payload.PermissionCheckResponse) => {
175-
if (response.can === permify.grpc.base.CheckResult.CHECK_RESULT_ALLOWED) {
123+
client.permission.check({
124+
tenantId: "t1",
125+
metadata: {
126+
snapToken: "",
127+
schemaVersion: "",
128+
depth: 20
129+
},
130+
entity: {
131+
type: "document",
132+
id: "1"
133+
},
134+
permission: "view",
135+
subject: {
136+
type: "user",
137+
id: "3"
138+
}
139+
}).then((response) => {
140+
if (response.can === PermissionCheckResponse_Result.RESULT_ALLOWED) {
176141
console.log("RESULT_ALLOWED")
177142
} else {
178143
console.log("RESULT_DENIED")
179144
}
180-
});
145+
})
181146
```
182147

183148
### Streaming Calls
@@ -192,31 +157,27 @@ function main() {
192157
insecure: true
193158
});
194159

195-
// Create and set the PermissionLookupEntityRequest
196-
let lookupEntityStreamRequest = new permify.grpc.payload.PermissionLookupEntityRequest();
197-
lookupEntityStreamRequest.setTenantId("t1");
198-
199-
// Set the request metadata
200-
lookupEntityStreamRequest.setMetadata(new permify.grpc.payload.PermissionLookupEntityRequestMetadata());
201-
202-
// Set the entity type and permission
203-
lookupEntityStreamRequest.setEntityType("document");
204-
lookupEntityStreamRequest.setPermission("view");
205-
206-
// Set the subject details
207-
let subject = new permify.grpc.payload.Subject();
208-
subject.setType("user");
209-
subject.setId("1");
210-
lookupEntityStreamRequest.setSubject(subject);
160+
let res = client.permission.lookupEntityStream({
161+
tenantId: "t1",
162+
metadata: {
163+
snapToken: "",
164+
schemaVersion: "",
165+
depth: 20
166+
},
167+
entityType: "document",
168+
permission: "view",
169+
subject: {
170+
type: "user",
171+
id: "1"
172+
}
173+
})
211174

212-
// Perform the lookup entity stream
213-
const res = client.permission.lookupEntityStream(lookupEntityStreamRequest);
214175
handle(res)
215176
}
216177

217178
async function handle(res: AsyncIterable<permify.grpc.payload.PermissionLookupEntityStreamResponse>) {
218179
for await (const response of res) {
219-
// response.toObject().entityId
180+
// response.entityId
220181
}
221182
}
222183
```

package-lock.json

Lines changed: 0 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"author": "permify",
2525
"license": "Apache-2.0",
2626
"dependencies": {
27-
"@buf/permifyco_permify.grpc_node": "^1.12.4-20240722150440-5ee7aa4c5fb5.4",
2827
"nice-grpc": "^2.1.9"
2928
},
3029
"devDependencies": {

0 commit comments

Comments
 (0)