Skip to content

Commit

Permalink
fix: implement workaround for schema invitations endpoint returning 403
Browse files Browse the repository at this point in the history
  • Loading branch information
rossiam committed Sep 10, 2024
1 parent 9041a85 commit dececa0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-houses-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smartthings/core-sdk": patch
---

implement workaround for schema invitations endpoint returning 403
10 changes: 9 additions & 1 deletion src/endpoint/invites-schemaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ export class InvitesSchemaAppEndpoint extends Endpoint {
}

public async list(schemaAppId: string): Promise<SchemaAppInvitation[]> {
return this.client.getPagedItems('', { schemaAppId })
try {
return await this.client.getPagedItems('', { schemaAppId })
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch(error: any) {
if (error.response?.status === 403) {
return []
}
throw error
}
}

public async revoke(invitationId: string): Promise<void> {
Expand Down
5 changes: 3 additions & 2 deletions src/endpoint/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ export class SchemaEndpoint extends Endpoint {
}

/**
* Update an ST Schema connector
* Update an ST Schema connector. The connector cannot be changed if the connector's
* `certificationStatus` is `wwst` or `cst`.
*
* @param id the "endpointApp" UUID of the connector, e.g. "viper_799ff3a0-8249-11e9-9bf1-b5c7d651c2c3"
* @param data new definition of the connector
* @param organizationId The organization to associate the connector with. You must be a member
* of the organization. The organization cannot be changed if the connector's `certificationStatus` is `wwst`.
* of the organization.
*/
public async update(id: string, data: SchemaAppRequest, organizationId?: string): Promise<Status> {
const options = organizationId ? { headerOverrides: { 'X-ST-Organization': organizationId } } : undefined
Expand Down
11 changes: 11 additions & 0 deletions test/unit/invites-schemaApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ test('list', async () => {
expect(getPagedItemsSpy).toHaveBeenCalledWith('', { schemaAppId: 'schema-app-id' })
})

test('list with 403 error', async () => {
getPagedItemsSpy.mockImplementationOnce(() => {
throw { response: { status: 403 } }
})

expect(await invitesEndpoint.list('schema-app-id')).toStrictEqual([])

expect(getPagedItemsSpy).toHaveBeenCalledTimes(1)
expect(getPagedItemsSpy).toHaveBeenCalledWith('', { schemaAppId: 'schema-app-id' })
})

test('revoke', async () => {
await expect(invitesEndpoint.revoke('schema-app-id')).resolves.not.toThrow()

Expand Down

0 comments on commit dececa0

Please sign in to comment.