Skip to content

Commit dececa0

Browse files
committed
fix: implement workaround for schema invitations endpoint returning 403
1 parent 9041a85 commit dececa0

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

.changeset/good-houses-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smartthings/core-sdk": patch
3+
---
4+
5+
implement workaround for schema invitations endpoint returning 403

src/endpoint/invites-schemaApp.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ export class InvitesSchemaAppEndpoint extends Endpoint {
4141
}
4242

4343
public async list(schemaAppId: string): Promise<SchemaAppInvitation[]> {
44-
return this.client.getPagedItems('', { schemaAppId })
44+
try {
45+
return await this.client.getPagedItems('', { schemaAppId })
46+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
47+
} catch(error: any) {
48+
if (error.response?.status === 403) {
49+
return []
50+
}
51+
throw error
52+
}
4553
}
4654

4755
public async revoke(invitationId: string): Promise<void> {

src/endpoint/schema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,13 @@ export class SchemaEndpoint extends Endpoint {
292292
}
293293

294294
/**
295-
* Update an ST Schema connector
295+
* Update an ST Schema connector. The connector cannot be changed if the connector's
296+
* `certificationStatus` is `wwst` or `cst`.
296297
*
297298
* @param id the "endpointApp" UUID of the connector, e.g. "viper_799ff3a0-8249-11e9-9bf1-b5c7d651c2c3"
298299
* @param data new definition of the connector
299300
* @param organizationId The organization to associate the connector with. You must be a member
300-
* of the organization. The organization cannot be changed if the connector's `certificationStatus` is `wwst`.
301+
* of the organization.
301302
*/
302303
public async update(id: string, data: SchemaAppRequest, organizationId?: string): Promise<Status> {
303304
const options = organizationId ? { headerOverrides: { 'X-ST-Organization': organizationId } } : undefined

test/unit/invites-schemaApp.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ test('list', async () => {
3737
expect(getPagedItemsSpy).toHaveBeenCalledWith('', { schemaAppId: 'schema-app-id' })
3838
})
3939

40+
test('list with 403 error', async () => {
41+
getPagedItemsSpy.mockImplementationOnce(() => {
42+
throw { response: { status: 403 } }
43+
})
44+
45+
expect(await invitesEndpoint.list('schema-app-id')).toStrictEqual([])
46+
47+
expect(getPagedItemsSpy).toHaveBeenCalledTimes(1)
48+
expect(getPagedItemsSpy).toHaveBeenCalledWith('', { schemaAppId: 'schema-app-id' })
49+
})
50+
4051
test('revoke', async () => {
4152
await expect(invitesEndpoint.revoke('schema-app-id')).resolves.not.toThrow()
4253

0 commit comments

Comments
 (0)