@sasjs/adapter 6.0.0 → 6.0.1

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.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Where the SASjs Server API is mounted.
3
+ *
4
+ * This is the one name the adapter needs for a SASjs Server, and it is the same
5
+ * kind of value as `pathSASViya` - a single path that says where this server
6
+ * type's endpoints live. Servers from the release that introduced the short
7
+ * paths answer `/api` as well, and a project may prefer that spelling for what
8
+ * it shows in a URL, a log or a network panel.
9
+ */
10
+ export declare const DEFAULT_PATH_SASJS = "/SASjsApi";
11
+ /** The stored-program endpoint under that mount. Hard-coded, not configurable. */
12
+ export declare const STP_EXECUTE_SUFFIX = "/stp/execute";
13
+ /** The mount used by the URL builders when no config reaches them. */
14
+ export declare const DEFAULT_API_BASE_PATH = "/SASjsApi";
15
+ /**
16
+ * A base path the URL builders can concatenate with confidence: one leading
17
+ * slash, no trailing one. `SASjsApi`, `/SASjsApi/` and ` /SASjsApi ` all mean
18
+ * the same mount, and a trailing slash here would double up in every path.
19
+ */
20
+ export declare const normaliseApiBasePath: (path?: string) => string;
21
+ /**
22
+ * The mount as callers concatenate it.
23
+ *
24
+ * A root mount contributes nothing, so a URL built as
25
+ * `${serverUrl}${apiBasePrefix(base)}/session` is `https://host/session` rather
26
+ * than `https://host//session`. Every place that composes a path by hand uses
27
+ * this, because a doubled slash is a different URL to a proxy.
28
+ */
29
+ export declare const apiBasePrefix: (base?: string) => string;
30
+ /**
31
+ * The mount, read from `pathSASJS`.
32
+ *
33
+ * `pathSASJS` names the mount itself (`/SASjsApi`, `/api`); the stored-program
34
+ * endpoint under it is `/stp/execute` and is appended by the code that calls it,
35
+ * so there is one place a stub path can be got wrong instead of a config value
36
+ * that has to agree with it.
37
+ *
38
+ * A value carrying the endpoint - `/api/stp/execute` - is accepted and read as
39
+ * the mount it names, because that spelling appears in earlier documentation and
40
+ * in bookmarks, and the two mean the same server.
41
+ */
42
+ export declare const apiBaseFromPathSASJS: (pathSASJS?: string) => string;
package/apiBasePath.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiBaseFromPathSASJS = exports.apiBasePrefix = exports.normaliseApiBasePath = exports.DEFAULT_API_BASE_PATH = exports.STP_EXECUTE_SUFFIX = exports.DEFAULT_PATH_SASJS = void 0;
4
+ /**
5
+ * Where the SASjs Server API is mounted.
6
+ *
7
+ * This is the one name the adapter needs for a SASjs Server, and it is the same
8
+ * kind of value as `pathSASViya` - a single path that says where this server
9
+ * type's endpoints live. Servers from the release that introduced the short
10
+ * paths answer `/api` as well, and a project may prefer that spelling for what
11
+ * it shows in a URL, a log or a network panel.
12
+ */
13
+ exports.DEFAULT_PATH_SASJS = '/SASjsApi';
14
+ /** The stored-program endpoint under that mount. Hard-coded, not configurable. */
15
+ exports.STP_EXECUTE_SUFFIX = '/stp/execute';
16
+ /** The mount used by the URL builders when no config reaches them. */
17
+ exports.DEFAULT_API_BASE_PATH = exports.DEFAULT_PATH_SASJS;
18
+ /**
19
+ * A base path the URL builders can concatenate with confidence: one leading
20
+ * slash, no trailing one. `SASjsApi`, `/SASjsApi/` and ` /SASjsApi ` all mean
21
+ * the same mount, and a trailing slash here would double up in every path.
22
+ */
23
+ const normaliseApiBasePath = (path) => {
24
+ const raw = (path || '').trim();
25
+ // Absent and empty mean the default. A value of only slashes is the root
26
+ // mount, and is a real deployment - a proxy that puts the API at the origin -
27
+ // so the two are separated before the runs are stripped, or both would fold
28
+ // into the default.
29
+ if (!raw)
30
+ return exports.DEFAULT_PATH_SASJS;
31
+ // Scanned rather than matched with /^\/+|\/+$/ : a run of slashes makes that
32
+ // pattern backtrack, which is the kind of input a config value can carry by
33
+ // accident, and CodeQL flags it.
34
+ let first = 0;
35
+ while (first < raw.length && raw.charAt(first) === '/')
36
+ first++;
37
+ let last = raw.length;
38
+ while (last > first && raw.charAt(last - 1) === '/')
39
+ last--;
40
+ const middle = raw.slice(first, last);
41
+ return middle ? `/${middle}` : '/';
42
+ };
43
+ exports.normaliseApiBasePath = normaliseApiBasePath;
44
+ /**
45
+ * The mount as callers concatenate it.
46
+ *
47
+ * A root mount contributes nothing, so a URL built as
48
+ * `${serverUrl}${apiBasePrefix(base)}/session` is `https://host/session` rather
49
+ * than `https://host//session`. Every place that composes a path by hand uses
50
+ * this, because a doubled slash is a different URL to a proxy.
51
+ */
52
+ const apiBasePrefix = (base) => (0, exports.normaliseApiBasePath)(base) === '/' ? '' : (0, exports.normaliseApiBasePath)(base);
53
+ exports.apiBasePrefix = apiBasePrefix;
54
+ /**
55
+ * The mount, read from `pathSASJS`.
56
+ *
57
+ * `pathSASJS` names the mount itself (`/SASjsApi`, `/api`); the stored-program
58
+ * endpoint under it is `/stp/execute` and is appended by the code that calls it,
59
+ * so there is one place a stub path can be got wrong instead of a config value
60
+ * that has to agree with it.
61
+ *
62
+ * A value carrying the endpoint - `/api/stp/execute` - is accepted and read as
63
+ * the mount it names, because that spelling appears in earlier documentation and
64
+ * in bookmarks, and the two mean the same server.
65
+ */
66
+ const apiBaseFromPathSASJS = (pathSASJS) => {
67
+ const base = (0, exports.normaliseApiBasePath)(pathSASJS);
68
+ if (base.endsWith(exports.STP_EXECUTE_SUFFIX))
69
+ return base.slice(0, -exports.STP_EXECUTE_SUFFIX.length) || '/';
70
+ return base;
71
+ };
72
+ exports.apiBaseFromPathSASJS = apiBaseFromPathSASJS;
package/package.json CHANGED
@@ -86,6 +86,7 @@
86
86
  "/SASjsApiClient.*",
87
87
  "/SessionManager.*",
88
88
  "/api/**",
89
+ "/apiBasePath.*",
89
90
  "/auth/**",
90
91
  "/file/**",
91
92
  "/job-execution/**",
@@ -130,7 +131,7 @@
130
131
  "safer-buffer": "npm:@socketregistry/safer-buffer@1.0.10",
131
132
  "side-channel": "npm:@socketregistry/side-channel@1.0.10"
132
133
  },
133
- "version": "6.0.0",
134
+ "version": "6.0.1",
134
135
  "engines": {
135
136
  "node": ">=22"
136
137
  },