Skip to content

Commit

Permalink
Merge pull request #96 from cap-js/SDMEXT-986
Browse files Browse the repository at this point in the history
Sdmext 986:[NodeJS] Read RepositoryId from Environment variable
  • Loading branch information
rashmiangadi11 authored Feb 17, 2025
2 parents f5e6d24 + a1aea9d commit c878a01
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,7 @@ using { Attachments } from '@cap-js/sdm';
extend my.Incidents with { attachments: Composition of many Attachments }
```

Create a SAP Document Management Integration Option [Service instance and key](https://help.sap.com/docs/document-management-service/sap-document-management-service/creating-service-instance-and-service-key). Using credentials from key [onboard a repository](https://help.sap.com/docs/document-management-service/sap-document-management-service/onboarding-repository) and configure the onboarded repositoryId under cds.requires in package.json. Currently only non versioned repositories are supported.

```
"sdm": {
"settings": {
"repositoryId": "<repository-Id>"
}
}
```
Create a SAP Document Management Integration Option [Service instance and key](https://help.sap.com/docs/document-management-service/sap-document-management-service/creating-service-instance-and-service-key). Using credentials from key [onboard a repository](https://help.sap.com/docs/document-management-service/sap-document-management-service/onboarding-repository) and configure the onboarded repositoryId in mta.yaml under the [srv module](https://github.com/cap-js/incidents-app/blob/incidents-app-deploy/mta.yaml#L18) and the [resources section](https://github.com/cap-js/incidents-app/blob/incidents-app-deploy/mta.yaml#L132) in the **mta.yaml**. Currently only non versioned repositories are supported.

## Deploying and testing the application

Expand Down
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default [
globals: {
...globals.browser,
...globals.jest,
...globals.node, // Add this line to include Node.js globals
response: "writable",
cds: "writable",
payload: "writable",
Expand All @@ -21,4 +22,4 @@ export default [
},
},
pluginJs.configs.recommended,
];
];
10 changes: 9 additions & 1 deletion lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,17 @@ async function getClientCredentialsToken(credentials) {
}

function getConfigurations() {
return cds.env.requires?.["sdm"]?.settings || {};
// Check if the environment variable is present
const repositoryId = process.env.REPOSITORY_ID;
if (repositoryId) {
return { repositoryId: repositoryId };
} else {
// If not present, return settings from cds.env.requires["sdm"]
return cds.env.requires?.["sdm"]?.settings || {};
}
}


async function checkAttachmentsToRename(attachment_val_rename, attachmentIDs, attachments){
let modifiedAttachments = [];
if(attachment_val_rename.length>0){
Expand Down
9 changes: 9 additions & 0 deletions test/lib/util/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ describe("util", () => {

expect(actualSettings).toEqual({});
});
it("should return repositoryId from environment variable", () => {
process.env = {
REPOSITORY_ID: "repo1",
};

const actualSettings = getConfigurations();

expect(actualSettings).toEqual({ "repositoryId": "repo1"});
});
});

describe("checkAttachmentsToRename", () => {
Expand Down

0 comments on commit c878a01

Please sign in to comment.