/
AppScript.ts
68 lines (59 loc) · 1.85 KB
/
AppScript.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
import { QlikSaaSClient } from "qlik-rest-api";
import { IScriptMeta, IScriptMetaWithScript } from "./Apps.interfaces";
export class AppScript {
#id: string;
private appId: string;
#saasClient: QlikSaaSClient;
details: IScriptMetaWithScript;
constructor(
saasClient: QlikSaaSClient,
versionId: string,
appId: string,
details?: IScriptMetaWithScript
) {
if (!versionId) throw new Error(`"versionId" parameter is required`);
this.details = details ?? ({} as IScriptMetaWithScript);
this.#id = versionId;
this.appId = appId;
this.#saasClient = saasClient;
}
async init(arg?: { force: boolean }) {
if (!this.details || arg?.force == true) {
this.details = await this.#saasClient
.Get<IScriptMetaWithScript>(
`apps/${this.appId}/scripts?filter=ScriptId eq "${this.#id}"`
)
.then((res) => ({ ...res.data, script: "" }));
}
}
async getScriptContent() {
this.details.script = await this.#saasClient
.Get<string>(`apps/${this.appId}/scripts/${this.#id}`)
.then((res) => res.data["script"]);
return this.details.script;
}
async remove() {
return await this.#saasClient
.Delete(`apps/${this.appId}/scripts/${this.#id}`)
.then((res) => res.status);
}
/**
* Not very clear from the documentation what can be done here
*
* The UI allows only the name of the version (`versionMessage` ) to be updated.
* And because of this, this method only updates the name as well
*/
async update(arg: { name: string }) {
const updateStatus = await this.#saasClient
.Patch(`apps/${this.appId}/scripts/${this.#id}`, [
{
op: "replace",
path: "/versionMessage",
value: arg.name,
},
])
.then((res) => res.status);
await this.init({ force: true });
return updateStatus;
}
}