diff --git a/src/__snapshots__/index.spec.ts.snap b/src/__snapshots__/index.spec.ts.snap index dd8764f..d18eb83 100644 --- a/src/__snapshots__/index.spec.ts.snap +++ b/src/__snapshots__/index.spec.ts.snap @@ -8,14 +8,35 @@ exports[`module exports > exposes the correct data from index.ts 1`] = ` "AbstractPublicEndpoint": [Function], "ApiException": [Function], "BASE_URL": "https://api.myparcel.nl", + "DeleteAccountMessage": [Function], + "DeleteCarrierOptions": [Function], + "DeleteWebhookSubscriptions": [Function], "FetchClient": [Function], + "GetAccount": [Function], + "GetAccountMessages": [Function], + "GetApiKeys": [Function], "GetCarrier": [Function], + "GetCarrierOptions": [Function], "GetCarriers": [Function], "GetDeliveryOptions": [Function], + "GetLocations": [Function], "GetPickupLocations": [Function], "GetShipment": [Function], "GetShipments": [Function], + "GetShop": [Function], + "GetSubscriptions": [Function], + "GetSystemCountryCodes": [Function], + "GetSystemMessages": [Function], + "GetWebhookSubscriptions": [Function], + "PatchSubscriptions": [Function], + "PostApiKeys": [Function], + "PostCarrierOptions": [Function], "PostShipments": [Function], + "PostShop": [Function], + "PostSubscriptions": [Function], + "PostWebhookSubscriptions": [Function], + "PutAccount": [Function], + "PutShop": [Function], "UserException": [Function], "createMyParcelSdk": [Function], "createPrivateSdk": [Function], diff --git a/src/endpoints/endpoints.spec.ts b/src/endpoints/endpoints.spec.ts new file mode 100644 index 0000000..cb01d93 --- /dev/null +++ b/src/endpoints/endpoints.spec.ts @@ -0,0 +1,10 @@ +import {describe, expect, it} from 'vitest'; +import * as Endpoints from '.'; + +describe('Endpoints', () => { + it.each(Object.values(Endpoints))(`%o has required properties`, (Endpoint) => { + const endpoint = new Endpoint(); + expect(endpoint.name).not.toBeUndefined(); + expect(endpoint.path).not.toBeUndefined(); + }); +}); diff --git a/src/endpoints/private/account-messages/AccountMessages.types.ts b/src/endpoints/private/account-messages/AccountMessages.types.ts new file mode 100644 index 0000000..02537c3 --- /dev/null +++ b/src/endpoints/private/account-messages/AccountMessages.types.ts @@ -0,0 +1,7 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +export interface MyParcelAccountMessage { + id: number; + account_id: number; + code: number; + message: string; +} diff --git a/src/endpoints/private/account-messages/DeleteAccountMessage.ts b/src/endpoints/private/account-messages/DeleteAccountMessage.ts new file mode 100644 index 0000000..8ee2fba --- /dev/null +++ b/src/endpoints/private/account-messages/DeleteAccountMessage.ts @@ -0,0 +1,20 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; + +type DeleteAccountMessageDefinition = CreateDefinition<{ + name: typeof DeleteAccountMessage.name; + path: { + id: number; + }; +}>; + +/** + * Deletes one system message by ID. + */ +export class DeleteAccountMessage extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'DELETE'; + public readonly name = 'deleteAccountMessage'; + public readonly path = 'account_messages/:id'; + public readonly property = 'messages'; +} diff --git a/src/endpoints/private/account-messages/GetAccountMessages.ts b/src/endpoints/private/account-messages/GetAccountMessages.ts new file mode 100644 index 0000000..090bbae --- /dev/null +++ b/src/endpoints/private/account-messages/GetAccountMessages.ts @@ -0,0 +1,21 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type MyParcelAccountMessage} from './AccountMessages.types'; + +type GetAccountMessagesDefinition = CreateDefinition<{ + name: typeof GetAccountMessages.name; + parameters: { + // eslint-disable-next-line @typescript-eslint/naming-convention + account_id: number; + }; + response: MyParcelAccountMessage[]; +}>; + +/** + * Retrieve system messages. + */ +export class GetAccountMessages extends AbstractPrivateEndpoint { + public readonly name = 'getAccountMessages'; + public readonly path = 'account_messages'; + public readonly property = 'messages'; +} diff --git a/src/endpoints/private/account-messages/index.ts b/src/endpoints/private/account-messages/index.ts new file mode 100644 index 0000000..60ec1bc --- /dev/null +++ b/src/endpoints/private/account-messages/index.ts @@ -0,0 +1,3 @@ +export * from './AccountMessages.types'; +export * from './DeleteAccountMessage'; +export * from './GetAccountMessages'; diff --git a/src/endpoints/private/accounts/Account.types.ts b/src/endpoints/private/accounts/Account.types.ts new file mode 100644 index 0000000..0d5df30 --- /dev/null +++ b/src/endpoints/private/accounts/Account.types.ts @@ -0,0 +1,50 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import {type Address} from '@/types/common.types'; +import {type MyParcelShop} from '@/endpoints/private/shops/Shop.types'; +import { IntBoolean, Price } from '@/types'; + +export interface AccountAdditionalInfo { + ecommerce_platform: string; + phone: string; + coupon: string; +} + +export interface AccountSettings { + affiliate_bcc: IntBoolean; + affiliate_fee: Price; + is_test: IntBoolean; + order_mode: IntBoolean; + order_feature: boolean; + order_Settings: { + shipment_label: 'apart' | 'nested' | 'none'; + }; + show_cumulio_dashboard: IntBoolean; + has_carrier_contract: IntBoolean; + has_carrier_mail_contract: IntBoolean; + use_mfa: IntBoolean; +} + +export interface MyParcelAccount { + additional_info: AccountAdditionalInfo; + carrier_references: []; + contact_id: number; + contact: Record; + created: string; + delivery_address: null | Address; + email: string; + first_name: string; + gender: string; + general_Settings: AccountSettings; + id: number; + last_name: string; + modified: string; + origin_id: number; + phone: string; + platform_id: number; + shipment_estimates: Record; + shops: MyParcelShop[]; + status: number; + terms_agreed: boolean; + username: string; + users: Record; +} diff --git a/src/endpoints/private/accounts/GetAccount.ts b/src/endpoints/private/accounts/GetAccount.ts new file mode 100644 index 0000000..72572c2 --- /dev/null +++ b/src/endpoints/private/accounts/GetAccount.ts @@ -0,0 +1,20 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type MyParcelAccount} from './Account.types'; + +type GetAccountDefinition = CreateDefinition<{ + name: typeof GetAccount.name; + path: { + id: number; + }; + response: [MyParcelAccount]; +}>; + +/** + * Retrieve a single account object by ID. + */ +export class GetAccount extends AbstractPrivateEndpoint { + public readonly name = 'getAccount'; + public readonly path = 'accounts/:id'; + public readonly property = 'accounts'; +} diff --git a/src/endpoints/private/accounts/PutAccount.ts b/src/endpoints/private/accounts/PutAccount.ts new file mode 100644 index 0000000..96b6b18 --- /dev/null +++ b/src/endpoints/private/accounts/PutAccount.ts @@ -0,0 +1,19 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; +import {type MyParcelAccount} from './Account.types'; + +type PutAccountDefinition = CreateDefinition<{ + name: typeof PutAccount.name; + path: { + id: number; + }; + response: MyParcelAccount[]; +}>; + +export class PutAccount extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'PUT'; + public readonly name = 'putAccount'; + public readonly path = 'accounts'; + public readonly property = 'accounts'; +} diff --git a/src/endpoints/private/accounts/index.ts b/src/endpoints/private/accounts/index.ts new file mode 100644 index 0000000..429a3a9 --- /dev/null +++ b/src/endpoints/private/accounts/index.ts @@ -0,0 +1,3 @@ +export * from './Account.types'; +export * from './GetAccount'; +export * from './PutAccount'; diff --git a/src/endpoints/private/api-key/ApiKey.types.ts b/src/endpoints/private/api-key/ApiKey.types.ts new file mode 100644 index 0000000..c799159 --- /dev/null +++ b/src/endpoints/private/api-key/ApiKey.types.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +export interface MyParcelApiKey { + id: number; + account_id: number; + shop_id: number; + status: number; + username: string; + key: string; +} + +export interface ApiKeyPostData { + account_id: number; + shop_id: number; +} diff --git a/src/endpoints/private/api-key/GetApiKeys.ts b/src/endpoints/private/api-key/GetApiKeys.ts new file mode 100644 index 0000000..f4409cb --- /dev/null +++ b/src/endpoints/private/api-key/GetApiKeys.ts @@ -0,0 +1,17 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type MyParcelApiKey} from './ApiKey.types'; + +type GetApiKeysDefinition = CreateDefinition<{ + name: typeof GetApiKeys.name; + response: MyParcelApiKey[]; +}>; + +/** + * Retrieve all API keys. + */ +export class GetApiKeys extends AbstractPrivateEndpoint { + public readonly name = 'getApiKeys'; + public readonly path = 'keys'; + public readonly property = 'api_keys'; +} diff --git a/src/endpoints/private/api-key/PostApiKeys.ts b/src/endpoints/private/api-key/PostApiKeys.ts new file mode 100644 index 0000000..1d824df --- /dev/null +++ b/src/endpoints/private/api-key/PostApiKeys.ts @@ -0,0 +1,20 @@ +import {type ApiKeyPostData, type MyParcelApiKey} from './ApiKey.types'; +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; + +type PostApiKeyDefinition = CreateDefinition<{ + name: typeof PostApiKeys.name; + body: ApiKeyPostData[]; + response: MyParcelApiKey[]; +}>; + +/** + * Submit a single new key. + */ +export class PostApiKeys extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'POST'; + public readonly name = 'postApiKeys'; + public readonly path = 'keys'; + public readonly property = 'api_keys'; +} diff --git a/src/endpoints/private/api-key/index.ts b/src/endpoints/private/api-key/index.ts new file mode 100644 index 0000000..1049b8d --- /dev/null +++ b/src/endpoints/private/api-key/index.ts @@ -0,0 +1,3 @@ +export * from './ApiKey.types'; +export * from './GetApiKeys'; +export * from './PostApiKeys'; diff --git a/src/endpoints/private/carrier-options/CarrierOption.types.ts b/src/endpoints/private/carrier-options/CarrierOption.types.ts new file mode 100644 index 0000000..4f31139 --- /dev/null +++ b/src/endpoints/private/carrier-options/CarrierOption.types.ts @@ -0,0 +1,39 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import {type CarrierId, type CarrierName} from '@myparcel/constants'; +import {type IntBoolean} from '@/types'; + +export interface MyParcelCarrierOption { + api_key: string; + carrier: { + id: CarrierId; + name: CarrierName; + }; + carrier_id: CarrierId; + enabled: IntBoolean; + id: number; + optional: IntBoolean; + options: { + customerCode: string; + customerNumber: string; + customerCollectionLocation: string; + serviceLevels: number; + barcodeOptions: { + gpType: string; + gpRange: string; + }; + }; + password: string; + primary: IntBoolean; + type: 'main' | 'custom'; + username: string; + subscription_id?: number; + label?: string; +} + +export interface CarrierOptionPostData { + carrier_id: CarrierId; + username?: string; + password?: string; + options?: Record; + api_key?: string; +} diff --git a/src/endpoints/private/carrier-options/DeleteCarrierOptions.ts b/src/endpoints/private/carrier-options/DeleteCarrierOptions.ts new file mode 100644 index 0000000..4eac475 --- /dev/null +++ b/src/endpoints/private/carrier-options/DeleteCarrierOptions.ts @@ -0,0 +1,21 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CarrierId} from '@myparcel/constants'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; + +type DeleteCarrierOptionsDefinition = CreateDefinition<{ + name: typeof DeleteCarrierOptions.name; + path: { + // eslint-disable-next-line @typescript-eslint/naming-convention + carrier_id: CarrierId; + // eslint-disable-next-line @typescript-eslint/naming-convention + account_id: number; + }; +}>; + +export class DeleteCarrierOptions extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'DELETE'; + public readonly name = 'deleteCarrierOption'; + public readonly path = 'accounts/:account_id/carrier_options/:carrier_id'; + public readonly property = 'carrier_options'; +} diff --git a/src/endpoints/private/carrier-options/GetCarrierOptions.ts b/src/endpoints/private/carrier-options/GetCarrierOptions.ts new file mode 100644 index 0000000..28f3e3c --- /dev/null +++ b/src/endpoints/private/carrier-options/GetCarrierOptions.ts @@ -0,0 +1,18 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type MyParcelCarrierOption} from './CarrierOption.types'; + +type GetCarrierOptionsDefinition = CreateDefinition<{ + name: typeof GetCarrierOptions.name; + parameters: { + // eslint-disable-next-line @typescript-eslint/naming-convention + account_id: number; + }; + response: MyParcelCarrierOption[]; +}>; + +export class GetCarrierOptions extends AbstractPrivateEndpoint { + public readonly name = 'getCarrierOptions'; + public readonly path = 'carrier_management/accounts/:account_id/carrier_options'; + public readonly property = 'carrier_options'; +} diff --git a/src/endpoints/private/carrier-options/PostCarrierOptions.ts b/src/endpoints/private/carrier-options/PostCarrierOptions.ts new file mode 100644 index 0000000..fe23c1c --- /dev/null +++ b/src/endpoints/private/carrier-options/PostCarrierOptions.ts @@ -0,0 +1,18 @@ +import {type HttpMethod} from '@/types'; +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CarrierOptionPostData} from './CarrierOption.types'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; + +type PostCarrierOptionsDefinition = CreateDefinition<{ + name: typeof PostCarrierOptions.name; + body: CarrierOptionPostData[]; + response: {id: number}[]; +}>; + +export class PostCarrierOptions extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'POST'; + public readonly name = 'postCarrierOptions'; + public readonly path = 'accounts/:account_id/carrier_options'; + public readonly property = 'carrier_options'; + public readonly responseProperty = 'ids'; +} diff --git a/src/endpoints/private/carrier-options/index.ts b/src/endpoints/private/carrier-options/index.ts new file mode 100644 index 0000000..eca6de0 --- /dev/null +++ b/src/endpoints/private/carrier-options/index.ts @@ -0,0 +1,4 @@ +export * from './CarrierOption.types'; +export * from './DeleteCarrierOptions'; +export * from './GetCarrierOptions'; +export * from './PostCarrierOptions'; diff --git a/src/endpoints/private/index.ts b/src/endpoints/private/index.ts index 73a51ff..b06da13 100644 --- a/src/endpoints/private/index.ts +++ b/src/endpoints/private/index.ts @@ -1 +1,11 @@ +export * from './account-messages'; +export * from './accounts'; +export * from './api-key'; +export * from './carrier-options'; +export * from './locations'; export * from './shipments'; +export * from './shops'; +export * from './subscriptions'; +export * from './system-country-codes'; +export * from './system-messages'; +export * from './webhook-subscriptions'; diff --git a/src/endpoints/private/locations/GetLocations.ts b/src/endpoints/private/locations/GetLocations.ts new file mode 100644 index 0000000..0d58d23 --- /dev/null +++ b/src/endpoints/private/locations/GetLocations.ts @@ -0,0 +1,15 @@ +import {type LocationParameters, type MyParcelLocation} from './Location.types'; +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; + +type GetLocationsDefinition = CreateDefinition<{ + name: typeof GetLocations.name; + parameters: LocationParameters; + response: MyParcelLocation[]; +}>; + +export class GetLocations extends AbstractPrivateEndpoint { + public readonly name = 'getLocations'; + public readonly path = 'locations'; + public readonly property = 'locations'; +} diff --git a/src/endpoints/private/locations/Location.types.ts b/src/endpoints/private/locations/Location.types.ts new file mode 100644 index 0000000..2b71431 --- /dev/null +++ b/src/endpoints/private/locations/Location.types.ts @@ -0,0 +1,11 @@ +export type LocationParameters = { + cc: string; + // eslint-disable-next-line @typescript-eslint/naming-convention + postal_code: string; + number: string; +}; + +export interface MyParcelLocation { + street: string; + city: string; +} diff --git a/src/endpoints/private/locations/index.ts b/src/endpoints/private/locations/index.ts new file mode 100644 index 0000000..f52ce78 --- /dev/null +++ b/src/endpoints/private/locations/index.ts @@ -0,0 +1,2 @@ +export * from './GetLocations'; +export * from './Location.types'; diff --git a/src/endpoints/private/shipments/PatchShipment.ts b/src/endpoints/private/shipments/PatchShipment.ts new file mode 100644 index 0000000..2ac898f --- /dev/null +++ b/src/endpoints/private/shipments/PatchShipment.ts @@ -0,0 +1,28 @@ +import {type HttpMethod, type RequestHeaders} from '@/types/request.types'; +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type ShipmentPatchData} from '@/endpoints/private/shipments/Shipment.types'; + +type PatchShipmentsDefinition = CreateDefinition<{ + name: typeof PatchShipments.name; + body: ShipmentPatchData[]; +}>; + +/** + * Patch an existing shipment. + * + * @see https://developer.myparcel.nl/api-reference/06.shipments.html + */ +export class PatchShipments extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'PATCH'; + public readonly name = 'patchShipments'; + public readonly path = 'shipments'; + public readonly property = 'shipments'; + + public getHeaders(): RequestHeaders { + return { + ...super.getHeaders(), + 'Content-Type': 'application/vnd.shipment+json;charset=utf-8;version=1.1', + }; + } +} diff --git a/src/endpoints/private/shipments/PostShipments.ts b/src/endpoints/private/shipments/PostShipments.ts index 64e3c29..4cc3512 100644 --- a/src/endpoints/private/shipments/PostShipments.ts +++ b/src/endpoints/private/shipments/PostShipments.ts @@ -12,7 +12,7 @@ type PostShipmentsDefinition = CreateDefinition<{ /** * Create a shipment. * - * @see https://myparcelnl.github.io/api/#6_B + * @see https://developer.myparcel.nl/api-reference/06.shipments.html */ export class PostShipments extends AbstractPrivateEndpoint { public readonly method: HttpMethod = 'POST'; diff --git a/src/endpoints/private/shipments/Shipment.types.ts b/src/endpoints/private/shipments/Shipment.types.ts index 842ce18..bf1ac41 100644 --- a/src/endpoints/private/shipments/Shipment.types.ts +++ b/src/endpoints/private/shipments/Shipment.types.ts @@ -183,3 +183,10 @@ export interface MyParcelShipment { transaction_status: string; user_agent: string | null; } + +export interface ShipmentPatchData { + id: number; + hidden?: IntBoolean; + status?: ShipmentStatus; + delivered?: IntBoolean; +} diff --git a/src/endpoints/private/shops/GetShop.ts b/src/endpoints/private/shops/GetShop.ts new file mode 100644 index 0000000..c29cff8 --- /dev/null +++ b/src/endpoints/private/shops/GetShop.ts @@ -0,0 +1,20 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type MyParcelShop} from './Shop.types'; + +type GetShopDefinition = CreateDefinition<{ + name: typeof GetShop.name; + path: { + id: number; + }; + response: MyParcelShop[]; +}>; + +/** + * Retrieve a single shop by ID. + */ +export class GetShop extends AbstractPrivateEndpoint { + public readonly name = 'getShop'; + public readonly path = 'shops/:id'; + public readonly property = 'shops'; +} diff --git a/src/endpoints/private/shops/PostShop.ts b/src/endpoints/private/shops/PostShop.ts new file mode 100644 index 0000000..219314a --- /dev/null +++ b/src/endpoints/private/shops/PostShop.ts @@ -0,0 +1,21 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types/request.types'; +import {type MyParcelShop} from './Shop.types'; + +type PostShopDefinition = CreateDefinition<{ + name: typeof PostShop.name; + body: MyParcelShop[]; + response: {id: number}[]; +}>; + +/** + * Create a shop. + */ +export class PostShop extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'POST'; + public readonly name = 'postShop'; + public readonly path = 'shops/duplicate'; + public readonly property = 'shops'; + public readonly responseProperty = 'ids'; +} diff --git a/src/endpoints/private/shops/PutShop.ts b/src/endpoints/private/shops/PutShop.ts new file mode 100644 index 0000000..9911275 --- /dev/null +++ b/src/endpoints/private/shops/PutShop.ts @@ -0,0 +1,17 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types/request.types'; +import {type MyParcelShop} from './Shop.types'; + +type PutShopDefinition = CreateDefinition<{ + name: typeof PutShop.name; + body: MyParcelShop[]; + response: MyParcelShop[]; +}>; + +export class PutShop extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'PUT'; + public readonly name = 'putShop'; + public readonly path = 'shops'; + public readonly property = 'shops'; +} diff --git a/src/endpoints/private/shops/Shop.types.ts b/src/endpoints/private/shops/Shop.types.ts new file mode 100644 index 0000000..2fb1e93 --- /dev/null +++ b/src/endpoints/private/shops/Shop.types.ts @@ -0,0 +1,85 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import {type Address, type IntBoolean} from '@/types'; + +export interface ShopBranding { + accent_color: string; + enable_returns: boolean; + enable_track_trace: boolean; + subdomain: string; + use_consumer_portal: boolean; +} + +export interface ShopBilling { + address: Address; + billing_method: 1 | 2 | 3 | 4; + coc?: string; + cycle: 'monthly' | 'weekly'; + eori_number?: string; + iban?: string; + reference: string; + vat_number_uk?: string; + vat_number?: string; +} + +export interface ReturnReason { + human: string; + name: string; +} + +export interface ShopReturnReasons { + enabled: boolean; + mandatory: boolean; + return_reasons: ReturnReason[]; +} + +export interface ShopReturn { + address: Address; + bcc: IntBoolean; + email_address_for_tracktrace_return_shipments: string; + from_address_name?: string; + link_expires_after?: number; + send_tracktrace_email_for_return_shipments: IntBoolean; + settle_printerless_return_cost: IntBoolean; + use_custom_description: IntBoolean; + use_printerless_return: IntBoolean; + use_shop_shipment_options: IntBoolean; +} + +export interface ShopSettings { + auto_save_addresses: IntBoolean; + default_collect_address_id?: number; + label_description: string; + label_format_locked: IntBoolean; + label_format: 'A4' | 'A6'; + preferred_locale?: string; + reminder_email: IntBoolean; + use_logo_label: IntBoolean; + weight: number; +} + +export interface ShopTrackTrace { + bcc_email: string; + bcc: IntBoolean; + carrier_email_basic_notification: IntBoolean; + delivery_notification: IntBoolean; + email_on_handed_to_courier: IntBoolean; + from_address_company: string; + from_address_email: string; + send_track_trace_emails: IntBoolean; +} + +export interface MyParcelShop { + account_id: number; + billing: ShopBilling; + branding: ShopBranding; + created: string; + general_settings: ShopSettings; + hidden: boolean; + id: number; + modified: string; + name: string; + platform_id: number; + return_reason_settings: ShopReturnReasons; + return: ShopReturn; + tracktrace: ShopTrackTrace; +} diff --git a/src/endpoints/private/shops/index.ts b/src/endpoints/private/shops/index.ts new file mode 100644 index 0000000..29b6c75 --- /dev/null +++ b/src/endpoints/private/shops/index.ts @@ -0,0 +1,4 @@ +export * from './GetShop'; +export * from './PostShop'; +export * from './PutShop'; +export * from './Shop.types'; diff --git a/src/endpoints/private/subscription-capabilities/GetSubscriptionCapabilities.ts b/src/endpoints/private/subscription-capabilities/GetSubscriptionCapabilities.ts new file mode 100644 index 0000000..df61455 --- /dev/null +++ b/src/endpoints/private/subscription-capabilities/GetSubscriptionCapabilities.ts @@ -0,0 +1,18 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type SubscriptionType} from '@/endpoints/private/subscriptions/Subscriptions.types'; +import {type SubscriptionCapability} from './SubscriptionCapability.types'; + +type GetSubscriptionsCapabilitiesDefinition = CreateDefinition<{ + name: typeof GetSubscriptionsCapabilities.name; + parameters: { + id: number; + }; + response: Record; +}>; + +export class GetSubscriptionsCapabilities extends AbstractPrivateEndpoint { + public readonly name = 'getSubscriptionsCapabilities'; + public readonly path = 'subscriptions/capabilities'; + public readonly property = 'capabilities'; +} diff --git a/src/endpoints/private/subscription-capabilities/SubscriptionCapability.types.ts b/src/endpoints/private/subscription-capabilities/SubscriptionCapability.types.ts new file mode 100644 index 0000000..bf78997 --- /dev/null +++ b/src/endpoints/private/subscription-capabilities/SubscriptionCapability.types.ts @@ -0,0 +1,57 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { + type SubscriptionProductId, + type SubscriptionTier, + type SubscriptionTierName, + type SubscriptionType, +} from '@/endpoints/private/subscriptions/Subscriptions.types'; +import {type Price} from '@/types'; + +export type DashboardSlug = + | 'shipments' + | 'returns' + | 'webshops' + | 'shipments-weekly' + | 'returns-weekly' + | 'webshops-weekly' + | 'transit-time' + | 'surcharges' + | 'cases' + | 'shipments-t2' + | 'returns-t2' + | 'webshops-t2' + | 'transit-time-t2' + | 'surcharges-t2' + | 'cases-t2' + | 'finance-t2' + | 'shortcoming-t2' + | 'shipments-t3' + | 'returns-t3' + | 'webshops-t3' + | 'transit-time-t3' + | 'surcharges-t3' + | 'cases-t3' + | 'finance-t3' + | 'shortcoming-t3'; + +export interface SubscriptionConfiguration { + dashboard_slugs: string[]; + free_shipments_per_month: number; + max_shipping_rules: number | null; + shipment_discount_price: Price; + shipment_discount_product: number; + shipment_fee_price: Price; + shipment_fee_product: number; +} + +export interface SubscriptionCapability { + configuration: SubscriptionConfiguration; + features: string[]; + price: Price; + tier: SubscriptionTier; + product_id: SubscriptionProductId; + product_name: string; + subscription_type_name: string; + tier_name: SubscriptionTierName; + type: SubscriptionType; +} diff --git a/src/endpoints/private/subscriptions/GetSubscriptions.ts b/src/endpoints/private/subscriptions/GetSubscriptions.ts new file mode 100644 index 0000000..2303532 --- /dev/null +++ b/src/endpoints/private/subscriptions/GetSubscriptions.ts @@ -0,0 +1,18 @@ +import {type MyParcelSubscription, type SubscriptionPostData} from './Subscriptions.types'; +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; + +type GetSubscriptionsDefinition = CreateDefinition<{ + name: typeof GetSubscriptions.name; + parameters: { + id: number; + }; + body: SubscriptionPostData[]; + response: MyParcelSubscription[]; +}>; + +export class GetSubscriptions extends AbstractPrivateEndpoint { + public readonly name = 'getSubscriptions'; + public readonly path = 'subscriptions'; + public readonly property = 'subscriptions'; +} diff --git a/src/endpoints/private/subscriptions/PatchSubscriptions.ts b/src/endpoints/private/subscriptions/PatchSubscriptions.ts new file mode 100644 index 0000000..bf19761 --- /dev/null +++ b/src/endpoints/private/subscriptions/PatchSubscriptions.ts @@ -0,0 +1,20 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; +import {type SubscriptionPatchData} from './Subscriptions.types'; + +type PatchSubscriptionsDefinition = CreateDefinition<{ + name: typeof PatchSubscriptions.name; + body: SubscriptionPatchData[]; + response: { + id: number; + }[]; +}>; + +export class PatchSubscriptions extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'PATCH'; + public readonly name = 'patchSubscriptions'; + public readonly path = 'subscriptions'; + public readonly property = 'subscriptions'; + public readonly responseProperty = 'ids'; +} diff --git a/src/endpoints/private/subscriptions/PostSubscriptions.ts b/src/endpoints/private/subscriptions/PostSubscriptions.ts new file mode 100644 index 0000000..b293f1d --- /dev/null +++ b/src/endpoints/private/subscriptions/PostSubscriptions.ts @@ -0,0 +1,20 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; +import {SubscriptionPostData} from './Subscriptions.types'; + +type PostSubscriptionsDefinition = CreateDefinition<{ + name: typeof PostSubscriptions.name; + body: SubscriptionPostData[]; + response: { + id: number; + }[]; +}>; + +export class PostSubscriptions extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'POST'; + public readonly name = 'postSubscriptions'; + public readonly path = 'subscriptions'; + public readonly property = 'subscriptions'; + public readonly responseProperty = 'ids'; +} diff --git a/src/endpoints/private/subscriptions/Subscriptions.types.ts b/src/endpoints/private/subscriptions/Subscriptions.types.ts new file mode 100644 index 0000000..592c98d --- /dev/null +++ b/src/endpoints/private/subscriptions/Subscriptions.types.ts @@ -0,0 +1,62 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +export type SubscriptionProductId = + | 4610 + | 4611 + | 4612 + | 4613 + | 4614 + | 4615 + | 4616 + | 4617 + | 4618 + | 4700 + | 4701 + | 4702 + | 4703 + | 4800 + | 4801 + | 4802 + | 4803; + +export type SubscriptionTier = 0 | 1 | 2 | 3 | 4 | 5; + +export type SubscriptionTierName = 'light' | 'start' | 'plus' | 'premium' | 'max'; + +export type SubscriptionType = 'my_contracts' | 'my_analytics' | 'my_orders' | 'bundle'; + +export type SubscriptionStatus = + | 'active' + | 'ended' + | 'pending' + | 'starting_soon' + | 'ending_soon' + | 'trial_active' + | 'trial_ended'; + +export type MyParcelSubscription = { + account_id: number; + billing_period_end: string; + billing_shop_id: number; + end: string | null; + id: number; + product_id: SubscriptionProductId; + start: string; + status: SubscriptionStatus; + tier: SubscriptionTier; + trial_end: string | null; + type: SubscriptionType; +}; + +export interface SubscriptionPostData { + account_id: number; + start: string; + billing_shop_id: number; + product_id: SubscriptionProductId; +} + +export interface SubscriptionPatchData { + id: number; + billing_shop_id?: number; + trial_end?: string; + end?: string; +} diff --git a/src/endpoints/private/subscriptions/index.ts b/src/endpoints/private/subscriptions/index.ts new file mode 100644 index 0000000..b35d9cd --- /dev/null +++ b/src/endpoints/private/subscriptions/index.ts @@ -0,0 +1,4 @@ +export * from './GetSubscriptions'; +export * from './PatchSubscriptions'; +export * from './PostSubscriptions'; +export * from './Subscriptions.types'; diff --git a/src/endpoints/private/system-country-codes/GetSystemCountryCodes.ts b/src/endpoints/private/system-country-codes/GetSystemCountryCodes.ts new file mode 100644 index 0000000..6a69cd8 --- /dev/null +++ b/src/endpoints/private/system-country-codes/GetSystemCountryCodes.ts @@ -0,0 +1,18 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CarrierId} from '@myparcel/constants'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type SystemCountryCodesPerCountry} from './SystemCountryCodes.types'; + +type GetSystemCountryCodesDefinition = CreateDefinition<{ + name: typeof GetSystemCountryCodes.name; + parameters: { + carrier_id?: CarrierId; + }; + response: SystemCountryCodesPerCountry; +}>; + +export class GetSystemCountryCodes extends AbstractPrivateEndpoint { + public readonly name = 'getSystemCountryCodes'; + public readonly path = 'system_country_codes'; + public readonly property = 'countries'; +} diff --git a/src/endpoints/private/system-country-codes/SystemCountryCodes.types.ts b/src/endpoints/private/system-country-codes/SystemCountryCodes.types.ts new file mode 100644 index 0000000..57b28ae --- /dev/null +++ b/src/endpoints/private/system-country-codes/SystemCountryCodes.types.ts @@ -0,0 +1,6 @@ +export interface SystemCountryCode { + label: string; + region: string; +} + +export type SystemCountryCodesPerCountry = Record[]; diff --git a/src/endpoints/private/system-country-codes/index.ts b/src/endpoints/private/system-country-codes/index.ts new file mode 100644 index 0000000..2254e72 --- /dev/null +++ b/src/endpoints/private/system-country-codes/index.ts @@ -0,0 +1,2 @@ +export * from './GetSystemCountryCodes'; +export * from './SystemCountryCodes.types'; diff --git a/src/endpoints/private/system-messages/GetSystemMessages.ts b/src/endpoints/private/system-messages/GetSystemMessages.ts new file mode 100644 index 0000000..bf99be3 --- /dev/null +++ b/src/endpoints/private/system-messages/GetSystemMessages.ts @@ -0,0 +1,17 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type MyParcelSystemMessage} from './SystemMessage.types'; + +type GetSystemMessagesDefinition = CreateDefinition<{ + name: typeof GetSystemMessages.name; + response: MyParcelSystemMessage[]; +}>; + +/** + * Retrieve system messages. + */ +export class GetSystemMessages extends AbstractPrivateEndpoint { + public readonly name = 'getSystemMessages'; + public readonly path = 'system_messages'; + public readonly property = 'messages'; +} diff --git a/src/endpoints/private/system-messages/SystemMessage.types.ts b/src/endpoints/private/system-messages/SystemMessage.types.ts new file mode 100644 index 0000000..1b6f98b --- /dev/null +++ b/src/endpoints/private/system-messages/SystemMessage.types.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +export interface MyParcelSystemMessage { + id: number; + content: string; + active: boolean; + additional_filter: string; + message_type: 1 | 2 | 3 | 4 | 5; + create: Date; + modified: Date; + start_date: Date; + end_date: Date; + notification_type: 'alert' | 'warning' | 'success' | 'info' | 'info'; + content_nl: string; + content_en: string; + content_fr: string; + platform_ids: number[]; + platform_id: number; + system_message_id: number; +} diff --git a/src/endpoints/private/system-messages/index.ts b/src/endpoints/private/system-messages/index.ts new file mode 100644 index 0000000..8063d85 --- /dev/null +++ b/src/endpoints/private/system-messages/index.ts @@ -0,0 +1,2 @@ +export * from './GetSystemMessages'; +export * from './SystemMessage.types'; diff --git a/src/endpoints/private/track-traces/GetTrackAndTraceByShipment.ts b/src/endpoints/private/track-traces/GetTrackAndTraceByShipment.ts new file mode 100644 index 0000000..bcc125c --- /dev/null +++ b/src/endpoints/private/track-traces/GetTrackAndTraceByShipment.ts @@ -0,0 +1,18 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type TrackAndTrace} from './TrackTraces.types'; + +type GetTrackAndTraceDefinition = CreateDefinition<{ + name: typeof GetTrackAndTrace.name; + response: TrackAndTrace[]; + path: { + // eslint-disable-next-line @typescript-eslint/naming-convention + shipment_id: string; + }; +}>; + +export class GetTrackAndTrace extends AbstractPrivateEndpoint { + public readonly name = 'getTrackAndTrace'; + public readonly path = 'tracktraces/:shipment_id'; + public readonly property = 'tracktraces'; +} diff --git a/src/endpoints/private/track-traces/TrackTraces.types.ts b/src/endpoints/private/track-traces/TrackTraces.types.ts new file mode 100644 index 0000000..a88f1a4 --- /dev/null +++ b/src/endpoints/private/track-traces/TrackTraces.types.ts @@ -0,0 +1,58 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import {type Address, type AddressWithContactDetails} from '@/types'; +import {type CarrierId} from '@myparcel/constants'; +import {type PickupLocation} from '@/endpoints/public'; +import {type ShipmentOptions} from '../shipments'; + +export interface PartnerTrackTraceLink { + barcode: string; + uri: string; +} + +export type ShipmentStatus = 'registered' | 'handed_to_carrier' | 'sorting' | 'distribution' | 'delivered'; + +export interface TrackAndTraceStatus { + main: ShipmentStatus; + final: boolean; + current: number; +} + +export interface TrackAndTraceLocation { + name: string; + countryCode: string; + city: string; + postalCode: string; + street: string; + number: string; + numberSuffix: string; + longitude: number; + latitude: number; +} + +export interface TrackTraceHistory { + code: string; + description: string; + time: string; + delayed: boolean; + location: TrackAndTraceLocation; +} + +export interface TrackAndTrace { + shipment_id: number; + carrier_id: CarrierId; + // Equal to PostNLStatusCodes status codes in core-api + code: string; + description: string; + time: string; + link_consumer_portal: string; + link_tracktrace: string; + partner_tracktraces: PartnerTrackTraceLink[]; + recipient: AddressWithContactDetails; + sender: Address; + options: ShipmentOptions; + pickup: PickupLocation | null; + delayed: boolean; + location: TrackAndTraceLocation | null; + status: TrackAndTraceStatus; + history: TrackTraceHistory[]; +} diff --git a/src/endpoints/private/track-traces/index.ts b/src/endpoints/private/track-traces/index.ts new file mode 100644 index 0000000..b2acfa3 --- /dev/null +++ b/src/endpoints/private/track-traces/index.ts @@ -0,0 +1,2 @@ +export * from './GetTrackAndTraceByShipment'; +export * from './TrackTraces.types'; diff --git a/src/endpoints/private/webhook-subscriptions/DeleteWebhookSubscriptions.ts b/src/endpoints/private/webhook-subscriptions/DeleteWebhookSubscriptions.ts new file mode 100644 index 0000000..6be01c5 --- /dev/null +++ b/src/endpoints/private/webhook-subscriptions/DeleteWebhookSubscriptions.ts @@ -0,0 +1,17 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; + +type DeleteWebhookSubscriptionsDefinition = CreateDefinition<{ + name: typeof DeleteWebhookSubscriptions.name; + path: { + ids: string; + }; +}>; + +export class DeleteWebhookSubscriptions extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'DELETE'; + public readonly name = 'deleteWebhookSubscriptions'; + public readonly path = 'webhook_subscriptions/:ids'; + public readonly property = 'webhook_subscriptions'; +} diff --git a/src/endpoints/private/webhook-subscriptions/GetWebhookSubscriptions.ts b/src/endpoints/private/webhook-subscriptions/GetWebhookSubscriptions.ts new file mode 100644 index 0000000..c8b9553 --- /dev/null +++ b/src/endpoints/private/webhook-subscriptions/GetWebhookSubscriptions.ts @@ -0,0 +1,15 @@ +import {type MyParcelWebhook, type WebhookSubscriptionParameters} from './Webhook.types'; +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; + +type GetWebhookSubscriptionsDefinition = CreateDefinition<{ + name: typeof GetWebhookSubscriptions.name; + parameters: WebhookSubscriptionParameters; + response: MyParcelWebhook[]; +}>; + +export class GetWebhookSubscriptions extends AbstractPrivateEndpoint { + public readonly name = 'getWebhookSubscriptions'; + public readonly path = 'webhook_subscriptions'; + public readonly property = 'webhook_subscriptions'; +} diff --git a/src/endpoints/private/webhook-subscriptions/PostWebhookSubscriptions.ts b/src/endpoints/private/webhook-subscriptions/PostWebhookSubscriptions.ts new file mode 100644 index 0000000..3f3a7db --- /dev/null +++ b/src/endpoints/private/webhook-subscriptions/PostWebhookSubscriptions.ts @@ -0,0 +1,20 @@ +import {AbstractPrivateEndpoint} from '@/model/endpoint/AbstractPrivateEndpoint'; +import {type CreateDefinition} from '@/model/endpoint/AbstractEndpoint.types'; +import {type HttpMethod} from '@/types'; +import {type MyParcelWebhook} from './Webhook.types'; + +type PostWebhookSubscriptionsDefinition = CreateDefinition<{ + name: typeof PostWebhookSubscriptions.name; + body: MyParcelWebhook[]; + response: { + id: number[]; + }; +}>; + +export class PostWebhookSubscriptions extends AbstractPrivateEndpoint { + public readonly method: HttpMethod = 'POST'; + public readonly name = 'postWebhookSubscriptions'; + public readonly path = 'webhook_subscriptions'; + public readonly property = 'webhook_subscriptions'; + public readonly responseProperty = 'ids'; +} diff --git a/src/endpoints/private/webhook-subscriptions/Webhook.types.ts b/src/endpoints/private/webhook-subscriptions/Webhook.types.ts new file mode 100644 index 0000000..ac461bd --- /dev/null +++ b/src/endpoints/private/webhook-subscriptions/Webhook.types.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +export type WebhookSubscriptionParameters = { + account_id?: number; + shop_id?: number; + hook?: string; + ids?: string; +}; + +export interface MyParcelWebhook { + account_id: number; + hook: 'shipment_label_created' | 'shipment_status_change'; + id: number; + shop_id: number; + url: string; +} diff --git a/src/endpoints/private/webhook-subscriptions/index.ts b/src/endpoints/private/webhook-subscriptions/index.ts new file mode 100644 index 0000000..26f6404 --- /dev/null +++ b/src/endpoints/private/webhook-subscriptions/index.ts @@ -0,0 +1,4 @@ +export * from './DeleteWebhookSubscriptions'; +export * from './GetWebhookSubscriptions'; +export * from './PostWebhookSubscriptions'; +export * from './Webhook.types';