@naturalcycles/nodejs-lib 15.81.1 → 15.82.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/dist/slack/slack.service.js +10 -1
- package/dist/slack/slack.service.model.d.ts +4 -3
- package/dist/validation/ajv/ajvSchema.d.ts +5 -0
- package/dist/validation/ajv/ajvSchema.js +45 -1
- package/package.json +1 -1
- package/src/slack/slack.service.model.ts +4 -3
- package/src/slack/slack.service.ts +11 -1
- package/src/validation/ajv/ajvSchema.ts +66 -1
|
@@ -82,7 +82,7 @@ export class SlackService {
|
|
|
82
82
|
text = '```' + text + '```';
|
|
83
83
|
}
|
|
84
84
|
if (msg.mentions?.length) {
|
|
85
|
-
text += '\n' + msg.mentions.map(
|
|
85
|
+
text += '\n' + msg.mentions.map(formatSlackMention).join(' ');
|
|
86
86
|
}
|
|
87
87
|
const prefix = await messagePrefixHook(msg);
|
|
88
88
|
if (prefix === null)
|
|
@@ -139,3 +139,12 @@ export function slackDefaultMessagePrefixHook(msg) {
|
|
|
139
139
|
}
|
|
140
140
|
return tokens.filter(Boolean);
|
|
141
141
|
}
|
|
142
|
+
// Formats a Slack mention based on the ID type:
|
|
143
|
+
// - User IDs (U...) and Bot IDs (B...) use: <@ID>
|
|
144
|
+
// - User Group IDs (S...) use: <!subteam^ID>
|
|
145
|
+
function formatSlackMention(id) {
|
|
146
|
+
if (id.startsWith('S')) {
|
|
147
|
+
return `<!subteam^${id}>`;
|
|
148
|
+
}
|
|
149
|
+
return `<@${id}>`;
|
|
150
|
+
}
|
|
@@ -42,9 +42,10 @@ export interface SlackMessage<CTX = any> extends SlackMessageProps {
|
|
|
42
42
|
*/
|
|
43
43
|
kv?: AnyObject;
|
|
44
44
|
/**
|
|
45
|
-
* Slack
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* Slack IDs to mention at the end of the message.
|
|
46
|
+
* Supports:
|
|
47
|
+
* - User IDs (e.g., 'U1234567890') - click profile → "..." → "Copy member ID"
|
|
48
|
+
* - User Group IDs (e.g., 'S1234567890') - from user group settings
|
|
48
49
|
*/
|
|
49
50
|
mentions?: string[];
|
|
50
51
|
/**
|
|
@@ -49,6 +49,11 @@ export declare class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
49
49
|
private getAJVValidateFunction;
|
|
50
50
|
private static requireValidJsonSchema;
|
|
51
51
|
private applyImprovementsOnErrorMessages;
|
|
52
|
+
private getErrorMessageForInstancePath;
|
|
53
|
+
private traverseSchemaPath;
|
|
54
|
+
private getChildSchema;
|
|
55
|
+
private getArrayItemSchema;
|
|
56
|
+
private getObjectPropertySchema;
|
|
52
57
|
}
|
|
53
58
|
export declare const HIDDEN_AJV_SCHEMA: unique symbol;
|
|
54
59
|
export type WithCachedAjvSchema<Base, IN, OUT> = Base & {
|
|
@@ -162,12 +162,56 @@ export class AjvSchema {
|
|
|
162
162
|
return;
|
|
163
163
|
const { errorMessages } = this.schema;
|
|
164
164
|
for (const error of errors) {
|
|
165
|
-
|
|
165
|
+
const errorMessage = this.getErrorMessageForInstancePath(this.schema, error.instancePath, error.keyword);
|
|
166
|
+
if (errorMessage) {
|
|
167
|
+
error.message = errorMessage;
|
|
168
|
+
}
|
|
169
|
+
else if (errorMessages?.[error.keyword]) {
|
|
166
170
|
error.message = errorMessages[error.keyword];
|
|
167
171
|
}
|
|
168
172
|
error.instancePath = error.instancePath.replaceAll(/\/(\d+)/g, `[$1]`).replaceAll('/', '.');
|
|
169
173
|
}
|
|
170
174
|
}
|
|
175
|
+
getErrorMessageForInstancePath(schema, instancePath, keyword) {
|
|
176
|
+
if (!schema || !instancePath)
|
|
177
|
+
return undefined;
|
|
178
|
+
const segments = instancePath.split('/').filter(Boolean);
|
|
179
|
+
return this.traverseSchemaPath(schema, segments, keyword);
|
|
180
|
+
}
|
|
181
|
+
traverseSchemaPath(schema, segments, keyword) {
|
|
182
|
+
if (!segments.length)
|
|
183
|
+
return undefined;
|
|
184
|
+
const [currentSegment, ...remainingSegments] = segments;
|
|
185
|
+
const nextSchema = this.getChildSchema(schema, currentSegment);
|
|
186
|
+
if (!nextSchema)
|
|
187
|
+
return undefined;
|
|
188
|
+
if (nextSchema.errorMessages?.[keyword]) {
|
|
189
|
+
return nextSchema.errorMessages[keyword];
|
|
190
|
+
}
|
|
191
|
+
if (remainingSegments.length) {
|
|
192
|
+
return this.traverseSchemaPath(nextSchema, remainingSegments, keyword);
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
getChildSchema(schema, segment) {
|
|
197
|
+
if (!segment)
|
|
198
|
+
return undefined;
|
|
199
|
+
if (/^\d+$/.test(segment) && schema.items) {
|
|
200
|
+
return this.getArrayItemSchema(schema, segment);
|
|
201
|
+
}
|
|
202
|
+
return this.getObjectPropertySchema(schema, segment);
|
|
203
|
+
}
|
|
204
|
+
getArrayItemSchema(schema, indexSegment) {
|
|
205
|
+
if (!schema.items)
|
|
206
|
+
return undefined;
|
|
207
|
+
if (Array.isArray(schema.items)) {
|
|
208
|
+
return schema.items[Number(indexSegment)];
|
|
209
|
+
}
|
|
210
|
+
return schema.items;
|
|
211
|
+
}
|
|
212
|
+
getObjectPropertySchema(schema, segment) {
|
|
213
|
+
return schema.properties?.[segment];
|
|
214
|
+
}
|
|
171
215
|
}
|
|
172
216
|
const separator = '\n';
|
|
173
217
|
export const HIDDEN_AJV_SCHEMA = Symbol('HIDDEN_AJV_SCHEMA');
|
package/package.json
CHANGED
|
@@ -51,9 +51,10 @@ export interface SlackMessage<CTX = any> extends SlackMessageProps {
|
|
|
51
51
|
kv?: AnyObject
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Slack
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
* Slack IDs to mention at the end of the message.
|
|
55
|
+
* Supports:
|
|
56
|
+
* - User IDs (e.g., 'U1234567890') - click profile → "..." → "Copy member ID"
|
|
57
|
+
* - User Group IDs (e.g., 'S1234567890') - from user group settings
|
|
57
58
|
*/
|
|
58
59
|
mentions?: string[]
|
|
59
60
|
|
|
@@ -109,7 +109,7 @@ export class SlackService<CTX = any> {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
if (msg.mentions?.length) {
|
|
112
|
-
text += '\n' + msg.mentions.map(
|
|
112
|
+
text += '\n' + msg.mentions.map(formatSlackMention).join(' ')
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
const prefix = await messagePrefixHook(msg)
|
|
@@ -191,3 +191,13 @@ export function slackDefaultMessagePrefixHook(msg: SlackMessage): string[] {
|
|
|
191
191
|
|
|
192
192
|
return tokens.filter(Boolean)
|
|
193
193
|
}
|
|
194
|
+
|
|
195
|
+
// Formats a Slack mention based on the ID type:
|
|
196
|
+
// - User IDs (U...) and Bot IDs (B...) use: <@ID>
|
|
197
|
+
// - User Group IDs (S...) use: <!subteam^ID>
|
|
198
|
+
function formatSlackMention(id: string): string {
|
|
199
|
+
if (id.startsWith('S')) {
|
|
200
|
+
return `<!subteam^${id}>`
|
|
201
|
+
}
|
|
202
|
+
return `<@${id}>`
|
|
203
|
+
}
|
|
@@ -229,13 +229,78 @@ export class AjvSchema<IN = unknown, OUT = IN> {
|
|
|
229
229
|
const { errorMessages } = this.schema
|
|
230
230
|
|
|
231
231
|
for (const error of errors) {
|
|
232
|
-
|
|
232
|
+
const errorMessage = this.getErrorMessageForInstancePath(
|
|
233
|
+
this.schema,
|
|
234
|
+
error.instancePath,
|
|
235
|
+
error.keyword,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
if (errorMessage) {
|
|
239
|
+
error.message = errorMessage
|
|
240
|
+
} else if (errorMessages?.[error.keyword]) {
|
|
233
241
|
error.message = errorMessages[error.keyword]
|
|
234
242
|
}
|
|
235
243
|
|
|
236
244
|
error.instancePath = error.instancePath.replaceAll(/\/(\d+)/g, `[$1]`).replaceAll('/', '.')
|
|
237
245
|
}
|
|
238
246
|
}
|
|
247
|
+
|
|
248
|
+
private getErrorMessageForInstancePath(
|
|
249
|
+
schema: JsonSchema<IN, OUT> | undefined,
|
|
250
|
+
instancePath: string,
|
|
251
|
+
keyword: string,
|
|
252
|
+
): string | undefined {
|
|
253
|
+
if (!schema || !instancePath) return undefined
|
|
254
|
+
|
|
255
|
+
const segments = instancePath.split('/').filter(Boolean)
|
|
256
|
+
return this.traverseSchemaPath(schema, segments, keyword)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private traverseSchemaPath<IN = unknown, OUT = IN>(
|
|
260
|
+
schema: JsonSchema<IN, OUT>,
|
|
261
|
+
segments: string[],
|
|
262
|
+
keyword: string,
|
|
263
|
+
): string | undefined {
|
|
264
|
+
if (!segments.length) return undefined
|
|
265
|
+
|
|
266
|
+
const [currentSegment, ...remainingSegments] = segments
|
|
267
|
+
|
|
268
|
+
const nextSchema = this.getChildSchema(schema, currentSegment)
|
|
269
|
+
if (!nextSchema) return undefined
|
|
270
|
+
|
|
271
|
+
if (nextSchema.errorMessages?.[keyword]) {
|
|
272
|
+
return nextSchema.errorMessages[keyword]
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (remainingSegments.length) {
|
|
276
|
+
return this.traverseSchemaPath(nextSchema, remainingSegments, keyword)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return undefined
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private getChildSchema(schema: JsonSchema, segment: string | undefined): JsonSchema | undefined {
|
|
283
|
+
if (!segment) return undefined
|
|
284
|
+
if (/^\d+$/.test(segment) && schema.items) {
|
|
285
|
+
return this.getArrayItemSchema(schema, segment)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return this.getObjectPropertySchema(schema, segment)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private getArrayItemSchema(schema: JsonSchema, indexSegment: string): JsonSchema | undefined {
|
|
292
|
+
if (!schema.items) return undefined
|
|
293
|
+
|
|
294
|
+
if (Array.isArray(schema.items)) {
|
|
295
|
+
return schema.items[Number(indexSegment)]
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return schema.items
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
private getObjectPropertySchema(schema: JsonSchema, segment: string): JsonSchema | undefined {
|
|
302
|
+
return schema.properties?.[segment as keyof typeof schema.properties]
|
|
303
|
+
}
|
|
239
304
|
}
|
|
240
305
|
|
|
241
306
|
const separator = '\n'
|