@pelican.ts/sdk 0.3.4-next.4 → 0.4.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.
@@ -0,0 +1,126 @@
1
+ import type {ServerClient} from "@/api/client/server";
2
+ import type {Schedule, ScheduleTask} from "@/api/common/types/server_schedule";
3
+ import type {Nullable, PartialBy} from "@/utils/types";
4
+
5
+
6
+ export class ServerSchedule {
7
+ private readonly client: ServerClient
8
+ readonly createdAt: Date
9
+ private $cron: {
10
+ day_of_week: string,
11
+ day_of_month: string,
12
+ hour: string,
13
+ minute: string
14
+ }
15
+ get cron() {return {...this.$cron}}
16
+ readonly id: number
17
+ private $isActive: boolean
18
+ get isActive() {return this.$isActive}
19
+ private $isProcessing: boolean
20
+ get isProcessing() {return this.$isProcessing}
21
+ readonly lastRunAt: Nullable<Date>
22
+ private $name: string
23
+ get name() {return this.$name}
24
+ readonly nextRunAt: Date
25
+ private $onlyWhenOnline: boolean
26
+ get onlyWhenOnline() {return this.$onlyWhenOnline}
27
+ readonly tasks: ServerScheduleTask[]
28
+ private $updatedAt: Date
29
+ get updatedAt() {return this.$updatedAt}
30
+
31
+ constructor(client: ServerClient, schedule: Schedule) {
32
+ this.client = client
33
+ this.createdAt = new Date(schedule.created_at)
34
+ this.$cron = schedule.cron
35
+ this.id = schedule.id
36
+ this.$isActive = schedule.is_active
37
+ this.$isProcessing = schedule.is_processing
38
+ this.lastRunAt = schedule.last_run_at ? new Date(schedule.last_run_at) : null
39
+ this.$name = schedule.name
40
+ this.nextRunAt = new Date(schedule.next_run_at)
41
+ this.$onlyWhenOnline = schedule.only_when_online
42
+ this.tasks = schedule.relationships.tasks.data.map(
43
+ d => new ServerScheduleTask(this.client, this.id, d.attributes)
44
+ )
45
+ this.$updatedAt = new Date(schedule.updated_at)
46
+ }
47
+
48
+ update = async (
49
+ opts: {
50
+ name: string,
51
+ is_active?: boolean,
52
+ only_when_online?: boolean,
53
+ minute: string,
54
+ hour: string,
55
+ day_of_week: string,
56
+ month: string,
57
+ day_of_month: string
58
+ }
59
+ ) => {
60
+ const data = await this.client.schedules.control(this.id).update(opts)
61
+ this.$name = data.name
62
+ this.$isActive = data.is_active
63
+ this.$isProcessing = data.is_processing
64
+ this.$onlyWhenOnline = data.only_when_online
65
+ this.$cron = data.cron
66
+ this.$updatedAt = new Date(data.updated_at)
67
+ }
68
+
69
+ delete = async () => this.client.schedules.control(this.id).delete()
70
+
71
+ execute = async () => this.client.schedules.control(this.id).execute()
72
+ }
73
+
74
+ export class ServerScheduleTask {
75
+ private readonly client: ServerClient
76
+ private readonly scheduleId: number
77
+ private $action: "command" | "power" | "backup" | "delete_files";
78
+ get action() {return this.$action}
79
+ private $continueOnFailure: boolean;
80
+ get continueOnFailure() {return this.$continueOnFailure}
81
+ readonly createdAt: Date;
82
+ readonly id: number;
83
+ private $isQueued: boolean;
84
+ get isQueued() {return this.$isQueued}
85
+ private $payload: string;
86
+ get payload() {return this.$payload}
87
+ private $sequenceId: number;
88
+ get sequenceId() {return this.$sequenceId}
89
+ private $timeOffset: number;
90
+ get timeOffset() {return this.$timeOffset}
91
+ private $updatedAt: Nullable<Date>;
92
+ get updatedAt() {return this.$updatedAt}
93
+
94
+ constructor(client: ServerClient, scheduleId: number, task: ScheduleTask) {
95
+ this.client = client
96
+ this.scheduleId = scheduleId
97
+ this.$action = task.action
98
+ this.$continueOnFailure = task.continue_on_failure
99
+ this.createdAt = new Date(task.created_at)
100
+ this.id = task.id
101
+ this.$isQueued = task.is_queued
102
+ this.$payload = task.payload
103
+ this.$sequenceId = task.sequence_id
104
+ this.$timeOffset = task.time_offset
105
+ this.$updatedAt = task.updated_at ? new Date(task.updated_at) : null
106
+ }
107
+
108
+ delete = async () =>
109
+ this.client.schedules.control(this.scheduleId).tasks.delete(this.id)
110
+
111
+ update = async (
112
+ opts: PartialBy<
113
+ Pick<ScheduleTask, "action" | "payload" | "time_offset" | "sequence_id" | "continue_on_failure">,
114
+ "payload" | "sequence_id" | "continue_on_failure"
115
+ >
116
+ ) => {
117
+ const data = await this.client.schedules.control(this.scheduleId).tasks.update(this.id, opts)
118
+ this.$action = data.action
119
+ this.$continueOnFailure = data.continue_on_failure
120
+ this.$isQueued = data.is_queued
121
+ this.$payload = data.payload
122
+ this.$sequenceId = data.sequence_id
123
+ this.$timeOffset = data.time_offset
124
+ this.$updatedAt = data.updated_at ? new Date(data.updated_at) : null
125
+ }
126
+ }
@@ -0,0 +1,42 @@
1
+ import type {ServerClient} from "@/api/client/server";
2
+ import type {ServerSubuser, SubuserPermission} from "@/api/client/types/server_subuser";
3
+
4
+ export class ServerUser {
5
+ private readonly client: ServerClient
6
+
7
+ readonly uuid: string;
8
+ readonly username: string;
9
+ readonly email: string;
10
+ readonly language: string;
11
+ readonly image: string;
12
+ readonly admin: boolean;
13
+ readonly root_admin: boolean;
14
+ readonly has2faEnabled: boolean;
15
+ readonly createdAt: Date;
16
+ private $permissions: SubuserPermission[] | string[];
17
+ get permissions() {return this.$permissions}
18
+
19
+ constructor(client: ServerClient, user: ServerSubuser) {
20
+ this.client = client
21
+ this.uuid = user.uuid
22
+ this.username = user.username
23
+ this.email = user.email
24
+ this.language = user.language
25
+ this.image = user.image
26
+ this.admin = user.admin
27
+ this.root_admin = user.root_admin
28
+ this.has2faEnabled = user["2fa_enabled"]
29
+ this.createdAt = new Date(user.created_at)
30
+ this.$permissions = user.permissions
31
+ }
32
+
33
+ update = async (
34
+ permissions: SubuserPermission[] | string[]
35
+ ) => {
36
+ const data = await this.client.users.update(this.uuid, permissions)
37
+ this.$permissions = data.permissions
38
+ }
39
+
40
+ delete = async () => this.client.users.delete(this.uuid)
41
+
42
+ }
package/src/index.ts CHANGED
@@ -1,17 +1,8 @@
1
- import {Client as UserClient} from "@/api/client/client";
2
- import {Client as AppClient} from "@/api/application/client";
3
- import {Agent} from "@/api/base/request";
1
+ import {PelicanAPIClient} from "@/api";
2
+ import {Client as UserClient} from "@/humane/Client";
4
3
 
5
- export class PelicanClient extends UserClient{
6
- constructor(url: string, token: string, suffix: string = "/api") {
7
- const ax = new Agent(url, token, "client", suffix)
8
- super(ax.requester)
9
- }
10
- }
11
4
 
12
- export class PelicanApplication extends AppClient{
13
- constructor(url: string, token: string, suffix: string = "/api") {
14
- const ax = new Agent(url, token, "application", suffix)
15
- super(ax.requester)
16
- }
5
+ export const createPelicanClient = (url: string, token: string, suffix: string = "/api") => {
6
+ const client = new PelicanAPIClient(url, token, suffix)
7
+ return new UserClient(client)
17
8
  }
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  export const SIZES = {
4
2
  B: 1,
5
3
  KB: 1024,
@@ -9,7 +7,7 @@ export const SIZES = {
9
7
  }
10
8
 
11
9
  const sized = (bytes: number, unit: keyof typeof SIZES): number => {
12
- return parseInt((bytes / SIZES[unit]).toFixed(3))
10
+ return parseInt((bytes / SIZES[unit]).toFixed(3), 10)
13
11
  }
14
12
 
15
13