@flowcore/cli 1.1.2 → 1.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/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@
7
7
 
8
8
 
9
9
 
10
+ ## [1.3.0](https://github.com/flowcore-io/flowcore-cli/compare/v1.2.0...v1.3.0) (2024-01-09)
11
+
12
+
13
+ ### Features
14
+
15
+ * added timeout for destination as flag ([f731aac](https://github.com/flowcore-io/flowcore-cli/commit/f731aac025262179af1fd56e2ab2477a674635f9))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * added description to start that includes week ([58687a7](https://github.com/flowcore-io/flowcore-cli/commit/58687a7bbb66aaa5d6da26af88e555cbb1e72467))
21
+
22
+ ## [1.2.0](https://github.com/flowcore-io/flowcore-cli/compare/v1.1.2...v1.2.0) (2024-01-09)
23
+
24
+
25
+ ### Features
26
+
27
+ * added multiple events, added weeks functionality to start time ([9a2f8cc](https://github.com/flowcore-io/flowcore-cli/commit/9a2f8cc5e4c5dd885f5cab6c3fbd886caf6b482d))
28
+
10
29
  ## [1.1.2](https://github.com/flowcore-io/flowcore-cli/compare/v1.1.1...v1.1.2) (2024-01-09)
11
30
 
12
31
 
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.3.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.3.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.3.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.3.0/src/commands/login.ts)_
170
170
 
171
171
  ## `flowcore plugins`
172
172
 
@@ -449,7 +449,7 @@ Stream events from a datacore running on the Flowcore Platform
449
449
 
450
450
  ```
451
451
  USAGE
452
- $ flowcore stream STREAM [--profile <value>] [-d <value>] [-j] [-l] [-o http|log] [-s <value>]
452
+ $ flowcore stream STREAM [--profile <value>] [-d <value>] [-j] [-l] [-o http|log] [-s <value>] [-t <value>]
453
453
 
454
454
  ARGUMENTS
455
455
  STREAM stream url to connect to
@@ -460,17 +460,24 @@ FLAGS
460
460
  -l, --[no-]live Change to live mode when reaching last time bucket
461
461
  -o, --output=<option> [default: http] Output format
462
462
  <options: http|log>
463
- -s, --start=<value> Start time bucket to stream from, example: (1y, 1m, 1d, 1h)
463
+ -s, --start=<value> Start time bucket to stream from, example: (1y, 1m, 1w, 1d, 1h)
464
+ -t, --timeout=<value> [default: 5000] Timeout in milliseconds to wait for a response from the destination
464
465
  --profile=<value> Specify the configuration profile to use
465
466
 
466
467
  DESCRIPTION
467
468
  Stream events from a datacore running on the Flowcore Platform
468
469
 
469
470
  EXAMPLES
470
- $ flowcore stream https://staging.flowcore.io/flowcore/flowcore-platform/organization.0/event.organization.subscription.updated-requested.0.stream
471
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream
472
+
473
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -s 1y
474
+
475
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/<event type>.stream -o log -s 3m --json > some.json
476
+
477
+ $ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/[<event type1>,<event type2>,<event type3>].stream -o log -s 3m
471
478
  ```
472
479
 
473
- _See code: [src/commands/stream.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.1.2/src/commands/stream.ts)_
480
+ _See code: [src/commands/stream.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.3.0/src/commands/stream.ts)_
474
481
 
475
482
  ## `flowcore version`
476
483
 
@@ -507,5 +514,5 @@ DESCRIPTION
507
514
  Check what user you are logged in as
508
515
  ```
509
516
 
510
- _See code: [src/commands/whoami.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.1.2/src/commands/whoami.ts)_
517
+ _See code: [src/commands/whoami.ts](https://github.com/flowcore-io/flowcore-cli/blob/v1.3.0/src/commands/whoami.ts)_
511
518
  <!-- commandsstop -->
@@ -11,6 +11,7 @@ export default class Stream extends BaseCommand<typeof Stream> {
11
11
  live: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
12
12
  output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
13
13
  start: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
14
+ timeout: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
14
15
  };
15
16
  run(): Promise<void>;
16
17
  private processEvents;
@@ -19,14 +19,18 @@ 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' }),
26
29
  json: Flags.boolean({ char: 'j', description: 'Output json only' }),
27
30
  live: Flags.boolean({ allowNo: true, char: 'l', default: true, description: 'Change to live mode when reaching last time bucket' }),
28
31
  output: Flags.string({ char: 'o', default: 'http', description: 'Output format', options: ['http', 'log'] }),
29
- start: Flags.string({ char: 's', description: 'Start time bucket to stream from, example: (1y, 1m, 1d, 1h)' }),
32
+ start: Flags.string({ char: 's', description: 'Start time bucket to stream from, example: (1y, 1m, 1w, 1d, 1h)' }),
33
+ timeout: Flags.integer({ char: 't', default: 5000, description: 'Timeout in milliseconds to wait for a response from the destination' }),
30
34
  };
31
35
  async run() {
32
36
  const config = this.cliConfiguration.getConfig();
@@ -53,7 +57,7 @@ export default class Stream extends BaseCommand {
53
57
  const org = parts[1];
54
58
  const dataCore = parts[2];
55
59
  const aggregator = parts[3];
56
- const eventType = parts[4].replace(/\.stream$/i, "");
60
+ const eventTypes = parts[4].replace(/\.stream$/i, "").replace("[", "").replace("]", "").split(",");
57
61
  const fetchDataCoreResponse = await graphqlClient.client.request(FETCH_DATA_CORE_GQL_QUERY, {
58
62
  dataCore,
59
63
  organization: org,
@@ -63,7 +67,7 @@ export default class Stream extends BaseCommand {
63
67
  aggregator,
64
68
  dataCoreId,
65
69
  });
66
- let firstTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => e.name === eventType)?.catalog.range.firstTimeBucket;
70
+ let firstTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => eventTypes.includes(e.name))?.catalog.range.firstTimeBucket;
67
71
  if (!firstTimeBucket && !flags.start) {
68
72
  firstTimeBucket = createTimebucket(dayjs());
69
73
  !this.flags.json && this.warn(`First time bucket not found, setting to current time (${ux.colorize("yellowBright", firstTimeBucket)})`);
@@ -76,15 +80,15 @@ export default class Stream extends BaseCommand {
76
80
  firstTimeBucket = this.setTimeBucket(dayjs(), "1d");
77
81
  !this.flags.json && this.log(ux.colorize("green", `Setting first time bucket to ${ux.colorize("yellow", "1d")} ago (${ux.colorize("yellowBright", firstTimeBucket)})`));
78
82
  }
79
- let lastTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => e.name === eventType)?.catalog.range.lastTimeBucket;
83
+ let lastTimeBucket = eventRangeRequest.datacore.flowtypes.find(ft => ft.aggregator === aggregator)?.events.find(e => eventTypes.includes(e.name))?.catalog.range.lastTimeBucket;
80
84
  if (!lastTimeBucket) {
81
85
  lastTimeBucket = createTimebucket(dayjs());
82
86
  !this.flags.json && this.warn(`Last time bucket not found, setting to current time (${ux.colorize("yellowBright", lastTimeBucket)})`);
83
87
  }
84
88
  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`));
89
+ !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
90
  // eslint-disable-next-line no-void
87
- void this.streamEvents(dataCoreId, aggregator, eventType, firstTimeBucket, lastTimeBucket, graphqlClient, observer, flags.live);
91
+ void this.streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, flags.live);
88
92
  await this.processEvents(observer, flags.destination, flags.output);
89
93
  }
90
94
  async processEvents(observer, destination, output) {
@@ -120,13 +124,14 @@ export default class Stream extends BaseCommand {
120
124
  !this.flags.json && this.log(`Sending event to ${destination}: ${event.eventId}`);
121
125
  try {
122
126
  // 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
- });
127
+ const result = await Promise.race([fetch(destination, {
128
+ body: JSON.stringify(event),
129
+ headers: {
130
+ "Content-Type": "application/json",
131
+ },
132
+ method: "POST",
133
+ }),
134
+ new Promise((resolve, reject) => { setTimeout(() => reject(new Error("Timeout waiting for response")), this.flags.timeout); }),]);
130
135
  if (!result.ok) {
131
136
  !this.flags.json && this.warn(`Error sending event to ${destination}: ${result.statusText}`);
132
137
  }
@@ -150,7 +155,7 @@ export default class Stream extends BaseCommand {
150
155
  }
151
156
  }
152
157
  setTimeBucket(date, start) {
153
- const parts = start.match(/(\d+)([dhmy])/i);
158
+ const parts = start.match(/(\d+)([dhmwy])/i);
154
159
  if (!parts) {
155
160
  ux.error(`Invalid start time bucket, generated from ${start}`);
156
161
  }
@@ -161,6 +166,9 @@ export default class Stream extends BaseCommand {
161
166
  case "m": {
162
167
  return createTimebucket(date.subtract(Number.parseInt(parts[1], 10), "month"));
163
168
  }
169
+ case "w": {
170
+ return createTimebucket(date.subtract(Number.parseInt(parts[1], 10), "week"));
171
+ }
164
172
  case "d": {
165
173
  return createTimebucket(date.subtract(Number.parseInt(parts[1], 10), "day"));
166
174
  }
@@ -172,7 +180,7 @@ export default class Stream extends BaseCommand {
172
180
  }
173
181
  }
174
182
  }
175
- async streamEvents(dataCoreId, aggregator, eventType, firstTimeBucket, lastTimeBucket, graphqlClient, observer, live) {
183
+ async streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, live) {
176
184
  let startTimeBucket = dayjs(firstTimeBucket, TIME_BUCKET_HOUR_PATTERN);
177
185
  const currentTime = dayjs.utc();
178
186
  let liveMode = false;
@@ -197,7 +205,7 @@ export default class Stream extends BaseCommand {
197
205
  afterEventId: lastEventId || undefined,
198
206
  aggregator,
199
207
  dataCoreId,
200
- eventType,
208
+ eventTypes,
201
209
  timeBucket,
202
210
  });
203
211
  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": {
@@ -100,11 +103,20 @@
100
103
  },
101
104
  "start": {
102
105
  "char": "s",
103
- "description": "Start time bucket to stream from, example: (1y, 1m, 1d, 1h)",
106
+ "description": "Start time bucket to stream from, example: (1y, 1m, 1w, 1d, 1h)",
104
107
  "name": "start",
105
108
  "hasDynamicHelp": false,
106
109
  "multiple": false,
107
110
  "type": "option"
111
+ },
112
+ "timeout": {
113
+ "char": "t",
114
+ "description": "Timeout in milliseconds to wait for a response from the destination",
115
+ "name": "timeout",
116
+ "default": 5000,
117
+ "hasDynamicHelp": false,
118
+ "multiple": false,
119
+ "type": "option"
108
120
  }
109
121
  },
110
122
  "hasDynamicHelp": false,
@@ -256,5 +268,5 @@
256
268
  ]
257
269
  }
258
270
  },
259
- "version": "1.1.2"
271
+ "version": "1.3.0"
260
272
  }
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.3.0",
90
90
  "bugs": "https://github.com/flowcore-io/flowcore-cli/issues",
91
91
  "keywords": [
92
92
  "flowcore",