@things-factory/scheduler-client 8.0.0-beta.9 → 8.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/scheduler-client",
3
- "version": "8.0.0-beta.9",
3
+ "version": "8.0.0",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -27,12 +27,12 @@
27
27
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
28
28
  },
29
29
  "dependencies": {
30
- "@operato/graphql": "^8.0.0-beta",
31
- "@operato/shell": "^8.0.0-beta",
32
- "@things-factory/auth-base": "^8.0.0-beta.9",
33
- "@things-factory/env": "^8.0.0-beta.4",
34
- "@things-factory/shell": "^8.0.0-beta.9",
30
+ "@operato/graphql": "^8.0.0",
31
+ "@operato/shell": "^8.0.0",
32
+ "@things-factory/auth-base": "^8.0.0",
33
+ "@things-factory/env": "^8.0.0",
34
+ "@things-factory/shell": "^8.0.0",
35
35
  "node-fetch": "^2.6.0"
36
36
  },
37
- "gitHead": "86b1dfa26292926a2d5447fdc23bfa5a9e983245"
37
+ "gitHead": "07ef27d272dd9a067a9648ac7013748510556a18"
38
38
  }
@@ -0,0 +1 @@
1
+ export * from './scheduler-api'
@@ -0,0 +1,11 @@
1
+ import { Domain } from '@things-factory/shell'
2
+ import { config } from '@things-factory/env'
3
+ const isPathBaseDomain = !config.get('subdomain') && !config.get('useVirtualHostBasedDomain')
4
+
5
+ export const SchedulerEndpoint: string = config.get('scheduler/endpoint', 'http://127.0.0.1:9902')
6
+ export const CallbackBase: string = config.get('scheduler/callbackBase', 'http://localhost:3000')
7
+ export const Application: string = config.get('scheduler/application')
8
+
9
+ export function getCallbackBaseWithDomainContext(domain: Domain) {
10
+ return isPathBaseDomain ? CallbackBase + `/domain/${domain.subdomain}` : CallbackBase
11
+ }
@@ -0,0 +1,9 @@
1
+ export * from './types'
2
+ export * from './schedule'
3
+ export * from './schedules'
4
+ export * from './register-schedule'
5
+ export * from './update-schedule'
6
+ export * from './unregister-schedule'
7
+ export * from './unregister-schedules'
8
+
9
+ export * from './config'
@@ -0,0 +1,24 @@
1
+ import fetch from 'node-fetch'
2
+
3
+ import { SchedulerEndpoint } from './config'
4
+ import { ScheduleRegisterRequest } from './types'
5
+
6
+ export async function registerSchedule(schedule: ScheduleRegisterRequest) {
7
+ var body = JSON.stringify(schedule)
8
+
9
+ try {
10
+ const response = await fetch(SchedulerEndpoint + '/schedules', {
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
+ return id
21
+ } catch (err) {
22
+ console.error(err)
23
+ }
24
+ }
@@ -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
+ }
@@ -0,0 +1,32 @@
1
+ import fetch from 'node-fetch'
2
+ import { SchedulerEndpoint } from './config'
3
+
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 || {}
13
+
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',
22
+ headers: {
23
+ accept: 'application/json'
24
+ }
25
+ })
26
+
27
+ if (!response.ok) {
28
+ throw new Error(`Failed to fetch schedules: ${response.statusText}`)
29
+ }
30
+
31
+ return await response.json()
32
+ }
@@ -0,0 +1,36 @@
1
+ export type ScheduleClient = {
2
+ application: string
3
+ group: string
4
+ type?: string
5
+ key?: string
6
+ operation?: string
7
+ }
8
+
9
+ export type ScheduleTask = {
10
+ type: 'rest' | 'kafka' | 'redis'
11
+ connection: any // callback endpoint
12
+ data: any // callback context
13
+ history_check?: boolean //
14
+ failed_policy?: 'ignore' | 'retry' | 'retry_dlq'
15
+ max_retry_count?: number // max_retries (default: -1 (unlimited),
16
+ retry_period?: 60
17
+ }
18
+
19
+ export type ScheduleRegisterRequest = {
20
+ name?: string
21
+ client: ScheduleClient
22
+ type: 'now' | 'date' | 'delay' | 'cron' | 'delay-recur'
23
+ schedule: string
24
+ timezone: string
25
+ task: ScheduleTask
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,14 @@
1
+ import fetch from 'node-fetch'
2
+ import { SchedulerEndpoint } from './config'
3
+
4
+ export async function unregisterSchedule(handle: string) {
5
+ const response = await fetch(SchedulerEndpoint + '/schedules/' + handle, {
6
+ method: 'delete',
7
+ headers: {
8
+ accept: 'application/json',
9
+ 'Content-Type': 'application/json'
10
+ }
11
+ })
12
+
13
+ return await response.json()
14
+ }
@@ -0,0 +1,25 @@
1
+ import fetch from 'node-fetch'
2
+
3
+ import { SchedulerEndpoint } from './config'
4
+ import { ScheduleClient } from './types'
5
+
6
+ export async function unregisterSchedules(client: ScheduleClient) {
7
+ const response = await fetch(
8
+ SchedulerEndpoint +
9
+ '/schedules?' +
10
+ new URLSearchParams({
11
+ operation: client?.operation || '',
12
+ application: client?.application || '',
13
+ group: client?.group || '',
14
+ key: client?.key || ''
15
+ }),
16
+ {
17
+ method: 'delete',
18
+ headers: {
19
+ accept: 'application/json'
20
+ }
21
+ }
22
+ )
23
+
24
+ return await response.json()
25
+ }
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export * from './controllers'
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "strict": false,
5
+ "module": "commonjs",
6
+ "outDir": "../dist-server",
7
+ "baseUrl": "./"
8
+ },
9
+ "include": ["./**/*"]
10
+ }