@mentra/sdk 1.1.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.
Files changed (101) hide show
  1. package/README.md +102 -0
  2. package/dist/constants/index.d.ts +14 -0
  3. package/dist/constants/index.d.ts.map +1 -0
  4. package/dist/constants/index.js +16 -0
  5. package/dist/examples/rtmp-streaming-example.d.ts +2 -0
  6. package/dist/examples/rtmp-streaming-example.d.ts.map +1 -0
  7. package/dist/examples/rtmp-streaming-example.js +102 -0
  8. package/dist/index.d.ts +4 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +33 -0
  11. package/dist/logging/logger.d.ts +3 -0
  12. package/dist/logging/logger.d.ts.map +1 -0
  13. package/dist/logging/logger.js +79 -0
  14. package/dist/tpa/index.d.ts +6 -0
  15. package/dist/tpa/index.d.ts.map +1 -0
  16. package/dist/tpa/index.js +24 -0
  17. package/dist/tpa/server/index.d.ts +193 -0
  18. package/dist/tpa/server/index.d.ts.map +1 -0
  19. package/dist/tpa/server/index.js +436 -0
  20. package/dist/tpa/session/api-client.d.ts +49 -0
  21. package/dist/tpa/session/api-client.d.ts.map +1 -0
  22. package/dist/tpa/session/api-client.js +101 -0
  23. package/dist/tpa/session/dashboard.d.ts +52 -0
  24. package/dist/tpa/session/dashboard.d.ts.map +1 -0
  25. package/dist/tpa/session/dashboard.js +149 -0
  26. package/dist/tpa/session/events.d.ts +178 -0
  27. package/dist/tpa/session/events.d.ts.map +1 -0
  28. package/dist/tpa/session/events.js +294 -0
  29. package/dist/tpa/session/index.d.ts +391 -0
  30. package/dist/tpa/session/index.d.ts.map +1 -0
  31. package/dist/tpa/session/index.js +1452 -0
  32. package/dist/tpa/session/layouts.d.ts +150 -0
  33. package/dist/tpa/session/layouts.d.ts.map +1 -0
  34. package/dist/tpa/session/layouts.js +282 -0
  35. package/dist/tpa/session/modules/streaming.d.ts +100 -0
  36. package/dist/tpa/session/modules/streaming.d.ts.map +1 -0
  37. package/dist/tpa/session/modules/streaming.js +270 -0
  38. package/dist/tpa/session/settings.d.ts +202 -0
  39. package/dist/tpa/session/settings.d.ts.map +1 -0
  40. package/dist/tpa/session/settings.js +361 -0
  41. package/dist/tpa/token/index.d.ts +7 -0
  42. package/dist/tpa/token/index.d.ts.map +1 -0
  43. package/dist/tpa/token/index.js +22 -0
  44. package/dist/tpa/token/utils.d.ts +69 -0
  45. package/dist/tpa/token/utils.d.ts.map +1 -0
  46. package/dist/tpa/token/utils.js +144 -0
  47. package/dist/tpa/webview/index.d.ts +47 -0
  48. package/dist/tpa/webview/index.d.ts.map +1 -0
  49. package/dist/tpa/webview/index.js +344 -0
  50. package/dist/types/dashboard/index.d.ts +128 -0
  51. package/dist/types/dashboard/index.d.ts.map +1 -0
  52. package/dist/types/dashboard/index.js +12 -0
  53. package/dist/types/enums.d.ts +57 -0
  54. package/dist/types/enums.d.ts.map +1 -0
  55. package/dist/types/enums.js +72 -0
  56. package/dist/types/index.d.ts +38 -0
  57. package/dist/types/index.d.ts.map +1 -0
  58. package/dist/types/index.js +87 -0
  59. package/dist/types/layouts.d.ts +51 -0
  60. package/dist/types/layouts.d.ts.map +1 -0
  61. package/dist/types/layouts.js +3 -0
  62. package/dist/types/message-types.d.ts +109 -0
  63. package/dist/types/message-types.d.ts.map +1 -0
  64. package/dist/types/message-types.js +189 -0
  65. package/dist/types/messages/base.d.ts +12 -0
  66. package/dist/types/messages/base.d.ts.map +1 -0
  67. package/dist/types/messages/base.js +3 -0
  68. package/dist/types/messages/cloud-to-glasses.d.ts +126 -0
  69. package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -0
  70. package/dist/types/messages/cloud-to-glasses.js +60 -0
  71. package/dist/types/messages/cloud-to-tpa.d.ts +228 -0
  72. package/dist/types/messages/cloud-to-tpa.d.ts.map +1 -0
  73. package/dist/types/messages/cloud-to-tpa.js +61 -0
  74. package/dist/types/messages/glasses-to-cloud.d.ts +219 -0
  75. package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -0
  76. package/dist/types/messages/glasses-to-cloud.js +88 -0
  77. package/dist/types/messages/tpa-to-cloud.d.ts +146 -0
  78. package/dist/types/messages/tpa-to-cloud.d.ts.map +1 -0
  79. package/dist/types/messages/tpa-to-cloud.js +67 -0
  80. package/dist/types/models.d.ts +165 -0
  81. package/dist/types/models.d.ts.map +1 -0
  82. package/dist/types/models.js +84 -0
  83. package/dist/types/rtmp-stream.d.ts +68 -0
  84. package/dist/types/rtmp-stream.d.ts.map +1 -0
  85. package/dist/types/rtmp-stream.js +3 -0
  86. package/dist/types/streams.d.ts +138 -0
  87. package/dist/types/streams.d.ts.map +1 -0
  88. package/dist/types/streams.js +251 -0
  89. package/dist/types/token.d.ts +41 -0
  90. package/dist/types/token.d.ts.map +1 -0
  91. package/dist/types/token.js +7 -0
  92. package/dist/types/user-session.d.ts +73 -0
  93. package/dist/types/user-session.d.ts.map +1 -0
  94. package/dist/types/user-session.js +17 -0
  95. package/dist/types/webhooks.d.ts +107 -0
  96. package/dist/types/webhooks.d.ts.map +1 -0
  97. package/dist/types/webhooks.js +55 -0
  98. package/dist/utils/resource-tracker.d.ts +94 -0
  99. package/dist/utils/resource-tracker.d.ts.map +1 -0
  100. package/dist/utils/resource-tracker.js +153 -0
  101. package/package.json +50 -0
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ // src/webhook.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.WebhookRequestType = void 0;
5
+ exports.isSessionWebhookRequest = isSessionWebhookRequest;
6
+ exports.isStopWebhookRequest = isStopWebhookRequest;
7
+ exports.isServerRegistrationWebhookRequest = isServerRegistrationWebhookRequest;
8
+ exports.isSessionRecoveryWebhookRequest = isSessionRecoveryWebhookRequest;
9
+ exports.isServerHeartbeatWebhookRequest = isServerHeartbeatWebhookRequest;
10
+ /**
11
+ * Types of webhook requests that can be sent to TPAs
12
+ */
13
+ var WebhookRequestType;
14
+ (function (WebhookRequestType) {
15
+ /** Request to start a TPA session */
16
+ WebhookRequestType["SESSION_REQUEST"] = "session_request";
17
+ /** Request to stop a TPA session */
18
+ WebhookRequestType["STOP_REQUEST"] = "stop_request";
19
+ /** Server registration confirmation */
20
+ WebhookRequestType["SERVER_REGISTRATION"] = "server_registration";
21
+ /** Server heartbeat response */
22
+ WebhookRequestType["SERVER_HEARTBEAT"] = "server_heartbeat";
23
+ /** Session recovery request */
24
+ WebhookRequestType["SESSION_RECOVERY"] = "session_recovery";
25
+ })(WebhookRequestType || (exports.WebhookRequestType = WebhookRequestType = {}));
26
+ /**
27
+ * Type guard to check if a webhook request is a session request
28
+ */
29
+ function isSessionWebhookRequest(request) {
30
+ return request.type === WebhookRequestType.SESSION_REQUEST;
31
+ }
32
+ /**
33
+ * Type guard to check if a webhook request is a stop request
34
+ */
35
+ function isStopWebhookRequest(request) {
36
+ return request.type === WebhookRequestType.STOP_REQUEST;
37
+ }
38
+ /**
39
+ * Type guard to check if a webhook request is a server registration request
40
+ */
41
+ function isServerRegistrationWebhookRequest(request) {
42
+ return request.type === WebhookRequestType.SERVER_REGISTRATION;
43
+ }
44
+ /**
45
+ * Type guard to check if a webhook request is a session recovery request
46
+ */
47
+ function isSessionRecoveryWebhookRequest(request) {
48
+ return request.type === WebhookRequestType.SESSION_RECOVERY;
49
+ }
50
+ /**
51
+ * Type guard to check if a webhook request is a server heartbeat request
52
+ */
53
+ function isServerHeartbeatWebhookRequest(request) {
54
+ return request.type === WebhookRequestType.SERVER_HEARTBEAT;
55
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Resource Tracker
3
+ *
4
+ * A utility class for tracking and automatically cleaning up resources
5
+ * like timers, event listeners, and other disposable objects.
6
+ *
7
+ * This helps prevent memory leaks by ensuring that all resources are
8
+ * properly disposed when they're no longer needed.
9
+ */
10
+ /**
11
+ * Type for a cleanup function that doesn't take any arguments
12
+ */
13
+ export type CleanupFunction = () => void;
14
+ /**
15
+ * Type for any object with a dispose or close method
16
+ */
17
+ export interface Disposable {
18
+ dispose?: () => void;
19
+ close?: () => void;
20
+ }
21
+ /**
22
+ * Manages resources to prevent memory leaks
23
+ */
24
+ export declare class ResourceTracker {
25
+ private cleanupFunctions;
26
+ private isDisposed;
27
+ /**
28
+ * Add a cleanup function to be executed when dispose() is called
29
+ *
30
+ * @param cleanup - The cleanup function to register
31
+ * @returns A function that will remove this cleanup function
32
+ */
33
+ track(cleanup: CleanupFunction): CleanupFunction;
34
+ /**
35
+ * Track a disposable object (anything with a dispose or close method)
36
+ *
37
+ * @param disposable - The object to track
38
+ * @returns A function that will remove this disposable
39
+ */
40
+ trackDisposable(disposable: Disposable): CleanupFunction;
41
+ /**
42
+ * Track a timer and ensure it gets cleared
43
+ *
44
+ * @param timerId - The timer ID to track
45
+ * @param isInterval - Whether this is an interval (true) or timeout (false)
46
+ * @returns A function that will remove this timer
47
+ */
48
+ trackTimer(timerId: NodeJS.Timeout, isInterval?: boolean): CleanupFunction;
49
+ /**
50
+ * Track a timeout and ensure it gets cleared
51
+ *
52
+ * @param timerId - The timeout ID to track
53
+ * @returns A function that will remove this timeout
54
+ */
55
+ trackTimeout(timerId: NodeJS.Timeout): CleanupFunction;
56
+ /**
57
+ * Track an interval and ensure it gets cleared
58
+ *
59
+ * @param timerId - The interval ID to track
60
+ * @returns A function that will remove this interval
61
+ */
62
+ trackInterval(timerId: NodeJS.Timeout): CleanupFunction;
63
+ /**
64
+ * Create a tracked timeout
65
+ *
66
+ * @param callback - Function to call when the timeout expires
67
+ * @param ms - Milliseconds to wait
68
+ * @returns The timeout ID
69
+ */
70
+ setTimeout(callback: (...args: any[]) => void, ms: number): NodeJS.Timeout;
71
+ /**
72
+ * Create a tracked interval
73
+ *
74
+ * @param callback - Function to call at each interval
75
+ * @param ms - Milliseconds between intervals
76
+ * @returns The interval ID
77
+ */
78
+ setInterval(callback: (...args: any[]) => void, ms: number): NodeJS.Timeout;
79
+ /**
80
+ * Dispose of all tracked resources
81
+ */
82
+ dispose(): void;
83
+ /**
84
+ * Check if this tracker has been disposed
85
+ */
86
+ get disposed(): boolean;
87
+ }
88
+ /**
89
+ * Create a new ResourceTracker instance
90
+ *
91
+ * @returns A new ResourceTracker
92
+ */
93
+ export declare function createResourceTracker(): ResourceTracker;
94
+ //# sourceMappingURL=resource-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-tracker.d.ts","sourceRoot":"","sources":["../../src/utils/resource-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,eAAe;IAE1B,OAAO,CAAC,gBAAgB,CAAyB;IAGjD,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe;IAgBhD;;;;;OAKG;IACH,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe;IAUxD;;;;;;OAMG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,UAAQ,GAAG,eAAe;IAUxE;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,GAAG,eAAe;IAItD;;;;;OAKG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,GAAG,eAAe;IAIvD;;;;;;OAMG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO;IAM1E;;;;;;OAMG;IACH,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO;IAM3E;;OAEG;IACH,OAAO,IAAI,IAAI;IAmBf;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;CACF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CAEvD"}
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ /**
3
+ * Resource Tracker
4
+ *
5
+ * A utility class for tracking and automatically cleaning up resources
6
+ * like timers, event listeners, and other disposable objects.
7
+ *
8
+ * This helps prevent memory leaks by ensuring that all resources are
9
+ * properly disposed when they're no longer needed.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ResourceTracker = void 0;
13
+ exports.createResourceTracker = createResourceTracker;
14
+ /**
15
+ * Manages resources to prevent memory leaks
16
+ */
17
+ class ResourceTracker {
18
+ constructor() {
19
+ // Collection of cleanup functions to call when dispose() is called
20
+ this.cleanupFunctions = [];
21
+ // Flag to track if this resource tracker has been disposed
22
+ this.isDisposed = false;
23
+ }
24
+ /**
25
+ * Add a cleanup function to be executed when dispose() is called
26
+ *
27
+ * @param cleanup - The cleanup function to register
28
+ * @returns A function that will remove this cleanup function
29
+ */
30
+ track(cleanup) {
31
+ if (this.isDisposed) {
32
+ throw new Error('Cannot track resources on a disposed ResourceTracker');
33
+ }
34
+ this.cleanupFunctions.push(cleanup);
35
+ // Return a function that will remove this cleanup function
36
+ return () => {
37
+ const index = this.cleanupFunctions.indexOf(cleanup);
38
+ if (index !== -1) {
39
+ this.cleanupFunctions.splice(index, 1);
40
+ }
41
+ };
42
+ }
43
+ /**
44
+ * Track a disposable object (anything with a dispose or close method)
45
+ *
46
+ * @param disposable - The object to track
47
+ * @returns A function that will remove this disposable
48
+ */
49
+ trackDisposable(disposable) {
50
+ return this.track(() => {
51
+ if (typeof disposable.dispose === 'function') {
52
+ disposable.dispose();
53
+ }
54
+ else if (typeof disposable.close === 'function') {
55
+ disposable.close();
56
+ }
57
+ });
58
+ }
59
+ /**
60
+ * Track a timer and ensure it gets cleared
61
+ *
62
+ * @param timerId - The timer ID to track
63
+ * @param isInterval - Whether this is an interval (true) or timeout (false)
64
+ * @returns A function that will remove this timer
65
+ */
66
+ trackTimer(timerId, isInterval = false) {
67
+ return this.track(() => {
68
+ if (isInterval) {
69
+ clearInterval(timerId);
70
+ }
71
+ else {
72
+ clearTimeout(timerId);
73
+ }
74
+ });
75
+ }
76
+ /**
77
+ * Track a timeout and ensure it gets cleared
78
+ *
79
+ * @param timerId - The timeout ID to track
80
+ * @returns A function that will remove this timeout
81
+ */
82
+ trackTimeout(timerId) {
83
+ return this.trackTimer(timerId, false);
84
+ }
85
+ /**
86
+ * Track an interval and ensure it gets cleared
87
+ *
88
+ * @param timerId - The interval ID to track
89
+ * @returns A function that will remove this interval
90
+ */
91
+ trackInterval(timerId) {
92
+ return this.trackTimer(timerId, true);
93
+ }
94
+ /**
95
+ * Create a tracked timeout
96
+ *
97
+ * @param callback - Function to call when the timeout expires
98
+ * @param ms - Milliseconds to wait
99
+ * @returns The timeout ID
100
+ */
101
+ setTimeout(callback, ms) {
102
+ const timerId = setTimeout(callback, ms);
103
+ this.trackTimeout(timerId);
104
+ return timerId;
105
+ }
106
+ /**
107
+ * Create a tracked interval
108
+ *
109
+ * @param callback - Function to call at each interval
110
+ * @param ms - Milliseconds between intervals
111
+ * @returns The interval ID
112
+ */
113
+ setInterval(callback, ms) {
114
+ const timerId = setInterval(callback, ms);
115
+ this.trackInterval(timerId);
116
+ return timerId;
117
+ }
118
+ /**
119
+ * Dispose of all tracked resources
120
+ */
121
+ dispose() {
122
+ if (this.isDisposed) {
123
+ return;
124
+ }
125
+ // Run all cleanup functions
126
+ for (const cleanup of this.cleanupFunctions) {
127
+ try {
128
+ cleanup();
129
+ }
130
+ catch (error) {
131
+ console.error('Error during resource cleanup:', error);
132
+ }
133
+ }
134
+ // Clear the array
135
+ this.cleanupFunctions = [];
136
+ this.isDisposed = true;
137
+ }
138
+ /**
139
+ * Check if this tracker has been disposed
140
+ */
141
+ get disposed() {
142
+ return this.isDisposed;
143
+ }
144
+ }
145
+ exports.ResourceTracker = ResourceTracker;
146
+ /**
147
+ * Create a new ResourceTracker instance
148
+ *
149
+ * @returns A new ResourceTracker
150
+ */
151
+ function createResourceTracker() {
152
+ return new ResourceTracker();
153
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@mentra/sdk",
3
+ "version": "1.1.19",
4
+ "description": "Build apps for MentraOS smartglasses. This SDK provides everything you need to create real-time smartglasses applications.",
5
+ "source": "src/index.ts",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ "development": {
10
+ "import": "./src/index.ts",
11
+ "require": "./src/index.ts",
12
+ "types": "./src/index.ts"
13
+ },
14
+ "default": {
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "rm -rf dist && bun x tsc -p tsconfig.json",
22
+ "dev": "echo 'No build needed in dev mode - using source files directly'",
23
+ "prepare": "bun run build",
24
+ "link-pkg": "bun link"
25
+ },
26
+ "dependencies": {
27
+ "@logtail/pino": "^0.5.4",
28
+ "axios": "^1.8.1",
29
+ "cookie-parser": "^1.4.7",
30
+ "dotenv": "^16.4.0",
31
+ "express": "^4.18.2",
32
+ "jsonwebtoken": "^8.5.1",
33
+ "jsrsasign": "^11.1.0",
34
+ "pino": "^9.6.0",
35
+ "pino-pretty": "^13.0.0",
36
+ "ws": "^8.18.2"
37
+ },
38
+ "devDependencies": {
39
+ "@types/babel__core": "^7.20.5",
40
+ "@types/express": "^4.17.17",
41
+ "@types/jsonwebtoken": "^9.0.2",
42
+ "@types/jsrsasign": "^10.5.15",
43
+ "@types/node": "^20.0.0",
44
+ "@types/ws": "^8.5.12",
45
+ "typescript": "^5.0.0"
46
+ },
47
+ "files": [
48
+ "dist"
49
+ ]
50
+ }