@session.js/types 1.0.11 → 1.0.13

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Viktor Shchelochkov <hi@hloth.dev> (https://hloth.dev)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,23 +8,23 @@ To build your own Storage adapter, use:
8
8
  import type { Storage } from '@session.js/types'
9
9
 
10
10
  export class MyInMemoryStorage implements Storage {
11
- storage: Map<string, string> = new Map()
11
+ storage: Map<string, string> = new Map()
12
12
 
13
- get(key: string) {
14
- return this.storage.get(key) ?? null
15
- }
13
+ get(key: string) {
14
+ return this.storage.get(key) ?? null
15
+ }
16
16
 
17
- set(key: string, value: string) {
18
- this.storage.set(key, value)
19
- }
17
+ set(key: string, value: string) {
18
+ this.storage.set(key, value)
19
+ }
20
20
 
21
- delete(key: string) {
22
- this.storage.delete(key)
23
- }
21
+ delete(key: string) {
22
+ this.storage.delete(key)
23
+ }
24
24
 
25
- has(key: string) {
26
- return this.storage.has(key)
27
- }
25
+ has(key: string) {
26
+ return this.storage.has(key)
27
+ }
28
28
  }
29
29
  ```
30
30
 
@@ -33,42 +33,46 @@ To build your own Network connecter, use:
33
33
  ```ts
34
34
  import type { Network } from '@session.js/types'
35
35
  import {
36
- RequestType,
37
- type RequestGetSwarmsBody,
38
- type RequestPollBody,
39
- type RequestStoreBody,
40
- type RequestUploadAttachment
36
+ RequestType,
37
+ type RequestGetSwarmsBody,
38
+ type RequestPollBody,
39
+ type RequestStoreBody,
40
+ type RequestUploadAttachment
41
41
  } from '@session.js/types/network/request'
42
42
 
43
43
  export class MyNetwork implements Network {
44
- onRequest(type: RequestType, body: object): Promise<object> {
45
- switch(type) {
46
- case RequestType.Store:
47
- return // typeof ResponseStore
44
+ onRequest(type: RequestType, body: object): Promise<object> {
45
+ switch(type) {
46
+ case RequestType.Store:
47
+ return // typeof ResponseStore
48
48
 
49
- case RequestType.GetSnodes:
50
- return // typeof ResponseGetSnodes
49
+ case RequestType.GetSnodes:
50
+ return // typeof ResponseGetSnodes
51
51
 
52
- case RequestType.GetSwarms:
53
- return // typeof ResponseGetSwarms
52
+ case RequestType.GetSwarms:
53
+ return // typeof ResponseGetSwarms
54
54
 
55
- case RequestType.Poll:
56
- return // typeof ResponsePoll
55
+ case RequestType.Poll:
56
+ return // typeof ResponsePoll
57
57
 
58
- case RequestType.UploadAttachment:
59
- return // typeof ResponseUploadAttachment
58
+ case RequestType.UploadAttachment:
59
+ return // typeof ResponseUploadAttachment
60
60
 
61
- default:
62
- throw new Error('Invalid request type')
63
- }
64
- }
61
+ default:
62
+ throw new Error('Invalid request type')
63
+ }
64
+ }
65
65
  }
66
66
  ```
67
67
 
68
- ## Made for session.js
68
+ ## Made for Session.js
69
69
 
70
- Use Session messenger programmatically with [Session.js](https://github.com/sessionjs/client): Session bots, custom Session clients, and more.
70
+ Use Session messenger programmatically with [Session.js](https://git.hloth.dev/session.js/client): Session bots, custom Session clients, and more.
71
71
 
72
72
  ## Donate
73
73
 
74
- [hloth.dev/donate](https://hloth.dev/donate)
74
+ [hloth.dev/donate](https://hloth.dev/donate) · Tor: [hlothdevzkti6suoksy7lcy7hmpxnr3msu5waokzaslsi2mnx5ouu4qd.onion/donate](http://hlothdevzkti6suoksy7lcy7hmpxnr3msu5waokzaslsi2mnx5ouu4qd.onion/donate)
75
+
76
+ ## License
77
+
78
+ [MIT](./LICENSE)
@@ -1 +1 @@
1
- export const DisappearingMessageMode = ['unknown', 'deleteAfterRead', 'deleteAfterSend'];
1
+ export const DisappearingMessageMode = ["unknown", "deleteAfterRead", "deleteAfterSend"];
@@ -1,5 +1,5 @@
1
- import type { SignalService } from './signal-bindings/index.js';
2
- export interface EnvelopePlus extends Omit<SignalService.Envelope, 'toJSON'> {
1
+ import type { SignalService } from "./signal-bindings/index.js";
2
+ export interface EnvelopePlus extends Omit<SignalService.Envelope, "toJSON"> {
3
3
  senderIdentity: string;
4
4
  receivedAt: number;
5
5
  id: string;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { SnodeNamespaces } from './namespaces.js';
2
- export type { Network } from './network/index.js';
3
- export type { Storage } from './storage/index.js';
1
+ export { SnodeNamespaces } from "./namespaces.js";
2
+ export type { Network } from "./network/index.js";
3
+ export type { Storage } from "./storage/index.js";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { SnodeNamespaces } from './namespaces.js';
1
+ export { SnodeNamespaces } from "./namespaces.js";
@@ -1,4 +1,4 @@
1
- import type { PickEnum } from './enums.js';
1
+ import type { PickEnum } from "./enums.js";
2
2
  export declare enum SnodeNamespaces {
3
3
  /**
4
4
  * This is the namespace anyone can deposit a message for us
@@ -1,6 +1,4 @@
1
- // CREDIT: OXEN, Session-Desktop
2
- // github.com/oxen-io/session-desktop
3
- import _ from 'lodash';
1
+ import { orderBy, last } from "lodash";
4
2
  export var SnodeNamespaces;
5
3
  (function (SnodeNamespaces) {
6
4
  /**
@@ -73,23 +71,23 @@ function namespacePriority(namespace) {
73
71
  }
74
72
  function maxSizeMap(namespaces) {
75
73
  let lastSplit = 1;
76
- const withPriorities = namespaces.map(namespace => {
74
+ const withPriorities = namespaces.map((namespace) => {
77
75
  return { namespace, priority: namespacePriority(namespace) };
78
76
  });
79
77
  const groupedByPriorities = [];
80
- withPriorities.forEach(item => {
81
- if (!groupedByPriorities.find(p => p.priority === item.priority)) {
78
+ withPriorities.forEach((item) => {
79
+ if (!groupedByPriorities.find((p) => p.priority === item.priority)) {
82
80
  groupedByPriorities.push({ priority: item.priority, namespaces: [] });
83
81
  }
84
- groupedByPriorities.find(p => p.priority === item.priority)?.namespaces.push(item.namespace);
82
+ groupedByPriorities.find((p) => p.priority === item.priority)?.namespaces.push(item.namespace);
85
83
  });
86
- const sortedDescPriorities = _.orderBy(groupedByPriorities, ['priority'], ['desc']);
87
- const lowestPriority = _.last(sortedDescPriorities)?.priority || 1;
88
- const sizeMap = sortedDescPriorities.flatMap(m => {
84
+ const sortedDescPriorities = orderBy(groupedByPriorities, ["priority"], ["desc"]);
85
+ const lowestPriority = last(sortedDescPriorities)?.priority || 1;
86
+ const sizeMap = sortedDescPriorities.flatMap((m) => {
89
87
  const paddingForLowerPriority = m.priority === lowestPriority ? 0 : 1;
90
88
  const splitsForPriority = paddingForLowerPriority + m.namespaces.length;
91
89
  lastSplit *= splitsForPriority;
92
- return m.namespaces.map(namespace => ({ namespace, maxSize: -lastSplit }));
90
+ return m.namespaces.map((namespace) => ({ namespace, maxSize: -lastSplit }));
93
91
  });
94
92
  return sizeMap;
95
93
  }
@@ -1,4 +1,4 @@
1
- import type { RequestType } from './request.js';
1
+ import type { RequestType } from "./request.js";
2
2
  export interface Network {
3
3
  onRequest(type: RequestType, body: unknown): Promise<unknown>;
4
4
  }
@@ -1,6 +1,6 @@
1
- import type { Snode } from '../snode.js';
2
- import type { RequestNamespace } from '../snode-retrieve.js';
3
- import type { Swarm } from '../swarm.js';
1
+ import type { Snode } from "../snode.js";
2
+ import type { RequestNamespace } from "../snode-retrieve.js";
3
+ import type { Swarm } from "../swarm.js";
4
4
  export declare enum RequestType {
5
5
  Store = "/store",
6
6
  GetSnodes = "/get_snodes",
@@ -28,7 +28,7 @@ export type RequestPollBody = {
28
28
  namespaces: RequestNamespace[];
29
29
  };
30
30
  export type RequestUploadAttachment = {
31
- data: ArrayBuffer;
31
+ data: Uint8Array;
32
32
  };
33
33
  export type RequestDownloadAttachment = {
34
34
  id: string;
@@ -44,6 +44,6 @@ export type RequestSogs = {
44
44
  host: string;
45
45
  endpoint: string;
46
46
  method: string;
47
- body: string | ArrayBuffer | null;
47
+ body: string | Uint8Array | null;
48
48
  headers: Record<string, string>;
49
49
  };
@@ -1,7 +1,7 @@
1
- import type { SnodeNamespaces } from '../namespaces.js';
2
- import type { Snode } from '../snode.js';
3
- import type { RetrieveMessageItem } from '../snode-retrieve.js';
4
- import type { Swarm } from '../swarm.js';
1
+ import type { SnodeNamespaces } from "../namespaces.js";
2
+ import type { Snode } from "../snode.js";
3
+ import type { RetrieveMessageItem } from "../snode-retrieve.js";
4
+ import type { Swarm } from "../swarm.js";
5
5
  export type ResponseStore = {
6
6
  hash: string;
7
7
  };
@@ -1,4 +1,4 @@
1
- import _ from 'lodash';
1
+ import { isNil } from "lodash";
2
2
  /**
3
3
  * This function is used to check that an optional property on a Protobuf object is not undefined or using a type-specific default value.
4
4
  * https://protobuf.dev/programming-guides/proto/#optional
@@ -8,7 +8,7 @@ import _ from 'lodash';
8
8
  * @returns true if the property is defined or false if undefined or using a type-specific default value
9
9
  */
10
10
  function hasDefinedProperty(object, property) {
11
- return !_.isNil(object) && Object.prototype.hasOwnProperty.call(object, property) !== false;
11
+ return !isNil(object) && Object.prototype.hasOwnProperty.call(object, property) !== false;
12
12
  }
13
13
  export const ProtobufUtils = {
14
14
  hasDefinedProperty,
@@ -1,4 +1,4 @@
1
- import type { SnodeNamespaces } from './namespaces.js';
1
+ import type { SnodeNamespaces } from "./namespaces.js";
2
2
  export type RetrieveMessageItem = {
3
3
  hash: string;
4
4
  expiration: number;
@@ -18,7 +18,7 @@ export type RetrieveRequestResult = {
18
18
  };
19
19
  export type RetrieveMessagesResultsBatched = Array<RetrieveRequestResult>;
20
20
  export type RequestNamespace = {
21
- namespace: SnodeNamespaces | 'all';
21
+ namespace: SnodeNamespaces | "all";
22
22
  pubkey: string;
23
23
  isOurPubkey: boolean;
24
24
  signature: {
package/package.json CHANGED
@@ -1,99 +1,108 @@
1
1
  {
2
- "name": "@session.js/types",
3
- "version": "1.0.11",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "author": "Viktor Shchelochkov <hi@hloth.dev> (https://hloth.dev)",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/sessionjs/types.git"
10
- },
11
- "bugs": {
12
- "url": "https://github.com/sessionjs/types/issues"
13
- },
14
- "homepage": "https://github.com/sessionjs/types#readme",
15
- "description": "A special package that holds TypeScript definitions and enums shared internally and for developing your own @session.js/client modular parts.",
16
- "type": "module",
17
- "files": [
18
- "dist/**/*.js",
19
- "dist/**/*.d.ts"
20
- ],
21
- "exports": {
22
- ".": {
23
- "import": "./dist/index.js",
24
- "types": "./dist/index.d.ts"
25
- },
26
- "./network": {
27
- "import": "./dist/network/index.js",
28
- "types": "./dist/network/index.d.ts"
29
- },
30
- "./network/request": {
31
- "import": "./dist/network/request.js",
32
- "types": "./dist/network/request.d.ts"
33
- },
34
- "./network/response": {
35
- "import": "./dist/network/response.js",
36
- "types": "./dist/network/response.d.ts"
37
- },
38
- "./storage": {
39
- "import": "./dist/storage/index.js",
40
- "types": "./dist/storage/index.d.ts"
41
- },
42
- "./signal-bindings": {
43
- "import": "./dist/signal-bindings/index.js",
44
- "types": "./dist/signal-bindings/index.d.ts"
45
- },
46
- "./disappearing-message": {
47
- "import": "./dist/disappearing-message.js",
48
- "types": "./dist/disappearing-message.d.ts"
49
- },
50
- "./enums": {
51
- "import": "./dist/enums.js",
52
- "types": "./dist/enums.d.ts"
53
- },
54
- "./envelope": {
55
- "import": "./dist/envelope.js",
56
- "types": "./dist/envelope.d.ts"
57
- },
58
- "./namespaces": {
59
- "import": "./dist/namespaces.js",
60
- "types": "./dist/namespaces.d.ts"
61
- },
62
- "./pubkey": {
63
- "import": "./dist/pubkey.js",
64
- "types": "./dist/pubkey.d.ts"
65
- },
66
- "./snode-retrieve": {
67
- "import": "./dist/snode-retrieve.js",
68
- "types": "./dist/snode-retrieve.d.ts"
69
- },
70
- "./snode-signature-result": {
71
- "import": "./dist/snode-signature-result.js",
72
- "types": "./dist/snode-signature-result.d.ts"
73
- },
74
- "./snode": {
75
- "import": "./dist/snode.js",
76
- "types": "./dist/snode.d.ts"
77
- },
78
- "./swarm": {
79
- "import": "./dist/swarm.js",
80
- "types": "./dist/swarm.d.ts"
81
- }
82
- },
83
- "scripts": {
84
- "build": "rm -rf dist && tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && cp src/signal-bindings/compiled.js dist/signal-bindings/compiled.js && cp src/signal-bindings/compiled.d.ts dist/signal-bindings/compiled.d.ts",
85
- "protobuf": "pbjs --target static-module --wrap es6 --out src/signal-bindings/compiled.js src/signal-bindings/signalservice.proto && pbts --out src/signal-bindings/compiled.d.ts src/signal-bindings/compiled.js --force-long"
86
- },
87
- "peerDependencies": {
88
- "typescript": "^5.0.0"
89
- },
90
- "dependencies": {
91
- "lodash": "^4.17.21",
92
- "protobufjs": "^7.3.2"
93
- },
94
- "devDependencies": {
95
- "@types/lodash": "^4.17.7",
96
- "protobufjs-cli": "^1.1.2",
97
- "tsc-alias": "^1.8.10"
98
- }
2
+ "name": "@session.js/types",
3
+ "version": "1.0.13",
4
+ "description": "A special package that holds TypeScript definitions and enums shared internally and for developing your own @session.js/client modular parts.",
5
+ "homepage": "https://git.hloth.dev/session.js/types#readme",
6
+ "bugs": {
7
+ "url": "https://git.hloth.dev/session.js/types/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://git.hloth.dev/session.js/types.git"
12
+ },
13
+ "funding": "https://hloth.dev/donate",
14
+ "license": "MIT",
15
+ "author": "Viktor Shchelochkov <hi@hloth.dev> (https://hloth.dev)",
16
+ "type": "module",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ },
22
+ "./network": {
23
+ "import": "./dist/network/index.js",
24
+ "types": "./dist/network/index.d.ts"
25
+ },
26
+ "./network/request": {
27
+ "import": "./dist/network/request.js",
28
+ "types": "./dist/network/request.d.ts"
29
+ },
30
+ "./network/response": {
31
+ "import": "./dist/network/response.js",
32
+ "types": "./dist/network/response.d.ts"
33
+ },
34
+ "./storage": {
35
+ "import": "./dist/storage/index.js",
36
+ "types": "./dist/storage/index.d.ts"
37
+ },
38
+ "./signal-bindings": {
39
+ "import": "./dist/signal-bindings/index.js",
40
+ "types": "./dist/signal-bindings/index.d.ts"
41
+ },
42
+ "./disappearing-message": {
43
+ "import": "./dist/disappearing-message.js",
44
+ "types": "./dist/disappearing-message.d.ts"
45
+ },
46
+ "./enums": {
47
+ "import": "./dist/enums.js",
48
+ "types": "./dist/enums.d.ts"
49
+ },
50
+ "./envelope": {
51
+ "import": "./dist/envelope.js",
52
+ "types": "./dist/envelope.d.ts"
53
+ },
54
+ "./namespaces": {
55
+ "import": "./dist/namespaces.js",
56
+ "types": "./dist/namespaces.d.ts"
57
+ },
58
+ "./pubkey": {
59
+ "import": "./dist/pubkey.js",
60
+ "types": "./dist/pubkey.d.ts"
61
+ },
62
+ "./snode-retrieve": {
63
+ "import": "./dist/snode-retrieve.js",
64
+ "types": "./dist/snode-retrieve.d.ts"
65
+ },
66
+ "./snode-signature-result": {
67
+ "import": "./dist/snode-signature-result.js",
68
+ "types": "./dist/snode-signature-result.d.ts"
69
+ },
70
+ "./snode": {
71
+ "import": "./dist/snode.js",
72
+ "types": "./dist/snode.d.ts"
73
+ },
74
+ "./swarm": {
75
+ "import": "./dist/swarm.js",
76
+ "types": "./dist/swarm.d.ts"
77
+ }
78
+ },
79
+ "main": "dist/index.js",
80
+ "types": "dist/index.d.ts",
81
+ "files": [
82
+ "dist/**/*.js",
83
+ "dist/**/*.d.ts",
84
+ "README.md",
85
+ "LICENSE"
86
+ ],
87
+ "scripts": {
88
+ "build": "rm -rf dist && tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && cp src/signal-bindings/compiled.js dist/signal-bindings/compiled.js && cp src/signal-bindings/compiled.d.ts dist/signal-bindings/compiled.d.ts",
89
+ "protobuf": "pbjs --target static-module --wrap es6 --out src/signal-bindings/compiled.js src/signal-bindings/signalservice.proto && pbts --out src/signal-bindings/compiled.d.ts src/signal-bindings/compiled.js --force-long"
90
+ },
91
+ "dependencies": {
92
+ "lodash": "^4.17.21",
93
+ "protobufjs": "^7.3.2"
94
+ },
95
+ "devDependencies": {
96
+ "@eslint/compat": "^2.0.1",
97
+ "@eslint/js": "^9.39.2",
98
+ "@types/lodash": "^4.17.7",
99
+ "eslint-config-prettier": "^10.1.8",
100
+ "prettier": "^3.8.0",
101
+ "protobufjs-cli": "^1.1.2",
102
+ "tsc-alias": "^1.8.10",
103
+ "typescript-eslint": "^8.53.1"
104
+ },
105
+ "peerDependencies": {
106
+ "typescript": "^5.0.0"
107
+ }
99
108
  }