cap-copilot-sdk 0.2.4 → 0.2.7
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/cds-plugin.js +11 -0
- package/package.json +15 -3
- package/postinstall.js +27 -20
package/cds-plugin.js
CHANGED
|
@@ -158,6 +158,17 @@ function _registerWidgetMiddleware(app) {
|
|
|
158
158
|
log("Serving widget bundle at /__btp-copilot-widget/btp-copilot.js");
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
app.get("/__btp-copilot/config", (_req, res) => {
|
|
162
|
+
res.setHeader("Cache-Control", "no-store");
|
|
163
|
+
res.json({
|
|
164
|
+
iframeUrl: iframeUrl || null,
|
|
165
|
+
backendUrl: backendUrl || null,
|
|
166
|
+
appId,
|
|
167
|
+
appName,
|
|
168
|
+
widgetPosition,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
161
172
|
// Auto-inject widget into HTML responses only when iframeUrl is configured
|
|
162
173
|
if (!injectWidget || !iframeUrl) {
|
|
163
174
|
if (!iframeUrl)
|
package/package.json
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cap-copilot-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "CDS plugin: auto-extracts entity schemas, relationships, project structure and registers with BTP Copilot backend",
|
|
5
5
|
"main": "cds-plugin.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./cds-plugin.js",
|
|
8
8
|
"./cds-plugin": "./cds-plugin.js"
|
|
9
9
|
},
|
|
10
|
-
"files": [
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"cds-plugin.js",
|
|
13
|
+
"postinstall.js"
|
|
14
|
+
],
|
|
11
15
|
"scripts": {
|
|
12
16
|
"postinstall": "node postinstall.js"
|
|
13
17
|
},
|
|
14
|
-
"keywords": [
|
|
18
|
+
"keywords": [
|
|
19
|
+
"sap",
|
|
20
|
+
"cap",
|
|
21
|
+
"cds",
|
|
22
|
+
"btp",
|
|
23
|
+
"ai",
|
|
24
|
+
"chatbot",
|
|
25
|
+
"plugin"
|
|
26
|
+
],
|
|
15
27
|
"license": "MIT",
|
|
16
28
|
"cds": {
|
|
17
29
|
"plugin": true
|
package/postinstall.js
CHANGED
|
@@ -18,15 +18,24 @@ const path = require("path");
|
|
|
18
18
|
// Useful in CI/CD pipelines where package.json is read-only or managed by tooling.
|
|
19
19
|
if (process.env.BTP_COPILOT_SKIP_POSTINSTALL === "1") process.exit(0);
|
|
20
20
|
|
|
21
|
-
// INIT_CWD = directory from which `npm install` was run (the consuming app root)
|
|
22
|
-
const appRoot = process.env.INIT_CWD;
|
|
23
|
-
|
|
24
|
-
|
|
25
21
|
const isInstalledPackage = __dirname.includes("node_modules");
|
|
26
|
-
if (!
|
|
27
|
-
|
|
22
|
+
if (!isInstalledPackage) process.exit(0);
|
|
23
|
+
|
|
24
|
+
function findAppRoot() {
|
|
25
|
+
const fromEnv =
|
|
26
|
+
process.env.INIT_CWD ||
|
|
27
|
+
process.env.npm_config_local_prefix;
|
|
28
|
+
if (fromEnv) return fromEnv;
|
|
29
|
+
const parts = __dirname.split(path.sep);
|
|
30
|
+
const nmIdx = parts.lastIndexOf("node_modules");
|
|
31
|
+
if (nmIdx > 0) return parts.slice(0, nmIdx).join(path.sep);
|
|
32
|
+
|
|
33
|
+
return null;
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
const appRoot = findAppRoot();
|
|
37
|
+
if (!appRoot) process.exit(0);
|
|
38
|
+
|
|
30
39
|
const pkgPath = path.join(appRoot, "package.json");
|
|
31
40
|
if (!fs.existsSync(pkgPath)) process.exit(0);
|
|
32
41
|
|
|
@@ -58,10 +67,17 @@ const changed =
|
|
|
58
67
|
existing.backendUrl !== undefined ||
|
|
59
68
|
existing.iframeUrl !== undefined;
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
// CDS 8 auto-discovers plugins via "cds": { "plugin": true } in the package itself —
|
|
71
|
+
// no explicit cds.plugins entry is needed. Clean up any stale entry written by older
|
|
72
|
+
// versions of this postinstall, since a stale/malformed entry causes CDS to crash.
|
|
73
|
+
const hadStalePlugin = Array.isArray(cdsSection.plugins) &&
|
|
74
|
+
cdsSection.plugins.includes("cap-copilot-sdk");
|
|
75
|
+
if (hadStalePlugin) {
|
|
76
|
+
cdsSection.plugins = cdsSection.plugins.filter(p => p !== "cap-copilot-sdk");
|
|
77
|
+
if (cdsSection.plugins.length === 0) delete cdsSection.plugins;
|
|
78
|
+
}
|
|
63
79
|
|
|
64
|
-
if (!changed && !
|
|
80
|
+
if (!changed && !hadStalePlugin) {
|
|
65
81
|
process.exit(0);
|
|
66
82
|
}
|
|
67
83
|
|
|
@@ -72,23 +88,14 @@ delete requires["btp-copilot"].backendUrl;
|
|
|
72
88
|
delete requires["btp-copilot"].iframeUrl;
|
|
73
89
|
|
|
74
90
|
cdsSection.requires = requires;
|
|
75
|
-
|
|
76
|
-
// Ensure cap-copilot-sdk is listed in cds.plugins so CDS loads it automatically
|
|
77
|
-
const plugins = Array.isArray(cdsSection.plugins) ? cdsSection.plugins : [];
|
|
78
|
-
const pluginAlreadyListed = plugins.includes("cap-copilot-sdk");
|
|
79
|
-
if (!pluginAlreadyListed) {
|
|
80
|
-
plugins.push("cap-copilot-sdk");
|
|
81
|
-
cdsSection.plugins = plugins;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
91
|
pkg.cds = cdsSection;
|
|
85
92
|
|
|
86
93
|
try {
|
|
87
94
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
88
95
|
console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m \u2714 Configured cds.requires["btp-copilot"] in package.json`);
|
|
89
96
|
console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m appId="${appDefaults.appId}" | appName="${appDefaults.appName}"`);
|
|
90
|
-
if (
|
|
91
|
-
console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m \u2714
|
|
97
|
+
if (hadStalePlugin) {
|
|
98
|
+
console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m \u2714 Removed stale cds.plugins entry (CDS auto-discovers this plugin)`);
|
|
92
99
|
}
|
|
93
100
|
} catch {
|
|
94
101
|
// Non-fatal
|