@goodandready/dsh-model-sync 0.5.14 → 0.5.15
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/lib/diff-notifier.js +15 -2
- package/lib/http.js +14 -2
- package/lib/synchronizer-helpers.js +12 -0
- package/lib/updater.js +13 -1
- package/package.json +1 -1
package/lib/diff-notifier.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
function getOptionalService(ctx, name) {
|
|
2
|
+
try {
|
|
3
|
+
return ctx?.[name] ?? ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
4
|
+
} catch {
|
|
5
|
+
try {
|
|
6
|
+
return ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
7
|
+
} catch {
|
|
8
|
+
return undefined
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
import { createHmac } from "node:crypto"
|
|
2
14
|
|
|
3
15
|
export function extractDiffEvents(results, options = {}) {
|
|
@@ -220,9 +232,10 @@ export async function dispatchDiffNotifications(ctx, config, results, { fetchImp
|
|
|
220
232
|
}
|
|
221
233
|
|
|
222
234
|
try {
|
|
223
|
-
|
|
235
|
+
const pluginNotify = getOptionalService(ctx, 'pluginNotify')
|
|
236
|
+
if (typeof pluginNotify?.send === "function") {
|
|
224
237
|
const summary = `Model Sync: +${events.counts.added} added, -${events.counts.deprecated} deprecated, ~${events.counts.priceChanged} price changed`
|
|
225
|
-
await
|
|
238
|
+
await pluginNotify.send({
|
|
226
239
|
source: "dsh-model-sync",
|
|
227
240
|
title: "Model Sync Catalog Changes",
|
|
228
241
|
message: summary,
|
package/lib/http.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
function getOptionalService(ctx, name) {
|
|
2
|
+
try {
|
|
3
|
+
return ctx?.[name] ?? ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
4
|
+
} catch {
|
|
5
|
+
try {
|
|
6
|
+
return ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
7
|
+
} catch {
|
|
8
|
+
return undefined
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
import { isForbiddenWebhookHost, isLoopbackHost } from './diff-notifier.js'
|
|
2
14
|
import crypto from 'node:crypto'
|
|
3
15
|
import { validateAliasName } from './alias-resolver.js'
|
|
@@ -43,7 +55,7 @@ export function isLoopbackAddress(ip) {
|
|
|
43
55
|
|
|
44
56
|
export function trusted(req, { requireLoopback = false, ctx = null } = {}) {
|
|
45
57
|
// 1. Core connection rejection check (#237)
|
|
46
|
-
const conn = ctx
|
|
58
|
+
const conn = getOptionalService(ctx, 'connection') || req?.connection
|
|
47
59
|
if (conn && typeof conn.requestRejection === 'function') {
|
|
48
60
|
const rejection = conn.requestRejection(req)
|
|
49
61
|
if (rejection !== undefined) return false
|
|
@@ -274,7 +286,7 @@ export function registerHttpApi(ctx, synchronizer, { getSchedulerStatus = () =>
|
|
|
274
286
|
const makeHandler = (route) => async (req, res) => {
|
|
275
287
|
try {
|
|
276
288
|
// 1. Core connection check on all routes (#237)
|
|
277
|
-
const conn = ctx
|
|
289
|
+
const conn = getOptionalService(ctx, 'connection') || req?.connection
|
|
278
290
|
if (conn && typeof conn.requestRejection === 'function') {
|
|
279
291
|
const rejection = conn.requestRejection(req)
|
|
280
292
|
if (rejection !== undefined) {
|
|
@@ -38,6 +38,18 @@ export function reliabilityOptions(config, options) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
export function getOptionalService(ctx, name) {
|
|
42
|
+
try {
|
|
43
|
+
return ctx?.[name] ?? ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
44
|
+
} catch {
|
|
45
|
+
try {
|
|
46
|
+
return ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
47
|
+
} catch {
|
|
48
|
+
return undefined
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
export function settingsOf(ctx) {
|
|
42
54
|
try {
|
|
43
55
|
return ctx?.settings ?? ctx?.reflect?.get?.('settings') ?? (typeof ctx?.get === 'function' ? ctx.get('settings') : undefined)
|
package/lib/updater.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
function getOptionalService(ctx, name) {
|
|
2
|
+
try {
|
|
3
|
+
return ctx?.[name] ?? ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
4
|
+
} catch {
|
|
5
|
+
try {
|
|
6
|
+
return ctx?.reflect?.get?.(name) ?? (typeof ctx?.get === 'function' ? ctx.get(name) : undefined)
|
|
7
|
+
} catch {
|
|
8
|
+
return undefined
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
import { spawn } from 'node:child_process'
|
|
2
14
|
import { existsSync, readFileSync } from 'node:fs'
|
|
3
15
|
import { readFile } from 'node:fs/promises'
|
|
@@ -315,7 +327,7 @@ export function registerPluginUpdater(ctx, options = {}) {
|
|
|
315
327
|
const handler = async (request, response) => {
|
|
316
328
|
try {
|
|
317
329
|
// 1. Core connection rejection check on all updater routes (#237)
|
|
318
|
-
const conn = ctx
|
|
330
|
+
const conn = getOptionalService(ctx, 'connection') || request?.connection
|
|
319
331
|
if (conn && typeof conn.requestRejection === 'function') {
|
|
320
332
|
const rejection = conn.requestRejection(request)
|
|
321
333
|
if (rejection !== undefined) {
|