oc 0.49.21 → 0.49.22

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.
Files changed (166) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/cli/domain/get-mocked-plugins.js +2 -3
  3. package/dist/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.js +1 -2
  4. package/dist/cli/domain/local.d.ts +1 -1
  5. package/dist/cli/domain/registry.d.ts +1 -1
  6. package/dist/cli/programmatic-api.d.ts +2 -2
  7. package/dist/components/oc-client/_package/package.json +1 -1
  8. package/dist/components/oc-client/package.json +1 -1
  9. package/dist/registry/domain/components-cache/components-list.d.ts +3 -3
  10. package/dist/registry/domain/components-cache/components-list.js +28 -5
  11. package/dist/registry/domain/components-cache/index.js +27 -22
  12. package/dist/registry/domain/components-details.js +1 -2
  13. package/dist/registry/domain/events-handler.d.ts +3 -3
  14. package/dist/registry/domain/plugins-initialiser.d.ts +1 -1
  15. package/dist/registry/domain/repository.d.ts +1 -1
  16. package/dist/registry/domain/storage-adapter.d.ts +2 -2
  17. package/dist/registry/domain/url-builder.d.ts +1 -1
  18. package/dist/registry/domain/validators/node-version.d.ts +3 -3
  19. package/dist/registry/domain/validators/oc-cli-version.d.ts +3 -3
  20. package/dist/registry/domain/validators/plugins-requirements.d.ts +1 -1
  21. package/dist/registry/domain/validators/registry-configuration.d.ts +1 -1
  22. package/dist/registry/domain/validators/uploaded-package.d.ts +1 -1
  23. package/dist/registry/index.js +2 -3
  24. package/dist/registry/routes/helpers/get-available-dependencies.js +2 -3
  25. package/dist/registry/routes/helpers/get-component-fallback.d.ts +1 -1
  26. package/dist/registry/routes/helpers/is-url-discoverable.js +1 -2
  27. package/dist/registry/views/info.d.ts +1 -1
  28. package/dist/registry/views/partials/selected-checkbox.d.ts +1 -1
  29. package/dist/types.d.ts +3 -3
  30. package/dist/utils/is-template-legacy.d.ts +1 -1
  31. package/logintervals.md +1 -1
  32. package/package.json +20 -20
  33. package/tsconfig.json +1 -1
  34. package/dist/components/oc-client/_package/src/oc-client.min.js +0 -3
  35. package/dist/components/oc-client/_package/src/oc-client.min.map +0 -1
  36. package/dist/components/oc-client/src/oc-client.min.js +0 -3
  37. package/dist/components/oc-client/src/oc-client.min.map +0 -1
  38. package/src/cli/commands.ts +0 -178
  39. package/src/cli/domain/clean.ts +0 -21
  40. package/src/cli/domain/get-components-by-dir.ts +0 -47
  41. package/src/cli/domain/get-mocked-plugins.ts +0 -154
  42. package/src/cli/domain/handle-dependencies/ensure-compiler-is-declared-as-devDependency.ts +0 -17
  43. package/src/cli/domain/handle-dependencies/get-compiler.ts +0 -35
  44. package/src/cli/domain/handle-dependencies/get-missing-dependencies.ts +0 -17
  45. package/src/cli/domain/handle-dependencies/index.ts +0 -93
  46. package/src/cli/domain/handle-dependencies/install-compiler.ts +0 -43
  47. package/src/cli/domain/handle-dependencies/install-missing-dependencies.ts +0 -48
  48. package/src/cli/domain/handle-dependencies/link-missing-dependencies.ts +0 -45
  49. package/src/cli/domain/handle-dependencies/require-template.ts +0 -62
  50. package/src/cli/domain/init-template/index.ts +0 -26
  51. package/src/cli/domain/init-template/install-template.ts +0 -52
  52. package/src/cli/domain/init-template/scaffold.ts +0 -45
  53. package/src/cli/domain/local.ts +0 -77
  54. package/src/cli/domain/mock.ts +0 -40
  55. package/src/cli/domain/package-components.ts +0 -61
  56. package/src/cli/domain/registry.ts +0 -147
  57. package/src/cli/domain/url-parser.ts +0 -44
  58. package/src/cli/domain/watch.ts +0 -33
  59. package/src/cli/facade/clean.ts +0 -75
  60. package/src/cli/facade/dev.ts +0 -214
  61. package/src/cli/facade/init.ts +0 -50
  62. package/src/cli/facade/mock.ts +0 -20
  63. package/src/cli/facade/package.ts +0 -65
  64. package/src/cli/facade/preview.ts +0 -28
  65. package/src/cli/facade/publish.ts +0 -209
  66. package/src/cli/facade/registry-add.ts +0 -23
  67. package/src/cli/facade/registry-ls.ts +0 -36
  68. package/src/cli/facade/registry-remove.ts +0 -23
  69. package/src/cli/facade/registry.ts +0 -9
  70. package/src/cli/index.ts +0 -142
  71. package/src/cli/logger.ts +0 -38
  72. package/src/cli/programmatic-api.ts +0 -142
  73. package/src/cli/validate-command.ts +0 -18
  74. package/src/components/oc-client/_package/package.json +0 -1
  75. package/src/components/oc-client/_package/server.js +0 -1
  76. package/src/components/oc-client/_package/src/oc-client.min.js +0 -3
  77. package/src/components/oc-client/_package/src/oc-client.min.map +0 -1
  78. package/src/components/oc-client/_package/template.js +0 -1
  79. package/src/components/oc-client/package.json +0 -26
  80. package/src/components/oc-client/server.js +0 -6
  81. package/src/components/oc-client/src/oc-client.min.js +0 -3
  82. package/src/components/oc-client/src/oc-client.min.map +0 -1
  83. package/src/components/oc-client/template.js +0 -4
  84. package/src/globals.d.ts +0 -103
  85. package/src/index.ts +0 -3
  86. package/src/oc-cli.js +0 -3
  87. package/src/registry/app-start.ts +0 -75
  88. package/src/registry/domain/authentication.ts +0 -59
  89. package/src/registry/domain/components-cache/components-list.ts +0 -70
  90. package/src/registry/domain/components-cache/index.ts +0 -90
  91. package/src/registry/domain/components-details.ts +0 -96
  92. package/src/registry/domain/events-handler.ts +0 -86
  93. package/src/registry/domain/extract-package.ts +0 -45
  94. package/src/registry/domain/get-package-json-from-temp-dir.ts +0 -9
  95. package/src/registry/domain/nested-renderer.ts +0 -88
  96. package/src/registry/domain/options-sanitiser.ts +0 -118
  97. package/src/registry/domain/plugins-initialiser.ts +0 -127
  98. package/src/registry/domain/register-templates.ts +0 -41
  99. package/src/registry/domain/repository.ts +0 -390
  100. package/src/registry/domain/require-wrapper.ts +0 -39
  101. package/src/registry/domain/sanitiser.ts +0 -60
  102. package/src/registry/domain/storage-adapter.ts +0 -85
  103. package/src/registry/domain/url-builder.ts +0 -80
  104. package/src/registry/domain/validators/component-parameters.ts +0 -112
  105. package/src/registry/domain/validators/index.ts +0 -24
  106. package/src/registry/domain/validators/node-version.ts +0 -59
  107. package/src/registry/domain/validators/oc-cli-version.ts +0 -52
  108. package/src/registry/domain/validators/package-json-validator.ts +0 -35
  109. package/src/registry/domain/validators/plugins-requirements.ts +0 -39
  110. package/src/registry/domain/validators/registry-configuration.ts +0 -143
  111. package/src/registry/domain/validators/uploaded-package.ts +0 -49
  112. package/src/registry/domain/version-handler.ts +0 -25
  113. package/src/registry/index.ts +0 -117
  114. package/src/registry/middleware/base-url-handler.ts +0 -16
  115. package/src/registry/middleware/cors.ts +0 -18
  116. package/src/registry/middleware/discovery-handler.ts +0 -20
  117. package/src/registry/middleware/file-uploads.ts +0 -28
  118. package/src/registry/middleware/index.ts +0 -53
  119. package/src/registry/middleware/request-handler.ts +0 -30
  120. package/src/registry/router.ts +0 -85
  121. package/src/registry/routes/component-info.ts +0 -119
  122. package/src/registry/routes/component-preview.ts +0 -87
  123. package/src/registry/routes/component.ts +0 -53
  124. package/src/registry/routes/components.ts +0 -107
  125. package/src/registry/routes/dependencies.ts +0 -27
  126. package/src/registry/routes/helpers/apply-default-values.ts +0 -29
  127. package/src/registry/routes/helpers/get-available-dependencies.ts +0 -31
  128. package/src/registry/routes/helpers/get-component-fallback.ts +0 -139
  129. package/src/registry/routes/helpers/get-component-retrieving-info.ts +0 -44
  130. package/src/registry/routes/helpers/get-component.ts +0 -583
  131. package/src/registry/routes/helpers/get-components-history.ts +0 -40
  132. package/src/registry/routes/helpers/is-url-discoverable.ts +0 -18
  133. package/src/registry/routes/index.ts +0 -127
  134. package/src/registry/routes/plugins.ts +0 -19
  135. package/src/registry/routes/publish.ts +0 -89
  136. package/src/registry/routes/static-redirector.ts +0 -74
  137. package/src/registry/views/index.ts +0 -66
  138. package/src/registry/views/info.ts +0 -89
  139. package/src/registry/views/partials/component-author.ts +0 -32
  140. package/src/registry/views/partials/component-parameters.ts +0 -53
  141. package/src/registry/views/partials/component-state.ts +0 -14
  142. package/src/registry/views/partials/component-versions.ts +0 -16
  143. package/src/registry/views/partials/components-dependencies.ts +0 -26
  144. package/src/registry/views/partials/components-history.ts +0 -24
  145. package/src/registry/views/partials/components-list.ts +0 -65
  146. package/src/registry/views/partials/components-plugins.ts +0 -23
  147. package/src/registry/views/partials/components-templates.ts +0 -36
  148. package/src/registry/views/partials/layout.ts +0 -32
  149. package/src/registry/views/partials/property.ts +0 -17
  150. package/src/registry/views/partials/selected-checkbox.ts +0 -16
  151. package/src/registry/views/preview.ts +0 -37
  152. package/src/registry/views/static/index.ts +0 -92
  153. package/src/registry/views/static/info.ts +0 -43
  154. package/src/registry/views/static/style.ts +0 -277
  155. package/src/resources/index.ts +0 -279
  156. package/src/resources/settings.ts +0 -17
  157. package/src/types.ts +0 -251
  158. package/src/utils/clean-require.ts +0 -35
  159. package/src/utils/date-stringify.ts +0 -23
  160. package/src/utils/error-to-string.ts +0 -13
  161. package/src/utils/is-template-legacy.ts +0 -7
  162. package/src/utils/is-template-valid.ts +0 -19
  163. package/src/utils/module-exists.ts +0 -14
  164. package/src/utils/npm-utils.ts +0 -109
  165. package/src/utils/put.ts +0 -35
  166. package/src/utils/strip-version.ts +0 -6
@@ -1,390 +0,0 @@
1
- import fs from 'fs-extra';
2
- import getUnixUtcTimestamp from 'oc-get-unix-utc-timestamp';
3
- import path from 'path';
4
- import dotenv from 'dotenv';
5
-
6
- import ComponentsCache from './components-cache';
7
- import getComponentsDetails from './components-details';
8
- import registerTemplates from './register-templates';
9
- import settings from '../../resources/settings';
10
- import strings from '../../resources';
11
- import * as validator from './validators';
12
- import getPromiseBasedAdapter from './storage-adapter';
13
- import * as versionHandler from './version-handler';
14
- import errorToString from '../../utils/error-to-string';
15
- import {
16
- Component,
17
- ComponentsDetails,
18
- Config,
19
- TemplateInfo
20
- } from '../../types';
21
- import { StorageAdapter } from 'oc-storage-adapters-utils';
22
-
23
- const packageInfo = fs.readJsonSync(
24
- path.join(__dirname, '..', '..', '..', 'package.json')
25
- );
26
-
27
- export default function repository(conf: Config) {
28
- const cdn: StorageAdapter =
29
- !conf.local &&
30
- (getPromiseBasedAdapter(conf.storage.adapter(conf.storage.options)) as any);
31
- const options = !conf.local ? conf.storage.options : null;
32
- const repositorySource = conf.local
33
- ? 'local repository'
34
- : cdn.adapterType + ' cdn';
35
- const componentsCache = ComponentsCache(conf, cdn);
36
- const componentsDetails = getComponentsDetails(conf, cdn);
37
-
38
- const getFilePath = (component: string, version: string, filePath: string) =>
39
- `${options!.componentsDir}/${component}/${version}/${filePath}`;
40
-
41
- const { templatesHash, templatesInfo } = registerTemplates(
42
- conf.templates,
43
- conf.local
44
- );
45
-
46
- const local = {
47
- getCompiledView(componentName: string): string {
48
- if (componentName === 'oc-client') {
49
- return fs
50
- .readFileSync(
51
- path.join(
52
- __dirname,
53
- '../../components/oc-client/_package/template.js'
54
- )
55
- )
56
- .toString();
57
- }
58
-
59
- return fs
60
- .readFileSync(
61
- path.join(conf.path, `${componentName}/_package/template.js`)
62
- )
63
- .toString();
64
- },
65
- getComponents(): string[] {
66
- const validComponents =
67
- conf.components ||
68
- fs.readdirSync(conf.path).filter(file => {
69
- const isDir = fs.lstatSync(path.join(conf.path, file)).isDirectory();
70
- const isValidComponent = isDir
71
- ? fs
72
- .readdirSync(path.join(conf.path, file))
73
- .filter(file => file === '_package').length === 1
74
- : false;
75
-
76
- return isValidComponent;
77
- });
78
-
79
- validComponents.push('oc-client');
80
- return validComponents;
81
- },
82
- getComponentVersions(componentName: string): Promise<string[]> {
83
- if (componentName === 'oc-client') {
84
- return Promise.all([
85
- fs
86
- .readJson(path.join(__dirname, '../../../package.json'))
87
- .then(x => x.version)
88
- ]);
89
- }
90
-
91
- if (!local.getComponents().includes(componentName)) {
92
- return Promise.reject(
93
- strings.errors.registry.COMPONENT_NOT_FOUND(
94
- componentName,
95
- repositorySource
96
- )
97
- );
98
- }
99
-
100
- return Promise.all([
101
- fs
102
- .readJson(path.join(conf.path, `${componentName}/package.json`))
103
- .then(x => x.version)
104
- ]);
105
- },
106
- getDataProvider(componentName: string) {
107
- const ocClientServerPath =
108
- '../../components/oc-client/_package/server.js';
109
- const filePath =
110
- componentName === 'oc-client'
111
- ? path.join(__dirname, ocClientServerPath)
112
- : path.join(conf.path, `${componentName}/_package/server.js`);
113
-
114
- return {
115
- content: fs.readFileSync(filePath).toString(),
116
- filePath
117
- };
118
- },
119
- getEnv(componentName: string): Record<string, string> {
120
- const pkg: Component = fs.readJsonSync(
121
- path.join(conf.path, `${componentName}/package.json`)
122
- );
123
- const filePath = path.join(conf.path, componentName, pkg.oc.files.env!);
124
-
125
- return dotenv.parse(fs.readFileSync(filePath).toString());
126
- }
127
- };
128
-
129
- const repository = {
130
- getCompiledView(
131
- componentName: string,
132
- componentVersion: string
133
- ): Promise<string> {
134
- if (conf.local) {
135
- return Promise.resolve(local.getCompiledView(componentName));
136
- }
137
-
138
- return cdn.getFile(
139
- getFilePath(componentName, componentVersion, 'template.js')
140
- );
141
- },
142
- async getComponent(
143
- componentName: string,
144
- componentVersion?: string
145
- ): Promise<Component> {
146
- const allVersions = await repository.getComponentVersions(componentName);
147
-
148
- if (allVersions.length === 0) {
149
- throw strings.errors.registry.COMPONENT_NOT_FOUND(
150
- componentName,
151
- repositorySource
152
- );
153
- }
154
-
155
- const version = versionHandler.getAvailableVersion(
156
- componentVersion,
157
- allVersions
158
- );
159
-
160
- if (!version) {
161
- throw strings.errors.registry.COMPONENT_VERSION_NOT_FOUND(
162
- componentName,
163
- componentVersion || '',
164
- repositorySource
165
- );
166
- }
167
-
168
- const component = await repository
169
- .getComponentInfo(componentName, version)
170
- .catch(err => {
171
- throw `component not available: ${errorToString(err)}`;
172
- });
173
-
174
- return Object.assign(component, { allVersions });
175
- },
176
- getComponentInfo(
177
- componentName: string,
178
- componentVersion: string
179
- ): Promise<Component> {
180
- if (conf.local) {
181
- let componentInfo: Component;
182
-
183
- if (componentName === 'oc-client') {
184
- componentInfo = fs.readJsonSync(
185
- path.join(
186
- __dirname,
187
- '../../components/oc-client/_package/package.json'
188
- )
189
- );
190
- } else {
191
- componentInfo = fs.readJsonSync(
192
- path.join(conf.path, `${componentName}/_package/package.json`)
193
- );
194
- }
195
-
196
- if (componentInfo.version === componentVersion) {
197
- return Promise.resolve(componentInfo);
198
- } else {
199
- // eslint-disable-next-line prefer-promise-reject-errors
200
- return Promise.reject('version not available');
201
- }
202
- }
203
-
204
- return cdn.getJson<Component>(
205
- getFilePath(componentName, componentVersion, 'package.json'),
206
- false
207
- );
208
- },
209
- getComponentPath(componentName: string, componentVersion: string): string {
210
- const prefix = conf.local
211
- ? conf.baseUrl
212
- : `${options!['path']}${options!.componentsDir}/`;
213
- return `${prefix}${componentName}/${componentVersion}/`;
214
- },
215
- async getComponents(): Promise<string[]> {
216
- if (conf.local) {
217
- return local.getComponents();
218
- }
219
-
220
- const { components } = await componentsCache.get();
221
- return Object.keys(components);
222
- },
223
- getComponentsDetails(): Promise<ComponentsDetails> {
224
- if (conf.local) {
225
- // when in local this won't get called
226
- return Promise.resolve(null) as any;
227
- }
228
-
229
- return componentsDetails.get();
230
- },
231
- async getComponentVersions(componentName: string): Promise<string[]> {
232
- if (conf.local) {
233
- return local.getComponentVersions(componentName);
234
- }
235
-
236
- const res = await componentsCache.get();
237
-
238
- return res.components[componentName] ? res.components[componentName] : [];
239
- },
240
- async getDataProvider(
241
- componentName: string,
242
- componentVersion: string
243
- ): Promise<{
244
- content: string;
245
- filePath: string;
246
- }> {
247
- if (conf.local) {
248
- return local.getDataProvider(componentName);
249
- }
250
-
251
- const filePath = getFilePath(
252
- componentName,
253
- componentVersion,
254
- 'server.js'
255
- );
256
-
257
- const content = await cdn.getFile(filePath);
258
-
259
- return { content, filePath };
260
- },
261
- async getEnv(
262
- componentName: string,
263
- componentVersion: string
264
- ): Promise<Record<string, string>> {
265
- if (conf.local) {
266
- return local.getEnv(componentName);
267
- }
268
-
269
- const filePath = getFilePath(componentName, componentVersion, '.env');
270
- const file = await cdn.getFile(filePath);
271
-
272
- return dotenv.parse(file);
273
- },
274
- getStaticClientPath: (): string =>
275
- `${options!['path']}${getFilePath(
276
- 'oc-client',
277
- packageInfo.version,
278
- 'src/oc-client.min.js'
279
- )}`,
280
-
281
- getStaticClientMapPath: (): string =>
282
- `${options!['path']}${getFilePath(
283
- 'oc-client',
284
- packageInfo.version,
285
- 'src/oc-client.min.map'
286
- )}`,
287
-
288
- getStaticFilePath: (
289
- componentName: string,
290
- componentVersion: string,
291
- filePath: string
292
- ): string =>
293
- `${repository.getComponentPath(componentName, componentVersion)}${
294
- conf.local ? settings.registry.localStaticRedirectorPath : ''
295
- }${filePath}`,
296
-
297
- getTemplatesInfo: (): TemplateInfo[] => templatesInfo,
298
- getTemplate: (type: string) => templatesHash[type],
299
- async init(): Promise<ComponentsDetails | undefined> {
300
- if (conf.local) {
301
- // when in local this won't get called
302
- return;
303
- }
304
-
305
- const componentsList = await componentsCache.load();
306
-
307
- return componentsDetails.refresh(componentsList);
308
- },
309
- async publishComponent(
310
- pkgDetails: { outputFolder: string; packageJson: Component },
311
- componentName: string,
312
- componentVersion: string
313
- ): Promise<ComponentsDetails> {
314
- if (conf.local) {
315
- throw {
316
- code: strings.errors.registry.LOCAL_PUBLISH_NOT_ALLOWED_CODE,
317
- msg: strings.errors.registry.LOCAL_PUBLISH_NOT_ALLOWED
318
- };
319
- }
320
-
321
- if (!validator.validateComponentName(componentName)) {
322
- throw {
323
- code: strings.errors.registry.COMPONENT_NAME_NOT_VALID_CODE,
324
- msg: strings.errors.registry.COMPONENT_NAME_NOT_VALID
325
- };
326
- }
327
-
328
- if (!validator.validateVersion(componentVersion)) {
329
- throw {
330
- code: strings.errors.registry.COMPONENT_VERSION_NOT_VALID_CODE,
331
- msg: strings.errors.registry.COMPONENT_VERSION_NOT_VALID(
332
- componentVersion
333
- )
334
- };
335
- }
336
-
337
- const validationResult = validator.validatePackageJson(
338
- Object.assign(pkgDetails, {
339
- componentName,
340
- customValidator: conf.publishValidation
341
- })
342
- );
343
-
344
- if (!validationResult.isValid) {
345
- throw {
346
- code: strings.errors.registry.COMPONENT_PUBLISHVALIDATION_FAIL_CODE,
347
- msg: strings.errors.registry.COMPONENT_PUBLISHVALIDATION_FAIL(
348
- String(validationResult.error)
349
- )
350
- };
351
- }
352
-
353
- const componentVersions = await repository.getComponentVersions(
354
- componentName
355
- );
356
-
357
- if (
358
- !versionHandler.validateNewVersion(componentVersion, componentVersions)
359
- ) {
360
- throw {
361
- code: strings.errors.registry.COMPONENT_VERSION_ALREADY_FOUND_CODE,
362
- msg: strings.errors.registry.COMPONENT_VERSION_ALREADY_FOUND(
363
- componentName,
364
- componentVersion,
365
- repositorySource
366
- )
367
- };
368
- }
369
-
370
- pkgDetails.packageJson.oc.date = getUnixUtcTimestamp();
371
-
372
- await fs.writeJson(
373
- path.join(pkgDetails.outputFolder, 'package.json'),
374
- pkgDetails.packageJson
375
- );
376
-
377
- await cdn.putDir(
378
- pkgDetails.outputFolder,
379
- `${options!.componentsDir}/${componentName}/${componentVersion}`
380
- );
381
-
382
- const componentsList = await componentsCache.refresh();
383
- return componentsDetails.refresh(componentsList);
384
- }
385
- };
386
-
387
- return repository;
388
- }
389
-
390
- export type Repository = ReturnType<typeof repository>;
@@ -1,39 +0,0 @@
1
- import coreModules from 'builtin-modules';
2
- import path from 'path';
3
- import requirePackageName from 'require-package-name';
4
- import tryRequire from 'try-require';
5
-
6
- import strings from '../../resources';
7
-
8
- const isCoreDependency = (x: string) => coreModules.includes(x);
9
- const requireCoreDependency = (x: string) =>
10
- (isCoreDependency(x) && tryRequire(x)) || undefined;
11
-
12
- const requireDependency = (requirePath: string) => {
13
- const nodeModulesPath = path.resolve('.', 'node_modules');
14
- const modulePath = path.resolve(nodeModulesPath, requirePath);
15
- return tryRequire(modulePath);
16
- };
17
-
18
- const throwError = (requirePath: string) => {
19
- throw {
20
- code: strings.errors.registry.DEPENDENCY_NOT_FOUND_CODE,
21
- missing: [requirePath]
22
- };
23
- };
24
-
25
- export default (injectedDependencies: string[]) =>
26
- <T = unknown>(requirePath: string): T => {
27
- const moduleName = requirePackageName(requirePath);
28
- const isAllowed = injectedDependencies.includes(moduleName);
29
-
30
- if (!isAllowed) {
31
- return throwError(requirePath);
32
- }
33
-
34
- return (
35
- requireDependency(requirePath) ||
36
- requireCoreDependency(requirePath) ||
37
- throwError(requirePath)
38
- );
39
- };
@@ -1,60 +0,0 @@
1
- import { OcParameter } from '../../types';
2
-
3
- const sanitise = {
4
- booleanParameter(variable: string | number | boolean) {
5
- if (typeof variable === 'string') {
6
- if (variable === 'true') {
7
- return true;
8
- } else if (variable === 'false') {
9
- return false;
10
- }
11
- }
12
-
13
- return variable;
14
- },
15
- numberParameter(variable: string | number | boolean) {
16
- return Number(variable);
17
- },
18
- stringParameter(variable: string | number | boolean) {
19
- return variable == null ? '' : variable;
20
- },
21
- parameter(variable: string | number | boolean, type: string) {
22
- if (type === 'boolean') {
23
- return sanitise.booleanParameter(variable);
24
- } else if (type === 'number') {
25
- return sanitise.numberParameter(variable);
26
- } else if (type === 'string') {
27
- return sanitise.stringParameter(variable);
28
- }
29
-
30
- return variable;
31
- }
32
- };
33
-
34
- const toRemove = ['__ocAcceptLanguage'];
35
-
36
- export function sanitiseComponentParameters(
37
- requestParameters: Record<string, string | number | boolean>,
38
- expectedParameters: Record<string, OcParameter>
39
- ): Record<string, string | number | boolean> {
40
- const result: Record<string, string | number | boolean> = {};
41
-
42
- for (const [requestParameterName, requestParameter] of Object.entries(
43
- requestParameters
44
- )) {
45
- if (
46
- typeof expectedParameters === 'object' &&
47
- // eslint-disable-next-line no-prototype-builtins
48
- expectedParameters.hasOwnProperty(requestParameterName)
49
- ) {
50
- const expectedType = expectedParameters[requestParameterName].type;
51
- const sanitised = sanitise.parameter(requestParameter, expectedType);
52
-
53
- result[requestParameterName] = sanitised;
54
- } else if (!toRemove.includes(requestParameterName)) {
55
- result[requestParameterName] = requestParameter;
56
- }
57
- }
58
-
59
- return result;
60
- }
@@ -1,85 +0,0 @@
1
- import { fromCallback } from 'universalify';
2
- import { StorageAdapter } from 'oc-storage-adapters-utils';
3
-
4
- type RemovePromiseOverload<T> = T extends {
5
- (...args: infer B): void;
6
- (...args: any[]): Promise<any>;
7
- }
8
- ? (...args: B) => void
9
- : T;
10
-
11
- type LegacyStorageAdapter = {
12
- [P in keyof StorageAdapter]: RemovePromiseOverload<StorageAdapter[P]>;
13
- };
14
-
15
- const officialAdapters = {
16
- s3: { name: 'oc-s3-storage-adapter', firstPromiseBasedVersion: '1.2.0' },
17
- gs: { name: 'oc-gs-storage-adapter', firstPromiseBasedVersion: '1.1.0' },
18
- 'azure-blob-storage': {
19
- name: 'oc-azure-storage-adapter',
20
- firstPromiseBasedVersion: '0.1.0'
21
- }
22
- };
23
- type OfficialAdapter = keyof typeof officialAdapters;
24
-
25
- function isOfficialAdapter(
26
- adapter: LegacyStorageAdapter
27
- ): adapter is LegacyStorageAdapter & { adapterType: OfficialAdapter } {
28
- return Object.keys(officialAdapters).includes(
29
- adapter.adapterType as OfficialAdapter
30
- );
31
- }
32
-
33
- function isPromiseBased(tryFunction: () => unknown) {
34
- try {
35
- (tryFunction as () => Promise<unknown>)().catch(() => {
36
- // To not throw unhandled promise exceptions
37
- });
38
- return true;
39
- } catch (err) {
40
- return false;
41
- }
42
- }
43
-
44
- function isLegacyAdapter(
45
- adapter: StorageAdapter | LegacyStorageAdapter
46
- ): adapter is LegacyStorageAdapter {
47
- return !isPromiseBased(() => (adapter as StorageAdapter).getFile(''));
48
- }
49
-
50
- function convertLegacyAdapter(adapter: LegacyStorageAdapter): StorageAdapter {
51
- return {
52
- getFile: fromCallback(adapter.getFile as any),
53
- getJson: fromCallback(adapter.getJson as any),
54
- listSubDirectories: fromCallback(adapter.listSubDirectories as any),
55
- putDir: fromCallback(adapter.putDir as any),
56
- putFile: fromCallback(adapter.putFile as any),
57
- putFileContent: fromCallback(adapter.putFileContent as any),
58
- getUrl: adapter.getUrl,
59
- maxConcurrentRequests: adapter.maxConcurrentRequests,
60
- adapterType: adapter.adapterType
61
- } as any;
62
- }
63
-
64
- export default function getPromiseBasedAdapter(
65
- adapter: StorageAdapter | LegacyStorageAdapter
66
- ): StorageAdapter {
67
- if (isLegacyAdapter(adapter)) {
68
- if (isOfficialAdapter(adapter)) {
69
- const pkg = officialAdapters[adapter.adapterType];
70
- process.emitWarning(
71
- `Adapters now should work with promises. Consider upgrading your package ${pkg.name} to at least version ${pkg.firstPromiseBasedVersion}`,
72
- 'DeprecationWarning'
73
- );
74
- } else {
75
- process.emitWarning(
76
- 'Your adapter is using the old interface of working with callbacks. Consider upgrading it to work with promises, as the previous one will be deprecated.',
77
- 'DeprecationWarning'
78
- );
79
- }
80
-
81
- return convertLegacyAdapter(adapter);
82
- }
83
-
84
- return adapter;
85
- }
@@ -1,80 +0,0 @@
1
- import querystring from 'querystring';
2
- import url from 'url';
3
-
4
- type Component = {
5
- name: string;
6
- version?: string;
7
- parameters?: Record<string, string>;
8
- };
9
-
10
- function componentForType(
11
- component: Component | string,
12
- baseUrl: string,
13
- type: string
14
- ): string {
15
- if (typeof component === 'string') {
16
- component = { name: component };
17
- }
18
-
19
- let href = url.resolve(baseUrl, component.name) + '/';
20
-
21
- if (component.version) {
22
- href += component.version + '/';
23
- }
24
-
25
- href += '~' + type;
26
-
27
- return href;
28
- }
29
-
30
- export function component(
31
- component: Component | string,
32
- baseUrl: string
33
- ): string {
34
- if (typeof component === 'string') {
35
- component = { name: component };
36
- }
37
-
38
- let componentUrl = url.resolve(baseUrl, component.name);
39
-
40
- if (component.version) {
41
- componentUrl += '/' + component.version;
42
- }
43
-
44
- componentUrl += queryString(component.parameters);
45
-
46
- return componentUrl;
47
- }
48
- export function componentInfo(component: Component, baseUrl: string): string {
49
- return componentForType(component, baseUrl, 'info');
50
- }
51
- export function componentPreview(
52
- component: Component,
53
- baseUrl: string
54
- ): string {
55
- let href = componentForType(component, baseUrl, 'preview');
56
- if (!!component.parameters && Object.keys(component.parameters).length) {
57
- href += '/?' + querystring.stringify(component.parameters);
58
- } else {
59
- href += '/';
60
- }
61
-
62
- return href;
63
- }
64
- export function queryString(parameters: Record<string, string> = {}): string {
65
- let qs = '';
66
-
67
- if (Object.keys(parameters).length > 0) {
68
- qs += '?';
69
-
70
- for (const [key, parameter] of Object.entries(parameters)) {
71
- qs += key + '=' + encodeURIComponent(parameter) + '&';
72
- }
73
-
74
- if (Object.keys(parameters).length > 0) {
75
- qs = qs.slice(0, -1);
76
- }
77
- }
78
-
79
- return qs;
80
- }