@openfga/sdk
Advanced tools
Comparing version 0.3.2 to 0.3.3
# Changelog | ||
## v0.3.3 | ||
### [0.3.3](https://github.com/openfga/js-sdk/compare/v0.3.2...v0.3.3) (2024-02-26) | ||
- fix: do not call ReadAuthorizationModel on BatchCheck or non-Transactional Write | ||
## v0.3.2 | ||
### [0.3.1](https://github.com/openfga/js-sdk/compare/v0.3.1...v0.3.2) (2024-02-13) | ||
### [0.3.2](https://github.com/openfga/js-sdk/compare/v0.3.1...v0.3.2) (2024-02-13) | ||
@@ -7,0 +13,0 @@ - feat: add example project |
@@ -268,2 +268,3 @@ "use strict"; | ||
write(body, options = {}) { | ||
var _a, e_1, _b, _c, _d, e_2, _e, _f; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -297,64 +298,65 @@ const { transaction = {}, headers = {} } = options; | ||
} | ||
// We initiate two chains in parallel (to avoid unnecessary latency) | ||
// 1- the actual request that we'll return at the end | ||
// 2- a request to check whether the store ID, auth model ID, and credentials are valid | ||
return Promise.all([ | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
var _a, e_1, _b, _c, _d, e_2, _e, _f; | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_METHOD_HEADER, "Write"); | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_BULK_REQUEST_ID_HEADER, (0, utils_1.generateRandomIdWithNonUniqueFallback)()); | ||
const writeResponses = []; | ||
if (writes === null || writes === void 0 ? void 0 : writes.length) { | ||
try { | ||
for (var _g = true, _h = __asyncValues(asyncPool(maxParallelRequests, (0, utils_1.chunkArray)(writes, maxPerChunk), (chunk) => this.writeTuples(chunk, Object.assign(Object.assign({}, options), { headers, transaction: undefined })).catch(err => ({ | ||
writes: chunk.map(tuple => ({ | ||
tuple_key: tuple, | ||
status: ClientWriteStatus.FAILURE, | ||
err, | ||
})), | ||
deletes: [] | ||
})))), _j; _j = yield _h.next(), _a = _j.done, !_a; _g = true) { | ||
_c = _j.value; | ||
_g = false; | ||
const singleChunkResponse = _c; | ||
writeResponses.push(singleChunkResponse.writes); | ||
} | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_METHOD_HEADER, "Write"); | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_BULK_REQUEST_ID_HEADER, (0, utils_1.generateRandomIdWithNonUniqueFallback)()); | ||
const writeResponses = []; | ||
if (writes === null || writes === void 0 ? void 0 : writes.length) { | ||
try { | ||
for (var _g = true, _h = __asyncValues(asyncPool(maxParallelRequests, (0, utils_1.chunkArray)(writes, maxPerChunk), (chunk) => this.writeTuples(chunk, Object.assign(Object.assign({}, options), { headers, transaction: undefined })).catch(err => { | ||
if (err instanceof errors_1.FgaApiAuthenticationError) { | ||
throw err; | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (!_g && !_a && (_b = _h.return)) yield _b.call(_h); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return { | ||
writes: chunk.map(tuple => ({ | ||
tuple_key: tuple, | ||
status: ClientWriteStatus.FAILURE, | ||
err, | ||
})), | ||
deletes: [] | ||
}; | ||
}))), _j; _j = yield _h.next(), _a = _j.done, !_a; _g = true) { | ||
_c = _j.value; | ||
_g = false; | ||
const singleChunkResponse = _c; | ||
writeResponses.push(singleChunkResponse.writes); | ||
} | ||
const deleteResponses = []; | ||
if (deletes === null || deletes === void 0 ? void 0 : deletes.length) { | ||
try { | ||
for (var _k = true, _l = __asyncValues(asyncPool(maxParallelRequests, (0, utils_1.chunkArray)(deletes, maxPerChunk), (chunk) => this.deleteTuples(chunk, Object.assign(Object.assign({}, options), { headers, transaction: undefined })).catch(err => ({ | ||
writes: [], | ||
deletes: chunk.map(tuple => ({ | ||
tuple_key: tuple, | ||
status: ClientWriteStatus.FAILURE, | ||
err, | ||
})) | ||
})))), _m; _m = yield _l.next(), _d = _m.done, !_d; _k = true) { | ||
_f = _m.value; | ||
_k = false; | ||
const singleChunkResponse = _f; | ||
deleteResponses.push(singleChunkResponse.deletes); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (!_g && !_a && (_b = _h.return)) yield _b.call(_h); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
const deleteResponses = []; | ||
if (deletes === null || deletes === void 0 ? void 0 : deletes.length) { | ||
try { | ||
for (var _k = true, _l = __asyncValues(asyncPool(maxParallelRequests, (0, utils_1.chunkArray)(deletes, maxPerChunk), (chunk) => this.deleteTuples(chunk, Object.assign(Object.assign({}, options), { headers, transaction: undefined })).catch(err => { | ||
if (err instanceof errors_1.FgaApiAuthenticationError) { | ||
throw err; | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (!_k && !_d && (_e = _l.return)) yield _e.call(_l); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
return { | ||
writes: [], | ||
deletes: chunk.map(tuple => ({ | ||
tuple_key: tuple, | ||
status: ClientWriteStatus.FAILURE, | ||
err, | ||
})), | ||
}; | ||
}))), _m; _m = yield _l.next(), _d = _m.done, !_d; _k = true) { | ||
_f = _m.value; | ||
_k = false; | ||
const singleChunkResponse = _f; | ||
deleteResponses.push(singleChunkResponse.deletes); | ||
} | ||
return { writes: writeResponses.flat(), deletes: deleteResponses.flat() }; | ||
}))(), | ||
this.checkValidApiConnection(options), | ||
]).then(res => res[0]); | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (!_k && !_d && (_e = _l.return)) yield _e.call(_l); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
} | ||
return { writes: writeResponses.flat(), deletes: deleteResponses.flat() }; | ||
}); | ||
@@ -443,43 +445,38 @@ } | ||
batchCheck(body, options = {}) { | ||
var _a, e_3, _b, _c; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// We initiate two chains in parallel (to avoid unnecessary latency) | ||
// 1- the actual request that we'll return at the end | ||
// 2- a request to check whether the store ID, auth model ID, and credentials are valid | ||
return Promise.all([ | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
var _a, e_3, _b, _c; | ||
const { headers = {}, maxParallelRequests = DEFAULT_MAX_METHOD_PARALLEL_REQS } = options; | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_METHOD_HEADER, "BatchCheck"); | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_BULK_REQUEST_ID_HEADER, (0, utils_1.generateRandomIdWithNonUniqueFallback)()); | ||
const responses = []; | ||
try { | ||
for (var _d = true, _e = __asyncValues(asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, Object.assign(Object.assign({}, options), { headers })) | ||
.then(response => { | ||
response._request = tuple; | ||
return response; | ||
}) | ||
.catch(err => { | ||
return { | ||
allowed: undefined, | ||
error: err, | ||
_request: tuple, | ||
}; | ||
}))), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) { | ||
_c = _f.value; | ||
_d = false; | ||
const singleCheckResponse = _c; | ||
responses.push(singleCheckResponse); | ||
} | ||
const { headers = {}, maxParallelRequests = DEFAULT_MAX_METHOD_PARALLEL_REQS } = options; | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_METHOD_HEADER, "BatchCheck"); | ||
(0, utils_1.setHeaderIfNotSet)(headers, CLIENT_BULK_REQUEST_ID_HEADER, (0, utils_1.generateRandomIdWithNonUniqueFallback)()); | ||
const responses = []; | ||
try { | ||
for (var _d = true, _e = __asyncValues(asyncPool(maxParallelRequests, body, (tuple) => this.check(tuple, Object.assign(Object.assign({}, options), { headers })) | ||
.then(response => { | ||
response._request = tuple; | ||
return response; | ||
}) | ||
.catch(err => { | ||
if (err instanceof errors_1.FgaApiAuthenticationError) { | ||
throw err; | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
return { responses }; | ||
}))(), | ||
this.checkValidApiConnection(options), | ||
]).then(res => res[0]); | ||
return { | ||
allowed: undefined, | ||
error: err, | ||
_request: tuple, | ||
}; | ||
}))), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) { | ||
_c = _f.value; | ||
_d = false; | ||
const singleCheckResponse = _c; | ||
responses.push(singleCheckResponse); | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
return { responses }; | ||
}); | ||
@@ -486,0 +483,0 @@ } |
{ | ||
"name": "@openfga/sdk", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "JavaScript and Node.js SDK for OpenFGA", | ||
@@ -29,10 +29,10 @@ "author": "OpenFGA", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "^20.11.10", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.11.20", | ||
"@types/tiny-async-pool": "^2.0.3", | ||
"@typescript-eslint/eslint-plugin": "^6.19.1", | ||
"@typescript-eslint/parser": "^6.19.1", | ||
"eslint": "^8.56.0", | ||
"@typescript-eslint/eslint-plugin": "^7.0.2", | ||
"@typescript-eslint/parser": "^7.0.2", | ||
"eslint": "^8.57.0", | ||
"jest": "^29.7.0", | ||
"nock": "^13.5.1", | ||
"nock": "^13.5.3", | ||
"ts-jest": "^29.1.2", | ||
@@ -39,0 +39,0 @@ "typescript": "^5.3.3" |
1340476
6075