fix(core): update

This commit is contained in:
Philipp Kunz 2024-01-25 00:09:32 +01:00
parent 4b5853072b
commit c124978aa1
19 changed files with 17 additions and 235 deletions

View File

@ -22,5 +22,6 @@
}
}
}
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}

3
dist_ts/index.d.ts vendored
View File

@ -1,3 +0,0 @@
export * from './slack.classes.slackaccount.js';
export * from './slack.classes.slackmessage.js';
export * from './slack.classes.slacklog.js';

View File

@ -1,4 +0,0 @@
export * from './slack.classes.slackaccount.js';
export * from './slack.classes.slackmessage.js';
export * from './slack.classes.slacklog.js';
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGlDQUFpQyxDQUFDO0FBQ2hELGNBQWMsaUNBQWlDLENBQUM7QUFDaEQsY0FBYyw2QkFBNkIsQ0FBQyJ9

View File

@ -1,14 +0,0 @@
import * as plugins from './slack.plugins.js';
import { type IMessageOptions } from './slack.classes.slackmessage.js';
export declare class SlackAccount {
private postUrl;
private updateUrl;
private slackToken;
constructor(slackTokenArg: string);
sendMessage(optionsArg: {
messageOptions: IMessageOptions;
channelArg: string;
ts?: string;
mode: 'new' | 'threaded' | 'update';
}): Promise<plugins.smartrequest.IExtendedIncomingMessage>;
}

View File

@ -1,52 +0,0 @@
import * as plugins from './slack.plugins.js';
import {} from './slack.classes.slackmessage.js';
export class SlackAccount {
constructor(slackTokenArg) {
this.postUrl = 'https://slack.com/api/chat.postMessage';
this.updateUrl = 'https://slack.com/api/chat.update';
this.slackToken = slackTokenArg;
}
async sendMessage(optionsArg) {
let requestBody = {
channel: optionsArg.channelArg,
text: optionsArg.messageOptions.text
};
if (optionsArg.messageOptions.fields) {
requestBody = {
...requestBody,
attachments: [
{
pretext: optionsArg.messageOptions.pretext,
fields: optionsArg.messageOptions.fields,
ts: optionsArg.messageOptions.ts,
color: optionsArg.messageOptions.color
}
]
};
}
let postUrl = this.postUrl;
switch (true) {
case optionsArg.ts && optionsArg.mode === 'update':
requestBody = {
...requestBody,
ts: optionsArg.ts
};
postUrl = this.updateUrl;
break;
case optionsArg.ts && optionsArg.mode === 'threaded':
requestBody = {
...requestBody,
thread_ts: optionsArg.ts
};
break;
}
const response = await plugins.smartrequest.postJson(postUrl, {
headers: {
Authorization: `Bearer ${this.slackToken}`
},
requestBody
});
return response;
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2suY2xhc3Nlcy5zbGFja2FjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbGFjay5jbGFzc2VzLnNsYWNrYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLG9CQUFvQixDQUFDO0FBQzlDLE9BQU8sRUFBd0IsTUFBTSxpQ0FBaUMsQ0FBQztBQUV2RSxNQUFNLE9BQU8sWUFBWTtJQUl2QixZQUFZLGFBQXFCO1FBSHpCLFlBQU8sR0FBRyx3Q0FBd0MsQ0FBQztRQUNuRCxjQUFTLEdBQUcsbUNBQW1DLENBQUM7UUFHdEQsSUFBSSxDQUFDLFVBQVUsR0FBRyxhQUFhLENBQUM7SUFDbEMsQ0FBQztJQUVELEtBQUssQ0FBQyxXQUFXLENBQUMsVUFLakI7UUFDQyxJQUFJLFdBQVcsR0FBUTtZQUNyQixPQUFPLEVBQUUsVUFBVSxDQUFDLFVBQVU7WUFDOUIsSUFBSSxFQUFFLFVBQVUsQ0FBQyxjQUFjLENBQUMsSUFBSTtTQUNyQyxDQUFDO1FBRUYsSUFBSSxVQUFVLENBQUMsY0FBYyxDQUFDLE1BQU0sRUFBRSxDQUFDO1lBQ3JDLFdBQVcsR0FBRztnQkFDWixHQUFHLFdBQVc7Z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yxRQUFRLENBQUM7SUFDbEIsQ0FBQztDQUNGIn0=

View File

@ -1,13 +0,0 @@
import { SlackAccount } from './slack.classes.slackaccount.js';
import { SlackMessage } from './slack.classes.slackmessage.js';
export declare class SlackLog {
slackAccount: SlackAccount;
slackMessage: SlackMessage;
channelName: string;
completeLog: string;
constructor(optionsArg: {
slackAccount: SlackAccount;
channelName: string;
});
sendLogLine(logText: string): Promise<void>;
}

View File

@ -1,24 +0,0 @@
import { SlackAccount } from './slack.classes.slackaccount.js';
import { SlackMessage } from './slack.classes.slackmessage.js';
export class SlackLog {
constructor(optionsArg) {
this.completeLog = ``;
this.slackAccount = optionsArg.slackAccount;
this.channelName = optionsArg.channelName;
}
async sendLogLine(logText) {
if (!this.slackMessage) {
this.slackMessage = new SlackMessage(this.slackAccount, {
text: '``` log is loading... ```'
});
await this.slackMessage.sendToRoom(this.channelName);
}
const date = new Date();
this.completeLog +=
`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} - ` + logText + '\n';
await this.slackMessage.updateAndSend({
text: '```\n' + this.completeLog + '\n```'
});
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2suY2xhc3Nlcy5zbGFja2xvZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NsYWNrLmNsYXNzZXMuc2xhY2tsb2cudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQy9ELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUUvRCxNQUFNLE9BQU8sUUFBUTtJQU9uQixZQUFZLFVBQStEO1FBRnBFLGdCQUFXLEdBQUcsRUFBRSxDQUFDO1FBR3RCLElBQUksQ0FBQyxZQUFZLEdBQUcsVUFBVSxDQUFDLFlBQVksQ0FBQztRQUM1QyxJQUFJLENBQUMsV0FBVyxHQUFHLFVBQVUsQ0FBQyxXQUFXLENBQUM7SUFDNUMsQ0FBQztJQUNNLEtBQUssQ0FBQyxXQUFXLENBQUMsT0FBZTtRQUN0QyxJQUFJLENBQUMsSUFBSSxDQUFDLFlBQVksRUFBRSxDQUFDO1lBQ3ZCLElBQUksQ0FBQyxZQUFZLEdBQUcsSUFBSSxZQUFZLENBQUMsSUFBSSxDQUFDLFlBQVksRUFBRTtnQkFDdEQsSUFBSSxFQUFFLDJCQUEyQjthQUNsQyxDQUFDLENBQUM7WUFDSCxNQUFNLElBQUksQ0FBQyxZQUFZLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUN2RCxDQUFDO1FBQ0QsTUFBTSxJQUFJLEdBQUcsSUFBSSxJQUFJLEVBQUUsQ0FBQztRQUN4QixJQUFJLENBQUMsV0FBVztZQUNkLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxJQUFJLElBQUksQ0FBQyxVQUFVLEVBQUUsSUFBSSxJQUFJLENBQUMsVUFBVSxFQUFFLEtBQUssR0FBRyxPQUFPLEdBQUcsSUFBSSxDQUFDO1FBQ3JGLE1BQU0sSUFBSSxDQUFDLFlBQVksQ0FBQyxhQUFhLENBQUM7WUFDcEMsSUFBSSxFQUFFLE9BQU8sR0FBRyxJQUFJLENBQUMsV0FBVyxHQUFHLE9BQU87U0FDM0MsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztDQUNGIn0=

View File

@ -1,62 +0,0 @@
import * as plugins from './slack.plugins.js';
import { SlackAccount } from './slack.classes.slackaccount.js';
export interface IAttachmentField {
title: string;
value: string;
short?: boolean;
}
export interface IMessageOptions {
/**
* "Required plain-text summary of the attachment."
*/
fallback?: string;
/**
* a side color
*/
color?: string;
/**
* a message to show above
*/
pretext?: string;
/**
* author name of the attachment
*/
author_name?: string;
/**
* a link to the author
*/
author_link?: string;
/**
* a string to the author
*/
author_icon?: string;
/**
* a title for the attachment
*/
title?: string;
/**
* a link for the title
*/
title_link?: string;
/**
* the main text of the message
*/
text?: string;
fields?: IAttachmentField[];
image_url?: string;
thumb_url?: string;
footer?: string;
footer_icon?: string;
ts?: number;
}
export declare class SlackMessage {
slackAccountRef: SlackAccount;
messageOptions: IMessageOptions;
channel: string;
ts: string;
requestRunning: plugins.smartpromise.Deferred<unknown>;
constructor(slackAccountArg: SlackAccount, messageOptionsArg: IMessageOptions);
updateAndSend(messageOptionsArg: IMessageOptions): Promise<void>;
startThread(messageOptionsArg: IMessageOptions): Promise<void>;
sendToRoom(channelNameArg: string, modeArg?: 'new' | 'update' | 'threaded'): Promise<void>;
}

View File

@ -1,39 +0,0 @@
import * as plugins from './slack.plugins.js';
import { SlackAccount } from './slack.classes.slackaccount.js';
export class SlackMessage {
constructor(slackAccountArg, messageOptionsArg) {
this.requestRunning = plugins.smartpromise.defer();
if (slackAccountArg) {
this.slackAccountRef = slackAccountArg;
}
this.messageOptions = messageOptionsArg;
this.requestRunning.resolve();
}
async updateAndSend(messageOptionsArg) {
this.messageOptions = messageOptionsArg;
await this.sendToRoom(this.channel, 'update');
}
async startThread(messageOptionsArg) {
this.messageOptions = messageOptionsArg;
this.sendToRoom(this.channel, 'threaded');
}
async sendToRoom(channelNameArg, modeArg = 'new') {
this.channel = channelNameArg;
if (this.slackAccountRef) {
const response = await this.slackAccountRef.sendMessage({
channelArg: this.channel,
messageOptions: this.messageOptions,
mode: modeArg,
ts: this.ts
});
if (modeArg === 'new') {
this.ts = response.body.message.ts;
this.channel = response.body.channel;
}
}
else {
throw new Error('you need to set a slackRef before sending the message!');
}
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2suY2xhc3Nlcy5zbGFja21lc3NhZ2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbGFjay5jbGFzc2VzLnNsYWNrbWVzc2FnZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmd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xJQUFJLENBQUMsZUFBZSxDQUFDLFdBQVcsQ0FBQztnQkFDdEQsVUFBVSxFQUFFLElBQUksQ0FBQyxPQUFPO2dCQUN4QixjQUFjLEVBQUUsSUFBSSxDQUFDLGNBQWM7Z0JBQ25DLElBQUksRUFBRSxPQUFPO2dCQUNiLEVBQUUsRUFBRSxJQUFJLENBQUMsRUFBRTthQUNaLENBQUMsQ0FBQztZQUNILElBQUksT0FBTyxLQUFLLEtBQUssRUFBRSxDQUFDO2dCQUN0QixJQUFJLENBQUMsRUFBRSxHQUFHLFFBQVEsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQztnQkFDbkMsSUFBSSxDQUFDLE9BQU8sR0FBRyxRQUFRLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztZQUN2QyxDQUFDO1FBQ0gsQ0FBQzthQUFNLENBQUM7WUFDTixNQUFNLElBQUksS0FBSyxDQUFDLHdEQUF3RCxDQUFDLENBQUM7UUFDNUUsQ0FBQztJQUNILENBQUM7Q0FDRiJ9

View File

@ -1,3 +0,0 @@
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrequest from '@push.rocks/smartrequest';
export { smartpromise, smartrequest };

View File

@ -1,5 +0,0 @@
// pushrocks scope
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrequest from '@push.rocks/smartrequest';
export { smartpromise, smartrequest };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhY2sucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NsYWNrLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsa0JBQWtCO0FBQ2xCLE9BQU8sS0FBSyxZQUFZLE1BQU0sMEJBQTBCLENBQUM7QUFDekQsT0FBTyxLQUFLLFlBQVksTUFBTSwwQkFBMEIsQ0FBQztBQUV6RCxPQUFPLEVBQUUsWUFBWSxFQUFFLFlBQVksRUFBRSxDQUFDIn0=

View File

@ -9,8 +9,7 @@
"license": "MIT",
"scripts": {
"test": "tstest test/",
"build": "tsbuild --web",
"buildDocs": "tsdoc"
"build": "tsbuild --web"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.25",
@ -18,7 +17,8 @@
"@git.zone/tstest": "^1.0.54",
"@push.rocks/qenv": "^6.0.4",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.11.6"
"@types/node": "^20.11.6",
"typescript": "^5.3.3"
},
"dependencies": {
"@push.rocks/smartpromise": "^4.0.3",
@ -44,8 +44,5 @@
"url": "https://gitlab.com/apiclient.xyz/slack/issues"
},
"homepage": "https://gitlab.com/apiclient.xyz/slack#readme",
"type": "module",
"browserslist": [
"last 1 chrome versions"
]
"type": "module"
}

View File

@ -31,6 +31,9 @@ devDependencies:
'@types/node':
specifier: ^20.11.6
version: 20.11.6
typescript:
specifier: ^5.3.3
version: 5.3.3
packages:

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiclient.xyz/slack',
version: '3.0.7',
version: '3.0.8',
description: 'slack api abstraction for the mojo.io ecosystem'
}

View File

@ -1,5 +1,5 @@
import * as plugins from './slack.plugins.js';
import { type IMessageOptions } from './slack.classes.slackmessage.js';
import { type IMessageOptions } from './classes.slackmessage.js';
export class SlackAccount {
private postUrl = 'https://slack.com/api/chat.postMessage';

View File

@ -1,5 +1,5 @@
import { SlackAccount } from './slack.classes.slackaccount.js';
import { SlackMessage } from './slack.classes.slackmessage.js';
import { SlackAccount } from './classes.slackaccount.js';
import { SlackMessage } from './classes.slackmessage.js';
export class SlackLog {
public slackAccount: SlackAccount;

View File

@ -1,5 +1,5 @@
import * as plugins from './slack.plugins.js';
import { SlackAccount } from './slack.classes.slackaccount.js';
import { SlackAccount } from './classes.slackaccount.js';
export interface IAttachmentField {
title: string;

View File

@ -1,3 +1,3 @@
export * from './slack.classes.slackaccount.js';
export * from './slack.classes.slackmessage.js';
export * from './slack.classes.slacklog.js';
export * from './classes.slackaccount.js';
export * from './classes.slackmessage.js';
export * from './classes.slacklog.js';