defender-serverless icon indicating copy to clipboard operation
defender-serverless copied to clipboard

Add and export types to support serverless typescript configuration file.

Open adjisb opened this issue 2 years ago • 1 comments

When trying to use the serverless configuration with typescript, like: Building a serverless app with TypeScript you need the right typescript types to declare the configuration.

There are two projects that declare the types: https://www.npmjs.com/package/@types/serverless (the interface is called Serverless) and https://github.com/serverless/typescript (the interface is called AWS)

I didn't find an equivalent interface in the serverless defender plugin file https://github.com/OpenZeppelin/defender-serverless/blob/main/src/types/index.ts.

It will be helpful to have something like that exported.

adjisb avatar Jul 07 '23 13:07 adjisb

This is the trick I'm using right now, it doesn't make sense to extend from AWS but I'm lazy.

import {YContract, YSentinel} from 'defender-serverless/src/types/index';
import {AWS} from '@serverless/typescript';
import {YNotification, YRelayer, YSecret} from 'defender-serverless/lib/types';

export interface DefenderServerless
  extends Omit<AWS, 'provider' | 'resources'> {
  provider: {
    name: 'defender';
    stage: string;
    stackName: string;
    ssot?: boolean;
  };
  defender: {
    key: string | undefined;
    secret: string | undefined;
  };
  resources?:
    | {
        Resources: {
          secrets?: {
            [contractName: string]: YSecret;
          };
          contracts?: {
            [contractName: string]: YContract;
          };
          sentinels?: {
            [contractName: string]: YSentinel;
          };
          notifications?: {
            [contractName: string]: YNotification;
          };
          relayers?: {
            [contractName: string]: YRelayer;
          };
        };
      }
    | undefined;
}

adjisb avatar Jul 10 '23 18:07 adjisb