@mostly-good-metrics/javascript 0.1.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.
- package/README.md +319 -0
- package/dist/cjs/client.js +416 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/index.js +65 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/logger.js +64 -0
- package/dist/cjs/logger.js.map +1 -0
- package/dist/cjs/network.js +192 -0
- package/dist/cjs/network.js.map +1 -0
- package/dist/cjs/storage.js +227 -0
- package/dist/cjs/storage.js.map +1 -0
- package/dist/cjs/types.js +70 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.js +249 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/client.js +412 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/index.js +40 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger.js +55 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/network.js +187 -0
- package/dist/esm/network.js.map +1 -0
- package/dist/esm/storage.js +221 -0
- package/dist/esm/storage.js.map +1 -0
- package/dist/esm/types.js +66 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.js +236 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/client.d.ts +126 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts +37 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/network.d.ts +28 -0
- package/dist/types/network.d.ts.map +1 -0
- package/dist/types/storage.d.ts +76 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/types.d.ts +279 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +48 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +68 -0
- package/src/client.test.ts +346 -0
- package/src/client.ts +510 -0
- package/src/index.ts +79 -0
- package/src/logger.ts +63 -0
- package/src/network.ts +230 -0
- package/src/storage.test.ts +175 -0
- package/src/storage.ts +249 -0
- package/src/types.ts +347 -0
- package/src/utils.test.ts +239 -0
- package/src/utils.ts +315 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the MostlyGoodMetrics SDK.
|
|
3
|
+
*/
|
|
4
|
+
export interface MGMConfiguration {
|
|
5
|
+
/**
|
|
6
|
+
* The API key for authenticating with MostlyGoodMetrics.
|
|
7
|
+
* Required.
|
|
8
|
+
*/
|
|
9
|
+
apiKey: string;
|
|
10
|
+
/**
|
|
11
|
+
* The base URL for the MostlyGoodMetrics API.
|
|
12
|
+
* @default "https://mostlygoodmetrics.com"
|
|
13
|
+
*/
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The environment name (e.g., "production", "staging", "development").
|
|
17
|
+
* @default "production"
|
|
18
|
+
*/
|
|
19
|
+
environment?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Maximum number of events to send in a single batch.
|
|
22
|
+
* Must be between 1 and 1000.
|
|
23
|
+
* @default 100
|
|
24
|
+
*/
|
|
25
|
+
maxBatchSize?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Interval in seconds between automatic flush attempts.
|
|
28
|
+
* Must be at least 1 second.
|
|
29
|
+
* @default 30
|
|
30
|
+
*/
|
|
31
|
+
flushInterval?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum number of events to store locally before dropping oldest events.
|
|
34
|
+
* Must be at least 100.
|
|
35
|
+
* @default 10000
|
|
36
|
+
*/
|
|
37
|
+
maxStoredEvents?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Whether to enable debug logging to the console.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
enableDebugLogging?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether to automatically track app lifecycle events
|
|
45
|
+
* ($app_opened, $app_backgrounded, $app_installed, $app_updated).
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
trackAppLifecycleEvents?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Custom bundle identifier to use instead of auto-detection.
|
|
51
|
+
* Useful for multi-tenant applications.
|
|
52
|
+
*/
|
|
53
|
+
bundleId?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The app version string to include with events.
|
|
56
|
+
* If not provided, will attempt to auto-detect from the environment.
|
|
57
|
+
*/
|
|
58
|
+
appVersion?: string;
|
|
59
|
+
/**
|
|
60
|
+
* The OS version string to include with events.
|
|
61
|
+
* If not provided, will attempt to auto-detect from the environment.
|
|
62
|
+
* For React Native, pass Platform.Version.toString().
|
|
63
|
+
*/
|
|
64
|
+
osVersion?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Custom storage adapter. If not provided, uses localStorage in browsers
|
|
67
|
+
* or in-memory storage in non-browser environments.
|
|
68
|
+
*/
|
|
69
|
+
storage?: IEventStorage;
|
|
70
|
+
/**
|
|
71
|
+
* Custom network client. If not provided, uses fetch-based client.
|
|
72
|
+
*/
|
|
73
|
+
networkClient?: INetworkClient;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Internal resolved configuration with all defaults applied.
|
|
77
|
+
*/
|
|
78
|
+
export interface ResolvedConfiguration extends Required<Omit<MGMConfiguration, 'storage' | 'networkClient'>> {
|
|
79
|
+
storage?: IEventStorage;
|
|
80
|
+
networkClient?: INetworkClient;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Properties that can be attached to an event.
|
|
84
|
+
* Supports nested objects up to 3 levels deep.
|
|
85
|
+
*/
|
|
86
|
+
export type EventProperties = Record<string, EventPropertyValue>;
|
|
87
|
+
/**
|
|
88
|
+
* Valid types for event property values.
|
|
89
|
+
*/
|
|
90
|
+
export type EventPropertyValue = null | boolean | number | string | EventPropertyValue[] | {
|
|
91
|
+
[key: string]: EventPropertyValue;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* An analytics event to be tracked.
|
|
95
|
+
*/
|
|
96
|
+
export interface MGMEvent {
|
|
97
|
+
/**
|
|
98
|
+
* The name of the event. Must match pattern: ^$?[a-zA-Z][a-zA-Z0-9_]*$
|
|
99
|
+
* Max 255 characters.
|
|
100
|
+
*/
|
|
101
|
+
name: string;
|
|
102
|
+
/**
|
|
103
|
+
* ISO8601 timestamp when the event occurred.
|
|
104
|
+
*/
|
|
105
|
+
timestamp: string;
|
|
106
|
+
/**
|
|
107
|
+
* The user ID associated with this event.
|
|
108
|
+
*/
|
|
109
|
+
userId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* The session ID associated with this event.
|
|
112
|
+
*/
|
|
113
|
+
sessionId?: string;
|
|
114
|
+
/**
|
|
115
|
+
* The platform this event was generated from.
|
|
116
|
+
*/
|
|
117
|
+
platform: Platform;
|
|
118
|
+
/**
|
|
119
|
+
* The app version string.
|
|
120
|
+
*/
|
|
121
|
+
appVersion?: string;
|
|
122
|
+
/**
|
|
123
|
+
* The OS version string.
|
|
124
|
+
*/
|
|
125
|
+
osVersion?: string;
|
|
126
|
+
/**
|
|
127
|
+
* The environment name.
|
|
128
|
+
*/
|
|
129
|
+
environment: string;
|
|
130
|
+
/**
|
|
131
|
+
* Custom properties attached to this event.
|
|
132
|
+
*/
|
|
133
|
+
properties?: EventProperties;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Context sent with each batch of events.
|
|
137
|
+
* Applied to all events in the batch server-side.
|
|
138
|
+
*/
|
|
139
|
+
export interface MGMEventContext {
|
|
140
|
+
platform: Platform;
|
|
141
|
+
appVersion?: string;
|
|
142
|
+
osVersion?: string;
|
|
143
|
+
userId?: string;
|
|
144
|
+
sessionId?: string;
|
|
145
|
+
environment: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The payload sent to the events API.
|
|
149
|
+
*/
|
|
150
|
+
export interface MGMEventsPayload {
|
|
151
|
+
events: MGMEvent[];
|
|
152
|
+
context: MGMEventContext;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Supported platforms.
|
|
156
|
+
*/
|
|
157
|
+
export type Platform = 'web' | 'ios' | 'android' | 'react-native' | 'expo' | 'node';
|
|
158
|
+
/**
|
|
159
|
+
* Device types for automatic device detection.
|
|
160
|
+
*/
|
|
161
|
+
export type DeviceType = 'phone' | 'tablet' | 'desktop' | 'tv' | 'watch' | 'unknown';
|
|
162
|
+
/**
|
|
163
|
+
* Error types that can occur in the SDK.
|
|
164
|
+
*/
|
|
165
|
+
export type MGMErrorType = 'NETWORK_ERROR' | 'ENCODING_ERROR' | 'BAD_REQUEST' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'RATE_LIMITED' | 'SERVER_ERROR' | 'INVALID_EVENT_NAME' | 'STORAGE_ERROR' | 'UNKNOWN_ERROR';
|
|
166
|
+
/**
|
|
167
|
+
* Result of a network send operation.
|
|
168
|
+
*/
|
|
169
|
+
export type SendResult = {
|
|
170
|
+
success: true;
|
|
171
|
+
} | {
|
|
172
|
+
success: false;
|
|
173
|
+
error: MGMError;
|
|
174
|
+
shouldRetry: boolean;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Interface for event storage implementations.
|
|
178
|
+
*/
|
|
179
|
+
export interface IEventStorage {
|
|
180
|
+
/**
|
|
181
|
+
* Store an event for later sending.
|
|
182
|
+
*/
|
|
183
|
+
store(event: MGMEvent): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Fetch up to `limit` events from storage (FIFO order).
|
|
186
|
+
*/
|
|
187
|
+
fetchEvents(limit: number): Promise<MGMEvent[]>;
|
|
188
|
+
/**
|
|
189
|
+
* Remove events from storage after successful send.
|
|
190
|
+
*/
|
|
191
|
+
removeEvents(count: number): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Get the current count of stored events.
|
|
194
|
+
*/
|
|
195
|
+
eventCount(): Promise<number>;
|
|
196
|
+
/**
|
|
197
|
+
* Clear all stored events.
|
|
198
|
+
*/
|
|
199
|
+
clear(): Promise<void>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Interface for network client implementations.
|
|
203
|
+
*/
|
|
204
|
+
export interface INetworkClient {
|
|
205
|
+
/**
|
|
206
|
+
* Send a batch of events to the server.
|
|
207
|
+
*/
|
|
208
|
+
sendEvents(payload: MGMEventsPayload, config: ResolvedConfiguration): Promise<SendResult>;
|
|
209
|
+
/**
|
|
210
|
+
* Check if the client is currently rate-limited.
|
|
211
|
+
*/
|
|
212
|
+
isRateLimited(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Get the retry-after time if rate-limited, or null if not.
|
|
215
|
+
*/
|
|
216
|
+
getRetryAfterTime(): Date | null;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Custom error class for SDK errors.
|
|
220
|
+
*/
|
|
221
|
+
export declare class MGMError extends Error {
|
|
222
|
+
readonly type: MGMErrorType;
|
|
223
|
+
readonly retryAfter?: number;
|
|
224
|
+
readonly statusCode?: number;
|
|
225
|
+
constructor(type: MGMErrorType, message: string, options?: {
|
|
226
|
+
retryAfter?: number;
|
|
227
|
+
statusCode?: number;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* System event names (prefixed with $).
|
|
232
|
+
*/
|
|
233
|
+
export declare const SystemEvents: {
|
|
234
|
+
readonly APP_INSTALLED: "$app_installed";
|
|
235
|
+
readonly APP_UPDATED: "$app_updated";
|
|
236
|
+
readonly APP_OPENED: "$app_opened";
|
|
237
|
+
readonly APP_BACKGROUNDED: "$app_backgrounded";
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* System property keys (prefixed with $).
|
|
241
|
+
*/
|
|
242
|
+
export declare const SystemProperties: {
|
|
243
|
+
readonly DEVICE_TYPE: "$device_type";
|
|
244
|
+
readonly DEVICE_MODEL: "$device_model";
|
|
245
|
+
readonly VERSION: "$version";
|
|
246
|
+
readonly PREVIOUS_VERSION: "$previous_version";
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Default configuration values.
|
|
250
|
+
*/
|
|
251
|
+
export declare const DefaultConfiguration: {
|
|
252
|
+
readonly baseURL: "https://mostlygoodmetrics.com";
|
|
253
|
+
readonly environment: "production";
|
|
254
|
+
readonly maxBatchSize: 100;
|
|
255
|
+
readonly flushInterval: 30;
|
|
256
|
+
readonly maxStoredEvents: 10000;
|
|
257
|
+
readonly enableDebugLogging: false;
|
|
258
|
+
readonly trackAppLifecycleEvents: true;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Validation constraints.
|
|
262
|
+
*/
|
|
263
|
+
export declare const Constraints: {
|
|
264
|
+
readonly MAX_EVENT_NAME_LENGTH: 255;
|
|
265
|
+
readonly MAX_BATCH_SIZE: 1000;
|
|
266
|
+
readonly MIN_BATCH_SIZE: 1;
|
|
267
|
+
readonly MIN_FLUSH_INTERVAL: 1;
|
|
268
|
+
readonly MIN_STORED_EVENTS: 100;
|
|
269
|
+
readonly MAX_STRING_PROPERTY_LENGTH: 1000;
|
|
270
|
+
readonly MAX_PROPERTY_DEPTH: 3;
|
|
271
|
+
readonly MAX_PROPERTY_SIZE_BYTES: number;
|
|
272
|
+
readonly COMPRESSION_THRESHOLD_BYTES: 1024;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Regular expression for validating event names.
|
|
276
|
+
* Must start with a letter (or $ for system events) followed by alphanumeric and underscores.
|
|
277
|
+
*/
|
|
278
|
+
export declare const EVENT_NAME_REGEX: RegExp;
|
|
279
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;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B,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DeviceType, EventProperties, MGMConfiguration, Platform, ResolvedConfiguration } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a UUID v4 string.
|
|
4
|
+
*/
|
|
5
|
+
export declare function generateUUID(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Get the current timestamp in ISO8601 format.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getISOTimestamp(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Validate an event name.
|
|
12
|
+
* Must match pattern: ^$?[a-zA-Z][a-zA-Z0-9_]*$
|
|
13
|
+
* Max 255 characters.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isValidEventName(name: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Validate an event name and throw if invalid.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateEventName(name: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Sanitize event properties by truncating strings and limiting depth.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sanitizeProperties(properties: EventProperties | undefined, maxDepth?: number): EventProperties | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve configuration with defaults.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveConfiguration(config: MGMConfiguration): ResolvedConfiguration;
|
|
28
|
+
/**
|
|
29
|
+
* Detect the current platform.
|
|
30
|
+
*/
|
|
31
|
+
export declare function detectPlatform(): Platform;
|
|
32
|
+
/**
|
|
33
|
+
* Detect the device type from user agent.
|
|
34
|
+
*/
|
|
35
|
+
export declare function detectDeviceType(): DeviceType;
|
|
36
|
+
/**
|
|
37
|
+
* Get the OS version string.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getOSVersion(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get the browser/device model.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getDeviceModel(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Delay execution for a specified number of milliseconds.
|
|
46
|
+
*/
|
|
47
|
+
export declare function delay(ms: number): Promise<void>;
|
|
48
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,UAAU,EAEV,eAAe,EAEf,gBAAgB,EAEhB,QAAQ,EACR,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAYrC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAkBpD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,eAAe,GAAG,SAAS,EACvC,QAAQ,GAAE,MAAuC,GAChD,eAAe,GAAG,SAAS,CAW7B;AA0DD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,qBAAqB,CAgCpF;AAeD;;GAEG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAczC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,CA0B7C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CA0BrC;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAyBvC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mostly-good-metrics/javascript",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript/TypeScript SDK for MostlyGoodMetrics - a lightweight analytics library for web applications",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.js",
|
|
12
|
+
"types": "./dist/types/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
|
21
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
22
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
23
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"lint": "eslint src --ext .ts",
|
|
26
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
27
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
28
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch",
|
|
31
|
+
"test:coverage": "jest --coverage",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"analytics",
|
|
37
|
+
"metrics",
|
|
38
|
+
"tracking",
|
|
39
|
+
"events",
|
|
40
|
+
"mostlygoodmetrics"
|
|
41
|
+
],
|
|
42
|
+
"author": "",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/jest": "^29.5.12",
|
|
46
|
+
"@types/node": "^20.11.0",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
48
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
49
|
+
"eslint": "^8.57.0",
|
|
50
|
+
"eslint-config-prettier": "^9.1.0",
|
|
51
|
+
"jest": "^29.7.0",
|
|
52
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
53
|
+
"prettier": "^3.2.0",
|
|
54
|
+
"ts-jest": "^29.1.2",
|
|
55
|
+
"typescript": "^5.3.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=16.0.0"
|
|
59
|
+
},
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "https://github.com/Mostly-Good-Metrics/mostly-good-metrics-js.git"
|
|
63
|
+
},
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/Mostly-Good-Metrics/mostly-good-metrics-js/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://mostlygoodmetrics.com"
|
|
68
|
+
}
|