@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,183 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { object } = require('../../../../execution/query-api');
|
|
4
|
+
const { normalizeMoney } = require('../../../../execution/money');
|
|
5
|
+
const { apiDateTime, formatDateTime, parseDateTime } = require('../../../../execution/datetime');
|
|
6
|
+
|
|
7
|
+
function id(value, allowZero = false) {
|
|
8
|
+
if (typeof value === 'number') {
|
|
9
|
+
if (!Number.isSafeInteger(value)) throw new Error('unsafe id');
|
|
10
|
+
value = String(value);
|
|
11
|
+
}
|
|
12
|
+
if (typeof value !== 'string' || !/^\d+$/.test(value) || (!allowZero && !/[1-9]/.test(value))) {
|
|
13
|
+
throw new Error('invalid id');
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function money(value, signed = false) {
|
|
19
|
+
if (typeof value !== 'string' || !(signed ? /^-?\d+(?:\.\d+)?$/ : /^\d+(?:\.\d+)?$/).test(value)) {
|
|
20
|
+
throw new Error('invalid yuan amount');
|
|
21
|
+
}
|
|
22
|
+
return normalizeMoney(value, { $comment: 'upstream-money:yuan' });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function text(value, nonempty = false) {
|
|
26
|
+
if (typeof value !== 'string' || (nonempty && !value.trim())) throw new Error('invalid text');
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function integer(value, nonnegative = false) {
|
|
31
|
+
if (!Number.isSafeInteger(value) || (nonnegative && value < 0)) throw new Error('invalid integer');
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function boolean(value) {
|
|
36
|
+
if (typeof value !== 'boolean') throw new Error('invalid boolean');
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function time(value, empty = false) {
|
|
41
|
+
if (empty && value === '') return value;
|
|
42
|
+
apiDateTime(value);
|
|
43
|
+
return formatDateTime(parseDateTime(value));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function project(source, fields, required = []) {
|
|
47
|
+
if (!object(source)) throw new Error('missing object');
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const [target, [field, convert]] of Object.entries(fields)) {
|
|
50
|
+
if (Object.hasOwn(source, field)) result[target] = convert(source[field]);
|
|
51
|
+
else if (required.includes(target)) throw new Error('missing field');
|
|
52
|
+
}
|
|
53
|
+
if (!Object.keys(result).length) throw new Error('empty selected module');
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function array(value, convert) {
|
|
58
|
+
if (!Array.isArray(value)) throw new Error('missing array');
|
|
59
|
+
return value.map(convert);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const nonemptyText = value => text(value, true);
|
|
63
|
+
const zeroId = value => id(value, true);
|
|
64
|
+
const nonnegative = value => integer(value, true);
|
|
65
|
+
const deliveryTypes = Object.freeze({ 0: 'EXPRESS', 1: 'SELF_FETCH', 2: 'LOCAL_DELIVERY', 9: 'VIRTUAL' });
|
|
66
|
+
|
|
67
|
+
function order(source) {
|
|
68
|
+
const result = project(source, {
|
|
69
|
+
orderNo: ['tid', nonemptyText], kdtId: ['node_kdt_id', id], rootKdtId: ['root_kdt_id', id],
|
|
70
|
+
status: ['status', nonemptyText], statusText: ['status_str', text], type: ['type', integer],
|
|
71
|
+
createdAt: ['created', time], updatedAt: ['update_time', time], shopName: ['shop_name', text]
|
|
72
|
+
}, ['orderNo', 'kdtId', 'status', 'type', 'createdAt']);
|
|
73
|
+
if (Object.hasOwn(source, 'pay_time') && source.pay_time !== '' && source.pay_time !== null) {
|
|
74
|
+
result.paidAt = time(source.pay_time);
|
|
75
|
+
}
|
|
76
|
+
if (Object.hasOwn(source, 'order_tags')) {
|
|
77
|
+
if (!object(source.order_tags)) throw new Error('invalid order tags');
|
|
78
|
+
if (Object.hasOwn(source.order_tags, 'is_payed')) result.isPaid = boolean(source.order_tags.is_payed);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function items(source) {
|
|
84
|
+
return array(source, entry => {
|
|
85
|
+
if (!object(entry)) throw new Error('missing item');
|
|
86
|
+
const normalized = { ...entry };
|
|
87
|
+
for (const name of ['unified_item_id', 'unified_sku_id']) {
|
|
88
|
+
if (normalized[name] === '') delete normalized[name];
|
|
89
|
+
}
|
|
90
|
+
return project(normalized, {
|
|
91
|
+
oid: ['oid', nonemptyText], title: ['title', text], quantity: ['num', nonnegative],
|
|
92
|
+
item_id: ['unified_item_id', id], sku_id: ['unified_sku_id', zeroId],
|
|
93
|
+
channel_item_id: ['item_id', id], channel_sku_id: ['sku_id', zeroId],
|
|
94
|
+
unitPrice: ['price', money], payment: ['payment', money],
|
|
95
|
+
isPresent: ['is_present', boolean], isCombo: ['is_combo', boolean]
|
|
96
|
+
}, ['oid', 'title', 'quantity']);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function payment(source) {
|
|
101
|
+
return project(source, {
|
|
102
|
+
totalFee: ['total_fee', money], postFee: ['post_fee', money],
|
|
103
|
+
payment: ['payment', money], realPayment: ['real_payment', money]
|
|
104
|
+
}, ['totalFee', 'postFee', 'payment', 'realPayment']);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function listPayment(source) {
|
|
108
|
+
return project(source, {
|
|
109
|
+
totalFee: ['total_fee', money], postFee: ['post_fee', money],
|
|
110
|
+
payment: ['payment', money]
|
|
111
|
+
}, ['totalFee', 'postFee', 'payment']);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function listExtension(name, full) {
|
|
115
|
+
switch (name) {
|
|
116
|
+
case 'buyer': return project(full.buyer_info, { yzOpenId: ['yz_open_id', text] });
|
|
117
|
+
case 'address': return project(full.address_info, {
|
|
118
|
+
receiverName: ['receiver_name', text], receiverPhone: ['receiver_tel', text],
|
|
119
|
+
province: ['delivery_province', text], city: ['delivery_city', text],
|
|
120
|
+
district: ['delivery_district', text], address: ['delivery_address', text],
|
|
121
|
+
postalCode: ['delivery_postal_code', text]
|
|
122
|
+
});
|
|
123
|
+
case 'remark': return project(full.remark_info, {
|
|
124
|
+
buyerMessage: ['buyer_message', text], tradeMemo: ['trade_memo', text]
|
|
125
|
+
});
|
|
126
|
+
case 'source': return project(full.source_info, {
|
|
127
|
+
isOfflineOrder: ['is_offline_order', boolean], bookKey: ['book_key', text]
|
|
128
|
+
});
|
|
129
|
+
case 'aftersale': return project(full.order_info,
|
|
130
|
+
{ refundState: ['refund_state', integer] }, ['refundState']);
|
|
131
|
+
case 'fulfillment': return project(full.order_info, {
|
|
132
|
+
deliveryType: ['express_type', value => {
|
|
133
|
+
integer(value);
|
|
134
|
+
if (!Object.hasOwn(deliveryTypes, value)) throw new Error('unknown delivery type');
|
|
135
|
+
return deliveryTypes[value];
|
|
136
|
+
}]
|
|
137
|
+
}, ['deliveryType']);
|
|
138
|
+
default: throw new Error('unknown module');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function extension(name, data, full) {
|
|
143
|
+
switch (name) {
|
|
144
|
+
case 'buyer': return project(full.buyer_info, { yzOpenId: ['yz_open_id', text] });
|
|
145
|
+
case 'address': return project(full.address_info, {
|
|
146
|
+
receiverName: ['receiver_name', text], receiverPhone: ['receiver_tel', text],
|
|
147
|
+
province: ['delivery_province', text], city: ['delivery_city', text],
|
|
148
|
+
district: ['delivery_district', text], address: ['delivery_address', text],
|
|
149
|
+
postalCode: ['delivery_postal_code', text]
|
|
150
|
+
});
|
|
151
|
+
case 'remark': return project(full.remark_info, {
|
|
152
|
+
buyerMessage: ['buyer_message', text], tradeMemo: ['trade_memo', text]
|
|
153
|
+
});
|
|
154
|
+
case 'source': return project(full.source_info, {
|
|
155
|
+
isOfflineOrder: ['is_offline_order', boolean], bookKey: ['book_key', text]
|
|
156
|
+
});
|
|
157
|
+
case 'promotion': return project(data.order_promotion, {
|
|
158
|
+
itemDiscountFee: ['item_discount_fee', money], orderDiscountFee: ['order_discount_fee', money],
|
|
159
|
+
adjustFee: ['adjust_fee', value => money(value, true)]
|
|
160
|
+
}, ['itemDiscountFee', 'orderDiscountFee', 'adjustFee']);
|
|
161
|
+
case 'fulfillment': return project(full.order_info, {
|
|
162
|
+
deliveryType: ['express_type', value => {
|
|
163
|
+
integer(value);
|
|
164
|
+
if (!Object.hasOwn(deliveryTypes, value)) throw new Error('unknown delivery type');
|
|
165
|
+
return deliveryTypes[value];
|
|
166
|
+
}], consignTime: ['consign_time', value => time(value, true)]
|
|
167
|
+
}, ['deliveryType']);
|
|
168
|
+
case 'aftersale': return {
|
|
169
|
+
...project(full.order_info, { refundState: ['refund_state', integer] }, ['refundState']),
|
|
170
|
+
cases: array(data.refund_order, entry => project(entry, {
|
|
171
|
+
caseId: ['refund_id', nonemptyText], type: ['refund_type', integer], state: ['refund_state', integer],
|
|
172
|
+
refundFee: ['refund_fee', money], appliedAt: ['refund_time', time],
|
|
173
|
+
oids: ['oids', value => array(value, reference => {
|
|
174
|
+
if (!object(reference)) throw new Error('invalid oid reference');
|
|
175
|
+
return nonemptyText(reference.oid);
|
|
176
|
+
})]
|
|
177
|
+
}, ['caseId', 'type', 'state']))
|
|
178
|
+
};
|
|
179
|
+
default: throw new Error('unknown module');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = { id, money, text, integer, time, order, items, payment, listPayment, extension, listExtension };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { resolveTargetShop } = require('../../../../execution/target-shop');
|
|
4
|
+
const { createShopQuery, bindingPath, failure } = require('../../../../execution/shop-query');
|
|
5
|
+
const { parseIncludeModules } = require('../../../../execution/command-io');
|
|
6
|
+
const { copyErrorDetails } = require('../../../../execution/error-details');
|
|
7
|
+
|
|
8
|
+
const RESPONSE_LIMIT = 10 * 1024 * 1024;
|
|
9
|
+
const OUTPUT_LIMIT = 5 * 1024 * 1024;
|
|
10
|
+
|
|
11
|
+
function reject(command, category, stage, scope = {}, requestState = 'not_sent', facts = {}) {
|
|
12
|
+
const error = failure(command, category, stage, scope, requestState, facts);
|
|
13
|
+
error.cliDetails.nextStep = stage === 'shop-binding' ?
|
|
14
|
+
'主订单请求尚未发送。核对原凭证绑定店铺与显式目标,不自动重试、切店或换身份。' :
|
|
15
|
+
category === 'limit' ? '本次结果超出字节限制,未输出部分订单;停止并核对原范围,不截断或自动重试。' :
|
|
16
|
+
'核对原店铺、订单号、上下文与服务端授权;结构不符时停止,不自动重试、解密或换身份。';
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function adaptError(error, command, scope) {
|
|
21
|
+
if (!error.cliDetails) return error;
|
|
22
|
+
const details = error.cliDetails;
|
|
23
|
+
const category = details.category === 'parameter' ? 'validation' : details.category;
|
|
24
|
+
const stage = ['scope', 'validation'].includes(details.stage) ? 'input' : details.stage;
|
|
25
|
+
const adapted = reject(command, category, stage, scope, details.requestState);
|
|
26
|
+
adapted.cliDetails = copyErrorDetails(details, {
|
|
27
|
+
category, stage, command, targetScope: scope, nextStep: adapted.cliDetails.nextStep
|
|
28
|
+
});
|
|
29
|
+
if (error.diagnosticReason) adapted.diagnosticReason = error.diagnosticReason;
|
|
30
|
+
if (error.issues) adapted.issues = error.issues;
|
|
31
|
+
return adapted;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function targetScope(options, context, command) {
|
|
35
|
+
try {
|
|
36
|
+
const scope = resolveTargetShop(options, context, command);
|
|
37
|
+
return Object.freeze({ kdtId: String(scope.kdtId) });
|
|
38
|
+
} catch (error) {
|
|
39
|
+
const scope = error.cliDetails?.targetScope?.kdtId;
|
|
40
|
+
throw adaptError(error, command, scope === undefined ? {} : { kdtId: String(scope) });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function includes(value, allowed, command, scope) {
|
|
45
|
+
if (value !== undefined && (typeof value !== 'string' || value.split(',').some(entry => !entry.trim()))) {
|
|
46
|
+
throw reject(command, 'validation', 'input', scope);
|
|
47
|
+
}
|
|
48
|
+
try { return [...parseIncludeModules(value, allowed)]; }
|
|
49
|
+
catch { throw reject(command, 'validation', 'input', scope); }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function createOrderQuery(scope, command, { responseLimit = RESPONSE_LIMIT, onRequest,
|
|
53
|
+
bounded = false, shopApp } = {}) {
|
|
54
|
+
let responseBytes = 0;
|
|
55
|
+
function onResponse(response, path) {
|
|
56
|
+
responseBytes += response.responseBytes;
|
|
57
|
+
if (responseBytes > responseLimit) {
|
|
58
|
+
throw reject(command, 'limit', path === bindingPath ? 'shop-binding' : 'order', scope,
|
|
59
|
+
'sent', { api: path, httpStatus: response.httpStatus });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const read = await createShopQuery({ kdtId: Number(scope.kdtId) }, command, {
|
|
64
|
+
onResponse, transportOptions: { onRequest, shopApp,
|
|
65
|
+
maxResponseBytes: bounded ? () => responseLimit - responseBytes : undefined }
|
|
66
|
+
});
|
|
67
|
+
return async (path, body, stage = 'order') => {
|
|
68
|
+
try { return await read(path, body, stage); }
|
|
69
|
+
catch (error) { throw adaptError(error, command, scope); }
|
|
70
|
+
};
|
|
71
|
+
} catch (error) { throw adaptError(error, command, scope); }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function serialize(output, format, command, scope, outputLimit = OUTPUT_LIMIT) {
|
|
75
|
+
const json = JSON.stringify(output, null, format === 'pretty' ? 2 : 0);
|
|
76
|
+
if (Buffer.byteLength(`${json}\n`, 'utf8') > outputLimit) {
|
|
77
|
+
throw reject(command, 'limit', 'output-model', scope, 'sent');
|
|
78
|
+
}
|
|
79
|
+
return json;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = {
|
|
83
|
+
bindingPath, reject, targetScope, includes, createOrderQuery, serialize, RESPONSE_LIMIT, OUTPUT_LIMIT
|
|
84
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { readTotal } = require('../../../../execution/list-total');
|
|
4
|
+
|
|
5
|
+
const { apiDateTime } = require('../../../../execution/datetime');
|
|
6
|
+
const { object } = require('../../../../execution/query-api');
|
|
7
|
+
const { createOrderQuery, reject } = require('./query');
|
|
8
|
+
const projection = require('./projection');
|
|
9
|
+
|
|
10
|
+
const listPath = 'youzan.trades.sold.get/4.0.4';
|
|
11
|
+
const lifecycleFields = [['created', 'created'], ['updated', 'update'], ['paid', 'pay'], ['succeeded', 'success']];
|
|
12
|
+
const filterOptions = Object.freeze([
|
|
13
|
+
['orderNo', 'orderNo', 'tid'], ['yzOpenId', 'yzOpenId', 'yz_open_id'],
|
|
14
|
+
['status', 'status', 'status'], ['type', 'type', 'type'],
|
|
15
|
+
['item_id', 'itemId', 'goods_id'], ['itemTitle', 'itemTitle', 'goods_title'],
|
|
16
|
+
['receiverPhone', 'receiverPhone', 'receiver_phone'],
|
|
17
|
+
['receiverName', 'receiverName', 'receiver_name'],
|
|
18
|
+
['deliveryType', 'deliveryType', 'express_type'], ['keyword', 'keyword', 'keywords']
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
function toRequestBody(input) {
|
|
22
|
+
const body = {
|
|
23
|
+
node_kdt_id: Number(input.scope.kdtId),
|
|
24
|
+
page_no: input.pagination.pageNo,
|
|
25
|
+
page_size: input.pagination.pageSize
|
|
26
|
+
};
|
|
27
|
+
for (const [name, , upstream] of filterOptions) {
|
|
28
|
+
if (input.filters[name] === undefined) continue;
|
|
29
|
+
body[upstream] = name === 'item_id' ? Number(input.filters[name]) : input.filters[name];
|
|
30
|
+
}
|
|
31
|
+
for (const [name, upstream] of lifecycleFields) {
|
|
32
|
+
if (!input.range[name]) continue;
|
|
33
|
+
body[`start_${upstream}`] = apiDateTime(input.range[name].start);
|
|
34
|
+
body[`end_${upstream}`] = apiDateTime(input.range[name].end);
|
|
35
|
+
}
|
|
36
|
+
if (input.range.delivery) {
|
|
37
|
+
const deliveryTime = value => {
|
|
38
|
+
const formatted = apiDateTime(value);
|
|
39
|
+
return `${formatted.slice(0, 10)}-${formatted.slice(11).replaceAll(':', '-')}`;
|
|
40
|
+
};
|
|
41
|
+
body.delivery_start_time = deliveryTime(input.range.delivery.start);
|
|
42
|
+
body.delivery_end_time = deliveryTime(input.range.delivery.end);
|
|
43
|
+
}
|
|
44
|
+
return body;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function toPreviewBody(input) {
|
|
48
|
+
const body = toRequestBody(input);
|
|
49
|
+
for (const name of ['receiver_phone', 'receiver_name', 'keywords']) {
|
|
50
|
+
if (Object.hasOwn(body, name)) body[name] = '***';
|
|
51
|
+
}
|
|
52
|
+
return body;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function adaptPage(data, input, context, facts, command = 'order.order.list') {
|
|
56
|
+
try {
|
|
57
|
+
if (!object(data) || !Array.isArray(data.full_order_info_list) ||
|
|
58
|
+
data.full_order_info_list.length > input.pagination.pageSize) throw new Error('invalid page');
|
|
59
|
+
const total = readTotal(data, 'total_results');
|
|
60
|
+
if (command === 'order.order.scan' && total === null) throw new Error('missing scan total');
|
|
61
|
+
const start = (input.pagination.pageNo - 1) * input.pagination.pageSize;
|
|
62
|
+
if (total !== null && ((data.full_order_info_list.length > 0 && start + data.full_order_info_list.length > total) ||
|
|
63
|
+
(total > 0 && start < total && data.full_order_info_list.length === 0))) {
|
|
64
|
+
throw new Error('contradictory page');
|
|
65
|
+
}
|
|
66
|
+
const orders = data.full_order_info_list.map(entry => {
|
|
67
|
+
if (!object(entry) || !object(entry.full_order_info)) throw new Error('missing order');
|
|
68
|
+
const full = entry.full_order_info;
|
|
69
|
+
const order = projection.order(full.order_info);
|
|
70
|
+
if (order.kdtId !== input.scope.kdtId ||
|
|
71
|
+
(Object.hasOwn(order, 'rootKdtId') && order.rootKdtId !== context.hq)) {
|
|
72
|
+
throw reject(command, 'scope_unresolved', 'orders', input.scope, 'sent', facts);
|
|
73
|
+
}
|
|
74
|
+
const row = { order };
|
|
75
|
+
for (const name of input.include) {
|
|
76
|
+
if (name === 'items') row.items = projection.items(full.orders);
|
|
77
|
+
else if (name === 'payment') row.payment = projection.listPayment(full.pay_info);
|
|
78
|
+
else row[name] = projection.listExtension(name, full);
|
|
79
|
+
}
|
|
80
|
+
return row;
|
|
81
|
+
});
|
|
82
|
+
const output = { data: { orders, pagination: {
|
|
83
|
+
pageNo: input.pagination.pageNo, pageSize: input.pagination.pageSize,
|
|
84
|
+
returned: orders.length, hasMore: total === null ? null : start + input.pagination.pageSize < total
|
|
85
|
+
} } };
|
|
86
|
+
if (command === 'order.order.list') {
|
|
87
|
+
const pagination = output.data.pagination;
|
|
88
|
+
if (total !== null) pagination.total = total;
|
|
89
|
+
pagination.nextPageNo = pagination.hasMore === true && pagination.pageNo < 100 ? pagination.pageNo + 1 : null;
|
|
90
|
+
pagination.windowLimitReached = pagination.hasMore !== false && pagination.pageNo >= 100;
|
|
91
|
+
}
|
|
92
|
+
return output;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (error.cliDetails) throw error;
|
|
95
|
+
throw reject(command, 'protocol', 'output-model', input.scope, 'sent', facts);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function createOrderPageReader(scope, context, command, options) {
|
|
100
|
+
const read = await createOrderQuery(scope, command, options);
|
|
101
|
+
return async input => {
|
|
102
|
+
const { pageNo, pageSize } = input.pagination;
|
|
103
|
+
if (input.scope.kdtId !== scope.kdtId || !Number.isSafeInteger(pageNo) || pageNo < 1 || pageNo > 100 ||
|
|
104
|
+
!Number.isSafeInteger(pageSize) || pageSize < 1 || pageSize > 100) {
|
|
105
|
+
throw reject(command, 'validation', 'input', scope);
|
|
106
|
+
}
|
|
107
|
+
const { data, facts } = await read(listPath, toRequestBody(input), 'orders');
|
|
108
|
+
return { output: adaptPage(data, input, context, facts, command), total: data.total_results };
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = { listPath, toRequestBody, toPreviewBody, adaptPage, createOrderPageReader, filterOptions };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 3,
|
|
3
|
+
"domain": "org",
|
|
4
|
+
"businessCommands": [
|
|
5
|
+
{
|
|
6
|
+
"path": "org.staff.get",
|
|
7
|
+
"kind": "atomic",
|
|
8
|
+
"risk": "read",
|
|
9
|
+
"availability": "available",
|
|
10
|
+
"at": "shop",
|
|
11
|
+
"module": "org/staff/get/command.js",
|
|
12
|
+
"fingerprint": "0e6c6fd91988b916f4d5690677c712059ec65f7d6ce003eed7d7192ce61f6d96"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "org.staff-role.get",
|
|
16
|
+
"kind": "atomic",
|
|
17
|
+
"risk": "read",
|
|
18
|
+
"availability": "available",
|
|
19
|
+
"at": "shop",
|
|
20
|
+
"module": "org/staff-role/get/command.js",
|
|
21
|
+
"fingerprint": "cfa719f5122449c0a57e5db59bfd760d17d717f95088c9d886586b53304a7041"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "org.unit.get",
|
|
25
|
+
"kind": "atomic",
|
|
26
|
+
"risk": "read",
|
|
27
|
+
"availability": "available",
|
|
28
|
+
"at": "all",
|
|
29
|
+
"module": "org/unit/get/command.js",
|
|
30
|
+
"fingerprint": "d11775de4f1c6d7500310c3f8b373bee7e829ab5afe586ae617037571b4d0597"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "org.unit.list",
|
|
34
|
+
"kind": "atomic",
|
|
35
|
+
"risk": "read",
|
|
36
|
+
"availability": "available",
|
|
37
|
+
"at": "hq",
|
|
38
|
+
"module": "org/unit/list/command.js",
|
|
39
|
+
"fingerprint": "6bee5cdcffb1893319280f50f9b49e752d16dbadcae5413bce3bbfcf476a9fc6"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { resolveTargetShop } = require('../../../../execution/target-shop');
|
|
4
|
+
const { readContext } = require('../../../../identity/context');
|
|
5
|
+
const { validateCommandValue } = require('../../../../execution/command-schema');
|
|
6
|
+
const { inputIssue, constraints, modelAt } = require('../../../../execution/error-details');
|
|
7
|
+
const { object } = require('../../../../execution/query-api');
|
|
8
|
+
const { createBoundShopQuery, failure, bindingPath } = require('../../../../execution/shop-query');
|
|
9
|
+
|
|
10
|
+
const staffPath = 'youzan.shop.single.staff.get/1.0.0';
|
|
11
|
+
|
|
12
|
+
function staffInput(options, context, command, schema) {
|
|
13
|
+
let scope;
|
|
14
|
+
try {
|
|
15
|
+
scope = resolveTargetShop(options, context, command);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error.cliDetails?.stage === 'validation') error.cliDetails.stage = 'input';
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
const state = readContext(context);
|
|
21
|
+
if (state.status === 'ready' && state.context.orgType !== 'shop') {
|
|
22
|
+
throw failure(command, 'permission', 'context', scope);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
if (typeof options.mobile !== 'string' || /[\x00-\x1f\x7f-\x9f]/.test(options.mobile)) {
|
|
26
|
+
throw inputIssue('/mobile', typeof options.mobile === 'string' ? 'invalid_format' : 'invalid_type',
|
|
27
|
+
constraints(modelAt(schema, 'input', '/mobile')));
|
|
28
|
+
}
|
|
29
|
+
const input = { ...scope, mobile: options.mobile.replace(/^ +| +$/g, '') };
|
|
30
|
+
if (schema.errors?.diagnosticsVersion === 2 && !/^1[0-9]{10}$/.test(input.mobile)) {
|
|
31
|
+
throw inputIssue('/mobile', 'invalid_format', {
|
|
32
|
+
...constraints(modelAt(schema, 'input', '/mobile')),
|
|
33
|
+
format: '员工登录账号的11位手机号,1开头且只含数字'
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
validateCommandValue(schema, 'input', input);
|
|
37
|
+
return input;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (schema.errors?.diagnosticsVersion === 2 && error.section === 'input') {
|
|
40
|
+
error.inputScope = scope;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
throw failure(command, 'parameter', 'input', scope);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function staffPreview(input) {
|
|
48
|
+
return { scope: { kdtId: input.kdtId }, requests: [
|
|
49
|
+
{ stage: 'shop-binding', method: 'POST', path: bindingPath, body: {} },
|
|
50
|
+
{ stage: 'staff', method: 'POST', path: staffPath, body: { account: '***' } }
|
|
51
|
+
] };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function readStaffModel(input, command, selectStaff, options) {
|
|
55
|
+
const scope = { kdtId: input.kdtId };
|
|
56
|
+
const { read, binding } = await createBoundShopQuery(scope, command, 'shop-binding', options);
|
|
57
|
+
if (!Number.isSafeInteger(binding.data.role) || binding.data.role < 0) {
|
|
58
|
+
throw failure(command, 'protocol', 'shop-binding', scope, 'sent', binding.facts);
|
|
59
|
+
}
|
|
60
|
+
if (binding.data.role !== 0) {
|
|
61
|
+
throw failure(command, 'permission', 'shop-binding', scope, 'sent', binding.facts);
|
|
62
|
+
}
|
|
63
|
+
const response = await read(staffPath, { account: input.mobile }, 'staff');
|
|
64
|
+
const staff = selectStaff(response.envelope);
|
|
65
|
+
const reject = (category, reason) => {
|
|
66
|
+
const error = failure(command, category, 'staff-model', scope, 'sent', response.facts);
|
|
67
|
+
error.diagnosticReason = reason;
|
|
68
|
+
return error;
|
|
69
|
+
};
|
|
70
|
+
if (!object(staff)) throw reject('protocol', 'staff_object_invalid');
|
|
71
|
+
if (!Number.isSafeInteger(staff.kdt_id) || staff.kdt_id < 1) {
|
|
72
|
+
throw reject('protocol', 'staff_shop_id_invalid');
|
|
73
|
+
}
|
|
74
|
+
if (staff.kdt_id !== input.kdtId) {
|
|
75
|
+
throw reject('scope_unresolved', 'staff_shop_mismatch');
|
|
76
|
+
}
|
|
77
|
+
return { staff, facts: response.facts, read };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function readSingleShopStaff(input, command) {
|
|
81
|
+
return readStaffModel(input, command, envelope => envelope.data);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function readSingleShopStaffIdentity(input, command, options) {
|
|
85
|
+
try {
|
|
86
|
+
return await readStaffModel(input, command, envelope => envelope.data, options);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error.cliDetails?.stage === 'staff' && error.cliDetails.category === 'business_rejected' &&
|
|
89
|
+
[error.cliDetails.businessCode, error.cliDetails.gatewayCode].some(code => String(code) === '232500001')) {
|
|
90
|
+
error.cliDetails.category = 'not_found';
|
|
91
|
+
error.message = '查询失败:not_found(staff)';
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function staffRoles(staff, command, facts) {
|
|
98
|
+
const reject = () => failure(command, 'protocol', 'staff-roles', { kdtId: staff.kdt_id }, 'sent', facts);
|
|
99
|
+
if (!Array.isArray(staff.roles)) throw reject();
|
|
100
|
+
return staff.roles.map(role => {
|
|
101
|
+
if (!object(role) || !Number.isSafeInteger(role.role_id) || role.role_id < 1 ||
|
|
102
|
+
typeof role.name !== 'string') throw reject();
|
|
103
|
+
return { roleId: role.role_id, name: role.name };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function redactStaffDiagnostics(error, mobile) {
|
|
108
|
+
for (const field of ['businessCode', 'gatewayCode', 'trace_id', 'request_id']) {
|
|
109
|
+
if (String(error.cliDetails?.[field]).includes(mobile)) delete error.cliDetails[field];
|
|
110
|
+
}
|
|
111
|
+
return error;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = { staffPath, staffInput, staffPreview, readSingleShopStaff, readSingleShopStaffIdentity,
|
|
115
|
+
staffRoles, redactStaffDiagnostics };
|