Skip to content

Commit

Permalink
feat: add get one business invitation endpoint (#557)
Browse files Browse the repository at this point in the history
* feat: add get one business invitation endpoint

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* chore: log auth token error

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* chore: always return new TestPlatform

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* fix: remove return type added by mistake

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* chore: log to see the actual error

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

---------

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
  • Loading branch information
chenhunghan authored Sep 4, 2024
1 parent e9d289c commit 448b3be
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
10 changes: 8 additions & 2 deletions integration-test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ export const testPlatformFactory = async (username: string, password: string) =>
scope: "openid",
};

const accessToken = (await client.getToken(tokenParams)).token.access_token as string;
try {
const accessToken = (await client.getToken(tokenParams)).token.access_token as string;

return new TestPlatform(accessToken);
return new TestPlatform(accessToken);
} catch (error) {
console.error(error);
}

return new TestPlatform("");
};

export const rng = () => String(Math.ceil(Math.random() * 1000000000));
72 changes: 72 additions & 0 deletions src/BusinessService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,60 @@ export type BusinessInvitation = {
createdById: string;
};

/**
* BusinessInvitation plus the public business info that is accessable to the invited, pending business user.
*/
export type BusinessInvitationWithBusinessInfo = BusinessInvitation & {
/**
* The business id (in uuid format)
*/
id: string;
/**
* The business name.
*/
name: string;
/**
* The department name of the business
*/
department: string;
/**
* The business handle.
*/
handle: string;
/**
* The website URL of the business
*/
websiteUrl: string;
/**
* The business phone number.
*/
phoneNumber: string;
/**
* The business country.
*/
country: string;
/**
* The business state / province.
*/
state: string | null;
/**
* The business zip/postal code.
*/
zip: string;
/**
* The business city.
*/
city: string;
/**
* The business address.
*/
address: string;
/**
* The business additional address (a.ka. "address line 2").
*/
additionalAddress: string | null;
};

export type BusinessHierarchyInvitationState = "pending" | "accepted" | "rejected" | "canceled";
export type BusinessHierarchyInvitation = {
/**
Expand Down Expand Up @@ -1017,6 +1071,24 @@ class BusinessService extends Base {
return json as unknown as BusinessInvitation[];
}

/**
* Get one business invitation by an invitation id
*/
async getOneInvitation(
businessId: Business["id"],
invitationId: BusinessInvitation["id"],
): Promise<BusinessInvitationWithBusinessInfo> {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/businesses/${businessId}/invitations/${invitationId}`;
const json = await throwExpected(async () => fetch.get(url), {
401: (error) => new UnauthorizedException(error?.body?.message),
403: (error) => new ForbiddenException(error?.body.message),
404: (error) => new NotFoundException(error?.body.message),
});

return json as unknown as BusinessInvitationWithBusinessInfo;
}

/**
* Create a new invitation for a user to join a business, optionally assigning them to a
* subscription by given subscriptionId.
Expand Down
1 change: 1 addition & 0 deletions src/exceptions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const throwExpected = async <T = any>(
}
}

console.log(error);
// If axios.isAxiosError(error) returns falsy
throw new LensSDKException(
(error as any)?.response?.status,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
Business,
BusinessSubscription,
BusinessInvitation,
BusinessInvitationWithBusinessInfo,
UserBusinessRole,
BusinessInvitationState,
BusinessUpdate,
Expand Down Expand Up @@ -80,6 +81,7 @@ export type {
Business,
BusinessSubscription,
BusinessInvitation,
BusinessInvitationWithBusinessInfo,
UserBusinessRole,
BusinessInvitationState,
BusinessUpdate,
Expand Down

0 comments on commit 448b3be

Please sign in to comment.