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
|
@@ -1 +1,576 @@
|
|
|
1
|
-
'use strict';const _0x26ef39=_0x169a;(function(_0x3c7b4a,_0x1be6dc){const _0x342164=_0x169a,_0x1d486a=_0x3c7b4a();while(!![]){try{const _0x184fea=parseInt(_0x342164(0x150))/0x1+parseInt(_0x342164(0x120))/0x2*(parseInt(_0x342164(0x1a1))/0x3)+-parseInt(_0x342164(0x15b))/0x4*(-parseInt(_0x342164(0x154))/0x5)+parseInt(_0x342164(0x1a6))/0x6*(parseInt(_0x342164(0x12a))/0x7)+parseInt(_0x342164(0x177))/0x8+-parseInt(_0x342164(0x11d))/0x9+-parseInt(_0x342164(0x163))/0xa;if(_0x184fea===_0x1be6dc)break;else _0x1d486a['push'](_0x1d486a['shift']());}catch(_0x38d1ce){_0x1d486a['push'](_0x1d486a['shift']());}}}(_0x452a,0xf1f2e));function _0x452a(){const _0x448278=['Aw5JBhvKzv9IAwXSAw5N','nZG2mdKWngvVtMLpDq','y3vZDg9TzxiGyw5Kihn1yMPLy3rFA2v5igfYzsbYzxf1AxjLza','C3vIC2nYAxb0Aw9Uswq','AxnZDwvmAwnLBNnL','AxngAw5PDgu','l3yXl2zLyxr1CMvZlW','BNvTyMvY','l3yXl2rPC2nVDw50CY9WCMv2Awv3','y3vZDg9TzxjFA2v5','uefuq0G','CgfYC2vbCgLfCNjVCK1LC3nHz2u','zMfPBhvYzv9YzwfZB24','yM9VBgvHBG','Ec1JBgLVzg90lwfWCc1ZzwnYzxq','CMv2B2TLtgLJzw5Zzq','Cgf5BwvUDf9PBNb1Da','C3vIC2nYAxb0Aw9UswqGyw5KihbSyw4GyxjLihjLCxvPCMvK','C3rYAw5N','yxbPs2v5','y3vZDg9TzxiGAxmGCMvXDwLYzwq','BgLZDezLyxr1CMvZ','yxnZAwDUu2vHDa','Dgf4x3jHDgu','yxbWBgLJyxrPB24VANnVBG','y2XPB2rVDefWAuvYCM9YrNjVBuf4Aw9Z','l3yXl2fUywX5DgLJCY9JAgfYDhm','B2jQzwn0','x19LC01VzhvSzq','yMfZzvvYBa','l2nVBw1LCMnPywW','BgLZDefKzg9UCW','y3vZDg9TzxiGyw5KihbSyw4GyxjLihjLCxvPCMvK','q2XPB2rVDefWAuvYCM9Y','l3yXl2zLyxr1CMvZ','l3yXl2XPy2vUC2vZl3zHBgLKyxrL','DhjPBq','BgLZDfrHEfjHDgvZ','l3yXl3n0yxrL','l3yXl2nOzwnR','zxHWAxjLC19HDa','ChjLDMLLD0rPC2nVDw50','z2v0ugXHBG','mZqZnda3C2zJAgHj','Dhj1zq','BgLZDfn1yNnJCMLWDgLVBNm','y3vZDg9Tzxi','CMvMzxjLBMnL','nteWEu5OreXd','l3yXl3bSyw5Z','l3yXl3bHEw1LBNqTBwv0Ag9KCW','mZe0nZm5menWshfxtW','l3yXl3bHEw1LBNrZl2nVBMzPCM0','l3jLDM9Rzq','mMfhEhblvq','BgLZDfbHEw1LBNrnzxrOB2rZ','l3yXl2rPC2nVDw50CW','y3vYCMvUy3K','BgLJzw5Zzv9RzxK','l3yXl3rHEc1YyxrLCW','BMfTzq','l3yXl2XPy2vUC2vZl2LZC3vL','C3rHDhvZ','z2v0sw52B2LJzq','mtyYmteZzKjcA0TL','y3jLyxrLu3vIC2nYAxb0Aw9U','C3rHDgu','zMvHDhvYzuLKigLZihjLCxvPCMvK','y3vZDg9TzxjjzcbPCYbYzxf1AxjLza','l3yXl2fKzg9UCW','x2LK','y3vZDg9TzxjFA2v5igfUzcbUyw1LigfYzsbYzxf1AxjLza','y3jLyxrLq3vZDg9Tzxi','ChjVDMLKzxjFCgf5BwvUDf9Pza','l2nOyw5Nzs1WBgfU','l3yXl3bYAwnPBMCVCxvVDgu','yM9KEq','CgXHBIbPCYbYzxf1AxjLza','yxHPB3m','l2fYy2HPDMu','y3jLyxrL','A2v5CW','q29TBwvYy2LHBefWCenSAwvUDcbYzxf1AxjLCYbIyxnLvxjS','l3yXl3bSyw5ZlW','BgLZDfbSyw5Z','r0vu','yxbWu2vJCMv0','y3vZDg9TzxiGyw5KigzLyxr1CMuGyxjLihjLCxvPCMvK','zw1HAwW','y29Kzq','q29TBwvYy2LHBefWCenSAwvUDa','q29TBwvYy2LHBefWCenSAwvUDcbJCMvKzw50AwfSCYbYzxf1AxjLzcaOyxbPs2v5l2fWCefWAuTLEsbVCIbHChbtzwnYzxqP','C2vHDhnFChvYy2HHC2vK','C3vIAMvJDf9RzxK','zgLZy291BNrFy29Kzq','uMvXDwvZDcbMywLSzwq6ia','l3yXl2LUDM9Py2vZ','Cgf5BwvUDf9TzxrOB2q','l3yXl2XPy2vUC2vZlW','ywrKB25Z','CxvVDgu','q29TBwvYy2LHBcbYzxf1zxn0igzHAwXLza','nZyZndK0u1nXEuzQ','CxvHBNrPDhK','qMvHCMvYia','CMvXDwvZDa','mtuWntGWALrfAwft','yxbWswq','CgfYyw1Z','zMvHDhvYzq','ue9tva','BgLZDeLUDM9Py2vZ','y2HLy2S','mZjKsKvfAMm','z2v0q3vZDg9TzxjtDwjZy3jPChrPB24','Bwv0ywrHDge','CgXHBKLKigLZihjLCxvPCMvK','l3yXl3nLyxrZl3vUyxnZAwDU','l3yXl2LUDM9Py2vZlW','l3yXl2n1C3rVBwvYCY8','Aw5WDxq','mJCYoti4nZbMuKLlq1m','zgvIDwC','yNvPBgrbDxrOsgvHzgvYCW','zgvMyxvSDa','l3yXl3n1yNnJCMLWDgLVBNm','Dgf4x2LKCW','y2HHBMDLugXHBG','DxbKyxrLu3vIC2nYAxb0Aw9Uu3rHDhvZ','z2v0u3vIC2nYAxb0Aw9U','l3yXl3n1yNnJCMLWDgLVBNmV','y29UC3vTzq','BgLZDen1C3rVBwvYCW','Aw5PDgLHDgvqyxLTzw50','Aw52B2LJzq','CgXHBG','l3yXl2n1C3rVBwvYCW','z2v0rMvHDhvYzq','BgLJzw5ZzuLKigLZihjLCxvPCMvK','AxnbCNjHEq'];_0x452a=function(){return _0x448278;};return _0x452a();}var __importDefault=this&&this['__importDefault']||function(_0x133e0e){const _0x47754f=_0x169a;return _0x133e0e&&_0x133e0e[_0x47754f(0x192)]?_0x133e0e:{'default':_0x133e0e};};Object['defineProperty'](exports,_0x26ef39(0x192),{'value':!![]}),exports[_0x26ef39(0x144)]=void 0x0;function _0x169a(_0x46d6a1,_0x428c14){_0x46d6a1=_0x46d6a1-0x11b;const _0x452acc=_0x452a();let _0x169aa5=_0x452acc[_0x46d6a1];if(_0x169a['PsXHsJ']===undefined){var _0x312a34=function(_0x43be7a){const _0x43f4d3='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x133e0e='',_0xb4c094='';for(let _0x468fc4=0x0,_0x5ab0bb,_0x808d93,_0x1c2e6b=0x0;_0x808d93=_0x43be7a['charAt'](_0x1c2e6b++);~_0x808d93&&(_0x5ab0bb=_0x468fc4%0x4?_0x5ab0bb*0x40+_0x808d93:_0x808d93,_0x468fc4++%0x4)?_0x133e0e+=String['fromCharCode'](0xff&_0x5ab0bb>>(-0x2*_0x468fc4&0x6)):0x0){_0x808d93=_0x43f4d3['indexOf'](_0x808d93);}for(let _0x87b6ef=0x0,_0x1b9e9d=_0x133e0e['length'];_0x87b6ef<_0x1b9e9d;_0x87b6ef++){_0xb4c094+='%'+('00'+_0x133e0e['charCodeAt'](_0x87b6ef)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0xb4c094);};_0x169a['ewKUPt']=_0x312a34,_0x169a['FQnnmk']={},_0x169a['PsXHsJ']=!![];}const _0x10edf9=_0x452acc[0x0],_0x437854=_0x46d6a1+_0x10edf9,_0x1c2a3a=_0x169a['FQnnmk'][_0x437854];return!_0x1c2a3a?(_0x169aa5=_0x169a['ewKUPt'](_0x169aa5),_0x169a['FQnnmk'][_0x437854]=_0x169aa5):_0x169aa5=_0x1c2a3a,_0x169aa5;}const axios_1=__importDefault(require('axios')),errors_1=require('./errors'),parse_api_error_1=require('./http/parse-api-error');function trimBaseUrl(_0xb4c094){const _0x2fd9b1=_0x26ef39;return _0xb4c094[_0x2fd9b1(0x19a)]()['replace'](/\/+$/,'');}function resolveIdRef(value,_0x468fc4=['_id','id']){const _0x58f68d=_0x26ef39;if(typeof value===_0x58f68d(0x188))return value[_0x58f68d(0x19a)]();if(typeof value===_0x58f68d(0x17d)&&Number['isFinite'](value))return String(value);if(value&&typeof value===_0x58f68d(0x191)){const _0x5ab0bb=value;for(const _0x808d93 of _0x468fc4){const _0x1c2e6b=_0x5ab0bb[_0x808d93];if(typeof _0x1c2e6b===_0x58f68d(0x188)&&_0x1c2e6b[_0x58f68d(0x19a)]())return _0x1c2e6b['trim']();if(typeof _0x1c2e6b===_0x58f68d(0x17d)&&Number[_0x58f68d(0x17b)](_0x1c2e6b))return String(_0x1c2e6b);}}return'';}function cleanParams(_0x87b6ef){const _0x29b645=_0x26ef39;if(!_0x87b6ef)return undefined;const _0x1b9e9d={};for(const [_0x40112c,value]of Object['entries'](_0x87b6ef)){if(value===undefined||value===null)continue;if(Array[_0x29b645(0x175)](value)){_0x1b9e9d[_0x40112c]=value['join'](',');continue;}(typeof value===_0x29b645(0x188)||typeof value===_0x29b645(0x17d)||typeof value===_0x29b645(0x183))&&(_0x1b9e9d[_0x40112c]=value);}return Object[_0x29b645(0x13b)](_0x1b9e9d)['length']?_0x1b9e9d:undefined;}class CommercialAppClient{constructor(_0x5a9b69){const _0x1eaf27=_0x26ef39;if(!_0x5a9b69[_0x1eaf27(0x193)]?.[_0x1eaf27(0x19a)]())throw new errors_1[(_0x1eaf27(0x197))](_0x1eaf27(0x13c));if(!_0x5a9b69[_0x1eaf27(0x155)]?.[_0x1eaf27(0x19a)]())throw new errors_1[(_0x1eaf27(0x197))]('CommercialAppClient\x20requires\x20appId');this[_0x1eaf27(0x193)]=trimBaseUrl(_0x5a9b69[_0x1eaf27(0x193)]),this[_0x1eaf27(0x155)]=_0x5a9b69[_0x1eaf27(0x155)][_0x1eaf27(0x19a)](),this[_0x1eaf27(0x189)]=_0x5a9b69[_0x1eaf27(0x189)]?.[_0x1eaf27(0x19a)]()||_0x5a9b69['appApiKey']?.[_0x1eaf27(0x19a)]()||undefined,this[_0x1eaf27(0x140)]=_0x5a9b69[_0x1eaf27(0x140)]?.[_0x1eaf27(0x19a)]()||undefined,this[_0x1eaf27(0x164)]=_0x5a9b69[_0x1eaf27(0x164)]??![],this['axios']=axios_1[_0x1eaf27(0x166)][_0x1eaf27(0x13a)]({'baseURL':this[_0x1eaf27(0x193)]+_0x1eaf27(0x194),'timeout':0xea60,'headers':{'Content-Type':_0x1eaf27(0x18e)}});}[_0x26ef39(0x15a)](_0x92f514){const _0x1f6456=_0x26ef39;if(!_0x92f514?.[_0x1f6456(0x1a4)]?.[_0x1f6456(0x19a)]()||!_0x92f514?.['feature']?.[_0x1f6456(0x19a)]())throw new errors_1[(_0x1f6456(0x197))](_0x1f6456(0x141));return this['request']('POST',_0x1f6456(0x19d),{'body':{'customer':_0x92f514['customer'][_0x1f6456(0x19a)](),'feature':_0x92f514[_0x1f6456(0x157)][_0x1f6456(0x19a)](),'quantity':_0x92f514[_0x1f6456(0x151)]}});}[_0x26ef39(0x16d)](_0x259ceb){const _0x4762a7=_0x26ef39;if(!_0x259ceb?.[_0x4762a7(0x1a4)]?.['trim']()||!_0x259ceb?.[_0x4762a7(0x157)]?.['trim']())throw new errors_1[(_0x4762a7(0x197))](_0x4762a7(0x141));return this[_0x4762a7(0x153)](_0x4762a7(0x158),'/v1/consume',{'body':{'customer':_0x259ceb[_0x4762a7(0x1a4)][_0x4762a7(0x19a)](),'feature':_0x259ceb[_0x4762a7(0x157)][_0x4762a7(0x19a)](),'quantity':_0x259ceb['quantity']}});}[_0x26ef39(0x12c)](_0x2fd6c1){const _0x35ff71=_0x26ef39;if(!_0x2fd6c1?.[_0x35ff71(0x1a4)]?.[_0x35ff71(0x19a)]())throw new errors_1[(_0x35ff71(0x197))](_0x35ff71(0x18a));return this[_0x35ff71(0x153)](_0x35ff71(0x13f),_0x35ff71(0x19c),{'params':{'customer':_0x2fd6c1[_0x35ff71(0x1a4)][_0x35ff71(0x19a)](),'include_billing':_0x2fd6c1[_0x35ff71(0x176)]?_0x35ff71(0x1a2):undefined}});}[_0x26ef39(0x15c)](_0x48a6e5,_0x51a023){const _0x3c9996=_0x26ef39;if(!_0x48a6e5?.[_0x3c9996(0x19a)]())throw new errors_1['CliodotApiError'](_0x3c9996(0x12e));return this[_0x3c9996(0x153)](_0x3c9996(0x13f),_0x3c9996(0x161)+encodeURIComponent(_0x48a6e5[_0x3c9996(0x19a)]())+'/subscription',{'params':{'include_billing':_0x51a023?.[_0x3c9996(0x176)]?_0x3c9996(0x1a2):undefined}});}[_0x26ef39(0x16e)](_0x374cb1){const _0x46eec=_0x26ef39;return this[_0x46eec(0x153)](_0x46eec(0x13f),_0x46eec(0x172),{'params':cleanParams(_0x374cb1)});}['getCustomer'](_0x285581){const _0x1c7997=_0x26ef39;if(!_0x285581?.[_0x1c7997(0x19a)]())throw new errors_1['CliodotApiError'](_0x1c7997(0x12e));return this[_0x1c7997(0x153)](_0x1c7997(0x13f),'/v1/customers/'+encodeURIComponent(_0x285581['trim']()));}[_0x26ef39(0x132)](_0xbfa570){const _0x124864=_0x26ef39;if(!_0xbfa570?.[_0x124864(0x17f)]?.[_0x124864(0x19a)]()||!_0xbfa570?.[_0x124864(0x126)]?.[_0x124864(0x19a)]())throw new errors_1[(_0x124864(0x197))](_0x124864(0x131));return this[_0x124864(0x153)](_0x124864(0x158),_0x124864(0x172),{'body':{'customer_key':_0xbfa570[_0x124864(0x17f)]['trim'](),'name':_0xbfa570[_0x124864(0x126)][_0x124864(0x19a)](),'email':_0xbfa570[_0x124864(0x142)],'preferred_currency':_0xbfa570['preferred_currency'],'tax_ids':_0xbfa570[_0x124864(0x168)],'billing_address':_0xbfa570['billing_address'],'metadata':_0xbfa570[_0x124864(0x15d)]}});}[_0x26ef39(0x18b)](_0x46b8ac){const _0xf53b8e=_0x26ef39;return this[_0xf53b8e(0x153)]('GET',_0xf53b8e(0x198),{'params':cleanParams(_0x46b8ac)});}[_0x26ef39(0x173)](_0x4c478c){const _0x7aac72=_0x26ef39;if(!_0x4c478c?.[_0x7aac72(0x19a)]())throw new errors_1[(_0x7aac72(0x197))](_0x7aac72(0x12d));return this[_0x7aac72(0x153)](_0x7aac72(0x13f),_0x7aac72(0x17c)+encodeURIComponent(_0x4c478c['trim']()));}[_0x26ef39(0x13e)](_0x23d3e6){const _0x25ccf7=_0x26ef39;return this['request'](_0x25ccf7(0x13f),_0x25ccf7(0x11b),{'params':cleanParams(_0x23d3e6)});}[_0x26ef39(0x1a0)](_0x345f90){const _0x371b39=_0x26ef39;if(!_0x345f90?.[_0x371b39(0x19a)]())throw new errors_1[(_0x371b39(0x197))](_0x371b39(0x15e));return this[_0x371b39(0x153)](_0x371b39(0x13f),_0x371b39(0x13d)+encodeURIComponent(_0x345f90[_0x371b39(0x19a)]()));}[_0x26ef39(0x1a3)](_0x2aabc3){const _0x220e60=_0x26ef39;return this[_0x220e60(0x153)](_0x220e60(0x13f),_0x220e60(0x167),{'params':cleanParams(_0x2aabc3)});}[_0x26ef39(0x16b)](_0x51b6b0){const _0x580aa6=_0x26ef39;if(!_0x51b6b0?.['trim']())throw new errors_1[(_0x580aa6(0x197))]('subscriptionId\x20is\x20required');return this[_0x580aa6(0x153)](_0x580aa6(0x13f),_0x580aa6(0x16c)+encodeURIComponent(_0x51b6b0['trim']()));}[_0x26ef39(0x159)](_0x37f1a1){const _0x112891=_0x26ef39;return this[_0x112891(0x153)]('GET',_0x112891(0x14a),{'params':cleanParams(_0x37f1a1)});}[_0x26ef39(0x129)](_0x2d89c9){const _0x489988=_0x26ef39,_0x32b0a4=resolveIdRef(_0x2d89c9,['invoiceId',_0x489988(0x130),'id',_0x489988(0x1a5)]);if(!_0x32b0a4)throw new errors_1[(_0x489988(0x197))]('invoiceId\x20is\x20required');return this['request']('GET',_0x489988(0x160)+encodeURIComponent(_0x32b0a4));}[_0x26ef39(0x12b)](_0x4adb39){const _0xa116cc=_0x26ef39;if(!_0x4adb39?.[_0xa116cc(0x1a4)]?.[_0xa116cc(0x19a)]()||!_0x4adb39?.['plan']?.['trim']())throw new errors_1[(_0xa116cc(0x197))](_0xa116cc(0x196));return this['request']('POST',_0xa116cc(0x167),{'body':{'customer':_0x4adb39[_0xa116cc(0x1a4)][_0xa116cc(0x19a)](),'plan':_0x4adb39[_0xa116cc(0x171)]['trim'](),'status':_0x4adb39['status'],'currency':_0x4adb39[_0xa116cc(0x123)],'discount_code':_0x4adb39['discount_code'],'tax_rate':_0x4adb39[_0xa116cc(0x18d)],'addons':_0x4adb39[_0xa116cc(0x14d)],'seats_purchased':_0x4adb39[_0xa116cc(0x146)],'metadata':_0x4adb39[_0xa116cc(0x15d)],'payment_method':_0x4adb39[_0xa116cc(0x14b)],'payment_input':_0x4adb39[_0xa116cc(0x186)]}});}['subscribe'](_0x18b899){const _0x1e73a9=_0x26ef39;return this[_0x1e73a9(0x12b)](_0x18b899);}[_0x26ef39(0x169)](_0x46924e){const _0x1fc096=_0x26ef39;if(!_0x46924e?.['subscriptionId']?.['trim']()||!_0x46924e?.['plan']?.[_0x1fc096(0x19a)]())throw new errors_1[(_0x1fc096(0x197))](_0x1fc096(0x187));return this['request'](_0x1fc096(0x158),_0x1fc096(0x16c)+encodeURIComponent(_0x46924e['subscriptionId'][_0x1fc096(0x19a)]())+_0x1fc096(0x134),{'body':{'plan':_0x46924e[_0x1fc096(0x171)][_0x1fc096(0x19a)](),'currency':_0x46924e[_0x1fc096(0x123)],'discount_code':_0x46924e[_0x1fc096(0x148)],'tax_rate':_0x46924e['tax_rate'],'addons':_0x46924e[_0x1fc096(0x14d)],'seats_purchased':_0x46924e[_0x1fc096(0x146)],'payment_method':_0x46924e[_0x1fc096(0x14b)],'payment_input':_0x46924e['payment_input']}});}[_0x26ef39(0x121)](){const _0x13ed44=_0x26ef39;return this['request'](_0x13ed44(0x13f),_0x13ed44(0x11c));}[_0x26ef39(0x16f)](_0x496222){const _0x9f8a21=_0x26ef39;if(!_0x496222?.['customer']?.['trim']())throw new errors_1['CliodotApiError'](_0x9f8a21(0x18a));return this[_0x9f8a21(0x153)](_0x9f8a21(0x158),'/v1/payments/initiate',{'body':{'customer':_0x496222[_0x9f8a21(0x1a4)][_0x9f8a21(0x19a)](),'subscription':_0x496222['subscription'],'invoice':_0x496222[_0x9f8a21(0x170)],'payment_method':_0x496222[_0x9f8a21(0x14b)],'input':_0x496222[_0x9f8a21(0x162)],'currency':_0x496222['currency'],'discount_code':_0x496222[_0x9f8a21(0x148)]}});}['confirmPayment'](_0x2824dd){const _0x40fc5f=_0x26ef39;if(!_0x2824dd?.[_0x40fc5f(0x1a5)]?.[_0x40fc5f(0x19a)]()||!_0x2824dd?.[_0x40fc5f(0x128)]?.[_0x40fc5f(0x19a)]())throw new errors_1[(_0x40fc5f(0x197))]('reference\x20and\x20status\x20are\x20required');return this['request'](_0x40fc5f(0x158),_0x40fc5f(0x11e),{'body':{'reference':_0x2824dd['reference'][_0x40fc5f(0x19a)](),'status':_0x2824dd[_0x40fc5f(0x128)],'provider_payment_id':_0x2824dd[_0x40fc5f(0x133)],'failure_reason':_0x2824dd[_0x40fc5f(0x182)],'metadata':_0x2824dd['metadata']}});}[_0x26ef39(0x14e)](_0x584d2f){const _0x3104ce=_0x26ef39;if(!_0x584d2f?.[_0x3104ce(0x171)]?.[_0x3104ce(0x19a)]())throw new errors_1[(_0x3104ce(0x197))](_0x3104ce(0x137));return this[_0x3104ce(0x153)](_0x3104ce(0x158),_0x3104ce(0x135),{'body':{'plan':_0x584d2f[_0x3104ce(0x171)]['trim'](),'customer':_0x584d2f[_0x3104ce(0x1a4)],'currency':_0x584d2f[_0x3104ce(0x123)],'discount_code':_0x584d2f['discount_code'],'tax_rate':_0x584d2f[_0x3104ce(0x18d)],'addons':_0x584d2f['addons'],'seats_purchased':_0x584d2f['seats_purchased'],'metadata':_0x584d2f[_0x3104ce(0x15d)]}});}[_0x26ef39(0x19f)](_0x4f7c61){const _0x10687b=_0x26ef39;if(!_0x4f7c61?.[_0x10687b(0x143)]?.[_0x10687b(0x19a)]()||!_0x4f7c61?.['plan']?.['trim']())throw new errors_1[(_0x10687b(0x197))]('code\x20and\x20plan\x20are\x20required');return this[_0x10687b(0x153)](_0x10687b(0x158),_0x10687b(0x17e),{'body':{'code':_0x4f7c61[_0x10687b(0x143)][_0x10687b(0x19a)](),'plan':_0x4f7c61['plan'][_0x10687b(0x19a)](),'currency':_0x4f7c61[_0x10687b(0x123)],'customer':_0x4f7c61['customer']}});}['listDiscounts'](_0x58aaa4){const _0x1de09c=_0x26ef39;return this[_0x1de09c(0x153)]('GET',_0x1de09c(0x122),{'params':cleanParams(_0x58aaa4)});}[_0x26ef39(0x19b)](_0x174c1a){const _0x523be1=_0x26ef39;return this[_0x523be1(0x153)](_0x523be1(0x13f),_0x523be1(0x125),{'params':cleanParams(_0x174c1a)});}[_0x26ef39(0x195)](_0x49a583){const _0xdb7954=_0x26ef39;return this[_0xdb7954(0x153)](_0xdb7954(0x13f),_0xdb7954(0x12f),{'params':cleanParams(_0x49a583)});}[_0x26ef39(0x16a)](_0x36154e){const _0x531326=_0x26ef39;if(!_0x36154e?.[_0x531326(0x179)]?.['trim']()||!_0x36154e?.[_0x531326(0x128)]?.['trim']())throw new errors_1[(_0x531326(0x197))]('subscriptionId\x20and\x20status\x20are\x20required');return this[_0x531326(0x153)](_0x531326(0x180),_0x531326(0x16c)+encodeURIComponent(_0x36154e['subscriptionId'][_0x531326(0x19a)]())+'/status',{'body':{'status':_0x36154e[_0x531326(0x128)][_0x531326(0x19a)]()}});}['archiveSubscription'](_0x267c6c){const _0x1379e4=_0x26ef39;if(!_0x267c6c?.[_0x1379e4(0x19a)]())throw new errors_1[(_0x1379e4(0x197))]('subscriptionId\x20is\x20required');return this[_0x1379e4(0x153)]('POST',_0x1379e4(0x16c)+encodeURIComponent(_0x267c6c['trim']())+_0x1379e4(0x139));}[_0x26ef39(0x18c)](_0x2912db){const _0x3a921e=_0x26ef39;if(!_0x2912db?.[_0x3a921e(0x1a4)]?.[_0x3a921e(0x19a)]()||!_0x2912db?.[_0x3a921e(0x147)]?.[_0x3a921e(0x19a)]())throw new errors_1[(_0x3a921e(0x197))](_0x3a921e(0x178));return this[_0x3a921e(0x153)]('POST','/v1/seats/assign',{'body':{'customer':_0x2912db['customer'][_0x3a921e(0x19a)](),'subject_key':_0x2912db[_0x3a921e(0x147)][_0x3a921e(0x19a)](),'email':_0x2912db['email'],'metadata':_0x2912db[_0x3a921e(0x15d)]}});}['unassignSeat'](_0x4666a5){const _0x350c43=_0x26ef39;if(!_0x4666a5?.[_0x350c43(0x1a4)]?.['trim']()||!_0x4666a5?.[_0x350c43(0x147)]?.['trim']())throw new errors_1[(_0x350c43(0x197))](_0x350c43(0x178));return this[_0x350c43(0x153)](_0x350c43(0x158),_0x350c43(0x15f),{'body':{'customer':_0x4666a5['customer'][_0x350c43(0x19a)](),'subject_key':_0x4666a5['subject_key'][_0x350c43(0x19a)](),'email':_0x4666a5[_0x350c43(0x142)],'metadata':_0x4666a5[_0x350c43(0x15d)]}});}[_0x26ef39(0x17a)](_0x44ae41){const _0x434bec=_0x26ef39;if(!_0x44ae41?.['customer']?.[_0x434bec(0x19a)]())throw new errors_1['CliodotApiError']('customer\x20is\x20required');return this[_0x434bec(0x153)](_0x434bec(0x158),_0x434bec(0x127),{'body':{'customer':_0x44ae41[_0x434bec(0x1a4)][_0x434bec(0x19a)](),'expires_at':_0x44ae41[_0x434bec(0x19e)],'metadata':_0x44ae41[_0x434bec(0x15d)]}});}['validateLicense'](_0x587cd4){const _0x39606c=_0x26ef39;if(!_0x587cd4?.[_0x39606c(0x124)]?.[_0x39606c(0x19a)]())throw new errors_1[(_0x39606c(0x197))]('license_key\x20is\x20required');return this[_0x39606c(0x153)](_0x39606c(0x158),_0x39606c(0x199),{'body':{'license_key':_0x587cd4[_0x39606c(0x124)][_0x39606c(0x19a)]()}});}[_0x26ef39(0x185)](_0x4d4c46){const _0x1949ae=_0x26ef39;if(!_0x4d4c46?.[_0x1949ae(0x19a)]())throw new errors_1[(_0x1949ae(0x197))](_0x1949ae(0x174));return this[_0x1949ae(0x153)](_0x1949ae(0x158),_0x1949ae(0x14c)+encodeURIComponent(_0x4d4c46[_0x1949ae(0x19a)]())+_0x1949ae(0x11f));}['analytics'](_0x48012f){const _0x6fbce=_0x26ef39;return this[_0x6fbce(0x153)]('GET','/v1/analytics',{'params':cleanParams(_0x48012f)});}['analyticsCharts'](_0x44e11c){const _0x37eb98=_0x26ef39;return this[_0x37eb98(0x153)](_0x37eb98(0x13f),_0x37eb98(0x190),{'params':cleanParams(_0x44e11c)});}[_0x26ef39(0x165)](){const _0x2c0bbb=_0x26ef39,_0x1fa9d0={'x-cliodot-app-id':this[_0x2c0bbb(0x155)]};if(this[_0x2c0bbb(0x189)])return _0x1fa9d0['Authorization']=_0x2c0bbb(0x152)+this['apiKey'],_0x1fa9d0;if(this[_0x2c0bbb(0x140)])return _0x1fa9d0[_0x2c0bbb(0x184)]=this[_0x2c0bbb(0x140)],_0x1fa9d0;throw new errors_1[(_0x2c0bbb(0x197))](_0x2c0bbb(0x145));}async[_0x26ef39(0x153)](_0x13454f,_0x532c11,_0x1b305c){const _0x15fd7a=_0x26ef39;try{const {data:_0x539d58}=await this[_0x15fd7a(0x138)]({'method':_0x13454f,'url':_0x532c11,'headers':this[_0x15fd7a(0x165)](),'data':_0x1b305c?.[_0x15fd7a(0x136)],'params':cleanParams(_0x1b305c?.[_0x15fd7a(0x156)])});if(_0x539d58?.['ok']===![])throw new errors_1[(_0x15fd7a(0x197))]((0x0,parse_api_error_1[_0x15fd7a(0x181)])(_0x539d58)||_0x15fd7a(0x14f),{'data':_0x539d58,'code':(0x0,parse_api_error_1['parseApiErrorCode'])(_0x539d58)});return _0x539d58;}catch(_0x185afe){if(_0x185afe instanceof errors_1[_0x15fd7a(0x197)])throw _0x185afe;throw(0x0,errors_1[_0x15fd7a(0x18f)])(_0x185afe,_0x15fd7a(0x149)+_0x13454f+'\x20'+_0x532c11);}}}exports[_0x26ef39(0x144)]=CommercialAppClient;
|
|
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
|
+
exports.CommercialAppClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const parse_api_error_1 = require("./http/parse-api-error");
|
|
10
|
+
const cliodot_request_1 = require("./http/cliodot-request");
|
|
11
|
+
function trimBaseUrl(url) {
|
|
12
|
+
return url.trim().replace(/\/+$/, "");
|
|
13
|
+
}
|
|
14
|
+
function resolveIdRef(value, keys = ["_id", "id"]) {
|
|
15
|
+
if (typeof value === "string")
|
|
16
|
+
return value.trim();
|
|
17
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
if (value && typeof value === "object") {
|
|
21
|
+
const obj = value;
|
|
22
|
+
for (const key of keys) {
|
|
23
|
+
const candidate = obj[key];
|
|
24
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
25
|
+
return candidate.trim();
|
|
26
|
+
}
|
|
27
|
+
if (typeof candidate === "number" && Number.isFinite(candidate)) {
|
|
28
|
+
return String(candidate);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
function cleanParams(params) {
|
|
35
|
+
if (!params)
|
|
36
|
+
return undefined;
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const [key, value] of Object.entries(params)) {
|
|
39
|
+
if (value === undefined || value === null)
|
|
40
|
+
continue;
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
out[key] = value.join(",");
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (typeof value === "string" ||
|
|
46
|
+
typeof value === "number" ||
|
|
47
|
+
typeof value === "boolean") {
|
|
48
|
+
out[key] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return Object.keys(out).length ? out : undefined;
|
|
52
|
+
}
|
|
53
|
+
class CommercialAppClient {
|
|
54
|
+
constructor(config) {
|
|
55
|
+
if (!config.baseUrl?.trim()) {
|
|
56
|
+
throw new errors_1.CliodotApiError("CommercialAppClient requires baseUrl");
|
|
57
|
+
}
|
|
58
|
+
if (!config.appId?.trim()) {
|
|
59
|
+
throw new errors_1.CliodotApiError("CommercialAppClient requires appId");
|
|
60
|
+
}
|
|
61
|
+
this.baseUrl = trimBaseUrl(config.baseUrl);
|
|
62
|
+
this.appId = config.appId.trim();
|
|
63
|
+
this.apiKey =
|
|
64
|
+
config.apiKey?.trim() || config.appApiKey?.trim() || undefined;
|
|
65
|
+
this.appSecret = config.appSecret?.trim() || undefined;
|
|
66
|
+
this.environment = config.environment;
|
|
67
|
+
this.debug = config.debug ?? false;
|
|
68
|
+
this.axios = axios_1.default.create({
|
|
69
|
+
baseURL: `${this.baseUrl}/commercial`,
|
|
70
|
+
timeout: 60000,
|
|
71
|
+
headers: { "Content-Type": "application/json" },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
check(input) {
|
|
75
|
+
if (!input?.customer?.trim() || !input?.feature?.trim()) {
|
|
76
|
+
throw new errors_1.CliodotApiError("customer and feature are required");
|
|
77
|
+
}
|
|
78
|
+
return this.request("POST", "/v1/check", {
|
|
79
|
+
body: {
|
|
80
|
+
customer: input.customer.trim(),
|
|
81
|
+
feature: input.feature.trim(),
|
|
82
|
+
quantity: input.quantity,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
consume(input) {
|
|
87
|
+
if (!input?.customer?.trim() || !input?.feature?.trim()) {
|
|
88
|
+
throw new errors_1.CliodotApiError("customer and feature are required");
|
|
89
|
+
}
|
|
90
|
+
return this.request("POST", "/v1/consume", {
|
|
91
|
+
body: {
|
|
92
|
+
customer: input.customer.trim(),
|
|
93
|
+
feature: input.feature.trim(),
|
|
94
|
+
quantity: input.quantity,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
state(input) {
|
|
99
|
+
if (!input?.customer?.trim()) {
|
|
100
|
+
throw new errors_1.CliodotApiError("customer is required");
|
|
101
|
+
}
|
|
102
|
+
return this.request("GET", "/v1/state", {
|
|
103
|
+
params: {
|
|
104
|
+
customer: input.customer.trim(),
|
|
105
|
+
include_billing: input.include_billing ? "true" : undefined,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getCustomerSubscription(customerId, options) {
|
|
110
|
+
if (!customerId?.trim()) {
|
|
111
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
112
|
+
}
|
|
113
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/subscription`, {
|
|
114
|
+
params: {
|
|
115
|
+
include_billing: options?.include_billing ? "true" : undefined,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
listCustomers(params) {
|
|
120
|
+
return this.request("GET", "/v1/customers", {
|
|
121
|
+
params: cleanParams(params),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
getCustomer(customerId) {
|
|
125
|
+
if (!customerId?.trim()) {
|
|
126
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
127
|
+
}
|
|
128
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}`);
|
|
129
|
+
}
|
|
130
|
+
listCredits(customerId, params) {
|
|
131
|
+
if (!customerId?.trim()) {
|
|
132
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
133
|
+
}
|
|
134
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/credits`, { params: cleanParams(params) });
|
|
135
|
+
}
|
|
136
|
+
topupCredits(input) {
|
|
137
|
+
if (!input?.customerId?.trim() || !input?.currency?.trim()) {
|
|
138
|
+
throw new errors_1.CliodotApiError("customerId and currency are required");
|
|
139
|
+
}
|
|
140
|
+
if (!Number.isFinite(input.amount) || input.amount <= 0) {
|
|
141
|
+
throw new errors_1.CliodotApiError("amount must be a positive number");
|
|
142
|
+
}
|
|
143
|
+
return this.request("POST", `/v1/customers/${encodeURIComponent(input.customerId.trim())}/credits/topup`, {
|
|
144
|
+
body: {
|
|
145
|
+
currency: input.currency.trim(),
|
|
146
|
+
amount: input.amount,
|
|
147
|
+
payment_method: input.payment_method,
|
|
148
|
+
card: input.card,
|
|
149
|
+
card_id: input.card_id,
|
|
150
|
+
payment_input: input.payment_input,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
listCards(customerId, params) {
|
|
155
|
+
if (!customerId?.trim()) {
|
|
156
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
157
|
+
}
|
|
158
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards`, { params: cleanParams(params) });
|
|
159
|
+
}
|
|
160
|
+
addCard(customerId, input = {}) {
|
|
161
|
+
if (!customerId?.trim()) {
|
|
162
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
163
|
+
}
|
|
164
|
+
return this.request("POST", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards`, { body: input });
|
|
165
|
+
}
|
|
166
|
+
updateCard(customerId, cardId, input = {}) {
|
|
167
|
+
if (!customerId?.trim() || !cardId?.trim()) {
|
|
168
|
+
throw new errors_1.CliodotApiError("customerId and cardId are required");
|
|
169
|
+
}
|
|
170
|
+
return this.request("PATCH", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards/${encodeURIComponent(cardId.trim())}`, { body: input });
|
|
171
|
+
}
|
|
172
|
+
removeCard(customerId, cardId) {
|
|
173
|
+
if (!customerId?.trim() || !cardId?.trim()) {
|
|
174
|
+
throw new errors_1.CliodotApiError("customerId and cardId are required");
|
|
175
|
+
}
|
|
176
|
+
return this.request("DELETE", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards/${encodeURIComponent(cardId.trim())}`);
|
|
177
|
+
}
|
|
178
|
+
setDefaultCard(customerId, cardId) {
|
|
179
|
+
if (!customerId?.trim() || !cardId?.trim()) {
|
|
180
|
+
throw new errors_1.CliodotApiError("customerId and cardId are required");
|
|
181
|
+
}
|
|
182
|
+
return this.request("POST", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards/${encodeURIComponent(cardId.trim())}/default`);
|
|
183
|
+
}
|
|
184
|
+
createCustomer(input) {
|
|
185
|
+
if (!input?.customer_key?.trim() || !input?.name?.trim()) {
|
|
186
|
+
throw new errors_1.CliodotApiError("customer_key and name are required");
|
|
187
|
+
}
|
|
188
|
+
return this.request("POST", "/v1/customers", {
|
|
189
|
+
body: {
|
|
190
|
+
customer_key: input.customer_key.trim(),
|
|
191
|
+
name: input.name.trim(),
|
|
192
|
+
email: input.email,
|
|
193
|
+
preferred_currency: input.preferred_currency,
|
|
194
|
+
tax_ids: input.tax_ids,
|
|
195
|
+
billing_address: input.billing_address,
|
|
196
|
+
metadata: input.metadata,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
listFeatures(params) {
|
|
201
|
+
return this.request("GET", "/v1/features", {
|
|
202
|
+
params: cleanParams(params),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
getFeature(featureId) {
|
|
206
|
+
if (!featureId?.trim()) {
|
|
207
|
+
throw new errors_1.CliodotApiError("featureId is required");
|
|
208
|
+
}
|
|
209
|
+
return this.request("GET", `/v1/features/${encodeURIComponent(featureId.trim())}`);
|
|
210
|
+
}
|
|
211
|
+
listPlans(params) {
|
|
212
|
+
return this.request("GET", "/v1/plans", {
|
|
213
|
+
params: cleanParams(params),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
getPlan(planId) {
|
|
217
|
+
if (!planId?.trim()) {
|
|
218
|
+
throw new errors_1.CliodotApiError("planId is required");
|
|
219
|
+
}
|
|
220
|
+
return this.request("GET", `/v1/plans/${encodeURIComponent(planId.trim())}`);
|
|
221
|
+
}
|
|
222
|
+
listSubscriptions(params) {
|
|
223
|
+
return this.request("GET", "/v1/subscriptions", {
|
|
224
|
+
params: cleanParams(params),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
getSubscription(subscriptionId) {
|
|
228
|
+
if (!subscriptionId?.trim()) {
|
|
229
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
230
|
+
}
|
|
231
|
+
return this.request("GET", `/v1/subscriptions/${encodeURIComponent(subscriptionId.trim())}`);
|
|
232
|
+
}
|
|
233
|
+
listInvoices(params) {
|
|
234
|
+
return this.request("GET", "/v1/invoices", {
|
|
235
|
+
params: cleanParams(params),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
getInvoice(invoiceId) {
|
|
239
|
+
const id = resolveIdRef(invoiceId, [
|
|
240
|
+
"invoiceId",
|
|
241
|
+
"_id",
|
|
242
|
+
"id",
|
|
243
|
+
"reference",
|
|
244
|
+
]);
|
|
245
|
+
if (!id) {
|
|
246
|
+
throw new errors_1.CliodotApiError("invoiceId is required");
|
|
247
|
+
}
|
|
248
|
+
return this.request("GET", `/v1/invoices/${encodeURIComponent(id)}`);
|
|
249
|
+
}
|
|
250
|
+
createSubscription(input) {
|
|
251
|
+
if (!input?.customer?.trim() || !input?.plan?.trim()) {
|
|
252
|
+
throw new errors_1.CliodotApiError("customer and plan are required");
|
|
253
|
+
}
|
|
254
|
+
return this.request("POST", "/v1/subscriptions", {
|
|
255
|
+
body: {
|
|
256
|
+
customer: input.customer.trim(),
|
|
257
|
+
plan: input.plan.trim(),
|
|
258
|
+
status: input.status,
|
|
259
|
+
currency: input.currency,
|
|
260
|
+
discount_code: input.discount_code,
|
|
261
|
+
tax_rate: input.tax_rate,
|
|
262
|
+
addons: input.addons,
|
|
263
|
+
seats_purchased: input.seats_purchased,
|
|
264
|
+
metadata: input.metadata,
|
|
265
|
+
payment_method: input.payment_method,
|
|
266
|
+
card: input.card,
|
|
267
|
+
card_id: input.card_id,
|
|
268
|
+
payment_input: input.payment_input,
|
|
269
|
+
auto_renew: input.auto_renew,
|
|
270
|
+
renewal_mode: input.renewal_mode,
|
|
271
|
+
skip_trial: input.skip_trial,
|
|
272
|
+
usage_rollover: input.usage_rollover,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
subscribe(input) {
|
|
277
|
+
return this.createSubscription(input);
|
|
278
|
+
}
|
|
279
|
+
updatePendingSubscription(input) {
|
|
280
|
+
if (!input?.subscriptionId?.trim()) {
|
|
281
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
282
|
+
}
|
|
283
|
+
return this.request("PATCH", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}`, {
|
|
284
|
+
body: {
|
|
285
|
+
plan: input.plan,
|
|
286
|
+
currency: input.currency,
|
|
287
|
+
discount_code: input.discount_code,
|
|
288
|
+
tax_rate: input.tax_rate,
|
|
289
|
+
addons: input.addons,
|
|
290
|
+
seats_purchased: input.seats_purchased,
|
|
291
|
+
payment_method: input.payment_method,
|
|
292
|
+
card: input.card,
|
|
293
|
+
card_id: input.card_id,
|
|
294
|
+
payment_input: input.payment_input,
|
|
295
|
+
auto_renew: input.auto_renew,
|
|
296
|
+
renewal_mode: input.renewal_mode,
|
|
297
|
+
skip_trial: input.skip_trial,
|
|
298
|
+
metadata: input.metadata,
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
changePlan(input) {
|
|
303
|
+
if (!input?.subscriptionId?.trim() || !input?.plan?.trim()) {
|
|
304
|
+
throw new errors_1.CliodotApiError("subscriptionId and plan are required");
|
|
305
|
+
}
|
|
306
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/change-plan`, {
|
|
307
|
+
body: {
|
|
308
|
+
plan: input.plan.trim(),
|
|
309
|
+
currency: input.currency,
|
|
310
|
+
discount_code: input.discount_code,
|
|
311
|
+
tax_rate: input.tax_rate,
|
|
312
|
+
addons: input.addons,
|
|
313
|
+
seats_purchased: input.seats_purchased,
|
|
314
|
+
payment_method: input.payment_method,
|
|
315
|
+
card: input.card,
|
|
316
|
+
card_id: input.card_id,
|
|
317
|
+
payment_input: input.payment_input,
|
|
318
|
+
auto_renew: input.auto_renew,
|
|
319
|
+
renewal_mode: input.renewal_mode,
|
|
320
|
+
apply_at: input.apply_at,
|
|
321
|
+
usage_rollover: input.usage_rollover,
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
entitlementTopup(input) {
|
|
326
|
+
if (!input?.subscriptionId?.trim() || !input?.feature?.trim()) {
|
|
327
|
+
throw new errors_1.CliodotApiError("subscriptionId and feature are required");
|
|
328
|
+
}
|
|
329
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/entitlement-topup`, {
|
|
330
|
+
body: {
|
|
331
|
+
feature: input.feature.trim(),
|
|
332
|
+
pack_units: input.pack_units,
|
|
333
|
+
pack_index: input.pack_index,
|
|
334
|
+
payment_method: input.payment_method,
|
|
335
|
+
card: input.card,
|
|
336
|
+
card_id: input.card_id,
|
|
337
|
+
payment_input: input.payment_input,
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
chargeUsage(input) {
|
|
342
|
+
if (!input?.subscriptionId?.trim()) {
|
|
343
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
344
|
+
}
|
|
345
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/charge-usage`, {
|
|
346
|
+
body: {
|
|
347
|
+
amount: input.amount,
|
|
348
|
+
payment_method: input.payment_method,
|
|
349
|
+
card: input.card,
|
|
350
|
+
card_id: input.card_id,
|
|
351
|
+
payment_input: input.payment_input,
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
renewSubscription(input) {
|
|
356
|
+
if (!input?.subscriptionId?.trim()) {
|
|
357
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
358
|
+
}
|
|
359
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/renew`, {
|
|
360
|
+
body: {
|
|
361
|
+
payment_method: input.payment_method,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
renew(input) {
|
|
366
|
+
return this.renewSubscription(input);
|
|
367
|
+
}
|
|
368
|
+
listEvents(customerId, params) {
|
|
369
|
+
if (!customerId?.trim()) {
|
|
370
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
371
|
+
}
|
|
372
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/events`, { params: cleanParams(params) });
|
|
373
|
+
}
|
|
374
|
+
listUsageEvents(customerId, params) {
|
|
375
|
+
if (!customerId?.trim()) {
|
|
376
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
377
|
+
}
|
|
378
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/usage-events`, { params: cleanParams(params) });
|
|
379
|
+
}
|
|
380
|
+
listEventTypes() {
|
|
381
|
+
return this.request("GET", "/v1/event-types");
|
|
382
|
+
}
|
|
383
|
+
listPaymentMethods() {
|
|
384
|
+
return this.request("GET", "/v1/payment-methods");
|
|
385
|
+
}
|
|
386
|
+
initiatePayment(input) {
|
|
387
|
+
if (!input?.customer?.trim()) {
|
|
388
|
+
throw new errors_1.CliodotApiError("customer is required");
|
|
389
|
+
}
|
|
390
|
+
return this.request("POST", "/v1/payments/initiate", {
|
|
391
|
+
body: {
|
|
392
|
+
customer: input.customer.trim(),
|
|
393
|
+
subscription: input.subscription,
|
|
394
|
+
invoice: input.invoice,
|
|
395
|
+
payment_method: input.payment_method,
|
|
396
|
+
card: input.card,
|
|
397
|
+
card_id: input.card_id,
|
|
398
|
+
input: input.input,
|
|
399
|
+
currency: input.currency,
|
|
400
|
+
discount_code: input.discount_code,
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
confirmPayment(input) {
|
|
405
|
+
if (!input?.reference?.trim() || !input?.status?.trim()) {
|
|
406
|
+
throw new errors_1.CliodotApiError("reference and status are required");
|
|
407
|
+
}
|
|
408
|
+
return this.request("POST", "/v1/payments/confirm", {
|
|
409
|
+
body: {
|
|
410
|
+
reference: input.reference.trim(),
|
|
411
|
+
status: input.status,
|
|
412
|
+
provider_payment_id: input.provider_payment_id,
|
|
413
|
+
failure_reason: input.failure_reason,
|
|
414
|
+
metadata: input.metadata,
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
quote(input) {
|
|
419
|
+
if (!input?.plan?.trim()) {
|
|
420
|
+
throw new errors_1.CliodotApiError("plan is required");
|
|
421
|
+
}
|
|
422
|
+
return this.request("POST", "/v1/pricing/quote", {
|
|
423
|
+
body: {
|
|
424
|
+
plan: input.plan.trim(),
|
|
425
|
+
customer: input.customer,
|
|
426
|
+
currency: input.currency,
|
|
427
|
+
discount_code: input.discount_code,
|
|
428
|
+
tax_rate: input.tax_rate,
|
|
429
|
+
addons: input.addons,
|
|
430
|
+
seats_purchased: input.seats_purchased,
|
|
431
|
+
metadata: input.metadata,
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
previewDiscount(input) {
|
|
436
|
+
if (!input?.code?.trim() || !input?.plan?.trim()) {
|
|
437
|
+
throw new errors_1.CliodotApiError("code and plan are required");
|
|
438
|
+
}
|
|
439
|
+
return this.request("POST", "/v1/discounts/preview", {
|
|
440
|
+
body: {
|
|
441
|
+
code: input.code.trim(),
|
|
442
|
+
plan: input.plan.trim(),
|
|
443
|
+
currency: input.currency,
|
|
444
|
+
customer: input.customer,
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
listDiscounts(params) {
|
|
449
|
+
return this.request("GET", "/v1/discounts", {
|
|
450
|
+
params: cleanParams(params),
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
listTaxRates(params) {
|
|
454
|
+
return this.request("GET", "/v1/tax-rates", {
|
|
455
|
+
params: cleanParams(params),
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
listAddons(params) {
|
|
459
|
+
return this.request("GET", "/v1/addons", {
|
|
460
|
+
params: cleanParams(params),
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
updateSubscriptionStatus(input) {
|
|
464
|
+
if (!input?.subscriptionId?.trim() || !input?.status?.trim()) {
|
|
465
|
+
throw new errors_1.CliodotApiError("subscriptionId and status are required");
|
|
466
|
+
}
|
|
467
|
+
return this.request("PATCH", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/status`, { body: { status: input.status.trim() } });
|
|
468
|
+
}
|
|
469
|
+
archiveSubscription(subscriptionId) {
|
|
470
|
+
if (!subscriptionId?.trim()) {
|
|
471
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
472
|
+
}
|
|
473
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(subscriptionId.trim())}/archive`);
|
|
474
|
+
}
|
|
475
|
+
assignSeat(input) {
|
|
476
|
+
if (!input?.customer?.trim() || !input?.subject_key?.trim()) {
|
|
477
|
+
throw new errors_1.CliodotApiError("customer and subject_key are required");
|
|
478
|
+
}
|
|
479
|
+
return this.request("POST", "/v1/seats/assign", {
|
|
480
|
+
body: {
|
|
481
|
+
customer: input.customer.trim(),
|
|
482
|
+
subject_key: input.subject_key.trim(),
|
|
483
|
+
email: input.email,
|
|
484
|
+
metadata: input.metadata,
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
unassignSeat(input) {
|
|
489
|
+
if (!input?.customer?.trim() || !input?.subject_key?.trim()) {
|
|
490
|
+
throw new errors_1.CliodotApiError("customer and subject_key are required");
|
|
491
|
+
}
|
|
492
|
+
return this.request("POST", "/v1/seats/unassign", {
|
|
493
|
+
body: {
|
|
494
|
+
customer: input.customer.trim(),
|
|
495
|
+
subject_key: input.subject_key.trim(),
|
|
496
|
+
email: input.email,
|
|
497
|
+
metadata: input.metadata,
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
issueLicense(input) {
|
|
502
|
+
if (!input?.customer?.trim()) {
|
|
503
|
+
throw new errors_1.CliodotApiError("customer is required");
|
|
504
|
+
}
|
|
505
|
+
return this.request("POST", "/v1/licenses/issue", {
|
|
506
|
+
body: {
|
|
507
|
+
customer: input.customer.trim(),
|
|
508
|
+
expires_at: input.expires_at,
|
|
509
|
+
metadata: input.metadata,
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
validateLicense(input) {
|
|
514
|
+
if (!input?.license_key?.trim()) {
|
|
515
|
+
throw new errors_1.CliodotApiError("license_key is required");
|
|
516
|
+
}
|
|
517
|
+
return this.request("POST", "/v1/licenses/validate", {
|
|
518
|
+
body: { license_key: input.license_key.trim() },
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
revokeLicense(licenseId) {
|
|
522
|
+
if (!licenseId?.trim()) {
|
|
523
|
+
throw new errors_1.CliodotApiError("licenseId is required");
|
|
524
|
+
}
|
|
525
|
+
return this.request("POST", `/v1/licenses/${encodeURIComponent(licenseId.trim())}/revoke`);
|
|
526
|
+
}
|
|
527
|
+
analytics(params) {
|
|
528
|
+
return this.request("GET", "/v1/analytics", {
|
|
529
|
+
params: cleanParams(params),
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
analyticsCharts(params) {
|
|
533
|
+
return this.request("GET", "/v1/analytics/charts", {
|
|
534
|
+
params: cleanParams(params),
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
buildAuthHeaders() {
|
|
538
|
+
const headers = (0, cliodot_request_1.applyEnvironmentHeader)({
|
|
539
|
+
"x-cliodot-app-id": this.appId,
|
|
540
|
+
}, this.environment);
|
|
541
|
+
if (this.apiKey) {
|
|
542
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
543
|
+
return headers;
|
|
544
|
+
}
|
|
545
|
+
if (this.appSecret) {
|
|
546
|
+
headers["x-cliodot-app-secret"] = this.appSecret;
|
|
547
|
+
return headers;
|
|
548
|
+
}
|
|
549
|
+
throw new errors_1.CliodotApiError("CommercialAppClient credentials required (apiKey/appApiKey or appSecret)");
|
|
550
|
+
}
|
|
551
|
+
async request(method, path, options) {
|
|
552
|
+
try {
|
|
553
|
+
const { data } = await this.axios({
|
|
554
|
+
method,
|
|
555
|
+
url: path,
|
|
556
|
+
headers: this.buildAuthHeaders(),
|
|
557
|
+
data: options?.body,
|
|
558
|
+
params: cleanParams(options?.params),
|
|
559
|
+
});
|
|
560
|
+
if (data?.ok === false) {
|
|
561
|
+
throw new errors_1.CliodotApiError((0, parse_api_error_1.parseApiErrorMessage)(data) || "Commercial request failed", {
|
|
562
|
+
data,
|
|
563
|
+
code: (0, parse_api_error_1.parseApiErrorCode)(data),
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
return data;
|
|
567
|
+
}
|
|
568
|
+
catch (err) {
|
|
569
|
+
if (err instanceof errors_1.CliodotApiError) {
|
|
570
|
+
throw err;
|
|
571
|
+
}
|
|
572
|
+
throw (0, errors_1.cliodotApiErrorFromAxios)(err, `Request failed: ${method} ${path}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
exports.CommercialAppClient = CommercialAppClient;
|