pinokiod 7.0.2 → 7.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "7.0.2",
3
+ "version": "7.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -112,8 +112,43 @@ module.exports = function registerAppRoutes(app, { registry, preferences, appSea
112
112
  }
113
113
  return `${normalizedAppId}@${host}`
114
114
  }
115
- const decorateSearchResult = (appResult, source) => {
115
+ const neutralizeRemoteSearchPreferences = (appResult) => {
116
116
  const next = appResult && typeof appResult === 'object' ? { ...appResult } : {}
117
+ next.starred = false
118
+ next.starred_at = null
119
+ next.last_launch_at = null
120
+ next.last_launch_source = 'unknown'
121
+ next.launch_count_total = 0
122
+ next.launch_count_pterm = 0
123
+ next.launch_count_ui = 0
124
+ next.preference_boost = 0
125
+ if (typeof next.score === 'number') {
126
+ next.adjusted_score = next.score
127
+ } else {
128
+ next.adjusted_score = null
129
+ }
130
+ return next
131
+ }
132
+ const runtimeRank = (appResult) => {
133
+ if (appResult && appResult.ready) {
134
+ return 2
135
+ }
136
+ if (appResult && appResult.running) {
137
+ return 1
138
+ }
139
+ return 0
140
+ }
141
+ const parseTimestamp = (value) => {
142
+ if (typeof value !== 'string' || !value.trim()) {
143
+ return 0
144
+ }
145
+ const parsed = Date.parse(value)
146
+ return Number.isFinite(parsed) ? parsed : 0
147
+ }
148
+ const decorateSearchResult = (appResult, source) => {
149
+ const next = source && !source.local
150
+ ? neutralizeRemoteSearchPreferences(appResult)
151
+ : (appResult && typeof appResult === 'object' ? { ...appResult } : {})
117
152
  next.app_id = qualifyAppId(next.app_id || next.name || '', source.host)
118
153
  next.source = source
119
154
  if (!source.local) {
@@ -171,11 +206,31 @@ module.exports = function registerAppRoutes(app, { registry, preferences, appSea
171
206
  }
172
207
  push(localApps)
173
208
  push(remoteApps)
174
- const normalizedQuery = typeof query === 'string' ? query.trim() : ''
175
- if (!normalizedQuery) {
176
- return merged
177
- }
178
209
  return merged.sort((a, b) => {
210
+ const aRuntimeRank = runtimeRank(a)
211
+ const bRuntimeRank = runtimeRank(b)
212
+ if (aRuntimeRank !== bRuntimeRank) {
213
+ return bRuntimeRank - aRuntimeRank
214
+ }
215
+ const normalizedQuery = typeof query === 'string' ? query.trim() : ''
216
+ if (!normalizedQuery) {
217
+ const aStarred = a && a.starred ? 1 : 0
218
+ const bStarred = b && b.starred ? 1 : 0
219
+ if (aStarred !== bStarred) {
220
+ return bStarred - aStarred
221
+ }
222
+ const aLaunchCount = Math.max(0, Number.parseInt(String(a && a.launch_count_total || 0), 10) || 0)
223
+ const bLaunchCount = Math.max(0, Number.parseInt(String(b && b.launch_count_total || 0), 10) || 0)
224
+ if (aLaunchCount !== bLaunchCount) {
225
+ return bLaunchCount - aLaunchCount
226
+ }
227
+ const aLastLaunch = parseTimestamp(a && a.last_launch_at)
228
+ const bLastLaunch = parseTimestamp(b && b.last_launch_at)
229
+ if (aLastLaunch !== bLastLaunch) {
230
+ return bLastLaunch - aLastLaunch
231
+ }
232
+ return String(a.app_id || '').localeCompare(String(b.app_id || ''))
233
+ }
179
234
  const aAdjusted = typeof a.adjusted_score === 'number' ? a.adjusted_score : -Infinity
180
235
  const bAdjusted = typeof b.adjusted_score === 'number' ? b.adjusted_score : -Infinity
181
236
  if (aAdjusted !== bAdjusted) {
@@ -259,6 +314,11 @@ module.exports = function registerAppRoutes(app, { registry, preferences, appSea
259
314
  res.status(400).json({ error: 'Invalid app_id' })
260
315
  return
261
316
  }
317
+ const parsedAppId = parseQualifiedAppId(appId)
318
+ if (parsedAppId.qualified && parsedAppId.host !== currentPeerHost()) {
319
+ res.status(400).json({ error: 'Remote app preferences are not supported' })
320
+ return
321
+ }
262
322
  const body = req.body && typeof req.body === 'object' ? req.body : {}
263
323
  const hasStarred = Object.prototype.hasOwnProperty.call(body, 'starred')
264
324
  if (!hasStarred) {