@itwin/object-storage-s3
Version:
Object storage implementation base for S3 compatible providers
42 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAndUseClient = createAndUseClient;
exports.getExpiresInSeconds = getExpiresInSeconds;
exports.getActions = getActions;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const internal_1 = require("@itwin/object-storage-core/lib/common/internal");
async function createAndUseClient(clientFactory, method) {
const clientWrapper = clientFactory();
try {
return await method(clientWrapper);
}
finally {
clientWrapper.releaseResources();
}
}
function getExpiresInSeconds(options) {
if (options?.expiresInSeconds && options?.expiresOn) {
throw new Error("Only one of 'expiresInSeconds' and 'expiresOn' can be specified.");
}
if (options?.expiresInSeconds) {
return Math.floor(options.expiresInSeconds);
}
if (options?.expiresOn) {
return Math.floor((options.expiresOn.getTime() - Date.now()) / 1000);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- false positive
return internal_1.defaultExpiresInSeconds; // expires in one hour by default
}
function getActions() {
const actions = [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucket",
];
return actions;
}
//# sourceMappingURL=Helpers.js.map