@shophost/rest-api 2.0.34 → 2.0.35
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/package.json +1 -1
- package/scripts/minify-dist.mjs +45 -0
- package/src/app.js +1 -53
- package/src/core/auth/auth.schema.js +1 -41
- package/src/core/auth/auth.util.js +1 -44
- package/src/core/auth/better-auth.lib.js +1 -100
- package/src/core/auth/generate-password-hash.util.js +1 -30
- package/src/core/auth/headers.schema.js +1 -22
- package/src/core/auth/user.schema.js +1 -30
- package/src/core/db/__generated__/client/browser.js +1 -18
- package/src/core/db/__generated__/client/client.js +1 -35
- package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
- package/src/core/db/__generated__/client/enums.js +1 -200
- package/src/core/db/__generated__/client/internal/class.js +769 -55
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
- package/src/core/db/__generated__/client/models/Account.js +1 -2
- package/src/core/db/__generated__/client/models/Address.js +1 -2
- package/src/core/db/__generated__/client/models/Campaign.js +1 -2
- package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
- package/src/core/db/__generated__/client/models/File.js +1 -2
- package/src/core/db/__generated__/client/models/Invitation.js +1 -2
- package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
- package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
- package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Member.js +1 -2
- package/src/core/db/__generated__/client/models/Modifier.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
- package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
- package/src/core/db/__generated__/client/models/Order.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
- package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Organization.js +1 -2
- package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
- package/src/core/db/__generated__/client/models/Payment.js +1 -2
- package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
- package/src/core/db/__generated__/client/models/Product.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
- package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
- package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
- package/src/core/db/__generated__/client/models/Reservation.js +1 -2
- package/src/core/db/__generated__/client/models/Session.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
- package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
- package/src/core/db/__generated__/client/models/User.js +1 -2
- package/src/core/db/__generated__/client/models/Verification.js +1 -2
- package/src/core/db/__generated__/client/models.js +1 -2
- package/src/core/db/index.js +1 -2
- package/src/core/exceptions/http-exception.js +1 -9
- package/src/core/hono/hono.js +1 -123
- package/src/core/lib/prisma.js +1 -11
- package/src/core/logging/pino.js +1 -5
- package/src/core/notifications/email.service.js +1 -116
- package/src/core/openapi/openapi.lib.js +1 -26
- package/src/core/types/google-maps.types.js +1 -2
- package/src/core/utils/currency.util.js +1 -11
- package/src/core/utils/env.util.js +1 -8
- package/src/core/utils/object.util.js +1 -39
- package/src/core/utils/translations.util.js +0 -1
- package/src/core/utils/zod.util.js +1 -85
- package/src/db.js +1 -3
- package/src/features/access/access.handler.js +1 -91
- package/src/features/access/access.route.js +1 -220
- package/src/features/access/access.schema.js +1 -108
- package/src/features/access/access.service.js +1 -294
- package/src/features/cart/cart.handler.js +1 -17
- package/src/features/cart/cart.route.js +1 -32
- package/src/features/cart/cart.schema.js +1 -39
- package/src/features/cart/cart.service.js +1 -97
- package/src/features/cart/cart.util.js +1 -76
- package/src/features/file/file.handler.js +1 -23
- package/src/features/file/file.route.js +1 -34
- package/src/features/file/file.schema.js +1 -77
- package/src/features/file/file.service.js +1 -66
- package/src/features/health/health.handler.js +1 -10
- package/src/features/health/health.route.js +1 -25
- package/src/features/index.js +1 -16
- package/src/features/location/location.handler.js +1 -25
- package/src/features/location/location.route.js +1 -56
- package/src/features/location/location.schema.js +1 -50
- package/src/features/location/location.service.js +1 -141
- package/src/features/manufacturer/manufacturer.handler.js +1 -53
- package/src/features/manufacturer/manufacturer.route.js +1 -97
- package/src/features/manufacturer/manufacturer.schema.js +1 -125
- package/src/features/manufacturer/manufacturer.service.js +1 -190
- package/src/features/order/emails/order-confirmation.email.js +1 -229
- package/src/features/order/emails/order-notification.email.js +1 -229
- package/src/features/order/fulfilment.schema.js +1 -3
- package/src/features/order/order.handler.js +1 -54
- package/src/features/order/order.route.js +1 -111
- package/src/features/order/order.schema.js +1 -158
- package/src/features/order/order.service.js +1 -306
- package/src/features/order/recipient.schema.js +1 -38
- package/src/features/organization/legal-entity.schema.js +1 -83
- package/src/features/organization/organization-configuration.schema.js +1 -115
- package/src/features/organization/organization.handler.js +1 -48
- package/src/features/organization/organization.route.js +1 -84
- package/src/features/organization/organization.schema.js +1 -64
- package/src/features/organization/organization.service.js +1 -334
- package/src/features/payment/payment.handler.js +1 -16
- package/src/features/payment/payment.route.js +1 -22
- package/src/features/payment/payment.schema.js +1 -46
- package/src/features/payment/payment.service.js +1 -100
- package/src/features/payment/stripe.service.js +1 -164
- package/src/features/product/product-modifier.schema.js +1 -84
- package/src/features/product/product.handler.js +1 -87
- package/src/features/product/product.route.js +1 -179
- package/src/features/product/product.schema.js +1 -143
- package/src/features/product/product.service.js +1 -440
- package/src/features/product-category/product-category.handler.js +1 -59
- package/src/features/product-category/product-category.route.js +1 -139
- package/src/features/product-category/product-category.schema.js +1 -86
- package/src/features/product-category/product-category.service.js +1 -220
- package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
- package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
- package/src/features/reservation/emails/reservation-notification.email.js +1 -93
- package/src/features/reservation/reservation.handler.js +1 -65
- package/src/features/reservation/reservation.route.js +1 -167
- package/src/features/reservation/reservation.schema.js +1 -51
- package/src/features/reservation/reservation.service.js +1 -231
- package/src/features/shipping/shipping.handler.js +1 -32
- package/src/features/shipping/shipping.route.js +1 -51
- package/src/features/shipping/shipping.service.js +1 -96
- package/src/features/shipping-method/shipping-method.handler.js +1 -60
- package/src/features/shipping-method/shipping-method.route.js +1 -144
- package/src/features/shipping-method/shipping-method.schema.js +1 -48
- package/src/features/shipping-method/shipping-method.service.js +1 -229
- package/src/features/shipping-method/shipping-zone.schema.js +1 -31
- package/src/features/webhook/webhook.handler.js +1 -50
- package/src/features/webhook/webhook.route.js +1 -33
- package/src/index.js +1 -6
- package/src/integrations/next.js +1 -82
- package/src/schemas/address.schema.js +1 -112
- package/src/schemas/currency.schema.js +1 -118
- package/src/schemas/error.schema.js +1 -12
- package/src/schemas/index.js +1 -29
- package/src/schemas/locales.schema.js +1 -238
- package/src/schemas/number.schema.js +1 -29
- package/src/schemas/pagination.schema.js +1 -54
- package/src/schemas/params.schema.js +1 -20
- package/src/schemas/queries.schema.js +1 -6
- package/src/test/global-setup.js +1 -37
- package/src/test/integration/api-fixtures.js +1 -160
- package/src/test/integration/seed.js +1 -368
- package/src/test/integration/test-helpers.js +1 -154
- package/src/test/setup-test-env.js +1 -7
package/package.json
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { transform } from "esbuild";
|
|
2
|
+
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
const distRoot = path.resolve("dist/packages/rest-api/src");
|
|
6
|
+
let count = 0;
|
|
7
|
+
let savedBytes = 0;
|
|
8
|
+
|
|
9
|
+
async function walk(dir) {
|
|
10
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
11
|
+
const full = path.join(dir, entry.name);
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
await walk(full);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (!entry.name.endsWith(".js")) continue;
|
|
17
|
+
|
|
18
|
+
const source = readFileSync(full, "utf8");
|
|
19
|
+
|
|
20
|
+
// Preserve "use client" / "use server" directives
|
|
21
|
+
const directiveMatch = source.match(
|
|
22
|
+
/^(?:["']use (?:client|server)["'];?\s*\n?)+/
|
|
23
|
+
);
|
|
24
|
+
const directive = directiveMatch ? directiveMatch[0].trim() + "\n" : "";
|
|
25
|
+
const code = directive
|
|
26
|
+
? source.slice(directiveMatch[0].length)
|
|
27
|
+
: source;
|
|
28
|
+
|
|
29
|
+
const result = await transform(code, {
|
|
30
|
+
minify: true,
|
|
31
|
+
loader: "js",
|
|
32
|
+
target: "es2020",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const output = directive + result.code;
|
|
36
|
+
savedBytes += source.length - output.length;
|
|
37
|
+
writeFileSync(full, output);
|
|
38
|
+
count++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await walk(distRoot);
|
|
43
|
+
console.log(
|
|
44
|
+
`✓ Minified ${count} files (saved ${(savedBytes / 1024).toFixed(0)} KB)`
|
|
45
|
+
);
|
package/src/app.js
CHANGED
|
@@ -1,53 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cors } from "hono/cors";
|
|
3
|
-
import { createApiRouter, createUnavailableAuth, handleAppError, } from "./core/hono/hono";
|
|
4
|
-
import { buildAccessHandler, buildCartHandler, buildFileHandler, buildHealthHandler, buildLocationHandler, buildManufacturerHandler, buildOrderHandler, buildOrganizationHandler, buildPaymentHandler, buildProductCategoryHandler, buildProductHandler, buildReservationHandler, buildShippingHandler, buildShippingMethodHandler, buildWebhookHandler, } from "./features";
|
|
5
|
-
const defaultCorsOptions = {
|
|
6
|
-
allowHeaders: [
|
|
7
|
-
"Content-Type",
|
|
8
|
-
"Authorization",
|
|
9
|
-
"X-Requested-With",
|
|
10
|
-
"Accept",
|
|
11
|
-
"Origin",
|
|
12
|
-
"X-CSRF-Token",
|
|
13
|
-
],
|
|
14
|
-
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"],
|
|
15
|
-
credentials: true,
|
|
16
|
-
exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
|
|
17
|
-
origin: ["http://localhost:3000"],
|
|
18
|
-
};
|
|
19
|
-
export const buildApiApp = ({ corsOptions, maps, payment, prisma, resolveAuth = () => createUnavailableAuth(), } = {}) => {
|
|
20
|
-
var _a, _b, _c, _d, _e;
|
|
21
|
-
const app = createApiRouter();
|
|
22
|
-
// cors
|
|
23
|
-
app.use("*", cors(Object.assign(Object.assign({}, defaultCorsOptions), corsOptions)));
|
|
24
|
-
// auth
|
|
25
|
-
app.use("*", (c, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
const auth = resolveAuth(c.req.raw, c.req.path);
|
|
27
|
-
c.set("auth", auth);
|
|
28
|
-
Object.assign(c.req.raw, { auth });
|
|
29
|
-
yield next();
|
|
30
|
-
}));
|
|
31
|
-
// error handler
|
|
32
|
-
app.onError((error) => handleAppError(error));
|
|
33
|
-
// routes
|
|
34
|
-
app.route("/", buildHealthHandler());
|
|
35
|
-
app.route("/", buildManufacturerHandler(prisma));
|
|
36
|
-
app.route("/", buildOrganizationHandler(prisma, (_b = (_a = maps === null || maps === void 0 ? void 0 : maps.google) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : ""));
|
|
37
|
-
app.route("/", buildFileHandler(prisma));
|
|
38
|
-
app.route("/", buildProductCategoryHandler(prisma));
|
|
39
|
-
app.route("/", buildProductHandler(prisma));
|
|
40
|
-
app.route("/", buildAccessHandler(prisma));
|
|
41
|
-
app.route("/", buildShippingMethodHandler(prisma));
|
|
42
|
-
app.route("/", buildOrderHandler(prisma, payment !== null && payment !== void 0 ? payment : {}));
|
|
43
|
-
app.route("/", buildCartHandler(prisma));
|
|
44
|
-
app.route("/", buildShippingHandler(prisma, (_d = (_c = maps === null || maps === void 0 ? void 0 : maps.google) === null || _c === void 0 ? void 0 : _c.key) !== null && _d !== void 0 ? _d : ""));
|
|
45
|
-
app.route("/", buildLocationHandler(maps !== null && maps !== void 0 ? maps : {}));
|
|
46
|
-
app.route("/", buildPaymentHandler(prisma, payment !== null && payment !== void 0 ? payment : {}));
|
|
47
|
-
app.route("/", buildWebhookHandler(prisma, payment !== null && payment !== void 0 ? payment : {}));
|
|
48
|
-
if ((_e = payment === null || payment === void 0 ? void 0 : payment.stripe) === null || _e === void 0 ? void 0 : _e.resendApiKey) {
|
|
49
|
-
app.route("/", buildReservationHandler(prisma, payment.stripe.resendApiKey));
|
|
50
|
-
}
|
|
51
|
-
return app;
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=app.js.map
|
|
1
|
+
import{__awaiter as h}from"tslib";import{cors as g}from"hono/cors";import{createApiRouter as s,createUnavailableAuth as A,handleAppError as O}from"./core/hono/hono";import{buildAccessHandler as f,buildCartHandler as T,buildFileHandler as C,buildHealthHandler as P,buildLocationHandler as _,buildManufacturerHandler as E,buildOrderHandler as w,buildOrganizationHandler as R,buildPaymentHandler as S,buildProductCategoryHandler as k,buildProductHandler as q,buildReservationHandler as j,buildShippingHandler as K,buildShippingMethodHandler as L,buildWebhookHandler as M}from"./features";const X={allowHeaders:["Content-Type","Authorization","X-Requested-With","Accept","Origin","X-CSRF-Token"],allowMethods:["GET","POST","PUT","DELETE","OPTIONS","PATCH"],credentials:!0,exposeHeaders:["Content-Length","X-Kuma-Revision"],origin:["http://localhost:3000"]};export const buildApiApp=({corsOptions:a,maps:r,payment:e,prisma:l,resolveAuth:c=()=>A()}={})=>{var i,u,t,n,v;const o=s();return o.use("*",g(Object.assign(Object.assign({},X),a))),o.use("*",(d,H)=>h(void 0,void 0,void 0,function*(){const b=c(d.req.raw,d.req.path);d.set("auth",b),Object.assign(d.req.raw,{auth:b}),yield H()})),o.onError(d=>O(d)),o.route("/",P()),o.route("/",E(l)),o.route("/",R(l,(u=(i=r?.google)===null||i===void 0?void 0:i.key)!==null&&u!==void 0?u:"")),o.route("/",C(l)),o.route("/",k(l)),o.route("/",q(l)),o.route("/",f(l)),o.route("/",L(l)),o.route("/",w(l,e??{})),o.route("/",T(l)),o.route("/",K(l,(n=(t=r?.google)===null||t===void 0?void 0:t.key)!==null&&n!==void 0?n:"")),o.route("/",_(r??{})),o.route("/",S(l,e??{})),o.route("/",M(l,e??{})),!((v=e?.stripe)===null||v===void 0)&&v.resendApiKey&&o.route("/",j(l,e.stripe.resendApiKey)),o};
|
|
@@ -1,41 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const SignUpSchema = z.object({
|
|
3
|
-
email: z
|
|
4
|
-
.string()
|
|
5
|
-
.min(1, "Email is required")
|
|
6
|
-
.email("Invalid email")
|
|
7
|
-
.openapi({
|
|
8
|
-
example: "user@example.com",
|
|
9
|
-
description: "User's email address",
|
|
10
|
-
}),
|
|
11
|
-
password: z
|
|
12
|
-
.string()
|
|
13
|
-
.min(1, "Password is required")
|
|
14
|
-
.min(8, "Password must be more than 8 characters")
|
|
15
|
-
.max(32, "Password must be less than 32 characters")
|
|
16
|
-
.openapi({
|
|
17
|
-
example: "password123",
|
|
18
|
-
description: "User's password",
|
|
19
|
-
}),
|
|
20
|
-
firstname: z
|
|
21
|
-
.string()
|
|
22
|
-
.min(1, "First name is required")
|
|
23
|
-
.max(32, "First name must be less than 32 characters")
|
|
24
|
-
.openapi({
|
|
25
|
-
example: "John",
|
|
26
|
-
description: "User's first name",
|
|
27
|
-
}),
|
|
28
|
-
lastname: z
|
|
29
|
-
.string()
|
|
30
|
-
.min(1, "Last name is required")
|
|
31
|
-
.max(32, "Last name must be less than 32 characters")
|
|
32
|
-
.openapi({
|
|
33
|
-
example: "Doe",
|
|
34
|
-
description: "User's last name",
|
|
35
|
-
}),
|
|
36
|
-
}).openapi("SignUp");
|
|
37
|
-
export const SignInSchema = SignUpSchema.pick({
|
|
38
|
-
email: true,
|
|
39
|
-
password: true,
|
|
40
|
-
}).openapi("SignIn");
|
|
41
|
-
//# sourceMappingURL=auth.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const SignUpSchema=e.object({email:e.string().min(1,"Email is required").email("Invalid email").openapi({example:"user@example.com",description:"User's email address"}),password:e.string().min(1,"Password is required").min(8,"Password must be more than 8 characters").max(32,"Password must be less than 32 characters").openapi({example:"password123",description:"User's password"}),firstname:e.string().min(1,"First name is required").max(32,"First name must be less than 32 characters").openapi({example:"John",description:"User's first name"}),lastname:e.string().min(1,"Last name is required").max(32,"Last name must be less than 32 characters").openapi({example:"Doe",description:"User's last name"})}).openapi("SignUp"),SignInSchema=SignUpSchema.pick({email:!0,password:!0}).openapi("SignIn");
|
|
@@ -1,44 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpException } from "../exceptions/http-exception";
|
|
3
|
-
import { logger } from "../logging/pino";
|
|
4
|
-
export const getCurrentUser = (auth) => (headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
5
|
-
const session = yield auth.api.getSession({
|
|
6
|
-
headers: headers,
|
|
7
|
-
});
|
|
8
|
-
if (!(session === null || session === void 0 ? void 0 : session.user)) {
|
|
9
|
-
throw new HttpException(401, "Unauthorized");
|
|
10
|
-
}
|
|
11
|
-
return session.user;
|
|
12
|
-
});
|
|
13
|
-
export const isGranted = (auth) => (headers, organizationId, accessLevel) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
if (!accessLevel) {
|
|
15
|
-
throw new Error("Resource and access level are required");
|
|
16
|
-
}
|
|
17
|
-
const session = yield auth.api.getSession({
|
|
18
|
-
headers: headers,
|
|
19
|
-
});
|
|
20
|
-
if (!(session === null || session === void 0 ? void 0 : session.user)) {
|
|
21
|
-
throw new HttpException(401, "Unauthorized");
|
|
22
|
-
}
|
|
23
|
-
const hasPermission = yield auth.api.hasPermission({
|
|
24
|
-
headers,
|
|
25
|
-
body: {
|
|
26
|
-
organizationId,
|
|
27
|
-
permissions: {
|
|
28
|
-
project: [accessLevel],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
if (!hasPermission.success) {
|
|
33
|
-
logger.error({
|
|
34
|
-
organizationId,
|
|
35
|
-
accessLevel,
|
|
36
|
-
message: "User does not have permission",
|
|
37
|
-
userId: session.user.id,
|
|
38
|
-
hasPermission,
|
|
39
|
-
});
|
|
40
|
-
throw new HttpException(403, "Forbidden");
|
|
41
|
-
}
|
|
42
|
-
return session.user;
|
|
43
|
-
});
|
|
44
|
-
//# sourceMappingURL=auth.util.js.map
|
|
1
|
+
import{__awaiter as d}from"tslib";import{HttpException as n}from"../exceptions/http-exception";import{logger as u}from"../logging/pino";export const getCurrentUser=r=>i=>d(void 0,void 0,void 0,function*(){const e=yield r.api.getSession({headers:i});if(!e?.user)throw new n(401,"Unauthorized");return e.user}),isGranted=r=>(i,e,s)=>d(void 0,void 0,void 0,function*(){if(!s)throw new Error("Resource and access level are required");const o=yield r.api.getSession({headers:i});if(!o?.user)throw new n(401,"Unauthorized");const t=yield r.api.hasPermission({headers:i,body:{organizationId:e,permissions:{project:[s]}}});if(!t.success)throw u.error({organizationId:e,accessLevel:s,message:"User does not have permission",userId:o.user.id,hasPermission:t}),new n(403,"Forbidden");return o.user});
|
|
@@ -1,100 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
3
|
-
import { nextCookies } from "better-auth/next-js";
|
|
4
|
-
import { openAPI, organization } from "better-auth/plugins";
|
|
5
|
-
import { createAccessControl } from "better-auth/plugins/access";
|
|
6
|
-
import { getCurrentUser, isGranted } from "./auth.util";
|
|
7
|
-
const statement = {
|
|
8
|
-
project: ["create", "read", "update", "delete"],
|
|
9
|
-
organization: ["create", "read", "update", "delete"],
|
|
10
|
-
};
|
|
11
|
-
const ac = createAccessControl(statement);
|
|
12
|
-
const readOnly = ac.newRole({
|
|
13
|
-
project: ["read"],
|
|
14
|
-
});
|
|
15
|
-
const member = ac.newRole({
|
|
16
|
-
project: ["read"],
|
|
17
|
-
});
|
|
18
|
-
const manager = ac.newRole({
|
|
19
|
-
project: ["create", "read", "update", "delete"],
|
|
20
|
-
});
|
|
21
|
-
const admin = ac.newRole({
|
|
22
|
-
project: ["create", "read", "update", "delete"],
|
|
23
|
-
organization: ["update"],
|
|
24
|
-
});
|
|
25
|
-
const owner = ac.newRole({
|
|
26
|
-
project: ["create", "read", "update", "delete"],
|
|
27
|
-
organization: ["update", "delete"],
|
|
28
|
-
});
|
|
29
|
-
export const createAuthClient = ({ prisma, baseURL, domain, trustedOrigins, socialProviders, }) => {
|
|
30
|
-
const auth = betterAuth({
|
|
31
|
-
baseURL,
|
|
32
|
-
database: prismaAdapter(prisma, {
|
|
33
|
-
provider: "postgresql",
|
|
34
|
-
}),
|
|
35
|
-
trustedOrigins,
|
|
36
|
-
user: {
|
|
37
|
-
additionalFields: {
|
|
38
|
-
firstname: {
|
|
39
|
-
type: "string",
|
|
40
|
-
required: true,
|
|
41
|
-
},
|
|
42
|
-
lastname: {
|
|
43
|
-
type: "string",
|
|
44
|
-
required: true,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
advanced: {
|
|
49
|
-
crossSubDomainCookies: {
|
|
50
|
-
enabled: true,
|
|
51
|
-
domain: domain,
|
|
52
|
-
},
|
|
53
|
-
useSecureCookies: domain !== "localhost",
|
|
54
|
-
defaultCookieAttributes: {
|
|
55
|
-
path: "/",
|
|
56
|
-
sameSite: "lax", // Use "none" if you need cross-site requests, but requires secure: true
|
|
57
|
-
httpOnly: true, // Prevents JavaScript access to cookies
|
|
58
|
-
secure: domain !== "localhost",
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
emailAndPassword: {
|
|
62
|
-
enabled: true,
|
|
63
|
-
},
|
|
64
|
-
socialProviders: Object.assign({}, ((socialProviders === null || socialProviders === void 0 ? void 0 : socialProviders.google)
|
|
65
|
-
? {
|
|
66
|
-
google: {
|
|
67
|
-
prompt: "select_account",
|
|
68
|
-
clientId: socialProviders.google.clientId,
|
|
69
|
-
clientSecret: socialProviders.google.clientSecret,
|
|
70
|
-
mapProfileToUser: (profile) => {
|
|
71
|
-
return {
|
|
72
|
-
firstname: profile.given_name,
|
|
73
|
-
lastname: profile.family_name,
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
: {})),
|
|
79
|
-
plugins: [
|
|
80
|
-
openAPI(),
|
|
81
|
-
nextCookies(),
|
|
82
|
-
organization({
|
|
83
|
-
ac,
|
|
84
|
-
roles: {
|
|
85
|
-
member,
|
|
86
|
-
readOnly,
|
|
87
|
-
manager,
|
|
88
|
-
admin,
|
|
89
|
-
owner,
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
],
|
|
93
|
-
});
|
|
94
|
-
return {
|
|
95
|
-
auth,
|
|
96
|
-
getCurrentUser: getCurrentUser(auth),
|
|
97
|
-
isGranted: isGranted(auth),
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
//# sourceMappingURL=better-auth.lib.js.map
|
|
1
|
+
import{betterAuth as l}from"better-auth";import{prismaAdapter as d}from"better-auth/adapters/prisma";import{nextCookies as c}from"better-auth/next-js";import{openAPI as p,organization as u}from"better-auth/plugins";import{createAccessControl as m}from"better-auth/plugins/access";import{getCurrentUser as g,isGranted as f}from"./auth.util";const b={project:["create","read","update","delete"],organization:["create","read","update","delete"]},e=m(b),C=e.newRole({project:["read"]}),h=e.newRole({project:["read"]}),j=e.newRole({project:["create","read","update","delete"]}),w=e.newRole({project:["create","read","update","delete"],organization:["update"]}),A=e.newRole({project:["create","read","update","delete"],organization:["update","delete"]});export const createAuthClient=({prisma:n,baseURL:s,domain:r,trustedOrigins:i,socialProviders:t})=>{const o=l({baseURL:s,database:d(n,{provider:"postgresql"}),trustedOrigins:i,user:{additionalFields:{firstname:{type:"string",required:!0},lastname:{type:"string",required:!0}}},advanced:{crossSubDomainCookies:{enabled:!0,domain:r},useSecureCookies:r!=="localhost",defaultCookieAttributes:{path:"/",sameSite:"lax",httpOnly:!0,secure:r!=="localhost"}},emailAndPassword:{enabled:!0},socialProviders:Object.assign({},t?.google?{google:{prompt:"select_account",clientId:t.google.clientId,clientSecret:t.google.clientSecret,mapProfileToUser:a=>({firstname:a.given_name,lastname:a.family_name})}}:{}),plugins:[p(),c(),u({ac:e,roles:{member:h,readOnly:C,manager:j,admin:w,owner:A}})]});return{auth:o,getCurrentUser:g(o),isGranted:f(o)}};
|
|
@@ -1,30 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import crypto from "crypto";
|
|
3
|
-
/**
|
|
4
|
-
* Generate a random salt using crypto.
|
|
5
|
-
*/
|
|
6
|
-
function randomBytes() {
|
|
7
|
-
return new Promise((resolve, reject) => crypto.randomBytes(32, (err, saltBuffer) => err ? reject(err) : resolve(saltBuffer)));
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Generate a hash using PBKDF2.
|
|
11
|
-
*/
|
|
12
|
-
function pbkdf2Promisified(password, salt) {
|
|
13
|
-
return new Promise((resolve, reject) => crypto.pbkdf2(password, salt, 25000, // Number of iterations
|
|
14
|
-
512, // Key length
|
|
15
|
-
"sha256", // Digest algorithm
|
|
16
|
-
(err, hashRaw) => (err ? reject(err) : resolve(hashRaw))));
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Generate a salt and hash for the password.
|
|
20
|
-
*/
|
|
21
|
-
export function generatePasswordSaltHash(password) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const saltBuffer = yield randomBytes();
|
|
24
|
-
const salt = saltBuffer.toString("hex");
|
|
25
|
-
const hashRaw = yield pbkdf2Promisified(password, salt);
|
|
26
|
-
const hash = hashRaw.toString("hex");
|
|
27
|
-
return { hash, salt };
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=generate-password-hash.util.js.map
|
|
1
|
+
import{__awaiter as a}from"tslib";import e from"crypto";function f(){return new Promise((o,n)=>e.randomBytes(32,(t,r)=>t?n(t):o(r)))}function h(o,n){return new Promise((t,r)=>e.pbkdf2(o,n,25e3,512,"sha256",(s,i)=>s?r(s):t(i)))}export function generatePasswordSaltHash(o){return a(this,void 0,void 0,function*(){const t=(yield f()).toString("hex");return{hash:(yield h(o,t)).toString("hex"),salt:t}})}
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const HeaderSchema = z
|
|
3
|
-
.object({
|
|
4
|
-
"accept-language": z.string().optional().openapi({
|
|
5
|
-
example: "en-US",
|
|
6
|
-
description: "Accept-Language header",
|
|
7
|
-
param: {
|
|
8
|
-
in: "header",
|
|
9
|
-
name: "accept-language",
|
|
10
|
-
},
|
|
11
|
-
}),
|
|
12
|
-
cookie: z.string().optional().openapi({
|
|
13
|
-
example: "session=1234567890",
|
|
14
|
-
description: "Cookie header",
|
|
15
|
-
param: {
|
|
16
|
-
in: "header",
|
|
17
|
-
name: "cookie",
|
|
18
|
-
},
|
|
19
|
-
}),
|
|
20
|
-
})
|
|
21
|
-
.openapi("Headers");
|
|
22
|
-
//# sourceMappingURL=headers.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const HeaderSchema=e.object({"accept-language":e.string().optional().openapi({example:"en-US",description:"Accept-Language header",param:{in:"header",name:"accept-language"}}),cookie:e.string().optional().openapi({example:"session=1234567890",description:"Cookie header",param:{in:"header",name:"cookie"}})}).openapi("Headers");
|
|
@@ -1,30 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const UserSchema = z
|
|
3
|
-
.object({
|
|
4
|
-
id: z.string().openapi({
|
|
5
|
-
example: "clm1234567890abcdef",
|
|
6
|
-
description: "User's ID",
|
|
7
|
-
}),
|
|
8
|
-
email: z.string().openapi({
|
|
9
|
-
example: "user@example.com",
|
|
10
|
-
description: "User's email address",
|
|
11
|
-
format: "email",
|
|
12
|
-
}),
|
|
13
|
-
firstname: z.string().openapi({
|
|
14
|
-
example: "John",
|
|
15
|
-
description: "User's first name",
|
|
16
|
-
}),
|
|
17
|
-
lastname: z.string().openapi({
|
|
18
|
-
example: "Doe",
|
|
19
|
-
description: "User's last name",
|
|
20
|
-
}),
|
|
21
|
-
image: z.string().nullable().optional().openapi({
|
|
22
|
-
example: "https://example.com/image.jpg",
|
|
23
|
-
description: "User's profile image",
|
|
24
|
-
}),
|
|
25
|
-
name: z.string().nullable().optional().openapi({
|
|
26
|
-
description: "User's full name (optional)",
|
|
27
|
-
}),
|
|
28
|
-
})
|
|
29
|
-
.openapi("User");
|
|
30
|
-
//# sourceMappingURL=user.schema.js.map
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const UserSchema=e.object({id:e.string().openapi({example:"clm1234567890abcdef",description:"User's ID"}),email:e.string().openapi({example:"user@example.com",description:"User's email address",format:"email"}),firstname:e.string().openapi({example:"John",description:"User's first name"}),lastname:e.string().openapi({example:"Doe",description:"User's last name"}),image:e.string().nullable().optional().openapi({example:"https://example.com/image.jpg",description:"User's profile image"}),name:e.string().nullable().optional().openapi({description:"User's full name (optional)"})}).openapi("User");
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
// biome-ignore-all lint: generated file
|
|
4
|
-
// @ts-nocheck
|
|
5
|
-
/*
|
|
6
|
-
* This file should be your main import to use Prisma-related types and utilities in a browser.
|
|
7
|
-
* Use it to get access to models, enums, and input types.
|
|
8
|
-
*
|
|
9
|
-
* This file does not contain a `PrismaClient` class, nor several other helpers that are intended as server-side only.
|
|
10
|
-
* See `client.ts` for the standard, server-side entry point.
|
|
11
|
-
*
|
|
12
|
-
* 🟢 You can import this file directly.
|
|
13
|
-
*/
|
|
14
|
-
import * as Prisma from './internal/prismaNamespaceBrowser';
|
|
15
|
-
export { Prisma };
|
|
16
|
-
export * as $Enums from './enums';
|
|
17
|
-
export * from './enums';
|
|
18
|
-
//# sourceMappingURL=browser.js.map
|
|
1
|
+
import*as r from"./internal/prismaNamespaceBrowser";export{r as Prisma};export*as $Enums from"./enums";export*from"./enums";
|
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
// biome-ignore-all lint: generated file
|
|
4
|
-
// @ts-nocheck
|
|
5
|
-
/*
|
|
6
|
-
* This file should be your main import to use Prisma. Through it you get access to all the models, enums, and input types.
|
|
7
|
-
* If you're looking for something you can import in the client-side of your application, please refer to the `browser.ts` file instead.
|
|
8
|
-
*
|
|
9
|
-
* 🟢 You can import this file directly.
|
|
10
|
-
*/
|
|
11
|
-
import * as path from 'node:path';
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
|
-
globalThis['__dirname'] = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
import * as $Class from "./internal/class";
|
|
15
|
-
import * as Prisma from "./internal/prismaNamespace";
|
|
16
|
-
export * as $Enums from './enums';
|
|
17
|
-
export * from "./enums";
|
|
18
|
-
/**
|
|
19
|
-
* ## Prisma Client
|
|
20
|
-
*
|
|
21
|
-
* Type-safe database client for TypeScript
|
|
22
|
-
* @example
|
|
23
|
-
* ```
|
|
24
|
-
* const prisma = new PrismaClient({
|
|
25
|
-
* adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL })
|
|
26
|
-
* })
|
|
27
|
-
* // Fetch zero or more Users
|
|
28
|
-
* const users = await prisma.user.findMany()
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* Read more in our [docs](https://pris.ly/d/client).
|
|
32
|
-
*/
|
|
33
|
-
export const PrismaClient = $Class.getPrismaClientClass();
|
|
34
|
-
export { Prisma };
|
|
35
|
-
//# sourceMappingURL=client.js.map
|
|
1
|
+
import*as r from"node:path";import{fileURLToPath as m}from"node:url";globalThis.__dirname=r.dirname(m(import.meta.url));import*as o from"./internal/class";import*as t from"./internal/prismaNamespace";export*as $Enums from"./enums";export*from"./enums";export const PrismaClient=o.getPrismaClientClass();export{t as Prisma};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
// biome-ignore-all lint: generated file
|
|
4
|
-
// @ts-nocheck
|
|
5
|
-
/*
|
|
6
|
-
* This file exports various common sort, input & filter types that are not directly linked to a particular model.
|
|
7
|
-
*
|
|
8
|
-
* 🟢 You can import this file directly.
|
|
9
|
-
*/
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=commonInputTypes.js.map
|
|
1
|
+
export{};
|