feat(projects): invite members to projects
This commit is contained in:
27
README.md
27
README.md
@@ -458,15 +458,38 @@ const project = await client.projects().create({
|
|||||||
**Returns:**
|
**Returns:**
|
||||||
- `ApiV1WorkspaceWorkspaceIdGet200ResponseWorkspace`: The project that was created.
|
- `ApiV1WorkspaceWorkspaceIdGet200ResponseWorkspace`: The project that was created.
|
||||||
|
|
||||||
|
|
||||||
|
#### Invite members to a project
|
||||||
|
|
||||||
|
When inviting members to projects, you must either specify the `emails` or `usernames`. If neither are specified, the SDK will throw an error.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const memberships = await client.projects().inviteMembers({
|
||||||
|
projectId: project.id,
|
||||||
|
emails: ["test1@example.com", "test2@example.com"], // Optional
|
||||||
|
usernames: ["example-user3", "example-user4"] // Optional
|
||||||
|
roleSlugs: ["member"] // Optional
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters:**
|
||||||
|
- `projectId`: (string): The ID of the project to invite members to
|
||||||
|
- `emails`: (string[]): An array of emails of the users to invite to the project.
|
||||||
|
- `usernames`: (string[]) An array of usernames of the users to invite to the project.
|
||||||
|
`roleSlugs`: (string[]): An array of role slugs to assign to the members. If not specified, this will default to `member`.
|
||||||
|
|
||||||
|
**Returns:**
|
||||||
|
- `ApiV1OrganizationAdminProjectsProjectIdGrantAdminAccessPost200ResponseMembership`: An array of the created project memberships.
|
||||||
|
|
||||||
### `environments`
|
### `environments`
|
||||||
|
|
||||||
#### Create a new environment
|
#### Create a new environment
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const environment = await client.environments().create({
|
const environment = await client.environments().create({
|
||||||
name: "Demo Environment",
|
name: "<environment-name>",
|
||||||
projectId: "<your-project-id>",
|
projectId: "<your-project-id>",
|
||||||
slug: "demo-environment",
|
slug: "<environment-slug>",
|
||||||
position: 1 // Optional
|
position: 1 // Optional
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
import { RawAxiosRequestConfig } from "axios";
|
import { RawAxiosRequestConfig } from "axios";
|
||||||
import { DefaultApi as InfisicalApi } from "../infisicalapi_client";
|
import { DefaultApi as InfisicalApi } from "../infisicalapi_client";
|
||||||
import type { ApiV2WorkspacePost200Response, ApiV2WorkspacePostRequest } from "../infisicalapi_client";
|
import type {
|
||||||
|
ApiV2WorkspacePost200Response,
|
||||||
|
ApiV2WorkspacePostRequest,
|
||||||
|
ApiV2WorkspaceProjectIdMembershipsPost200Response,
|
||||||
|
ApiV2WorkspaceProjectIdMembershipsPostRequest
|
||||||
|
} from "../infisicalapi_client";
|
||||||
import { newInfisicalError } from "./errors";
|
import { newInfisicalError } from "./errors";
|
||||||
|
|
||||||
export type CreateProjectOptions = ApiV2WorkspacePostRequest;
|
export type CreateProjectOptions = ApiV2WorkspacePostRequest;
|
||||||
export type CreateProjectResult = ApiV2WorkspacePost200Response;
|
export type CreateProjectResult = ApiV2WorkspacePost200Response;
|
||||||
|
|
||||||
|
export type InviteMemberToProjectOptions = { projectId: string } & ApiV2WorkspaceProjectIdMembershipsPostRequest;
|
||||||
|
export type InviteMemberToProjectResult = ApiV2WorkspaceProjectIdMembershipsPost200Response;
|
||||||
export default class ProjectsClient {
|
export default class ProjectsClient {
|
||||||
#apiInstance: InfisicalApi;
|
#apiInstance: InfisicalApi;
|
||||||
#requestOptions: RawAxiosRequestConfig | undefined;
|
#requestOptions: RawAxiosRequestConfig | undefined;
|
||||||
@@ -27,4 +34,23 @@ export default class ProjectsClient {
|
|||||||
throw newInfisicalError(err);
|
throw newInfisicalError(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inviteMembers = async (options: InviteMemberToProjectOptions): Promise<InviteMemberToProjectResult["memberships"]> => {
|
||||||
|
try {
|
||||||
|
if (!options.usernames?.length && !options.emails?.length) {
|
||||||
|
throw new Error("Either usernames or emails must be provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await this.#apiInstance.apiV2WorkspaceProjectIdMembershipsPost(
|
||||||
|
{
|
||||||
|
projectId: options.projectId,
|
||||||
|
apiV2WorkspaceProjectIdMembershipsPostRequest: options
|
||||||
|
},
|
||||||
|
this.#requestOptions
|
||||||
|
);
|
||||||
|
return res.data.memberships;
|
||||||
|
} catch (err) {
|
||||||
|
throw newInfisicalError(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +1,52 @@
|
|||||||
import { InfisicalSDK } from "../src";
|
import { InfisicalSDK } from "../src";
|
||||||
|
|
||||||
const PROJECT_ID = "PROJECT_ID";
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const client = new InfisicalSDK({
|
const client = new InfisicalSDK({
|
||||||
siteUrl: "http://localhost:8080" // Optional, defaults to https://app.infisical.com
|
siteUrl: "http://localhost:8080" // Optional, defaults to https://app.infisical.com
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const EMAIL_TO_INVITE = "<your-email>";
|
||||||
|
|
||||||
|
const universalAuthClientId = process.env.UNIVERSAL_AUTH_CLIENT_ID;
|
||||||
|
const universalAuthClientSecret = process.env.UNIVERSAL_AUTH_CLIENT_SECRET;
|
||||||
|
|
||||||
|
if (!universalAuthClientId || !universalAuthClientSecret) {
|
||||||
|
throw new Error("UNIVERSAL_AUTH_CLIENT_ID and UNIVERSAL_AUTH_CLIENT_SECRET must be set");
|
||||||
|
}
|
||||||
|
|
||||||
await client.auth().universalAuth.login({
|
await client.auth().universalAuth.login({
|
||||||
clientId: "CLIENT_ID",
|
clientId: universalAuthClientId,
|
||||||
clientSecret: "CLIENT_SECRET"
|
clientSecret: universalAuthClientSecret
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Creating project");
|
||||||
|
const project = await client.projects().create({
|
||||||
|
projectDescription: "test description",
|
||||||
|
projectName: "test project1344assdfd",
|
||||||
|
type: "secret-manager",
|
||||||
|
slug: "test-project1assdfd43"
|
||||||
});
|
});
|
||||||
|
|
||||||
const environment = await client.environments().create({
|
const environment = await client.environments().create({
|
||||||
name: "Demo Environment",
|
position: 100,
|
||||||
projectId: "<your-project-id>",
|
slug: "test-environment-custom-slug",
|
||||||
slug: "demo-environment",
|
name: "test environment",
|
||||||
position: 1 // Optional
|
projectId: project.id
|
||||||
});
|
|
||||||
|
|
||||||
const project = await client.projects().create({
|
|
||||||
projectName: "<name-of-project>",
|
|
||||||
type: "secret-manager", // cert-manager, secret-manager, kms, ssh
|
|
||||||
projectDescription: "<project-description>", // Optional
|
|
||||||
slug: "<slug-of-project-to-create>", // Optional
|
|
||||||
template: "<project-template-name>", // Optional
|
|
||||||
kmsKeyId: "kms-key-id" // Optional
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("Creating folder");
|
||||||
const folder = await client.folders().create({
|
const folder = await client.folders().create({
|
||||||
name: "<folder-name>",
|
name: "test-folder",
|
||||||
path: "<folder-path>",
|
projectId: project.id,
|
||||||
projectId: "<your-project-id>",
|
environment: environment.slug
|
||||||
environment: "<environment-slug>",
|
|
||||||
description: "<folder-description>" // Optional
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("Inviting member to project");
|
||||||
|
const memberships = await client.projects().inviteMembers({
|
||||||
|
projectId: project.id,
|
||||||
|
emails: [EMAIL_TO_INVITE],
|
||||||
|
roleSlugs: ["admin"]
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Memberships", memberships);
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user