stentor-service-event 1.61.16 → 1.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/FirehoseStream.d.ts +1 -2
- package/lib/FirehoseStream.js +61 -25
- package/lib/FirehoseStream.js.map +1 -1
- package/lib/KinesisStream.d.ts +1 -2
- package/lib/KinesisStream.js +48 -12
- package/lib/KinesisStream.js.map +1 -1
- package/lib/SNSStream.d.ts +1 -2
- package/lib/SNSStream.js +47 -16
- package/lib/SNSStream.js.map +1 -1
- package/package.json +13 -7
package/lib/FirehoseStream.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
2
2
|
import { Event } from "stentor-models";
|
|
3
|
-
import { Firehose } from "aws-sdk";
|
|
4
3
|
import { AbstractEventStream } from "./AbstractEventStream";
|
|
5
4
|
export declare class FirehoseStream extends AbstractEventStream {
|
|
6
5
|
private readonly deliveryStreamName;
|
|
7
6
|
private readonly firehose;
|
|
8
|
-
constructor(deliveryStreamName: string,
|
|
7
|
+
constructor(deliveryStreamName: string, injectedFirehose?: any);
|
|
9
8
|
flushEvents(events: Event<any>[]): Promise<void>;
|
|
10
9
|
}
|
package/lib/FirehoseStream.js
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.FirehoseStream = void 0;
|
|
4
|
-
const aws_sdk_1 = require("aws-sdk");
|
|
5
13
|
const AbstractEventStream_1 = require("./AbstractEventStream");
|
|
6
|
-
|
|
14
|
+
// Try AWS SDK v3 first, fallback to v2
|
|
15
|
+
let FirehoseClient;
|
|
16
|
+
let PutRecordBatchCommand;
|
|
17
|
+
let Firehose;
|
|
18
|
+
let globalFirehose;
|
|
19
|
+
try {
|
|
20
|
+
// AWS SDK v3
|
|
21
|
+
const firehoseV3 = require("@aws-sdk/client-firehose");
|
|
22
|
+
FirehoseClient = firehoseV3.FirehoseClient;
|
|
23
|
+
PutRecordBatchCommand = firehoseV3.PutRecordBatchCommand;
|
|
24
|
+
globalFirehose = new FirehoseClient({});
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
// AWS SDK v2 fallback
|
|
28
|
+
const awsSdk = require("aws-sdk");
|
|
29
|
+
Firehose = awsSdk.Firehose;
|
|
30
|
+
globalFirehose = new Firehose({ apiVersion: "2015-08-04" });
|
|
31
|
+
}
|
|
7
32
|
function generateRecords(events = []) {
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}));
|
|
14
|
-
});
|
|
33
|
+
return Promise.resolve(events.map((event) => {
|
|
34
|
+
return {
|
|
35
|
+
Data: JSON.stringify(event)
|
|
36
|
+
};
|
|
37
|
+
}));
|
|
15
38
|
}
|
|
16
39
|
function validateRecords(events = []) {
|
|
17
40
|
return new Promise((resolve, reject) => {
|
|
@@ -34,26 +57,39 @@ function validateRecords(events = []) {
|
|
|
34
57
|
});
|
|
35
58
|
}
|
|
36
59
|
class FirehoseStream extends AbstractEventStream_1.AbstractEventStream {
|
|
37
|
-
constructor(deliveryStreamName,
|
|
60
|
+
constructor(deliveryStreamName, injectedFirehose = globalFirehose) {
|
|
38
61
|
super();
|
|
39
62
|
this.deliveryStreamName = deliveryStreamName;
|
|
40
|
-
this.firehose =
|
|
63
|
+
this.firehose = injectedFirehose;
|
|
41
64
|
}
|
|
42
65
|
flushEvents(events) {
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
const validatedEvents = yield validateRecords(events);
|
|
69
|
+
const records = yield generateRecords(validatedEvents);
|
|
70
|
+
if (PutRecordBatchCommand) {
|
|
71
|
+
// AWS SDK v3
|
|
72
|
+
const command = new PutRecordBatchCommand({
|
|
73
|
+
DeliveryStreamName: this.deliveryStreamName,
|
|
74
|
+
Records: records
|
|
75
|
+
});
|
|
76
|
+
yield this.firehose.send(command);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// AWS SDK v2
|
|
80
|
+
yield this.firehose
|
|
81
|
+
.putRecordBatch({
|
|
82
|
+
DeliveryStreamName: this.deliveryStreamName,
|
|
83
|
+
Records: records
|
|
84
|
+
})
|
|
85
|
+
.promise();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
console.error("Error generating records.", e);
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
57
93
|
}
|
|
58
94
|
}
|
|
59
95
|
exports.FirehoseStream = FirehoseStream;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirehoseStream.js","sourceRoot":"","sources":["../src/FirehoseStream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FirehoseStream.js","sourceRoot":"","sources":["../src/FirehoseStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,+DAA4D;AAE5D,uCAAuC;AACvC,IAA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AE,CAAC,CAAC,CAAC;gBAC9C,MAAM,CAAC,CAAC;YACZ,CAAC;QACL,CAAC;KAAA;CACJ;AApCD,wCAoCC"}
|
package/lib/KinesisStream.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
2
2
|
import { Event } from "stentor-models";
|
|
3
|
-
import { Kinesis } from "aws-sdk";
|
|
4
3
|
import { AbstractEventStream } from "./AbstractEventStream";
|
|
5
4
|
export type PartitionKeyGenerator = () => string;
|
|
6
5
|
export declare function staticPartitionGenerator(partition: string): PartitionKeyGenerator;
|
|
@@ -8,7 +7,7 @@ export declare function randomPartitionKeyGenerator(stringSize?: number): Partit
|
|
|
8
7
|
export interface KinesisStreamProps {
|
|
9
8
|
streamName: string;
|
|
10
9
|
partitionKey?: string | PartitionKeyGenerator;
|
|
11
|
-
kinesis?:
|
|
10
|
+
kinesis?: any;
|
|
12
11
|
}
|
|
13
12
|
export declare class KinesisStream extends AbstractEventStream {
|
|
14
13
|
private readonly streamName;
|
package/lib/KinesisStream.js
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.KinesisStream = void 0;
|
|
4
13
|
exports.staticPartitionGenerator = staticPartitionGenerator;
|
|
5
14
|
exports.randomPartitionKeyGenerator = randomPartitionKeyGenerator;
|
|
6
15
|
const stentor_utils_1 = require("stentor-utils");
|
|
7
|
-
const aws_sdk_1 = require("aws-sdk");
|
|
8
16
|
const AbstractEventStream_1 = require("./AbstractEventStream");
|
|
9
|
-
|
|
17
|
+
// Try AWS SDK v3 first, fallback to v2
|
|
18
|
+
let KinesisClient;
|
|
19
|
+
let PutRecordsCommand;
|
|
20
|
+
let Kinesis;
|
|
21
|
+
let globalKinesis;
|
|
22
|
+
try {
|
|
23
|
+
// AWS SDK v3
|
|
24
|
+
const kinesisV3 = require("@aws-sdk/client-kinesis");
|
|
25
|
+
KinesisClient = kinesisV3.KinesisClient;
|
|
26
|
+
PutRecordsCommand = kinesisV3.PutRecordsCommand;
|
|
27
|
+
globalKinesis = new KinesisClient({});
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
// AWS SDK v2 fallback
|
|
31
|
+
const awsSdk = require("aws-sdk");
|
|
32
|
+
Kinesis = awsSdk.Kinesis;
|
|
33
|
+
globalKinesis = new Kinesis({ apiVersion: "2013-12-02" });
|
|
34
|
+
}
|
|
10
35
|
function staticPartitionGenerator(partition) {
|
|
11
36
|
return () => partition;
|
|
12
37
|
}
|
|
@@ -37,16 +62,27 @@ class KinesisStream extends AbstractEventStream_1.AbstractEventStream {
|
|
|
37
62
|
}
|
|
38
63
|
}
|
|
39
64
|
flushEvents(events) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
console.time("Kinesis Flush");
|
|
67
|
+
const StreamName = this.streamName;
|
|
68
|
+
try {
|
|
69
|
+
const records = generateRecords(events, this.partitionGenerator);
|
|
70
|
+
if (PutRecordsCommand) {
|
|
71
|
+
// AWS SDK v3
|
|
72
|
+
const command = new PutRecordsCommand({ StreamName, Records: records });
|
|
73
|
+
yield this.kinesis.send(command);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// AWS SDK v2
|
|
77
|
+
yield this.kinesis.putRecords({ StreamName, Records: records }).promise();
|
|
78
|
+
}
|
|
79
|
+
console.timeEnd("Kinesis Flush");
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
console.error("Error generating kinesis records.", e);
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
50
86
|
}
|
|
51
87
|
}
|
|
52
88
|
exports.KinesisStream = KinesisStream;
|
package/lib/KinesisStream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KinesisStream.js","sourceRoot":"","sources":["../src/KinesisStream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"KinesisStream.js","sourceRoot":"","sources":["../src/KinesisStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AA2BA,4DAEC;AAED,kEAEC;AA9BD,iDAA6C;AAC7C,+DAA4D;AAE5D,uCAAuC;AACvC,IAAI,aAAkB,CAAC;AACvB,IAAI,iBAAsB,CAAC;AAC3B,IAAI,OAAY,CAAC;AACjB,IAAI,aAAkB,CAAC;AAEvB,IAAI,CAAC;IACD,aAAa;IACb,MAAM,SAAS,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACrD,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;IACxC,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,CAAC;IAChD,aAAa,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC;AAAC,WAAM,CAAC;IACL,sBAAsB;IACtB,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAClC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACzB,aAAa,GAAG,IAAI,OAAO,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,CA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AI,CAAC;gBACD,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBAEjE,IAAI,iBAAiB,EAAE,CAAC;oBACpB,aAAa;oBACb,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;oBACxE,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACrC,CAAC;qBAAM,CAAC;oBACJ,aAAa;oBACb,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;gBAC9E,CAAC;gBAED,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,CAAC,CAAC,CAAC;gBACtD,MAAM,CAAC,CAAC;YACZ,CAAC;QACL,CAAC;KAAA;CACJ;AA3CD,sCA2CC"}
|
package/lib/SNSStream.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
2
2
|
import { Event } from "stentor-models";
|
|
3
|
-
import { SNS } from "aws-sdk";
|
|
4
3
|
import { AbstractEventStream } from "./AbstractEventStream";
|
|
5
4
|
export declare class SNSStream extends AbstractEventStream {
|
|
6
5
|
private readonly topicArn;
|
|
7
6
|
private readonly sns;
|
|
8
|
-
constructor(topicArn: string, sns?:
|
|
7
|
+
constructor(topicArn: string, sns?: any);
|
|
9
8
|
flushEvents(events: Event<any>[]): Promise<void>;
|
|
10
9
|
}
|
package/lib/SNSStream.js
CHANGED
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.SNSStream = void 0;
|
|
4
|
-
const aws_sdk_1 = require("aws-sdk");
|
|
5
13
|
const AbstractEventStream_1 = require("./AbstractEventStream");
|
|
6
|
-
|
|
14
|
+
// Try AWS SDK v3 first, fallback to v2
|
|
15
|
+
let SNSClient;
|
|
16
|
+
let PublishCommand;
|
|
17
|
+
let SNS;
|
|
18
|
+
let globalSNS;
|
|
19
|
+
// Default region can be overridden by AWS_DEFAULT_REGION or AWS_REGION environment variables
|
|
20
|
+
const defaultRegion = process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION || "us-east-1";
|
|
21
|
+
try {
|
|
22
|
+
// AWS SDK v3
|
|
23
|
+
const snsV3 = require("@aws-sdk/client-sns");
|
|
24
|
+
SNSClient = snsV3.SNSClient;
|
|
25
|
+
PublishCommand = snsV3.PublishCommand;
|
|
26
|
+
globalSNS = new SNSClient({ region: defaultRegion });
|
|
27
|
+
}
|
|
28
|
+
catch (_a) {
|
|
29
|
+
// AWS SDK v2 fallback
|
|
30
|
+
const awsSdk = require("aws-sdk");
|
|
31
|
+
SNS = awsSdk.SNS;
|
|
32
|
+
globalSNS = new SNS({ apiVersion: "2010-03-31", region: defaultRegion });
|
|
33
|
+
}
|
|
7
34
|
function eventsToString(events) {
|
|
8
|
-
return
|
|
9
|
-
resolve(JSON.stringify(events));
|
|
10
|
-
});
|
|
35
|
+
return Promise.resolve(JSON.stringify(events));
|
|
11
36
|
}
|
|
12
37
|
class SNSStream extends AbstractEventStream_1.AbstractEventStream {
|
|
13
38
|
constructor(topicArn, sns = globalSNS) {
|
|
@@ -16,17 +41,23 @@ class SNSStream extends AbstractEventStream_1.AbstractEventStream {
|
|
|
16
41
|
this.sns = sns;
|
|
17
42
|
}
|
|
18
43
|
flushEvents(events) {
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
try {
|
|
46
|
+
const Message = yield eventsToString(events);
|
|
47
|
+
if (PublishCommand) {
|
|
48
|
+
// AWS SDK v3
|
|
49
|
+
const command = new PublishCommand({ TopicArn: this.topicArn, Message });
|
|
50
|
+
yield this.sns.send(command);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// AWS SDK v2
|
|
54
|
+
yield this.sns.publish({ TopicArn: this.topicArn, Message }).promise();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error("Error converting events to a string.", e);
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
30
61
|
});
|
|
31
62
|
}
|
|
32
63
|
}
|
package/lib/SNSStream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SNSStream.js","sourceRoot":"","sources":["../src/SNSStream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SNSStream.js","sourceRoot":"","sources":["../src/SNSStream.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,+DAA4D;AAE5D,uCAAuC;AACvC,IAAI,SAAc,CAAC;AACnB,IAAI,cAAmB,CAAC;AACxB,IAAI,GAAQ,CAAC;AACb,IAAI,SAAc,CAAC;AAEnB,6FAA6F;AAC7F,MAA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AAC,OAAO,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACJ,aAAa;oBACb,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;gBAC3E,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,CAAC,CAAC,CAAC;gBACzD,MAAM,CAAC,CAAC;YACZ,CAAC;QACL,CAAC;KAAA;CACJ;AA3BD,8BA2BC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.64.0",
|
|
8
8
|
"description": "Event service for 📣 stentor",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -12,9 +12,12 @@
|
|
|
12
12
|
"lib"
|
|
13
13
|
],
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": "^12 || ^14 || ^16 || ^18 || ^20
|
|
15
|
+
"node": "^12 || ^14 || ^16 || ^18 || ^20 || ^22"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
+
"@aws-sdk/client-firehose": "3.888.0",
|
|
19
|
+
"@aws-sdk/client-kinesis": "3.888.0",
|
|
20
|
+
"@aws-sdk/client-sns": "3.888.0",
|
|
18
21
|
"@types/chai": "5.2.2",
|
|
19
22
|
"@types/mocha": "10.0.10",
|
|
20
23
|
"@types/sinon": "17.0.4",
|
|
@@ -25,17 +28,20 @@
|
|
|
25
28
|
"mocha": "11.7.2",
|
|
26
29
|
"sinon": "20.0.0",
|
|
27
30
|
"sinon-chai": "3.7.0",
|
|
28
|
-
"stentor-models": "1.
|
|
31
|
+
"stentor-models": "1.64.0",
|
|
29
32
|
"ts-node": "10.9.2",
|
|
30
33
|
"typescript": "5.9.2"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"stacktrace-parser": "0.1.11",
|
|
34
|
-
"stentor-guards": "1.
|
|
35
|
-
"stentor-logger": "1.
|
|
36
|
-
"stentor-utils": "1.
|
|
37
|
+
"stentor-guards": "1.64.0",
|
|
38
|
+
"stentor-logger": "1.64.0",
|
|
39
|
+
"stentor-utils": "1.64.0"
|
|
37
40
|
},
|
|
38
41
|
"peerDependencies": {
|
|
42
|
+
"@aws-sdk/client-firehose": "3.x",
|
|
43
|
+
"@aws-sdk/client-kinesis": "3.x",
|
|
44
|
+
"@aws-sdk/client-sns": "3.x",
|
|
39
45
|
"aws-sdk": "2.x",
|
|
40
46
|
"stentor-models": "1.x"
|
|
41
47
|
},
|
|
@@ -44,5 +50,5 @@
|
|
|
44
50
|
"clean": "rm -rf ./lib/*",
|
|
45
51
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
46
52
|
},
|
|
47
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "8e0990d935538de2ebbf77b7782db134b23f5844"
|
|
48
54
|
}
|