@mantiq/notify 0.2.1 → 0.3.0-rc.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantiq/notify",
3
- "version": "0.2.1",
3
+ "version": "0.3.0-rc.2",
4
4
  "description": "Multi-channel notifications — mail, database, broadcast, SMS, Slack, webhook",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,14 +43,21 @@
43
43
  "LICENSE"
44
44
  ],
45
45
  "scripts": {
46
- "build": "bun build ./src/index.ts --outdir ./dist --target bun",
46
+ "build": "bun build ./src/index.ts --outdir ./dist --target bun --packages=external",
47
47
  "test": "bun test",
48
48
  "typecheck": "tsc --noEmit",
49
49
  "clean": "rm -rf dist"
50
50
  },
51
51
  "devDependencies": {
52
52
  "bun-types": "latest",
53
- "typescript": "^5.7.0"
53
+ "typescript": "^5.7.0",
54
+ "@mantiq/core": "workspace:*",
55
+ "@mantiq/database": "workspace:*",
56
+ "@mantiq/mail": "workspace:*",
57
+ "@mantiq/events": "workspace:*",
58
+ "@mantiq/realtime": "workspace:*",
59
+ "@mantiq/queue": "workspace:*",
60
+ "@mantiq/cli": "workspace:*"
54
61
  },
55
62
  "peerDependencies": {
56
63
  "@mantiq/core": "^0.1.0",
@@ -60,5 +67,8 @@
60
67
  "@mantiq/realtime": "^0.1.0",
61
68
  "@mantiq/queue": "^0.1.0",
62
69
  "@mantiq/cli": "^0.1.0"
70
+ },
71
+ "mantiq": {
72
+ "provider": "NotificationServiceProvider"
63
73
  }
64
74
  }
@@ -2,30 +2,30 @@ import type { Notifiable } from './contracts/Notifiable.ts'
2
2
  import type { Mailable } from '@mantiq/mail'
3
3
 
4
4
  export interface SlackMessage {
5
- text?: string
6
- blocks?: any[]
7
- channel?: string
8
- username?: string
9
- iconEmoji?: string
10
- iconUrl?: string
5
+ text?: string | undefined
6
+ blocks?: any[] | undefined
7
+ channel?: string | undefined
8
+ username?: string | undefined
9
+ iconEmoji?: string | undefined
10
+ iconUrl?: string | undefined
11
11
  }
12
12
 
13
13
  export interface BroadcastPayload {
14
14
  event: string
15
15
  data: any
16
- channel?: string
16
+ channel?: string | undefined
17
17
  }
18
18
 
19
19
  export interface SmsPayload {
20
- to?: string
20
+ to?: string | undefined
21
21
  body: string
22
22
  }
23
23
 
24
24
  export interface WebhookPayload {
25
25
  url: string
26
26
  body: any
27
- method?: 'POST' | 'PUT' | 'PATCH'
28
- headers?: Record<string, string>
27
+ method?: 'POST' | 'PUT' | 'PATCH' | undefined
28
+ headers?: Record<string, string> | undefined
29
29
  }
30
30
 
31
31
  /**
@@ -72,10 +72,10 @@ export abstract class Notification {
72
72
  shouldQueue = false
73
73
 
74
74
  /** Queue name override */
75
- queue?: string
75
+ queue?: string | undefined
76
76
 
77
77
  /** Queue connection override */
78
- connection?: string
78
+ connection?: string | undefined
79
79
 
80
80
  /** Max retry attempts */
81
81
  tries = 3
@@ -4,24 +4,24 @@ import type { Notification } from '../Notification.ts'
4
4
  import { NotifyError } from '../errors/NotifyError.ts'
5
5
 
6
6
  export interface DiscordEmbed {
7
- title?: string
8
- description?: string
9
- url?: string
10
- color?: number
11
- fields?: Array<{ name: string; value: string; inline?: boolean }>
12
- footer?: { text: string; icon_url?: string }
13
- thumbnail?: { url: string }
14
- image?: { url: string }
15
- author?: { name: string; url?: string; icon_url?: string }
16
- timestamp?: string
7
+ title?: string | undefined
8
+ description?: string | undefined
9
+ url?: string | undefined
10
+ color?: number | undefined
11
+ fields?: Array<{ name: string; value: string; inline?: boolean | undefined }> | undefined
12
+ footer?: { text: string; icon_url?: string | undefined } | undefined
13
+ thumbnail?: { url: string } | undefined
14
+ image?: { url: string } | undefined
15
+ author?: { name: string; url?: string | undefined; icon_url?: string | undefined } | undefined
16
+ timestamp?: string | undefined
17
17
  }
18
18
 
19
19
  export interface DiscordPayload {
20
20
  webhookUrl: string
21
- content?: string
22
- embeds?: DiscordEmbed[]
23
- username?: string
24
- avatarUrl?: string
21
+ content?: string | undefined
22
+ embeds?: DiscordEmbed[] | undefined
23
+ username?: string | undefined
24
+ avatarUrl?: string | undefined
25
25
  }
26
26
 
27
27
  /**
@@ -5,17 +5,17 @@ import { NotifyError } from '../errors/NotifyError.ts'
5
5
 
6
6
  export interface FirebaseConfig {
7
7
  projectId: string
8
- accessToken?: string
9
- serviceAccountKey?: string
8
+ accessToken?: string | undefined
9
+ serviceAccountKey?: string | undefined
10
10
  }
11
11
 
12
12
  export interface FirebasePayload {
13
- token?: string
14
- topic?: string
13
+ token?: string | undefined
14
+ topic?: string | undefined
15
15
  title: string
16
16
  body: string
17
- data?: Record<string, string>
18
- imageUrl?: string
17
+ data?: Record<string, string> | undefined
18
+ imageUrl?: string | undefined
19
19
  }
20
20
 
21
21
  /**
@@ -164,7 +164,7 @@ export class FirebaseChannel implements NotificationChannel {
164
164
  })
165
165
  }
166
166
 
167
- const result = await response.json()
167
+ const result = (await response.json()) as any
168
168
  this.cachedAccessToken = result.access_token
169
169
  this.tokenExpiresAt = Date.now() + (result.expires_in ?? 3600) * 1000
170
170
 
@@ -9,7 +9,7 @@ export interface IMessageConfig {
9
9
  }
10
10
 
11
11
  export interface IMessagePayload {
12
- to?: string
12
+ to?: string | undefined
13
13
  text: string
14
14
  interactiveData?: any
15
15
  }
@@ -9,10 +9,10 @@ export interface RcsConfig {
9
9
  }
10
10
 
11
11
  export interface RcsPayload {
12
- to?: string
13
- text?: string
12
+ to?: string | undefined
13
+ text?: string | undefined
14
14
  richCard?: any
15
- suggestions?: any[]
15
+ suggestions?: any[] | undefined
16
16
  }
17
17
 
18
18
  /**
@@ -115,7 +115,7 @@ export class SlackChannel implements NotificationChannel {
115
115
  }
116
116
 
117
117
  // Slack API returns 200 even on failure — check the `ok` field
118
- const result = await response.json().catch(() => null)
118
+ const result: any = await response.json().catch(() => null)
119
119
  if (result && !result.ok) {
120
120
  throw new NotifyError(`Slack API error: ${result.error ?? 'unknown error'}`, {
121
121
  channel: this.name,
@@ -133,7 +133,7 @@ export class SmsChannel implements NotificationChannel {
133
133
  }
134
134
 
135
135
  // Vonage returns 200 even on failure — check the response body
136
- const result = await response.json().catch(() => null)
136
+ const result: any = await response.json().catch(() => null)
137
137
  if (result?.messages?.[0]?.status !== '0') {
138
138
  const errorText = result?.messages?.[0]?.['error-text'] ?? 'Unknown Vonage error'
139
139
  throw new NotifyError(`Vonage delivery failed: ${errorText}`, {
@@ -8,9 +8,9 @@ export interface TelegramConfig {
8
8
  }
9
9
 
10
10
  export interface TelegramPayload {
11
- chatId?: string | number
11
+ chatId?: string | number | undefined
12
12
  text: string
13
- parseMode?: 'HTML' | 'Markdown' | 'MarkdownV2'
13
+ parseMode?: 'HTML' | 'Markdown' | 'MarkdownV2' | undefined
14
14
  replyMarkup?: any
15
15
  }
16
16
 
@@ -64,7 +64,7 @@ export class TelegramChannel implements NotificationChannel {
64
64
  })
65
65
  }
66
66
 
67
- const result = await response.json().catch(() => null)
67
+ const result: any = await response.json().catch(() => null)
68
68
  if (result && !result.ok) {
69
69
  throw new NotifyError(`Telegram API error: ${result.description ?? 'unknown error'}`, {
70
70
  channel: this.name,
@@ -9,13 +9,13 @@ export interface WhatsAppConfig {
9
9
  }
10
10
 
11
11
  export interface WhatsAppPayload {
12
- to?: string
12
+ to?: string | undefined
13
13
  template?: {
14
14
  name: string
15
15
  languageCode: string
16
- components?: any[]
17
- }
18
- text?: string
16
+ components?: any[] | undefined
17
+ } | undefined
18
+ text?: string | undefined
19
19
  }
20
20
 
21
21
  /**
@@ -91,7 +91,7 @@ export class WhatsAppChannel implements NotificationChannel {
91
91
  })
92
92
  }
93
93
 
94
- const result = await response.json().catch(() => null)
94
+ const result: any = await response.json().catch(() => null)
95
95
  if (result?.error) {
96
96
  throw new NotifyError(`WhatsApp API error: ${result.error.message ?? 'unknown error'}`, {
97
97
  channel: this.name,
@@ -1,12 +1,12 @@
1
1
  export interface SmsConfig {
2
2
  driver: 'twilio' | 'vonage'
3
- twilio?: { sid: string; token: string; from: string }
4
- vonage?: { apiKey: string; apiSecret: string; from: string }
3
+ twilio?: { sid: string; token: string; from: string } | undefined
4
+ vonage?: { apiKey: string; apiSecret: string; from: string } | undefined
5
5
  }
6
6
 
7
7
  export interface SlackConfig {
8
- webhookUrl?: string
9
- token?: string
8
+ webhookUrl?: string | undefined
9
+ token?: string | undefined
10
10
  }
11
11
 
12
12
  export interface TelegramConfig {
@@ -30,20 +30,20 @@ export interface RcsConfig {
30
30
 
31
31
  export interface FirebaseConfig {
32
32
  projectId: string
33
- accessToken?: string
34
- serviceAccountKey?: string
33
+ accessToken?: string | undefined
34
+ serviceAccountKey?: string | undefined
35
35
  }
36
36
 
37
37
  export interface NotifyConfig {
38
38
  channels?: {
39
- sms?: SmsConfig
40
- slack?: SlackConfig
41
- telegram?: TelegramConfig
42
- whatsapp?: WhatsAppConfig
43
- imessage?: IMessageConfig
44
- rcs?: RcsConfig
45
- firebase?: FirebaseConfig
46
- }
39
+ sms?: SmsConfig | undefined
40
+ slack?: SlackConfig | undefined
41
+ telegram?: TelegramConfig | undefined
42
+ whatsapp?: WhatsAppConfig | undefined
43
+ imessage?: IMessageConfig | undefined
44
+ rcs?: RcsConfig | undefined
45
+ firebase?: FirebaseConfig | undefined
46
+ } | undefined
47
47
  }
48
48
 
49
49
  export const DEFAULT_CONFIG: NotifyConfig = {
@@ -3,7 +3,7 @@ import type { Notifiable } from '../contracts/Notifiable.ts'
3
3
  import type { Notification } from '../Notification.ts'
4
4
 
5
5
  export class SendNotificationJob extends Job {
6
- override name = 'notify:send'
6
+ name = 'notify:send'
7
7
  override tries = 3
8
8
 
9
9
  constructor(