ame-super-app-web
Advanced tools
Comparing version 0.5.5 to 0.6.0
@@ -5,3 +5,2 @@ /** | ||
*/ | ||
import SuperApp from "./SuperApp"; | ||
import EnvironmentManager from "./helper/EnvironmentManager"; | ||
@@ -11,2 +10,3 @@ import InitInputI from "./model/input/InitInput"; | ||
import OpenMiniAppWorkspaceInputI from "./model/input/OpenMiniAppWorkspaceInput"; | ||
import SuperApp from "./SuperApp"; | ||
declare const superApp: SuperApp; | ||
@@ -13,0 +13,0 @@ export declare type InitInput = InitInputI; |
@@ -9,5 +9,5 @@ "use strict"; | ||
*/ | ||
const SuperApp_1 = (0, tslib_1.__importDefault)(require("./SuperApp")); | ||
const EnvironmentManager_1 = (0, tslib_1.__importDefault)(require("./helper/EnvironmentManager")); | ||
exports.EnvironmentManager = EnvironmentManager_1.default; | ||
const SuperApp_1 = (0, tslib_1.__importDefault)(require("./SuperApp")); | ||
// setup web | ||
@@ -14,0 +14,0 @@ const superApp = new SuperApp_1.default(); |
export default interface OpenMiniAppWorkspaceInput { | ||
container: HTMLElement; | ||
url: string; | ||
slug: string; | ||
url?: string; | ||
shareId?: string; | ||
} |
@@ -1,6 +0,6 @@ | ||
import MiniAppData from "./MiniAppData"; | ||
import MiniAppDataOutput from "./output/MiniAppDataOutput"; | ||
import SuperAppData from "./SuperAppData"; | ||
export default interface MiniAppConfigs { | ||
miniAppData: MiniAppData; | ||
miniAppData: MiniAppDataOutput; | ||
superAppData: SuperAppData; | ||
} |
@@ -0,4 +1,64 @@ | ||
import MiniappPermissionEnum from "./MiniappPermissionEnum"; | ||
import { MiniAppPermission } from "./MiniAppPermission"; | ||
export default interface MiniAppData { | ||
id: string; | ||
slug: string; | ||
featureToggleKey: string; | ||
organization: Organization; | ||
url: string; | ||
name: string; | ||
sceneType: string; | ||
title: string; | ||
publicKey?: string; | ||
type: string; | ||
trusted: boolean; | ||
isWorkspace: boolean; | ||
developerEmail: string; | ||
extras: any; | ||
permissions?: Array<MiniappPermissionEnum>; | ||
miniAppPermissions?: Array<MiniAppPermission>; | ||
initializationInfos: InitializationInfos; | ||
/** | ||
* storage key do miniapp, usado para criptografia de dados de um miniapp usando Ame.storage | ||
*/ | ||
storageKey: string; | ||
slug: string; | ||
/** | ||
* chave da stack de navegação de miniapps | ||
*/ | ||
stackKey: string; | ||
/** | ||
* controla se o miniapp requer que o cliente esteja validado no fluxo de KYC da Ame | ||
*/ | ||
customerIdentityValidationEnabled: boolean; | ||
/** | ||
* controla se o cliente terá que validar documentos durante a validação de KYC da Ame | ||
*/ | ||
customerIdentityValidationOcrEnabled: boolean; | ||
/** | ||
* metadados vindos do manager | ||
*/ | ||
metadata: any; | ||
/** | ||
* dados de id e env da api de share, quando aplicável | ||
*/ | ||
workspaceData?: WorkspaceData; | ||
} | ||
export interface WorkspaceData { | ||
shareId: string; | ||
shareEnvironment: string; | ||
} | ||
export declare class MiniAppDataFactory { | ||
static makeShallowInstance(): MiniAppData; | ||
} | ||
export interface InitializationInfos { | ||
shareContext: { | ||
valuesPromise: Promise<any>; | ||
id: string; | ||
}; | ||
navigationParams: {}; | ||
} | ||
export interface Organization { | ||
owner: { | ||
email: string; | ||
}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MiniAppDataFactory = void 0; | ||
class MiniAppDataFactory { | ||
static makeShallowInstance() { | ||
return { | ||
storageKey: "", | ||
developerEmail: "", | ||
extras: undefined, | ||
id: "", | ||
featureToggleKey: "", | ||
isWorkspace: false, | ||
name: "", | ||
sceneType: "", | ||
slug: "", | ||
stackKey: "", | ||
title: "", | ||
trusted: false, | ||
type: "", | ||
url: "", | ||
metadata: {}, | ||
initializationInfos: { | ||
shareContext: { valuesPromise: Promise.resolve(), id: "" }, | ||
navigationParams: {}, | ||
}, | ||
organization: { | ||
owner: { | ||
email: "", | ||
}, | ||
}, | ||
customerIdentityValidationEnabled: false, | ||
customerIdentityValidationOcrEnabled: false, | ||
}; | ||
} | ||
} | ||
exports.MiniAppDataFactory = MiniAppDataFactory; | ||
//# sourceMappingURL=MiniAppData.js.map |
@@ -7,2 +7,4 @@ import InitInput from "./model/input/InitInput"; | ||
import StorageKeyService from "./service/StorageKeyService"; | ||
import MiniAppManagerService from "./service/MiniAppManagerService"; | ||
import MiniAppData from "./model/MiniAppData"; | ||
declare global { | ||
@@ -18,7 +20,9 @@ interface Window { | ||
storageKeyService: StorageKeyService; | ||
miniAppManagerService: MiniAppManagerService; | ||
context: SuperAppContext; | ||
constructor(); | ||
init: (config: InitInput) => void; | ||
openMiniApp: (input: OpenMiniAppInput) => never; | ||
openMiniAppWorkspace: (input: OpenMiniAppWorkspaceInput) => void; | ||
openMiniApp: (input: OpenMiniAppInput) => Promise<void>; | ||
openMiniAppWorkspace: (input: OpenMiniAppWorkspaceInput) => Promise<void>; | ||
generateMiniAppDataToLegacyOpenWorkspaceMethod: (input: OpenMiniAppWorkspaceInput) => Promise<MiniAppData>; | ||
private initMiniApp; | ||
@@ -35,7 +39,1 @@ postMessageToWindow: (window: any, message: any) => void; | ||
} | ||
export interface Message { | ||
methodName: string; | ||
promiseId: string; | ||
args: Array<any>; | ||
res?: any; | ||
} |
@@ -8,2 +8,5 @@ "use strict"; | ||
const StorageKeyService_1 = (0, tslib_1.__importDefault)(require("./service/StorageKeyService")); | ||
const Config_1 = (0, tslib_1.__importDefault)(require("./config/Config")); | ||
const MiniAppManagerService_1 = (0, tslib_1.__importDefault)(require("./service/MiniAppManagerService")); | ||
const SuperAppEnvironment_1 = require("./model/SuperAppEnvironment"); | ||
class SuperApp { | ||
@@ -21,13 +24,50 @@ constructor() { | ||
ctx.validateInit(); | ||
Config_1.default.init(config.environment); | ||
window.addEventListener("message", this.receiveMessage); | ||
}; | ||
this.openMiniApp = (input) => { | ||
input; | ||
// TODO implementação de prod | ||
throw new Error("not.implemented"); | ||
}; | ||
this.openMiniAppWorkspace = (input) => { | ||
this.openMiniApp = (input) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
if (!input.container || !input.slug) { | ||
throw new Error("slug.and.container.required"); | ||
} | ||
const miniAppData = yield this.miniAppManagerService.findMiniApp(input.slug); | ||
if (!miniAppData.url) { | ||
throw new Error("openMiniApp.unpublished"); | ||
} | ||
this.context.miniAppData = miniAppData; | ||
this.context.miniAppData.storageKey = yield this.storageKeyService.generateKey(input.slug); | ||
//TODO initialization params | ||
yield this.initMiniApp({ container: input.container, slug: input.slug, url: miniAppData.url }); | ||
}); | ||
this.openMiniAppWorkspace = (input) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
console.debug("openMiniAppByWorkspace", input.url); | ||
this.initMiniApp(input); | ||
}; | ||
this.context.miniAppData = yield this.generateMiniAppDataToLegacyOpenWorkspaceMethod(input); | ||
const miniAppData = this.context.miniAppData; | ||
console.debug("miniAppData", miniAppData); | ||
const initParams = { url: miniAppData.url, container: input.container, slug: miniAppData.slug }; | ||
yield this.initMiniApp(initParams); | ||
}); | ||
this.generateMiniAppDataToLegacyOpenWorkspaceMethod = (input) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
let miniAppData; | ||
if (input.slug) { | ||
miniAppData = yield this.miniAppManagerService.findMiniApp(input.slug); | ||
} | ||
else if (input.shareId) { | ||
//TODO implementar abertura por shareId. Será necessária para o novo conceito com permissions programáticas. | ||
throw new Error("open.by.shareId.not.implemented"); | ||
//miniAppData = await this.miniAppManagerService.findMiniAppByShareId(input.shareId); | ||
} | ||
else { | ||
throw new Error("shareId.or.slug.required"); | ||
} | ||
const storageKey = yield this.storageKeyService.generateKey(miniAppData.slug); | ||
//TODO implementar todos os campos faltando para completar a interface MiniAppData | ||
return { | ||
url: input.url, | ||
slug: input.slug, | ||
trusted: this.context.environment === SuperAppEnvironment_1.SuperAppEnvironment.DEV, | ||
isWorkspace: true, | ||
storageKey: storageKey, | ||
permissions: miniAppData === null || miniAppData === void 0 ? void 0 : miniAppData.permissions, | ||
}; | ||
}); | ||
this.postMessageToWindow = (window, message) => { | ||
@@ -48,2 +88,7 @@ //TODO validar segurança | ||
const originWindow = event.source.window; | ||
if (originWindow === window) { | ||
console.debug("ignorando mensagem enviada pela mesma window"); | ||
// não aceita mensagens do próprio window pai | ||
return; | ||
} | ||
const data = event.data; | ||
@@ -91,2 +136,3 @@ const methodName = data === null || data === void 0 ? void 0 : data.methodName; | ||
this.storageKeyService = new StorageKeyService_1.default(); | ||
this.miniAppManagerService = new MiniAppManagerService_1.default(); | ||
this.context = new SuperAppContext_1.default(); | ||
@@ -97,2 +143,3 @@ } | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
console.debug("abrindo url no sandbox", input.url); | ||
if (!input.container) { | ||
@@ -112,6 +159,2 @@ throw new Error("container.not.found"); | ||
// frame.setAttribute("csp", "frame-src http://local.calindra.tech/*"); | ||
this.context.miniAppData = { | ||
storageKey: yield this.storageKeyService.generateKey(input.slug), | ||
slug: input.slug, | ||
}; | ||
console.debug("parent: ==== contextBeforeOpenMiniApp", this.context); | ||
@@ -118,0 +161,0 @@ input.container.appendChild(frame); |
@@ -1,2 +0,2 @@ | ||
declare const _default: "0.5.5"; | ||
declare const _default: "0.6.0"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = "0.5.5"; | ||
exports.default = "0.6.0"; | ||
//# sourceMappingURL=version.js.map |
@@ -9,2 +9,6 @@ "use strict"; | ||
const SuperAppFactory_1 = (0, tslib_1.__importDefault)(require("./helper/SuperAppFactory")); | ||
const nock_1 = (0, tslib_1.__importDefault)(require("nock")); | ||
const FindMiniAppBySlugFixture_1 = (0, tslib_1.__importDefault)(require("./fixture/FindMiniAppBySlugFixture")); | ||
const Config_1 = (0, tslib_1.__importDefault)(require("../src/config/Config")); | ||
const NockHelper_1 = (0, tslib_1.__importDefault)(require("./helper/NockHelper")); | ||
describe("AmeSuperApp structural tests", () => { | ||
@@ -47,3 +51,23 @@ test("validate imports", () => { | ||
}); | ||
test("SuperApp.openMiniApp()", () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
var _a; | ||
const slug = "mySlug"; | ||
const superApp = SuperAppFactory_1.default.withConfigs(); | ||
(0, nock_1.default)(`${Config_1.default.profile.miniAppManager.endpoint}/o/mini-apps/${slug}`) | ||
.get(/.*/) | ||
.reply(200, FindMiniAppBySlugFixture_1.default, NockHelper_1.default.DEFAULT_HEADERS); | ||
yield superApp.openMiniApp({ | ||
container: { | ||
appendChild: (iframe) => { | ||
expect(iframe).toBeDefined(); | ||
}, | ||
}, | ||
slug: slug, | ||
}); | ||
const miniAppData = (_a = superApp.context) === null || _a === void 0 ? void 0 : _a.miniAppData; | ||
expect(miniAppData).toBeDefined(); | ||
expect(miniAppData.slug).toBe(slug); | ||
expect(miniAppData.url).toBeDefined(); | ||
})); | ||
}); | ||
//# sourceMappingURL=AmeSuperApp.test.js.map |
@@ -0,7 +1,7 @@ | ||
import BridgeMessage from "../../src/model/Message"; | ||
import MiniAppConfigs from "../../src/model/MiniAppConfigs"; | ||
import { Message } from "../../src/SuperApp"; | ||
export default class BridgeHelper { | ||
static mockStorageKey(): string; | ||
static mockMethodMessage(methodName: string, args: any[], callback: (message: Message) => void): any; | ||
static mockMethodMessage(methodName: string, args: any[], callback: (message: BridgeMessage) => void): any; | ||
static getConfigs: (configs?: any) => Promise<MiniAppConfigs>; | ||
} |
@@ -11,3 +11,4 @@ "use strict"; | ||
test("validate method on SuperAppService", () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
const ameSuperAppService = new SuperAppService_1.default(new SuperApp_1.default()); | ||
const superApp = new SuperApp_1.default(); | ||
const ameSuperAppService = new SuperAppService_1.default(superApp); | ||
const methodName = "askUserData"; | ||
@@ -14,0 +15,0 @@ const argsToCall = [{ url: "https://baconipsum.com/api/?type=meat-and-filler" }]; |
{ | ||
"name": "ame-super-app-web", | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"_versionBetaExample": "1.0.2-beta.0", | ||
@@ -5,0 +5,0 @@ "__versionBetaExample": "1.0.2-alpha.0", |
@@ -9,4 +9,6 @@ # ame-super-app-web | ||
## BFF (bff-ame-sua conta) | ||
Para rodar o ame-sua-conta primeiro vá no repositório do projeto bff-ame-sua-conta e faço o seguinte procedimento: | ||
## BFF (bff-ame-sua-conta) | ||
instalar o `redis` e rodar na porta default | ||
@@ -20,3 +22,8 @@ | ||
<br /> | ||
<br /> | ||
- Caso ocorra algum erro como `connect ECONNREFUSED` durante a execução do comando `yarn start`, prefira executar o redis localmente. | ||
<a><https://redis.io/download></a> | ||
### criar arquivo .env com o conteúdo | ||
@@ -47,3 +54,6 @@ | ||
```yarn start``` | ||
<br /> | ||
Com o bff-ame-sua-conta rodando vá no repositório do projeto ame-sua-conta e faça o seguinte procedimento: | ||
## Front (ame-sua-conta) | ||
@@ -50,0 +60,0 @@ |
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
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
778246
127
2019
85