@myparcel-dev/pdk-common 1.11.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 +426 -0
- package/dist/data/common.d.ts +21 -0
- package/dist/data/constants.d.ts +18 -0
- package/dist/data/endpoints.d.ts +97 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/types/endpoints.types.d.ts +13 -0
- package/dist/types/generic.types.d.ts +7 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/php-pdk.types.d.ts +750 -0
- package/dist/types/pluginSettings.types.d.ts +29 -0
- package/package.json +48 -0
- package/src/__tests__/__snapshots__/exports.spec.ts.snap +14 -0
- package/src/__tests__/exports.spec.ts +8 -0
- package/src/data/common.ts +23 -0
- package/src/data/constants.ts +21 -0
- package/src/data/endpoints.ts +114 -0
- package/src/data/index.ts +3 -0
- package/src/index.ts +2 -0
- package/src/types/endpoints.types.ts +29 -0
- package/src/types/generic.types.ts +10 -0
- package/src/types/index.ts +4 -0
- package/src/types/php-pdk.types.ts +880 -0
- package/src/types/pluginSettings.types.ts +42 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type PackageTypeName } from '@myparcel-dev/constants';
|
|
2
|
+
import { type TriState } from '../data';
|
|
3
|
+
export type LabelFormat = 'a4' | 'a6';
|
|
4
|
+
export type LabelOutput = 'open' | 'download';
|
|
5
|
+
type LabelPositionNumber = 1 | 2 | 3 | 4;
|
|
6
|
+
export type LabelPosition = LabelPositionNumber | `${LabelPositionNumber}`;
|
|
7
|
+
/**
|
|
8
|
+
* @see 'allowedShippingMethodsKeys' in pdk config
|
|
9
|
+
*/
|
|
10
|
+
export type ShippingMethodType = TriState.Off | TriState.Inherit | PackageTypeName.Package | PackageTypeName.PackageSmall | PackageTypeName.Mailbox | PackageTypeName.DigitalStamp | PackageTypeName.Letter;
|
|
11
|
+
export type ShippingMethodId = string;
|
|
12
|
+
/**
|
|
13
|
+
* Shipping method types as keys and an array of shipping method IDs as values. Each shipping method ID can only be in one array.
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* ```json
|
|
17
|
+
* {
|
|
18
|
+
* "off": [ "method_5" ],
|
|
19
|
+
* "inherit": [ "method_1", "method_2" ],
|
|
20
|
+
* "package": [ "method_3" ],
|
|
21
|
+
* "package_small": [],
|
|
22
|
+
* "mailbox": [ "method_4" ],
|
|
23
|
+
* "digital_stamp": [],
|
|
24
|
+
* "letter": []
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type ShippingMethodTypeMap = Record<ShippingMethodType, ShippingMethodId[]>;
|
|
29
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@myparcel-dev/pdk-common",
|
|
3
|
+
"version": "1.11.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/myparcelnl/js-pdk.git",
|
|
7
|
+
"directory": "libs/common"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": "./src/index.ts",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"./src",
|
|
16
|
+
"./dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "run ws:ts:build \"$(pwd)\"",
|
|
20
|
+
"clean": "run ws:clean \"$(pwd)\"",
|
|
21
|
+
"emit": "run ws:ts:emit \"$(pwd)\"",
|
|
22
|
+
"lint": "run ws:lint \"$(pwd)\"",
|
|
23
|
+
"lint:fix": "run ws:lint:fix \"$(pwd)\"",
|
|
24
|
+
"test": "run ws:test \"$(pwd)\"",
|
|
25
|
+
"test:coverage": "run ws:test:coverage \"$(pwd)\"",
|
|
26
|
+
"test:run": "run ws:test:run \"$(pwd)\"",
|
|
27
|
+
"test:update": "run ws:test:update \"$(pwd)\"",
|
|
28
|
+
"typecheck": "run ws:ts:typecheck \"$(pwd)\""
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@myparcel-dev/constants": "^2.7.0",
|
|
32
|
+
"@myparcel-dev/delivery-options": "^6.23.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.2.2",
|
|
36
|
+
"vitest": "^2.1.3",
|
|
37
|
+
"vue": "^3.3.0"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20"
|
|
41
|
+
},
|
|
42
|
+
"volta": {
|
|
43
|
+
"extends": "../../package.json"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`exports > exports from index.ts 1`] = `
|
|
4
|
+
[
|
|
5
|
+
"AdminContextKey",
|
|
6
|
+
"BackendEndpoint",
|
|
7
|
+
"FrontendEndpoint",
|
|
8
|
+
"Size",
|
|
9
|
+
"SortType",
|
|
10
|
+
"Status",
|
|
11
|
+
"TriState",
|
|
12
|
+
"Variant",
|
|
13
|
+
]
|
|
14
|
+
`;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export enum Variant {
|
|
2
|
+
Primary = 'primary',
|
|
3
|
+
Secondary = 'secondary',
|
|
4
|
+
Info = 'info',
|
|
5
|
+
Warning = 'warning',
|
|
6
|
+
Error = 'error',
|
|
7
|
+
Success = 'success',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum Size {
|
|
11
|
+
ExtraSmall = 'xs',
|
|
12
|
+
Small = 'sm',
|
|
13
|
+
Medium = 'md',
|
|
14
|
+
Large = 'lg',
|
|
15
|
+
ExtraLarge = 'xl',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum Status {
|
|
19
|
+
Error = 'error',
|
|
20
|
+
Pending = 'pending',
|
|
21
|
+
Success = 'success',
|
|
22
|
+
Warning = 'warning',
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export enum TriState {
|
|
2
|
+
Inherit = -1,
|
|
3
|
+
On = 1,
|
|
4
|
+
Off = 0,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum SortType {
|
|
8
|
+
Ascending = 'asc',
|
|
9
|
+
Descending = 'desc',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum AdminContextKey {
|
|
13
|
+
Global = 'global',
|
|
14
|
+
Dynamic = 'dynamic',
|
|
15
|
+
OrderData = 'orderData',
|
|
16
|
+
PluginSettingsView = 'pluginSettingsView',
|
|
17
|
+
ProductData = 'productData',
|
|
18
|
+
ProductSettingsView = 'productSettingsView',
|
|
19
|
+
|
|
20
|
+
Instance = 'instance',
|
|
21
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoints in global context.
|
|
3
|
+
*
|
|
4
|
+
* @see Plugin.ModelContextGlobalContext.endpoints
|
|
5
|
+
* @see https://github.com/myparcelnl/pdk/blob/main/config/actions.php
|
|
6
|
+
*/
|
|
7
|
+
export enum BackendEndpoint {
|
|
8
|
+
/**
|
|
9
|
+
* Get context.
|
|
10
|
+
*/
|
|
11
|
+
FetchContext = 'fetchContext',
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Delete account.
|
|
15
|
+
*/
|
|
16
|
+
DeleteAccount = 'deleteAccount',
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Update account.
|
|
20
|
+
*/
|
|
21
|
+
UpdateAccount = 'updateAccount',
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get order data from the plugin.
|
|
25
|
+
*/
|
|
26
|
+
FetchOrders = 'fetchOrders',
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Tells the plugin to update the orders by fetching data from MyParcel.
|
|
30
|
+
*/
|
|
31
|
+
UpdateOrders = 'updateOrders',
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Export orders to MyParcel as shipments or orders, depending on the plugin settings.
|
|
35
|
+
*/
|
|
36
|
+
ExportOrders = 'exportOrders',
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Print all shipments belonging to the given orders.
|
|
40
|
+
*/
|
|
41
|
+
PrintOrders = 'printOrders',
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Delete given shipments.
|
|
45
|
+
*/
|
|
46
|
+
DeleteShipments = 'deleteShipments',
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Print given shipments.
|
|
50
|
+
*/
|
|
51
|
+
PrintShipments = 'printShipments',
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Tell the plugin to update given shipments by fetching data from MyParcel.
|
|
55
|
+
*/
|
|
56
|
+
UpdateShipments = 'updateShipments',
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get shipment data from the plugin.
|
|
60
|
+
*/
|
|
61
|
+
FetchShipments = 'fetchShipments',
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create return shipments
|
|
65
|
+
*/
|
|
66
|
+
ExportReturn = 'exportReturn',
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Fetch a product from the plugin.
|
|
70
|
+
*/
|
|
71
|
+
FetchProducts = 'fetchProducts',
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Update plugin settings.
|
|
75
|
+
*/
|
|
76
|
+
UpdatePluginSettings = 'updatePluginSettings',
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Update product settings
|
|
80
|
+
*/
|
|
81
|
+
UpdateProductSettings = 'updateProductSettings',
|
|
82
|
+
|
|
83
|
+
CreateWebhooks = 'createWebhooks',
|
|
84
|
+
DeleteWebhooks = 'deleteWebhooks',
|
|
85
|
+
FetchWebhooks = 'fetchWebhooks',
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Debug actions.
|
|
89
|
+
*/
|
|
90
|
+
DownloadLogs = 'downloadLogs',
|
|
91
|
+
SwitchToAcceptanceApi = 'switchToAcceptanceApi',
|
|
92
|
+
SwitchToProductionApi = 'switchToProductionApi',
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Endpoints in checkout context.
|
|
97
|
+
*
|
|
98
|
+
* @see Plugin.ModelContextCheckoutContext.endpoints
|
|
99
|
+
* @see https://github.com/myparcelnl/pdk/blob/main/config/actions.php
|
|
100
|
+
*/
|
|
101
|
+
export enum FrontendEndpoint {
|
|
102
|
+
/**
|
|
103
|
+
* Get checkout context.
|
|
104
|
+
*/
|
|
105
|
+
FetchCheckoutContext = 'fetchCheckoutContext',
|
|
106
|
+
/**
|
|
107
|
+
* Proxy for listing addresses through the Microservice.
|
|
108
|
+
*/
|
|
109
|
+
ProxyAddressesList = 'proxyAddressList',
|
|
110
|
+
/**
|
|
111
|
+
* Proxy for validating addresses through the Microservice.
|
|
112
|
+
*/
|
|
113
|
+
ProxyAddressValidate = 'proxyAddressValidate',
|
|
114
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {type EndpointDefinition} from '@myparcel-dev/sdk';
|
|
2
|
+
import {type Plugin} from './php-pdk.types';
|
|
3
|
+
|
|
4
|
+
export interface PdkEndpointDefinition extends EndpointDefinition {
|
|
5
|
+
formattedResponse?: unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type ExtractEndpointDefinition<E extends string, D extends PdkEndpointDefinition> = Extract<
|
|
9
|
+
D,
|
|
10
|
+
{
|
|
11
|
+
name: E;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
export type PdkEndpointResponse<E extends string, D extends PdkEndpointDefinition> = ExtractEndpointDefinition<
|
|
16
|
+
E,
|
|
17
|
+
D
|
|
18
|
+
> extends {
|
|
19
|
+
formattedResponse: infer R;
|
|
20
|
+
}
|
|
21
|
+
? R
|
|
22
|
+
: ExtractEndpointDefinition<E, D>['response'];
|
|
23
|
+
|
|
24
|
+
export type PdkEndpointParameters<E extends string, D extends PdkEndpointDefinition> = ExtractEndpointDefinition<
|
|
25
|
+
E,
|
|
26
|
+
D
|
|
27
|
+
>['parameters'];
|
|
28
|
+
|
|
29
|
+
export type EndpointObject<E extends string> = Record<E, Plugin.AbstractEndpointRequest>;
|