@tocca-systems/twp-cli 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.public.md +12 -0
- package/README.md +81 -7
- package/dist/{ai-dispatch-MFVPYNZ5.js → ai-dispatch-LY6OVZC3.js} +1 -1
- package/dist/{api-command-W77HSRUC.js → api-command-YUZFGC2W.js} +3 -3
- package/dist/{app-IVIYIONG.js → app-NIJ3MAGU.js} +4 -4
- package/dist/{backlog-OQ5JJ6F6.js → backlog-2VHFVU5C.js} +1 -1
- package/dist/chunk-523KROGI.js +3 -0
- package/dist/{chunk-5Q2CH4E7.js → chunk-6NEQ6PZZ.js} +1 -1
- package/dist/{chunk-YVAN3H5W.js → chunk-BUZKNZ45.js} +3 -3
- package/dist/chunk-DBIDYOKW.js +94 -0
- package/dist/{chunk-226G6ONZ.js → chunk-DCGL7XJF.js} +1 -1
- package/dist/{chunk-OK4ITT5Y.js → chunk-HAIZHSNZ.js} +1 -1
- package/dist/chunk-IF2K4PM5.js +20 -0
- package/dist/chunk-MQ3WFH54.js +141 -0
- package/dist/{chunk-KRTG6HSA.js → chunk-PLBOUQE7.js} +1 -1
- package/dist/{chunk-M364RN3O.js → chunk-R5HF6LTR.js} +15 -15
- package/dist/{chunk-EVR3OFVS.js → chunk-VECUCVIY.js} +8 -8
- package/dist/{chunk-P3RQICAS.js → chunk-VQMR5UTD.js} +1 -1
- package/dist/chunk-XNW2UNWQ.js +6 -0
- package/dist/cli.js +94 -9
- package/dist/{commands-45VQS3LX.js → commands-M4B3MDUA.js} +3 -3
- package/dist/{commands-7ZRA2BHR.js → commands-OABOHHNC.js} +2 -2
- package/dist/company-6HMFGVPJ.js +161 -0
- package/dist/{completion-EFIZU6YO.js → completion-DGJH42YO.js} +1 -1
- package/dist/{department-G4H75GGM.js → department-DH5YABBF.js} +1 -1
- package/dist/{inquiry-4SUKNVMY.js → inquiry-67OW3HBZ.js} +1 -1
- package/dist/{job-title-T3P3625A.js → job-title-YEIANJNC.js} +1 -1
- package/dist/{leave-7MXKEOQ2.js → leave-XXDCHUGK.js} +1 -1
- package/dist/{media-TZWSBMCP.js → media-NZD6J7KE.js} +4 -5
- package/dist/{notification-CA2LOXPS.js → notification-BQ4ODX6U.js} +1 -1
- package/dist/{oneshot-Y7P6SMY2.js → oneshot-GCQYYNIH.js} +1 -1
- package/dist/{position-GDOY4TFK.js → position-WR5YODDU.js} +1 -1
- package/dist/prospect-YZUHE7PL.js +107 -0
- package/dist/{registry-JYFK6PU7.js → registry-3O2KBG5I.js} +1 -1
- package/dist/{render-K45EOLHX.js → render-W523YEYF.js} +1 -1
- package/dist/report-SGAVGU4G.js +73 -0
- package/dist/{run-MH6LOFQS.js → run-WXHHCFT7.js} +2 -2
- package/dist/{sales-W2DV7FWL.js → sales-OFEVE2PG.js} +1 -1
- package/dist/{task-75VRLRYO.js → task-IE7DNU34.js} +2 -2
- package/dist/{user-VRIXQF5Q.js → user-UJIB3SCU.js} +1 -1
- package/dist/{workflow-OFA6XJOV.js → workflow-QWVZH4NG.js} +1 -1
- package/package.json +1 -1
- package/dist/chunk-4OKUCLIC.js +0 -3
- package/dist/chunk-CKGB7CLM.js +0 -6
- package/dist/chunk-FTYJZFEK.js +0 -10
- package/dist/chunk-RM4ECBIO.js +0 -80
- package/dist/company-E3VKXS75.js +0 -107
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{readCsvFileText}from"./chunk-I6DWJXPC.js";import{contentTypeFor,inspectLocalFile,issued}from"./chunk-VECUCVIY.js";import{checkUploadQuota}from"./chunk-DDKZ5IPT.js";import{featureLicenseGuidance}from"./chunk-PLBOUQE7.js";import{createFlags,fieldBody,hasAnyField,updateFlags}from"./chunk-DCGL7XJF.js";import{CUSTOMERS_PATH,SALES_COMPANIES_PATH,isExactNumericId}from"./chunk-DBIDYOKW.js";import{ApiError,errorListMessages}from"./chunk-IF2K4PM5.js";import{
|
|
4
|
+
isSafePathSegment}from"./chunk-GMBJTG6A.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-R53CMVWR.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import{acknowledgement,isRecord,pick}from"./chunk-ZWVYVS2A.js";import{ApiRejectedError,ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";import fs from"fs";import path from"path";function levelForbidden(licenseGuidance,levelGuidance){return body=>body?.error==="permission_denied"?licenseGuidance:levelGuidance}var COMPANY_LICENSE="\u53D6\u5F15\u5148\u3092\u6271\u3046\u306B\u306F\u8CA9\u58F2\u7BA1\u7406\u304B\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u8981\u308A\u307E\u3059\u304C\u3001\u3069\u3061\u3089\u3082\u3042\u308A\u307E\u305B\u3093\u3002\u30C6\u30CA\u30F3\u30C8\u304C\u3069\u3061\u3089\u3082\u5951\u7D04\u3057\u3066\u3044\u306A\u3044\u304B\u3001\u3042\u306A\u305F\u306E\u6A29\u9650\u304C\u3069\u3061\u3089\u3082\u300C\u306A\u3057\u300D\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002";
|
|
5
|
+
var CUSTOMER_LICENSE=featureLicenseGuidance("\u9867\u5BA2\u7BA1\u7406");var COMPANY_WRITE_FORBIDDEN=levelForbidden(COMPANY_LICENSE,"\u9867\u5BA2\u306E\u4F5C\u6210\u30FB\u66F4\u65B0\u306B\u306F\u3001\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u7DE8\u96C6\u8005\u300D\u4EE5\u4E0A\u304B\u3001\u8CA9\u58F2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u30E1\u30F3\u30D0\u30FC\u300D\u4EE5\u4E0A\u306E\u3069\u3061\u3089\u304B\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
|
|
6
|
+
var LEVEL_LABELS={admin:"\u7BA1\u7406\u8005",editor:"\u7DE8\u96C6\u8005",viewer:"\u95B2\u89A7\u8005",none:"\u306A\u3057"};var CHILD_DELETE_NEEDS="\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u306E\u524A\u9664\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u7BA1\u7406\u8005\u300D\u3067\u3042\u308B\u3053\u3068\u304C\u8981\u308A\u307E\u3059";var CUSTOMER_DELETE_FORBIDDEN=levelForbidden(COMPANY_LICENSE,"\u9867\u5BA2\u306E\u524A\u9664\u306B\u306F\u3001\u4F01\u696D\u306E\u524A\u9664\u306B\u9867\u5BA2\u7BA1\u7406\u306E\u300C\u7BA1\u7406\u8005\u300D\u304B\u8CA9\u58F2\u7BA1\u7406\u306E\u300C\u30E1\u30F3\u30D0\u30FC\u300D\u4EE5\u4E0A\u3001\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u306E\u524A\u9664\u306B\u9867\u5BA2\u7BA1\u7406\u306E\u300C\u7BA1\u7406\u8005\u300D\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\
|
|
7
|
+
\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002");var CUSTOMER_UPDATE_FORBIDDEN=levelForbidden(CUSTOMER_LICENSE,"\u9867\u5BA2\u306E\u66F4\u65B0\u306B\u306F\u3001\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u7DE8\u96C6\u8005\u300D\u4EE5\u4E0A\u304B\u3001\u8CA9\u58F2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u30E1\u30F3\u30D0\u30FC\u300D\u4EE5\u4E0A\u306E\u3069\u3061\u3089\u304B\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
|
|
8
|
+
function childForbidden(label,write){return levelForbidden(CUSTOMER_LICENSE,write==="edit"?`${label}\u306E\u4F5C\u6210\u30FB\u66F4\u65B0\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u7DE8\u96C6\u8005\u300D\u4EE5\u4E0A\u3067\u3042\u308B\u3053\u3068\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`:`${label}\u306E\u524A\u9664\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u7BA1\u7406\u8005\u300D\u3067\u3042\u308B\u3053\u3068\u304C\u8981\u308A\u307E\u3059\uFF08\u300C\u7DE8\u96C6\u8005\u300D\u3067\u306F\u524A\u9664\u3067\u304D\u307E\u305B\u3093\uFF09\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}
|
|
9
|
+
var NO_LIMIT=Number.POSITIVE_INFINITY;var COMPANY_FIELDS=[{kind:"text",flag:"--name",key:"company_name",label:"\u4F01\u696D\u540D",maxChars:255,summary:"\u4F01\u696D\u540D\uFF08create \u3067\u306F\u5FC5\u9808\uFF09"},{kind:"text",flag:"--kana",key:"company_name_kana",label:"\u30D5\u30EA\u30AC\u30CA",maxChars:255,summary:"\u4F01\u696D\u540D\u306E\u30D5\u30EA\u30AC\u30CA"},{kind:"text",flag:"--short-name",key:"company_short_name",label:"\u7565\u79F0",maxChars:100,summary:"\u7565\u79F0"},{kind:"tex\
|
|
10
|
+
t",flag:"--company-no",key:"company_no",label:"\u6CD5\u4EBA\u756A\u53F7",maxChars:20,summary:"\u6CD5\u4EBA\u756A\u53F7"},{kind:"text",flag:"--post-code",key:"post_code",label:"\u90F5\u4FBF\u756A\u53F7",maxChars:10,summary:"\u90F5\u4FBF\u756A\u53F7"},{kind:"text",flag:"--address1",key:"address1",label:"\u4F4F\u62401",maxChars:255,summary:"\u4F4F\u62401\uFF08\u90FD\u9053\u5E9C\u770C\u30FB\u5E02\u533A\u753A\u6751\uFF09"},{kind:"text",flag:"--address2",key:"address2",label:"\u4F4F\u62402",maxChars:255,
|
|
11
|
+
summary:"\u4F4F\u62402\uFF08\u756A\u5730\uFF09"},{kind:"text",flag:"--address3",key:"address3",label:"\u4F4F\u62403",maxChars:255,summary:"\u4F4F\u62403\uFF08\u5EFA\u7269\u540D\uFF09"},{kind:"text",flag:"--tel",key:"tel",label:"\u96FB\u8A71\u756A\u53F7",maxChars:20,summary:"\u96FB\u8A71\u756A\u53F7"},{kind:"text",flag:"--fax",key:"fax",label:"FAX",maxChars:20,summary:"FAX \u756A\u53F7"},{kind:"text",flag:"--industry",key:"industry",label:"\u696D\u7A2E",maxChars:100,summary:"\u696D\u7A2E"},{kind:"\
|
|
12
|
+
text",flag:"--website",key:"website",label:"Web \u30B5\u30A4\u30C8",maxChars:255,summary:"Web \u30B5\u30A4\u30C8\u306E URL"},{kind:"text",flag:"--memo",key:"memo",label:"\u30E1\u30E2",maxChars:NO_LIMIT,summary:"\u30E1\u30E2"},{kind:"boolean",flag:"--supplier",key:"supplier_flg",summary:"\u4ED5\u5165\u5148\uFF08\u8ABF\u9054\u5148\uFF09\u3068\u3057\u3066\u3082\u767B\u9332\u3059\u308B\u304B\uFF08true / false\uFF09"}];var CONTACT_FIELDS=[{kind:"text",flag:"--name",key:"name",label:"\u6C0F\u540D",maxChars:255,
|
|
13
|
+
summary:"\u6C0F\u540D\uFF08create \u3067\u306F\u5FC5\u9808\uFF09"},{kind:"text",flag:"--kana",key:"name_kana",label:"\u30D5\u30EA\u30AC\u30CA",maxChars:255,summary:"\u6C0F\u540D\u306E\u30D5\u30EA\u30AC\u30CA"},{kind:"text",flag:"--department",key:"department",label:"\u90E8\u7F72",maxChars:255,summary:"\u90E8\u7F72"},{kind:"text",flag:"--position",key:"position",label:"\u5F79\u8077",maxChars:255,summary:"\u5F79\u8077"},{kind:"text",flag:"--role",key:"role_label",label:"\u5F79\u5272",maxChars:255,
|
|
14
|
+
summary:"\u5F79\u5272\uFF08\u6C7A\u88C1\u8005\u30FB\u7A93\u53E3 \u306A\u3069\uFF09"},{kind:"text",flag:"--email",key:"email",label:"\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9",maxChars:255,summary:"\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9"},{kind:"text",flag:"--phone",key:"phone",label:"\u96FB\u8A71\u756A\u53F7",maxChars:50,summary:"\u96FB\u8A71\u756A\u53F7"},{kind:"text",flag:"--mobile",key:"mobile",label:"\u643A\u5E2F\u96FB\u8A71",maxChars:50,summary:"\u643A\u5E2F\u96FB\u8A71\u306E\u756A\u53F7"},
|
|
15
|
+
{kind:"boolean",flag:"--primary",key:"is_primary",summary:"\u4E3B\u62C5\u5F53\u306B\u3059\u308B\u304B\uFF08true / false\uFF09"},{kind:"text",flag:"--notes",key:"notes",label:"\u30E1\u30E2",maxChars:1e4,summary:"\u30E1\u30E2"}];var INTERACTION_TYPES=["call","email","visit","web_meeting","other"];var INTERACTION_STATUSES=["appointment","meeting","meeting_completed","proposing","proposal_accepted","communication","thanks_mail_sent"];var INTERACTION_FIELDS=[{kind:"enum",flag:"--type",key:"interactio\
|
|
16
|
+
n_type",values:INTERACTION_TYPES,summary:`\u5BFE\u5FDC\u306E\u7A2E\u5225\uFF08${INTERACTION_TYPES.join(" / ")}\u30FBcreate \u3067\u306F\u5FC5\u9808\uFF09`},{kind:"text",flag:"--date",key:"interaction_date",label:"\u5BFE\u5FDC\u65E5",maxChars:NO_LIMIT,summary:"\u5BFE\u5FDC\u65E5\uFF08\u4F8B 2026-09-29\u30FBcreate \u3067\u306F\u5FC5\u9808\uFF09"},{kind:"enum",flag:"--status",key:"status",values:INTERACTION_STATUSES,summary:`\u72B6\u6CC1\uFF08${INTERACTION_STATUSES.join(" / ")}\uFF09`},{kind:"text",
|
|
17
|
+
flag:"--subject",key:"subject",label:"\u4EF6\u540D",maxChars:255,summary:"\u4EF6\u540D"},{kind:"text",flag:"--content",key:"content",label:"\u5185\u5BB9",maxChars:5e4,summary:"\u5185\u5BB9"},{kind:"text",flag:"--contact",key:"contact_id",label:"\u62C5\u5F53\u8005 ID",maxChars:255,summary:"\u5BFE\u5FDC\u3057\u305F\u76F8\u624B\u306E\u62C5\u5F53\u8005 ID\uFF08twp customer contact list \u306E id \u5217\uFF09"},{kind:"text",flag:"--next-action",key:"next_action",label:"\u6B21\u306E\u30A2\u30AF\u30B7\u30E7\u30F3",
|
|
18
|
+
maxChars:1e3,summary:"\u6B21\u306E\u30A2\u30AF\u30B7\u30E7\u30F3"},{kind:"text",flag:"--next-action-date",key:"next_action_date",label:"\u6B21\u306E\u30A2\u30AF\u30B7\u30E7\u30F3\u306E\u65E5\u4ED8",maxChars:NO_LIMIT,summary:"\u6B21\u306E\u30A2\u30AF\u30B7\u30E7\u30F3\u306E\u65E5\u4ED8"}];function dataOf(body,what){const data=isRecord(body)?body["data"]:void 0;if(!isRecord(body)||body["result"]!==true||!isRecord(data)||typeof data["id"]!=="string"&&typeof data["id"]!=="number"){throw new ApiResponseError(
|
|
19
|
+
`${what}\u306E\u5FDC\u7B54\u306B data.id \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}return data}var COMPANY_COLUMNS=["id","company_name","company_name_kana","company_short_name","customer_flg","supplier_flg","tel","address1"];var CONTACT_COLUMNS=["id","company_id","name","department","position","email","phone","is_primary"];var INTERACTION_COLUMNS=["id","company_id","interaction_type","interaction_date","status","sub\
|
|
20
|
+
ject","contact_id"];var RECENT_COLUMNS=["id","target_type","company_id","prospect_id","interaction_type","interaction_date","status","subject"];var CONTACT_GET_COLUMNS=[...CONTACT_COLUMNS,"name_kana","role_label","mobile","is_customer","notes","updated_at"];var INTERACTION_GET_COLUMNS=[...INTERACTION_COLUMNS,"content","next_action","next_action_date","user_name","updated_at"];async function resolveCustomer(ctx,raw,flag){return(await ctx.resolver.company(raw,{flag,source:"customer",mustExist:true})).
|
|
21
|
+
id}function companyPath(input){const id=requireResolved(input,"companyId");if(!isExactNumericId(id))throw new ApiResponseError(`\u30B5\u30FC\u30D0\u304C\u8FD4\u3057\u305F\u53D6\u5F15\u5148 ID \u3092\u30D1\u30B9\u306B\u4F7F\u3048\u307E\u305B\u3093: ${id}\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);return`${SALES_COMPANIES_PATH}/${id}`}function childBase(companyId,kind){if(!isExactNumericId(companyId))throw new ApiResponseError(`\u53D6\u5F15\u5148 ID \u3092\u30D1\u30B9\u306B\u4F7F\u3048\u307E\u305B\u3093: ${companyId}\
|
|
22
|
+
\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);return`${CUSTOMERS_PATH}/${companyId}/${kind}`}var REF_HELP="<\u9867\u5BA2> \u306F\u4F01\u696D\u540D\u30FB\u7565\u79F0\u30FB\u30AB\u30CA\u306E\u5B8C\u5168\u4E00\u81F4\u304B ID\uFF08twp customer list \u306E id \u5217\u306E\u6570\u5B57\uFF09\u3067\u6307\u5B9A\u3057\u307E\u3059\u3002\n\u4ED5\u5165\u5148\u3060\u3051\u306E\u53D6\u5F15\u5148\u306F\u9867\u5BA2\u3068\u3057\u3066\u6271\u308F\u306A\u3044\u306E\u3067\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\uFF08twp company list \u3067\u898B\u3048\u307E\u3059\uFF09\u3002";
|
|
23
|
+
var createOperation={name:"create",summary:"\u9867\u5BA2\uFF08\u53D6\u5F15\u5148\u4F01\u696D\uFF09\u3092\u767B\u9332\u3059\u308B",usage:"twp customer create --name <\u4F01\u696D\u540D> [\u9805\u76EE\u2026]",description:"\u53D6\u5F15\u5148\u4F01\u696D\u3092\u300C\u9867\u5BA2\u300D\u3068\u3057\u3066\u767B\u9332\u3057\u307E\u3059\uFF08customer_flg \u3092\u7ACB\u3066\u3066\u4F5C\u6210\u3057\u307E\u3059\uFF09\u3002--name \u304C\u5FC5\u9808\u3067\u3059\u3002\n--supplier true \u3092\u4ED8\u3051\u308B\u3068\u4ED5\u5165\u5148\uFF08\u8ABF\u9054\u5148\uFF09\u3068\u3057\u3066\u3082\u767B\u9332\u3057\u307E\u3059\u3002\n\n\u4F5C\u6210\u3057\u305F\u9867\u5BA2\u306E ID \u304C\u8FD4\u308A\u307E\u3059\u3002\u62C5\u5F53\u8005\u306F twp customer contact create \u3067\u8DB3\u3057\u307E\u3059\u3002",
|
|
24
|
+
forbidden:COMPANY_WRITE_FORBIDDEN,flags:createFlags(COMPANY_FIELDS),plan(input){if(input.args.length>0)throw new UsageError(`create \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,"twp customer create help");const body=fieldBody(input,COMPANY_FIELDS);if(body["company_name"]===void 0)throw new UsageError("--name \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","twp customer create help");return{method:"POST",path:SALES_COMPANIES_PATH,body:{...body,
|
|
25
|
+
customer_flg:true}}},summarize:body=>pick(dataOf(body,"\u9867\u5BA2\u306E\u767B\u9332"),COMPANY_COLUMNS),raw:body=>dataOf(body,"\u9867\u5BA2\u306E\u767B\u9332")};var updateOperation={name:"update",summary:"\u9867\u5BA2\uFF08\u53D6\u5F15\u5148\u4F01\u696D\uFF09\u306E\u9805\u76EE\u3092\u66F4\u65B0\u3059\u308B",usage:"twp customer update <\u9867\u5BA2> [\u9805\u76EE\u2026]",description:`\u6307\u5B9A\u3057\u305F\u9805\u76EE\u3060\u3051\u3092\u5909\u66F4\u3057\u307E\u3059\uFF08\u6307\u5B9A\u3057\u306A\u304B\u3063\u305F\u9805\u76EE\u306F\u5909\u308F\u308A\u307E\u305B\u3093\uFF09\u3002\u5909\u66F4\u3059\u308B\u9805\u76EE\u30921\u3064\u3082\u6307\u5B9A\u3057\u306A\u3044\u3068\u30A8\u30E9\u30FC\u306B\u306A\u308A\u307E\u3059\u3002
|
|
26
|
+
|
|
27
|
+
${REF_HELP}`,forbidden:CUSTOMER_UPDATE_FORBIDDEN,flags:updateFlags(COMPANY_FIELDS),async prepare(input,ctx){if(!hasAnyField(input,COMPANY_FIELDS))throw new UsageError("\u5909\u66F4\u3059\u308B\u9805\u76EE\u30921\u3064\u4EE5\u4E0A\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","twp customer update help");fieldBody(input,COMPANY_FIELDS);const raw=singleRef(input,{flag:"<\u9867\u5BA2>",label:"\u9867\u5BA2",usage:"twp customer update help"});return withResolved(input,{companyId:await resolveCustomer(
|
|
28
|
+
ctx,raw,"<\u9867\u5BA2>")})},plan:input=>({method:"PUT",path:companyPath(input),body:fieldBody(input,COMPANY_FIELDS)}),summarize:body=>pick(dataOf(body,"\u9867\u5BA2\u306E\u66F4\u65B0"),COMPANY_COLUMNS),raw:body=>dataOf(body,"\u9867\u5BA2\u306E\u66F4\u65B0")};var DELETE_FILE_MAX_BYTES=1024*1024;var CHILD_PAGE_LIMIT=100;var FILE_FLAG={name:"--file",summary:"\u524A\u9664\u3059\u308B\u9867\u5BA2\u306E ID \u30921\u884C\u306B1\u3064\u66F8\u3044\u305F\u30D5\u30A1\u30A4\u30EB",takesValue:true,placeholder:"\
|
|
29
|
+
<\u30D5\u30A1\u30A4\u30EB>"};function parseDeleteIds(text){const ids=[];const errors=[];const seen=new Map;text.split(/\r?\n/).forEach((raw,index)=>{const line=index+1;const value=raw.trim();if(value===""||value.startsWith("#"))return;if(!isExactNumericId(value)){errors.push(`${line} \u884C\u76EE: \u9867\u5BA2\u306E ID\uFF08\u5148\u982D\u306B 0 \u3092\u4ED8\u3051\u306A\u3044\u6570\u5B57\uFF09\u3067\u306F\u3042\u308A\u307E\u305B\u3093: ${value}`);return}const first=seen.get(value);if(first!==void 0){
|
|
30
|
+
errors.push(`${line} \u884C\u76EE: ID ${value} \u306F ${first} \u884C\u76EE\u3068\u91CD\u8907\u3057\u3066\u3044\u307E\u3059`);return}seen.set(value,line);ids.push({line,id:value})});return{ids,errors}}function flagIsCustomer(value){return value===true||value===1}async function inspectTarget(ctx,id,line){const record=await ctx.resolver.companyRecord(id);if(record!==null&&!flagIsCustomer(record["customer_flg"])){throw new UsageError(`ID ${id}\uFF08${String(record["company_name"]??"")}\uFF09\u306F\u9867\u5BA2\u3067\u306F\u306A\u3044\uFF08\u4ED5\u5165\u5148\u3060\
|
|
31
|
+
\u3051\u306E\uFF09\u53D6\u5F15\u5148\u3067\u3059\u3002twp customer delete \u3067\u306F\u524A\u9664\u3057\u307E\u305B\u3093`)}const contacts=await ctx.resolver.customerChildren(id,"contacts");const interactions=await ctx.resolver.customerChildren(id,"interactions");return{line,id,exists:record!==null,name:record===null?null:String(record["company_name"]??""),supplier:record!==null&&flagIsCustomer(record["supplier_flg"]),contactIds:contacts.map(row=>String(row["id"])),interactionCount:interactions.
|
|
32
|
+
length}}async function prepareDelete(input,ctx){const usage="twp customer delete help";const file=input.flags.get(FILE_FLAG.name);if(file===void 0){const raw=singleRef(input,{flag:"<\u9867\u5BA2>",label:"\u9867\u5BA2",usage});const id=isExactNumericId(raw.trim())?raw.trim():await resolveCustomer(ctx,raw,"<\u9867\u5BA2>");const target=await inspectTarget(ctx,id,null);if(!target.exists&&target.contactIds.length===0&&target.interactionCount===0){throw new UsageError(`ID ${id} \u306E\u9867\u5BA2\u306F\u3042\u308A\u307E\u305B\u3093\uFF08\u524A\u9664\u6E08\u307F\u3067\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\
|
|
33
|
+
\u6B74\u3082\u6B8B\u3063\u3066\u3044\u306A\u3044\u304B\u3001\u5B58\u5728\u3057\u306A\u3044 ID \u3067\u3059\uFF09`,"twp customer list \u3067 ID \u3092\u78BA\u304B\u3081\u3066\u304F\u3060\u3055\u3044\u3002")}return withTargets(input,ctx,[target])}if(input.args.length>0)throw new UsageError(`--file \u306E\u3068\u304D\u306F\u9867\u5BA2\u3092\u4F4D\u7F6E\u5F15\u6570\u3067\u53D7\u3051\u307E\u305B\u3093: ${input.args.join(" ")}`,usage);if(file.trim()==="")throw new UsageError("--file <\u30D5\u30A1\u30A4\u30EB> \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
34
|
+
usage);const text=readCsvFileText(file,usage,DELETE_FILE_MAX_BYTES,size=>new UsageError(`--file \u306E\u30D5\u30A1\u30A4\u30EB\u304C\u5927\u304D\u3059\u304E\u307E\u3059\uFF08${size} \u30D0\u30A4\u30C8\u30FB\u4E0A\u9650 ${DELETE_FILE_MAX_BYTES} \u30D0\u30A4\u30C8\uFF09: ${file}`,"\u30D5\u30A1\u30A4\u30EB\u3092\u5206\u3051\u3066\u6253\u3063\u3066\u304F\u3060\u3055\u3044\u3002"));const parsed=parseDeleteIds(text);const errors=parsed.errors.map(text2=>({line:Number(text2.split(" ")[0]),text:text2}));
|
|
35
|
+
const targets=[];for(const{line,id}of parsed.ids){try{targets.push(await inspectTarget(ctx,id,line))}catch(err){if(!(err instanceof UsageError))throw err;errors.push({line,text:`${line} \u884C\u76EE: ${err.message}`})}}if(errors.length>0){errors.sort((a,b)=>a.line-b.line);throw new UsageError(`\u30D5\u30A1\u30A4\u30EB\u306B\u524A\u9664\u3067\u304D\u306A\u3044\u884C\u304C ${errors.length} \u884C\u3042\u308B\u305F\u3081\u30011\u4EF6\u3082\u524A\u9664\u3057\u3066\u3044\u307E\u305B\u3093:
|
|
36
|
+
${errors.map(e=>e.text).join("\n ")}`,`\u6B63\u3057\u3044\u884C\u306F ${targets.length} \u884C\u3067\u3059\u3002\u305D\u306E\u884C\u3092\u76F4\u3059\u304B\u524A\u9664\u3057\u3066\u304B\u3089\u6253\u3061\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}if(targets.length===0)throw new UsageError(`\u30D5\u30A1\u30A4\u30EB\u306B\u9867\u5BA2\u306E ID \u304C\u3042\u308A\u307E\u305B\u3093: ${file}`,usage);return withTargets(input,ctx,targets)}async function withTargets(input,ctx,targets){const children=targets.
|
|
37
|
+
reduce((n,t)=>n+t.contactIds.length+(t.exists?0:t.interactionCount),0);let blocked="";if(children>0){const{isAdmin,level}=await ctx.resolver.featureLevel("customer");if(!isAdmin&&level!=="admin"){blocked=`${CHILD_DELETE_NEEDS}\uFF08\u3042\u306A\u305F\u306E\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650: ${LEVEL_LABELS[level??""]??level??"\u4E0D\u660E"}\uFF09\u3002\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u304C ${children} \u4EF6\u3042\u308B\u305F\u3081\u3001\u59CB\u3081\u308B\u3068\u4F01\u696D\u3060\u3051\u304C\u6D88\u3048\u3066\u62C5\u5F53\u8005\u304C\u6B8B\u308A\u307E\u3059\u30021\u4EF6\u3082\u9001\u3063\u3066\u3044\u307E\u305B\u3093\u3002`}}
|
|
38
|
+
return withResolved(input,{targets:JSON.stringify(targets),childDeleteBlocked:blocked})}function deleteTargets(input){return JSON.parse(requireResolved(input,"targets"))}function contactPath(companyId,contactId){if(!isSafePathSegment(contactId))throw new ApiResponseError(`\u30B5\u30FC\u30D0\u304C\u8FD4\u3057\u305F\u62C5\u5F53\u8005 ID \u3092\u30D1\u30B9\u306B\u4F7F\u3048\u307E\u305B\u3093: ${contactId}\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);return`${childBase(
|
|
39
|
+
companyId,"contacts")}/${encodeURIComponent(contactId)}`}function firstDeletePlan(targets){for(const target of targets){if(target.exists)return{method:"DELETE",path:`${SALES_COMPANIES_PATH}/${target.id}`};const[contactId]=target.contactIds;if(contactId!==void 0)return{method:"DELETE",path:contactPath(target.id,contactId)}}return{method:"GET",path:`${SALES_COMPANIES_PATH}/${targets[0].id}`}}function targetLabel(target){const where=target.line===null?"":`${target.line} \u884C\u76EE `;return`${where}\
|
|
40
|
+
ID ${target.id}${target.name===null?"\uFF08\u4F01\u696D\u306F\u524A\u9664\u6E08\u307F\u30FB\u307E\u305F\u306F\u5B58\u5728\u3057\u306A\u3044 ID\uFF09":` ${target.name}`}`}function deletePlannedNotes(input){const targets=deleteTargets(input);const companies=targets.filter(t=>t.exists).length;const contacts=targets.reduce((n,t)=>n+t.contactIds.length,0);const interactions=targets.reduce((n,t)=>n+t.interactionCount,0);const lines=[`\u524A\u9664\u306E\u4E0B\u898B: \u4F01\u696D ${companies} \u793E\u30FB\u62C5\u5F53\u8005 ${contacts}\
|
|
41
|
+
\u4EF6\u30FB\u5BFE\u5FDC\u5C65\u6B74 ${interactions} \u4EF6\uFF08${targets.length} \u4EF6\u306E\u6307\u5B9A\uFF09`];for(const target of targets){const supplier=target.supplier?"\u30FB\u4ED5\u5165\u5148\u3068\u3057\u3066\u3082\u767B\u9332\u3055\u308C\u3066\u3044\u307E\u3059\uFF08\u524A\u9664\u3059\u308B\u3068\u4ED5\u5165\u5148\u3068\u3057\u3066\u3082\u6D88\u3048\u307E\u3059\uFF09":"";lines.push(` ${targetLabel(target)}: \u62C5\u5F53\u8005 ${target.contactIds.length} \u4EF6\u30FB\u5BFE\u5FDC\u5C65\u6B74 ${target.
|
|
42
|
+
interactionCount} \u4EF6${supplier}`)}const blocked=input.resolved?.["childDeleteBlocked"];if(blocked!==void 0&&blocked!=="")lines.push(`\u3053\u306E\u6A29\u9650\u3067\u306F\u5B9F\u884C\u3067\u304D\u307E\u305B\u3093: ${blocked}`);if(companies+contacts+interactions===0){lines.push("\u524A\u9664\u3059\u308B\u3082\u306E\u306F\u6B8B\u3063\u3066\u3044\u307E\u305B\u3093\uFF08\u9001\u308B\u306E\u306F\u78BA\u8A8D\u306E GET \u3060\u3051\u3067\u3059\uFF09\u3002");return lines}lines.push("\u4F01\u696D\u3054\u3068\u306B\u300C\u4F01\u696D\u306E\u8AAD\u307F\u76F4\u3057\uFF08\u9867\u5BA2\u306E\
|
|
43
|
+
\u307E\u307E\u304B\uFF09\u2192 \u4F01\u696D\u306E\u524A\u9664 \u2192 \u62C5\u5F53\u8005\u306E\u524A\u9664 \u2192 \u5BFE\u5FDC\u5C65\u6B74\u304C\u6B8B\u3063\u3066\u3044\u306A\u3044\u304B\u306E\u78BA\u8A8D\u300D\u306E\u9806\u3067\u9001\u308A\u307E\u3059\uFF08\u5BFE\u5FDC\u5C65\u6B74\u306F\u4F01\u696D\u306E\u524A\u9664\u3067\u30B5\u30FC\u30D0\u304C\u9023\u9396\u3057\u3066\u6D88\u3057\u307E\u3059\uFF09\u3002","\u898B\u7A4D\u30FB\u8ACB\u6C42\u66F8\u30FB\u6848\u4EF6\u66F8\u985E\u30FB\u5951\u7D04\u66F8\u30FB\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u7B49\u304B\u3089\u53C2\u7167\u3055\u308C\u3066\u3044\u308B\u4F01\u696D\u306F\u30B5\u30FC\u30D0\u304C\u524A\u9664\u3092\u65AD\u308A\u307E\u3059\u3002\u305D\u306E\u3068\u304D\u306F\u305D\u306E\u4F01\u696D\u3067\u306F\u4F55\u3082\u524A\u9664\u305B\u305A\u3001\u305D\u3053\u3067\u6B62\u3081\u307E\u3059\uFF08\u4F7F\u7528\u4E2D\u304B\u3069\u3046\u304B\u306F\u30B5\u30FC\u30D0\u304C\u5224\u5B9A\u3059\u308B\u306E\
|
|
44
|
+
\u3067\u3001\u3053\u306E\u4E0B\u898B\u306B\u306F\u51FA\u307E\u305B\u3093\uFF09\u3002","\u9014\u4E2D\u3067\u6B62\u307E\u3063\u305F\u3089\u3001\u6D88\u3048\u305F\u3082\u306E\u30FB\u6B8B\u3063\u305F\u3082\u306E\u3092\u51FA\u3057\u307E\u3059\u3002\u539F\u56E0\u3092\u53D6\u308A\u9664\u3044\u3066\u540C\u3058\u30B3\u30DE\u30F3\u30C9\u3092\u6253\u3061\u76F4\u3059\u3068\u3001\u524A\u9664\u6E08\u307F\u306E\u4F01\u696D\u306F\u6B8B\u308A\u3060\u3051\u3092\u6D88\u3057\u307E\u3059\u3002");lines.push("--dry-ru\
|
|
45
|
+
n \u304C\u8868\u793A\u3059\u308B\u8981\u6C42\u306F\u3001\u6700\u521D\u306B\u72B6\u614B\u3092\u5909\u3048\u308B1\u4EF6\u3067\u3059\uFF08\u305D\u306E\u524D\u306B\u4F01\u696D\u3092\u8AAD\u307F\u76F4\u3059 GET \u3092\u9001\u308A\u307E\u3059\uFF09\u3002");return lines}function isDeleteBody(body){return isRecord(body)&&body["customerDelete"]===true&&Array.isArray(body["done"])}function rejectionReason(err){if(!(err instanceof ApiError))return err.message;const list=err.body?.error_list;const first=Array.
|
|
46
|
+
isArray(list)?list[0]:void 0;const message=isRecord(first)?first["message"]:void 0;if(typeof message==="string"&&message!=="")return message;return errorListMessages(list)[0]??err.body?.error_description??err.body?.message??err.message}var DeleteStopped=class extends Error{constructor(reason,companyDeleted,contactsDeleted,interactionsDeleted){super("stopped");this.reason=reason;this.companyDeleted=companyDeleted;this.contactsDeleted=contactsDeleted;this.interactionsDeleted=interactionsDeleted}reason;companyDeleted;contactsDeleted;interactionsDeleted};
|
|
47
|
+
async function listAllChildren(ctx,companyId,kind){const label=kind==="contacts"?"\u62C5\u5F53\u8005":"\u5BFE\u5FDC\u5C65\u6B74";const ids=[];const seenCursors=new Set;let cursor;for(;;){const body=await ctx.send({method:"GET",path:childBase(companyId,kind),query:{limit:CHILD_PAGE_LIMIT,cursor}});const items=isRecord(body)?body["items"]:void 0;if(!Array.isArray(items))throw new ApiResponseError(`${label}\u4E00\u89A7\u306E\u5FDC\u7B54\u306B items \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);
|
|
48
|
+
for(const row of items){const id=isRecord(row)?row["id"]:void 0;if(typeof id!=="string"||!isSafePathSegment(id)){throw new ApiResponseError(`\u30B5\u30FC\u30D0\u304C\u8FD4\u3057\u305F${label} ID \u3092\u30D1\u30B9\u306B\u4F7F\u3048\u307E\u305B\u3093: ${String(id)}\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}ids.push(id)}const hasMore=isRecord(body)?body["has_more"]:void 0;const next=isRecord(body)?body["next_cursor"]:void 0;if(hasMore===false)return ids;
|
|
49
|
+
if(hasMore!==true||typeof next!=="string"||next===""||seenCursors.has(next)){throw new ApiResponseError(`${label}\u4E00\u89A7\u306E\u5FDC\u7B54\u306E has_more / next_cursor \u304C\u8AAD\u3081\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}seenCursors.add(next);cursor=next}}async function drain(ctx,companyId,kind,onDeleted){const label=kind==="contacts"?"\u62C5\u5F53\u8005":"\u5BFE\u5FDC\u5C65\u6B74";const gone=new Set;for(;;){const listed=await listAllChildren(
|
|
50
|
+
ctx,companyId,kind);const fresh=listed.filter(id=>!gone.has(id));if(fresh.length===0){for(const id of listed){try{await ctx.send({method:"GET",path:`${childBase(companyId,kind)}/${encodeURIComponent(id)}`})}catch(err){if(err instanceof ApiError&&err.status===404)continue;throw err}throw new ApiResponseError(`\u524A\u9664\u3092\u53D7\u3051\u4ED8\u3051\u305F${label}\uFF08ID ${id}\uFF09\u304C\u307E\u3060\u6B8B\u3063\u3066\u3044\u307E\u3059\u3002\u6642\u9593\u3092\u7F6E\u3044\u3066\u540C\u3058\u30B3\u30DE\u30F3\u30C9\u3092\u6253\u3061\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}
|
|
51
|
+
return}for(const id of fresh){try{await ctx.send({method:"DELETE",path:`${childBase(companyId,kind)}/${encodeURIComponent(id)}`});onDeleted()}catch(err){if(!(err instanceof ApiError)||err.status!==404)throw err}gone.add(id)}}}function rejectedBeforeWrite(err){return err instanceof ApiError&&[401,403,422].includes(err.status)}async function companyNow(ctx,id){try{const body=await ctx.send({method:"GET",path:`${SALES_COMPANIES_PATH}/${id}`});return dataOf(body,"\u53D6\u5F15\u5148")}catch(err){if(err instanceof
|
|
52
|
+
ApiError&&err.status===404)return null;throw err}}async function deleteOne(ctx,target){let company="already";let current;try{current=await companyNow(ctx,target.id)}catch(err){throw new DeleteStopped(err,"no",0,0)}if(current!==null&&!flagIsCustomer(current["customer_flg"])){throw new DeleteStopped(new UsageError(`\u4E0B\u898B\u306E\u5F8C\u306B\u9867\u5BA2\u3067\u306F\u306A\u3044\uFF08\u4ED5\u5165\u5148\u3060\u3051\u306E\uFF09\u53D6\u5F15\u5148\u306B\u5909\u308F\u3063\u305F\u305F\u3081\u3001\u524A\u9664\u3057\u307E\u305B\u3093`),
|
|
53
|
+
"no",0,0)}if(current!==null){try{await ctx.send({method:"DELETE",path:`${SALES_COMPANIES_PATH}/${target.id}`});company="deleted"}catch(err){if(rejectedBeforeWrite(err))throw new DeleteStopped(err,"no",0,0);if(!(err instanceof ApiError&&err.status===404)){let after;try{after=await companyNow(ctx,target.id)}catch{throw new DeleteStopped(err,"uncertain",0,0)}if(after!==null)throw new DeleteStopped(err,"no",0,0);company="deleted"}}}let contacts=0;let interactions=0;try{await drain(ctx,target.id,"con\
|
|
54
|
+
tacts",()=>contacts+=1);await drain(ctx,target.id,"interactions",()=>interactions+=1)}catch(err){throw new DeleteStopped(err,company,contacts,interactions)}if(contacts>target.contactIds.length){ctx.warn(`ID ${target.id}: \u4E0B\u898B\u306E\u5F8C\u306B\u5897\u3048\u305F\u62C5\u5F53\u8005 ${contacts-target.contactIds.length} \u4EF6\u3082\u524A\u9664\u3057\u307E\u3057\u305F\uFF08\u4F01\u696D\u306B\u7D10\u3065\u304F\u62C5\u5F53\u8005\u3092\u6B8B\u3055\u306A\u3044\u305F\u3081\uFF09\u3002`)}return{id:target.
|
|
55
|
+
id,line:target.line,company_name:target.name,company,contacts_deleted:contacts,interactions_deleted:interactions}}function doneLine(item){const where=item.line===null?"":`${item.line} \u884C\u76EE `;const company=item.company==="deleted"?"\u4F01\u696D\u3092\u524A\u9664":"\u4F01\u696D\u306F\u524A\u9664\u6E08\u307F";return`${where}ID ${item.id}${item.company_name===null?"":` ${item.company_name}`}\uFF08${company}\u30FB\u62C5\u5F53\u8005 ${item.contacts_deleted} \u4EF6\u30FB\u9023\u9396\u3067\u6D88\u3048\u306A\u304B\u3063\u305F\u5BFE\u5FDC\u5C65\u6B74 ${item.
|
|
56
|
+
interactions_deleted} \u4EF6\uFF09`}function stopReason(err){if(err instanceof ApiError&&err.status===422)return rejectionReason(err);if(err instanceof ApiError&&err.status===403)return`\u6A29\u9650\u304C\u8DB3\u308A\u307E\u305B\u3093\uFF08${CHILD_DELETE_NEEDS}\uFF09`;return err.message}async function runDelete(input,ctx){const targets=deleteTargets(input);const blocked=input.resolved?.["childDeleteBlocked"];if(blocked!==void 0&&blocked!=="")throw new ApiRejectedError(blocked);const done=[];for(const[
|
|
57
|
+
index,target]of targets.entries()){try{done.push(await deleteOne(ctx,target))}catch(caught){if(!(caught instanceof DeleteStopped))throw caught;const err=caught.reason;const unsent=targets.slice(index+1);const touched=caught.companyDeleted!=="no"||caught.contactsDeleted+caught.interactionsDeleted>0;if(targets.length===1&&!touched)throw err;const lines=[`\u9867\u5BA2\u306E\u524A\u9664\u306F ${targetLabel(target)} \u3067\u6B62\u307E\u308A\u307E\u3057\u305F\uFF08${targets.length} \u4EF6\u4E2D \u5B8C\u4E86 ${done.
|
|
58
|
+
length} \u4EF6\u30FB\u5931\u6557 1 \u4EF6\u30FB\u672A\u7740\u624B ${unsent.length} \u4EF6\uFF09\u3002`];if(caught.companyDeleted==="no"){lines.push(` \u5931\u6557: \u4F01\u696D\u3092\u524A\u9664\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F: ${stopReason(err)}`);lines.push(" \u3053\u306E\u4F01\u696D\u3067\u306F\u4F55\u3082\u524A\u9664\u3057\u3066\u3044\u307E\u305B\u3093\uFF08\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u3082\u305D\u306E\u307E\u307E\u3067\u3059\uFF09\u3002")}else if(caught.
|
|
59
|
+
companyDeleted==="uncertain"){lines.push(` \u5931\u6557: \u4F01\u696D\u306E\u524A\u9664\u306E\u7D50\u679C\u304C\u5206\u304B\u308A\u307E\u305B\u3093\uFF08${err.message}\uFF09\u3002\u8AAD\u307F\u76F4\u3057\u3082\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002`);lines.push(" \u4F01\u696D\u304C\u6D88\u3048\u305F\u304B\u3069\u3046\u304B\u306F\u672A\u78BA\u8A8D\u3067\u3059\u3002\u62C5\u5F53\u8005\u306F\u307E\u3060\u6D88\u3057\u3066\u3044\u307E\u305B\u3093\u3002")}else{lines.push(` \u5931\u6557: ${caught.
|
|
60
|
+
companyDeleted==="deleted"?"\u4F01\u696D\u306F\u524A\u9664\u3057\u307E\u3057\u305F\u304C\u3001":"\u4F01\u696D\u306F\u524A\u9664\u6E08\u307F\u3067\u3059\u304C\u3001"}\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u306E\u524A\u9664\u3067\u6B62\u307E\u308A\u307E\u3057\u305F\uFF08${stopReason(err)}\uFF09\u3002`);lines.push(` \u6D88\u3057\u305F\u62C5\u5F53\u8005 ${caught.contactsDeleted} \u4EF6\u30FB\u5BFE\u5FDC\u5C65\u6B74 ${caught.interactionsDeleted} \u4EF6\u3002\u6B8B\u308A\u306F\u3053\u306E\u4F01\u696D ID \u306B\u6B8B\u3063\u3066\u3044\u307E\u3059\u3002`)}
|
|
61
|
+
lines.push(done.length===0?" \u5B8C\u4E86: \u306A\u3057":` \u5B8C\u4E86:
|
|
62
|
+
${done.map(item=>` ${doneLine(item)}`).join("\n")}`);lines.push(unsent.length===0?" \u672A\u7740\u624B: \u306A\u3057":` \u672A\u7740\u624B: ${unsent.map(t=>`ID ${t.id}`).join(" / ")}`);if(err instanceof ApiError&&err.status===422){lines.push("\u53C2\u7167\u3057\u3066\u3044\u308B\u30C7\u30FC\u30BF\u3092\u524A\u9664\u30FB\u4ED8\u3051\u66FF\u3048\u308B\u304B\u3001\u305D\u306E ID \u3092\u30D5\u30A1\u30A4\u30EB\u304B\u3089\u9664\u3044\u3066\u304B\u3089\u3001\u540C\u3058\u30B3\u30DE\u30F3\u30C9\u3092\u6253\u3061\u76F4\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u5B8C\u4E86\u3057\u305F\u4F01\u696D\u306F\u524A\u9664\u6E08\u307F\u3068\u3057\u3066\u98DB\u3070\u3057\u307E\u3059\uFF09\u3002")}else if(err instanceof
|
|
63
|
+
ApiError&&err.status===403){lines.push(`\u3053\u306E\u6A29\u9650\u3067\u306F\u6253\u3061\u76F4\u3057\u3066\u3082\u9032\u307F\u307E\u305B\u3093\u3002${CHILD_DELETE_NEEDS}\u3002\u6A29\u9650\u3092\u6301\u3064\u4EBA\u306B\u540C\u3058\u30B3\u30DE\u30F3\u30C9\u306E\u5B9F\u884C\u3092\u4F9D\u983C\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u524A\u9664\u6E08\u307F\u306E\u4F01\u696D\u306F\u6B8B\u308A\u3060\u3051\u3092\u6D88\u3057\u307E\u3059\uFF09\u3002`)}else{lines.push("\u539F\u56E0\u3092\u53D6\u308A\u9664\u3044\u3066\u304B\u3089\u540C\u3058\u30B3\u30DE\u30F3\u30C9\u3092\u6253\u3061\u76F4\u3059\u3068\u3001\u524A\u9664\u6E08\u307F\u306E\u4F01\u696D\u306F\u6B8B\u308A\u306E\u62C5\
|
|
64
|
+
\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u3060\u3051\u3092\u6D88\u3057\u307E\u3059\u3002")}ctx.warn(lines.join("\n"));if(done.length===0&&!touched)throw err;throw new ApiRejectedError(`\u9867\u5BA2\u306E\u524A\u9664\u306F\u5B8C\u4E86\u3057\u3066\u3044\u307E\u305B\u3093\uFF08\u5B8C\u4E86 ${done.length} \u4EF6\u30FB\u5931\u6557 1 \u4EF6\u30FB\u672A\u7740\u624B ${unsent.length} \u4EF6\uFF09\u3002`)}}return{customerDelete:true,done}}var deleteOperation={name:"delete",summary:"\u9867\u5BA2\u3092\u524A\u9664\u3059\u308B\uFF08\u4F01\u696D\u3068\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u3092\u307E\
|
|
65
|
+
\u3068\u3081\u3066\u3002--file \u3067\u4E00\u62EC\u30FB--yes \u304C\u8981\u308B\uFF09",usage:"twp customer delete <\u9867\u5BA2> --yes | twp customer delete --file <\u30D5\u30A1\u30A4\u30EB> --yes",description:"\u9867\u5BA2\uFF08\u53D6\u5F15\u5148\u4F01\u696D\uFF09\u3068\u3001\u305D\u308C\u306B\u7D10\u3065\u304F\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u3092\u307E\u3068\u3081\u3066\u524A\u9664\u3057\u307E\u3059\u3002\n\u9001\u308B\u524D\u306B\u4F01\u696D\u30FB\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u306E\u4EF6\u6570\u3092\u6570\u3048\u3066 stderr \u306B\u51FA\u3057\u307E\u3059\u3002--dry-run \u3067\u9001\u3089\u305A\u306B\u4E0B\u898B\u3060\u3051\u3067\u304D\u307E\u3059\u3002\n\n\u9806\u5E8F\u306F\u4F01\u696D\u3054\u3068\u306B\u300C\u4F01\u696D\u306E\u8AAD\u307F\u76F4\u3057\uFF08\u9867\u5BA2\u306E\u307E\u307E\u304B\uFF09\u2192 \u4F01\u696D\u306E\u524A\u9664 \u2192 \u62C5\u5F53\u8005\u306E\u524A\u9664 \u2192 \u5BFE\u5FDC\u5C65\u6B74\u304C\u6B8B\u3063\u3066\u3044\u306A\u3044\u304B\u306E\u78BA\u8A8D\u300D\u3067\u3059\u3002\n\u4F01\u696D\u304C\u898B\u7A4D\u30FB\u8ACB\u6C42\u66F8\u30FB\u6848\u4EF6\u66F8\u985E\u30FB\u5951\u7D04\u66F8\u30FB\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u7B49\u304B\u3089\u53C2\u7167\u3055\u308C\u3066\u3044\u308B\u3068\u3001\u30B5\u30FC\u30D0\u304C\u524A\u9664\u3092\u65AD\u308A\u307E\u3059\uFF08\u7406\u7531\u306E\u6587\u9762\u3092\u305D\u306E\u307E\u307E\u51FA\u3057\u307E\u3059\uFF09\u3002\n\u305D\u306E\u3068\u304D\u306F\u305D\u306E\u4F01\u696D\u3067\u306F\u4F55\u3082\u524A\u9664\u305B\u305A\u306B\u6B62\u307E\u308A\u307E\u3059\uFF08\u62C5\u5F53\u8005\u3092\u5148\u306B\u6D88\u3057\u3066\u4F01\u696D\u3060\u3051\u6B8B\u308B\u3001\u306F\u8D77\u304D\u307E\u305B\u3093\uFF09\u3002\n\u5951\u7D04\u66F8\u304C\u6B8B\u3063\u3066\u3044\u308B\u306A\u3089 \
|
|
66
|
+
twp customer contract list / delete \u3067\u5148\u306B\u6D88\u3057\u307E\u3059\u3002\n\n\u4E00\u62EC\uFF08--file\uFF09: 1\u884C\u306B1\u3064\u9867\u5BA2\u306E ID \u3092\u66F8\u304D\u307E\u3059\uFF08\u540D\u524D\u306F\u53D7\u3051\u307E\u305B\u3093\uFF09\u3002\u7A7A\u884C\u3068 # \u3067\u59CB\u307E\u308B\u884C\u306F\u8AAD\u307F\u98DB\u3070\u3057\u307E\u3059\u3002\n\u9001\u308B\u524D\u306B\u5168\u884C\u3092\u691C\u67FB\u3057\u3001\u9867\u5BA2\u3067\u306F\u306A\u3044\uFF08\u4ED5\u5165\u5148\u3060\u3051\u306E\uFF09\u53D6\u5F15\u5148\u30FBID \u306E\u5F62\u306E\u8AA4\u308A\u30FB\u91CD\u8907\u304C1\u3064\u3067\u3082\u3042\u308C\u3070\n1\u4EF6\u3082\u9001\u3089\u305A\u306B\u884C\u756A\u53F7\u3068\u7406\u7531\u3092\u3059\u3079\u3066\u51FA\u3057\u3066\u7D42\u4E86\u30B3\u30FC\u30C9 2 \u3067\u7D42\u308F\u308A\u307E\u3059\u3002\n\u9001\u4FE1\u4E2D\u306B\u5931\u6557\u3057\u305F\u3089\u305D\u3053\u3067\u6B62\u3081\u3001\u5B8C\u4E86\u3057\u305F\u4F01\u696D\u30FB\u5931\u6557\u3057\u305F\u4F01\u696D\uFF08\u3069\u3053\u307E\u3067\u6D88\u3048\u305F\u304B\uFF09\u30FB\u672A\u7740\u624B\u306E ID \u3092\u51FA\u3057\u307E\u3059\n\uFF08\u7D42\u4E86\u30B3\u30FC\u30C9 3\u3002\u4F55\u3082\u6D88\u3057\u3066\u3044\u306A\u3051\u308C\u3070\u5931\u6557\u3057\u305F\u8981\u6C42\u306E\u7D42\u4E86\u30B3\u30FC\u30C9\uFF09\u3002\u540C\u3058\u30B3\u30DE\u30F3\u30C9\u3092\u6253\u3061\u76F4\u3059\u3068\u3001\n\u524A\u9664\u6E08\u307F\u306E\u4F01\u696D\u306F\u6B8B\u308A\u306E\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u3060\u3051\u3092\u6D88\u3057\u3066\u9032\u307F\u307E\u3059\u3002\n\n\u9867\u5BA2\u304B\u3064\u4ED5\u5165\u5148\u306E\u4F01\u696D\u3082\u524A\u9664\u3057\u307E\u3059\uFF08\u4F01\u696D\u306F1\u4EF6\u306A\u306E\u3067\u3001\u4ED5\u5165\u5148\u3068\u3057\u3066\u3082\u6D88\u3048\u307E\u3059\u3002\u4E0B\u898B\u3067\u77E5\u3089\u305B\u307E\u3059\uFF09\u3002\n\u4F01\u696D\u306E\u524A\u9664\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u300C\u7BA1\u7406\u8005\u300D\u304B\u8CA9\u58F2\u7BA1\u7406\u306E\u300C\u30E1\u30F3\u30D0\u30FC\u300D\u4EE5\u4E0A\u3001\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u306E\u524A\u9664\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u300C\u7BA1\u7406\u8005\u300D\u304C\u8981\u308A\u307E\u3059\u3002\n\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u304C\u6B8B\u308B\u9867\u5BA2\u3092\u3001\u9867\u5BA2\u7BA1\u7406\u306E\u300C\u7BA1\u7406\u8005\u300D\u3067\u306A\u3044\u6A29\u9650\u3067\u6D88\u305D\u3046\u3068\u3059\u308B\u3068\u3001\u4F01\u696D\u3060\u3051\u6D88\u3048\u3066\u62C5\u5F53\u8005\u304C\u6B8B\u308B\u306E\u3092\u907F\u3051\u308B\u305F\u3081\n1\u4EF6\u3082\u9001\u3089\
|
|
67
|
+
\u305A\u306B\u6B62\u3081\u307E\u3059\uFF08--dry-run \u3067\u306F\u4E0B\u898B\u3068\u7406\u7531\u3092\u51FA\u3057\u307E\u3059\uFF09\u3002\n\n"+REF_HELP,destructive:true,forbidden:CUSTOMER_DELETE_FORBIDDEN,flags:[FILE_FLAG],prepare:prepareDelete,plan:input=>firstDeletePlan(deleteTargets(input)),plannedNotes:deletePlannedNotes,execute:runDelete,summarize:body=>isDeleteBody(body)?body.done:body,raw:body=>isDeleteBody(body)?body.done:body,notes(body){if(!isDeleteBody(body))return[];const companies=body.
|
|
68
|
+
done.filter(d=>d.company==="deleted").length;const contacts=body.done.reduce((n,d)=>n+d.contacts_deleted,0);const interactions=body.done.reduce((n,d)=>n+d.interactions_deleted,0);return[`\u524A\u9664\u3057\u307E\u3057\u305F: \u4F01\u696D ${companies} \u793E\u30FB\u62C5\u5F53\u8005 ${contacts} \u4EF6\uFF08\u5BFE\u5FDC\u5C65\u6B74\u306F\u4F01\u696D\u306E\u524A\u9664\u3067\u9023\u9396\u3002\u9023\u9396\u3067\u6D88\u3048\u305A\u306B\u500B\u5225\u306B\u6D88\u3057\u305F\u3082\u306E ${interactions} \u4EF6\uFF09\u3002`,
|
|
69
|
+
"\u62C5\u5F53\u8005\u30FB\u5BFE\u5FDC\u5C65\u6B74\u304C\u4E00\u89A7\u304B\u3089\u6D88\u3048\u305F\u3053\u3068\u3092\u78BA\u304B\u3081\u3066\u304B\u3089\u7D42\u3048\u3066\u3044\u307E\u3059\u3002"]}};var CUSTOMER_FLAG={name:"--customer",summary:"\u5BFE\u8C61\u306E\u9867\u5BA2\uFF08\u4F01\u696D\u540D\u30FB\u7565\u79F0\u30FB\u30AB\u30CA\u306E\u5B8C\u5168\u4E00\u81F4\u304B ID\uFF09",takesValue:true,placeholder:"<\u9867\u5BA2>"};async function prepareCustomerFlag(input,ctx,usage){const raw=nonEmpty(input.
|
|
70
|
+
flags,CUSTOMER_FLAG.name);if(raw===void 0)throw new UsageError("--customer <\u9867\u5BA2> \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",usage);return withResolved(input,{companyId:await resolveCustomer(ctx,raw,CUSTOMER_FLAG.name)})}function childId(input,spec,usage){const[raw,...rest]=input.args;if(raw===void 0||raw.trim()==="")throw new UsageError(`${spec.label}\u306E ID \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`,usage);if(rest.length>0)throw new UsageError(`\u53D7\u3051\u53D6\u308C\u308B${spec.
|
|
71
|
+
label}\u306E ID \u306F1\u3064\u3060\u3051\u3067\u3059: ${rest.join(" ")}`,usage);const id=raw.trim();if(!isSafePathSegment(id))throw new UsageError(`${spec.label}\u306E ID \u3068\u3057\u3066\u4F7F\u3048\u306A\u3044\u6587\u5B57\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u3059: ${id}`,`twp customer ${spec.name} list \u306E id \u5217\u306E\u5024\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);return id}function childResource(spec){const base=input=>childBase(requireResolved(input,"comp\
|
|
72
|
+
anyId"),spec.kind);const item=(input,usage2)=>`${base(input)}/${encodeURIComponent(childId(input,spec,usage2))}`;const one=(body,what)=>dataOf(body,what);const paging=envelopePaging({label:`${spec.label}\u4E00\u89A7`});const usage=op=>`twp customer ${spec.name} ${op} help`;return{name:spec.name,summary:`\u9867\u5BA2\u306E${spec.label}\u306E\u4E00\u89A7\u30FB\u8A73\u7D30\u30FB\u4F5C\u6210\u30FB\u66F4\u65B0\u30FB\u524A\u9664${spec.extraOperations===void 0?"":`\u30FB${spec.extraOperations.map(op=>op.
|
|
73
|
+
name).join("\u30FB")}`}`,operations:[{name:"list",summary:`\u9867\u5BA2\u306E${spec.label}\u3092\u4E00\u89A7\u3059\u308B`,usage:`twp customer ${spec.name} list --customer <\u9867\u5BA2> [--all] [--limit <\u4EF6\u6570>]`,description:`--customer \u304C\u5FC5\u9808\u3067\u3059\u3002
|
|
74
|
+
|
|
75
|
+
--output json \u306F API \u304C\u8FD4\u3059\u5168\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u51FA\u3057\u307E\u3059\u3002
|
|
76
|
+
--output table / text / tsv \u306F\u8981\u7D04\u5217\uFF08${spec.columns.join(" / ")}\uFF09\u3067\u3059\u3002
|
|
77
|
+
|
|
78
|
+
${LIST_PAGING_HELP}`,flags:[...LIST_FLAGS,CUSTOMER_FLAG],paging,forbidden:levelForbidden(CUSTOMER_LICENSE,`${spec.label}\u3092\u898B\u308B\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`),async prepare(input,ctx){if(input.args.length>0)throw new UsageError(`list \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,
|
|
79
|
+
usage("list"));return prepareCustomerFlag(input,ctx,usage("list"))},plan:input=>({method:"GET",path:base(input),query:{limit:positiveInteger(input.flags,"--limit"),cursor:nonEmpty(input.flags,"--cursor")}}),summarize:body=>paging.items(body).map(row=>pick(row,spec.columns)),raw:body=>paging.items(body)},{name:"get",summary:`\u9867\u5BA2\u306E${spec.label}1\u4EF6\u306E\u8A73\u7D30\u3092\u8868\u793A\u3059\u308B`,usage:`twp customer ${spec.name} get <${spec.label}ID> --customer <\u9867\u5BA2>`,description:`${spec.
|
|
80
|
+
label}\u306E ID \u306F twp customer ${spec.name} list \u306E id \u5217\u306E\u5024\u3067\u3059\u3002--customer \u304C\u5FC5\u9808\u3067\u3059\uFF08\u5225\u306E\u9867\u5BA2\u306E ID \u3092\u6307\u5B9A\u3059\u308B\u3068\u300C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u300D\u306B\u306A\u308A\u307E\u3059\uFF09\u3002
|
|
81
|
+
|
|
82
|
+
--output json \u306F API \u304C\u8FD4\u3059\u5168\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u51FA\u3057\u307E\u3059\u3002
|
|
83
|
+
--output table / text / tsv \u306F\u8981\u7D04\u5217\uFF08${spec.getColumns.join(" / ")}\uFF09\u3067\u3059\u3002`,flags:[CUSTOMER_FLAG],forbidden:levelForbidden(CUSTOMER_LICENSE,`${spec.label}\u3092\u898B\u308B\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`),async prepare(input,ctx){childId(input,spec,usage("get"));return prepareCustomerFlag(input,ctx,
|
|
84
|
+
usage("get"))},plan:input=>({method:"GET",path:item(input,usage("get"))}),summarize:body=>pick(one(body,spec.label),spec.getColumns),raw:body=>one(body,spec.label)},{name:"create",summary:`\u9867\u5BA2\u306B${spec.label}\u3092\u767B\u9332\u3059\u308B`,usage:`twp customer ${spec.name} create --customer <\u9867\u5BA2> ${spec.required.map(f=>`${f} <\u5024>`).join(" ")} [\u9805\u76EE\u2026]`,description:spec.createHelp,forbidden:childForbidden(spec.label,"edit"),flags:[...createFlags(spec.fields),CUSTOMER_FLAG],
|
|
85
|
+
async prepare(input,ctx){if(input.args.length>0)throw new UsageError(`create \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,usage("create"));fieldBody(input,spec.fields);for(const flag of spec.required){if(!input.flags.has(flag))throw new UsageError(`${flag} \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`,usage("create"))}return prepareCustomerFlag(input,ctx,usage("create"))},plan:input=>({method:"POST",path:base(input),body:fieldBody(input,spec.
|
|
86
|
+
fields)}),summarize:body=>pick(one(body,`${spec.label}\u306E\u767B\u9332`),spec.columns),raw:body=>one(body,`${spec.label}\u306E\u767B\u9332`)},{name:"update",summary:`\u9867\u5BA2\u306E${spec.label}\u3092\u66F4\u65B0\u3059\u308B`,usage:`twp customer ${spec.name} update <${spec.label}ID> --customer <\u9867\u5BA2> [\u9805\u76EE\u2026]`,description:"\u6307\u5B9A\u3057\u305F\u9805\u76EE\u3060\u3051\u3092\u5909\u66F4\u3057\u307E\u3059\uFF08\u6307\u5B9A\u3057\u306A\u304B\u3063\u305F\u9805\u76EE\u306F\u5909\u308F\u308A\u307E\u305B\u3093\uFF09\u3002\u5909\u66F4\u3059\u308B\u9805\u76EE\u30921\u3064\u3082\u6307\u5B9A\u3057\u306A\u3044\u3068\u30A8\u30E9\u30FC\u306B\u306A\u308A\u307E\u3059\u3002",
|
|
87
|
+
forbidden:childForbidden(spec.label,"edit"),flags:[...updateFlags(spec.fields),CUSTOMER_FLAG],async prepare(input,ctx){if(!hasAnyField(input,spec.fields))throw new UsageError("\u5909\u66F4\u3059\u308B\u9805\u76EE\u30921\u3064\u4EE5\u4E0A\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",usage("update"));fieldBody(input,spec.fields);childId(input,spec,usage("update"));return prepareCustomerFlag(input,ctx,usage("update"))},plan:input=>({method:"PUT",path:item(input,usage("update")),body:fieldBody(input,
|
|
88
|
+
spec.fields)}),summarize:body=>pick(one(body,`${spec.label}\u306E\u66F4\u65B0`),spec.columns),raw:body=>one(body,`${spec.label}\u306E\u66F4\u65B0`)},{name:"delete",summary:`\u9867\u5BA2\u306E${spec.label}\u3092\u524A\u9664\u3059\u308B\uFF08\u9867\u5BA2\u7BA1\u7406\u306E\u7BA1\u7406\u8005\u306E\u307F\u30FB--yes \u304C\u8981\u308B\uFF09`,usage:`twp customer ${spec.name} delete <${spec.label}ID> --customer <\u9867\u5BA2> --yes`,description:`${spec.label}1\u4EF6\u3092\u524A\u9664\u3057\u307E\u3059\u3002\u9867\u5BA2\u3054\u3068\u307E\u3068\u3081\u3066\u6D88\u3059\u306A\u3089 twp customer delete \u3092\u4F7F\u3044\
|
|
89
|
+
\u307E\u3059\u3002`,destructive:true,forbidden:childForbidden(spec.label,"delete"),flags:[CUSTOMER_FLAG],async prepare(input,ctx){childId(input,spec,usage("delete"));return prepareCustomerFlag(input,ctx,usage("delete"))},plan:input=>({method:"DELETE",path:item(input,usage("delete"))}),summarize:body=>acknowledgement(body,`${spec.label}\u524A\u9664`),raw:body=>acknowledgement(body,`${spec.label}\u524A\u9664`)},...spec.extraOperations??[]]}}var contactResource=childResource({name:"contact",kind:"c\
|
|
90
|
+
ontacts",label:"\u62C5\u5F53\u8005",fields:CONTACT_FIELDS,required:["--name"],columns:CONTACT_COLUMNS,getColumns:CONTACT_GET_COLUMNS,createHelp:"--customer \u3068 --name \u304C\u5FC5\u9808\u3067\u3059\u3002\u4F5C\u6210\u3057\u305F\u62C5\u5F53\u8005\u306E ID \u304C\u8FD4\u308A\u307E\u3059\u3002\u540D\u523A\u306E\u753B\u50CF\u306F twp customer business-card add \u3067\u8DB3\u3057\u307E\u3059\u3002"});var interactionResource=childResource({name:"interaction",kind:"interactions",label:"\u5BFE\u5FDC\u5C65\u6B74",
|
|
91
|
+
fields:INTERACTION_FIELDS,required:["--type","--date"],columns:INTERACTION_COLUMNS,getColumns:INTERACTION_GET_COLUMNS,extraOperations:[recentOperation()],createHelp:`--customer\u30FB--type\uFF08${INTERACTION_TYPES.join(" / ")}\uFF09\u30FB--date \u304C\u5FC5\u9808\u3067\u3059\u3002\u4F5C\u6210\u3057\u305F\u5BFE\u5FDC\u5C65\u6B74\u306E ID \u304C\u8FD4\u308A\u307E\u3059\u3002`});function recentOperation(){const paging=envelopePaging({label:"\u6700\u8FD1\u306E\u5BFE\u5FDC\u5C65\u6B74"});return{name:"\
|
|
92
|
+
recent",summary:"\u6700\u8FD1\u306E\u5BFE\u5FDC\u5C65\u6B74\u3092\u9867\u5BA2\u30FB\u30A2\u30D7\u30ED\u30FC\u30C1\u5148\u3092\u307E\u305F\u3044\u3067\u65B0\u3057\u3044\u9806\u306B\u4E00\u89A7\u3059\u308B\uFF08--customer \u4E0D\u8981\uFF09",usage:"twp customer interaction recent [--all] [--limit <\u4EF6\u6570>]",description:`\u9867\u5BA2\u3092\u307E\u305F\u3044\u3067\u3001\u6700\u8FD1\u306E\u5BFE\u5FDC\u5C65\u6B74\u3092\u65B0\u3057\u3044\u9806\u306B\u4E00\u89A7\u3057\u307E\u3059\u3002\u30A2\u30D7\u30ED\u30FC\u30C1\u5148\uFF08\u898B\u8FBC\u5BA2\uFF09\u306E\u5BFE\u5FDC\u5C65\u6B74\u3082\u6DF7\u3056\u308A\u307E\u3059\u3002
|
|
93
|
+
\u3069\u308C\u306E\u5BFE\u5FDC\u304B\u306F target_type \u5217\u3067\u5206\u304B\u308A\u307E\u3059\uFF08company \u306A\u3089 company_id \u2192 twp customer get\u3001prospect \u306A\u3089 prospect_id \u2192 twp prospect get\uFF09\u3002
|
|
94
|
+
|
|
95
|
+
--output json \u306F API \u304C\u8FD4\u3059\u5168\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u51FA\u3057\u307E\u3059\u3002
|
|
96
|
+
--output table / text / tsv \u306F\u8981\u7D04\u5217\uFF08${RECENT_COLUMNS.join(" / ")}\uFF09\u3067\u3059\u3002
|
|
97
|
+
|
|
98
|
+
${LIST_PAGING_HELP}`,flags:[...LIST_FLAGS],paging,forbidden:levelForbidden(CUSTOMER_LICENSE,"\u5BFE\u5FDC\u5C65\u6B74\u3092\u898B\u308B\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),plan(input){if(input.args.length>0)throw new UsageError(`recent \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,"twp customer\
|
|
99
|
+
interaction recent help");return{method:"GET",path:`${CUSTOMERS_PATH}/interactions/recent`,query:{limit:positiveInteger(input.flags,"--limit"),cursor:nonEmpty(input.flags,"--cursor")}}},summarize:body=>paging.items(body).map(row=>pick(row,RECENT_COLUMNS)),raw:body=>paging.items(body)}}var CARD_SOURCE="customer_contact";var CARD_COLUMNS=["card_id","front_attachment_id","back_attachment_id","back_note","created_at"];var BACK_NOTE_MAX_CHARS=1e4;var CONTACT_FLAG={name:"--contact",summary:"\u540D\u523A\u3092\u6301\u3064\u62C5\u5F53\u8005\u306E\
|
|
100
|
+
ID\uFF08twp customer contact list \u306E id \u5217\uFF09",takesValue:true,placeholder:"<\u62C5\u5F53\u8005ID>"};var FRONT_FLAG={name:"--front",summary:"\u540D\u523A\u306E\u8868\u9762\u306E\u753B\u50CF\u30D5\u30A1\u30A4\u30EB",takesValue:true,placeholder:"<\u30D1\u30B9>"};var BACK_FLAG={name:"--back",summary:"\u540D\u523A\u306E\u88CF\u9762\u306E\u753B\u50CF\u30D5\u30A1\u30A4\u30EB",takesValue:true,placeholder:"<\u30D1\u30B9>"};var NOTE_FLAG={name:"--note",summary:"\u88CF\u9762\u30E1\u30E2\uFF0810,000 \u6587\u5B57\u307E\u3067\u3002\u88CF\u9762\u306E\u753B\u50CF\u304C\u3042\u308B\u540D\u523A\u306B\u3060\u3051\u4ED8\
|
|
101
|
+
\u3051\u3089\u308C\u307E\u3059\uFF09",takesValue:true,placeholder:"<\u30E1\u30E2>"};var CLEAR_NOTE_FLAG={name:"--clear",summary:"\u88CF\u9762\u30E1\u30E2\u3092\u6D88\u3059",takesValue:false};var CARD_REF_HELP="--customer\uFF08\u9867\u5BA2\uFF09\u3068 --contact\uFF08\u62C5\u5F53\u8005\u306E ID\uFF09\u304C\u5FC5\u9808\u3067\u3059\u3002\u540D\u523A\u306E ID \u306F twp customer business-card list \u306E card_id \u5217\u306E\u5024\u3067\u3059\u3002";function cardUsage(op){return`twp customer business\
|
|
102
|
+
-card ${op} help`}function contactIdOf(input,usage){const raw=nonEmpty(input.flags,CONTACT_FLAG.name);if(raw===void 0)throw new UsageError("--contact <\u62C5\u5F53\u8005ID> \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",usage);const id=raw.trim();if(!isSafePathSegment(id))throw new UsageError(`\u62C5\u5F53\u8005\u306E ID \u3068\u3057\u3066\u4F7F\u3048\u306A\u3044\u6587\u5B57\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u3059: ${id}`,"twp customer contact list \u306E id \u5217\u306E\u5024\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
|
|
103
|
+
return id}function cardIdOf(input,usage){const[raw,...rest]=input.args;if(raw===void 0||raw.trim()==="")throw new UsageError("\u540D\u523A\u306E ID \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",usage);if(rest.length>0)throw new UsageError(`\u53D7\u3051\u53D6\u308C\u308B\u540D\u523A\u306E ID \u306F1\u3064\u3060\u3051\u3067\u3059: ${rest.join(" ")}`,usage);const id=raw.trim();if(!isSafePathSegment(id))throw new UsageError(`\u540D\u523A\u306E ID \u3068\u3057\u3066\u4F7F\u3048\u306A\u3044\u6587\u5B57\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u3059: ${id}`,
|
|
104
|
+
"twp customer business-card list \u306E card_id \u5217\u306E\u5024\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");return id}function contactPathOf(input,usage){return`${childBase(requireResolved(input,"companyId"),"contacts")}/${encodeURIComponent(contactIdOf(input,usage))}`}function cardsOf(body,what){const cards=dataOf(body,what)["business_cards"];if(!Array.isArray(cards)||!cards.every(isRecord)){throw new ApiResponseError(`${what}\u306E\u5FDC\u7B54\u306B business_cards \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`)}
|
|
105
|
+
return cards}function prepareCardTarget(input,ctx,usage){contactIdOf(input,usage);return prepareCustomerFlag(input,ctx,usage)}var CARD_FORBIDDEN_EDIT=childForbidden("\u540D\u523A","edit");function cardSides(input){const sides=[];for(const[side,flag]of[["front",FRONT_FLAG.name],["back",BACK_FLAG.name]]){if(!input.flags.has(flag))continue;const{file,size}=inspectLocalFile(input.flags.get(flag),flag,cardUsage("add"));const name=path.basename(file);sides.push({side,file,name,size,contentType:contentTypeFor(
|
|
106
|
+
name)})}return sides}function backNoteOf(input){const note=input.flags.get(NOTE_FLAG.name);if(note===void 0)return void 0;if(Array.from(note).length>BACK_NOTE_MAX_CHARS){throw new UsageError(`\u88CF\u9762\u30E1\u30E2\u306F ${BACK_NOTE_MAX_CHARS.toLocaleString()} \u6587\u5B57\u307E\u3067\u3067\u3059\uFF08${Array.from(note).length.toLocaleString()} \u6587\u5B57\uFF09`)}return note}function cardUploadPlan(side){return{method:"POST",path:"/api/v2/attachments/upload-url",body:{file_name:side.name,content_type:side.
|
|
107
|
+
contentType,file_size:side.size,source:CARD_SOURCE}}}async function addCard(input,ctx){const blocked=input.resolved?.["cardAddBlocked"];if(blocked!==void 0&&blocked!=="")throw new ApiRejectedError(blocked);const sides=cardSides(input);const note=backNoteOf(input);const contactPath2=contactPathOf(input,cardUsage("add"));dataOf(await ctx.send({method:"GET",path:contactPath2}),"\u62C5\u5F53\u8005");await checkUploadQuota(ctx,sides.reduce((sum,side)=>sum+side.size,0));const issuedIds=[];let registerSent=false;
|
|
108
|
+
const leftover=()=>registerSent?"\u540D\u523A\u306E\u767B\u9332\u306F\u9001\u4FE1\u3057\u307E\u3057\u305F\u304C\u3001\u5FDC\u7B54\u3092\u78BA\u304B\u3081\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u6253\u3061\u76F4\u3059\u524D\u306B twp customer business-card list \u3067\u767B\u9332\u3055\u308C\u305F\u304B\u3092\u78BA\u304B\u3081\u3066\u304F\u3060\u3055\u3044\u3002":issuedIds.length===0?"":`\u767A\u884C\u3057\u305F\u753B\u50CF\u306E\u6DFB\u4ED8\uFF08${issuedIds.map(u=>`${u.side==="fro\
|
|
109
|
+
nt"?"\u8868":"\u88CF"}: ${u.id}`).join(" / ")}\uFF09\u306F\u540D\u523A\u306B\u767B\u9332\u3055\u308C\u3066\u3044\u306A\u3044\u305F\u3081\u672A\u78BA\u5B9A\u306E\u307E\u307E\u3067\u3059\u3002\u672A\u78BA\u5B9A\u306E\u6DFB\u4ED8\u306F\u4E00\u5B9A\u6642\u9593\uFF08\u7F72\u540DURL\u306E\u6709\u52B9\u671F\u9650\uFF0B1\u6642\u9593\uFF09\u5F8C\u306B\u8A18\u9332\u304C\u5931\u52B9\u3057\u3001\u53C2\u7167\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\uFF08\u30B9\u30C8\u30EC\u30FC\u30B8\u4E0A\u306E\u5B9F\u4F53\u304C\u3044\u3064\u6D88\u3048\u308B\u304B\u306F\u3053\u306E CLI \u304B\u3089\u306F\u78BA\u304B\u3081\u3089\u308C\u307E\u305B\u3093\uFF09\u3002\u539F\u56E0\u3092\u53D6\u308A\u9664\u3044\u3066\u3082\u3046\u4E00\u5EA6 twp customer business-card add \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002`;
|
|
110
|
+
try{for(const side of sides){const{id,uploadUrl}=issued(await ctx.send(cardUploadPlan(side)));issuedIds.push({side:side.side,id});const bytes=new Uint8Array(fs.readFileSync(side.file));if(bytes.byteLength!==side.size){throw new UsageError(`\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D\u306B\u30D5\u30A1\u30A4\u30EB\u306E\u5927\u304D\u3055\u304C\u5909\u308F\u308A\u307E\u3057\u305F\uFF08${side.size} \u2192 ${bytes.byteLength} \u30D0\u30A4\u30C8\uFF09: ${side.file}`)}await ctx.putSigned(uploadUrl,bytes,
|
|
111
|
+
side.contentType)}const frontId=issuedIds.find(u=>u.side==="front")?.id??null;const backId=issuedIds.find(u=>u.side==="back")?.id??null;const registration=ctx.send({method:"POST",path:`${contactPath2}/business-cards`,body:{front_attachment_id:frontId,back_attachment_id:backId,...note===void 0?{}:{back_note:note}}});const body=await registration;registerSent=true;const card=cardsOf(body,"\u540D\u523A\u306E\u767B\u9332").find(row=>(row["front_attachment_id"]??null)===frontId&&(row["back_attachment\
|
|
112
|
+
_id"]??null)===backId);if(card===void 0){throw new ApiResponseError("\u540D\u523A\u306E\u767B\u9332\u306E\u5FDC\u7B54\u306B\u4ECA\u56DE\u306E\u540D\u523A\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return{data:{...card,contact_id:contactIdOf(input,cardUsage("add")),company_id:requireResolved(input,"companyId")}}}catch(err){const text=leftover();if(text!=="")ctx.warn(`${text}
|
|
113
|
+
`);throw err}}function cardRow(body){const data=isRecord(body)?body["data"]:void 0;if(!isRecord(data))throw new ApiResponseError("\u540D\u523A\u306E\u5FDC\u7B54\u306E\u5F62\u304C\u60F3\u5B9A\u3068\u9055\u3044\u307E\u3059\u3002");return data}function cardAfter(body,cardId,what){return cardsOf(body,what).find(row=>row["card_id"]===cardId)}var businessCardResource={name:"business-card",summary:"\u62C5\u5F53\u8005\u306E\u540D\u523A\uFF08\u4E00\u89A7\u30FB\u753B\u50CF\u306E\u767B\u9332\u30FB\u88CF\u9762\u30E1\u30E2\u30FB\u524A\u9664\uFF09",
|
|
114
|
+
operations:[{name:"list",summary:"\u62C5\u5F53\u8005\u306E\u540D\u523A\u3092\u65B0\u3057\u3044\u9806\u306B\u4E00\u89A7\u3059\u308B",usage:"twp customer business-card list --customer <\u9867\u5BA2> --contact <\u62C5\u5F53\u8005ID>",description:`${CARD_REF_HELP}
|
|
115
|
+
\u753B\u50CF\u306F\u6DFB\u4ED8\u306E ID\uFF08front_attachment_id / back_attachment_id\uFF09\u3067\u51FA\u307E\u3059\u3002\u753B\u50CF\u305D\u306E\u3082\u306E\u306F twp task attachment download <\u6DFB\u4ED8ID> --out <\u30D1\u30B9> \u3067\u53D6\u308A\u51FA\u305B\u307E\u3059\u3002
|
|
116
|
+
|
|
117
|
+
--output table / text / tsv \u306F\u8981\u7D04\u5217\uFF08${CARD_COLUMNS.join(" / ")}\uFF09\u3067\u3059\u3002`,flags:[CUSTOMER_FLAG,CONTACT_FLAG],forbidden:levelForbidden(CUSTOMER_LICENSE,"\u540D\u523A\u3092\u898B\u308B\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),async prepare(input,ctx){if(input.args.length>0)throw new UsageError(`list \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093\
|
|
118
|
+
: ${input.args.join(" ")}`,cardUsage("list"));return prepareCardTarget(input,ctx,cardUsage("list"))},plan:input=>({method:"GET",path:contactPathOf(input,cardUsage("list"))}),summarize:body=>cardsOf(body,"\u62C5\u5F53\u8005").map(row=>pick(row,CARD_COLUMNS)),raw:body=>cardsOf(body,"\u62C5\u5F53\u8005")},{name:"add",summary:"\u540D\u523A\u306E\u753B\u50CF\uFF08\u8868\u30FB\u88CF\uFF09\u3092\u62C5\u5F53\u8005\u306B\u767B\u9332\u3059\u308B\uFF08\u5BB9\u91CF\u691C\u67FB\u30FB\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u30FB\u767B\u9332\u30921\u30B3\u30DE\u30F3\u30C9\u3067\uFF09",
|
|
119
|
+
usage:"twp customer business-card add --customer <\u9867\u5BA2> --contact <\u62C5\u5F53\u8005ID> [--front <\u30D1\u30B9>] [--back <\u30D1\u30B9>] [--note <\u88CF\u9762\u30E1\u30E2>]",description:"--front \u3068 --back \u306E\u5C11\u306A\u304F\u3068\u3082\u4E00\u65B9\u304C\u5FC5\u8981\u3067\u3059\u3002\u65E2\u5B58\u306E\u540D\u523A\u306F\u5DEE\u3057\u66FF\u3048\u305A\u3001\u8FFD\u52A0\u3057\u305F\u540D\u523A\u304C\u6700\u65B0\u306B\u306A\u308A\u307E\u3059\u3002\n--note\uFF08\u88CF\u9762\u30E1\u30E2\uFF09\u306F --back \u3068\u4E00\u7DD2\u306B\u3060\u3051\u6307\u5B9A\u3067\u304D\u307E\u3059\uFF08\u30B5\u30FC\u30D0\u306F\u88CF\u9762\u306E\u7121\u3044\u540D\u523A\u306E\u30E1\u30E2\u3092\u4FDD\u5B58\u3057\u307E\u305B\u3093\uFF09\u3002\n\n\u6B21\u306E\u9806\u306B\u9001\u308A\u307E\u3059\u3002\n 0. POST /api/v2/storage/check-upload\uFF08\u8868\u30FB\u88CF\u306E\u5408\u8A08\u3067\u30C6\u30CA\u30F3\u30C8\u306E\u5BB9\u91CF\u3092\u691C\u67FB\u3002\u8D85\u904E\u306A\u3089\u4F55\u3082\u9001\u3089\u305A\u306B\u6B62\u307E\u308A\u307E\u3059\uFF09\n 1. POST /api/v2/attachments/upload-url \u2192 \u7F72\u540DURL\u3078 PUT\uFF08\u8868\u30FB\u88CF\u305D\u308C\u305E\u308C\u3002TWP \u306E\u8A8D\u8A3C\u60C5\u5831\u306F\u9001\u308A\u307E\u305B\u3093\uFF09\n 2. POST \u2026/contacts/{\u62C5\
|
|
120
|
+
\u5F53\u8005ID}/business-cards\uFF08\u3053\u3053\u3067\u753B\u50CF\u304C\u78BA\u5B9A\u3057\u307E\u3059\uFF09\n0 \u306E\u524D\u306B\u3001\u62C5\u5F53\u8005\u304C\u3053\u306E\u9867\u5BA2\u306B\u5B9F\u5728\u3059\u308B\u3053\u3068\u3092 GET \u3067\u78BA\u304B\u3081\u307E\u3059\uFF08\u7121\u3051\u308C\u3070\u753B\u50CF\u3092\u4E0A\u3052\u305A\u306B\u6B62\u307E\u308A\u307E\u3059\uFF09\u3002\n2 \u304C\u5931\u6557\u3057\u305F\u5834\u5408\u306F\u3001\u767A\u884C\u3057\u305F\u753B\u50CF\u306E\u6DFB\u4ED8 ID \u3092 stderr \u306B\u51FA\u3057\u3066\u5931\u6557\u3057\u307E\u3059\uFF08\u672A\u78BA\u5B9A\u306E\u6DFB\u4ED8\u306F\u4E00\u5B9A\u6642\u9593\u5F8C\u306B\u8A18\u9332\u304C\u5931\u52B9\u3057\u307E\u3059\uFF09\u3002\n\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u95B2\u89A7\u8005\u300D\u4EE5\u4E0B\u3068\u5206\u304B\u3063\u3066\u3044\u308C\u3070\u3001\u753B\u50CF\u3092\u4E0A\u3052\u308B\u524D\u306B\u6B62\u3081\u307E\u3059\u3002\n--dry-run \u306F 1 \u306E\u6700\u521D\u306E\u30EA\u30AF\u30A8\u30B9\u30C8\u3060\u3051\u3092\u8868\u793A\u3057\u307E\u3059\uFF08\u4EE5\u964D\u306F\u5FDC\u7B54\u306B\u4F9D\u5B58\u3059\u308B\u305F\u3081\uFF09\u3002",
|
|
121
|
+
flags:[CUSTOMER_FLAG,CONTACT_FLAG,FRONT_FLAG,BACK_FLAG,NOTE_FLAG],forbidden:CARD_FORBIDDEN_EDIT,async prepare(input,ctx){if(input.args.length>0)throw new UsageError(`add \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,cardUsage("add"));const sides=cardSides(input);if(sides.length===0)throw new UsageError("--front \u304B --back \u306E\u5C11\u306A\u304F\u3068\u3082\u4E00\u65B9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",cardUsage("add"));if(input.
|
|
122
|
+
flags.has(NOTE_FLAG.name)&&!input.flags.has(BACK_FLAG.name)){throw new UsageError("--note\uFF08\u88CF\u9762\u30E1\u30E2\uFF09\u306F --back\uFF08\u88CF\u9762\u306E\u753B\u50CF\uFF09\u3068\u4E00\u7DD2\u306B\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","\u30B5\u30FC\u30D0\u306F\u88CF\u9762\u306E\u753B\u50CF\u304C\u7121\u3044\u540D\u523A\u306E\u30E1\u30E2\u3092\u4FDD\u5B58\u3057\u307E\u305B\u3093\u3002")}backNoteOf(input);const prepared=await prepareCardTarget(input,ctx,cardUsage("add"));const{isAdmin,
|
|
123
|
+
level}=await ctx.resolver.featureLevel("customer");const blocked=!isAdmin&&(level==="viewer"||level==="none")?`\u540D\u523A\u306E\u767B\u9332\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u300C\u7DE8\u96C6\u8005\u300D\u4EE5\u4E0A\u3067\u3042\u308B\u3053\u3068\u304C\u8981\u308A\u307E\u3059\uFF08\u3042\u306A\u305F\u306E\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650: ${LEVEL_LABELS[level]??level}\uFF09\u3002\u753B\u50CF\u306F1\u679A\u3082\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3057\u3066\u3044\u307E\u305B\u3093\u3002`:
|
|
124
|
+
"";return withResolved(prepared,{cardAddBlocked:blocked})},plan:input=>cardUploadPlan(cardSides(input)[0]),plannedNotes:input=>{const sides=cardSides(input);const blocked=input.resolved?.["cardAddBlocked"];if(blocked!==void 0&&blocked!=="")return[`\u5B9F\u884C\u3057\u3066\u3082\u9001\u308A\u307E\u305B\u3093: ${blocked}`];return[`\u5B9F\u884C\u6642\u306F\u3001\u3053\u306E\u524D\u306B\u5BB9\u91CF\u691C\u67FB\uFF08POST /api/v2/storage/check-upload\u30FB${sides.reduce((sum,side)=>sum+side.size,0)} \u30D0\
|
|
125
|
+
\u30A4\u30C8\uFF09\u3092\u9001\u308A\u3001${sides.map(side=>`${side.side==="front"?"\u8868":"\u88CF"}\uFF08${side.size} \u30D0\u30A4\u30C8\uFF09`).join("\u30FB")}\u3092\u7F72\u540DURL\u3078 PUT \u3057\u3066\u304B\u3089\u3001POST ${contactPathOf(input,cardUsage("add"))}/business-cards \u3067\u540D\u523A\u3092\u767B\u9332\u3057\u307E\u3059\u3002`]},execute:addCard,summarize:body=>pick(cardRow(body),["card_id","contact_id","company_id","front_attachment_id","back_attachment_id","back_note"]),raw:cardRow},
|
|
126
|
+
{name:"note",summary:"\u540D\u523A\u306E\u88CF\u9762\u30E1\u30E2\u3092\u66F8\u304D\u63DB\u3048\u308B\uFF08--clear \u3067\u6D88\u3059\uFF09",usage:"twp customer business-card note <\u540D\u523AID> --customer <\u9867\u5BA2> --contact <\u62C5\u5F53\u8005ID> (--note <\u30E1\u30E2> | --clear)",description:`${CARD_REF_HELP}
|
|
127
|
+
\u88CF\u9762\u306E\u753B\u50CF\u304C\u3042\u308B\u540D\u523A\u306B\u3060\u3051\u30E1\u30E2\u3092\u4ED8\u3051\u3089\u308C\u307E\u3059\uFF08\u7121\u3051\u308C\u3070\u30B5\u30FC\u30D0\u304C 422 \u3067\u65AD\u308A\u307E\u3059\uFF09\u3002`,flags:[CUSTOMER_FLAG,CONTACT_FLAG,NOTE_FLAG,CLEAR_NOTE_FLAG],forbidden:CARD_FORBIDDEN_EDIT,async prepare(input,ctx){cardIdOf(input,cardUsage("note"));const has=input.flags.has(NOTE_FLAG.name);const clear=input.flags.has(CLEAR_NOTE_FLAG.name);if(has===clear)throw new UsageError(
|
|
128
|
+
"--note <\u30E1\u30E2> \u304B --clear \u306E\u3069\u3061\u3089\u304B\u4E00\u65B9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",cardUsage("note"));backNoteOf(input);return prepareCardTarget(input,ctx,cardUsage("note"))},plan:notePlan,execute:async(input,ctx)=>({data:noteResult(await ctx.send(notePlan(input)),cardIdOf(input,cardUsage("note")))}),summarize:body=>pick(cardRow(body),CARD_COLUMNS),raw:cardRow},{name:"delete",summary:"\u540D\u523A\u30921\u4EF6\u524A\u9664\u3059\u308B\uFF08\u753B\u50CF\u3082\u6D88\u3048\u307E\u3059\u30FB--yes \u304C\u8981\u308B\uFF09",
|
|
129
|
+
usage:"twp customer business-card delete <\u540D\u523AID> --customer <\u9867\u5BA2> --contact <\u62C5\u5F53\u8005ID> --yes",description:`${CARD_REF_HELP}
|
|
130
|
+
\u540D\u523A\u306E\u753B\u50CF\uFF08\u8868\u30FB\u88CF\u306E\u6DFB\u4ED8\uFF09\u3082\u30B5\u30FC\u30D0\u304C\u4F75\u305B\u3066\u524A\u9664\u3057\u307E\u3059\u3002\u62C5\u5F53\u8005\u305D\u306E\u3082\u306E\u306F\u6D88\u3048\u307E\u305B\u3093\u3002`,destructive:true,flags:[CUSTOMER_FLAG,CONTACT_FLAG],forbidden:CARD_FORBIDDEN_EDIT,async prepare(input,ctx){cardIdOf(input,cardUsage("delete"));return prepareCardTarget(input,ctx,cardUsage("delete"))},plan:deletePlan,execute:async(input,ctx)=>({data:deleteResult(
|
|
131
|
+
await ctx.send(deletePlan(input)),cardIdOf(input,cardUsage("delete")))}),summarize:cardRow,raw:cardRow}]};function notePlan(input){return{method:"PATCH",path:`${contactPathOf(input,cardUsage("note"))}/business-cards/${encodeURIComponent(cardIdOf(input,cardUsage("note")))}`,body:{back_note:input.flags.has(CLEAR_NOTE_FLAG.name)?null:backNoteOf(input)}}}function deletePlan(input){return{method:"DELETE",path:`${contactPathOf(input,cardUsage("delete"))}/business-cards/${encodeURIComponent(cardIdOf(input,
|
|
132
|
+
cardUsage("delete")))}`}}function noteResult(body,cardId){const card=cardAfter(body,cardId,"\u88CF\u9762\u30E1\u30E2\u306E\u66F4\u65B0");if(card===void 0)throw new ApiResponseError(`\u88CF\u9762\u30E1\u30E2\u306E\u66F4\u65B0\u306E\u5FDC\u7B54\u306B\u540D\u523A ${cardId} \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);return card}function deleteResult(body,cardId){const remaining=cardsOf(body,"\u540D\u523A\u306E\u524A\u9664");
|
|
133
|
+
if(remaining.some(row=>row["card_id"]===cardId)){throw new ApiResponseError(`\u540D\u523A\u306E\u524A\u9664\u306E\u5FDC\u7B54\u306B\u540D\u523A ${cardId} \u304C\u6B8B\u3063\u3066\u3044\u307E\u3059\u3002twp customer business-card list \u3067\u78BA\u304B\u3081\u3066\u304F\u3060\u3055\u3044\u3002`)}return{deleted:cardId,remaining:remaining.length}}var SIMILAR_COLUMNS=["id","name","address","contact_count"];function similarRows(body){const data=isRecord(body)?body["data"]:void 0;if(!isRecord(body)||
|
|
134
|
+
body["result"]!==true||!Array.isArray(data)){throw new ApiResponseError("\u985E\u4F3C\u4F01\u696D\u691C\u7D22\u306E\u5FDC\u7B54\u306B data \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return data}var searchSimilarOperation={name:"search-similar",summary:"\u767B\u9332\u306E\u524D\u306B\u3001\u540D\u524D\u304C\u4F3C\u305F\u65E2\u5B58\u306E\u53D6\u5F15\u5148\u3092\u63A2\u3059\uFF08\u91CD\u8907\u78BA\u8A8D\uFF09",
|
|
135
|
+
usage:"twp customer search-similar <\u4F01\u696D\u540D> [--limit <\u4EF6\u6570>]",description:`\u4F01\u696D\u540D\u306E\u90E8\u5206\u4E00\u81F4\uFF08\u300C\u682A\u5F0F\u4F1A\u793E\u300D\u306A\u3069\u3092\u9664\u3044\u305F\u540D\u524D\u3067\u3082\u7167\u5408\uFF09\u3067\u3001\u65E2\u306B\u767B\u9332\u3055\u308C\u3066\u3044\u308B\u53D6\u5F15\u5148\u3092\u63A2\u3057\u307E\u3059\u3002
|
|
136
|
+
\u9867\u5BA2\u3060\u3051\u3067\u306A\u304F\u4ED5\u5165\u5148\u3060\u3051\u306E\u53D6\u5F15\u5148\u3082\u5F53\u305F\u308A\u307E\u3059\u3002\u62C5\u5F53\u8005\u6570\uFF08contact_count\uFF09\u3082\u51FA\u307E\u3059\u3002
|
|
137
|
+
--limit \u306E\u65E2\u5B9A\u306F\u30B5\u30FC\u30D0\u306E 10 \u4EF6\u3067\u3059\uFF08\u30B5\u30FC\u30D0\u306E\u4E0A\u9650\u306F 50 \u4EF6\uFF09\u3002
|
|
138
|
+
|
|
139
|
+
--output table / text / tsv \u306F\u8981\u7D04\u5217\uFF08${SIMILAR_COLUMNS.join(" / ")}\uFF09\u3067\u3059\u3002`,flags:[{name:"--limit",summary:"\u6700\u5927\u4EF6\u6570\uFF08\u65E2\u5B9A 10\u30FB\u30B5\u30FC\u30D0\u306E\u4E0A\u9650 50\uFF09",takesValue:true,placeholder:"<\u4EF6\u6570>"}],forbidden:levelForbidden(CUSTOMER_LICENSE,"\u985E\u4F3C\u4F01\u696D\u306E\u691C\u7D22\u306B\u306F\u9867\u5BA2\u7BA1\u7406\u306E\u6A29\u9650\u304C\u8981\u308A\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002"),
|
|
140
|
+
plan(input){const[raw,...rest]=input.args;if(raw===void 0||raw.trim()==="")throw new UsageError("\u4F01\u696D\u540D\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044","twp customer search-similar help");if(rest.length>0){throw new UsageError(`\u53D7\u3051\u53D6\u308C\u308B\u4F01\u696D\u540D\u306F1\u3064\u3060\u3051\u3067\u3059: ${rest.join(" ")}`,'\u7A7A\u767D\u3092\u542B\u3080\u540D\u524D\u306F\u5F15\u7528\u7B26\u3067\u56F2\u3093\u3067\u304F\u3060\u3055\u3044\uFF08\u4F8B: "\u682A\u5F0F\u4F1A\u793E \u30B5\u30F3\u30D7\u30EB"\uFF09\u3002')}
|
|
141
|
+
return{method:"GET",path:`${CUSTOMERS_PATH}/companies/search-similar`,query:{name:raw.trim(),limit:positiveInteger(input.flags,"--limit")}}},summarize:body=>similarRows(body).map(row=>pick(row,SIMILAR_COLUMNS)),raw:similarRows};var customerWriteOperations=[createOperation,updateOperation,deleteOperation,searchSimilarOperation];var customerSubresources=[contactResource,interactionResource,businessCardResource];export{levelForbidden,COMPANY_LICENSE,CUSTOMER_LICENSE,childForbidden,COMPANY_FIELDS,INTERACTION_TYPES,INTERACTION_FIELDS,dataOf,CUSTOMER_FLAG,prepareCustomerFlag,customerWriteOperations,customerSubresources};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{repeatedValues}from"./chunk-IOGVQVGD.js";import{isoDate}from"./chunk-UDPJ2IGK.js";import{SALES_ESTIMATES_PATH,SALES_INVOICES_PATH,isExactNumericId,resolveNamed}from"./chunk-
|
|
3
|
+
import{repeatedValues}from"./chunk-IOGVQVGD.js";import{isoDate}from"./chunk-UDPJ2IGK.js";import{SALES_ESTIMATES_PATH,SALES_INVOICES_PATH,isExactNumericId,resolveNamed}from"./chunk-DBIDYOKW.js";import{LIST_PAGING_HELP,PAGE_NUMBER_LIST_FLAGS,PAGE_NUMBER_PAGING_HELP,STABLE_PAGE_ORDER,nonEmpty,pageNumberPaging,pageNumberQuery,pageRangeNotes}from"./chunk-R53CMVWR.js";import{withResolved}from"./chunk-ZN5EFDH7.js";import{isRecord,pick}from"./chunk-ZWVYVS2A.js";import{
|
|
4
4
|
ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";var ESTIMATE_STATUSES={new:"\u4F5C\u6210\u4E2D",create_completed:"\u4F5C\u6210\u5B8C\u4E86",in_progress:"\u7533\u8ACB\u4E2D",approved:"\u627F\u8A8D\u6E08",submitted:"\u63D0\u793A\u6E08",rejected:"\u5DEE\u3057\u623B\u3057",deleted:"\u524A\u9664\u6E08"};var INVOICE_STATUSES={new:"\u4F5C\u6210\u4E2D",create_completed:"\u4F5C\u6210\u5B8C\u4E86",in_progress:"\u7533\u8ACB\u4E2D",approved:"\u627F\u8A8D\u6E08",rejected:"\u5DEE\u3057\u623B\u3057",submitted:"\u63D0\u793A\u6E08",manager_confirmation:"\u6848\u4EF6\u62C5\u5F53\u8005\
|
|
5
5
|
_\u6848\u4EF6\u5185\u5BB9\u30FB\u91D1\u984D\u78BA\u8A8D",invoice_issued:"\u8ACB\u6C42\u66F8\u767A\u884C\u6E08",sent_to_client:"\u5148\u65B9\u9001\u4ED8\u6E08",archived:"\u4FDD\u7BA1\u6E08",deleted:"\u524A\u9664\u6E08",cancelled:"\u53D6\u6D88\uFF08\u7121\u52B9\uFF09",lost:"\u5931\u6CE8"};var ALLOCATION_STATUSES={unallocated:"\u672A\u56DE\u53CE",allocated:"\u56DE\u53CE\u6E08"};function statusRefs(table){return Object.entries(table).map(([code,name])=>({id:code,name,code}))}function statusHelp(table){
|
|
6
6
|
return Object.entries(table).map(([code,name])=>`${code}\uFF08${name}\uFF09`).join(" / ")}function licenseForbidden(guidance){return body=>body?.error==="permission_denied"?guidance:void 0}function featureLicenseGuidance(feature){return`${feature}\u3092\u4F7F\u3046\u6A29\u9650\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u30C6\u30CA\u30F3\u30C8\u304C${feature}\u3092\u5951\u7D04\u3057\u3066\u3044\u306A\u3044\u304B\u3001\u3042\u306A\u305F\u306E${feature}\u306E\u6A29\u9650\u304C\u300C\u306A\u3057\u300D\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u3002\u30C6\u30CA\u30F3\u30C8\u7BA1\u7406\u8005\u306B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{
|
|
4
|
-
import{AuthSession,NotLoggedInError,SessionExpiredError,loadCredentials}from"./chunk-XNLIEUAW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,loadUserConfig,resolveConfiguredOutput,resolveProfile}from"./chunk-4VZKNEVN.js";import{HELP_TOKEN}from"./chunk-
|
|
5
|
-
DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-R53CMVWR.js";import{ApiRejectedError,ApiResponseError,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,EXIT_FAILURE,EXIT_OK,EXIT_USAGE,NetworkError,UsageError}from"./chunk-7WSNIXTQ.js";import fs from"fs";import path from"path";var NO_REDACT_FLAG={name:"--no-redact",summary:"\u5FDC\u7B54\u306E\u4F0F\u5B57\u5316\u3092\u89E3\u9664\u3057\u3066\u751F\u306E\u5024\u3092\u51FA\u3059\uFF08\u9375\u306E\u53D7\u3051\u53D6\u308A\u7B49\uFF09",takesValue:false};var NO_REDACT_NOTICE="\u6CE8\u8A18: --no-redact \u306E\u305F\u3081\u51FA\u529B\u3092\u4F0F\u5B57\u5316\u3057\u307E\u305B\u3093\uFF08\u7AEF\u672B\u3068\u30ED\u30B0\u306B\u5E73\u6587\u3067\u6B8B\u308A\u307E\u3059\uFF09\u3002";function withCommonFlags(flags){return flags.some(flag=>flag.
|
|
3
|
+
import{renderOutput}from"./chunk-6NEQ6PZZ.js";import{redactSecretValues,redactSecrets,withDebug}from"./chunk-BUZKNZ45.js";import{loadDomain}from"./chunk-XNW2UNWQ.js";import{evaluateQuery}from"./chunk-GDM2QUBL.js";import{parseOperationArgs}from"./chunk-IOGVQVGD.js";import{Resolver,requireDefaultProject}from"./chunk-DBIDYOKW.js";import{ApiError,MultipartBody,TwpApiClient,appendQuery}from"./chunk-IF2K4PM5.js";import{ResolveError}from"./chunk-GMBJTG6A.js";
|
|
4
|
+
import{GLOBAL_OPTIONS_HELP}from"./chunk-TAN5I2DP.js";import{AuthSession,NotLoggedInError,SessionExpiredError,loadCredentials}from"./chunk-XNLIEUAW.js";import{httpFetch}from"./chunk-J7QYPKVK.js";import{effectiveApiUrl,loadUserConfig,resolveConfiguredOutput,resolveProfile}from"./chunk-4VZKNEVN.js";import{HELP_TOKEN}from"./chunk-523KROGI.js";import{OUTPUT_FORMATS,resolveOutputFormat}from"./chunk-K2ONOH3L.js";import{stringWidth}from"./chunk-WVS4W5FY.js";import{
|
|
5
|
+
stripTerminalControls}from"./chunk-NHYMHCAT.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-R53CMVWR.js";import{ApiRejectedError,ApiResponseError,EXIT_API_CLIENT,EXIT_API_SERVER,EXIT_AUTH,EXIT_FAILURE,EXIT_OK,EXIT_USAGE,NetworkError,UsageError}from"./chunk-7WSNIXTQ.js";import fs from"fs";import path from"path";var NO_REDACT_FLAG={name:"--no-redact",summary:"\u5FDC\u7B54\u306E\u4F0F\u5B57\u5316\u3092\u89E3\u9664\u3057\u3066\u751F\u306E\u5024\u3092\u51FA\u3059\uFF08\u9375\u306E\u53D7\u3051\u53D6\u308A\u7B49\uFF09",takesValue:false};var NO_REDACT_NOTICE="\u6CE8\u8A18: --no-redact \u306E\u305F\u3081\u51FA\u529B\u3092\u4F0F\u5B57\u5316\u3057\u307E\u305B\u3093\uFF08\u7AEF\u672B\u3068\u30ED\u30B0\u306B\u5E73\u6587\u3067\u6B8B\u308A\u307E\u3059\uFF09\u3002";function withCommonFlags(flags){return flags.some(flag=>flag.
|
|
6
6
|
name===NO_REDACT_FLAG.name)?flags:[...flags,NO_REDACT_FLAG]}function alignedList(entries,indent=" "){const width=entries.reduce((max,[left])=>Math.max(max,stringWidth(left)),0);return entries.map(([left,right])=>`${indent}${left}${" ".repeat(Math.max(0,width-stringWidth(left)))} ${right}`).join("\n")}function subresourcesOf(resource){return resource.subresources??[]}function renderResourceHelp(resource,path2){const subresources=subresourcesOf(resource);const operationSection=resource.operations.length===0?"":`
|
|
7
7
|
\u64CD\u4F5C:
|
|
8
8
|
${alignedList(resource.operations.map(op=>[op.name,op.summary]))}
|
|
@@ -24,18 +24,18 @@ return EXIT_AUTH;if(err instanceof ApiError)return exitCodeForStatus(err.status)
|
|
|
24
24
|
Error?err.message:String(err));const rawHint=err instanceof UsageError?err.hint:void 0;const hint=rawHint!==void 0?safeText(rawHint):void 0;if(format==="json"){const body={code,message};if(err instanceof ApiError)body["status"]=err.status;if(err instanceof ResolveError&&err.status!==null)body["status"]=err.status;if(hint!==void 0)body["hint"]=hint;write(`${JSON.stringify({error:body},null,2)}
|
|
25
25
|
`);return}write(`${message}
|
|
26
26
|
`);if(hint!==void 0)write(`${hint}
|
|
27
|
-
`)}function dryRunValue(apiUrl,plan){const value={method:plan.method,url:`${apiUrl}${appendQuery(plan.path,plan.query)}`};if(plan.body!==void 0)value["body"]=plan.body;return value}async function send(client,apiUrl,plan){try{return await client.request(plan.method,appendQuery(plan.path,plan.query),plan.body)}catch(err){if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof SessionExpiredError){throw err}throw new NetworkError(
|
|
28
|
-
message}`,{cause:err})}}async function putSigned(fetchImpl,url,bytes,contentType){let res;try{res=await fetchImpl(url,{method:"PUT",headers:{"Content-Type":contentType},body:bytes})}catch(err){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}if(!res.ok){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\
|
|
29
|
-
status}\uFF09`)}}async function getSigned(fetchImpl,url){let res;try{res=await fetchImpl(url,{method:"GET"})}catch(err){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u304B\u3089\u306E\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}if(!res.ok){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u304B\u3089\u306E\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u304C\u62D2\u5426\u3055\u308C\u307E\u3057\u305F\uFF08HTTP ${res.
|
|
30
|
-
return{bytes:new Uint8Array(await res.arrayBuffer()),contentType:res.headers.get("content-type")}}function resolveDownloadTarget(spec,commandPath,operationName,input){const raw=input.flags.get(spec.outFlag);if(raw===void 0||raw.trim()===""){throw new UsageError(`${spec.outFlag} \u306F\u5FC5\u9808\u3067\u3059\uFF08twp ${commandPath} ${operationName}\uFF09`,`\u66F8\u304D\u51FA\u3057\u5148\u306E\u30D5\u30A1\u30A4\u30EB\u30D1\u30B9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u6A19\u6E96\u51FA\u529B\u3078\u306F\u51FA\u3057\u307E\u305B\u3093\uFF09\u3002`)}
|
|
27
|
+
`)}function dryRunValue(apiUrl,plan){const value={method:plan.method,url:`${apiUrl}${appendQuery(plan.path,plan.query)}`};if(plan.body!==void 0)value["body"]=plan.body instanceof MultipartBody?plan.body.toJSON():plan.body;return value}async function send(client,apiUrl,plan){try{return await client.request(plan.method,appendQuery(plan.path,plan.query),plan.body)}catch(err){if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof SessionExpiredError){throw err}throw new NetworkError(
|
|
28
|
+
`${apiUrl} \u3078\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}}async function putSigned(fetchImpl,url,bytes,contentType){let res;try{res=await fetchImpl(url,{method:"PUT",headers:{"Content-Type":contentType},body:bytes})}catch(err){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}if(!res.ok){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\
|
|
29
|
+
\u30FC\u30C9\u304C\u62D2\u5426\u3055\u308C\u307E\u3057\u305F\uFF08HTTP ${res.status}\uFF09`)}}async function getSigned(fetchImpl,url){let res;try{res=await fetchImpl(url,{method:"GET"})}catch(err){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u304B\u3089\u306E\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}if(!res.ok){throw new NetworkError(`\u30B9\u30C8\u30EC\u30FC\u30B8\u304B\u3089\u306E\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u304C\u62D2\u5426\u3055\u308C\u307E\u3057\u305F\uFF08HTTP ${res.
|
|
30
|
+
status}\uFF09`)}return{bytes:new Uint8Array(await res.arrayBuffer()),contentType:res.headers.get("content-type")}}function resolveDownloadTarget(spec,commandPath,operationName,input){const raw=input.flags.get(spec.outFlag);if(raw===void 0||raw.trim()===""){throw new UsageError(`${spec.outFlag} \u306F\u5FC5\u9808\u3067\u3059\uFF08twp ${commandPath} ${operationName}\uFF09`,`\u66F8\u304D\u51FA\u3057\u5148\u306E\u30D5\u30A1\u30A4\u30EB\u30D1\u30B9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u6A19\u6E96\u51FA\u529B\u3078\u306F\u51FA\u3057\u307E\u305B\u3093\uFF09\u3002`)}
|
|
31
31
|
return{out:path.resolve(raw.trim()),force:input.flags.has(spec.forceFlag)}}function assertWritableTarget(target,forceFlag){if(!target.force&&fs.existsSync(target.out)){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308A\u307E\u3059: ${target.out}`,`\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 ${forceFlag} \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\uFF08\u65E2\u5B9A\u3067\u306F\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\uFF09\u3002`)}const dir=path.dirname(target.
|
|
32
32
|
out);if(!fs.existsSync(dir)){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u306E\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u3042\u308A\u307E\u305B\u3093: ${dir}`,"\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3092\u4F5C\u3063\u3066\u304B\u3089\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\uFF08\u81EA\u52D5\u3067\u306F\u4F5C\u6210\u3057\u307E\u305B\u3093\uFF09\u3002")}}async function download(args){let received;if(args.signed!==void 0){const url=args.signed.signedUrl(await send(args.client,args.
|
|
33
33
|
apiUrl,args.plan),args.plan);received=await getSigned(args.signed.fetchImpl,url)}else{try{received=await args.client.requestBinary(args.plan.method,appendQuery(args.plan.path,args.plan.query))}catch(err){if(err instanceof ApiError||err instanceof NotLoggedInError||err instanceof SessionExpiredError)throw err;throw new NetworkError(`${args.apiUrl} \u3078\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${err.message}`,{cause:err})}}try{fs.writeFileSync(args.target.out,received.bytes,{
|
|
34
|
-
flag:args.target.force?"w":"wx"})}catch(err){const code=err.code;if(code==="EEXIST"){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308A\u307E\u3059: ${args.target.out}`,"\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 --force \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002")}throw new Error(`\u66F8\u304D\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${args.target.out}\uFF09: ${err.message}`,{cause:err})}
|
|
35
|
-
byteLength,contentType:received.contentType}}var CURATED_PAGING_VOCABULARY={mode:"--all",resumeFlag:"--cursor",capAdvice:"--limit \u3092\u5927\u304D\u304F\u3057\u3066\u5F80\u5FA9\u3092\u6E1B\u3089\u3059\u304B\u3001--max-pages / --max-items \u3092\u4E0A\u3052\u3066\u304F\u3060\u3055\u3044\u3002"};function capExceeded(vocabulary,reason,pages,count,cursor){
|
|
36
|
-
\uFF0F${pages} \u30DA\u30FC\u30B8\u30FB${count} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`,`${vocabulary.capAdvice}\u7D9A\u304D\u3060\u3051\u3092\u53D6\u308B\u306A\u3089 ${vocabulary.resumeFlag} ${shellQuote(cursor)} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059`)}
|
|
37
|
-
const first=args.plan.query?.[paging.cursorParam];let sent=typeof first==="string"?first:"";for(let page=1;;page+=1){const plan=page===1?args.plan:{...args.plan,query:{...args.plan.query,[paging.cursorParam]:sent}};let body;try{body=page===1&&"firstPage"in args?args.firstPage:await send(args.client,args.apiUrl,plan)}catch(err){if(page>1){(args.warn??
|
|
38
|
-
length} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7D9A\u304D\u306F ${vocabulary.resumeFlag} ${shellQuote(stripTerminalControls(sent))} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059\u3002
|
|
34
|
+
flag:args.target.force?"w":"wx"})}catch(err){const code=err.code;if(code==="EEXIST"){throw new UsageError(`\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308A\u307E\u3059: ${args.target.out}`,"\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 --force \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002")}throw new Error(`\u66F8\u304D\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${args.target.out}\uFF09: ${err.message}`,{cause:err})}const captured={};for(const name of args.captureHeaders??
|
|
35
|
+
[]){const value=received.headers?.get(name);if(typeof value==="string")captured[name]=value}return{path:args.target.out,size:received.bytes.byteLength,contentType:received.contentType,...Object.keys(captured).length>0?{headers:captured}:{}}}var CURATED_PAGING_VOCABULARY={mode:"--all",resumeFlag:"--cursor",capAdvice:"--limit \u3092\u5927\u304D\u304F\u3057\u3066\u5F80\u5FA9\u3092\u6E1B\u3089\u3059\u304B\u3001--max-pages / --max-items \u3092\u4E0A\u3052\u3066\u304F\u3060\u3055\u3044\u3002"};function capExceeded(vocabulary,reason,pages,count,cursor){
|
|
36
|
+
return new UsageError(`${vocabulary.mode} \u304C\u4E0A\u9650\u306B\u9054\u3057\u305F\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\uFF08${reason}\uFF0F${pages} \u30DA\u30FC\u30B8\u30FB${count} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`,`${vocabulary.capAdvice}\u7D9A\u304D\u3060\u3051\u3092\u53D6\u308B\u306A\u3089 ${vocabulary.resumeFlag} ${shellQuote(cursor)} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059`)}
|
|
37
|
+
async function fetchAllPages(args){const{paging,maxPages,maxItems}=args;const vocabulary=args.vocabulary??CURATED_PAGING_VOCABULARY;const merged=[];const first=args.plan.query?.[paging.cursorParam];let sent=typeof first==="string"?first:"";for(let page=1;;page+=1){const plan=page===1?args.plan:{...args.plan,query:{...args.plan.query,[paging.cursorParam]:sent}};let body;try{body=page===1&&"firstPage"in args?args.firstPage:await send(args.client,args.apiUrl,plan)}catch(err){if(page>1){(args.warn??
|
|
38
|
+
writeErr)(`${vocabulary.mode} \u306F ${page} \u30DA\u30FC\u30B8\u76EE\u3067\u5931\u6557\u3057\u307E\u3057\u305F\uFF08${page-1} \u30DA\u30FC\u30B8\u30FB${merged.length} \u4EF6\u3092\u53D6\u5F97\u6E08\u307F\uFF09\u3002\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7D9A\u304D\u306F ${vocabulary.resumeFlag} ${shellQuote(stripTerminalControls(sent))} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059\u3002
|
|
39
39
|
`)}throw err}for(const item of paging.items(body))merged.push(item);const next=paging.nextCursor(body);if(next===null)return{body:paging.withItems(body,merged),pages:page,count:merged.length};if(merged.length>=maxItems)throw capExceeded(vocabulary,`\u6700\u5927\u4EF6\u6570 ${maxItems} \u4EF6`,page,merged.length,next);if(page>=maxPages)throw capExceeded(vocabulary,`\u6700\u5927\u30DA\u30FC\u30B8\u6570 ${maxPages}`,page,merged.length,next);if(next===sent){throw new ApiResponseError(`\u540C\u3058\u30AB\u30FC\u30BD\u30EB\uFF08${next}\
|
|
40
40
|
\uFF09\u304C\u7E70\u308A\u8FD4\u3057\u8FD4\u3055\u308C\u305F\u305F\u3081\u4E2D\u65AD\u3057\u307E\u3057\u305F\u3002${merged.length} \u4EF6\u3092\u53D6\u5F97\u3057\u305F\u6642\u70B9\u3067\u3001\u3053\u308C\u306F\u5168\u4EF6\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`)}sent=next}}function resolvePaging(operation,path2,input){const all=input.flags.has("--all");const maxPages=positiveInteger(input.flags,"--max-pages")??DEFAULT_MAX_PAGES;const maxItems=positiveInteger(input.flags,"--max-items")??
|
|
41
41
|
DEFAULT_MAX_ITEMS;positiveInteger(input.flags,"--limit");if(all&&operation.paging===void 0){throw new UsageError(`twp ${path2} ${operation.name} \u306F --all \u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u305B\u3093`)}for(const name of["--max-pages","--max-items"]){if(!all&&input.flags.has(name)){throw new UsageError(`${name} \u306F --all \u3068\u4F75\u305B\u3066\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`,`${name} \u3060\u3051\u3067\u306F\u4F55\u3082\u5909\u308F\u308A\u307E\u305B\u3093`)}}return{
|
|
@@ -51,9 +51,9 @@ session,fetchImpl,options.version);const ctx=buildPrepareContext({resolver:new R
|
|
|
51
51
|
void 0&&(operation.download!==void 0||operation.paging!==void 0||operation.destructive===true||plan.method!=="GET")){throw new Error(`twp ${path2} ${operation.name}: fetchCached \u306F\u9001\u4FE1\u3057\u306A\u3044\u8AAD\u307F\u53D6\u308A\u5C02\u7528\u306E\u64CD\u4F5C\u306B\u3060\u3051\u5BA3\u8A00\u3067\u304D\u307E\u3059\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}for(const note of operation.plannedNotes?.(prepared)??[])errOut(`${safeText(note)}
|
|
52
52
|
`);if(noRedact)errOut(`${NO_REDACT_NOTICE}
|
|
53
53
|
`);if(globals.dryRun){out(line(renderOutput(dryRunValue(apiUrl,plan),format,noRedact)));return EXIT_OK}let body;let paged;try{if(operation.execute!==void 0){const executeCtx={send:next=>send(client,apiUrl,next),putSigned:(url,bytes,contentType)=>putSigned(fetchImpl,url,bytes,contentType),warn:text=>errOut(`${safeText(text)}
|
|
54
|
-
`)};body=await operation.execute(prepared,executeCtx)}else if(operation.fetchCached!==void 0){body=await operation.fetchCached(prepared,ctx)}else if(operation.download!==void 0&&downloadTarget!==void 0){assertWritableTarget(downloadTarget,operation.download.forceFlag);const signedUrl=operation.download.signedUrl;body=await download({client,apiUrl,plan,target:downloadTarget,...signedUrl===void 0?{}:{signed:{fetchImpl,signedUrl}}
|
|
55
|
-
{client,apiUrl,plan,paging:operation.paging,maxPages:paging.maxPages,maxItems:paging.maxItems,warn:errOut});body=paged.body}else{body=await send(client,apiUrl,plan)}}finally{try{operation.invalidates?.(prepared,ctx)}catch{}}const visible=noRedact?body:redactSecretValues(body);const value=globals.query!==void 0?await evaluateQuery(globals.query,operation.raw(visible)):outputValue(operation,format,visible);
|
|
56
|
-
\u30DA\u30FC\u30B8\u3092\u8FBF\u3063\u3066 ${paged.count} \u4EF6\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F\u3002
|
|
54
|
+
`)};body=await operation.execute(prepared,executeCtx)}else if(operation.fetchCached!==void 0){body=await operation.fetchCached(prepared,ctx)}else if(operation.download!==void 0&&downloadTarget!==void 0){assertWritableTarget(downloadTarget,operation.download.forceFlag);const signedUrl=operation.download.signedUrl;body=await download({client,apiUrl,plan,target:downloadTarget,...signedUrl===void 0?{}:{signed:{fetchImpl,signedUrl}},...operation.download.captureHeaders===void 0?{}:{captureHeaders:operation.
|
|
55
|
+
download.captureHeaders}})}else if(paging.all&&operation.paging!==void 0){paged=await fetchAllPages({client,apiUrl,plan,paging:operation.paging,maxPages:paging.maxPages,maxItems:paging.maxItems,warn:errOut});body=paged.body}else{body=await send(client,apiUrl,plan)}}finally{try{operation.invalidates?.(prepared,ctx)}catch{}}const visible=noRedact?body:redactSecretValues(body);const value=globals.query!==void 0?await evaluateQuery(globals.query,operation.raw(visible)):outputValue(operation,format,visible);
|
|
56
|
+
out(line(renderOutput(value,format,noRedact)));if(paged!==void 0){errOut(`--all: ${paged.pages} \u30DA\u30FC\u30B8\u3092\u8FBF\u3063\u3066 ${paged.count} \u4EF6\u3092\u53D6\u5F97\u3057\u307E\u3057\u305F\u3002
|
|
57
57
|
`)}const pagingNotes=operation.paging===void 0?[]:nextPageNotes(body,prepared,{command:`twp ${path2} ${operation.name}`,flags:operation.flags,profile:globals.profile,readCursor:operation.paging.readCursor});for(const note of[...pagingNotes,...operation.notes?.(visible,prepared)??[]]){errOut(`${safeText(note)}
|
|
58
58
|
`)}return EXIT_OK}catch(caught){const err=withRejectedGuidance(withForbiddenGuidance(caught,forbidden),rejected);const code=exitCodeFor(err);reportError(err,format,code,errOut);return code}}function withForbiddenGuidance(err,forbidden){if(forbidden===void 0||!(err instanceof ApiError)||err.status!==403)return err;const guidance=typeof forbidden==="function"?forbidden(err.body):forbidden;if(guidance===void 0)return err;const server=err.body?.error_description??err.body?.message;const wrapped=new ApiError(
|
|
59
59
|
err.status,err.body,"","");wrapped.message=server!==void 0&&server!==""?`${guidance}\uFF08\u30B5\u30FC\u30D0\u306E\u5FDC\u7B54: ${server}\uFF09`:guidance;return wrapped}function withRejectedGuidance(err,guidance){if(guidance===void 0||!(err instanceof ApiError)||err.status!==422)return err;const description=err.body?.error_description;const fallback=err.body?.message;const server=(typeof description==="string"&&description!==""?description:void 0)??(typeof fallback==="string"?fallback:"");const extra=guidance(
|
|
@@ -29,13 +29,13 @@ takesValue:true,placeholder:"<\u578B>"};var OUT_FLAG={name:"--out",summary:"\u66
|
|
|
29
29
|
<\u6DFB\u4ED8ID>"};var FORCE_FLAG={name:"--force",summary:"\u66F8\u304D\u51FA\u3057\u5148\u304C\u65E2\u306B\u3042\u308C\u3070\u4E0A\u66F8\u304D\u3059\u308B\uFF08\u65E2\u5B9A\u3067\u306F\u4E0A\u66F8\u304D\u3057\u306A\u3044\uFF09",takesValue:false};function taskPath(input){const projectId=encodeURIComponent(requireResolved(input,"projectId"));return`/api/v2/projects/${projectId}/tasks/${encodeURIComponent(requireResolved(input,"taskId"))}`}function taskAttachmentIds(body){const task=isRecord(body)?
|
|
30
30
|
body["task"]:void 0;if(!isRecord(task)){throw new ApiResponseError("\u30BF\u30B9\u30AF\u8A73\u7D30\u306E\u5FDC\u7B54\u306B task \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}const ids=task["attachment_ids"];if(ids===null||ids===void 0)return[];if(!Array.isArray(ids)||!ids.every(id=>typeof id==="string")){throw new ApiResponseError("\u30BF\u30B9\u30AF\u8A73\u7D30\u306E attachment_ids \u304C\u6587\u5B57\u5217\u306E\u914D\u5217\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
31
31
|
return ids}function attachmentRows(body){const data=isRecord(body)?body["data"]:void 0;if(!Array.isArray(data)){throw new ApiResponseError("\u6DFB\u4ED8\u4E00\u89A7\u306E\u5FDC\u7B54\u306B data \u914D\u5217\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return data}async function resolveTask(input,ctx,usage){const ref=singleRef(input,{flag:"--task",label:"\u30BF\u30B9\u30AF",usage});return withResolved(input,await resolveTaskLocation(
|
|
32
|
-
input,ctx,ref))}function localFile(input){const
|
|
33
|
-
if(
|
|
34
|
-
return{method:"POST",path:"/api/v2/attachments/upload-url",body:{file_name:requireResolved(input,"fileName"),content_type:requireResolved(input,"contentType"),file_size:Number(requireResolved(input,"fileSize")),source:TASK_SOURCE}}}function issued(body){const data=isRecord(body)?body["data"]:void 0;const id=isRecord(data)?data["id"]:void 0;const uploadUrl=isRecord(data)?data["
|
|
35
|
-
"\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9URL\u767A\u884C\u306E\u5FDC\u7B54\u306B data.id / data.upload_url \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return{id,uploadUrl}}async function upload(input,ctx){const file=requireResolved(input,"file");const size=Number(requireResolved(input,"
|
|
36
|
-
uploadUrlPlan(input)));const bytes=new Uint8Array(fs.readFileSync(file));if(bytes.byteLength!==size){throw new UsageError(`\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D\u306B\u30D5\u30A1\u30A4\u30EB\u306E\u5927\u304D\u3055\u304C\u5909\u308F\u308A\u307E\u3057\u305F\uFF08${size} \u2192 ${bytes.byteLength} \u30D0\u30A4\u30C8\uFF09: ${file}`)}await ctx.putSigned(uploadUrl,
|
|
37
|
-
id)?current:[...current,id];const updated=await ctx.send({method:"PUT",path:taskPath(input),body:{attachment_ids:next}});const linked=taskAttachmentIds(updated);if(!linked.includes(id)){throw new ApiResponseError("\u30BF\u30B9\u30AF\u66F4\u65B0\u306E\u5FDC\u7B54\u306E attachment_ids \u306B\u4ECA\u56DE\u306E\u6DFB\u4ED8\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
38
|
-
|
|
32
|
+
input,ctx,ref))}function localFile(input){const{file,size}=inspectLocalFile(input.flags.get("--file"),"--file","twp task attachment upload <\u30AD\u30FC|ID> --file <\u30D1\u30B9>");const nameFlag=input.flags.get("--name");const name=nameFlag!==void 0&&nameFlag.trim()!==""?nameFlag.trim():path.basename(file);const typeFlag=input.flags.get("--content-type");const contentType=typeFlag!==void 0&&typeFlag.trim()!==""?typeFlag.trim():contentTypeFor(name);return{file,name,size,contentType}}function inspectLocalFile(raw,flag,usage){
|
|
33
|
+
if(raw===void 0||raw.trim()===""){throw new UsageError(`${flag} \u306F\u5FC5\u9808\u3067\u3059`,usage)}const file=path.resolve(raw.trim());let stat;try{stat=fs.statSync(file)}catch{throw new UsageError(`\u30D5\u30A1\u30A4\u30EB\u304C\u3042\u308A\u307E\u305B\u3093\uFF08${flag}\uFF09: ${file}`)}if(!stat.isFile())throw new UsageError(`\u901A\u5E38\u306E\u30D5\u30A1\u30A4\u30EB\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${flag}\uFF09: ${file}`);if(stat.size===0)throw new UsageError(`\u7A7A\u306E\u30D5\u30A1\u30A4\u30EB\u306F\u30A2\u30C3\u30D7\u30ED\u30FC\
|
|
34
|
+
\u30C9\u3067\u304D\u307E\u305B\u3093\uFF08${flag}\uFF09: ${file}`);return{file,size:stat.size}}function uploadUrlPlan(input){return{method:"POST",path:"/api/v2/attachments/upload-url",body:{file_name:requireResolved(input,"fileName"),content_type:requireResolved(input,"contentType"),file_size:Number(requireResolved(input,"fileSize")),source:TASK_SOURCE}}}function issued(body){const data=isRecord(body)?body["data"]:void 0;const id=isRecord(data)?data["id"]:void 0;const uploadUrl=isRecord(data)?data["\
|
|
35
|
+
upload_url"]:void 0;if(!isSafePathSegment(id)||typeof uploadUrl!=="string"||!/^https:\/\//.test(uploadUrl)){throw new ApiResponseError("\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9URL\u767A\u884C\u306E\u5FDC\u7B54\u306B data.id / data.upload_url \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}return{id,uploadUrl}}async function upload(input,ctx){const file=requireResolved(input,"file");const size=Number(requireResolved(input,"fil\
|
|
36
|
+
eSize"));const contentType=requireResolved(input,"contentType");await checkUploadQuota(ctx,size);const{id,uploadUrl}=issued(await ctx.send(uploadUrlPlan(input)));const bytes=new Uint8Array(fs.readFileSync(file));if(bytes.byteLength!==size){throw new UsageError(`\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D\u306B\u30D5\u30A1\u30A4\u30EB\u306E\u5927\u304D\u3055\u304C\u5909\u308F\u308A\u307E\u3057\u305F\uFF08${size} \u2192 ${bytes.byteLength} \u30D0\u30A4\u30C8\uFF09: ${file}`)}await ctx.putSigned(uploadUrl,
|
|
37
|
+
bytes,contentType);try{const current=taskAttachmentIds(await ctx.send({method:"GET",path:taskPath(input)}));const next=current.includes(id)?current:[...current,id];const updated=await ctx.send({method:"PUT",path:taskPath(input),body:{attachment_ids:next}});const linked=taskAttachmentIds(updated);if(!linked.includes(id)){throw new ApiResponseError("\u30BF\u30B9\u30AF\u66F4\u65B0\u306E\u5FDC\u7B54\u306E attachment_ids \u306B\u4ECA\u56DE\u306E\u6DFB\u4ED8\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002")}
|
|
38
|
+
return{attachment_id:id,task_id:requireResolved(input,"taskId"),project_id:requireResolved(input,"projectId"),file_name:requireResolved(input,"fileName"),content_type:contentType,file_size:size,attachment_count:linked.length}}catch(err){ctx.warn(`\u6DFB\u4ED8 ${id} \u306F\u30B9\u30C8\u30EC\u30FC\u30B8\u3078\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u307E\u3067\u5B8C\u4E86\u3057\u307E\u3057\u305F\u304C\u3001\u30BF\u30B9\u30AF\u3078\u306E\u7D10\u3065\u3051\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002
|
|
39
39
|
\u672A\u7D10\u3065\u3051\u306E\u6DFB\u4ED8\u306F\u30B5\u30FC\u30D0\u304C\u4E00\u5B9A\u6642\u9593\uFF08\u7F72\u540DURL\u306E\u6709\u52B9\u671F\u9650\uFF0B1\u6642\u9593\uFF09\u5F8C\u306B\u81EA\u52D5\u3067\u524A\u9664\u3057\u307E\u3059\u3002\u3082\u3046\u4E00\u5EA6 twp task attachment upload \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);throw err}}async function list(input,ctx){const ids=taskAttachmentIds(await ctx.send({method:"GET",path:taskPath(input)}));const rows=[];for(let offset=0;offset<
|
|
40
40
|
ids.length;offset+=IDS_PER_REQUEST){const chunk=ids.slice(offset,offset+IDS_PER_REQUEST);rows.push(...attachmentRows(await ctx.send({method:"GET",path:"/api/v2/attachments",query:{ids:chunk.join(",")}})))}if(rows.length<ids.length){ctx.warn(`\u30BF\u30B9\u30AF\u306B\u7D10\u3065\u304F\u6DFB\u4ED8 ${ids.length} \u4EF6\u306E\u3046\u3061 ${ids.length-rows.length} \u4EF6\u306F\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u524A\u9664\u6E08\u307F\u304B\u3001\u95B2\u89A7\u3067\u304D\u307E\u305B\u3093\uFF09\u3002`)}
|
|
41
41
|
return{data:rows}}var taskAttachmentResource={name:"attachment",summary:"\u30BF\u30B9\u30AF\u306E\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\uFF08\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u30FB\u4E00\u89A7\u30FB\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\uFF09",operations:[{name:"list",summary:"\u30BF\u30B9\u30AF\u306E\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\u3092\u4E00\u89A7\u3059\u308B",usage:"twp task attachment list <\u30AD\u30FC|ID> [--project <\u30B3\u30FC\u30C9|ID>]",description:`${TASK_REF_HELP}
|
|
@@ -54,4 +54,4 @@ execute:list,summarize:body=>attachmentRows(body).map(row=>pick(row,LIST_COLUMNS
|
|
|
54
54
|
--dry-run \u306F 1 \u306E\u30EA\u30AF\u30A8\u30B9\u30C8\u3060\u3051\u3092\u8868\u793A\u3057\u307E\u3059\uFF082 \u4EE5\u964D\u306F 1 \u306E\u5FDC\u7B54\u306B\u4F9D\u5B58\u3059\u308B\u305F\u3081\uFF09\u3002`,flags:[FILE_FLAG,NAME_FLAG,CONTENT_TYPE_FLAG,TASK_REF_FLAG,PROJECT_FLAG],async prepare(input,ctx){const local=localFile(input);const resolved=await resolveTask(input,ctx,"twp task attachment upload help");return withResolved(resolved,{file:local.file,fileName:local.name,fileSize:String(local.size),
|
|
55
55
|
contentType:local.contentType})},plan:uploadUrlPlan,plannedNotes:input=>[`\u5B9F\u884C\u6642\u306F\u3001\u3053\u306E\u524D\u306B\u5BB9\u91CF\u691C\u67FB\uFF08POST /api/v2/storage/check-upload\uFF09\u3092\u9001\u308A\u3001\u3053\u306E\u3042\u3068\u7F72\u540DURL\u3078 ${requireResolved(input,"fileSize")} \u30D0\u30A4\u30C8\u3092 PUT \u3057\u3001\u30BF\u30B9\u30AF\u306E attachment_ids \u306B\u8FFD\u52A0\u3057\u3066 PUT \u3057\u307E\u3059\u3002`],execute:upload,summarize:body=>pick(body,UPLOAD_COLUMNS),
|
|
56
56
|
raw:body=>body},{name:"download",summary:"\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u3057\u3066\u30D5\u30A1\u30A4\u30EB\u3078\u66F8\u304D\u51FA\u3059",usage:"twp task attachment download <\u6DFB\u4ED8ID> --out <\u30D1\u30B9> [--force]",description:"\u6DFB\u4ED8 ID \u306F twp task attachment list \u306E id \u3067\u3059\u3002\n\u66F8\u304D\u51FA\u3057\u5148\u306F --out \u3067\u5FC5\u305A\u6307\u5B9A\u3057\u307E\u3059\uFF08\u6A19\u6E96\u51FA\u529B\u3078\u306F\u51FA\u3057\u307E\u305B\u3093\uFF09\u3002\u65E2\u5B58\u30D5\u30A1\u30A4\u30EB\u306F --force \u304C\u7121\u3051\u308C\u3070\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\u3002",
|
|
57
|
-
flags:[ATTACHMENT_REF_FLAG,OUT_FLAG,FORCE_FLAG],download:{outFlag:"--out",forceFlag:"--force"},plan(input){const id=singleRef(input,{flag:"--attachment",label:"\u6DFB\u4ED8ID",usage:"twp task attachment download help"});if(!isSafePathSegment(id))throw new UsageError(`\u6DFB\u4ED8ID \u306E\u5F62\u5F0F\u304C\u9055\u3044\u307E\u3059: ${id}`);return{method:"GET",path:`/api/v2/attachments/${encodeURIComponent(id)}/download`}},summarize:body=>body,raw:body=>body}]};export{classifyTaskRef,wantsPrivateSurface,taskSurface,rejectPrivateSurface,resolveTaskLocation,rejectRedundantProject,TASK_REF_FLAG,PROJECT_FLAG,TASK_REF_HELP,contentTypeFor,taskAttachmentResource};
|
|
57
|
+
flags:[ATTACHMENT_REF_FLAG,OUT_FLAG,FORCE_FLAG],download:{outFlag:"--out",forceFlag:"--force"},plan(input){const id=singleRef(input,{flag:"--attachment",label:"\u6DFB\u4ED8ID",usage:"twp task attachment download help"});if(!isSafePathSegment(id))throw new UsageError(`\u6DFB\u4ED8ID \u306E\u5F62\u5F0F\u304C\u9055\u3044\u307E\u3059: ${id}`);return{method:"GET",path:`/api/v2/attachments/${encodeURIComponent(id)}/download`}},summarize:body=>body,raw:body=>body}]};export{classifyTaskRef,wantsPrivateSurface,taskSurface,rejectPrivateSurface,resolveTaskLocation,rejectRedundantProject,TASK_REF_FLAG,PROJECT_FLAG,TASK_REF_HELP,contentTypeFor,inspectLocalFile,issued,taskAttachmentResource};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{isModeId,isPermissionModeId}from"./chunk-NAUH75MM.js";import{API_TOKEN,HELP_TOKEN,isDomainName}from"./chunk-
|
|
3
|
+
import{isModeId,isPermissionModeId}from"./chunk-NAUH75MM.js";import{API_TOKEN,HELP_TOKEN,isDomainName}from"./chunk-523KROGI.js";import{splitFlagToken}from"./chunk-QQRJLH6B.js";var BUILTIN_COMMANDS=["login","logout","whoami","update","task-loop"];var TASK_LOOP_ACTIONS=["run","status","stop","schedule","setup","charter","skill"];var VALUE_FLAGS=new Set(["-p","--print","--profile","--tenant","--mode","--permission-mode","--model","--allowed-tools","--disallowed-tools","--project","--engine","--interval","--max-cycles","--ai","--workspace","--ai-config-file","--now","--counts","--gate","--file","--out","--revision","--dir","--output","--query"]);var BOOLEAN_FLAGS=new Set(
|
|
4
4
|
["-h","--help","-v","--version","--no-tui","--doctor","--password","--token","--no-browser","--safe","--daemon","--force-runner","--force","--drain","--yes","-y","--no-ai-config-file","--verbose","--all","--dry-run","--debug","--refresh"]);function dispatch(argv,limit=2){const tokens=[];const indexes=[];let truncated=false;for(let i=0;i<argv.length;i++){const arg=argv[i];if(arg===void 0)continue;if(arg.startsWith("-")&&arg!=="-"){const{name,value:inline}=splitFlagToken(arg);if(BOOLEAN_FLAGS.has(
|
|
5
5
|
name)){if(inline!==void 0){truncated=true;break}continue}if(VALUE_FLAGS.has(name)){if(inline!==void 0)continue;const next=argv[i+1];if(next!==void 0&&(!next.startsWith("-")||next==="-"))i++;continue}truncated=true;break}if(arg===""||arg==="-")continue;if(tokens.length>=limit)break;tokens.push(arg);indexes.push(i)}return{tokens,indexes,truncated}}function isBuiltin(token){return token!==void 0&&BUILTIN_COMMANDS.includes(token)}function isTaskLoopAction(token){return token!==void 0&&TASK_LOOP_ACTIONS.
|
|
6
6
|
includes(token)}function resolveRoute(result){const{tokens,indexes}=result;const[first,second]=tokens;const firstIndex=indexes[0];if(first===void 0||firstIndex===void 0)return{kind:"none",consumed:[]};const consumed=[firstIndex];const secondIndex=indexes[1];if(isBuiltin(first)){if(first==="task-loop"&&isTaskLoopAction(second)){if(secondIndex!==void 0)consumed.push(secondIndex);return{kind:"builtin",command:first,action:second,consumed}}return{kind:"builtin",command:first,...first==="task-loop"?{
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
var LOADERS={"agent-loop":async()=>(await import("./agent-loop-SP2UKXIG.js")).agentLoopDomain,attendance:async()=>(await import("./attendance-LM3Q4TAU.js")).attendanceDomain,backlog:async()=>(await import("./backlog-2VHFVU5C.js")).backlogDomain,company:async()=>(await import("./company-6HMFGVPJ.js")).companyDomain,customer:async()=>(await import("./company-6HMFGVPJ.js")).customerDomain,department:async()=>(await import("./department-DH5YABBF.js")).departmentDomain,estimate:async()=>(await import("./sales-OFEVE2PG.js")).
|
|
4
|
+
estimateDomain,inquiry:async()=>(await import("./inquiry-67OW3HBZ.js")).inquiryDomain,invoice:async()=>(await import("./sales-OFEVE2PG.js")).invoiceDomain,"job-title":async()=>(await import("./job-title-YEIANJNC.js")).jobTitleDomain,leave:async()=>(await import("./leave-XXDCHUGK.js")).leaveDomain,media:async()=>(await import("./media-NZD6J7KE.js")).mediaDomain,notification:async()=>(await import("./notification-BQ4ODX6U.js")).notificationDomain,position:async()=>(await import("./position-WR5YODDU.js")).
|
|
5
|
+
positionDomain,project:async()=>(await import("./project-ROLQ535L.js")).projectDomain,prospect:async()=>(await import("./prospect-YZUHE7PL.js")).prospectDomain,report:async()=>(await import("./report-SGAVGU4G.js")).reportDomain,shift:async()=>(await import("./attendance-lists-PR6NQDQB.js")).shiftDomain,storage:async()=>(await import("./storage-ANKKJJJO.js")).storageDomain,task:async()=>(await import("./task-IE7DNU34.js")).taskDomain,user:async()=>(await import("./user-UJIB3SCU.js")).
|
|
6
|
+
userDomain,workchange:async()=>(await import("./attendance-lists-PR6NQDQB.js")).workchangeDomain,workflow:async()=>(await import("./workflow-QWVZH4NG.js")).workflowDomain};async function loadDomain(name){return LOADERS[name]()}export{loadDomain};
|