@keystrokehq/platform 0.0.136 → 0.0.137

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.
@@ -1,6 +1,7 @@
1
1
  import { n as pingProjectTarget } from "./dist-CkPv4pkS.mjs";
2
2
  import { $t as mapProjectDeployment, A as CreateOrganizationRequestSchema, At as UpdateOrganizationMemberResponseSchema, C as AgentSummaryDetailResponseSchema, Ct as StoredProjectSourceManifestSchema, G as ListOrganizationsResponseSchema, Gt as WorkflowSummarySchema, H as InviteOrganizationMembersResponseSchema, J as ListProjectMetricsResponseSchema, Jt as listenPortFromPublicUrl, K as ListProjectDeploymentsResponseSchema, L as DeclineOrganizationInvitationResponseSchema, Lt as UserAvatarPatchSchema, M as CreateProjectArtifactResponseSchema, Mt as UpdateProjectRequestSchema, N as CreateProjectRequestSchema, Nt as UploadProjectSourceManifestRequestSchema, O as CompleteProjectArtifactResponseSchema, P as CreateProjectResponseSchema, Pt as UploadProjectSourceResponseSchema, Q as OrganizationSidebarBrandingSchema, Qt as mapProjectArtifact, R as ErrorResponseSchema, Rt as UserAvatarSchema, St as SlugAvailabilityResponseSchema, T as AgentSummarySchema, U as ListOrganizationInvitationsResponseSchema, Ut as WorkflowSummaryDetailResponseSchema, V as InviteOrganizationMembersRequestSchema, W as ListOrganizationMembersResponseSchema, Wt as WorkflowSummaryListResponseSchema, Xt as mapOrganizationMember, Y as ListProjectsResponseSchema, Yt as mapOrganizationInvitation, Z as OrganizationSidebarBrandingPatchSchema, Zt as mapProject, _ as ACTIVE_ORG_HEADER, _t as RecentResourceSchema, a as isKeystrokeAssetsAvatarPublicUrl, at as PresignProjectSourceResponseSchema, bt as SkillSummarySchema, c as isUserAvatarStorageKey, ct as ProjectReachabilityResponseSchema, dt as ProjectSlugAvailabilityResponseSchema, en as mapUserOrganization, et as PLATFORM_RESOURCE_UNSUPPORTED_TEXT, f as orgLogoStorageKey, fn as validationErrorResponse, g as userAvatarStorageKey, gt as RecentResourceListResponseSchema, h as publicKeystrokeAssetsObjectUrl, i as ensureKeystrokeAssetsBucket, in as organizationSlugErrorCodeFromMessage, it as PresignProjectSourceRequestSchema, j as CreateOrganizationResponseSchema, jt as UpdateOrganizationRequestSchema, kt as UpdateOrganizationMemberRequestSchema, l as keystrokeAssetsAvatarKeyFromPublicUrl, ln as projectFileId, lt as ProjectResponseSchema, m as projectSourceBlobKey, nt as PresignOrgLogoRequestSchema, o as isKeystrokeAssetsOrgLogoPublicUrl, on as parseStoredRouteManifest, ot as PresignUserAvatarRequestSchema, p as projectArtifactKey, pt as PromptInputSchema, q as ListProjectFilesResponseSchema, rn as organizationInvitationAcceptPath, rt as PresignOrgLogoResponseSchema, s as isOrgLogoStorageKey, st as PresignUserAvatarResponseSchema, t as createAssetsStorageClient, tt as PROJECT_SLUG_TAKEN_MESSAGE, u as keystrokeAssetsOrgLogoKeyFromPublicUrl, ut as ProjectSlugAvailabilityQuerySchema, v as AcceptOrganizationInvitationResponseSchema, vt as SkillSummaryDetailResponseSchema, w as AgentSummaryListResponseSchema, xt as SlugAvailabilityQuerySchema, y as ActiveOrganizationResponseSchema, yt as SkillSummaryListResponseSchema } from "./dist-DQNiucMJ.mjs";
3
3
  import { $n as updateProjectArtifactSourceManifest, $t as ProjectSlugTakenError, A as webhookRouteFromEndpoint, An as runWithWorkspaceContext, Ar as authDeviceCodes, B as verifySlackSignature, Bn as selectProjectDeployments, Cn as organizationRowToSidebarBranding, Cr as selectAgentLastRunAtByIds, Ct as createOAuthTokenAdapterFromBackend, D as syncRegistryFromStoredManifest, Dn as resolveOrgDatabaseUrl, Dr as syncSkillRegistry, E as seedOAuthAppsFromEnvForOrganization, En as resolveNewOrganizationIdentity, Er as selectWorkflowLastRunAtBySlugs, F as createSlackGatewayIngress, Fn as selectOrganizationMembers, Fr as users, Gn as selectUserOrganizationMembership, Hn as selectProjectsByOrganizationId, I as isSlackMentionEventPayload, In as selectPendingInvitationsForUser, Jn as updateOrganizationName, Jt as OrganizationInvitationExpiredError, Kn as selectUserOrganizations, L as postSlackChannelMessage, Ln as selectProjectArtifactById, M as workflowRunsListHandler, Mn as selectActiveArtifactSourceManifestForProject, Mr as authSessions, N as buildSlackGatewaySetupUrl, Nn as selectLastDeploymentAtByProject, Nr as authVerifications, O as triggerRunDetailHandler, On as resolveProjectRuntimeDatabase, Or as touchResourceActivity, P as channelIdFromSlackEventPayload, Pn as selectOrganizationById, Pr as getDatabaseHandle, Qn as updateProjectArtifactManifest, Qt as OrganizationSlugTakenError, R as slackSignatureHeaders, Rn as selectProjectArtifactForProject, S as mountWorkflowCredentialRoutes, Sn as normalizeUserEmail, Sr as selectAgentBySlug, St as createLocalCredentialBackend, T as seedOAuthAppsFromEnvForAllOrganizations, Tn as removeOrganizationMember, Tr as selectProjectResourceCounts, Un as selectUserById, Vn as selectProjectForOrganization, Wn as selectUserByNormalizedEmail, Xn as updateOrganizationSlug, Xt as OrganizationInvitationNotFoundError, Yn as updateOrganizationSidebarBranding, Yt as OrganizationInvitationForbiddenError, Zn as updateProjectActive, Zt as OrganizationMemberNotFoundError, _n as insertProjectArtifact, _r as selectActiveSkillById, a as createAgentsListHandler, an as createOrgStorageClient, ar as getActiveOrgGatewayAttachmentByTeamAndChannel, at as configureSharedScheduler, b as mountCredentialInstanceRoutes, bn as listOAuthInstallationsByAppSlugAndExternalId, br as selectActiveWorkflowBySlug, c as createTriggerGetHandler, cn as declineInvitation, cr as listActiveAgents, ct as resolveSchedulerPluginFromEnv, d as enqueueWebhookIngress, dn as ensureProjectPgBossGrants, dr as listRecentResourceActivity, dt as prepareAgentSession, en as acceptInvitation, er as updateProjectFailed, f as enqueueWorkflowRunByKey, fn as ensureWebhookApiKeyForRoute, fr as runWithProjectDatabase, gn as initDatabase, gr as selectActiveAgentsByIds, h as findWorkflowManifestEntry, hn as getOAuthAppSigningSecretBySlugGlobal, hr as selectActiveAgentById, i as connectProvidersFromManifest, in as createOrgContainerPresign, ir as createPgConnection, j as workflowRunDetailHandler, jn as selectActiveArtifactManifestForProject, jr as authJwks, k as triggerRunsListHandler, kn as runWithOrganizationScope, kr as authAccounts, l as createTriggersListHandler, ln as deleteProjectForOrganization, lr as listActiveSkills, lt as startPgBoss, m as fetchStoredRouteManifest, mn as getGlobalOAuthAccessTokenByAppSlugAndExternalId, mr as runWithTenantScope, n as agentSessionsListHandler, nn as checkProjectSlugAvailability, nr as updateUserById, o as createCredentialMaterializeHandler, on as createOrganizationForUser, or as getOrCreateGatewayThreadSession, ot as createScheduler, p as extractWebhookRoutesFromManifest, pn as ensureWebhookApiKeys, pr as runWithProjectScope, qn as updateOrganizationMemberRole, qt as CannotModifyOwnerError, r as buildWebhookUrl, rn as completeProjectArtifact, rr as verifyWebhookApiKeyForRoute, s as createGatewayAttachmentHandlers, sn as createProjectForOrganization, sr as getProjectScopeId, st as getPgBoss, t as agentSessionDetailHandler, tn as checkOrganizationSlugAvailability, tr as updateProjectForOrganization, u as enqueueAgentPrompt, un as encryptCredentialPayload, ur as listActiveWorkflows, ut as matchWebhookPayload, v as listKnownIntegrationKeys, vn as inviteOrganizationMembers, vr as selectActiveSkillsByIds, w as resumeWorkflowHook, wn as promoteProjectArtifact, wr as selectEphemeralTriggerAttachments, wt as createOAuthTokenRefreshRegistry, x as mountProjectIntegrations, xn as listWebhookApiKeysForProject, xr as selectActiveWorkflowsByIds, y as loadWebhookAttachmentSchemasForRoute, yn as isOrganizationStorageBucketInUse, yr as selectActiveWorkflowById, z as teamIdFromSlackEventPayload, zn as selectProjectById } from "./dist-Bwp-8Ffx.mjs";
4
+ import * as z$1 from "zod";
4
5
  import { ZodError, z } from "zod";
5
6
  import { serve } from "@hono/node-server";
6
7
  import { drizzleAdapter } from "@better-auth/drizzle-adapter";
@@ -8,9 +9,10 @@ import { betterAuth } from "better-auth";
8
9
  import { bearer } from "better-auth/plugins/bearer";
9
10
  import { deviceAuthorization } from "better-auth/plugins/device-authorization";
10
11
  import { jwt, lastLoginMethod } from "better-auth/plugins";
12
+ import { AsyncLocalStorage } from "node:async_hooks";
13
+ import { APIError, createAuthEndpoint, getSessionFromCtx } from "better-auth/api";
11
14
  import { magicLink } from "better-auth/plugins/magic-link";
12
15
  import { Resend } from "resend";
13
- import { AsyncLocalStorage } from "node:async_hooks";
14
16
  import { Hono } from "hono";
15
17
  import { cors } from "hono/cors";
16
18
  //#region ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/lib/buffer_utils.js
@@ -1295,6 +1297,78 @@ function createAuthDatabaseAdapter() {
1295
1297
  }
1296
1298
  //#endregion
1297
1299
  //#region ../../packages/auth/dist/index.mjs
1300
+ function normalizeUserCode(userCode) {
1301
+ return userCode.replace(/-/g, "");
1302
+ }
1303
+ function createCliDeviceOrganizationPlugin() {
1304
+ return {
1305
+ id: "cli-device-organization",
1306
+ endpoints: { attachOrganization: createAuthEndpoint("/device/attach-organization", {
1307
+ method: "POST",
1308
+ body: z$1.object({
1309
+ userCode: z$1.string(),
1310
+ organizationId: z$1.string()
1311
+ }),
1312
+ requireHeaders: true
1313
+ }, async (ctx) => {
1314
+ const session = await getSessionFromCtx(ctx);
1315
+ if (!session) throw new APIError("UNAUTHORIZED", {
1316
+ error: "unauthorized",
1317
+ error_description: "Authentication required"
1318
+ });
1319
+ const organizationId = ctx.body.organizationId.trim();
1320
+ if (!organizationId) throw new APIError("BAD_REQUEST", {
1321
+ error: "invalid_request",
1322
+ error_description: "Organization id is required"
1323
+ });
1324
+ if (!await selectUserOrganizationMembership(session.user.id, organizationId)) throw new APIError("FORBIDDEN", {
1325
+ error: "access_denied",
1326
+ error_description: "You are not a member of this organization"
1327
+ });
1328
+ const cleanUserCode = normalizeUserCode(ctx.body.userCode);
1329
+ const deviceCodeRecord = await ctx.context.adapter.findOne({
1330
+ model: "deviceCode",
1331
+ where: [{
1332
+ field: "userCode",
1333
+ value: cleanUserCode
1334
+ }]
1335
+ });
1336
+ if (!deviceCodeRecord) throw new APIError("BAD_REQUEST", {
1337
+ error: "invalid_request",
1338
+ error_description: "Invalid device user code"
1339
+ });
1340
+ if (deviceCodeRecord.expiresAt < /* @__PURE__ */ new Date()) throw new APIError("BAD_REQUEST", {
1341
+ error: "expired_token",
1342
+ error_description: "Device user code has expired"
1343
+ });
1344
+ if (deviceCodeRecord.status !== "pending") throw new APIError("BAD_REQUEST", {
1345
+ error: "invalid_request",
1346
+ error_description: "Device authorization has already been processed"
1347
+ });
1348
+ if (deviceCodeRecord.clientId && deviceCodeRecord.clientId !== "keystroke-cli") throw new APIError("BAD_REQUEST", {
1349
+ error: "invalid_request",
1350
+ error_description: "Invalid device client"
1351
+ });
1352
+ if (!deviceCodeRecord.userId) throw new APIError("BAD_REQUEST", {
1353
+ error: "invalid_request",
1354
+ error_description: "Device authorization has not been claimed yet"
1355
+ });
1356
+ if (deviceCodeRecord.userId !== session.user.id) throw new APIError("FORBIDDEN", {
1357
+ error: "access_denied",
1358
+ error_description: "You are not authorized to update this device authorization"
1359
+ });
1360
+ await ctx.context.adapter.update({
1361
+ model: "deviceCode",
1362
+ where: [{
1363
+ field: "id",
1364
+ value: deviceCodeRecord.id
1365
+ }],
1366
+ update: { scope: organizationId }
1367
+ });
1368
+ return ctx.json({ success: true });
1369
+ }) }
1370
+ };
1371
+ }
1298
1372
  function envValue$1(name) {
1299
1373
  return process.env[name]?.trim() || void 0;
1300
1374
  }
@@ -1430,6 +1504,7 @@ function createAuthInstance(options) {
1430
1504
  interval: "1s",
1431
1505
  schema: {}
1432
1506
  }),
1507
+ createCliDeviceOrganizationPlugin(),
1433
1508
  bearer(),
1434
1509
  jwt({ jwt: { definePayload: ({ user }) => ({
1435
1510
  id: user.id,
@@ -3663,4 +3738,4 @@ async function startPlatformServer(platformConfig, hooks = {}) {
3663
3738
  //#endregion
3664
3739
  export { startPlatformServer as t };
3665
3740
 
3666
- //# sourceMappingURL=start-pFr_c6SD.mjs.map
3741
+ //# sourceMappingURL=start-yehsjk2a.mjs.map