cliodot 1.2.2 → 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 +81 -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 +178 -0
- package/dist/CommercialAppClient.d.ts.map +1 -0
- package/dist/CommercialAppClient.js +576 -0
- 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 +23 -0
- package/dist/IdentityAppClient.d.ts.map +1 -0
- package/dist/IdentityAppClient.js +197 -0
- package/dist/MemoryAppClient.d.ts +28 -0
- package/dist/MemoryAppClient.d.ts.map +1 -0
- package/dist/MemoryAppClient.js +149 -0
- package/dist/MemoryClient.d.ts +8 -0
- package/dist/MemoryClient.d.ts.map +1 -0
- package/dist/MemoryClient.js +20 -0
- 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.d.ts +20 -0
- package/dist/Webhooks.d.ts.map +1 -0
- package/dist/Webhooks.js +61 -0
- 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.d.ts +2 -0
- package/dist/__tests__/IdentityAppClient.test.d.ts.map +1 -0
- package/dist/__tests__/IdentityAppClient.test.js +232 -0
- 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.d.ts +6 -0
- package/dist/identity-offline-verify.d.ts.map +1 -0
- package/dist/identity-offline-verify.js +174 -0
- package/dist/identity-token-cache.d.ts +6 -0
- package/dist/identity-token-cache.d.ts.map +1 -0
- package/dist/identity-token-cache.js +51 -0
- package/dist/index.d.ts +10 -0
- 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 +963 -0
- package/dist/types/commercial-app.api.d.ts.map +1 -0
- package/dist/types/commercial-app.api.js +2 -0
- 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 +99 -0
- package/dist/types/identity-app.api.d.ts.map +1 -0
- package/dist/types/identity-app.api.js +2 -0
- package/dist/types/index.js +23 -1
- package/dist/types/memory-app.api.d.ts +140 -0
- package/dist/types/memory-app.api.d.ts.map +1 -0
- package/dist/types/memory-app.api.js +2 -0
- 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.d.ts +2 -0
- package/dist/types/webhook-app.api.d.ts.map +1 -0
- package/dist/types/webhook-app.api.js +2 -0
- 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/OAuthAppClient.js
CHANGED
|
@@ -1 +1,269 @@
|
|
|
1
|
-
'use strict';const _0x1184f5=_0x1d39;function _0x1d39(_0x1e263f,_0x11a18a){_0x1e263f=_0x1e263f-0x1ad;const _0x227514=_0x2275();let _0x1d3981=_0x227514[_0x1e263f];if(_0x1d39['vThYtI']===undefined){var _0x26d495=function(_0x3fbffc){const _0x52a3dd='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x2f6f26='',_0x3c505c='';for(let _0x66c948=0x0,_0x334281,_0x39cff3,_0x239e7f=0x0;_0x39cff3=_0x3fbffc['charAt'](_0x239e7f++);~_0x39cff3&&(_0x334281=_0x66c948%0x4?_0x334281*0x40+_0x39cff3:_0x39cff3,_0x66c948++%0x4)?_0x2f6f26+=String['fromCharCode'](0xff&_0x334281>>(-0x2*_0x66c948&0x6)):0x0){_0x39cff3=_0x52a3dd['indexOf'](_0x39cff3);}for(let _0x2a4ca7=0x0,_0x4e211f=_0x2f6f26['length'];_0x2a4ca7<_0x4e211f;_0x2a4ca7++){_0x3c505c+='%'+('00'+_0x2f6f26['charCodeAt'](_0x2a4ca7)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3c505c);};_0x1d39['zCDtQr']=_0x26d495,_0x1d39['gLVzhy']={},_0x1d39['vThYtI']=!![];}const _0x464361=_0x227514[0x0],_0x45f100=_0x1e263f+_0x464361,_0x48c180=_0x1d39['gLVzhy'][_0x45f100];return!_0x48c180?(_0x1d3981=_0x1d39['zCDtQr'](_0x1d3981),_0x1d39['gLVzhy'][_0x45f100]=_0x1d3981):_0x1d3981=_0x48c180,_0x1d3981;}(function(_0x5d4ed7,_0x13fc0f){const _0x3dd4ee=_0x1d39,_0x40651e=_0x5d4ed7();while(!![]){try{const _0x6da98a=parseInt(_0x3dd4ee(0x1e0))/0x1+-parseInt(_0x3dd4ee(0x205))/0x2*(parseInt(_0x3dd4ee(0x1e9))/0x3)+parseInt(_0x3dd4ee(0x1f7))/0x4*(parseInt(_0x3dd4ee(0x1e5))/0x5)+parseInt(_0x3dd4ee(0x1f4))/0x6+parseInt(_0x3dd4ee(0x20a))/0x7*(parseInt(_0x3dd4ee(0x1fc))/0x8)+parseInt(_0x3dd4ee(0x1e8))/0x9*(parseInt(_0x3dd4ee(0x1b6))/0xa)+-parseInt(_0x3dd4ee(0x1b7))/0xb*(parseInt(_0x3dd4ee(0x203))/0xc);if(_0x6da98a===_0x13fc0f)break;else _0x40651e['push'](_0x40651e['shift']());}catch(_0x8590ed){_0x40651e['push'](_0x40651e['shift']());}}}(_0x2275,0x83e88));var __importDefault=this&&this[_0x1184f5(0x1df)]||function(_0x2f6f26){const _0xb4e1bc=_0x1184f5;return _0x2f6f26&&_0x2f6f26[_0xb4e1bc(0x206)]?_0x2f6f26:{'default':_0x2f6f26};};Object[_0x1184f5(0x1c1)](exports,'__esModule',{'value':!![]}),exports[_0x1184f5(0x1db)]=void 0x0;const axios_1=__importDefault(require(_0x1184f5(0x1cf))),errors_1=require(_0x1184f5(0x1d5)),parse_api_error_1=require(_0x1184f5(0x1fa)),oauth_app_api_1=require(_0x1184f5(0x1b2));function trimBaseUrl(_0x3c505c){const _0x4df40f=_0x1184f5;return _0x3c505c[_0x4df40f(0x20c)]()['replace'](/\/+$/,'');}function resolveScope(_0x66c948){const _0x49dc0b=_0x1184f5;if(_0x66c948[_0x49dc0b(0x1d4)]?.['trim']())return _0x66c948['scope'][_0x49dc0b(0x20c)]();if(_0x66c948['scopes']?.[_0x49dc0b(0x208)])return _0x66c948[_0x49dc0b(0x1ba)]['filter'](Boolean)[_0x49dc0b(0x1ad)]('\x20');return undefined;}function _0x2275(){const _0x5b286f=['Bwf4qxr0zw1WDhm','t0f1DgGGyxbWignYzwrLBNrPywXZihjLCxvPCMvKicHHChbbCgLlzxKGB3iGyxbWu2vJCMv0kq','y29UBMvJDcbYzxf1AxjLCYbWCM92AwrLCG','t0f1DgGGCMvXDwvZDcbMywLSzwq','mtK0mZiYmdbuwuHmEvK','l3rVA2vUl2v4y2HHBMDL','mti4zMrPB2fc','x19LC01VzhvSzq','l29HDxrOl2fWChmV','BgvUz3rO','y29Kzq','mJy1ota5BwvUAuvV','A2v5CW','DhjPBq','CMvZB2X2zufWCeLK','AM9PBG','l3rVA2vU','zxH0zxjUywXFDxnLCL9Pza','uMvXDwvZDcbMywLSzwq6ia','CgfYC2vbCgLfCNjVCKnVzgu','lI90ExbLCY9Vyxv0Ac1HChaUyxbP','ywn0B3jFDg9Rzw5FDhLWzq','zxHJAgfUz2uGCMvXDwLYzxmGy29UBMvJDgLVBL9Pza','CMvHC29U','mZy2mZK5mgz4BLbbqq','mtfNtKvmBMS','y29UBMvJDgLVBNm','CMvSyxLFC3rHDgu','C2nVCgvZ','C2fTBf9Yzxf1zxn0','yxvKAwvUy2u','Dg9tDhjPBMC','Cg9ZDa','yxbWBgLJyxrPB24VANnVBG','l3jLDM9Rzq','zgvMAw5LuhjVCgvYDhK','q2XPB2rVDefWAuvYCM9Y','y29UBMvJDgLVBL9ZDg9YywDL','ChjVDMLKzxi','C3rHDhvZq29Kzq','l2fWChmV','yM9KEq','CMvKAxjLy3rFDxjP','C3vIAMvJDf90B2TLBG','zxHJAgfUz2uGCMvXDwLYzxmGy29Kzq','Cg9SBf9ZDgf0zq','rgv2AwnLigf1DgHVCML6yxrPB24GCg9SBcb0Aw1LzcbVDxq','yMfZzvvYBa','yxbWswq','yxHPB3m','revmrvrf','t0f1DgHbChbdBgLLBNqGCMvXDwLYzxmGyxbWswq','yxv0Ag9YAxPHDgLVBL91CMW','yxbWqxbPs2v5','C2nVCgu','lI9LCNjVCNm','DMfSAwrHDgvszxnWB25Zzq','r0vu','l2nVBM5Ly3rPB25ZlW','y29UBMvJDgLVBL9Pza','l2nVBM5Ly3q','t0f1DgHbChbdBgLLBNq','qMvHCMvYia','yNvPBgrtmLnizwfKzxjZ','zw50CMLLCW','x19PBxbVCNrezwzHDwX0','nJq3mZu3wLfVv2v1','l2nVBM5Ly3qVCg9SBa','AxnezxzPy2vbDxrOB3jPEMf0Aw9UugvUzgLUz0vYCM9Y','z2v0vg9Rzw4','y2XPB2rVDefWAuvYCM9YrNjVBuf4Aw9Z','ntvmwwnOwgG','C2v0','CMvXDwvZDgvKx3rVA2vUx3r5Cgu','ouruyNfvqG','mZa4ntjKrK1hwhC','yxbWu2vJCMv0','CgfYC2vbCgLfCNjVCK1LC3nHz2u','Cg9SBeLUDgvYDMfStxm','y29UBMvJDcbYzxf1AxjLCYbYzwrPCMvJDf91CMK','C3vIAMvJDf90B2TLBL90ExbL','ywn0B3jFDg9Rzw4','Cg9SBcbYzxf1AxjLCYbWB2XSx3n0yxrL','C3rHDgu','C2vHCMnOugfYyw1Z','CMvXDwvZDa','nti0mdiWohLLBM9hDW','CgfYyw1Z','y29UBMvJDgLVBKLKigLZihjLCxvPCMvK','mJi3oti4AwXmsLny','ue9tva','C3nVx2jPBMrPBMC','lI9ODhrWl3bHCNnLlwfWAs1LCNjVCG','zxHJAgfUz2u','nJrgyw1AuxK','l3jLzNjLC2G','zgvIDwC'];_0x2275=function(){return _0x5b286f;};return _0x2275();}function buildConnectQuery(_0x334281){const _0x57eb3f=_0x1184f5,_0x39cff3={'provider':_0x334281[_0x57eb3f(0x1c4)][_0x57eb3f(0x20c)](),'redirect_uri':_0x334281['redirect_uri'][_0x57eb3f(0x20c)]()},_0x239e7f=resolveScope(_0x334281);if(_0x239e7f)_0x39cff3[_0x57eb3f(0x1d4)]=_0x239e7f;if(_0x334281[_0x57eb3f(0x1f1)])_0x39cff3[_0x57eb3f(0x1f1)]=_0x334281[_0x57eb3f(0x1f1)];if(_0x334281[_0x57eb3f(0x1af)])_0x39cff3['external_user_id']=_0x334281[_0x57eb3f(0x1af)];if(_0x334281[_0x57eb3f(0x1c3)])_0x39cff3[_0x57eb3f(0x1c3)]=_0x334281[_0x57eb3f(0x1c3)];return _0x39cff3;}function buildConnectBody(_0x2a4ca7){const _0xe1d36=_0x1184f5,_0x4e211f={'provider':_0x2a4ca7[_0xe1d36(0x1c4)][_0xe1d36(0x20c)](),'redirect_uri':_0x2a4ca7[_0xe1d36(0x1c8)][_0xe1d36(0x20c)]()},_0x3e3eeb=resolveScope(_0x2a4ca7);if(_0x3e3eeb)_0x4e211f['scope']=_0x3e3eeb;if(_0x2a4ca7[_0xe1d36(0x1ba)]?.['length'])_0x4e211f[_0xe1d36(0x1ba)]=_0x2a4ca7[_0xe1d36(0x1ba)];if(_0x2a4ca7[_0xe1d36(0x1f1)])_0x4e211f[_0xe1d36(0x1f1)]=_0x2a4ca7[_0xe1d36(0x1f1)];if(_0x2a4ca7[_0xe1d36(0x1af)])_0x4e211f['external_user_id']=_0x2a4ca7['external_user_id'];if(_0x2a4ca7[_0xe1d36(0x1c3)])_0x4e211f['connection_storage']=_0x2a4ca7[_0xe1d36(0x1c3)];if(_0x2a4ca7['assertion'])_0x4e211f['assertion']=_0x2a4ca7['assertion'];if(_0x2a4ca7[_0xe1d36(0x1c9)])_0x4e211f[_0xe1d36(0x1c9)]=_0x2a4ca7[_0xe1d36(0x1c9)];if(_0x2a4ca7[_0xe1d36(0x1ee)])_0x4e211f[_0xe1d36(0x1ee)]=_0x2a4ca7['subject_token_type'];if(_0x2a4ca7[_0xe1d36(0x1e7)])_0x4e211f[_0xe1d36(0x1e7)]=_0x2a4ca7[_0xe1d36(0x1e7)];if(_0x2a4ca7[_0xe1d36(0x1ef)])_0x4e211f[_0xe1d36(0x1ef)]=_0x2a4ca7[_0xe1d36(0x1ef)];if(_0x2a4ca7['actor_token_type'])_0x4e211f['actor_token_type']=_0x2a4ca7[_0xe1d36(0x1b3)];if(_0x2a4ca7[_0xe1d36(0x1bc)])_0x4e211f['audience']=_0x2a4ca7[_0xe1d36(0x1bc)];return _0x4e211f;}function assertConnectInput(_0x3cc835){const _0x56f3c1=_0x1184f5;if(!_0x3cc835[_0x56f3c1(0x1c4)]?.[_0x56f3c1(0x20c)]())throw new errors_1[(_0x56f3c1(0x1c2))](_0x56f3c1(0x201));if(!_0x3cc835[_0x56f3c1(0x1c8)]?.[_0x56f3c1(0x20c)]())throw new errors_1[(_0x56f3c1(0x1c2))](_0x56f3c1(0x1ed));}function assertPollInput(_0xaf4bb0){const _0x13dc0b=_0x1184f5;if(!_0xaf4bb0[_0x13dc0b(0x1c4)]?.[_0x13dc0b(0x20c)]())throw new errors_1[(_0x13dc0b(0x1c2))]('poll\x20requires\x20provider');if(!_0xaf4bb0[_0x13dc0b(0x1cb)]?.['trim']())throw new errors_1[(_0x13dc0b(0x1c2))](_0x13dc0b(0x1f0));}function assertExchangeInput(_0x1f187b){const _0x178544=_0x1184f5;if(!_0x1f187b[_0x178544(0x209)]?.[_0x178544(0x20c)]())throw new errors_1['CliodotApiError'](_0x178544(0x1ca));if(!_0x1f187b[_0x178544(0x1d9)]?.[_0x178544(0x20c)]())throw new errors_1[(_0x178544(0x1c2))](_0x178544(0x1b4));}function assertConnectionId(_0x5765f4){const _0x54dcdb=_0x1184f5;if(!_0x5765f4?.[_0x54dcdb(0x20c)]())throw new errors_1[(_0x54dcdb(0x1c2))](_0x54dcdb(0x1f6));}function sleep(_0x5a6578){return new Promise(_0x1ddae6=>setTimeout(_0x1ddae6,_0x5a6578));}class OAuthAppClient{constructor(_0x5aea42){const _0x34a5ae=_0x1184f5;this['connect']={'start':async _0x441f72=>{const _0x3106a9=_0x1d39;assertConnectInput(_0x441f72);const _0x29979a=this[_0x3106a9(0x20d)](_0x441f72[_0x3106a9(0x1ce)]);return this[_0x3106a9(0x1f3)](_0x3106a9(0x1f8),'/apps/'+encodeURIComponent(_0x29979a)+_0x3106a9(0x1da),{'body':buildConnectBody(_0x441f72),'auth':![]});},'poll':async _0xe2158a=>{const _0x150698=_0x1d39;assertPollInput(_0xe2158a);const _0x2b324f=this[_0x150698(0x20d)](_0xe2158a[_0x150698(0x1ce)]),_0xfeb299=_0xe2158a[_0x150698(0x1ec)]??0x1388,_0x54d11a=_0xe2158a[_0x150698(0x1ff)]??0x78;for(let _0x375e0b=0x0;_0x375e0b<_0x54d11a;_0x375e0b+=0x1){try{return await this[_0x150698(0x1f3)]('POST',_0x150698(0x1c6)+encodeURIComponent(_0x2b324f)+_0x150698(0x1e1),{'body':{'provider':_0xe2158a['provider'][_0x150698(0x20c)](),'poll_state':_0xe2158a['poll_state'][_0x150698(0x20c)]()},'auth':![]});}catch(_0x950c7b){if(!(0x0,oauth_app_api_1[_0x150698(0x1e2)])(_0x950c7b)||_0x375e0b===_0x54d11a-0x1)throw _0x950c7b;await sleep(_0xfeb299);}}throw new errors_1[(_0x150698(0x1c2))](_0x150698(0x1cc));},'buildUrl':_0x32a851=>{const _0x3134f3=_0x1d39;assertConnectInput(_0x32a851);const _0x55c5f3=this[_0x3134f3(0x20d)](_0x32a851[_0x3134f3(0x1ce)]),_0x1bdfab=new URL(this[_0x3134f3(0x1cd)]+_0x3134f3(0x207)+encodeURIComponent(_0x55c5f3)+_0x3134f3(0x1da)),_0x3755a5=buildConnectQuery(_0x32a851);for(const [_0x392534,value]of Object[_0x3134f3(0x1de)](_0x3755a5)){_0x1bdfab[_0x3134f3(0x1f2)][_0x3134f3(0x1e6)](_0x392534,value);}return _0x1bdfab[_0x3134f3(0x1bd)]();},'isSamlPostBinding':_0x56e028=>{const _0x310a9b=_0x1d39;return _0x56e028[_0x310a9b(0x1f9)]===_0x310a9b(0x1be)&&!!_0x56e028[_0x310a9b(0x1bb)]&&!!_0x56e028[_0x310a9b(0x1b9)];},'buildSamlPostForm':_0x1e58c5=>{const _0x3f1667=_0x1d39;if(!_0x1e58c5['saml_request']||!_0x1e58c5[_0x3f1667(0x1b9)]||!_0x1e58c5[_0x3f1667(0x1d2)])return null;if(_0x1e58c5[_0x3f1667(0x1f9)]&&_0x1e58c5[_0x3f1667(0x1f9)]!==_0x3f1667(0x1be))return null;return{'action':_0x1e58c5['authorization_url'],'samlRequest':_0x1e58c5[_0x3f1667(0x1bb)],'relayState':_0x1e58c5[_0x3f1667(0x1b9)]};}},this[_0x34a5ae(0x1b8)]={'get':async _0x352943=>{const _0x5c664a=_0x34a5ae;return assertConnectionId(_0x352943),this['request'](_0x5c664a(0x1d7),_0x5c664a(0x1d8)+encodeURIComponent(_0x352943[_0x5c664a(0x20c)]()));},'getToken':async _0x1ba587=>{const _0x11c680=_0x34a5ae;return assertConnectionId(_0x1ba587),this[_0x11c680(0x1f3)](_0x11c680(0x1d7),_0x11c680(0x1d8)+encodeURIComponent(_0x1ba587[_0x11c680(0x20c)]())+_0x11c680(0x1ae));},'sync':async _0x55acc8=>{const _0x24647e=_0x34a5ae;return this[_0x24647e(0x1b8)][_0x24647e(0x1e3)](_0x55acc8);},'refresh':async _0x24bdf0=>{const _0x3a2362=_0x34a5ae;return assertConnectionId(_0x24bdf0),this[_0x3a2362(0x1f3)]('POST',_0x3a2362(0x1d8)+encodeURIComponent(_0x24bdf0[_0x3a2362(0x20c)]())+_0x3a2362(0x1fd));},'revoke':async(_0x202fb5,_0x556d0b)=>{const _0xe25d1d=_0x34a5ae;assertConnectionId(_0x202fb5);const _0x3ac169={};return _0x556d0b?.[_0xe25d1d(0x1b5)]?.[_0xe25d1d(0x20c)]()&&(_0x3ac169[_0xe25d1d(0x1b5)]=_0x556d0b[_0xe25d1d(0x1b5)][_0xe25d1d(0x20c)]()),this[_0xe25d1d(0x1f3)](_0xe25d1d(0x1f8),_0xe25d1d(0x1d8)+encodeURIComponent(_0x202fb5[_0xe25d1d(0x20c)]())+_0xe25d1d(0x1c0),{'body':Object[_0xe25d1d(0x20b)](_0x3ac169)[_0xe25d1d(0x208)]?_0x3ac169:undefined});},'delete':async _0x18d382=>{const _0x507274=_0x34a5ae;return assertConnectionId(_0x18d382),this[_0x507274(0x1f3)](_0x507274(0x1d0),'/connections/'+encodeURIComponent(_0x18d382['trim']()));}};if(!_0x5aea42['baseUrl']?.[_0x34a5ae(0x20c)]())throw new errors_1[(_0x34a5ae(0x1c2))]('OAuthAppClient\x20requires\x20baseUrl');if(!_0x5aea42['appId']?.['trim']())throw new errors_1['CliodotApiError'](_0x34a5ae(0x1d1));this[_0x34a5ae(0x1cd)]=trimBaseUrl(_0x5aea42[_0x34a5ae(0x1cd)]),this[_0x34a5ae(0x1ce)]=_0x5aea42[_0x34a5ae(0x1ce)][_0x34a5ae(0x20c)](),this[_0x34a5ae(0x1d3)]=_0x5aea42['appApiKey']?.[_0x34a5ae(0x20c)]()||undefined,this['appSecret']=_0x5aea42[_0x34a5ae(0x1ea)]?.[_0x34a5ae(0x20c)]()||undefined,this[_0x34a5ae(0x1fe)]=_0x5aea42[_0x34a5ae(0x1fe)]??![],this[_0x34a5ae(0x1cf)]=axios_1['default']['create']({'baseURL':this['baseUrl']+'/oauth','timeout':0x7530,'headers':{'Content-Type':_0x34a5ae(0x1bf)}});}[_0x1184f5(0x20d)](_0xcb7bb4){const _0x16780a=_0x1184f5;return(_0xcb7bb4?.['trim']()||this[_0x16780a(0x1ce)])['trim']();}[_0x1184f5(0x1dd)](){const _0x3b92d3=_0x1184f5;if(this[_0x3b92d3(0x1d3)])return{'Authorization':_0x3b92d3(0x1dc)+this[_0x3b92d3(0x1d3)]};if(this[_0x3b92d3(0x1ea)])return{'X-Cliodot-App-Id':this[_0x3b92d3(0x1ce)],'X-Cliodot-App-Secret':this['appSecret']};throw new errors_1[(_0x3b92d3(0x1c2))](_0x3b92d3(0x200));}async[_0x1184f5(0x1f3)](_0x57a968,_0x435062,_0x578e81){const _0x3c1151=_0x1184f5,_0x1c443d={};_0x578e81?.['auth']!==![]&&Object['assign'](_0x1c443d,this[_0x3c1151(0x1dd)]());try{const {data:_0x33d8cf}=await this['axios']({'method':_0x57a968,'url':_0x435062,'headers':_0x1c443d,'data':_0x578e81?.[_0x3c1151(0x1c7)],'params':_0x578e81?.[_0x3c1151(0x1f5)],'validateStatus':_0x578e81?.[_0x3c1151(0x1d6)]===![]?_0xfb9873=>_0xfb9873<0x1f4:undefined});if(_0x33d8cf?.['ok']===![]){const _0x124a55=_0x33d8cf[_0x3c1151(0x1c5)];throw new errors_1[(_0x3c1151(0x1c2))]((0x0,parse_api_error_1[_0x3c1151(0x1eb)])(_0x33d8cf)||_0x3c1151(0x202),{'data':_0x33d8cf,'code':(0x0,parse_api_error_1[_0x3c1151(0x1b1)])(_0x33d8cf),'status':_0x124a55===0x1ac?0x1ac:undefined});}return _0x33d8cf;}catch(_0x42d368){if(_0x42d368 instanceof errors_1[_0x3c1151(0x1c2)])throw _0x42d368;const _0xfb8eea=(0x0,errors_1[_0x3c1151(0x1e4)])(_0x42d368,_0x3c1151(0x1b0)+_0x57a968+'\x20'+_0x435062);throw _0xfb8eea;}}async[_0x1184f5(0x1fb)](_0x11cfbd){const _0x1f17fc=_0x1184f5;return assertExchangeInput(_0x11cfbd),this[_0x1f17fc(0x1f3)](_0x1f17fc(0x1f8),_0x1f17fc(0x204),{'body':{'code':_0x11cfbd[_0x1f17fc(0x209)][_0x1f17fc(0x20c)](),'connection_id':_0x11cfbd[_0x1f17fc(0x1d9)][_0x1f17fc(0x20c)]()}});}}exports['OAuthAppClient']=OAuthAppClient;
|
|
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.OAuthAppClient = 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
|
+
const oauth_app_api_1 = require("./types/oauth-app.api");
|
|
12
|
+
function trimBaseUrl(url) {
|
|
13
|
+
return url.trim().replace(/\/+$/, "");
|
|
14
|
+
}
|
|
15
|
+
function resolveScope(input) {
|
|
16
|
+
if (input.scope?.trim()) {
|
|
17
|
+
return input.scope.trim();
|
|
18
|
+
}
|
|
19
|
+
if (input.scopes?.length) {
|
|
20
|
+
return input.scopes.filter(Boolean).join(" ");
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
function buildConnectQuery(input) {
|
|
25
|
+
const query = {
|
|
26
|
+
provider: input.provider.trim(),
|
|
27
|
+
redirect_uri: input.redirect_uri.trim(),
|
|
28
|
+
};
|
|
29
|
+
const scope = resolveScope(input);
|
|
30
|
+
if (scope)
|
|
31
|
+
query.scope = scope;
|
|
32
|
+
if (input.state)
|
|
33
|
+
query.state = input.state;
|
|
34
|
+
if (input.external_user_id)
|
|
35
|
+
query.external_user_id = input.external_user_id;
|
|
36
|
+
if (input.connection_storage)
|
|
37
|
+
query.connection_storage = input.connection_storage;
|
|
38
|
+
return query;
|
|
39
|
+
}
|
|
40
|
+
function buildConnectBody(input) {
|
|
41
|
+
const body = {
|
|
42
|
+
provider: input.provider.trim(),
|
|
43
|
+
redirect_uri: input.redirect_uri.trim(),
|
|
44
|
+
};
|
|
45
|
+
const scope = resolveScope(input);
|
|
46
|
+
if (scope)
|
|
47
|
+
body.scope = scope;
|
|
48
|
+
if (input.scopes?.length)
|
|
49
|
+
body.scopes = input.scopes;
|
|
50
|
+
if (input.state)
|
|
51
|
+
body.state = input.state;
|
|
52
|
+
if (input.external_user_id)
|
|
53
|
+
body.external_user_id = input.external_user_id;
|
|
54
|
+
if (input.connection_storage)
|
|
55
|
+
body.connection_storage = input.connection_storage;
|
|
56
|
+
if (input.assertion)
|
|
57
|
+
body.assertion = input.assertion;
|
|
58
|
+
if (input.subject_token)
|
|
59
|
+
body.subject_token = input.subject_token;
|
|
60
|
+
if (input.subject_token_type)
|
|
61
|
+
body.subject_token_type = input.subject_token_type;
|
|
62
|
+
if (input.requested_token_type)
|
|
63
|
+
body.requested_token_type = input.requested_token_type;
|
|
64
|
+
if (input.actor_token)
|
|
65
|
+
body.actor_token = input.actor_token;
|
|
66
|
+
if (input.actor_token_type)
|
|
67
|
+
body.actor_token_type = input.actor_token_type;
|
|
68
|
+
if (input.audience)
|
|
69
|
+
body.audience = input.audience;
|
|
70
|
+
return body;
|
|
71
|
+
}
|
|
72
|
+
function assertConnectInput(input) {
|
|
73
|
+
if (!input.provider?.trim()) {
|
|
74
|
+
throw new errors_1.CliodotApiError("connect requires provider");
|
|
75
|
+
}
|
|
76
|
+
if (!input.redirect_uri?.trim()) {
|
|
77
|
+
throw new errors_1.CliodotApiError("connect requires redirect_uri");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function assertPollInput(input) {
|
|
81
|
+
if (!input.provider?.trim()) {
|
|
82
|
+
throw new errors_1.CliodotApiError("poll requires provider");
|
|
83
|
+
}
|
|
84
|
+
if (!input.poll_state?.trim()) {
|
|
85
|
+
throw new errors_1.CliodotApiError("poll requires poll_state");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function assertExchangeInput(input) {
|
|
89
|
+
if (!input.code?.trim()) {
|
|
90
|
+
throw new errors_1.CliodotApiError("exchange requires code");
|
|
91
|
+
}
|
|
92
|
+
if (!input.connection_id?.trim()) {
|
|
93
|
+
throw new errors_1.CliodotApiError("exchange requires connection_id");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function assertConnectionId(connectionId) {
|
|
97
|
+
if (!connectionId?.trim()) {
|
|
98
|
+
throw new errors_1.CliodotApiError("connectionId is required");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function sleep(ms) {
|
|
102
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
103
|
+
}
|
|
104
|
+
class OAuthAppClient {
|
|
105
|
+
constructor(config) {
|
|
106
|
+
this.connect = {
|
|
107
|
+
start: async (input) => {
|
|
108
|
+
assertConnectInput(input);
|
|
109
|
+
const appId = this.resolveAppId(input.appId);
|
|
110
|
+
return this.request("POST", `/apps/${encodeURIComponent(appId)}/connect`, { body: buildConnectBody(input), auth: false });
|
|
111
|
+
},
|
|
112
|
+
poll: async (input) => {
|
|
113
|
+
assertPollInput(input);
|
|
114
|
+
const appId = this.resolveAppId(input.appId);
|
|
115
|
+
const intervalMs = input.pollIntervalMs ?? 5000;
|
|
116
|
+
const maxAttempts = input.maxAttempts ?? 120;
|
|
117
|
+
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
118
|
+
try {
|
|
119
|
+
return await this.request("POST", `/apps/${encodeURIComponent(appId)}/connect/poll`, {
|
|
120
|
+
body: {
|
|
121
|
+
provider: input.provider.trim(),
|
|
122
|
+
poll_state: input.poll_state.trim(),
|
|
123
|
+
},
|
|
124
|
+
auth: false,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
if (!(0, oauth_app_api_1.isDeviceAuthorizationPendingError)(err) || attempt === maxAttempts - 1) {
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
await sleep(intervalMs);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
throw new errors_1.CliodotApiError("Device authorization poll timed out");
|
|
135
|
+
},
|
|
136
|
+
buildUrl: (input) => {
|
|
137
|
+
assertConnectInput(input);
|
|
138
|
+
const appId = this.resolveAppId(input.appId);
|
|
139
|
+
const url = new URL(`${this.baseUrl}/oauth/apps/${encodeURIComponent(appId)}/connect`);
|
|
140
|
+
const query = buildConnectQuery(input);
|
|
141
|
+
for (const [key, value] of Object.entries(query)) {
|
|
142
|
+
url.searchParams.set(key, value);
|
|
143
|
+
}
|
|
144
|
+
return url.toString();
|
|
145
|
+
},
|
|
146
|
+
isSamlPostBinding: (response) => {
|
|
147
|
+
return response.sso_binding === "post" && !!response.saml_request && !!response.relay_state;
|
|
148
|
+
},
|
|
149
|
+
buildSamlPostForm: (response) => {
|
|
150
|
+
if (!response.saml_request || !response.relay_state || !response.authorization_url) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
if (response.sso_binding && response.sso_binding !== "post") {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
action: response.authorization_url,
|
|
158
|
+
samlRequest: response.saml_request,
|
|
159
|
+
relayState: response.relay_state,
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
this.connections = {
|
|
164
|
+
get: async (connectionId) => {
|
|
165
|
+
assertConnectionId(connectionId);
|
|
166
|
+
return this.request("GET", `/connections/${encodeURIComponent(connectionId.trim())}`);
|
|
167
|
+
},
|
|
168
|
+
getToken: async (connectionId) => {
|
|
169
|
+
assertConnectionId(connectionId);
|
|
170
|
+
return this.request("GET", `/connections/${encodeURIComponent(connectionId.trim())}/token`);
|
|
171
|
+
},
|
|
172
|
+
sync: async (connectionId) => {
|
|
173
|
+
return this.connections.getToken(connectionId);
|
|
174
|
+
},
|
|
175
|
+
refresh: async (connectionId) => {
|
|
176
|
+
assertConnectionId(connectionId);
|
|
177
|
+
return this.request("POST", `/connections/${encodeURIComponent(connectionId.trim())}/refresh`);
|
|
178
|
+
},
|
|
179
|
+
revoke: async (connectionId, input) => {
|
|
180
|
+
assertConnectionId(connectionId);
|
|
181
|
+
const body = {};
|
|
182
|
+
if (input?.reason?.trim()) {
|
|
183
|
+
body.reason = input.reason.trim();
|
|
184
|
+
}
|
|
185
|
+
return this.request("POST", `/connections/${encodeURIComponent(connectionId.trim())}/revoke`, { body: Object.keys(body).length ? body : undefined });
|
|
186
|
+
},
|
|
187
|
+
delete: async (connectionId) => {
|
|
188
|
+
assertConnectionId(connectionId);
|
|
189
|
+
return this.request("DELETE", `/connections/${encodeURIComponent(connectionId.trim())}`);
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
if (!config.baseUrl?.trim()) {
|
|
193
|
+
throw new errors_1.CliodotApiError("OAuthAppClient requires baseUrl");
|
|
194
|
+
}
|
|
195
|
+
if (!config.appId?.trim()) {
|
|
196
|
+
throw new errors_1.CliodotApiError("OAuthAppClient requires appId");
|
|
197
|
+
}
|
|
198
|
+
this.baseUrl = trimBaseUrl(config.baseUrl);
|
|
199
|
+
this.appId = config.appId.trim();
|
|
200
|
+
this.appApiKey = config.appApiKey?.trim() || undefined;
|
|
201
|
+
this.appSecret = config.appSecret?.trim() || undefined;
|
|
202
|
+
this.environment = config.environment;
|
|
203
|
+
this.debug = config.debug ?? false;
|
|
204
|
+
this.axios = axios_1.default.create({
|
|
205
|
+
baseURL: `${this.baseUrl}/oauth`,
|
|
206
|
+
timeout: 30000,
|
|
207
|
+
headers: { "Content-Type": "application/json" },
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
resolveAppId(appId) {
|
|
211
|
+
return (appId?.trim() || this.appId).trim();
|
|
212
|
+
}
|
|
213
|
+
buildS2SHeaders() {
|
|
214
|
+
if (this.appApiKey) {
|
|
215
|
+
return (0, cliodot_request_1.applyEnvironmentHeader)({ Authorization: `Bearer ${this.appApiKey}` }, this.environment);
|
|
216
|
+
}
|
|
217
|
+
if (this.appSecret) {
|
|
218
|
+
return (0, cliodot_request_1.applyEnvironmentHeader)({
|
|
219
|
+
"X-Cliodot-App-Id": this.appId,
|
|
220
|
+
"X-Cliodot-App-Secret": this.appSecret,
|
|
221
|
+
}, this.environment);
|
|
222
|
+
}
|
|
223
|
+
throw new errors_1.CliodotApiError("OAuth app credentials required (appApiKey or appSecret)");
|
|
224
|
+
}
|
|
225
|
+
async request(method, path, options) {
|
|
226
|
+
const headers = {};
|
|
227
|
+
if (options?.auth !== false) {
|
|
228
|
+
Object.assign(headers, this.buildS2SHeaders());
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const { data } = await this.axios({
|
|
232
|
+
method,
|
|
233
|
+
url: path,
|
|
234
|
+
headers,
|
|
235
|
+
data: options?.body,
|
|
236
|
+
params: options?.params,
|
|
237
|
+
validateStatus: options?.validateResponse === false
|
|
238
|
+
? (status) => status < 500
|
|
239
|
+
: undefined,
|
|
240
|
+
});
|
|
241
|
+
if (data?.ok === false) {
|
|
242
|
+
const status = data.statusCode;
|
|
243
|
+
throw new errors_1.CliodotApiError((0, parse_api_error_1.parseApiErrorMessage)(data) || "OAuth request failed", {
|
|
244
|
+
data,
|
|
245
|
+
code: (0, parse_api_error_1.parseApiErrorCode)(data),
|
|
246
|
+
status: status === 428 ? 428 : undefined,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return data;
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
if (err instanceof errors_1.CliodotApiError) {
|
|
253
|
+
throw err;
|
|
254
|
+
}
|
|
255
|
+
const apiErr = (0, errors_1.cliodotApiErrorFromAxios)(err, `Request failed: ${method} ${path}`);
|
|
256
|
+
throw apiErr;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async exchange(input) {
|
|
260
|
+
assertExchangeInput(input);
|
|
261
|
+
return this.request("POST", "/token/exchange", {
|
|
262
|
+
body: {
|
|
263
|
+
code: input.code.trim(),
|
|
264
|
+
connection_id: input.connection_id.trim(),
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.OAuthAppClient = OAuthAppClient;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CliodotFail, type CliodotMethodResult } from "./http/cliodot-result";
|
|
2
|
+
import type { ProviderCatalogResponse, ProviderExecuteInput, ProviderExecuteResult, ProviderSdkTypesArtifact, ProviderServicesClientConfig } from "./types/provider-services.api";
|
|
3
|
+
export declare class ProviderServicesClient<TCatalog = any> {
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly appId;
|
|
6
|
+
private readonly apiKey?;
|
|
7
|
+
private readonly appSecret?;
|
|
8
|
+
private readonly environment?;
|
|
9
|
+
private readonly axios;
|
|
10
|
+
private readonly configError;
|
|
11
|
+
readonly debug: boolean;
|
|
12
|
+
readonly api: TCatalog;
|
|
13
|
+
constructor(config: ProviderServicesClientConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Execute a catalog operation. Pass `provider` to pin a binding when routing allows it.
|
|
16
|
+
*/
|
|
17
|
+
execute<TResult = Record<string, unknown>>(input: ProviderExecuteInput): Promise<ProviderExecuteResult<TResult> | CliodotFail>;
|
|
18
|
+
catalog(): Promise<CliodotMethodResult<ProviderCatalogResponse>>;
|
|
19
|
+
downloadTypes(): Promise<CliodotMethodResult<ProviderSdkTypesArtifact>>;
|
|
20
|
+
private asProxy;
|
|
21
|
+
private buildAuthHeaders;
|
|
22
|
+
private request;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ProviderServicesClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderServicesClient.d.ts","sourceRoot":"","sources":["../src/ProviderServicesClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAGzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EAEpB,qBAAqB,EACrB,wBAAwB,EAExB,4BAA4B,EAC7B,MAAM,+BAA+B,CAAC;AAsCvC,qBAAa,sBAAsB,CAAC,QAAQ,GAAG,GAAG;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAC5D,SAAgB,KAAK,EAAE,OAAO,CAAC;IAC/B,SAAgB,GAAG,EAAE,QAAQ,CAAC;gBAElB,MAAM,EAAE,4BAA4B;IA2BhD;;OAEG;IACH,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;IAmBxD,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;IAI1D,aAAa,IAAI,OAAO,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;IAW7E,OAAO,CAAC,OAAO;IAoCf,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,OAAO;CAiBhB"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderServicesClient = void 0;
|
|
4
|
+
const create_client_1 = require("./http/create-client");
|
|
5
|
+
const cliodot_request_1 = require("./http/cliodot-request");
|
|
6
|
+
const cliodot_result_1 = require("./http/cliodot-result");
|
|
7
|
+
function trimBaseUrl(url) {
|
|
8
|
+
return url.trim().replace(/\/+$/, "");
|
|
9
|
+
}
|
|
10
|
+
function isExecuteResult(value) {
|
|
11
|
+
if (!value || typeof value !== "object")
|
|
12
|
+
return false;
|
|
13
|
+
const obj = value;
|
|
14
|
+
return (typeof obj.service === "string" &&
|
|
15
|
+
typeof obj.operation === "string" &&
|
|
16
|
+
Array.isArray(obj.attempts));
|
|
17
|
+
}
|
|
18
|
+
function normalizeExecuteResult(data, status) {
|
|
19
|
+
if (!isExecuteResult(data))
|
|
20
|
+
return null;
|
|
21
|
+
if (status === 502 || data.ok === false) {
|
|
22
|
+
const error = data.error;
|
|
23
|
+
return {
|
|
24
|
+
...data,
|
|
25
|
+
ok: false,
|
|
26
|
+
error: {
|
|
27
|
+
code: error?.code || cliodot_result_1.SDK_ERROR.REQUEST_FAILED,
|
|
28
|
+
message: error?.message || "Provider execute failed",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (data.ok === true) {
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
return { ...data, ok: true };
|
|
36
|
+
}
|
|
37
|
+
class ProviderServicesClient {
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.configError = (0, cliodot_result_1.resolveConfigError)([
|
|
40
|
+
{
|
|
41
|
+
valid: !!config.baseUrl?.trim(),
|
|
42
|
+
message: "ProviderServicesClient requires baseUrl",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
valid: !!config.appId?.trim(),
|
|
46
|
+
message: "ProviderServicesClient requires appId",
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
this.baseUrl = trimBaseUrl(config.baseUrl || "");
|
|
50
|
+
this.appId = config.appId?.trim() || "";
|
|
51
|
+
this.apiKey =
|
|
52
|
+
config.apiKey?.trim() || config.appApiKey?.trim() || undefined;
|
|
53
|
+
this.appSecret = config.appSecret?.trim() || undefined;
|
|
54
|
+
this.environment = config.environment;
|
|
55
|
+
this.debug = config.debug ?? false;
|
|
56
|
+
this.axios = (0, create_client_1.createCliodotAxios)({
|
|
57
|
+
baseURL: `${this.baseUrl}/provider`,
|
|
58
|
+
timeout: config.timeoutMs ?? 60000,
|
|
59
|
+
headers: { "Content-Type": "application/json" },
|
|
60
|
+
validateStatus: (status) => status === 200 || status === 502,
|
|
61
|
+
});
|
|
62
|
+
this.api = this.asProxy();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Execute a catalog operation. Pass `provider` to pin a binding when routing allows it.
|
|
66
|
+
*/
|
|
67
|
+
execute(input) {
|
|
68
|
+
const serviceError = (0, cliodot_result_1.resolveRequiredString)(input?.service, "service");
|
|
69
|
+
if (serviceError)
|
|
70
|
+
return Promise.resolve(serviceError);
|
|
71
|
+
const operationError = (0, cliodot_result_1.resolveRequiredString)(input?.operation, "operation");
|
|
72
|
+
if (operationError)
|
|
73
|
+
return Promise.resolve(operationError);
|
|
74
|
+
const body = {
|
|
75
|
+
service: input.service.trim(),
|
|
76
|
+
operation: input.operation.trim(),
|
|
77
|
+
input: input.input ?? {},
|
|
78
|
+
};
|
|
79
|
+
if (input.version?.trim())
|
|
80
|
+
body.version = input.version.trim();
|
|
81
|
+
if (input.provider?.trim())
|
|
82
|
+
body.provider = input.provider.trim();
|
|
83
|
+
if (input.idempotency_key?.trim()) {
|
|
84
|
+
body.idempotency_key = input.idempotency_key.trim();
|
|
85
|
+
}
|
|
86
|
+
return this.request("POST", "/v1/execute", body);
|
|
87
|
+
}
|
|
88
|
+
catalog() {
|
|
89
|
+
return this.request("GET", "/v1/catalog");
|
|
90
|
+
}
|
|
91
|
+
async downloadTypes() {
|
|
92
|
+
const result = await this.request("GET", "/v1/types");
|
|
93
|
+
if ((0, cliodot_result_1.isCliodotFail)(result))
|
|
94
|
+
return result;
|
|
95
|
+
return {
|
|
96
|
+
ok: true,
|
|
97
|
+
typescript: result.typescript,
|
|
98
|
+
filename: result.filename,
|
|
99
|
+
export_name: result.export_name,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
asProxy(path = []) {
|
|
103
|
+
const client = this;
|
|
104
|
+
const callable = (...args) => {
|
|
105
|
+
if (path.length !== 2) {
|
|
106
|
+
return Promise.resolve((0, cliodot_result_1.cliodotValidationFail)("Provider fluent calls are service.operation(input, opts?)"));
|
|
107
|
+
}
|
|
108
|
+
const [service, operation] = path;
|
|
109
|
+
const input = args[0] ?? {};
|
|
110
|
+
const opts = args[1] || {};
|
|
111
|
+
return client.execute({
|
|
112
|
+
service,
|
|
113
|
+
operation,
|
|
114
|
+
input,
|
|
115
|
+
version: opts.version,
|
|
116
|
+
provider: opts.provider,
|
|
117
|
+
idempotency_key: opts.idempotency_key,
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
return new Proxy(callable, {
|
|
121
|
+
get(_target, prop) {
|
|
122
|
+
if (typeof prop === "symbol")
|
|
123
|
+
return undefined;
|
|
124
|
+
if (prop === "then")
|
|
125
|
+
return undefined;
|
|
126
|
+
if (prop === "toString")
|
|
127
|
+
return () => "[ProviderServicesClient.api]";
|
|
128
|
+
return client.asProxy([...path, String(prop)]);
|
|
129
|
+
},
|
|
130
|
+
apply(_target, _thisArg, argArray) {
|
|
131
|
+
return callable(...(argArray || []));
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
buildAuthHeaders() {
|
|
136
|
+
return (0, cliodot_request_1.resolveBearerAuthHeaders)({
|
|
137
|
+
appId: this.appId,
|
|
138
|
+
apiKey: this.apiKey,
|
|
139
|
+
appSecret: this.appSecret,
|
|
140
|
+
environment: this.environment,
|
|
141
|
+
missingMessage: "Provider app credentials required (apiKey/appApiKey or appSecret)",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
request(method, path, body) {
|
|
145
|
+
return (0, cliodot_request_1.executeCliodotRequest)({
|
|
146
|
+
configError: this.configError,
|
|
147
|
+
authHeaders: this.buildAuthHeaders(),
|
|
148
|
+
axios: this.axios,
|
|
149
|
+
method,
|
|
150
|
+
path,
|
|
151
|
+
body,
|
|
152
|
+
validateStatus: (status) => status === 200 || status === 502,
|
|
153
|
+
passThrough: (data, status) => normalizeExecuteResult(data, status),
|
|
154
|
+
fallbackMessage: `Request failed: ${method} ${path}`,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.ProviderServicesClient = ProviderServicesClient;
|
package/dist/Surface.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface SurfaceConfig {
|
|
|
6
6
|
apiKeyHeader?: string;
|
|
7
7
|
fetchSurface?: boolean;
|
|
8
8
|
version?: string;
|
|
9
|
+
/** Pin project env bag for connector auth templates. Omit to follow the project switch. */
|
|
10
|
+
environment?: "dev" | "prod" | "development" | "production";
|
|
9
11
|
}
|
|
10
12
|
export interface SurfaceOp {
|
|
11
13
|
id: string;
|
package/dist/Surface.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Surface.d.ts","sourceRoot":"","sources":["../src/Surface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Surface.d.ts","sourceRoot":"","sources":["../src/Surface.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2FAA2F;IAC3F,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,aAAa,GAAG,YAAY,CAAC;CAC7D;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7C,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IACF,GAAG,EAAE,SAAS,EAAE,CAAC;CAClB;AAwSD,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,QAAQ,GAAG,GAAG,IAAI,QAAQ,GAAG,cAAc,CAAC;AAEtE,KAAK,kBAAkB,GAAG;IACxB,KAAK,QAAQ,GAAG,GAAG,EAAE,MAAM,EAAE,aAAa,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;CACtE,CAAC;AAEF,eAAO,MAAM,OAAO,EAMJ,kBAAkB,CAAC"}
|