cliodot 1.2.3 → 1.2.4
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.
- package/LICENSE +201 -0
- package/README.md +2 -0
- package/dist/AuthAppClient.d.ts +1 -0
- package/dist/AuthAppClient.d.ts.map +1 -1
- package/dist/AuthAppClient.js +199 -1
- package/dist/CommercialAppClient.d.ts +50 -9
- package/dist/CommercialAppClient.d.ts.map +1 -1
- package/dist/CommercialAppClient.js +576 -1
- package/dist/ConnectorBuilder.js +104 -1
- package/dist/Events.d.ts +2 -0
- package/dist/Events.d.ts.map +1 -1
- package/dist/Events.js +325 -1
- package/dist/Flosync.js +296 -1
- package/dist/FlosyncClient.js +429 -1
- package/dist/FunctionBuilder.js +65 -1
- package/dist/IdentityAppClient.d.ts +1 -0
- package/dist/IdentityAppClient.d.ts.map +1 -1
- package/dist/IdentityAppClient.js +197 -1
- package/dist/MemoryAppClient.d.ts +1 -0
- package/dist/MemoryAppClient.d.ts.map +1 -1
- package/dist/MemoryAppClient.js +149 -1
- package/dist/MemoryClient.js +20 -1
- package/dist/OAuthAppClient.d.ts +1 -0
- package/dist/OAuthAppClient.d.ts.map +1 -1
- package/dist/OAuthAppClient.js +269 -1
- package/dist/ProviderServicesClient.d.ts +24 -0
- package/dist/ProviderServicesClient.d.ts.map +1 -0
- package/dist/ProviderServicesClient.js +158 -0
- package/dist/Surface.d.ts +2 -0
- package/dist/Surface.d.ts.map +1 -1
- package/dist/Surface.js +255 -1
- package/dist/ValidatorBuilder.js +24 -1
- package/dist/Webhooks.js +61 -1
- package/dist/WorkflowBuilder.js +279 -1
- package/dist/__tests__/CommercialAppClient.test.d.ts +2 -0
- package/dist/__tests__/CommercialAppClient.test.d.ts.map +1 -0
- package/dist/__tests__/CommercialAppClient.test.js +217 -0
- package/dist/__tests__/Events.test.js +191 -1
- package/dist/__tests__/IdentityAppClient.test.js +232 -1
- package/dist/__tests__/OAuthAppClient.test.js +300 -1
- package/dist/__tests__/ProviderServicesClient.test.d.ts +2 -0
- package/dist/__tests__/ProviderServicesClient.test.d.ts.map +1 -0
- package/dist/__tests__/ProviderServicesClient.test.js +131 -0
- package/dist/__tests__/Surface.test.js +150 -1
- package/dist/__tests__/errors.test.js +54 -1
- package/dist/__tests__/function.test.js +58 -1
- package/dist/__tests__/helpers.d.ts +5 -0
- package/dist/__tests__/helpers.d.ts.map +1 -0
- package/dist/__tests__/helpers.js +10 -0
- package/dist/__tests__/localhost-lookup.test.d.ts +2 -0
- package/dist/__tests__/localhost-lookup.test.d.ts.map +1 -0
- package/dist/__tests__/localhost-lookup.test.js +26 -0
- package/dist/__tests__/parse-api-error.test.js +26 -1
- package/dist/__tests__/runner.test.js +156 -1
- package/dist/connectors/builtin.js +354 -1
- package/dist/connectors/registry.js +300 -1
- package/dist/decorators/build.js +105 -1
- package/dist/decorators/connector.js +56 -1
- package/dist/decorators/index.js +34 -1
- package/dist/decorators/metadata.js +338 -1
- package/dist/decorators/steps.js +220 -1
- package/dist/decorators/workflow.js +52 -1
- package/dist/errors.js +76 -1
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-request.environment.test.js +37 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-result.test.js +57 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts +2 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts.map +1 -0
- package/dist/http/__tests__/events-instance-id.test.js +45 -0
- package/dist/http/cliodot-request.d.ts +35 -0
- package/dist/http/cliodot-request.d.ts.map +1 -0
- package/dist/http/cliodot-request.js +105 -0
- package/dist/http/cliodot-result.d.ts +40 -0
- package/dist/http/cliodot-result.d.ts.map +1 -0
- package/dist/http/cliodot-result.js +139 -0
- package/dist/http/create-client.d.ts +3 -0
- package/dist/http/create-client.d.ts.map +1 -0
- package/dist/http/create-client.js +14 -0
- package/dist/http/events-instance-id.d.ts +11 -0
- package/dist/http/events-instance-id.d.ts.map +1 -0
- package/dist/http/events-instance-id.js +86 -0
- package/dist/http/localhost-lookup.d.ts +12 -0
- package/dist/http/localhost-lookup.d.ts.map +1 -0
- package/dist/http/localhost-lookup.js +67 -0
- package/dist/http/parse-api-error.js +56 -1
- package/dist/http/sanitize-execution-headers.js +79 -1
- package/dist/identity-offline-verify.js +174 -1
- package/dist/identity-token-cache.js +51 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -1
- package/dist/runner/ProcessorEngine.js +1311 -1
- package/dist/runner/connector.executor.js +1786 -1
- package/dist/runner/utilities/math.executor.js +153 -1
- package/dist/runner/utilities/random.executor.js +151 -1
- package/dist/runner/utilities/string.executor.js +825 -1
- package/dist/template.js +127 -1
- package/dist/transformers/StepsToNodesTransformer.js +214 -1
- package/dist/transformers/WorkflowTransformer.js +189 -1
- package/dist/types/auth-app.api.d.ts +2 -0
- package/dist/types/auth-app.api.d.ts.map +1 -1
- package/dist/types/auth-app.api.js +2 -1
- package/dist/types/builtin.js +2 -1
- package/dist/types/client.api.js +2 -1
- package/dist/types/commercial-app.api.d.ts +407 -11
- package/dist/types/commercial-app.api.d.ts.map +1 -1
- package/dist/types/commercial-app.api.js +2 -1
- package/dist/types/connector.js +2 -1
- package/dist/types/context.js +2 -1
- package/dist/types/event-app.api.d.ts +8 -0
- package/dist/types/event-app.api.d.ts.map +1 -1
- package/dist/types/event-app.api.js +2 -1
- package/dist/types/function.js +2 -1
- package/dist/types/identity-app.api.d.ts +2 -0
- package/dist/types/identity-app.api.d.ts.map +1 -1
- package/dist/types/identity-app.api.js +2 -1
- package/dist/types/index.js +23 -1
- package/dist/types/memory-app.api.d.ts +2 -0
- package/dist/types/memory-app.api.d.ts.map +1 -1
- package/dist/types/memory-app.api.js +2 -1
- package/dist/types/oauth-app.api.d.ts +2 -0
- package/dist/types/oauth-app.api.d.ts.map +1 -1
- package/dist/types/oauth-app.api.js +105 -1
- package/dist/types/provider-services.api.d.ts +98 -0
- package/dist/types/provider-services.api.d.ts.map +1 -0
- package/dist/types/provider-services.api.js +2 -0
- package/dist/types/validator.js +2 -1
- package/dist/types/webhook-app.api.js +2 -1
- package/dist/types/workflow.js +33 -1
- package/dist/validators/validators.js +478 -1
- package/dist/variable.js +37 -1
- package/package.json +3 -2
package/dist/WorkflowBuilder.js
CHANGED
|
@@ -1 +1,279 @@
|
|
|
1
|
-
'use strict';const _0xa1635b=_0x231a;(function(_0x46d7ae,_0x596ded){const _0x68931b=_0x231a,_0x1080ab=_0x46d7ae();while(!![]){try{const _0x347539=-parseInt(_0x68931b(0xb9))/0x1*(parseInt(_0x68931b(0xbf))/0x2)+-parseInt(_0x68931b(0xa5))/0x3+parseInt(_0x68931b(0x86))/0x4+parseInt(_0x68931b(0xa4))/0x5*(parseInt(_0x68931b(0x95))/0x6)+-parseInt(_0x68931b(0x91))/0x7*(parseInt(_0x68931b(0x7b))/0x8)+-parseInt(_0x68931b(0x9f))/0x9*(-parseInt(_0x68931b(0x96))/0xa)+parseInt(_0x68931b(0x9c))/0xb;if(_0x347539===_0x596ded)break;else _0x1080ab['push'](_0x1080ab['shift']());}catch(_0x368f65){_0x1080ab['push'](_0x1080ab['shift']());}}}(_0x3a50,0xd6c9e));Object[_0xa1635b(0x90)](exports,'__esModule',{'value':!![]}),exports['WorkflowBuilder']=exports[_0xa1635b(0x83)]=void 0x0;const workflow_1=require(_0xa1635b(0x99)),metadata_1=require('./decorators/metadata'),registry_1=require(_0xa1635b(0xb8));function createStepResult(_0x150a0a){return{'step':_0x150a0a,'then'(_0x24cb09){const _0x2d44df=_0x231a;return this[_0x2d44df(0x8a)][_0x2d44df(0x75)]=_0x24cb09[_0x2d44df(0x84)](/[.\-\s]/g,'_'),this;},'else'(_0x26f970){const _0x5c5dbc=_0x231a;return this[_0x5c5dbc(0x8a)][_0x5c5dbc(0xaf)]=_0x26f970['replace'](/[.\-\s]/g,'_'),this;}};}class StepBuilder{[_0xa1635b(0xac)](_0x22b2a4,_0xcbfb4d,_0x123ddf){const _0x43dfd1=_0xa1635b,_0x47ac8a=_0x123ddf??{};let _0x5ce3b,_0x1b4387;if((0x0,registry_1[_0x43dfd1(0x9d)])(_0x22b2a4)){_0x5ce3b=_0x22b2a4['id'];const _0x47f31a=_0xcbfb4d,_0x164ef7=_0x22b2a4[_0x43dfd1(0xa8)][_0x47f31a];if(typeof _0x164ef7!=='string')throw new Error(_0x43dfd1(0xbd)+_0x5ce3b+':\x20'+String(_0xcbfb4d));_0x1b4387=_0x164ef7;}else _0x5ce3b=_0x22b2a4,_0x1b4387=_0xcbfb4d;const _0x34a231=(0x0,metadata_1[_0x43dfd1(0x92)])('',_0x5ce3b,_0x1b4387,_0x47ac8a);return createStepResult(_0x34a231);}['db'](_0x123f6a,_0x412179,_0x29c94d){const _0x272654=_0xa1635b,_0xd1e8f4=_0x123f6a===_0x272654(0x79)?'mongodb.system':_0x272654(0xae),_0x251a90={'id':'','type':workflow_1[_0x272654(0xab)]['DB'],'connector_id':_0xd1e8f4,'action':_0x412179,'body':_0x29c94d,'params':_0x29c94d[_0x272654(0x80)]};if(_0x29c94d['connection_id'])_0x251a90[_0x272654(0x97)]=_0x29c94d[_0x272654(0x97)];if(_0x29c94d[_0x272654(0x7d)])_0x251a90['database']=_0x29c94d[_0x272654(0x7d)];return createStepResult(_0x251a90);}[_0xa1635b(0xb5)](_0x45d776){const _0x24a196=_0xa1635b;let _0x226ffb;Array[_0x24a196(0xb4)](_0x45d776)?_0x226ffb=_0x45d776:_0x226ffb=[{'fields':Object[_0x24a196(0xa9)](_0x45d776),'validators':Object[_0x24a196(0xb1)](_0x45d776)[_0x24a196(0x81)](()=>({'name':_0x24a196(0xbe),'config':{}}))}];const _0x227b69={'id':'','type':workflow_1[_0x24a196(0xab)][_0x24a196(0x74)],'validationGroups':_0x226ffb};return createStepResult(_0x227b69);}['condition'](_0x3c2877){const _0x4f7521=_0xa1635b,_0x4fd984={'id':'','type':workflow_1[_0x4f7521(0xab)]['CONDITION'],'mode':_0x4f7521(0xa2),'if':_0x3c2877};return createStepResult(_0x4fd984);}[_0xa1635b(0x7e)](_0x73f928,_0x4d7776,_0x42151a){const _0x4f8d06=_0xa1635b,_0x2266c2={'id':'','type':workflow_1[_0x4f8d06(0xab)][_0x4f8d06(0x94)],'over':_0x73f928,'as':_0x42151a?.['as']??'item','index_as':_0x42151a?.[_0x4f8d06(0x70)]??_0x4f8d06(0x9e),'steps':_0x4d7776,'max_iterations':_0x42151a?.[_0x4f8d06(0x8c)]??0x3e8};return createStepResult(_0x2266c2);}[_0xa1635b(0x7f)](_0x381593,_0x1d6778,_0x20f423,_0x17b2be){const _0x1018a7=_0xa1635b,_0x4a9cc5=!_0x1d6778&&!_0x381593['includes'](_0x1018a7(0xb6))&&!_0x381593[_0x1018a7(0x7a)]('{{'),_0x124b83={'id':'','type':workflow_1['WorkflowStepType'][_0x1018a7(0xa0)],..._0x4a9cc5?{'module_ref':_0x381593,'fn':_0x1d6778||_0x1018a7(0xa3),'args':_0x20f423||{}}:{'source':_0x381593,'args':_0x20f423||{}},'input_from':_0x17b2be?.[_0x1018a7(0xa6)],'timeout':_0x17b2be?.[_0x1018a7(0x77)]??0x3e8};return createStepResult(_0x124b83);}[_0xa1635b(0x88)](_0x3bb192,_0x1243ac){const _0x1555f6=_0xa1635b,_0x41a55e={'id':'','type':workflow_1[_0x1555f6(0xab)][_0x1555f6(0xa7)],'function_id':_0x3bb192,'function_slug':_0x3bb192,'args':_0x1243ac};return createStepResult(_0x41a55e);}[_0xa1635b(0xbc)](_0x4e1fcb,_0x4636c0){const _0xea2de2=_0xa1635b,_0x1c4c9e={'id':'','type':workflow_1[_0xea2de2(0xab)]['CALL_WORKFLOW'],'workflow_id':_0x4e1fcb,'payload':_0x4636c0??{}};return createStepResult(_0x1c4c9e);}[_0xa1635b(0x93)](_0x4b21bb,_0xa15ed7,_0x6d3634){const _0x30b909=_0xa1635b,_0x50dd79={'id':'','type':workflow_1[_0x30b909(0xab)]['AUTHENTICATION'],'connector_id':_0x4b21bb,'action':_0xa15ed7,'params':_0x6d3634,'body':_0x6d3634};return createStepResult(_0x50dd79);}[_0xa1635b(0x78)](_0x393ad3,_0x3e7c49,_0x5a10e3){const _0x4ad7e9=_0xa1635b;return this[_0x4ad7e9(0xac)](_0x393ad3,_0x3e7c49,_0x5a10e3);}['transform'](_0x3e8ac9){const _0x4952e8=_0xa1635b,_0xc855bb=!Array['isArray'](_0x3e8ac9),_0x10275d={'id':'','type':workflow_1[_0x4952e8(0xab)]['TRANSFORM'],..._0xc855bb?{'mapping':_0x3e8ac9}:{'operations':_0x3e8ac9}};return createStepResult(_0x10275d);}[_0xa1635b(0xb0)](_0x3e76b8,_0x557627,_0x471f40){const _0x26a9b9=_0xa1635b,_0x4da81c={'id':'','type':workflow_1[_0x26a9b9(0xab)][_0x26a9b9(0x73)],'connector_id':_0x3e76b8,'action':_0x557627,'params':_0x471f40,'body':_0x471f40};return createStepResult(_0x4da81c);}[_0xa1635b(0x89)](_0x26e5a2,_0x1e11fc){const _0x1847c5=_0xa1635b,_0x46b5a4={'id':'','type':workflow_1['WorkflowStepType']['RESPONDER'],'responder':_0x26e5a2,'config':{'statusCode':_0x1e11fc[_0x1847c5(0x8f)]??0xc8,'headers':_0x1e11fc[_0x1847c5(0x7c)],'body':_0x1e11fc[_0x1847c5(0x85)],'contentType':_0x1e11fc['contentType'],'location':_0x1e11fc[_0x1847c5(0xa1)]}};return createStepResult(_0x46b5a4);}[_0xa1635b(0x76)](_0x482758){const _0x24fa3c=_0xa1635b,_0x19fee3={'id':'','type':workflow_1[_0x24fa3c(0xab)]['LOG'],'message':_0x482758};return createStepResult(_0x19fee3);}[_0xa1635b(0xb7)](_0x3352fc){const _0x13fdc8=_0xa1635b,_0x2bb0d6={'id':'','type':workflow_1[_0x13fdc8(0xab)]['DELAY'],'ms':_0x3352fc};return createStepResult(_0x2bb0d6);}['notify'](_0x4b65fa,_0x45badc){const _0x2362bf=_0xa1635b,_0x427bcc={'id':'','type':workflow_1[_0x2362bf(0xab)]['NOTIFY'],'channel':_0x4b65fa,'message':_0x45badc};return createStepResult(_0x427bcc);}}exports[_0xa1635b(0x83)]=StepBuilder;function sanitizeStepId(_0x5314bb){return _0x5314bb['replace'](/[.\-\s]/g,'_');}function _0x231a(_0x176a07,_0x1c786e){_0x176a07=_0x176a07-0x70;const _0x3a50b2=_0x3a50();let _0x231ade=_0x3a50b2[_0x176a07];if(_0x231a['uToFVT']===undefined){var _0x1b393d=function(_0x31d0a0){const _0x3415f8='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x150a0a='',_0x24cb09='';for(let _0x26f970=0x0,_0x22b2a4,_0xcbfb4d,_0x123ddf=0x0;_0xcbfb4d=_0x31d0a0['charAt'](_0x123ddf++);~_0xcbfb4d&&(_0x22b2a4=_0x26f970%0x4?_0x22b2a4*0x40+_0xcbfb4d:_0xcbfb4d,_0x26f970++%0x4)?_0x150a0a+=String['fromCharCode'](0xff&_0x22b2a4>>(-0x2*_0x26f970&0x6)):0x0){_0xcbfb4d=_0x3415f8['indexOf'](_0xcbfb4d);}for(let _0x47ac8a=0x0,_0x5ce3b=_0x150a0a['length'];_0x47ac8a<_0x5ce3b;_0x47ac8a++){_0x24cb09+='%'+('00'+_0x150a0a['charCodeAt'](_0x47ac8a)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x24cb09);};_0x231a['yMbJrn']=_0x1b393d,_0x231a['wyFzoC']={},_0x231a['uToFVT']=!![];}const _0x5c013b=_0x3a50b2[0x0],_0x2ccea8=_0x176a07+_0x5c013b,_0x2bb413=_0x231a['wyFzoC'][_0x2ccea8];return!_0x2bb413?(_0x231ade=_0x231a['yMbJrn'](_0x231ade),_0x231a['wyFzoC'][_0x2ccea8]=_0x231ade):_0x231ade=_0x2bb413,_0x231ade;}function _0x3a50(){const _0x3a3cf2=['ywn0Aw9UCW','DMfSDwvZ','sfruua','v29YA2zSB3DtDgvWvhLWzq','y29UBMvJDg9Y','DhjPz2DLCG','BxLZCwWUC3LZDgvT','zwXZzq','zw5JCNLWDa','zw50CMLLCW','C2nOzwr1Bgu','Ahr0Ca','AxnbCNjHEq','DMfSAwrHDg9Y','CMv0DxjU','zgvSyxK','lI9JB25Uzwn0B3jZl3jLz2LZDhj5','mtq4nte0nvLvBfblza','D29YA2zSB3Doyw1L','yNvPBgq','y2fSBfDVCMTMBg93','vw5RBM93BIbHy3rPB24GA2v5ig9UignVBM5Ly3rVCIa','CMvXDwLYzwq','mNvNCezRzq','Aw5KzxHFyxm','v29YA2zSB3DuCMLNz2vYvhLWzq','C3rLCe9YzgvY','ru5duLLqveLptG','vKfmsurbve9s','DgHLBG','Bg9N','DgLTzw91Da','DxrPBa','Bw9Uz29KyG','Aw5JBhvKzxm','mZq0D2P6AfbK','AgvHzgvYCW','zgf0ywjHC2u','Bg9VCa','y29Kzq','CgfYyw1Z','BwfW','ChvZAa','u3rLCej1AwXKzxi','CMvWBgfJzq','yM9KEq','mJuYnti3nKzwrvHoyq','igrPzcbUB3qGChjVzhvJzsbHihzHBgLKihn0zxa','y2fSBa','CMvZCg9UzgvY','C3rLCa','AM9I','Bwf4x2L0zxjHDgLVBNm','ywn0AxzL','C3rLChm','C3rHDhvZq29Kzq','zgvMAw5LuhjVCgvYDhK','mJm4mZC4zgTPzwjn','BwfRzunVBM5Ly3rVCLn0zxa','yxv0Aa','te9pua','mZCYCLvIAwj4','mtbLvMTnsvO','y29UBMvJDgLVBL9Pza','D2vIAg9VA01LDgHVza','lI90ExbLCY93B3jRzMXVDW','D29YA2zSB3Djza','sK9c','mJaYmJu1otbuzfnhzMq','AxnuExbLzenVBM5Ly3rVCKrLzG','Aw5KzxG','mta4nZi2mJftCeDlt1G','q09erq','Bg9JyxrPB24','AMv4Ba','zxHLy3v0zq','nti2nZvjzMrbwMe','mtuWnJaYmxDlzKnjBq','Aw5WDxrFzNjVBq','rLvoq1rjt04'];_0x3a50=function(){return _0x3a3cf2;};return _0x3a50();}class WorkflowBuilder{constructor(_0x4d2af2,_0x182e01){const _0x285f0d=_0xa1635b;this[_0x285f0d(0xad)]={'type':workflow_1[_0x285f0d(0x71)]['MANUAL']},this[_0x285f0d(0x8e)]=[],this[_0x285f0d(0x72)]=[],this[_0x285f0d(0x9a)]=_0x4d2af2,this[_0x285f0d(0xba)]=_0x182e01||_0x4d2af2;}[_0xa1635b(0xb3)](_0x5013bc,_0x72e9db){const _0x3c9925=_0xa1635b;return this[_0x3c9925(0xad)]={'type':workflow_1[_0x3c9925(0x71)][_0x3c9925(0xaa)],'webhook_url':_0x72e9db},this['trigger'][_0x3c9925(0x98)]=_0x5013bc,this;}['webhook'](_0x2f7ebd,_0x3d4503){return this['http'](_0x2f7ebd,_0x3d4503);}[_0xa1635b(0x8b)](_0x5e6ab1,_0xe9c28d){const _0x376482=_0xa1635b;return this[_0x376482(0xad)]={'type':workflow_1[_0x376482(0x71)][_0x376482(0x9b)],'cron':_0x5e6ab1??'*\x20*\x20*\x20*\x20*','timezone':_0xe9c28d},this;}[_0xa1635b(0xb2)](_0x439a82,_0x5d62b6){const _0x1d89e8=_0xa1635b;return this[_0x1d89e8(0xad)]={'type':workflow_1[_0x1d89e8(0x71)]['SCHEDULE'],'cron':_0x439a82,'timezone':_0x5d62b6},this;}[_0xa1635b(0x8a)](_0x410c3c,_0x24cd13){const _0x1f6427=_0xa1635b,_0x2e5c59=new StepBuilder(),_0x4edc00=_0x24cd13(_0x2e5c59),_0x141100=_0x4edc00[_0x1f6427(0x8a)]!==undefined?_0x4edc00[_0x1f6427(0x8a)]:_0x4edc00;if(!_0x141100||typeof _0x141100!=='object')throw new Error('Step\x20'+_0x410c3c+_0x1f6427(0x87));const _0x636aef=sanitizeStepId(_0x410c3c),_0x46352c={..._0x141100,'id':_0x636aef};return this[_0x1f6427(0x8e)][_0x1f6427(0x82)](_0x46352c),this[_0x1f6427(0x72)][_0x1f6427(0x82)](_0x410c3c),this;}[_0xa1635b(0xbb)](){const _0x3a55b0=_0xa1635b,_0xf65958=[];for(let _0x435ab7=0x0;_0x435ab7<this[_0x3a55b0(0x8e)]['length'];_0x435ab7++){const _0x44ceef={...this[_0x3a55b0(0x8e)][_0x435ab7]};_0x435ab7>0x0&&(_0x44ceef['input_from']=sanitizeStepId(this[_0x3a55b0(0x72)][_0x435ab7-0x1])),_0xf65958[_0x3a55b0(0x82)](_0x44ceef);}return{'_id':sanitizeStepId(this['workflowId']),'name':this[_0x3a55b0(0xba)],'trigger':this['trigger'],'steps':_0xf65958,'status':_0x3a55b0(0x8d)};}}exports['WorkflowBuilder']=WorkflowBuilder;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowBuilder = exports.StepBuilder = void 0;
|
|
4
|
+
const workflow_1 = require("./types/workflow");
|
|
5
|
+
const metadata_1 = require("./decorators/metadata");
|
|
6
|
+
const registry_1 = require("./connectors/registry");
|
|
7
|
+
function createStepResult(step) {
|
|
8
|
+
return {
|
|
9
|
+
step,
|
|
10
|
+
then(stepId) {
|
|
11
|
+
this.step.then = stepId.replace(/[.\-\s]/g, "_");
|
|
12
|
+
return this;
|
|
13
|
+
},
|
|
14
|
+
else(stepId) {
|
|
15
|
+
this.step.else = stepId.replace(/[.\-\s]/g, "_");
|
|
16
|
+
return this;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
class StepBuilder {
|
|
21
|
+
connector(connectorIdOrDef, actionOrKey, config) {
|
|
22
|
+
const resolved = (config ?? {});
|
|
23
|
+
let connectorId;
|
|
24
|
+
let action;
|
|
25
|
+
if ((0, registry_1.isTypedConnectorDef)(connectorIdOrDef)) {
|
|
26
|
+
connectorId = connectorIdOrDef.id;
|
|
27
|
+
const key = actionOrKey;
|
|
28
|
+
const mapped = connectorIdOrDef.actions[key];
|
|
29
|
+
if (typeof mapped !== "string") {
|
|
30
|
+
throw new Error(`Unknown action key on connector ${connectorId}: ${String(actionOrKey)}`);
|
|
31
|
+
}
|
|
32
|
+
action = mapped;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
connectorId = connectorIdOrDef;
|
|
36
|
+
action = actionOrKey;
|
|
37
|
+
}
|
|
38
|
+
const step = (0, metadata_1.makeConnectorStep)("", connectorId, action, resolved);
|
|
39
|
+
return createStepResult(step);
|
|
40
|
+
}
|
|
41
|
+
db(engine, action, config) {
|
|
42
|
+
const connectorId = engine === "mongodb" ? "mongodb.system" : "mysql.system";
|
|
43
|
+
const step = {
|
|
44
|
+
id: "",
|
|
45
|
+
type: workflow_1.WorkflowStepType.DB,
|
|
46
|
+
connector_id: connectorId,
|
|
47
|
+
action,
|
|
48
|
+
body: config,
|
|
49
|
+
params: config.params,
|
|
50
|
+
};
|
|
51
|
+
if (config.connection_id)
|
|
52
|
+
step.connection_id = config.connection_id;
|
|
53
|
+
if (config.database)
|
|
54
|
+
step.database = config.database;
|
|
55
|
+
return createStepResult(step);
|
|
56
|
+
}
|
|
57
|
+
validator(fieldsOrGroups) {
|
|
58
|
+
let validationGroups;
|
|
59
|
+
if (Array.isArray(fieldsOrGroups)) {
|
|
60
|
+
validationGroups = fieldsOrGroups;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
validationGroups = [
|
|
64
|
+
{
|
|
65
|
+
fields: Object.values(fieldsOrGroups),
|
|
66
|
+
validators: Object.entries(fieldsOrGroups).map(() => ({ name: "required", config: {} })),
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
const step = {
|
|
71
|
+
id: "",
|
|
72
|
+
type: workflow_1.WorkflowStepType.VALIDATOR,
|
|
73
|
+
validationGroups,
|
|
74
|
+
};
|
|
75
|
+
return createStepResult(step);
|
|
76
|
+
}
|
|
77
|
+
condition(expr) {
|
|
78
|
+
const step = {
|
|
79
|
+
id: "",
|
|
80
|
+
type: workflow_1.WorkflowStepType.CONDITION,
|
|
81
|
+
mode: "jexl",
|
|
82
|
+
if: expr,
|
|
83
|
+
};
|
|
84
|
+
return createStepResult(step);
|
|
85
|
+
}
|
|
86
|
+
loop(over, steps, config) {
|
|
87
|
+
const step = {
|
|
88
|
+
id: "",
|
|
89
|
+
type: workflow_1.WorkflowStepType.LOOP,
|
|
90
|
+
over,
|
|
91
|
+
as: config?.as ?? "item",
|
|
92
|
+
index_as: config?.index_as ?? "index",
|
|
93
|
+
steps,
|
|
94
|
+
max_iterations: config?.max_iterations ?? 1000,
|
|
95
|
+
};
|
|
96
|
+
return createStepResult(step);
|
|
97
|
+
}
|
|
98
|
+
code(sourceOrModule, fn, args, config) {
|
|
99
|
+
const isModule = !fn && !sourceOrModule.includes("return") && !sourceOrModule.includes("{{");
|
|
100
|
+
const step = {
|
|
101
|
+
id: "",
|
|
102
|
+
type: workflow_1.WorkflowStepType.CODE,
|
|
103
|
+
...(isModule
|
|
104
|
+
? { module_ref: sourceOrModule, fn: fn || "execute", args: args || {} }
|
|
105
|
+
: { source: sourceOrModule, args: args || {} }),
|
|
106
|
+
input_from: config?.input_from,
|
|
107
|
+
timeout: config?.timeout ?? 1000,
|
|
108
|
+
};
|
|
109
|
+
return createStepResult(step);
|
|
110
|
+
}
|
|
111
|
+
call(functionSlugOrId, args) {
|
|
112
|
+
const step = {
|
|
113
|
+
id: "",
|
|
114
|
+
type: workflow_1.WorkflowStepType.FUNCTION,
|
|
115
|
+
function_id: functionSlugOrId,
|
|
116
|
+
function_slug: functionSlugOrId,
|
|
117
|
+
args,
|
|
118
|
+
};
|
|
119
|
+
return createStepResult(step);
|
|
120
|
+
}
|
|
121
|
+
callWorkflow(workflowId, payload) {
|
|
122
|
+
const step = {
|
|
123
|
+
id: "",
|
|
124
|
+
type: workflow_1.WorkflowStepType.CALL_WORKFLOW,
|
|
125
|
+
workflow_id: workflowId,
|
|
126
|
+
payload: payload ?? {},
|
|
127
|
+
};
|
|
128
|
+
return createStepResult(step);
|
|
129
|
+
}
|
|
130
|
+
auth(connectorId, action, config) {
|
|
131
|
+
const step = {
|
|
132
|
+
id: "",
|
|
133
|
+
type: workflow_1.WorkflowStepType.AUTHENTICATION,
|
|
134
|
+
connector_id: connectorId,
|
|
135
|
+
action,
|
|
136
|
+
params: config,
|
|
137
|
+
body: config,
|
|
138
|
+
};
|
|
139
|
+
return createStepResult(step);
|
|
140
|
+
}
|
|
141
|
+
util(connectorId, action, config) {
|
|
142
|
+
return this.connector(connectorId, action, config);
|
|
143
|
+
}
|
|
144
|
+
transform(mappingOrOperations) {
|
|
145
|
+
const isMapping = !Array.isArray(mappingOrOperations);
|
|
146
|
+
const step = {
|
|
147
|
+
id: "",
|
|
148
|
+
type: workflow_1.WorkflowStepType.TRANSFORM,
|
|
149
|
+
...(isMapping
|
|
150
|
+
? { mapping: mappingOrOperations }
|
|
151
|
+
: { operations: mappingOrOperations }),
|
|
152
|
+
};
|
|
153
|
+
return createStepResult(step);
|
|
154
|
+
}
|
|
155
|
+
encrypt(connectorId, action, config) {
|
|
156
|
+
const step = {
|
|
157
|
+
id: "",
|
|
158
|
+
type: workflow_1.WorkflowStepType.ENCRYPTION,
|
|
159
|
+
connector_id: connectorId,
|
|
160
|
+
action,
|
|
161
|
+
params: config,
|
|
162
|
+
body: config,
|
|
163
|
+
};
|
|
164
|
+
return createStepResult(step);
|
|
165
|
+
}
|
|
166
|
+
responder(type, config) {
|
|
167
|
+
const step = {
|
|
168
|
+
id: "",
|
|
169
|
+
type: workflow_1.WorkflowStepType.RESPONDER,
|
|
170
|
+
responder: type,
|
|
171
|
+
config: {
|
|
172
|
+
statusCode: config.statusCode ?? 200,
|
|
173
|
+
headers: config.headers,
|
|
174
|
+
body: config.body,
|
|
175
|
+
contentType: config.contentType,
|
|
176
|
+
location: config.location,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
return createStepResult(step);
|
|
180
|
+
}
|
|
181
|
+
log(message) {
|
|
182
|
+
const step = {
|
|
183
|
+
id: "",
|
|
184
|
+
type: workflow_1.WorkflowStepType.LOG,
|
|
185
|
+
message,
|
|
186
|
+
};
|
|
187
|
+
return createStepResult(step);
|
|
188
|
+
}
|
|
189
|
+
delay(ms) {
|
|
190
|
+
const step = {
|
|
191
|
+
id: "",
|
|
192
|
+
type: workflow_1.WorkflowStepType.DELAY,
|
|
193
|
+
ms,
|
|
194
|
+
};
|
|
195
|
+
return createStepResult(step);
|
|
196
|
+
}
|
|
197
|
+
notify(channel, message) {
|
|
198
|
+
const step = {
|
|
199
|
+
id: "",
|
|
200
|
+
type: workflow_1.WorkflowStepType.NOTIFY,
|
|
201
|
+
channel,
|
|
202
|
+
message,
|
|
203
|
+
};
|
|
204
|
+
return createStepResult(step);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.StepBuilder = StepBuilder;
|
|
208
|
+
function sanitizeStepId(id) {
|
|
209
|
+
return id.replace(/[.\-\s]/g, "_");
|
|
210
|
+
}
|
|
211
|
+
class WorkflowBuilder {
|
|
212
|
+
constructor(workflowId, workflowName) {
|
|
213
|
+
this.trigger = { type: workflow_1.WorkflowTriggerType.MANUAL };
|
|
214
|
+
this.steps = [];
|
|
215
|
+
this.stepOrder = [];
|
|
216
|
+
this.workflowId = workflowId;
|
|
217
|
+
this.workflowName = workflowName || workflowId;
|
|
218
|
+
}
|
|
219
|
+
http(method, path) {
|
|
220
|
+
this.trigger = {
|
|
221
|
+
type: workflow_1.WorkflowTriggerType.HTTP,
|
|
222
|
+
webhook_url: path,
|
|
223
|
+
};
|
|
224
|
+
this.trigger.webhookMethod = method;
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
webhook(method, path) {
|
|
228
|
+
return this.http(method, path);
|
|
229
|
+
}
|
|
230
|
+
job(cron, timezone) {
|
|
231
|
+
this.trigger = {
|
|
232
|
+
type: workflow_1.WorkflowTriggerType.JOB,
|
|
233
|
+
cron: cron ?? "* * * * *",
|
|
234
|
+
timezone,
|
|
235
|
+
};
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
schedule(cron, timezone) {
|
|
239
|
+
this.trigger = {
|
|
240
|
+
type: workflow_1.WorkflowTriggerType.SCHEDULE,
|
|
241
|
+
cron,
|
|
242
|
+
timezone,
|
|
243
|
+
};
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
step(stepId, fn) {
|
|
247
|
+
const s = new StepBuilder();
|
|
248
|
+
const result = fn(s);
|
|
249
|
+
const rawStep = result.step !== undefined ? result.step : result;
|
|
250
|
+
if (!rawStep || typeof rawStep !== "object")
|
|
251
|
+
throw new Error(`Step ${stepId} did not produce a valid step`);
|
|
252
|
+
const sanitizedId = sanitizeStepId(stepId);
|
|
253
|
+
const fullStep = {
|
|
254
|
+
...rawStep,
|
|
255
|
+
id: sanitizedId,
|
|
256
|
+
};
|
|
257
|
+
this.steps.push(fullStep);
|
|
258
|
+
this.stepOrder.push(stepId);
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
build() {
|
|
262
|
+
const stepsWithInputFrom = [];
|
|
263
|
+
for (let i = 0; i < this.steps.length; i++) {
|
|
264
|
+
const step = { ...this.steps[i] };
|
|
265
|
+
if (i > 0) {
|
|
266
|
+
step.input_from = sanitizeStepId(this.stepOrder[i - 1]);
|
|
267
|
+
}
|
|
268
|
+
stepsWithInputFrom.push(step);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
_id: sanitizeStepId(this.workflowId),
|
|
272
|
+
name: this.workflowName,
|
|
273
|
+
trigger: this.trigger,
|
|
274
|
+
steps: stepsWithInputFrom,
|
|
275
|
+
status: "active",
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.WorkflowBuilder = WorkflowBuilder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommercialAppClient.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/CommercialAppClient.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const CommercialAppClient_1 = require("../CommercialAppClient");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
jest.mock("axios");
|
|
10
|
+
const mockedAxios = axios_1.default;
|
|
11
|
+
describe("CommercialAppClient", () => {
|
|
12
|
+
const mockAxiosInstance = jest.fn();
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
jest.clearAllMocks();
|
|
15
|
+
mockedAxios.create.mockReturnValue(mockAxiosInstance);
|
|
16
|
+
});
|
|
17
|
+
function createClient(overrides) {
|
|
18
|
+
return new CommercialAppClient_1.CommercialAppClient({
|
|
19
|
+
baseUrl: "https://api.example.com",
|
|
20
|
+
appId: "com_app_test",
|
|
21
|
+
apiKey: "cak_test_key",
|
|
22
|
+
...overrides,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
it("requires baseUrl and appId", () => {
|
|
26
|
+
expect(() => new CommercialAppClient_1.CommercialAppClient({ baseUrl: "", appId: "com_app_test" })).toThrow(errors_1.CliodotApiError);
|
|
27
|
+
expect(() => new CommercialAppClient_1.CommercialAppClient({
|
|
28
|
+
baseUrl: "https://api.example.com",
|
|
29
|
+
appId: "",
|
|
30
|
+
})).toThrow(errors_1.CliodotApiError);
|
|
31
|
+
});
|
|
32
|
+
it("opens a renewal invoice on the current subscription", async () => {
|
|
33
|
+
mockAxiosInstance.mockResolvedValue({
|
|
34
|
+
data: {
|
|
35
|
+
ok: true,
|
|
36
|
+
created: true,
|
|
37
|
+
invoice: {
|
|
38
|
+
_id: "com_inv_ren_1",
|
|
39
|
+
status: "open",
|
|
40
|
+
currency: "USD",
|
|
41
|
+
amount: 4900,
|
|
42
|
+
total: 4900,
|
|
43
|
+
metadata: { kind: "renewal", renew_on_success: true },
|
|
44
|
+
},
|
|
45
|
+
subscription: {
|
|
46
|
+
_id: "com_sub_1",
|
|
47
|
+
status: "pending_renewal",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const client = createClient();
|
|
52
|
+
const result = await client.renewSubscription({
|
|
53
|
+
subscriptionId: "com_sub_1",
|
|
54
|
+
payment_method: "paystack",
|
|
55
|
+
});
|
|
56
|
+
expect(result.invoice._id).toBe("com_inv_ren_1");
|
|
57
|
+
expect(result.created).toBe(true);
|
|
58
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
59
|
+
method: "POST",
|
|
60
|
+
url: "/v1/subscriptions/com_sub_1/renew",
|
|
61
|
+
headers: {
|
|
62
|
+
"x-cliodot-app-id": "com_app_test",
|
|
63
|
+
Authorization: "Bearer cak_test_key",
|
|
64
|
+
},
|
|
65
|
+
data: { payment_method: "paystack" },
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
it("renew aliases renewSubscription", async () => {
|
|
69
|
+
mockAxiosInstance.mockResolvedValue({
|
|
70
|
+
data: {
|
|
71
|
+
ok: true,
|
|
72
|
+
created: false,
|
|
73
|
+
invoice: { _id: "com_inv_ren_1", status: "open" },
|
|
74
|
+
subscription: { _id: "com_sub_1" },
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const client = createClient();
|
|
78
|
+
await client.renew({ subscriptionId: "com_sub_1" });
|
|
79
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
80
|
+
method: "POST",
|
|
81
|
+
url: "/v1/subscriptions/com_sub_1/renew",
|
|
82
|
+
}));
|
|
83
|
+
});
|
|
84
|
+
it("requires subscriptionId for renew", () => {
|
|
85
|
+
const client = createClient();
|
|
86
|
+
expect(() => client.renewSubscription({ subscriptionId: " " })).toThrow("subscriptionId is required");
|
|
87
|
+
});
|
|
88
|
+
it("confirms a provider renewal against the invoice", async () => {
|
|
89
|
+
mockAxiosInstance.mockResolvedValue({
|
|
90
|
+
data: {
|
|
91
|
+
ok: true,
|
|
92
|
+
reference: "com_inv_ren_1",
|
|
93
|
+
invoice: { _id: "com_inv_ren_1", status: "paid", amount: 4900 },
|
|
94
|
+
payment: {
|
|
95
|
+
_id: "com_pay_1",
|
|
96
|
+
status: "succeeded",
|
|
97
|
+
provider_payment_id: "in_123",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const client = createClient();
|
|
102
|
+
const result = await client.confirmPayment({
|
|
103
|
+
reference: "com_inv_ren_1",
|
|
104
|
+
status: "succeeded",
|
|
105
|
+
provider_payment_id: "in_123",
|
|
106
|
+
});
|
|
107
|
+
expect(result.invoice.status).toBe("paid");
|
|
108
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
109
|
+
method: "POST",
|
|
110
|
+
url: "/v1/payments/confirm",
|
|
111
|
+
data: {
|
|
112
|
+
reference: "com_inv_ren_1",
|
|
113
|
+
status: "succeeded",
|
|
114
|
+
provider_payment_id: "in_123",
|
|
115
|
+
},
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
118
|
+
it("lists and saves customer cards", async () => {
|
|
119
|
+
mockAxiosInstance.mockResolvedValue({
|
|
120
|
+
data: {
|
|
121
|
+
ok: true,
|
|
122
|
+
cards: [
|
|
123
|
+
{
|
|
124
|
+
_id: "com_card_1",
|
|
125
|
+
last4: "4242",
|
|
126
|
+
brand: "visa",
|
|
127
|
+
is_default: true,
|
|
128
|
+
status: "active",
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
pagination: { totalDocs: 1, page: 1, limit: 20 },
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const client = createClient();
|
|
135
|
+
const listed = await client.listCards("acme-corp");
|
|
136
|
+
expect(listed.cards[0].last4).toBe("4242");
|
|
137
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
138
|
+
method: "GET",
|
|
139
|
+
url: "/v1/customers/acme-corp/cards",
|
|
140
|
+
}));
|
|
141
|
+
mockAxiosInstance.mockResolvedValue({
|
|
142
|
+
data: {
|
|
143
|
+
ok: true,
|
|
144
|
+
card: {
|
|
145
|
+
_id: "com_card_2",
|
|
146
|
+
last4: "1111",
|
|
147
|
+
brand: "mastercard",
|
|
148
|
+
is_default: false,
|
|
149
|
+
status: "active",
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
const added = await client.addCard("acme-corp", {
|
|
154
|
+
token: "AUTH_ok",
|
|
155
|
+
last4: "1111",
|
|
156
|
+
brand: "mastercard",
|
|
157
|
+
});
|
|
158
|
+
expect(added.card._id).toBe("com_card_2");
|
|
159
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
160
|
+
method: "POST",
|
|
161
|
+
url: "/v1/customers/acme-corp/cards",
|
|
162
|
+
data: {
|
|
163
|
+
token: "AUTH_ok",
|
|
164
|
+
last4: "1111",
|
|
165
|
+
brand: "mastercard",
|
|
166
|
+
},
|
|
167
|
+
}));
|
|
168
|
+
});
|
|
169
|
+
it("sets default and removes a card", async () => {
|
|
170
|
+
mockAxiosInstance.mockResolvedValue({
|
|
171
|
+
data: {
|
|
172
|
+
ok: true,
|
|
173
|
+
card: { _id: "com_card_1", is_default: true, status: "active" },
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
const client = createClient();
|
|
177
|
+
await client.setDefaultCard("acme-corp", "com_card_1");
|
|
178
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
179
|
+
method: "POST",
|
|
180
|
+
url: "/v1/customers/acme-corp/cards/com_card_1/default",
|
|
181
|
+
}));
|
|
182
|
+
mockAxiosInstance.mockResolvedValue({
|
|
183
|
+
data: {
|
|
184
|
+
ok: true,
|
|
185
|
+
card: { _id: "com_card_1", status: "revoked" },
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
await client.removeCard("acme-corp", "com_card_1");
|
|
189
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
190
|
+
method: "DELETE",
|
|
191
|
+
url: "/v1/customers/acme-corp/cards/com_card_1",
|
|
192
|
+
}));
|
|
193
|
+
});
|
|
194
|
+
it("passes card_id on initiatePayment", async () => {
|
|
195
|
+
mockAxiosInstance.mockResolvedValue({
|
|
196
|
+
data: {
|
|
197
|
+
ok: true,
|
|
198
|
+
reference: "com_inv_1",
|
|
199
|
+
invoice: { _id: "com_inv_1", status: "processing" },
|
|
200
|
+
charge: {},
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
const client = createClient();
|
|
204
|
+
await client.initiatePayment({
|
|
205
|
+
customer: "acme-corp",
|
|
206
|
+
card_id: "com_card_1",
|
|
207
|
+
});
|
|
208
|
+
expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
|
|
209
|
+
method: "POST",
|
|
210
|
+
url: "/v1/payments/initiate",
|
|
211
|
+
data: expect.objectContaining({
|
|
212
|
+
customer: "acme-corp",
|
|
213
|
+
card_id: "com_card_1",
|
|
214
|
+
}),
|
|
215
|
+
}));
|
|
216
|
+
});
|
|
217
|
+
});
|