@api7/portal-sdk 0.0.1 → 0.0.2
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 +39 -5
- package/dist/api_product.d.ts +4 -2
- package/dist/api_product.d.ts.map +1 -1
- package/dist/application.d.ts +7 -11
- package/dist/application.d.ts.map +1 -1
- package/dist/browser.cjs +1 -0
- package/dist/browser.d.ts +22 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +23 -0
- package/dist/credential.d.ts +51 -2
- package/dist/credential.d.ts.map +1 -1
- package/dist/index.cjs +1 -7
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1012
- package/dist/subscription-DPb2gn6N.js +1054 -0
- package/dist/subscription-ukRySaBq.cjs +7 -0
- package/dist/subscription.d.ts +1 -0
- package/dist/subscription.d.ts.map +1 -1
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +1 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -14,24 +14,58 @@ This package supports both ESM and CJS, and you can use it in browsers and Node.
|
|
|
14
14
|
|
|
15
15
|
## Configure
|
|
16
16
|
|
|
17
|
+
### Server-side (Node.js/Serverless/Edge-functions)
|
|
18
|
+
|
|
19
|
+
Call APIs in the backend or build a BFF.
|
|
20
|
+
|
|
17
21
|
```typescript
|
|
18
22
|
import { API7Portal } from '@api7/portal-sdk'
|
|
19
23
|
|
|
20
|
-
const client = new API7Portal(
|
|
21
|
-
'https://portal.example.com',
|
|
22
|
-
'a7prt-...'
|
|
23
|
-
)
|
|
24
|
+
const client = new API7Portal({
|
|
25
|
+
endpoint: 'https://portal.example.com',
|
|
26
|
+
token: 'a7prt-...',
|
|
27
|
+
getDeveloperId: async () => await getDeveloperIdFromSession(),
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Client-side (Browser)
|
|
32
|
+
|
|
33
|
+
This pattern is used to send requests to a BFF on the same origin within the browser. Authentication and Developer ID injection should occur within the BFF, so you do not need to configure authentication here.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { API7Portal } from '@api7/portal-sdk/browser'
|
|
37
|
+
|
|
38
|
+
// request the API exposed on current page's window.origin
|
|
39
|
+
const client = new API7Portal();
|
|
24
40
|
```
|
|
25
41
|
|
|
26
42
|
## Usage
|
|
27
43
|
|
|
28
|
-
Access API
|
|
44
|
+
### Access the API programmatically
|
|
29
45
|
|
|
30
46
|
```typescript
|
|
31
47
|
const apps = await client.apiProduct.list();
|
|
32
48
|
console.log(apps);
|
|
33
49
|
```
|
|
34
50
|
|
|
51
|
+
### Proxy requests through SDK
|
|
52
|
+
|
|
53
|
+
> [!IMPORTANT]
|
|
54
|
+
> This applies only to the Server-side SDK.
|
|
55
|
+
>
|
|
56
|
+
> I.e., using the SDK imported via `import { API7Portal } from '@api7/portal-sdk'`.
|
|
57
|
+
|
|
58
|
+
It is used to design and build the BFF, which enables lightweight API reverse proxies on the server to inject additional fields when forwarding requests to backend services.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const resp = await client.proxy({
|
|
62
|
+
method: clientReq.method,
|
|
63
|
+
url: clientReq.url,
|
|
64
|
+
headers: clientReq.headers,
|
|
65
|
+
data: clientReq.body,
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
35
69
|
## Error Handling
|
|
36
70
|
|
|
37
71
|
When you call an API, APIError is the only type of error expected to be thrown, whether it's an error on the REST API or a network error.
|
package/dist/api_product.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Client } from './generated/client/types.gen.js';
|
|
2
|
-
import { ListApiProductsData, ListApiProductsResponses, ApiProduct } from './generated/index.js';
|
|
2
|
+
import { ListApiProductsData, ListApiProductsResponses, ApiProduct, CreateApiProductSubscriptionReq } from './generated/index.js';
|
|
3
3
|
export declare class APIProductAPI {
|
|
4
4
|
private readonly client;
|
|
5
5
|
constructor(client: Client);
|
|
6
6
|
/**
|
|
7
7
|
* List all API products.
|
|
8
|
+
* @param query The query parameters.
|
|
8
9
|
* @returns The list of API products.
|
|
9
10
|
* @throws {APIError} If the API request fails or network error occurs.
|
|
10
11
|
*/
|
|
@@ -19,8 +20,9 @@ export declare class APIProductAPI {
|
|
|
19
20
|
/**
|
|
20
21
|
* Subscribe to an API product by ID.
|
|
21
22
|
* @param id The API product ID.
|
|
23
|
+
* @param data The subscription data.
|
|
22
24
|
* @throws {APIError} If the API request fails or network error occurs.
|
|
23
25
|
*/
|
|
24
|
-
subscribe(id: string): Promise<void>;
|
|
26
|
+
subscribe(id: string, data: CreateApiProductSubscriptionReq): Promise<void>;
|
|
25
27
|
}
|
|
26
28
|
//# sourceMappingURL=api_product.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_product.d.ts","sourceRoot":"","sources":["../src/api_product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,UAAU,
|
|
1
|
+
{"version":3,"file":"api_product.d.ts","sourceRoot":"","sources":["../src/api_product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,UAAU,EACV,+BAA+B,EAChC,MAAM,sBAAsB,CAAC;AAG9B,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C;;;;;OAKG;IACU,IAAI,CACf,KAAK,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACnC,OAAO,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAM3C;;;;;OAKG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IASjD;;;;;OAKG;IACU,SAAS,CACpB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,+BAA+B,GACpC,OAAO,CAAC,IAAI,CAAC;CASjB"}
|
package/dist/application.d.ts
CHANGED
|
@@ -7,43 +7,39 @@ export declare class ApplicationAPI {
|
|
|
7
7
|
constructor(client: Client);
|
|
8
8
|
/**
|
|
9
9
|
* Create a new developer application.
|
|
10
|
-
* @param
|
|
11
|
-
* @param application The application data.
|
|
10
|
+
* @param data The application data.
|
|
12
11
|
* @returns The created developer application.
|
|
13
12
|
* @throws {APIError} If the API request fails or network error occurs.
|
|
14
13
|
*/
|
|
15
|
-
create(
|
|
14
|
+
create(data: CreateDeveloperApplicationReq): Promise<DeveloperApplication>;
|
|
16
15
|
/**
|
|
17
16
|
* List all applications for a developer.
|
|
18
|
-
* @param
|
|
17
|
+
* @param query The query parameters.
|
|
19
18
|
* @returns The list of developer's applications.
|
|
20
19
|
* @throws {APIError} If the API request fails or network error occurs.
|
|
21
20
|
*/
|
|
22
|
-
list(
|
|
21
|
+
list(query?: ListDeveloperApplicationsData['query']): Promise<ListDeveloperApplicationsResponses['200']>;
|
|
23
22
|
/**
|
|
24
23
|
* Get a developer application by ID.
|
|
25
|
-
* @param developerId The developer ID.
|
|
26
24
|
* @param applicationId The application ID.
|
|
27
25
|
* @returns The developer application.
|
|
28
26
|
* @throws {APIError} If the API request fails or network error occurs.
|
|
29
27
|
*/
|
|
30
|
-
get(
|
|
28
|
+
get(applicationId: string): Promise<DeveloperApplication>;
|
|
31
29
|
/**
|
|
32
30
|
* Update a developer application.
|
|
33
|
-
* @param developerId The developer ID.
|
|
34
31
|
* @param applicationId The application ID.
|
|
35
32
|
* @param data The application data.
|
|
36
33
|
* @returns The updated developer application.
|
|
37
34
|
* @throws {APIError} If the API request fails or network error occurs.
|
|
38
35
|
*/
|
|
39
|
-
update(
|
|
36
|
+
update(applicationId: string, data: CreateDeveloperApplicationReq): Promise<DeveloperApplication>;
|
|
40
37
|
/**
|
|
41
38
|
* Delete a developer application.
|
|
42
|
-
* @param developerId The developer ID.
|
|
43
39
|
* @param applicationId The application ID.
|
|
44
40
|
* @throws {APIError} If the API request fails or network error occurs.
|
|
45
41
|
*/
|
|
46
|
-
delete(
|
|
42
|
+
delete(applicationId: string): Promise<void>;
|
|
47
43
|
/**
|
|
48
44
|
* Get API call metrics.
|
|
49
45
|
* @param query The query parameters.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,6BAA6B,EAE7B,oBAAoB,EAGpB,6BAA6B,EAC7B,kCAAkC,EAGlC,eAAe,EACf,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAGzD,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,SAAgB,UAAU,EAAE,wBAAwB,CAAC;gBAExB,MAAM,EAAE,MAAM;IAI3C
|
|
1
|
+
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,6BAA6B,EAE7B,oBAAoB,EAGpB,6BAA6B,EAC7B,kCAAkC,EAGlC,eAAe,EACf,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAGzD,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,SAAgB,UAAU,EAAE,wBAAwB,CAAC;gBAExB,MAAM,EAAE,MAAM;IAI3C;;;;;OAKG;IACU,MAAM,CACjB,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,oBAAoB,CAAC;IAShC;;;;;OAKG;IACU,IAAI,CACf,KAAK,CAAC,EAAE,6BAA6B,CAAC,OAAO,CAAC,GAC7C,OAAO,CAAC,kCAAkC,CAAC,KAAK,CAAC,CAAC;IAMrD;;;;;OAKG;IACU,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAStE;;;;;;OAMG;IACU,MAAM,CACjB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,6BAA6B,GAClC,OAAO,CAAC,oBAAoB,CAAC;IAUhC;;;;OAIG;IACU,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASzD;;;;;OAKG;IACU,OAAO,CAClB,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,GAC9B,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;CAQxC"}
|
package/dist/browser.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("axios"),e=require("./subscription-ukRySaBq.cjs");class s{apiProduct;application;credential;dcrProvider;developer;misc;subscription;systemSetting;constructor(i){const t=e.createClient({axios:r.create({baseURL:i?.endpoint})});this.apiProduct=new e.APIProductAPI(t),this.application=new e.ApplicationAPI(t),this.credential=new e.CredentialAPI(t),this.dcrProvider=new e.DCRProviderAPI(t),this.developer=new e.DeveloperAPI(t),this.misc=new e.MiscellaneousAPI(t),this.subscription=new e.SubscriptionAPI(t),this.systemSetting=new e.SystemSettingAPI(t)}}exports.APIError=e.APIError;exports.API7Portal=s;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ApplicationAPI } from './application.js';
|
|
2
|
+
import { CredentialAPI } from './credential.js';
|
|
3
|
+
import { DCRProviderAPI, MiscellaneousAPI, SystemSettingAPI } from './miscellaneous.js';
|
|
4
|
+
import { DeveloperAPI } from './developer.js';
|
|
5
|
+
import { APIProductAPI } from './api_product.js';
|
|
6
|
+
import { SubscriptionAPI } from './subscription.js';
|
|
7
|
+
export { APIError } from './utils.js';
|
|
8
|
+
export type Options = {
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class API7Portal {
|
|
12
|
+
readonly apiProduct: APIProductAPI;
|
|
13
|
+
readonly application: ApplicationAPI;
|
|
14
|
+
readonly credential: CredentialAPI;
|
|
15
|
+
readonly dcrProvider: DCRProviderAPI;
|
|
16
|
+
readonly developer: DeveloperAPI;
|
|
17
|
+
readonly misc: MiscellaneousAPI;
|
|
18
|
+
readonly subscription: SubscriptionAPI;
|
|
19
|
+
readonly systemSetting: SystemSettingAPI;
|
|
20
|
+
constructor(opts?: Options);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,qBAAa,UAAU;IACrB,SAAgB,UAAU,EAAE,aAAa,CAAC;IAC1C,SAAgB,WAAW,EAAE,cAAc,CAAC;IAC5C,SAAgB,UAAU,EAAE,aAAa,CAAC;IAC1C,SAAgB,WAAW,EAAE,cAAc,CAAC;IAC5C,SAAgB,SAAS,EAAE,YAAY,CAAC;IACxC,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IACvC,SAAgB,YAAY,EAAE,eAAe,CAAC;IAC9C,SAAgB,aAAa,EAAE,gBAAgB,CAAC;gBAEpC,IAAI,CAAC,EAAE,OAAO;CAa3B"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import i from "axios";
|
|
2
|
+
import { c as s, A as r, a as o, C as a, D as n, b as c, M as p, S as P, d } from "./subscription-DPb2gn6N.js";
|
|
3
|
+
import { e as w } from "./subscription-DPb2gn6N.js";
|
|
4
|
+
class m {
|
|
5
|
+
apiProduct;
|
|
6
|
+
application;
|
|
7
|
+
credential;
|
|
8
|
+
dcrProvider;
|
|
9
|
+
developer;
|
|
10
|
+
misc;
|
|
11
|
+
subscription;
|
|
12
|
+
systemSetting;
|
|
13
|
+
constructor(t) {
|
|
14
|
+
const e = s({
|
|
15
|
+
axios: i.create({ baseURL: t?.endpoint })
|
|
16
|
+
});
|
|
17
|
+
this.apiProduct = new r(e), this.application = new o(e), this.credential = new a(e), this.dcrProvider = new n(e), this.developer = new c(e), this.misc = new p(e), this.subscription = new P(e), this.systemSetting = new d(e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
m as API7Portal,
|
|
22
|
+
w as APIError
|
|
23
|
+
};
|
package/dist/credential.d.ts
CHANGED
|
@@ -3,16 +3,65 @@ import { Client } from './generated/client/types.gen.js';
|
|
|
3
3
|
export declare class ApplicationCredentialAPI {
|
|
4
4
|
private readonly client;
|
|
5
5
|
constructor(client: Client);
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Create a new application credential.
|
|
8
|
+
* @param applicationId The application ID.
|
|
9
|
+
* @param data The credential data.
|
|
10
|
+
* @returns The created application credential.
|
|
11
|
+
* @throws {APIError} If the API request fails or network error occurs.
|
|
12
|
+
*/
|
|
13
|
+
create(applicationId: string, data: CreateApplicationCredentialReq): Promise<ApplicationCredential>;
|
|
14
|
+
/**
|
|
15
|
+
* List all application credentials for a given application.
|
|
16
|
+
* @param applicationId The application ID.
|
|
17
|
+
* @param query The query parameters.
|
|
18
|
+
* @returns The list of application credentials.
|
|
19
|
+
* @throws {APIError} If the API request fails or network error occurs.
|
|
20
|
+
*/
|
|
7
21
|
list(applicationId: string, query: ListDeveloperCredentialsData['query']): Promise<ListDeveloperCredentialsResponses['200']>;
|
|
22
|
+
/**
|
|
23
|
+
* Get an application credential by ID.
|
|
24
|
+
* @param applicationId The application ID.
|
|
25
|
+
* @param credentialId The credential ID.
|
|
26
|
+
* @returns The application credential.
|
|
27
|
+
* @throws {APIError} If the API request fails or network error occurs.
|
|
28
|
+
*/
|
|
8
29
|
get(applicationId: string, credentialId: string): Promise<ApplicationCredential>;
|
|
30
|
+
/**
|
|
31
|
+
* Update an application credential.
|
|
32
|
+
* @param applicationId The application ID.
|
|
33
|
+
* @param credentialId The credential ID.
|
|
34
|
+
* @param data The credential data.
|
|
35
|
+
* @returns The updated application credential.
|
|
36
|
+
* @throws {APIError} If the API request fails or network error occurs.
|
|
37
|
+
*/
|
|
9
38
|
update(applicationId: string, credentialId: string, data: UpdateApplicationCredentialReq): Promise<ApplicationCredential>;
|
|
39
|
+
/**
|
|
40
|
+
* Delete an application credential.
|
|
41
|
+
* @param applicationId The application ID.
|
|
42
|
+
* @param credentialId The credential ID.
|
|
43
|
+
* @throws {APIError} If the API request fails or network error occurs.
|
|
44
|
+
*/
|
|
10
45
|
delete(applicationId: string, credentialId: string): Promise<void>;
|
|
11
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Regenerate an application credential.
|
|
48
|
+
* @param applicationId The application ID.
|
|
49
|
+
* @param credentialId The credential ID.
|
|
50
|
+
* @param data The credential data.
|
|
51
|
+
* @returns The regenerated application credential.
|
|
52
|
+
* @throws {APIError} If the API request fails or network error occurs.
|
|
53
|
+
*/
|
|
54
|
+
regenerate(applicationId: string, credentialId: string, data: RegenerateApplicationCredentialReq): Promise<ApplicationCredential>;
|
|
12
55
|
}
|
|
13
56
|
export declare class CredentialAPI {
|
|
14
57
|
private readonly client;
|
|
15
58
|
constructor(client: Client);
|
|
59
|
+
/**
|
|
60
|
+
* List all credentials.
|
|
61
|
+
* @param query The query parameters.
|
|
62
|
+
* @returns The list of credentials.
|
|
63
|
+
* @throws {APIError} If the API request fails or network error occurs.
|
|
64
|
+
*/
|
|
16
65
|
list(query: ListCredentialsData['query']): Promise<ListCredentialsResponses['200']>;
|
|
17
66
|
}
|
|
18
67
|
//# sourceMappingURL=credential.d.ts.map
|
package/dist/credential.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,8BAA8B,EAC9B,8BAA8B,EAC9B,kCAAkC,EAGlC,qBAAqB,EACrB,iCAAiC,EACjC,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAGzD,qBAAa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,8BAA8B,EAC9B,8BAA8B,EAC9B,kCAAkC,EAGlC,qBAAqB,EACrB,iCAAiC,EACjC,4BAA4B,EAC5B,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAGzD,qBAAa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C;;;;;;OAMG;IACU,MAAM,CACjB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,8BAA8B,GACnC,OAAO,CAAC,qBAAqB,CAAC;IAUjC;;;;;;OAMG;IACU,IAAI,CACf,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,4BAA4B,CAAC,OAAO,CAAC,GAC3C,OAAO,CAAC,iCAAiC,CAAC,KAAK,CAAC,CAAC;IAUpD;;;;;;OAMG;IACU,GAAG,CACd,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,qBAAqB,CAAC;IAYjC;;;;;;;OAOG;IACU,MAAM,CACjB,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,8BAA8B,GACnC,OAAO,CAAC,qBAAqB,CAAC;IAajC;;;;;OAKG;IACU,MAAM,CACjB,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;OAOG;IACU,UAAU,CACrB,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,kCAAkC,GACvC,OAAO,CAAC,qBAAqB,CAAC;CAYlC;AAED,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C;;;;;OAKG;IACU,IAAI,CACf,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAClC,OAAO,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;CAQ5C"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).replace(/\r/g,`
|
|
3
|
-
`);const q=S.split(`
|
|
4
|
-
|
|
5
|
-
`);S=q.pop()??"";for(const Y of q){const Z=Y.split(`
|
|
6
|
-
`),D=[];let U;for(const f of Z)if(f.startsWith("data:"))D.push(f.replace(/^data:\s*/,""));else if(f.startsWith("event:"))U=f.replace(/^event:\s*/,"");else if(f.startsWith("id:"))h=f.replace(/^id:\s*/,"");else if(f.startsWith("retry:")){const B=Number.parseInt(f.replace(/^retry:\s*/,""),10);Number.isNaN(B)||(m=B)}let T,N=!1;if(D.length){const f=D.join(`
|
|
7
|
-
`);try{T=JSON.parse(f),N=!0}catch{T=f}}N&&(n&&await n(T),s&&(T=await s(T))),r?.({data:T,event:U,id:h,retry:m}),D.length&&(yield T)}}}finally{j.removeEventListener("abort",O),$.releaseLock()}break}catch(P){if(t?.(P),c!==void 0&&y>=c)break;const R=Math.min(m*2**(y-1),i??3e4);await b(R)}}}()}},te=e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},re=e=>{switch(e){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},se=e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},V=({allowReserved:e,explode:t,name:r,style:s,value:n})=>{if(!t){const i=(e?n:n.map(o=>encodeURIComponent(o))).join(re(s));switch(s){case"label":return`.${i}`;case"matrix":return`;${r}=${i}`;case"simple":return i;default:return`${r}=${i}`}}const l=te(s),c=n.map(i=>s==="label"||s==="simple"?e?i:encodeURIComponent(i):E({allowReserved:e,name:r,value:i})).join(l);return s==="label"||s==="matrix"?l+c:c},E=({allowReserved:e,name:t,value:r})=>{if(r==null)return"";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${t}=${e?r:encodeURIComponent(r)}`},M=({allowReserved:e,explode:t,name:r,style:s,value:n,valueOnly:l})=>{if(n instanceof Date)return l?n.toISOString():`${r}=${n.toISOString()}`;if(s!=="deepObject"&&!t){let o=[];Object.entries(n).forEach(([a,h])=>{o=[...o,a,e?h:encodeURIComponent(h)]});const d=o.join(",");switch(s){case"form":return`${r}=${d}`;case"label":return`.${d}`;case"matrix":return`;${r}=${d}`;default:return d}}const c=se(s),i=Object.entries(n).map(([o,d])=>E({allowReserved:e,name:s==="deepObject"?`${r}[${o}]`:o,value:d})).join(c);return s==="label"||s==="matrix"?c+i:i},ne=/\{[^{}]+\}/g,ie=({path:e,url:t})=>{let r=t;const s=t.match(ne);if(s)for(const n of s){let l=!1,c=n.substring(1,n.length-1),i="simple";c.endsWith("*")&&(l=!0,c=c.substring(0,c.length-1)),c.startsWith(".")?(c=c.substring(1),i="label"):c.startsWith(";")&&(c=c.substring(1),i="matrix");const o=e[c];if(o==null)continue;if(Array.isArray(o)){r=r.replace(n,V({explode:l,name:c,style:i,value:o}));continue}if(typeof o=="object"){r=r.replace(n,M({explode:l,name:c,style:i,value:o,valueOnly:!0}));continue}if(i==="matrix"){r=r.replace(n,`;${E({name:c,value:o})}`);continue}const d=encodeURIComponent(i==="label"?`.${o}`:o);r=r.replace(n,d)}return r},ae=({baseUrl:e,path:t,query:r,querySerializer:s,url:n})=>{const l=n.startsWith("/")?n:`/${n}`;let c=(e??"")+l;t&&(c=ie({path:t,url:c}));let i=r?s(r):"";return i.startsWith("?")&&(i=i.substring(1)),i&&(c+=`?${i}`),c};function ce(e){const t=e.body!==void 0;if(t&&e.bodySerializer)return"serializedBody"in e?e.serializedBody!==void 0&&e.serializedBody!==""?e.serializedBody:null:e.body!==""?e.body:null;if(t)return e.body}const oe=async(e,t)=>{const r=typeof t=="function"?await t(e):t;if(r)return e.scheme==="bearer"?`Bearer ${r}`:e.scheme==="basic"?`Basic ${btoa(r)}`:r},le=({parameters:e={},...t}={})=>s=>{const n=[];if(s&&typeof s=="object")for(const l in s){const c=s[l];if(c==null)continue;const i=e[l]||t;if(Array.isArray(c)){const o=V({allowReserved:i.allowReserved,explode:!0,name:l,style:"form",value:c,...i.array});o&&n.push(o)}else if(typeof c=="object"){const o=M({allowReserved:i.allowReserved,explode:!0,name:l,style:"deepObject",value:c,...i.object});o&&n.push(o)}else{const o=E({allowReserved:i.allowReserved,name:l,value:c});o&&n.push(o)}}return n.join("&")},pe=(e,t)=>t?t in e.headers||e.query?.[t]?!0:"Cookie"in e.headers&&e.headers.Cookie&&typeof e.headers.Cookie=="string"?e.headers.Cookie.includes(`${t}=`):!1:!1,ue=async({security:e,...t})=>{for(const r of e){if(pe(t,r.name))continue;const s=await oe(r,t.auth);if(!s)continue;const n=r.name??"Authorization";switch(r.in){case"query":t.query||(t.query={}),t.query[n]=s;break;case"cookie":{const l=`${n}=${s}`;"Cookie"in t.headers&&t.headers.Cookie?t.headers.Cookie=`${t.headers.Cookie}; ${l}`:t.headers.Cookie=l;break}case"header":default:t.headers[n]=s;break}}},L=e=>{const t=e.axios?.defaults?.baseURL,r=e.baseURL&&typeof e.baseURL=="string"?e.baseURL:t;return ae({baseUrl:r,path:e.path,query:e.paramsSerializer?void 0:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:le(e.querySerializer),url:e.url})},H=(e,t)=>{const r={...e,...t};return r.headers=z(e.headers,t.headers),r},de=["common","delete","get","head","patch","post","put"],z=(...e)=>{const t={};for(const r of e){if(!r||typeof r!="object")continue;const s=Object.entries(r);for(const[n,l]of s)if(de.includes(n)&&typeof l=="object")t[n]={...t[n],...l};else if(l===null)delete t[n];else if(Array.isArray(l))for(const c of l)t[n]=[...t[n]??[],c];else l!==void 0&&(t[n]=typeof l=="object"?JSON.stringify(l):l)}return t},F=(e={})=>({...e}),J=(e={})=>{let t=H(F(),e),r;if(t.axios&&!("Axios"in t.axios))r=t.axios;else{const{auth:d,...a}=t;r=W.create(a)}const s=()=>({...t}),n=d=>(t=H(t,d),r.defaults={...r.defaults,...t,headers:z(r.defaults.headers,t.headers)},s()),l=async d=>{const a={...t,...d,axios:d.axios??t.axios??r,headers:z(t.headers,d.headers)};a.security&&await ue({...a,security:a.security}),a.requestValidator&&await a.requestValidator(a),a.body!==void 0&&a.bodySerializer&&(a.body=a.bodySerializer(a.body));const h=L(a);return{opts:a,url:h}},c=async d=>{const{opts:a,url:h}=await l(d);try{const b=a.axios,{auth:w,...k}=a,m=await b({...k,baseURL:"",data:ce(a),headers:a.headers,params:a.paramsSerializer?a.query:void 0,url:h});let{data:y}=m;return a.responseType==="json"&&(a.responseValidator&&await a.responseValidator(y),a.responseTransformer&&(y=await a.responseTransformer(y))),{...m,data:y??{}}}catch(b){const w=b;if(a.throwOnError)throw w;return w.error=w.response?.data??{},w}},i=d=>a=>c({...a,method:d}),o=d=>async a=>{const{opts:h,url:b}=await l(a);return ee({...h,body:h.body,headers:h.headers,method:d,signal:h.signal,url:b})};return{buildUrl:L,connect:i("CONNECT"),delete:i("DELETE"),get:i("GET"),getConfig:s,head:i("HEAD"),instance:r,options:i("OPTIONS"),patch:i("PATCH"),post:i("POST"),put:i("PUT"),request:c,setConfig:n,sse:{connect:o("CONNECT"),delete:o("DELETE"),get:o("GET"),head:o("HEAD"),options:o("OPTIONS"),patch:o("PATCH"),post:o("POST"),put:o("PUT"),trace:o("TRACE")},trace:i("TRACE")}},u=J(F()),g=e=>(e=new Date(e),e),G=e=>(e.last_active_at&&(e.last_active_at=g(e.last_active_at)),e.created_at=g(e.created_at),e.updated_at=g(e.updated_at),e),he=async e=>(e.list=e.list.map(t=>G(t)),e),fe=async e=>(e=G(e),e),ye=e=>(e.subscribed_at=g(e.subscribed_at),e),me=async e=>(e.list=e.list.map(t=>ye(t)),e),K=e=>(e.created_at=g(e.created_at),e.updated_at=g(e.updated_at),e),x=e=>(e=K(e),e),be=e=>(e=x(e),e),Te=async e=>(e.list=e.list.map(t=>be(t)),e),ge=async e=>(e=x(e),e),we=async e=>(e=x(e),e),ve=async e=>(e=x(e),e),v=e=>(e=K(e),e),_e=async e=>(e.list=e.list.map(t=>v(t)),e),Se=async e=>(e=v(e),e),Ae=async e=>(e=v(e),e),Ce=async e=>(e=v(e),e),je=async e=>(e=v(e),e),Pe=e=>(e.hour_timestamp=g(e.hour_timestamp),e),Re=async e=>(e.list=e.list.map(t=>Pe(t)),e),De=async e=>(e.list=e.list.map(t=>v(t)),e),Ee=e=>(e?.client??u).get({responseTransformer:he,responseType:"json",url:"/api/developers",...e}),xe=e=>(e?.client??u).post({responseTransformer:fe,responseType:"json",url:"/api/developers",...e,headers:{"Content-Type":"application/json",...e?.headers}}),$e=e=>(e.client??u).delete({url:"/api/developers/{developer_id}",...e}),ze=e=>(e?.client??u).get({responseType:"json",url:"/api/api_products",...e}),ke=e=>(e.client??u).get({responseType:"json",url:"/api/api_products/{api_product_id}",...e}),Ie=e=>(e.client??u).post({url:"/api/api_products/{api_product_id}/subscriptions",...e,headers:{"Content-Type":"application/json",...e.headers}}),Oe=e=>(e?.client??u).get({responseTransformer:me,responseType:"json",url:"/api/subscriptions",...e}),qe=e=>(e?.client??u).post({url:"/api/subscriptions",...e,headers:{"Content-Type":"application/json",...e?.headers}}),Ue=e=>(e.client??u).delete({url:"/api/subscriptions/{subscription_id}",...e}),Ne=e=>(e?.client??u).get({responseTransformer:Te,responseType:"json",url:"/api/applications",...e}),Be=e=>(e?.client??u).post({responseTransformer:ge,responseType:"json",url:"/api/applications",...e,headers:{"Content-Type":"application/json",...e?.headers}}),Le=e=>(e.client??u).delete({url:"/api/applications/{application_id}",...e}),He=e=>(e.client??u).get({responseTransformer:we,responseType:"json",url:"/api/applications/{application_id}",...e}),We=e=>(e.client??u).put({responseTransformer:ve,responseType:"json",url:"/api/applications/{application_id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ve=e=>(e.client??u).get({responseTransformer:_e,responseType:"json",url:"/api/applications/{application_id}/credentials",...e}),Me=e=>(e.client??u).post({responseTransformer:Se,responseType:"json",url:"/api/applications/{application_id}/credentials",...e,headers:{"Content-Type":"application/json",...e.headers}}),Fe=e=>(e.client??u).delete({url:"/api/applications/{application_id}/credentials/{credential_id}",...e}),Je=e=>(e.client??u).get({responseTransformer:Ae,responseType:"json",url:"/api/applications/{application_id}/credentials/{credential_id}",...e}),Ge=e=>(e.client??u).put({responseTransformer:Ce,responseType:"json",url:"/api/applications/{application_id}/credentials/{credential_id}",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ke=e=>(e.client??u).put({responseTransformer:je,responseType:"json",url:"/api/applications/{application_id}/credentials/{credential_id}/regenerate",...e,headers:{"Content-Type":"application/json",...e.headers}}),Xe=e=>(e.client??u).get({responseTransformer:Re,responseType:"json",url:"/api/applications/api_calls",...e}),Qe=e=>(e?.client??u).get({responseTransformer:De,responseType:"json",url:"/api/credentials",...e}),Ye=e=>(e.client??u).get({responseType:"json",url:"/api/labels/{resource_type}",...e}),Ze=e=>(e?.client??u).get({responseType:"json",url:"/api/system_settings/public_access",...e}),et=e=>(e?.client??u).get({responseType:"json",url:"/api/dcr_providers",...e}),A=(e,t)=>({...t,"X-Portal-Developer-ID":e});class C extends Error{constructor(t,r,s,n,l){super(t),this.message=t,this.status=r,this.method=s,this.url=n,this.stack=void 0,this.#e=l}#e;static fromAxiosError=t=>{const r=t.error&&t.error.error_msg;return new C(`Request failed: ${r||(t.status?`with status code ${t.status}`:t.message)}`,t.status??0,t.config?.method?.toUpperCase()??"",t.config?.url??"",t)};static isAPIError=t=>t instanceof C;rawError(){return this.#e}}const p=e=>{if(e.error||e.status&&e.status>=400)throw C.fromAxiosError(e);return e.data};class tt{constructor(t){this.client=t}async create(t,r){return p(await Me({client:this.client,path:{application_id:t},body:r}))}async list(t,r){return p(await Ve({client:this.client,path:{application_id:t},query:r}))}async get(t,r){return p(await Je({client:this.client,path:{application_id:t,credential_id:r}}))}async update(t,r,s){return p(await Ge({client:this.client,path:{application_id:t,credential_id:r},body:s}))}async delete(t,r){return p(await Fe({client:this.client,path:{application_id:t,credential_id:r}}))}async regenerate(t,r,s){return p(await Ke({client:this.client,path:{application_id:t,credential_id:r},body:s}))}}class rt{constructor(t){this.client=t}async list(t){return p(await Qe({client:this.client,query:t}))}}class st{constructor(t){this.client=t,this.credential=new tt(this.client)}credential;async create(t,r){return p(await Be({client:this.client,headers:A(t),body:r}))}async list(t,r){return p(await Ne({client:this.client,headers:A(t),query:r}))}async get(t,r){return p(await He({client:this.client,headers:A(t),path:{application_id:r}}))}async update(t,r,s){return p(await We({client:this.client,headers:A(t),path:{application_id:r},body:s}))}async delete(t,r){p(await Le({client:this.client,headers:A(t),path:{application_id:r}}))}async apiCall(t){return p(await Xe({client:this.client,query:t}))}}class nt{constructor(t){this.client=t}async list(t){return p(await et({client:this.client,query:t}))}}class it{constructor(t){this.client=t}async getPublicAccess(){return p(await Ze({client:this.client})).portal_public_access}}class at{constructor(t){this.client=t}async listLabels(t){return p(await Ye({client:this.client,path:{resource_type:t}}))}}class ct{constructor(t){this.client=t}async create(t){return p(await xe({client:this.client,body:t}))}async list(t){return p(await Ee({client:this.client,query:t}))}async delete(t){p(await $e({client:this.client,path:{developer_id:t}}))}}class ot{constructor(t){this.client=t}async list(t){return p(await ze({client:this.client,query:t}))}async get(t){return p(await ke({client:this.client,path:{api_product_id:t}}))}async subscribe(t){p(await Ie({client:this.client,path:{api_product_id:t}}))}}class lt{constructor(t){this.client=t}async list(t){return p(await Oe({client:this.client,query:t}))}async bulkSubscribe(t){p(await qe({client:this.client,data:t}))}async unsubscribe(t){p(await Ue({client:this.client,path:{subscription_id:t}}))}}class pt{apiProduct;application;credential;dcrProvider;developer;misc;subscription;systemSetting;constructor(t,r){const s=J({axios:W.create({baseURL:t,headers:{"X-Portal-TOKEN":`${r}`}})});this.apiProduct=new ot(s),this.application=new st(s),this.credential=new rt(s),this.dcrProvider=new nt(s),this.developer=new ct(s),this.misc=new at(s),this.subscription=new lt(s),this.systemSetting=new it(s)}}exports.API7Portal=pt;exports.APIError=C;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("axios"),e=require("./subscription-ukRySaBq.cjs");class a{apiProduct;application;credential;dcrProvider;developer;misc;subscription;systemSetting;proxy;constructor(i){const s=n.create({baseURL:i.endpoint,headers:{Authorization:`Bearer ${i.token}`}});s.interceptors.request.use(async t=>{t.headers=t.headers??{};try{t.headers["X-Portal-Developer-ID"]=await i.getDeveloperId()}catch(o){return Promise.reject(o)}return t});const r=e.createClient({axios:s});this.apiProduct=new e.APIProductAPI(r),this.application=new e.ApplicationAPI(r),this.credential=new e.CredentialAPI(r),this.dcrProvider=new e.DCRProviderAPI(r),this.developer=new e.DeveloperAPI(r),this.misc=new e.MiscellaneousAPI(r),this.subscription=new e.SubscriptionAPI(r),this.systemSetting=new e.SystemSettingAPI(r),this.proxy=t=>s.request(t)}}exports.APIError=e.APIError;exports.API7Portal=a;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
1
2
|
import { ApplicationAPI } from './application.js';
|
|
2
3
|
import { CredentialAPI } from './credential.js';
|
|
3
4
|
import { DCRProviderAPI, MiscellaneousAPI, SystemSettingAPI } from './miscellaneous.js';
|
|
@@ -5,6 +6,11 @@ import { DeveloperAPI } from './developer.js';
|
|
|
5
6
|
import { APIProductAPI } from './api_product.js';
|
|
6
7
|
import { SubscriptionAPI } from './subscription.js';
|
|
7
8
|
export { APIError } from './utils.js';
|
|
9
|
+
export type Options = {
|
|
10
|
+
endpoint: string;
|
|
11
|
+
token: string;
|
|
12
|
+
getDeveloperId: () => Promise<string>;
|
|
13
|
+
};
|
|
8
14
|
export declare class API7Portal {
|
|
9
15
|
readonly apiProduct: APIProductAPI;
|
|
10
16
|
readonly application: ApplicationAPI;
|
|
@@ -14,6 +20,7 @@ export declare class API7Portal {
|
|
|
14
20
|
readonly misc: MiscellaneousAPI;
|
|
15
21
|
readonly subscription: SubscriptionAPI;
|
|
16
22
|
readonly systemSetting: SystemSettingAPI;
|
|
17
|
-
|
|
23
|
+
readonly proxy: (req: AxiosRequestConfig) => Promise<AxiosResponse>;
|
|
24
|
+
constructor(opts: Options);
|
|
18
25
|
}
|
|
19
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC,CAAC;AAEF,qBAAa,UAAU;IACrB,SAAgB,UAAU,EAAE,aAAa,CAAC;IAC1C,SAAgB,WAAW,EAAE,cAAc,CAAC;IAC5C,SAAgB,UAAU,EAAE,aAAa,CAAC;IAC1C,SAAgB,WAAW,EAAE,cAAc,CAAC;IAC5C,SAAgB,SAAS,EAAE,YAAY,CAAC;IACxC,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IACvC,SAAgB,YAAY,EAAE,eAAe,CAAC;IAC9C,SAAgB,aAAa,EAAE,gBAAgB,CAAC;IAChD,SAAgB,KAAK,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;gBAE/D,IAAI,EAAE,OAAO;CA2B1B"}
|