@@ -5,38 +5,37 @@ import {
55 LinkedApiWorkflowTimeoutError ,
66 TLinkedApiErrorType ,
77 TWorkflowCompletion ,
8- TWorkflowDefinition ,
98 TWorkflowResponse ,
109 TWorkflowRunningStatus ,
1110} from '../types' ;
1211
1312import { pollWorkflowResult } from './poll-results' ;
1413
1514export const OPERATION_NAME = {
16- fetchPerson : 'fetchPerson' ,
17- fetchCompany : 'fetchCompany' ,
18- salesNavigatorFetchCompany : 'salesNavigatorFetchCompany' ,
19- salesNavigatorFetchPerson : 'salesNavigatorFetchPerson' ,
20- fetchPost : 'fetchPost' ,
21- searchCompanies : 'searchCompanies' ,
22- salesNavigatorSearchCompanies : 'salesNavigatorSearchCompanies' ,
23- searchPeople : 'searchPeople' ,
24- salesNavigatorSearchPeople : 'salesNavigatorSearchPeople' ,
15+ customWorkflow : 'customWorkflow' ,
2516 sendMessage : 'sendMessage' ,
2617 syncConversation : 'syncConversation' ,
27- salesNavigatorSendMessage : 'salesNavigatorSendMessage' ,
28- salesNavigatorSyncConversation : 'salesNavigatorSyncConversation' ,
29- sendConnectionRequest : 'sendConnectionRequest' ,
3018 checkConnectionStatus : 'checkConnectionStatus' ,
19+ sendConnectionRequest : 'sendConnectionRequest' ,
3120 withdrawConnectionRequest : 'withdrawConnectionRequest' ,
3221 retrievePendingRequests : 'retrievePendingRequests' ,
3322 retrieveConnections : 'retrieveConnections' ,
3423 removeConnection : 'removeConnection' ,
24+ searchCompanies : 'searchCompanies' ,
25+ searchPeople : 'searchPeople' ,
26+ fetchPerson : 'fetchPerson' ,
27+ fetchCompany : 'fetchCompany' ,
28+ fetchPost : 'fetchPost' ,
3529 reactToPost : 'reactToPost' ,
3630 commentOnPost : 'commentOnPost' ,
3731 retrieveSSI : 'retrieveSSI' ,
3832 retrievePerformance : 'retrievePerformance' ,
39- customWorkflow : 'customWorkflow' ,
33+ nvSendMessage : 'nvSendMessage' ,
34+ nvSyncConversation : 'nvSyncConversation' ,
35+ nvSearchCompanies : 'nvSearchCompanies' ,
36+ nvSearchPeople : 'nvSearchPeople' ,
37+ nvFetchCompany : 'nvFetchCompany' ,
38+ nvFetchPerson : 'nvFetchPerson' ,
4039} as const ;
4140export type TOperationName = ( typeof OPERATION_NAME ) [ keyof typeof OPERATION_NAME ] ;
4241
@@ -45,52 +44,15 @@ export interface WaitForCompletionOptions {
4544 timeout ?: number ;
4645}
4746
48- export abstract class PredefinedOperation < TParams , TResult > {
47+ export abstract class Operation < TParams , TResult > {
4948 protected abstract readonly operationName : TOperationName ;
5049 protected abstract readonly mapper : BaseMapper < TParams , TResult > ;
5150
52- private readonly operation : CustomWorkflowOperation ;
53-
54- constructor ( httpClient : HttpClient ) {
55- this . operation = new CustomWorkflowOperation ( httpClient ) ;
56- }
51+ constructor ( private readonly httpClient : HttpClient ) { }
5752
5853 public async execute ( params : TParams ) : Promise < string > {
5954 const request = this . mapper . mapRequest ( params ) ;
60- return this . operation . execute ( request ) ;
61- }
62-
63- public async result (
64- workflowId : string ,
65- options : WaitForCompletionOptions = { } ,
66- ) : Promise < TMappedResponse < TResult > > {
67- try {
68- const rawResult = await this . operation . result ( workflowId , options ) ;
69- return this . mapper . mapResponse ( rawResult ) ;
70- } catch ( error ) {
71- if ( error instanceof LinkedApiError && error . type === 'workflowTimeout' ) {
72- throw new LinkedApiWorkflowTimeoutError ( workflowId , this . operationName ) ;
73- }
74- throw error ;
75- }
76- }
77-
78- public async status (
79- workflowId : string ,
80- ) : Promise < TWorkflowRunningStatus | TMappedResponse < TResult > > {
81- const result = await this . operation . status ( workflowId ) ;
82- if ( result === 'running' ) {
83- return result ;
84- }
85- return this . mapper . mapResponse ( result ) ;
86- }
87- }
88-
89- export class CustomWorkflowOperation {
90- constructor ( private readonly httpClient : HttpClient ) { }
91-
92- public async execute ( params : TWorkflowDefinition ) : Promise < string > {
93- const response = await this . httpClient . post < TWorkflowResponse > ( `/workflows` , params ) ;
55+ const response = await this . httpClient . post < TWorkflowResponse > ( `/workflows` , request ) ;
9456 if ( response . error ) {
9557 throw new LinkedApiError ( response . error . type as TLinkedApiErrorType , response . error . message ) ;
9658 }
@@ -103,23 +65,26 @@ export class CustomWorkflowOperation {
10365 public async result (
10466 workflowId : string ,
10567 options : WaitForCompletionOptions = { } ,
106- ) : Promise < TWorkflowCompletion > {
68+ ) : Promise < TMappedResponse < TResult > > {
10769 try {
108- return pollWorkflowResult ( ( ) => this . status ( workflowId ) , options ) ;
70+ return pollWorkflowResult < TMappedResponse < TResult > > ( ( ) => this . status ( workflowId ) , options ) ;
10971 } catch ( error ) {
11072 if ( error instanceof LinkedApiError && error . type === 'workflowTimeout' ) {
111- throw new LinkedApiWorkflowTimeoutError ( workflowId , 'customWorkflow' ) ;
73+ throw new LinkedApiWorkflowTimeoutError ( workflowId , this . operationName ) ;
11274 }
11375 throw error ;
11476 }
11577 }
11678
117- public async status ( workflowId : string ) : Promise < TWorkflowRunningStatus | TWorkflowCompletion > {
79+ public async status (
80+ workflowId : string ,
81+ ) : Promise < TWorkflowRunningStatus | TMappedResponse < TResult > > {
11882 const workflowResult = await this . getWorkflowResult ( workflowId ) ;
11983 if ( workflowResult . workflowStatus === 'running' ) {
12084 return workflowResult . workflowStatus ;
12185 }
122- return this . getCompletion ( workflowResult ) ;
86+ const result = this . getCompletion ( workflowResult ) ;
87+ return this . mapper . mapResponse ( result ) ;
12388 }
12489
12590 private async getWorkflowResult ( workflowId : string ) : Promise < TWorkflowResponse > {
0 commit comments