@astro-minimax/notify 0.5.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/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/templates/comment.js +6 -0
- package/package.json +1 -1
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);
|
|
@@ -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