aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.41k stars 2.11k forks source link

Amplify class (Amplify.ts) of aws-amplify unpredictable behaviour #1419

Closed akasa9525 closed 5 years ago

akasa9525 commented 6 years ago

I am using Node js - 8.11.3

var awsAmplify = require('aws-amplify');
    awsAmplify.configure({
          //
    });

throws me an error : awsAmplify.configure is not a function But we see in aws-amplify/packages/aws-amplify/src/Common/Amplify.ts at line 28, there is a static function by the name of configure.

I found that this issue is happening because, all the member functions oh the amplify class are wrapped in a json with key as default.

Amplify structure:

{ Analytics:
   AnalyticsClass {
     _config: {},
     _pluggables: [],
     _disabled: false,
     onHubCapsule: [Function] },
  AnalyticsClass: [Function: AnalyticsClass],
  AWSPinpointProvider: { [Function: AWSPinpointProvider] category: 'Analytics', providerName: 'AWSPinpoint' },
  AWSKinesisProvider: [Function: AWSKinesisProvider],
  Auth:
   AuthClass {
     userPool: null,
     _cognitoAuthClient: null,
     user: null,
     _gettingCredPromise: null,
     currentUserCredentials: [Function: bound ] },
  AuthClass: [Function: AuthClass],
  Storage:
   StorageClass {
     _options: null,
     vault: StorageClass { _options: [Object] },
     configure: [Function] },
  StorageClass: [Function: StorageClass],
  API: APIClass { _api: null, _pubSub: null, _options: null },
  APIClass: [Function: APIClass],
  graphqlOperation: [Function],
  PubSub:
   PubSub {
     _options: null,
     _pluggables: [],
     subscribe: [Function: bound ] },
  PubSubClass: [Function: PubSub],
  Cache:
   BrowserStorageCache {
     config:
      { keyPrefix: 'aws-amplify-cache',
        capacityInBytes: 1048576,
        itemMaxSize: 210000,
        defaultTTL: 259200000,
        defaultPriority: 5,
        warningThreshold: 0.8,
        storage: [Object] },
     cacheCurSizeKey: 'aws-amplify-cacheCurSize',
     getItem: [Function: bound ],
     setItem: [Function: bound ],
     removeItem: [Function: bound ] },
  Interactions: Interactions { _options: null, _pluggables: {} },
  InteractionsClass: [Function: Interactions],
  Logger: { [Function: ConsoleLogger] LOG_LEVEL: null },
  Hub:
   HubClass {
     bus: [],
     listeners: { auth: [Array], storage: [Array], analytics: [Array] },
     name: '__default__' },
  JS:
   { [Function: JS]
     isEmpty: [Function],
     sortByField: [Function],
     objectLessAttributes: [Function],
     filenameToContentType: [Function],
     isTextFile: [Function],
     generateRandomString: [Function],
     makeQuerablePromise: [Function] },
  ClientDevice: { [Function: ClientDevice] clientInfo: [Function], dimension: [Function] },
  Signer: { [Function: Signer] sign: [Function: sign], signUrl: [Function: signUrl] },
  I18n:
   { [Function: I18n]
     configure: [Function],
     getModuleName: [Function],
     createInstance: [Function],
     setLanguage: [Function],
     get: [Function],
     putVocabulariesForLanguage: [Function],
     putVocabularies: [Function],
     checkConfig: [Function] },
  ServiceWorker: [Function: ServiceWorkerClass],
  default:
   { [Function: Amplify]
     register: [Function],
     configure: [Function],
     addPluggable: [Function],
     _components:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     _config: {},
     Auth:
      AuthClass {
        userPool: null,
        _cognitoAuthClient: null,
        user: null,
        _gettingCredPromise: null,
        currentUserCredentials: [Function: bound ] },
     Analytics:
      AnalyticsClass {
        _config: {},
        _pluggables: [],
        _disabled: false,
        onHubCapsule: [Function] },
     API: APIClass { _api: null, _pubSub: null, _options: null },
     Storage: StorageClass { _options: null, vault: [Object], configure: [Function] },
     I18n:
      { [Function: I18n]
        configure: [Function],
        getModuleName: [Function],
        createInstance: [Function],
        setLanguage: [Function],
        get: [Function],
        putVocabulariesForLanguage: [Function],
        putVocabularies: [Function],
        checkConfig: [Function] },
     Cache:
      BrowserStorageCache {
        config: [Object],
        cacheCurSizeKey: 'aws-amplify-cacheCurSize',
        getItem: [Function: bound ],
        setItem: [Function: bound ],
        removeItem: [Function: bound ] },
     PubSub:
      PubSub {
        _options: null,
        _pluggables: [],
        subscribe: [Function: bound ] },
     Interactions: Interactions { _options: null, _pluggables: {} },
     Pushnotification: null,
     Logger: { [Function: ConsoleLogger] LOG_LEVEL: null },
     ServiceWorker: [Function: ServiceWorkerClass] } }

so for calling the configure function i had to use awsAmplify.default.configure()
We can remove this default wrapping around the members of amplify class.

powerful23 commented 6 years ago

@akasa9525 This is a expected behavior. Will this as documentation enhancement.

mlabieniec commented 5 years ago

closing this and referencing in story for node support as we currently do not support running amplify in node

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.