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.
Files changed (147) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +81 -0
  3. package/dist/AuthAppClient.d.ts +1 -0
  4. package/dist/AuthAppClient.d.ts.map +1 -1
  5. package/dist/AuthAppClient.js +199 -1
  6. package/dist/CommercialAppClient.d.ts +178 -0
  7. package/dist/CommercialAppClient.d.ts.map +1 -0
  8. package/dist/CommercialAppClient.js +576 -0
  9. package/dist/ConnectorBuilder.js +104 -1
  10. package/dist/Events.d.ts +2 -0
  11. package/dist/Events.d.ts.map +1 -1
  12. package/dist/Events.js +325 -1
  13. package/dist/Flosync.js +296 -1
  14. package/dist/FlosyncClient.js +429 -1
  15. package/dist/FunctionBuilder.js +65 -1
  16. package/dist/IdentityAppClient.d.ts +23 -0
  17. package/dist/IdentityAppClient.d.ts.map +1 -0
  18. package/dist/IdentityAppClient.js +197 -0
  19. package/dist/MemoryAppClient.d.ts +28 -0
  20. package/dist/MemoryAppClient.d.ts.map +1 -0
  21. package/dist/MemoryAppClient.js +149 -0
  22. package/dist/MemoryClient.d.ts +8 -0
  23. package/dist/MemoryClient.d.ts.map +1 -0
  24. package/dist/MemoryClient.js +20 -0
  25. package/dist/OAuthAppClient.d.ts +1 -0
  26. package/dist/OAuthAppClient.d.ts.map +1 -1
  27. package/dist/OAuthAppClient.js +269 -1
  28. package/dist/ProviderServicesClient.d.ts +24 -0
  29. package/dist/ProviderServicesClient.d.ts.map +1 -0
  30. package/dist/ProviderServicesClient.js +158 -0
  31. package/dist/Surface.d.ts +2 -0
  32. package/dist/Surface.d.ts.map +1 -1
  33. package/dist/Surface.js +255 -1
  34. package/dist/ValidatorBuilder.js +24 -1
  35. package/dist/Webhooks.d.ts +20 -0
  36. package/dist/Webhooks.d.ts.map +1 -0
  37. package/dist/Webhooks.js +61 -0
  38. package/dist/WorkflowBuilder.js +279 -1
  39. package/dist/__tests__/CommercialAppClient.test.d.ts +2 -0
  40. package/dist/__tests__/CommercialAppClient.test.d.ts.map +1 -0
  41. package/dist/__tests__/CommercialAppClient.test.js +217 -0
  42. package/dist/__tests__/Events.test.js +191 -1
  43. package/dist/__tests__/IdentityAppClient.test.d.ts +2 -0
  44. package/dist/__tests__/IdentityAppClient.test.d.ts.map +1 -0
  45. package/dist/__tests__/IdentityAppClient.test.js +232 -0
  46. package/dist/__tests__/OAuthAppClient.test.js +300 -1
  47. package/dist/__tests__/ProviderServicesClient.test.d.ts +2 -0
  48. package/dist/__tests__/ProviderServicesClient.test.d.ts.map +1 -0
  49. package/dist/__tests__/ProviderServicesClient.test.js +131 -0
  50. package/dist/__tests__/Surface.test.js +150 -1
  51. package/dist/__tests__/errors.test.js +54 -1
  52. package/dist/__tests__/function.test.js +58 -1
  53. package/dist/__tests__/helpers.d.ts +5 -0
  54. package/dist/__tests__/helpers.d.ts.map +1 -0
  55. package/dist/__tests__/helpers.js +10 -0
  56. package/dist/__tests__/localhost-lookup.test.d.ts +2 -0
  57. package/dist/__tests__/localhost-lookup.test.d.ts.map +1 -0
  58. package/dist/__tests__/localhost-lookup.test.js +26 -0
  59. package/dist/__tests__/parse-api-error.test.js +26 -1
  60. package/dist/__tests__/runner.test.js +156 -1
  61. package/dist/connectors/builtin.js +354 -1
  62. package/dist/connectors/registry.js +300 -1
  63. package/dist/decorators/build.js +105 -1
  64. package/dist/decorators/connector.js +56 -1
  65. package/dist/decorators/index.js +34 -1
  66. package/dist/decorators/metadata.js +338 -1
  67. package/dist/decorators/steps.js +220 -1
  68. package/dist/decorators/workflow.js +52 -1
  69. package/dist/errors.js +76 -1
  70. package/dist/http/__tests__/cliodot-request.environment.test.d.ts +2 -0
  71. package/dist/http/__tests__/cliodot-request.environment.test.d.ts.map +1 -0
  72. package/dist/http/__tests__/cliodot-request.environment.test.js +37 -0
  73. package/dist/http/__tests__/cliodot-result.test.d.ts +2 -0
  74. package/dist/http/__tests__/cliodot-result.test.d.ts.map +1 -0
  75. package/dist/http/__tests__/cliodot-result.test.js +57 -0
  76. package/dist/http/__tests__/events-instance-id.test.d.ts +2 -0
  77. package/dist/http/__tests__/events-instance-id.test.d.ts.map +1 -0
  78. package/dist/http/__tests__/events-instance-id.test.js +45 -0
  79. package/dist/http/cliodot-request.d.ts +35 -0
  80. package/dist/http/cliodot-request.d.ts.map +1 -0
  81. package/dist/http/cliodot-request.js +105 -0
  82. package/dist/http/cliodot-result.d.ts +40 -0
  83. package/dist/http/cliodot-result.d.ts.map +1 -0
  84. package/dist/http/cliodot-result.js +139 -0
  85. package/dist/http/create-client.d.ts +3 -0
  86. package/dist/http/create-client.d.ts.map +1 -0
  87. package/dist/http/create-client.js +14 -0
  88. package/dist/http/events-instance-id.d.ts +11 -0
  89. package/dist/http/events-instance-id.d.ts.map +1 -0
  90. package/dist/http/events-instance-id.js +86 -0
  91. package/dist/http/localhost-lookup.d.ts +12 -0
  92. package/dist/http/localhost-lookup.d.ts.map +1 -0
  93. package/dist/http/localhost-lookup.js +67 -0
  94. package/dist/http/parse-api-error.js +56 -1
  95. package/dist/http/sanitize-execution-headers.js +79 -1
  96. package/dist/identity-offline-verify.d.ts +6 -0
  97. package/dist/identity-offline-verify.d.ts.map +1 -0
  98. package/dist/identity-offline-verify.js +174 -0
  99. package/dist/identity-token-cache.d.ts +6 -0
  100. package/dist/identity-token-cache.d.ts.map +1 -0
  101. package/dist/identity-token-cache.js +51 -0
  102. package/dist/index.d.ts +10 -0
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +108 -1
  105. package/dist/runner/ProcessorEngine.js +1311 -1
  106. package/dist/runner/connector.executor.js +1786 -1
  107. package/dist/runner/utilities/math.executor.js +153 -1
  108. package/dist/runner/utilities/random.executor.js +151 -1
  109. package/dist/runner/utilities/string.executor.js +825 -1
  110. package/dist/template.js +127 -1
  111. package/dist/transformers/StepsToNodesTransformer.js +214 -1
  112. package/dist/transformers/WorkflowTransformer.js +189 -1
  113. package/dist/types/auth-app.api.d.ts +2 -0
  114. package/dist/types/auth-app.api.d.ts.map +1 -1
  115. package/dist/types/auth-app.api.js +2 -1
  116. package/dist/types/builtin.js +2 -1
  117. package/dist/types/client.api.js +2 -1
  118. package/dist/types/commercial-app.api.d.ts +963 -0
  119. package/dist/types/commercial-app.api.d.ts.map +1 -0
  120. package/dist/types/commercial-app.api.js +2 -0
  121. package/dist/types/connector.js +2 -1
  122. package/dist/types/context.js +2 -1
  123. package/dist/types/event-app.api.d.ts +8 -0
  124. package/dist/types/event-app.api.d.ts.map +1 -1
  125. package/dist/types/event-app.api.js +2 -1
  126. package/dist/types/function.js +2 -1
  127. package/dist/types/identity-app.api.d.ts +99 -0
  128. package/dist/types/identity-app.api.d.ts.map +1 -0
  129. package/dist/types/identity-app.api.js +2 -0
  130. package/dist/types/index.js +23 -1
  131. package/dist/types/memory-app.api.d.ts +140 -0
  132. package/dist/types/memory-app.api.d.ts.map +1 -0
  133. package/dist/types/memory-app.api.js +2 -0
  134. package/dist/types/oauth-app.api.d.ts +2 -0
  135. package/dist/types/oauth-app.api.d.ts.map +1 -1
  136. package/dist/types/oauth-app.api.js +105 -1
  137. package/dist/types/provider-services.api.d.ts +98 -0
  138. package/dist/types/provider-services.api.d.ts.map +1 -0
  139. package/dist/types/provider-services.api.js +2 -0
  140. package/dist/types/validator.js +2 -1
  141. package/dist/types/webhook-app.api.d.ts +2 -0
  142. package/dist/types/webhook-app.api.d.ts.map +1 -0
  143. package/dist/types/webhook-app.api.js +2 -0
  144. package/dist/types/workflow.js +33 -1
  145. package/dist/validators/validators.js +478 -1
  146. package/dist/variable.js +37 -1
  147. package/package.json +3 -2
@@ -1 +1,191 @@
1
- 'use strict';const _0x47b85d=_0x2344;(function(_0x2116e1,_0x4036f9){const _0x4bc500=_0x2344,_0x26104a=_0x2116e1();while(!![]){try{const _0x14c20b=parseInt(_0x4bc500(0x175))/0x1+parseInt(_0x4bc500(0x150))/0x2*(parseInt(_0x4bc500(0x14f))/0x3)+-parseInt(_0x4bc500(0x14c))/0x4+-parseInt(_0x4bc500(0x15d))/0x5+parseInt(_0x4bc500(0x158))/0x6*(parseInt(_0x4bc500(0x152))/0x7)+parseInt(_0x4bc500(0x173))/0x8*(parseInt(_0x4bc500(0x169))/0x9)+-parseInt(_0x4bc500(0x146))/0xa*(parseInt(_0x4bc500(0x182))/0xb);if(_0x14c20b===_0x4036f9)break;else _0x26104a['push'](_0x26104a['shift']());}catch(_0x37620f){_0x26104a['push'](_0x26104a['shift']());}}}(_0x48a8,0xd428e));var __importDefault=this&&this[_0x47b85d(0x16e)]||function(_0x5d711a){const _0x490b0a=_0x47b85d;return _0x5d711a&&_0x5d711a[_0x490b0a(0x167)]?_0x5d711a:{'default':_0x5d711a};};Object[_0x47b85d(0x163)](exports,_0x47b85d(0x167),{'value':!![]});const axios_1=__importDefault(require('axios')),Events_1=require('../Events'),errors_1=require('../errors');jest['mock'](_0x47b85d(0x176));function _0x2344(_0x8c4169,_0x532e71){_0x8c4169=_0x8c4169-0x13d;const _0x48a894=_0x48a8();let _0x234444=_0x48a894[_0x8c4169];if(_0x2344['auijDx']===undefined){var _0x29d961=function(_0x3d8b73){const _0x3516b8='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5d711a='',_0x3c6c01='';for(let _0x43f447=0x0,_0x3d9910,_0x12ac55,_0x4cb325=0x0;_0x12ac55=_0x3d8b73['charAt'](_0x4cb325++);~_0x12ac55&&(_0x3d9910=_0x43f447%0x4?_0x3d9910*0x40+_0x12ac55:_0x12ac55,_0x43f447++%0x4)?_0x5d711a+=String['fromCharCode'](0xff&_0x3d9910>>(-0x2*_0x43f447&0x6)):0x0){_0x12ac55=_0x3516b8['indexOf'](_0x12ac55);}for(let _0x2463e4=0x0,_0x1a90b6=_0x5d711a['length'];_0x2463e4<_0x1a90b6;_0x2463e4++){_0x3c6c01+='%'+('00'+_0x5d711a['charCodeAt'](_0x2463e4)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3c6c01);};_0x2344['yLXVwi']=_0x29d961,_0x2344['WTbZXF']={},_0x2344['auijDx']=!![];}const _0x257e03=_0x48a894[0x0],_0x7f3ad7=_0x8c4169+_0x257e03,_0x3010c5=_0x2344['WTbZXF'][_0x7f3ad7];return!_0x3010c5?(_0x234444=_0x2344['yLXVwi'](_0x234444),_0x2344['WTbZXF'][_0x7f3ad7]=_0x234444):_0x234444=_0x3010c5,_0x234444;}const mockedAxios=axios_1['default'];describe(_0x47b85d(0x168),()=>{const _0x1f69e2=_0x47b85d,_0x3c6c01=jest['fn']();beforeEach(()=>{const _0x3a3995=_0x2344;jest['clearAllMocks'](),mockedAxios[_0x3a3995(0x166)][_0x3a3995(0x15c)](_0x3c6c01);});function _0x43f447(_0x3d9910){const _0x441471=_0x2344;return new Events_1[(_0x441471(0x168))]({'baseUrl':_0x441471(0x161),'appId':_0x441471(0x15f),'apiKey':'eak_test_key',..._0x3d9910});}it('requires\x20baseUrl\x20and\x20appId',()=>{const _0x1da3f0=_0x2344;expect(()=>new Events_1[(_0x1da3f0(0x168))]({'baseUrl':'','appId':_0x1da3f0(0x15f)}))[_0x1da3f0(0x172)](errors_1[_0x1da3f0(0x14e)]),expect(()=>new Events_1[(_0x1da3f0(0x168))]({'baseUrl':_0x1da3f0(0x161),'appId':''}))[_0x1da3f0(0x172)](errors_1['CliodotApiError']);}),it(_0x1f69e2(0x177),async()=>{const _0x452df9=_0x1f69e2;_0x3c6c01['mockResolvedValue']({'data':{'ok':!![],'event_id':_0x452df9(0x155),'accepted':!![]}});const _0x12ac55=_0x43f447(),_0x4cb325=await _0x12ac55['publish'](_0x452df9(0x160),{'id':'ord_1'},{'ordering_key':_0x452df9(0x16c)});expect(_0x4cb325['event_id'])[_0x452df9(0x174)](_0x452df9(0x155)),expect(_0x3c6c01)[_0x452df9(0x17c)](expect[_0x452df9(0x14a)]({'method':_0x452df9(0x147),'url':_0x452df9(0x171),'headers':{'Authorization':_0x452df9(0x145),'x-cliodot-app-id':_0x452df9(0x15f)},'data':{'event':_0x452df9(0x160),'payload':{'id':_0x452df9(0x16c)},'ordering_key':'ord_1'}}));}),it(_0x1f69e2(0x14d),async()=>{const _0x546854=_0x1f69e2;_0x3c6c01['mockResolvedValue']({'data':{'ok':!![],'subscription_id':_0x546854(0x178),'events':[_0x546854(0x160)]}});const _0x2463e4=_0x43f447({'apiKey':undefined,'appSecret':_0x546854(0x154)});await _0x2463e4[_0x546854(0x13d)]({'events':['order.created'],'name':_0x546854(0x148)}),expect(_0x3c6c01)['toHaveBeenCalledWith'](expect[_0x546854(0x14a)]({'method':_0x546854(0x147),'url':_0x546854(0x17f),'headers':{'x-cliodot-app-id':_0x546854(0x15f),'x-cliodot-app-secret':_0x546854(0x154)},'data':{'events':['order.created'],'name':_0x546854(0x148)}}));}),it('unsubscribes\x20by\x20id',async()=>{const _0x2efa4c=_0x1f69e2;_0x3c6c01[_0x2efa4c(0x157)]({'data':{'ok':!![],'deleted':!![]}});const _0x1a90b6=_0x43f447(),_0x3929a2=await _0x1a90b6[_0x2efa4c(0x13f)](_0x2efa4c(0x178));expect(_0x3929a2[_0x2efa4c(0x170)])['toBe'](!![]),expect(_0x3c6c01)['toHaveBeenCalledWith'](expect[_0x2efa4c(0x14a)]({'method':_0x2efa4c(0x141),'url':_0x2efa4c(0x17d)}));}),it(_0x1f69e2(0x165),()=>{const _0x2c407a=_0x1f69e2,_0x328604=_0x43f447(),_0x3b8e1f=_0x328604[_0x2c407a(0x164)]({'events':[_0x2c407a(0x160),_0x2c407a(0x179)]});expect(_0x3b8e1f)[_0x2c407a(0x174)](_0x2c407a(0x151));}),it(_0x1f69e2(0x16d),async()=>{const _0x1cfd2b=_0x1f69e2;_0x3c6c01[_0x1cfd2b(0x157)]({'data':{'ok':!![],'event_id':_0x1cfd2b(0x14b),'accepted':!![]}});const _0xc0ec17=_0x43f447({'apiKey':undefined,'appApiKey':_0x1cfd2b(0x162)});await _0xc0ec17['publish'](_0x1cfd2b(0x144),{}),expect(_0x3c6c01)[_0x1cfd2b(0x17c)](expect[_0x1cfd2b(0x14a)]({'headers':expect[_0x1cfd2b(0x14a)]({'Authorization':'Bearer\x20eak_alias'})}));}),it('auto-reconnects\x20listen\x20after\x20stream\x20ends\x20until\x20close',async()=>{const _0x59838b=_0x1f69e2;jest[_0x59838b(0x159)]();const {EventEmitter:_0x4816c4}=require(_0x59838b(0x143)),_0x3eee80=new _0x4816c4(),_0x2924ff=new _0x4816c4();_0x3eee80[_0x59838b(0x140)]=jest['fn'](),_0x2924ff[_0x59838b(0x140)]=jest['fn'](),_0x3c6c01['mockResolvedValueOnce']({'data':_0x3eee80})['mockResolvedValueOnce']({'data':_0x2924ff});const _0x5181c5=_0x43f447({'debug':![]}),_0x3ac195=[],_0x52ce49=_0x5181c5[_0x59838b(0x17a)]({'events':['order.created']},_0x25c9c6=>{const _0x3fb72a=_0x59838b;_0x3ac195[_0x3fb72a(0x142)](_0x25c9c6);});await Promise['resolve'](),await Promise[_0x59838b(0x156)](),_0x3eee80['emit'](_0x59838b(0x17e),Buffer[_0x59838b(0x15b)]('data:\x20{\x22type\x22:\x22connected\x22,\x22listener_id\x22:\x22sse_1\x22,\x22events\x22:[\x22order.created\x22]}\x0a\x0a')),_0x3eee80[_0x59838b(0x17b)](_0x59838b(0x13e)),await Promise[_0x59838b(0x156)](),expect(_0x3ac195)['toHaveLength'](0x1),await jest[_0x59838b(0x183)](0x3e8),await Promise[_0x59838b(0x156)](),await Promise[_0x59838b(0x156)](),_0x2924ff['emit']('data',Buffer['from'](_0x59838b(0x149))),expect(_0x3ac195)[_0x59838b(0x15e)](0x2),expect(_0x3c6c01)[_0x59838b(0x16a)](0x2),_0x52ce49[_0x59838b(0x16b)](),jest['useRealTimers']();}),it('does\x20not\x20reconnect\x20when\x20reconnect\x20is\x20false',async()=>{const _0x4d426d=_0x1f69e2;jest[_0x4d426d(0x159)]();const {EventEmitter:_0x312caf}=require('events'),_0x1c5125=new _0x312caf();_0x1c5125[_0x4d426d(0x140)]=jest['fn'](),_0x3c6c01[_0x4d426d(0x180)]({'data':_0x1c5125});const _0x3fee3d=_0x43f447();_0x3fee3d[_0x4d426d(0x17a)]({'events':[_0x4d426d(0x160)],'reconnect':![]},()=>{}),await Promise['resolve'](),await Promise[_0x4d426d(0x156)](),_0x1c5125[_0x4d426d(0x17b)](_0x4d426d(0x13e)),await Promise[_0x4d426d(0x156)](),await jest['advanceTimersByTimeAsync'](0x1388),expect(_0x3c6c01)[_0x4d426d(0x16a)](0x1),jest['useRealTimers']();}),it(_0x1f69e2(0x16f),async()=>{const _0x1f92bf=_0x1f69e2;_0x3c6c01[_0x1f92bf(0x157)]({'data':{'ok':!![],'event_id':_0x1f92bf(0x15a),'accepted':!![]}});const _0x5696ea=_0x43f447();await _0x5696ea[_0x1f92bf(0x153)](_0x1f92bf(0x160),{'id':'1'},{'environment':'dev'}),expect(_0x3c6c01)[_0x1f92bf(0x17c)](expect['objectContaining']({'data':expect[_0x1f92bf(0x14a)]({'event':_0x1f92bf(0x160),'environment':_0x1f92bf(0x181)})}));});});function _0x48a8(){const _0x21992c=['y2HLy2TVDxq','zgf0ytOGEYj0ExbLiJOIy29UBMvJDgvKiIWIBgLZDgvUzxjFAwqIoIjZC2vFmIiSiMv2zw50CYi6wYjVCMrLCI5JCMvHDgvKiL19cGO','B2jQzwn0q29UDgfPBMLUzW','zxz0xZi','nta1mJi4uxP3BwPx','DxnLCYbHChaGC2vJCMv0igHLywrLCNmGD2HLBIbHCgKGA2v5igLZigfIC2vUDa','q2XPB2rVDefWAuvYCM9Y','mti4mtnWCurqBe8','mZy2AwfqvMTZ','Ahr0Chm6lY9HCgKUzxHHBxbSzs5JB20VzxzLBNqVDJeVBgLZDgvUp2fWCf9Pzd1LDNrFyxbWx3rLC3qMywnJzxnZx3rVA2vUpwvHA190zxn0x2TLEszLDMvUDhm9B3jKzxiUy3jLyxrLzcuYq3bHEw1LBNqUy29TCgXLDgvK','nJnuvxjfr3i','ChvIBgLZAa','C2vJCMv0xZe','zxz0xZe','CMvZB2X2zq','Bw9JA1jLC29SDMvKvMfSDwu','mZm0nZiYqLvsyLPZ','DxnLrMfRzvrPBwvYCW','zxz0x2vUDG','zNjVBq','Bw9JA1jLDhvYBLzHBhvL','mtyXnJiWnvnVsLbfsW','Dg9iyxzLtgvUz3rO','zxz0x2fWCf90zxn0','B3jKzxiUy3jLyxrLza','Ahr0Chm6lY9HCgKUzxHHBxbSzs5JB20','zwfRx2fSAwfZ','zgvMAw5LuhjVCgvYDhK','BgLZDgvUvxjS','yNvPBgrZigjYB3DZzxiGBgLZDgvUvxjSihDPDgGGCxvLCNKGyxv0Aa','y3jLyxrL','x19LC01VzhvSzq','rxzLBNrZ','ntC4n3f0uvP1wG','Dg9iyxzLqMvLBKnHBgXLzfrPBwvZ','y2XVC2u','B3jKxZe','ywnJzxb0CYbHChbbCgLlzxKGywXPyxm','x19PBxbVCNrezwzHDwX0','CgfZC2vZigvUDMLYB25Tzw50ig9Uihb1yMXPC2G','zgvSzxrLza','l3yXl3b1yMXPC2G','Dg9uAhjVDW','mta1mZzQrMPAAei','Dg9czq','mti4ntmXmuHoALHLtq','yxHPB3m','ChvIBgLZAgvZihDPDgGGyMvHCMvYigfWAsbRzxKGyw5KigfWCcbPzcbOzwfKzxi','zxz0x3n1yL8X','Cgf5BwvUDc5JB21WBgv0zwq','BgLZDgvU','zw1PDa','Dg9iyxzLqMvLBKnHBgXLzfDPDgG','l3yXl3n1yNnJCMLIzs9LDNrFC3vIxZe','zgf0yq','l3yXl3n1yNnJCMLIzq','Bw9JA1jLC29SDMvKvMfSDwvpBMnL','zgv2','mZG0ndK4ngTlDMrHDW','ywr2yw5JzvrPBwvYC0j5vgLTzufZEw5J','C3vIC2nYAwjL','zw5K','Dw5ZDwjZy3jPyMu','zgvZDhjVEq','revmrvrf','ChvZAa','zxzLBNrZ','CgLUzW','qMvHCMvYigvHA190zxn0x2TLEq','nJbYwhbpz2K','ue9tva'];_0x48a8=function(){return _0x21992c;};return _0x48a8();}
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const axios_1 = __importDefault(require("axios"));
7
+ const Events_1 = require("../Events");
8
+ const errors_1 = require("../errors");
9
+ jest.mock("axios");
10
+ const mockedAxios = axios_1.default;
11
+ describe("Events", () => {
12
+ const mockAxiosInstance = jest.fn();
13
+ beforeEach(() => {
14
+ jest.clearAllMocks();
15
+ mockedAxios.create.mockReturnValue(mockAxiosInstance);
16
+ });
17
+ function createClient(overrides) {
18
+ return new Events_1.Events({
19
+ baseUrl: "https://api.example.com",
20
+ appId: "evt_app_test",
21
+ apiKey: "eak_test_key",
22
+ instanceId: "test-instance",
23
+ ...overrides,
24
+ });
25
+ }
26
+ it("requires baseUrl and appId", () => {
27
+ expect(() => new Events_1.Events({ baseUrl: "", appId: "evt_app_test" })).toThrow(errors_1.CliodotApiError);
28
+ expect(() => new Events_1.Events({ baseUrl: "https://api.example.com", appId: "" })).toThrow(errors_1.CliodotApiError);
29
+ });
30
+ it("publishes with bearer api key and app id header", async () => {
31
+ mockAxiosInstance.mockResolvedValue({
32
+ data: { ok: true, event_id: "evt_1", accepted: true },
33
+ });
34
+ const client = createClient();
35
+ const result = await client.publish("order.created", { id: "ord_1" }, {
36
+ ordering_key: "ord_1",
37
+ });
38
+ expect(result.event_id).toBe("evt_1");
39
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
40
+ method: "POST",
41
+ url: "/v1/publish",
42
+ headers: {
43
+ Authorization: "Bearer eak_test_key",
44
+ "x-cliodot-app-id": "evt_app_test",
45
+ "x-cliodot-instance-id": "test-instance",
46
+ },
47
+ data: {
48
+ event: "order.created",
49
+ payload: { id: "ord_1" },
50
+ ordering_key: "ord_1",
51
+ },
52
+ }));
53
+ });
54
+ it("uses app secret headers when api key is absent", async () => {
55
+ mockAxiosInstance.mockResolvedValue({
56
+ data: { ok: true, subscription_id: "evt_sub_1", events: ["order.created"] },
57
+ });
58
+ const client = createClient({
59
+ apiKey: undefined,
60
+ appSecret: "secret_1",
61
+ });
62
+ await client.subscribe({ events: ["order.created"], name: "checkout" });
63
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
64
+ method: "POST",
65
+ url: "/v1/subscribe",
66
+ headers: {
67
+ "x-cliodot-app-id": "evt_app_test",
68
+ "x-cliodot-app-secret": "secret_1",
69
+ "x-cliodot-instance-id": "test-instance",
70
+ },
71
+ data: {
72
+ events: ["order.created"],
73
+ name: "checkout",
74
+ instance_id: "test-instance",
75
+ },
76
+ }));
77
+ });
78
+ it("unsubscribes by id", async () => {
79
+ mockAxiosInstance.mockResolvedValue({
80
+ data: { ok: true, deleted: true },
81
+ });
82
+ const client = createClient();
83
+ const result = await client.unsubscribe("evt_sub_1");
84
+ expect(result.deleted).toBe(true);
85
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
86
+ method: "DELETE",
87
+ url: "/v1/subscribe/evt_sub_1",
88
+ }));
89
+ });
90
+ it("builds browser listenUrl with query auth", () => {
91
+ const client = createClient();
92
+ const url = client.listenUrl({ events: ["order.created", "payment.completed"] });
93
+ expect(url).toBe("https://api.example.com/event/v1/listen?app_id=evt_app_test&access_token=eak_test_key&instance_id=test-instance&events=order.created%2Cpayment.completed");
94
+ });
95
+ it("accepts appApiKey alias", async () => {
96
+ mockAxiosInstance.mockResolvedValue({
97
+ data: { ok: true, event_id: "evt_2", accepted: true },
98
+ });
99
+ const client = createClient({
100
+ apiKey: undefined,
101
+ appApiKey: "eak_alias",
102
+ });
103
+ await client.publish("ping", {});
104
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
105
+ headers: expect.objectContaining({
106
+ Authorization: "Bearer eak_alias",
107
+ }),
108
+ }));
109
+ });
110
+ it("auto-reconnects listen after stream ends until close", async () => {
111
+ jest.useFakeTimers();
112
+ const { EventEmitter } = require("events");
113
+ const stream1 = new EventEmitter();
114
+ const stream2 = new EventEmitter();
115
+ stream1.destroy = jest.fn();
116
+ stream2.destroy = jest.fn();
117
+ mockAxiosInstance
118
+ .mockResolvedValueOnce({ data: stream1 })
119
+ .mockResolvedValueOnce({ data: stream2 });
120
+ const client = createClient({ debug: false });
121
+ const messages = [];
122
+ const handle = client.listen({ events: ["order.created"] }, (m) => {
123
+ messages.push(m);
124
+ });
125
+ await Promise.resolve();
126
+ await Promise.resolve();
127
+ stream1.emit("data", Buffer.from('data: {"type":"connected","listener_id":"sse_1","events":["order.created"]}\n\n'));
128
+ stream1.emit("end");
129
+ await Promise.resolve();
130
+ expect(messages).toHaveLength(1);
131
+ await jest.advanceTimersByTimeAsync(1000);
132
+ await Promise.resolve();
133
+ await Promise.resolve();
134
+ stream2.emit("data", Buffer.from('data: {"type":"connected","listener_id":"sse_2","events":["order.created"]}\n\n'));
135
+ expect(messages).toHaveLength(2);
136
+ expect(mockAxiosInstance).toHaveBeenCalledTimes(2);
137
+ handle.close();
138
+ jest.useRealTimers();
139
+ });
140
+ it("does not reconnect when reconnect is false", async () => {
141
+ jest.useFakeTimers();
142
+ const { EventEmitter } = require("events");
143
+ const stream1 = new EventEmitter();
144
+ stream1.destroy = jest.fn();
145
+ mockAxiosInstance.mockResolvedValueOnce({ data: stream1 });
146
+ const client = createClient();
147
+ client.listen({ events: ["order.created"], reconnect: false }, () => { });
148
+ await Promise.resolve();
149
+ await Promise.resolve();
150
+ stream1.emit("end");
151
+ await Promise.resolve();
152
+ await jest.advanceTimersByTimeAsync(5000);
153
+ expect(mockAxiosInstance).toHaveBeenCalledTimes(1);
154
+ jest.useRealTimers();
155
+ });
156
+ it("passes environment on publish", async () => {
157
+ mockAxiosInstance.mockResolvedValue({
158
+ data: { ok: true, event_id: "evt_env", accepted: true },
159
+ });
160
+ const client = createClient();
161
+ await client.publish("order.created", { id: "1" }, { environment: "dev" });
162
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
163
+ data: expect.objectContaining({
164
+ event: "order.created",
165
+ environment: "dev",
166
+ }),
167
+ }));
168
+ });
169
+ it("keeps instance id stable for this client and distinct across computers", async () => {
170
+ mockAxiosInstance.mockResolvedValue({
171
+ data: {
172
+ ok: true,
173
+ subscription_id: "evt_sub_1",
174
+ events: ["order.created"],
175
+ instance_id: "test-instance",
176
+ },
177
+ });
178
+ const sameBox = createClient();
179
+ await sameBox.subscribe({ events: ["order.created"] });
180
+ await sameBox.subscribe({ events: ["order.created"] });
181
+ const otherBox = createClient({ instanceId: "other-computer" });
182
+ await otherBox.subscribe({ events: ["order.created"] });
183
+ const calls = mockAxiosInstance.mock.calls.filter((c) => c[0]?.url === "/v1/subscribe");
184
+ expect(calls).toHaveLength(3);
185
+ expect(calls[0][0].data.instance_id).toBe("test-instance");
186
+ expect(calls[1][0].data.instance_id).toBe("test-instance");
187
+ expect(calls[2][0].data.instance_id).toBe("other-computer");
188
+ expect(sameBox.instanceId).toBe("test-instance");
189
+ expect(otherBox.instanceId).not.toBe(sameBox.instanceId);
190
+ });
191
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IdentityAppClient.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdentityAppClient.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/IdentityAppClient.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const axios_1 = __importDefault(require("axios"));
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
+ const IdentityAppClient_1 = require("../IdentityAppClient");
10
+ const errors_1 = require("../errors");
11
+ const identity_offline_verify_1 = require("../identity-offline-verify");
12
+ const identity_token_cache_1 = require("../identity-token-cache");
13
+ jest.mock("axios");
14
+ const mockedAxios = axios_1.default;
15
+ describe("IdentityAppClient", () => {
16
+ const mockAxiosInstance = jest.fn();
17
+ beforeEach(() => {
18
+ jest.clearAllMocks();
19
+ mockedAxios.create.mockReturnValue(mockAxiosInstance);
20
+ });
21
+ function createClient(overrides) {
22
+ return new IdentityAppClient_1.IdentityAppClient({
23
+ baseUrl: "https://api.example.com",
24
+ appId: "identity_payroll",
25
+ appApiKey: "iak_test_key",
26
+ ...overrides,
27
+ });
28
+ }
29
+ it("requires baseUrl and appId", () => {
30
+ expect(() => new IdentityAppClient_1.IdentityAppClient({ baseUrl: "", appId: "identity_payroll" })).toThrow(errors_1.CliodotApiError);
31
+ expect(() => new IdentityAppClient_1.IdentityAppClient({
32
+ baseUrl: "https://api.example.com",
33
+ appId: "",
34
+ })).toThrow(errors_1.CliodotApiError);
35
+ });
36
+ it("authenticates with bearer api key", async () => {
37
+ mockAxiosInstance.mockResolvedValue({
38
+ data: {
39
+ ok: true,
40
+ access_token: "jwt",
41
+ token_type: "Bearer",
42
+ expires_in: 3600,
43
+ caller_app_id: "identity_payroll",
44
+ target_app_id: "identity_hrms",
45
+ },
46
+ });
47
+ const client = createClient();
48
+ const result = await client.authenticate({
49
+ target_app_id: "identity_hrms",
50
+ });
51
+ expect(result.access_token).toBe("jwt");
52
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
53
+ method: "POST",
54
+ url: "/v1/authenticate",
55
+ headers: {
56
+ "x-cliodot-app-id": "identity_payroll",
57
+ Authorization: "Bearer iak_test_key",
58
+ },
59
+ data: { target_app_id: "identity_hrms" },
60
+ }));
61
+ });
62
+ it("authenticate and verify pass scopes", async () => {
63
+ mockAxiosInstance.mockResolvedValue({
64
+ data: {
65
+ ok: true,
66
+ access_token: "jwt",
67
+ token_type: "Bearer",
68
+ expires_in: 3600,
69
+ caller_app_id: "identity_payroll",
70
+ target_app_id: "identity_hrms",
71
+ },
72
+ });
73
+ const client = createClient();
74
+ await client.authenticate({
75
+ target_app_id: "identity_hrms",
76
+ scopes: ["employees.read"],
77
+ });
78
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
79
+ data: {
80
+ target_app_id: "identity_hrms",
81
+ scopes: ["employees.read"],
82
+ },
83
+ }));
84
+ mockAxiosInstance.mockResolvedValue({
85
+ data: {
86
+ ok: true,
87
+ valid: true,
88
+ jti: "j1",
89
+ caller_app_id: "identity_payroll",
90
+ target_app_id: "identity_hrms",
91
+ expires_at: new Date().toISOString(),
92
+ claims: { scope: "employees.read" },
93
+ },
94
+ });
95
+ await client.verify({
96
+ access_token: "jwt",
97
+ required_scopes: ["employees.read"],
98
+ });
99
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
100
+ data: {
101
+ access_token: "jwt",
102
+ required_scopes: ["employees.read"],
103
+ },
104
+ }));
105
+ });
106
+ it("uses app secret headers when no api key", async () => {
107
+ mockAxiosInstance.mockResolvedValue({
108
+ data: {
109
+ ok: true,
110
+ app: {
111
+ _id: "identity_payroll",
112
+ name: "Payroll",
113
+ slug: "identity_payroll",
114
+ tenant_id: "t1",
115
+ status: "active",
116
+ },
117
+ },
118
+ });
119
+ const client = createClient({
120
+ appApiKey: undefined,
121
+ appSecret: "secret_hex",
122
+ });
123
+ await client.me();
124
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
125
+ method: "GET",
126
+ url: "/v1/me",
127
+ headers: {
128
+ "x-cliodot-app-id": "identity_payroll",
129
+ "x-cliodot-app-secret": "secret_hex",
130
+ },
131
+ }));
132
+ });
133
+ it("maps API error codes", async () => {
134
+ mockAxiosInstance.mockResolvedValue({
135
+ data: {
136
+ ok: false,
137
+ error: "Target app does not trust the caller",
138
+ code: "IDENTITY_TRUST_DENIED",
139
+ },
140
+ });
141
+ const client = createClient();
142
+ await expect(client.authenticate({ target_app_id: "identity_hrms" })).rejects.toMatchObject({
143
+ code: "IDENTITY_TRUST_DENIED",
144
+ });
145
+ });
146
+ it("fetches JWKS without auth headers", async () => {
147
+ mockAxiosInstance.mockResolvedValue({
148
+ data: { keys: [{ kid: "k1", kty: "RSA" }] },
149
+ });
150
+ const client = createClient();
151
+ const jwks = await client.getJwks("identity_hrms");
152
+ expect(jwks.keys[0].kid).toBe("k1");
153
+ expect(mockAxiosInstance).toHaveBeenCalledWith(expect.objectContaining({
154
+ method: "GET",
155
+ url: "/v1/apps/identity_hrms/jwks.json",
156
+ }));
157
+ });
158
+ });
159
+ describe("verifyIdentityTokenOffline", () => {
160
+ beforeEach(() => {
161
+ (0, identity_offline_verify_1.clearIdentityJwksCache)();
162
+ });
163
+ it("verifies HS256 tokens", async () => {
164
+ const secret = "ijwt_test_secret_value_1234567890";
165
+ const token = jsonwebtoken_1.default.sign({ sub: "identity_payroll", jti: "j1", exp: Math.floor(Date.now() / 1000) + 60 }, secret, { algorithm: "HS256", noTimestamp: true });
166
+ const claims = await (0, identity_offline_verify_1.verifyIdentityTokenOffline)(token, {
167
+ algorithm: "HS256",
168
+ secret,
169
+ });
170
+ expect(claims.jti).toBe("j1");
171
+ });
172
+ it("verifies RS256 via JWKS kid", async () => {
173
+ const { publicKey, privateKey } = crypto_1.default.generateKeyPairSync("rsa", {
174
+ modulusLength: 2048,
175
+ publicKeyEncoding: { type: "spki", format: "pem" },
176
+ privateKeyEncoding: { type: "pkcs8", format: "pem" },
177
+ });
178
+ const jwk = crypto_1.default
179
+ .createPublicKey(publicKey)
180
+ .export({ format: "jwk" });
181
+ const token = jsonwebtoken_1.default.sign({ sub: "identity_payroll", jti: "j2", exp: Math.floor(Date.now() / 1000) + 60 }, privateKey, { algorithm: "RS256", keyid: "kid_1", noTimestamp: true });
182
+ const fetchImpl = jest.fn().mockResolvedValue({
183
+ ok: true,
184
+ json: async () => ({
185
+ keys: [
186
+ {
187
+ kty: jwk.kty || "RSA",
188
+ kid: "kid_1",
189
+ n: jwk.n,
190
+ e: jwk.e,
191
+ alg: "RS256",
192
+ use: "sig",
193
+ },
194
+ ],
195
+ }),
196
+ });
197
+ const claims = await (0, identity_offline_verify_1.verifyIdentityTokenOffline)(token, {
198
+ algorithm: "RS256",
199
+ jwksUrl: "https://api.example.com/identity/v1/apps/identity_hrms/jwks.json",
200
+ fetch: fetchImpl,
201
+ });
202
+ expect(claims.jti).toBe("j2");
203
+ expect(fetchImpl).toHaveBeenCalled();
204
+ });
205
+ it("tokenHasScopes checks JWT scope claim", () => {
206
+ const token = jsonwebtoken_1.default.sign({ scope: "employees.read employees.write", jti: "j" }, "secret", { algorithm: "HS256", noTimestamp: true });
207
+ expect((0, identity_offline_verify_1.tokenHasScopes)(token, ["employees.read"])).toBe(true);
208
+ expect((0, identity_offline_verify_1.tokenHasScopes)(token, ["employees.admin"])).toBe(false);
209
+ });
210
+ });
211
+ describe("createIdentityTokenCache", () => {
212
+ it("authenticates then reuses until near expiry", async () => {
213
+ const authenticate = jest.fn().mockResolvedValue({
214
+ ok: true,
215
+ access_token: "at_1",
216
+ token_type: "Bearer",
217
+ expires_in: 3600,
218
+ refresh_token: "irt_1",
219
+ caller_app_id: "identity_payroll",
220
+ target_app_id: "identity_hrms",
221
+ });
222
+ const refresh = jest.fn();
223
+ const cache = (0, identity_token_cache_1.createIdentityTokenCache)({
224
+ client: { authenticate, refresh },
225
+ });
226
+ const first = await cache.getAccessToken("identity_hrms");
227
+ const second = await cache.getAccessToken("identity_hrms");
228
+ expect(first).toBe("at_1");
229
+ expect(second).toBe("at_1");
230
+ expect(authenticate).toHaveBeenCalledTimes(1);
231
+ });
232
+ });