@tonder.io/ionic-lite-sdk 0.0.18-beta → 0.0.20-beta

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.
@@ -28,6 +28,7 @@ export declare class LiteCheckout implements LiteCheckoutConstructor {
28
28
  getFieldsPromise(data: any, collectContainer: CollectContainer): Promise<Promise<boolean>[]>;
29
29
  registerCustomerCard(customerToken: string, data: RegisterCustomerCardRequest): Promise<RegisterCustomerCardResponse | ErrorResponse>;
30
30
  getCustomerCards(customerToken: string, query?: string): Promise<GetCustomerCardsResponse | ErrorResponse>;
31
+ deleteCustomerCard(customerToken: string, skyflowId?: string): Promise<Boolean | ErrorResponse>;
31
32
  private buildErrorResponseFromCatch;
32
33
  private buildErrorResponse;
33
34
  private getFields;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import e from"skyflow-js";function t(e,t,o,i){return new(o||(o=Promise))((function(r,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,d)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class o{constructor({code:e,body:t,name:o,message:i,stack:r}){this.code=e,this.body=t,this.name=o,this.message=i,this.stack=r}}class i{constructor({signal:e,baseUrlTonder:t,apiKeyTonder:o}){this.baseUrlTonder=t,this.signal=e,this.apiKeyTonder=o}getOpenpayDeviceSessionID(e,o,i){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(o),t.setSandboxMode(i),yield t.deviceData.setup({signal:this.signal})}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{const e=yield fetch(`${this.baseUrlTonder}/api/v1/payments/business/${this.apiKeyTonder}`,{headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});return e.ok?yield e.json():yield this.buildErrorResponse(e)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/customer/`,o={email:e},i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal,body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/orders/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/business/${e.business_pk}/payments/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/checkout-router/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getSkyflowTokens({vault_id:o,vault_url:i,data:r}){return t(this,void 0,void 0,(function*(){const n=e.init({vaultID:o,vaultURL:i,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield this.getVaultToken()})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),s=yield this.getFieldsPromise(r,n);if((yield Promise.all(s)).some((e=>!e)))return this.buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const e=yield n.collect();return e?e.records[0].fields:this.buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getVaultToken(){var e;return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(t.ok)return null===(e=yield t.json())||void 0===e?void 0:e.token;throw new Error(`HTTPCODE: ${t.status}`)}catch(e){throw new Error(`Failed to retrieve bearer token; ${"string"==typeof e?e:e.message}`)}}))}getFieldsPromise(e,o){return t(this,void 0,void 0,(function*(){const t=yield this.getFields(e,o);return t?t.map((t=>new Promise((o=>{var i;const r=document.createElement("div");r.hidden=!0,r.id=`id-${t.key}`,null===(i=document.querySelector("body"))||void 0===i||i.appendChild(r),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const i=e[t.key];return t.element.update({value:i}),o(t.element.isMounted())}}),120)}),120)})))):[]}))}registerCustomerCard(e,o){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/`,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal,body:JSON.stringify(o)});return t.ok?yield t.json():yield this.buildErrorResponse(t)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getCustomerCards(e,o=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${o}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});return t.ok?yield t.json():yield this.buildErrorResponse(t)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}buildErrorResponseFromCatch(e){return new o({code:void 0,body:void 0,name:"string"==typeof e?"catch":e.name,message:"string"==typeof e?e:e.message,stack:"string"==typeof e?void 0:e.stack})}buildErrorResponse(e,i=void 0){var r,n,s,d,a,l;return t(this,void 0,void 0,(function*(){return new o({code:null===(n=null===(r=e.status)||void 0===r?void 0:r.toString)||void 0===n?void 0:n.call(r),body:yield null===(s=null==e?void 0:e.json)||void 0===s?void 0:s.call(e),name:null===(a=null===(d=e.status)||void 0===d?void 0:d.toString)||void 0===a?void 0:a.call(d),message:yield null===(l=null==e?void 0:e.text)||void 0===l?void 0:l.call(e),stack:i})}))}getFields(o,i){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(o).map((o=>t(this,void 0,void 0,(function*(){return{element:yield i.create({table:"cards",column:o,type:e.ElementType.INPUT_FIELD}),key:o}})))))}))}}export{i as LiteCheckout};
1
+ import e from"skyflow-js";function t(e,t,o,i){return new(o||(o=Promise))((function(r,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,d)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class o{constructor({code:e,body:t,name:o,message:i,stack:r}){this.code=e,this.body=t,this.name=o,this.message=i,this.stack=r}}class i{constructor({signal:e,baseUrlTonder:t,apiKeyTonder:o}){this.baseUrlTonder=t,this.signal=e,this.apiKeyTonder=o}getOpenpayDeviceSessionID(e,o,i){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(o),t.setSandboxMode(i),yield t.deviceData.setup({signal:this.signal})}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{const e=yield fetch(`${this.baseUrlTonder}/api/v1/payments/business/${this.apiKeyTonder}`,{headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});return e.ok?yield e.json():yield this.buildErrorResponse(e)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/customer/`,o={email:e},i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal,body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/orders/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/business/${e.business_pk}/payments/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/checkout-router/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getSkyflowTokens({vault_id:o,vault_url:i,data:r}){return t(this,void 0,void 0,(function*(){const n=e.init({vaultID:o,vaultURL:i,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield this.getVaultToken()})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),s=yield this.getFieldsPromise(r,n);if((yield Promise.all(s)).some((e=>!e)))return this.buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const e=yield n.collect();return e?e.records[0].fields:this.buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getVaultToken(){var e;return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(t.ok)return null===(e=yield t.json())||void 0===e?void 0:e.token;throw new Error(`HTTPCODE: ${t.status}`)}catch(e){throw new Error(`Failed to retrieve bearer token; ${"string"==typeof e?e:e.message}`)}}))}getFieldsPromise(e,o){return t(this,void 0,void 0,(function*(){const t=yield this.getFields(e,o);return t?t.map((t=>new Promise((o=>{var i;const r=document.createElement("div");r.hidden=!0,r.id=`id-${t.key}`,null===(i=document.querySelector("body"))||void 0===i||i.appendChild(r),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const i=e[t.key];return t.element.update({value:i}),o(t.element.isMounted())}}),120)}),120)})))):[]}))}registerCustomerCard(e,o){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/`,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal,body:JSON.stringify(o)});return t.ok?yield t.json():yield this.buildErrorResponse(t)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getCustomerCards(e,o=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${o}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});return t.ok?yield t.json():yield this.buildErrorResponse(t)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}deleteCustomerCard(e,o=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${o}`,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});return!!t.ok||(yield this.buildErrorResponse(t))}catch(e){return this.buildErrorResponseFromCatch(e)}}))}buildErrorResponseFromCatch(e){return new o({code:void 0,body:void 0,name:"string"==typeof e?"catch":e.name,message:"string"==typeof e?e:e.message,stack:"string"==typeof e?void 0:e.stack})}buildErrorResponse(e,i=void 0){var r,n,s,d,a,l;return t(this,void 0,void 0,(function*(){return new o({code:null===(n=null===(r=e.status)||void 0===r?void 0:r.toString)||void 0===n?void 0:n.call(r),body:yield null===(s=null==e?void 0:e.json)||void 0===s?void 0:s.call(e),name:null===(a=null===(d=e.status)||void 0===d?void 0:d.toString)||void 0===a?void 0:a.call(d),message:yield null===(l=null==e?void 0:e.text)||void 0===l?void 0:l.call(e),stack:i})}))}getFields(o,i){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(o).map((o=>t(this,void 0,void 0,(function*(){return{element:yield i.create({table:"cards",column:o,type:e.ElementType.INPUT_FIELD}),key:o}})))))}))}}export{i as LiteCheckout};
package/jest.config.ts CHANGED
@@ -1,15 +1,15 @@
1
- import type { JestConfigWithTsJest } from 'ts-jest'
2
-
3
- const jestConfig: JestConfigWithTsJest = {
4
- testEnvironment: "jsdom",
5
- preset: 'ts-jest',
6
- transform: {
7
- '^.+\\.tsx?$': [
8
- 'ts-jest',
9
- {
10
- },
11
- ],
12
- },
13
- }
14
-
1
+ import type { JestConfigWithTsJest } from 'ts-jest'
2
+
3
+ const jestConfig: JestConfigWithTsJest = {
4
+ testEnvironment: "jsdom",
5
+ preset: 'ts-jest',
6
+ transform: {
7
+ '^.+\\.tsx?$': [
8
+ 'ts-jest',
9
+ {
10
+ },
11
+ ],
12
+ },
13
+ }
14
+
15
15
  export default jestConfig
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "name": "@tonder.io/ionic-lite-sdk",
3
- "version": "0.0.18-beta",
4
- "description": "Tonder ionic lite SDK",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "tsc -noEmit && rollup --config",
9
- "test": "jest",
10
- "ts-coverage": "typescript-coverage-report"
11
- },
12
- "author": "",
13
- "license": "ISC",
14
- "dependencies": {
15
- "skyflow-js": "^1.34.1",
16
- "ts-node": "^10.9.2"
17
- },
18
- "publishConfig": {
19
- "access": "public",
20
- "registry": "https://registry.npmjs.org/"
21
- },
22
- "devDependencies": {
23
- "@rollup/plugin-terser": "^0.4.4",
24
- "@rollup/plugin-typescript": "11.1.6",
25
- "@types/crypto-js": "^4.2.2",
26
- "@types/jest": "^29.5.11",
27
- "@types/node": "^20.11.5",
28
- "jest": "^29.7.0",
29
- "jest-environment-jsdom": "^29.7.0",
30
- "jsdom": "^24.0.0",
31
- "rollup": "4.9.6",
32
- "ts-jest": "^29.1.2",
33
- "ts-loader": "^9.5.1",
34
- "tslib": "^2.6.2",
35
- "typescript": "^5.3.3",
36
- "typescript-coverage-report": "^0.8.0"
37
- }
38
- }
1
+ {
2
+ "name": "@tonder.io/ionic-lite-sdk",
3
+ "version": "0.0.20-beta",
4
+ "description": "Tonder ionic lite SDK",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -noEmit && rollup --config",
9
+ "test": "jest",
10
+ "ts-coverage": "typescript-coverage-report"
11
+ },
12
+ "author": "",
13
+ "license": "ISC",
14
+ "dependencies": {
15
+ "skyflow-js": "^1.34.1",
16
+ "ts-node": "^10.9.2"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "registry": "https://registry.npmjs.org/"
21
+ },
22
+ "devDependencies": {
23
+ "@rollup/plugin-terser": "^0.4.4",
24
+ "@rollup/plugin-typescript": "11.1.6",
25
+ "@types/crypto-js": "^4.2.2",
26
+ "@types/jest": "^29.5.11",
27
+ "@types/node": "^20.11.5",
28
+ "jest": "^29.7.0",
29
+ "jest-environment-jsdom": "^29.7.0",
30
+ "jsdom": "^24.0.0",
31
+ "rollup": "4.9.6",
32
+ "ts-jest": "^29.1.2",
33
+ "ts-loader": "^9.5.1",
34
+ "tslib": "^2.6.2",
35
+ "typescript": "^5.3.3",
36
+ "typescript-coverage-report": "^0.8.0"
37
+ }
38
+ }
package/rollup.config.js CHANGED
@@ -1,17 +1,17 @@
1
- const typescript = require('@rollup/plugin-typescript');
2
- const terser = require('@rollup/plugin-terser');
3
-
4
- module.exports = {
5
- input: './src/index.ts',
6
- output: {
7
- dir: 'dist',
8
- format: 'es',
9
- plugins: [terser()]
10
- },
11
- plugins: [
12
- typescript({
13
- exclude: ["tests/**", "jest.config.ts"]
14
- })
15
- ],
16
- external: ["skyflow-js", "crypto-js"]
1
+ const typescript = require('@rollup/plugin-typescript');
2
+ const terser = require('@rollup/plugin-terser');
3
+
4
+ module.exports = {
5
+ input: './src/index.ts',
6
+ output: {
7
+ dir: 'dist',
8
+ format: 'es',
9
+ plugins: [terser()]
10
+ },
11
+ plugins: [
12
+ typescript({
13
+ exclude: ["tests/**", "jest.config.ts"]
14
+ })
15
+ ],
16
+ external: ["skyflow-js", "crypto-js"]
17
17
  };
@@ -1,17 +1,17 @@
1
- import { IErrorResponse } from "../types/responses";
2
-
3
- export class ErrorResponse implements IErrorResponse {
4
- code?: string | undefined;
5
- body?: string | undefined;
6
- name!: string;
7
- message!: string;
8
- stack?: string | undefined;
9
-
10
- constructor({ code, body, name, message, stack }: IErrorResponse) {
11
- this.code = code;
12
- this.body = body;
13
- this.name = name;
14
- this.message = message;
15
- this.stack = stack;
16
- }
1
+ import { IErrorResponse } from "../types/responses";
2
+
3
+ export class ErrorResponse implements IErrorResponse {
4
+ code?: string | undefined;
5
+ body?: string | undefined;
6
+ name!: string;
7
+ message!: string;
8
+ stack?: string | undefined;
9
+
10
+ constructor({ code, body, name, message, stack }: IErrorResponse) {
11
+ this.code = code;
12
+ this.body = body;
13
+ this.name = name;
14
+ this.message = message;
15
+ this.stack = stack;
16
+ }
17
17
  }