@open-mercato/core 0.6.3-develop.3805.1.357827108c → 0.6.3-develop.3809.1.bde5459e65
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/auth/api/locale/route.js +36 -1
- package/dist/modules/auth/api/locale/route.js.map +2 -2
- package/dist/modules/customer_accounts/subscribers/search-reindex-created.js +37 -0
- package/dist/modules/customer_accounts/subscribers/search-reindex-created.js.map +7 -0
- package/dist/modules/customer_accounts/subscribers/search-reindex-deleted.js +35 -0
- package/dist/modules/customer_accounts/subscribers/search-reindex-deleted.js.map +7 -0
- package/dist/modules/customer_accounts/subscribers/search-reindex-updated.js +37 -0
- package/dist/modules/customer_accounts/subscribers/search-reindex-updated.js.map +7 -0
- package/package.json +7 -7
- package/src/modules/auth/api/locale/route.ts +36 -0
- package/src/modules/customer_accounts/subscribers/search-reindex-created.ts +42 -0
- package/src/modules/customer_accounts/subscribers/search-reindex-deleted.ts +40 -0
- package/src/modules/customer_accounts/subscribers/search-reindex-updated.ts +42 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { locales } from "@open-mercato/shared/lib/i18n/config";
|
|
3
4
|
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
4
5
|
import { sanitizeRedirectPath } from "@open-mercato/core/modules/auth/lib/safeRedirect";
|
|
5
6
|
import { getAppBaseUrl } from "@open-mercato/shared/lib/url";
|
|
6
7
|
const supportedLocales = new Set(locales);
|
|
8
|
+
const localeSchema = z.object({ locale: z.enum(locales) });
|
|
9
|
+
const localeQuerySchema = localeSchema.extend({
|
|
10
|
+
redirect: z.string().optional()
|
|
11
|
+
});
|
|
12
|
+
const localeResponseSchema = z.object({ ok: z.boolean() });
|
|
13
|
+
const localeErrorSchema = z.object({ error: z.string() });
|
|
7
14
|
const metadata = {
|
|
8
15
|
GET: { requireAuth: false },
|
|
9
16
|
POST: { requireAuth: false }
|
|
@@ -35,9 +42,37 @@ async function GET(req) {
|
|
|
35
42
|
res.cookies.set("locale", locale, { path: "/", maxAge: 60 * 60 * 24 * 365 });
|
|
36
43
|
return res;
|
|
37
44
|
}
|
|
45
|
+
const openApi = {
|
|
46
|
+
tag: "Authentication & Accounts",
|
|
47
|
+
summary: "Locale preference",
|
|
48
|
+
methods: {
|
|
49
|
+
GET: {
|
|
50
|
+
summary: "Set locale and redirect",
|
|
51
|
+
description: "Stores the selected locale in a cookie and redirects to a safe local path.",
|
|
52
|
+
query: localeQuerySchema,
|
|
53
|
+
responses: [
|
|
54
|
+
{ status: 302, description: "Locale cookie set and request redirected" },
|
|
55
|
+
{ status: 400, description: "Invalid locale", schema: localeErrorSchema }
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
POST: {
|
|
59
|
+
summary: "Set locale",
|
|
60
|
+
description: "Stores the selected locale in a cookie and returns a JSON success response.",
|
|
61
|
+
requestBody: {
|
|
62
|
+
contentType: "application/json",
|
|
63
|
+
schema: localeSchema
|
|
64
|
+
},
|
|
65
|
+
responses: [
|
|
66
|
+
{ status: 200, description: "Locale cookie set", schema: localeResponseSchema },
|
|
67
|
+
{ status: 400, description: "Invalid locale or malformed request body", schema: localeErrorSchema }
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
38
72
|
export {
|
|
39
73
|
GET,
|
|
40
74
|
POST,
|
|
41
|
-
metadata
|
|
75
|
+
metadata,
|
|
76
|
+
openApi
|
|
42
77
|
};
|
|
43
78
|
//# sourceMappingURL=route.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/auth/api/locale/route.ts"],
|
|
4
|
-
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { locales, type Locale } from '@open-mercato/shared/lib/i18n/config'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { sanitizeRedirectPath } from '@open-mercato/core/modules/auth/lib/safeRedirect'\nimport { getAppBaseUrl } from '@open-mercato/shared/lib/url'\n\nconst supportedLocales = new Set<Locale>(locales)\n\nexport const metadata = {\n GET: { requireAuth: false },\n POST: { requireAuth: false },\n}\n\nexport async function POST(req: Request) {\n const { t } = await resolveTranslations()\n try {\n const { locale } = await req.json()\n if (typeof locale !== 'string' || !supportedLocales.has(locale as Locale)) {\n return NextResponse.json({ error: t('api.errors.invalidLocale', 'Invalid locale') }, { status: 400 })\n }\n const res = NextResponse.json({ ok: true })\n res.cookies.set('locale', locale as Locale, { path: '/', maxAge: 60 * 60 * 24 * 365 })\n return res\n } catch {\n return NextResponse.json({ error: t('api.errors.badRequest', 'Bad request') }, { status: 400 })\n }\n}\n\nexport async function GET(req: Request) {\n const { t } = await resolveTranslations()\n const url = new URL(req.url)\n const locale = url.searchParams.get('locale')\n if (!locale || !supportedLocales.has(locale as Locale)) {\n return NextResponse.json({ error: t('api.errors.invalidLocale', 'Invalid locale') }, { status: 400 })\n }\n const baseUrl = getAppBaseUrl(req)\n const safePath = sanitizeRedirectPath(url.searchParams.get('redirect'), baseUrl, '/')\n const res = NextResponse.redirect(new URL(safePath, url.origin))\n res.cookies.set('locale', locale as Locale, { path: '/', maxAge: 60 * 60 * 24 * 365 })\n return res\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,eAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAE9B,MAAM,mBAAmB,IAAI,IAAY,OAAO;
|
|
4
|
+
"sourcesContent": ["import { NextResponse } from 'next/server'\nimport { z } from 'zod'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { locales, type Locale } from '@open-mercato/shared/lib/i18n/config'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { sanitizeRedirectPath } from '@open-mercato/core/modules/auth/lib/safeRedirect'\nimport { getAppBaseUrl } from '@open-mercato/shared/lib/url'\n\nconst supportedLocales = new Set<Locale>(locales)\nconst localeSchema = z.object({ locale: z.enum(locales as [Locale, ...Locale[]]) })\nconst localeQuerySchema = localeSchema.extend({\n redirect: z.string().optional(),\n})\nconst localeResponseSchema = z.object({ ok: z.boolean() })\nconst localeErrorSchema = z.object({ error: z.string() })\n\nexport const metadata = {\n GET: { requireAuth: false },\n POST: { requireAuth: false },\n}\n\nexport async function POST(req: Request) {\n const { t } = await resolveTranslations()\n try {\n const { locale } = await req.json()\n if (typeof locale !== 'string' || !supportedLocales.has(locale as Locale)) {\n return NextResponse.json({ error: t('api.errors.invalidLocale', 'Invalid locale') }, { status: 400 })\n }\n const res = NextResponse.json({ ok: true })\n res.cookies.set('locale', locale as Locale, { path: '/', maxAge: 60 * 60 * 24 * 365 })\n return res\n } catch {\n return NextResponse.json({ error: t('api.errors.badRequest', 'Bad request') }, { status: 400 })\n }\n}\n\nexport async function GET(req: Request) {\n const { t } = await resolveTranslations()\n const url = new URL(req.url)\n const locale = url.searchParams.get('locale')\n if (!locale || !supportedLocales.has(locale as Locale)) {\n return NextResponse.json({ error: t('api.errors.invalidLocale', 'Invalid locale') }, { status: 400 })\n }\n const baseUrl = getAppBaseUrl(req)\n const safePath = sanitizeRedirectPath(url.searchParams.get('redirect'), baseUrl, '/')\n const res = NextResponse.redirect(new URL(safePath, url.origin))\n res.cookies.set('locale', locale as Locale, { path: '/', maxAge: 60 * 60 * 24 * 365 })\n return res\n}\n\nexport const openApi: OpenApiRouteDoc = {\n tag: 'Authentication & Accounts',\n summary: 'Locale preference',\n methods: {\n GET: {\n summary: 'Set locale and redirect',\n description: 'Stores the selected locale in a cookie and redirects to a safe local path.',\n query: localeQuerySchema,\n responses: [\n { status: 302, description: 'Locale cookie set and request redirected' },\n { status: 400, description: 'Invalid locale', schema: localeErrorSchema },\n ],\n },\n POST: {\n summary: 'Set locale',\n description: 'Stores the selected locale in a cookie and returns a JSON success response.',\n requestBody: {\n contentType: 'application/json',\n schema: localeSchema,\n },\n responses: [\n { status: 200, description: 'Locale cookie set', schema: localeResponseSchema },\n { status: 400, description: 'Invalid locale or malformed request body', schema: localeErrorSchema },\n ],\n },\n },\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAElB,SAAS,eAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAE9B,MAAM,mBAAmB,IAAI,IAAY,OAAO;AAChD,MAAM,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,OAAgC,EAAE,CAAC;AAClF,MAAM,oBAAoB,aAAa,OAAO;AAAA,EAC5C,UAAU,EAAE,OAAO,EAAE,SAAS;AAChC,CAAC;AACD,MAAM,uBAAuB,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AACzD,MAAM,oBAAoB,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAEjD,MAAM,WAAW;AAAA,EACtB,KAAK,EAAE,aAAa,MAAM;AAAA,EAC1B,MAAM,EAAE,aAAa,MAAM;AAC7B;AAEA,eAAsB,KAAK,KAAc;AACvC,QAAM,EAAE,EAAE,IAAI,MAAM,oBAAoB;AACxC,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,IAAI,KAAK;AAClC,QAAI,OAAO,WAAW,YAAY,CAAC,iBAAiB,IAAI,MAAgB,GAAG;AACzE,aAAO,aAAa,KAAK,EAAE,OAAO,EAAE,4BAA4B,gBAAgB,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IACtG;AACA,UAAM,MAAM,aAAa,KAAK,EAAE,IAAI,KAAK,CAAC;AAC1C,QAAI,QAAQ,IAAI,UAAU,QAAkB,EAAE,MAAM,KAAK,QAAQ,KAAK,KAAK,KAAK,IAAI,CAAC;AACrF,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,aAAa,KAAK,EAAE,OAAO,EAAE,yBAAyB,aAAa,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAChG;AACF;AAEA,eAAsB,IAAI,KAAc;AACtC,QAAM,EAAE,EAAE,IAAI,MAAM,oBAAoB;AACxC,QAAM,MAAM,IAAI,IAAI,IAAI,GAAG;AAC3B,QAAM,SAAS,IAAI,aAAa,IAAI,QAAQ;AAC5C,MAAI,CAAC,UAAU,CAAC,iBAAiB,IAAI,MAAgB,GAAG;AACtD,WAAO,aAAa,KAAK,EAAE,OAAO,EAAE,4BAA4B,gBAAgB,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtG;AACA,QAAM,UAAU,cAAc,GAAG;AACjC,QAAM,WAAW,qBAAqB,IAAI,aAAa,IAAI,UAAU,GAAG,SAAS,GAAG;AACpF,QAAM,MAAM,aAAa,SAAS,IAAI,IAAI,UAAU,IAAI,MAAM,CAAC;AAC/D,MAAI,QAAQ,IAAI,UAAU,QAAkB,EAAE,MAAM,KAAK,QAAQ,KAAK,KAAK,KAAK,IAAI,CAAC;AACrF,SAAO;AACT;AAEO,MAAM,UAA2B;AAAA,EACtC,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS;AAAA,IACP,KAAK;AAAA,MACH,SAAS;AAAA,MACT,aAAa;AAAA,MACb,OAAO;AAAA,MACP,WAAW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,2CAA2C;AAAA,QACvE,EAAE,QAAQ,KAAK,aAAa,kBAAkB,QAAQ,kBAAkB;AAAA,MAC1E;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,SAAS;AAAA,MACT,aAAa;AAAA,MACb,aAAa;AAAA,QACX,aAAa;AAAA,QACb,QAAQ;AAAA,MACV;AAAA,MACA,WAAW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,qBAAqB,QAAQ,qBAAqB;AAAA,QAC9E,EAAE,QAAQ,KAAK,aAAa,4CAA4C,QAAQ,kBAAkB;AAAA,MACpG;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const metadata = {
|
|
2
|
+
event: "customer_accounts.user.created",
|
|
3
|
+
persistent: false,
|
|
4
|
+
id: "customer_accounts:query-index-reindex-created"
|
|
5
|
+
};
|
|
6
|
+
async function handle(payload, ctx) {
|
|
7
|
+
const userId = typeof payload?.id === "string" ? payload.id : null;
|
|
8
|
+
const tenantId = typeof payload?.tenantId === "string" ? payload.tenantId : null;
|
|
9
|
+
if (!userId || !tenantId) return;
|
|
10
|
+
let bus = null;
|
|
11
|
+
try {
|
|
12
|
+
bus = ctx.resolve("eventBus");
|
|
13
|
+
} catch {
|
|
14
|
+
bus = null;
|
|
15
|
+
}
|
|
16
|
+
if (!bus) return;
|
|
17
|
+
await bus.emitEvent(
|
|
18
|
+
"query_index.upsert_one",
|
|
19
|
+
{
|
|
20
|
+
entityType: "customer_accounts:customer_user",
|
|
21
|
+
recordId: userId,
|
|
22
|
+
organizationId: payload.organizationId ?? null,
|
|
23
|
+
tenantId,
|
|
24
|
+
crudAction: "created",
|
|
25
|
+
coverageBaseDelta: 1
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
tenantId,
|
|
29
|
+
organizationId: payload.organizationId ?? null
|
|
30
|
+
}
|
|
31
|
+
).catch(() => void 0);
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
handle as default,
|
|
35
|
+
metadata
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=search-reindex-created.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/customer_accounts/subscribers/search-reindex-created.ts"],
|
|
4
|
+
"sourcesContent": ["export const metadata = {\n event: 'customer_accounts.user.created',\n persistent: false,\n id: 'customer_accounts:query-index-reindex-created',\n}\n\ntype Payload = {\n id?: string\n tenantId?: string | null\n organizationId?: string | null\n}\n\ntype EventBus = { emitEvent: (name: string, body: unknown, options?: unknown) => Promise<void> }\ntype HandlerContext = { resolve: <T = unknown>(name: string) => T }\n\nexport default async function handle(payload: Payload, ctx: HandlerContext) {\n const userId = typeof payload?.id === 'string' ? payload.id : null\n const tenantId = typeof payload?.tenantId === 'string' ? payload.tenantId : null\n if (!userId || !tenantId) return\n let bus: EventBus | null = null\n try {\n bus = ctx.resolve<EventBus>('eventBus')\n } catch {\n bus = null\n }\n if (!bus) return\n await bus.emitEvent(\n 'query_index.upsert_one',\n {\n entityType: 'customer_accounts:customer_user',\n recordId: userId,\n organizationId: payload.organizationId ?? null,\n tenantId,\n crudAction: 'created',\n coverageBaseDelta: 1,\n },\n {\n tenantId,\n organizationId: payload.organizationId ?? null,\n },\n ).catch(() => undefined)\n}"],
|
|
5
|
+
"mappings": "AAAO,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,IAAI;AACN;AAWA,eAAO,OAA8B,SAAkB,KAAqB;AAC1E,QAAM,SAAS,OAAO,SAAS,OAAO,WAAW,QAAQ,KAAK;AAC9D,QAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,WAAW;AAC5E,MAAI,CAAC,UAAU,CAAC,SAAU;AAC1B,MAAI,MAAuB;AAC3B,MAAI;AACF,UAAM,IAAI,QAAkB,UAAU;AAAA,EACxC,QAAQ;AACN,UAAM;AAAA,EACR;AACA,MAAI,CAAC,IAAK;AACV,QAAM,IAAI;AAAA,IACR;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,gBAAgB,QAAQ,kBAAkB;AAAA,MAC1C;AAAA,MACA,YAAY;AAAA,MACZ,mBAAmB;AAAA,IACrB;AAAA,IACA;AAAA,MACE;AAAA,MACA,gBAAgB,QAAQ,kBAAkB;AAAA,IAC5C;AAAA,EACF,EAAE,MAAM,MAAM,MAAS;AACzB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const metadata = {
|
|
2
|
+
event: "customer_accounts.user.deleted",
|
|
3
|
+
persistent: false,
|
|
4
|
+
id: "customer_accounts:query-index-reindex-deleted"
|
|
5
|
+
};
|
|
6
|
+
async function handle(payload, ctx) {
|
|
7
|
+
const userId = typeof payload?.id === "string" ? payload.id : null;
|
|
8
|
+
const tenantId = typeof payload?.tenantId === "string" ? payload.tenantId : null;
|
|
9
|
+
if (!userId || !tenantId) return;
|
|
10
|
+
let bus = null;
|
|
11
|
+
try {
|
|
12
|
+
bus = ctx.resolve("eventBus");
|
|
13
|
+
} catch {
|
|
14
|
+
bus = null;
|
|
15
|
+
}
|
|
16
|
+
if (!bus) return;
|
|
17
|
+
await bus.emitEvent(
|
|
18
|
+
"query_index.delete_one",
|
|
19
|
+
{
|
|
20
|
+
entityType: "customer_accounts:customer_user",
|
|
21
|
+
recordId: userId,
|
|
22
|
+
organizationId: payload.organizationId ?? null,
|
|
23
|
+
tenantId
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
tenantId,
|
|
27
|
+
organizationId: payload.organizationId ?? null
|
|
28
|
+
}
|
|
29
|
+
).catch(() => void 0);
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
handle as default,
|
|
33
|
+
metadata
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=search-reindex-deleted.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/customer_accounts/subscribers/search-reindex-deleted.ts"],
|
|
4
|
+
"sourcesContent": ["export const metadata = {\n event: 'customer_accounts.user.deleted',\n persistent: false,\n id: 'customer_accounts:query-index-reindex-deleted',\n}\n\ntype Payload = {\n id?: string\n tenantId?: string | null\n organizationId?: string | null\n}\n\ntype EventBus = { emitEvent: (name: string, body: unknown, options?: unknown) => Promise<void> }\ntype HandlerContext = { resolve: <T = unknown>(name: string) => T }\n\nexport default async function handle(payload: Payload, ctx: HandlerContext) {\n const userId = typeof payload?.id === 'string' ? payload.id : null\n const tenantId = typeof payload?.tenantId === 'string' ? payload.tenantId : null\n if (!userId || !tenantId) return\n let bus: EventBus | null = null\n try {\n bus = ctx.resolve<EventBus>('eventBus')\n } catch {\n bus = null\n }\n if (!bus) return\n await bus.emitEvent(\n 'query_index.delete_one',\n {\n entityType: 'customer_accounts:customer_user',\n recordId: userId,\n organizationId: payload.organizationId ?? null,\n tenantId,\n },\n {\n tenantId,\n organizationId: payload.organizationId ?? null,\n },\n ).catch(() => undefined)\n}"],
|
|
5
|
+
"mappings": "AAAO,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,IAAI;AACN;AAWA,eAAO,OAA8B,SAAkB,KAAqB;AAC1E,QAAM,SAAS,OAAO,SAAS,OAAO,WAAW,QAAQ,KAAK;AAC9D,QAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,WAAW;AAC5E,MAAI,CAAC,UAAU,CAAC,SAAU;AAC1B,MAAI,MAAuB;AAC3B,MAAI;AACF,UAAM,IAAI,QAAkB,UAAU;AAAA,EACxC,QAAQ;AACN,UAAM;AAAA,EACR;AACA,MAAI,CAAC,IAAK;AACV,QAAM,IAAI;AAAA,IACR;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,gBAAgB,QAAQ,kBAAkB;AAAA,MAC1C;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA,gBAAgB,QAAQ,kBAAkB;AAAA,IAC5C;AAAA,EACF,EAAE,MAAM,MAAM,MAAS;AACzB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const metadata = {
|
|
2
|
+
event: "customer_accounts.user.updated",
|
|
3
|
+
persistent: false,
|
|
4
|
+
id: "customer_accounts:query-index-reindex-updated"
|
|
5
|
+
};
|
|
6
|
+
async function handle(payload, ctx) {
|
|
7
|
+
const userId = typeof payload?.id === "string" ? payload.id : null;
|
|
8
|
+
const tenantId = typeof payload?.tenantId === "string" ? payload.tenantId : null;
|
|
9
|
+
if (!userId || !tenantId) return;
|
|
10
|
+
let bus = null;
|
|
11
|
+
try {
|
|
12
|
+
bus = ctx.resolve("eventBus");
|
|
13
|
+
} catch {
|
|
14
|
+
bus = null;
|
|
15
|
+
}
|
|
16
|
+
if (!bus) return;
|
|
17
|
+
await bus.emitEvent(
|
|
18
|
+
"query_index.upsert_one",
|
|
19
|
+
{
|
|
20
|
+
entityType: "customer_accounts:customer_user",
|
|
21
|
+
recordId: userId,
|
|
22
|
+
organizationId: payload.organizationId ?? null,
|
|
23
|
+
tenantId,
|
|
24
|
+
crudAction: "updated",
|
|
25
|
+
coverageBaseDelta: 0
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
tenantId,
|
|
29
|
+
organizationId: payload.organizationId ?? null
|
|
30
|
+
}
|
|
31
|
+
).catch(() => void 0);
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
handle as default,
|
|
35
|
+
metadata
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=search-reindex-updated.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/customer_accounts/subscribers/search-reindex-updated.ts"],
|
|
4
|
+
"sourcesContent": ["export const metadata = {\n event: 'customer_accounts.user.updated',\n persistent: false,\n id: 'customer_accounts:query-index-reindex-updated',\n}\n\ntype Payload = {\n id?: string\n tenantId?: string | null\n organizationId?: string | null\n}\n\ntype EventBus = { emitEvent: (name: string, body: unknown, options?: unknown) => Promise<void> }\ntype HandlerContext = { resolve: <T = unknown>(name: string) => T }\n\nexport default async function handle(payload: Payload, ctx: HandlerContext) {\n const userId = typeof payload?.id === 'string' ? payload.id : null\n const tenantId = typeof payload?.tenantId === 'string' ? payload.tenantId : null\n if (!userId || !tenantId) return\n let bus: EventBus | null = null\n try {\n bus = ctx.resolve<EventBus>('eventBus')\n } catch {\n bus = null\n }\n if (!bus) return\n await bus.emitEvent(\n 'query_index.upsert_one',\n {\n entityType: 'customer_accounts:customer_user',\n recordId: userId,\n organizationId: payload.organizationId ?? null,\n tenantId,\n crudAction: 'updated',\n coverageBaseDelta: 0,\n },\n {\n tenantId,\n organizationId: payload.organizationId ?? null,\n },\n ).catch(() => undefined)\n}"],
|
|
5
|
+
"mappings": "AAAO,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,IAAI;AACN;AAWA,eAAO,OAA8B,SAAkB,KAAqB;AAC1E,QAAM,SAAS,OAAO,SAAS,OAAO,WAAW,QAAQ,KAAK;AAC9D,QAAM,WAAW,OAAO,SAAS,aAAa,WAAW,QAAQ,WAAW;AAC5E,MAAI,CAAC,UAAU,CAAC,SAAU;AAC1B,MAAI,MAAuB;AAC3B,MAAI;AACF,UAAM,IAAI,QAAkB,UAAU;AAAA,EACxC,QAAQ;AACN,UAAM;AAAA,EACR;AACA,MAAI,CAAC,IAAK;AACV,QAAM,IAAI;AAAA,IACR;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,gBAAgB,QAAQ,kBAAkB;AAAA,MAC1C;AAAA,MACA,YAAY;AAAA,MACZ,mBAAmB;AAAA,IACrB;AAAA,IACA;AAAA,MACE;AAAA,MACA,gBAAgB,QAAQ,kBAAkB;AAAA,IAC5C;AAAA,EACF,EAAE,MAAM,MAAM,MAAS;AACzB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/core",
|
|
3
|
-
"version": "0.6.3-develop.
|
|
3
|
+
"version": "0.6.3-develop.3809.1.bde5459e65",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -243,16 +243,16 @@
|
|
|
243
243
|
"zod": "^4.4.3"
|
|
244
244
|
},
|
|
245
245
|
"peerDependencies": {
|
|
246
|
-
"@open-mercato/ai-assistant": "0.6.3-develop.
|
|
247
|
-
"@open-mercato/shared": "0.6.3-develop.
|
|
248
|
-
"@open-mercato/ui": "0.6.3-develop.
|
|
246
|
+
"@open-mercato/ai-assistant": "0.6.3-develop.3809.1.bde5459e65",
|
|
247
|
+
"@open-mercato/shared": "0.6.3-develop.3809.1.bde5459e65",
|
|
248
|
+
"@open-mercato/ui": "0.6.3-develop.3809.1.bde5459e65",
|
|
249
249
|
"react": "^19.0.0",
|
|
250
250
|
"react-dom": "^19.0.0"
|
|
251
251
|
},
|
|
252
252
|
"devDependencies": {
|
|
253
|
-
"@open-mercato/ai-assistant": "0.6.3-develop.
|
|
254
|
-
"@open-mercato/shared": "0.6.3-develop.
|
|
255
|
-
"@open-mercato/ui": "0.6.3-develop.
|
|
253
|
+
"@open-mercato/ai-assistant": "0.6.3-develop.3809.1.bde5459e65",
|
|
254
|
+
"@open-mercato/shared": "0.6.3-develop.3809.1.bde5459e65",
|
|
255
|
+
"@open-mercato/ui": "0.6.3-develop.3809.1.bde5459e65",
|
|
256
256
|
"@testing-library/dom": "^10.4.1",
|
|
257
257
|
"@testing-library/jest-dom": "^6.9.1",
|
|
258
258
|
"@testing-library/react": "^16.3.1",
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
2
4
|
import { locales, type Locale } from '@open-mercato/shared/lib/i18n/config'
|
|
3
5
|
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
4
6
|
import { sanitizeRedirectPath } from '@open-mercato/core/modules/auth/lib/safeRedirect'
|
|
5
7
|
import { getAppBaseUrl } from '@open-mercato/shared/lib/url'
|
|
6
8
|
|
|
7
9
|
const supportedLocales = new Set<Locale>(locales)
|
|
10
|
+
const localeSchema = z.object({ locale: z.enum(locales as [Locale, ...Locale[]]) })
|
|
11
|
+
const localeQuerySchema = localeSchema.extend({
|
|
12
|
+
redirect: z.string().optional(),
|
|
13
|
+
})
|
|
14
|
+
const localeResponseSchema = z.object({ ok: z.boolean() })
|
|
15
|
+
const localeErrorSchema = z.object({ error: z.string() })
|
|
8
16
|
|
|
9
17
|
export const metadata = {
|
|
10
18
|
GET: { requireAuth: false },
|
|
@@ -39,3 +47,31 @@ export async function GET(req: Request) {
|
|
|
39
47
|
res.cookies.set('locale', locale as Locale, { path: '/', maxAge: 60 * 60 * 24 * 365 })
|
|
40
48
|
return res
|
|
41
49
|
}
|
|
50
|
+
|
|
51
|
+
export const openApi: OpenApiRouteDoc = {
|
|
52
|
+
tag: 'Authentication & Accounts',
|
|
53
|
+
summary: 'Locale preference',
|
|
54
|
+
methods: {
|
|
55
|
+
GET: {
|
|
56
|
+
summary: 'Set locale and redirect',
|
|
57
|
+
description: 'Stores the selected locale in a cookie and redirects to a safe local path.',
|
|
58
|
+
query: localeQuerySchema,
|
|
59
|
+
responses: [
|
|
60
|
+
{ status: 302, description: 'Locale cookie set and request redirected' },
|
|
61
|
+
{ status: 400, description: 'Invalid locale', schema: localeErrorSchema },
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
POST: {
|
|
65
|
+
summary: 'Set locale',
|
|
66
|
+
description: 'Stores the selected locale in a cookie and returns a JSON success response.',
|
|
67
|
+
requestBody: {
|
|
68
|
+
contentType: 'application/json',
|
|
69
|
+
schema: localeSchema,
|
|
70
|
+
},
|
|
71
|
+
responses: [
|
|
72
|
+
{ status: 200, description: 'Locale cookie set', schema: localeResponseSchema },
|
|
73
|
+
{ status: 400, description: 'Invalid locale or malformed request body', schema: localeErrorSchema },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
event: 'customer_accounts.user.created',
|
|
3
|
+
persistent: false,
|
|
4
|
+
id: 'customer_accounts:query-index-reindex-created',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type Payload = {
|
|
8
|
+
id?: string
|
|
9
|
+
tenantId?: string | null
|
|
10
|
+
organizationId?: string | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type EventBus = { emitEvent: (name: string, body: unknown, options?: unknown) => Promise<void> }
|
|
14
|
+
type HandlerContext = { resolve: <T = unknown>(name: string) => T }
|
|
15
|
+
|
|
16
|
+
export default async function handle(payload: Payload, ctx: HandlerContext) {
|
|
17
|
+
const userId = typeof payload?.id === 'string' ? payload.id : null
|
|
18
|
+
const tenantId = typeof payload?.tenantId === 'string' ? payload.tenantId : null
|
|
19
|
+
if (!userId || !tenantId) return
|
|
20
|
+
let bus: EventBus | null = null
|
|
21
|
+
try {
|
|
22
|
+
bus = ctx.resolve<EventBus>('eventBus')
|
|
23
|
+
} catch {
|
|
24
|
+
bus = null
|
|
25
|
+
}
|
|
26
|
+
if (!bus) return
|
|
27
|
+
await bus.emitEvent(
|
|
28
|
+
'query_index.upsert_one',
|
|
29
|
+
{
|
|
30
|
+
entityType: 'customer_accounts:customer_user',
|
|
31
|
+
recordId: userId,
|
|
32
|
+
organizationId: payload.organizationId ?? null,
|
|
33
|
+
tenantId,
|
|
34
|
+
crudAction: 'created',
|
|
35
|
+
coverageBaseDelta: 1,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
tenantId,
|
|
39
|
+
organizationId: payload.organizationId ?? null,
|
|
40
|
+
},
|
|
41
|
+
).catch(() => undefined)
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
event: 'customer_accounts.user.deleted',
|
|
3
|
+
persistent: false,
|
|
4
|
+
id: 'customer_accounts:query-index-reindex-deleted',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type Payload = {
|
|
8
|
+
id?: string
|
|
9
|
+
tenantId?: string | null
|
|
10
|
+
organizationId?: string | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type EventBus = { emitEvent: (name: string, body: unknown, options?: unknown) => Promise<void> }
|
|
14
|
+
type HandlerContext = { resolve: <T = unknown>(name: string) => T }
|
|
15
|
+
|
|
16
|
+
export default async function handle(payload: Payload, ctx: HandlerContext) {
|
|
17
|
+
const userId = typeof payload?.id === 'string' ? payload.id : null
|
|
18
|
+
const tenantId = typeof payload?.tenantId === 'string' ? payload.tenantId : null
|
|
19
|
+
if (!userId || !tenantId) return
|
|
20
|
+
let bus: EventBus | null = null
|
|
21
|
+
try {
|
|
22
|
+
bus = ctx.resolve<EventBus>('eventBus')
|
|
23
|
+
} catch {
|
|
24
|
+
bus = null
|
|
25
|
+
}
|
|
26
|
+
if (!bus) return
|
|
27
|
+
await bus.emitEvent(
|
|
28
|
+
'query_index.delete_one',
|
|
29
|
+
{
|
|
30
|
+
entityType: 'customer_accounts:customer_user',
|
|
31
|
+
recordId: userId,
|
|
32
|
+
organizationId: payload.organizationId ?? null,
|
|
33
|
+
tenantId,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
tenantId,
|
|
37
|
+
organizationId: payload.organizationId ?? null,
|
|
38
|
+
},
|
|
39
|
+
).catch(() => undefined)
|
|
40
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const metadata = {
|
|
2
|
+
event: 'customer_accounts.user.updated',
|
|
3
|
+
persistent: false,
|
|
4
|
+
id: 'customer_accounts:query-index-reindex-updated',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type Payload = {
|
|
8
|
+
id?: string
|
|
9
|
+
tenantId?: string | null
|
|
10
|
+
organizationId?: string | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type EventBus = { emitEvent: (name: string, body: unknown, options?: unknown) => Promise<void> }
|
|
14
|
+
type HandlerContext = { resolve: <T = unknown>(name: string) => T }
|
|
15
|
+
|
|
16
|
+
export default async function handle(payload: Payload, ctx: HandlerContext) {
|
|
17
|
+
const userId = typeof payload?.id === 'string' ? payload.id : null
|
|
18
|
+
const tenantId = typeof payload?.tenantId === 'string' ? payload.tenantId : null
|
|
19
|
+
if (!userId || !tenantId) return
|
|
20
|
+
let bus: EventBus | null = null
|
|
21
|
+
try {
|
|
22
|
+
bus = ctx.resolve<EventBus>('eventBus')
|
|
23
|
+
} catch {
|
|
24
|
+
bus = null
|
|
25
|
+
}
|
|
26
|
+
if (!bus) return
|
|
27
|
+
await bus.emitEvent(
|
|
28
|
+
'query_index.upsert_one',
|
|
29
|
+
{
|
|
30
|
+
entityType: 'customer_accounts:customer_user',
|
|
31
|
+
recordId: userId,
|
|
32
|
+
organizationId: payload.organizationId ?? null,
|
|
33
|
+
tenantId,
|
|
34
|
+
crudAction: 'updated',
|
|
35
|
+
coverageBaseDelta: 0,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
tenantId,
|
|
39
|
+
organizationId: payload.organizationId ?? null,
|
|
40
|
+
},
|
|
41
|
+
).catch(() => undefined)
|
|
42
|
+
}
|