Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

ES6 and npm usage #133

Closed
johnf opened this issue Aug 27, 2016 · 7 comments
Closed

ES6 and npm usage #133

johnf opened this issue Aug 27, 2016 · 7 comments

Comments

@johnf
Copy link
Contributor

johnf commented Aug 27, 2016

Just as an FYI for others and maybe for some README improvements. I've done the following to get it working.

Followed the instructions in the README to configure webpack as they are but then in my code I do

import AWS from 'aws-sdk';
// FIXME: Remove this when https://github.com/aws/amazon-cognito-identity-js/pull/120 is merged.
AWS.config.region = 'us-east-1';

import { CognitoUserPool, CognitoUserAttribute, CognitoUser } from 'amazon-cognito-identity-js';

const poolData = {
  UserPoolId : 'us-east-1_XXX',
  ClientId : 'YYY',
};

const userPool = new CognitoUserPool(poolData);
userPool.signUp(username, password, attributeList, validationData, callback);
@simonbuchan
Copy link
Contributor

Yeah, I didn't get arond to updating example usage, since I'm not sure how we want to handle it without breaking loose script usage, see the description in #119.

Barring AuthenticationDetails (which is totally useless), all the exported types that look like they are intended to be public start with Cognito..., so we could push the modular usage and say:

The usage examples use the unqualified names for types in the Amazon Cognito Identity SDK for JavaScript, remember to import or qualify access to any of these types:

    ```
    // Loose Javascript files:
    var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;

    // Also under the original name:
    var CognitoUserPool = AWSCognito.CognitoIndentityServiceProvider.CognitoUserPool;

    // Modules, e.g. Webpack:
    var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
    var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;

    // ES Modules, e.g. transpiling with Babel
    import { CognitoUserPool } from 'amazon-cognito-identity-js';
    ```

@itrestian
Copy link
Contributor

Hi guys, I will make the updates to the documentation ASAP. However, if you want to send a pull request that is welcome as well.

@simonbuchan
Copy link
Contributor

@itrestian See alse the recent webpack update in aws-sdk-js, we should probably align / link to their webpack docs, esp. if they land aws/aws-sdk-js#1117.

@itrestian
Copy link
Contributor

Thanks Simon. I will work on this these next few days.

@itrestian
Copy link
Contributor

itrestian commented Sep 2, 2016

So I will add the below just under the Usage section, before all the use cases, if everyone is ok with it. It's along the lines you both mentioned:

The usage examples below use the unqualified names for types in the Amazon Cognito Identity SDK for JavaScript. Remember to import or qualify access to any of these types:

    ```
    // When using loose Javascript files:
    var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;

    // Wnder the original name:
    var CognitoUserPool = AWSCognito.CognitoIndentityServiceProvider.CognitoUserPool;

    // Modules, e.g. Webpack:
    var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
    var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;

    // ES Modules, e.g. transpiling with Babel
    import { CognitoUserPool, CognitoUserAttribute, CognitoUser } from 'amazon-cognito-identity-js';
    ```

@simonbuchan
Copy link
Contributor

👍 Looks great!

@itrestian
Copy link
Contributor

Updated. Thanks everyone!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants