@openpeepshq/common 0.1.45 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/lib/adminSections.js +1 -1
  2. package/dist/lib/capabilitiesHelpers.d.ts +9 -7
  3. package/dist/lib/capabilitiesHelpers.js +43 -38
  4. package/dist/lib/csvHelpers.js +1 -1
  5. package/dist/lib/eventIcs.d.ts +17 -0
  6. package/dist/lib/eventIcs.js +91 -15
  7. package/dist/lib/eventRecurrence.d.ts +19 -0
  8. package/dist/lib/eventRecurrence.js +82 -20
  9. package/dist/lib/eventTime.d.ts +7 -0
  10. package/dist/lib/eventTime.js +23 -9
  11. package/dist/lib/federationHosts.d.ts +3 -0
  12. package/dist/lib/federationHosts.js +17 -0
  13. package/dist/lib/feedCursor.d.ts +14 -0
  14. package/dist/lib/feedCursor.js +22 -0
  15. package/dist/lib/feedFormat.d.ts +12 -0
  16. package/dist/lib/feedFormat.js +14 -0
  17. package/dist/lib/groupHelpers.js +13 -34
  18. package/dist/lib/groupTemplateHelpers.js +6 -10
  19. package/dist/lib/index.d.ts +7 -0
  20. package/dist/lib/index.js +7 -0
  21. package/dist/lib/jamHelpers.d.ts +11 -2
  22. package/dist/lib/jamHelpers.js +43 -9
  23. package/dist/lib/legacyThemeRoot.d.ts +3 -0
  24. package/dist/lib/legacyThemeRoot.js +10 -0
  25. package/dist/lib/markdownHelpers.d.ts +8 -0
  26. package/dist/lib/markdownHelpers.js +34 -6
  27. package/dist/lib/postHelpers.d.ts +142 -3
  28. package/dist/lib/postHelpers.js +323 -47
  29. package/dist/lib/profileHelpers.d.ts +11 -0
  30. package/dist/lib/profileHelpers.js +34 -10
  31. package/dist/lib/pushHelpers.js +3 -4
  32. package/dist/lib/reactions.d.ts +17 -0
  33. package/dist/lib/reactions.js +37 -0
  34. package/dist/lib/scopeHelpers.d.ts +31 -2
  35. package/dist/lib/scopeHelpers.js +39 -8
  36. package/dist/lib/ssoLoginUrl.js +4 -6
  37. package/dist/lib/ssoProviders.d.ts +72 -0
  38. package/dist/lib/ssoProviders.js +366 -0
  39. package/dist/lib/timeZone.d.ts +9 -0
  40. package/dist/lib/timeZone.js +44 -0
  41. package/dist/lib/tokenHelpers.js +5 -5
  42. package/dist/lib/utils.js +6 -7
  43. package/dist/types/admin-db.js +1 -1
  44. package/dist/types/analytics.d.ts +20 -0
  45. package/dist/types/analytics.js +4 -0
  46. package/dist/types/api.d.ts +41800 -11853
  47. package/dist/types/api.js +53 -5
  48. package/dist/types/auth.d.ts +20 -6
  49. package/dist/types/capabilities.d.ts +15 -1
  50. package/dist/types/capabilities.js +51 -0
  51. package/dist/types/config.d.ts +99 -0
  52. package/dist/types/config.js +56 -4
  53. package/dist/types/db.d.ts +1155 -164
  54. package/dist/types/db.js +14 -0
  55. package/dist/types/export.d.ts +120 -0
  56. package/dist/types/export.js +7 -0
  57. package/dist/types/index.d.ts +2 -0
  58. package/dist/types/index.js +2 -0
  59. package/dist/types/internal.d.ts +2577 -524
  60. package/dist/types/internal.js +6 -0
  61. package/dist/types/models.d.ts +63 -7
  62. package/dist/types/models.js +40 -3
  63. package/dist/types/plugins.d.ts +22 -0
  64. package/dist/types/plugins.js +66 -0
  65. package/dist/types/roleDefaults.d.ts +31 -0
  66. package/dist/types/roleDefaults.js +110 -0
  67. package/dist/types/stats.d.ts +54606 -6065
  68. package/dist/types/stats.js +30 -0
  69. package/dist/types/utils.d.ts +2 -0
  70. package/dist/types/utils.js +1 -3
  71. package/dist/zod.d.ts +1 -0
  72. package/dist/zod.js +1 -0
  73. package/package.json +36 -6
  74. package/src/index.ts +4 -0
  75. package/src/lib/adminSections.ts +84 -0
  76. package/src/lib/attachmentHelpers.ts +14 -0
  77. package/src/lib/capabilitiesHelpers.ts +532 -0
  78. package/src/lib/colors.ts +20 -0
  79. package/src/lib/csvHelpers.ts +31 -0
  80. package/src/lib/eventIcs.ts +265 -0
  81. package/src/lib/eventRecurrence.ts +495 -0
  82. package/src/lib/eventTime.ts +206 -0
  83. package/src/lib/federationHosts.ts +22 -0
  84. package/src/lib/feedCursor.ts +27 -0
  85. package/src/lib/feedFormat.ts +24 -0
  86. package/src/lib/groupHelpers.ts +421 -0
  87. package/src/lib/groupTemplateHelpers.ts +83 -0
  88. package/src/lib/index.ts +29 -0
  89. package/src/lib/jamHelpers.ts +164 -0
  90. package/src/lib/legacyThemeRoot.ts +14 -0
  91. package/src/lib/markdownHelpers.ts +122 -0
  92. package/src/lib/mediaDimensions.ts +21 -0
  93. package/src/lib/postHelpers.ts +783 -0
  94. package/src/lib/profileHelpers.ts +220 -0
  95. package/src/lib/pushHelpers.ts +34 -0
  96. package/src/lib/reactions.ts +52 -0
  97. package/src/lib/reportHelpers.ts +7 -0
  98. package/src/lib/scopeHelpers.ts +176 -0
  99. package/src/lib/ssoLoginUrl.ts +93 -0
  100. package/src/lib/ssoProviders.ts +472 -0
  101. package/src/lib/text.ts +26 -0
  102. package/src/lib/timeZone.ts +52 -0
  103. package/src/lib/tokenHelpers.ts +119 -0
  104. package/src/lib/utils.ts +322 -0
  105. package/src/types/admin-db.ts +74 -0
  106. package/src/types/admin-email.ts +55 -0
  107. package/src/types/admin-jobs.ts +17 -0
  108. package/src/types/admin-performance.ts +20 -0
  109. package/src/types/analytics.ts +318 -0
  110. package/src/types/api.ts +871 -0
  111. package/src/types/apple-app-site-association.ts +54 -0
  112. package/src/types/auth.ts +22 -0
  113. package/src/types/capabilities.ts +280 -0
  114. package/src/types/config.ts +546 -0
  115. package/src/types/db.ts +138 -0
  116. package/src/types/export.ts +10 -0
  117. package/src/types/index.ts +20 -0
  118. package/src/types/internal.ts +338 -0
  119. package/src/types/models.ts +939 -0
  120. package/src/types/notifications.ts +92 -0
  121. package/src/types/plugins.ts +150 -0
  122. package/src/types/roleDefaults.ts +132 -0
  123. package/src/types/stats.ts +195 -0
  124. package/src/types/stripe.ts +45 -0
  125. package/src/types/utils.ts +100 -0
  126. package/src/zod.ts +1 -0
@@ -61,7 +61,7 @@ export const adminSections = [
61
61
  capabilities: ['core-db-access'],
62
62
  },
63
63
  ];
64
- export const canAccessAdminSection = (roles, section) => checkRoleCapabilities(roles !== null && roles !== void 0 ? roles : [], [...section.capabilities]).success;
64
+ export const canAccessAdminSection = (roles, section) => checkRoleCapabilities(roles ?? [], [...section.capabilities]).success;
65
65
  export const getVisibleAdminSections = (roles) => adminSections.filter((section) => canAccessAdminSection(roles, section));
66
66
  /** True when the profile may see at least one admin menu entry. */
67
67
  export const canAccessAdminMenu = (roles) => getVisibleAdminSections(roles).length > 0;
@@ -7,6 +7,8 @@ export declare const checkCapabilities: (neededCapabilities: string[], presentCa
7
7
  missingCapabilities: string[];
8
8
  };
9
9
  export declare const mergeCapabilities: (capabilities?: Partial<Capabilities>[]) => Capabilities;
10
+ /** Order-independent equality check for two capability add/remove lists. */
11
+ export declare const capabilitySetsEqual: (a: string[] | undefined, b: string[] | undefined) => boolean;
10
12
  export declare const checkRoleCapabilities: (roles: Role[] | undefined, neededCapabilities: string[]) => {
11
13
  success: boolean;
12
14
  missingCapabilities: string[];
@@ -37,7 +39,7 @@ export declare const checkGroupCapabilities: (authData: AuthorizationData, neede
37
39
  missingCapabilities: string[];
38
40
  missingScope: {
39
41
  resource: {
40
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
42
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
41
43
  id?: string | undefined;
42
44
  };
43
45
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -48,7 +50,7 @@ export declare const checkPostCapabilities: (authData: AuthorizationData, needed
48
50
  missingCapabilities: string[];
49
51
  missingScope: {
50
52
  resource: {
51
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
53
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
52
54
  id?: string | undefined;
53
55
  };
54
56
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -59,7 +61,7 @@ export declare const checkProfileCapabilities: (authData: AuthorizationData, nee
59
61
  missingCapabilities: string[];
60
62
  missingScope: {
61
63
  resource: {
62
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
64
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
63
65
  id?: string | undefined;
64
66
  };
65
67
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -70,7 +72,7 @@ export declare const checkReportCapabilities: (authData: AuthorizationData, need
70
72
  missingCapabilities: string[];
71
73
  missingScope: {
72
74
  resource: {
73
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
75
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
74
76
  id?: string | undefined;
75
77
  };
76
78
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -81,7 +83,7 @@ export declare const checkAccessTokenCapabilities: (authData: AuthorizationData,
81
83
  missingCapabilities: string[];
82
84
  missingScope: {
83
85
  resource: {
84
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
86
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
85
87
  id?: string | undefined;
86
88
  };
87
89
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -92,7 +94,7 @@ export declare const checkAccountCapabilities: (authData: AuthorizationData, nee
92
94
  missingCapabilities: string[];
93
95
  missingScope: {
94
96
  resource: {
95
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
97
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
96
98
  id?: string | undefined;
97
99
  };
98
100
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -110,7 +112,7 @@ export declare const checkAccountCreateAuthorization: (authData: AuthorizationDa
110
112
  missingCapabilities: string[];
111
113
  missingScope: {
112
114
  resource: {
113
- type: "self" | "db" | "jams" | "profiles" | "*" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
115
+ type: "self" | "*" | "db" | "jams" | "profiles" | "notifications" | "posts" | "groups" | "reports" | "webhooks" | "analytics" | "render";
114
116
  id?: string | undefined;
115
117
  };
116
118
  scopeLevel?: "admin" | "write" | "read" | undefined;
@@ -1,28 +1,33 @@
1
- import { calculateRequiredScope, scopeMatches, withPublicPostReadScopes, withPublicGroupReadScopes, } from './scopeHelpers.js';
1
+ import { calculateRequiredScope, scopeMatches, withPublicPostReadScopes, withPublicGroupReadScopes, withPublicProfileReadScopes, } from './scopeHelpers.js';
2
+ import { viewerBlockedTarget, targetBlockedViewer } from './profileHelpers.js';
2
3
  export const checkCapabilities = (neededCapabilities, presentCapabilities = {
3
4
  add: [],
4
5
  remove: [],
5
6
  }) => {
6
- const containsCapability = (c, clist) => !!(clist === null || clist === void 0 ? void 0 : clist.find((pc) => pc === c || (pc.includes('*') && c.startsWith(pc.split('*')[0]))));
7
- const missingCapabilities = neededCapabilities.filter((c) => {
8
- var _a, _b;
9
- return containsCapability(c, (_a = presentCapabilities.remove) !== null && _a !== void 0 ? _a : []) ||
10
- !containsCapability(c, (_b = presentCapabilities.add) !== null && _b !== void 0 ? _b : []);
11
- });
7
+ const containsCapability = (c, clist) => !!clist?.find((pc) => pc === c || (pc.includes('*') && c.startsWith(pc.split('*')[0])));
8
+ const missingCapabilities = neededCapabilities.filter((c) => containsCapability(c, presentCapabilities.remove ?? []) ||
9
+ !containsCapability(c, presentCapabilities.add ?? []));
12
10
  return {
13
11
  success: missingCapabilities.length === 0,
14
12
  missingCapabilities,
15
13
  };
16
14
  };
17
15
  export const mergeCapabilities = (capabilities) => {
18
- var _a, _b;
19
16
  return {
20
- add: [...new Set((_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.map((c) => (c === null || c === void 0 ? void 0 : c.add) || []).flat()) !== null && _a !== void 0 ? _a : [])],
17
+ add: [...new Set(capabilities?.map((c) => c?.add || []).flat() ?? [])],
21
18
  remove: [
22
- ...new Set((_b = capabilities === null || capabilities === void 0 ? void 0 : capabilities.map((c) => (c === null || c === void 0 ? void 0 : c.remove) || []).flat()) !== null && _b !== void 0 ? _b : []),
19
+ ...new Set(capabilities?.map((c) => c?.remove || []).flat() ?? []),
23
20
  ],
24
21
  };
25
22
  };
23
+ /** Order-independent equality check for two capability add/remove lists. */
24
+ export const capabilitySetsEqual = (a, b) => {
25
+ const sa = new Set(a ?? []);
26
+ const sb = new Set(b ?? []);
27
+ if (sa.size !== sb.size)
28
+ return false;
29
+ return [...sa].every((value) => sb.has(value));
30
+ };
26
31
  export const checkRoleCapabilities = (roles = [], neededCapabilities) => checkCapabilities(neededCapabilities, mergeCapabilities(roles.map((r) => r.capabilities)));
27
32
  /** Any of these matching `roles` shows the Administration row (submenu is separate UX). */
28
33
  export const ADMIN_SIDEBAR_MENU_CAPABILITIES = [
@@ -53,8 +58,8 @@ export const localOrNone = (authData) => {
53
58
  return ['none'];
54
59
  };
55
60
  export const getGroupRelationships = (authData, group) => {
56
- var _a, _b, _c;
57
- const membershipRoles = (_c = (_b = (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.memberships.find((m) => m.group.id === group.id)) === null || _b === void 0 ? void 0 : _b.roles) !== null && _c !== void 0 ? _c : [];
61
+ const membershipRoles = authData.profile?.memberships.find((m) => m.group.id === group.id)?.roles ??
62
+ [];
58
63
  if (authData.profile || authData.service) {
59
64
  return [...localOrNone(authData), ...membershipRoles];
60
65
  }
@@ -62,35 +67,40 @@ export const getGroupRelationships = (authData, group) => {
62
67
  };
63
68
  export const getProfileRelationships = (authData, otherProfile) => {
64
69
  const { profile } = authData;
65
- if (profile && profile.id === (otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
70
+ if (profile && profile.id === otherProfile?.id) {
66
71
  return ['self', ...localOrNone(authData)];
67
72
  }
68
73
  const relationships = localOrNone(authData);
69
- if (profile === null || profile === void 0 ? void 0 : profile.followers.map((f) => f.id).includes(otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
74
+ if (profile?.followers.map((f) => f.id).includes(otherProfile?.id)) {
70
75
  relationships.push('followed-by');
71
76
  }
72
- if (profile === null || profile === void 0 ? void 0 : profile.following.map((f) => f.id).includes(otherProfile === null || otherProfile === void 0 ? void 0 : otherProfile.id)) {
77
+ if (profile?.following.map((f) => f.id).includes(otherProfile?.id)) {
73
78
  relationships.push('following');
74
79
  }
80
+ if (viewerBlockedTarget(profile, otherProfile?.id)) {
81
+ relationships.push('blocked');
82
+ }
83
+ if (targetBlockedViewer(profile, otherProfile?.id)) {
84
+ relationships.push('blocked-by');
85
+ }
75
86
  return relationships;
76
87
  };
77
88
  export const getPostRelationships = (authData, post) => {
78
- var _a, _b, _c;
79
89
  const { profile } = authData;
80
90
  const relationships = [];
81
91
  if (['public', 'local'].includes(post.visibility)) {
82
92
  relationships.push(...localOrNone(authData));
83
93
  }
84
- if (profile && ((_a = post.audience) === null || _a === void 0 ? void 0 : _a.some((a) => a.id === profile.id))) {
94
+ if (profile && post.audience?.some((a) => a.id === profile.id)) {
85
95
  relationships.push('audience');
86
96
  }
87
- if (profile && ((_b = post.mentions) === null || _b === void 0 ? void 0 : _b.some((m) => m.profile.id === profile.id))) {
97
+ if (profile && post.mentions?.some((m) => m.profile.id === profile.id)) {
88
98
  relationships.push('mentioned');
89
99
  }
90
100
  if (profile &&
91
- ((_c = post.entries) === null || _c === void 0 ? void 0 : _c.some((e) => e.type === 'rsvp' &&
101
+ post.entries?.some((e) => e.type === 'rsvp' &&
92
102
  e.profile.id === profile.id &&
93
- ['yes', 'tentative'].includes(e.data.response)))) {
103
+ ['yes', 'tentative'].includes(e.data.response))) {
94
104
  relationships.push('attendee');
95
105
  }
96
106
  return relationships;
@@ -106,30 +116,28 @@ export const getReportRelationships = (authData, report) => {
106
116
  return localOrNone(authData);
107
117
  };
108
118
  export const getAccessTokenRelationships = (authData, accessToken) => {
109
- var _a;
110
119
  const { profile } = authData;
111
120
  const relationships = [...localOrNone(authData)];
112
- const ownerProfileId = (_a = accessToken.ownedBy) === null || _a === void 0 ? void 0 : _a.id;
113
- if (ownerProfileId && (profile === null || profile === void 0 ? void 0 : profile.id) === ownerProfileId) {
121
+ const ownerProfileId = accessToken.ownedBy?.id;
122
+ if (ownerProfileId && profile?.id === ownerProfileId) {
114
123
  relationships.push('owner');
115
124
  }
116
125
  return relationships;
117
126
  };
118
127
  const getConfigCapabilities = (object, relationships, config) => mergeCapabilities(relationships.map((r) => {
119
- var _a;
120
128
  const group = config[object];
121
- return (_a = group[r]) !== null && _a !== void 0 ? _a : { add: [], remove: [] };
129
+ return group[r] ?? { add: [], remove: [] };
122
130
  }));
123
131
  const getGroupRelationshipCapabilities = (authData, group) => mergeCapabilities(group
124
- ? getGroupRelationships(authData, group).map((r) => { var _a, _b; return (_b = (_a = group.capabilities) === null || _a === void 0 ? void 0 : _a[r]) !== null && _b !== void 0 ? _b : { add: [], remove: [] }; })
132
+ ? getGroupRelationships(authData, group).map((r) => group.capabilities?.[r] ?? { add: [], remove: [] })
125
133
  : []);
126
- export const getGroupCapabilitiesByRoles = (roles, group) => mergeCapabilities((roles !== null && roles !== void 0 ? roles : []).map((r) => { var _a, _b; return (_b = (_a = group === null || group === void 0 ? void 0 : group.capabilities) === null || _a === void 0 ? void 0 : _a[r]) !== null && _b !== void 0 ? _b : { add: [], remove: [] }; }));
134
+ export const getGroupCapabilitiesByRoles = (roles, group) => mergeCapabilities((roles ?? []).map((r) => group?.capabilities?.[r] ?? { add: [], remove: [] }));
127
135
  // Per-group powers (add member, post in group, moderate, …) come from the
128
136
  // caller's relationship to the group (edge roles plus none/local), never from
129
137
  // their instance role. Instance roles only gate group *creation*
130
138
  // (`core-groups-create`), checked separately at the creation entry points.
131
139
  export const getGroupCapabilities = (authData, group) => getGroupRelationshipCapabilities(authData, group);
132
- const getRoleCapabilities = (profile) => { var _a; return mergeCapabilities((_a = profile === null || profile === void 0 ? void 0 : profile.roles.map((r) => r.capabilities)) !== null && _a !== void 0 ? _a : []); };
140
+ const getRoleCapabilities = (profile) => mergeCapabilities(profile?.roles.map((r) => r.capabilities) ?? []);
133
141
  export const getProfileCapabilities = (authData, targetProfile, config) => getConfigCapabilities('profile', getProfileRelationships(authData, targetProfile), config);
134
142
  const getPostVisibilityCapabilities = (post, profile) => {
135
143
  switch (post.visibility) {
@@ -178,15 +186,12 @@ const getAccessTokenCapabilities = (authData, accessToken, config) => mergeCapab
178
186
  getConfigCapabilities('accessToken', getAccessTokenRelationships(authData, accessToken), config),
179
187
  getRoleCapabilities(authData.profile),
180
188
  ]);
181
- const getAccountCapabilities = (authData, targetAccount) => {
182
- var _a;
183
- return mergeCapabilities([
184
- ((_a = authData.account) === null || _a === void 0 ? void 0 : _a.id) === targetAccount.id
185
- ? { add: ['core-accounts-update'], remove: [] }
186
- : { add: [], remove: [] },
187
- getRoleCapabilities(authData.profile),
188
- ]);
189
- };
189
+ const getAccountCapabilities = (authData, targetAccount) => mergeCapabilities([
190
+ authData.account?.id === targetAccount.id
191
+ ? { add: ['core-accounts-update'], remove: [] }
192
+ : { add: [], remove: [] },
193
+ getRoleCapabilities(authData.profile),
194
+ ]);
190
195
  const checkCapabilitiesWithCalculatedScope = (capabilities, authData, neededCapabilities, resource) => {
191
196
  const requiredScope = calculateRequiredScope({
192
197
  resource,
@@ -211,7 +216,7 @@ export const checkPostCapabilities = (authData, neededCapabilities, post, config
211
216
  ]);
212
217
  return checkCapabilitiesWithCalculatedScope(capabilities, withPublicPostReadScopes(authData, post, neededCapabilities), neededCapabilities, { type: 'posts', id: post.id });
213
218
  };
214
- export const checkProfileCapabilities = (authData, neededCapabilities, targetProfile, config) => checkCapabilitiesWithCalculatedScope(getProfileCapabilities(authData, targetProfile, config), authData, neededCapabilities, { type: 'profiles', id: targetProfile.id });
219
+ export const checkProfileCapabilities = (authData, neededCapabilities, targetProfile, config) => checkCapabilitiesWithCalculatedScope(getProfileCapabilities(authData, targetProfile, config), withPublicProfileReadScopes(authData, targetProfile, neededCapabilities, config), neededCapabilities, { type: 'profiles', id: targetProfile.id });
215
220
  export const checkReportCapabilities = (authData, neededCapabilities, report, config) => checkCapabilitiesWithCalculatedScope(getReportCapabilities(authData, report, config), authData, neededCapabilities, { type: 'reports', id: report.id });
216
221
  export const checkAccessTokenCapabilities = (authData, neededCapabilities, accessToken, config) => checkCapabilitiesWithExplicitScope(getAccessTokenCapabilities(authData, accessToken, config), authData, neededCapabilities, { scopeLevel: 'admin', resource: { type: 'self' } });
217
222
  export const checkAccountCapabilities = (authData, neededCapabilities, targetAccount) => checkCapabilitiesWithExplicitScope(getAccountCapabilities(authData, targetAccount), authData, neededCapabilities, { scopeLevel: 'admin', resource: { type: 'self' } });
@@ -10,7 +10,7 @@ export const escapeCsvCell = (value) => {
10
10
  };
11
11
  export const toCsvRow = (values) => values.map(escapeCsvCell).join(',');
12
12
  export const formatMemberExportCustomFields = (fields) => {
13
- if (!(fields === null || fields === void 0 ? void 0 : fields.length)) {
13
+ if (!fields?.length) {
14
14
  return '';
15
15
  }
16
16
  return JSON.stringify(fields.map(({ name, value }) => ({ name, value })));
@@ -2,3 +2,20 @@ import type { PublicPost } from '../types';
2
2
  export declare const buildEventIcs: (post: PublicPost, options?: {
3
3
  postUrl?: string;
4
4
  }) => string | null;
5
+ /** Attendance ICS: discrete booked dates, or the series definition when none. */
6
+ export declare const buildRsvpIcs: (post: PublicPost, options?: {
7
+ postUrl?: string;
8
+ occurrenceIds?: string[];
9
+ }) => string | null;
10
+ export declare const rsvpConfirmationContent: (post: PublicPost, options: {
11
+ postUrl: string;
12
+ occurrenceIds?: string[];
13
+ }) => {
14
+ ics: string;
15
+ eventName: string;
16
+ start: string;
17
+ end: string | null;
18
+ location: string | null;
19
+ allDay: boolean;
20
+ occurrenceCount: number;
21
+ } | null;
@@ -1,4 +1,5 @@
1
1
  import ical, { ICalCalendarMethod, ICalEventRepeatingFreq, ICalWeekday, } from 'ical-generator';
2
+ import { effectiveEventTimes } from './eventRecurrence.js';
2
3
  import { getJamUrl } from './jamHelpers.js';
3
4
  const utcDateFromYmd = (yyyyMmDd) => {
4
5
  const [y, m, d] = yyyyMmDd.split('-').map(Number);
@@ -22,8 +23,7 @@ const originFromUrl = (url) => {
22
23
  };
23
24
  /** Prefer a joinable place: physical address, jam URL, then external event URL. */
24
25
  const eventLocation = (post, event, postUrl) => {
25
- var _a, _b, _c;
26
- const physical = (_b = (_a = event.physicalLocation) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.trim();
26
+ const physical = event.physicalLocation?.text?.trim();
27
27
  if (physical) {
28
28
  return physical;
29
29
  }
@@ -33,7 +33,7 @@ const eventLocation = (post, event, postUrl) => {
33
33
  return jamUrl;
34
34
  }
35
35
  }
36
- return ((_c = event.url) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
36
+ return event.url?.trim() || undefined;
37
37
  };
38
38
  const repeatingFreq = {
39
39
  DAILY: ICalEventRepeatingFreq.DAILY,
@@ -50,17 +50,16 @@ const repeatingWeekday = {
50
50
  SU: ICalWeekday.SU,
51
51
  };
52
52
  const repeatingOptions = (event) => {
53
- var _a, _b, _c;
54
53
  const recurrence = event.recurrence;
55
54
  if (!recurrence)
56
55
  return undefined;
57
- const exclude = ((_a = event.exceptions) !== null && _a !== void 0 ? _a : [])
56
+ const exclude = (event.exceptions ?? [])
58
57
  .filter((exception) => exception.cancelled)
59
58
  .map((exception) => new Date(exception.recurrenceId));
60
59
  return {
61
60
  freq: repeatingFreq[recurrence.freq],
62
- interval: (_b = recurrence.interval) !== null && _b !== void 0 ? _b : 1,
63
- ...(((_c = recurrence.byDay) === null || _c === void 0 ? void 0 : _c.length)
61
+ interval: recurrence.interval ?? 1,
62
+ ...(recurrence.byDay?.length
64
63
  ? { byDay: recurrence.byDay.map((day) => repeatingWeekday[day]) }
65
64
  : {}),
66
65
  ...(recurrence.until ? { until: new Date(recurrence.until) } : {}),
@@ -69,8 +68,7 @@ const repeatingOptions = (event) => {
69
68
  };
70
69
  };
71
70
  export const buildEventIcs = (post, options) => {
72
- var _a, _b, _c, _d, _e, _f, _g;
73
- if (post.type !== 'event' || ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) !== 'event') {
71
+ if (post.type !== 'event' || post.data?.type !== 'event') {
74
72
  return null;
75
73
  }
76
74
  const event = post.data;
@@ -79,14 +77,14 @@ export const buildEventIcs = (post, options) => {
79
77
  method: ICalCalendarMethod.PUBLISH,
80
78
  scale: 'GREGORIAN',
81
79
  });
82
- const link = (_b = event.url) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.postUrl;
83
- const summary = ((_c = event.name) === null || _c === void 0 ? void 0 : _c.trim()) || 'Event';
84
- const description = (_d = event.content) === null || _d === void 0 ? void 0 : _d.trim();
85
- const location = eventLocation(post, event, options === null || options === void 0 ? void 0 : options.postUrl);
80
+ const link = event.url ?? options?.postUrl;
81
+ const summary = event.name?.trim() || 'Event';
82
+ const description = event.content?.trim();
83
+ const location = eventLocation(post, event, options?.postUrl);
86
84
  const repeating = repeatingOptions(event);
87
85
  if (event.wholeDay) {
88
86
  const startYmd = event.start.slice(0, 10);
89
- const lastInclusiveYmd = (_f = (_e = event.end) === null || _e === void 0 ? void 0 : _e.slice(0, 10)) !== null && _f !== void 0 ? _f : startYmd;
87
+ const lastInclusiveYmd = event.end?.slice(0, 10) ?? startYmd;
90
88
  calendar.createEvent({
91
89
  id: `openpeeps-event-${post.id}@openpeepshq`,
92
90
  allDay: true,
@@ -115,7 +113,7 @@ export const buildEventIcs = (post, options) => {
115
113
  ...(repeating ? { repeating } : {}),
116
114
  });
117
115
  }
118
- for (const exception of (_g = event.exceptions) !== null && _g !== void 0 ? _g : []) {
116
+ for (const exception of event.exceptions ?? []) {
119
117
  if (exception.cancelled || !exception.start)
120
118
  continue;
121
119
  const start = new Date(exception.start);
@@ -135,3 +133,81 @@ export const buildEventIcs = (post, options) => {
135
133
  }
136
134
  return calendar.toString() + '\r\n';
137
135
  };
136
+ const addOccurrenceEvent = (calendar, post, event, recurrenceId, options) => {
137
+ const link = event.url ?? options?.postUrl;
138
+ const summary = event.name?.trim() || 'Event';
139
+ const description = event.content?.trim();
140
+ const location = eventLocation(post, event, options?.postUrl);
141
+ const times = effectiveEventTimes(event, recurrenceId);
142
+ const id = `openpeeps-event-${post.id}-${recurrenceId}@openpeepshq`;
143
+ if (event.wholeDay) {
144
+ const startYmd = times.start.slice(0, 10);
145
+ const lastInclusiveYmd = times.end?.slice(0, 10) ?? startYmd;
146
+ calendar.createEvent({
147
+ id,
148
+ allDay: true,
149
+ start: utcDateFromYmd(startYmd),
150
+ end: exclusiveEndAfterInclusiveDay(lastInclusiveYmd),
151
+ summary,
152
+ ...(description ? { description } : {}),
153
+ ...(location ? { location } : {}),
154
+ ...(link ? { url: link } : {}),
155
+ });
156
+ return;
157
+ }
158
+ const start = new Date(times.start);
159
+ const end = times.end
160
+ ? new Date(times.end)
161
+ : new Date(start.getTime() + 60 * 60 * 1000);
162
+ calendar.createEvent({
163
+ id,
164
+ start,
165
+ end,
166
+ summary,
167
+ ...(description ? { description } : {}),
168
+ ...(location ? { location } : {}),
169
+ ...(link ? { url: link } : {}),
170
+ });
171
+ };
172
+ /** Attendance ICS: discrete booked dates, or the series definition when none. */
173
+ export const buildRsvpIcs = (post, options) => {
174
+ const occurrenceIds = options?.occurrenceIds?.filter(Boolean) ?? [];
175
+ if (!occurrenceIds.length) {
176
+ return buildEventIcs(post, { postUrl: options?.postUrl });
177
+ }
178
+ if (post.type !== 'event' || post.data?.type !== 'event') {
179
+ return null;
180
+ }
181
+ const event = post.data;
182
+ const calendar = ical({
183
+ prodId: '//OpenPeeps//Event//EN',
184
+ method: ICalCalendarMethod.PUBLISH,
185
+ scale: 'GREGORIAN',
186
+ });
187
+ for (const recurrenceId of occurrenceIds) {
188
+ addOccurrenceEvent(calendar, post, event, recurrenceId, options);
189
+ }
190
+ return calendar.toString() + '\r\n';
191
+ };
192
+ export const rsvpConfirmationContent = (post, options) => {
193
+ if (post.type !== 'event' || post.data?.type !== 'event') {
194
+ return null;
195
+ }
196
+ const ics = buildRsvpIcs(post, options);
197
+ if (!ics)
198
+ return null;
199
+ const event = post.data;
200
+ const occurrenceIds = options.occurrenceIds?.filter(Boolean) ?? [];
201
+ const times = occurrenceIds.length > 0
202
+ ? effectiveEventTimes(event, occurrenceIds[0])
203
+ : { start: event.start, end: event.end };
204
+ return {
205
+ ics,
206
+ eventName: event.name?.trim() || 'Event',
207
+ start: times.start,
208
+ end: times.end ?? null,
209
+ location: event.physicalLocation?.text ?? null,
210
+ allDay: event.wholeDay ?? false,
211
+ occurrenceCount: occurrenceIds.length,
212
+ };
213
+ };
@@ -21,6 +21,25 @@ export declare const expandEventOccurrences: (event: Event, window: {
21
21
  to: Date;
22
22
  }) => ExpandedOccurrence[];
23
23
  export declare const occurrencesForIndex: (event: Event, now?: Date) => ExpandedOccurrence[];
24
+ export declare const listRsvpOccurrences: (event: Event, now?: Date) => ExpandedOccurrence[];
25
+ export declare const occurrenceHasEnded: (start: string, end?: string, now?: Date) => boolean;
26
+ export type EventRsvpOpenOptions = {
27
+ recurrenceId?: string;
28
+ lockToOccurrence?: boolean;
29
+ now?: Date;
30
+ };
31
+ /** False once the event, or the locked occurrence, is over. */
32
+ export declare const eventRsvpOpen: (event: Event, options?: EventRsvpOpenOptions) => boolean;
33
+ export type RsvpTimeTarget = {
34
+ occurrenceIds?: string[];
35
+ recurrenceId?: string;
36
+ };
37
+ /**
38
+ * True when every targeted time is already over. A series RSVP with no ids
39
+ * is past only when the series has nothing left open.
40
+ */
41
+ export declare const rsvpTargetsPastEvent: (event: Event, target?: RsvpTimeTarget, now?: Date) => boolean;
42
+ export declare const defaultRsvpRecurrenceId: (event: Event, queryId?: string, now?: Date) => string | undefined;
24
43
  export declare const previewUpcomingOccurrences: (event: Event, count?: number, now?: Date) => ExpandedOccurrence[];
25
44
  export declare const effectiveEventTimes: (event: Event, recurrenceId?: string) => {
26
45
  start: string;