Skip to content

Commit c104403

Browse files
Improve JS getDestinationFromServiceBinding() doc (#2019)
* docs: improve getDestinationFromServiceBinding doc * vale * Update docs-js/features/connectivity/destination.mdx --------- Co-authored-by: Tom Frenken <[email protected]>
1 parent 32317cc commit c104403

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

docs-js/features/connectivity/destination.mdx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ The SAP Cloud SDK provides a default implementation for the transformation of se
200200
201201
The default implementation also retrieves a service token, if needed.
202202
203-
Additionally, we provide a function to transform service bindings into OAuth2ClientCredentials destinations, assuming the service binding follows the structure outlined below:
203+
Additionally, if the service binding follows the structure, we provide a transform function `transformServiceBindingToClientCredentialsDestination()` to transform the service binding to an `OAuth2ClientCredentials` destination.
204204
205205
```json
206206
{
@@ -221,30 +221,33 @@ Additionally, we provide a function to transform service bindings into OAuth2Cli
221221
}
222222
````
223223

224-
If the service URL is not specified in the `url` property, it can alternatively be provided as part of the `options` parameter.
225-
226-
The following is a multi-tenant example, where the user's JWT is used for tenant-isolation in the cache together with a custom URL as target.
224+
The following example shows how to retrieve an `OAuth2ClientCredentials` destination from a service binding with retrieved JWT from the incoming request, and a custom URL:
227225

228226
```ts
229-
const serviceBinding = getServiceBinding('custom-service');
230227
const userJwt = retrieveJwt(request);
231228
const destination = getDestinationFromServiceBinding({
232-
destinationName: 'custom-service',
229+
destinationName: 'my-custom-service',
233230
jwt: userJwt,
234231
useCache: true,
235-
transformServiceBindingToClientCredentialsDestination(serviceBinding, { url: 'custom-url', jwt: userJwt })
232+
serviceBindingTransformFn: async (service, options) => transformServiceBindingToClientCredentialsDestination({
233+
service,
234+
{
235+
...options,
236+
url: 'https://example.com'
237+
}
238+
})
236239
})
237240
```
238241

239-
For other types of service bindings or if you want to overwrite the default behavior, provide a callback function (`serviceBindingTransformFn()`) in the request execution.
242+
For a different service binding structure, write your own transform function of type `ServiceBindingTransformFunction`.
240243

241-
For example, if you have a binding for a custom service:
244+
For example, if you have the following binding for a custom service:
242245

243246
```json
244247
{
245248
"VCAP_SERVICES": {
246249
"custom-service": [
247-
// This object is passed to `serviceBindingTransformFn()`
250+
// This is the `service` object passed to `serviceBindingTransformFn()` function.
248251
{
249252
"name": "my-custom-service",
250253
"label": "custom-service",
@@ -259,8 +262,7 @@ For example, if you have a binding for a custom service:
259262
}
260263
```
261264

262-
To transform this custom service binding you need to provide the `serviceBindingTransformFn()` function.
263-
In the example below, we access the `service.credentials` to create a destination with authentiction type "BasicAuthentication".
265+
You can write the following `serviceBindingTransformFn()` to create a destination with authentication type "BasicAuthentication".
264266

265267
```ts
266268
await req.execute({

0 commit comments

Comments
 (0)