@cregis/market-app-web-sdk
v1.0.15
Published
Reusable frontend integration layer for third-party app-market web applications.
Readme
market-app-web-sdk
@cregis/market-app-web-sdk is the reusable frontend integration layer for App Market third-party applications.
What it provides
- SSO bridge flow
- Local auth state storage
- HTTP auth interception and re-auth trigger
- Route guard and visible-menu navigation
- App shell layout helpers
- App-scoped permission helpers
- Third-party-mode route and permission adaptation
Install
npm install @cregis/market-app-web-sdkQuick Start
1. Initialize the SDK
import { initCregisMarketAppConfig } from '@cregis/market-app-web-sdk'
initCregisMarketAppConfig({
sdkServerUrl: import.meta.env.VITE_MARKET_APP_SERVER_URL || 'http://127.0.0.1:48088',
})Notes:
- In third-party mode,
sdkServerUrlshould point to the real third-party backend - In internal mode, the SDK automatically resolves the API base to
{origin}/app-market-api/{appCode} - Frontends must never hold
appThirdId/appSecret - If the backend wants to push API errors to
marketingby default, setapp-market.app-api-error-enabled=truein the server SDK config
2. Create an HTTP client
import { createMarketAppHttp } from '@cregis/market-app-web-sdk'
export const http = createMarketAppHttp()The backend is expected to return the standard structure below on success:
{
"code": 200,
"msg": "success",
"data": {}
}Using MarketAppCommonResult<T> from marketing-app-security-sdk is recommended, but any backend response with the same JSON shape is also supported.
3. Install the route guard
import { installMarketAppRouteGuard } from '@cregis/market-app-web-sdk'
installMarketAppRouteGuard(router)4. Use the SSO bridge
<template>
<MarketAppSsoBridge
:bootstrap-login="bootstrapLogin"
:fetch-menu-access="getCurrentMenuAccess"
:fetch-data-permission="getCurrentDataPermission"
:fetch-menus="getCurrentMenus"
/>
</template>Mode Detection
The SDK decides the runtime mode from the current path:
/app-market/{appCode}/...-> internal mode- Anything else -> third-party mode
In internal mode, the SDK automatically:
- Resolves the router base to
/app-market/{appCode} - Resolves the API base to
{origin}/app-market-api/{appCode}
In third-party mode, the SDK uses the configured sdkServerUrl.
Permission Convention
Business pages are expected to declare permission suffixes, for example:
meta: { menuAccess: ['class:query'] }The SDK automatically matches them against the current app-scoped permission set.
Environment Variable
Default env variable:
VITE_MARKET_APP_SERVER_URL
Security Rules
- Do not expose
appThirdId/appSecretto the frontend - Do not call normal
marketingadmin APIs from the third-party frontend - Keep backend authorization checks even when buttons are hidden in the UI
- Keep the backend
allow-originslist aligned with the real page origins
Docs
Unified documents:
docs/三方独立应用接入.mddocs/三方独立应用架构设计文档.md
