@openstax/ts-utils 1.35.3 → 1.35.5

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,11 @@
1
+ import { AccountsGateway } from '../accountsGateway';
2
+ import { LaunchVerifier } from '../launchParams/verifier';
3
+ import type { Logger } from '../logger';
4
+ import { AuthProvider } from '.';
5
+ export declare const launchTokenAuthMiddleware: () => <M extends {
6
+ logger: Logger;
7
+ accountsGateway: AccountsGateway;
8
+ launchVerifier: LaunchVerifier;
9
+ }>(middleware: M) => M & {
10
+ authProvider: AuthProvider;
11
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.launchTokenAuthMiddleware = void 0;
4
+ const assertions_1 = require("../../assertions");
5
+ const helpers_1 = require("../../misc/helpers");
6
+ const stubAuthProvider = (services) => {
7
+ const getUserUuid = (0, helpers_1.once)(async () => {
8
+ const token = await services.launchVerifier.verify();
9
+ return (0, assertions_1.assertDefined)(token.sub, new Error('Launch token does not contain a user UUID'));
10
+ });
11
+ const getUser = (0, helpers_1.once)(async () => {
12
+ const uuid = await getUserUuid();
13
+ const { items } = await services.accountsGateway.searchUsers({ q: `uuid:${uuid}` });
14
+ return (0, assertions_1.assertDefined)(items[0], new Error(`User with UUID ${uuid} not found`));
15
+ });
16
+ return {
17
+ getAuthToken: () => {
18
+ throw new Error('Auth token not available when authenticated via JWT');
19
+ },
20
+ getAuthorizedFetchConfig: () => {
21
+ throw new Error('Authorized subrequest not available when authenticated via JWT');
22
+ },
23
+ getUser,
24
+ loadUserData: getUser,
25
+ };
26
+ };
27
+ const launchTokenAuthMiddleware = () => (middleware) => ({
28
+ ...middleware,
29
+ authProvider: stubAuthProvider(middleware),
30
+ });
31
+ exports.launchTokenAuthMiddleware = launchTokenAuthMiddleware;
@@ -68,7 +68,8 @@ const s3FileServer = (initializer) => (configProvider) => {
68
68
  const Conditions = [
69
69
  { acl: 'private' },
70
70
  { bucket },
71
- ['starts-with', '$key', prefix]
71
+ ['starts-with', '$key', prefix],
72
+ ['starts-with', '$Content-Type', ''],
72
73
  ];
73
74
  const defaultFields = {
74
75
  acl: 'private',