@orchesty/connector-slack 1.0.0

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,210 @@
1
+ /* eslint-disable */
2
+ var addSorting = (function() {
3
+ 'use strict';
4
+ var cols,
5
+ currentSort = {
6
+ index: 0,
7
+ desc: false
8
+ };
9
+
10
+ // returns the summary table element
11
+ function getTable() {
12
+ return document.querySelector('.coverage-summary');
13
+ }
14
+ // returns the thead element of the summary table
15
+ function getTableHeader() {
16
+ return getTable().querySelector('thead tr');
17
+ }
18
+ // returns the tbody element of the summary table
19
+ function getTableBody() {
20
+ return getTable().querySelector('tbody');
21
+ }
22
+ // returns the th element for nth column
23
+ function getNthColumn(n) {
24
+ return getTableHeader().querySelectorAll('th')[n];
25
+ }
26
+
27
+ function onFilterInput() {
28
+ const searchValue = document.getElementById('fileSearch').value;
29
+ const rows = document.getElementsByTagName('tbody')[0].children;
30
+
31
+ // Try to create a RegExp from the searchValue. If it fails (invalid regex),
32
+ // it will be treated as a plain text search
33
+ let searchRegex;
34
+ try {
35
+ searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
36
+ } catch (error) {
37
+ searchRegex = null;
38
+ }
39
+
40
+ for (let i = 0; i < rows.length; i++) {
41
+ const row = rows[i];
42
+ let isMatch = false;
43
+
44
+ if (searchRegex) {
45
+ // If a valid regex was created, use it for matching
46
+ isMatch = searchRegex.test(row.textContent);
47
+ } else {
48
+ // Otherwise, fall back to the original plain text search
49
+ isMatch = row.textContent
50
+ .toLowerCase()
51
+ .includes(searchValue.toLowerCase());
52
+ }
53
+
54
+ row.style.display = isMatch ? '' : 'none';
55
+ }
56
+ }
57
+
58
+ // loads the search box
59
+ function addSearchBox() {
60
+ var template = document.getElementById('filterTemplate');
61
+ var templateClone = template.content.cloneNode(true);
62
+ templateClone.getElementById('fileSearch').oninput = onFilterInput;
63
+ template.parentElement.appendChild(templateClone);
64
+ }
65
+
66
+ // loads all columns
67
+ function loadColumns() {
68
+ var colNodes = getTableHeader().querySelectorAll('th'),
69
+ colNode,
70
+ cols = [],
71
+ col,
72
+ i;
73
+
74
+ for (i = 0; i < colNodes.length; i += 1) {
75
+ colNode = colNodes[i];
76
+ col = {
77
+ key: colNode.getAttribute('data-col'),
78
+ sortable: !colNode.getAttribute('data-nosort'),
79
+ type: colNode.getAttribute('data-type') || 'string'
80
+ };
81
+ cols.push(col);
82
+ if (col.sortable) {
83
+ col.defaultDescSort = col.type === 'number';
84
+ colNode.innerHTML =
85
+ colNode.innerHTML + '<span class="sorter"></span>';
86
+ }
87
+ }
88
+ return cols;
89
+ }
90
+ // attaches a data attribute to every tr element with an object
91
+ // of data values keyed by column name
92
+ function loadRowData(tableRow) {
93
+ var tableCols = tableRow.querySelectorAll('td'),
94
+ colNode,
95
+ col,
96
+ data = {},
97
+ i,
98
+ val;
99
+ for (i = 0; i < tableCols.length; i += 1) {
100
+ colNode = tableCols[i];
101
+ col = cols[i];
102
+ val = colNode.getAttribute('data-value');
103
+ if (col.type === 'number') {
104
+ val = Number(val);
105
+ }
106
+ data[col.key] = val;
107
+ }
108
+ return data;
109
+ }
110
+ // loads all row data
111
+ function loadData() {
112
+ var rows = getTableBody().querySelectorAll('tr'),
113
+ i;
114
+
115
+ for (i = 0; i < rows.length; i += 1) {
116
+ rows[i].data = loadRowData(rows[i]);
117
+ }
118
+ }
119
+ // sorts the table using the data for the ith column
120
+ function sortByIndex(index, desc) {
121
+ var key = cols[index].key,
122
+ sorter = function(a, b) {
123
+ a = a.data[key];
124
+ b = b.data[key];
125
+ return a < b ? -1 : a > b ? 1 : 0;
126
+ },
127
+ finalSorter = sorter,
128
+ tableBody = document.querySelector('.coverage-summary tbody'),
129
+ rowNodes = tableBody.querySelectorAll('tr'),
130
+ rows = [],
131
+ i;
132
+
133
+ if (desc) {
134
+ finalSorter = function(a, b) {
135
+ return -1 * sorter(a, b);
136
+ };
137
+ }
138
+
139
+ for (i = 0; i < rowNodes.length; i += 1) {
140
+ rows.push(rowNodes[i]);
141
+ tableBody.removeChild(rowNodes[i]);
142
+ }
143
+
144
+ rows.sort(finalSorter);
145
+
146
+ for (i = 0; i < rows.length; i += 1) {
147
+ tableBody.appendChild(rows[i]);
148
+ }
149
+ }
150
+ // removes sort indicators for current column being sorted
151
+ function removeSortIndicators() {
152
+ var col = getNthColumn(currentSort.index),
153
+ cls = col.className;
154
+
155
+ cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
156
+ col.className = cls;
157
+ }
158
+ // adds sort indicators for current column being sorted
159
+ function addSortIndicators() {
160
+ getNthColumn(currentSort.index).className += currentSort.desc
161
+ ? ' sorted-desc'
162
+ : ' sorted';
163
+ }
164
+ // adds event listeners for all sorter widgets
165
+ function enableUI() {
166
+ var i,
167
+ el,
168
+ ithSorter = function ithSorter(i) {
169
+ var col = cols[i];
170
+
171
+ return function() {
172
+ var desc = col.defaultDescSort;
173
+
174
+ if (currentSort.index === i) {
175
+ desc = !currentSort.desc;
176
+ }
177
+ sortByIndex(i, desc);
178
+ removeSortIndicators();
179
+ currentSort.index = i;
180
+ currentSort.desc = desc;
181
+ addSortIndicators();
182
+ };
183
+ };
184
+ for (i = 0; i < cols.length; i += 1) {
185
+ if (cols[i].sortable) {
186
+ // add the click event handler on the th so users
187
+ // dont have to click on those tiny arrows
188
+ el = getNthColumn(i).querySelector('.sorter').parentElement;
189
+ if (el.addEventListener) {
190
+ el.addEventListener('click', ithSorter(i));
191
+ } else {
192
+ el.attachEvent('onclick', ithSorter(i));
193
+ }
194
+ }
195
+ }
196
+ }
197
+ // adds sorting functionality to the UI
198
+ return function() {
199
+ if (!getTable()) {
200
+ return;
201
+ }
202
+ cols = loadColumns();
203
+ loadData();
204
+ addSearchBox();
205
+ addSortIndicators();
206
+ enableUI();
207
+ };
208
+ })();
209
+
210
+ window.addEventListener('load', addSorting);
File without changes
@@ -0,0 +1,8 @@
1
+ import AConnector from '@orchesty/nodejs-sdk/dist/lib/Connector/AConnector';
2
+ import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
3
+ export default class SlackSendMessageConnector extends AConnector {
4
+ getName(): string;
5
+ processAction(dto: ProcessDto<{
6
+ channel: string;
7
+ }>): Promise<ProcessDto>;
8
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const AConnector_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Connector/AConnector"));
7
+ const HttpMethods_1 = require("@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods");
8
+ const SLACK_SEND_MESSAGE_ENDPOINT = 'chat.postMessage';
9
+ class SlackSendMessageConnector extends AConnector_1.default {
10
+ getName() {
11
+ return 'slack-send-message';
12
+ }
13
+ async processAction(dto) {
14
+ const { channel } = dto.getJsonData();
15
+ const application = this.getApplication();
16
+ const applicationInstall = await this.getApplicationInstallFromProcess(dto);
17
+ const data = {
18
+ channel,
19
+ blocks: [
20
+ {
21
+ type: 'section',
22
+ text: {
23
+ type: 'mrkdwn',
24
+ text: `Hello, *${dto.getUser()}*`,
25
+ },
26
+ },
27
+ ],
28
+ };
29
+ const request = await application.getRequestDto(dto, applicationInstall, HttpMethods_1.HttpMethods.POST, SLACK_SEND_MESSAGE_ENDPOINT, JSON.stringify(data));
30
+ const response = await this.getSender().send(request, [202]);
31
+ return dto;
32
+ }
33
+ }
34
+ exports.default = SlackSendMessageConnector;
@@ -0,0 +1,18 @@
1
+ import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
2
+ import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
3
+ import AOAuth2Application from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/AOAuth2Application';
4
+ import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
5
+ import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
6
+ import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
7
+ export default class SlackApplication extends AOAuth2Application {
8
+ getAuthUrl(): string;
9
+ getTokenUrl(): string;
10
+ getDescription(): string;
11
+ getName(): string;
12
+ getPublicName(): string;
13
+ getLogo(): string;
14
+ getRequestDto(_dto: AProcessDto, applicationInstall: ApplicationInstall, method: HttpMethods, url?: string, data?: unknown): Promise<RequestDto> | RequestDto;
15
+ getScopes(applicationInstall: ApplicationInstall): string[];
16
+ getFormStack(): FormStack;
17
+ isAuthorized(applicationInstall: ApplicationInstall): boolean;
18
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const CoreFormsEnum_1 = __importStar(require("@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum"));
40
+ const Field_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Field"));
41
+ const FieldType_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FieldType"));
42
+ const Form_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form"));
43
+ const FormStack_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack"));
44
+ const OAuth2Provider_1 = require("@orchesty/nodejs-sdk/dist/lib/Authorization/Provider/OAuth2/OAuth2Provider");
45
+ const ABasicApplication_1 = require("@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication");
46
+ const AOAuth2Application_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/AOAuth2Application"));
47
+ const IOAuth2Application_1 = require("@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/IOAuth2Application");
48
+ const RequestDto_1 = __importDefault(require("@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto"));
49
+ const Headers_1 = require("@orchesty/nodejs-sdk/dist/lib/Utils/Headers");
50
+ const BASE_URL = 'https://slack.com/api/';
51
+ class SlackApplication extends AOAuth2Application_1.default {
52
+ getAuthUrl() {
53
+ return 'https://slack.com/oauth/v2/authorize';
54
+ }
55
+ getTokenUrl() {
56
+ return 'https://slack.com/api/oauth.v2.access';
57
+ }
58
+ getDescription() {
59
+ return 'In-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine';
60
+ }
61
+ getName() {
62
+ return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2LjcsMHMxMC41LDQuNywxMC41LDEwLjVWMjFIMzYuN3ogTTM2LjcsMjYuMwoJYzUuOCwwLDEwLjUsNC43LDEwLjUsMTAuNXMtNC43LDEwLjUtMTAuNSwxMC41SDEwLjRDNC42LDQ3LjMsMCw0Mi42LDAsMzYuOHM0LjctMTAuNSwxMC41LTEwLjVIMzYuN3oiLz4KPHBhdGggY2xhc3M9InN0MiIgZD0iTTc4LjcsMzYuOGMwLTUuOCw0LjctMTAuNSwxMC41LTEwLjVjNS44LDAsMTAuNSw0LjcsMTAuNSwxMC41Uzk1LDQ3LjMsODkuMiw0Ny4zSDc4LjdWMzYuOHogTTczLjUsMzYuOAoJYzAsNS44LTQuNywxMC41LTEwLjUsMTAuNXMtMTAuNS00LjctMTAuNS0xMC41VjEwLjVDNTIuNSw0LjcsNTcuMiwwLDYzLDBjNS44LDAsMTAuNSw0LjcsMTAuNSwxMC41QzczLjUsMTAuNSw3My41LDM2LjgsNzMuNSwzNi44egoJIi8+CjxwYXRoIGNsYXNzPSJzdDMiIGQ9Ik02Myw3OC44YzUuOCwwLDEwLjUsNC43LDEwLjUsMTAuNWMwLDUuOC00LjcsMTAuNS0xMC41LDEwLjVTNTIuNSw5NSw1Mi41LDg5LjJWNzguOEg2M3ogTTYzLDczLjUKCWMtNS44LDAtMTAuNS00LjctMTAuNS0xMC41UzU3LjIsNTIuNiw2Myw1Mi42aDI2LjNjNS44LDAsMTAuNSw0LjcsMTAuNSwxMC41Uzk1LDczLjUsODkuMiw3My41SDYzeiIvPgo8L3N2Zz4K';
69
+ }
70
+ getRequestDto(_dto, applicationInstall, method, url, data) {
71
+ if (!this.isAuthorized(applicationInstall)) {
72
+ throw new Error(`Application [${this.getPublicName()}] is not authorized!`);
73
+ }
74
+ const token = applicationInstall.getSettings()[CoreFormsEnum_1.default.AUTHORIZATION_FORM][ABasicApplication_1.TOKEN][OAuth2Provider_1.ACCESS_TOKEN];
75
+ return new RequestDto_1.default(`${BASE_URL}${url}`, method, _dto, data, {
76
+ [Headers_1.CommonHeaders.CONTENT_TYPE]: Headers_1.JSON_TYPE,
77
+ [Headers_1.CommonHeaders.AUTHORIZATION]: `Bearer ${token}`,
78
+ });
79
+ }
80
+ getScopes(applicationInstall) {
81
+ return [
82
+ 'app_mentions:read',
83
+ 'chat:write',
84
+ 'chat:write.public',
85
+ ];
86
+ }
87
+ getFormStack() {
88
+ const form = new Form_1.default(CoreFormsEnum_1.default.AUTHORIZATION_FORM, (0, CoreFormsEnum_1.getFormName)(CoreFormsEnum_1.default.AUTHORIZATION_FORM))
89
+ .addField(new Field_1.default(FieldType_1.default.TEXT, IOAuth2Application_1.CLIENT_ID, 'Client Id', undefined, true))
90
+ .addField(new Field_1.default(FieldType_1.default.TEXT, IOAuth2Application_1.CLIENT_SECRET, 'Client Secret', undefined, true));
91
+ return new FormStack_1.default().addForm(form);
92
+ }
93
+ isAuthorized(applicationInstall) {
94
+ const authorizationForm = applicationInstall.getSettings()[CoreFormsEnum_1.default.AUTHORIZATION_FORM];
95
+ return super.isAuthorized(applicationInstall)
96
+ && authorizationForm?.[IOAuth2Application_1.CLIENT_ID]
97
+ && authorizationForm?.[IOAuth2Application_1.CLIENT_SECRET];
98
+ }
99
+ }
100
+ exports.default = SlackApplication;
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@orchesty/connector-slack",
3
+ "description": "",
4
+ "version": "0.0.0",
5
+ "license": "Apache-2.0",
6
+ "url": "https://github.com/Orchesty/orchesty-nodejs-connectors",
7
+ "repository": "https://github.com/Orchesty/orchesty-nodejs-connectors",
8
+ "scripts": {
9
+ "build": "rm -rf dist && rm -rf tsconfig.prod.tsbuildinfo && tsc -d -p tsconfig.prod.json && cp package.json ./dist/package.json",
10
+ "test": "jest --coverage --forceExit --passWithNoTests",
11
+ "lint": "eslint src --fix",
12
+ "lint-ci": "eslint src"
13
+ },
14
+ "keywords": [],
15
+ "author": "info@hanaboso.com",
16
+ "dependencies": {
17
+ "@orchesty/nodejs-sdk": "^4.3.6"
18
+ },
19
+ "engines": {
20
+ "node": ">=24"
21
+ }
22
+ }
package/jest.config.js ADDED
@@ -0,0 +1,13 @@
1
+ const baseConfig = require('../../jest.config.js');
2
+
3
+ module.exports = {
4
+ ...baseConfig,
5
+ roots: ["<rootDir>/src"],
6
+ setupFiles: ["<rootDir>/../../.jest/testEnvs.ts"],
7
+ setupFilesAfterEnv: ["<rootDir>/../../.jest/testLifecycle.ts"],
8
+ globalSetup: "<rootDir>/../../.jest/globalSetup.ts",
9
+ moduleNameMapper: {
10
+ "^@orchesty/nodejs-connectors/test/(.*)$": "<rootDir>/../../test/$1",
11
+ "^@orchesty/nodejs-connectors/lib/(.*)$": "<rootDir>/../../lib/$1",
12
+ },
13
+ }
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@orchesty/connector-slack",
3
+ "description": "",
4
+ "version": "1.0.0",
5
+ "license": "Apache-2.0",
6
+ "url": "https://github.com/Orchesty/orchesty-nodejs-connectors",
7
+ "repository": "https://github.com/Orchesty/orchesty-nodejs-connectors",
8
+ "keywords": [],
9
+ "author": "info@hanaboso.com",
10
+ "dependencies": {
11
+ "@orchesty/nodejs-sdk": "^4.3.6"
12
+ },
13
+ "engines": {
14
+ "node": ">=24"
15
+ },
16
+ "scripts": {
17
+ "build": "rm -rf dist && rm -rf tsconfig.prod.tsbuildinfo && tsc -d -p tsconfig.prod.json && cp package.json ./dist/package.json",
18
+ "test": "jest --coverage --forceExit --passWithNoTests",
19
+ "lint": "eslint src --fix",
20
+ "lint-ci": "eslint src"
21
+ }
22
+ }
@@ -0,0 +1,45 @@
1
+ import AConnector from '@orchesty/nodejs-sdk/dist/lib/Connector/AConnector';
2
+ import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
3
+ import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
4
+ import SlackApplication from '../SlackApplication';
5
+
6
+ const SLACK_SEND_MESSAGE_ENDPOINT = 'chat.postMessage';
7
+
8
+ export default class SlackSendMessageConnector extends AConnector {
9
+
10
+ public getName(): string {
11
+ return 'slack-send-message';
12
+ }
13
+
14
+ public async processAction(dto: ProcessDto<{ channel: string }>): Promise<ProcessDto> {
15
+ const { channel } = dto.getJsonData();
16
+ const application = this.getApplication<SlackApplication>();
17
+ const applicationInstall = await this.getApplicationInstallFromProcess(dto);
18
+ const data = {
19
+ channel,
20
+ blocks: [
21
+ {
22
+ type: 'section',
23
+ text: {
24
+ type: 'mrkdwn',
25
+ text: `Hello, *${dto.getUser()}*`,
26
+ },
27
+ },
28
+ ],
29
+ };
30
+
31
+ const request = await application.getRequestDto(
32
+ dto,
33
+ applicationInstall,
34
+ HttpMethods.POST,
35
+ SLACK_SEND_MESSAGE_ENDPOINT,
36
+ JSON.stringify(data),
37
+ );
38
+
39
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
+ const response = await this.getSender().send(request, [202]);
41
+
42
+ return dto;
43
+ }
44
+
45
+ }
@@ -0,0 +1,92 @@
1
+ import CoreFormsEnum, { getFormName } from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
2
+ import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
3
+ import Field from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Field';
4
+ import FieldType from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FieldType';
5
+ import Form from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form';
6
+ import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
7
+ import { ACCESS_TOKEN } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Provider/OAuth2/OAuth2Provider';
8
+ import { TOKEN } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication';
9
+ import AOAuth2Application from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/AOAuth2Application';
10
+ import { CLIENT_ID, CLIENT_SECRET } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/IOAuth2Application';
11
+ import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
12
+ import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
13
+ import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
14
+ import { CommonHeaders, JSON_TYPE } from '@orchesty/nodejs-sdk/dist/lib/Utils/Headers';
15
+
16
+ const BASE_URL = 'https://slack.com/api/';
17
+
18
+ export default class SlackApplication extends AOAuth2Application {
19
+
20
+ public getAuthUrl(): string {
21
+ return 'https://slack.com/oauth/v2/authorize';
22
+ }
23
+
24
+ public getTokenUrl(): string {
25
+ return 'https://slack.com/api/oauth.v2.access';
26
+ }
27
+
28
+ public getDescription(): string {
29
+ return 'In-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine';
30
+ }
31
+
32
+ public getName(): string {
33
+ return 'slack';
34
+ }
35
+
36
+ public getPublicName(): string {
37
+ return 'Slack';
38
+ }
39
+
40
+ public getLogo(): string {
41
+ return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IlZyc3R2YV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTAwIDEwMDsiIHhtbDpzcGFjZT0icH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YXRoIGNsYXNzPSJzdDMiIGQ9Ik02Myw3OC44YzUuOCwwLDEwLjUsNC43LDEwLjUsMTAuNWMwLDUuOC00LjcsMTAuNS0xMC41LDEwLjVTNTIuNSw5NSw1Mi41LDg5LjJWNzguOEg2M3ogTTYzLDczLjUKCWMtNS44LDAtMTAuNS00LjctMTAuNS0xMC41UzU3LjIsNTIuNiw2Myw1Mi42aDI2LjNjNS44LDAsMTAuNSw0LjcsMTAuNSwxMC41Uzk1LDczLjUsODkuMiw3My41SDYzeiIvPgo8L3N2Zz4K';
42
+ }
43
+
44
+ public getRequestDto(
45
+ _dto: AProcessDto,
46
+ applicationInstall: ApplicationInstall,
47
+ method: HttpMethods,
48
+ url?: string,
49
+ data?: unknown,
50
+ ): Promise<RequestDto> | RequestDto {
51
+ if (!this.isAuthorized(applicationInstall)) {
52
+ throw new Error(`Application [${this.getPublicName()}] is not authorized!`);
53
+ }
54
+
55
+ const token = applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM][TOKEN][ACCESS_TOKEN];
56
+ return new RequestDto(
57
+ `${BASE_URL}${url}`,
58
+ method,
59
+ _dto,
60
+ data,
61
+ {
62
+ [CommonHeaders.CONTENT_TYPE]: JSON_TYPE,
63
+ [CommonHeaders.AUTHORIZATION]: `Bearer ${token}`,
64
+ },
65
+ );
66
+ }
67
+
68
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
69
+ public getScopes(applicationInstall: ApplicationInstall): string[] {
70
+ return [
71
+ 'app_mentions:read',
72
+ 'chat:write',
73
+ 'chat:write.public',
74
+ ];
75
+ }
76
+
77
+ public getFormStack(): FormStack {
78
+ const form = new Form(CoreFormsEnum.AUTHORIZATION_FORM, getFormName(CoreFormsEnum.AUTHORIZATION_FORM))
79
+ .addField(new Field(FieldType.TEXT, CLIENT_ID, 'Client Id', undefined, true))
80
+ .addField(new Field(FieldType.TEXT, CLIENT_SECRET, 'Client Secret', undefined, true));
81
+
82
+ return new FormStack().addForm(form);
83
+ }
84
+
85
+ public isAuthorized(applicationInstall: ApplicationInstall): boolean {
86
+ const authorizationForm = applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM];
87
+ return super.isAuthorized(applicationInstall)
88
+ && authorizationForm?.[CLIENT_ID]
89
+ && authorizationForm?.[CLIENT_SECRET];
90
+ }
91
+
92
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "composite": true
6
+ },
7
+ "include": ["src", "test", "../../test"]
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ },
6
+ "include": [
7
+ "src",
8
+ ],
9
+ "exclude": [
10
+ "node_modules",
11
+ "src/**/__tests__",
12
+ ]
13
+ }