@@ -4,62 +4,114 @@ import type {
44 AddSecretPayload ,
55 Bundle ,
66 CreateIntegrationPayload ,
7+ CreateWebhookPayload ,
8+ CustomEvent ,
9+ CustomEventUpdatePayload ,
710 GenereteDeleteTokenResponse ,
811 GetBundlesResponse ,
12+ GetCustomEventsResponse ,
13+ GetEventHistoryParams ,
14+ GetEventHistoryResponse ,
15+ GetEventPayloadResponse ,
16+ GetIntegrationsResponse ,
17+ GetLogQueriesResponse ,
18+ GetLogsResponse ,
919 GetSubscriptionsResponse ,
10- Integration ,
20+ GetWebhooksResponse ,
21+ InitializeLogQueryParams ,
22+ IntegrationDetail ,
1123 SubscribePayload ,
24+ TriggerWebhookPayload ,
1225 UpdateIntegrationPayload ,
26+ Webhook ,
1327} from './types.js' ;
1428
1529export class ArcIFX extends ArcAbstractAPI {
1630 constructor ( options : ArcAPIOptions ) {
1731 super ( { ...options , apiPath : 'ifx/api/v1' } ) ;
1832 }
1933
20- async createIntegration ( payload : CreateIntegrationPayload ) {
34+ // ---------------------------------------------------------------------------
35+ // Integrations
36+ // ---------------------------------------------------------------------------
37+
38+ async createIntegration ( payload : CreateIntegrationPayload ) : Promise < void > {
2139 await this . client . post ( '/admin/integration' , payload ) ;
2240 }
2341
24- async updateIntegration ( integrationName : string , payload : UpdateIntegrationPayload ) {
42+ async getIntegration ( integrationName : string ) : Promise < IntegrationDetail > {
43+ const { data } = await this . client . get < IntegrationDetail > ( `/admin/integration/${ integrationName } ` ) ;
44+ return data ;
45+ }
46+
47+ async getIntegrations ( page = 1 , pageSize = 50 ) : Promise < GetIntegrationsResponse > {
48+ const { data } = await this . client . get < GetIntegrationsResponse > ( '/admin/integration' , {
49+ params : { page, pageSize } ,
50+ } ) ;
51+ return data ;
52+ }
53+
54+ async updateIntegration ( integrationName : string , payload : UpdateIntegrationPayload ) : Promise < void > {
2555 await this . client . put ( `/admin/integration/${ integrationName } ` , payload ) ;
2656 }
2757
28- async deleteIntegration ( integrationName : string , token : string ) {
58+ async deleteIntegration ( integrationName : string , token : string ) : Promise < void > {
2959 await this . client . delete ( `/admin/integration/${ integrationName } ` , { params : { token } } ) ;
3060 }
3161
32- async generateDeleteIntegrationToken ( integrationName : string ) {
33- const response = await this . client . get < GenereteDeleteTokenResponse > ( `/admin/integration/${ integrationName } /token` ) ;
34-
35- return response . data ;
62+ async generateDeleteIntegrationToken ( integrationName : string ) : Promise < GenereteDeleteTokenResponse > {
63+ const { data } = await this . client . get < GenereteDeleteTokenResponse > (
64+ `/admin/integration/${ integrationName } /token` ,
65+ ) ;
66+ return data ;
3667 }
3768
38- async getIntegrations ( ) {
39- const { data } = await this . client . get < Integration [ ] > ( '/admin/integrations' ) ;
69+ // ---------------------------------------------------------------------------
70+ // Bundles
71+ // ---------------------------------------------------------------------------
72+
73+ async getBundles ( integrationName : string ) : Promise < GetBundlesResponse > {
74+ const { data } = await this . client . get < GetBundlesResponse > ( `/admin/bundles/${ integrationName } ` ) ;
4075 return data ;
4176 }
4277
43- async getJobs ( integrationName : string ) {
44- const { data } = await this . client . get ( `/admin/jobs/status/${ integrationName } ` ) ;
78+ async uploadBundle ( integrationName : string , name : string , bundlePath : string ) : Promise < Bundle > {
79+ const fs = await platform . fs ( ) ;
80+ const FormData = await platform . form_data ( ) ;
81+
82+ const form = new FormData ( ) ;
83+ const bundle = fs . createReadStream ( bundlePath ) ;
84+
85+ form . append ( 'bundle' , bundle ) ;
86+ form . append ( 'name' , name ) ;
87+
88+ const { data } = await this . client . post < Bundle > ( `/admin/bundles/${ integrationName } ` , form , {
89+ headers : form . getHeaders ( ) ,
90+ } ) ;
4591 return data ;
4692 }
4793
48- async getStatus ( integrationName : string ) {
49- const { data } = await this . client . get ( `/admin/integration /${ integrationName } /provisionStatus ` ) ;
94+ async deployBundle ( integrationName : string , bundleName : string ) : Promise < Bundle > {
95+ const { data } = await this . client . post < Bundle > ( `/admin/bundles /${ integrationName } /deploy/ ${ bundleName } ` ) ;
5096 return data ;
5197 }
5298
53- async initializeQuery ( integrationName : string , query ?: string ) {
54- const { data } = await this . client . get < { queryId : string } > ( `/admin/logs/integration/${ integrationName } ?${ query } ` ) ;
99+ async downloadBundle ( integrationName : string , bundleName : string ) : Promise < Buffer > {
100+ const { data } = await this . client . get < Buffer > ( `/admin/bundles/${ integrationName } /download/${ bundleName } ` , {
101+ responseType : 'arraybuffer' ,
102+ } ) ;
55103 return data ;
56104 }
57105
58- async getLogs ( queryId : string , raw = true ) {
59- const { data } = await this . client . get ( ' /admin/logs/results' , { params : { queryId , raw } } ) ;
106+ async promoteBundle ( integrationName : string , version : number ) : Promise < Bundle > {
107+ const { data } = await this . client . post < Bundle > ( ` /admin/bundles/ ${ integrationName } /promote/ ${ version } ` ) ;
60108 return data ;
61109 }
62110
111+ // ---------------------------------------------------------------------------
112+ // Event Subscriptions
113+ // ---------------------------------------------------------------------------
114+
63115 async subscribe ( payload : SubscribePayload ) {
64116 const { data } = await this . client . post ( '/admin/events/subscriptions' , payload ) ;
65117 return data ;
@@ -70,11 +122,105 @@ export class ArcIFX extends ArcAbstractAPI {
70122 return data ;
71123 }
72124
73- async getSubscriptions ( ) {
125+ async getSubscriptions ( ) : Promise < GetSubscriptionsResponse > {
74126 const { data } = await this . client . get < GetSubscriptionsResponse > ( '/admin/events/subscriptions' ) ;
75127 return data ;
76128 }
77129
130+ // ---------------------------------------------------------------------------
131+ // Events
132+ // ---------------------------------------------------------------------------
133+
134+ async getEventPayload ( integrationName : string , invocationId : string ) : Promise < GetEventPayloadResponse > {
135+ const { data } = await this . client . get < GetEventPayloadResponse > (
136+ `/eventdata/${ integrationName } /${ invocationId } ` ,
137+ ) ;
138+ return data ;
139+ }
140+
141+ async getEventHistory (
142+ integrationName : string ,
143+ params ?: GetEventHistoryParams ,
144+ ) : Promise < GetEventHistoryResponse > {
145+ const { data } = await this . client . get < GetEventHistoryResponse > (
146+ `/admin/events/${ integrationName } /history` ,
147+ { params } ,
148+ ) ;
149+ return data ;
150+ }
151+
152+ // ---------------------------------------------------------------------------
153+ // Custom Events
154+ // ---------------------------------------------------------------------------
155+
156+ async getCustomEvents ( page = 1 , pageSize = 50 ) : Promise < GetCustomEventsResponse > {
157+ const { data } = await this . client . get < GetCustomEventsResponse > ( '/admin/events/custom' , {
158+ params : { page, pageSize } ,
159+ } ) ;
160+ return data ;
161+ }
162+
163+ async createCustomEvent ( payload : CustomEvent ) : Promise < CustomEvent > {
164+ const { data } = await this . client . post < CustomEvent > ( '/admin/events/custom' , payload ) ;
165+ return data ;
166+ }
167+
168+ async updateCustomEvent ( eventName : string , payload : CustomEventUpdatePayload ) : Promise < CustomEvent > {
169+ const { data } = await this . client . put < CustomEvent > ( `/admin/events/custom/${ eventName } ` , payload ) ;
170+ return data ;
171+ }
172+
173+ async deleteCustomEvent ( eventName : string ) : Promise < { message : string } > {
174+ const { data } = await this . client . delete < { message : string } > ( `/admin/events/custom/${ eventName } ` ) ;
175+ return data ;
176+ }
177+
178+ async deleteCustomEventSchedule ( eventName : string ) : Promise < { message : string } > {
179+ const { data } = await this . client . delete < { message : string } > (
180+ `/admin/events/custom/${ eventName } /schedule` ,
181+ ) ;
182+ return data ;
183+ }
184+
185+ // ---------------------------------------------------------------------------
186+ // Webhooks
187+ // ---------------------------------------------------------------------------
188+
189+ async getWebhooks ( page = 1 , pageSize = 50 ) : Promise < GetWebhooksResponse > {
190+ const { data } = await this . client . get < GetWebhooksResponse > ( '/admin/events/custom/webhooks' , {
191+ params : { page, pageSize } ,
192+ } ) ;
193+ return data ;
194+ }
195+
196+ async createWebhook ( eventName : string , payload ?: CreateWebhookPayload ) : Promise < Webhook > {
197+ const { data } = await this . client . post < Webhook > (
198+ `/admin/events/custom/${ eventName } /webhooks` ,
199+ payload ?? { } ,
200+ ) ;
201+ return data ;
202+ }
203+
204+ async updateWebhook ( eventName : string , payload : CreateWebhookPayload ) : Promise < Webhook > {
205+ const { data } = await this . client . put < Webhook > ( `/admin/events/custom/${ eventName } /webhooks` , payload ) ;
206+ return data ;
207+ }
208+
209+ async deleteWebhook ( eventName : string ) : Promise < { message : string } > {
210+ const { data } = await this . client . delete < { message : string } > (
211+ `/admin/events/custom/${ eventName } /webhooks` ,
212+ ) ;
213+ return data ;
214+ }
215+
216+ async triggerWebhook ( uuid : string , payload : TriggerWebhookPayload ) : Promise < void > {
217+ await this . client . post ( `/webhook/${ uuid } ` , payload ) ;
218+ }
219+
220+ // ---------------------------------------------------------------------------
221+ // Secrets
222+ // ---------------------------------------------------------------------------
223+
78224 async addSecret ( payload : AddSecretPayload ) {
79225 const { data } = await this . client . post ( `/admin/secret?integrationName=${ payload . integrationName } ` , {
80226 secretName : payload . secretName ,
@@ -83,42 +229,52 @@ export class ArcIFX extends ArcAbstractAPI {
83229 return data ;
84230 }
85231
86- async getSecrets ( integrationName : string ) {
87- const { data } = await this . client . get ( `/admin/secret?integrationName=${ integrationName } ` ) ;
232+ async updateSecret ( payload : AddSecretPayload ) {
233+ const { data } = await this . client . put ( `/admin/secret?integrationName=${ payload . integrationName } ` , {
234+ secretName : payload . secretName ,
235+ secretValue : payload . secretValue ,
236+ } ) ;
88237 return data ;
89238 }
90239
91- async getBundles ( integrationName : string ) {
92- const { data } = await this . client . get < GetBundlesResponse > ( `/admin/bundles/ ${ integrationName } ` ) ;
240+ async getSecrets ( integrationName : string ) : Promise < string [ ] > {
241+ const { data } = await this . client . get < string [ ] > ( `/admin/secret` , { params : { integrationName } } ) ;
93242 return data ;
94243 }
95244
96- async uploadBundle ( integrationName : string , name : string , bundlePath : string ) {
97- const fs = await platform . fs ( ) ;
98- const FormData = await platform . form_data ( ) ;
245+ // ---------------------------------------------------------------------------
246+ // Logs
247+ // ---------------------------------------------------------------------------
99248
100- const form = new FormData ( ) ;
101-
102- console . log ( 'platform' , platform ) ;
103- console . log ( form ) ;
104- const bundle = fs . createReadStream ( bundlePath ) ;
105-
106- form . append ( 'bundle' , bundle ) ;
107- form . append ( 'name' , name ) ;
249+ async initializeLogQuery (
250+ integrationName : string ,
251+ params ?: InitializeLogQueryParams ,
252+ ) : Promise < { queryId : string } > {
253+ const { data } = await this . client . get < { queryId : string } > (
254+ `/admin/logs/integration/${ integrationName } ` ,
255+ { params } ,
256+ ) ;
257+ return data ;
258+ }
108259
109- const { data } = await this . client . post < Bundle > ( `/admin/bundles/${ integrationName } ` , form , {
110- headers : form . getHeaders ( ) ,
260+ async getLogs ( queryId : string , raw = false ) : Promise < GetLogsResponse > {
261+ const { data } = await this . client . get < GetLogsResponse > ( '/admin/logs/results' , {
262+ params : { queryId, raw } ,
111263 } ) ;
112264 return data ;
113265 }
114266
115- async deployBundle ( integrationName : string , name : string ) {
116- const { data } = await this . client . post < Bundle > ( `/admin/bundles/${ integrationName } /deploy/${ name } ` ) ;
267+ async cancelLogQuery ( queryId : string ) : Promise < { message : string } > {
268+ const { data } = await this . client . delete < { message : string } > ( '/admin/logs/cancel' , {
269+ params : { queryId } ,
270+ } ) ;
117271 return data ;
118272 }
119273
120- async promoteBundle ( integrationName : string , version : number ) {
121- const { data } = await this . client . post < Bundle > ( `/admin/bundles/${ integrationName } /promote/${ version } ` ) ;
274+ async getLogQueries ( page ?: number , pageSize ?: number ) : Promise < GetLogQueriesResponse > {
275+ const { data } = await this . client . get < GetLogQueriesResponse > ( '/admin/logs/queries' , {
276+ params : { page, pageSize } ,
277+ } ) ;
122278 return data ;
123279 }
124280}
0 commit comments