@nhtio/swarm 1.20250424.0 → 1.20251110.0

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,5 +1,6 @@
1
- import { TypedEventEmitter } from '../lib/emitter';
2
- import type { TypedEventMap } from '../lib/emitter';
1
+ import { TypedEventEmitter } from './emitter';
2
+ import type { TypedEventMap } from './emitter';
3
+ import type { Secret } from '@nhtio/swarm';
3
4
  export type RequestHandlerMap<Events extends TypedEventMap> = {
4
5
  [K in keyof Events]: (...args: Events[K]) => any;
5
6
  };
@@ -12,7 +13,7 @@ export declare class Swarm<Events extends TypedEventMap = TypedEventMap> extends
12
13
  private static readonly INTERNAL_HEARTBEAT;
13
14
  private static readonly INTERNAL_OBITUARY;
14
15
  /** @private */
15
- constructor();
16
+ constructor(secret?: string | Secret<string>);
16
17
  /**
17
18
  * The ID of the current instance.
18
19
  */
@@ -100,5 +101,5 @@ export declare class Swarm<Events extends TypedEventMap = TypedEventMap> extends
100
101
  * @typeParam Events - The map of events and their arguments that can be emitted and listened to.
101
102
  * @returns The current instance of the Swarm class for the current context.
102
103
  */
103
- static instance<Events extends TypedEventMap = TypedEventMap>(): Swarm<Events>;
104
+ static instance<Events extends TypedEventMap = TypedEventMap>(secret?: string | Secret<string>): Swarm<Events>;
104
105
  }
package/lib/common.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare const isTabEnvironment: () => boolean;
8
8
  * @returns {boolean} - true if the environment is a service worker
9
9
  */
10
10
  export declare const isWorkerEnvironment: () => boolean;
11
+ export declare const isWebWorkerEnvironment: () => boolean;
11
12
  /**
12
13
  * Returns true if the environment is an SSR (Server-Side Rendering) environment
13
14
  * @returns {boolean} - true if the environment is an SSR environment
@@ -0,0 +1,9 @@
1
+ import { Encryption } from '@nhtio/web-encryption';
2
+ import { Secret } from '@nhtio/swarm';
3
+ export declare const getEncryption: (secret?: string | Secret<string>) => Encryption;
4
+ /**
5
+ * Set the pre-shared key used to ensure that any data shared between nodes in the swarm is encrypted and namespaced.
6
+ * @param secret The pre-shared key to use
7
+ * @returns
8
+ */
9
+ export declare const setPSK: (secret: string | Secret<string>) => void;
package/lib/logger.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare const LogLevelStyles: {
1
+ export declare const LogLevelStyles: {
2
2
  EMERG: (text: string) => string[];
3
3
  ALERT: (text: string) => string[];
4
4
  CRIT: (text: string) => string[];
package/lib/symbols.d.ts CHANGED
@@ -3,3 +3,4 @@ export declare const FOR_WORKER: unique symbol;
3
3
  export declare const FOR_SWARM: unique symbol;
4
4
  export declare const FOR_LOGGER: unique symbol;
5
5
  export declare const CAPTURE_REJECTION_SYMBOL: unique symbol;
6
+ export declare const FOR_ENCRYPTION: unique symbol;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhtio/swarm",
3
- "version": "1.20250424.0",
3
+ "version": "1.20251110.0",
4
4
  "description": "A library that provides peer communication between browser tabs and service workers",
5
5
  "keywords": [],
6
6
  "author": "Jak Giveon",
package/types.d.ts CHANGED
@@ -37,3 +37,4 @@ export interface BrowserInfo {
37
37
  }
38
38
  export type { TypedEventMap } from './lib/emitter';
39
39
  export type { RequestHandlerMap } from './lib/class_swarm';
40
+ export type { LogLevel, LogLevelStyles } from './lib/logger';
@@ -1,4 +0,0 @@
1
- "use strict";var h=Object.defineProperty;var p=(r,e,t)=>e in r?h(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e,t)=>p(r,typeof e!="symbol"?e+"":e,t);class i extends Error{constructor(t,s){const l=s?{cause:s.cause}:{};super(t,l);o(this,"$__name");o(this,"$__message");const n=this.constructor;if(Object.setPrototypeOf(this,n),this.$__name=n.name,this.$__message=t,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,n),this.stack&&s&&s.trim&&s.trim>0){const a=this.stack.split(`
2
- `);a.splice(0,s.trim),this.stack=a.join(`
3
- `)}}get name(){return this.$__name}get message(){return this.$__message}get[Symbol.toStringTag](){return this.constructor.name}toString(){return`${this.name}: ${this.message}`}[Symbol.toPrimitive](t){switch(t){case"string":return this.toString();default:return!0}}static[Symbol.hasInstance](t){if(typeof t=="object"&&t!==null||typeof t=="function"){const s=Object.getPrototypeOf(t);return s.name===this.name||s===this}return!1}}class c extends i{constructor(){super("Unable to setup instance because Service Workers are not supported in this environment")}}class u extends i{constructor(){super("Unable to setup instance because another instance is already initialized in this context")}}class m extends i{constructor(e){super(`Request timed out while waiting for event "${String(e)}".`)}}const d=Object.freeze(Object.defineProperty({__proto__:null,AlreadyInitializedInContextError:u,RequestTimeoutError:m,UnsupportedEnvironmentError:c},Symbol.toStringTag,{value:"Module"}));exports.AlreadyInitializedInContextError=u;exports.RequestTimeoutError=m;exports.UnsupportedEnvironmentError=c;exports.errors=d;
4
- //# sourceMappingURL=errors-DTZFdRbq.js.map