@fraym/streams 0.2.0 → 0.2.1

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/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
@@ -16,10 +16,11 @@ 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
+ value: any;
22
+ gdprDefault: any;
23
23
  }
24
+ export declare const isGdprEventData: (value: EventData) => value is GdprEventData;
24
25
  export type HandlerFunc = (event: SubscriptionEvent) => Promise<void>;
25
26
  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,14 @@ 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
+ : "",
18
27
  };
19
28
  }
20
29
  else {
21
- payload[key] = data.value;
30
+ payload[key] = JSON.parse(data.value);
22
31
  }
23
32
  }
24
33
  }
@@ -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({
@@ -21,21 +22,20 @@ const getEventEnvelopeFromPublishedEvent = (event) => {
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: "",
37
33
  },
38
- };
34
+ },
35
+ }
36
+ : {
37
+ value: JSON.stringify(currentData),
38
+ };
39
39
  }
40
40
  return {
41
41
  broadcast: (_a = event.broadcast) !== null && _a !== void 0 ? _a : false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/streams",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/streams-nodejs",
6
6
  "repository": {