@openpeepshq/core 0.1.34 → 0.1.35

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 (165) hide show
  1. package/dist/accessTokens/finders.js +5 -6
  2. package/dist/accessTokens/mutations.js +1 -1
  3. package/dist/accessTokens/tokens.js +8 -11
  4. package/dist/accounts/helpers.js +6 -2
  5. package/dist/accounts/mutations.js +13 -8
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +1 -2
  9. package/dist/analytics/dateRange.js +3 -5
  10. package/dist/analytics/jobs.js +3 -4
  11. package/dist/analytics/pdfReport.js +45 -61
  12. package/dist/analytics/privacy.js +1 -1
  13. package/dist/analytics/read.js +116 -135
  14. package/dist/analytics/report.d.ts +2 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +13 -16
  18. package/dist/backups/metadata.js +1 -1
  19. package/dist/config/db.js +2 -4
  20. package/dist/config/defaults/community.js +1 -0
  21. package/dist/config/defaults/core.js +13 -8
  22. package/dist/config/index.d.ts +1 -0
  23. package/dist/config/index.js +9 -11
  24. package/dist/db/explorer/query.js +9 -8
  25. package/dist/db/explorer/sql.js +8 -8
  26. package/dist/db/helpers.js +15 -5
  27. package/dist/db/migration/importCollections.js +15 -18
  28. package/dist/db/migration/shared.js +15 -35
  29. package/dist/db/pg/client.js +4 -7
  30. package/dist/db/pg/filters/index.js +1 -1
  31. package/dist/db/pg/filters/posts.d.ts +2 -0
  32. package/dist/db/pg/filters/posts.js +2 -0
  33. package/dist/db/pg/helpers.js +2 -14
  34. package/dist/db/pg/map/filters.js +8 -8
  35. package/dist/db/pg/map/helpers.js +5 -1
  36. package/dist/db/pg/map/index.js +46 -51
  37. package/dist/db/pg/map/mutations.js +56 -21
  38. package/dist/db/pg/map/registry.js +87 -50
  39. package/dist/db/pg/map/relations.js +67 -63
  40. package/dist/db/pg/map/search.js +15 -37
  41. package/dist/db/pg/mappers.js +13 -7
  42. package/dist/db/pg/migrate.js +2 -3
  43. package/dist/db/pg/queries/activity.js +2 -2
  44. package/dist/db/pg/queries/derived.js +8 -12
  45. package/dist/db/pg/schema/documents.js +119 -18
  46. package/dist/db/pg/schema/edges.js +7 -1
  47. package/dist/db/pg/schema/index.js +5 -1
  48. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  49. package/dist/db/pg/sql/meta/_journal.json +8 -1
  50. package/dist/db/replaceOrigin.js +1 -1
  51. package/dist/email/queueStats.js +8 -11
  52. package/dist/email/render.js +7 -4
  53. package/dist/email/send.js +19 -17
  54. package/dist/email/smtpTest.js +10 -6
  55. package/dist/errors/index.js +1 -1
  56. package/dist/events/once.js +2 -4
  57. package/dist/federation/activities.js +1 -2
  58. package/dist/groups/helpers.js +1 -2
  59. package/dist/groups/mutations.js +1 -1
  60. package/dist/hashtags/finders.js +2 -2
  61. package/dist/inviteLinks/mutations.js +2 -3
  62. package/dist/jams/export.js +5 -7
  63. package/dist/jams/finders.js +4 -1
  64. package/dist/jams/health.d.ts +6 -4
  65. package/dist/jams/health.js +15 -11
  66. package/dist/jams/helpers.js +6 -2
  67. package/dist/jams/index.js +2 -2
  68. package/dist/jams/jobs.js +1 -2
  69. package/dist/jams/livekit.js +8 -8
  70. package/dist/jams/recording.js +1 -1
  71. package/dist/jams/token.js +13 -17
  72. package/dist/jobs/index.js +7 -6
  73. package/dist/jobs/jobDetail.js +5 -6
  74. package/dist/jobs/jobLog.js +2 -3
  75. package/dist/lib/streams.js +4 -39
  76. package/dist/lib/zodDeepPartial.d.ts +1 -1
  77. package/dist/lib/zodDeepPartial.js +1 -1
  78. package/dist/log/index.js +13 -29
  79. package/dist/media/index.js +50 -4
  80. package/dist/media/jobs.js +1 -2
  81. package/dist/media/openpeeps/index.js +11 -46
  82. package/dist/media/processing.js +7 -4
  83. package/dist/media/streaming.js +5 -5
  84. package/dist/media/streamingCleanupJobs.js +1 -2
  85. package/dist/media/streamingJobs.js +3 -4
  86. package/dist/media/streamingPrewarm.js +7 -11
  87. package/dist/mediaAttachments/index.js +6 -2
  88. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  89. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  90. package/dist/notifications/defaultNotifications/follow/index.js +14 -17
  91. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  92. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  93. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  94. package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
  95. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  96. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  97. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  98. package/dist/notifications/defaultNotifications/newGroupPost/index.js +6 -7
  99. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  100. package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
  101. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
  102. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  103. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  104. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  105. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  106. package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
  107. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
  108. package/dist/notifications/fcmCredential.js +1 -1
  109. package/dist/notifications/finders.js +1 -1
  110. package/dist/notifications/helpers.js +13 -10
  111. package/dist/notifications/jobs.js +10 -7
  112. package/dist/notifications/mutations.js +4 -1
  113. package/dist/notifications/push.js +11 -16
  114. package/dist/performance/index.js +3 -3
  115. package/dist/plugins/helpers.js +3 -6
  116. package/dist/plugins/index.js +2 -3
  117. package/dist/plugins/install.js +31 -17
  118. package/dist/plugins/pluginAuth.js +3 -4
  119. package/dist/plugins/state.js +2 -3
  120. package/dist/posts/activity.js +1 -2
  121. package/dist/posts/contextClosure.js +1 -2
  122. package/dist/posts/conversationQueries.js +2 -4
  123. package/dist/posts/eventAgenda.js +8 -5
  124. package/dist/posts/eventOccurrences.js +2 -2
  125. package/dist/posts/finders.d.ts +42 -2
  126. package/dist/posts/finders.js +21 -9
  127. package/dist/posts/helpers/filters.js +2 -3
  128. package/dist/posts/helpers/index.d.ts +152 -0
  129. package/dist/posts/helpers/index.js +43 -27
  130. package/dist/posts/mapping.d.ts +546 -14
  131. package/dist/posts/mapping.js +60 -18
  132. package/dist/posts/mutations.d.ts +76 -0
  133. package/dist/posts/mutations.js +46 -31
  134. package/dist/posts/pollEnd.js +3 -6
  135. package/dist/posts/rsvpConfirmationEmail.js +18 -8
  136. package/dist/posts/threadPreview.js +1 -1
  137. package/dist/processingStats/queries.js +6 -7
  138. package/dist/profileSettings/cache.js +1 -2
  139. package/dist/profiles/activitySummary.js +23 -28
  140. package/dist/profiles/cache.js +15 -8
  141. package/dist/profiles/export.js +30 -39
  142. package/dist/profiles/finders.js +7 -5
  143. package/dist/profiles/mutations.js +3 -5
  144. package/dist/redis/connection.js +1 -1
  145. package/dist/reports/helpers.js +7 -3
  146. package/dist/roles/mutations.js +20 -21
  147. package/dist/search/finders.js +15 -3
  148. package/dist/search/helpers.js +1 -1
  149. package/dist/sentry/index.js +9 -11
  150. package/dist/seo/index.d.ts +50 -0
  151. package/dist/seo/index.js +145 -0
  152. package/dist/seo/route.d.ts +18 -0
  153. package/dist/seo/route.js +19 -0
  154. package/dist/server/index.d.ts +1 -0
  155. package/dist/server/index.js +16 -11
  156. package/dist/server/status.js +6 -7
  157. package/dist/session/index.js +2 -2
  158. package/dist/stats/finders.js +13 -4
  159. package/dist/stats/helpers.js +4 -1
  160. package/dist/stats/mapping.d.ts +39 -1
  161. package/dist/stats/mapping.js +9 -2
  162. package/dist/stripe/cache.js +5 -6
  163. package/dist/stripe/connection.js +3 -4
  164. package/dist/stripe/helpers.js +15 -20
  165. package/package.json +5 -6
@@ -27,15 +27,13 @@ export const protocolForServerHost = (host, envProtocol = process.env.SERVER_PRO
27
27
  export const serverProtocol = async () => protocolForServerHost((await config()).server.host);
28
28
  export const serverRootUrl = async () => `${await serverProtocol()}://${(await config()).server.host}`;
29
29
  const lastAccessedFromPostViews = async () => {
30
- var _a;
31
30
  const db = await database();
32
31
  const rows = await db
33
32
  .select({ last: sql `max(${postSeen.createdAt})` })
34
33
  .from(postSeen);
35
- return normalizeComputedDatetime((_a = rows[0]) === null || _a === void 0 ? void 0 : _a.last);
34
+ return normalizeComputedDatetime(rows[0]?.last);
36
35
  };
37
36
  export const serverInfo = () => config().then(async (coreConfig) => {
38
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
39
37
  const [lastAccessed, disk, community] = await Promise.all([
40
38
  lastAccessedFromPostViews(),
41
39
  diskUsage(coreConfig.media.storage.params.path),
@@ -43,7 +41,7 @@ export const serverInfo = () => config().then(async (coreConfig) => {
43
41
  ]);
44
42
  return {
45
43
  version: coreConfig.version,
46
- build: ((_a = process.env.BUILD) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
44
+ build: process.env.BUILD?.trim() || undefined,
47
45
  environment: coreConfig.environment,
48
46
  publicContent: coreConfig.server.publicContent,
49
47
  startedAt: processStartedAt,
@@ -51,7 +49,14 @@ export const serverInfo = () => config().then(async (coreConfig) => {
51
49
  disk,
52
50
  lastAccessed,
53
51
  maxProfiles: coreConfig.server.maxProfiles || undefined,
54
- communityConfig: Object.assign(Object.assign({}, community), { theme: withLegacyThemeRoot(community.theme), settings: Object.assign(Object.assign({}, community.settings), { openRegistrations: !!coreConfig.server.signUpsOpen }) }),
52
+ communityConfig: {
53
+ ...community,
54
+ theme: withLegacyThemeRoot(community.theme),
55
+ settings: {
56
+ ...community.settings,
57
+ openRegistrations: !!coreConfig.server.signUpsOpen,
58
+ },
59
+ },
55
60
  jams: {
56
61
  livekit: {
57
62
  url: coreConfig.jams.livekit.url,
@@ -65,16 +70,16 @@ export const serverInfo = () => config().then(async (coreConfig) => {
65
70
  publicKey: coreConfig.vapid.publicKey,
66
71
  },
67
72
  sentryConfig: {
68
- enabled: !!((_c = (_b = coreConfig.services) === null || _b === void 0 ? void 0 : _b.sentry) === null || _c === void 0 ? void 0 : _c.enabled) &&
69
- !!((_e = (_d = coreConfig.services) === null || _d === void 0 ? void 0 : _d.sentry) === null || _e === void 0 ? void 0 : _e.dsn),
70
- dsn: (_g = (_f = coreConfig.services) === null || _f === void 0 ? void 0 : _f.sentry) === null || _g === void 0 ? void 0 : _g.dsn,
71
- replayEnabled: !!((_j = (_h = coreConfig.services) === null || _h === void 0 ? void 0 : _h.sentry) === null || _j === void 0 ? void 0 : _j.replayEnabled) &&
72
- !!((_l = (_k = coreConfig.services) === null || _k === void 0 ? void 0 : _k.sentry) === null || _l === void 0 ? void 0 : _l.dsn),
73
+ enabled: !!coreConfig.services?.sentry?.enabled &&
74
+ !!coreConfig.services?.sentry?.dsn,
75
+ dsn: coreConfig.services?.sentry?.dsn,
76
+ replayEnabled: !!coreConfig.services?.sentry?.replayEnabled &&
77
+ !!coreConfig.services?.sentry?.dsn,
73
78
  },
74
79
  payments: {
75
80
  stripe: {
76
81
  paidMembership: {
77
- enabled: !!((_p = (_o = (_m = coreConfig.payments) === null || _m === void 0 ? void 0 : _m.stripe) === null || _o === void 0 ? void 0 : _o.paidMembership) === null || _p === void 0 ? void 0 : _p.enabled),
82
+ enabled: !!coreConfig.payments?.stripe?.paidMembership?.enabled,
78
83
  },
79
84
  },
80
85
  },
@@ -2,7 +2,7 @@ import { readdir, stat, statfs } from 'node:fs/promises';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  export const processStartedAt = new Date(Date.now() - process.uptime() * 1000).toISOString();
5
- const FOLDER_SIZE_CACHE_MS = 30000;
5
+ const FOLDER_SIZE_CACHE_MS = 30_000;
6
6
  let folderSizeCache = null;
7
7
  /** Sum of regular files under dir. Skips unreadable entries. */
8
8
  export const folderSize = async (dir) => {
@@ -11,7 +11,7 @@ export const folderSize = async (dir) => {
11
11
  try {
12
12
  entries = await readdir(dir, { withFileTypes: true });
13
13
  }
14
- catch (_a) {
14
+ catch {
15
15
  return 0;
16
16
  }
17
17
  for (const entry of entries) {
@@ -27,7 +27,7 @@ export const folderSize = async (dir) => {
27
27
  total += (await stat(full)).size;
28
28
  }
29
29
  }
30
- catch (_b) {
30
+ catch {
31
31
  // Skip entries we cannot stat (permissions, races).
32
32
  }
33
33
  }
@@ -56,7 +56,7 @@ export const diskUsage = async (mediaPath) => {
56
56
  const folderBytes = await cachedFolderSize(mediaPath);
57
57
  return { folderBytes, totalBytes, freeBytes };
58
58
  }
59
- catch (_a) {
59
+ catch {
60
60
  return null;
61
61
  }
62
62
  };
@@ -85,14 +85,13 @@ export const memoryUsage = (totalBytes = os.totalmem(), freeBytes = os.freemem()
85
85
  };
86
86
  const CPU_SAMPLE_MS = 50;
87
87
  export const hostResources = async (wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) => {
88
- var _a, _b;
89
88
  const memory = memoryUsage();
90
89
  const previous = cpuTimes();
91
90
  await wait(CPU_SAMPLE_MS);
92
91
  const cpuPercent = Math.round(cpuUsedPercent(previous, cpuTimes()) * 10) / 10;
93
92
  return {
94
- memoryUsedBytes: (_a = memory === null || memory === void 0 ? void 0 : memory.usedBytes) !== null && _a !== void 0 ? _a : 0,
95
- memoryTotalBytes: (_b = memory === null || memory === void 0 ? void 0 : memory.totalBytes) !== null && _b !== void 0 ? _b : 0,
93
+ memoryUsedBytes: memory?.usedBytes ?? 0,
94
+ memoryTotalBytes: memory?.totalBytes ?? 0,
96
95
  cpuUsedPercent: cpuPercent,
97
96
  };
98
97
  };
@@ -50,9 +50,9 @@ export const getSessionPresence = async (profileId) => {
50
50
  const connections = Object.entries(raw).flatMap(([connectionId, value]) => {
51
51
  try {
52
52
  const parsed = JSON.parse(value);
53
- return [Object.assign({ connectionId }, parsed)];
53
+ return [{ connectionId, ...parsed }];
54
54
  }
55
- catch (_a) {
55
+ catch {
56
56
  return [];
57
57
  }
58
58
  });
@@ -120,25 +120,34 @@ const createIntervals = (duration) => {
120
120
  start: sub(new Date(), { days: i + 1 }),
121
121
  end: sub(new Date(), { days: i }),
122
122
  }))
123
- .map((interval) => (Object.assign({ name: interval.start.toISOString().split('T')[0] }, interval)));
123
+ .map((interval) => ({
124
+ name: interval.start.toISOString().split('T')[0],
125
+ ...interval,
126
+ }));
124
127
  case 'P4W':
125
128
  return [0, 1, 2, 3]
126
129
  .map((i) => ({
127
130
  start: sub(new Date(), { days: (i + 1) * 7 }),
128
131
  end: sub(new Date(), { days: i * 7 }),
129
132
  }))
130
- .map((interval) => (Object.assign({ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}` }, interval)));
133
+ .map((interval) => ({
134
+ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
135
+ ...interval,
136
+ }));
131
137
  case 'P120D':
132
138
  return [0, 1, 2, 3]
133
139
  .map((i) => ({
134
140
  start: sub(new Date(), { days: (i + 1) * 30 }),
135
141
  end: sub(new Date(), { days: i * 30 }),
136
142
  }))
137
- .map((interval) => (Object.assign({ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}` }, interval)));
143
+ .map((interval) => ({
144
+ name: `${interval.start.toISOString().split('T')[0]} - ${interval.end.toISOString().split('T')[0]}`,
145
+ ...interval,
146
+ }));
138
147
  }
139
148
  };
140
149
  export const signupsTimeline = (duration) => Promise.all(createIntervals(duration).map((interval) => newProfilesForInterval(interval.start, interval.end).then((count) => ({
141
- name: interval === null || interval === void 0 ? void 0 : interval.name,
150
+ name: interval?.name,
142
151
  count,
143
152
  }))));
144
153
  export const serverStats = async () => ({
@@ -31,4 +31,7 @@ export const compileStats = async (fn) => allpeepDb().then(async ({ db }) => ({
31
31
  lastPeriod: await fn(db, sub(new Date(), { years: 2 }), sub(new Date(), { years: 1 })),
32
32
  },
33
33
  }));
34
- export const compileStatsWithAll = async (fn) => allpeepDb().then(async ({ db }) => (Object.assign(Object.assign({}, (await compileStats(fn))), { all: await fn(db) })));
34
+ export const compileStatsWithAll = async (fn) => allpeepDb().then(async ({ db }) => ({
35
+ ...(await compileStats(fn)),
36
+ all: await fn(db),
37
+ }));
@@ -1,7 +1,7 @@
1
1
  import { DbPost } from '@openpeepshq/common/types';
2
2
  export declare const profileWithActivityScoreMapping: (start?: Date, end?: Date) => import("../db/pg/map").Mapping<object, import("../db/pg/map").WithId<object>, import("@openpeepshq/common").Profile>;
3
3
  export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mapping<{
4
- type: "note" | "question" | "event" | "article";
4
+ type: "resource" | "note" | "question" | "event" | "article";
5
5
  visibility: "local" | "group" | "report" | "public" | "unlisted" | "private" | "direct";
6
6
  creatorId: string;
7
7
  capabilitiesNeeded?: string[] | undefined;
@@ -197,6 +197,44 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
197
197
  language?: string | undefined;
198
198
  image?: string | undefined;
199
199
  title?: string | undefined;
200
+ } | {
201
+ type: "resource";
202
+ title: string;
203
+ resourceKind: "link" | "file" | "video" | "gallery" | "audio";
204
+ content?: string | undefined;
205
+ sensitive?: boolean | undefined;
206
+ spoilerText?: string | undefined;
207
+ attachments?: {
208
+ type: string;
209
+ url: string;
210
+ previewUrl: string | null;
211
+ textUrl: null;
212
+ filename: string;
213
+ meta: {
214
+ usage?: string | undefined;
215
+ focus?: {
216
+ x: number;
217
+ y: number;
218
+ } | undefined;
219
+ mimetype?: string | undefined;
220
+ size?: number | undefined;
221
+ };
222
+ description?: string | undefined;
223
+ blurhash?: string | undefined;
224
+ status?: "failed" | "processing" | "ready" | undefined;
225
+ error?: string | undefined;
226
+ }[] | undefined;
227
+ customEmojis?: {
228
+ shortcode: string;
229
+ url: string;
230
+ staticUrl: string;
231
+ visibleInPicker: boolean;
232
+ category: string;
233
+ }[] | undefined;
234
+ language?: string | undefined;
235
+ tags?: string[] | undefined;
236
+ categoryPath?: string[] | undefined;
237
+ url?: string | undefined;
200
238
  } | undefined;
201
239
  }, DbPost & {
202
240
  activityScore: number;
@@ -3,8 +3,15 @@ import { baseProfilesMapping } from '../profiles/index.js';
3
3
  import { postsMapping } from '../posts/index.js';
4
4
  import { map } from '../db/pg/map/index.js';
5
5
  import { computedFields } from '../db/pg/queries/index.js';
6
- export const profileWithActivityScoreMapping = (start, end) => map(Object.assign(Object.assign({}, baseProfilesMapping.data()), { activityWindow: { start, end }, computedFields: [computedFields.profileActivityScore({ start, end })] }));
7
- export const postsWithActivityScoreMapping = map(Object.assign(Object.assign({}, postsMapping.data()), { computedFields: [computedFields.postActivityScore()] }));
6
+ export const profileWithActivityScoreMapping = (start, end) => map({
7
+ ...baseProfilesMapping.data(),
8
+ activityWindow: { start, end },
9
+ computedFields: [computedFields.profileActivityScore({ start, end })],
10
+ });
11
+ export const postsWithActivityScoreMapping = map({
12
+ ...postsMapping.data(),
13
+ computedFields: [computedFields.postActivityScore()],
14
+ });
8
15
  export const followsMapping = map({
9
16
  collection: collectionInfos.followsCollection.name,
10
17
  });
@@ -6,14 +6,13 @@ export const stripeCache = createCache({
6
6
  refreshThreshold: 60 * 60 * 1000,
7
7
  });
8
8
  const loadStripeSubscription = async (customerId) => {
9
- var _a, _b, _c, _d, _e, _f;
10
9
  const subscriptions = await getStripe().then((stripe) => stripe.subscriptions.list({
11
10
  customer: customerId,
12
11
  limit: 1,
13
12
  status: 'all',
14
13
  expand: ['data.default_payment_method'],
15
14
  }));
16
- if (!(subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.data) || (subscriptions === null || subscriptions === void 0 ? void 0 : subscriptions.data.length) === 0) {
15
+ if (!subscriptions?.data || subscriptions?.data.length === 0) {
17
16
  return { status: 'none' };
18
17
  }
19
18
  const subscription = subscriptions.data[0];
@@ -21,14 +20,14 @@ const loadStripeSubscription = async (customerId) => {
21
20
  subscriptionId: subscription.id,
22
21
  status: subscription.status,
23
22
  priceId: subscription.items.data[0].price.id,
24
- currentPeriodEnd: (_a = subscription.ended_at) !== null && _a !== void 0 ? _a : null,
25
- currentPeriodStart: (_b = subscription.start_date) !== null && _b !== void 0 ? _b : null,
23
+ currentPeriodEnd: subscription.ended_at ?? null,
24
+ currentPeriodStart: subscription.start_date ?? null,
26
25
  cancelAtPeriodEnd: subscription.cancel_at_period_end,
27
26
  paymentMethod: subscription.default_payment_method &&
28
27
  typeof subscription.default_payment_method !== 'string'
29
28
  ? {
30
- brand: (_d = (_c = subscription.default_payment_method.card) === null || _c === void 0 ? void 0 : _c.brand) !== null && _d !== void 0 ? _d : null,
31
- last4: (_f = (_e = subscription.default_payment_method.card) === null || _e === void 0 ? void 0 : _e.last4) !== null && _f !== void 0 ? _f : null,
29
+ brand: subscription.default_payment_method.card?.brand ?? null,
30
+ last4: subscription.default_payment_method.card?.last4 ?? null,
32
31
  }
33
32
  : null,
34
33
  };
@@ -1,18 +1,17 @@
1
1
  import Stripe from 'stripe';
2
2
  import { config } from '../config/index.js';
3
3
  import { hub } from '../events/index.js';
4
- export const initStripeWithCredentials = (data) => (data === null || data === void 0 ? void 0 : data.publishableKey) || (data === null || data === void 0 ? void 0 : data.secretKey) || (data === null || data === void 0 ? void 0 : data.webhookSecret)
5
- ? new Stripe(data === null || data === void 0 ? void 0 : data.secretKey, { apiVersion: '2025-07-30.basil' })
4
+ export const initStripeWithCredentials = (data) => data?.publishableKey || data?.secretKey || data?.webhookSecret
5
+ ? new Stripe(data?.secretKey, { apiVersion: '2025-07-30.basil' })
6
6
  : undefined;
7
7
  export const initStripe = async () => {
8
- var _a;
9
8
  hub.on('configUpdated', (namespace, name) => {
10
9
  if (namespace === 'openpeeps' && name === 'core') {
11
10
  _stripe = null;
12
11
  }
13
12
  });
14
13
  const cfg = await config();
15
- return initStripeWithCredentials((_a = cfg.payments) === null || _a === void 0 ? void 0 : _a.stripe);
14
+ return initStripeWithCredentials(cfg.payments?.stripe);
16
15
  };
17
16
  let _stripe = null;
18
17
  export const getStripe = async () => {
@@ -4,22 +4,19 @@ import { getUserStripeSubscription, refreshStripeSubscription, stripeCache, } fr
4
4
  import { findProfileSettings, updateProfileSettings } from '../profileSettings/index.js';
5
5
  import { getStripe, initStripeWithCredentials } from './connection.js';
6
6
  export const getStripeDetails = async () => {
7
- var _a;
8
7
  const cfg = await config();
9
- const data = (_a = cfg.payments) === null || _a === void 0 ? void 0 : _a.stripe;
8
+ const data = cfg.payments?.stripe;
10
9
  const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
11
10
  const success_url = `${protocol}://${cfg.server.host}/payment/success`;
12
11
  const cancel_url = `${protocol}://${cfg.server.host}/auth/login`;
13
12
  const portal_return_url = `${protocol}://${cfg.server.host}/settings/billing`;
14
- return Object.assign(Object.assign({}, data), { success_url, cancel_url, portal_return_url });
13
+ return { ...data, success_url, cancel_url, portal_return_url };
15
14
  };
16
15
  export const stripeMembershipActive = async () => {
17
- var _a;
18
16
  const data = await getStripeDetails();
19
- return !!((_a = data === null || data === void 0 ? void 0 : data.paidMembership) === null || _a === void 0 ? void 0 : _a.enabled);
17
+ return !!data?.paidMembership?.enabled;
20
18
  };
21
19
  const getPrices = async (stripeInstance, productId = '', limit = 1) => {
22
- var _a, _b;
23
20
  if (!productId) {
24
21
  throw new Error('[STRIPE_PRICE][ERROR] No productId found');
25
22
  }
@@ -31,13 +28,13 @@ const getPrices = async (stripeInstance, productId = '', limit = 1) => {
31
28
  }
32
29
  const defaultPriceId = typeof product.default_price === 'string'
33
30
  ? product.default_price
34
- : ((_b = (_a = product.default_price) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null);
31
+ : (product.default_price?.id ?? null);
35
32
  if (defaultPriceId && limit === 1) {
36
33
  try {
37
34
  const price = await stripeInstance.prices.retrieve(defaultPriceId);
38
35
  return { data: [price] };
39
36
  }
40
- catch (_c) {
37
+ catch {
41
38
  return { data: [] };
42
39
  }
43
40
  }
@@ -51,7 +48,7 @@ const getPrices = async (stripeInstance, productId = '', limit = 1) => {
51
48
  };
52
49
  export const testStripeCredentials = async (data) => {
53
50
  try {
54
- const credentials = Object.assign(Object.assign({}, (await getStripeDetails())), data);
51
+ const credentials = { ...(await getStripeDetails()), ...data };
55
52
  const stripe = initStripeWithCredentials(credentials);
56
53
  if (!stripe) {
57
54
  return {
@@ -60,14 +57,14 @@ export const testStripeCredentials = async (data) => {
60
57
  };
61
58
  }
62
59
  const { paidMembership } = credentials;
63
- const productId = paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.productId;
60
+ const productId = paidMembership?.productId;
64
61
  if (!productId) {
65
62
  return {
66
63
  success: false,
67
64
  key: 'configuration.server.stripe.errors.noProductId',
68
65
  };
69
66
  }
70
- const prices = await getPrices(stripe, paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.productId, 1);
67
+ const prices = await getPrices(stripe, paidMembership?.productId, 1);
71
68
  if (prices.data.length === 0) {
72
69
  return {
73
70
  success: false,
@@ -92,7 +89,7 @@ export const createStripeCustomerPortal = async (stripeId) => {
92
89
  }));
93
90
  return session.url;
94
91
  }
95
- catch (_a) { }
92
+ catch { }
96
93
  };
97
94
  export const createStripeCustomer = async (profile, account) => {
98
95
  const profileSettings = await findProfileSettings(profile.id);
@@ -134,10 +131,9 @@ const allowedEvents = [
134
131
  'payment_intent.canceled',
135
132
  ];
136
133
  export const processEvent = async (event) => {
137
- var _a;
138
134
  if (!allowedEvents.includes(event.type))
139
135
  return;
140
- const { customer: customerId } = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.object;
136
+ const { customer: customerId } = event?.data?.object;
141
137
  if (typeof customerId !== 'string') {
142
138
  throw new Error(`[STRIPE HOOK][CANCER] ID isn't string.\nEvent type: ${event.type}`);
143
139
  }
@@ -167,14 +163,13 @@ export const checkSubscription = async (profile, account, refresh = false) => {
167
163
  return true;
168
164
  };
169
165
  export const createStripeCheckoutUrl = async (profile, account) => {
170
- var _a;
171
166
  const stripeCustomerId = await getOrCreateStripeCustomerId(profile, account);
172
167
  if (!stripeCustomerId) {
173
168
  throw new Error('[STRIPE_CHECKOUT][ERROR] No stripe customer id found');
174
169
  }
175
170
  const { paidMembership, success_url, cancel_url } = (await getStripeDetails());
176
- const productId = paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.productId;
177
- const trialPeriodDays = (_a = paidMembership === null || paidMembership === void 0 ? void 0 : paidMembership.trialPeriodDays) !== null && _a !== void 0 ? _a : 0;
171
+ const productId = paidMembership?.productId;
172
+ const trialPeriodDays = paidMembership?.trialPeriodDays ?? 0;
178
173
  const prices = await getPrices(await getStripe(), productId, 1);
179
174
  const line_items = prices.data.map((price) => ({
180
175
  price: price.id,
@@ -186,7 +181,7 @@ export const createStripeCheckoutUrl = async (profile, account) => {
186
181
  try {
187
182
  const res = await getUserStripeSubscription(stripeCustomerId);
188
183
  let successUrl = success_url;
189
- if (res !== null && (res === null || res === void 0 ? void 0 : res.status) !== 'none') {
184
+ if (res !== null && res?.status !== 'none') {
190
185
  successUrl = `${success_url}?user=true`;
191
186
  }
192
187
  const subscription_data = trialPeriodDays > 0
@@ -205,7 +200,7 @@ export const createStripeCheckoutUrl = async (profile, account) => {
205
200
  subscription_data,
206
201
  allow_promotion_codes: true,
207
202
  }))
208
- .then((session) => { var _a; return (_a = session.url) !== null && _a !== void 0 ? _a : undefined; });
203
+ .then((session) => session.url ?? undefined);
209
204
  }
210
- catch (_b) { }
205
+ catch { }
211
206
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "dependencies": {
@@ -37,11 +37,10 @@
37
37
  "type-fest": "^4.31.0",
38
38
  "uuidv7": "^1.0.2",
39
39
  "web-push": "^3.6.7",
40
- "zod": "^4.4.3",
41
- "@openpeepshq/common": "0.1.46",
42
- "@openpeepshq/i18n": "^0.1.10",
43
- "@openpeepshq/geocoder": "^0.1.2",
44
- "@openpeepshq/fetch-client": "^0.1.7"
40
+ "@openpeepshq/common": "0.3.1",
41
+ "@openpeepshq/fetch-client": "^0.2.1",
42
+ "@openpeepshq/i18n": "^0.1.12",
43
+ "@openpeepshq/geocoder": "^0.1.2"
45
44
  },
46
45
  "main": "dist/index.js",
47
46
  "types": "dist/index.d.ts",