@bundleup/react 0.0.2

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 Plugin for React
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@bundleup/react.svg)](https://www.npmjs.com/package/@bundleup/react)
4
+ [![Documentation](https://img.shields.io/badge/documentation-bundleup.io-green.svg)](https://bundleup.io/docs/react)
@@ -0,0 +1,14 @@
1
+ import { AuthenticateWithPopupOptions } from '@bundleup/core/client';
2
+
3
+ type CallbackResponse = {
4
+ success: true;
5
+ } | {
6
+ success: false;
7
+ error: Error;
8
+ };
9
+ type CallbackFn = (response: CallbackResponse) => void;
10
+ declare function useBundleup(callback: CallbackFn, opts?: AuthenticateWithPopupOptions): {
11
+ start: (token: string) => void;
12
+ };
13
+
14
+ export { useBundleup };
@@ -0,0 +1,14 @@
1
+ import { AuthenticateWithPopupOptions } from '@bundleup/core/client';
2
+
3
+ type CallbackResponse = {
4
+ success: true;
5
+ } | {
6
+ success: false;
7
+ error: Error;
8
+ };
9
+ type CallbackFn = (response: CallbackResponse) => void;
10
+ declare function useBundleup(callback: CallbackFn, opts?: AuthenticateWithPopupOptions): {
11
+ start: (token: string) => void;
12
+ };
13
+
14
+ export { useBundleup };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
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
+ useBundleup: () => useBundleup
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var import_react = require("react");
27
+ var import_client = require("@bundleup/core/client");
28
+ var import_utils = require("@bundleup/core/utils");
29
+ function useBundleup(callback, opts = {}) {
30
+ const [options, setOptions] = (0, import_react.useState)(opts);
31
+ (0, import_react.useEffect)(() => {
32
+ setOptions(opts);
33
+ }, [opts]);
34
+ const log = (0, import_react.useCallback)(
35
+ (msg, ...args) => (0, import_utils.logger)(!!options.debug)(msg, ...args),
36
+ [options.debug]
37
+ );
38
+ const start = (0, import_react.useCallback)(
39
+ (token) => {
40
+ if (!token) {
41
+ log("No token provided, skipping BundleUp authentication.");
42
+ return;
43
+ }
44
+ (0, import_client.authenticateWithPopup)(token, options).then(() => {
45
+ log("BundleUp authentication successful.");
46
+ callback({ success: true });
47
+ }).catch((error) => {
48
+ log("BundleUp authentication failed:", error?.message || error);
49
+ callback({ success: false, error });
50
+ });
51
+ },
52
+ [options, callback]
53
+ );
54
+ return { start };
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ useBundleup
59
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,36 @@
1
+ // src/index.ts
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import {
4
+ authenticateWithPopup
5
+ } from "@bundleup/core/client";
6
+ import { logger } from "@bundleup/core/utils";
7
+ function useBundleup(callback, opts = {}) {
8
+ const [options, setOptions] = useState(opts);
9
+ useEffect(() => {
10
+ setOptions(opts);
11
+ }, [opts]);
12
+ const log = useCallback(
13
+ (msg, ...args) => logger(!!options.debug)(msg, ...args),
14
+ [options.debug]
15
+ );
16
+ const start = useCallback(
17
+ (token) => {
18
+ if (!token) {
19
+ log("No token provided, skipping BundleUp authentication.");
20
+ return;
21
+ }
22
+ authenticateWithPopup(token, options).then(() => {
23
+ log("BundleUp authentication successful.");
24
+ callback({ success: true });
25
+ }).catch((error) => {
26
+ log("BundleUp authentication failed:", error?.message || error);
27
+ callback({ success: false, error });
28
+ });
29
+ },
30
+ [options, callback]
31
+ );
32
+ return { start };
33
+ }
34
+ export {
35
+ useBundleup
36
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@bundleup/react",
3
+ "version": "0.0.2",
4
+ "description": "BundleUp plugin for React applications",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsup src/index.ts --format cjs,esm --dts",
17
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
18
+ "lint": "eslint src/",
19
+ "test": "jest",
20
+ "clean": "rm -rf dist"
21
+ },
22
+ "dependencies": {
23
+ "@bundleup/core": "0.0.2"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=16.8.0"
27
+ },
28
+ "devDependencies": {
29
+ "tsup": "^7.0.0",
30
+ "typescript": "^5.0.0",
31
+ "eslint": "^8.0.0",
32
+ "jest": "^29.0.0",
33
+ "@types/react": "^18.0.0",
34
+ "react": "^18.0.0"
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "keywords": [
40
+ "bundleup",
41
+ "react",
42
+ "plugin"
43
+ ],
44
+ "author": "BundleUp",
45
+ "license": "ISC"
46
+ }