Skip to content
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
25 changes: 25 additions & 0 deletions examples/src/environments/get-environments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ClientConfiguration, EnvironmentV2Repository } from "../../../src/index";
import { CreateClient } from "../utility";

const main = async () => {

const configuration: ClientConfiguration = {
userAgentApp: "examples",
instanceURL: "instance-url", // required
apiKey: "api-key", // required
};

const client = await CreateClient(configuration);

const environmentsRepo = new EnvironmentV2Repository(client, "Default");

const environments = await environmentsRepo.list({ skip: 0, take: 1000 });

if (environments.Items.length === 0) {
console.log("No environments found.");
return;
}
environments.Items.map(env => console.log(` - ${env.Name} (ID: ${env.Id})`));
};

main();
28 changes: 28 additions & 0 deletions src/features/deploymentEnvironments/environmentV2Repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Client, DeploymentEnvironmentV2, ResourceCollection, spaceScopedRoutePrefix } from "../..";

type EnvironmentV2RepositoryListArgs = {
Copy link
Contributor

Choose a reason for hiding this comment

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

The v2 endpoint supports optional filtering by an array of environment types using the type property, for completeness it's prob worth adding that as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea :)

ids?: string[];
partialName?: string;
type?: EnvironmentType;
skip: number;
take: number;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the skip and take values required as they're required on the v2 endpoint.

};

type EnvironmentType = "Static" | "Parent" | "Ephemeral";

export class EnvironmentV2Repository {
private client: Client;
private spaceName: string;

constructor(client: Client, spaceName: string) {
this.client = client;
this.spaceName = spaceName;
}

async list(args?: EnvironmentV2RepositoryListArgs): Promise<ResourceCollection<DeploymentEnvironmentV2>> {
return this.client.request(`${spaceScopedRoutePrefix}/environments/v2{?ids,partialName,type,skip,take}`, {
spaceName: this.spaceName,
...args,
});
}
}
1 change: 1 addition & 0 deletions src/features/deploymentEnvironments/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./deploymentEnvironment";
export * from "./environmentRepository";
export * from "./environmentV2Repository";
Loading