@shipfox/api-integration-gitea 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.
Files changed (119) hide show
  1. package/.turbo/turbo-build.log +2 -0
  2. package/.turbo/turbo-type$colon$emit.log +1 -0
  3. package/.turbo/turbo-type.log +1 -0
  4. package/CHANGELOG.md +96 -0
  5. package/LICENSE +21 -0
  6. package/README.md +61 -0
  7. package/dist/api/client.d.ts +58 -0
  8. package/dist/api/client.d.ts.map +1 -0
  9. package/dist/api/client.js +225 -0
  10. package/dist/api/client.js.map +1 -0
  11. package/dist/config.d.ts +11 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +38 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/core/connect.d.ts +18 -0
  16. package/dist/core/connect.d.ts.map +1 -0
  17. package/dist/core/connect.js +32 -0
  18. package/dist/core/connect.js.map +1 -0
  19. package/dist/core/connection-url.d.ts +2 -0
  20. package/dist/core/connection-url.d.ts.map +1 -0
  21. package/dist/core/connection-url.js +8 -0
  22. package/dist/core/connection-url.js.map +1 -0
  23. package/dist/core/errors.d.ts +10 -0
  24. package/dist/core/errors.d.ts.map +1 -0
  25. package/dist/core/errors.js +17 -0
  26. package/dist/core/errors.js.map +1 -0
  27. package/dist/core/source-control.d.ts +14 -0
  28. package/dist/core/source-control.d.ts.map +1 -0
  29. package/dist/core/source-control.js +177 -0
  30. package/dist/core/source-control.js.map +1 -0
  31. package/dist/core/webhook.d.ts +38 -0
  32. package/dist/core/webhook.d.ts.map +1 -0
  33. package/dist/core/webhook.js +162 -0
  34. package/dist/core/webhook.js.map +1 -0
  35. package/dist/db/connections.d.ts +19 -0
  36. package/dist/db/connections.d.ts.map +1 -0
  37. package/dist/db/connections.js +42 -0
  38. package/dist/db/connections.js.map +1 -0
  39. package/dist/db/db.d.ts +191 -0
  40. package/dist/db/db.d.ts.map +1 -0
  41. package/dist/db/db.js +18 -0
  42. package/dist/db/db.js.map +1 -0
  43. package/dist/db/migrations.d.ts +2 -0
  44. package/dist/db/migrations.d.ts.map +1 -0
  45. package/dist/db/migrations.js +5 -0
  46. package/dist/db/migrations.js.map +1 -0
  47. package/dist/db/schema/common.d.ts +2 -0
  48. package/dist/db/schema/common.d.ts.map +1 -0
  49. package/dist/db/schema/common.js +4 -0
  50. package/dist/db/schema/common.js.map +1 -0
  51. package/dist/db/schema/connections.d.ts +97 -0
  52. package/dist/db/schema/connections.d.ts.map +1 -0
  53. package/dist/db/schema/connections.js +28 -0
  54. package/dist/db/schema/connections.js.map +1 -0
  55. package/dist/index.d.ts +39 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +42 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/presentation/dto/integrations.d.ts +17 -0
  60. package/dist/presentation/dto/integrations.d.ts.map +1 -0
  61. package/dist/presentation/dto/integrations.js +11 -0
  62. package/dist/presentation/dto/integrations.js.map +1 -0
  63. package/dist/presentation/routes/connections.d.ts +13 -0
  64. package/dist/presentation/routes/connections.d.ts.map +1 -0
  65. package/dist/presentation/routes/connections.js +47 -0
  66. package/dist/presentation/routes/connections.js.map +1 -0
  67. package/dist/presentation/routes/errors.d.ts +2 -0
  68. package/dist/presentation/routes/errors.d.ts.map +1 -0
  69. package/dist/presentation/routes/errors.js +36 -0
  70. package/dist/presentation/routes/errors.js.map +1 -0
  71. package/dist/presentation/routes/webhooks.d.ts +11 -0
  72. package/dist/presentation/routes/webhooks.d.ts.map +1 -0
  73. package/dist/presentation/routes/webhooks.js +109 -0
  74. package/dist/presentation/routes/webhooks.js.map +1 -0
  75. package/dist/tsconfig.test.tsbuildinfo +1 -0
  76. package/drizzle/0000_initial.sql +10 -0
  77. package/drizzle/meta/0000_snapshot.json +96 -0
  78. package/drizzle/meta/_journal.json +13 -0
  79. package/drizzle.config.ts +7 -0
  80. package/package.json +66 -0
  81. package/src/api/client.test.ts +367 -0
  82. package/src/api/client.ts +364 -0
  83. package/src/config.ts +42 -0
  84. package/src/connection-external-url.test.ts +36 -0
  85. package/src/core/connect.test.ts +149 -0
  86. package/src/core/connect.ts +52 -0
  87. package/src/core/connection-url.ts +8 -0
  88. package/src/core/errors.ts +17 -0
  89. package/src/core/source-control-clone-url.test.ts +83 -0
  90. package/src/core/source-control.test.ts +349 -0
  91. package/src/core/source-control.ts +231 -0
  92. package/src/core/webhook.test.ts +396 -0
  93. package/src/core/webhook.ts +203 -0
  94. package/src/db/connections.test.ts +69 -0
  95. package/src/db/connections.ts +80 -0
  96. package/src/db/db.ts +18 -0
  97. package/src/db/migrations.ts +4 -0
  98. package/src/db/schema/common.ts +3 -0
  99. package/src/db/schema/connections.ts +32 -0
  100. package/src/index.test.ts +23 -0
  101. package/src/index.ts +83 -0
  102. package/src/presentation/dto/integrations.ts +14 -0
  103. package/src/presentation/routes/connections.test.ts +200 -0
  104. package/src/presentation/routes/connections.ts +63 -0
  105. package/src/presentation/routes/errors.ts +35 -0
  106. package/src/presentation/routes/webhooks.test.ts +188 -0
  107. package/src/presentation/routes/webhooks.ts +111 -0
  108. package/test/env.ts +11 -0
  109. package/test/factories/gitea-connection.ts +19 -0
  110. package/test/factories/index.ts +1 -0
  111. package/test/fixtures/gitea-webhook.ts +237 -0
  112. package/test/globalSetup.ts +14 -0
  113. package/test/index.ts +6 -0
  114. package/test/setup.ts +17 -0
  115. package/tsconfig.build.json +9 -0
  116. package/tsconfig.build.tsbuildinfo +1 -0
  117. package/tsconfig.json +3 -0
  118. package/tsconfig.test.json +9 -0
  119. package/vitest.config.ts +12 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/db/connections.ts"],"sourcesContent":["import {eq} from 'drizzle-orm';\nimport {GiteaOrgAlreadyLinkedError} from '#core/errors.js';\nimport {db} from './db.js';\nimport {giteaConnections, toGiteaConnection} from './schema/connections.js';\n\nexport interface GiteaConnection {\n id: string;\n connectionId: string;\n org: string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface UpsertGiteaConnectionParams {\n connectionId: string;\n org: string;\n}\n\ntype GiteaDb = ReturnType<typeof db>;\ntype GiteaTx = Parameters<Parameters<GiteaDb['transaction']>[0]>[0];\n\nexport async function upsertGiteaConnection(\n params: UpsertGiteaConnectionParams,\n options: {tx?: unknown} = {},\n): Promise<GiteaConnection> {\n const executor = (options.tx ?? db()) as GiteaDb | GiteaTx;\n const now = new Date();\n const [row] = await executor\n .insert(giteaConnections)\n .values({\n connectionId: params.connectionId,\n org: params.org,\n })\n .onConflictDoUpdate({\n target: giteaConnections.org,\n // TOCTOU guard: only (re)point this org at the connection that already\n // owns it. A concurrent connect of the same org to a different workspace\n // inserts its own connection row, so its connectionId differs here; the\n // predicate is false, Postgres updates nothing, and the empty RETURNING\n // below rolls the losing transaction back instead of silently repointing\n // the org (cross-tenant connection takeover).\n setWhere: eq(giteaConnections.connectionId, params.connectionId),\n set: {\n connectionId: params.connectionId,\n updatedAt: now,\n },\n })\n .returning();\n\n if (!row) throw new GiteaOrgAlreadyLinkedError(params.org);\n return toGiteaConnection(row);\n}\n\nexport async function getGiteaConnectionByOrg(\n org: string,\n options: {tx?: unknown} = {},\n): Promise<GiteaConnection | undefined> {\n const executor = (options.tx ?? db()) as GiteaDb | GiteaTx;\n const rows = await executor\n .select()\n .from(giteaConnections)\n .where(eq(giteaConnections.org, org))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toGiteaConnection(row);\n}\n\nexport async function getGiteaConnectionByConnectionId(\n connectionId: string,\n): Promise<GiteaConnection | undefined> {\n const rows = await db()\n .select()\n .from(giteaConnections)\n .where(eq(giteaConnections.connectionId, connectionId))\n .limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toGiteaConnection(row);\n}\n"],"names":["eq","GiteaOrgAlreadyLinkedError","db","giteaConnections","toGiteaConnection","upsertGiteaConnection","params","options","executor","tx","now","Date","row","insert","values","connectionId","org","onConflictDoUpdate","target","setWhere","set","updatedAt","returning","getGiteaConnectionByOrg","rows","select","from","where","limit","undefined","getGiteaConnectionByConnectionId"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAc;AAC/B,SAAQC,0BAA0B,QAAO,kBAAkB;AAC3D,SAAQC,EAAE,QAAO,UAAU;AAC3B,SAAQC,gBAAgB,EAAEC,iBAAiB,QAAO,0BAA0B;AAkB5E,OAAO,eAAeC,sBACpBC,MAAmC,EACnCC,UAA0B,CAAC,CAAC;IAE5B,MAAMC,WAAYD,QAAQE,EAAE,IAAIP;IAChC,MAAMQ,MAAM,IAAIC;IAChB,MAAM,CAACC,IAAI,GAAG,MAAMJ,SACjBK,MAAM,CAACV,kBACPW,MAAM,CAAC;QACNC,cAAcT,OAAOS,YAAY;QACjCC,KAAKV,OAAOU,GAAG;IACjB,GACCC,kBAAkB,CAAC;QAClBC,QAAQf,iBAAiBa,GAAG;QAC5B,uEAAuE;QACvE,yEAAyE;QACzE,wEAAwE;QACxE,wEAAwE;QACxE,yEAAyE;QACzE,8CAA8C;QAC9CG,UAAUnB,GAAGG,iBAAiBY,YAAY,EAAET,OAAOS,YAAY;QAC/DK,KAAK;YACHL,cAAcT,OAAOS,YAAY;YACjCM,WAAWX;QACb;IACF,GACCY,SAAS;IAEZ,IAAI,CAACV,KAAK,MAAM,IAAIX,2BAA2BK,OAAOU,GAAG;IACzD,OAAOZ,kBAAkBQ;AAC3B;AAEA,OAAO,eAAeW,wBACpBP,GAAW,EACXT,UAA0B,CAAC,CAAC;IAE5B,MAAMC,WAAYD,QAAQE,EAAE,IAAIP;IAChC,MAAMsB,OAAO,MAAMhB,SAChBiB,MAAM,GACNC,IAAI,CAACvB,kBACLwB,KAAK,CAAC3B,GAAGG,iBAAiBa,GAAG,EAAEA,MAC/BY,KAAK,CAAC;IACT,MAAMhB,MAAMY,IAAI,CAAC,EAAE;IACnB,IAAI,CAACZ,KAAK,OAAOiB;IACjB,OAAOzB,kBAAkBQ;AAC3B;AAEA,OAAO,eAAekB,iCACpBf,YAAoB;IAEpB,MAAMS,OAAO,MAAMtB,KAChBuB,MAAM,GACNC,IAAI,CAACvB,kBACLwB,KAAK,CAAC3B,GAAGG,iBAAiBY,YAAY,EAAEA,eACxCa,KAAK,CAAC;IACT,MAAMhB,MAAMY,IAAI,CAAC,EAAE;IACnB,IAAI,CAACZ,KAAK,OAAOiB;IACjB,OAAOzB,kBAAkBQ;AAC3B"}
@@ -0,0 +1,191 @@
1
+ import { type NodePgDatabase } from '@shipfox/node-drizzle';
2
+ export declare const schema: {
3
+ giteaConnections: import("drizzle-orm/pg-core").PgTableWithColumns<{
4
+ name: "connections";
5
+ schema: undefined;
6
+ columns: {
7
+ id: import("drizzle-orm/pg-core").PgColumn<{
8
+ name: "id";
9
+ tableName: "connections";
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: "connections";
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
+ org: import("drizzle-orm/pg-core").PgColumn<{
42
+ name: "org";
43
+ tableName: "connections";
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
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
59
+ name: "created_at";
60
+ tableName: "connections";
61
+ dataType: "date";
62
+ columnType: "PgTimestamp";
63
+ data: Date;
64
+ driverParam: string;
65
+ notNull: true;
66
+ hasDefault: true;
67
+ isPrimaryKey: false;
68
+ isAutoincrement: false;
69
+ hasRuntimeDefault: false;
70
+ enumValues: undefined;
71
+ baseColumn: never;
72
+ identity: undefined;
73
+ generated: undefined;
74
+ }, {}, {}>;
75
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
76
+ name: "updated_at";
77
+ tableName: "connections";
78
+ dataType: "date";
79
+ columnType: "PgTimestamp";
80
+ data: Date;
81
+ driverParam: string;
82
+ notNull: true;
83
+ hasDefault: true;
84
+ isPrimaryKey: false;
85
+ isAutoincrement: false;
86
+ hasRuntimeDefault: false;
87
+ enumValues: undefined;
88
+ baseColumn: never;
89
+ identity: undefined;
90
+ generated: undefined;
91
+ }, {}, {}>;
92
+ };
93
+ dialect: "pg";
94
+ }>;
95
+ };
96
+ export declare function db(): NodePgDatabase<{
97
+ giteaConnections: import("drizzle-orm/pg-core").PgTableWithColumns<{
98
+ name: "connections";
99
+ schema: undefined;
100
+ columns: {
101
+ id: import("drizzle-orm/pg-core").PgColumn<{
102
+ name: "id";
103
+ tableName: "connections";
104
+ dataType: "string";
105
+ columnType: "PgUUID";
106
+ data: string;
107
+ driverParam: string;
108
+ notNull: true;
109
+ hasDefault: true;
110
+ isPrimaryKey: true;
111
+ isAutoincrement: false;
112
+ hasRuntimeDefault: false;
113
+ enumValues: undefined;
114
+ baseColumn: never;
115
+ identity: undefined;
116
+ generated: undefined;
117
+ }, {}, {}>;
118
+ connectionId: import("drizzle-orm/pg-core").PgColumn<{
119
+ name: "connection_id";
120
+ tableName: "connections";
121
+ dataType: "string";
122
+ columnType: "PgUUID";
123
+ data: string;
124
+ driverParam: string;
125
+ notNull: true;
126
+ hasDefault: false;
127
+ isPrimaryKey: false;
128
+ isAutoincrement: false;
129
+ hasRuntimeDefault: false;
130
+ enumValues: undefined;
131
+ baseColumn: never;
132
+ identity: undefined;
133
+ generated: undefined;
134
+ }, {}, {}>;
135
+ org: import("drizzle-orm/pg-core").PgColumn<{
136
+ name: "org";
137
+ tableName: "connections";
138
+ dataType: "string";
139
+ columnType: "PgText";
140
+ data: string;
141
+ driverParam: string;
142
+ notNull: true;
143
+ hasDefault: false;
144
+ isPrimaryKey: false;
145
+ isAutoincrement: false;
146
+ hasRuntimeDefault: false;
147
+ enumValues: [string, ...string[]];
148
+ baseColumn: never;
149
+ identity: undefined;
150
+ generated: undefined;
151
+ }, {}, {}>;
152
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
153
+ name: "created_at";
154
+ tableName: "connections";
155
+ dataType: "date";
156
+ columnType: "PgTimestamp";
157
+ data: Date;
158
+ driverParam: string;
159
+ notNull: true;
160
+ hasDefault: true;
161
+ isPrimaryKey: false;
162
+ isAutoincrement: false;
163
+ hasRuntimeDefault: false;
164
+ enumValues: undefined;
165
+ baseColumn: never;
166
+ identity: undefined;
167
+ generated: undefined;
168
+ }, {}, {}>;
169
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
170
+ name: "updated_at";
171
+ tableName: "connections";
172
+ dataType: "date";
173
+ columnType: "PgTimestamp";
174
+ data: Date;
175
+ driverParam: string;
176
+ notNull: true;
177
+ hasDefault: true;
178
+ isPrimaryKey: false;
179
+ isAutoincrement: false;
180
+ hasRuntimeDefault: false;
181
+ enumValues: undefined;
182
+ baseColumn: never;
183
+ identity: undefined;
184
+ generated: undefined;
185
+ }, {}, {}>;
186
+ };
187
+ dialect: "pg";
188
+ }>;
189
+ }>;
190
+ export declare function closeDb(): void;
191
+ //# 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 { giteaConnections } from './schema/connections.js';
4
+ export const schema = {
5
+ giteaConnections
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 {giteaConnections} from './schema/connections.js';\n\nexport const schema = {\n giteaConnections,\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","giteaConnections","schema","_db","db","closeDb","undefined"],"mappings":"AAAA,SAAQA,OAAO,QAA4B,wBAAwB;AACnE,SAAQC,QAAQ,QAAO,yBAAyB;AAChD,SAAQC,gBAAgB,QAAO,0BAA0B;AAEzD,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,2 @@
1
+ export declare const migrationsPath: string;
2
+ //# sourceMappingURL=migrations.d.ts.map
@@ -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,5 @@
1
+ import { dirname, resolve } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ export const migrationsPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../drizzle');
4
+
5
+ //# sourceMappingURL=migrations.js.map
@@ -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,2 @@
1
+ export declare const pgTable: import("drizzle-orm/pg-core").PgTableFn<undefined>;
2
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/db/schema/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,oDAAyD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { pgTableCreator } from 'drizzle-orm/pg-core';
2
+ export const pgTable = pgTableCreator((name)=>`integrations_gitea_${name}`);
3
+
4
+ //# sourceMappingURL=common.js.map
@@ -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_gitea_${name}`);\n"],"names":["pgTableCreator","pgTable","name"],"mappings":"AAAA,SAAQA,cAAc,QAAO,sBAAsB;AAEnD,OAAO,MAAMC,UAAUD,eAAe,CAACE,OAAS,CAAC,mBAAmB,EAAEA,MAAM,EAAE"}
@@ -0,0 +1,97 @@
1
+ import type { GiteaConnection } from '#db/connections.js';
2
+ export declare const giteaConnections: import("drizzle-orm/pg-core").PgTableWithColumns<{
3
+ name: "connections";
4
+ schema: undefined;
5
+ columns: {
6
+ id: import("drizzle-orm/pg-core").PgColumn<{
7
+ name: "id";
8
+ tableName: "connections";
9
+ dataType: "string";
10
+ columnType: "PgUUID";
11
+ data: string;
12
+ driverParam: string;
13
+ notNull: true;
14
+ hasDefault: true;
15
+ isPrimaryKey: true;
16
+ isAutoincrement: false;
17
+ hasRuntimeDefault: false;
18
+ enumValues: undefined;
19
+ baseColumn: never;
20
+ identity: undefined;
21
+ generated: undefined;
22
+ }, {}, {}>;
23
+ connectionId: import("drizzle-orm/pg-core").PgColumn<{
24
+ name: "connection_id";
25
+ tableName: "connections";
26
+ dataType: "string";
27
+ columnType: "PgUUID";
28
+ data: string;
29
+ driverParam: string;
30
+ notNull: true;
31
+ hasDefault: false;
32
+ isPrimaryKey: false;
33
+ isAutoincrement: false;
34
+ hasRuntimeDefault: false;
35
+ enumValues: undefined;
36
+ baseColumn: never;
37
+ identity: undefined;
38
+ generated: undefined;
39
+ }, {}, {}>;
40
+ org: import("drizzle-orm/pg-core").PgColumn<{
41
+ name: "org";
42
+ tableName: "connections";
43
+ dataType: "string";
44
+ columnType: "PgText";
45
+ data: string;
46
+ driverParam: string;
47
+ notNull: true;
48
+ hasDefault: false;
49
+ isPrimaryKey: false;
50
+ isAutoincrement: false;
51
+ hasRuntimeDefault: false;
52
+ enumValues: [string, ...string[]];
53
+ baseColumn: never;
54
+ identity: undefined;
55
+ generated: undefined;
56
+ }, {}, {}>;
57
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
58
+ name: "created_at";
59
+ tableName: "connections";
60
+ dataType: "date";
61
+ columnType: "PgTimestamp";
62
+ data: Date;
63
+ driverParam: string;
64
+ notNull: true;
65
+ hasDefault: true;
66
+ isPrimaryKey: false;
67
+ isAutoincrement: false;
68
+ hasRuntimeDefault: false;
69
+ enumValues: undefined;
70
+ baseColumn: never;
71
+ identity: undefined;
72
+ generated: undefined;
73
+ }, {}, {}>;
74
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
75
+ name: "updated_at";
76
+ tableName: "connections";
77
+ dataType: "date";
78
+ columnType: "PgTimestamp";
79
+ data: Date;
80
+ driverParam: string;
81
+ notNull: true;
82
+ hasDefault: true;
83
+ isPrimaryKey: false;
84
+ isAutoincrement: false;
85
+ hasRuntimeDefault: false;
86
+ enumValues: undefined;
87
+ baseColumn: never;
88
+ identity: undefined;
89
+ generated: undefined;
90
+ }, {}, {}>;
91
+ };
92
+ dialect: "pg";
93
+ }>;
94
+ export type GiteaConnectionDb = typeof giteaConnections.$inferSelect;
95
+ export type GiteaConnectionCreateDb = typeof giteaConnections.$inferInsert;
96
+ export declare function toGiteaConnection(row: GiteaConnectionDb): GiteaConnection;
97
+ //# sourceMappingURL=connections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/db/schema/connections.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAGxD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAa5B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAC;AACrE,MAAM,MAAM,uBAAuB,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAC;AAE3E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,iBAAiB,GAAG,eAAe,CAQzE"}
@@ -0,0 +1,28 @@
1
+ import { uuidv7PrimaryKey } from '@shipfox/node-drizzle';
2
+ import { text, timestamp, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
3
+ import { pgTable } from './common.js';
4
+ export const giteaConnections = pgTable('connections', {
5
+ id: uuidv7PrimaryKey(),
6
+ connectionId: uuid('connection_id').notNull(),
7
+ org: text('org').notNull(),
8
+ createdAt: timestamp('created_at', {
9
+ withTimezone: true
10
+ }).notNull().defaultNow(),
11
+ updatedAt: timestamp('updated_at', {
12
+ withTimezone: true
13
+ }).notNull().defaultNow()
14
+ }, (table)=>[
15
+ uniqueIndex('integrations_gitea_connections_connection_unique').on(table.connectionId),
16
+ uniqueIndex('integrations_gitea_connections_org_unique').on(table.org)
17
+ ]);
18
+ export function toGiteaConnection(row) {
19
+ return {
20
+ id: row.id,
21
+ connectionId: row.connectionId,
22
+ org: row.org,
23
+ createdAt: row.createdAt,
24
+ updatedAt: row.updatedAt
25
+ };
26
+ }
27
+
28
+ //# sourceMappingURL=connections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/db/schema/connections.ts"],"sourcesContent":["import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';\nimport {text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';\nimport type {GiteaConnection} from '#db/connections.js';\nimport {pgTable} from './common.js';\n\nexport const giteaConnections = pgTable(\n 'connections',\n {\n id: uuidv7PrimaryKey(),\n connectionId: uuid('connection_id').notNull(),\n org: text('org').notNull(),\n createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),\n updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),\n },\n (table) => [\n uniqueIndex('integrations_gitea_connections_connection_unique').on(table.connectionId),\n uniqueIndex('integrations_gitea_connections_org_unique').on(table.org),\n ],\n);\n\nexport type GiteaConnectionDb = typeof giteaConnections.$inferSelect;\nexport type GiteaConnectionCreateDb = typeof giteaConnections.$inferInsert;\n\nexport function toGiteaConnection(row: GiteaConnectionDb): GiteaConnection {\n return {\n id: row.id,\n connectionId: row.connectionId,\n org: row.org,\n createdAt: row.createdAt,\n updatedAt: row.updatedAt,\n };\n}\n"],"names":["uuidv7PrimaryKey","text","timestamp","uniqueIndex","uuid","pgTable","giteaConnections","id","connectionId","notNull","org","createdAt","withTimezone","defaultNow","updatedAt","table","on","toGiteaConnection","row"],"mappings":"AAAA,SAAQA,gBAAgB,QAAO,wBAAwB;AACvD,SAAQC,IAAI,EAAEC,SAAS,EAAEC,WAAW,EAAEC,IAAI,QAAO,sBAAsB;AAEvE,SAAQC,OAAO,QAAO,cAAc;AAEpC,OAAO,MAAMC,mBAAmBD,QAC9B,eACA;IACEE,IAAIP;IACJQ,cAAcJ,KAAK,iBAAiBK,OAAO;IAC3CC,KAAKT,KAAK,OAAOQ,OAAO;IACxBE,WAAWT,UAAU,cAAc;QAACU,cAAc;IAAI,GAAGH,OAAO,GAAGI,UAAU;IAC7EC,WAAWZ,UAAU,cAAc;QAACU,cAAc;IAAI,GAAGH,OAAO,GAAGI,UAAU;AAC/E,GACA,CAACE,QAAU;QACTZ,YAAY,oDAAoDa,EAAE,CAACD,MAAMP,YAAY;QACrFL,YAAY,6CAA6Ca,EAAE,CAACD,MAAML,GAAG;KACtE,EACD;AAKF,OAAO,SAASO,kBAAkBC,GAAsB;IACtD,OAAO;QACLX,IAAIW,IAAIX,EAAE;QACVC,cAAcU,IAAIV,YAAY;QAC9BE,KAAKQ,IAAIR,GAAG;QACZC,WAAWO,IAAIP,SAAS;QACxBG,WAAWI,IAAIJ,SAAS;IAC1B;AACF"}
@@ -0,0 +1,39 @@
1
+ import type { GetIntegrationConnectionByIdFn, IntegrationConnection, PublishSourcePushFn, RecordDeliveryOnlyFn } from '@shipfox/api-integration-core-dto';
2
+ import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
3
+ import { type GiteaApiClient } from '#api/client.js';
4
+ import type { ConnectGiteaConnectionInput } from '#core/connect.js';
5
+ import { GiteaSourceControlProvider } from '#core/source-control.js';
6
+ import { closeDb, db } from '#db/db.js';
7
+ import { migrationsPath } from '#db/migrations.js';
8
+ export type { GiteaApiClient, GiteaFileContent, GiteaRepository, GiteaRepositoryPage, GiteaTree, GiteaTreeBlob, } from '#api/client.js';
9
+ export { createGiteaApiClient } from '#api/client.js';
10
+ export type { ConnectGiteaConnectionInput } from '#core/connect.js';
11
+ export { handleGiteaConnect } from '#core/connect.js';
12
+ export { GiteaIntegrationProviderError, GiteaOrgAlreadyLinkedError, GiteaOrganizationNotFoundError, } from '#core/errors.js';
13
+ export { GiteaSourceControlProvider } from '#core/source-control.js';
14
+ export type { GiteaConnection, UpsertGiteaConnectionParams } from '#db/connections.js';
15
+ export { getGiteaConnectionByConnectionId, getGiteaConnectionByOrg, upsertGiteaConnection, } from '#db/connections.js';
16
+ export { closeDb, db, migrationsPath };
17
+ export interface CreateGiteaIntegrationProviderOptions {
18
+ gitea?: GiteaApiClient | undefined;
19
+ getExistingGiteaConnection: (input: {
20
+ org: string;
21
+ }) => Promise<IntegrationConnection<'gitea'> | undefined>;
22
+ connectGiteaConnection: (input: ConnectGiteaConnectionInput) => Promise<IntegrationConnection<'gitea'>>;
23
+ coreDb: () => NodePgDatabase<Record<string, unknown>>;
24
+ publishSourcePush: PublishSourcePushFn;
25
+ recordDeliveryOnly: RecordDeliveryOnlyFn;
26
+ getIntegrationConnectionById: GetIntegrationConnectionByIdFn;
27
+ }
28
+ export declare function createGiteaIntegrationProvider(options: CreateGiteaIntegrationProviderOptions): {
29
+ provider: string;
30
+ displayName: string;
31
+ adapters: {
32
+ source_control: GiteaSourceControlProvider;
33
+ };
34
+ connectionExternalUrl(connection: {
35
+ externalAccountId: string;
36
+ }): Promise<string | undefined>;
37
+ routes: import("@shipfox/node-fastify").RouteGroup[];
38
+ };
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAuB,KAAK,cAAc,EAAC,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAC,0BAA0B,EAAC,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAC,OAAO,EAAE,EAAE,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAIjD,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,SAAS,EACT,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAC,oBAAoB,EAAC,MAAM,gBAAgB,CAAC;AACpD,YAAY,EAAC,2BAA2B,EAAC,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,0BAA0B,EAAC,MAAM,yBAAyB,CAAC;AACnE,YAAY,EAAC,eAAe,EAAE,2BAA2B,EAAC,MAAM,oBAAoB,CAAC;AACrF,OAAO,EACL,gCAAgC,EAChC,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,OAAO,EAAE,EAAE,EAAE,cAAc,EAAC,CAAC;AAErC,MAAM,WAAW,qCAAqC;IACpD,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,0BAA0B,EAAE,CAAC,KAAK,EAAE;QAClC,GAAG,EAAE,MAAM,CAAC;KACb,KAAK,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1D,sBAAsB,EAAE,CACtB,KAAK,EAAE,2BAA2B,KAC/B,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,MAAM,EAAE,MAAM,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,iBAAiB,EAAE,mBAAmB,CAAC;IACvC,kBAAkB,EAAE,oBAAoB,CAAC;IACzC,4BAA4B,EAAE,8BAA8B,CAAC;CAC9D;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,qCAAqC;;;;;;sCASvD;QAAC,iBAAiB,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;;EAiB9F"}
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import { giteaProviderKind } from '@shipfox/api-integration-gitea-dto';
2
+ import { createGiteaApiClient } from '#api/client.js';
3
+ import { giteaConnectionExternalUrl } from '#core/connection-url.js';
4
+ import { GiteaSourceControlProvider } from '#core/source-control.js';
5
+ import { closeDb, db } from '#db/db.js';
6
+ import { migrationsPath } from '#db/migrations.js';
7
+ import { createGiteaConnectionRoutes } from '#presentation/routes/connections.js';
8
+ import { createGiteaWebhookRoutes } from '#presentation/routes/webhooks.js';
9
+ export { createGiteaApiClient } from '#api/client.js';
10
+ export { handleGiteaConnect } from '#core/connect.js';
11
+ export { GiteaIntegrationProviderError, GiteaOrgAlreadyLinkedError, GiteaOrganizationNotFoundError } from '#core/errors.js';
12
+ export { GiteaSourceControlProvider } from '#core/source-control.js';
13
+ export { getGiteaConnectionByConnectionId, getGiteaConnectionByOrg, upsertGiteaConnection } from '#db/connections.js';
14
+ export { closeDb, db, migrationsPath };
15
+ export function createGiteaIntegrationProvider(options) {
16
+ const gitea = options.gitea ?? createGiteaApiClient();
17
+ return {
18
+ provider: giteaProviderKind,
19
+ displayName: 'Gitea',
20
+ adapters: {
21
+ source_control: new GiteaSourceControlProvider(gitea)
22
+ },
23
+ connectionExternalUrl (connection) {
24
+ return Promise.resolve(giteaConnectionExternalUrl(connection.externalAccountId));
25
+ },
26
+ routes: [
27
+ createGiteaConnectionRoutes({
28
+ gitea,
29
+ getExistingGiteaConnection: options.getExistingGiteaConnection,
30
+ connectGiteaConnection: options.connectGiteaConnection
31
+ }),
32
+ createGiteaWebhookRoutes({
33
+ coreDb: options.coreDb,
34
+ publishSourcePush: options.publishSourcePush,
35
+ recordDeliveryOnly: options.recordDeliveryOnly,
36
+ getIntegrationConnectionById: options.getIntegrationConnectionById
37
+ })
38
+ ]
39
+ };
40
+ }
41
+
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n GetIntegrationConnectionByIdFn,\n IntegrationConnection,\n PublishSourcePushFn,\n RecordDeliveryOnlyFn,\n} from '@shipfox/api-integration-core-dto';\nimport {giteaProviderKind} from '@shipfox/api-integration-gitea-dto';\nimport type {NodePgDatabase} from 'drizzle-orm/node-postgres';\nimport {createGiteaApiClient, type GiteaApiClient} from '#api/client.js';\nimport type {ConnectGiteaConnectionInput} from '#core/connect.js';\nimport {giteaConnectionExternalUrl} from '#core/connection-url.js';\nimport {GiteaSourceControlProvider} from '#core/source-control.js';\nimport {closeDb, db} from '#db/db.js';\nimport {migrationsPath} from '#db/migrations.js';\nimport {createGiteaConnectionRoutes} from '#presentation/routes/connections.js';\nimport {createGiteaWebhookRoutes} from '#presentation/routes/webhooks.js';\n\nexport type {\n GiteaApiClient,\n GiteaFileContent,\n GiteaRepository,\n GiteaRepositoryPage,\n GiteaTree,\n GiteaTreeBlob,\n} from '#api/client.js';\nexport {createGiteaApiClient} from '#api/client.js';\nexport type {ConnectGiteaConnectionInput} from '#core/connect.js';\nexport {handleGiteaConnect} from '#core/connect.js';\nexport {\n GiteaIntegrationProviderError,\n GiteaOrgAlreadyLinkedError,\n GiteaOrganizationNotFoundError,\n} from '#core/errors.js';\nexport {GiteaSourceControlProvider} from '#core/source-control.js';\nexport type {GiteaConnection, UpsertGiteaConnectionParams} from '#db/connections.js';\nexport {\n getGiteaConnectionByConnectionId,\n getGiteaConnectionByOrg,\n upsertGiteaConnection,\n} from '#db/connections.js';\nexport {closeDb, db, migrationsPath};\n\nexport interface CreateGiteaIntegrationProviderOptions {\n gitea?: GiteaApiClient | undefined;\n getExistingGiteaConnection: (input: {\n org: string;\n }) => Promise<IntegrationConnection<'gitea'> | undefined>;\n connectGiteaConnection: (\n input: ConnectGiteaConnectionInput,\n ) => Promise<IntegrationConnection<'gitea'>>;\n coreDb: () => NodePgDatabase<Record<string, unknown>>;\n publishSourcePush: PublishSourcePushFn;\n recordDeliveryOnly: RecordDeliveryOnlyFn;\n getIntegrationConnectionById: GetIntegrationConnectionByIdFn;\n}\n\nexport function createGiteaIntegrationProvider(options: CreateGiteaIntegrationProviderOptions) {\n const gitea = options.gitea ?? createGiteaApiClient();\n\n return {\n provider: giteaProviderKind,\n displayName: 'Gitea',\n adapters: {\n source_control: new GiteaSourceControlProvider(gitea),\n },\n connectionExternalUrl(connection: {externalAccountId: string}): Promise<string | undefined> {\n return Promise.resolve(giteaConnectionExternalUrl(connection.externalAccountId));\n },\n routes: [\n createGiteaConnectionRoutes({\n gitea,\n getExistingGiteaConnection: options.getExistingGiteaConnection,\n connectGiteaConnection: options.connectGiteaConnection,\n }),\n createGiteaWebhookRoutes({\n coreDb: options.coreDb,\n publishSourcePush: options.publishSourcePush,\n recordDeliveryOnly: options.recordDeliveryOnly,\n getIntegrationConnectionById: options.getIntegrationConnectionById,\n }),\n ],\n };\n}\n"],"names":["giteaProviderKind","createGiteaApiClient","giteaConnectionExternalUrl","GiteaSourceControlProvider","closeDb","db","migrationsPath","createGiteaConnectionRoutes","createGiteaWebhookRoutes","handleGiteaConnect","GiteaIntegrationProviderError","GiteaOrgAlreadyLinkedError","GiteaOrganizationNotFoundError","getGiteaConnectionByConnectionId","getGiteaConnectionByOrg","upsertGiteaConnection","createGiteaIntegrationProvider","options","gitea","provider","displayName","adapters","source_control","connectionExternalUrl","connection","Promise","resolve","externalAccountId","routes","getExistingGiteaConnection","connectGiteaConnection","coreDb","publishSourcePush","recordDeliveryOnly","getIntegrationConnectionById"],"mappings":"AAMA,SAAQA,iBAAiB,QAAO,qCAAqC;AAErE,SAAQC,oBAAoB,QAA4B,iBAAiB;AAEzE,SAAQC,0BAA0B,QAAO,0BAA0B;AACnE,SAAQC,0BAA0B,QAAO,0BAA0B;AACnE,SAAQC,OAAO,EAAEC,EAAE,QAAO,YAAY;AACtC,SAAQC,cAAc,QAAO,oBAAoB;AACjD,SAAQC,2BAA2B,QAAO,sCAAsC;AAChF,SAAQC,wBAAwB,QAAO,mCAAmC;AAU1E,SAAQP,oBAAoB,QAAO,iBAAiB;AAEpD,SAAQQ,kBAAkB,QAAO,mBAAmB;AACpD,SACEC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,8BAA8B,QACzB,kBAAkB;AACzB,SAAQT,0BAA0B,QAAO,0BAA0B;AAEnE,SACEU,gCAAgC,EAChCC,uBAAuB,EACvBC,qBAAqB,QAChB,qBAAqB;AAC5B,SAAQX,OAAO,EAAEC,EAAE,EAAEC,cAAc,GAAE;AAgBrC,OAAO,SAASU,+BAA+BC,OAA8C;IAC3F,MAAMC,QAAQD,QAAQC,KAAK,IAAIjB;IAE/B,OAAO;QACLkB,UAAUnB;QACVoB,aAAa;QACbC,UAAU;YACRC,gBAAgB,IAAInB,2BAA2Be;QACjD;QACAK,uBAAsBC,UAAuC;YAC3D,OAAOC,QAAQC,OAAO,CAACxB,2BAA2BsB,WAAWG,iBAAiB;QAChF;QACAC,QAAQ;YACNrB,4BAA4B;gBAC1BW;gBACAW,4BAA4BZ,QAAQY,0BAA0B;gBAC9DC,wBAAwBb,QAAQa,sBAAsB;YACxD;YACAtB,yBAAyB;gBACvBuB,QAAQd,QAAQc,MAAM;gBACtBC,mBAAmBf,QAAQe,iBAAiB;gBAC5CC,oBAAoBhB,QAAQgB,kBAAkB;gBAC9CC,8BAA8BjB,QAAQiB,4BAA4B;YACpE;SACD;IACH;AACF"}
@@ -0,0 +1,17 @@
1
+ import { type IntegrationConnection } from '@shipfox/api-integration-core-dto';
2
+ export declare function toIntegrationConnectionDto(connection: IntegrationConnection<'gitea'>, options?: {
3
+ externalUrl?: string | undefined;
4
+ }): {
5
+ created_at: string;
6
+ updated_at: string;
7
+ external_url?: string;
8
+ id: string;
9
+ workspace_id: string;
10
+ provider: string;
11
+ external_account_id: string;
12
+ slug: string;
13
+ display_name: string;
14
+ lifecycle_status: import("@shipfox/api-integration-core-dto").IntegrationConnectionLifecycleStatus;
15
+ capabilities: import("@shipfox/api-integration-core-dto").IntegrationCapability[];
16
+ };
17
+ //# sourceMappingURL=integrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrations.d.ts","sourceRoot":"","sources":["../../../src/presentation/dto/integrations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,mCAAmC,CAAC;AAE3C,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAC1C,OAAO,GAAE;IAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAM;;;;;;;;;;;;EAMjD"}
@@ -0,0 +1,11 @@
1
+ import { toIntegrationConnectionDto as toCoreIntegrationConnectionDto } from '@shipfox/api-integration-core-dto';
2
+ export function toIntegrationConnectionDto(connection, options = {}) {
3
+ return toCoreIntegrationConnectionDto(connection, {
4
+ capabilities: [
5
+ 'source_control'
6
+ ],
7
+ externalUrl: options.externalUrl
8
+ });
9
+ }
10
+
11
+ //# sourceMappingURL=integrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/presentation/dto/integrations.ts"],"sourcesContent":["import {\n type IntegrationConnection,\n toIntegrationConnectionDto as toCoreIntegrationConnectionDto,\n} from '@shipfox/api-integration-core-dto';\n\nexport function toIntegrationConnectionDto(\n connection: IntegrationConnection<'gitea'>,\n options: {externalUrl?: string | undefined} = {},\n) {\n return toCoreIntegrationConnectionDto(connection, {\n capabilities: ['source_control'],\n externalUrl: options.externalUrl,\n });\n}\n"],"names":["toIntegrationConnectionDto","toCoreIntegrationConnectionDto","connection","options","capabilities","externalUrl"],"mappings":"AAAA,SAEEA,8BAA8BC,8BAA8B,QACvD,oCAAoC;AAE3C,OAAO,SAASD,2BACdE,UAA0C,EAC1CC,UAA8C,CAAC,CAAC;IAEhD,OAAOF,+BAA+BC,YAAY;QAChDE,cAAc;YAAC;SAAiB;QAChCC,aAAaF,QAAQE,WAAW;IAClC;AACF"}
@@ -0,0 +1,13 @@
1
+ import type { IntegrationConnection } from '@shipfox/api-integration-core-dto';
2
+ import { type RouteGroup } from '@shipfox/node-fastify';
3
+ import type { GiteaApiClient } from '#api/client.js';
4
+ import { type ConnectGiteaConnectionInput } from '#core/connect.js';
5
+ export interface CreateGiteaConnectionRoutesOptions {
6
+ gitea: GiteaApiClient;
7
+ getExistingGiteaConnection: (input: {
8
+ org: string;
9
+ }) => Promise<IntegrationConnection<'gitea'> | undefined>;
10
+ connectGiteaConnection: (input: ConnectGiteaConnectionInput) => Promise<IntegrationConnection<'gitea'>>;
11
+ }
12
+ export declare function createGiteaConnectionRoutes({ gitea, getExistingGiteaConnection, connectGiteaConnection, }: CreateGiteaConnectionRoutesOptions): RouteGroup;
13
+ //# sourceMappingURL=connections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/connections.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,mCAAmC,CAAC;AAK7E,OAAO,EAAc,KAAK,UAAU,EAAC,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAC,KAAK,2BAA2B,EAAqB,MAAM,kBAAkB,CAAC;AAKtF,MAAM,WAAW,kCAAkC;IACjD,KAAK,EAAE,cAAc,CAAC;IACtB,0BAA0B,EAAE,CAAC,KAAK,EAAE;QAClC,GAAG,EAAE,MAAM,CAAC;KACb,KAAK,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1D,sBAAsB,EAAE,CACtB,KAAK,EAAE,2BAA2B,KAC/B,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;CAC9C;AAED,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,EAAE,kCAAkC,GAAG,UAAU,CAmCjD"}
@@ -0,0 +1,47 @@
1
+ import { AUTH_USER, requireWorkspaceAccess } from '@shipfox/api-auth-context';
2
+ import { createGiteaConnectionBodySchema, createGiteaConnectionResponseSchema } from '@shipfox/api-integration-gitea-dto';
3
+ import { defineRoute } from '@shipfox/node-fastify';
4
+ import { handleGiteaConnect } from '#core/connect.js';
5
+ import { giteaConnectionExternalUrl } from '#core/connection-url.js';
6
+ import { toIntegrationConnectionDto } from '#presentation/dto/integrations.js';
7
+ import { giteaRouteErrorHandler } from './errors.js';
8
+ export function createGiteaConnectionRoutes({ gitea, getExistingGiteaConnection, connectGiteaConnection }) {
9
+ const createConnectionRoute = defineRoute({
10
+ method: 'POST',
11
+ path: '/connections',
12
+ auth: AUTH_USER,
13
+ description: 'Connect a Gitea organization to a workspace.',
14
+ schema: {
15
+ body: createGiteaConnectionBodySchema,
16
+ response: {
17
+ 200: createGiteaConnectionResponseSchema
18
+ }
19
+ },
20
+ errorHandler: giteaRouteErrorHandler,
21
+ handler: async (request)=>{
22
+ const { workspace_id: workspaceId, org } = request.body;
23
+ requireWorkspaceAccess({
24
+ request,
25
+ workspaceId
26
+ });
27
+ const connection = await handleGiteaConnect({
28
+ gitea,
29
+ workspaceId,
30
+ org,
31
+ getExistingGiteaConnection,
32
+ connectGiteaConnection
33
+ });
34
+ return toIntegrationConnectionDto(connection, {
35
+ externalUrl: giteaConnectionExternalUrl(connection.externalAccountId)
36
+ });
37
+ }
38
+ });
39
+ return {
40
+ prefix: '/integrations/gitea',
41
+ routes: [
42
+ createConnectionRoute
43
+ ]
44
+ };
45
+ }
46
+
47
+ //# sourceMappingURL=connections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/presentation/routes/connections.ts"],"sourcesContent":["import {AUTH_USER, requireWorkspaceAccess} from '@shipfox/api-auth-context';\nimport type {IntegrationConnection} from '@shipfox/api-integration-core-dto';\nimport {\n createGiteaConnectionBodySchema,\n createGiteaConnectionResponseSchema,\n} from '@shipfox/api-integration-gitea-dto';\nimport {defineRoute, type RouteGroup} from '@shipfox/node-fastify';\nimport type {GiteaApiClient} from '#api/client.js';\nimport {type ConnectGiteaConnectionInput, handleGiteaConnect} from '#core/connect.js';\nimport {giteaConnectionExternalUrl} from '#core/connection-url.js';\nimport {toIntegrationConnectionDto} from '#presentation/dto/integrations.js';\nimport {giteaRouteErrorHandler} from './errors.js';\n\nexport interface CreateGiteaConnectionRoutesOptions {\n gitea: GiteaApiClient;\n getExistingGiteaConnection: (input: {\n org: string;\n }) => Promise<IntegrationConnection<'gitea'> | undefined>;\n connectGiteaConnection: (\n input: ConnectGiteaConnectionInput,\n ) => Promise<IntegrationConnection<'gitea'>>;\n}\n\nexport function createGiteaConnectionRoutes({\n gitea,\n getExistingGiteaConnection,\n connectGiteaConnection,\n}: CreateGiteaConnectionRoutesOptions): RouteGroup {\n const createConnectionRoute = defineRoute({\n method: 'POST',\n path: '/connections',\n auth: AUTH_USER,\n description: 'Connect a Gitea organization to a workspace.',\n schema: {\n body: createGiteaConnectionBodySchema,\n response: {\n 200: createGiteaConnectionResponseSchema,\n },\n },\n errorHandler: giteaRouteErrorHandler,\n handler: async (request) => {\n const {workspace_id: workspaceId, org} = request.body;\n\n requireWorkspaceAccess({request, workspaceId});\n const connection = await handleGiteaConnect({\n gitea,\n workspaceId,\n org,\n getExistingGiteaConnection,\n connectGiteaConnection,\n });\n\n return toIntegrationConnectionDto(connection, {\n externalUrl: giteaConnectionExternalUrl(connection.externalAccountId),\n });\n },\n });\n\n return {\n prefix: '/integrations/gitea',\n routes: [createConnectionRoute],\n };\n}\n"],"names":["AUTH_USER","requireWorkspaceAccess","createGiteaConnectionBodySchema","createGiteaConnectionResponseSchema","defineRoute","handleGiteaConnect","giteaConnectionExternalUrl","toIntegrationConnectionDto","giteaRouteErrorHandler","createGiteaConnectionRoutes","gitea","getExistingGiteaConnection","connectGiteaConnection","createConnectionRoute","method","path","auth","description","schema","body","response","errorHandler","handler","request","workspace_id","workspaceId","org","connection","externalUrl","externalAccountId","prefix","routes"],"mappings":"AAAA,SAAQA,SAAS,EAAEC,sBAAsB,QAAO,4BAA4B;AAE5E,SACEC,+BAA+B,EAC/BC,mCAAmC,QAC9B,qCAAqC;AAC5C,SAAQC,WAAW,QAAwB,wBAAwB;AAEnE,SAA0CC,kBAAkB,QAAO,mBAAmB;AACtF,SAAQC,0BAA0B,QAAO,0BAA0B;AACnE,SAAQC,0BAA0B,QAAO,oCAAoC;AAC7E,SAAQC,sBAAsB,QAAO,cAAc;AAYnD,OAAO,SAASC,4BAA4B,EAC1CC,KAAK,EACLC,0BAA0B,EAC1BC,sBAAsB,EACa;IACnC,MAAMC,wBAAwBT,YAAY;QACxCU,QAAQ;QACRC,MAAM;QACNC,MAAMhB;QACNiB,aAAa;QACbC,QAAQ;YACNC,MAAMjB;YACNkB,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,cAAcb;QACdc,SAAS,OAAOC;YACd,MAAM,EAACC,cAAcC,WAAW,EAAEC,GAAG,EAAC,GAAGH,QAAQJ,IAAI;YAErDlB,uBAAuB;gBAACsB;gBAASE;YAAW;YAC5C,MAAME,aAAa,MAAMtB,mBAAmB;gBAC1CK;gBACAe;gBACAC;gBACAf;gBACAC;YACF;YAEA,OAAOL,2BAA2BoB,YAAY;gBAC5CC,aAAatB,2BAA2BqB,WAAWE,iBAAiB;YACtE;QACF;IACF;IAEA,OAAO;QACLC,QAAQ;QACRC,QAAQ;YAAClB;SAAsB;IACjC;AACF"}
@@ -0,0 +1,2 @@
1
+ export declare function giteaRouteErrorHandler(error: unknown): never;
2
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/errors.ts"],"names":[],"mappings":"AAiBA,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAiB5D"}