@shophost/rest-api 2.0.45 → 2.0.47
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/README.md +2 -7
- package/package.json +1 -1
- package/schema.prisma +14 -0
- package/src/app.d.ts +3 -1
- package/src/app.js +1 -1
- package/src/app.js.map +1 -1
- package/src/core/db/__generated__/client/browser.d.ts +5 -0
- package/src/core/db/__generated__/client/client.d.ts +5 -0
- package/src/core/db/__generated__/client/commonInputTypes.d.ts +54 -54
- package/src/core/db/__generated__/client/internal/class.d.ts +11 -0
- package/src/core/db/__generated__/client/internal/class.js +16 -2
- package/src/core/db/__generated__/client/internal/class.js.map +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +99 -13
- package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +15 -4
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -1
- package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +1 -1
- package/src/core/db/__generated__/client/models/Integration.d.ts +1240 -0
- package/src/core/db/__generated__/client/models/Integration.js +1 -0
- package/src/core/db/__generated__/client/models/Integration.js.map +1 -0
- package/src/core/db/__generated__/client/models/Organization.d.ts +235 -0
- package/src/core/db/__generated__/client/models.d.ts +1 -0
- package/src/core/lib/prisma.d.ts +24 -0
- package/src/core/notifications/notification-options.d.ts +3 -0
- package/src/core/notifications/notification-options.js +1 -0
- package/src/core/notifications/notification-options.js.map +1 -0
- package/src/features/index.d.ts +1 -0
- package/src/features/index.js +1 -1
- package/src/features/index.js.map +1 -1
- package/src/features/integration/integration.handler.d.ts +2 -0
- package/src/features/integration/integration.handler.js +1 -0
- package/src/features/integration/integration.handler.js.map +1 -0
- package/src/features/integration/integration.route.d.ts +212 -0
- package/src/features/integration/integration.route.js +1 -0
- package/src/features/integration/integration.route.js.map +1 -0
- package/src/features/integration/integration.schema.d.ts +44 -0
- package/src/features/integration/integration.schema.js +1 -0
- package/src/features/integration/integration.schema.js.map +1 -0
- package/src/features/integration/integration.service.d.ts +30 -0
- package/src/features/integration/integration.service.js +1 -0
- package/src/features/integration/integration.service.js.map +1 -0
- package/src/features/order/order.handler.d.ts +2 -1
- package/src/features/order/order.handler.js +1 -1
- package/src/features/order/order.handler.js.map +1 -1
- package/src/features/order/order.service.d.ts +3 -1
- package/src/features/order/order.service.js +1 -1
- package/src/features/order/order.service.js.map +1 -1
- package/src/features/organization/organization.service.js +1 -1
- package/src/features/organization/organization.service.js.map +1 -1
- package/src/features/payment/payment.handler.js +1 -1
- package/src/features/payment/payment.handler.js.map +1 -1
- package/src/features/payment/payment.service.d.ts +12 -7
- package/src/features/payment/payment.service.js +1 -1
- package/src/features/payment/payment.service.js.map +1 -1
- package/src/features/payment/stripe.service.d.ts +1 -1
- package/src/features/payment/stripe.service.js +1 -1
- package/src/features/payment/stripe.service.js.map +1 -1
- package/src/features/webhook/webhook.handler.d.ts +2 -1
- package/src/features/webhook/webhook.handler.js +1 -1
- package/src/features/webhook/webhook.handler.js.map +1 -1
- package/src/features/webhook/webhook.route.d.ts +64 -0
- package/src/features/webhook/webhook.route.js +1 -1
- package/src/features/webhook/webhook.route.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js.map +1 -1
- package/src/integrations/next.d.ts +3 -1
- package/src/integrations/next.js +1 -1
- package/src/integrations/next.js.map +1 -1
- package/src/schemas/index.d.ts +1 -0
- package/src/schemas/index.js +1 -1
- package/src/schemas/index.js.map +1 -1
|
@@ -8,6 +8,7 @@ export type * from './models/Organization';
|
|
|
8
8
|
export type * from './models/OpeningTimes';
|
|
9
9
|
export type * from './models/ClosingTimes';
|
|
10
10
|
export type * from './models/OrganizationConfiguration';
|
|
11
|
+
export type * from './models/Integration';
|
|
11
12
|
export type * from './models/Address';
|
|
12
13
|
export type * from './models/LegalEntity';
|
|
13
14
|
export type * from './models/File';
|
package/src/core/lib/prisma.d.ts
CHANGED
|
@@ -194,6 +194,18 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
|
|
|
194
194
|
}) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
|
|
195
195
|
};
|
|
196
196
|
};
|
|
197
|
+
integration: {
|
|
198
|
+
paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
|
|
199
|
+
withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
|
|
200
|
+
limit?: P["limit"] | undefined;
|
|
201
|
+
}) | undefined) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").PageNumberPaginationMeta<TOptions extends {
|
|
202
|
+
includePageCount: boolean;
|
|
203
|
+
} ? TOptions["includePageCount"] : true>]>;
|
|
204
|
+
withCursor: <TOptions extends Omit<P_1, "limit">, P_1 extends import("prisma-extension-pagination").CursorPaginationOptions<import("@prisma/client/runtime/client").Result<T, A, "findMany">[number], NonNullable<import("@prisma/client/runtime/client").Args<T, "findMany">["cursor"]>>>(options: TOptions & {
|
|
205
|
+
limit: P_1["limit"];
|
|
206
|
+
}) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
197
209
|
legalEntity: {
|
|
198
210
|
paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
|
|
199
211
|
withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
|
|
@@ -596,6 +608,18 @@ export declare const createPrismaClient: (options: CreatePrismaClientOptions) =>
|
|
|
596
608
|
}) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
|
|
597
609
|
};
|
|
598
610
|
};
|
|
611
|
+
integration: {
|
|
612
|
+
paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
|
|
613
|
+
withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
|
|
614
|
+
limit?: P["limit"] | undefined;
|
|
615
|
+
}) | undefined) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").PageNumberPaginationMeta<TOptions extends {
|
|
616
|
+
includePageCount: boolean;
|
|
617
|
+
} ? TOptions["includePageCount"] : true>]>;
|
|
618
|
+
withCursor: <TOptions extends Omit<P_1, "limit">, P_1 extends import("prisma-extension-pagination").CursorPaginationOptions<import("@prisma/client/runtime/client").Result<T, A, "findMany">[number], NonNullable<import("@prisma/client/runtime/client").Args<T, "findMany">["cursor"]>>>(options: TOptions & {
|
|
619
|
+
limit: P_1["limit"];
|
|
620
|
+
}) => Promise<[import("@prisma/client/runtime/client").Result<T, A, "findMany">, import("prisma-extension-pagination").CursorPaginationMeta]>;
|
|
621
|
+
};
|
|
622
|
+
};
|
|
599
623
|
legalEntity: {
|
|
600
624
|
paginate: () => <T, A>(this: T, args?: import("@prisma/client/runtime/client").Exact<A, Omit<import("@prisma/client/runtime/client").Args<T, "findMany">, "cursor" | "take" | "skip">> | undefined) => {
|
|
601
625
|
withPages: <TOptions extends Omit<P, "limit">, P extends import("prisma-extension-pagination").PageNumberPaginationOptions>(options?: (TOptions & {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-options.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/core/notifications/notification-options.ts"],"names":[],"mappings":""}
|
package/src/features/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { buildAccessHandler } from "./access/access.handler";
|
|
|
3
3
|
export { buildCartHandler } from "./cart/cart.handler";
|
|
4
4
|
export { buildFileHandler } from "./file/file.handler";
|
|
5
5
|
export { buildHealthHandler } from "./health/health.handler";
|
|
6
|
+
export { buildIntegrationHandler } from "./integration/integration.handler";
|
|
6
7
|
export { buildLocationHandler } from "./location/location.handler";
|
|
7
8
|
export { buildManufacturerHandler } from "./manufacturer/manufacturer.handler";
|
|
8
9
|
export { buildOrderHandler } from "./order/order.handler";
|
package/src/features/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{buildAnalyticsHandler}from"./analytics/analytics.handler";export{buildAccessHandler}from"./access/access.handler";export{buildCartHandler}from"./cart/cart.handler";export{buildFileHandler}from"./file/file.handler";export{buildHealthHandler}from"./health/health.handler";export{buildLocationHandler}from"./location/location.handler";export{buildManufacturerHandler}from"./manufacturer/manufacturer.handler";export{buildOrderHandler}from"./order/order.handler";export{buildOrganizationHandler}from"./organization/organization.handler";export{buildPaymentHandler}from"./payment/payment.handler";export{buildProductCategoryHandler}from"./product-category/product-category.handler";export{buildProductHandler}from"./product/product.handler";export{buildReservationHandler}from"./reservation/reservation.handler";export{buildShippingHandler}from"./shipping/shipping.handler";export{buildShippingMethodHandler}from"./shipping-method/shipping-method.handler";export{buildWebhookHandler}from"./webhook/webhook.handler";
|
|
1
|
+
export{buildAnalyticsHandler}from"./analytics/analytics.handler";export{buildAccessHandler}from"./access/access.handler";export{buildCartHandler}from"./cart/cart.handler";export{buildFileHandler}from"./file/file.handler";export{buildHealthHandler}from"./health/health.handler";export{buildIntegrationHandler}from"./integration/integration.handler";export{buildLocationHandler}from"./location/location.handler";export{buildManufacturerHandler}from"./manufacturer/manufacturer.handler";export{buildOrderHandler}from"./order/order.handler";export{buildOrganizationHandler}from"./organization/organization.handler";export{buildPaymentHandler}from"./payment/payment.handler";export{buildProductCategoryHandler}from"./product-category/product-category.handler";export{buildProductHandler}from"./product/product.handler";export{buildReservationHandler}from"./reservation/reservation.handler";export{buildShippingHandler}from"./shipping/shipping.handler";export{buildShippingMethodHandler}from"./shipping-method/shipping-method.handler";export{buildWebhookHandler}from"./webhook/webhook.handler";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/rest-api/src/features/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,6CAA6C,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/rest-api/src/features/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,6CAA6C,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as d}from"tslib";import{createApiRouter as v}from"../../core/hono/hono";import{IntegrationService as s}from"./integration.service";import{integrationRoutes as p}from"./integration.route";export const buildIntegrationHandler=i=>{const o=v();return o.openapi(p.getIntegrations,t=>d(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param");yield n.isGranted("read");const a=yield new s(i).getIntegrations(e.organizationId);return t.json(a,200)})),o.openapi(p.upsertIntegration,t=>d(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param"),r=t.req.valid("json"),a=yield n.isGranted("update"),u=yield new s(i).upsertIntegration(e.organizationId,e.type,a.id,r);return t.json(u,200)})),o.openapi(p.deleteIntegration,t=>d(void 0,void 0,void 0,function*(){const n=t.get("auth"),e=t.req.valid("param");return yield n.isGranted("update"),yield new s(i).deleteIntegration(e.organizationId,e.type),t.body(null,204)})),o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.handler.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/integration/integration.handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAwB,EAAE,EAAE;IAClE,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;IAE9B,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,eAAe,EAAE,CAAO,CAAC,EAAE,EAAE;QACzD,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEpC,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAE7B,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QAE1E,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC,CAAA,CAAC,CAAC;IAEH,GAA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AAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
export declare const integrationRoutes: {
|
|
3
|
+
getIntegrations: {
|
|
4
|
+
description: string | undefined;
|
|
5
|
+
method: import("@hono/zod-openapi").RouteConfig["method"];
|
|
6
|
+
operationId: string;
|
|
7
|
+
path: string;
|
|
8
|
+
request: Record<never, never> & {
|
|
9
|
+
headers: z.ZodObject<{
|
|
10
|
+
"accept-language": z.ZodOptional<z.ZodString>;
|
|
11
|
+
cookie: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
} & {
|
|
14
|
+
params: z.ZodObject<{
|
|
15
|
+
organizationId: z.ZodString;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
};
|
|
18
|
+
responses: {
|
|
19
|
+
200: {
|
|
20
|
+
content: {
|
|
21
|
+
"application/json": {
|
|
22
|
+
schema: z.ZodArray<z.ZodObject<{
|
|
23
|
+
organizationId: z.ZodString;
|
|
24
|
+
type: z.ZodString;
|
|
25
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
26
|
+
createdAt: z.ZodDate;
|
|
27
|
+
updatedAt: z.ZodDate;
|
|
28
|
+
}, z.core.$strip>>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
33
|
+
400: {
|
|
34
|
+
content: {
|
|
35
|
+
"application/json": {
|
|
36
|
+
schema: z.ZodObject<{
|
|
37
|
+
status: z.ZodNumber;
|
|
38
|
+
message: z.ZodString;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
401: {
|
|
45
|
+
content: {
|
|
46
|
+
"application/json": {
|
|
47
|
+
schema: z.ZodObject<{
|
|
48
|
+
status: z.ZodNumber;
|
|
49
|
+
message: z.ZodString;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
description: string;
|
|
54
|
+
};
|
|
55
|
+
404: {
|
|
56
|
+
content: {
|
|
57
|
+
"application/json": {
|
|
58
|
+
schema: z.ZodObject<{
|
|
59
|
+
status: z.ZodNumber;
|
|
60
|
+
message: z.ZodString;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
description: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
summary: string;
|
|
68
|
+
tags: string[];
|
|
69
|
+
} & {
|
|
70
|
+
getRoutingPath(): string;
|
|
71
|
+
};
|
|
72
|
+
upsertIntegration: {
|
|
73
|
+
description: string | undefined;
|
|
74
|
+
method: import("@hono/zod-openapi").RouteConfig["method"];
|
|
75
|
+
operationId: string;
|
|
76
|
+
path: string;
|
|
77
|
+
request: {
|
|
78
|
+
body: {
|
|
79
|
+
content: {
|
|
80
|
+
"application/json": {
|
|
81
|
+
schema: z.ZodObject<{
|
|
82
|
+
config: z.ZodUnknown;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
required: boolean;
|
|
87
|
+
};
|
|
88
|
+
} & {
|
|
89
|
+
headers: z.ZodObject<{
|
|
90
|
+
"accept-language": z.ZodOptional<z.ZodString>;
|
|
91
|
+
cookie: z.ZodOptional<z.ZodString>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
} & {
|
|
94
|
+
params: z.ZodObject<{
|
|
95
|
+
organizationId: z.ZodString;
|
|
96
|
+
type: z.ZodString;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
} & Record<never, never>;
|
|
99
|
+
responses: {
|
|
100
|
+
200: {
|
|
101
|
+
content: {
|
|
102
|
+
"application/json": {
|
|
103
|
+
schema: z.ZodObject<{
|
|
104
|
+
organizationId: z.ZodString;
|
|
105
|
+
type: z.ZodString;
|
|
106
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
107
|
+
createdAt: z.ZodDate;
|
|
108
|
+
updatedAt: z.ZodDate;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
description: string;
|
|
113
|
+
};
|
|
114
|
+
400: {
|
|
115
|
+
content: {
|
|
116
|
+
"application/json": {
|
|
117
|
+
schema: z.ZodObject<{
|
|
118
|
+
status: z.ZodNumber;
|
|
119
|
+
message: z.ZodString;
|
|
120
|
+
}, z.core.$strip>;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
description: string;
|
|
124
|
+
};
|
|
125
|
+
401: {
|
|
126
|
+
content: {
|
|
127
|
+
"application/json": {
|
|
128
|
+
schema: z.ZodObject<{
|
|
129
|
+
status: z.ZodNumber;
|
|
130
|
+
message: z.ZodString;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
404: {
|
|
137
|
+
content: {
|
|
138
|
+
"application/json": {
|
|
139
|
+
schema: z.ZodObject<{
|
|
140
|
+
status: z.ZodNumber;
|
|
141
|
+
message: z.ZodString;
|
|
142
|
+
}, z.core.$strip>;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
description: string;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
summary: string;
|
|
149
|
+
tags: string[];
|
|
150
|
+
} & {
|
|
151
|
+
getRoutingPath(): string;
|
|
152
|
+
};
|
|
153
|
+
deleteIntegration: {
|
|
154
|
+
description: string | undefined;
|
|
155
|
+
method: import("@hono/zod-openapi").RouteConfig["method"];
|
|
156
|
+
operationId: string;
|
|
157
|
+
path: string;
|
|
158
|
+
request: Record<never, never> & {
|
|
159
|
+
headers: z.ZodObject<{
|
|
160
|
+
"accept-language": z.ZodOptional<z.ZodString>;
|
|
161
|
+
cookie: z.ZodOptional<z.ZodString>;
|
|
162
|
+
}, z.core.$strip>;
|
|
163
|
+
} & {
|
|
164
|
+
params: z.ZodObject<{
|
|
165
|
+
organizationId: z.ZodString;
|
|
166
|
+
type: z.ZodString;
|
|
167
|
+
}, z.core.$strip>;
|
|
168
|
+
};
|
|
169
|
+
responses: {
|
|
170
|
+
204: {
|
|
171
|
+
description: string;
|
|
172
|
+
};
|
|
173
|
+
400: {
|
|
174
|
+
content: {
|
|
175
|
+
"application/json": {
|
|
176
|
+
schema: z.ZodObject<{
|
|
177
|
+
status: z.ZodNumber;
|
|
178
|
+
message: z.ZodString;
|
|
179
|
+
}, z.core.$strip>;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
description: string;
|
|
183
|
+
};
|
|
184
|
+
401: {
|
|
185
|
+
content: {
|
|
186
|
+
"application/json": {
|
|
187
|
+
schema: z.ZodObject<{
|
|
188
|
+
status: z.ZodNumber;
|
|
189
|
+
message: z.ZodString;
|
|
190
|
+
}, z.core.$strip>;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
description: string;
|
|
194
|
+
};
|
|
195
|
+
404: {
|
|
196
|
+
content: {
|
|
197
|
+
"application/json": {
|
|
198
|
+
schema: z.ZodObject<{
|
|
199
|
+
status: z.ZodNumber;
|
|
200
|
+
message: z.ZodString;
|
|
201
|
+
}, z.core.$strip>;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
description: string;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
summary: string;
|
|
208
|
+
tags: string[];
|
|
209
|
+
} & {
|
|
210
|
+
getRoutingPath(): string;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as i}from"@hono/zod-openapi";import{createApiRoute as e}from"../../core/hono/hono";import{ErrorSchema as t,HeaderSchema as n,OrganizationParams as a}from"../../schemas";import{IntegrationSchema as o,IntegrationTypeSchema as s,UpsertIntegrationSchema as g}from"./integration.schema";const r=a.extend({type:s.openapi({param:{in:"path",name:"type"}})}),p=e({description:"Fetches integrations configured for an organization",headers:n,method:"GET",operationId:"getIntegrations",path:"/:organizationId/integrations",pathParams:a,responses:{200:i.array(o),400:t,401:t,404:t},summary:"Get Integrations",tags:["Integration"]}),m=e({body:g,description:"Creates or updates an integration configuration",headers:n,method:"PUT",operationId:"upsertIntegration",path:"/:organizationId/integrations/:type",pathParams:r,responses:{200:o,400:t,401:t,404:t},summary:"Upsert Integration",tags:["Integration"]}),I=e({description:"Deletes an integration configuration",headers:n,method:"DELETE",operationId:"deleteIntegration",path:"/:organizationId/integrations/:type",pathParams:r,responses:{204:null,400:t,401:t,404:t},summary:"Delete Integration",tags:["Integration"]});export const integrationRoutes={getIntegrations:p,upsertIntegration:m,deleteIntegration:I};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.route.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/integration/integration.route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,MAAM,CAAC;IAClD,IAAI,EAAE,qBAAqB,CAAC,OAAO,CAAC;QAClC,KAAK,EAAE;YACL,EAAE,EAAE,MAAM;YACV,IAAI,EAAE,MAAM;SACb;KACF,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,cAAc,CAAC;IAC1C,WAAW,EAAE,qDAAqD;IAClE,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,KAAK;IACb,WAAW,EAAE,iBAAiB;IAC9B,IAAI,EAAE,+BAA+B;IACrC,UAAU,EAAE,kBAAkB;IAC9B,SAAS,E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zod-openapi";
|
|
2
|
+
export declare const IntegrationTypeSchema: z.ZodString;
|
|
3
|
+
export declare const StripePaymentMethodSchema: z.ZodEnum<{
|
|
4
|
+
card: "card";
|
|
5
|
+
blik: "blik";
|
|
6
|
+
}>;
|
|
7
|
+
export declare const StripeIntegrationStoredConfigSchema: z.ZodObject<{
|
|
8
|
+
paymentMethods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
9
|
+
card: "card";
|
|
10
|
+
blik: "blik";
|
|
11
|
+
}>>>;
|
|
12
|
+
secretKey: z.ZodOptional<z.ZodString>;
|
|
13
|
+
webhookSecret: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
export declare const StripeIntegrationConfigSchema: z.ZodObject<{
|
|
16
|
+
paymentMethods: z.ZodArray<z.ZodEnum<{
|
|
17
|
+
card: "card";
|
|
18
|
+
blik: "blik";
|
|
19
|
+
}>>;
|
|
20
|
+
hasSecretKey: z.ZodBoolean;
|
|
21
|
+
hasWebhookSecret: z.ZodBoolean;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export declare const UpsertStripeIntegrationConfigSchema: z.ZodObject<{
|
|
24
|
+
paymentMethods: z.ZodArray<z.ZodEnum<{
|
|
25
|
+
card: "card";
|
|
26
|
+
blik: "blik";
|
|
27
|
+
}>>;
|
|
28
|
+
secretKey: z.ZodOptional<z.ZodString>;
|
|
29
|
+
webhookSecret: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strict>;
|
|
31
|
+
export declare const IntegrationConfigSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
32
|
+
export declare const IntegrationSchema: z.ZodObject<{
|
|
33
|
+
organizationId: z.ZodString;
|
|
34
|
+
type: z.ZodString;
|
|
35
|
+
config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
36
|
+
createdAt: z.ZodDate;
|
|
37
|
+
updatedAt: z.ZodDate;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export declare const UpsertIntegrationSchema: z.ZodObject<{
|
|
40
|
+
config: z.ZodUnknown;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
export type StripeIntegrationConfig = z.infer<typeof StripeIntegrationConfigSchema>;
|
|
43
|
+
export type StripeIntegrationStoredConfig = z.infer<typeof StripeIntegrationStoredConfigSchema>;
|
|
44
|
+
export type UpsertStripeIntegrationConfig = z.infer<typeof UpsertStripeIntegrationConfigSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"@hono/zod-openapi";export const IntegrationTypeSchema=e.string().min(1).openapi({example:"stripe",description:"Integration type key"}),StripePaymentMethodSchema=e.enum(["card","blik"]).openapi({example:"card",description:"Stripe payment method"}),StripeIntegrationStoredConfigSchema=e.object({paymentMethods:e.array(StripePaymentMethodSchema).max(2).optional(),secretKey:e.string().trim().min(1).optional(),webhookSecret:e.string().trim().min(1).optional()}).strict(),StripeIntegrationConfigSchema=e.object({paymentMethods:e.array(StripePaymentMethodSchema).max(2).openapi({example:["card","blik"],description:"Enabled Stripe payment methods for the organization"}),hasSecretKey:e.boolean().openapi({example:!0,description:"Whether the Stripe API key has been configured"}),hasWebhookSecret:e.boolean().openapi({example:!0,description:"Whether the Stripe webhook signing secret has been configured"})}).strict().openapi("StripeIntegrationConfig"),UpsertStripeIntegrationConfigSchema=e.object({paymentMethods:e.array(StripePaymentMethodSchema).max(2).openapi({example:["card","blik"],description:"Enabled Stripe payment methods for the organization"}),secretKey:e.string().trim().min(1).optional().openapi({example:"sk_live_123456789",description:"Stripe secret API key for the organization"}),webhookSecret:e.string().trim().min(1).optional().openapi({example:"whsec_123456789",description:"Stripe webhook signing secret for the organization"})}).strict().openapi("UpsertStripeIntegrationConfig"),IntegrationConfigSchema=e.record(e.string(),e.unknown()).openapi("IntegrationConfig"),IntegrationSchema=e.object({organizationId:e.string().openapi({example:"clm1234567890abcdef",description:"Organization ID"}),type:IntegrationTypeSchema,config:IntegrationConfigSchema.openapi({description:"Stored integration configuration JSON"}),createdAt:e.date().openapi({description:"Timestamp when the integration was created"}),updatedAt:e.date().openapi({description:"Timestamp when the integration was last updated"})}).openapi("Integration"),UpsertIntegrationSchema=e.object({config:e.unknown().openapi({example:{paymentMethods:["card","blik"],secretKey:"sk_live_123456789",webhookSecret:"whsec_123456789"},description:"Integration configuration payload. Validation depends on the integration type."})}).openapi("UpsertIntegration");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.schema.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/integration/integration.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEtC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7D,OAAO,EAAE,QAAQ;IACjB,WAAW,EAAE,sBAAsB;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IACxE,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,uBAAuB;CACrC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC;KACjD,MAAM,CAAC;IACN,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACpE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC9C,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACnD,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,CAAC,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BAA+B,CAAC,CAAC;AAE5C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;KAC/B,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC;KAC/B,MAAM,CAAC;IACN,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC;QACjC,OAAO,EAAE,qBAAqB;QAC9B,WAAW,EAAE,iBAAiB;KAC/B,CAAC;IACF,IAAI,EAAE,qBAAqB;IAC3B,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC;QACtC,WAAW,EAAE,uCAAuC;KACrD,CAAC;IACF,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC;QAC1B,WAAW,EAAE,4CAA4C;KAC1D,CAAC;IACF,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC;QAC1B,WAAW,EAAE,iDAAiD;KAC/D,CAAC;CACH,CAAC;KACD,OAAO,CAAC,aAAa,CAAC,CAAC;AAE1B,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,CAAC;IACN,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC;QAC1B,OAAO,EAAE;YACP,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;YAChC,SAAS,EAAE,mBAAmB;YAC9B,aAAa,EAAE,iBAAiB;SACjC;QACD,WAAW,EACT,gFAAgF;KACnF,CAAC;CACH,CAAC;KACD,OAAO,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
import { PrismaClientType } from "../../core/lib/prisma";
|
|
3
|
+
import { UpsertIntegrationSchema } from "./integration.schema";
|
|
4
|
+
declare class IntegrationService {
|
|
5
|
+
private readonly prisma;
|
|
6
|
+
constructor(prisma: PrismaClientType);
|
|
7
|
+
private normalizeSecret;
|
|
8
|
+
private normalizeStripePaymentMethods;
|
|
9
|
+
private parseStripeStoredConfig;
|
|
10
|
+
private sanitizeConfig;
|
|
11
|
+
private sanitizeIntegration;
|
|
12
|
+
private ensureOrganizationExists;
|
|
13
|
+
private validateConfig;
|
|
14
|
+
getIntegrations(organizationId: string): Promise<{
|
|
15
|
+
organizationId: string;
|
|
16
|
+
type: string;
|
|
17
|
+
config: Record<string, unknown>;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
}[]>;
|
|
21
|
+
upsertIntegration(organizationId: string, type: string, userId: string, body: z.infer<typeof UpsertIntegrationSchema>): Promise<{
|
|
22
|
+
organizationId: string;
|
|
23
|
+
type: string;
|
|
24
|
+
config: Record<string, unknown>;
|
|
25
|
+
createdAt: Date;
|
|
26
|
+
updatedAt: Date;
|
|
27
|
+
}>;
|
|
28
|
+
deleteIntegration(organizationId: string, type: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export { IntegrationService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as h}from"tslib";import{HttpException as a}from"../../core/exceptions/http-exception";import{IntegrationSchema as p,StripeIntegrationConfigSchema as g,StripeIntegrationStoredConfigSchema as f,UpsertStripeIntegrationConfigSchema as m}from"./integration.schema";class y{constructor(e){this.prisma=e}normalizeSecret(e){const t=e?.trim();return t||void 0}normalizeStripePaymentMethods(e){return Array.from(new Set(e.filter(t=>t==="card"||t==="blik")))}parseStripeStoredConfig(e){const t=f.safeParse(e);if(t.success)return{paymentMethods:t.data.paymentMethods?this.normalizeStripePaymentMethods(t.data.paymentMethods):void 0,secretKey:this.normalizeSecret(t.data.secretKey),webhookSecret:this.normalizeSecret(t.data.webhookSecret)}}sanitizeConfig(e,t){var n;if(e==="stripe"){const i=this.parseStripeStoredConfig(t);return g.parse({paymentMethods:(n=i?.paymentMethods)!==null&&n!==void 0?n:[],hasSecretKey:!!i?.secretKey,hasWebhookSecret:!!i?.webhookSecret})}else return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}sanitizeIntegration(e){return p.parse(Object.assign(Object.assign({},e),{config:this.sanitizeConfig(e.type,e.config)}))}ensureOrganizationExists(e){return h(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:e,deletedAt:null},select:{id:!0}})))throw new a(404,"Organization not found")})}validateConfig(e,t,n){var i,r,o,d;switch(e){case"stripe":{const c=m.safeParse(t);if(!c.success)throw new a(400,(r=(i=c.error.issues[0])===null||i===void 0?void 0:i.message)!==null&&r!==void 0?r:"Invalid Stripe configuration");const s=this.parseStripeStoredConfig(n),l=(o=this.normalizeSecret(c.data.secretKey))!==null&&o!==void 0?o:s?.secretKey,u=(d=this.normalizeSecret(c.data.webhookSecret))!==null&&d!==void 0?d:s?.webhookSecret;if(!l)throw new a(400,"Stripe API key is required");if(!u)throw new a(400,"Stripe webhook secret is required");return{paymentMethods:this.normalizeStripePaymentMethods(c.data.paymentMethods),secretKey:l,webhookSecret:u}}default:throw new a(400,`Unsupported integration type: ${e}`)}}getIntegrations(e){return h(this,void 0,void 0,function*(){return yield this.ensureOrganizationExists(e),(yield this.prisma.integration.findMany({where:{organizationId:e},orderBy:{type:"asc"}})).map(n=>this.sanitizeIntegration(n))})}upsertIntegration(e,t,n,i){return h(this,void 0,void 0,function*(){yield this.ensureOrganizationExists(e);const r=yield this.prisma.integration.findUnique({where:{organizationId_type:{organizationId:e,type:t}}}),o=this.validateConfig(t,i.config,r?.config),d=yield this.prisma.integration.upsert({where:{organizationId_type:{organizationId:e,type:t}},update:{config:o,updatedBy:n},create:{organization:{connect:{id:e}},type:t,config:o,createdBy:n,updatedBy:n}});return this.sanitizeIntegration(d)})}deleteIntegration(e,t){return h(this,void 0,void 0,function*(){if(yield this.ensureOrganizationExists(e),(yield this.prisma.integration.deleteMany({where:{organizationId:e,type:t}})).count===0)throw new a(404,"Integration not found")})}}export{y as IntegrationService};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/integration/integration.service.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,mCAAmC,EAEnC,mCAAmC,GACpC,MAAM,sBAAsB,CAAC;AAE9B,MAAM,kBAAkB;IACtB,YAA6B,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;IAAG,CAAC;IAEjD,eAAe,CAAC,KAAc;QACpC,MAAM,UAAU,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,EAAE,CAAC;QACjC,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7C,CAAC;IAEO,6BAA6B,CAAC,OAAiB;QACrD,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,GAAG,CACL,OAAO,CAAC,MAAM,CACZ,CAAC,MAAM,EAA6B,EAAE,CACpC,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,MAAM,CACzC,CACF,CACF,CAAC;IACJ,CAAC;IAEO,uBAAuB,CAAC,MAAe;QAC7C,MAAM,MAAM,GAAG,mCAAmC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAErE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO;YACL,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc;gBACxC,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC;gBAChE,CAAC,CAAC,SAAS;YACb,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YACtD,aAAa,EAA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Ac;yBACnB;qBACF;oBACD,IAAI;oBACJ,MAAM;oBACN,SAAS,EAAE,MAAM;oBACjB,SAAS,EAAE,MAAM;iBAClB;aACF,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QAC/C,CAAC;KAAA;IAEY,iBAAiB,CAAC,cAAsB,EAAE,IAAY;;YACjE,MAAM,IAAI,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAC;YAEpD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC;gBACtD,KAAK,EAAE;oBACL,cAAc;oBACd,IAAI;iBACL;aACF,CAAC,CAAC;YAEH,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;gBACvB,MAAM,IAAI,aAAa,CAAC,GAAG,EAAE,uBAAuB,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;KAAA;CACF;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { PrismaClientType } from "../../core/lib/prisma";
|
|
2
|
+
import { NotificationOptions } from "../../core/notifications/notification-options";
|
|
2
3
|
import { PaymentServiceOptions } from "../payment/payment.service";
|
|
3
|
-
export declare const buildOrderHandler: (prisma: PrismaClientType, options: PaymentServiceOptions) => import("@hono/zod-openapi").OpenAPIHono<import("../../core/hono/hono").AppBindings, {}, "/">;
|
|
4
|
+
export declare const buildOrderHandler: (prisma: PrismaClientType, options: PaymentServiceOptions, notifications?: NotificationOptions) => import("@hono/zod-openapi").OpenAPIHono<import("../../core/hono/hono").AppBindings, {}, "/">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as
|
|
1
|
+
import{__awaiter as v}from"tslib";import{createApiRouter as y}from"../../core/hono/hono";import{orderRoute as c}from"./order.route";import{OrderService as l}from"./order.service";export const buildOrderHandler=(a,i,s={})=>{const n=y();return n.openapi(c.createOrder,e=>v(void 0,void 0,void 0,function*(){const t=e.get("auth"),r=e.req.valid("param"),d=e.req.valid("json"),o=yield t.getCurrentUser(),u=new l(a,i,s),{order:p,redirectUrl:g}=yield u.createOrder(r.organizationId,o,d);return e.json({order:p,redirectUrl:g},201)})),n.openapi(c.getMyOrders,e=>v(void 0,void 0,void 0,function*(){const t=e.get("auth"),r=e.req.valid("param"),d=e.req.valid("query"),o=yield t.getCurrentUser(),p=yield new l(a,i,s).getMyOrders(o.id,r.organizationId,d);return e.json(p,200)})),n.openapi(c.getOrder,e=>v(void 0,void 0,void 0,function*(){const t=e.get("auth"),r=e.req.valid("param"),d=yield t.getCurrentUser(),u=yield new l(a,i,s).getOrder(d,r.organizationId,r.id);return e.json(u,200)})),n.openapi(c.getOrders,e=>v(void 0,void 0,void 0,function*(){const t=e.get("auth"),r=e.req.valid("param"),d=e.req.valid("query");yield t.isGranted("read");const u=yield new l(a,i,s).getOrders(r.organizationId,d);return e.json(u,200)})),n.openapi(c.updateStatus,e=>v(void 0,void 0,void 0,function*(){const t=e.get("auth"),r=e.req.valid("param");yield t.isGranted("update");const o=yield new l(a,i,s).updateStatus(r.organizationId,r.id,r.operation);return e.json(o,200)})),n.openapi(c.deleteOrder,e=>v(void 0,void 0,void 0,function*(){const t=e.get("auth"),r=e.req.valid("param"),d=yield t.isGranted("delete");return yield new l(a,i,s).deleteOrder(r.organizationId,r.id,d.id),e.body(null,204)})),n};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.handler.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/order/order.handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"order.handler.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/order/order.handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD,OAAO,EAAE,UAAU,EAAE,MAAM,eA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M,OAAO,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QACjE,MAAM,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAErE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAA,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { z } from "@hono/zod-openapi";
|
|
2
2
|
import { PrismaClientType } from "../../core/lib/prisma";
|
|
3
|
+
import { NotificationOptions } from "../../core/notifications/notification-options";
|
|
3
4
|
import { CreateOrderSchema, OrderStatus, User } from "../../schemas";
|
|
4
5
|
import { PaymentServiceOptions } from "../payment/payment.service";
|
|
5
6
|
declare class OrderService {
|
|
6
7
|
private readonly prisma;
|
|
7
8
|
private readonly paymentOptions;
|
|
9
|
+
private readonly notificationOptions;
|
|
8
10
|
private paymentService;
|
|
9
|
-
constructor(prisma: PrismaClientType, paymentOptions: PaymentServiceOptions);
|
|
11
|
+
constructor(prisma: PrismaClientType, paymentOptions: PaymentServiceOptions, notificationOptions?: NotificationOptions);
|
|
10
12
|
/**
|
|
11
13
|
* Create a draft order
|
|
12
14
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as o}from"tslib";import{z as v}from"@hono/zod-openapi";import{customAlphabet as
|
|
1
|
+
import{__awaiter as o}from"tslib";import{z as v}from"@hono/zod-openapi";import{customAlphabet as U}from"nanoid";import{HttpException as u}from"../../core/exceptions/http-exception";import{OrderSchema as a,PaginationMetaSchema as w}from"../../schemas";import{transformCartItemToOrderItem as Z}from"../cart/cart.util";import{PaymentService as I}from"../payment/payment.service";const y=U("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ",6);class S{constructor(t,i,e={}){this.prisma=t,this.paymentOptions=i,this.notificationOptions=e,this.paymentService=new I(t,i,e)}createOrder(t,i,e){return o(this,void 0,void 0,function*(){var n,r,d,c,p;const l=yield this.prisma.organization.findFirst({where:{id:t},include:{configuration:!0}});if(!l)throw new u(404,"Organization not found");const h=yield this.prisma.address.findFirst({where:{users:{some:{id:i.id}},isDefault:!0}});if(e.fulfilmentMethod==="delivery"&&!h)throw new u(400,"This user does not have a default shipping address");const g=yield Promise.all(e.items.map(Z(this.prisma))),s=yield this.prisma.shippingMethod.findFirst({where:{id:e.shippingMethodId},include:{shippingZones:!0}}),A=(r=(n=s?.shippingZones[0])===null||n===void 0?void 0:n.price)!==null&&r!==void 0?r:0,f=g.reduce((k,D)=>k+D.totalPrice,0),O=f+A,m=yield this.prisma.order.create({data:Object.assign(Object.assign({token:y(),referenceId:y(),organization:{connect:{id:t}},fulfilmentMethod:e.fulfilmentMethod,shippingMethod:e.shippingMethodId?{connect:{id:e.shippingMethodId}}:void 0,currency:l.configuration.defaultCurrency,sourceIp:"127.0.0.1",items:{create:g}},h?{shippingAddress:{create:Object.assign(Object.assign({},h),{id:void 0})}}:{}),{user:{connect:{id:i.id}},payment:{create:{method:e.payment.method,provider:e.payment.provider,shipping:(c=(d=s?.shippingZones[0])===null||d===void 0?void 0:d.price)!==null&&c!==void 0?c:0,subtotal:f,total:O,discount:0,currency:l.configuration.defaultCurrency}}}),include:{items:{include:{translations:!0,image:!0}},payment:!0,shippingMethod:{include:{shippingZones:!0}}}}),M=a.parse(m);return{redirectUrl:(p=(yield this.paymentService.createCheckoutSession(t,i,M,{locale:"en",successUrl:`${e.checkoutBaseUrl}/account/orders/${m.id}?clearCart=true`,cancelUrl:`${e.checkoutBaseUrl}/checkout/shipping-and-payment`})).redirectUrl)!==null&&p!==void 0?p:void 0,order:a.parse(m)}})}getOrder(t,i,e){return o(this,void 0,void 0,function*(){const n=yield this.prisma.order.findUnique({where:{id:e,organizationId:i,deletedAt:null,user:{id:t.id}},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});if(!n)throw new u(404,"Order not found");return a.parse(n)})}getMyOrders(t,i,e){return o(this,void 0,void 0,function*(){const{page:n=1,limit:r=10,search:d}=e,[c,p]=yield this.prisma.order.paginate({where:Object.assign({organizationId:i,userId:t,deletedAt:null},d?{referenceId:{contains:d,mode:"insensitive"}}:{}),include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0},orderBy:{createdAt:"desc"}}).withPages({page:n,limit:r});return{meta:w.parse(p),list:v.array(a).parse(c)}})}getOrders(t,i){return o(this,void 0,void 0,function*(){const{page:e=1,limit:n=10}=i,[r,d]=yield this.prisma.order.paginate({where:{organizationId:t,deletedAt:null},include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0},orderBy:{createdAt:"desc"}}).withPages({page:e,limit:n});return{meta:w.parse(d),list:v.array(a).parse(r)}})}deleteOrder(t,i,e){return o(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:i,organizationId:t,deletedAt:null}})))throw new u(404,"Order not found");yield this.prisma.order.update({where:{id:i,organizationId:t,deletedAt:null},data:{deletedAt:new Date,deletedBy:e}})})}updateStatus(t,i,e){return o(this,void 0,void 0,function*(){if(!(yield this.prisma.order.findUnique({where:{id:i,organizationId:t,deletedAt:null},include:{items:!0,shippingMethod:{include:{shippingZones:!0}}}})))throw new u(404,"Order not found");let r={};switch(e){case"accepted":r={acceptedAt:new Date};break;case"ready-for-dispatch":r={readyForDispatchAt:new Date};break;case"dispatched":r={dispatchedAt:new Date};break;case"completed":r={completedAt:new Date};break;case"cancelled":r={cancelledAt:new Date};break}const d=yield this.prisma.order.update({where:{id:i},data:r,include:{items:{include:{translations:!0,image:!0}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}},payment:!0}});return a.parse(d)})}}export{S as OrderService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/order/order.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"order.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/order/order.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,OAAO,EAEL,WAAW,EAEX,oBAAoB,GAErB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,cAAc,GAEf,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,GAAG,cAAc,CAAC,sCAAsC,EAAE,CAAC,CAAC,CAAC;AAEzE,MAAM,YAAY;IAGhB,YACmB,MAAwB,EACxB,cAAqC,EACrC,sBAA2C,EAAE;QAF7C,WAAM,GAAN,MAAM,CAAkB;QACxB,mBAAc,GAAd,cAAc,CAAuB;QACrC,wBAAmB,GAAnB,mBAAmB,CAA0B;QAE9D,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CACtC,MAAM,EACN,cAAc,EACd,mBAAmB,CACpB,CAAC;IACJ,CAAC;IAED;;OAEG;IACU,WAAW,CACtB,cAAsB,EACtB,IAAU,EACV,IAAuC;;;YAEvC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC;gBAC5D,KAAK,EAAE;oBACL,EAAE,EAAE,cAAc;iBACnB;gBACD,OAAO,EAAE;oBACP,aAAa,EAAE,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AM;gBACR,KAAK,WAAW;oBACd,UAAU,GAAG;wBACX,WAAW,EAAE,IAAI,IAAI,EAAE;qBACxB,CAAC;oBACF,MAAM;YACV,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;gBAClD,KAAK,EAAE;oBACL,EAAE,EAAE,OAAO;iBACZ;gBACD,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE;oBACP,KAAK,EAAE;wBACL,OAAO,EAAE;4BACP,YAAY,EAAE,IAAI;4BAClB,KAAK,EAAE,IAAI;yBACZ;qBACF;oBACD,eAAe,EAAE,IAAI;oBACrB,cAAc,EAAE;wBACd,OAAO,EAAE;4BACP,aAAa,EAAE,IAAI;yBACpB;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd;aACF,CAAC,CAAC;YAEH,OAAO,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACzC,CAAC;KAAA;CACF;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as
|
|
1
|
+
import{__awaiter as l}from"tslib";import{z as p}from"@hono/zod-openapi";import{HttpException as T}from"../../core/exceptions/http-exception";import{OrganizationSchema as d,PaginationMetaSchema as h}from"../../schemas";import{LocationService as S}from"../location/location.service";class w{constructor(t,e){this.prisma=t,this.convertToTimeString=i=>i?i.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"UTC"}):"",this.locationService=new S(e)}getOrganizations(t,e){return l(this,void 0,void 0,function*(){const{page:i,limit:n}=e,[o,s]=yield this.prisma.organization.paginate({orderBy:{createdAt:"desc"},where:{members:{some:{userId:t}}},include:{address:!0,configuration:!0,logoFile:!0}}).withPages({page:i,limit:n});return{meta:h.parse(s),list:p.array(d).parse(o)}})}formatDateScheduleToTimeString(t){return t?["monday","tuesday","wednesday","thursday","friday","saturday","sunday"].reduce((i,n)=>(i[n]=this.convertToTimeString(t[n]),i),{}):null}getOrganization(t){return l(this,void 0,void 0,function*(){var e,i;const n=yield this.prisma.organization.findUnique({where:{id:t,deletedAt:null},include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});if(!n)throw new T(404,"Organization not found");const o=(()=>{if(!n.configuration.isAcceptingOrders||!n.configuration.openingTimes||!n.configuration.closingTimes)return!1;const s=new Date(new Date().toLocaleString("en-US",{timeZone:"Europe/Warsaw"})),u=s.toLocaleDateString("en-US",{weekday:"long"}).toLowerCase(),a=s.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"Europe/Warsaw"}),r=n.configuration.openingTimes[u],c=n.configuration.closingTimes[u];if(!r||!c)return!1;const m=this.convertToTimeString(r),f=this.convertToTimeString(c);return a>=m&&a<=f})();return d.parse(Object.assign(Object.assign({},n),{configuration:Object.assign(Object.assign({},n.configuration),{isOpen:o,openingTimes:(e=this.formatDateScheduleToTimeString(n.configuration.openingTimes))!==null&&e!==void 0?e:void 0,closingTimes:(i=this.formatDateScheduleToTimeString(n.configuration.closingTimes))!==null&&i!==void 0?i:void 0})}))})}createOrganization(t,e){return l(this,void 0,void 0,function*(){var i,n;const o=yield this.locationService.getPlaceDetails(e.address.placeId),s=yield this.prisma.organization.create({data:Object.assign({name:e.name,phone:e.phone,email:e.email,address:{create:Object.assign(Object.assign({},e.address),{latitude:o.latitude,longitude:o.longitude,createdBy:t})},configuration:{create:{countriesShipping:["us"],createdBy:t,enableHostCheckout:!1,enableHostTracking:!1,openingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null,sunday:null}},closingTimes:{create:{monday:null,tuesday:null,wednesday:null,thursday:null,friday:null,saturday:null}}}},members:{create:{user:{connect:{id:t}},role:"owner"}},createdBy:t},e.logoId?{logoFile:{connect:{id:e.logoId}}}:{}),include:{address:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}},logoFile:!0}});return d.parse(Object.assign(Object.assign({},s),{configuration:Object.assign(Object.assign({},s.configuration),{openingTimes:(i=this.formatDateScheduleToTimeString(s.configuration.openingTimes))!==null&&i!==void 0?i:void 0,closingTimes:(n=this.formatDateScheduleToTimeString(s.configuration.closingTimes))!==null&&n!==void 0?n:void 0})}))})}updateOrganization(t,e,i){return l(this,void 0,void 0,function*(){var n,o;if(!(yield this.prisma.organization.findUnique({where:{id:t,deletedAt:null}})))throw new T(404,"Organization not found");const u=i.address?yield this.locationService.getPlaceDetails(i.address.placeId):void 0,a=c=>{if(!c)return null;const[m,f]=c.split(":").map(Number),g=new Date;return g.setUTCHours(m),g.setUTCMinutes(f),g.setUTCSeconds(0),g.setUTCMilliseconds(0),g},r=yield this.prisma.organization.update({where:{id:t},data:Object.assign(Object.assign(Object.assign(Object.assign({name:i.name,phone:i.phone,email:i.email},i.logoId?{logoFile:{connect:{id:i.logoId}}}:{}),{address:i.address?{update:Object.assign(Object.assign({},i.address),{latitude:u.latitude,longitude:u.longitude,updatedBy:e})}:void 0}),i.configuration?{configuration:{update:{countriesShipping:i.configuration.countriesShipping,enableHostCheckout:i.configuration.enableHostCheckout,enableHostTracking:i.configuration.enableHostTracking,defaultLocale:i.configuration.defaultLocale,supportedLocales:i.configuration.supportedLocales,defaultCurrency:i.configuration.defaultCurrency,updatedBy:e,isAcceptingOrders:i.configuration.isAcceptingOrders,openingTimes:i.configuration.openingTimes?{update:{data:{monday:i.configuration.openingTimes.monday?a(i.configuration.openingTimes.monday):null,tuesday:i.configuration.openingTimes.tuesday?a(i.configuration.openingTimes.tuesday):null,wednesday:i.configuration.openingTimes.wednesday?a(i.configuration.openingTimes.wednesday):null,thursday:i.configuration.openingTimes.thursday?a(i.configuration.openingTimes.thursday):null,friday:i.configuration.openingTimes.friday?a(i.configuration.openingTimes.friday):null,saturday:i.configuration.openingTimes.saturday?a(i.configuration.openingTimes.saturday):null,sunday:i.configuration.openingTimes.sunday?a(i.configuration.openingTimes.sunday):null}}}:void 0,closingTimes:i.configuration.closingTimes?{update:{data:{monday:i.configuration.closingTimes.monday?a(i.configuration.closingTimes.monday):null,tuesday:i.configuration.closingTimes.tuesday?a(i.configuration.closingTimes.tuesday):null,wednesday:i.configuration.closingTimes.wednesday?a(i.configuration.closingTimes.wednesday):null,thursday:i.configuration.closingTimes.thursday?a(i.configuration.closingTimes.thursday):null,friday:i.configuration.closingTimes.friday?a(i.configuration.closingTimes.friday):null,saturday:i.configuration.closingTimes.saturday?a(i.configuration.closingTimes.saturday):null,sunday:i.configuration.closingTimes.sunday?a(i.configuration.closingTimes.sunday):null}}}:void 0}}}:void 0),{updatedBy:e}),include:{address:!0,logoFile:!0,configuration:{include:{openingTimes:!0,closingTimes:!0}}}});return d.parse(Object.assign(Object.assign({},r),{configuration:Object.assign(Object.assign({},r.configuration),{openingTimes:(n=this.formatDateScheduleToTimeString(r.configuration.openingTimes))!==null&&n!==void 0?n:void 0,closingTimes:(o=this.formatDateScheduleToTimeString(r.configuration.closingTimes))!==null&&o!==void 0?o:void 0})}))})}deleteOrganization(t,e){return l(this,void 0,void 0,function*(){if(!(yield this.prisma.organization.findUnique({where:{id:t}})))throw new T(404,"Organization not found");yield this.prisma.organization.update({where:{id:t},data:{deletedAt:new Date,deletedBy:e}})})}}export{w as OrganizationService};
|