@pinelab/vendure-plugin-anonymized-order 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 1.2.0 (2024-07-21)
2
+
3
+ - Updated Vendure to 2.2.6
4
+
5
+ # 1.1.0 (2024-06-14)
6
+
7
+ - Allow overriding the default removal of fields with the custom strategy
8
+
1
9
  # 1.0.1 (2023-12-29)
2
10
 
3
11
  - Fixed exposed fields bug reported in [here](https://github.com/Pinelab-studio/pinelab-vendure-plugins/issues/316)
package/README.md CHANGED
@@ -8,13 +8,7 @@ Add the plugin to your config:
8
8
 
9
9
  ```ts
10
10
  import { AnonymizedOrderPlugin } from '@pinelab/vendure-plugin-anonymized-order';
11
- plugins: [
12
- AnonymizedOrderPlugin.init({
13
- anonymizeOrderFn: (order) => {
14
- order.lines = [];
15
- },
16
- }),
17
- ];
11
+ plugins: [AnonymizedOrderPlugin.init({})];
18
12
  ```
19
13
 
20
14
  ## Displaying placed order without requiring the customer to log in
@@ -36,3 +30,22 @@ In the order confirmation email, you could have a link like `https://my-storefro
36
30
  ```
37
31
 
38
32
  This will then return the order without `shippingAddress`, `billingAddress` and `customer` fields.
33
+
34
+ ## Customizing what data is removed
35
+
36
+ You can supply your own strategy for anonymizing a given order. In that case, **the plugin will not remove any data from the order** for you.
37
+
38
+ The example below will only remove the customer, but still expose shipping and billing address:
39
+
40
+ ```ts
41
+ import { AnonymizedOrderPlugin } from '@pinelab/vendure-plugin-anonymized-order';
42
+ plugins: [
43
+ AnonymizedOrderPlugin.init({
44
+ anonymizeOrderFn: (order) => {
45
+ order.customer = {};
46
+ },
47
+ }),
48
+ ];
49
+ ```
50
+
51
+ You should be cautious about what to return, because of the relational nature of GraphQL. For example, exposing the `order.customer`, will also allow the client to query `order.customer.orders`, thus exposing all orders of that customer.
@@ -6,5 +6,5 @@ export declare class AnonymizeOrderShopResolver {
6
6
  anonymizedOrder(ctx: RequestContext, args: {
7
7
  orderCode: string;
8
8
  emailAddress: string;
9
- }): Promise<Order>;
9
+ }, info: any): Promise<Order>;
10
10
  }
@@ -20,20 +20,21 @@ let AnonymizeOrderShopResolver = class AnonymizeOrderShopResolver {
20
20
  constructor(anonymizeOrderService) {
21
21
  this.anonymizeOrderService = anonymizeOrderService;
22
22
  }
23
- async anonymizedOrder(ctx, args) {
23
+ async anonymizedOrder(ctx, args, info) {
24
24
  return await this.anonymizeOrderService.getAnonymizedOrder(ctx, args.orderCode, args.emailAddress);
25
25
  }
26
26
  };
27
+ exports.AnonymizeOrderShopResolver = AnonymizeOrderShopResolver;
27
28
  __decorate([
28
29
  (0, graphql_1.Query)(),
29
30
  __param(0, (0, core_1.Ctx)()),
30
31
  __param(1, (0, graphql_1.Args)()),
32
+ __param(2, (0, graphql_1.Info)()),
31
33
  __metadata("design:type", Function),
32
- __metadata("design:paramtypes", [core_1.RequestContext, Object]),
34
+ __metadata("design:paramtypes", [core_1.RequestContext, Object, Object]),
33
35
  __metadata("design:returntype", Promise)
34
36
  ], AnonymizeOrderShopResolver.prototype, "anonymizedOrder", null);
35
- AnonymizeOrderShopResolver = __decorate([
37
+ exports.AnonymizeOrderShopResolver = AnonymizeOrderShopResolver = __decorate([
36
38
  (0, graphql_1.Resolver)(),
37
39
  __metadata("design:paramtypes", [anonymized_order_service_1.AnonymizeOrderService])
38
40
  ], AnonymizeOrderShopResolver);
39
- exports.AnonymizeOrderShopResolver = AnonymizeOrderShopResolver;
@@ -22,25 +22,25 @@ let AnonymizeOrderService = class AnonymizeOrderService {
22
22
  this.orderService = orderService;
23
23
  }
24
24
  async getAnonymizedOrder(ctx, orderCode, emailAddress) {
25
- const order = await this.orderService.findOneByCode(ctx, orderCode);
25
+ let order = await this.orderService.findOneByCode(ctx, orderCode);
26
26
  if (order && order.customer?.emailAddress === emailAddress) {
27
- order.customer = undefined;
28
- order.shippingAddress = {};
29
- order.billingAddress = {};
30
- for (let line of order.lines) {
31
- line.order = new core_1.Order();
32
- }
33
27
  if (this.options?.anonymizeOrderFn) {
34
28
  this.options.anonymizeOrderFn(order);
35
29
  }
30
+ else {
31
+ order.customer = undefined;
32
+ order.customerId = undefined;
33
+ order.shippingAddress = {};
34
+ order.billingAddress = {};
35
+ }
36
36
  return order;
37
37
  }
38
38
  throw new core_1.ForbiddenError();
39
39
  }
40
40
  };
41
- AnonymizeOrderService = __decorate([
41
+ exports.AnonymizeOrderService = AnonymizeOrderService;
42
+ exports.AnonymizeOrderService = AnonymizeOrderService = __decorate([
42
43
  (0, common_1.Injectable)(),
43
44
  __param(0, (0, common_1.Inject)(constants_1.PLUGIN_INIT_OPTIONS)),
44
45
  __metadata("design:paramtypes", [Object, core_1.OrderService])
45
46
  ], AnonymizeOrderService);
46
- exports.AnonymizeOrderService = AnonymizeOrderService;
package/dist/plugin.js CHANGED
@@ -19,13 +19,14 @@ let AnonymizedOrderPlugin = AnonymizedOrderPlugin_1 = class AnonymizedOrderPlugi
19
19
  return AnonymizedOrderPlugin_1;
20
20
  }
21
21
  };
22
- AnonymizedOrderPlugin = AnonymizedOrderPlugin_1 = __decorate([
22
+ exports.AnonymizedOrderPlugin = AnonymizedOrderPlugin;
23
+ exports.AnonymizedOrderPlugin = AnonymizedOrderPlugin = AnonymizedOrderPlugin_1 = __decorate([
23
24
  (0, core_1.VendurePlugin)({
24
25
  providers: [
25
26
  anonymized_order_service_1.AnonymizeOrderService,
26
27
  {
27
28
  provide: constants_1.PLUGIN_INIT_OPTIONS,
28
- useFactory: () => AnonymizedOrderPlugin_1.options,
29
+ useFactory: () => AnonymizedOrderPlugin.options,
29
30
  },
30
31
  ],
31
32
  shopApiExtensions: {
@@ -35,4 +36,3 @@ AnonymizedOrderPlugin = AnonymizedOrderPlugin_1 = __decorate([
35
36
  imports: [core_1.PluginCommonModule],
36
37
  })
37
38
  ], AnonymizedOrderPlugin);
38
- exports.AnonymizedOrderPlugin = AnonymizedOrderPlugin;
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@pinelab/vendure-plugin-anonymized-order",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "This plugin facilitates the retrieval of anonymized customer orders",
5
- "icon": "incognito",
6
5
  "author": "Surafel Tariku <surafelmelese09@gmail.com>",
7
6
  "homepage": "https://pinelab-plugins.com/",
8
7
  "repository": "https://github.com/Pinelab-studio/pinelab-vendure-plugins",
@@ -25,7 +24,8 @@
25
24
  "start": "yarn ts-node test/dev-server.ts",
26
25
  "build": "rimraf dist && yarn graphql-codegen && tsc",
27
26
  "test": "vitest run",
28
- "generate": "graphql-codegen"
27
+ "generate": "graphql-codegen",
28
+ "lint": "echo 'No linting configured'"
29
29
  },
30
- "gitHead": "4720c6183691dbf9fb027bb901f53fba18e5d3cb"
30
+ "gitHead": "a4375f51797b974b3edfb15e6f68926e7ccebe96"
31
31
  }