seller-base-service 0.0.1-security → 0.1.12

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.

Potentially problematic release.


This version of seller-base-service might be problematic. Click here for more details.

Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -3
  3. package/dist/babel-config-for-main-project.js +74 -0
  4. package/dist/collection/index.js +189 -0
  5. package/dist/collection/index.js.map +1 -0
  6. package/dist/common/index.js +206 -0
  7. package/dist/common/index.js.map +1 -0
  8. package/dist/feedback/index.js +249 -0
  9. package/dist/feedback/index.js.map +1 -0
  10. package/dist/index.d.ts +1117 -0
  11. package/dist/index.js +3223 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/notification/index.js +2373 -0
  14. package/dist/notification/index.js.map +1 -0
  15. package/dist/otp/index.js +197 -0
  16. package/dist/otp/index.js.map +1 -0
  17. package/dist/redteam.js +64 -0
  18. package/dist/report/index.js +330 -0
  19. package/dist/report/index.js.map +1 -0
  20. package/dist/sip/index.js +191 -0
  21. package/dist/sip/index.js.map +1 -0
  22. package/dist/upload/index.js +235 -0
  23. package/dist/upload/index.js.map +1 -0
  24. package/package.json +40 -3
  25. package/src/development/index.ts +38 -0
  26. package/src/index.ts +6 -0
  27. package/src/modules/collection/constants.ts +11 -0
  28. package/src/modules/collection/index.ts +9 -0
  29. package/src/modules/collection/service.ts +53 -0
  30. package/src/modules/collection/types.ts +31 -0
  31. package/src/modules/common/index.ts +7 -0
  32. package/src/modules/common/interceptors.ts +16 -0
  33. package/src/modules/common/service.ts +60 -0
  34. package/src/modules/common/types.ts +36 -0
  35. package/src/modules/feedback/index.ts +6 -0
  36. package/src/modules/feedback/service.ts +73 -0
  37. package/src/modules/feedback/types.ts +68 -0
  38. package/src/modules/index.ts +77 -0
  39. package/src/modules/notification/action.ts +215 -0
  40. package/src/modules/notification/constants.ts +420 -0
  41. package/src/modules/notification/index.ts +23 -0
  42. package/src/modules/notification/service.ts +90 -0
  43. package/src/modules/notification/types.ts +155 -0
  44. package/src/modules/otp/constants.ts +39 -0
  45. package/src/modules/otp/index.ts +11 -0
  46. package/src/modules/otp/service.ts +28 -0
  47. package/src/modules/otp/types.ts +13 -0
  48. package/src/modules/report/constants.ts +20 -0
  49. package/src/modules/report/index.ts +19 -0
  50. package/src/modules/report/service.ts +100 -0
  51. package/src/modules/report/types.ts +31 -0
  52. package/src/modules/report/utils.ts +74 -0
  53. package/src/modules/sip/index.ts +2 -0
  54. package/src/modules/sip/service.ts +59 -0
  55. package/src/modules/sip/types.ts +33 -0
  56. package/src/modules/upload/index.ts +8 -0
  57. package/src/modules/upload/service.ts +94 -0
  58. package/src/modules/upload/types.ts +34 -0
@@ -0,0 +1,39 @@
1
+ /**
2
+ * OtpSeed 是所有 Otp 验证参数的类型配置
3
+ */
4
+ export enum OtpSeed {
5
+ /**
6
+ * 下载报告
7
+ */
8
+ Report = 'report',
9
+
10
+ /**
11
+ * 添加银行账号
12
+ */
13
+ AddBankAccount = 'add-bank-account',
14
+
15
+ /**
16
+ * 编辑银行账号,删除银行账号
17
+ */
18
+ EditBankAccount = 'edit-bank-account',
19
+
20
+ /**
21
+ * 修改密码返回400,需要二次验证带上此类型
22
+ */
23
+ ResetPassword = 'reset-password',
24
+
25
+ /**
26
+ * 绑定手机,修改手机
27
+ */
28
+ PhoneNumber = 'phone-number',
29
+
30
+ /**
31
+ * 钱包身份认证
32
+ */
33
+ KycVerify = 'kyc-verify',
34
+
35
+ /**
36
+ * 添加验证支付密码
37
+ */
38
+ PaymentPasscode = 'payment-passcode',
39
+ }
@@ -0,0 +1,11 @@
1
+ export {
2
+ OtpSeed
3
+ } from './constants';
4
+
5
+ export {
6
+ default as OtpService
7
+ } from './service';
8
+
9
+ export {
10
+ OtpVerifyData
11
+ } from './types';
@@ -0,0 +1,28 @@
1
+ import { Service, ServiceModule, APIPromise, APIExternalPromise, APIRequestConfig } from 'seller-base';
2
+ import { OtpVerifyData } from './types';
3
+
4
+ export default class OtpService extends ServiceModule {
5
+ public static $instance: OtpService;
6
+
7
+ constructor(service: Service) {
8
+ super(service);
9
+ this.name = 'otp';
10
+ OtpService.$instance = this;
11
+ }
12
+
13
+ /**
14
+ * 获取短信验证码
15
+ * @see https://api.seller.shopee.io/project/50/interface/api/7950
16
+ */
17
+ public sendSmsOtp(data: OtpVerifyData, config?: APIRequestConfig): APIPromise<{}> {
18
+ return this.api.v3Request.post('/general/send_sms_otp/', data, config) as APIExternalPromise<{}>;
19
+ }
20
+
21
+ /**
22
+ * 发送语音验证码
23
+ * @see https://api.seller.shopee.io/project/50/interface/api/9270
24
+ */
25
+ public sendVoiceOtp(data: OtpVerifyData, config?: APIRequestConfig): APIPromise<{}> {
26
+ return this.api.v3Request.post('/general/send_voice_otp/', data, config) as APIExternalPromise<{}>;
27
+ }
28
+ }
@@ -0,0 +1,13 @@
1
+ import { OtpSeed } from './constants';
2
+
3
+ export interface OtpVerifyData {
4
+ /**
5
+ * OTP 验证的手机号
6
+ */
7
+ phone?: string;
8
+
9
+ /**
10
+ * OTP 验证类型
11
+ */
12
+ otpSeed: OtpSeed;
13
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 文件类型配置
3
+ */
4
+ export const FileTypeConfig: { [key: string]: string } = {
5
+ xls: 'application/vnd.ms-excel',
6
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
7
+ csv: 'text/plain;charset=utf-8',
8
+ zip: 'application/zip',
9
+ };
10
+
11
+ /**
12
+ * 报表状态
13
+ */
14
+ export enum ReportStatus {
15
+ PROCESSING = 1,
16
+ DOWNLOADABLE = 2,
17
+ DOWNLOADED = 3,
18
+ FAILED = 4,
19
+ DELETED = 5
20
+ }
@@ -0,0 +1,19 @@
1
+ export {
2
+ FileTypeConfig,
3
+ ReportStatus
4
+ } from './constants';
5
+
6
+ export {
7
+ default as ReportService
8
+ } from './service';
9
+
10
+ export {
11
+ downloadBlobData,
12
+ parseBlobJsonResponse
13
+ } from './utils';
14
+
15
+ export {
16
+ Report,
17
+ ReportListParams,
18
+ ReportListResponse
19
+ } from './types';
@@ -0,0 +1,100 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Service, ServiceModule, APIPromise, APIExternalPromise, APIRequestConfig, APIExternalResponse } from 'seller-base';
3
+ import { FileTypeConfig } from './constants';
4
+ import { parseBlobJsonResponse, normalizeError, downloadBlobData } from './utils';
5
+ import { Report, ReportListParams, ReportListResponse } from './types';
6
+
7
+ /**
8
+ * 这整个report不应该将具体的实现放在这里,后续需要去掉
9
+ */
10
+ interface ServiceAPICreatorConfig extends APIRequestConfig {
11
+ responseInterceptor: any;
12
+ }
13
+
14
+ export default class ReportService extends ServiceModule {
15
+ public static $instance: ReportService;
16
+
17
+ constructor(service: Service) {
18
+ super(service);
19
+ this.name = 'report';
20
+ ReportService.$instance = this;
21
+ }
22
+
23
+ protected getRequestConfig() {
24
+ return {
25
+ downloadRequest: {
26
+ path: 'api/v3',
27
+ useTransform: false,
28
+ useCamelCaseKeys: false,
29
+ config: {
30
+ skipError: true,
31
+ responseType: 'blob',
32
+ headers: {
33
+ Accept: 'application/json, application/force-download, text/plain, */*'
34
+ },
35
+ namespace: Service.Constants.APICommonNamespace.v3Request,
36
+ },
37
+ requestInterceptors: [(config: any) => {
38
+ Object.assign(config, {
39
+ skipErorr: config.skipErorr || true,
40
+ });
41
+ return config;
42
+ }],
43
+
44
+ responseInterceptor: [
45
+ [(res: AxiosResponse) => {
46
+ if (res.data) {
47
+ if (res.headers['content-disposition']) {
48
+ const matches = res.headers['content-disposition'].match(/.*filename="([a-zA-Z0-9._]+)"/i);
49
+ downloadBlobData(new Blob([res.data]), matches ? matches[1] : '', res.config.url, FileTypeConfig);
50
+ (res as any).error = false;
51
+ return res;
52
+ } else {
53
+ return parseBlobJsonResponse(res).then(res => {
54
+ res.error = res.data ? normalizeError(res.data.code, res.data.message, new Error('ParseBlobError: Server response error.')) : normalizeError(null, null, new Error('ParseBlobError: Default Error.')),
55
+ res.data = null;
56
+ return res;
57
+ });
58
+ }
59
+ }
60
+ }, (error: Error) => {
61
+ return {
62
+ data: null,
63
+ error: normalizeError(null, null, error),
64
+ headers: null,
65
+ config: null
66
+ } as APIExternalResponse;
67
+ }]
68
+ ]
69
+ } as ServiceAPICreatorConfig
70
+ };
71
+ }
72
+
73
+ /**
74
+ * 下载 Report 的基础方法
75
+ */
76
+ public downloadReport(url: string, params: any = {}, config: APIRequestConfig = {}): APIPromise<any> {
77
+ return this.api.downloadRequest.get(url, Object.assign({}, config, {
78
+ params: Service.Utility.snakeCaseKeys(params)
79
+ })) as APIExternalPromise<any>;
80
+ }
81
+
82
+ /**
83
+ * 获取 Report 详情的基础方法
84
+ */
85
+ public getReport(url: string, reportId: number, config: APIRequestConfig = {}): APIPromise<Report> {
86
+ return this.api.v3Request.get(url, Object.assign({}, config, {
87
+ params: Service.Utility.snakeCaseKeys({ reportId })
88
+ })) as APIExternalPromise<Report>;
89
+ }
90
+
91
+ /**
92
+ * 获取 Report List 的基础方法
93
+ */
94
+ public getReportList(url: string, params: ReportListParams, config: APIRequestConfig = {}): APIPromise<ReportListResponse> {
95
+ const status = params.status ? params.status.join(',') : undefined;
96
+ return this.api.v3Request.get(url, Object.assign({}, config, {
97
+ params: Service.Utility.snakeCaseKeys(Object.assign({}, params, { status }))
98
+ })) as APIExternalPromise<ReportListResponse>;
99
+ }
100
+ }
@@ -0,0 +1,31 @@
1
+ import { CommonListResponse } from '../common';
2
+
3
+ /**
4
+ * 获取 Report List 的参数
5
+ */
6
+ export interface ReportListParams {
7
+ pageNumber: number;
8
+ pageSize: number;
9
+ parentType: string;
10
+ subType?: string;
11
+ status: number[];
12
+ }
13
+
14
+ /**
15
+ * 单个 Report 的类型
16
+ */
17
+ export interface Report {
18
+ reportId: number;
19
+ parentType: string;
20
+ reportFileName: string;
21
+ requestTime: number;
22
+ status: number;
23
+ subType?: string;
24
+ userName: string;
25
+ downloadLink?: string;
26
+ }
27
+
28
+ /**
29
+ * Report List 类型
30
+ */
31
+ export type ReportListResponse = CommonListResponse<Report>;
@@ -0,0 +1,74 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Service, APIError, APIPromise } from 'seller-base';
3
+
4
+ /**
5
+ * 创建一个标准 error 的结构,仅仅 ReportService 内部使用
6
+ */
7
+ export function normalizeError(code: number | string, message: string, error: Error): APIError {
8
+ return {
9
+ code: code || Service.Constants.APIPredfinedErrors.Default.CODE,
10
+ message: message || Service.Constants.APIPredfinedErrors.Default.MESSAGE,
11
+ stack: error.stack || error,
12
+ data: null,
13
+ status: 200,
14
+ } as APIError;
15
+ }
16
+
17
+ /**
18
+ * 解析Blob JSON Response,用于把 Blob Data 转化为 JSON Data
19
+ */
20
+ export function parseBlobJsonResponse(res: AxiosResponse<Blob>): APIPromise<any> {
21
+ return new Promise((resolve) => {
22
+ const fileReader = new FileReader();
23
+ fileReader.onload = (e) => {
24
+ let data = {};
25
+ if ((window as any).TextDecoder) {
26
+ const decoder = new TextDecoder('utf-8');
27
+ data = JSON.parse(decoder.decode(new Uint8Array(e.target.result as any)));
28
+ } else {
29
+ data = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(e.target.result as any)));
30
+ }
31
+ resolve({
32
+ data,
33
+ error: false,
34
+ headers: res.headers,
35
+ config: res.config
36
+ });
37
+ };
38
+ fileReader.onerror = () => {
39
+ resolve({
40
+ data: null,
41
+ error: normalizeError(null, null, new Error('ParseBlobError: Default Error.')),
42
+ headers: res.headers,
43
+ config: res.config
44
+ });
45
+ fileReader.abort();
46
+ };
47
+ fileReader.readAsArrayBuffer(res.data);
48
+ }) as APIPromise<any>;
49
+ }
50
+
51
+ /**
52
+ * 下载 Blob Data
53
+ */
54
+ export function downloadBlobData(content: any, filename: string, url: string, fileTypes: { [key: string]: string }) {
55
+ const downLink = document.createElement('a');
56
+
57
+ const matches = filename.match(/.+\.([a-z]+)$/);
58
+ const type = matches ? fileTypes[matches[1]] : undefined;
59
+
60
+ if (!('download' in downLink) || !type) {
61
+ return window.open(url);
62
+ }
63
+
64
+ downLink.download = filename;
65
+ downLink.style.display = 'none';
66
+
67
+ const blobURL = new Blob([content], { type });
68
+
69
+ downLink.href = URL.createObjectURL(blobURL);
70
+
71
+ document.body.appendChild(downLink);
72
+ downLink.click();
73
+ document.body.removeChild(downLink);
74
+ }
@@ -0,0 +1,2 @@
1
+ export { default as SipGlobalService } from './service';
2
+ export { SipOrderResponse, SipOrder, SipOrderItem } from './types';
@@ -0,0 +1,59 @@
1
+ import { SipOrderResponse } from './types';
2
+ import { Service, ServiceModule, APIPromise, APIExternalPromise, APICreatorConfig } from 'seller-base';
3
+ export default class SipGlobalService extends ServiceModule {
4
+ public static $instance: SipGlobalService;
5
+ public static GlobalServiceModule = true; // 公用service
6
+
7
+ constructor(service: Service) {
8
+ super(service);
9
+ this.name = 'sipGlobal';
10
+ SipGlobalService.$instance = this;
11
+ }
12
+
13
+ protected getRequestConfig(): { [key: string]: Partial<APICreatorConfig> } {
14
+ return {
15
+ sipRequestV1: {
16
+ path: 'api/sip/',
17
+ useUnpackData: true
18
+ },
19
+ sipRequest: {
20
+ path: 'api/sip/v2/',
21
+ useUnpackData: true
22
+ }
23
+ };
24
+ }
25
+
26
+ /**
27
+ * getSipOrderDetail 调用SIP接口获取a-shop的订单详情
28
+ */
29
+ public getSipOrderDetail(orderidList: number[], aShopId?: number): APIPromise<SipOrderResponse> {
30
+ const { sipShopid } = Service.Utility.camelCaseKeys(Service.Utility.parseQueryString(window.location.search.substr(1)));
31
+
32
+ return this.api.sipRequest.get('orders/detail/', {
33
+ params: {
34
+ orderid_list: JSON.stringify(orderidList),
35
+ affi_shopid: aShopId || sipShopid
36
+ }
37
+ }) as APIExternalPromise<SipOrderResponse>;
38
+ }
39
+
40
+ /**
41
+ * getSuggestedPrice 获取a-shop的sku推荐的价格
42
+ */
43
+ public getSuggestedPrice(params: object) {
44
+ return this.api.sipRequestV1.get('items/price/', { params }).then((response: any) => {
45
+ const res = response.error ? {} : response.data;
46
+ return (res as any);
47
+ });
48
+ }
49
+
50
+ /**
51
+ * setAskuPrice 设置a-shop的sku的价格
52
+ */
53
+ public setAskuPrice(params: object) {
54
+ return this.api.sipRequestV1.put('items/price/', params).then((response: any) => {
55
+ const res = response.error ? {} : response.data;
56
+ return (res as any);
57
+ });
58
+ }
59
+ }
@@ -0,0 +1,33 @@
1
+ export interface SipOrderResponse {
2
+ list: SipOrder[];
3
+ }
4
+ export interface SipOrder {
5
+ orderid: number;
6
+ transactionFee: number;
7
+ totalFee: number;
8
+ netSettlementAmount: number;
9
+ commissionFee: number;
10
+ settlementAmount: number;
11
+ orderItems: SipOrderItem[];
12
+ priceRatio: number;
13
+ }
14
+ export interface SipOrderItem extends OriginSipOrderItem {
15
+ subtotal: number;
16
+ tipText: string;
17
+ }
18
+ export interface OriginSipOrderItem {
19
+ mstItemid: number;
20
+ mstModelid: number;
21
+ affiItemid: number;
22
+ affiModelid: number;
23
+ itemSku: string;
24
+ itemName: string;
25
+ image: string;
26
+ promoPrice: number;
27
+ origPrice: number;
28
+ mstHpfs: number;
29
+ settlementPrice: number;
30
+ modelName: string;
31
+ modelSku: string;
32
+ quantity: number;
33
+ }
@@ -0,0 +1,8 @@
1
+ export {
2
+ default as UploadService
3
+ } from './service';
4
+
5
+ export {
6
+ UploadOptions,
7
+ UploadVideoData
8
+ } from './types';
@@ -0,0 +1,94 @@
1
+ import { Service, ServiceModule, APIPromise, APIExternalPromise, APIRequestConfig } from 'seller-base';
2
+ import { UploadOptions, UploadVideoData } from './types';
3
+
4
+ export default class UploadService extends ServiceModule {
5
+ public static $instance: UploadService;
6
+
7
+ constructor(service: Service) {
8
+ super(service);
9
+ this.name = 'upload';
10
+ UploadService.$instance = this;
11
+ }
12
+
13
+ /**
14
+ * 转化 Base64 为 Blob
15
+ */
16
+ public dataUrlToBlob(dataURI: string): Blob {
17
+ let byteString;
18
+ if (dataURI.split(',')[0].indexOf('base64') >= 0) {
19
+ byteString = window.atob(dataURI.split(',')[1]);
20
+ } else {
21
+ byteString = decodeURIComponent(dataURI.split(',')[1]);
22
+ }
23
+
24
+ /**
25
+ * 获取 mimeType
26
+ */
27
+ const mimeType = dataURI.split(',')[0].split(':')[1].split(';')[0];
28
+
29
+ const ia = new Uint8Array(byteString.length);
30
+ for (let i = 0; i < byteString.length; i++) {
31
+ ia[i] = byteString.charCodeAt(i);
32
+ }
33
+
34
+ return new Blob([ia], { type: mimeType });
35
+ }
36
+
37
+ /**
38
+ * 转化传入的对象为 FromData 数据
39
+ */
40
+ public createFormData(data: { [name: string]: string | Blob }) {
41
+ const formData = new FormData();
42
+ Object.keys(data).forEach(name => {
43
+ if (data.hasOwnProperty(name)) {
44
+ const value = data[name];
45
+ if (value) {
46
+ const isBase64 = typeof value === 'string' && value.indexOf('data:') === 0;
47
+ formData.append(name, isBase64 ? this.dataUrlToBlob(value as string) : value);
48
+ }
49
+ }
50
+ });
51
+ return formData;
52
+ }
53
+
54
+ /**
55
+ * 一个上传的通用方法 Post 数据,类型是 FormData
56
+ */
57
+ public postData(config: UploadOptions): APIPromise<any> {
58
+ const formData = this.createFormData(config.data);
59
+ return config.request.post(config.path, formData, Object.assign({}, config.config || {}, { params: config.params || {} })) as APIExternalPromise<any>;
60
+ }
61
+
62
+ /**
63
+ * 上传图片 V1
64
+ */
65
+ public uploadImageV1(file: string | Blob, params?: any, config?: APIRequestConfig): APIPromise<any> {
66
+ return this.postData({
67
+ path: '/images/',
68
+ data: { file },
69
+ request: this.api.v1Request,
70
+ params,
71
+ config
72
+ });
73
+ }
74
+
75
+ /**
76
+ * 上传图片 V3,一般应该使用这个接口
77
+ */
78
+ public uploadImage(file: string | Blob, params?: any, config?: APIRequestConfig): APIPromise<any> {
79
+ return this.postData({
80
+ path: '/general/upload_image/',
81
+ data: { file },
82
+ request: this.api.v3Request,
83
+ params,
84
+ config
85
+ });
86
+ }
87
+
88
+ /**
89
+ * 上传 Video
90
+ */
91
+ public uploadVideo(data: UploadVideoData): APIPromise<{}> {
92
+ return this.api.v3Request.post('/general/upload_video/', data) as APIExternalPromise<{}>;
93
+ }
94
+ }
@@ -0,0 +1,34 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { APIRequestConfig } from 'seller-base';
3
+
4
+ export interface UploadOptions {
5
+ /**
6
+ * 上传的路径
7
+ */
8
+ path: string;
9
+
10
+ /**
11
+ * 上传的数据,会全部加到 FormData
12
+ */
13
+ data: { [name: string]: string | Blob };
14
+
15
+ /**
16
+ * 上传链接的 Params
17
+ */
18
+ params?: any;
19
+
20
+ /**
21
+ * 上传的参数配置
22
+ */
23
+ config?: APIRequestConfig;
24
+
25
+ /**
26
+ * 上传的 Request
27
+ */
28
+ request: AxiosInstance;
29
+ }
30
+
31
+ export interface UploadVideoData {
32
+ ratio?: number;
33
+ videoUrl: string;
34
+ }