Skip to content

Commit 35e256a

Browse files
feat(api): manual updates
1 parent 2f06be9 commit 35e256a

6 files changed

Lines changed: 383 additions & 48 deletions

File tree

‎.stats.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 38
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c1b6ca84f9bec1b1936cebb61f058924c3d7a5f6977e4cd76cf0544c4c7d8737.yml
1+
configured_endpoints: 40
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e2ba5381de3010ee53f27388aa6727ad567eb18e4b0b4eb1c4c66402bfea64cc.yml
33
openapi_spec_hash: 141bfa8430ddccfb5a37c4bd703d163b
4-
config_hash: bff282047fafdad771fb7ec685f56944
4+
config_hash: 920678668dd2da6f8966fbf1b8fde4e2

‎pkg/cmd/batch.go‎

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ var batchList = cli.Command{
7070
HideHelpCommand: true,
7171
}
7272

73+
var batchDelete = cli.Command{
74+
Name: "delete",
75+
Usage: "Permanently delete a finished batch and its stored results. Active batches must\nsettle first.",
76+
Suggest: true,
77+
Flags: []cli.Flag{
78+
&requestflag.Flag[string]{
79+
Name: "batch-id",
80+
Usage: "ID of the batch to retrieve or cancel.",
81+
Required: true,
82+
PathParam: "batch_id",
83+
},
84+
},
85+
Action: handleBatchDelete,
86+
HideHelpCommand: true,
87+
}
88+
7389
var batchCancel = cli.Command{
7490
Name: "cancel",
7591
Usage: "Stop a batch from starting new pages. In-progress pages finish, and unused\ncredits are refunded.",
@@ -112,39 +128,36 @@ var batchGetResults = cli.Command{
112128
HideHelpCommand: true,
113129
}
114130

115-
var batchSubmit = requestflag.WithInnerFlags(cli.Command{
131+
var batchSubmit = cli.Command{
116132
Name: "submit",
117-
Usage: "Retrieve and normalize a person profile from identifiers.",
133+
Usage: "Scrape 25K URLs or crawl large websites asynchronously.",
118134
Suggest: true,
119135
Flags: []cli.Flag{
120136
&requestflag.Flag[map[string]any]{
121-
Name: "identifiers",
122-
Usage: "Known identifiers for the person. At least one identifier is required.",
137+
Name: "input",
138+
Usage: "Choose a URL list or a site crawl.",
123139
Required: true,
124-
BodyPath: "identifiers",
140+
BodyPath: "input",
125141
},
126142
&requestflag.Flag[[]string]{
127143
Name: "tag",
128-
Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.",
144+
Usage: "Tags stored on the batch. Filter the batch list by them later.",
129145
BodyPath: "tags",
130146
},
131-
&requestflag.Flag[int64]{
132-
Name: "timeout-ms",
133-
Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).",
134-
BodyPath: "timeoutMS",
147+
&requestflag.Flag[string]{
148+
Name: "webhook-url",
149+
Usage: "URL notified when the batch finishes.",
150+
BodyPath: "webhookUrl",
151+
},
152+
&requestflag.Flag[string]{
153+
Name: "idempotency-key",
154+
Usage: "Any string unique to this submission. Retries with the same key return the original batch.",
155+
HeaderPath: "Idempotency-Key",
135156
},
136157
},
137158
Action: handleBatchSubmit,
138159
HideHelpCommand: true,
139-
}, map[string][]requestflag.HasOuterFlag{
140-
"identifiers": {
141-
&requestflag.InnerFlag[string]{
142-
Name: "identifiers.linkedin-url",
143-
Usage: "LinkedIn profile URL, e.g. https://www.linkedin.com/in/yahia-bakour/.",
144-
InnerField: "linkedinUrl",
145-
},
146-
},
147-
})
160+
}
148161

149162
func handleBatchRetrieve(ctx context.Context, cmd *cli.Command) error {
150163
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
@@ -229,6 +242,48 @@ func handleBatchList(ctx context.Context, cmd *cli.Command) error {
229242
})
230243
}
231244

245+
func handleBatchDelete(ctx context.Context, cmd *cli.Command) error {
246+
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
247+
unusedArgs := cmd.Args().Slice()
248+
if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 {
249+
cmd.Set("batch-id", unusedArgs[0])
250+
unusedArgs = unusedArgs[1:]
251+
}
252+
if len(unusedArgs) > 0 {
253+
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
254+
}
255+
256+
options, err := flagOptions(
257+
cmd,
258+
apiquery.NestedQueryFormatBrackets,
259+
apiquery.ArrayQueryFormatComma,
260+
EmptyBody,
261+
false,
262+
)
263+
if err != nil {
264+
return err
265+
}
266+
267+
var res []byte
268+
options = append(options, option.WithResponseBodyInto(&res))
269+
_, err = client.Batch.Delete(ctx, cmd.Value("batch-id").(string), options...)
270+
if err != nil {
271+
return err
272+
}
273+
274+
obj := gjson.ParseBytes(res)
275+
format := cmd.Root().String("format")
276+
explicitFormat := cmd.Root().IsSet("format")
277+
transform := cmd.Root().String("transform")
278+
return ShowJSON(obj, ShowJSONOpts{
279+
ExplicitFormat: explicitFormat,
280+
Format: format,
281+
RawOutput: cmd.Root().Bool("raw-output"),
282+
Title: "batch delete",
283+
Transform: transform,
284+
})
285+
}
286+
232287
func handleBatchCancel(ctx context.Context, cmd *cli.Command) error {
233288
client := contextdev.NewClient(getDefaultRequestOptions(cmd)...)
234289
unusedArgs := cmd.Args().Slice()

‎pkg/cmd/batch_test.go‎

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77

88
"github.com/context-dot-dev/context-dev-cli/internal/mocktest"
9-
"github.com/context-dot-dev/context-dev-cli/internal/requestflag"
109
)
1110

1211
func TestBatchRetrieve(t *testing.T) {
@@ -38,6 +37,18 @@ func TestBatchList(t *testing.T) {
3837
})
3938
}
4039

40+
func TestBatchDelete(t *testing.T) {
41+
t.Skip("Mock server tests are disabled")
42+
t.Run("regular flags", func(t *testing.T) {
43+
mocktest.TestRunMockTestWithFlags(
44+
t,
45+
"--api-key", "string",
46+
"batch", "delete",
47+
"--batch-id", "batch_9f2c8a",
48+
)
49+
})
50+
}
51+
4152
func TestBatchCancel(t *testing.T) {
4253
t.Skip("Mock server tests are disabled")
4354
t.Run("regular flags", func(t *testing.T) {
@@ -71,42 +82,57 @@ func TestBatchSubmit(t *testing.T) {
7182
t,
7283
"--api-key", "string",
7384
"batch", "submit",
74-
"--identifiers", "{linkedinUrl: https://www.linkedin.com/in/yahia-bakour/}",
75-
"--tag", "production",
76-
"--tag", "team-alpha",
77-
"--timeout-ms", "1000",
78-
)
79-
})
80-
81-
t.Run("inner flags", func(t *testing.T) {
82-
// Check that inner flags have been set up correctly
83-
requestflag.CheckInnerFlags(batchSubmit)
84-
85-
// Alternative argument passing style using inner flags
86-
mocktest.TestRunMockTestWithFlags(
87-
t,
88-
"--api-key", "string",
89-
"batch", "submit",
90-
"--identifiers.linkedin-url", "https://www.linkedin.com/in/yahia-bakour/",
91-
"--tag", "production",
92-
"--tag", "team-alpha",
93-
"--timeout-ms", "1000",
85+
"--input", "{data: {format: markdown, urls: [{url: https://example.com/products/anvil, itemId: sku-1, meta: {category: bar}}, {url: https://example.com/products/hammer, itemId: sku-2, meta: {foo: bar}}], options: {country: de, excludeSelectors: [x], includeImages: true, includeLinks: true, includeSelectors: [x], maxAgeMs: 0, pdf: {end: 1, ocr: 'true', shouldParse: 'true', start: 1}, settleAnimations: true, shortenBase64Images: true, useMainContentOnly: true, waitForMs: 0}}, mode: scrape}",
86+
"--tag", "docs",
87+
"--tag", "competitor",
88+
"--webhook-url", "webhookUrl",
89+
"--idempotency-key", "Idempotency-Key",
9490
)
9591
})
9692

9793
t.Run("piping data", func(t *testing.T) {
9894
// Test piping YAML data over stdin
9995
pipeData := []byte("" +
100-
"identifiers:\n" +
101-
" linkedinUrl: https://www.linkedin.com/in/yahia-bakour/\n" +
96+
"input:\n" +
97+
" data:\n" +
98+
" format: markdown\n" +
99+
" urls:\n" +
100+
" - url: https://example.com/products/anvil\n" +
101+
" itemId: sku-1\n" +
102+
" meta:\n" +
103+
" category: bar\n" +
104+
" - url: https://example.com/products/hammer\n" +
105+
" itemId: sku-2\n" +
106+
" meta:\n" +
107+
" foo: bar\n" +
108+
" options:\n" +
109+
" country: de\n" +
110+
" excludeSelectors:\n" +
111+
" - x\n" +
112+
" includeImages: true\n" +
113+
" includeLinks: true\n" +
114+
" includeSelectors:\n" +
115+
" - x\n" +
116+
" maxAgeMs: 0\n" +
117+
" pdf:\n" +
118+
" end: 1\n" +
119+
" ocr: 'true'\n" +
120+
" shouldParse: 'true'\n" +
121+
" start: 1\n" +
122+
" settleAnimations: true\n" +
123+
" shortenBase64Images: true\n" +
124+
" useMainContentOnly: true\n" +
125+
" waitForMs: 0\n" +
126+
" mode: scrape\n" +
102127
"tags:\n" +
103-
" - production\n" +
104-
" - team-alpha\n" +
105-
"timeoutMS: 1000\n")
128+
" - docs\n" +
129+
" - competitor\n" +
130+
"webhookUrl: webhookUrl\n")
106131
mocktest.TestRunMockTestWithPipeAndFlags(
107132
t, pipeData,
108133
"--api-key", "string",
109134
"batch", "submit",
135+
"--idempotency-key", "Idempotency-Key",
110136
)
111137
})
112138
}

‎pkg/cmd/cmd.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,20 @@ func init() {
173173
Commands: []*cli.Command{
174174
&batchRetrieve,
175175
&batchList,
176+
&batchDelete,
176177
&batchCancel,
177178
&batchGetResults,
178179
&batchSubmit,
179180
},
180181
},
182+
{
183+
Name: "people",
184+
Category: "API RESOURCE",
185+
Suggest: true,
186+
Commands: []*cli.Command{
187+
&peopleEnrich,
188+
},
189+
},
181190
{
182191
Name: "@manpages",
183192
Usage: "Generate documentation for 'man'",

0 commit comments

Comments
 (0)