@shipfox/api-integration-linear 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 +89 -0
- package/LICENSE +21 -0
- package/README.md +88 -0
- package/dist/api/client.d.ts +29 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +189 -0
- package/dist/api/client.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +22 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-tools-provider.d.ts +32 -0
- package/dist/core/agent-tools-provider.d.ts.map +1 -0
- package/dist/core/agent-tools-provider.js +63 -0
- package/dist/core/agent-tools-provider.js.map +1 -0
- package/dist/core/agent-tools.d.ts +10 -0
- package/dist/core/agent-tools.d.ts.map +1 -0
- package/dist/core/agent-tools.js +920 -0
- package/dist/core/agent-tools.js.map +1 -0
- package/dist/core/disconnect.d.ts +18 -0
- package/dist/core/disconnect.d.ts.map +1 -0
- package/dist/core/disconnect.js +23 -0
- package/dist/core/disconnect.js.map +1 -0
- package/dist/core/errors.d.ts +35 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +59 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/install.d.ts +47 -0
- package/dist/core/install.d.ts.map +1 -0
- package/dist/core/install.js +102 -0
- package/dist/core/install.js.map +1 -0
- package/dist/core/scopes.d.ts +4 -0
- package/dist/core/scopes.d.ts.map +1 -0
- package/dist/core/scopes.js +17 -0
- package/dist/core/scopes.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/tokens.d.ts +39 -0
- package/dist/core/tokens.d.ts.map +1 -0
- package/dist/core/tokens.js +117 -0
- package/dist/core/tokens.js.map +1 -0
- package/dist/core/webhook.d.ts +16 -0
- package/dist/core/webhook.d.ts.map +1 -0
- package/dist/core/webhook.js +105 -0
- package/dist/core/webhook.js.map +1 -0
- package/dist/db/db.d.ts +369 -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/installations.d.ts +53 -0
- package/dist/db/installations.d.ts.map +1 -0
- package/dist/db/installations.js +125 -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 +186 -0
- package/dist/db/schema/installations.d.ts.map +1 -0
- package/dist/db/schema/installations.js +40 -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 +56 -0
- package/dist/index.js.map +1 -0
- package/dist/presentation/dto/integrations.d.ts +17 -0
- package/dist/presentation/dto/integrations.d.ts.map +1 -0
- package/dist/presentation/dto/integrations.js +6 -0
- package/dist/presentation/dto/integrations.js.map +1 -0
- package/dist/presentation/e2eRoutes/create-connection.d.ts +16 -0
- package/dist/presentation/e2eRoutes/create-connection.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/create-connection.js +64 -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 +65 -0
- package/dist/presentation/routes/errors.js.map +1 -0
- package/dist/presentation/routes/install.d.ts +19 -0
- package/dist/presentation/routes/install.d.ts.map +1 -0
- package/dist/presentation/routes/install.js +100 -0
- package/dist/presentation/routes/install.js.map +1 -0
- package/dist/presentation/routes/webhooks.d.ts +11 -0
- package/dist/presentation/routes/webhooks.d.ts.map +1 -0
- package/dist/presentation/routes/webhooks.js +136 -0
- package/dist/presentation/routes/webhooks.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +15 -0
- package/drizzle/meta/0000_snapshot.json +126 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +72 -0
- package/src/api/client.test.ts +366 -0
- package/src/api/client.ts +281 -0
- package/src/config.test.ts +34 -0
- package/src/config.ts +22 -0
- package/src/connection-external-url.test.ts +64 -0
- package/src/core/agent-tools-provider.test.ts +245 -0
- package/src/core/agent-tools-provider.ts +106 -0
- package/src/core/agent-tools.ts +918 -0
- package/src/core/disconnect.test.ts +45 -0
- package/src/core/disconnect.ts +27 -0
- package/src/core/errors.ts +71 -0
- package/src/core/install.ts +162 -0
- package/src/core/scopes.ts +18 -0
- package/src/core/state.test.ts +51 -0
- package/src/core/state.ts +85 -0
- package/src/core/tokens.test.ts +281 -0
- package/src/core/tokens.ts +219 -0
- package/src/core/webhook.test.ts +318 -0
- package/src/core/webhook.ts +146 -0
- package/src/db/db.ts +18 -0
- package/src/db/installations.test.ts +182 -0
- package/src/db/installations.ts +215 -0
- package/src/db/migrations.ts +4 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/installations.ts +42 -0
- package/src/index.test.ts +20 -0
- package/src/index.ts +153 -0
- package/src/presentation/dto/integrations.ts +9 -0
- package/src/presentation/e2eRoutes/create-connection.ts +85 -0
- package/src/presentation/e2eRoutes/index.test.ts +193 -0
- package/src/presentation/e2eRoutes/index.ts +14 -0
- package/src/presentation/routes/errors.ts +60 -0
- package/src/presentation/routes/install.test.ts +460 -0
- package/src/presentation/routes/install.ts +132 -0
- package/src/presentation/routes/webhooks.test.ts +407 -0
- package/src/presentation/routes/webhooks.ts +154 -0
- package/test/api-secrets.d.ts +28 -0
- package/test/env.ts +13 -0
- package/test/factories/index.ts +1 -0
- package/test/globalSetup.ts +23 -0
- package/test/index.ts +1 -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,369 @@
|
|
|
1
|
+
import { type NodePgDatabase } from '@shipfox/node-drizzle';
|
|
2
|
+
export declare const schema: {
|
|
3
|
+
linearInstallations: 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
|
+
organizationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
42
|
+
name: "organization_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
|
+
organizationUrlKey: import("drizzle-orm/pg-core").PgColumn<{
|
|
59
|
+
name: "organization_url_key";
|
|
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
|
+
appUserId: import("drizzle-orm/pg-core").PgColumn<{
|
|
76
|
+
name: "app_user_id";
|
|
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
|
+
scopes: import("drizzle-orm/pg-core").PgColumn<{
|
|
93
|
+
name: "scopes";
|
|
94
|
+
tableName: "installations";
|
|
95
|
+
dataType: "json";
|
|
96
|
+
columnType: "PgJsonb";
|
|
97
|
+
data: string[];
|
|
98
|
+
driverParam: unknown;
|
|
99
|
+
notNull: true;
|
|
100
|
+
hasDefault: false;
|
|
101
|
+
isPrimaryKey: false;
|
|
102
|
+
isAutoincrement: false;
|
|
103
|
+
hasRuntimeDefault: false;
|
|
104
|
+
enumValues: undefined;
|
|
105
|
+
baseColumn: never;
|
|
106
|
+
identity: undefined;
|
|
107
|
+
generated: undefined;
|
|
108
|
+
}, {}, {
|
|
109
|
+
$type: string[];
|
|
110
|
+
}>;
|
|
111
|
+
tokenExpiresAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
112
|
+
name: "token_expires_at";
|
|
113
|
+
tableName: "installations";
|
|
114
|
+
dataType: "date";
|
|
115
|
+
columnType: "PgTimestamp";
|
|
116
|
+
data: Date;
|
|
117
|
+
driverParam: string;
|
|
118
|
+
notNull: false;
|
|
119
|
+
hasDefault: false;
|
|
120
|
+
isPrimaryKey: false;
|
|
121
|
+
isAutoincrement: false;
|
|
122
|
+
hasRuntimeDefault: false;
|
|
123
|
+
enumValues: undefined;
|
|
124
|
+
baseColumn: never;
|
|
125
|
+
identity: undefined;
|
|
126
|
+
generated: undefined;
|
|
127
|
+
}, {}, {}>;
|
|
128
|
+
status: import("drizzle-orm/pg-core").PgColumn<{
|
|
129
|
+
name: "status";
|
|
130
|
+
tableName: "installations";
|
|
131
|
+
dataType: "string";
|
|
132
|
+
columnType: "PgText";
|
|
133
|
+
data: import("./installations.js").LinearInstallationStatus;
|
|
134
|
+
driverParam: string;
|
|
135
|
+
notNull: true;
|
|
136
|
+
hasDefault: false;
|
|
137
|
+
isPrimaryKey: false;
|
|
138
|
+
isAutoincrement: false;
|
|
139
|
+
hasRuntimeDefault: false;
|
|
140
|
+
enumValues: [string, ...string[]];
|
|
141
|
+
baseColumn: never;
|
|
142
|
+
identity: undefined;
|
|
143
|
+
generated: undefined;
|
|
144
|
+
}, {}, {
|
|
145
|
+
$type: import("./installations.js").LinearInstallationStatus;
|
|
146
|
+
}>;
|
|
147
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
148
|
+
name: "created_at";
|
|
149
|
+
tableName: "installations";
|
|
150
|
+
dataType: "date";
|
|
151
|
+
columnType: "PgTimestamp";
|
|
152
|
+
data: Date;
|
|
153
|
+
driverParam: string;
|
|
154
|
+
notNull: true;
|
|
155
|
+
hasDefault: true;
|
|
156
|
+
isPrimaryKey: false;
|
|
157
|
+
isAutoincrement: false;
|
|
158
|
+
hasRuntimeDefault: false;
|
|
159
|
+
enumValues: undefined;
|
|
160
|
+
baseColumn: never;
|
|
161
|
+
identity: undefined;
|
|
162
|
+
generated: undefined;
|
|
163
|
+
}, {}, {}>;
|
|
164
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
165
|
+
name: "updated_at";
|
|
166
|
+
tableName: "installations";
|
|
167
|
+
dataType: "date";
|
|
168
|
+
columnType: "PgTimestamp";
|
|
169
|
+
data: Date;
|
|
170
|
+
driverParam: string;
|
|
171
|
+
notNull: true;
|
|
172
|
+
hasDefault: true;
|
|
173
|
+
isPrimaryKey: false;
|
|
174
|
+
isAutoincrement: false;
|
|
175
|
+
hasRuntimeDefault: false;
|
|
176
|
+
enumValues: undefined;
|
|
177
|
+
baseColumn: never;
|
|
178
|
+
identity: undefined;
|
|
179
|
+
generated: undefined;
|
|
180
|
+
}, {}, {}>;
|
|
181
|
+
};
|
|
182
|
+
dialect: "pg";
|
|
183
|
+
}>;
|
|
184
|
+
};
|
|
185
|
+
export declare function db(): NodePgDatabase<{
|
|
186
|
+
linearInstallations: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
187
|
+
name: "installations";
|
|
188
|
+
schema: undefined;
|
|
189
|
+
columns: {
|
|
190
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
191
|
+
name: "id";
|
|
192
|
+
tableName: "installations";
|
|
193
|
+
dataType: "string";
|
|
194
|
+
columnType: "PgUUID";
|
|
195
|
+
data: string;
|
|
196
|
+
driverParam: string;
|
|
197
|
+
notNull: true;
|
|
198
|
+
hasDefault: true;
|
|
199
|
+
isPrimaryKey: true;
|
|
200
|
+
isAutoincrement: false;
|
|
201
|
+
hasRuntimeDefault: false;
|
|
202
|
+
enumValues: undefined;
|
|
203
|
+
baseColumn: never;
|
|
204
|
+
identity: undefined;
|
|
205
|
+
generated: undefined;
|
|
206
|
+
}, {}, {}>;
|
|
207
|
+
connectionId: import("drizzle-orm/pg-core").PgColumn<{
|
|
208
|
+
name: "connection_id";
|
|
209
|
+
tableName: "installations";
|
|
210
|
+
dataType: "string";
|
|
211
|
+
columnType: "PgUUID";
|
|
212
|
+
data: string;
|
|
213
|
+
driverParam: string;
|
|
214
|
+
notNull: true;
|
|
215
|
+
hasDefault: false;
|
|
216
|
+
isPrimaryKey: false;
|
|
217
|
+
isAutoincrement: false;
|
|
218
|
+
hasRuntimeDefault: false;
|
|
219
|
+
enumValues: undefined;
|
|
220
|
+
baseColumn: never;
|
|
221
|
+
identity: undefined;
|
|
222
|
+
generated: undefined;
|
|
223
|
+
}, {}, {}>;
|
|
224
|
+
organizationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
225
|
+
name: "organization_id";
|
|
226
|
+
tableName: "installations";
|
|
227
|
+
dataType: "string";
|
|
228
|
+
columnType: "PgText";
|
|
229
|
+
data: string;
|
|
230
|
+
driverParam: string;
|
|
231
|
+
notNull: true;
|
|
232
|
+
hasDefault: false;
|
|
233
|
+
isPrimaryKey: false;
|
|
234
|
+
isAutoincrement: false;
|
|
235
|
+
hasRuntimeDefault: false;
|
|
236
|
+
enumValues: [string, ...string[]];
|
|
237
|
+
baseColumn: never;
|
|
238
|
+
identity: undefined;
|
|
239
|
+
generated: undefined;
|
|
240
|
+
}, {}, {}>;
|
|
241
|
+
organizationUrlKey: import("drizzle-orm/pg-core").PgColumn<{
|
|
242
|
+
name: "organization_url_key";
|
|
243
|
+
tableName: "installations";
|
|
244
|
+
dataType: "string";
|
|
245
|
+
columnType: "PgText";
|
|
246
|
+
data: string;
|
|
247
|
+
driverParam: string;
|
|
248
|
+
notNull: true;
|
|
249
|
+
hasDefault: false;
|
|
250
|
+
isPrimaryKey: false;
|
|
251
|
+
isAutoincrement: false;
|
|
252
|
+
hasRuntimeDefault: false;
|
|
253
|
+
enumValues: [string, ...string[]];
|
|
254
|
+
baseColumn: never;
|
|
255
|
+
identity: undefined;
|
|
256
|
+
generated: undefined;
|
|
257
|
+
}, {}, {}>;
|
|
258
|
+
appUserId: import("drizzle-orm/pg-core").PgColumn<{
|
|
259
|
+
name: "app_user_id";
|
|
260
|
+
tableName: "installations";
|
|
261
|
+
dataType: "string";
|
|
262
|
+
columnType: "PgText";
|
|
263
|
+
data: string;
|
|
264
|
+
driverParam: string;
|
|
265
|
+
notNull: true;
|
|
266
|
+
hasDefault: false;
|
|
267
|
+
isPrimaryKey: false;
|
|
268
|
+
isAutoincrement: false;
|
|
269
|
+
hasRuntimeDefault: false;
|
|
270
|
+
enumValues: [string, ...string[]];
|
|
271
|
+
baseColumn: never;
|
|
272
|
+
identity: undefined;
|
|
273
|
+
generated: undefined;
|
|
274
|
+
}, {}, {}>;
|
|
275
|
+
scopes: import("drizzle-orm/pg-core").PgColumn<{
|
|
276
|
+
name: "scopes";
|
|
277
|
+
tableName: "installations";
|
|
278
|
+
dataType: "json";
|
|
279
|
+
columnType: "PgJsonb";
|
|
280
|
+
data: string[];
|
|
281
|
+
driverParam: unknown;
|
|
282
|
+
notNull: true;
|
|
283
|
+
hasDefault: false;
|
|
284
|
+
isPrimaryKey: false;
|
|
285
|
+
isAutoincrement: false;
|
|
286
|
+
hasRuntimeDefault: false;
|
|
287
|
+
enumValues: undefined;
|
|
288
|
+
baseColumn: never;
|
|
289
|
+
identity: undefined;
|
|
290
|
+
generated: undefined;
|
|
291
|
+
}, {}, {
|
|
292
|
+
$type: string[];
|
|
293
|
+
}>;
|
|
294
|
+
tokenExpiresAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
295
|
+
name: "token_expires_at";
|
|
296
|
+
tableName: "installations";
|
|
297
|
+
dataType: "date";
|
|
298
|
+
columnType: "PgTimestamp";
|
|
299
|
+
data: Date;
|
|
300
|
+
driverParam: string;
|
|
301
|
+
notNull: false;
|
|
302
|
+
hasDefault: false;
|
|
303
|
+
isPrimaryKey: false;
|
|
304
|
+
isAutoincrement: false;
|
|
305
|
+
hasRuntimeDefault: false;
|
|
306
|
+
enumValues: undefined;
|
|
307
|
+
baseColumn: never;
|
|
308
|
+
identity: undefined;
|
|
309
|
+
generated: undefined;
|
|
310
|
+
}, {}, {}>;
|
|
311
|
+
status: import("drizzle-orm/pg-core").PgColumn<{
|
|
312
|
+
name: "status";
|
|
313
|
+
tableName: "installations";
|
|
314
|
+
dataType: "string";
|
|
315
|
+
columnType: "PgText";
|
|
316
|
+
data: import("./installations.js").LinearInstallationStatus;
|
|
317
|
+
driverParam: string;
|
|
318
|
+
notNull: true;
|
|
319
|
+
hasDefault: false;
|
|
320
|
+
isPrimaryKey: false;
|
|
321
|
+
isAutoincrement: false;
|
|
322
|
+
hasRuntimeDefault: false;
|
|
323
|
+
enumValues: [string, ...string[]];
|
|
324
|
+
baseColumn: never;
|
|
325
|
+
identity: undefined;
|
|
326
|
+
generated: undefined;
|
|
327
|
+
}, {}, {
|
|
328
|
+
$type: import("./installations.js").LinearInstallationStatus;
|
|
329
|
+
}>;
|
|
330
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
331
|
+
name: "created_at";
|
|
332
|
+
tableName: "installations";
|
|
333
|
+
dataType: "date";
|
|
334
|
+
columnType: "PgTimestamp";
|
|
335
|
+
data: Date;
|
|
336
|
+
driverParam: string;
|
|
337
|
+
notNull: true;
|
|
338
|
+
hasDefault: true;
|
|
339
|
+
isPrimaryKey: false;
|
|
340
|
+
isAutoincrement: false;
|
|
341
|
+
hasRuntimeDefault: false;
|
|
342
|
+
enumValues: undefined;
|
|
343
|
+
baseColumn: never;
|
|
344
|
+
identity: undefined;
|
|
345
|
+
generated: undefined;
|
|
346
|
+
}, {}, {}>;
|
|
347
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
348
|
+
name: "updated_at";
|
|
349
|
+
tableName: "installations";
|
|
350
|
+
dataType: "date";
|
|
351
|
+
columnType: "PgTimestamp";
|
|
352
|
+
data: Date;
|
|
353
|
+
driverParam: string;
|
|
354
|
+
notNull: true;
|
|
355
|
+
hasDefault: true;
|
|
356
|
+
isPrimaryKey: false;
|
|
357
|
+
isAutoincrement: false;
|
|
358
|
+
hasRuntimeDefault: false;
|
|
359
|
+
enumValues: undefined;
|
|
360
|
+
baseColumn: never;
|
|
361
|
+
identity: undefined;
|
|
362
|
+
generated: undefined;
|
|
363
|
+
}, {}, {}>;
|
|
364
|
+
};
|
|
365
|
+
dialect: "pg";
|
|
366
|
+
}>;
|
|
367
|
+
}>;
|
|
368
|
+
export declare function closeDb(): void;
|
|
369
|
+
//# 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 { linearInstallations } from './schema/installations.js';
|
|
4
|
+
export const schema = {
|
|
5
|
+
linearInstallations
|
|
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 {linearInstallations} from './schema/installations.js';\n\nexport const schema = {\n linearInstallations,\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","linearInstallations","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,53 @@
|
|
|
1
|
+
export type LinearInstallationStatus = 'installed' | 'revoked';
|
|
2
|
+
export interface LinearInstallation {
|
|
3
|
+
id: string;
|
|
4
|
+
connectionId: string;
|
|
5
|
+
organizationId: string;
|
|
6
|
+
organizationUrlKey: string;
|
|
7
|
+
appUserId: string;
|
|
8
|
+
scopes: string[];
|
|
9
|
+
tokenExpiresAt: Date | null;
|
|
10
|
+
status: LinearInstallationStatus;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
}
|
|
14
|
+
export interface UpsertLinearInstallationParams {
|
|
15
|
+
connectionId: string;
|
|
16
|
+
organizationId: string;
|
|
17
|
+
organizationUrlKey: string;
|
|
18
|
+
appUserId: string;
|
|
19
|
+
scopes: string[];
|
|
20
|
+
tokenExpiresAt?: Date | null | undefined;
|
|
21
|
+
status: LinearInstallationStatus;
|
|
22
|
+
}
|
|
23
|
+
export interface UpdateLinearInstallationTokenExpiryParams {
|
|
24
|
+
connectionId: string;
|
|
25
|
+
tokenExpiresAt: Date | null;
|
|
26
|
+
scopes?: string[] | undefined;
|
|
27
|
+
}
|
|
28
|
+
export declare function upsertLinearInstallation(params: UpsertLinearInstallationParams, options?: {
|
|
29
|
+
tx?: unknown;
|
|
30
|
+
}): Promise<LinearInstallation>;
|
|
31
|
+
export declare function getLinearInstallationByConnectionId(connectionId: string, options?: {
|
|
32
|
+
tx?: unknown;
|
|
33
|
+
}): Promise<LinearInstallation | undefined>;
|
|
34
|
+
export declare function getLinearInstallationByOrganizationId(organizationId: string, options?: {
|
|
35
|
+
tx?: unknown;
|
|
36
|
+
}): Promise<LinearInstallation | undefined>;
|
|
37
|
+
export declare function updateLinearInstallationTokenExpiry(params: UpdateLinearInstallationTokenExpiryParams, options?: {
|
|
38
|
+
tx?: unknown;
|
|
39
|
+
}): Promise<LinearInstallation | undefined>;
|
|
40
|
+
export declare function markLinearInstallationRevoked(connectionId: string, options?: {
|
|
41
|
+
tx?: unknown;
|
|
42
|
+
}): Promise<LinearInstallation | undefined>;
|
|
43
|
+
export declare function deleteLinearInstallationByConnectionId(connectionId: string, options?: {
|
|
44
|
+
tx?: unknown;
|
|
45
|
+
}): Promise<boolean>;
|
|
46
|
+
export type LinearRefreshLockResult<T> = {
|
|
47
|
+
acquired: true;
|
|
48
|
+
value: T;
|
|
49
|
+
} | {
|
|
50
|
+
acquired: false;
|
|
51
|
+
};
|
|
52
|
+
export declare function withLinearRefreshLock<T>(connectionId: string, fn: () => Promise<T>): Promise<LinearRefreshLockResult<T>>;
|
|
53
|
+
//# sourceMappingURL=installations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installations.d.ts","sourceRoot":"","sources":["../../src/db/installations.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,wBAAwB,GAAG,WAAW,GAAG,SAAS,CAAC;AAE/D,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,EAAE,IAAI,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,wBAAwB,CAAC;IACjC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAA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,sCAAsC,CAC1D,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE;IAAC,EAAE,CAAC,EAAE,OAAO,CAAA;CAAM,GAC3B,OAAO,CAAC,OAAO,CAAC,CAMlB;AAED,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI;IAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAA;CAAC,CAAC;AAExF,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,YAAY,EAAE,MAAM,EACpB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAErC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { pgClient } from '@shipfox/node-postgres';
|
|
2
|
+
import { eq } from 'drizzle-orm';
|
|
3
|
+
import { LinearConnectionAlreadyLinkedError, LinearInstallationAlreadyLinkedError } from '#core/errors.js';
|
|
4
|
+
import { db } from './db.js';
|
|
5
|
+
import { linearInstallations, toLinearInstallation } from './schema/installations.js';
|
|
6
|
+
export async function upsertLinearInstallation(params, options = {}) {
|
|
7
|
+
const executor = options.tx ?? db();
|
|
8
|
+
const now = new Date();
|
|
9
|
+
let row;
|
|
10
|
+
try {
|
|
11
|
+
[row] = await executor.insert(linearInstallations).values({
|
|
12
|
+
connectionId: params.connectionId,
|
|
13
|
+
organizationId: params.organizationId,
|
|
14
|
+
organizationUrlKey: params.organizationUrlKey,
|
|
15
|
+
appUserId: params.appUserId,
|
|
16
|
+
scopes: params.scopes,
|
|
17
|
+
tokenExpiresAt: params.tokenExpiresAt ?? null,
|
|
18
|
+
status: params.status
|
|
19
|
+
}).onConflictDoUpdate({
|
|
20
|
+
target: linearInstallations.organizationId,
|
|
21
|
+
setWhere: eq(linearInstallations.connectionId, params.connectionId),
|
|
22
|
+
set: {
|
|
23
|
+
connectionId: params.connectionId,
|
|
24
|
+
organizationId: params.organizationId,
|
|
25
|
+
organizationUrlKey: params.organizationUrlKey,
|
|
26
|
+
appUserId: params.appUserId,
|
|
27
|
+
scopes: params.scopes,
|
|
28
|
+
tokenExpiresAt: params.tokenExpiresAt ?? null,
|
|
29
|
+
status: params.status,
|
|
30
|
+
updatedAt: now
|
|
31
|
+
}
|
|
32
|
+
}).returning();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (isUniqueViolation(error, 'integrations_linear_installations_connection_unique')) {
|
|
35
|
+
throw new LinearConnectionAlreadyLinkedError(params.connectionId);
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
if (!row) throw new LinearInstallationAlreadyLinkedError(params.organizationId);
|
|
40
|
+
return toLinearInstallation(row);
|
|
41
|
+
}
|
|
42
|
+
function isUniqueViolation(error, constraint) {
|
|
43
|
+
let current = error;
|
|
44
|
+
while(typeof current === 'object' && current !== null){
|
|
45
|
+
const postgresError = current;
|
|
46
|
+
if (postgresError.code === '23505' && postgresError.constraint === constraint) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
current = postgresError.cause;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
export async function getLinearInstallationByConnectionId(connectionId, options = {}) {
|
|
54
|
+
const executor = options.tx ?? db();
|
|
55
|
+
const rows = await executor.select().from(linearInstallations).where(eq(linearInstallations.connectionId, connectionId)).limit(1);
|
|
56
|
+
const row = rows[0];
|
|
57
|
+
if (!row) return undefined;
|
|
58
|
+
return toLinearInstallation(row);
|
|
59
|
+
}
|
|
60
|
+
export async function getLinearInstallationByOrganizationId(organizationId, options = {}) {
|
|
61
|
+
const executor = options.tx ?? db();
|
|
62
|
+
const rows = await executor.select().from(linearInstallations).where(eq(linearInstallations.organizationId, organizationId)).limit(1);
|
|
63
|
+
const row = rows[0];
|
|
64
|
+
if (!row) return undefined;
|
|
65
|
+
return toLinearInstallation(row);
|
|
66
|
+
}
|
|
67
|
+
export async function updateLinearInstallationTokenExpiry(params, options = {}) {
|
|
68
|
+
const executor = options.tx ?? db();
|
|
69
|
+
const [row] = await executor.update(linearInstallations).set({
|
|
70
|
+
tokenExpiresAt: params.tokenExpiresAt,
|
|
71
|
+
...params.scopes === undefined ? {} : {
|
|
72
|
+
scopes: params.scopes
|
|
73
|
+
},
|
|
74
|
+
updatedAt: new Date()
|
|
75
|
+
}).where(eq(linearInstallations.connectionId, params.connectionId)).returning();
|
|
76
|
+
if (!row) return undefined;
|
|
77
|
+
return toLinearInstallation(row);
|
|
78
|
+
}
|
|
79
|
+
export async function markLinearInstallationRevoked(connectionId, options = {}) {
|
|
80
|
+
const executor = options.tx ?? db();
|
|
81
|
+
const [row] = await executor.update(linearInstallations).set({
|
|
82
|
+
status: 'revoked',
|
|
83
|
+
updatedAt: new Date()
|
|
84
|
+
}).where(eq(linearInstallations.connectionId, connectionId)).returning();
|
|
85
|
+
if (!row) return undefined;
|
|
86
|
+
return toLinearInstallation(row);
|
|
87
|
+
}
|
|
88
|
+
export async function deleteLinearInstallationByConnectionId(connectionId, options = {}) {
|
|
89
|
+
const executor = options.tx ?? db();
|
|
90
|
+
const result = await executor.delete(linearInstallations).where(eq(linearInstallations.connectionId, connectionId));
|
|
91
|
+
return (result.rowCount ?? 0) > 0;
|
|
92
|
+
}
|
|
93
|
+
export function withLinearRefreshLock(connectionId, fn) {
|
|
94
|
+
return withLinearRefreshLockClient(connectionId, fn);
|
|
95
|
+
}
|
|
96
|
+
async function withLinearRefreshLockClient(connectionId, fn) {
|
|
97
|
+
const client = await pgClient().connect();
|
|
98
|
+
let acquired = false;
|
|
99
|
+
try {
|
|
100
|
+
const lock = await client.query('SELECT pg_try_advisory_lock(hashtext($1)) AS acquired', [
|
|
101
|
+
connectionId
|
|
102
|
+
]);
|
|
103
|
+
acquired = lock.rows[0]?.acquired === true;
|
|
104
|
+
if (!acquired) return {
|
|
105
|
+
acquired: false
|
|
106
|
+
};
|
|
107
|
+
const value = await fn();
|
|
108
|
+
return {
|
|
109
|
+
acquired: true,
|
|
110
|
+
value
|
|
111
|
+
};
|
|
112
|
+
} finally{
|
|
113
|
+
try {
|
|
114
|
+
if (acquired) {
|
|
115
|
+
await client.query('SELECT pg_advisory_unlock(hashtext($1))', [
|
|
116
|
+
connectionId
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
} finally{
|
|
120
|
+
client.release();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=installations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/installations.ts"],"sourcesContent":["import {pgClient} from '@shipfox/node-postgres';\nimport {eq} from 'drizzle-orm';\nimport {\n LinearConnectionAlreadyLinkedError,\n LinearInstallationAlreadyLinkedError,\n} from '#core/errors.js';\nimport {db} from './db.js';\nimport {linearInstallations, toLinearInstallation} from './schema/installations.js';\n\nexport type LinearInstallationStatus = 'installed' | 'revoked';\n\nexport interface LinearInstallation {\n id: string;\n connectionId: string;\n organizationId: string;\n organizationUrlKey: string;\n appUserId: string;\n scopes: string[];\n tokenExpiresAt: Date | null;\n status: LinearInstallationStatus;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface UpsertLinearInstallationParams {\n connectionId: string;\n organizationId: string;\n organizationUrlKey: string;\n appUserId: string;\n scopes: string[];\n tokenExpiresAt?: Date | null | undefined;\n status: LinearInstallationStatus;\n}\n\nexport interface UpdateLinearInstallationTokenExpiryParams {\n connectionId: string;\n tokenExpiresAt: Date | null;\n scopes?: string[] | undefined;\n}\n\ntype LinearDb = ReturnType<typeof db>;\ntype LinearTx = Parameters<Parameters<LinearDb['transaction']>[0]>[0];\n\ninterface PostgresErrorFields {\n code?: unknown;\n constraint?: unknown;\n cause?: unknown;\n}\n\nexport async function upsertLinearInstallation(\n params: UpsertLinearInstallationParams,\n options: {tx?: unknown} = {},\n): Promise<LinearInstallation> {\n const executor = (options.tx ?? db()) as LinearDb | LinearTx;\n const now = new Date();\n let row: typeof linearInstallations.$inferSelect | undefined;\n\n try {\n [row] = await executor\n .insert(linearInstallations)\n .values({\n connectionId: params.connectionId,\n organizationId: params.organizationId,\n organizationUrlKey: params.organizationUrlKey,\n appUserId: params.appUserId,\n scopes: params.scopes,\n tokenExpiresAt: params.tokenExpiresAt ?? null,\n status: params.status,\n })\n .onConflictDoUpdate({\n target: linearInstallations.organizationId,\n setWhere: eq(linearInstallations.connectionId, params.connectionId),\n set: {\n connectionId: params.connectionId,\n organizationId: params.organizationId,\n organizationUrlKey: params.organizationUrlKey,\n appUserId: params.appUserId,\n scopes: params.scopes,\n tokenExpiresAt: params.tokenExpiresAt ?? null,\n status: params.status,\n updatedAt: now,\n },\n })\n .returning();\n } catch (error) {\n if (isUniqueViolation(error, 'integrations_linear_installations_connection_unique')) {\n throw new LinearConnectionAlreadyLinkedError(params.connectionId);\n }\n throw error;\n }\n\n if (!row) throw new LinearInstallationAlreadyLinkedError(params.organizationId);\n return toLinearInstallation(row);\n}\n\nfunction isUniqueViolation(error: unknown, constraint: string): boolean {\n let current = error;\n while (typeof current === 'object' && current !== null) {\n const postgresError = current as PostgresErrorFields;\n if (postgresError.code === '23505' && postgresError.constraint === constraint) {\n return true;\n }\n current = postgresError.cause;\n }\n return false;\n}\n\nexport async function getLinearInstallationByConnectionId(\n connectionId: string,\n options: {tx?: unknown} = {},\n): Promise<LinearInstallation | undefined> {\n const executor = (options.tx ?? db()) as LinearDb | LinearTx;\n const rows = await executor\n .select()\n .from(linearInstallations)\n .where(eq(linearInstallations.connectionId, connectionId))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toLinearInstallation(row);\n}\n\nexport async function getLinearInstallationByOrganizationId(\n organizationId: string,\n options: {tx?: unknown} = {},\n): Promise<LinearInstallation | undefined> {\n const executor = (options.tx ?? db()) as LinearDb | LinearTx;\n const rows = await executor\n .select()\n .from(linearInstallations)\n .where(eq(linearInstallations.organizationId, organizationId))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toLinearInstallation(row);\n}\n\nexport async function updateLinearInstallationTokenExpiry(\n params: UpdateLinearInstallationTokenExpiryParams,\n options: {tx?: unknown} = {},\n): Promise<LinearInstallation | undefined> {\n const executor = (options.tx ?? db()) as LinearDb | LinearTx;\n const [row] = await executor\n .update(linearInstallations)\n .set({\n tokenExpiresAt: params.tokenExpiresAt,\n ...(params.scopes === undefined ? {} : {scopes: params.scopes}),\n updatedAt: new Date(),\n })\n .where(eq(linearInstallations.connectionId, params.connectionId))\n .returning();\n if (!row) return undefined;\n return toLinearInstallation(row);\n}\n\nexport async function markLinearInstallationRevoked(\n connectionId: string,\n options: {tx?: unknown} = {},\n): Promise<LinearInstallation | undefined> {\n const executor = (options.tx ?? db()) as LinearDb | LinearTx;\n const [row] = await executor\n .update(linearInstallations)\n .set({status: 'revoked', updatedAt: new Date()})\n .where(eq(linearInstallations.connectionId, connectionId))\n .returning();\n if (!row) return undefined;\n return toLinearInstallation(row);\n}\n\nexport async function deleteLinearInstallationByConnectionId(\n connectionId: string,\n options: {tx?: unknown} = {},\n): Promise<boolean> {\n const executor = (options.tx ?? db()) as LinearDb | LinearTx;\n const result = await executor\n .delete(linearInstallations)\n .where(eq(linearInstallations.connectionId, connectionId));\n return (result.rowCount ?? 0) > 0;\n}\n\nexport type LinearRefreshLockResult<T> = {acquired: true; value: T} | {acquired: false};\n\nexport function withLinearRefreshLock<T>(\n connectionId: string,\n fn: () => Promise<T>,\n): Promise<LinearRefreshLockResult<T>> {\n return withLinearRefreshLockClient(connectionId, fn);\n}\n\nasync function withLinearRefreshLockClient<T>(\n connectionId: string,\n fn: () => Promise<T>,\n): Promise<LinearRefreshLockResult<T>> {\n const client = await pgClient().connect();\n let acquired = false;\n try {\n const lock = await client.query<{acquired: boolean}>(\n 'SELECT pg_try_advisory_lock(hashtext($1)) AS acquired',\n [connectionId],\n );\n acquired = lock.rows[0]?.acquired === true;\n if (!acquired) return {acquired: false};\n\n const value = await fn();\n return {acquired: true, value};\n } finally {\n try {\n if (acquired) {\n await client.query('SELECT pg_advisory_unlock(hashtext($1))', [connectionId]);\n }\n } finally {\n client.release();\n }\n }\n}\n"],"names":["pgClient","eq","LinearConnectionAlreadyLinkedError","LinearInstallationAlreadyLinkedError","db","linearInstallations","toLinearInstallation","upsertLinearInstallation","params","options","executor","tx","now","Date","row","insert","values","connectionId","organizationId","organizationUrlKey","appUserId","scopes","tokenExpiresAt","status","onConflictDoUpdate","target","setWhere","set","updatedAt","returning","error","isUniqueViolation","constraint","current","postgresError","code","cause","getLinearInstallationByConnectionId","rows","select","from","where","limit","undefined","getLinearInstallationByOrganizationId","updateLinearInstallationTokenExpiry","update","markLinearInstallationRevoked","deleteLinearInstallationByConnectionId","result","delete","rowCount","withLinearRefreshLock","fn","withLinearRefreshLockClient","client","connect","acquired","lock","query","value","release"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,yBAAyB;AAChD,SAAQC,EAAE,QAAO,cAAc;AAC/B,SACEC,kCAAkC,EAClCC,oCAAoC,QAC/B,kBAAkB;AACzB,SAAQC,EAAE,QAAO,UAAU;AAC3B,SAAQC,mBAAmB,EAAEC,oBAAoB,QAAO,4BAA4B;AA0CpF,OAAO,eAAeC,yBACpBC,MAAsC,EACtCC,UAA0B,CAAC,CAAC;IAE5B,MAAMC,WAAYD,QAAQE,EAAE,IAAIP;IAChC,MAAMQ,MAAM,IAAIC;IAChB,IAAIC;IAEJ,IAAI;QACF,CAACA,IAAI,GAAG,MAAMJ,SACXK,MAAM,CAACV,qBACPW,MAAM,CAAC;YACNC,cAAcT,OAAOS,YAAY;YACjCC,gBAAgBV,OAAOU,cAAc;YACrCC,oBAAoBX,OAAOW,kBAAkB;YAC7CC,WAAWZ,OAAOY,SAAS;YAC3BC,QAAQb,OAAOa,MAAM;YACrBC,gBAAgBd,OAAOc,cAAc,IAAI;YACzCC,QAAQf,OAAOe,MAAM;QACvB,GACCC,kBAAkB,CAAC;YAClBC,QA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EAAE,IAAIP;IAChC,MAAM6C,SAAS,MAAMvC,SAClBwC,MAAM,CAAC7C,qBACPoC,KAAK,CAACxC,GAAGI,oBAAoBY,YAAY,EAAEA;IAC9C,OAAO,AAACgC,CAAAA,OAAOE,QAAQ,IAAI,CAAA,IAAK;AAClC;AAIA,OAAO,SAASC,sBACdnC,YAAoB,EACpBoC,EAAoB;IAEpB,OAAOC,4BAA4BrC,cAAcoC;AACnD;AAEA,eAAeC,4BACbrC,YAAoB,EACpBoC,EAAoB;IAEpB,MAAME,SAAS,MAAMvD,WAAWwD,OAAO;IACvC,IAAIC,WAAW;IACf,IAAI;QACF,MAAMC,OAAO,MAAMH,OAAOI,KAAK,CAC7B,yDACA;YAAC1C;SAAa;QAEhBwC,WAAWC,KAAKpB,IAAI,CAAC,EAAE,EAAEmB,aAAa;QACtC,IAAI,CAACA,UAAU,OAAO;YAACA,UAAU;QAAK;QAEtC,MAAMG,QAAQ,MAAMP;QACpB,OAAO;YAACI,UAAU;YAAMG;QAAK;IAC/B,SAAU;QACR,IAAI;YACF,IAAIH,UAAU;gBACZ,MAAMF,OAAOI,KAAK,CAAC,2CAA2C;oBAAC1C;iBAAa;YAC9E;QACF,SAAU;YACRsC,OAAOM,OAAO;QAChB;IACF;AACF"}
|
|
@@ -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_linear_${name}`);\n"],"names":["pgTableCreator","pgTable","name"],"mappings":"AAAA,SAAQA,cAAc,QAAO,sBAAsB;AAEnD,OAAO,MAAMC,UAAUD,eAAe,CAACE,OAAS,CAAC,oBAAoB,EAAEA,MAAM,EAAE"}
|