@shipfox/api-integration-github 2.0.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.
- package/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +138 -0
- package/LICENSE +21 -0
- package/dist/api/client.d.ts +90 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +306 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/installation-token-envelope.d.ts +36 -0
- package/dist/api/installation-token-envelope.d.ts.map +1 -0
- package/dist/api/installation-token-envelope.js +123 -0
- package/dist/api/installation-token-envelope.js.map +1 -0
- package/dist/api/installation-token-provider.d.ts +23 -0
- package/dist/api/installation-token-provider.d.ts.map +1 -0
- package/dist/api/installation-token-provider.js +130 -0
- package/dist/api/installation-token-provider.js.map +1 -0
- package/dist/api/shared-installation-token-cache.d.ts +43 -0
- package/dist/api/shared-installation-token-cache.d.ts.map +1 -0
- package/dist/api/shared-installation-token-cache.js +224 -0
- package/dist/api/shared-installation-token-cache.js.map +1 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/core/actions-logs.d.ts +47 -0
- package/dist/core/actions-logs.d.ts.map +1 -0
- package/dist/core/actions-logs.js +134 -0
- package/dist/core/actions-logs.js.map +1 -0
- package/dist/core/agent-tool-selection.d.ts +4 -0
- package/dist/core/agent-tool-selection.d.ts.map +1 -0
- package/dist/core/agent-tool-selection.js +38 -0
- package/dist/core/agent-tool-selection.js.map +1 -0
- package/dist/core/agent-tools.d.ts +50 -0
- package/dist/core/agent-tools.d.ts.map +1 -0
- package/dist/core/agent-tools.js +1122 -0
- package/dist/core/agent-tools.js.map +1 -0
- package/dist/core/errors.d.ts +15 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +22 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/install.d.ts +38 -0
- package/dist/core/install.d.ts.map +1 -0
- package/dist/core/install.js +64 -0
- package/dist/core/install.js.map +1 -0
- package/dist/core/source-control.d.ts +15 -0
- package/dist/core/source-control.d.ts.map +1 -0
- package/dist/core/source-control.js +175 -0
- package/dist/core/source-control.js.map +1 -0
- package/dist/core/state.d.ts +12 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +54 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/webhook.d.ts +20 -0
- package/dist/core/webhook.d.ts.map +1 -0
- package/dist/core/webhook.js +216 -0
- package/dist/core/webhook.js.map +1 -0
- package/dist/db/db.d.ts +433 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +18 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/installation-token-lock.d.ts +8 -0
- package/dist/db/installation-token-lock.d.ts.map +1 -0
- package/dist/db/installation-token-lock.js +37 -0
- package/dist/db/installation-token-lock.js.map +1 -0
- package/dist/db/installations.d.ts +33 -0
- package/dist/db/installations.d.ts.map +1 -0
- package/dist/db/installations.js +56 -0
- package/dist/db/installations.js.map +1 -0
- package/dist/db/migrations.d.ts +2 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +5 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/installations.d.ts +218 -0
- package/dist/db/schema/installations.d.ts.map +1 -0
- package/dist/db/schema/installations.js +46 -0
- package/dist/db/schema/installations.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +14 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +75 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/presentation/dto/integrations.d.ts +15 -0
- package/dist/presentation/dto/integrations.d.ts.map +1 -0
- package/dist/presentation/dto/integrations.js +10 -0
- package/dist/presentation/dto/integrations.js.map +1 -0
- package/dist/presentation/e2eRoutes/create-connection.d.ts +11 -0
- package/dist/presentation/e2eRoutes/create-connection.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/create-connection.js +57 -0
- package/dist/presentation/e2eRoutes/create-connection.js.map +1 -0
- package/dist/presentation/e2eRoutes/index.d.ts +5 -0
- package/dist/presentation/e2eRoutes/index.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/index.js +11 -0
- package/dist/presentation/e2eRoutes/index.js.map +1 -0
- package/dist/presentation/routes/errors.d.ts +2 -0
- package/dist/presentation/routes/errors.d.ts.map +1 -0
- package/dist/presentation/routes/errors.js +46 -0
- package/dist/presentation/routes/errors.js.map +1 -0
- package/dist/presentation/routes/install.d.ts +13 -0
- package/dist/presentation/routes/install.d.ts.map +1 -0
- package/dist/presentation/routes/install.js +77 -0
- package/dist/presentation/routes/install.js.map +1 -0
- package/dist/presentation/routes/webhooks.d.ts +16 -0
- package/dist/presentation/routes/webhooks.d.ts.map +1 -0
- package/dist/presentation/routes/webhooks.js +110 -0
- package/dist/presentation/routes/webhooks.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +17 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +71 -0
- package/src/api/client.test.ts +94 -0
- package/src/api/client.ts +525 -0
- package/src/api/installation-token-envelope.ts +171 -0
- package/src/api/installation-token-provider.test.ts +241 -0
- package/src/api/installation-token-provider.ts +224 -0
- package/src/api/shared-installation-token-cache.test.ts +294 -0
- package/src/api/shared-installation-token-cache.ts +346 -0
- package/src/config.test.ts +14 -0
- package/src/config.ts +47 -0
- package/src/connection-external-url.test.ts +78 -0
- package/src/core/actions-logs.test.ts +156 -0
- package/src/core/actions-logs.ts +186 -0
- package/src/core/agent-tool-selection.test.ts +41 -0
- package/src/core/agent-tool-selection.ts +42 -0
- package/src/core/agent-tools.test.ts +539 -0
- package/src/core/agent-tools.ts +1269 -0
- package/src/core/errors.ts +23 -0
- package/src/core/install.test.ts +238 -0
- package/src/core/install.ts +119 -0
- package/src/core/source-control.test.ts +327 -0
- package/src/core/source-control.ts +223 -0
- package/src/core/state.test.ts +43 -0
- package/src/core/state.ts +85 -0
- package/src/core/webhook.test.ts +522 -0
- package/src/core/webhook.ts +296 -0
- package/src/db/db.ts +18 -0
- package/src/db/installation-token-lock.test.ts +68 -0
- package/src/db/installation-token-lock.ts +39 -0
- package/src/db/installations.test.ts +67 -0
- package/src/db/installations.ts +108 -0
- package/src/db/migrations.ts +4 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/installations.ts +46 -0
- package/src/index.ts +124 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.ts +82 -0
- package/src/presentation/dto/integrations.ts +8 -0
- package/src/presentation/e2eRoutes/create-connection.ts +70 -0
- package/src/presentation/e2eRoutes/index.test.ts +126 -0
- package/src/presentation/e2eRoutes/index.ts +14 -0
- package/src/presentation/routes/errors.ts +43 -0
- package/src/presentation/routes/install.test.ts +279 -0
- package/src/presentation/routes/install.ts +93 -0
- package/src/presentation/routes/webhooks.test.ts +560 -0
- package/src/presentation/routes/webhooks.ts +115 -0
- package/test/env.ts +16 -0
- package/test/factories/github-installation.ts +35 -0
- package/test/factories/index.ts +1 -0
- package/test/fixtures/github-webhook.ts +20 -0
- package/test/globalSetup.ts +14 -0
- package/test/index.ts +2 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +9 -0
- package/vitest.config.ts +12 -0
package/dist/db/db.d.ts
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { type NodePgDatabase } from '@shipfox/node-drizzle';
|
|
2
|
+
export declare const schema: {
|
|
3
|
+
githubInstallations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
4
|
+
name: "installations";
|
|
5
|
+
schema: undefined;
|
|
6
|
+
columns: {
|
|
7
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
8
|
+
name: "id";
|
|
9
|
+
tableName: "installations";
|
|
10
|
+
dataType: "string";
|
|
11
|
+
columnType: "PgUUID";
|
|
12
|
+
data: string;
|
|
13
|
+
driverParam: string;
|
|
14
|
+
notNull: true;
|
|
15
|
+
hasDefault: true;
|
|
16
|
+
isPrimaryKey: true;
|
|
17
|
+
isAutoincrement: false;
|
|
18
|
+
hasRuntimeDefault: false;
|
|
19
|
+
enumValues: undefined;
|
|
20
|
+
baseColumn: never;
|
|
21
|
+
identity: undefined;
|
|
22
|
+
generated: undefined;
|
|
23
|
+
}, {}, {}>;
|
|
24
|
+
connectionId: import("drizzle-orm/pg-core").PgColumn<{
|
|
25
|
+
name: "connection_id";
|
|
26
|
+
tableName: "installations";
|
|
27
|
+
dataType: "string";
|
|
28
|
+
columnType: "PgUUID";
|
|
29
|
+
data: string;
|
|
30
|
+
driverParam: string;
|
|
31
|
+
notNull: true;
|
|
32
|
+
hasDefault: false;
|
|
33
|
+
isPrimaryKey: false;
|
|
34
|
+
isAutoincrement: false;
|
|
35
|
+
hasRuntimeDefault: false;
|
|
36
|
+
enumValues: undefined;
|
|
37
|
+
baseColumn: never;
|
|
38
|
+
identity: undefined;
|
|
39
|
+
generated: undefined;
|
|
40
|
+
}, {}, {}>;
|
|
41
|
+
installationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
42
|
+
name: "installation_id";
|
|
43
|
+
tableName: "installations";
|
|
44
|
+
dataType: "string";
|
|
45
|
+
columnType: "PgText";
|
|
46
|
+
data: string;
|
|
47
|
+
driverParam: string;
|
|
48
|
+
notNull: true;
|
|
49
|
+
hasDefault: false;
|
|
50
|
+
isPrimaryKey: false;
|
|
51
|
+
isAutoincrement: false;
|
|
52
|
+
hasRuntimeDefault: false;
|
|
53
|
+
enumValues: [string, ...string[]];
|
|
54
|
+
baseColumn: never;
|
|
55
|
+
identity: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}, {}, {}>;
|
|
58
|
+
accountLogin: import("drizzle-orm/pg-core").PgColumn<{
|
|
59
|
+
name: "account_login";
|
|
60
|
+
tableName: "installations";
|
|
61
|
+
dataType: "string";
|
|
62
|
+
columnType: "PgText";
|
|
63
|
+
data: string;
|
|
64
|
+
driverParam: string;
|
|
65
|
+
notNull: true;
|
|
66
|
+
hasDefault: false;
|
|
67
|
+
isPrimaryKey: false;
|
|
68
|
+
isAutoincrement: false;
|
|
69
|
+
hasRuntimeDefault: false;
|
|
70
|
+
enumValues: [string, ...string[]];
|
|
71
|
+
baseColumn: never;
|
|
72
|
+
identity: undefined;
|
|
73
|
+
generated: undefined;
|
|
74
|
+
}, {}, {}>;
|
|
75
|
+
accountType: import("drizzle-orm/pg-core").PgColumn<{
|
|
76
|
+
name: "account_type";
|
|
77
|
+
tableName: "installations";
|
|
78
|
+
dataType: "string";
|
|
79
|
+
columnType: "PgText";
|
|
80
|
+
data: string;
|
|
81
|
+
driverParam: string;
|
|
82
|
+
notNull: true;
|
|
83
|
+
hasDefault: false;
|
|
84
|
+
isPrimaryKey: false;
|
|
85
|
+
isAutoincrement: false;
|
|
86
|
+
hasRuntimeDefault: false;
|
|
87
|
+
enumValues: [string, ...string[]];
|
|
88
|
+
baseColumn: never;
|
|
89
|
+
identity: undefined;
|
|
90
|
+
generated: undefined;
|
|
91
|
+
}, {}, {}>;
|
|
92
|
+
repositorySelection: import("drizzle-orm/pg-core").PgColumn<{
|
|
93
|
+
name: "repository_selection";
|
|
94
|
+
tableName: "installations";
|
|
95
|
+
dataType: "string";
|
|
96
|
+
columnType: "PgText";
|
|
97
|
+
data: string;
|
|
98
|
+
driverParam: string;
|
|
99
|
+
notNull: true;
|
|
100
|
+
hasDefault: false;
|
|
101
|
+
isPrimaryKey: false;
|
|
102
|
+
isAutoincrement: false;
|
|
103
|
+
hasRuntimeDefault: false;
|
|
104
|
+
enumValues: [string, ...string[]];
|
|
105
|
+
baseColumn: never;
|
|
106
|
+
identity: undefined;
|
|
107
|
+
generated: undefined;
|
|
108
|
+
}, {}, {}>;
|
|
109
|
+
suspendedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
110
|
+
name: "suspended_at";
|
|
111
|
+
tableName: "installations";
|
|
112
|
+
dataType: "date";
|
|
113
|
+
columnType: "PgTimestamp";
|
|
114
|
+
data: Date;
|
|
115
|
+
driverParam: string;
|
|
116
|
+
notNull: false;
|
|
117
|
+
hasDefault: false;
|
|
118
|
+
isPrimaryKey: false;
|
|
119
|
+
isAutoincrement: false;
|
|
120
|
+
hasRuntimeDefault: false;
|
|
121
|
+
enumValues: undefined;
|
|
122
|
+
baseColumn: never;
|
|
123
|
+
identity: undefined;
|
|
124
|
+
generated: undefined;
|
|
125
|
+
}, {}, {}>;
|
|
126
|
+
deletedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
127
|
+
name: "deleted_at";
|
|
128
|
+
tableName: "installations";
|
|
129
|
+
dataType: "date";
|
|
130
|
+
columnType: "PgTimestamp";
|
|
131
|
+
data: Date;
|
|
132
|
+
driverParam: string;
|
|
133
|
+
notNull: false;
|
|
134
|
+
hasDefault: false;
|
|
135
|
+
isPrimaryKey: false;
|
|
136
|
+
isAutoincrement: false;
|
|
137
|
+
hasRuntimeDefault: false;
|
|
138
|
+
enumValues: undefined;
|
|
139
|
+
baseColumn: never;
|
|
140
|
+
identity: undefined;
|
|
141
|
+
generated: undefined;
|
|
142
|
+
}, {}, {}>;
|
|
143
|
+
latestEvent: import("drizzle-orm/pg-core").PgColumn<{
|
|
144
|
+
name: "latest_event";
|
|
145
|
+
tableName: "installations";
|
|
146
|
+
dataType: "json";
|
|
147
|
+
columnType: "PgJsonb";
|
|
148
|
+
data: Record<string, unknown>;
|
|
149
|
+
driverParam: unknown;
|
|
150
|
+
notNull: true;
|
|
151
|
+
hasDefault: false;
|
|
152
|
+
isPrimaryKey: false;
|
|
153
|
+
isAutoincrement: false;
|
|
154
|
+
hasRuntimeDefault: false;
|
|
155
|
+
enumValues: undefined;
|
|
156
|
+
baseColumn: never;
|
|
157
|
+
identity: undefined;
|
|
158
|
+
generated: undefined;
|
|
159
|
+
}, {}, {
|
|
160
|
+
$type: Record<string, unknown>;
|
|
161
|
+
}>;
|
|
162
|
+
installerUserId: import("drizzle-orm/pg-core").PgColumn<{
|
|
163
|
+
name: "installer_user_id";
|
|
164
|
+
tableName: "installations";
|
|
165
|
+
dataType: "string";
|
|
166
|
+
columnType: "PgUUID";
|
|
167
|
+
data: string;
|
|
168
|
+
driverParam: string;
|
|
169
|
+
notNull: false;
|
|
170
|
+
hasDefault: false;
|
|
171
|
+
isPrimaryKey: false;
|
|
172
|
+
isAutoincrement: false;
|
|
173
|
+
hasRuntimeDefault: false;
|
|
174
|
+
enumValues: undefined;
|
|
175
|
+
baseColumn: never;
|
|
176
|
+
identity: undefined;
|
|
177
|
+
generated: undefined;
|
|
178
|
+
}, {}, {}>;
|
|
179
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
180
|
+
name: "created_at";
|
|
181
|
+
tableName: "installations";
|
|
182
|
+
dataType: "date";
|
|
183
|
+
columnType: "PgTimestamp";
|
|
184
|
+
data: Date;
|
|
185
|
+
driverParam: string;
|
|
186
|
+
notNull: true;
|
|
187
|
+
hasDefault: true;
|
|
188
|
+
isPrimaryKey: false;
|
|
189
|
+
isAutoincrement: false;
|
|
190
|
+
hasRuntimeDefault: false;
|
|
191
|
+
enumValues: undefined;
|
|
192
|
+
baseColumn: never;
|
|
193
|
+
identity: undefined;
|
|
194
|
+
generated: undefined;
|
|
195
|
+
}, {}, {}>;
|
|
196
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
197
|
+
name: "updated_at";
|
|
198
|
+
tableName: "installations";
|
|
199
|
+
dataType: "date";
|
|
200
|
+
columnType: "PgTimestamp";
|
|
201
|
+
data: Date;
|
|
202
|
+
driverParam: string;
|
|
203
|
+
notNull: true;
|
|
204
|
+
hasDefault: true;
|
|
205
|
+
isPrimaryKey: false;
|
|
206
|
+
isAutoincrement: false;
|
|
207
|
+
hasRuntimeDefault: false;
|
|
208
|
+
enumValues: undefined;
|
|
209
|
+
baseColumn: never;
|
|
210
|
+
identity: undefined;
|
|
211
|
+
generated: undefined;
|
|
212
|
+
}, {}, {}>;
|
|
213
|
+
};
|
|
214
|
+
dialect: "pg";
|
|
215
|
+
}>;
|
|
216
|
+
};
|
|
217
|
+
export declare function db(): NodePgDatabase<{
|
|
218
|
+
githubInstallations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
219
|
+
name: "installations";
|
|
220
|
+
schema: undefined;
|
|
221
|
+
columns: {
|
|
222
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
223
|
+
name: "id";
|
|
224
|
+
tableName: "installations";
|
|
225
|
+
dataType: "string";
|
|
226
|
+
columnType: "PgUUID";
|
|
227
|
+
data: string;
|
|
228
|
+
driverParam: string;
|
|
229
|
+
notNull: true;
|
|
230
|
+
hasDefault: true;
|
|
231
|
+
isPrimaryKey: true;
|
|
232
|
+
isAutoincrement: false;
|
|
233
|
+
hasRuntimeDefault: false;
|
|
234
|
+
enumValues: undefined;
|
|
235
|
+
baseColumn: never;
|
|
236
|
+
identity: undefined;
|
|
237
|
+
generated: undefined;
|
|
238
|
+
}, {}, {}>;
|
|
239
|
+
connectionId: import("drizzle-orm/pg-core").PgColumn<{
|
|
240
|
+
name: "connection_id";
|
|
241
|
+
tableName: "installations";
|
|
242
|
+
dataType: "string";
|
|
243
|
+
columnType: "PgUUID";
|
|
244
|
+
data: string;
|
|
245
|
+
driverParam: string;
|
|
246
|
+
notNull: true;
|
|
247
|
+
hasDefault: false;
|
|
248
|
+
isPrimaryKey: false;
|
|
249
|
+
isAutoincrement: false;
|
|
250
|
+
hasRuntimeDefault: false;
|
|
251
|
+
enumValues: undefined;
|
|
252
|
+
baseColumn: never;
|
|
253
|
+
identity: undefined;
|
|
254
|
+
generated: undefined;
|
|
255
|
+
}, {}, {}>;
|
|
256
|
+
installationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
257
|
+
name: "installation_id";
|
|
258
|
+
tableName: "installations";
|
|
259
|
+
dataType: "string";
|
|
260
|
+
columnType: "PgText";
|
|
261
|
+
data: string;
|
|
262
|
+
driverParam: string;
|
|
263
|
+
notNull: true;
|
|
264
|
+
hasDefault: false;
|
|
265
|
+
isPrimaryKey: false;
|
|
266
|
+
isAutoincrement: false;
|
|
267
|
+
hasRuntimeDefault: false;
|
|
268
|
+
enumValues: [string, ...string[]];
|
|
269
|
+
baseColumn: never;
|
|
270
|
+
identity: undefined;
|
|
271
|
+
generated: undefined;
|
|
272
|
+
}, {}, {}>;
|
|
273
|
+
accountLogin: import("drizzle-orm/pg-core").PgColumn<{
|
|
274
|
+
name: "account_login";
|
|
275
|
+
tableName: "installations";
|
|
276
|
+
dataType: "string";
|
|
277
|
+
columnType: "PgText";
|
|
278
|
+
data: string;
|
|
279
|
+
driverParam: string;
|
|
280
|
+
notNull: true;
|
|
281
|
+
hasDefault: false;
|
|
282
|
+
isPrimaryKey: false;
|
|
283
|
+
isAutoincrement: false;
|
|
284
|
+
hasRuntimeDefault: false;
|
|
285
|
+
enumValues: [string, ...string[]];
|
|
286
|
+
baseColumn: never;
|
|
287
|
+
identity: undefined;
|
|
288
|
+
generated: undefined;
|
|
289
|
+
}, {}, {}>;
|
|
290
|
+
accountType: import("drizzle-orm/pg-core").PgColumn<{
|
|
291
|
+
name: "account_type";
|
|
292
|
+
tableName: "installations";
|
|
293
|
+
dataType: "string";
|
|
294
|
+
columnType: "PgText";
|
|
295
|
+
data: string;
|
|
296
|
+
driverParam: string;
|
|
297
|
+
notNull: true;
|
|
298
|
+
hasDefault: false;
|
|
299
|
+
isPrimaryKey: false;
|
|
300
|
+
isAutoincrement: false;
|
|
301
|
+
hasRuntimeDefault: false;
|
|
302
|
+
enumValues: [string, ...string[]];
|
|
303
|
+
baseColumn: never;
|
|
304
|
+
identity: undefined;
|
|
305
|
+
generated: undefined;
|
|
306
|
+
}, {}, {}>;
|
|
307
|
+
repositorySelection: import("drizzle-orm/pg-core").PgColumn<{
|
|
308
|
+
name: "repository_selection";
|
|
309
|
+
tableName: "installations";
|
|
310
|
+
dataType: "string";
|
|
311
|
+
columnType: "PgText";
|
|
312
|
+
data: string;
|
|
313
|
+
driverParam: string;
|
|
314
|
+
notNull: true;
|
|
315
|
+
hasDefault: false;
|
|
316
|
+
isPrimaryKey: false;
|
|
317
|
+
isAutoincrement: false;
|
|
318
|
+
hasRuntimeDefault: false;
|
|
319
|
+
enumValues: [string, ...string[]];
|
|
320
|
+
baseColumn: never;
|
|
321
|
+
identity: undefined;
|
|
322
|
+
generated: undefined;
|
|
323
|
+
}, {}, {}>;
|
|
324
|
+
suspendedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
325
|
+
name: "suspended_at";
|
|
326
|
+
tableName: "installations";
|
|
327
|
+
dataType: "date";
|
|
328
|
+
columnType: "PgTimestamp";
|
|
329
|
+
data: Date;
|
|
330
|
+
driverParam: string;
|
|
331
|
+
notNull: false;
|
|
332
|
+
hasDefault: false;
|
|
333
|
+
isPrimaryKey: false;
|
|
334
|
+
isAutoincrement: false;
|
|
335
|
+
hasRuntimeDefault: false;
|
|
336
|
+
enumValues: undefined;
|
|
337
|
+
baseColumn: never;
|
|
338
|
+
identity: undefined;
|
|
339
|
+
generated: undefined;
|
|
340
|
+
}, {}, {}>;
|
|
341
|
+
deletedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
342
|
+
name: "deleted_at";
|
|
343
|
+
tableName: "installations";
|
|
344
|
+
dataType: "date";
|
|
345
|
+
columnType: "PgTimestamp";
|
|
346
|
+
data: Date;
|
|
347
|
+
driverParam: string;
|
|
348
|
+
notNull: false;
|
|
349
|
+
hasDefault: false;
|
|
350
|
+
isPrimaryKey: false;
|
|
351
|
+
isAutoincrement: false;
|
|
352
|
+
hasRuntimeDefault: false;
|
|
353
|
+
enumValues: undefined;
|
|
354
|
+
baseColumn: never;
|
|
355
|
+
identity: undefined;
|
|
356
|
+
generated: undefined;
|
|
357
|
+
}, {}, {}>;
|
|
358
|
+
latestEvent: import("drizzle-orm/pg-core").PgColumn<{
|
|
359
|
+
name: "latest_event";
|
|
360
|
+
tableName: "installations";
|
|
361
|
+
dataType: "json";
|
|
362
|
+
columnType: "PgJsonb";
|
|
363
|
+
data: Record<string, unknown>;
|
|
364
|
+
driverParam: unknown;
|
|
365
|
+
notNull: true;
|
|
366
|
+
hasDefault: false;
|
|
367
|
+
isPrimaryKey: false;
|
|
368
|
+
isAutoincrement: false;
|
|
369
|
+
hasRuntimeDefault: false;
|
|
370
|
+
enumValues: undefined;
|
|
371
|
+
baseColumn: never;
|
|
372
|
+
identity: undefined;
|
|
373
|
+
generated: undefined;
|
|
374
|
+
}, {}, {
|
|
375
|
+
$type: Record<string, unknown>;
|
|
376
|
+
}>;
|
|
377
|
+
installerUserId: import("drizzle-orm/pg-core").PgColumn<{
|
|
378
|
+
name: "installer_user_id";
|
|
379
|
+
tableName: "installations";
|
|
380
|
+
dataType: "string";
|
|
381
|
+
columnType: "PgUUID";
|
|
382
|
+
data: string;
|
|
383
|
+
driverParam: string;
|
|
384
|
+
notNull: false;
|
|
385
|
+
hasDefault: false;
|
|
386
|
+
isPrimaryKey: false;
|
|
387
|
+
isAutoincrement: false;
|
|
388
|
+
hasRuntimeDefault: false;
|
|
389
|
+
enumValues: undefined;
|
|
390
|
+
baseColumn: never;
|
|
391
|
+
identity: undefined;
|
|
392
|
+
generated: undefined;
|
|
393
|
+
}, {}, {}>;
|
|
394
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
395
|
+
name: "created_at";
|
|
396
|
+
tableName: "installations";
|
|
397
|
+
dataType: "date";
|
|
398
|
+
columnType: "PgTimestamp";
|
|
399
|
+
data: Date;
|
|
400
|
+
driverParam: string;
|
|
401
|
+
notNull: true;
|
|
402
|
+
hasDefault: true;
|
|
403
|
+
isPrimaryKey: false;
|
|
404
|
+
isAutoincrement: false;
|
|
405
|
+
hasRuntimeDefault: false;
|
|
406
|
+
enumValues: undefined;
|
|
407
|
+
baseColumn: never;
|
|
408
|
+
identity: undefined;
|
|
409
|
+
generated: undefined;
|
|
410
|
+
}, {}, {}>;
|
|
411
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
412
|
+
name: "updated_at";
|
|
413
|
+
tableName: "installations";
|
|
414
|
+
dataType: "date";
|
|
415
|
+
columnType: "PgTimestamp";
|
|
416
|
+
data: Date;
|
|
417
|
+
driverParam: string;
|
|
418
|
+
notNull: true;
|
|
419
|
+
hasDefault: true;
|
|
420
|
+
isPrimaryKey: false;
|
|
421
|
+
isAutoincrement: false;
|
|
422
|
+
hasRuntimeDefault: false;
|
|
423
|
+
enumValues: undefined;
|
|
424
|
+
baseColumn: never;
|
|
425
|
+
identity: undefined;
|
|
426
|
+
generated: undefined;
|
|
427
|
+
}, {}, {}>;
|
|
428
|
+
};
|
|
429
|
+
dialect: "pg";
|
|
430
|
+
}>;
|
|
431
|
+
}>;
|
|
432
|
+
export declare function closeDb(): void;
|
|
433
|
+
//# sourceMappingURL=db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAInE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAElB,CAAC;AAIF,wBAAgB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGjB;AAED,wBAAgB,OAAO,IAAI,IAAI,CAE9B"}
|
package/dist/db/db.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { drizzle } from '@shipfox/node-drizzle';
|
|
2
|
+
import { pgClient } from '@shipfox/node-postgres';
|
|
3
|
+
import { githubInstallations } from './schema/installations.js';
|
|
4
|
+
export const schema = {
|
|
5
|
+
githubInstallations
|
|
6
|
+
};
|
|
7
|
+
let _db;
|
|
8
|
+
export function db() {
|
|
9
|
+
if (!_db) _db = drizzle(pgClient(), {
|
|
10
|
+
schema
|
|
11
|
+
});
|
|
12
|
+
return _db;
|
|
13
|
+
}
|
|
14
|
+
export function closeDb() {
|
|
15
|
+
_db = undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/db.ts"],"sourcesContent":["import {drizzle, type NodePgDatabase} from '@shipfox/node-drizzle';\nimport {pgClient} from '@shipfox/node-postgres';\nimport {githubInstallations} from './schema/installations.js';\n\nexport const schema = {\n githubInstallations,\n};\n\nlet _db: NodePgDatabase<typeof schema> | undefined;\n\nexport function db() {\n if (!_db) _db = drizzle(pgClient(), {schema});\n return _db;\n}\n\nexport function closeDb(): void {\n _db = undefined;\n}\n"],"names":["drizzle","pgClient","githubInstallations","schema","_db","db","closeDb","undefined"],"mappings":"AAAA,SAAQA,OAAO,QAA4B,wBAAwB;AACnE,SAAQC,QAAQ,QAAO,yBAAyB;AAChD,SAAQC,mBAAmB,QAAO,4BAA4B;AAE9D,OAAO,MAAMC,SAAS;IACpBD;AACF,EAAE;AAEF,IAAIE;AAEJ,OAAO,SAASC;IACd,IAAI,CAACD,KAAKA,MAAMJ,QAAQC,YAAY;QAACE;IAAM;IAC3C,OAAOC;AACT;AAEA,OAAO,SAASE;IACdF,MAAMG;AACR"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type InstallationTokenLockResult<T> = {
|
|
2
|
+
acquired: true;
|
|
3
|
+
value: T;
|
|
4
|
+
} | {
|
|
5
|
+
acquired: false;
|
|
6
|
+
};
|
|
7
|
+
export declare function withInstallationTokenLock<T>(installationId: number, fn: () => Promise<T>): Promise<InstallationTokenLockResult<T>>;
|
|
8
|
+
//# sourceMappingURL=installation-token-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installation-token-lock.d.ts","sourceRoot":"","sources":["../../src/db/installation-token-lock.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,2BAA2B,CAAC,CAAC,IAAI;IAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAA;CAAC,CAAC;AAE5F,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAoBzC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { recordInstallationTokenLockWait } from '#metrics/index.js';
|
|
3
|
+
import { db } from './db.js';
|
|
4
|
+
export function withInstallationTokenLock(installationId, fn) {
|
|
5
|
+
const lockKey = installationTokenLockKey(installationId);
|
|
6
|
+
return db().transaction(async (tx)=>{
|
|
7
|
+
const startedAt = Date.now();
|
|
8
|
+
const lock = await tx.execute(sql`
|
|
9
|
+
SELECT pg_try_advisory_xact_lock(${lockKey}::bigint) AS acquired
|
|
10
|
+
`);
|
|
11
|
+
const acquired = lock.rows[0]?.acquired === true;
|
|
12
|
+
if (!acquired) {
|
|
13
|
+
recordInstallationTokenLockWait(Date.now() - startedAt);
|
|
14
|
+
return {
|
|
15
|
+
acquired: false
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const value = await fn();
|
|
20
|
+
return {
|
|
21
|
+
acquired: true,
|
|
22
|
+
value
|
|
23
|
+
};
|
|
24
|
+
} finally{
|
|
25
|
+
recordInstallationTokenLockWait(Date.now() - startedAt);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function installationTokenLockKey(installationId) {
|
|
30
|
+
if (!Number.isSafeInteger(installationId) || installationId < 0) {
|
|
31
|
+
throw new Error(`Invalid GitHub installation id for advisory lock: ${installationId}`);
|
|
32
|
+
}
|
|
33
|
+
// Keep these exact per-installation keys away from positive advisory-lock ids.
|
|
34
|
+
return String(-BigInt(installationId) - 1n);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=installation-token-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/installation-token-lock.ts"],"sourcesContent":["import {sql} from 'drizzle-orm';\nimport {recordInstallationTokenLockWait} from '#metrics/index.js';\nimport {db} from './db.js';\n\nexport type InstallationTokenLockResult<T> = {acquired: true; value: T} | {acquired: false};\n\nexport function withInstallationTokenLock<T>(\n installationId: number,\n fn: () => Promise<T>,\n): Promise<InstallationTokenLockResult<T>> {\n const lockKey = installationTokenLockKey(installationId);\n return db().transaction(async (tx) => {\n const startedAt = Date.now();\n const lock = await tx.execute<{acquired: boolean}>(sql`\n SELECT pg_try_advisory_xact_lock(${lockKey}::bigint) AS acquired\n `);\n const acquired = lock.rows[0]?.acquired === true;\n if (!acquired) {\n recordInstallationTokenLockWait(Date.now() - startedAt);\n return {acquired: false};\n }\n\n try {\n const value = await fn();\n return {acquired: true, value};\n } finally {\n recordInstallationTokenLockWait(Date.now() - startedAt);\n }\n });\n}\n\nfunction installationTokenLockKey(installationId: number): string {\n if (!Number.isSafeInteger(installationId) || installationId < 0) {\n throw new Error(`Invalid GitHub installation id for advisory lock: ${installationId}`);\n }\n\n // Keep these exact per-installation keys away from positive advisory-lock ids.\n return String(-BigInt(installationId) - 1n);\n}\n"],"names":["sql","recordInstallationTokenLockWait","db","withInstallationTokenLock","installationId","fn","lockKey","installationTokenLockKey","transaction","tx","startedAt","Date","now","lock","execute","acquired","rows","value","Number","isSafeInteger","Error","String","BigInt"],"mappings":"AAAA,SAAQA,GAAG,QAAO,cAAc;AAChC,SAAQC,+BAA+B,QAAO,oBAAoB;AAClE,SAAQC,EAAE,QAAO,UAAU;AAI3B,OAAO,SAASC,0BACdC,cAAsB,EACtBC,EAAoB;IAEpB,MAAMC,UAAUC,yBAAyBH;IACzC,OAAOF,KAAKM,WAAW,CAAC,OAAOC;QAC7B,MAAMC,YAAYC,KAAKC,GAAG;QAC1B,MAAMC,OAAO,MAAMJ,GAAGK,OAAO,CAAsBd,GAAG,CAAC;uCACpB,EAAEM,QAAQ;IAC7C,CAAC;QACD,MAAMS,WAAWF,KAAKG,IAAI,CAAC,EAAE,EAAED,aAAa;QAC5C,IAAI,CAACA,UAAU;YACbd,gCAAgCU,KAAKC,GAAG,KAAKF;YAC7C,OAAO;gBAACK,UAAU;YAAK;QACzB;QAEA,IAAI;YACF,MAAME,QAAQ,MAAMZ;YACpB,OAAO;gBAACU,UAAU;gBAAME;YAAK;QAC/B,SAAU;YACRhB,gCAAgCU,KAAKC,GAAG,KAAKF;QAC/C;IACF;AACF;AAEA,SAASH,yBAAyBH,cAAsB;IACtD,IAAI,CAACc,OAAOC,aAAa,CAACf,mBAAmBA,iBAAiB,GAAG;QAC/D,MAAM,IAAIgB,MAAM,CAAC,kDAAkD,EAAEhB,gBAAgB;IACvF;IAEA,+EAA+E;IAC/E,OAAOiB,OAAO,CAACC,OAAOlB,kBAAkB,EAAE;AAC5C"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface GithubInstallation {
|
|
2
|
+
id: string;
|
|
3
|
+
connectionId: string;
|
|
4
|
+
installationId: string;
|
|
5
|
+
accountLogin: string;
|
|
6
|
+
accountType: string;
|
|
7
|
+
repositorySelection: string;
|
|
8
|
+
suspendedAt: Date | null;
|
|
9
|
+
deletedAt: Date | null;
|
|
10
|
+
latestEvent: Record<string, unknown>;
|
|
11
|
+
installerUserId: string | null;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
updatedAt: Date;
|
|
14
|
+
}
|
|
15
|
+
export interface UpsertGithubInstallationParams {
|
|
16
|
+
connectionId: string;
|
|
17
|
+
installationId: string;
|
|
18
|
+
accountLogin: string;
|
|
19
|
+
accountType: string;
|
|
20
|
+
repositorySelection: string;
|
|
21
|
+
suspendedAt?: Date | null | undefined;
|
|
22
|
+
deletedAt?: Date | null | undefined;
|
|
23
|
+
latestEvent: Record<string, unknown>;
|
|
24
|
+
installerUserId?: string | null | undefined;
|
|
25
|
+
}
|
|
26
|
+
export declare function upsertGithubInstallation(params: UpsertGithubInstallationParams, options?: {
|
|
27
|
+
tx?: unknown;
|
|
28
|
+
}): Promise<GithubInstallation>;
|
|
29
|
+
export declare function getGithubInstallationByConnectionId(connectionId: string): Promise<GithubInstallation | undefined>;
|
|
30
|
+
export declare function getGithubInstallationByInstallationId(installationId: string, options?: {
|
|
31
|
+
tx?: unknown;
|
|
32
|
+
}): Promise<GithubInstallation | undefined>;
|
|
33
|
+
//# sourceMappingURL=installations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installations.d.ts","sourceRoot":"","sources":["../../src/db/installations.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;IACtC,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAC7C;AAKD,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,8BAA8B,EACtC,OAAO,GAAE;IAAC,EAAE,CAAC,EAAE,OAAO,CAAA;CAAM,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAyC7B;AAED,wBAAsB,mCAAmC,CACvD,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CASzC;AAED,wBAAsB,qCAAqC,CACzD,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE;IAAC,EAAE,CAAC,EAAE,OAAO,CAAA;CAAM,GAC3B,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAUzC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { eq } from 'drizzle-orm';
|
|
2
|
+
import { GithubInstallationAlreadyLinkedError } from '#core/errors.js';
|
|
3
|
+
import { db } from './db.js';
|
|
4
|
+
import { githubInstallations, toGithubInstallation } from './schema/installations.js';
|
|
5
|
+
export async function upsertGithubInstallation(params, options = {}) {
|
|
6
|
+
const executor = options.tx ?? db();
|
|
7
|
+
const now = new Date();
|
|
8
|
+
const [row] = await executor.insert(githubInstallations).values({
|
|
9
|
+
connectionId: params.connectionId,
|
|
10
|
+
installationId: params.installationId,
|
|
11
|
+
accountLogin: params.accountLogin,
|
|
12
|
+
accountType: params.accountType,
|
|
13
|
+
repositorySelection: params.repositorySelection,
|
|
14
|
+
suspendedAt: params.suspendedAt ?? null,
|
|
15
|
+
deletedAt: params.deletedAt ?? null,
|
|
16
|
+
latestEvent: params.latestEvent,
|
|
17
|
+
installerUserId: params.installerUserId ?? null
|
|
18
|
+
}).onConflictDoUpdate({
|
|
19
|
+
target: githubInstallations.installationId,
|
|
20
|
+
// TOCTOU guard: only (re)point this installation at the connection that
|
|
21
|
+
// already owns it. A concurrent connect of the same installation to a
|
|
22
|
+
// different workspace inserts its own connection row, so its connectionId
|
|
23
|
+
// differs here; the predicate is false, Postgres updates nothing, and the
|
|
24
|
+
// empty RETURNING below rolls the losing transaction back instead of
|
|
25
|
+
// silently repointing the installation (cross-tenant event misroute).
|
|
26
|
+
setWhere: eq(githubInstallations.connectionId, params.connectionId),
|
|
27
|
+
set: {
|
|
28
|
+
connectionId: params.connectionId,
|
|
29
|
+
accountLogin: params.accountLogin,
|
|
30
|
+
accountType: params.accountType,
|
|
31
|
+
repositorySelection: params.repositorySelection,
|
|
32
|
+
suspendedAt: params.suspendedAt ?? null,
|
|
33
|
+
deletedAt: params.deletedAt ?? null,
|
|
34
|
+
latestEvent: params.latestEvent,
|
|
35
|
+
installerUserId: params.installerUserId ?? null,
|
|
36
|
+
updatedAt: now
|
|
37
|
+
}
|
|
38
|
+
}).returning();
|
|
39
|
+
if (!row) throw new GithubInstallationAlreadyLinkedError(params.installationId);
|
|
40
|
+
return toGithubInstallation(row);
|
|
41
|
+
}
|
|
42
|
+
export async function getGithubInstallationByConnectionId(connectionId) {
|
|
43
|
+
const rows = await db().select().from(githubInstallations).where(eq(githubInstallations.connectionId, connectionId)).limit(1);
|
|
44
|
+
const row = rows[0];
|
|
45
|
+
if (!row) return undefined;
|
|
46
|
+
return toGithubInstallation(row);
|
|
47
|
+
}
|
|
48
|
+
export async function getGithubInstallationByInstallationId(installationId, options = {}) {
|
|
49
|
+
const executor = options.tx ?? db();
|
|
50
|
+
const rows = await executor.select().from(githubInstallations).where(eq(githubInstallations.installationId, installationId)).limit(1);
|
|
51
|
+
const row = rows[0];
|
|
52
|
+
if (!row) return undefined;
|
|
53
|
+
return toGithubInstallation(row);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=installations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/installations.ts"],"sourcesContent":["import {eq} from 'drizzle-orm';\nimport {GithubInstallationAlreadyLinkedError} from '#core/errors.js';\nimport {db} from './db.js';\nimport {githubInstallations, toGithubInstallation} from './schema/installations.js';\n\nexport interface GithubInstallation {\n id: string;\n connectionId: string;\n installationId: string;\n accountLogin: string;\n accountType: string;\n repositorySelection: string;\n suspendedAt: Date | null;\n deletedAt: Date | null;\n latestEvent: Record<string, unknown>;\n installerUserId: string | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface UpsertGithubInstallationParams {\n connectionId: string;\n installationId: string;\n accountLogin: string;\n accountType: string;\n repositorySelection: string;\n suspendedAt?: Date | null | undefined;\n deletedAt?: Date | null | undefined;\n latestEvent: Record<string, unknown>;\n installerUserId?: string | null | undefined;\n}\n\ntype GithubDb = ReturnType<typeof db>;\ntype GithubTx = Parameters<Parameters<GithubDb['transaction']>[0]>[0];\n\nexport async function upsertGithubInstallation(\n params: UpsertGithubInstallationParams,\n options: {tx?: unknown} = {},\n): Promise<GithubInstallation> {\n const executor = (options.tx ?? db()) as GithubDb | GithubTx;\n const now = new Date();\n const [row] = await executor\n .insert(githubInstallations)\n .values({\n connectionId: params.connectionId,\n installationId: params.installationId,\n accountLogin: params.accountLogin,\n accountType: params.accountType,\n repositorySelection: params.repositorySelection,\n suspendedAt: params.suspendedAt ?? null,\n deletedAt: params.deletedAt ?? null,\n latestEvent: params.latestEvent,\n installerUserId: params.installerUserId ?? null,\n })\n .onConflictDoUpdate({\n target: githubInstallations.installationId,\n // TOCTOU guard: only (re)point this installation at the connection that\n // already owns it. A concurrent connect of the same installation to a\n // different workspace inserts its own connection row, so its connectionId\n // differs here; the predicate is false, Postgres updates nothing, and the\n // empty RETURNING below rolls the losing transaction back instead of\n // silently repointing the installation (cross-tenant event misroute).\n setWhere: eq(githubInstallations.connectionId, params.connectionId),\n set: {\n connectionId: params.connectionId,\n accountLogin: params.accountLogin,\n accountType: params.accountType,\n repositorySelection: params.repositorySelection,\n suspendedAt: params.suspendedAt ?? null,\n deletedAt: params.deletedAt ?? null,\n latestEvent: params.latestEvent,\n installerUserId: params.installerUserId ?? null,\n updatedAt: now,\n },\n })\n .returning();\n\n if (!row) throw new GithubInstallationAlreadyLinkedError(params.installationId);\n return toGithubInstallation(row);\n}\n\nexport async function getGithubInstallationByConnectionId(\n connectionId: string,\n): Promise<GithubInstallation | undefined> {\n const rows = await db()\n .select()\n .from(githubInstallations)\n .where(eq(githubInstallations.connectionId, connectionId))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toGithubInstallation(row);\n}\n\nexport async function getGithubInstallationByInstallationId(\n installationId: string,\n options: {tx?: unknown} = {},\n): Promise<GithubInstallation | undefined> {\n const executor = (options.tx ?? db()) as GithubDb | GithubTx;\n const rows = await executor\n .select()\n .from(githubInstallations)\n .where(eq(githubInstallations.installationId, installationId))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toGithubInstallation(row);\n}\n"],"names":["eq","GithubInstallationAlreadyLinkedError","db","githubInstallations","toGithubInstallation","upsertGithubInstallation","params","options","executor","tx","now","Date","row","insert","values","connectionId","installationId","accountLogin","accountType","repositorySelection","suspendedAt","deletedAt","latestEvent","installerUserId","onConflictDoUpdate","target","setWhere","set","updatedAt","returning","getGithubInstallationByConnectionId","rows","select","from","where","limit","undefined","getGithubInstallationByInstallationId"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAc;AAC/B,SAAQC,oCAAoC,QAAO,kBAAkB;AACrE,SAAQC,EAAE,QAAO,UAAU;AAC3B,SAAQC,mBAAmB,EAAEC,oBAAoB,QAAO,4BAA4B;AAgCpF,OAAO,eAAeC,yBACpBC,MAAsC,EACtCC,UAA0B,CAAC,CAAC;IAE5B,MAAMC,WAAYD,QAAQE,EAAE,IAAIP;IAChC,MAAMQ,MAAM,IAAIC;IAChB,MAAM,CAACC,IAAI,GAAG,MAAMJ,SACjBK,MAAM,CAACV,qBACPW,MAAM,CAAC;QACNC,cAAcT,OAAOS,YAAY;QACjCC,gBAAgBV,OAAOU,cAAc;QACrCC,cAAcX,OAAOW,YAAY;QACjCC,aAAaZ,OAAOY,WAAW;QAC/BC,qBAAqBb,OAAOa,mBAAmB;QAC/CC,aAAad,OAAOc,WAAW,IAAI;QACnCC,WAAWf,OAAOe,SAAS,IAAI;QAC/BC,aAAahB,OAAOgB,WAAW;QAC/BC,iBAAiBjB,OAAOiB,eAAe,IAAI;IAC7C,GACCC,kBAAkB,CAAC;QAClBC,QAAQtB,oBAAoBa,cAAc;QAC1C,wEAAwE;QACxE,sEAAsE;QACtE,0EAA0E;QAC1E,0EAA0E;QAC1E,qEAAqE;QACrE,sEAAsE;QACtEU,UAAU1B,GAAGG,oBAAoBY,YAAY,EAAET,OAAOS,YAAY;QAClEY,KAAK;YACHZ,cAAcT,OAAOS,YAAY;YACjCE,cAAcX,OAAOW,YAAY;YACjCC,aAAaZ,OAAOY,WAAW;YAC/BC,qBAAqBb,OAAOa,mBAAmB;YAC/CC,aAAad,OAAOc,WAAW,IAAI;YACnCC,WAAWf,OAAOe,SAAS,IAAI;YAC/BC,aAAahB,OAAOgB,WAAW;YAC/BC,iBAAiBjB,OAAOiB,eAAe,IAAI;YAC3CK,WAAWlB;QACb;IACF,GACCmB,SAAS;IAEZ,IAAI,CAACjB,KAAK,MAAM,IAAIX,qCAAqCK,OAAOU,cAAc;IAC9E,OAAOZ,qBAAqBQ;AAC9B;AAEA,OAAO,eAAekB,oCACpBf,YAAoB;IAEpB,MAAMgB,OAAO,MAAM7B,KAChB8B,MAAM,GACNC,IAAI,CAAC9B,qBACL+B,KAAK,CAAClC,GAAGG,oBAAoBY,YAAY,EAAEA,eAC3CoB,KAAK,CAAC;IACT,MAAMvB,MAAMmB,IAAI,CAAC,EAAE;IACnB,IAAI,CAACnB,KAAK,OAAOwB;IACjB,OAAOhC,qBAAqBQ;AAC9B;AAEA,OAAO,eAAeyB,sCACpBrB,cAAsB,EACtBT,UAA0B,CAAC,CAAC;IAE5B,MAAMC,WAAYD,QAAQE,EAAE,IAAIP;IAChC,MAAM6B,OAAO,MAAMvB,SAChBwB,MAAM,GACNC,IAAI,CAAC9B,qBACL+B,KAAK,CAAClC,GAAGG,oBAAoBa,cAAc,EAAEA,iBAC7CmB,KAAK,CAAC;IACT,MAAMvB,MAAMmB,IAAI,CAAC,EAAE;IACnB,IAAI,CAACnB,KAAK,OAAOwB;IACjB,OAAOhC,qBAAqBQ;AAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/db/migrations.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAoE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/migrations.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nexport const migrationsPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../drizzle');\n"],"names":["dirname","resolve","fileURLToPath","migrationsPath","url"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAY;AAC3C,SAAQC,aAAa,QAAO,WAAW;AAEvC,OAAO,MAAMC,iBAAiBF,QAAQD,QAAQE,cAAc,YAAYE,GAAG,IAAI,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/db/schema/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,oDAA0D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/db/schema/common.ts"],"sourcesContent":["import {pgTableCreator} from 'drizzle-orm/pg-core';\n\nexport const pgTable = pgTableCreator((name) => `integrations_github_${name}`);\n"],"names":["pgTableCreator","pgTable","name"],"mappings":"AAAA,SAAQA,cAAc,QAAO,sBAAsB;AAEnD,OAAO,MAAMC,UAAUD,eAAe,CAACE,OAAS,CAAC,oBAAoB,EAAEA,MAAM,EAAE"}
|