return List.get(this.userId, this.listId).then((list) => {
   if (!list.importStatus[this.key]) {
     return List.createFileImportStatus(this.userId, this.listId, this.key, this._createStatusFromEvent());
   } else {
     return List.updateImportStatus(this.userId, this.listId, this.key, this._updateStatusFromEvent());
   }
 });
示例#2
0
export function respond(event, cb) {
  debug('= subscribeToList.action', JSON.stringify(event));
  const params = getParameters(event);
  if (params.listId && params.recipient && params.encodedUserId) {
    const userId = base64url.decode(params.encodedUserId);
    return List.get(userId, params.listId)
      .then((list) => {
        const newRecipient = Object.assign({}, params.recipient, { userId });
        delete newRecipient.u;
        return discoverFieldsFromRequestMetadata(JSON.parse(event.headers))
          .then(systemMetadata => Object.assign({}, newRecipient, { systemMetadata }))
          .then(recipientWithSystemMetadata => ListSubscribeService.subscribe(list, recipientWithSystemMetadata, userId))
          .then(() => handleResponse(null, { listName: list.name }, event, cb))
          .catch((err) => {
            if (err.name === 'RecipientAlreadyExists') {
              return handleResponse({ email: 'E-mail address already exists!' }, null, event, cb);
            } else {
              return handleResponse(err, null, event, cb);
            }
          });
      });
  } else {
    return handleResponse(new Error('Missing params'), null, event, cb);
  }
}
 updateListImportStatus() {
   debug('= UpdateImportStatusService.updateListImportStatus', this.importStatusEvent);
   return List.get(this.userId, this.listId).then((list) => {
     if (!list.importStatus[this.key]) {
       return List.createFileImportStatus(this.userId, this.listId, this.key, this._createStatusFromEvent());
     } else {
       return List.updateImportStatus(this.userId, this.listId, this.key, this._updateStatusFromEvent());
     }
   });
 }
示例#4
0
 decrypt(event.authToken).then((decoded) => {
   let cleanOptions = omitEmpty(event.options);
   cleanOptions.limit = cleanOptions.limit ? parseInt(cleanOptions.limit, 10) : 10;
   List.allBy('userId', decoded.sub, cleanOptions).then(list => {
     debug('= listEmailLists.action', 'Success');
     return cb(null, list);
   })
     .catch(e => {
       debug('= listEmailLists.action', e);
       return cb(ApiErrors.response(e));
     });
 })
示例#5
0
 static async _createSampleListAndRecipients({userId, email, name}) {
   const list = {
     userId,
     id: cuid(),
     name: 'Sample List',
     isDeleted: false.toString(),
     importStatus: {}
   };
   await List.save(list);
   const recipients = this._buildRecipients(email, list.id, userId);
   const recipientsPromises = recipients.map(recipient => Recipient.save(recipient));
   await Promise.all(recipientsPromises);
   return {listId: list.id, userId};
 }
示例#6
0
 decrypt(event.authToken).then((decoded) => {
   if (event.listId) {
     List.delete(decoded.sub, event.listId).then(result => {
       debug('= deleteEmailList.action', 'Success');
       return cb(null, result);
     })
     .catch(e => {
       debug('= deleteEmailList.action', e);
       return cb(ApiErrors.response(e));
     });
   } else {
     return cb(ApiErrors.response('No list specified'));
   }
 })
示例#7
0
 decrypt(event.authToken).then((decoded) => {
   if(decoded.sub === 'google-oauth2|113947278021199221588') throw 'Sorry, the demo account is not allowed to perform this action' //demo account
   if (event.list && event.listId) {
     List.update(event.list, decoded.sub, event.listId).then(list => {
       debug('= updateEmailList.action', 'Success');
       return cb(null, list);
     })
     .catch(e => {
       debug('= updateEmailList.action', e);
       return cb(ApiErrors.response(e));
     });
   } else {
     return cb(ApiErrors.response('No list specified'));
   }
 })
示例#8
0
      sns.publish(params, (err, data) => {
        if (err) {
          debug('= unsubscribeRecipient.action', 'Error publishing to SNS', JSON.stringify(err));
          return cb(ApiErrors.response(err));
        } else {
          debug('= unsubscribeRecipient.action', 'Successfully published to SNS');
          List.get(newRecipient.userId, event.listId).then((list) => {
            const callbackUrl = buildRedirectCallback(process.env.UNSUBSCRIBED_CALLBACK_URL, list, event.recipientId, event.campaignId);
            return cb(null, { url: callbackUrl });
          }).catch((e) => {
            const callbackUrl = process.env.UNSUBSCRIBED_CALLBACK_URL;
            return cb(null, { url: callbackUrl });
          });

        }
      });
 static _doCreate(listId, recipient, userId) {
   const subscriptionOrigin = Recipient.subscriptionOrigins.signupForm;
   const recipientParams = Object.assign({}, { listId, subscriptionOrigin }, omitEmpty(recipient));
   recipientParams.id = base64url.encode(recipient.email);
   return List.get(userId, listId).then((list) => {
     if (list.hasOwnProperty('sendEmailVerificationOnSubscribe')) {
       if (JSON.parse(list.sendEmailVerificationOnSubscribe) === false) {
         recipientParams.status = Recipient.statuses.subscribed;
         return Recipient.save(recipientParams).then(() => recipientParams);
       }
     }
     recipientParams.verificationCode = this._generateVerificationCode();
     recipientParams.status = Recipient.statuses.awaitingConfirmation;
     return Recipient.save(recipientParams).then(() => recipientParams);
   });
 }
示例#10
0
const getList = async ({ params, userId }) => {
  debug('= subscribeToList.getList', JSON.stringify(userId))
  const list = await List.get(userId, params.listId)

  return { params, userId, list }
}
 const getListPromises = listIds.map(listId => List.get(this.userId, listId));
 return Promise.map(Object.keys(aggregatedCounters), (listId) => {
   if (!listIdUserIdMapping[listId]) return true;
   return List.incrementAll(listIdUserIdMapping[listId], listId, aggregatedCounters[listId]);
 }, { concurrency: 5 });