@interfy/client 0.0.12 → 1.1.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/README.md +194 -1
- package/dist/client.d.ts +42 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +219 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +14 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -15
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -108
- package/dist/index.js.map +1 -0
- package/dist/services/BPMService.d.ts +16 -0
- package/dist/services/BPMService.d.ts.map +1 -0
- package/dist/services/BPMService.js +50 -0
- package/dist/services/BPMService.js.map +1 -0
- package/dist/services/CustomTablesService.d.ts +17 -1
- package/dist/services/CustomTablesService.d.ts.map +1 -0
- package/dist/services/CustomTablesService.js +56 -104
- package/dist/services/CustomTablesService.js.map +1 -0
- package/dist/services/FormFileService.d.ts +8 -1
- package/dist/services/FormFileService.d.ts.map +1 -0
- package/dist/services/FormFileService.js +15 -22
- package/dist/services/FormFileService.js.map +1 -0
- package/dist/services/OrganizationalUnitService.d.ts +9 -0
- package/dist/services/OrganizationalUnitService.d.ts.map +1 -0
- package/dist/services/OrganizationalUnitService.js +20 -0
- package/dist/services/OrganizationalUnitService.js.map +1 -0
- package/dist/services/UserService.d.ts +19 -1
- package/dist/services/UserService.d.ts.map +1 -0
- package/dist/services/UserService.js +49 -19
- package/dist/services/UserService.js.map +1 -0
- package/dist/services/ecm/DocumentService.d.ts +24 -0
- package/dist/services/ecm/DocumentService.d.ts.map +1 -0
- package/dist/services/ecm/DocumentService.js +30 -0
- package/dist/services/ecm/DocumentService.js.map +1 -0
- package/dist/services/ecm/FileService.d.ts +11 -0
- package/dist/services/ecm/FileService.d.ts.map +1 -0
- package/dist/services/ecm/FileService.js +31 -0
- package/dist/services/ecm/FileService.js.map +1 -0
- package/dist/types.d.ts +121 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/{models/authentication.js → types.js} +3 -2
- package/dist/types.js.map +1 -0
- package/package.json +11 -6
- package/dist/models/CustomTable.d.ts +0 -7
- package/dist/models/CustomTable.js +0 -10
- package/dist/models/CustomTableField.d.ts +0 -4
- package/dist/models/CustomTableField.js +0 -8
- package/dist/models/ECM/Document.d.ts +0 -6
- package/dist/models/ECM/Document.js +0 -10
- package/dist/models/ECM/File.d.ts +0 -9
- package/dist/models/ECM/File.js +0 -13
- package/dist/models/User.d.ts +0 -10
- package/dist/models/User.js +0 -14
- package/dist/models/authentication.d.ts +0 -19
- package/dist/services/ECM/DocumentService.d.ts +0 -1
- package/dist/services/ECM/DocumentService.js +0 -46
package/README.md
CHANGED
|
@@ -1 +1,194 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @interfy/client
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Interfy API. Covers BPM, ECM, Custom Tables, Users, Organizational Units, and Form Files.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @interfy/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Client, AuthenticationType } from '@interfy/client'
|
|
15
|
+
|
|
16
|
+
const client = new Client('my-workspace', {
|
|
17
|
+
type: AuthenticationType.OAuthClient,
|
|
18
|
+
client_credentials: {
|
|
19
|
+
client_id: 'your-client-id',
|
|
20
|
+
client_secret: 'your-client-secret',
|
|
21
|
+
scope: 'your-scope',
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// List users
|
|
26
|
+
const users = await client.users.list()
|
|
27
|
+
|
|
28
|
+
// Start a BPM case
|
|
29
|
+
const newCase = await client.bpm.startCase({
|
|
30
|
+
starting_stage: 42,
|
|
31
|
+
context: { priority: 'high' },
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Upload a file to an ECM document
|
|
35
|
+
const file = await client.ecm.files.upload(documentId, buffer, 'report.pdf')
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Authentication
|
|
39
|
+
|
|
40
|
+
### OAuth2 Client Credentials
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const client = new Client('workspace', {
|
|
44
|
+
type: AuthenticationType.OAuthClient,
|
|
45
|
+
client_credentials: {
|
|
46
|
+
client_id: 'id',
|
|
47
|
+
client_secret: 'secret',
|
|
48
|
+
scope: 'scope',
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Basic Auth
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const client = new Client('workspace', {
|
|
57
|
+
type: AuthenticationType.Basic,
|
|
58
|
+
basic_credentials: {
|
|
59
|
+
username: 'user',
|
|
60
|
+
password: 'pass',
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Environment Variables (ScriptTasks)
|
|
66
|
+
|
|
67
|
+
When running inside `interfy-functions` ScriptTasks, environment variables are auto-injected. No constructor arguments needed:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const client = new Client()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Variable | Description |
|
|
74
|
+
|----------|-------------|
|
|
75
|
+
| `INTERFY_WORKSPACE` | Workspace (tenant) identifier |
|
|
76
|
+
| `INTERFY_AUTHENTICATION_TYPE` | `0` = Basic, `1` = OAuth Client |
|
|
77
|
+
| `INTERFY_CLIENT_AUTH_CLIENT_ID` | OAuth client ID |
|
|
78
|
+
| `INTERFY_CLIENT_AUTH_CLIENT_SECRET` | OAuth client secret |
|
|
79
|
+
| `INTERFY_CLIENT_AUTH_SCOPE` | OAuth scope |
|
|
80
|
+
| `INTERFY_BASIC_AUTH_USERNAME` | Basic auth username |
|
|
81
|
+
| `INTERFY_BASIC_AUTH_PASSWORD` | Basic auth password |
|
|
82
|
+
| `INTERFY_API_URL` | API base URL (default: `http://api.interfy.io/api/v2`) |
|
|
83
|
+
| `INTERFY_OAUTH_URL` | OAuth URL (default: `http://api.interfy.io/oauth`) |
|
|
84
|
+
|
|
85
|
+
## Services
|
|
86
|
+
|
|
87
|
+
### Users
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
client.users.list()
|
|
91
|
+
client.users.get(userId)
|
|
92
|
+
client.users.create({ username, email, name, surname })
|
|
93
|
+
client.users.update(userId, { name: 'Updated' })
|
|
94
|
+
client.users.activate(userId)
|
|
95
|
+
client.users.deactivate(userId)
|
|
96
|
+
client.users.restore(userId)
|
|
97
|
+
client.users.delete(userId)
|
|
98
|
+
client.users.getActiveCount()
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### BPM
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
client.bpm.listProcesses()
|
|
105
|
+
client.bpm.getProcess(processId)
|
|
106
|
+
client.bpm.getProcessVariables(processId)
|
|
107
|
+
client.bpm.listVariables()
|
|
108
|
+
client.bpm.getStage(stageId)
|
|
109
|
+
client.bpm.listCases()
|
|
110
|
+
client.bpm.startCase({ starting_stage, context?, data?, active? })
|
|
111
|
+
client.bpm.getCase(caseId)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### ECM Documents
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
client.ecm.documents.get(documentId)
|
|
118
|
+
client.ecm.documents.create({ folder_id, title?, template_id?, fields? })
|
|
119
|
+
client.ecm.documents.update(documentId, data)
|
|
120
|
+
client.ecm.documents.importBatch({ documents: [{ folder_id, title, ... }] })
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### ECM Files
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// Upload a file (multipart/form-data)
|
|
127
|
+
client.ecm.files.upload(documentId, bufferOrStream, 'filename.pdf')
|
|
128
|
+
|
|
129
|
+
// Reference an existing S3 file
|
|
130
|
+
client.ecm.files.uploadRemote(documentId, {
|
|
131
|
+
remote_path: 's3://bucket/path',
|
|
132
|
+
name: 'file.pdf',
|
|
133
|
+
file_type: 'application/pdf',
|
|
134
|
+
file_size: 1024,
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
client.ecm.files.update(documentId, fileId, data)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Custom Tables
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
client.customTables.list()
|
|
144
|
+
client.customTables.get(tableName)
|
|
145
|
+
client.customTables.getColumns(tableName)
|
|
146
|
+
client.customTables.listRows(tableName)
|
|
147
|
+
client.customTables.filterRows(tableName, { column: 'value' })
|
|
148
|
+
client.customTables.addRow(tableName, { column: 'value' })
|
|
149
|
+
client.customTables.getRow(tableName, rowId)
|
|
150
|
+
client.customTables.updateRow(tableName, rowId, data)
|
|
151
|
+
client.customTables.deleteRow(tableName, rowId)
|
|
152
|
+
client.customTables.truncate(tableName)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Organizational Units
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
client.organizationalUnits.list()
|
|
159
|
+
client.organizationalUnits.get(unitId)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Form Files
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
client.formFiles.appendFormFileToECMDocument(formFileId, ecmDocumentId)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Error Handling
|
|
169
|
+
|
|
170
|
+
All API errors are wrapped in `InterfyApiError`:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { InterfyApiError } from '@interfy/client'
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
await client.users.get(999)
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error instanceof InterfyApiError) {
|
|
179
|
+
console.log(error.status) // 404
|
|
180
|
+
console.log(error.endpoint) // "client/users/999"
|
|
181
|
+
console.log(error.response) // API response body
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
OAuth tokens are automatically refreshed on 401 responses.
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
npm install
|
|
192
|
+
npm run build # Compile TypeScript
|
|
193
|
+
npm test # Run tests (Jest)
|
|
194
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AxiosResponse, Method } from 'axios';
|
|
2
|
+
import { AuthenticationConfig } from './types';
|
|
3
|
+
import { UserService } from './services/UserService';
|
|
4
|
+
import { OrganizationalUnitService } from './services/OrganizationalUnitService';
|
|
5
|
+
import { BPMService } from './services/BPMService';
|
|
6
|
+
import { CustomTablesService } from './services/CustomTablesService';
|
|
7
|
+
import { FormFileService } from './services/FormFileService';
|
|
8
|
+
import { DocumentService } from './services/ecm/DocumentService';
|
|
9
|
+
import { FileService } from './services/ecm/FileService';
|
|
10
|
+
export declare class Client {
|
|
11
|
+
authenticationConfig: AuthenticationConfig;
|
|
12
|
+
private workspace;
|
|
13
|
+
private url;
|
|
14
|
+
private oauthUrl;
|
|
15
|
+
private httpClient;
|
|
16
|
+
private authToken?;
|
|
17
|
+
private isRefreshing;
|
|
18
|
+
private _users?;
|
|
19
|
+
private _organizationalUnits?;
|
|
20
|
+
private _bpm?;
|
|
21
|
+
private _customTables?;
|
|
22
|
+
private _formFiles?;
|
|
23
|
+
private _ecm?;
|
|
24
|
+
constructor(workspace?: string, authenticationConfig?: AuthenticationConfig, url?: string, oauthUrl?: string);
|
|
25
|
+
get users(): UserService;
|
|
26
|
+
get organizationalUnits(): OrganizationalUnitService;
|
|
27
|
+
get bpm(): BPMService;
|
|
28
|
+
get customTables(): CustomTablesService;
|
|
29
|
+
get formFiles(): FormFileService;
|
|
30
|
+
get ecm(): {
|
|
31
|
+
documents: DocumentService;
|
|
32
|
+
files: FileService;
|
|
33
|
+
};
|
|
34
|
+
resolveEndpoint(path: string): string;
|
|
35
|
+
private authenticate;
|
|
36
|
+
private fetchToken;
|
|
37
|
+
private clearToken;
|
|
38
|
+
makeRequest(method: Method, endpoint: string, data?: object, params?: Record<string, unknown>): Promise<AxiosResponse>;
|
|
39
|
+
makeMultipartRequest(method: Method, endpoint: string, formData: unknown, headers?: Record<string, string>): Promise<AxiosResponse>;
|
|
40
|
+
private static getAuthenticationConfigFromEnvironment;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,aAAa,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAsB,MAAM,SAAS,CAAA;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD,qBAAa,MAAM;IACjB,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,GAAG,CAAyC;IACpD,OAAO,CAAC,QAAQ,CAAwC;IAExD,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,SAAS,CAAC,CAAQ;IAC1B,OAAO,CAAC,YAAY,CAAQ;IAG5B,OAAO,CAAC,MAAM,CAAC,CAAa;IAC5B,OAAO,CAAC,oBAAoB,CAAC,CAA2B;IACxD,OAAO,CAAC,IAAI,CAAC,CAAY;IACzB,OAAO,CAAC,aAAa,CAAC,CAAqB;IAC3C,OAAO,CAAC,UAAU,CAAC,CAAiB;IACpC,OAAO,CAAC,IAAI,CAAC,CAAoD;gBAG/D,SAAS,CAAC,EAAE,MAAM,EAClB,oBAAoB,CAAC,EAAE,oBAAoB,EAC3C,GAAG,CAAC,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM;IAwCnB,IAAI,KAAK,IAAI,WAAW,CAGvB;IAED,IAAI,mBAAmB,IAAI,yBAAyB,CAGnD;IAED,IAAI,GAAG,IAAI,UAAU,CAGpB;IAED,IAAI,YAAY,IAAI,mBAAmB,CAGtC;IAED,IAAI,SAAS,IAAI,eAAe,CAG/B;IAED,IAAI,GAAG,IAAI;QAAE,SAAS,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,WAAW,CAAA;KAAE,CAQ5D;IAID,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;YASvB,YAAY;YAQZ,UAAU;IAiBxB,OAAO,CAAC,UAAU;IAOZ,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IA4CtH,oBAAoB,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,EACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,aAAa,CAAC;IA4BzB,OAAO,CAAC,MAAM,CAAC,sCAAsC;CAqCtD"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Client = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
const UserService_1 = require("./services/UserService");
|
|
11
|
+
const OrganizationalUnitService_1 = require("./services/OrganizationalUnitService");
|
|
12
|
+
const BPMService_1 = require("./services/BPMService");
|
|
13
|
+
const CustomTablesService_1 = require("./services/CustomTablesService");
|
|
14
|
+
const FormFileService_1 = require("./services/FormFileService");
|
|
15
|
+
const DocumentService_1 = require("./services/ecm/DocumentService");
|
|
16
|
+
const FileService_1 = require("./services/ecm/FileService");
|
|
17
|
+
class Client {
|
|
18
|
+
constructor(workspace, authenticationConfig, url, oauthUrl) {
|
|
19
|
+
this.url = 'http://api.interfy.io/api/v2';
|
|
20
|
+
this.oauthUrl = 'http://api.interfy.io/oauth';
|
|
21
|
+
this.isRefreshing = false;
|
|
22
|
+
if (process.env.INTERFY_WORKSPACE) {
|
|
23
|
+
this.workspace = process.env.INTERFY_WORKSPACE;
|
|
24
|
+
}
|
|
25
|
+
else if (workspace !== undefined) {
|
|
26
|
+
this.workspace = workspace;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new Error('must provide a workspace');
|
|
30
|
+
}
|
|
31
|
+
if (authenticationConfig !== undefined) {
|
|
32
|
+
this.authenticationConfig = authenticationConfig;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const authConfig = Client.getAuthenticationConfigFromEnvironment();
|
|
36
|
+
if (authConfig === undefined)
|
|
37
|
+
throw new Error('must provide authentication config');
|
|
38
|
+
this.authenticationConfig = authConfig;
|
|
39
|
+
}
|
|
40
|
+
if (url !== undefined) {
|
|
41
|
+
this.url = url;
|
|
42
|
+
}
|
|
43
|
+
else if (process.env.INTERFY_API_URL) {
|
|
44
|
+
this.url = process.env.INTERFY_API_URL;
|
|
45
|
+
}
|
|
46
|
+
if (oauthUrl !== undefined) {
|
|
47
|
+
this.oauthUrl = oauthUrl;
|
|
48
|
+
}
|
|
49
|
+
else if (process.env.INTERFY_OAUTH_URL) {
|
|
50
|
+
this.oauthUrl = process.env.INTERFY_OAUTH_URL;
|
|
51
|
+
}
|
|
52
|
+
this.httpClient = axios_1.default.create({
|
|
53
|
+
baseURL: this.url,
|
|
54
|
+
headers: {
|
|
55
|
+
'X-Workspace': this.workspace,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// Service accessors
|
|
60
|
+
get users() {
|
|
61
|
+
if (!this._users)
|
|
62
|
+
this._users = new UserService_1.UserService(this);
|
|
63
|
+
return this._users;
|
|
64
|
+
}
|
|
65
|
+
get organizationalUnits() {
|
|
66
|
+
if (!this._organizationalUnits)
|
|
67
|
+
this._organizationalUnits = new OrganizationalUnitService_1.OrganizationalUnitService(this);
|
|
68
|
+
return this._organizationalUnits;
|
|
69
|
+
}
|
|
70
|
+
get bpm() {
|
|
71
|
+
if (!this._bpm)
|
|
72
|
+
this._bpm = new BPMService_1.BPMService(this);
|
|
73
|
+
return this._bpm;
|
|
74
|
+
}
|
|
75
|
+
get customTables() {
|
|
76
|
+
if (!this._customTables)
|
|
77
|
+
this._customTables = new CustomTablesService_1.CustomTablesService(this);
|
|
78
|
+
return this._customTables;
|
|
79
|
+
}
|
|
80
|
+
get formFiles() {
|
|
81
|
+
if (!this._formFiles)
|
|
82
|
+
this._formFiles = new FormFileService_1.FormFileService(this);
|
|
83
|
+
return this._formFiles;
|
|
84
|
+
}
|
|
85
|
+
get ecm() {
|
|
86
|
+
if (!this._ecm) {
|
|
87
|
+
this._ecm = {
|
|
88
|
+
documents: new DocumentService_1.DocumentService(this),
|
|
89
|
+
files: new FileService_1.FileService(this),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return this._ecm;
|
|
93
|
+
}
|
|
94
|
+
// Endpoint resolution
|
|
95
|
+
resolveEndpoint(path) {
|
|
96
|
+
if (this.authenticationConfig.type === types_1.AuthenticationType.OAuthClient) {
|
|
97
|
+
return `client/${path}`;
|
|
98
|
+
}
|
|
99
|
+
return path;
|
|
100
|
+
}
|
|
101
|
+
// Authentication
|
|
102
|
+
async authenticate() {
|
|
103
|
+
if (this.authenticationConfig.type === types_1.AuthenticationType.Basic) {
|
|
104
|
+
this.httpClient.defaults.auth = this.authenticationConfig.basic_credentials;
|
|
105
|
+
}
|
|
106
|
+
else if (this.authToken === undefined) {
|
|
107
|
+
await this.fetchToken();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async fetchToken() {
|
|
111
|
+
const response = await (0, axios_1.default)({
|
|
112
|
+
method: 'POST',
|
|
113
|
+
url: this.oauthUrl + '/token',
|
|
114
|
+
data: {
|
|
115
|
+
...this.authenticationConfig.client_credentials,
|
|
116
|
+
grant_type: 'client_credentials',
|
|
117
|
+
},
|
|
118
|
+
headers: {
|
|
119
|
+
'X-Workspace': this.workspace,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
this.authToken = response.data.access_token;
|
|
123
|
+
this.httpClient.defaults.headers.common['Authorization'] = 'Bearer ' + this.authToken;
|
|
124
|
+
}
|
|
125
|
+
clearToken() {
|
|
126
|
+
this.authToken = undefined;
|
|
127
|
+
delete this.httpClient.defaults.headers.common['Authorization'];
|
|
128
|
+
}
|
|
129
|
+
// Request execution
|
|
130
|
+
async makeRequest(method, endpoint, data, params) {
|
|
131
|
+
await this.authenticate();
|
|
132
|
+
try {
|
|
133
|
+
return await this.httpClient.request({
|
|
134
|
+
method,
|
|
135
|
+
url: endpoint,
|
|
136
|
+
data,
|
|
137
|
+
params,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (axios_1.default.isAxiosError(error) &&
|
|
142
|
+
error.response?.status === 401 &&
|
|
143
|
+
this.authenticationConfig.type === types_1.AuthenticationType.OAuthClient &&
|
|
144
|
+
!this.isRefreshing) {
|
|
145
|
+
this.isRefreshing = true;
|
|
146
|
+
try {
|
|
147
|
+
this.clearToken();
|
|
148
|
+
await this.fetchToken();
|
|
149
|
+
return await this.httpClient.request({
|
|
150
|
+
method,
|
|
151
|
+
url: endpoint,
|
|
152
|
+
data,
|
|
153
|
+
params,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
this.isRefreshing = false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
161
|
+
throw new errors_1.InterfyApiError(error.message, error.response?.status ?? 0, endpoint, error.response?.data);
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async makeMultipartRequest(method, endpoint, formData, headers) {
|
|
167
|
+
await this.authenticate();
|
|
168
|
+
try {
|
|
169
|
+
return await this.httpClient.request({
|
|
170
|
+
method,
|
|
171
|
+
url: endpoint,
|
|
172
|
+
data: formData,
|
|
173
|
+
headers: {
|
|
174
|
+
...headers,
|
|
175
|
+
'Content-Type': 'multipart/form-data',
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
181
|
+
throw new errors_1.InterfyApiError(error.message, error.response?.status ?? 0, endpoint, error.response?.data);
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Environment config
|
|
187
|
+
static getAuthenticationConfigFromEnvironment() {
|
|
188
|
+
const authTypeStr = process.env.INTERFY_AUTHENTICATION_TYPE;
|
|
189
|
+
if (!authTypeStr || isNaN(parseInt(authTypeStr)))
|
|
190
|
+
return undefined;
|
|
191
|
+
const authType = parseInt(authTypeStr);
|
|
192
|
+
if (authType === types_1.AuthenticationType.Basic &&
|
|
193
|
+
process.env.INTERFY_BASIC_AUTH_USERNAME &&
|
|
194
|
+
process.env.INTERFY_BASIC_AUTH_PASSWORD) {
|
|
195
|
+
return {
|
|
196
|
+
type: authType,
|
|
197
|
+
basic_credentials: {
|
|
198
|
+
username: process.env.INTERFY_BASIC_AUTH_USERNAME,
|
|
199
|
+
password: process.env.INTERFY_BASIC_AUTH_PASSWORD,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
if (process.env.INTERFY_CLIENT_AUTH_CLIENT_ID &&
|
|
204
|
+
process.env.INTERFY_CLIENT_AUTH_CLIENT_SECRET &&
|
|
205
|
+
process.env.INTERFY_CLIENT_AUTH_SCOPE) {
|
|
206
|
+
return {
|
|
207
|
+
type: authType,
|
|
208
|
+
client_credentials: {
|
|
209
|
+
client_id: process.env.INTERFY_CLIENT_AUTH_CLIENT_ID,
|
|
210
|
+
client_secret: process.env.INTERFY_CLIENT_AUTH_CLIENT_SECRET,
|
|
211
|
+
scope: process.env.INTERFY_CLIENT_AUTH_SCOPE,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.Client = Client;
|
|
219
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmE;AACnE,mCAAkE;AAClE,qCAA0C;AAC1C,wDAAoD;AACpD,oFAAgF;AAChF,sDAAkD;AAClD,wEAAoE;AACpE,gEAA4D;AAC5D,oEAAgE;AAChE,4DAAwD;AAExD,MAAa,MAAM;IAkBjB,YACE,SAAkB,EAClB,oBAA2C,EAC3C,GAAY,EACZ,QAAiB;QAnBX,QAAG,GAAW,8BAA8B,CAAA;QAC5C,aAAQ,GAAW,6BAA6B,CAAA;QAIhD,iBAAY,GAAG,KAAK,CAAA;QAgB1B,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;Y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AI,EAAE,QAAQ;gBACd,kBAAkB,EAAE;oBAClB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,6BAA6B;oBACpD,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,iCAAiC;oBAC5D,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;iBAC7C;aACF,CAAA;QACH,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AA9PD,wBA8PC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;gBAEN,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO;CAOlF"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InterfyApiError = void 0;
|
|
4
|
+
class InterfyApiError extends Error {
|
|
5
|
+
constructor(message, status, endpoint, response) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'InterfyApiError';
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.endpoint = endpoint;
|
|
10
|
+
this.response = response;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.InterfyApiError = InterfyApiError;
|
|
14
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;IAKxC,YAAY,OAAe,EAAE,MAAc,EAAE,QAAgB,EAAE,QAAkB;QAC/E,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAZD,0CAYC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private httpClient;
|
|
10
|
-
private authToken?;
|
|
11
|
-
constructor(workspace?: string, authenticationConfig?: Authentication.AuthenticationConfig, url?: string, oauthUrl?: string);
|
|
12
|
-
private authenticate;
|
|
13
|
-
makeRequest(method: Method, endpoint: string, data?: object): Promise<AxiosResponse>;
|
|
14
|
-
private static getAuthenticationConfigFromEnvironment;
|
|
15
|
-
}
|
|
1
|
+
export { Client } from './client';
|
|
2
|
+
export { InterfyApiError } from './errors';
|
|
3
|
+
export { AuthenticationType } from './types';
|
|
4
|
+
export type { AuthenticationConfig, ClientCredentials, BasicCredentials, PaginatedResponse, ListParams, CustomTableListParams, User, CustomTable, CustomTableField, CustomTableRow, ECMDocument, ECMFile, RemoteFileConfig, BPMProcess, BPMCase, BPMStage, BPMVariable, StartCaseData, OrganizationalUnit, } from './types';
|
|
5
|
+
export type { ImportBatchPayload } from './services/ecm/DocumentService';
|
|
6
|
+
import { Client } from './client';
|
|
7
|
+
export default Client;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAC5C,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,qBAAqB,EACrB,IAAI,EACJ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,kBAAkB,GACnB,MAAM,SAAS,CAAA;AAChB,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAGxE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,eAAe,MAAM,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,109 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
constructor(workspace, authenticationConfig, url, oauthUrl) {
|
|
15
|
-
this.url = 'http://api.interfy.io/api/v2';
|
|
16
|
-
this.oauthUrl = 'http://api.interfy.io/oauth';
|
|
17
|
-
if ('INTERFY_WORKSPACE' in process.env && process.env.INTERFY_WORKSPACE) {
|
|
18
|
-
this.workspace = process.env.INTERFY_WORKSPACE;
|
|
19
|
-
}
|
|
20
|
-
else if (workspace !== undefined) {
|
|
21
|
-
this.workspace = workspace;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw new Error("must provide a workspace");
|
|
25
|
-
}
|
|
26
|
-
if (authenticationConfig !== undefined) {
|
|
27
|
-
this.authenticationConfig = authenticationConfig;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
var authConfig = Client.getAuthenticationConfigFromEnvironment();
|
|
31
|
-
if (authConfig === undefined)
|
|
32
|
-
throw new Error("must provide authentication config");
|
|
33
|
-
this.authenticationConfig = authConfig;
|
|
34
|
-
}
|
|
35
|
-
if (url !== undefined) {
|
|
36
|
-
this.url = url;
|
|
37
|
-
}
|
|
38
|
-
else if ('INTERFY_API_URL' in process.env && process.env.INTERFY_API_URL) {
|
|
39
|
-
this.url = process.env.INTERFY_API_URL;
|
|
40
|
-
}
|
|
41
|
-
if (oauthUrl !== undefined) {
|
|
42
|
-
this.oauthUrl = oauthUrl;
|
|
43
|
-
}
|
|
44
|
-
else if ('INTERFY_OAUTH_URL' in process.env && process.env.INTERFY_OAUTH_URL) {
|
|
45
|
-
this.oauthUrl = process.env.INTERFY_OAUTH_URL;
|
|
46
|
-
}
|
|
47
|
-
this.httpClient = axios_1.default.create({
|
|
48
|
-
baseURL: this.url,
|
|
49
|
-
headers: {
|
|
50
|
-
'X-Workspace': this.workspace
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
authenticate() {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
if (this.authenticationConfig.type == Authentication.AuthenticationType.Basic) {
|
|
57
|
-
this.httpClient.defaults.auth = this.authenticationConfig.basic_credentials;
|
|
58
|
-
}
|
|
59
|
-
else if (this.authToken === undefined) {
|
|
60
|
-
let response = yield axios_1.default({
|
|
61
|
-
method: 'POST',
|
|
62
|
-
url: this.oauthUrl + '/token',
|
|
63
|
-
data: Object.assign(Object.assign({}, this.authenticationConfig.client_credentials), { grant_type: 'client_credentials' }),
|
|
64
|
-
headers: {
|
|
65
|
-
'X-Workspace': this.workspace
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
this.authToken = response.data.access_token;
|
|
69
|
-
this.httpClient.defaults.headers.common['Authorization'] = 'Bearer ' + this.authToken;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
makeRequest(method, endpoint, data) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
yield this.authenticate();
|
|
76
|
-
return this.httpClient.request({
|
|
77
|
-
method: method,
|
|
78
|
-
url: endpoint,
|
|
79
|
-
data: data
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
static getAuthenticationConfigFromEnvironment() {
|
|
84
|
-
if ('INTERFY_AUTHENTICATION_TYPE' in process.env && process.env.INTERFY_AUTHENTICATION_TYPE && !isNaN(parseInt(process.env.INTERFY_AUTHENTICATION_TYPE))) {
|
|
85
|
-
var authType = parseInt(process.env.INTERFY_AUTHENTICATION_TYPE);
|
|
86
|
-
var authConfig = {
|
|
87
|
-
type: authType
|
|
88
|
-
};
|
|
89
|
-
if (authType == Authentication.AuthenticationType.Basic &&
|
|
90
|
-
(process.env.INTERFY_BASIC_AUTH_USERNAME &&
|
|
91
|
-
process.env.INTERFY_BASIC_AUTH_PASSWORD)) {
|
|
92
|
-
return Object.assign(Object.assign({}, authConfig), { basic_credentials: {
|
|
93
|
-
username: process.env.INTERFY_BASIC_AUTH_USERNAME,
|
|
94
|
-
password: process.env.INTERFY_BASIC_AUTH_PASSWORD
|
|
95
|
-
} });
|
|
96
|
-
}
|
|
97
|
-
else if (process.env.INTERFY_CLIENT_AUTH_CLIENT_ID &&
|
|
98
|
-
process.env.INTERFY_CLIENT_AUTH_CLIENT_SECRET &&
|
|
99
|
-
process.env.INTERFY_CLIENT_AUTH_SCOPE) {
|
|
100
|
-
return Object.assign(Object.assign({}, authConfig), { client_credentials: {
|
|
101
|
-
client_id: process.env.INTERFY_CLIENT_AUTH_CLIENT_ID,
|
|
102
|
-
client_secret: process.env.INTERFY_CLIENT_AUTH_CLIENT_SECRET,
|
|
103
|
-
scope: process.env.INTERFY_CLIENT_AUTH_SCOPE
|
|
104
|
-
} });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
module.exports = Client;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationType = exports.InterfyApiError = exports.Client = void 0;
|
|
4
|
+
var client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
6
|
+
var errors_1 = require("./errors");
|
|
7
|
+
Object.defineProperty(exports, "InterfyApiError", { enumerable: true, get: function () { return errors_1.InterfyApiError; } });
|
|
8
|
+
var types_1 = require("./types");
|
|
9
|
+
Object.defineProperty(exports, "AuthenticationType", { enumerable: true, get: function () { return types_1.AuthenticationType; } });
|
|
10
|
+
// Default export for backward compat with CommonJS require()
|
|
11
|
+
const client_2 = require("./client");
|
|
12
|
+
exports.default = client_2.Client;
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAAxB,gGAAA,MAAM,OAAA;AACf,mCAA0C;AAAjC,yGAAA,eAAe,OAAA;AACxB,iCAA4C;AAAnC,2GAAA,kBAAkB,OAAA;AAwB3B,6DAA6D;AAC7D,qCAAiC;AACjC,kBAAe,eAAM,CAAA"}
|