Skip to content

Commit

Permalink
Merge pull request #278 from skedify/feat/experimental-ts-definition-…
Browse files Browse the repository at this point in the history
…files

feat(project): experimental TS definition files
  • Loading branch information
DemianD authored Jun 29, 2021
2 parents cca0df1 + cf4630c commit 4d81a88
Show file tree
Hide file tree
Showing 24 changed files with 996 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.snap
*.snap
/**/*.d.ts
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ SDK.appointments('appointment id').then({ data } => {
```

## Custom Domain Map
Some endpoints require a domain mapping when instantiating the SDK. Consider the
Some endpoints require a domain mapping when instantiating the SDK. Consider the
following example:

```js
Expand Down Expand Up @@ -646,3 +646,21 @@ Object {
## Contributing

Use `npm run commit` when you want to commit a change.


## Typescript

There are **experimental** type definition available.
You can include them in your typescript project by adding a `.d.ts` file with the following content:
`/// <reference types="skedify-sdk/types" />`

So for example:

`./src/skedify-sdk.d.ts`:
```ts
/// <reference types="skedify-sdk/types" />
```

Will add typescript definitions for a couple of exposed API's.

Please note that these are **experimental** and will be updated with possible breaking changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"homepage": "https://github.com/skedify/sdk-js",
"files": [
"lib"
"lib",
"types"
],
"scripts": {
"prebuild": "npm run lint && rimraf lib",
Expand Down
11 changes: 11 additions & 0 deletions types/calendarEventTemplates.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module "skedify-sdk" {
export interface CalendarEventTemplate extends Omit<BaseFields, "external_id"> {
locale: Locale;
meeting_type: string;
receiver_type: string;
title: string;
description: string;
updated_at: string;
deleted_at: string;
}
}
9 changes: 9 additions & 0 deletions types/contactOfficeSubjects.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module "skedify-sdk" {
export interface ContactOfficeSubject {
id: string;
contact_office_id: string;
subject_id: string;
created_at: string;
updated_at: string;
}
}
17 changes: 17 additions & 0 deletions types/contactOffices.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
declare module "skedify-sdk" {
export interface ContactOffice {
id: string;
contact_id: string;
office_id: string;
created_at: string | null;
updated_at: string | null;
}

export interface WithContact<T> {
contact: Contact & T;
}

export interface WithOffice {
office: Office;
}
}
112 changes: 112 additions & 0 deletions types/employees.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
declare module "skedify-sdk" {
export interface User {
id: string;
created_at: string;
email: string;
external_id: string | null;
first_name: string | null;
gender: string | null;
last_name: string | null;
language: string | null;
phone_number: string | null;
profile_picture: string | null;
state: State;
timezone: string;
updated_at: string;
}

interface BaseRole {
id: string;
created_at: string;
updated_at: string;
}

interface ContactRole extends BaseRole {
uuid: string;
default_week_template: string | null;
function: string | null;
introduction: string | null;
is_active: boolean;
video_url?: string | null;
timezone: null | string;
}

interface AdminRole extends BaseRole {
is_owner: boolean;
}

interface CentralPlannerRole extends BaseRole {}
interface OfficeManagerRole extends BaseRole {}

/**
* No support for enum in d.ts
* Use StateEnum for mapped enum value
* corresponds with:
* - PENDING = 0,
* - SUSPENDED = 4,
* - ACTIVE = 8,
*/
export type State = 0 | 4 | 8;

export type RoleIdentifier = "central_planner" | "contact" | "admin" | "office_manager";

export interface ContactInfo extends BaseFields {
email: string;
phone_number: string | null;
profile_picture: string | null;
state: State;
updated_at: string;
user_id: string;
}

export interface WithEmployeeUser {
user: User | null;
}

export interface WithEmployeeRoles {
roles: {
central_planner?: CentralPlannerRole;
contact?: ContactRole;
admin?: AdminRole;
office_manager?: OfficeManagerRole;
};
}

export interface Employee extends ContactInfo {}

export interface WithContactEmployee {
roles: {
contact: ContactRole;
};
}

export interface WithOfficeManagerEmployee {
roles: {
office_manager: OfficeManagerRole;
};
}

export interface Admin extends ContactInfo {
roles: {
admin?: AdminRole;
};
}

export interface CentralPlanner extends ContactInfo {
roles: {
admin?: CentralPlannerRole;
};
}

export interface OfficeManager extends ContactInfo {
roles: {
office_manager?: OfficeManagerRole;
};
}

export interface Contact extends ContactInfo {
roles: {
contact?: ContactRole;
};
}
}
12 changes: 12 additions & 0 deletions types/enterprise.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module "skedify-sdk" {
export interface Enterprise {
id: string;
country: string;
default_timezone: string;
name: string;
logo: string;
picture_id: string | number;
created_at: string;
updated_at: string;
}
}
129 changes: 129 additions & 0 deletions types/enterpriseSettings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
declare module "skedify-sdk" {
export type ReminderTypes = "textMessage" | "email";

export type NotificationSettings = Record<ReminderTypes, boolean>;

/**
* No enum support in d.ts files,
* Use NotificationKeysEnum for mapped enum value
* corresponds with:
* - acceptedByContact = 0,
* - assignedByContact= 1,
* - completedByContact = 2,
* - invitedByContact = 3,
* - cancelledByContact = 4,
* - cancelledByCustomer = 5,
* - dateCreatedByContact = 6,
* - dateCreatedByCustomer =7,
* - dateChangedByContact = 8,
* - dateChangedByCustomer = 9,
* - possibilitiesCreatedByCustomer = 10,
* - possibilitiesChangedByCustomer = 11,
* - possibilitiesRequestedByContact = 12,
*/
export type NotificationKeys = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;

export type Notifications = {
[k in NotificationKeys]: NotificationSettings;
};

interface ReminderInterval {
time: number;
}

export type ReminderSettings = Record<ReminderTypes, ReminderInterval[]>;

interface DefaultEnterpriseSettings {
allow_office_365_login: boolean;
allowed_sync_providers: string[];
appointment_block_suggestions: string;
appointment_completion_max_future_days: number;
appointment_contact_select: string;
appointment_max_suggestions: number;
appointment_min_preparation_time: number;
appointment_min_suggestions: number;
availability_max_future_days_to_sync: number;
contact_notifications: Notifications;
default_language: Locale;
enterprise_id: number;
first_time_customer_fields: FirstTimeCustomerFields;
id: string;
internal_customer_fields: unknown;
notifications_window?: unknown;
notifications: Notifications;
reminders: ReminderSettings;
returning_customer_fields: ReturningCustomerFields;
sender_email_addresses?: null | {
[locale: string]: string | undefined | null;
};
show_qr_code_in_customer_email: boolean;
video_provider_test_url: string;
web_app_is_reassign_search_enabled: boolean;
}

export interface EnterpriseCustomerSettings {
appointment_create_allow_change_customer: boolean;
appointment_create_allow_create_customer: boolean;
appointment_create_allow_customer_instigator: boolean;
appointment_create_allow_invite_customer: boolean;
web_app_customers_behaviour: "enabled" | "disabled";
}

export interface EnterpriseSubjectSettings {
appointment_create_allow_set_subject: boolean;
default_subject_id?: string | null;
}

export interface EnterpriseAvailabilitySettings {
appointment_default_duration: number;
appointment_earliest_possible: number;
appointment_latest_possible: number;
time_slot_granularity: number;
}

export interface EnterprisePluginSettings {
redirect_url: string;
localized_redirect_urls: [] | { [lang: string]: string };
terms_conditions_url: string;
}

export type EnterpriseSettings = DefaultEnterpriseSettings &
EnterpriseCustomerSettings &
EnterpriseSubjectSettings &
EnterpriseAvailabilitySettings &
EnterprisePluginSettings;

export interface CustomerFieldSetting {
ask: boolean;
required: boolean;
order: number;
}

export interface FirstTimeCustomerFields {
address: CustomerFieldSetting;
cell_phone_number: CustomerFieldSetting;
company: CustomerFieldSetting;
credit_card_number: CustomerFieldSetting;
customer_number: CustomerFieldSetting;
debit_card_number: CustomerFieldSetting;
dob: CustomerFieldSetting;
/**
* Mandatory
*/
email: CustomerFieldSetting;
home_phone_number: CustomerFieldSetting;
is_existing: CustomerFieldSetting;
/**
* Mandatory
*/
name: CustomerFieldSetting;
title: CustomerFieldSetting;
}

export interface ReturningCustomerFields extends FirstTimeCustomerFields {
/**
* Mandatory
*/
external_customer_id: CustomerFieldSetting;
}
}
5 changes: 5 additions & 0 deletions types/featureFlag.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "skedify-sdk" {
export interface FeatureFlag extends Omit<BaseFields, "enterprise_id"> {
is_enabled: boolean;
}
}
Loading

0 comments on commit 4d81a88

Please sign in to comment.