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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/commonjs/helper/admin-api.d.ts +27 -3
  2. package/dist/commonjs/helper/admin-api.d.ts.map +1 -1
  3. package/dist/commonjs/helper/admin-api.js +24 -0
  4. package/dist/commonjs/helper/admin-api.js.map +1 -1
  5. package/dist/commonjs/helper/criteria.d.ts +19 -3
  6. package/dist/commonjs/helper/criteria.d.ts.map +1 -1
  7. package/dist/commonjs/helper/criteria.js +2 -9
  8. package/dist/commonjs/helper/criteria.js.map +1 -1
  9. package/dist/commonjs/integration/dynamodb.d.ts.map +1 -1
  10. package/dist/commonjs/integration/dynamodb.js +12 -8
  11. package/dist/commonjs/integration/dynamodb.js.map +1 -1
  12. package/dist/commonjs/integration/hono.d.ts +1 -1
  13. package/dist/commonjs/integration/hono.d.ts.map +1 -1
  14. package/dist/commonjs/integration/hono.js +4 -0
  15. package/dist/commonjs/integration/hono.js.map +1 -1
  16. package/dist/commonjs/registration.d.ts +3 -3
  17. package/dist/commonjs/registration.d.ts.map +1 -1
  18. package/dist/commonjs/registration.js +8 -7
  19. package/dist/commonjs/registration.js.map +1 -1
  20. package/dist/esm/helper/admin-api.d.ts +27 -3
  21. package/dist/esm/helper/admin-api.d.ts.map +1 -1
  22. package/dist/esm/helper/admin-api.js +24 -0
  23. package/dist/esm/helper/admin-api.js.map +1 -1
  24. package/dist/esm/helper/criteria.d.ts +19 -3
  25. package/dist/esm/helper/criteria.d.ts.map +1 -1
  26. package/dist/esm/helper/criteria.js +2 -9
  27. package/dist/esm/helper/criteria.js.map +1 -1
  28. package/dist/esm/integration/dynamodb.d.ts.map +1 -1
  29. package/dist/esm/integration/dynamodb.js +13 -9
  30. package/dist/esm/integration/dynamodb.js.map +1 -1
  31. package/dist/esm/integration/hono.d.ts +1 -1
  32. package/dist/esm/integration/hono.d.ts.map +1 -1
  33. package/dist/esm/integration/hono.js +4 -0
  34. package/dist/esm/integration/hono.js.map +1 -1
  35. package/dist/esm/registration.d.ts +3 -3
  36. package/dist/esm/registration.d.ts.map +1 -1
  37. package/dist/esm/registration.js +8 -7
  38. package/dist/esm/registration.js.map +1 -1
  39. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"criteria.js","sourceRoot":"","sources":["../../../src/helper/criteria.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,cAOX;AAPD,WAAY,cAAc;IACzB,yFAAyF;IACzF,uEAAkB,CAAA;IAClB,kGAAkG;IAClG,6EAAqB,CAAA;IACrB,iGAAiG;IACjG,uFAA0B,CAAA;AAC3B,CAAC,EAPW,cAAc,KAAd,cAAc,QAOzB;AAyJD,MAAM,OAAO,QAAQ;IACpB,KAAK,CAAgB;IAErB,IAAI,CAAgB;IAEpB,KAAK,CAAgB;IAErB,IAAI,CAAgB;IAEpB,OAAO,CAAiB;IAExB,GAAG,CAAW;IAEd,OAAO,CAAU;IAEjB,YAAY,CAAgB;IAE5B,UAAU,CAAiB;IAE3B,QAAQ,CAAY;IAEpB,YAAY,CAAgB;IAE5B,QAAQ,CAAW;IAEnB,MAAM,CAAW;IAEjB,cAAc,CAAwB;IAEtC,QAAQ,CAAiB;IAEzB,YAAY,MAAgB,EAAE;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,UAAU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B,EAAE;QAE5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACD","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"]}
1
+ {"version":3,"file":"criteria.js","sourceRoot":"","sources":["../../../src/helper/criteria.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,cAOX;AAPD,WAAY,cAAc;IACzB,yFAAyF;IACzF,uEAAkB,CAAA;IAClB,kGAAkG;IAClG,6EAAqB,CAAA;IACrB,iGAAiG;IACjG,uFAA0B,CAAA;AAC3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AO,EAAE,IAAI,EAAE,QAAQ,EAAE,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","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\n// Type utilities for enhanced type safety with nested paths\ntype DeepNonNullable<T> = T extends object\n\t? {\n\t\t\t[P in keyof T]: DeepNonNullable<NonNullable<T[P]>>;\n\t\t}\n\t: NonNullable<T>;\n\ntype MakeRequired<T, K extends keyof T> = Omit<T, K> & {\n\t[P in K]-?: DeepNonNullable<T[P]>;\n};\n\n// Type for handling nested paths\ntype NestedMakeRequired<\n\tT,\n\tPath extends string,\n> = Path extends `${infer First}.${infer Rest}`\n\t? First extends keyof T\n\t\t? Omit<T, First> & {\n\t\t\t\t[K in First]-?: NestedMakeRequired<NonNullable<T[First]>, Rest>;\n\t\t\t}\n\t\t: T\n\t: Path extends keyof T\n\t\t? MakeRequired<T, Path>\n\t\t: T;\n\ntype PropertyType<T, K extends keyof T> = NonNullable<T[K]>;\n\n// Get nested property type\ntype NestedPropertyType<\n\tT,\n\tPath extends string,\n> = Path extends `${infer First}.${infer Rest}`\n\t? First extends keyof T\n\t\t? NestedPropertyType<NonNullable<T[First]>, Rest>\n\t\t: never\n\t: Path extends keyof T\n\t\t? NonNullable<T[Path]>\n\t\t: never;\n\nexport type Autoloadable<T> = T;\n\nexport class Criteria<T = object> {\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\t * When used with a type parameter T, provides type-safe access to ensure fields are\n\t * defined when accessing results from a Repository search.\n\t */\n\t// For direct field association\n\taddAssociation<K extends keyof T & string>(\n\t\tfield: K,\n\t): Criteria<MakeRequired<T, K>>;\n\n\t// For nested path association\n\taddAssociation<P extends string & `${string}.${string}`>(\n\t\tpath: P,\n\t): Criteria<NestedMakeRequired<T, P>>;\n\n\t// Implementation with traditional behavior\n\taddAssociation(path: string): this {\n\t\tthis.getAssociation(path);\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\t// For direct field association\n\tgetAssociation<K extends keyof T & string>(\n\t\tfield: K,\n\t): Criteria<PropertyType<T, K>>;\n\n\t// For nested path association\n\tgetAssociation<P extends string>(path: P): Criteria<T>;\n\n\t// Implementation with traditional behavior\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 +1 @@
1
- {"version":3,"file":"dynamodb.d.ts","sourceRoot":"","sources":["../../../src/integration/dynamodb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAEN,sBAAsB,EAGtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,uBAAuB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,qBAAa,kBAAmB,YAAW,uBAAuB,CAAC,UAAU,CAAC;IAC7E,SAAS,EAAE,sBAAsB,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;gBAEN,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM;IAK/C,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBlE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAoCnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB3C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAU3C"}
1
+ {"version":3,"file":"dynamodb.d.ts","sourceRoot":"","sources":["../../../src/integration/dynamodb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAEN,sBAAsB,EAItB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,uBAAuB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,qBAAa,kBAAmB,YAAW,uBAAuB,CAAC,UAAU,CAAC;IAC7E,SAAS,EAAE,sBAAsB,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;gBAEN,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM;IAK/C,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBlE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAoCnD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB3C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAU3C"}
@@ -1,4 +1,4 @@
1
- import { DeleteCommand, DynamoDBDocumentClient, GetCommand, PutCommand, } from "@aws-sdk/lib-dynamodb";
1
+ import { DeleteCommand, DynamoDBDocumentClient, GetCommand, PutCommand, UpdateCommand, } from "@aws-sdk/lib-dynamodb";
2
2
  import { SimpleShop } from "../repository.js";
3
3
  export class DynamoDBRepository {
4
4
  docClient;
@@ -43,15 +43,19 @@ export class DynamoDBRepository {
43
43
  return shop;
44
44
  }
45
45
  async updateShop(shop) {
46
- const cmd = new PutCommand({
46
+ const cmd = new UpdateCommand({
47
47
  TableName: this.tableName,
48
- Item: {
49
- id: shop.getShopId(),
50
- active: shop.getShopActive(),
51
- url: shop.getShopUrl(),
52
- secret: shop.getShopSecret(),
53
- clientId: shop.getShopClientId(),
54
- clientSecret: shop.getShopClientSecret(),
48
+ Key: { id: shop.getShopId() },
49
+ UpdateExpression: "SET active = :active, #u = :url, secret = :secret, clientId = :clientId, clientSecret = :clientSecret",
50
+ ExpressionAttributeNames: {
51
+ "#u": "url",
52
+ },
53
+ ExpressionAttributeValues: {
54
+ ":active": shop.getShopActive(),
55
+ ":url": shop.getShopUrl(),
56
+ ":secret": shop.getShopSecret(),
57
+ ":clientId": shop.getShopClientId(),
58
+ ":clientSecret": shop.getShopClientSecret(),
55
59
  },
56
60
  });
57
61
  await this.docClient.send(cmd);
@@ -1 +1 @@
1
- {"version":3,"file":"dynamodb.js","sourceRoot":"","sources":["../../../src/integration/dynamodb.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EACb,sBAAsB,EACtB,UAAU,EACV,UAAU,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAgC,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,MAAM,OAAO,kBAAkB;IAC9B,SAAS,CAAyB;IAClC,SAAS,CAAS;IAElB,YAAY,MAAsB,EAAE,SAAiB;QACpD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,GAAW,EAAE,MAAc;QACvD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC;YAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE;gBACL,EAAE,EAAE,EAAE;gBACN,MAAM,EAAE,KAAK;gBACb,GAAG,EAAE,GAAG;gBACR,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,IAAI;gBACd,YAAY,EAAE,IAAI;aAClB;SACD,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC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I,CAAC,aAAa,EAAE;gBAC5B,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE;gBAChC,YAAY,EAAE,IAAI,CAAC,mBAAmB,EAAE;aACxC;SACD,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QAC1B,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,EAAE;gBACJ,EAAE,EAAE,EAAE;aACN;SACD,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["import type { DynamoDBClient } from \"@aws-sdk/client-dynamodb\";\nimport {\n\tDeleteCommand,\n\tDynamoDBDocumentClient,\n\tGetCommand,\n\tPutCommand,\n} from \"@aws-sdk/lib-dynamodb\";\nimport { type ShopRepositoryInterface, SimpleShop } from \"../repository.js\";\n\nexport class DynamoDBRepository implements ShopRepositoryInterface<SimpleShop> {\n\tdocClient: DynamoDBDocumentClient;\n\ttableName: string;\n\n\tconstructor(client: DynamoDBClient, tableName: string) {\n\t\tthis.tableName = tableName;\n\t\tthis.docClient = DynamoDBDocumentClient.from(client);\n\t}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\tconst cmd = new PutCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tItem: {\n\t\t\t\tid: id,\n\t\t\t\tactive: false,\n\t\t\t\turl: url,\n\t\t\t\tsecret: secret,\n\t\t\t\tclientId: null,\n\t\t\t\tclientSecret: null,\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst cmd = new GetCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tKey: {\n\t\t\t\tid: id,\n\t\t\t},\n\t\t});\n\n\t\tconst response = await this.docClient.send(cmd);\n\n\t\tif (!response.Item) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst shop = new SimpleShop(\n\t\t\tresponse.Item.id,\n\t\t\tresponse.Item.url,\n\t\t\tresponse.Item.secret,\n\t\t);\n\n\t\tif (response.Item.active === undefined) {\n\t\t\tresponse.Item.active = true;\n\t\t}\n\n\t\tshop.setShopActive(response.Item.active);\n\n\t\tif (response.Item.clientId) {\n\t\t\tshop.setShopCredentials(\n\t\t\t\tresponse.Item.clientId,\n\t\t\t\tresponse.Item.clientSecret,\n\t\t\t);\n\t\t}\n\n\t\treturn shop;\n\t}\n\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tconst cmd = new PutCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tItem: {\n\t\t\t\tid: shop.getShopId(),\n\t\t\t\tactive: shop.getShopActive(),\n\t\t\t\turl: shop.getShopUrl(),\n\t\t\t\tsecret: shop.getShopSecret(),\n\t\t\t\tclientId: shop.getShopClientId(),\n\t\t\t\tclientSecret: shop.getShopClientSecret(),\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n\n\tasync deleteShop(id: string): Promise<void> {\n\t\tconst cmd = new DeleteCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tKey: {\n\t\t\t\tid: id,\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n}\n"]}
1
+ {"version":3,"file":"dynamodb.js","sourceRoot":"","sources":["../../../src/integration/dynamodb.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EACb,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,aAAa,GACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAgC,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE5E,MAAM,OAAO,kBAAkB;IAC9B,SAAS,CAAyB;IAClC,SAAS,CAAS;IAElB,YAAY,MAAsB,EAAE,SAAiB;QACpD,IAAI,CA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CAAC;QAEzC,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,kBAAkB,CACtB,QAAQ,CAAC,IAAI,CAAC,QAAQ,EACtB,QAAQ,CAAC,IAAI,CAAC,YAAY,CAC1B,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAgB;QAChC,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE;YAC7B,gBAAgB,EACf,uGAAuG;YACxG,wBAAwB,EAAE;gBACzB,IAAI,EAAE,KAAK;aACX;YACD,yBAAyB,EAAE;gBAC1B,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE;gBAC/B,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE;gBACzB,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE;gBAC/B,WAAW,EAAE,IAAI,CAAC,eAAe,EAAE;gBACnC,eAAe,EAAE,IAAI,CAAC,mBAAmB,EAAE;aAC3C;SACD,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QAC1B,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,EAAE;gBACJ,EAAE,EAAE,EAAE;aACN;SACD,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;CACD","sourcesContent":["import type { DynamoDBClient } from \"@aws-sdk/client-dynamodb\";\nimport {\n\tDeleteCommand,\n\tDynamoDBDocumentClient,\n\tGetCommand,\n\tPutCommand,\n\tUpdateCommand,\n} from \"@aws-sdk/lib-dynamodb\";\nimport { type ShopRepositoryInterface, SimpleShop } from \"../repository.js\";\n\nexport class DynamoDBRepository implements ShopRepositoryInterface<SimpleShop> {\n\tdocClient: DynamoDBDocumentClient;\n\ttableName: string;\n\n\tconstructor(client: DynamoDBClient, tableName: string) {\n\t\tthis.tableName = tableName;\n\t\tthis.docClient = DynamoDBDocumentClient.from(client);\n\t}\n\n\tasync createShop(id: string, url: string, secret: string): Promise<void> {\n\t\tconst cmd = new PutCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tItem: {\n\t\t\t\tid: id,\n\t\t\t\tactive: false,\n\t\t\t\turl: url,\n\t\t\t\tsecret: secret,\n\t\t\t\tclientId: null,\n\t\t\t\tclientSecret: null,\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n\n\tasync getShopById(id: string): Promise<SimpleShop | null> {\n\t\tconst cmd = new GetCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tKey: {\n\t\t\t\tid: id,\n\t\t\t},\n\t\t});\n\n\t\tconst response = await this.docClient.send(cmd);\n\n\t\tif (!response.Item) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst shop = new SimpleShop(\n\t\t\tresponse.Item.id,\n\t\t\tresponse.Item.url,\n\t\t\tresponse.Item.secret,\n\t\t);\n\n\t\tif (response.Item.active === undefined) {\n\t\t\tresponse.Item.active = true;\n\t\t}\n\n\t\tshop.setShopActive(response.Item.active);\n\n\t\tif (response.Item.clientId) {\n\t\t\tshop.setShopCredentials(\n\t\t\t\tresponse.Item.clientId,\n\t\t\t\tresponse.Item.clientSecret,\n\t\t\t);\n\t\t}\n\n\t\treturn shop;\n\t}\n\n\tasync updateShop(shop: SimpleShop): Promise<void> {\n\t\tconst cmd = new UpdateCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tKey: { id: shop.getShopId() },\n\t\t\tUpdateExpression:\n\t\t\t\t\"SET active = :active, #u = :url, secret = :secret, clientId = :clientId, clientSecret = :clientSecret\",\n\t\t\tExpressionAttributeNames: {\n\t\t\t\t\"#u\": \"url\",\n\t\t\t},\n\t\t\tExpressionAttributeValues: {\n\t\t\t\t\":active\": shop.getShopActive(),\n\t\t\t\t\":url\": shop.getShopUrl(),\n\t\t\t\t\":secret\": shop.getShopSecret(),\n\t\t\t\t\":clientId\": shop.getShopClientId(),\n\t\t\t\t\":clientSecret\": shop.getShopClientSecret(),\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n\n\tasync deleteShop(id: string): Promise<void> {\n\t\tconst cmd = new DeleteCommand({\n\t\t\tTableName: this.tableName,\n\t\t\tKey: {\n\t\t\t\tid: id,\n\t\t\t},\n\t\t});\n\n\t\tawait this.docClient.send(cmd);\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { AppServer } from "../app.js";
2
- import type { Context } from "../context-resolver.js";
2
+ import { Context } from "../context-resolver.js";
3
3
  import type { ShopInterface, ShopRepositoryInterface } from "../repository.js";
4
4
  import type { Hono, Context as HonoContext } from "hono";
5
5
  declare module "hono" {
@@ -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;;OA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E,MAAM,GAAG,IAAI,CAAC;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE5C;;OAEG;IACH,cAAc,EACX,uBAAuB,GACvB,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,uBAAuB,CAAC,CAAC;IAEjD;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,gBAAgB,QA+LnE"}
@@ -1,5 +1,7 @@
1
1
  import { getSignedCookie, setSignedCookie } from "hono/cookie";
2
2
  import { AppServer } from "../app.js";
3
+ import { Context } from "../context-resolver.js";
4
+ import { HttpClient } from "../http-client.js";
3
5
  /**
4
6
  * Configure the Hono server to handle the app registration and context resolution
5
7
  */
@@ -112,6 +114,8 @@ export function configureAppServer(hono, cfg) {
112
114
  return ctx.json({ message: "Shop not found" }, { status: 400 });
113
115
  }
114
116
  ctx.set("shop", shop);
117
+ // @ts-ignore
118
+ ctx.set("context", new Context(shop, {}, new HttpClient(shop)));
115
119
  await next();
116
120
  });
117
121
  for (let [path, redirect] of Object.entries(cfg.appIframeRedirects || {})) {
@@ -1 +1 @@
1
- {"version":3,"file":"hono.js","sourceRoot":"","sources":["../../../src/integration/hono.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAyHtC;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAA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IAChC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { getSignedCookie, setSignedCookie } from \"hono/cookie\";\nimport { AppServer } from \"../app.js\";\nimport type { Context } from \"../context-resolver.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\nimport type { Hono, Context as HonoContext } from \"hono\";\n\ndeclare module \"hono\" {\n\tinterface ContextVariableMap {\n\t\t// @ts-ignore\n\t\tapp: AppServer<ShopInterface>;\n\t\tshop: ShopInterface;\n\t\t// @ts-ignore\n\t\tcontext: Context<ShopInterface, unknown>;\n\t}\n}\n\ninterface MiddlewareConfig {\n\t/**\n\t * The name of the app\n\t */\n\tappName: string | ((c: HonoContext) => string);\n\t/**\n\t * The secret of the app. When the app is published in the Shopware Store, the Shopware Store provides this value.\n\t */\n\tappSecret: string | ((c: HonoContext) => string);\n\n\t/**\n\t * The URL of the app. This is the base URL of the app. This will automatically determined by default\n\t */\n\tappUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration endpoint\n\t *\n\t * @default \"/app/register\"\n\t */\n\tregistrationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration confirmation endpoint\n\t *\n\t * @default \"/app/register/confirm\"\n\t */\n\tregisterConfirmationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app installation lifecycle endpoint\n\t *\n\t * @default \"/app/install\"\n\t */\n\tappInstallUrl?: string | null;\n\n\t/**\n\t * The relative url of the app activation lifecycle endpoint\n\t *\n\t * @default \"/app/activate\"\n\t */\n\tappActivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app update lifecycle endpoint\n\t *\n\t * @default \"/app/update\"\n\t */\n\tappUpdateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deactivation lifecycle endpoint\n\t *\n\t * @default \"/app/deactivate\"\n\t */\n\tappDeactivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deletion lifecycle endpoint\n\t *\n\t * @default \"/app/delete\"\n\t */\n\tappDeleteUrl?: string | null;\n\n\t/**\n\t * The relative url of the app scope. All requests matching this will be the signature automatically validated and the response will be signed\n\t *\n\t * @default \"/app/*\"\n\t */\n\tappPath?: string | null;\n\n\t/**\n\t * Enable the app iframe integration. This will automatically set a cookie to identifiy the shopware shop and validate the request from a client side application. See appIframeRedirects\n\t */\n\tappIframeEnable?: boolean;\n\n\t/**\n\t * The relative url of the app iframe scope. All requests matching this will require that the request has an cookie set with the shopware shop. This cookie will be automatically set by\n\t *\n\t * @default \"/client-api/*\"\n\t */\n\tappIframePath?: string | null;\n\n\t/**\n\t * A mapping of the app iframe paths to the actual paths. This route will set a cookie automatically before the redirect to the actual path. In that way the client side application can send requests to /app-iframe/* with the cookie set and the server will automatically validate the request and knows which shop the request is for.\n\t *\n\t * @default {\n\t * \"/app/module\": \"https://my-static-client-side-app.com\"\n\t * }\n\t */\n\tappIframeRedirects?: Record<string, string>;\n\n\t/**\n\t * The repository to fetch and store the shop data\n\t */\n\tshopRepository:\n\t\t| ShopRepositoryInterface\n\t\t| ((c: HonoContext) => ShopRepositoryInterface);\n\n\t/**\n\t * A callback to setup the app server. It will be called after the app server is created and before the first request is handled\n\t */\n\tsetup?: (app: AppServer) => void;\n}\n\n/**\n * Configure the Hono server to handle the app registration and context resolution\n */\nexport function configureAppServer(hono: Hono, cfg: MiddlewareConfig) {\n\tlet app: AppServer | null = null;\n\n\tcfg.registrationUrl = cfg.registrationUrl || \"/app/register\";\n\tcfg.registerConfirmationUrl =\n\t\tcfg.registerConfirmationUrl || \"/app/register/confirm\";\n\tcfg.appActivateUrl = cfg.appActivateUrl || \"/app/activate\";\n\tcfg.appDeactivateUrl = cfg.appDeactivateUrl || \"/app/deactivate\";\n\tcfg.appDeleteUrl = cfg.appDeleteUrl || \"/app/delete\";\n\tcfg.appPath = cfg.appPath || \"/app/*\";\n\tcfg.appInstallUrl = cfg.appInstallUrl || \"/app/install\";\n\tcfg.appUpdateUrl = cfg.appUpdateUrl || \"/app/update\";\n\n\tcfg.appIframePath = cfg.appIframePath || \"/client-api/*\";\n\n\thono.use(\"*\", async (ctx, next) => {\n\t\tif (app === null) {\n\t\t\tconst appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);\n\n\t\t\tif (typeof cfg.shopRepository === \"function\") {\n\t\t\t\tcfg.shopRepository = cfg.shopRepository(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appName === \"function\") {\n\t\t\t\tcfg.appName = cfg.appName(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appSecret === \"function\") {\n\t\t\t\tcfg.appSecret = cfg.appSecret(ctx);\n\t\t\t}\n\n\t\t\tapp = new AppServer(\n\t\t\t\t{\n\t\t\t\t\tappName: cfg.appName,\n\t\t\t\t\tappSecret: cfg.appSecret,\n\t\t\t\t\tauthorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,\n\t\t\t\t},\n\t\t\t\tcfg.shopRepository,\n\t\t\t);\n\n\t\t\tif (cfg.setup) {\n\t\t\t\tcfg.setup(app);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"app\", app);\n\n\t\tawait next();\n\t});\n\n\thono.use(cfg.appPath, async (ctx, next) => {\n\t\t// @ts-ignore\n\t\tconst app = ctx.get(\"app\") as AppServer;\n\n\t\t// Don't validate signature for registration\n\t\tif (\n\t\t\tctx.req.path === cfg.registrationUrl ||\n\t\t\tctx.req.path === cfg.registerConfirmationUrl ||\n\t\t\tctx.req.path === cfg.appActivateUrl ||\n\t\t\tctx.req.path === cfg.appDeactivateUrl ||\n\t\t\tctx.req.path === cfg.appDeleteUrl\n\t\t) {\n\t\t\tawait next();\n\t\t\treturn;\n\t\t}\n\n\t\tlet context: Context<ShopInterface, unknown>;\n\t\ttry {\n\t\t\tcontext =\n\t\t\t\tctx.req.method === \"GET\"\n\t\t\t\t\t? await app.contextResolver.fromBrowser(ctx.req.raw)\n\t\t\t\t\t: await app.contextResolver.fromAPI(ctx.req.raw);\n\t\t} catch (_e) {\n\t\t\treturn jsonResponse({ message: \"Invalid request\" }, 400);\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"shop\", context.shop);\n\t\t// @ts-ignore\n\t\tctx.set(\"context\", context);\n\n\t\tawait next();\n\n\t\tconst cloned = ctx.res.clone();\n\n\t\tawait ctx\n\t\t\t.get(\"app\")\n\t\t\t.signer.signResponse(cloned, ctx.get(\"shop\").getShopSecret());\n\n\t\tctx.header(\n\t\t\t\"shopware-app-signature\",\n\t\t\tcloned.headers.get(\"shopware-app-signature\") as string,\n\t\t);\n\t});\n\n\thono.get(cfg.registrationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorize(ctx.req.raw);\n\t});\n\n\thono.post(cfg.registerConfirmationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorizeCallback(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appInstallUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.install(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appActivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.activate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appUpdateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.update(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeactivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.deactivate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeleteUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.delete(ctx.req.raw);\n\t});\n\n\tif (cfg.appIframeEnable) {\n\t\thono.use(cfg.appIframePath, async (ctx, next) => {\n\t\t\tconst shopId = await getSignedCookie(\n\t\t\t\tctx,\n\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t\"shop\",\n\t\t\t);\n\n\t\t\tif (!shopId) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tconst shop = await ctx.get(\"app\").repository.getShopById(shopId);\n\n\t\t\tif (!shop) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tctx.set(\"shop\", shop);\n\n\t\t\tawait next();\n\t\t});\n\n\t\tfor (let [path, redirect] of Object.entries(cfg.appIframeRedirects || {})) {\n\t\t\thono.get(path, async (ctx) => {\n\t\t\t\tconst url = new URL(ctx.req.url);\n\n\t\t\t\tif (redirect.startsWith(\"/\")) {\n\t\t\t\t\turl.pathname = redirect;\n\t\t\t\t\tredirect = url.toString();\n\t\t\t\t} else {\n\t\t\t\t\tconst newUrl = new URL(redirect);\n\n\t\t\t\t\tfor (const [key, value] of url.searchParams) {\n\t\t\t\t\t\tnewUrl.searchParams.set(key, value);\n\t\t\t\t\t}\n\n\t\t\t\t\tredirect = newUrl.toString();\n\t\t\t\t}\n\n\t\t\t\tawait setSignedCookie(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"shop\",\n\t\t\t\t\tctx.get(\"shop\").getShopId(),\n\t\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t);\n\n\t\t\t\treturn ctx.redirect(redirect);\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction jsonResponse(body: object, status = 200): Response {\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t});\n}\n\nfunction buildBaseUrl(url: string): string {\n\tconst u = new URL(url);\n\n\treturn `${u.protocol}//${u.host}`;\n}\n"]}
1
+ {"version":3,"file":"hono.js","sourceRoot":"","sources":["../../../src/integration/hono.ts"],"names":[],"mappings":"AAA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C,CAAC,GAAG,CAAC,SAAS,CAC5B,CAAC;gBAEF,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,MAAM,GAAG,GAAG;IAC/C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM;QACN,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;SAClC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAChC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { getSignedCookie, setSignedCookie } from \"hono/cookie\";\nimport { AppServer } from \"../app.js\";\nimport { Context } from \"../context-resolver.js\";\nimport type { ShopInterface, ShopRepositoryInterface } from \"../repository.js\";\n\nimport type { Hono, Context as HonoContext } from \"hono\";\nimport { HttpClient } from \"../http-client.js\";\n\ndeclare module \"hono\" {\n\tinterface ContextVariableMap {\n\t\t// @ts-ignore\n\t\tapp: AppServer<ShopInterface>;\n\t\tshop: ShopInterface;\n\t\t// @ts-ignore\n\t\tcontext: Context<ShopInterface, unknown>;\n\t}\n}\n\ninterface MiddlewareConfig {\n\t/**\n\t * The name of the app\n\t */\n\tappName: string | ((c: HonoContext) => string);\n\t/**\n\t * The secret of the app. When the app is published in the Shopware Store, the Shopware Store provides this value.\n\t */\n\tappSecret: string | ((c: HonoContext) => string);\n\n\t/**\n\t * The URL of the app. This is the base URL of the app. This will automatically determined by default\n\t */\n\tappUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration endpoint\n\t *\n\t * @default \"/app/register\"\n\t */\n\tregistrationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app registration confirmation endpoint\n\t *\n\t * @default \"/app/register/confirm\"\n\t */\n\tregisterConfirmationUrl?: string | null;\n\n\t/**\n\t * The relative url of the app installation lifecycle endpoint\n\t *\n\t * @default \"/app/install\"\n\t */\n\tappInstallUrl?: string | null;\n\n\t/**\n\t * The relative url of the app activation lifecycle endpoint\n\t *\n\t * @default \"/app/activate\"\n\t */\n\tappActivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app update lifecycle endpoint\n\t *\n\t * @default \"/app/update\"\n\t */\n\tappUpdateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deactivation lifecycle endpoint\n\t *\n\t * @default \"/app/deactivate\"\n\t */\n\tappDeactivateUrl?: string | null;\n\n\t/**\n\t * The relative url of the app deletion lifecycle endpoint\n\t *\n\t * @default \"/app/delete\"\n\t */\n\tappDeleteUrl?: string | null;\n\n\t/**\n\t * The relative url of the app scope. All requests matching this will be the signature automatically validated and the response will be signed\n\t *\n\t * @default \"/app/*\"\n\t */\n\tappPath?: string | null;\n\n\t/**\n\t * Enable the app iframe integration. This will automatically set a cookie to identifiy the shopware shop and validate the request from a client side application. See appIframeRedirects\n\t */\n\tappIframeEnable?: boolean;\n\n\t/**\n\t * The relative url of the app iframe scope. All requests matching this will require that the request has an cookie set with the shopware shop. This cookie will be automatically set by\n\t *\n\t * @default \"/client-api/*\"\n\t */\n\tappIframePath?: string | null;\n\n\t/**\n\t * A mapping of the app iframe paths to the actual paths. This route will set a cookie automatically before the redirect to the actual path. In that way the client side application can send requests to /app-iframe/* with the cookie set and the server will automatically validate the request and knows which shop the request is for.\n\t *\n\t * @default {\n\t * \"/app/module\": \"https://my-static-client-side-app.com\"\n\t * }\n\t */\n\tappIframeRedirects?: Record<string, string>;\n\n\t/**\n\t * The repository to fetch and store the shop data\n\t */\n\tshopRepository:\n\t\t| ShopRepositoryInterface\n\t\t| ((c: HonoContext) => ShopRepositoryInterface);\n\n\t/**\n\t * A callback to setup the app server. It will be called after the app server is created and before the first request is handled\n\t */\n\tsetup?: (app: AppServer) => void;\n}\n\n/**\n * Configure the Hono server to handle the app registration and context resolution\n */\nexport function configureAppServer(hono: Hono, cfg: MiddlewareConfig) {\n\tlet app: AppServer | null = null;\n\n\tcfg.registrationUrl = cfg.registrationUrl || \"/app/register\";\n\tcfg.registerConfirmationUrl =\n\t\tcfg.registerConfirmationUrl || \"/app/register/confirm\";\n\tcfg.appActivateUrl = cfg.appActivateUrl || \"/app/activate\";\n\tcfg.appDeactivateUrl = cfg.appDeactivateUrl || \"/app/deactivate\";\n\tcfg.appDeleteUrl = cfg.appDeleteUrl || \"/app/delete\";\n\tcfg.appPath = cfg.appPath || \"/app/*\";\n\tcfg.appInstallUrl = cfg.appInstallUrl || \"/app/install\";\n\tcfg.appUpdateUrl = cfg.appUpdateUrl || \"/app/update\";\n\n\tcfg.appIframePath = cfg.appIframePath || \"/client-api/*\";\n\n\thono.use(\"*\", async (ctx, next) => {\n\t\tif (app === null) {\n\t\t\tconst appUrl = cfg.appUrl || buildBaseUrl(ctx.req.url);\n\n\t\t\tif (typeof cfg.shopRepository === \"function\") {\n\t\t\t\tcfg.shopRepository = cfg.shopRepository(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appName === \"function\") {\n\t\t\t\tcfg.appName = cfg.appName(ctx);\n\t\t\t}\n\n\t\t\tif (typeof cfg.appSecret === \"function\") {\n\t\t\t\tcfg.appSecret = cfg.appSecret(ctx);\n\t\t\t}\n\n\t\t\tapp = new AppServer(\n\t\t\t\t{\n\t\t\t\t\tappName: cfg.appName,\n\t\t\t\t\tappSecret: cfg.appSecret,\n\t\t\t\t\tauthorizeCallbackUrl: appUrl + cfg.registerConfirmationUrl,\n\t\t\t\t},\n\t\t\t\tcfg.shopRepository,\n\t\t\t);\n\n\t\t\tif (cfg.setup) {\n\t\t\t\tcfg.setup(app);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"app\", app);\n\n\t\tawait next();\n\t});\n\n\thono.use(cfg.appPath, async (ctx, next) => {\n\t\t// @ts-ignore\n\t\tconst app = ctx.get(\"app\") as AppServer;\n\n\t\t// Don't validate signature for registration\n\t\tif (\n\t\t\tctx.req.path === cfg.registrationUrl ||\n\t\t\tctx.req.path === cfg.registerConfirmationUrl ||\n\t\t\tctx.req.path === cfg.appActivateUrl ||\n\t\t\tctx.req.path === cfg.appDeactivateUrl ||\n\t\t\tctx.req.path === cfg.appDeleteUrl\n\t\t) {\n\t\t\tawait next();\n\t\t\treturn;\n\t\t}\n\n\t\tlet context: Context<ShopInterface, unknown>;\n\t\ttry {\n\t\t\tcontext =\n\t\t\t\tctx.req.method === \"GET\"\n\t\t\t\t\t? await app.contextResolver.fromBrowser(ctx.req.raw)\n\t\t\t\t\t: await app.contextResolver.fromAPI(ctx.req.raw);\n\t\t} catch (_e) {\n\t\t\treturn jsonResponse({ message: \"Invalid request\" }, 400);\n\t\t}\n\n\t\t// @ts-ignore\n\t\tctx.set(\"shop\", context.shop);\n\t\t// @ts-ignore\n\t\tctx.set(\"context\", context);\n\n\t\tawait next();\n\n\t\tconst cloned = ctx.res.clone();\n\n\t\tawait ctx\n\t\t\t.get(\"app\")\n\t\t\t.signer.signResponse(cloned, ctx.get(\"shop\").getShopSecret());\n\n\t\tctx.header(\n\t\t\t\"shopware-app-signature\",\n\t\t\tcloned.headers.get(\"shopware-app-signature\") as string,\n\t\t);\n\t});\n\n\thono.get(cfg.registrationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorize(ctx.req.raw);\n\t});\n\n\thono.post(cfg.registerConfirmationUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.authorizeCallback(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appInstallUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.install(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appActivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.activate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appUpdateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.update(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeactivateUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.deactivate(ctx.req.raw);\n\t});\n\n\thono.post(cfg.appDeleteUrl, async (ctx) => {\n\t\tconst app = ctx.get(\"app\");\n\n\t\treturn await app.registration.delete(ctx.req.raw);\n\t});\n\n\tif (cfg.appIframeEnable) {\n\t\thono.use(cfg.appIframePath, async (ctx, next) => {\n\t\t\tconst shopId = await getSignedCookie(\n\t\t\t\tctx,\n\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t\"shop\",\n\t\t\t);\n\n\t\t\tif (!shopId) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tconst shop = await ctx.get(\"app\").repository.getShopById(shopId);\n\n\t\t\tif (!shop) {\n\t\t\t\treturn ctx.json({ message: \"Shop not found\" }, { status: 400 });\n\t\t\t}\n\n\t\t\tctx.set(\"shop\", shop);\n\t\t\t// @ts-ignore\n\t\t\tctx.set(\"context\", new Context(shop, {}, new HttpClient(shop)));\n\n\t\t\tawait next();\n\t\t});\n\n\t\tfor (let [path, redirect] of Object.entries(cfg.appIframeRedirects || {})) {\n\t\t\thono.get(path, async (ctx) => {\n\t\t\t\tconst url = new URL(ctx.req.url);\n\n\t\t\t\tif (redirect.startsWith(\"/\")) {\n\t\t\t\t\turl.pathname = redirect;\n\t\t\t\t\tredirect = url.toString();\n\t\t\t\t} else {\n\t\t\t\t\tconst newUrl = new URL(redirect);\n\n\t\t\t\t\tfor (const [key, value] of url.searchParams) {\n\t\t\t\t\t\tnewUrl.searchParams.set(key, value);\n\t\t\t\t\t}\n\n\t\t\t\t\tredirect = newUrl.toString();\n\t\t\t\t}\n\n\t\t\t\tawait setSignedCookie(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"shop\",\n\t\t\t\t\tctx.get(\"shop\").getShopId(),\n\t\t\t\t\tctx.get(\"app\").cfg.appSecret,\n\t\t\t\t);\n\n\t\t\t\treturn ctx.redirect(redirect);\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction jsonResponse(body: object, status = 200): Response {\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t});\n}\n\nfunction buildBaseUrl(url: string): string {\n\tconst u = new URL(url);\n\n\treturn `${u.protocol}//${u.host}`;\n}\n"]}
@@ -18,7 +18,7 @@ export declare class Registration<Shop extends ShopInterface = ShopInterface> {
18
18
  * This method should be called by Shopware Shop to set the shop active.
19
19
  *
20
20
  * <webhooks>
21
- * <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/>
21
+ * <webhook name="appActivate" url="http://localhost:3000/app/activate" event="app.activated"/>
22
22
  * </webhooks>
23
23
  */
24
24
  activate(req: Request): Promise<Response>;
@@ -26,7 +26,7 @@ export declare class Registration<Shop extends ShopInterface = ShopInterface> {
26
26
  * This method should be called by Shopware when the app was installed.
27
27
  *
28
28
  * <webhooks>
29
- * <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/>
29
+ * <webhook name="appInstall" url="http://localhost:3000/app/install" event="app.installed"/>
30
30
  * </webhooks>
31
31
  */
32
32
  install(req: Request): Promise<Response>;
@@ -42,7 +42,7 @@ export declare class Registration<Shop extends ShopInterface = ShopInterface> {
42
42
  * This method should be called by Shopware when the app was updated.
43
43
  *
44
44
  * <webhooks>
45
- * <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/>
45
+ * <webhook name="appUpdated" url="http://localhost:3000/app/update" event="app.updated"/>
46
46
  * </webhooks>
47
47
  */
48
48
  update(req: Request): Promise<Response>;
@@ -1 +1 @@
1
- {"version":3,"file":"registration.d.ts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;IAE/D,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;gBADV,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI;CAElB;AAED,qBAAa,kBAAkB,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAEjE,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;gBADV,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI;CAElB;AAED,qBAAa,cAAc,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAE7D,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,MAAM,GAAG,IAAI;gBAFzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,UAAU,GAAE,MAAM,GAAG,IAAW;CAExC;AAED,qBAAa,iBAAiB,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa;IAEhE,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,OAAO,GAAG,IAAI;gBAF5B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,YAAY,GAAE,OAAO,GAAG,IAAW;CAE3C"}
@@ -17,16 +17,17 @@ export class Registration {
17
17
  return new InvalidRequestResponse("Invalid Request", 400);
18
18
  }
19
19
  const shopId = url.searchParams.get("shop-id");
20
- const shopUrl = url.searchParams.get("shop-url")
21
- .toString()
22
- .replace(/\/+$/, "");
20
+ const shopUrl = url.searchParams.get("shop-url");
23
21
  const timestamp = url.searchParams.get("timestamp");
24
22
  const v = await this.app.signer.verify(req.headers.get("shopware-app-signature"), `shop-id=${shopId}&shop-url=${shopUrl}&timestamp=${timestamp}`, this.app.cfg.appSecret);
25
23
  if (!v) {
26
24
  return new InvalidRequestResponse("Cannot validate app signature");
27
25
  }
28
26
  const shopSecret = randomString();
29
- await this.app.repository.createShop(shopId, shopUrl, shopSecret);
27
+ const sanitizedShopUrl = shopUrl
28
+ .replace(/([^:])(\/\/+)/g, "$1/")
29
+ .replace(/\/+$/, "");
30
+ await this.app.repository.createShop(shopId, sanitizedShopUrl, shopSecret);
30
31
  return new Response(JSON.stringify({
31
32
  proof: await this.app.signer.sign(shopId + shopUrl + this.app.cfg.appName, this.app.cfg.appSecret),
32
33
  secret: shopSecret,
@@ -74,7 +75,7 @@ export class Registration {
74
75
  * This method should be called by Shopware Shop to set the shop active.
75
76
  *
76
77
  * <webhooks>
77
- * <webhook name="appActivate" url="http://localhost:3000/app/delete" event="app.activated"/>
78
+ * <webhook name="appActivate" url="http://localhost:3000/app/activate" event="app.activated"/>
78
79
  * </webhooks>
79
80
  */
80
81
  async activate(req) {
@@ -89,7 +90,7 @@ export class Registration {
89
90
  * This method should be called by Shopware when the app was installed.
90
91
  *
91
92
  * <webhooks>
92
- * <webhook name="appInstall" url="http://localhost:3000/app/installed" event="app.installed"/>
93
+ * <webhook name="appInstall" url="http://localhost:3000/app/install" event="app.installed"/>
93
94
  * </webhooks>
94
95
  */
95
96
  async install(req) {
@@ -117,7 +118,7 @@ export class Registration {
117
118
  * This method should be called by Shopware when the app was updated.
118
119
  *
119
120
  * <webhooks>
120
- * <webhook name="appUpdated" url="http://localhost:3000/app/updated" event="app.updated"/>
121
+ * <webhook name="appUpdated" url="http://localhost:3000/app/update" event="app.updated"/>
121
122
  * </webhooks>
122
123
  */
123
124
  async update(req) {
@@ -1 +1 @@
1
- {"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/registration.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,YAAY;IACJ;IAApB,YAAoB,GAAoB;QAApB,QAAG,GAAH,GAAG,CAAiB;IAAG,CAAC;IAE5C;;;;OAIG;IACI,KAAK,CAAC,SAAS,CAAC,GAAY;QAClC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE7B,IACC,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC;YACjC,CAAC,GAAG,CAAC,OAAO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OAAgB,EAChB,IAAU;QADV,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;IACf,CAAC;CACJ;AAED,MAAM,OAAO,cAAc;IAElB;IACA;IACA;IAHR,YACQ,OAAgB,EAChB,IAAU,EACV,aAA4B,IAAI;QAFhC,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,eAAU,GAAV,UAAU,CAAsB;IACrC,CAAC;CACJ;AAED,MAAM,OAAO,iBAAiB;IAErB;IACA;IACA;IAHR,YACQ,OAAgB,EAChB,IAAU,EACV,eAA+B,IAAI;QAFnC,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,iBAAY,GAAZ,YAAY,CAAuB;IACxC,CAAC;CACJ","sourcesContent":["import type { AppServer } from \"./app.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\nexport class Registration<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(private app: AppServer<Shop>) {}\n\n\t/**\n\t * This method checks the request for the handshake with the Shopware Shop.\n\t * if it's valid a Shop will be created, and a proof will be responded with a confirmation url.\n\t * then the Shop will call the confirmation url, and this should be handled by the authorizeCallback method to finish the handshake.\n\t */\n\tpublic async authorize(req: Request): Promise<Response> {\n\t\tconst url = new URL(req.url);\n\n\t\tif (\n\t\t\t!url.searchParams.has(\"shop-url\") ||\n\t\t\t!req.headers.has(\"shopware-app-signature\") ||\n\t\t\t!url.searchParams.has(\"shop-id\") ||\n\t\t\t!url.searchParams.has(\"timestamp\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shopId = url.searchParams.get(\"shop-id\") as string;\n\t\tconst shopUrl = (url.searchParams.get(\"shop-url\") as string)\n\t\t\t.toString()\n\t\t\t.replace(/\\/+$/, \"\");\n\t\tconst timestamp = url.searchParams.get(\"timestamp\") as string;\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-app-signature\") as string,\n\t\t\t`shop-id=${shopId}&shop-url=${shopUrl}&timestamp=${timestamp}`,\n\t\t\tthis.app.cfg.appSecret,\n\t\t);\n\n\t\tif (!v) {\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tconst shopSecret = randomString();\n\n\t\tawait this.app.repository.createShop(shopId, shopUrl, shopSecret);\n\n\t\treturn new Response(\n\t\t\tJSON.stringify({\n\t\t\t\tproof: await this.app.signer.sign(\n\t\t\t\t\tshopId + shopUrl + this.app.cfg.appName,\n\t\t\t\t\tthis.app.cfg.appSecret,\n\t\t\t\t),\n\t\t\t\tsecret: shopSecret,\n\t\t\t\tconfirmation_url: this.app.cfg.authorizeCallbackUrl,\n\t\t\t}),\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * This method is called by the Shopware Shop to confirm the handshake.\n\t * It will update the shop with the given oauth2 credentials.\n\t */\n\tpublic async authorizeCallback(req: Request): Promise<Response> {\n\t\tconst bodyContent = await req.text();\n\n\t\tconst body = JSON.parse(bodyContent);\n\n\t\tif (\n\t\t\ttypeof body.shopId !== \"string\" ||\n\t\t\ttypeof body.apiKey !== \"string\" ||\n\t\t\ttypeof body.secretKey !== \"string\" ||\n\t\t\t!req.headers.has(\"shopware-shop-signature\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(body.shopId as string);\n\n\t\tif (shop === null) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid shop given\");\n\t\t}\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-shop-signature\") as string,\n\t\t\tbodyContent,\n\t\t\tshop.getShopSecret(),\n\t\t);\n\n\t\tif (!v) {\n\t\t\t// Shop has failed the verification. Delete it from our DB.\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tshop.setShopCredentials(body.apiKey, body.secretKey);\n\n\t\tconst event = new ShopAuthorizeEvent(req, shop);\n\t\tawait this.app.hooks.publish(\"onAuthorize\", event);\n\n\t\tif (event.reason) {\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(event.reason, 403);\n\t\t}\n\n\t\tawait this.app.repository.updateShop(shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appActivate\" url=\"http://localhost:3000/app/delete\" event=\"app.activated\"/>\n\t * </webhooks>\n\t */\n\tpublic async activate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppActivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppActivate\", event);\n\n\t\tctx.shop.setShopActive(true);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was installed.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appInstall\" url=\"http://localhost:3000/app/installed\" event=\"app.installed\"/>\n\t * </webhooks>\n\t */\n\tpublic async install(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppInstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppInstall\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop in-active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDeactivated\" url=\"http://localhost:3000/app/deactivated\" event=\"app.deactivated\"/>\n\t * </webhooks>\n\t */\n\tpublic async deactivate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppDeactivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppDeactivate\", event);\n\n\t\tctx.shop.setShopActive(false);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was updated.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appUpdated\" url=\"http://localhost:3000/app/updated\" event=\"app.updated\"/>\n\t * </webhooks>\n\t */\n\tpublic async update(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppUpdateEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUpdate\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to delete the app.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDelete\" url=\"http://localhost:3000/app/delete\" event=\"app.deleted\"/>\n\t * </webhooks>\n\t */\n\tpublic async delete(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { keepUserData?: boolean } };\n\t\t}>(req);\n\n\t\tconst event = new AppUninstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.keepUserData ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUninstall\", event);\n\n\t\tif (event.keepUserData === false) {\n\t\t\tawait this.app.repository.deleteShop(ctx.shop.getShopId());\n\t\t}\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n}\n\nexport function randomString(length = 120) {\n\tlet result = \"\";\n\tconst characters =\n\t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\tconst charactersLength = characters.length;\n\tfor (let i = 0; i < length; i++) {\n\t\tresult += characters.charAt(Math.floor(Math.random() * charactersLength));\n\t}\n\n\treturn result;\n}\n\nclass InvalidRequestResponse extends Response {\n\tconstructor(message: string, status = 401) {\n\t\tsuper(JSON.stringify({ message }), {\n\t\t\tstatus,\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport class ShopAuthorizeEvent<Shop extends ShopInterface = ShopInterface> {\n\tprivate reject: string | null = null;\n\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n\n\tpublic rejectRegistration(reason: string) {\n\t\tthis.reject = reason;\n\t}\n\n\tpublic get reason() {\n\t\treturn this.reject;\n\t}\n}\n\nexport class AppInstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppActivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppDeactivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppUpdateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppUninstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic keepUserData: boolean | null = null,\n\t) {}\n}\n"]}
1
+ {"version":3,"file":"registration.js","sourceRoot":"","sources":["../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pB,CAAC;CACD;AAED,MAAM,OAAO,eAAe;IAEnB;IACA;IACA;IAHR,YACQ,OAAgB,EAChB,IAAU,EACV,aAA4B,IAAI;QAFhC,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,eAAU,GAAV,UAAU,CAAsB;IACrC,CAAC;CACJ;AAED,MAAM,OAAO,gBAAgB;IAEpB;IACA;IAFR,YACQ,OAAgB,EAChB,IAAU;QADV,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;IACf,CAAC;CACJ;AAED,MAAM,OAAO,kBAAkB;IAEtB;IACA;IAFR,YACQ,OAAgB,EAChB,IAAU;QADV,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;IACf,CAAC;CACJ;AAED,MAAM,OAAO,cAAc;IAElB;IACA;IACA;IAHR,YACQ,OAAgB,EAChB,IAAU,EACV,aAA4B,IAAI;QAFhC,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,eAAU,GAAV,UAAU,CAAsB;IACrC,CAAC;CACJ;AAED,MAAM,OAAO,iBAAiB;IAErB;IACA;IACA;IAHR,YACQ,OAAgB,EAChB,IAAU,EACV,eAA+B,IAAI;QAFnC,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAM;QACV,iBAAY,GAAZ,YAAY,CAAuB;IACxC,CAAC;CACJ","sourcesContent":["import type { AppServer } from \"./app.js\";\nimport type { ShopInterface } from \"./repository.js\";\n\nexport class Registration<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(private app: AppServer<Shop>) {}\n\n\t/**\n\t * This method checks the request for the handshake with the Shopware Shop.\n\t * if it's valid a Shop will be created, and a proof will be responded with a confirmation url.\n\t * then the Shop will call the confirmation url, and this should be handled by the authorizeCallback method to finish the handshake.\n\t */\n\tpublic async authorize(req: Request): Promise<Response> {\n\t\tconst url = new URL(req.url);\n\n\t\tif (\n\t\t\t!url.searchParams.has(\"shop-url\") ||\n\t\t\t!req.headers.has(\"shopware-app-signature\") ||\n\t\t\t!url.searchParams.has(\"shop-id\") ||\n\t\t\t!url.searchParams.has(\"timestamp\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shopId = url.searchParams.get(\"shop-id\") as string;\n\t\tconst shopUrl = url.searchParams.get(\"shop-url\") as string;\n\t\tconst timestamp = url.searchParams.get(\"timestamp\") as string;\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-app-signature\") as string,\n\t\t\t`shop-id=${shopId}&shop-url=${shopUrl}&timestamp=${timestamp}`,\n\t\t\tthis.app.cfg.appSecret,\n\t\t);\n\n\t\tif (!v) {\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tconst shopSecret = randomString();\n\t\tconst sanitizedShopUrl = shopUrl\n\t\t\t.replace(/([^:])(\\/\\/+)/g, \"$1/\")\n\t\t\t.replace(/\\/+$/, \"\");\n\n\t\tawait this.app.repository.createShop(shopId, sanitizedShopUrl, shopSecret);\n\n\t\treturn new Response(\n\t\t\tJSON.stringify({\n\t\t\t\tproof: await this.app.signer.sign(\n\t\t\t\t\tshopId + shopUrl + this.app.cfg.appName,\n\t\t\t\t\tthis.app.cfg.appSecret,\n\t\t\t\t),\n\t\t\t\tsecret: shopSecret,\n\t\t\t\tconfirmation_url: this.app.cfg.authorizeCallbackUrl,\n\t\t\t}),\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * This method is called by the Shopware Shop to confirm the handshake.\n\t * It will update the shop with the given oauth2 credentials.\n\t */\n\tpublic async authorizeCallback(req: Request): Promise<Response> {\n\t\tconst bodyContent = await req.text();\n\n\t\tconst body = JSON.parse(bodyContent);\n\n\t\tif (\n\t\t\ttypeof body.shopId !== \"string\" ||\n\t\t\ttypeof body.apiKey !== \"string\" ||\n\t\t\ttypeof body.secretKey !== \"string\" ||\n\t\t\t!req.headers.has(\"shopware-shop-signature\")\n\t\t) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid Request\", 400);\n\t\t}\n\n\t\tconst shop = await this.app.repository.getShopById(body.shopId as string);\n\n\t\tif (shop === null) {\n\t\t\treturn new InvalidRequestResponse(\"Invalid shop given\");\n\t\t}\n\n\t\tconst v = await this.app.signer.verify(\n\t\t\treq.headers.get(\"shopware-shop-signature\") as string,\n\t\t\tbodyContent,\n\t\t\tshop.getShopSecret(),\n\t\t);\n\n\t\tif (!v) {\n\t\t\t// Shop has failed the verification. Delete it from our DB.\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(\"Cannot validate app signature\");\n\t\t}\n\n\t\tshop.setShopCredentials(body.apiKey, body.secretKey);\n\n\t\tconst event = new ShopAuthorizeEvent(req, shop);\n\t\tawait this.app.hooks.publish(\"onAuthorize\", event);\n\n\t\tif (event.reason) {\n\t\t\tawait this.app.repository.deleteShop(shop.getShopId());\n\n\t\t\treturn new InvalidRequestResponse(event.reason, 403);\n\t\t}\n\n\t\tawait this.app.repository.updateShop(shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appActivate\" url=\"http://localhost:3000/app/activate\" event=\"app.activated\"/>\n\t * </webhooks>\n\t */\n\tpublic async activate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppActivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppActivate\", event);\n\n\t\tctx.shop.setShopActive(true);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was installed.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appInstall\" url=\"http://localhost:3000/app/install\" event=\"app.installed\"/>\n\t * </webhooks>\n\t */\n\tpublic async install(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppInstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppInstall\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to set the shop in-active.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDeactivated\" url=\"http://localhost:3000/app/deactivated\" event=\"app.deactivated\"/>\n\t * </webhooks>\n\t */\n\tpublic async deactivate(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI(req);\n\n\t\tconst event = new AppDeactivateEvent(req, ctx.shop);\n\t\tawait this.app.hooks.publish(\"onAppDeactivate\", event);\n\n\t\tctx.shop.setShopActive(false);\n\n\t\tawait this.app.repository.updateShop(ctx.shop);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware when the app was updated.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appUpdated\" url=\"http://localhost:3000/app/update\" event=\"app.updated\"/>\n\t * </webhooks>\n\t */\n\tpublic async update(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { appVersion: string } };\n\t\t}>(req);\n\n\t\tconst event = new AppUpdateEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.appVersion ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUpdate\", event);\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n\n\t/**\n\t * This method should be called by Shopware Shop to delete the app.\n\t *\n\t * <webhooks>\n\t * <webhook name=\"appDelete\" url=\"http://localhost:3000/app/delete\" event=\"app.deleted\"/>\n\t * </webhooks>\n\t */\n\tpublic async delete(req: Request): Promise<Response> {\n\t\tconst ctx = await this.app.contextResolver.fromAPI<{\n\t\t\tdata: { payload: { keepUserData?: boolean } };\n\t\t}>(req);\n\n\t\tconst event = new AppUninstallEvent(\n\t\t\treq,\n\t\t\tctx.shop,\n\t\t\tctx.payload?.data?.payload?.keepUserData ?? null,\n\t\t);\n\t\tawait this.app.hooks.publish(\"onAppUninstall\", event);\n\n\t\tif (event.keepUserData === false) {\n\t\t\tawait this.app.repository.deleteShop(ctx.shop.getShopId());\n\t\t}\n\n\t\treturn new Response(null, { status: 204 });\n\t}\n}\n\nexport function randomString(length = 120) {\n\tlet result = \"\";\n\tconst characters =\n\t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\tconst charactersLength = characters.length;\n\tfor (let i = 0; i < length; i++) {\n\t\tresult += characters.charAt(Math.floor(Math.random() * charactersLength));\n\t}\n\n\treturn result;\n}\n\nclass InvalidRequestResponse extends Response {\n\tconstructor(message: string, status = 401) {\n\t\tsuper(JSON.stringify({ message }), {\n\t\t\tstatus,\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport class ShopAuthorizeEvent<Shop extends ShopInterface = ShopInterface> {\n\tprivate reject: string | null = null;\n\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n\n\tpublic rejectRegistration(reason: string) {\n\t\tthis.reject = reason;\n\t}\n\n\tpublic get reason() {\n\t\treturn this.reject;\n\t}\n}\n\nexport class AppInstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppActivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppDeactivateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t) {}\n}\n\nexport class AppUpdateEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic appVersion: string | null = null,\n\t) {}\n}\n\nexport class AppUninstallEvent<Shop extends ShopInterface = ShopInterface> {\n\tconstructor(\n\t\tpublic request: Request,\n\t\tpublic shop: Shop,\n\t\tpublic keepUserData: boolean | null = null,\n\t) {}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/app-server-sdk",
3
- "version": "1.1.15",
3
+ "version": "1.1.17",
4
4
  "description": "App Server SDK for JavaScript",
5
5
  "type": "module",
6
6
  "license": "MIT",