-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-record.ts
53 lines (45 loc) · 1.07 KB
/
get-record.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
RecordsClient,
withEndpoint,
withKeyCredentials,
} from "@sajari/sdk-node";
import program, { withDefaultOptions } from "./program";
import { handleError } from "./api-util";
withDefaultOptions(program);
program.requiredOption(
"--record-key-field <record_key_field>",
"record key field",
"id"
);
program.requiredOption(
"--record-key-value <record_key_value>",
"record key value",
"1234"
);
program.parse(process.argv);
async function main(
endpoint = program.endpoint,
collectionId = program.collectionId,
keyId = program.keyId,
keySecret = program.keySecret,
recordKeyField = program.recordKeyField,
recordKeySecret = program.recordKeyValue
) {
try {
const client = new RecordsClient(
collectionId,
withEndpoint(endpoint),
withKeyCredentials(keyId, keySecret)
);
const r = await client.getRecord({
field: recordKeyField,
value: recordKeySecret,
});
for (const [k, v] of Object.entries(r)) {
console.log(`${k}=${JSON.stringify(v)}`);
}
} catch (e) {
handleError(e);
}
}
main();