Skip to content

Commit 086b254

Browse files
committed
update index, example and README
1 parent d97760e commit 086b254

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

DeveloperNotes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Developer Notes
22

33
Major part of this sdk is generated from
4-
OpenAPI Spec obtained from the api docs.
4+
OpenAPI Spec obtained from the api docs.
55

66
#### Generation from Spec
77

88
Whenever there are new changes to APIs, the openapi
99
spec available at `openapi.yaml` should be replaced
1010
and the `generate_spec` npm script should be run:
11-
11+
1212
```bash
1313
npm run generate_spec
1414
```

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Docupilot API - JS SDK
22

33
This SDK will help simplify interaction with Docupilot
4-
APIs from `nodejs` or `javascript` environments
4+
APIs from `nodejs` or `javascript` environments
55

66
#### Installation
77

@@ -22,5 +22,5 @@ const client = Docupilot.authorize('<your api token>');
2222
To troy out the _basic_ example
2323

2424
```bash
25-
DOCUPILOT_TOKEN=<your-api-token> ts-node examples/basic
26-
```
25+
DOCUPILOT_ACCESS_KEY=<your-access-key> DOCUPILOT_ACCESS_SECRET=<your-access-secret> ts-node basic.ts
26+
```

examples/basic.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Docupilot from '../index';
22

33
async function run() {
4-
const client = await Docupilot.authorize();
5-
console.log(await client.FoldersService.listFolders({}));
6-
console.log(await client.TemplatesService.listTemplates({}));
4+
const Client = await Docupilot.authorize();
5+
const user = await Client.UsersService.getMe();
6+
console.log(`Docupilot client authenticated as ${user.email}`);
7+
console.log(await Client.FoldersService.listFolders({}));
8+
console.log(await Client.TemplatesService.listTemplates({}));
79
}
810

911
run()

index.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import * as API from './api/index';
22

33
class Client {
4-
readonly TemplatesService = API.TemplatesService;
5-
readonly FoldersService = API.FoldersService;
6-
readonly HistoryService = API.HistoryService;
7-
readonly LinkedAccountsService = API.LinkedAccountsService;
4+
static readonly FoldersService = API.FoldersService;
5+
static readonly TemplatesService = API.TemplatesService;
6+
static readonly GenerateService = API.GenerateService;
7+
static readonly HistoryService = API.HistoryService;
8+
static readonly LinkedAccountsService = API.LinkedAccountsService;
9+
static readonly GenerateBulkService = API.GenerateBulkService;
10+
static readonly TemplateDeliveryService = API.TemplateDeliveryService;
11+
static readonly UsersService = API.UsersService;
812
}
913

1014
export default class Docupilot {
11-
static async authorize(token?: string) {
12-
API.OpenAPI.BASE = (process.env.DOCUPILOT_HOST || 'http://api.docupilot.app').replace(/\/+$/g, '');
13-
API.OpenAPI.TOKEN = token ?? process.env.DOCUPILOT_TOKEN;
14-
console.log("API.OpenAPI.BASE", API.OpenAPI.BASE, API.OpenAPI.TOKEN);
15-
const user = await API.AccountsService.accountsV2UsersMeRetrieve();
16-
console.log(`Docupilot client authenticated as ${user.email}`);
17-
return new Client();
15+
static async authorize(
16+
access_key: string = process.env.DOCUPILOT_ACCESS_KEY as string,
17+
access_secret: string = process.env.DOCUPILOT_ACCESS_SECRET as string,
18+
host: string = process.env.DOCUPILOT_HOST as string,
19+
logger = console.log,
20+
) {
21+
API.OpenAPI.BASE = (host ?? 'https://api.docupilot.app').replace(
22+
/\/+$/g,
23+
'',
24+
);
25+
API.OpenAPI.TOKEN = btoa(`${access_key}:${access_secret}`);
26+
return Client;
1827
}
1928
}

0 commit comments

Comments
 (0)