@fraym/streams 0.2.1 → 0.3.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,13 +1,17 @@
1
+ import { ServiceClient } from "@fraym/streams-proto";
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
+ getEvent: (tenantId: string, topic: string, eventId: string) => Promise<SubscriptionEvent>;
5
7
  getStream: (tenantId: string, stream: string) => Promise<SubscriptionEvent[]>;
6
8
  useEventHandler: (type: string, handler: HandlerFunc) => void;
7
9
  useEventHandlerForAllEventTypes: (handler: HandlerFunc) => void;
8
10
  subscribe: (includedTopics?: string[], excludedTopics?: string[]) => Promise<void>;
9
11
  publish: (topic: string, events: PublishEvent[]) => Promise<void>;
10
12
  invalidateGdprData: (tenantId: string, topic: string, gdprId: string) => Promise<void>;
13
+ introduceGdprOnField: (defaultValue: string, topic: string, eventType: string, fieldName: string, serviceClient: ServiceClient) => Promise<void>;
14
+ introduceGdprOnEventField: (tenantId: string, defaultValue: string, topic: string, eventId: string, fieldName: string, serviceClient: ServiceClient) => Promise<void>;
11
15
  createSnapshot: (topic: string, toTime: Date) => Promise<void>;
12
16
  close: () => void;
13
17
  }
@@ -13,6 +13,8 @@ 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");
16
18
  const newClient = async (config) => {
17
19
  config = (0, config_1.useConfigDefaults)(config);
18
20
  const serviceClient = new streams_proto_1.ServiceClient(config.serverAddress, grpc_js_1.credentials.createInsecure(), {
@@ -27,6 +29,9 @@ const newClient = async (config) => {
27
29
  getAllEvents: async (handler, includedTopics = [], excludedTopics = []) => {
28
30
  await (0, allEvents_1.getAllEvents)(includedTopics, excludedTopics, handler, serviceClient);
29
31
  },
32
+ getEvent: async (tenantId, topic, eventId) => {
33
+ return await (0, getEvent_1.getEvent)(tenantId, topic, eventId, serviceClient);
34
+ },
30
35
  getStream: async (tenantId, stream) => {
31
36
  return await (0, stream_1.getStream)(tenantId, stream, serviceClient);
32
37
  },
@@ -45,6 +50,12 @@ const newClient = async (config) => {
45
50
  publish: async (topic, events) => {
46
51
  return (0, publish_1.sendPublish)(topic, events, serviceClient);
47
52
  },
53
+ introduceGdprOnField: async (defaultValue, topic, eventType, fieldName) => {
54
+ return await (0, introduceGdpr_1.introduceGdprOnField)(defaultValue, topic, eventType, fieldName, serviceClient);
55
+ },
56
+ introduceGdprOnEventField: async (tenantId, defaultValue, topic, eventId, fieldName) => {
57
+ return (0, introduceGdpr_1.introduceGdprOnEventField)(tenantId, defaultValue, topic, eventId, fieldName, serviceClient);
58
+ },
48
59
  invalidateGdprData: async (tenantId, topic, gdprId) => {
49
60
  return await (0, invalidateGdpr_1.sendInvalidateGdpr)(tenantId, topic, gdprId, serviceClient);
50
61
  },
@@ -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 {
@@ -0,0 +1,3 @@
1
+ import { ServiceClient } from "@fraym/streams-proto";
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;
@@ -0,0 +1,3 @@
1
+ import { ServiceClient } from "@fraym/streams-proto";
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;
@@ -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,15 +39,15 @@ 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
52
  raisedAt: "0",
52
53
  },
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.3.0",
4
+ "license": "MIT",
5
5
  "homepage": "https://github.com/fraym/streams-nodejs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,16 +24,16 @@
24
24
  "main": "dist/index.js",
25
25
  "types": "dist/index.d.ts",
26
26
  "dependencies": {
27
- "@fraym/streams-proto": "^7.0.0-alpha.1",
28
- "@grpc/grpc-js": "^1.8.7",
27
+ "@fraym/streams-proto": "^7.1.2",
28
+ "@grpc/grpc-js": "^1.8.17",
29
29
  "ts-node": "^10.9.1",
30
30
  "uuid": "^9.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@becklyn/prettier": "^1.0.2",
34
34
  "@types/uuid": "^8.3.4",
35
- "prettier": "^2.7.1",
36
- "typescript": "^4.8.4"
35
+ "prettier": "^2.8.8",
36
+ "typescript": "^4.9.5"
37
37
  },
38
38
  "prettier": "@becklyn/prettier"
39
39
  }