@or-sdk/notifications 1.1.20 → 1.2.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/CHANGELOG.md +9 -0
- package/dist/cjs/Notifications.js +93 -44
- package/dist/cjs/Notifications.js.map +1 -1
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/schemas/config.schema.js +24 -0
- package/dist/cjs/schemas/config.schema.js.map +1 -0
- package/dist/cjs/schemas/createTrailEvent.schema.js +10 -0
- package/dist/cjs/schemas/createTrailEvent.schema.js.map +1 -0
- package/dist/cjs/schemas/index.js +21 -0
- package/dist/cjs/schemas/index.js.map +1 -0
- package/dist/cjs/schemas/listTrailEvents.schema.js +21 -0
- package/dist/cjs/schemas/listTrailEvents.schema.js.map +1 -0
- package/dist/cjs/schemas/trailEvent.schema.js +25 -0
- package/dist/cjs/schemas/trailEvent.schema.js.map +1 -0
- package/dist/esm/Notifications.js +25 -18
- package/dist/esm/Notifications.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/config.schema.js +21 -0
- package/dist/esm/schemas/config.schema.js.map +1 -0
- package/dist/esm/schemas/createTrailEvent.schema.js +7 -0
- package/dist/esm/schemas/createTrailEvent.schema.js.map +1 -0
- package/dist/esm/schemas/index.js +5 -0
- package/dist/esm/schemas/index.js.map +1 -0
- package/dist/esm/schemas/listTrailEvents.schema.js +18 -0
- package/dist/esm/schemas/listTrailEvents.schema.js.map +1 -0
- package/dist/esm/schemas/trailEvent.schema.js +22 -0
- package/dist/esm/schemas/trailEvent.schema.js.map +1 -0
- package/dist/types/Notifications.d.ts +11 -8
- package/dist/types/Notifications.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/schemas/config.schema.d.ts +48 -0
- package/dist/types/schemas/config.schema.d.ts.map +1 -0
- package/dist/types/schemas/createTrailEvent.schema.d.ts +72 -0
- package/dist/types/schemas/createTrailEvent.schema.d.ts.map +1 -0
- package/dist/types/schemas/index.d.ts +5 -0
- package/dist/types/schemas/index.d.ts.map +1 -0
- package/dist/types/schemas/listTrailEvents.schema.d.ts +46 -0
- package/dist/types/schemas/listTrailEvents.schema.d.ts.map +1 -0
- package/dist/types/schemas/trailEvent.schema.d.ts +120 -0
- package/dist/types/schemas/trailEvent.schema.d.ts.map +1 -0
- package/dist/types/types.d.ts +0 -29
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/Notifications.ts +88 -39
- package/src/index.ts +2 -1
- package/src/schemas/config.schema.ts +37 -0
- package/src/schemas/createTrailEvent.schema.ts +12 -0
- package/src/schemas/index.ts +4 -0
- package/src/schemas/listTrailEvents.schema.ts +39 -0
- package/src/schemas/trailEvent.schema.ts +46 -0
- package/src/types.ts +0 -48
package/src/index.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Token } from '@or-sdk/base';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const baseNotificationsConfig = z.object({
|
|
5
|
+
/** Authorization token or factory function. */
|
|
6
|
+
token: z.union([
|
|
7
|
+
z.string().min(1),
|
|
8
|
+
z.function().args().returns(z.string()),
|
|
9
|
+
]).describe('Authorization token or factory function') satisfies z.ZodType<Token>,
|
|
10
|
+
/** Account id for cross-account requests. Requires SUPER_ADMIN role. */
|
|
11
|
+
accountId: z.string().uuid().optional().describe('Account ID for cross-account requests'),
|
|
12
|
+
|
|
13
|
+
/** If true validate method params. Default: true */
|
|
14
|
+
validateInputs: z.boolean().optional().describe('If true validate inputs'),
|
|
15
|
+
/** If true validate method results. Default: true */
|
|
16
|
+
validateOutputs: z.boolean().optional().describe('If true validate outputs'),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const notificationsConfigSchema = z.union([
|
|
20
|
+
baseNotificationsConfig.extend({
|
|
21
|
+
/** URL of ServiceDiscovery API service */
|
|
22
|
+
discoveryUrl: z.undefined(),
|
|
23
|
+
/** URL of Notifications API service */
|
|
24
|
+
notificationsUrl: z.string().url().describe('URL of notifications API service'),
|
|
25
|
+
}),
|
|
26
|
+
baseNotificationsConfig.extend({
|
|
27
|
+
/** URL of ServiceDiscovery API service */
|
|
28
|
+
discoveryUrl: z.string().url().describe('URL of service discovery API'),
|
|
29
|
+
/** URL of Notifications API service */
|
|
30
|
+
notificationsUrl: z.undefined(),
|
|
31
|
+
}),
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {z.infer<typeof notificationsConfigSchema>} NotificationsConfig
|
|
36
|
+
*/
|
|
37
|
+
export type NotificationsConfig = z.infer<typeof notificationsConfigSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import { trailEventSchema } from './trailEvent.schema';
|
|
4
|
+
|
|
5
|
+
export const createTrailEventSchema = z.object({
|
|
6
|
+
/** The service that triggered the event */
|
|
7
|
+
service: trailEventSchema.shape.name,
|
|
8
|
+
/** Trail event details */
|
|
9
|
+
data: trailEventSchema.shape.attributes,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type CreateTrailEvent = Omit<z.infer<typeof createTrailEventSchema>, never>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import { trailEventSchema } from './trailEvent.schema';
|
|
4
|
+
|
|
5
|
+
export const listTrailEventsParamsSchema = z.object({
|
|
6
|
+
/** The message to be displayed in the notification */
|
|
7
|
+
service: trailEventSchema.shape.name,
|
|
8
|
+
|
|
9
|
+
/** The starting point for the list of events */
|
|
10
|
+
from: z.number().int().min(0).optional().describe('The starting point for the list of events'),
|
|
11
|
+
/** The number of events to retrieve */
|
|
12
|
+
size: z.number().min(1).optional().describe('The number of events to retrieve'),
|
|
13
|
+
|
|
14
|
+
/** The start date for filtering events */
|
|
15
|
+
dateFrom: z.coerce.date().optional().describe('The start date for filtering events'),
|
|
16
|
+
/** The end date for filtering events */
|
|
17
|
+
dateTo: z.coerce.date().optional().describe('The end date for filtering events'),
|
|
18
|
+
|
|
19
|
+
/** Unique identifier of the trail event */
|
|
20
|
+
id: trailEventSchema.shape.id.optional(),
|
|
21
|
+
/** User ID related to the trail event */
|
|
22
|
+
userId: trailEventSchema.shape.userId.optional(),
|
|
23
|
+
|
|
24
|
+
/** The flow ID associated with the event */
|
|
25
|
+
flowId: trailEventSchema.shape.attributes.shape.flowId,
|
|
26
|
+
/** The bot ID associated with the event */
|
|
27
|
+
botId: trailEventSchema.shape.attributes.shape.botId,
|
|
28
|
+
|
|
29
|
+
/** The name of the creator of the event */
|
|
30
|
+
creatorName: trailEventSchema.shape.attributes.shape['creator.name'],
|
|
31
|
+
/** The user ID of the creator of the event */
|
|
32
|
+
creatorUserId: trailEventSchema.shape.attributes.shape['creator.userId'],
|
|
33
|
+
/** The multi-user ID of the creator of the event */
|
|
34
|
+
creatorMultiUserId: trailEventSchema.shape.attributes.shape['creator.multiUserId'],
|
|
35
|
+
/** The flow ID of the creator of the event */
|
|
36
|
+
creatorFlowId: trailEventSchema.shape.attributes.shape['creator.flowId'],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export type ListTrailEventsParams = Omit<z.infer<typeof listTrailEventsParamsSchema>, never>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const trailEventAttributesSchema = z.object({
|
|
4
|
+
/** The message to be displayed in the notification */
|
|
5
|
+
message: z.string().min(1).describe('The message to be displayed in the notification'),
|
|
6
|
+
/** The icon to be displayed in the notification */
|
|
7
|
+
icon: z.string().min(1).describe('The icon to be displayed in the notification'),
|
|
8
|
+
|
|
9
|
+
/** The URL to be opened when the notification is clicked */
|
|
10
|
+
url: z.string().url().optional().describe('The URL to be opened when the notification is clicked'),
|
|
11
|
+
/** The name of the URL to be displayed in the notification */
|
|
12
|
+
urlName: z.string().min(1).optional().describe('The name of the URL to be displayed in the notification'),
|
|
13
|
+
|
|
14
|
+
/** The flow ID associated with the event */
|
|
15
|
+
flowId: z.string().uuid().optional().describe('The flow ID associated with the event'),
|
|
16
|
+
/** The bot ID associated with the event */
|
|
17
|
+
botId: z.string().uuid().optional().describe('The bot ID associated with the event'),
|
|
18
|
+
|
|
19
|
+
/** The name of the creator of the event */
|
|
20
|
+
'creator.name': z.string().min(1).describe('The name of the creator of the event'),
|
|
21
|
+
/** The user ID of the creator of the event */
|
|
22
|
+
'creator.userId': z.string().uuid().optional().describe('The user ID of the creator of the event'),
|
|
23
|
+
/** The multi-user ID of the creator of the event */
|
|
24
|
+
'creator.multiUserId': z.string().uuid().optional().describe('The multi-user ID of the creator of the event'),
|
|
25
|
+
/** The flow ID of the creator of the event */
|
|
26
|
+
'creator.flowId': z.string().uuid().optional().describe('The flow ID of the creator of the event'),
|
|
27
|
+
}).passthrough(); // allow unknown fields
|
|
28
|
+
|
|
29
|
+
export type TrailEventAttributes = z.infer<typeof trailEventAttributesSchema>;
|
|
30
|
+
|
|
31
|
+
export const trailEventSchema = z.object({
|
|
32
|
+
/** Unique identifier of the trail event */
|
|
33
|
+
id: z.string().uuid().readonly().describe('Unique identifier of the trail event'),
|
|
34
|
+
/** The service that triggered the event */
|
|
35
|
+
name: z.string().min(1).describe('The service that triggered the event'),
|
|
36
|
+
/** Account ID related to the trail event */
|
|
37
|
+
accountId: z.string().uuid().describe('Account ID related to the trail event'),
|
|
38
|
+
/** User ID related to the trail event */
|
|
39
|
+
userId: z.string().uuid().optional().describe('User ID related to the trail event'),
|
|
40
|
+
/** Date-time of the trail event as ISO date-time string */
|
|
41
|
+
timestamp: z.date().readonly().describe('Date-time of the trail event as ISO date-time string'),
|
|
42
|
+
/** Trail event details */
|
|
43
|
+
attributes: trailEventAttributesSchema,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export type TrailEvent = Omit<z.infer<typeof trailEventSchema>, never>;
|
package/src/types.ts
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
import { Token } from '@or-sdk/base';
|
|
2
|
-
|
|
3
|
-
export type NotificationsConfig = {
|
|
4
|
-
/**
|
|
5
|
-
* token
|
|
6
|
-
*/
|
|
7
|
-
token: Token;
|
|
8
|
-
/**
|
|
9
|
-
* service discrovery url
|
|
10
|
-
*/
|
|
11
|
-
discoveryUrl?: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* url of notifications service
|
|
15
|
-
*/
|
|
16
|
-
notificationsUrl?: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Account id for cross account re
|
|
20
|
-
*/
|
|
21
|
-
accountId?: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
1
|
export type ListNotificationsParams = {
|
|
26
2
|
from?: number;
|
|
27
3
|
size?: number;
|
|
@@ -87,27 +63,3 @@ export type SAListNotifications = {
|
|
|
87
63
|
};
|
|
88
64
|
};
|
|
89
65
|
|
|
90
|
-
export type NewTrailEvent = {
|
|
91
|
-
service: string;
|
|
92
|
-
data: {
|
|
93
|
-
message: string;
|
|
94
|
-
icon?: string;
|
|
95
|
-
urlName?: string;
|
|
96
|
-
url?: string;
|
|
97
|
-
[key: string]: unknown;
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export type ListTrailParams = {
|
|
102
|
-
from?: number;
|
|
103
|
-
size?: number;
|
|
104
|
-
service?: string;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export type TrailEvent = {
|
|
108
|
-
id: string;
|
|
109
|
-
data: {
|
|
110
|
-
message: string;
|
|
111
|
-
};
|
|
112
|
-
dateCreated: Date;
|
|
113
|
-
};
|