Skip to content

Commit

Permalink
feat: add private endpoints (#144)
Browse files Browse the repository at this point in the history
Add endpoints:
- account messages
- accounts
- api-key
- carrier-options
- locations
- shipments
- shops
- subscriptiopn-capabilities
- subscriptions
- system-country-codes
- track traces
- webhook subscriptions
  • Loading branch information
Cysword authored Dec 18, 2023
1 parent 5b6e274 commit aed019f
Show file tree
Hide file tree
Showing 52 changed files with 961 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
10 changes: 10 additions & 0 deletions src/endpoints/endpoints.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
export interface MyParcelAccountMessage {
id: number;
account_id: number;
code: number;
message: string;
}
20 changes: 20 additions & 0 deletions src/endpoints/private/account-messages/DeleteAccountMessage.ts
Original file line number Diff line number Diff line change
@@ -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<DeleteAccountMessageDefinition> {
public readonly method: HttpMethod = 'DELETE';
public readonly name = 'deleteAccountMessage';
public readonly path = 'account_messages/:id';
public readonly property = 'messages';
}
21 changes: 21 additions & 0 deletions src/endpoints/private/account-messages/GetAccountMessages.ts
Original file line number Diff line number Diff line change
@@ -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<GetAccountMessagesDefinition> {
public readonly name = 'getAccountMessages';
public readonly path = 'account_messages';
public readonly property = 'messages';
}
3 changes: 3 additions & 0 deletions src/endpoints/private/account-messages/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './AccountMessages.types';
export * from './DeleteAccountMessage';
export * from './GetAccountMessages';
50 changes: 50 additions & 0 deletions src/endpoints/private/accounts/Account.types.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>;
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<string, unknown>;
shops: MyParcelShop[];
status: number;
terms_agreed: boolean;
username: string;
users: Record<string, unknown>;
}
20 changes: 20 additions & 0 deletions src/endpoints/private/accounts/GetAccount.ts
Original file line number Diff line number Diff line change
@@ -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<GetAccountDefinition> {
public readonly name = 'getAccount';
public readonly path = 'accounts/:id';
public readonly property = 'accounts';
}
19 changes: 19 additions & 0 deletions src/endpoints/private/accounts/PutAccount.ts
Original file line number Diff line number Diff line change
@@ -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<PutAccountDefinition> {
public readonly method: HttpMethod = 'PUT';
public readonly name = 'putAccount';
public readonly path = 'accounts';
public readonly property = 'accounts';
}
3 changes: 3 additions & 0 deletions src/endpoints/private/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './Account.types';
export * from './GetAccount';
export * from './PutAccount';
14 changes: 14 additions & 0 deletions src/endpoints/private/api-key/ApiKey.types.ts
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 17 additions & 0 deletions src/endpoints/private/api-key/GetApiKeys.ts
Original file line number Diff line number Diff line change
@@ -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<GetApiKeysDefinition> {
public readonly name = 'getApiKeys';
public readonly path = 'keys';
public readonly property = 'api_keys';
}
20 changes: 20 additions & 0 deletions src/endpoints/private/api-key/PostApiKeys.ts
Original file line number Diff line number Diff line change
@@ -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<PostApiKeyDefinition> {
public readonly method: HttpMethod = 'POST';
public readonly name = 'postApiKeys';
public readonly path = 'keys';
public readonly property = 'api_keys';
}
3 changes: 3 additions & 0 deletions src/endpoints/private/api-key/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './ApiKey.types';
export * from './GetApiKeys';
export * from './PostApiKeys';
39 changes: 39 additions & 0 deletions src/endpoints/private/carrier-options/CarrierOption.types.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>;
api_key?: string;
}
21 changes: 21 additions & 0 deletions src/endpoints/private/carrier-options/DeleteCarrierOptions.ts
Original file line number Diff line number Diff line change
@@ -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<DeleteCarrierOptionsDefinition> {
public readonly method: HttpMethod = 'DELETE';
public readonly name = 'deleteCarrierOption';
public readonly path = 'accounts/:account_id/carrier_options/:carrier_id';
public readonly property = 'carrier_options';
}
18 changes: 18 additions & 0 deletions src/endpoints/private/carrier-options/GetCarrierOptions.ts
Original file line number Diff line number Diff line change
@@ -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<GetCarrierOptionsDefinition> {
public readonly name = 'getCarrierOptions';
public readonly path = 'carrier_management/accounts/:account_id/carrier_options';
public readonly property = 'carrier_options';
}
18 changes: 18 additions & 0 deletions src/endpoints/private/carrier-options/PostCarrierOptions.ts
Original file line number Diff line number Diff line change
@@ -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<PostCarrierOptionsDefinition> {
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';
}
4 changes: 4 additions & 0 deletions src/endpoints/private/carrier-options/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './CarrierOption.types';
export * from './DeleteCarrierOptions';
export * from './GetCarrierOptions';
export * from './PostCarrierOptions';
10 changes: 10 additions & 0 deletions src/endpoints/private/index.ts
Original file line number Diff line number Diff line change
@@ -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';
15 changes: 15 additions & 0 deletions src/endpoints/private/locations/GetLocations.ts
Original file line number Diff line number Diff line change
@@ -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<GetLocationsDefinition> {
public readonly name = 'getLocations';
public readonly path = 'locations';
public readonly property = 'locations';
}
Loading

0 comments on commit aed019f

Please sign in to comment.