@openpeepshq/core 0.1.32 → 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.
- package/dist/accessTokens/helpers.d.ts +2 -2
- package/dist/accessTokens/tokens.js +14 -7
- package/dist/accounts/mutations.d.ts +2 -2
- package/dist/analytics/cache.js +12 -7
- package/dist/analytics/pdfReport.d.ts +1 -0
- package/dist/analytics/pdfReport.js +5 -4
- package/dist/analytics/privacy.d.ts +18 -0
- package/dist/analytics/privacy.js +10 -0
- package/dist/analytics/read.js +24 -11
- package/dist/analytics/report.d.ts +1 -1
- package/dist/analytics/report.js +9 -2
- package/dist/backups/index.js +6 -3
- package/dist/backups/metadata.d.ts +7 -0
- package/dist/config/defaults/community.js +0 -6
- package/dist/config/defaults/db.d.ts +0 -2
- package/dist/config/defaults/db.js +0 -2
- package/dist/config/index.d.ts +10 -9
- package/dist/db/helpers.d.ts +6 -28
- package/dist/db/helpers.js +19 -149
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +4 -0
- package/dist/db/init.js +3 -2
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -54
- package/dist/db/migration/importCollections.d.ts +1 -1
- package/dist/db/migration/importCollections.js +22 -6
- package/dist/db/migration/shared.d.ts +0 -4
- package/dist/db/migration/shared.js +0 -7
- package/dist/db/migration/transform.d.ts +2 -0
- package/dist/db/migration/transform.js +23 -0
- package/dist/db/pg/client.js +4 -0
- package/dist/db/pg/filters/edges.d.ts +1 -1
- package/dist/db/pg/filters/edges.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +1 -0
- package/dist/db/pg/filters/posts.js +11 -1
- package/dist/db/pg/map/filters.js +5 -0
- package/dist/db/pg/map/relations.d.ts +1 -1
- package/dist/db/pg/map/relations.js +89 -41
- package/dist/db/pg/migrate.d.ts +23 -0
- package/dist/db/pg/migrate.js +87 -1
- package/dist/db/pg/schema/documents.d.ts +143 -0
- package/dist/db/pg/schema/documents.js +22 -1
- package/dist/db/pg/schema/edges.d.ts +1 -0
- package/dist/db/pg/schema/edges.js +2 -1
- package/dist/db/pg/schema/index.d.ts +143 -0
- package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
- package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
- package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
- package/dist/db/pg/sql/meta/0007_snapshot.json +4179 -0
- package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
- package/dist/db/pg/sql/meta/_journal.json +21 -0
- package/dist/db/replaceOrigin.js +6 -0
- package/dist/db/types.d.ts +0 -4
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.js +54 -33
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mapping.js +2 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/inviteLinks/helpers.d.ts +4 -4
- package/dist/jams/cache.d.ts +1 -1
- package/dist/jams/cache.js +2 -1
- package/dist/jams/finders.d.ts +2 -1
- package/dist/jams/finders.js +18 -7
- package/dist/jams/helpers.d.ts +4 -0
- package/dist/jams/index.d.ts +4 -3
- package/dist/jams/index.js +20 -13
- package/dist/jams/livekit.d.ts +46 -8
- package/dist/jams/livekit.js +103 -21
- package/dist/jams/mapping.d.ts +14 -4
- package/dist/jams/mutations.d.ts +2 -0
- package/dist/jams/rtmp.d.ts +5 -0
- package/dist/jams/rtmp.js +8 -0
- package/dist/jams/token.d.ts +3 -3
- package/dist/jams/token.js +15 -12
- package/dist/jams/waitingRoom.d.ts +6 -6
- package/dist/jams/waitingRoom.js +24 -23
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.js +4 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
- package/dist/notifications/helpers.js +6 -2
- package/dist/notifications/push.js +11 -4
- package/dist/plugins/helpers.d.ts +1 -0
- package/dist/plugins/helpers.js +1 -8
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +41 -4
- package/dist/plugins/install.d.ts +20 -0
- package/dist/plugins/install.js +223 -0
- package/dist/plugins/state.d.ts +4 -0
- package/dist/plugins/state.js +29 -0
- package/dist/posts/eventAgenda.d.ts +165 -0
- package/dist/posts/eventAgenda.js +120 -0
- package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
- package/dist/posts/eventOccurrenceJobs.js +23 -0
- package/dist/posts/eventOccurrences.d.ts +4 -0
- package/dist/posts/eventOccurrences.js +40 -0
- package/dist/posts/finders.d.ts +32 -8
- package/dist/posts/finders.js +27 -45
- package/dist/posts/helpers/filters.js +1 -1
- package/dist/posts/helpers/index.d.ts +102 -16
- package/dist/posts/helpers/index.js +33 -20
- package/dist/posts/index.d.ts +3 -0
- package/dist/posts/index.js +3 -0
- package/dist/posts/mapping.d.ts +275 -0
- package/dist/posts/mapping.js +37 -3
- package/dist/posts/mutations.d.ts +1 -1
- package/dist/posts/mutations.js +29 -18
- package/dist/posts/rsvpConfirmationEmail.js +2 -1
- package/dist/posts/unseenCounts.d.ts +2 -0
- package/dist/posts/unseenCounts.js +25 -8
- package/dist/profiles/cache.d.ts +3 -1
- package/dist/profiles/cache.js +9 -1
- package/dist/profiles/helpers.d.ts +5 -5
- package/dist/profiles/index.d.ts +1 -1
- package/dist/profiles/index.js +1 -1
- package/dist/profiles/mapping.d.ts +5 -5
- package/dist/profiles/mutations.js +12 -14
- package/dist/pushSubscriptions/helpers.d.ts +2 -2
- package/dist/pushSubscriptions/mutations.js +13 -1
- package/dist/reports/helpers.d.ts +6 -6
- package/dist/roles/defaults.js +1 -0
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +15 -8
- package/dist/stats/finders.d.ts +1692 -142
- package/dist/stats/mapping.d.ts +21 -0
- package/package.json +4 -9
- package/dist/db/arango.d.ts +0 -2
- package/dist/db/arango.js +0 -110
- package/dist/db/migration/autoMigrate.d.ts +0 -2
- package/dist/db/migration/autoMigrate.js +0 -111
- package/dist/db/migration/cli.d.ts +0 -1
- package/dist/db/migration/cli.js +0 -56
- package/dist/db/migration/exportArango.d.ts +0 -4
- package/dist/db/migration/exportArango.js +0 -80
|
@@ -3,9 +3,9 @@ export declare const profileAccessTokenConnector: (db: PgDb, from: {
|
|
|
3
3
|
id: string;
|
|
4
4
|
}, to: {
|
|
5
5
|
id: string;
|
|
6
|
-
}, data?: {
|
|
6
|
+
}, data?: object & {
|
|
7
7
|
id?: string;
|
|
8
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
8
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
9
9
|
_from: string;
|
|
10
10
|
_to: string;
|
|
11
11
|
}>>;
|
|
@@ -67,10 +67,22 @@ export const createSignedServiceToken = async ({ scopes, name, description, expi
|
|
|
67
67
|
expirationTime,
|
|
68
68
|
});
|
|
69
69
|
export const createSignedGuestPass = async (profile, expirationTime = '1d') => {
|
|
70
|
-
var _a
|
|
70
|
+
var _a;
|
|
71
71
|
if (!((_a = profile.guestData) === null || _a === void 0 ? void 0 : _a.resource)) {
|
|
72
72
|
throw new Error('Guest pass requires a resource');
|
|
73
73
|
}
|
|
74
|
+
const resource = profile.guestData.resource;
|
|
75
|
+
// Jam chat resolves message authors via profile GET; guests need a profiles
|
|
76
|
+
// read scope so ensureProfileCapabilities succeeds after ensureAccess.
|
|
77
|
+
const scopes = resource.type === 'jams'
|
|
78
|
+
? [
|
|
79
|
+
{ scopeLevel: 'read', resource },
|
|
80
|
+
{
|
|
81
|
+
scopeLevel: 'read',
|
|
82
|
+
resource: { type: 'profiles', id: '*' },
|
|
83
|
+
},
|
|
84
|
+
]
|
|
85
|
+
: [{ scopeLevel: 'read', resource }];
|
|
74
86
|
return createSignedAccessToken({
|
|
75
87
|
profile,
|
|
76
88
|
name: profile.handle,
|
|
@@ -78,12 +90,7 @@ export const createSignedGuestPass = async (profile, expirationTime = '1d') => {
|
|
|
78
90
|
identities: {
|
|
79
91
|
profile: profile.id,
|
|
80
92
|
},
|
|
81
|
-
scopes
|
|
82
|
-
{
|
|
83
|
-
scopeLevel: 'read',
|
|
84
|
-
resource: (_b = profile.guestData) === null || _b === void 0 ? void 0 : _b.resource,
|
|
85
|
-
},
|
|
86
|
-
],
|
|
93
|
+
scopes,
|
|
87
94
|
},
|
|
88
95
|
expirationTime,
|
|
89
96
|
});
|
|
@@ -13,9 +13,9 @@ export declare const giveControl: (db: import("../db").PgDb, from: {
|
|
|
13
13
|
id: string;
|
|
14
14
|
}, to: {
|
|
15
15
|
id: string;
|
|
16
|
-
}, data?: {
|
|
16
|
+
}, data?: object & {
|
|
17
17
|
id?: string;
|
|
18
|
-
}) => Promise<import("../db/pg/map").WithId<{
|
|
18
|
+
}) => Promise<import("../db/pg/map").WithId<object & {
|
|
19
19
|
_from: string;
|
|
20
20
|
_to: string;
|
|
21
21
|
}>>;
|
package/dist/analytics/cache.js
CHANGED
|
@@ -4,11 +4,11 @@ const OPEN_DAY_TTL_SEC = 60 * 60;
|
|
|
4
4
|
const CLOSED_RANGE_TTL_SEC = 60 * 60 * 6;
|
|
5
5
|
export const analyticsCacheKey = (section, from, to) => `${KEY_PREFIX}${section}:${from}:${to}`;
|
|
6
6
|
export const getAnalyticsCache = async (key) => {
|
|
7
|
-
const redis = await getSharedConnection();
|
|
8
|
-
const raw = await redis.get(key);
|
|
9
|
-
if (!raw)
|
|
10
|
-
return undefined;
|
|
11
7
|
try {
|
|
8
|
+
const redis = await getSharedConnection();
|
|
9
|
+
const raw = await redis.get(key);
|
|
10
|
+
if (!raw)
|
|
11
|
+
return undefined;
|
|
12
12
|
return JSON.parse(raw);
|
|
13
13
|
}
|
|
14
14
|
catch (_a) {
|
|
@@ -16,9 +16,14 @@ export const getAnalyticsCache = async (key) => {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
export const setAnalyticsCache = async (key, value, opts) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
try {
|
|
20
|
+
const redis = await getSharedConnection();
|
|
21
|
+
const ttl = (opts === null || opts === void 0 ? void 0 : opts.includesToday) ? OPEN_DAY_TTL_SEC : CLOSED_RANGE_TTL_SEC;
|
|
22
|
+
await redis.set(key, JSON.stringify(value), { EX: ttl });
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
// Overview still returns; Redis must not 500 the request.
|
|
26
|
+
}
|
|
22
27
|
};
|
|
23
28
|
export const invalidateAnalyticsCache = async () => {
|
|
24
29
|
const redis = await getSharedConnection();
|
|
@@ -73,12 +73,12 @@ const cumulativeGrowth = (points, series) => {
|
|
|
73
73
|
return { label: p.label, values: Object.assign({}, running) };
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
|
-
const createDoc = () => new PDFDocument({
|
|
76
|
+
const createDoc = (communityName) => new PDFDocument({
|
|
77
77
|
size: 'LETTER',
|
|
78
78
|
margin: MARGIN,
|
|
79
79
|
compress: false,
|
|
80
80
|
info: {
|
|
81
|
-
Title:
|
|
81
|
+
Title: `${communityName} analytics report`,
|
|
82
82
|
Author: 'OpenPeeps',
|
|
83
83
|
},
|
|
84
84
|
});
|
|
@@ -788,7 +788,7 @@ const drawGroupsPage = (layout, overview) => {
|
|
|
788
788
|
};
|
|
789
789
|
/** Multi-page visual PDF mirroring the analytics tabs. */
|
|
790
790
|
export const buildAnalyticsPdf = async (data) => {
|
|
791
|
-
const doc = createDoc();
|
|
791
|
+
const doc = createDoc(data.communityName);
|
|
792
792
|
const pending = bufferFromDoc(doc);
|
|
793
793
|
const period = `${data.overview.range.from} to ${data.overview.range.to}`;
|
|
794
794
|
const layout = {
|
|
@@ -800,8 +800,9 @@ export const buildAnalyticsPdf = async (data) => {
|
|
|
800
800
|
};
|
|
801
801
|
// Cover strip on first page before section chrome
|
|
802
802
|
doc.fontSize(10).fillColor(COLORS.muted).font('Helvetica');
|
|
803
|
-
writeText(doc,
|
|
803
|
+
writeText(doc, `${data.communityName} - Community analytics`, MARGIN, layout.y, {
|
|
804
804
|
width: CONTENT_WIDTH,
|
|
805
|
+
ellipsis: true,
|
|
805
806
|
});
|
|
806
807
|
layout.y += 16;
|
|
807
808
|
doc.fontSize(22).fillColor(COLORS.ink).font('Helvetica-Bold');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Group body fields used to decide public vs private for analytics. */
|
|
2
|
+
export type AnalyticsGroupCapabilities = {
|
|
3
|
+
capabilities?: {
|
|
4
|
+
none?: {
|
|
5
|
+
add?: string[];
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Public groups grant `core-groups-read` to role `none`. Missing capabilities
|
|
11
|
+
* means private — same rule as the analytics group tables.
|
|
12
|
+
*/
|
|
13
|
+
export declare const isPublicAnalyticsGroup: (body: AnalyticsGroupCapabilities) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Top-posts cards show author + snippet. Exclude DMs and any post linked to a
|
|
16
|
+
* private group. A post with no group links is eligible when not `direct`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const isAnalyticsTopPostEligible: (visibility: string, linkedGroupBodies: AnalyticsGroupCapabilities[]) => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public groups grant `core-groups-read` to role `none`. Missing capabilities
|
|
3
|
+
* means private — same rule as the analytics group tables.
|
|
4
|
+
*/
|
|
5
|
+
export const isPublicAnalyticsGroup = (body) => { var _a, _b, _c; return ((_c = (_b = (_a = body.capabilities) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : []).includes('core-groups-read'); };
|
|
6
|
+
/**
|
|
7
|
+
* Top-posts cards show author + snippet. Exclude DMs and any post linked to a
|
|
8
|
+
* private group. A post with no group links is eligible when not `direct`.
|
|
9
|
+
*/
|
|
10
|
+
export const isAnalyticsTopPostEligible = (visibility, linkedGroupBodies) => visibility !== 'direct' && linkedGroupBodies.every(isPublicAnalyticsGroup);
|
package/dist/analytics/read.js
CHANGED
|
@@ -6,6 +6,7 @@ import { groups, posts, profiles } from '../db/pg/schema/documents.js';
|
|
|
6
6
|
import { analyticsCacheKey, getAnalyticsCache, setAnalyticsCache, } from './cache.js';
|
|
7
7
|
import { aggregateSeriesIntoBuckets, eachUtcDay, resolveAnalyticsRange, selectChartBuckets, } from './dateRange.js';
|
|
8
8
|
import { metricCard, sumSeries, averageSeries } from './metrics.js';
|
|
9
|
+
import { isPublicAnalyticsGroup } from './privacy.js';
|
|
9
10
|
const POST_TYPE_KEYS = ['jam', 'article', 'note', 'poll', 'event'];
|
|
10
11
|
const todayString = () => formatISO(startOfDay(new Date()), { representation: 'date' });
|
|
11
12
|
const includesToday = (to) => to >= todayString();
|
|
@@ -108,12 +109,7 @@ const latestCompiledAt = async (from, to) => {
|
|
|
108
109
|
.limit(1);
|
|
109
110
|
return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.compiledAt) !== null && _b !== void 0 ? _b : null;
|
|
110
111
|
};
|
|
111
|
-
const groupVisibility = (body) =>
|
|
112
|
-
var _a, _b, _c;
|
|
113
|
-
return ((_c = (_b = (_a = body.capabilities) === null || _a === void 0 ? void 0 : _a.none) === null || _b === void 0 ? void 0 : _b.add) !== null && _c !== void 0 ? _c : []).includes('core-groups-read')
|
|
114
|
-
? 'public'
|
|
115
|
-
: 'private';
|
|
116
|
-
};
|
|
112
|
+
const groupVisibility = (body) => isPublicAnalyticsGroup(body) ? 'public' : 'private';
|
|
117
113
|
const groupDisplayName = (body, handle) => { var _a, _b, _c; return (_c = (_b = (_a = body.name) !== null && _a !== void 0 ? _a : body.displayName) !== null && _b !== void 0 ? _b : handle) !== null && _c !== void 0 ? _c : undefined; };
|
|
118
114
|
const enrichGroupRows = async (rows, from, to) => {
|
|
119
115
|
if (rows.length === 0)
|
|
@@ -410,6 +406,11 @@ const topMembers = async (from, to, limit = 10) => {
|
|
|
410
406
|
});
|
|
411
407
|
});
|
|
412
408
|
};
|
|
409
|
+
/**
|
|
410
|
+
* Top posts must not expose DM content or private-group posts (snippets +
|
|
411
|
+
* authors). SQL mirrors {@link isAnalyticsTopPostEligible} /
|
|
412
|
+
* {@link isPublicAnalyticsGroup}.
|
|
413
|
+
*/
|
|
413
414
|
const topPostsByViews = async (from, to, limit = 10) => {
|
|
414
415
|
const db = await database();
|
|
415
416
|
const rows = await db
|
|
@@ -423,9 +424,18 @@ const topPostsByViews = async (from, to, limit = 10) => {
|
|
|
423
424
|
profileBody: profiles.body,
|
|
424
425
|
})
|
|
425
426
|
.from(analyticsPostViewsDaily)
|
|
426
|
-
.
|
|
427
|
+
.innerJoin(posts, sql `${posts.id}::text = ${analyticsPostViewsDaily.postId}`)
|
|
427
428
|
.leftJoin(profiles, sql `${profiles.id}::text = ${posts.creatorId}`)
|
|
428
|
-
.where(and(gte(analyticsPostViewsDaily.day, from), lte(analyticsPostViewsDaily.day, to)
|
|
429
|
+
.where(and(gte(analyticsPostViewsDaily.day, from), lte(analyticsPostViewsDaily.day, to), sql `${posts.visibility} <> 'direct'`, sql `not exists (
|
|
430
|
+
select 1
|
|
431
|
+
from post_groups pg
|
|
432
|
+
inner join groups g on g.id::text = pg.to_id
|
|
433
|
+
where pg.from_id = ${posts.id}::text
|
|
434
|
+
and not coalesce(
|
|
435
|
+
g.body->'capabilities'->'none'->'add' ? 'core-groups-read',
|
|
436
|
+
false
|
|
437
|
+
)
|
|
438
|
+
)`))
|
|
429
439
|
.groupBy(analyticsPostViewsDaily.postId, posts.body, posts.type, profiles.handle, profiles.body)
|
|
430
440
|
.orderBy(desc(sum(analyticsPostViewsDaily.uniqueViewers)))
|
|
431
441
|
.limit(limit);
|
|
@@ -441,7 +451,9 @@ const topPostsByViews = async (from, to, limit = 10) => {
|
|
|
441
451
|
const profileBody = ((_h = r.profileBody) !== null && _h !== void 0 ? _h : {});
|
|
442
452
|
return {
|
|
443
453
|
postId: r.postId,
|
|
444
|
-
snippet: content
|
|
454
|
+
snippet: typeof content === 'string'
|
|
455
|
+
? content.slice(0, 120) || undefined
|
|
456
|
+
: undefined,
|
|
445
457
|
authorHandle: (_j = r.handle) !== null && _j !== void 0 ? _j : undefined,
|
|
446
458
|
authorDisplayName: (_l = (_k = profileBody.displayName) !== null && _k !== void 0 ? _k : profileBody.name) !== null && _l !== void 0 ? _l : undefined,
|
|
447
459
|
postType,
|
|
@@ -461,7 +473,7 @@ const withCache = async (section, from, to, build) => {
|
|
|
461
473
|
};
|
|
462
474
|
export const getAnalyticsOverview = async (query = {}) => {
|
|
463
475
|
const range = await resolveQueryRange(query);
|
|
464
|
-
return withCache('overview-
|
|
476
|
+
return withCache('overview-v6', range.from, range.to, async () => {
|
|
465
477
|
var _a, _b;
|
|
466
478
|
const [activeMembersSeries, postsSeries, likesSeries, commentsSeries, postsByTypeDaily, topGroupRows, groupGrowth, topPostRows, topMemberRows, compiledAt, totalMembers, totalGroups, allTimePosts, prevActive, prevPosts, prevTotalMembers, prevTotalGroups, prevAllTimePosts,] = await Promise.all([
|
|
467
479
|
loadTotalsSeries(range.from, range.to, 'activeMembers'),
|
|
@@ -558,7 +570,7 @@ export const getAnalyticsOverview = async (query = {}) => {
|
|
|
558
570
|
};
|
|
559
571
|
export const getAnalyticsGrowth = async (query = {}) => {
|
|
560
572
|
const range = await resolveQueryRange(query);
|
|
561
|
-
return withCache('growth-
|
|
573
|
+
return withCache('growth-v7', range.from, range.to, async () => {
|
|
562
574
|
const db = await database();
|
|
563
575
|
const mauFrom = rollingMauFrom(range.to);
|
|
564
576
|
const prevMauFrom = rollingMauFrom(range.previousTo);
|
|
@@ -576,6 +588,7 @@ export const getAnalyticsGrowth = async (query = {}) => {
|
|
|
576
588
|
from profiles p
|
|
577
589
|
left join invite_link_redeemers r on r.to_id = p.id::text
|
|
578
590
|
where p.deleted_at is null
|
|
591
|
+
and p.type <> 'guest'
|
|
579
592
|
and p.created_at >= ${`${range.from}T00:00:00.000Z`}
|
|
580
593
|
and p.created_at <= ${`${range.to}T23:59:59.999Z`}
|
|
581
594
|
order by p.created_at desc
|
|
@@ -74,7 +74,7 @@ export declare const buildAnalyticsBoardReport: (query?: AnalyticsDateQuery) =>
|
|
|
74
74
|
event: number;
|
|
75
75
|
}[];
|
|
76
76
|
postTypes: {
|
|
77
|
-
type: "
|
|
77
|
+
type: "poll" | "note" | "event" | "article" | "jam";
|
|
78
78
|
count: number;
|
|
79
79
|
}[];
|
|
80
80
|
activeUsersSeries: {
|
package/dist/analytics/report.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { endOfMonth, formatISO, startOfMonth, subMonths } from 'date-fns';
|
|
2
2
|
import { eq } from 'drizzle-orm';
|
|
3
3
|
import { uuidv7 } from 'uuidv7';
|
|
4
|
+
import { communityConfig } from '../config/index.js';
|
|
4
5
|
import { sendEmailQueue } from '../email/index.js';
|
|
5
6
|
import { database } from '../db/index.js';
|
|
6
7
|
import { analyticsReportDeliveries } from '../db/pg/schema/analytics.js';
|
|
@@ -25,10 +26,11 @@ const narrativeSentence = (label, value, deltaPct) => {
|
|
|
25
26
|
};
|
|
26
27
|
/** Board-ready report: plain-text email body + visual multi-page PDF. */
|
|
27
28
|
export const buildAnalyticsBoardReport = async (query = {}) => {
|
|
28
|
-
const [overview, growth, engagement] = await Promise.all([
|
|
29
|
+
const [overview, growth, engagement, community] = await Promise.all([
|
|
29
30
|
getAnalyticsOverview(query),
|
|
30
31
|
getAnalyticsGrowth(query),
|
|
31
32
|
getAnalyticsEngagement(query),
|
|
33
|
+
communityConfig(),
|
|
32
34
|
]);
|
|
33
35
|
const from = overview.range.from;
|
|
34
36
|
const to = overview.range.to;
|
|
@@ -51,7 +53,12 @@ export const buildAnalyticsBoardReport = async (query = {}) => {
|
|
|
51
53
|
'',
|
|
52
54
|
...summary,
|
|
53
55
|
].join('\n');
|
|
54
|
-
const pdf = await buildAnalyticsPdf({
|
|
56
|
+
const pdf = await buildAnalyticsPdf({
|
|
57
|
+
communityName: community.info.name,
|
|
58
|
+
overview,
|
|
59
|
+
growth,
|
|
60
|
+
engagement,
|
|
61
|
+
});
|
|
55
62
|
return { text, pdf, overview, growth, engagement };
|
|
56
63
|
};
|
|
57
64
|
/** @deprecated Prefer buildAnalyticsBoardReport().pdf — kept for tests. */
|
package/dist/backups/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import extract from 'extract-zip';
|
|
|
9
9
|
import { collectionInfos } from '../db/index.js';
|
|
10
10
|
import { communityConfig, config } from '../config/index.js';
|
|
11
11
|
import { exportAllPostgresCollections, importAllArangoCollections, importAllPostgresCollections, } from '../db/migration/importCollections.js';
|
|
12
|
+
import { getLatestSchemaVersion } from '../db/pg/migrate.js';
|
|
12
13
|
import { replaceOrigin } from '../db/replaceOrigin.js';
|
|
13
14
|
import { logger } from '../log/index.js';
|
|
14
15
|
import { setDefaultRoles } from '../roles/index.js';
|
|
@@ -153,10 +154,10 @@ const assertBackupExtracted = async (tempDir) => {
|
|
|
153
154
|
}
|
|
154
155
|
log.info(`Found ${jsonlFiles.length} collection backup files in archive`);
|
|
155
156
|
};
|
|
156
|
-
const restoreDatabaseFromBackup = async (collectionsDir, databaseType) => {
|
|
157
|
+
const restoreDatabaseFromBackup = async (collectionsDir, databaseType, schemaVersion) => {
|
|
157
158
|
log.info('Restoring %s database from JSONL collections', databaseType);
|
|
158
159
|
const { total } = databaseType === 'postgres'
|
|
159
|
-
? await importAllPostgresCollections(collectionsDir)
|
|
160
|
+
? await importAllPostgresCollections(collectionsDir, schemaVersion)
|
|
160
161
|
: await importAllArangoCollections(collectionsDir);
|
|
161
162
|
if (total === 0) {
|
|
162
163
|
throw new Error('Backup restore completed with zero rows; archive may be empty or corrupt');
|
|
@@ -189,6 +190,8 @@ export const createBackup = async () => {
|
|
|
189
190
|
await writeFile(join(metaDir, 'collectionInfos.json'), JSON.stringify(collectionInfos, null, 2));
|
|
190
191
|
await writeFile(join(backupDir, 'metadata.json'), JSON.stringify({
|
|
191
192
|
databaseType: 'postgres',
|
|
193
|
+
createdAt: new Date().toISOString(),
|
|
194
|
+
schemaVersion: getLatestSchemaVersion(),
|
|
192
195
|
config: {
|
|
193
196
|
hostname: hostnameFromServerHost(coreConfig.server.host),
|
|
194
197
|
},
|
|
@@ -254,7 +257,7 @@ export const restoreBackups = async (zipFilePath) => {
|
|
|
254
257
|
await cp(join(tempDir, 'logs'), coreConfig.logs.local.path, {
|
|
255
258
|
recursive: true,
|
|
256
259
|
});
|
|
257
|
-
await restoreDatabaseFromBackup(collectionsDir, databaseType);
|
|
260
|
+
await restoreDatabaseFromBackup(collectionsDir, databaseType, backupMetadata === null || backupMetadata === void 0 ? void 0 : backupMetadata.schemaVersion);
|
|
258
261
|
// Repoint the backup's absolute URLs at this server's full origin (scheme +
|
|
259
262
|
// host + port). Matching by the backup hostname means a prod backup on
|
|
260
263
|
// `https://host` restores cleanly onto `http://localhost:5174` without
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export type BackupDatabaseType = 'arango' | 'postgres';
|
|
2
2
|
export type BackupMetadata = {
|
|
3
3
|
databaseType?: BackupDatabaseType;
|
|
4
|
+
/** When this backup archive was created (ISO-8601). */
|
|
5
|
+
createdAt?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Drizzle journal tag the database was on when the backup was created
|
|
8
|
+
* (e.g. `0007_shallow_oracle`). Omitted on legacy Arango archives.
|
|
9
|
+
*/
|
|
10
|
+
schemaVersion?: string;
|
|
4
11
|
config?: {
|
|
5
12
|
hostname?: string;
|
|
6
13
|
};
|
|
@@ -3,12 +3,6 @@ dotenv.config();
|
|
|
3
3
|
export const defaultCommunityConfig = {
|
|
4
4
|
theme: {
|
|
5
5
|
base: 'OpenpeepsLight',
|
|
6
|
-
primaryHex: '#15678a',
|
|
7
|
-
logoFull: '/img/logo-full.png',
|
|
8
|
-
logoSmall: '/img/logo-small.png',
|
|
9
|
-
defaultProfileAvatar: '/img/default-avatar.png',
|
|
10
|
-
defaultGroupAvatar: '/img/default-group-avatar.svg',
|
|
11
|
-
backgroundAuth: '/img/background-auth.png',
|
|
12
6
|
icon: '/img/icon.svg',
|
|
13
7
|
light: {
|
|
14
8
|
primaryHex: '#15678a',
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import dotenv from 'dotenv';
|
|
2
2
|
dotenv.config();
|
|
3
3
|
export default {
|
|
4
|
-
url: process.env.DB_URL || 'http://localhost:8529',
|
|
5
|
-
databaseName: process.env.DB_NAME || undefined,
|
|
6
4
|
databaseUrl: process.env.DATABASE_URL ||
|
|
7
5
|
'postgresql://openpeeps:openpeeps@localhost:5432/openpeeps',
|
|
8
6
|
};
|
package/dist/config/index.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export declare const config: <T = {
|
|
|
24
24
|
maxProfiles?: number | undefined;
|
|
25
25
|
};
|
|
26
26
|
db: {
|
|
27
|
-
url: string;
|
|
28
27
|
databaseUrl: string;
|
|
28
|
+
url?: string | undefined;
|
|
29
29
|
databaseName?: string | undefined;
|
|
30
30
|
};
|
|
31
31
|
redis: {
|
|
@@ -95,6 +95,8 @@ export declare const config: <T = {
|
|
|
95
95
|
};
|
|
96
96
|
sso: {
|
|
97
97
|
generic: {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
98
100
|
userProfileRequest: {
|
|
99
101
|
url: string;
|
|
100
102
|
authHeader?: string | undefined;
|
|
@@ -105,6 +107,7 @@ export declare const config: <T = {
|
|
|
105
107
|
avatar?: string | undefined;
|
|
106
108
|
displayName?: string | undefined;
|
|
107
109
|
};
|
|
110
|
+
loginLink?: string | undefined;
|
|
108
111
|
createAccounts?: boolean | undefined;
|
|
109
112
|
createProfiles?: boolean | undefined;
|
|
110
113
|
}[];
|
|
@@ -126,6 +129,7 @@ export declare const config: <T = {
|
|
|
126
129
|
} | undefined;
|
|
127
130
|
approvalRequired?: boolean | undefined;
|
|
128
131
|
}[];
|
|
132
|
+
onlySSO?: boolean | undefined;
|
|
129
133
|
};
|
|
130
134
|
services: {
|
|
131
135
|
sentry: {
|
|
@@ -171,7 +175,6 @@ export declare const config: <T = {
|
|
|
171
175
|
export declare const communityConfig: () => Promise<{
|
|
172
176
|
theme: {
|
|
173
177
|
base: string;
|
|
174
|
-
primaryHex: string;
|
|
175
178
|
light: {
|
|
176
179
|
primaryHex: string;
|
|
177
180
|
secondaryHex?: string | undefined;
|
|
@@ -198,12 +201,6 @@ export declare const communityConfig: () => Promise<{
|
|
|
198
201
|
};
|
|
199
202
|
icon?: string | undefined;
|
|
200
203
|
mobileIcon?: string | undefined;
|
|
201
|
-
logoFull?: string | undefined;
|
|
202
|
-
logoSmall?: string | undefined;
|
|
203
|
-
defaultProfileAvatar?: string | undefined;
|
|
204
|
-
defaultGroupAvatar?: string | undefined;
|
|
205
|
-
backgroundAuth?: string | undefined;
|
|
206
|
-
background?: string | undefined;
|
|
207
204
|
};
|
|
208
205
|
info: {
|
|
209
206
|
name: string;
|
|
@@ -253,8 +250,8 @@ export declare const sanitizedConfigWithDefaults: <T = {
|
|
|
253
250
|
maxProfiles?: number | undefined;
|
|
254
251
|
};
|
|
255
252
|
db: {
|
|
256
|
-
url: string;
|
|
257
253
|
databaseUrl: string;
|
|
254
|
+
url?: string | undefined;
|
|
258
255
|
databaseName?: string | undefined;
|
|
259
256
|
};
|
|
260
257
|
redis: {
|
|
@@ -324,6 +321,8 @@ export declare const sanitizedConfigWithDefaults: <T = {
|
|
|
324
321
|
};
|
|
325
322
|
sso: {
|
|
326
323
|
generic: {
|
|
324
|
+
id: string;
|
|
325
|
+
name: string;
|
|
327
326
|
userProfileRequest: {
|
|
328
327
|
url: string;
|
|
329
328
|
authHeader?: string | undefined;
|
|
@@ -334,6 +333,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
|
|
|
334
333
|
avatar?: string | undefined;
|
|
335
334
|
displayName?: string | undefined;
|
|
336
335
|
};
|
|
336
|
+
loginLink?: string | undefined;
|
|
337
337
|
createAccounts?: boolean | undefined;
|
|
338
338
|
createProfiles?: boolean | undefined;
|
|
339
339
|
}[];
|
|
@@ -355,6 +355,7 @@ export declare const sanitizedConfigWithDefaults: <T = {
|
|
|
355
355
|
} | undefined;
|
|
356
356
|
approvalRequired?: boolean | undefined;
|
|
357
357
|
}[];
|
|
358
|
+
onlySSO?: boolean | undefined;
|
|
358
359
|
};
|
|
359
360
|
services: {
|
|
360
361
|
sentry: {
|
package/dist/db/helpers.d.ts
CHANGED
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Document, DocumentMetadata, Edge, EdgeMetadata, Patch } from 'arangojs/documents';
|
|
4
|
-
import type { Base } from '@openpeepshq/common/types';
|
|
5
|
-
import { type Filter } from '@openpeepshq/arango-querybuilder';
|
|
6
|
-
import type { CollectionInfo, ViewInfo } from './pg/map/queryTypes';
|
|
1
|
+
import type { FilterAndTransformOptions, ObjectFilter } from './types';
|
|
2
|
+
import type { CollectionInfo } from './pg/map/queryTypes';
|
|
7
3
|
import type { Mapping, ObjectSort, WithId } from './pg/map';
|
|
8
4
|
import type { PgQueryResult } from './pg/map/types';
|
|
9
5
|
import type { PgDb } from './pg/client';
|
|
10
|
-
import { EdgeDefinitionOptions } from 'arangojs/graphs';
|
|
11
|
-
import { EnsureIndexOptions } from 'arangojs/indexes';
|
|
12
|
-
import { FilterAndTransformOptions, ObjectFilter, UserFunctionDefinition } from './types';
|
|
13
|
-
export declare const addModificationDates: (collection: DocumentCollection) => Promise<void>;
|
|
14
|
-
export declare const addIndices: (collection: DocumentCollection | EdgeCollection, indices: EnsureIndexOptions[]) => Promise<void>;
|
|
15
|
-
export declare const ensureIndexedCollection: <T extends Record<string, unknown>>(db: Database, collectionInfo: CollectionInfo) => Promise<DocumentCollection<Base<T>, T>>;
|
|
16
|
-
export declare const ensureView: (db: Database, viewInfo: ViewInfo) => Promise<import("arangojs/views").View | undefined>;
|
|
17
|
-
export declare const ensureGraph: (db: Database, name: string, edgeDefinitions: EdgeDefinitionOptions[]) => Promise<import("arangojs/graphs").Graph>;
|
|
18
|
-
export declare const ensureFunction: (db: Database, { name, dbFunction }: UserFunctionDefinition) => Promise<void>;
|
|
19
|
-
export declare const createEdge: <T extends object | {} = {}>(collection: EdgeCollection<Base<T>, T>, document: T & EdgeMetadata & {
|
|
20
|
-
id?: string;
|
|
21
|
-
}) => Promise<WithId<Base<T>>>;
|
|
22
|
-
export declare const updateEdge: <T extends Record<string, unknown> & EdgeMetadata>(collection: EdgeCollection<Base<T>>, documentKey: string, document: Patch<Document<Base<T>>>) => Promise<Document<Base<T>> | undefined>;
|
|
23
|
-
export declare const deleteEdge: <T extends Record<string, unknown> & Base<EdgeMetadata>>(collection: EdgeCollection<Base<T>>, documentKey: string) => Promise<DocumentMetadata & {
|
|
24
|
-
old?: Edge<Base<T>> | undefined;
|
|
25
|
-
}>;
|
|
26
|
-
export declare const findOneBy: <O extends object>(db: Database, collectionInfo: CollectionInfo) => (filter: Filter) => Promise<O | undefined>;
|
|
27
|
-
export declare const edgeCollections: (database: Database) => Promise<(DocumentCollection<any, any> & EdgeCollection<any, any>)[]>;
|
|
28
6
|
export declare const connector: <F extends {
|
|
29
7
|
id: string;
|
|
30
8
|
}, T extends {
|
|
31
9
|
id: string;
|
|
32
|
-
}, E extends object
|
|
10
|
+
}, E extends object = object>(fromCollectionInfo: CollectionInfo, toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T, data?: E & {
|
|
33
11
|
id?: string;
|
|
34
12
|
}) => Promise<WithId<E & {
|
|
35
13
|
_from: string;
|
|
@@ -39,17 +17,17 @@ export declare const disconnector: <F extends {
|
|
|
39
17
|
id: string;
|
|
40
18
|
}, T extends {
|
|
41
19
|
id: string;
|
|
42
|
-
}>(
|
|
20
|
+
}>(_fromCollectionInfo: CollectionInfo, _toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T) => Promise<void>;
|
|
43
21
|
export declare const connectionUpdater: <F extends {
|
|
44
22
|
id: string;
|
|
45
23
|
}, T extends {
|
|
46
24
|
id: string;
|
|
47
|
-
}, C extends Record<string, unknown> | undefined =
|
|
25
|
+
}, C extends Record<string, unknown> | undefined = Record<string, unknown>>(_fromCollectionInfo: CollectionInfo, _toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T, data?: C) => Promise<void>;
|
|
48
26
|
export declare const connectionFinder: <F extends {
|
|
49
27
|
id: string;
|
|
50
28
|
}, T extends {
|
|
51
29
|
id: string;
|
|
52
|
-
}, C extends Record<string, unknown> =
|
|
30
|
+
}, C extends Record<string, unknown> = Record<string, unknown>>(_fromCollectionInfo: CollectionInfo, _toCollectionInfo: CollectionInfo, edgeCollectionInfo: CollectionInfo) => (db: PgDb, from: F, to: T) => Promise<C | undefined>;
|
|
53
31
|
export declare const filterBefore: <T extends object>(mapping: Mapping<T>, id?: string) => Mapping<T>;
|
|
54
32
|
export declare const filterAfter: <T extends object>(mapping: Mapping<T>, id?: string) => Mapping<T>;
|
|
55
33
|
export declare const addQuerySort: <T extends object>(mapping: Mapping<T>, sort?: ObjectSort) => Mapping<T>;
|