@dilipod/ui 0.4.29 → 0.4.31
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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -1
- package/dist/index.mjs.map +1 -1
- package/dist/lib/slack.d.ts +83 -0
- package/dist/lib/slack.d.ts.map +1 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +195 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +181 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +6 -1
- package/src/index.ts +4 -0
- package/src/lib/slack.ts +142 -0
- package/src/server.ts +20 -0
package/src/lib/slack.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack Block Kit Helpers
|
|
3
|
+
*
|
|
4
|
+
* Shared Slack message and block builders used by both platform and admin apps.
|
|
5
|
+
* Pure functions with zero dependencies — same pattern as email.ts.
|
|
6
|
+
*
|
|
7
|
+
* Transport layers (sendSlackMessage, sendSlackWebhook) stay local in each app.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// ============================================
|
|
11
|
+
// Types
|
|
12
|
+
// ============================================
|
|
13
|
+
|
|
14
|
+
export interface SlackBlock {
|
|
15
|
+
type: string
|
|
16
|
+
text?: { type: string; text: string }
|
|
17
|
+
elements?: SlackElement[]
|
|
18
|
+
fields?: SlackField[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SlackElement {
|
|
22
|
+
type: string
|
|
23
|
+
text?: { type: string; text: string }
|
|
24
|
+
style?: string
|
|
25
|
+
value?: string
|
|
26
|
+
url?: string
|
|
27
|
+
action_id?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SlackField {
|
|
31
|
+
type: string
|
|
32
|
+
text: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SlackMessage {
|
|
36
|
+
text: string
|
|
37
|
+
blocks: SlackBlock[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ============================================
|
|
41
|
+
// Block Builders
|
|
42
|
+
// ============================================
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Build a single mrkdwn section block.
|
|
46
|
+
*
|
|
47
|
+
* slackSection('*Hello* world')
|
|
48
|
+
*/
|
|
49
|
+
export function slackSection(mrkdwn: string): SlackBlock {
|
|
50
|
+
return {
|
|
51
|
+
type: 'section',
|
|
52
|
+
text: { type: 'mrkdwn', text: mrkdwn },
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Build a key-value fields block.
|
|
58
|
+
*
|
|
59
|
+
* slackFields({ Worker: 'Invoice Bot', Status: 'Live' })
|
|
60
|
+
*/
|
|
61
|
+
export function slackFields(fields: Record<string, string | number>): SlackBlock {
|
|
62
|
+
return {
|
|
63
|
+
type: 'section',
|
|
64
|
+
fields: Object.entries(fields).map(([key, value]) => ({
|
|
65
|
+
type: 'mrkdwn',
|
|
66
|
+
text: `*${key}:*\n${value}`,
|
|
67
|
+
})),
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Build an actions block with buttons.
|
|
73
|
+
*
|
|
74
|
+
* slackActions([
|
|
75
|
+
* { text: 'View', url: 'https://...' },
|
|
76
|
+
* { text: 'Approve', actionId: 'approve', style: 'primary', value: '123' },
|
|
77
|
+
* ])
|
|
78
|
+
*/
|
|
79
|
+
export function slackActions(
|
|
80
|
+
buttons: {
|
|
81
|
+
text: string
|
|
82
|
+
url?: string
|
|
83
|
+
value?: string
|
|
84
|
+
actionId?: string
|
|
85
|
+
style?: 'primary' | 'danger'
|
|
86
|
+
}[]
|
|
87
|
+
): SlackBlock {
|
|
88
|
+
return {
|
|
89
|
+
type: 'actions',
|
|
90
|
+
elements: buttons.map((btn) => ({
|
|
91
|
+
type: 'button',
|
|
92
|
+
text: { type: 'plain_text', text: btn.text },
|
|
93
|
+
...(btn.url ? { url: btn.url } : {}),
|
|
94
|
+
...(btn.value ? { value: btn.value } : {}),
|
|
95
|
+
...(btn.actionId ? { action_id: btn.actionId } : {}),
|
|
96
|
+
...(btn.style ? { style: btn.style } : {}),
|
|
97
|
+
})),
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ============================================
|
|
102
|
+
// Message Builder
|
|
103
|
+
// ============================================
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Build a complete Slack message with optional details, note, and button.
|
|
107
|
+
* Covers 90% of notification use cases.
|
|
108
|
+
*
|
|
109
|
+
* slackMessage({
|
|
110
|
+
* title: '🚀 New signup',
|
|
111
|
+
* details: { Name: 'John', Email: 'john@acme.com' },
|
|
112
|
+
* note: 'First user from this company',
|
|
113
|
+
* buttonText: 'View Customer',
|
|
114
|
+
* buttonUrl: 'https://admin.dilipod.com/customers/123',
|
|
115
|
+
* })
|
|
116
|
+
*/
|
|
117
|
+
export function slackMessage(options: {
|
|
118
|
+
title: string
|
|
119
|
+
details?: Record<string, string | number>
|
|
120
|
+
note?: string
|
|
121
|
+
buttonText?: string
|
|
122
|
+
buttonUrl?: string
|
|
123
|
+
}): SlackMessage {
|
|
124
|
+
const blocks: SlackBlock[] = [slackSection(`*${options.title}*`)]
|
|
125
|
+
|
|
126
|
+
if (options.details && Object.keys(options.details).length > 0) {
|
|
127
|
+
blocks.push(slackFields(options.details))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (options.note) {
|
|
131
|
+
blocks.push(slackSection(options.note))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (options.buttonUrl && options.buttonText) {
|
|
135
|
+
blocks.push(slackActions([{ text: options.buttonText, url: options.buttonUrl }]))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
text: options.title,
|
|
140
|
+
blocks,
|
|
141
|
+
}
|
|
142
|
+
}
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-safe exports from @dilipod/ui
|
|
3
|
+
*
|
|
4
|
+
* This entry point does NOT include the "use client" directive,
|
|
5
|
+
* so these utilities can be safely used in Next.js API routes,
|
|
6
|
+
* server actions, and other server-side code.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Email Template Helpers
|
|
10
|
+
export { emailTemplate, buttonHtml, infoBoxHtml, noteBoxHtml } from './lib/email'
|
|
11
|
+
|
|
12
|
+
// Slack Block Kit Helpers
|
|
13
|
+
export { slackMessage, slackSection, slackFields, slackActions } from './lib/slack'
|
|
14
|
+
export type { SlackBlock, SlackElement, SlackField, SlackMessage } from './lib/slack'
|
|
15
|
+
|
|
16
|
+
// Formatting Utilities
|
|
17
|
+
export { formatCentsToEuros, formatEuros, formatDuration, formatRelativeTime } from './lib/formatting'
|
|
18
|
+
|
|
19
|
+
// General Utilities
|
|
20
|
+
export { cn } from './lib/utils'
|