ame-super-app-web
Advanced tools
Comparing version 4.1.0-beta.1 to 4.1.0
@@ -9,3 +9,3 @@ import { NavigationListenerFunction } from "../output/NavigationListenerEvent"; | ||
environment: SuperAppEnvironment; | ||
target: SuperAppTargetEnum; | ||
target: string | SuperAppTargetEnum; | ||
methods?: SharedMethods; | ||
@@ -12,0 +12,0 @@ urlPatterns?: UrlPatterns; |
@@ -11,3 +11,3 @@ import UrlPatterns from "./input/UrlPatterns"; | ||
methods?: SharedMethods; | ||
target?: SuperAppTargetEnum; | ||
target?: string | SuperAppTargetEnum; | ||
urlPatterns?: UrlPatterns; | ||
@@ -14,0 +14,0 @@ hostVersion?: string; |
@@ -6,3 +6,2 @@ "use strict"; | ||
const SuperAppEnvironment_1 = require("./SuperAppEnvironment"); | ||
const SuperAppTargetEnum_1 = require("./SuperAppTargetEnum"); | ||
class SuperAppContext { | ||
@@ -26,5 +25,6 @@ constructor() { | ||
} | ||
if (!Object.values(SuperAppTargetEnum_1.SuperAppTargetEnum).includes(this.target)) { | ||
throw new Error("init.error.invalid.target"); | ||
} | ||
//TODO validar contra o backend no init ou deixar para o openMiniApp? | ||
// if (!Object.values(SuperAppTargetEnum).includes(this.target)) { | ||
// throw new Error("init.error.invalid.target"); | ||
// } | ||
const customMethods = (_a = this.methods) === null || _a === void 0 ? void 0 : _a.customMethods; | ||
@@ -31,0 +31,0 @@ if (customMethods) { |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @deprecated use string. Com o suporte a targets dinâmicos o enum fixo na lib não é mais usado. | ||
*/ | ||
export declare enum SuperAppTargetEnum { | ||
@@ -2,0 +5,0 @@ "AME_EMPRESAS_WEB" = "AME_EMPRESAS_WEB", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SuperAppTargetEnum = void 0; | ||
// Apenas targets web | ||
/** | ||
* @deprecated use string. Com o suporte a targets dinâmicos o enum fixo na lib não é mais usado. | ||
*/ | ||
var SuperAppTargetEnum; | ||
@@ -6,0 +8,0 @@ (function (SuperAppTargetEnum) { |
@@ -5,2 +5,3 @@ import UploadFileInput from "../model/input/UploadFileInput"; | ||
import DownloadFileInputModel from "../model/download/DownloadFileInputModel"; | ||
import { FileBase64Output } from "../model/output/FileBase64Output"; | ||
export default class FileService { | ||
@@ -14,2 +15,4 @@ private selectedFiles; | ||
downloadFile(params: DownloadFileInputModel): Promise<void>; | ||
getFileAsBase64String(fileId: string): Promise<FileBase64Output>; | ||
private formatBase64Output; | ||
} |
@@ -105,4 +105,32 @@ "use strict"; | ||
} | ||
getFileAsBase64String(fileId) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (!fileId) { | ||
throw new Error("fileId.is.required"); | ||
} | ||
const file = this.selectedFiles[fileId]; | ||
if (!file) { | ||
throw new Error("not.found"); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.readAsDataURL(file); | ||
reader.onload = () => { | ||
resolve(this.formatBase64Output(file.name, String(reader.result))); | ||
}; | ||
reader.onerror = () => { | ||
reject("getFileAsBase64String.convertion.error"); | ||
}; | ||
}); | ||
}); | ||
} | ||
formatBase64Output(fileName, input) { | ||
const fileTypeSplit = fileName.split("."); | ||
const fileType = fileTypeSplit.length > 1 ? fileTypeSplit[fileTypeSplit.length - 1] : ""; | ||
const inputSplit = input.substring(input.indexOf("/") + 1); | ||
const base64 = inputSplit.split(",")[1]; | ||
return { fileType: fileType, base64: base64 }; | ||
} | ||
} | ||
exports.default = FileService; | ||
//# sourceMappingURL=FileService.js.map |
@@ -13,2 +13,4 @@ import MiniAppConfigs from "../model/MiniAppConfigs"; | ||
import { CustomMethodListOutput } from "../model/output/CustomMethodListOutput"; | ||
import { FileBase64Output } from "../model/output/FileBase64Output"; | ||
import { Base64FileInput } from "../model/input/FileInput"; | ||
export default class SuperAppService { | ||
@@ -31,2 +33,3 @@ superApp: SuperApp; | ||
downloadFile(params: DownloadFileInputModel): Promise<void>; | ||
getFileAsBase64String(params: Base64FileInput): Promise<FileBase64Output>; | ||
httpPost(url: string, data?: any, config?: any): Promise<HttpResponse>; | ||
@@ -33,0 +36,0 @@ httpGet(url: string, config?: any): Promise<HttpResponse>; |
@@ -123,2 +123,7 @@ "use strict"; | ||
} | ||
getFileAsBase64String(params) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return this.fileService.getFileAsBase64String(params.fileId); | ||
}); | ||
} | ||
httpPost(url, data, config) { | ||
@@ -125,0 +130,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function* () { |
@@ -1,2 +0,2 @@ | ||
declare const _default: "4.1.0-beta.1"; | ||
declare const _default: "4.1.0"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = "4.1.0-beta.1"; | ||
exports.default = "4.1.0"; | ||
//# sourceMappingURL=version.js.map |
@@ -223,3 +223,19 @@ "use strict"; | ||
}); | ||
test.each([{ target: "AME_EMPRESAS_WEB" }, { target: src_1.SuperAppTargetEnum.AME_EMPRESAS_WEB }])("Ame.init target supports string and SuperAppEnvironment %j", (testContext) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const ame = new SuperApp_1.default(); | ||
let errors; | ||
try { | ||
ame.init({ | ||
url: "http://localhost", | ||
environment: src_1.SuperAppEnvironment.DEV, | ||
target: testContext.target, | ||
version: "1.0.0-host", | ||
}); | ||
} | ||
catch (e) { | ||
errors = e; | ||
} | ||
expect(errors).toBeUndefined(); | ||
})); | ||
}); | ||
//# sourceMappingURL=AmeSuperApp.test.js.map |
@@ -78,3 +78,19 @@ "use strict"; | ||
})); | ||
const cases = [ | ||
["filename.txt", "txt"], | ||
["filename.txt.abc", "abc"], | ||
["filename", ""], | ||
]; | ||
test.each(cases)("arquivo %p , deve retornar %p", (fileName, expectedResult) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const fileService = new FileService_1.default(); | ||
const fileContent = "teste"; | ||
const fakeFile = new File([fileContent], fileName); | ||
const contentBase64 = btoa(fileContent); | ||
const resSelect = yield fileService.selectFile(fakeFile); | ||
const res = yield fileService.getFileAsBase64String(resSelect.id); | ||
expect(res).toBeDefined(); | ||
expect(res.fileType).toBe(expectedResult); | ||
expect(res.base64).toBe(contentBase64); | ||
})); | ||
}); | ||
//# sourceMappingURL=FileService.test.js.map |
{ | ||
"name": "ame-super-app-web", | ||
"version": "4.1.0-beta.1", | ||
"version": "4.1.0", | ||
"_versionBetaExample": "1.0.2-beta.0", | ||
@@ -23,2 +23,3 @@ "__versionBetaExample": "1.0.2-alpha.0", | ||
"build-all": "yarn clean && yarn build && yarn webpack:build", | ||
"build-all-no-clean": "yarn build && yarn webpack:build", | ||
"esbuild-browser": "esbuild src/index.ts --bundle --minify --sourcemap=external --outfile=dist/ame-super-app-web.js", | ||
@@ -33,2 +34,5 @@ "esbuild-browser:dev": "esbuild src/index.ts --bundle --outfile=dist/ame-super-app-web.js", | ||
"unlink-ame-minha-conta": "./scripts/unlink-target.sh ame-minha-conta", | ||
"watch-build": "nodemon --watch 'src/**/*' -e ts,tsx --exec 'yarn build-all-no-clean'", | ||
"playground": "./scripts/playground.sh", | ||
"dev": "concurrently --kill-others \"npm run watch-build\" \"npm run playground\"", | ||
"cypress:open": "cd ./test/e2e && cypress open", | ||
@@ -49,3 +53,3 @@ "cypress:ci": "cd ./test/e2e && cypress run" | ||
"babel-loader": "^8.2.2", | ||
"concurrently": "^6.3.0", | ||
"concurrently": "^7.5.0", | ||
"cypress": "^9.5.4", | ||
@@ -52,0 +56,0 @@ "esbuild": "^0.11.11", |
# ame-super-app-web | ||
API de suporte para super-app sites da Ame | ||
## O que é esse projeto? | ||
O ame-super-app-web é a biblioteca que permite tornar um site, que chamaremos de target, em um ambiente capaz de executar mini-apps construídos com a plataforma de mini-apps web da Ame. | ||
Um target que deseje adotar a plataforma de mini-apps web da Ame, deve instalar esse pacote e seguir os passos descritos nesse manual a seguir. | ||
## Como utilizar? | ||
Para utilizar esse pacote é necessário executar dois passos: | ||
1. Invocar a função de inicialização da lib *Ame.init()* num ponto de entrada/configuração do site | ||
2. Criar uma rota/página na qual o mini-app será exibido. | ||
## Inicialização da lib | ||
Em algum momento no início do ciclo de vida da aplicação (recomendado: No index da aplicação ou equivalente) a função Ame.init deve ser chamada. | ||
Parâmetros obrigatórios: | ||
### environment | ||
Os valores suportados são de "dev", "hml" ou "prod", de acordo com o ambiente da aplicação. | ||
O enum *SuperAppEnvironment* também pode ser utilizado. | ||
### url | ||
Endereço principal do site onde a plataforma está instalada. Ex: "https://www.amedigital.com" | ||
### target | ||
- Identifica qual sistema está rodando a plataforma de mini-apps.</li> | ||
- Essa configuração permite escolher os mini-apps adequados ao sistema que está sendo executado.</li> | ||
- Novos targets precisam de um setup prévio para funcionar adequadamente.</li> | ||
- Entre em contato para avaliarmos a criação de um novo target.</li> | ||
## Código de exemplo | ||
Para rodar o projeto de exemplo basta seguir os seguintes passos: | ||
1. rodar o comando yarn example | ||
2. acessar o diretório ./ame-super-app-web/example/ame-super-app-web-example | ||
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1041762
223
4507
1
50