@sasjs/api 0.27.0 → 0.28.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.
@@ -26,6 +26,24 @@ const RUN_ROUTES = [
26
26
  ];
27
27
  /** A payload value, when the caller actually stated one. */
28
28
  const given = (value) => typeof value === 'string' && value !== '' ? value : undefined;
29
+ /**
30
+ * `replace`, as the two deploy routes state it: a query string on the upload
31
+ * route, a boolean in the JSON one. Anything else is refused rather than guessed
32
+ * at, because guessing "keep" when the caller said nothing would leave a dropped
33
+ * file being served.
34
+ */
35
+ const replaceOf = (value) => {
36
+ if (value === undefined || value === '')
37
+ return undefined;
38
+ if (typeof value === 'boolean')
39
+ return value;
40
+ const text = String(value).trim().toLowerCase();
41
+ if (text === 'true')
42
+ return true;
43
+ if (text === 'false')
44
+ return false;
45
+ throw new types_js_1.ApiError(400, '"replace" must be true or false.');
46
+ };
29
47
  /**
30
48
  * The parameters the table marks required, checked before the handler runs.
31
49
  *
@@ -285,20 +303,40 @@ const dispatch = async (services, routeId, request = {}) => {
285
303
  // statement that this folder is an app. The manifest is metadata, so it is
286
304
  // taken out of the tree before anything is written.
287
305
  const bundle = (0, bundle_js_1.splitAppBundle)(body.fileTree);
288
- const appLoc = String(body.appLoc ?? '');
306
+ const isUpload = routeId === 'POST /SASjsApi/drive/deploy/upload';
307
+ // The query is read on the upload route only: that is where the document
308
+ // states these, because the archive is the body. There the body is still the
309
+ // fallback, for a host that expands the archive before it dispatches. On the
310
+ // JSON route the document states them in the body, and a stray `?appLoc=`
311
+ // beside a body that names one would silently deploy to another folder.
312
+ const setting = (name) => isUpload ? (given(query[name]) ?? body?.[name]) : body?.[name];
313
+ const appLoc = String(setting('appLoc') ?? '');
289
314
  const requested = services.appStream
290
315
  ? (0, bundle_js_1.publishRequestFor)({
291
316
  appLoc,
292
- streamWebFolder: given(body.streamWebFolder),
293
- streamServiceName: given(body.streamServiceName),
294
- streamLogo: given(body.streamLogo)
317
+ streamWebFolder: given(setting('streamWebFolder')),
318
+ streamServiceName: given(setting('streamServiceName')),
319
+ streamLogo: given(setting('streamLogo'))
295
320
  }, bundle.manifest)
296
321
  : undefined;
297
322
  // the index's own checks run BEFORE the drive is written: a tree the index
298
323
  // would refuse must not leave its files behind, which is what happened when
299
- // the deploy came first - a request answered `400` had already deployed
300
- const publish = requested === undefined ? undefined : (0, service_js_1.checkPublishRequest)(requested);
301
- await drive.deploy(appLoc, bundle.tree);
324
+ // the deploy came first - a request answered `400` had already deployed.
325
+ // The tree goes in, so a tree without the folder the app would be served
326
+ // from is refused rather than indexed as an app that 404s.
327
+ // the folder the refusal should tell the caller to fix: the bundle's, when
328
+ // the request did not state one and the manifest did
329
+ const folderFromManifest = requested?.streamWebFolder !== undefined &&
330
+ given(setting('streamWebFolder')) === undefined &&
331
+ bundle.manifest?.streamWebFolder !== undefined;
332
+ const publish = requested === undefined
333
+ ? undefined
334
+ : (0, service_js_1.checkPublishRequest)(requested, bundle.tree, { folderFromManifest });
335
+ // an archive upload replaces by default - publishing a folder means the
336
+ // folder is what the archive says it is - while the JSON route writes over
337
+ // what is there unless it is told otherwise
338
+ const replace = replaceOf(setting('replace')) ?? isUpload;
339
+ await drive.deploy(appLoc, bundle.tree, { replace });
302
340
  // a deploy of something that is not an app writes files and says so; an app
303
341
  // is indexed in the same request, so the two cannot disagree
304
342
  if (publish === undefined || !services.appStream)
@@ -505,7 +505,7 @@ exports.GENERATED_ROUTES = [
505
505
  method: 'DELETE',
506
506
  path: '/SASjsApi/drive/deploy',
507
507
  tag: 'Drive',
508
- summary: 'Remove an app stream entry',
508
+ summary: 'Remove an app',
509
509
  params: [
510
510
  {
511
511
  name: 'id',
@@ -549,6 +549,24 @@ exports.GENERATED_ROUTES = [
549
549
  required: false,
550
550
  type: 'string'
551
551
  },
552
+ {
553
+ name: 'streamServiceName',
554
+ in: 'body',
555
+ required: false,
556
+ type: 'string'
557
+ },
558
+ {
559
+ name: 'streamLogo',
560
+ in: 'body',
561
+ required: false,
562
+ type: 'string'
563
+ },
564
+ {
565
+ name: 'replace',
566
+ in: 'body',
567
+ required: false,
568
+ type: 'boolean'
569
+ },
552
570
  {
553
571
  name: 'fileTree',
554
572
  in: 'body',
@@ -583,6 +601,36 @@ exports.GENERATED_ROUTES = [
583
601
  tag: 'Drive',
584
602
  summary: 'Deploy an uploaded file to SASjs Drive',
585
603
  params: [
604
+ {
605
+ name: 'appLoc',
606
+ in: 'query',
607
+ required: false,
608
+ type: 'string'
609
+ },
610
+ {
611
+ name: 'streamWebFolder',
612
+ in: 'query',
613
+ required: false,
614
+ type: 'string'
615
+ },
616
+ {
617
+ name: 'streamServiceName',
618
+ in: 'query',
619
+ required: false,
620
+ type: 'string'
621
+ },
622
+ {
623
+ name: 'streamLogo',
624
+ in: 'query',
625
+ required: false,
626
+ type: 'string'
627
+ },
628
+ {
629
+ name: 'replace',
630
+ in: 'query',
631
+ required: false,
632
+ type: 'boolean'
633
+ },
586
634
  {
587
635
  name: 'file',
588
636
  in: 'formData',
@@ -68,6 +68,15 @@ export declare const defaultAppName: (appLoc: string) => string;
68
68
  export interface CheckedPublish extends Omit<PublishAppRequest, 'frameAncestors'> {
69
69
  frameAncestors?: string[];
70
70
  }
71
+ /**
72
+ * Whether a deploy tree carries the folder an app is served from.
73
+ *
74
+ * An app is served out of `<appLoc>/services/<streamWebFolder>`, so a tree
75
+ * without that folder would be indexed and then answer `404` to every request -
76
+ * a tile that opens nothing, which is worse than a refusal that names the missing
77
+ * folder.
78
+ */
79
+ export declare const hasStreamFolder: (tree: unknown, streamWebFolder: string) => boolean;
71
80
  /**
72
81
  * A publish request, checked and normalised, with no default applied.
73
82
  *
@@ -75,8 +84,13 @@ export interface CheckedPublish extends Omit<PublishAppRequest, 'frameAncestors'
75
84
  * deployment: the drive and the index are two writes, and a request the index
76
85
  * would refuse must not leave the files behind. `name` is left absent when the
77
86
  * caller did not state one, because a redeploy inherits the label it had.
87
+ *
88
+ * The tree is optional so that a caller holding only the request can still check
89
+ * it; when it is stated, the folder the app would be served from has to be in it.
78
90
  */
79
- export declare const checkPublishRequest: (request: PublishAppRequest) => CheckedPublish;
91
+ export declare const checkPublishRequest: (request: PublishAppRequest, tree?: unknown, options?: {
92
+ folderFromManifest?: boolean;
93
+ }) => CheckedPublish;
80
94
  /**
81
95
  * The index, over a store.
82
96
  *
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/appstream/service.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,cAAc;IAC7B,oFAAoF;IACpF,EAAE,EAAE,MAAM,CAAA;IACV,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;IACZ,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,eAAe,EAAE,MAAM,CAAA;IACvB,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;IACjC,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gEAAgE;IAChE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KA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/**
70
+ * Whether a deploy tree carries the folder an app is served from.
71
+ *
72
+ * An app is served out of `<appLoc>/services/<streamWebFolder>`, so a tree
73
+ * without that folder would be indexed and then answer `404` to every request -
74
+ * a tile that opens nothing, which is worse than a refusal that names the missing
75
+ * folder.
76
+ */
77
+ export const hasStreamFolder = (tree, streamWebFolder) => {
78
+ const members = tree?.members;
79
+ if (!Array.isArray(members))
80
+ return false;
81
+ const isFolder = (member, name) => {
82
+ const entry = member;
83
+ return entry?.type === 'folder' && entry?.name === name;
84
+ };
85
+ const services = members.find((member) => isFolder(member, 'services'));
86
+ const children = services?.members;
87
+ return (Array.isArray(children) &&
88
+ children.some((member) => isFolder(member, streamWebFolder)));
89
+ };
69
90
  /**
70
91
  * A publish request, checked and normalised, with no default applied.
71
92
  *
@@ -73,8 +94,11 @@ const appLocOf = (value) => {
73
94
  * deployment: the drive and the index are two writes, and a request the index
74
95
  * would refuse must not leave the files behind. `name` is left absent when the
75
96
  * caller did not state one, because a redeploy inherits the label it had.
97
+ *
98
+ * The tree is optional so that a caller holding only the request can still check
99
+ * it; when it is stated, the folder the app would be served from has to be in it.
76
100
  */
77
- export const checkPublishRequest = (request) => {
101
+ export const checkPublishRequest = (request, tree, options = {}) => {
78
102
  const appLoc = appLocOf(request.appLoc);
79
103
  // the drive root is not a folder an app can live in: a deploy to `/` writes
80
104
  // `//index.html`, which nothing can read, so it is refused rather than indexed
@@ -82,9 +106,18 @@ export const checkPublishRequest = (request) => {
82
106
  throw new ApiError(400, 'An app cannot be published at the drive root.');
83
107
  const logo = logoOf(request.logo);
84
108
  const frameAncestors = frameAncestorsOf(request.frameAncestors);
109
+ const streamWebFolder = webFolderOf(request.streamWebFolder);
110
+ // the tree has to carry the folder the app is served from, or the publish
111
+ // advertises an app whose every request is a `404`. The advice names the source
112
+ // of the folder: a caller whose bundle stated it cannot omit the field, and the
113
+ // bundle is the thing to correct.
114
+ if (tree !== undefined && !hasStreamFolder(tree, streamWebFolder))
115
+ throw new ApiError(400, `The deployed tree has no "services/${streamWebFolder}" folder, so nothing would be published at ${appLoc}. Deploy the web assets under services/${streamWebFolder}, or ${options.folderFromManifest
116
+ ? 'correct the folder sasjs.app.json names.'
117
+ : 'omit streamWebFolder.'}`);
85
118
  return {
86
119
  appLoc,
87
- streamWebFolder: webFolderOf(request.streamWebFolder),
120
+ streamWebFolder,
88
121
  ...(request.name === undefined
89
122
  ? {}
90
123
  : { name: nameOf(request.name, appLoc) }),
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/corpus/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAW5C,eAAO,MAAM,aAAa,EAAE,UAAU,EAyNrC,CAAA"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/corpus/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAW5C,eAAO,MAAM,aAAa,EAAE,UAAU,EAwVrC,CAAA"}
@@ -41,15 +41,18 @@ export const DEPLOY_CORPUS = [
41
41
  },
42
42
  // ------------------------------------------- the uploaded-archive route
43
43
  // The archive is expanded by the host, so what arrives here is the same tree
44
- // `POST /deploy` takes - which is why every answer below matches its twin.
44
+ // `POST /deploy` takes - which is why every answer below matches its twin. The
45
+ // folder and the stream are stated in the QUERY, where the document puts them on
46
+ // this route: the body is the archive. A host that receives an archive builds it
47
+ // from the tree below; the tree is what the archive has to expand to.
45
48
  {
46
49
  id: 'upload-tree',
47
50
  route: 'POST /SASjsApi/drive/deploy/upload',
48
51
  description: 'writes the tree an uploaded archive expanded to',
49
52
  request: {
50
53
  subject: SUBJECT,
54
+ query: { appLoc: '/Public/apps/uploaded' },
51
55
  body: {
52
- appLoc: '/Public/apps/uploaded',
53
56
  fileTree: {
54
57
  members: [
55
58
  {
@@ -70,14 +73,70 @@ export const DEPLOY_CORPUS = [
70
73
  }
71
74
  }
72
75
  },
76
+ {
77
+ id: 'upload-query-fields',
78
+ route: 'POST /SASjsApi/drive/deploy/upload',
79
+ description: 'takes the folder and the stream from the query, where the document states them',
80
+ request: {
81
+ subject: SUBJECT,
82
+ query: { appLoc: '/Public/apps/from-query', streamWebFolder: 'web' },
83
+ body: {
84
+ fileTree: {
85
+ members: [
86
+ {
87
+ name: 'services',
88
+ type: 'folder',
89
+ members: [
90
+ {
91
+ name: 'web',
92
+ type: 'folder',
93
+ members: [
94
+ { name: 'index.html', type: 'file', code: '<h1>Hello</h1>' }
95
+ ]
96
+ }
97
+ ]
98
+ }
99
+ ]
100
+ }
101
+ }
102
+ },
103
+ expect: {
104
+ status: 200,
105
+ partial: {
106
+ status: 'success',
107
+ app: { name: 'from-query' }
108
+ }
109
+ }
110
+ },
111
+ {
112
+ id: 'deploy-refuses-a-tree-without-its-web-folder',
113
+ route: 'POST /SASjsApi/drive/deploy',
114
+ description: 'refuses a stream the tree does not carry, rather than indexing an app that would answer 404',
115
+ request: {
116
+ subject: SUBJECT,
117
+ body: {
118
+ appLoc: '/Public/apps/no-web',
119
+ streamWebFolder: 'web',
120
+ fileTree: {
121
+ members: [
122
+ { name: 'index.html', type: 'file', code: '<h1>Hello</h1>' }
123
+ ]
124
+ }
125
+ }
126
+ },
127
+ expect: {
128
+ status: 400,
129
+ error: 'The deployed tree has no "services/web" folder, so nothing would be published at /Public/apps/no-web. Deploy the web assets under services/web, or omit streamWebFolder.'
130
+ }
131
+ },
73
132
  {
74
133
  id: 'upload-text-file',
75
134
  route: 'POST /SASjsApi/drive/deploy/upload',
76
135
  description: 'writes a file member as its own text when no encoding is stated',
77
136
  request: {
78
137
  subject: SUBJECT,
138
+ query: { appLoc: '/Public/apps/text' },
79
139
  body: {
80
- appLoc: '/Public/apps/text',
81
140
  fileTree: {
82
141
  members: [
83
142
  { name: 'index.html', type: 'file', code: '<h1>Hello</h1>' }
@@ -97,9 +156,12 @@ export const DEPLOY_CORPUS = [
97
156
  id: 'upload-refused-by-shape',
98
157
  route: 'POST /SASjsApi/drive/deploy/upload',
99
158
  description: 'refuses an expansion that is not a tree',
159
+ // no archive expands to this: only a host handed an expansion can send it
160
+ transport: 'expansion',
100
161
  request: {
101
162
  subject: SUBJECT,
102
- body: { appLoc: '/Public/apps/bad', fileTree: { members: 1 } }
163
+ query: { appLoc: '/Public/apps/bad' },
164
+ body: { fileTree: { members: 1 } }
103
165
  },
104
166
  expect: {
105
167
  status: 400,
@@ -116,8 +178,8 @@ export const DEPLOY_CORPUS = [
116
178
  description: 'applies the deploy cap to the expanded tree, not the bytes',
117
179
  request: {
118
180
  subject: SUBJECT,
181
+ query: { appLoc: '/Public/apps/many' },
119
182
  body: {
120
- appLoc: '/Public/apps/many',
121
183
  fileTree: { members: manyMembers(10001) }
122
184
  }
123
185
  },
@@ -203,8 +265,8 @@ export const DEPLOY_CORPUS = [
203
265
  unwritable: true,
204
266
  request: {
205
267
  subject: SUBJECT,
268
+ query: { appLoc: '/Public/apps/demo' },
206
269
  body: {
207
- appLoc: '/Public/apps/demo',
208
270
  fileTree: {
209
271
  members: [{ name: 'run', type: 'service', code: '%put hi;' }]
210
272
  }
@@ -215,5 +277,65 @@ export const DEPLOY_CORPUS = [
215
277
  body: { status: 'failure', message: 'Deployment failed!' },
216
278
  error: 'Deployment failed!'
217
279
  }
280
+ },
281
+ {
282
+ id: 'upload-replaces-the-folder',
283
+ route: 'POST /SASjsApi/drive/deploy/upload',
284
+ description: "an archive upload is the folder's whole contents, so a file it drops is gone",
285
+ seed: {
286
+ '/Public/apps/replaced/services/web/old.html': '<h1>old</h1>'
287
+ },
288
+ request: {
289
+ subject: SUBJECT,
290
+ query: { appLoc: '/Public/apps/replaced', streamWebFolder: 'web' },
291
+ body: {
292
+ fileTree: {
293
+ members: [
294
+ {
295
+ name: 'services',
296
+ type: 'folder',
297
+ members: [
298
+ {
299
+ name: 'web',
300
+ type: 'folder',
301
+ members: [
302
+ { name: 'index.html', type: 'file', code: '<h1>new</h1>' }
303
+ ]
304
+ }
305
+ ]
306
+ }
307
+ ]
308
+ }
309
+ }
310
+ },
311
+ expect: {
312
+ status: 200,
313
+ partial: { status: 'success', app: { name: 'replaced' } }
314
+ },
315
+ expectDrive: {
316
+ present: ['/Public/apps/replaced/services/web/index.html'],
317
+ missing: ['/Public/apps/replaced/services/web/old.html']
318
+ }
319
+ },
320
+ {
321
+ id: 'deploy-keeps-what-is-there',
322
+ route: 'POST /SASjsApi/drive/deploy',
323
+ description: 'the JSON route writes over what is there unless it is told to replace',
324
+ seed: {
325
+ '/Public/apps/kept/old.html': '<h1>old</h1>'
326
+ },
327
+ request: {
328
+ subject: SUBJECT,
329
+ body: {
330
+ appLoc: '/Public/apps/kept',
331
+ fileTree: {
332
+ members: [{ name: 'a.html', type: 'file', code: '<h1>a</h1>' }]
333
+ }
334
+ }
335
+ },
336
+ expect: { status: 200 },
337
+ expectDrive: {
338
+ present: ['/Public/apps/kept/a.html', '/Public/apps/kept/old.html']
339
+ }
218
340
  }
219
341
  ];
@@ -42,6 +42,29 @@ export interface CorpusCase {
42
42
  };
43
43
  /** The run fails, so a case can pin the `400` a failed run answers. */
44
44
  failingRun?: boolean;
45
+ /**
46
+ * Which host transport can produce this request, where only one can.
47
+ *
48
+ * Most cases are reachable either way: a host that expands an archive before it
49
+ * dispatches, and one that takes the archive and expands it itself. A case whose
50
+ * request no archive could produce - a tree that is not a tree - is reachable
51
+ * only by the first, and says so here rather than in the filter of each host that
52
+ * runs the corpus.
53
+ */
54
+ transport?: 'expansion' | 'archive';
55
+ /**
56
+ * The state the case leaves in the drive, where a status cannot see it.
57
+ *
58
+ * The deploy routes' `replace` policy is exactly that: both answers are `200`
59
+ * and the difference is a file the drive does or does not still hold, so a case
60
+ * that pinned only the status would let a host drop the option.
61
+ */
62
+ expectDrive?: {
63
+ /** Files the drive must hold once the case has run. */
64
+ present?: string[];
65
+ /** Files it must not: the ones a replacement removes, or never writes. */
66
+ missing?: string[];
67
+ };
45
68
  request: ApiRequest;
46
69
  expect: {
47
70
  status: number;
@@ -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;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;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACnE,uEAAuE;IACvE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,EAAE,UAAU,CAAA;IACnB,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,yDAAyD;QACzD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;QACf;;;;;;;;;WASG;QACH,KAAK,CAAC,EAAE;YACN,QAAQ,EAAE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N,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,yDAAyD;QACzD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;QACf;;;;;;;;;WASG;QACH,KAAK,CAAC,EAAE;YACN,QAAQ,EAAE,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,EAwapC,CAAA"}
@@ -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;AAsCnD,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,QA0ClD,CAAA;AA2BD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAepB,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;AAsCnD,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,QA0ClD,CAAA;AA8DD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAgBpB,CAAA"}
@@ -92,6 +92,32 @@ class RefusingDriveStore extends MemoryDriveStore {
92
92
  throw new Error('the store refused the write');
93
93
  }
94
94
  }
95
+ /**
96
+ * The drive state a case says it leaves, checked where the case states it.
97
+ *
98
+ * Reported as a thrown error naming the case rather than as a status mismatch: a
99
+ * host that dropped the deploy option answers `200` and fails here, which is the
100
+ * only place the difference between "replaced" and "kept" can be seen.
101
+ */
102
+ const checkDrive = async (testCase, services) => {
103
+ if (!testCase.expectDrive || !services.drive)
104
+ return;
105
+ const holds = async (path) => {
106
+ try {
107
+ await services.drive.read(path);
108
+ return true;
109
+ }
110
+ catch (e) {
111
+ return false;
112
+ }
113
+ };
114
+ for (const path of testCase.expectDrive.present || [])
115
+ if (!(await holds(path)))
116
+ throw new Error(`${testCase.id}: expected a file at ${path}, and the drive has none`);
117
+ for (const path of testCase.expectDrive.missing || [])
118
+ if (await holds(path))
119
+ throw new Error(`${testCase.id}: expected no file at ${path}, and the drive still holds one`);
120
+ };
95
121
  /**
96
122
  * Runs a corpus case against the drive the case seeds itself, or against
97
123
  * services a caller supplies - that is how a host (or a failing store) is put
@@ -100,6 +126,7 @@ class RefusingDriveStore extends MemoryDriveStore {
100
126
  export const runCase = async (testCase, services = servicesFor(testCase)) => {
101
127
  try {
102
128
  const response = await dispatch(services, testCase.route, testCase.request);
129
+ await checkDrive(testCase, services);
103
130
  return {
104
131
  status: response.status,
105
132
  body: response.body,
@@ -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,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAG/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,EAAE,MAAM,aAAa,CAAA;AAuBtC,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,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AO,CAAC,EAAE,cAAc,CAAA;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAC7B;AAiED,eAAO,MAAM,QAAQ,GACnB,UAAU,QAAQ,EAClB,SAAS,MAAM,EACf,UAAS,UAAe,KACvB,OAAO,CAAC,WAAW,CA4sBrB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,KAAG,QAO3C,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,cAAc,EAAE,MAAM,EA8DlC,CAAA"}
@@ -23,6 +23,24 @@ const RUN_ROUTES = [
23
23
  ];
24
24
  /** A payload value, when the caller actually stated one. */
25
25
  const given = (value) => typeof value === 'string' && value !== '' ? value : undefined;
26
+ /**
27
+ * `replace`, as the two deploy routes state it: a query string on the upload
28
+ * route, a boolean in the JSON one. Anything else is refused rather than guessed
29
+ * at, because guessing "keep" when the caller said nothing would leave a dropped
30
+ * file being served.
31
+ */
32
+ const replaceOf = (value) => {
33
+ if (value === undefined || value === '')
34
+ return undefined;
35
+ if (typeof value === 'boolean')
36
+ return value;
37
+ const text = String(value).trim().toLowerCase();
38
+ if (text === 'true')
39
+ return true;
40
+ if (text === 'false')
41
+ return false;
42
+ throw new ApiError(400, '"replace" must be true or false.');
43
+ };
26
44
  /**
27
45
  * The parameters the table marks required, checked before the handler runs.
28
46
  *
@@ -282,20 +300,40 @@ export const dispatch = async (services, routeId, request = {}) => {
282
300
  // statement that this folder is an app. The manifest is metadata, so it is
283
301
  // taken out of the tree before anything is written.
284
302
  const bundle = splitAppBundle(body.fileTree);
285
- const appLoc = String(body.appLoc ?? '');
303
+ const isUpload = routeId === 'POST /SASjsApi/drive/deploy/upload';
304
+ // The query is read on the upload route only: that is where the document
305
+ // states these, because the archive is the body. There the body is still the
306
+ // fallback, for a host that expands the archive before it dispatches. On the
307
+ // JSON route the document states them in the body, and a stray `?appLoc=`
308
+ // beside a body that names one would silently deploy to another folder.
309
+ const setting = (name) => isUpload ? (given(query[name]) ?? body?.[name]) : body?.[name];
310
+ const appLoc = String(setting('appLoc') ?? '');
286
311
  const requested = services.appStream
287
312
  ? publishRequestFor({
288
313
  appLoc,
289
- streamWebFolder: given(body.streamWebFolder),
290
- streamServiceName: given(body.streamServiceName),
291
- streamLogo: given(body.streamLogo)
314
+ streamWebFolder: given(setting('streamWebFolder')),
315
+ streamServiceName: given(setting('streamServiceName')),
316
+ streamLogo: given(setting('streamLogo'))
292
317
  }, bundle.manifest)
293
318
  : undefined;
294
319
  // the index's own checks run BEFORE the drive is written: a tree the index
295
320
  // would refuse must not leave its files behind, which is what happened when
296
- // the deploy came first - a request answered `400` had already deployed
297
- const publish = requested === undefined ? undefined : checkPublishRequest(requested);
298
- await drive.deploy(appLoc, bundle.tree);
321
+ // the deploy came first - a request answered `400` had already deployed.
322
+ // The tree goes in, so a tree without the folder the app would be served
323
+ // from is refused rather than indexed as an app that 404s.
324
+ // the folder the refusal should tell the caller to fix: the bundle's, when
325
+ // the request did not state one and the manifest did
326
+ const folderFromManifest = requested?.streamWebFolder !== undefined &&
327
+ given(setting('streamWebFolder')) === undefined &&
328
+ bundle.manifest?.streamWebFolder !== undefined;
329
+ const publish = requested === undefined
330
+ ? undefined
331
+ : checkPublishRequest(requested, bundle.tree, { folderFromManifest });
332
+ // an archive upload replaces by default - publishing a folder means the
333
+ // folder is what the archive says it is - while the JSON route writes over
334
+ // what is there unless it is told otherwise
335
+ const replace = replaceOf(setting('replace')) ?? isUpload;
336
+ await drive.deploy(appLoc, bundle.tree, { replace });
299
337
  // a deploy of something that is not an app writes files and says so; an app
300
338
  // is indexed in the same request, so the two cannot disagree
301
339
  if (publish === undefined || !services.appStream)
@@ -1 +1 @@
1
- {"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../../src/routes/generated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,gBAAgB,EAAE,cAAc,EAghE5C,CAAA"}
1
+ {"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../../src/routes/generated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,gBAAgB,EAAE,cAAc,EAgkE5C,CAAA"}