@openstax/ts-utils 1.37.0 → 1.37.1-hotfix2

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.
@@ -3,5 +3,5 @@ import type { JWK } from 'node-jose';
3
3
  export type JwksFetcher = (uri: string) => Promise<{
4
4
  keys: JWK.RawKey[];
5
5
  }>;
6
- export declare const getJwksClient: (iss: string, fetcher?: JwksFetcher) => JwksClient;
6
+ export declare const getJwksClient: (jwksUri: string, fetcher?: JwksFetcher) => JwksClient;
7
7
  export declare const getJwksKey: (iss: string, kid?: string, fetcher?: JwksFetcher) => Promise<import("jwks-rsa").SigningKey>;
@@ -1,10 +1,10 @@
1
1
  import { JwksClient } from 'jwks-rsa';
2
2
  import { memoize } from './helpers';
3
- export const getJwksClient = memoize((iss, fetcher) => {
4
- const jwksUri = new URL('/.well-known/jwks.json', iss).toString();
3
+ export const getJwksClient = memoize((jwksUri, fetcher) => {
5
4
  return new JwksClient({ jwksUri, fetcher });
6
5
  });
7
6
  export const getJwksKey = memoize(async (iss, kid, fetcher) => {
8
- const client = getJwksClient(iss, fetcher);
7
+ const jwksUri = new URL('/.well-known/jwks.json', iss).toString();
8
+ const client = getJwksClient(jwksUri, fetcher);
9
9
  return client.getSigningKey(kid);
10
10
  });
@@ -3,6 +3,7 @@ import { VerifyConfig } from 'http-message-signatures';
3
3
  import { JWK } from 'node-jose';
4
4
  import { ConfigProviderForConfig } from '../../config';
5
5
  type Config = {
6
+ apiHost: string;
6
7
  bypassSignatureVerification: string;
7
8
  };
8
9
  interface Initializer<C> {
@@ -9,6 +9,7 @@ import { once } from '../../misc/helpers';
9
9
  import { getJwksClient } from '../../misc/jwks';
10
10
  export const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configProvider) => {
11
11
  const config = configProvider[configSpace !== null && configSpace !== void 0 ? configSpace : 'verifier'];
12
+ const getApiHost = once(async () => await resolveConfigValue(config.apiHost));
12
13
  const getBypassSignatureVerification = once(async () => (await resolveConfigValue(config.bypassSignatureVerification)) === 'true');
13
14
  return ({ request }) => ({
14
15
  verify: async ({ configOverride, signatureAgentVerifier }) => {
@@ -41,8 +42,7 @@ export const createHttpMessageVerifier = ({ configSpace, fetcher }) => (configPr
41
42
  body,
42
43
  headers,
43
44
  method: requestContext.http.method,
44
- // Node's request.url is really just the path and querystring
45
- url: requestContext.http.path,
45
+ url: `${await getApiHost()}${requestContext.http.path}${request.rawQueryString ? `?${request.rawQueryString}` : ''}`,
46
46
  };
47
47
  if (!await httpbis.verifyMessage({
48
48
  all: true,
@@ -0,0 +1,5 @@
1
+ export interface QueueProvider<T> {
2
+ enqueueMessage: (payload: T, options?: {
3
+ delaySeconds?: number;
4
+ }) => Promise<void>;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { ConfigProviderForConfig } from '../../config';
2
+ import { QueueProvider } from '.';
3
+ export type Config = {
4
+ handlerModulePath: string;
5
+ };
6
+ interface Initializer<C> {
7
+ configSpace?: C;
8
+ }
9
+ export declare const localQueueProvider: <C extends string = "local">(initializer?: Initializer<C>) => <T>() => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => QueueProvider<T>;
10
+ export {};
@@ -0,0 +1,18 @@
1
+ import { resolveConfigValue } from '../../config';
2
+ import { ifDefined } from '../../guards';
3
+ import { once } from '../../misc/helpers';
4
+ export const localQueueProvider = (initializer) => {
5
+ const init = ifDefined(initializer, {});
6
+ return () => (configProvider) => {
7
+ const config = configProvider[ifDefined(init.configSpace, 'local')];
8
+ const handlerModulePath = once(() => resolveConfigValue(config.handlerModulePath));
9
+ return {
10
+ enqueueMessage: async (payload, _options) => {
11
+ const modulePath = await handlerModulePath();
12
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
13
+ const module = require(modulePath);
14
+ await module.handler(payload);
15
+ },
16
+ };
17
+ };
18
+ };
@@ -0,0 +1,12 @@
1
+ import { SQS } from '@aws-sdk/client-sqs';
2
+ import { ConfigProviderForConfig } from '../../config';
3
+ import { QueueProvider } from '.';
4
+ export type Config = {
5
+ queueUrl: string;
6
+ };
7
+ interface Initializer<C> {
8
+ configSpace?: C;
9
+ sqsClient?: SQS;
10
+ }
11
+ export declare const sqsQueueProvider: <C extends string = "deployed">(initializer?: Initializer<C>) => <T>() => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => QueueProvider<T>;
12
+ export {};
@@ -0,0 +1,22 @@
1
+ import { SendMessageCommand, SQS } from '@aws-sdk/client-sqs';
2
+ import { resolveConfigValue } from '../../config';
3
+ import { ifDefined } from '../../guards';
4
+ import { once } from '../../misc/helpers';
5
+ export const sqsQueueProvider = (initializer) => {
6
+ const init = ifDefined(initializer, {});
7
+ const sqs = once(() => { var _a; return (_a = init.sqsClient) !== null && _a !== void 0 ? _a : new SQS({ apiVersion: '2012-11-05' }); });
8
+ return () => (configProvider) => {
9
+ const config = configProvider[ifDefined(init.configSpace, 'deployed')];
10
+ const queueUrl = once(() => resolveConfigValue(config.queueUrl));
11
+ return {
12
+ enqueueMessage: async (payload, options) => {
13
+ const command = new SendMessageCommand({
14
+ QueueUrl: await queueUrl(),
15
+ MessageBody: JSON.stringify(payload),
16
+ DelaySeconds: options === null || options === void 0 ? void 0 : options.delaySeconds,
17
+ });
18
+ await sqs().send(command);
19
+ },
20
+ };
21
+ };
22
+ };