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

4️⃣ [ORG-61] Introduce OrganizationDomain and return domains from useOrganization #1569

Merged
merged 9 commits into from
Aug 10, 2023
34 changes: 0 additions & 34 deletions packages/clerk-js/src/core/resources/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,40 +126,6 @@ export class Organization extends BaseResource implements OrganizationResource {
return new OrganizationDomain(json);
};

prepareDomainAffiliationVerification = async ({
domainId,
emailAddress,
}: {
domainId: string;
emailAddress: string;
}): Promise<OrganizationDomainResource> => {
const json = (
await BaseResource._fetch<OrganizationDomainJSON>({
path: `/organizations/${this.id}/domains/${domainId}/prepare_affiliation_verification`,
method: 'POST',
body: { affiliationEmailAddress: emailAddress } as any,
})
)?.response as unknown as OrganizationDomainJSON;
return new OrganizationDomain(json);
};

attemptDomainAffiliationVerification = async ({
domainId,
code,
}: {
domainId: string;
code: string;
}): Promise<OrganizationDomainResource> => {
const json = (
await BaseResource._fetch<OrganizationDomainJSON>({
path: `/organizations/${this.id}/domains/${domainId}/attempt_affiliation_verification`,
method: 'POST',
body: { code } as any,
})
)?.response as unknown as OrganizationDomainJSON;
return new OrganizationDomain(json);
};

createDomain = async (name: string): Promise<OrganizationDomainResource> => {
return OrganizationDomain.create(this.id, { name });
};
Expand Down
38 changes: 22 additions & 16 deletions packages/clerk-js/src/core/resources/OrganizationDomain.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type {
AttemptAffiliationVerificationParams,
OrganizationDomainJSON,
OrganizationDomainResource,
OrganizationDomainVerification,
OrganizationEnrollmentMode,
PrepareAffiliationVerificationParams,
UpdateOrganizationDomainParams,
} from '@clerk/types';

Expand Down Expand Up @@ -35,6 +37,26 @@ export class OrganizationDomain extends BaseResource implements OrganizationDoma
return new OrganizationDomain(json);
}

prepareDomainAffiliationVerification = async (
params: PrepareAffiliationVerificationParams,
): Promise<OrganizationDomainResource> => {
return this._basePost({
path: `/organizations/${this.organizationId}/domains/${this.id}/prepare_affiliation_verification`,
method: 'POST',
body: params as any,
});
};

attemptAffiliationVerification = async (
params: AttemptAffiliationVerificationParams,
): Promise<OrganizationDomainResource> => {
return this._basePost({
path: `/organizations/${this.organizationId}/domains/${this.id}/attempt_affiliation_verification`,
method: 'POST',
body: params as any,
});
};

update = (params: UpdateOrganizationDomainParams): Promise<OrganizationDomainResource> => {
return this._basePatch({
method: 'PATCH',
Expand All @@ -49,22 +71,6 @@ export class OrganizationDomain extends BaseResource implements OrganizationDoma
});
};

// static async get({
// organizationId,
// domainId,
// }: {
// organizationId: string;
// domainId: string;
// }): Promise<OrganizationDomainResource> {
// const json = (
// await BaseResource._fetch<OrganizationDomainJSON>({
// path: `/organizations/${organizationId}/domains/${domainId}`,
// method: 'GET',
// })
// )?.response as unknown as OrganizationDomainJSON;
// return new OrganizationDomain(json);
// }

protected fromJSON(data: OrganizationDomainJSON | null): this {
if (data) {
this.id = data.id;
Expand Down
15 changes: 0 additions & 15 deletions packages/types/src/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@ export interface OrganizationResource extends ClerkResource {
removeMember: (userId: string) => Promise<OrganizationMembershipResource>;
createDomain: (domainName: string) => Promise<OrganizationDomainResource>;
getDomain: ({ domainId }: { domainId: string }) => Promise<OrganizationDomainResource>;
prepareDomainAffiliationVerification: ({
domainId,
emailAddress,
}: {
domainId: string;
emailAddress: string;
}) => Promise<OrganizationDomainResource>;

attemptDomainAffiliationVerification: ({
domainId,
code,
}: {
domainId: string;
code: string;
}) => Promise<OrganizationDomainResource>;
destroy: () => Promise<void>;
setLogo: (params: SetOrganizationLogoParams) => Promise<OrganizationResource>;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/types/src/organizationDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,21 @@ export interface OrganizationDomainResource extends ClerkResource {
createdAt: Date;
updatedAt: Date;
affiliationEmailAddress: string | null;
prepareDomainAffiliationVerification: (
params: PrepareAffiliationVerificationParams,
) => Promise<OrganizationDomainResource>;

attemptAffiliationVerification: (params: AttemptAffiliationVerificationParams) => Promise<OrganizationDomainResource>;
delete: () => Promise<void>;
update: (params: UpdateOrganizationDomainParams) => Promise<OrganizationDomainResource>;
}

export type PrepareAffiliationVerificationParams = {
affiliationEmailAddress: string;
};

export type AttemptAffiliationVerificationParams = {
emailAddress: string;
panteliselef marked this conversation as resolved.
Show resolved Hide resolved
};

export type UpdateOrganizationDomainParams = Partial<Pick<OrganizationDomainResource, 'enrollmentMode'>>;