@frigear-nu/crew 0.0.0-stage → 0.0.1

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 (155) hide show
  1. package/README.md +39 -2
  2. package/dist/module.d.mts +250 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +172 -0
  5. package/dist/runtime/access.d.ts +1 -0
  6. package/dist/runtime/access.js +45 -0
  7. package/dist/runtime/app/components/CrewAddMemberSlideover.d.vue.ts +18 -0
  8. package/dist/runtime/app/components/CrewAddMemberSlideover.vue +198 -0
  9. package/dist/runtime/app/components/CrewAddMemberSlideover.vue.d.ts +18 -0
  10. package/dist/runtime/app/components/CrewInviteSlideover.d.vue.ts +14 -0
  11. package/dist/runtime/app/components/CrewInviteSlideover.vue +147 -0
  12. package/dist/runtime/app/components/CrewInviteSlideover.vue.d.ts +14 -0
  13. package/dist/runtime/app/components/CrewMemberSlideover.d.vue.ts +14 -0
  14. package/dist/runtime/app/components/CrewMemberSlideover.vue +126 -0
  15. package/dist/runtime/app/components/CrewMemberSlideover.vue.d.ts +14 -0
  16. package/dist/runtime/app/composables/index.d.ts +4 -0
  17. package/dist/runtime/app/composables/index.js +3 -0
  18. package/dist/runtime/app/composables/useCrewActions.d.ts +45 -0
  19. package/dist/runtime/app/composables/useCrewActions.js +122 -0
  20. package/dist/runtime/app/composables/useCrewLinks.d.ts +10 -0
  21. package/dist/runtime/app/composables/useCrewLinks.js +6 -0
  22. package/dist/runtime/app/composables/useCrewTranslate.d.ts +7 -0
  23. package/dist/runtime/app/composables/useCrewTranslate.js +15 -0
  24. package/dist/runtime/app/dashboard/CrewStatus.d.vue.ts +3 -0
  25. package/dist/runtime/app/dashboard/CrewStatus.vue +78 -0
  26. package/dist/runtime/app/dashboard/CrewStatus.vue.d.ts +3 -0
  27. package/dist/runtime/app/pages/apply.d.vue.ts +3 -0
  28. package/dist/runtime/app/pages/apply.vue +95 -0
  29. package/dist/runtime/app/pages/apply.vue.d.ts +3 -0
  30. package/dist/runtime/app/pages/home.d.vue.ts +3 -0
  31. package/dist/runtime/app/pages/home.vue +37 -0
  32. package/dist/runtime/app/pages/home.vue.d.ts +3 -0
  33. package/dist/runtime/app/pages/invite.d.vue.ts +3 -0
  34. package/dist/runtime/app/pages/invite.vue +86 -0
  35. package/dist/runtime/app/pages/invite.vue.d.ts +3 -0
  36. package/dist/runtime/app/pages/status.d.vue.ts +3 -0
  37. package/dist/runtime/app/pages/status.vue +21 -0
  38. package/dist/runtime/app/pages/status.vue.d.ts +3 -0
  39. package/dist/runtime/app/tabs/Crew.d.vue.ts +9 -0
  40. package/dist/runtime/app/tabs/Crew.vue +590 -0
  41. package/dist/runtime/app/tabs/Crew.vue.d.ts +9 -0
  42. package/dist/runtime/app/tabs/HomeOverview.d.vue.ts +3 -0
  43. package/dist/runtime/app/tabs/HomeOverview.vue +8 -0
  44. package/dist/runtime/app/tabs/HomeOverview.vue.d.ts +3 -0
  45. package/dist/runtime/app/tabs/HomeStatus.d.vue.ts +3 -0
  46. package/dist/runtime/app/tabs/HomeStatus.vue +90 -0
  47. package/dist/runtime/app/tabs/HomeStatus.vue.d.ts +3 -0
  48. package/dist/runtime/app/utils/admin-crew.d.ts +48 -0
  49. package/dist/runtime/app/utils/admin-crew.js +23 -0
  50. package/dist/runtime/app/widgets/InboxAddToCrew.d.vue.ts +13 -0
  51. package/dist/runtime/app/widgets/InboxAddToCrew.vue +34 -0
  52. package/dist/runtime/app/widgets/InboxAddToCrew.vue.d.ts +13 -0
  53. package/dist/runtime/dashboard.d.ts +8 -0
  54. package/dist/runtime/dashboard.js +14 -0
  55. package/dist/runtime/emails/crew-status-applied.d.vue.ts +16 -0
  56. package/dist/runtime/emails/crew-status-applied.vue +40 -0
  57. package/dist/runtime/emails/crew-status-applied.vue.d.ts +16 -0
  58. package/dist/runtime/emails/crew-status-approved.d.vue.ts +16 -0
  59. package/dist/runtime/emails/crew-status-approved.vue +40 -0
  60. package/dist/runtime/emails/crew-status-approved.vue.d.ts +16 -0
  61. package/dist/runtime/emails/crew-status-rejected.d.vue.ts +15 -0
  62. package/dist/runtime/emails/crew-status-rejected.vue +33 -0
  63. package/dist/runtime/emails/crew-status-rejected.vue.d.ts +15 -0
  64. package/dist/runtime/emails/crew-status-waitlisted.d.vue.ts +16 -0
  65. package/dist/runtime/emails/crew-status-waitlisted.vue +40 -0
  66. package/dist/runtime/emails/crew-status-waitlisted.vue.d.ts +16 -0
  67. package/dist/runtime/emails/crew-status-withdrawn.d.vue.ts +16 -0
  68. package/dist/runtime/emails/crew-status-withdrawn.vue +40 -0
  69. package/dist/runtime/emails/crew-status-withdrawn.vue.d.ts +16 -0
  70. package/dist/runtime/i18n/lang/da.json +241 -0
  71. package/dist/runtime/i18n/lang/en.json +241 -0
  72. package/dist/runtime/menus.d.ts +2 -0
  73. package/dist/runtime/menus.js +19 -0
  74. package/dist/runtime/notifications.d.ts +5 -0
  75. package/dist/runtime/notifications.js +10 -0
  76. package/dist/runtime/server/db/schema.postgresql.d.ts +433 -0
  77. package/dist/runtime/server/db/schema.postgresql.js +43 -0
  78. package/dist/runtime/server/db/schema.sqlite.d.ts +451 -0
  79. package/dist/runtime/server/db/schema.sqlite.js +43 -0
  80. package/dist/runtime/server/db/team-members.postgresql.d.ts +143 -0
  81. package/dist/runtime/server/db/team-members.postgresql.js +20 -0
  82. package/dist/runtime/server/db/team-members.sqlite.d.ts +151 -0
  83. package/dist/runtime/server/db/team-members.sqlite.js +20 -0
  84. package/dist/runtime/server/plugins/forms.d.ts +2 -0
  85. package/dist/runtime/server/plugins/forms.js +27 -0
  86. package/dist/runtime/server/plugins/participation.d.ts +2 -0
  87. package/dist/runtime/server/plugins/participation.js +16 -0
  88. package/dist/runtime/server/policies.d.ts +2 -0
  89. package/dist/runtime/server/policies.js +10 -0
  90. package/dist/runtime/server/routes/admin/forms.get.d.ts +2 -0
  91. package/dist/runtime/server/routes/admin/forms.get.js +8 -0
  92. package/dist/runtime/server/routes/admin/invite.delete.d.ts +2 -0
  93. package/dist/runtime/server/routes/admin/invite.delete.js +13 -0
  94. package/dist/runtime/server/routes/admin/invites.get.d.ts +2 -0
  95. package/dist/runtime/server/routes/admin/invites.get.js +14 -0
  96. package/dist/runtime/server/routes/admin/invites.post.d.ts +2 -0
  97. package/dist/runtime/server/routes/admin/invites.post.js +31 -0
  98. package/dist/runtime/server/routes/admin/member-approve.post.d.ts +2 -0
  99. package/dist/runtime/server/routes/admin/member-approve.post.js +10 -0
  100. package/dist/runtime/server/routes/admin/member-reject.post.d.ts +2 -0
  101. package/dist/runtime/server/routes/admin/member-reject.post.js +9 -0
  102. package/dist/runtime/server/routes/admin/member-submission.get.d.ts +2 -0
  103. package/dist/runtime/server/routes/admin/member-submission.get.js +17 -0
  104. package/dist/runtime/server/routes/admin/member-waitlist.post.d.ts +2 -0
  105. package/dist/runtime/server/routes/admin/member-waitlist.post.js +9 -0
  106. package/dist/runtime/server/routes/admin/member-withdraw.post.d.ts +2 -0
  107. package/dist/runtime/server/routes/admin/member-withdraw.post.js +9 -0
  108. package/dist/runtime/server/routes/admin/member.patch.d.ts +2 -0
  109. package/dist/runtime/server/routes/admin/member.patch.js +10 -0
  110. package/dist/runtime/server/routes/admin/members-approve.post.d.ts +2 -0
  111. package/dist/runtime/server/routes/admin/members-approve.post.js +12 -0
  112. package/dist/runtime/server/routes/admin/members.get.d.ts +2 -0
  113. package/dist/runtime/server/routes/admin/members.get.js +10 -0
  114. package/dist/runtime/server/routes/admin/members.post.d.ts +2 -0
  115. package/dist/runtime/server/routes/admin/members.post.js +30 -0
  116. package/dist/runtime/server/routes/admin/settings.get.d.ts +2 -0
  117. package/dist/runtime/server/routes/admin/settings.get.js +9 -0
  118. package/dist/runtime/server/routes/admin/settings.put.d.ts +2 -0
  119. package/dist/runtime/server/routes/admin/settings.put.js +12 -0
  120. package/dist/runtime/server/routes/admin/users.get.d.ts +2 -0
  121. package/dist/runtime/server/routes/admin/users.get.js +8 -0
  122. package/dist/runtime/server/routes/me/crew.get.d.ts +2 -0
  123. package/dist/runtime/server/routes/me/crew.get.js +5 -0
  124. package/dist/runtime/server/routes/public/apply.get.d.ts +2 -0
  125. package/dist/runtime/server/routes/public/apply.get.js +9 -0
  126. package/dist/runtime/server/routes/public/invite-accept.post.d.ts +2 -0
  127. package/dist/runtime/server/routes/public/invite-accept.post.js +7 -0
  128. package/dist/runtime/server/routes/public/member.get.d.ts +2 -0
  129. package/dist/runtime/server/routes/public/member.get.js +9 -0
  130. package/dist/runtime/server/routes/public/members.get.d.ts +2 -0
  131. package/dist/runtime/server/routes/public/members.get.js +11 -0
  132. package/dist/runtime/server/utils/crew-dto.d.ts +46 -0
  133. package/dist/runtime/server/utils/crew-dto.js +80 -0
  134. package/dist/runtime/server/utils/crew-emails.d.ts +43 -0
  135. package/dist/runtime/server/utils/crew-emails.js +139 -0
  136. package/dist/runtime/server/utils/crew-schemas.d.ts +121 -0
  137. package/dist/runtime/server/utils/crew-schemas.js +69 -0
  138. package/dist/runtime/server/utils/crew-send.d.ts +19 -0
  139. package/dist/runtime/server/utils/crew-send.js +20 -0
  140. package/dist/runtime/server/utils/crew-settings.d.ts +52 -0
  141. package/dist/runtime/server/utils/crew-settings.js +100 -0
  142. package/dist/runtime/server/utils/crew-tokens.d.ts +8 -0
  143. package/dist/runtime/server/utils/crew-tokens.js +9 -0
  144. package/dist/runtime/server/utils/crew.d.ts +172 -0
  145. package/dist/runtime/server/utils/crew.js +502 -0
  146. package/dist/runtime/utils/api.d.ts +44 -0
  147. package/dist/runtime/utils/api.js +47 -0
  148. package/dist/runtime/utils/index.d.ts +8 -0
  149. package/dist/runtime/utils/index.js +6 -0
  150. package/dist/runtime/utils/links.d.ts +49 -0
  151. package/dist/runtime/utils/links.js +27 -0
  152. package/dist/runtime/utils/status.d.ts +36 -0
  153. package/dist/runtime/utils/status.js +39 -0
  154. package/dist/types.d.mts +5 -0
  155. package/package.json +118 -3
@@ -0,0 +1,100 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, asc, count, eq, isNotNull, isNull, ne } from "drizzle-orm";
3
+ import { conflict, validationError } from "@frigear-nu/module-kit/server";
4
+ import { newId } from "../../utils/index.js";
5
+ import { toCrewSettingsDto } from "./crew-dto.js";
6
+ export async function findCrewSettings(operationId) {
7
+ const [row] = await db.select().from(schema.crewSettings).where(eq(schema.crewSettings.operationId, operationId)).limit(1);
8
+ return row;
9
+ }
10
+ export async function crewSettingsDtoOf(operationId) {
11
+ const [row, approved] = await Promise.all([findCrewSettings(operationId), crewApprovedCount(operationId)]);
12
+ return toCrewSettingsDto(operationId, row, approved);
13
+ }
14
+ export async function crewApprovedCount(operationId) {
15
+ const [row] = await db.select({ total: count() }).from(schema.teamMembers).innerJoin(schema.teams, eq(schema.teamMembers.teamId, schema.teams.id)).where(and(eq(schema.teams.ownerType, "operation"), eq(schema.teams.ownerId, operationId), eq(schema.teamMembers.crewStatus, "approved")));
16
+ return Number(row?.total ?? 0);
17
+ }
18
+ export function crewOperationTeams(operationId) {
19
+ return db.select().from(schema.teams).where(and(eq(schema.teams.ownerType, "operation"), eq(schema.teams.ownerId, operationId))).orderBy(asc(schema.teams.sort), asc(schema.teams.createdAt), asc(schema.teams.id));
20
+ }
21
+ export async function findCrewOperationTeam(operationId, teamId) {
22
+ const [row] = await db.select().from(schema.teams).where(eq(schema.teams.id, teamId)).limit(1);
23
+ return row && row.ownerType === "operation" && row.ownerId === operationId ? row : void 0;
24
+ }
25
+ export async function getCrewOperationTeamOr400(operationId, teamId, field = "teamId") {
26
+ const team = await findCrewOperationTeam(operationId, teamId);
27
+ if (!team) throw validationError([{ path: [field], message: "The team must belong to this operation." }], "Unknown team");
28
+ return team;
29
+ }
30
+ export async function crewEnsureDefaultTeam(event, operationId, preferredId) {
31
+ if (preferredId) return getCrewOperationTeamOr400(operationId, preferredId, "defaultTeamId");
32
+ const [first] = await crewOperationTeams(operationId);
33
+ if (first) return first;
34
+ const kind = useRuntimeConfig(event).crew?.defaultTeamKind ?? "default";
35
+ return createTeamRow(event, { ownerType: "operation", ownerId: operationId, kind, name: { en: "Crew", da: "Crew" } });
36
+ }
37
+ export async function crewDefaultTeamOf(event, operationId, settings) {
38
+ const stored = settings?.defaultTeamId ? await findCrewOperationTeam(operationId, settings.defaultTeamId) : void 0;
39
+ return stored ?? crewEnsureDefaultTeam(event, operationId);
40
+ }
41
+ export async function crewLowestRole(event, kind) {
42
+ const ladder = await getTeamLadderOr400(event, kind);
43
+ return ladder.roles[0].key;
44
+ }
45
+ export async function crewEnsurePresets(event, operationId) {
46
+ const presets = useRuntimeConfig(event).crew?.rolePresets ?? [];
47
+ const owner = { ownerType: "operation", ownerId: operationId };
48
+ const existing = await db.select().from(schema.teamRoleMappings).where(and(eq(schema.teamRoleMappings.ownerType, owner.ownerType), eq(schema.teamRoleMappings.ownerId, operationId), isNull(schema.teamRoleMappings.teamId)));
49
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
50
+ for (const preset of presets) {
51
+ const match = normalizeTeamRoleMatch(preset.match);
52
+ if (existing.some((row) => same(normalizeTeamRoleMatch(row.match), match))) continue;
53
+ try {
54
+ await assertTeamMappingTarget(event, { ...owner, teamId: null, teamRole: preset.teamRole });
55
+ } catch {
56
+ continue;
57
+ }
58
+ await db.insert(schema.teamRoleMappings).values({ id: newId("trm"), ...owner, teamId: null, match, teamRole: preset.teamRole, priority: 0 });
59
+ }
60
+ forgetTeamRoles(event);
61
+ }
62
+ export async function assertCrewForm(formId, operationId) {
63
+ const [form] = await db.select().from(schema.forms).where(eq(schema.forms.id, formId)).limit(1);
64
+ if (!form) throw validationError([{ path: ["formId"], message: "This form does not exist." }], "Unknown form");
65
+ if ((form.definition.access?.auth ?? "none") !== "user") {
66
+ throw validationError([{ path: ["formId"], message: "The form must require a signed-in user (access: user)." }], "Unsuitable form");
67
+ }
68
+ if (form.definition.storage === "none") {
69
+ throw validationError([{ path: ["formId"], message: "The form must store its submissions." }], "Unsuitable form");
70
+ }
71
+ const [other] = await db.select({ operationId: schema.crewSettings.operationId }).from(schema.crewSettings).where(and(eq(schema.crewSettings.formId, formId), ne(schema.crewSettings.operationId, operationId))).limit(1);
72
+ if (other) throw conflict("Another operation recruits with this form already.", { field: "formId" });
73
+ }
74
+ export async function crewEligibleForms(operationId) {
75
+ const [forms, used] = await Promise.all([
76
+ db.select({ id: schema.forms.id, name: schema.forms.name, slug: schema.forms.slug, status: schema.forms.status, definition: schema.forms.definition }).from(schema.forms).where(ne(schema.forms.status, "archived")).orderBy(asc(schema.forms.name)).limit(500),
77
+ db.select({ formId: schema.crewSettings.formId, operationId: schema.crewSettings.operationId }).from(schema.crewSettings).where(isNotNull(schema.crewSettings.formId))
78
+ ]);
79
+ const taken = new Set(used.filter((row) => row.operationId !== operationId).map((row) => row.formId));
80
+ return forms.filter((form) => (form.definition.access?.auth ?? "none") === "user" && form.definition.storage !== "none" && !taken.has(form.id)).map(({ id, name, slug, status }) => ({ id, name, slug, status }));
81
+ }
82
+ export async function saveCrewSettings(event, operationId, input) {
83
+ if (input.formId) await assertCrewForm(input.formId, operationId);
84
+ const previous = await findCrewSettings(operationId);
85
+ const team = await crewEnsureDefaultTeam(event, operationId, input.defaultTeamId);
86
+ const values = {
87
+ formId: input.formId ?? null,
88
+ defaultTeamId: team.id,
89
+ capacity: input.capacity ?? null,
90
+ waitlist: input.waitlist,
91
+ previousCrewFirst: input.previousCrewFirst,
92
+ opensAt: input.opensAt ?? null,
93
+ closesAt: input.closesAt ?? null,
94
+ statusEmails: input.statusEmails ?? null,
95
+ presets: previous ? previous.presets : input.presets
96
+ };
97
+ const [row] = await db.insert(schema.crewSettings).values({ operationId, ...values }).onConflictDoUpdate({ target: schema.crewSettings.operationId, set: { ...values, updatedAt: /* @__PURE__ */ new Date() } }).returning();
98
+ if (!previous && input.presets) await crewEnsurePresets(event, operationId);
99
+ return row;
100
+ }
@@ -0,0 +1,8 @@
1
+ /** SHA-256 of an invite token, base64url: what `crew_invites.tokenHash` stores. */
2
+ export declare function crewHashToken(token: string): Promise<string>;
3
+ /** A new random invite token (shown once), its hash and the first characters kept to recognise it. */
4
+ export declare function crewGenerateToken(): Promise<{
5
+ token: string;
6
+ tokenHash: string;
7
+ prefix: string;
8
+ }>;
@@ -0,0 +1,9 @@
1
+ import { randomToken, sha256Base64Url } from "@frigear-nu/module-kit/server";
2
+ const INVITE_TOKEN_PREFIX = "cvt_";
3
+ export async function crewHashToken(token) {
4
+ return sha256Base64Url(token);
5
+ }
6
+ export async function crewGenerateToken() {
7
+ const token = `${INVITE_TOKEN_PREFIX}${randomToken(32)}`;
8
+ return { token, tokenHash: await crewHashToken(token), prefix: token.slice(0, INVITE_TOKEN_PREFIX.length + 4) };
9
+ }
@@ -0,0 +1,172 @@
1
+ import type { H3Event } from 'h3';
2
+ import { schema } from '@nuxthub/db';
3
+ import type { SQL } from 'drizzle-orm';
4
+ import type { z } from 'zod';
5
+ import type { Page } from '@frigear-nu/module-kit/server';
6
+ import type { CrewApplyDto, CrewMemberDto, MyCrewDto, Translated } from '../../../types.js';
7
+ import type { CrewUserLite } from './crew-dto.js';
8
+ import type { crewMembersQuery } from './crew-schemas.js';
9
+ import type { CrewSettingsRow, CrewTeamRow } from './crew-settings.js';
10
+ export type CrewMemberRow = typeof schema.teamMembers.$inferSelect;
11
+ export type CrewOperationRow = typeof schema.operations.$inferSelect;
12
+ /** A crew membership with its team. */
13
+ export type CrewEntry = {
14
+ member: CrewMemberRow;
15
+ team: CrewTeamRow;
16
+ };
17
+ type MembersQuery = z.output<typeof crewMembersQuery>;
18
+ /** The name, email, avatar and phone number of users, by id (`loadUserRefs` of `@frigear-nu/users`, in chunks). */
19
+ export declare function crewUsersById(ids: number[]): Promise<Map<number, NonNullable<CrewUserLite>>>;
20
+ /**
21
+ * The crew membership of a user in an operation, or `undefined`: a `team_members` row with a `crewStatus` on a team the
22
+ * operation owns. Rows teams staff added by hand (no `crewStatus`) are not crew memberships. When a person has more than
23
+ * one (an invite filled a row on its own team and withdrew the older one), a live row wins over a withdrawn one, then
24
+ * the oldest.
25
+ */
26
+ export declare function findCrewEntry(userId: number, operationId: string): Promise<CrewEntry | undefined>;
27
+ /** The crew membership with this row id, or a 404. */
28
+ export declare function getCrewEntryOr404(id: string): Promise<CrewEntry>;
29
+ /**
30
+ * The ONE rule of who takes part in an operation, on a `team_members` row of a team it owns: a membership that grants
31
+ * (`status` null or `active`, teams' rule) that is either a plain one (added in teams, no `crewStatus`) or an approved
32
+ * crew row. Applied, waitlisted, rejected and withdrawn people do not take part. My crew, the apply page and the
33
+ * `operations:participation:resolve` / `operations:participants:resolve` answers all use it, so everyone who takes part
34
+ * (and can be given shifts) sees their crew. Mapped team roles are no rows, so a mapping rule never makes anyone take part.
35
+ */
36
+ export declare const crewTakesPart: () => SQL<unknown> | undefined;
37
+ /** Whether the user holds a role on a team of the operation that crew did not create (a hand-added teams member). */
38
+ export declare function crewHasPlainMembership(userId: number, operationId: string): Promise<boolean>;
39
+ /** Whether the user was approved in an earlier operation. */
40
+ export declare function crewIsPreviousCrew(operation: Pick<CrewOperationRow, 'id' | 'startsAt'>, userId: number): Promise<boolean>;
41
+ /** The DTO of one crew member; `pii` copies the email and phone number into it. */
42
+ export declare function crewMemberDtoOf(entry: CrewEntry, operation: Pick<CrewOperationRow, 'id' | 'startsAt'>, pii: boolean): Promise<CrewMemberDto>;
43
+ /** The DTO a staff response carries for a crew member: with the contact details only for a caller holding `crew:pii`. */
44
+ export declare function crewMemberResponse(event: H3Event, entry: CrewEntry): Promise<CrewMemberDto>;
45
+ /** The label of a role on the ladder of a team kind, as stored (a plain text or one per language); the key when unknown. */
46
+ export declare function crewRoleLabelOf(event: H3Event, kind: string, role: string): Promise<Translated>;
47
+ /** The label of a role on the ladder of a team kind, in `locale`. */
48
+ export declare function crewRoleLabel(event: H3Event, kind: string, role: string, locale?: string): Promise<string>;
49
+ /** My own crew status for one entry, with the role's label. */
50
+ export declare function crewMyEntryOf(event: H3Event, entry: CrewEntry, operation: Pick<CrewOperationRow, 'slug' | 'name'>): Promise<MyCrewDto>;
51
+ /**
52
+ * My crew status in every operation I take part in (`crewTakesPart`: an approved crew row or a membership added in
53
+ * teams) or applied to (my own crew rows in any other status). A teams-added row shows as an approved place
54
+ * (`source: 'teams'`), which only teams staff can end.
55
+ */
56
+ export declare function crewMyEntries(event: H3Event, userId: number): Promise<MyCrewDto[]>;
57
+ /** The ids of the operations a user takes part in (`operations:participation:resolve`). */
58
+ export declare function crewParticipationOperationIds(userId: number): Promise<string[]>;
59
+ /**
60
+ * The ids (as text) of the users who take part in any of `operationIds` (`operations:participants:resolve`), in queries
61
+ * under D1's bound parameter limit.
62
+ */
63
+ export declare function crewOperationParticipants(operationIds: string[]): Promise<string[]>;
64
+ /**
65
+ * Whether a user may read an operation, by the rule of `operations:read`: a public operation, one they take part in, or
66
+ * `operations:manage`. A private operation takes no applications from people who cannot read it.
67
+ */
68
+ export declare function crewUserReadsOperation(event: H3Event, operation: Pick<CrewOperationRow, 'id' | 'public'>, userId: number): Promise<boolean>;
69
+ /** Whether applications to an operation are open now, by its form, status and window. */
70
+ export declare function crewOpenState(operation: Pick<CrewOperationRow, 'status'>, settings: CrewSettingsRow | undefined, now?: Date): 'open' | 'scheduled' | 'closed' | 'unavailable';
71
+ /** What the apply page shows for this user: the form, or the reason why not. */
72
+ export declare function crewApplyDto(operation: CrewOperationRow, settings: CrewSettingsRow | undefined, userId: number): Promise<CrewApplyDto>;
73
+ /**
74
+ * Keeps the phone number of an application on the user (shown with `crew:pii`), under the rule of `@frigear-nu/users`
75
+ * (`parseUserPhone`: at most 40 digits, spaces and `+-().`). Anything else (not a string, empty, or breaking the rule)
76
+ * is ignored and leaves the stored number as it was.
77
+ */
78
+ export declare function crewStorePhone(userId: number, value: unknown): Promise<void>;
79
+ /** The primary language tag of the request (`da-DK,da;q=0.9` is `da`), or `undefined`. */
80
+ export declare function crewRequestLocale(event: H3Event): string | undefined;
81
+ /**
82
+ * Registers an application: a new `applied` (or `waitlisted`, because the crew is full) person on the operation's default
83
+ * team holding its lowest role without a grant. A person who has applied already is left as they are (`created: false`;
84
+ * a withdrawn one reopens their application, `created: true`), and `null` is returned for someone who already works on a
85
+ * team of the operation through teams.
86
+ */
87
+ export declare function crewApply(event: H3Event, input: {
88
+ operation: CrewOperationRow;
89
+ settings: CrewSettingsRow | undefined;
90
+ userId: number;
91
+ submissionId: string | null;
92
+ locale?: string;
93
+ }): Promise<{
94
+ entry: CrewEntry;
95
+ created: boolean;
96
+ } | null>;
97
+ /**
98
+ * Moves a crew member to `approved`, `rejected` or `waitlisted`. Approving may also set the team (of the same operation)
99
+ * and role. Asking for the status the person has is a no-op, so a double click does no harm; any other move the status
100
+ * table does not allow is a 409. The write is conditional on the status that was read: when somebody else moved the person
101
+ * first, the current row comes back and no hook fires and no email goes out. Fires the crew hook and sends the status email;
102
+ * a person leaving `approved` frees a place on the waiting list. Staff approval does not check the capacity.
103
+ */
104
+ export declare function crewDecide(event: H3Event, id: string, to: 'approved' | 'rejected' | 'waitlisted' | 'withdrawn', options?: {
105
+ by: number | null;
106
+ teamId?: string;
107
+ role?: string;
108
+ }): Promise<CrewEntry>;
109
+ /**
110
+ * Adds a person to an operation's crew, approved at once: staff picked them, so there is no application to decide. A
111
+ * person with no crew row in the operation gets one (on `teamId`, else the default team; `role`, else the lowest of the
112
+ * ladder). A withdrawn or rejected person's row is reused (`created: false`) and approved, on the given team and role
113
+ * when set. A person who is applied, waitlisted or approved already is a 409 with their `status` (and `memberId`), and
114
+ * so is someone who works on a team of the operation through teams. Fires the teams hooks and `crew:member:approved`
115
+ * and sends the approval message (`notifyUser`), like a staff approval. Staff adding does not check the capacity.
116
+ */
117
+ export declare function crewAddMember(event: H3Event, input: {
118
+ operation: CrewOperationRow;
119
+ userId: number;
120
+ teamId?: string;
121
+ role?: string;
122
+ by: number | null;
123
+ }): Promise<{
124
+ entry: CrewEntry;
125
+ created: boolean;
126
+ }>;
127
+ /**
128
+ * Approves people in turn. People who cannot be approved because of what they are (unknown, another operation's, in a
129
+ * status that cannot become approved: a 4xx) come back in `skipped`; any other failure is thrown.
130
+ */
131
+ export declare function crewApproveMany(event: H3Event, operationId: string, ids: string[], by: number | null): Promise<{
132
+ approved: CrewEntry[];
133
+ skipped: string[];
134
+ }>;
135
+ /** Moves a crew member to another team and/or role of the same operation (an approved person keeps their grant). */
136
+ export declare function crewMove(event: H3Event, id: string, input: {
137
+ teamId?: string;
138
+ role?: string;
139
+ }): Promise<CrewEntry>;
140
+ /**
141
+ * Fills the places the approved crew leaves free from the waiting list (when the operation has a capacity and a list), but
142
+ * only with people who were waitlisted because the crew was full (`waitlistReason: 'capacity'`): staff waitlisting is
143
+ * sticky. Previous crew go first when the setting is on, then in the order people joined the list. Each candidate is
144
+ * claimed with a conditional update and the capacity is checked again after the claim, so two requests promoting at once
145
+ * cannot overfill the crew: the claim that went over is put back, and the loop reads the count again (both requests may
146
+ * have put theirs back, so a place may still be free). A promotion fires the same hooks and email as an approval.
147
+ */
148
+ export declare function crewPromoteWaitlist(event: H3Event, operation: CrewOperationRow, settings: CrewSettingsRow | undefined): Promise<CrewEntry[]>;
149
+ /** Whether an operation is over for crew: wrapped up, archived, or past its end. Invites to it no longer work. */
150
+ export declare function crewOperationEnded(operation: Pick<CrewOperationRow, 'status' | 'endsAt'>, now?: Date): boolean;
151
+ /**
152
+ * Accepts an invite link for a signed-in user: the invite's team, approved, with the invite's role. A use is claimed
153
+ * atomically (`uses < maxUses`, not revoked, not expired), so a link with one use adds exactly one person even when it
154
+ * is opened twice at once; the use is given back only when writing the membership itself fails, not when a hook listener
155
+ * throws afterwards. 404 for an unknown token, 410 for a link that is revoked, expired or used up, or whose operation
156
+ * has ended (wrapped up, archived or past its end: `invite_unavailable`). 409
157
+ * `crew_already_member` when the user is approved anywhere in the operation (or holds a role there through teams), and 409
158
+ * `crew_rejected` for a rejected applicant: staff's decision wins. An applicant who is waiting or withdrawn is moved onto
159
+ * the team. An invite does not check the capacity.
160
+ */
161
+ export declare function crewAcceptInvite(event: H3Event, token: string, userId: number): Promise<MyCrewDto>;
162
+ /** The ids of the teams of an operation that a user leads (the ladder's lead role and up). */
163
+ export declare function crewLedTeamIds(event: H3Event, userId: number, operationId: string): Promise<string[]>;
164
+ /**
165
+ * One page of an operation's crew. `teamIds` limits it to those teams (what a lead may read; `[]` is nobody) and `pii`
166
+ * copies emails and phone numbers into the rows and lets the search match them.
167
+ */
168
+ export declare function crewMembersPage(operation: CrewOperationRow, query: MembersQuery, scope: {
169
+ teamIds?: string[];
170
+ pii: boolean;
171
+ }): Promise<Page<CrewMemberDto>>;
172
+ export {};