Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function ValidateRequest() : void {
let requestAppId = '';
if (this._event.context) {
requestAppId = this._event.context.System.application.applicationId;
} else if (this._event.session) {
requestAppId = this._event.session.application.applicationId;
}
if (!this.appId) {
console.log('Warning: Application ID is not set');
}
try {
if (this.appId && (requestAppId !== this.appId)) {
console.log(`The applicationIds don\'t match: ${requestAppId} and ${this.appId}`);
const error = createAskSdkError('In validating request', 'Invalid ApplicationId: ' + this.appId);
if (typeof this.callback === 'undefined') {
this._context.fail(error);
} else {
this._callback(error);
}
}
if (this.dynamoDBTableName && (!this._event.session.sessionId || this._event.session.new)) {
if (!dynamoDbPersistenceAdapter) {
dynamoDbPersistenceAdapter = new DynamoDbPersistenceAdapter({
createTable : true,
dynamoDBClient : this.dynamoDBClient,
partitionKeyName : 'userId',
attributesName : 'mapAttr',
tableName : this.dynamoDBTableName,
});
return new Promise((resolve, reject) => {
this.adapter.promiseResolve = resolve;
try {
if (this.adapter.listenerCount(this.targetHandlerName + this.adapter.state) >= 1) {
this.adapter.emit(this.targetHandlerName + this.adapter.state);
} else if (this.adapter.listenerCount('Unhandled' + this.adapter.state) >= 1) {
this.adapter.emit('Unhandled' + this.adapter.state);
} else {
reject(createAskSdkError(
this.constructor.name,
`In state: ${this.adapter.state}. No handler function was defined for event ${this.targetHandlerName} and no 'Unhandled' function was defined.`));
}
} catch (e) {
reject(e);
}
});
}
function EmitWithState() : void {
if (arguments.length === 0) {
throw createAskSdkError(this.constructor.name, 'EmitWithState called without arguments');
}
arguments[0] = arguments[0] + this.state;
if (this.listenerCount(arguments[0]) < 1) {
arguments[0] = 'Unhandled' + this.state;
}
if (this.listenerCount(arguments[0]) < 1) {
throw createAskSdkError(this.constructor.name, `No 'Unhandled' function defined for event: ${arguments[0]}`);
}
this.emit.apply(this, arguments);
}
public registerHandlers(...v1Handlers : V1Handler[]) : void {
for ( const handler of v1Handlers) {
if (!IsObject(handler)) {
throw createAskSdkError(this.constructor.name, `Argument #${handler.constructor.name} was not an Object`);
}
const eventNames = Object.keys(handler);
for (const eventName of eventNames) {
if (typeof(handler[eventName]) !== 'function') {
throw createAskSdkError(this.constructor.name, `Event handler for '${eventName}' was not a function`);
}
let targetEventName = eventName;
if (handler[StateString as any]) {
targetEventName += handler[StateString as any];
}
const handlerContext = {
on: this.on.bind(this),
emit: this.emit.bind(this),
emitWithState: EmitWithState.bind(this),
handler: this,
i18n: this.i18n,
locale: this.locale,
t : (...argArray : string[]) : string => {
}, (err) => {
if (err) {
throw createAskSdkError(this.constructor.name, 'Error initializing i19next: ' + err);
}
ValidateRequest.call(this);
});
} else {
public registerHandlers(...v1Handlers : V1Handler[]) : void {
for ( const handler of v1Handlers) {
if (!IsObject(handler)) {
throw createAskSdkError(this.constructor.name, `Argument #${handler.constructor.name} was not an Object`);
}
const eventNames = Object.keys(handler);
for (const eventName of eventNames) {
if (typeof(handler[eventName]) !== 'function') {
throw createAskSdkError(this.constructor.name, `Event handler for '${eventName}' was not a function`);
}
let targetEventName = eventName;
if (handler[StateString as any]) {
targetEventName += handler[StateString as any];
}
const handlerContext = {
on: this.on.bind(this),
emit: this.emit.bind(this),
function EmitWithState() : void {
if (arguments.length === 0) {
throw createAskSdkError(this.constructor.name, 'EmitWithState called without arguments');
}
arguments[0] = arguments[0] + this.state;
if (this.listenerCount(arguments[0]) < 1) {
arguments[0] = 'Unhandled' + this.state;
}
if (this.listenerCount(arguments[0]) < 1) {
throw createAskSdkError(this.constructor.name, `No 'Unhandled' function defined for event: ${arguments[0]}`);
}
this.emit.apply(this, arguments);
}
.catch((error) => {
const err = createAskSdkError(this.constructor.name, 'Error fetching user state: ' + error);
if (typeof this._callback === 'undefined') {
return this._context.fail(err);
} else {
return this._callback(err);
}
});
} else {