Skip to content
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0f9eaa9
add manual req
SirSimon04 Dec 15, 2025
e6bc5a9
fixes
SirSimon04 Dec 15, 2025
6089a7b
fix
SirSimon04 Dec 15, 2025
851d861
fix
SirSimon04 Dec 15, 2025
c30b6bb
update to bearer
SirSimon04 Dec 15, 2025
4f8f9c8
update to jwt
SirSimon04 Dec 15, 2025
b3e70be
update for print function
SirSimon04 Dec 15, 2025
261684c
update
SirSimon04 Dec 15, 2025
83198a1
update
SirSimon04 Dec 15, 2025
8d60225
fix
SirSimon04 Dec 15, 2025
b276440
update to fetch
SirSimon04 Dec 15, 2025
5432176
use res.jsn
SirSimon04 Dec 15, 2025
bcb1310
fixes
SirSimon04 Dec 15, 2025
1543052
fix
SirSimon04 Dec 15, 2025
355018d
update
SirSimon04 Dec 15, 2025
e62a8cf
udpate
SirSimon04 Dec 15, 2025
762764b
add tentant id t request
SirSimon04 Dec 15, 2025
946aa31
refactoring to use cache and utils
SirSimon04 Dec 15, 2025
fefd202
update token cache
SirSimon04 Dec 15, 2025
2c0fd98
fixes
SirSimon04 Dec 15, 2025
a8829d5
fix
SirSimon04 Dec 15, 2025
5ca8d2a
update
SirSimon04 Dec 15, 2025
590038b
remove cloud sdk
SirSimon04 Dec 16, 2025
edfa1b2
fix
SirSimon04 Dec 16, 2025
cfde832
fix
SirSimon04 Dec 16, 2025
ec61dcd
update
SirSimon04 Dec 16, 2025
6d59a06
update
SirSimon04 Dec 16, 2025
b841e83
changes
SirSimon04 Dec 16, 2025
e1dd342
polished
SirSimon04 Dec 16, 2025
3b5475a
comment
SirSimon04 Dec 16, 2025
5fc0bb4
update lint config
SirSimon04 Dec 16, 2025
1cc406f
Update srv/BTPPrintService.js
SirSimon04 Dec 17, 2025
52400f0
Update srv/BTPPrintService.js
SirSimon04 Dec 17, 2025
4afcded
Update srv/BTPPrintService.js
SirSimon04 Dec 17, 2025
3cbe484
update error handling
SirSimon04 Dec 17, 2025
445e5c9
update error handling
SirSimon04 Dec 17, 2025
e892f13
updates
SirSimon04 Dec 17, 2025
48a4abd
update creds
SirSimon04 Dec 17, 2025
a9dc1ae
try to use xssec
SirSimon04 Dec 17, 2025
2d6eedb
update vcap.tag
SirSimon04 Dec 17, 2025
09dd720
update cds.requires
SirSimon04 Dec 17, 2025
11a974f
update label
SirSimon04 Dec 17, 2025
e9e4466
remove param
SirSimon04 Dec 17, 2025
c2d4ce7
add cache back in
SirSimon04 Dec 17, 2025
f3f6064
update deps
SirSimon04 Dec 17, 2025
4adbcdd
try
SirSimon04 Dec 17, 2025
d91b008
change name to PrintService
SirSimon04 Dec 17, 2025
b0fd21d
try
SirSimon04 Dec 17, 2025
8c731c1
Revert "try"
SirSimon04 Dec 17, 2025
4a6b5d8
add zone id
SirSimon04 Dec 17, 2025
24942bc
remoce zid
SirSimon04 Dec 17, 2025
9b8d9be
add zoneid back in
SirSimon04 Dec 17, 2025
4d4e9e0
lint
SirSimon04 Dec 17, 2025
2d6a7c9
change name to print again
SirSimon04 Dec 17, 2025
249dd54
only add zid when needed
SirSimon04 Dec 18, 2025
fb0ecd1
make service internal
SirSimon04 Dec 18, 2025
72ef3fc
remove package update
SirSimon04 Dec 18, 2025
4c06fb6
Update srv/BTPPrintService.js
SirSimon04 Dec 18, 2025
b9842f1
update error handling
SirSimon04 Dec 18, 2025
160ffec
update test package.json
SirSimon04 Dec 18, 2025
9dc8de2
Changelog
SirSimon04 Dec 18, 2025
977dd0c
Update srv/localPrintService.js
SirSimon04 Dec 19, 2025
4ad8c84
prettier
SirSimon04 Dec 19, 2025
b47407e
update error handling
SirSimon04 Dec 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .eslintrc

This file was deleted.

10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
"runtimeArgs": ["run", "test"],
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal"
},
{
"type": "pwa-node",
"request": "launch",
"name": "watch sample hybrid",
"cwd": "${workspaceFolder}/test/bookshop",
"runtimeExecutable": "cds",
"runtimeArgs": ["bind", "--exec", "--", "cds", "w"],
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal"
}
]
}
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 0.1.0 - TBD
## Version 0.2.0 - 2025-12-19

### Added
- Multitenancy support

### Fixed
- Draft enabled entities can be print enabled
- Entities with composite keys can be print enabled

## Version 0.1.0 - 2025-11-28

### Added

Expand Down
11 changes: 8 additions & 3 deletions cds-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ cds.once("served", async () => {
],
});

return req.info({
return req.notify({
status: 200,
message: "PRINT_JOB_SENT",
args: [object[fileNameAttribute], queueID],
});
} catch (error) {
LOG.error("Print error:", error);
return req.reject({ status: 500, message: "PRINT_UNKNOWN_ERROR" });
LOG.error(error);
// Only return client errors to not show technical errors to the user
if (error.code >= 400 && error.code < 500) {
req.reject(error.code, error.message);
} else {
req.reject(500, "PRINT_UNKNOWN_ERROR");
}
}
});
}
Expand Down
15 changes: 15 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ export default [
...cds,
{
files: ["**/*.js"],
languageOptions: {
globals: {
SELECT: "readonly",
INSERT: "readonly",
UPSERT: "readonly",
UPDATE: "readonly",
DELETE: "readonly",
CREATE: "readonly",
DROP: "readonly",
CDL: "readonly",
CQL: "readonly",
CXL: "readonly",
cds: "readonly",
},
},
rules: {
"no-await-in-loop": "error",
"no-console": ["error", { allow: ["warn", "error"] }],
Expand Down
29 changes: 29 additions & 0 deletions lib/btp-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { XsuaaService } = require("@sap/xssec");

const getServiceCredentials = (name) => (cds?.env?.requires[name] || [])?.credentials;

async function getServiceToken(serviceName) {
const srvCredentials = getServiceCredentials(serviceName);
if (!srvCredentials) {
throw new Error(`Missing binding credentials for service "${serviceName}"`);
}

const tenantId = cds.context?.tenant;
const xsuaaService = new XsuaaService(srvCredentials.uaa);
const { access_token: jwt, expires_in } = await xsuaaService.fetchClientCredentialsToken({
...(tenantId && { zid: tenantId }),
});

if (!jwt) {
throw new Error(
`Empty JWT returned from authorization service for bound service "${serviceName}"`,
);
}

return { jwt, expires_in };
}

module.exports = {
getServiceToken,
getServiceCredentials,
};
29 changes: 29 additions & 0 deletions lib/token-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const cds = require("@sap/cds");
const LOG = cds.log("print");

module.exports = class TokenCache {
constructor() {
this.cache = new Map();
}

set(key, token, expiresIn) {
const expiresAt = Date.now() + expiresIn * 1000;
this.cache.set(key, { token, expiresAt });
LOG.debug(`Token set for key: ${key}, expires in ${expiresIn} seconds.`);
}

get(key) {
const entry = this.cache.get(key);
if (!entry) {
LOG.debug(`No token found for key: ${key}.`);
return undefined;
}
if (Date.now() >= entry.expiresAt) {
this.cache.delete(key);
LOG.debug(`Token expired for key: ${key}.`);
return undefined;
}
LOG.debug(`Token retrieved for key: ${key}.`);
return entry.token;
}
};
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"plugin"
],
"dependencies": {
"@sap-cloud-sdk/connectivity": "^3.26.4",
"@sap-cloud-sdk/http-client": "^4.1.2",
"@sap/xssec": "^3.6.2"
"@sap-cloud-sdk/connectivity": "^4.2.0",
"@sap-cloud-sdk/http-client": "^4.2.0",
"@sap-cloud-sdk/resilience": "^4.2.0"
},
"peerDependencies": {
"@sap/cds": ">= 9"
Expand All @@ -38,8 +38,7 @@
],
"cds": {
"requires": {
"destinations": true,
"PrintService": {
"print": {
"[development]": {
"kind": "print-to-console"
},
Expand All @@ -53,7 +52,10 @@
"kind": "print-to-service"
},
"vcap": {
"tag": "print"
"label": "print"
},
"subscriptionDependency": {
"uaa": "xsappname"
},
"outbox": true
},
Expand Down
1 change: 1 addition & 0 deletions srv/BTPPrintService.cds
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@impl: './BTPPrintService.js'
@requires: 'authenticated-user'
@protocol: 'none'
service PrintService {

@UI.HeaderInfo: {
Expand Down
Loading
Loading