@flowcore/cli 1.1.2 → 1.2.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/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@
7
7
 
8
8
 
9
9
 
10
+ ## [1.2.0](https://github.com/flowcore-io/flowcore-cli/compare/v1.1.2...v1.2.0) (2024-01-09)
11
+
12
+
13
+ ### Features
14
+
15
+ * added multiple events, added weeks functionality to start time ([9a2f8cc](https://github.com/flowcore-io/flowcore-cli/commit/9a2f8cc5e4c5dd885f5cab6c3fbd886caf6b482d))
16
+
10
17
  ## [1.1.2](https://github.com/flowcore-io/flowcore-cli/compare/v1.1.1...v1.1.2) (2024-01-09)
11
18
 
12
19
 
package/README.md CHANGED
@@ -17,7 +17,7 @@ $ npm install -g @flowcore/cli
17
17
  $ flowcore COMMAND
18
18
  running command...
19
19
  $ flowcore (--version)
20
- @flowcore/cli/1.1.2 linux-x64 node-v20.10.0
20
+ @flowcore/cli/1.2.0 linux-x64 node-v20.10.0
21
21
  $ flowcore --help [COMMAND]
22
22
  USAGE
23
23
  $ flowcore COMMAND
@@ -103,7 +103,7 @@ EXAMPLES
103
103
  $ flowcore config set -l https://auth.flowcore.io/realms/flowcore/.well-known/openid-configuration -c my-client-id -p
104
104
  ```
105
105
 
106
- _See code: [src/commands/config/set.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.1.2/src/commands/config/set.ts)_
106
+ _See code: [src/commands/config/set.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.2.0/src/commands/config/set.ts)_
107
107
 
108
108
  ## `flowcore config show`
109
109
 
@@ -123,7 +123,7 @@ EXAMPLES
123
123
  $ flowcore config show
124
124
  ```
125
125
 
126
- _See code: [src/commands/config/show.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.1.2/src/commands/config/show.ts)_
126
+ _See code: [src/commands/config/show.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.2.0/src/commands/config/show.ts)_
127
127
 
128
128
  ## `flowcore help [COMMANDS]`
129
129
 
@@ -166,7 +166,7 @@ EXAMPLES
166
166
  $ flowcore login --port 8080
167
167
  ```
168
168
 
169
- _See code: [src/commands/login.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.1.2/src/commands/login.ts)_
169
+ _See code: [src/commands/login.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.2.0/src/commands/login.ts)_
170
170
 
171
171
  ## `flowcore plugins`
172
172
 
@@ -467,10 +467,16 @@ DESCRIPTION
467
467
  Stream events from a datacore running on the Flowcore Platform
468
468
 
469
469
  EXAMPLES
470
- $ flowcore stream https://staging.flowcore.io/flowcore/flowcore-platform/organization.0/event.organization.subscription.updated-requested.0.stream
470
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream
471
+
472
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -s 1y
473
+
474
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -o log -s 3m --json > some.json
475
+
476
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/[<event type1>,<event type2>,<event type3>].stream -o log -s 3m
471
477
  ```
472
478
 
473
- _See code: [src/commands/stream.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.1.2/src/commands/stream.ts)_
479
+ _See code: [src/commands/stream.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.2.0/src/commands/stream.ts)_
474
480
 
475
481
  ## `flowcore version`
476
482
 
@@ -507,5 +513,5 @@ DESCRIPTION
507
513
  Check what user you are logged in as
508
514
  ```
509
515
 
510
- _See code: [src/commands/whoami.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.1.2/src/commands/whoami.ts)_
516
+ _See code: [src/commands/whoami.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.2.0/src/commands/whoami.ts)_
511
517
  <!-- commandsstop -->
@@ -19,7 +19,10 @@ export default class Stream extends BaseCommand {
19
19
  };
20
20
  static description = 'Stream events from a datacore running on the Flowcore Platform';
21
21
  static examples = [
22
- '<%= config.bin %> <%= command.id %> https://staging.flowcore.io/flowcore/flowcore-platform/organization.0/event.organization.subscription.updated-requested.0.stream',
22
+ '<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream',
23
+ '<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -s 1y',
24
+ '<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -o log -s 3m --json > some.json',
25
+ '<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/[<event type1>,<event type2>,<event type3>].stream -o log -s 3m',
23
26
  ];
24
27
  static flags = {
25
28
  destination: Flags.string({ char: 'd', default: "http://localhost:3000/transform", description: 'Destination to send events to' }),
@@ -53,7 +56,7 @@ export default class Stream extends BaseCommand {
53
56
  const org = parts[1];
54
57
  const dataCore = parts[2];
55
58
  const aggregator = parts[3];
56
- const eventType = parts[4].replace(/\.stream$/i, "");
59
+ const eventTypes = parts[4].replace(/\.stream$/i, "").replace("[", "").replace("]", "").split(",");
57
60
  const fetchDataCoreResponse = await graphqlClient.client.request(FETCH_DATA_CORE_GQL_QUERY, {
58
61
  dataCore,
59
62
  organization: org,
@@ -63,7 +66,7 @@ export default class Stream extends BaseCommand {
63
66
  aggregator,
64
67
  dataCoreId,
65
68
  });
66
- let firstTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => e.name === eventType)?.catalog.range.firstTimeBucket;
69
+ let firstTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => eventTypes.includes(e.name))?.catalog.range.firstTimeBucket;
67
70
  if (!firstTimeBucket && !flags.start) {
68
71
  firstTimeBucket = createTimebucket(dayjs());
69
72
  !this.flags.json && this.warn(`First time bucket not found, setting to current time (${ux.colorize("yellowBright", firstTimeBucket)})`);
@@ -76,15 +79,15 @@ export default class Stream extends BaseCommand {
76
79
  firstTimeBucket = this.setTimeBucket(dayjs(), "1d");
77
80
  !this.flags.json && this.log(ux.colorize("green", `Setting first time bucket to ${ux.colorize("yellow", "1d")} ago (${ux.colorize("yellowBright", firstTimeBucket)})`));
78
81
  }
79
- let lastTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => e.name === eventType)?.catalog.range.lastTimeBucket;
82
+ let lastTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => eventTypes.includes(e.name))?.catalog.range.lastTimeBucket;
80
83
  if (!lastTimeBucket) {
81
84
  lastTimeBucket = createTimebucket(dayjs());
82
85
  !this.flags.json && this.warn(`Last time bucket not found, setting to current time (${ux.colorize("yellowBright", lastTimeBucket)})`);
83
86
  }
84
87
  const observer = new Subject();
85
- !this.flags.json && this.log(ux.colorize("blackBright", `Starting to stream events for ${dataCoreId} - ${aggregator} - ${eventType}, press ${ux.colorize("whiteBright", "ctrl+c")} to stop`));
88
+ !this.flags.json && this.log(ux.colorize("blackBright", `Starting to stream events for ${dataCoreId} - ${aggregator} - ${eventTypes}, press ${ux.colorize("whiteBright", "ctrl+c")} to stop`));
86
89
  // eslint-disable-next-line no-void
87
- void this.streamEvents(dataCoreId, aggregator, eventType, firstTimeBucket, lastTimeBucket, graphqlClient, observer, flags.live);
90
+ void this.streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, flags.live);
88
91
  await this.processEvents(observer, flags.destination, flags.output);
89
92
  }
90
93
  async processEvents(observer, destination, output) {
@@ -120,13 +123,14 @@ export default class Stream extends BaseCommand {
120
123
  !this.flags.json && this.log(`Sending event to ${destination}: ${event.eventId}`);
121
124
  try {
122
125
  // eslint-disable-next-line no-await-in-loop
123
- const result = await fetch(destination, {
124
- body: JSON.stringify(event),
125
- headers: {
126
- "Content-Type": "application/json",
127
- },
128
- method: "POST",
129
- });
126
+ const result = await Promise.race([fetch(destination, {
127
+ body: JSON.stringify(event),
128
+ headers: {
129
+ "Content-Type": "application/json",
130
+ },
131
+ method: "POST",
132
+ }),
133
+ new Promise((resolve, reject) => { setTimeout(() => reject(new Error("Timeout waiting for response")), 5000); }),]);
130
134
  if (!result.ok) {
131
135
  !this.flags.json && this.warn(`Error sending event to ${destination}: ${result.statusText}`);
132
136
  }
@@ -161,6 +165,9 @@ export default class Stream extends BaseCommand {
161
165
  case "m": {
162
166
  return createTimebucket(date.subtract(Number.parseInt(parts[1], 10), "month"));
163
167
  }
168
+ case "w": {
169
+ return createTimebucket(date.subtract(Number.parseInt(parts[1], 10), "week"));
170
+ }
164
171
  case "d": {
165
172
  return createTimebucket(date.subtract(Number.parseInt(parts[1], 10), "day"));
166
173
  }
@@ -172,7 +179,7 @@ export default class Stream extends BaseCommand {
172
179
  }
173
180
  }
174
181
  }
175
- async streamEvents(dataCoreId, aggregator, eventType, firstTimeBucket, lastTimeBucket, graphqlClient, observer, live) {
182
+ async streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, live) {
176
183
  let startTimeBucket = dayjs(firstTimeBucket, TIME_BUCKET_HOUR_PATTERN);
177
184
  const currentTime = dayjs.utc();
178
185
  let liveMode = false;
@@ -197,7 +204,7 @@ export default class Stream extends BaseCommand {
197
204
  afterEventId: lastEventId || undefined,
198
205
  aggregator,
199
206
  dataCoreId,
200
- eventType,
207
+ eventTypes,
201
208
  timeBucket,
202
209
  });
203
210
  cursor = response.datacore.fetchEvents.cursor;
@@ -21,7 +21,7 @@ export type FetchEventsQueryInput = {
21
21
  beforeEventId?: string;
22
22
  cursor?: string;
23
23
  dataCoreId: string;
24
- eventType: string;
24
+ eventTypes: string[];
25
25
  pageSize?: number;
26
26
  timeBucket: string;
27
27
  };
@@ -1,10 +1,10 @@
1
1
  import { gql } from "graphql-request";
2
2
  export const FETCH_EVENTS_GQL_QUERY = gql `
3
- query FLOWCORE_CLI_FETCH_EVENTS($dataCoreId: ID!, $aggregator: String!, $eventType: String!, $timeBucket: String!, $cursor: String, $afterEventId: String, $beforeEventId: String, $pageSize: Int) {
3
+ query FLOWCORE_CLI_FETCH_EVENTS($dataCoreId: ID!, $aggregator: String!, $eventTypes: [String!]!, $timeBucket: String!, $cursor: String, $afterEventId: String, $beforeEventId: String, $pageSize: Int) {
4
4
  datacore(search: {id: $dataCoreId}) {
5
5
  fetchEvents(input: {
6
6
  aggregator: $aggregator,
7
- eventTypes: [$eventType],
7
+ eventTypes: $eventTypes,
8
8
  timeBucket: $timeBucket
9
9
  cursor: $cursor
10
10
  afterEventId: $afterEventId
@@ -52,7 +52,10 @@
52
52
  },
53
53
  "description": "Stream events from a datacore running on the Flowcore Platform",
54
54
  "examples": [
55
- "<%= config.bin %> <%= command.id %> https://staging.flowcore.io/flowcore/flowcore-platform/organization.0/event.organization.subscription.updated-requested.0.stream"
55
+ "<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream",
56
+ "<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -s 1y",
57
+ "<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -o log -s 3m --json > some.json",
58
+ "<%= config.bin %> <%= command.id %> https://flowcore.io/<org>/<data core>/<flow type>/[<event type1>,<event type2>,<event type3>].stream -o log -s 3m"
56
59
  ],
57
60
  "flags": {
58
61
  "profile": {
@@ -256,5 +259,5 @@
256
259
  ]
257
260
  }
258
261
  },
259
- "version": "1.1.2"
262
+ "version": "1.2.0"
260
263
  }
package/package.json CHANGED
@@ -86,7 +86,7 @@
86
86
  "prestart": "npm run build",
87
87
  "update-schema": "rover graph introspect https://graph.api.staging.flowcore.io/graphql -o schema.gql"
88
88
  },
89
- "version": "1.1.2",
89
+ "version": "1.2.0",
90
90
  "bugs": "https://github.com/flowcore-io/flowcore-cli/issues",
91
91
  "keywords": [
92
92
  "flowcore",