-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 034873e
Showing
11 changed files
with
393 additions
and
0 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,175 @@ | ||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore | ||
|
||
# Logs | ||
|
||
logs | ||
_.log | ||
npm-debug.log_ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Caches | ||
|
||
.cache | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
|
||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
||
# Runtime data | ||
|
||
pids | ||
_.pid | ||
_.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
|
||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
|
||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
|
||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
|
||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
|
||
bower_components | ||
|
||
# node-waf configuration | ||
|
||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
||
build/Release | ||
|
||
# Dependency directories | ||
|
||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
|
||
web_modules/ | ||
|
||
# TypeScript cache | ||
|
||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
|
||
.npm | ||
|
||
# Optional eslint cache | ||
|
||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
|
||
.stylelintcache | ||
|
||
# Microbundle cache | ||
|
||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
|
||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
|
||
*.tgz | ||
|
||
# Yarn Integrity file | ||
|
||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
|
||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
|
||
.parcel-cache | ||
|
||
# Next.js build output | ||
|
||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
|
||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
|
||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
|
||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
|
||
# public | ||
|
||
# vuepress build output | ||
|
||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
|
||
.temp | ||
|
||
# Docusaurus cache and generated files | ||
|
||
.docusaurus | ||
|
||
# Serverless directories | ||
|
||
.serverless/ | ||
|
||
# FuseBox cache | ||
|
||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
|
||
.dynamodb/ | ||
|
||
# TernJS port file | ||
|
||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
|
||
.vscode-test | ||
|
||
# yarn v2 | ||
|
||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# IntelliJ based IDEs | ||
.idea | ||
|
||
# Finder (MacOS) folder config | ||
.DS_Store |
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,30 @@ | ||
# @session.js/errors | ||
|
||
Session.js error classes. This module can be used to check instance of thrown errors in Session.js. All errors extend from `SessionJsError` class which itself extends from generic Error class. | ||
|
||
```ts | ||
import { SessionRuntimeError, SessionJsError } from '@session.js/error' | ||
|
||
try { | ||
// something throws | ||
} catch(e) { | ||
if(e instanceof SessionRuntimeError) { | ||
console.error('Session.js runtime error handled') | ||
} else { | ||
if(e instanceof SessionJsError) { | ||
console.error('It\'s not Session.js runtime error... but at least we know it\'s Session\.js error') | ||
} else { | ||
console.error('No idea what is this error') | ||
throw e | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Made for session.js | ||
|
||
Use Session messenger programmatically with [Session.js](https://github.com/sessionjs/client): Session bots, custom Session clients, and more. | ||
|
||
## Donate | ||
|
||
[hloth.dev/donate](https://hloth.dev/donate) |
Binary file not shown.
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,31 @@ | ||
{ | ||
"name": "@session.js/errors", | ||
"version": "1.0.0", | ||
"module": "src/index.ts", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"author": "Viktor Shchelochkov <[email protected]> (https://hloth.dev)", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sessionjs/errors.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sessionjs/errors/issues" | ||
}, | ||
"homepage": "https://github.com/sessionjs/errors#readme", | ||
"description": "Session.js errors classes", | ||
"type": "module", | ||
"files": [ | ||
"dist/**.js", | ||
"dist/**.d.ts" | ||
], | ||
"scripts": { | ||
"build": "tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"tsc-alias": "^1.8.10" | ||
} | ||
} |
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,20 @@ | ||
import { SessionJsError } from "./index" | ||
|
||
export enum SessionCryptoErrorCode { | ||
MessageEncryptionFailed = 'message_encryption_failed', | ||
MessageDecryptionFailed = 'message_decryption_failed', | ||
MessageVerificationFailed = 'message_verification_failed', | ||
} | ||
|
||
/** Generic error for cases where developer does something incorrectly */ | ||
export class SessionCryptoError extends SessionJsError { | ||
code: SessionCryptoErrorCode | ||
|
||
constructor({ code, message }: { | ||
code: SessionCryptoErrorCode, | ||
message: string | ||
}) { | ||
super(message) | ||
this.code = code | ||
} | ||
} |
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,23 @@ | ||
import { SessionJsError } from "./index" | ||
|
||
export enum SessionFetchErrorCode { | ||
RetryWithOtherNode421Error = 'retry_with_other_node_421_error', | ||
NoSnodesAvailable = 'no_snodes_available', | ||
NoSwarmsAvailable = 'no_swarms_available', | ||
FetchFailed = 'fetch_failed', | ||
InvalidResponse = 'invalid_response', | ||
PollingFailed = 'polling_failed', | ||
} | ||
|
||
/** Generic error for cases where developer does something incorrectly */ | ||
export class SessionFetchError extends SessionJsError { | ||
code: SessionFetchErrorCode | ||
|
||
constructor({ code, message }: { | ||
code: SessionFetchErrorCode, | ||
message: string | ||
}) { | ||
super(message) | ||
this.code = code | ||
} | ||
} |
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,10 @@ | ||
export { SessionValidationError, SessionValidationErrorCode } from './validation' | ||
export { SessionCryptoError, SessionCryptoErrorCode } from './crypto' | ||
export { SessionRuntimeError, SessionRuntimeErrorCode } from './runtime' | ||
export { SessionFetchError, SessionFetchErrorCode } from './fetch' | ||
|
||
export class SessionJsError extends Error { | ||
constructor(message: string) { | ||
super(message) | ||
} | ||
} |
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,23 @@ | ||
import { SessionJsError } from "./index" | ||
|
||
export enum SessionRuntimeErrorCode { | ||
EmptyUser = 'empty_user', | ||
Generic = 'generic', | ||
NoSwarmsAvailable = 'no_swarms_available', | ||
MultipleInstancesNotAllowed = 'multiple_instances_not_allowed', | ||
NoInstancePolling = 'no_instance_polling', | ||
InstanceAlreadyAuthorized = 'instance_already_authorized', | ||
} | ||
|
||
/** Generic error for cases where developer does something incorrectly */ | ||
export class SessionRuntimeError extends SessionJsError { | ||
code: SessionRuntimeErrorCode | ||
|
||
constructor({ code, message }: { | ||
code: SessionRuntimeErrorCode, | ||
message: string | ||
}) { | ||
super(message) | ||
this.code = code | ||
} | ||
} |
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,26 @@ | ||
import { SessionJsError } from "./index" | ||
|
||
export enum SessionValidationErrorCode { | ||
InvalidMnemonic = 'invalid_mnemonic', | ||
InvalidDisplayName = 'invalid_display_name', | ||
InvalidSessionID = 'invalid_session_id', | ||
InvalidPoller = 'invalid_poller', | ||
InvalidNamespaces = 'invalid_namespaces', | ||
NotOurPubkeyNotLegacyClosedGroup = 'not_our_pubkey_not_legacy_closed_group', | ||
NotZeroNamespaceNotLegacyClosedGroup = 'not_zero_namespace_not_legacy_closed_group', | ||
UnsupportedFeature = 'unsupported_feature', | ||
InvalidMessage = 'invalid_message', | ||
} | ||
|
||
/** Validation error, indicating that the developer provided invalid input */ | ||
export class SessionValidationError extends SessionJsError { | ||
code: SessionValidationErrorCode | ||
|
||
constructor({ code, message }: { | ||
code: SessionValidationErrorCode, | ||
message: string | ||
}) { | ||
super(message) | ||
this.code = code | ||
} | ||
} |
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,28 @@ | ||
{ | ||
"compilerOptions": { | ||
// Enable latest features | ||
"lib": ["ESNext", "DOM"], | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleDetection": "force", | ||
"jsx": "react-jsx", | ||
"allowJs": true, | ||
"declaration": true, | ||
|
||
// Bundler mode | ||
"moduleResolution": "bundler", | ||
"verbatimModuleSyntax": true, | ||
|
||
// Best practices | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"noFallthroughCasesInSwitch": true, | ||
|
||
// Some stricter flags (disabled by default) | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"noPropertyAccessFromIndexSignature": false, | ||
"outDir": "dist", | ||
}, | ||
"include": ["src/index.ts"] | ||
} |
Oops, something went wrong.