@astro-minimax/notify 0.1.0 → 0.7.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.
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/notify.d.ts +10 -0
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +41 -0
- package/dist/providers/email.d.ts.map +1 -1
- package/dist/providers/email.js +0 -17
- package/dist/providers/telegram.d.ts.map +1 -1
- package/dist/providers/telegram.js +3 -17
- package/dist/templates/comment.js +6 -0
- package/package.json +31 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Souloss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createNotifier } from './notify.js';
|
|
1
|
+
export { createNotifier, getNotifier, resetNotifier } from './notify.js';
|
|
2
2
|
export type { NotifyConfig, NotifyEvent, CommentEvent, AiChatEvent, ArticleRef, ModelInfo, TokenUsage, PhaseTiming, NotifyResult, SendResult, Notifier, EventTemplates, Logger, TelegramConfig, WebhookConfig, EmailConfig, TelegramTemplate, WebhookPayload, EmailTemplate, Channel, EventType, } from './types.js';
|
|
3
3
|
export { defaultTemplates } from './templates/index.js';
|
|
4
4
|
export { createTelegramProvider, createWebhookProvider, createEmailProvider, } from './providers/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACzE,YAAY,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,cAAc,EACd,MAAM,EACN,cAAc,EACd,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,OAAO,EACP,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createNotifier } from './notify.js';
|
|
1
|
+
export { createNotifier, getNotifier, resetNotifier } from './notify.js';
|
|
2
2
|
export { defaultTemplates } from './templates/index.js';
|
|
3
3
|
export { createTelegramProvider, createWebhookProvider, createEmailProvider, } from './providers/index.js';
|
package/dist/notify.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import type { NotifyConfig, Notifier } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a cached notifier instance if the config matches the previous one.
|
|
4
|
+
* Creates a new instance only when the config changes.
|
|
5
|
+
* This optimization avoids recreating provider instances on every request.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getNotifier(config: NotifyConfig): Notifier;
|
|
8
|
+
/**
|
|
9
|
+
* Resets the singleton instance (useful for testing).
|
|
10
|
+
*/
|
|
11
|
+
export declare function resetNotifier(): void;
|
|
2
12
|
export declare function createNotifier(config: NotifyConfig): Notifier;
|
|
3
13
|
//# sourceMappingURL=notify.d.ts.map
|
package/dist/notify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../src/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAMZ,QAAQ,EAIT,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../src/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAMZ,QAAQ,EAIT,MAAM,YAAY,CAAC;AAwEpB;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,QAAQ,CAU1D;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAGpC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,QAAQ,CA4H7D"}
|
package/dist/notify.js
CHANGED
|
@@ -27,6 +27,47 @@ function mergeTemplates(custom) {
|
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
// Singleton instance and its config hash for caching
|
|
31
|
+
let notifierInstance = null;
|
|
32
|
+
let lastConfigHash = null;
|
|
33
|
+
/**
|
|
34
|
+
* Computes a simple hash of the notify config for singleton caching.
|
|
35
|
+
* Only includes fields that affect provider creation.
|
|
36
|
+
*/
|
|
37
|
+
function computeConfigHash(config) {
|
|
38
|
+
const parts = [];
|
|
39
|
+
if (config.telegram) {
|
|
40
|
+
parts.push(`telegram:${config.telegram.botToken}:${config.telegram.chatId}`);
|
|
41
|
+
}
|
|
42
|
+
if (config.webhook) {
|
|
43
|
+
parts.push(`webhook:${config.webhook.url}`);
|
|
44
|
+
}
|
|
45
|
+
if (config.email) {
|
|
46
|
+
parts.push(`email:${config.email.provider}:${config.email.apiKey}:${config.email.from}:${config.email.to}`);
|
|
47
|
+
}
|
|
48
|
+
return parts.join('|');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns a cached notifier instance if the config matches the previous one.
|
|
52
|
+
* Creates a new instance only when the config changes.
|
|
53
|
+
* This optimization avoids recreating provider instances on every request.
|
|
54
|
+
*/
|
|
55
|
+
export function getNotifier(config) {
|
|
56
|
+
const hash = computeConfigHash(config);
|
|
57
|
+
if (notifierInstance && hash === lastConfigHash) {
|
|
58
|
+
return notifierInstance;
|
|
59
|
+
}
|
|
60
|
+
notifierInstance = createNotifier(config);
|
|
61
|
+
lastConfigHash = hash;
|
|
62
|
+
return notifierInstance;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Resets the singleton instance (useful for testing).
|
|
66
|
+
*/
|
|
67
|
+
export function resetNotifier() {
|
|
68
|
+
notifierInstance = null;
|
|
69
|
+
lastConfigHash = null;
|
|
70
|
+
}
|
|
30
71
|
export function createNotifier(config) {
|
|
31
72
|
const logger = config.logger ?? new DefaultLogger();
|
|
32
73
|
const templates = mergeTemplates(config.templates);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/providers/email.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAElF,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD;
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/providers/email.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAElF,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,aAAa,CA4Ef"}
|
package/dist/providers/email.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
let proxyConfigured = false;
|
|
2
|
-
async function configureProxy() {
|
|
3
|
-
if (proxyConfigured)
|
|
4
|
-
return;
|
|
5
|
-
const proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
|
6
|
-
if (proxyUrl) {
|
|
7
|
-
try {
|
|
8
|
-
const { setGlobalDispatcher, ProxyAgent } = await import('undici');
|
|
9
|
-
setGlobalDispatcher(new ProxyAgent(proxyUrl));
|
|
10
|
-
proxyConfigured = true;
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
// ProxyAgent not available, continue without proxy
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
1
|
export function createEmailProvider(config, logger) {
|
|
18
2
|
const { provider, apiKey, from, to } = config;
|
|
19
3
|
return {
|
|
@@ -28,7 +12,6 @@ export function createEmailProvider(config, logger) {
|
|
|
28
12
|
};
|
|
29
13
|
}
|
|
30
14
|
try {
|
|
31
|
-
await configureProxy();
|
|
32
15
|
const response = await fetch('https://api.resend.com/emails', {
|
|
33
16
|
method: 'POST',
|
|
34
17
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../src/providers/telegram.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACvD;
|
|
1
|
+
{"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../src/providers/telegram.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACvD;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,cAAc,EACtB,MAAM,CAAC,EAAE,MAAM,GACd,gBAAgB,CAqElB"}
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
let proxyConfigured = false;
|
|
2
|
-
async function configureProxy() {
|
|
3
|
-
if (proxyConfigured)
|
|
4
|
-
return;
|
|
5
|
-
const proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
|
|
6
|
-
if (proxyUrl) {
|
|
7
|
-
try {
|
|
8
|
-
const { setGlobalDispatcher, ProxyAgent } = await import('undici');
|
|
9
|
-
setGlobalDispatcher(new ProxyAgent(proxyUrl));
|
|
10
|
-
proxyConfigured = true;
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
// ProxyAgent not available, continue without proxy
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
1
|
export function createTelegramProvider(config, logger) {
|
|
18
2
|
const { botToken, chatId } = config;
|
|
19
3
|
return {
|
|
20
4
|
async send(template) {
|
|
21
5
|
const start = Date.now();
|
|
22
6
|
try {
|
|
23
|
-
|
|
7
|
+
// Note: Proxy configuration is not supported in Cloudflare Edge Runtime.
|
|
8
|
+
// If you need proxy support, consider using a dedicated proxy service
|
|
9
|
+
// or running the notification service in a Node.js environment.
|
|
24
10
|
const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
|
|
25
11
|
const response = await fetch(url, {
|
|
26
12
|
method: 'POST',
|
|
@@ -74,6 +74,12 @@ export function emailTemplate(event) {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
function escapeHtml(text) {
|
|
77
|
+
if (text === null || text === undefined) {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
if (typeof text !== 'string') {
|
|
81
|
+
return String(text);
|
|
82
|
+
}
|
|
77
83
|
return text
|
|
78
84
|
.replace(/&/g, '&')
|
|
79
85
|
.replace(/</g, '<')
|
package/package.json
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astro-minimax/notify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Multi-channel notification package for astro-minimax blogs",
|
|
5
|
+
"description": "Multi-channel notification package for astro-minimax blogs — supports Telegram, Email (Resend), and more.",
|
|
6
6
|
"author": "Souloss",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"astro",
|
|
10
|
+
"notification",
|
|
11
|
+
"telegram",
|
|
12
|
+
"email",
|
|
13
|
+
"resend",
|
|
14
|
+
"webhook"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/souloss/astro-minimax#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/souloss/astro-minimax/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/souloss/astro-minimax",
|
|
23
|
+
"directory": "packages/notify"
|
|
24
|
+
},
|
|
8
25
|
"main": "./dist/index.js",
|
|
9
26
|
"types": "./dist/index.d.ts",
|
|
10
27
|
"exports": {
|
|
@@ -18,15 +35,10 @@
|
|
|
18
35
|
"dist/"
|
|
19
36
|
],
|
|
20
37
|
"sideEffects": false,
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "tsc -p tsconfig.build.json",
|
|
23
|
-
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
24
|
-
"clean": "rm -rf dist",
|
|
25
|
-
"prepublishOnly": "pnpm run clean && pnpm run build",
|
|
26
|
-
"publish": "npm publish --access public"
|
|
27
|
-
},
|
|
28
38
|
"dependencies": {
|
|
29
|
-
"grammy": "^1.41.1"
|
|
39
|
+
"grammy": "^1.41.1"
|
|
40
|
+
},
|
|
41
|
+
"optionalDependencies": {
|
|
30
42
|
"undici": "^6.0.0"
|
|
31
43
|
},
|
|
32
44
|
"peerDependencies": {
|
|
@@ -43,6 +55,13 @@
|
|
|
43
55
|
"typescript": "^5.9.3"
|
|
44
56
|
},
|
|
45
57
|
"engines": {
|
|
46
|
-
"node": ">=22.12.0"
|
|
58
|
+
"node": ">=22.12.0",
|
|
59
|
+
"pnpm": ">=9.0.0"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc -p tsconfig.build.json",
|
|
63
|
+
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"clean": "rm -rf dist"
|
|
47
66
|
}
|
|
48
|
-
}
|
|
67
|
+
}
|