0.5.0 • Published 6 years ago
@tingcore/awsome v0.5.0
awsome
AWSome AWS utilities for web browsers and React Native.
Notes
This library assumes a somewhat standards-compliant, browser-like environment. It will not work by default in Node. Missing features must to be polyfilled.
In React Native, you will need to link the native dependencies first.
react-native link amazon-cognito-identity-js
Required features:
The list may be incomplete.
- Browser
XMLHttpRequest
navigator
- ECMAScript 2015
Map
Promise
Symbol
,Symbol.for
,Symbol.iterator
Array.from
ArrayBuffer
,Uint8Array
,Uint32Array
,Int32Array
- WHATWG Fetch
fetch
Request
Headers
Headers.prototype[Symbol.iterator]
- WHATWG URL
URL
(Must have thesearchParams
getter/setter)URLSearchParams
URLSearchParams.prototype[Symbol.iterator]
Optional features:
- ECMAScript 2017
String.prototype.padStart
- W3C Web Cryptography API
crypto.subtle
orcrypto.webkitSubtle
- WHATWG Encoding
TextEncoder
andTextDecoder
- WHATWG Fetch
Request.prototype.arrayBuffer
Example
import { SignInResultType, UserPool } from '@tingcore/awsome';
const userPool = new UserPool({
region: '<REGION>',
clientId: '<CLIENT_ID>',
userPoolId: '<USER_POOL_ID>',
identityPoolId: '<IDENTITY_POOL_ID>',
});
(async () => {
const signInResult = await userPool.signIn('<USERNAME>', '<PASSWORD>');
if (signInResult.type === SignInResultType.Authenticated) {
const { user } = signInResult;
// Call an API behind API Gateway
// The request will be signed with the current credentials using AWS Signature V4
const url = 'https://<API_ID>.execute-api.<REGION>.amazonaws.com/<STAGE_NAME>/<RESOURCE_PATH>';
const response = await user.fetchWithSignature(url);
const data = await response.json();
console.log(data);
}
})();