@workos-inc/node 7.15.0 → 7.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/interfaces/event.interface.d.ts +67 -3
- package/lib/common/interfaces/get-options.interface.d.ts +1 -0
- package/lib/common/interfaces/post-options.interface.d.ts +1 -0
- package/lib/common/serializers/event.serializer.js +9 -0
- package/lib/common/utils/fetch-and-deserialize.d.ts +2 -2
- package/lib/common/utils/fetch-and-deserialize.js +2 -4
- package/lib/fga/fga-live-test.spec.d.ts +1 -0
- package/lib/fga/fga-live-test.spec.js +872 -0
- package/lib/fga/fga.d.ts +18 -0
- package/lib/fga/fga.js +105 -0
- package/lib/fga/fga.spec.d.ts +1 -0
- package/lib/fga/fga.spec.js +518 -0
- package/lib/fga/interfaces/check-op.enum.d.ts +5 -0
- package/lib/fga/interfaces/check-op.enum.js +9 -0
- package/lib/fga/interfaces/check.interface.d.ts +71 -0
- package/lib/fga/interfaces/check.interface.js +21 -0
- package/lib/fga/interfaces/index.d.ts +7 -0
- package/lib/fga/interfaces/index.js +23 -0
- package/lib/fga/interfaces/query.interface.d.ts +30 -0
- package/lib/fga/interfaces/query.interface.js +2 -0
- package/lib/fga/interfaces/resource.interface.d.ts +60 -0
- package/lib/fga/interfaces/resource.interface.js +2 -0
- package/lib/fga/interfaces/warrant-op.enum.d.ts +4 -0
- package/lib/fga/interfaces/warrant-op.enum.js +8 -0
- package/lib/fga/interfaces/warrant-token.interface.d.ts +6 -0
- package/lib/fga/interfaces/warrant-token.interface.js +2 -0
- package/lib/fga/interfaces/warrant.interface.d.ts +65 -0
- package/lib/fga/interfaces/warrant.interface.js +2 -0
- package/lib/fga/serializers/check-options.serializer.d.ts +4 -0
- package/lib/fga/serializers/check-options.serializer.js +62 -0
- package/lib/fga/serializers/create-resource-options.serializer.d.ts +2 -0
- package/lib/fga/serializers/create-resource-options.serializer.js +16 -0
- package/lib/fga/serializers/delete-resource-options.serializer.d.ts +2 -0
- package/lib/fga/serializers/delete-resource-options.serializer.js +15 -0
- package/lib/fga/serializers/index.d.ts +11 -0
- package/lib/fga/serializers/index.js +27 -0
- package/lib/fga/serializers/list-resources-options.serializer.d.ts +2 -0
- package/lib/fga/serializers/list-resources-options.serializer.js +12 -0
- package/lib/fga/serializers/list-warrants-options.serializer.d.ts +2 -0
- package/lib/fga/serializers/list-warrants-options.serializer.js +14 -0
- package/lib/fga/serializers/query-options.serializer.d.ts +2 -0
- package/lib/fga/serializers/query-options.serializer.js +12 -0
- package/lib/fga/serializers/query-result.serializer.d.ts +2 -0
- package/lib/fga/serializers/query-result.serializer.js +21 -0
- package/lib/fga/serializers/resource.serializer.d.ts +2 -0
- package/lib/fga/serializers/resource.serializer.js +9 -0
- package/lib/fga/serializers/warrant-token.serializer.d.ts +2 -0
- package/lib/fga/serializers/warrant-token.serializer.js +7 -0
- package/lib/fga/serializers/warrant.serializer.d.ts +2 -0
- package/lib/fga/serializers/warrant.serializer.js +14 -0
- package/lib/fga/serializers/write-warrant-options.serializer.d.ts +2 -0
- package/lib/fga/serializers/write-warrant-options.serializer.js +27 -0
- package/lib/fga/utils/interface-check.d.ts +3 -0
- package/lib/fga/utils/interface-check.js +15 -0
- package/lib/user-management/interfaces/authentication-event.interface.d.ts +25 -0
- package/lib/user-management/interfaces/authentication-event.interface.js +2 -0
- package/lib/user-management/interfaces/index.d.ts +1 -0
- package/lib/user-management/interfaces/index.js +1 -0
- package/lib/user-management/serializers/authentication-event.serializer.d.ts +2 -0
- package/lib/user-management/serializers/authentication-event.serializer.js +13 -0
- package/lib/user-management/serializers/index.d.ts +1 -0
- package/lib/user-management/serializers/index.js +1 -0
- package/lib/workos.d.ts +2 -0
- package/lib/workos.js +19 -7
- package/package.json +1 -1
package/lib/fga/fga.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WorkOS } from '../workos';
|
|
2
|
+
import { Resource, CheckBatchOptions, CheckOptions, CheckRequestOptions, CheckResult, CreateResourceOptions, DeleteResourceOptions, ListResourcesOptions, ListWarrantsRequestOptions, ListWarrantsOptions, QueryOptions, QueryRequestOptions, QueryResult, ResourceInterface, ResourceOptions, UpdateResourceOptions, WriteWarrantOptions, Warrant, WarrantToken } from './interfaces';
|
|
3
|
+
import { AutoPaginatable } from '../common/utils/pagination';
|
|
4
|
+
export declare class FGA {
|
|
5
|
+
private readonly workos;
|
|
6
|
+
constructor(workos: WorkOS);
|
|
7
|
+
check(checkOptions: CheckOptions, options?: CheckRequestOptions): Promise<CheckResult>;
|
|
8
|
+
checkBatch(checkOptions: CheckBatchOptions, options?: CheckRequestOptions): Promise<CheckResult[]>;
|
|
9
|
+
createResource(resource: CreateResourceOptions): Promise<Resource>;
|
|
10
|
+
getResource(resource: ResourceInterface | ResourceOptions): Promise<Resource>;
|
|
11
|
+
listResources(options?: ListResourcesOptions): Promise<AutoPaginatable<Resource>>;
|
|
12
|
+
updateResource(options: UpdateResourceOptions): Promise<Resource>;
|
|
13
|
+
deleteResource(resource: DeleteResourceOptions): Promise<void>;
|
|
14
|
+
writeWarrant(options: WriteWarrantOptions): Promise<WarrantToken>;
|
|
15
|
+
batchWriteWarrants(options: WriteWarrantOptions[]): Promise<WarrantToken>;
|
|
16
|
+
listWarrants(options?: ListWarrantsOptions, requestOptions?: ListWarrantsRequestOptions): Promise<AutoPaginatable<Warrant>>;
|
|
17
|
+
query(options: QueryOptions, requestOptions?: QueryRequestOptions): Promise<AutoPaginatable<QueryResult>>;
|
|
18
|
+
}
|
package/lib/fga/fga.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FGA = void 0;
|
|
13
|
+
const interfaces_1 = require("./interfaces");
|
|
14
|
+
const serializers_1 = require("./serializers");
|
|
15
|
+
const interface_check_1 = require("./utils/interface-check");
|
|
16
|
+
const pagination_1 = require("../common/utils/pagination");
|
|
17
|
+
const fetch_and_deserialize_1 = require("../common/utils/fetch-and-deserialize");
|
|
18
|
+
class FGA {
|
|
19
|
+
constructor(workos) {
|
|
20
|
+
this.workos = workos;
|
|
21
|
+
}
|
|
22
|
+
check(checkOptions, options = {}) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const { data } = yield this.workos.post(`/fga/v1/check`, (0, serializers_1.serializeCheckOptions)(checkOptions), options);
|
|
25
|
+
return new interfaces_1.CheckResult(data);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
checkBatch(checkOptions, options = {}) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const { data } = yield this.workos.post(`/fga/v1/check`, (0, serializers_1.serializeCheckBatchOptions)(checkOptions), options);
|
|
31
|
+
return data.map((checkResult) => new interfaces_1.CheckResult(checkResult));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
createResource(resource) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const { data } = yield this.workos.post('/fga/v1/resources', (0, serializers_1.serializeCreateResourceOptions)(resource));
|
|
37
|
+
return (0, serializers_1.deserializeResource)(data);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getResource(resource) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const resourceType = (0, interface_check_1.isResourceInterface)(resource)
|
|
43
|
+
? resource.getResourceType()
|
|
44
|
+
: resource.resourceType;
|
|
45
|
+
const resourceId = (0, interface_check_1.isResourceInterface)(resource)
|
|
46
|
+
? resource.getResourceId()
|
|
47
|
+
: resource.resourceId;
|
|
48
|
+
const { data } = yield this.workos.get(`/fga/v1/resources/${resourceType}/${resourceId}`);
|
|
49
|
+
return (0, serializers_1.deserializeResource)(data);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
listResources(options) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/resources', serializers_1.deserializeResource, options ? (0, serializers_1.serializeListResourceOptions)(options) : undefined), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/resources', serializers_1.deserializeResource, params), options ? (0, serializers_1.serializeListResourceOptions)(options) : undefined);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
updateResource(options) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const resourceType = (0, interface_check_1.isResourceInterface)(options.resource)
|
|
60
|
+
? options.resource.getResourceType()
|
|
61
|
+
: options.resource.resourceType;
|
|
62
|
+
const resourceId = (0, interface_check_1.isResourceInterface)(options.resource)
|
|
63
|
+
? options.resource.getResourceId()
|
|
64
|
+
: options.resource.resourceId;
|
|
65
|
+
const { data } = yield this.workos.put(`/fga/v1/resources/${resourceType}/${resourceId}`, {
|
|
66
|
+
meta: options.meta,
|
|
67
|
+
});
|
|
68
|
+
return (0, serializers_1.deserializeResource)(data);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
deleteResource(resource) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const resourceType = (0, interface_check_1.isResourceInterface)(resource)
|
|
74
|
+
? resource.getResourceType()
|
|
75
|
+
: resource.resourceType;
|
|
76
|
+
const resourceId = (0, interface_check_1.isResourceInterface)(resource)
|
|
77
|
+
? resource.getResourceId()
|
|
78
|
+
: resource.resourceId;
|
|
79
|
+
yield this.workos.delete(`/fga/v1/resources/${resourceType}/${resourceId}`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
writeWarrant(options) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const { data } = yield this.workos.post('/fga/v1/warrants', (0, serializers_1.serializeWriteWarrantOptions)(options));
|
|
85
|
+
return (0, serializers_1.deserializeWarrantToken)(data);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
batchWriteWarrants(options) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const { data: warrantToken } = yield this.workos.post('/fga/v1/warrants', options.map(serializers_1.serializeWriteWarrantOptions));
|
|
91
|
+
return (0, serializers_1.deserializeWarrantToken)(warrantToken);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
listWarrants(options, requestOptions) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/warrants', serializers_1.deserializeWarrant, options ? (0, serializers_1.serializeListWarrantsOptions)(options) : undefined, requestOptions), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/warrants', serializers_1.deserializeWarrant, params, requestOptions), options ? (0, serializers_1.serializeListWarrantsOptions)(options) : undefined);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
query(options, requestOptions = {}) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/query', serializers_1.deserializeQueryResult, (0, serializers_1.serializeQueryOptions)(options), requestOptions), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/query', serializers_1.deserializeQueryResult, params, requestOptions), (0, serializers_1.serializeQueryOptions)(options));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.FGA = FGA;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
|
|
16
|
+
const test_utils_1 = require("../common/utils/test-utils");
|
|
17
|
+
const workos_1 = require("../workos");
|
|
18
|
+
const interfaces_1 = require("./interfaces");
|
|
19
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
20
|
+
describe('FGA', () => {
|
|
21
|
+
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
22
|
+
describe('check', () => {
|
|
23
|
+
it('makes check request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
(0, test_utils_1.fetchOnce)({
|
|
25
|
+
result: 'authorized',
|
|
26
|
+
is_implicit: false,
|
|
27
|
+
});
|
|
28
|
+
const checkResult = yield workos.fga.check({
|
|
29
|
+
checks: [
|
|
30
|
+
{
|
|
31
|
+
resource: {
|
|
32
|
+
resourceType: 'role',
|
|
33
|
+
resourceId: 'admin',
|
|
34
|
+
},
|
|
35
|
+
relation: 'member',
|
|
36
|
+
subject: {
|
|
37
|
+
resourceType: 'user',
|
|
38
|
+
resourceId: 'user_123',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/check');
|
|
44
|
+
expect(checkResult).toMatchObject({
|
|
45
|
+
result: 'authorized',
|
|
46
|
+
isImplicit: false,
|
|
47
|
+
});
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
describe('createResource', () => {
|
|
51
|
+
it('creates resource', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
(0, test_utils_1.fetchOnce)({
|
|
53
|
+
resource_type: 'role',
|
|
54
|
+
resource_id: 'admin',
|
|
55
|
+
});
|
|
56
|
+
const resource = yield workos.fga.createResource({
|
|
57
|
+
resource: {
|
|
58
|
+
resourceType: 'role',
|
|
59
|
+
resourceId: 'admin',
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources');
|
|
63
|
+
expect(resource).toMatchObject({
|
|
64
|
+
resourceType: 'role',
|
|
65
|
+
resourceId: 'admin',
|
|
66
|
+
});
|
|
67
|
+
}));
|
|
68
|
+
it('creates resource with metadata', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
(0, test_utils_1.fetchOnce)({
|
|
70
|
+
resource_type: 'role',
|
|
71
|
+
resource_id: 'admin',
|
|
72
|
+
meta: {
|
|
73
|
+
description: 'The admin role',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const resource = yield workos.fga.createResource({
|
|
77
|
+
resource: {
|
|
78
|
+
resourceType: 'role',
|
|
79
|
+
resourceId: 'admin',
|
|
80
|
+
},
|
|
81
|
+
meta: {
|
|
82
|
+
description: 'The admin role',
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources');
|
|
86
|
+
expect(resource).toMatchObject({
|
|
87
|
+
resourceType: 'role',
|
|
88
|
+
resourceId: 'admin',
|
|
89
|
+
meta: {
|
|
90
|
+
description: 'The admin role',
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}));
|
|
94
|
+
});
|
|
95
|
+
describe('getResource', () => {
|
|
96
|
+
it('gets resource', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
(0, test_utils_1.fetchOnce)({
|
|
98
|
+
resource_type: 'role',
|
|
99
|
+
resource_id: 'admin',
|
|
100
|
+
});
|
|
101
|
+
const resource = yield workos.fga.getResource({
|
|
102
|
+
resourceType: 'role',
|
|
103
|
+
resourceId: 'admin',
|
|
104
|
+
});
|
|
105
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources/role/admin');
|
|
106
|
+
expect(resource).toMatchObject({
|
|
107
|
+
resourceType: 'role',
|
|
108
|
+
resourceId: 'admin',
|
|
109
|
+
});
|
|
110
|
+
}));
|
|
111
|
+
});
|
|
112
|
+
describe('listResources', () => {
|
|
113
|
+
it('lists resources', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
(0, test_utils_1.fetchOnce)({
|
|
115
|
+
data: [
|
|
116
|
+
{
|
|
117
|
+
resource_type: 'role',
|
|
118
|
+
resource_id: 'admin',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
resource_type: 'role',
|
|
122
|
+
resource_id: 'manager',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
list_metadata: {
|
|
126
|
+
before: null,
|
|
127
|
+
after: null,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const { data: resources } = yield workos.fga.listResources();
|
|
131
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources');
|
|
132
|
+
expect(resources).toMatchObject([
|
|
133
|
+
{
|
|
134
|
+
resourceType: 'role',
|
|
135
|
+
resourceId: 'admin',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
resourceType: 'role',
|
|
139
|
+
resourceId: 'manager',
|
|
140
|
+
},
|
|
141
|
+
]);
|
|
142
|
+
}));
|
|
143
|
+
it('sends correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
+
(0, test_utils_1.fetchOnce)({
|
|
145
|
+
data: [
|
|
146
|
+
{
|
|
147
|
+
resource_type: 'role',
|
|
148
|
+
resource_id: 'admin',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
resource_type: 'role',
|
|
152
|
+
resource_id: 'manager',
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
list_metadata: {
|
|
156
|
+
before: null,
|
|
157
|
+
after: null,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
yield workos.fga.listResources({
|
|
161
|
+
resourceType: 'role',
|
|
162
|
+
});
|
|
163
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources');
|
|
164
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
165
|
+
resource_type: 'role',
|
|
166
|
+
order: 'desc',
|
|
167
|
+
});
|
|
168
|
+
}));
|
|
169
|
+
});
|
|
170
|
+
describe('deleteResource', () => {
|
|
171
|
+
it('should delete resource', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
172
|
+
(0, test_utils_1.fetchOnce)();
|
|
173
|
+
const response = yield workos.fga.deleteResource({
|
|
174
|
+
resourceType: 'role',
|
|
175
|
+
resourceId: 'admin',
|
|
176
|
+
});
|
|
177
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/resources/role/admin');
|
|
178
|
+
expect(response).toBeUndefined();
|
|
179
|
+
}));
|
|
180
|
+
});
|
|
181
|
+
describe('writeWarrant', () => {
|
|
182
|
+
it('should create warrant with no op', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
+
(0, test_utils_1.fetchOnce)({
|
|
184
|
+
warrant_token: 'some_token',
|
|
185
|
+
});
|
|
186
|
+
const warrantToken = yield workos.fga.writeWarrant({
|
|
187
|
+
resource: {
|
|
188
|
+
resourceType: 'role',
|
|
189
|
+
resourceId: 'admin',
|
|
190
|
+
},
|
|
191
|
+
relation: 'member',
|
|
192
|
+
subject: {
|
|
193
|
+
resourceType: 'user',
|
|
194
|
+
resourceId: 'user_123',
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
|
|
198
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
199
|
+
resource_type: 'role',
|
|
200
|
+
resource_id: 'admin',
|
|
201
|
+
relation: 'member',
|
|
202
|
+
subject: {
|
|
203
|
+
resource_type: 'user',
|
|
204
|
+
resource_id: 'user_123',
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
expect(warrantToken).toMatchObject({
|
|
208
|
+
warrantToken: 'some_token',
|
|
209
|
+
});
|
|
210
|
+
}));
|
|
211
|
+
it('should create warrant with create op', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
212
|
+
(0, test_utils_1.fetchOnce)({
|
|
213
|
+
warrant_token: 'some_token',
|
|
214
|
+
});
|
|
215
|
+
const warrantToken = yield workos.fga.writeWarrant({
|
|
216
|
+
op: interfaces_1.WarrantOp.Create,
|
|
217
|
+
resource: {
|
|
218
|
+
resourceType: 'role',
|
|
219
|
+
resourceId: 'admin',
|
|
220
|
+
},
|
|
221
|
+
relation: 'member',
|
|
222
|
+
subject: {
|
|
223
|
+
resourceType: 'user',
|
|
224
|
+
resourceId: 'user_123',
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
|
|
228
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
229
|
+
op: 'create',
|
|
230
|
+
resource_type: 'role',
|
|
231
|
+
resource_id: 'admin',
|
|
232
|
+
relation: 'member',
|
|
233
|
+
subject: {
|
|
234
|
+
resource_type: 'user',
|
|
235
|
+
resource_id: 'user_123',
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
expect(warrantToken).toMatchObject({
|
|
239
|
+
warrantToken: 'some_token',
|
|
240
|
+
});
|
|
241
|
+
}));
|
|
242
|
+
it('should delete warrant with delete op', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
|
+
(0, test_utils_1.fetchOnce)({
|
|
244
|
+
warrant_token: 'some_token',
|
|
245
|
+
});
|
|
246
|
+
const warrantToken = yield workos.fga.writeWarrant({
|
|
247
|
+
op: interfaces_1.WarrantOp.Delete,
|
|
248
|
+
resource: {
|
|
249
|
+
resourceType: 'role',
|
|
250
|
+
resourceId: 'admin',
|
|
251
|
+
},
|
|
252
|
+
relation: 'member',
|
|
253
|
+
subject: {
|
|
254
|
+
resourceType: 'user',
|
|
255
|
+
resourceId: 'user_123',
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
|
|
259
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
260
|
+
op: 'delete',
|
|
261
|
+
resource_type: 'role',
|
|
262
|
+
resource_id: 'admin',
|
|
263
|
+
relation: 'member',
|
|
264
|
+
subject: {
|
|
265
|
+
resource_type: 'user',
|
|
266
|
+
resource_id: 'user_123',
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
expect(warrantToken).toMatchObject({
|
|
270
|
+
warrantToken: 'some_token',
|
|
271
|
+
});
|
|
272
|
+
}));
|
|
273
|
+
});
|
|
274
|
+
describe('batchWriteWarrants', () => {
|
|
275
|
+
it('should create warrants with no op or create op and delete warrants with delete op', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
276
|
+
(0, test_utils_1.fetchOnce)({
|
|
277
|
+
warrant_token: 'some_token',
|
|
278
|
+
});
|
|
279
|
+
const warrantToken = yield workos.fga.batchWriteWarrants([
|
|
280
|
+
{
|
|
281
|
+
resource: {
|
|
282
|
+
resourceType: 'role',
|
|
283
|
+
resourceId: 'admin',
|
|
284
|
+
},
|
|
285
|
+
relation: 'member',
|
|
286
|
+
subject: {
|
|
287
|
+
resourceType: 'user',
|
|
288
|
+
resourceId: 'user_123',
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
op: interfaces_1.WarrantOp.Create,
|
|
293
|
+
resource: {
|
|
294
|
+
resourceType: 'role',
|
|
295
|
+
resourceId: 'admin',
|
|
296
|
+
},
|
|
297
|
+
relation: 'member',
|
|
298
|
+
subject: {
|
|
299
|
+
resourceType: 'user',
|
|
300
|
+
resourceId: 'user_124',
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
op: interfaces_1.WarrantOp.Delete,
|
|
305
|
+
resource: {
|
|
306
|
+
resourceType: 'role',
|
|
307
|
+
resourceId: 'admin',
|
|
308
|
+
},
|
|
309
|
+
relation: 'member',
|
|
310
|
+
subject: {
|
|
311
|
+
resourceType: 'user',
|
|
312
|
+
resourceId: 'user_125',
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
]);
|
|
316
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
|
|
317
|
+
expect((0, test_utils_1.fetchBody)()).toEqual([
|
|
318
|
+
{
|
|
319
|
+
resource_type: 'role',
|
|
320
|
+
resource_id: 'admin',
|
|
321
|
+
relation: 'member',
|
|
322
|
+
subject: {
|
|
323
|
+
resource_type: 'user',
|
|
324
|
+
resource_id: 'user_123',
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
op: 'create',
|
|
329
|
+
resource_type: 'role',
|
|
330
|
+
resource_id: 'admin',
|
|
331
|
+
relation: 'member',
|
|
332
|
+
subject: {
|
|
333
|
+
resource_type: 'user',
|
|
334
|
+
resource_id: 'user_124',
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
op: 'delete',
|
|
339
|
+
resource_type: 'role',
|
|
340
|
+
resource_id: 'admin',
|
|
341
|
+
relation: 'member',
|
|
342
|
+
subject: {
|
|
343
|
+
resource_type: 'user',
|
|
344
|
+
resource_id: 'user_125',
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
]);
|
|
348
|
+
expect(warrantToken).toMatchObject({
|
|
349
|
+
warrantToken: 'some_token',
|
|
350
|
+
});
|
|
351
|
+
}));
|
|
352
|
+
});
|
|
353
|
+
describe('listWarrants', () => {
|
|
354
|
+
it('should list warrants', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
355
|
+
(0, test_utils_1.fetchOnce)({
|
|
356
|
+
data: [
|
|
357
|
+
{
|
|
358
|
+
resource_type: 'role',
|
|
359
|
+
resource_id: 'admin',
|
|
360
|
+
relation: 'member',
|
|
361
|
+
subject: {
|
|
362
|
+
resource_type: 'user',
|
|
363
|
+
resource_id: 'user_123',
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
resource_type: 'role',
|
|
368
|
+
resource_id: 'admin',
|
|
369
|
+
relation: 'member',
|
|
370
|
+
subject: {
|
|
371
|
+
resource_type: 'user',
|
|
372
|
+
resource_id: 'user_124',
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
list_metadata: {
|
|
377
|
+
before: null,
|
|
378
|
+
after: null,
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
const { data: warrants } = yield workos.fga.listWarrants();
|
|
382
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
|
|
383
|
+
expect(warrants).toMatchObject([
|
|
384
|
+
{
|
|
385
|
+
resourceType: 'role',
|
|
386
|
+
resourceId: 'admin',
|
|
387
|
+
relation: 'member',
|
|
388
|
+
subject: {
|
|
389
|
+
resourceType: 'user',
|
|
390
|
+
resourceId: 'user_123',
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
resourceType: 'role',
|
|
395
|
+
resourceId: 'admin',
|
|
396
|
+
relation: 'member',
|
|
397
|
+
subject: {
|
|
398
|
+
resourceType: 'user',
|
|
399
|
+
resourceId: 'user_124',
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
]);
|
|
403
|
+
}));
|
|
404
|
+
it('sends correct params when filtering', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
405
|
+
(0, test_utils_1.fetchOnce)({
|
|
406
|
+
data: [
|
|
407
|
+
{
|
|
408
|
+
resource_type: 'role',
|
|
409
|
+
resource_id: 'admin',
|
|
410
|
+
relation: 'member',
|
|
411
|
+
subject: {
|
|
412
|
+
resource_type: 'user',
|
|
413
|
+
resource_id: 'user_123',
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
list_metadata: {
|
|
418
|
+
before: null,
|
|
419
|
+
after: null,
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
yield workos.fga.listWarrants({
|
|
423
|
+
subjectType: 'user',
|
|
424
|
+
subjectId: 'user_123',
|
|
425
|
+
});
|
|
426
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/warrants');
|
|
427
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
428
|
+
subject_type: 'user',
|
|
429
|
+
subject_id: 'user_123',
|
|
430
|
+
order: 'desc',
|
|
431
|
+
});
|
|
432
|
+
}));
|
|
433
|
+
});
|
|
434
|
+
describe('query', () => {
|
|
435
|
+
it('makes query request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
436
|
+
(0, test_utils_1.fetchOnce)({
|
|
437
|
+
data: [
|
|
438
|
+
{
|
|
439
|
+
resource_type: 'role',
|
|
440
|
+
resource_id: 'admin',
|
|
441
|
+
warrant: {
|
|
442
|
+
resource_type: 'role',
|
|
443
|
+
resource_id: 'admin',
|
|
444
|
+
relation: 'member',
|
|
445
|
+
subject: {
|
|
446
|
+
resource_type: 'user',
|
|
447
|
+
resource_id: 'user_123',
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
is_implicit: false,
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
list_metadata: {
|
|
454
|
+
before: null,
|
|
455
|
+
after: null,
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
const { data: queryResults } = yield workos.fga.query({
|
|
459
|
+
q: 'select role where user:user_123 is member',
|
|
460
|
+
});
|
|
461
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/query');
|
|
462
|
+
expect(queryResults).toMatchObject([
|
|
463
|
+
{
|
|
464
|
+
resourceType: 'role',
|
|
465
|
+
resourceId: 'admin',
|
|
466
|
+
warrant: {
|
|
467
|
+
resourceType: 'role',
|
|
468
|
+
resourceId: 'admin',
|
|
469
|
+
relation: 'member',
|
|
470
|
+
subject: {
|
|
471
|
+
resourceType: 'user',
|
|
472
|
+
resourceId: 'user_123',
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
isImplicit: false,
|
|
476
|
+
},
|
|
477
|
+
]);
|
|
478
|
+
}));
|
|
479
|
+
it('sends correct params and options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
480
|
+
(0, test_utils_1.fetchOnce)({
|
|
481
|
+
data: [
|
|
482
|
+
{
|
|
483
|
+
resourceType: 'role',
|
|
484
|
+
resourceId: 'admin',
|
|
485
|
+
warrant: {
|
|
486
|
+
resourceType: 'role',
|
|
487
|
+
resourceId: 'admin',
|
|
488
|
+
relation: 'member',
|
|
489
|
+
subject: {
|
|
490
|
+
resourceType: 'user',
|
|
491
|
+
resourceId: 'user_123',
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
isImplicit: false,
|
|
495
|
+
},
|
|
496
|
+
],
|
|
497
|
+
list_metadata: {
|
|
498
|
+
before: null,
|
|
499
|
+
after: null,
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
yield workos.fga.query({
|
|
503
|
+
q: 'select role where user:user_123 is member',
|
|
504
|
+
order: 'asc',
|
|
505
|
+
}, {
|
|
506
|
+
warrantToken: 'some_token',
|
|
507
|
+
});
|
|
508
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/query');
|
|
509
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
510
|
+
q: 'select role where user:user_123 is member',
|
|
511
|
+
order: 'asc',
|
|
512
|
+
});
|
|
513
|
+
expect((0, test_utils_1.fetchHeaders)()).toMatchObject({
|
|
514
|
+
'Warrant-Token': 'some_token',
|
|
515
|
+
});
|
|
516
|
+
}));
|
|
517
|
+
});
|
|
518
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheckOp = void 0;
|
|
4
|
+
var CheckOp;
|
|
5
|
+
(function (CheckOp) {
|
|
6
|
+
CheckOp["AllOf"] = "all_of";
|
|
7
|
+
CheckOp["AnyOf"] = "any_of";
|
|
8
|
+
CheckOp["Batch"] = "batch";
|
|
9
|
+
})(CheckOp || (exports.CheckOp = CheckOp = {}));
|