UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

37 lines (36 loc) 1.73 kB
export const putAccessRole = async (accessRole, { apiUrl, fetch: _fetch = fetch, apiKey }) => { const { awsAccountId, roleName } = accessRole; // We get the access-role first so as to not reissue the access token const getResponse = await _fetch([apiUrl, 'access-role', awsAccountId, roleName].join('/'), { headers: { Authorization: apiKey }, signal: AbortSignal.timeout(30000) }); if (!getResponse.ok) { if (getResponse.status !== 404) { const { message, Message } = (await getResponse.json()); throw new Error(message !== null && message !== void 0 ? message : Message); } const putResponse = await _fetch([apiUrl, 'access-role'].join('/'), { method: 'POST', headers: { Authorization: apiKey }, body: JSON.stringify(accessRole), signal: AbortSignal.timeout(30000) }); if (!putResponse.ok) { const { message, Message } = (await putResponse.json()); throw new Error(message !== null && message !== void 0 ? message : Message); } } }; export const assignAccessRole = async ({ awsAccountId, awsRegion, tableName, roleName }, { apiUrl, fetch: _fetch = fetch, apiKey }) => { const response = await _fetch([apiUrl, 'table', awsAccountId, awsRegion, tableName, 'access-role'].join('/'), { method: 'POST', headers: { Authorization: apiKey }, body: JSON.stringify({ awsAccountId, roleName }), signal: AbortSignal.timeout(30000) }); if (!response.ok) { const { message, Message } = (await response.json()); throw new Error(message !== null && message !== void 0 ? message : Message); } };