-
Notifications
You must be signed in to change notification settings - Fork 16
Favorites / TS API structures #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smar-ben-feigin
wants to merge
11
commits into
mainline
Choose a base branch
from
bfeigin/favorites-ts
base: mainline
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b9ab288
structure for ts building
smar-ben-feigin 909a9b7
small refactor
smar-ben-feigin ecb3a42
rename section => resource
smar-ben-feigin 30c4dd9
rename section => resource
smar-ben-feigin d2634af
fix why no tsc find?
smar-ben-feigin 2550312
revert big lint changes
smar-ben-feigin af26eeb
just update name of apiUrls
smar-ben-feigin 0e2f3e5
combine types and enums in single file, preserve backwards compat
smar-ben-feigin 9606a37
Merge branch 'mainline' into bfeigin/favorites-ts
smar-ben-feigin 476df76
Merge branch 'mainline' into bfeigin/favorites-ts
smar-ben-feigin 1bb4e47
wip
smar-ben-feigin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,14 @@ | ||
| import { createApiProvider } from '../utils/createApiProvider'; | ||
| import { EventsApi, GetEventsOptions, GetEventsResponse } from './types'; | ||
| import { ClientOptions, CreateOptions, RequestCallback, RequestOptions } from '../types'; | ||
|
|
||
| type OptionsToSend = Partial<ClientOptions> & { | ||
| url: string; | ||
| }; | ||
| import { ApiResource, CreateOptions, RequestCallback, RequestOptions } from '../types'; | ||
|
|
||
| export const createEvents = (options: CreateOptions): EventsApi => { | ||
| const requester = options.requestor; | ||
|
|
||
| let optionsToSend: OptionsToSend = { | ||
| url: options.apiUrls.events, | ||
| }; | ||
|
|
||
| if (options.clientOptions) { | ||
| optionsToSend = { | ||
| ...optionsToSend, | ||
| ...options.clientOptions, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| return createApiProvider<EventsApi>(options, ApiResource.Events, (requester, optionsToSend) => ({ | ||
| getEvents: ( | ||
| options: RequestOptions<GetEventsOptions, undefined>, | ||
| callback?: RequestCallback<GetEventsResponse> | ||
| ): Promise<GetEventsResponse> => { | ||
| return requester.get({ ...optionsToSend, ...options }, callback); | ||
| }, | ||
| }; | ||
| })); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { RequestCallback } from '../../types'; | ||
| import { ApiGenerator, FavoritableResource, FavoriteItem, PostResult } from '../sharedTypes'; | ||
| const _ = require('underscore'); | ||
|
|
||
| type AddItemsToFavoritesParams = { | ||
| body: FavoriteItem | FavoriteItem[]; | ||
| }; | ||
|
|
||
| type AddItemsToFavoritesResponse = { | ||
| /** | ||
| * @description Favorite (object) or Array of Favorite (objects) | ||
| */ | ||
| result: FavoriteItem | FavoriteItem[]; | ||
| } & PostResult; | ||
|
|
||
| type AddItemsToFavoritesRequest = ( | ||
| params: AddItemsToFavoritesParams, | ||
| callback: RequestCallback<AddItemsToFavoritesResponse> | ||
| ) => Promise<AddItemsToFavoritesResponse>; | ||
|
|
||
| export const addItemsToFavorites: ApiGenerator<AddItemsToFavoritesRequest> = | ||
| (requestor, optionsToSend) => (params, callback) => { | ||
| // TODO Bfeigin do i need to explicitly set this to be a body param? | ||
| return requestor.post(_.extend({}, optionsToSend, params), callback); | ||
| }; | ||
|
|
||
| type AddResourceToFavoritesParams = { | ||
| objectId: string; | ||
| }; | ||
|
|
||
| type AddItemOfTypeToFavoritesRequest = ( | ||
| params: AddResourceToFavoritesParams, | ||
| callback: RequestCallback<AddItemsToFavoritesResponse> | ||
| ) => Promise<AddItemsToFavoritesResponse>; | ||
|
|
||
| type AddFavoritesBuilder = (resourceType: FavoritableResource) => ApiGenerator<AddItemOfTypeToFavoritesRequest>; | ||
|
|
||
| export const buildAddFavoriteResourceFn: AddFavoritesBuilder = (resourceType: FavoritableResource) => { | ||
| return (requestor, optionsToSend) => (params, callback) => { | ||
| const generatedBody = { | ||
| objectId: params.objectId, | ||
| type: resourceType, | ||
| }; | ||
|
|
||
| // Ensure we've extracted out any type and objectId params, placing them into body instead | ||
| const constructedPostParams = { | ||
| ..._.omit(params, 'type', 'objectId'), | ||
| body: generatedBody, | ||
| }; | ||
|
|
||
| return requestor.post(_.extend({}, optionsToSend, constructedPostParams), callback); | ||
| }; | ||
| }; | ||
|
|
||
| export const addSheetToFavorites = buildAddFavoriteResourceFn(FavoritableResource.Sheet); | ||
| export const addFolderToFavorites = buildAddFavoriteResourceFn(FavoritableResource.Folder); | ||
| export const addReportToFavorites = buildAddFavoriteResourceFn(FavoritableResource.Report); | ||
| export const addTemplateToFavorites = buildAddFavoriteResourceFn(FavoritableResource.Template); | ||
| export const addWorkspaceToFavorites = buildAddFavoriteResourceFn(FavoritableResource.Workspace); | ||
| export const addSightToFavorites = buildAddFavoriteResourceFn(FavoritableResource.Sight); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { RequestCallback } from '../../types'; | ||
| import { ApiGenerator, FavoriteItem, Pagination, PaginationResponse } from '../sharedTypes'; | ||
|
|
||
| type IncludeOptions = string; | ||
|
|
||
| type ListFavortesParams = { | ||
| /** | ||
| * @description If true, include all results, that is, do not paginate. Mutually exclusive with page and pageSize (they are ignored if includeAll=true is specified). | ||
| */ | ||
| includeAll?: boolean; | ||
| /** | ||
| * @description A comma-separated list of optional elements to include in the response. | ||
| * Enum ["directId", "name"] | ||
| */ | ||
| include?: IncludeOptions; | ||
| } & Pagination; | ||
|
|
||
| export type ListFavoritesResponse = PaginationResponse & { | ||
| data: FavoriteItem[]; | ||
| }; | ||
| /** | ||
| * @description Gets a list of all of the user's favorite items. | ||
| */ | ||
| export type ListFavoritesRequest = ( | ||
| params: ListFavortesParams, | ||
| callback: RequestCallback<ListFavoritesResponse> | ||
| ) => Promise<ListFavoritesResponse>; | ||
|
|
||
| export const createListFavorites: ApiGenerator<ListFavoritesRequest> = | ||
| (requestor, optionsToSend) => (params, callback) => { | ||
| return requestor.get({ ...optionsToSend, ...params }, callback); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { FavoritableResource, FavoriteItem } from '../sharedTypes'; | ||
|
|
||
| type RemoveSingleFavoriteItem = {}; | ||
|
Check failure on line 3 in lib/favorites/endpoints/RemoveFavorites.ts
|
||
|
|
||
| type RemoveFavoritesBaseParams = { | ||
| /** | ||
| * @description A string or array of strings representing the objectIds to remove from favorites | ||
| */ | ||
| objectIds: FavoriteItem['objectId'] | FavoriteItem['objectId'][]; | ||
| favoriteType: FavoritableResource; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { ApiResource, CreateOptions } from '../types'; | ||
| import { createApiProvider } from '../utils/createApiProvider'; | ||
| import { createListFavorites } from './endpoints/ListFavorites'; | ||
| import { | ||
| addFolderToFavorites, | ||
| addItemsToFavorites, | ||
| addReportToFavorites, | ||
| addSheetToFavorites, | ||
| addSightToFavorites, | ||
| addTemplateToFavorites, | ||
| addWorkspaceToFavorites, | ||
| } from './endpoints/AddItemsToFavorites'; | ||
| import { ApiGenerator } from './sharedTypes'; | ||
| import { FavoritesApi } from './types'; | ||
|
|
||
| const buildFavoritesApi: ApiGenerator<FavoritesApi> = (requestor, optionsToSend) => { | ||
| return { | ||
| listFavorites: createListFavorites(requestor, optionsToSend), | ||
| addItemsToFavorites: addItemsToFavorites(requestor, optionsToSend), | ||
| addFolderToFavorites: addFolderToFavorites(requestor, optionsToSend), | ||
| addReportToFavorites: addReportToFavorites(requestor, optionsToSend), | ||
| addSheetToFavorites: addSheetToFavorites(requestor, optionsToSend), | ||
| addSightToFavorites: addSightToFavorites(requestor, optionsToSend), | ||
| addTemplateToFavorites: addTemplateToFavorites(requestor, optionsToSend), | ||
| addWorkspaceToFavorites: addWorkspaceToFavorites(requestor, optionsToSend), | ||
| // Duplicate of addItemsToFavorites | ||
| addMultipleToFavorites: addItemsToFavorites(requestor, optionsToSend), | ||
| }; | ||
| }; | ||
|
|
||
| //type FavoritesApi = { | ||
| // listFavorites : listFavorites, | ||
| // addItemsToFavorites : addItemsToFavorites, | ||
| // addSheetToFavorites : addSheetToFavorites, | ||
| // addFolderToFavorites : addFolderToFavorites, | ||
| // addReportToFavorites : addReportToFavorites, | ||
| // addTemplateToFavorites : addTemplateToFavorites, | ||
| // addSightToFavorites : addSightToFavorites, | ||
| // addWorkspaceToFavorites : addWorkspaceToFavorites, | ||
| // addMultipleToFavorites : addMultipleToFavorites, | ||
| // removeSheetFromFavorites : removeSheetFromFavorites, | ||
| // removeFolderFromFavorites : removeFolderFromFavorites, | ||
| // removeReportFromFavorites : removeReportFromFavorites, | ||
| // removeTemplateFromFavorites : removeTemplateFromFavorites, | ||
| // removeSightFromFavorites : removeSightFromFavorites, | ||
| // removeWorkspaceFromFavorites : removeWorkspaceFromFavorites, | ||
| // //convenience methods to remove multiples. | ||
| // //Uses the same as the singular remove methods. | ||
| // removeSheetsFromFavorites : removeSheetFromFavorites, | ||
| // removeFoldersFromFavorites : removeFolderFromFavorites, | ||
| // removeReportsFromFavorites : removeReportFromFavorites, | ||
| // removeTemplatesFromFavorites : removeTemplateFromFavorites, | ||
| // removeSightsFromFavorites : removeSightFromFavorites, | ||
| // removeWorkspacesFromFavorites : removeWorkspaceFromFavorites | ||
| // | ||
| //} | ||
|
|
||
| export const createFavorites = (options: CreateOptions) => { | ||
| return createApiProvider(options, ApiResource.Favorites, buildFavoritesApi); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { OptionsToSend, Requestor } from '../types'; | ||
|
|
||
| export type Pagination = { | ||
| /** | ||
| * @description Which page to return. Defaults to 1 if not specified. If you specify a value greater than the total number of pages, the last page of results is returned. | ||
| * | ||
| */ | ||
| page?: number; | ||
| /** | ||
| * @description The maximum number of items to return per page. Unless otherwise stated for a specific endpoint, defaults to 100. If only page is specified, defaults to a page size of 100. For reports, the default is 100 rows. If you need larger sets of data from your report, returns a maximum of 10,000 rows per request. | ||
| */ | ||
| pageSize?: number; | ||
| }; | ||
|
|
||
| export type PaginationResponse = { | ||
| pageNumber: number; | ||
| pageSize?: number; | ||
| totalPages: number; | ||
| totalCount: number; | ||
| }; | ||
|
|
||
| export enum FavoritableResource { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a standard set of resources? |
||
| Folder = 'folder', | ||
| Report = 'report', | ||
| Sheet = 'sheet', | ||
| Sight = 'sight', | ||
| Template = 'template', | ||
| Workspace = 'workspace', | ||
| } | ||
|
|
||
| export enum ResponseStatusMessage { | ||
| PartialSuccess = 'PARTIAL_SUCCESS', | ||
| SUCCESS = 'SUCCESS', | ||
| } | ||
|
|
||
| export enum ResultCode { | ||
| Success = 0, | ||
| PartialSuccess = 3, | ||
| } | ||
|
|
||
| export type PostResult = { | ||
| /** | ||
| * @description Message that indicates the outcome of the request. (One of SUCCESS or PARTIAL_SUCCESS) | ||
| */ | ||
| message: ResponseStatusMessage; | ||
| /** | ||
| * @description number indicating result status: 0 Success, 3 Partial Success of Bulk Operation | ||
| * | ||
| */ | ||
| resultCode: ResultCode; | ||
| }; | ||
|
|
||
| export type FavoriteItem = { | ||
| objectId: string; | ||
| type: FavoritableResource; | ||
| }; | ||
|
|
||
| export type ApiGenerator<T> = (requestor: Requestor, optionsToSend: OptionsToSend) => T; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { ListFavoritesRequest } from "./endpoints/ListFavorites"; | ||
|
|
||
| export type FavoritesApi = { | ||
| listFavorites: ListFavoritesRequest; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,47 @@ | ||
| export interface ApiUrls { | ||
| contacts: string; | ||
| events: string; | ||
| favorites: string; | ||
| folders: string; | ||
| groups: string; | ||
| home: string; | ||
| imageUrls: string; | ||
| reports: string; | ||
| search: string; | ||
| server: string; | ||
| sheets: string; | ||
| sights: string; | ||
| templates: string; | ||
| templatesPublic: string; | ||
| token: string; | ||
| users: string; | ||
| webhooks: string; | ||
| workspaces: string; | ||
| export enum ApiResource { | ||
| Contacts = 'contacts', | ||
| Events = 'events', | ||
| Favorites = 'favorites', | ||
| Folders = 'folders', | ||
| Groups = 'groups', | ||
| Home = 'home', | ||
| ImageUrls = 'imageurls', | ||
| Reports = 'reports', | ||
| Search = 'search', | ||
| Server = 'serverinfo', | ||
| Sheets = 'sheets', | ||
| Sights = 'sights', | ||
| Templates = 'templates', | ||
| TemplatesPublic = 'templatespublic', | ||
| Token = 'token', | ||
| Users = 'users', | ||
| Webhooks = 'webhooks', | ||
| Workspaces = 'workspaces', | ||
| } | ||
|
|
||
| export const apiUrlByResource = { | ||
| [ApiResource.Contacts]: 'contacts/', | ||
| [ApiResource.Events]: 'events/', | ||
| [ApiResource.Favorites]: 'favorites/', | ||
| [ApiResource.Folders]: 'folders/', | ||
| [ApiResource.Groups]: 'groups/', | ||
| [ApiResource.Home]: 'home/', | ||
| [ApiResource.ImageUrls]: 'imageurls/', | ||
| [ApiResource.Reports]: 'reports/', | ||
| [ApiResource.Search]: 'search/', | ||
| [ApiResource.Server]: 'serverinfo/', | ||
| [ApiResource.Sheets]: 'sheets/', | ||
| [ApiResource.Sights]: 'sights/', | ||
| [ApiResource.Templates]: 'templates/', | ||
| [ApiResource.TemplatesPublic]: 'templates/public', | ||
| [ApiResource.Token]: 'token', | ||
| [ApiResource.Users]: 'users/', | ||
| [ApiResource.Webhooks]: 'webhooks/', | ||
| [ApiResource.Workspaces]: 'workspaces/', | ||
| } as const; | ||
|
|
||
| // Map of ApiResource to path | ||
| export type ApiUrlPathByResource = typeof apiUrlByResource; | ||
|
|
||
| // Valid paths for Api Resources | ||
| export type ApiUrlPath = ApiUrlPathByResource[ApiResource]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,30 @@ | ||
| import { ApiUrls } from './ApiUrls'; | ||
| import { ApiUrlPathByResource } from './ApiUrls'; | ||
| import { CreateClientOptions } from './CreateClientOptions'; | ||
|
|
||
| export type ClientOptions = Pick<CreateClientOptions, 'accessToken' | 'userAgent' | 'baseUrl'>; | ||
|
|
||
| export interface Requestor { | ||
| get: (options: any, callback: any) => any; | ||
| put: (options: any, callback: any) => any; | ||
| post: (options: any, callback: any) => any; | ||
| postFile: (options: any, callback: any) => any; | ||
| delete: (options: any, callback: any) => any; | ||
| internal: { | ||
| buildHeaders: (options: any) => { | ||
| Accept: any; | ||
| 'Content-Type': any; | ||
| 'User-Agent': string; | ||
| }; | ||
| buildUrl: (options: any) => any; | ||
| }; | ||
| } | ||
|
|
||
| export interface CreateOptions { | ||
| apiUrls: ApiUrls; | ||
| requestor: any; | ||
| apiUrls: ApiUrlPathByResource; | ||
| requestor: Requestor; | ||
| clientOptions?: ClientOptions; | ||
| } | ||
|
|
||
| export type OptionsToSend = Partial<ClientOptions> & { | ||
| url: string; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How frequently are these types used (everywhere?)