@bundleup/core 0.0.3 → 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/client.js CHANGED
@@ -66,11 +66,11 @@ function authenticateWithPopup(token, options = {}) {
66
66
  );
67
67
  if (!popup) {
68
68
  log("Failed to open popup window. Please check popup blocker settings.");
69
- return reject(
70
- new Error(
71
- "Failed to open popup window. Please check popup blocker settings."
72
- )
69
+ const error = new Error(
70
+ "Failed to open popup window. Please check popup blocker settings."
73
71
  );
72
+ error.name = "POPUP_BLOCKED";
73
+ return reject(error);
74
74
  }
75
75
  const handleMessage = (event) => {
76
76
  if (event.origin !== "https://auth.bundleup.io") {
@@ -87,16 +87,20 @@ function authenticateWithPopup(token, options = {}) {
87
87
  }
88
88
  if (event.data.type === "bundleup:error") {
89
89
  log("Authentication failed", event.data.message);
90
- return reject(new Error(event.data.message || "Authentication failed"));
90
+ const error = new Error(event.data.message || "Authentication failed");
91
+ error.name = event.data.code || "AUTHENTICATION_ERROR";
92
+ return reject(error);
91
93
  }
92
94
  };
93
95
  const checkClosed = setInterval(() => {
94
96
  if (!popup.closed) {
95
97
  return;
96
98
  }
99
+ const error = new Error("Authentication popup was closed by user");
100
+ error.name = "POPUP_CLOSED";
97
101
  cleanup();
98
102
  log("Authentication popup closed by user");
99
- reject(new Error("Authentication popup was closed by user"));
103
+ reject(error);
100
104
  }, 1e3);
101
105
  const cleanup = () => {
102
106
  window.removeEventListener("message", handleMessage);
@@ -109,7 +113,9 @@ function authenticateWithPopup(token, options = {}) {
109
113
  }
110
114
  cleanup();
111
115
  log("Authentication popup was blocked or closed immediately");
112
- reject(new Error("Popup was blocked or closed immediately"));
116
+ const error = new Error("Popup was blocked or closed immediately");
117
+ error.name = "POPUP_BLOCKED";
118
+ reject(error);
113
119
  }, 100);
114
120
  });
115
121
  }
package/dist/client.mjs CHANGED
@@ -32,11 +32,11 @@ function authenticateWithPopup(token, options = {}) {
32
32
  );
33
33
  if (!popup) {
34
34
  log("Failed to open popup window. Please check popup blocker settings.");
35
- return reject(
36
- new Error(
37
- "Failed to open popup window. Please check popup blocker settings."
38
- )
35
+ const error = new Error(
36
+ "Failed to open popup window. Please check popup blocker settings."
39
37
  );
38
+ error.name = "POPUP_BLOCKED";
39
+ return reject(error);
40
40
  }
41
41
  const handleMessage = (event) => {
42
42
  if (event.origin !== "https://auth.bundleup.io") {
@@ -53,16 +53,20 @@ function authenticateWithPopup(token, options = {}) {
53
53
  }
54
54
  if (event.data.type === "bundleup:error") {
55
55
  log("Authentication failed", event.data.message);
56
- return reject(new Error(event.data.message || "Authentication failed"));
56
+ const error = new Error(event.data.message || "Authentication failed");
57
+ error.name = event.data.code || "AUTHENTICATION_ERROR";
58
+ return reject(error);
57
59
  }
58
60
  };
59
61
  const checkClosed = setInterval(() => {
60
62
  if (!popup.closed) {
61
63
  return;
62
64
  }
65
+ const error = new Error("Authentication popup was closed by user");
66
+ error.name = "POPUP_CLOSED";
63
67
  cleanup();
64
68
  log("Authentication popup closed by user");
65
- reject(new Error("Authentication popup was closed by user"));
69
+ reject(error);
66
70
  }, 1e3);
67
71
  const cleanup = () => {
68
72
  window.removeEventListener("message", handleMessage);
@@ -75,7 +79,9 @@ function authenticateWithPopup(token, options = {}) {
75
79
  }
76
80
  cleanup();
77
81
  log("Authentication popup was blocked or closed immediately");
78
- reject(new Error("Popup was blocked or closed immediately"));
82
+ const error = new Error("Popup was blocked or closed immediately");
83
+ error.name = "POPUP_BLOCKED";
84
+ reject(error);
79
85
  }, 100);
80
86
  });
81
87
  }
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.3",
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
+ }