@dilipod/ui 0.4.29 → 0.4.30

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.
@@ -0,0 +1,83 @@
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
+ export interface SlackBlock {
10
+ type: string;
11
+ text?: {
12
+ type: string;
13
+ text: string;
14
+ };
15
+ elements?: SlackElement[];
16
+ fields?: SlackField[];
17
+ }
18
+ export interface SlackElement {
19
+ type: string;
20
+ text?: {
21
+ type: string;
22
+ text: string;
23
+ };
24
+ style?: string;
25
+ value?: string;
26
+ url?: string;
27
+ action_id?: string;
28
+ }
29
+ export interface SlackField {
30
+ type: string;
31
+ text: string;
32
+ }
33
+ export interface SlackMessage {
34
+ text: string;
35
+ blocks: SlackBlock[];
36
+ }
37
+ /**
38
+ * Build a single mrkdwn section block.
39
+ *
40
+ * slackSection('*Hello* world')
41
+ */
42
+ export declare function slackSection(mrkdwn: string): SlackBlock;
43
+ /**
44
+ * Build a key-value fields block.
45
+ *
46
+ * slackFields({ Worker: 'Invoice Bot', Status: 'Live' })
47
+ */
48
+ export declare function slackFields(fields: Record<string, string | number>): SlackBlock;
49
+ /**
50
+ * Build an actions block with buttons.
51
+ *
52
+ * slackActions([
53
+ * { text: 'View', url: 'https://...' },
54
+ * { text: 'Approve', actionId: 'approve', style: 'primary', value: '123' },
55
+ * ])
56
+ */
57
+ export declare function slackActions(buttons: {
58
+ text: string;
59
+ url?: string;
60
+ value?: string;
61
+ actionId?: string;
62
+ style?: 'primary' | 'danger';
63
+ }[]): SlackBlock;
64
+ /**
65
+ * Build a complete Slack message with optional details, note, and button.
66
+ * Covers 90% of notification use cases.
67
+ *
68
+ * slackMessage({
69
+ * title: '🚀 New signup',
70
+ * details: { Name: 'John', Email: 'john@acme.com' },
71
+ * note: 'First user from this company',
72
+ * buttonText: 'View Customer',
73
+ * buttonUrl: 'https://admin.dilipod.com/customers/123',
74
+ * })
75
+ */
76
+ export declare function slackMessage(options: {
77
+ title: string;
78
+ details?: Record<string, string | number>;
79
+ note?: string;
80
+ buttonText?: string;
81
+ buttonUrl?: string;
82
+ }): SlackMessage;
83
+ //# sourceMappingURL=slack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../src/lib/slack.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACrC,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAA;IACzB,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACrC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,UAAU,EAAE,CAAA;CACrB;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAKvD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,UAAU,CAQ/E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE;IACP,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;CAC7B,EAAE,GACF,UAAU,CAYZ;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACpC,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;IACzC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,YAAY,CAmBf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dilipod/ui",
3
- "version": "0.4.29",
3
+ "version": "0.4.30",
4
4
  "description": "Dilipod Design System - Shared UI components and styles",
5
5
  "author": "Dilipod <hello@dilipod.com>",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -318,6 +318,10 @@ export { formatCentsToEuros, formatEuros, formatDuration, formatRelativeTime } f
318
318
  // Email Template Helpers
319
319
  export { emailTemplate, buttonHtml, infoBoxHtml, noteBoxHtml } from './lib/email'
320
320
 
321
+ // Slack Block Kit Helpers
322
+ export { slackMessage, slackSection, slackFields, slackActions } from './lib/slack'
323
+ export type { SlackBlock, SlackElement, SlackField, SlackMessage } from './lib/slack'
324
+
321
325
  // Utilities
322
326
  export { cn } from './lib/utils'
323
327
 
@@ -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
+ }