Skip to content
4 changes: 4 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export const serviceUsageOrigin = utils.envOverride(
"FIREBASE_SERVICE_USAGE_URL",
"https://serviceusage.googleapis.com"
);
export const frameworksOrigin = utils.envOverride(
"FRAMEWORKS_URL",
"https://placeholder.googleapis.com"
);
export const githubOrigin = utils.envOverride("GITHUB_URL", "https://github.com");
export const githubApiOrigin = utils.envOverride("GITHUB_API_URL", "https://api.github.com");
export const secretManagerOrigin = utils.envOverride(
Expand Down
117 changes: 117 additions & 0 deletions src/api/frameworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Client } from "../apiv2";
import { frameworksOrigin } from "../api";

export const API_VERSION = "v1";

const client = new Client({
urlPrefix: frameworksOrigin,
auth: true,
apiVersion: API_VERSION,
});

export type State = "BUILDING" | "BUILD" | "DEPLOYING" | "READY" | "FAILED";

interface Codebase {
repository?: string;
rootDirectory: string;
}

/** A Stack, the primary resource of Frameworks. */
interface Stack {
name: string;
mode?: string;
codebase: Codebase;
labels: Record<string, string>;
createTime: string;
updateTime: string;
uri: string;
}

export type StackOutputOnlyFields = "createTime" | "updateTime" | "uri";

interface Build {
name: string;
state: State;
error: Status;
image: string;
source: BuildSource;
buildLogsUri: string;
createTime: Date;
updateTime: Date;
sourceRef: string;
}

export type BuildOutputOnlyFields = "createTime" | "updateTime" | "sourceRef";

interface BuildSource {
codeBaseSource?: CodebaseSource;
}

interface Status {
code: number;
message: string;
details: any[];
}

interface CodebaseSource {
// oneof reference
branch: string;
commit: string;
tag: string;
// end oneof reference
}

export interface OperationMetadata {
createTime: string;
endTime: string;
target: string;
verb: string;
statusDetail: string;
cancelRequested: boolean;
apiVersion: string;
}

export interface Operation {
name: string;
metadata?: OperationMetadata;
done: boolean;
// oneof result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: what do these mean 🤔 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are part of Long Running Operation object and they are returned as response from the rpc method,
name: Service assigned name which is unique. For HttpMapping, the name is a resource name ending with operations/{unique_id}.
OperationMetadata: Service specific metadata associated with the operation. The is the metadata_type of the Operation.
done: If false then Operation is still running, if true operation is completed.

error?: Status;
response?: any;
// end oneof result
}

/**
* Creates a new Stack in a given project and location.
*/
export async function createStack(
projectId: string,
location: string,
stackId: string,
stack: Stack
): Promise<Operation> {
const res = await client.post<Omit<Stack, StackOutputOnlyFields>, Operation>(
`projects/${projectId}/locations/${location}/stacks`,
stack,
{ queryParams: { stackId } }
);
return res.body;
}

/**
* Creates a new Build in a given project and location.
*/
export async function createBuild(
projectId: string,
location: string,
stackId: string,
buildId: string,
build: Build
): Promise<Operation> {
const res = await client.post<Omit<Build, BuildOutputOnlyFields>, Operation>(
`projects/${projectId}/locations/${location}/stacks/${stackId}/builds`,
build,
{ queryParams: { buildId } }
);
return res.body;
}