2025-09-04 15:52:37 -07:00
|
|
|
import { IEncoder, IMessage } from "./message.js";
|
|
|
|
|
import { LightPushSDKResult } from "./protocols.js";
|
|
|
|
|
import type { ISendOptions } from "./sender.js";
|
2022-12-05 17:00:24 +11:00
|
|
|
|
2025-02-25 22:40:03 +01:00
|
|
|
export type LightPushProtocolOptions = ISendOptions & {
|
|
|
|
|
/**
|
|
|
|
|
* The interval in milliseconds to wait before retrying a failed push.
|
|
|
|
|
* @default 1000
|
|
|
|
|
*/
|
|
|
|
|
retryIntervalMs: number;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Number of peers to send message to.
|
|
|
|
|
*
|
|
|
|
|
* @default 1
|
|
|
|
|
*/
|
|
|
|
|
numPeersToUse?: number;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-04 15:52:37 -07:00
|
|
|
export type ILightPush = {
|
|
|
|
|
readonly multicodec: string[];
|
2025-02-25 22:40:03 +01:00
|
|
|
start: () => void;
|
|
|
|
|
stop: () => void;
|
2025-09-04 15:52:37 -07:00
|
|
|
send: (
|
|
|
|
|
encoder: IEncoder,
|
|
|
|
|
message: IMessage,
|
|
|
|
|
options?: ISendOptions
|
|
|
|
|
) => Promise<LightPushSDKResult>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export enum LightPushStatusCode {
|
|
|
|
|
SUCCESS = 200,
|
|
|
|
|
BAD_REQUEST = 400,
|
|
|
|
|
PAYLOAD_TOO_LARGE = 413,
|
|
|
|
|
INVALID_MESSAGE = 420,
|
|
|
|
|
UNSUPPORTED_TOPIC = 421,
|
|
|
|
|
TOO_MANY_REQUESTS = 429,
|
|
|
|
|
INTERNAL_ERROR = 500,
|
|
|
|
|
UNAVAILABLE = 503,
|
|
|
|
|
NO_RLN_PROOF = 504,
|
|
|
|
|
NO_PEERS = 505
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const StatusDescriptions: Record<LightPushStatusCode, string> = {
|
|
|
|
|
[LightPushStatusCode.SUCCESS]: "Message sent successfully",
|
|
|
|
|
[LightPushStatusCode.BAD_REQUEST]: "Bad request format",
|
|
|
|
|
[LightPushStatusCode.PAYLOAD_TOO_LARGE]:
|
|
|
|
|
"Message payload exceeds maximum size",
|
|
|
|
|
[LightPushStatusCode.INVALID_MESSAGE]: "Message validation failed",
|
|
|
|
|
[LightPushStatusCode.UNSUPPORTED_TOPIC]: "Unsupported pubsub topic",
|
|
|
|
|
[LightPushStatusCode.TOO_MANY_REQUESTS]: "Rate limit exceeded",
|
|
|
|
|
[LightPushStatusCode.INTERNAL_ERROR]: "Internal server error",
|
|
|
|
|
[LightPushStatusCode.UNAVAILABLE]: "Service temporarily unavailable",
|
|
|
|
|
[LightPushStatusCode.NO_RLN_PROOF]: "RLN proof generation failed",
|
|
|
|
|
[LightPushStatusCode.NO_PEERS]: "No relay peers available"
|
2025-02-25 22:40:03 +01:00
|
|
|
};
|