Skip to content

Commit

Permalink
Merge branch '242-new-api---qlik-cloud-data-integratio'
Browse files Browse the repository at this point in the history
  • Loading branch information
countnazgul committed Jan 11, 2024
2 parents 4750a28 + 575e3b9 commit 192834b
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 152 deletions.
300 changes: 152 additions & 148 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@
},
"homepage": "https://informatiqal.com/qlik-saas-api/",
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.5",
"@rollup/plugin-typescript": "^11.1.6",
"@types/form-data": "^2.5.0",
"@types/node": "20.10.5",
"@types/node": "20.11.0",
"dotenv": "16.3.1",
"esm": "^3.2.25",
"nyc": "15.1.0",
"rollup": "^4.9.1",
"rollup": "^4.9.4",
"rollup-plugin-delete": "2.0.0",
"ts-node": "10.9.2",
"tslib": "^2.6.2",
"typedoc": "0.25.4",
"typedoc": "0.25.7",
"typescript": "5.0.4",
"vitest": "^0.34.6"
},
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { QlikSaaSClient } from "qlik-rest-api";
import { Apps } from "./modules/Apps";
import { Brands } from "./modules/Brands";
import { DataAlerts } from "./modules/DataAlerts";
import { DiProjects } from "./modules/DiProjects";
import { Automations } from "./modules/Automations";
import { AutomationConnections } from "./modules/AutomationConnections";
import { APIKeys } from "./modules/APIKeys";
Expand Down Expand Up @@ -49,6 +50,7 @@ export namespace QlikSaaSApi {
* BETA
*/
public dataAlerts: DataAlerts;
public diProjects: DiProjects;
public dataConnections: DataConnections;
public dataCredentials: DataCredentials;
public conditions: Conditions;
Expand Down Expand Up @@ -97,6 +99,7 @@ export namespace QlikSaaSApi {
this.audits = new Audits(this.#saasClient);
this.brands = new Brands(this.#saasClient);
this.dataAlerts = new DataAlerts(this.#saasClient);
this.diProjects = new DiProjects(this.#saasClient);
this.dataConnections = new DataConnections(this.#saasClient);
this.dataCredentials = new DataCredentials(this.#saasClient);
this.conditions = new Conditions(this.#saasClient);
Expand Down
37 changes: 37 additions & 0 deletions src/modules/DiProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { QlikSaaSClient } from "qlik-rest-api";
import { DiProjectTasks } from "./DiProjectTasks";

export interface IDiProject {
id: string;
name: string;
ownerId: string;
spaceId: string;
description: string;
}

export class DiProject {
#id: string;
#saasClient: QlikSaaSClient;
details: IDiProject;
tasks: DiProjectTasks;
constructor(saasClient: QlikSaaSClient, id: string, details?: IDiProject) {
if (!id) throw new Error(`diProject.get: "id" parameter is required`);

this.details = details ?? ({} as IDiProject);
this.#id = id;
this.#saasClient = saasClient;
this.tasks = new DiProjectTasks(saasClient, id);
}

async init(arg?: { force: boolean }) {
if (
!this.details ||
Object.keys(this.details).length == 0 ||
arg?.force == true
) {
this.details = await this.#saasClient
.Get<IDiProject>(`di-projects/${this.#id}`)
.then((res) => res.data);
}
}
}
93 changes: 93 additions & 0 deletions src/modules/DiProjectTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { QlikSaaSClient } from "qlik-rest-api";

export interface IDiProjectTask {
id: string;
name: string;
type:
| "LANDING"
| "STORAGE"
| "QVD_STORAGE"
| "TRANSFORM"
| "DATAMART"
| "REGISTERED_DATA"
| "REPLICATION"
| "DISTRIBUTION"
| "LAKE_LANDING"
| string;
ownerId: string;
spaceId: string;
description: string;
}

export interface IDataTaskInstanceState {
lastRun: {
state: "STARTING" | "RUNNING" | "COMPLETED" | "FAILED" | "CANCELED";
message: string;
};
runReadiness: {
state: "READY_TO_RUN" | "ALREADY_RUNNING" | "NOT_RUNNABLE";
message: string;
};
}

export class DiProjectTask {
#id: string;
#projectId: string;
#saasClient: QlikSaaSClient;
details: IDiProjectTask;
constructor(
saasClient: QlikSaaSClient,
id: string,
projectId: string,
details?: IDiProjectTask
) {
if (!id) throw new Error(`diProjectTask.get: "id" parameter is required`);
if (!projectId)
throw new Error(`diProjectTask.projectId: "id" parameter is required`);

this.details = details ?? ({} as IDiProjectTask);
this.#id = id;
this.#projectId = projectId;
this.#saasClient = saasClient;
}

async init(arg?: { force: boolean }) {
if (
!this.details ||
Object.keys(this.details).length == 0 ||
arg?.force == true
) {
this.details = await this.#saasClient
.Get<IDiProjectTask>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}`
)
.then((res) => res.data);
}
}

async start() {
return await this.#saasClient
.Post<IDiProjectTask>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}/start`,
{}
)
.then((res) => res.status);
}

async stop() {
return await this.#saasClient
.Post<IDiProjectTask>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}/stop`,
{}
)
.then((res) => res.status);
}

async state() {
return await this.#saasClient
.Get<IDataTaskInstanceState>(
`di-projects/${this.#projectId}/di-tasks/${this.#id}/state`
)
.then((res) => res.data);
}
}
46 changes: 46 additions & 0 deletions src/modules/DiProjectTasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { QlikSaaSClient } from "qlik-rest-api";
import { DiProjectTask, IDiProjectTask } from "./DiProjectTask";

export class DiProjectTasks {
#saasClient: QlikSaaSClient;
#projectId: string;
constructor(saasClient: QlikSaaSClient, projectId: string) {
this.#saasClient = saasClient;
this.#projectId = projectId;
}

/**
* Returns instance of single data integration task
*/
async get(arg: { id: string; projectId: string }) {
if (!arg.id)
throw new Error(`diProjectTasks.get: "id" parameter is required`);
if (!arg.projectId)
throw new Error(
`diProjectTasks.projectId: "projectId" parameter is required`
);

const diTask: DiProjectTask = new DiProjectTask(
this.#saasClient,
arg.id,
arg.projectId
);
await diTask.init();

return diTask;
}

/**
* Returns instances list of data integrations tasks
*/
async getAll() {
return await this.#saasClient
.Get<IDiProjectTask[]>(`di-projects/${this.#projectId}/di-tasks?limit=50`)
.then((res) => res.data)
.then((data) =>
data.map(
(t) => new DiProjectTask(this.#saasClient, t.id, this.#projectId, t)
)
);
}
}
33 changes: 33 additions & 0 deletions src/modules/DiProjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { QlikSaaSClient } from "qlik-rest-api";
import { DiProject, IDiProject } from "./DiProject";

export class DiProjects {
#saasClient: QlikSaaSClient;
constructor(saasClient: QlikSaaSClient) {
this.#saasClient = saasClient;
}

/**
* Returns instance of single data integration project
*/
async get(arg: { id: string }) {
if (!arg.id) throw new Error(`diProjects.get: "id" parameter is required`);

const di: DiProject = new DiProject(this.#saasClient, arg.id);
await di.init();

return di;
}

/**
* Returns a list of data integrations as an instance
*/
async getAll() {
return await this.#saasClient
.Get<IDiProject[]>(`di-projects?limit=50`)
.then((res) => res.data)
.then((data) =>
data.map((t) => new DiProject(this.#saasClient, t.id, t))
);
}
}

0 comments on commit 192834b

Please sign in to comment.