@sasjs/api 0.40.2 → 0.41.0

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DRIVE_CORPUS = void 0;
4
+ const deploymentFile_js_1 = require("../drive/deploymentFile.js");
4
5
  const success = { status: 'success' };
5
6
  /**
6
7
  * Bytes without an encoding API: the package builds with `lib: ES2020` and no
@@ -133,6 +134,34 @@ exports.DRIVE_CORPUS = [
133
134
  request: { query: { _filePath: '/../escape.csv' } },
134
135
  expect: { status: 400, error: "Can't get file outside drive." }
135
136
  },
137
+ {
138
+ id: 'read-file-names-both',
139
+ route: 'GET /SASjsApi/drive/file',
140
+ description: 'refuses a request that names the file twice, in two readings',
141
+ seed: { '/data/keep.csv': 'a' },
142
+ request: {
143
+ query: { _filePath: '/data/keep.csv', _FILE: '/data/keep.csv' }
144
+ },
145
+ expect: {
146
+ status: 400,
147
+ error: 'Exactly one of "_filePath" and "_FILE" may be given.'
148
+ }
149
+ },
150
+ {
151
+ id: 'read-streamed-file',
152
+ route: 'GET /SASjsApi/drive/file',
153
+ description: 'reads a deployment file by the name a streamed page links to',
154
+ seed: { '/Public/app/services/web/main.js': 'console.log(1)' },
155
+ request: { query: { _FILE: '/Public/app/services/web/main.js' } },
156
+ expect: { status: 200, contents: 'console.log(1)' }
157
+ },
158
+ {
159
+ id: 'read-streamed-file-missing',
160
+ route: 'GET /SASjsApi/drive/file',
161
+ description: 'answers a missing deployment file the way the estate does, not as a 404',
162
+ request: { query: { _FILE: '/Public/app/services/web/gone.js' } },
163
+ expect: { status: 202, contents: deploymentFile_js_1.DEPLOYMENT_FILE_ERROR }
164
+ },
136
165
  {
137
166
  id: 'delete-file',
138
167
  route: 'DELETE /SASjsApi/drive/file',
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCase = exports.servicesFor = exports.CORPUS_APP = void 0;
4
4
  const dispatch_js_1 = require("../host/dispatch.js");
5
5
  const service_js_1 = require("../drive/service.js");
6
+ const deploymentFile_js_1 = require("../drive/deploymentFile.js");
6
7
  const memory_store_js_1 = require("../drive/memory-store.js");
7
8
  const service_js_2 = require("../appstream/service.js");
8
9
  const service_js_3 = require("../identity/service.js");
@@ -55,10 +56,15 @@ const servicesFor = (testCase) => {
55
56
  ? { [programOf(testCase)]: testCase.runOutput }
56
57
  : undefined
57
58
  });
59
+ // one store, shared by the drive and the streamed-file read: a file the drive
60
+ // writes has to be the file a streamed page can fetch, or the corpus would be
61
+ // asserting two different drives
62
+ const driveStore = testCase.unwritable
63
+ ? new RefusingDriveStore(testCase.seed || {})
64
+ : new memory_store_js_1.MemoryDriveStore(testCase.seed || {});
58
65
  return {
59
- drive: (0, service_js_1.createDriveService)(testCase.unwritable
60
- ? new RefusingDriveStore(testCase.seed || {})
61
- : new memory_store_js_1.MemoryDriveStore(testCase.seed || {})),
66
+ drive: (0, service_js_1.createDriveService)(driveStore),
67
+ deploymentFile: (0, deploymentFile_js_1.createDeploymentFileService)(driveStore),
62
68
  info: (0, service_js_6.createInfoService)(service_js_6.BROWSER_INFO),
63
69
  home: (0, service_js_10.createHomeService)(async () => home_js_1.CORPUS_WEB_PAGE),
64
70
  authConfig: (0, service_js_7.createAuthConfigService)(authconfig_js_1.CORPUS_AUTH_CONFIG),
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDeploymentFileService = exports.assertOneFileName = exports.ONE_NAME_ONLY = exports.DEPLOYMENT_FILE_ERROR = void 0;
4
+ /**
5
+ * The read a streamed deployment links to: one file out of the drive, by path.
6
+ *
7
+ * A build made with `streamWeb` rewrites every asset link in the entry page to
8
+ * name the file it fetches - `?path=/Public/app/services/web/main.4f3a9c1d.js`,
9
+ * the `_FILE=` spelling the estate answers - so the host has to read one file
10
+ * back and hand it to a browser as itself. Serve it as bytes and the page
11
+ * renders nothing: the difference between a working app and a blank one is the
12
+ * Content-Type.
13
+ *
14
+ * So the typing, the caching and the refusal live here rather than in each
15
+ * host, the same way the drive's own rules do. Every platform has one web tier
16
+ * a browser fetches a program or a file from - `/SASStoredProcess` on SAS 9,
17
+ * `/SASJobExecution` on Viya, `/StoredProgram` on SASjs server - and each of
18
+ * those spellings is meant to resolve to this read.
19
+ *
20
+ * Conditional, because the hosts are what adopt it: the browser build already
21
+ * answers two of them (a mock site holds the drive), while sasjs/server answers
22
+ * `/StoredProgram` and `/SASJobExecution` by handing the request to `GET
23
+ * /SASjsApi/drive/file?_FILE=` only once sasjs/server#736 merges. Until then a
24
+ * consumer's own default branch has no such route, and a sentence here that
25
+ * forgot it would send a reader looking for one.
26
+ *
27
+ * A file that is not there answers the way the estate answers - `202` with a
28
+ * two-line message, not a `404`. A streamed app whose asset is missing has to
29
+ * fail the same way in both places, or a fault reproduced locally is a
30
+ * different fault from the one being chased.
31
+ */
32
+ const types_js_1 = require("../types.js");
33
+ const web_js_1 = require("../appstream/web.js");
34
+ const paths_js_1 = require("./paths.js");
35
+ /** What SAS Viya's job execution route answers for a file it cannot read. */
36
+ exports.DEPLOYMENT_FILE_ERROR = 'Parameter Error\nFile error';
37
+ /** The words a request that names the file twice earns. */
38
+ exports.ONE_NAME_ONLY = 'Exactly one of "_filePath" and "_FILE" may be given.';
39
+ /**
40
+ * Refuses a request that names one file two ways.
41
+ *
42
+ * Both names exist because they answer differently - `_FILE=` is typed and
43
+ * answers a missing file the way the estate does, `_filePath=` is bytes - so a
44
+ * request carrying both is a caller disagreeing with itself. Resolving it would
45
+ * mean picking an answer nobody asked for, and picking the same way in every
46
+ * host. The rule lives here, with the message, so a host that answers the read
47
+ * through its own route (sasjs/server does) refuses it identically instead of
48
+ * re-deciding.
49
+ */
50
+ const assertOneFileName = (query) => {
51
+ if (query._filePath !== undefined && query._FILE !== undefined)
52
+ throw new types_js_1.ApiError(400, exports.ONE_NAME_ONLY);
53
+ };
54
+ exports.assertOneFileName = assertOneFileName;
55
+ /**
56
+ * Whether a store refused because there is nothing at the path.
57
+ *
58
+ * Two spellings reach this code and both mean the same thing: the package's
59
+ * stores throw `ApiError(404, "File doesn't exist.")`, and a host's store over a
60
+ * filesystem (sasjs/server's) lets `fs` throw `ENOENT`. Anything else - a
61
+ * permission failure, a broken link - is a real error and travels on.
62
+ */
63
+ const notFound = (error) => ((0, types_js_1.isApiError)(error) && error.status === 404) ||
64
+ // a structural read, not `NodeJS.ErrnoException`: this module is in the
65
+ // browser build, which has no node types at all
66
+ error?.code === 'ENOENT';
67
+ /** The answer for a file that is not there, in the estate's words. */
68
+ const notThere = () => ({
69
+ status: 202,
70
+ contentType: 'text/plain; charset=utf-8',
71
+ body: exports.DEPLOYMENT_FILE_ERROR
72
+ });
73
+ const createDeploymentFileService = (store) => ({
74
+ async read(input) {
75
+ // the drive's containment and extension rules decide first: a streamed page
76
+ // is caller-supplied content, and this read must not be a way round them
77
+ const checked = (0, paths_js_1.checkFilePath)(input);
78
+ if ('reason' in checked)
79
+ throw checked.reason === 'extension'
80
+ ? new types_js_1.ApiError(400, 'Invalid file extension')
81
+ : new types_js_1.ApiError(400, `Can't get file outside drive.`);
82
+ if ((0, paths_js_1.isRoot)(checked.path))
83
+ throw new types_js_1.ApiError(400, `Can't get file outside drive.`);
84
+ const path = checked.path;
85
+ // The stat and the read are one attempt, not a check followed by an action:
86
+ // a file can be removed or replaced between them, and the fault this route
87
+ // exists to reproduce is a missing asset - which has to answer `202` in the
88
+ // estate's words, not whatever the store threw at that instant. A folder is
89
+ // refused the same way: there is no file to send.
90
+ try {
91
+ if ((await store.stat(path)).directory)
92
+ return notThere();
93
+ return {
94
+ status: 200,
95
+ contentType: (0, web_js_1.contentTypeFor)(path),
96
+ // lower case, matching the app stream's own answer (src/appstream/web.ts):
97
+ // the names are case-insensitive in HTTP but not in a plain object, and a
98
+ // host copying one into the other would lose a policy that mattered
99
+ headers: { 'cache-control': (0, web_js_1.cacheControlFor)(path) },
100
+ body: await store.read(path)
101
+ };
102
+ }
103
+ catch (error) {
104
+ if (notFound(error))
105
+ return notThere();
106
+ throw error;
107
+ }
108
+ }
109
+ });
110
+ exports.createDeploymentFileService = createDeploymentFileService;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HANDLED_ROUTES = exports.noHandler = exports.dispatch = void 0;
4
4
  const index_js_1 = require("../routes/index.js");
5
+ const deploymentFile_js_1 = require("../drive/deploymentFile.js");
5
6
  const service_js_1 = require("../appstream/service.js");
6
7
  const web_js_1 = require("../appstream/web.js");
7
8
  const bundle_js_1 = require("../appstream/bundle.js");
@@ -273,7 +274,26 @@ const dispatch = async (services, routeId, request = {}) => {
273
274
  return { status: 200, body: await services.directory.synchronise() };
274
275
  }
275
276
  case 'GET /SASjsApi/drive/file': {
276
- const file = await drive.read(String(query._filePath || ''));
277
+ // two names for one read that answer differently; a request carrying both
278
+ // is refused by the package rather than resolved here, so a host answering
279
+ // through its own route refuses it with the same words
280
+ (0, deploymentFile_js_1.assertOneFileName)(query);
281
+ if (query._FILE !== undefined) {
282
+ if (!services.deploymentFile)
283
+ throw new types_js_1.ApiError(501, `This host has no deployment-file service, so it cannot answer ${routeId}.`);
284
+ const page = await services.deploymentFile.read(String(query._FILE));
285
+ return {
286
+ status: page.status,
287
+ contents: page.body,
288
+ contentType: page.contentType,
289
+ headers: page.headers
290
+ };
291
+ }
292
+ // one of the two names the file; the table allows either, so a request
293
+ // with neither is the same `400` a missing `_filePath` always was
294
+ if (query._filePath === undefined)
295
+ throw new types_js_1.ApiError(400, '"_filePath" is required');
296
+ const file = await drive.read(String(query._filePath));
277
297
  return { status: 200, contents: file.contents };
278
298
  }
279
299
  case 'POST /SASjsApi/drive/file':
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.BROWSER_INFO = exports.withBundleVersion = exports.createHomeService = exports.NO_WEB_BUILD = exports.BUNDLE_NAME = exports.HOME_CORPUS = exports.DIRECTORY_CORPUS = exports.AUTH_CONFIG_CORPUS = exports.ADMIN_CORPUS = exports.INFO_CORPUS = exports.CODE_CORPUS = exports.sanitiseDisplayName = exports.createRecordService = exports.createIdentityService = exports.HANDLED_ROUTES = exports.dispatch = exports.VIYA_CORPUS = exports.VIYA_HANDLERS = exports.VIYA_OVERLAY = exports.findViyaOperation = exports.dispatchViya = exports.emulatedHeaders = exports.VIYA_TARGET_VERSION = exports.VIYA_CAPTURED_AT = exports.EMULATED_HEADER_VALUE = exports.EMULATED_HEADER = exports.UNRECORDED = exports.VIYA_TABLE = exports.SURFACE_ADAPTER_VERSION = exports.SURFACE = exports.TAG_CAPABILITIES = exports.OVERLAY = exports.findRoute = exports.routeById = exports.ROUTES = exports.MemoryDriveStore = exports.measureDeployTree = exports.isDeployTree = exports.deployTree = exports.decodeBase64 = exports.checkDeployTree = exports.DEPLOY_SUCCESS = exports.DEPLOY_PAYLOAD_BYTES = exports.DEPLOY_LIMITS = exports.createDriveService = exports.isRoot = exports.basename = exports.dirname = exports.hasBlockedExtension = exports.normaliseDrivePath = void 0;
18
- exports.publishRequestFor = exports.parseAppManifest = exports.FRONTEND_FOLDER = exports.BACKEND_FOLDER = exports.APP_MANIFEST = exports.MemoryAppStreamStore = exports.hasFrontendRoot = exports.frontendFolderOf = exports.defaultAppName = exports.createAppStreamService = exports.checkPublishRequest = exports.appSummary = exports.APP_FOLDERS_ROOT = exports.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.runTimeOfPath = exports.resolveProgram = exports.programNotFound = exports.DOCUMENTED_RUN_TIMES = exports.createRuntimeService = exports.CODE_DEBUG = exports.MemorySessionHost = exports.DEFAULT_SESSIONS = exports.createSessionService = exports.SESSION_CORPUS = exports.APP_CORPUS = exports.DEPLOY_CORPUS = exports.IDENTITY_CORPUS = exports.DRIVE_CORPUS = exports.parseIdentity = exports.IDENTITY_FORMAT = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = exports.createDirectoryService = exports.normaliseLogFiles = exports.normaliseDiagnostics = exports.logLines = exports.createAdminService = exports.checkLogFileName = exports.MAX_LOG_LINES = exports.DEFAULT_LOG_LINES = exports.normaliseAuthConfig = exports.createAuthConfigService = exports.normaliseInfo = exports.createInfoService = void 0;
19
- exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.appRootOf = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = void 0;
17
+ exports.BUNDLE_NAME = exports.HOME_CORPUS = exports.DIRECTORY_CORPUS = exports.AUTH_CONFIG_CORPUS = exports.ADMIN_CORPUS = exports.INFO_CORPUS = exports.CODE_CORPUS = exports.sanitiseDisplayName = exports.createRecordService = exports.createIdentityService = exports.HANDLED_ROUTES = exports.dispatch = exports.VIYA_CORPUS = exports.VIYA_HANDLERS = exports.VIYA_OVERLAY = exports.findViyaOperation = exports.dispatchViya = exports.emulatedHeaders = exports.VIYA_TARGET_VERSION = exports.VIYA_CAPTURED_AT = exports.EMULATED_HEADER_VALUE = exports.EMULATED_HEADER = exports.UNRECORDED = exports.VIYA_TABLE = exports.SURFACE_ADAPTER_VERSION = exports.SURFACE = exports.TAG_CAPABILITIES = exports.OVERLAY = exports.findRoute = exports.routeById = exports.ROUTES = exports.MemoryDriveStore = exports.measureDeployTree = exports.isDeployTree = exports.deployTree = exports.decodeBase64 = exports.checkDeployTree = exports.DEPLOY_SUCCESS = exports.DEPLOY_PAYLOAD_BYTES = exports.DEPLOY_LIMITS = exports.ONE_NAME_ONLY = exports.DEPLOYMENT_FILE_ERROR = exports.createDeploymentFileService = exports.assertOneFileName = exports.createDriveService = exports.isRoot = exports.basename = exports.dirname = exports.hasBlockedExtension = exports.normaliseDrivePath = void 0;
18
+ exports.APP_MANIFEST = exports.MemoryAppStreamStore = exports.hasFrontendRoot = exports.frontendFolderOf = exports.defaultAppName = exports.createAppStreamService = exports.checkPublishRequest = exports.appSummary = exports.APP_FOLDERS_ROOT = exports.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.runTimeOfPath = exports.resolveProgram = exports.programNotFound = exports.DOCUMENTED_RUN_TIMES = exports.createRuntimeService = exports.CODE_DEBUG = exports.MemorySessionHost = exports.DEFAULT_SESSIONS = exports.createSessionService = exports.SESSION_CORPUS = exports.APP_CORPUS = exports.DEPLOY_CORPUS = exports.IDENTITY_CORPUS = exports.DRIVE_CORPUS = exports.parseIdentity = exports.IDENTITY_FORMAT = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = exports.createDirectoryService = exports.normaliseLogFiles = exports.normaliseDiagnostics = exports.logLines = exports.createAdminService = exports.checkLogFileName = exports.MAX_LOG_LINES = exports.DEFAULT_LOG_LINES = exports.normaliseAuthConfig = exports.createAuthConfigService = exports.normaliseInfo = exports.createInfoService = exports.BROWSER_INFO = exports.withBundleVersion = exports.createHomeService = exports.NO_WEB_BUILD = void 0;
19
+ exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.appRootOf = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = exports.publishRequestFor = exports.parseAppManifest = exports.FRONTEND_FOLDER = exports.BACKEND_FOLDER = void 0;
20
20
  /**
21
21
  * `@sasjs/api` - the SASjs Server API described once.
22
22
  *
@@ -41,6 +41,11 @@ Object.defineProperty(exports, "basename", { enumerable: true, get: function ()
41
41
  Object.defineProperty(exports, "isRoot", { enumerable: true, get: function () { return paths_js_1.isRoot; } });
42
42
  var service_js_1 = require("./drive/service.js");
43
43
  Object.defineProperty(exports, "createDriveService", { enumerable: true, get: function () { return service_js_1.createDriveService; } });
44
+ var deploymentFile_js_1 = require("./drive/deploymentFile.js");
45
+ Object.defineProperty(exports, "assertOneFileName", { enumerable: true, get: function () { return deploymentFile_js_1.assertOneFileName; } });
46
+ Object.defineProperty(exports, "createDeploymentFileService", { enumerable: true, get: function () { return deploymentFile_js_1.createDeploymentFileService; } });
47
+ Object.defineProperty(exports, "DEPLOYMENT_FILE_ERROR", { enumerable: true, get: function () { return deploymentFile_js_1.DEPLOYMENT_FILE_ERROR; } });
48
+ Object.defineProperty(exports, "ONE_NAME_ONLY", { enumerable: true, get: function () { return deploymentFile_js_1.ONE_NAME_ONLY; } });
44
49
  var deploy_js_1 = require("./drive/deploy.js");
45
50
  Object.defineProperty(exports, "DEPLOY_LIMITS", { enumerable: true, get: function () { return deploy_js_1.DEPLOY_LIMITS; } });
46
51
  Object.defineProperty(exports, "DEPLOY_PAYLOAD_BYTES", { enumerable: true, get: function () { return deploy_js_1.DEPLOY_PAYLOAD_BYTES; } });
@@ -744,7 +744,13 @@ exports.GENERATED_ROUTES = [
744
744
  {
745
745
  name: '_filePath',
746
746
  in: 'query',
747
- required: true,
747
+ required: false,
748
+ type: 'string'
749
+ },
750
+ {
751
+ name: '_FILE',
752
+ in: 'query',
753
+ required: false,
748
754
  type: 'string'
749
755
  }
750
756
  ],
@@ -754,9 +760,13 @@ exports.GENERATED_ROUTES = [
754
760
  status: 200,
755
761
  description: 'The contents of the file'
756
762
  },
763
+ {
764
+ status: 202,
765
+ description: 'A streamed file is not there: Parameter Error / File error'
766
+ },
757
767
  {
758
768
  status: 400,
759
- description: "Can't get file outside drive"
769
+ description: 'A path outside the drive, a refused extension, or a request naming neither or both'
760
770
  },
761
771
  {
762
772
  status: 404,
@@ -197,7 +197,16 @@ exports.OVERLAY = {
197
197
  },
198
198
  // Drive - the file and folder rules, and the three deploy routes
199
199
  // The body is the file itself, so there is nothing to annotate
200
- 'GET /SASjsApi/drive/file': { implemented: true },
200
+ // The `_FILE=` read needs one capability the plain drive read does not: a
201
+ // host that serves a streamed deployment must supply the typed read, and one
202
+ // that does not answers 501 naming it - which is what a capability is for.
203
+ // (No route documents 501; the answer a host gives for a capability it lacks
204
+ // is outside the contract, and this field is where the package says it may
205
+ // happen.)
206
+ 'GET /SASjsApi/drive/file': {
207
+ implemented: true,
208
+ capabilities: ['storage', 'deploymentFile']
209
+ },
201
210
  'POST /SASjsApi/drive/file': {
202
211
  implemented: true,
203
212
  responses: { 200: success, 409: 'File already exists.' }
@@ -1 +1 @@
1
- {"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/corpus/drive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAA;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,cAAc,EAAE,CAAA;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,MAA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MAAM,EAAE,CAAA;YAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;SACpB,CAAA;QACD;;;;;;;WAOG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAC3B,CAAA;CACF;AAmBD,eAAO,MAAM,YAAY,EAAE,UAAU,EAqcpC,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { DEPLOYMENT_FILE_ERROR } from '../drive/deploymentFile.js';
1
2
  const success = { status: 'success' };
2
3
  /**
3
4
  * Bytes without an encoding API: the package builds with `lib: ES2020` and no
@@ -130,6 +131,34 @@ export const DRIVE_CORPUS = [
130
131
  request: { query: { _filePath: '/../escape.csv' } },
131
132
  expect: { status: 400, error: "Can't get file outside drive." }
132
133
  },
134
+ {
135
+ id: 'read-file-names-both',
136
+ route: 'GET /SASjsApi/drive/file',
137
+ description: 'refuses a request that names the file twice, in two readings',
138
+ seed: { '/data/keep.csv': 'a' },
139
+ request: {
140
+ query: { _filePath: '/data/keep.csv', _FILE: '/data/keep.csv' }
141
+ },
142
+ expect: {
143
+ status: 400,
144
+ error: 'Exactly one of "_filePath" and "_FILE" may be given.'
145
+ }
146
+ },
147
+ {
148
+ id: 'read-streamed-file',
149
+ route: 'GET /SASjsApi/drive/file',
150
+ description: 'reads a deployment file by the name a streamed page links to',
151
+ seed: { '/Public/app/services/web/main.js': 'console.log(1)' },
152
+ request: { query: { _FILE: '/Public/app/services/web/main.js' } },
153
+ expect: { status: 200, contents: 'console.log(1)' }
154
+ },
155
+ {
156
+ id: 'read-streamed-file-missing',
157
+ route: 'GET /SASjsApi/drive/file',
158
+ description: 'answers a missing deployment file the way the estate does, not as a 404',
159
+ request: { query: { _FILE: '/Public/app/services/web/gone.js' } },
160
+ expect: { status: 202, contents: DEPLOYMENT_FILE_ERROR }
161
+ },
133
162
  {
134
163
  id: 'delete-file',
135
164
  route: 'DELETE /SASjsApi/drive/file',
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/corpus/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAyBnD;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;;;;CAMtB,CAAA;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,UAAU,KAAG,QA4ClD,CAAA;AA8DD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAgBpB,CAAA"}
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/corpus/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AA0BnD;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;;;;CAMtB,CAAA;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,UAAU,KAAG,QAgDlD,CAAA;AA8DD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAgBpB,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { dispatch } from '../host/dispatch.js';
2
2
  import { createDriveService } from '../drive/service.js';
3
+ import { createDeploymentFileService } from '../drive/deploymentFile.js';
3
4
  import { MemoryDriveStore } from '../drive/memory-store.js';
4
5
  import { MemoryAppStreamStore, createAppStreamService } from '../appstream/service.js';
5
6
  import { createIdentityService } from '../identity/service.js';
@@ -52,10 +53,15 @@ export const servicesFor = (testCase) => {
52
53
  ? { [programOf(testCase)]: testCase.runOutput }
53
54
  : undefined
54
55
  });
56
+ // one store, shared by the drive and the streamed-file read: a file the drive
57
+ // writes has to be the file a streamed page can fetch, or the corpus would be
58
+ // asserting two different drives
59
+ const driveStore = testCase.unwritable
60
+ ? new RefusingDriveStore(testCase.seed || {})
61
+ : new MemoryDriveStore(testCase.seed || {});
55
62
  return {
56
- drive: createDriveService(testCase.unwritable
57
- ? new RefusingDriveStore(testCase.seed || {})
58
- : new MemoryDriveStore(testCase.seed || {})),
63
+ drive: createDriveService(driveStore),
64
+ deploymentFile: createDeploymentFileService(driveStore),
59
65
  info: createInfoService(BROWSER_INFO),
60
66
  home: createHomeService(async () => CORPUS_WEB_PAGE),
61
67
  authConfig: createAuthConfigService(CORPUS_AUTH_CONFIG),
@@ -0,0 +1,43 @@
1
+ import type { DriveStore } from '../types.js';
2
+ /** What SAS Viya's job execution route answers for a file it cannot read. */
3
+ export declare const DEPLOYMENT_FILE_ERROR = "Parameter Error\nFile error";
4
+ /** The words a request that names the file twice earns. */
5
+ export declare const ONE_NAME_ONLY = "Exactly one of \"_filePath\" and \"_FILE\" may be given.";
6
+ /**
7
+ * Refuses a request that names one file two ways.
8
+ *
9
+ * Both names exist because they answer differently - `_FILE=` is typed and
10
+ * answers a missing file the way the estate does, `_filePath=` is bytes - so a
11
+ * request carrying both is a caller disagreeing with itself. Resolving it would
12
+ * mean picking an answer nobody asked for, and picking the same way in every
13
+ * host. The rule lives here, with the message, so a host that answers the read
14
+ * through its own route (sasjs/server does) refuses it identically instead of
15
+ * re-deciding.
16
+ */
17
+ export declare const assertOneFileName: (query: {
18
+ _filePath?: unknown;
19
+ _FILE?: unknown;
20
+ }) => void;
21
+ /**
22
+ * One file, typed and ready to send.
23
+ *
24
+ * `body` is the file's bytes when there is a file, and the refusal's words when
25
+ * there is not - a host sends whichever it got, with the status and type stated
26
+ * here, so neither can quietly become the other.
27
+ */
28
+ export interface DeploymentFilePage {
29
+ status: number;
30
+ contentType: string;
31
+ /** Headers the host must set, chiefly the cache policy of an app's asset. */
32
+ headers?: Record<string, string>;
33
+ body?: string | Uint8Array;
34
+ }
35
+ export interface DeploymentFileService {
36
+ /**
37
+ * Reads one file for a streamed deployment. Refuses a path outside the drive
38
+ * or one carrying a blocked extension with the drive's own `400`.
39
+ */
40
+ read(filePath: unknown): Promise<DeploymentFilePage>;
41
+ }
42
+ export declare const createDeploymentFileService: (store: DriveStore) => DeploymentFileService;
43
+ //# sourceMappingURL=deploymentFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploymentFile.d.ts","sourceRoot":"","sources":["../../../src/drive/deploymentFile.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAI7C,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,gCAAgC,CAAA;AAElE,2DAA2D;AAC3D,eAAO,MAAM,aAAa,6DAC8B,CAAA;AAExD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO;IACvC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,KAAG,IAGH,CAAA;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACrD;AAuBD,eAAO,MAAM,2BAA2B,GACtC,OAAO,UAAU,KAChB,qBAuCD,CAAA"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The read a streamed deployment links to: one file out of the drive, by path.
3
+ *
4
+ * A build made with `streamWeb` rewrites every asset link in the entry page to
5
+ * name the file it fetches - `?path=/Public/app/services/web/main.4f3a9c1d.js`,
6
+ * the `_FILE=` spelling the estate answers - so the host has to read one file
7
+ * back and hand it to a browser as itself. Serve it as bytes and the page
8
+ * renders nothing: the difference between a working app and a blank one is the
9
+ * Content-Type.
10
+ *
11
+ * So the typing, the caching and the refusal live here rather than in each
12
+ * host, the same way the drive's own rules do. Every platform has one web tier
13
+ * a browser fetches a program or a file from - `/SASStoredProcess` on SAS 9,
14
+ * `/SASJobExecution` on Viya, `/StoredProgram` on SASjs server - and each of
15
+ * those spellings is meant to resolve to this read.
16
+ *
17
+ * Conditional, because the hosts are what adopt it: the browser build already
18
+ * answers two of them (a mock site holds the drive), while sasjs/server answers
19
+ * `/StoredProgram` and `/SASJobExecution` by handing the request to `GET
20
+ * /SASjsApi/drive/file?_FILE=` only once sasjs/server#736 merges. Until then a
21
+ * consumer's own default branch has no such route, and a sentence here that
22
+ * forgot it would send a reader looking for one.
23
+ *
24
+ * A file that is not there answers the way the estate answers - `202` with a
25
+ * two-line message, not a `404`. A streamed app whose asset is missing has to
26
+ * fail the same way in both places, or a fault reproduced locally is a
27
+ * different fault from the one being chased.
28
+ */
29
+ import { ApiError, isApiError } from '../types.js';
30
+ import { cacheControlFor, contentTypeFor } from '../appstream/web.js';
31
+ import { checkFilePath, isRoot } from './paths.js';
32
+ /** What SAS Viya's job execution route answers for a file it cannot read. */
33
+ export const DEPLOYMENT_FILE_ERROR = 'Parameter Error\nFile error';
34
+ /** The words a request that names the file twice earns. */
35
+ export const ONE_NAME_ONLY = 'Exactly one of "_filePath" and "_FILE" may be given.';
36
+ /**
37
+ * Refuses a request that names one file two ways.
38
+ *
39
+ * Both names exist because they answer differently - `_FILE=` is typed and
40
+ * answers a missing file the way the estate does, `_filePath=` is bytes - so a
41
+ * request carrying both is a caller disagreeing with itself. Resolving it would
42
+ * mean picking an answer nobody asked for, and picking the same way in every
43
+ * host. The rule lives here, with the message, so a host that answers the read
44
+ * through its own route (sasjs/server does) refuses it identically instead of
45
+ * re-deciding.
46
+ */
47
+ export const assertOneFileName = (query) => {
48
+ if (query._filePath !== undefined && query._FILE !== undefined)
49
+ throw new ApiError(400, ONE_NAME_ONLY);
50
+ };
51
+ /**
52
+ * Whether a store refused because there is nothing at the path.
53
+ *
54
+ * Two spellings reach this code and both mean the same thing: the package's
55
+ * stores throw `ApiError(404, "File doesn't exist.")`, and a host's store over a
56
+ * filesystem (sasjs/server's) lets `fs` throw `ENOENT`. Anything else - a
57
+ * permission failure, a broken link - is a real error and travels on.
58
+ */
59
+ const notFound = (error) => (isApiError(error) && error.status === 404) ||
60
+ // a structural read, not `NodeJS.ErrnoException`: this module is in the
61
+ // browser build, which has no node types at all
62
+ error?.code === 'ENOENT';
63
+ /** The answer for a file that is not there, in the estate's words. */
64
+ const notThere = () => ({
65
+ status: 202,
66
+ contentType: 'text/plain; charset=utf-8',
67
+ body: DEPLOYMENT_FILE_ERROR
68
+ });
69
+ export const createDeploymentFileService = (store) => ({
70
+ async read(input) {
71
+ // the drive's containment and extension rules decide first: a streamed page
72
+ // is caller-supplied content, and this read must not be a way round them
73
+ const checked = checkFilePath(input);
74
+ if ('reason' in checked)
75
+ throw checked.reason === 'extension'
76
+ ? new ApiError(400, 'Invalid file extension')
77
+ : new ApiError(400, `Can't get file outside drive.`);
78
+ if (isRoot(checked.path))
79
+ throw new ApiError(400, `Can't get file outside drive.`);
80
+ const path = checked.path;
81
+ // The stat and the read are one attempt, not a check followed by an action:
82
+ // a file can be removed or replaced between them, and the fault this route
83
+ // exists to reproduce is a missing asset - which has to answer `202` in the
84
+ // estate's words, not whatever the store threw at that instant. A folder is
85
+ // refused the same way: there is no file to send.
86
+ try {
87
+ if ((await store.stat(path)).directory)
88
+ return notThere();
89
+ return {
90
+ status: 200,
91
+ contentType: contentTypeFor(path),
92
+ // lower case, matching the app stream's own answer (src/appstream/web.ts):
93
+ // the names are case-insensitive in HTTP but not in a plain object, and a
94
+ // host copying one into the other would lose a policy that mattered
95
+ headers: { 'cache-control': cacheControlFor(path) },
96
+ body: await store.read(path)
97
+ };
98
+ }
99
+ catch (error) {
100
+ if (notFound(error))
101
+ return notThere();
102
+ throw error;
103
+ }
104
+ }
105
+ });
@@ -5,6 +5,7 @@ import type { SessionService } from '../session/service.js';
5
5
  import type { ViyaSeedSettings } from '../viya/seed.js';
6
6
  import type { RuntimeService } from '../runtime/service.js';
7
7
  import type { AppStreamService } from '../appstream/service.js';
8
+ import type { DeploymentFileService } from '../drive/deploymentFile.js';
8
9
  import type { CodeService } from '../code/service.js';
9
10
  import type { InfoService } from '../info/service.js';
10
11
  import type { AuthConfigService } from '../authconfig/service.js';
@@ -49,8 +50,16 @@ export interface ApiResponse {
49
50
  status: number;
50
51
  /** A JSON body. */
51
52
  body?: unknown;
52
- /** A raw body, for the one route that answers with the file itself. */
53
+ /** A raw body, for the routes that answer with a file rather than JSON. */
53
54
  contents?: string | Uint8Array;
55
+ /**
56
+ * The type of `contents`, for the reads that serve a browser: a streamed
57
+ * deployment's asset is a page, a script or a stylesheet, and a host that
58
+ * guesses the type sends the wrong one.
59
+ */
60
+ contentType?: string;
61
+ /** Headers the host must set with the answer - chiefly an asset's caching. */
62
+ headers?: Record<string, string>;
54
63
  }
55
64
  export interface Services {
56
65
  /** The editor routes, where the host supplies a linter. */
@@ -115,6 +124,12 @@ export interface Services {
115
124
  * an app is, but only a host can store one.
116
125
  */
117
126
  appStream?: AppStreamService;
127
+ /**
128
+ * One file out of the drive, typed for a browser - the read a streamed
129
+ * deployment links to. Absent, a `_FILE=` read answers 501: the rules are the
130
+ * package's, but the bytes are a store's, and only the host has one.
131
+ */
132
+ deploymentFile?: DeploymentFileService;
118
133
  }
119
134
  export declare const dispatch: (services: Services, routeId: string, request?: ApiRequest) => Promise<ApiResponse>;
120
135
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/host/dispatch.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAQ/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAA;AAwBlD,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,E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,WAAW,CAAA;IAClB;;;;OAIG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,iBAAiB,CAAA;IAC9B;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,YAAY,CAAA;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,yFAAyF;IACzF,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAA;CACvC;AAmFD,eAAO,MAAM,QAAQ,GACnB,UAAU,QAAQ,EAClB,SAAS,MAAM,EACf,UAAS,UAAe,KACvB,OAAO,CAAC,WAAW,CAm3BrB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,KAAG,QAO3C,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,cAAc,EAAE,MAAM,EA+DlC,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { routeById } from '../routes/index.js';
2
+ import { assertOneFileName } from '../drive/deploymentFile.js';
2
3
  import { appSummary, checkPublishRequest, frontendFolderOf } from '../appstream/service.js';
3
4
  import { appRootOf } from '../appstream/web.js';
4
5
  import { publishRequestFor, splitAppBundle } from '../appstream/bundle.js';
@@ -270,7 +271,26 @@ export const dispatch = async (services, routeId, request = {}) => {
270
271
  return { status: 200, body: await services.directory.synchronise() };
271
272
  }
272
273
  case 'GET /SASjsApi/drive/file': {
273
- const file = await drive.read(String(query._filePath || ''));
274
+ // two names for one read that answer differently; a request carrying both
275
+ // is refused by the package rather than resolved here, so a host answering
276
+ // through its own route refuses it with the same words
277
+ assertOneFileName(query);
278
+ if (query._FILE !== undefined) {
279
+ if (!services.deploymentFile)
280
+ throw new ApiError(501, `This host has no deployment-file service, so it cannot answer ${routeId}.`);
281
+ const page = await services.deploymentFile.read(String(query._FILE));
282
+ return {
283
+ status: page.status,
284
+ contents: page.body,
285
+ contentType: page.contentType,
286
+ headers: page.headers
287
+ };
288
+ }
289
+ // one of the two names the file; the table allows either, so a request
290
+ // with neither is the same `400` a missing `_filePath` always was
291
+ if (query._filePath === undefined)
292
+ throw new ApiError(400, '"_filePath" is required');
293
+ const file = await drive.read(String(query._filePath));
274
294
  return { status: 200, contents: file.contents };
275
295
  }
276
296
  case 'POST /SASjsApi/drive/file':
@@ -16,6 +16,8 @@
16
16
  export * from './types.js';
17
17
  export { normaliseDrivePath, hasBlockedExtension, dirname, basename, isRoot } from './drive/paths.js';
18
18
  export { createDriveService } from './drive/service.js';
19
+ export { assertOneFileName, createDeploymentFileService, DEPLOYMENT_FILE_ERROR, ONE_NAME_ONLY } from './drive/deploymentFile.js';
20
+ export type { DeploymentFilePage, DeploymentFileService } from './drive/deploymentFile.js';
19
21
  export { DEPLOY_LIMITS, DEPLOY_PAYLOAD_BYTES, DEPLOY_SUCCESS, checkDeployTree, decodeBase64, deployTree, isDeployTree, measureDeployTree } from './drive/deploy.js';
20
22
  export type { DeployFileEncoding, DeployLimits, DeployMeasurements, DeployMember, DeployOptions, DeployRefusal, DeployTree } from './drive/deploy.js';
21
23
  export type { DriveService, DriveResult, DriveListing, DriveFile, DriveTree } from './drive/service.js';