Skip to content

Commit e7b1cf1

Browse files
committed
feat: add isSecurityHeld flag (algolia#657)
1 parent 011a174 commit e7b1cf1

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ For every single NPM package, we create a record in the Algolia index. The resul
105105
deprecated: 'Deprecated', // This field will be removed, please use `isDeprecated` instead
106106
isDeprecated: true,
107107
deprecatedReason: 'Deprecated',
108+
isSecurityHeld: false, // See https://github.com/npm/security-holder
108109
badPackage: false,
109110
homepage: 'https://babeljs.io/',
110111
license: 'MIT',

src/@types/pkg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface RawPkg {
6464
deprecated: boolean | string;
6565
isDeprecated: boolean;
6666
deprecatedReason: string | null;
67+
isSecurityHeld: boolean;
6768
homepage: string | null;
6869
license: string | null;
6970
keywords: string[];

src/__tests__/__snapshots__/formatPkg.test.ts.snap

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Object {
3131
"homepage": null,
3232
"humanDownloadsLast30Days": "0",
3333
"isDeprecated": true,
34+
"isSecurityHeld": false,
3435
"keywords": Array [],
3536
"lastCrawl": Any<String>,
3637
"lastPublisher": null,
@@ -111,6 +112,7 @@ Object {
111112
"homepage": "https://bitbucket.org/atlassian/atlaskit#readme",
112113
"humanDownloadsLast30Days": "0",
113114
"isDeprecated": false,
115+
"isSecurityHeld": false,
114116
"keywords": Array [
115117
"atlaskit",
116118
"ui",
@@ -337,6 +339,7 @@ Object {
337339
"homepage": null,
338340
"humanDownloadsLast30Days": "0",
339341
"isDeprecated": false,
342+
"isSecurityHeld": false,
340343
"keywords": Array [],
341344
"lastCrawl": Any<String>,
342345
"lastPublisher": Object {
@@ -467,6 +470,7 @@ Object {
467470
"homepage": null,
468471
"humanDownloadsLast30Days": "0",
469472
"isDeprecated": false,
473+
"isSecurityHeld": false,
470474
"keywords": Array [
471475
"algolia",
472476
"instantsearch",
@@ -557,6 +561,7 @@ Object {
557561
"homepage": null,
558562
"humanDownloadsLast30Days": "0",
559563
"isDeprecated": false,
564+
"isSecurityHeld": false,
560565
"keywords": Array [
561566
"index",
562567
"array",
@@ -667,6 +672,7 @@ Object {
667672
"homepage": null,
668673
"humanDownloadsLast30Days": "0",
669674
"isDeprecated": false,
675+
"isSecurityHeld": false,
670676
"keywords": Array [
671677
"prism",
672678
"highlight",
@@ -858,6 +864,7 @@ Object {
858864
"homepage": null,
859865
"humanDownloadsLast30Days": "0",
860866
"isDeprecated": false,
867+
"isSecurityHeld": false,
861868
"keywords": Array [],
862869
"lastCrawl": Any<String>,
863870
"lastPublisher": null,
@@ -1537,3 +1544,76 @@ QE+S
15371544
],
15381545
}
15391546
`;
1547+
1548+
exports[`security held log security held flag 1`] = `
1549+
Object {
1550+
"_searchInternal": Object {
1551+
"alternativeNames": Array [
1552+
"0",
1553+
"0.js",
1554+
"0js",
1555+
],
1556+
"expiresAt": Any<Number>,
1557+
},
1558+
"bin": Object {},
1559+
"computedKeywords": Array [],
1560+
"computedMetadata": Object {},
1561+
"created": NaN,
1562+
"dependencies": Object {},
1563+
"deprecated": false,
1564+
"deprecatedReason": null,
1565+
"description": null,
1566+
"devDependencies": Object {},
1567+
"downloadsLast30Days": 0,
1568+
"downloadsRatio": 0,
1569+
"gitHead": null,
1570+
"githubRepo": null,
1571+
"homepage": null,
1572+
"humanDownloadsLast30Days": "0",
1573+
"isDeprecated": false,
1574+
"isSecurityHeld": true,
1575+
"keywords": Array [],
1576+
"lastCrawl": Any<String>,
1577+
"lastPublisher": null,
1578+
"license": null,
1579+
"modified": NaN,
1580+
"moduleTypes": Array [
1581+
"unknown",
1582+
],
1583+
"name": "0",
1584+
"objectID": "0",
1585+
"originalAuthor": Object {
1586+
"name": "npm",
1587+
},
1588+
"owner": Object {
1589+
"avatar": "https://github.com/npm.png",
1590+
"link": "https://github.com/npm",
1591+
"name": "npm",
1592+
},
1593+
"owners": Array [],
1594+
"popular": false,
1595+
"readme": "",
1596+
"repository": Object {
1597+
"branch": "master",
1598+
"head": undefined,
1599+
"host": "github.com",
1600+
"path": "",
1601+
"project": "security-holder",
1602+
"type": "git",
1603+
"url": "npm/security-holder",
1604+
"user": "npm",
1605+
},
1606+
"rev": Any<String>,
1607+
"styleTypes": Array [],
1608+
"tags": Object {
1609+
"latest": "1.2.3",
1610+
},
1611+
"types": Object {
1612+
"ts": Object {
1613+
"possible": true,
1614+
},
1615+
},
1616+
"version": "0.0.0",
1617+
"versions": Object {},
1618+
}
1619+
`;

src/__tests__/formatPkg.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getVersions,
99
getExportKeys,
1010
} from '../formatPkg';
11-
import type { GetPackage } from '../npm/types';
11+
import type { GetPackage, PackageRepo } from '../npm/types';
1212

1313
import preact from './preact-simplified.json';
1414
import rawPackages from './rawPackages.json';
@@ -859,3 +859,31 @@ describe('deprecated', () => {
859859
});
860860
});
861861
});
862+
863+
describe('security held', () => {
864+
it('log security held flag', () => {
865+
const pkg: GetPackage = {
866+
...BASE,
867+
'dist-tags': {
868+
latest: '1.2.3',
869+
},
870+
versions: {
871+
'1.2.3': {
872+
...BASE_VERSION,
873+
},
874+
},
875+
repository: 'npm/security-holder' as unknown as PackageRepo,
876+
author: { name: 'npm' },
877+
};
878+
const formatted = formatPkg(pkg);
879+
880+
expect(formatted).toMatchSnapshot({
881+
rev: expect.any(String),
882+
lastCrawl: expect.any(String),
883+
isSecurityHeld: true,
884+
_searchInternal: {
885+
expiresAt: expect.any(Number),
886+
},
887+
});
888+
});
889+
});

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const indexSettings: Settings = {
1818
'_searchInternal.expiresAt',
1919
'deprecated',
2020
'isDeprecated',
21+
'isSecurityHeld',
2122
'types.ts',
2223
'moduleTypes',
2324
'styleTypes',
@@ -38,6 +39,7 @@ const indexSettings: Settings = {
3839
'words',
3940
'proximity',
4041
'attribute',
42+
'asc(isSecurityHeld)',
4143
'asc(deprecated)',
4244
'asc(isDeprecated)',
4345
'asc(badPackage)',

src/formatPkg.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export function formatPkg(pkg: GetPackage): RawPkg | undefined {
146146
const tags = pkg['dist-tags'];
147147
const isDeprecated =
148148
cleaned.deprecated !== undefined && cleaned.deprecated !== false;
149+
const isSecurityHeld =
150+
repository?.user === 'npm' && repository?.project === 'security-holder';
149151

150152
const rawPkg: RawPkg = {
151153
objectID: cleaned.name,
@@ -170,6 +172,7 @@ export function formatPkg(pkg: GetPackage): RawPkg | undefined {
170172
deprecated: isDeprecated ? cleaned.deprecated! : false,
171173
isDeprecated,
172174
deprecatedReason: isDeprecated ? String(cleaned.deprecated) : null,
175+
isSecurityHeld,
173176
homepage: getHomePage(cleaned),
174177
license,
175178
keywords,

0 commit comments

Comments
 (0)