@verdaccio/config 9.0.0-next-9.10 → 9.0.0-next-9.11

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/README.md CHANGED
@@ -33,41 +33,125 @@ To start using `@verdaccio/config`, import the `ConfigBuilder` class and begin c
33
33
 
34
34
  ## `ConfigBuilder` constructor
35
35
 
36
- The `ConfigBuilder` class is a helper configuration builder constructor used to programmatically create configuration objects for testing or other purposes.
36
+ The `ConfigBuilder` class is a helper configuration builder constructor used to programmatically create configuration objects for testing or other purposes. All setter methods return `this` for fluent chaining.
37
37
 
38
38
  ```typescript
39
-
40
39
  import { ConfigBuilder } from '@verdaccio/config';
40
+ import { constants } from '@verdaccio/core';
41
+
42
+ const config = ConfigBuilder.build()
43
+ .addStorage('./storage')
44
+ .addSecurity({
45
+ api: {
46
+ jwt: { sign: { expiresIn: '7d' }, verify: {} },
47
+ legacy: false,
48
+ },
49
+ web: {
50
+ sign: { expiresIn: '1h' },
51
+ verify: {},
52
+ },
53
+ })
54
+ .addAuth({
55
+ htpasswd: { file: '.htpasswd' },
56
+ })
57
+ .addUplink('npmjs', { url: 'https://registry.npmjs.org/' })
58
+ .addPackageAccess('@scope/*', {
59
+ access: constants.ROLES.$AUTH,
60
+ publish: constants.ROLES.$AUTH,
61
+ proxy: 'npmjs',
62
+ })
63
+ .addWeb({ title: 'My Registry', darkMode: true, primaryColor: '#4b5e40' })
64
+ .addLogger({ type: 'stdout', format: 'pretty', level: 'info' })
65
+ .addMiddlewares({ audit: { enabled: true } })
66
+ .addFlags({ changePassword: true })
67
+ .addI18n({ web: 'en-US' });
41
68
 
42
- // Create a new configuration builder instance
43
- const config = ConfigBuilder.build({ security: { api: { legacy: false } } });
44
-
45
- // Add package access configuration
46
- configBuilder.addPackageAccess('@scope/*', { access: 'read', publish: 'write' });
47
-
48
- // Add an uplink configuration
49
- configBuilder.addUplink('npmjs', { url: 'https://registry.npmjs.org/' });
69
+ // Get the configuration object
70
+ const configObj = config.getConfig();
50
71
 
51
- // Add security configuration
52
- configBuilder.addSecurity({ allow_offline: true });
72
+ // Get the configuration as YAML text
73
+ const configYaml = config.getAsYaml();
74
+ ```
53
75
 
54
- // Get the configuration object
55
- const config = configBuilder.getConfig();
76
+ You can also pass an initial partial configuration to `ConfigBuilder.build()`:
56
77
 
57
- // Get the configuration yaml text
58
- const config = configBuilder.getAsYaml();
78
+ ```typescript
79
+ const config = ConfigBuilder.build({ security: { api: { legacy: false } } });
59
80
  ```
60
81
 
61
82
  ### Methods
62
83
 
63
- - `addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml)`: Adds package access configuration.
84
+ - `addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml)`: Adds package access configuration for a pattern.
64
85
  - `addUplink(id: string, uplink: UpLinkConf)`: Adds an uplink configuration.
65
- - `addSecurity(security: Partial<Security>)`: Adds security configuration.
66
- - `addAuth(auth: Partial<AuthConf>)`: Adds authentication configuration.
67
- - `addLogger(log: LoggerConfItem)`: Adds logger configuration.
68
- - `addStorage(storage: string | object)`: Adds storage configuration.
86
+ - `addSecurity(security: Partial<Security>)`: Merges security configuration.
87
+ - `addAuth(auth: Partial<AuthConf>)`: Merges authentication configuration.
88
+ - `addLogger(log: LoggerConfigItem)`: Sets logger configuration.
89
+ - `addServer(server: Partial<ServerSettingsConf>)`: Merges server settings.
90
+ - `addStorage(storage: string | object)`: Sets storage path (string) or store plugin configuration (object).
91
+ - `addWeb(web: Partial<WebConf>)`: Merges web UI configuration.
92
+ - `addListen(listen: ListenAddress)`: Sets listen address.
93
+ - `addHttps(https: HttpsConf)`: Sets HTTPS configuration.
94
+ - `addPublish(publish: Partial<PublishOptions>)`: Merges publish options.
95
+ - `addFlags(flags: Partial<FlagsConfig>)`: Merges feature flags.
96
+ - `addNotify(notify: Notifications | Notifications[])`: Sets notification hooks.
97
+ - `addMiddlewares(middlewares: any)`: Merges middlewares configuration.
98
+ - `addFilters(filters: any)`: Merges filters configuration.
99
+ - `addMaxBodySize(maxBodySize: string)`: Sets the max body size (e.g., `'50mb'`).
100
+ - `addUserRateLimit(rateLimit: RateLimit)`: Merges user rate limit settings.
101
+ - `addUrlPrefix(urlPrefix: string)`: Sets URL prefix.
102
+ - `addI18n(i18n: ConfigYaml['i18n'])`: Sets i18n configuration.
103
+ - `addUserAgent(userAgent: string)`: Sets the user agent string.
104
+ - `addHttpProxy(httpProxy: string)`: Sets the HTTP proxy.
105
+ - `addHttpsProxy(httpsProxy: string)`: Sets the HTTPS proxy.
106
+ - `addNoProxy(noProxy: string)`: Sets the no-proxy exclusion list.
107
+ - `addPlugins(plugins: string)`: Sets the plugins directory path.
108
+ - `addNotifications(notifications: Notifications)`: Sets notifications configuration.
69
109
  - `getConfig(): ConfigYaml`: Retrieves the configuration object.
70
- - `getAsYaml(): string`: Retrieves the configuration object as YAML format.
110
+ - `getAsYaml(): string`: Retrieves the configuration as YAML format.
111
+
112
+ ## Using `ConfigBuilder` with `runServer`
113
+
114
+ The `ConfigBuilder` pairs with `runServer` from the `verdaccio` package to start a registry programmatically:
115
+
116
+ ```typescript
117
+ import { runServer } from 'verdaccio';
118
+
119
+ import { ConfigBuilder } from '@verdaccio/config';
120
+ import { constants } from '@verdaccio/core';
121
+
122
+ const config = ConfigBuilder.build()
123
+ .addStorage('./storage')
124
+ .addAuth({ htpasswd: { file: '.htpasswd' } })
125
+ .addUplink('npmjs', { url: 'https://registry.npmjs.org/' })
126
+ .addPackageAccess(constants.PACKAGE_ACCESS.SCOPE, {
127
+ access: constants.ROLES.$AUTH,
128
+ publish: constants.ROLES.$AUTH,
129
+ proxy: 'npmjs',
130
+ })
131
+ .addPackageAccess(constants.PACKAGE_ACCESS.ALL, {
132
+ access: constants.ROLES.$ALL,
133
+ publish: constants.ROLES.$AUTH,
134
+ proxy: 'npmjs',
135
+ })
136
+ .addWeb({ title: 'My Registry', darkMode: true })
137
+ .addMiddlewares({ audit: { enabled: true } })
138
+ .addLogger({ type: 'stdout', format: 'pretty', level: 'info' })
139
+ .addSecurity({
140
+ api: { jwt: { sign: { expiresIn: '7d' }, verify: {} }, legacy: false },
141
+ web: { sign: { expiresIn: '1h' }, verify: {} },
142
+ })
143
+ .addI18n({ web: 'en-US' });
144
+
145
+ runServer(config.getConfig())
146
+ .then((app) => {
147
+ app.listen(4873, () => {
148
+ console.log('verdaccio running on port 4873');
149
+ });
150
+ })
151
+ .catch((err) => {
152
+ console.error(err);
153
+ });
154
+ ```
71
155
 
72
156
  ## `getDefaultConfig`
73
157
 
@@ -1,4 +1,4 @@
1
- import { AuthConf, ConfigYaml, LoggerConfigItem, PackageAccessYaml, Security, ServerSettingsConf, UpLinkConf } from '@verdaccio/types';
1
+ import { AuthConf, ConfigYaml, FlagsConfig, HttpsConf, ListenAddress, LoggerConfigItem, Notifications, PackageAccessYaml, PublishOptions, RateLimit, Security, ServerSettingsConf, UpLinkConf, WebConf } from '@verdaccio/types';
2
2
  /**
3
3
  * Helper configuration builder constructor, used to build the configuration for testing or
4
4
  * programatically creating a configuration.
@@ -14,6 +14,24 @@ export default class ConfigBuilder {
14
14
  addLogger(log: LoggerConfigItem): this;
15
15
  addServer(server: Partial<ServerSettingsConf>): this;
16
16
  addStorage(storage: string | object): this;
17
+ addWeb(web: Partial<WebConf>): this;
18
+ addListen(listen: ListenAddress): this;
19
+ addHttps(https: HttpsConf): this;
20
+ addPublish(publish: Partial<PublishOptions>): this;
21
+ addFlags(flags: Partial<FlagsConfig>): this;
22
+ addNotify(notify: Notifications | Notifications[]): this;
23
+ addMiddlewares(middlewares: any): this;
24
+ addFilters(filters: any): this;
25
+ addMaxBodySize(maxBodySize: string): this;
26
+ addUserRateLimit(rateLimit: RateLimit): this;
27
+ addUrlPrefix(urlPrefix: string): this;
28
+ addI18n(i18n: ConfigYaml['i18n']): this;
29
+ addUserAgent(userAgent: string): this;
30
+ addHttpProxy(httpProxy: string): this;
31
+ addHttpsProxy(httpsProxy: string): this;
32
+ addNoProxy(noProxy: string): this;
33
+ addPlugins(plugins: string): this;
34
+ addNotifications(notifications: Notifications): this;
17
35
  getConfig(): ConfigYaml;
18
36
  getAsYaml(): string;
19
37
  }
package/build/builder.js CHANGED
@@ -10,11 +10,11 @@ let lodash_es = require("lodash-es");
10
10
  var ConfigBuilder = class ConfigBuilder {
11
11
  config;
12
12
  constructor(config) {
13
- this.config = (0, lodash_es.merge)(config, {
13
+ this.config = (0, lodash_es.merge)({
14
14
  uplinks: {},
15
15
  packages: {},
16
16
  security: {}
17
- });
17
+ }, config);
18
18
  }
19
19
  static build(config) {
20
20
  return new ConfigBuilder(config);
@@ -48,6 +48,78 @@ var ConfigBuilder = class ConfigBuilder {
48
48
  else this.config.store = storage;
49
49
  return this;
50
50
  }
51
+ addWeb(web) {
52
+ this.config.web = (0, lodash_es.merge)(this.config.web, web);
53
+ return this;
54
+ }
55
+ addListen(listen) {
56
+ this.config.listen = listen;
57
+ return this;
58
+ }
59
+ addHttps(https) {
60
+ this.config.https = https;
61
+ return this;
62
+ }
63
+ addPublish(publish) {
64
+ this.config.publish = (0, lodash_es.merge)(this.config.publish, publish);
65
+ return this;
66
+ }
67
+ addFlags(flags) {
68
+ this.config.flags = (0, lodash_es.merge)(this.config.flags, flags);
69
+ return this;
70
+ }
71
+ addNotify(notify) {
72
+ this.config.notify = notify;
73
+ return this;
74
+ }
75
+ addMiddlewares(middlewares) {
76
+ this.config.middlewares = (0, lodash_es.merge)(this.config.middlewares, middlewares);
77
+ return this;
78
+ }
79
+ addFilters(filters) {
80
+ this.config.filters = (0, lodash_es.merge)(this.config.filters, filters);
81
+ return this;
82
+ }
83
+ addMaxBodySize(maxBodySize) {
84
+ this.config.max_body_size = maxBodySize;
85
+ return this;
86
+ }
87
+ addUserRateLimit(rateLimit) {
88
+ this.config.userRateLimit = (0, lodash_es.merge)(this.config.userRateLimit, rateLimit);
89
+ return this;
90
+ }
91
+ addUrlPrefix(urlPrefix) {
92
+ this.config.url_prefix = urlPrefix;
93
+ return this;
94
+ }
95
+ addI18n(i18n) {
96
+ this.config.i18n = i18n;
97
+ return this;
98
+ }
99
+ addUserAgent(userAgent) {
100
+ this.config.user_agent = userAgent;
101
+ return this;
102
+ }
103
+ addHttpProxy(httpProxy) {
104
+ this.config.http_proxy = httpProxy;
105
+ return this;
106
+ }
107
+ addHttpsProxy(httpsProxy) {
108
+ this.config.https_proxy = httpsProxy;
109
+ return this;
110
+ }
111
+ addNoProxy(noProxy) {
112
+ this.config.no_proxy = noProxy;
113
+ return this;
114
+ }
115
+ addPlugins(plugins) {
116
+ this.config.plugins = plugins;
117
+ return this;
118
+ }
119
+ addNotifications(notifications) {
120
+ this.config.notifications = notifications;
121
+ return this;
122
+ }
51
123
  getConfig() {
52
124
  return this.config;
53
125
  }
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import { merge } from 'lodash-es';\n\nimport type {\n AuthConf,\n ConfigYaml,\n LoggerConfigItem,\n PackageAccessYaml,\n Security,\n ServerSettingsConf,\n UpLinkConf,\n} from '@verdaccio/types';\n\nimport { fromJStoYAML } from '.';\n\n/**\n * Helper configuration builder constructor, used to build the configuration for testing or\n * programatically creating a configuration.\n */\nexport default class ConfigBuilder {\n private config: ConfigYaml;\n\n public constructor(config?: Partial<ConfigYaml>) {\n this.config = merge(config, { uplinks: {}, packages: {}, security: {} });\n }\n\n public static build(config?: Partial<ConfigYaml>): ConfigBuilder {\n return new ConfigBuilder(config);\n }\n\n public addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml) {\n // @ts-ignore\n this.config.packages[pattern] = pkgAccess;\n return this;\n }\n\n public addUplink(id: string, uplink: UpLinkConf) {\n this.config.uplinks[id] = uplink;\n return this;\n }\n\n public addSecurity(security: Partial<Security>) {\n this.config.security = merge(this.config.security, security);\n return this;\n }\n\n public addAuth(auth: Partial<AuthConf>) {\n this.config.auth = merge(this.config.auth, auth);\n return this;\n }\n\n public addLogger(log: LoggerConfigItem) {\n this.config.log = log;\n return this;\n }\n\n public addServer(server: Partial<ServerSettingsConf>) {\n this.config.server = merge(this.config.server, server);\n return this;\n }\n\n public addStorage(storage: string | object) {\n if (typeof storage === 'string') {\n this.config.storage = storage;\n } else {\n this.config.store = storage;\n }\n return this;\n }\n\n public getConfig(): ConfigYaml {\n return this.config;\n }\n\n public getAsYaml(): string {\n return fromJStoYAML(this.config) as string;\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAqB,gBAArB,MAAqB,cAAc;CACjC;CAEA,YAAmB,QAA8B;AAC/C,OAAK,UAAA,GAAA,UAAA,OAAe,QAAQ;GAAE,SAAS,EAAE;GAAE,UAAU,EAAE;GAAE,UAAU,EAAE;GAAE,CAAC;;CAG1E,OAAc,MAAM,QAA6C;AAC/D,SAAO,IAAI,cAAc,OAAO;;CAGlC,iBAAwB,SAAiB,WAA8B;AAErE,OAAK,OAAO,SAAS,WAAW;AAChC,SAAO;;CAGT,UAAiB,IAAY,QAAoB;AAC/C,OAAK,OAAO,QAAQ,MAAM;AAC1B,SAAO;;CAGT,YAAmB,UAA6B;AAC9C,OAAK,OAAO,YAAA,GAAA,UAAA,OAAiB,KAAK,OAAO,UAAU,SAAS;AAC5D,SAAO;;CAGT,QAAe,MAAyB;AACtC,OAAK,OAAO,QAAA,GAAA,UAAA,OAAa,KAAK,OAAO,MAAM,KAAK;AAChD,SAAO;;CAGT,UAAiB,KAAuB;AACtC,OAAK,OAAO,MAAM;AAClB,SAAO;;CAGT,UAAiB,QAAqC;AACpD,OAAK,OAAO,UAAA,GAAA,UAAA,OAAe,KAAK,OAAO,QAAQ,OAAO;AACtD,SAAO;;CAGT,WAAkB,SAA0B;AAC1C,MAAI,OAAO,YAAY,SACrB,MAAK,OAAO,UAAU;MAEtB,MAAK,OAAO,QAAQ;AAEtB,SAAO;;CAGT,YAA+B;AAC7B,SAAO,KAAK;;CAGd,YAA2B;AACzB,SAAO,cAAA,aAAa,KAAK,OAAO"}
1
+ {"version":3,"file":"builder.js","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import { merge } from 'lodash-es';\n\nimport type {\n AuthConf,\n ConfigYaml,\n FlagsConfig,\n HttpsConf,\n ListenAddress,\n LoggerConfigItem,\n Notifications,\n PackageAccessYaml,\n PublishOptions,\n RateLimit,\n Security,\n ServerSettingsConf,\n UpLinkConf,\n WebConf,\n} from '@verdaccio/types';\n\nimport { fromJStoYAML } from '.';\n\n/**\n * Helper configuration builder constructor, used to build the configuration for testing or\n * programatically creating a configuration.\n */\nexport default class ConfigBuilder {\n private config: ConfigYaml;\n\n public constructor(config?: Partial<ConfigYaml>) {\n this.config = merge({ uplinks: {}, packages: {}, security: {} }, config);\n }\n\n public static build(config?: Partial<ConfigYaml>): ConfigBuilder {\n return new ConfigBuilder(config);\n }\n\n public addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml) {\n // PackageAccessYaml uses string for publish/access while PackageAccess uses string[]\n // The config parser normalizes these later, so the cast is safe here\n (this.config.packages as Record<string, PackageAccessYaml>)[pattern] = pkgAccess;\n return this;\n }\n\n public addUplink(id: string, uplink: UpLinkConf) {\n this.config.uplinks[id] = uplink;\n return this;\n }\n\n public addSecurity(security: Partial<Security>) {\n this.config.security = merge(this.config.security, security);\n return this;\n }\n\n public addAuth(auth: Partial<AuthConf>) {\n this.config.auth = merge(this.config.auth, auth);\n return this;\n }\n\n public addLogger(log: LoggerConfigItem) {\n this.config.log = log;\n return this;\n }\n\n public addServer(server: Partial<ServerSettingsConf>) {\n this.config.server = merge(this.config.server, server);\n return this;\n }\n\n public addStorage(storage: string | object) {\n if (typeof storage === 'string') {\n this.config.storage = storage;\n } else {\n this.config.store = storage;\n }\n return this;\n }\n\n public addWeb(web: Partial<WebConf>) {\n this.config.web = merge(this.config.web, web);\n return this;\n }\n\n public addListen(listen: ListenAddress) {\n this.config.listen = listen;\n return this;\n }\n\n public addHttps(https: HttpsConf) {\n this.config.https = https;\n return this;\n }\n\n public addPublish(publish: Partial<PublishOptions>) {\n this.config.publish = merge(this.config.publish, publish);\n return this;\n }\n\n public addFlags(flags: Partial<FlagsConfig>) {\n this.config.flags = merge(this.config.flags, flags);\n return this;\n }\n\n public addNotify(notify: Notifications | Notifications[]) {\n this.config.notify = notify;\n return this;\n }\n\n public addMiddlewares(middlewares: any) {\n this.config.middlewares = merge(this.config.middlewares, middlewares);\n return this;\n }\n\n public addFilters(filters: any) {\n this.config.filters = merge(this.config.filters, filters);\n return this;\n }\n\n public addMaxBodySize(maxBodySize: string) {\n this.config.max_body_size = maxBodySize;\n return this;\n }\n\n public addUserRateLimit(rateLimit: RateLimit) {\n this.config.userRateLimit = merge(this.config.userRateLimit, rateLimit);\n return this;\n }\n\n public addUrlPrefix(urlPrefix: string) {\n this.config.url_prefix = urlPrefix;\n return this;\n }\n\n public addI18n(i18n: ConfigYaml['i18n']) {\n this.config.i18n = i18n;\n return this;\n }\n\n public addUserAgent(userAgent: string) {\n this.config.user_agent = userAgent;\n return this;\n }\n\n public addHttpProxy(httpProxy: string) {\n this.config.http_proxy = httpProxy;\n return this;\n }\n\n public addHttpsProxy(httpsProxy: string) {\n this.config.https_proxy = httpsProxy;\n return this;\n }\n\n public addNoProxy(noProxy: string) {\n this.config.no_proxy = noProxy;\n return this;\n }\n\n public addPlugins(plugins: string) {\n this.config.plugins = plugins;\n return this;\n }\n\n public addNotifications(notifications: Notifications) {\n this.config.notifications = notifications;\n return this;\n }\n\n public getConfig(): ConfigYaml {\n return this.config;\n }\n\n public getAsYaml(): string {\n return fromJStoYAML(this.config) as string;\n }\n}\n"],"mappings":";;;;;;;;;AAyBA,IAAqB,gBAArB,MAAqB,cAAc;CACjC;CAEA,YAAmB,QAA8B;AAC/C,OAAK,UAAA,GAAA,UAAA,OAAe;GAAE,SAAS,EAAE;GAAE,UAAU,EAAE;GAAE,UAAU,EAAE;GAAE,EAAE,OAAO;;CAG1E,OAAc,MAAM,QAA6C;AAC/D,SAAO,IAAI,cAAc,OAAO;;CAGlC,iBAAwB,SAAiB,WAA8B;AAGpE,OAAK,OAAO,SA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AQ;AACzD,SAAO;;CAGT,eAAsB,aAAqB;AACzC,OAAK,OAAO,gBAAgB;AAC5B,SAAO;;CAGT,iBAAwB,WAAsB;AAC5C,OAAK,OAAO,iBAAA,GAAA,UAAA,OAAsB,KAAK,OAAO,eAAe,UAAU;AACvE,SAAO;;CAGT,aAAoB,WAAmB;AACrC,OAAK,OAAO,aAAa;AACzB,SAAO;;CAGT,QAAe,MAA0B;AACvC,OAAK,OAAO,OAAO;AACnB,SAAO;;CAGT,aAAoB,WAAmB;AACrC,OAAK,OAAO,aAAa;AACzB,SAAO;;CAGT,aAAoB,WAAmB;AACrC,OAAK,OAAO,aAAa;AACzB,SAAO;;CAGT,cAAqB,YAAoB;AACvC,OAAK,OAAO,cAAc;AAC1B,SAAO;;CAGT,WAAkB,SAAiB;AACjC,OAAK,OAAO,WAAW;AACvB,SAAO;;CAGT,WAAkB,SAAiB;AACjC,OAAK,OAAO,UAAU;AACtB,SAAO;;CAGT,iBAAwB,eAA8B;AACpD,OAAK,OAAO,gBAAgB;AAC5B,SAAO;;CAGT,YAA+B;AAC7B,SAAO,KAAK;;CAGd,YAA2B;AACzB,SAAO,cAAA,aAAa,KAAK,OAAO"}
package/build/builder.mjs CHANGED
@@ -9,11 +9,11 @@ import { merge } from "lodash-es";
9
9
  var ConfigBuilder = class ConfigBuilder {
10
10
  config;
11
11
  constructor(config) {
12
- this.config = merge(config, {
12
+ this.config = merge({
13
13
  uplinks: {},
14
14
  packages: {},
15
15
  security: {}
16
- });
16
+ }, config);
17
17
  }
18
18
  static build(config) {
19
19
  return new ConfigBuilder(config);
@@ -47,6 +47,78 @@ var ConfigBuilder = class ConfigBuilder {
47
47
  else this.config.store = storage;
48
48
  return this;
49
49
  }
50
+ addWeb(web) {
51
+ this.config.web = merge(this.config.web, web);
52
+ return this;
53
+ }
54
+ addListen(listen) {
55
+ this.config.listen = listen;
56
+ return this;
57
+ }
58
+ addHttps(https) {
59
+ this.config.https = https;
60
+ return this;
61
+ }
62
+ addPublish(publish) {
63
+ this.config.publish = merge(this.config.publish, publish);
64
+ return this;
65
+ }
66
+ addFlags(flags) {
67
+ this.config.flags = merge(this.config.flags, flags);
68
+ return this;
69
+ }
70
+ addNotify(notify) {
71
+ this.config.notify = notify;
72
+ return this;
73
+ }
74
+ addMiddlewares(middlewares) {
75
+ this.config.middlewares = merge(this.config.middlewares, middlewares);
76
+ return this;
77
+ }
78
+ addFilters(filters) {
79
+ this.config.filters = merge(this.config.filters, filters);
80
+ return this;
81
+ }
82
+ addMaxBodySize(maxBodySize) {
83
+ this.config.max_body_size = maxBodySize;
84
+ return this;
85
+ }
86
+ addUserRateLimit(rateLimit) {
87
+ this.config.userRateLimit = merge(this.config.userRateLimit, rateLimit);
88
+ return this;
89
+ }
90
+ addUrlPrefix(urlPrefix) {
91
+ this.config.url_prefix = urlPrefix;
92
+ return this;
93
+ }
94
+ addI18n(i18n) {
95
+ this.config.i18n = i18n;
96
+ return this;
97
+ }
98
+ addUserAgent(userAgent) {
99
+ this.config.user_agent = userAgent;
100
+ return this;
101
+ }
102
+ addHttpProxy(httpProxy) {
103
+ this.config.http_proxy = httpProxy;
104
+ return this;
105
+ }
106
+ addHttpsProxy(httpsProxy) {
107
+ this.config.https_proxy = httpsProxy;
108
+ return this;
109
+ }
110
+ addNoProxy(noProxy) {
111
+ this.config.no_proxy = noProxy;
112
+ return this;
113
+ }
114
+ addPlugins(plugins) {
115
+ this.config.plugins = plugins;
116
+ return this;
117
+ }
118
+ addNotifications(notifications) {
119
+ this.config.notifications = notifications;
120
+ return this;
121
+ }
50
122
  getConfig() {
51
123
  return this.config;
52
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"builder.mjs","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import { merge } from 'lodash-es';\n\nimport type {\n AuthConf,\n ConfigYaml,\n LoggerConfigItem,\n PackageAccessYaml,\n Security,\n ServerSettingsConf,\n UpLinkConf,\n} from '@verdaccio/types';\n\nimport { fromJStoYAML } from '.';\n\n/**\n * Helper configuration builder constructor, used to build the configuration for testing or\n * programatically creating a configuration.\n */\nexport default class ConfigBuilder {\n private config: ConfigYaml;\n\n public constructor(config?: Partial<ConfigYaml>) {\n this.config = merge(config, { uplinks: {}, packages: {}, security: {} });\n }\n\n public static build(config?: Partial<ConfigYaml>): ConfigBuilder {\n return new ConfigBuilder(config);\n }\n\n public addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml) {\n // @ts-ignore\n this.config.packages[pattern] = pkgAccess;\n return this;\n }\n\n public addUplink(id: string, uplink: UpLinkConf) {\n this.config.uplinks[id] = uplink;\n return this;\n }\n\n public addSecurity(security: Partial<Security>) {\n this.config.security = merge(this.config.security, security);\n return this;\n }\n\n public addAuth(auth: Partial<AuthConf>) {\n this.config.auth = merge(this.config.auth, auth);\n return this;\n }\n\n public addLogger(log: LoggerConfigItem) {\n this.config.log = log;\n return this;\n }\n\n public addServer(server: Partial<ServerSettingsConf>) {\n this.config.server = merge(this.config.server, server);\n return this;\n }\n\n public addStorage(storage: string | object) {\n if (typeof storage === 'string') {\n this.config.storage = storage;\n } else {\n this.config.store = storage;\n }\n return this;\n }\n\n public getConfig(): ConfigYaml {\n return this.config;\n }\n\n public getAsYaml(): string {\n return fromJStoYAML(this.config) as string;\n }\n}\n"],"mappings":";;;;;;;;AAkBA,IAAqB,gBAArB,MAAqB,cAAc;CACjC;CAEA,YAAmB,QAA8B;AAC/C,OAAK,SAAS,MAAM,QAAQ;GAAE,SAAS,EAAE;GAAE,UAAU,EAAE;GAAE,UAAU,EAAE;GAAE,CAAC;;CAG1E,OAAc,MAAM,QAA6C;AAC/D,SAAO,IAAI,cAAc,OAAO;;CAGlC,iBAAwB,SAAiB,WAA8B;AAErE,OAAK,OAAO,SAAS,WAAW;AAChC,SAAO;;CAGT,UAAiB,IAAY,QAAoB;AAC/C,OAAK,OAAO,QAAQ,MAAM;AAC1B,SAAO;;CAGT,YAAmB,UAA6B;AAC9C,OAAK,OAAO,WAAW,MAAM,KAAK,OAAO,UAAU,SAAS;AAC5D,SAAO;;CAGT,QAAe,MAAyB;AACtC,OAAK,OAAO,OAAO,MAAM,KAAK,OAAO,MAAM,KAAK;AAChD,SAAO;;CAGT,UAAiB,KAAuB;AACtC,OAAK,OAAO,MAAM;AAClB,SAAO;;CAGT,UAAiB,QAAqC;AACpD,OAAK,OAAO,SAAS,MAAM,KAAK,OAAO,QAAQ,OAAO;AACtD,SAAO;;CAGT,WAAkB,SAA0B;AAC1C,MAAI,OAAO,YAAY,SACrB,MAAK,OAAO,UAAU;MAEtB,MAAK,OAAO,QAAQ;AAEtB,SAAO;;CAGT,YAA+B;AAC7B,SAAO,KAAK;;CAGd,YAA2B;AACzB,SAAO,aAAa,KAAK,OAAO"}
1
+ {"version":3,"file":"builder.mjs","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import { merge } from 'lodash-es';\n\nimport type {\n AuthConf,\n ConfigYaml,\n FlagsConfig,\n HttpsConf,\n ListenAddress,\n LoggerConfigItem,\n Notifications,\n PackageAccessYaml,\n PublishOptions,\n RateLimit,\n Security,\n ServerSettingsConf,\n UpLinkConf,\n WebConf,\n} from '@verdaccio/types';\n\nimport { fromJStoYAML } from '.';\n\n/**\n * Helper configuration builder constructor, used to build the configuration for testing or\n * programatically creating a configuration.\n */\nexport default class ConfigBuilder {\n private config: ConfigYaml;\n\n public constructor(config?: Partial<ConfigYaml>) {\n this.config = merge({ uplinks: {}, packages: {}, security: {} }, config);\n }\n\n public static build(config?: Partial<ConfigYaml>): ConfigBuilder {\n return new ConfigBuilder(config);\n }\n\n public addPackageAccess(pattern: string, pkgAccess: PackageAccessYaml) {\n // PackageAccessYaml uses string for publish/access while PackageAccess uses string[]\n // The config parser normalizes these later, so the cast is safe here\n (this.config.packages as Record<string, PackageAccessYaml>)[pattern] = pkgAccess;\n return this;\n }\n\n public addUplink(id: string, uplink: UpLinkConf) {\n this.config.uplinks[id] = uplink;\n return this;\n }\n\n public addSecurity(security: Partial<Security>) {\n this.config.security = merge(this.config.security, security);\n return this;\n }\n\n public addAuth(auth: Partial<AuthConf>) {\n this.config.auth = merge(this.config.auth, auth);\n return this;\n }\n\n public addLogger(log: LoggerConfigItem) {\n this.config.log = log;\n return this;\n }\n\n public addServer(server: Partial<ServerSettingsConf>) {\n this.config.server = merge(this.config.server, server);\n return this;\n }\n\n public addStorage(storage: string | object) {\n if (typeof storage === 'string') {\n this.config.storage = storage;\n } else {\n this.config.store = storage;\n }\n return this;\n }\n\n public addWeb(web: Partial<WebConf>) {\n this.config.web = merge(this.config.web, web);\n return this;\n }\n\n public addListen(listen: ListenAddress) {\n this.config.listen = listen;\n return this;\n }\n\n public addHttps(https: HttpsConf) {\n this.config.https = https;\n return this;\n }\n\n public addPublish(publish: Partial<PublishOptions>) {\n this.config.publish = merge(this.config.publish, publish);\n return this;\n }\n\n public addFlags(flags: Partial<FlagsConfig>) {\n this.config.flags = merge(this.config.flags, flags);\n return this;\n }\n\n public addNotify(notify: Notifications | Notifications[]) {\n this.config.notify = notify;\n return this;\n }\n\n public addMiddlewares(middlewares: any) {\n this.config.middlewares = merge(this.config.middlewares, middlewares);\n return this;\n }\n\n public addFilters(filters: any) {\n this.config.filters = merge(this.config.filters, filters);\n return this;\n }\n\n public addMaxBodySize(maxBodySize: string) {\n this.config.max_body_size = maxBodySize;\n return this;\n }\n\n public addUserRateLimit(rateLimit: RateLimit) {\n this.config.userRateLimit = merge(this.config.userRateLimit, rateLimit);\n return this;\n }\n\n public addUrlPrefix(urlPrefix: string) {\n this.config.url_prefix = urlPrefix;\n return this;\n }\n\n public addI18n(i18n: ConfigYaml['i18n']) {\n this.config.i18n = i18n;\n return this;\n }\n\n public addUserAgent(userAgent: string) {\n this.config.user_agent = userAgent;\n return this;\n }\n\n public addHttpProxy(httpProxy: string) {\n this.config.http_proxy = httpProxy;\n return this;\n }\n\n public addHttpsProxy(httpsProxy: string) {\n this.config.https_proxy = httpsProxy;\n return this;\n }\n\n public addNoProxy(noProxy: string) {\n this.config.no_proxy = noProxy;\n return this;\n }\n\n public addPlugins(plugins: string) {\n this.config.plugins = plugins;\n return this;\n }\n\n public addNotifications(notifications: Notifications) {\n this.config.notifications = notifications;\n return this;\n }\n\n public getConfig(): ConfigYaml {\n return this.config;\n }\n\n public getAsYaml(): string {\n return fromJStoYAML(this.config) as string;\n }\n}\n"],"mappings":";;;;;;;;AAyBA,IAAqB,gBAArB,MAAqB,cAAc;CACjC;CAEA,YAAmB,QAA8B;AAC/C,OAAK,SAAS,MAAM;GAAE,SAAS,EAAE;GAAE,UAAU,EAAE;GAAE,UAAU,EAAE;GAAE,EAAE,OAAO;;CAG1E,OAAc,MAAM,QAA6C;AAC/D,SAAO,IAAI,cAAc,OAAO;;CAGlC,iBAAwB,SAAiB,WAA8B;AAGpE,OAAK,OAAO,SAA+C,WAAW;AACvE,SAAO;;CAGT,UAAiB,IAAY,QAAoB;AAC/C,OAAK,OAAO,QAAQ,MAAM;AAC1B,SAAO;;CAGT,YAAmB,UAA6B;AAC9C,OAAK,OAAO,WAAW,MAAM,KAAK,OAAO,UAAU,SAAS;AAC5D,SAAO;;CAGT,QAAe,MAAyB;AACtC,OAAK,OAAO,OAAO,MAAM,KAAK,OAAO,MAAM,KAAK;AAChD,SAAO;;CAGT,UAAiB,KAAuB;AACtC,OAAK,OAAO,MAAM;AAClB,SAAO;;CAGT,UAAiB,QAAqC;AACpD,OAAK,OAAO,SAAS,MAAM,KAAK,OAAO,QAAQ,OAAO;AACtD,SAAO;;CAGT,WAAkB,SAA0B;AAC1C,MAAI,OAAO,YAAY,SACrB,MAAK,OAAO,UAAU;MAEtB,MAAK,OAAO,QAAQ;AAEtB,SAAO;;CAGT,OAAc,KAAuB;AACnC,OAAK,OAAO,MAAM,MAAM,KAAK,OAAO,KAAK,IAAI;AAC7C,SAAO;;CAGT,UAAiB,QAAuB;AACtC,OAAK,OAAO,SAAS;AACrB,SAAO;;CAGT,SAAgB,OAAkB;AAChC,OAAK,OAAO,QAAQ;AACpB,SAAO;;CAGT,WAAkB,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Configuration",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "node": ">=24"
34
34
  },
35
35
  "dependencies": {
36
- "@verdaccio/core": "9.0.0-next-9.10",
36
+ "@verdaccio/core": "9.0.0-next-9.11",
37
37
  "debug": "4.4.3",
38
38
  "js-yaml": "4.1.1",
39
39
  "lodash-es": "4.17.23"