Skip to content

Commit

Permalink
fix(nightingale-slack): remove dependency request
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Jul 27, 2023
1 parent cf9ea88 commit 9ed95ee
Show file tree
Hide file tree
Showing 50 changed files with 89 additions and 361 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/asn1-npm-0.2.6-bdd07356c4-39f2ae343b.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/jsbn-npm-0.1.1-0eb7132404-e5ff29c1b8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/psl-npm-1.8.0-226099d70e-6150048ed2.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/uuid-npm-3.4.0-4fd8ef88ad-58de2feed6.zip
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion packages/nightingale-example/package.json
Expand Up @@ -69,14 +69,16 @@
"console",
"debug",
"errors",
"jsonConsole"
"jsonConsole",
"slack"
]
},
"dependencies": {
"nightingale": "14.0.2",
"nightingale-console": "14.0.2",
"nightingale-console-output": "14.0.2",
"nightingale-json-formatter": "14.0.2",
"nightingale-slack": "14.0.2",
"nightingale-string": "14.0.2",
"nightingale-types": "14.0.2"
},
Expand Down
23 changes: 23 additions & 0 deletions packages/nightingale-example/src/slack.ts
@@ -0,0 +1,23 @@
import { Logger, configure, Level } from 'nightingale';
import { SlackHandler } from 'nightingale-slack';

if (!process.env.WEBHOOK_URL) {
throw new Error('Missing WEBHOOK_URL environment variable');
}

configure([
{
handlers: [
new SlackHandler(
{
webhookUrl: process.env.WEBHOOK_URL,
},
Level.ALL,
),
],
},
]);

const logger = new Logger('app');

logger.success('Test', { value: 1 });
3 changes: 3 additions & 0 deletions packages/nightingale-slack/dist/definitions/index.d.ts
Expand Up @@ -2,6 +2,9 @@ import type { Handle, Handler, Level } from 'nightingale-types';
import type { SlackConfig } from './SlackConfig';
export type { SlackConfig } from './SlackConfig';
export { default as createBody } from './createBody';
declare global {
const fetch: typeof import('node-fetch').default;
}
export declare class SlackHandler implements Handler {
minLevel: Level;
handle: Handle;
Expand Down
2 changes: 1 addition & 1 deletion packages/nightingale-slack/dist/definitions/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions packages/nightingale-slack/dist/index-node18.mjs
@@ -1,4 +1,3 @@
import { post } from 'request';
import { Level } from 'nightingale-levels';
import markdownFormatter from 'nightingale-markdown-formatter';
import rawFormatter from 'nightingale-raw-formatter';
Expand Down Expand Up @@ -32,14 +31,15 @@ function createBody(record, slackConfig) {
};
}

// temp fix for global fetch: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/60924

const createHandler = slackConfig => record => {
const body = createBody(record, slackConfig);
post({
url: slackConfig.webhookUrl,
body,
json: true
}).on('error', err2 => {
console.error(err2.stack);
fetch(slackConfig.webhookUrl, {
method: 'POST',
body: JSON.stringify(body)
}).catch(error => {
console.error(error.stack);
});
};
class SlackHandler {
Expand Down
2 changes: 1 addition & 1 deletion packages/nightingale-slack/dist/index-node18.mjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/nightingale-slack/package.json
Expand Up @@ -56,12 +56,12 @@
"nightingale-levels": "14.0.2",
"nightingale-markdown-formatter": "14.0.2",
"nightingale-raw-formatter": "14.0.2",
"nightingale-types": "14.0.2",
"request": "^2.88.0"
"nightingale-types": "14.0.2"
},
"devDependencies": {
"@babel/core": "7.22.9",
"@types/request": "2.48.8",
"@types/node": "18.17.1",
"@types/node-fetch": "2.6.4",
"pob-babel": "36.2.0",
"typescript": "5.1.6"
}
Expand Down
19 changes: 12 additions & 7 deletions packages/nightingale-slack/src/index.ts
Expand Up @@ -5,25 +5,30 @@ import type {
Handler,
Level,
} from 'nightingale-types';
import { post } from 'request';
import type { SlackConfig } from './SlackConfig';
import createBody from './createBody';

export type { SlackConfig } from './SlackConfig';

export { default as createBody } from './createBody';

// temp fix for global fetch: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/60924
declare global {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const fetch: typeof import('node-fetch').default;
}

const createHandler =
(slackConfig: SlackConfig) =>
<T extends Metadata>(record: LogRecord<T>) => {
const body = createBody(record, slackConfig);

post({ url: slackConfig.webhookUrl, body, json: true }).on(
'error',
(err2: Error) => {
console.error(err2.stack);
},
);
fetch(slackConfig.webhookUrl, {
method: 'POST',
body: JSON.stringify(body),
}).catch((error: Error) => {
console.error(error.stack);
});
};

export class SlackHandler implements Handler {
Expand Down

0 comments on commit 9ed95ee

Please sign in to comment.