0.5.0 • Published 7 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-jsRequired features:
The list may be incomplete.
- Browser
XMLHttpRequestnavigator
- ECMAScript 2015
MapPromiseSymbol,Symbol.for,Symbol.iteratorArray.fromArrayBuffer,Uint8Array,Uint32Array,Int32Array
- WHATWG Fetch
fetchRequestHeadersHeaders.prototype[Symbol.iterator]
- WHATWG URL
URL(Must have thesearchParamsgetter/setter)URLSearchParamsURLSearchParams.prototype[Symbol.iterator]
Optional features:
- ECMAScript 2017
String.prototype.padStart
- W3C Web Cryptography API
crypto.subtleorcrypto.webkitSubtle
- WHATWG Encoding
TextEncoderandTextDecoder
- 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);
}
})();