-
Notifications
You must be signed in to change notification settings - Fork 0
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
afc3a18
commit 0e8a7bc
Showing
65 changed files
with
207 additions
and
255 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,131 @@ | ||
/** | ||
* This file auto-generated by Fern from our API Definition. | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as environments from "./environments"; | ||
import * as core from "./core"; | ||
import { Client as DeviceClient } from "./resources/device/client/Client"; | ||
import { Client as EventClient } from "./resources/event/client/Client"; | ||
import { Client as UserClient } from "./resources/user/client/Client"; | ||
import { RavenApi } from "."; | ||
import { RavenApi } from "@ravenapp/raven"; | ||
import urlJoin from "url-join"; | ||
import * as serializers from "./serialization"; | ||
import * as errors from "./errors"; | ||
import { Client as DeviceClient } from "./api/resources/device/client/Client"; | ||
import { Client as UserClient } from "./api/resources/user/client/Client"; | ||
|
||
export declare namespace RavenApiClient { | ||
interface Options { | ||
environment?: environments.Environment | string; | ||
auth?: { | ||
authorization?: core.Supplier<string>; | ||
}; | ||
} | ||
interface Options { | ||
environment?: environments.RavenApiEnvironment | string; | ||
authorization?: core.Supplier<string>; | ||
} | ||
} | ||
|
||
export class RavenApiClient { | ||
constructor(private readonly options: RavenApiClient.Options) {} | ||
constructor(private readonly options: RavenApiClient.Options) {} | ||
|
||
#device: DeviceClient | undefined; | ||
/** | ||
* This endpoint allows you to send messages | ||
* @throws {RavenApi.EventNotFoundError} | ||
*/ | ||
public async send(appId: RavenApi.AppId, request: RavenApi.SendEventRequest): Promise<RavenApi.SendEventResponse> { | ||
const { idempotencyKey, ..._body } = request; | ||
const _response = await core.fetcher({ | ||
url: urlJoin( | ||
this.options.environment ?? environments.RavenApiEnvironment.Prod, | ||
`/v1/apps/${appId}/events/send` | ||
), | ||
method: "POST", | ||
headers: { | ||
"Idempotency-Key": idempotencyKey, | ||
Authorization: await core.Supplier.get(this.options.authorization), | ||
}, | ||
body: await serializers.SendEventRequest.json(_body), | ||
}); | ||
if (_response.ok) { | ||
return await serializers.SendEventResponse.parse(_response.body as serializers.SendEventResponse.Raw); | ||
} | ||
|
||
public get device(): DeviceClient { | ||
return (this.#device ??= new DeviceClient(this.options)); | ||
} | ||
if (_response.error.reason === "status-code") { | ||
switch (_response.error.statusCode) { | ||
case 404: | ||
throw new RavenApi.EventNotFoundError( | ||
await serializers.EventNotFoundErrorBody.parse( | ||
_response.error.body as serializers.EventNotFoundErrorBody.Raw | ||
) | ||
); | ||
default: | ||
throw new errors.RavenApiError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
} | ||
|
||
#event: EventClient | undefined; | ||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.RavenApiError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.RavenApiTimeoutError(); | ||
case "unknown": | ||
throw new errors.RavenApiError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
public get event(): EventClient { | ||
return (this.#event ??= new EventClient(this.options)); | ||
} | ||
public async sendBulk( | ||
appId: RavenApi.AppId, | ||
request: RavenApi.BulkSendEventRequest | ||
): Promise<RavenApi.SendEventResponse> { | ||
const { idempotencyKey, ..._body } = request; | ||
const _response = await core.fetcher({ | ||
url: urlJoin( | ||
this.options.environment ?? environments.RavenApiEnvironment.Prod, | ||
`/v1/apps/${appId}/events/bulk_send` | ||
), | ||
method: "POST", | ||
headers: { | ||
"Idempotency-Key": idempotencyKey, | ||
Authorization: await core.Supplier.get(this.options.authorization), | ||
}, | ||
body: await serializers.BulkSendEventRequest.json(_body), | ||
}); | ||
if (_response.ok) { | ||
return await serializers.SendEventResponse.parse(_response.body as serializers.SendEventResponse.Raw); | ||
} | ||
|
||
public async send( | ||
request: RavenApi.event.send.Request | ||
): Promise<RavenApi.event.send.Response> { | ||
return this.event.send(request); | ||
} | ||
if (_response.error.reason === "status-code") { | ||
throw new errors.RavenApiError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
|
||
public async sendBulk( | ||
request: RavenApi.event.sendBulk.Request | ||
): Promise<RavenApi.event.sendBulk.Response> { | ||
return this.event.sendBulk(request); | ||
} | ||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.RavenApiError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.RavenApiTimeoutError(); | ||
case "unknown": | ||
throw new errors.RavenApiError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
#user: UserClient | undefined; | ||
#device: DeviceClient | undefined; | ||
|
||
public get user(): UserClient { | ||
return (this.#user ??= new UserClient(this.options)); | ||
} | ||
public get device(): DeviceClient { | ||
return (this.#device ??= new DeviceClient(this.options)); | ||
} | ||
|
||
#user: UserClient | undefined; | ||
|
||
public get user(): UserClient { | ||
return (this.#user ??= new UserClient(this.options)); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 +1,4 @@ | ||
export * from "./resources"; | ||
export * from "./types"; | ||
export * from "./errors"; | ||
export * from "./client"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
export * as device from "./device"; | ||
export * from "./device/types"; | ||
export * as event from "./event"; | ||
export * from "./event/types"; | ||
export * as ids from "./ids"; | ||
export * from "./ids/types"; | ||
export * as user from "./user"; | ||
export * from "./user/types"; | ||
export * from "./event/errors"; | ||
export * from "./event/client/requests"; | ||
export * from "./user/client/requests"; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 +1,3 @@ | ||
export * from "./resources"; | ||
export * from "./types"; | ||
export * from "./client"; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
export * as device from "./device"; | ||
export * from "./device/types"; | ||
export * as event from "./event"; | ||
export * from "./event/types"; | ||
export * as ids from "./ids"; | ||
export * from "./ids/types"; | ||
export * as user from "./user"; | ||
export * from "./user/types"; | ||
export * from "./event/client/requests"; | ||
export * from "./user/client/requests"; |
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
Oops, something went wrong.