Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-amplify

Package Overview
Dependencies
Maintainers
8
Versions
2384
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-amplify - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

7

lib/Analytics/Analytics.d.ts

@@ -47,2 +47,7 @@ import { AnalyticsOptions, EventAttributes, EventMetrics } from './types';

/**
* Receive a capsule from Hub
* @param {any} capsuak - The message from hub
*/
onHubCapsule(capsule: any): void;
/**
* Record one analytic event

@@ -71,3 +76,3 @@ * @param {String} name - Event name

*/
_ensureCredentials(): any;
_ensureCredentials(): Promise<boolean>;
/**

@@ -74,0 +79,0 @@ * @private

244

lib/Analytics/Analytics.js

@@ -106,30 +106,43 @@ "use strict";

AnalyticsClass.prototype.startSession = function () {
var _this = this;
logger.debug('record session start');
var sessionId = this.generateRandomString();
this._sessionId = sessionId;
var clientContext = this._generateClientContext();
var params = {
clientContext: clientContext,
events: [
{
eventType: '_session.start',
timestamp: new Date().toISOString(),
'session': {
'id': sessionId,
'startTimestamp': new Date().toISOString()
}
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var credentialsOK, sessionId, clientContext, params;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._ensureCredentials()];
case 1:
credentialsOK = _a.sent();
if (!credentialsOK) {
return [2 /*return*/, Promise.resolve(false)];
}
logger.debug('record session start');
sessionId = this.generateRandomString();
this._sessionId = sessionId;
clientContext = this._generateClientContext();
params = {
clientContext: clientContext,
events: [
{
eventType: '_session.start',
timestamp: new Date().toISOString(),
'session': {
'id': sessionId,
'startTimestamp': new Date().toISOString()
}
}
]
};
return [2 /*return*/, new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ', data);
res(data);
}
});
})];
}
]
};
return new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ', data);
res(data);
}
});

@@ -143,29 +156,42 @@ });

AnalyticsClass.prototype.stopSession = function () {
var _this = this;
logger.debug('record session stop');
var sessionId = this._sessionId ? this._sessionId : this.generateRandomString();
var clientContext = this._generateClientContext();
var params = {
clientContext: clientContext,
events: [
{
eventType: '_session.stop',
timestamp: new Date().toISOString(),
'session': {
'id': sessionId,
'startTimestamp': new Date().toISOString()
}
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var credentialsOK, sessionId, clientContext, params;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._ensureCredentials()];
case 1:
credentialsOK = _a.sent();
if (!credentialsOK) {
return [2 /*return*/, Promise.resolve(false)];
}
logger.debug('record session stop');
sessionId = this._sessionId ? this._sessionId : this.generateRandomString();
clientContext = this._generateClientContext();
params = {
clientContext: clientContext,
events: [
{
eventType: '_session.stop',
timestamp: new Date().toISOString(),
'session': {
'id': sessionId,
'startTimestamp': new Date().toISOString()
}
}
]
};
return [2 /*return*/, new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ', data);
res(data);
}
});
})];
}
]
};
return new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ', data);
res(data);
}
});

@@ -181,11 +207,20 @@ });

return __awaiter(this, void 0, void 0, function () {
var _this = this;
var ret;
return __generator(this, function (_a) {
this.stopSession().then(function (data) {
logger.debug('restarting clients');
return _this._initClients();
}).catch(function (e) {
logger.debug('restart error', e);
});
return [2 /*return*/];
switch (_a.label) {
case 0: return [4 /*yield*/, this._initClients()];
case 1:
ret = _a.sent();
if (!ret) {
logger.debug('restart failed');
return [2 /*return*/];
}
this.stopSession().then(function (data) {
logger.debug('restarting clients');
return;
}).catch(function (e) {
logger.debug('restart error', e);
});
return [2 /*return*/];
}
});

@@ -202,39 +237,58 @@ });

AnalyticsClass.prototype.record = function (name, attributes, metrics) {
var _this = this;
logger.debug("record event: { name: " + name + ", attributes: " + attributes + ", metrics: " + metrics);
// if mobile analytics client not ready, buffer it
if (!this.mobileAnalytics) {
logger.debug('mobileAnalytics not ready, put in buffer');
this._buffer.push({
name: name,
attributes: attributes,
metrics: metrics
});
return;
}
var clientContext = this._generateClientContext();
var params = {
clientContext: clientContext,
events: [
{
eventType: name,
timestamp: new Date().toISOString(),
attributes: attributes,
metrics: metrics
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var credentialsOK, clientContext, params;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.debug("record event: { name: " + name + ", attributes: " + attributes + ", metrics: " + metrics);
return [4 /*yield*/, this._ensureCredentials()];
case 1:
credentialsOK = _a.sent();
if (!credentialsOK) {
return [2 /*return*/, Promise.resolve(false)];
}
// if mobile analytics client not ready, buffer it
if (!this.mobileAnalytics) {
logger.debug('mobileAnalytics not ready, put in buffer');
this._buffer.push({
name: name,
attributes: attributes,
metrics: metrics
});
return [2 /*return*/];
}
clientContext = this._generateClientContext();
params = {
clientContext: clientContext,
events: [
{
eventType: name,
timestamp: new Date().toISOString(),
attributes: attributes,
metrics: metrics
}
]
};
return [2 /*return*/, new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ', data);
res(data);
}
});
})];
}
]
};
return new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ', data);
res(data);
}
});
});
};
/**
* Receive a capsule from Hub
* @param {any} capsuak - The message from hub
*/
AnalyticsClass.prototype.onHubCapsule = function (capsule) { };
/*

@@ -320,2 +374,4 @@ _putEventsCallback() {

.then(function (credentials) {
if (!credentials)
return false;
var cred = Auth_1.default.essentialCredentials(credentials);

@@ -322,0 +378,0 @@ conf.credentials = cred;

@@ -1,2 +0,3 @@

declare const Analytics: any;
import AnalyticsClass from './Analytics';
declare const Analytics: AnalyticsClass;
export default Analytics;

@@ -83,3 +83,3 @@ /**

*/
_ensureCredentials(): any;
_ensureCredentials(): Promise<boolean>;
}

@@ -371,2 +371,4 @@ "use strict";

.then(function (credentials) {
if (!credentials)
return false;
var cred = Auth_1.default.essentialCredentials(credentials);

@@ -373,0 +375,0 @@ logger.debug('set credentials for api', cred);

@@ -1,2 +0,3 @@

declare const API: any;
import APIClass from './API';
declare const API: APIClass;
export default API;

@@ -17,2 +17,3 @@ import { apiOptions } from './types';

private _options;
private _region;
/**

@@ -87,5 +88,5 @@ * @param {RestClientOptions} [options] - Instance options

/** private methods **/
private _signed(params, credentials);
private _request(params);
private _signed(params, credentials, isAllResponse);
private _request(params, isAllResponse);
private _parseUrl(url);
}

@@ -82,2 +82,3 @@ "use strict";

function RestClient(options) {
this._region = null;
var endpoints = options.endpoints;

@@ -105,3 +106,3 @@ this._options = options;

var _this = this;
var parsed_url, params, libraryHeaders, userAgent, extraParams;
var parsed_url, params, libraryHeaders, userAgent, extraParams, isAllResponse;
return __generator(this, function (_a) {

@@ -126,2 +127,3 @@ logger.debug(method + ' ' + url);

extraParams = Object.assign({}, init);
isAllResponse = init ? init.response : null;
if (extraParams.body) {

@@ -135,6 +137,6 @@ libraryHeaders['content-type'] = 'application/json; charset=UTF-8';

if (params.headers['Authorization']) {
return [2 /*return*/, this._request(params)];
return [2 /*return*/, this._request(params, isAllResponse)];
}
return [2 /*return*/, Auth_1.default.currentCredentials()
.then(function (credentials) { return _this._signed(params, credentials); })];
.then(function (credentials) { return _this._signed(params, credentials, isAllResponse); })];
});

@@ -203,2 +205,3 @@ });

RestClient.prototype.endpoint = function (apiName) {
var _this = this;
var cloud_logic_array = this._options.endpoints;

@@ -209,2 +212,8 @@ var response = '';

response = v.endpoint;
if (typeof v.region === 'string') {
_this._region = v.region;
}
else if (typeof _this._options.region === 'string') {
_this._region = _this._options.region;
}
}

@@ -215,15 +224,21 @@ });

/** private methods **/
RestClient.prototype._signed = function (params, credentials) {
var signed_params = Signer_1.default.sign(params, {
secret_key: credentials.secretAccessKey,
access_key: credentials.accessKeyId,
session_token: credentials.sessionToken
});
RestClient.prototype._signed = function (params, credentials, isAllResponse) {
var endpoint_region = this._region || this._options.region;
var creds = {
'secret_key': credentials.secretAccessKey,
'access_key': credentials.accessKeyId,
'session_token': credentials.sessionToken
};
var service_info = {
'service': 'execute-api',
'region': endpoint_region
};
var signed_params = Signer_1.default.sign(params, creds, service_info);
if (signed_params.data) {
signed_params.body = signed_params.data;
}
logger.debug(signed_params);
logger.debug('Signed Request: ', signed_params);
delete signed_params.headers['host'];
return axios_1.default(signed_params)
.then(function (response) { return response.data; })
.then(function (response) { return isAllResponse ? response : response.data; })
.catch(function (error) {

@@ -234,5 +249,5 @@ logger.debug(error);

};
RestClient.prototype._request = function (params) {
RestClient.prototype._request = function (params, isAllResponse) {
return axios_1.default(params)
.then(function (response) { return response.data; })
.then(function (response) { return isAllResponse ? response : response.data; })
.catch(function (error) {

@@ -239,0 +254,0 @@ logger.debug(error);

@@ -89,3 +89,4 @@ "use strict";

region: conf['aws_cognito_region'],
identityPoolId: conf['aws_cognito_identity_pool_id']
identityPoolId: conf['aws_cognito_identity_pool_id'],
mandatorySignIn: conf['aws_mandatory_sign_in'] === 'enable' ? true : false
};

@@ -449,2 +450,5 @@ }

return this.getSyncedUser().then(function (user) {
if (!user) {
return Promise.reject('No current user in userPool');
}
return new Promise(function (resolve, reject) {

@@ -874,3 +878,3 @@ user.getSession(function (err, session) {

AuthClass.prototype.pickupCredentials = function () {
var _this = this;
var that = this;
if (this.credentials) {

@@ -884,7 +888,12 @@ return this.keepAlive();

return this.currentUserCredentials()
.then(function () { return _this.keepAlive(); })
.then(function () {
if (that.credentials_source === 'no credentials') {
return Promise.resolve(null);
}
return that.keepAlive();
})
.catch(function (err) {
logger.debug('error when pickup', err);
_this.setCredentialsForGuest();
return _this.keepAlive();
that.setCredentialsForGuest();
return that.keepAlive();
});

@@ -902,3 +911,8 @@ }

AuthClass.prototype.setCredentialsForGuest = function () {
var _a = this._config, identityPoolId = _a.identityPoolId, region = _a.region;
var _a = this._config, identityPoolId = _a.identityPoolId, region = _a.region, mandatorySignIn = _a.mandatorySignIn;
if (mandatorySignIn) {
this.credentials = null;
this.credentials_source = 'no credentials';
return;
}
var credentials = new CognitoIdentityCredentials({

@@ -905,0 +919,0 @@ IdentityPoolId: identityPoolId

@@ -1,2 +0,3 @@

declare const Auth: any;
import AuthClass from './Auth';
declare const Auth: AuthClass;
export default Auth;

@@ -17,2 +17,3 @@ /**

region?: string;
mandatorySignIn: boolean;
}

@@ -19,0 +20,0 @@ /**

@@ -1,2 +0,3 @@

declare const Storage: any;
import StorageClass from './Storage';
declare const Storage: StorageClass;
export default Storage;

@@ -11,2 +11,6 @@ import { StorageOptions } from './types';

/**
* @public
*/
vault: StorageClass;
/**
* Initialize Storage with AWS configurations

@@ -54,3 +58,3 @@ * @param {Object} options - Configuration object for storage

*/
_ensureCredentials(): any;
_ensureCredentials(): Promise<boolean>;
/**

@@ -57,0 +61,0 @@ * @private

@@ -314,2 +314,4 @@ "use strict";

.then(function (credentials) {
if (!credentials)
return false;
var cred = Auth_1.default.essentialCredentials(credentials);

@@ -316,0 +318,0 @@ logger.debug('set credentials for storage', cred);

{
"name": "aws-amplify",
"version": "0.2.6",
"version": "0.2.7",
"description": "AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.",

@@ -58,3 +58,3 @@ "main": "./lib/index.js",

"amazon-cognito-identity-js": "^2.0.0",
"aws-sdk": "2.193.0",
"aws-sdk": "2.198.0",
"axios": "^0.17.0"

@@ -61,0 +61,0 @@ },

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc