@qzsy/group-sdk 0.0.0-stage → 0.1.0

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # 变更记录
2
+
3
+ ## 0.1.0
4
+
5
+ 首个版本:群兴云集团 SaaS 对接支付网关的独立 SDK。
6
+
7
+ - `createGroupClient(options)` 创建集团客户端,支持构造时配置默认操作人(`operator`)
8
+ - `GroupSdkClient` 在 `@qzsy/unipay-sdk` 的 `GroupClient` 之上补充:
9
+ - `withOperator(operator)` 复用同一套凭据切换操作人
10
+ - 五个写接口(建主体 / 建应用 / 绑通道 / 进件 / 申请分账)自动携带 `X-Operator-*`
11
+ - 导出 `GROUP_LIMITS`、`GROUP_STATEMENT_SCOPES` 常量与 `describeGroupError` 错误格式化
12
+ - 完整转出 `@qzsy/unipay-sdk`:集团侧只装一个包,即可同时使用应用维度接口(下单 / 收银台 / 退款 / 付款)
13
+ - 覆盖接口:G-1~G-10 读接口、W-1~W-6 写接口
package/README.md CHANGED
@@ -1,3 +1,190 @@
1
- # Temporary Holding Version
1
+ # @qzsy/group-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 群兴云集团 SaaS 对接统一支付网关的官方 SDK:**集团凭据一次接入,管理多个营业执照主体、每执照一个小程序应用,并读取门店账单、发起佣金转账。**
4
+
5
+ 底层 HTTP、OAuth 令牌缓存、错误模型全部复用 [`@qzsy/unipay-sdk`](https://www.npmjs.com/package/@qzsy/unipay-sdk),所以集团侧只需要安装这一个包:应用维度(下单、收银台、退款、付款)的能力也一并可用。
6
+
7
+ - Node.js ≥ 18(使用原生 `fetch`,无运行时依赖)
8
+ - ESM / CJS / TypeScript 类型三者齐全
9
+ - 金额一律「分」为单位,时间一律 ISO 8601 字符串
10
+
11
+ ## 安装
12
+
13
+ ```bash
14
+ npm install @qzsy/group-sdk
15
+ # 或 pnpm add @qzsy/group-sdk / yarn add @qzsy/group-sdk
16
+ ```
17
+
18
+ ## 快速开始
19
+
20
+ ```ts
21
+ import { createGroupClient } from '@qzsy/group-sdk'
22
+
23
+ const group = createGroupClient({
24
+ baseUrl: 'https://pay.example.com', // 网关根地址,不要带 /api
25
+ clientId: process.env.GROUP_CLIENT_ID!, // 运营签发的集团凭据
26
+ clientSecret: process.env.GROUP_CLIENT_SECRET!,
27
+ // 集团总管理员代门店操作时上报,网关写入审计
28
+ operator: { id: 'manager_1', name: 'Group Admin' },
29
+ })
30
+
31
+ // G-1 概览:主体数 / 应用数 / 已完成进件的账户数
32
+ const overview = await group.getOverview()
33
+
34
+ // G-2 主体列表:含每个主体的支付账户与应用
35
+ const { items: entities } = await group.listEntities()
36
+ ```
37
+
38
+ ## 典型流程
39
+
40
+ ### 1. 开通一个门店(营业执照主体)
41
+
42
+ ```ts
43
+ const { entity } = await group.createEntity({
44
+ name: '杭州西湖店',
45
+ legal_name: '杭州西湖咖啡有限公司',
46
+ license_no: '91330100MA2H8XK21P',
47
+ license_address: '杭州市西湖区文三路 100 号',
48
+ contact_name: '沈亦然',
49
+ contact_phone: '13800001234',
50
+ })
51
+
52
+ // W-2 建 LIVE 应用并签发应用凭据(client_secret 只返回这一次)
53
+ const { application, credential } = await group.createApplication({
54
+ entity_id: entity.id,
55
+ name: '西湖店小程序',
56
+ wechat_app_id: 'wx1234567890abcdef',
57
+ })
58
+
59
+ // W-4 提交微信进件(platform_channel_id 省略时按 provider 自动选唯一的 LIVE 通道)
60
+ await group.createMerchantAccount({
61
+ provider: 'WECHAT',
62
+ merchant_entity_id: entity.id,
63
+ materials: { /* 见《业务对接》5.2 进件资料 */ },
64
+ })
65
+ ```
66
+
67
+ > 进件状态通过 G-2 / G-10 读取,也可订阅 `com.unifiedpay.onboarding.*` 回调。
68
+
69
+ ### 2. 门店账单(按主体 + 站点)
70
+
71
+ ```ts
72
+ // 门店账单由日结任务按 (主体, 站点) 生成,scope=STORE 必须带 store_code
73
+ const { items } = await group.listStatements({
74
+ scope: 'STORE',
75
+ entity_id: entity.id,
76
+ store_code: 'store-hz-01',
77
+ period_key: '2026-11-16',
78
+ })
79
+
80
+ const detail = await group.getStatement(items[0].id) // 含明细行
81
+ const csv = await group.downloadStatementCsv(items[0].id) // 直接落盘即可
82
+ ```
83
+
84
+ ### 3. 佣金转账(分销分佣)
85
+
86
+ ```ts
87
+ import { UnifiedPay } from '@qzsy/group-sdk'
88
+
89
+ // 付款主体 = 收这笔钱的应用所属主体,用它的应用凭据发起付款
90
+ const pay = new UnifiedPay({ baseUrl, clientId: APP_CLIENT_ID, clientSecret: APP_CLIENT_SECRET })
91
+
92
+ await pay.createPayout({
93
+ scene_key: 'commission',
94
+ merchant_payout_no: `DIST-${distributorId}-${periodKey}`,
95
+ amount: { value: 1280, currency: 'CNY' },
96
+ payee: { type: 'WECHAT_OPENID', id: distributorOpenId, app_id: appId },
97
+ remark: '11 月分销佣金',
98
+ site_code: 'store-hz-01',
99
+ source_order_nos: ['ORD-1001', 'ORD-1002'],
100
+ })
101
+
102
+ // G-9 查集团范围内所有付款
103
+ const { items: payouts, next_cursor } = await group.listGroupPayouts({
104
+ site_code: 'store-hz-01',
105
+ status: 'SUCCEEDED',
106
+ })
107
+ ```
108
+
109
+ ## 接口对照
110
+
111
+ | 方法 | 网关接口 | 说明 |
112
+ | --- | --- | --- |
113
+ | `getOverview()` | G-1 `/v1/group/overview` | 主体 / 应用 / 可用账户计数 |
114
+ | `listEntities(query?)` | G-2 `/v1/group/entities` | 支持 `updated_since`、`limit` |
115
+ | `listApplications(query?)` | G-3 `/v1/group/applications` | 可按 `entity_id` 过滤 |
116
+ | `listChannelAccounts(query?)` | G-4 `/v1/group/channel-accounts` | 平台镜像 / 直连 |
117
+ | `listSplitRules(accountId)` | G-5 `/v1/group/split-rules` | 分账接收方 |
118
+ | `listStatements(query?)` | G-6 `/v1/group/statements` | `scope=STORE` 需 `store_code` |
119
+ | `getStatement(id)` | G-6 `/v1/group/statements/:id` | 含明细行 |
120
+ | `downloadStatementCsv(id)` | G-6 `…/download` | 返回 CSV 文本 |
121
+ | `listPaymentIntents(query?)` | G-7 `/v1/group/payment-intents` | 订单汇总 |
122
+ | `getSnapshot()` | G-8 `/v1/group/snapshot` | 五个维度一次取回 |
123
+ | `listGroupPayouts(query?)` | G-9 `/v1/group/payouts` | 游标翻页 |
124
+ | `getGroupPayout(id)` | G-10 `/v1/group/payouts/:id` | 单笔详情 |
125
+ | `createEntity(input)` | W-1 `/v1/group/entities` | 按 `license_no` 幂等 |
126
+ | `createApplication(input)` | W-2 `/v1/group/applications` | 首次返回一次性凭据 |
127
+ | `bindApplicationChannel(input)` | W-3 `/v1/group/application-channels` | 复用控制台校验 |
128
+ | `createMerchantAccount(input)` | W-4 `/v1/group/merchant-accounts` | 代门店进件 |
129
+ | `applyEscrowPermission(accountId)` | W-5 `/v1/group/escrow-applications` | 申请担保+分账 |
130
+ | `getEscrowApplication(id)` | W-6 `/v1/group/escrow-applications/:id` | 查审批进度 |
131
+
132
+ 应用维度接口(下单、收银台、退款、付款、对账)由 `UnifiedPay` 提供,与 `@qzsy/unipay-sdk` 完全一致。
133
+
134
+ ## 操作人(审计)
135
+
136
+ 写接口会带上 `X-Operator-Id / Name / Site` 三个请求头。两种用法:
137
+
138
+ ```ts
139
+ // 方式一:构造时设置默认操作人,后续所有写操作自动携带
140
+ const group = createGroupClient({ baseUrl, clientId, clientSecret, operator })
141
+
142
+ // 方式二:换一个身份(复用同一套凭据)
143
+ const asStoreManager = group.withOperator({ id: 'store_1_manager', name: '店长' })
144
+
145
+ // 单次覆盖
146
+ await group.createEntity(input, { operator: { id: 'manager_2', name: '运营' } })
147
+ ```
148
+
149
+ > 请求头只能放 ASCII,姓名请用拼音或英文。
150
+
151
+ ## 幂等
152
+
153
+ 所有写接口自动携带 `Idempotency-Key`(首次调用生成,重试同一客户端实例会复用)。业务侧更应依赖自然幂等键:
154
+
155
+ - W-1 建主体:`license_no` 相同 → 返回已有主体
156
+ - W-2 建应用:`(entity_id, slug, LIVE)` 相同 → 返回已有应用,`credential` 为 `null`
157
+ - W-5 申请分账:同账户已有 `PENDING` → 返回同一张申请单
158
+
159
+ ## 错误处理
160
+
161
+ ```ts
162
+ import { describeGroupError, isGatewayError } from '@qzsy/group-sdk'
163
+
164
+ try {
165
+ await group.createEntity(input)
166
+ } catch (error) {
167
+ if (isGatewayError(error)) {
168
+ console.error(error.status, error.problem?.code, describeGroupError(error))
169
+ }
170
+ throw error
171
+ }
172
+ ```
173
+
174
+ 常见错误:`GROUP_CONTEXT_REQUIRED`(用了应用凭据调集团接口)、`ENTITY_NOT_OWNED`(主体不属于本集团)、`STORE_CODE_REQUIRED`(`scope=STORE` 缺 `store_code`)、`ONBOARDING_NOT_FINISHED`(进件未完成不能申请分账)。
175
+
176
+ ## 类型
177
+
178
+ ```ts
179
+ import type {
180
+ GroupEntity,
181
+ GroupApplication,
182
+ GroupStatement,
183
+ GroupPayout,
184
+ GroupEscrowApplication,
185
+ } from '@qzsy/group-sdk'
186
+ ```
187
+
188
+ ## 许可
189
+
190
+ UNLICENSED(内部使用)。问题请提给支付网关仓库。
package/dist/index.cjs ADDED
@@ -0,0 +1,125 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __reExport = (target, mod, secondTarget) => {
9
+ var keys = mod && typeof mod === "object" || typeof mod === "function" ? __getOwnPropNames(mod) : [];
10
+ for (let key of keys)
11
+ if (!__hasOwnProp.call(target, key) && key !== "default")
12
+ __defProp(target, key, {
13
+ get: __accessProp.bind(mod, key),
14
+ enumerable: true
15
+ });
16
+ if (secondTarget) {
17
+ for (let key of keys)
18
+ if (!__hasOwnProp.call(secondTarget, key) && key !== "default")
19
+ __defProp(secondTarget, key, {
20
+ get: __accessProp.bind(mod, key),
21
+ enumerable: true
22
+ });
23
+ return secondTarget;
24
+ }
25
+ };
26
+ var __toCommonJS = (from) => {
27
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
28
+ if (entry)
29
+ return entry;
30
+ entry = __defProp({}, "__esModule", { value: true });
31
+ if (from && typeof from === "object" || typeof from === "function") {
32
+ for (var key of __getOwnPropNames(from))
33
+ if (!__hasOwnProp.call(entry, key))
34
+ __defProp(entry, key, {
35
+ get: __accessProp.bind(from, key),
36
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
37
+ });
38
+ }
39
+ __moduleCache.set(from, entry);
40
+ return entry;
41
+ };
42
+ var __moduleCache;
43
+ var __returnValue = (v) => v;
44
+ function __exportSetter(name, newValue) {
45
+ this[name] = __returnValue.bind(null, newValue);
46
+ }
47
+ var __export = (target, all) => {
48
+ for (var name in all)
49
+ __defProp(target, name, {
50
+ get: all[name],
51
+ enumerable: true,
52
+ configurable: true,
53
+ set: __exportSetter.bind(all, name)
54
+ });
55
+ };
56
+
57
+ // src/index.ts
58
+ var exports_src = {};
59
+ __export(exports_src, {
60
+ GROUP_LIMITS: () => GROUP_LIMITS,
61
+ GROUP_STATEMENT_SCOPES: () => GROUP_STATEMENT_SCOPES,
62
+ GroupClient: () => import_unipay_sdk.GroupClient,
63
+ GroupSdkClient: () => GroupSdkClient,
64
+ UnifiedPay: () => import_unipay_sdk.UnifiedPay,
65
+ createGroupClient: () => createGroupClient,
66
+ describeGroupError: () => describeGroupError
67
+ });
68
+ module.exports = __toCommonJS(exports_src);
69
+ var import_unipay_sdk = require("@qzsy/unipay-sdk");
70
+ __reExport(exports_src, require("@qzsy/unipay-sdk"), module.exports);
71
+ var GROUP_STATEMENT_SCOPES = ["ORG", "ENTITY", "STORE"];
72
+ var GROUP_LIMITS = {
73
+ list: 100,
74
+ page: 500,
75
+ snapshot: 200,
76
+ statementLines: 1000
77
+ };
78
+
79
+ class GroupSdkClient extends import_unipay_sdk.GroupClient {
80
+ sdkOptions;
81
+ constructor(options) {
82
+ const { operator: _operator, ...clientOptions } = options;
83
+ super(clientOptions);
84
+ this.sdkOptions = options;
85
+ }
86
+ get defaultOperator() {
87
+ return this.sdkOptions.operator;
88
+ }
89
+ withOperator(operator) {
90
+ return new GroupSdkClient({ ...this.sdkOptions, operator });
91
+ }
92
+ withDefaultOperator(options = {}) {
93
+ const operator = this.sdkOptions.operator;
94
+ if (!operator || options.operator)
95
+ return options;
96
+ return { ...options, operator };
97
+ }
98
+ async createEntity(input, options = {}) {
99
+ return super.createEntity(input, this.withDefaultOperator(options));
100
+ }
101
+ async createApplication(input, options = {}) {
102
+ return super.createApplication(input, this.withDefaultOperator(options));
103
+ }
104
+ async bindApplicationChannel(input, options = {}) {
105
+ return super.bindApplicationChannel(input, this.withDefaultOperator(options));
106
+ }
107
+ async createMerchantAccount(input, options = {}) {
108
+ return super.createMerchantAccount(input, this.withDefaultOperator(options));
109
+ }
110
+ async applyEscrowPermission(accountId, options = {}) {
111
+ return super.applyEscrowPermission(accountId, this.withDefaultOperator(options));
112
+ }
113
+ }
114
+ function createGroupClient(options) {
115
+ return new GroupSdkClient(options);
116
+ }
117
+ function describeGroupError(error) {
118
+ if (import_unipay_sdk.isGatewayError(error)) {
119
+ const problem = error.problem;
120
+ return problem?.detail || problem?.title || error.message || "网关返回了错误";
121
+ }
122
+ if (error instanceof Error)
123
+ return error.message;
124
+ return "未知错误";
125
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @qzsy/group-sdk
3
+ *
4
+ * 群兴云集团 SaaS 对接统一支付网关:集团凭据 → 多营业执照主体 → 每执照一个小程序应用
5
+ * → 门店账单与佣金付款。底层 HTTP、令牌缓存与类型复用 `@qzsy/unipay-sdk`。
6
+ *
7
+ * ```ts
8
+ * const group = createGroupClient({
9
+ * baseUrl: 'https://pay.example.com',
10
+ * clientId: process.env.GROUP_CLIENT_ID!,
11
+ * clientSecret: process.env.GROUP_CLIENT_SECRET!,
12
+ * operator: { id: 'manager_1', name: 'Group Admin' },
13
+ * })
14
+ *
15
+ * const overview = await group.getOverview() // G-1
16
+ * const { items } = await group.listEntities() // G-2
17
+ * ```
18
+ */
19
+ import { GroupClient, UnifiedPay, type BindGroupApplicationChannelInput, type CreateGroupApplicationInput, type CreateGroupEntityInput, type CreateGroupMerchantAccountInput, type GroupApplicationChannelResponse, type GroupApplicationResponse, type GroupClientOptions, type GroupEntityResponse, type GroupEscrowApplication, type GroupMerchantAccountResponse, type GroupMutationOptions, type GroupOperator } from '@qzsy/unipay-sdk';
20
+ /** 账单查询可用的 scope(G-6) */
21
+ export declare const GROUP_STATEMENT_SCOPES: readonly ['ORG', 'ENTITY', 'STORE'];
22
+ export type GroupStatementScope = (typeof GROUP_STATEMENT_SCOPES)[number];
23
+ /** 列表类接口的服务端上限:普通列表 100、单页 500、快照每维 200、账单明细 1000 */
24
+ export declare const GROUP_LIMITS: {
25
+ readonly list: 100;
26
+ readonly page: 500;
27
+ readonly snapshot: 200;
28
+ readonly statementLines: 1000;
29
+ };
30
+ /** 集团 SDK 的构造参数:在集团凭据之外,可带一个默认操作人 */
31
+ export interface GroupSdkOptions extends GroupClientOptions {
32
+ /**
33
+ * 默认操作人:集团总管理员代门店操作时上报,网关写入审计与审批单。
34
+ * 单个调用也可以用 `{ operator }` 覆盖。
35
+ */
36
+ operator?: GroupOperator;
37
+ }
38
+ /**
39
+ * 带默认操作人的集团客户端。
40
+ *
41
+ * 与 `GroupClient` 的唯一差别:写接口不传 `options.operator` 时自动带上构造时的操作人,
42
+ * 集团侧不用每个写操作都重复拼 `X-Operator-*`。
43
+ */
44
+ export declare class GroupSdkClient extends GroupClient {
45
+ /** 构造参数(保留一份,便于 `withOperator` 换身份复用连接配置) */
46
+ private readonly sdkOptions;
47
+ constructor(options: GroupSdkOptions);
48
+ /** 构造时配置的默认操作人 */
49
+ get defaultOperator(): GroupOperator | undefined;
50
+ /** 换一个默认操作人:复用同一套凭据,返回新客户端 */
51
+ withOperator(operator: GroupOperator): GroupSdkClient;
52
+ /** 写操作合并默认操作人(显式传入的优先) */
53
+ private withDefaultOperator;
54
+ createEntity(input: CreateGroupEntityInput, options?: GroupMutationOptions): Promise<GroupEntityResponse>;
55
+ createApplication(input: CreateGroupApplicationInput, options?: GroupMutationOptions): Promise<GroupApplicationResponse>;
56
+ bindApplicationChannel(input: BindGroupApplicationChannelInput, options?: GroupMutationOptions): Promise<GroupApplicationChannelResponse>;
57
+ createMerchantAccount(input: CreateGroupMerchantAccountInput, options?: GroupMutationOptions): Promise<GroupMerchantAccountResponse>;
58
+ applyEscrowPermission(accountId: string, options?: GroupMutationOptions): Promise<GroupEscrowApplication>;
59
+ }
60
+ /** 创建集团客户端(推荐入口) */
61
+ export declare function createGroupClient(options: GroupSdkOptions): GroupSdkClient;
62
+ /**
63
+ * 把任意错误整理成可展示的文案:优先用网关的 `problem.detail`,
64
+ * 否则回退 `message`,最后兜底。
65
+ */
66
+ export declare function describeGroupError(error: unknown): string;
67
+ export { GroupClient, UnifiedPay };
68
+ export * from '@qzsy/unipay-sdk';
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EACL,WAAW,EAEX,UAAU,EACV,KAAK,gCAAgC,EACrC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,+BAA+B,EAEpC,KAAK,+BAA+B,EACpC,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,oBAAoB,EACzB,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAA;AAEzB,yBAAyB;AACzB,eAAO,MAAM,sBAAsB,YAAI,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAA;AACzE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzE,qDAAqD;AACrD,eAAO,MAAM,YAAY;aACvB,IAAI,EAAE,GAAG;aACT,IAAI,EAAE,GAAG;aACT,QAAQ,EAAE,GAAG;aACb,cAAc,EAAE,IAAI;CACZ,CAAA;AAEV,qCAAqC;AACrC,MAAM,WAAW,eAAgB,SAAQ,kBAAkB;IACzD;;;OAGG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAA;CACzB;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,6CAA6C;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAE5C,YAAY,OAAO,EAAE,eAAe,EAInC;IAED,kBAAkB;IAClB,IAAI,eAAe,IAAI,aAAa,GAAG,SAAS,CAE/C;IAED,8BAA8B;IAC9B,YAAY,CAAC,QAAQ,EAAE,aAAa,GAAG,cAAc,CAEpD;IAED,0BAA0B;IAC1B,OAAO,CAAC,mBAAmB;IAMZ,YAAY,CACzB,KAAK,EAAE,sBAAsB,EAC7B,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAE9B;IAEc,iBAAiB,CAC9B,KAAK,EAAE,2BAA2B,EAClC,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,wBAAwB,CAAC,CAEnC;IAEc,sBAAsB,CACnC,KAAK,EAAE,gCAAgC,EACvC,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,+BAA+B,CAAC,CAE1C;IAEc,qBAAqB,CAClC,KAAK,EAAE,+BAA+B,EACtC,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,4BAA4B,CAAC,CAEvC;IAEc,qBAAqB,CAClC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,sBAAsB,CAAC,CAEjC;CACF;AAED,oBAAoB;AACpB,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAE1E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOzD;AAOD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAA;AAClC,cAAc,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ // src/index.ts
2
+ import {
3
+ GroupClient,
4
+ isGatewayError,
5
+ UnifiedPay
6
+ } from "@qzsy/unipay-sdk";
7
+
8
+ export * from "@qzsy/unipay-sdk";
9
+ var GROUP_STATEMENT_SCOPES = ["ORG", "ENTITY", "STORE"];
10
+ var GROUP_LIMITS = {
11
+ list: 100,
12
+ page: 500,
13
+ snapshot: 200,
14
+ statementLines: 1000
15
+ };
16
+
17
+ class GroupSdkClient extends GroupClient {
18
+ sdkOptions;
19
+ constructor(options) {
20
+ const { operator: _operator, ...clientOptions } = options;
21
+ super(clientOptions);
22
+ this.sdkOptions = options;
23
+ }
24
+ get defaultOperator() {
25
+ return this.sdkOptions.operator;
26
+ }
27
+ withOperator(operator) {
28
+ return new GroupSdkClient({ ...this.sdkOptions, operator });
29
+ }
30
+ withDefaultOperator(options = {}) {
31
+ const operator = this.sdkOptions.operator;
32
+ if (!operator || options.operator)
33
+ return options;
34
+ return { ...options, operator };
35
+ }
36
+ async createEntity(input, options = {}) {
37
+ return super.createEntity(input, this.withDefaultOperator(options));
38
+ }
39
+ async createApplication(input, options = {}) {
40
+ return super.createApplication(input, this.withDefaultOperator(options));
41
+ }
42
+ async bindApplicationChannel(input, options = {}) {
43
+ return super.bindApplicationChannel(input, this.withDefaultOperator(options));
44
+ }
45
+ async createMerchantAccount(input, options = {}) {
46
+ return super.createMerchantAccount(input, this.withDefaultOperator(options));
47
+ }
48
+ async applyEscrowPermission(accountId, options = {}) {
49
+ return super.applyEscrowPermission(accountId, this.withDefaultOperator(options));
50
+ }
51
+ }
52
+ function createGroupClient(options) {
53
+ return new GroupSdkClient(options);
54
+ }
55
+ function describeGroupError(error) {
56
+ if (isGatewayError(error)) {
57
+ const problem = error.problem;
58
+ return problem?.detail || problem?.title || error.message || "网关返回了错误";
59
+ }
60
+ if (error instanceof Error)
61
+ return error.message;
62
+ return "未知错误";
63
+ }
64
+ export {
65
+ GROUP_LIMITS,
66
+ GROUP_STATEMENT_SCOPES,
67
+ GroupClient,
68
+ GroupSdkClient,
69
+ UnifiedPay,
70
+ createGroupClient,
71
+ describeGroupError
72
+ };
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@qzsy/group-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "群兴云集团 SaaS 对接统一支付网关的 TypeScript SDK:集团凭据、多主体/多应用管理、门店账单与佣金付款",
6
+ "license": "MIT",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "sideEffects": false,
24
+ "scripts": {
25
+ "build": "bun run build:js && bun run build:types",
26
+ "build:js": "bun build src/index.ts --outfile dist/index.js --target node --format esm --external @qzsy/unipay-sdk && bun build src/index.ts --outfile dist/index.cjs --target node --format cjs --external @qzsy/unipay-sdk",
27
+ "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
28
+ "prepublishOnly": "bun run build && bun test",
29
+ "test": "bun test",
30
+ "type-check": "tsc --noEmit"
31
+ },
32
+ "dependencies": {
33
+ "@qzsy/unipay-sdk": "^0.3.0"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "registry": "https://registry.npmjs.org"
38
+ },
39
+ "keywords": [
40
+ "payment",
41
+ "gateway",
42
+ "group",
43
+ "saas",
44
+ "unifiedpay",
45
+ "qzsy"
46
+ ],
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://codeup.aliyun.com/qzsy/XKGY/payment-gateway.git",
50
+ "directory": "packages/group-sdk"
51
+ },
52
+ "engines": {
53
+ "node": ">=18"
54
+ },
55
+ "devDependencies": {
56
+ "@repo/typescript-config": "workspace:*",
57
+ "@types/bun": "^1.3.14",
58
+ "typescript": "7.0.2"
59
+ }
60
+ }