@pinelab/vendure-plugin-anonymized-order 1.0.1 → 1.1.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
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.
|
|
@@ -20,7 +20,7 @@ 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
|
};
|
|
@@ -28,8 +28,9 @@ __decorate([
|
|
|
28
28
|
(0, graphql_1.Query)(),
|
|
29
29
|
__param(0, (0, core_1.Ctx)()),
|
|
30
30
|
__param(1, (0, graphql_1.Args)()),
|
|
31
|
+
__param(2, (0, graphql_1.Info)()),
|
|
31
32
|
__metadata("design:type", Function),
|
|
32
|
-
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
33
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object, Object]),
|
|
33
34
|
__metadata("design:returntype", Promise)
|
|
34
35
|
], AnonymizeOrderShopResolver.prototype, "anonymizedOrder", null);
|
|
35
36
|
AnonymizeOrderShopResolver = __decorate([
|
|
@@ -22,17 +22,16 @@ let AnonymizeOrderService = class AnonymizeOrderService {
|
|
|
22
22
|
this.orderService = orderService;
|
|
23
23
|
}
|
|
24
24
|
async getAnonymizedOrder(ctx, orderCode, emailAddress) {
|
|
25
|
-
|
|
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.shippingAddress = {};
|
|
33
|
+
order.billingAddress = {};
|
|
34
|
+
}
|
|
36
35
|
return order;
|
|
37
36
|
}
|
|
38
37
|
throw new core_1.ForbiddenError();
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinelab/vendure-plugin-anonymized-order",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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": "
|
|
30
|
+
"gitHead": "58fff53b60a3f1fa9933affdee99001247f46f49"
|
|
31
31
|
}
|