santoid-sdk 1.0.0 → 1.0.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.
package/README.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # SantoiD SDK
2
2
  Com esta biblioteca, você pode conectar-se ao Santo iD via código JavaScript de forma fácil e rápida, podendo integrá-lo à sua aplicação de forma mais eficiente.
3
3
 
4
+ ## Instalação
5
+ Para instalar o SDK utilizando o NPM, utilize o seguinte comando:
6
+ ```
7
+ npm install santoid-sdk
8
+ ```
9
+
10
+ Para instalar utilizando o Yarn, utilize este outro comando:
11
+ ```
12
+ yarn add santoid-sdk
13
+ ```
14
+
4
15
  ## Autenticação
5
16
  Atualmente, o SDK suporta a autenticação via contas de serviço do Santo iD. Para realizar a autenticação, crie uma conta de serviço do Santo iD na [página de Contas de Serviço](https://app.santoid.com.br/identity/service-accounts) da plataforma.
6
17
 
@@ -46,6 +57,8 @@ startSDK()
46
57
  Atualmente, o SDK conta com a funcionalidade de **Prova de Vida**, que possibilita a verificação do usuário atual, avaliando se uma pessoa real está realizando as atividades online por meio de uma rápida análise facial.
47
58
 
48
59
  ### Como utilizar?
60
+
61
+ #### Em JavaScript
49
62
  Para utilizar a funcionalidade de Prova de Vida, é necessário importar a função para iniciar a verificação e passar alguns parâmetros:
50
63
 
51
64
  ```ts
@@ -104,7 +117,7 @@ async function startLivenessDetection () {
104
117
  video.srcObject = videoStream
105
118
  }
106
119
  ```
107
-
120
+ #### Em Node.js
108
121
  Caso deseje executar a função da prova de vida no servidor (Node.js), é obrigatório informar ao SDK a função de obtenção de frames, a qual deve retornar um Buffer ou semelhante (bytes da imagem do frame).
109
122
 
110
123
  Fique atento ao caminho de importação da função, que muda para o caso de execução no servidor (Node.js):
@@ -123,4 +136,63 @@ async function startLivenessDetection () {
123
136
  // ...
124
137
  })
125
138
  }
139
+ ```
140
+
141
+ #### Utilização via CDN
142
+ Caso deseje utilizar a biblioteca via CDN, importando-a diretamente em uma tag **script**, basta utilizar o caminho especificado no exemplo abaixo.
143
+
144
+ Ao importar a biblioteca via tag script, a função **livenessDetection** ficará disponível por meio da classe **SantoiDSDK**.
145
+
146
+ ```html
147
+ <body>
148
+ <button onclick="startLiveness()">Iniciar</button>
149
+
150
+ <script src="https://cdn.jsdelivr.net/npm/santoid-sdk@1.0.2/dist/browser/liveness/index.js"></script>
151
+
152
+ <script>
153
+ async function startLiveness () {
154
+ await SantoiDSDK.livenessDetection({
155
+ track: 'test-track',
156
+ token: '...', // Token recebido via autenticação no back-end
157
+
158
+ // ...
159
+ })
160
+ }
161
+ </script>
162
+ </body>
163
+ ```
164
+
165
+ ## Possíveis dúvidas
166
+
167
+ ### A importação da biblioteca não está funcionando pelos caminhos indicados na documentação
168
+ Caso a biblioteca não esteja funcionando pelos caminhos indicados anteriormente para utilização em JavaScript ou Node.js, seja por incompatibilidade com o framework utilizado ou com alguma outra configuração do ambiente, tente adicionar o caminho **dist** após o nome da biblioteca e referenciar o caminho completo até o arquivo **index.js**, como nos exemplos abaixo:
169
+
170
+ ```ts
171
+ // Exemplo 1
172
+ import { livenessDetection } from 'santoid-sdk/dist/esm/liveness/index.js'
173
+
174
+ // Exemplo 2
175
+ import { livenessDetection } from 'santoid-sdk/dist/node/liveness/index.js'
176
+
177
+ // Exemplo 3
178
+ import { initialize } from 'santoid-sdk/dist/node/auth/index.js'
179
+ ```
180
+
181
+ ## Para desenvolvedores
182
+ Caso seja um desenvolvedor e deseje realizar alguma alteração no código da biblioteca, abaixo estão alguns comandos úteis que serão necessários:
183
+
184
+ ### Instalação de dependências
185
+ ```
186
+ yarn
187
+ ```
188
+
189
+ ### Realizar build
190
+ ```
191
+ yarn build
192
+ ```
193
+
194
+ ### Publicação da biblioteca
195
+ ```
196
+ npm login
197
+ npm publish
126
198
  ```
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("SantoiDSDK",[],t):"object"==typeof exports?exports.SantoiDSDK=t():e.SantoiDSDK=t()}(this,(()=>(()=>{"use strict";var e={401:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var a=Object.getOwnPropertyDescriptor(t,o);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,a)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),a=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),t.livenessDetection=void 0;const r=o(553),i=o(793),c=o(692);async function l(e){var t,o,n;let a,l,d,s=!1,u=!1,v=!1;async function p(e,t,o){var n;o&&clearInterval(o),t&&(0,c.disconnectFromWebSocket)(t),a&&a.stopGetNextFrame(),!v&&await(null===(n=e.endCallback)||void 0===n?void 0:n.call(e)),v=!0,s=!0}try{let n;return d=await(0,c.connectToWebSocket)(e),await(null===(t=e.nextStepCallback)||void 0===t?void 0:t.call(e,"front")),await(null===(o=e.frontCallback)||void 0===o?void 0:o.call(e)),e.getNextFrame||a||(a=await(0,i.builtInGetNextFrame)()),l=setInterval((async()=>{try{if(null==n?void 0:n.can_send_next_bytes){let t;t=e.getNextFrame?await e.getNextFrame():await(null==a?void 0:a.getNextFrame()),t&&(null==d||d.send(t))}}catch(t){await p(e,d,l)}}),r.SEND_FRAMES_INTERVAL_MS),d.addEventListener("message",(async t=>{var o;const a=await async function(e,t){var o,n,a;const r=t.data;let i;try{i=JSON.parse(r)}catch(e){console.error("Cannot parse API message",e)}return(null==i?void 0:i.next_step)&&!i.error&&(await(null===(o=e.nextStepCallback)||void 0===o?void 0:o.call(e,i.next_step)),await(null===(n=e[`${i.next_step}Callback`])||void 0===n?void 0:n.call(e))),(null==i?void 0:i.error)&&await(null===(a=e.errorCallback)||void 0===a?void 0:a.call(e,{code:"wrong-position"})),i}(e,t);a&&(n=a),(null==a?void 0:a.success)&&(u=!0,await(null===(o=e.successCallback)||void 0===o?void 0:o.call(e)),await p(e,d,l))})),d.addEventListener("error",(async()=>{var t;!u&&(null===(t=e.errorCallback)||void 0===t||t.call(e,{code:"internal-error"})),await p(e,d,l)})),d.addEventListener("close",(async()=>{var t;s||(!u&&(null===(t=e.errorCallback)||void 0===t||t.call(e,{code:"internal-error"})),await p(e,d,l))})),n={can_send_next_bytes:!0},{stopLivenessDetection:async()=>{await p(e,d,l)},videoStream:null==a?void 0:a.videoStream}}catch(t){throw!u&&(null===(n=e.errorCallback)||void 0===n||n.call(e,{code:"internal-error"})),await p(e,d,l),t}}a(o(722),t),t.livenessDetection=l;class d{}d.livenessDetection=l,t.default=d},793:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.builtInGetNextFrame=void 0,t.builtInGetNextFrame=async function(){let e,t,o;return e&&t&&o||(e=await navigator.mediaDevices.getUserMedia({video:!0}),t=document.createElement("video"),t.setAttribute("autoplay","true"),t.style.position="absolute",t.style.left="99999px",document.body.appendChild(t),t.srcObject=e,o=document.createElement("canvas")),{getNextFrame:async function(){if(o&&t){const e=o.getContext("2d");return o.width=t.videoWidth,o.height=t.videoHeight,null==e||e.drawImage(t,0,0,o.width,o.height),await new Promise(((e,t)=>{o?o.toBlob((t=>{e(t)})):e(null)}))}throw new Error("Cannot found video element")},stopGetNextFrame:function(){t&&(document.body.removeChild(t),t=void 0),o&&(o=void 0),null==e||e.getTracks().forEach((e=>{e.stop()})),e=void 0},videoStream:e}}},268:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.decodeJwt=void 0,t.decodeJwt=function(e){const t=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),o=decodeURIComponent(window.atob(t).split("").map((e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2))).join(""));return JSON.parse(o)}},722:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var a=Object.getOwnPropertyDescriptor(t,o);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,a)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),a=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),a(o(307),t)},692:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.disconnectFromWebSocket=t.connectToWebSocket=void 0;const n=o(268),a=o(553);t.connectToWebSocket=async function(e){var t;const o=(0,n.decodeJwt)(e.token),r=`?x_endpoint_api_userinfo=${e.token}&domain=${o.claims.domain}&track=${e.track}&customerRequestId=${e.customId}`,i=new WebSocket(`${null!==(t=e.customWebSocketUrl)&&void 0!==t?t:a.WEBSOCKET_BASE_URL}${r}`);return await async function(e){if(await new Promise((t=>{const o=setInterval((()=>{[3,1].includes(e.readyState)&&(clearInterval(o),t())}),5)})),3===e.readyState)throw new Error("Cannot connect to server")}(i),i},t.disconnectFromWebSocket=function(e){var t;[2,3].includes(e.readyState)||null===(t=e.close)||void 0===t||t.call(e)}},553:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SEND_FRAMES_INTERVAL_MS=t.API_GATEWAY_URL=t.WEBSOCKET_BASE_URL=void 0,t.WEBSOCKET_BASE_URL="ws://santoid-liveness-w4ynos5dlq-ue.a.run.app/ws",t.API_GATEWAY_URL="https://api.santoid.com.br/api/v1/service-account/refresh-token",t.SEND_FRAMES_INTERVAL_MS=100},307:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})}},t={},o=function o(n){var a=t[n];if(void 0!==a)return a.exports;var r=t[n]={exports:{}};return e[n].call(r.exports,r,r.exports,o),r.exports}(401);return o.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("SantoiDSDK",[],t):"object"==typeof exports?exports.SantoiDSDK=t():e.SantoiDSDK=t()}(this,(()=>(()=>{"use strict";var e={401:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var a=Object.getOwnPropertyDescriptor(t,o);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,a)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),a=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),t.livenessDetection=void 0;const r=o(553),i=o(793),c=o(692);async function l(e){var t,o,n;let a,l,s,d=!1,u=!1,v=!1;async function p(e,t,o){var n;o&&clearInterval(o),t&&(0,c.disconnectFromWebSocket)(t),a&&a.stopGetNextFrame(),!v&&await(null===(n=e.endCallback)||void 0===n?void 0:n.call(e)),v=!0,d=!0}try{let n;return s=await(0,c.connectToWebSocket)(e),await(null===(t=e.nextStepCallback)||void 0===t?void 0:t.call(e,"front")),await(null===(o=e.frontCallback)||void 0===o?void 0:o.call(e)),e.getNextFrame||a||(a=await(0,i.builtInGetNextFrame)()),l=setInterval((async()=>{try{if(null==n?void 0:n.can_send_next_bytes){let t;t=e.getNextFrame?await e.getNextFrame():await(null==a?void 0:a.getNextFrame()),t&&(null==s||s.send(t))}}catch(t){await p(e,s,l)}}),r.SEND_FRAMES_INTERVAL_MS),s.addEventListener("message",(async t=>{var o;const a=await async function(e,t){var o,n,a;const r=t.data;let i;try{i=JSON.parse(r)}catch(e){console.error("Cannot parse API message",e)}return(null==i?void 0:i.next_step)&&!i.error&&(await(null===(o=e.nextStepCallback)||void 0===o?void 0:o.call(e,i.next_step)),await(null===(n=e[`${i.next_step}Callback`])||void 0===n?void 0:n.call(e))),(null==i?void 0:i.error)&&await(null===(a=e.errorCallback)||void 0===a?void 0:a.call(e,{code:"wrong-position"})),i}(e,t);a&&(n=a),(null==a?void 0:a.success)&&(u=!0,await(null===(o=e.successCallback)||void 0===o?void 0:o.call(e)),await p(e,s,l))})),s.addEventListener("error",(async()=>{var t;!u&&(null===(t=e.errorCallback)||void 0===t||t.call(e,{code:"internal-error"})),await p(e,s,l)})),s.addEventListener("close",(async()=>{var t;d||(!u&&(null===(t=e.errorCallback)||void 0===t||t.call(e,{code:"internal-error"})),await p(e,s,l))})),n={can_send_next_bytes:!0},{stopLivenessDetection:async()=>{await p(e,s,l)},videoStream:null==a?void 0:a.videoStream}}catch(t){throw!u&&(null===(n=e.errorCallback)||void 0===n||n.call(e,{code:"internal-error"})),await p(e,s,l),t}}a(o(722),t),t.livenessDetection=l;class s{}s.livenessDetection=l,t.default=s},793:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.builtInGetNextFrame=void 0,t.builtInGetNextFrame=async function(){let e,t,o;return e&&t&&o||(e=await navigator.mediaDevices.getUserMedia({video:!0}),t=document.createElement("video"),t.setAttribute("autoplay","true"),t.style.transform="scale(-1, 1)",t.style.position="absolute",t.style.left="0",document.body.appendChild(t),t.srcObject=e,o=document.createElement("canvas")),{getNextFrame:async function(){if(o&&t){const e=o.getContext("2d");return o.width=t.videoWidth,o.height=t.videoHeight,null==e||e.drawImage(t,0,0,o.width,o.height),await new Promise(((e,t)=>{o?o.toBlob((t=>{e(t)})):e(null)}))}throw new Error("Cannot found video element")},stopGetNextFrame:function(){t&&(document.body.removeChild(t),t=void 0),o&&(o=void 0),null==e||e.getTracks().forEach((e=>{e.stop()})),e=void 0},videoStream:e}}},268:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.decodeJwt=void 0,t.decodeJwt=function(e){const t=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),o=decodeURIComponent(window.atob(t).split("").map((e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2))).join(""));return JSON.parse(o)}},722:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var a=Object.getOwnPropertyDescriptor(t,o);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,a)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),a=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),a(o(307),t)},692:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.disconnectFromWebSocket=t.connectToWebSocket=void 0;const n=o(268),a=o(553);t.connectToWebSocket=async function(e){var t;const o=(0,n.decodeJwt)(e.token),r=`?x_endpoint_api_userinfo=${e.token}&domain=${o.claims.domain}&track=${e.track}&customerRequestId=${e.customId}`,i=new WebSocket(`${null!==(t=e.customWebSocketUrl)&&void 0!==t?t:a.WEBSOCKET_BASE_URL}${r}`);return await async function(e){if(await new Promise((t=>{const o=setInterval((()=>{[3,1].includes(e.readyState)&&(clearInterval(o),t())}),5)})),3===e.readyState)throw new Error("Cannot connect to server")}(i),i},t.disconnectFromWebSocket=function(e){var t;[2,3].includes(e.readyState)||null===(t=e.close)||void 0===t||t.call(e)}},553:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SEND_FRAMES_INTERVAL_MS=t.API_GATEWAY_URL=t.WEBSOCKET_BASE_URL=void 0,t.WEBSOCKET_BASE_URL="ws://santoid-liveness-w4ynos5dlq-ue.a.run.app/api/v1/liveness/ws",t.API_GATEWAY_URL="https://api.santoid.com.br/api/v1/service-account/refresh-token",t.SEND_FRAMES_INTERVAL_MS=100},307:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})}},t={},o=function o(n){var a=t[n];if(void 0!==a)return a.exports;var r=t[n]={exports:{}};return e[n].call(r.exports,r,r.exports,o),r.exports}(401);return o.default})()));
@@ -40,8 +40,9 @@ async function builtInGetNextFrame() {
40
40
  videoStream = await navigator.mediaDevices.getUserMedia({ video: true });
41
41
  videoElement = document.createElement('video');
42
42
  videoElement.setAttribute('autoplay', 'true');
43
+ videoElement.style.transform = 'scale(-1, 1)';
43
44
  videoElement.style.position = 'absolute';
44
- videoElement.style.left = '99999px';
45
+ videoElement.style.left = '0';
45
46
  document.body.appendChild(videoElement);
46
47
  videoElement.srcObject = videoStream;
47
48
  canvasElement = document.createElement('canvas');
@@ -1,3 +1,3 @@
1
- export declare const WEBSOCKET_BASE_URL = "ws://santoid-liveness-w4ynos5dlq-ue.a.run.app/ws";
1
+ export declare const WEBSOCKET_BASE_URL = "ws://santoid-liveness-w4ynos5dlq-ue.a.run.app/api/v1/liveness/ws";
2
2
  export declare const API_GATEWAY_URL = "https://api.santoid.com.br/api/v1/service-account/refresh-token";
3
3
  export declare const SEND_FRAMES_INTERVAL_MS = 100;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SEND_FRAMES_INTERVAL_MS = exports.API_GATEWAY_URL = exports.WEBSOCKET_BASE_URL = void 0;
4
- exports.WEBSOCKET_BASE_URL = 'ws://santoid-liveness-w4ynos5dlq-ue.a.run.app/ws';
4
+ exports.WEBSOCKET_BASE_URL = 'ws://santoid-liveness-w4ynos5dlq-ue.a.run.app/api/v1/liveness/ws';
5
5
  exports.API_GATEWAY_URL = 'https://api.santoid.com.br/api/v1/service-account/refresh-token';
6
6
  exports.SEND_FRAMES_INTERVAL_MS = 100;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "santoid-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/esm/liveness/index.js",
6
6
  "types": "dist/esm/liveness/index.d.ts",
@@ -53,6 +53,7 @@ export async function builtInGetNextFrame (): Promise<builtInGetNextFrameReturn>
53
53
  videoElement = document.createElement('video')
54
54
  videoElement.setAttribute('autoplay', 'true')
55
55
 
56
+ videoElement.style.transform = 'scale(-1, 1)'
56
57
  videoElement.style.position = 'absolute'
57
58
  videoElement.style.left = '99999px'
58
59
 
@@ -1,3 +1,3 @@
1
- export const WEBSOCKET_BASE_URL = 'ws://santoid-liveness-w4ynos5dlq-ue.a.run.app/ws'
1
+ export const WEBSOCKET_BASE_URL = 'wss://santoid-liveness-w4ynos5dlq-ue.a.run.app/api/v1/liveness/ws'
2
2
  export const API_GATEWAY_URL = 'https://api.santoid.com.br/api/v1/service-account/refresh-token'
3
3
  export const SEND_FRAMES_INTERVAL_MS = 100