@bundleup/sdk 0.0.1

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 ADDED
@@ -0,0 +1,4 @@
1
+ # Official Bundle Up SDK Library
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@bundleup/sdk.svg)](https://www.npmjs.com/package/@bundleup/sdk)
4
+ [![Documentation](https://img.shields.io/badge/documentation-bundleup.io-green.svg)](https://bundleup.io/docs/sdk)
@@ -0,0 +1,24 @@
1
+ // src/utils.ts
2
+ function isClient() {
3
+ return typeof window !== "undefined";
4
+ }
5
+ function logger(isDebug) {
6
+ return (message, ...args) => {
7
+ if (!isDebug) {
8
+ return;
9
+ }
10
+ console.log("%c[BundleUp]", "color: #00f;", message, ...args);
11
+ };
12
+ }
13
+ function isTrue(val) {
14
+ if (!val) {
15
+ return false;
16
+ }
17
+ return val.toLowerCase() === "true";
18
+ }
19
+
20
+ export {
21
+ isClient,
22
+ logger,
23
+ isTrue
24
+ };
@@ -0,0 +1,17 @@
1
+ // src/utils.ts
2
+ function isClient() {
3
+ return typeof window !== "undefined";
4
+ }
5
+ function logger(isDebug) {
6
+ return (message, ...args) => {
7
+ if (!isDebug) {
8
+ return;
9
+ }
10
+ console.log("%c[BundleUp]", "color: #00f;", message, ...args);
11
+ };
12
+ }
13
+
14
+ export {
15
+ isClient,
16
+ logger
17
+ };
@@ -0,0 +1,17 @@
1
+ // src/utils.ts
2
+ function isClient() {
3
+ return typeof window !== "undefined";
4
+ }
5
+ function logger(isDebug) {
6
+ return (message, ...args) => {
7
+ if (!isDebug) {
8
+ return;
9
+ }
10
+ console.log("%c[BundleUp]", "color: #00f;", message, ...args);
11
+ };
12
+ }
13
+
14
+ export {
15
+ isClient,
16
+ logger
17
+ };
@@ -0,0 +1,8 @@
1
+ interface AuthenticateWithPopupOptions {
2
+ width?: number;
3
+ height?: number;
4
+ debug?: boolean;
5
+ }
6
+ declare function authenticateWithPopup(token: string, options?: AuthenticateWithPopupOptions): Promise<Record<string, any>>;
7
+
8
+ export { AuthenticateWithPopupOptions, authenticateWithPopup };
@@ -0,0 +1,8 @@
1
+ interface AuthenticateWithPopupOptions {
2
+ width?: number;
3
+ height?: number;
4
+ debug?: boolean;
5
+ }
6
+ declare function authenticateWithPopup(token: string, options?: AuthenticateWithPopupOptions): Promise<Record<string, any>>;
7
+
8
+ export { AuthenticateWithPopupOptions, authenticateWithPopup };
package/dist/client.js ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/client.ts
21
+ var client_exports = {};
22
+ __export(client_exports, {
23
+ authenticateWithPopup: () => authenticateWithPopup
24
+ });
25
+ module.exports = __toCommonJS(client_exports);
26
+
27
+ // src/utils.ts
28
+ function isClient() {
29
+ return typeof window !== "undefined";
30
+ }
31
+ function logger(isDebug) {
32
+ return (message, ...args) => {
33
+ if (!isDebug) {
34
+ return;
35
+ }
36
+ console.log("%c[BundleUp]", "color: #00f;", message, ...args);
37
+ };
38
+ }
39
+
40
+ // src/client.ts
41
+ function authenticateWithPopup(token, options = {}) {
42
+ return new Promise((resolve, reject) => {
43
+ if (!token) {
44
+ return reject(new Error("Token is required"));
45
+ }
46
+ const width = options?.width ?? 500;
47
+ const height = options?.height ?? 600;
48
+ const left = window.screenX + (window.outerWidth - width) / 2;
49
+ const top = window.screenY + (window.outerHeight - height) / 2.5;
50
+ const debug = options?.debug ?? false;
51
+ const client = isClient();
52
+ const log = logger(debug);
53
+ if (!client) {
54
+ log("Authentication failed: not in client environment");
55
+ return reject(
56
+ new Error(
57
+ "authenticateWithPopup can only be used in a client environment"
58
+ )
59
+ );
60
+ }
61
+ log("Starting authentication with popup");
62
+ const popup = window.open(
63
+ `https://auth.bundleup.io/${token}`,
64
+ "bundleup-auth",
65
+ `width=${width},height=${height},left=${left},top=${top},scrollbars=yes,resizable=yes`
66
+ );
67
+ if (!popup) {
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
+ )
73
+ );
74
+ }
75
+ const handleMessage = (event) => {
76
+ if (event.origin !== "https://auth.bundleup.io") {
77
+ return;
78
+ }
79
+ if (!event.data?.type) {
80
+ return;
81
+ }
82
+ cleanup();
83
+ popup.close();
84
+ if (event.data.type === "bundleup:success") {
85
+ log("Authentication successful");
86
+ return resolve(event.data.data);
87
+ }
88
+ if (event.data.type === "bundleup:error") {
89
+ log("Authentication failed", event.data.message);
90
+ return reject(new Error(event.data.message || "Authentication failed"));
91
+ }
92
+ };
93
+ const checkClosed = setInterval(() => {
94
+ if (!popup.closed) {
95
+ return;
96
+ }
97
+ cleanup();
98
+ log("Authentication popup closed by user");
99
+ reject(new Error("Authentication popup was closed by user"));
100
+ }, 1e3);
101
+ const cleanup = () => {
102
+ window.removeEventListener("message", handleMessage);
103
+ clearInterval(checkClosed);
104
+ };
105
+ window.addEventListener("message", handleMessage);
106
+ setTimeout(() => {
107
+ if (!popup.closed) {
108
+ return;
109
+ }
110
+ cleanup();
111
+ log("Authentication popup was blocked or closed immediately");
112
+ reject(new Error("Popup was blocked or closed immediately"));
113
+ }, 100);
114
+ });
115
+ }
116
+ // Annotate the CommonJS export names for ESM import in node:
117
+ 0 && (module.exports = {
118
+ authenticateWithPopup
119
+ });
@@ -0,0 +1,84 @@
1
+ import {
2
+ isClient,
3
+ logger
4
+ } from "./chunk-B6T6V2FR.mjs";
5
+
6
+ // src/client.ts
7
+ function authenticateWithPopup(token, options = {}) {
8
+ return new Promise((resolve, reject) => {
9
+ if (!token) {
10
+ return reject(new Error("Token is required"));
11
+ }
12
+ const width = options?.width ?? 500;
13
+ const height = options?.height ?? 600;
14
+ const left = window.screenX + (window.outerWidth - width) / 2;
15
+ const top = window.screenY + (window.outerHeight - height) / 2.5;
16
+ const debug = options?.debug ?? false;
17
+ const client = isClient();
18
+ const log = logger(debug);
19
+ if (!client) {
20
+ log("Authentication failed: not in client environment");
21
+ return reject(
22
+ new Error(
23
+ "authenticateWithPopup can only be used in a client environment"
24
+ )
25
+ );
26
+ }
27
+ log("Starting authentication with popup");
28
+ const popup = window.open(
29
+ `https://auth.bundleup.io/${token}`,
30
+ "bundleup-auth",
31
+ `width=${width},height=${height},left=${left},top=${top},scrollbars=yes,resizable=yes`
32
+ );
33
+ if (!popup) {
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
+ )
39
+ );
40
+ }
41
+ const handleMessage = (event) => {
42
+ if (event.origin !== "https://auth.bundleup.io") {
43
+ return;
44
+ }
45
+ if (!event.data?.type) {
46
+ return;
47
+ }
48
+ cleanup();
49
+ popup.close();
50
+ if (event.data.type === "bundleup:success") {
51
+ log("Authentication successful");
52
+ return resolve(event.data.data);
53
+ }
54
+ if (event.data.type === "bundleup:error") {
55
+ log("Authentication failed", event.data.message);
56
+ return reject(new Error(event.data.message || "Authentication failed"));
57
+ }
58
+ };
59
+ const checkClosed = setInterval(() => {
60
+ if (!popup.closed) {
61
+ return;
62
+ }
63
+ cleanup();
64
+ log("Authentication popup closed by user");
65
+ reject(new Error("Authentication popup was closed by user"));
66
+ }, 1e3);
67
+ const cleanup = () => {
68
+ window.removeEventListener("message", handleMessage);
69
+ clearInterval(checkClosed);
70
+ };
71
+ window.addEventListener("message", handleMessage);
72
+ setTimeout(() => {
73
+ if (!popup.closed) {
74
+ return;
75
+ }
76
+ cleanup();
77
+ log("Authentication popup was blocked or closed immediately");
78
+ reject(new Error("Popup was blocked or closed immediately"));
79
+ }, 100);
80
+ });
81
+ }
82
+ export {
83
+ authenticateWithPopup
84
+ };
@@ -0,0 +1,75 @@
1
+ declare abstract class Base<T> {
2
+ protected abstract path: string;
3
+ protected apiKey: string;
4
+ protected baseUrl: string;
5
+ protected version: string;
6
+ constructor(apiKey: string);
7
+ protected get apiUrl(): string;
8
+ protected get headers(): Record<string, string>;
9
+ list<K extends Record<string, any>>(params?: K): Promise<T[]>;
10
+ create<K extends Record<string, any>>(body: K): Promise<T>;
11
+ retrieve(id: string): Promise<T>;
12
+ update<K extends Record<string, any>>(id: string, body: K): Promise<T>;
13
+ del(id: string): Promise<void>;
14
+ }
15
+
16
+ interface Connection {
17
+ id: string;
18
+ externalId?: string;
19
+ expiresAt: Date;
20
+ integrationId: string;
21
+ isValid: boolean;
22
+ refreshedAt?: Date;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ }
26
+ declare class Connections extends Base<Connection> {
27
+ protected path: string;
28
+ }
29
+
30
+ interface Integration {
31
+ id: true;
32
+ identifier: true;
33
+ createdAt: true;
34
+ updatedAt: true;
35
+ }
36
+ declare class Integrations extends Base<Integration> {
37
+ protected path: string;
38
+ }
39
+
40
+ interface Webhook {
41
+ id: string;
42
+ name: string;
43
+ url: string;
44
+ events: Record<string, boolean>;
45
+ createdAt: Date;
46
+ updatedAt: Date;
47
+ lastTriggeredAt?: Date;
48
+ }
49
+ declare class Webhooks extends Base<Webhook> {
50
+ protected path: string;
51
+ }
52
+
53
+ declare class BURequest {
54
+ private apiKey;
55
+ private connectionId;
56
+ constructor(apiKey: string, connectionId: string);
57
+ protected get baseUrl(): string;
58
+ protected get headers(): Record<string, string>;
59
+ get(path: string, params?: Record<string, any>): Promise<any>;
60
+ post(path: string, body?: Record<string, any>): Promise<any>;
61
+ put(path: string, body?: Record<string, any>): Promise<any>;
62
+ patch(path: string, body?: Record<string, any>): Promise<any>;
63
+ delete(path: string): Promise<any>;
64
+ }
65
+
66
+ declare class BundleUp {
67
+ private apiKey;
68
+ constructor(apiKey: string);
69
+ connections(): Connections;
70
+ integrations(): Integrations;
71
+ webhooks(): Webhooks;
72
+ request(connectionId: string): BURequest;
73
+ }
74
+
75
+ export { BundleUp };
@@ -0,0 +1,75 @@
1
+ declare abstract class Base<T> {
2
+ protected abstract path: string;
3
+ protected apiKey: string;
4
+ protected baseUrl: string;
5
+ protected version: string;
6
+ constructor(apiKey: string);
7
+ protected get apiUrl(): string;
8
+ protected get headers(): Record<string, string>;
9
+ list<K extends Record<string, any>>(params?: K): Promise<T[]>;
10
+ create<K extends Record<string, any>>(body: K): Promise<T>;
11
+ retrieve(id: string): Promise<T>;
12
+ update<K extends Record<string, any>>(id: string, body: K): Promise<T>;
13
+ del(id: string): Promise<void>;
14
+ }
15
+
16
+ interface Connection {
17
+ id: string;
18
+ externalId?: string;
19
+ expiresAt: Date;
20
+ integrationId: string;
21
+ isValid: boolean;
22
+ refreshedAt?: Date;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ }
26
+ declare class Connections extends Base<Connection> {
27
+ protected path: string;
28
+ }
29
+
30
+ interface Integration {
31
+ id: true;
32
+ identifier: true;
33
+ createdAt: true;
34
+ updatedAt: true;
35
+ }
36
+ declare class Integrations extends Base<Integration> {
37
+ protected path: string;
38
+ }
39
+
40
+ interface Webhook {
41
+ id: string;
42
+ name: string;
43
+ url: string;
44
+ events: Record<string, boolean>;
45
+ createdAt: Date;
46
+ updatedAt: Date;
47
+ lastTriggeredAt?: Date;
48
+ }
49
+ declare class Webhooks extends Base<Webhook> {
50
+ protected path: string;
51
+ }
52
+
53
+ declare class BURequest {
54
+ private apiKey;
55
+ private connectionId;
56
+ constructor(apiKey: string, connectionId: string);
57
+ protected get baseUrl(): string;
58
+ protected get headers(): Record<string, string>;
59
+ get(path: string, params?: Record<string, any>): Promise<any>;
60
+ post(path: string, body?: Record<string, any>): Promise<any>;
61
+ put(path: string, body?: Record<string, any>): Promise<any>;
62
+ patch(path: string, body?: Record<string, any>): Promise<any>;
63
+ delete(path: string): Promise<any>;
64
+ }
65
+
66
+ declare class BundleUp {
67
+ private apiKey;
68
+ constructor(apiKey: string);
69
+ connections(): Connections;
70
+ integrations(): Integrations;
71
+ webhooks(): Webhooks;
72
+ request(connectionId: string): BURequest;
73
+ }
74
+
75
+ export { BundleUp };
package/dist/index.js ADDED
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ BundleUp: () => BundleUp
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/base.ts
28
+ var Base = class {
29
+ constructor(apiKey) {
30
+ this.baseUrl = "https://api.bundleup.io";
31
+ this.version = "v1";
32
+ this.apiKey = apiKey;
33
+ }
34
+ get apiUrl() {
35
+ return `${this.baseUrl}/${this.version}`;
36
+ }
37
+ get headers() {
38
+ return {
39
+ "Content-Type": "application/json",
40
+ Authorization: `Bearer ${this.apiKey}`
41
+ };
42
+ }
43
+ async list(params = {}) {
44
+ const response = await fetch(`${this.apiUrl}${this.path}`, {
45
+ method: "GET",
46
+ headers: this.headers,
47
+ body: JSON.stringify({
48
+ ...params
49
+ })
50
+ });
51
+ if (!response.ok) {
52
+ throw new Error(`Failed to fetch ${this.path}: ${response.statusText}`);
53
+ }
54
+ const data = await response.json();
55
+ return data;
56
+ }
57
+ async create(body) {
58
+ const response = await fetch(`${this.apiUrl}${this.path}`, {
59
+ method: "POST",
60
+ headers: this.headers,
61
+ body: JSON.stringify(body)
62
+ });
63
+ if (!response.ok) {
64
+ throw new Error(`Failed to create ${this.path}: ${response.statusText}`);
65
+ }
66
+ const data = await response.json();
67
+ return data;
68
+ }
69
+ async retrieve(id) {
70
+ const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
71
+ method: "GET",
72
+ headers: this.headers
73
+ });
74
+ if (!response.ok) {
75
+ throw new Error(`Failed to retrieve ${this.path}/${id}: ${response.statusText}`);
76
+ }
77
+ const data = await response.json();
78
+ return data;
79
+ }
80
+ async update(id, body) {
81
+ const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
82
+ method: "PATCH",
83
+ headers: this.headers,
84
+ body: JSON.stringify(body)
85
+ });
86
+ if (!response.ok) {
87
+ throw new Error(`Failed to update ${this.path}/${id}: ${response.statusText}`);
88
+ }
89
+ const data = await response.json();
90
+ return data;
91
+ }
92
+ async del(id) {
93
+ const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
94
+ method: "DELETE",
95
+ headers: this.headers
96
+ });
97
+ if (!response.ok) {
98
+ throw new Error(`Failed to delete ${this.path}/${id}: ${response.statusText}`);
99
+ }
100
+ }
101
+ };
102
+
103
+ // src/connection.ts
104
+ var Connections = class extends Base {
105
+ constructor() {
106
+ super(...arguments);
107
+ this.path = "/connections";
108
+ }
109
+ };
110
+
111
+ // src/integration.ts
112
+ var Integrations = class extends Base {
113
+ constructor() {
114
+ super(...arguments);
115
+ this.path = "/integrations";
116
+ }
117
+ };
118
+
119
+ // src/webhooks.ts
120
+ var Webhooks = class extends Base {
121
+ constructor() {
122
+ super(...arguments);
123
+ this.path = "/webhooks";
124
+ }
125
+ };
126
+
127
+ // src/request.ts
128
+ var BURequest = class {
129
+ constructor(apiKey, connectionId) {
130
+ this.apiKey = apiKey;
131
+ this.connectionId = connectionId;
132
+ }
133
+ get baseUrl() {
134
+ return "https://req.bundleup.io";
135
+ }
136
+ get headers() {
137
+ return {
138
+ "Content-Type": "application/json",
139
+ Authorization: `Bearer ${this.apiKey}`,
140
+ "BU-Connection-Id": this.connectionId
141
+ };
142
+ }
143
+ async get(path, params = {}) {
144
+ const queryString = new URLSearchParams(params).toString();
145
+ const url = queryString ? `${path}?${queryString}` : path;
146
+ const response = await fetch(`${this.baseUrl}${url}`, {
147
+ method: "GET",
148
+ headers: this.headers
149
+ });
150
+ if (!response.ok) {
151
+ throw new Error(`Failed to fetch ${path}: ${response.statusText}`);
152
+ }
153
+ return response.json();
154
+ }
155
+ async post(path, body = {}) {
156
+ const response = await fetch(`${this.baseUrl}${path}`, {
157
+ method: "POST",
158
+ headers: {
159
+ "Content-Type": "application/json",
160
+ Authorization: `Bearer ${this.apiKey}`
161
+ },
162
+ body: JSON.stringify(body)
163
+ });
164
+ if (!response.ok) {
165
+ throw new Error(`Failed to post to ${path}: ${response.statusText}`);
166
+ }
167
+ return response.json();
168
+ }
169
+ async put(path, body = {}) {
170
+ const response = await fetch(`${this.baseUrl}${path}`, {
171
+ method: "PUT",
172
+ headers: this.headers,
173
+ body: JSON.stringify(body)
174
+ });
175
+ if (!response.ok) {
176
+ throw new Error(`Failed to put to ${path}: ${response.statusText}`);
177
+ }
178
+ return response.json();
179
+ }
180
+ async patch(path, body = {}) {
181
+ const response = await fetch(`${this.baseUrl}${path}`, {
182
+ method: "PATCH",
183
+ headers: this.headers,
184
+ body: JSON.stringify(body)
185
+ });
186
+ if (!response.ok) {
187
+ throw new Error(`Failed to patch ${path}: ${response.statusText}`);
188
+ }
189
+ return response.json();
190
+ }
191
+ async delete(path) {
192
+ const response = await fetch(`${this.baseUrl}${path}`, {
193
+ method: "DELETE",
194
+ headers: this.headers
195
+ });
196
+ if (!response.ok) {
197
+ throw new Error(`Failed to delete ${path}: ${response.statusText}`);
198
+ }
199
+ return response.json();
200
+ }
201
+ };
202
+
203
+ // src/index.ts
204
+ var BundleUp = class {
205
+ constructor(apiKey) {
206
+ this.apiKey = apiKey;
207
+ }
208
+ connections() {
209
+ return new Connections(this.apiKey);
210
+ }
211
+ integrations() {
212
+ return new Integrations(this.apiKey);
213
+ }
214
+ webhooks() {
215
+ return new Webhooks(this.apiKey);
216
+ }
217
+ request(connectionId) {
218
+ if (!connectionId) {
219
+ throw new Error("Connection ID is required to create a Request instance.");
220
+ }
221
+ return new BURequest(this.apiKey, connectionId);
222
+ }
223
+ };
224
+ // Annotate the CommonJS export names for ESM import in node:
225
+ 0 && (module.exports = {
226
+ BundleUp
227
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,200 @@
1
+ // src/base.ts
2
+ var Base = class {
3
+ constructor(apiKey) {
4
+ this.baseUrl = "https://api.bundleup.io";
5
+ this.version = "v1";
6
+ this.apiKey = apiKey;
7
+ }
8
+ get apiUrl() {
9
+ return `${this.baseUrl}/${this.version}`;
10
+ }
11
+ get headers() {
12
+ return {
13
+ "Content-Type": "application/json",
14
+ Authorization: `Bearer ${this.apiKey}`
15
+ };
16
+ }
17
+ async list(params = {}) {
18
+ const response = await fetch(`${this.apiUrl}${this.path}`, {
19
+ method: "GET",
20
+ headers: this.headers,
21
+ body: JSON.stringify({
22
+ ...params
23
+ })
24
+ });
25
+ if (!response.ok) {
26
+ throw new Error(`Failed to fetch ${this.path}: ${response.statusText}`);
27
+ }
28
+ const data = await response.json();
29
+ return data;
30
+ }
31
+ async create(body) {
32
+ const response = await fetch(`${this.apiUrl}${this.path}`, {
33
+ method: "POST",
34
+ headers: this.headers,
35
+ body: JSON.stringify(body)
36
+ });
37
+ if (!response.ok) {
38
+ throw new Error(`Failed to create ${this.path}: ${response.statusText}`);
39
+ }
40
+ const data = await response.json();
41
+ return data;
42
+ }
43
+ async retrieve(id) {
44
+ const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
45
+ method: "GET",
46
+ headers: this.headers
47
+ });
48
+ if (!response.ok) {
49
+ throw new Error(`Failed to retrieve ${this.path}/${id}: ${response.statusText}`);
50
+ }
51
+ const data = await response.json();
52
+ return data;
53
+ }
54
+ async update(id, body) {
55
+ const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
56
+ method: "PATCH",
57
+ headers: this.headers,
58
+ body: JSON.stringify(body)
59
+ });
60
+ if (!response.ok) {
61
+ throw new Error(`Failed to update ${this.path}/${id}: ${response.statusText}`);
62
+ }
63
+ const data = await response.json();
64
+ return data;
65
+ }
66
+ async del(id) {
67
+ const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
68
+ method: "DELETE",
69
+ headers: this.headers
70
+ });
71
+ if (!response.ok) {
72
+ throw new Error(`Failed to delete ${this.path}/${id}: ${response.statusText}`);
73
+ }
74
+ }
75
+ };
76
+
77
+ // src/connection.ts
78
+ var Connections = class extends Base {
79
+ constructor() {
80
+ super(...arguments);
81
+ this.path = "/connections";
82
+ }
83
+ };
84
+
85
+ // src/integration.ts
86
+ var Integrations = class extends Base {
87
+ constructor() {
88
+ super(...arguments);
89
+ this.path = "/integrations";
90
+ }
91
+ };
92
+
93
+ // src/webhooks.ts
94
+ var Webhooks = class extends Base {
95
+ constructor() {
96
+ super(...arguments);
97
+ this.path = "/webhooks";
98
+ }
99
+ };
100
+
101
+ // src/request.ts
102
+ var BURequest = class {
103
+ constructor(apiKey, connectionId) {
104
+ this.apiKey = apiKey;
105
+ this.connectionId = connectionId;
106
+ }
107
+ get baseUrl() {
108
+ return "https://req.bundleup.io";
109
+ }
110
+ get headers() {
111
+ return {
112
+ "Content-Type": "application/json",
113
+ Authorization: `Bearer ${this.apiKey}`,
114
+ "BU-Connection-Id": this.connectionId
115
+ };
116
+ }
117
+ async get(path, params = {}) {
118
+ const queryString = new URLSearchParams(params).toString();
119
+ const url = queryString ? `${path}?${queryString}` : path;
120
+ const response = await fetch(`${this.baseUrl}${url}`, {
121
+ method: "GET",
122
+ headers: this.headers
123
+ });
124
+ if (!response.ok) {
125
+ throw new Error(`Failed to fetch ${path}: ${response.statusText}`);
126
+ }
127
+ return response.json();
128
+ }
129
+ async post(path, body = {}) {
130
+ const response = await fetch(`${this.baseUrl}${path}`, {
131
+ method: "POST",
132
+ headers: {
133
+ "Content-Type": "application/json",
134
+ Authorization: `Bearer ${this.apiKey}`
135
+ },
136
+ body: JSON.stringify(body)
137
+ });
138
+ if (!response.ok) {
139
+ throw new Error(`Failed to post to ${path}: ${response.statusText}`);
140
+ }
141
+ return response.json();
142
+ }
143
+ async put(path, body = {}) {
144
+ const response = await fetch(`${this.baseUrl}${path}`, {
145
+ method: "PUT",
146
+ headers: this.headers,
147
+ body: JSON.stringify(body)
148
+ });
149
+ if (!response.ok) {
150
+ throw new Error(`Failed to put to ${path}: ${response.statusText}`);
151
+ }
152
+ return response.json();
153
+ }
154
+ async patch(path, body = {}) {
155
+ const response = await fetch(`${this.baseUrl}${path}`, {
156
+ method: "PATCH",
157
+ headers: this.headers,
158
+ body: JSON.stringify(body)
159
+ });
160
+ if (!response.ok) {
161
+ throw new Error(`Failed to patch ${path}: ${response.statusText}`);
162
+ }
163
+ return response.json();
164
+ }
165
+ async delete(path) {
166
+ const response = await fetch(`${this.baseUrl}${path}`, {
167
+ method: "DELETE",
168
+ headers: this.headers
169
+ });
170
+ if (!response.ok) {
171
+ throw new Error(`Failed to delete ${path}: ${response.statusText}`);
172
+ }
173
+ return response.json();
174
+ }
175
+ };
176
+
177
+ // src/index.ts
178
+ var BundleUp = class {
179
+ constructor(apiKey) {
180
+ this.apiKey = apiKey;
181
+ }
182
+ connections() {
183
+ return new Connections(this.apiKey);
184
+ }
185
+ integrations() {
186
+ return new Integrations(this.apiKey);
187
+ }
188
+ webhooks() {
189
+ return new Webhooks(this.apiKey);
190
+ }
191
+ request(connectionId) {
192
+ if (!connectionId) {
193
+ throw new Error("Connection ID is required to create a Request instance.");
194
+ }
195
+ return new BURequest(this.apiKey, connectionId);
196
+ }
197
+ };
198
+ export {
199
+ BundleUp
200
+ };
@@ -0,0 +1,21 @@
1
+ interface BundleUpConfig {
2
+ apiKey?: string;
3
+ debug?: boolean;
4
+ }
5
+ interface BundleUpResponse {
6
+ token: string;
7
+ expires_in: number;
8
+ externalId: string;
9
+ }
10
+ interface ConnectionOptions {
11
+ externalId?: string;
12
+ metadata?: Record<string, unknown>;
13
+ }
14
+ declare class BundleUp {
15
+ private config;
16
+ constructor(config?: BundleUpConfig);
17
+ private log;
18
+ createConnection(integrationId: string, options: ConnectionOptions): Promise<BundleUpResponse>;
19
+ }
20
+
21
+ export { BundleUp, BundleUpConfig, BundleUpResponse, ConnectionOptions };
@@ -0,0 +1,21 @@
1
+ interface BundleUpConfig {
2
+ apiKey?: string;
3
+ debug?: boolean;
4
+ }
5
+ interface BundleUpResponse {
6
+ token: string;
7
+ expires_in: number;
8
+ externalId: string;
9
+ }
10
+ interface ConnectionOptions {
11
+ externalId?: string;
12
+ metadata?: Record<string, unknown>;
13
+ }
14
+ declare class BundleUp {
15
+ private config;
16
+ constructor(config?: BundleUpConfig);
17
+ private log;
18
+ createConnection(integrationId: string, options: ConnectionOptions): Promise<BundleUpResponse>;
19
+ }
20
+
21
+ export { BundleUp, BundleUpConfig, BundleUpResponse, ConnectionOptions };
package/dist/server.js ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/server.ts
21
+ var server_exports = {};
22
+ __export(server_exports, {
23
+ BundleUp: () => BundleUp
24
+ });
25
+ module.exports = __toCommonJS(server_exports);
26
+
27
+ // src/utils.ts
28
+ function logger(isDebug) {
29
+ return (message, ...args) => {
30
+ if (!isDebug) {
31
+ return;
32
+ }
33
+ console.log("%c[BundleUp]", "color: #00f;", message, ...args);
34
+ };
35
+ }
36
+
37
+ // src/server.ts
38
+ var BundleUp = class {
39
+ constructor(config = {}) {
40
+ if (!config.apiKey) {
41
+ throw new Error("API key is required for authentication");
42
+ }
43
+ this.config = {
44
+ apiKey: config.apiKey,
45
+ debug: config.debug ?? false
46
+ };
47
+ }
48
+ log(message, ...args) {
49
+ return logger(!!this.config.debug)(message, ...args);
50
+ }
51
+ async createConnection(integrationId, options) {
52
+ this.log(`Creating connection for integration: ${integrationId}`);
53
+ if (!integrationId) {
54
+ this.log("Integration ID is missing");
55
+ throw new Error("Integration ID is required to create a connection");
56
+ }
57
+ 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
+ })
69
+ });
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
+ if (!data.token) {
80
+ this.log("Invalid response: could not create token", data);
81
+ throw new Error("Invalid response: could not create token");
82
+ }
83
+ this.log("Authentication token received successfully");
84
+ return data;
85
+ } catch (error) {
86
+ this.log("Error creating connection", error);
87
+ throw error;
88
+ }
89
+ }
90
+ };
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ BundleUp
94
+ });
@@ -0,0 +1,61 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-B6T6V2FR.mjs";
4
+
5
+ // src/server.ts
6
+ var BundleUp = class {
7
+ constructor(config = {}) {
8
+ if (!config.apiKey) {
9
+ throw new Error("API key is required for authentication");
10
+ }
11
+ this.config = {
12
+ apiKey: config.apiKey,
13
+ debug: config.debug ?? false
14
+ };
15
+ }
16
+ log(message, ...args) {
17
+ return logger(!!this.config.debug)(message, ...args);
18
+ }
19
+ async createConnection(integrationId, options) {
20
+ this.log(`Creating connection for integration: ${integrationId}`);
21
+ if (!integrationId) {
22
+ this.log("Integration ID is missing");
23
+ throw new Error("Integration ID is required to create a connection");
24
+ }
25
+ 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
+ })
37
+ });
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
+ if (!data.token) {
48
+ this.log("Invalid response: could not create token", data);
49
+ throw new Error("Invalid response: could not create token");
50
+ }
51
+ this.log("Authentication token received successfully");
52
+ return data;
53
+ } catch (error) {
54
+ this.log("Error creating connection", error);
55
+ throw error;
56
+ }
57
+ }
58
+ };
59
+ export {
60
+ BundleUp
61
+ };
@@ -0,0 +1,5 @@
1
+ declare function isClient(): boolean;
2
+ declare function logger(isDebug: boolean): (message: string, ...args: any[]) => void;
3
+ declare function isTrue(val?: string): boolean;
4
+
5
+ export { isClient, isTrue, logger };
@@ -0,0 +1,5 @@
1
+ declare function isClient(): boolean;
2
+ declare function logger(isDebug: boolean): (message: string, ...args: any[]) => void;
3
+ declare function isTrue(val?: string): boolean;
4
+
5
+ export { isClient, isTrue, logger };
package/dist/utils.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ isClient: () => isClient,
24
+ isTrue: () => isTrue,
25
+ logger: () => logger
26
+ });
27
+ module.exports = __toCommonJS(utils_exports);
28
+ function isClient() {
29
+ return typeof window !== "undefined";
30
+ }
31
+ function logger(isDebug) {
32
+ return (message, ...args) => {
33
+ if (!isDebug) {
34
+ return;
35
+ }
36
+ console.log("%c[BundleUp]", "color: #00f;", message, ...args);
37
+ };
38
+ }
39
+ function isTrue(val) {
40
+ if (!val) {
41
+ return false;
42
+ }
43
+ return val.toLowerCase() === "true";
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ isClient,
48
+ isTrue,
49
+ logger
50
+ });
package/dist/utils.mjs ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ isClient,
3
+ isTrue,
4
+ logger
5
+ } from "./chunk-B6T6V2FR.mjs";
6
+ export {
7
+ isClient,
8
+ isTrue,
9
+ logger
10
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@bundleup/sdk",
3
+ "version": "0.0.1",
4
+ "description": "SDK package for BundleUp",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.mjs",
9
+ "require": "./dist/index.js"
10
+ }
11
+ },
12
+ "scripts": {
13
+ "build": "tsup src/index.ts --format cjs,esm --dts",
14
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
15
+ "lint": "eslint src/",
16
+ "test": "jest",
17
+ "clean": "rm -rf dist"
18
+ },
19
+ "devDependencies": {
20
+ "tsup": "^7.0.0",
21
+ "typescript": "^5.0.0",
22
+ "eslint": "^8.0.0",
23
+ "jest": "^29.0.0"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "author": "BundleUp",
29
+ "license": "ISC"
30
+ }