@deenruv/copy-order-plugin 1.0.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.
Files changed (44) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +39 -0
  3. package/dist/plugin-server/constants.d.ts +1 -0
  4. package/dist/plugin-server/constants.js +4 -0
  5. package/dist/plugin-server/extensions/admin.extension.d.ts +1 -0
  6. package/dist/plugin-server/extensions/admin.extension.js +18 -0
  7. package/dist/plugin-server/index.d.ts +1 -0
  8. package/dist/plugin-server/index.js +17 -0
  9. package/dist/plugin-server/plugin.d.ts +5 -0
  10. package/dist/plugin-server/plugin.js +35 -0
  11. package/dist/plugin-server/resolvers/admin.resolver.d.ts +9 -0
  12. package/dist/plugin-server/resolvers/admin.resolver.js +40 -0
  13. package/dist/plugin-server/services/copy-order.service.d.ts +16 -0
  14. package/dist/plugin-server/services/copy-order.service.js +105 -0
  15. package/dist/plugin-server/types.d.ts +4 -0
  16. package/dist/plugin-server/types.js +2 -0
  17. package/dist/plugin-server/zeus/const.d.ts +6 -0
  18. package/dist/plugin-server/zeus/const.js +3621 -0
  19. package/dist/plugin-server/zeus/index.d.ts +18436 -0
  20. package/dist/plugin-server/zeus/index.js +1093 -0
  21. package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
  22. package/dist/plugin-server/zeus/typedDocumentNode.js +16 -0
  23. package/dist/plugin-ui/components/CopyOrderButton.d.ts +2 -0
  24. package/dist/plugin-ui/components/CopyOrderButton.js +40 -0
  25. package/dist/plugin-ui/constants.d.ts +1 -0
  26. package/dist/plugin-ui/constants.js +1 -0
  27. package/dist/plugin-ui/graphql/mutations.d.ts +11 -0
  28. package/dist/plugin-ui/graphql/mutations.js +13 -0
  29. package/dist/plugin-ui/index.d.ts +4 -0
  30. package/dist/plugin-ui/index.js +16 -0
  31. package/dist/plugin-ui/locales/en/index.d.ts +6 -0
  32. package/dist/plugin-ui/locales/en/index.js +2 -0
  33. package/dist/plugin-ui/locales/en/test.json +5 -0
  34. package/dist/plugin-ui/locales/pl/index.d.ts +6 -0
  35. package/dist/plugin-ui/locales/pl/index.js +2 -0
  36. package/dist/plugin-ui/locales/pl/test.json +5 -0
  37. package/dist/plugin-ui/tsconfig.json +18 -0
  38. package/dist/plugin-ui/zeus/const.d.ts +6 -0
  39. package/dist/plugin-ui/zeus/const.js +3618 -0
  40. package/dist/plugin-ui/zeus/index.d.ts +18436 -0
  41. package/dist/plugin-ui/zeus/index.js +1085 -0
  42. package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
  43. package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
  44. package/package.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ # License 1
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2025-present Aexol
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+
13
+ # License 2
14
+
15
+ The MIT License
16
+
17
+ Copyright (c) 2018-2025 Michael Bromley
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @deenruv/copy-order-plugin
2
+
3
+ Admin plugin that allows duplicating existing orders. It adds a `copyOrder` mutation to the Admin API and provides a UI button on the order detail page.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/copy-order-plugin
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { CopyOrderPlugin } from '@deenruv/copy-order-plugin';
15
+
16
+ // In your Deenruv server config:
17
+ plugins: [
18
+ CopyOrderPlugin.init({
19
+ // Optional: order states where copying is not allowed
20
+ notAllowedStates: ['Cancelled'],
21
+ }),
22
+ ]
23
+ ```
24
+
25
+ ## Features
26
+
27
+ - Duplicate any order with a single click from the admin panel
28
+ - Configurable state restrictions to prevent copying orders in certain states
29
+ - Returns the new order or an error response
30
+
31
+ ## Admin UI
32
+
33
+ This plugin extends the admin UI with a "Copy Order" button on the order detail page, allowing administrators to quickly duplicate orders.
34
+
35
+ ## API Extensions
36
+
37
+ ### Admin API
38
+
39
+ - **Mutation** `copyOrder(id: ID!): CopyOrderResult!` — Duplicates an order by ID. Returns either the new `Order` or a `CopyOrderErrorResponse` with an error message.
@@ -0,0 +1 @@
1
+ export declare const PLUGIN_INIT_OPTIONS: unique symbol;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PLUGIN_INIT_OPTIONS = void 0;
4
+ exports.PLUGIN_INIT_OPTIONS = Symbol("COPY_ORDER_PLUGIN_INIT_OPTIONS");
@@ -0,0 +1 @@
1
+ export declare const ADMIN_API_EXTENSION: import("graphql").DocumentNode;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ADMIN_API_EXTENSION = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ exports.ADMIN_API_EXTENSION = (0, graphql_tag_1.default) `
9
+ type CopyOrderErrorResponse {
10
+ message: String!
11
+ }
12
+
13
+ union CopyOrderResult = Order | CopyOrderErrorResponse
14
+
15
+ extend type Mutation {
16
+ copyOrder(id: ID!): CopyOrderResult!
17
+ }
18
+ `;
@@ -0,0 +1 @@
1
+ export * from "./plugin.js";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./plugin.js"), exports);
@@ -0,0 +1,5 @@
1
+ import { CopyOrderPluginOptions } from "./types.js";
2
+ export declare class CopyOrderPlugin {
3
+ private static options;
4
+ static init(options: CopyOrderPluginOptions): typeof CopyOrderPlugin;
5
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CopyOrderPlugin = void 0;
10
+ const core_1 = require("@deenruv/core");
11
+ const admin_resolver_1 = require("./resolvers/admin.resolver");
12
+ const constants_1 = require("./constants");
13
+ const admin_extension_js_1 = require("./extensions/admin.extension.js");
14
+ const copy_order_service_js_1 = require("./services/copy-order.service.js");
15
+ let CopyOrderPlugin = class CopyOrderPlugin {
16
+ static init(options) {
17
+ this.options = options;
18
+ return this;
19
+ }
20
+ };
21
+ exports.CopyOrderPlugin = CopyOrderPlugin;
22
+ exports.CopyOrderPlugin = CopyOrderPlugin = __decorate([
23
+ (0, core_1.DeenruvPlugin)({
24
+ compatibility: "^0.0.0",
25
+ imports: [core_1.PluginCommonModule],
26
+ providers: [
27
+ { provide: constants_1.PLUGIN_INIT_OPTIONS, useFactory: () => CopyOrderPlugin.options },
28
+ copy_order_service_js_1.CopyOrderService,
29
+ ],
30
+ adminApiExtensions: {
31
+ schema: admin_extension_js_1.ADMIN_API_EXTENSION,
32
+ resolvers: [admin_resolver_1.AdminResolver, copy_order_service_js_1.CopyOrderResultResolver],
33
+ },
34
+ })
35
+ ], CopyOrderPlugin);
@@ -0,0 +1,9 @@
1
+ import { ID, RequestContext } from "@deenruv/core";
2
+ import { CopyOrderService } from "../services/copy-order.service";
3
+ export declare class AdminResolver {
4
+ private service;
5
+ constructor(service: CopyOrderService);
6
+ copyOrder(ctx: RequestContext, args: {
7
+ id: ID;
8
+ }): Promise<import("@deenruv/core").Order>;
9
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AdminResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ const core_1 = require("@deenruv/core");
18
+ const copy_order_service_1 = require("../services/copy-order.service");
19
+ let AdminResolver = class AdminResolver {
20
+ constructor(service) {
21
+ this.service = service;
22
+ }
23
+ async copyOrder(ctx, args) {
24
+ return this.service.copyOrder(ctx, args.id);
25
+ }
26
+ };
27
+ exports.AdminResolver = AdminResolver;
28
+ __decorate([
29
+ (0, core_1.Allow)(core_1.Permission.SuperAdmin),
30
+ (0, graphql_1.Mutation)(),
31
+ __param(0, (0, core_1.Ctx)()),
32
+ __param(1, (0, graphql_1.Args)()),
33
+ __metadata("design:type", Function),
34
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
35
+ __metadata("design:returntype", Promise)
36
+ ], AdminResolver.prototype, "copyOrder", null);
37
+ exports.AdminResolver = AdminResolver = __decorate([
38
+ (0, graphql_1.Resolver)(),
39
+ __metadata("design:paramtypes", [copy_order_service_1.CopyOrderService])
40
+ ], AdminResolver);
@@ -0,0 +1,16 @@
1
+ import { HistoryService, ID, Order, OrderService, RelationPaths, RequestContext } from "@deenruv/core";
2
+ import { CopyOrderPluginOptions } from "../types.js";
3
+ export declare class CopyOrderError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ export declare class CopyOrderResultResolver {
7
+ __resolveType(value: unknown): string;
8
+ }
9
+ export declare class CopyOrderService {
10
+ private readonly orderService;
11
+ private readonly historyService;
12
+ private options?;
13
+ private notAllowedStates;
14
+ constructor(orderService: OrderService, historyService: HistoryService, options?: CopyOrderPluginOptions | undefined);
15
+ copyOrder(ctx: RequestContext, id: ID, relations?: RelationPaths<Order>): Promise<Order>;
16
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CopyOrderService = exports.CopyOrderResultResolver = exports.CopyOrderError = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@deenruv/core");
18
+ const constants_1 = require("../constants");
19
+ const generated_types_js_1 = require("@deenruv/common/lib/generated-types.js");
20
+ const graphql_1 = require("@nestjs/graphql");
21
+ class CopyOrderError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = "CopyOrderError";
25
+ }
26
+ }
27
+ exports.CopyOrderError = CopyOrderError;
28
+ let CopyOrderResultResolver = class CopyOrderResultResolver {
29
+ __resolveType(value) {
30
+ if (value instanceof CopyOrderError) {
31
+ return "CopyOrderErrorResponse";
32
+ }
33
+ return "Order";
34
+ }
35
+ };
36
+ exports.CopyOrderResultResolver = CopyOrderResultResolver;
37
+ __decorate([
38
+ (0, graphql_1.ResolveField)(),
39
+ __metadata("design:type", Function),
40
+ __metadata("design:paramtypes", [Object]),
41
+ __metadata("design:returntype", String)
42
+ ], CopyOrderResultResolver.prototype, "__resolveType", null);
43
+ exports.CopyOrderResultResolver = CopyOrderResultResolver = __decorate([
44
+ (0, graphql_1.Resolver)("CopyOrderResult")
45
+ ], CopyOrderResultResolver);
46
+ let CopyOrderService = class CopyOrderService {
47
+ constructor(orderService, historyService, options) {
48
+ var _a;
49
+ this.orderService = orderService;
50
+ this.historyService = historyService;
51
+ this.options = options;
52
+ this.notAllowedStates = [];
53
+ this.options = options;
54
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.notAllowedStates)
55
+ this.notAllowedStates = this.options.notAllowedStates;
56
+ }
57
+ async copyOrder(ctx, id, relations = []) {
58
+ var _a, _b, _c, _d, _e;
59
+ const order = await this.orderService.findOne(ctx, id, [
60
+ ...relations,
61
+ "customer",
62
+ "lines",
63
+ "shippingLines.shippingMethod",
64
+ ]);
65
+ if (!order)
66
+ throw new CopyOrderError("ORDER_NOT_FOUND");
67
+ if (this.notAllowedStates.includes(order.state))
68
+ throw new CopyOrderError("ORDER_STATE_NOT_ALLOWED");
69
+ const draftOrder = await this.orderService.createDraft(ctx);
70
+ if (!order.customer)
71
+ throw new CopyOrderError("ORDER_HAS_NO_CUSTOMER");
72
+ await this.orderService.setShippingAddress(ctx, draftOrder.id, Object.assign(Object.assign({}, order.shippingAddress), { streetLine1: ((_a = order.shippingAddress) === null || _a === void 0 ? void 0 : _a.streetLine1) || "", countryCode: ((_b = order.shippingAddress) === null || _b === void 0 ? void 0 : _b.countryCode) || "" }));
73
+ await this.orderService.setBillingAddress(ctx, draftOrder.id, Object.assign(Object.assign({}, order.billingAddress), { streetLine1: ((_c = order.billingAddress) === null || _c === void 0 ? void 0 : _c.streetLine1) || "", countryCode: ((_d = order.billingAddress) === null || _d === void 0 ? void 0 : _d.countryCode) || "" }));
74
+ await this.orderService.addCustomerToOrder(ctx, draftOrder.id, order.customer);
75
+ await this.orderService.addItemsToOrder(ctx, draftOrder.id, order.lines);
76
+ const shippingMethod = (_e = order.shippingLines[0]) === null || _e === void 0 ? void 0 : _e.shippingMethod;
77
+ if (shippingMethod)
78
+ await this.orderService.setShippingMethod(ctx, draftOrder.id, [
79
+ shippingMethod.id,
80
+ ]);
81
+ const history = await this.historyService.getHistoryForOrder(ctx, order.id, false);
82
+ for (const entry of history.items) {
83
+ if (entry.type === generated_types_js_1.HistoryEntryType.ORDER_NOTE) {
84
+ await this.historyService.createHistoryEntryForOrder({ ctx, data: entry.data, type: entry.type, orderId: draftOrder.id }, entry.isPublic);
85
+ }
86
+ }
87
+ await this.historyService.createHistoryEntryForOrder({
88
+ ctx,
89
+ data: { note: "createCopyNote" },
90
+ orderId: draftOrder.id,
91
+ type: generated_types_js_1.HistoryEntryType.ORDER_NOTE,
92
+ }, false);
93
+ const final = await this.orderService.findOne(ctx, draftOrder.id, relations);
94
+ if (!final)
95
+ throw new CopyOrderError("COULD_NOT_COPY_ORDER");
96
+ return final;
97
+ }
98
+ };
99
+ exports.CopyOrderService = CopyOrderService;
100
+ exports.CopyOrderService = CopyOrderService = __decorate([
101
+ (0, common_1.Injectable)(),
102
+ __param(2, (0, common_1.Inject)(constants_1.PLUGIN_INIT_OPTIONS)),
103
+ __metadata("design:paramtypes", [core_1.OrderService,
104
+ core_1.HistoryService, Object])
105
+ ], CopyOrderService);
@@ -0,0 +1,4 @@
1
+ import { Order } from "@deenruv/core";
2
+ export type CopyOrderPluginOptions = {
3
+ notAllowedStates?: Order["state"][];
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare const AllTypesProps: Record<string, any>;
2
+ export declare const ReturnTypes: Record<string, any>;
3
+ export declare const Ops: {
4
+ query: "Query";
5
+ mutation: "Mutation";
6
+ };