@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,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
4
|
+
const { constraints, modelAt } = require('../../../../../execution/error-details');
|
|
5
|
+
const { formatBeijingMilliseconds } = require('../../../../../execution/beijing-time');
|
|
6
|
+
const { object } = require('../../../../../execution/query-api');
|
|
7
|
+
const { createShopQuery, failure } = require('../../../../../execution/shop-query');
|
|
8
|
+
const schema = require('./schema.json');
|
|
9
|
+
|
|
10
|
+
const command = 'interaction.lottery.get';
|
|
11
|
+
const bindingBytes = 512 * 1024;
|
|
12
|
+
const responseBytes = 8 * 1024 * 1024;
|
|
13
|
+
const kinds = ['cards', 'wheel', 'zodiac', 'crazyguess', 'shake'];
|
|
14
|
+
const participationFields = {
|
|
15
|
+
requireFollow: 'is_need_follow', followValidationType: 'follow_validate_type',
|
|
16
|
+
filterUsers: 'is_filter_user', allowedTagIds: 'white_tags', allowedCardIds: 'white_cards',
|
|
17
|
+
costPoints: 'cost_points', givePoints: 'give_points', giveOnlyWhenNotWinning: 'is_only_give_no_prize',
|
|
18
|
+
limitType: 'limit_times_type', limitCount: 'limit_times_value',
|
|
19
|
+
shareLimit: 'limit_share_times_value', conditionType: 'join_condition_type'
|
|
20
|
+
};
|
|
21
|
+
const awardFields = {
|
|
22
|
+
awardId: 'id', name: 'award_name', type: 'award_type', imageUrl: 'image_url',
|
|
23
|
+
originName: 'origin_name', stockQuantity: 'total_amount', sourceRewardId: 'award_fetch',
|
|
24
|
+
position: 'award_sort', pointsValue: 'points_value', issuedCount: 'total_send_num',
|
|
25
|
+
probabilityPercent: 'winning_probability'
|
|
26
|
+
};
|
|
27
|
+
const slotFields = {
|
|
28
|
+
awardId: 'id', type: 'award_type', name: 'award_name', imageUrl: 'image_url',
|
|
29
|
+
originName: 'origin_name', position: 'position'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function pick(source, fields, path, invalid) {
|
|
33
|
+
if (!object(source)) throw invalid('protocol', path, source === undefined ? 'required' : 'invalid_type');
|
|
34
|
+
const result = {};
|
|
35
|
+
for (const [field, upstream] of Object.entries(fields)) {
|
|
36
|
+
if (Object.hasOwn(source, upstream)) result[field] = source[upstream];
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function projectArray(source, fields, path, invalid) {
|
|
42
|
+
if (!Array.isArray(source)) throw invalid('protocol', path, 'invalid_type');
|
|
43
|
+
return source.map((row, index) => pick(row, fields, `${path}/${index}`, invalid));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function projectLottery(data, input, facts = {}) {
|
|
47
|
+
const base = '/data/lottery';
|
|
48
|
+
const invalid = (category, path, reason = 'constraint', expected) => {
|
|
49
|
+
const error = failure(command, category, 'response', { kdtId: input.kdtId }, 'sent', facts);
|
|
50
|
+
if (path) error.issues = [{ source: 'output', path, reason,
|
|
51
|
+
expected: expected || constraints(modelAt(schema, 'output', path)) }];
|
|
52
|
+
return error;
|
|
53
|
+
};
|
|
54
|
+
if (!object(data)) throw invalid('protocol', base, data === undefined ? 'required' : 'invalid_type');
|
|
55
|
+
for (const [field, target] of [['id', 'activityId'], ['kdt_id', 'ownerKdtId']]) {
|
|
56
|
+
if (!Number.isSafeInteger(data[field]) || data[field] < 1) {
|
|
57
|
+
throw invalid('protocol', `${base}/${target}`, Object.hasOwn(data, field) ? 'constraint' : 'required');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (typeof data.app_name !== 'string' || !data.app_name.trim()) {
|
|
61
|
+
throw invalid('protocol', `${base}/kind`, !Object.hasOwn(data, 'app_name') ? 'required' :
|
|
62
|
+
typeof data.app_name === 'string' ? 'invalid_format' : 'invalid_type');
|
|
63
|
+
}
|
|
64
|
+
if (data.id !== input.activityId) throw invalid('scope_unresolved', `${base}/activityId`);
|
|
65
|
+
if (data.kdt_id !== input.kdtId) throw invalid('scope_unresolved', `${base}/ownerKdtId`);
|
|
66
|
+
if (!kinds.includes(data.app_name)) throw invalid('scope_unresolved', `${base}/kind`, 'invalid_choice');
|
|
67
|
+
try {
|
|
68
|
+
const lottery = pick(data, {
|
|
69
|
+
activityId: 'id', ownerKdtId: 'kdt_id', title: 'title', kind: 'app_name', alias: 'alias',
|
|
70
|
+
autoReplyEnabled: 'is_auto_reply'
|
|
71
|
+
}, base, invalid);
|
|
72
|
+
for (const [field, upstream] of [['startsAt', 'start_date'], ['endsAt', 'end_date']]) {
|
|
73
|
+
if (!Object.hasOwn(data, upstream)) continue;
|
|
74
|
+
try { lottery[field] = formatBeijingMilliseconds(data[upstream]); }
|
|
75
|
+
catch { throw invalid('protocol', `${base}/${field}`, 'invalid_format'); }
|
|
76
|
+
}
|
|
77
|
+
const participation = pick(data, participationFields, `${base}/participation`, invalid);
|
|
78
|
+
if (Object.keys(participation).length) lottery.participation = participation;
|
|
79
|
+
if (Object.hasOwn(data, 'winning_setting')) {
|
|
80
|
+
const source = data.winning_setting;
|
|
81
|
+
lottery.winning = pick(source, {
|
|
82
|
+
probabilityBasisPoints: 'winning_probability', noPrizeName: 'un_winning_name',
|
|
83
|
+
noPrizeText: 'un_winning_words', noPrizeImageUrl: 'un_winning_image_url',
|
|
84
|
+
jumpWhenNotWinning: 'is_un_winning_jump'
|
|
85
|
+
}, `${base}/winning`, invalid);
|
|
86
|
+
if (Object.hasOwn(source, 'un_winning_jump_url')) {
|
|
87
|
+
lottery.winning.noPrizeLink = pick(source.un_winning_jump_url, {
|
|
88
|
+
alias: 'alias', id: 'link_id', title: 'link_title', type: 'link_type', url: 'link_url'
|
|
89
|
+
}, `${base}/winning/noPrizeLink`, invalid);
|
|
90
|
+
}
|
|
91
|
+
if (Object.hasOwn(source, 'awards')) {
|
|
92
|
+
lottery.winning.awards = projectArray(source.awards, awardFields, `${base}/winning/awards`, invalid);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (Object.hasOwn(data, 'turntables')) {
|
|
96
|
+
lottery.wheelSlots = projectArray(data.turntables, slotFields, `${base}/wheelSlots`, invalid);
|
|
97
|
+
}
|
|
98
|
+
if (Object.hasOwn(data, 'view')) {
|
|
99
|
+
lottery.view = pick(data.view, { backgroundImageUrl: 'bg_image_url', description: 'description' }, `${base}/view`, invalid);
|
|
100
|
+
for (const [field, upstream] of [['showWinnerList', 'is_show_winner_list'], ['showLogo', 'is_show_logo_image']]) {
|
|
101
|
+
if (!Object.hasOwn(data.view, upstream)) continue;
|
|
102
|
+
if (![0, 1].includes(data.view[upstream])) throw invalid('protocol', `${base}/view/${field}`, 'invalid_choice',
|
|
103
|
+
{ type: 'integer', enum: [0, 1], format: '接口开关须为0或1,再转换为布尔值' });
|
|
104
|
+
lottery.view[field] = data.view[upstream] === 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (Object.hasOwn(data, 'auto_reply')) {
|
|
108
|
+
lottery.autoReply = pick(data.auto_reply, { content: 'content', ruleId: 'rule_id' }, `${base}/autoReply`, invalid);
|
|
109
|
+
if (Object.hasOwn(data.auto_reply, 'keywords')) {
|
|
110
|
+
lottery.autoReply.keywords = projectArray(data.auto_reply.keywords, { name: 'name', fullMatch: 'is_full_match' },
|
|
111
|
+
`${base}/autoReply/keywords`, invalid);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const output = { data: { lottery } };
|
|
115
|
+
validateCommandValue(schema, 'output', output);
|
|
116
|
+
return output;
|
|
117
|
+
} catch (cause) {
|
|
118
|
+
if (cause.cliDetails) throw cause;
|
|
119
|
+
const error = invalid('protocol');
|
|
120
|
+
if (cause.issues) error.issues = cause.issues;
|
|
121
|
+
if (cause.issuesTruncated) error.issuesTruncated = true;
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function executeLottery(input) {
|
|
127
|
+
const scope = { kdtId: input.kdtId };
|
|
128
|
+
let limit = bindingBytes;
|
|
129
|
+
let response;
|
|
130
|
+
try {
|
|
131
|
+
const read = await createShopQuery(scope, command, {
|
|
132
|
+
transportOptions: { maxResponseBytes: () => limit }
|
|
133
|
+
});
|
|
134
|
+
limit = responseBytes;
|
|
135
|
+
response = await read(schema.api.path, { activity_id: input.activityId }, 'query');
|
|
136
|
+
} catch (error) {
|
|
137
|
+
const details = error.cliDetails;
|
|
138
|
+
if (details?.category === 'limit' ||
|
|
139
|
+
(details?.category === 'business_rejected' && details.stage === 'query' &&
|
|
140
|
+
details.api === schema.api.path && !Object.hasOwn(details, 'gatewayCode') &&
|
|
141
|
+
[1605406001, '1605406001'].includes(details.businessCode))) {
|
|
142
|
+
const facts = Object.fromEntries(['api', 'httpStatus', 'businessCode', 'trace_id', 'request_id']
|
|
143
|
+
.filter(field => Object.hasOwn(details, field)).map(field => [field, details[field]]));
|
|
144
|
+
throw failure(command, details.category === 'limit' ? 'limit' : 'not_found',
|
|
145
|
+
details.category === 'limit' ? 'response' : 'query', scope, 'sent', facts);
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
return projectLottery(response.data, input, response.facts);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
module.exports = { projectLottery, executeLottery };
|