@opengeni/db 0.17.1 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-TLAC622R.js → chunk-YKWJ7QJ2.js} +11 -1
- package/dist/chunk-YKWJ7QJ2.js.map +1 -0
- package/dist/index.d.ts +70 -2
- package/dist/index.js +176 -6
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +87 -2
- package/dist/schema.js +1 -1
- package/drizzle/0141_social_connection_credentials.sql +8 -0
- package/drizzle/0151_slack_delivery_backoff.sql +134 -0
- package/package.json +3 -3
- package/src/index.ts +294 -6
- package/src/schema.ts +10 -0
- package/dist/chunk-TLAC622R.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -680,9 +680,28 @@ export type CreateSocialConnectionInput = {
|
|
|
680
680
|
status: SocialConnectionStatus;
|
|
681
681
|
scopes?: string[];
|
|
682
682
|
credentialRef?: string | null;
|
|
683
|
+
credentialEncrypted?: string | null;
|
|
683
684
|
tokenMetadata?: Record<string, unknown>;
|
|
684
685
|
metadata?: Record<string, unknown>;
|
|
685
686
|
};
|
|
687
|
+
export type UpsertSocialOAuthConnectionInput = {
|
|
688
|
+
accountId: string;
|
|
689
|
+
workspaceId: string;
|
|
690
|
+
provider: SocialProvider;
|
|
691
|
+
accountHandle: string;
|
|
692
|
+
accountName?: string | null;
|
|
693
|
+
externalAccountId?: string | null;
|
|
694
|
+
scopes: string[];
|
|
695
|
+
credentialEncrypted: string;
|
|
696
|
+
tokenMetadata?: Record<string, unknown>;
|
|
697
|
+
};
|
|
698
|
+
export type UpdateSocialConnectionCredentialInput = {
|
|
699
|
+
workspaceId: string;
|
|
700
|
+
connectionId: string;
|
|
701
|
+
credentialEncrypted?: string | null;
|
|
702
|
+
status?: SocialConnectionStatus;
|
|
703
|
+
tokenMetadata?: Record<string, unknown>;
|
|
704
|
+
};
|
|
686
705
|
export type CreateSocialPostInput = {
|
|
687
706
|
accountId: string;
|
|
688
707
|
workspaceId: string;
|
|
@@ -1173,6 +1192,7 @@ export type SlackInteractionInboxEntry = {
|
|
|
1173
1192
|
claimHolderId: string | null;
|
|
1174
1193
|
claimExpiresAt: Date | null;
|
|
1175
1194
|
attemptCount: number;
|
|
1195
|
+
retryAt: Date | null;
|
|
1176
1196
|
lastErrorCode: string | null;
|
|
1177
1197
|
processedAt: Date | null;
|
|
1178
1198
|
createdAt: Date;
|
|
@@ -1195,6 +1215,9 @@ export type SlackInteraction = {
|
|
|
1195
1215
|
lastDeliveredSessionEventSequence: number;
|
|
1196
1216
|
deliveryClaimHolderId: string | null;
|
|
1197
1217
|
deliveryClaimExpiresAt: Date | null;
|
|
1218
|
+
deliveryAttemptCount: number;
|
|
1219
|
+
deliveryRetryAt: Date | null;
|
|
1220
|
+
deliveryLastErrorCode: string | null;
|
|
1198
1221
|
ackSlackMessageTs: string | null;
|
|
1199
1222
|
progressCount: number;
|
|
1200
1223
|
terminalDeliveryState: "open" | "completed" | "failed" | "cancelled" | "blocked";
|
|
@@ -1215,7 +1238,7 @@ export declare function resolveSlackInstallationRoute(db: Database, slackTeamId:
|
|
|
1215
1238
|
export declare function saveSlackBotUserLink(db: Database, input: Omit<SlackBotUserLink, "id" | "createdAt" | "updatedAt">): Promise<SlackBotUserLink>;
|
|
1216
1239
|
export declare function getSlackBotUserLink(db: Database, workspaceId: string, connectionId: string, slackUserId: string): Promise<SlackBotUserLink | null>;
|
|
1217
1240
|
export declare function deleteSlackBotUserLink(db: Database, workspaceId: string, connectionId: string, slackUserId: string): Promise<boolean>;
|
|
1218
|
-
export declare function enqueueSlackInteractionInbox(db: Database, input: Omit<SlackInteractionInboxEntry, "id" | "status" | "claimHolderId" | "claimExpiresAt" | "attemptCount" | "lastErrorCode" | "processedAt" | "createdAt" | "updatedAt">): Promise<{
|
|
1241
|
+
export declare function enqueueSlackInteractionInbox(db: Database, input: Omit<SlackInteractionInboxEntry, "id" | "status" | "claimHolderId" | "claimExpiresAt" | "attemptCount" | "retryAt" | "lastErrorCode" | "processedAt" | "createdAt" | "updatedAt">): Promise<{
|
|
1219
1242
|
inserted: boolean;
|
|
1220
1243
|
entry: SlackInteractionInboxEntry;
|
|
1221
1244
|
}>;
|
|
@@ -1230,8 +1253,9 @@ export declare function releaseSlackInteractionInbox(db: Database, input: {
|
|
|
1230
1253
|
entry: Pick<SlackInteractionInboxEntry, "id" | "accountId" | "workspaceId">;
|
|
1231
1254
|
claimHolderId: string;
|
|
1232
1255
|
errorCode: string;
|
|
1256
|
+
retryAt: Date;
|
|
1233
1257
|
}): Promise<boolean>;
|
|
1234
|
-
export declare function getOrCreateSlackInteraction(db: Database, input: Omit<SlackInteraction, "id" | "sessionReservationId" | "sessionId" | "lastDeliveredSessionEventSequence" | "deliveryClaimHolderId" | "deliveryClaimExpiresAt" | "ackSlackMessageTs" | "progressCount" | "terminalDeliveryState" | "createdAt" | "updatedAt">): Promise<{
|
|
1258
|
+
export declare function getOrCreateSlackInteraction(db: Database, input: Omit<SlackInteraction, "id" | "sessionReservationId" | "sessionId" | "lastDeliveredSessionEventSequence" | "deliveryClaimHolderId" | "deliveryClaimExpiresAt" | "deliveryAttemptCount" | "deliveryRetryAt" | "deliveryLastErrorCode" | "ackSlackMessageTs" | "progressCount" | "terminalDeliveryState" | "createdAt" | "updatedAt">): Promise<{
|
|
1235
1259
|
created: boolean;
|
|
1236
1260
|
interaction: SlackInteraction;
|
|
1237
1261
|
}>;
|
|
@@ -1286,10 +1310,16 @@ export declare function advanceSlackInteractionDelivery(db: Database, input: Pic
|
|
|
1286
1310
|
export declare function releaseSlackInteractionDelivery(db: Database, input: Pick<SlackInteraction, "id" | "accountId" | "workspaceId"> & {
|
|
1287
1311
|
claimHolderId: string;
|
|
1288
1312
|
}): Promise<boolean>;
|
|
1313
|
+
export declare function deferSlackInteractionDelivery(db: Database, input: Pick<SlackInteraction, "id" | "accountId" | "workspaceId"> & {
|
|
1314
|
+
claimHolderId: string;
|
|
1315
|
+
retryAt: Date;
|
|
1316
|
+
errorCode: string;
|
|
1317
|
+
}): Promise<boolean>;
|
|
1289
1318
|
export declare function closeSlackInteractionDelivery(db: Database, input: Pick<SlackInteraction, "id" | "accountId" | "workspaceId"> & {
|
|
1290
1319
|
claimHolderId: string;
|
|
1291
1320
|
sequence: number;
|
|
1292
1321
|
state: Exclude<SlackInteraction["terminalDeliveryState"], "open">;
|
|
1322
|
+
errorCode?: string | null;
|
|
1293
1323
|
}): Promise<boolean>;
|
|
1294
1324
|
export declare class SlackBotLifecycleSuccessAuditError extends Error {
|
|
1295
1325
|
constructor();
|
|
@@ -1526,10 +1556,48 @@ export declare function correctWorkspaceMemory(db: Database, input: CorrectWorks
|
|
|
1526
1556
|
export declare function searchWorkspaceMemories(db: Database, workspaceId: string, input: WorkspaceMemorySearchInput, embedder?: MemoryEmbedder): Promise<WorkspaceMemorySearchResult[]>;
|
|
1527
1557
|
export declare function resolveWorkspaceMemoryBlock(db: Database, workspaceId: string): Promise<string | null>;
|
|
1528
1558
|
export declare function createSocialConnection(db: Database, input: CreateSocialConnectionInput): Promise<SocialConnection>;
|
|
1559
|
+
/**
|
|
1560
|
+
* OAuth-callback persistence: reconnecting the same provider account replaces
|
|
1561
|
+
* the stored credential and revives the connection instead of failing on the
|
|
1562
|
+
* (workspace, provider, handle) unique index.
|
|
1563
|
+
*/
|
|
1564
|
+
export declare function upsertSocialOAuthConnection(db: Database, input: UpsertSocialOAuthConnectionInput): Promise<SocialConnection>;
|
|
1565
|
+
/**
|
|
1566
|
+
* Host-side credential read for the social API client. Deliberately not part
|
|
1567
|
+
* of mapSocialConnection so the encrypted bundle never rides along on list or
|
|
1568
|
+
* MCP responses.
|
|
1569
|
+
*/
|
|
1570
|
+
export declare function loadSocialConnectionCredential(db: Database, workspaceId: string, connectionId: string): Promise<{
|
|
1571
|
+
connection: SocialConnection;
|
|
1572
|
+
credentialEncrypted: string | null;
|
|
1573
|
+
} | null>;
|
|
1574
|
+
export declare function updateSocialConnectionCredential(db: Database, input: UpdateSocialConnectionCredentialInput): Promise<SocialConnection | null>;
|
|
1529
1575
|
export declare function listSocialConnections(db: Database, workspaceId: string, limit?: number): Promise<SocialConnection[]>;
|
|
1530
1576
|
export declare function getSocialConnection(db: Database, workspaceId: string, connectionId: string): Promise<SocialConnection | null>;
|
|
1531
1577
|
export declare function requireSocialConnection(db: Database, workspaceId: string, connectionId: string): Promise<SocialConnection>;
|
|
1532
1578
|
export declare function createSocialPost(db: Database, input: CreateSocialPostInput): Promise<SocialPost>;
|
|
1579
|
+
/**
|
|
1580
|
+
* Idempotent bulk ingest for provider sync: rows already present under the
|
|
1581
|
+
* (workspace, connection, external post id) unique index are skipped, so a
|
|
1582
|
+
* scheduled re-sync never duplicates or fails.
|
|
1583
|
+
*/
|
|
1584
|
+
export declare function recordSyncedSocialPosts(db: Database, input: {
|
|
1585
|
+
accountId: string;
|
|
1586
|
+
workspaceId: string;
|
|
1587
|
+
connectionId: string;
|
|
1588
|
+
posts: Array<{
|
|
1589
|
+
externalPostId: string;
|
|
1590
|
+
url?: string | null;
|
|
1591
|
+
authorHandle?: string | null;
|
|
1592
|
+
text: string;
|
|
1593
|
+
publishedAt: Date;
|
|
1594
|
+
metrics?: Record<string, number>;
|
|
1595
|
+
raw?: Record<string, unknown>;
|
|
1596
|
+
}>;
|
|
1597
|
+
}): Promise<{
|
|
1598
|
+
inserted: number;
|
|
1599
|
+
skipped: number;
|
|
1600
|
+
}>;
|
|
1533
1601
|
export declare function listSocialPosts(db: Database, options: {
|
|
1534
1602
|
workspaceId: string;
|
|
1535
1603
|
connectionIds?: string[];
|
package/dist/index.js
CHANGED
|
@@ -90,7 +90,7 @@ import {
|
|
|
90
90
|
workspaceVariableSetVariables,
|
|
91
91
|
workspaceVariableSets,
|
|
92
92
|
workspaces
|
|
93
|
-
} from "./chunk-
|
|
93
|
+
} from "./chunk-YKWJ7QJ2.js";
|
|
94
94
|
import {
|
|
95
95
|
migrate,
|
|
96
96
|
runMigrations
|
|
@@ -164,6 +164,7 @@ import {
|
|
|
164
164
|
asc as asc5,
|
|
165
165
|
desc as desc5,
|
|
166
166
|
eq as eq10,
|
|
167
|
+
getTableColumns,
|
|
167
168
|
gt as gt2,
|
|
168
169
|
gte as gte2,
|
|
169
170
|
inArray as inArray5,
|
|
@@ -10114,6 +10115,20 @@ function connectionSubjectVisibility(subjectId) {
|
|
|
10114
10115
|
function connectionExactSubject(subjectId) {
|
|
10115
10116
|
return subjectId ? eq10(connections.subjectId, subjectId) : isNull3(connections.subjectId);
|
|
10116
10117
|
}
|
|
10118
|
+
function personalSlackCanonicalConnectionOrder() {
|
|
10119
|
+
return [
|
|
10120
|
+
sql7`case ${connections.status}
|
|
10121
|
+
when 'active' then 0
|
|
10122
|
+
when 'needs_reauth' then 1
|
|
10123
|
+
when 'error' then 2
|
|
10124
|
+
when 'revoked' then 3
|
|
10125
|
+
else 4
|
|
10126
|
+
end`,
|
|
10127
|
+
desc5(connections.updatedAt),
|
|
10128
|
+
desc5(connections.createdAt),
|
|
10129
|
+
desc5(connections.id)
|
|
10130
|
+
];
|
|
10131
|
+
}
|
|
10117
10132
|
async function withConnectionSubjectRls(db, workspaceId, subjectId, fn) {
|
|
10118
10133
|
return subjectId ? await withWorkspaceSubjectRls(db, workspaceId, subjectId, fn) : await withWorkspaceRls(db, workspaceId, fn);
|
|
10119
10134
|
}
|
|
@@ -10332,6 +10347,7 @@ async function settleSlackInteractionInbox(db, input) {
|
|
|
10332
10347
|
status: input.outcome,
|
|
10333
10348
|
claimHolderId: null,
|
|
10334
10349
|
claimExpiresAt: null,
|
|
10350
|
+
retryAt: null,
|
|
10335
10351
|
processedAt: sql7`now()`,
|
|
10336
10352
|
lastErrorCode: input.errorCode ?? null,
|
|
10337
10353
|
updatedAt: sql7`now()`
|
|
@@ -10351,6 +10367,7 @@ async function releaseSlackInteractionInbox(db, input) {
|
|
|
10351
10367
|
status: "pending",
|
|
10352
10368
|
claimHolderId: null,
|
|
10353
10369
|
claimExpiresAt: null,
|
|
10370
|
+
retryAt: input.retryAt,
|
|
10354
10371
|
lastErrorCode: input.errorCode,
|
|
10355
10372
|
updatedAt: sql7`now()`
|
|
10356
10373
|
}).where(
|
|
@@ -10561,7 +10578,13 @@ async function claimSlackInteractionDelivery(db, claimHolderId, claimLeaseMs) {
|
|
|
10561
10578
|
}
|
|
10562
10579
|
async function reopenSlackInteractionDelivery(db, input) {
|
|
10563
10580
|
return await withRlsContext(db, input, async (scopedDb) => {
|
|
10564
|
-
const rows = await scopedDb.update(slackInteractions).set({
|
|
10581
|
+
const rows = await scopedDb.update(slackInteractions).set({
|
|
10582
|
+
terminalDeliveryState: "open",
|
|
10583
|
+
deliveryAttemptCount: 0,
|
|
10584
|
+
deliveryRetryAt: null,
|
|
10585
|
+
deliveryLastErrorCode: null,
|
|
10586
|
+
updatedAt: sql7`now()`
|
|
10587
|
+
}).where(eq10(slackInteractions.id, input.id)).returning({ id: slackInteractions.id });
|
|
10565
10588
|
return rows.length === 1;
|
|
10566
10589
|
});
|
|
10567
10590
|
}
|
|
@@ -10570,6 +10593,9 @@ async function advanceSlackInteractionDelivery(db, input) {
|
|
|
10570
10593
|
const rows = await scopedDb.update(slackInteractions).set({
|
|
10571
10594
|
lastDeliveredSessionEventSequence: input.sequence,
|
|
10572
10595
|
...input.ackSlackMessageTs !== void 0 ? { ackSlackMessageTs: input.ackSlackMessageTs } : {},
|
|
10596
|
+
deliveryAttemptCount: 0,
|
|
10597
|
+
deliveryRetryAt: null,
|
|
10598
|
+
deliveryLastErrorCode: null,
|
|
10573
10599
|
updatedAt: sql7`now()`
|
|
10574
10600
|
}).where(
|
|
10575
10601
|
and10(
|
|
@@ -10596,6 +10622,23 @@ async function releaseSlackInteractionDelivery(db, input) {
|
|
|
10596
10622
|
return rows.length === 1;
|
|
10597
10623
|
});
|
|
10598
10624
|
}
|
|
10625
|
+
async function deferSlackInteractionDelivery(db, input) {
|
|
10626
|
+
return await withRlsContext(db, input, async (scopedDb) => {
|
|
10627
|
+
const rows = await scopedDb.update(slackInteractions).set({
|
|
10628
|
+
deliveryClaimHolderId: null,
|
|
10629
|
+
deliveryClaimExpiresAt: null,
|
|
10630
|
+
deliveryRetryAt: input.retryAt,
|
|
10631
|
+
deliveryLastErrorCode: input.errorCode.slice(0, 128),
|
|
10632
|
+
updatedAt: sql7`now()`
|
|
10633
|
+
}).where(
|
|
10634
|
+
and10(
|
|
10635
|
+
eq10(slackInteractions.id, input.id),
|
|
10636
|
+
eq10(slackInteractions.deliveryClaimHolderId, input.claimHolderId)
|
|
10637
|
+
)
|
|
10638
|
+
).returning({ id: slackInteractions.id });
|
|
10639
|
+
return rows.length === 1;
|
|
10640
|
+
});
|
|
10641
|
+
}
|
|
10599
10642
|
async function closeSlackInteractionDelivery(db, input) {
|
|
10600
10643
|
return await withRlsContext(db, input, async (scopedDb) => {
|
|
10601
10644
|
const rows = await scopedDb.update(slackInteractions).set({
|
|
@@ -10603,6 +10646,8 @@ async function closeSlackInteractionDelivery(db, input) {
|
|
|
10603
10646
|
terminalDeliveryState: input.state,
|
|
10604
10647
|
deliveryClaimHolderId: null,
|
|
10605
10648
|
deliveryClaimExpiresAt: null,
|
|
10649
|
+
deliveryRetryAt: null,
|
|
10650
|
+
deliveryLastErrorCode: input.errorCode?.slice(0, 128) ?? null,
|
|
10606
10651
|
updatedAt: sql7`now()`
|
|
10607
10652
|
}).where(
|
|
10608
10653
|
and10(
|
|
@@ -10635,6 +10680,7 @@ function mapSlackInteractionInbox(row) {
|
|
|
10635
10680
|
claimHolderId: slackRowNullableString(row, "claimHolderId", "claim_holder_id"),
|
|
10636
10681
|
claimExpiresAt: slackRowNullableDate(row, "claimExpiresAt", "claim_expires_at"),
|
|
10637
10682
|
attemptCount: slackRowNumber(row, "attemptCount", "attempt_count"),
|
|
10683
|
+
retryAt: slackRowNullableDate(row, "retryAt", "retry_at"),
|
|
10638
10684
|
lastErrorCode: slackRowNullableString(row, "lastErrorCode", "last_error_code"),
|
|
10639
10685
|
processedAt: slackRowNullableDate(row, "processedAt", "processed_at"),
|
|
10640
10686
|
createdAt: slackRowDate(row, "createdAt", "created_at"),
|
|
@@ -10675,6 +10721,13 @@ function mapSlackInteraction(row) {
|
|
|
10675
10721
|
"deliveryClaimExpiresAt",
|
|
10676
10722
|
"delivery_claim_expires_at"
|
|
10677
10723
|
),
|
|
10724
|
+
deliveryAttemptCount: slackRowNumber(row, "deliveryAttemptCount", "delivery_attempt_count"),
|
|
10725
|
+
deliveryRetryAt: slackRowNullableDate(row, "deliveryRetryAt", "delivery_retry_at"),
|
|
10726
|
+
deliveryLastErrorCode: slackRowNullableString(
|
|
10727
|
+
row,
|
|
10728
|
+
"deliveryLastErrorCode",
|
|
10729
|
+
"delivery_last_error_code"
|
|
10730
|
+
),
|
|
10678
10731
|
ackSlackMessageTs: slackRowNullableString(row, "ackSlackMessageTs", "ack_slack_message_ts"),
|
|
10679
10732
|
progressCount: slackRowNumber(row, "progressCount", "progress_count"),
|
|
10680
10733
|
terminalDeliveryState: slackRowString(
|
|
@@ -11257,9 +11310,12 @@ async function loadConnectionCredentialForBroker(db, settings, input) {
|
|
|
11257
11310
|
input.workspaceId,
|
|
11258
11311
|
input.allowSubjectOwned ? input.subjectId : null,
|
|
11259
11312
|
async (scopedDb) => {
|
|
11313
|
+
const personalSlackSubjectLookup = !input.connectionId && input.allowSubjectOwned === true && input.providerDomain === "slack.com" && input.kind === "oauth2";
|
|
11260
11314
|
const [row] = await scopedDb.select().from(connections).where(and10(...conditions)).orderBy(
|
|
11261
|
-
|
|
11262
|
-
|
|
11315
|
+
...personalSlackSubjectLookup ? personalSlackCanonicalConnectionOrder() : [
|
|
11316
|
+
desc5(sql7`(${connections.status} = 'active')`),
|
|
11317
|
+
desc5(connections.updatedAt)
|
|
11318
|
+
]
|
|
11263
11319
|
).limit(1);
|
|
11264
11320
|
if (!row) {
|
|
11265
11321
|
return null;
|
|
@@ -12312,6 +12368,7 @@ async function createSocialConnection(db, input) {
|
|
|
12312
12368
|
status: input.status,
|
|
12313
12369
|
scopes: input.scopes ?? [],
|
|
12314
12370
|
credentialRef: input.credentialRef ?? null,
|
|
12371
|
+
credentialEncrypted: input.credentialEncrypted ?? null,
|
|
12315
12372
|
tokenMetadata: input.tokenMetadata ?? {},
|
|
12316
12373
|
metadata: input.metadata ?? {}
|
|
12317
12374
|
}).returning();
|
|
@@ -12322,15 +12379,85 @@ async function createSocialConnection(db, input) {
|
|
|
12322
12379
|
}
|
|
12323
12380
|
);
|
|
12324
12381
|
}
|
|
12382
|
+
async function upsertSocialOAuthConnection(db, input) {
|
|
12383
|
+
return await withRlsContext(
|
|
12384
|
+
db,
|
|
12385
|
+
{ accountId: input.accountId, workspaceId: input.workspaceId },
|
|
12386
|
+
async (scopedDb) => {
|
|
12387
|
+
const [row] = await scopedDb.insert(socialConnections).values({
|
|
12388
|
+
accountId: input.accountId,
|
|
12389
|
+
workspaceId: input.workspaceId,
|
|
12390
|
+
provider: input.provider,
|
|
12391
|
+
accountHandle: input.accountHandle,
|
|
12392
|
+
accountName: input.accountName ?? null,
|
|
12393
|
+
externalAccountId: input.externalAccountId ?? null,
|
|
12394
|
+
status: "connected",
|
|
12395
|
+
scopes: input.scopes,
|
|
12396
|
+
credentialEncrypted: input.credentialEncrypted,
|
|
12397
|
+
tokenMetadata: input.tokenMetadata ?? {}
|
|
12398
|
+
}).onConflictDoUpdate({
|
|
12399
|
+
target: [
|
|
12400
|
+
socialConnections.workspaceId,
|
|
12401
|
+
socialConnections.provider,
|
|
12402
|
+
socialConnections.accountHandle
|
|
12403
|
+
],
|
|
12404
|
+
set: {
|
|
12405
|
+
accountName: input.accountName ?? null,
|
|
12406
|
+
externalAccountId: input.externalAccountId ?? null,
|
|
12407
|
+
status: "connected",
|
|
12408
|
+
scopes: input.scopes,
|
|
12409
|
+
credentialEncrypted: input.credentialEncrypted,
|
|
12410
|
+
tokenMetadata: input.tokenMetadata ?? {},
|
|
12411
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
12412
|
+
}
|
|
12413
|
+
}).returning();
|
|
12414
|
+
if (!row) {
|
|
12415
|
+
throw new Error("Failed to upsert social connection");
|
|
12416
|
+
}
|
|
12417
|
+
return mapSocialConnection(row);
|
|
12418
|
+
}
|
|
12419
|
+
);
|
|
12420
|
+
}
|
|
12421
|
+
async function loadSocialConnectionCredential(db, workspaceId, connectionId) {
|
|
12422
|
+
return await withWorkspaceRls(db, workspaceId, async (scopedDb) => {
|
|
12423
|
+
const [row] = await scopedDb.select().from(socialConnections).where(
|
|
12424
|
+
and10(
|
|
12425
|
+
eq10(socialConnections.workspaceId, workspaceId),
|
|
12426
|
+
eq10(socialConnections.id, connectionId)
|
|
12427
|
+
)
|
|
12428
|
+
).limit(1);
|
|
12429
|
+
if (!row) {
|
|
12430
|
+
return null;
|
|
12431
|
+
}
|
|
12432
|
+
return { connection: mapSocialConnection(row), credentialEncrypted: row.credentialEncrypted };
|
|
12433
|
+
});
|
|
12434
|
+
}
|
|
12435
|
+
async function updateSocialConnectionCredential(db, input) {
|
|
12436
|
+
return await withWorkspaceRls(db, input.workspaceId, async (scopedDb) => {
|
|
12437
|
+
const [row] = await scopedDb.update(socialConnections).set({
|
|
12438
|
+
...input.credentialEncrypted !== void 0 ? { credentialEncrypted: input.credentialEncrypted } : {},
|
|
12439
|
+
...input.status !== void 0 ? { status: input.status } : {},
|
|
12440
|
+
...input.tokenMetadata !== void 0 ? { tokenMetadata: input.tokenMetadata } : {},
|
|
12441
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
12442
|
+
}).where(
|
|
12443
|
+
and10(
|
|
12444
|
+
eq10(socialConnections.workspaceId, input.workspaceId),
|
|
12445
|
+
eq10(socialConnections.id, input.connectionId)
|
|
12446
|
+
)
|
|
12447
|
+
).returning();
|
|
12448
|
+
return row ? mapSocialConnection(row) : null;
|
|
12449
|
+
});
|
|
12450
|
+
}
|
|
12451
|
+
var { credentialEncrypted: _socialCredentialColumn, ...socialConnectionPublicColumns } = getTableColumns(socialConnections);
|
|
12325
12452
|
async function listSocialConnections(db, workspaceId, limit = 100) {
|
|
12326
12453
|
return await withWorkspaceRls(db, workspaceId, async (scopedDb) => {
|
|
12327
|
-
const rows = await scopedDb.select().from(socialConnections).where(eq10(socialConnections.workspaceId, workspaceId)).orderBy(desc5(socialConnections.createdAt)).limit(limit);
|
|
12454
|
+
const rows = await scopedDb.select(socialConnectionPublicColumns).from(socialConnections).where(eq10(socialConnections.workspaceId, workspaceId)).orderBy(desc5(socialConnections.createdAt)).limit(limit);
|
|
12328
12455
|
return rows.map(mapSocialConnection);
|
|
12329
12456
|
});
|
|
12330
12457
|
}
|
|
12331
12458
|
async function getSocialConnection(db, workspaceId, connectionId) {
|
|
12332
12459
|
return await withWorkspaceRls(db, workspaceId, async (scopedDb) => {
|
|
12333
|
-
const [row] = await scopedDb.select().from(socialConnections).where(
|
|
12460
|
+
const [row] = await scopedDb.select(socialConnectionPublicColumns).from(socialConnections).where(
|
|
12334
12461
|
and10(
|
|
12335
12462
|
eq10(socialConnections.workspaceId, workspaceId),
|
|
12336
12463
|
eq10(socialConnections.id, connectionId)
|
|
@@ -12376,6 +12503,44 @@ async function createSocialPost(db, input) {
|
|
|
12376
12503
|
}
|
|
12377
12504
|
);
|
|
12378
12505
|
}
|
|
12506
|
+
async function recordSyncedSocialPosts(db, input) {
|
|
12507
|
+
if (input.posts.length === 0) {
|
|
12508
|
+
return { inserted: 0, skipped: 0 };
|
|
12509
|
+
}
|
|
12510
|
+
return await withRlsContext(
|
|
12511
|
+
db,
|
|
12512
|
+
{ accountId: input.accountId, workspaceId: input.workspaceId },
|
|
12513
|
+
async (scopedDb) => {
|
|
12514
|
+
const connection = await requireSocialConnection(
|
|
12515
|
+
scopedDb,
|
|
12516
|
+
input.workspaceId,
|
|
12517
|
+
input.connectionId
|
|
12518
|
+
);
|
|
12519
|
+
const rows = await scopedDb.insert(socialPosts).values(
|
|
12520
|
+
input.posts.map((post) => ({
|
|
12521
|
+
accountId: input.accountId,
|
|
12522
|
+
workspaceId: input.workspaceId,
|
|
12523
|
+
connectionId: input.connectionId,
|
|
12524
|
+
provider: connection.provider,
|
|
12525
|
+
externalPostId: post.externalPostId,
|
|
12526
|
+
url: post.url ?? null,
|
|
12527
|
+
authorHandle: post.authorHandle ?? connection.accountHandle,
|
|
12528
|
+
text: post.text,
|
|
12529
|
+
publishedAt: post.publishedAt,
|
|
12530
|
+
metrics: post.metrics ?? {},
|
|
12531
|
+
raw: post.raw ?? {}
|
|
12532
|
+
}))
|
|
12533
|
+
).onConflictDoNothing({
|
|
12534
|
+
target: [
|
|
12535
|
+
socialPosts.workspaceId,
|
|
12536
|
+
socialPosts.connectionId,
|
|
12537
|
+
socialPosts.externalPostId
|
|
12538
|
+
]
|
|
12539
|
+
}).returning({ id: socialPosts.id });
|
|
12540
|
+
return { inserted: rows.length, skipped: input.posts.length - rows.length };
|
|
12541
|
+
}
|
|
12542
|
+
);
|
|
12543
|
+
}
|
|
12379
12544
|
async function listSocialPosts(db, options) {
|
|
12380
12545
|
const conditions = [eq10(socialPosts.workspaceId, options.workspaceId)];
|
|
12381
12546
|
if (options.connectionIds?.length) {
|
|
@@ -33261,6 +33426,7 @@ export {
|
|
|
33261
33426
|
decryptEnvironmentValue as decryptVariableSetValue,
|
|
33262
33427
|
decryptedCapabilityHeaders,
|
|
33263
33428
|
deferRetainedProcessReconciliation,
|
|
33429
|
+
deferSlackInteractionDelivery,
|
|
33264
33430
|
deleteGitHubInstallationBinding,
|
|
33265
33431
|
deleteRecording,
|
|
33266
33432
|
deleteRig,
|
|
@@ -33501,6 +33667,7 @@ export {
|
|
|
33501
33667
|
loadCodexCredentialForRun,
|
|
33502
33668
|
loadConnectionCredentialForBroker,
|
|
33503
33669
|
loadIntegrationOAuthClient,
|
|
33670
|
+
loadSocialConnectionCredential,
|
|
33504
33671
|
loadVariableSetForRun,
|
|
33505
33672
|
loadWorkspaceEnvironmentForRun,
|
|
33506
33673
|
lockSessionEventWriteRows,
|
|
@@ -33577,6 +33744,7 @@ export {
|
|
|
33577
33744
|
recordStartedContextCompaction,
|
|
33578
33745
|
recordStreamAcknowledgment,
|
|
33579
33746
|
recordStripeWebhookEvent,
|
|
33747
|
+
recordSyncedSocialPosts,
|
|
33580
33748
|
recordUsageEvent,
|
|
33581
33749
|
recordWarmingSandboxCreated,
|
|
33582
33750
|
recoverSessionDispatch,
|
|
@@ -33718,6 +33886,7 @@ export {
|
|
|
33718
33886
|
updateSessionMcpApprovalPolicy,
|
|
33719
33887
|
updateSessionMcpServerCredentials,
|
|
33720
33888
|
updateSessionTitle,
|
|
33889
|
+
updateSocialConnectionCredential,
|
|
33721
33890
|
updateVariableSet,
|
|
33722
33891
|
updateWorkspace,
|
|
33723
33892
|
updateWorkspaceEnvironment,
|
|
@@ -33731,6 +33900,7 @@ export {
|
|
|
33731
33900
|
upsertSandboxSessionEnvelope,
|
|
33732
33901
|
upsertSessionGoal,
|
|
33733
33902
|
upsertSessionGoalWithEvent,
|
|
33903
|
+
upsertSocialOAuthConnection,
|
|
33734
33904
|
upsertWorkspaceModelPolicy,
|
|
33735
33905
|
validateHumanInputResponse,
|
|
33736
33906
|
verifyDirectWorkspaceMutationSettlement,
|