@fraym/streams 0.2.1 → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Becklyn Studios
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,3 +1,3 @@
1
- import { ServiceClient } from "@fraym/streams-proto";
1
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
2
2
  import { HandlerFunc } from "./event";
3
3
  export declare const getAllEvents: (includedTopics: string[], excludedTopics: string[], handler: HandlerFunc, serviceClient: ServiceClient) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
2
+ import { HandlerFunc } from "./event";
3
+ export declare const getAllEventsFiltered: (includedTopics: string[], includedEventTypes: string[], handler: HandlerFunc, serviceClient: ServiceClient) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllEventsFiltered = void 0;
4
+ const event_1 = require("./event");
5
+ const getAllEventsFiltered = async (includedTopics, includedEventTypes, handler, serviceClient) => {
6
+ const stream = serviceClient.getFilteredEventsFromStart({
7
+ includedTopics,
8
+ includedEventTypes,
9
+ });
10
+ return new Promise((resolve, reject) => {
11
+ stream.on("data", (data) => {
12
+ const event = (0, event_1.getSubscriptionEvent)(data);
13
+ if (event) {
14
+ handler(event);
15
+ }
16
+ });
17
+ stream.on("end", () => {
18
+ resolve();
19
+ });
20
+ stream.on("error", e => {
21
+ reject(e);
22
+ });
23
+ });
24
+ };
25
+ exports.getAllEventsFiltered = getAllEventsFiltered;
@@ -1,13 +1,18 @@
1
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
1
2
  import { ClientConfig } from "./config";
2
3
  import { HandlerFunc, PublishEvent, SubscriptionEvent } from "./event";
3
4
  export interface Client {
4
5
  getAllEvents: (handler: HandlerFunc, includedTopics?: string[], excludedTopics?: string[]) => Promise<void>;
6
+ getAllEventsFiltered: (handler: HandlerFunc, includedTopics: string[], includedEventTypes: string[]) => Promise<void>;
7
+ getEvent: (tenantId: string, topic: string, eventId: string) => Promise<SubscriptionEvent>;
5
8
  getStream: (tenantId: string, stream: string) => Promise<SubscriptionEvent[]>;
6
9
  useEventHandler: (type: string, handler: HandlerFunc) => void;
7
10
  useEventHandlerForAllEventTypes: (handler: HandlerFunc) => void;
8
11
  subscribe: (includedTopics?: string[], excludedTopics?: string[]) => Promise<void>;
9
12
  publish: (topic: string, events: PublishEvent[]) => Promise<void>;
10
13
  invalidateGdprData: (tenantId: string, topic: string, gdprId: string) => Promise<void>;
14
+ introduceGdprOnField: (defaultValue: string, topic: string, eventType: string, fieldName: string, serviceClient: ServiceClient) => Promise<void>;
15
+ introduceGdprOnEventField: (tenantId: string, defaultValue: string, topic: string, eventId: string, fieldName: string, serviceClient: ServiceClient) => Promise<void>;
11
16
  createSnapshot: (topic: string, toTime: Date) => Promise<void>;
12
17
  close: () => void;
13
18
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.newClient = void 0;
4
- const streams_proto_1 = require("@fraym/streams-proto");
4
+ const clientchannel_1 = require("@fraym/proto/freym/streams/clientchannel");
5
5
  const grpc_js_1 = require("@grpc/grpc-js");
6
6
  const allEvents_1 = require("./allEvents");
7
7
  const config_1 = require("./config");
@@ -13,9 +13,12 @@ const publish_1 = require("./publish");
13
13
  const snapshot_1 = require("./snapshot");
14
14
  const stream_1 = require("./stream");
15
15
  const subscribe_1 = require("./subscribe");
16
+ const getEvent_1 = require("./getEvent");
17
+ const introduceGdpr_1 = require("./introduceGdpr");
18
+ const allEventsFiltered_1 = require("./allEventsFiltered");
16
19
  const newClient = async (config) => {
17
20
  config = (0, config_1.useConfigDefaults)(config);
18
- const serviceClient = new streams_proto_1.ServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
21
+ const serviceClient = new clientchannel_1.ServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
19
22
  "grpc.keepalive_time_ms": config.keepaliveInterval,
20
23
  "grpc.keepalive_timeout_ms": config.keepaliveTimeout,
21
24
  "grpc.keepalive_permit_without_calls": 1,
@@ -27,6 +30,12 @@ const newClient = async (config) => {
27
30
  getAllEvents: async (handler, includedTopics = [], excludedTopics = []) => {
28
31
  await (0, allEvents_1.getAllEvents)(includedTopics, excludedTopics, handler, serviceClient);
29
32
  },
33
+ getAllEventsFiltered: async (handler, includedTopics, includedEventTypes) => {
34
+ await (0, allEventsFiltered_1.getAllEventsFiltered)(includedTopics, includedEventTypes, handler, serviceClient);
35
+ },
36
+ getEvent: async (tenantId, topic, eventId) => {
37
+ return await (0, getEvent_1.getEvent)(tenantId, topic, eventId, serviceClient);
38
+ },
30
39
  getStream: async (tenantId, stream) => {
31
40
  return await (0, stream_1.getStream)(tenantId, stream, serviceClient);
32
41
  },
@@ -45,6 +54,12 @@ const newClient = async (config) => {
45
54
  publish: async (topic, events) => {
46
55
  return (0, publish_1.sendPublish)(topic, events, serviceClient);
47
56
  },
57
+ introduceGdprOnField: async (defaultValue, topic, eventType, fieldName) => {
58
+ return await (0, introduceGdpr_1.introduceGdprOnField)(defaultValue, topic, eventType, fieldName, serviceClient);
59
+ },
60
+ introduceGdprOnEventField: async (tenantId, defaultValue, topic, eventId, fieldName) => {
61
+ return (0, introduceGdpr_1.introduceGdprOnEventField)(tenantId, defaultValue, topic, eventId, fieldName, serviceClient);
62
+ },
48
63
  invalidateGdprData: async (tenantId, topic, gdprId) => {
49
64
  return await (0, invalidateGdpr_1.sendInvalidateGdpr)(tenantId, topic, gdprId, serviceClient);
50
65
  },
@@ -1,4 +1,4 @@
1
- import { PublishEventEnvelope } from "@fraym/streams-proto";
1
+ import { PublishEventEnvelope } from "@fraym/proto/freym/streams/clientchannel";
2
2
  export interface SubscriptionEvent extends BaseEvent {
3
3
  topic: string;
4
4
  raisedAt: Date;
@@ -18,8 +18,10 @@ export interface BaseEvent {
18
18
  }
19
19
  export type EventData = any | GdprEventData;
20
20
  export interface GdprEventData {
21
+ id?: string;
21
22
  value: any;
22
23
  gdprDefault: any;
24
+ isInvalidated: boolean;
23
25
  }
24
26
  export declare const isGdprEventData: (value: EventData) => value is GdprEventData;
25
27
  export type HandlerFunc = (event: SubscriptionEvent) => Promise<void>;
@@ -24,6 +24,7 @@ const getSubscriptionEvent = (eventEnvelope) => {
24
24
  gdprDefault: data.metadata.gdpr.default
25
25
  ? JSON.parse(data.metadata.gdpr.default)
26
26
  : "",
27
+ isInvalidated: data.metadata.gdpr.invalidated,
27
28
  };
28
29
  }
29
30
  else {
@@ -36,7 +37,7 @@ const getSubscriptionEvent = (eventEnvelope) => {
36
37
  topic: eventEnvelope.topic,
37
38
  tenantId: eventEnvelope.tenantId,
38
39
  payload,
39
- raisedAt: new Date(parseInt(event.raisedAt.slice(0, -6))),
40
+ raisedAt: new Date(parseInt(event.raisedAt.toString().slice(0, -6))),
40
41
  stream: event.stream || undefined,
41
42
  type: event.type || undefined,
42
43
  causationId: event.causationId || undefined,
@@ -0,0 +1,3 @@
1
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
2
+ import { SubscriptionEvent } from "./event";
3
+ export declare const getEvent: (tenantId: string, topic: string, eventId: string, serviceClient: ServiceClient) => Promise<SubscriptionEvent>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEvent = void 0;
4
+ const event_1 = require("./event");
5
+ const getEvent = async (tenantId, topic, eventId, serviceClient) => {
6
+ return new Promise((resolve, reject) => {
7
+ serviceClient.getEvent({
8
+ tenantId,
9
+ topic,
10
+ eventId,
11
+ }, (error, response) => {
12
+ if (error) {
13
+ reject(error.message);
14
+ return;
15
+ }
16
+ const event = (0, event_1.getSubscriptionEvent)(response);
17
+ if (event) {
18
+ resolve(event);
19
+ }
20
+ reject("unable to resolve event from event data");
21
+ });
22
+ });
23
+ };
24
+ exports.getEvent = getEvent;
@@ -1,5 +1,5 @@
1
1
  import { ClientConfig } from "./config";
2
2
  import { ClientDuplexStream } from "@grpc/grpc-js";
3
- import { SubscribeRequest, ServiceClient, SubscribeResponse } from "@fraym/streams-proto";
3
+ import { SubscribeRequest, ServiceClient, SubscribeResponse } from "@fraym/proto/freym/streams/clientchannel";
4
4
  export type Stream = ClientDuplexStream<SubscribeRequest, SubscribeResponse>;
5
5
  export declare const initStream: (config: ClientConfig, serviceClient: ServiceClient) => Promise<Stream>;
@@ -0,0 +1,3 @@
1
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
2
+ export declare const introduceGdprOnField: (defaultValue: string, topic: string, eventType: string, fieldName: string, serviceClient: ServiceClient) => Promise<void>;
3
+ export declare const introduceGdprOnEventField: (tenantId: string, defaultValue: string, topic: string, eventId: string, fieldName: string, serviceClient: ServiceClient) => Promise<void>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.introduceGdprOnEventField = exports.introduceGdprOnField = void 0;
4
+ const introduceGdprOnField = async (defaultValue, topic, eventType, fieldName, serviceClient) => {
5
+ return new Promise((resolve, reject) => {
6
+ serviceClient.introduceGdprOnField({
7
+ defaultValue,
8
+ topic,
9
+ eventType,
10
+ fieldName,
11
+ }, error => {
12
+ if (error) {
13
+ reject(error.message);
14
+ return;
15
+ }
16
+ resolve();
17
+ });
18
+ });
19
+ };
20
+ exports.introduceGdprOnField = introduceGdprOnField;
21
+ const introduceGdprOnEventField = async (tenantId, defaultValue, topic, eventId, fieldName, serviceClient) => {
22
+ return new Promise((resolve, reject) => {
23
+ serviceClient.introduceGdprOnEventField({
24
+ tenant: tenantId,
25
+ defaultValue,
26
+ topic,
27
+ eventId,
28
+ fieldName,
29
+ }, error => {
30
+ if (error) {
31
+ reject(error.message);
32
+ return;
33
+ }
34
+ resolve();
35
+ });
36
+ });
37
+ };
38
+ exports.introduceGdprOnEventField = introduceGdprOnEventField;
@@ -1,2 +1,2 @@
1
- import { ServiceClient } from "@fraym/streams-proto";
1
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
2
2
  export declare const sendInvalidateGdpr: (tenantId: string, topic: string, gdprId: string, serviceClient: ServiceClient) => Promise<void>;
@@ -1,3 +1,3 @@
1
1
  import { PublishEvent } from "./event";
2
- import { ServiceClient } from "@fraym/streams-proto";
2
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
3
3
  export declare const sendPublish: (topic: string, events: PublishEvent[], serviceClient: ServiceClient) => Promise<void>;
@@ -18,7 +18,7 @@ const sendPublish = async (topic, events, serviceClient) => {
18
18
  };
19
19
  exports.sendPublish = sendPublish;
20
20
  const getEventEnvelopeFromPublishedEvent = (event) => {
21
- var _a, _b, _c, _d, _e, _f;
21
+ var _a, _b, _c, _d, _e, _f, _g;
22
22
  const payload = {};
23
23
  for (const key in event.payload) {
24
24
  const currentData = event.payload[key];
@@ -29,7 +29,8 @@ const getEventEnvelopeFromPublishedEvent = (event) => {
29
29
  $case: "gdpr",
30
30
  gdpr: {
31
31
  default: JSON.stringify(currentData.gdprDefault),
32
- id: "",
32
+ id: (_a = currentData.id) !== null && _a !== void 0 ? _a : "",
33
+ invalidated: false,
33
34
  },
34
35
  },
35
36
  }
@@ -38,17 +39,17 @@ const getEventEnvelopeFromPublishedEvent = (event) => {
38
39
  };
39
40
  }
40
41
  return {
41
- broadcast: (_a = event.broadcast) !== null && _a !== void 0 ? _a : false,
42
+ broadcast: (_b = event.broadcast) !== null && _b !== void 0 ? _b : false,
42
43
  tenantId: event.tenantId,
43
44
  event: {
44
45
  id: event.id,
45
- type: (_b = event.type) !== null && _b !== void 0 ? _b : "",
46
- reason: (_c = event.reason) !== null && _c !== void 0 ? _c : "",
47
- stream: (_d = event.stream) !== null && _d !== void 0 ? _d : "",
48
- correlationId: (_e = event.correlationId) !== null && _e !== void 0 ? _e : "",
49
- causationId: (_f = event.causationId) !== null && _f !== void 0 ? _f : "",
46
+ type: (_c = event.type) !== null && _c !== void 0 ? _c : "",
47
+ reason: (_d = event.reason) !== null && _d !== void 0 ? _d : "",
48
+ stream: (_e = event.stream) !== null && _e !== void 0 ? _e : "",
49
+ correlationId: (_f = event.correlationId) !== null && _f !== void 0 ? _f : "",
50
+ causationId: (_g = event.causationId) !== null && _g !== void 0 ? _g : "",
50
51
  payload,
51
- raisedAt: "0",
52
+ raisedAt: 0,
52
53
  },
53
54
  };
54
55
  };
@@ -1,2 +1,2 @@
1
- import { ServiceClient } from "@fraym/streams-proto";
1
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
2
2
  export declare const sendSnapshot: (topic: string, toTime: Date, serviceClient: ServiceClient) => Promise<void>;
@@ -1,3 +1,3 @@
1
1
  import { SubscriptionEvent } from "./event";
2
- import { ServiceClient } from "@fraym/streams-proto";
2
+ import { ServiceClient } from "@fraym/proto/freym/streams/clientchannel";
3
3
  export declare const getStream: (tenantId: string, stream: string, serviceClient: ServiceClient) => Promise<SubscriptionEvent[]>;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./client/client";
2
- export { HandlerFunc, PublishEvent, SubscriptionEvent } from "./client/event";
2
+ export { HandlerFunc, PublishEvent, SubscriptionEvent, BaseEvent, EventData, GdprEventData, } from "./client/event";
3
3
  export { ClientConfig } from "./client/config";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fraym/streams",
3
- "version": "0.2.1",
4
- "license": "UNLICENSED",
3
+ "version": "0.4.0",
4
+ "license": "MIT",
5
5
  "homepage": "https://github.com/fraym/streams-nodejs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -15,25 +15,27 @@
15
15
  "build": "npm run clean && tsc",
16
16
  "clean": "rm -rf dist",
17
17
  "prepublishOnly": "npm test && npm run lint && npm run build",
18
- "preversion": "npm run lint",
19
- "protobuf": "./protobuf.sh"
18
+ "preversion": "npm run lint"
20
19
  },
21
20
  "files": [
22
21
  "dist/**/*"
23
22
  ],
23
+ "engines": {
24
+ "node": ">=16"
25
+ },
24
26
  "main": "dist/index.js",
25
27
  "types": "dist/index.d.ts",
26
28
  "dependencies": {
27
- "@fraym/streams-proto": "^7.0.0-alpha.1",
28
- "@grpc/grpc-js": "^1.8.7",
29
+ "@fraym/proto": "^0.3.0",
30
+ "@grpc/grpc-js": "^1.8.17",
29
31
  "ts-node": "^10.9.1",
30
32
  "uuid": "^9.0.0"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@becklyn/prettier": "^1.0.2",
34
36
  "@types/uuid": "^8.3.4",
35
- "prettier": "^2.7.1",
36
- "typescript": "^4.8.4"
37
+ "prettier": "^2.8.8",
38
+ "typescript": "^4.9.5"
37
39
  },
38
40
  "prettier": "@becklyn/prettier"
39
41
  }