@burdenoff/be-sdk 2026.1101.3 → 2026.1102.1
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/README.md +39 -0
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +2 -2
- package/dist/cache/index.js +2 -2
- package/dist/{chunk-INAZ3PKF.js → chunk-23WAZL7I.js} +232 -135
- package/dist/chunk-23WAZL7I.js.map +1 -0
- package/dist/{chunk-QGBXVNRM.js → chunk-5SIL5AG2.js} +2 -2
- package/dist/chunk-5SIL5AG2.js.map +1 -0
- package/dist/{chunk-CKL6U4XE.js → chunk-64QUSPYG.js} +3 -3
- package/dist/{chunk-CKL6U4XE.js.map → chunk-64QUSPYG.js.map} +1 -1
- package/dist/{chunk-RAHVPZAA.js → chunk-6SDWH4OM.js} +96 -12
- package/dist/chunk-6SDWH4OM.js.map +1 -0
- package/dist/{chunk-6XZ4ELHR.js → chunk-7TOWWNHR.js} +3 -3
- package/dist/{chunk-6XZ4ELHR.js.map → chunk-7TOWWNHR.js.map} +1 -1
- package/dist/{chunk-UD5PPGVU.js → chunk-DXTBH7IW.js} +3 -3
- package/dist/{chunk-UD5PPGVU.js.map → chunk-DXTBH7IW.js.map} +1 -1
- package/dist/{chunk-4YPW6NMW.js → chunk-PAQK3YF2.js} +3 -3
- package/dist/{chunk-4YPW6NMW.js.map → chunk-PAQK3YF2.js.map} +1 -1
- package/dist/{chunk-7OAEY6FG.js → chunk-Q5H45UXV.js} +3 -3
- package/dist/{chunk-7OAEY6FG.js.map → chunk-Q5H45UXV.js.map} +1 -1
- package/dist/{chunk-QCOC2SF3.js → chunk-WSAWJC4D.js} +3 -3
- package/dist/{chunk-QCOC2SF3.js.map → chunk-WSAWJC4D.js.map} +1 -1
- package/dist/{chunk-QHSAIVEB.js → chunk-XUS3NXR5.js} +8 -8
- package/dist/{chunk-QHSAIVEB.js.map → chunk-XUS3NXR5.js.map} +1 -1
- package/dist/{chunk-PQGMZH6K.js → chunk-Y4N7N2G4.js} +3 -3
- package/dist/{chunk-PQGMZH6K.js.map → chunk-Y4N7N2G4.js.map} +1 -1
- package/dist/{chunk-Q5MGYZHG.js → chunk-YZIWBUIN.js} +3 -3
- package/dist/{chunk-Q5MGYZHG.js.map → chunk-YZIWBUIN.js.map} +1 -1
- package/dist/database/index.js +2 -2
- package/dist/event-queue/index.d.ts +3 -3
- package/dist/export/index.js +2 -2
- package/dist/gateway/index.js +2 -2
- package/dist/gateway/security/index.js +1 -1
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/index.js +2 -2
- package/dist/{graphql-BUbw43Zx.d.ts → graphql-CEblo7lw.d.ts} +1 -1
- package/dist/{index-CV3r9Taj.d.ts → index-7pTpoN3Q.d.ts} +1 -0
- package/dist/{index-BKOBmdq7.d.ts → index-BHe7zIVb.d.ts} +16 -8
- package/dist/{index-DXPFlxpZ.d.ts → index-BV8hveh_.d.ts} +3 -3
- package/dist/{index-Coua7_P7.d.ts → index-BioY0Ewz.d.ts} +1 -1
- package/dist/{index-Dtj9Eer3.d.ts → index-KZ4OzW6D.d.ts} +1 -1
- package/dist/{index-3ZE1m-ZJ.d.ts → index-XzbbMKe4.d.ts} +2 -2
- package/dist/{index-JTx7ZQHe.d.ts → index-zCx_euvK.d.ts} +2 -2
- package/dist/index.d.ts +13 -13
- package/dist/index.js +37 -34
- package/dist/index.js.map +1 -1
- package/dist/init/index.js +2 -2
- package/dist/instrumentation/index.d.ts +3 -3
- package/dist/logger/index.d.ts +2 -2
- package/dist/notifications/index.d.ts +3 -3
- package/dist/notifications/index.js +2 -2
- package/dist/prisma/index.js +2 -2
- package/dist/rbac/index.d.ts +2 -2
- package/dist/rbac/index.js +2 -2
- package/dist/resource-caps/index.d.ts +2 -2
- package/dist/telemetry/index.d.ts +4 -4
- package/dist/tracker/index.d.ts +4 -4
- package/dist/tracker/index.js +7 -7
- package/dist/usage/index.d.ts +2 -2
- package/dist/usage/index.js +4 -4
- package/package.json +3 -3
- package/dist/chunk-INAZ3PKF.js.map +0 -1
- package/dist/chunk-QGBXVNRM.js.map +0 -1
- package/dist/chunk-RAHVPZAA.js.map +0 -1
package/README.md
CHANGED
|
@@ -91,6 +91,45 @@ await sdk.translation.upsertProductTranslations({
|
|
|
91
91
|
});
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
## Tenant notification delivery
|
|
95
|
+
|
|
96
|
+
Workspace services use the private `GLOBAL_PUBLIC_GATEWAY_URL` for tenant/global calls.
|
|
97
|
+
Supply the actual service identity through the normal runtime configuration. Per-request
|
|
98
|
+
workspace and organization context can be passed without mutating a shared SDK instance:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import {
|
|
102
|
+
TenantNotificationChannel,
|
|
103
|
+
TenantNotificationType,
|
|
104
|
+
} from '@burdenoff/be-sdk';
|
|
105
|
+
|
|
106
|
+
const notificationId = await sdk.tenantNotifications.send(
|
|
107
|
+
{
|
|
108
|
+
recipient: { userId: recipientId },
|
|
109
|
+
channel: TenantNotificationChannel.IN_APP,
|
|
110
|
+
type: TenantNotificationType.SYSTEM,
|
|
111
|
+
subject: 'Workflow completed',
|
|
112
|
+
body: 'Your workflow has completed.',
|
|
113
|
+
metadata: { eventId, resourceId },
|
|
114
|
+
expiresAt,
|
|
115
|
+
},
|
|
116
|
+
{ workspaceId, organizationId },
|
|
117
|
+
);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`send()` uses the owner's trigger API, preserving metadata and expiry, and returns a real
|
|
121
|
+
notification identifier only after acknowledgement. External delivery remains asynchronous.
|
|
122
|
+
A supplied `scheduledFor` uses the dedicated scheduling API. Batch notifications must share
|
|
123
|
+
a schedule; use individual sends for different schedules. The legacy batch `totalQueued`
|
|
124
|
+
field aliases the owner's `totalTriggered` acceptance counter, not a final delivery count.
|
|
125
|
+
|
|
126
|
+
Read/delete helpers return the owner's acknowledgement, including `false` for incomplete
|
|
127
|
+
operations. List helpers unwrap owner connections; template inventory is paginated completely
|
|
128
|
+
within a bounded limit. `getStats()` exposes actual owner counters, including `triggered`,
|
|
129
|
+
`scheduled` and `cancelled`; deprecated `queued` and `processing` fields are absent because the
|
|
130
|
+
owner does not publish those measurements. The `TenantNotificationType` delivery-intent enum
|
|
131
|
+
is distinct from the convenience API's severity enum.
|
|
132
|
+
|
|
94
133
|
## Features
|
|
95
134
|
|
|
96
135
|
- **Unified Tracking**: Single function for RBAC + Activity + Usage + Quota checking
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BurdenoffGraphQLClient } from '../graphql-
|
|
2
|
-
import { a as SDKContext } from '../index-
|
|
1
|
+
import { B as BurdenoffGraphQLClient } from '../graphql-CEblo7lw.js';
|
|
2
|
+
import { a as SDKContext } from '../index-7pTpoN3Q.js';
|
|
3
3
|
import { G as GraphQLContext } from '../types-USOv09qy.js';
|
|
4
4
|
import 'graphql-request';
|
|
5
5
|
import '../layer-Cv9vSwBx.js';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { AuthCookieHelper, AuthModule } from '../chunk-
|
|
1
|
+
export { AuthCookieHelper, AuthModule } from '../chunk-YZIWBUIN.js';
|
|
2
2
|
import '../chunk-LA5KPWZ2.js';
|
|
3
|
-
import '../chunk-
|
|
3
|
+
import '../chunk-5SIL5AG2.js';
|
|
4
4
|
import '../chunk-5CAFHK2Z.js';
|
|
5
5
|
import '../chunk-RU266375.js';
|
|
6
6
|
import '../chunk-XE4OXN2W.js';
|
package/dist/cache/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { CacheFactory, CacheProviderType, MemoryCacheProvider, ValkeyGlideProvider, assertCacheEndpointConfigured, closeAllCaches, createCache, getCache, getValkeyClient, warnOnLayerDefaultEndpoint } from '../chunk-
|
|
2
|
-
import '../chunk-KO2ZXZ7W.js';
|
|
1
|
+
export { CacheFactory, CacheProviderType, MemoryCacheProvider, ValkeyGlideProvider, assertCacheEndpointConfigured, closeAllCaches, createCache, getCache, getValkeyClient, warnOnLayerDefaultEndpoint } from '../chunk-PAQK3YF2.js';
|
|
3
2
|
import '../chunk-A5F6Z5UE.js';
|
|
3
|
+
import '../chunk-KO2ZXZ7W.js';
|
|
4
4
|
import '../chunk-5CAFHK2Z.js';
|
|
5
5
|
import '../chunk-RU266375.js';
|
|
6
6
|
import '../chunk-XE4OXN2W.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ValidationError } from './chunk-
|
|
1
|
+
import { APIError, ValidationError } from './chunk-5SIL5AG2.js';
|
|
2
2
|
import { logger } from './chunk-RU266375.js';
|
|
3
3
|
import { __export, __name } from './chunk-XE4OXN2W.js';
|
|
4
4
|
|
|
@@ -50,54 +50,89 @@ var TenantNotificationsModule = class {
|
|
|
50
50
|
/**
|
|
51
51
|
* Send a single notification
|
|
52
52
|
*/
|
|
53
|
-
async send(input) {
|
|
53
|
+
async send(input, context) {
|
|
54
54
|
this.validateSendInput(input);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
mutation
|
|
62
|
-
|
|
55
|
+
const notification = this.createNotificationInput(input);
|
|
56
|
+
const callContext = {
|
|
57
|
+
...this.context,
|
|
58
|
+
...context
|
|
59
|
+
};
|
|
60
|
+
if (input.scheduledFor) {
|
|
61
|
+
const response2 = await this.client.tenantQuery(`mutation ScheduleTenantNotification($input: ScheduleNotificationInput!) {
|
|
62
|
+
scheduleNotification(input: $input) { notificationId status }
|
|
63
|
+
}`, {
|
|
64
|
+
input: {
|
|
65
|
+
notification,
|
|
66
|
+
scheduledFor: input.scheduledFor.toISOString(),
|
|
67
|
+
timezone: input.recipient.timezone
|
|
68
|
+
}
|
|
69
|
+
}, callContext);
|
|
70
|
+
const result2 = response2.scheduleNotification;
|
|
71
|
+
if (!result2?.notificationId || result2.status !== "PENDING") {
|
|
72
|
+
throw new APIError("Notification scheduling was not acknowledged", {
|
|
73
|
+
operation: "scheduleNotification"
|
|
74
|
+
});
|
|
63
75
|
}
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
return result2.notificationId;
|
|
77
|
+
}
|
|
78
|
+
const response = await this.client.tenantQuery(`mutation TriggerTenantNotification($input: TriggerNotificationInput!) {
|
|
79
|
+
triggerNotification(input: $input) { id status channel }
|
|
80
|
+
}`, {
|
|
66
81
|
input: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
priority: input.priority || "MEDIUM",
|
|
71
|
-
subject: input.subject,
|
|
72
|
-
body: input.body,
|
|
73
|
-
htmlBody: input.htmlBody,
|
|
74
|
-
data: input.data,
|
|
75
|
-
metadata: input.metadata,
|
|
76
|
-
scheduledFor: input.scheduledFor?.toISOString(),
|
|
77
|
-
expiresAt: input.expiresAt?.toISOString(),
|
|
78
|
-
trackOpens: input.trackOpens,
|
|
79
|
-
trackClicks: input.trackClicks
|
|
82
|
+
notification,
|
|
83
|
+
platform: input.channel,
|
|
84
|
+
includeInApp: false
|
|
80
85
|
}
|
|
81
|
-
};
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
}, callContext);
|
|
87
|
+
const result = response.triggerNotification;
|
|
88
|
+
if (!result?.id || result.channel !== input.channel || ![
|
|
89
|
+
"TRIGGERED",
|
|
90
|
+
"SENT",
|
|
91
|
+
"DELIVERED"
|
|
92
|
+
].includes(result.status)) {
|
|
93
|
+
throw new APIError("Notification trigger was not acknowledged", {
|
|
94
|
+
operation: "triggerNotification",
|
|
95
|
+
notificationId: result?.id
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
logger.info("[TenantNotifications] Notification accepted", {
|
|
99
|
+
notificationId: result.id,
|
|
100
|
+
channel: result.channel,
|
|
101
|
+
status: result.status
|
|
85
102
|
});
|
|
86
|
-
return
|
|
103
|
+
return result.id;
|
|
104
|
+
}
|
|
105
|
+
/** Owner input deliberately excludes scheduling, which has a separate API. */
|
|
106
|
+
createNotificationInput(input, priority) {
|
|
107
|
+
return {
|
|
108
|
+
recipient: input.recipient,
|
|
109
|
+
channel: input.channel,
|
|
110
|
+
type: input.type ?? "TRANSACTIONAL",
|
|
111
|
+
priority: input.priority ?? priority ?? "MEDIUM",
|
|
112
|
+
subject: input.subject,
|
|
113
|
+
body: input.body,
|
|
114
|
+
htmlBody: input.htmlBody,
|
|
115
|
+
data: input.data,
|
|
116
|
+
metadata: input.metadata,
|
|
117
|
+
expiresAt: input.expiresAt?.toISOString(),
|
|
118
|
+
trackOpens: input.trackOpens,
|
|
119
|
+
trackClicks: input.trackClicks
|
|
120
|
+
};
|
|
87
121
|
}
|
|
88
122
|
/**
|
|
89
123
|
* Send notification using a template
|
|
90
124
|
*/
|
|
91
|
-
async sendWithTemplate(input) {
|
|
125
|
+
async sendWithTemplate(input, context) {
|
|
92
126
|
if (!input.templateSlug || input.templateSlug.trim().length === 0) {
|
|
93
127
|
throw new ValidationError("Template slug is required");
|
|
94
128
|
}
|
|
95
|
-
if (!input.variables ||
|
|
96
|
-
throw new ValidationError("Template variables
|
|
129
|
+
if (!input.variables || typeof input.variables !== "object" || Array.isArray(input.variables)) {
|
|
130
|
+
throw new ValidationError("Template variables must be an object");
|
|
97
131
|
}
|
|
98
132
|
if (!input.recipient || !input.recipient.email && !input.recipient.userId) {
|
|
99
133
|
throw new ValidationError("Recipient email or userId is required");
|
|
100
134
|
}
|
|
135
|
+
this.validateDates(input);
|
|
101
136
|
logger.info("[TenantNotifications] Sending notification with template", {
|
|
102
137
|
templateSlug: input.templateSlug,
|
|
103
138
|
priority: input.priority || "MEDIUM"
|
|
@@ -133,7 +168,10 @@ var TenantNotificationsModule = class {
|
|
|
133
168
|
timezone: input.timezone
|
|
134
169
|
}
|
|
135
170
|
};
|
|
136
|
-
const response = await this.client.tenantQuery(mutation, variables,
|
|
171
|
+
const response = await this.client.tenantQuery(mutation, variables, {
|
|
172
|
+
...this.context,
|
|
173
|
+
...context
|
|
174
|
+
});
|
|
137
175
|
const result = response.triggerNotificationWithTemplate;
|
|
138
176
|
const firstNotification = result.notifications[0];
|
|
139
177
|
if (result.totalTriggered === 0 || !firstNotification) {
|
|
@@ -150,53 +188,38 @@ var TenantNotificationsModule = class {
|
|
|
150
188
|
/**
|
|
151
189
|
* Send batch notifications
|
|
152
190
|
*/
|
|
153
|
-
async sendBatch(input) {
|
|
154
|
-
if (!input.notifications
|
|
155
|
-
|
|
191
|
+
async sendBatch(input, context) {
|
|
192
|
+
if (!input.notifications?.length) throw new ValidationError("At least one notification is required");
|
|
193
|
+
for (const notification of input.notifications) this.validateSendInput(notification);
|
|
194
|
+
const schedules = new Set(input.notifications.map((notification) => notification.scheduledFor?.toISOString() ?? ""));
|
|
195
|
+
if (schedules.size > 1) {
|
|
196
|
+
throw new ValidationError("Batch notifications must share a schedule; use send() for distinct schedules");
|
|
156
197
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
totalFailed
|
|
167
|
-
batchId
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
`;
|
|
171
|
-
const variables = {
|
|
198
|
+
if (input.batchSize !== void 0 && (!Number.isInteger(input.batchSize) || input.batchSize <= 0)) {
|
|
199
|
+
throw new ValidationError("Batch size must be a positive integer");
|
|
200
|
+
}
|
|
201
|
+
if (input.delayBetweenBatches !== void 0 && (!Number.isInteger(input.delayBetweenBatches) || input.delayBetweenBatches < 0)) {
|
|
202
|
+
throw new ValidationError("Batch delay must be a nonnegative integer");
|
|
203
|
+
}
|
|
204
|
+
const response = await this.client.tenantQuery(`mutation TriggerTenantBatchNotifications($input: TriggerBatchNotificationsInput!) {
|
|
205
|
+
triggerBatchNotifications(input: $input) { totalRequested totalQueued: totalTriggered totalFailed batchId }
|
|
206
|
+
}`, {
|
|
172
207
|
input: {
|
|
173
|
-
notifications: input.notifications.map((
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
type: n.type || "TRANSACTIONAL",
|
|
177
|
-
priority: n.priority || "MEDIUM",
|
|
178
|
-
subject: n.subject,
|
|
179
|
-
body: n.body,
|
|
180
|
-
htmlBody: n.htmlBody,
|
|
181
|
-
data: n.data,
|
|
182
|
-
metadata: n.metadata,
|
|
183
|
-
scheduledFor: n.scheduledFor?.toISOString(),
|
|
184
|
-
expiresAt: n.expiresAt?.toISOString(),
|
|
185
|
-
trackOpens: n.trackOpens,
|
|
186
|
-
trackClicks: n.trackClicks
|
|
187
|
-
})),
|
|
208
|
+
notifications: input.notifications.map((notification) => this.createNotificationInput(notification, input.priority)),
|
|
209
|
+
priority: input.priority,
|
|
210
|
+
scheduledFor: input.notifications[0]?.scheduledFor?.toISOString(),
|
|
188
211
|
batchSize: input.batchSize,
|
|
189
|
-
delayBetweenBatches: input.delayBetweenBatches
|
|
190
|
-
priority: input.priority
|
|
212
|
+
delayBetweenBatches: input.delayBetweenBatches
|
|
191
213
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
214
|
+
}, {
|
|
215
|
+
...this.context,
|
|
216
|
+
...context
|
|
217
|
+
});
|
|
218
|
+
const result = response.triggerBatchNotifications;
|
|
219
|
+
if (!result?.batchId) throw new APIError("Notification batch was not acknowledged", {
|
|
220
|
+
operation: "triggerBatchNotifications"
|
|
198
221
|
});
|
|
199
|
-
return
|
|
222
|
+
return result;
|
|
200
223
|
}
|
|
201
224
|
/**
|
|
202
225
|
* Get a notification by ID
|
|
@@ -241,6 +264,7 @@ var TenantNotificationsModule = class {
|
|
|
241
264
|
const query = `
|
|
242
265
|
query GetNotifications($filter: NotificationFilterInput, $limit: Int, $offset: Int) {
|
|
243
266
|
notifications(filter: $filter, limit: $limit, offset: $offset) {
|
|
267
|
+
items {
|
|
244
268
|
id
|
|
245
269
|
userId
|
|
246
270
|
channel
|
|
@@ -260,6 +284,7 @@ var TenantNotificationsModule = class {
|
|
|
260
284
|
deliveredAt
|
|
261
285
|
createdAt
|
|
262
286
|
updatedAt
|
|
287
|
+
}
|
|
263
288
|
}
|
|
264
289
|
}
|
|
265
290
|
`;
|
|
@@ -273,11 +298,11 @@ var TenantNotificationsModule = class {
|
|
|
273
298
|
startDate: filter.startDate?.toISOString(),
|
|
274
299
|
endDate: filter.endDate?.toISOString()
|
|
275
300
|
} : void 0,
|
|
276
|
-
limit: filter?.limit
|
|
277
|
-
offset: filter?.offset
|
|
301
|
+
limit: filter?.limit ?? 50,
|
|
302
|
+
offset: filter?.offset ?? 0
|
|
278
303
|
};
|
|
279
304
|
const response = await this.client.tenantQuery(query, variables, this.context);
|
|
280
|
-
return response.notifications;
|
|
305
|
+
return response.notifications.items;
|
|
281
306
|
}
|
|
282
307
|
/**
|
|
283
308
|
* Get notification template
|
|
@@ -314,31 +339,45 @@ var TenantNotificationsModule = class {
|
|
|
314
339
|
* Get all notification templates
|
|
315
340
|
*/
|
|
316
341
|
async getTemplates(filter) {
|
|
317
|
-
const query = `
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
342
|
+
const query = `query GetNotificationTemplates($filter: TemplateFilterInput, $limit: Int!, $offset: Int!) {
|
|
343
|
+
notificationTemplates(filter: $filter, limit: $limit, offset: $offset) {
|
|
344
|
+
items { id name slug description channel type locale subject bodyTemplate htmlTemplate variables enabled version createdAt updatedAt }
|
|
345
|
+
hasMore
|
|
346
|
+
}
|
|
347
|
+
}`;
|
|
348
|
+
const templates = [];
|
|
349
|
+
const seen = /* @__PURE__ */ new Set();
|
|
350
|
+
for (let page = 0; page < 100; page++) {
|
|
351
|
+
const response = await this.client.tenantQuery(query, {
|
|
352
|
+
filter,
|
|
353
|
+
limit: 100,
|
|
354
|
+
offset: templates.length
|
|
355
|
+
}, this.context);
|
|
356
|
+
const result = response.notificationTemplates;
|
|
357
|
+
if (!result || !Array.isArray(result.items) || typeof result.hasMore !== "boolean") {
|
|
358
|
+
throw new APIError("Notification template page was invalid", {
|
|
359
|
+
operation: "notificationTemplates"
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
for (const template of result.items) {
|
|
363
|
+
if (!template.id || seen.has(template.id)) {
|
|
364
|
+
throw new APIError("Notification template pagination did not progress", {
|
|
365
|
+
operation: "notificationTemplates"
|
|
366
|
+
});
|
|
335
367
|
}
|
|
368
|
+
seen.add(template.id);
|
|
369
|
+
templates.push(template);
|
|
336
370
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
371
|
+
if (!result.hasMore) return templates;
|
|
372
|
+
if (!result.items.length) {
|
|
373
|
+
throw new APIError("Notification template pagination did not progress", {
|
|
374
|
+
operation: "notificationTemplates"
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
throw new APIError("Notification template pagination exceeded its bounded limit", {
|
|
379
|
+
operation: "notificationTemplates"
|
|
380
|
+
});
|
|
342
381
|
}
|
|
343
382
|
/**
|
|
344
383
|
* Get notification statistics
|
|
@@ -349,8 +388,9 @@ var TenantNotificationsModule = class {
|
|
|
349
388
|
notificationStats(filter: $filter) {
|
|
350
389
|
total
|
|
351
390
|
pending
|
|
352
|
-
|
|
353
|
-
|
|
391
|
+
triggered
|
|
392
|
+
scheduled
|
|
393
|
+
cancelled
|
|
354
394
|
sent
|
|
355
395
|
delivered
|
|
356
396
|
failed
|
|
@@ -375,16 +415,17 @@ var TenantNotificationsModule = class {
|
|
|
375
415
|
async markAsRead(notificationIds) {
|
|
376
416
|
const mutation = `
|
|
377
417
|
mutation MarkNotificationsAsRead($notificationIds: [ID!]!) {
|
|
378
|
-
markNotificationsAsRead(notificationIds: $notificationIds)
|
|
418
|
+
markNotificationsAsRead(notificationIds: $notificationIds) { success count failedIds }
|
|
379
419
|
}
|
|
380
420
|
`;
|
|
381
|
-
await this.client.tenantQuery(mutation, {
|
|
421
|
+
const result = await this.client.tenantQuery(mutation, {
|
|
382
422
|
notificationIds
|
|
383
423
|
}, this.context);
|
|
384
|
-
logger.info("[TenantNotifications]
|
|
424
|
+
logger.info("[TenantNotifications] Read request completed", {
|
|
425
|
+
success: result.markNotificationsAsRead.success,
|
|
385
426
|
count: notificationIds.length
|
|
386
427
|
});
|
|
387
|
-
return
|
|
428
|
+
return result.markNotificationsAsRead.success;
|
|
388
429
|
}
|
|
389
430
|
/**
|
|
390
431
|
* Mark all notifications as read for the current user
|
|
@@ -392,12 +433,14 @@ var TenantNotificationsModule = class {
|
|
|
392
433
|
async markAllAsRead() {
|
|
393
434
|
const mutation = `
|
|
394
435
|
mutation MarkAllMyNotificationsAsRead {
|
|
395
|
-
markAllMyNotificationsAsRead
|
|
436
|
+
markAllMyNotificationsAsRead { success count failedIds }
|
|
396
437
|
}
|
|
397
438
|
`;
|
|
398
|
-
await this.client.tenantQuery(mutation, {}, this.context);
|
|
399
|
-
logger.info("[TenantNotifications]
|
|
400
|
-
|
|
439
|
+
const result = await this.client.tenantQuery(mutation, {}, this.context);
|
|
440
|
+
logger.info("[TenantNotifications] Read-all request completed", {
|
|
441
|
+
success: result.markAllMyNotificationsAsRead.success
|
|
442
|
+
});
|
|
443
|
+
return result.markAllMyNotificationsAsRead.success;
|
|
401
444
|
}
|
|
402
445
|
/**
|
|
403
446
|
* Delete notifications
|
|
@@ -408,13 +451,14 @@ var TenantNotificationsModule = class {
|
|
|
408
451
|
deleteNotifications(notificationIds: $notificationIds)
|
|
409
452
|
}
|
|
410
453
|
`;
|
|
411
|
-
await this.client.tenantQuery(mutation, {
|
|
454
|
+
const result = await this.client.tenantQuery(mutation, {
|
|
412
455
|
notificationIds
|
|
413
456
|
}, this.context);
|
|
414
|
-
logger.info("[TenantNotifications]
|
|
457
|
+
logger.info("[TenantNotifications] Delete request completed", {
|
|
458
|
+
success: result.deleteNotifications,
|
|
415
459
|
count: notificationIds.length
|
|
416
460
|
});
|
|
417
|
-
return
|
|
461
|
+
return result.deleteNotifications;
|
|
418
462
|
}
|
|
419
463
|
/**
|
|
420
464
|
* Delete all read notifications for the current user
|
|
@@ -425,31 +469,79 @@ var TenantNotificationsModule = class {
|
|
|
425
469
|
deleteMyReadNotifications
|
|
426
470
|
}
|
|
427
471
|
`;
|
|
428
|
-
await this.client.tenantQuery(mutation, {}, this.context);
|
|
429
|
-
logger.info("[TenantNotifications]
|
|
430
|
-
|
|
472
|
+
const result = await this.client.tenantQuery(mutation, {}, this.context);
|
|
473
|
+
logger.info("[TenantNotifications] Delete-read request completed", {
|
|
474
|
+
success: result.deleteMyReadNotifications
|
|
475
|
+
});
|
|
476
|
+
return result.deleteMyReadNotifications;
|
|
431
477
|
}
|
|
432
478
|
/**
|
|
433
479
|
* Validate send notification input
|
|
434
480
|
*/
|
|
435
481
|
validateSendInput(input) {
|
|
436
|
-
if (!
|
|
437
|
-
throw new ValidationError("
|
|
482
|
+
if (!Object.values(NotificationChannel).includes(input.channel)) {
|
|
483
|
+
throw new ValidationError("A supported notification channel is required");
|
|
438
484
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
485
|
+
const recipientKeys = {
|
|
486
|
+
EMAIL: [
|
|
487
|
+
"email",
|
|
488
|
+
"userId"
|
|
489
|
+
],
|
|
490
|
+
SMS: [
|
|
491
|
+
"phoneNumber",
|
|
492
|
+
"userId"
|
|
493
|
+
],
|
|
494
|
+
PUSH: [
|
|
495
|
+
"pushToken",
|
|
496
|
+
"userId"
|
|
497
|
+
],
|
|
498
|
+
IN_APP: [
|
|
499
|
+
"userId"
|
|
500
|
+
],
|
|
501
|
+
WEBHOOK: [
|
|
502
|
+
"webhookUrl",
|
|
503
|
+
"userId"
|
|
504
|
+
],
|
|
505
|
+
WHATSAPP: [
|
|
506
|
+
"whatsappNumber",
|
|
507
|
+
"phoneNumber",
|
|
508
|
+
"userId"
|
|
509
|
+
],
|
|
510
|
+
TEAMS: [
|
|
511
|
+
"teamsUserId",
|
|
512
|
+
"userId"
|
|
513
|
+
],
|
|
514
|
+
SLACK: [
|
|
515
|
+
"slackUserId",
|
|
516
|
+
"userId"
|
|
517
|
+
],
|
|
518
|
+
TELEGRAM: [
|
|
519
|
+
"userId"
|
|
520
|
+
],
|
|
521
|
+
DISCORD: [
|
|
522
|
+
"userId"
|
|
523
|
+
]
|
|
524
|
+
};
|
|
525
|
+
if (!input.recipient || !recipientKeys[input.channel].some((key) => {
|
|
526
|
+
const value = input.recipient[key];
|
|
527
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
528
|
+
})) throw new ValidationError("A recipient address or userId appropriate for the channel is required");
|
|
529
|
+
if (typeof input.body !== "string" || input.body.trim().length === 0) {
|
|
443
530
|
throw new ValidationError("Notification body is required");
|
|
444
531
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
532
|
+
this.validateDates(input);
|
|
533
|
+
}
|
|
534
|
+
validateDates(input) {
|
|
535
|
+
for (const value of [
|
|
536
|
+
input.scheduledFor,
|
|
537
|
+
input.expiresAt
|
|
538
|
+
]) {
|
|
539
|
+
if (value != null && (!(value instanceof Date) || !Number.isFinite(value.getTime()))) {
|
|
540
|
+
throw new ValidationError("Notification dates must be valid Date values");
|
|
541
|
+
}
|
|
450
542
|
}
|
|
451
|
-
if (input.
|
|
452
|
-
throw new ValidationError("
|
|
543
|
+
if (input.scheduledFor && input.expiresAt && input.expiresAt <= input.scheduledFor) {
|
|
544
|
+
throw new ValidationError("Notification expiry must follow its scheduled delivery");
|
|
453
545
|
}
|
|
454
546
|
}
|
|
455
547
|
};
|
|
@@ -505,8 +597,10 @@ var NotificationsModule = class {
|
|
|
505
597
|
if (!options.userIds || options.userIds.length === 0) {
|
|
506
598
|
throw new ValidationError("At least one user ID is required");
|
|
507
599
|
}
|
|
600
|
+
if (options.expiresAt && (!(options.expiresAt instanceof Date) || !Number.isFinite(options.expiresAt.getTime()))) {
|
|
601
|
+
throw new ValidationError("Notification expiry must be a valid Date");
|
|
602
|
+
}
|
|
508
603
|
logger.info("[Notifications] Sending notification", {
|
|
509
|
-
title: options.title,
|
|
510
604
|
userCount: options.userIds.length,
|
|
511
605
|
type: options.type || "info"
|
|
512
606
|
});
|
|
@@ -532,6 +626,9 @@ var NotificationsModule = class {
|
|
|
532
626
|
type: mapNotificationType(options.type),
|
|
533
627
|
subject: options.title,
|
|
534
628
|
body: options.message,
|
|
629
|
+
metadata: options.metadata,
|
|
630
|
+
data: options.data,
|
|
631
|
+
expiresAt: options.expiresAt?.toISOString(),
|
|
535
632
|
...options.redirectUrl ? {
|
|
536
633
|
redirectUrl: options.redirectUrl
|
|
537
634
|
} : {},
|
|
@@ -961,6 +1058,6 @@ var NotificationsModule = class {
|
|
|
961
1058
|
}
|
|
962
1059
|
};
|
|
963
1060
|
|
|
964
|
-
export {
|
|
965
|
-
//# sourceMappingURL=chunk-
|
|
966
|
-
//# sourceMappingURL=chunk-
|
|
1061
|
+
export { NotificationChannel, NotificationChannel2, NotificationPriority, NotificationType, NotificationType2, NotificationsModule, TenantNotificationsModule, tenant_notifications_exports };
|
|
1062
|
+
//# sourceMappingURL=chunk-23WAZL7I.js.map
|
|
1063
|
+
//# sourceMappingURL=chunk-23WAZL7I.js.map
|