@peers-app/peers-sdk 0.7.17 → 0.7.19

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.
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * Example usage of the Logger class
4
+ *
5
+ * This file demonstrates how to use the Logger class for reliable, source-specific logging
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.processData = processData;
9
+ exports.initializeApp = initializeApp;
10
+ const console_logger_1 = require("./console-logger");
11
+ // Create a logger at the top of your file with a descriptive source name
12
+ const logger = new console_logger_1.Logger('MyModule');
13
+ // You can also let it auto-detect the source from the filename
14
+ // const logger = new Logger();
15
+ /**
16
+ * Example function that uses the logger
17
+ */
18
+ function processData(data) {
19
+ logger.log('Processing data', { dataSize: data.length });
20
+ try {
21
+ // Do some work
22
+ if (!data) {
23
+ logger.warn('No data provided');
24
+ return;
25
+ }
26
+ // More processing...
27
+ logger.debug('Data processing in progress', { step: 'validation' });
28
+ // Success
29
+ logger.info('Data processed successfully');
30
+ }
31
+ catch (error) {
32
+ logger.error('Failed to process data', error);
33
+ throw error;
34
+ }
35
+ }
36
+ /**
37
+ * Example initialization flow
38
+ */
39
+ async function initializeApp() {
40
+ // Early logging (before system is ready) - these get queued
41
+ logger.log('Application starting...');
42
+ // ... Initialize databases, connections, etc ...
43
+ // Mark logging as initialized - this flushes all queued logs
44
+ (0, console_logger_1.markLoggingInitialized)();
45
+ logger.log('Application fully initialized');
46
+ }
47
+ /**
48
+ * Benefits of using Logger class:
49
+ *
50
+ * 1. **Reliable Source Tracking**: Source is set once at construction time,
51
+ * not extracted from stack traces which can be unreliable
52
+ *
53
+ * 2. **Initialization Safety**: Logs before system is ready are queued and
54
+ * flushed once markLoggingInitialized() is called
55
+ *
56
+ * 3. **Infinite Loop Protection**: Inherits all the cross-process and
57
+ * single-process infinite loop detection
58
+ *
59
+ * 4. **Type Safety**: Full TypeScript support with proper typing
60
+ *
61
+ * 5. **Console Passthrough**: All logs still appear in the console immediately,
62
+ * database writes happen asynchronously
63
+ *
64
+ * Usage pattern:
65
+ * ```typescript
66
+ * // At the top of each file:
67
+ * const logger = new Logger('FeatureName');
68
+ *
69
+ * // Throughout your code:
70
+ * logger.log('Something happened');
71
+ * logger.error('Something went wrong', error);
72
+ * logger.debug('Detailed debugging info', { context });
73
+ * ```
74
+ */
@@ -9,13 +9,13 @@ export interface IPeerDevice {
9
9
  notifyOfChanges(deviceId: string, timestampLastApplied: number): Promise<void>;
10
10
  sendDeviceMessage(message: IDeviceMessage): Promise<any>;
11
11
  }
12
- export interface IDeviceMessage {
12
+ export interface IDeviceMessage<T = any> {
13
13
  deviceMessageId: string;
14
14
  fromDeviceId: string;
15
15
  toDeviceId: string;
16
16
  dataContextId: string;
17
17
  ttl: number;
18
- payload: any;
18
+ payload: T;
19
19
  hops: string[];
20
20
  suggestedPath?: string[];
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.7.17",
3
+ "version": "0.7.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"
@@ -30,8 +30,10 @@
30
30
  "release": "yarn release:patch"
31
31
  },
32
32
  "dependencies": {
33
+ "@msgpack/msgpack": "^3.1.2",
33
34
  "@noble/hashes": "^1.8.0",
34
35
  "fast-json-stable-stringify": "^2.1.0",
36
+ "fflate": "^0.8.2",
35
37
  "lodash": "^4.17.21",
36
38
  "moment": "^2.30.1",
37
39
  "moment-timezone": "^0.5.46",