@lynkoria/contracts 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ export declare const ErrorCode: {
2
+ readonly BadRequest: 'bad_request';
3
+ readonly Unauthorized: 'unauthorized';
4
+ readonly Forbidden: 'forbidden';
5
+ readonly NotFound: 'not_found';
6
+ readonly Conflict: 'conflict';
7
+ readonly PayloadTooLarge: 'payload_too_large';
8
+ readonly RateLimited: 'rate_limited';
9
+ readonly QuotaExceeded: 'quota_exceeded';
10
+ readonly FeatureDisabled: 'feature_disabled';
11
+ readonly Internal: 'internal_error';
12
+ readonly Unavailable: 'service_unavailable';
13
+ };
14
+ export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
15
+ export type ErrorBody = {
16
+ error: {
17
+ code: ErrorCode;
18
+ message: string;
19
+ requestId?: string;
20
+ details?: unknown;
21
+ };
22
+ };
23
+ /** Typed error thrown by every Lynkoria SDK for non-2xx responses and socket failures. */
24
+ export declare class LynkoriaError extends Error {
25
+ readonly code: ErrorCode;
26
+ readonly status: number;
27
+ readonly requestId: string | undefined;
28
+ readonly details: unknown;
29
+ constructor(code: ErrorCode, message: string, status?: number, requestId?: string, details?: unknown);
30
+ static fromBody(status: number, body: unknown): LynkoriaError;
31
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,35 @@
1
+ // src/errors.ts
2
+ const ErrorCode = {
3
+ BadRequest: "bad_request",
4
+ Unauthorized: "unauthorized",
5
+ Forbidden: "forbidden",
6
+ NotFound: "not_found",
7
+ Conflict: "conflict",
8
+ PayloadTooLarge: "payload_too_large",
9
+ RateLimited: "rate_limited",
10
+ QuotaExceeded: "quota_exceeded",
11
+ FeatureDisabled: "feature_disabled",
12
+ Internal: "internal_error",
13
+ Unavailable: "service_unavailable"
14
+ };
15
+ /** Typed error thrown by every Lynkoria SDK for non-2xx responses and socket failures. */
16
+ var LynkoriaError = class LynkoriaError extends Error {
17
+ code;
18
+ status;
19
+ requestId;
20
+ details;
21
+ constructor(code, message, status = 0, requestId, details) {
22
+ super(message);
23
+ this.name = "LynkoriaError";
24
+ this.code = code;
25
+ this.status = status;
26
+ this.requestId = requestId;
27
+ this.details = details;
28
+ }
29
+ static fromBody(status, body) {
30
+ const err = body?.error;
31
+ if (err && typeof err.code === "string" && typeof err.message === "string") return new LynkoriaError(err.code, err.message, status, err.requestId, err.details);
32
+ return new LynkoriaError(status >= 500 ? ErrorCode.Internal : ErrorCode.BadRequest, `HTTP ${status}`, status);
33
+ }
34
+ };
35
+ export { ErrorCode, LynkoriaError };
@@ -0,0 +1,118 @@
1
+ import { ErrorCode } from "./errors.js";
2
+ import { CallSignalType, ConversationEvent, ManualStatus, Presence, SendMessageRequest, SendMessageResponse } from "./schemas.js";
3
+ /** Socket.IO acknowledgement envelope used by every client → server event with a callback. */
4
+ export type Ack<T> = {
5
+ ok: true;
6
+ data: T;
7
+ } | {
8
+ ok: false;
9
+ error: {
10
+ code: ErrorCode;
11
+ message: string;
12
+ };
13
+ };
14
+ export type CallSignalEvent = {
15
+ callId: string;
16
+ type: CallSignalType;
17
+ fromUserId: string | null;
18
+ data: Record<string, unknown>;
19
+ sentAt: string;
20
+ };
21
+ export type ConversationReadEvent = {
22
+ conversationId: string;
23
+ userId: string;
24
+ seq: number;
25
+ };
26
+ export type TypingEvent = {
27
+ conversationId: string;
28
+ userId: string;
29
+ };
30
+ export type ConversationUpdatedEvent = {
31
+ conversationId: string;
32
+ reason: 'members_changed' | 'removed';
33
+ };
34
+ export interface ServerToClientEvents {
35
+ 'message:created': (event: ConversationEvent) => void;
36
+ 'message:updated': (event: ConversationEvent) => void;
37
+ 'message:deleted': (event: ConversationEvent) => void;
38
+ 'reaction:added': (event: ConversationEvent) => void;
39
+ 'reaction:removed': (event: ConversationEvent) => void;
40
+ 'conversation:updated': (event: ConversationUpdatedEvent) => void;
41
+ 'conversation:read': (event: ConversationReadEvent) => void;
42
+ 'typing:start': (event: TypingEvent) => void;
43
+ 'typing:stop': (event: TypingEvent) => void;
44
+ 'presence:changed': (presence: Presence) => void;
45
+ 'call:invited': (event: CallSignalEvent) => void;
46
+ 'call:ringing': (event: CallSignalEvent) => void;
47
+ 'call:accepted': (event: CallSignalEvent) => void;
48
+ 'call:declined': (event: CallSignalEvent) => void;
49
+ 'call:ended': (event: CallSignalEvent) => void;
50
+ 'session:expiring': (event: {
51
+ expiresAt: string;
52
+ }) => void;
53
+ }
54
+ export interface ClientToServerEvents {
55
+ 'message:send': (input: SendMessageRequest & {
56
+ conversationId: string;
57
+ }, ack: (res: Ack<SendMessageResponse>) => void) => void;
58
+ 'typing:start': (input: {
59
+ conversationId: string;
60
+ }) => void;
61
+ 'typing:stop': (input: {
62
+ conversationId: string;
63
+ }) => void;
64
+ 'presence:heartbeat': () => void;
65
+ 'presence:subscribe': (input: {
66
+ userIds: string[];
67
+ }, ack: (res: Ack<Presence[]>) => void) => void;
68
+ 'presence:unsubscribe': (input: {
69
+ userIds: string[];
70
+ }) => void;
71
+ 'presence:set-status': (input: {
72
+ status: ManualStatus;
73
+ }, ack: (res: Ack<null>) => void) => void;
74
+ 'session:refresh': (input: {
75
+ token: string;
76
+ }, ack: (res: Ack<{
77
+ expiresAt: string;
78
+ }>) => void) => void;
79
+ }
80
+ /** Event names, for consumers that cannot use the typed maps. */
81
+ export declare const SocketEvents: {
82
+ readonly MessageCreated: 'message:created';
83
+ readonly MessageUpdated: 'message:updated';
84
+ readonly MessageDeleted: 'message:deleted';
85
+ readonly ReactionAdded: 'reaction:added';
86
+ readonly ReactionRemoved: 'reaction:removed';
87
+ readonly ConversationUpdated: 'conversation:updated';
88
+ readonly ConversationRead: 'conversation:read';
89
+ readonly TypingStart: 'typing:start';
90
+ readonly TypingStop: 'typing:stop';
91
+ readonly PresenceChanged: 'presence:changed';
92
+ readonly CallInvited: 'call:invited';
93
+ readonly CallRinging: 'call:ringing';
94
+ readonly CallAccepted: 'call:accepted';
95
+ readonly CallDeclined: 'call:declined';
96
+ readonly CallEnded: 'call:ended';
97
+ };
98
+ export declare const WEBHOOK_SIGNATURE_HEADER = "lynkoria-signature";
99
+ /** Products reject signatures older than this. */
100
+ export declare const WEBHOOK_TOLERANCE_SECONDS = 300;
101
+ export type WebhookEventType = 'call.started' | 'call.ended' | 'participant.joined' | 'participant.left' | 'message.created';
102
+ export type WebhookEvent<T = Record<string, unknown>> = {
103
+ id: string;
104
+ type: WebhookEventType;
105
+ created_at: string;
106
+ project_id: string;
107
+ environment_id: string;
108
+ data: T;
109
+ };
110
+ /** Payload keys every SDK reads from a Lynkoria push (`data` on FCM, `lynkoria` on APNs). */
111
+ export declare const PushPayloadKeys: {
112
+ readonly kind: 'lynkoria_kind';
113
+ readonly callId: 'lynkoria_call_id';
114
+ readonly callType: 'lynkoria_call_type';
115
+ readonly fromUserId: 'lynkoria_from_user_id';
116
+ readonly tenantId: 'lynkoria_tenant_id';
117
+ readonly sentAt: 'lynkoria_sent_at';
118
+ };
package/dist/events.js ADDED
@@ -0,0 +1,32 @@
1
+ // src/events.ts
2
+ /** Event names, for consumers that cannot use the typed maps. */
3
+ const SocketEvents = {
4
+ MessageCreated: "message:created",
5
+ MessageUpdated: "message:updated",
6
+ MessageDeleted: "message:deleted",
7
+ ReactionAdded: "reaction:added",
8
+ ReactionRemoved: "reaction:removed",
9
+ ConversationUpdated: "conversation:updated",
10
+ ConversationRead: "conversation:read",
11
+ TypingStart: "typing:start",
12
+ TypingStop: "typing:stop",
13
+ PresenceChanged: "presence:changed",
14
+ CallInvited: "call:invited",
15
+ CallRinging: "call:ringing",
16
+ CallAccepted: "call:accepted",
17
+ CallDeclined: "call:declined",
18
+ CallEnded: "call:ended"
19
+ };
20
+ const WEBHOOK_SIGNATURE_HEADER = "lynkoria-signature";
21
+ /** Products reject signatures older than this. */
22
+ const WEBHOOK_TOLERANCE_SECONDS = 300;
23
+ /** Payload keys every SDK reads from a Lynkoria push (`data` on FCM, `lynkoria` on APNs). */
24
+ const PushPayloadKeys = {
25
+ kind: "lynkoria_kind",
26
+ callId: "lynkoria_call_id",
27
+ callType: "lynkoria_call_type",
28
+ fromUserId: "lynkoria_from_user_id",
29
+ tenantId: "lynkoria_tenant_id",
30
+ sentAt: "lynkoria_sent_at"
31
+ };
32
+ export { PushPayloadKeys, SocketEvents, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TOLERANCE_SECONDS };
@@ -0,0 +1,6 @@
1
+ import { ErrorBody, ErrorCode, LynkoriaError } from "./errors.js";
2
+ import { Ack, CallSignalEvent, ClientToServerEvents, ConversationReadEvent, ConversationUpdatedEvent, PushPayloadKeys, ServerToClientEvents, SocketEvents, TypingEvent, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TOLERANCE_SECONDS, WebhookEvent, WebhookEventType } from "./events.js";
3
+ import { AdminCall, AdminCallDetail, AdminCallPage, AdminCallQuery, AdminMe, AdminParticipant, Attachment, AttachmentScanStatus, AttachmentStatus, AuditEvent, AuditPage, AuditQuery, Call, CallSignalRequest, CallSignalType, CallStatus, CallType, ConnectivityStatus, ConsoleRole, ConsoleSession, Conversation, ConversationEvent, ConversationEventPage, ConversationEventType, ConversationList, ConversationType, CreateCallRequest, CreateConversationRequest, CreateEnvironmentRequest, CreateKeyRequest, CreateProjectRequest, CreatedServiceKey, DownloadUrlResponse, EditMessageRequest, Environment, EnvironmentLive, EnvironmentName, GrantRoleRequest, JoinTokenRequest, JoinTokenResponse, ManualStatus, MembersRequest, Message, MessagingTokenRequest, MessagingTokenResponse, NotificationPreferences, OpsOverview, OrganizationLive, ParticipantRole, PatchEnvironmentRequest, PatchProjectRequest, Presence, PresenceStatus, ProductId, ProductMessagingPolicy, Project, ProjectFeatures, ProjectLimits, ProjectLive, PushDeliveryView, PushDevice, PushPlatform, PushProvider, Reaction, ReactionRequest, ReadRequest, Recording, RecordingDownload, RecordingFile, RecordingKind, RecordingList, RecordingOutput, RecordingStatus, RegisterDeviceRequest, RoleGrant, ScanSummary, SendMessageRequest, SendMessageResponse, SendNotificationRequest, SendNotificationResponse, ServiceKey, ServiceScope, StartRecordingRequest, TenantId, UpdatePermissionsRequest, UploadIntentRequest, UploadIntentResponse, UsageCounts, UsageQuery, UsageRow, UsageSeries, UsageSeriesQuery, Uuid, WebhookDelivery, WebhookEventPage, WebhookSecret } from "./schemas.js";
4
+ /** Bumped when the REST/event contract changes incompatibly. */
5
+ export declare const API_VERSION = "v1";
6
+ export { Ack, AdminCall, AdminCallDetail, AdminCallPage, AdminCallQuery, AdminMe, AdminParticipant, Attachment, AttachmentScanStatus, AttachmentStatus, AuditEvent, AuditPage, AuditQuery, Call, CallSignalEvent, CallSignalRequest, CallSignalType, CallStatus, CallType, ClientToServerEvents, ConnectivityStatus, ConsoleRole, ConsoleSession, Conversation, ConversationEvent, ConversationEventPage, ConversationEventType, ConversationList, ConversationReadEvent, ConversationType, ConversationUpdatedEvent, CreateCallRequest, CreateConversationRequest, CreateEnvironmentRequest, CreateKeyRequest, CreateProjectRequest, CreatedServiceKey, DownloadUrlResponse, EditMessageRequest, Environment, EnvironmentLive, EnvironmentName, ErrorBody, ErrorCode, GrantRoleRequest, JoinTokenRequest, JoinTokenResponse, LynkoriaError, ManualStatus, MembersRequest, Message, MessagingTokenRequest, MessagingTokenResponse, NotificationPreferences, OpsOverview, OrganizationLive, ParticipantRole, PatchEnvironmentRequest, PatchProjectRequest, Presence, PresenceStatus, ProductId, ProductMessagingPolicy, Project, ProjectFeatures, ProjectLimits, ProjectLive, PushDeliveryView, PushDevice, PushPayloadKeys, PushPlatform, PushProvider, Reaction, ReactionRequest, ReadRequest, Recording, RecordingDownload, RecordingFile, RecordingKind, RecordingList, RecordingOutput, RecordingStatus, RegisterDeviceRequest, RoleGrant, ScanSummary, SendMessageRequest, SendMessageResponse, SendNotificationRequest, SendNotificationResponse, ServerToClientEvents, ServiceKey, ServiceScope, SocketEvents, StartRecordingRequest, TenantId, TypingEvent, UpdatePermissionsRequest, UploadIntentRequest, UploadIntentResponse, UsageCounts, UsageQuery, UsageRow, UsageSeries, UsageSeriesQuery, Uuid, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TOLERANCE_SECONDS, WebhookDelivery, WebhookEvent, WebhookEventPage, WebhookEventType, WebhookSecret };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { ErrorCode, LynkoriaError } from "./errors.js";
2
+ import { PushPayloadKeys, SocketEvents, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TOLERANCE_SECONDS } from "./events.js";
3
+ import { AdminCall, AdminCallDetail, AdminCallPage, AdminCallQuery, AdminMe, AdminParticipant, Attachment, AttachmentScanStatus, AttachmentStatus, AuditEvent, AuditPage, AuditQuery, Call, CallSignalRequest, CallSignalType, CallStatus, CallType, ConnectivityStatus, ConsoleRole, ConsoleSession, Conversation, ConversationEvent, ConversationEventPage, ConversationEventType, ConversationList, ConversationType, CreateCallRequest, CreateConversationRequest, CreateEnvironmentRequest, CreateKeyRequest, CreateProjectRequest, CreatedServiceKey, DownloadUrlResponse, EditMessageRequest, Environment, EnvironmentLive, EnvironmentName, GrantRoleRequest, JoinTokenRequest, JoinTokenResponse, ManualStatus, MembersRequest, Message, MessagingTokenRequest, MessagingTokenResponse, NotificationPreferences, OpsOverview, OrganizationLive, ParticipantRole, PatchEnvironmentRequest, PatchProjectRequest, Presence, PresenceStatus, ProductId, ProductMessagingPolicy, Project, ProjectFeatures, ProjectLimits, ProjectLive, PushDeliveryView, PushDevice, PushPlatform, PushProvider, Reaction, ReactionRequest, ReadRequest, Recording, RecordingDownload, RecordingFile, RecordingKind, RecordingList, RecordingOutput, RecordingStatus, RegisterDeviceRequest, RoleGrant, ScanSummary, SendMessageRequest, SendMessageResponse, SendNotificationRequest, SendNotificationResponse, ServiceKey, ServiceScope, StartRecordingRequest, TenantId, UpdatePermissionsRequest, UploadIntentRequest, UploadIntentResponse, UsageCounts, UsageQuery, UsageRow, UsageSeries, UsageSeriesQuery, Uuid, WebhookDelivery, WebhookEventPage, WebhookSecret } from "./schemas.js";
4
+ // src/index.ts
5
+ /** Bumped when the REST/event contract changes incompatibly. */
6
+ const API_VERSION = "v1";
7
+ export { API_VERSION, AdminCall, AdminCallDetail, AdminCallPage, AdminCallQuery, AdminMe, AdminParticipant, Attachment, AttachmentScanStatus, AttachmentStatus, AuditEvent, AuditPage, AuditQuery, Call, CallSignalRequest, CallSignalType, CallStatus, CallType, ConnectivityStatus, ConsoleRole, ConsoleSession, Conversation, ConversationEvent, ConversationEventPage, ConversationEventType, ConversationList, ConversationType, CreateCallRequest, CreateConversationRequest, CreateEnvironmentRequest, CreateKeyRequest, CreateProjectRequest, CreatedServiceKey, DownloadUrlResponse, EditMessageRequest, Environment, EnvironmentLive, EnvironmentName, ErrorCode, GrantRoleRequest, JoinTokenRequest, JoinTokenResponse, LynkoriaError, ManualStatus, MembersRequest, Message, MessagingTokenRequest, MessagingTokenResponse, NotificationPreferences, OpsOverview, OrganizationLive, ParticipantRole, PatchEnvironmentRequest, PatchProjectRequest, Presence, PresenceStatus, ProductId, ProductMessagingPolicy, Project, ProjectFeatures, ProjectLimits, ProjectLive, PushDeliveryView, PushDevice, PushPayloadKeys, PushPlatform, PushProvider, Reaction, ReactionRequest, ReadRequest, Recording, RecordingDownload, RecordingFile, RecordingKind, RecordingList, RecordingOutput, RecordingStatus, RegisterDeviceRequest, RoleGrant, ScanSummary, SendMessageRequest, SendMessageResponse, SendNotificationRequest, SendNotificationResponse, ServiceKey, ServiceScope, SocketEvents, StartRecordingRequest, TenantId, UpdatePermissionsRequest, UploadIntentRequest, UploadIntentResponse, UsageCounts, UsageQuery, UsageRow, UsageSeries, UsageSeriesQuery, Uuid, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TOLERANCE_SECONDS, WebhookDelivery, WebhookEventPage, WebhookSecret };