@sap/cds-dk 6.1.5 → 6.2.1

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 (152) hide show
  1. package/CHANGELOG.md +36 -2
  2. package/bin/cds.js +7 -5
  3. package/bin/deploy/index.js +3 -2
  4. package/bin/deploy/to-sqlite.js +4 -3
  5. package/bin/help.js +4 -0
  6. package/bin/init.js +2 -1
  7. package/bin/login.js +23 -9
  8. package/bin/mock.js +1 -0
  9. package/bin/pull.js +24 -19
  10. package/bin/push.js +20 -9
  11. package/bin/subscribe.js +40 -10
  12. package/bin/watch.js +15 -10
  13. package/lib/bind/kubernetesCredentialsProvider.js +1 -0
  14. package/lib/client/activate.js +42 -51
  15. package/lib/client/auth_manager.js +7 -8
  16. package/lib/client/base_command.js +5 -2
  17. package/lib/client/extend.js +33 -38
  18. package/lib/client/helper/cf_helper.js +11 -11
  19. package/lib/client/helper/dependency_helper.js +2 -2
  20. package/lib/client/helper/errors.js +4 -3
  21. package/lib/client/helper/logging.js +17 -23
  22. package/lib/client/params.js +5 -5
  23. package/lib/client/pull.js +19 -21
  24. package/lib/client/push.js +16 -15
  25. package/lib/client/settings_manager.js +54 -55
  26. package/lib/compile/openapi/csdl2openapi.js +18 -12
  27. package/lib/import/message.js +1 -1
  28. package/lib/import/odata/metadataconverter/MetadataConverter.js +23 -17
  29. package/lib/import/odata/v2parser.js +43 -17
  30. package/lib/import/odata/v4parser.js +77 -22
  31. package/lib/init/constants.js +5 -2
  32. package/lib/init/index.js +16 -4
  33. package/lib/init/template/_merging/registry-mta.js +13 -0
  34. package/lib/init/template/approuter/index.js +9 -0
  35. package/lib/{k8s/connectivity/templates/connectivity.yaml → init/template/auditlog/files/auditlog.yaml} +0 -0
  36. package/lib/init/template/auditlog/index.js +46 -27
  37. package/lib/{k8s/connectivity/templates → init/template/connectivity/files}/connectivity-binding.yaml +0 -0
  38. package/lib/{k8s/connectivity/templates → init/template/connectivity/files}/connectivity-proxy-info.yaml +1 -1
  39. package/lib/init/template/connectivity/files/connectivity.yaml +1 -0
  40. package/lib/init/template/connectivity/files/values.yaml.hbs +26 -0
  41. package/lib/init/template/connectivity/index.js +41 -0
  42. package/lib/init/template/data/index.js +8 -8
  43. package/lib/init/template/destinations/files/destination.yaml +1 -0
  44. package/lib/init/template/destinations/index.js +44 -0
  45. package/lib/init/template/enterprise-messaging/files/cds.package.json +10 -0
  46. package/lib/init/template/enterprise-messaging/files/cds.profile.package.json.hbs +12 -0
  47. package/lib/init/template/enterprise-messaging/files/cdsrc.json +8 -0
  48. package/lib/init/template/enterprise-messaging/files/cdsrc.json.hbs +10 -0
  49. package/lib/init/template/enterprise-messaging/files/event-mesh.yaml +1 -0
  50. package/lib/init/template/enterprise-messaging/files/mta.yaml.hbs +13 -0
  51. package/lib/init/template/enterprise-messaging/files/values.yaml +8 -0
  52. package/lib/init/template/enterprise-messaging/index.js +56 -0
  53. package/lib/init/template/extensibility/files/cdsrc.json +5 -0
  54. package/lib/init/template/extensibility/files/cdsrc.json.hbs +7 -0
  55. package/lib/init/template/extensibility/index.js +18 -13
  56. package/lib/{k8s/hana-deployer/templates → init/template/hana/files}/hana-deployer-job.yaml +0 -0
  57. package/lib/init/template/hana/files/java/{cdsrc.json.hbs → cds.json.hbs} +0 -0
  58. package/lib/init/template/hana/files/java/{profile.cdsrc.json.hbs → cds.profile.json.hbs} +0 -0
  59. package/lib/init/template/hana/files/java/cds.shortcut.json.hbs +5 -0
  60. package/lib/init/template/hana/files/java/cds.shortcut.profile.json.hbs +8 -0
  61. package/lib/init/template/hana/files/java/db/package.json +2 -1
  62. package/lib/init/template/hana/files/mta.yaml.hbs +6 -0
  63. package/lib/init/template/hana/files/nodejs/{cds.package.json.hbs → cds.json.hbs} +0 -0
  64. package/lib/init/template/hana/files/nodejs/{cds.profile.package.json.hbs → cds.profile.json.hbs} +0 -0
  65. package/lib/init/template/hana/files/nodejs/cds.shortcut.json.hbs +7 -0
  66. package/lib/init/template/hana/files/nodejs/cds.shortcut.profile.json.hbs +10 -0
  67. package/lib/init/template/hana/files/values.yaml.hbs +19 -0
  68. package/lib/init/template/hana/index.js +29 -29
  69. package/lib/{k8s → init/template/helm}/Model.d.ts +0 -0
  70. package/lib/{k8s/resources → init/template}/helm/chart/templates/NOTES.txt +0 -0
  71. package/lib/{k8s/resources → init/template}/helm/chart/templates/_deployment_helpers.tpl +0 -0
  72. package/lib/{k8s/resources → init/template}/helm/chart/templates/_helpers.tpl +4 -5
  73. package/lib/{k8s/resources → init/template}/helm/chart/templates/_sapcp_helpers.tpl +0 -0
  74. package/lib/{k8s/resources/helm/chart/schemas → init/template/helm/chart}/values.root.schema.json +0 -0
  75. package/lib/{k8s/resources/helm/chart/schemas → init/template/helm/chart}/values.schema.json +0 -0
  76. package/lib/init/template/helm/files/Chart.yaml.hbs +13 -0
  77. package/lib/init/template/helm/files/values.yaml.hbs +26 -0
  78. package/lib/init/template/helm/index.js +74 -14
  79. package/lib/{k8s/deployment → init/template/helm}/subchart/Chart.yaml +0 -0
  80. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/_helpers.tpl +0 -0
  81. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/api-rule.yaml +0 -0
  82. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/deployment.yaml +0 -0
  83. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/network-policy.yaml +0 -0
  84. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/pod-disruption-budget.yaml +0 -0
  85. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/secret.yaml +0 -0
  86. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/service-binding.yaml +0 -0
  87. package/lib/{k8s/deployment → init/template/helm}/subchart/templates/service.yaml +0 -0
  88. package/lib/{k8s/deployment → init/template/helm}/subchart/values-lint.yaml +0 -0
  89. package/lib/{k8s/deployment → init/template/helm}/subchart/values.md +0 -0
  90. package/lib/{k8s/deployment → init/template/helm}/subchart/values.schema.json +0 -0
  91. package/lib/{k8s/deployment → init/template/helm}/subchart/values.yaml +0 -0
  92. package/lib/{k8s/html5-apps-deployer/templates → init/template/html5-repo/files}/_html5_deployment_helpers.tpl +0 -0
  93. package/lib/{k8s/html5-apps-deployer/templates → init/template/html5-repo/files}/html5-apps-deployer-job.yaml +1 -1
  94. package/lib/{k8s/html5-apps-repo-host/templates → init/template/html5-repo/files}/html5-apps-repo-host.yaml +0 -0
  95. package/lib/init/template/html5-repo/index.js +59 -0
  96. package/lib/init/template/kibana-logging/index.js +8 -0
  97. package/lib/init/template/lint/index.js +1 -4
  98. package/lib/init/template/mta/files/mta.yaml.hbs +3 -2
  99. package/lib/init/template/mta/index.js +6 -1
  100. package/lib/init/template/multitenancy/files/java/.cdsrc.json +3 -0
  101. package/lib/init/template/multitenancy/files/java/package.json +2 -6
  102. package/lib/{k8s/multitenancy/templates → init/template/multitenancy/files}/saas-registry.yaml +3 -3
  103. package/lib/init/template/multitenancy/files/xsuaa.yaml +1 -0
  104. package/lib/init/template/multitenancy/index.js +53 -26
  105. package/lib/init/template/nodejs/files/.gitignore.hbs +1 -0
  106. package/lib/init/template/templateBase.js +1 -1
  107. package/lib/init/template/xsuaa/files/values.yaml.hbs +10 -0
  108. package/lib/init/template/xsuaa/files/xsuaa.yaml +1 -0
  109. package/lib/init/template/xsuaa/index.js +34 -22
  110. package/lib/init/util/fsUtil.js +11 -5
  111. package/lib/init/util/projectReader.js +24 -32
  112. package/lib/init/util/templateUtil.js +17 -5
  113. package/lib/lint/Linter.js +9 -17
  114. package/lib/lint/checks.js +0 -1
  115. package/lib/lint/generators.js +2 -192
  116. package/lib/lint/io.js +1 -3
  117. package/lib/watch/node-watch.js +2 -2
  118. package/npm-shrinkwrap.json +1666 -873
  119. package/package.json +5 -4
  120. package/lib/init/template/helm/update/index.js +0 -28
  121. package/lib/k8s/ChartAdder.js +0 -75
  122. package/lib/k8s/ChartBuilder.js +0 -192
  123. package/lib/k8s/Context.js +0 -71
  124. package/lib/k8s/ImageUtil.js +0 -21
  125. package/lib/k8s/auditlog/index.js +0 -29
  126. package/lib/k8s/auditlog/templates/auditlog.yaml +0 -1
  127. package/lib/k8s/buildModel.js +0 -68
  128. package/lib/k8s/connectivity/index.js +0 -80
  129. package/lib/k8s/deployment/index.js +0 -79
  130. package/lib/k8s/deployment/subchart-override/templates/_web_application_helpers.tpl +0 -81
  131. package/lib/k8s/destinations/index.js +0 -40
  132. package/lib/k8s/destinations/lib.js +0 -16
  133. package/lib/k8s/destinations/templates/destinations.yaml +0 -1
  134. package/lib/k8s/docker/push.js +0 -8
  135. package/lib/k8s/event-mesh/index.js +0 -53
  136. package/lib/k8s/event-mesh/lib.js +0 -9
  137. package/lib/k8s/event-mesh/templates/event-mesh.yaml +0 -1
  138. package/lib/k8s/hana-deployer/index.js +0 -48
  139. package/lib/k8s/helm/Release.js +0 -80
  140. package/lib/k8s/html5-apps-deployer/index.js +0 -53
  141. package/lib/k8s/html5-apps-repo-host/index.js +0 -26
  142. package/lib/k8s/html5-apps-repo-host/lib.js +0 -16
  143. package/lib/k8s/index.js +0 -153
  144. package/lib/k8s/modules.js +0 -36
  145. package/lib/k8s/multitenancy/index.js +0 -24
  146. package/lib/k8s/multitenancy/lib.js +0 -25
  147. package/lib/k8s/readProject.js +0 -14
  148. package/lib/k8s/util.js +0 -186
  149. package/lib/k8s/wrapFeature.js +0 -55
  150. package/lib/k8s/xsuaa/index.js +0 -64
  151. package/lib/k8s/xsuaa/lib.js +0 -17
  152. package/lib/k8s/xsuaa/templates/xsuaa.yaml +0 -1
package/CHANGELOG.md CHANGED
@@ -7,7 +7,39 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
9
9
 
10
- ## Version 6.1.5 - tbd
10
+ ## Version 6.2.1 - 2022-10-10
11
+
12
+ ### Fixed
13
+
14
+ - Installation errors with unresolvable `@sap/hdi` 4.4.0 are fixed.
15
+
16
+ ## Version 6.2.0 - 2022-10-07
17
+
18
+ ### Added
19
+
20
+ - `cds import` now imports Singleton entities for OData V4 files.
21
+ - `cds deploy` now supports the new default`.sqlite` file ending
22
+ - `cds add mta` no longer creates a `before-all` custom build command for Java single and multi tenant applications. Custom build commands are defined for `db-deployer` and `mtx/sidecar` modules instead.
23
+ - `cds import` now supports enum types for OData V4
24
+ - `cds add enterprise-messaging` can be now be used to set up configuration and deployment descriptors for SAP Event Mesh.
25
+ - `cds add` now throws an error if no facet is passed.
26
+ - `cds watch` now also considers more files from SAP Fiori (`change,variant,ctrl_variant,ctrl_variant_change,ctrl_variant_management_change`)
27
+
28
+ ### Changed
29
+
30
+ - `cds add data` no longer creates CSV headers in UPPERCASE, but keeps the original case of the declared element. Both styles work, but the latter is preferred.
31
+ - `cds pull` requires `@sap/cds` 6.2 or higher
32
+
33
+ ### Fixed
34
+
35
+ - `cds import` now imports csn for OData V2 file even if the `association set` is missing and throws error if the corresponding `association` is missing.
36
+ - `cds import` now adds the annotation `@odata.Precision` entry only if precision > 0 for Edm.DateTime and Edm.DateTimeOffset.
37
+ - `cds compile --to openapi` now has schema Objects for `-create` and `-update` to only advertise "deep" insert/update for _containment_ navigation properties. Non-containment navigation properties are no longer mentioned.
38
+ - `.sqlite` files are now git-ignored in new projects created with `cds init`
39
+ - `cds compile --to openapi` now fixes the issue of failing range assertions for an element having undefined maximum and minimum range values.
40
+ - `cds import` now for OData V2 files doesn't throw warning for `EntityType` being referred as type in complex types, functions and actions, provided it is present in the file.
41
+
42
+ ## Version 6.1.5 - 2022-09-13
11
43
 
12
44
  ### Fixed
13
45
 
@@ -23,6 +55,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
23
55
 
24
56
  ### Fixed
25
57
 
58
+ - `cds import` now gives higher precedence to complex type in case of name collision with actions or functions.
26
59
  - `cds extend` and other commands no longer fail with `TypeError: Class constructor CliError cannot be invoked without 'new'`
27
60
 
28
61
  ## Version 6.1.2 - 2022-08-25
@@ -33,7 +66,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
33
66
  ### Fixed
34
67
  - `cds add helm` fixed JSON Schema for `srv` property in values.yaml
35
68
  - `cds add helm` fixed env property errors for `hana_deployer` and `html5_apps_deployer`
36
- - `cds add data` now creates proper data file names for entites in a `context`, i.e. `sap.common-Countries.csv` instead of `sap-common-Countries.csv`
69
+ - `cds add data` now creates proper data file names for entities in a `context`, i.e. `sap.common-Countries.csv` instead of `sap-common-Countries.csv`
37
70
  - `cds import` now captures the parameter/property of collection type differently and the associated annotations are pulled out of the `items` object of the parameter/property entry in the csn.
38
71
  - Remove redundant `console.log()` statement in `cds lint`
39
72
  - `cds push` now shows complete error messages from extension validation
@@ -66,6 +99,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
66
99
  - `cds add lint:dev` updated to adjust to new api structure of `@sap/eslint-plugin-cds` v2.5.0
67
100
  - `cds init` uses latest Maven Java archetype version 1.27.0 for creating Java projects.
68
101
  - `cds login localhost:<port> -u <username>` now saves username (and empty password, if applicable) with project settings for convenience.
102
+ - `cds add` error handling is improved and will give suggestions if you make a typo.
69
103
 
70
104
  ### Fixed
71
105
 
package/bin/cds.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+
3
4
  const cli = { //NOSONAR
4
5
 
5
6
  Shortcuts: {
@@ -25,10 +26,6 @@ const cli = { //NOSONAR
25
26
  },
26
27
 
27
28
  exec (cmd = process.argv[2], ...argv) {
28
- if (process[Symbol.for('ts-node.register.instance')]) {
29
- process.env.CDS_TYPESCRIPT = process.env.CDS_TYPESCRIPT || 'true'
30
- }
31
- require('util').inspect.defaultOptions = { colors: !!process.stderr.isTTY, depth:11 }
32
29
  if (!argv.length) argv = process.argv.slice(3)
33
30
  if (!cmd) cmd = process.stdin.isTTY ? 'help' : 'compile'
34
31
  if (cmd in this.Shortcuts) cmd = process.argv[2] = this.Shortcuts[cmd]
@@ -93,9 +90,14 @@ function _dieForUnknownCommand(cmd) {
93
90
  const term = require('../lib/util/term');
94
91
  const fuzzySearch = _require('./util/fuzzySearch');
95
92
 
96
- const commands = Array.from(new Set(Object.values(cli.Shortcuts))).sort();
97
93
  let bestMatchText = '';
98
94
 
95
+ const excludeList = ['cds.js', 'cds-ts.js', 'fix-redirects.js'];
96
+ const { readdirSync } = require('fs');
97
+ const commands = readdirSync(__dirname, { withFileTypes: true })
98
+ .filter((f) => f.isFile() && !excludeList.includes(f.name))
99
+ .map((f) => f.name.split('.')[0]).sort();
100
+
99
101
  const bestMatches = fuzzySearch(cmd, commands, DEBUG);
100
102
 
101
103
  switch (bestMatches.length) {
@@ -46,7 +46,8 @@ module.exports = Object.assign(deploy, {
46
46
 
47
47
  Use credentials from the given file when deploying to *SAP HANA*, instead of
48
48
  creating new credentials. File must be in *default-env.json* format, with a root
49
- node *VCAP_SERVICES*.
49
+ node *VCAP_SERVICES*. The following hdi related entries are supported:
50
+ TARGET_CONTAINER, VCAP_SERVICES and SERVICE_REPLACEMENTS.
50
51
 
51
52
  *--store-credentials* (only in combination with *--to hana*)
52
53
 
@@ -114,7 +115,7 @@ async function update_package_json (kind, model, database) {
114
115
  const requires = ['cds','requires'] .reduce ((p,n)=>p[n] || (p[n]={}), conf)
115
116
  requires.db = cds.env.requires.db = { kind, model }
116
117
  if (database) requires.db.credentials = { database }
117
- else if (kind === 'sqlite') requires.db.credentials = { database:'sqlite.db' }
118
+ else if (kind === 'sqlite') requires.db.credentials = { database:'db.sqlite' }
118
119
  await writeFile (package_json, JSON.stringify(conf,null,' '))
119
120
  console.log (`/> ${ exists ? 'updated' : 'created' } ./package.json`)
120
121
  }
@@ -6,14 +6,15 @@ exports.deploy = function deploy_to_sqlite (_model, _db, options) {
6
6
  const model = _model || conf.model || cds.resolve(!fts ? '*' : ['*',fts], false)
7
7
  const file = _database4 (_db, _dbrl, conf)
8
8
  const dialect = _dbrl && _dbrl.match(/^(\w+)/) && RegExp.$1
9
- if (dialect) options.dialect = dialect === 'sql' ? 'plain' : dialect
9
+ if (dialect) options.dialect = dialect === 'sql' ? conf.dialect || 'plain' : dialect
10
10
  return cds.deploy(model) .to ('sqlite:'+file, options)
11
11
  .then (db => db && db.disconnect()) // REVISIT: we should NOT require to disconnect explicitly
12
12
  }
13
13
 
14
14
  function _database4 (_db,_dbrl,conf) {
15
15
  if (_db) return _db
16
- if (_dbrl === 'sqlite') return 'sqlite.db'
16
+ if (conf.credentials?.database) return conf.credentials.database
17
+ if (conf.credentials?.url) return conf.credentials.url
18
+ if (_dbrl === 'sqlite') return 'db.sqlite'
17
19
  if (_dbrl === 'sql') return ':memory:'
18
- if (conf.credentials) return conf.credentials.database || conf.credentials.url
19
20
  }
package/bin/help.js CHANGED
@@ -25,6 +25,10 @@ module.exports = exports = Object.assign (help, {help:`
25
25
  *t* | *lint* [beta] run linter for env or model checks
26
26
  *v* | *version* get detailed version information
27
27
  *?* | *help* get detailed usage information
28
+ * * | *pull* pull the base model for your SaaS app extension.
29
+ * * | *push* push your extension to the SaaS app in order to enable or update it
30
+ * * | *subscribe* subscribe a tenant to a multitenant SaaS app
31
+ * * | *mock* call _cds serve_ with mocked service
28
32
 
29
33
  Learn more about each command using:
30
34
  *cds help* <command> or
package/bin/init.js CHANGED
@@ -100,6 +100,7 @@ function _showWarningMessage () {
100
100
  ************************************************
101
101
  `
102
102
 
103
- const { warn } = require('@sap/cds/bin/utils/term')
103
+ const { warn } = require('../lib/util/term');
104
+
104
105
  console.log(warn(message))
105
106
  }
package/bin/login.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const { bold } = require('../lib/util/term');
2
2
 
3
3
  module.exports = Object.assign(login, {
4
- options: ['--subdomain', '--directory', '--passcode', '--user', '--clientid'],
4
+ options: ['--subdomain', '--directory', '--passcode', '--user', '--client'],
5
5
  shortcuts: ['-s', '-d', '-p', '-u', '-c'],
6
6
  flags: ['--plain'],
7
7
  get help() {
@@ -73,18 +73,28 @@ module.exports = Object.assign(login, {
73
73
 
74
74
  *-u* | *--user* <name>[:[<password>]]
75
75
 
76
- Username and optionally password for authentication with Basic Auth in test scenarios.
76
+ Username and optionally password for authentication with Basic Auth in test scenarios.
77
77
  See https://cap.cloud.sap/docs/guides/multitenancy/#send-subscribe-events for information
78
78
  on suitable mock users.
79
79
 
80
- When typing the colon but omitting <password>, the password is assumed empty.
80
+ When typing the colon but omitting <password>, the password is assumed empty.
81
+ When omitting both, password will be queried interactively.
81
82
 
82
83
  For security reasons, username will only be saved for app URLs that look like localhost.
83
84
  The same is true for an empty password. Non-empty passwords will never be saved.
85
+
86
+ Note: Productive secrets should not be specified on a command line, since this might expose them to
87
+ unauthorized users on the same machine!
84
88
 
85
- *-c* | *--clientid* <clientid>
89
+ *-c* | *--client* <clientid>[:<clientsecret>]
86
90
 
87
- Client ID for authentication. This will override the default Client ID from environment.
91
+ Client ID and optionally Client Secret for authentication. If omitted, Client Secret will be
92
+ queried interactively.
93
+
94
+ Neither Client ID nor Client Secret will be saved, only the resulting token.
95
+
96
+ Note: Productive secrets should not be specified on a command line, since this might expose them to
97
+ unauthorized users on the same machine!
88
98
 
89
99
  *--plain*
90
100
 
@@ -107,23 +117,27 @@ module.exports = Object.assign(login, {
107
117
 
108
118
  *cds logout* to remove any authentication data
109
119
  `
110
- }})
120
+ }});
111
121
 
112
122
 
113
123
  async function login ([url], options = {}) {
114
124
  const [username, password] = options.user?.split(':') ?? [];
115
125
  delete options.user;
126
+ const [clientid, clientsecret] = options.client?.split(':') ?? [];
127
+ delete options.client;
116
128
  Object.assign(options, {
117
129
  url,
118
130
  username,
119
131
  password,
132
+ clientid,
133
+ clientsecret,
120
134
  tokenStorage: options.plain ? 'plain' : 'keyring',
121
135
  renewLogin: true,
122
136
  saveData: true
123
- })
124
- delete options.plain
137
+ });
138
+ delete options.plain;
125
139
 
126
- await require('../lib/client/auth_manager').login(options)
140
+ await require('../lib/client/auth_manager').login(options);
127
141
  }
128
142
 
129
143
 
package/bin/mock.js CHANGED
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line
1
2
  const serve = require ('@sap/cds/bin/serve')
2
3
  module.exports = Object.assign (
3
4
  cds_mock, serve, {help: `
package/bin/pull.js CHANGED
@@ -1,25 +1,17 @@
1
1
  module.exports = Object.assign(pull, {
2
- options: ['--directory', '--subdomain', '--passcode', '--username', '--clientid'],
2
+ options: ['--directory', '--subdomain', '--passcode', '--user', '--client', '--from'],
3
3
  flags: [],
4
4
  shortcuts: ['-d', '-s', '-p', '-u', '-c'],
5
5
  help: `
6
6
  # SYNOPSIS
7
7
 
8
- *cds pull* [ <app-url> ]
8
+ *cds pull* [ [--from] <app url> ]
9
9
 
10
10
  Pull the base model for your SaaS app extension.
11
-
12
- To run this command, you need to obtain from the SaaS application provider:
13
- - the app URL
14
- - a template for your extension project.
15
-
16
- Then create your extension project from the template and run *cds pull* to update your copy of the CDS model of the
17
- SaaS app (also known as the base model).
18
-
19
- To facilitate running this multiple times against the same app, refer to the *cds login* command.
20
-
21
11
  If the app URL is omitted, it is determined from the current user's active CDS or Cloud Foundry login.
22
12
 
13
+ Authentication data will not be saved.
14
+
23
15
 
24
16
  # OPTIONS
25
17
 
@@ -35,24 +27,37 @@ module.exports = Object.assign(pull, {
35
27
 
36
28
  Tenant-specific passcode for authentication.
37
29
 
38
- *-u* | *--username* <name>
30
+ *-u* | *--user* <name>[:[<password>]]
39
31
 
40
- Username for authentication with Basic Auth in test scenarios.
32
+ Username and optionally password for authentication with Basic Auth in test scenarios.
41
33
 
42
- *-c* | *--clientid* <clientid>
34
+ *-c* | *--client* <clientid>[:<clientsecret>]
43
35
 
44
- Client ID for authentication. This will override the default Client ID from environment.
36
+ Client ID and optionally Client Secret for authentication.
45
37
 
46
38
  # SEE ALSO
47
39
 
48
40
  *cds push* to push an extension to the SaaS app.
49
-
50
- `})
41
+ *cds login* for more information on authentication options.
42
+ *cds login* to save authentication data, simplifying multiple runs of *cds pull* and *cds push* against the same app.
43
+
44
+ `});
51
45
 
52
46
 
53
47
  async function pull([url], options = {}) {
48
+ const [username, password] = options.user?.split(':') ?? [];
49
+ delete options.user;
50
+ const [clientid, clientsecret] = options.client?.split(':') ?? [];
51
+ delete options.client;
52
+ if (options.from) url = options.from
53
+ delete options.from
54
+
54
55
  await require('../lib/client/pull').run({
55
56
  ...options,
56
- url
57
+ url,
58
+ username,
59
+ password,
60
+ clientid,
61
+ clientsecret
57
62
  })
58
63
  }
package/bin/push.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = Object.assign(push, {
2
- options: ['--subdomain', '--passcode', '--username', '--clientid', '--to'],
2
+ options: ['--subdomain', '--passcode', '--user', '--client', '--to'],
3
3
  flags: [],
4
4
  shortcuts: ['-s', '-p', '-u', '-c'],
5
5
  help: `
@@ -8,10 +8,10 @@ module.exports = Object.assign(push, {
8
8
  *cds push* [ <extension-project-directory> ]
9
9
 
10
10
  Push your extension to the SaaS app in order to enable or update it.
11
-
11
+
12
12
  By default, the current working directory is used as project directory.
13
13
 
14
- To facilitate running this multiple times against the same app, refer to the *cds login* command.
14
+ Authentication data will not be saved.
15
15
 
16
16
 
17
17
  # OPTIONS
@@ -29,24 +29,35 @@ module.exports = Object.assign(push, {
29
29
 
30
30
  Tenant-specific passcode for authentication.
31
31
 
32
- *-u* | *--username* <name>
32
+ *-u* | *--user* <name>[:[<password>]]
33
33
 
34
- Username for authentication with Basic Auth in test scenarios.
34
+ Username and optionally password for authentication with Basic Auth in test scenarios.
35
35
 
36
- *-c* | *--clientid* <clientid>
36
+ *-c* | *--client* <clientid>[:<clientsecret>]
37
37
 
38
- Client ID for authentication. This will override the default Client ID from environment.
38
+ Client ID and optionally Client Secret for authentication.
39
39
 
40
40
  # SEE ALSO
41
41
 
42
42
  *cds pull* to get the CDS model of the SaaS app.
43
+ *cds login* for more information on authentication options.
44
+ *cds login* to save authentication data, simplifying multiple runs of *cds pull* and *cds push* against the same app.
43
45
 
44
- `})
46
+ `});
45
47
 
46
48
 
47
49
  async function push([projectFolder], options = {}) {
50
+ const [username, password] = options.user?.split(':') ?? [];
51
+ delete options.user;
52
+ const [clientid, clientsecret] = options.client?.split(':') ?? [];
53
+ delete options.client;
54
+
48
55
  await require('../lib/client/push').run({
49
56
  ...options,
50
- projectFolder
57
+ projectFolder,
58
+ username,
59
+ password,
60
+ clientid,
61
+ clientsecret
51
62
  })
52
63
  }
package/bin/subscribe.js CHANGED
@@ -22,7 +22,7 @@ module.exports = Object.assign(subscribe, {
22
22
 
23
23
  Username and optionally password for authentication. Required setting.
24
24
  See https://cap.cloud.sap/docs/guides/multitenancy/#send-subscribe-events for information on suitable mock users.
25
-
25
+
26
26
  If password is omitted, it is assumed empty.
27
27
  Note: productive passwords should not be specified on the command line.
28
28
 
@@ -31,15 +31,45 @@ module.exports = Object.assign(subscribe, {
31
31
 
32
32
 
33
33
  async function subscribe([tenant], { to: url, user } = {}) {
34
- const Logger = require('../lib/client/helper/logging');
35
-
36
- if (!tenant) throw new Error('Must provide a tenant')
37
- if (!url) throw new Error('Must provide an app URL via `--to`') // for now, if we don't infer it from the project
38
- if (typeof user !== 'string') throw new Error('Must provide a username')
39
- const [username, password = ''] = user.split(':');
40
- Logger.log(`Subscribing to ${url} for tenant '${tenant}' with user '${username}'${password === '' ? ' and empty password' : ''}`);
41
- const options = { auth: { username, password } };
42
- return require('axios').post (url+'/-/cds/deployment/subscribe', { tenant }, options);
34
+
35
+ const cds = require('../lib/cds')
36
+
37
+ // check for application environment
38
+ // fails for edge cases (ignored for now):
39
+ // @sap/cds-mtx application with missing modules (no npm install)
40
+ // dev scenario with both @sap/cds-mtx and @sap/cds-mtxs installed
41
+ function _hasMtEnv() {
42
+ return cds.requires.multitenancy && !cds.mtx
43
+ }
44
+
45
+
46
+ if (!tenant) {
47
+ console.error('Must provide a tenant')
48
+ return this.help('subscribe')
49
+ }
50
+ if (!url) {
51
+ // check whether we are in a mt(xs) environment
52
+ if (!_hasMtEnv()) throw new Error('Local cds subscribe operation can only be run inside a multitenant application environment using @sap/cds-mtxs. Please specify application url (--to <url>) if you want to subscribe from remote')
53
+ console.log ('\nSubscribing', {tenant})
54
+ const { 'cds.xt.DeploymentService':ds } = await cds.serve ([
55
+ '@sap/cds-mtxs/srv/deployment-service',
56
+ '@sap/cds-mtxs/srv/model-provider'
57
+ ])
58
+ cds.emit('served')
59
+ // await cds.connect.to('db')
60
+ await ds.subscribe(tenant)
61
+ } else {
62
+ // Connecting to a deployment service in a subscribed application
63
+ if (typeof user !== 'string') throw new Error('Must provide a username')
64
+ const [username, password = ''] = user.split(':');
65
+ console.log ('\nSubscribing', {tenant}, 'to', {url})
66
+ await require('axios').post (url+'/-/cds/deployment/subscribe', {
67
+ tenant
68
+ }, {
69
+ auth: { username, password }
70
+ });
71
+ }
72
+ console.log('Subscription succeeded.\n')
43
73
  }
44
74
 
45
75
  // cds subscribe t1 --to http://localhost:4004 -u yves
package/bin/watch.js CHANGED
@@ -45,16 +45,19 @@ module.exports = Object.assign ( watch, {
45
45
  const DEBUG = /\bwatch\b/.test(process.env.DEBUG) && console.debug
46
46
  const {delimiter,dirname,relative,resolve,sep} = require ('path')
47
47
  const fs = require ('fs')
48
+
49
+ const colors = !!process.stdout.isTTY && !!process.stderr.isTTY
48
50
  const t = module.exports.codes = {
49
- reset: '\x1b[0m', // Default
50
- bold: '\x1b[1m', // Bold/Bright
51
- link: '\x1b[4m', // underline
52
- red: '\x1b[91m', // Bright Foreground Red
53
- green: '\x1b[32m', // Foreground Green
54
- yellow: '\x1b[33m', // Foreground Green
55
- orange: '\x1b[38;2;255;140;0m' // darker orange, works with bright and dark background
51
+ reset: colors ? '\x1b[0m' : '', // Default
52
+ bold: colors ? '\x1b[1m' : '', // Bold/Bright
53
+ link: colors ? '\x1b[4m' : '', // underline
54
+ red: colors ? '\x1b[91m' : '', // Bright Foreground Red
55
+ green: colors ? '\x1b[32m' : '', // Foreground Green
56
+ yellow: colors ? '\x1b[33m' : '', // Foreground Green
57
+ orange: colors ? '\x1b[38;2;255;140;0m' : '' // darker orange, works with bright and dark background
56
58
  }
57
59
  const extDefaults = 'cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml,env'
60
+ const fioriIncludes = /_?(change|variant)$/ // according to fiori: change,variant,ctrl_variant,ctrl_variant_change,ctrl_variant_management_change.
58
61
  let ignore = /node_modules|target|\.cds-services\.json$/
59
62
 
60
63
  async function watch ([cwd], {
@@ -80,10 +83,12 @@ async function watch ([cwd], {
80
83
 
81
84
  if (typeof ext !== 'string') ext = extDefaults
82
85
 
86
+ let includes
83
87
  let liveReload //= ...
84
88
  let firstTime = true
85
89
  if (!/false|no/.test(options['livereload'])) {
86
90
  ext += ',css,gif,html,jpg,png,svg'
91
+ includes = fioriIncludes
87
92
  liveReload = new (require ('../lib/watch/livereload-server'))
88
93
  env.CDS_LIVERELOAD_PATH = require.resolve ('connect-livereload')
89
94
  env.CDS_LIVERELOAD_URL = await liveReload.start (options['livereload'])
@@ -104,6 +109,7 @@ async function watch ([cwd], {
104
109
  log ()
105
110
  log (`${t.bold}cds ${args.join(' ')}`)
106
111
  log (`watching: ${ext}...`)
112
+ DEBUG && log (`also watching: ${includes.source}`)
107
113
  if (liveReload) log (`live reload enabled for browsers`)
108
114
 
109
115
  const BindingManager = require('../lib/bind/BindingManager')
@@ -113,11 +119,11 @@ async function watch ([cwd], {
113
119
 
114
120
  const nodemon = require('../lib/watch/node-watch')
115
121
  const watcher = nodemon ({
116
- watch: ['*','.env','.cdsrc.json'],
117
- script:__filename, cwd, env, ext, ignore,
122
+ script:__filename, cwd, env, ext, includes, ignore,
118
123
  delay: parseInt(process.env.CDS_WATCH_DELAY) || 200,
119
124
  options
120
125
  }).on('restart', (files)=>{
126
+ log (`\n${t.bold} ___________________________\n\n`)
121
127
  DEBUG && DEBUG (files)
122
128
  if (liveReload) liveReload.markPending(files)
123
129
  if (this.delayed) clearTimeout (this.delayed)
@@ -129,7 +135,6 @@ async function watch ([cwd], {
129
135
  watcher.restart()
130
136
  }
131
137
  })
132
- log (`\n${t.bold} ___________________________\n\n`)
133
138
  FileHandlers.changed (files,cwd)
134
139
  }, 111)
135
140
  }).on('message', async (msg) => { switch (msg.code) { // messages from child process
@@ -158,6 +158,7 @@ function readBinding(name, secret) {
158
158
 
159
159
  let parseBinding
160
160
  try {
161
+ // eslint-disable-next-line
161
162
  parseBinding = require('@sap/cds/lib/env/serviceBindings').parseBinding;
162
163
  } catch (error) {
163
164
  //