@bundleup/core 0.0.4 → 0.0.5

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/server.d.mts CHANGED
@@ -12,10 +12,15 @@ interface ConnectionOptions {
12
12
  metadata?: Record<string, unknown>;
13
13
  }
14
14
  declare class BundleUp {
15
- private config;
15
+ private client;
16
+ private debug;
16
17
  constructor(config?: BundleUpConfig);
17
18
  private log;
18
- createConnection(integrationId: string, options: ConnectionOptions): Promise<BundleUpResponse>;
19
+ createConnection(integrationId: string, options: ConnectionOptions): Promise<{
20
+ token: string;
21
+ expires_in: number;
22
+ externalId: string | undefined;
23
+ }>;
19
24
  }
20
25
 
21
26
  export { BundleUp, BundleUpConfig, BundleUpResponse, ConnectionOptions };
package/dist/server.d.ts CHANGED
@@ -12,10 +12,15 @@ interface ConnectionOptions {
12
12
  metadata?: Record<string, unknown>;
13
13
  }
14
14
  declare class BundleUp {
15
- private config;
15
+ private client;
16
+ private debug;
16
17
  constructor(config?: BundleUpConfig);
17
18
  private log;
18
- createConnection(integrationId: string, options: ConnectionOptions): Promise<BundleUpResponse>;
19
+ createConnection(integrationId: string, options: ConnectionOptions): Promise<{
20
+ token: string;
21
+ expires_in: number;
22
+ externalId: string | undefined;
23
+ }>;
19
24
  }
20
25
 
21
26
  export { BundleUp, BundleUpConfig, BundleUpResponse, ConnectionOptions };
package/dist/server.js CHANGED
@@ -35,18 +35,17 @@ function logger(isDebug) {
35
35
  }
36
36
 
37
37
  // src/server.ts
38
+ var import_sdk = require("@bundleup/sdk");
38
39
  var BundleUp = class {
39
40
  constructor(config = {}) {
40
41
  if (!config.apiKey) {
41
42
  throw new Error("API key is required for authentication");
42
43
  }
43
- this.config = {
44
- apiKey: config.apiKey,
45
- debug: config.debug ?? false
46
- };
44
+ this.debug = config.debug ?? false;
45
+ this.client = new import_sdk.BundleUp(config.apiKey);
47
46
  }
48
47
  log(message, ...args) {
49
- return logger(!!this.config.debug)(message, ...args);
48
+ return logger(!!this.debug)(message, ...args);
50
49
  }
51
50
  async createConnection(integrationId, options) {
52
51
  this.log(`Creating connection for integration: ${integrationId}`);
@@ -55,33 +54,21 @@ var BundleUp = class {
55
54
  throw new Error("Integration ID is required to create a connection");
56
55
  }
57
56
  try {
58
- const response = await fetch("https://auth.bundleup.io/authorize", {
59
- method: "POST",
60
- headers: {
61
- "Content-Type": "application/json",
62
- Authorization: `Bearer ${this.config.apiKey}`
63
- },
64
- body: JSON.stringify({
65
- integrationId,
66
- externalId: options.externalId || void 0,
67
- metadata: options.metadata || {}
68
- })
57
+ const data = await this.client.sessions.create({
58
+ integrationId,
59
+ externalId: options.externalId,
60
+ metadata: options.metadata
69
61
  });
70
- if (!response.ok) {
71
- this.log(
72
- `Authentication request failed: ${response.status} ${response.statusText}`
73
- );
74
- throw new Error(
75
- `Authentication request failed: ${response.status} ${response.statusText}`
76
- );
77
- }
78
- const data = await response.json();
79
62
  if (!data.token) {
80
63
  this.log("Invalid response: could not create token", data);
81
64
  throw new Error("Invalid response: could not create token");
82
65
  }
83
66
  this.log("Authentication token received successfully");
84
- return data;
67
+ return {
68
+ token: data.token,
69
+ expires_in: data.expires_in,
70
+ externalId: data.externalId
71
+ };
85
72
  } catch (error) {
86
73
  this.log("Error creating connection", error);
87
74
  throw error;
package/dist/server.mjs CHANGED
@@ -3,18 +3,17 @@ import {
3
3
  } from "./chunk-B6T6V2FR.mjs";
4
4
 
5
5
  // src/server.ts
6
+ import { BundleUp as BundleUpSDK } from "@bundleup/sdk";
6
7
  var BundleUp = class {
7
8
  constructor(config = {}) {
8
9
  if (!config.apiKey) {
9
10
  throw new Error("API key is required for authentication");
10
11
  }
11
- this.config = {
12
- apiKey: config.apiKey,
13
- debug: config.debug ?? false
14
- };
12
+ this.debug = config.debug ?? false;
13
+ this.client = new BundleUpSDK(config.apiKey);
15
14
  }
16
15
  log(message, ...args) {
17
- return logger(!!this.config.debug)(message, ...args);
16
+ return logger(!!this.debug)(message, ...args);
18
17
  }
19
18
  async createConnection(integrationId, options) {
20
19
  this.log(`Creating connection for integration: ${integrationId}`);
@@ -23,33 +22,21 @@ var BundleUp = class {
23
22
  throw new Error("Integration ID is required to create a connection");
24
23
  }
25
24
  try {
26
- const response = await fetch("https://auth.bundleup.io/authorize", {
27
- method: "POST",
28
- headers: {
29
- "Content-Type": "application/json",
30
- Authorization: `Bearer ${this.config.apiKey}`
31
- },
32
- body: JSON.stringify({
33
- integrationId,
34
- externalId: options.externalId || void 0,
35
- metadata: options.metadata || {}
36
- })
25
+ const data = await this.client.sessions.create({
26
+ integrationId,
27
+ externalId: options.externalId,
28
+ metadata: options.metadata
37
29
  });
38
- if (!response.ok) {
39
- this.log(
40
- `Authentication request failed: ${response.status} ${response.statusText}`
41
- );
42
- throw new Error(
43
- `Authentication request failed: ${response.status} ${response.statusText}`
44
- );
45
- }
46
- const data = await response.json();
47
30
  if (!data.token) {
48
31
  this.log("Invalid response: could not create token", data);
49
32
  throw new Error("Invalid response: could not create token");
50
33
  }
51
34
  this.log("Authentication token received successfully");
52
- return data;
35
+ return {
36
+ token: data.token,
37
+ expires_in: data.expires_in,
38
+ externalId: data.externalId
39
+ };
53
40
  } catch (error) {
54
41
  this.log("Error creating connection", error);
55
42
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bundleup/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Core package for BundleUp",
5
5
  "exports": {
6
6
  "./client": {
@@ -27,14 +27,17 @@
27
27
  "clean": "rm -rf dist"
28
28
  },
29
29
  "devDependencies": {
30
- "tsup": "^7.0.0",
31
- "typescript": "^5.0.0",
32
30
  "eslint": "^8.0.0",
33
- "jest": "^29.0.0"
31
+ "jest": "^29.0.0",
32
+ "tsup": "^7.0.0",
33
+ "typescript": "^5.0.0"
34
34
  },
35
35
  "files": [
36
36
  "dist"
37
37
  ],
38
38
  "author": "BundleUp",
39
- "license": "ISC"
40
- }
39
+ "license": "ISC",
40
+ "dependencies": {
41
+ "@bundleup/sdk": "^0.0.8"
42
+ }
43
+ }