@fraym/streams 0.2.0 → 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.
package/README.md CHANGED
@@ -37,6 +37,9 @@ await client.publish("topic", [
37
37
  tenantId: "tenantId",
38
38
  payload: {
39
39
  key: "value",
40
+ object: {
41
+ key: "objectKeyValue"
42
+ },
40
43
  },
41
44
  // set `broadcast` to true if you want all subscribers of a group to process the event.
42
45
  // set to false (or remove) if you want this event to be handled only once by a group of subscribers.
@@ -135,38 +138,3 @@ You won't lose any data if you don't. Use it for your peace of mind.
135
138
  ```typescript
136
139
  client.close();
137
140
  ```
138
-
139
- ## Development
140
-
141
- You'll need the following apps for a smooth development experience:
142
-
143
- - minikube
144
- - lens
145
- - okteto
146
- - helm
147
-
148
- ### Running the dev environment
149
-
150
- - Start minikube if not already done:
151
-
152
- ```shell
153
- minikube start
154
- ```
155
-
156
- - add mongodb and minio to your lokal kubernetes
157
- - use Makefiles in `./.dev/*`
158
- - copy `.env.build` to `.env.build.local`
159
- - add your personal access token (needs read access for private fraym org repositories)
160
- - deploy the app to your cluster
161
-
162
- ```
163
- make init
164
- ```
165
-
166
- - start okteto
167
-
168
- ```
169
- make dev
170
- ```
171
-
172
- - connect your IDE to that okteto instance
@@ -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
  },
@@ -16,10 +16,13 @@ export interface BaseEvent {
16
16
  causationId?: string;
17
17
  reason?: string;
18
18
  }
19
- export type EventData = string | GdprEventData;
19
+ export type EventData = any | GdprEventData;
20
20
  export interface GdprEventData {
21
- value: string;
22
- gdprDefault: string;
21
+ id?: string;
22
+ value: any;
23
+ gdprDefault: any;
24
+ isInvalidated: boolean;
23
25
  }
26
+ export declare const isGdprEventData: (value: EventData) => value is GdprEventData;
24
27
  export type HandlerFunc = (event: SubscriptionEvent) => Promise<void>;
25
28
  export declare const getSubscriptionEvent: (eventEnvelope: PublishEventEnvelope) => SubscriptionEvent | null;
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSubscriptionEvent = void 0;
3
+ exports.getSubscriptionEvent = exports.isGdprEventData = void 0;
4
+ const isGdprEventData = (value) => {
5
+ return (value &&
6
+ typeof value === "object" &&
7
+ Object.keys(value).length == 2 &&
8
+ value.hasOwnProperty("value") &&
9
+ value.hasOwnProperty("gdprDefault"));
10
+ };
11
+ exports.isGdprEventData = isGdprEventData;
4
12
  const getSubscriptionEvent = (eventEnvelope) => {
5
- var _a;
6
13
  const event = eventEnvelope.event;
7
14
  if (!event) {
8
15
  return null;
@@ -13,12 +20,15 @@ const getSubscriptionEvent = (eventEnvelope) => {
13
20
  const data = event.payload[key];
14
21
  if (data.metadata && data.metadata.gdpr) {
15
22
  payload[key] = {
16
- value: data.value,
17
- gdprDefault: (_a = data.metadata.gdpr.default) !== null && _a !== void 0 ? _a : "",
23
+ value: JSON.parse(data.value),
24
+ gdprDefault: data.metadata.gdpr.default
25
+ ? JSON.parse(data.metadata.gdpr.default)
26
+ : "",
27
+ isInvalidated: data.metadata.gdpr.invalidated,
18
28
  };
19
29
  }
20
30
  else {
21
- payload[key] = data.value;
31
+ payload[key] = JSON.parse(data.value);
22
32
  }
23
33
  }
24
34
  }
@@ -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;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendPublish = void 0;
4
+ const event_1 = require("./event");
4
5
  const sendPublish = async (topic, events, serviceClient) => {
5
6
  return new Promise((resolve, reject) => {
6
7
  serviceClient.publish({
@@ -17,36 +18,36 @@ const sendPublish = async (topic, events, serviceClient) => {
17
18
  };
18
19
  exports.sendPublish = sendPublish;
19
20
  const getEventEnvelopeFromPublishedEvent = (event) => {
20
- var _a, _b, _c, _d, _e, _f;
21
+ var _a, _b, _c, _d, _e, _f, _g;
21
22
  const payload = {};
22
23
  for (const key in event.payload) {
23
24
  const currentData = event.payload[key];
24
- payload[key] =
25
- typeof currentData === "string"
26
- ? {
27
- value: currentData,
28
- }
29
- : {
30
- value: currentData.value,
31
- metadata: {
32
- $case: "gdpr",
33
- gdpr: {
34
- default: currentData.gdprDefault,
35
- id: "",
36
- },
25
+ payload[key] = (0, event_1.isGdprEventData)(currentData)
26
+ ? {
27
+ value: JSON.stringify(currentData.value),
28
+ metadata: {
29
+ $case: "gdpr",
30
+ gdpr: {
31
+ default: JSON.stringify(currentData.gdprDefault),
32
+ id: (_a = currentData.id) !== null && _a !== void 0 ? _a : "",
33
+ invalidated: false,
37
34
  },
38
- };
35
+ },
36
+ }
37
+ : {
38
+ value: JSON.stringify(currentData),
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.0",
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
  }