@shopware-ag/app-server-sdk 1.1.15 → 1.1.17

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.
Files changed (39) hide show
  1. package/dist/commonjs/helper/admin-api.d.ts +27 -3
  2. package/dist/commonjs/helper/admin-api.d.ts.map +1 -1
  3. package/dist/commonjs/helper/admin-api.js +24 -0
  4. package/dist/commonjs/helper/admin-api.js.map +1 -1
  5. package/dist/commonjs/helper/criteria.d.ts +19 -3
  6. package/dist/commonjs/helper/criteria.d.ts.map +1 -1
  7. package/dist/commonjs/helper/criteria.js +2 -9
  8. package/dist/commonjs/helper/criteria.js.map +1 -1
  9. package/dist/commonjs/integration/dynamodb.d.ts.map +1 -1
  10. package/dist/commonjs/integration/dynamodb.js +12 -8
  11. package/dist/commonjs/integration/dynamodb.js.map +1 -1
  12. package/dist/commonjs/integration/hono.d.ts +1 -1
  13. package/dist/commonjs/integration/hono.d.ts.map +1 -1
  14. package/dist/commonjs/integration/hono.js +4 -0
  15. package/dist/commonjs/integration/hono.js.map +1 -1
  16. package/dist/commonjs/registration.d.ts +3 -3
  17. package/dist/commonjs/registration.d.ts.map +1 -1
  18. package/dist/commonjs/registration.js +8 -7
  19. package/dist/commonjs/registration.js.map +1 -1
  20. package/dist/esm/helper/admin-api.d.ts +27 -3
  21. package/dist/esm/helper/admin-api.d.ts.map +1 -1
  22. package/dist/esm/helper/admin-api.js +24 -0
  23. package/dist/esm/helper/admin-api.js.map +1 -1
  24. package/dist/esm/helper/criteria.d.ts +19 -3
  25. package/dist/esm/helper/criteria.d.ts.map +1 -1
  26. package/dist/esm/helper/criteria.js +2 -9
  27. package/dist/esm/helper/criteria.js.map +1 -1
  28. package/dist/esm/integration/dynamodb.d.ts.map +1 -1
  29. package/dist/esm/integration/dynamodb.js +13 -9
  30. package/dist/esm/integration/dynamodb.js.map +1 -1
  31. package/dist/esm/integration/hono.d.ts +1 -1
  32. package/dist/esm/integration/hono.d.ts.map +1 -1
  33. package/dist/esm/integration/hono.js +4 -0
  34. package/dist/esm/integration/hono.js.map +1 -1
  35. package/dist/esm/registration.d.ts +3 -3
  36. package/dist/esm/registration.d.ts.map +1 -1
  37. package/dist/esm/registration.js +8 -7
  38. package/dist/esm/registration.js.map +1 -1
  39. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"hono.js","sourceRoot":"","sources":["../../../src/integration/hono.ts"],"names":[],"mappings":";;AA6HA,gDA6LC;AA1TD,wCAA+D;AAC/D,sCAAsC;AAyHtC;;GAEG;AACH,SAAgB,kBAAkB,CAAC,IAAU,EAAE,GAAqB;IACnE,IAAI,GAAG,GAAqB,IAAI,CAAC;IAEjC,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,eAAe,IAAI,eAAe,CAAC;IAC7D,GAAG,CAAC,uBAAuB;QAC1B,GAAG,CAAC,uBAAuB,IAAI,uBAAuB,CAAC;IACxD,GAAG,CAAC,cAAc,GAAG,GAAG,CAAC,cAAc,IAAI,eAAe,CAAC;IAC3D,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,gBAAgB,IAAI,iBAAiB,CAAC;IACjE,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,IAAI,aAAa,CAAC;IACrD,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,QAAQ,CAAC;IACtC,GAAG,CAAC,aAAa,GAAG,GAAG,CAAC,aAAa,IAAI,cAAc,CAAC;IACxD,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,IAAI,aAAa,CAAC;IAErD,GAAG,CAAC,aAAa,GAAG,GAAG,CAAC,aAAa,IAAI,eAAe,CAAC;IAEzD,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACjC,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,YAAY,CAAC,GAA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CAAC,SAAS,CAC5B,CAAC;gBAEF,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,MAAM,GAAG,GAAG;IAC/C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM;QACN,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { getSignedCookie, setSignedCookie } from \"hono/cookie\";\nimport { AppServer } from \"../app.js\";\nimport type { Context } from \"../context-resolver.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\nimport type { Hono, Context as HonoContext } from \"hono\";\n\ndeclare module \"hono\" {\n\tinterface ContextVariableMap {\n\t\t// @ts-ignore\n\t\tapp: AppServer<ShopInterface>;\n\t\tshop: ShopInterface;\n\t\t// @ts-ignore\n\t\tcontext: Context<ShopInterface, unknown>;\n\t}\n}\n\ninterface MiddlewareConfig {\n\t/**\n\t * The name of the app\n\t */\n\tappName: string | ((c: HonoContext) => string);\n\t/**\n\t * The secret of the app. When the app is published in the Shopware Store, the Shopware Store provides this value.\n\t */\n\tappSecret: string | ((c: HonoContext) => string);\n\n\t/**\n\t * The URL of the app. This is the base URL of the app. This will automatically determined by default\n\t */\n\tappUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration endpoint\n\t *\n\t * @default \"/app/register\"\n\t */\n\tregistrationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration confirmation endpoint\n\t *\n\t * @default \"/app/register/confirm\"\n\t */\n\tregisterConfirmationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app installation lifecycle endpoint\n\t *\n\t * @default \"/app/install\"\n\t */\n\tappInstallUrl?: string | null;\n\n\t/**\n\t * The relative url of the app activation lifecycle endpoint\n\t *\n\t * @default \"/app/activate\"\n\t */\n\tappActivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app update lifecycle endpoint\n\t *\n\t * @default \"/app/update\"\n\t */\n\tappUpdateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deactivation lifecycle endpoint\n\t *\n\t * @default \"/app/deactivate\"\n\t */\n\tappDeactivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deletion lifecycle endpoint\n\t *\n\t * @default \"/app/delete\"\n\t */\n\tappDeleteUrl?: string | null;\n\n\t/**\n\t * The relative url of the app scope. All requests matching this will be the signature automatically validated and the response will be signed\n\t *\n\t * @default \"/app/*\"\n\t */\n\tappPath?: string | null;\n\n\t/**\n\t * Enable the app iframe integration. This will automatically set a cookie to identifiy the shopware shop and validate the request from a client side application. See appIframeRedirects\n\t */\n\tappIframeEnable?: boolean;\n\n\t/**\n\t * The relative url of the app iframe scope. All requests matching this will require that the request has an cookie set with the shopware shop. This cookie will be automatically set by\n\t *\n\t * @default \"/client-api/*\"\n\t */\n\tappIframePath?: string | null;\n\n\t/**\n\t * A mapping of the app iframe paths to the actual paths. This route will set a cookie automatically before the redirect to the actual path. In that way the client side application can send requests to /app-iframe/* with the cookie set and the server will automatically validate the request and knows which shop the request is for.\n\t *\n\t * @default {\n\t * \"/app/module\": \"https://my-static-client-side-app.com\"\n\t * }\n\t */\n\tappIframeRedirects?: Record<string, string>;\n\n\t/**\n\t * The repository to fetch and store the shop data\n\t */\n\tshopRepository:\n\t\t| ShopRepositoryInterface\n\t\t| ((c: HonoContext) => ShopRepositoryInterface);\n\n\t/**\n\t * A callback to setup the app server. It will be called after the app server is created and before the first request is handled\n\t */\n\tsetup?: (app: AppServer) => void;\n}\n\n/**\n * Configure the Hono server to handle the app registration and context resolution\n */\nexport function configureAppServer(hono: Hono, cfg: MiddlewareConfig) {\n\tlet app: AppServer | null = null;\n\n\tcfg.registrationUrl = cfg.registrationUrl || \"/app/register\";\n\tcfg.registerConfirmationUrl =\n\t\tcfg.registerConfirmationUrl || \"/app/register/confirm\";\n\tcfg.appActivateUrl = cfg.appActivateUrl || \"/app/activate\";\n\tcfg.appDeactivateUrl = cfg.appDeactivateUrl || \"/app/deactivate\";\n\tcfg.appDeleteUrl = cfg.appDeleteUrl || \"/app/delete\";\n\tcfg.appPath = cfg.appPath || \"/app/*\";\n\tcfg.appInstallUrl = cfg.appInstallUrl || \"/app/install\";\n\tcfg.appUpdateUrl = cfg.appUpdateUrl || \"/app/update\";\n\n\tcfg.appIframePath = cfg.appIframePath || \"/client-api/*\";\n\n\thono.use(\"*\", async (ctx, next) => {\n\t\tif (app === null) {\n\t\t\tconst appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);\n\n\t\t\tif (typeof cfg.shopRepository === \"function\") {\n\t\t\t\tcfg.shopRepository = cfg.shopRepository(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appName === \"function\") {\n\t\t\t\tcfg.appName = cfg.appName(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appSecret === \"function\") {\n\t\t\t\tcfg.appSecret = cfg.appSecret(ctx);\n\t\t\t}\n\n\t\t\tapp = new AppServer(\n\t\t\t\t{\n\t\t\t\t\tappName: cfg.appName,\n\t\t\t\t\tappSecret: cfg.appSecret,\n\t\t\t\t\tauthorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,\n\t\t\t\t},\n\t\t\t\tcfg.shopRepository,\n\t\t\t);\n\n\t\t\tif (cfg.setup) {\n\t\t\t\tcfg.setup(app);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"app\", app);\n\n\t\tawait next();\n\t});\n\n\thono.use(cfg.appPath, async (ctx, next) => {\n\t\t// @ts-ignore\n\t\tconst app = ctx.get(\"app\") as AppServer;\n\n\t\t// Don't validate signature for registration\n\t\tif (\n\t\t\tctx.req.path === cfg.registrationUrl ||\n\t\t\tctx.req.path === cfg.registerConfirmationUrl ||\n\t\t\tctx.req.path === cfg.appActivateUrl ||\n\t\t\tctx.req.path === cfg.appDeactivateUrl ||\n\t\t\tctx.req.path === cfg.appDeleteUrl\n\t\t) {\n\t\t\tawait next();\n\t\t\treturn;\n\t\t}\n\n\t\tlet context: Context<ShopInterface, unknown>;\n\t\ttry {\n\t\t\tcontext =\n\t\t\t\tctx.req.method === \"GET\"\n\t\t\t\t\t? await app.contextResolver.fromBrowser(ctx.req.raw)\n\t\t\t\t\t: await app.contextResolver.fromAPI(ctx.req.raw);\n\t\t} catch (_e) {\n\t\t\treturn jsonResponse({ message: \"Invalid request\" }, 400);\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"shop\", context.shop);\n\t\t// @ts-ignore\n\t\tctx.set(\"context\", context);\n\n\t\tawait next();\n\n\t\tconst cloned = ctx.res.clone();\n\n\t\tawait ctx\n\t\t\t.get(\"app\")\n\t\t\t.signer.signResponse(cloned, ctx.get(\"shop\").getShopSecret());\n\n\t\tctx.header(\n\t\t\t\"shopware-app-signature\",\n\t\t\tcloned.headers.get(\"shopware-app-signature\") as string,\n\t\t);\n\t});\n\n\thono.get(cfg.registrationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorize(ctx.req.raw);\n\t});\n\n\thono.post(cfg.registerConfirmationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorizeCallback(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appInstallUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.install(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appActivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.activate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appUpdateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.update(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeactivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.deactivate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeleteUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.delete(ctx.req.raw);\n\t});\n\n\tif (cfg.appIframeEnable) {\n\t\thono.use(cfg.appIframePath, async (ctx, next) => {\n\t\t\tconst shopId = await getSignedCookie(\n\t\t\t\tctx,\n\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t\"shop\",\n\t\t\t);\n\n\t\t\tif (!shopId) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tconst shop = await ctx.get(\"app\").repository.getShopById(shopId);\n\n\t\t\tif (!shop) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tctx.set(\"shop\", shop);\n\n\t\t\tawait next();\n\t\t});\n\n\t\tfor (let [path, redirect] of Object.entries(cfg.appIframeRedirects || {})) {\n\t\t\thono.get(path, async (ctx) => {\n\t\t\t\tconst url = new URL(ctx.req.url);\n\n\t\t\t\tif (redirect.startsWith(\"/\")) {\n\t\t\t\t\turl.pathname = redirect;\n\t\t\t\t\tredirect = url.toString();\n\t\t\t\t} else {\n\t\t\t\t\tconst newUrl = new URL(redirect);\n\n\t\t\t\t\tfor (const [key, value] of url.searchParams) {\n\t\t\t\t\t\tnewUrl.searchParams.set(key, value);\n\t\t\t\t\t}\n\n\t\t\t\t\tredirect = newUrl.toString();\n\t\t\t\t}\n\n\t\t\t\tawait setSignedCookie(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"shop\",\n\t\t\t\t\tctx.get(\"shop\").getShopId(),\n\t\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t);\n\n\t\t\t\treturn ctx.redirect(redirect);\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction jsonResponse(body: object, status = 200): Response {\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t});\n}\n\nfunction buildBaseUrl(url: string): string {\n\tconst u = new URL(url);\n\n\treturn `${u.protocol}//${u.host}`;\n}\n"]}
1
+ {"version":3,"file":"hono.js","sourceRoot":"","sources":["../../../src/integration/hono.ts"],"names":[],"mappings":";;AA8HA,gDA+LC;AA7TD,wCAA+D;AAC/D,sCAAsC;AACtC,gEAAiD;AAIjD,sDAA+C;AAqH/C;;GAEG;AACH,SAAgB,kBAAkB,CAAC,IAAU,EAAE,GAAqB;IACnE,IAAI,GAAG,GAAqB,IAAI,CAAC;IAEjC,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,eAAe,IAAI,eAAe,CAAC;IAC7D,GAAG,CAAC,uBAAuB;QAC1B,GAAG,CAAC,uBAAuB,IAAI,uBAAuB,CAAC;IACxD,GAAG,CAAC,cAAc,GAAG,GAAG,CAAC,cAAc,IAAI,eAAe,CAAC;IAC3D,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,gBAAgB,IAAI,iBAAiB,CAAC;IACjE,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,IAAI,aAAa,CAAC;IACrD,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,QAAQ,CAAC;IACtC,GAAG,CAAC,aAAa,GAAG,GAAG,CAAC,aAAa,IAAI,cAAc,CAAC;IACxD,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,IAAI,aAAa,CAAC;IAErD,GAAG,CAAC,aAAa,GAAG,GAAG,CAAC,aAAa,IAAI,eAAe,CAAC;IAEzD,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,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AAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBACrC,CAAC;oBAED,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAC9B,CAAC;gBAED,MAAM,IAAA,wBAAe,EACpB,GAAG,EACH,MAAM,EACN,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAC3B,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,SAAS,CAC5B,CAAC;gBAEF,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,MAAM,GAAG,GAAG;IAC/C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM;QACN,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { getSignedCookie, setSignedCookie } from \"hono/cookie\";\nimport { AppServer } from \"../app.js\";\nimport { Context } from \"../context-resolver.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\nimport type { Hono, Context as HonoContext } from \"hono\";\nimport { HttpClient } from \"../http-client.js\";\n\ndeclare module \"hono\" {\n\tinterface ContextVariableMap {\n\t\t// @ts-ignore\n\t\tapp: AppServer<ShopInterface>;\n\t\tshop: ShopInterface;\n\t\t// @ts-ignore\n\t\tcontext: Context<ShopInterface, unknown>;\n\t}\n}\n\ninterface MiddlewareConfig {\n\t/**\n\t * The name of the app\n\t */\n\tappName: string | ((c: HonoContext) => string);\n\t/**\n\t * The secret of the app. When the app is published in the Shopware Store, the Shopware Store provides this value.\n\t */\n\tappSecret: string | ((c: HonoContext) => string);\n\n\t/**\n\t * The URL of the app. This is the base URL of the app. This will automatically determined by default\n\t */\n\tappUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration endpoint\n\t *\n\t * @default \"/app/register\"\n\t */\n\tregistrationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration confirmation endpoint\n\t *\n\t * @default \"/app/register/confirm\"\n\t */\n\tregisterConfirmationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app installation lifecycle endpoint\n\t *\n\t * @default \"/app/install\"\n\t */\n\tappInstallUrl?: string | null;\n\n\t/**\n\t * The relative url of the app activation lifecycle endpoint\n\t *\n\t * @default \"/app/activate\"\n\t */\n\tappActivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app update lifecycle endpoint\n\t *\n\t * @default \"/app/update\"\n\t */\n\tappUpdateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deactivation lifecycle endpoint\n\t *\n\t * @default \"/app/deactivate\"\n\t */\n\tappDeactivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deletion lifecycle endpoint\n\t *\n\t * @default \"/app/delete\"\n\t */\n\tappDeleteUrl?: string | null;\n\n\t/**\n\t * The relative url of the app scope. All requests matching this will be the signature automatically validated and the response will be signed\n\t *\n\t * @default \"/app/*\"\n\t */\n\tappPath?: string | null;\n\n\t/**\n\t * Enable the app iframe integration. This will automatically set a cookie to identifiy the shopware shop and validate the request from a client side application. See appIframeRedirects\n\t */\n\tappIframeEnable?: boolean;\n\n\t/**\n\t * The relative url of the app iframe scope. All requests matching this will require that the request has an cookie set with the shopware shop. This cookie will be automatically set by\n\t *\n\t * @default \"/client-api/*\"\n\t */\n\tappIframePath?: string | null;\n\n\t/**\n\t * A mapping of the app iframe paths to the actual paths. This route will set a cookie automatically before the redirect to the actual path. In that way the client side application can send requests to /app-iframe/* with the cookie set and the server will automatically validate the request and knows which shop the request is for.\n\t *\n\t * @default {\n\t * \"/app/module\": \"https://my-static-client-side-app.com\"\n\t * }\n\t */\n\tappIframeRedirects?: Record<string, string>;\n\n\t/**\n\t * The repository to fetch and store the shop data\n\t */\n\tshopRepository:\n\t\t| ShopRepositoryInterface\n\t\t| ((c: HonoContext) => ShopRepositoryInterface);\n\n\t/**\n\t * A callback to setup the app server. It will be called after the app server is created and before the first request is handled\n\t */\n\tsetup?: (app: AppServer) => void;\n}\n\n/**\n * Configure the Hono server to handle the app registration and context resolution\n */\nexport function configureAppServer(hono: Hono, cfg: MiddlewareConfig) {\n\tlet app: AppServer | null = null;\n\n\tcfg.registrationUrl = cfg.registrationUrl || \"/app/register\";\n\tcfg.registerConfirmationUrl =\n\t\tcfg.registerConfirmationUrl || \"/app/register/confirm\";\n\tcfg.appActivateUrl = cfg.appActivateUrl || \"/app/activate\";\n\tcfg.appDeactivateUrl = cfg.appDeactivateUrl || \"/app/deactivate\";\n\tcfg.appDeleteUrl = cfg.appDeleteUrl || \"/app/delete\";\n\tcfg.appPath = cfg.appPath || \"/app/*\";\n\tcfg.appInstallUrl = cfg.appInstallUrl || \"/app/install\";\n\tcfg.appUpdateUrl = cfg.appUpdateUrl || \"/app/update\";\n\n\tcfg.appIframePath = cfg.appIframePath || \"/client-api/*\";\n\n\thono.use(\"*\", async (ctx, next) => {\n\t\tif (app === null) {\n\t\t\tconst appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);\n\n\t\t\tif (typeof cfg.shopRepository === \"function\") {\n\t\t\t\tcfg.shopRepository = cfg.shopRepository(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appName === \"function\") {\n\t\t\t\tcfg.appName = cfg.appName(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appSecret === \"function\") {\n\t\t\t\tcfg.appSecret = cfg.appSecret(ctx);\n\t\t\t}\n\n\t\t\tapp = new AppServer(\n\t\t\t\t{\n\t\t\t\t\tappName: cfg.appName,\n\t\t\t\t\tappSecret: cfg.appSecret,\n\t\t\t\t\tauthorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,\n\t\t\t\t},\n\t\t\t\tcfg.shopRepository,\n\t\t\t);\n\n\t\t\tif (cfg.setup) {\n\t\t\t\tcfg.setup(app);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"app\", app);\n\n\t\tawait next();\n\t});\n\n\thono.use(cfg.appPath, async (ctx, next) => {\n\t\t// @ts-ignore\n\t\tconst app = ctx.get(\"app\") as AppServer;\n\n\t\t// Don't validate signature for registration\n\t\tif (\n\t\t\tctx.req.path === cfg.registrationUrl ||\n\t\t\tctx.req.path === cfg.registerConfirmationUrl ||\n\t\t\tctx.req.path === cfg.appActivateUrl ||\n\t\t\tctx.req.path === cfg.appDeactivateUrl ||\n\t\t\tctx.req.path === cfg.appDeleteUrl\n\t\t) {\n\t\t\tawait next();\n\t\t\treturn;\n\t\t}\n\n\t\tlet context: Context<ShopInterface, unknown>;\n\t\ttry {\n\t\t\tcontext =\n\t\t\t\tctx.req.method === \"GET\"\n\t\t\t\t\t? await app.contextResolver.fromBrowser(ctx.req.raw)\n\t\t\t\t\t: await app.contextResolver.fromAPI(ctx.req.raw);\n\t\t} catch (_e) {\n\t\t\treturn jsonResponse({ message: \"Invalid request\" }, 400);\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"shop\", context.shop);\n\t\t// @ts-ignore\n\t\tctx.set(\"context\", context);\n\n\t\tawait next();\n\n\t\tconst cloned = ctx.res.clone();\n\n\t\tawait ctx\n\t\t\t.get(\"app\")\n\t\t\t.signer.signResponse(cloned, ctx.get(\"shop\").getShopSecret());\n\n\t\tctx.header(\n\t\t\t\"shopware-app-signature\",\n\t\t\tcloned.headers.get(\"shopware-app-signature\") as string,\n\t\t);\n\t});\n\n\thono.get(cfg.registrationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorize(ctx.req.raw);\n\t});\n\n\thono.post(cfg.registerConfirmationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorizeCallback(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appInstallUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.install(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appActivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.activate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appUpdateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.update(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeactivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.deactivate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeleteUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.delete(ctx.req.raw);\n\t});\n\n\tif (cfg.appIframeEnable) {\n\t\thono.use(cfg.appIframePath, async (ctx, next) => {\n\t\t\tconst shopId = await getSignedCookie(\n\t\t\t\tctx,\n\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t\"shop\",\n\t\t\t);\n\n\t\t\tif (!shopId) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tconst shop = await ctx.get(\"app\").repository.getShopById(shopId);\n\n\t\t\tif (!shop) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tctx.set(\"shop\", shop);\n\t\t\t// @ts-ignore\n\t\t\tctx.set(\"context\", new Context(shop, {}, new HttpClient(shop)));\n\n\t\t\tawait next();\n\t\t});\n\n\t\tfor (let [path, redirect] of Object.entries(cfg.appIframeRedirects || {})) {\n\t\t\thono.get(path, async (ctx) => {\n\t\t\t\tconst url = new URL(ctx.req.url);\n\n\t\t\t\tif (redirect.startsWith(\"/\")) {\n\t\t\t\t\turl.pathname = redirect;\n\t\t\t\t\tredirect = url.toString();\n\t\t\t\t} else {\n\t\t\t\t\tconst newUrl = new URL(redirect);\n\n\t\t\t\t\tfor (const [key, value] of url.searchParams) {\n\t\t\t\t\t\tnewUrl.searchParams.set(key, value);\n\t\t\t\t\t}\n\n\t\t\t\t\tredirect = newUrl.toString();\n\t\t\t\t}\n\n\t\t\t\tawait setSignedCookie(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"shop\",\n\t\t\t\t\tctx.get(\"shop\").getShopId(),\n\t\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t);\n\n\t\t\t\treturn ctx.redirect(redirect);\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction jsonResponse(body: object, status = 200): Response {\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t});\n}\n\nfunction buildBaseUrl(url: string): string {\n\tconst u = new URL(url);\n\n\treturn `${u.protocol}//${u.host}`;\n}\n"]}
@@ -18,7 +18,7 @@ export declare class Registration<Shop extends ShopInterface = ShopInterface> {
18
18
  * This method should be called by Shopware Shop to set the shop active.
19
19
  *
20
20
  * <webhooks>
21
- * <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/>
21
+ * <webhook name="appActivate" url="http://localhost:3000/app/activate" event="app.activated"/>
22
22
  * </webhooks>
23
23
  */
24
24
  activate(req: Request): Promise<Response>;
@@ -26,7 +26,7 @@ export declare class Registration<Shop extends ShopInterface = ShopInterface> {
26
26
  * This method should be called by Shopware when the app was installed.
27
27
  *
28
28
  * <webhooks>
29
- * <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/>
29
+ * <webhook name="appInstall" url="http://localhost:3000/app/install" event="app.installed"/>
30
30
  * </webhooks>
31
31
  */
32
32
  install(req: Request): Promise<Response>;
@@ -42,7 +42,7 @@ export declare class Registration<Shop extends ShopInterface = ShopInterface> {
42
42
  * This method should be called by Shopware when the app was updated.
43
43
  *
44
44
  * <webhooks>
45
- * <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/>
45
+ * <webhook name="appUpdated" url="http://localhost:3000/app/update" event="app.updated"/>
46
46
  * </webhooks>
47
47
  */
48
48
  update(req: Request): Promise<Response>;
@@ -1 +1 @@
1
- {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/registration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,qBAAa,YAAY,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IACvD,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC;IAExC;;;;OAIG;IACU,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiDvD;;;OAGG;IACU,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiD/D;;;;;;OAMG;IACU,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAatD;;;;;;OAMG;IACU,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAerD;;;;;;OAMG;IACU,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAaxD;;;;;;OAMG;IACU,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAepD;;;;;;OAMG;IACU,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CAkBpD;AAED,wBAAgB,YAAY,CAAC,MAAM,SAAM,UAUxC;AAaD,qBAAa,kBAAkB,CAAC,IAAI,SAAS,a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CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAE9D,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,MAAM,GAAG,IAAI;gBAFzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,UAAU,GAAE,MAAM,GAAG,IAAW;CAExC;AAED,qBAAa,gBAAgB,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAE/D,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;gBADV,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI;CAElB;AAED,qBAAa,kBAAkB,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAEjE,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;gBADV,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI;CAElB;AAED,qBAAa,cAAc,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAE7D,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,MAAM,GAAG,IAAI;gBAFzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,UAAU,GAAE,MAAM,GAAG,IAAW;CAExC;AAED,qBAAa,iBAAiB,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAEhE,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,OAAO,GAAG,IAAI;gBAF5B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,YAAY,GAAE,OAAO,GAAG,IAAW;CAE3C"}
@@ -21,16 +21,17 @@ class Registration {
21
21
  return new InvalidRequestResponse("Invalid Request", 400);
22
22
  }
23
23
  const shopId = url.searchParams.get("shop-id");
24
- const shopUrl = url.searchParams.get("shop-url")
25
- .toString()
26
- .replace(/\/+$/, "");
24
+ const shopUrl = url.searchParams.get("shop-url");
27
25
  const timestamp = url.searchParams.get("timestamp");
28
26
  const v = await this.app.signer.verify(req.headers.get("shopware-app-signature"), `shop-id=${shopId}&shop-url=${shopUrl}&timestamp=${timestamp}`, this.app.cfg.appSecret);
29
27
  if (!v) {
30
28
  return new InvalidRequestResponse("Cannot validate app signature");
31
29
  }
32
30
  const shopSecret = randomString();
33
- await this.app.repository.createShop(shopId, shopUrl, shopSecret);
31
+ const sanitizedShopUrl = shopUrl
32
+ .replace(/([^:])(\/\/+)/g, "$1/")
33
+ .replace(/\/+$/, "");
34
+ await this.app.repository.createShop(shopId, sanitizedShopUrl, shopSecret);
34
35
  return new Response(JSON.stringify({
35
36
  proof: await this.app.signer.sign(shopId + shopUrl + this.app.cfg.appName, this.app.cfg.appSecret),
36
37
  secret: shopSecret,
@@ -78,7 +79,7 @@ class Registration {
78
79
  * This method should be called by Shopware Shop to set the shop active.
79
80
  *
80
81
  * <webhooks>
81
- * <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/>
82
+ * <webhook name="appActivate" url="http://localhost:3000/app/activate" event="app.activated"/>
82
83
  * </webhooks>
83
84
  */
84
85
  async activate(req) {
@@ -93,7 +94,7 @@ class Registration {
93
94
  * This method should be called by Shopware when the app was installed.
94
95
  *
95
96
  * <webhooks>
96
- * <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/>
97
+ * <webhook name="appInstall" url="http://localhost:3000/app/install" event="app.installed"/>
97
98
  * </webhooks>
98
99
  */
99
100
  async install(req) {
@@ -121,7 +122,7 @@ class Registration {
121
122
  * This method should be called by Shopware when the app was updated.
122
123
  *
123
124
  * <webhooks>
124
- * <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/>
125
+ * <webhook name="appUpdated" url="http://localhost:3000/app/update" event="app.updated"/>
125
126
  * </webhooks>
126
127
  */
127
128
  async update(req) {
@@ -1 +1 @@
1
- {"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/registration.ts"],"names":[],"mappings":";;;AAgOA,oCAUC;AAvOD,MAAa,YAAY;IACJ;IAApB,YA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OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,eAAU,GAAV,UAAU,CAAsB;IACrC,CAAC;CACJ;AAND,0CAMC;AAED,MAAa,gBAAgB;IAEpB;IACA;IAFR,YACQ,OAAgB,EAChB,IAAU;QADV,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;IACf,CAAC;CACJ;AALD,4CAKC;AAED,MAAa,kBAAkB;IAEtB;IACA;IAFR,YACQ,OAAgB,EAChB,IAAU;QADV,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;IACf,CAAC;CACJ;AALD,gDAKC;AAED,MAAa,cAAc;IAElB;IACA;IACA;IAHR,YACQ,OAAgB,EAChB,IAAU,EACV,aAA4B,IAAI;QAFhC,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,eAAU,GAAV,UAAU,CAAsB;IACrC,CAAC;CACJ;AAND,wCAMC;AAED,MAAa,iBAAiB;IAErB;IACA;IACA;IAHR,YACQ,OAAgB,EAChB,IAAU,EACV,eAA+B,IAAI;QAFnC,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,iBAAY,GAAZ,YAAY,CAAuB;IACxC,CAAC;CACJ;AAND,8CAMC","sourcesContent":["import type { AppServer } from \"./app.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\nexport class Registration<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(private app: AppServer<Shop>) {}\n\n\t/**\n\t * This method checks the request for the handshake with the Shopware Shop.\n\t * if it's valid a Shop will be created, and a proof will be responded with a confirmation url.\n\t * then the Shop will call the confirmation url, and this should be handled by the authorizeCallback method to finish the handshake.\n\t */\n\tpublic async authorize(req: Request): Promise<Response> {\n\t\tconst url = new URL(req.url);\n\n\t\tif (\n\t\t\t!url.searchParams.has(\"shop-url\") ||\n\t\t\t!req.headers.has(\"shopware-app-signature\") ||\n\t\t\t!url.searchParams.has(\"shop-id\") ||\n\t\t\t!url.searchParams.has(\"timestamp\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shopId = url.searchParams.get(\"shop-id\") as string;\n\t\tconst shopUrl = (url.searchParams.get(\"shop-url\") as string)\n\t\t\t.toString()\n\t\t\t.replace(/\\/+$/, \"\");\n\t\tconst timestamp = url.searchParams.get(\"timestamp\") as string;\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-app-signature\") as string,\n\t\t\t`shop-id=${shopId}&shop-url=${shopUrl}&timestamp=${timestamp}`,\n\t\t\tthis.app.cfg.appSecret,\n\t\t);\n\n\t\tif (!v) {\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tconst shopSecret = randomString();\n\n\t\tawait this.app.repository.createShop(shopId, shopUrl, shopSecret);\n\n\t\treturn new Response(\n\t\t\tJSON.stringify({\n\t\t\t\tproof: await this.app.signer.sign(\n\t\t\t\t\tshopId + shopUrl + this.app.cfg.appName,\n\t\t\t\t\tthis.app.cfg.appSecret,\n\t\t\t\t),\n\t\t\t\tsecret: shopSecret,\n\t\t\t\tconfirmation_url: this.app.cfg.authorizeCallbackUrl,\n\t\t\t}),\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * This method is called by the Shopware Shop to confirm the handshake.\n\t * It will update the shop with the given oauth2 credentials.\n\t */\n\tpublic async authorizeCallback(req: Request): Promise<Response> {\n\t\tconst bodyContent = await req.text();\n\n\t\tconst body = JSON.parse(bodyContent);\n\n\t\tif (\n\t\t\ttypeof body.shopId !== \"string\" ||\n\t\t\ttypeof body.apiKey !== \"string\" ||\n\t\t\ttypeof body.secretKey !== \"string\" ||\n\t\t\t!req.headers.has(\"shopware-shop-signature\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(body.shopId as string);\n\n\t\tif (shop === null) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid shop given\");\n\t\t}\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-shop-signature\") as string,\n\t\t\tbodyContent,\n\t\t\tshop.getShopSecret(),\n\t\t);\n\n\t\tif (!v) {\n\t\t\t// Shop has failed the verification. Delete it from our DB.\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tshop.setShopCredentials(body.apiKey, body.secretKey);\n\n\t\tconst event = new ShopAuthorizeEvent(req, shop);\n\t\tawait this.app.hooks.publish(\"onAuthorize\", event);\n\n\t\tif (event.reason) {\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(event.reason, 403);\n\t\t}\n\n\t\tawait this.app.repository.updateShop(shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appActivate\" url=\"http://localhost:3000/app/delete\" event=\"app.activated\"/>\n\t * </webhooks>\n\t */\n\tpublic async activate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppActivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppActivate\", event);\n\n\t\tctx.shop.setShopActive(true);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was installed.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appInstall\" url=\"http://localhost:3000/app/installed\" event=\"app.installed\"/>\n\t * </webhooks>\n\t */\n\tpublic async install(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppInstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppInstall\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop in-active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDeactivated\" url=\"http://localhost:3000/app/deactivated\" event=\"app.deactivated\"/>\n\t * </webhooks>\n\t */\n\tpublic async deactivate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppDeactivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppDeactivate\", event);\n\n\t\tctx.shop.setShopActive(false);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was updated.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appUpdated\" url=\"http://localhost:3000/app/updated\" event=\"app.updated\"/>\n\t * </webhooks>\n\t */\n\tpublic async update(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppUpdateEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUpdate\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to delete the app.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDelete\" url=\"http://localhost:3000/app/delete\" event=\"app.deleted\"/>\n\t * </webhooks>\n\t */\n\tpublic async delete(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { keepUserData?: boolean } };\n\t\t}>(req);\n\n\t\tconst event = new AppUninstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.keepUserData ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUninstall\", event);\n\n\t\tif (event.keepUserData === false) {\n\t\t\tawait this.app.repository.deleteShop(ctx.shop.getShopId());\n\t\t}\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n}\n\nexport function randomString(length = 120) {\n\tlet result = \"\";\n\tconst characters =\n\t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\tconst charactersLength = characters.length;\n\tfor (let i = 0; i < length; i++) {\n\t\tresult += characters.charAt(Math.floor(Math.random() * charactersLength));\n\t}\n\n\treturn result;\n}\n\nclass InvalidRequestResponse extends Response {\n\tconstructor(message: string, status = 401) {\n\t\tsuper(JSON.stringify({ message }), {\n\t\t\tstatus,\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport class ShopAuthorizeEvent<Shop extends ShopInterface = ShopInterface> {\n\tprivate reject: string | null = null;\n\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n\n\tpublic rejectRegistration(reason: string) {\n\t\tthis.reject = reason;\n\t}\n\n\tpublic get reason() {\n\t\treturn this.reject;\n\t}\n}\n\nexport class AppInstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppActivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppDeactivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppUpdateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppUninstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic keepUserData: boolean | null = null,\n\t) {}\n}\n"]}
1
+ {"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/registration.ts"],"names":[],"mappings":";;;AAiOA,oCAUC;AAxOD,MAAa,YAAY;IACJ;IAApB,YAAoB,GAAoB;QAApB,QAAG,GAAH,GAAG,CAAiB;IAAG,CAAC;IAE5C;;;;OAIG;IACI,KAAK,CAAC,SAAS,CAAC,GAAY;QAClC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE7B,IACC,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC;YACjC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;YAC1C,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC;YAChC,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EACjC,CAAC;YACF,OAAO,IAAI,sBAAsB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAW,CAAC;QACzD,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAW,CAAC;QAC3D,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAW,CAAC;QAE9D,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CACrC,G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iBAAY,GAAZ,YAAY,CAAuB;IACxC,CAAC;CACJ;AAND,8CAMC","sourcesContent":["import type { AppServer } from \"./app.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\nexport class Registration<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(private app: AppServer<Shop>) {}\n\n\t/**\n\t * This method checks the request for the handshake with the Shopware Shop.\n\t * if it's valid a Shop will be created, and a proof will be responded with a confirmation url.\n\t * then the Shop will call the confirmation url, and this should be handled by the authorizeCallback method to finish the handshake.\n\t */\n\tpublic async authorize(req: Request): Promise<Response> {\n\t\tconst url = new URL(req.url);\n\n\t\tif (\n\t\t\t!url.searchParams.has(\"shop-url\") ||\n\t\t\t!req.headers.has(\"shopware-app-signature\") ||\n\t\t\t!url.searchParams.has(\"shop-id\") ||\n\t\t\t!url.searchParams.has(\"timestamp\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shopId = url.searchParams.get(\"shop-id\") as string;\n\t\tconst shopUrl = url.searchParams.get(\"shop-url\") as string;\n\t\tconst timestamp = url.searchParams.get(\"timestamp\") as string;\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-app-signature\") as string,\n\t\t\t`shop-id=${shopId}&shop-url=${shopUrl}&timestamp=${timestamp}`,\n\t\t\tthis.app.cfg.appSecret,\n\t\t);\n\n\t\tif (!v) {\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tconst shopSecret = randomString();\n\t\tconst sanitizedShopUrl = shopUrl\n\t\t\t.replace(/([^:])(\\/\\/+)/g, \"$1/\")\n\t\t\t.replace(/\\/+$/, \"\");\n\n\t\tawait this.app.repository.createShop(shopId, sanitizedShopUrl, shopSecret);\n\n\t\treturn new Response(\n\t\t\tJSON.stringify({\n\t\t\t\tproof: await this.app.signer.sign(\n\t\t\t\t\tshopId + shopUrl + this.app.cfg.appName,\n\t\t\t\t\tthis.app.cfg.appSecret,\n\t\t\t\t),\n\t\t\t\tsecret: shopSecret,\n\t\t\t\tconfirmation_url: this.app.cfg.authorizeCallbackUrl,\n\t\t\t}),\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * This method is called by the Shopware Shop to confirm the handshake.\n\t * It will update the shop with the given oauth2 credentials.\n\t */\n\tpublic async authorizeCallback(req: Request): Promise<Response> {\n\t\tconst bodyContent = await req.text();\n\n\t\tconst body = JSON.parse(bodyContent);\n\n\t\tif (\n\t\t\ttypeof body.shopId !== \"string\" ||\n\t\t\ttypeof body.apiKey !== \"string\" ||\n\t\t\ttypeof body.secretKey !== \"string\" ||\n\t\t\t!req.headers.has(\"shopware-shop-signature\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(body.shopId as string);\n\n\t\tif (shop === null) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid shop given\");\n\t\t}\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-shop-signature\") as string,\n\t\t\tbodyContent,\n\t\t\tshop.getShopSecret(),\n\t\t);\n\n\t\tif (!v) {\n\t\t\t// Shop has failed the verification. Delete it from our DB.\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tshop.setShopCredentials(body.apiKey, body.secretKey);\n\n\t\tconst event = new ShopAuthorizeEvent(req, shop);\n\t\tawait this.app.hooks.publish(\"onAuthorize\", event);\n\n\t\tif (event.reason) {\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(event.reason, 403);\n\t\t}\n\n\t\tawait this.app.repository.updateShop(shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appActivate\" url=\"http://localhost:3000/app/activate\" event=\"app.activated\"/>\n\t * </webhooks>\n\t */\n\tpublic async activate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppActivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppActivate\", event);\n\n\t\tctx.shop.setShopActive(true);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was installed.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appInstall\" url=\"http://localhost:3000/app/install\" event=\"app.installed\"/>\n\t * </webhooks>\n\t */\n\tpublic async install(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppInstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppInstall\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop in-active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDeactivated\" url=\"http://localhost:3000/app/deactivated\" event=\"app.deactivated\"/>\n\t * </webhooks>\n\t */\n\tpublic async deactivate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppDeactivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppDeactivate\", event);\n\n\t\tctx.shop.setShopActive(false);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was updated.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appUpdated\" url=\"http://localhost:3000/app/update\" event=\"app.updated\"/>\n\t * </webhooks>\n\t */\n\tpublic async update(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppUpdateEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUpdate\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to delete the app.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDelete\" url=\"http://localhost:3000/app/delete\" event=\"app.deleted\"/>\n\t * </webhooks>\n\t */\n\tpublic async delete(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { keepUserData?: boolean } };\n\t\t}>(req);\n\n\t\tconst event = new AppUninstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.keepUserData ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUninstall\", event);\n\n\t\tif (event.keepUserData === false) {\n\t\t\tawait this.app.repository.deleteShop(ctx.shop.getShopId());\n\t\t}\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n}\n\nexport function randomString(length = 120) {\n\tlet result = \"\";\n\tconst characters =\n\t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\tconst charactersLength = characters.length;\n\tfor (let i = 0; i < length; i++) {\n\t\tresult += characters.charAt(Math.floor(Math.random() * charactersLength));\n\t}\n\n\treturn result;\n}\n\nclass InvalidRequestResponse extends Response {\n\tconstructor(message: string, status = 401) {\n\t\tsuper(JSON.stringify({ message }), {\n\t\t\tstatus,\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport class ShopAuthorizeEvent<Shop extends ShopInterface = ShopInterface> {\n\tprivate reject: string | null = null;\n\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n\n\tpublic rejectRegistration(reason: string) {\n\t\tthis.reject = reason;\n\t}\n\n\tpublic get reason() {\n\t\treturn this.reject;\n\t}\n}\n\nexport class AppInstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppActivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppDeactivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppUpdateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppUninstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic keepUserData: boolean | null = null,\n\t) {}\n}\n"]}
@@ -15,9 +15,21 @@ export declare class EntityRepository<Entity extends object = object> {
15
15
  private client;
16
16
  private entityName;
17
17
  constructor(client: HttpClient, entityName: string);
18
- search<Aggregations = object>(criteria: Criteria, context?: ApiContext): Promise<EntitySearchResult<Entity, Aggregations>>;
19
- searchIds(criteria: Criteria, context?: ApiContext): Promise<string[]>;
20
- aggregate<Aggregations>(criteria: Criteria, context?: ApiContext): Promise<EntitySearchResult<object, Aggregations>>;
18
+ /**
19
+ * Search for entities with the given criteria
20
+ *
21
+ * When using Criteria<T>, the returned entities will have type-safe associations
22
+ * based on which associations were added to the criteria.
23
+ */
24
+ search<T extends Entity, Aggregations = object>(criteria: Criteria<T>, context?: ApiContext): Promise<EntitySearchResult<T, Aggregations>>;
25
+ /**
26
+ * Search for entity IDs with the given criteria
27
+ */
28
+ searchIds(criteria: Criteria<Entity>, context?: ApiContext): Promise<string[]>;
29
+ /**
30
+ * Aggregate entities with the given criteria
31
+ */
32
+ aggregate<Aggregations>(criteria: Criteria<Entity>, context?: ApiContext): Promise<EntitySearchResult<object, Aggregations>>;
21
33
  upsert(payload: Entity[], context?: ApiContext): Promise<void>;
22
34
  delete<DeleteType extends object = {
23
35
  id: string;
@@ -37,11 +49,23 @@ export declare class SyncOperation {
37
49
  criteria: SingleFilter[] | null;
38
50
  constructor(key: string, entity: string, action: "upsert" | "delete", payload: object[], criteria?: SingleFilter[] | null);
39
51
  }
52
+ /**
53
+ * Result of an entity search operation
54
+ *
55
+ * Contains the search results with proper typing for associated entities
56
+ * when used with the enhanced Criteria<T> class.
57
+ */
40
58
  export declare class EntitySearchResult<Entity = unknown, Aggregations = object> {
41
59
  total: number;
42
60
  aggregations: Aggregations;
43
61
  data: Entity[];
44
62
  constructor(total: number, aggregations: Aggregations, data: Entity[]);
63
+ /**
64
+ * Get the first result or null if no results
65
+ *
66
+ * The returned entity will be properly typed with all associations
67
+ * that were added to the criteria.
68
+ */
45
69
  first(): Entity | null;
46
70
  }
47
71
  export declare const Defaults: {
@@ -1 +1 @@
1
- {"version":3,"file":"admin-api.d.ts","sourceRoot":"","sources":["../../../src/helper/admin-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,qBAAa,UAAU;IACtB,OAAO,CAAC,UAAU,CAAgB;IAClC,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gBAAgB,EAAE,OAAO,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}
@@ -42,14 +42,26 @@ export class EntityRepository {
42
42
  this.client = client;
43
43
  this.entityName = entityName;
44
44
  }
45
+ /**
46
+ * Search for entities with the given criteria
47
+ *
48
+ * When using Criteria<T>, the returned entities will have type-safe associations
49
+ * based on which associations were added to the criteria.
50
+ */
45
51
  async search(criteria, context = new ApiContext()) {
46
52
  const response = await this.client.post(`/search/${this.entityName.replaceAll("_", "-")}`, criteria.toPayload(), context.toHeaders());
47
53
  return new EntitySearchResult(response.body.total, response.body.aggregations, response.body.data);
48
54
  }
55
+ /**
56
+ * Search for entity IDs with the given criteria
57
+ */
49
58
  async searchIds(criteria, context = new ApiContext()) {
50
59
  const response = await this.client.post(`/search-ids/${this.entityName.replaceAll("_", "-")}`, criteria.toPayload(), context.toHeaders());
51
60
  return response.body.data;
52
61
  }
62
+ /**
63
+ * Aggregate entities with the given criteria
64
+ */
53
65
  async aggregate(criteria, context = new ApiContext()) {
54
66
  criteria.setLimit(1);
55
67
  const response = await this.client.post(`/search/${this.entityName.replaceAll("_", "-")}`, criteria.toPayload(), context.toHeaders());
@@ -94,6 +106,12 @@ export class SyncOperation {
94
106
  this.criteria = criteria;
95
107
  }
96
108
  }
109
+ /**
110
+ * Result of an entity search operation
111
+ *
112
+ * Contains the search results with proper typing for associated entities
113
+ * when used with the enhanced Criteria<T> class.
114
+ */
97
115
  export class EntitySearchResult {
98
116
  total;
99
117
  aggregations;
@@ -106,6 +124,12 @@ export class EntitySearchResult {
106
124
  this.aggregations = aggregations;
107
125
  this.data = data;
108
126
  }
127
+ /**
128
+ * Get the first result or null if no results
129
+ *
130
+ * The returned entity will be properly typed with all associations
131
+ * that were added to the criteria.
132
+ */
109
133
  first() {
110
134
  return this.data[0] || null;
111
135
  }
@@ -1 +1 @@
1
- {"version":3,"file":"admin-api.js","sourceRoot":"","sources":["../../../src/helper/admin-api.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,UAAU;IACd,UAAU,CAAgB;IAClC,WAAW,CAAiB;IAC5B,SAA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ChD,CAAC","sourcesContent":["import type { HttpClient } from \"../http-client.js\";\nimport type { Criteria } from \"./criteria.js\";\nimport type { SingleFilter } from \"./criteria.js\";\n\nexport class ApiContext {\n\tprivate languageId: string | null;\n\tinheritance: boolean | null;\n\tversionId: string | null;\n\tskipTriggerFlows: boolean | null;\n\tindexingSkip: string | null;\n\tindexingBehaviour: string | null;\n\n\tconstructor(\n\t\tlanguageId: string | null = null,\n\t\tinheritance: boolean | null = null,\n\t\tversionId: string | null = null,\n\t\tskipTriggerFlows: boolean | null = null,\n\t\tindexingSkip: string | null = null,\n\t\tindexingBehaviour: string | null = null,\n\t) {\n\t\tthis.languageId = languageId;\n\t\tthis.inheritance = inheritance;\n\t\tthis.versionId = versionId;\n\t\tthis.skipTriggerFlows = skipTriggerFlows;\n\t\tthis.indexingSkip = indexingSkip;\n\t\tthis.indexingBehaviour = indexingBehaviour;\n\t}\n\n\ttoHeaders(): Record<string, string> {\n\t\tconst headers = {\n\t\t\t\"sw-language-id\": this.languageId,\n\t\t\t\"sw-inheritance\": this.inheritance === true ? \"1\" : \"0\",\n\t\t\t\"sw-version-id\": this.versionId,\n\t\t\t\"sw-skip-trigger-flow\": this.skipTriggerFlows === true ? \"1\" : \"0\",\n\t\t\t\"indexing-skip\": this.indexingSkip,\n\t\t\t\"indexing-behavior\": this.indexingBehaviour,\n\t\t};\n\n\t\tfor (const key of Object.keys(headers)) {\n\t\t\t// @ts-expect-error\n\t\t\tif (headers[key] === null) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tdelete headers[key];\n\t\t\t}\n\t\t}\n\n\t\t// @ts-expect-error\n\t\treturn headers;\n\t}\n}\n\nexport class EntityRepository<Entity extends object = object> {\n\tconstructor(\n\t\tprivate client: HttpClient,\n\t\tprivate entityName: string,\n\t) {\n\t\tthis.client = client;\n\t\tthis.entityName = entityName;\n\t}\n\n\tasync search<Aggregations = object>(\n\t\tcriteria: Criteria,\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<EntitySearchResult<Entity, Aggregations>> {\n\t\tconst response = await this.client.post<\n\t\t\tEntitySearchResponse<Entity, Aggregations>\n\t\t>(\n\t\t\t`/search/${this.entityName.replaceAll(\"_\", \"-\")}`,\n\t\t\tcriteria.toPayload(),\n\t\t\tcontext.toHeaders(),\n\t\t);\n\n\t\treturn new EntitySearchResult<Entity, Aggregations>(\n\t\t\tresponse.body.total,\n\t\t\tresponse.body.aggregations,\n\t\t\tresponse.body.data,\n\t\t);\n\t}\n\n\tasync searchIds(\n\t\tcriteria: Criteria,\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<string[]> {\n\t\tconst response = await this.client.post<{ data: string[] }>(\n\t\t\t`/search-ids/${this.entityName.replaceAll(\"_\", \"-\")}`,\n\t\t\tcriteria.toPayload(),\n\t\t\tcontext.toHeaders(),\n\t\t);\n\n\t\treturn response.body.data;\n\t}\n\n\tasync aggregate<Aggregations>(\n\t\tcriteria: Criteria,\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<EntitySearchResult<object, Aggregations>> {\n\t\tcriteria.setLimit(1);\n\n\t\tconst response = await this.client.post<\n\t\t\tEntitySearchResponse<object, Aggregations>\n\t\t>(\n\t\t\t`/search/${this.entityName.replaceAll(\"_\", \"-\")}`,\n\t\t\tcriteria.toPayload(),\n\t\t\tcontext.toHeaders(),\n\t\t);\n\n\t\treturn new EntitySearchResult<object, Aggregations>(\n\t\t\tresponse.body.total,\n\t\t\tresponse.body.aggregations,\n\t\t\tresponse.body.data,\n\t\t);\n\t}\n\n\tasync upsert(\n\t\tpayload: Entity[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait new SyncService(this.client).sync(\n\t\t\t[\n\t\t\t\tnew SyncOperation(\n\t\t\t\t\t\"upsert\",\n\t\t\t\t\tthis.entityName.replaceAll(\"-\", \"_\"),\n\t\t\t\t\t\"upsert\",\n\t\t\t\t\tpayload,\n\t\t\t\t),\n\t\t\t],\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tasync delete<DeleteType extends object = { id: string }>(\n\t\tpayload: DeleteType[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait new SyncService(this.client).sync(\n\t\t\t[\n\t\t\t\tnew SyncOperation(\n\t\t\t\t\t\"delete\",\n\t\t\t\t\tthis.entityName.replaceAll(\"-\", \"_\"),\n\t\t\t\t\t\"delete\",\n\t\t\t\t\tpayload,\n\t\t\t\t),\n\t\t\t],\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tasync deleteByFilters(\n\t\tfilters: SingleFilter[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait new SyncService(this.client).sync(\n\t\t\t[\n\t\t\t\tnew SyncOperation(\n\t\t\t\t\t\"delete\",\n\t\t\t\t\tthis.entityName.replaceAll(\"-\", \"_\"),\n\t\t\t\t\t\"delete\",\n\t\t\t\t\t[],\n\t\t\t\t\tfilters,\n\t\t\t\t),\n\t\t\t],\n\t\t\tcontext,\n\t\t);\n\t}\n}\n\nexport class SyncService {\n\tconstructor(private client: HttpClient) {}\n\n\tasync sync(\n\t\toperations: SyncOperation[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait this.client.post<{ notFound: string[]; deleted: string[] }>(\n\t\t\t\"/_action/sync\",\n\t\t\toperations,\n\t\t\tcontext.toHeaders(),\n\t\t);\n\t}\n}\n\nexport class SyncOperation {\n\tconstructor(\n\t\tpublic key: string,\n\t\tpublic entity: string,\n\t\tpublic action: \"upsert\" | \"delete\",\n\t\tpublic payload: object[],\n\t\tpublic criteria: SingleFilter[] | null = null,\n\t) {}\n}\n\ntype EntitySearchResponse<Entity = unknown, Aggregations = object> = {\n\ttotal: number;\n\taggregations: Aggregations;\n\tdata: Entity[];\n};\n\nexport class EntitySearchResult<Entity = unknown, Aggregations = object> {\n\tconstructor(\n\t\tpublic total: number,\n\t\tpublic aggregations: Aggregations,\n\t\tpublic data: Entity[],\n\t) {\n\t\tthis.total = total;\n\t\tthis.aggregations = aggregations;\n\t\tthis.data = data;\n\t}\n\n\tfirst(): Entity | null {\n\t\treturn this.data[0] || null;\n\t}\n}\n\nexport const Defaults = {\n\tsystemLanguageId: \"2fbb5fe2e29a4d70aa5854ce7ce3e20b\",\n\tliveVersion: \"0fa91ce3e96a4bc2be4bd9ce752c3425\",\n\tsystemCurrencyId: \"b7d2554b0ce847cd82f3ac9bd1c0dfca\",\n\tsalesChannelTypeApi: \"f183ee5650cf4bdb8a774337575067a6\",\n\tsalesChannelTypeSalesChannel: \"8a243080f92e4c719546314b577cf82b\",\n\tsalesChannelTypeProductComparision: \"ed535e5722134ac1aa6524f73e26881b\",\n};\n\nexport function uuid(): string {\n\treturn crypto.randomUUID().replaceAll(\"-\", \"\");\n}\n"]}
1
+ {"version":3,"file":"admin-api.js","sourceRoot":"","sources":["../../../src/helper/admin-api.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,UAAU;IACd,UAAU,CAAgB;IAClC,WAAW,CAAiB;IAC5B,SAAS,CAAgB;IACzB,gBAAgB,CAAiB;IACjC,YAAY,CAAgB;IAC5B,iBAAiB,CAAgB;IAEjC,YACC,aAA4B,IAAI,EAChC,cAA8B,IAAI,EAClC,YAA2B,IAAI,EAC/B,mBAAmC,IAAI,EACvC,eAA8B,IAAI,EAClC,oBAAmC,IAAI;QAEvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC5C,CAAC;IAED,SAAS;QACR,MAAM,OAAO,GAAG;YACf,gBAAgB,EAAE,IAAI,CAAC,UAAU;YACjC,gBAAgB,EAAE,IAAI,CAAC,WAAW,K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HR,YACQ,KAAa,EACb,YAA0B,EAC1B,IAAc;QAFd,UAAK,GAAL,KAAK,CAAQ;QACb,iBAAY,GAAZ,YAAY,CAAc;QAC1B,SAAI,GAAJ,IAAI,CAAU;QAErB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC7B,CAAC;CACD;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,gBAAgB,EAAE,kCAAkC;IACpD,WAAW,EAAE,kCAAkC;IAC/C,gBAAgB,EAAE,kCAAkC;IACpD,mBAAmB,EAAE,kCAAkC;IACvD,4BAA4B,EAAE,kCAAkC;IAChE,kCAAkC,EAAE,kCAAkC;CACtE,CAAC;AAEF,MAAM,UAAU,IAAI;IACnB,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { HttpClient } from \"../http-client.js\";\nimport type { Criteria } from \"./criteria.js\";\nimport type { SingleFilter } from \"./criteria.js\";\n\nexport class ApiContext {\n\tprivate languageId: string | null;\n\tinheritance: boolean | null;\n\tversionId: string | null;\n\tskipTriggerFlows: boolean | null;\n\tindexingSkip: string | null;\n\tindexingBehaviour: string | null;\n\n\tconstructor(\n\t\tlanguageId: string | null = null,\n\t\tinheritance: boolean | null = null,\n\t\tversionId: string | null = null,\n\t\tskipTriggerFlows: boolean | null = null,\n\t\tindexingSkip: string | null = null,\n\t\tindexingBehaviour: string | null = null,\n\t) {\n\t\tthis.languageId = languageId;\n\t\tthis.inheritance = inheritance;\n\t\tthis.versionId = versionId;\n\t\tthis.skipTriggerFlows = skipTriggerFlows;\n\t\tthis.indexingSkip = indexingSkip;\n\t\tthis.indexingBehaviour = indexingBehaviour;\n\t}\n\n\ttoHeaders(): Record<string, string> {\n\t\tconst headers = {\n\t\t\t\"sw-language-id\": this.languageId,\n\t\t\t\"sw-inheritance\": this.inheritance === true ? \"1\" : \"0\",\n\t\t\t\"sw-version-id\": this.versionId,\n\t\t\t\"sw-skip-trigger-flow\": this.skipTriggerFlows === true ? \"1\" : \"0\",\n\t\t\t\"indexing-skip\": this.indexingSkip,\n\t\t\t\"indexing-behavior\": this.indexingBehaviour,\n\t\t};\n\n\t\tfor (const key of Object.keys(headers)) {\n\t\t\t// @ts-expect-error\n\t\t\tif (headers[key] === null) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tdelete headers[key];\n\t\t\t}\n\t\t}\n\n\t\t// @ts-expect-error\n\t\treturn headers;\n\t}\n}\n\nexport class EntityRepository<Entity extends object = object> {\n\tconstructor(\n\t\tprivate client: HttpClient,\n\t\tprivate entityName: string,\n\t) {\n\t\tthis.client = client;\n\t\tthis.entityName = entityName;\n\t}\n\n\t/**\n\t * Search for entities with the given criteria\n\t *\n\t * When using Criteria<T>, the returned entities will have type-safe associations\n\t * based on which associations were added to the criteria.\n\t */\n\tasync search<T extends Entity, Aggregations = object>(\n\t\tcriteria: Criteria<T>,\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<EntitySearchResult<T, Aggregations>> {\n\t\tconst response = await this.client.post<\n\t\t\tEntitySearchResponse<T, Aggregations>\n\t\t>(\n\t\t\t`/search/${this.entityName.replaceAll(\"_\", \"-\")}`,\n\t\t\tcriteria.toPayload(),\n\t\t\tcontext.toHeaders(),\n\t\t);\n\n\t\treturn new EntitySearchResult<T, Aggregations>(\n\t\t\tresponse.body.total,\n\t\t\tresponse.body.aggregations,\n\t\t\tresponse.body.data,\n\t\t);\n\t}\n\n\t/**\n\t * Search for entity IDs with the given criteria\n\t */\n\tasync searchIds(\n\t\tcriteria: Criteria<Entity>,\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<string[]> {\n\t\tconst response = await this.client.post<{ data: string[] }>(\n\t\t\t`/search-ids/${this.entityName.replaceAll(\"_\", \"-\")}`,\n\t\t\tcriteria.toPayload(),\n\t\t\tcontext.toHeaders(),\n\t\t);\n\n\t\treturn response.body.data;\n\t}\n\n\t/**\n\t * Aggregate entities with the given criteria\n\t */\n\tasync aggregate<Aggregations>(\n\t\tcriteria: Criteria<Entity>,\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<EntitySearchResult<object, Aggregations>> {\n\t\tcriteria.setLimit(1);\n\n\t\tconst response = await this.client.post<\n\t\t\tEntitySearchResponse<object, Aggregations>\n\t\t>(\n\t\t\t`/search/${this.entityName.replaceAll(\"_\", \"-\")}`,\n\t\t\tcriteria.toPayload(),\n\t\t\tcontext.toHeaders(),\n\t\t);\n\n\t\treturn new EntitySearchResult<object, Aggregations>(\n\t\t\tresponse.body.total,\n\t\t\tresponse.body.aggregations,\n\t\t\tresponse.body.data,\n\t\t);\n\t}\n\n\tasync upsert(\n\t\tpayload: Entity[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait new SyncService(this.client).sync(\n\t\t\t[\n\t\t\t\tnew SyncOperation(\n\t\t\t\t\t\"upsert\",\n\t\t\t\t\tthis.entityName.replaceAll(\"-\", \"_\"),\n\t\t\t\t\t\"upsert\",\n\t\t\t\t\tpayload,\n\t\t\t\t),\n\t\t\t],\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tasync delete<DeleteType extends object = { id: string }>(\n\t\tpayload: DeleteType[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait new SyncService(this.client).sync(\n\t\t\t[\n\t\t\t\tnew SyncOperation(\n\t\t\t\t\t\"delete\",\n\t\t\t\t\tthis.entityName.replaceAll(\"-\", \"_\"),\n\t\t\t\t\t\"delete\",\n\t\t\t\t\tpayload,\n\t\t\t\t),\n\t\t\t],\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tasync deleteByFilters(\n\t\tfilters: SingleFilter[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait new SyncService(this.client).sync(\n\t\t\t[\n\t\t\t\tnew SyncOperation(\n\t\t\t\t\t\"delete\",\n\t\t\t\t\tthis.entityName.replaceAll(\"-\", \"_\"),\n\t\t\t\t\t\"delete\",\n\t\t\t\t\t[],\n\t\t\t\t\tfilters,\n\t\t\t\t),\n\t\t\t],\n\t\t\tcontext,\n\t\t);\n\t}\n}\n\nexport class SyncService {\n\tconstructor(private client: HttpClient) {}\n\n\tasync sync(\n\t\toperations: SyncOperation[],\n\t\tcontext: ApiContext = new ApiContext(),\n\t): Promise<void> {\n\t\tawait this.client.post<{ notFound: string[]; deleted: string[] }>(\n\t\t\t\"/_action/sync\",\n\t\t\toperations,\n\t\t\tcontext.toHeaders(),\n\t\t);\n\t}\n}\n\nexport class SyncOperation {\n\tconstructor(\n\t\tpublic key: string,\n\t\tpublic entity: string,\n\t\tpublic action: \"upsert\" | \"delete\",\n\t\tpublic payload: object[],\n\t\tpublic criteria: SingleFilter[] | null = null,\n\t) {}\n}\n\ntype EntitySearchResponse<Entity = unknown, Aggregations = object> = {\n\ttotal: number;\n\taggregations: Aggregations;\n\tdata: Entity[];\n};\n\n/**\n * Result of an entity search operation\n *\n * Contains the search results with proper typing for associated entities\n * when used with the enhanced Criteria<T> class.\n */\nexport class EntitySearchResult<Entity = unknown, Aggregations = object> {\n\tconstructor(\n\t\tpublic total: number,\n\t\tpublic aggregations: Aggregations,\n\t\tpublic data: Entity[],\n\t) {\n\t\tthis.total = total;\n\t\tthis.aggregations = aggregations;\n\t\tthis.data = data;\n\t}\n\n\t/**\n\t * Get the first result or null if no results\n\t *\n\t * The returned entity will be properly typed with all associations\n\t * that were added to the criteria.\n\t */\n\tfirst(): Entity | null {\n\t\treturn this.data[0] || null;\n\t}\n}\n\nexport const Defaults = {\n\tsystemLanguageId: \"2fbb5fe2e29a4d70aa5854ce7ce3e20b\",\n\tliveVersion: \"0fa91ce3e96a4bc2be4bd9ce752c3425\",\n\tsystemCurrencyId: \"b7d2554b0ce847cd82f3ac9bd1c0dfca\",\n\tsalesChannelTypeApi: \"f183ee5650cf4bdb8a774337575067a6\",\n\tsalesChannelTypeSalesChannel: \"8a243080f92e4c719546314b577cf82b\",\n\tsalesChannelTypeProductComparision: \"ed535e5722134ac1aa6524f73e26881b\",\n};\n\nexport function uuid(): string {\n\treturn crypto.randomUUID().replaceAll(\"-\", \"\");\n}\n"]}
@@ -150,7 +150,18 @@ interface RequestParams {
150
150
  includes?: Include;
151
151
  "total-count-mode"?: TotalCountMode;
152
152
  }
153
- export declare class Criteria {
153
+ type DeepNonNullable<T> = T extends object ? {
154
+ [P in keyof T]: DeepNonNullable<NonNullable<T[P]>>;
155
+ } : NonNullable<T>;
156
+ type MakeRequired<T, K extends keyof T> = Omit<T, K> & {
157
+ [P in K]-?: DeepNonNullable<T[P]>;
158
+ };
159
+ type NestedMakeRequired<T, Path extends string> = Path extends `${infer First}.${infer Rest}` ? First extends keyof T ? Omit<T, First> & {
160
+ [K in First]-?: NestedMakeRequired<NonNullable<T[First]>, Rest>;
161
+ } : T : Path extends keyof T ? MakeRequired<T, Path> : T;
162
+ type PropertyType<T, K extends keyof T> = NonNullable<T[K]>;
163
+ export type Autoloadable<T> = T;
164
+ export declare class Criteria<T = object> {
154
165
  title: string | null;
155
166
  page: number | null;
156
167
  limit: number | null;
@@ -222,13 +233,18 @@ export declare class Criteria {
222
233
  * Ensures that a criterion is created for each segment of the passed path.
223
234
  * Existing Criteria objects are not overwritten.
224
235
  * Returns the own instance
236
+ *
237
+ * When used with a type parameter T, provides type-safe access to ensure fields are
238
+ * defined when accessing results from a Repository search.
225
239
  */
226
- addAssociation(path: string): this;
240
+ addAssociation<K extends keyof T & string>(field: K): Criteria<MakeRequired<T, K>>;
241
+ addAssociation<P extends string & `${string}.${string}`>(path: P): Criteria<NestedMakeRequired<T, P>>;
227
242
  /**
228
243
  * Ensures that a criterion is created for each segment of the passed path.
229
244
  * Returns the criteria instance of the last path segment
230
245
  */
231
- getAssociation(path: string): Criteria;
246
+ getAssociation<K extends keyof T & string>(field: K): Criteria<PropertyType<T, K>>;
247
+ getAssociation<P extends string>(path: P): Criteria<T>;
232
248
  private getAssociationCriteria;
233
249
  getLimit(): number;
234
250
  getPage(): number;
@@ -1 +1 @@
1
- {"version":3,"file":"criteria.d.ts","sourceRoot":"","sources":["../../../src/helper/criteria.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IAEzB,cAAc,IAAI;IAElB,iBAAiB,IAAI;IAErB,sBAAsB,IAAI;CAC1B;AAED,UAAU,OAAO;IAChB,QAAQ,EAAE;QACT,IAAI,EAAE,UAAU,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACd,CAAC;IACF,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACd,CAAC;IACF,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACd,CAAC;IACF,SAAS,EAAE;QACV,IAAI,EAAE,WAAW,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;KAC5C,CAAC;IACF,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;KACxC,CAAC;IACF,KAAK,EAAE;QACN,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE;YACX,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;YACtB,EAAE,C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AK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GACrC,OAAO,CAAC,QAAQ,CAAC;IAIpB;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,GAAG,CACT,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,EACpC,OAAO,GAAE,YAAY,EAAO,GAC1B,OAAO,CAAC,KAAK,CAAC;IAIjB;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,CACX,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,EACtC,OAAO,GAAE,YAAY,EAAO,GAC1B,OAAO,CAAC,OAAO,CAAC;CAGnB"}
@@ -201,19 +201,12 @@ export class Criteria {
201
201
  this.aggregations.push(aggregation);
202
202
  return this;
203
203
  }
204
- /**
205
- * Ensures that a criterion is created for each segment of the passed path.
206
- * Existing Criteria objects are not overwritten.
207
- * Returns the own instance
208
- */
204
+ // Implementation with traditional behavior
209
205
  addAssociation(path) {
210
206
  this.getAssociation(path);
211
207
  return this;
212
208
  }
213
- /**
214
- * Ensures that a criterion is created for each segment of the passed path.
215
- * Returns the criteria instance of the last path segment
216
- */
209
+ // Implementation with traditional behavior
217
210
  getAssociation(path) {
218
211
  const parts = path.split(".");
219
212
  // eslint-disable-next-line @typescript-eslint/no-this-alias