@openstax/ts-utils 1.31.1 → 1.31.2

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.
@@ -13,6 +13,7 @@ export declare const isFolderValue: (thing: any) => thing is FolderValue;
13
13
  export interface FileServerAdapter {
14
14
  putFileContent: (source: FileValue, content: string) => Promise<FileValue>;
15
15
  getSignedViewerUrl: (source: FileValue) => Promise<string>;
16
+ getPublicViewerUrl: (source: FileValue) => Promise<string>;
16
17
  getFileContent: (source: FileValue) => Promise<Buffer>;
17
18
  getSignedFileUploadConfig: () => Promise<{
18
19
  url: string;
@@ -63,6 +63,9 @@ const localFileServer = (initializer) => (configProvider) => {
63
63
  const getSignedViewerUrl = async (source) => {
64
64
  return `https://${await host}:${await port}/${source.path}`;
65
65
  };
66
+ const getPublicViewerUrl = async (source) => {
67
+ return `https://${await host}:${await port}/${source.path}`;
68
+ };
66
69
  const getFileContent = async (source) => {
67
70
  const filePath = path_1.default.join(await fileDir, source.path);
68
71
  return fs_1.default.promises.readFile(filePath);
@@ -115,6 +118,7 @@ const localFileServer = (initializer) => (configProvider) => {
115
118
  };
116
119
  return {
117
120
  getSignedViewerUrl,
121
+ getPublicViewerUrl,
118
122
  getFileContent,
119
123
  putFileContent,
120
124
  getSignedFileUploadConfig,
@@ -4,6 +4,7 @@ import { FileServerAdapter } from '.';
4
4
  export type Config = {
5
5
  bucketName: string;
6
6
  bucketRegion: string;
7
+ publicViewerDomain?: string;
7
8
  };
8
9
  interface Initializer<C> {
9
10
  configSpace?: C;
@@ -18,6 +18,9 @@ const s3FileServer = (initializer) => (configProvider) => {
18
18
  const config = configProvider[(0, guards_1.ifDefined)(initializer.configSpace, 'deployed')];
19
19
  const bucketName = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.bucketName));
20
20
  const bucketRegion = (0, __1.once)(() => (0, config_1.resolveConfigValue)(config.bucketRegion));
21
+ const publicViewerDomain = (0, __1.once)(() => 'publicViewerDomain' in config && config.publicViewerDomain
22
+ ? (0, config_1.resolveConfigValue)(config.publicViewerDomain)
23
+ : undefined);
21
24
  const s3Service = (0, __1.once)(async () => {
22
25
  var _a, _b;
23
26
  const args = { apiVersion: '2012-08-10', region: await bucketRegion() };
@@ -33,6 +36,10 @@ const s3FileServer = (initializer) => (configProvider) => {
33
36
  expiresIn: 3600, // 1 hour
34
37
  });
35
38
  };
39
+ const getPublicViewerUrl = async (source) => {
40
+ const host = (0, assertions_1.assertDefined)(await publicViewerDomain(), new Error(`Tried to get public viewer URL for ${source.path} but no publicViewerDomain configured`));
41
+ return `https://${host}/${source.path}`;
42
+ };
36
43
  const getFileContent = async (source) => {
37
44
  const bucket = await bucketName();
38
45
  const command = new client_s3_1.GetObjectCommand({ Bucket: bucket, Key: source.path });
@@ -71,7 +78,7 @@ const s3FileServer = (initializer) => (configProvider) => {
71
78
  Key: prefix + '/${filename}',
72
79
  Conditions,
73
80
  Fields: defaultFields,
74
- Expires: 3600, // 1 hour
81
+ Expires: 3600, // 1 hour
75
82
  });
76
83
  return {
77
84
  url, payload: fields
@@ -112,6 +119,7 @@ const s3FileServer = (initializer) => (configProvider) => {
112
119
  getFileContent,
113
120
  putFileContent,
114
121
  getSignedViewerUrl,
122
+ getPublicViewerUrl,
115
123
  getSignedFileUploadConfig,
116
124
  copyFileTo,
117
125
  copyFileToDirectory,
@@ -29,9 +29,6 @@ const openSearchService = (initializer = {}) => (configProvider) => {
29
29
  maxRetries: 4, // default is 3
30
30
  requestTimeout: 5000, // default is 30000
31
31
  pingTimeout: 2000, // default is 30000
32
- sniffOnConnectionFault: true,
33
- sniffOnStart: true,
34
- resurrectStrategy: 'ping',
35
32
  node: await (0, config_1.resolveConfigValue)(config.node),
36
33
  }));
37
34
  return (indexConfig) => {
@@ -67,6 +64,9 @@ const openSearchService = (initializer = {}) => (configProvider) => {
67
64
  body: params.body,
68
65
  id: params.id,
69
66
  refresh: true
67
+ }, {
68
+ requestTimeout: 10000,
69
+ maxRetries: 1,
70
70
  });
71
71
  };
72
72
  const bulkIndex = async (items) => {
@@ -78,6 +78,9 @@ const openSearchService = (initializer = {}) => (configProvider) => {
78
78
  item.body
79
79
  ]),
80
80
  refresh: true
81
+ }, {
82
+ requestTimeout: 10000,
83
+ maxRetries: 1,
81
84
  });
82
85
  };
83
86
  const search = async (options) => {