@approvio/ts-sdk 0.0.14 → 0.0.15

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 CHANGED
@@ -23,9 +23,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  //#endregion
24
24
  let jose = require("jose");
25
25
  jose = __toESM(jose);
26
+ let _approvio_api = require("@approvio/api");
26
27
  let axios = require("axios");
27
28
  axios = __toESM(axios);
28
- let _approvio_api = require("@approvio/api");
29
29
  let node_crypto = require("node:crypto");
30
30
  node_crypto = __toESM(node_crypto);
31
31
  let fp_ts_TaskEither = require("fp-ts/TaskEither");
@@ -57,6 +57,21 @@ function validateURL(url) {
57
57
  function removeTrailingSlash(url) {
58
58
  return url.endsWith("/") ? url.slice(0, -1) : url;
59
59
  }
60
+ const USER_AGENT = `Approvio-TS-SDK/0.0.15`;
61
+ //#endregion
62
+ //#region src/client/http.ts
63
+ /**
64
+ * Creates a pre-configured axios instance with the common headers.
65
+ */
66
+ function createAxiosInstance(config) {
67
+ return axios.default.create({
68
+ ...config,
69
+ headers: {
70
+ "User-Agent": USER_AGENT,
71
+ ...config?.headers
72
+ }
73
+ });
74
+ }
60
75
  //#endregion
61
76
  //#region src/auth/user.authenticator.ts
62
77
  /**
@@ -65,15 +80,17 @@ function removeTrailingSlash(url) {
65
80
  */
66
81
  var CliUserAuthenticator = class {
67
82
  endpoint;
83
+ axios;
68
84
  constructor(endpoint, accessToken, refreshToken, onTokenRefreshed) {
69
85
  this.accessToken = accessToken;
70
86
  this.refreshToken = refreshToken;
71
87
  this.onTokenRefreshed = onTokenRefreshed;
72
88
  validateURL(endpoint);
73
89
  this.endpoint = removeTrailingSlash(endpoint);
90
+ this.axios = createAxiosInstance({ baseURL: this.endpoint });
74
91
  }
75
- customizeAxios(axios$6) {
76
- axios$6.interceptors.request.use(async (axiosConfig) => {
92
+ customizeAxios(axios) {
93
+ axios.interceptors.request.use(async (axiosConfig) => {
77
94
  const accessToken = await this.getAccessToken();
78
95
  axiosConfig.headers.set("Authorization", `Bearer ${accessToken}`);
79
96
  return axiosConfig;
@@ -98,7 +115,7 @@ var CliUserAuthenticator = class {
98
115
  }
99
116
  async renewToken() {
100
117
  const request = { refreshToken: this.refreshToken };
101
- return (await axios.default.post(`${this.endpoint}/auth/cli/refresh`, request)).data;
118
+ return (await this.axios.post("/auth/cli/refresh", request)).data;
102
119
  }
103
120
  };
104
121
  //#endregion
@@ -134,9 +151,11 @@ var WebAuthenticator = class {
134
151
  */
135
152
  var AuthHelper = class {
136
153
  endpoint;
154
+ axios;
137
155
  constructor(endpoint) {
138
156
  validateURL(endpoint);
139
157
  this.endpoint = removeTrailingSlash(endpoint);
158
+ this.axios = createAxiosInstance({ baseURL: this.endpoint });
140
159
  }
141
160
  /**
142
161
  * Generates the login URL to initiate the OIDC authentication flow for users.
@@ -150,7 +169,7 @@ var AuthHelper = class {
150
169
  */
151
170
  initiateCliLogin(redirectUri) {
152
171
  return fp_ts_TaskEither.tryCatch(async () => {
153
- return (await axios.default.post(`${this.endpoint}/auth/cli/initiate`, { redirectUri })).data.authorizationUrl;
172
+ return (await this.axios.post("/auth/cli/initiate", { redirectUri })).data.authorizationUrl;
154
173
  }, (error) => this.handleError(error));
155
174
  }
156
175
  /**
@@ -163,7 +182,7 @@ var AuthHelper = class {
163
182
  state
164
183
  };
165
184
  return fp_ts_TaskEither.tryCatch(async () => {
166
- return (await axios.default.post(`${this.endpoint}/auth/cli/token`, request)).data;
185
+ return (await this.axios.post("/auth/cli/token", request)).data;
167
186
  }, (error) => this.handleError(error));
168
187
  }
169
188
  /**
@@ -176,7 +195,7 @@ var AuthHelper = class {
176
195
  authenticateAgent(agentName, privateKeyPem) {
177
196
  return fp_ts_TaskEither.tryCatch(async () => {
178
197
  const challengeRequest = { agentName };
179
- const { challenge: b64EncodedChallenge } = (await axios.default.post(`${this.endpoint}/auth/agents/challenge`, challengeRequest)).data;
198
+ const { challenge: b64EncodedChallenge } = (await this.axios.post("/auth/agents/challenge", challengeRequest)).data;
180
199
  const encryptedBuffer = Buffer.from(b64EncodedChallenge, "base64");
181
200
  const decryptedContent = node_crypto.privateDecrypt({
182
201
  key: privateKeyPem,
@@ -198,7 +217,7 @@ var AuthHelper = class {
198
217
  typ: "JWT"
199
218
  }).setIssuedAt().setExpirationTime("5m").sign(privateKey)
200
219
  };
201
- return (await axios.default.post(`${this.endpoint}/auth/agents/token`, tokenRequest)).data;
220
+ return (await this.axios.post("/auth/agents/token", tokenRequest)).data;
202
221
  }, (error) => this.handleError(error));
203
222
  }
204
223
  handleError(error) {
@@ -222,6 +241,7 @@ var AuthHelper = class {
222
241
  */
223
242
  var AgentAuthenticator = class {
224
243
  endpoint;
244
+ axios;
225
245
  constructor(endpoint, privateKey, accessToken, refreshToken, onTokenRefreshed) {
226
246
  this.privateKey = privateKey;
227
247
  this.accessToken = accessToken;
@@ -229,9 +249,10 @@ var AgentAuthenticator = class {
229
249
  this.onTokenRefreshed = onTokenRefreshed;
230
250
  validateURL(endpoint);
231
251
  this.endpoint = removeTrailingSlash(endpoint);
252
+ this.axios = createAxiosInstance({ baseURL: this.endpoint });
232
253
  }
233
- customizeAxios(axios$5) {
234
- axios$5.interceptors.request.use(async (axiosConfig) => {
254
+ customizeAxios(axios) {
255
+ axios.interceptors.request.use(async (axiosConfig) => {
235
256
  const accessToken = await this.getAccessToken();
236
257
  axiosConfig.headers.set("Authorization", `Bearer ${accessToken}`);
237
258
  return axiosConfig;
@@ -253,7 +274,7 @@ var AgentAuthenticator = class {
253
274
  async renewToken() {
254
275
  const request = { refreshToken: this.refreshToken };
255
276
  const dpopProof = await this.generateDpopProof("POST", `${this.endpoint}/auth/agents/refresh`);
256
- return (await axios.default.post(`${this.endpoint}/auth/agents/refresh`, request, { headers: { DPoP: dpopProof } })).data;
277
+ return (await this.axios.post("/auth/agents/refresh", request, { headers: { DPoP: dpopProof } })).data;
257
278
  }
258
279
  async generateDpopProof(method, url) {
259
280
  const privateKey = await jose.importPKCS8(this.privateKey, "RS256");
@@ -296,7 +317,7 @@ var BaseApprovioClient = class {
296
317
  this.config = config;
297
318
  this.authenticator = authenticator;
298
319
  validateURL(config.endpoint);
299
- this.axios = axios.default.create({
320
+ this.axios = createAxiosInstance({
300
321
  baseURL: removeTrailingSlash(config.endpoint),
301
322
  paramsSerializer: { indexes: null }
302
323
  });
package/dist/index.d.cts CHANGED
@@ -19,6 +19,7 @@ declare class CliUserAuthenticator implements TokenBaseAuthenticator {
19
19
  private refreshToken;
20
20
  private readonly onTokenRefreshed?;
21
21
  private readonly endpoint;
22
+ private readonly axios;
22
23
  constructor(endpoint: string, accessToken: string, refreshToken: string, onTokenRefreshed?: ((accessToken: string, refreshToken: string) => void) | undefined);
23
24
  customizeAxios(axios: AxiosInstance): void;
24
25
  getAccessToken(): Promise<string>;
@@ -65,6 +66,7 @@ declare abstract class BaseApprovioClient {
65
66
  //#region src/auth/auth.helpers.d.ts
66
67
  declare class AuthHelper {
67
68
  private readonly endpoint;
69
+ private readonly axios;
68
70
  constructor(endpoint: string);
69
71
  getUserLoginUrl(): string;
70
72
  initiateCliLogin(redirectUri: string): TE.TaskEither<ApprovioError, string>;
@@ -80,6 +82,7 @@ declare class AgentAuthenticator implements TokenBaseAuthenticator {
80
82
  private refreshToken;
81
83
  private readonly onTokenRefreshed?;
82
84
  private readonly endpoint;
85
+ private readonly axios;
83
86
  constructor(endpoint: string, privateKey: string, accessToken: string, refreshToken: string, onTokenRefreshed?: ((accessToken: string, refreshToken: string) => void) | undefined);
84
87
  customizeAxios(axios: AxiosInstance): void;
85
88
  getAccessToken(): Promise<string>;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { AxiosInstance } from "axios";
2
1
  import { APIError, AddGroupEntitiesRequest, AgentGet200Response, AgentRegistrationRequest, AgentRegistrationResponse, AgentTokenResponse, CanVoteResponse, GetEntityInfo200Response, GetWorkflowParams, GetWorkflowVotes200Response, Group, GroupCreate, ListGroupEntities200Response, ListGroups200Response, ListGroupsParams, ListOrganizationAdminsForOrg200Response, ListRoleTemplates200Response, ListSpaces200Response, ListSpacesParams, ListUsers200Response, ListUsersParams, ListWorkflowTemplates200Response, ListWorkflowTemplatesParams, ListWorkflowVotesParams, ListWorkflows200Response, ListWorkflowsParams, OrganizationAdminCreate, OrganizationAdminRemove, RemoveGroupEntitiesRequest, RoleAssignmentRequest, RoleRemovalRequest, Space, SpaceCreate, TokenResponse, User, UserCreate, Workflow, WorkflowCreate, WorkflowTemplate, WorkflowTemplateCreate, WorkflowTemplateDeprecate, WorkflowTemplateUpdate, WorkflowVoteRequest } from "@approvio/api";
2
+ import { AxiosInstance } from "axios";
3
3
  import * as TE from "fp-ts/TaskEither";
4
4
 
5
5
  //#region src/interfaces.d.ts
@@ -19,6 +19,7 @@ declare class CliUserAuthenticator implements TokenBaseAuthenticator {
19
19
  private refreshToken;
20
20
  private readonly onTokenRefreshed?;
21
21
  private readonly endpoint;
22
+ private readonly axios;
22
23
  constructor(endpoint: string, accessToken: string, refreshToken: string, onTokenRefreshed?: ((accessToken: string, refreshToken: string) => void) | undefined);
23
24
  customizeAxios(axios: AxiosInstance): void;
24
25
  getAccessToken(): Promise<string>;
@@ -65,6 +66,7 @@ declare abstract class BaseApprovioClient {
65
66
  //#region src/auth/auth.helpers.d.ts
66
67
  declare class AuthHelper {
67
68
  private readonly endpoint;
69
+ private readonly axios;
68
70
  constructor(endpoint: string);
69
71
  getUserLoginUrl(): string;
70
72
  initiateCliLogin(redirectUri: string): TE.TaskEither<ApprovioError, string>;
@@ -80,6 +82,7 @@ declare class AgentAuthenticator implements TokenBaseAuthenticator {
80
82
  private refreshToken;
81
83
  private readonly onTokenRefreshed?;
82
84
  private readonly endpoint;
85
+ private readonly axios;
83
86
  constructor(endpoint: string, privateKey: string, accessToken: string, refreshToken: string, onTokenRefreshed?: ((accessToken: string, refreshToken: string) => void) | undefined);
84
87
  customizeAxios(axios: AxiosInstance): void;
85
88
  getAccessToken(): Promise<string>;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as jose from "jose";
2
2
  import { decodeJwt } from "jose";
3
- import axios from "axios";
4
3
  import { isAPIError } from "@approvio/api";
4
+ import axios from "axios";
5
5
  import * as crypto$1 from "node:crypto";
6
6
  import * as TE from "fp-ts/TaskEither";
7
7
  import { pipe } from "fp-ts/function";
@@ -31,6 +31,21 @@ function validateURL(url) {
31
31
  function removeTrailingSlash(url) {
32
32
  return url.endsWith("/") ? url.slice(0, -1) : url;
33
33
  }
34
+ const USER_AGENT = `Approvio-TS-SDK/0.0.15`;
35
+ //#endregion
36
+ //#region src/client/http.ts
37
+ /**
38
+ * Creates a pre-configured axios instance with the common headers.
39
+ */
40
+ function createAxiosInstance(config) {
41
+ return axios.create({
42
+ ...config,
43
+ headers: {
44
+ "User-Agent": USER_AGENT,
45
+ ...config?.headers
46
+ }
47
+ });
48
+ }
34
49
  //#endregion
35
50
  //#region src/auth/user.authenticator.ts
36
51
  /**
@@ -39,12 +54,14 @@ function removeTrailingSlash(url) {
39
54
  */
40
55
  var CliUserAuthenticator = class {
41
56
  endpoint;
57
+ axios;
42
58
  constructor(endpoint, accessToken, refreshToken, onTokenRefreshed) {
43
59
  this.accessToken = accessToken;
44
60
  this.refreshToken = refreshToken;
45
61
  this.onTokenRefreshed = onTokenRefreshed;
46
62
  validateURL(endpoint);
47
63
  this.endpoint = removeTrailingSlash(endpoint);
64
+ this.axios = createAxiosInstance({ baseURL: this.endpoint });
48
65
  }
49
66
  customizeAxios(axios) {
50
67
  axios.interceptors.request.use(async (axiosConfig) => {
@@ -72,7 +89,7 @@ var CliUserAuthenticator = class {
72
89
  }
73
90
  async renewToken() {
74
91
  const request = { refreshToken: this.refreshToken };
75
- return (await axios.post(`${this.endpoint}/auth/cli/refresh`, request)).data;
92
+ return (await this.axios.post("/auth/cli/refresh", request)).data;
76
93
  }
77
94
  };
78
95
  //#endregion
@@ -108,9 +125,11 @@ var WebAuthenticator = class {
108
125
  */
109
126
  var AuthHelper = class {
110
127
  endpoint;
128
+ axios;
111
129
  constructor(endpoint) {
112
130
  validateURL(endpoint);
113
131
  this.endpoint = removeTrailingSlash(endpoint);
132
+ this.axios = createAxiosInstance({ baseURL: this.endpoint });
114
133
  }
115
134
  /**
116
135
  * Generates the login URL to initiate the OIDC authentication flow for users.
@@ -124,7 +143,7 @@ var AuthHelper = class {
124
143
  */
125
144
  initiateCliLogin(redirectUri) {
126
145
  return TE.tryCatch(async () => {
127
- return (await axios.post(`${this.endpoint}/auth/cli/initiate`, { redirectUri })).data.authorizationUrl;
146
+ return (await this.axios.post("/auth/cli/initiate", { redirectUri })).data.authorizationUrl;
128
147
  }, (error) => this.handleError(error));
129
148
  }
130
149
  /**
@@ -137,7 +156,7 @@ var AuthHelper = class {
137
156
  state
138
157
  };
139
158
  return TE.tryCatch(async () => {
140
- return (await axios.post(`${this.endpoint}/auth/cli/token`, request)).data;
159
+ return (await this.axios.post("/auth/cli/token", request)).data;
141
160
  }, (error) => this.handleError(error));
142
161
  }
143
162
  /**
@@ -150,7 +169,7 @@ var AuthHelper = class {
150
169
  authenticateAgent(agentName, privateKeyPem) {
151
170
  return TE.tryCatch(async () => {
152
171
  const challengeRequest = { agentName };
153
- const { challenge: b64EncodedChallenge } = (await axios.post(`${this.endpoint}/auth/agents/challenge`, challengeRequest)).data;
172
+ const { challenge: b64EncodedChallenge } = (await this.axios.post("/auth/agents/challenge", challengeRequest)).data;
154
173
  const encryptedBuffer = Buffer.from(b64EncodedChallenge, "base64");
155
174
  const decryptedContent = crypto$1.privateDecrypt({
156
175
  key: privateKeyPem,
@@ -172,7 +191,7 @@ var AuthHelper = class {
172
191
  typ: "JWT"
173
192
  }).setIssuedAt().setExpirationTime("5m").sign(privateKey)
174
193
  };
175
- return (await axios.post(`${this.endpoint}/auth/agents/token`, tokenRequest)).data;
194
+ return (await this.axios.post("/auth/agents/token", tokenRequest)).data;
176
195
  }, (error) => this.handleError(error));
177
196
  }
178
197
  handleError(error) {
@@ -196,6 +215,7 @@ var AuthHelper = class {
196
215
  */
197
216
  var AgentAuthenticator = class {
198
217
  endpoint;
218
+ axios;
199
219
  constructor(endpoint, privateKey, accessToken, refreshToken, onTokenRefreshed) {
200
220
  this.privateKey = privateKey;
201
221
  this.accessToken = accessToken;
@@ -203,6 +223,7 @@ var AgentAuthenticator = class {
203
223
  this.onTokenRefreshed = onTokenRefreshed;
204
224
  validateURL(endpoint);
205
225
  this.endpoint = removeTrailingSlash(endpoint);
226
+ this.axios = createAxiosInstance({ baseURL: this.endpoint });
206
227
  }
207
228
  customizeAxios(axios) {
208
229
  axios.interceptors.request.use(async (axiosConfig) => {
@@ -227,7 +248,7 @@ var AgentAuthenticator = class {
227
248
  async renewToken() {
228
249
  const request = { refreshToken: this.refreshToken };
229
250
  const dpopProof = await this.generateDpopProof("POST", `${this.endpoint}/auth/agents/refresh`);
230
- return (await axios.post(`${this.endpoint}/auth/agents/refresh`, request, { headers: { DPoP: dpopProof } })).data;
251
+ return (await this.axios.post("/auth/agents/refresh", request, { headers: { DPoP: dpopProof } })).data;
231
252
  }
232
253
  async generateDpopProof(method, url) {
233
254
  const privateKey = await jose.importPKCS8(this.privateKey, "RS256");
@@ -270,7 +291,7 @@ var BaseApprovioClient = class {
270
291
  this.config = config;
271
292
  this.authenticator = authenticator;
272
293
  validateURL(config.endpoint);
273
- this.axios = axios.create({
294
+ this.axios = createAxiosInstance({
274
295
  baseURL: removeTrailingSlash(config.endpoint),
275
296
  paramsSerializer: { indexes: null }
276
297
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@approvio/ts-sdk",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -30,9 +30,9 @@
30
30
  "prepublishOnly": "yarn format && yarn lint && yarn build"
31
31
  },
32
32
  "dependencies": {
33
- "@approvio/api": "0.0.45",
34
- "axios": "1.13.2",
35
- "jose": "6.1.3"
33
+ "@approvio/api": "0.0.46",
34
+ "axios": "1.16.1",
35
+ "jose": "6.2.3"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "fp-ts": "^2.0.0",