@peers-app/peers-sdk 0.16.2 → 0.16.4

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.
@@ -84,7 +84,7 @@ const getPrimaryAssistant = async (dataContext) => {
84
84
  if (a)
85
85
  return a;
86
86
  }
87
- const fallback = await Assistants(dataContext).get(system_ids_1.openCodeAssistantId);
87
+ const fallback = await Assistants(dataContext).get(system_ids_1.defaultAssistantId);
88
88
  if (!fallback)
89
89
  throw new Error("Primary assistant not found");
90
90
  return fallback;
@@ -29,6 +29,6 @@ function Devices(dataContext) {
29
29
  return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.deviceSchema);
30
30
  }
31
31
  exports.trustedServers = (0, persistent_vars_1.groupVar)("trustedServers", {
32
- defaultValue: ["https://peers.app", "https://peers-services.azurewebsites.net"],
32
+ defaultValue: ["https://peers.app"],
33
33
  });
34
34
  exports.thisDeviceId = (0, persistent_vars_1.deviceVar)("thisDeviceId");
@@ -184,8 +184,10 @@ async function copyToClipboard(text) {
184
184
  }
185
185
  }
186
186
  // get around circular dependency issue
187
- setTimeout(async () => {
188
- __1.rpcServerCalls.importGroupShare = (groupShareJson) => importGroupShare(groupShareJson);
187
+ setTimeout(() => {
188
+ if (__1.rpcServerCalls) {
189
+ __1.rpcServerCalls.importGroupShare = (groupShareJson) => importGroupShare(groupShareJson);
190
+ }
189
191
  }, 10);
190
192
  function getLowestDataSource(table) {
191
193
  let ds = table.dataSource;
@@ -10,7 +10,7 @@ export * from "./group-members";
10
10
  export * from "./group-permissions";
11
11
  export * from "./group-share";
12
12
  export * from "./groups";
13
- export * from "./knowledge/peer-types";
13
+ export * from "./peer-types";
14
14
  export * from "./messages";
15
15
  export * from "./package-versions";
16
16
  export * from "./packages";
@@ -26,7 +26,7 @@ __exportStar(require("./group-members"), exports);
26
26
  __exportStar(require("./group-permissions"), exports);
27
27
  __exportStar(require("./group-share"), exports);
28
28
  __exportStar(require("./groups"), exports);
29
- __exportStar(require("./knowledge/peer-types"), exports);
29
+ __exportStar(require("./peer-types"), exports);
30
30
  __exportStar(require("./messages"), exports);
31
31
  __exportStar(require("./package-versions"), exports);
32
32
  __exportStar(require("./packages"), exports);
@@ -1,22 +1,22 @@
1
1
  import { z } from "zod";
2
- import type { DataContext } from "../../context/data-context";
2
+ import type { DataContext } from "../context/data-context";
3
3
  declare const valueTypeSchema: z.ZodObject<{
4
4
  peerTypeId: z.ZodEffects<z.ZodString, string, string>;
5
5
  name: z.ZodString;
6
6
  description: z.ZodOptional<z.ZodString>;
7
7
  schema: z.ZodObject<{
8
- type: z.ZodNativeEnum<typeof import("../tools").IOSchemaType>;
8
+ type: z.ZodNativeEnum<typeof import("./tools").IOSchemaType>;
9
9
  fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
10
10
  name: z.ZodString;
11
11
  description: z.ZodOptional<z.ZodString>;
12
- type: z.ZodNativeEnum<typeof import("../..").FieldType>;
12
+ type: z.ZodNativeEnum<typeof import("..").FieldType>;
13
13
  defaultValue: z.ZodOptional<z.ZodAny>;
14
14
  optional: z.ZodOptional<z.ZodBoolean>;
15
15
  isArray: z.ZodOptional<z.ZodBoolean>;
16
16
  subType: z.ZodOptional<z.ZodString>;
17
17
  }, "strip", z.ZodTypeAny, {
18
18
  name: string;
19
- type: import("../..").FieldType;
19
+ type: import("..").FieldType;
20
20
  optional?: boolean | undefined;
21
21
  description?: string | undefined;
22
22
  defaultValue?: any;
@@ -24,7 +24,7 @@ declare const valueTypeSchema: z.ZodObject<{
24
24
  subType?: string | undefined;
25
25
  }, {
26
26
  name: string;
27
- type: import("../..").FieldType;
27
+ type: import("..").FieldType;
28
28
  optional?: boolean | undefined;
29
29
  description?: string | undefined;
30
30
  defaultValue?: any;
@@ -32,10 +32,10 @@ declare const valueTypeSchema: z.ZodObject<{
32
32
  subType?: string | undefined;
33
33
  }>, "many">>;
34
34
  }, "strip", z.ZodTypeAny, {
35
- type: import("../tools").IOSchemaType;
35
+ type: import("./tools").IOSchemaType;
36
36
  fields: {
37
37
  name: string;
38
- type: import("../..").FieldType;
38
+ type: import("..").FieldType;
39
39
  optional?: boolean | undefined;
40
40
  description?: string | undefined;
41
41
  defaultValue?: any;
@@ -43,10 +43,10 @@ declare const valueTypeSchema: z.ZodObject<{
43
43
  subType?: string | undefined;
44
44
  }[];
45
45
  }, {
46
- type: import("../tools").IOSchemaType;
46
+ type: import("./tools").IOSchemaType;
47
47
  fields?: {
48
48
  name: string;
49
- type: import("../..").FieldType;
49
+ type: import("..").FieldType;
50
50
  optional?: boolean | undefined;
51
51
  description?: string | undefined;
52
52
  defaultValue?: any;
@@ -58,10 +58,10 @@ declare const valueTypeSchema: z.ZodObject<{
58
58
  }, "strip", z.ZodTypeAny, {
59
59
  name: string;
60
60
  schema: {
61
- type: import("../tools").IOSchemaType;
61
+ type: import("./tools").IOSchemaType;
62
62
  fields: {
63
63
  name: string;
64
- type: import("../..").FieldType;
64
+ type: import("..").FieldType;
65
65
  optional?: boolean | undefined;
66
66
  description?: string | undefined;
67
67
  defaultValue?: any;
@@ -75,10 +75,10 @@ declare const valueTypeSchema: z.ZodObject<{
75
75
  }, {
76
76
  name: string;
77
77
  schema: {
78
- type: import("../tools").IOSchemaType;
78
+ type: import("./tools").IOSchemaType;
79
79
  fields?: {
80
80
  name: string;
81
- type: import("../..").FieldType;
81
+ type: import("..").FieldType;
82
82
  optional?: boolean | undefined;
83
83
  description?: string | undefined;
84
84
  defaultValue?: any;
@@ -91,13 +91,13 @@ declare const valueTypeSchema: z.ZodObject<{
91
91
  iconClass?: string | undefined;
92
92
  }>;
93
93
  export type IPeerType = z.infer<typeof valueTypeSchema>;
94
- export declare function PeerTypes(dataContext?: DataContext): import("../orm").Table<{
94
+ export declare function PeerTypes(dataContext?: DataContext): import("./orm").Table<{
95
95
  name: string;
96
96
  schema: {
97
- type: import("../tools").IOSchemaType;
97
+ type: import("./tools").IOSchemaType;
98
98
  fields: {
99
99
  name: string;
100
- type: import("../..").FieldType;
100
+ type: import("..").FieldType;
101
101
  optional?: boolean | undefined;
102
102
  description?: string | undefined;
103
103
  defaultValue?: any;
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PeerTypes = PeerTypes;
4
4
  const zod_1 = require("zod");
5
- const user_context_singleton_1 = require("../../context/user-context-singleton");
6
- const zod_types_1 = require("../../types/zod-types");
7
- const table_definitions_system_1 = require("../orm/table-definitions.system");
8
- const types_1 = require("../orm/types");
9
- const tools_1 = require("../tools");
5
+ const user_context_singleton_1 = require("../context/user-context-singleton");
6
+ const zod_types_1 = require("../types/zod-types");
7
+ const table_definitions_system_1 = require("./orm/table-definitions.system");
8
+ const types_1 = require("./orm/types");
9
+ const tools_1 = require("./tools");
10
10
  const valueTypeSchema = zod_1.z.object({
11
11
  peerTypeId: zod_types_1.zodPeerId,
12
12
  name: zod_1.z.string().describe("The name of the peer type"),
@@ -61,7 +61,7 @@ class PersistentVarsTable extends table_1.Table {
61
61
  persistentVar.persistentVarId = (0, utils_1.newid)();
62
62
  }
63
63
  const dbVar = await this.get(persistentVar.persistentVarId);
64
- if (persistentVar.isSecret && persistentVar.value.value !== undefined && !rpc_types_1.isClient) {
64
+ if (persistentVar.isSecret && persistentVar.value.value !== undefined && (!rpc_types_1.isClient || (0, rpc_types_1.isSingleProcessClient)())) {
65
65
  if (!dbVar ||
66
66
  dbVar.value.value !== persistentVar.value.value ||
67
67
  dbVar.isSecret !== persistentVar.isSecret) {
package/dist/events.js CHANGED
@@ -64,7 +64,7 @@ async function emit(event, dontPropagate) {
64
64
  // : rpcClientCalls.emitEvent(event).catch((err) => { console.error(`Error while propagating event to client`, err); return false; })
65
65
  // );
66
66
  // }
67
- if (!(dontPropagate || unitTests)) {
67
+ if (!(dontPropagate || unitTests || (0, rpc_types_1.isSingleProcessClient)())) {
68
68
  matchedHandlerPromises.push(rpc_types_1.rpcClientCalls.emitEvent(event).catch((err) => {
69
69
  console.error(`Error while propagating event to client`, err);
70
70
  return false;
package/dist/keys.js CHANGED
@@ -221,15 +221,25 @@ function encryptString(data, secretKey) {
221
221
  return `${encodeBase64(encryptedData)}~${encodeBase64(nonce)}`;
222
222
  }
223
223
  function decryptString(data, secretKey) {
224
- const _secretKey = decodeBase64(secretKey);
225
- const [encryptedData, nonce] = data.split("~");
226
- const _data = decodeBase64(encryptedData);
227
- const _nonce = decodeBase64(nonce);
228
- const decryptedData = nacl.secretbox.open(_data, _nonce, _secretKey.slice(0, 32));
229
- if (decryptedData === null) {
230
- throw new Error("Failed to decrypt data");
224
+ const preview = typeof data === "string" ? data.slice(0, 24) : String(data);
225
+ const hasSeparator = typeof data === "string" && data.includes("~");
226
+ try {
227
+ const _secretKey = decodeBase64(secretKey);
228
+ const [encryptedData, nonce] = data.split("~");
229
+ const _data = decodeBase64(encryptedData);
230
+ const _nonce = decodeBase64(nonce);
231
+ const decryptedData = nacl.secretbox.open(_data, _nonce, _secretKey.slice(0, 32));
232
+ if (decryptedData === null) {
233
+ throw new Error("secretbox.open returned null (wrong key or corrupted ciphertext)");
234
+ }
235
+ return (0, tweetnacl_util_1.encodeUTF8)(decryptedData);
236
+ }
237
+ catch (err) {
238
+ const reason = hasSeparator
239
+ ? "base64 decode or secretbox failed"
240
+ : "value does not look encrypted (missing '~' separator — was it saved without encryption?)";
241
+ throw new Error(`decryptString failed: ${reason}. Preview: "${preview}…" | Original error: ${err?.message ?? err}`);
231
242
  }
232
- return (0, tweetnacl_util_1.encodeUTF8)(decryptedData);
233
243
  }
234
244
  /** JSON-serializes `data` then NaCl `secretbox` with a random nonce; returns base64 payload `~` base64 nonce. */
235
245
  function encryptData(data, secretKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.16.2",
3
+ "version": "0.16.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"