-
Notifications
You must be signed in to change notification settings - Fork 578
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
Showing
8 changed files
with
700 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: v1 | ||
plugins: | ||
- plugin: es | ||
opt: | ||
- target=ts | ||
- import_extension=.ts | ||
out: src/proto | ||
- plugin: connect-es | ||
opt: | ||
- target=ts | ||
- import_extension=.ts | ||
out: src/proto |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
syntax = "proto3"; | ||
|
||
package courier; | ||
option go_package = "./;courier"; | ||
|
||
import "google/protobuf/struct.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
|
||
// | ||
// Messages | ||
// | ||
|
||
// Ping | ||
message PingRequest {} | ||
message PingResponse {} | ||
|
||
// Notifications | ||
|
||
enum AppPlatform { | ||
APP_PLATFORM_UNSPECIFIED = 0; | ||
APP_PLATFORM_IOS = 1; | ||
APP_PLATFORM_ANDROID = 2; | ||
APP_PLATFORM_WEB = 3; | ||
} | ||
|
||
message Notification { | ||
string id = 1; | ||
string recipient_did = 2; | ||
string title = 3; | ||
string message = 4; | ||
string collapse_key = 5; | ||
bool always_deliver = 6; | ||
google.protobuf.Timestamp timestamp = 7; | ||
google.protobuf.Struct additional = 8; | ||
} | ||
|
||
message PushNotificationsRequest { | ||
repeated Notification notifications = 1; | ||
} | ||
|
||
message PushNotificationsResponse {} | ||
|
||
message RegisterDeviceTokenRequest { | ||
string did = 1; | ||
string token = 2; | ||
string app_id = 3; | ||
AppPlatform platform = 4; | ||
} | ||
|
||
message RegisterDeviceTokenResponse {} | ||
|
||
service Service { | ||
rpc Ping(PingRequest) returns (PingResponse); | ||
rpc PushNotifications(PushNotificationsRequest) returns (PushNotificationsResponse); | ||
rpc RegisterDeviceToken(RegisterDeviceTokenRequest) returns (RegisterDeviceTokenResponse); | ||
} |
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,41 @@ | ||
import { Service } from './proto/courier_connect' | ||
import { | ||
Code, | ||
ConnectError, | ||
PromiseClient, | ||
createPromiseClient, | ||
Interceptor, | ||
} from '@connectrpc/connect' | ||
import { | ||
createConnectTransport, | ||
ConnectTransportOptions, | ||
} from '@connectrpc/connect-node' | ||
|
||
export type CourierClient = PromiseClient<typeof Service> | ||
|
||
export const createCourierClient = ( | ||
opts: ConnectTransportOptions, | ||
): CourierClient => { | ||
const transport = createConnectTransport(opts) | ||
return createPromiseClient(Service, transport) | ||
} | ||
|
||
export { Code } | ||
|
||
export const isCourierError = ( | ||
err: unknown, | ||
code?: Code, | ||
): err is ConnectError => { | ||
if (err instanceof ConnectError) { | ||
return !code || err.code === code | ||
} | ||
return false | ||
} | ||
|
||
export const authWithApiKey = | ||
(apiKey: string): Interceptor => | ||
(next) => | ||
(req) => { | ||
req.header.set('authorization', `Bearer ${apiKey}`) | ||
return next(req) | ||
} |
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,44 @@ | ||
// @generated by protoc-gen-connect-es v1.3.0 with parameter "target=ts,import_extension=.ts" | ||
// @generated from file courier.proto (package courier, syntax proto3) | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
|
||
import { PingRequest, PingResponse, PushNotificationsRequest, PushNotificationsResponse, RegisterDeviceTokenRequest, RegisterDeviceTokenResponse } from "./courier_pb.ts"; | ||
import { MethodKind } from "@bufbuild/protobuf"; | ||
|
||
/** | ||
* @generated from service courier.Service | ||
*/ | ||
export const Service = { | ||
typeName: "courier.Service", | ||
methods: { | ||
/** | ||
* @generated from rpc courier.Service.Ping | ||
*/ | ||
ping: { | ||
name: "Ping", | ||
I: PingRequest, | ||
O: PingResponse, | ||
kind: MethodKind.Unary, | ||
}, | ||
/** | ||
* @generated from rpc courier.Service.PushNotifications | ||
*/ | ||
pushNotifications: { | ||
name: "PushNotifications", | ||
I: PushNotificationsRequest, | ||
O: PushNotificationsResponse, | ||
kind: MethodKind.Unary, | ||
}, | ||
/** | ||
* @generated from rpc courier.Service.RegisterDeviceToken | ||
*/ | ||
registerDeviceToken: { | ||
name: "RegisterDeviceToken", | ||
I: RegisterDeviceTokenRequest, | ||
O: RegisterDeviceTokenResponse, | ||
kind: MethodKind.Unary, | ||
}, | ||
} | ||
} as const; | ||
|
Oops, something went wrong.