Skip to content

Commit 0e8a7bc

Browse files
committed
Release 0.0.41
1 parent afc3a18 commit 0e8a7bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+207
-255
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ravenapp/raven",
3-
"version": "0.0.40",
3+
"version": "0.0.41",
44
"repository": "https://github.com/ravenappdev/raven-node",
55
"files": [
66
"dist",

src/Client.ts

Lines changed: 112 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,131 @@
11
/**
2-
* This file auto-generated by Fern from our API Definition.
2+
* This file was auto-generated by Fern from our API Definition.
33
*/
44

55
import * as environments from "./environments";
66
import * as core from "./core";
7-
import { Client as DeviceClient } from "./resources/device/client/Client";
8-
import { Client as EventClient } from "./resources/event/client/Client";
9-
import { Client as UserClient } from "./resources/user/client/Client";
10-
import { RavenApi } from ".";
7+
import { RavenApi } from "@ravenapp/raven";
8+
import urlJoin from "url-join";
9+
import * as serializers from "./serialization";
10+
import * as errors from "./errors";
11+
import { Client as DeviceClient } from "./api/resources/device/client/Client";
12+
import { Client as UserClient } from "./api/resources/user/client/Client";
1113

1214
export declare namespace RavenApiClient {
13-
interface Options {
14-
environment?: environments.Environment | string;
15-
auth?: {
16-
authorization?: core.Supplier<string>;
17-
};
18-
}
15+
interface Options {
16+
environment?: environments.RavenApiEnvironment | string;
17+
authorization?: core.Supplier<string>;
18+
}
1919
}
2020

2121
export class RavenApiClient {
22-
constructor(private readonly options: RavenApiClient.Options) {}
22+
constructor(private readonly options: RavenApiClient.Options) {}
2323

24-
#device: DeviceClient | undefined;
24+
/**
25+
* This endpoint allows you to send messages
26+
* @throws {RavenApi.EventNotFoundError}
27+
*/
28+
public async send(appId: RavenApi.AppId, request: RavenApi.SendEventRequest): Promise<RavenApi.SendEventResponse> {
29+
const { idempotencyKey, ..._body } = request;
30+
const _response = await core.fetcher({
31+
url: urlJoin(
32+
this.options.environment ?? environments.RavenApiEnvironment.Prod,
33+
`/v1/apps/${appId}/events/send`
34+
),
35+
method: "POST",
36+
headers: {
37+
"Idempotency-Key": idempotencyKey,
38+
Authorization: await core.Supplier.get(this.options.authorization),
39+
},
40+
body: await serializers.SendEventRequest.json(_body),
41+
});
42+
if (_response.ok) {
43+
return await serializers.SendEventResponse.parse(_response.body as serializers.SendEventResponse.Raw);
44+
}
2545

26-
public get device(): DeviceClient {
27-
return (this.#device ??= new DeviceClient(this.options));
28-
}
46+
if (_response.error.reason === "status-code") {
47+
switch (_response.error.statusCode) {
48+
case 404:
49+
throw new RavenApi.EventNotFoundError(
50+
await serializers.EventNotFoundErrorBody.parse(
51+
_response.error.body as serializers.EventNotFoundErrorBody.Raw
52+
)
53+
);
54+
default:
55+
throw new errors.RavenApiError({
56+
statusCode: _response.error.statusCode,
57+
body: _response.error.body,
58+
});
59+
}
60+
}
2961

30-
#event: EventClient | undefined;
62+
switch (_response.error.reason) {
63+
case "non-json":
64+
throw new errors.RavenApiError({
65+
statusCode: _response.error.statusCode,
66+
body: _response.error.rawBody,
67+
});
68+
case "timeout":
69+
throw new errors.RavenApiTimeoutError();
70+
case "unknown":
71+
throw new errors.RavenApiError({
72+
message: _response.error.errorMessage,
73+
});
74+
}
75+
}
3176

32-
public get event(): EventClient {
33-
return (this.#event ??= new EventClient(this.options));
34-
}
77+
public async sendBulk(
78+
appId: RavenApi.AppId,
79+
request: RavenApi.BulkSendEventRequest
80+
): Promise<RavenApi.SendEventResponse> {
81+
const { idempotencyKey, ..._body } = request;
82+
const _response = await core.fetcher({
83+
url: urlJoin(
84+
this.options.environment ?? environments.RavenApiEnvironment.Prod,
85+
`/v1/apps/${appId}/events/bulk_send`
86+
),
87+
method: "POST",
88+
headers: {
89+
"Idempotency-Key": idempotencyKey,
90+
Authorization: await core.Supplier.get(this.options.authorization),
91+
},
92+
body: await serializers.BulkSendEventRequest.json(_body),
93+
});
94+
if (_response.ok) {
95+
return await serializers.SendEventResponse.parse(_response.body as serializers.SendEventResponse.Raw);
96+
}
3597

36-
public async send(
37-
request: RavenApi.event.send.Request
38-
): Promise<RavenApi.event.send.Response> {
39-
return this.event.send(request);
40-
}
98+
if (_response.error.reason === "status-code") {
99+
throw new errors.RavenApiError({
100+
statusCode: _response.error.statusCode,
101+
body: _response.error.body,
102+
});
103+
}
41104

42-
public async sendBulk(
43-
request: RavenApi.event.sendBulk.Request
44-
): Promise<RavenApi.event.sendBulk.Response> {
45-
return this.event.sendBulk(request);
46-
}
105+
switch (_response.error.reason) {
106+
case "non-json":
107+
throw new errors.RavenApiError({
108+
statusCode: _response.error.statusCode,
109+
body: _response.error.rawBody,
110+
});
111+
case "timeout":
112+
throw new errors.RavenApiTimeoutError();
113+
case "unknown":
114+
throw new errors.RavenApiError({
115+
message: _response.error.errorMessage,
116+
});
117+
}
118+
}
47119

48-
#user: UserClient | undefined;
120+
#device: DeviceClient | undefined;
49121

50-
public get user(): UserClient {
51-
return (this.#user ??= new UserClient(this.options));
52-
}
122+
public get device(): DeviceClient {
123+
return (this.#device ??= new DeviceClient(this.options));
124+
}
125+
126+
#user: UserClient | undefined;
127+
128+
public get user(): UserClient {
129+
return (this.#user ??= new UserClient(this.options));
130+
}
53131
}
File renamed without changes.

src/api/resources/event/errors/EventNotFoundError.ts renamed to src/api/errors/EventNotFoundError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file was auto-generated by Fern from our API Definition.
33
*/
44

5-
import * as errors from "../../../../errors";
5+
import * as errors from "../../errors";
66
import { RavenApi } from "@ravenapp/raven";
77

88
export class EventNotFoundError extends errors.RavenApiError {
File renamed without changes.

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
export * from "./resources";
2+
export * from "./types";
3+
export * from "./errors";
4+
export * from "./client";

src/api/resources/event/client/Client.ts

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)