@shopware-ag/app-server-sdk 1.1.9 → 1.1.11

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 (55) hide show
  1. package/dist/commonjs/app.d.ts +3 -1
  2. package/dist/commonjs/app.d.ts.map +1 -1
  3. package/dist/commonjs/app.js +3 -0
  4. package/dist/commonjs/app.js.map +1 -1
  5. package/dist/commonjs/context-resolver.d.ts +1 -1
  6. package/dist/commonjs/context-resolver.d.ts.map +1 -1
  7. package/dist/commonjs/context-resolver.js.map +1 -1
  8. package/dist/commonjs/helper/criteria.d.ts.map +1 -1
  9. package/dist/commonjs/helper/criteria.js.map +1 -1
  10. package/dist/commonjs/hooks.d.ts +13 -0
  11. package/dist/commonjs/hooks.d.ts.map +1 -0
  12. package/dist/commonjs/hooks.js +29 -0
  13. package/dist/commonjs/hooks.js.map +1 -0
  14. package/dist/commonjs/http-client.d.ts.map +1 -1
  15. package/dist/commonjs/http-client.js +26 -0
  16. package/dist/commonjs/http-client.js.map +1 -1
  17. package/dist/commonjs/integration/hono.d.ts +4 -0
  18. package/dist/commonjs/integration/hono.d.ts.map +1 -1
  19. package/dist/commonjs/integration/hono.js +3 -0
  20. package/dist/commonjs/integration/hono.js.map +1 -1
  21. package/dist/commonjs/registration.d.ts +11 -2
  22. package/dist/commonjs/registration.d.ts.map +1 -1
  23. package/dist/commonjs/registration.js +23 -1
  24. package/dist/commonjs/registration.js.map +1 -1
  25. package/dist/commonjs/repository.d.ts +1 -1
  26. package/dist/commonjs/repository.d.ts.map +1 -1
  27. package/dist/commonjs/repository.js.map +1 -1
  28. package/dist/esm/app.d.ts +3 -1
  29. package/dist/esm/app.d.ts.map +1 -1
  30. package/dist/esm/app.js +3 -0
  31. package/dist/esm/app.js.map +1 -1
  32. package/dist/esm/context-resolver.d.ts +1 -1
  33. package/dist/esm/context-resolver.d.ts.map +1 -1
  34. package/dist/esm/context-resolver.js.map +1 -1
  35. package/dist/esm/helper/criteria.d.ts.map +1 -1
  36. package/dist/esm/helper/criteria.js.map +1 -1
  37. package/dist/esm/hooks.d.ts +13 -0
  38. package/dist/esm/hooks.d.ts.map +1 -0
  39. package/dist/esm/hooks.js +25 -0
  40. package/dist/esm/hooks.js.map +1 -0
  41. package/dist/esm/http-client.d.ts.map +1 -1
  42. package/dist/esm/http-client.js +26 -0
  43. package/dist/esm/http-client.js.map +1 -1
  44. package/dist/esm/integration/hono.d.ts +4 -0
  45. package/dist/esm/integration/hono.d.ts.map +1 -1
  46. package/dist/esm/integration/hono.js +3 -0
  47. package/dist/esm/integration/hono.js.map +1 -1
  48. package/dist/esm/registration.d.ts +11 -2
  49. package/dist/esm/registration.d.ts.map +1 -1
  50. package/dist/esm/registration.js +21 -0
  51. package/dist/esm/registration.js.map +1 -1
  52. package/dist/esm/repository.d.ts +1 -1
  53. package/dist/esm/repository.d.ts.map +1 -1
  54. package/dist/esm/repository.js.map +1 -1
  55. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import { ContextResolver } from "./context-resolver.js";
2
+ import { Hooks } from "./hooks.js";
2
3
  import { Registration } from "./registration.js";
3
4
  import type { ShopInterface, ShopRepositoryInterface } from "./repository.js";
4
5
  import { WebCryptoHmacSigner } from "./signer.js";
@@ -8,9 +9,10 @@ import { WebCryptoHmacSigner } from "./signer.js";
8
9
  export declare class AppServer<Shop extends ShopInterface = ShopInterface> {
9
10
  cfg: Configuration;
10
11
  repository: ShopRepositoryInterface<Shop>;
11
- registration: Registration;
12
+ registration: Registration<Shop>;
12
13
  contextResolver: ContextResolver<Shop>;
13
14
  signer: WebCryptoHmacSigner;
15
+ hooks: Hooks<Shop>;
14
16
  constructor(cfg: Configuration, repository: ShopRepositoryInterface<Shop>);
15
17
  }
16
18
  interface Configuration {
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;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ACvC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;gBAGlB,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,uBAAuB,CAAC,IAAI,CAAC;CAOjD;AAED,UAAU,aAAa;IACtB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAC;CAC7B"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AppServer = void 0;
4
4
  const context_resolver_js_1 = require("./context-resolver.js");
5
+ const hooks_js_1 = require("./hooks.js");
5
6
  const registration_js_1 = require("./registration.js");
6
7
  const signer_js_1 = require("./signer.js");
7
8
  /**
@@ -13,12 +14,14 @@ class AppServer {
13
14
  registration;
14
15
  contextResolver;
15
16
  signer;
17
+ hooks;
16
18
  constructor(cfg, repository) {
17
19
  this.cfg = cfg;
18
20
  this.repository = repository;
19
21
  this.registration = new registration_js_1.Registration(this);
20
22
  this.contextResolver = new context_resolver_js_1.ContextResolver(this);
21
23
  this.signer = new signer_js_1.WebCryptoHmacSigner();
24
+ this.hooks = new hooks_js_1.Hooks();
22
25
  }
23
26
  }
24
27
  exports.AppServer = AppServer;
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;AAAA,+DAAwD;AACxD,uDAAiD;AAEjD,2CAAkD;AAElD;;GAEG;AACH,MAAa,SAAS;IAMb;IACA;IAND,YAAY,CAAe;IAC3B,eAAe,CAAwB;IACvC,MAAM,CAAsB;IAEnC,YACQ,GAAkB,EAClB,UAAyC;QADzC,QAAG,GAAH,GAAG,CAAe;QAClB,eAAU,GAAV,UAAU,CAA+B;QAEhD,IAAI,CAAC,YAAY,GAAG,IAAI,8BAAY,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,qCAAe,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,IAAI,+BAAmB,EAAE,CAAC;IACzC,CAAC;CACD;AAbD,8BAaC","sourcesContent":["import { ContextResolver } from \"./context-resolver.js\";\nimport { Registration } from \"./registration.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"./repository.js\";\nimport { WebCryptoHmacSigner } from \"./signer.js\";\n\n/**\n * AppServer is the main class, this is where you start your app\n */\nexport class AppServer<Shop extends ShopInterface = ShopInterface> {\n\tpublic registration: Registration;\n\tpublic contextResolver: ContextResolver<Shop>;\n\tpublic signer: WebCryptoHmacSigner;\n\n\tconstructor(\n\t\tpublic cfg: Configuration,\n\t\tpublic repository: ShopRepositoryInterface<Shop>,\n\t) {\n\t\tthis.registration = new Registration(this);\n\t\tthis.contextResolver = new ContextResolver(this);\n\t\tthis.signer = new WebCryptoHmacSigner();\n\t}\n}\n\ninterface Configuration {\n\t/**\n\t * Your app name\n\t */\n\tappName: string;\n\n\t/**\n\t * Your app secret\n\t */\n\tappSecret: string;\n\n\t/**\n\t * URL to authorize callback url\n\t */\n\tauthorizeCallbackUrl: string;\n}\n"]}
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;AAAA,+DAAwD;AACxD,yCAAmC;AACnC,uDAAiD;AAEjD,2CAAkD;AAElD;;GAEG;AACH,MAAa,SAAS;IAOb;IACA;IAPD,YAAY,CAAqB;IACjC,eAAe,CAAwB;IACvC,MAAM,CAAsB;IAC5B,KAAK,CAAc;IAE1B,YACQ,GAAkB,EAClB,UAAyC;QADzC,QAAG,GAAH,GAAG,CAAe;QAClB,eAAU,GAAV,UAAU,CAA+B;QAEhD,IAAI,CAAC,YAAY,GAAG,IAAI,8BAAY,CAAO,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,eAAe,GAAG,IAAI,qCAAe,CAAO,IAAI,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,GAAG,IAAI,+BAAmB,EAAE,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,gBAAK,EAAQ,CAAC;IAChC,CAAC;CACD;AAfD,8BAeC","sourcesContent":["import { ContextResolver } from \"./context-resolver.js\";\nimport { Hooks } from \"./hooks.js\";\nimport { Registration } from \"./registration.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"./repository.js\";\nimport { WebCryptoHmacSigner } from \"./signer.js\";\n\n/**\n * AppServer is the main class, this is where you start your app\n */\nexport class AppServer<Shop extends ShopInterface = ShopInterface> {\n\tpublic registration: Registration<Shop>;\n\tpublic contextResolver: ContextResolver<Shop>;\n\tpublic signer: WebCryptoHmacSigner;\n\tpublic hooks: Hooks<Shop>;\n\n\tconstructor(\n\t\tpublic cfg: Configuration,\n\t\tpublic repository: ShopRepositoryInterface<Shop>,\n\t) {\n\t\tthis.registration = new Registration<Shop>(this);\n\t\tthis.contextResolver = new ContextResolver<Shop>(this);\n\t\tthis.signer = new WebCryptoHmacSigner();\n\t\tthis.hooks = new Hooks<Shop>();\n\t}\n}\n\ninterface Configuration {\n\t/**\n\t * Your app name\n\t */\n\tappName: string;\n\n\t/**\n\t * Your app secret\n\t */\n\tappSecret: string;\n\n\t/**\n\t * URL to authorize callback url\n\t */\n\tauthorizeCallbackUrl: string;\n}\n"]}
@@ -7,7 +7,7 @@ import type { ShopInterface } from "./repository.js";
7
7
  */
8
8
  export declare class ContextResolver<Shop extends ShopInterface = ShopInterface> {
9
9
  private app;
10
- constructor(app: AppServer);
10
+ constructor(app: AppServer<Shop>);
11
11
  /**
12
12
  * Create a context from a request body
13
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"context-resolver.d.ts","sourceRoot":"","sources":["../../src/context-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,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H,OAAO,IAAI,OAAO,CACjB,IAAY,EACZ,YAAuB,EACvB,IAAI,2BAAU,CAAC,IAAI,CAAC,CACpB,CAAC;IACH,CAAC;CACD;AArFD,0CAqFC;AAED;;GAEG;AACH,MAAa,OAAO;IAKX;IACA;IACA;IAHR,YACQ,IAAU,EACV,OAAgB,EAChB,UAAsB;QAFtB,SAAI,GAAJ,IAAI,CAAM;QACV,YAAO,GAAP,OAAO,CAAS;QAChB,eAAU,GAAV,UAAU,CAAY;IAC3B,CAAC;CACJ;AATD,0BASC","sourcesContent":["import type { AppServer } from \"./app.js\";\nimport { HttpClient } from \"./http-client.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\n/**\n * ContextResolver is a helper class to create a Context object from a request.\n * The context contains the shop, the payload and an instance of the HttpClient\n */\nexport class ContextResolver<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(private app: AppServer) {}\n\n\t/**\n\t * Create a context from a request body\n\t */\n\tpublic async fromAPI<Payload = unknown>(\n\t\treq: Request,\n\t): Promise<Context<Shop, Payload>> {\n\t\tconst webHookContent = await req.text();\n\t\tconst webHookBody = JSON.parse(webHookContent);\n\n\t\tif (\n\t\t\twebHookBody.source === undefined ||\n\t\t\twebHookBody.source.shopId === undefined\n\t\t) {\n\t\t\tthrow new Error(\"Invalid request\");\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(\n\t\t\twebHookBody.source.shopId,\n\t\t);\n\n\t\tif (shop === null) {\n\t\t\tthrow new Error(`Cannot find shop by id ${webHookBody.source.shopId}`);\n\t\t}\n\n\t\tconst signature = req.headers.get(\"shopware-shop-signature\");\n\n\t\tif (signature === null) {\n\t\t\tthrow new Error(\"Missing shopware-shop-signature header\");\n\t\t}\n\n\t\tif (\n\t\t\t!(await this.app.signer.verify(\n\t\t\t\tsignature,\n\t\t\t\twebHookContent,\n\t\t\t\tshop.getShopSecret(),\n\t\t\t))\n\t\t) {\n\t\t\tthrow new Error(\"Invalid signature\");\n\t\t}\n\n\t\treturn new Context<Shop, Payload>(\n\t\t\tshop as Shop,\n\t\t\twebHookBody,\n\t\t\tnew HttpClient(shop),\n\t\t);\n\t}\n\n\t/**\n\t * Create a context from a request query parameters\n\t * This is usually a module request from the shopware admin\n\t */\n\tpublic async fromBrowser<Payload = unknown>(\n\t\treq: Request,\n\t): Promise<Context<Shop, Payload>> {\n\t\tconst url = new URL(req.url);\n\n\t\tconst shopId = url.searchParams.get(\"shop-id\");\n\n\t\tif (shopId === null) {\n\t\t\tthrow new Error(\"Missing shop-id query parameter\");\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(shopId);\n\n\t\tif (shop === null) {\n\t\t\tthrow new Error(`Cannot find shop by id ${shopId}`);\n\t\t}\n\n\t\tawait this.app.signer.verifyGetRequest(req, shop.getShopSecret());\n\n\t\tconst paramsObject: Record<string, string> = {};\n\n\t\turl.searchParams.forEach((value, key) => {\n\t\t\tparamsObject[key] = value;\n\t\t});\n\n\t\treturn new Context<Shop, Payload>(\n\t\t\tshop as Shop,\n\t\t\tparamsObject as Payload,\n\t\t\tnew HttpClient(shop),\n\t\t);\n\t}\n}\n\n/**\n * Context is the parsed data from the request\n */\nexport class Context<\n\tShop extends ShopInterface = ShopInterface,\n\tPayload = unknown,\n> {\n\tconstructor(\n\t\tpublic shop: Shop,\n\t\tpublic payload: Payload,\n\t\tpublic httpClient: HttpClient,\n\t) {}\n}\n"]}
1
+ {"version":3,"file":"context-resolver.js","sourceRoot":"","sources":["../../src/context-resolver.ts"],"names":[],"mappings":";;;AACA,qDAA8C;AAG9C;;;GAGG;AACH,MAAa,eAAe;IACP;IAApB,YAAoB,GAAoB;QAApB,QAAG,GAAH,GAAG,CAAiB;IAAG,CAAC;IAE5C;;OAEG;IACI,KAAK,CAAC,OAAO,CACnB,GAAY;QAEZ,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QA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MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE3D,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAElE,MAAM,YAAY,GAA2B,EAAE,CAAC;QAEhD,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACvC,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,OAAO,CACjB,IAAY,EACZ,YAAuB,EACvB,IAAI,2BAAU,CAAC,IAAI,CAAC,CACpB,CAAC;IACH,CAAC;CACD;AArFD,0CAqFC;AAED;;GAEG;AACH,MAAa,OAAO;IAKX;IACA;IACA;IAHR,YACQ,IAAU,EACV,OAAgB,EAChB,UAAsB;QAFtB,SAAI,GAAJ,IAAI,CAAM;QACV,YAAO,GAAP,OAAO,CAAS;QAChB,eAAU,GAAV,UAAU,CAAY;IAC3B,CAAC;CACJ;AATD,0BASC","sourcesContent":["import type { AppServer } from \"./app.js\";\nimport { HttpClient } from \"./http-client.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\n/**\n * ContextResolver is a helper class to create a Context object from a request.\n * The context contains the shop, the payload and an instance of the HttpClient\n */\nexport class ContextResolver<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(private app: AppServer<Shop>) {}\n\n\t/**\n\t * Create a context from a request body\n\t */\n\tpublic async fromAPI<Payload = unknown>(\n\t\treq: Request,\n\t): Promise<Context<Shop, Payload>> {\n\t\tconst webHookContent = await req.text();\n\t\tconst webHookBody = JSON.parse(webHookContent);\n\n\t\tif (\n\t\t\twebHookBody.source === undefined ||\n\t\t\twebHookBody.source.shopId === undefined\n\t\t) {\n\t\t\tthrow new Error(\"Invalid request\");\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(\n\t\t\twebHookBody.source.shopId,\n\t\t);\n\n\t\tif (shop === null) {\n\t\t\tthrow new Error(`Cannot find shop by id ${webHookBody.source.shopId}`);\n\t\t}\n\n\t\tconst signature = req.headers.get(\"shopware-shop-signature\");\n\n\t\tif (signature === null) {\n\t\t\tthrow new Error(\"Missing shopware-shop-signature header\");\n\t\t}\n\n\t\tif (\n\t\t\t!(await this.app.signer.verify(\n\t\t\t\tsignature,\n\t\t\t\twebHookContent,\n\t\t\t\tshop.getShopSecret(),\n\t\t\t))\n\t\t) {\n\t\t\tthrow new Error(\"Invalid signature\");\n\t\t}\n\n\t\treturn new Context<Shop, Payload>(\n\t\t\tshop as Shop,\n\t\t\twebHookBody,\n\t\t\tnew HttpClient(shop),\n\t\t);\n\t}\n\n\t/**\n\t * Create a context from a request query parameters\n\t * This is usually a module request from the shopware admin\n\t */\n\tpublic async fromBrowser<Payload = unknown>(\n\t\treq: Request,\n\t): Promise<Context<Shop, Payload>> {\n\t\tconst url = new URL(req.url);\n\n\t\tconst shopId = url.searchParams.get(\"shop-id\");\n\n\t\tif (shopId === null) {\n\t\t\tthrow new Error(\"Missing shop-id query parameter\");\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(shopId);\n\n\t\tif (shop === null) {\n\t\t\tthrow new Error(`Cannot find shop by id ${shopId}`);\n\t\t}\n\n\t\tawait this.app.signer.verifyGetRequest(req, shop.getShopSecret());\n\n\t\tconst paramsObject: Record<string, string> = {};\n\n\t\turl.searchParams.forEach((value, key) => {\n\t\t\tparamsObject[key] = value;\n\t\t});\n\n\t\treturn new Context<Shop, Payload>(\n\t\t\tshop as Shop,\n\t\t\tparamsObject as Payload,\n\t\t\tnew HttpClient(shop),\n\t\t);\n\t}\n}\n\n/**\n * Context is the parsed data from the request\n */\nexport class Context<\n\tShop extends ShopInterface = ShopInterface,\n\tPayload = unknown,\n> {\n\tconstructor(\n\t\tpublic shop: Shop,\n\t\tpublic payload: Payload,\n\t\tpublic httpClient: HttpClient,\n\t) {}\n}\n"]}
@@ -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,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;YACrB,GAAG,CAAC,EAAE,MAAM,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AO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACD;AAvjBD,4BAujBC","sourcesContent":["export enum TotalCountMode {\n\t/* No total count will be selected. Should be used if no pagination required (fastest) */\n\tNO_TOTAL_COUNT = 0,\n\t/* Exact total count will be selected. Should be used if an exact pagination is required (slow) */\n\tEXACT_TOTAL_COUNT = 1,\n\t/* Fetches limit * 5 + 1. Should be used if pagination can work with \"next page exists\" (fast) */\n\tPAGINATION_TOTAL_COUNT = 2,\n}\n\ninterface Filters {\n\tcontains: {\n\t\ttype: \"contains\";\n\t\tfield: string;\n\t\tvalue: string;\n\t};\n\tprefix: {\n\t\ttype: \"prefix\";\n\t\tfield: string;\n\t\tvalue: string;\n\t};\n\tsuffix: {\n\t\ttype: \"suffix\";\n\t\tfield: string;\n\t\tvalue: string;\n\t};\n\tequalsAny: {\n\t\ttype: \"equalsAny\";\n\t\tfield: string;\n\t\tvalue: (string | number | boolean | null)[];\n\t};\n\tequals: {\n\t\ttype: \"equals\";\n\t\tfield: string;\n\t\tvalue: string | number | boolean | null;\n\t};\n\trange: {\n\t\ttype: \"range\";\n\t\tfield: string;\n\t\tparameters: {\n\t\t\tlte?: string | number;\n\t\t\tlt?: string | number;\n\t\t\tgte?: string | number;\n\t\t\tgt?: string | number;\n\t\t};\n\t};\n\tnot: {\n\t\ttype: \"not\";\n\t\toperator: \"and\" | \"AND\" | \"or\" | \"OR\";\n\t\tqueries: SingleFilter[];\n\t};\n\tmulti: {\n\t\ttype: \"multi\";\n\t\toperator: \"and\" | \"AND\" | \"or\" | \"OR\";\n\t\tqueries: SingleFilter[];\n\t};\n}\n\ninterface Aggregations {\n\thistogram: {\n\t\ttype: \"histogram\";\n\t\tname: string;\n\t\tfield: string;\n\t\tinterval: string | null;\n\t\tformat: string | null;\n\t\taggregation: Aggregation | null;\n\t\ttimeZone: string | null;\n\t};\n\tterms: {\n\t\ttype: \"terms\";\n\t\tname: string;\n\t\tfield: string;\n\t\tlimit?: number | null;\n\t\tsort?: Sorting | null;\n\t\taggregation?: Aggregation | null;\n\t};\n\tsum: {\n\t\ttype: \"sum\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tstats: {\n\t\ttype: \"stats\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tmin: {\n\t\ttype: \"min\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tmax: {\n\t\ttype: \"max\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tcount: {\n\t\ttype: \"count\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tavg: {\n\t\ttype: \"avg\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tentity: {\n\t\ttype: \"entity\";\n\t\tname: string;\n\t\tfield: string;\n\t\tdefinition: string;\n\t};\n\tfilter: {\n\t\ttype: \"filter\";\n\t\tname: string;\n\t\tfilter: SingleFilter[];\n\t\taggregation: Aggregation;\n\t};\n}\n\ntype ValueOf<T> = T[keyof T];\nexport type SingleFilter = ValueOf<Filters>;\ntype Aggregation = ValueOf<Aggregations>;\n\ninterface Include {\n\t[entityName: string]: string[];\n}\ninterface Association {\n\tassociation: string;\n\tcriteria: Criteria;\n}\ninterface Query {\n\tscore: number;\n\tquery: SingleFilter;\n\tscoreField?: string;\n}\ninterface Sorting {\n\tfield: string;\n\torder: \"ASC\" | \"DESC\";\n\tnaturalSorting: boolean;\n\ttype?: string;\n}\ntype GroupField = string;\ninterface RequestParams {\n\tids?: string[];\n\tpage?: number;\n\tlimit?: number;\n\tterm?: string;\n\tquery?: Query[];\n\tfilter?: SingleFilter[];\n\t\"post-filter\"?: SingleFilter[];\n\tsort?: Sorting[];\n\taggregations?: Aggregation[];\n\tgrouping?: string[];\n\tfields?: string[];\n\tassociations?: {\n\t\t[association: string]: RequestParams;\n\t};\n\tincludes?: Include;\n\t\"total-count-mode\"?: TotalCountMode;\n}\n\nexport class Criteria {\n\ttitle: string | null;\n\n\tpage: number | null;\n\n\tlimit: number | null;\n\n\tterm: string | null;\n\n\tfilters: SingleFilter[];\n\n\tids: string[];\n\n\tqueries: Query[];\n\n\tassociations: Association[];\n\n\tpostFilter: SingleFilter[];\n\n\tsortings: Sorting[];\n\n\taggregations: Aggregation[];\n\n\tgrouping: string[];\n\n\tfields: string[];\n\n\ttotalCountMode: TotalCountMode | null;\n\n\tincludes: Include | null;\n\n\tconstructor(ids: string[] = []) {\n\t\tthis.page = null;\n\t\tthis.limit = null;\n\t\tthis.term = null;\n\t\tthis.title = null;\n\t\tthis.filters = [];\n\t\tthis.includes = null;\n\t\tthis.ids = ids;\n\t\tthis.queries = [];\n\t\tthis.associations = [];\n\t\tthis.postFilter = [];\n\t\tthis.sortings = [];\n\t\tthis.aggregations = [];\n\t\tthis.grouping = [];\n\t\tthis.fields = [];\n\t\tthis.totalCountMode = null;\n\t}\n\n\t/**\n\t * Parses the current criteria and generates an object which can be provided to the api\n\t */\n\ttoPayload(): RequestParams {\n\t\tconst params: RequestParams = {};\n\n\t\tif (this.ids.length > 0) {\n\t\t\tparams.ids = this.ids;\n\t\t}\n\t\tif (this.page !== null) {\n\t\t\tparams.page = this.page;\n\t\t}\n\t\tif (this.limit !== null) {\n\t\t\tparams.limit = this.limit;\n\t\t}\n\t\tif (this.term !== null) {\n\t\t\tparams.term = this.term;\n\t\t}\n\t\tif (this.queries.length > 0) {\n\t\t\tparams.query = this.queries;\n\t\t}\n\t\tif (this.filters.length > 0) {\n\t\t\tparams.filter = this.filters;\n\t\t}\n\t\tif (this.postFilter.length > 0) {\n\t\t\tparams[\"post-filter\"] = this.postFilter;\n\t\t}\n\t\tif (this.sortings.length > 0) {\n\t\t\tparams.sort = this.sortings;\n\t\t}\n\t\tif (this.aggregations.length > 0) {\n\t\t\tparams.aggregations = this.aggregations;\n\t\t}\n\t\tif (this.grouping.length > 0) {\n\t\t\tparams.grouping = this.grouping;\n\t\t}\n\t\tif (this.fields.length > 0) {\n\t\t\tparams.fields = this.fields;\n\t\t}\n\t\tif (this.associations.length > 0) {\n\t\t\tparams.associations = {};\n\n\t\t\tfor (const item of this.associations) {\n\t\t\t\tif (!params.associations) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tparams.associations[item.association] = item.criteria.toPayload();\n\t\t\t}\n\t\t}\n\t\tif (this.includes !== null) {\n\t\t\tparams.includes = this.includes;\n\t\t}\n\n\t\tif (this.totalCountMode !== null) {\n\t\t\tparams[\"total-count-mode\"] = this.totalCountMode;\n\t\t}\n\n\t\treturn params;\n\t}\n\n\t/**\n\t * Allows to provide a title for the criteria. This title will be shown in the `repository.search` request url so it can be used for debugging in network's tab\n\t */\n\tsetTitle(title: string): this {\n\t\tthis.title = title;\n\t\treturn this;\n\t}\n\n\tgetTitle(): string | null {\n\t\treturn this.title;\n\t}\n\t/**\n\t * Allows to provide a list of ids which are used as a filter\n\t */\n\tsetIds(ids: string[]): this {\n\t\tthis.ids = ids;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows to configure the total value of a search result.\n\t * 0 - no total count will be selected. Should be used if no pagination required (fastest)\n\t * 1 - exact total count will be selected. Should be used if an exact pagination is required (slow)\n\t * 2 - fetches limit * 5 + 1. Should be used if pagination can work with \"next page exists\" (fast)\n\t */\n\tsetTotalCountMode(mode: TotalCountMode): this {\n\t\tif (typeof mode !== \"number\") {\n\t\t\tthis.totalCountMode = null;\n\t\t}\n\n\t\tthis.totalCountMode = mode < 0 || mode > 2 ? null : mode;\n\t\treturn this;\n\t}\n\n\tsetPage(page: number): this {\n\t\tthis.page = page;\n\t\treturn this;\n\t}\n\n\tsetLimit(limit: number): this {\n\t\tthis.limit = limit;\n\t\treturn this;\n\t}\n\n\tsetTerm(term: string): this {\n\t\tthis.term = term;\n\t\treturn this;\n\t}\n\n\taddFilter(filter: SingleFilter): this {\n\t\tthis.filters.push(filter);\n\n\t\treturn this;\n\t}\n\n\taddIncludes(include: Include): this {\n\t\tfor (const [entityName, includeValues] of Object.entries(include)) {\n\t\t\tif (this.includes === null) {\n\t\t\t\tthis.includes = {};\n\t\t\t}\n\t\t\tif (!this.includes[entityName]) {\n\t\t\t\tthis.includes[entityName] = [];\n\t\t\t}\n\n\t\t\tthis.includes[entityName].push(...includeValues);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the provided filter as post filter.\n\t * Post filter will be considered for the documents query but not for the aggregations.\n\t */\n\taddPostFilter(filter: SingleFilter): this {\n\t\tthis.postFilter.push(filter);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows to add different sortings for the criteria, to sort the entity result.\n\t */\n\taddSorting(sorting: Sorting): this {\n\t\tthis.sortings.push(sorting);\n\t\treturn this;\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Query\\ScoreQuery.\n\t * These queries are used to search for documents and score them with a ranking\n\t */\n\taddQuery(\n\t\tfilter: SingleFilter,\n\t\tscore: number,\n\t\tscoreField: string | null = null,\n\t): this {\n\t\tconst query: Query = { score: score, query: filter };\n\n\t\tif (scoreField) {\n\t\t\tquery.scoreField = scoreField;\n\t\t}\n\n\t\tthis.queries.push(query);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows grouping the result by a specific field\n\t */\n\taddGrouping(field: string): this {\n\t\tthis.grouping.push(field);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows loading partial fields for the result.\n\t */\n\taddFields(...field: string[]): this {\n\t\tthis.fields.push(...field);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * @param {Object} aggregation\n\t */\n\taddAggregation(aggregation: Aggregation): this {\n\t\tthis.aggregations.push(aggregation);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Ensures that a criterion is created for each segment of the passed path.\n\t * Existing Criteria objects are not overwritten.\n\t * Returns the own instance\n\t */\n\taddAssociation(path: string): this {\n\t\tthis.getAssociation(path);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Ensures that a criterion is created for each segment of the passed path.\n\t * Returns the criteria instance of the last path segment\n\t */\n\tgetAssociation(path: string): Criteria {\n\t\tconst parts = path.split(\".\");\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tlet criteria = this;\n\n\t\tfor (const part of parts) {\n\t\t\tif (!criteria.hasAssociation(part)) {\n\t\t\t\tcriteria.associations.push({\n\t\t\t\t\tassociation: part,\n\t\t\t\t\tcriteria: new Criteria(),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// @ts-expect-error - another this instance\n\t\t\tcriteria = criteria.getAssociationCriteria(part);\n\t\t}\n\n\t\treturn criteria;\n\t}\n\n\tprivate getAssociationCriteria(part: string): Criteria {\n\t\tlet criteria = null;\n\n\t\tfor (const association of this.associations) {\n\t\t\tif (association.association === part) {\n\t\t\t\tcriteria = association.criteria;\n\t\t\t}\n\t\t}\n\n\t\tif (!criteria) {\n\t\t\tcriteria = new Criteria();\n\t\t\tthis.associations.push({\n\t\t\t\tassociation: part,\n\t\t\t\tcriteria,\n\t\t\t});\n\t\t}\n\n\t\treturn criteria;\n\t}\n\n\tgetLimit(): number {\n\t\treturn this.limit ?? 0;\n\t}\n\n\tgetPage(): number {\n\t\treturn this.page ?? 0;\n\t}\n\n\thasAssociation(property: string): boolean {\n\t\treturn this.associations.some((assocation) => {\n\t\t\treturn assocation.association === property;\n\t\t});\n\t}\n\n\t/**\n\t * Resets the sorting parameter\n\t */\n\tresetSorting(): void {\n\t\tthis.sortings = [];\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\AvgAggregation\n\t * Allows to calculate the avg value for the provided field\n\t */\n\tstatic avg(name: string, field: string): Aggregations[\"avg\"] {\n\t\treturn { type: \"avg\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\CountAggregation\n\t * Allows to calculate the count value for the provided field\n\t */\n\tstatic count(name: string, field: string): Aggregations[\"count\"] {\n\t\treturn { type: \"count\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\MaxAggregation\n\t * Allows to calculate the max value for the provided field\n\t */\n\tstatic max(name: string, field: string): Aggregations[\"max\"] {\n\t\treturn { type: \"max\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\MinAggregation\n\t * Allows to calculate the min value for the provided field\n\t */\n\tstatic min(name: string, field: string): Aggregations[\"min\"] {\n\t\treturn { type: \"min\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\StatsAggregation\n\t * Allows to calculate the sum, max, min, avg, count values for the provided field\n\t */\n\tstatic stats(name: string, field: string): Aggregations[\"stats\"] {\n\t\treturn { type: \"stats\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\SumAggregation\n\t * Allows to calculate the sum value for the provided field\n\t */\n\tstatic sum(name: string, field: string): Aggregations[\"sum\"] {\n\t\treturn { type: \"sum\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Bucket\\TermsAggregation\n\t * Allows to fetch term buckets for the provided field\n\t */\n\tstatic terms(\n\t\tname: string,\n\t\tfield: string,\n\t\tlimit: number | null = null,\n\t\tsort: Sorting | null = null,\n\t\taggregation: Aggregation | null = null,\n\t): Aggregations[\"terms\"] {\n\t\treturn { type: \"terms\", name, field, limit, sort, aggregation };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\EntityAggregation\n\t * Allows to filter an aggregation result\n\t */\n\tstatic entityAggregation(\n\t\tname: string,\n\t\tfield: string,\n\t\tdefinition: string,\n\t): Aggregations[\"entity\"] {\n\t\treturn { type: \"entity\", name, field, definition };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Bucket\\FilterAggregation\n\t * Allows to filter an aggregation result\n\t */\n\tstatic filter(\n\t\tname: string,\n\t\tfilter: SingleFilter[],\n\t\taggregation: Aggregation,\n\t): Aggregations[\"filter\"] {\n\t\treturn { type: \"filter\", name, filter, aggregation };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Bucket\\DateHistogramAggregation\n\t * Allows to fetch date buckets for the provided date interval\n\t */\n\tstatic histogram(\n\t\tname: string,\n\t\tfield: string,\n\t\tinterval: string | null = null,\n\t\tformat: string | null = null,\n\t\taggregation: Aggregation | null = null,\n\t\ttimeZone: string | null = null,\n\t): Aggregations[\"histogram\"] {\n\t\treturn {\n\t\t\ttype: \"histogram\",\n\t\t\tname,\n\t\t\tfield,\n\t\t\tinterval,\n\t\t\tformat,\n\t\t\taggregation,\n\t\t\ttimeZone,\n\t\t};\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Sorting\\FieldSorting.\n\t * Allows to sort the documents by the provided field\n\t */\n\tstatic sort(\n\t\tfield: string,\n\t\torder: Sorting[\"order\"] = \"ASC\",\n\t\tnaturalSorting = false,\n\t): Sorting {\n\t\treturn { field, order, naturalSorting };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Sorting\\FieldSorting.\n\t * Allows to sort the documents by the provided field naturally\n\t */\n\tstatic naturalSorting(\n\t\tfield: string,\n\t\torder: Sorting[\"order\"] = \"ASC\",\n\t): Sorting {\n\t\treturn { field, order, naturalSorting: true };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Sorting\\CountSorting.\n\t * Allows to sort the documents by counting associations via the provided field\n\t *\n\t * Sql representation: `ORDER BY COUNT({field}) {order}`\n\t */\n\tstatic countSorting(field: string, order: Sorting[\"order\"] = \"ASC\"): Sorting {\n\t\treturn { field, order, naturalSorting: false, type: \"count\" };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\ContainsFilter.\n\t * This allows to filter documents where the value are contained in the provided field.\n\t *\n\t * Sql representation: `{field} LIKE %{value}%`\n\t */\n\tstatic contains(field: string, value: string): Filters[\"contains\"] {\n\t\treturn { type: \"contains\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\PrefixFilter.\n\t * This allows to filter documents where the value marks the beginning of the provided field.\n\t *\n\t * Sql representation: `{field} LIKE {value}%`\n\t */\n\tstatic prefix(field: string, value: string): Filters[\"prefix\"] {\n\t\treturn { type: \"prefix\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\SuffixFilter.\n\t * This allows to filter documents where the value marks the end of the provided field.\n\t *\n\t * Sql representation: `{field} LIKE %{value}`\n\t */\n\tstatic suffix(field: string, value: string): Filters[\"suffix\"] {\n\t\treturn { type: \"suffix\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\EqualsAnyFilter.\n\t * This allows to filter documents where the field matches one of the provided values\n\t *\n\t * Sql representation: `{field} IN ({value}, {value})`\n\t */\n\tstatic equalsAny(\n\t\tfield: string,\n\t\tvalue: (string | number | boolean | null)[],\n\t): Filters[\"equalsAny\"] {\n\t\treturn { type: \"equalsAny\", field, value: value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\RangeFilter.\n\t * This allows to filter documents where the field matches a defined range\n\t *\n\t * Sql representation: `{field} >= {value}`, `{field} <= {value}`, ...\n\t */\n\tstatic range(\n\t\tfield: string,\n\t\trange: Filters[\"range\"][\"parameters\"],\n\t): Filters[\"range\"] {\n\t\treturn { type: \"range\", field, parameters: range };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\EqualsFilter.\n\t * This allows to filter documents where the field matches a defined range\n\t *\n\t * Sql representation: `{field} = {value}`\n\t */\n\tstatic equals(\n\t\tfield: string,\n\t\tvalue: string | number | boolean | null,\n\t): Filters[\"equals\"] {\n\t\treturn { type: \"equals\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\NotFilter.\n\t * This allows to filter documents which not matches for the provided filters\n\t * All above listed queries can be provided (equals, equalsAny, range, contains)\n\t *\n\t * Sql representation: `NOT({query} {operator} {query} {operator} {query})`\n\t *\n\t * @param {string} operator - and/or\n\t * @param {array} queries\n\t *\n\t * @returns {Object}\n\t */\n\tstatic not(\n\t\toperator: Filters[\"not\"][\"operator\"],\n\t\tqueries: SingleFilter[] = [],\n\t): Filters[\"not\"] {\n\t\treturn { type: \"not\", operator: operator, queries: queries };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\NotFilter.\n\t * This allows to filter documents which matches for the provided filters\n\t * All above listed queries can be provided (equals, equalsAny, range, contains)\n\t *\n\t * Sql representation: `({query} {operator} {query} {operator} {query})`\n\t *\n\t * @param {string} operator - and/or\n\t * @param {array} queries\n\t *\n\t * @returns {Object}\n\t */\n\tstatic multi(\n\t\toperator: Filters[\"multi\"][\"operator\"],\n\t\tqueries: SingleFilter[] = [],\n\t): Filters[\"multi\"] {\n\t\treturn { type: \"multi\", operator, queries };\n\t}\n}\n"]}
1
+ {"version":3,"file":"criteria.js","sourceRoot":"","sources":["../../../src/helper/criteria.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAOX;AAPD,WAAY,cAAc;IACzB,yFAAyF;IACzF,uEAAkB,CAAA;IAClB,kGAAkG;IAClG,6EAAqB,CAAA;IACrB,iGAAiG;IACjG,uFAA0B,CAAA;AAC3B,CAAC,EAPW,cAAc,8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,KAAK,EAAE,KAAK,EAAE,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CACf,KAAa,EACb,KAA2C;QAE3C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CACX,KAAa,EACb,KAAqC;QAErC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CACZ,KAAa,EACb,KAAuC;QAEvC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACzC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,GAAG,CACT,QAAoC,EACpC,UAA0B,EAAE;QAE5B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC9D,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,CACX,QAAsC,EACtC,UAA0B,EAAE;QAE5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACD;AAvjBD,4BAujBC","sourcesContent":["export enum TotalCountMode {\n\t/* No total count will be selected. Should be used if no pagination required (fastest) */\n\tNO_TOTAL_COUNT = 0,\n\t/* Exact total count will be selected. Should be used if an exact pagination is required (slow) */\n\tEXACT_TOTAL_COUNT = 1,\n\t/* Fetches limit * 5 + 1. Should be used if pagination can work with \"next page exists\" (fast) */\n\tPAGINATION_TOTAL_COUNT = 2,\n}\n\ninterface Filters {\n\tcontains: {\n\t\ttype: \"contains\";\n\t\tfield: string;\n\t\tvalue: string;\n\t};\n\tprefix: {\n\t\ttype: \"prefix\";\n\t\tfield: string;\n\t\tvalue: string;\n\t};\n\tsuffix: {\n\t\ttype: \"suffix\";\n\t\tfield: string;\n\t\tvalue: string;\n\t};\n\tequalsAny: {\n\t\ttype: \"equalsAny\";\n\t\tfield: string;\n\t\tvalue: (string | number | boolean | null)[];\n\t};\n\tequals: {\n\t\ttype: \"equals\";\n\t\tfield: string;\n\t\tvalue: string | number | boolean | null;\n\t};\n\trange: {\n\t\ttype: \"range\";\n\t\tfield: string;\n\t\tparameters: {\n\t\t\tlte?: string | number;\n\t\t\tlt?: string | number;\n\t\t\tgte?: string | number;\n\t\t\tgt?: string | number;\n\t\t};\n\t};\n\tnot: {\n\t\ttype: \"not\";\n\t\toperator: \"and\" | \"AND\" | \"or\" | \"OR\";\n\t\tqueries: SingleFilter[];\n\t};\n\tmulti: {\n\t\ttype: \"multi\";\n\t\toperator: \"and\" | \"AND\" | \"or\" | \"OR\";\n\t\tqueries: SingleFilter[];\n\t};\n}\n\ninterface Aggregations {\n\thistogram: {\n\t\ttype: \"histogram\";\n\t\tname: string;\n\t\tfield: string;\n\t\tinterval: string | null;\n\t\tformat: string | null;\n\t\taggregation: Aggregation | null;\n\t\ttimeZone: string | null;\n\t};\n\tterms: {\n\t\ttype: \"terms\";\n\t\tname: string;\n\t\tfield: string;\n\t\tlimit?: number | null;\n\t\tsort?: Sorting | null;\n\t\taggregation?: Aggregation | null;\n\t};\n\tsum: {\n\t\ttype: \"sum\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tstats: {\n\t\ttype: \"stats\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tmin: {\n\t\ttype: \"min\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tmax: {\n\t\ttype: \"max\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tcount: {\n\t\ttype: \"count\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tavg: {\n\t\ttype: \"avg\";\n\t\tname: string;\n\t\tfield: string;\n\t};\n\tentity: {\n\t\ttype: \"entity\";\n\t\tname: string;\n\t\tfield: string;\n\t\tdefinition: string;\n\t};\n\tfilter: {\n\t\ttype: \"filter\";\n\t\tname: string;\n\t\tfilter: SingleFilter[];\n\t\taggregation: Aggregation;\n\t};\n}\n\ntype ValueOf<T> = T[keyof T];\nexport type SingleFilter = ValueOf<Filters>;\ntype Aggregation = ValueOf<Aggregations>;\n\ninterface Include {\n\t[entityName: string]: string[];\n}\ninterface Association {\n\tassociation: string;\n\tcriteria: Criteria;\n}\ninterface Query {\n\tscore: number;\n\tquery: SingleFilter;\n\tscoreField?: string;\n}\ninterface Sorting {\n\tfield: string;\n\torder: \"ASC\" | \"DESC\";\n\tnaturalSorting: boolean;\n\ttype?: string;\n}\ninterface RequestParams {\n\tids?: string[];\n\tpage?: number;\n\tlimit?: number;\n\tterm?: string;\n\tquery?: Query[];\n\tfilter?: SingleFilter[];\n\t\"post-filter\"?: SingleFilter[];\n\tsort?: Sorting[];\n\taggregations?: Aggregation[];\n\tgrouping?: string[];\n\tfields?: string[];\n\tassociations?: {\n\t\t[association: string]: RequestParams;\n\t};\n\tincludes?: Include;\n\t\"total-count-mode\"?: TotalCountMode;\n}\n\nexport class Criteria {\n\ttitle: string | null;\n\n\tpage: number | null;\n\n\tlimit: number | null;\n\n\tterm: string | null;\n\n\tfilters: SingleFilter[];\n\n\tids: string[];\n\n\tqueries: Query[];\n\n\tassociations: Association[];\n\n\tpostFilter: SingleFilter[];\n\n\tsortings: Sorting[];\n\n\taggregations: Aggregation[];\n\n\tgrouping: string[];\n\n\tfields: string[];\n\n\ttotalCountMode: TotalCountMode | null;\n\n\tincludes: Include | null;\n\n\tconstructor(ids: string[] = []) {\n\t\tthis.page = null;\n\t\tthis.limit = null;\n\t\tthis.term = null;\n\t\tthis.title = null;\n\t\tthis.filters = [];\n\t\tthis.includes = null;\n\t\tthis.ids = ids;\n\t\tthis.queries = [];\n\t\tthis.associations = [];\n\t\tthis.postFilter = [];\n\t\tthis.sortings = [];\n\t\tthis.aggregations = [];\n\t\tthis.grouping = [];\n\t\tthis.fields = [];\n\t\tthis.totalCountMode = null;\n\t}\n\n\t/**\n\t * Parses the current criteria and generates an object which can be provided to the api\n\t */\n\ttoPayload(): RequestParams {\n\t\tconst params: RequestParams = {};\n\n\t\tif (this.ids.length > 0) {\n\t\t\tparams.ids = this.ids;\n\t\t}\n\t\tif (this.page !== null) {\n\t\t\tparams.page = this.page;\n\t\t}\n\t\tif (this.limit !== null) {\n\t\t\tparams.limit = this.limit;\n\t\t}\n\t\tif (this.term !== null) {\n\t\t\tparams.term = this.term;\n\t\t}\n\t\tif (this.queries.length > 0) {\n\t\t\tparams.query = this.queries;\n\t\t}\n\t\tif (this.filters.length > 0) {\n\t\t\tparams.filter = this.filters;\n\t\t}\n\t\tif (this.postFilter.length > 0) {\n\t\t\tparams[\"post-filter\"] = this.postFilter;\n\t\t}\n\t\tif (this.sortings.length > 0) {\n\t\t\tparams.sort = this.sortings;\n\t\t}\n\t\tif (this.aggregations.length > 0) {\n\t\t\tparams.aggregations = this.aggregations;\n\t\t}\n\t\tif (this.grouping.length > 0) {\n\t\t\tparams.grouping = this.grouping;\n\t\t}\n\t\tif (this.fields.length > 0) {\n\t\t\tparams.fields = this.fields;\n\t\t}\n\t\tif (this.associations.length > 0) {\n\t\t\tparams.associations = {};\n\n\t\t\tfor (const item of this.associations) {\n\t\t\t\tif (!params.associations) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tparams.associations[item.association] = item.criteria.toPayload();\n\t\t\t}\n\t\t}\n\t\tif (this.includes !== null) {\n\t\t\tparams.includes = this.includes;\n\t\t}\n\n\t\tif (this.totalCountMode !== null) {\n\t\t\tparams[\"total-count-mode\"] = this.totalCountMode;\n\t\t}\n\n\t\treturn params;\n\t}\n\n\t/**\n\t * Allows to provide a title for the criteria. This title will be shown in the `repository.search` request url so it can be used for debugging in network's tab\n\t */\n\tsetTitle(title: string): this {\n\t\tthis.title = title;\n\t\treturn this;\n\t}\n\n\tgetTitle(): string | null {\n\t\treturn this.title;\n\t}\n\t/**\n\t * Allows to provide a list of ids which are used as a filter\n\t */\n\tsetIds(ids: string[]): this {\n\t\tthis.ids = ids;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows to configure the total value of a search result.\n\t * 0 - no total count will be selected. Should be used if no pagination required (fastest)\n\t * 1 - exact total count will be selected. Should be used if an exact pagination is required (slow)\n\t * 2 - fetches limit * 5 + 1. Should be used if pagination can work with \"next page exists\" (fast)\n\t */\n\tsetTotalCountMode(mode: TotalCountMode): this {\n\t\tif (typeof mode !== \"number\") {\n\t\t\tthis.totalCountMode = null;\n\t\t}\n\n\t\tthis.totalCountMode = mode < 0 || mode > 2 ? null : mode;\n\t\treturn this;\n\t}\n\n\tsetPage(page: number): this {\n\t\tthis.page = page;\n\t\treturn this;\n\t}\n\n\tsetLimit(limit: number): this {\n\t\tthis.limit = limit;\n\t\treturn this;\n\t}\n\n\tsetTerm(term: string): this {\n\t\tthis.term = term;\n\t\treturn this;\n\t}\n\n\taddFilter(filter: SingleFilter): this {\n\t\tthis.filters.push(filter);\n\n\t\treturn this;\n\t}\n\n\taddIncludes(include: Include): this {\n\t\tfor (const [entityName, includeValues] of Object.entries(include)) {\n\t\t\tif (this.includes === null) {\n\t\t\t\tthis.includes = {};\n\t\t\t}\n\t\t\tif (!this.includes[entityName]) {\n\t\t\t\tthis.includes[entityName] = [];\n\t\t\t}\n\n\t\t\tthis.includes[entityName].push(...includeValues);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the provided filter as post filter.\n\t * Post filter will be considered for the documents query but not for the aggregations.\n\t */\n\taddPostFilter(filter: SingleFilter): this {\n\t\tthis.postFilter.push(filter);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows to add different sortings for the criteria, to sort the entity result.\n\t */\n\taddSorting(sorting: Sorting): this {\n\t\tthis.sortings.push(sorting);\n\t\treturn this;\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Query\\ScoreQuery.\n\t * These queries are used to search for documents and score them with a ranking\n\t */\n\taddQuery(\n\t\tfilter: SingleFilter,\n\t\tscore: number,\n\t\tscoreField: string | null = null,\n\t): this {\n\t\tconst query: Query = { score: score, query: filter };\n\n\t\tif (scoreField) {\n\t\t\tquery.scoreField = scoreField;\n\t\t}\n\n\t\tthis.queries.push(query);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows grouping the result by a specific field\n\t */\n\taddGrouping(field: string): this {\n\t\tthis.grouping.push(field);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Allows loading partial fields for the result.\n\t */\n\taddFields(...field: string[]): this {\n\t\tthis.fields.push(...field);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * @param {Object} aggregation\n\t */\n\taddAggregation(aggregation: Aggregation): this {\n\t\tthis.aggregations.push(aggregation);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Ensures that a criterion is created for each segment of the passed path.\n\t * Existing Criteria objects are not overwritten.\n\t * Returns the own instance\n\t */\n\taddAssociation(path: string): this {\n\t\tthis.getAssociation(path);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Ensures that a criterion is created for each segment of the passed path.\n\t * Returns the criteria instance of the last path segment\n\t */\n\tgetAssociation(path: string): Criteria {\n\t\tconst parts = path.split(\".\");\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tlet criteria = this;\n\n\t\tfor (const part of parts) {\n\t\t\tif (!criteria.hasAssociation(part)) {\n\t\t\t\tcriteria.associations.push({\n\t\t\t\t\tassociation: part,\n\t\t\t\t\tcriteria: new Criteria(),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// @ts-expect-error - another this instance\n\t\t\tcriteria = criteria.getAssociationCriteria(part);\n\t\t}\n\n\t\treturn criteria;\n\t}\n\n\tprivate getAssociationCriteria(part: string): Criteria {\n\t\tlet criteria = null;\n\n\t\tfor (const association of this.associations) {\n\t\t\tif (association.association === part) {\n\t\t\t\tcriteria = association.criteria;\n\t\t\t}\n\t\t}\n\n\t\tif (!criteria) {\n\t\t\tcriteria = new Criteria();\n\t\t\tthis.associations.push({\n\t\t\t\tassociation: part,\n\t\t\t\tcriteria,\n\t\t\t});\n\t\t}\n\n\t\treturn criteria;\n\t}\n\n\tgetLimit(): number {\n\t\treturn this.limit ?? 0;\n\t}\n\n\tgetPage(): number {\n\t\treturn this.page ?? 0;\n\t}\n\n\thasAssociation(property: string): boolean {\n\t\treturn this.associations.some((assocation) => {\n\t\t\treturn assocation.association === property;\n\t\t});\n\t}\n\n\t/**\n\t * Resets the sorting parameter\n\t */\n\tresetSorting(): void {\n\t\tthis.sortings = [];\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\AvgAggregation\n\t * Allows to calculate the avg value for the provided field\n\t */\n\tstatic avg(name: string, field: string): Aggregations[\"avg\"] {\n\t\treturn { type: \"avg\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\CountAggregation\n\t * Allows to calculate the count value for the provided field\n\t */\n\tstatic count(name: string, field: string): Aggregations[\"count\"] {\n\t\treturn { type: \"count\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\MaxAggregation\n\t * Allows to calculate the max value for the provided field\n\t */\n\tstatic max(name: string, field: string): Aggregations[\"max\"] {\n\t\treturn { type: \"max\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\MinAggregation\n\t * Allows to calculate the min value for the provided field\n\t */\n\tstatic min(name: string, field: string): Aggregations[\"min\"] {\n\t\treturn { type: \"min\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\StatsAggregation\n\t * Allows to calculate the sum, max, min, avg, count values for the provided field\n\t */\n\tstatic stats(name: string, field: string): Aggregations[\"stats\"] {\n\t\treturn { type: \"stats\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\SumAggregation\n\t * Allows to calculate the sum value for the provided field\n\t */\n\tstatic sum(name: string, field: string): Aggregations[\"sum\"] {\n\t\treturn { type: \"sum\", name, field };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Bucket\\TermsAggregation\n\t * Allows to fetch term buckets for the provided field\n\t */\n\tstatic terms(\n\t\tname: string,\n\t\tfield: string,\n\t\tlimit: number | null = null,\n\t\tsort: Sorting | null = null,\n\t\taggregation: Aggregation | null = null,\n\t): Aggregations[\"terms\"] {\n\t\treturn { type: \"terms\", name, field, limit, sort, aggregation };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Metric\\EntityAggregation\n\t * Allows to filter an aggregation result\n\t */\n\tstatic entityAggregation(\n\t\tname: string,\n\t\tfield: string,\n\t\tdefinition: string,\n\t): Aggregations[\"entity\"] {\n\t\treturn { type: \"entity\", name, field, definition };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Bucket\\FilterAggregation\n\t * Allows to filter an aggregation result\n\t */\n\tstatic filter(\n\t\tname: string,\n\t\tfilter: SingleFilter[],\n\t\taggregation: Aggregation,\n\t): Aggregations[\"filter\"] {\n\t\treturn { type: \"filter\", name, filter, aggregation };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Aggregation\\Bucket\\DateHistogramAggregation\n\t * Allows to fetch date buckets for the provided date interval\n\t */\n\tstatic histogram(\n\t\tname: string,\n\t\tfield: string,\n\t\tinterval: string | null = null,\n\t\tformat: string | null = null,\n\t\taggregation: Aggregation | null = null,\n\t\ttimeZone: string | null = null,\n\t): Aggregations[\"histogram\"] {\n\t\treturn {\n\t\t\ttype: \"histogram\",\n\t\t\tname,\n\t\t\tfield,\n\t\t\tinterval,\n\t\t\tformat,\n\t\t\taggregation,\n\t\t\ttimeZone,\n\t\t};\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Sorting\\FieldSorting.\n\t * Allows to sort the documents by the provided field\n\t */\n\tstatic sort(\n\t\tfield: string,\n\t\torder: Sorting[\"order\"] = \"ASC\",\n\t\tnaturalSorting = false,\n\t): Sorting {\n\t\treturn { field, order, naturalSorting };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Sorting\\FieldSorting.\n\t * Allows to sort the documents by the provided field naturally\n\t */\n\tstatic naturalSorting(\n\t\tfield: string,\n\t\torder: Sorting[\"order\"] = \"ASC\",\n\t): Sorting {\n\t\treturn { field, order, naturalSorting: true };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Sorting\\CountSorting.\n\t * Allows to sort the documents by counting associations via the provided field\n\t *\n\t * Sql representation: `ORDER BY COUNT({field}) {order}`\n\t */\n\tstatic countSorting(field: string, order: Sorting[\"order\"] = \"ASC\"): Sorting {\n\t\treturn { field, order, naturalSorting: false, type: \"count\" };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\ContainsFilter.\n\t * This allows to filter documents where the value are contained in the provided field.\n\t *\n\t * Sql representation: `{field} LIKE %{value}%`\n\t */\n\tstatic contains(field: string, value: string): Filters[\"contains\"] {\n\t\treturn { type: \"contains\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\PrefixFilter.\n\t * This allows to filter documents where the value marks the beginning of the provided field.\n\t *\n\t * Sql representation: `{field} LIKE {value}%`\n\t */\n\tstatic prefix(field: string, value: string): Filters[\"prefix\"] {\n\t\treturn { type: \"prefix\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\SuffixFilter.\n\t * This allows to filter documents where the value marks the end of the provided field.\n\t *\n\t * Sql representation: `{field} LIKE %{value}`\n\t */\n\tstatic suffix(field: string, value: string): Filters[\"suffix\"] {\n\t\treturn { type: \"suffix\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\EqualsAnyFilter.\n\t * This allows to filter documents where the field matches one of the provided values\n\t *\n\t * Sql representation: `{field} IN ({value}, {value})`\n\t */\n\tstatic equalsAny(\n\t\tfield: string,\n\t\tvalue: (string | number | boolean | null)[],\n\t): Filters[\"equalsAny\"] {\n\t\treturn { type: \"equalsAny\", field, value: value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\RangeFilter.\n\t * This allows to filter documents where the field matches a defined range\n\t *\n\t * Sql representation: `{field} >= {value}`, `{field} <= {value}`, ...\n\t */\n\tstatic range(\n\t\tfield: string,\n\t\trange: Filters[\"range\"][\"parameters\"],\n\t): Filters[\"range\"] {\n\t\treturn { type: \"range\", field, parameters: range };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\EqualsFilter.\n\t * This allows to filter documents where the field matches a defined range\n\t *\n\t * Sql representation: `{field} = {value}`\n\t */\n\tstatic equals(\n\t\tfield: string,\n\t\tvalue: string | number | boolean | null,\n\t): Filters[\"equals\"] {\n\t\treturn { type: \"equals\", field, value };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\NotFilter.\n\t * This allows to filter documents which not matches for the provided filters\n\t * All above listed queries can be provided (equals, equalsAny, range, contains)\n\t *\n\t * Sql representation: `NOT({query} {operator} {query} {operator} {query})`\n\t *\n\t * @param {string} operator - and/or\n\t * @param {array} queries\n\t *\n\t * @returns {Object}\n\t */\n\tstatic not(\n\t\toperator: Filters[\"not\"][\"operator\"],\n\t\tqueries: SingleFilter[] = [],\n\t): Filters[\"not\"] {\n\t\treturn { type: \"not\", operator: operator, queries: queries };\n\t}\n\n\t/**\n\t * @see \\Shopware\\Core\\Framework\\DataAbstractionLayer\\Search\\Filter\\NotFilter.\n\t * This allows to filter documents which matches for the provided filters\n\t * All above listed queries can be provided (equals, equalsAny, range, contains)\n\t *\n\t * Sql representation: `({query} {operator} {query} {operator} {query})`\n\t *\n\t * @param {string} operator - and/or\n\t * @param {array} queries\n\t *\n\t * @returns {Object}\n\t */\n\tstatic multi(\n\t\toperator: Filters[\"multi\"][\"operator\"],\n\t\tqueries: SingleFilter[] = [],\n\t): Filters[\"multi\"] {\n\t\treturn { type: \"multi\", operator, queries };\n\t}\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { ShopAuthroizeEvent } from "./registration.js";
2
+ import type { ShopInterface } from "./repository.js";
3
+ interface HookRegistry<Shop extends ShopInterface> {
4
+ onAuthorize: (event: ShopAuthroizeEvent<Shop>) => Promise<void>;
5
+ }
6
+ export declare class Hooks<Shop extends ShopInterface = ShopInterface> {
7
+ private eventListeners;
8
+ hasListeners(event: keyof HookRegistry<Shop>): boolean;
9
+ on(event: keyof HookRegistry<Shop>, cb: HookRegistry<Shop>[keyof HookRegistry<Shop>]): void;
10
+ publish(event: keyof HookRegistry<Shop>, ...args: Parameters<HookRegistry<Shop>[keyof HookRegistry<Shop>]>): Promise<void>;
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,UAAU,YAAY,CAAC,IAAI,SAAS,aAAa;IAChD,WAAW,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChE;AAED,qBAAa,KAAK,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAC5D,OAAO,CAAC,cAAc,CAGlB;IAEJ,YAAY,CAAC,KAAK,EAAE,MAAM,YAAY,CAAC,IAAI,CAAC,GAAG,OAAO;IAItD,EAAE,CACD,KAAK,EAAE,MAAM,YAAY,CAAC,IAAI,CAAC,EAC/B,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IAS3C,OAAO,CACZ,KAAK,EAAE,MAAM,YAAY,CAAC,IAAI,CAAC,EAC/B,GAAG,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,GAC/D,OAAO,CAAC,IAAI,CAAC;CAehB"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hooks = void 0;
4
+ class Hooks {
5
+ eventListeners = new Map();
6
+ hasListeners(event) {
7
+ return this.eventListeners.has(event);
8
+ }
9
+ on(event, cb) {
10
+ if (!this.eventListeners.has(event)) {
11
+ this.eventListeners.set(event, []);
12
+ }
13
+ this.eventListeners.get(event)?.push(cb);
14
+ }
15
+ async publish(event, ...args) {
16
+ const events = this.eventListeners.get(event);
17
+ if (!events) {
18
+ return;
19
+ }
20
+ for (const cb of events) {
21
+ const res = cb(...args);
22
+ if (res instanceof Promise) {
23
+ await res;
24
+ }
25
+ }
26
+ }
27
+ }
28
+ exports.Hooks = Hooks;
29
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/hooks.ts"],"names":[],"mappings":";;;AAOA,MAAa,KAAK;IACT,cAAc,GAAG,IAAI,GAAG,EAG7B,CAAC;IAEJ,YAAY,CAAC,KAA+B;QAC3C,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,EAAE,CACD,KAA+B,EAC/B,EAAgD;QAEhD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,OAAO,CACZ,KAA+B,EAC/B,GAAG,IAA8D;QAEjE,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE9C,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,OAAO;QACR,CAAC;QAED,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YAExB,IAAI,GAAG,YAAY,OAAO,EAAE,CAAC;gBAC5B,MAAM,GAAG,CAAC;YACX,CAAC;QACF,CAAC;IACF,CAAC;CACD;AAvCD,sBAuCC","sourcesContent":["import type { ShopAuthroizeEvent } from \"./registration.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\ninterface HookRegistry<Shop extends ShopInterface> {\n\tonAuthorize: (event: ShopAuthroizeEvent<Shop>) => Promise<void>;\n}\n\nexport class Hooks<Shop extends ShopInterface = ShopInterface> {\n\tprivate eventListeners = new Map<\n\t\tkeyof HookRegistry<Shop>,\n\t\tHookRegistry<Shop>[keyof HookRegistry<Shop>][]\n\t>();\n\n\thasListeners(event: keyof HookRegistry<Shop>): boolean {\n\t\treturn this.eventListeners.has(event);\n\t}\n\n\ton(\n\t\tevent: keyof HookRegistry<Shop>,\n\t\tcb: HookRegistry<Shop>[keyof HookRegistry<Shop>],\n\t) {\n\t\tif (!this.eventListeners.has(event)) {\n\t\t\tthis.eventListeners.set(event, []);\n\t\t}\n\n\t\tthis.eventListeners.get(event)?.push(cb);\n\t}\n\n\tasync publish(\n\t\tevent: keyof HookRegistry<Shop>,\n\t\t...args: Parameters<HookRegistry<Shop>[keyof HookRegistry<Shop>]>\n\t): Promise<void> {\n\t\tconst events = this.eventListeners.get(event);\n\n\t\tif (!events) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const cb of events) {\n\t\t\tconst res = cb(...args);\n\n\t\t\tif (res instanceof Promise) {\n\t\t\t\tawait res;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;GAEG;AACH,qBAAa,UAAU;IAGV,OAAO,CAAC,IAAI;IAFxB,OAAO,CAAC,OAAO,CAAmD;gBAE9C,IAAI,EAAE,aAAa;IAOvC;;OAEG;IACG,GAAG,CAAC,YAAY,EACrB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAClC,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAI5C;;OAEG;IACG,IAAI,CAAC,YAAY,EACtB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAM,GAAG,QAAQ,GAAG,IAAS,EACnC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAClC,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAkB5C;;OAEG;IACG,GAAG,CAAC,YAAY,EACrB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAW,EACjB,OAAO,GAA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C,CAAC;YAO9B,OAAO;IA+DrB;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;CA6EjC;AAED;;GAEG;AACH,qBAAa,kBAAkB,CAAC,YAAY;IAEnC,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,OAAO;gBAFhB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,OAAO;CAExB;AAED,KAAK,qBAAqB,GAAG;IAC5B,MAAM,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;CACJ,CAAC;AAEF;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;IAG/C,QAAQ,EAAE,kBAAkB,CAAC,MAAM,CAAC;gBAD3C,MAAM,EAAE,MAAM,EACP,QAAQ,EAAE,kBAAkB,CAAC,MAAM,CAAC;CAM5C;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAGxC,QAAQ,EAAE,kBAAkB,CAAC,qBAAqB,CAAC;gBAD1D,MAAM,EAAE,MAAM,EACP,QAAQ,EAAE,kBAAkB,CAAC,qBAAqB,CAAC;CAM3D"}
@@ -58,12 +58,25 @@ class HttpClient {
58
58
  }
59
59
  async request(method, url, body = "", headers = {}) {
60
60
  const f = await globalThis.fetch(`${this.shop.getShopUrl()}/api${url}`, {
61
+ redirect: "manual",
61
62
  body,
62
63
  headers: Object.assign({
63
64
  Authorization: `Bearer ${await this.getToken()}`,
64
65
  }, headers),
65
66
  method,
66
67
  });
68
+ if (f.status === 301 || f.status === 302) {
69
+ throw new ApiClientRequestFailed(this.shop.getShopId(), new HttpClientResponse(f.status, {
70
+ errors: [
71
+ {
72
+ code: "301",
73
+ status: "301",
74
+ title: "301",
75
+ detail: "Got a redirect response from the URL, the URL should point to the Shop without redirect",
76
+ },
77
+ ],
78
+ }, f.headers));
79
+ }
67
80
  // Obtain new token
68
81
  if (!f.ok && f.status === 401) {
69
82
  this.storage.expiresIn = null;
@@ -84,6 +97,7 @@ class HttpClient {
84
97
  if (this.storage.expiresIn === null) {
85
98
  const auth = await globalThis.fetch(`${this.shop.getShopUrl()}/api/oauth/token`, {
86
99
  method: "POST",
100
+ redirect: "manual",
87
101
  headers: {
88
102
  "content-type": "application/json",
89
103
  },
@@ -93,6 +107,18 @@ class HttpClient {
93
107
  client_secret: this.shop.getShopClientSecret(),
94
108
  }),
95
109
  });
110
+ if (auth.status === 301 || auth.status === 302) {
111
+ throw new ApiClientRequestFailed(this.shop.getShopId(), new HttpClientResponse(auth.status, {
112
+ errors: [
113
+ {
114
+ code: "301",
115
+ status: "301",
116
+ title: "301",
117
+ detail: "Got a redirect response from the URL, the URL should point to the Shop without redirect",
118
+ },
119
+ ],
120
+ }, auth.headers));
121
+ }
96
122
  if (!auth.ok) {
97
123
  const contentType = auth.headers.get("content-type") || "text/plain";
98
124
  let body = "";
@@ -1 +1 @@
1
- {"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/http-client.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,UAAU;IAGF;IAFZ,OAAO,CAAmD;IAElE,YAAoB,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;QACtC,IAAI,CAAC,OAAO,GAAG;YACd,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI;SACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CACR,GAAW,EACX,UAAkC,EAAE;QAEpC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CACT,GAAW,EACX,OAAiC,EAAE,EACnC,UAAkC,EAAE;QAEpC,IAAI,IAAI,GAAsC,IAAI,CA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AI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErE,KAAK,CAAC,8BAA8B,OAAO,sBAAsB,MAAM,EAAE,CAAC,CAAC;QAJpE,aAAQ,GAAR,QAAQ,CAA2C;IAK3D,CAAC;CACD;AATD,wDASC","sourcesContent":["import type { ShopInterface } from \"./repository.js\";\n\n/**\n * HttpClient is a simple wrapper around the fetch API, pre-configured with the shop's URL and access token\n */\nexport class HttpClient {\n\tprivate storage: { expiresIn: Date | null; token: string | null };\n\n\tconstructor(private shop: ShopInterface) {\n\t\tthis.storage = {\n\t\t\ttoken: null,\n\t\t\texpiresIn: null,\n\t\t};\n\t}\n\n\t/**\n\t * Permform a GET request\n\t */\n\tasync get<ResponseType>(\n\t\turl: string,\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\treturn await this.request(\"GET\", url, null, headers);\n\t}\n\n\t/**\n\t * Permform a POST request\n\t */\n\tasync post<ResponseType>(\n\t\turl: string,\n\t\tjson: object | FormData | Blob = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\tlet data: object | FormData | Blob | string = json;\n\n\t\tif (!(json instanceof Blob) && !(json instanceof FormData)) {\n\t\t\theaders[\"content-type\"] = \"application/json\";\n\t\t\tdata = JSON.stringify(json);\n\t\t}\n\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\n\t\t\t\"POST\",\n\t\t\turl,\n\t\t\tdata as FormData | Blob | string,\n\t\t\theaders,\n\t\t);\n\t}\n\n\t/**\n\t * Permform a PUT request\n\t */\n\tasync put<ResponseType>(\n\t\turl: string,\n\t\tjson: object = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\theaders[\"content-type\"] = \"application/json\";\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\"PUT\", url, JSON.stringify(json), headers);\n\t}\n\n\t/**\n\t * Permform a PATCH request\n\t */\n\tasync patch<ResponseType>(\n\t\turl: string,\n\t\tjson: object = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\theaders[\"content-type\"] = \"application/json\";\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\"PATCH\", url, JSON.stringify(json), headers);\n\t}\n\n\t/**\n\t * Permform a DELETE request\n\t */\n\tasync delete<ResponseType>(\n\t\turl: string,\n\t\tjson: object = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\theaders[\"content-type\"] = \"application/json\";\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\"DELETE\", url, JSON.stringify(json), headers);\n\t}\n\n\tprivate async request<ResponseType>(\n\t\tmethod: string,\n\t\turl: string,\n\t\tbody: string | FormData | Blob | null = \"\",\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\tconst f = await globalThis.fetch(`${this.shop.getShopUrl()}/api${url}`, {\n\t\t\tbody,\n\t\t\theaders: Object.assign(\n\t\t\t\t{\n\t\t\t\t\tAuthorization: `Bearer ${await this.getToken()}`,\n\t\t\t\t},\n\t\t\t\theaders,\n\t\t\t),\n\t\t\tmethod,\n\t\t});\n\n\t\t// Obtain new token\n\t\tif (!f.ok && f.status === 401) {\n\t\t\tthis.storage.expiresIn = null;\n\n\t\t\treturn await this.request(method, url, body, headers);\n\t\t}\n\t\tif (!f.ok) {\n\t\t\tthrow new ApiClientRequestFailed(\n\t\t\t\tthis.shop.getShopId(),\n\t\t\t\tnew HttpClientResponse(f.status, await f.json(), f.headers),\n\t\t\t);\n\t\t}\n\n\t\tif (f.status === 204) {\n\t\t\treturn new HttpClientResponse<ResponseType>(\n\t\t\t\tf.status,\n\t\t\t\t{} as ResponseType,\n\t\t\t\tf.headers,\n\t\t\t);\n\t\t}\n\n\t\treturn new HttpClientResponse(f.status, await f.json(), f.headers);\n\t}\n\n\t/**\n\t * Obtain a valid bearer token\n\t */\n\tasync getToken(): Promise<string> {\n\t\tif (this.storage.expiresIn === null) {\n\t\t\tconst auth = await globalThis.fetch(\n\t\t\t\t`${this.shop.getShopUrl()}/api/oauth/token`,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tgrant_type: \"client_credentials\",\n\t\t\t\t\t\tclient_id: this.shop.getShopClientId(),\n\t\t\t\t\t\tclient_secret: this.shop.getShopClientSecret(),\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (!auth.ok) {\n\t\t\t\tconst contentType = auth.headers.get(\"content-type\") || \"text/plain\";\n\t\t\t\tlet body = \"\";\n\n\t\t\t\tif (contentType.indexOf(\"application/json\") !== -1) {\n\t\t\t\t\tbody = await auth.json();\n\t\t\t\t} else {\n\t\t\t\t\tbody = await auth.text();\n\t\t\t\t}\n\n\t\t\t\tthrow new ApiClientAuthenticationFailed(\n\t\t\t\t\tthis.shop.getShopId(),\n\t\t\t\t\tnew HttpClientResponse<string>(auth.status, body, auth.headers),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst expireDate = new Date();\n\t\t\tconst authBody = (await auth.json()) as {\n\t\t\t\taccess_token: string;\n\t\t\t\texpires_in: number;\n\t\t\t};\n\t\t\tthis.storage.token = authBody.access_token;\n\t\t\texpireDate.setSeconds(expireDate.getSeconds() + authBody.expires_in);\n\t\t\tthis.storage.expiresIn = expireDate;\n\n\t\t\treturn this.storage.token as string;\n\t\t}\n\n\t\tif (this.storage.expiresIn.getTime() < new Date().getTime()) {\n\t\t\t// Expired\n\n\t\t\tthis.storage.expiresIn = null;\n\n\t\t\treturn await this.getToken();\n\t\t}\n\n\t\treturn this.storage.token as string;\n\t}\n}\n\n/**\n * HttpClientResponse is the response object of the HttpClient\n */\nexport class HttpClientResponse<ResponseType> {\n\tconstructor(\n\t\tpublic statusCode: number,\n\t\tpublic body: ResponseType,\n\t\tpublic headers: Headers,\n\t) {}\n}\n\ntype ShopwareErrorResponse = {\n\terrors: {\n\t\tcode: string;\n\t\tstatus: string;\n\t\ttitle: string;\n\t\tdetail: string;\n\t}[];\n};\n\n/**\n * ApiClientAuthenticationFailed is thrown when the authentication to the shop's API fails\n */\nexport class ApiClientAuthenticationFailed extends Error {\n\tconstructor(\n\t\tshopId: string,\n\t\tpublic response: HttpClientResponse<string>,\n\t) {\n\t\tsuper(\n\t\t\t`The api client authentication to shop with id: ${shopId} with response: ${JSON.stringify(response.body)}`,\n\t\t);\n\t}\n}\n\n/**\n * ApiClientRequestFailed is thrown when the request to the shop's API fails\n */\nexport class ApiClientRequestFailed extends Error {\n\tconstructor(\n\t\tshopId: string,\n\t\tpublic response: HttpClientResponse<ShopwareErrorResponse>,\n\t) {\n\t\tconst message = response.body.errors.map((e) => e.detail).join(\", \");\n\n\t\tsuper(`Request failed with error: ${message} for shop with id: ${shopId}`);\n\t}\n}\n"]}
1
+ {"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/http-client.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,UAAU;IAGF;IAFZ,OAAO,CAAmD;IAElE,YAAoB,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;QACtC,IAAI,CAAC,OAAO,GAAG;YACd,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI;SACf,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CACR,GAAW,EACX,UAAkC,EAAE;QAEpC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CACT,GAAW,EACX,OA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rapper around the fetch API, pre-configured with the shop's URL and access token\n */\nexport class HttpClient {\n\tprivate storage: { expiresIn: Date | null; token: string | null };\n\n\tconstructor(private shop: ShopInterface) {\n\t\tthis.storage = {\n\t\t\ttoken: null,\n\t\t\texpiresIn: null,\n\t\t};\n\t}\n\n\t/**\n\t * Permform a GET request\n\t */\n\tasync get<ResponseType>(\n\t\turl: string,\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\treturn await this.request(\"GET\", url, null, headers);\n\t}\n\n\t/**\n\t * Permform a POST request\n\t */\n\tasync post<ResponseType>(\n\t\turl: string,\n\t\tjson: object | FormData | Blob = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\tlet data: object | FormData | Blob | string = json;\n\n\t\tif (!(json instanceof Blob) && !(json instanceof FormData)) {\n\t\t\theaders[\"content-type\"] = \"application/json\";\n\t\t\tdata = JSON.stringify(json);\n\t\t}\n\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\n\t\t\t\"POST\",\n\t\t\turl,\n\t\t\tdata as FormData | Blob | string,\n\t\t\theaders,\n\t\t);\n\t}\n\n\t/**\n\t * Permform a PUT request\n\t */\n\tasync put<ResponseType>(\n\t\turl: string,\n\t\tjson: object = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\theaders[\"content-type\"] = \"application/json\";\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\"PUT\", url, JSON.stringify(json), headers);\n\t}\n\n\t/**\n\t * Permform a PATCH request\n\t */\n\tasync patch<ResponseType>(\n\t\turl: string,\n\t\tjson: object = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\theaders[\"content-type\"] = \"application/json\";\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\"PATCH\", url, JSON.stringify(json), headers);\n\t}\n\n\t/**\n\t * Permform a DELETE request\n\t */\n\tasync delete<ResponseType>(\n\t\turl: string,\n\t\tjson: object = {},\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\theaders[\"content-type\"] = \"application/json\";\n\t\theaders.accept = \"application/json\";\n\n\t\treturn await this.request(\"DELETE\", url, JSON.stringify(json), headers);\n\t}\n\n\tprivate async request<ResponseType>(\n\t\tmethod: string,\n\t\turl: string,\n\t\tbody: string | FormData | Blob | null = \"\",\n\t\theaders: Record<string, string> = {},\n\t): Promise<HttpClientResponse<ResponseType>> {\n\t\tconst f = await globalThis.fetch(`${this.shop.getShopUrl()}/api${url}`, {\n\t\t\tredirect: \"manual\",\n\t\t\tbody,\n\t\t\theaders: Object.assign(\n\t\t\t\t{\n\t\t\t\t\tAuthorization: `Bearer ${await this.getToken()}`,\n\t\t\t\t},\n\t\t\t\theaders,\n\t\t\t),\n\t\t\tmethod,\n\t\t});\n\n\t\tif (f.status === 301 || f.status === 302) {\n\t\t\tthrow new ApiClientRequestFailed(\n\t\t\t\tthis.shop.getShopId(),\n\t\t\t\tnew HttpClientResponse<ShopwareErrorResponse>(\n\t\t\t\t\tf.status,\n\t\t\t\t\t{\n\t\t\t\t\t\terrors: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcode: \"301\",\n\t\t\t\t\t\t\t\tstatus: \"301\",\n\t\t\t\t\t\t\t\ttitle: \"301\",\n\t\t\t\t\t\t\t\tdetail:\n\t\t\t\t\t\t\t\t\t\"Got a redirect response from the URL, the URL should point to the Shop without redirect\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\tf.headers,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\t// Obtain new token\n\t\tif (!f.ok && f.status === 401) {\n\t\t\tthis.storage.expiresIn = null;\n\n\t\t\treturn await this.request(method, url, body, headers);\n\t\t}\n\t\tif (!f.ok) {\n\t\t\tthrow new ApiClientRequestFailed(\n\t\t\t\tthis.shop.getShopId(),\n\t\t\t\tnew HttpClientResponse(f.status, await f.json(), f.headers),\n\t\t\t);\n\t\t}\n\n\t\tif (f.status === 204) {\n\t\t\treturn new HttpClientResponse<ResponseType>(\n\t\t\t\tf.status,\n\t\t\t\t{} as ResponseType,\n\t\t\t\tf.headers,\n\t\t\t);\n\t\t}\n\n\t\treturn new HttpClientResponse(f.status, await f.json(), f.headers);\n\t}\n\n\t/**\n\t * Obtain a valid bearer token\n\t */\n\tasync getToken(): Promise<string> {\n\t\tif (this.storage.expiresIn === null) {\n\t\t\tconst auth = await globalThis.fetch(\n\t\t\t\t`${this.shop.getShopUrl()}/api/oauth/token`,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tgrant_type: \"client_credentials\",\n\t\t\t\t\t\tclient_id: this.shop.getShopClientId(),\n\t\t\t\t\t\tclient_secret: this.shop.getShopClientSecret(),\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (auth.status === 301 || auth.status === 302) {\n\t\t\t\tthrow new ApiClientRequestFailed(\n\t\t\t\t\tthis.shop.getShopId(),\n\t\t\t\t\tnew HttpClientResponse<ShopwareErrorResponse>(\n\t\t\t\t\t\tauth.status,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\terrors: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcode: \"301\",\n\t\t\t\t\t\t\t\t\tstatus: \"301\",\n\t\t\t\t\t\t\t\t\ttitle: \"301\",\n\t\t\t\t\t\t\t\t\tdetail:\n\t\t\t\t\t\t\t\t\t\t\"Got a redirect response from the URL, the URL should point to the Shop without redirect\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tauth.headers,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!auth.ok) {\n\t\t\t\tconst contentType = auth.headers.get(\"content-type\") || \"text/plain\";\n\t\t\t\tlet body = \"\";\n\n\t\t\t\tif (contentType.indexOf(\"application/json\") !== -1) {\n\t\t\t\t\tbody = await auth.json();\n\t\t\t\t} else {\n\t\t\t\t\tbody = await auth.text();\n\t\t\t\t}\n\n\t\t\t\tthrow new ApiClientAuthenticationFailed(\n\t\t\t\t\tthis.shop.getShopId(),\n\t\t\t\t\tnew HttpClientResponse<string>(auth.status, body, auth.headers),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst expireDate = new Date();\n\t\t\tconst authBody = (await auth.json()) as {\n\t\t\t\taccess_token: string;\n\t\t\t\texpires_in: number;\n\t\t\t};\n\t\t\tthis.storage.token = authBody.access_token;\n\t\t\texpireDate.setSeconds(expireDate.getSeconds() + authBody.expires_in);\n\t\t\tthis.storage.expiresIn = expireDate;\n\n\t\t\treturn this.storage.token as string;\n\t\t}\n\n\t\tif (this.storage.expiresIn.getTime() < new Date().getTime()) {\n\t\t\t// Expired\n\n\t\t\tthis.storage.expiresIn = null;\n\n\t\t\treturn await this.getToken();\n\t\t}\n\n\t\treturn this.storage.token as string;\n\t}\n}\n\n/**\n * HttpClientResponse is the response object of the HttpClient\n */\nexport class HttpClientResponse<ResponseType> {\n\tconstructor(\n\t\tpublic statusCode: number,\n\t\tpublic body: ResponseType,\n\t\tpublic headers: Headers,\n\t) {}\n}\n\ntype ShopwareErrorResponse = {\n\terrors: {\n\t\tcode: string;\n\t\tstatus: string;\n\t\ttitle: string;\n\t\tdetail: string;\n\t}[];\n};\n\n/**\n * ApiClientAuthenticationFailed is thrown when the authentication to the shop's API fails\n */\nexport class ApiClientAuthenticationFailed extends Error {\n\tconstructor(\n\t\tshopId: string,\n\t\tpublic response: HttpClientResponse<string>,\n\t) {\n\t\tsuper(\n\t\t\t`The api client authentication to shop with id: ${shopId} with response: ${JSON.stringify(response.body)}`,\n\t\t);\n\t}\n}\n\n/**\n * ApiClientRequestFailed is thrown when the request to the shop's API fails\n */\nexport class ApiClientRequestFailed extends Error {\n\tconstructor(\n\t\tshopId: string,\n\t\tpublic response: HttpClientResponse<ShopwareErrorResponse>,\n\t) {\n\t\tconst message = response.body.errors.map((e) => e.detail).join(\", \");\n\n\t\tsuper(`Request failed with error: ${message} for shop with id: ${shopId}`);\n\t}\n}\n"]}
@@ -80,6 +80,10 @@ interface MiddlewareConfig {
80
80
  * The repository to fetch and store the shop data
81
81
  */
82
82
  shopRepository: ShopRepositoryInterface | ((c: HonoContext) => ShopRepositoryInterface);
83
+ /**
84
+ * A callback to setup the app server. It will be called after the app server is created and before the first request is handled
85
+ */
86
+ setup?: (app: AppServer) => void;
83
87
  }
84
88
  /**
85
89
  * Configure the Hono server to handle the app registration and context resolution
@@ -1 +1 @@
1
- {"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../../src/integration/hono.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAEzD,OAAO,QAAQ,MAAM,CAAC;IACrB,UAAU,kBAAkB;QAE3B,GAAG,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC;QAC9B,IAAI,EAAE,aAAa,CAAC;QAEpB,OAAO,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;KACzC;CACD;AAED,UAAU,gBAAgB;IACzB;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,MAAM,CAAC,CAAC;IAC/C;;OAEG;IACH,SAAS,EAAE,MAAM,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AAK,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,gBAAgB,QA+KnE"}
@@ -33,6 +33,9 @@ function configureAppServer(hono, cfg) {
33
33
  appSecret: cfg.appSecret,
34
34
  authorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,
35
35
  }, cfg.shopRepository);
36
+ if (cfg.setup) {
37
+ cfg.setup(app);
38
+ }
36
39
  }
37
40
  // @ts-ignore
38
41
  ctx.set("app", app);
@@ -1 +1 @@
1
- {"version":3,"file":"hono.js","sourceRoot":"","sources":["../../../src/integration/hono.ts"],"names":[],"mappings":";;AA0GA,gDA2KC;AArRD,wCAA+D;AAC/D,sCAAsC;AAsGtC;;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;IAEtC,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,C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AC;oBAC9B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;oBACxB,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;gBAC3B,CAAC;qBAAM,CAAC;oBACP,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;oBAEjC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;wBAC7C,MAAM,CAAC,YAAY,CAAC,GAAG,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 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 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 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\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\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\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.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.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":";;AA+GA,gDA+KC;AA9RD,wCAA+D;AAC/D,sCAAsC;AA2GtC;;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;IAEtC,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,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CA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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 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 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\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.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.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"]}