@juki-team/commons 0.1.40 → 0.1.42

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.
@@ -1,6 +1,28 @@
1
- import { ClientId } from '../types';
1
+ import { ClientId, ContestChannelRole } from '../types';
2
2
  export declare const CHANNEL_PUBLISH_SUBSCRIPTIONS = "pub:subscriptions";
3
3
  export declare const CHANNEL_SUBSCRIBE_NOTIFICATIONS = "sub:notifications";
4
4
  export declare const CHANNEL_SUBSCRIBE_CLIENT: (clientId: ClientId) => string;
5
5
  export declare const CHANNEL_PUBLISH_MESSAGES = "pub:messages";
6
6
  export declare const CHANNEL_PRESENCE_CLIENT = "pre:client";
7
+ /** private: events of one session (code runs, requested data, client track commands) */
8
+ export declare const CHANNEL_SESSION: (sessionId: string) => string;
9
+ /** private: events of one user (own submissions while the contest is frozen, notifications) */
10
+ export declare const CHANNEL_USER: (userId: string) => string;
11
+ /** public: status of a submission when it is visible to everyone */
12
+ export declare const CHANNEL_SUBMISSION: (submitId: string) => string;
13
+ /** public: changes of a problem */
14
+ export declare const CHANNEL_PROBLEM: (problemKey: string) => string;
15
+ /** per role: events of a contest for one role (and the roles above it, see `ContestChannelRole`) */
16
+ export declare const CHANNEL_CONTEST: (contestKey: string, role: ContestChannelRole) => string;
17
+ /** system administrators only: data sent by a tracked client (screenshots, location, device) */
18
+ export declare const CHANNEL_CLIENT_TRACK: (trackedClientId: ClientId) => string;
19
+ export declare const CHANNEL_SUBMISSION_ALL = "submission:*";
20
+ export declare const CHANNEL_PROBLEM_ALL = "problem:*";
21
+ export declare const CHANNEL_CLIENT_TRACK_ALL = "client-track:*";
22
+ /**
23
+ * Returns the contest and role of a `CHANNEL_CONTEST` channel name, or null if it is not one.
24
+ */
25
+ export declare const getContestChannelParams: (channel: string) => {
26
+ contestKey: string;
27
+ role: ContestChannelRole;
28
+ } | null;
@@ -94,8 +94,16 @@ export interface UnsubscribeUserNotificationWebSocketEventDTO extends WebsocketS
94
94
  event: WebSocketSubscriptionEvent.UNSUBSCRIBE_USER_NOTIFICATION;
95
95
  userKey: string;
96
96
  }
97
- export type WebSocketSubscribeEventDTO = SubscribeCodeRunStatusWebSocketEventDTO | SubscribeSubmissionRunStatusWebSocketEventDTO | SubscribeGetDataWebSocketEventDTO | SubscribeProblemCrawledWebSocketEventDTO | SubscribeSubmissionsCrawlWebSocketEventDTO | SubscribeContestChangesWebSocketEventDTO | SubscribeClientTrackWebSocketEventDTO | SubscribeUserNotificationWebsocketEventDTO;
98
- export type WebSocketUnsubscribeEventDTO = UnsubscribeCodeRunStatusWebSocketEventDTO | UnsubscribeSubmissionRunStatusWebSocketEventDTO | UnsubscribeGetDataWebSocketEventDTO | UnsubscribeProblemCrawledWebSocketEventDTO | UnsubscribeSubmissionsCrawlWebSocketEventDTO | UnsubscribeContestChangesWebSocketEventDTO | UnsubscribeClientTrackWebSocketEventDTO | UnsubscribeUserNotificationWebSocketEventDTO;
97
+ export interface SubscribeClientTrackDataWebSocketEventDTO extends WebsocketSubscription {
98
+ event: WebSocketSubscriptionEvent.SUBSCRIBE_CLIENT_TRACK_DATA;
99
+ trackedClientId: ClientId;
100
+ }
101
+ export interface UnsubscribeClientTrackDataWebSocketEventDTO extends WebsocketSubscription {
102
+ event: WebSocketSubscriptionEvent.UNSUBSCRIBE_CLIENT_TRACK_DATA;
103
+ trackedClientId: ClientId;
104
+ }
105
+ export type WebSocketSubscribeEventDTO = SubscribeCodeRunStatusWebSocketEventDTO | SubscribeSubmissionRunStatusWebSocketEventDTO | SubscribeGetDataWebSocketEventDTO | SubscribeProblemCrawledWebSocketEventDTO | SubscribeSubmissionsCrawlWebSocketEventDTO | SubscribeContestChangesWebSocketEventDTO | SubscribeClientTrackWebSocketEventDTO | SubscribeUserNotificationWebsocketEventDTO | SubscribeClientTrackDataWebSocketEventDTO;
106
+ export type WebSocketUnsubscribeEventDTO = UnsubscribeCodeRunStatusWebSocketEventDTO | UnsubscribeSubmissionRunStatusWebSocketEventDTO | UnsubscribeGetDataWebSocketEventDTO | UnsubscribeProblemCrawledWebSocketEventDTO | UnsubscribeSubmissionsCrawlWebSocketEventDTO | UnsubscribeContestChangesWebSocketEventDTO | UnsubscribeClientTrackWebSocketEventDTO | UnsubscribeUserNotificationWebSocketEventDTO | UnsubscribeClientTrackDataWebSocketEventDTO;
99
107
  export interface WebSocketResponse {
100
108
  event: WebSocketResponseEvent;
101
109
  key: WebSocketResponseEventKey;
@@ -253,4 +261,12 @@ export interface UserNotificationContestClarificationWebSocketResponseEventDTO e
253
261
  };
254
262
  }
255
263
  export type WebSocketResponseEventDTO = PongWebSocketResponseEventDTO | CodeRunStatusWebSocketResponseEventDTO | SubmissionRunStatusWebSocketResponseEventDTO | UserMessageWebSocketResponseEventDTO | SendDataEcsTaskDefinitionListWebSocketResponseEventDTO | SendDataEcsTasksListWebSocketResponseEventDTO | SendDataEc2InstancesListWebSocketResponseEventDTO | SendDataSsmSessionsListWebSocketResponseEventDTO | ProblemCrawledWebSocketResponseEventDTO | SendDataChatCompletionsWebSocketResponseEventDTO | SubmissionsCrawlWebSocketResponseEventDTO | ContestChangesWebSocketResponseEventDTO | SendDataRunCommandWebSocketResponseEventDTO | SendDataClientTrackWebSocketResponseEventDTO | ClientTrackWebSocketResponseEventDTO | UserNotificationSubmissionWebSocketResponseEventDTO | UserNotificationContestClarificationWebSocketResponseEventDTO;
264
+ /**
265
+ * Message sent by the backend producers to the websocket SQS queue:
266
+ * the producer (trusted, with access to the DB) decides the Ably channels where the event is published.
267
+ */
268
+ export interface WebSocketChannelsMessageDTO {
269
+ channels: string[];
270
+ event: WebSocketResponseEventDTO;
271
+ }
256
272
  export {};
@@ -1,4 +1,4 @@
1
- import { ChatCompletionsWebSocketEventDTO, ClientTrackDeviceWebSocketEventDTO, ClientTrackLocationWebSocketEventDTO, ClientTrackScreenshotWebSocketEventDTO, ClientTrackWebSocketResponseEventDTO, CodeRunStatusWebSocketResponseEventDTO, ContestChangesWebSocketResponseEventDTO, PingWebSocketEventDTO, PongWebSocketResponseEventDTO, ProblemCrawledWebSocketResponseEventDTO, SendDataChatCompletionsWebSocketResponseEventDTO, SendDataClientTrackWebSocketResponseEventDTO, SendDataEc2InstancesListWebSocketResponseEventDTO, SendDataEcsTaskDefinitionListWebSocketResponseEventDTO, SendDataEcsTasksListWebSocketResponseEventDTO, SendDataRunCommandWebSocketResponseEventDTO, SendDataSsmSessionsListWebSocketResponseEventDTO, SendDataWebSocketResponseEventDTO, SubmissionRunStatusWebSocketResponseEventDTO, SubmissionsCrawlWebSocketResponseEventDTO, SubscribeClientTrackWebSocketEventDTO, SubscribeCodeRunStatusWebSocketEventDTO, SubscribeContestChangesWebSocketEventDTO, SubscribeGetDataWebSocketEventDTO, SubscribeProblemCrawledWebSocketEventDTO, SubscribeSubmissionRunStatusWebSocketEventDTO, SubscribeSubmissionsCrawlWebSocketEventDTO, SubscribeUserNotificationWebsocketEventDTO, UnsubscribeClientTrackWebSocketEventDTO, UnsubscribeCodeRunStatusWebSocketEventDTO, UnsubscribeContestChangesWebSocketEventDTO, UnsubscribeGetDataWebSocketEventDTO, UnsubscribeProblemCrawledWebSocketEventDTO, UnsubscribeSubmissionRunStatusWebSocketEventDTO, UnsubscribeSubmissionsCrawlWebSocketEventDTO, UnsubscribeUserNotificationWebSocketEventDTO, UserMessageWebSocketResponseEventDTO, UserNotificationContestClarificationWebSocketResponseEventDTO, UserNotificationSubmissionWebSocketResponseEventDTO, UserNotificationWebSocketResponseEventDTO, WebSocketMessageEventDTO, WebSocketResponseEventDTO, WebSocketSubscribeEventDTO, WebSocketUnsubscribeEventDTO } from '../dto';
1
+ import { ChatCompletionsWebSocketEventDTO, ClientTrackDeviceWebSocketEventDTO, ClientTrackLocationWebSocketEventDTO, ClientTrackScreenshotWebSocketEventDTO, ClientTrackWebSocketResponseEventDTO, CodeRunStatusWebSocketResponseEventDTO, ContestChangesWebSocketResponseEventDTO, PingWebSocketEventDTO, PongWebSocketResponseEventDTO, ProblemCrawledWebSocketResponseEventDTO, SendDataChatCompletionsWebSocketResponseEventDTO, SendDataClientTrackWebSocketResponseEventDTO, SendDataEc2InstancesListWebSocketResponseEventDTO, SendDataEcsTaskDefinitionListWebSocketResponseEventDTO, SendDataEcsTasksListWebSocketResponseEventDTO, SendDataRunCommandWebSocketResponseEventDTO, SendDataSsmSessionsListWebSocketResponseEventDTO, SendDataWebSocketResponseEventDTO, SubmissionRunStatusWebSocketResponseEventDTO, SubmissionsCrawlWebSocketResponseEventDTO, SubscribeClientTrackDataWebSocketEventDTO, SubscribeClientTrackWebSocketEventDTO, SubscribeCodeRunStatusWebSocketEventDTO, SubscribeContestChangesWebSocketEventDTO, SubscribeGetDataWebSocketEventDTO, SubscribeProblemCrawledWebSocketEventDTO, SubscribeSubmissionRunStatusWebSocketEventDTO, SubscribeSubmissionsCrawlWebSocketEventDTO, SubscribeUserNotificationWebsocketEventDTO, UnsubscribeClientTrackDataWebSocketEventDTO, UnsubscribeClientTrackWebSocketEventDTO, UnsubscribeCodeRunStatusWebSocketEventDTO, UnsubscribeContestChangesWebSocketEventDTO, UnsubscribeGetDataWebSocketEventDTO, UnsubscribeProblemCrawledWebSocketEventDTO, UnsubscribeSubmissionRunStatusWebSocketEventDTO, UnsubscribeSubmissionsCrawlWebSocketEventDTO, UnsubscribeUserNotificationWebSocketEventDTO, UserMessageWebSocketResponseEventDTO, UserNotificationContestClarificationWebSocketResponseEventDTO, UserNotificationSubmissionWebSocketResponseEventDTO, UserNotificationWebSocketResponseEventDTO, WebSocketChannelsMessageDTO, WebSocketMessageEventDTO, WebSocketResponseEventDTO, WebSocketSubscribeEventDTO, WebSocketUnsubscribeEventDTO } from '../dto';
2
2
  import { ClientId, WebSocketResponseEvent, WebSocketResponseEventKey } from '../types';
3
3
  export declare const isWebsocketSubscription: (event: any) => event is WebSocketSubscribeEventDTO | WebSocketUnsubscribeEventDTO | WebSocketMessageEventDTO;
4
4
  export declare const isPingWebSocketEventDTO: (event: any) => event is PingWebSocketEventDTO;
@@ -22,6 +22,8 @@ export declare const isSubscribeClientTrackWebSocketEventDTO: (event: any) => ev
22
22
  export declare const isUnsubscribeClientTrackWebSocketEventDTO: (event: any) => event is UnsubscribeClientTrackWebSocketEventDTO;
23
23
  export declare const isSubscribeUserNotificationWebSocketEventDTO: (event: any) => event is SubscribeUserNotificationWebsocketEventDTO;
24
24
  export declare const isUnsubscribeUserNotificationWebSocketEventDTO: (event: any) => event is UnsubscribeUserNotificationWebSocketEventDTO;
25
+ export declare const isSubscribeClientTrackDataWebSocketEventDTO: (event: any) => event is SubscribeClientTrackDataWebSocketEventDTO;
26
+ export declare const isUnsubscribeClientTrackDataWebSocketEventDTO: (event: any) => event is UnsubscribeClientTrackDataWebSocketEventDTO;
25
27
  export declare const isWebSocketResponseEventDTO: (event: any) => event is WebSocketResponseEventDTO;
26
28
  export declare const isPongWebSocketResponseEventDTO: (event: any) => event is PongWebSocketResponseEventDTO;
27
29
  export declare const isCodeRunStatusMessageWebSocketResponseEventDTO: (event: any) => event is CodeRunStatusWebSocketResponseEventDTO;
@@ -43,3 +45,20 @@ export declare const isUserNotificationWebSocketResponseEventDTO: (event: any) =
43
45
  export declare const isUserNotificationSubmissionWebSocketResponseEventDTO: (event: any) => event is UserNotificationSubmissionWebSocketResponseEventDTO;
44
46
  export declare const isUserNotificationContestClarificationWebSocketResponseEventDTO: (event: any) => event is UserNotificationContestClarificationWebSocketResponseEventDTO;
45
47
  export declare const getWebSocketResponseEventKey: (event: WebSocketResponseEvent, clientId: ClientId, id: string) => WebSocketResponseEventKey;
48
+ export declare const isWebSocketChannelsMessageDTO: (message: any) => message is WebSocketChannelsMessageDTO;
49
+ /**
50
+ * Key used by the client to dispatch a response received on a TOPIC channel to its subscribers.
51
+ * It is the same key that `getKeyWebSocketEventDTO` (base-ui) computes for the subscription.
52
+ * Returns null when the response is not addressed to this client.
53
+ */
54
+ export declare const getWebSocketResponseEventKeyOfResponse: (response: WebSocketResponseEventDTO, clientId: ClientId) => WebSocketResponseEventKey | null;
55
+ /**
56
+ * TOPIC channel that the client has to attach to receive the events of a subscription,
57
+ * or null when the events arrive by the private channels (session / user) the client is always attached to.
58
+ * Ably rejects the attach if the token has no capability for the channel.
59
+ */
60
+ export declare const getChannelOfWebSocketSubscribeEvent: (event: WebSocketSubscribeEventDTO) => string | null;
61
+ /**
62
+ * Contest whose role channels the client needs (the API grants them when the token is requested with this contest).
63
+ */
64
+ export declare const getContestKeyOfWebSocketSubscribeEvent: (event: WebSocketSubscribeEventDTO) => string | null;
@@ -22,7 +22,9 @@ export declare enum WebSocketSubscriptionEvent {
22
22
  SUBSCRIBE_CLIENT_TRACK = "SUBSCRIBE_CLIENT_TRACK",
23
23
  UNSUBSCRIBE_CLIENT_TRACK = "UNSUBSCRIBE_CLIENT_TRACK",
24
24
  SUBSCRIBE_USER_NOTIFICATION = "SUBSCRIBE_USER_NOTIFICATION",
25
- UNSUBSCRIBE_USER_NOTIFICATION = "UNSUBSCRIBE_USER_NOTIFICATION"
25
+ UNSUBSCRIBE_USER_NOTIFICATION = "UNSUBSCRIBE_USER_NOTIFICATION",
26
+ SUBSCRIBE_CLIENT_TRACK_DATA = "SUBSCRIBE_CLIENT_TRACK_DATA",
27
+ UNSUBSCRIBE_CLIENT_TRACK_DATA = "UNSUBSCRIBE_CLIENT_TRACK_DATA"
26
28
  }
27
29
  export declare enum WebSocketResponseEvent {
28
30
  PONG = "PONG",
@@ -47,3 +49,16 @@ export declare enum WebSocketResponseEvent {
47
49
  }
48
50
  export type ClientId = `${RecordId}|${string}`;
49
51
  export type WebSocketResponseEventKey = `${WebSocketResponseEvent}-${ClientId}-${string}`;
52
+ /**
53
+ * Roles of a contest, with the same names as the contest members in the DB.
54
+ * Each role has its own Ably channel: `contest:{contestKey}:{role}` (see `CHANNEL_CONTEST`).
55
+ * The inclusions follow `getContestAccessPermissions`:
56
+ * spectators ⊇ managers ⊇ administrators, spectators ⊇ participants, spectators ⊇ guests
57
+ */
58
+ export declare enum ContestChannelRole {
59
+ ADMINISTRATORS = "administrators",
60
+ MANAGERS = "managers",
61
+ PARTICIPANTS = "participants",
62
+ GUESTS = "guests",
63
+ SPECTATORS = "spectators"
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juki-team/commons",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "author": "juki-team",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,22 +17,29 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
- "repository": "https://github.com/juki-team/commons.git",
21
- "scripts": {
22
- "docs": "typedoc src/index.ts",
23
- "watch": "rollup -cw",
24
- "build": "rm -rf docs && rm -rf dist && rollup -c && yarn docs",
25
- "git:commit-push": "f() { param=${1}; message=${param:-chore}; echo ${message}; git add .; echo $message | git commit -F -; yarn publish --patch --no-git-tag-version; version=\"v$(node -p \"require('./package.json').version\")\"; git add .; echo $version | git commit -F -; git push origin main; echo $version | git tag -a $(echo $version) -F -; git push origin --tags; }; f",
26
- "git:push": "f() { yarn publish --patch --no-git-tag-version; version=\"v$(node -p \"require('./package.json').version\")\"; git add .; echo $version | git commit -F -; git push origin main; echo $version | git tag -a $(echo $version) -F -; git push origin --tags; }; f",
27
- "push-commit": "f() { yarn build && yarn git-push \"${1}\"; }; f",
28
- "push": "yarn build && yarn git:push"
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/juki-team/commons.git"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "registry": "https://registry.npmjs.org"
29
27
  },
30
28
  "devDependencies": {
31
- "@types/uuid": "^11.0.0",
32
29
  "prettier": "^3.8.1",
33
30
  "rollup": "^4.57.1",
34
31
  "rollup-plugin-typescript2": "^0.36.0",
35
32
  "typedoc": "^0.28.16",
36
- "typescript": "^5.9.3"
33
+ "typescript": "^6.0.3"
34
+ },
35
+ "dependencies": {
36
+ "uuid": "^13.0.0 || ^14.0.0"
37
+ },
38
+ "scripts": {
39
+ "docs": "typedoc src/index.ts",
40
+ "watch": "rollup -cw",
41
+ "build": "rm -rf docs && rm -rf dist && rollup -c && pnpm run docs",
42
+ "push-commit": "f() { git add -A && git commit -m \"${1:-chore}\" && pnpm push; }; f",
43
+ "push": "f() { pnpm version patch --no-git-tag-version --no-git-checks && pnpm build && pnpm publish --tag release-0.1 --no-git-checks && version=\"v$(node -p \"require('./package.json').version\")\" && git add -A && git commit -m $version && git tag -a $version -m $version && git push origin v0.1.x --follow-tags; }; f"
37
44
  }
38
- }
45
+ }