@sap/cds 7.9.4 → 8.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -3659
- package/_i18n/i18n_en_US_saptrc.properties +113 -0
- package/_i18n/i18n_zh_CN.properties +7 -4
- package/app/index.css +129 -0
- package/app/index.html +16 -64
- package/app/index.js +14 -9
- package/bin/args.js +34 -0
- package/bin/serve.js +18 -24
- package/bin/test.js +97 -0
- package/common.cds +5 -12
- package/eslint.config.mjs +133 -0
- package/lib/auth/basic-auth.js +16 -20
- package/lib/auth/dummy-auth.js +1 -1
- package/lib/auth/ias-auth.js +9 -41
- package/lib/auth/index.js +1 -14
- package/lib/auth/jwt-auth.js +10 -40
- package/lib/compile/cds-compile.js +1 -2
- package/lib/compile/cdsc.js +21 -26
- package/lib/compile/etc/_localized.js +1 -6
- package/lib/compile/etc/csv.js +1 -1
- package/lib/compile/etc/properties.js +1 -1
- package/lib/compile/for/java.js +1 -1
- package/lib/compile/for/lean_drafts.js +4 -6
- package/lib/compile/for/nodejs.js +1 -1
- package/lib/compile/parse.js +4 -0
- package/lib/compile/resolve.js +4 -4
- package/lib/compile/to/edm-files.js +16 -23
- package/lib/compile/to/hana.js +27 -0
- package/lib/compile/to/json.js +1 -1
- package/lib/compile/to/sql.js +5 -1
- package/lib/compile/to/yaml.js +3 -3
- package/lib/dbs/cds-deploy.js +4 -2
- package/lib/env/cds-env.js +10 -14
- package/lib/env/cds-requires.js +30 -13
- package/lib/env/defaults.js +46 -16
- package/lib/env/plugins.js +1 -1
- package/lib/env/schemas/cds-rc.js +8 -4
- package/lib/env/schemas/index.js +7 -7
- package/lib/env/serviceBindings.js +1 -1
- package/lib/index.js +12 -10
- package/lib/lazy.js +1 -1
- package/lib/linked/classes.js +36 -8
- package/lib/linked/entities.js +2 -10
- package/lib/linked/models.js +2 -1
- package/lib/linked/validate.js +292 -0
- package/lib/log/cds-error.js +0 -6
- package/lib/log/cds-log.js +3 -3
- package/lib/log/format/json.js +1 -1
- package/lib/log/service/index.js +0 -1
- package/lib/plugins.js +2 -2
- package/lib/ql/Query.js +2 -10
- package/lib/ql/SELECT.js +1 -1
- package/lib/ql/Whereable.js +3 -2
- package/lib/req/cds-context.js +14 -25
- package/lib/req/context.js +23 -25
- package/lib/req/request.js +1 -34
- package/lib/req/user.js +47 -35
- package/lib/srv/bindings.js +1 -1
- package/lib/srv/cds-connect.js +4 -4
- package/lib/srv/cds-serve.js +2 -2
- package/lib/srv/factory.js +1 -1
- package/lib/srv/middlewares/cds-context.js +11 -22
- package/lib/srv/middlewares/ctx-model.js +2 -3
- package/lib/srv/middlewares/errors.js +41 -8
- package/lib/srv/middlewares/index.js +3 -3
- package/lib/srv/middlewares/trace.js +0 -2
- package/lib/srv/protocols/hcql.js +15 -10
- package/lib/srv/protocols/http.js +44 -49
- package/lib/srv/protocols/index.js +1 -23
- package/lib/srv/protocols/odata-v4.js +12 -74
- package/lib/srv/protocols/rest.js +1 -13
- package/lib/srv/srv-api.js +0 -20
- package/lib/srv/srv-dispatch.js +3 -2
- package/lib/srv/srv-handlers.js +22 -11
- package/lib/srv/srv-methods.js +2 -2
- package/lib/srv/srv-models.js +3 -36
- package/lib/test/expect.js +343 -0
- package/lib/test/index.js +2 -0
- package/lib/test/reporter.js +176 -0
- package/lib/utils/axios.js +10 -9
- package/lib/utils/cds-test.js +85 -36
- package/lib/utils/cds-utils.js +54 -7
- package/lib/utils/check-version.js +0 -4
- package/lib/utils/colors.js +49 -0
- package/lib/utils/data.js +5 -4
- package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +2 -7
- package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +3 -30
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +6 -12
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +1 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +0 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +4 -7
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +12 -6
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +2 -4
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/applyToCQN.js +1 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/index.js +0 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +1 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/edm/AbstractEdmStructuredType.js +1 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/deserializer/ResourceJsonDeserializer.js +5 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/ContextURLFactory.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +9 -43
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/metaInfo.js +0 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +8 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/request.js +4 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +1 -3
- package/libx/_runtime/cds-services/util/assert.js +1 -1
- package/libx/_runtime/cds.js +10 -3
- package/libx/_runtime/common/Service.js +12 -32
- package/libx/_runtime/common/aspects/any.js +1 -0
- package/libx/_runtime/common/code-ext/execute.js +1 -1
- package/libx/_runtime/common/code-ext/worker.js +0 -1
- package/libx/_runtime/common/composition/data.js +0 -1
- package/libx/_runtime/common/composition/delete.js +0 -1
- package/libx/_runtime/common/composition/tree.js +0 -1
- package/libx/_runtime/common/composition/update.js +3 -3
- package/libx/_runtime/common/error/frontend.js +21 -12
- package/libx/_runtime/common/error/log.js +36 -0
- package/libx/_runtime/common/error/utils.js +2 -5
- package/libx/_runtime/common/generic/auth/autoexpose.js +18 -17
- package/libx/_runtime/common/generic/auth/expand.js +1 -1
- package/libx/_runtime/common/generic/auth/readOnly.js +1 -2
- package/libx/_runtime/common/generic/auth/restrict.js +23 -42
- package/libx/_runtime/common/generic/auth/restrictions.js +2 -7
- package/libx/_runtime/common/generic/auth/utils.js +91 -88
- package/libx/_runtime/common/generic/crud.js +6 -5
- package/libx/_runtime/common/generic/etag.js +7 -12
- package/libx/_runtime/common/generic/input.js +70 -68
- package/libx/_runtime/common/generic/paging.js +1 -0
- package/libx/_runtime/common/generic/sorting.js +1 -0
- package/libx/_runtime/common/generic/temporal.js +8 -2
- package/libx/_runtime/common/i18n/index.js +1 -1
- package/libx/_runtime/common/i18n/messages.properties +3 -1
- package/libx/_runtime/common/utils/binary.js +8 -2
- package/libx/_runtime/common/utils/compareJson.js +5 -1
- package/libx/_runtime/common/utils/copy.js +6 -11
- package/libx/_runtime/common/utils/cqn2cqn4sql.js +16 -14
- package/libx/_runtime/common/utils/differ.js +3 -6
- package/libx/_runtime/common/utils/keys.js +77 -18
- package/libx/_runtime/common/utils/postProcess.js +12 -15
- package/libx/_runtime/common/utils/propagateForeignKeys.js +0 -1
- package/libx/_runtime/common/utils/resolveView.js +2 -3
- package/libx/_runtime/common/utils/restrictions.js +45 -17
- package/libx/_runtime/common/utils/rewriteAsterisks.js +1 -8
- package/libx/_runtime/common/utils/stream.js +3 -16
- package/libx/_runtime/common/utils/streamProp.js +8 -18
- package/libx/_runtime/common/utils/structured.js +1 -1
- package/libx/_runtime/common/utils/ucsn.js +0 -2
- package/libx/_runtime/db/Service.js +0 -72
- package/libx/_runtime/db/data-conversion/post-processing.js +0 -1
- package/libx/_runtime/db/expand/expandCQNToJoin.js +9 -9
- package/libx/_runtime/db/expand/rawToExpanded.js +0 -8
- package/libx/_runtime/db/generic/input.js +3 -8
- package/libx/_runtime/db/generic/rewrite.js +1 -0
- package/libx/_runtime/db/query/read.js +2 -2
- package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +0 -1
- package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -1
- package/libx/_runtime/db/utils/columns.js +2 -6
- package/libx/_runtime/fiori/lean-draft.js +138 -56
- package/libx/_runtime/hana/Service.js +0 -1
- package/libx/_runtime/hana/driver.js +1 -1
- package/libx/_runtime/hana/dynatrace.js +1 -2
- package/libx/_runtime/hana/pool.js +11 -21
- package/libx/_runtime/hana/streaming.js +0 -1
- package/libx/_runtime/messaging/common-utils/AMQPClient.js +0 -1
- package/libx/_runtime/messaging/common-utils/authorizedRequest.js +1 -1
- package/libx/_runtime/messaging/common-utils/normalizeIncomingMessage.js +1 -1
- package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +1 -1
- package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +19 -33
- package/libx/_runtime/messaging/event-broker.js +54 -27
- package/libx/_runtime/messaging/file-based.js +3 -3
- package/libx/_runtime/messaging/http-utils/token.js +1 -1
- package/libx/_runtime/messaging/kafka.js +2 -2
- package/libx/_runtime/messaging/redis-messaging.js +0 -1
- package/libx/_runtime/remote/Service.js +25 -25
- package/libx/_runtime/remote/utils/client.js +4 -5
- package/libx/_runtime/remote/utils/cloudSdkProvider.js +0 -3
- package/libx/_runtime/remote/utils/data.js +0 -1
- package/libx/_runtime/sqlite/Service.js +1 -2
- package/libx/_runtime/ucl/Service.js +37 -78
- package/libx/common/assert/index.js +22 -21
- package/libx/common/assert/type-relaxed.js +39 -0
- package/libx/common/assert/utils.js +3 -2
- package/libx/common/assert/validation.js +3 -8
- package/libx/common/utils/index.js +5 -0
- package/libx/common/utils/path.js +51 -0
- package/libx/odata/ODataAdapter.js +126 -0
- package/libx/odata/index.js +15 -2
- package/libx/odata/middleware/batch.js +320 -84
- package/libx/odata/middleware/body-parser.js +33 -0
- package/libx/odata/middleware/create.js +44 -59
- package/libx/odata/middleware/delete.js +23 -12
- package/libx/odata/middleware/error.js +30 -6
- package/libx/odata/middleware/metadata.js +38 -26
- package/libx/odata/middleware/operation.js +93 -69
- package/libx/odata/middleware/parse.js +6 -8
- package/libx/odata/middleware/read.js +117 -93
- package/libx/odata/middleware/service-document.js +22 -19
- package/libx/odata/middleware/stream.js +54 -56
- package/libx/odata/middleware/update.js +79 -87
- package/libx/odata/parse/afterburner.js +191 -175
- package/libx/odata/parse/cqn2odata.js +5 -5
- package/libx/odata/parse/grammar.peggy +27 -20
- package/libx/odata/parse/multipartToJson.js +17 -9
- package/libx/odata/parse/parser.js +1 -1
- package/libx/odata/utils/etag.js +14 -6
- package/libx/odata/utils/index.js +84 -12
- package/libx/odata/utils/metadata.js +161 -0
- package/libx/odata/utils/postProcess.js +89 -0
- package/libx/odata/utils/readAfterWrite.js +134 -17
- package/libx/odata/utils/result.js +36 -142
- package/libx/outbox/index.js +4 -3
- package/libx/rest/RestAdapter.js +115 -182
- package/libx/rest/middleware/create.js +28 -24
- package/libx/rest/middleware/delete.js +7 -10
- package/libx/rest/middleware/error.js +26 -16
- package/libx/rest/middleware/operation.js +48 -41
- package/libx/rest/middleware/parse.js +128 -126
- package/libx/rest/middleware/read.js +20 -27
- package/libx/rest/middleware/update.js +26 -31
- package/package.json +17 -8
- package/server.js +4 -2
- package/apis/cds.d.ts +0 -3
- package/apis/core.d.ts +0 -21
- package/apis/cqn.d.ts +0 -18
- package/apis/csn.d.ts +0 -21
- package/apis/events.d.ts +0 -18
- package/apis/internal/inference.d.ts +0 -18
- package/apis/linked.d.ts +0 -18
- package/apis/log.d.ts +0 -20
- package/apis/models.d.ts +0 -18
- package/apis/ql.d.ts +0 -18
- package/apis/reflect.d.ts +0 -32
- package/apis/server.d.ts +0 -18
- package/apis/services.d.ts +0 -22
- package/bin/cds-serve.js +0 -56
- package/lib/compile/to/gql.js +0 -15
- package/lib/srv/protocols/_legacy.js +0 -44
- package/lib/utils/jest.js +0 -43
- package/libx/_runtime/auth/index.js +0 -193
- package/libx/_runtime/auth/strategies/JWT.js +0 -37
- package/libx/_runtime/auth/strategies/basic.js +0 -20
- package/libx/_runtime/auth/strategies/dummy.js +0 -14
- package/libx/_runtime/auth/strategies/ias-auth.js +0 -1
- package/libx/_runtime/auth/strategies/mock.js +0 -77
- package/libx/_runtime/auth/strategies/xssecUtils.js +0 -93
- package/libx/_runtime/auth/strategies/xsuaa.js +0 -38
- package/libx/_runtime/common/perf/index.js +0 -19
- package/libx/_runtime/common/utils/ensureIEEE754.js +0 -29
- package/libx/_runtime/fiori/draft.js +0 -2
- package/libx/_runtime/fiori/generic/activate.js +0 -190
- package/libx/_runtime/fiori/generic/before.js +0 -201
- package/libx/_runtime/fiori/generic/cancel.js +0 -19
- package/libx/_runtime/fiori/generic/delete.js +0 -21
- package/libx/_runtime/fiori/generic/edit.js +0 -157
- package/libx/_runtime/fiori/generic/index.js +0 -25
- package/libx/_runtime/fiori/generic/new.js +0 -82
- package/libx/_runtime/fiori/generic/patch.js +0 -101
- package/libx/_runtime/fiori/generic/prepare.js +0 -57
- package/libx/_runtime/fiori/generic/read.js +0 -1340
- package/libx/_runtime/fiori/generic/readOverDraft.js +0 -146
- package/libx/_runtime/fiori/utils/csn.js +0 -13
- package/libx/_runtime/fiori/utils/delete.js +0 -114
- package/libx/_runtime/fiori/utils/handler.js +0 -264
- package/libx/_runtime/fiori/utils/lockInfo.js +0 -27
- package/libx/_runtime/fiori/utils/req.js +0 -23
- package/libx/_runtime/fiori/utils/stream.js +0 -36
- package/libx/_runtime/fiori/utils/where.js +0 -254
- package/libx/_runtime/index.js +0 -22
- package/libx/odata/utils/handler.js +0 -120
- package/libx/odata/utils/metaInfo.js +0 -410
- package/libx/odata/utils/path.js +0 -75
- package/libx/rest/RestRequest.js +0 -32
- package/libx/rest/index.js +0 -3
- package/libx/rest/readme.md +0 -1
- /package/libx/common/assert/{type.js → type-strict.js} +0 -0
package/apis/cds.d.ts
DELETED
package/apis/core.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/core'
|
|
19
|
-
|
|
20
|
-
// this was moved to 'events' with 7.4
|
|
21
|
-
export { User } from '@cap-js/cds-types'
|
package/apis/cqn.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/cqn'
|
package/apis/csn.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/csn'
|
|
19
|
-
|
|
20
|
-
// this got moved to 'linked' with 7.4
|
|
21
|
-
export { Definitions } from '@cap-js/cds-types/apis/linked'
|
package/apis/events.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/events'
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/internal/inference'
|
package/apis/linked.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/linked'
|
package/apis/log.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export { Logger } from '@cap-js/cds-types/apis/log'
|
|
20
|
-
|
package/apis/models.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/models'
|
package/apis/ql.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/ql'
|
package/apis/reflect.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/linked'
|
|
19
|
-
|
|
20
|
-
// 'reflect' got removed with 7.4
|
|
21
|
-
// Also, these got removed/renamed in 7.4
|
|
22
|
-
export {
|
|
23
|
-
CSN as ParsedModel,
|
|
24
|
-
Definition,
|
|
25
|
-
entity
|
|
26
|
-
} from '@cap-js/cds-types/apis/csn'
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
Definitions as ReflectedDefinitions,
|
|
30
|
-
LinkedCSN as LinkedModel,
|
|
31
|
-
LinkedCSN as ReflectedModel,
|
|
32
|
-
} from '@cap-js/cds-types/apis/linked'
|
package/apis/server.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/server'
|
package/apis/services.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NO LONGER IMPORT THIS FILE
|
|
3
|
-
*
|
|
4
|
-
* Instead use:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```
|
|
8
|
-
* import * as cds from '@sap/cds'
|
|
9
|
-
* cds.Request
|
|
10
|
-
* or
|
|
11
|
-
* import { Request } from '@sap/cds'
|
|
12
|
-
* or
|
|
13
|
-
* @type { import('@sap/cds').Request }
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
export * from '@cap-js/cds-types/apis/services'
|
|
19
|
-
|
|
20
|
-
// this got moved to 'events' in 7.4
|
|
21
|
-
export { Request } from '@cap-js/cds-types/apis/events'
|
|
22
|
-
|
package/bin/cds-serve.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const cds = require('../lib') //> ensure we are the first to load @sap/cds locally
|
|
3
|
-
const cli = {
|
|
4
|
-
|
|
5
|
-
exec (...argv) {
|
|
6
|
-
if (!argv.length) argv = process.argv.slice(2)
|
|
7
|
-
const task = require ('./serve')
|
|
8
|
-
|
|
9
|
-
let args = []
|
|
10
|
-
try {
|
|
11
|
-
args = this.args(task, argv)
|
|
12
|
-
} catch (err) { process.exitCode = 1; return console.error(err) }
|
|
13
|
-
|
|
14
|
-
return task.apply (this, args)
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
// TODO replace w/ common arg parser from node
|
|
18
|
-
args (task, argv) {
|
|
19
|
-
|
|
20
|
-
const { options:o=[], flags:f=[], shortcuts:s=[] } = task
|
|
21
|
-
const _global = /^--(profile|production|sql|odata|build-.*|cdsc-.*|odata-.*|folders-.*)$/
|
|
22
|
-
const _flags = { '--production':true }
|
|
23
|
-
const options = {}, args = []
|
|
24
|
-
let k,a, env = null
|
|
25
|
-
|
|
26
|
-
if (argv.length) for (let i=0; i < argv.length; ++i) {
|
|
27
|
-
if ((a = argv[i])[0] !== '-') args.push(a)
|
|
28
|
-
else if ((k = s.indexOf(a)) >= 0) k < o.length ? add(o[k],argv[++i]) : add(f[k-o.length])
|
|
29
|
-
else if ((k = o.indexOf(a)) >= 0) add(o[k],argv[++i])
|
|
30
|
-
else if ((k = f.indexOf(a)) >= 0) add(f[k])
|
|
31
|
-
else if (_global.test(a)) add_global(a, _flags[a] || argv[++i])
|
|
32
|
-
else throw 'Invalid option: '+ a
|
|
33
|
-
}
|
|
34
|
-
// consistent production setting for NODE_ENV and CDS_ENV
|
|
35
|
-
if (process.env.NODE_ENV !== 'production') process.env.NODE_ENV = process.env.CDS_ENV?.split(',').find(p => p === 'production') || process.env.NODE_ENV
|
|
36
|
-
else process.env.CDS_ENV = Array.from(new Set([...process.env.CDS_ENV?.split(',') ?? [], 'production']))
|
|
37
|
-
|
|
38
|
-
function add (k,v) { options[k.slice(2)] = v || true }
|
|
39
|
-
function add_global (k,v='') {
|
|
40
|
-
if (k === '--production') return process.env.CDS_ENV = Array.from(new Set([...process.env.CDS_ENV?.split(',') ?? [], 'production']))
|
|
41
|
-
if (k === '--profile') return process.env.CDS_ENV = Array.from(new Set([...process.env.CDS_ENV?.split(',') ?? [], ...v.split(',')]))
|
|
42
|
-
if (k === '--odata') v = { flavor:v }
|
|
43
|
-
let e=env || (env={}), path = k.slice(2).split('-')
|
|
44
|
-
while (path.length > 1) { let p = path.shift(); e = e[p]||(e[p]={}) }
|
|
45
|
-
add (k, e[path[0]] = v)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (env) cds.env.add (env)
|
|
49
|
-
return [ args, options ]
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = Object.assign ((..._) => cli.exec(..._), cli)
|
|
54
|
-
if (!module.parent) cli.exec()
|
|
55
|
-
|
|
56
|
-
/* eslint no-console:off */
|
package/lib/compile/to/gql.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const cds = require ('../..')
|
|
2
|
-
const LOG = cds.log()
|
|
3
|
-
// eslint-disable-next-line cds/no-missing-dependencies -- needs to be added by app dev
|
|
4
|
-
const { SchemaGenerator } = require('@cap-js/graphql/lib/schema')
|
|
5
|
-
|
|
6
|
-
// REVISIT: remove module with cds^8
|
|
7
|
-
function cds_compile_to_gql (csn) {
|
|
8
|
-
LOG._warn && LOG.warn('WARNING: cds.compile.to.gql and .to.graphql will require @cap-js/graphql >= 0.9.0 with an upcoming release. Please update your dependency.')
|
|
9
|
-
|
|
10
|
-
const m = cds.linked(csn)
|
|
11
|
-
const services = Object.fromEntries(m.services.map(s => [s.name, new cds.ApplicationService(s.name, m)]))
|
|
12
|
-
return new SchemaGenerator().generate(services).printSchema()
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = cds_compile_to_gql
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const cds = require('../../index')
|
|
2
|
-
cds.env.features.serve_on_root = true
|
|
3
|
-
|
|
4
|
-
const protocols = require('.'), { serve } = protocols
|
|
5
|
-
protocols['odata-v4'] = { ...protocols['odata-v4'], get impl() { return libx.to.odata_v4 } }
|
|
6
|
-
protocols['odata'] = { ...protocols['odata'], get impl() { return libx.to.odata_v4 } }
|
|
7
|
-
protocols['rest'] = { ...protocols['rest'], get impl() { return libx.to.rest } }
|
|
8
|
-
|
|
9
|
-
const cds_context_model = require('../srv-models')
|
|
10
|
-
const cds_context = require('../middlewares/cds-context')()
|
|
11
|
-
const ctx_auth = require('../../auth')._ctx_auth
|
|
12
|
-
const libx = require('../../../libx/_runtime')
|
|
13
|
-
|
|
14
|
-
Object.defineProperty (protocols, 'serve', {
|
|
15
|
-
value: function _serve_legacy_adapter4 (srv, app) {
|
|
16
|
-
const endpoints = this.endpoints4 (srv)
|
|
17
|
-
if (endpoints.length > 1)
|
|
18
|
-
throw cds.error `Cannot serve multiple endpoints if cds.requires.middlewares is set to false`
|
|
19
|
-
return serve (srv, app, {
|
|
20
|
-
before: [
|
|
21
|
-
cds_context,
|
|
22
|
-
libx.perf,
|
|
23
|
-
libx.auth(srv), ctx_auth,
|
|
24
|
-
cap_req_logger,
|
|
25
|
-
cds_context_model.middleware4(srv)
|
|
26
|
-
],
|
|
27
|
-
after:[]
|
|
28
|
-
})
|
|
29
|
-
}.bind(protocols)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const LOG = cds.log(), DEBUG = cds.debug()
|
|
33
|
-
function cap_req_logger (req,_,next) {
|
|
34
|
-
let url = req.originalUrl
|
|
35
|
-
try { url = decodeURI(req.originalUrl) } catch (e) { /* decodeURI throws error for invalid urls */ }
|
|
36
|
-
LOG && LOG (req.method, url, req.body||'')
|
|
37
|
-
if (/\$batch/.test(req.url)) req.on ('dispatch', (req) => {
|
|
38
|
-
let path = req._path
|
|
39
|
-
try { path = decodeURI(req._path) } catch (e) { /* decodeURI throws error for invalid urls */ }
|
|
40
|
-
LOG && LOG ('>', req.event, path, req._query||'')
|
|
41
|
-
if (DEBUG && req.query) DEBUG (req.query)
|
|
42
|
-
})
|
|
43
|
-
next()
|
|
44
|
-
}
|
package/lib/utils/jest.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
let vm = require('vm')
|
|
2
|
-
if (!vm.__caching__) {
|
|
3
|
-
vm.__caching__ = true
|
|
4
|
-
const scriptCache = {}
|
|
5
|
-
vm._Script = vm._Script || vm.Script
|
|
6
|
-
class CachedScript extends vm._Script {
|
|
7
|
-
constructor(src, options) {
|
|
8
|
-
const cached = scriptCache[options.filename]
|
|
9
|
-
if (cached) {
|
|
10
|
-
return cached
|
|
11
|
-
}
|
|
12
|
-
super(src, options)
|
|
13
|
-
// Assume that .test.js files are only loaded once
|
|
14
|
-
if (!options.filename.endsWith('.test.js')) {
|
|
15
|
-
scriptCache[options.filename] = this
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
vm.Script = CachedScript
|
|
21
|
-
}
|
|
22
|
-
vm = undefined
|
|
23
|
-
|
|
24
|
-
let asyncHooks = require('async_hooks')
|
|
25
|
-
if (!asyncHooks._AsyncLocalStorage) {
|
|
26
|
-
asyncHooks._AsyncLocalStorage = asyncHooks.AsyncLocalStorage
|
|
27
|
-
class TmpAsyncLocalStorage extends asyncHooks._AsyncLocalStorage {
|
|
28
|
-
disable() {
|
|
29
|
-
if (this._timer) clearTimeout(this._timer)
|
|
30
|
-
return super.disable()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
_enable() {
|
|
34
|
-
if (this._timer) clearTimeout(this._timer)
|
|
35
|
-
this._timer = setTimeout(() => this.disable(), 60 * 1000)
|
|
36
|
-
this._timer.unref()
|
|
37
|
-
return super._enable()
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
asyncHooks.AsyncLocalStorage = TmpAsyncLocalStorage
|
|
42
|
-
}
|
|
43
|
-
asyncHooks = null
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
const cds = require('../cds')
|
|
2
|
-
const LOG = cds.log()
|
|
3
|
-
|
|
4
|
-
const _require = require('../common/utils/require')
|
|
5
|
-
const { containsAnyRestrictions } = require('../common/utils/restrictions')
|
|
6
|
-
const { ODATA_UNAUTHORIZED } = require('../common/error/constants')
|
|
7
|
-
|
|
8
|
-
let passport, logged
|
|
9
|
-
|
|
10
|
-
// strategy initializers for lazy loading of dependencies
|
|
11
|
-
const _initializers = {
|
|
12
|
-
// REVISIT: support basic authentication?
|
|
13
|
-
basic: ({ credentials, users }) => {
|
|
14
|
-
const BasicStrategy = require('./strategies/basic')
|
|
15
|
-
passport.use(new BasicStrategy(credentials || users))
|
|
16
|
-
},
|
|
17
|
-
dummy: () => {
|
|
18
|
-
const DummyStrategy = require('./strategies/dummy')
|
|
19
|
-
passport.use(new DummyStrategy())
|
|
20
|
-
},
|
|
21
|
-
jwt: ({ credentials, uaa }) => {
|
|
22
|
-
const JWTStrategy = require('./strategies/JWT')
|
|
23
|
-
if (credentials) {
|
|
24
|
-
passport.use(new JWTStrategy(credentials))
|
|
25
|
-
} else if (uaa) {
|
|
26
|
-
// REVISIT: compat, remove with cds^6
|
|
27
|
-
passport.use(new JWTStrategy(uaa.credentials))
|
|
28
|
-
} else {
|
|
29
|
-
throw Object.assign(new Error('No or malformed credentials for auth kind "jwt-auth"'), { credentials })
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
mock: ({ users }, srvName) => {
|
|
33
|
-
const MockStrategy = require('./strategies/mock')
|
|
34
|
-
passport.use(new MockStrategy(users, `mock_${srvName}`))
|
|
35
|
-
},
|
|
36
|
-
xsuaa: ({ credentials, uaa }) => {
|
|
37
|
-
const XSUAAStrategy = require('./strategies/xsuaa')
|
|
38
|
-
if (credentials) {
|
|
39
|
-
passport.use(new XSUAAStrategy(credentials))
|
|
40
|
-
} else if (uaa) {
|
|
41
|
-
// REVISIT: compat, remove with cds^6
|
|
42
|
-
passport.use(new XSUAAStrategy(uaa.credentials))
|
|
43
|
-
} else {
|
|
44
|
-
throw Object.assign(
|
|
45
|
-
new Error('No or malformed credentials for auth kind "xsuaa". Make sure to bind the app to an "xsuaa" service'),
|
|
46
|
-
{ credentials }
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// map for initialized authenticators
|
|
53
|
-
const _authenticators = {}
|
|
54
|
-
|
|
55
|
-
const _log = (req, challenges) => {
|
|
56
|
-
if (!LOG._debug) return
|
|
57
|
-
const challengesLog = challenges ? ['User challenges:', challenges] : []
|
|
58
|
-
LOG.debug(`User "${req.user.id}" request URL`, req.url, '\n', ...challengesLog)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const cap_auth_callback = (req, res, next, internalError, user, arg) => {
|
|
62
|
-
// An internal error occurs during the authentication process
|
|
63
|
-
if (internalError) {
|
|
64
|
-
return res.status(401).json({ error: ODATA_UNAUTHORIZED }) // no details to client
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let challenges
|
|
68
|
-
if (arg) {
|
|
69
|
-
if (!user) {
|
|
70
|
-
// > challenges
|
|
71
|
-
if (Array.isArray(arg)) {
|
|
72
|
-
challenges = arg.filter(ele => ele)
|
|
73
|
-
challenges = challenges.length ? challenges : undefined
|
|
74
|
-
} else {
|
|
75
|
-
challenges = [arg]
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
// REVISIT: req._.req.authInfo compat
|
|
79
|
-
if (arg.verifyToken) req.authInfo = arg
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
req.user = user || Object.defineProperty(new cds.User(), '_challenges', { enumerable: false, value: challenges })
|
|
83
|
-
_log(req, challenges)
|
|
84
|
-
|
|
85
|
-
next()
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const _mountCustomAuth = (srv, app, config) => {
|
|
89
|
-
const impl = cds.resolve(config.impl)
|
|
90
|
-
app.use(_require(impl))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const _mountMockAuth = (srv, app, strategy, config) => {
|
|
94
|
-
const impl =
|
|
95
|
-
strategy === 'dummy'
|
|
96
|
-
? new (require('./strategies/dummy'))()
|
|
97
|
-
: new (require('./strategies/mock'))(config, `mock_${srv.name}`)
|
|
98
|
-
|
|
99
|
-
app.use(function cap_auth(req, res, next) {
|
|
100
|
-
let user, challenge
|
|
101
|
-
impl.success = arg => (user = arg)
|
|
102
|
-
impl.fail = arg => (challenge = arg)
|
|
103
|
-
impl.authenticate(req)
|
|
104
|
-
cap_auth_callback(req, res, next, undefined, user, [challenge])
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const _mountPassportAuth = (srv, app, strategy, config) => {
|
|
109
|
-
if (strategy in { jwt: 1, xsuaa: 1 } && !config.credentials) {
|
|
110
|
-
let msg = `Authentication kind "${config.kind}" configured, but no XSUAA instance bound to application.`
|
|
111
|
-
msg += ' Either bind an XSUAA instance, or switch to an authentication kind that does not require a binding.'
|
|
112
|
-
throw new Error(msg)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!passport) passport = _require('passport')
|
|
116
|
-
|
|
117
|
-
// initialize strategy
|
|
118
|
-
if (!_authenticators[strategy] || process.env.NODE_ENV === 'test') {
|
|
119
|
-
_initializers[strategy](config, srv.name)
|
|
120
|
-
_authenticators[strategy] = true
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// authenticate
|
|
124
|
-
app.use(passport.initialize())
|
|
125
|
-
app.use((req, res, next) => {
|
|
126
|
-
const options = { session: false, failWithError: true }
|
|
127
|
-
const callback = cap_auth_callback.bind(undefined, req, res, next)
|
|
128
|
-
passport.authenticate(strategy === 'jwt' ? 'JWT' : strategy, options, callback)(req, res, next)
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/*
|
|
133
|
-
* export authentication middleware
|
|
134
|
-
*/
|
|
135
|
-
// eslint-disable-next-line complexity
|
|
136
|
-
module.exports = (srv, options = srv.options) => {
|
|
137
|
-
const handlers = [],
|
|
138
|
-
app = { use: h => handlers.push(h) }
|
|
139
|
-
|
|
140
|
-
// NOTE: options.auth is not an official API
|
|
141
|
-
let config = 'auth' in options ? options.auth : cds.env.requires.auth
|
|
142
|
-
if (!config) {
|
|
143
|
-
// REVISIT: can config be falsy? req.user would be undefined!
|
|
144
|
-
if (cds.requires.db && cds.requires.multitenancy) {
|
|
145
|
-
process.exitCode = 1 // REVISIT: why exitCode needed?
|
|
146
|
-
throw new Error('Authentication required for multitenancy')
|
|
147
|
-
}
|
|
148
|
-
if (containsAnyRestrictions(srv)) {
|
|
149
|
-
process.exitCode = 1 // REVISIT: why exitCode needed?
|
|
150
|
-
throw new Error('Authentication required for authorization checks')
|
|
151
|
-
}
|
|
152
|
-
if (process.env.NODE_ENV !== 'production' && !logged) {
|
|
153
|
-
LOG._warn && LOG.warn(`No authentication configured. This is not recommended in production.`)
|
|
154
|
-
}
|
|
155
|
-
// no auth wanted > return
|
|
156
|
-
return handlers
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// cds.env.requires.auth = { kind: 'xsuaa-auth' } was briefly documented on capire -> also support
|
|
160
|
-
if (config.kind === 'xsuaa-auth' && !config.credentials) config = cds.env.requires.xsuaa
|
|
161
|
-
|
|
162
|
-
// mount authentication middleware or strategy
|
|
163
|
-
if (!logged) LOG._debug && LOG.debug(`Using authentication`, { kind: config.kind })
|
|
164
|
-
|
|
165
|
-
if (config.impl) {
|
|
166
|
-
// mount custom authentication middleware
|
|
167
|
-
_mountCustomAuth(srv, app, config)
|
|
168
|
-
} else if (config.kind === 'ias' || config.kind === 'ias-auth') {
|
|
169
|
-
// ias-auth follows the new implementation pattern for auth middlewares
|
|
170
|
-
const iasAuth = require('./strategies/ias-auth')(config)
|
|
171
|
-
if (iasAuth) app.use(iasAuth)
|
|
172
|
-
} else {
|
|
173
|
-
// mount our authentication strategies (legacy style)
|
|
174
|
-
const strategy = _strategy4(config)
|
|
175
|
-
if (strategy in { dummy: 1, mock: 1 }) {
|
|
176
|
-
_mountMockAuth(srv, app, strategy, config)
|
|
177
|
-
} else {
|
|
178
|
-
_mountPassportAuth(srv, app, strategy, config)
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// so we don't log the same stuff multiple times
|
|
183
|
-
logged = true
|
|
184
|
-
|
|
185
|
-
return handlers
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const _strategy4 = config => {
|
|
189
|
-
const strategy = config.kind.replace('mocked', 'mock').replace(/-auth$/, '')
|
|
190
|
-
if (strategy in _initializers) return strategy
|
|
191
|
-
process.exitCode = 1 // REVISIT: why exitCode needed?
|
|
192
|
-
throw new Error(`Authentication kind "${config.kind}" is not supported`)
|
|
193
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const cds = require('../../cds')
|
|
2
|
-
|
|
3
|
-
const _require = require('../../common/utils/require')
|
|
4
|
-
const xssecUtils = require('./xssecUtils')
|
|
5
|
-
|
|
6
|
-
// use _require for a better error message
|
|
7
|
-
const { JWTStrategy: JS } = _require('@sap/xssec')
|
|
8
|
-
|
|
9
|
-
class JWTStrategy extends JS {
|
|
10
|
-
constructor(credentials) {
|
|
11
|
-
super(credentials)
|
|
12
|
-
this.credentials = credentials
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
authenticate(req, options) {
|
|
16
|
-
const credentials = this.credentials
|
|
17
|
-
|
|
18
|
-
// monkey patch success
|
|
19
|
-
const _success = this.success
|
|
20
|
-
this.success = (user, info) => {
|
|
21
|
-
// create cds.User
|
|
22
|
-
user = new cds.User({
|
|
23
|
-
id: xssecUtils.getUserId(user, info),
|
|
24
|
-
roles: xssecUtils.getRoles(['any', 'identified-user'], info, credentials),
|
|
25
|
-
attr: xssecUtils.getAttrForJWT(info)
|
|
26
|
-
})
|
|
27
|
-
xssecUtils.addRolesFromGrantType(user, info, credentials)
|
|
28
|
-
const tenant = xssecUtils.getTenant(info)
|
|
29
|
-
if (tenant) user.tenant = tenant
|
|
30
|
-
// call "super.success"
|
|
31
|
-
_success(user, info)
|
|
32
|
-
}
|
|
33
|
-
super.authenticate(req, options)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = JWTStrategy
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const cds = require('../../cds')
|
|
2
|
-
|
|
3
|
-
const _require = require('../../common/utils/require')
|
|
4
|
-
|
|
5
|
-
// use _require for a better error message
|
|
6
|
-
const { BasicStrategy: BS } = _require('passport-http')
|
|
7
|
-
|
|
8
|
-
class BasicStrategy extends BS {
|
|
9
|
-
constructor(credentials) {
|
|
10
|
-
super(function (user, password, done) {
|
|
11
|
-
if ((credentials[user]?.password || credentials[user]) === password) {
|
|
12
|
-
done(null, new cds.User({ id: user, roles: credentials[user].roles || [] }))
|
|
13
|
-
} else {
|
|
14
|
-
this.fail()
|
|
15
|
-
}
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = BasicStrategy
|