@nu-art/bug-report-backend 0.400.7

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 @@
1
+ export declare const ModulePack_Backend_BugReport: (import("../modules/ModuleBE_BugReport.js").ModuleBE_BugReport_Class | import("../modules/ModuleBE_AdminBR.js").ModuleBE_AdminBR_Class | import("../modules/JiraBugReportIntegrator.js").JiraBugReportIntegrator_Class | import("@nu-art/slack-backend").ModuleBE_Slack_Class | import("../modules/SlackBugReportIntegrator.js").SlackBugReportIntegrator_Class)[];
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Allow the user to file a bug report directly from your app
3
+ *
4
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ import { ModuleBE_BugReport } from '../modules/ModuleBE_BugReport.js';
19
+ import { ModuleBE_AdminBR } from '../modules/ModuleBE_AdminBR.js';
20
+ import { JiraBugReportIntegrator } from '../modules/JiraBugReportIntegrator.js';
21
+ // import {JiraModule} from '@nu-art/jira-backend';
22
+ import { SlackBugReportIntegrator } from '../modules/SlackBugReportIntegrator.js';
23
+ import { ModuleBE_Slack } from '@nu-art/slack-backend';
24
+ export const ModulePack_Backend_BugReport = [
25
+ ModuleBE_BugReport,
26
+ ModuleBE_AdminBR,
27
+ JiraBugReportIntegrator,
28
+ // JiraModule,
29
+ SlackBugReportIntegrator,
30
+ ModuleBE_Slack
31
+ ];
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './core/module-pack.js';
2
+ export * from './modules/ModuleBE_AdminBR.js';
3
+ export * from './modules/ModuleBE_BugReport.js';
4
+ export * from './modules/JiraBugReportIntegrator.js';
5
+ export * from './modules/SlackBugReportIntegrator.js';
package/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ export * from './core/module-pack.js';
20
+ export * from './modules/ModuleBE_AdminBR.js';
21
+ export * from './modules/ModuleBE_BugReport.js';
22
+ export * from './modules/JiraBugReportIntegrator.js';
23
+ export * from './modules/SlackBugReportIntegrator.js';
@@ -0,0 +1,15 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ import { IssueType, JiraProject, LabelType } from '@nu-art/jira-backend';
3
+ import { ReportLogFile, Request_BugReport, TicketDetails } from '@nu-art/bug-report-shared';
4
+ type Config = {
5
+ jiraProject: JiraProject;
6
+ issueType: IssueType;
7
+ label: LabelType;
8
+ };
9
+ export declare class JiraBugReportIntegrator_Class extends Module<Config> {
10
+ setIssueTitleProcessor(parser: (name: string) => string): void;
11
+ private parser;
12
+ openTicket: (bugReport: Request_BugReport, logs: ReportLogFile[], reporter?: string) => Promise<TicketDetails | undefined>;
13
+ }
14
+ export declare const JiraBugReportIntegrator: JiraBugReportIntegrator_Class;
15
+ export {};
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Allow the user to file a bug report directly from your app
3
+ *
4
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ import { ImplementationMissingException, Module } from '@nu-art/ts-common';
19
+ import { JiraModule } from '@nu-art/jira-backend';
20
+ import { Platform_Jira } from '@nu-art/bug-report-shared';
21
+ export class JiraBugReportIntegrator_Class extends Module {
22
+ setIssueTitleProcessor(parser) {
23
+ this.parser = parser;
24
+ }
25
+ parser = (name) => `Bug: ${name}`;
26
+ openTicket = async (bugReport, logs, reporter) => {
27
+ if (bugReport.platforms && !bugReport.platforms.includes(Platform_Jira))
28
+ return;
29
+ if (!this.config.jiraProject)
30
+ throw new ImplementationMissingException('missing Jira project in bug report configurations');
31
+ const description = logs.reduce((carry, log, i) => {
32
+ carry.push({ href: log.path, text: '\nClick to view logs (' + i + ')' });
33
+ return carry;
34
+ }, [bugReport.description]);
35
+ if (reporter)
36
+ description.push('\nReported by: ' + reporter);
37
+ const issue = await JiraModule.issue.create(this.config.jiraProject, this.config.issueType, this.parser(bugReport.subject), description, this.config.label.label);
38
+ return { platform: Platform_Jira, issueId: issue.url };
39
+ };
40
+ }
41
+ export const JiraBugReportIntegrator = new JiraBugReportIntegrator_Class();
@@ -0,0 +1,20 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ import { DB_BugReport, Paths } from '@nu-art/bug-report-shared/api';
3
+ type Config = {
4
+ projectId: string;
5
+ bucket?: string;
6
+ };
7
+ export declare class ModuleBE_AdminBR_Class extends Module<Config> {
8
+ private bugReport;
9
+ private storage;
10
+ constructor();
11
+ protected init(): void;
12
+ getFilesFirebase: () => Promise<DB_BugReport[]>;
13
+ downloadFiles: (path: Paths) => Promise<{
14
+ fileName: string;
15
+ signedUrl: string;
16
+ publicUrl: string;
17
+ }>;
18
+ }
19
+ export declare const ModuleBE_AdminBR: ModuleBE_AdminBR_Class;
20
+ export {};
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { Module } from '@nu-art/ts-common';
20
+ import { ApiDef_AdminBugReport } from '@nu-art/bug-report-shared/api';
21
+ import { ModuleBE_Firebase } from '@nu-art/firebase-backend';
22
+ import { addRoutes, createBodyServerApi, createQueryServerApi } from '@nu-art/thunderstorm-backend';
23
+ export class ModuleBE_AdminBR_Class extends Module {
24
+ bugReport;
25
+ storage;
26
+ constructor() {
27
+ super();
28
+ }
29
+ init() {
30
+ super.init();
31
+ const sessAdmin = ModuleBE_Firebase.createAdminSession();
32
+ const firestore = sessAdmin.getFirestore();
33
+ this.bugReport = firestore.getCollection('bug-report', ['_id']);
34
+ this.storage = sessAdmin.getStorage();
35
+ addRoutes([
36
+ createBodyServerApi(ApiDef_AdminBugReport.v1.downloadLogs, ModuleBE_AdminBR.downloadFiles),
37
+ createQueryServerApi(ApiDef_AdminBugReport.v1.retrieveLogs, ModuleBE_AdminBR.getFilesFirebase),
38
+ ]);
39
+ }
40
+ getFilesFirebase = async () => this.bugReport.getAll();
41
+ downloadFiles = async (path) => {
42
+ const bucket = await this.storage.getOrCreateBucket(this.config?.bucket);
43
+ const file = await bucket.getFile(path.path);
44
+ return file.getReadSignedUrl(600000, 'application/zip');
45
+ };
46
+ }
47
+ export const ModuleBE_AdminBR = new ModuleBE_AdminBR_Class();
@@ -0,0 +1,20 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ import { BugReport, ReportLogFile, Request_BugReport, TicketDetails } from '@nu-art/bug-report-shared';
3
+ type Config = {
4
+ projectId?: string;
5
+ bucket?: string;
6
+ };
7
+ type TicketCreatorApi = (bugReport: Request_BugReport, logs: ReportLogFile[], email?: string) => Promise<TicketDetails | undefined>;
8
+ export declare class ModuleBE_BugReport_Class extends Module<Config> {
9
+ private bugReport;
10
+ private storage;
11
+ private ticketCreatorApis;
12
+ constructor();
13
+ protected init(): void;
14
+ private sendBugReport;
15
+ addTicketCreator(ticketCreator: TicketCreatorApi): void;
16
+ saveLog: (report: BugReport, id: string) => Promise<ReportLogFile>;
17
+ saveFile: (bugReport: Request_BugReport, email?: string) => Promise<TicketDetails[]>;
18
+ }
19
+ export declare const ModuleBE_BugReport: ModuleBE_BugReport_Class;
20
+ export {};
@@ -0,0 +1,81 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { addItemToArray, auditBy, currentTimeMillis, filterInstances, generateHex, Module, padNumber } from '@nu-art/ts-common';
20
+ import { ModuleBE_Firebase } from '@nu-art/firebase-backend';
21
+ import { addRoutes, createBodyServerApi } from '@nu-art/thunderstorm-backend';
22
+ import JSZip from 'jszip';
23
+ import { ApiDef_BugReport } from '@nu-art/bug-report-shared';
24
+ import { MemKey_AccountId } from '@nu-art/user-account-backend/_entity/session/index';
25
+ export class ModuleBE_BugReport_Class extends Module {
26
+ bugReport;
27
+ storage;
28
+ ticketCreatorApis = [];
29
+ constructor() {
30
+ super();
31
+ }
32
+ init() {
33
+ const sessionAdmin = ModuleBE_Firebase.createAdminSession();
34
+ const firestore = sessionAdmin.getFirestore();
35
+ this.bugReport = firestore.getCollection('bug-report', ['_id']);
36
+ this.storage = sessionAdmin.getStorage();
37
+ addRoutes([
38
+ createBodyServerApi(ApiDef_BugReport.v1.sendBugReport, (body) => this.sendBugReport(body)),
39
+ ]);
40
+ }
41
+ sendBugReport = async (body) => {
42
+ return await ModuleBE_BugReport.saveFile(body, MemKey_AccountId.get());
43
+ };
44
+ addTicketCreator(ticketCreator) {
45
+ addItemToArray(this.ticketCreatorApis, ticketCreator);
46
+ }
47
+ saveLog = async (report, id) => {
48
+ const zip = new JSZip();
49
+ report.log.forEach((message, i) => zip.file(`${report.name}_${padNumber(i, 2)}.txt`, message));
50
+ const buffer = await zip.generateAsync({ type: 'nodebuffer' });
51
+ const bucket = await this.storage.getOrCreateBucket(this.config?.bucket);
52
+ const fileName = `${id}-${report.name}.zip`;
53
+ const file = await bucket.getFile(fileName);
54
+ await file.write(buffer);
55
+ return {
56
+ path: `https://storage.cloud.google.com/${file.file.metadata.bucket}/${file.file.metadata.name}`,
57
+ name: fileName
58
+ };
59
+ };
60
+ saveFile = async (bugReport, email) => {
61
+ const _id = generateHex(16);
62
+ const logs = await Promise.all(bugReport.reports.map(report => this.saveLog(report, _id)));
63
+ const now = currentTimeMillis();
64
+ const instance = {
65
+ _id,
66
+ __created: now,
67
+ __updated: now,
68
+ subject: bugReport.subject,
69
+ description: bugReport.description,
70
+ reports: logs,
71
+ _audit: auditBy(email || 'bug-report'),
72
+ };
73
+ if (this.config?.bucket)
74
+ instance.bucket = this.config.bucket;
75
+ const tickets = await Promise.all(this.ticketCreatorApis.map(api => api(bugReport, logs, email)));
76
+ instance.tickets = filterInstances(tickets);
77
+ await this.bugReport.insert(instance);
78
+ return instance.tickets;
79
+ };
80
+ }
81
+ export const ModuleBE_BugReport = new ModuleBE_BugReport_Class();
@@ -0,0 +1,10 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ import { ReportLogFile, Request_BugReport, TicketDetails } from '@nu-art/bug-report-shared';
3
+ type Config = {
4
+ channel: string;
5
+ };
6
+ export declare class SlackBugReportIntegrator_Class extends Module<Config> {
7
+ openTicket: (bugReport: Request_BugReport, logs: ReportLogFile[], reporter?: string) => Promise<TicketDetails | undefined>;
8
+ }
9
+ export declare const SlackBugReportIntegrator: SlackBugReportIntegrator_Class;
10
+ export {};
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { generateHex, ImplementationMissingException, Module } from '@nu-art/ts-common';
20
+ import { Platform_Slack } from '@nu-art/bug-report-shared';
21
+ import { ModuleBE_Slack } from '@nu-art/slack-backend';
22
+ export class SlackBugReportIntegrator_Class extends Module {
23
+ openTicket = async (bugReport, logs, reporter) => {
24
+ if (bugReport.platforms && !bugReport.platforms.includes(Platform_Slack))
25
+ return;
26
+ if (!this.config.channel)
27
+ throw new ImplementationMissingException('Missing Slack Channel in bug report configurations');
28
+ let description = logs.reduce((carry, log, i) => {
29
+ return carry + '\n' + `<${log.path}|Click to view logs (${i})>`;
30
+ }, bugReport.subject + '\n' + bugReport.description);
31
+ if (reporter)
32
+ description += '\nReported by: ' + reporter;
33
+ await ModuleBE_Slack.postMessage(description, this.config.channel);
34
+ return { platform: Platform_Slack, issueId: generateHex(32) };
35
+ };
36
+ }
37
+ export const SlackBugReportIntegrator = new SlackBugReportIntegrator_Class();
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@nu-art/bug-report-backend",
3
+ "version": "0.400.7",
4
+ "description": "Bug Report Backend",
5
+ "keywords": [
6
+ "TacB0sS",
7
+ "express",
8
+ "infra",
9
+ "bug-report",
10
+ "nu-art",
11
+ "thunderstorm",
12
+ "typescript"
13
+ ],
14
+ "homepage": "https://github.com/nu-art-js/bug-report",
15
+ "bugs": {
16
+ "url": "https://github.com/nu-art-js/bug-report/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+ssh://git@github.com:nu-art-js/bug-report.git"
21
+ },
22
+ "publishConfig": {
23
+ "directory": "dist",
24
+ "linkDirectory": true
25
+ },
26
+ "license": "Apache-2.0",
27
+ "author": "TacB0sS",
28
+ "scripts": {
29
+ "build": "tsc"
30
+ },
31
+ "dependencies": {
32
+ "@nu-art/bug-report-shared": "0.400.7",
33
+ "@nu-art/firebase-backend": "0.400.7",
34
+ "@nu-art/firebase-shared": "0.400.7",
35
+ "@nu-art/jira-backend": "0.400.7",
36
+ "@nu-art/jira-shared": "0.400.7",
37
+ "@nu-art/slack-backend": "0.400.7",
38
+ "@nu-art/slack-shared": "0.400.7",
39
+ "@nu-art/thunderstorm-backend": "0.400.7",
40
+ "@nu-art/thunderstorm-shared": "0.400.7",
41
+ "@nu-art/ts-common": "0.400.7",
42
+ "@nu-art/user-account-backend": "0.400.7",
43
+ "@nu-art/user-account-shared": "0.400.7",
44
+ "express": "^4.18.2",
45
+ "firebase": "^11.9.0",
46
+ "firebase-admin": "13.4.0",
47
+ "jszip": "^3.3.0",
48
+ "moment": "^2.29.4",
49
+ "react": "^18.0.0",
50
+ "react-dom": "^18.0.0",
51
+ "react-router-dom": "^6.9.0",
52
+ "request": "^2.88.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/express": "^4.17.17",
56
+ "@types/file-saver": "^2.0.1",
57
+ "@types/history": "^4.7.2",
58
+ "@types/jszip": "^3.1.7",
59
+ "@types/react": "^18.0.0",
60
+ "@types/request": "^2.48.1"
61
+ },
62
+ "unitConfig": {
63
+ "type": "typescript-lib"
64
+ },
65
+ "type": "module",
66
+ "exports": {
67
+ ".": {
68
+ "types": "./index.d.ts",
69
+ "import": "./index.js"
70
+ },
71
+ "./*": {
72
+ "types": "./*.d.ts",
73
+ "import": "./*.js"
74
+ }
75
+ }
76
+ }