@brokr/sdk 1.0.0 → 2.0.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/dist/account.js +34 -0
- package/dist/account.mjs +7 -0
- package/dist/auth.js +628 -114
- package/dist/auth.mjs +611 -111
- package/dist/chat.js +34 -0
- package/dist/chat.mjs +7 -0
- package/dist/events.js +64 -0
- package/dist/events.mjs +37 -0
- package/dist/feature.js +6304 -0
- package/dist/feature.mjs +6278 -0
- package/dist/files.js +428 -0
- package/dist/files.mjs +408 -0
- package/dist/index.d.ts +18 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4069 -454
- package/dist/index.mjs +4040 -448
- package/dist/logs.js +148 -0
- package/dist/logs.mjs +124 -0
- package/dist/management.js +14 -13
- package/dist/management.mjs +14 -13
- package/dist/next.js +2725 -0
- package/dist/next.mjs +2710 -0
- package/dist/notifications.js +140 -0
- package/dist/notifications.mjs +110 -0
- package/dist/payments.js +32 -0
- package/dist/payments.mjs +7 -0
- package/dist/react-notifications.js +286 -0
- package/dist/react-notifications.mjs +254 -0
- package/dist/react-styles.js +2718 -0
- package/dist/react-styles.mjs +2682 -0
- package/dist/react-theme.js +4194 -0
- package/dist/react-theme.mjs +4170 -0
- package/dist/react.js +8512 -209
- package/dist/react.mjs +8488 -179
- package/dist/runtime.js +2113 -385
- package/dist/runtime.mjs +2085 -397
- package/dist/src/account/config.d.ts +42 -0
- package/dist/src/account/config.d.ts.map +1 -0
- package/dist/src/account/index.d.ts +3 -0
- package/dist/src/account/index.d.ts.map +1 -0
- package/dist/src/ai/client.d.ts +58 -0
- package/dist/src/ai/client.d.ts.map +1 -0
- package/dist/src/ai/conversation-title.d.ts +13 -0
- package/dist/src/ai/conversation-title.d.ts.map +1 -0
- package/dist/src/ai/types.d.ts +81 -0
- package/dist/src/ai/types.d.ts.map +1 -0
- package/dist/src/auth.d.ts +133 -20
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/chat/config.d.ts +61 -0
- package/dist/src/chat/config.d.ts.map +1 -0
- package/dist/src/chat/index.d.ts +3 -0
- package/dist/src/chat/index.d.ts.map +1 -0
- package/dist/src/chat/sse-parser.d.ts +44 -0
- package/dist/src/chat/sse-parser.d.ts.map +1 -0
- package/dist/src/dev-console.d.ts +18 -0
- package/dist/src/dev-console.d.ts.map +1 -0
- package/dist/src/email/client.d.ts +33 -0
- package/dist/src/email/client.d.ts.map +1 -0
- package/dist/src/email/templates.d.ts +15 -0
- package/dist/src/email/templates.d.ts.map +1 -0
- package/dist/src/email/types.d.ts +35 -0
- package/dist/src/email/types.d.ts.map +1 -0
- package/dist/src/env-detect.d.ts +25 -0
- package/dist/src/env-detect.d.ts.map +1 -0
- package/dist/src/errors.d.ts +53 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/events/client.d.ts +25 -0
- package/dist/src/events/client.d.ts.map +1 -0
- package/dist/src/events/index.d.ts +9 -0
- package/dist/src/events/index.d.ts.map +1 -0
- package/dist/src/events/types.d.ts +10 -0
- package/dist/src/events/types.d.ts.map +1 -0
- package/dist/src/feature/canonical.d.ts +33 -0
- package/dist/src/feature/canonical.d.ts.map +1 -0
- package/dist/src/feature/create-feature.d.ts +33 -0
- package/dist/src/feature/create-feature.d.ts.map +1 -0
- package/dist/src/feature/db.d.ts +16 -0
- package/dist/src/feature/db.d.ts.map +1 -0
- package/dist/src/feature/handlers.d.ts +28 -0
- package/dist/src/feature/handlers.d.ts.map +1 -0
- package/dist/src/feature/index.d.ts +21 -0
- package/dist/src/feature/index.d.ts.map +1 -0
- package/dist/src/feature/manifest.d.ts +173 -0
- package/dist/src/feature/manifest.d.ts.map +1 -0
- package/dist/src/feature/mapping.d.ts +18 -0
- package/dist/src/feature/mapping.d.ts.map +1 -0
- package/dist/src/feature/runtime.d.ts +45 -0
- package/dist/src/feature/runtime.d.ts.map +1 -0
- package/dist/src/feature/types.d.ts +65 -0
- package/dist/src/feature/types.d.ts.map +1 -0
- package/dist/src/files/client.d.ts +28 -0
- package/dist/src/files/client.d.ts.map +1 -0
- package/dist/src/files/types.d.ts +28 -0
- package/dist/src/files/types.d.ts.map +1 -0
- package/dist/src/fix-registry.d.ts +8 -0
- package/dist/src/fix-registry.d.ts.map +1 -0
- package/dist/src/gateway.d.ts +32 -0
- package/dist/src/gateway.d.ts.map +1 -0
- package/dist/src/logs/capture.d.ts +56 -0
- package/dist/src/logs/capture.d.ts.map +1 -0
- package/dist/src/logs/index.d.ts +2 -0
- package/dist/src/logs/index.d.ts.map +1 -0
- package/dist/src/management.d.ts +1 -1
- package/dist/src/management.d.ts.map +1 -1
- package/dist/src/models.d.ts +32 -0
- package/dist/src/models.d.ts.map +1 -0
- package/dist/src/next/auth.d.ts +54 -0
- package/dist/src/next/auth.d.ts.map +1 -0
- package/dist/src/next/chat.d.ts +31 -0
- package/dist/src/next/chat.d.ts.map +1 -0
- package/dist/src/next/index.d.ts +14 -0
- package/dist/src/next/index.d.ts.map +1 -0
- package/dist/src/next/notifications.d.ts +67 -0
- package/dist/src/next/notifications.d.ts.map +1 -0
- package/dist/src/notifications/built-ins.d.ts +9 -0
- package/dist/src/notifications/built-ins.d.ts.map +1 -0
- package/dist/src/notifications/client.d.ts +38 -0
- package/dist/src/notifications/client.d.ts.map +1 -0
- package/dist/src/notifications/config.d.ts +71 -0
- package/dist/src/notifications/config.d.ts.map +1 -0
- package/dist/src/notifications/index.d.ts +6 -0
- package/dist/src/notifications/index.d.ts.map +1 -0
- package/dist/src/notifications/registry.d.ts +67 -0
- package/dist/src/notifications/registry.d.ts.map +1 -0
- package/dist/src/notifications/types.d.ts +48 -0
- package/dist/src/notifications/types.d.ts.map +1 -0
- package/dist/src/payments/client.d.ts +64 -0
- package/dist/src/payments/client.d.ts.map +1 -0
- package/dist/src/payments/config.d.ts +46 -0
- package/dist/src/payments/config.d.ts.map +1 -0
- package/dist/src/payments/entitlements.d.ts +48 -0
- package/dist/src/payments/entitlements.d.ts.map +1 -0
- package/dist/src/payments/types.d.ts +135 -0
- package/dist/src/payments/types.d.ts.map +1 -0
- package/dist/src/react/BrokrErrorBoundary.d.ts +23 -0
- package/dist/src/react/BrokrErrorBoundary.d.ts.map +1 -0
- package/dist/src/react/account/AccountPanel.d.ts +12 -0
- package/dist/src/react/account/AccountPanel.d.ts.map +1 -0
- package/dist/src/react/account/Avatar.d.ts +11 -0
- package/dist/src/react/account/Avatar.d.ts.map +1 -0
- package/dist/src/react/account/ProfilePhotoButton.d.ts +7 -0
- package/dist/src/react/account/ProfilePhotoButton.d.ts.map +1 -0
- package/dist/src/react/account/UserButton.d.ts +7 -0
- package/dist/src/react/account/UserButton.d.ts.map +1 -0
- package/dist/src/react/auth-pages/AuthPageShell.d.ts +9 -0
- package/dist/src/react/auth-pages/AuthPageShell.d.ts.map +1 -0
- package/dist/src/react/auth-pages/SignInPage.d.ts +9 -0
- package/dist/src/react/auth-pages/SignInPage.d.ts.map +1 -0
- package/dist/src/react/auth-pages/SignUpPage.d.ts +8 -0
- package/dist/src/react/auth-pages/SignUpPage.d.ts.map +1 -0
- package/dist/src/react/auth.d.ts +1 -49
- package/dist/src/react/auth.d.ts.map +1 -1
- package/dist/src/react/chat/AIChat.d.ts +4 -0
- package/dist/src/react/chat/AIChat.d.ts.map +1 -0
- package/dist/src/react/chat/ChatContext.d.ts +76 -0
- package/dist/src/react/chat/ChatContext.d.ts.map +1 -0
- package/dist/src/react/chat/ChatInput.d.ts +3 -0
- package/dist/src/react/chat/ChatInput.d.ts.map +1 -0
- package/dist/src/react/chat/MarkdownRenderer.d.ts +5 -0
- package/dist/src/react/chat/MarkdownRenderer.d.ts.map +1 -0
- package/dist/src/react/chat/MessageBubble.d.ts +14 -0
- package/dist/src/react/chat/MessageBubble.d.ts.map +1 -0
- package/dist/src/react/chat/MessagePane.d.ts +10 -0
- package/dist/src/react/chat/MessagePane.d.ts.map +1 -0
- package/dist/src/react/chat/ModelSelector.d.ts +13 -0
- package/dist/src/react/chat/ModelSelector.d.ts.map +1 -0
- package/dist/src/react/chat/ThreadSidebar.d.ts +3 -0
- package/dist/src/react/chat/ThreadSidebar.d.ts.map +1 -0
- package/dist/src/react/chat/index.d.ts +5 -0
- package/dist/src/react/chat/index.d.ts.map +1 -0
- package/dist/src/react/chat/token-limit.d.ts +14 -0
- package/dist/src/react/chat/token-limit.d.ts.map +1 -0
- package/dist/src/react/chat/types.d.ts +65 -0
- package/dist/src/react/chat/types.d.ts.map +1 -0
- package/dist/src/react/chat/useChat.d.ts +57 -0
- package/dist/src/react/chat/useChat.d.ts.map +1 -0
- package/dist/src/react/composites/FabAI.d.ts +15 -0
- package/dist/src/react/composites/FabAI.d.ts.map +1 -0
- package/dist/src/react/composites/FeedbackWidget.d.ts +10 -0
- package/dist/src/react/composites/FeedbackWidget.d.ts.map +1 -0
- package/dist/src/react/composites/SmartUpload.d.ts +12 -0
- package/dist/src/react/composites/SmartUpload.d.ts.map +1 -0
- package/dist/src/react/config.d.ts +23 -0
- package/dist/src/react/config.d.ts.map +1 -0
- package/dist/src/react/context.d.ts +4 -0
- package/dist/src/react/context.d.ts.map +1 -0
- package/dist/src/react/css/account.d.ts +2 -0
- package/dist/src/react/css/account.d.ts.map +1 -0
- package/dist/src/react/css/animations.d.ts +2 -0
- package/dist/src/react/css/animations.d.ts.map +1 -0
- package/dist/src/react/css/auth.d.ts +2 -0
- package/dist/src/react/css/auth.d.ts.map +1 -0
- package/dist/src/react/css/chat-extras.d.ts +2 -0
- package/dist/src/react/css/chat-extras.d.ts.map +1 -0
- package/dist/src/react/css/chat.d.ts +2 -0
- package/dist/src/react/css/chat.d.ts.map +1 -0
- package/dist/src/react/css/composites.d.ts +2 -0
- package/dist/src/react/css/composites.d.ts.map +1 -0
- package/dist/src/react/css/gates.d.ts +2 -0
- package/dist/src/react/css/gates.d.ts.map +1 -0
- package/dist/src/react/css/index.d.ts +3 -0
- package/dist/src/react/css/index.d.ts.map +1 -0
- package/dist/src/react/css/markdown.d.ts +2 -0
- package/dist/src/react/css/markdown.d.ts.map +1 -0
- package/dist/src/react/css/notifications.d.ts +2 -0
- package/dist/src/react/css/notifications.d.ts.map +1 -0
- package/dist/src/react/css/primitives.d.ts +2 -0
- package/dist/src/react/css/primitives.d.ts.map +1 -0
- package/dist/src/react/css/reset.d.ts +2 -0
- package/dist/src/react/css/reset.d.ts.map +1 -0
- package/dist/src/react/css/responsive.d.ts +2 -0
- package/dist/src/react/css/responsive.d.ts.map +1 -0
- package/dist/src/react/css/skeleton.d.ts +2 -0
- package/dist/src/react/css/skeleton.d.ts.map +1 -0
- package/dist/src/react/css/tokens.d.ts +2 -0
- package/dist/src/react/css/tokens.d.ts.map +1 -0
- package/dist/src/react/gates/AuthWall.d.ts +7 -0
- package/dist/src/react/gates/AuthWall.d.ts.map +1 -0
- package/dist/src/react/gates/BillingBoundary.d.ts +4 -0
- package/dist/src/react/gates/BillingBoundary.d.ts.map +1 -0
- package/dist/src/react/gates/Gate.d.ts +9 -0
- package/dist/src/react/gates/Gate.d.ts.map +1 -0
- package/dist/src/react/gates/RequirePlan.d.ts +4 -0
- package/dist/src/react/gates/RequirePlan.d.ts.map +1 -0
- package/dist/src/react/gates/RequireUser.d.ts +4 -0
- package/dist/src/react/gates/RequireUser.d.ts.map +1 -0
- package/dist/src/react/gates/UsageGate.d.ts +4 -0
- package/dist/src/react/gates/UsageGate.d.ts.map +1 -0
- package/dist/src/react/helpers.d.ts +7 -0
- package/dist/src/react/helpers.d.ts.map +1 -0
- package/dist/src/react/hooks/use-theme.d.ts +15 -0
- package/dist/src/react/hooks/use-theme.d.ts.map +1 -0
- package/dist/src/react/hooks/use-user.d.ts +12 -0
- package/dist/src/react/hooks/use-user.d.ts.map +1 -0
- package/dist/src/react/icons.d.ts +26 -0
- package/dist/src/react/icons.d.ts.map +1 -0
- package/dist/src/react/index.d.ts +48 -0
- package/dist/src/react/index.d.ts.map +1 -0
- package/dist/src/react/notifications/NotificationBell.d.ts +7 -0
- package/dist/src/react/notifications/NotificationBell.d.ts.map +1 -0
- package/dist/src/react/notifications/NotificationList.d.ts +7 -0
- package/dist/src/react/notifications/NotificationList.d.ts.map +1 -0
- package/dist/src/react/notifications/Toast.d.ts +13 -0
- package/dist/src/react/notifications/Toast.d.ts.map +1 -0
- package/dist/src/react/notifications/index.d.ts +8 -0
- package/dist/src/react/notifications/index.d.ts.map +1 -0
- package/dist/src/react/notifications/provider.d.ts +14 -0
- package/dist/src/react/notifications/provider.d.ts.map +1 -0
- package/dist/src/react/notifications/use-notifications.d.ts +24 -0
- package/dist/src/react/notifications/use-notifications.d.ts.map +1 -0
- package/dist/src/react/payments/AutoReloadToggle.d.ts +6 -0
- package/dist/src/react/payments/AutoReloadToggle.d.ts.map +1 -0
- package/dist/src/react/payments/Balance.d.ts +8 -0
- package/dist/src/react/payments/Balance.d.ts.map +1 -0
- package/dist/src/react/payments/CancelSubscription.d.ts +6 -0
- package/dist/src/react/payments/CancelSubscription.d.ts.map +1 -0
- package/dist/src/react/payments/CheckoutButton.d.ts +7 -0
- package/dist/src/react/payments/CheckoutButton.d.ts.map +1 -0
- package/dist/src/react/payments/CustomerPortalButton.d.ts +6 -0
- package/dist/src/react/payments/CustomerPortalButton.d.ts.map +1 -0
- package/dist/src/react/payments/FeatureMeter.d.ts +6 -0
- package/dist/src/react/payments/FeatureMeter.d.ts.map +1 -0
- package/dist/src/react/payments/Plans.d.ts +8 -0
- package/dist/src/react/payments/Plans.d.ts.map +1 -0
- package/dist/src/react/payments/TopUpButton.d.ts +8 -0
- package/dist/src/react/payments/TopUpButton.d.ts.map +1 -0
- package/dist/src/react/payments/UpdateBilling.d.ts +3 -0
- package/dist/src/react/payments/UpdateBilling.d.ts.map +1 -0
- package/dist/src/react/payments/UpgradePrompt.d.ts +8 -0
- package/dist/src/react/payments/UpgradePrompt.d.ts.map +1 -0
- package/dist/src/react/primitives/Skeleton.d.ts +15 -0
- package/dist/src/react/primitives/Skeleton.d.ts.map +1 -0
- package/dist/src/react/provider.d.ts +21 -0
- package/dist/src/react/provider.d.ts.map +1 -0
- package/dist/src/react/request.d.ts +2 -0
- package/dist/src/react/request.d.ts.map +1 -0
- package/dist/src/react/styles-entry.d.ts +4 -0
- package/dist/src/react/styles-entry.d.ts.map +1 -0
- package/dist/src/react/styles.d.ts +2 -0
- package/dist/src/react/styles.d.ts.map +1 -0
- package/dist/src/react/theme-entry.d.ts +3 -0
- package/dist/src/react/theme-entry.d.ts.map +1 -0
- package/dist/src/react/theme.d.ts +6 -0
- package/dist/src/react/theme.d.ts.map +1 -0
- package/dist/src/react/types.d.ts +191 -0
- package/dist/src/react/types.d.ts.map +1 -0
- package/dist/src/react/use-brokr-theme.d.ts +6 -0
- package/dist/src/react/use-brokr-theme.d.ts.map +1 -0
- package/dist/src/runtime.d.ts +69 -180
- package/dist/src/runtime.d.ts.map +1 -1
- package/dist/src/storage/client.d.ts +113 -0
- package/dist/src/storage/client.d.ts.map +1 -0
- package/dist/src/storage/types.d.ts +60 -0
- package/dist/src/storage/types.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +70 -9
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/notifications/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BROKR_BUILT_IN_TYPES: () => BROKR_BUILT_IN_TYPES,
|
|
24
|
+
defineNotifications: () => defineNotifications,
|
|
25
|
+
resolveNotificationType: () => resolveNotificationType,
|
|
26
|
+
resolveRegistry: () => resolveRegistry
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/models.ts
|
|
31
|
+
var providers = [
|
|
32
|
+
{ id: "deepseek", label: "Deepseek", model: "deepseek-chat", color: "#0EA5E9", free: true, logo: "https://assets.brokr.sh/sdk/deepseek_logo.png" },
|
|
33
|
+
{ id: "openai", label: "ChatGPT", model: "gpt-5.4-mini", color: "#10B981", free: false, logo: "https://assets.brokr.sh/sdk/gpt_logo.png" },
|
|
34
|
+
{ id: "anthropic", label: "Claude", model: "claude-sonnet-4-6", color: "#F59E0B", free: false, logo: "https://assets.brokr.sh/sdk/claude_logo.png" },
|
|
35
|
+
{ id: "kimi", label: "Kimi", model: "fireworks/kimi-k2p5", color: "#8B5CF6", free: false, logo: "https://assets.brokr.sh/sdk/kimi_logo.png" },
|
|
36
|
+
{ id: "minimax", label: "Minimax", model: "MiniMaxAI/MiniMax-M2.5", color: "#EC4899", free: false, logo: "https://assets.brokr.sh/sdk/minimax_logo.png" }
|
|
37
|
+
];
|
|
38
|
+
function resolveProviderByModel(model) {
|
|
39
|
+
return providers.find((p) => p.model === model) ?? providers.find((p) => model.toLowerCase().includes(p.id));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/notifications/built-ins.ts
|
|
43
|
+
var BROKR_BUILT_IN_TYPES = {
|
|
44
|
+
/**
|
|
45
|
+
* AI response completed — auto-fired by handleChat's background task.
|
|
46
|
+
* Shows the AI provider logo (Deepseek, GPT, Claude, etc.) and links
|
|
47
|
+
* to the chat thread.
|
|
48
|
+
*/
|
|
49
|
+
ai_response: {
|
|
50
|
+
label: "AI Response",
|
|
51
|
+
defaultVariant: "default",
|
|
52
|
+
imageResolver: (data) => {
|
|
53
|
+
const logo = data.providerLogo;
|
|
54
|
+
const provider = data.provider;
|
|
55
|
+
if (typeof logo === "string" && logo) {
|
|
56
|
+
return { url: logo, alt: typeof provider === "string" ? provider : "AI" };
|
|
57
|
+
}
|
|
58
|
+
const model = data.model;
|
|
59
|
+
if (typeof model === "string") {
|
|
60
|
+
const entry = resolveProviderByModel(model);
|
|
61
|
+
if (entry) return { url: entry.logo, alt: entry.label };
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
},
|
|
65
|
+
hrefResolver: (data) => {
|
|
66
|
+
const threadId = data.threadId;
|
|
67
|
+
if (typeof threadId !== "string") return null;
|
|
68
|
+
return `/chat?thread=${encodeURIComponent(threadId)}`;
|
|
69
|
+
},
|
|
70
|
+
suppressKey: (data) => {
|
|
71
|
+
const threadId = data.threadId;
|
|
72
|
+
return typeof threadId === "string" ? threadId : null;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
/** System notifications — platform announcements, maintenance, etc. */
|
|
76
|
+
system: {
|
|
77
|
+
label: "System",
|
|
78
|
+
defaultVariant: "default"
|
|
79
|
+
},
|
|
80
|
+
/** Billing notifications — payment success/failure, plan changes. */
|
|
81
|
+
billing: {
|
|
82
|
+
label: "Billing",
|
|
83
|
+
defaultVariant: "warning",
|
|
84
|
+
hrefResolver: () => "/settings/billing"
|
|
85
|
+
},
|
|
86
|
+
/** Fallback for untyped notifications. */
|
|
87
|
+
default: {
|
|
88
|
+
label: "Notification",
|
|
89
|
+
defaultVariant: "default"
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/notifications/config.ts
|
|
94
|
+
function defineNotifications(config) {
|
|
95
|
+
return config;
|
|
96
|
+
}
|
|
97
|
+
function resolveRegistry(config) {
|
|
98
|
+
const consumer = config?.types ?? {};
|
|
99
|
+
const merged = { ...BROKR_BUILT_IN_TYPES };
|
|
100
|
+
for (const [key, entry] of Object.entries(consumer)) {
|
|
101
|
+
merged[key] = { ...merged[key], ...entry };
|
|
102
|
+
}
|
|
103
|
+
return merged;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/notifications/registry.ts
|
|
107
|
+
function resolveNotificationType(registry, type, data) {
|
|
108
|
+
const entry = registry[type ?? "default"];
|
|
109
|
+
if (!entry) {
|
|
110
|
+
return { image: null, href: null, variant: "default", suppressKey: null };
|
|
111
|
+
}
|
|
112
|
+
let image = null;
|
|
113
|
+
try {
|
|
114
|
+
image = entry.imageResolver?.(data) ?? null;
|
|
115
|
+
} catch {
|
|
116
|
+
}
|
|
117
|
+
let href = null;
|
|
118
|
+
try {
|
|
119
|
+
href = entry.hrefResolver?.(data) ?? null;
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
let suppressKey = null;
|
|
123
|
+
try {
|
|
124
|
+
suppressKey = entry.suppressKey?.(data) ?? null;
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
image,
|
|
129
|
+
href,
|
|
130
|
+
variant: entry.defaultVariant ?? "default",
|
|
131
|
+
suppressKey
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
BROKR_BUILT_IN_TYPES,
|
|
137
|
+
defineNotifications,
|
|
138
|
+
resolveNotificationType,
|
|
139
|
+
resolveRegistry
|
|
140
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// src/models.ts
|
|
2
|
+
var providers = [
|
|
3
|
+
{ id: "deepseek", label: "Deepseek", model: "deepseek-chat", color: "#0EA5E9", free: true, logo: "https://assets.brokr.sh/sdk/deepseek_logo.png" },
|
|
4
|
+
{ id: "openai", label: "ChatGPT", model: "gpt-5.4-mini", color: "#10B981", free: false, logo: "https://assets.brokr.sh/sdk/gpt_logo.png" },
|
|
5
|
+
{ id: "anthropic", label: "Claude", model: "claude-sonnet-4-6", color: "#F59E0B", free: false, logo: "https://assets.brokr.sh/sdk/claude_logo.png" },
|
|
6
|
+
{ id: "kimi", label: "Kimi", model: "fireworks/kimi-k2p5", color: "#8B5CF6", free: false, logo: "https://assets.brokr.sh/sdk/kimi_logo.png" },
|
|
7
|
+
{ id: "minimax", label: "Minimax", model: "MiniMaxAI/MiniMax-M2.5", color: "#EC4899", free: false, logo: "https://assets.brokr.sh/sdk/minimax_logo.png" }
|
|
8
|
+
];
|
|
9
|
+
function resolveProviderByModel(model) {
|
|
10
|
+
return providers.find((p) => p.model === model) ?? providers.find((p) => model.toLowerCase().includes(p.id));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/notifications/built-ins.ts
|
|
14
|
+
var BROKR_BUILT_IN_TYPES = {
|
|
15
|
+
/**
|
|
16
|
+
* AI response completed — auto-fired by handleChat's background task.
|
|
17
|
+
* Shows the AI provider logo (Deepseek, GPT, Claude, etc.) and links
|
|
18
|
+
* to the chat thread.
|
|
19
|
+
*/
|
|
20
|
+
ai_response: {
|
|
21
|
+
label: "AI Response",
|
|
22
|
+
defaultVariant: "default",
|
|
23
|
+
imageResolver: (data) => {
|
|
24
|
+
const logo = data.providerLogo;
|
|
25
|
+
const provider = data.provider;
|
|
26
|
+
if (typeof logo === "string" && logo) {
|
|
27
|
+
return { url: logo, alt: typeof provider === "string" ? provider : "AI" };
|
|
28
|
+
}
|
|
29
|
+
const model = data.model;
|
|
30
|
+
if (typeof model === "string") {
|
|
31
|
+
const entry = resolveProviderByModel(model);
|
|
32
|
+
if (entry) return { url: entry.logo, alt: entry.label };
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
},
|
|
36
|
+
hrefResolver: (data) => {
|
|
37
|
+
const threadId = data.threadId;
|
|
38
|
+
if (typeof threadId !== "string") return null;
|
|
39
|
+
return `/chat?thread=${encodeURIComponent(threadId)}`;
|
|
40
|
+
},
|
|
41
|
+
suppressKey: (data) => {
|
|
42
|
+
const threadId = data.threadId;
|
|
43
|
+
return typeof threadId === "string" ? threadId : null;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
/** System notifications — platform announcements, maintenance, etc. */
|
|
47
|
+
system: {
|
|
48
|
+
label: "System",
|
|
49
|
+
defaultVariant: "default"
|
|
50
|
+
},
|
|
51
|
+
/** Billing notifications — payment success/failure, plan changes. */
|
|
52
|
+
billing: {
|
|
53
|
+
label: "Billing",
|
|
54
|
+
defaultVariant: "warning",
|
|
55
|
+
hrefResolver: () => "/settings/billing"
|
|
56
|
+
},
|
|
57
|
+
/** Fallback for untyped notifications. */
|
|
58
|
+
default: {
|
|
59
|
+
label: "Notification",
|
|
60
|
+
defaultVariant: "default"
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/notifications/config.ts
|
|
65
|
+
function defineNotifications(config) {
|
|
66
|
+
return config;
|
|
67
|
+
}
|
|
68
|
+
function resolveRegistry(config) {
|
|
69
|
+
const consumer = config?.types ?? {};
|
|
70
|
+
const merged = { ...BROKR_BUILT_IN_TYPES };
|
|
71
|
+
for (const [key, entry] of Object.entries(consumer)) {
|
|
72
|
+
merged[key] = { ...merged[key], ...entry };
|
|
73
|
+
}
|
|
74
|
+
return merged;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/notifications/registry.ts
|
|
78
|
+
function resolveNotificationType(registry, type, data) {
|
|
79
|
+
const entry = registry[type ?? "default"];
|
|
80
|
+
if (!entry) {
|
|
81
|
+
return { image: null, href: null, variant: "default", suppressKey: null };
|
|
82
|
+
}
|
|
83
|
+
let image = null;
|
|
84
|
+
try {
|
|
85
|
+
image = entry.imageResolver?.(data) ?? null;
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
let href = null;
|
|
89
|
+
try {
|
|
90
|
+
href = entry.hrefResolver?.(data) ?? null;
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
let suppressKey = null;
|
|
94
|
+
try {
|
|
95
|
+
suppressKey = entry.suppressKey?.(data) ?? null;
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
image,
|
|
100
|
+
href,
|
|
101
|
+
variant: entry.defaultVariant ?? "default",
|
|
102
|
+
suppressKey
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
BROKR_BUILT_IN_TYPES,
|
|
107
|
+
defineNotifications,
|
|
108
|
+
resolveNotificationType,
|
|
109
|
+
resolveRegistry
|
|
110
|
+
};
|
package/dist/payments.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/payments/config.ts
|
|
21
|
+
var config_exports = {};
|
|
22
|
+
__export(config_exports, {
|
|
23
|
+
definePayments: () => definePayments
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(config_exports);
|
|
26
|
+
function definePayments(config) {
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
definePayments
|
|
32
|
+
});
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/react/notifications/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
NotificationBell: () => NotificationBell,
|
|
35
|
+
NotificationList: () => NotificationList,
|
|
36
|
+
defineNotifications: () => defineNotifications,
|
|
37
|
+
useNotifications: () => useNotifications
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
|
|
41
|
+
// src/react/notifications/NotificationBell.tsx
|
|
42
|
+
var import_react4 = __toESM(require("react"));
|
|
43
|
+
|
|
44
|
+
// src/react/notifications/use-notifications.ts
|
|
45
|
+
var import_react3 = require("react");
|
|
46
|
+
|
|
47
|
+
// src/react/notifications/provider.tsx
|
|
48
|
+
var import_react2 = __toESM(require("react"));
|
|
49
|
+
|
|
50
|
+
// src/notifications/config.ts
|
|
51
|
+
function defineNotifications(config) {
|
|
52
|
+
return config;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/notifications/registry.ts
|
|
56
|
+
function resolveNotificationType(registry, type, data) {
|
|
57
|
+
const entry = registry[type ?? "default"];
|
|
58
|
+
if (!entry) {
|
|
59
|
+
return { image: null, href: null, variant: "default", suppressKey: null };
|
|
60
|
+
}
|
|
61
|
+
let image = null;
|
|
62
|
+
try {
|
|
63
|
+
image = entry.imageResolver?.(data) ?? null;
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
let href = null;
|
|
67
|
+
try {
|
|
68
|
+
href = entry.hrefResolver?.(data) ?? null;
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
let suppressKey = null;
|
|
72
|
+
try {
|
|
73
|
+
suppressKey = entry.suppressKey?.(data) ?? null;
|
|
74
|
+
} catch {
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
image,
|
|
78
|
+
href,
|
|
79
|
+
variant: entry.defaultVariant ?? "default",
|
|
80
|
+
suppressKey
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/react/notifications/Toast.tsx
|
|
85
|
+
var import_react = __toESM(require("react"));
|
|
86
|
+
|
|
87
|
+
// src/react/notifications/provider.tsx
|
|
88
|
+
var NotificationsContext = (0, import_react2.createContext)(null);
|
|
89
|
+
|
|
90
|
+
// src/react/notifications/use-notifications.ts
|
|
91
|
+
function useNotifications() {
|
|
92
|
+
const ctx = (0, import_react3.useContext)(NotificationsContext);
|
|
93
|
+
if (!ctx) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
"useNotifications() requires <BrokrProvider notifications> or <BrokrProvider notifications={config}>. Pass the notifications prop to enable the notification system."
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return ctx;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/react/notifications/NotificationBell.tsx
|
|
102
|
+
function timeAgo(iso) {
|
|
103
|
+
const diff = Date.now() - new Date(iso).getTime();
|
|
104
|
+
const mins = Math.floor(diff / 6e4);
|
|
105
|
+
if (mins < 1) return "just now";
|
|
106
|
+
if (mins < 60) return `${mins}m ago`;
|
|
107
|
+
const hours = Math.floor(mins / 60);
|
|
108
|
+
if (hours < 24) return `${hours}h ago`;
|
|
109
|
+
const days = Math.floor(hours / 24);
|
|
110
|
+
return `${days}d ago`;
|
|
111
|
+
}
|
|
112
|
+
function NotificationBell() {
|
|
113
|
+
const { notifications, unreadCount, markRead, markAllRead, isLoading, registry } = useNotifications();
|
|
114
|
+
const [open, setOpen] = (0, import_react4.useState)(false);
|
|
115
|
+
const containerRef = (0, import_react4.useRef)(null);
|
|
116
|
+
const markReadTimerRef = (0, import_react4.useRef)(null);
|
|
117
|
+
const toggle = (0, import_react4.useCallback)(() => setOpen((o) => !o), []);
|
|
118
|
+
(0, import_react4.useEffect)(() => {
|
|
119
|
+
if (markReadTimerRef.current) {
|
|
120
|
+
clearTimeout(markReadTimerRef.current);
|
|
121
|
+
markReadTimerRef.current = null;
|
|
122
|
+
}
|
|
123
|
+
if (open && unreadCount > 0) {
|
|
124
|
+
markReadTimerRef.current = setTimeout(() => {
|
|
125
|
+
markAllRead();
|
|
126
|
+
}, 800);
|
|
127
|
+
}
|
|
128
|
+
return () => {
|
|
129
|
+
if (markReadTimerRef.current) {
|
|
130
|
+
clearTimeout(markReadTimerRef.current);
|
|
131
|
+
markReadTimerRef.current = null;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}, [open, unreadCount, markAllRead]);
|
|
135
|
+
(0, import_react4.useEffect)(() => {
|
|
136
|
+
if (!open) return;
|
|
137
|
+
function handleClick(e) {
|
|
138
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
139
|
+
setOpen(false);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
document.addEventListener("mousedown", handleClick);
|
|
143
|
+
return () => document.removeEventListener("mousedown", handleClick);
|
|
144
|
+
}, [open]);
|
|
145
|
+
(0, import_react4.useEffect)(() => {
|
|
146
|
+
if (!open) return;
|
|
147
|
+
function handleKey(e) {
|
|
148
|
+
if (e.key === "Escape") setOpen(false);
|
|
149
|
+
}
|
|
150
|
+
document.addEventListener("keydown", handleKey);
|
|
151
|
+
return () => document.removeEventListener("keydown", handleKey);
|
|
152
|
+
}, [open]);
|
|
153
|
+
const sorted = (0, import_react4.useMemo)(
|
|
154
|
+
() => [...notifications].sort(
|
|
155
|
+
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
|
156
|
+
),
|
|
157
|
+
[notifications]
|
|
158
|
+
);
|
|
159
|
+
const handleItemClick = (0, import_react4.useCallback)((notif) => {
|
|
160
|
+
if (!notif.read) markRead(notif.id);
|
|
161
|
+
const notifData = notif.data ?? {};
|
|
162
|
+
const notifType = notif.type ?? notifData.type ?? "default";
|
|
163
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
164
|
+
const href = resolved.href ?? notif.href ?? notifData.href ?? null;
|
|
165
|
+
if (href) {
|
|
166
|
+
window.location.assign(href);
|
|
167
|
+
}
|
|
168
|
+
}, [markRead, registry]);
|
|
169
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", { className: "brokr-notif-bell-wrap", ref: containerRef }, /* @__PURE__ */ import_react4.default.createElement(
|
|
170
|
+
"button",
|
|
171
|
+
{
|
|
172
|
+
type: "button",
|
|
173
|
+
className: "brokr-notif-bell",
|
|
174
|
+
onClick: toggle,
|
|
175
|
+
"aria-label": `Notifications${unreadCount > 0 ? ` (${unreadCount} unread)` : ""}`,
|
|
176
|
+
"aria-expanded": open
|
|
177
|
+
},
|
|
178
|
+
/* @__PURE__ */ import_react4.default.createElement("svg", { "aria-hidden": "true", width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ import_react4.default.createElement("path", { d: "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }), /* @__PURE__ */ import_react4.default.createElement("path", { d: "M10.3 21a1.94 1.94 0 0 0 3.4 0" })),
|
|
179
|
+
unreadCount > 0 && /* @__PURE__ */ import_react4.default.createElement("span", { className: "brokr-notif-badge" }, unreadCount > 99 ? "99+" : unreadCount)
|
|
180
|
+
), open && /* @__PURE__ */ import_react4.default.createElement("div", { className: "brokr-notif-dropdown", role: "menu" }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "brokr-notif-dropdown-header" }, /* @__PURE__ */ import_react4.default.createElement("span", { className: "brokr-notif-dropdown-title" }, "Notifications"), unreadCount > 0 && /* @__PURE__ */ import_react4.default.createElement(
|
|
181
|
+
"button",
|
|
182
|
+
{
|
|
183
|
+
type: "button",
|
|
184
|
+
className: "brokr-notif-mark-all",
|
|
185
|
+
onClick: markAllRead
|
|
186
|
+
},
|
|
187
|
+
"Mark all read"
|
|
188
|
+
)), /* @__PURE__ */ import_react4.default.createElement("div", { className: "brokr-notif-dropdown-list" }, isLoading ? /* @__PURE__ */ import_react4.default.createElement("div", { className: "brokr-notif-empty" }, /* @__PURE__ */ import_react4.default.createElement("span", { className: "brokr-notif-empty-text" }, "Loading\u2026")) : sorted.length === 0 ? /* @__PURE__ */ import_react4.default.createElement("div", { className: "brokr-notif-empty" }, /* @__PURE__ */ import_react4.default.createElement("span", { className: "brokr-notif-empty-text" }, "No notifications yet")) : sorted.map((notif) => {
|
|
189
|
+
const notifData = notif.data ?? {};
|
|
190
|
+
const notifType = notifData.type ?? "default";
|
|
191
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
192
|
+
return /* @__PURE__ */ import_react4.default.createElement(
|
|
193
|
+
"button",
|
|
194
|
+
{
|
|
195
|
+
key: notif.id,
|
|
196
|
+
type: "button",
|
|
197
|
+
className: `brokr-notif-item${notif.read ? "" : " brokr-notif-item--unread"}`,
|
|
198
|
+
onClick: () => handleItemClick(notif),
|
|
199
|
+
role: "menuitem"
|
|
200
|
+
},
|
|
201
|
+
resolved.image ? /* @__PURE__ */ import_react4.default.createElement(
|
|
202
|
+
"img",
|
|
203
|
+
{
|
|
204
|
+
src: resolved.image.url,
|
|
205
|
+
alt: resolved.image.alt,
|
|
206
|
+
className: "brokr-notif-item-logo"
|
|
207
|
+
}
|
|
208
|
+
) : /* @__PURE__ */ import_react4.default.createElement("span", { className: `brokr-notif-item-dot brokr-notif-item-dot--${notif.variant}` }),
|
|
209
|
+
/* @__PURE__ */ import_react4.default.createElement("div", { className: "brokr-notif-item-body" }, /* @__PURE__ */ import_react4.default.createElement("span", { className: "brokr-notif-item-title" }, notif.title), /* @__PURE__ */ import_react4.default.createElement("span", { className: "brokr-notif-item-message" }, notif.message)),
|
|
210
|
+
/* @__PURE__ */ import_react4.default.createElement("span", { className: "brokr-notif-item-time" }, timeAgo(notif.createdAt))
|
|
211
|
+
);
|
|
212
|
+
}))));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/react/notifications/NotificationList.tsx
|
|
216
|
+
var import_react5 = __toESM(require("react"));
|
|
217
|
+
function formatTimestamp(iso) {
|
|
218
|
+
const date = new Date(iso);
|
|
219
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
220
|
+
month: "short",
|
|
221
|
+
day: "numeric",
|
|
222
|
+
hour: "numeric",
|
|
223
|
+
minute: "2-digit"
|
|
224
|
+
}).format(date);
|
|
225
|
+
}
|
|
226
|
+
function NotificationListSkeleton() {
|
|
227
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", { className: "brokr-notif-list-items" }, [1, 2, 3].map((i) => /* @__PURE__ */ import_react5.default.createElement("div", { key: i, className: "brokr-notif-list-row brokr-notif-list-row--skeleton" }, /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-item-dot brokr-notif-item-dot--skeleton" }), /* @__PURE__ */ import_react5.default.createElement("div", { className: "brokr-notif-item-body" }, /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-item-title brokr-skeleton-line", style: { width: "60%" } }), /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-item-message brokr-skeleton-line", style: { width: "80%" } })), /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-item-time brokr-skeleton-line", style: { width: 48 } }))));
|
|
228
|
+
}
|
|
229
|
+
function NotificationList() {
|
|
230
|
+
const { notifications, unreadCount, markRead, markAllRead, isLoading, registry } = useNotifications();
|
|
231
|
+
const sorted = (0, import_react5.useMemo)(
|
|
232
|
+
() => [...notifications].sort(
|
|
233
|
+
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
|
|
234
|
+
),
|
|
235
|
+
[notifications]
|
|
236
|
+
);
|
|
237
|
+
const handleClick = (0, import_react5.useCallback)((notif) => {
|
|
238
|
+
if (!notif.read) markRead(notif.id);
|
|
239
|
+
const notifData = notif.data ?? {};
|
|
240
|
+
const notifType = notif.type ?? notifData.type ?? "default";
|
|
241
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
242
|
+
const href = resolved.href ?? notif.href ?? notifData.href ?? null;
|
|
243
|
+
if (href) {
|
|
244
|
+
window.location.assign(href);
|
|
245
|
+
}
|
|
246
|
+
}, [markRead, registry]);
|
|
247
|
+
return /* @__PURE__ */ import_react5.default.createElement("div", { className: "brokr-notif-list" }, /* @__PURE__ */ import_react5.default.createElement("div", { className: "brokr-notif-list-header" }, /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-list-title" }, "Notifications"), unreadCount > 0 && /* @__PURE__ */ import_react5.default.createElement(
|
|
248
|
+
"button",
|
|
249
|
+
{
|
|
250
|
+
type: "button",
|
|
251
|
+
className: "brokr-notif-mark-all",
|
|
252
|
+
onClick: markAllRead
|
|
253
|
+
},
|
|
254
|
+
"Mark all read"
|
|
255
|
+
)), isLoading ? /* @__PURE__ */ import_react5.default.createElement(NotificationListSkeleton, null) : sorted.length === 0 ? /* @__PURE__ */ import_react5.default.createElement("div", { className: "brokr-notif-empty" }, /* @__PURE__ */ import_react5.default.createElement("svg", { "aria-hidden": "true", width: "40", height: "40", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1", strokeLinecap: "round", strokeLinejoin: "round", style: { opacity: 0.3 } }, /* @__PURE__ */ import_react5.default.createElement("path", { d: "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }), /* @__PURE__ */ import_react5.default.createElement("path", { d: "M10.3 21a1.94 1.94 0 0 0 3.4 0" })), /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-empty-text" }, "No notifications yet")) : /* @__PURE__ */ import_react5.default.createElement("div", { className: "brokr-notif-list-items" }, sorted.map((notif) => {
|
|
256
|
+
const notifData = notif.data ?? {};
|
|
257
|
+
const notifType = notif.type ?? notifData.type ?? "default";
|
|
258
|
+
const resolved = resolveNotificationType(registry, notifType, notifData);
|
|
259
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
260
|
+
"button",
|
|
261
|
+
{
|
|
262
|
+
key: notif.id,
|
|
263
|
+
type: "button",
|
|
264
|
+
className: `brokr-notif-list-row${notif.read ? "" : " brokr-notif-list-row--unread"}`,
|
|
265
|
+
onClick: () => handleClick(notif)
|
|
266
|
+
},
|
|
267
|
+
resolved.image ? /* @__PURE__ */ import_react5.default.createElement(
|
|
268
|
+
"img",
|
|
269
|
+
{
|
|
270
|
+
src: resolved.image.url,
|
|
271
|
+
alt: resolved.image.alt,
|
|
272
|
+
className: "brokr-notif-item-logo"
|
|
273
|
+
}
|
|
274
|
+
) : /* @__PURE__ */ import_react5.default.createElement("span", { className: `brokr-notif-item-dot brokr-notif-item-dot--${notif.variant}` }),
|
|
275
|
+
/* @__PURE__ */ import_react5.default.createElement("div", { className: "brokr-notif-item-body" }, /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-item-title" }, notif.title), /* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-item-message" }, notif.message)),
|
|
276
|
+
/* @__PURE__ */ import_react5.default.createElement("span", { className: "brokr-notif-item-time" }, formatTimestamp(notif.createdAt))
|
|
277
|
+
);
|
|
278
|
+
})));
|
|
279
|
+
}
|
|
280
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
281
|
+
0 && (module.exports = {
|
|
282
|
+
NotificationBell,
|
|
283
|
+
NotificationList,
|
|
284
|
+
defineNotifications,
|
|
285
|
+
useNotifications
|
|
286
|
+
});
|