@openinc/parse-server-opendash 2.4.89 → 2.4.91

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.
Files changed (78) hide show
  1. package/dist/app_types/ConfigKeys.d.ts +9 -0
  2. package/dist/app_types/ConfigKeys.js +14 -0
  3. package/dist/app_types/Notifications.d.ts +10 -0
  4. package/dist/app_types/Notifications.js +16 -0
  5. package/dist/app_types/Permissions.d.ts +42 -0
  6. package/dist/app_types/Permissions.js +61 -0
  7. package/dist/app_types/index.d.ts +3 -0
  8. package/dist/app_types/index.js +9 -0
  9. package/dist/featuremap.json +7 -5
  10. package/dist/functions/openinc-deregister-permission.js +2 -2
  11. package/dist/functions/openinc-openservice-save-ticket-data.d.ts +40 -0
  12. package/dist/functions/openinc-openservice-save-ticket-data.js +328 -0
  13. package/dist/functions/openinc-openservice-ticket-data.js +17 -74
  14. package/dist/functions/openinc-register-permission.js +1 -1
  15. package/dist/functions/openinc-user-roles.js +1 -1
  16. package/dist/helper/TicketData.d.ts +15 -0
  17. package/dist/helper/TicketData.js +2 -0
  18. package/dist/helper/pdf2img.d.ts +4 -1
  19. package/dist/helper/pdf2img.js +151 -104
  20. package/dist/helper/registerNotification.d.ts +25 -0
  21. package/dist/helper/registerNotification.js +61 -0
  22. package/dist/helper/registerPermissions.d.ts +0 -41
  23. package/dist/helper/registerPermissions.js +5 -61
  24. package/dist/hooks/Assets.js +17 -0
  25. package/dist/hooks/Documentation_Category.d.ts +1 -0
  26. package/dist/hooks/Documentation_Category.js +17 -0
  27. package/dist/hooks/Documentation_Document.d.ts +1 -0
  28. package/dist/hooks/Documentation_Document.js +17 -0
  29. package/dist/hooks/Knowledge_Document.js +35 -2
  30. package/dist/hooks/Maintenance_Message.js +12 -6
  31. package/dist/hooks/Maintenance_Message_Body.js +11 -2
  32. package/dist/hooks/Maintenance_Schedule_Execution.js +4 -4
  33. package/dist/hooks/Maintenance_Schedule_Template.js +19 -8
  34. package/dist/hooks/Maintenance_Ticket.js +1 -4
  35. package/dist/hooks/Maintenance_Ticket_Kanban_State_Current.js +1 -1
  36. package/dist/hooks/Notification_Setting.d.ts +1 -0
  37. package/dist/hooks/Notification_Setting.js +55 -0
  38. package/dist/hooks/User_Setting.d.ts +1 -0
  39. package/dist/hooks/User_Setting.js +17 -0
  40. package/dist/hooks/_User.js +0 -12
  41. package/dist/index.js +12 -0
  42. package/dist/jobs/open_service_notifyOnSchedule.js +125 -19
  43. package/dist/types/Assets.d.ts +27 -0
  44. package/dist/types/Assets.js +41 -0
  45. package/dist/types/Documentation_Category.d.ts +3 -0
  46. package/dist/types/Documentation_Category.js +6 -0
  47. package/dist/types/Documentation_Document.d.ts +3 -6
  48. package/dist/types/Documentation_Document.js +4 -10
  49. package/dist/types/Knowledge_Document.d.ts +3 -0
  50. package/dist/types/Knowledge_Document.js +6 -0
  51. package/dist/types/Maintenance_Message.d.ts +9 -0
  52. package/dist/types/Maintenance_Message.js +15 -0
  53. package/dist/types/Maintenance_Message_Body.d.ts +3 -0
  54. package/dist/types/Maintenance_Message_Body.js +6 -0
  55. package/dist/types/Maintenance_Schedule_Execution.d.ts +3 -0
  56. package/dist/types/Maintenance_Schedule_Execution.js +6 -0
  57. package/dist/types/Notification_Setting.d.ts +29 -0
  58. package/dist/types/Notification_Setting.js +41 -0
  59. package/dist/types/User_Setting.d.ts +13 -0
  60. package/dist/types/User_Setting.js +17 -0
  61. package/dist/types/_User.d.ts +2 -0
  62. package/dist/types/index.d.ts +6 -2
  63. package/dist/types/index.js +8 -4
  64. package/package.json +4 -4
  65. package/schema/Assets.json +52 -0
  66. package/schema/Documentation_Category.json +4 -0
  67. package/schema/Documentation_Document.json +3 -9
  68. package/schema/Knowledge_Document.json +5 -0
  69. package/schema/Maintenance_Message.json +13 -0
  70. package/schema/Maintenance_Message_Body.json +4 -0
  71. package/schema/Maintenance_Schedule_Execution.json +4 -0
  72. package/schema/Notification_Setting.json +57 -0
  73. package/schema/User_Setting.json +35 -0
  74. package/dist/hooks/Group.js +0 -55
  75. package/dist/types/Group.d.ts +0 -31
  76. package/dist/types/Group.js +0 -47
  77. package/schema/Group.json +0 -62
  78. /package/dist/hooks/{Group.d.ts → Assets.d.ts} +0 -0
@@ -9,7 +9,7 @@ async function init(name) {
9
9
  });
10
10
  }
11
11
  async function handleRequest(request) {
12
- if (typeof request.user === "undefined") {
12
+ if (request.user === undefined) {
13
13
  return { success: false, error: "User not found" };
14
14
  }
15
15
  console.log("openinc-openservice-ticket-data: Handling request with", request.params);
@@ -49,14 +49,16 @@ async function handleRequest(request) {
49
49
  }
50
50
  }
51
51
  // get total count of tickets before applying pagination
52
- const totalCount = await ticketQuery.count({ useMasterKey: true });
52
+ const totalCount = await ticketQuery.count({
53
+ sessionToken: request.user.getSessionToken(),
54
+ });
53
55
  if (request.params.config[0].skip !== undefined &&
54
56
  request.params.config[0].limit !== undefined) {
55
57
  ticketQuery = ticketQuery
56
58
  .skip(request.params.config[0].skip)
57
59
  .limit(request.params.config[0].limit);
58
60
  }
59
- const [ticketError, ticketsResult] = await (0, catchError_1.catchError)(ticketQuery.find({ useMasterKey: true }));
61
+ const [ticketError, ticketsResult] = await (0, catchError_1.catchError)(ticketQuery.find({ sessionToken: request.user.getSessionToken() }));
60
62
  if (ticketError) {
61
63
  throw ticketError;
62
64
  }
@@ -80,12 +82,12 @@ async function getTicketData(tickets) {
80
82
  const ticketDataPromises = tickets.map(async (ticket) => {
81
83
  let assignedusers = [];
82
84
  let assignedroles = [];
83
- if (typeof ticket.assignedusers !== "undefined") {
85
+ if (ticket.assignedusers !== undefined) {
84
86
  assignedusers = await ticket.assignedusers
85
87
  .query()
86
88
  .find({ useMasterKey: true });
87
89
  }
88
- if (typeof ticket.assignedroles !== "undefined") {
90
+ if (ticket.assignedroles !== undefined) {
89
91
  assignedroles = await ticket.assignedroles
90
92
  .query()
91
93
  .find({ useMasterKey: true });
@@ -124,7 +126,6 @@ async function getTicketData(tickets) {
124
126
  state: dataPromises[7]?.get("state"),
125
127
  dailySchedule: dataPromises[8],
126
128
  messages: dataPromises[9].messages,
127
- messageBodies: dataPromises[9].messageBodies,
128
129
  assignedTo: [...assignedusers, ...assignedroles],
129
130
  };
130
131
  });
@@ -157,12 +158,7 @@ async function getDueDate(ticket) {
157
158
  return await new Parse.Query(types_1.Maintenance_Duedate)
158
159
  .descending("updatedAt")
159
160
  .equalTo("ticket", ticket)
160
- // .containedIn("ticket", ticketIds)
161
- // .limit(1_000_000)
162
161
  .first({ useMasterKey: true });
163
- // .filter((duedate) => duedate.get("ticket").id === ticket.id, {
164
- // useMasterKey: true,
165
- // });
166
162
  }
167
163
  /**
168
164
  * Fetches the frequency for a ticket
@@ -173,12 +169,7 @@ async function getFrequency(ticket) {
173
169
  return await new Parse.Query(types_1.Maintenance_Frequency)
174
170
  .descending("updatedAt")
175
171
  .equalTo("ticket", ticket)
176
- // .containedIn("ticket", ticketIds)
177
- // .limit(1_000_000)
178
172
  .first({ useMasterKey: true });
179
- // .filter((frequency) => frequency.get("ticket").id === ticket.id, {
180
- // useMasterKey: true,
181
- // });
182
173
  }
183
174
  /**
184
175
  * Fetches the restriction for a ticket
@@ -189,12 +180,7 @@ async function getRestriction(ticket) {
189
180
  return await new Parse.Query(types_1.Maintenance_Restriction)
190
181
  .descending("updatedAt")
191
182
  .equalTo("ticket", ticket)
192
- // .containedIn("ticket", ticketIds)
193
- // .limit(1_000_000)
194
183
  .first({ useMasterKey: true });
195
- // .filter((restriction) => restriction.get("ticket").id === ticket.id, {
196
- // useMasterKey: true,
197
- // });
198
184
  }
199
185
  /**
200
186
  * Fetches the priority for a ticket
@@ -206,13 +192,8 @@ async function getPriority(ticket) {
206
192
  return await new Parse.Query(types_1.Maintenance_Priority)
207
193
  .descending("updatedAt")
208
194
  .equalTo("ticket", ticket)
209
- // .containedIn("ticket", ticketIds)
210
- // .limit(1_000_000)
211
195
  .equalTo("ticket", ticket)
212
196
  .first({ useMasterKey: true });
213
- // .filter((priority) => priority.get("ticket").id === ticket.id, {
214
- // useMasterKey: true,
215
- // });
216
197
  }
217
198
  /**
218
199
  * Fetches the state for a ticket
@@ -223,14 +204,8 @@ async function getState(ticket) {
223
204
  return await new Parse.Query(types_1.Maintenance_Ticket_Kanban_State_Current)
224
205
  .descending("updatedAt")
225
206
  .includeAll()
226
- .matchesQuery("ticket", new Parse.Query(types_1.Maintenance_Ticket).equalTo("objectId", ticket.id)
227
- // .containedIn("objectId", ticketIds)
228
- )
229
- // .limit(1_000_000)
207
+ .matchesQuery("ticket", new Parse.Query(types_1.Maintenance_Ticket).equalTo("objectId", ticket.id))
230
208
  .first({ useMasterKey: true });
231
- // .filter((ts) => ts.get("ticket")?.id === ticket.id, {
232
- // useMasterKey: true,
233
- // });
234
209
  }
235
210
  /**
236
211
  * Fetches the messages for a ticket
@@ -238,23 +213,11 @@ async function getState(ticket) {
238
213
  * @param ticketIds
239
214
  */
240
215
  async function getMessages(ticket) {
241
- const messageBodies = await new Parse.Query(types_1.Maintenance_Message_Body)
242
- .include("message")
243
- .matchesQuery("message", new Parse.Query(types_1.Maintenance_Message)
216
+ const messages = await new Parse.Query(types_1.Maintenance_Message)
244
217
  .descending("updatedAt")
245
218
  .equalTo("referencedObjectId", ticket.id)
246
- // .containedIn("referencedObjectId", ticketIds)
247
- // .limit(1_000_000)
248
- )
249
- .limit(1000000)
250
219
  .find({ useMasterKey: true });
251
- const messages = messageBodies
252
- .map((msgB) => msgB.message)
253
- .filter((msg) => !!msg);
254
- return {
255
- messages: messages.filter((msg) => msg?.get("referencedObjectId") === ticket.id),
256
- messageBodies: messageBodies.filter((msgB) => messages?.some((msg) => msg.id === msgB.get("message")?.id)),
257
- };
220
+ return { messages };
258
221
  }
259
222
  /**
260
223
  * Fetches the issuecategory for a ticket
@@ -267,12 +230,7 @@ async function getIssueCategory(ticket) {
267
230
  .includeAll()
268
231
  .descending("updatedAt")
269
232
  .equalTo("ticket", ticket)
270
- // .containedIn("ticket", ticketIds)
271
- // .limit(1_000_000)
272
233
  .first({ useMasterKey: true });
273
- // .filter((issuecategory) => issuecategory.get("ticket").id === ticket.id, {
274
- // useMasterKey: true,
275
- // });
276
234
  }
277
235
  /**
278
236
  * Fetches the source for a ticket
@@ -284,12 +242,7 @@ async function getTicketSource(ticket) {
284
242
  .includeAll()
285
243
  .descending("updatedAt")
286
244
  .equalTo("ticket", ticket)
287
- // .containedIn("ticket", ticketIds)
288
- // .limit(1_000_000)
289
245
  .first({ useMasterKey: true });
290
- // .filter((source) => source.get("ticket").id === ticket.id, {
291
- // useMasterKey: true,
292
- // });
293
246
  }
294
247
  /**
295
248
  * Fetches the daily schedule for a ticket
@@ -299,9 +252,7 @@ async function getTicketSource(ticket) {
299
252
  async function getDailySchedule(ticket) {
300
253
  const schedules = await new Parse.Query(types_1.Maintenance_DailySchedule)
301
254
  .include("tickets")
302
- .matchesQuery("tickets", new Parse.Query(types_1.Maintenance_DailySchedule).matchesQuery("tickets", new Parse.Query(types_1.Maintenance_Ticket).equalTo("objectId", ticket.id)
303
- // .containedIn("objectId", ticketIds)
304
- ))
255
+ .matchesQuery("tickets", new Parse.Query(types_1.Maintenance_DailySchedule).matchesQuery("tickets", new Parse.Query(types_1.Maintenance_Ticket).equalTo("objectId", ticket.id)))
305
256
  .limit(1000000)
306
257
  .find({ useMasterKey: true });
307
258
  const scheduleTickets = await Promise.all(schedules.map(async (schedule) => {
@@ -313,7 +264,7 @@ async function getDailySchedule(ticket) {
313
264
  .find({ useMasterKey: true }),
314
265
  };
315
266
  }));
316
- return scheduleTickets.find((scheduleTicket) => scheduleTicket.tickets.some((ticket) => ticket.id === ticket.id))?.schedule;
267
+ return scheduleTickets.find((scheduleTicket) => scheduleTicket.tickets.some((t) => t.id === ticket.id))?.schedule;
317
268
  }
318
269
  /**
319
270
  * Used to filter tickets based on the filterBy attribute
@@ -333,9 +284,9 @@ const filterQueryMap = {
333
284
  .matchesQuery("ticket", query)
334
285
  .includeAll()
335
286
  .find({ useMasterKey: true });
336
- const filteredTicketSources = arrayToDistinct(allTicketSources, (ts) => ts.get("ticket").id, (ts) => ts.get("source").id === value);
287
+ const filteredTicketSources = arrayToDistinct(allTicketSources, (ts) => ts?.get("ticket")?.id, (ts) => ts?.get("source")?.id === value);
337
288
  // @ts-ignore
338
- query.containedIn("objectId", filteredTicketSources.map((ts) => ts.get("ticket").id));
289
+ query.containedIn("objectId", filteredTicketSources.map((ts) => ts.get("ticket")?.id));
339
290
  },
340
291
  issuecategory: async (query, value) => {
341
292
  const ticketIssuecategories = await new Parse.Query(types_1.Maintenance_Ticket_Issuecategory)
@@ -343,9 +294,10 @@ const filterQueryMap = {
343
294
  .descending("createdAt")
344
295
  .includeAll()
345
296
  .find({ useMasterKey: true });
346
- const filteredTicketIssuecategories = arrayToDistinct(ticketIssuecategories, (tic) => tic.get("ticket").id, (tic) => tic.get("issuecategory").id === value);
297
+ const filteredTicketIssuecategories = arrayToDistinct(ticketIssuecategories, (tic) => tic.get("ticket")?.id, (tic) => tic.get("issuecategory")?.id === value &&
298
+ tic.get("ticket")?.id !== undefined);
347
299
  // @ts-ignore
348
- query.containedIn("objectId", filteredTicketIssuecategories.map((tic) => tic.get("ticket").id));
300
+ query.containedIn("objectId", filteredTicketIssuecategories.map((tic) => tic.get("ticket")?.id));
349
301
  },
350
302
  user: async (query, value) => {
351
303
  const userQuery = new Parse.Query(Parse.User).equalTo("objectId", value);
@@ -380,12 +332,3 @@ function arrayToDistinct(arr, getId, filter) {
380
332
  const array = Array.from(map.values());
381
333
  return filter ? array.filter(filter) : array;
382
334
  }
383
- function findSortByValue(sortBy, obj) {
384
- if (!sortBy)
385
- return "";
386
- const keyChain = sortBy.split(".");
387
- let currentValue = obj;
388
- for (const key of keyChain)
389
- currentValue = currentValue[key];
390
- return currentValue;
391
- }
@@ -8,7 +8,7 @@ const types_1 = require("../types");
8
8
  */
9
9
  async function init(name) {
10
10
  Parse.Cloud.define(name, async function (request) {
11
- if (typeof request.user === "undefined") {
11
+ if (request.user === undefined) {
12
12
  return { success: false, error: "User is not provided." };
13
13
  }
14
14
  //Get the current user
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  async function init(name) {
5
5
  Parse.Cloud.define(name, async function (request) {
6
- if (typeof request.user === "undefined") {
6
+ if (request.user === undefined) {
7
7
  return { success: false, error: "User not found" };
8
8
  }
9
9
  const user = await new Parse.Query(Parse.User).get(request.user.id, {
@@ -0,0 +1,15 @@
1
+ import { Maintenance_Ticket, Maintenance_DailySchedule, Maintenance_Downtime, Maintenance_Duedate, Maintenance_Frequency, Maintenance_Issuecategory, Maintenance_Kanban_State, Maintenance_Message, Maintenance_Priority, Maintenance_Restriction, Source } from "../types";
2
+ export type TicketData = {
3
+ ticket: Maintenance_Ticket;
4
+ dailySchedule?: Maintenance_DailySchedule;
5
+ downtime?: Maintenance_Downtime;
6
+ duedate?: Maintenance_Duedate;
7
+ frequency?: Maintenance_Frequency;
8
+ issuecategory?: Maintenance_Issuecategory;
9
+ state?: Maintenance_Kanban_State;
10
+ messages?: Maintenance_Message[];
11
+ priority?: Maintenance_Priority;
12
+ restriction?: Maintenance_Restriction;
13
+ source?: Source;
14
+ assignedTo?: Array<Parse.User | Parse.Role>;
15
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -8,5 +8,8 @@ interface Options {
8
8
  /** Output as base64 */
9
9
  base64?: boolean;
10
10
  }
11
- export declare function convert(pdf: string, conversion_config?: Options): Promise<any[]>;
11
+ /**
12
+ * @deprecated This should be deleted as pdf-img-converter can be used directly
13
+ */
14
+ export declare function convert(pdf: string, conversion_config?: Options): Promise<string[] | Uint8Array<ArrayBufferLike>[]>;
12
15
  export {};
@@ -1,110 +1,157 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.convert = convert;
8
2
  // Fork of: https://www.npmjs.com/package/pdf-img-convert
9
3
  // node_modules/pdf-img-convert/pdf-img-convert.js
10
- const node_fetch_1 = __importDefault(require("node-fetch"));
11
- const strict_1 = __importDefault(require("assert/strict"));
12
- // import pdfjs from "pdfjs-dist/legacy/build/pdf.js";
13
- // import Canvas from "canvas";
14
- // Somehow the import does not work
15
- const pdfjs = require("pdfjs-dist/legacy/build/pdf.js");
16
- const Canvas = require("canvas");
17
- function NodeCanvasFactory() { }
18
- NodeCanvasFactory.prototype = {
19
- create: function NodeCanvasFactory_create(width, height) {
20
- (0, strict_1.default)(width > 0 && height > 0, "Invalid canvas size");
21
- var canvas = Canvas.createCanvas(width, height);
22
- var context = canvas.getContext("2d");
23
- return {
24
- canvas: canvas,
25
- context: context,
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
26
  };
27
- },
28
- reset: function NodeCanvasFactory_reset(canvasAndContext, width, height) {
29
- (0, strict_1.default)(canvasAndContext.canvas, "Canvas is not specified");
30
- (0, strict_1.default)(width > 0 && height > 0, "Invalid canvas size");
31
- canvasAndContext.canvas.width = width;
32
- canvasAndContext.canvas.height = height;
33
- },
34
- destroy: function NodeCanvasFactory_destroy(canvasAndContext) {
35
- (0, strict_1.default)(canvasAndContext.canvas, "Canvas is not specified");
36
- // Zeroing the width and height cause Firefox to release graphics
37
- // resources immediately, which can greatly reduce memory consumption.
38
- canvasAndContext.canvas.width = 0;
39
- canvasAndContext.canvas.height = 0;
40
- canvasAndContext.canvas = null;
41
- canvasAndContext.context = null;
42
- },
43
- };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.convert = convert;
39
+ // class NodeCanvasFactory {
40
+ // constructor() {}
41
+ // create(width: number, height: number) {
42
+ // assert(width > 0 && height > 0, "Invalid canvas size");
43
+ // var canvas = Canvas.createCanvas(width, height);
44
+ // var context = canvas.getContext("2d");
45
+ // return {
46
+ // canvas: canvas,
47
+ // context: context,
48
+ // };
49
+ // }
50
+ // reset(canvasAndContext: any, width: number, height: number) {
51
+ // assert(canvasAndContext.canvas, "Canvas is not specified");
52
+ // assert(width > 0 && height > 0, "Invalid canvas size");
53
+ // canvasAndContext.canvas.width = width;
54
+ // canvasAndContext.canvas.height = height;
55
+ // }
56
+ // destroy(canvasAndContext: any) {
57
+ // assert(canvasAndContext.canvas, "Canvas is not specified");
58
+ // // Zeroing the width and height cause Firefox to release graphics
59
+ // // resources immediately, which can greatly reduce memory consumption.
60
+ // canvasAndContext.canvas.width = 0;
61
+ // canvasAndContext.canvas.height = 0;
62
+ // canvasAndContext.canvas = null;
63
+ // canvasAndContext.context = null;
64
+ // }
65
+ // }
66
+ /**
67
+ * @deprecated This should be deleted as pdf-img-converter can be used directly
68
+ */
44
69
  async function convert(pdf, conversion_config = {}) {
45
- // Get the PDF in Uint8Array form
46
- const resp = await (0, node_fetch_1.default)(pdf);
47
- const pdfData = new Uint8Array(await resp.arrayBuffer());
48
- var outputPages = [];
49
- var loadingTask = pdfjs.getDocument({ data: pdfData, verbosity: 0 });
50
- var pdfDocument = await loadingTask.promise;
51
- var canvasFactory = new NodeCanvasFactory();
52
- if (conversion_config.height <= 0 || conversion_config.width <= 0)
53
- console.error("Negative viewport dimension given. Defaulting to 100% scale.");
54
- // If there are page numbers supplied in the conversion config
55
- if (conversion_config.page_numbers)
56
- for (let i = 0; i < conversion_config.page_numbers.length; i++) {
57
- // This just pushes a render of the page to the array
58
- let currentPage = await doc_render(pdfDocument, conversion_config.page_numbers[i], canvasFactory, conversion_config);
59
- if (currentPage != null) {
60
- // This allows for base64 conversion of output images
61
- if (conversion_config.base64)
62
- outputPages.push(currentPage.toString("base64"));
63
- else
64
- outputPages.push(new Uint8Array(currentPage));
65
- }
66
- }
67
- // Otherwise just loop the whole doc
68
- else
69
- for (let i = 1; i <= pdfDocument.numPages; i++) {
70
- let currentPage = await doc_render(pdfDocument, i, canvasFactory, conversion_config);
71
- if (currentPage != null) {
72
- // This allows for base64 conversion of output images
73
- if (conversion_config.base64)
74
- outputPages.push(currentPage.toString("base64"));
75
- else
76
- outputPages.push(new Uint8Array(currentPage));
77
- }
78
- }
79
- return outputPages;
70
+ const pdf2img = await Promise.resolve().then(() => __importStar(require("pdf-img-convert")));
71
+ const output = await pdf2img.convert(pdf, {
72
+ base64: conversion_config.base64,
73
+ width: conversion_config.width,
74
+ height: conversion_config.height,
75
+ page_numbers: conversion_config.page_numbers,
76
+ });
77
+ return output;
78
+ // const resp = await fetch(pdf);
79
+ // const pdfData = new Uint8Array(await resp.arrayBuffer());
80
+ // var outputPages = [];
81
+ // var loadingTask = pdfjs.getDocument({ data: pdfData, verbosity: 0 });
82
+ // var pdfDocument = await loadingTask.promise;
83
+ // var canvasFactory = new NodeCanvasFactory();
84
+ // if (conversion_config.height <= 0 || conversion_config.width <= 0)
85
+ // console.error(
86
+ // "Negative viewport dimension given. Defaulting to 100% scale."
87
+ // );
88
+ // // If there are page numbers supplied in the conversion config
89
+ // if (conversion_config.page_numbers)
90
+ // for (let i = 0; i < conversion_config.page_numbers.length; i++) {
91
+ // // This just pushes a render of the page to the array
92
+ // let currentPage = await doc_render(
93
+ // pdfDocument,
94
+ // conversion_config.page_numbers[i],
95
+ // canvasFactory,
96
+ // conversion_config
97
+ // );
98
+ // if (currentPage != null) {
99
+ // // This allows for base64 conversion of output images
100
+ // if (conversion_config.base64)
101
+ // outputPages.push(currentPage.toString("base64"));
102
+ // else outputPages.push(new Uint8Array(currentPage));
103
+ // }
104
+ // }
105
+ // // Otherwise just loop the whole doc
106
+ // else
107
+ // for (let i = 1; i <= pdfDocument.numPages; i++) {
108
+ // let currentPage = await doc_render(
109
+ // pdfDocument,
110
+ // i,
111
+ // canvasFactory,
112
+ // conversion_config
113
+ // );
114
+ // if (currentPage != null) {
115
+ // // This allows for base64 conversion of output images
116
+ // if (conversion_config.base64)
117
+ // outputPages.push(currentPage.toString("base64"));
118
+ // else outputPages.push(new Uint8Array(currentPage));
119
+ // }
120
+ // }
121
+ // return outputPages;
80
122
  } // convert method
81
- async function doc_render(pdfDocument, pageNo, canvasFactory, conversion_config) {
82
- // Page number sanity check
83
- if (pageNo < 1 || pageNo > pdfDocument.numPages) {
84
- console.error("Invalid page number " + pageNo);
85
- return;
86
- }
87
- // Get the page
88
- let page = await pdfDocument.getPage(pageNo);
89
- // Create a viewport at 100% scale
90
- let outputScale = 1.0;
91
- let viewport = page.getViewport({ scale: outputScale });
92
- // Scale it up / down dependent on the sizes given in the config (if there
93
- // are any)
94
- if (conversion_config.width)
95
- outputScale = conversion_config.width / viewport.width;
96
- else if (conversion_config.height)
97
- outputScale = conversion_config.height / viewport.height;
98
- if (outputScale != 1 && outputScale > 0)
99
- viewport = page.getViewport({ scale: outputScale });
100
- let canvasAndContext = canvasFactory.create(viewport.width, viewport.height);
101
- let renderContext = {
102
- canvasContext: canvasAndContext.context,
103
- viewport: viewport,
104
- canvasFactory: canvasFactory,
105
- };
106
- let renderTask = await page.render(renderContext).promise;
107
- // Convert the canvas to an image buffer.
108
- let image = canvasAndContext.canvas.toBuffer();
109
- return image;
110
- } // doc_render
123
+ // async function doc_render(
124
+ // pdfDocument: PDFDocumentProxy,
125
+ // pageNo: number,
126
+ // canvasFactory: { create: (arg0: any, arg1: any) => any },
127
+ // conversion_config: Options
128
+ // ) {
129
+ // // Page number sanity check
130
+ // if (pageNo < 1 || pageNo > pdfDocument.numPages) {
131
+ // console.error("Invalid page number " + pageNo);
132
+ // return;
133
+ // }
134
+ // // Get the page
135
+ // let page = await pdfDocument.getPage(pageNo);
136
+ // // Create a viewport at 100% scale
137
+ // let outputScale = 1.0;
138
+ // let viewport = page.getViewport({ scale: outputScale });
139
+ // // Scale it up / down dependent on the sizes given in the config (if there
140
+ // // are any)
141
+ // if (conversion_config.width)
142
+ // outputScale = conversion_config.width / viewport.width;
143
+ // else if (conversion_config.height)
144
+ // outputScale = conversion_config.height / viewport.height;
145
+ // if (outputScale != 1 && outputScale > 0)
146
+ // viewport = page.getViewport({ scale: outputScale });
147
+ // let canvasAndContext = canvasFactory.create(viewport.width, viewport.height);
148
+ // let renderContext = {
149
+ // canvasContext: canvasAndContext.context,
150
+ // viewport: viewport,
151
+ // canvasFactory: canvasFactory,
152
+ // };
153
+ // let renderTask = await page.render(renderContext).promise;
154
+ // // Convert the canvas to an image buffer.
155
+ // let image = canvasAndContext.canvas.toBuffer();
156
+ // return image;
157
+ // } // doc_render
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Gets all registered notifications.
3
+ */
4
+ /**
5
+ * Returns all notifications from the OpenService plugin defined in types/config.ts as an array of Notification objects.
6
+ * @returns all notifications from the OpenService plugin
7
+ */
8
+ export declare function getAllNotifications(): RegisteredNotification[];
9
+ interface NotificationInterface {
10
+ label: string;
11
+ description: string;
12
+ key: string;
13
+ }
14
+ type FunctionKeys<T> = {
15
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
16
+ }[keyof T];
17
+ export declare class RegisteredNotification implements NotificationInterface {
18
+ key: string;
19
+ label: string;
20
+ description: string;
21
+ constructor(key: string, label: string, description: string);
22
+ get<T extends Exclude<keyof RegisteredNotification, FunctionKeys<RegisteredNotification>>>(attribute: T): (typeof this)[T];
23
+ set<T extends Exclude<keyof RegisteredNotification, FunctionKeys<RegisteredNotification>>>(attribute: T, value: (typeof this)[T]): this;
24
+ }
25
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * Gets all registered notifications.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RegisteredNotification = void 0;
7
+ exports.getAllNotifications = getAllNotifications;
8
+ const index_js_1 = require("../app_types/index.js");
9
+ /**
10
+ * Returns all notifications from the OpenService plugin defined in types/config.ts as an array of Notification objects.
11
+ * @returns all notifications from the OpenService plugin
12
+ */
13
+ function getAllNotifications() {
14
+ const notifications = []; // stores all notifications
15
+ for (const key in index_js_1.Notifications) {
16
+ // iterate over the objects / enums of the Notifications namespace
17
+ if (Object.prototype.hasOwnProperty.call(index_js_1.Notifications, key)) {
18
+ const element = index_js_1.Notifications[key]; // get the object / enum
19
+ const createdNotification = createNotification(element); // create Notification objects recursively
20
+ notifications.push(...createdNotification);
21
+ }
22
+ }
23
+ return notifications;
24
+ }
25
+ class RegisteredNotification {
26
+ constructor(key, label, description) {
27
+ this.key = key;
28
+ this.label = label;
29
+ this.description = description;
30
+ }
31
+ get(attribute) {
32
+ return this[attribute];
33
+ }
34
+ set(attribute, value) {
35
+ this[attribute] = value;
36
+ return this;
37
+ }
38
+ }
39
+ exports.RegisteredNotification = RegisteredNotification;
40
+ /**
41
+ * Recursively creates Notification objects from the input object.
42
+ * @param input a string from an enum or an enum itself
43
+ * @returns an array of Notification objects
44
+ */
45
+ function createNotification(input) {
46
+ const notifications = []; // all notification objects created from the input
47
+ if (typeof input === "string") {
48
+ // if the input is a string, create a Notification object from it
49
+ notifications.push(new RegisteredNotification(input, input + ".label", input + ".description"));
50
+ }
51
+ else {
52
+ // if the input is an object, iterate over its keys and create Notification objects from the values
53
+ for (const key in input) {
54
+ if (Object.prototype.hasOwnProperty.call(input, key)) {
55
+ const element = input[key];
56
+ notifications.push(...createNotification(element));
57
+ }
58
+ }
59
+ }
60
+ return notifications;
61
+ }