@benup/bensdk 1.2.0 → 1.2.2

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.
@@ -31,7 +31,7 @@ export function createStateHandlerCtxMock(benefitDefinition, logger) {
31
31
  };
32
32
 
33
33
  // Mockar o endpoint GET /some-path para retornar 200 OK
34
- apisMocks.benefitsAPI.onGet('/some-path').replyOnce(200, {
34
+ apisMocks.benefitsAPI.onGet('/proxy-http/<Algum path>').replyOnce(200, {
35
35
  values: ['123']
36
36
  });
37
37
 
@@ -20,16 +20,39 @@ const handler: StateHandler<
20
20
  ActionCtx
21
21
  > = async (message, action, ctx) => {
22
22
  /**
23
- * 🪄 ctx.benefitsAPI.getVendor retorna AxiosInstance com path do proxy do vendor (benefitApi),
24
- * implicitamente adiciona accountID e companyID na request para interagir com a credencial correta
23
+ * 🪄 ctx.benefitsAPI é uma instância Axios apontando para a API de benefícios benup
24
+ * implicitamente adiciona accountID e companyID na request para interagir com a credencial correta cadastrada
25
+ * para fazer requisições para o benefício, basta usar a URL normal que usaria após o /proxy-http/
25
26
  */
26
27
 
27
- const res = await ctx.benefitsAPI.get<BenefitResponse>('/some-path');
28
+ const res = await ctx.benefitsAPI.get<BenefitResponse>('/proxy-http/<Algum path>');
28
29
  const { status, data } = res;
29
30
 
31
+ /**
32
+ * 🪄 Na resposta do handler retornamos qual é a ação que o consumer precisa tomar em relação a mensagem
33
+ */
34
+
35
+ if (status === 500) {
36
+ /**
37
+ * 🪄 Exemplo de erro catastrófico
38
+ */
39
+ return {
40
+ handlerResponse: {
41
+ response: 'ACK'
42
+ },
43
+ action: {
44
+ state: stateMachine.fail,
45
+ ctx: {},
46
+ logs: {
47
+ benefitAPI: getLogsFromResponse(res)
48
+ }
49
+ }
50
+ };
51
+ }
52
+
30
53
  if (status !== 200) {
31
54
  /**
32
- * 🪄 Na resposta do handler retornamos qual é a ação que o consumer precisa tomar em relação a mensagem
55
+ * 🪄 Exemplo de erro retentável
33
56
  */
34
57
  return {
35
58
  handlerResponse: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benup/bensdk",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {