/
SharingTasks.ts
136 lines (124 loc) · 3.44 KB
/
SharingTasks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { QlikSaaSClient } from "qlik-rest-api";
import {
ISharingTask,
ISharingTaskRecurringRecipients,
ITemplateResult,
SharingTask,
} from "./SharingTask";
import { SharingTasksSettings } from "./SharingTasksSettings";
export interface ISharingTaskRecurringCreateRequest {
name: string;
type:
| "chart-monitoring"
| "chart-sharing"
| "sheet-sharing"
| "template-sharing";
state: {
fields: {}[];
queryItems: {}[];
selections: {
name: string;
values: string[];
isNumeric: boolean;
stateName: string;
displayName?: string;
displayValues?: string[];
}[];
};
/**
* @deprecated https://qlik.dev/changelog/77-api-deprecation-sharing-tasks/
*/
appName: string;
enabled?: boolean;
message?: string;
subType?: string;
tags?: string[];
trigger?: {
recurrence: string[];
chronosJobID?: string;
executeOnAppReload?: boolean;
executionHistoryInterval?: string;
};
startTime?: string;
templates: ITemplateResult[];
expiration?: string;
recipients?: ISharingTaskRecurringRecipients;
description?: string;
emailContent?: {
body: string;
subject: string;
};
retentionPolicy?: {
historySize: number;
overrideInterval: string;
};
scheduleOptions?: {
timezone: string;
recurrence: string[];
endDateTime: string;
chronosJobID: string;
startDateTime: string;
lastExecutionTime: string;
nextExecutionTime: string;
};
dataConnectionID?: string;
sharePointFolder?: string;
executeOnCreation?: boolean;
transportChannels?: string[];
distributionListId: string;
}
export class SharingTasks {
#saasClient: QlikSaaSClient;
settings: SharingTasksSettings;
constructor(saasClient: QlikSaaSClient) {
this.#saasClient = saasClient;
this.settings = new SharingTasksSettings(this.#saasClient);
}
async get(arg: { id: string }) {
if (!arg.id) throw new Error(`sharingTask.get: "id" parameter is required`);
const st: SharingTask = new SharingTask(this.#saasClient, arg.id);
await st.init();
return st;
}
/**
* Returns a list of sharing tasks as an instance
*/
async getAll() {
return await this.#saasClient
.Get<ISharingTask[]>(`sharing-tasks?limit=50`)
.then((res) => res.data)
.then((data) =>
data.map((t) => new SharingTask(this.#saasClient, t.id, t))
);
}
// async getFilter(arg: { filter: string }) {
// if (!arg.filter)
// throw new Error(`users.getFilter: "filter" parameter is required`);
// return await this.getAll().then((entities) => {
// const anonFunction = Function(
// "entities",
// `return entities.filter(f => ${parseFilter(arg.filter, "f.details")})`
// );
// return anonFunction(entities) as User[];
// });
// }
// async removeFilter(arg: { filter: string }) {
// if (!arg.filter)
// throw new Error(`users.removeFilter: "filter" parameter is required`);
// return await this.getFilter(arg).then((entities) =>
// Promise.all(
// entities.map((entity) =>
// entity.remove().then((s) => ({ id: entity.details.id, status: s }))
// )
// )
// );
// }
/**
* Creates a new recurring sharing task
*/
async create(arg: ISharingTaskRecurringCreateRequest) {
return await this.#saasClient
.Post<ISharingTask>(`shared-tasks`, arg)
.then((res) => new SharingTask(this.#saasClient, res.data.id, res.data));
}
}