Skip to content
This repository has been archived by the owner on Dec 29, 2021. It is now read-only.

Commit

Permalink
Release v2.0.0 (#17)
Browse files Browse the repository at this point in the history
* Remove non-project files from <.gitignore>

* Remove the "official" word because it's useless

* Fix docs

* Migrate to Omni Chat Backend 0.23.0

* Add enums

* Prep for release
  • Loading branch information
Neel Kamath committed Jul 5, 2021
1 parent 2465e88 commit 435999e
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
node-version: 14
- run: npm i
- run: npm run doc
- run: npm run doc:build
- uses: actions/upload-artifact@v2
with:
name: docs
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.idea/
dist/
docs/
node_modules/
.DS_Store
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0](https://github.com/neelkamath/omni-chat-js/releases/tag/v2.0.0) - 2021-07-05

### Added

- `type GroupChatPublicity`
- `class MustBeAdminError`

### Changed

- Throw `class InvalidPicError`, `class InvalidAudioError`, `class InvalidVideoError`, and `class InvalidDocError` when the media is 3 MiB instead of 5 MiB.
- Limit `type Pic`, `type Audio`, `type Video`, and `type Doc` to 3 MiB instead of 5 MiB.
- Throw a `class MustBeAdminError` instead of a `class UnauthorizedError` when `postPicMessage()`, `postAudioMessage()`, `postVideoMessage()`, and `postDocMessage()` fail because the user attempted to send a message in a broadcast chat they're not an admin of.

## [1.0.0](https://github.com/neelkamath/omni-chat-js/releases/tag/v1.0.0) - 2021-06-03

### Changed
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ If you're forking the repo to develop the project as your own instead of just to
- Test: `npm t`
- Check for lint issues: `npm run lint`
- Check for, and fix lint issues: `npm run fix`
- Generate docs to `docs/`: `npm run doc`
- Generate docs to `docs/`:
- Production: `npm run doc:build`
- Development (watches for changes): `npm run doc:watch`

### Conventions

Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![npm (scoped)](https://img.shields.io/npm/v/@neelkamath/omni-chat)](https://www.npmjs.com/package/@neelkamath/omni-chat)

Official [Omni Chat API](https://github.com/neelkamath/omni-chat-backend) JavaScript wrapper library.
[Omni Chat API](https://github.com/neelkamath/omni-chat-backend) JavaScript wrapper library.

- Platforms: Browsers supporting ES6 or higher
- Module systems: ECMAScript Modules
Expand All @@ -13,13 +13,14 @@ Official [Omni Chat API](https://github.com/neelkamath/omni-chat-backend) JavaSc

This table shows which versions of Omni Chat JS support which versions of Omni Chat Backend:

| Omni Chat JS | Omni Chat Backend |
| :--------------: | :---------------: |
| 0.12.0 or higher | 0.19.0 or higher |
| 0.11.0 | 0.18.0 |
| 0.8.0 - 0.10.0 | 0.17.0 |
| 0.5.0 - 0.7.0 | 0.16.0 |
| 0.1.0 - 0.4.0 | 0.15.0 |
| Omni Chat JS | Omni Chat Backend |
| :-------------: | :---------------: |
| 2.0.0 or higher | 0.23.0 or higher |
| 0.12.0 - 1.0.0 | 0.19.0 - 0.22.0 |
| 0.11.0 | 0.18.0 |
| 0.8.0 - 0.10.0 | 0.17.0 |
| 0.5.0 - 0.7.0 | 0.16.0 |
| 0.1.0 - 0.4.0 | 0.15.0 |

```
npm i @neelkamath/omni-chat
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@neelkamath/omni-chat",
"version": "1.0.0",
"description": "Official Omni Chat API wrapper library",
"version": "2.0.0",
"description": "Omni Chat API wrapper library",
"scripts": {
"test": "jest",
"doc": "typedoc src/index.ts --includeVersion --readme none",
"doc:build": "npm run doc",
"doc:watch": "npm run doc -- --watch",
"prepare": "tsc",
"lint": "eslint . && prettier -c . && tsc --noEmit",
"fix": "eslint --fix . && prettier -w . && tsc --noEmit"
Expand Down
9 changes: 9 additions & 0 deletions src/graphql-api/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* - `'NOT_INVITABLE'`: Users cannot join the chat via an invite code.
* - `'INVITABLE'`: Users can join the chat via an invite code.
* - `'PUBLIC'`: People can search for, and view public chats without an account. Invite codes are permanently turned on.
* Anyone with an account can join a public chat. A frontend UI may allow for a search engine to index the chat should
* the administrator allow for it. A chat must be made public when it's being created because chats can't switch between
* being public after they've been created.
*/
export type GroupChatPublicity = 'NOT_INVITABLE' | 'INVITABLE' | 'PUBLIC';
1 change: 1 addition & 0 deletions src/graphql-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './operator';
export * from './scalars';
export * from './enums';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Official [Omni Chat API](https://github.com/neelkamath/omni-chat-backend) JavaScript wrapper library.
* [Omni Chat API](https://github.com/neelkamath/omni-chat-backend) JavaScript wrapper library.
*
* The Omni Chat API consists of a REST API, and a GraphQL API.
*
Expand Down
11 changes: 7 additions & 4 deletions src/rest-api/errors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/** Pic wasn't a PNG or JPEG not exceeding 5 MiB. */
/** Pic wasn't a PNG or JPEG not exceeding 3 MiB. */
export class InvalidPicError extends Error {}

/** Audio wasn't an MP3/MP4 not exceeding 5 MiB. */
/** Audio wasn't an MP3/MP4 not exceeding 3 MiB. */
export class InvalidAudioError extends Error {}

/** Video wasn't an MP4 not exceeding 5 MiB. */
/** Video wasn't an MP4 not exceeding 3 MiB. */
export class InvalidVideoError extends Error {}

/** Doc exceeded 5 MiB. */
/** Doc exceeded 3 MiB. */
export class InvalidDocError extends Error {}

export class NonexistentUserIdError extends Error {}
Expand All @@ -19,3 +19,6 @@ export class UserNotInChatError extends Error {}
export class InvalidContextMessageError extends Error {}

export class MessageTextScalarError extends Error {}

/** The user attempted to create a message in a broadcast chat but was disallowed because they're not an admin. */
export class MustBeAdminError extends Error {}
8 changes: 4 additions & 4 deletions src/rest-api/models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type PicType = 'ORIGINAL' | 'THUMBNAIL';

/** A PNG or JPEG image not exceeding 5 MiB. */
/** A PNG or JPEG image not exceeding 3 MiB. */
export type Pic = Blob;

/**
Expand All @@ -9,11 +9,11 @@ export type Pic = Blob;
*/
export type ContextMessageId = number;

/** An MP3/MP4 audio not exceeding 5 MiB. */
/** An MP3/MP4 audio not exceeding 3 MiB. */
export type Audio = Blob;

/** An MP4 video not exceeding 5 MiB. */
/** An MP4 video not exceeding 3 MiB. */
export type Video = Blob;

/** A doc not exceeding 5 MiB. */
/** A doc not exceeding 3 MiB. */
export type Doc = Blob;
15 changes: 9 additions & 6 deletions src/rest-api/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
InvalidContextMessageError,
InvalidPicError,
MessageTextScalarError,
MustBeAdminError,
NonexistentChatError,
NonexistentUserIdError,
UserNotInChatError,
Expand All @@ -13,7 +14,7 @@ import { HttpApiConfig } from '../config';
import { MessageText } from '../graphql-api';

/**
* @return `Blob` if the user has a profile pic, and `null` if they don't.
* @return {Pic | null} if the user has a profile pic, and `null` if they don't.
* @throws {@link NonexistentUserIdError}
* @throws {@link ConnectionError}
* @throws {@link InternalServerError}
Expand Down Expand Up @@ -76,7 +77,7 @@ export async function patchProfilePic(
/**
* Retrieves the group chat's pic. An access token needn't be sent if the chat is public. Otherwise, the user must be
* a participant to view the pic.
* @return `Pic` if the chat has a pic, and `null` otherwise.
* @return {Pic | null} if the chat has a pic, and `null` otherwise.
* @throws {@link NonexistentChatError}
* @throws {@link ConnectionError}
* @throws {@link InternalServerError}
Expand Down Expand Up @@ -161,7 +162,7 @@ export async function getPicMessage(

/**
*
* Creates a pic message. If the chat is a broadcast group, the user must be an admin.
* Creates a pic message.
* @throws {@link UserNotInChatError}
* @throws {@link InvalidPicError}
* @throws {@link InvalidContextMessageError}
Expand Down Expand Up @@ -203,6 +204,8 @@ export async function postPicMessage(
throw new InvalidContextMessageError();
case 'INVALID_CAPTION':
throw new MessageTextScalarError();
case 'MUST_BE_ADMIN':
throw new MustBeAdminError();
}
break;
}
Expand All @@ -228,7 +231,7 @@ export async function getAudioMessage(
}

/**
* Creates an audio message. If the chat is a broadcast group, the user must be an admin.
* Creates an audio message.
* @throws {@link InternalServerError}
* @throws {@link UserNotInChatError}
* @throws {@link InvalidAudioError}
Expand Down Expand Up @@ -261,7 +264,7 @@ export async function getVideoMessage(
}

/**
* Creates a video message. If the chat is a broadcast group, the user must be an admin.
* Creates a video message.
* @throws {@link InternalServerError}
* @throws {@link UserNotInChatError}
* @throws {@link InvalidVideoError}
Expand Down Expand Up @@ -294,7 +297,7 @@ export async function getDocMessage(
}

/**
* Creates a doc message. If the chat is a broadcast group, the user must be an admin.
* Creates a doc message.
* @throws {@link InternalServerError}
* @throws {@link UserNotInChatError}
* @throws {@link InvalidDocError}
Expand Down
5 changes: 4 additions & 1 deletion src/rest-api/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
InvalidContextMessageError,
InvalidDocError,
InvalidVideoError,
MustBeAdminError,
UserNotInChatError,
} from './errors';
import { HttpApiConfig } from '../config';
Expand Down Expand Up @@ -86,7 +87,7 @@ export async function postMediaMessage(
}

interface InvalidMessage {
readonly reason: 'USER_NOT_IN_CHAT' | 'INVALID_FILE' | 'INVALID_CONTEXT_MESSAGE';
readonly reason: 'USER_NOT_IN_CHAT' | 'INVALID_FILE' | 'INVALID_CONTEXT_MESSAGE' | 'MUST_BE_ADMIN';
}

function readInvalidMessageError(message: InvalidMessage, type: MediaType): Error {
Expand All @@ -95,6 +96,8 @@ function readInvalidMessageError(message: InvalidMessage, type: MediaType): Erro
return new UserNotInChatError();
case 'INVALID_CONTEXT_MESSAGE':
return new InvalidContextMessageError();
case 'MUST_BE_ADMIN':
return new MustBeAdminError();
case 'INVALID_FILE':
switch (type) {
case 'audio':
Expand Down

0 comments on commit 435999e

Please sign in to comment.