@adobe/aio-cli-plugin-api-mesh 1.0.1-beta → 1.0.4-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,746 @@
1
+ /**
2
+ * Functions to support Dev Console operations
3
+ */
4
+ const axios = require('axios');
5
+
6
+ const logger = require('../classes/logger');
7
+ const { objToString } = require('../utils');
8
+ const CONSTANTS = require('../constants');
9
+
10
+ const { DEV_CONSOLE_TRANSPORTER_API_KEY } = CONSTANTS;
11
+
12
+ const { getDevConsoleConfig } = require('../helpers');
13
+
14
+ const getApiKeyCredential = async (organizationId, projectId, workspaceId) => {
15
+ const { baseUrl: devConsoleUrl, accessToken } = await getDevConsoleConfig();
16
+ const config = {
17
+ method: 'get',
18
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/credentials`,
19
+ headers: {
20
+ 'Authorization': `Bearer ${accessToken}`,
21
+ 'Content-Type': 'application/json',
22
+ 'x-request-id': global.requestId,
23
+ 'x-api-key': DEV_CONSOLE_TRANSPORTER_API_KEY, // API Key for Dev Console
24
+ },
25
+ };
26
+
27
+ logger.info(
28
+ 'Initiating GET %s',
29
+ `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/credentials`,
30
+ );
31
+
32
+ try {
33
+ const response = await axios(config);
34
+
35
+ logger.info('Response from GET %s', response.status);
36
+
37
+ if (response && response.status === 200) {
38
+ logger.info(`Credentials on the workspace : ${objToString(response, ['data'])}`);
39
+
40
+ if (response.data && Array.isArray(response.data) && response.data.length > 0) {
41
+ const apiCred = response.data.find(
42
+ credential =>
43
+ credential.integration_type === 'apikey' && credential.flow_type === 'adobeid',
44
+ );
45
+
46
+ logger.info(`API Key credential on the workspace : ${objToString(apiCred)}`);
47
+
48
+ if (apiCred) {
49
+ return apiCred;
50
+ } else {
51
+ logger.error('API Key credential not found on workspace');
52
+
53
+ return null;
54
+ }
55
+ } else {
56
+ return null;
57
+ }
58
+ } else {
59
+ // Non 200 response received
60
+ logger.error(
61
+ `Something went wrong: ${objToString(
62
+ response,
63
+ ['data'],
64
+ 'Unable to get credential',
65
+ )}. Received ${response.status} response instead of 200`,
66
+ );
67
+
68
+ throw new Error(
69
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to get credential')}`,
70
+ );
71
+ }
72
+ } catch (error) {
73
+ logger.error('Error while getting credential');
74
+ logger.error(error);
75
+
76
+ return null;
77
+ }
78
+ };
79
+
80
+ const describeMesh = async (organizationId, projectId, workspaceId) => {
81
+ logger.info('Initiating Describe Mesh');
82
+
83
+ try {
84
+ const meshId = await getMeshId(organizationId, projectId, workspaceId);
85
+
86
+ logger.info('Response from getMeshId %s', meshId);
87
+
88
+ if (meshId) {
89
+ const credential = await getApiKeyCredential(organizationId, projectId, workspaceId);
90
+
91
+ if (credential) {
92
+ return { meshId, apiKey: credential.client_id };
93
+ } else {
94
+ logger.error('API Key credential not found on workspace');
95
+
96
+ return { meshId, apiKey: null };
97
+ }
98
+ } else {
99
+ logger.error(`Unable to retrieve meshId.`);
100
+
101
+ throw new Error(`Unable to retrieve meshId.`);
102
+ }
103
+ } catch (error) {
104
+ logger.error(error);
105
+
106
+ return null;
107
+ }
108
+ };
109
+
110
+ const getMesh = async (organizationId, projectId, workspaceId, meshId) => {
111
+ const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
112
+ const config = {
113
+ method: 'get',
114
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${apiKey}`,
115
+ headers: {
116
+ 'Authorization': `Bearer ${accessToken}`,
117
+ 'x-request-id': global.requestId,
118
+ },
119
+ };
120
+
121
+ logger.info(
122
+ 'Initiating GET %s',
123
+ `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${apiKey}`,
124
+ );
125
+
126
+ try {
127
+ const response = await axios(config);
128
+
129
+ logger.info('Response from GET %s', response.status);
130
+
131
+ if (response && response.status === 200) {
132
+ logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
133
+
134
+ return response.data;
135
+ } else {
136
+ // Non 200 response received
137
+ logger.error(
138
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to get mesh')}. Received ${
139
+ response.status
140
+ } response instead of 200`,
141
+ );
142
+
143
+ throw new Error(
144
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to get mesh')}`,
145
+ );
146
+ }
147
+ } catch (error) {
148
+ logger.info('Response from GET %s', error.response.status);
149
+
150
+ if (error.response.status === 404) {
151
+ // The request was made and the server responded with a 404 status code
152
+ logger.error('Mesh not found');
153
+
154
+ return null;
155
+ } else if (error.response && error.response.data) {
156
+ // The request was made and the server responded with an unsupported status code
157
+ logger.error(
158
+ 'Error while getting mesh. Response: %s',
159
+ objToString(error, ['response', 'data'], 'Unable to get mesh'),
160
+ );
161
+
162
+ if (error.response.data.messages) {
163
+ const message = objToString(
164
+ error,
165
+ ['response', 'data', 'messages', '0', 'message'],
166
+ 'Unable to get mesh',
167
+ );
168
+
169
+ throw new Error(message);
170
+ } else if (error.response.data.message) {
171
+ const message = objToString(error, ['response', 'data', 'message'], 'Unable to get mesh');
172
+
173
+ throw new Error(message);
174
+ } else {
175
+ const message = objToString(error, ['response', 'data'], 'Unable to get mesh');
176
+
177
+ throw new Error(message);
178
+ }
179
+ } else {
180
+ // The request was made but no response was received
181
+ logger.error(
182
+ 'Error while getting mesh. No response received from the server: %s',
183
+ objToString(error, [], 'Unable to get mesh'),
184
+ );
185
+
186
+ throw new Error('Unable to get mesh from Schema Management Service: %s', error.message);
187
+ }
188
+ }
189
+ };
190
+
191
+ const createMesh = async (organizationId, projectId, workspaceId, data) => {
192
+ const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
193
+ const config = {
194
+ method: 'post',
195
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes?API_KEY=${apiKey}`,
196
+ headers: {
197
+ 'Authorization': `Bearer ${accessToken}`,
198
+ 'Content-Type': 'application/json',
199
+ 'x-request-id': global.requestId,
200
+ },
201
+ data: JSON.stringify(data),
202
+ };
203
+
204
+ logger.info(
205
+ 'Initiating POST %s',
206
+ `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes?API_KEY=${apiKey}`,
207
+ );
208
+
209
+ try {
210
+ const response = await axios(config);
211
+
212
+ logger.info('Response from POST %s', response.status);
213
+
214
+ if (response && response.status === 201) {
215
+ logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
216
+ return response.data;
217
+ } else {
218
+ // Non 201 response received
219
+ logger.error(
220
+ `Something went wrong: ${objToString(
221
+ response,
222
+ ['data'],
223
+ 'Unable to create mesh',
224
+ )}. Received ${response.status} response instead of 201`,
225
+ );
226
+
227
+ throw new Error(response.data.message);
228
+ }
229
+ } catch (error) {
230
+ if (error.response.status === 409) {
231
+ // The request was made and the server responded with a 409 status code
232
+ logger.error('Error while creating mesh: %j', error.response.data);
233
+
234
+ throw new Error('Selected org, project and workspace already has a mesh');
235
+ } else if (error.response && error.response.data) {
236
+ // The request was made and the server responded with an unsupported status code
237
+ logger.error(
238
+ 'Error while creating mesh. Response: %s',
239
+ objToString(error, ['response', 'data'], 'Unable to create mesh'),
240
+ );
241
+
242
+ if (error.response.data.messages) {
243
+ const message = objToString(
244
+ error,
245
+ ['response', 'data', 'messages'],
246
+ 'Unable to create mesh',
247
+ );
248
+
249
+ throw new Error(message);
250
+ } else if (error.response.data.message) {
251
+ const message = objToString(
252
+ error,
253
+ ['response', 'data', 'message'],
254
+ 'Unable to create mesh',
255
+ );
256
+
257
+ throw new Error(message);
258
+ } else {
259
+ const message = objToString(error, ['response', 'data'], 'Unable to create mesh');
260
+
261
+ throw new Error(message);
262
+ }
263
+ } else {
264
+ // The request was made but no response was received
265
+ logger.error(
266
+ 'Error while creating mesh. No response received from the server: %s',
267
+ objToString(error, [], 'Unable to create mesh'),
268
+ );
269
+
270
+ throw new Error('Unable to create mesh in Schema Management Service: %s', error.message);
271
+ }
272
+ }
273
+ };
274
+
275
+ const updateMesh = async (organizationId, projectId, workspaceId, meshId, data) => {
276
+ const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
277
+ const config = {
278
+ method: 'put',
279
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${apiKey}`,
280
+ headers: {
281
+ 'Authorization': `Bearer ${accessToken}`,
282
+ 'Content-Type': 'application/json',
283
+ 'x-request-id': global.requestId,
284
+ },
285
+ data: JSON.stringify(data),
286
+ };
287
+
288
+ logger.info(
289
+ 'Initiating PUT %s',
290
+ `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${apiKey}`,
291
+ );
292
+
293
+ try {
294
+ const response = await axios(config);
295
+
296
+ logger.info('Response from POST %s', response.status);
297
+
298
+ if (response && response.status === 204) {
299
+ return response.data;
300
+ } else {
301
+ // Non 204 response received
302
+ logger.error(
303
+ `Something went wrong: ${objToString(
304
+ response,
305
+ ['data'],
306
+ 'Unable to update mesh',
307
+ )}. Received ${response.status} response instead of 204`,
308
+ );
309
+
310
+ throw new Error(
311
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to update mesh')}`,
312
+ );
313
+ }
314
+ } catch (error) {
315
+ logger.info('Response from PUT %s', error.response.status);
316
+
317
+ if (error.response.status === 404) {
318
+ // The request was made and the server responded with a 404 status code
319
+ logger.error('Mesh not found');
320
+
321
+ throw new Error('Mesh not found');
322
+ } else if (error.response && error.response.data) {
323
+ // The request was made and the server responded with an unsupported status code
324
+ logger.error(
325
+ 'Error while updating mesh. Response: %s',
326
+ objToString(error, ['response', 'data'], 'Unable to update mesh'),
327
+ );
328
+
329
+ if (error.response.data.messages) {
330
+ const message = objToString(
331
+ error,
332
+ ['response', 'data', 'messages', '0', 'message'],
333
+ 'Unable to update mesh',
334
+ );
335
+
336
+ throw new Error(message);
337
+ } else if (error.response.data.message) {
338
+ const message = objToString(
339
+ error,
340
+ ['response', 'data', 'message'],
341
+ 'Unable to update mesh',
342
+ );
343
+
344
+ throw new Error(message);
345
+ } else {
346
+ const message = objToString(error, ['response', 'data'], 'Unable to update mesh');
347
+
348
+ throw new Error(message);
349
+ }
350
+ } else {
351
+ // The request was made but no response was received
352
+ logger.error(
353
+ 'Error while updating mesh. No response received from the server: %s',
354
+ objToString(error, [], 'Unable to update mesh'),
355
+ );
356
+
357
+ throw new Error('Unable to update mesh from Schema Management Service: %s', error.message);
358
+ }
359
+ }
360
+ };
361
+
362
+ const deleteMesh = async (organizationId, projectId, workspaceId, meshId) => {
363
+ const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
364
+ const config = {
365
+ method: 'delete',
366
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${apiKey}`,
367
+ headers: {
368
+ 'Authorization': `Bearer ${accessToken}`,
369
+ 'x-request-id': global.requestId,
370
+ },
371
+ };
372
+
373
+ logger.info(
374
+ 'Initiating DELETE %s',
375
+ `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${apiKey}`,
376
+ );
377
+
378
+ try {
379
+ const response = await axios(config);
380
+
381
+ logger.info('Response from DELETE %s', response.status);
382
+
383
+ if (response && response.status === 204) {
384
+ return response;
385
+ } else {
386
+ // Non 204 response received
387
+ logger.error(
388
+ `Something went wrong: ${objToString(
389
+ response,
390
+ ['data'],
391
+ 'Unable to delete mesh',
392
+ )}. Received ${response.status} response instead of 204`,
393
+ );
394
+
395
+ throw new Error(
396
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to delete mesh')}`,
397
+ );
398
+ }
399
+ } catch (error) {
400
+ logger.info('Response from DELETE %s', error.response.status);
401
+
402
+ if (error.response.status === 404) {
403
+ // The request was made and the server responded with a 404 status code
404
+ logger.error('Mesh not found');
405
+
406
+ throw new Error('Mesh not found');
407
+ } else if (error.response && error.response.data) {
408
+ // The request was made and the server responded with an unsupported status code
409
+ logger.error(
410
+ 'Error while deleting mesh. Response: %s',
411
+ objToString(error, ['response', 'data'], 'Unable to delete mesh'),
412
+ );
413
+
414
+ if (error.response.data.messages) {
415
+ const message = objToString(
416
+ error,
417
+ ['response', 'data', 'messages', '0', 'message'],
418
+ 'Unable to delete mesh',
419
+ );
420
+
421
+ throw new Error(message);
422
+ } else if (error.response.data.message) {
423
+ const message = objToString(
424
+ error,
425
+ ['response', 'data', 'message'],
426
+ 'Unable to delete mesh',
427
+ );
428
+
429
+ throw new Error(message);
430
+ } else {
431
+ const message = objToString(error, ['response', 'data'], 'Unable to delete mesh');
432
+
433
+ throw new Error(message);
434
+ }
435
+ } else {
436
+ // The request was made but no response was received
437
+ logger.error(
438
+ 'Error while deleting mesh. No response received from the server: %s',
439
+ objToString(error, [], 'Unable to delete mesh'),
440
+ );
441
+
442
+ throw new Error('Unable to delete mesh from Schema Management Service: %s', error.message);
443
+ }
444
+ }
445
+ };
446
+
447
+ const getMeshId = async (organizationId, projectId, workspaceId) => {
448
+ const { baseUrl: devConsoleUrl, accessToken, apiKey } = await getDevConsoleConfig();
449
+ logger.info('Initiating Mesh ID request');
450
+
451
+ const config = {
452
+ method: 'get',
453
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/describe?API_KEY=${apiKey}`,
454
+ headers: {
455
+ 'Authorization': `Bearer ${accessToken}`,
456
+ 'x-request-id': global.requestId,
457
+ },
458
+ };
459
+
460
+ logger.info(
461
+ 'Initiating GET %s',
462
+ `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/describe?API_KEY=${apiKey}`,
463
+ );
464
+
465
+ try {
466
+ const response = await axios(config);
467
+
468
+ logger.info('Response from GET %s', response.status);
469
+
470
+ if (response && response.status === 200) {
471
+ logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
472
+
473
+ return response.data.meshId;
474
+ } else {
475
+ // Non 200 response received
476
+ logger.error(
477
+ `Something went wrong: ${objToString(
478
+ response,
479
+ ['data'],
480
+ 'Unable to get mesh ID',
481
+ )}. Received ${response.status} response instead of 200`,
482
+ );
483
+
484
+ throw new Error(
485
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to get mesh')}`,
486
+ );
487
+ }
488
+ } catch (error) {
489
+ if (error.response.status === 400) {
490
+ // The request was made and the server responded with a 400 status code
491
+ logger.error('Mesh not found');
492
+ } else {
493
+ // The request was made and the server responded with a different status code
494
+ logger.error('Error while describing mesh');
495
+ }
496
+
497
+ return null;
498
+ }
499
+ };
500
+
501
+ const createAPIMeshCredentials = async (organizationId, projectId, workspaceId) => {
502
+ const { baseUrl: devConsoleUrl, accessToken } = await getDevConsoleConfig();
503
+ const input = {
504
+ name: `Project ${Date.now()}K`,
505
+ description: `Project ${Date.now()}K`,
506
+ platform: 'apiKey',
507
+ domain: 'www.graph.adobe.io',
508
+ };
509
+ const credentialConfig = {
510
+ method: 'post',
511
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/credentials/adobeId`,
512
+ headers: {
513
+ 'Authorization': `Bearer ${accessToken}`,
514
+ 'Content-Type': 'application/json',
515
+ 'x-request-id': global.requestId,
516
+ 'x-api-key': DEV_CONSOLE_TRANSPORTER_API_KEY,
517
+ },
518
+ data: JSON.stringify(input),
519
+ };
520
+ try {
521
+ const response = await axios(credentialConfig);
522
+ if (response && response.status === 200) {
523
+ logger.info(`API Key credential : ${objToString(response, ['data'])}`);
524
+
525
+ return response.data;
526
+ } else {
527
+ // Receive a non 200 response
528
+ logger.error(
529
+ `Something went wrong: ${objToString(
530
+ response,
531
+ ['data'],
532
+ 'Unable to create credential',
533
+ )}. Received ${response.status} response instead of 200`,
534
+ );
535
+
536
+ throw new Error(response.data.message);
537
+ }
538
+ } catch (error) {
539
+ logger.info('Response from Create Mesh Credential %s', error.response.status);
540
+ return null;
541
+ }
542
+ };
543
+
544
+ const getListOfCurrentServices = async (organizationId, credentialId) => {
545
+ const { baseUrl: devConsoleUrl, accessToken } = await getDevConsoleConfig();
546
+ try {
547
+ const config = {
548
+ method: 'get',
549
+ url: `${devConsoleUrl}/organizations/${organizationId}/integrations/${credentialId}`,
550
+ headers: {
551
+ 'Authorization': `Bearer ${accessToken}`,
552
+ 'Content-Type': 'application/json',
553
+ 'x-request-id': global.requestId,
554
+ 'x-api-key': DEV_CONSOLE_TRANSPORTER_API_KEY,
555
+ },
556
+ };
557
+
558
+ const response = await axios(config);
559
+
560
+ if (response && response.status === 200) {
561
+ logger.info(`List of current services: ${objToString(response, ['data'])}`);
562
+
563
+ return response.data.sdkList;
564
+ } else {
565
+ // Receive a non 200 response
566
+ logger.error(
567
+ `Something went wrong: ${objToString(
568
+ response,
569
+ ['data'],
570
+ 'Unable to get list of current services',
571
+ )}. Received ${response.status} response instead of 200`,
572
+ );
573
+
574
+ throw new Error(response.data.message);
575
+ }
576
+ } catch (err) {
577
+ logger.error(`Error while getting list of services: ${err}`);
578
+
579
+ return null;
580
+ }
581
+ };
582
+
583
+ const subscribeCredentialToServices = async (
584
+ organizationId,
585
+ projectId,
586
+ workspaceId,
587
+ credentialType,
588
+ credentialId,
589
+ services,
590
+ ) => {
591
+ try {
592
+ const { baseUrl: devConsoleUrl, accessToken } = await getDevConsoleConfig();
593
+
594
+ const input = services.map(service => ({
595
+ sdkCode: service,
596
+ }));
597
+
598
+ const subscribeCredentialToService = {
599
+ method: 'put',
600
+ url: `${devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/credentials/${credentialType}/${credentialId}/services`,
601
+ headers: {
602
+ 'Authorization': `Bearer ${accessToken}`,
603
+ 'Content-Type': 'application/json',
604
+ 'x-request-id': global.requestId,
605
+ 'x-api-key': DEV_CONSOLE_TRANSPORTER_API_KEY,
606
+ },
607
+ data: JSON.stringify(input),
608
+ };
609
+
610
+ const response = await axios(subscribeCredentialToService);
611
+
612
+ if (response && response.status === 200) {
613
+ logger.info(`SDK codes associated with credential : ${objToString(response, ['data'])}`);
614
+
615
+ return response.data.sdkList.map(({ service }) => service);
616
+ } else {
617
+ // Receive a non 200 response
618
+ logger.error(
619
+ `Something went wrong: ${objToString(
620
+ response,
621
+ ['data'],
622
+ 'Unable to create credential',
623
+ )}. Received ${response.status} response instead of 200`,
624
+ );
625
+
626
+ throw new Error(response.data.message);
627
+ }
628
+ } catch (err) {
629
+ logger.error(`Error while subscribing credential to services: ${err}`);
630
+
631
+ return null;
632
+ }
633
+ };
634
+
635
+ const subscribeCredentialToMeshService = async (
636
+ organizationId,
637
+ projectId,
638
+ workspaceId,
639
+ credentialId,
640
+ ) => {
641
+ const credentialType = 'adobeid';
642
+
643
+ try {
644
+ const currentListOfServices = await getListOfCurrentServices(organizationId, credentialId);
645
+
646
+ if (!currentListOfServices) {
647
+ throw new Error('Unable to get list of current services');
648
+ }
649
+
650
+ if (currentListOfServices.includes('GraphQLServiceSDK')) {
651
+ logger.info('Service is already subscribed');
652
+
653
+ return currentListOfServices;
654
+ }
655
+
656
+ const newListOfServices = [...currentListOfServices, 'GraphQLServiceSDK'];
657
+
658
+ const sdkList = await subscribeCredentialToServices(
659
+ organizationId,
660
+ projectId,
661
+ workspaceId,
662
+ credentialType,
663
+ credentialId,
664
+ newListOfServices,
665
+ );
666
+
667
+ logger.info(`Successfully subscribed credential to services: ${sdkList}`);
668
+
669
+ return sdkList;
670
+ } catch (error) {
671
+ logger.info('Response from subscribe credential %s', error.response);
672
+
673
+ if (error.response.status === 404) {
674
+ // The request was made and the server responded with a 404 status code
675
+ logger.error('Credential not found');
676
+ return [];
677
+ }
678
+
679
+ return null;
680
+ }
681
+ };
682
+
683
+ const unsubscribeCredentialFromMeshService = async (
684
+ organizationId,
685
+ projectId,
686
+ workspaceId,
687
+ credentialId,
688
+ ) => {
689
+ const credentialType = 'adobeid';
690
+
691
+ try {
692
+ const currentListOfServices = await getListOfCurrentServices(organizationId, credentialId);
693
+
694
+ if (!currentListOfServices) {
695
+ throw new Error('Unable to get list of current services');
696
+ }
697
+
698
+ if (!currentListOfServices.includes('GraphQLServiceSDK')) {
699
+ logger.info('Service is not subscribed');
700
+
701
+ return currentListOfServices;
702
+ }
703
+
704
+ const newListOfServices = currentListOfServices.filter(
705
+ service => service !== 'GraphQLServiceSDK',
706
+ );
707
+
708
+ const sdkList = await subscribeCredentialToServices(
709
+ organizationId,
710
+ projectId,
711
+ workspaceId,
712
+ credentialType,
713
+ credentialId,
714
+ newListOfServices,
715
+ );
716
+
717
+ logger.info(`Successfully unsubscribed credential to services: ${sdkList}`);
718
+
719
+ return sdkList;
720
+ } catch (error) {
721
+ logger.info('Response from unsubscribe credential %s', error.response);
722
+
723
+ if (error.response.status === 404) {
724
+ // The request was made and the server responded with a 404 status code
725
+ logger.error('Credential not found');
726
+ return [];
727
+ }
728
+
729
+ return null;
730
+ }
731
+ };
732
+
733
+ module.exports = {
734
+ getApiKeyCredential,
735
+ describeMesh,
736
+ getMesh,
737
+ createMesh,
738
+ updateMesh,
739
+ deleteMesh,
740
+ getMeshId,
741
+ createAPIMeshCredentials,
742
+ getListOfCurrentServices,
743
+ subscribeCredentialToServices,
744
+ subscribeCredentialToMeshService,
745
+ unsubscribeCredentialFromMeshService,
746
+ };