mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat: 新增浏览器插件
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
export const EXTENSION_NAME = 'ECBI 数据同步';
|
||||
|
||||
export const OPEN_API_PATHS = {
|
||||
pddShopList: '/open/v1/channel/pdd/shop/list',
|
||||
pddGoodsAdFeeBatchImport: '/open/v1/channel/pdd/goods/adfee/batch-import',
|
||||
} as const;
|
||||
|
||||
export const OPEN_SCOPES = {
|
||||
pddShopRead: 'open:scope:pdd_shop:read',
|
||||
pddGoodsAdFeeImport: 'open:scope:pdd_goods_ad_fee:import',
|
||||
} as const;
|
||||
@@ -0,0 +1,32 @@
|
||||
export type ExtensionErrorCode =
|
||||
| 'PLATFORM_NOT_SUPPORTED'
|
||||
| 'PAGE_NOT_READY'
|
||||
| 'DATA_PARSE_FAILED'
|
||||
| 'INVALID_DATA'
|
||||
| 'AUTH_FAILED'
|
||||
| 'API_REQUEST_FAILED'
|
||||
| 'API_BUSINESS_ERROR'
|
||||
| 'NETWORK_ERROR'
|
||||
| 'CONFIG_MISSING'
|
||||
| 'NO_ACTIVE_TAB'
|
||||
| 'UNKNOWN';
|
||||
|
||||
export class ExtensionError extends Error {
|
||||
readonly code: ExtensionErrorCode;
|
||||
|
||||
constructor(code: ExtensionErrorCode, message: string) {
|
||||
super(message);
|
||||
this.name = 'ExtensionError';
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
export function toUserMessage(error: unknown): string {
|
||||
if (error instanceof ExtensionError) {
|
||||
return error.message;
|
||||
}
|
||||
if (error instanceof Error && error.message) {
|
||||
return error.message;
|
||||
}
|
||||
return '发生未知错误,请稍后重试';
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { AdvertisingCostBatch, PageContext } from '@/types/advertisingCost';
|
||||
|
||||
export type ExtensionMessage =
|
||||
| { type: 'GET_PAGE_CONTEXT' }
|
||||
| { type: 'PARSE_ADVERTISING_COST'; payload: { feeDate: string } }
|
||||
| { type: 'PING' };
|
||||
|
||||
export type ExtensionResponse =
|
||||
| { ok: true; data: PageContext }
|
||||
| { ok: true; data: AdvertisingCostBatch }
|
||||
| { ok: true; data: { pong: true } }
|
||||
| { ok: false; code: string; message: string };
|
||||
|
||||
export function isExtensionMessage(value: unknown): value is ExtensionMessage {
|
||||
if (!value || typeof value !== 'object') return false;
|
||||
const type = (value as { type?: unknown }).type;
|
||||
return (
|
||||
type === 'GET_PAGE_CONTEXT' ||
|
||||
type === 'PARSE_ADVERTISING_COST' ||
|
||||
type === 'PING'
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user