Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move alias creation from microapps-publish to deployer-svc #299

Merged
merged 18 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 2 additions & 119 deletions packages/microapps-deployer-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,119 +1,2 @@
/**
* Represents a Base Request
*/
export interface IRequestBase {
readonly type: 'createApp' | 'deleteVersion' | 'deployVersion' | 'deployVersionPreflight';
}

/**
* Represents a Create Application Request
*/
export interface ICreateApplicationRequest extends IRequestBase {
readonly type: 'createApp';

/**
* Name of the application
*/
readonly appName: string;

/**
* Display name of the application
*/
readonly displayName: string;
}

/**
* Represents a Deploy Version Base Request
*/
export interface IDeployVersionRequestBase extends IRequestBase {
/**
* Name of the application
*/
readonly appName: string;

/**
* SemVer being published
*/
readonly semVer: string;

/**
* Allow overwrite of existing version
*
* @default false;
*/
readonly overwrite?: boolean;
}

/**
* Represents a Deploy Version Preflight Request
*/
export interface IDeployVersionPreflightRequest extends IDeployVersionRequestBase {
readonly type: 'deployVersionPreflight';

/**
* Retrieve S3 upload credentials
*
* @default true
*/
readonly needS3Creds?: boolean;
}

/**
* Represents a Deploy Version Request
*/
export interface IDeployVersionRequest extends IDeployVersionRequestBase {
readonly type: 'deployVersion';
/**
* Type of the app (which implies how it's routed)
*/
readonly appType?: 'lambda' | 'lambda-url' | 'url' | 'static';
/**
* Render the `/appName` route as an iframe pointing to `/appName/semVer`
* or proxy directly to `/appName/semVer` and render the app at `/appName`
*
* @default 'iframe'
*/
readonly startupType?: 'iframe' | 'direct';
/**
* LambdaARN w/Alias
* Used for `lambda` and `lambda-url` apps
*/
readonly lambdaARN?: string;
/**
* Default file or path
* Typically used for `static` apps, but can be used for non-static apps
*/
readonly defaultFile: string;
/**
* Used for `url` not for `lambda-url` (as the Function URL is created by the
* DeployVersion action in that case)
*/
readonly url?: string;
}

/**
* Represents a Delete Version Request
*/
export interface IDeleteVersionRequest
extends Pick<IDeployVersionRequestBase, 'appName' | 'semVer'> {
readonly type: 'deleteVersion';
}

/**
* Represents a Deployer Response
*/
export interface IDeployerResponse {
readonly statusCode: number;
}

/**
* Represents a Deploy Version Preflight Response
*/
export interface IDeployVersionPreflightResponse extends IDeployerResponse {
readonly s3UploadUrl?: string;
readonly awsCredentials?: {
readonly accessKeyId: string;
readonly secretAccessKey: string;
readonly sessionToken: string;
};
}
export * from './messages';
export * from './versions';
34 changes: 34 additions & 0 deletions packages/microapps-deployer-lib/src/messages/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Application Type
* - `lambda` - Lambda Function using API Gateway w/optional S3 files
* - `lambda-url` - Lambda Function using Lambda Function URLs w/optional S3 files
* - `url` - Any arbitrary URL
* - `static` - Static files (only) served from S3
*/
export type AppType = 'lambda' | 'lambda-url' | 'url' | 'static';

/**
* Application Startup Type
* - `iframe` - Render an iframe that points to the version
* - `direct` - Proxy directly to the version, incompatible with `static` and `apigwy` (`lambda`)
*/
export type AppStartupType = 'iframe' | 'direct';

/**
* Represents a Base Request
*/
export interface IRequestBase {
readonly type:
| 'createApp'
| 'deleteVersion'
| 'deployVersion'
| 'deployVersionPreflight'
| 'lambdaAlias';
}

/**
* Represents a Deployer Response
*/
export interface IResponseBase {
readonly statusCode: number;
}
18 changes: 18 additions & 0 deletions packages/microapps-deployer-lib/src/messages/create-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IRequestBase } from './base';

/**
* Represents a Create Application Request
*/
export interface ICreateApplicationRequest extends IRequestBase {
readonly type: 'createApp';

/**
* Name of the application
*/
readonly appName: string;

/**
* Display name of the application
*/
readonly displayName: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IDeployVersionRequestBase } from './deploy-version';

/**
* Represents a Delete Version Request
*/
export interface IDeleteVersionRequest
extends Pick<IDeployVersionRequestBase, 'appName' | 'semVer'> {
readonly type: 'deleteVersion';
}
59 changes: 59 additions & 0 deletions packages/microapps-deployer-lib/src/messages/deploy-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { AppStartupType, AppType, IRequestBase } from './base';

/**
* Represents a Deploy Version Base Request
*/
export interface IDeployVersionRequestBase extends IRequestBase {
/**
* Name of the application
*/
readonly appName: string;

/**
* SemVer being published
*/
readonly semVer: string;

/**
* Allow overwrite of existing version
*
* @default false;
*/
readonly overwrite?: boolean;
}

/**
* Represents a Deploy Version Request
*/
export interface IDeployVersionRequest extends IDeployVersionRequestBase {
readonly type: 'deployVersion';
/**
* Type of the app (which implies how it's routed)
*/
readonly appType?: AppType;
/**
* Render the `/appName` route as an iframe pointing to `/appName/semVer`
* or proxy directly to `/appName/semVer` and render the app at `/appName`
*
* @default 'iframe'
*/
readonly startupType?: AppStartupType;
/**
* LambdaARN
* - With Alias suffix, used directly
* - With Version suffix, Alias will be updated or created for semVer
*
* Used for `lambda` and `lambda-url` apps
*/
readonly lambdaARN?: string;
/**
* Default file or path
* Typically used for `static` apps, but can be used for non-static apps
*/
readonly defaultFile: string;
/**
* Used for `url` not for `lambda-url` (as the Function URL is created by the
* DeployVersion action in that case)
*/
readonly url?: string;
}
3 changes: 3 additions & 0 deletions packages/microapps-deployer-lib/src/messages/deployer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IResponseBase } from './base';

export type IDeployerResponse = IResponseBase;
7 changes: 7 additions & 0 deletions packages/microapps-deployer-lib/src/messages/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './base';
export * from './create-app';
export * from './delete-version';
export * from './deploy-version';
export * from './deployer';
export * from './lambda-alias';
export * from './preflight';
44 changes: 44 additions & 0 deletions packages/microapps-deployer-lib/src/messages/lambda-alias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// import { AppType } from './base';
import { IDeployVersionRequestBase } from './deploy-version';
import { IDeployerResponse } from './deployer';

/**
* Represents a Lambda Alias Request
*/
export interface ILambdaAliasRequest extends IDeployVersionRequestBase {
readonly type: 'lambdaAlias';

/**
* Type of the app (which implies how it's routed)
*/
// readonly appType: Extract<AppType, 'lambda' | 'lambda-url'>;

/**
* LambdaARN
* - With Alias suffix, used directly
* - With Version suffix, Alias will be updated or created for semVer
*
* Used for `lambda` and `lambda-url` apps
*/
readonly lambdaARN: string;
}

/**
* Represents a Lambda Alias Response
*/
export interface ILambdaAliasResponse extends IDeployerResponse {
readonly type: 'lambdaAlias';

/**
* Full ARN of the Lambda Alias for this version
*/
readonly lambdaAliasARN: string;

/**
* Action taken by the deployer
* - `created` - Alias was created
* - `updated` - Alias was updated to point to a new version
* - `verified` - Alias already points to the correct version
*/
readonly actionTaken: 'created' | 'updated' | 'verified';
}
40 changes: 40 additions & 0 deletions packages/microapps-deployer-lib/src/messages/preflight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { IDeployVersionRequestBase } from './deploy-version';
import { IDeployerResponse } from './deployer';

/**
* Represents a Deploy Version Preflight Request
*/
export interface IDeployVersionPreflightRequest extends IDeployVersionRequestBase {
readonly type: 'deployVersionPreflight';

/**
* Retrieve S3 upload credentials
*
* @default true
*/
readonly needS3Creds?: boolean;
}

/**
* Represents a Deploy Version Preflight Response
*/
export interface IDeployVersionPreflightResponse extends IDeployerResponse {
/**
* Used to indicate which capabilities are available on this deployer
*/
readonly capabilities?: { readonly createAlias: string };

/**
* S3 upload URL for the staging bucket
*/
readonly s3UploadUrl?: string;

/**
* Temporary credentials for S3 upload to the staging bucket
*/
readonly awsCredentials?: {
readonly accessKeyId: string;
readonly secretAccessKey: string;
readonly sessionToken: string;
};
}
16 changes: 16 additions & 0 deletions packages/microapps-deployer-lib/src/versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Represents a Versions
*/
export interface IVersions {
version: string;
alias?: string;
}

/**
* Setup version and alias strings
* @param version
* @returns
*/
export function createVersions(version: string): IVersions {
return { version, alias: `v${version.replace(/\./g, '_')}` };
}
Loading