@odatano/core 2.0.0-rc.39 → 2.0.0-rc.40

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/README.md CHANGED
@@ -102,7 +102,7 @@ Service available at `http://localhost:4004`. See the [Quick Start Guide](docs/Q
102
102
 
103
103
  | Service | Path | Purpose |
104
104
  |---|---|---|
105
- | CardanoODataService | `/odata/v4/cardano-odata/` | Read blockchain data (29 entities, 19 actions) |
105
+ | CardanoODataService | `/odata/v4/cardano/` | Read blockchain data (29 entities, 19 actions) |
106
106
  | CardanoTransactionService | `/odata/v4/cardano-transaction/` | Build & submit transactions (13 actions) |
107
107
  | CardanoSignService | `/odata/v4/cardano-sign/` | External signing + HSM (9 actions) |
108
108
  | CardanoIndexerService | `/odata/v4/cardano-indexer/` | Chain crawler / pre-sync control (v2.0, off by default) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatano/core",
3
- "version": "2.0.0-rc.39",
3
+ "version": "2.0.0-rc.40",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
package/src/plugin.js CHANGED
@@ -85,6 +85,9 @@ logger.debug('Plugin registered');
85
85
  */
86
86
  require('../srv/utils/agent-grants-config')
87
87
  .activateAgentGrants();
88
+ // The old path of the read service keeps answering until the 2.0.0 release.
89
+ require('../srv/utils/legacy-service-paths')
90
+ .registerLegacyServicePaths();
88
91
  /**
89
92
  * Plugin mode: relative @impl paths resolve from cds.root (the consumer app), so
90
93
  * rewrite them to package-qualified paths that Node module resolution can find.
@@ -31,6 +31,7 @@ using { Blake2b256, Bech32, AssetUnit, ParsedTransaction, TransactionConfirmatio
31
31
  * middleware) that maps JWT claims to allowed wallet addresses if needed.
32
32
  */
33
33
  @requires: 'authenticated-user'
34
+ @path: '/odata/v4/cardano'
34
35
  service CardanoODataService @(impl: './cardano-service') {
35
36
 
36
37
  // ---------------------------------------------------------------------------
package/srv/server.js CHANGED
@@ -34,6 +34,7 @@ const pg_inline_json_1 = require("./utils/pg-inline-json");
34
34
  const crawler_1 = require("./blockchain/crawler");
35
35
  const wallet_worker_1 = require("./blockchain/wallet-worker");
36
36
  const agent_grants_config_1 = require("./utils/agent-grants-config");
37
+ const legacy_service_paths_1 = require("./utils/legacy-service-paths");
37
38
  const process_1 = require("process");
38
39
  const logger = cds_1.default.log('ODATANO');
39
40
  const VALID_NETWORKS = ['mainnet', 'preview', 'preprod'];
@@ -128,6 +129,7 @@ Object.defineProperty(exports, "activateAgentGrants", { enumerable: true, get: f
128
129
  // Standalone mode never loads src/plugin.ts, so swap the auth impl here as well
129
130
  // (bin/serve.js imports this file before the middlewares exist). Idempotent.
130
131
  (0, agent_grants_config_1.activateAgentGrants)();
132
+ (0, legacy_service_paths_1.registerLegacyServicePaths)();
131
133
  /**
132
134
  * The application context.
133
135
  * @throws {ProviderUnavailableError} 503 when uninitialized; a bootstrap failure is appended as cause.
@@ -10,7 +10,7 @@ export declare function __setAgentServicePathsForTests(paths: string[] | null):
10
10
  export declare function __resetAgentTokenLaneForTests(): void;
11
11
  /** Mount paths of the six services, read from `cds.services` once they are served. */
12
12
  export declare function agentServicePaths(): string[];
13
- /** Exact segment boundary: `/odata/v4/cardano-odata` and below, never `/odata/v4/cardano-odata-evil`. */
13
+ /** Exact segment boundary: `/odata/v4/cardano` and below, never `/odata/v4/cardano-evil`. */
14
14
  export declare function inAgentLane(path: string, servicePaths?: string[]): boolean;
15
15
  export declare const agentTokenLane: TransportLane;
16
16
  //# sourceMappingURL=agent-token-auth.d.ts.map
@@ -44,7 +44,7 @@ function agentServicePaths() {
44
44
  servicePathsCache = paths;
45
45
  return paths;
46
46
  }
47
- /** Exact segment boundary: `/odata/v4/cardano-odata` and below, never `/odata/v4/cardano-odata-evil`. */
47
+ /** Exact segment boundary: `/odata/v4/cardano` and below, never `/odata/v4/cardano-evil`. */
48
48
  function inAgentLane(path, servicePaths = agentServicePaths()) {
49
49
  const bare = path.split('?')[0];
50
50
  return servicePaths.some((p) => (0, cap_auth_1.inLaneOf)(bare, p));
@@ -0,0 +1,11 @@
1
+ import type { NextFunction, Request, Response } from 'express';
2
+ /** Old service path -> the path the service is mounted at. */
3
+ export declare const LEGACY_SERVICE_PATHS: Readonly<Record<string, string>>;
4
+ /** The URL on the new path, or null when it is not on an old path (`/odata/v4/cardano-odata-x` is not). */
5
+ export declare function rewriteLegacyServicePath(url: string): string | null;
6
+ export declare function legacyServicePathMiddleware(req: Request, _res: Response, next: NextFunction): void;
7
+ /** Once per process; the middleware goes onto the app at bootstrap, before the services are mounted. */
8
+ export declare function registerLegacyServicePaths(): void;
9
+ /** Forget the first-use warnings (tests). */
10
+ export declare function __resetLegacyServicePathsForTests(): void;
11
+ //# sourceMappingURL=legacy-service-paths.d.ts.map
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ // Serves the old service path `/odata/v4/cardano-odata` as `/odata/v4/cardano` until the 2.0.0 release.
3
+ // The rewrite runs before CAP mounts the services; the standalone server and the plugin both register it.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.LEGACY_SERVICE_PATHS = void 0;
9
+ exports.rewriteLegacyServicePath = rewriteLegacyServicePath;
10
+ exports.legacyServicePathMiddleware = legacyServicePathMiddleware;
11
+ exports.registerLegacyServicePaths = registerLegacyServicePaths;
12
+ exports.__resetLegacyServicePathsForTests = __resetLegacyServicePathsForTests;
13
+ const cds_1 = __importDefault(require("@sap/cds"));
14
+ const logger = cds_1.default.log('ODATANO');
15
+ /** Old service path -> the path the service is mounted at. */
16
+ exports.LEGACY_SERVICE_PATHS = {
17
+ '/odata/v4/cardano-odata': '/odata/v4/cardano',
18
+ };
19
+ let registered = false;
20
+ // Warned once per client address, so the log names every caller still on the old path.
21
+ const warned = new Set();
22
+ /** The URL on the new path, or null when it is not on an old path (`/odata/v4/cardano-odata-x` is not). */
23
+ function rewriteLegacyServicePath(url) {
24
+ for (const [from, to] of Object.entries(exports.LEGACY_SERVICE_PATHS)) {
25
+ if (url === from || url.startsWith(from + '/') || url.startsWith(from + '?'))
26
+ return to + url.slice(from.length);
27
+ }
28
+ return null;
29
+ }
30
+ function legacyServicePathMiddleware(req, _res, next) {
31
+ const url = rewriteLegacyServicePath(req.url);
32
+ if (url !== null) {
33
+ const caller = req.ip ?? req.socket?.remoteAddress ?? 'unknown';
34
+ if (!warned.has(caller)) {
35
+ warned.add(caller);
36
+ logger.warn(`${caller} called ${req.url.split('?')[0]}, a deprecated service path; use ${url.split('?')[0]} (the old path goes with the 2.0.0 release)`);
37
+ }
38
+ const original = rewriteLegacyServicePath(req.originalUrl);
39
+ if (original !== null)
40
+ req.originalUrl = original;
41
+ req.url = url;
42
+ }
43
+ next();
44
+ }
45
+ /** Once per process; the middleware goes onto the app at bootstrap, before the services are mounted. */
46
+ function registerLegacyServicePaths() {
47
+ if (registered)
48
+ return;
49
+ registered = true;
50
+ cds_1.default.on('bootstrap', (app) => {
51
+ app.use(legacyServicePathMiddleware);
52
+ });
53
+ }
54
+ /** Forget the first-use warnings (tests). */
55
+ function __resetLegacyServicePathsForTests() {
56
+ warned.clear();
57
+ }
58
+ //# sourceMappingURL=legacy-service-paths.js.map