@youzan-cloud/zan-saas-cli 0.0.0-stage → 0.1.0-beta.4
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/DEPENDENCIES.json +50 -0
- package/INSTALL.md +79 -0
- package/LICENSE +21 -0
- package/NOTICE +1 -0
- package/README.md +151 -2
- package/THIRD_PARTY_NOTICES.txt +162 -0
- package/bin/zan-saas-cli.js +28 -0
- package/internal/registry/index.js +123 -0
- package/internal/registry/manifest.json +424 -0
- package/npm-shrinkwrap.json +86 -0
- package/package.json +33 -4
- package/skills/README.md +30 -0
- package/skills/zan-saas/SKILL.md +54 -0
- package/skills/zan-saas/references/host-entry.md +25 -0
- package/skills/zan-saas-access/SKILL.md +37 -0
- package/skills/zan-saas-access/references/role-list.md +11 -0
- package/skills/zan-saas-access/references/staff-perms-get.md +11 -0
- package/skills/zan-saas-aftersale/SKILL.md +31 -0
- package/skills/zan-saas-aftersale/references/case-list.md +13 -0
- package/skills/zan-saas-aftersale/references/case-scan.md +31 -0
- package/skills/zan-saas-benefit/SKILL.md +46 -0
- package/skills/zan-saas-benefit/references/card-get.md +7 -0
- package/skills/zan-saas-benefit/references/card-grant-list.md +11 -0
- package/skills/zan-saas-benefit/references/card-list.md +7 -0
- package/skills/zan-saas-benefit/references/customer-card-get.md +7 -0
- package/skills/zan-saas-benefit/references/customer-card-list.md +7 -0
- package/skills/zan-saas-coupon/SKILL.md +41 -0
- package/skills/zan-saas-coupon/references/activity-get.md +11 -0
- package/skills/zan-saas-coupon/references/activity-list.md +15 -0
- package/skills/zan-saas-coupon/references/voucher-get.md +13 -0
- package/skills/zan-saas-coupon/references/voucher-list.md +25 -0
- package/skills/zan-saas-customer/SKILL.md +73 -0
- package/skills/zan-saas-customer/references/customer-scan.md +11 -0
- package/skills/zan-saas-customer/references/segment-list.md +22 -0
- package/skills/zan-saas-fulfillment/SKILL.md +36 -0
- package/skills/zan-saas-fulfillment/references/delivery-get.md +11 -0
- package/skills/zan-saas-fulfillment/references/shipment-list.md +11 -0
- package/skills/zan-saas-fulfillment/references/waybill-get.md +9 -0
- package/skills/zan-saas-interaction/SKILL.md +37 -0
- package/skills/zan-saas-interaction/references/lottery-get.md +11 -0
- package/skills/zan-saas-interaction/references/lottery-list.md +19 -0
- package/skills/zan-saas-item/SKILL.md +61 -0
- package/skills/zan-saas-item/references/attribute-list.md +11 -0
- package/skills/zan-saas-item/references/brand-list.md +7 -0
- package/skills/zan-saas-item/references/classification-get.md +7 -0
- package/skills/zan-saas-item/references/classification-list.md +7 -0
- package/skills/zan-saas-item/references/group-list.md +9 -0
- package/skills/zan-saas-item/references/item-content.md +9 -0
- package/skills/zan-saas-item/references/item-get.md +9 -0
- package/skills/zan-saas-item/references/item-search.md +23 -0
- package/skills/zan-saas-item/references/product-identity.md +11 -0
- package/skills/zan-saas-member/SKILL.md +41 -0
- package/skills/zan-saas-member/references/customer-level-get.md +7 -0
- package/skills/zan-saas-member/references/growth-log-list.md +17 -0
- package/skills/zan-saas-member/references/membership-get.md +7 -0
- package/skills/zan-saas-order/SKILL.md +56 -0
- package/skills/zan-saas-order/references/order-get.md +26 -0
- package/skills/zan-saas-order/references/order-list.md +25 -0
- package/skills/zan-saas-order/references/order-scan.md +35 -0
- package/skills/zan-saas-org/SKILL.md +37 -0
- package/skills/zan-saas-org/references/staff-get.md +15 -0
- package/skills/zan-saas-org/references/staff-role-get.md +11 -0
- package/skills/zan-saas-org/references/unit-get.md +11 -0
- package/skills/zan-saas-org/references/unit-list.md +15 -0
- package/skills/zan-saas-points/SKILL.md +42 -0
- package/skills/zan-saas-points/references/account-get.md +7 -0
- package/skills/zan-saas-points/references/log-list.md +17 -0
- package/skills/zan-saas-points/references/rule-list.md +2 -0
- package/skills/zan-saas-privacy/SKILL.md +30 -0
- package/skills/zan-saas-privacy/references/field-decrypt.md +19 -0
- package/skills/zan-saas-shared/SKILL.md +94 -0
- package/skills/zan-saas-shared/references/authentication.md +52 -0
- package/skills/zan-saas-shared/references/value-processing.md +27 -0
- package/skills/zan-saas-stock/SKILL.md +28 -0
- package/skills/zan-saas-stock/references/log-list.md +11 -0
- package/skills/zan-saas-valuecard/SKILL.md +37 -0
- package/skills/zan-saas-valuecard/references/card-get.md +13 -0
- package/skills/zan-saas-valuecard/references/card-list.md +11 -0
- package/src/auth/browser.js +28 -0
- package/src/auth/callback-server.js +99 -0
- package/src/auth/config.js +53 -0
- package/src/auth/credential-store.js +109 -0
- package/src/auth/oauth-client.js +105 -0
- package/src/auth/pkce.js +28 -0
- package/src/auth/session.js +178 -0
- package/src/auth/tool.js +25 -0
- package/src/cli/command-paths.js +126 -0
- package/src/cli/context-help.js +102 -0
- package/src/cli/diagnostic-command.js +57 -0
- package/src/cli/domain-catalog.js +42 -0
- package/src/cli/help-text.js +32 -0
- package/src/cli/native-loader.js +120 -0
- package/src/cli/native-path.js +22 -0
- package/src/cli/parser-policy.js +141 -0
- package/src/cli/program.js +134 -0
- package/src/cli/skill-catalog.js +241 -0
- package/src/commands/native/access/commands.index.json +24 -0
- package/src/commands/native/access/domain.json +3 -0
- package/src/commands/native/access/role/list/command.js +141 -0
- package/src/commands/native/access/role/list/schema.json +393 -0
- package/src/commands/native/access/staff-perms/get/command.js +119 -0
- package/src/commands/native/access/staff-perms/get/schema.json +703 -0
- package/src/commands/native/aftersale/case/get/command.js +104 -0
- package/src/commands/native/aftersale/case/get/exact-json.js +52 -0
- package/src/commands/native/aftersale/case/get/money.js +28 -0
- package/src/commands/native/aftersale/case/get/projection.js +120 -0
- package/src/commands/native/aftersale/case/get/query.js +72 -0
- package/src/commands/native/aftersale/case/get/schema.json +134 -0
- package/src/commands/native/aftersale/case/list/command.js +135 -0
- package/src/commands/native/aftersale/case/list/schema.json +1095 -0
- package/src/commands/native/aftersale/case/scan/command.js +110 -0
- package/src/commands/native/aftersale/case/scan/query.js +62 -0
- package/src/commands/native/aftersale/case/scan/scan.js +78 -0
- package/src/commands/native/aftersale/case/scan/schema.json +964 -0
- package/src/commands/native/aftersale/case/scan/search.js +108 -0
- package/src/commands/native/aftersale/commands.index.json +42 -0
- package/src/commands/native/aftersale/domain.json +3 -0
- package/src/commands/native/aftersale/refund/list/command.js +97 -0
- package/src/commands/native/aftersale/refund/list/money.js +25 -0
- package/src/commands/native/aftersale/refund/list/projection.js +50 -0
- package/src/commands/native/aftersale/refund/list/query.js +73 -0
- package/src/commands/native/aftersale/refund/list/schema.json +130 -0
- package/src/commands/native/aftersale/shared/query.js +58 -0
- package/src/commands/native/aftersale/shared/search.js +128 -0
- package/src/commands/native/benefit/card-definition/get/command.js +110 -0
- package/src/commands/native/benefit/card-definition/get/schema.json +545 -0
- package/src/commands/native/benefit/card-definition/list/command.js +106 -0
- package/src/commands/native/benefit/card-definition/list/schema.json +690 -0
- package/src/commands/native/benefit/card-grant/list/command.js +135 -0
- package/src/commands/native/benefit/card-grant/list/schema.json +758 -0
- package/src/commands/native/benefit/commands.index.json +51 -0
- package/src/commands/native/benefit/customer-card/get/command.js +110 -0
- package/src/commands/native/benefit/customer-card/get/schema.json +340 -0
- package/src/commands/native/benefit/customer-card/list/command.js +103 -0
- package/src/commands/native/benefit/customer-card/list/schema.json +731 -0
- package/src/commands/native/benefit/domain.json +3 -0
- package/src/commands/native/coupon/activity/get/command.js +183 -0
- package/src/commands/native/coupon/activity/get/schema.json +624 -0
- package/src/commands/native/coupon/activity/list/command.js +169 -0
- package/src/commands/native/coupon/activity/list/schema.json +845 -0
- package/src/commands/native/coupon/commands.index.json +42 -0
- package/src/commands/native/coupon/domain.json +3 -0
- package/src/commands/native/coupon/shared/query.js +15 -0
- package/src/commands/native/coupon/voucher/get/command.js +113 -0
- package/src/commands/native/coupon/voucher/get/schema.json +147 -0
- package/src/commands/native/coupon/voucher/list/command.js +155 -0
- package/src/commands/native/coupon/voucher/list/schema.json +772 -0
- package/src/commands/native/customer/commands.index.json +96 -0
- package/src/commands/native/customer/customer/get/adapter.js +82 -0
- package/src/commands/native/customer/customer/get/command.js +106 -0
- package/src/commands/native/customer/customer/get/schema.json +958 -0
- package/src/commands/native/customer/customer/list/command.js +78 -0
- package/src/commands/native/customer/customer/list/input.js +145 -0
- package/src/commands/native/customer/customer/list/query.js +103 -0
- package/src/commands/native/customer/customer/list/schema.json +969 -0
- package/src/commands/native/customer/customer/scan/command.js +80 -0
- package/src/commands/native/customer/customer/scan/scan.js +92 -0
- package/src/commands/native/customer/customer/scan/schema.json +211 -0
- package/src/commands/native/customer/customer-tag/get/command.js +166 -0
- package/src/commands/native/customer/customer-tag/get/schema.json +317 -0
- package/src/commands/native/customer/customer-tag/list/command.js +143 -0
- package/src/commands/native/customer/customer-tag/list/schema.json +259 -0
- package/src/commands/native/customer/domain.json +3 -0
- package/src/commands/native/customer/segment/list/command.js +96 -0
- package/src/commands/native/customer/segment/list/query.js +98 -0
- package/src/commands/native/customer/segment/list/schema.json +135 -0
- package/src/commands/native/customer/segment-customer/list/command.js +171 -0
- package/src/commands/native/customer/segment-customer/list/schema.json +123 -0
- package/src/commands/native/customer/shared/search-input.js +179 -0
- package/src/commands/native/customer/shared/search-page.js +54 -0
- package/src/commands/native/customer/tag/get/command.js +73 -0
- package/src/commands/native/customer/tag/get/schema.json +339 -0
- package/src/commands/native/customer/tagcategory/get/command.js +80 -0
- package/src/commands/native/customer/tagcategory/get/query.js +98 -0
- package/src/commands/native/customer/tagcategory/get/schema.json +339 -0
- package/src/commands/native/customer/tagcategory/list/command.js +127 -0
- package/src/commands/native/customer/tagcategory/list/schema.json +394 -0
- package/src/commands/native/fulfillment/commands.index.json +33 -0
- package/src/commands/native/fulfillment/delivery/get/command.js +107 -0
- package/src/commands/native/fulfillment/delivery/get/projection.js +142 -0
- package/src/commands/native/fulfillment/delivery/get/schema.json +173 -0
- package/src/commands/native/fulfillment/domain.json +3 -0
- package/src/commands/native/fulfillment/shipment/list/command.js +83 -0
- package/src/commands/native/fulfillment/shipment/list/projection.js +130 -0
- package/src/commands/native/fulfillment/shipment/list/schema.json +752 -0
- package/src/commands/native/fulfillment/waybill/get/command.js +193 -0
- package/src/commands/native/fulfillment/waybill/get/response.js +68 -0
- package/src/commands/native/fulfillment/waybill/get/schema.json +190 -0
- package/src/commands/native/interaction/commands.index.json +24 -0
- package/src/commands/native/interaction/domain.json +3 -0
- package/src/commands/native/interaction/lottery/get/command.js +61 -0
- package/src/commands/native/interaction/lottery/get/query.js +152 -0
- package/src/commands/native/interaction/lottery/get/schema.json +1004 -0
- package/src/commands/native/interaction/lottery/list/command.js +176 -0
- package/src/commands/native/interaction/lottery/list/schema.json +898 -0
- package/src/commands/native/item/attribute/list/command.js +122 -0
- package/src/commands/native/item/attribute/list/schema.json +727 -0
- package/src/commands/native/item/brand/list/command.js +114 -0
- package/src/commands/native/item/brand/list/schema.json +725 -0
- package/src/commands/native/item/classification/get/command.js +87 -0
- package/src/commands/native/item/classification/get/schema.json +596 -0
- package/src/commands/native/item/classification/list/command.js +105 -0
- package/src/commands/native/item/classification/list/schema.json +676 -0
- package/src/commands/native/item/commands.index.json +87 -0
- package/src/commands/native/item/domain.json +1 -0
- package/src/commands/native/item/group/list/command.js +122 -0
- package/src/commands/native/item/group/list/schema.json +809 -0
- package/src/commands/native/item/item/get/command.js +122 -0
- package/src/commands/native/item/item/get/schema.json +3799 -0
- package/src/commands/native/item/item/list/command.js +7 -0
- package/src/commands/native/item/item/list/schema.json +1118 -0
- package/src/commands/native/item/item/scan/command.js +7 -0
- package/src/commands/native/item/item/scan/schema.json +1046 -0
- package/src/commands/native/item/item-content/get/command.js +54 -0
- package/src/commands/native/item/item-content/get/schema.json +677 -0
- package/src/commands/native/item/shared/api.js +31 -0
- package/src/commands/native/item/shared/content.js +20 -0
- package/src/commands/native/item/shared/diagnostics.js +61 -0
- package/src/commands/native/item/shared/h5.js +63 -0
- package/src/commands/native/item/shared/identity.js +62 -0
- package/src/commands/native/item/shared/normalize.js +49 -0
- package/src/commands/native/item/shared/scope.js +22 -0
- package/src/commands/native/item/shared/search-command.js +61 -0
- package/src/commands/native/item/shared/search-options.js +150 -0
- package/src/commands/native/item/shared/search.js +158 -0
- package/src/commands/native/member/commands.index.json +60 -0
- package/src/commands/native/member/customer-level/get/command.js +122 -0
- package/src/commands/native/member/customer-level/get/schema.json +300 -0
- package/src/commands/native/member/domain.json +3 -0
- package/src/commands/native/member/growth/get/command.js +64 -0
- package/src/commands/native/member/growth/get/schema.json +283 -0
- package/src/commands/native/member/growth-log/list/command.js +203 -0
- package/src/commands/native/member/growth-log/list/schema.json +695 -0
- package/src/commands/native/member/level/get/command.js +70 -0
- package/src/commands/native/member/level/get/query.js +125 -0
- package/src/commands/native/member/level/get/schema.json +339 -0
- package/src/commands/native/member/level/list/command.js +50 -0
- package/src/commands/native/member/level/list/query.js +109 -0
- package/src/commands/native/member/level/list/schema.json +104 -0
- package/src/commands/native/member/membership/get/command.js +78 -0
- package/src/commands/native/member/membership/get/schema.json +283 -0
- package/src/commands/native/order/commands.index.json +33 -0
- package/src/commands/native/order/domain.json +3 -0
- package/src/commands/native/order/order/get/command.js +155 -0
- package/src/commands/native/order/order/get/schema.json +1167 -0
- package/src/commands/native/order/order/list/command.js +230 -0
- package/src/commands/native/order/order/list/schema.json +1363 -0
- package/src/commands/native/order/order/scan/command.js +148 -0
- package/src/commands/native/order/order/scan/scan.js +89 -0
- package/src/commands/native/order/order/scan/schema.json +1445 -0
- package/src/commands/native/order/shared/projection.js +183 -0
- package/src/commands/native/order/shared/query.js +84 -0
- package/src/commands/native/order/shared/search.js +112 -0
- package/src/commands/native/org/commands.index.json +42 -0
- package/src/commands/native/org/domain.json +3 -0
- package/src/commands/native/org/shared/single-staff.js +115 -0
- package/src/commands/native/org/staff/get/command.js +148 -0
- package/src/commands/native/org/staff/get/schema.json +114 -0
- package/src/commands/native/org/staff-role/get/command.js +45 -0
- package/src/commands/native/org/staff-role/get/schema.json +93 -0
- package/src/commands/native/org/unit/get/command.js +131 -0
- package/src/commands/native/org/unit/get/schema.json +478 -0
- package/src/commands/native/org/unit/list/command.js +187 -0
- package/src/commands/native/org/unit/list/schema.json +828 -0
- package/src/commands/native/points/account/get/command.js +65 -0
- package/src/commands/native/points/account/get/schema.json +303 -0
- package/src/commands/native/points/commands.index.json +33 -0
- package/src/commands/native/points/domain.json +3 -0
- package/src/commands/native/points/log/list/command.js +141 -0
- package/src/commands/native/points/log/list/schema.json +761 -0
- package/src/commands/native/points/rule/list/command.js +82 -0
- package/src/commands/native/points/rule/list/schema.json +294 -0
- package/src/commands/native/privacy/commands.index.json +15 -0
- package/src/commands/native/privacy/domain.json +3 -0
- package/src/commands/native/privacy/field/decrypt/command.js +185 -0
- package/src/commands/native/privacy/field/decrypt/schema.json +656 -0
- package/src/commands/native/privacy/shared/order-source.js +33 -0
- package/src/commands/native/stock/commands.index.json +15 -0
- package/src/commands/native/stock/domain.json +3 -0
- package/src/commands/native/stock/log/list/command.js +207 -0
- package/src/commands/native/stock/log/list/schema.json +922 -0
- package/src/commands/native/valuecard/card/get/command.js +107 -0
- package/src/commands/native/valuecard/card/get/schema.json +683 -0
- package/src/commands/native/valuecard/card/list/command.js +136 -0
- package/src/commands/native/valuecard/card/list/pagination.js +23 -0
- package/src/commands/native/valuecard/card/list/schema.json +780 -0
- package/src/commands/native/valuecard/commands.index.json +24 -0
- package/src/commands/native/valuecard/domain.json +3 -0
- package/src/commands/native/valuecard/shared/projection.js +57 -0
- package/src/commands/system/api.js +47 -0
- package/src/commands/system/auth.js +118 -0
- package/src/commands/system/contracts.js +373 -0
- package/src/commands/system/doctor.js +24 -0
- package/src/commands/system/install.js +41 -0
- package/src/commands/system/printer.js +16 -0
- package/src/commands/system/schema.js +162 -0
- package/src/commands/system/shop-guidance.js +9 -0
- package/src/commands/system/shop.js +237 -0
- package/src/commands/system/skills.js +49 -0
- package/src/execution/beijing-date-time.js +29 -0
- package/src/execution/beijing-time.js +21 -0
- package/src/execution/bounded-input.js +42 -0
- package/src/execution/command-io.js +137 -0
- package/src/execution/command-policy.js +41 -0
- package/src/execution/command-schema.js +131 -0
- package/src/execution/datetime.js +83 -0
- package/src/execution/error-details.js +399 -0
- package/src/execution/error-model.js +82 -0
- package/src/execution/exact-json.js +80 -0
- package/src/execution/list-total.js +10 -0
- package/src/execution/money.js +59 -0
- package/src/execution/parser-error.js +66 -0
- package/src/execution/privacy.js +197 -0
- package/src/execution/public-schema.js +52 -0
- package/src/execution/query-api.js +101 -0
- package/src/execution/range.js +84 -0
- package/src/execution/request-state.js +55 -0
- package/src/execution/schema-completeness.js +116 -0
- package/src/execution/shop-query.js +54 -0
- package/src/execution/target-shop-default.js +23 -0
- package/src/execution/target-shop.js +49 -0
- package/src/identity/context-store.js +54 -0
- package/src/identity/context.js +38 -0
- package/src/installation/install.js +158 -0
- package/src/installation/npm-error.js +93 -0
- package/src/installation/skill.js +113 -0
- package/src/transport/account-api.js +152 -0
- package/src/transport/api.js +199 -0
- package/src/transport/shop-app.js +63 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Option } = require('commander');
|
|
4
|
+
const { DiagnosticCommand } = require('../../../../../cli/diagnostic-command');
|
|
5
|
+
const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
|
|
6
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
7
|
+
const { buildInput, requestBody } = require('./input');
|
|
8
|
+
const { reject, createQuery, adapt, serialize, bindingPath } = require('./query');
|
|
9
|
+
const schema = require('./schema.json');
|
|
10
|
+
|
|
11
|
+
function preview(input) {
|
|
12
|
+
const body = requestBody(input);
|
|
13
|
+
for (const name of ['keyword', 'mobile']) if (Object.hasOwn(body, name)) body[name] = '***';
|
|
14
|
+
const plan = { requests: [{ method: 'POST', path: bindingPath, body: {} },
|
|
15
|
+
{ method: 'POST', path: schema.api.path, body }] };
|
|
16
|
+
validateCommandValue(schema, 'preview', plan);
|
|
17
|
+
return plan;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function createCommand({ context } = {}) {
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
const optionPaths = Object.fromEntries(Object.keys(schema.input.properties.filters.properties)
|
|
23
|
+
.map(name => [`/filters/${name}`, name]));
|
|
24
|
+
const command = new DiagnosticCommand('list', { path: 'customer.customer.list', schema, optionPaths })
|
|
25
|
+
.description('按条件查询一页客户摘要,恢复等级与持卡筛选,不返回全店全集')
|
|
26
|
+
.allowExcessArguments(false)
|
|
27
|
+
.option('--kdt-id <id>', '目标店铺正安全整数 ID;省略时使用当前上下文店铺')
|
|
28
|
+
.option('--keyword <text>', '模糊搜索姓名、手机号、昵称,1..200 字符,与 mobile 互斥')
|
|
29
|
+
.option('--mobile <number>', '精确单手机号,可选加号及 5..20 位数字,保留前导零')
|
|
30
|
+
.option('--is-member <boolean>', 'true 会员,false 非会员,省略不筛选')
|
|
31
|
+
.option('--tag-ids <ids>', '必须全部满足的标签 ID,CSV 或 JSON 字符串数组,1..50 项')
|
|
32
|
+
.option('--created <range>', '成为客户时间,北京时间起点..终点,可单边,必须含 ..')
|
|
33
|
+
.option('--member-created <range>', '成为会员时间,起点..终点,可单边,不推断当前会员身份')
|
|
34
|
+
.option('--last-trade <range>', '最后购买时间,起点..终点,可单边,不表示窗口内任意购买')
|
|
35
|
+
.option('--trade-count <range>', '历史购次 LOW..HIGH,可单边或裸值,非负 32 位整数')
|
|
36
|
+
.option('--trade-amount <range>', '历史消费金额,元文本 LOW..HIGH,可单边或裸值,最多两位小数')
|
|
37
|
+
.option('--points <range>', '积分 LOW..HIGH,可单边或裸值,非负安全整数')
|
|
38
|
+
.option('--stored-balance <range>', '储值余额,元文本 LOW..HIGH,可单边或裸值,不代表逐卡可支付余额')
|
|
39
|
+
.option('--level-ids <ids>', '等级定义数值 ID,CSV 或 JSON 字符串数组,非 alias 或等级值')
|
|
40
|
+
.option('--has-level <boolean>', 'true 有等级,false 无等级;false 与 level-ids 冲突')
|
|
41
|
+
.option('--benefit-card-ids <ids>', '权益卡定义数值 ID,CSV 或 JSON 字符串数组,非 cardAlias 或 cardNo')
|
|
42
|
+
.option('--has-benefit-card <boolean>', 'true 有卡,false 无卡;false 与 benefit-card-ids 冲突,不证明卡有效')
|
|
43
|
+
.option('--page-no <number>', '页码 1..500,页码乘页容量不得超过 10000', '1')
|
|
44
|
+
.option('--page-size <number>', '本页容量 1..50,不表示总量', '20')
|
|
45
|
+
.addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进').choices(['json', 'pretty']).default('json'))
|
|
46
|
+
.option('--dry-run', '纯本地脱敏预览,零认证和业务请求')
|
|
47
|
+
.addHelpText('after', `
|
|
48
|
+
固定按服务端创建时间降序,不开放排序、来源渠道、批量手机号或任意过滤 JSON。
|
|
49
|
+
时间格式 YYYY-MM-DD HH:mm:ss[.SSS],固定 UTC+08:00,只允许零毫秒。
|
|
50
|
+
数值裸值传相同双边;省略边界不补零或当前时间,范围上下限不可倒置。
|
|
51
|
+
等级和卡使用定义 ID,集合关系沿用服务端语义,不自动补 has=true。
|
|
52
|
+
执行需要四字段上下文,同店核验后仅查询一页,最多两次请求,不重试、切店或换身份。
|
|
53
|
+
只输出有限客户摘要和四字段分页;未取得总数时省略 total,hasMore 为 null,短页或空页不证明取完。
|
|
54
|
+
响应累计上限 10MiB,输出含换行上限 5MiB;失败 stdout 为空,stderr 为脱敏错误。
|
|
55
|
+
手机号和姓名不能代替 yzOpenId;本地预览和店铺绑定不证明员工权限。
|
|
56
|
+
契约:zan-saas schema customer.customer.list
|
|
57
|
+
示例:zan-saas customer customer list --kdt-id 63077 --points '100..500' --dry-run
|
|
58
|
+
`)
|
|
59
|
+
.action(async options => {
|
|
60
|
+
const input = buildInput(options, context);
|
|
61
|
+
if (options.dryRun) {
|
|
62
|
+
console.log(JSON.stringify(preview(input), null, options.format === 'pretty' ? 2 : 0));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const read = await createQuery(input);
|
|
66
|
+
const { data, facts } = await read(requestBody(input));
|
|
67
|
+
console.log(serialize(adapt(data, input, facts), options.format, { kdtId: input.kdtId }));
|
|
68
|
+
});
|
|
69
|
+
for (const option of command.options) {
|
|
70
|
+
command.on(`option:${option.name()}`, () => {
|
|
71
|
+
if (seen.has(option.name())) throw command.issue('constraint', option);
|
|
72
|
+
seen.add(option.name());
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return command;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand), preview, buildInput };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { resolveTargetShop } = require('../../../../../execution/target-shop');
|
|
4
|
+
const { apiSeconds } = require('../../../../../execution/datetime');
|
|
5
|
+
const { parseIntegerRange, parseMoneyRange, parseDateTimeRange } = require('../../../../../execution/range');
|
|
6
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
7
|
+
const { inputIssue, constraints, modelAt, withInputScope } = require('../../../../../execution/error-details');
|
|
8
|
+
const { reject } = require('./query');
|
|
9
|
+
const schema = require('./schema.json');
|
|
10
|
+
|
|
11
|
+
const rangeFields = {
|
|
12
|
+
created: ['created_at', 'time'],
|
|
13
|
+
memberCreated: ['created_member_at', 'time'],
|
|
14
|
+
lastTrade: ['last_trade_time', 'time'],
|
|
15
|
+
tradeCount: ['total_trade_count', 'count'],
|
|
16
|
+
tradeAmount: ['total_trade_amount', 'money'],
|
|
17
|
+
points: ['points', 'points'],
|
|
18
|
+
storedBalance: ['stored_balance', 'money']
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function integer(value, maximum = Number.MAX_SAFE_INTEGER) {
|
|
22
|
+
if (typeof value !== 'string' || !/^(0|[1-9]\d*)$/.test(value) ||
|
|
23
|
+
!Number.isSafeInteger(Number(value)) || Number(value) > maximum) throw new Error('integer');
|
|
24
|
+
return Number(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function cents(value) {
|
|
28
|
+
if (typeof value !== 'string' || !/^(0|[1-9]\d*)(\.\d{1,2})?$/.test(value)) throw new Error('money');
|
|
29
|
+
const [whole, fraction = ''] = value.split('.');
|
|
30
|
+
const amount = BigInt(whole) * 100n + BigInt(fraction.padEnd(2, '0'));
|
|
31
|
+
if (amount > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error('money');
|
|
32
|
+
return Number(amount);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function boundary(value, type) {
|
|
36
|
+
if (type === 'time') {
|
|
37
|
+
if (value !== value.trim()) throw new Error('time whitespace');
|
|
38
|
+
const seconds = apiSeconds(value);
|
|
39
|
+
if (seconds < 0 || seconds > 4102444800) throw new Error('time bounds');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (type === 'money') {
|
|
43
|
+
cents(value);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
integer(value, type === 'count' ? 2147483647 : Number.MAX_SAFE_INTEGER);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function range(value, type) {
|
|
50
|
+
if (typeof value !== 'string') throw new Error('range');
|
|
51
|
+
for (const part of value.split('..')) if (part !== '') boundary(part, type);
|
|
52
|
+
if (type === 'time') return parseDateTimeRange(value, { precision: 'seconds' });
|
|
53
|
+
if (type === 'money') return parseMoneyRange(value, { maximum: '90071992547409.91' });
|
|
54
|
+
return parseIntegerRange(value, { maximum: type === 'count' ? 2147483647 : Number.MAX_SAFE_INTEGER });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function idList(value) {
|
|
58
|
+
if (typeof value !== 'string' || value !== value.trim()) throw new Error('ids');
|
|
59
|
+
const entries = value.startsWith('[') ? JSON.parse(value) : value.split(',');
|
|
60
|
+
if (!Array.isArray(entries) || entries.length < 1 || entries.length > 50) throw new Error('ids');
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
if (typeof entry !== 'string' || integer(entry) < 1) throw new Error('id');
|
|
63
|
+
}
|
|
64
|
+
return [...new Set(entries)];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function buildInput(options, context) {
|
|
68
|
+
let kdtId;
|
|
69
|
+
try {
|
|
70
|
+
if (typeof options.kdtId !== 'string' || integer(options.kdtId) < 1) throw new Error('shop');
|
|
71
|
+
kdtId = options.kdtId;
|
|
72
|
+
} catch { throw inputIssue('/kdtId', 'invalid_format', constraints(modelAt(schema, 'input', '/kdtId'))); }
|
|
73
|
+
const scope = { kdtId };
|
|
74
|
+
try { resolveTargetShop(options, context, 'customer.customer.list'); }
|
|
75
|
+
catch (error) {
|
|
76
|
+
const details = error.cliDetails;
|
|
77
|
+
throw reject(details?.category || 'configuration', details?.stage === 'context' ? 'context' : 'input', scope);
|
|
78
|
+
}
|
|
79
|
+
return withInputScope(scope, () => {
|
|
80
|
+
function field(name, parse, path = `/filters/${name}`) {
|
|
81
|
+
try { return parse(); }
|
|
82
|
+
catch {
|
|
83
|
+
const expected = constraints(modelAt(schema, 'input', path));
|
|
84
|
+
if (rangeFields[name]?.[1] === 'time') {
|
|
85
|
+
expected.format = '北京时间 YYYY-MM-DD HH:mm:ss,区间必须包含 ..,不接受时间戳';
|
|
86
|
+
}
|
|
87
|
+
throw inputIssue(path, expected.type === 'integer' ? 'out_of_range' : 'invalid_format', expected);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const filters = {};
|
|
91
|
+
for (const name of ['keyword', 'mobile']) {
|
|
92
|
+
if (options[name] !== undefined) filters[name] = options[name];
|
|
93
|
+
}
|
|
94
|
+
for (const name of ['isMember', 'hasLevel', 'hasBenefitCard']) {
|
|
95
|
+
if (options[name] === undefined) continue;
|
|
96
|
+
if (!['true', 'false'].includes(options[name])) {
|
|
97
|
+
throw inputIssue(`/filters/${name}`, 'invalid_choice', { type: 'boolean', enum: [true, false] });
|
|
98
|
+
}
|
|
99
|
+
filters[name] = options[name] === 'true';
|
|
100
|
+
}
|
|
101
|
+
for (const name of ['tagIds', 'levelIds', 'benefitCardIds']) {
|
|
102
|
+
if (options[name] !== undefined) filters[name] = field(name, () => idList(options[name]));
|
|
103
|
+
}
|
|
104
|
+
for (const [name, [, type]] of Object.entries(rangeFields)) {
|
|
105
|
+
if (options[name] !== undefined) filters[name] = field(name, () => range(options[name], type));
|
|
106
|
+
}
|
|
107
|
+
const input = { kdtId, filters,
|
|
108
|
+
pageNo: field('pageNo', () => integer(options.pageNo, 500), '/pageNo'),
|
|
109
|
+
pageSize: field('pageSize', () => integer(options.pageSize, 50), '/pageSize') };
|
|
110
|
+
validateCommandValue(schema, 'input', input);
|
|
111
|
+
for (const [left, right] of [['keyword', 'mobile'], ['hasLevel', 'levelIds'], ['hasBenefitCard', 'benefitCardIds']]) {
|
|
112
|
+
if (filters[right] !== undefined && (left === 'keyword' ? filters[left] !== undefined : filters[left] === false)) {
|
|
113
|
+
throw inputIssue(`/filters/${right}`, 'constraint', undefined, [`/filters/${left}`]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (input.pageNo * input.pageSize > 10000) {
|
|
117
|
+
throw inputIssue('/pageNo', 'constraint', { maximum: Math.floor(10000 / input.pageSize) }, ['/pageSize']);
|
|
118
|
+
}
|
|
119
|
+
return input;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function requestBody(input) {
|
|
124
|
+
const body = { page_no: input.pageNo, page_size: input.pageSize };
|
|
125
|
+
const { filters } = input;
|
|
126
|
+
for (const name of ['keyword', 'mobile']) {
|
|
127
|
+
if (filters[name] !== undefined) body[name] = filters[name];
|
|
128
|
+
}
|
|
129
|
+
if (filters.isMember !== undefined) body.is_member = filters.isMember ? 1 : 0;
|
|
130
|
+
for (const [name, field] of Object.entries({ tagIds: 'all_match_tag_ids', levelIds: 'level_ids', benefitCardIds: 'card_ids' })) {
|
|
131
|
+
if (filters[name]) body[field] = filters[name].map(Number);
|
|
132
|
+
}
|
|
133
|
+
for (const [name, field] of Object.entries({ hasLevel: 'has_level', hasBenefitCard: 'has_card' })) {
|
|
134
|
+
if (filters[name] !== undefined) body[field] = filters[name];
|
|
135
|
+
}
|
|
136
|
+
for (const [name, [field, type]] of Object.entries(rangeFields)) {
|
|
137
|
+
if (!filters[name]) continue;
|
|
138
|
+
for (const [bound, value] of Object.entries(filters[name])) {
|
|
139
|
+
body[`${field}_${bound}`] = type === 'time' ? apiSeconds(value) : type === 'money' ? cents(value) : value;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return body;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = { buildInput, requestBody, range, cents };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { readTotal } = require('../../../../../execution/list-total');
|
|
4
|
+
|
|
5
|
+
const { createBoundShopQuery, bindingPath } = require('../../../../../execution/shop-query');
|
|
6
|
+
const { QueryError, object } = require('../../../../../execution/query-api');
|
|
7
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
8
|
+
const { formatDateTime } = require('../../../../../execution/datetime');
|
|
9
|
+
const schema = require('./schema.json');
|
|
10
|
+
|
|
11
|
+
const command = 'customer.customer.list';
|
|
12
|
+
const RESPONSE_LIMIT = 10 * 1024 * 1024;
|
|
13
|
+
const OUTPUT_LIMIT = 5 * 1024 * 1024;
|
|
14
|
+
|
|
15
|
+
function reject(category, stage, scope = {}, state = 'not_sent', facts = {}) {
|
|
16
|
+
return new QueryError(category, stage, scope, facts, state, command,
|
|
17
|
+
'核对原店铺、筛选范围、字段来源和服务端授权;失败不返回部分客户,不自动换店、换身份或重放请求。');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function createQuery(input, responseLimit = RESPONSE_LIMIT) {
|
|
21
|
+
const scope = { kdtId: input.kdtId };
|
|
22
|
+
let responseBytes = 0;
|
|
23
|
+
try {
|
|
24
|
+
const query = await createBoundShopQuery({ kdtId: Number(input.kdtId) }, command, 'shop-binding', {
|
|
25
|
+
onResponse: response => { responseBytes += response.responseBytes; },
|
|
26
|
+
transportOptions: { maxResponseBytes: () => responseLimit - responseBytes, shopApp: false }
|
|
27
|
+
});
|
|
28
|
+
return async body => {
|
|
29
|
+
try { return await query.read(schema.api.path, body, 'search'); }
|
|
30
|
+
catch (error) { throw adaptError(error, scope); }
|
|
31
|
+
};
|
|
32
|
+
} catch (error) { throw adaptError(error, scope); }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function adaptError(error, scope) {
|
|
36
|
+
if (!error.cliDetails) return reject('configuration', 'configuration', scope);
|
|
37
|
+
const { category, stage, requestState, ...details } = error.cliDetails;
|
|
38
|
+
const facts = {};
|
|
39
|
+
for (const name of ['api', 'httpStatus', 'businessCode', 'gatewayCode', 'trace_id', 'request_id']) {
|
|
40
|
+
if (details[name] !== undefined) facts[name] = details[name];
|
|
41
|
+
}
|
|
42
|
+
return reject(category, stage, scope, requestState, facts);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function customer(source) {
|
|
46
|
+
if (!object(source)) throw new Error('customer');
|
|
47
|
+
const result = {};
|
|
48
|
+
for (const [name, field] of Object.entries({ yzOpenId: 'yz_open_id', name: 'name', showName: 'show_name',
|
|
49
|
+
mobile: 'mobile', gender: 'gender', tradeCount: 'trade_count', points: 'points', isMobileAuthorized: 'is_mobile_auth' })) {
|
|
50
|
+
if (Object.hasOwn(source, field)) result[name] = source[field];
|
|
51
|
+
}
|
|
52
|
+
if (Object.hasOwn(source, 'is_member')) {
|
|
53
|
+
if (![0, 1].includes(source.is_member)) throw new Error('member');
|
|
54
|
+
result.isMember = source.is_member === 1;
|
|
55
|
+
}
|
|
56
|
+
for (const [name, field] of Object.entries({ createdAt: 'created_at', memberCreatedAt: 'created_member_at' })) {
|
|
57
|
+
if (!Object.hasOwn(source, field)) continue;
|
|
58
|
+
const seconds = source[field];
|
|
59
|
+
if (field === 'created_member_at' && seconds === 0) result[name] = 0;
|
|
60
|
+
else {
|
|
61
|
+
if (!Number.isSafeInteger(seconds) || seconds <= 0) throw new Error('timestamp');
|
|
62
|
+
result[name] = formatDateTime(seconds * 1000);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function adapt(data, input, facts = {}) {
|
|
69
|
+
try {
|
|
70
|
+
if (!object(data) || !Array.isArray(data.record_list) || data.record_list.length > input.pageSize) throw new Error('page');
|
|
71
|
+
for (const [name, value] of Object.entries({ page_no: input.pageNo, page_size: input.pageSize })) {
|
|
72
|
+
if (Object.hasOwn(data, name) && data[name] !== value) throw new Error('page mismatch');
|
|
73
|
+
}
|
|
74
|
+
const total = readTotal(data, 'total');
|
|
75
|
+
const count = data.record_list.length;
|
|
76
|
+
const position = (input.pageNo - 1) * input.pageSize + count;
|
|
77
|
+
if (total !== null && (count > 0 && total < position || count < input.pageSize && total > position)) {
|
|
78
|
+
throw new Error('total position');
|
|
79
|
+
}
|
|
80
|
+
const customers = data.record_list.map(customer);
|
|
81
|
+
const boundary = input.pageNo * input.pageSize;
|
|
82
|
+
const canContinue = input.pageNo < 500 && boundary + input.pageSize <= 10000;
|
|
83
|
+
const hasMore = total === null ? null : total <= boundary ? false : canContinue ? true : null;
|
|
84
|
+
const output = { data: { customers, pagination: { pageNo: input.pageNo, pageSize: input.pageSize,
|
|
85
|
+
...(total === null ? {} : { total }), hasMore } } };
|
|
86
|
+
validateCommandValue(schema, 'output', output);
|
|
87
|
+
const seen = new Set();
|
|
88
|
+
output.data.customers = customers.filter(row => {
|
|
89
|
+
if (seen.has(row.yzOpenId)) return false;
|
|
90
|
+
seen.add(row.yzOpenId);
|
|
91
|
+
return true;
|
|
92
|
+
});
|
|
93
|
+
return output;
|
|
94
|
+
} catch { throw reject('protocol', 'output', { kdtId: input.kdtId }, 'sent', facts); }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function serialize(output, format, scope, limit = OUTPUT_LIMIT) {
|
|
98
|
+
const text = JSON.stringify(output, null, format === 'pretty' ? 2 : 0);
|
|
99
|
+
if (Buffer.byteLength(`${text}\n`, 'utf8') > limit) throw reject('limit', 'output', scope, 'sent');
|
|
100
|
+
return text;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = { reject, createQuery, adapt, serialize, bindingPath, RESPONSE_LIMIT, OUTPUT_LIMIT };
|