Skip to content

Commit

Permalink
feat: Continue reorganizting and renaming Favro API data types into n…
Browse files Browse the repository at this point in the history
…amespaced structures.
  • Loading branch information
adam-coster committed Aug 29, 2021
1 parent a08beb5 commit e28bad5
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/triple-slash-reference": "off",
"camelcase": "off",
"no-array-constructor": "off",
"no-constant-condition": "off",
Expand Down
10 changes: 1 addition & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
export * from './lib/BravoClient.js';
export * from './types/FavroApiTypes.js';
// TODO: Figure out how to choose which types to export
// export * from './types/FavroCardTypes.js';
// export * from './types/FavroCardUpdateTypes.js';
// export * from './types/FavroColumnTypes.js';
// export * from './types/FavroCustomFieldTypes.js';
// export * from './types/FavroTagTypes.js';
// export * from './types/FavroWidgetTypes.js';
// export * from './types/ParameterOptions.js';
export * from './types/FavroApi.js';
24 changes: 6 additions & 18 deletions src/lib/BravoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { BravoUser } from '$/lib/entities/BravoUser';
import { BravoOrganization } from '$entities/BravoOrganization';
import { BravoWidget } from '$entities/BravoWidget.js';
import type { DataFavroWidget } from '$/types/FavroWidgetTypes.js';
import type { FavroApi } from '$/types/FavroApiTypes';
import type { FavroApi } from '$favro';
import type { OptionsBravoCreateWidget } from '$/types/ParameterOptions.js';
import { BravoColumn } from './entities/BravoColumn.js';
import type { DataFavroColumn } from '$/types/FavroColumnTypes.js';
Expand All @@ -36,7 +36,6 @@ import type { FavroResponse } from './clientLib/FavroResponse.js';
import { readFileSync } from 'fs';
import { basename } from 'path';
import { BravoTagDefinition } from './entities/BravoTag.js';
import type { FavroApiData } from '$/types/FavroTagTypes.js';
import type { BravoEntity } from './BravoEntity.js';

type ConstructorFavroEntity<EntityData extends Record<string, any>> = new (
Expand Down Expand Up @@ -658,19 +657,14 @@ export class BravoClient extends FavroClient {
`tags`,
{ method: 'get' },
BravoTagDefinition,
)) as BravoResponseEntities<
FavroApiData.Tag.Definition,
BravoTagDefinition
>;
)) as BravoResponseEntities<FavroApi.Tag.Data, BravoTagDefinition>;
this.cache.tags = res;
}
return this.cache.tags!;
}

async createTagDefinition(
options: Partial<
Omit<FavroApiData.Tag.Definition, 'tagId' | 'organizationId'>
>,
options: Partial<Omit<FavroApi.Tag.Data, 'tagId' | 'organizationId'>>,
) {
const res = (await this.requestWithReturnedEntities(
`tags`,
Expand All @@ -679,16 +673,13 @@ export class BravoClient extends FavroClient {
body: options,
},
BravoTagDefinition,
)) as BravoResponseEntities<
FavroApiData.Tag.Definition,
BravoTagDefinition
>;
)) as BravoResponseEntities<FavroApi.Tag.Data, BravoTagDefinition>;
return await res.getFirstEntity();
}

async updateTagDefinition(
options: RequiredBy<
Partial<Omit<FavroApiData.Tag.Definition, 'organizationId'>>,
Partial<Omit<FavroApi.Tag.Data, 'organizationId'>>,
'tagId'
>,
) {
Expand All @@ -699,10 +690,7 @@ export class BravoClient extends FavroClient {
body: options,
},
BravoTagDefinition,
)) as BravoResponseEntities<
FavroApiData.Tag.Definition,
BravoTagDefinition
>;
)) as BravoResponseEntities<FavroApi.Tag.Data, BravoTagDefinition>;
return await res.getFirstEntity();
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/clientLib/BravoResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { DataFavroCustomFieldDefinition } from '$/types/FavroCustomFieldTyp
import type { DataFavroWidget } from '$/types/FavroWidgetTypes.js';
import type { BravoWidget } from '$entities/BravoWidget.js';
import type { BravoCustomFieldDefinition } from '../entities/BravoCustomField.js';
import type { FavroApiData } from '$/types/FavroTagTypes.js';
import type { FavroApi } from '$favro';
import type { BravoTagDefinition } from '../entities/BravoTag.js';

export type BravoResponseWidgets = BravoResponseEntities<
Expand All @@ -19,7 +19,7 @@ export type BravoResponseCustomFields = BravoResponseEntities<
>;

export type BravoResponseTags = BravoResponseEntities<
FavroApiData.Tag.Definition,
FavroApi.Tag.Data,
BravoTagDefinition
>;

Expand Down
1 change: 0 additions & 1 deletion src/lib/clientLib/FavroClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assertBravoClaim, BravoError } from '$lib/errors.js';
import fetch from 'node-fetch';
import { URL } from 'url';
import type { FavroApi } from '$/types/FavroApiTypes';
import { FavroResponse } from '$lib/clientLib/FavroResponse';
import { toBase64 } from '$lib/utility.js';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/clientLib/FavroResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Response } from 'node-fetch';
import { URL } from 'url';
import type { FavroApi } from '$/types/FavroApiTypes';
import type { FavroApi } from '$favro';
import { BravoError } from '../errors.js';
import type { FavroClient } from './FavroClient.js';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/entities/BravoCollection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BravoEntity } from '../BravoEntity.js';
import type { BravoWidget } from './BravoWidget.js';
import type { FavroApi } from '$/types/FavroApiTypes';
import type { FavroApi } from '$favro';
import type { OptionsBravoCreateWidget } from '$/types/ParameterOptions.js';

export class BravoCollection extends BravoEntity<FavroApi.Collection.Data> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/entities/BravoOrganization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FavroApi } from '$types/FavroApiTypes';
import type { FavroApi } from '$types/FavroApi';
import { BravoEntity } from '$lib/BravoEntity.js';

/** Hydrated Favro Organization. */
Expand Down
4 changes: 2 additions & 2 deletions src/lib/entities/BravoTag.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FavroApiData } from '$/types/FavroTagTypes.js';
import { BravoEntity } from '$lib/BravoEntity.js';
import type { FavroApi } from '$favro';

/** Hydrated Favro Organization. */
export class BravoTagDefinition extends BravoEntity<FavroApiData.Tag.Definition> {
export class BravoTagDefinition extends BravoEntity<FavroApi.Tag.Data> {
get name() {
return this._data.name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/entities/BravoUser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FavroApi } from '$types/FavroApiTypes';
import type { FavroApi } from '$types/FavroApi';
import { BravoEntity } from '$lib/BravoEntity.js';

/**
Expand Down
31 changes: 31 additions & 0 deletions src/types/FavroApiTypes.ts → src/types/FavroApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,35 @@ export namespace FavroApi {
organizationRole: Organization.FieldTypes.Role;
}
}

/**
* Favro tags are global to an organization.
*/
export namespace Tag {
export namespace FieldTypes {
/** {@link https://favro.com/developer/#tag-colors} */
export type Color =
| 'blue'
| 'purple'
| 'cyan'
| 'green'
| 'lightgreen'
| 'yellow'
| 'orange'
| 'red'
| 'brown'
| 'gray'
| 'slategray';
}

/**
* The data model for a Tag returned from the Favro API.
* See {@link https://favro.com/developer/#tag} */
export interface Data {
tagId: string;
organizationId: string;
name: string;
color: FieldTypes.Color;
}
}
}
27 changes: 0 additions & 27 deletions src/types/FavroTagTypes.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"$lib/*": ["src/lib/*"],
"$entities/*": ["src/lib/entities/*"],
"$types/*": ["src/types/*"],
"$favro": ["src/types/FavroApi.js"],
"$cli/*": ["src/cli/*"],
"$test/*": ["src/test/*"]
}
Expand Down

0 comments on commit e28bad5

Please sign in to comment.