@palettelab/sdk 0.1.24 → 0.1.25
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.mts +65 -1
- package/dist/index.d.ts +65 -1
- package/dist/index.js +43 -11
- package/dist/index.mjs +42 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -189,6 +189,56 @@ declare const broker: {
|
|
|
189
189
|
/** Typed proxy: `palette.services("org/v1").members.list({ ... })`. */
|
|
190
190
|
declare function servicesProxy(namespaceVersion: string): any;
|
|
191
191
|
|
|
192
|
+
/**
|
|
193
|
+
* OS notifications — push a notification into the OS-level notification pool.
|
|
194
|
+
*
|
|
195
|
+
* import { notifications } from "@palettelab/sdk"
|
|
196
|
+
*
|
|
197
|
+
* await notifications.push({
|
|
198
|
+
* title: "Export complete",
|
|
199
|
+
* body: "Your report is ready to download.",
|
|
200
|
+
* severity: "success",
|
|
201
|
+
* route: "/exports/123", // opened inside this app when clicked
|
|
202
|
+
* })
|
|
203
|
+
*
|
|
204
|
+
* The notification appears in the OS notification center (and as a transient
|
|
205
|
+
* toast); clicking it opens/focuses the app window at `action_route`.
|
|
206
|
+
*
|
|
207
|
+
* The stable contract is `POST /api/v1/notifications/` on the platform API —
|
|
208
|
+
* this helper is sugar over it. Runs in the user's session (cookies included);
|
|
209
|
+
* sandboxed iframe apps are not supported yet (no session in the iframe).
|
|
210
|
+
*/
|
|
211
|
+
type OsNotificationSeverity = "info" | "success" | "warning" | "error";
|
|
212
|
+
type OsNotificationInput = {
|
|
213
|
+
title: string;
|
|
214
|
+
body?: string;
|
|
215
|
+
/**
|
|
216
|
+
* Route to open when the notification is clicked. Relative routes
|
|
217
|
+
* ("/exports/123") resolve inside the calling app; absolute routes
|
|
218
|
+
* ("/apps/other-app") are used as-is.
|
|
219
|
+
*/
|
|
220
|
+
route?: string;
|
|
221
|
+
severity?: OsNotificationSeverity;
|
|
222
|
+
/** Arbitrary structured payload, stored alongside the notification. */
|
|
223
|
+
data?: Record<string, unknown>;
|
|
224
|
+
/** Override the source app id. Inferred from the URL when omitted. */
|
|
225
|
+
appId?: string;
|
|
226
|
+
};
|
|
227
|
+
type OsNotification = {
|
|
228
|
+
id: number;
|
|
229
|
+
type: string;
|
|
230
|
+
title: string;
|
|
231
|
+
body: string | null;
|
|
232
|
+
source_app_id: string | null;
|
|
233
|
+
action_route: string | null;
|
|
234
|
+
severity: OsNotificationSeverity | null;
|
|
235
|
+
is_read: boolean;
|
|
236
|
+
created_at: string;
|
|
237
|
+
};
|
|
238
|
+
declare const notifications: {
|
|
239
|
+
push(input: OsNotificationInput): Promise<OsNotification>;
|
|
240
|
+
};
|
|
241
|
+
|
|
192
242
|
interface DataRoomContents {
|
|
193
243
|
room?: DataRoom;
|
|
194
244
|
folders: DataRoomFolder[];
|
|
@@ -350,6 +400,13 @@ declare function createPaletteClient(ctx?: PlatformContext): {
|
|
|
350
400
|
error: (message: string) => void | undefined;
|
|
351
401
|
info: (message: string) => void | undefined;
|
|
352
402
|
};
|
|
403
|
+
/**
|
|
404
|
+
* OS notification pool. Unlike `toast`, these persist in the OS
|
|
405
|
+
* notification center and can open the app when clicked.
|
|
406
|
+
*/
|
|
407
|
+
notifications: {
|
|
408
|
+
push: (input: OsNotificationInput) => Promise<OsNotification>;
|
|
409
|
+
};
|
|
353
410
|
/**
|
|
354
411
|
* OS-broker RPC. Typed entry point: `palette.services("org/v1").members.list({...})`.
|
|
355
412
|
* The proxy resolves a dotted method chain into a qualified target string
|
|
@@ -397,6 +454,13 @@ declare const palette: {
|
|
|
397
454
|
error: (message: string) => void | undefined;
|
|
398
455
|
info: (message: string) => void | undefined;
|
|
399
456
|
};
|
|
457
|
+
/**
|
|
458
|
+
* OS notification pool. Unlike `toast`, these persist in the OS
|
|
459
|
+
* notification center and can open the app when clicked.
|
|
460
|
+
*/
|
|
461
|
+
notifications: {
|
|
462
|
+
push: (input: OsNotificationInput) => Promise<OsNotification>;
|
|
463
|
+
};
|
|
400
464
|
/**
|
|
401
465
|
* OS-broker RPC. Typed entry point: `palette.services("org/v1").members.list({...})`.
|
|
402
466
|
* The proxy resolves a dotted method chain into a qualified target string
|
|
@@ -423,4 +487,4 @@ declare function hasPermission(ctx: PlatformContext, permission: string): boolea
|
|
|
423
487
|
declare function hasAnyPermission(ctx: PlatformContext, permissions: string[]): boolean;
|
|
424
488
|
declare function hasAllPermissions(ctx: PlatformContext, permissions: string[]): boolean;
|
|
425
489
|
|
|
426
|
-
export { BrokerCallError, type BrokerCallOptions, type ConnectionAuthStart, type ConnectionStatus, type ConnectionStatusValue, CrossAppGrantError, DataRoom, DataRoomClient, type DataRoomContents, DataRoomFile, DataRoomFolder, type DataRoomUploadOptions, type EventMeta, type InstallConfig, MissingDependencyError, type OrgInviteMemberInput, type OrgInviteMemberResponse, type OrgMember, type OrgMemberRole, OrgSummary, OrganizationClient, PaletteApiError, type PaletteClient, PlatformContext, type SandboxBridge, type SandboxBrokerMessage, StorageClient, type StorageUploadOptions, type StorageUploadProgress, type StorageUploadResult, type StorageUploadState, User, UserClient, apiFetch, apiUpload, broker, createMockPlatformContext, createPaletteClient, createSandboxBridge, dataRooms, disconnectConnection, errorFromResponse, events, getBaseUrl, getConnections, getInstallConfig, hasAllPermissions, hasAnyPermission, hasPermission, isPaletteApiError, isSandboxRuntime, palette, requireConnection, servicesProxy, setBaseUrl, startConnection, updateInstallConfig, uploadToSignedUrl, withPluginProvider };
|
|
490
|
+
export { BrokerCallError, type BrokerCallOptions, type ConnectionAuthStart, type ConnectionStatus, type ConnectionStatusValue, CrossAppGrantError, DataRoom, DataRoomClient, type DataRoomContents, DataRoomFile, DataRoomFolder, type DataRoomUploadOptions, type EventMeta, type InstallConfig, MissingDependencyError, type OrgInviteMemberInput, type OrgInviteMemberResponse, type OrgMember, type OrgMemberRole, OrgSummary, OrganizationClient, type OsNotification, type OsNotificationInput, type OsNotificationSeverity, PaletteApiError, type PaletteClient, PlatformContext, type SandboxBridge, type SandboxBrokerMessage, StorageClient, type StorageUploadOptions, type StorageUploadProgress, type StorageUploadResult, type StorageUploadState, User, UserClient, apiFetch, apiUpload, broker, createMockPlatformContext, createPaletteClient, createSandboxBridge, dataRooms, disconnectConnection, errorFromResponse, events, getBaseUrl, getConnections, getInstallConfig, hasAllPermissions, hasAnyPermission, hasPermission, isPaletteApiError, isSandboxRuntime, notifications, palette, requireConnection, servicesProxy, setBaseUrl, startConnection, updateInstallConfig, uploadToSignedUrl, withPluginProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -189,6 +189,56 @@ declare const broker: {
|
|
|
189
189
|
/** Typed proxy: `palette.services("org/v1").members.list({ ... })`. */
|
|
190
190
|
declare function servicesProxy(namespaceVersion: string): any;
|
|
191
191
|
|
|
192
|
+
/**
|
|
193
|
+
* OS notifications — push a notification into the OS-level notification pool.
|
|
194
|
+
*
|
|
195
|
+
* import { notifications } from "@palettelab/sdk"
|
|
196
|
+
*
|
|
197
|
+
* await notifications.push({
|
|
198
|
+
* title: "Export complete",
|
|
199
|
+
* body: "Your report is ready to download.",
|
|
200
|
+
* severity: "success",
|
|
201
|
+
* route: "/exports/123", // opened inside this app when clicked
|
|
202
|
+
* })
|
|
203
|
+
*
|
|
204
|
+
* The notification appears in the OS notification center (and as a transient
|
|
205
|
+
* toast); clicking it opens/focuses the app window at `action_route`.
|
|
206
|
+
*
|
|
207
|
+
* The stable contract is `POST /api/v1/notifications/` on the platform API —
|
|
208
|
+
* this helper is sugar over it. Runs in the user's session (cookies included);
|
|
209
|
+
* sandboxed iframe apps are not supported yet (no session in the iframe).
|
|
210
|
+
*/
|
|
211
|
+
type OsNotificationSeverity = "info" | "success" | "warning" | "error";
|
|
212
|
+
type OsNotificationInput = {
|
|
213
|
+
title: string;
|
|
214
|
+
body?: string;
|
|
215
|
+
/**
|
|
216
|
+
* Route to open when the notification is clicked. Relative routes
|
|
217
|
+
* ("/exports/123") resolve inside the calling app; absolute routes
|
|
218
|
+
* ("/apps/other-app") are used as-is.
|
|
219
|
+
*/
|
|
220
|
+
route?: string;
|
|
221
|
+
severity?: OsNotificationSeverity;
|
|
222
|
+
/** Arbitrary structured payload, stored alongside the notification. */
|
|
223
|
+
data?: Record<string, unknown>;
|
|
224
|
+
/** Override the source app id. Inferred from the URL when omitted. */
|
|
225
|
+
appId?: string;
|
|
226
|
+
};
|
|
227
|
+
type OsNotification = {
|
|
228
|
+
id: number;
|
|
229
|
+
type: string;
|
|
230
|
+
title: string;
|
|
231
|
+
body: string | null;
|
|
232
|
+
source_app_id: string | null;
|
|
233
|
+
action_route: string | null;
|
|
234
|
+
severity: OsNotificationSeverity | null;
|
|
235
|
+
is_read: boolean;
|
|
236
|
+
created_at: string;
|
|
237
|
+
};
|
|
238
|
+
declare const notifications: {
|
|
239
|
+
push(input: OsNotificationInput): Promise<OsNotification>;
|
|
240
|
+
};
|
|
241
|
+
|
|
192
242
|
interface DataRoomContents {
|
|
193
243
|
room?: DataRoom;
|
|
194
244
|
folders: DataRoomFolder[];
|
|
@@ -350,6 +400,13 @@ declare function createPaletteClient(ctx?: PlatformContext): {
|
|
|
350
400
|
error: (message: string) => void | undefined;
|
|
351
401
|
info: (message: string) => void | undefined;
|
|
352
402
|
};
|
|
403
|
+
/**
|
|
404
|
+
* OS notification pool. Unlike `toast`, these persist in the OS
|
|
405
|
+
* notification center and can open the app when clicked.
|
|
406
|
+
*/
|
|
407
|
+
notifications: {
|
|
408
|
+
push: (input: OsNotificationInput) => Promise<OsNotification>;
|
|
409
|
+
};
|
|
353
410
|
/**
|
|
354
411
|
* OS-broker RPC. Typed entry point: `palette.services("org/v1").members.list({...})`.
|
|
355
412
|
* The proxy resolves a dotted method chain into a qualified target string
|
|
@@ -397,6 +454,13 @@ declare const palette: {
|
|
|
397
454
|
error: (message: string) => void | undefined;
|
|
398
455
|
info: (message: string) => void | undefined;
|
|
399
456
|
};
|
|
457
|
+
/**
|
|
458
|
+
* OS notification pool. Unlike `toast`, these persist in the OS
|
|
459
|
+
* notification center and can open the app when clicked.
|
|
460
|
+
*/
|
|
461
|
+
notifications: {
|
|
462
|
+
push: (input: OsNotificationInput) => Promise<OsNotification>;
|
|
463
|
+
};
|
|
400
464
|
/**
|
|
401
465
|
* OS-broker RPC. Typed entry point: `palette.services("org/v1").members.list({...})`.
|
|
402
466
|
* The proxy resolves a dotted method chain into a qualified target string
|
|
@@ -423,4 +487,4 @@ declare function hasPermission(ctx: PlatformContext, permission: string): boolea
|
|
|
423
487
|
declare function hasAnyPermission(ctx: PlatformContext, permissions: string[]): boolean;
|
|
424
488
|
declare function hasAllPermissions(ctx: PlatformContext, permissions: string[]): boolean;
|
|
425
489
|
|
|
426
|
-
export { BrokerCallError, type BrokerCallOptions, type ConnectionAuthStart, type ConnectionStatus, type ConnectionStatusValue, CrossAppGrantError, DataRoom, DataRoomClient, type DataRoomContents, DataRoomFile, DataRoomFolder, type DataRoomUploadOptions, type EventMeta, type InstallConfig, MissingDependencyError, type OrgInviteMemberInput, type OrgInviteMemberResponse, type OrgMember, type OrgMemberRole, OrgSummary, OrganizationClient, PaletteApiError, type PaletteClient, PlatformContext, type SandboxBridge, type SandboxBrokerMessage, StorageClient, type StorageUploadOptions, type StorageUploadProgress, type StorageUploadResult, type StorageUploadState, User, UserClient, apiFetch, apiUpload, broker, createMockPlatformContext, createPaletteClient, createSandboxBridge, dataRooms, disconnectConnection, errorFromResponse, events, getBaseUrl, getConnections, getInstallConfig, hasAllPermissions, hasAnyPermission, hasPermission, isPaletteApiError, isSandboxRuntime, palette, requireConnection, servicesProxy, setBaseUrl, startConnection, updateInstallConfig, uploadToSignedUrl, withPluginProvider };
|
|
490
|
+
export { BrokerCallError, type BrokerCallOptions, type ConnectionAuthStart, type ConnectionStatus, type ConnectionStatusValue, CrossAppGrantError, DataRoom, DataRoomClient, type DataRoomContents, DataRoomFile, DataRoomFolder, type DataRoomUploadOptions, type EventMeta, type InstallConfig, MissingDependencyError, type OrgInviteMemberInput, type OrgInviteMemberResponse, type OrgMember, type OrgMemberRole, OrgSummary, OrganizationClient, type OsNotification, type OsNotificationInput, type OsNotificationSeverity, PaletteApiError, type PaletteClient, PlatformContext, type SandboxBridge, type SandboxBrokerMessage, StorageClient, type StorageUploadOptions, type StorageUploadProgress, type StorageUploadResult, type StorageUploadState, User, UserClient, apiFetch, apiUpload, broker, createMockPlatformContext, createPaletteClient, createSandboxBridge, dataRooms, disconnectConnection, errorFromResponse, events, getBaseUrl, getConnections, getInstallConfig, hasAllPermissions, hasAnyPermission, hasPermission, isPaletteApiError, isSandboxRuntime, notifications, palette, requireConnection, servicesProxy, setBaseUrl, startConnection, updateInstallConfig, uploadToSignedUrl, withPluginProvider };
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,7 @@ __export(src_exports, {
|
|
|
52
52
|
isSandboxRuntime: () => isSandboxRuntime,
|
|
53
53
|
normalizePaletteLanguage: () => normalizePaletteLanguage,
|
|
54
54
|
notFound: () => notFound,
|
|
55
|
+
notifications: () => notifications,
|
|
55
56
|
palette: () => palette,
|
|
56
57
|
requireConnection: () => requireConnection,
|
|
57
58
|
servicesProxy: () => servicesProxy,
|
|
@@ -400,6 +401,13 @@ var DataRoomClient = class {
|
|
|
400
401
|
};
|
|
401
402
|
var dataRooms = new DataRoomClient();
|
|
402
403
|
|
|
404
|
+
// src/plugin-id.ts
|
|
405
|
+
function currentPluginId() {
|
|
406
|
+
if (typeof window === "undefined") return void 0;
|
|
407
|
+
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
408
|
+
return match ? decodeURIComponent(match[1]) : void 0;
|
|
409
|
+
}
|
|
410
|
+
|
|
403
411
|
// src/services.ts
|
|
404
412
|
var BrokerCallError = class extends Error {
|
|
405
413
|
constructor(message, target, status) {
|
|
@@ -432,11 +440,6 @@ function brokerError(message, target, status) {
|
|
|
432
440
|
return new BrokerCallError(message, target, status);
|
|
433
441
|
}
|
|
434
442
|
var CALLER_HEADER = "X-Palette-Caller-App";
|
|
435
|
-
function currentPluginId() {
|
|
436
|
-
if (typeof window === "undefined") return void 0;
|
|
437
|
-
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
438
|
-
return match ? decodeURIComponent(match[1]) : void 0;
|
|
439
|
-
}
|
|
440
443
|
async function brokerCallDirect(target, payload, options = {}) {
|
|
441
444
|
const callerAppId = options.callerAppId ?? currentPluginId();
|
|
442
445
|
const headers = {};
|
|
@@ -561,16 +564,11 @@ var SUBSCRIBERS = /* @__PURE__ */ new Map();
|
|
|
561
564
|
var activeStream = null;
|
|
562
565
|
var activeStreamUrl = null;
|
|
563
566
|
var sandboxBound = false;
|
|
564
|
-
function currentPluginId2() {
|
|
565
|
-
if (typeof window === "undefined") return void 0;
|
|
566
|
-
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
567
|
-
return match ? decodeURIComponent(match[1]) : void 0;
|
|
568
|
-
}
|
|
569
567
|
function streamUrl() {
|
|
570
568
|
const params = new URLSearchParams();
|
|
571
569
|
const targets = Array.from(SUBSCRIBERS.keys());
|
|
572
570
|
if (targets.length) params.set("targets", targets.join(","));
|
|
573
|
-
const callerAppId =
|
|
571
|
+
const callerAppId = currentPluginId();
|
|
574
572
|
if (callerAppId) params.set("caller_app_id", callerAppId);
|
|
575
573
|
const query = params.toString();
|
|
576
574
|
return `${getBaseUrl()}/api/v1/os-broker/events/stream${query ? `?${query}` : ""}`;
|
|
@@ -666,6 +664,32 @@ var events = {
|
|
|
666
664
|
}
|
|
667
665
|
};
|
|
668
666
|
|
|
667
|
+
// src/notifications.ts
|
|
668
|
+
function resolveActionRoute(route, appId) {
|
|
669
|
+
if (!route) return appId ? `/apps/${appId}` : void 0;
|
|
670
|
+
if (route.startsWith("/apps/")) return route;
|
|
671
|
+
if (!appId) return route;
|
|
672
|
+
return `/apps/${appId}${route.startsWith("/") ? route : `/${route}`}`;
|
|
673
|
+
}
|
|
674
|
+
var notifications = {
|
|
675
|
+
async push(input) {
|
|
676
|
+
const appId = input.appId ?? currentPluginId();
|
|
677
|
+
const res = await apiFetch("/api/v1/notifications/", {
|
|
678
|
+
method: "POST",
|
|
679
|
+
body: JSON.stringify({
|
|
680
|
+
title: input.title,
|
|
681
|
+
body: input.body,
|
|
682
|
+
type: "app",
|
|
683
|
+
source_app_id: appId,
|
|
684
|
+
action_route: resolveActionRoute(input.route, appId),
|
|
685
|
+
severity: input.severity,
|
|
686
|
+
data: input.data
|
|
687
|
+
})
|
|
688
|
+
});
|
|
689
|
+
return await res.json();
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
|
|
669
693
|
// src/permissions.ts
|
|
670
694
|
function hasPermission(ctx, permission) {
|
|
671
695
|
return ctx.permissions?.includes(permission) ?? false;
|
|
@@ -996,6 +1020,13 @@ function createPaletteClient(ctx) {
|
|
|
996
1020
|
error: (message) => ctx?.showToast(message, "error"),
|
|
997
1021
|
info: (message) => ctx?.showToast(message, "info")
|
|
998
1022
|
},
|
|
1023
|
+
/**
|
|
1024
|
+
* OS notification pool. Unlike `toast`, these persist in the OS
|
|
1025
|
+
* notification center and can open the app when clicked.
|
|
1026
|
+
*/
|
|
1027
|
+
notifications: {
|
|
1028
|
+
push: (input) => notifications.push({ appId: ctx?.pluginId || void 0, ...input })
|
|
1029
|
+
},
|
|
999
1030
|
/**
|
|
1000
1031
|
* OS-broker RPC. Typed entry point: `palette.services("org/v1").members.list({...})`.
|
|
1001
1032
|
* The proxy resolves a dotted method chain into a qualified target string
|
|
@@ -1504,6 +1535,7 @@ function usePluginChat(agentId) {
|
|
|
1504
1535
|
isSandboxRuntime,
|
|
1505
1536
|
normalizePaletteLanguage,
|
|
1506
1537
|
notFound,
|
|
1538
|
+
notifications,
|
|
1507
1539
|
palette,
|
|
1508
1540
|
requireConnection,
|
|
1509
1541
|
servicesProxy,
|
package/dist/index.mjs
CHANGED
|
@@ -325,6 +325,13 @@ var DataRoomClient = class {
|
|
|
325
325
|
};
|
|
326
326
|
var dataRooms = new DataRoomClient();
|
|
327
327
|
|
|
328
|
+
// src/plugin-id.ts
|
|
329
|
+
function currentPluginId() {
|
|
330
|
+
if (typeof window === "undefined") return void 0;
|
|
331
|
+
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
332
|
+
return match ? decodeURIComponent(match[1]) : void 0;
|
|
333
|
+
}
|
|
334
|
+
|
|
328
335
|
// src/services.ts
|
|
329
336
|
var BrokerCallError = class extends Error {
|
|
330
337
|
constructor(message, target, status) {
|
|
@@ -357,11 +364,6 @@ function brokerError(message, target, status) {
|
|
|
357
364
|
return new BrokerCallError(message, target, status);
|
|
358
365
|
}
|
|
359
366
|
var CALLER_HEADER = "X-Palette-Caller-App";
|
|
360
|
-
function currentPluginId() {
|
|
361
|
-
if (typeof window === "undefined") return void 0;
|
|
362
|
-
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
363
|
-
return match ? decodeURIComponent(match[1]) : void 0;
|
|
364
|
-
}
|
|
365
367
|
async function brokerCallDirect(target, payload, options = {}) {
|
|
366
368
|
const callerAppId = options.callerAppId ?? currentPluginId();
|
|
367
369
|
const headers = {};
|
|
@@ -486,16 +488,11 @@ var SUBSCRIBERS = /* @__PURE__ */ new Map();
|
|
|
486
488
|
var activeStream = null;
|
|
487
489
|
var activeStreamUrl = null;
|
|
488
490
|
var sandboxBound = false;
|
|
489
|
-
function currentPluginId2() {
|
|
490
|
-
if (typeof window === "undefined") return void 0;
|
|
491
|
-
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
492
|
-
return match ? decodeURIComponent(match[1]) : void 0;
|
|
493
|
-
}
|
|
494
491
|
function streamUrl() {
|
|
495
492
|
const params = new URLSearchParams();
|
|
496
493
|
const targets = Array.from(SUBSCRIBERS.keys());
|
|
497
494
|
if (targets.length) params.set("targets", targets.join(","));
|
|
498
|
-
const callerAppId =
|
|
495
|
+
const callerAppId = currentPluginId();
|
|
499
496
|
if (callerAppId) params.set("caller_app_id", callerAppId);
|
|
500
497
|
const query = params.toString();
|
|
501
498
|
return `${getBaseUrl()}/api/v1/os-broker/events/stream${query ? `?${query}` : ""}`;
|
|
@@ -591,6 +588,32 @@ var events = {
|
|
|
591
588
|
}
|
|
592
589
|
};
|
|
593
590
|
|
|
591
|
+
// src/notifications.ts
|
|
592
|
+
function resolveActionRoute(route, appId) {
|
|
593
|
+
if (!route) return appId ? `/apps/${appId}` : void 0;
|
|
594
|
+
if (route.startsWith("/apps/")) return route;
|
|
595
|
+
if (!appId) return route;
|
|
596
|
+
return `/apps/${appId}${route.startsWith("/") ? route : `/${route}`}`;
|
|
597
|
+
}
|
|
598
|
+
var notifications = {
|
|
599
|
+
async push(input) {
|
|
600
|
+
const appId = input.appId ?? currentPluginId();
|
|
601
|
+
const res = await apiFetch("/api/v1/notifications/", {
|
|
602
|
+
method: "POST",
|
|
603
|
+
body: JSON.stringify({
|
|
604
|
+
title: input.title,
|
|
605
|
+
body: input.body,
|
|
606
|
+
type: "app",
|
|
607
|
+
source_app_id: appId,
|
|
608
|
+
action_route: resolveActionRoute(input.route, appId),
|
|
609
|
+
severity: input.severity,
|
|
610
|
+
data: input.data
|
|
611
|
+
})
|
|
612
|
+
});
|
|
613
|
+
return await res.json();
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
|
|
594
617
|
// src/permissions.ts
|
|
595
618
|
function hasPermission(ctx, permission) {
|
|
596
619
|
return ctx.permissions?.includes(permission) ?? false;
|
|
@@ -921,6 +944,13 @@ function createPaletteClient(ctx) {
|
|
|
921
944
|
error: (message) => ctx?.showToast(message, "error"),
|
|
922
945
|
info: (message) => ctx?.showToast(message, "info")
|
|
923
946
|
},
|
|
947
|
+
/**
|
|
948
|
+
* OS notification pool. Unlike `toast`, these persist in the OS
|
|
949
|
+
* notification center and can open the app when clicked.
|
|
950
|
+
*/
|
|
951
|
+
notifications: {
|
|
952
|
+
push: (input) => notifications.push({ appId: ctx?.pluginId || void 0, ...input })
|
|
953
|
+
},
|
|
924
954
|
/**
|
|
925
955
|
* OS-broker RPC. Typed entry point: `palette.services("org/v1").members.list({...})`.
|
|
926
956
|
* The proxy resolves a dotted method chain into a qualified target string
|
|
@@ -1437,6 +1467,7 @@ export {
|
|
|
1437
1467
|
isSandboxRuntime,
|
|
1438
1468
|
normalizePaletteLanguage,
|
|
1439
1469
|
notFound,
|
|
1470
|
+
notifications,
|
|
1440
1471
|
palette,
|
|
1441
1472
|
requireConnection,
|
|
1442
1473
|
servicesProxy,
|