@bundleup/sdk 0.0.17 → 0.1.0

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/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "@bundleup/sdk",
3
- "version": "0.0.17",
4
- "description": "SDK package for BundleUp",
3
+ "version": "0.1.0",
4
+ "description": "Official JavaScript/TypeScript SDK for BundleUp",
5
+ "homepage": "https://github.com/bundleup/bundleup-sdk-js#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/bundleup/bundleup-sdk-js/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/bundleup/bundleup-sdk-js.git"
12
+ },
13
+ "license": "ISC",
14
+ "author": "BundleUp",
5
15
  "exports": {
6
16
  ".": {
7
17
  "types": "./dist/index.d.ts",
@@ -9,24 +19,34 @@
9
19
  "require": "./dist/index.js"
10
20
  }
11
21
  },
22
+ "main": "./dist/index.js",
23
+ "module": "./dist/index.mjs",
24
+ "types": "./dist/index.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
12
28
  "scripts": {
13
29
  "build": "tsup src/index.ts --format cjs,esm --dts",
30
+ "clean": "rm -rf dist",
14
31
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
15
- "lint": "eslint src/",
16
- "test": "jest",
17
- "clean": "rm -rf dist"
32
+ "lint": "eslint src",
33
+ "test": "jest"
18
34
  },
19
35
  "devDependencies": {
20
36
  "@types/jest": "^29.5.0",
37
+ "eslint": "^9.39.2",
38
+ "eslint-config-prettier": "^10.1.8",
21
39
  "jest": "^29.0.0",
40
+ "prettier": "^3.8.0",
41
+ "prettier-plugin-packagejson": "^3.0.0",
22
42
  "ts-jest": "^29.1.0",
23
43
  "tsup": "^7.0.0",
44
+ "turbo": "^1.10.0",
24
45
  "typescript": "^5.0.0",
25
- "eslint": "^8.0.0"
46
+ "typescript-eslint": "^8.53.1"
26
47
  },
27
- "files": [
28
- "dist"
29
- ],
30
- "author": "BundleUp",
31
- "license": "ISC"
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ }
32
52
  }
@@ -1,24 +0,0 @@
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
- };
@@ -1,17 +0,0 @@
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
- };
@@ -1,17 +0,0 @@
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
- };
package/dist/client.d.mts DELETED
@@ -1,8 +0,0 @@
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.d.ts DELETED
@@ -1,8 +0,0 @@
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 DELETED
@@ -1,119 +0,0 @@
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
- });
package/dist/client.mjs DELETED
@@ -1,84 +0,0 @@
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
- };
package/dist/server.d.mts DELETED
@@ -1,21 +0,0 @@
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.d.ts DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,94 +0,0 @@
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
- });
package/dist/server.mjs DELETED
@@ -1,61 +0,0 @@
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
- };
package/dist/utils.d.mts DELETED
@@ -1,5 +0,0 @@
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.d.ts DELETED
@@ -1,5 +0,0 @@
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 DELETED
@@ -1,50 +0,0 @@
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 DELETED
@@ -1,10 +0,0 @@
1
- import {
2
- isClient,
3
- isTrue,
4
- logger
5
- } from "./chunk-B6T6V2FR.mjs";
6
- export {
7
- isClient,
8
- isTrue,
9
- logger
10
- };