@verdaccio/api 6.0.0-6-next.59 → 7.0.0-next-7.8

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 CHANGED
@@ -1,5 +1,538 @@
1
1
  # @verdaccio/api
2
2
 
3
+ ## 7.0.0-next-7.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 74cd588: fix: bug on change password npm profile
8
+ - @verdaccio/core@7.0.0-next-7.8
9
+ - @verdaccio/config@7.0.0-next-7.8
10
+ - @verdaccio/auth@7.0.0-next-7.8
11
+ - @verdaccio/middleware@7.0.0-next-7.8
12
+ - @verdaccio/store@7.0.0-next-7.8
13
+ - @verdaccio/utils@7.0.0-next-7.8
14
+ - @verdaccio/logger@7.0.0-next-7.8
15
+
16
+ ## 7.0.0-next-7.7
17
+
18
+ ### Patch Changes
19
+
20
+ - @verdaccio/core@7.0.0-next-7.7
21
+ - @verdaccio/config@7.0.0-next-7.7
22
+ - @verdaccio/auth@7.0.0-next-7.7
23
+ - @verdaccio/middleware@7.0.0-next-7.7
24
+ - @verdaccio/store@7.0.0-next-7.7
25
+ - @verdaccio/utils@7.0.0-next-7.7
26
+ - @verdaccio/logger@7.0.0-next-7.7
27
+
28
+ ## 7.0.0-next.6
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [e14b064]
33
+ - Updated dependencies [4d96324]
34
+ - @verdaccio/store@7.0.0-next.6
35
+ - @verdaccio/config@7.0.0-next.6
36
+ - @verdaccio/auth@7.0.0-next.6
37
+ - @verdaccio/middleware@7.0.0-next.6
38
+ - @verdaccio/core@7.0.0-next.6
39
+ - @verdaccio/utils@7.0.0-next.6
40
+ - @verdaccio/logger@7.0.0-next.6
41
+
42
+ ## 7.0.0-next.5
43
+
44
+ ### Minor Changes
45
+
46
+ - f047cc8: refactor: auth with legacy sign support
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [f047cc8]
51
+ - @verdaccio/middleware@7.0.0-next.5
52
+ - @verdaccio/core@7.0.0-next.5
53
+ - @verdaccio/config@7.0.0-next.5
54
+ - @verdaccio/auth@7.0.0-next.5
55
+ - @verdaccio/store@7.0.0-next.5
56
+ - @verdaccio/logger@7.0.0-next.5
57
+ - @verdaccio/utils@7.0.0-next.5
58
+
59
+ ## 7.0.0-next.4
60
+
61
+ ### Patch Changes
62
+
63
+ - @verdaccio/auth@7.0.0-next.4
64
+ - @verdaccio/core@7.0.0-next.4
65
+ - @verdaccio/config@7.0.0-next.4
66
+ - @verdaccio/middleware@7.0.0-next.4
67
+ - @verdaccio/store@7.0.0-next.4
68
+ - @verdaccio/utils@7.0.0-next.4
69
+ - @verdaccio/logger@7.0.0-next.4
70
+
71
+ ## 7.0.0-next.3
72
+
73
+ ### Major Changes
74
+
75
+ - e7ebccb61: update major dependencies, remove old nodejs support
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies [daceb6d87]
80
+ - Updated dependencies [e7ebccb61]
81
+ - @verdaccio/config@7.0.0-next.3
82
+ - @verdaccio/core@7.0.0-next.3
83
+ - @verdaccio/middleware@7.0.0-next.3
84
+ - @verdaccio/utils@7.0.0-next.3
85
+ - @verdaccio/auth@7.0.0-next.3
86
+ - @verdaccio/logger@7.0.0-next.3
87
+ - @verdaccio/store@7.0.0-next.3
88
+
89
+ ## 7.0.0-next.2
90
+
91
+ ### Patch Changes
92
+
93
+ - @verdaccio/core@7.0.0-next.2
94
+ - @verdaccio/config@7.0.0-next.2
95
+ - @verdaccio/auth@7.0.0-next.2
96
+ - @verdaccio/middleware@7.0.0-next.2
97
+ - @verdaccio/store@7.0.0-next.2
98
+ - @verdaccio/utils@7.0.0-next.2
99
+ - @verdaccio/logger@7.0.0-next.2
100
+
101
+ ## 7.0.0-next.1
102
+
103
+ ### Patch Changes
104
+
105
+ - @verdaccio/core@7.0.0-next.1
106
+ - @verdaccio/config@7.0.0-next.1
107
+ - @verdaccio/auth@7.0.0-next.1
108
+ - @verdaccio/middleware@7.0.0-next.1
109
+ - @verdaccio/store@7.0.0-next.1
110
+ - @verdaccio/utils@7.0.0-next.1
111
+ - @verdaccio/logger@7.0.0-next.1
112
+
113
+ ## 7.0.0-next.0
114
+
115
+ ### Major Changes
116
+
117
+ - feat!: bump to v7
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies
122
+ - @verdaccio/auth@7.0.0-next.0
123
+ - @verdaccio/config@7.0.0-next.0
124
+ - @verdaccio/core@7.0.0-next.0
125
+ - @verdaccio/logger@7.0.0-next.0
126
+ - @verdaccio/middleware@7.0.0-next.0
127
+ - @verdaccio/store@7.0.0-next.0
128
+ - @verdaccio/utils@7.0.0-next.0
129
+
130
+ ## 6.0.0
131
+
132
+ ### Major Changes
133
+
134
+ - 292c0a37f: feat!: replace deprecated request dependency by got
135
+
136
+ This is a big refactoring of the core, fetching dependencies, improve code, more tests and better stability. This is essential for the next release, will take some time but would allow modularize more the core.
137
+
138
+ ## Notes
139
+
140
+ - Remove deprecated `request` by other `got`, retry improved, custom Agent ( got does not include it built-in)
141
+ - Remove `async` dependency from storage (used by core) it was linked with proxy somehow safe to remove now
142
+ - Refactor with promises instead callback wherever is possible
143
+ - ~Document the API~
144
+ - Improve testing, integration tests
145
+ - Bugfix
146
+ - Clean up old validations
147
+ - Improve performance
148
+
149
+ ## 💥 Breaking changes
150
+
151
+ - Plugin API methods were callbacks based are returning promises, this will break current storage plugins, check documentation for upgrade.
152
+ - Write Tarball, Read Tarball methods parameters change, a new set of options like `AbortController` signals are being provided to the `addAbortSignal` can be internally used with Streams when a request is aborted. eg: `addAbortSignal(signal, fs.createReadStream(pathName));`
153
+ - `@verdaccio/streams` stream abort support is legacy is being deprecated removed
154
+ - Remove AWS and Google Cloud packages for future refactoring [#2574](https://github.com/verdaccio/verdaccio/pull/2574).
155
+
156
+ - a828271d6: refactor: download manifest endpoint and integrate fastify
157
+
158
+ Much simpler API for fetching a package
159
+
160
+ ```
161
+ const manifest = await storage.getPackageNext({
162
+ name,
163
+ uplinksLook: true,
164
+ req,
165
+ version: queryVersion,
166
+ requestOptions,
167
+ });
168
+ ```
169
+
170
+ > not perfect, the `req` still is being passed to the proxy (this has to be refactored at proxy package) and then removed from here, in proxy we pass the request instance to the `request` library.
171
+
172
+ ### Details
173
+
174
+ - `async/await` sugar for getPackage()
175
+ - Improve and reuse code between current implementation and new fastify endpoint (add scaffolding for request manifest)
176
+ - Improve performance
177
+ - Add new tests
178
+
179
+ ### Breaking changes
180
+
181
+ All storage plugins will stop to work since the storage uses `getPackageNext` method which is Promise based, I won't replace this now because will force me to update all plugins, I'll follow up in another PR. Currently will throw http 500
182
+
183
+ - 459b6fa72: refactor: search v1 endpoint and local-database
184
+
185
+ - refactor search `api v1` endpoint, improve performance
186
+ - remove usage of `async` dependency https://github.com/verdaccio/verdaccio/issues/1225
187
+ - refactor method storage class
188
+ - create new module `core` to reduce the ammount of modules with utilities
189
+ - use `undici` instead `node-fetch`
190
+ - use `fastify` instead `express` for functional test
191
+
192
+ ### Breaking changes
193
+
194
+ - plugin storage API changes
195
+ - remove old search endpoint (return 404)
196
+ - filter local private packages at plugin level
197
+
198
+ The storage api changes for methods `get`, `add`, `remove` as promise base. The `search` methods also changes and recieves a `query` object that contains all query params from the client.
199
+
200
+ ```ts
201
+ export interface IPluginStorage<T> extends IPlugin {
202
+ add(name: string): Promise<void>;
203
+ remove(name: string): Promise<void>;
204
+ get(): Promise<any>;
205
+ init(): Promise<void>;
206
+ getSecret(): Promise<string>;
207
+ setSecret(secret: string): Promise<any>;
208
+ getPackageStorage(packageInfo: string): IPackageStorage;
209
+ search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;
210
+ saveToken(token: Token): Promise<any>;
211
+ deleteToken(user: string, tokenKey: string): Promise<any>;
212
+ readTokens(filter: TokenFilter): Promise<Token[]>;
213
+ }
214
+ ```
215
+
216
+ - 9fc2e7961: feat(plugins): improve plugin loader
217
+
218
+ ### Changes
219
+
220
+ - Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
221
+ - Avoid config collisions https://github.com/verdaccio/verdaccio/issues/928
222
+ - https://github.com/verdaccio/verdaccio/issues/1394
223
+ - `config.plugins` plugin path validations
224
+ - Updated algorithm for plugin loader.
225
+ - improved documentation (included dev)
226
+
227
+ ## Features
228
+
229
+ - Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
230
+ - Custom prefix:
231
+
232
+ ```
233
+ // config.yaml
234
+ server:
235
+ pluginPrefix: mycompany
236
+ middleware:
237
+ audit:
238
+ foo: 1
239
+ ```
240
+
241
+ This configuration will look up for `mycompany-audit` instead `Verdaccio-audit`.
242
+
243
+ ## Breaking Changes
244
+
245
+ ### sinopia plugins
246
+
247
+ - `sinopia` fallback support is removed, but can be restored using `pluginPrefix`
248
+
249
+ ### plugin filter
250
+
251
+ - method rename `filter_metadata`->`filterMetadata`
252
+
253
+ ### Plugin constructor does not merge configs anymore https://github.com/verdaccio/verdaccio/issues/928
254
+
255
+ The plugin receives as first argument `config`, which represents the config of the plugin. Example:
256
+
257
+ ```
258
+ // config.yaml
259
+ auth:
260
+ plugin:
261
+ foo: 1
262
+ bar: 2
263
+
264
+ export class Plugin<T> {
265
+ public constructor(config: T, options: PluginOptions) {
266
+ console.log(config);
267
+ // {foo:1, bar: 2}
268
+ }
269
+ }
270
+ ```
271
+
272
+ - 794af76c5: Remove Node 12 support
273
+
274
+ - We need move to the new `undici` and does not support Node.js 12
275
+
276
+ - 10aeb4f13: feat!: experiments config renamed to flags
277
+
278
+ - The `experiments` configuration is renamed to `flags`. The functionality is exactly the same.
279
+
280
+ ```js
281
+ flags: token: false;
282
+ search: false;
283
+ ```
284
+
285
+ - The `self_path` property from the config file is being removed in favor of `config_file` full path.
286
+ - Refactor `config` module, better types and utilities
287
+
288
+ - e367c3f1e: - Replace signature handler for legacy tokens by removing deprecated crypto.createDecipher by createCipheriv
289
+
290
+ - Introduce environment variables for legacy tokens
291
+
292
+ ### Code Improvements
293
+
294
+ - Add debug library for improve developer experience
295
+
296
+ ### Breaking change
297
+
298
+ - The new signature invalidates all previous tokens generated by Verdaccio 4 or previous versions.
299
+ - The secret key must have 32 characters long.
300
+
301
+ ### New environment variables
302
+
303
+ - `VERDACCIO_LEGACY_ALGORITHM`: Allows to define the specific algorithm for the token signature which by default is `aes-256-ctr`
304
+ - `VERDACCIO_LEGACY_ENCRYPTION_KEY`: By default, the token stores in the database, but using this variable allows to get it from memory
305
+
306
+ - 82cb0f2bf: feat!: config.logs throw an error, logging config not longer accept array or logs property
307
+
308
+ ### 💥 Breaking change
309
+
310
+ This is valid
311
+
312
+ ```yaml
313
+ log: { type: stdout, format: pretty, level: http }
314
+ ```
315
+
316
+ This is invalid
317
+
318
+ ```yaml
319
+ logs: { type: stdout, format: pretty, level: http }
320
+ ```
321
+
322
+ or
323
+
324
+ ```yaml
325
+ logs:
326
+ - [{ type: stdout, format: pretty, level: http }]
327
+ ```
328
+
329
+ ### Minor Changes
330
+
331
+ - a1986e098: feat: expose middleware utils
332
+ - ef88da3b4: feat: improve support for fs promises older nodejs
333
+ - ae93e039d: fix: expose middleware methods
334
+ - 24b9be020: refactor: improve docker image build with strict dependencies and prod build
335
+ - 631abe1ac: feat: refactor logger
336
+ - b702ea363: abort search request support for proxy
337
+ - 00d1d2a17: chore: env variable for launch fastify
338
+
339
+ - Update fastify to major release `v4.3.0`
340
+ - Update CLI launcher
341
+
342
+ via CLI
343
+
344
+ ```
345
+ VERDACCIO_SERVER=fastify verdaccio
346
+ ```
347
+
348
+ with docker
349
+
350
+ ```
351
+ docker run -it --rm --name verdaccio \
352
+ -e "VERDACCIO_SERVER=8080" -p 8080:8080 \
353
+ -e "VERDACCIO_SERVER=fastify" \
354
+ verdaccio/verdaccio
355
+ ```
356
+
357
+ - e54ec4b5d: feat: remove level dependency by lowdb for npm token cli as storage
358
+
359
+ ### new npm token database
360
+
361
+ There will be a new database located in your storage named `.token-db.json` which
362
+ will store all references to created tokens, **it does not store tokens**, just
363
+ mask of them and related metadata required to reference them.
364
+
365
+ #### Breaking change
366
+
367
+ If you were relying on `npm token` experiment. This PR will replace the
368
+ used database (level) by a json plain based one (lowbd) which does not
369
+ require Node.js C++ compilation step and has less dependencies. Since was
370
+ a experiment there is no migration step.
371
+
372
+ - b61f762d6: feat: add server rate limit protection to all request
373
+
374
+ To modify custom values, use the server settings property.
375
+
376
+ ```markdown
377
+ server:
378
+
379
+ ## https://www.npmjs.com/package/express-rate-limit#configuration-options
380
+
381
+ rateLimit:
382
+ windowMs: 1000
383
+ max: 10000
384
+ ```
385
+
386
+ The values are intended to be high, if you want to improve security of your server consider
387
+ using different values.
388
+
389
+ - 154b2ecd3: refactor: remove @verdaccio/commons-api in favor @verdaccio/core and remove duplications
390
+ - aa763baec: feat: add typescript project references settings
391
+
392
+ Reading https://ebaytech.berlin/optimizing-multi-package-apps-with-typescript-project-references-d5c57a3b4440 I realized I can use project references to solve the issue to pre-compile modules on develop mode.
393
+
394
+ It allows to navigate (IDE) trough the packages without need compile the packages.
395
+
396
+ Add two `tsconfig`, one using the previous existing configuration that is able to produce declaration files (`tsconfig.build`) and a new one `tsconfig` which is enables [_projects references_](https://www.typescriptlang.org/docs/handbook/project-references.html).
397
+
398
+ - ce013d2fc: refactor: npm star command support reimplemented
399
+ - 62c24b632: feat: add passwordValidationRegex property
400
+ - 5167bb528: feat: ui search support for remote, local and private packages
401
+
402
+ The command `npm search` search globally and return all matches, with this improvement the user interface
403
+ is powered with the same capabilities.
404
+
405
+ The UI also tag where is the origin the package with a tag, also provide the latest version and description of the package.
406
+
407
+ - 4b29d715b: chore: move improvements from v5 to v6
408
+
409
+ Migrate improvements form v5 to v6:
410
+
411
+ - https://github.com/verdaccio/verdaccio/pull/3158
412
+ - https://github.com/verdaccio/verdaccio/pull/3151
413
+ - https://github.com/verdaccio/verdaccio/pull/2271
414
+ - https://github.com/verdaccio/verdaccio/pull/2787
415
+ - https://github.com/verdaccio/verdaccio/pull/2791
416
+ - https://github.com/verdaccio/verdaccio/pull/2205
417
+
418
+ - b13a3fefd: refactor: improve versions and dist-tag filters
419
+ - 37274e4c8: feat: implement abbreviated manifest
420
+
421
+ Enable abbreviated manifest data by adding the header:
422
+
423
+ ```
424
+ curl -H "Accept: application/vnd.npm.install-v1+json" https://registry.npmjs.org/verdaccio
425
+ ```
426
+
427
+ It returns a filtered manifest, additionally includes the [time](https://github.com/pnpm/rfcs/pull/2) field by request.
428
+
429
+ Current support for packages managers:
430
+
431
+ - npm: yes
432
+ - pnpm: yes
433
+ - yarn classic: yes
434
+ - yarn modern (+2.x): [no](https://github.com/yarnpkg/berry/pull/3981#issuecomment-1076566096)
435
+
436
+ https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-metadata-format
437
+
438
+ - 45c03819e: refactor: render html middleware
439
+
440
+ ### Patch Changes
441
+
442
+ - 43f32687c: fix: abbreviated headers handle quality values
443
+ - 351aeeaa8: fix(deps): @verdaccio/utils should be a prod dep of local-storage
444
+ - a610ef26b: chore: add release step to private regisry on merge changeset pr
445
+ - 34f0f1101: Enable prerelease mode with **changesets**
446
+ - f859d2b1a: fix: official package "-" cannot be synced
447
+ - 168833d85: testing changesets
448
+ - b4cc80017: fix: improve abort request search
449
+ - 68ea21214: ESLint Warnings Fixed
450
+
451
+ Related to issue #1461
452
+
453
+ - max-len: most of the sensible max-len errors are fixed
454
+ - no-unused-vars: most of these types of errors are fixed by deleting not needed declarations
455
+ - @typescript-eslint/no-unused-vars: same as above
456
+
457
+ - b849128de: fix: handle upload scoped tarball
458
+ - Updated dependencies [292c0a37f]
459
+ - Updated dependencies [dc05edfe6]
460
+ - Updated dependencies [a1986e098]
461
+ - Updated dependencies [974cd8c19]
462
+ - Updated dependencies [a828271d6]
463
+ - Updated dependencies [ef88da3b4]
464
+ - Updated dependencies [43f32687c]
465
+ - Updated dependencies [679c19c1b]
466
+ - Updated dependencies [a3a209b5e]
467
+ - Updated dependencies [459b6fa72]
468
+ - Updated dependencies [9fc2e7961]
469
+ - Updated dependencies [9943e2b18]
470
+ - Updated dependencies [ae93e039d]
471
+ - Updated dependencies [24b9be020]
472
+ - Updated dependencies [794af76c5]
473
+ - Updated dependencies [e75c0a3b9]
474
+ - Updated dependencies [351aeeaa8]
475
+ - Updated dependencies [10aeb4f13]
476
+ - Updated dependencies [1d1112805]
477
+ - Updated dependencies [631abe1ac]
478
+ - Updated dependencies [9718e0330]
479
+ - Updated dependencies [7ef599cc4]
480
+ - Updated dependencies [b702ea363]
481
+ - Updated dependencies [1b217fd34]
482
+ - Updated dependencies [e367c3f1e]
483
+ - Updated dependencies [a1da11308]
484
+ - Updated dependencies [d167f92e1]
485
+ - Updated dependencies [d2c65da9c]
486
+ - Updated dependencies [00d1d2a17]
487
+ - Updated dependencies [1810ed0d8]
488
+ - Updated dependencies [a610ef26b]
489
+ - Updated dependencies [ddb6a2239]
490
+ - Updated dependencies [648575aa4]
491
+ - Updated dependencies [b61f762d6]
492
+ - Updated dependencies [4fc21146a]
493
+ - Updated dependencies [d43894e8f]
494
+ - Updated dependencies [154b2ecd3]
495
+ - Updated dependencies [061bfcc8d]
496
+ - Updated dependencies [aa763baec]
497
+ - Updated dependencies [378e907d5]
498
+ - Updated dependencies [16e38df8a]
499
+ - Updated dependencies [34f0f1101]
500
+ - Updated dependencies [82cb0f2bf]
501
+ - Updated dependencies [dc571aabd]
502
+ - Updated dependencies [5ddfa5264]
503
+ - Updated dependencies [b78f35257]
504
+ - Updated dependencies [ce013d2fc]
505
+ - Updated dependencies [f859d2b1a]
506
+ - Updated dependencies [2c594910d]
507
+ - Updated dependencies [6c1eb021b]
508
+ - Updated dependencies [62c24b632]
509
+ - Updated dependencies [0a6412ca9]
510
+ - Updated dependencies [0a6412ca9]
511
+ - Updated dependencies [d08fe29d9]
512
+ - Updated dependencies [5167bb528]
513
+ - Updated dependencies [f86c31ed0]
514
+ - Updated dependencies [65f88b826]
515
+ - Updated dependencies [aeff267d9]
516
+ - Updated dependencies [20c9e43ed]
517
+ - Updated dependencies [b3e8438f6]
518
+ - Updated dependencies [c9d1af0e5]
519
+ - Updated dependencies [730b5d8cc]
520
+ - Updated dependencies [4b29d715b]
521
+ - Updated dependencies [b13a3fefd]
522
+ - Updated dependencies [68ea21214]
523
+ - Updated dependencies [37274e4c8]
524
+ - Updated dependencies [fa274ee44]
525
+ - Updated dependencies [8f43bf17d]
526
+ - Updated dependencies [45c03819e]
527
+ - Updated dependencies [b849128de]
528
+ - @verdaccio/auth@6.0.0
529
+ - @verdaccio/config@6.0.0
530
+ - @verdaccio/core@6.0.0
531
+ - @verdaccio/logger@6.0.0
532
+ - @verdaccio/middleware@6.0.0
533
+ - @verdaccio/store@6.0.0
534
+ - @verdaccio/utils@6.0.0
535
+
3
536
  ## 6.0.0-6-next.59
4
537
 
5
538
  ### Patch Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Verdaccio contributors
3
+ Copyright (c) 2024 Verdaccio contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/build/index.js CHANGED
@@ -41,7 +41,6 @@ function _default(config, auth, storage) {
41
41
  strict: false,
42
42
  limit: config.max_body_size || '10mb'
43
43
  }));
44
- // @ts-ignore
45
44
  app.use((0, _middleware.antiLoop)(config));
46
45
  // encode / in a scoped package name to be matched as a single parameter in routes
47
46
  app.use(_middleware.encodeScopePackage);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_express","_interopRequireDefault","require","_middleware","_distTags","_package","_ping","_publish","_search","_stars","_user","_profile","_search2","_token","_whoami","obj","__esModule","default","_default","config","auth","storage","app","express","Router","param","validatePackage","validateName","match","use","apiJWTmiddleware","json","strict","limit","max_body_size","antiLoop","encodeScopePackage","whoami","profile","search","user","distTags","publish","ping","stars","v1Search","token","pkg"],"sources":["../src/index.ts"],"sourcesContent":["import express, { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n match,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { Config } from '@verdaccio/types';\n\nimport distTags from './dist-tags';\nimport pkg from './package';\nimport ping from './ping';\nimport publish from './publish';\nimport search from './search';\nimport stars from './stars';\nimport user from './user';\nimport profile from './v1/profile';\nimport v1Search from './v1/search';\nimport token from './v1/token';\nimport whoami from './whoami';\n\nexport default function (config: Config, auth: Auth, storage: Storage): Router {\n /* eslint new-cap:off */\n const app = express.Router();\n /* eslint new-cap:off */\n\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble\n app.param('package', validatePackage);\n app.param('filename', validateName);\n app.param('tag', validateName);\n app.param('version', validateName);\n app.param('revision', validateName);\n app.param('token', validateName);\n\n // these can't be safely put into express url for some reason\n // TODO: For some reason? what reason?\n app.param('_rev', match(/^-rev$/));\n app.param('org_couchdb_user', match(/^org\\.couchdb\\.user:/));\n app.use(auth.apiJWTmiddleware());\n app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' }));\n // @ts-ignore\n app.use(antiLoop(config));\n // encode / in a scoped package name to be matched as a single parameter in routes\n app.use(encodeScopePackage);\n // for \"npm whoami\"\n whoami(app);\n profile(app, auth, config);\n search(app);\n user(app, auth, config);\n distTags(app, auth, storage);\n publish(app, auth, storage);\n ping(app);\n stars(app, storage);\n v1Search(app, auth, storage);\n token(app, auth, storage, config);\n pkg(app, auth, storage);\n return app;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AAUA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,KAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IA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AACe,aAAa,IAAI;EAAO,CAAC,CAAC,CAAC;EAC/E;EACAZ,GAAG,CAACO,GAAG,CAAC,IAAAM,oBAAQ,EAAChB,MAAM,CAAC,CAAC;EACzB;EACAG,GAAG,CAACO,GAAG,CAACO,8BAAkB,CAAC;EAC3B;EACA,IAAAC,eAAM,EAACf,GAAG,CAAC;EACX,IAAAgB,gBAAO,EAAChB,GAAG,EAAEF,IAAI,EAAED,MAAM,CAAC;EAC1B,IAAAoB,eAAM,EAACjB,GAAG,CAAC;EACX,IAAAkB,aAAI,EAAClB,GAAG,EAAEF,IAAI,EAAED,MAAM,CAAC;EACvB,IAAAsB,iBAAQ,EAACnB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EAC5B,IAAAqB,gBAAO,EAACpB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EAC3B,IAAAsB,aAAI,EAACrB,GAAG,CAAC;EACT,IAAAsB,cAAK,EAACtB,GAAG,EAAED,OAAO,CAAC;EACnB,IAAAwB,gBAAQ,EAACvB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EAC5B,IAAAyB,cAAK,EAACxB,GAAG,EAAEF,IAAI,EAAEC,OAAO,EAAEF,MAAM,CAAC;EACjC,IAAA4B,gBAAG,EAACzB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EACvB,OAAOC,GAAG;AACZ"}
1
+ {"version":3,"file":"index.js","names":["_express","_interopRequireDefault","require","_middleware","_distTags","_package","_ping","_publish","_search","_stars","_user","_profile","_search2","_token","_whoami","obj","__esModule","default","_default","config","auth","storage","app","express","Router","param","validatePackage","validateName","match","use","apiJWTmiddleware","json","strict","limit","max_body_size","antiLoop","encodeScopePackage","whoami","profile","search","user","distTags","publish","ping","stars","v1Search","token","pkg"],"sources":["../src/index.ts"],"sourcesContent":["import express, { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n antiLoop,\n encodeScopePackage,\n match,\n validateName,\n validatePackage,\n} from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { Config } from '@verdaccio/types';\n\nimport distTags from './dist-tags';\nimport pkg from './package';\nimport ping from './ping';\nimport publish from './publish';\nimport search from './search';\nimport stars from './stars';\nimport user from './user';\nimport profile from './v1/profile';\nimport v1Search from './v1/search';\nimport token from './v1/token';\nimport whoami from './whoami';\n\nexport default function (config: Config, auth: Auth, storage: Storage): Router {\n /* eslint new-cap:off */\n const app = express.Router();\n /* eslint new-cap:off */\n\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble\n app.param('package', validatePackage);\n app.param('filename', validateName);\n app.param('tag', validateName);\n app.param('version', validateName);\n app.param('revision', validateName);\n app.param('token', validateName);\n\n // these can't be safely put into express url for some reason\n // TODO: For some reason? what reason?\n app.param('_rev', match(/^-rev$/));\n app.param('org_couchdb_user', match(/^org\\.couchdb\\.user:/));\n app.use(auth.apiJWTmiddleware());\n app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' }));\n app.use(antiLoop(config));\n // encode / in a scoped package name to be matched as a single parameter in routes\n app.use(encodeScopePackage);\n // for \"npm whoami\"\n whoami(app);\n profile(app, auth, config);\n search(app);\n user(app, auth, config);\n distTags(app, auth, storage);\n publish(app, auth, storage);\n ping(app);\n stars(app, storage);\n v1Search(app, auth, storage);\n token(app, auth, storage, config);\n pkg(app, auth, storage);\n return app;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AAUA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,KAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ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,GAAG,CAACO,GAAG,CAAC,IAAAM,oBAAQ,EAAChB,MAAM,CAAC,CAAC;EACzB;EACAG,GAAG,CAACO,GAAG,CAACO,8BAAkB,CAAC;EAC3B;EACA,IAAAC,eAAM,EAACf,GAAG,CAAC;EACX,IAAAgB,gBAAO,EAAChB,GAAG,EAAEF,IAAI,EAAED,MAAM,CAAC;EAC1B,IAAAoB,eAAM,EAACjB,GAAG,CAAC;EACX,IAAAkB,aAAI,EAAClB,GAAG,EAAEF,IAAI,EAAED,MAAM,CAAC;EACvB,IAAAsB,iBAAQ,EAACnB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EAC5B,IAAAqB,gBAAO,EAACpB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EAC3B,IAAAsB,aAAI,EAACrB,GAAG,CAAC;EACT,IAAAsB,cAAK,EAACtB,GAAG,EAAED,OAAO,CAAC;EACnB,IAAAwB,gBAAQ,EAACvB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EAC5B,IAAAyB,cAAK,EAACxB,GAAG,EAAEF,IAAI,EAAEC,OAAO,EAAEF,MAAM,CAAC;EACjC,IAAA4B,gBAAG,EAACzB,GAAG,EAAEF,IAAI,EAAEC,OAAO,CAAC;EACvB,OAAOC,GAAG;AACZ"}
package/build/package.js CHANGED
@@ -60,7 +60,6 @@ function _default(route, auth, storage) {
60
60
  // TODO: review why this param
61
61
  // enableRemote: true,
62
62
  });
63
-
64
63
  stream.on('content-length', size => {
65
64
  res.header(_core.HEADER_TYPE.CONTENT_LENGTH, size);
66
65
  });
@@ -1 +1 @@
1
- {"version":3,"file":"package.js","names":["_debug","_interopRequireDefault","require","_core","_logger","_middleware","_store","obj","__esModule","default","debug","buildDebug","_default","route","auth","storage","can","allow","beforeAll","a","b","logger","trace","afterAll","get","req","_res","next","name","params","package","version","write","query","abbreviated","stringUtils","getByQualityPriorityValue","Storage","ABBREVIATED_HEADER","requestOptions","protocol","headers","host","remoteAddress","socket","byPassCache","manifest","getPackageByOptions","uplinksLook","setHeader","HEADER_TYPE","CONTENT_TYPE","HEADERS","JSON_INSTALL_CHARSET","JSON","err","res","pkgName","filename","abort","AbortController","stream","getTarballNext","signal","on","size","header","CONTENT_LENGTH","once","locals","report_error","url","OCTET_STREAM","pipe"],"sources":["../src/package.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport { HEADERS, HEADER_TYPE, stringUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { allow } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:package');\n\nexport default function (route: Router, auth: Auth, storage: Storage): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n route.get(\n '/:package/:version?',\n can('access'),\n async function (\n req: $RequestExtend,\n _res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug('init package by version');\n const name = req.params.package;\n let version = req.params.version;\n const write = req.query.write === 'true';\n const abbreviated =\n stringUtils.getByQualityPriorityValue(req.get('Accept')) === Storage.ABBREVIATED_HEADER;\n const requestOptions = {\n protocol: req.protocol,\n headers: req.headers as any,\n // FIXME: if we migrate to req.hostname, the port is not longer included.\n host: req.host,\n remoteAddress: req.socket.remoteAddress,\n byPassCache: write,\n };\n\n try {\n const manifest = await storage.getPackageByOptions({\n name,\n uplinksLook: true,\n abbreviated,\n version,\n requestOptions,\n });\n if (abbreviated) {\n _res.setHeader(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_INSTALL_CHARSET);\n } else {\n _res.setHeader(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON);\n }\n\n next(manifest);\n } catch (err) {\n next(err);\n }\n }\n );\n\n route.get(\n '/:package/-/:filename',\n can('access'),\n async function (req: $RequestExtend, res: $ResponseExtend, next): Promise<void> {\n const { package: pkgName, filename } = req.params;\n const abort = new AbortController();\n try {\n const stream = (await storage.getTarballNext(pkgName, filename, {\n signal: abort.signal,\n // TODO: review why this param\n // enableRemote: true,\n })) as any;\n\n stream.on('content-length', (size) => {\n res.header(HEADER_TYPE.CONTENT_LENGTH, size);\n });\n\n stream.once('error', (err) => {\n res.locals.report_error(err);\n next(err);\n });\n\n req.on('abort', () => {\n debug('request aborted for %o', req.url);\n abort.abort();\n });\n\n res.header(HEADERS.CONTENT_TYPE, HEADERS.OCTET_STREAM);\n stream.pipe(res);\n } catch (err: any) {\n // console.log('catch API error request', err);\n res.locals.report_error(err);\n next(err);\n }\n }\n );\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAA2C,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAI3C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,uBAAuB,CAAC;AAElC,SAAAC,SAAUC,KAAa,EAAEC,IAAU,EAAEC,OAAgB,EAAQ;EAC1E,MAAMC,GAAG,GAAG,IAAAC,iBAAK,EAACH,IAAI,EAAE;IACtBI,SAAS,EAAEA,CAACC,CAAC,EAAEC,CAAC,KAAKC,cAAM,CAACC,KAAK,CAACH,CAAC,EAAEC,CAAC,CAAC;IACvCG,QAAQ,EAAEA,CAACJ,CAAC,EAAEC,CAAC,KAAKC,cAAM,CAACC,KAAK,CAACH,CAAC,EAAEC,CAAC;EACvC,CAAC,CAAC;EACFP,KAAK,CAACW,GAAG,CACP,qBAAqB,EACrBR,GAAG,CAAC,QAAQ,CAAC,EACb,gBACES,GAAmB,EACnBC,IAAq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;IAC9E,MAAM;MAAEG,OAAO,EAAE2B,OAAO;MAAEC;IAAS,CAAC,GAAGjC,GAAG,CAACI,MAAM;IACjD,MAAM8B,KAAK,GAAG,IAAIC,eAAe,CAAC,CAAC;IACnC,IAAI;MACF,MAAMC,MAAM,GAAI,MAAM9C,OAAO,CAAC+C,cAAc,CAACL,OAAO,EAAEC,QAAQ,EAAE;QAC9DK,MAAM,EAAEJ,KAAK,CAACI;QACd;QACA;MACF,CAAC,CAAS;;MAEVF,MAAM,CAACG,EAAE,CAAC,gBAAgB,EAAGC,IAAI,IAAK;QACpCT,GAAG,CAACU,MAAM,CAAChB,iBAAW,CAACiB,cAAc,EAAEF,IAAI,CAAC;MAC9C,CAAC,CAAC;MAEFJ,MAAM,CAACO,IAAI,CAAC,OAAO,EAAGb,GAAG,IAAK;QAC5BC,GAAG,CAACa,MAAM,CAACC,YAAY,CAACf,GAAG,CAAC;QAC5B5B,IAAI,CAAC4B,GAAG,CAAC;MACX,CAAC,CAAC;MAEF9B,GAAG,CAACuC,EAAE,CAAC,OAAO,EAAE,MAAM;QACpBtD,KAAK,CAAC,wBAAwB,EAAEe,GAAG,CAAC8C,GAAG,CAAC;QACxCZ,KAAK,CAACA,KAAK,CAAC,CAAC;MACf,CAAC,CAAC;MAEFH,GAAG,CAACU,MAAM,CAACd,aAAO,CAACD,YAAY,EAAEC,aAAO,CAACoB,YAAY,CAAC;MACtDX,MAAM,CAACY,IAAI,CAACjB,GAAG,CAAC;IAClB,CAAC,CAAC,OAAOD,GAAQ,EAAE;MACjB;MACAC,GAAG,CAACa,MAAM,CAACC,YAAY,CAACf,GAAG,CAAC;MAC5B5B,IAAI,CAAC4B,GAAG,CAAC;IACX;EACF,CACF,CAAC;AACH"}
1
+ {"version":3,"file":"package.js","names":["_debug","_interopRequireDefault","require","_core","_logger","_middleware","_store","obj","__esModule","default","debug","buildDebug","_default","route","auth","storage","can","allow","beforeAll","a","b","logger","trace","afterAll","get","req","_res","next","name","params","package","version","write","query","abbreviated","stringUtils","getByQualityPriorityValue","Storage","ABBREVIATED_HEADER","requestOptions","protocol","headers","host","remoteAddress","socket","byPassCache","manifest","getPackageByOptions","uplinksLook","setHeader","HEADER_TYPE","CONTENT_TYPE","HEADERS","JSON_INSTALL_CHARSET","JSON","err","res","pkgName","filename","abort","AbortController","stream","getTarballNext","signal","on","size","header","CONTENT_LENGTH","once","locals","report_error","url","OCTET_STREAM","pipe"],"sources":["../src/package.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport { HEADERS, HEADER_TYPE, stringUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { allow } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\nconst debug = buildDebug('verdaccio:api:package');\n\nexport default function (route: Router, auth: Auth, storage: Storage): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n route.get(\n '/:package/:version?',\n can('access'),\n async function (\n req: $RequestExtend,\n _res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n debug('init package by version');\n const name = req.params.package;\n let version = req.params.version;\n const write = req.query.write === 'true';\n const abbreviated =\n stringUtils.getByQualityPriorityValue(req.get('Accept')) === Storage.ABBREVIATED_HEADER;\n const requestOptions = {\n protocol: req.protocol,\n headers: req.headers as any,\n // FIXME: if we migrate to req.hostname, the port is not longer included.\n host: req.host,\n remoteAddress: req.socket.remoteAddress,\n byPassCache: write,\n };\n\n try {\n const manifest = await storage.getPackageByOptions({\n name,\n uplinksLook: true,\n abbreviated,\n version,\n requestOptions,\n });\n if (abbreviated) {\n _res.setHeader(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_INSTALL_CHARSET);\n } else {\n _res.setHeader(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON);\n }\n\n next(manifest);\n } catch (err) {\n next(err);\n }\n }\n );\n\n route.get(\n '/:package/-/:filename',\n can('access'),\n async function (req: $RequestExtend, res: $ResponseExtend, next): Promise<void> {\n const { package: pkgName, filename } = req.params;\n const abort = new AbortController();\n try {\n const stream = (await storage.getTarballNext(pkgName, filename, {\n signal: abort.signal,\n // TODO: review why this param\n // enableRemote: true,\n })) as any;\n\n stream.on('content-length', (size) => {\n res.header(HEADER_TYPE.CONTENT_LENGTH, size);\n });\n\n stream.once('error', (err) => {\n res.locals.report_error(err);\n next(err);\n });\n\n req.on('abort', () => {\n debug('request aborted for %o', req.url);\n abort.abort();\n });\n\n res.header(HEADERS.CONTENT_TYPE, HEADERS.OCTET_STREAM);\n stream.pipe(res);\n } catch (err: any) {\n // console.log('catch API error request', err);\n res.locals.report_error(err);\n next(err);\n }\n }\n );\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAA2C,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAI3C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,uBAAuB,CAAC;AAElC,SAAAC,SAAUC,KAAa,EAAEC,IAAU,EAAEC,OAAgB,EAAQ;EAC1E,MAAMC,GAAG,GAAG,IAAAC,iBAAK,EAACH,IAAI,EAAE;IACtBI,SAAS,EAAEA,CAACC,CAAC,EAAEC,CAAC,KAAKC,cAAM,CAACC,KAAK,CAACH,CAAC,EAAEC,CAAC,CAAC;IACvCG,QAAQ,EAAEA,CAACJ,CAAC,EAAEC,CAAC,KAAKC,cAAM,CAACC,KAAK,CAACH,CAAC,EAAEC,CAAC;EACvC,CAAC,CAAC;EACFP,KAAK,CAAC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,GAAG,CAAC,QAAQ,CAAC,EACb,gBAAgBS,GAAmB,EAAE+B,GAAoB,EAAE7B,IAAI,EAAiB;IAC9E,MAAM;MAAEG,OAAO,EAAE2B,OAAO;MAAEC;IAAS,CAAC,GAAGjC,GAAG,CAACI,MAAM;IACjD,MAAM8B,KAAK,GAAG,IAAIC,eAAe,CAAC,CAAC;IACnC,IAAI;MACF,MAAMC,MAAM,GAAI,MAAM9C,OAAO,CAAC+C,cAAc,CAACL,OAAO,EAAEC,QAAQ,EAAE;QAC9DK,MAAM,EAAEJ,KAAK,CAACI;QACd;QACA;MACF,CAAC,CAAS;MAEVF,MAAM,CAACG,EAAE,CAAC,gBAAgB,EAAGC,IAAI,IAAK;QACpCT,GAAG,CAACU,MAAM,CAAChB,iBAAW,CAACiB,cAAc,EAAEF,IAAI,CAAC;MAC9C,CAAC,CAAC;MAEFJ,MAAM,CAACO,IAAI,CAAC,OAAO,EAAGb,GAAG,IAAK;QAC5BC,GAAG,CAACa,MAAM,CAACC,YAAY,CAACf,GAAG,CAAC;QAC5B5B,IAAI,CAAC4B,GAAG,CAAC;MACX,CAAC,CAAC;MAEF9B,GAAG,CAACuC,EAAE,CAAC,OAAO,EAAE,MAAM;QACpBtD,KAAK,CAAC,wBAAwB,EAAEe,GAAG,CAAC8C,GAAG,CAAC;QACxCZ,KAAK,CAACA,KAAK,CAAC,CAAC;MACf,CAAC,CAAC;MAEFH,GAAG,CAACU,MAAM,CAACd,aAAO,CAACD,YAAY,EAAEC,aAAO,CAACoB,YAAY,CAAC;MACtDX,MAAM,CAACY,IAAI,CAACjB,GAAG,CAAC;IAClB,CAAC,CAAC,OAAOD,GAAQ,EAAE;MACjB;MACAC,GAAG,CAACa,MAAM,CAACC,YAAY,CAACf,GAAG,CAAC;MAC5B5B,IAAI,CAAC4B,GAAG,CAAC;IACX;EACF,CACF,CAAC;AACH"}
package/build/publish.js CHANGED
@@ -176,10 +176,10 @@ function publishPackage(storage) {
176
176
  requestOptions: {
177
177
  host: req.hostname,
178
178
  protocol: req.protocol,
179
- // @ts-ignore
180
179
  headers: req.headers,
181
180
  username
182
- }
181
+ },
182
+ uplinksLook: false
183
183
  });
184
184
  res.status(_core.HTTP_STATUS.CREATED);
185
185
  return next({
@@ -1 +1 @@
1
- {"version":3,"file":"publish.js","names":["_debug","_interopRequireDefault","require","_mime","_core","_logger","_middleware","obj","__esModule","default","debug","buildDebug","publish","router","auth","storage","can","allow","beforeAll","a","b","logger","trace","afterAll","put","media","mime","getType","expectJson","publishPackage","delete","req","res","next","packageName","params","package","rev","revision","removePackage","status","HTTP_STATUS","CREATED","ok","API_MESSAGE","PKG_REMOVED","err","filename","removeTarball","TARBALL_REMOVED","_req$remote_user","ac","AbortController","metadata","body","username","remote_user","name","message","updateManifest","signal","requestOptions","host","hostname","protocol","headers","success"],"sources":["../src/publish.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport mime from 'mime';\n\nimport { Auth } from '@verdaccio/auth';\nimport { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { allow, expectJson, media } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\n// import star from './star';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package / un/start a package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n * \n * 3. Star a package\n *\n * Permissions: start a package depends of the publish and unpublish permissions, there is no\n * specific flag for star or un start.\n * The URL for star is similar to the unpublish (change package format)\n *\n * npm has no endpoint for star a package, rather mutate the metadata and acts as, the difference\n * is the users property which is part of the payload and the body only includes\n *\n * {\n\t\t \"_id\": pkgName,\n\t \t\"_rev\": \"3-b0cdaefc9bdb77c8\",\n\t\t \"users\": {\n\t\t [username]: boolean value (true, false)\n\t\t }\n\t}\n *\n */\nexport default function publish(router: Router, auth: Auth, storage: Storage): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n router.put(\n '/:package',\n can('publish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n router.put(\n '/:package/-rev/:revision',\n can('unpublish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when the first call detect there is only one version remaining\n * in the metadata, then the client decides to DELETE the resource\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-rev/:revision',\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-/:filename/-rev/:revision',\n can('unpublish'),\n can('publish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(storage: Storage): any {\n return async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n const metadata = req.body;\n const username = req?.remote_user?.name;\n\n try {\n const message = await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions: {\n host: req.hostname,\n protocol: req.protocol,\n // @ts-ignore\n headers: req.headers,\n username,\n },\n });\n\n res.status(HTTP_STATUS.CREATED);\n\n return next({\n success: true,\n ok: message,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAGA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAAiE,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAKjE;;AAEA,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,uBAAuB,CAAC;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,OAAOA,CAACC,MAAc,EAAEC,IAAU,EAAEC,OAAgB,EAAQ;EAClF,MAAMC,GAAG,GAAG,IAAAC,iBAAK,EAACH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B,GAAG,CAACuB,IAAI;IACzB,MAAMC,QAAQ,GAAGxB,GAAG,aAAHA,GAAG,wBAAAmB,gBAAA,GAAHnB,GAAG,CAAEyB,WAAW,cAAAN,gBAAA,uBAAhBA,gBAAA,CAAkBO,IAAI;IAEvC,IAAI;MACF,MAAMC,OAAO,GAAG,MAAM3C,OAAO,CAAC4C,cAAc,CAACN,QAAQ,EAAE;QACrDI,IAAI,EAAEvB,WAAW;QACjBI,QAAQ;QACRsB,MAAM,EAAET,EAAE,CAACS,MAAM;QACjBC,cAAc,EAAE;UACdC,IAAI,EAAE/B,GAAG,CAACgC,QAAQ;UAClBC,QAAQ,EAAEjC,GAAG,CAACiC,QAAQ;UACtB;UACAC,OAAO,EAAElC,GAAG,CAACkC,OAAO;UACpBV;QACF;MACF,CAAC,CAAC;MAEFvB,GAAG,CAACQ,MAAM,CAACC,iBAAW,CAACC,OAAO,CAAC;MAE/B,OAAOT,IAAI,CAAC;QACViC,OAAO,EAAE,IAAI;QACbvB,EAAE,EAAEe;MACN,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOZ,GAAQ,EAAE;MACjB;MACAb,IAAI,CAACa,GAAG,CAAC;IACX;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"publish.js","names":["_debug","_interopRequireDefault","require","_mime","_core","_logger","_middleware","obj","__esModule","default","debug","buildDebug","publish","router","auth","storage","can","allow","beforeAll","a","b","logger","trace","afterAll","put","media","mime","getType","expectJson","publishPackage","delete","req","res","next","packageName","params","package","rev","revision","removePackage","status","HTTP_STATUS","CREATED","ok","API_MESSAGE","PKG_REMOVED","err","filename","removeTarball","TARBALL_REMOVED","_req$remote_user","ac","AbortController","metadata","body","username","remote_user","name","message","updateManifest","signal","requestOptions","host","hostname","protocol","headers","uplinksLook","success"],"sources":["../src/publish.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Router } from 'express';\nimport mime from 'mime';\n\nimport { Auth } from '@verdaccio/auth';\nimport { API_MESSAGE, HTTP_STATUS } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { allow, expectJson, media } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\n\n// import star from './star';\n\nconst debug = buildDebug('verdaccio:api:publish');\n\n/**\n * Publish a package / update package / un/start a package\n *\n * There are multiples scenarios here to be considered:\n *\n * 1. Publish scenario\n *\n * Publish a package consist of at least 1 step (PUT) with a metadata payload.\n * When a package is published, an _attachment property is present that contains the data\n * of the tarball.\n *\n * Example flow of publish.\n *\n * npm http fetch PUT 201 http://localhost:4873/@scope%2ftest1 9627ms\n npm info lifecycle @scope/test1@1.0.1~publish: @scope/test1@1.0.1\n npm info lifecycle @scope/test1@1.0.1~postpublish: @scope/test1@1.0.1\n + @scope/test1@1.0.1\n npm verb exit [ 0, true ]\n *\n *\n * 2. Unpublish scenario\n *\n * Unpublish consist in 3 steps.\n * 1. Try to fetch metadata -> if it fails, return 404\n * 2. Compute metadata locally (client side) and send a mutate payload excluding the version to\n * be unpublished\n * eg: if metadata reflects 1.0.1, 1.0.2 and 1.0.3, the computed metadata won't include 1.0.3.\n * 3. Once the second step has been successfully finished, delete the tarball.\n *\n * All these steps are consecutive and required, there is no transacions here, if step 3 fails,\n * metadata might get corrupted.\n *\n * Note the unpublish call will suffix in the url a /-rev/14-5d500cfce92f90fd revision number,\n * this not\n * used internally.\n *\n *\n * Example flow of unpublish.\n *\n * There are two possible flows:\n *\n * - Remove all packages (entirely)\n * eg: npm unpublish package-name@* --force\n * eg: npm unpublish package-name --force\n *\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n *\n * - Remove a specific version\n * eg: npm unpublish package-name@1.0.0 --force\n *\n * Get fresh manifest\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1680ms\n * Update manifest without the version to be unpublished\n * npm http fetch PUT 201 http://localhost:4873/custom-name/-rev/14-5d500cfce92f90fd 956606ms\n * Get fresh manifest (revision should be different)\n * npm http fetch GET 200 http://localhost:4873/custom-name?write=true 1601ms\n * Remove the tarball\n * npm http fetch DELETE 201 http://localhost:4873/custom-name/-/test1-1.0.3.tgz/-rev/16-e11c8db282b2d992 19ms\n * \n * 3. Star a package\n *\n * Permissions: start a package depends of the publish and unpublish permissions, there is no\n * specific flag for star or un start.\n * The URL for star is similar to the unpublish (change package format)\n *\n * npm has no endpoint for star a package, rather mutate the metadata and acts as, the difference\n * is the users property which is part of the payload and the body only includes\n *\n * {\n\t\t \"_id\": pkgName,\n\t \t\"_rev\": \"3-b0cdaefc9bdb77c8\",\n\t\t \"users\": {\n\t\t [username]: boolean value (true, false)\n\t\t }\n\t}\n *\n */\nexport default function publish(router: Router, auth: Auth, storage: Storage): void {\n const can = allow(auth, {\n beforeAll: (a, b) => logger.trace(a, b),\n afterAll: (a, b) => logger.trace(a, b),\n });\n router.put(\n '/:package',\n can('publish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n router.put(\n '/:package/-rev/:revision',\n can('unpublish'),\n media(mime.getType('json')),\n expectJson,\n publishPackage(storage)\n );\n\n /**\n * Un-publishing an entire package.\n *\n * This scenario happens when the first call detect there is only one version remaining\n * in the metadata, then the client decides to DELETE the resource\n * npm http fetch GET 304 http://localhost:4873/package-name?write=true 1076ms (from cache)\n * npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-rev/:revision',\n can('unpublish'),\n async function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n const packageName = req.params.package;\n const rev = req.params.revision;\n\n logger.debug({ packageName }, `unpublishing @{packageName}`);\n try {\n await storage.removePackage(packageName, rev);\n debug('package %s unpublished', packageName);\n res.status(HTTP_STATUS.CREATED);\n return next({ ok: API_MESSAGE.PKG_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n\n /*\n Remove a tarball, this happens when npm unpublish a package unique version.\n npm http fetch DELETE 201 http://localhost:4873/package-name/-rev/18-d8ebe3020bd4ac9c 22ms\n */\n router.delete(\n '/:package/-/:filename/-rev/:revision',\n can('unpublish'),\n can('publish'),\n async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const packageName = req.params.package;\n const { filename, revision } = req.params;\n\n logger.debug(\n { packageName, filename, revision },\n `removing a tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n try {\n await storage.removeTarball(packageName, filename, revision);\n res.status(HTTP_STATUS.CREATED);\n\n logger.debug(\n { packageName, filename, revision },\n `success remove tarball for @{packageName}-@{tarballName}-@{revision}`\n );\n return next({ ok: API_MESSAGE.TARBALL_REMOVED });\n } catch (err) {\n return next(err);\n }\n }\n );\n}\n\nexport function publishPackage(storage: Storage): any {\n return async function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): Promise<void> {\n const ac = new AbortController();\n const packageName = req.params.package;\n const { revision } = req.params;\n const metadata = req.body;\n const username = req?.remote_user?.name;\n\n try {\n const message = await storage.updateManifest(metadata, {\n name: packageName,\n revision,\n signal: ac.signal,\n requestOptions: {\n host: req.hostname,\n protocol: req.protocol,\n headers: req.headers as { [key: string]: string },\n username,\n },\n uplinksLook: false,\n });\n\n res.status(HTTP_STATUS.CREATED);\n\n return next({\n success: true,\n ok: message,\n });\n } catch (err: any) {\n // TODO: review if we need the abort controller here\n next(err);\n }\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAGA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAAiE,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAKjE;;AAEA,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,uBAAuB,CAAC;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,OAAOA,CAACC,MAAc,EAAEC,IAAU,EAAEC,OAAgB,EAAQ;EAClF,MAAMC,GAAG,GAAG,IAAAC,iBAAK,EAACH,IAAI,EAAE;IACtBI,SAAS,EAAEA,CAACC,CAAC,EAAEC,CAAC,KAAKC,cAAM,CAACC,KAAK,CAACH,CAAC,EAAEC,CAAC,CAAC;IACvCG,QAAQ,EAAEA,CAACJ,CAAC,EAAEC,CAAC,KAAKC,cAAM,CAACC,KAAK,CAACH,CAAC,EAAEC,CAAC;EACvC,CAAC,CAAC;EACFP,MAAM,CAACW,GAAG,CACR,WAAW,EACXR,GAAG,CAAC,SAAS,CAAC,EACd,IAAAS,iBAAK,EAACC,aAAI,CAACC,OAAO,CAAC,MAAM,CAAC,CAAC,EAC3BC,sBAAU,EACVC,cAAc,CAACd,OAAO,CACxB,CAAC;EAEDF,MAAM,CAACW,GAAG,CACR,0BAA0B,EAC1BR,GAAG,CAAC,WAAW,CAAC,EAChB,IAAAS,iBAAK,EAACC,aAAI,CAACC,OAAO,CAAC,MAAM,CAAC,CAAC,EAC3BC,sBAAU,EACVC,cAAc,CAACd,OAAO,CACxB,CAAC;;EAED;AACF;AACA;AACA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,IAAI;QACbxB,EAAE,EAAEe;MACN,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOZ,GAAQ,EAAE;MACjB;MACAb,IAAI,CAACa,GAAG,CAAC;IACX;EACF,CAAC;AACH"}
@@ -51,10 +51,12 @@ function _default(route, auth, config) {
51
51
  return next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNAUTHORIZED, _core.API_ERROR.PASSWORD_SHORT));
52
52
  /* eslint new-cap:off */
53
53
  }
54
-
54
+ if (_lodash.default.isEmpty(password.old)) {
55
+ return next(_core.errorUtils.getBadRequest('old password is required'));
56
+ }
55
57
  auth.changePassword(name, password.old, password.new, (err, isUpdated) => {
56
58
  if (_lodash.default.isNull(err) === false) {
57
- return next(_core.errorUtils.getCode(err.status, err.message) || _core.errorUtils.getConflict(err.message));
59
+ return next(_core.errorUtils.getForbidden(err.message));
58
60
  }
59
61
  if (isUpdated) {
60
62
  return next(buildProfile(req.remote_user.name));
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","names":["_lodash","_interopRequireDefault","require","_core","_middleware","obj","__esModule","default","_default","route","auth","config","buildProfile","name","tfa","email","email_verified","created","updated","cidr_whitelist","fullname","get","rateLimit","userRateLimit","req","res","next","_","isNil","remote_user","status","HTTP_STATUS","UNAUTHORIZED","message","API_ERROR","MUST_BE_LOGGED","post","password","body","_config$serverSetting","validatioUtils","validatePassword","new","serverSettings","passwordValidationRegex","errorUtils","getCode","PASSWORD_SHORT","changePassword","old","err","isUpdated","isNull","getConflict","getInternalError","INTERNAL_SERVER_ERROR","SERVICE_UNAVAILABLE","SUPPORT_ERRORS","TFA_DISABLED","INTERNAL_ERROR","APP_ERROR","PROFILE_ERROR"],"sources":["../../src/v1/profile.ts"],"sourcesContent":["import { Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n API_ERROR,\n APP_ERROR,\n HTTP_STATUS,\n SUPPORT_ERRORS,\n errorUtils,\n validatioUtils,\n} from '@verdaccio/core';\nimport { rateLimit } from '@verdaccio/middleware';\nimport { Config } from '@verdaccio/types';\n\nimport { $NextFunctionVer, $RequestExtend } from '../../types/custom';\n\nexport interface Profile {\n tfa: boolean;\n name: string;\n email: string;\n email_verified: boolean;\n created: string;\n updated: string;\n cidr_whitelist: string[] | null;\n fullname: string;\n}\n\nexport default function (route: Router, auth: Auth, config: Config): void {\n function buildProfile(name: string): Profile {\n return {\n tfa: false,\n name,\n email: '',\n email_verified: false,\n created: '',\n updated: '',\n cidr_whitelist: null,\n fullname: '',\n };\n }\n\n route.get(\n '/-/npm/v1/user',\n rateLimit(config?.userRateLimit),\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name) === false) {\n return next(buildProfile(req.remote_user.name));\n }\n\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n );\n\n route.post(\n '/-/npm/v1/user',\n rateLimit(config?.userRateLimit),\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name)) {\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n\n const { password, tfa } = req.body;\n const { name } = req.remote_user;\n\n if (_.isNil(password) === false) {\n if (\n validatioUtils.validatePassword(\n password.new,\n config?.serverSettings?.passwordValidationRegex\n ) === false\n ) {\n /* eslint new-cap:off */\n return next(errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT));\n /* eslint new-cap:off */\n }\n\n auth.changePassword(\n name,\n password.old,\n password.new,\n (err, isUpdated): $NextFunctionVer => {\n if (_.isNull(err) === false) {\n return next(\n errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message)\n );\n }\n\n if (isUpdated) {\n return next(buildProfile(req.remote_user.name));\n }\n return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR));\n }\n );\n } else if (_.isNil(tfa) === false) {\n return next(\n errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED)\n );\n } else {\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR));\n }\n }\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAQA,IAAAE,WAAA,GAAAF,OAAA;AAAkD,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAgBnC,SAAAG,SAAUC,KAAa,EAAEC,IAAU,EAAEC,MAAc,EAAQ;EACxE,SAASC,YAAYA,CAACC,IAAY,EAAW;IAC3C,OAAO;MACLC,GAAG,EAAE,KAAK;MACVD,IAAI;MACJE,KAAK,EAAE,EAAE;MACTC,cAAc,EAAE,KAAK;MACrBC,OAAO,EAAE,EAAE;MACXC,OAAO,EAAE,EAAE;MACXC,cAAc,EAAE,IAAI;MACpBC,QAAQ,EAAE;IACZ,CAAC;EACH;EAEAX,KAAK,CAACY,GAAG,CACP,gBAAgB,EAChB,IAAAC,qBAAS,EAACX,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEY,aAAa,CAAC,EAChC,UAAUC,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAQ;IAC1E,IAAIC,eAAC,CAACC,KAAK,CAACJ,GAAG,CAACK,WAAW,CAAChB,IAAI,CAAC,KAAK,KAAK,EAAE;MAC3C,OAAOa,IAAI,CAACd,YAAY,CAACY,GAAG,CAACK,WAAW,CAAChB,IAAI,CAAC,CAAC;IACjD;IAEAY,GAAG,CAACK,MAAM,CAACC,iBAAW,CAACC,YAAY,CAAC;IACpC,OAAON,IAAI,CAAC;MACVO,OAAO,EAAEC,eAAS,CAACC;IACrB,CAAC,CAAC;EACJ,CACF,CAAC;EAED1B,KA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B,OAAO,CAAC,IAAIY,gBAAU,CAACQ,WAAW,CAACH,GAAG,CAACjB,OAAO,CACnF,CAAC;QACH;QAEA,IAAIkB,SAAS,EAAE;UACb,OAAOzB,IAAI,CAACd,YAAY,CAACY,GAAG,CAACK,WAAW,CAAChB,IAAI,CAAC,CAAC;QACjD;QACA,OAAOa,IAAI,CAACmB,gBAAU,CAACS,gBAAgB,CAACpB,eAAS,CAACqB,qBAAqB,CAAC,CAAC;MAC3E,CACF,CAAC;IACH,CAAC,MAAM,IAAI5B,eAAC,CAACC,KAAK,CAACd,GAAG,CAAC,KAAK,KAAK,EAAE;MACjC,OAAOY,IAAI,CACTmB,gBAAU,CAACC,OAAO,CAACf,iBAAW,CAACyB,mBAAmB,EAAEC,oBAAc,CAACC,YAAY,CACjF,CAAC;IACH,CAAC,MAAM;MACL,OAAOhC,IAAI,CAACmB,gBAAU,CAACC,OAAO,CAACf,iBAAW,CAAC4B,cAAc,EAAEC,eAAS,CAACC,aAAa,CAAC,CAAC;IACtF;EACF,CACF,CAAC;AACH"}
1
+ {"version":3,"file":"profile.js","names":["_lodash","_interopRequireDefault","require","_core","_middleware","obj","__esModule","default","_default","route","auth","config","buildProfile","name","tfa","email","email_verified","created","updated","cidr_whitelist","fullname","get","rateLimit","userRateLimit","req","res","next","_","isNil","remote_user","status","HTTP_STATUS","UNAUTHORIZED","message","API_ERROR","MUST_BE_LOGGED","post","password","body","_config$serverSetting","validatioUtils","validatePassword","new","serverSettings","passwordValidationRegex","errorUtils","getCode","PASSWORD_SHORT","isEmpty","old","getBadRequest","changePassword","err","isUpdated","isNull","getForbidden","getInternalError","INTERNAL_SERVER_ERROR","SERVICE_UNAVAILABLE","SUPPORT_ERRORS","TFA_DISABLED","INTERNAL_ERROR","APP_ERROR","PROFILE_ERROR"],"sources":["../../src/v1/profile.ts"],"sourcesContent":["import { Response, Router } from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n API_ERROR,\n APP_ERROR,\n HTTP_STATUS,\n SUPPORT_ERRORS,\n errorUtils,\n validatioUtils,\n} from '@verdaccio/core';\nimport { rateLimit } from '@verdaccio/middleware';\nimport { Config } from '@verdaccio/types';\n\nimport { $NextFunctionVer, $RequestExtend } from '../../types/custom';\n\nexport interface Profile {\n tfa: boolean;\n name: string;\n email: string;\n email_verified: boolean;\n created: string;\n updated: string;\n cidr_whitelist: string[] | null;\n fullname: string;\n}\n\nexport default function (route: Router, auth: Auth, config: Config): void {\n function buildProfile(name: string): Profile {\n return {\n tfa: false,\n name,\n email: '',\n email_verified: false,\n created: '',\n updated: '',\n cidr_whitelist: null,\n fullname: '',\n };\n }\n\n route.get(\n '/-/npm/v1/user',\n rateLimit(config?.userRateLimit),\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name) === false) {\n return next(buildProfile(req.remote_user.name));\n }\n\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n );\n\n route.post(\n '/-/npm/v1/user',\n rateLimit(config?.userRateLimit),\n function (req: $RequestExtend, res: Response, next: $NextFunctionVer): void {\n if (_.isNil(req.remote_user.name)) {\n res.status(HTTP_STATUS.UNAUTHORIZED);\n return next({\n message: API_ERROR.MUST_BE_LOGGED,\n });\n }\n\n const { password, tfa } = req.body;\n const { name } = req.remote_user;\n\n if (_.isNil(password) === false) {\n if (\n validatioUtils.validatePassword(\n password.new,\n config?.serverSettings?.passwordValidationRegex\n ) === false\n ) {\n /* eslint new-cap:off */\n return next(errorUtils.getCode(HTTP_STATUS.UNAUTHORIZED, API_ERROR.PASSWORD_SHORT));\n /* eslint new-cap:off */\n }\n\n if (_.isEmpty(password.old)) {\n return next(errorUtils.getBadRequest('old password is required'));\n }\n\n auth.changePassword(\n name,\n password.old,\n password.new,\n (err, isUpdated): $NextFunctionVer => {\n if (_.isNull(err) === false) {\n return next(errorUtils.getForbidden(err.message));\n }\n\n if (isUpdated) {\n return next(buildProfile(req.remote_user.name));\n }\n return next(errorUtils.getInternalError(API_ERROR.INTERNAL_SERVER_ERROR));\n }\n );\n } else if (_.isNil(tfa) === false) {\n return next(\n errorUtils.getCode(HTTP_STATUS.SERVICE_UNAVAILABLE, SUPPORT_ERRORS.TFA_DISABLED)\n );\n } else {\n return next(errorUtils.getCode(HTTP_STATUS.INTERNAL_ERROR, APP_ERROR.PROFILE_ERROR));\n }\n }\n );\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAQA,IAAAE,WAAA,GAAAF,OAAA;AAAkD,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAgBnC,SAAAG,SAAUC,KAAa,EAAEC,IAAU,EAAEC,MAAc,EAAQ;EACxE,SAASC,YAAYA,CAACC,IAAY,EAAW;IAC3C,OAAO;MACLC,GAAG,EAAE,KAAK;MACVD,IAAI;MACJE,KAAK,EAAE,EAAE;MACTC,cAAc,EAAE,KAAK;MACrBC,OAAO,EAAE,EAAE;MACXC,OAAO,EAAE,EAAE;MACXC,cAAc,EAAE,IAAI;MACpBC,QAAQ,EAAE;IACZ,CAAC;EACH;EAEAX,KAAK,CAACY,GAAG,CACP,gBAAgB,EAChB,IAAAC,qBAAS,EAACX,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEY,aAAa,CAAC,EAChC,UAAUC,GAAmB,EAAEC,GAAa,EAAEC,IAAsB,EAAQ;IAC1E,IAAIC,eAAC,CAACC,KAAK,CAACJ,GAAG,CAACK,WAAW,CAAChB,IAAI,CAAC,KAAK,KAAK,EAAE;MAC3C,OAAOa,IAAI,CAACd,YAAY,CAACY,GAAG,CAACK,WAAW,CAAChB,IAAI,CAAC,CAAC;IACjD;IAEAY,GAAG,CAACK,MAAM,CAACC,iBAAW,CAACC,YAAY,CAAC;I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B,QAAQ,CAACY,GAAG,EACZZ,QAAQ,CAACK,GAAG,EACZ,CAACU,GAAG,EAAEC,SAAS,KAAuB;QACpC,IAAI1B,eAAC,CAAC2B,MAAM,CAACF,GAAG,CAAC,KAAK,KAAK,EAAE;UAC3B,OAAO1B,IAAI,CAACmB,gBAAU,CAACU,YAAY,CAACH,GAAG,CAACnB,OAAO,CAAC,CAAC;QACnD;QAEA,IAAIoB,SAAS,EAAE;UACb,OAAO3B,IAAI,CAACd,YAAY,CAACY,GAAG,CAACK,WAAW,CAAChB,IAAI,CAAC,CAAC;QACjD;QACA,OAAOa,IAAI,CAACmB,gBAAU,CAACW,gBAAgB,CAACtB,eAAS,CAACuB,qBAAqB,CAAC,CAAC;MAC3E,CACF,CAAC;IACH,CAAC,MAAM,IAAI9B,eAAC,CAACC,KAAK,CAACd,GAAG,CAAC,KAAK,KAAK,EAAE;MACjC,OAAOY,IAAI,CACTmB,gBAAU,CAACC,OAAO,CAACf,iBAAW,CAAC2B,mBAAmB,EAAEC,oBAAc,CAACC,YAAY,CACjF,CAAC;IACH,CAAC,MAAM;MACL,OAAOlC,IAAI,CAACmB,gBAAU,CAACC,OAAO,CAACf,iBAAW,CAAC8B,cAAc,EAAEC,eAAS,CAACC,aAAa,CAAC,CAAC;IACtF;EACF,CACF,CAAC;AACH"}
package/jest.config.js CHANGED
@@ -1,10 +1,3 @@
1
1
  const config = require('../../jest/config');
2
2
 
3
- module.exports = Object.assign({}, config, {
4
- coverageThreshold: {
5
- global: {
6
- // FIXME: increase to 90
7
- lines: 60,
8
- },
9
- },
10
- });
3
+ module.exports = Object.assign({}, config, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/api",
3
- "version": "6.0.0-6-next.59",
3
+ "version": "7.0.0-next-7.8",
4
4
  "description": "loaders logic",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -25,34 +25,32 @@
25
25
  "verdaccio"
26
26
  ],
27
27
  "engines": {
28
- "node": ">=14",
29
- "npm": ">=6"
28
+ "node": ">=18"
30
29
  },
31
30
  "license": "MIT",
32
31
  "dependencies": {
33
- "@verdaccio/auth": "6.0.0-6-next.55",
34
- "@verdaccio/config": "6.0.0-6-next.76",
35
- "@verdaccio/core": "6.0.0-6-next.76",
36
- "@verdaccio/logger": "6.0.0-6-next.44",
37
- "@verdaccio/middleware": "6.0.0-6-next.55",
38
- "@verdaccio/store": "6.0.0-6-next.56",
39
- "@verdaccio/utils": "6.0.0-6-next.44",
32
+ "@verdaccio/auth": "7.0.0-next-7.8",
33
+ "@verdaccio/config": "7.0.0-next-7.8",
34
+ "@verdaccio/core": "7.0.0-next-7.8",
35
+ "@verdaccio/logger": "7.0.0-next-7.8",
36
+ "@verdaccio/middleware": "7.0.0-next-7.8",
37
+ "@verdaccio/store": "7.0.0-next-7.8",
38
+ "@verdaccio/utils": "7.0.0-next-7.8",
40
39
  "abortcontroller-polyfill": "1.7.5",
41
- "cookies": "0.8.0",
42
- "debug": "4.3.4",
43
40
  "body-parser": "1.20.2",
41
+ "cookies": "0.9.0",
42
+ "debug": "4.3.4",
44
43
  "express": "4.18.2",
45
44
  "lodash": "4.17.21",
46
45
  "mime": "2.6.0",
47
46
  "semver": "7.5.4"
48
47
  },
49
48
  "devDependencies": {
50
- "@verdaccio/server": "6.0.0-6-next.65",
51
- "@verdaccio/types": "11.0.0-6-next.25",
52
- "@verdaccio/test-helper": "2.0.0-6-next.8",
53
- "supertest": "6.3.3",
54
- "nock": "13.2.9",
55
- "mockdate": "3.0.5"
49
+ "@verdaccio/test-helper": "3.0.0-next.1",
50
+ "@verdaccio/types": "12.0.0-next.2",
51
+ "mockdate": "3.0.5",
52
+ "nock": "13.5.1",
53
+ "supertest": "6.3.4"
56
54
  },
57
55
  "funding": {
58
56
  "type": "opencollective",
package/src/index.ts CHANGED
@@ -43,7 +43,6 @@ export default function (config: Config, auth: Auth, storage: Storage): Router {
43
43
  app.param('org_couchdb_user', match(/^org\.couchdb\.user:/));
44
44
  app.use(auth.apiJWTmiddleware());
45
45
  app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' }));
46
- // @ts-ignore
47
46
  app.use(antiLoop(config));
48
47
  // encode / in a scoped package name to be matched as a single parameter in routes
49
48
  app.use(encodeScopePackage);
package/src/publish.ts CHANGED
@@ -196,10 +196,10 @@ export function publishPackage(storage: Storage): any {
196
196
  requestOptions: {
197
197
  host: req.hostname,
198
198
  protocol: req.protocol,
199
- // @ts-ignore
200
- headers: req.headers,
199
+ headers: req.headers as { [key: string]: string },
201
200
  username,
202
201
  },
202
+ uplinksLook: false,
203
203
  });
204
204
 
205
205
  res.status(HTTP_STATUS.CREATED);
package/src/v1/profile.ts CHANGED
@@ -81,15 +81,17 @@ export default function (route: Router, auth: Auth, config: Config): void {
81
81
  /* eslint new-cap:off */
82
82
  }
83
83
 
84
+ if (_.isEmpty(password.old)) {
85
+ return next(errorUtils.getBadRequest('old password is required'));
86
+ }
87
+
84
88
  auth.changePassword(
85
89
  name,
86
90
  password.old,
87
91
  password.new,
88
92
  (err, isUpdated): $NextFunctionVer => {
89
93
  if (_.isNull(err) === false) {
90
- return next(
91
- errorUtils.getCode(err.status, err.message) || errorUtils.getConflict(err.message)
92
- );
94
+ return next(errorUtils.getForbidden(err.message));
93
95
  }
94
96
 
95
97
  if (isUpdated) {
@@ -0,0 +1,27 @@
1
+ auth:
2
+ htpasswd:
3
+ file: ./htpasswd-profile
4
+ web:
5
+ enable: true
6
+ title: verdaccio
7
+
8
+ uplinks:
9
+
10
+ log: { type: stdout, format: pretty, level: trace }
11
+
12
+ packages:
13
+ '@*/*':
14
+ access: $all
15
+ publish: $all
16
+ unpublish: $all
17
+ proxy: npmjs
18
+ 'verdaccio':
19
+ access: $all
20
+ publish: $all
21
+ '**':
22
+ access: $all
23
+ publish: $all
24
+ unpublish: $all
25
+ proxy: npmjs
26
+
27
+ _debug: true
@@ -26,8 +26,8 @@ describe('package', () => {
26
26
  });
27
27
 
28
28
  test.each([
29
- ['foo', 'foo-1.0.0.tgz'],
30
- ['@scope/foo', 'foo-1.0.0.tgz'],
29
+ ['foo2', 'foo2-1.0.0.tgz'],
30
+ ['@scope/foo2', 'foo2-1.0.0.tgz'],
31
31
  ])('should fails if tarball does not exist', async (pkg, fileName) => {
32
32
  await publishVersion(app, pkg, '1.0.1');
33
33
  return await supertest(app)
@@ -0,0 +1,111 @@
1
+ import supertest from 'supertest';
2
+
3
+ import { HEADERS, HEADER_TYPE, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/core';
4
+ import { buildToken } from '@verdaccio/utils';
5
+
6
+ import { createUser, initializeServer } from './_helper';
7
+
8
+ describe('profile ', () => {
9
+ describe('get profile ', () => {
10
+ test('should return Unauthorized if header token is missing', async () => {
11
+ const app = await initializeServer('profile.yaml');
12
+ return supertest(app)
13
+ .get('/-/npm/v1/user')
14
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
15
+ .expect(HTTP_STATUS.UNAUTHORIZED);
16
+ });
17
+
18
+ test('should return user details', async () => {
19
+ const app = await initializeServer('profile.yaml');
20
+ const credentials = { name: 'test', password: 'test' };
21
+ const response = await createUser(app, credentials.name, credentials.password);
22
+ return supertest(app)
23
+ .get('/-/npm/v1/user')
24
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
25
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
26
+ .expect(HTTP_STATUS.OK);
27
+ });
28
+ });
29
+ describe('post profile ', () => {
30
+ test('should return Unauthorized if header token is missing', async () => {
31
+ const app = await initializeServer('profile.yaml');
32
+ return supertest(app)
33
+ .post('/-/npm/v1/user')
34
+ .send({})
35
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
36
+ .expect(HTTP_STATUS.UNAUTHORIZED);
37
+ });
38
+
39
+ test('should return handle to short new password', async () => {
40
+ const app = await initializeServer('profile.yaml');
41
+ const credentials = { name: 'test', password: 'test' };
42
+ const response = await createUser(app, credentials.name, credentials.password);
43
+ return supertest(app)
44
+ .post('/-/npm/v1/user')
45
+ .send({ password: { new: '_' } })
46
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
47
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
48
+ .expect(HTTP_STATUS.UNAUTHORIZED);
49
+ });
50
+
51
+ test('should return handle to missing old password', async () => {
52
+ const app = await initializeServer('profile.yaml');
53
+ const credentials = { name: 'test', password: 'test' };
54
+ const response = await createUser(app, credentials.name, credentials.password);
55
+ return supertest(app)
56
+ .post('/-/npm/v1/user')
57
+ .send({ password: { new: 'fooooo', old: undefined } })
58
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
59
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
60
+ .expect(HTTP_STATUS.BAD_REQUEST);
61
+ });
62
+
63
+ test('should return handle to missing password', async () => {
64
+ const app = await initializeServer('profile.yaml');
65
+ const credentials = { name: 'test', password: 'test' };
66
+ const response = await createUser(app, credentials.name, credentials.password);
67
+ return supertest(app)
68
+ .post('/-/npm/v1/user')
69
+ .send({ another: '_' })
70
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
71
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
72
+ .expect(HTTP_STATUS.INTERNAL_ERROR);
73
+ });
74
+
75
+ test('should return handle change password', async () => {
76
+ const app = await initializeServer('profile.yaml');
77
+ const credentials = { name: 'test', password: 'test' };
78
+ const response = await createUser(app, credentials.name, credentials.password);
79
+ return supertest(app)
80
+ .post('/-/npm/v1/user')
81
+ .send({ password: { new: 'good password_.%#@$@#$@#', old: 'test' } })
82
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
83
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
84
+ .expect(HTTP_STATUS.OK);
85
+ });
86
+
87
+ test('should return handle change password failure', async () => {
88
+ const app = await initializeServer('profile.yaml');
89
+ const credentials = { name: 'test', password: 'test' };
90
+ const response = await createUser(app, credentials.name, credentials.password);
91
+ return supertest(app)
92
+ .post('/-/npm/v1/user')
93
+ .send({ password: { new: 'good password_.%#@$@#$@#', old: 'test_do_not_match' } })
94
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
95
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
96
+ .expect(HTTP_STATUS.FORBIDDEN);
97
+ });
98
+
99
+ test('should handle tfa ( two factor auth) disabled', async () => {
100
+ const app = await initializeServer('profile.yaml');
101
+ const credentials = { name: 'test', password: 'test' };
102
+ const response = await createUser(app, credentials.name, credentials.password);
103
+ return supertest(app)
104
+ .post('/-/npm/v1/user')
105
+ .send({ tfa: '_' })
106
+ .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
107
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
108
+ .expect(HTTP_STATUS.SERVICE_UNAVAILABLE);
109
+ });
110
+ });
111
+ });