@noodleseed/one 0.97.0 → 0.98.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 (84) hide show
  1. package/dist/bin.js +0 -0
  2. package/node_modules/@noodle-borg/service/dist/billing/stripe-provider.d.ts +4 -2
  3. package/node_modules/@noodle-borg/service/dist/billing/stripe-provider.d.ts.map +1 -1
  4. package/node_modules/@noodle-borg/service/dist/billing/stripe-provider.js +4 -26
  5. package/node_modules/@noodle-borg/service/dist/billing/stripe-provider.js.map +1 -1
  6. package/node_modules/@noodle-borg/service/dist/billing/stripe-service.d.ts +1 -0
  7. package/node_modules/@noodle-borg/service/dist/billing/stripe-service.d.ts.map +1 -1
  8. package/node_modules/@noodle-borg/service/dist/billing/stripe-service.js +7 -3
  9. package/node_modules/@noodle-borg/service/dist/billing/stripe-service.js.map +1 -1
  10. package/node_modules/@noodle-borg/service/dist/billing/stripe-webhook.d.ts +10 -0
  11. package/node_modules/@noodle-borg/service/dist/billing/stripe-webhook.d.ts.map +1 -0
  12. package/node_modules/@noodle-borg/service/dist/billing/stripe-webhook.js +133 -0
  13. package/node_modules/@noodle-borg/service/dist/billing/stripe-webhook.js.map +1 -0
  14. package/node_modules/@noodle-borg/service/dist/feedback-operations/bootstrap.d.ts +7 -0
  15. package/node_modules/@noodle-borg/service/dist/feedback-operations/bootstrap.d.ts.map +1 -0
  16. package/node_modules/@noodle-borg/service/dist/feedback-operations/bootstrap.js +23 -0
  17. package/node_modules/@noodle-borg/service/dist/feedback-operations/bootstrap.js.map +1 -0
  18. package/node_modules/@noodle-borg/service/dist/feedback-operations/config.d.ts +12 -0
  19. package/node_modules/@noodle-borg/service/dist/feedback-operations/config.d.ts.map +1 -0
  20. package/node_modules/@noodle-borg/service/dist/feedback-operations/config.js +47 -0
  21. package/node_modules/@noodle-borg/service/dist/feedback-operations/config.js.map +1 -0
  22. package/node_modules/@noodle-borg/service/dist/feedback-operations/contracts.d.ts +24 -0
  23. package/node_modules/@noodle-borg/service/dist/feedback-operations/contracts.d.ts.map +1 -0
  24. package/node_modules/@noodle-borg/service/dist/feedback-operations/contracts.js +2 -0
  25. package/node_modules/@noodle-borg/service/dist/feedback-operations/contracts.js.map +1 -0
  26. package/node_modules/@noodle-borg/service/dist/feedback-operations/delivery-worker.d.ts +29 -0
  27. package/node_modules/@noodle-borg/service/dist/feedback-operations/delivery-worker.d.ts.map +1 -0
  28. package/node_modules/@noodle-borg/service/dist/feedback-operations/delivery-worker.js +256 -0
  29. package/node_modules/@noodle-borg/service/dist/feedback-operations/delivery-worker.js.map +1 -0
  30. package/node_modules/@noodle-borg/service/dist/feedback-operations/linear-client.d.ts +39 -0
  31. package/node_modules/@noodle-borg/service/dist/feedback-operations/linear-client.d.ts.map +1 -0
  32. package/node_modules/@noodle-borg/service/dist/feedback-operations/linear-client.js +142 -0
  33. package/node_modules/@noodle-borg/service/dist/feedback-operations/linear-client.js.map +1 -0
  34. package/node_modules/@noodle-borg/service/dist/feedback-operations/reporter-email.d.ts +33 -0
  35. package/node_modules/@noodle-borg/service/dist/feedback-operations/reporter-email.d.ts.map +1 -0
  36. package/node_modules/@noodle-borg/service/dist/feedback-operations/reporter-email.js +142 -0
  37. package/node_modules/@noodle-borg/service/dist/feedback-operations/reporter-email.js.map +1 -0
  38. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-card.d.ts +138 -0
  39. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-card.d.ts.map +1 -0
  40. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-card.js +199 -0
  41. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-card.js.map +1 -0
  42. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-client.d.ts +44 -0
  43. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-client.d.ts.map +1 -0
  44. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-client.js +95 -0
  45. package/node_modules/@noodle-borg/service/dist/feedback-operations/slack-client.js.map +1 -0
  46. package/node_modules/@noodle-borg/service/dist/main.js +38 -3
  47. package/node_modules/@noodle-borg/service/dist/main.js.map +1 -1
  48. package/node_modules/@noodle-borg/service/dist/options.d.ts +14 -0
  49. package/node_modules/@noodle-borg/service/dist/options.d.ts.map +1 -1
  50. package/node_modules/@noodle-borg/service/dist/routes/feedback-operations-dispatch.d.ts +9 -0
  51. package/node_modules/@noodle-borg/service/dist/routes/feedback-operations-dispatch.d.ts.map +1 -0
  52. package/node_modules/@noodle-borg/service/dist/routes/feedback-operations-dispatch.js +53 -0
  53. package/node_modules/@noodle-borg/service/dist/routes/feedback-operations-dispatch.js.map +1 -0
  54. package/node_modules/@noodle-borg/service/dist/routes/feedback.d.ts +2 -0
  55. package/node_modules/@noodle-borg/service/dist/routes/feedback.d.ts.map +1 -1
  56. package/node_modules/@noodle-borg/service/dist/routes/feedback.js +22 -0
  57. package/node_modules/@noodle-borg/service/dist/routes/feedback.js.map +1 -1
  58. package/node_modules/@noodle-borg/service/dist/routes/linear-feedback-webhook.d.ts +17 -0
  59. package/node_modules/@noodle-borg/service/dist/routes/linear-feedback-webhook.d.ts.map +1 -0
  60. package/node_modules/@noodle-borg/service/dist/routes/linear-feedback-webhook.js +141 -0
  61. package/node_modules/@noodle-borg/service/dist/routes/linear-feedback-webhook.js.map +1 -0
  62. package/node_modules/@noodle-borg/service/dist/routes/slack-feedback-actions.d.ts +13 -0
  63. package/node_modules/@noodle-borg/service/dist/routes/slack-feedback-actions.d.ts.map +1 -0
  64. package/node_modules/@noodle-borg/service/dist/routes/slack-feedback-actions.js +99 -0
  65. package/node_modules/@noodle-borg/service/dist/routes/slack-feedback-actions.js.map +1 -0
  66. package/node_modules/@noodle-borg/service/dist/serve.d.ts.map +1 -1
  67. package/node_modules/@noodle-borg/service/dist/serve.js +23 -0
  68. package/node_modules/@noodle-borg/service/dist/serve.js.map +1 -1
  69. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.d.ts +1 -0
  70. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.d.ts.map +1 -1
  71. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.js +2 -0
  72. package/node_modules/@noodle-borg/service/dist/service-resource-cleanup.js.map +1 -1
  73. package/node_modules/@noodle-borg/service/dist/service.d.ts.map +1 -1
  74. package/node_modules/@noodle-borg/service/dist/service.js +6 -0
  75. package/node_modules/@noodle-borg/service/dist/service.js.map +1 -1
  76. package/node_modules/@noodle-borg/service/dist/store/feedback-operations.d.ts +186 -0
  77. package/node_modules/@noodle-borg/service/dist/store/feedback-operations.d.ts.map +1 -0
  78. package/node_modules/@noodle-borg/service/dist/store/feedback-operations.js +483 -0
  79. package/node_modules/@noodle-borg/service/dist/store/feedback-operations.js.map +1 -0
  80. package/node_modules/@noodle-borg/service/dist/store/postgres-feedback-operations.d.ts +35 -0
  81. package/node_modules/@noodle-borg/service/dist/store/postgres-feedback-operations.d.ts.map +1 -0
  82. package/node_modules/@noodle-borg/service/dist/store/postgres-feedback-operations.js +172 -0
  83. package/node_modules/@noodle-borg/service/dist/store/postgres-feedback-operations.js.map +1 -0
  84. package/package.json +1 -1
@@ -0,0 +1,186 @@
1
+ import type { LinearWorkflowStateType } from '../feedback-operations/contracts.js';
2
+ export interface LinearFeedbackSnapshot {
3
+ readonly id: string;
4
+ readonly identifier: string;
5
+ readonly url: string;
6
+ readonly title: string;
7
+ readonly description: string;
8
+ readonly status: {
9
+ readonly id: string;
10
+ readonly name: string;
11
+ readonly type: LinearWorkflowStateType;
12
+ };
13
+ readonly assigneeName?: string | undefined;
14
+ readonly labels: readonly string[];
15
+ }
16
+ export interface FeedbackOperationsRecord {
17
+ readonly id: string;
18
+ readonly trustedReporter: boolean;
19
+ readonly githubIssueNumber?: number | undefined;
20
+ readonly githubIssueUrl?: string | undefined;
21
+ readonly title: string;
22
+ readonly message: string;
23
+ readonly reporterEmail?: string | undefined;
24
+ readonly createdAt: string;
25
+ readonly linearIssueId?: string | undefined;
26
+ readonly linearIdentifier?: string | undefined;
27
+ readonly linearUrl?: string | undefined;
28
+ readonly linearStatus?: LinearFeedbackSnapshot['status'] | undefined;
29
+ readonly linearAssigneeName?: string | undefined;
30
+ readonly linearLabels: readonly string[];
31
+ readonly slackChannelId?: string | undefined;
32
+ readonly slackMessageTs?: string | undefined;
33
+ readonly slackAttemptCount: number;
34
+ readonly slackNextAttemptAt?: string | undefined;
35
+ readonly slackLeaseExpiresAt?: string | undefined;
36
+ readonly slackLastDeliveredAt?: string | undefined;
37
+ readonly slackSuppressedAt?: string | undefined;
38
+ readonly firstInProgressAt?: string | undefined;
39
+ readonly acceptedAt?: string | undefined;
40
+ readonly emailAttemptCount: number;
41
+ readonly emailNextAttemptAt?: string | undefined;
42
+ readonly emailLeaseExpiresAt?: string | undefined;
43
+ readonly emailFirstAttemptAt?: string | undefined;
44
+ readonly emailSentAt?: string | undefined;
45
+ readonly emailProviderMessageId?: string | undefined;
46
+ readonly emailSuppressedAt?: string | undefined;
47
+ readonly emailDeliveryUnknownAt?: string | undefined;
48
+ }
49
+ export interface StartWorkCommand {
50
+ readonly actionKey: string;
51
+ readonly linearIssueId: string;
52
+ readonly slackUserId: string;
53
+ readonly responseUrl: string;
54
+ readonly createdAt: string;
55
+ readonly attemptCount: number;
56
+ readonly nextAttemptAt: string;
57
+ readonly leaseExpiresAt?: string | undefined;
58
+ readonly completedAt?: string | undefined;
59
+ }
60
+ export interface FeedbackOperationsStore {
61
+ createTrustedFeedback(input: {
62
+ githubIssueNumber: number;
63
+ githubIssueUrl: string;
64
+ title: string;
65
+ message: string;
66
+ reporterEmail: string;
67
+ createdAt: string;
68
+ }): Promise<FeedbackOperationsRecord>;
69
+ getByGithubIssueNumber(issueNumber: number): Promise<FeedbackOperationsRecord | undefined>;
70
+ getByLinearIssueId(linearIssueId: string): Promise<FeedbackOperationsRecord | undefined>;
71
+ getBySlackMessage(channelId: string, messageTs: string): Promise<FeedbackOperationsRecord | undefined>;
72
+ applyLinearEvent(input: {
73
+ deliveryId: string;
74
+ eventCreatedAt: string;
75
+ enteredInProgress: boolean;
76
+ githubIssueNumber?: number;
77
+ issue: LinearFeedbackSnapshot;
78
+ }): Promise<{
79
+ duplicate: boolean;
80
+ bindingConflict: boolean;
81
+ slackEnqueued: boolean;
82
+ emailEnqueued: boolean;
83
+ record?: FeedbackOperationsRecord;
84
+ }>;
85
+ claimSlackDelivery(input: {
86
+ now: Date;
87
+ leaseMs: number;
88
+ }): Promise<FeedbackOperationsRecord | undefined>;
89
+ markSlackDelivered(input: {
90
+ recordId: string;
91
+ channelId: string;
92
+ messageTs: string;
93
+ deliveredAt: string;
94
+ }): Promise<void>;
95
+ markSlackFailed(input: {
96
+ recordId: string;
97
+ nextAttemptAt: Date;
98
+ }): Promise<void>;
99
+ markSlackSuppressed(input: {
100
+ recordId: string;
101
+ suppressedAt: string;
102
+ }): Promise<void>;
103
+ claimReporterEmail(input: {
104
+ now: Date;
105
+ leaseMs: number;
106
+ }): Promise<FeedbackOperationsRecord | undefined>;
107
+ markReporterEmailSent(input: {
108
+ recordId: string;
109
+ providerMessageId: string;
110
+ sentAt: string;
111
+ }): Promise<void>;
112
+ markReporterEmailFailed(input: {
113
+ recordId: string;
114
+ nextAttemptAt: Date;
115
+ }): Promise<void>;
116
+ markReporterEmailSuppressed(input: {
117
+ recordId: string;
118
+ suppressedAt: string;
119
+ }): Promise<void>;
120
+ markReporterEmailUnknown(input: {
121
+ recordId: string;
122
+ unknownAt: string;
123
+ }): Promise<void>;
124
+ enqueueStartWork(input: {
125
+ actionKey: string;
126
+ linearIssueId: string;
127
+ slackUserId: string;
128
+ responseUrl: string;
129
+ createdAt: string;
130
+ }): Promise<{
131
+ created: boolean;
132
+ command: StartWorkCommand;
133
+ }>;
134
+ claimStartWork(input: {
135
+ now: Date;
136
+ leaseMs: number;
137
+ }): Promise<StartWorkCommand | undefined>;
138
+ markStartWorkCompleted(input: {
139
+ actionKey: string;
140
+ completedAt: string;
141
+ }): Promise<void>;
142
+ markStartWorkFailed(input: {
143
+ actionKey: string;
144
+ nextAttemptAt: Date;
145
+ }): Promise<void>;
146
+ }
147
+ export interface FeedbackOperationsStateSnapshot {
148
+ records: Record<string, FeedbackOperationsRecord>;
149
+ linearDeliveries: Record<string, string>;
150
+ startWork: Record<string, StartWorkCommand>;
151
+ }
152
+ export declare class InMemoryFeedbackOperationsStore implements FeedbackOperationsStore {
153
+ #private;
154
+ protected state: FeedbackOperationsStateSnapshot;
155
+ protected persistState: (state: FeedbackOperationsStateSnapshot) => Promise<void>;
156
+ constructor(options?: {
157
+ state?: FeedbackOperationsStateSnapshot;
158
+ persist?: (state: FeedbackOperationsStateSnapshot) => Promise<void>;
159
+ });
160
+ snapshot(): Promise<FeedbackOperationsStateSnapshot>;
161
+ createTrustedFeedback(input: Parameters<FeedbackOperationsStore['createTrustedFeedback']>[0]): Promise<FeedbackOperationsRecord>;
162
+ getByGithubIssueNumber(issueNumber: number): Promise<FeedbackOperationsRecord | undefined>;
163
+ getByLinearIssueId(linearIssueId: string): Promise<FeedbackOperationsRecord | undefined>;
164
+ getBySlackMessage(channelId: string, messageTs: string): Promise<FeedbackOperationsRecord | undefined>;
165
+ applyLinearEvent(input: Parameters<FeedbackOperationsStore['applyLinearEvent']>[0]): ReturnType<FeedbackOperationsStore['applyLinearEvent']>;
166
+ claimSlackDelivery(input: Parameters<FeedbackOperationsStore['claimSlackDelivery']>[0]): Promise<FeedbackOperationsRecord | undefined>;
167
+ markSlackDelivered(input: Parameters<FeedbackOperationsStore['markSlackDelivered']>[0]): Promise<void>;
168
+ markSlackFailed(input: Parameters<FeedbackOperationsStore['markSlackFailed']>[0]): Promise<void>;
169
+ markSlackSuppressed(input: Parameters<FeedbackOperationsStore['markSlackSuppressed']>[0]): Promise<void>;
170
+ claimReporterEmail(input: Parameters<FeedbackOperationsStore['claimReporterEmail']>[0]): Promise<FeedbackOperationsRecord | undefined>;
171
+ markReporterEmailSent(input: Parameters<FeedbackOperationsStore['markReporterEmailSent']>[0]): Promise<void>;
172
+ markReporterEmailFailed(input: Parameters<FeedbackOperationsStore['markReporterEmailFailed']>[0]): Promise<void>;
173
+ markReporterEmailSuppressed(input: Parameters<FeedbackOperationsStore['markReporterEmailSuppressed']>[0]): Promise<void>;
174
+ markReporterEmailUnknown(input: Parameters<FeedbackOperationsStore['markReporterEmailUnknown']>[0]): Promise<void>;
175
+ enqueueStartWork(input: Parameters<FeedbackOperationsStore['enqueueStartWork']>[0]): ReturnType<FeedbackOperationsStore['enqueueStartWork']>;
176
+ claimStartWork(input: Parameters<FeedbackOperationsStore['claimStartWork']>[0]): Promise<StartWorkCommand | undefined>;
177
+ markStartWorkCompleted(input: Parameters<FeedbackOperationsStore['markStartWorkCompleted']>[0]): Promise<void>;
178
+ markStartWorkFailed(input: Parameters<FeedbackOperationsStore['markStartWorkFailed']>[0]): Promise<void>;
179
+ }
180
+ export declare class JsonFileFeedbackOperationsStore extends InMemoryFeedbackOperationsStore implements FeedbackOperationsStore {
181
+ #private;
182
+ constructor(directory: string);
183
+ ensureReady(): Promise<void>;
184
+ }
185
+ export declare function validateFeedbackOperationsState(value: unknown): FeedbackOperationsStateSnapshot;
186
+ //# sourceMappingURL=feedback-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedback-operations.d.ts","sourceRoot":"","sources":["../../src/store/feedback-operations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAInF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,IAAI,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K,EAAE,OAAO,GAAG,+BAA+B,CAI/F"}
@@ -0,0 +1,483 @@
1
+ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { z } from 'zod';
4
+ const LINEAR_DELIVERY_REPLAY_WINDOW_MS = 48 * 60 * 60_000;
5
+ function emptyState() {
6
+ return { records: {}, linearDeliveries: {}, startWork: {} };
7
+ }
8
+ export class InMemoryFeedbackOperationsStore {
9
+ state;
10
+ persistState;
11
+ #tail = Promise.resolve();
12
+ constructor(options = {}) {
13
+ this.state = options.state ?? emptyState();
14
+ this.persistState = options.persist ?? (() => Promise.resolve());
15
+ }
16
+ snapshot() {
17
+ return this.#read(() => structuredClone(this.state));
18
+ }
19
+ createTrustedFeedback(input) {
20
+ return this.#write(() => {
21
+ const existing = this.#byGithub(input.githubIssueNumber);
22
+ if (existing !== undefined) {
23
+ if (existing.trustedReporter)
24
+ return existing;
25
+ const firstAcceptance = existing.firstInProgressAt !== undefined && existing.acceptedAt === undefined;
26
+ const upgraded = {
27
+ ...existing,
28
+ trustedReporter: true,
29
+ githubIssueUrl: input.githubIssueUrl,
30
+ title: input.title,
31
+ message: input.message,
32
+ reporterEmail: normalizeEmail(input.reporterEmail),
33
+ createdAt: input.createdAt,
34
+ ...(firstAcceptance
35
+ ? {
36
+ acceptedAt: existing.firstInProgressAt,
37
+ emailNextAttemptAt: input.createdAt,
38
+ }
39
+ : {}),
40
+ };
41
+ this.state.records[existing.id] = upgraded;
42
+ return upgraded;
43
+ }
44
+ const id = `github:${input.githubIssueNumber}`;
45
+ const record = {
46
+ id,
47
+ trustedReporter: true,
48
+ githubIssueNumber: input.githubIssueNumber,
49
+ githubIssueUrl: input.githubIssueUrl,
50
+ title: input.title,
51
+ message: input.message,
52
+ reporterEmail: normalizeEmail(input.reporterEmail),
53
+ createdAt: input.createdAt,
54
+ linearLabels: [],
55
+ slackAttemptCount: 0,
56
+ emailAttemptCount: 0,
57
+ };
58
+ this.state.records[id] = record;
59
+ return record;
60
+ });
61
+ }
62
+ getByGithubIssueNumber(issueNumber) {
63
+ return this.#read(() => this.#byGithub(issueNumber));
64
+ }
65
+ getByLinearIssueId(linearIssueId) {
66
+ return this.#read(() => Object.values(this.state.records).find((record) => record.linearIssueId === linearIssueId));
67
+ }
68
+ getBySlackMessage(channelId, messageTs) {
69
+ return this.#read(() => Object.values(this.state.records).find((record) => record.slackChannelId === channelId && record.slackMessageTs === messageTs));
70
+ }
71
+ applyLinearEvent(input) {
72
+ return this.#write(() => {
73
+ const cutoff = Date.parse(input.eventCreatedAt) - LINEAR_DELIVERY_REPLAY_WINDOW_MS;
74
+ for (const [deliveryId, createdAt] of Object.entries(this.state.linearDeliveries)) {
75
+ if (Date.parse(createdAt) < cutoff)
76
+ delete this.state.linearDeliveries[deliveryId];
77
+ }
78
+ if (this.state.linearDeliveries[input.deliveryId] !== undefined) {
79
+ return {
80
+ duplicate: true,
81
+ bindingConflict: false,
82
+ slackEnqueued: false,
83
+ emailEnqueued: false,
84
+ };
85
+ }
86
+ const byLinear = Object.values(this.state.records).find((record) => record.linearIssueId === input.issue.id);
87
+ const byGithub = input.githubIssueNumber === undefined ? undefined : this.#byGithub(input.githubIssueNumber);
88
+ const linearConflict = input.githubIssueNumber !== undefined &&
89
+ byLinear?.githubIssueNumber !== undefined &&
90
+ byLinear.githubIssueNumber !== input.githubIssueNumber;
91
+ const githubConflict = byGithub?.linearIssueId !== undefined && byGithub.linearIssueId !== input.issue.id;
92
+ if (linearConflict || githubConflict) {
93
+ return {
94
+ duplicate: false,
95
+ bindingConflict: true,
96
+ slackEnqueued: false,
97
+ emailEnqueued: false,
98
+ };
99
+ }
100
+ this.state.linearDeliveries[input.deliveryId] = input.eventCreatedAt;
101
+ let current = byGithub ?? byLinear;
102
+ if (byGithub !== undefined && byLinear !== undefined && byGithub.id !== byLinear.id) {
103
+ current = {
104
+ ...byGithub,
105
+ ...definedDeliveryState(byLinear),
106
+ slackAttemptCount: Math.max(byGithub.slackAttemptCount, byLinear.slackAttemptCount),
107
+ emailAttemptCount: Math.max(byGithub.emailAttemptCount, byLinear.emailAttemptCount),
108
+ };
109
+ delete this.state.records[byLinear.id];
110
+ }
111
+ current ??= {
112
+ id: `linear:${input.issue.id}`,
113
+ trustedReporter: false,
114
+ ...(input.githubIssueNumber !== undefined
115
+ ? { githubIssueNumber: input.githubIssueNumber }
116
+ : {}),
117
+ title: input.issue.title,
118
+ message: input.issue.description,
119
+ createdAt: input.eventCreatedAt,
120
+ linearLabels: [],
121
+ slackAttemptCount: 0,
122
+ emailAttemptCount: 0,
123
+ };
124
+ const firstInProgressAt = current.firstInProgressAt ?? (input.enteredInProgress ? input.eventCreatedAt : undefined);
125
+ const firstAcceptance = firstInProgressAt !== undefined &&
126
+ current.trustedReporter &&
127
+ current.reporterEmail !== undefined &&
128
+ current.acceptedAt === undefined;
129
+ const updated = {
130
+ ...current,
131
+ title: current.trustedReporter ? current.title : input.issue.title,
132
+ message: current.trustedReporter ? current.message : input.issue.description,
133
+ linearIssueId: input.issue.id,
134
+ linearIdentifier: input.issue.identifier,
135
+ linearUrl: input.issue.url,
136
+ linearStatus: input.issue.status,
137
+ ...(input.issue.assigneeName !== undefined
138
+ ? { linearAssigneeName: input.issue.assigneeName }
139
+ : {}),
140
+ linearLabels: [...input.issue.labels],
141
+ slackNextAttemptAt: input.eventCreatedAt,
142
+ ...(firstInProgressAt !== undefined ? { firstInProgressAt } : {}),
143
+ ...(firstAcceptance
144
+ ? { acceptedAt: firstInProgressAt, emailNextAttemptAt: input.eventCreatedAt }
145
+ : {}),
146
+ };
147
+ this.state.records[updated.id] = updated;
148
+ return {
149
+ duplicate: false,
150
+ bindingConflict: false,
151
+ slackEnqueued: true,
152
+ emailEnqueued: firstAcceptance,
153
+ record: updated,
154
+ };
155
+ });
156
+ }
157
+ claimSlackDelivery(input) {
158
+ return this.#claimRecord('slack', input);
159
+ }
160
+ markSlackDelivered(input) {
161
+ return this.#updateRecord(input.recordId, (record) => {
162
+ const { slackNextAttemptAt: _nextAttempt, slackLeaseExpiresAt: _lease, ...pendingCleared } = record;
163
+ return {
164
+ ...pendingCleared,
165
+ slackChannelId: input.channelId,
166
+ slackMessageTs: input.messageTs,
167
+ slackLastDeliveredAt: input.deliveredAt,
168
+ };
169
+ });
170
+ }
171
+ markSlackFailed(input) {
172
+ return this.#updateRecord(input.recordId, (record) => {
173
+ const { slackLeaseExpiresAt: _lease, ...leaseCleared } = record;
174
+ return { ...leaseCleared, slackNextAttemptAt: input.nextAttemptAt.toISOString() };
175
+ });
176
+ }
177
+ markSlackSuppressed(input) {
178
+ return this.#updateRecord(input.recordId, (record) => {
179
+ const { slackNextAttemptAt: _nextAttempt, slackLeaseExpiresAt: _lease, ...pendingCleared } = record;
180
+ return { ...pendingCleared, slackSuppressedAt: input.suppressedAt };
181
+ });
182
+ }
183
+ claimReporterEmail(input) {
184
+ return this.#claimRecord('email', input);
185
+ }
186
+ markReporterEmailSent(input) {
187
+ return this.#updateRecord(input.recordId, (record) => {
188
+ const { emailNextAttemptAt: _nextAttempt, emailLeaseExpiresAt: _lease, ...pendingCleared } = record;
189
+ return {
190
+ ...pendingCleared,
191
+ emailSentAt: input.sentAt,
192
+ emailProviderMessageId: input.providerMessageId,
193
+ slackNextAttemptAt: input.sentAt,
194
+ };
195
+ });
196
+ }
197
+ markReporterEmailFailed(input) {
198
+ return this.#updateRecord(input.recordId, (record) => {
199
+ const { emailLeaseExpiresAt: _lease, ...leaseCleared } = record;
200
+ const nextAttemptAt = input.nextAttemptAt.toISOString();
201
+ return {
202
+ ...leaseCleared,
203
+ emailNextAttemptAt: nextAttemptAt,
204
+ slackNextAttemptAt: nextAttemptAt,
205
+ };
206
+ });
207
+ }
208
+ markReporterEmailSuppressed(input) {
209
+ return this.#updateRecord(input.recordId, (record) => {
210
+ const { emailNextAttemptAt: _nextAttempt, emailLeaseExpiresAt: _lease, ...pendingCleared } = record;
211
+ return {
212
+ ...pendingCleared,
213
+ emailSuppressedAt: input.suppressedAt,
214
+ slackNextAttemptAt: input.suppressedAt,
215
+ };
216
+ });
217
+ }
218
+ markReporterEmailUnknown(input) {
219
+ return this.#updateRecord(input.recordId, (record) => {
220
+ const { emailNextAttemptAt: _nextAttempt, emailLeaseExpiresAt: _lease, ...pendingCleared } = record;
221
+ return {
222
+ ...pendingCleared,
223
+ emailDeliveryUnknownAt: input.unknownAt,
224
+ slackNextAttemptAt: input.unknownAt,
225
+ };
226
+ });
227
+ }
228
+ enqueueStartWork(input) {
229
+ return this.#write(() => {
230
+ const existing = this.state.startWork[input.actionKey];
231
+ if (existing !== undefined)
232
+ return { created: false, command: existing };
233
+ const command = {
234
+ ...input,
235
+ attemptCount: 0,
236
+ nextAttemptAt: input.createdAt,
237
+ };
238
+ this.state.startWork[input.actionKey] = command;
239
+ return { created: true, command };
240
+ });
241
+ }
242
+ claimStartWork(input) {
243
+ return this.#write(() => {
244
+ const nowMs = input.now.getTime();
245
+ const command = Object.values(this.state.startWork)
246
+ .filter((candidate) => candidate.completedAt === undefined &&
247
+ Date.parse(candidate.nextAttemptAt) <= nowMs &&
248
+ (candidate.leaseExpiresAt === undefined ||
249
+ Date.parse(candidate.leaseExpiresAt) <= nowMs))
250
+ .sort((a, b) => a.createdAt.localeCompare(b.createdAt))[0];
251
+ if (command === undefined)
252
+ return undefined;
253
+ const claimed = {
254
+ ...command,
255
+ attemptCount: command.attemptCount + 1,
256
+ leaseExpiresAt: new Date(nowMs + input.leaseMs).toISOString(),
257
+ };
258
+ this.state.startWork[command.actionKey] = claimed;
259
+ return claimed;
260
+ });
261
+ }
262
+ markStartWorkCompleted(input) {
263
+ return this.#updateCommand(input.actionKey, (command) => {
264
+ const { leaseExpiresAt: _lease, ...leaseCleared } = command;
265
+ return { ...leaseCleared, completedAt: input.completedAt };
266
+ });
267
+ }
268
+ markStartWorkFailed(input) {
269
+ return this.#updateCommand(input.actionKey, (command) => {
270
+ const { leaseExpiresAt: _lease, ...leaseCleared } = command;
271
+ return { ...leaseCleared, nextAttemptAt: input.nextAttemptAt.toISOString() };
272
+ });
273
+ }
274
+ #claimRecord(kind, input) {
275
+ return this.#write(() => {
276
+ const nowMs = input.now.getTime();
277
+ const record = Object.values(this.state.records)
278
+ .filter((candidate) => {
279
+ const next = kind === 'slack' ? candidate.slackNextAttemptAt : candidate.emailNextAttemptAt;
280
+ const lease = kind === 'slack' ? candidate.slackLeaseExpiresAt : candidate.emailLeaseExpiresAt;
281
+ const complete = kind === 'email' &&
282
+ (candidate.emailSentAt !== undefined ||
283
+ candidate.emailSuppressedAt !== undefined ||
284
+ candidate.emailDeliveryUnknownAt !== undefined);
285
+ return (!complete &&
286
+ next !== undefined &&
287
+ Date.parse(next) <= nowMs &&
288
+ (lease === undefined || Date.parse(lease) <= nowMs));
289
+ })
290
+ .sort((a, b) => a.createdAt.localeCompare(b.createdAt))[0];
291
+ if (record === undefined)
292
+ return undefined;
293
+ const leaseExpiresAt = new Date(nowMs + input.leaseMs).toISOString();
294
+ const claimed = kind === 'slack'
295
+ ? {
296
+ ...record,
297
+ slackAttemptCount: record.slackAttemptCount + 1,
298
+ slackLeaseExpiresAt: leaseExpiresAt,
299
+ }
300
+ : {
301
+ ...record,
302
+ emailAttemptCount: record.emailAttemptCount + 1,
303
+ emailLeaseExpiresAt: leaseExpiresAt,
304
+ emailFirstAttemptAt: record.emailFirstAttemptAt ?? input.now.toISOString(),
305
+ };
306
+ this.state.records[record.id] = claimed;
307
+ return claimed;
308
+ });
309
+ }
310
+ #updateRecord(recordId, update) {
311
+ return this.#write(() => {
312
+ const record = this.state.records[recordId];
313
+ if (record === undefined)
314
+ throw new Error('feedback operations record not found');
315
+ this.state.records[recordId] = update(record);
316
+ });
317
+ }
318
+ #updateCommand(actionKey, update) {
319
+ return this.#write(() => {
320
+ const command = this.state.startWork[actionKey];
321
+ if (command === undefined)
322
+ throw new Error('feedback start-work command not found');
323
+ this.state.startWork[actionKey] = update(command);
324
+ });
325
+ }
326
+ #byGithub(issueNumber) {
327
+ return Object.values(this.state.records).find((record) => record.githubIssueNumber === issueNumber);
328
+ }
329
+ #read(read) {
330
+ return this.#tail.then(read);
331
+ }
332
+ #write(write) {
333
+ const operation = this.#tail.then(async () => {
334
+ const previous = structuredClone(this.state);
335
+ try {
336
+ const result = write();
337
+ await this.persistState(this.state);
338
+ return result;
339
+ }
340
+ catch (error) {
341
+ this.state = previous;
342
+ throw error;
343
+ }
344
+ });
345
+ this.#tail = operation.then(() => undefined, () => undefined);
346
+ return operation;
347
+ }
348
+ }
349
+ export class JsonFileFeedbackOperationsStore extends InMemoryFeedbackOperationsStore {
350
+ #directory;
351
+ constructor(directory) {
352
+ super();
353
+ this.#directory = directory;
354
+ }
355
+ async ensureReady() {
356
+ await mkdir(this.#directory, { recursive: true });
357
+ const path = join(this.#directory, 'feedback-operations.json');
358
+ try {
359
+ this.state = validateFeedbackOperationsState(JSON.parse(await readFile(path, 'utf8')));
360
+ }
361
+ catch (error) {
362
+ if (error.code !== 'ENOENT')
363
+ throw error;
364
+ }
365
+ const directory = this.#directory;
366
+ this.persistState = async (next) => {
367
+ const target = join(directory, 'feedback-operations.json');
368
+ const temporary = `${target}.tmp`;
369
+ await writeFile(temporary, JSON.stringify(next), { encoding: 'utf8', mode: 0o600 });
370
+ await rename(temporary, target);
371
+ };
372
+ }
373
+ }
374
+ const TimestampSchema = z.iso.datetime();
375
+ const LinearStatusSchema = z.strictObject({
376
+ id: z.string().min(1),
377
+ name: z.string(),
378
+ type: z.enum(['backlog', 'unstarted', 'started', 'completed', 'canceled']),
379
+ });
380
+ const FeedbackOperationsRecordSchema = z.strictObject({
381
+ id: z.string().min(1),
382
+ trustedReporter: z.boolean(),
383
+ githubIssueNumber: z.number().int().positive().optional(),
384
+ githubIssueUrl: z.url().optional(),
385
+ title: z.string(),
386
+ message: z.string(),
387
+ reporterEmail: z.email().optional(),
388
+ createdAt: TimestampSchema,
389
+ linearIssueId: z.string().min(1).optional(),
390
+ linearIdentifier: z.string().min(1).optional(),
391
+ linearUrl: z.url().optional(),
392
+ linearStatus: LinearStatusSchema.optional(),
393
+ linearAssigneeName: z.string().optional(),
394
+ linearLabels: z.array(z.string()),
395
+ slackChannelId: z.string().min(1).optional(),
396
+ slackMessageTs: z.string().min(1).optional(),
397
+ slackAttemptCount: z.number().int().nonnegative(),
398
+ slackNextAttemptAt: TimestampSchema.optional(),
399
+ slackLeaseExpiresAt: TimestampSchema.optional(),
400
+ slackLastDeliveredAt: TimestampSchema.optional(),
401
+ slackSuppressedAt: TimestampSchema.optional(),
402
+ firstInProgressAt: TimestampSchema.optional(),
403
+ acceptedAt: TimestampSchema.optional(),
404
+ emailAttemptCount: z.number().int().nonnegative(),
405
+ emailNextAttemptAt: TimestampSchema.optional(),
406
+ emailLeaseExpiresAt: TimestampSchema.optional(),
407
+ emailFirstAttemptAt: TimestampSchema.optional(),
408
+ emailSentAt: TimestampSchema.optional(),
409
+ emailProviderMessageId: z.string().min(1).optional(),
410
+ emailSuppressedAt: TimestampSchema.optional(),
411
+ emailDeliveryUnknownAt: TimestampSchema.optional(),
412
+ });
413
+ const StartWorkCommandSchema = z.strictObject({
414
+ actionKey: z.string().min(1),
415
+ linearIssueId: z.string().min(1),
416
+ slackUserId: z.string().min(1),
417
+ responseUrl: z.url(),
418
+ createdAt: TimestampSchema,
419
+ attemptCount: z.number().int().nonnegative(),
420
+ nextAttemptAt: TimestampSchema,
421
+ leaseExpiresAt: TimestampSchema.optional(),
422
+ completedAt: TimestampSchema.optional(),
423
+ });
424
+ const FeedbackOperationsStateSchema = z.strictObject({
425
+ records: z.record(z.string(), FeedbackOperationsRecordSchema),
426
+ linearDeliveries: z.record(z.string(), TimestampSchema),
427
+ startWork: z.record(z.string(), StartWorkCommandSchema),
428
+ });
429
+ export function validateFeedbackOperationsState(value) {
430
+ const parsed = FeedbackOperationsStateSchema.safeParse(value);
431
+ if (!parsed.success)
432
+ throw new Error('invalid feedback operations state');
433
+ return parsed.data;
434
+ }
435
+ function normalizeEmail(value) {
436
+ const normalized = value.trim().toLowerCase();
437
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalized)) {
438
+ throw new Error('invalid feedback reporter email');
439
+ }
440
+ return normalized;
441
+ }
442
+ function definedDeliveryState(record) {
443
+ return {
444
+ ...(record.slackChannelId !== undefined ? { slackChannelId: record.slackChannelId } : {}),
445
+ ...(record.slackMessageTs !== undefined ? { slackMessageTs: record.slackMessageTs } : {}),
446
+ ...(record.slackNextAttemptAt !== undefined
447
+ ? { slackNextAttemptAt: record.slackNextAttemptAt }
448
+ : {}),
449
+ ...(record.slackLeaseExpiresAt !== undefined
450
+ ? { slackLeaseExpiresAt: record.slackLeaseExpiresAt }
451
+ : {}),
452
+ ...(record.slackLastDeliveredAt !== undefined
453
+ ? { slackLastDeliveredAt: record.slackLastDeliveredAt }
454
+ : {}),
455
+ ...(record.slackSuppressedAt !== undefined
456
+ ? { slackSuppressedAt: record.slackSuppressedAt }
457
+ : {}),
458
+ ...(record.firstInProgressAt !== undefined
459
+ ? { firstInProgressAt: record.firstInProgressAt }
460
+ : {}),
461
+ ...(record.acceptedAt !== undefined ? { acceptedAt: record.acceptedAt } : {}),
462
+ ...(record.emailNextAttemptAt !== undefined
463
+ ? { emailNextAttemptAt: record.emailNextAttemptAt }
464
+ : {}),
465
+ ...(record.emailLeaseExpiresAt !== undefined
466
+ ? { emailLeaseExpiresAt: record.emailLeaseExpiresAt }
467
+ : {}),
468
+ ...(record.emailFirstAttemptAt !== undefined
469
+ ? { emailFirstAttemptAt: record.emailFirstAttemptAt }
470
+ : {}),
471
+ ...(record.emailSentAt !== undefined ? { emailSentAt: record.emailSentAt } : {}),
472
+ ...(record.emailProviderMessageId !== undefined
473
+ ? { emailProviderMessageId: record.emailProviderMessageId }
474
+ : {}),
475
+ ...(record.emailSuppressedAt !== undefined
476
+ ? { emailSuppressedAt: record.emailSuppressedAt }
477
+ : {}),
478
+ ...(record.emailDeliveryUnknownAt !== undefined
479
+ ? { emailDeliveryUnknownAt: record.emailDeliveryUnknownAt }
480
+ : {}),
481
+ };
482
+ }
483
+ //# sourceMappingURL=feedback-operations.js.map