@tocca-systems/twp-cli 0.38.0 → 0.40.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 +22 -0
- package/README.md +213 -3
- package/dist/{api-command-BZVUZIOB.js → api-command-7PZCMQO5.js} +4 -4
- package/dist/{app-SNRFIHTQ.js → app-PNHDMD3V.js} +4 -4
- package/dist/{backlog-33ELMSV6.js → backlog-ISEIWKMQ.js} +1 -1
- package/dist/chunk-43OMEGNH.js +94 -0
- package/dist/{chunk-HAIZHSNZ.js → chunk-6ZUVESMI.js} +1 -1
- package/dist/chunk-7ACENLLZ.js +147 -0
- package/dist/{chunk-QBA6THJ5.js → chunk-B7YCG2T7.js} +1 -1
- package/dist/{chunk-IRT7VFG4.js → chunk-BPCK5RAB.js} +1 -1
- package/dist/{chunk-ADQD5OPN.js → chunk-BZ7ULFR3.js} +15 -14
- package/dist/{chunk-ZST7XESB.js → chunk-BZAXQOLB.js} +54 -43
- package/dist/chunk-EOSSFTNG.js +4 -0
- package/dist/chunk-FKS2Z34P.js +70 -0
- package/dist/{chunk-57HDZYSN.js → chunk-H54MGGHB.js} +1 -1
- package/dist/{chunk-TAN5I2DP.js → chunk-I4ARX6NM.js} +1 -1
- package/dist/chunk-L6AHCTQZ.js +8 -0
- package/dist/chunk-PEM3HR7L.js +58 -0
- package/dist/{chunk-VECUCVIY.js → chunk-PKWMJIBM.js} +1 -1
- package/dist/{chunk-BUZKNZ45.js → chunk-UT4FACHN.js} +5 -3
- package/dist/chunk-V3GQEUYI.js +16 -0
- package/dist/{chunk-FEOST3GF.js → chunk-VK5T7ULK.js} +1 -1
- package/dist/{chunk-LS7P3IWP.js → chunk-WV3ZKUF4.js} +25 -23
- package/dist/{chunk-OHIERIBW.js → chunk-X5IVIOGL.js} +1 -1
- package/dist/chunk-XN5TUZOT.js +48 -0
- package/dist/cli.js +247 -8
- package/dist/{commands-7PGS2PTH.js → commands-PG5VVBKO.js} +1 -1
- package/dist/company-4Z4JJVA7.js +71 -0
- package/dist/{completion-3X7HPIPM.js → completion-EFGQJDIU.js} +1 -1
- package/dist/contract-BQ76SGWV.js +86 -0
- package/dist/{department-PVUB3ZPI.js → department-YHZRSWLB.js} +1 -1
- package/dist/deposit-U4AVQH5O.js +4 -0
- package/dist/estimate-U2K7DPGH.js +173 -0
- package/dist/{inquiry-CUK2LWQK.js → inquiry-5D4U6CLU.js} +1 -1
- package/dist/invoice-2VLK2BFV.js +210 -0
- package/dist/{job-title-CZRZFVUU.js → job-title-G7MIYWVA.js} +1 -1
- package/dist/{knowledge-XYLG42MB.js → knowledge-7QDC775Q.js} +1 -1
- package/dist/{leave-DL3JPO5I.js → leave-GHFJOGNC.js} +1 -1
- package/dist/{media-CMNIZUPY.js → media-XO6X3UQT.js} +1 -1
- package/dist/{notification-ULATH7AC.js → notification-SUSR5NGQ.js} +1 -1
- package/dist/{oneshot-RYWJ6ECA.js → oneshot-UGYF2PLB.js} +1 -1
- package/dist/{position-ICOGEMRG.js → position-UY33ETLX.js} +1 -1
- package/dist/{prospect-MB2OP7L2.js → prospect-G426O6XL.js} +1 -1
- package/dist/purchase-3GGAQRE6.js +214 -0
- package/dist/receivable-TNH4KCUO.js +4 -0
- package/dist/{registry-XBYUPKQQ.js → registry-ODJB7AS3.js} +1 -1
- package/dist/{render-MTSSHDAZ.js → render-F4MRN2FQ.js} +1 -1
- package/dist/{report-JL7UJB4G.js → report-UC2PCK7B.js} +1 -1
- package/dist/run-GDYEOQQK.js +4 -0
- package/dist/sales-master-ORLR5VK4.js +71 -0
- package/dist/sales-numbering-MBFKVR2C.js +4 -0
- package/dist/supplier-payment-AFJ7G6AP.js +110 -0
- package/dist/{task-CMCHUX2D.js → task-S3BBBELE.js} +2 -2
- package/dist/{user-5JXFO56G.js → user-O7H5PD4N.js} +1 -1
- package/dist/{workflow-XBUMFS2G.js → workflow-2YL2OF2Y.js} +1 -1
- package/package.json +1 -1
- package/dist/chunk-GLBQAXWC.js +0 -6
- package/dist/chunk-O4NSYHR4.js +0 -3
- package/dist/company-GMCHRVHF.js +0 -161
- package/dist/run-6JRHCC67.js +0 -4
- package/dist/sales-GJKW7VVG.js +0 -4
|
@@ -5,8 +5,10 @@ import{stripTerminalControls}from"./chunk-NHYMHCAT.js";var SENSITIVE_HEADERS=new
|
|
|
5
5
|
item=>redactSecretValues(item));if(value!==null&&typeof value==="object"){const out={};for(const[key,item]of Object.entries(value)){out[key]=SECRET_KEY_NAME.test(key)?REDACTED:redactSecretValues(item)}return out}return value}function formatHeaders(headers){if(!headers)return[];const entries=headers instanceof Headers?[...headers.entries()]:Array.isArray(headers)?headers:Object.entries(headers);return entries.map(([name,value])=>{const shown=SENSITIVE_HEADERS.has(name.toLowerCase())?REDACTED:redactSecrets(
|
|
6
6
|
String(value));return` ${name.toLowerCase()}: ${shown}`})}var BODY_LIMIT=4e3;function formatBody(raw){const safe=redactSecrets(stripTerminalControls(raw));return safe.length>BODY_LIMIT?`${safe.slice(0,BODY_LIMIT)}
|
|
7
7
|
\u2026\uFF08\u4EE5\u964D ${safe.length-BODY_LIMIT} \u6587\u5B57\u3092\u7701\u7565\uFF09`:safe}function isTextualContentType(contentType){if(contentType===null)return false;return/^\s*(text\/|application\/(json|xml|javascript|x-www-form-urlencoded)|application\/[\w.+-]*\+(json|xml))/i.test(contentType)}function withDebug(inner,options={}){const write=options.write??(text=>void process.stderr.write(text));const now=options.now??(()=>Date.now());return async(input,init)=>{const method=init?.method??
|
|
8
|
-
"GET";const lines=[`[debug] \u2192 ${method} ${redactSecrets(input)}`,...formatHeaders(init?.headers)];if(typeof init?.body==="string")lines.push(` ${formatBody(init.body)}`);else if(init?.body instanceof Uint8Array)lines.push(` \uFF08\u672C\u6587\u306F ${init.body.byteLength} \u30D0\u30A4\u30C8\u306E\u30D0\u30A4\u30C8\u5217\u3002\u51FA\u529B\u3057\u306A\u3044\uFF09`);
|
|
8
|
+
"GET";const lines=[`[debug] \u2192 ${method} ${redactSecrets(input)}`,...formatHeaders(init?.headers)];if(options.omitBodies!==void 0&&init?.body!==void 0&&init.body!==null)lines.push(` \uFF08\u672C\u6587\u306F${options.omitBodies}\u305F\u3081\u51FA\u529B\u3057\u306A\u3044\uFF09`);else if(typeof init?.body==="string")lines.push(` ${formatBody(init.body)}`);else if(init?.body instanceof Uint8Array)lines.push(` \uFF08\u672C\u6587\u306F ${init.body.byteLength} \u30D0\u30A4\u30C8\u306E\u30D0\u30A4\u30C8\u5217\u3002\u51FA\u529B\u3057\u306A\u3044\uFF09`);
|
|
9
|
+
write(`${lines.join("\n")}
|
|
9
10
|
`);const started=now();let res;try{res=await inner(input,init)}catch(err){write(`[debug] \u2717 \u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F (${now()-started}ms): ${redactSecrets(err.message)}
|
|
10
|
-
`);throw err}const out=[`[debug] \u2190 ${res.status} ${res.statusText} (${now()-started}ms)`,...formatHeaders(res.headers)];const contentType=res.headers.get("content-type");const attachment=/^\s*attachment\b/i.test(res.headers.get("content-disposition")??"");if(
|
|
11
|
-
headers.get("content-length");out.push(` \uFF08\u672C\u6587\u306F ${contentType??"content-type \u4E0D\u660E"}\u30FB${length===null?"\u30B5\u30A4\u30BA\u4E0D\u660E":`${length} \u30D0\u30A4\u30C8`}\u3002${attachment?"\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u306E\u672C\u4F53\u306E\u305F\u3081":"\u30C6\u30AD\u30B9\u30C8\u3067\u306A\u3044\u305F\u3081"}\u51FA\u529B\u3057\u306A\u3044\
|
|
11
|
+
`);throw err}const out=[`[debug] \u2190 ${res.status} ${res.statusText} (${now()-started}ms)`,...formatHeaders(res.headers)];const contentType=res.headers.get("content-type");const attachment=/^\s*attachment\b/i.test(res.headers.get("content-disposition")??"");if(options.omitBodies!==void 0){out.push(` \uFF08\u672C\u6587\u306F${options.omitBodies}\u305F\u3081\u51FA\u529B\u3057\u306A\u3044\uFF09`)}else if(isTextualContentType(contentType)&&!attachment){const raw=await res.clone().text().catch(()=>"\
|
|
12
|
+
\uFF08\u672C\u6587\u3092\u8AAD\u3081\u307E\u305B\u3093\u3067\u3057\u305F\uFF09");if(raw!=="")out.push(` ${formatBody(raw)}`)}else{const length=res.headers.get("content-length");out.push(` \uFF08\u672C\u6587\u306F ${contentType??"content-type \u4E0D\u660E"}\u30FB${length===null?"\u30B5\u30A4\u30BA\u4E0D\u660E":`${length} \u30D0\u30A4\u30C8`}\u3002${attachment?"\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u306E\u672C\u4F53\u306E\u305F\u3081":"\u30C6\u30AD\u30B9\u30C8\u3067\u306A\u3044\u305F\u3081"}\u51FA\u529B\u3057\u306A\u3044\
|
|
13
|
+
\uFF09`)}write(`${out.join("\n")}
|
|
12
14
|
`);return res}}export{redactSecrets,redactSecretValues,withDebug};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{featureLicenseGuidance}from"./chunk-BZ7ULFR3.js";import{isExactNumericId}from"./chunk-BZAXQOLB.js";import{nonEmpty}from"./chunk-5R4SEO3I.js";import{UsageError}from"./chunk-7WSNIXTQ.js";var PDF_PATH="/api/v2/sales/pdf";var FEATURE_DENIED="\u3053\u306E\u6A5F\u80FD\u306B\u30A2\u30AF\u30BB\u30B9\u3059\u308B\u6A29\u9650\u304C\u3042\u308A\u307E\u305B\u3093\u3002";function pdfForbidden(body){if(body?.error==="permission_denied"||body?.error==="forbidden"&&body.error_description===FEATURE_DENIED){return featureLicenseGuidance("\u8CA9\u58F2\u7BA1\u7406")}const reason=body?.error;if(typeof reason==="string"&&reason.endsWith("\u6A29\u9650\u304C\u3042\u308A\u307E\u305B\u3093")){return`${reason}\
|
|
4
|
+
\uFF08\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306B\u7D10\u3065\u304F\u66F8\u985E\u306F\u305D\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306E\u30E1\u30F3\u30D0\u30FC\u3001\u7D10\u3065\u304B\u306A\u3044\u66F8\u985E\u306F\u4F5C\u6210\u8005\u30FB\u62C5\u5F53\u8005\u3068\u7BA1\u7406\u8005\u3060\u3051\u304C\u51FA\u529B\u3067\u304D\u307E\u3059\uFF09`}return void 0}var ESTIMATE={name:"estimate",label:"\u898B\u7A4D",noExample:"EST0000063",defaultKind:"estimate",kinds:{estimate:{segment:"estimate",label:"\u898B\u7A4D\
|
|
5
|
+
\u66F8"},order:{segment:"order",label:"\u6CE8\u6587\u66F8"},"order-acceptance":{segment:"order-acceptance",label:"\u6CE8\u6587\u8ACB\u66F8"}}};var INVOICE={name:"invoice",label:"\u8ACB\u6C42",noExample:"INV0000170",defaultKind:"invoice",kinds:{invoice:{segment:"invoice",label:"\u8ACB\u6C42\u66F8"},delivery:{segment:"delivery",label:"\u7D0D\u54C1\u66F8"},inspection:{segment:"inspection",label:"\u691C\u53CE\u66F8"}}};var PURCHASE={name:"purchase",label:"\u4ED5\u5165",defaultKind:"order",kinds:{order:{
|
|
6
|
+
segment:"purchase-order",label:"\u6CE8\u6587\u66F8"},"order-acceptance":{segment:"purchase-order-acceptance",label:"\u6CE8\u6587\u8ACB\u66F8"}}};var OUT_FLAG={name:"--out",summary:"\u66F8\u304D\u51FA\u3057\u5148\u306E\u30D5\u30A1\u30A4\u30EB\u30D1\u30B9\uFF08\u5FC5\u9808\uFF09",takesValue:true,placeholder:"<\u30D1\u30B9.pdf>"};var FORCE_FLAG={name:"--force",summary:"\u65E2\u5B58\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u4E0A\u66F8\u304D\u3059\u308B",takesValue:false};function usageOf(resource){return`\
|
|
7
|
+
twp ${resource.name} download help`}function kindList(resource){return Object.entries(resource.kinds).map(([key,kind])=>`${key}\uFF08${kind.label}\uFF09`).join(" / ")}function kindOf(input,resource){const raw=nonEmpty(input.flags,"--kind")?.trim()??resource.defaultKind;if(!Object.hasOwn(resource.kinds,raw)){throw new UsageError(`--kind \u306F ${kindList(resource)} \u306E\u3069\u308C\u304B\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${raw}`,usageOf(resource))}return resource.kinds[raw]}
|
|
8
|
+
function recordId(input,resource){const[raw,...rest]=input.args;const id=raw?.trim()??"";if(id==="")throw new UsageError(`${resource.label}\u306E ID \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`,usageOf(resource));if(rest.length>0)throw new UsageError(`\u53D7\u3051\u53D6\u308C\u308B${resource.label}\u306E ID \u306F1\u3064\u3060\u3051\u3067\u3059: ${rest.join(" ")}`,usageOf(resource));if(!isExactNumericId(id)){throw new UsageError(`${resource.label}\u306E ID \u306F\u6570\u5B57\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${id}`,
|
|
9
|
+
`${resource.label}\u756A\u53F7${resource.noExample===void 0?"":`\uFF08${resource.noExample} \u306E\u3088\u3046\u306A\u5024\uFF09`}\u3067\u63A2\u3059\u306A\u3089 twp ${resource.name} list --keyword <\u756A\u53F7> \u306E id \u5217\u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044\u3002`)}return id}function pdfOperation(resource){const labels=Object.values(resource.kinds).map(kind=>kind.label);const defaultLabel=resource.kinds[resource.defaultKind]?.label??resource.defaultKind;return{name:"download",
|
|
10
|
+
summary:`${resource.label}\u306E\u5E33\u7968 PDF\uFF08${labels.join("\u30FB")}\uFF09\u3092\u66F8\u304D\u51FA\u3059\uFF08--out\u30FB--kind\uFF09`,usage:`twp ${resource.name} download <${resource.label}ID> --out <\u30D1\u30B9.pdf> [--kind ${Object.keys(resource.kinds).join("|")}] [--force]`,description:`\u753B\u9762\u306E\u300CPDF\u51FA\u529B\u300D\u3068\u540C\u3058\u5E33\u7968\u3092\u30D5\u30A1\u30A4\u30EB\u306B\u66F8\u304D\u51FA\u3057\u307E\u3059\u3002--kind \u3092\u7701\u304F\u3068${defaultLabel}\
|
|
11
|
+
\u3067\u3059\u3002
|
|
12
|
+
--kind: ${kindList(resource)}
|
|
13
|
+
ID \u306F twp ${resource.name} list \u306E id \u5217\u306E\u6570\u5B57\u3067\u3059\uFF08${resource.label}\u756A\u53F7\u3067\u306F\u3042\u308A\u307E\u305B\u3093\uFF09\u3002
|
|
14
|
+
\u5370\u5F71\u30FB\u62BC\u5370\u306E\u6709\u7121\u306F\u30B5\u30FC\u30D0\u304C\u66F8\u985E\u3054\u3068\u306B\u6C7A\u3081\u307E\u3059\uFF08\u753B\u9762\u3067\u51FA\u529B\u3057\u305F\u3082\u306E\u3068\u540C\u3058\u306B\u306A\u308A\u307E\u3059\uFF09\u3002
|
|
15
|
+
\u65E2\u5B58\u306E\u30D5\u30A1\u30A4\u30EB\u306F\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\uFF08\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 --force\uFF09\u3002\u6A19\u6E96\u51FA\u529B\u3078\u306F\u51FA\u3057\u307E\u305B\u3093\u3002`,flags:[OUT_FLAG,FORCE_FLAG,{name:"--kind",summary:`\u5E33\u7968\u306E\u7A2E\u5225\uFF08${kindList(resource)}\u3002\u65E2\u5B9A ${resource.defaultKind}\uFF09`,takesValue:true,placeholder:"<\u7A2E\u5225>"}],download:{outFlag:OUT_FLAG.name,forceFlag:FORCE_FLAG.name},forbidden:pdfForbidden,
|
|
16
|
+
plan:input=>({method:"GET",path:`${PDF_PATH}/${kindOf(input,resource).segment}/${encodeURIComponent(recordId(input,resource))}`}),summarize:body=>body,raw:body=>body}}var estimatePdfOperation=pdfOperation(ESTIMATE);var invoicePdfOperation=pdfOperation(INVOICE);var purchasePdfOperation=pdfOperation(PURCHASE);export{estimatePdfOperation,invoicePdfOperation,purchasePdfOperation};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{redactSecretValues,redactSecrets}from"./chunk-
|
|
3
|
+
import{redactSecretValues,redactSecrets}from"./chunk-UT4FACHN.js";import{formatOutput}from"./chunk-K2ONOH3L.js";import{stripTerminalControls}from"./chunk-NHYMHCAT.js";function renderOutput(value,format,noRedact=false){if(noRedact)return formatOutput(value,format);return redactSecrets(formatOutput(redactSecretValues(value),format))}function renderDocument(text,noRedact=false){const visible=stripTerminalControls(text);return noRedact?visible:redactSecrets(visible)}export{renderOutput,renderDocument};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{evaluateQuery}from"./chunk-GDM2QUBL.js";import{renderDocument,renderOutput}from"./chunk-
|
|
4
|
-
import{GLOBAL_OPTIONS_HELP}from"./chunk-
|
|
5
|
-
stripTerminalControls}from"./chunk-NHYMHCAT.js";import{DEFAULT_MAX_ITEMS,DEFAULT_MAX_PAGES,nextPageNotes,positiveInteger,shellQuote}from"./chunk-5R4SEO3I.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{evaluateQuery}from"./chunk-GDM2QUBL.js";import{renderDocument,renderOutput}from"./chunk-VK5T7ULK.js";import{redactSecretValues,redactSecrets,withDebug}from"./chunk-UT4FACHN.js";import{loadDomain}from"./chunk-L6AHCTQZ.js";import{parseOperationArgs}from"./chunk-IOGVQVGD.js";import{Resolver,requireDefaultProject}from"./chunk-BZAXQOLB.js";import{ApiError,MultipartBody,TwpApiClient,appendQuery}from"./chunk-IF2K4PM5.js";import{ResolveError}from"./chunk-GMBJTG6A.js";
|
|
4
|
+
import{GLOBAL_OPTIONS_HELP}from"./chunk-I4ARX6NM.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-EOSSFTNG.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-5R4SEO3I.js";import{isRecord}from"./chunk-ZWVYVS2A.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]))}
|
|
@@ -16,26 +16,27 @@ ${alignedList(subresources.map(sub=>[`${sub.name} <\u64CD\u4F5C>`,sub.summary]))
|
|
|
16
16
|
twp ${path2} <\u64CD\u4F5C> ${HELP_TOKEN} \u305D\u306E\u64CD\u4F5C\u306E\u8A73\u3057\u3044\u30D8\u30EB\u30D7
|
|
17
17
|
${operationSection}${subSection}
|
|
18
18
|
${GLOBAL_OPTIONS_HELP}
|
|
19
|
-
`}function renderOperationHelp(op,path2){const sections=[`twp ${path2} ${op.name} \u2014 ${op.summary}`,"","\u4F7F\u3044\u65B9:",` ${op.usage}`];if(op.description!==void 0){sections.push("",...op.description.split("\n"))}if(op.destructive===true){sections.push(""
|
|
20
|
-
alignedList(flags.map(flag=>[flag.takesValue?`${flag.name} ${flag.placeholder??"<\u5024>"}`:flag.name,flag.summary])))}sections.push("",GLOBAL_OPTIONS_HELP,"");return sections.join("\n")}function renderUnknownOperation(resource,path2,attempted){const names=[...resource.operations.map(op=>op.name),...subresourcesOf(resource).map(sub=>`${sub.name} <\u64CD\u4F5C>`)].join(" / ");return attempted===void 0?`twp ${path2} \u306B\u306F\u64CD\u4F5C\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\uFF08${names}\
|
|
19
|
+
`}function renderOperationHelp(op,path2){const sections=[`twp ${path2} ${op.name} \u2014 ${op.summary}`,"","\u4F7F\u3044\u65B9:",` ${op.usage}`];if(op.description!==void 0){sections.push("",...op.description.split("\n"))}if(op.destructive===true){sections.push("",`\u26A0 ${op.confirmation??"\u7834\u58CA\u7684\u306A\u64CD\u4F5C"}\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u304C\u5FC5\u8981\u3067\u3059\u3002`)}const flags=withCommonFlags(op.flags);if(flags.length>0){sections.push(
|
|
20
|
+
"","\u30AA\u30D7\u30B7\u30E7\u30F3:",alignedList(flags.map(flag=>[flag.takesValue?`${flag.name} ${flag.placeholder??"<\u5024>"}`:flag.name,flag.summary])))}sections.push("",GLOBAL_OPTIONS_HELP,"");return sections.join("\n")}function renderUnknownOperation(resource,path2,attempted){const names=[...resource.operations.map(op=>op.name),...subresourcesOf(resource).map(sub=>`${sub.name} <\u64CD\u4F5C>`)].join(" / ");return attempted===void 0?`twp ${path2} \u306B\u306F\u64CD\u4F5C\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\uFF08${names}\
|
|
21
21
|
\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`:`twp ${path2} \u306B\u300C${attempted}\u300D\u3068\u3044\u3046\u64CD\u4F5C\u306F\u3042\u308A\u307E\u305B\u3093\uFF08${names}\uFF09\u3002\u8A73\u3057\u304F\u306F twp ${path2} ${HELP_TOKEN}`}var writeOut=text=>void process.stdout.write(text);var writeErr=text=>void process.stderr.write(text);function line(text){return text===""?"":text.endsWith("\n")?text:`${text}
|
|
22
22
|
`}function outputValue(operation,format,body){return format==="json"?operation.raw(body):operation.summarize(body)}function requiresYes(operation,yes){return operation.destructive===true&&!yes}function exitCodeForStatus(status){if(status===401)return EXIT_AUTH;if(status===429)return EXIT_API_SERVER;if(status>=400&&status<500)return EXIT_API_CLIENT;return EXIT_API_SERVER}function exitCodeFor(err){if(err instanceof UsageError)return EXIT_USAGE;if(err instanceof NotLoggedInError||err instanceof SessionExpiredError)
|
|
23
23
|
return EXIT_AUTH;if(err instanceof ApiError)return exitCodeForStatus(err.status);if(err instanceof ApiRejectedError)return EXIT_API_CLIENT;if(err instanceof ApiResponseError||err instanceof NetworkError)return EXIT_API_SERVER;if(err instanceof ResolveError){return err.status===null?EXIT_API_SERVER:exitCodeForStatus(err.status)}return EXIT_FAILURE}function safeText(text){return redactSecrets(stripTerminalControls(text))}function reportError(err,format,code,write=writeErr){const message=safeText(err instanceof
|
|
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 instanceof MultipartBody?plan.body.toJSON():plan.body;
|
|
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:{"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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.
|
|
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.
|
|
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
|
|
36
|
-
|
|
37
|
-
vocabulary,cursor)} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059`)}async function fetchAllPages(args){
|
|
38
|
-
args.firstPage:await send(args.client,args.apiUrl,plan)}catch(err){if(page>1){(args.warn??writeErr)(`${vocabulary.
|
|
27
|
+
`)}function dryRunValue(apiUrl,plan,sensitiveBody){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;if(sensitiveBody!==void 0&&isRecord(value["body"])){const hidden=`\uFF08${sensitiveBody}\u305F\u3081\u8868\u793A\u3057\u306A\u3044\u30FB--no-redact \u3067\u8868\u793A\uFF09`;value["body"]=Object.fromEntries(Object.keys(value["body"]).map(key=>[key,hidden]))}return value}
|
|
28
|
+
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(`${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:{"Con\
|
|
29
|
+
tent-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\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:"\
|
|
30
|
+
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.status}\uFF09`)}return{bytes:new Uint8Array(await res.arrayBuffer()),contentType:res.headers.get("content-type")}}function resolveDownloadTarget(spec,commandPath,operationName,input){
|
|
31
|
+
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`)}return{out:path.resolve(raw.trim()),force:input.flags.has(spec.forceFlag)}}function assertWritableTarget(target,forceFlag){
|
|
32
|
+
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.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}`,
|
|
33
|
+
"\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.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.
|
|
34
|
+
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,{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.
|
|
35
|
+
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??[]){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,
|
|
36
|
+
...Object.keys(captured).length>0?{headers:captured}:{}}}function resumeHint(vocabulary,cursor){return vocabulary.resume!==void 0?vocabulary.resume(cursor):`${vocabulary.resumeFlag} ${shellQuote(cursor)}`}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){
|
|
37
|
+
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 ${resumeHint(vocabulary,cursor)} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059`)}async function fetchAllPages(args){
|
|
38
|
+
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:"";let scanTruncated=false;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??writeErr)(`${vocabulary.
|
|
39
|
+
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 ${resumeHint(vocabulary,stripTerminalControls(sent))} \u304B\u3089\u518D\u958B\u3067\u304D\u307E\u3059\u3002
|
|
39
40
|
`)}throw err}for(const item of paging.items(body))merged.push(item);if(typeof body==="object"&&body!==null&&body["scan_truncated"]===true)scanTruncated=true;const next=paging.nextCursor(body);if(next===null){const combined=paging.withItems(body,merged);const flagged=scanTruncated&&typeof combined==="object"&&combined!==null&&!Array.isArray(combined)?{...combined,scan_truncated:true}:combined;return{body:flagged,pages:page,count:merged.length}}if(merged.length>=maxItems)throw capExceeded(vocabulary,
|
|
40
41
|
`\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}\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`)}
|
|
41
42
|
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")??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&&
|
|
@@ -45,13 +46,14 @@ resolved);return resolved}}}async function runDomain(options){const{globals}=opt
|
|
|
45
46
|
null){throw new UsageError(`--output \u306B\u300C${globals.output??""}\u300D\u306F\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093`,`\u6307\u5B9A\u3067\u304D\u308B\u306E\u306F ${OUTPUT_FORMATS.join(" / ")} \u3067\u3059`)}const domain=await loadDomain(options.domain);if(options.operation===HELP_TOKEN||options.help&&options.operation===void 0){const[extra,...rest2]=options.argv;if(extra===void 0){out(renderResourceHelp(domain,domain.name));return EXIT_OK}const target=domain.subresources?.find(resource2=>resource2.
|
|
46
47
|
name===extra);if(target===void 0||rest2.length>0){throw new UsageError(renderUnknownOperation(domain,domain.name,extra))}out(renderResourceHelp(target,`${domain.name} ${extra}`));return EXIT_OK}const sub=domain.subresources?.find(resource2=>resource2.name===options.operation);const resource=sub??domain;const path2=sub===void 0?domain.name:`${domain.name} ${sub.name}`;const operationName=sub===void 0?options.operation:options.argv[0];const rest=sub===void 0?options.argv:options.argv.slice(1);if(sub!==
|
|
47
48
|
void 0&&(operationName===HELP_TOKEN||options.help&&operationName===void 0)){out(renderResourceHelp(sub,path2));return EXIT_OK}const operation=resource.operations.find(op=>op.name===operationName);if(operation===void 0){throw new UsageError(renderUnknownOperation(resource,path2,operationName))}forbidden=operation.forbidden;rejected=operation.rejected;if(options.help||rest[0]===HELP_TOKEN){out(renderOperationHelp(operation,path2));return EXIT_OK}const input=parseOperationArgs(rest,withCommonFlags(
|
|
48
|
-
operation.flags));const noRedact=input.flags.has("--no-redact");if(!globals.dryRun&&requiresYes(operation,globals.yes)){throw new UsageError(`twp ${path2} ${operation.name} \u306F\u7834\u58CA\u7684\u306A\u64CD\u4F5C\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`)}const paging=resolvePaging(operation,path2,input);const downloadTarget=operation.download===void 0?void 0:resolveDownloadTarget(operation.
|
|
49
|
-
input);const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(profile,stored?.api_url);const transport=options.fetchImpl??httpFetch;const fetchImpl=globals.debug?withDebug(transport,{write:errOut}):transport;const session=new AuthSession(profile.name,apiUrl,process.env,fetchImpl);const client=new TwpApiClient(apiUrl,session,fetchImpl,options.version);const ctx=buildPrepareContext(
|
|
50
|
-
name)}),profileName:profile.name,env:process.env,cwd:process.cwd()});const prepared=operation.prepare===void 0?input:await operation.prepare(input,ctx);const plan=operation.plan(prepared);if(operation.execute!==void 0&&(operation.download!==void 0||operation.paging!==void 0||operation.fetchCached!==void 0)){throw new Error(`twp ${path2} ${operation.name}: execute \u306F download / paging /
|
|
51
|
-
if(operation.narrow!==void 0&&(operation.execute!==void 0||operation.download!==void 0||operation.fetchCached!==void 0)){throw new Error(`twp ${path2} ${operation.name}: narrow \u306F execute / download / fetchCached \u3068\u540C\u6642\u306B\u5BA3\u8A00\u3067\u304D\u307E\u305B\u3093\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}if(operation.invalidates!==void 0&&(operation.fetchCached!==
|
|
52
|
-
\u8AA4\u308A\uFF09`)}if(operation.fetchCached!==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`)}
|
|
49
|
+
operation.flags));const noRedact=input.flags.has("--no-redact");if(!globals.dryRun&&requiresYes(operation,globals.yes)){throw new UsageError(`twp ${path2} ${operation.name} \u306F${operation.confirmation??"\u7834\u58CA\u7684\u306A\u64CD\u4F5C"}\u3067\u3059\u3002\u5B9F\u884C\u3059\u308B\u306B\u306F --yes \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002`)}const paging=resolvePaging(operation,path2,input);const downloadTarget=operation.download===void 0?void 0:resolveDownloadTarget(operation.
|
|
50
|
+
download,path2,operation.name,input);const stored=loadCredentials(profile.name);const apiUrl=effectiveApiUrl(profile,stored?.api_url);const transport=options.fetchImpl??httpFetch;const fetchImpl=globals.debug?withDebug(transport,{write:errOut,...operation.sensitiveBody!==void 0?{omitBodies:operation.sensitiveBody}:{}}):transport;const session=new AuthSession(profile.name,apiUrl,process.env,fetchImpl);const client=new TwpApiClient(apiUrl,session,fetchImpl,options.version);const ctx=buildPrepareContext(
|
|
51
|
+
{resolver:new Resolver(client,{profile:profile.name,refresh:globals.refresh,...profileAliases(profile.name)}),profileName:profile.name,env:process.env,cwd:process.cwd()});const prepared=operation.prepare===void 0?input:await operation.prepare(input,ctx);const plan=operation.plan(prepared);if(operation.execute!==void 0&&(operation.download!==void 0||operation.paging!==void 0||operation.fetchCached!==void 0)){throw new Error(`twp ${path2} ${operation.name}: execute \u306F download / paging / fetchCache\
|
|
52
|
+
d \u3068\u540C\u6642\u306B\u5BA3\u8A00\u3067\u304D\u307E\u305B\u3093\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}if(operation.narrow!==void 0&&(operation.execute!==void 0||operation.download!==void 0||operation.fetchCached!==void 0)){throw new Error(`twp ${path2} ${operation.name}: narrow \u306F execute / download / fetchCached \u3068\u540C\u6642\u306B\u5BA3\u8A00\u3067\u304D\u307E\u305B\u3093\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}if(operation.invalidates!==void 0&&(operation.fetchCached!==
|
|
53
|
+
void 0||plan.method==="GET")){throw new Error(`twp ${path2} ${operation.name}: invalidates \u306F\u66F8\u304D\u8FBC\u307F\u306E\u64CD\u4F5C\u306B\u3060\u3051\u5BA3\u8A00\u3067\u304D\u307E\u3059\uFF08\u914D\u7DDA\u306E\u8AA4\u308A\uFF09`)}if(operation.fetchCached!==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`)}
|
|
54
|
+
for(const note of operation.plannedNotes?.(prepared)??[])errOut(`${safeText(note)}
|
|
53
55
|
`);if(noRedact)errOut(`${NO_REDACT_NOTICE}
|
|
54
|
-
`);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)}
|
|
56
|
+
`);if(globals.dryRun){out(line(renderOutput(dryRunValue(apiUrl,plan,noRedact?void 0:operation.sensitiveBody),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)}
|
|
55
57
|
`)};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.
|
|
56
58
|
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{}}if(operation.narrow!==void 0){body=operation.narrow(body,prepared);if(paged!==void 0&&operation.paging!==void 0){paged={...paged,count:operation.paging.items(body).length}}}const visible=noRedact?
|
|
57
59
|
body:redactSecretValues(body);const document=globals.query===void 0&&format==="text"&&operation.document!==void 0?operation.document(visible):void 0;const value=document!==void 0?void 0:globals.query!==void 0?await evaluateQuery(globals.query,operation.raw(visible)):outputValue(operation,format,visible);out(line(document!==void 0?renderDocument(document,noRedact):renderOutput(value,format,noRedact)));if(paged!==void 0){errOut(`--all: ${paged.pages} \u30DA\u30FC\u30B8\u3092\u8FBF\u3063\u3066 ${paged.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
2
|
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
-
import{readBody}from"./chunk-HGTG5XQ7.js";import{WORKFLOWS_PATH}from"./chunk-
|
|
3
|
+
import{readBody}from"./chunk-HGTG5XQ7.js";import{WORKFLOWS_PATH}from"./chunk-BZAXQOLB.js";import{UUID_RE,isSafePathSegment}from"./chunk-GMBJTG6A.js";import{LIST_FLAGS,LIST_PAGING_HELP,envelopePaging,nonEmpty,positiveInteger}from"./chunk-5R4SEO3I.js";import{requireResolved,singleRef,withResolved}from"./chunk-ZN5EFDH7.js";import{acknowledgement,isRecord,pick}from"./chunk-ZWVYVS2A.js";import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";var WORKFLOW_FLAG={name:"--workflow",summary:"\u7533\u8ACB\u66F8\uFF08\u30EF\u30FC\u30AF\u30D5\u30ED\u30FC\uFF09\u306E\u540D\u524D\u304B ID \u3067\u7D5E\u308A\u8FBC\u3080",takesValue:true,placeholder:"<\u30EF\u30FC\u30AF\u30D5\u30ED\u30FC>"};var CATEGORIES={undefined:"\u6C4E\u7528",paid_holiday:"\u6709\u7D66\u4F11\u6687",substitute_holiday:"\u632F\u66FF\u4F11\u6687",comp_holiday:"\u4EE3\u4F11",absence:"\u6B20\u52E4",special_holiday:"\u7279\u5225\u4F11\u6687",other_leave:"\u305D\u306E\u4ED6\u4F11\u6687\u30FB\u6B20\u52E4",
|
|
4
4
|
sales:"\u53D6\u5F15",commuting_expenses:"\u901A\u52E4\u4EA4\u901A\u8CBB",cms_publish:"\u30B3\u30F3\u30C6\u30F3\u30C4\u516C\u958B",equipment_lending:"\u5099\u54C1\u8CB8\u51FA",ai_tool_license:"AI\u30C4\u30FC\u30EB\u30E9\u30A4\u30BB\u30F3\u30B9",qualification_bonus:"\u5408\u683C\u304A\u795D\u3044\u91D1"};var CATEGORY_HELP=`\u30AB\u30C6\u30B4\u30EA: ${Object.entries(CATEGORIES).map(([key,label])=>`${key}\uFF08${label}\uFF09`).join(" / ")}`;var WORKFLOW_STATUSES=["active","inactive","draft"];var INSTANCE_STATUSES=[
|
|
5
5
|
"new","in_progress","approved","rejected","canceled","sent_back"];var INSTANCE_STATUS_HELP="\u72B6\u614B: new\uFF08\u4E0B\u66F8\u304D\uFF09/ in_progress\uFF08\u627F\u8A8D\u5F85\u3061\uFF09/ approved\uFF08\u627F\u8A8D\u6E08\u307F\uFF09/ rejected\uFF08\u5374\u4E0B\uFF09/ canceled\uFF08\u53D6\u6D88\uFF09/ sent_back\uFF08\u5DEE\u3057\u623B\u3057\uFF09";var WORKFLOW_COLUMNS=["id","name","defined_category","status","is_hidden","valid_from","valid_to"];var WORKFLOW_ADMIN_COLUMNS=[...WORKFLOW_COLUMNS,"s\
|
|
6
6
|
tep_count"];var WORKFLOW_GET_COLUMNS=["id","name","defined_category","status","is_hidden","valid_from","valid_to","description"];var INSTANCE_COLUMNS=["id","title","workflow_name","status","current_step_no","applicant_name","applied_at","completed_at"];var INSTANCE_GET_COLUMNS=["id","title","workflow_id","workflow_name","status","current_step_no","applicant_name","applied_at","completed_at","can_approve","is_editable","is_cancelable"];var PENDING_COLUMNS=["id","title","workflow_name","applicant_\
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createRequire as __twpCreateRequire } from 'node:module';
|
|
2
|
+
const require = __twpCreateRequire(import.meta.url);
|
|
3
|
+
import{salesAdminForbidden}from"./chunk-7ACENLLZ.js";import{nonEmpty,positiveInteger}from"./chunk-5R4SEO3I.js";import{withResolved}from"./chunk-ZN5EFDH7.js";import{isRecord,pick}from"./chunk-ZWVYVS2A.js";import{ApiResponseError,UsageError}from"./chunk-7WSNIXTQ.js";var PATH="/api/v2/sales/receivables";var FORBIDDEN=salesAdminForbidden("\u58F2\u639B\u91D1\u6B8B\u9AD8\u3068\u7DE0\u3081");var CLOSING_LIST_MAX=36;var SUMMARY_LABELS=[["previous_balance","\u524D\u6708\u6B8B\u9AD8"],["current_debit","\u5F53\u6708\u501F\u65B9\uFF08\u5F53\u6708\u8ACB\u6C42\u984D\uFF09"],["current_credit","\u5F53\u6708\u8CB8\u65B9\uFF08\u5F53\u6708\u5165\u91D1\u5F15\u5F53\u984D\uFF09"],["current_balance","\u5F53\u6708\u6B8B\u9AD8"],["current_month_uncollected","\u2460 \u5F53\u6708\u8ACB\u6C42 \u672A\u56DE\u53CE"],
|
|
4
|
+
["previous_uncollected","\u2461 \u524D\u6708\u4EE5\u524D \u672A\u5165\u91D1\u58F2\u639B\u91D1"],["advance_received","\u524D\u53D7\u91D1\uFF08\u7FCC\u6708\u4EE5\u964D\u8ACB\u6C42\u3078\u306E\u5165\u91D1\uFF09"],["future_invoice_total","\u2462 \u7FCC\u6708\u4EE5\u964D \u58F2\u639B\u91D1\uFF08\u8ACB\u6C42\u7DCF\u984D\u30FB\u53C2\u8003\uFF09"]];var ITEM_COLUMNS=["invoice_id","invoice_no","company_name","title","invoice_date","due_date","total","collected","uncollected"];var CLOSING_COLUMNS=["year_mo\
|
|
5
|
+
nth","basis_date","closed_at","closed_by_name","has_variance"];function usageOf(op){return`twp receivable ${op} help`}function yen(value){return typeof value==="number"?`${value.toLocaleString("ja-JP")} \u5186`:"\uFF08\u4E0D\u660E\uFF09"}function text(value){return typeof value==="string"||typeof value==="number"?String(value):""}function yearMonthValue(raw,label){const value=raw.trim();if(!/^\d{4}-(0[1-9]|1[0-2])$/.test(value))throw new UsageError(`${label} \u306F YYYY-MM \u306E\u5F62\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044: ${raw}`,
|
|
6
|
+
"\u4F8B: 2026-09");return value}function previousYearMonth(yearMonth){const[y,m]=yearMonth.split("-").map(Number);return m===1?`${y-1}-12`:`${y}-${String(m-1).padStart(2,"0")}`}function envelope(body,what){if(!isRecord(body)||body["result"]!==true)throw new ApiResponseError(`${what}\u306E\u5FDC\u7B54\u306E\u5F62\u304C\u60F3\u5B9A\u3068\u9055\u3044\u307E\u3059\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);return body}function withoutResult(body){return Object.
|
|
7
|
+
fromEntries(Object.entries(body).filter(([key])=>key!=="result"))}function summaryLines(summary,indent=" "){if(!isRecord(summary))return[];return SUMMARY_LABELS.filter(([key])=>key in summary).map(([key,label])=>`${indent}${label}: ${yen(summary[key])}`)}function varianceLines(variance,indent=" "){const items=isRecord(variance)&&Array.isArray(variance["items"])?variance["items"].filter(isRecord):[];return items.map(item=>`${indent}${text(item["label"])}: \u78BA\u5B9A\u5024 ${yen(item["snapshot"])}\
|
|
8
|
+
\u2192 \u73FE\u5728\u5024 ${yen(item["current"])}\uFF08\u5DEE ${yen(item["diff"])}\uFF09`)}function hasVariance(variance){return isRecord(variance)&&variance["has_variance"]===true}var FILTER_FLAGS=[{name:"--month",summary:"\u57FA\u6E96\u5E74\u6708\uFF08YYYY-MM\u30FB\u7701\u304F\u3068\u4ECA\u6708\uFF09",takesValue:true,placeholder:"<\u5E74\u6708>"},{name:"--customer",summary:"\u53D6\u5F15\u5148\u3067\u7D5E\u308A\u8FBC\u3080\uFF08\u4F01\u696D\u540D\u30FB\u7565\u79F0\u30FB\u30AB\u30CA\u306E\u5B8C\u5168\u4E00\u81F4\u304B ID\uFF09",
|
|
9
|
+
takesValue:true,placeholder:"<\u53D6\u5F15\u5148>"},{name:"--department",summary:"\u8ACB\u6C42\u306E\u4E3B\u5E79\u90E8\u7F72\u3067\u7D5E\u308A\u8FBC\u3080\uFF08\u540D\u524D\u30FB\u30B3\u30FC\u30C9\u30FBID\uFF09",takesValue:true,placeholder:"<\u90E8\u7F72>"},{name:"--negative-only",summary:"\u672A\u56DE\u53CE\u304C\u30DE\u30A4\u30CA\u30B9\uFF08\u5165\u91D1\u8D85\u904E\uFF09\u306E\u8ACB\u6C42\u3060\u3051\u306B\u3059\u308B",takesValue:false}];var FILTER_HELP="--month \u306F\u57FA\u6E96\u5E74\u6708\u3067\u3059\uFF08\u57FA\u6E96\u65E5\u306F\u305D\u306E\u6708\u306E\u672B\u65E5\uFF09\u3002\u7701\u304F\u3068\u30B5\u30FC\u30D0\u306E\u4ECA\u6708\u3067\u3059\
|
|
10
|
+
\u3002\n\u7D5E\u308A\u8FBC\u307F\uFF08--customer / --department / --negative-only\uFF09\u3092\u4ED8\u3051\u308B\u3068\u3001\u7DE0\u3081\u6E08\u307F\u306E\u6708\u3067\u3082\u30B5\u30DE\u30EA\u30FC\u306F\u78BA\u5B9A\u5024\u3067\u306F\u306A\u304F\u73FE\u5728\u5024\u306B\u306A\u308A\u307E\u3059\n\uFF08\u78BA\u5B9A\u5024\u306F\u5168\u4F53\u306E\u5024\u3060\u3051\u3092\u6301\u3064\u305F\u3081\u3002stderr \u306B\u305D\u3046\u51FA\u307E\u3059\uFF09\u3002";async function prepareFilters(input,ctx,op){if(input.
|
|
11
|
+
args.length>0)throw new UsageError(`${op} \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,usageOf(op));const month=nonEmpty(input.flags,"--month");if(month!==void 0)yearMonthValue(month,"--month");const resolved={};const customer=nonEmpty(input.flags,"--customer");if(customer!==void 0)resolved["customer"]=(await ctx.resolver.company(customer,{flag:"--customer",source:"sales",mustExist:true})).id;const department=nonEmpty(input.flags,"--department");if(department!==
|
|
12
|
+
void 0)resolved["department"]=(await ctx.resolver.department(department,"--department")).id;return withResolved(input,resolved)}function filterQuery(input){const month=nonEmpty(input.flags,"--month");const resolved=input.resolved??{};return{year_month:month===void 0?void 0:yearMonthValue(month,"--month"),company_id:resolved["customer"],department_id:resolved["department"],negative_only:input.flags.has("--negative-only")?1:void 0}}function balanceOf(body){const data=envelope(body,"\u58F2\u639B\u91D1\u6B8B\u9AD8");
|
|
13
|
+
if(!isRecord(data["summary"])||!isRecord(data["blocks"]))throw new ApiResponseError("\u58F2\u639B\u91D1\u6B8B\u9AD8\u306E\u5FDC\u7B54\u306B summary / blocks \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002");return data}function balanceRows(body){const blocks=balanceOf(body)["blocks"];return Object.entries(blocks).flatMap(([key,block])=>{if(!isRecord(block)||!Array.isArray(block["items"]))return[];return block["items"].filter(
|
|
14
|
+
isRecord).map(item=>({block:key,block_label:text(block["label"]),...pick(item,ITEM_COLUMNS)}))})}function balanceNotes(body){const data=balanceOf(body);const lines=[`\u57FA\u6E96\u5E74\u6708 ${text(data["year_month"])}\uFF08\u57FA\u6E96\u65E5 ${text(data["basis_date"])}\uFF09`];if(data["is_closed"]===true){const closing=isRecord(data["closing"])?data["closing"]:{};const who=`${text(closing["closed_at"])}${text(closing["closed_by_name"])===""?"":` / ${text(closing["closed_by_name"])}`}`;lines.push(
|
|
15
|
+
data["summary_is_snapshot"]===true?`\u7DE0\u3081\u6E08\u307F\uFF08${who}\uFF09\u3002\u30B5\u30DE\u30EA\u30FC\u306F\u7DE0\u3081\u6642\u70B9\u306E\u78BA\u5B9A\u5024\u3067\u3059:`:`\u7DE0\u3081\u6E08\u307F\uFF08${who}\uFF09\u3002\u7D5E\u308A\u8FBC\u307F\u4E2D\u306E\u305F\u3081\u3001\u30B5\u30DE\u30EA\u30FC\u306F\u78BA\u5B9A\u5024\u3067\u306F\u306A\u304F\u73FE\u5728\u5024\u3067\u3059:`)}else{lines.push("\u7DE0\u3081\u3066\u3044\u307E\u305B\u3093\u3002\u30B5\u30DE\u30EA\u30FC\u306F\u73FE\u5728\u5024\u3067\u3059:")}
|
|
16
|
+
lines.push(...summaryLines(data["summary"]));if(hasVariance(data["variance"]))lines.push("\u7DE0\u3081\u305F\u5F8C\u306B\u5024\u304C\u52D5\u3044\u3066\u3044\u307E\u3059\uFF08\u78BA\u5B9A\u5024\u3068\u306E\u5DEE\u7570\uFF09:",...varianceLines(data["variance"]));const blocks=data["blocks"];for(const block of Object.values(blocks)){if(!isRecord(block)||!isRecord(block["subtotal"]))continue;const sub=block["subtotal"];lines.push(`${text(block["label"])}: ${text(sub["count"])} \u4EF6\u30FB\u8ACB\u6C42 ${yen(
|
|
17
|
+
sub["total"])}\u30FB\u56DE\u53CE\u6E08 ${yen(sub["collected"])}\u30FB\u672A\u56DE\u53CE ${yen(sub["uncollected"])}`)}return lines}var listOperation={name:"list",summary:"\u57FA\u6E96\u5E74\u6708\u306E\u58F2\u639B\u91D1\u6B8B\u9AD8\uFF08\u30B5\u30DE\u30EA\u30FC\u3068\u8ACB\u6C42\u3054\u3068\u306E\u660E\u7D30\uFF09\u3092\u8868\u793A\u3059\u308B",usage:"twp receivable list [--month <\u5E74\u6708>] [--customer <\u53D6\u5F15\u5148>] [--department <\u90E8\u7F72>] [--negative-only]",description:"GET /a\
|
|
18
|
+
pi/v2/sales/receivables\u3002\u753B\u9762\u306E\u300C\u58F2\u639B\u91D1\u6B8B\u9AD8\u4E00\u89A7\u300D\u3068\u540C\u3058\u8A08\u7B97\u3067\u3001\u57FA\u6E96\u5E74\u6708\u306E\u6B8B\u9AD8\u3092\u51FA\u3057\u307E\u3059\u3002\u8CA9\u58F2\u7BA1\u7406\u306E\u7BA1\u7406\u8005\u3060\u3051\u304C\u4F7F\u3048\u307E\u3059\u3002\n\u6A19\u6E96\u51FA\u529B\u306F\u8ACB\u6C42\u3054\u3068\u306E\u660E\u7D30\uFF08\u533A\u5206\u30FB\u8ACB\u6C42\u30FB\u91D1\u984D\u30FB\u56DE\u53CE\u6E08\u30FB\u672A\u56DE\u53CE\uFF09\u3067\u3001\u30B5\u30DE\u30EA\u30FC\uFF08\u524D\u6708\u6B8B\u9AD8\u30FB\u5F53\u6708\u501F\u65B9\u30FB\u5F53\u6708\u8CB8\u65B9\u30FB\u5F53\u6708\u6B8B\u9AD8\u307B\u304B\uFF09\u3068\n\u533A\u5206\u3054\u3068\u306E\u5C0F\u8A08\u30FB\u7DE0\u3081\u306E\u72B6\u614B\u306F stderr \u306B\u51FA\u307E\u3059\u3002\u30DA\u30FC\u30B8\u30F3\u30B0\u306F\u3042\u308A\u307E\u305B\u3093\u3002\n\n"+
|
|
19
|
+
FILTER_HELP+`
|
|
20
|
+
|
|
21
|
+
--output json \u306F\u5FDC\u7B54\u306E\u5168\u90E8\uFF08summary\u30FBblocks\u30FB\u7DE0\u3081\u306E\u72B6\u614B closing\u30FB\u78BA\u5B9A\u5024\u3068\u306E\u5DEE\u7570 variance\uFF09\u3092\u51FA\u3057\u307E\u3059\u3002
|
|
22
|
+
--output table / text / tsv \u306F\u660E\u7D30\u306E\u8981\u7D04\u5217\uFF08block / block_label / ${ITEM_COLUMNS.join(" / ")}\uFF09\u3067\u3059\u3002`,flags:FILTER_FLAGS,forbidden:FORBIDDEN,prepare:(input,ctx)=>prepareFilters(input,ctx,"list"),plan:input=>({method:"GET",path:PATH,query:filterQuery(input)}),summarize:balanceRows,raw:body=>withoutResult(balanceOf(body)),notes:balanceNotes};function exportType(input){const type=nonEmpty(input.flags,"--type")??"detail";if(type!=="detail"&&type!=="su\
|
|
23
|
+
mmary")throw new UsageError(`--type \u306F detail \u304B summary \u3067\u3059: ${type}`,usageOf("export"));return type}var exportOperation={name:"export",summary:"\u58F2\u639B\u91D1\u6B8B\u9AD8\u3092 CSV \u306B\u66F8\u304D\u51FA\u3059\uFF08--out\u30FB--type summary|detail\uFF09",usage:"twp receivable export --out <\u30D1\u30B9.csv> [--force] [--type detail|summary] [--month <\u5E74\u6708>] [\u7D5E\u308A\u8FBC\u307F\u2026]",description:"GET /api/v2/sales/receivables/export\u3002\u753B\u9762\u306E CSV \u51FA\u529B\u3068\u540C\u3058\u5185\u5BB9\uFF08UTF-8\u30FBB\
|
|
24
|
+
OM \u4ED8\u304D\uFF09\u3067\u3059\u3002\n--type detail\uFF08\u65E2\u5B9A\uFF09\u306F\u8ACB\u6C42\u3054\u3068\u306E\u660E\u7D30\u3068\u533A\u5206\u3054\u3068\u306E\u5C0F\u8A08\u3001--type summary \u306F\u30B5\u30DE\u30EA\u30FC\u306E9\u9805\u76EE\uFF08\u7DE0\u3081\u6E08\u307F\u306A\u3089\u7DE0\u3081\u306E\u72B6\u614B\u3068\u5DEE\u7570\u306E\u884C\u3064\u304D\uFF09\u3067\u3059\u3002\n\u65E2\u5B58\u306E\u30D5\u30A1\u30A4\u30EB\u306F\u4E0A\u66F8\u304D\u3057\u307E\u305B\u3093\uFF08\u4E0A\u66F8\u304D\u3059\u308B\u306A\u3089 --force\uFF09\u3002\n\n"+
|
|
25
|
+
FILTER_HELP,flags:[{name:"--out",summary:"\u66F8\u304D\u51FA\u3057\u5148\u306E\u30D5\u30A1\u30A4\u30EB\u30D1\u30B9\uFF08\u5FC5\u9808\uFF09",takesValue:true,placeholder:"<\u30D1\u30B9>"},{name:"--force",summary:"\u65E2\u5B58\u306E\u30D5\u30A1\u30A4\u30EB\u3092\u4E0A\u66F8\u304D\u3059\u308B",takesValue:false},{name:"--type",summary:"detail\uFF08\u660E\u7D30\u30FB\u65E2\u5B9A\uFF09\u304B summary\uFF08\u30B5\u30DE\u30EA\u30FC\uFF09",takesValue:true,placeholder:"<\u7A2E\u985E>"},...FILTER_FLAGS],download:{
|
|
26
|
+
outFlag:"--out",forceFlag:"--force"},forbidden:FORBIDDEN,prepare:(input,ctx)=>{exportType(input);return prepareFilters(input,ctx,"export")},plan:input=>({method:"GET",path:`${PATH}/export`,query:{...filterQuery(input),type:exportType(input)}}),summarize:body=>body,raw:body=>body};function yearMonthArg(input,op){const[raw,...rest]=input.args;if(raw===void 0||raw.trim()==="")throw new UsageError("\u5BFE\u8C61\u306E\u5E74\u6708\uFF08YYYY-MM\uFF09\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
27
|
+
usageOf(`closing ${op}`));if(rest.length>0)throw new UsageError(`\u53D7\u3051\u53D6\u308C\u308B\u5E74\u6708\u306F1\u3064\u3060\u3051\u3067\u3059: ${rest.join(" ")}`,usageOf(`closing ${op}`));return yearMonthValue(raw,"\u5E74\u6708")}function closingRows(body){const list=envelope(body,"\u7DE0\u3081\u306E\u4E00\u89A7")["list"];if(!Array.isArray(list))throw new ApiResponseError("\u7DE0\u3081\u306E\u4E00\u89A7\u306E\u5FDC\u7B54\u306B list \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
|
|
28
|
+
return list.filter(isRecord)}function closingState(body){const data=envelope(body,"\u7DE0\u3081");if(typeof data["is_closed"]!=="boolean")throw new ApiResponseError("\u7DE0\u3081\u306E\u5FDC\u7B54\u306B is_closed \u304C\u3042\u308A\u307E\u305B\u3093\u3002\u63A5\u7D9A\u5148\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002");return data}var closingListOperation={name:"list",summary:"\u7DE0\u3081\u6E08\u307F\u306E\u6708\u3092\u65B0\u3057\u3044\u9806\u306B\u4E00\u89A7\u3059\u308B\uFF08\u78BA\u5B9A\u5024\u3068\u306E\u5DEE\u7570\u306E\u6709\u7121\u3064\u304D\uFF09",
|
|
29
|
+
usage:`twp receivable closing list [--limit <\u6708\u6570>]`,description:`GET /api/v2/sales/receivables/closings\u3002\u7DE0\u3081\u6E08\u307F\u306E\u6708\u3092\u65B0\u3057\u3044\u9806\u306B\u51FA\u3057\u307E\u3059\uFF08\u65E2\u5B9A 12 \u304B\u6708\u30FB--limit \u306F ${CLOSING_LIST_MAX} \u307E\u3067\uFF09\u3002
|
|
30
|
+
has_variance \u306F\u3001\u7DE0\u3081\u305F\u5F8C\u306B\u305D\u306E\u6708\u306E\u5024\u304C\u52D5\u3044\u305F\uFF08\u78BA\u5B9A\u5024\u3068\u73FE\u5728\u5024\u304C\u9055\u3046\uFF09\u304B\u3067\u3059\u3002\u4E2D\u8EAB\u306F twp receivable closing get <\u5E74\u6708> \u3067\u898B\u307E\u3059\u3002`,flags:[{name:"--limit",summary:`\u51FA\u3059\u6708\u6570\uFF08\u65E2\u5B9A 12\u30FB${CLOSING_LIST_MAX} \u307E\u3067\uFF09`,takesValue:true,placeholder:"<\u6708\u6570>"}],forbidden:FORBIDDEN,plan:input=>{
|
|
31
|
+
if(input.args.length>0)throw new UsageError(`closing list \u306F\u4F4D\u7F6E\u5F15\u6570\u3092\u53D6\u308A\u307E\u305B\u3093: ${input.args.join(" ")}`,usageOf("closing list"));const limit=positiveInteger(input.flags,"--limit");if(limit!==void 0&&limit>CLOSING_LIST_MAX)throw new UsageError(`--limit \u306F ${CLOSING_LIST_MAX} \u307E\u3067\u3067\u3059: ${limit}`);return{method:"GET",path:`${PATH}/closings`,query:{limit}}},summarize:body=>closingRows(body).map(row=>({...pick(row,CLOSING_COLUMNS),has_variance:hasVariance(
|
|
32
|
+
row["variance"])})),raw:closingRows,notes:body=>closingRows(body).length===0?["\u7DE0\u3081\u6E08\u307F\u306E\u6708\u306F\u3042\u308A\u307E\u305B\u3093"]:[]};var closingGetOperation={name:"get",summary:"1\u304B\u6708\u306E\u7DE0\u3081\u306E\u72B6\u614B\uFF08\u78BA\u5B9A\u5024\u30FB\u73FE\u5728\u5024\u30FB\u5DEE\u7570\uFF09\u3092\u8868\u793A\u3059\u308B",usage:"twp receivable closing get <\u5E74\u6708>",description:"GET /api/v2/sales/receivables/closings/{yearMonth}\u3002\u7DE0\u3081\u3066\u3044\u306A\u3044\u6708\u306F is_closed=false \u3092\u8FD4\u3057\u307E\u3059\
|
|
33
|
+
\uFF08\u30A8\u30E9\u30FC\u306B\u306F\u306A\u308A\u307E\u305B\u3093\uFF09\u3002\n\u7DE0\u3081\u6E08\u307F\u306A\u3089\u3001\u78BA\u5B9A\u5024\uFF08\u7DE0\u3081\u6642\u70B9\u306E\u30B5\u30DE\u30EA\u30FC\uFF09\u30FB\u73FE\u5728\u5024\u30FB\u5DEE\u7570\u3092 stderr \u306B\u51FA\u3057\u307E\u3059\u3002",flags:[],forbidden:FORBIDDEN,plan:input=>({method:"GET",path:`${PATH}/closings/${yearMonthArg(input,"get")}`}),summarize:body=>{const data=closingState(body);const closing=isRecord(data["closing"])?data["\
|
|
34
|
+
closing"]:{};return{year_month:data["year_month"]??null,is_closed:data["is_closed"],closed_at:closing["closed_at"]??null,closed_by_name:closing["closed_by_name"]??null,has_variance:hasVariance(data["variance"])}},raw:body=>withoutResult(closingState(body)),notes:body=>{const data=closingState(body);if(data["is_closed"]!==true)return[`${text(data["year_month"])} \u306F\u7DE0\u3081\u3066\u3044\u307E\u305B\u3093`];const closing=isRecord(data["closing"])?data["closing"]:{};return[`${text(data["year_\
|
|
35
|
+
month"])} \u306F\u7DE0\u3081\u6E08\u307F\u3067\u3059\uFF08${text(closing["closed_at"])}${text(closing["closed_by_name"])===""?"":` / ${text(closing["closed_by_name"])}`}\uFF09\u3002\u78BA\u5B9A\u5024:`,...summaryLines(closing["snapshot_summary"]),...hasVariance(data["variance"])?["\u7DE0\u3081\u305F\u5F8C\u306B\u5024\u304C\u52D5\u3044\u3066\u3044\u307E\u3059\uFF08\u78BA\u5B9A\u5024 \u2192 \u73FE\u5728\u5024\uFF09:",...varianceLines(data["variance"])]:["\u78BA\u5B9A\u5024\u3068\u73FE\u5728\u5024\u306B\u5DEE\u7570\u306F\u3042\u308A\u307E\u305B\u3093"]]}};
|
|
36
|
+
async function prepareClose(input,ctx){const yearMonth=yearMonthArg(input,"close");const previous=previousYearMonth(yearMonth);const target=await ctx.resolver.salesJson(`${PATH}/closings/${yearMonth}`,"\u7DE0\u3081");const balance=await ctx.resolver.salesJson(`${PATH}?year_month=${yearMonth}`,"\u58F2\u639B\u91D1\u6B8B\u9AD8");const prior=await ctx.resolver.salesJson(`${PATH}/closings/${previous}`,"\u7DE0\u3081");return withResolved(input,{yearMonth,target:JSON.stringify(target),balance:JSON.stringify(
|
|
37
|
+
balance),prior:JSON.stringify(prior)})}function resolvedJson(input,key){const raw=input.resolved?.[key];if(raw===void 0)throw new Error(`\u5185\u90E8\u30A8\u30E9\u30FC: ${key} \u304C\u89E3\u6C7A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\uFF08prepare() \u306E\u914D\u7DDA\u6F0F\u308C\uFF09`);return JSON.parse(raw)}var MONTH_LOCK_HELP="\u7DE0\u3081\u305F\u6708\u306E\u5165\u91D1\u306F\u3001\u767B\u9332\u30FB\u5165\u91D1\u65E5\u306E\u5909\u66F4\u30FB\u524A\u9664\u30FB\u5F15\u5F53\u306E\u5909\u66F4\u3092\u30B5\u30FC\u30D0\u304C\u65AD\u308B\u3088\u3046\u306B\u306A\u308A\u307E\u3059\uFF08\u8ACB\u6C42\u306F\u7DE0\u3081\u306E\u5BFE\u8C61\u5916\u3067\u3059\uFF09\u3002";
|
|
38
|
+
var closingCloseOperation={name:"close",summary:"\u6708\u3092\u7DE0\u3081\u308B\uFF08\u6B8B\u9AD8\u3092\u78BA\u5B9A\u5024\u3068\u3057\u3066\u4FDD\u5B58\u3057\u3001\u305D\u306E\u6708\u306E\u5165\u91D1\u3092\u52D5\u304B\u305B\u306A\u304F\u3059\u308B\u30FB--yes \u304C\u8981\u308B\uFF09",usage:"twp receivable closing close <\u5E74\u6708> --yes",description:"POST /api/v2/sales/receivables/closings\u3002\u57FA\u6E96\u5E74\u6708\u306E\u58F2\u639B\u91D1\u6B8B\u9AD8\uFF08\u30B5\u30DE\u30EA\u30FC\uFF09\u3092\u78BA\u5B9A\u5024\u3068\u3057\u3066\u4FDD\u5B58\u3057\u307E\u3059\u3002\u7DE0\u3081\u306F\u30C6\u30CA\u30F3\u30C8\u5168\u4F53\u306B\u52B9\u304D\u307E\u3059\u3002\n"+
|
|
39
|
+
MONTH_LOCK_HELP+"\n\u6708\u672B\u304C\u307E\u3060\u6765\u3066\u3044\u306A\u3044\u6708\u30FB\u65E2\u306B\u7DE0\u3081\u305F\u6708\u306F\u30B5\u30FC\u30D0\u304C\u65AD\u308A\u307E\u3059\u3002\u89E3\u9664\u306F twp receivable closing reopen <\u5E74\u6708>\u3002\n\u9001\u308B\u524D\u306B\u3001\u7DE0\u3081\u308B\u6708\u306E\u73FE\u5728\u5024\u3068\u3001\u524D\u6708\u306E\u7DE0\u3081\u3068\u306E\u5DEE\u7570\uFF08\u524D\u6708\u3092\u7DE0\u3081\u305F\u5F8C\u306B\u524D\u6708\u306E\u5024\u304C\u52D5\u3044\u3066\u3044\u308C\u3070\u3001\u3053\u306E\u6708\u306E\u524D\u6708\u6B8B\u9AD8\u306F\u524D\u6708\u306E\u78BA\u5B9A\u5024\u3068\n\u4E00\u81F4\u3057\u307E\u305B\u3093\uFF09\u3092 stderr \u306B\u51FA\u3057\u307E\u3059\uFF08--dry-run \u3067\u3082\u51FA\u307E\u3059\uFF09\u3002",
|
|
40
|
+
destructive:true,flags:[],forbidden:FORBIDDEN,prepare:prepareClose,plan:input=>({method:"POST",path:`${PATH}/closings`,body:{year_month:yearMonthArg(input,"close")}}),plannedNotes(input){const yearMonth=yearMonthArg(input,"close");const target=resolvedJson(input,"target");const balance=resolvedJson(input,"balance");const prior=resolvedJson(input,"prior");if(target["is_closed"]===true)return[`${yearMonth} \u306F\u65E2\u306B\u7DE0\u3081\u6E08\u307F\u3067\u3059\uFF08\u30B5\u30FC\u30D0\u304C\u65AD\u308A\u307E\u3059\u3002\u7DE0\u3081\u76F4\u3059\u306A\u3089\u5148\u306B twp receivable closing reopen ${yearMonth}\
|
|
41
|
+
\uFF09`];const lines=[];lines.push(`${yearMonth} \u3092\u7DE0\u3081\u307E\u3059\u3002\u78BA\u5B9A\u5024\u306B\u306A\u308B\u73FE\u5728\u306E\u30B5\u30DE\u30EA\u30FC\uFF08\u57FA\u6E96\u65E5 ${text(balance["basis_date"])}\uFF09:`,...summaryLines(balance["summary"]));const previous=previousYearMonth(yearMonth);if(prior["is_closed"]!==true)lines.push(`\u524D\u6708\uFF08${previous}\uFF09\u306F\u7DE0\u3081\u3066\u3044\u307E\u305B\u3093`);else if(hasVariance(prior["variance"]))lines.push(`\u26A0 \u524D\u6708\uFF08${previous}\
|
|
42
|
+
\uFF09\u306F\u7DE0\u3081\u305F\u5F8C\u306B\u5024\u304C\u52D5\u3044\u3066\u3044\u307E\u3059\u3002\u3053\u306E\u6708\u306E\u524D\u6708\u6B8B\u9AD8\u306F\u524D\u6708\u306E\u78BA\u5B9A\u5024\u3068\u4E00\u81F4\u3057\u307E\u305B\u3093:`,...varianceLines(prior["variance"]));else lines.push(`\u524D\u6708\uFF08${previous}\uFF09\u306E\u7DE0\u3081\u3068\u5DEE\u7570\u306F\u3042\u308A\u307E\u305B\u3093`);lines.push(MONTH_LOCK_HELP);return lines},summarize:body=>pick(envelope(body,"\u7DE0\u3081")["data"],["ye\
|
|
43
|
+
ar_month","basis_date","closed_at","closed_by_name"]),raw:body=>envelope(body,"\u7DE0\u3081")["data"],notes:body=>{const message=envelope(body,"\u7DE0\u3081")["message"];return typeof message==="string"?[message]:[]}};async function prepareReopen(input,ctx){const yearMonth=yearMonthArg(input,"reopen");const target=await ctx.resolver.salesJson(`${PATH}/closings/${yearMonth}`,"\u7DE0\u3081");return withResolved(input,{yearMonth,target:JSON.stringify(target)})}var closingReopenOperation={name:"reop\
|
|
44
|
+
en",summary:"\u6708\u306E\u7DE0\u3081\u3092\u89E3\u9664\u3059\u308B\uFF08\u78BA\u5B9A\u5024\u3092\u6D88\u3057\u3001\u305D\u306E\u6708\u306E\u5165\u91D1\u3092\u52D5\u304B\u305B\u308B\u3088\u3046\u306B\u3059\u308B\u30FB--yes \u304C\u8981\u308B\uFF09",usage:"twp receivable closing reopen <\u5E74\u6708> --yes",description:"DELETE /api/v2/sales/receivables/closings/{yearMonth}\u3002\u7DE0\u3081\u306E\u78BA\u5B9A\u5024\uFF08\u7DE0\u3081\u6642\u70B9\u306E\u30B5\u30DE\u30EA\u30FC\uFF09\u3092\u6D88\u3057\u3001\u305D\u306E\u6708\u306E\u5165\u91D1\u3092\u307E\u305F\u767B\u9332\u30FB\u5909\u66F4\u3067\u304D\u308B\u3088\u3046\u306B\u3057\u307E\u3059\u3002\n\u6D88\u3057\u305F\u78BA\u5B9A\u5024\u306F\u623B\u308A\u307E\u305B\u3093\uFF08\u3082\u3046\u4E00\u5EA6\u7DE0\u3081\u308B\u3068\u3001\u305D\u306E\u6642\u70B9\u306E\u73FE\u5728\u5024\u3067\u78BA\u5B9A\u3057\u76F4\u3057\u307E\u3059\uFF09\u3002\u7DE0\u3081\u3066\u3044\u306A\u3044\u6708\u306F\u30B5\u30FC\u30D0\u304C\u65AD\u308A\u307E\u3059\u3002\n\u9001\u308B\u524D\u306B\u7DE0\u3081\u306E\u8A18\u9332\u3068\u78BA\u5B9A\u5024\u3092 stderr\
|
|
45
|
+
\u306B\u51FA\u3057\u307E\u3059\uFF08--dry-run \u3067\u3082\u51FA\u307E\u3059\uFF09\u3002",destructive:true,flags:[],forbidden:FORBIDDEN,prepare:prepareReopen,plan:input=>({method:"DELETE",path:`${PATH}/closings/${yearMonthArg(input,"reopen")}`}),plannedNotes(input){const yearMonth=yearMonthArg(input,"reopen");const target=resolvedJson(input,"target");if(target["is_closed"]!==true)return[`${yearMonth} \u306F\u7DE0\u3081\u3066\u3044\u307E\u305B\u3093\uFF08\u30B5\u30FC\u30D0\u304C\u65AD\u308A\u307E\u3059\uFF09`];
|
|
46
|
+
const closing=isRecord(target["closing"])?target["closing"]:{};return[`${yearMonth} \u306E\u7DE0\u3081\uFF08${text(closing["closed_at"])}${text(closing["closed_by_name"])===""?"":` / ${text(closing["closed_by_name"])}`}\uFF09\u3092\u89E3\u9664\u3057\u307E\u3059\u3002\u6D88\u3048\u308B\u78BA\u5B9A\u5024:`,...summaryLines(closing["snapshot_summary"]),...hasVariance(target["variance"])?["\u7DE0\u3081\u305F\u5F8C\u306B\u5024\u304C\u52D5\u3044\u3066\u3044\u307E\u3059\uFF08\u78BA\u5B9A\u5024 \u2192 \u73FE\u5728\u5024\uFF09:",
|
|
47
|
+
...varianceLines(target["variance"])]:[]]},summarize:body=>({result:envelope(body,"\u7DE0\u3081\u306E\u89E3\u9664")["result"],message:body["message"]??null}),raw:body=>({result:envelope(body,"\u7DE0\u3081\u306E\u89E3\u9664")["result"],message:body["message"]??null})};var closingResource={name:"closing",summary:"\u58F2\u639B\u91D1\u306E\u6708\u6B21\u7DE0\u3081\uFF08\u4E00\u89A7\u30FB\u72B6\u614B\u30FB\u7DE0\u3081\u30FB\u7DE0\u3081\u306E\u89E3\u9664\uFF09",operations:[closingListOperation,closingGetOperation,
|
|
48
|
+
closingCloseOperation,closingReopenOperation]};var receivableDomain={name:"receivable",summary:"\u8CA9\u58F2\u7BA1\u7406\u306E\u58F2\u639B\u91D1\u6B8B\u9AD8\uFF08\u57FA\u6E96\u5E74\u6708\u306E\u30B5\u30DE\u30EA\u30FC\u3068\u660E\u7D30\u30FBCSV\uFF09\u3068\u6708\u6B21\u7DE0\u3081\uFF08\u8CA9\u58F2\u7BA1\u7406\u306E\u7BA1\u7406\u8005\uFF09",operations:[listOperation,exportOperation],subresources:[closingResource]};export{yearMonthValue,previousYearMonth,balanceRows,receivableDomain};
|