@things-factory/scheduler-client 7.1.33 → 7.1.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/scheduler-client",
3
- "version": "7.1.33",
3
+ "version": "7.1.47",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -29,10 +29,10 @@
29
29
  "dependencies": {
30
30
  "@operato/graphql": "^7.0.0",
31
31
  "@operato/shell": "^7.0.0",
32
- "@things-factory/auth-base": "^7.1.33",
32
+ "@things-factory/auth-base": "^7.1.47",
33
33
  "@things-factory/env": "^7.1.16",
34
- "@things-factory/shell": "^7.1.24",
34
+ "@things-factory/shell": "^7.1.47",
35
35
  "node-fetch": "^2.6.0"
36
36
  },
37
- "gitHead": "da463a7d7851cf47c7d4b8136e7be6690b55969e"
37
+ "gitHead": "2d63d16d4d974193802a0c23b6794061d2ba4bd2"
38
38
  }
@@ -1,6 +1,8 @@
1
1
  export * from './types'
2
+ export * from './schedule'
2
3
  export * from './schedules'
3
4
  export * from './register-schedule'
5
+ export * from './update-schedule'
4
6
  export * from './unregister-schedule'
5
7
  export * from './unregister-schedules'
6
8
 
@@ -0,0 +1,19 @@
1
+ import fetch from 'node-fetch'
2
+ import { SchedulerEndpoint } from './config'
3
+
4
+ export async function getSchedule(id: string) {
5
+ const response = await fetch(`${SchedulerEndpoint}/schedules/${id}`, {
6
+ method: 'get',
7
+ headers: {
8
+ accept: 'application/json',
9
+ 'Content-Type': 'application/json'
10
+ }
11
+ })
12
+
13
+ if (!response.ok) {
14
+ throw new Error(`Failed to fetch schedule with id ${id}: ${response.statusText}`)
15
+ }
16
+
17
+ const schedules = await response.json()
18
+ return schedules && schedules[0]
19
+ }
@@ -1,17 +1,32 @@
1
1
  import fetch from 'node-fetch'
2
2
  import { SchedulerEndpoint } from './config'
3
3
 
4
- export async function getSchedules(name: string, group: string, dlq: boolean) {
5
- var body = JSON.stringify({ name, group, dlq })
4
+ export async function getSchedules(params: {
5
+ application?: string
6
+ group?: string
7
+ type?: string
8
+ key?: string
9
+ operation?: string
10
+ }) {
11
+ const url = new URL('/schedules', SchedulerEndpoint)
12
+ const { application, group, type, key, operation } = params || {}
6
13
 
7
- const response = await fetch(SchedulerEndpoint + '/schedules', {
8
- method: 'get',
14
+ application && url.searchParams.append('application', application)
15
+ group && url.searchParams.append('group', group)
16
+ type && url.searchParams.append('type', type)
17
+ key && url.searchParams.append('key', key)
18
+ operation && url.searchParams.append('operation', operation)
19
+
20
+ const response = await fetch(url, {
21
+ method: 'GET',
9
22
  headers: {
10
- accept: 'application/json',
11
- 'Content-Type': 'application/json'
12
- },
13
- body
23
+ accept: 'application/json'
24
+ }
14
25
  })
15
26
 
27
+ if (!response.ok) {
28
+ throw new Error(`Failed to fetch schedules: ${response.statusText}`)
29
+ }
30
+
16
31
  return await response.json()
17
32
  }
@@ -24,3 +24,13 @@ export type ScheduleRegisterRequest = {
24
24
  timezone: string
25
25
  task: ScheduleTask
26
26
  }
27
+
28
+ export type ScheduleUpdateRequest = {
29
+ id: string
30
+ name?: string
31
+ client: ScheduleClient
32
+ type: 'now' | 'date' | 'delay' | 'cron' | 'delay-recur'
33
+ schedule: string
34
+ timezone: string
35
+ task: ScheduleTask
36
+ }
@@ -0,0 +1,25 @@
1
+ import fetch from 'node-fetch'
2
+
3
+ import { SchedulerEndpoint } from './config'
4
+ import { ScheduleUpdateRequest } from './types'
5
+
6
+ export async function updateSchedule(schedule: ScheduleUpdateRequest) {
7
+ var body = JSON.stringify(schedule)
8
+
9
+ try {
10
+ const response = await fetch(SchedulerEndpoint + `/schedules/${schedule?.id}/update`, {
11
+ method: 'POST',
12
+ headers: {
13
+ accept: 'application/json',
14
+ 'Content-Type': 'application/json'
15
+ },
16
+ body
17
+ })
18
+
19
+ const { id } = await response.json()
20
+
21
+ return id
22
+ } catch (err) {
23
+ console.error(err)
24
+ }
25
+ }