@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.
- package/dist/run.cjs +1 -1
- package/dist/run.mjs +1 -1
- package/dist/{start-AL_o2HoK.cjs → start-BuRTgJlJ.cjs} +77 -2
- package/dist/start-BuRTgJlJ.cjs.map +1 -0
- package/dist/{start-pFr_c6SD.mjs → start-yehsjk2a.mjs} +77 -2
- package/dist/start-yehsjk2a.mjs.map +1 -0
- package/dist/start.cjs +1 -1
- package/dist/start.d.cts +14 -0
- package/dist/start.d.mts +14 -0
- package/dist/start.mjs +1 -1
- package/package.json +1 -1
- package/dist/start-AL_o2HoK.cjs.map +0 -1
- package/dist/start-pFr_c6SD.mjs.map +0 -1
package/dist/run.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_config = require("./config.cjs");
|
|
2
|
-
const require_start = require("./start-
|
|
2
|
+
const require_start = require("./start-BuRTgJlJ.cjs");
|
|
3
3
|
//#region src/run.ts
|
|
4
4
|
async function main() {
|
|
5
5
|
await require_start.startPlatformServer(require_config.definePlatformConfig());
|
package/dist/run.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { definePlatformConfig } from "./config.mjs";
|
|
2
|
-
import { t as startPlatformServer } from "./start-
|
|
2
|
+
import { t as startPlatformServer } from "./start-yehsjk2a.mjs";
|
|
3
3
|
//#region src/run.ts
|
|
4
4
|
async function main() {
|
|
5
5
|
await startPlatformServer(definePlatformConfig());
|
|
@@ -2,15 +2,17 @@ const require_dist = require("./dist-CT6EPgxh.cjs");
|
|
|
2
2
|
const require_dist$1 = require("./dist-CfpZlJ5K.cjs");
|
|
3
3
|
const require_dist$2 = require("./dist-CVHjeM1T.cjs");
|
|
4
4
|
let zod = require("zod");
|
|
5
|
+
zod = require_dist.__toESM(zod, 1);
|
|
5
6
|
let _hono_node_server = require("@hono/node-server");
|
|
6
7
|
let _better_auth_drizzle_adapter = require("@better-auth/drizzle-adapter");
|
|
7
8
|
let better_auth = require("better-auth");
|
|
8
9
|
let better_auth_plugins_bearer = require("better-auth/plugins/bearer");
|
|
9
10
|
let better_auth_plugins_device_authorization = require("better-auth/plugins/device-authorization");
|
|
10
11
|
let better_auth_plugins = require("better-auth/plugins");
|
|
12
|
+
let node_async_hooks = require("node:async_hooks");
|
|
13
|
+
let better_auth_api = require("better-auth/api");
|
|
11
14
|
let better_auth_plugins_magic_link = require("better-auth/plugins/magic-link");
|
|
12
15
|
let resend = require("resend");
|
|
13
|
-
let node_async_hooks = require("node:async_hooks");
|
|
14
16
|
let hono = require("hono");
|
|
15
17
|
let hono_cors = require("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: (0, better_auth_api.createAuthEndpoint)("/device/attach-organization", {
|
|
1307
|
+
method: "POST",
|
|
1308
|
+
body: zod.object({
|
|
1309
|
+
userCode: zod.string(),
|
|
1310
|
+
organizationId: zod.string()
|
|
1311
|
+
}),
|
|
1312
|
+
requireHeaders: true
|
|
1313
|
+
}, async (ctx) => {
|
|
1314
|
+
const session = await (0, better_auth_api.getSessionFromCtx)(ctx);
|
|
1315
|
+
if (!session) throw new better_auth_api.APIError("UNAUTHORIZED", {
|
|
1316
|
+
error: "unauthorized",
|
|
1317
|
+
error_description: "Authentication required"
|
|
1318
|
+
});
|
|
1319
|
+
const organizationId = ctx.body.organizationId.trim();
|
|
1320
|
+
if (!organizationId) throw new better_auth_api.APIError("BAD_REQUEST", {
|
|
1321
|
+
error: "invalid_request",
|
|
1322
|
+
error_description: "Organization id is required"
|
|
1323
|
+
});
|
|
1324
|
+
if (!await require_dist$2.selectUserOrganizationMembership(session.user.id, organizationId)) throw new better_auth_api.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 better_auth_api.APIError("BAD_REQUEST", {
|
|
1337
|
+
error: "invalid_request",
|
|
1338
|
+
error_description: "Invalid device user code"
|
|
1339
|
+
});
|
|
1340
|
+
if (deviceCodeRecord.expiresAt < /* @__PURE__ */ new Date()) throw new better_auth_api.APIError("BAD_REQUEST", {
|
|
1341
|
+
error: "expired_token",
|
|
1342
|
+
error_description: "Device user code has expired"
|
|
1343
|
+
});
|
|
1344
|
+
if (deviceCodeRecord.status !== "pending") throw new better_auth_api.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 better_auth_api.APIError("BAD_REQUEST", {
|
|
1349
|
+
error: "invalid_request",
|
|
1350
|
+
error_description: "Invalid device client"
|
|
1351
|
+
});
|
|
1352
|
+
if (!deviceCodeRecord.userId) throw new better_auth_api.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 better_auth_api.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
|
(0, better_auth_plugins_bearer.bearer)(),
|
|
1434
1509
|
(0, better_auth_plugins.jwt)({ jwt: { definePayload: ({ user }) => ({
|
|
1435
1510
|
id: user.id,
|
|
@@ -3668,4 +3743,4 @@ Object.defineProperty(exports, "startPlatformServer", {
|
|
|
3668
3743
|
}
|
|
3669
3744
|
});
|
|
3670
3745
|
|
|
3671
|
-
//# sourceMappingURL=start-
|
|
3746
|
+
//# sourceMappingURL=start-BuRTgJlJ.cjs.map
|