{"action":"created","comment":{"url":"https://api.github.com/repos/coveo/platform-client/pulls/comments/350777982","pull_request_review_id":323027040,"id":350777982,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM1MDc3Nzk4Mg==","diff_hunk":"@@ -38,10 +39,21 @@ export class PlatformClient extends PlatformResources {\n             throw new HostUndefinedError();\n         }\n \n-        this.API = new API(this.apiConfiguration);\n+        const api: IAPI = new API(this.apiConfiguration);\n+        this.API = this.options.apiFeatures\n+            ? this.options.apiFeatures.reduce((current, feature) => feature(current), api)\n+            : api;\n         this.registerAll();\n     }\n \n+    withFeatures(...features: IAPIFeature[]): this {\n+        const newInstance = Object.create(this) as this;\n+        return newInstance.constructor({\n+            ...this.options,\n+            apiFeatures: [...(this.options.apiFeatures || []), ...features],\n+        } as PlatformClientOptions);","path":"src/PlatformClient.ts","position":26,"original_position":26,"commit_id":"54f30d96e2fbc1bae59098c61f1bf2280086ce99","original_commit_id":"54f30d96e2fbc1bae59098c61f1bf2280086ce99","user":{"login":"francoislg","id":8355585,"node_id":"MDQ6VXNlcjgzNTU1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/8355585?v=4","gravatar_id":"","url":"https://api.github.com/users/francoislg","html_url":"https://github.com/francoislg","followers_url":"https://api.github.com/users/francoislg/followers","following_url":"https://api.github.com/users/francoislg/following{/other_user}","gists_url":"https://api.github.com/users/francoislg/gists{/gist_id}","starred_url":"https://api.github.com/users/francoislg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francoislg/subscriptions","organizations_url":"https://api.github.com/users/francoislg/orgs","repos_url":"https://api.github.com/users/francoislg/repos","events_url":"https://api.github.com/users/francoislg/events{/privacy}","received_events_url":"https://api.github.com/users/francoislg/received_events","type":"User","site_admin":false},"body":"I did try it at first, but I get:\r\n\r\n```\r\nThe initial value of Object.prototype.constructor is the standard built-in Object constructor.\r\n\r\nThis expression is not constructable.\r\n  Type 'Function' has no construct signatures.ts(2351)\r\n```","created_at":"2019-11-26T14:36:52Z","updated_at":"2019-11-26T14:36:53Z","html_url":"https://github.com/coveo/platform-client/pull/44#discussion_r350777982","pull_request_url":"https://api.github.com/repos/coveo/platform-client/pulls/44","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/coveo/platform-client/pulls/comments/350777982"},"html":{"href":"https://github.com/coveo/platform-client/pull/44#discussion_r350777982"},"pull_request":{"href":"https://api.github.com/repos/coveo/platform-client/pulls/44"}},"in_reply_to_id":350752189},"pull_request":{"url":"https://api.github.com/repos/coveo/platform-client/pulls/44","id":341070743,"node_id":"MDExOlB1bGxSZXF1ZXN0MzQxMDcwNzQz","html_url":"https://github.com/coveo/platform-client/pull/44","diff_url":"https://github.com/coveo/platform-client/pull/44.diff","patch_url":"https://github.com/coveo/platform-client/pull/44.patch","issue_url":"https://api.github.com/repos/coveo/platform-client/issues/44","number":44,"state":"open","locked":false,"title":"(DO NOT MERGE) Experimental API Features wrappers","user":{"login":"francoislg","id":8355585,"node_id":"MDQ6VXNlcjgzNTU1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/8355585?v=4","gravatar_id":"","url":"https://api.github.com/users/francoislg","html_url":"https://github.com/francoislg","followers_url":"https://api.github.com/users/francoislg/followers","following_url":"https://api.github.com/users/francoislg/following{/other_user}","gists_url":"https://api.github.com/users/francoislg/gists{/gist_id}","starred_url":"https://api.github.com/users/francoislg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francoislg/subscriptions","organizations_url":"https://api.github.com/users/francoislg/orgs","repos_url":"https://api.github.com/users/francoislg/repos","events_url":"https://api.github.com/users/francoislg/events{/privacy}","received_events_url":"https://api.github.com/users/francoislg/received_events","type":"User","site_admin":false},"body":"The goal here is to allow cherry-picking hooks before and after requests.\r\n\r\nFor instance, I would like to be able to support a couple of use cases:\r\n\r\n* `client.withFeature(requestId(FETCH_ACTION)).get()` that would automatically dispatch the actions for \"request started\", \"request failed\" and \"request succeeded\".\r\n* `client.withFeature(toastErrorNotification())` that would automatically prompt a toast on known errors.\r\n\r\nI would also like to have to features either at large in a client (`client.withFeature(x).catalog`) or cherry-picked before executing a query: `client.catalog.withFeature(x)`.\r\n\r\nSo here is my early PoC. I would like to get some feedback on the feature, whether you like it, whether you see better/cleaner way of doing this.\r\n\r\nThe way I built it now, I really like that I didn't have to alter the `API` implementation that much, and also that we don't have any \"state\" to keep track of whether a feature should be enabled or not.","created_at":"2019-11-14T16:40:22Z","updated_at":"2019-11-26T14:36:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d1c8166bfc3cbfdb6427ad1e92d52d047e18d83c","assignee":null,"assignees":[],"requested_reviewers":[{"login":"rosalie-liu","id":52677246,"node_id":"MDQ6VXNlcjUyNjc3MjQ2","avatar_url":"https://avatars1.githubusercontent.com/u/52677246?v=4","gravatar_id":"","url":"https://api.github.com/users/rosalie-liu","html_url":"https://github.com/rosalie-liu","followers_url":"https://api.github.com/users/rosalie-liu/followers","following_url":"https://api.github.com/users/rosalie-liu/following{/other_user}","gists_url":"https://api.github.com/users/rosalie-liu/gists{/gist_id}","starred_url":"https://api.github.com/users/rosalie-liu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosalie-liu/subscriptions","organizations_url":"https://api.github.com/users/rosalie-liu/orgs","repos_url":"https://api.github.com/users/rosalie-liu/repos","events_url":"https://api.github.com/users/rosalie-liu/events{/privacy}","received_events_url":"https://api.github.com/users/rosalie-liu/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/coveo/platform-client/pulls/44/commits","review_comments_url":"https://api.github.com/repos/coveo/platform-client/pulls/44/comments","review_comment_url":"https://api.github.com/repos/coveo/platform-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coveo/platform-client/issues/44/comments","statuses_url":"https://api.github.com/repos/coveo/platform-client/statuses/54f30d96e2fbc1bae59098c61f1bf2280086ce99","head":{"label":"coveo:experimental-api-features-hoc","ref":"experimental-api-features-hoc","sha":"54f30d96e2fbc1bae59098c61f1bf2280086ce99","user":{"login":"coveo","id":8632328,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg2MzIzMjg=","avatar_url":"https://avatars2.githubusercontent.com/u/8632328?v=4","gravatar_id":"","url":"https://api.github.com/users/coveo","html_url":"https://github.com/coveo","followers_url":"https://api.github.com/users/coveo/followers","following_url":"https://api.github.com/users/coveo/following{/other_user}","gists_url":"https://api.github.com/users/coveo/gists{/gist_id}","starred_url":"https://api.github.com/users/coveo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveo/subscriptions","organizations_url":"https://api.github.com/users/coveo/orgs","repos_url":"https://api.github.com/users/coveo/repos","events_url":"https://api.github.com/users/coveo/events{/privacy}","received_events_url":"https://api.github.com/users/coveo/received_events","type":"Organization","site_admin":false},"repo":{"id":208327937,"node_id":"MDEwOlJlcG9zaXRvcnkyMDgzMjc5Mzc=","name":"platform-client","full_name":"coveo/platform-client","private":false,"owner":{"login":"coveo","id":8632328,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg2MzIzMjg=","avatar_url":"https://avatars2.githubusercontent.com/u/8632328?v=4","gravatar_id":"","url":"https://api.github.com/users/coveo","html_url":"https://github.com/coveo","followers_url":"https://api.github.com/users/coveo/followers","following_url":"https://api.github.com/users/coveo/following{/other_user}","gists_url":"https://api.github.com/users/coveo/gists{/gist_id}","starred_url":"https://api.github.com/users/coveo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveo/subscriptions","organizations_url":"https://api.github.com/users/coveo/orgs","repos_url":"https://api.github.com/users/coveo/repos","events_url":"https://api.github.com/users/coveo/events{/privacy}","received_events_url":"https://api.github.com/users/coveo/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/coveo/platform-client","description":"Official Coveo Cloud APIs JavaScript Client","fork":false,"url":"https://api.github.com/repos/coveo/platform-client","forks_url":"https://api.github.com/repos/coveo/platform-client/forks","keys_url":"https://api.github.com/repos/coveo/platform-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coveo/platform-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coveo/platform-client/teams","hooks_url":"https://api.github.com/repos/coveo/platform-client/hooks","issue_events_url":"https://api.github.com/repos/coveo/platform-client/issues/events{/number}","events_url":"https://api.github.com/repos/coveo/platform-client/events","assignees_url":"https://api.github.com/repos/coveo/platform-client/assignees{/user}","branches_url":"https://api.github.com/repos/coveo/platform-client/branches{/branch}","tags_url":"https://api.github.com/repos/coveo/platform-client/tags","blobs_url":"https://api.github.com/repos/coveo/platform-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coveo/platform-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coveo/platform-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/coveo/platform-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coveo/platform-client/statuses/{sha}","languages_url":"https://api.github.com/repos/coveo/platform-client/languages","stargazers_url":"https://api.github.com/repos/coveo/platform-client/stargazers","contributors_url":"https://api.github.com/repos/coveo/platform-client/contributors","subscribers_url":"https://api.github.com/repos/coveo/platform-client/subscribers","subscription_url":"https://api.github.com/repos/coveo/platform-client/subscription","commits_url":"https://api.github.com/repos/coveo/platform-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/coveo/platform-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/coveo/platform-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/coveo/platform-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/coveo/platform-client/contents/{+path}","compare_url":"https://api.github.com/repos/coveo/platform-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coveo/platform-client/merges","archive_url":"https://api.github.com/repos/coveo/platform-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coveo/platform-client/downloads","issues_url":"https://api.github.com/repos/coveo/platform-client/issues{/number}","pulls_url":"https://api.github.com/repos/coveo/platform-client/pulls{/number}","milestones_url":"https://api.github.com/repos/coveo/platform-client/milestones{/number}","notifications_url":"https://api.github.com/repos/coveo/platform-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coveo/platform-client/labels{/name}","releases_url":"https://api.github.com/repos/coveo/platform-client/releases{/id}","deployments_url":"https://api.github.com/repos/coveo/platform-client/deployments","created_at":"2019-09-13T18:56:33Z","updated_at":"2019-11-22T15:51:24Z","pushed_at":"2019-11-25T15:49:08Z","git_url":"git://github.com/coveo/platform-client.git","ssh_url":"git@github.com:coveo/platform-client.git","clone_url":"https://github.com/coveo/platform-client.git","svn_url":"https://github.com/coveo/platform-client","homepage":"","size":194,"stargazers_count":1,"watchers_count":1,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"coveo:master","ref":"master","sha":"f9b1140e449b06b5713638f47d27eb3017027625","user":{"login":"coveo","id":8632328,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg2MzIzMjg=","avatar_url":"https://avatars2.githubusercontent.com/u/8632328?v=4","gravatar_id":"","url":"https://api.github.com/users/coveo","html_url":"https://github.com/coveo","followers_url":"https://api.github.com/users/coveo/followers","following_url":"https://api.github.com/users/coveo/following{/other_user}","gists_url":"https://api.github.com/users/coveo/gists{/gist_id}","starred_url":"https://api.github.com/users/coveo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveo/subscriptions","organizations_url":"https://api.github.com/users/coveo/orgs","repos_url":"https://api.github.com/users/coveo/repos","events_url":"https://api.github.com/users/coveo/events{/privacy}","received_events_url":"https://api.github.com/users/coveo/received_events","type":"Organization","site_admin":false},"repo":{"id":208327937,"node_id":"MDEwOlJlcG9zaXRvcnkyMDgzMjc5Mzc=","name":"platform-client","full_name":"coveo/platform-client","private":false,"owner":{"login":"coveo","id":8632328,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg2MzIzMjg=","avatar_url":"https://avatars2.githubusercontent.com/u/8632328?v=4","gravatar_id":"","url":"https://api.github.com/users/coveo","html_url":"https://github.com/coveo","followers_url":"https://api.github.com/users/coveo/followers","following_url":"https://api.github.com/users/coveo/following{/other_user}","gists_url":"https://api.github.com/users/coveo/gists{/gist_id}","starred_url":"https://api.github.com/users/coveo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveo/subscriptions","organizations_url":"https://api.github.com/users/coveo/orgs","repos_url":"https://api.github.com/users/coveo/repos","events_url":"https://api.github.com/users/coveo/events{/privacy}","received_events_url":"https://api.github.com/users/coveo/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/coveo/platform-client","description":"Official Coveo Cloud APIs JavaScript Client","fork":false,"url":"https://api.github.com/repos/coveo/platform-client","forks_url":"https://api.github.com/repos/coveo/platform-client/forks","keys_url":"https://api.github.com/repos/coveo/platform-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coveo/platform-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coveo/platform-client/teams","hooks_url":"https://api.github.com/repos/coveo/platform-client/hooks","issue_events_url":"https://api.github.com/repos/coveo/platform-client/issues/events{/number}","events_url":"https://api.github.com/repos/coveo/platform-client/events","assignees_url":"https://api.github.com/repos/coveo/platform-client/assignees{/user}","branches_url":"https://api.github.com/repos/coveo/platform-client/branches{/branch}","tags_url":"https://api.github.com/repos/coveo/platform-client/tags","blobs_url":"https://api.github.com/repos/coveo/platform-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coveo/platform-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coveo/platform-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/coveo/platform-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coveo/platform-client/statuses/{sha}","languages_url":"https://api.github.com/repos/coveo/platform-client/languages","stargazers_url":"https://api.github.com/repos/coveo/platform-client/stargazers","contributors_url":"https://api.github.com/repos/coveo/platform-client/contributors","subscribers_url":"https://api.github.com/repos/coveo/platform-client/subscribers","subscription_url":"https://api.github.com/repos/coveo/platform-client/subscription","commits_url":"https://api.github.com/repos/coveo/platform-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/coveo/platform-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/coveo/platform-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/coveo/platform-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/coveo/platform-client/contents/{+path}","compare_url":"https://api.github.com/repos/coveo/platform-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coveo/platform-client/merges","archive_url":"https://api.github.com/repos/coveo/platform-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coveo/platform-client/downloads","issues_url":"https://api.github.com/repos/coveo/platform-client/issues{/number}","pulls_url":"https://api.github.com/repos/coveo/platform-client/pulls{/number}","milestones_url":"https://api.github.com/repos/coveo/platform-client/milestones{/number}","notifications_url":"https://api.github.com/repos/coveo/platform-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coveo/platform-client/labels{/name}","releases_url":"https://api.github.com/repos/coveo/platform-client/releases{/id}","deployments_url":"https://api.github.com/repos/coveo/platform-client/deployments","created_at":"2019-09-13T18:56:33Z","updated_at":"2019-11-22T15:51:24Z","pushed_at":"2019-11-25T15:49:08Z","git_url":"git://github.com/coveo/platform-client.git","ssh_url":"git@github.com:coveo/platform-client.git","clone_url":"https://github.com/coveo/platform-client.git","svn_url":"https://github.com/coveo/platform-client","homepage":"","size":194,"stargazers_count":1,"watchers_count":1,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coveo/platform-client/pulls/44"},"html":{"href":"https://github.com/coveo/platform-client/pull/44"},"issue":{"href":"https://api.github.com/repos/coveo/platform-client/issues/44"},"comments":{"href":"https://api.github.com/repos/coveo/platform-client/issues/44/comments"},"review_comments":{"href":"https://api.github.com/repos/coveo/platform-client/pulls/44/comments"},"review_comment":{"href":"https://api.github.com/repos/coveo/platform-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coveo/platform-client/pulls/44/commits"},"statuses":{"href":"https://api.github.com/repos/coveo/platform-client/statuses/54f30d96e2fbc1bae59098c61f1bf2280086ce99"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"francoislg"}}