@approvio/ts-sdk 0.0.9 → 0.0.10
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/index.cjs +20 -18
- package/dist/index.d.cts +5 -2
- package/dist/index.d.mts +5 -2
- package/dist/index.mjs +5 -4
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -25,11 +25,12 @@ let jose = require("jose");
|
|
|
25
25
|
jose = __toESM(jose);
|
|
26
26
|
let axios = require("axios");
|
|
27
27
|
axios = __toESM(axios);
|
|
28
|
+
let _approvio_api = require("@approvio/api");
|
|
28
29
|
let node_crypto = require("node:crypto");
|
|
29
30
|
node_crypto = __toESM(node_crypto);
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
let
|
|
31
|
+
let fp_ts_TaskEither_js = require("fp-ts/TaskEither.js");
|
|
32
|
+
fp_ts_TaskEither_js = __toESM(fp_ts_TaskEither_js);
|
|
33
|
+
let fp_ts_function_js = require("fp-ts/function.js");
|
|
33
34
|
//#region src/auth/utils.ts
|
|
34
35
|
function isJwtTokenExpired(token) {
|
|
35
36
|
if (!token) return true;
|
|
@@ -42,7 +43,7 @@ function isJwtTokenExpired(token) {
|
|
|
42
43
|
* Checks if the given data matches the APIError structure.
|
|
43
44
|
*/
|
|
44
45
|
function isApprovioError(data) {
|
|
45
|
-
return
|
|
46
|
+
return (0, _approvio_api.isAPIError)(data);
|
|
46
47
|
}
|
|
47
48
|
function validateURL(url) {
|
|
48
49
|
try {
|
|
@@ -148,7 +149,7 @@ var AuthHelper = class {
|
|
|
148
149
|
* Prompts the backend to return an authorization URL for the IDP.
|
|
149
150
|
*/
|
|
150
151
|
initiateCliLogin(redirectUri) {
|
|
151
|
-
return
|
|
152
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
152
153
|
return (await axios.default.post(`${this.endpoint}/auth/cli/initiate`, { redirectUri })).data.authorizationUrl;
|
|
153
154
|
}, (error) => this.handleError(error));
|
|
154
155
|
}
|
|
@@ -161,7 +162,7 @@ var AuthHelper = class {
|
|
|
161
162
|
code,
|
|
162
163
|
state
|
|
163
164
|
};
|
|
164
|
-
return
|
|
165
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
165
166
|
return (await axios.default.post(`${this.endpoint}/auth/cli/token`, request)).data;
|
|
166
167
|
}, (error) => this.handleError(error));
|
|
167
168
|
}
|
|
@@ -173,7 +174,7 @@ var AuthHelper = class {
|
|
|
173
174
|
* 4. Exchange the assertion for an access token.
|
|
174
175
|
*/
|
|
175
176
|
authenticateAgent(agentName, privateKeyPem) {
|
|
176
|
-
return
|
|
177
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
177
178
|
const challengeRequest = { agentName };
|
|
178
179
|
const { challenge: b64EncodedChallenge } = (await axios.default.post(`${this.endpoint}/auth/agents/challenge`, challengeRequest)).data;
|
|
179
180
|
const encryptedBuffer = Buffer.from(b64EncodedChallenge, "base64");
|
|
@@ -315,7 +316,7 @@ var BaseApprovioClient = class {
|
|
|
315
316
|
* Performs a GET request.
|
|
316
317
|
*/
|
|
317
318
|
get(url, params) {
|
|
318
|
-
return
|
|
319
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
319
320
|
return (await this.axios.get(url, { params })).data;
|
|
320
321
|
}, (error) => this.handleError(error));
|
|
321
322
|
}
|
|
@@ -323,12 +324,12 @@ var BaseApprovioClient = class {
|
|
|
323
324
|
* Performs a POST request.
|
|
324
325
|
*/
|
|
325
326
|
post(url, data) {
|
|
326
|
-
return
|
|
327
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
327
328
|
return (await this.axios.post(url, data)).data;
|
|
328
329
|
}, (error) => this.handleError(error));
|
|
329
330
|
}
|
|
330
331
|
postWithLocation(url, data) {
|
|
331
|
-
return
|
|
332
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
332
333
|
const response = await this.axios.post(url, data);
|
|
333
334
|
const location = response.headers["location"];
|
|
334
335
|
if (!location) throw new LocationNotFoundError();
|
|
@@ -342,7 +343,7 @@ var BaseApprovioClient = class {
|
|
|
342
343
|
* Performs a PUT request.
|
|
343
344
|
*/
|
|
344
345
|
put(url, data) {
|
|
345
|
-
return
|
|
346
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
346
347
|
return (await this.axios.put(url, data)).data;
|
|
347
348
|
}, (error) => this.handleError(error));
|
|
348
349
|
}
|
|
@@ -350,7 +351,7 @@ var BaseApprovioClient = class {
|
|
|
350
351
|
* Performs a DELETE request.
|
|
351
352
|
*/
|
|
352
353
|
delete(url, data) {
|
|
353
|
-
return
|
|
354
|
+
return fp_ts_TaskEither_js.tryCatch(async () => {
|
|
354
355
|
const config = data !== void 0 ? { data } : void 0;
|
|
355
356
|
return (await this.axios.delete(url, config)).data;
|
|
356
357
|
}, (error) => this.handleError(error));
|
|
@@ -439,10 +440,10 @@ var ApprovioUserClient = class extends BaseApprovioClient {
|
|
|
439
440
|
* Creates a new user.
|
|
440
441
|
*/
|
|
441
442
|
createUser(data) {
|
|
442
|
-
return (0,
|
|
443
|
+
return (0, fp_ts_function_js.pipe)(this.postWithLocation("/users", data), fp_ts_TaskEither_js.map(({ location }) => location), fp_ts_TaskEither_js.chain((location) => {
|
|
443
444
|
const id = location.split("/").pop();
|
|
444
|
-
if (!id) return
|
|
445
|
-
return
|
|
445
|
+
if (!id) return fp_ts_TaskEither_js.left(/* @__PURE__ */ new Error("Invalid location"));
|
|
446
|
+
return fp_ts_TaskEither_js.right(id);
|
|
446
447
|
}));
|
|
447
448
|
}
|
|
448
449
|
/**
|
|
@@ -497,10 +498,10 @@ var ApprovioUserClient = class extends BaseApprovioClient {
|
|
|
497
498
|
* Create a new group.
|
|
498
499
|
*/
|
|
499
500
|
createGroup(data) {
|
|
500
|
-
return (0,
|
|
501
|
+
return (0, fp_ts_function_js.pipe)(this.postWithLocation("/groups", data), fp_ts_TaskEither_js.map(({ location }) => location), fp_ts_TaskEither_js.chain((location) => {
|
|
501
502
|
const id = location.split("/").pop();
|
|
502
|
-
if (!id) return
|
|
503
|
-
return
|
|
503
|
+
if (!id) return fp_ts_TaskEither_js.left(/* @__PURE__ */ new Error("Invalid location"));
|
|
504
|
+
return fp_ts_TaskEither_js.right(id);
|
|
504
505
|
}));
|
|
505
506
|
}
|
|
506
507
|
/**
|
|
@@ -601,3 +602,4 @@ exports.AuthHelper = AuthHelper;
|
|
|
601
602
|
exports.BaseApprovioClient = BaseApprovioClient;
|
|
602
603
|
exports.CliUserAuthenticator = CliUserAuthenticator;
|
|
603
604
|
exports.WebAuthenticator = WebAuthenticator;
|
|
605
|
+
exports.isApprovioError = isApprovioError;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { APIError, AddGroupEntitiesRequest, AgentGet200Response, AgentRegistrationRequest, AgentRegistrationResponse, AgentTokenResponse, CanVoteResponse, GetEntityInfo200Response, GetWorkflowParams, Group, GroupCreate, ListGroupEntities200Response, ListGroups200Response, ListOrganizationAdminsForOrg200Response, ListRoleTemplates200Response, ListSpaces200Response, ListUsers200Response, ListWorkflowTemplates200Response, ListWorkflows200Response, ListWorkflowsParams, OrganizationAdminCreate, OrganizationAdminRemove, RemoveGroupEntitiesRequest, RoleAssignmentRequest, RoleRemovalRequest, Space, SpaceCreate, TokenResponse, User, UserCreate, Workflow, WorkflowCreate, WorkflowTemplate, WorkflowTemplateCreate, WorkflowTemplateDeprecate, WorkflowTemplateUpdate, WorkflowVoteRequest } from "@approvio/api";
|
|
3
|
-
import * as TE from "fp-ts/TaskEither";
|
|
3
|
+
import * as TE from "fp-ts/TaskEither.js";
|
|
4
4
|
|
|
5
5
|
//#region src/interfaces.d.ts
|
|
6
6
|
interface Authenticator {
|
|
@@ -142,4 +142,7 @@ declare class ApprovioAgentClient extends BaseApprovioClient {
|
|
|
142
142
|
getAuthenticator(): Authenticator;
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
|
-
|
|
145
|
+
//#region src/client/utils.d.ts
|
|
146
|
+
declare function isApprovioError(data: unknown): data is APIError;
|
|
147
|
+
//#endregion
|
|
148
|
+
export { AgentAuthenticator, ApprovioAgentClient, ApprovioError, ApprovioServerConfig, ApprovioUserClient, AuthHelper, Authenticator, BaseApprovioClient, CliUserAuthenticator, TokenBaseAuthenticator, WebAuthenticator, isApprovioError };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import * as TE from "fp-ts/TaskEither";
|
|
3
2
|
import { APIError, AddGroupEntitiesRequest, AgentGet200Response, AgentRegistrationRequest, AgentRegistrationResponse, AgentTokenResponse, CanVoteResponse, GetEntityInfo200Response, GetWorkflowParams, Group, GroupCreate, ListGroupEntities200Response, ListGroups200Response, ListOrganizationAdminsForOrg200Response, ListRoleTemplates200Response, ListSpaces200Response, ListUsers200Response, ListWorkflowTemplates200Response, ListWorkflows200Response, ListWorkflowsParams, OrganizationAdminCreate, OrganizationAdminRemove, RemoveGroupEntitiesRequest, RoleAssignmentRequest, RoleRemovalRequest, Space, SpaceCreate, TokenResponse, User, UserCreate, Workflow, WorkflowCreate, WorkflowTemplate, WorkflowTemplateCreate, WorkflowTemplateDeprecate, WorkflowTemplateUpdate, WorkflowVoteRequest } from "@approvio/api";
|
|
3
|
+
import * as TE from "fp-ts/TaskEither.js";
|
|
4
4
|
|
|
5
5
|
//#region src/interfaces.d.ts
|
|
6
6
|
interface Authenticator {
|
|
@@ -142,4 +142,7 @@ declare class ApprovioAgentClient extends BaseApprovioClient {
|
|
|
142
142
|
getAuthenticator(): Authenticator;
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
|
-
|
|
145
|
+
//#region src/client/utils.d.ts
|
|
146
|
+
declare function isApprovioError(data: unknown): data is APIError;
|
|
147
|
+
//#endregion
|
|
148
|
+
export { AgentAuthenticator, ApprovioAgentClient, ApprovioError, ApprovioServerConfig, ApprovioUserClient, AuthHelper, Authenticator, BaseApprovioClient, CliUserAuthenticator, TokenBaseAuthenticator, WebAuthenticator, isApprovioError };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as jose from "jose";
|
|
2
2
|
import { decodeJwt } from "jose";
|
|
3
3
|
import axios from "axios";
|
|
4
|
+
import { isAPIError } from "@approvio/api";
|
|
4
5
|
import * as crypto$1 from "node:crypto";
|
|
5
|
-
import * as TE from "fp-ts/TaskEither";
|
|
6
|
-
import { pipe } from "fp-ts/function";
|
|
6
|
+
import * as TE from "fp-ts/TaskEither.js";
|
|
7
|
+
import { pipe } from "fp-ts/function.js";
|
|
7
8
|
//#region src/auth/utils.ts
|
|
8
9
|
function isJwtTokenExpired(token) {
|
|
9
10
|
if (!token) return true;
|
|
@@ -16,7 +17,7 @@ function isJwtTokenExpired(token) {
|
|
|
16
17
|
* Checks if the given data matches the APIError structure.
|
|
17
18
|
*/
|
|
18
19
|
function isApprovioError(data) {
|
|
19
|
-
return data
|
|
20
|
+
return isAPIError(data);
|
|
20
21
|
}
|
|
21
22
|
function validateURL(url) {
|
|
22
23
|
try {
|
|
@@ -568,4 +569,4 @@ var ApprovioAgentClient = class extends BaseApprovioClient {
|
|
|
568
569
|
}
|
|
569
570
|
};
|
|
570
571
|
//#endregion
|
|
571
|
-
export { AgentAuthenticator, ApprovioAgentClient, ApprovioUserClient, AuthHelper, BaseApprovioClient, CliUserAuthenticator, WebAuthenticator };
|
|
572
|
+
export { AgentAuthenticator, ApprovioAgentClient, ApprovioUserClient, AuthHelper, BaseApprovioClient, CliUserAuthenticator, WebAuthenticator, isApprovioError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@approvio/ts-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"prepublishOnly": "yarn format && yarn lint && yarn build"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@approvio/api": "0.0.
|
|
33
|
+
"@approvio/api": "0.0.32",
|
|
34
34
|
"axios": "1.13.2",
|
|
35
35
|
"jose": "6.1.3"
|
|
36
36
|
},
|