@youzan-cloud/zan-saas-cli 0.0.0-stage → 0.1.0-beta.3
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 +105 -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 +102 -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,148 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
|
|
4
|
+
|
|
5
|
+
const { Option } = require('commander');
|
|
6
|
+
const { DiagnosticCommand } = require('../../../../../cli/diagnostic-command');
|
|
7
|
+
const { inputIssue, withInputScope, constraints, modelAt } = require('../../../../../execution/error-details');
|
|
8
|
+
const { parseIncludeModules } = require('../../../../../execution/command-io');
|
|
9
|
+
const { readContext } = require('../../../../../identity/context');
|
|
10
|
+
const { parseDateTime } = require('../../../../../execution/datetime');
|
|
11
|
+
const { parseDateTimeRange } = require('../../../../../execution/range');
|
|
12
|
+
const { queryDefinition, validateCommandValue } = require('../../../../../execution/command-schema');
|
|
13
|
+
const { bindingPath, targetScope, reject, serialize } = require('../../shared/query');
|
|
14
|
+
const { listPath, toPreviewBody, filterOptions } = require('../../shared/search');
|
|
15
|
+
const { scan, initialRanges, pageInput, addCalendarMonths } = require('./scan');
|
|
16
|
+
const schema = require('./schema.json');
|
|
17
|
+
|
|
18
|
+
const command = 'order.order.scan';
|
|
19
|
+
const { includeModules } = queryDefinition(schema);
|
|
20
|
+
const filterSchema = schema.input.properties.filters.properties;
|
|
21
|
+
|
|
22
|
+
function buildInput(options, context) {
|
|
23
|
+
const scope = targetScope(options, context, command);
|
|
24
|
+
return withInputScope(scope, () => normalizedInput(options, scope));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizedInput(options, scope) {
|
|
28
|
+
const fail = (path, reason, expected, relatedPaths) => {
|
|
29
|
+
throw inputIssue(path, reason, expected || constraints(modelAt(schema, 'input', path)), relatedPaths);
|
|
30
|
+
};
|
|
31
|
+
if ((options.createdAt !== undefined) === (options.paidAt !== undefined)) {
|
|
32
|
+
fail('/range', 'constraint', { format: '--created-at 与 --paid-at 必须二选一,提供完整 START..END' });
|
|
33
|
+
}
|
|
34
|
+
const timeField = options.paidAt !== undefined ? 'paidAt' : 'createdAt';
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
let start;
|
|
37
|
+
let end;
|
|
38
|
+
let range;
|
|
39
|
+
try {
|
|
40
|
+
range = parseDateTimeRange(options[timeField], { precision: 'seconds', requireBoth: true, strictOrder: true });
|
|
41
|
+
start = parseDateTime(range.start);
|
|
42
|
+
end = parseDateTime(range.end);
|
|
43
|
+
} catch {
|
|
44
|
+
const error = inputIssue('/range', 'invalid_format', {
|
|
45
|
+
format: '北京时间 YYYY-MM-DD HH:mm:ss,START..END 必须两端,开始早于结束,非零毫秒不支持'
|
|
46
|
+
});
|
|
47
|
+
error.issues[0].option = timeField === 'paidAt' ? '--paid-at' : '--created-at';
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
if (start % 1000 !== 0 || end % 1000 !== 0 || start < parseDateTime('2020-01-01 00:00:00') ||
|
|
51
|
+
end <= start || end > now || end > addCalendarMonths(start, 12)) {
|
|
52
|
+
const error = inputIssue('/range', 'out_of_range', {
|
|
53
|
+
format: '开始不早于2020年,结束晚于开始且不晚于当前时刻,跨度最多一日历年'
|
|
54
|
+
});
|
|
55
|
+
error.issues[0].option = timeField === 'paidAt' ? '--paid-at' : '--created-at';
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const filters = {};
|
|
59
|
+
for (const [name, optionName] of filterOptions) {
|
|
60
|
+
if (name === 'orderNo' || options[optionName] === undefined) continue;
|
|
61
|
+
const value = options[optionName];
|
|
62
|
+
if (typeof value !== 'string' || !value.trim()) fail(`/filters/${name}`, 'invalid_format');
|
|
63
|
+
if (name === 'item_id' && (!/^[1-9]\d*$/.test(value) || !Number.isSafeInteger(Number(value)))) {
|
|
64
|
+
fail('/filters/item_id', 'invalid_format', { type: 'string', pattern: '^[1-9]\\d*$', maximum: Number.MAX_SAFE_INTEGER });
|
|
65
|
+
}
|
|
66
|
+
filters[name] = value;
|
|
67
|
+
}
|
|
68
|
+
const maxItems = options.maxItems === undefined ? 1000 : Number(options.maxItems);
|
|
69
|
+
const maxRequests = options.maxRequests === undefined ? 100 : Number(options.maxRequests);
|
|
70
|
+
const input = {
|
|
71
|
+
scope, filters, range, timeField,
|
|
72
|
+
limits: { maxItems, maxRequests }, include: [...parseIncludeModules(options.include, includeModules, '/include')],
|
|
73
|
+
format: options.format, dryRun: options.dryRun === true
|
|
74
|
+
};
|
|
75
|
+
validateCommandValue(schema, 'input', input);
|
|
76
|
+
return input;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function preview(input) {
|
|
80
|
+
const ranges = initialRanges(input.range);
|
|
81
|
+
const output = {
|
|
82
|
+
requests: [{ method: 'POST', path: bindingPath, body: {} }],
|
|
83
|
+
initialRanges: ranges.map(({ start, end }) => ({ start, end })),
|
|
84
|
+
requestTemplate: { method: 'POST', path: listPath, body: toPreviewBody(pageInput(input, ranges[0])) },
|
|
85
|
+
limits: { ...input.limits, pageSize: Math.min(100, input.limits.maxItems) }
|
|
86
|
+
};
|
|
87
|
+
validateCommandValue(schema, 'preview', output);
|
|
88
|
+
return output;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function createCommand({ context } = {}) {
|
|
92
|
+
const instance = new DiagnosticCommand('scan', { path: command, schema, optionPaths: {
|
|
93
|
+
'/scope/kdtId': 'kdtId', '/range': 'createdAt', '/limits/maxItems': 'maxItems', '/limits/maxRequests': 'maxRequests',
|
|
94
|
+
...Object.fromEntries(filterOptions.filter(([name]) => name !== 'orderNo').map(([name, option]) => [`/filters/${name}`, option]))
|
|
95
|
+
} })
|
|
96
|
+
.description('按显式时间范围和预算读取订单;可提前停止并报告已读结果和未完成范围')
|
|
97
|
+
.allowExcessArguments(false)
|
|
98
|
+
.option('--kdt-id <id>', '目标店铺正安全整数;省略时使用当前上下文店铺')
|
|
99
|
+
.option('--created-at <range>', '创建时间 START..END,与 --paid-at 必须二选一,北京时间,秒精度,不早于2020年')
|
|
100
|
+
.option('--paid-at <range>', '支付时间 START..END,与 --created-at 必须二选一,北京时间,秒精度,不早于2020年')
|
|
101
|
+
.option('--yz-open-id <id>', '客户统一标识')
|
|
102
|
+
.addOption(new Option('--status <value>', '交易状态筛选').choices(filterSchema.status.enum))
|
|
103
|
+
.addOption(new Option('--type <value>', '订单类型筛选').choices(filterSchema.type.enum))
|
|
104
|
+
.option('--item-id <id>', '统一商品 ID')
|
|
105
|
+
.option('--item-title <text>', '商品名称模糊搜索')
|
|
106
|
+
.option('--receiver-phone <text>', '收货人电话')
|
|
107
|
+
.option('--receiver-name <text>', '收货人姓名')
|
|
108
|
+
.addOption(new Option('--delivery-type <value>', '配送类型筛选').choices(filterSchema.deliveryType.enum))
|
|
109
|
+
.option('--keyword <text>', '订单号、收货人手机或后四位搜索')
|
|
110
|
+
.option('--include <modules>', `追加模块:${includeModules.join(', ')};仅投影,不增加请求`)
|
|
111
|
+
.option('--max-items <n>', '去重结果上限,1至10000,不裁切整页', '1000')
|
|
112
|
+
.option('--max-requests <n>', '总请求预算,2至500,含店铺核验、探测和翻页', '100')
|
|
113
|
+
.addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进').choices(['json', 'pretty']).default('json'))
|
|
114
|
+
.option('--dry-run', '纯本地预览,收货电话、姓名及关键词全部遮盖为 ***;不读凭证、不联网')
|
|
115
|
+
.addHelpText('after', `
|
|
116
|
+
商品行 item_id/sku_id 是OneID,channel_item_id/channel_sku_id 为历史渠道身份。
|
|
117
|
+
--item-id沿用统一商品筛选,不把上游goods_id机械视为旧item_id,不增加渠道映射查询。
|
|
118
|
+
示例:zan-saas order order scan --kdt-id 63077 --created-at "2026-10-01 00:00:00..2026-10-02 00:00:00" --max-requests 2 --dry-run
|
|
119
|
+
创建时间或支付时间必须二选一,用 .. 分隔且包含两端,开始早于结束;结束不晚于当前时刻,跨度最多一日历年,非零毫秒拒绝。
|
|
120
|
+
所有分片、二分、翻页和停止范围保持所选时间轴,支付轴不附加创建约束;固定并发1,每页 min(100,maxItems),初始区间最多三个月,相邻区间共享端点。
|
|
121
|
+
支付轴示例:zan-saas order order scan --kdt-id 63077 --paid-at "2026-10-01 00:00:00..2026-11-01 00:00:00" --max-requests 2 --dry-run
|
|
122
|
+
默认订单可含 paidAt、isPaid;缺失表示未取得,不从状态、金额或请求窗口推算。订单级支付时间不是逐笔资金事件。
|
|
123
|
+
--include payment 仍为列表金额,不含 realPayment,不逐单请求详情,不能据此求实付或净收入。
|
|
124
|
+
返回订单号通常为 E/V/C 开头加 23 位数字,仅供核对,不按该格式拒绝响应;本命令不接收 --order-no。
|
|
125
|
+
超过100页容量按整数秒二分;1秒区间仍过密时停止。不发送第101页,不重试、不轮询、不后台导出。
|
|
126
|
+
按店铺和订单号去重,保留首次提交版本。剩余预算不足下一整页时停止,结果可能少于上限。
|
|
127
|
+
pagination 返回停止原因;存在未完成范围时附带 pendingRanges,不提供恢复游标。
|
|
128
|
+
预算不足可以成功返回已取得的完整页;须检查 stopReason 和 pendingRanges 判断是否读完。
|
|
129
|
+
range_exhausted 只表示本次观测的范围走完,不保证端点开闭、稳定顺序、快照或无遗漏。
|
|
130
|
+
本批默认 CNY,金额为两位小数字符串,不换汇、不新增币种字段;这是批次约定,不是官方币种保证。
|
|
131
|
+
累计响应20MiB、最终UTF-8输出含换行10MiB,超限及任一请求/锚点/模型错误整体失败,不输出部分订单。
|
|
132
|
+
执行需要有效的用户、组织与店铺上下文,可通过登录后选店或 ZAN_SAAS_CONTEXT 提供;目标范围和服务端授权按本命令契约校验,公共调用前置见 zan-saas skills read zan-saas-shared。
|
|
133
|
+
`)
|
|
134
|
+
.action(async options => {
|
|
135
|
+
const state = readContext(context);
|
|
136
|
+
const input = buildInput(options, context);
|
|
137
|
+
const plan = preview(input);
|
|
138
|
+
const output = input.dryRun ? plan : await scan(input, state.context);
|
|
139
|
+
if (!input.dryRun) {
|
|
140
|
+
try { validateCommandValue(schema, 'output', output); }
|
|
141
|
+
catch { throw reject(command, 'protocol', 'output-model', input.scope, 'sent'); }
|
|
142
|
+
}
|
|
143
|
+
console.log(serialize(output, input.format, command, input.scope, 10 * 1024 * 1024));
|
|
144
|
+
});
|
|
145
|
+
return instance;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand), buildInput, preview };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { formatDateTime, parseDateTime } = require('../../../../../execution/datetime');
|
|
4
|
+
const { createOrderPageReader } = require('../../shared/search');
|
|
5
|
+
|
|
6
|
+
function addCalendarMonths(milliseconds, months) {
|
|
7
|
+
const offset = 8 * 60 * 60 * 1000;
|
|
8
|
+
const date = new Date(milliseconds + offset);
|
|
9
|
+
const day = date.getUTCDate();
|
|
10
|
+
date.setUTCDate(1);
|
|
11
|
+
date.setUTCMonth(date.getUTCMonth() + months);
|
|
12
|
+
const lastDay = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 0)).getUTCDate();
|
|
13
|
+
date.setUTCDate(Math.min(day, lastDay));
|
|
14
|
+
return date.getTime() - offset;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function initialRanges(range) {
|
|
18
|
+
const pending = [];
|
|
19
|
+
const end = parseDateTime(range.end);
|
|
20
|
+
let start = parseDateTime(range.start);
|
|
21
|
+
while (start < end) {
|
|
22
|
+
const next = Math.min(end, addCalendarMonths(start, 3));
|
|
23
|
+
pending.push({ start: formatDateTime(start), end: formatDateTime(next), pageNo: 1 });
|
|
24
|
+
start = next;
|
|
25
|
+
}
|
|
26
|
+
return pending;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pageInput(input, range) {
|
|
30
|
+
return {
|
|
31
|
+
scope: input.scope, filters: input.filters,
|
|
32
|
+
range: { [input.timeField === 'paidAt' ? 'paid' : 'created']: { start: range.start, end: range.end } },
|
|
33
|
+
include: input.include, pagination: { pageNo: range.pageNo, pageSize: Math.min(100, input.limits.maxItems) }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function scan(input, context, readerFactory = createOrderPageReader) {
|
|
38
|
+
const { maxItems, maxRequests } = input.limits;
|
|
39
|
+
const pageSize = Math.min(100, maxItems);
|
|
40
|
+
const pending = initialRanges(input.range);
|
|
41
|
+
const orders = [];
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
let requests = 0;
|
|
44
|
+
let halt;
|
|
45
|
+
const read = await readerFactory(input.scope, context, 'order.order.scan', {
|
|
46
|
+
responseLimit: 20 * 1024 * 1024, bounded: true,
|
|
47
|
+
onRequest: () => { requests++; }
|
|
48
|
+
});
|
|
49
|
+
while (true) {
|
|
50
|
+
const stopReason = pending.length === 0 ? 'range_exhausted' :
|
|
51
|
+
maxItems - orders.length < pageSize ? 'max_items' :
|
|
52
|
+
requests >= maxRequests ? 'max_requests' : halt;
|
|
53
|
+
if (stopReason) {
|
|
54
|
+
const pagination = { stopReason };
|
|
55
|
+
if (pending.length > 0) pagination.pendingRanges = pending;
|
|
56
|
+
return { data: { orders, pagination } };
|
|
57
|
+
}
|
|
58
|
+
const current = pending[0];
|
|
59
|
+
const { output: result, total } = await read(pageInput(input, current));
|
|
60
|
+
const { hasMore } = result.data.pagination;
|
|
61
|
+
if (total > 100 * pageSize) {
|
|
62
|
+
if (current.pageNo > 1) {
|
|
63
|
+
current.pageNo = 1;
|
|
64
|
+
halt = 'page_window';
|
|
65
|
+
} else {
|
|
66
|
+
const start = parseDateTime(current.start);
|
|
67
|
+
const end = parseDateTime(current.end);
|
|
68
|
+
const midpoint = Math.floor((start / 1000 + end / 1000) / 2) * 1000;
|
|
69
|
+
if (midpoint <= start || midpoint >= end) halt = 'density_limit';
|
|
70
|
+
else {
|
|
71
|
+
const mid = formatDateTime(midpoint);
|
|
72
|
+
pending.splice(0, 1, { start: current.start, end: mid, pageNo: 1 },
|
|
73
|
+
{ start: mid, end: current.end, pageNo: 1 });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
for (const row of result.data.orders) {
|
|
79
|
+
const key = `${row.order.kdtId}:${row.order.orderNo}`;
|
|
80
|
+
if (seen.has(key)) continue;
|
|
81
|
+
seen.add(key);
|
|
82
|
+
orders.push(row);
|
|
83
|
+
}
|
|
84
|
+
if (hasMore) current.pageNo++;
|
|
85
|
+
else pending.shift();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = { scan, initialRanges, pageInput, addCalendarMonths };
|