socket-function 0.138.0 → 0.140.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/SocketFunction.ts CHANGED
@@ -431,6 +431,9 @@ export class SocketFunction {
431
431
  }
432
432
  return SocketFunction.connect({ address: location.hostname, port: +location.port || 443 });
433
433
  }
434
+ public static getBrowserNodeId() {
435
+ return this.browserNodeId();
436
+ }
434
437
 
435
438
  public static addGlobalHook(hook: SocketFunctionHook) {
436
439
  registerGlobalHook(hook as SocketFunctionHook);
@@ -117,8 +117,11 @@ export type CallerContext = Readonly<CallerContextBase>;
117
117
  export type CallerContextBase = {
118
118
  // IMPORTANT! Do not pass nodeId to other nodes with the intention of having
119
119
  // them call functions directly using nodeId. Instead pass location, and have them use connect.
120
- // - nodeId will be unique per thread, so is only useful for temporary communcation. If you want
120
+ // - nodeId will be unique per thread, so is only useful for temporary communication. If you want
121
121
  // a more permanent identity, you must derive it from certInfo yourself.
122
+ // ALSO IMPORTANT! DO NOT CHANGE THIS! Even though you might have a better id (a real domain name), and this might be a a weird id (`client:127.0.0.1:1758627917980.2603:0.08946007605096495`), IF you change this, it will break things.
123
+ // 1) It will break checks for client connections. This is used for security purposes. We do less security checks if WE established the connection, so if this is changed and it now looks like it is not a client, then it can create security vulnerabilities.
124
+ // 2) It will cause a connection to no longer appear to be === to it's past self.
122
125
  nodeId: string;
123
126
 
124
127
  // The nodeId they contacted. This is useful to determine their intention (otherwise
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.138.0",
3
+ "version": "0.140.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -363,7 +363,7 @@ export function requireMain() {
363
363
  try {
364
364
  resultObj = JSON.parse(rawText);
365
365
  } catch (e: any) {
366
- throw new Error(`Failed to require modules (likely permissions errors): ${JSON.stringify(requests)}. Start of response was: ${JSON.stringify(rawText.slice(0, 100))}. Error is: ${e.stack}`);
366
+ throw new Error(`require(${JSON.stringify(requests)}). Likely a permissions error, possibly fixed by restarting the local http server. Start of response was: ${JSON.stringify(rawText.slice(0, 100))}. Error is: ${e.stack}`);
367
367
  }
368
368
  let { modules, requestsResolvedPaths, requireSeqNumProcessId, error } = resultObj;
369
369
 
@@ -244,7 +244,7 @@ export function formatDateTimeDetailed(time: number) {
244
244
  let timeString = time.toString();
245
245
  let decimalIndex = timeString.indexOf(".");
246
246
  if (decimalIndex !== -1) {
247
- let fractionalPart = timeString.substring(decimalIndex + 4);
247
+ let fractionalPart = timeString.substring(decimalIndex + 1);
248
248
  millisecondsString += fractionalPart;
249
249
  }
250
250
 
@@ -255,6 +255,70 @@ export function formatDateTimeDetailed(time: number) {
255
255
  return date.getFullYear() + "/" + p(date.getMonth() + 1) + "/" + p(date.getDate()) + " " + strTime;
256
256
  }
257
257
 
258
+
259
+ // Lookup table for common timezone abbreviations by UTC offset (in minutes)
260
+ const timezoneAbbreviations: { [offsetMinutes: string]: string } = {
261
+ // UTC and GMT
262
+ "0": "UTC",
263
+
264
+ // US/Canada timezones
265
+ "300": "EST", // UTC-5 (Eastern Standard Time)
266
+ "240": "EDT", // UTC-4 (Eastern Daylight Time)
267
+ "360": "CST", // UTC-6 (Central Standard Time)
268
+ "420": "MST", // UTC-7 (Mountain Standard Time)
269
+ "480": "PST", // UTC-8 (Pacific Standard Time)
270
+
271
+ // European timezones
272
+ "-60": "CET", // UTC+1 (Central European Time)
273
+ "-120": "CEST", // UTC+2 (Central European Summer Time)
274
+
275
+ // Other common timezones
276
+ "-480": "CST", // UTC+8 (China Standard Time)
277
+ "-540": "JST", // UTC+9 (Japan Standard Time)
278
+ "-330": "IST", // UTC+5:30 (India Standard Time)
279
+ "-570": "ACST", // UTC+9:30 (Australian Central Standard Time)
280
+ "-600": "AEST", // UTC+10 (Australian Eastern Standard Time)
281
+ };
282
+
283
+
284
+ // YYYY-MM-DD_HH-MM-SS.mmm TIMEZONE
285
+ export function formatFileTimestampLocal(time: number): string {
286
+ function p(s: number) {
287
+ return s.toString().padStart(2, "0");
288
+ }
289
+
290
+ let date = new Date(time);
291
+ let year = date.getFullYear();
292
+ let month = p(date.getMonth() + 1);
293
+ let day = p(date.getDate());
294
+ let hours = p(date.getHours());
295
+ let minutes = p(date.getMinutes());
296
+ let seconds = p(date.getSeconds());
297
+ let milliseconds = date.getMilliseconds();
298
+ let millisecondsString = milliseconds.toString().padStart(3, "0");
299
+
300
+ let timeString = time.toString();
301
+ let decimalIndex = timeString.indexOf(".");
302
+ if (decimalIndex !== -1) {
303
+ let fractionalPart = timeString.substring(decimalIndex + 1);
304
+ millisecondsString += fractionalPart;
305
+ }
306
+ // Get timezone offset in minutes (negative of getTimezoneOffset because it returns opposite sign)
307
+ let timezoneOffsetMinutes = date.getTimezoneOffset();
308
+
309
+ // Look up the abbreviation or fallback to numeric format
310
+ let timezoneString = timezoneAbbreviations[timezoneOffsetMinutes.toString()];
311
+ if (!timezoneString) {
312
+ // Fallback: format as ±HHMM
313
+ let offsetSign = timezoneOffsetMinutes >= 0 ? "+" : "-";
314
+ let offsetHours = p(Math.floor(Math.abs(timezoneOffsetMinutes) / 60));
315
+ let offsetMins = p(Math.abs(timezoneOffsetMinutes) % 60);
316
+ timezoneString = `${offsetSign}${offsetHours}${offsetMins}`;
317
+ }
318
+
319
+ return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}.${millisecondsString}_${timezoneString}`;
320
+ }
321
+
258
322
  /** 2024 January 1, Monday, 12:53:02pm */
259
323
  export function formatNiceDateTime(time: number) {
260
324
  function p(s: number) {