-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57dcb00
commit 7e32685
Showing
73 changed files
with
1,589 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
import type { ErrorCode, ErrorResponse } from '$http/types'; | ||
import type { WebhookErrorCode, WebhookErrorResponse } from '$webhooks/types'; | ||
|
||
export default class MindbodyError extends Error { | ||
public code: ErrorCode; | ||
public code: ErrorCode | WebhookErrorCode[]; | ||
|
||
constructor(errorResponse: ErrorResponse) { | ||
constructor(errorResponse: ErrorResponse | WebhookErrorResponse) { | ||
super(); | ||
this.message = errorResponse.Error.Message; | ||
this.code = errorResponse.Error.Code; | ||
|
||
if (Object.keys(errorResponse).includes('errors')) { | ||
const error = errorResponse as WebhookErrorResponse; | ||
this.code = error.errors.map(e => e.errorType); | ||
this.message = error.errors | ||
.map(e => e.errorMessage) | ||
.join('. ') | ||
.trim(); | ||
return; | ||
} | ||
|
||
const error = errorResponse as ErrorResponse; | ||
this.code = error.Error.Code; | ||
this.message = error.Error.Message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { | ||
WebhooksRequestsArgsPatch, | ||
WebhooksRequestsArgsPost, | ||
} from '$http/types'; | ||
import type { Kv } from '$http/types/Kv'; | ||
|
||
import { BaseClient } from '$http/BaseClient'; | ||
|
||
type Returnable = Kv | (string | number)[]; | ||
|
||
export class MindbodyWebhooksClient extends BaseClient { | ||
private static instance?: MindbodyWebhooksClient = new this(); | ||
|
||
private constructor() { | ||
super('webhooks-client'); | ||
} | ||
|
||
public static get(): MindbodyWebhooksClient { | ||
return this.instance ?? (this.instance = new this()); | ||
} | ||
|
||
public async get<R extends Returnable>(endpoint: string): Promise<R> { | ||
const [client, headers] = this.webhookRequest(); | ||
const res = await client<R>(endpoint, { | ||
method: 'GET', | ||
headers, | ||
}); | ||
|
||
return res.data; | ||
} | ||
|
||
public async post<R extends Returnable>( | ||
endpoint: string, | ||
args: WebhooksRequestsArgsPost<Kv>, | ||
): Promise<R> { | ||
const [client, headers] = this.webhookRequest(); | ||
const res = await client<R>(endpoint, { | ||
method: 'POST', | ||
headers, | ||
data: args, | ||
}); | ||
|
||
return res.data; | ||
} | ||
|
||
public async patch<R extends Returnable>( | ||
endpoint: string, | ||
args: WebhooksRequestsArgsPatch<Kv>, | ||
): Promise<R> { | ||
const [client, headers] = this.webhookRequest(); | ||
const res = await client<R>(endpoint, { | ||
method: 'PATCH', | ||
headers, | ||
data: args, | ||
}); | ||
|
||
return res.data; | ||
} | ||
|
||
public async delete<R extends Returnable>(endpoint: string): Promise<R> { | ||
const [client, headers] = this.webhookRequest(); | ||
const res = await client.delete<R>(endpoint, { | ||
method: 'DELETE', | ||
headers, | ||
}); | ||
|
||
return res.data; | ||
} | ||
} |
Oops, something went wrong.