@owox/api-client 0.26.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/dist/auth.d.ts +11 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +64 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +67 -0
- package/dist/data-marts.d.ts +13 -0
- package/dist/data-marts.d.ts.map +1 -0
- package/dist/data-marts.js +41 -0
- package/dist/destinations.d.ts +12 -0
- package/dist/destinations.d.ts.map +1 -0
- package/dist/destinations.js +16 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +64 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/storages.d.ts +12 -0
- package/dist/storages.d.ts.map +1 -0
- package/dist/storages.js +16 -0
- package/package.json +57 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const API_KEY_EXCHANGE_PATH = "/api/auth/api-keys/exchange";
|
|
2
|
+
export type AuthConfig = {
|
|
3
|
+
apiOrigin: string;
|
|
4
|
+
apiKeyId: string;
|
|
5
|
+
apiKeySecret: string;
|
|
6
|
+
fetchImpl: typeof fetch;
|
|
7
|
+
};
|
|
8
|
+
export declare function normalizeApiOrigin(apiOrigin: string): string;
|
|
9
|
+
export declare function readResponseBody(response: Response): Promise<unknown>;
|
|
10
|
+
export declare function exchangeAccessToken(config: AuthConfig): Promise<string>;
|
|
11
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AAEnE,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,OAAO,KAAK,CAAC;CACzB,CAAC;AAMF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAuB5D;AAED,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB3E;AAED,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CA6B7E"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createHttpError, OWOXAuthError, OWOXConfigError } from './errors.js';
|
|
2
|
+
export const API_KEY_EXCHANGE_PATH = '/api/auth/api-keys/exchange';
|
|
3
|
+
export function normalizeApiOrigin(apiOrigin) {
|
|
4
|
+
if (!apiOrigin.trim()) {
|
|
5
|
+
throw new OWOXConfigError('OWOX API origin is required');
|
|
6
|
+
}
|
|
7
|
+
let url;
|
|
8
|
+
try {
|
|
9
|
+
url = new URL(apiOrigin);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
throw new OWOXConfigError('OWOX API origin must be a valid http or https URL', {
|
|
13
|
+
cause: error,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
17
|
+
throw new OWOXConfigError('OWOX API origin must use http or https');
|
|
18
|
+
}
|
|
19
|
+
if (url.username || url.password || url.search || url.hash || url.pathname !== '/') {
|
|
20
|
+
throw new OWOXConfigError('OWOX API origin must include only scheme, host, and optional port');
|
|
21
|
+
}
|
|
22
|
+
return url.origin;
|
|
23
|
+
}
|
|
24
|
+
export async function readResponseBody(response) {
|
|
25
|
+
const text = await response.text();
|
|
26
|
+
if (!text) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
30
|
+
if (contentType.includes('application/json')) {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(text);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
40
|
+
export async function exchangeAccessToken(config) {
|
|
41
|
+
const response = await config.fetchImpl(new URL(API_KEY_EXCHANGE_PATH, config.apiOrigin), {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: {
|
|
44
|
+
accept: 'application/json',
|
|
45
|
+
'content-type': 'application/json',
|
|
46
|
+
'x-owox-api-key-id': config.apiKeyId,
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify({ apiKeySecret: config.apiKeySecret }),
|
|
49
|
+
});
|
|
50
|
+
const body = await readResponseBody(response);
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw createHttpError(response, body, { auth: true });
|
|
53
|
+
}
|
|
54
|
+
const tokenResponse = body;
|
|
55
|
+
if (!tokenResponse ||
|
|
56
|
+
typeof tokenResponse.accessToken !== 'string' ||
|
|
57
|
+
!tokenResponse.accessToken) {
|
|
58
|
+
throw new OWOXAuthError('OWOX authentication response did not include an access token', {
|
|
59
|
+
status: response.status,
|
|
60
|
+
details: body,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return tokenResponse.accessToken;
|
|
64
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DataMartsApi } from './data-marts.js';
|
|
2
|
+
import { DestinationsApi } from './destinations.js';
|
|
3
|
+
import { StoragesApi } from './storages.js';
|
|
4
|
+
export type OWOXApiClientOptions = {
|
|
5
|
+
apiOrigin: string;
|
|
6
|
+
apiKeyId: string;
|
|
7
|
+
apiKeySecret: string;
|
|
8
|
+
fetchImpl?: typeof fetch;
|
|
9
|
+
};
|
|
10
|
+
export declare class OWOXApiClient {
|
|
11
|
+
readonly dataMarts: DataMartsApi;
|
|
12
|
+
readonly storages: StoragesApi;
|
|
13
|
+
readonly destinations: DestinationsApi;
|
|
14
|
+
private readonly apiOrigin;
|
|
15
|
+
private readonly apiKeyId;
|
|
16
|
+
private readonly apiKeySecret;
|
|
17
|
+
private readonly fetchImpl;
|
|
18
|
+
private accessToken;
|
|
19
|
+
constructor(options: OWOXApiClientOptions);
|
|
20
|
+
authenticate(): Promise<void>;
|
|
21
|
+
getJson<T>(path: string, query?: Record<string, string>): Promise<T>;
|
|
22
|
+
private getJsonWithAuth;
|
|
23
|
+
private getAccessToken;
|
|
24
|
+
private buildUrl;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,qBAAa,aAAa;IACxB,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IAEvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,WAAW,CAAqB;gBAE5B,OAAO,EAAE,oBAAoB;IAWnC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;YAI5D,eAAe;YA4Bf,cAAc;IAa5B,OAAO,CAAC,QAAQ;CASjB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { exchangeAccessToken, normalizeApiOrigin, readResponseBody } from './auth.js';
|
|
2
|
+
import { DataMartsApi } from './data-marts.js';
|
|
3
|
+
import { DestinationsApi } from './destinations.js';
|
|
4
|
+
import { createHttpError } from './errors.js';
|
|
5
|
+
import { StoragesApi } from './storages.js';
|
|
6
|
+
export class OWOXApiClient {
|
|
7
|
+
dataMarts;
|
|
8
|
+
storages;
|
|
9
|
+
destinations;
|
|
10
|
+
apiOrigin;
|
|
11
|
+
apiKeyId;
|
|
12
|
+
apiKeySecret;
|
|
13
|
+
fetchImpl;
|
|
14
|
+
accessToken;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.apiOrigin = normalizeApiOrigin(options.apiOrigin);
|
|
17
|
+
this.apiKeyId = options.apiKeyId;
|
|
18
|
+
this.apiKeySecret = options.apiKeySecret;
|
|
19
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
20
|
+
this.dataMarts = new DataMartsApi(this);
|
|
21
|
+
this.storages = new StoragesApi(this);
|
|
22
|
+
this.destinations = new DestinationsApi(this);
|
|
23
|
+
}
|
|
24
|
+
async authenticate() {
|
|
25
|
+
await this.getAccessToken();
|
|
26
|
+
}
|
|
27
|
+
async getJson(path, query) {
|
|
28
|
+
return this.getJsonWithAuth(path, query, true);
|
|
29
|
+
}
|
|
30
|
+
async getJsonWithAuth(path, query, retryOnUnauthorized) {
|
|
31
|
+
const response = await this.fetchImpl(this.buildUrl(path, query), {
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers: {
|
|
34
|
+
accept: 'application/json',
|
|
35
|
+
'x-owox-authorization': `Bearer ${await this.getAccessToken()}`,
|
|
36
|
+
'x-owox-api-key-id': this.apiKeyId,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (response.status === 401 && retryOnUnauthorized) {
|
|
40
|
+
this.accessToken = undefined;
|
|
41
|
+
return this.getJsonWithAuth(path, query, false);
|
|
42
|
+
}
|
|
43
|
+
const body = await readResponseBody(response);
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
throw createHttpError(response, body);
|
|
46
|
+
}
|
|
47
|
+
return body;
|
|
48
|
+
}
|
|
49
|
+
async getAccessToken() {
|
|
50
|
+
if (!this.accessToken) {
|
|
51
|
+
this.accessToken = await exchangeAccessToken({
|
|
52
|
+
apiOrigin: this.apiOrigin,
|
|
53
|
+
apiKeyId: this.apiKeyId,
|
|
54
|
+
apiKeySecret: this.apiKeySecret,
|
|
55
|
+
fetchImpl: this.fetchImpl,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return this.accessToken;
|
|
59
|
+
}
|
|
60
|
+
buildUrl(path, query) {
|
|
61
|
+
const url = new URL(path, this.apiOrigin);
|
|
62
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
63
|
+
url.searchParams.set(key, value);
|
|
64
|
+
}
|
|
65
|
+
return url;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type OWOXDataMart = Record<string, unknown> & {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
};
|
|
5
|
+
export type JsonRequester = {
|
|
6
|
+
getJson<T>(path: string, query?: Record<string, string>): Promise<T>;
|
|
7
|
+
};
|
|
8
|
+
export declare class DataMartsApi {
|
|
9
|
+
private readonly requester;
|
|
10
|
+
constructor(requester: JsonRequester);
|
|
11
|
+
list(): Promise<OWOXDataMart[]>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=data-marts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-marts.d.ts","sourceRoot":"","sources":["../src/data-marts.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAQF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtE,CAAC;AAqBF,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE/C,IAAI,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;CA8BtC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { OWOXApiError } from './errors.js';
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function parsePage(response) {
|
|
6
|
+
if (!isRecord(response) ||
|
|
7
|
+
!Array.isArray(response.items) ||
|
|
8
|
+
typeof response.total !== 'number' ||
|
|
9
|
+
(typeof response.nextOffset !== 'number' && response.nextOffset !== null)) {
|
|
10
|
+
throw new OWOXApiError('OWOX Data Marts API returned an unexpected response shape', {
|
|
11
|
+
details: response,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return response;
|
|
15
|
+
}
|
|
16
|
+
export class DataMartsApi {
|
|
17
|
+
requester;
|
|
18
|
+
constructor(requester) {
|
|
19
|
+
this.requester = requester;
|
|
20
|
+
}
|
|
21
|
+
async list() {
|
|
22
|
+
const dataMarts = [];
|
|
23
|
+
const requestedOffsets = new Set();
|
|
24
|
+
let offset;
|
|
25
|
+
while (true) {
|
|
26
|
+
const offsetKey = String(offset ?? 0);
|
|
27
|
+
if (requestedOffsets.has(offsetKey)) {
|
|
28
|
+
throw new OWOXApiError(`OWOX Data Marts API returned repeated nextOffset ${offsetKey}`, {
|
|
29
|
+
details: { offset },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
requestedOffsets.add(offsetKey);
|
|
33
|
+
const page = parsePage(await this.requester.getJson('/api/data-marts', offset === undefined ? undefined : { offset: String(offset) }));
|
|
34
|
+
dataMarts.push(...page.items);
|
|
35
|
+
if (page.nextOffset === null) {
|
|
36
|
+
return dataMarts;
|
|
37
|
+
}
|
|
38
|
+
offset = page.nextOffset;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JsonRequester } from './data-marts.js';
|
|
2
|
+
export type OWOXDestination = Record<string, unknown> & {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
type: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class DestinationsApi {
|
|
8
|
+
private readonly requester;
|
|
9
|
+
constructor(requester: JsonRequester);
|
|
10
|
+
list(): Promise<OWOXDestination[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=destinations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destinations.d.ts","sourceRoot":"","sources":["../src/destinations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE/C,IAAI,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAWzC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OWOXApiError } from './errors.js';
|
|
2
|
+
export class DestinationsApi {
|
|
3
|
+
requester;
|
|
4
|
+
constructor(requester) {
|
|
5
|
+
this.requester = requester;
|
|
6
|
+
}
|
|
7
|
+
async list() {
|
|
8
|
+
const response = await this.requester.getJson('/api/data-destinations');
|
|
9
|
+
if (!Array.isArray(response)) {
|
|
10
|
+
throw new OWOXApiError('OWOX Data Destinations API returned an unexpected response shape', {
|
|
11
|
+
details: response,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return response;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type OWOXApiErrorOptions = {
|
|
2
|
+
status?: number;
|
|
3
|
+
code?: string;
|
|
4
|
+
details?: unknown;
|
|
5
|
+
cause?: unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare class OWOXApiError extends Error {
|
|
8
|
+
status?: number;
|
|
9
|
+
code?: string;
|
|
10
|
+
details?: unknown;
|
|
11
|
+
constructor(message: string, options?: OWOXApiErrorOptions);
|
|
12
|
+
}
|
|
13
|
+
export declare class OWOXAuthError extends OWOXApiError {
|
|
14
|
+
}
|
|
15
|
+
export declare class OWOXConfigError extends Error {
|
|
16
|
+
constructor(message: string, options?: {
|
|
17
|
+
cause?: unknown;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export declare function createHttpError(response: Response, body: unknown, options?: {
|
|
21
|
+
auth?: boolean;
|
|
22
|
+
}): OWOXApiError;
|
|
23
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,qBAAa,YAAa,SAAQ,KAAK;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEN,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAO/D;AAED,qBAAa,aAAc,SAAQ,YAAY;CAAG;AAElD,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAI/D;AAgDD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,OAAO,EACb,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,GAC/B,YAAY,CAcd"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class OWOXApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
code;
|
|
4
|
+
details;
|
|
5
|
+
constructor(message, options = {}) {
|
|
6
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
7
|
+
this.name = new.target.name;
|
|
8
|
+
this.status = options.status;
|
|
9
|
+
this.code = options.code;
|
|
10
|
+
this.details = options.details;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class OWOXAuthError extends OWOXApiError {
|
|
14
|
+
}
|
|
15
|
+
export class OWOXConfigError extends Error {
|
|
16
|
+
constructor(message, options = {}) {
|
|
17
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
18
|
+
this.name = 'OWOXConfigError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function isRecord(value) {
|
|
22
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
function readErrorCode(body) {
|
|
25
|
+
if (!isRecord(body)) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const { code, error } = body;
|
|
29
|
+
if (typeof code === 'string' && code) {
|
|
30
|
+
return code;
|
|
31
|
+
}
|
|
32
|
+
if (typeof error === 'string' && error) {
|
|
33
|
+
return error;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function readErrorMessage(body) {
|
|
38
|
+
if (!isRecord(body)) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const { message } = body;
|
|
42
|
+
return typeof message === 'string' && message ? message : undefined;
|
|
43
|
+
}
|
|
44
|
+
function readErrorDetails(body) {
|
|
45
|
+
if (!isRecord(body)) {
|
|
46
|
+
return body;
|
|
47
|
+
}
|
|
48
|
+
const { details } = body;
|
|
49
|
+
return details === undefined ? body : details;
|
|
50
|
+
}
|
|
51
|
+
export function createHttpError(response, body, options = {}) {
|
|
52
|
+
const code = readErrorCode(body);
|
|
53
|
+
const responseMessage = readErrorMessage(body);
|
|
54
|
+
const statusText = response.statusText || 'HTTP error';
|
|
55
|
+
const message = responseMessage
|
|
56
|
+
? `OWOX API request failed with ${response.status} ${statusText}: ${responseMessage}`
|
|
57
|
+
: `OWOX API request failed with ${response.status} ${statusText}`;
|
|
58
|
+
const ErrorClass = options.auth || response.status === 401 ? OWOXAuthError : OWOXApiError;
|
|
59
|
+
return new ErrorClass(message, {
|
|
60
|
+
status: response.status,
|
|
61
|
+
code,
|
|
62
|
+
details: readErrorDetails(body),
|
|
63
|
+
});
|
|
64
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { OWOXApiClient, type OWOXApiClientOptions } from './client.js';
|
|
2
|
+
export { OWOXApiError, OWOXAuthError, OWOXConfigError } from './errors.js';
|
|
3
|
+
export { type OWOXDataMart } from './data-marts.js';
|
|
4
|
+
export { type OWOXStorage } from './storages.js';
|
|
5
|
+
export { type OWOXDestination } from './destinations.js';
|
|
6
|
+
//# 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,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JsonRequester } from './data-marts.js';
|
|
2
|
+
export type OWOXStorage = Record<string, unknown> & {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
type: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class StoragesApi {
|
|
8
|
+
private readonly requester;
|
|
9
|
+
constructor(requester: JsonRequester);
|
|
10
|
+
list(): Promise<OWOXStorage[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=storages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storages.d.ts","sourceRoot":"","sources":["../src/storages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAClD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE/C,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAWrC"}
|
package/dist/storages.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OWOXApiError } from './errors.js';
|
|
2
|
+
export class StoragesApi {
|
|
3
|
+
requester;
|
|
4
|
+
constructor(requester) {
|
|
5
|
+
this.requester = requester;
|
|
6
|
+
}
|
|
7
|
+
async list() {
|
|
8
|
+
const response = await this.requester.getJson('/api/data-storages');
|
|
9
|
+
if (!Array.isArray(response)) {
|
|
10
|
+
throw new OWOXApiError('OWOX Data Storages API returned an unexpected response shape', {
|
|
11
|
+
details: response,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return response;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@owox/api-client",
|
|
3
|
+
"version": "0.26.0",
|
|
4
|
+
"description": "HTTP API client for OWOX Data Marts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "OWOX",
|
|
7
|
+
"license": "ELv2",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22.16.0"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/OWOX/owox-data-marts",
|
|
15
|
+
"bugs": "https://github.com/OWOX/owox-data-marts/issues",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/OWOX/owox-data-marts.git",
|
|
19
|
+
"directory": "packages/api-client"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"clean": "shx rm -rf dist",
|
|
24
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
|
|
25
|
+
"lint": "eslint . --config ./eslint.config.js",
|
|
26
|
+
"lint:fix": "eslint . --fix --config ./eslint.config.js",
|
|
27
|
+
"format": "prettier --write \"**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
|
|
28
|
+
"format:check": "prettier --check \"**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"prepublishOnly": "npm run lint && npm run typecheck"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"owox",
|
|
34
|
+
"data-marts",
|
|
35
|
+
"api-client",
|
|
36
|
+
"http"
|
|
37
|
+
],
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@owox/eslint-config": "*",
|
|
40
|
+
"@owox/prettier-config": "*",
|
|
41
|
+
"@types/jest": "29.5.14",
|
|
42
|
+
"@types/node": "^22.10.7",
|
|
43
|
+
"jest": "^30.2.0",
|
|
44
|
+
"ts-jest": "^29.4.6"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"exports": {
|
|
50
|
+
".": {
|
|
51
|
+
"import": "./dist/index.js",
|
|
52
|
+
"types": "./dist/index.d.ts"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"main": "./dist/index.js",
|
|
56
|
+
"types": "./dist/index.d.ts"
|
|
57
|
+
}
|