@openpeepshq/core 0.1.31 → 0.1.33

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 (167) hide show
  1. package/dist/accessTokens/helpers.d.ts +2 -2
  2. package/dist/accessTokens/tokens.js +14 -7
  3. package/dist/accounts/mutations.d.ts +2 -2
  4. package/dist/analytics/cache.js +12 -7
  5. package/dist/analytics/clicks.d.ts +20 -0
  6. package/dist/analytics/clicks.js +194 -0
  7. package/dist/analytics/index.d.ts +1 -0
  8. package/dist/analytics/index.js +1 -0
  9. package/dist/analytics/metrics.d.ts +1 -0
  10. package/dist/analytics/metrics.js +5 -0
  11. package/dist/analytics/pdfReport.d.ts +1 -0
  12. package/dist/analytics/pdfReport.js +7 -5
  13. package/dist/analytics/privacy.d.ts +18 -0
  14. package/dist/analytics/privacy.js +10 -0
  15. package/dist/analytics/read.js +74 -16
  16. package/dist/analytics/report.d.ts +32 -1
  17. package/dist/analytics/report.js +9 -2
  18. package/dist/backups/index.js +13 -5
  19. package/dist/backups/metadata.d.ts +7 -0
  20. package/dist/config/defaults/community.js +0 -6
  21. package/dist/config/defaults/core.js +1 -0
  22. package/dist/config/defaults/db.d.ts +0 -2
  23. package/dist/config/defaults/db.js +0 -2
  24. package/dist/config/index.d.ts +20 -9
  25. package/dist/db/helpers.d.ts +6 -28
  26. package/dist/db/helpers.js +19 -149
  27. package/dist/db/index.d.ts +2 -0
  28. package/dist/db/index.js +4 -0
  29. package/dist/db/init.js +3 -2
  30. package/dist/db/migration/detect.d.ts +0 -3
  31. package/dist/db/migration/detect.js +0 -54
  32. package/dist/db/migration/importCollections.d.ts +1 -1
  33. package/dist/db/migration/importCollections.js +22 -6
  34. package/dist/db/migration/shared.d.ts +0 -4
  35. package/dist/db/migration/shared.js +0 -7
  36. package/dist/db/migration/transform.d.ts +2 -0
  37. package/dist/db/migration/transform.js +23 -0
  38. package/dist/db/pg/client.js +4 -0
  39. package/dist/db/pg/filters/edges.d.ts +1 -1
  40. package/dist/db/pg/filters/edges.js +1 -1
  41. package/dist/db/pg/filters/posts.d.ts +1 -0
  42. package/dist/db/pg/filters/posts.js +11 -1
  43. package/dist/db/pg/map/filters.js +5 -0
  44. package/dist/db/pg/map/relations.d.ts +1 -1
  45. package/dist/db/pg/map/relations.js +89 -41
  46. package/dist/db/pg/migrate.d.ts +23 -0
  47. package/dist/db/pg/migrate.js +87 -1
  48. package/dist/db/pg/queries/derived.d.ts +5 -0
  49. package/dist/db/pg/queries/derived.js +21 -0
  50. package/dist/db/pg/schema/analytics.d.ts +76 -0
  51. package/dist/db/pg/schema/analytics.js +11 -1
  52. package/dist/db/pg/schema/documents.d.ts +143 -0
  53. package/dist/db/pg/schema/documents.js +22 -1
  54. package/dist/db/pg/schema/edges.d.ts +1 -0
  55. package/dist/db/pg/schema/edges.js +1 -0
  56. package/dist/db/pg/schema/index.d.ts +218 -0
  57. package/dist/db/pg/sql/0005_open_power_man.sql +9 -0
  58. package/dist/db/pg/sql/0006_fine_trish_tilby.sql +8 -0
  59. package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
  60. package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
  61. package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
  62. package/dist/db/pg/sql/meta/0004_snapshot.json +1 -1
  63. package/dist/db/pg/sql/meta/0005_snapshot.json +4179 -0
  64. package/dist/db/pg/sql/meta/0006_snapshot.json +4200 -0
  65. package/dist/db/pg/sql/meta/0007_snapshot.json +4179 -0
  66. package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
  67. package/dist/db/pg/sql/meta/_journal.json +35 -0
  68. package/dist/db/replaceOrigin.d.ts +11 -0
  69. package/dist/db/replaceOrigin.js +116 -0
  70. package/dist/db/types.d.ts +0 -4
  71. package/dist/events/index.d.ts +2 -1
  72. package/dist/events/index.js +54 -33
  73. package/dist/groups/finders.d.ts +2 -2
  74. package/dist/groups/helpers.d.ts +6 -6
  75. package/dist/groups/mapping.d.ts +4 -4
  76. package/dist/groups/mapping.js +2 -2
  77. package/dist/groups/mutations.js +1 -1
  78. package/dist/inviteLinks/helpers.d.ts +4 -4
  79. package/dist/jams/cache.d.ts +1 -1
  80. package/dist/jams/cache.js +2 -1
  81. package/dist/jams/finders.d.ts +2 -1
  82. package/dist/jams/finders.js +18 -7
  83. package/dist/jams/helpers.d.ts +8 -4
  84. package/dist/jams/index.d.ts +4 -3
  85. package/dist/jams/index.js +23 -12
  86. package/dist/jams/livekit.d.ts +46 -8
  87. package/dist/jams/livekit.js +103 -21
  88. package/dist/jams/mapping.d.ts +14 -4
  89. package/dist/jams/mutations.d.ts +2 -0
  90. package/dist/jams/rtmp.d.ts +5 -0
  91. package/dist/jams/rtmp.js +8 -0
  92. package/dist/jams/token.d.ts +3 -3
  93. package/dist/jams/token.js +15 -12
  94. package/dist/jams/waitingRoom.d.ts +6 -4
  95. package/dist/jams/waitingRoom.js +33 -24
  96. package/dist/migration/index.d.ts +4 -0
  97. package/dist/migration/index.js +4 -0
  98. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
  99. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
  100. package/dist/notifications/helpers.js +6 -2
  101. package/dist/notifications/jobs.js +13 -2
  102. package/dist/notifications/push.js +11 -4
  103. package/dist/plugins/helpers.d.ts +6 -2
  104. package/dist/plugins/helpers.js +22 -10
  105. package/dist/plugins/index.d.ts +6 -1
  106. package/dist/plugins/index.js +54 -13
  107. package/dist/plugins/install.d.ts +20 -0
  108. package/dist/plugins/install.js +223 -0
  109. package/dist/plugins/state.d.ts +4 -0
  110. package/dist/plugins/state.js +29 -0
  111. package/dist/posts/contextClosure.d.ts +2 -1
  112. package/dist/posts/contextClosure.js +6 -1
  113. package/dist/posts/conversationQueries.d.ts +23 -0
  114. package/dist/posts/conversationQueries.js +135 -0
  115. package/dist/posts/eventAgenda.d.ts +165 -0
  116. package/dist/posts/eventAgenda.js +120 -0
  117. package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
  118. package/dist/posts/eventOccurrenceJobs.js +23 -0
  119. package/dist/posts/eventOccurrences.d.ts +4 -0
  120. package/dist/posts/eventOccurrences.js +40 -0
  121. package/dist/posts/finders.d.ts +39 -13
  122. package/dist/posts/finders.js +51 -66
  123. package/dist/posts/helpers/filters.js +1 -1
  124. package/dist/posts/helpers/index.d.ts +120 -34
  125. package/dist/posts/helpers/index.js +34 -21
  126. package/dist/posts/index.d.ts +4 -0
  127. package/dist/posts/index.js +4 -0
  128. package/dist/posts/mapping.d.ts +454 -0
  129. package/dist/posts/mapping.js +43 -9
  130. package/dist/posts/mutations.d.ts +4 -2
  131. package/dist/posts/mutations.js +49 -16
  132. package/dist/posts/rsvpConfirmationEmail.js +2 -1
  133. package/dist/posts/unseenCounts.d.ts +12 -0
  134. package/dist/posts/unseenCounts.js +98 -0
  135. package/dist/profiles/cache.d.ts +5 -1
  136. package/dist/profiles/cache.js +27 -1
  137. package/dist/profiles/helpers.d.ts +5 -5
  138. package/dist/profiles/index.d.ts +1 -0
  139. package/dist/profiles/index.js +1 -0
  140. package/dist/profiles/mapping.d.ts +45 -4
  141. package/dist/profiles/mapping.js +24 -0
  142. package/dist/profiles/mutations.js +12 -14
  143. package/dist/pushSubscriptions/helpers.d.ts +2 -2
  144. package/dist/pushSubscriptions/mutations.js +13 -1
  145. package/dist/reports/helpers.d.ts +6 -6
  146. package/dist/reports/helpers.js +2 -1
  147. package/dist/reports/mapping.js +6 -2
  148. package/dist/roles/defaults.js +1 -0
  149. package/dist/roles/mutations.d.ts +3 -3
  150. package/dist/roles/mutations.js +5 -3
  151. package/dist/server/index.d.ts +15 -7
  152. package/dist/server/index.js +15 -8
  153. package/dist/session/index.d.ts +28 -0
  154. package/dist/session/index.js +79 -0
  155. package/dist/stats/finders.d.ts +1912 -362
  156. package/dist/stats/mapping.d.ts +26 -5
  157. package/package.json +7 -12
  158. package/dist/db/arango.d.ts +0 -2
  159. package/dist/db/arango.js +0 -110
  160. package/dist/db/migration/autoMigrate.d.ts +0 -2
  161. package/dist/db/migration/autoMigrate.js +0 -111
  162. package/dist/db/migration/cli.d.ts +0 -1
  163. package/dist/db/migration/cli.js +0 -56
  164. package/dist/db/migration/exportArango.d.ts +0 -4
  165. package/dist/db/migration/exportArango.js +0 -80
  166. package/dist/db/replaceHostname.d.ts +0 -1
  167. package/dist/db/replaceHostname.js +0 -88
@@ -1,4 +1,4 @@
1
- import { RoleData } from '@openpeepshq/common/types';
2
- export declare const createRole: (roleData: RoleData) => Promise<import("@openpeepshq/common").Role>;
3
- export declare const updateRole: (id: string, roleData: Partial<RoleData>) => Promise<boolean>;
1
+ import { Role, RoleData } from '@openpeepshq/common/types';
2
+ export declare const createRole: (roleData: RoleData) => Promise<Role>;
3
+ export declare const updateRole: (id: string, roleData: Partial<RoleData>) => Promise<Role>;
4
4
  export declare const setDefaultRoles: () => Promise<void>;
@@ -14,9 +14,11 @@ export const createRole = (roleData) => allpeepDb().then(async ({ db }) => {
14
14
  }
15
15
  return rolesMapping.create(db, roleData);
16
16
  });
17
- export const updateRole = (id, roleData) => allpeepDb()
18
- .then(async ({ db }) => rolesMapping.update(db, id, roleData))
19
- .then(() => profilesCache.clear());
17
+ export const updateRole = (id, roleData) => allpeepDb().then(async ({ db }) => {
18
+ const role = await rolesMapping.update(db, id, roleData);
19
+ await profilesCache.clear();
20
+ return role;
21
+ });
20
22
  export const setDefaultRoles = async () => {
21
23
  for (const role of defaultRoles) {
22
24
  const existingRole = await findRoleByKey(role.key);
@@ -7,12 +7,16 @@ export declare const serverInfo: () => Promise<{
7
7
  version: string;
8
8
  environment: string;
9
9
  publicContent: boolean;
10
+ lastAccessed: string | null;
10
11
  communityConfig: {
11
12
  theme: {
12
13
  base: string;
13
- primaryHex: string;
14
14
  light: {
15
15
  primaryHex: string;
16
+ secondaryHex?: string | undefined;
17
+ fontFamily?: string | undefined;
18
+ buttonRadius?: string | undefined;
19
+ radius?: string | undefined;
16
20
  logoSmall?: string | undefined;
17
21
  defaultProfileAvatar?: string | undefined;
18
22
  defaultGroupAvatar?: string | undefined;
@@ -21,6 +25,10 @@ export declare const serverInfo: () => Promise<{
21
25
  };
22
26
  dark: {
23
27
  primaryHex: string;
28
+ secondaryHex?: string | undefined;
29
+ fontFamily?: string | undefined;
30
+ buttonRadius?: string | undefined;
31
+ radius?: string | undefined;
24
32
  logoSmall?: string | undefined;
25
33
  defaultProfileAvatar?: string | undefined;
26
34
  defaultGroupAvatar?: string | undefined;
@@ -29,12 +37,6 @@ export declare const serverInfo: () => Promise<{
29
37
  };
30
38
  icon?: string | undefined;
31
39
  mobileIcon?: string | undefined;
32
- logoFull?: string | undefined;
33
- logoSmall?: string | undefined;
34
- defaultProfileAvatar?: string | undefined;
35
- defaultGroupAvatar?: string | undefined;
36
- backgroundAuth?: string | undefined;
37
- background?: string | undefined;
38
40
  };
39
41
  info: {
40
42
  name: string;
@@ -97,9 +99,15 @@ export declare const serverInfo: () => Promise<{
97
99
  };
98
100
  maxProfiles?: number | undefined;
99
101
  sso?: {
102
+ generic: {
103
+ id: string;
104
+ name: string;
105
+ loginLink: string;
106
+ }[];
100
107
  oidc: {
101
108
  id: string;
102
109
  name: string;
103
110
  }[];
111
+ onlySSO?: boolean | undefined;
104
112
  } | undefined;
105
113
  }>;
@@ -1,4 +1,9 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { publicSsoInfo } from '@openpeepshq/common/lib';
1
3
  import { communityConfig, config } from '../config/index.js';
4
+ import { database } from '../db/index.js';
5
+ import { normalizeComputedDatetime } from '../db/pg/mappers.js';
6
+ import { postSeen } from '../db/pg/schema/index.js';
2
7
  /** Infer http vs https for absolute URLs (OIDC redirects, emails, media). */
3
8
  export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PROTOCOL) => {
4
9
  if (envProtocol === 'http' || envProtocol === 'https') {
@@ -18,12 +23,21 @@ export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PRO
18
23
  };
19
24
  export const serverProtocol = async () => protocolForServerHost((await config()).server.host);
20
25
  export const serverRootUrl = async () => `${await serverProtocol()}://${(await config()).server.host}`;
26
+ const lastAccessedFromPostViews = async () => {
27
+ var _a;
28
+ const db = await database();
29
+ const rows = await db
30
+ .select({ last: sql `max(${postSeen.createdAt})` })
31
+ .from(postSeen);
32
+ return normalizeComputedDatetime((_a = rows[0]) === null || _a === void 0 ? void 0 : _a.last);
33
+ };
21
34
  export const serverInfo = () => config().then(async (coreConfig) => {
22
35
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
23
36
  return ({
24
37
  version: coreConfig.version,
25
38
  environment: coreConfig.environment,
26
39
  publicContent: coreConfig.server.publicContent,
40
+ lastAccessed: await lastAccessedFromPostViews(),
27
41
  maxProfiles: coreConfig.server.maxProfiles || undefined,
28
42
  communityConfig: Object.assign(Object.assign({}, (await communityConfig())), { settings: Object.assign(Object.assign({}, (await communityConfig()).settings), { openRegistrations: !!coreConfig.server.signUpsOpen }) }),
29
43
  jams: {
@@ -52,13 +66,6 @@ export const serverInfo = () => config().then(async (coreConfig) => {
52
66
  },
53
67
  },
54
68
  },
55
- sso: coreConfig.sso.oidc.length > 0
56
- ? {
57
- oidc: coreConfig.sso.oidc.map((p) => ({
58
- id: p.id,
59
- name: p.name,
60
- })),
61
- }
62
- : undefined,
69
+ sso: publicSsoInfo(coreConfig.sso),
63
70
  });
64
71
  });
@@ -0,0 +1,28 @@
1
+ import type { SessionEvent, SessionPlatform } from '@openpeepshq/common/types';
2
+ export declare const publishSessionEvent: (profileId: string, event: SessionEvent) => Promise<void>;
3
+ export declare const subscribeToSessionEvents: (profileId: string, onEvent: (event: SessionEvent) => void | Promise<void>) => Promise<() => Promise<void>>;
4
+ export declare const registerSessionPresence: ({ profileId, connectionId, platform, }: {
5
+ profileId: string;
6
+ connectionId: string;
7
+ platform: SessionPlatform;
8
+ }) => Promise<void>;
9
+ export declare const refreshSessionPresence: (profileId: string, connectionId: string) => Promise<void>;
10
+ export declare const unregisterSessionPresence: (profileId: string, connectionId: string) => Promise<void>;
11
+ export declare const getSessionPresence: (profileId: string) => Promise<{
12
+ profileId: string;
13
+ connections: {
14
+ platform: SessionPlatform;
15
+ connectedAt: number;
16
+ connectionId: string;
17
+ }[];
18
+ platforms: ("ios" | "android" | "web")[];
19
+ } | undefined>;
20
+ export declare const listOnlineSessionPresence: () => Promise<{
21
+ profileId: string;
22
+ connections: {
23
+ platform: SessionPlatform;
24
+ connectedAt: number;
25
+ connectionId: string;
26
+ }[];
27
+ platforms: ("ios" | "android" | "web")[];
28
+ }[]>;
@@ -0,0 +1,79 @@
1
+ import { disconnect, getConnection, getSharedConnection, } from '../redis/connection.js';
2
+ import { logger } from '../log/index.js';
3
+ const log = logger('core:session');
4
+ const eventsChannel = (profileId) => `session:events:profile:${profileId}`;
5
+ const presenceOnlineKey = 'session:presence:online';
6
+ const presenceProfileKey = (profileId) => `session:presence:profile:${profileId}`;
7
+ const PRESENCE_TTL_SEC = 90;
8
+ export const publishSessionEvent = async (profileId, event) => {
9
+ const conn = await getSharedConnection();
10
+ await conn.publish(eventsChannel(profileId), JSON.stringify(event));
11
+ };
12
+ export const subscribeToSessionEvents = async (profileId, onEvent) => {
13
+ const conn = await getConnection();
14
+ await conn.subscribe(eventsChannel(profileId), (message) => {
15
+ try {
16
+ void onEvent(JSON.parse(message));
17
+ }
18
+ catch (error) {
19
+ log.error('Failed to parse session event', error);
20
+ }
21
+ });
22
+ return () => disconnect(conn);
23
+ };
24
+ export const registerSessionPresence = async ({ profileId, connectionId, platform, }) => {
25
+ const conn = await getSharedConnection();
26
+ const key = presenceProfileKey(profileId);
27
+ await conn.hSet(key, connectionId, JSON.stringify({ platform, connectedAt: Date.now() }));
28
+ await conn.expire(key, PRESENCE_TTL_SEC);
29
+ await conn.sAdd(presenceOnlineKey, profileId);
30
+ };
31
+ export const refreshSessionPresence = async (profileId, connectionId) => {
32
+ const conn = await getSharedConnection();
33
+ const key = presenceProfileKey(profileId);
34
+ if (!(await conn.hExists(key, connectionId)))
35
+ return;
36
+ await conn.expire(key, PRESENCE_TTL_SEC);
37
+ };
38
+ export const unregisterSessionPresence = async (profileId, connectionId) => {
39
+ const conn = await getSharedConnection();
40
+ const key = presenceProfileKey(profileId);
41
+ await conn.hDel(key, connectionId);
42
+ if ((await conn.hLen(key)) === 0) {
43
+ await conn.del(key);
44
+ await conn.sRem(presenceOnlineKey, profileId);
45
+ }
46
+ };
47
+ export const getSessionPresence = async (profileId) => {
48
+ const conn = await getSharedConnection();
49
+ const raw = await conn.hGetAll(presenceProfileKey(profileId));
50
+ const connections = Object.entries(raw).flatMap(([connectionId, value]) => {
51
+ try {
52
+ const parsed = JSON.parse(value);
53
+ return [Object.assign({ connectionId }, parsed)];
54
+ }
55
+ catch (_a) {
56
+ return [];
57
+ }
58
+ });
59
+ if (connections.length === 0)
60
+ return undefined;
61
+ return {
62
+ profileId,
63
+ connections,
64
+ platforms: [...new Set(connections.map((c) => c.platform))],
65
+ };
66
+ };
67
+ export const listOnlineSessionPresence = async () => {
68
+ const conn = await getSharedConnection();
69
+ const profileIds = await conn.sMembers(presenceOnlineKey);
70
+ const profiles = [];
71
+ for (const profileId of profileIds) {
72
+ const presence = await getSessionPresence(profileId);
73
+ if (presence)
74
+ profiles.push(presence);
75
+ else
76
+ await conn.sRem(presenceOnlineKey, profileId);
77
+ }
78
+ return profiles;
79
+ };