@clipmx/lambda-utils
Advanced tools
Comparing version 0.2.0 to 0.3.1
@@ -52,3 +52,5 @@ import { DynamoDB } from 'aws-sdk/clients/all'; | ||
* | ||
* const records = await (new Dynamo()).getByPrimaryKey('merchant_token', '99ky334-hd4h566', 'merchant_referrals'); | ||
* const records = await (new Dynamo()).getByPrimaryKey( | ||
'email_address', 'wildburger@doublestack.com', 'clip_customers' | ||
); | ||
* ``` | ||
@@ -55,0 +57,0 @@ */ |
@@ -43,3 +43,5 @@ "use strict"; | ||
* | ||
* const records = await (new Dynamo()).getByPrimaryKey('merchant_token', '99ky334-hd4h566', 'merchant_referrals'); | ||
* const records = await (new Dynamo()).getByPrimaryKey( | ||
'email_address', 'wildburger@doublestack.com', 'clip_customers' | ||
); | ||
* ``` | ||
@@ -46,0 +48,0 @@ */ |
@@ -44,3 +44,3 @@ import { KinesisStreamEvent, KinesisStreamRecord } from 'aws-lambda'; | ||
* ```js | ||
* module.exports.handler = (event, context, callback) => { | ||
* module.exports.handler = async (event, context, callback) => { | ||
* await Kinesis.asyncForEachRecord(event, async (record, index) => { | ||
@@ -47,0 +47,0 @@ * // do something with each record |
@@ -74,3 +74,3 @@ "use strict"; | ||
* ```js | ||
* module.exports.handler = (event, context, callback) => { | ||
* module.exports.handler = async (event, context, callback) => { | ||
* await Kinesis.asyncForEachRecord(event, async (record, index) => { | ||
@@ -77,0 +77,0 @@ * // do something with each record |
@@ -1,2 +0,2 @@ | ||
import { KinesisStreamEvent, KinesisStreamRecord, KinesisStreamRecordPayload } from 'aws-lambda'; | ||
import { KinesisStreamEvent, KinesisStreamRecord, KinesisStreamRecordPayload, SNSEvent, SNSEventRecord, SNSMessage } from 'aws-lambda'; | ||
import { EnterpriseEvent } from '../../models'; | ||
@@ -23,2 +23,5 @@ /** | ||
static isEnterpriseEvent: (arg: any) => arg is EnterpriseEvent; | ||
static isSNSEvent: (arg: any) => arg is SNSEvent; | ||
static isSNSEventRecord: (arg: any) => arg is SNSEventRecord; | ||
static isSNSMessage: (arg: any) => arg is SNSMessage; | ||
} |
@@ -34,3 +34,24 @@ "use strict"; | ||
&& arg.hasOwnProperty('detail')); | ||
TypeGuards.isSNSEvent = (arg) => (TypeGuards.isObject(arg) | ||
&& arg.hasOwnProperty('Records') | ||
&& Array.isArray(arg.Records)); | ||
TypeGuards.isSNSEventRecord = (arg) => (TypeGuards.isObject(arg) | ||
&& arg.hasOwnProperty('EventVersion') | ||
&& arg.hasOwnProperty('EventSubscriptionArn') | ||
&& arg.hasOwnProperty('EventSource') | ||
&& arg.hasOwnProperty('Sns')); | ||
TypeGuards.isSNSMessage = (arg) => (TypeGuards.isObject(arg) | ||
&& arg.hasOwnProperty('SignatureVersion') | ||
&& arg.hasOwnProperty('Timestamp') | ||
&& arg.hasOwnProperty('Signature') | ||
&& arg.hasOwnProperty('SigningCertUrl') | ||
&& arg.hasOwnProperty('MessageId') | ||
&& arg.hasOwnProperty('Message') | ||
&& arg.hasOwnProperty('MessageAttributes') | ||
&& arg.hasOwnProperty('Type') | ||
&& arg.hasOwnProperty('UnsubscribeUrl') | ||
&& arg.hasOwnProperty('TopicArn') | ||
&& arg.hasOwnProperty('Subject') | ||
&& typeof arg.Message === 'string'); | ||
exports.default = TypeGuards; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { KinesisStreamRecord } from 'aws-lambda'; | ||
import { KinesisStreamRecord, SNSEventRecord } from 'aws-lambda'; | ||
import { EnterpriseEvent } from '..'; | ||
@@ -9,1 +9,4 @@ export interface KinesisStreamRecordCallback { | ||
} | ||
export interface SNSEventRecordCallback { | ||
(record: SNSEventRecord, index: number, array: SNSEventRecord[]): void; | ||
} |
{ | ||
"name": "@clipmx/lambda-utils", | ||
"version": "0.2.0", | ||
"version": "0.3.1", | ||
"description": "Common helpers for Node Lambdas", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -52,3 +52,3 @@ # Node Lambda Utils | ||
4. `npm version [major|minor|patch]` | ||
5. `npm publish --access public` | ||
6. Create a pull request for release branch | ||
5. Create a pull request for release branch | ||
6. `npm publish --access public` |
@@ -65,3 +65,5 @@ import { DynamoDB } from 'aws-sdk/clients/all'; | ||
* | ||
* const records = await (new Dynamo()).getByPrimaryKey('merchant_token', '99ky334-hd4h566', 'merchant_referrals'); | ||
* const records = await (new Dynamo()).getByPrimaryKey( | ||
'email_address', 'wildburger@doublestack.com', 'clip_customers' | ||
); | ||
* ``` | ||
@@ -68,0 +70,0 @@ */ |
@@ -83,3 +83,3 @@ import { KinesisStreamEvent, KinesisStreamRecord, KinesisStreamRecordPayload } from 'aws-lambda'; | ||
* ```js | ||
* module.exports.handler = (event, context, callback) => { | ||
* module.exports.handler = async (event, context, callback) => { | ||
* await Kinesis.asyncForEachRecord(event, async (record, index) => { | ||
@@ -86,0 +86,0 @@ * // do something with each record |
@@ -1,2 +0,9 @@ | ||
import { KinesisStreamEvent, KinesisStreamRecord, KinesisStreamRecordPayload } from 'aws-lambda'; | ||
import { | ||
KinesisStreamEvent, | ||
KinesisStreamRecord, | ||
KinesisStreamRecordPayload, | ||
SNSEvent, | ||
SNSEventRecord, | ||
SNSMessage, | ||
} from 'aws-lambda'; | ||
import { EnterpriseEvent } from '../../models'; | ||
@@ -54,2 +61,32 @@ | ||
) | ||
static isSNSEvent = (arg: any): arg is SNSEvent => ( | ||
TypeGuards.isObject(arg) | ||
&& arg.hasOwnProperty('Records') | ||
&& Array.isArray(arg.Records) | ||
) | ||
static isSNSEventRecord = (arg: any): arg is SNSEventRecord => ( | ||
TypeGuards.isObject(arg) | ||
&& arg.hasOwnProperty('EventVersion') | ||
&& arg.hasOwnProperty('EventSubscriptionArn') | ||
&& arg.hasOwnProperty('EventSource') | ||
&& arg.hasOwnProperty('Sns') | ||
) | ||
static isSNSMessage = (arg: any): arg is SNSMessage => ( | ||
TypeGuards.isObject(arg) | ||
&& arg.hasOwnProperty('SignatureVersion') | ||
&& arg.hasOwnProperty('Timestamp') | ||
&& arg.hasOwnProperty('Signature') | ||
&& arg.hasOwnProperty('SigningCertUrl') | ||
&& arg.hasOwnProperty('MessageId') | ||
&& arg.hasOwnProperty('Message') | ||
&& arg.hasOwnProperty('MessageAttributes') | ||
&& arg.hasOwnProperty('Type') | ||
&& arg.hasOwnProperty('UnsubscribeUrl') | ||
&& arg.hasOwnProperty('TopicArn') | ||
&& arg.hasOwnProperty('Subject') | ||
&& typeof arg.Message === 'string' | ||
) | ||
} |
@@ -1,2 +0,2 @@ | ||
import { KinesisStreamRecord } from 'aws-lambda'; | ||
import { KinesisStreamRecord, SNSEventRecord } from 'aws-lambda'; | ||
import { EnterpriseEvent } from '..'; | ||
@@ -11,1 +11,5 @@ | ||
} | ||
export interface SNSEventRecordCallback { | ||
(record: SNSEventRecord, index: number, array: SNSEventRecord[]): void; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
103732
53
2300