@hellocoop/react 1.0.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/dist/auth.d.ts +20 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +31 -0
- package/dist/buttons.d.ts +35 -0
- package/dist/buttons.d.ts.map +1 -0
- package/dist/buttons.js +105 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/login-status.d.ts +7 -0
- package/dist/login-status.d.ts.map +1 -0
- package/dist/login-status.js +15 -0
- package/dist/logout.d.ts +3 -0
- package/dist/logout.d.ts.map +1 -0
- package/dist/logout.js +10 -0
- package/dist/provider.d.ts +11 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +47 -0
- package/package.json +56 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Claims } from '@hellocoop/types';
|
|
2
|
+
type AuthCookie = {
|
|
3
|
+
sub: string;
|
|
4
|
+
iat: number;
|
|
5
|
+
} & Claims & {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export type Auth = {
|
|
9
|
+
isLoggedIn: false;
|
|
10
|
+
} | ({
|
|
11
|
+
isLoggedIn: true;
|
|
12
|
+
} & AuthCookie);
|
|
13
|
+
export type AuthState = {
|
|
14
|
+
auth: Auth | {};
|
|
15
|
+
isLoading: boolean;
|
|
16
|
+
isLoggedIn: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare const useAuth: () => AuthState;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAe9C,KAAK,UAAU,GAAG;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAA;CACd,GAAG,MAAM,GAAG;IACT,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAA;AAEL,MAAM,MAAM,IAAI,GAAG;IACf,UAAU,EAAE,KAAK,CAAA;CACpB,GAAG,CAAC;IACD,UAAU,EAAE,IAAI,CAAC;CACpB,GAAG,UAAU,CAAE,CAAA;AAGhB,MAAM,MAAM,SAAS,GAAG;IACpB,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,GAAG,SAAS,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,OAAO,QAAO,SAS1B,CAAA"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useAuth = void 0;
|
|
7
|
+
const swr_1 = __importDefault(require("swr"));
|
|
8
|
+
const provider_1 = require("./provider");
|
|
9
|
+
const fetcher = async (url) => {
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch(url);
|
|
12
|
+
const auth = await response.json();
|
|
13
|
+
return auth;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error(err);
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const useAuth = () => {
|
|
21
|
+
const defaultAuth = (0, provider_1.useHelloProviderContext)();
|
|
22
|
+
const { data: auth, isLoading } = (0, swr_1.default)(provider_1.routeConfig.auth, fetcher, {
|
|
23
|
+
fallbackData: defaultAuth
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
auth: auth || {},
|
|
27
|
+
isLoading,
|
|
28
|
+
isLoggedIn: auth === null || auth === void 0 ? void 0 : auth.isLoggedIn
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.useAuth = useAuth;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ProviderHint, Scope } from '@hellocoop/types';
|
|
3
|
+
import { Button } from '@hellocoop/types';
|
|
4
|
+
interface CommonButtonProps {
|
|
5
|
+
label?: string;
|
|
6
|
+
onClick?: any;
|
|
7
|
+
style?: any;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
showLoader?: boolean;
|
|
10
|
+
color?: Button.Color;
|
|
11
|
+
theme?: Button.Theme;
|
|
12
|
+
hover?: Button.Hover;
|
|
13
|
+
targetURI?: string;
|
|
14
|
+
providerHint?: ProviderHint[] | string;
|
|
15
|
+
}
|
|
16
|
+
export interface BaseButtonProps extends CommonButtonProps {
|
|
17
|
+
scope?: Scope[] | string;
|
|
18
|
+
updateScope?: Button.UpdateScope;
|
|
19
|
+
}
|
|
20
|
+
export interface LoginButtonProps extends CommonButtonProps {
|
|
21
|
+
scope?: Scope[] | string;
|
|
22
|
+
}
|
|
23
|
+
export interface UpdateButtonProps extends CommonButtonProps {
|
|
24
|
+
updateScope?: Button.UpdateScope;
|
|
25
|
+
}
|
|
26
|
+
export declare function ContinueButton(props: LoginButtonProps): React.JSX.Element;
|
|
27
|
+
export declare function LoginButton(props: LoginButtonProps): React.JSX.Element;
|
|
28
|
+
export declare function UpdateEmailButton(props: UpdateButtonProps): React.JSX.Element;
|
|
29
|
+
export declare function UpdatePictureButton(props: UpdateButtonProps): React.JSX.Element;
|
|
30
|
+
export declare function UpdateDiscordButton(props: UpdateButtonProps): React.JSX.Element;
|
|
31
|
+
export declare function UpdateTwitterButton(props: UpdateButtonProps): React.JSX.Element;
|
|
32
|
+
export declare function UpdateGitHubButton(props: UpdateButtonProps): React.JSX.Element;
|
|
33
|
+
export declare function UpdateGitLabButton(props: UpdateButtonProps): React.JSX.Element;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=buttons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buttons.d.ts","sourceRoot":"","sources":["../src/buttons.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAMzC,UAAU,iBAAiB;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;CACzC;AAED,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACtD,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC,WAAW,CAAA;CACnC;AAED,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACvD,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC,WAAW,CAAA;CACnC;AAyDD,wBAAgB,cAAc,CAAC,KAAK,EAAE,gBAAgB,qBAErD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,qBAElD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,qBAEzD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,qBAE3D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,qBAE3D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,qBAE3D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,qBAE1D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,qBAE1D"}
|
package/dist/buttons.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.UpdateGitLabButton = exports.UpdateGitHubButton = exports.UpdateTwitterButton = exports.UpdateDiscordButton = exports.UpdatePictureButton = exports.UpdateEmailButton = exports.LoginButton = exports.ContinueButton = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
const types_1 = require("@hellocoop/types");
|
|
29
|
+
const provider_1 = require("./provider");
|
|
30
|
+
let checkedForStylesheet = false;
|
|
31
|
+
function BaseButton({ scope, updateScope, targetURI, providerHint, label, style, color = "black", theme = "ignore-light", hover = "pop", showLoader = false, disabled = false }) {
|
|
32
|
+
var _a;
|
|
33
|
+
//check if dev has added Hellō stylesheet to pages with Hellō buttons
|
|
34
|
+
if (!checkedForStylesheet) {
|
|
35
|
+
const hasStylesheet = typeof document != 'undefined' && !Array.from(document.head.getElementsByTagName('link')).find((element) => {
|
|
36
|
+
var _a;
|
|
37
|
+
return element.getAttribute('rel') === 'stylesheet' &&
|
|
38
|
+
((_a = element.getAttribute('href')) === null || _a === void 0 ? void 0 : _a.startsWith(types_1.Button.STYLES_URL));
|
|
39
|
+
});
|
|
40
|
+
if (!hasStylesheet)
|
|
41
|
+
console.info('Could not find Hellō stylesheet. Please add to pages with Hellō buttons. See http://hello.dev/docs/buttons/#stylesheet for more info.');
|
|
42
|
+
checkedForStylesheet = true;
|
|
43
|
+
}
|
|
44
|
+
const helloBtnClass = (_a = types_1.Button.CLASS_MAPPING[color]) === null || _a === void 0 ? void 0 : _a[theme];
|
|
45
|
+
const [clicked, setClicked] = (0, react_1.useState)(false);
|
|
46
|
+
const loginRoute = new URL(provider_1.routeConfig.login, window.location.origin);
|
|
47
|
+
if (scope) {
|
|
48
|
+
if (typeof scope == 'string')
|
|
49
|
+
loginRoute.searchParams.set("scope", scope);
|
|
50
|
+
else
|
|
51
|
+
loginRoute.searchParams.set("scope", scope.join(" "));
|
|
52
|
+
}
|
|
53
|
+
targetURI = targetURI || (typeof window != 'undefined' && window.location.pathname) || "";
|
|
54
|
+
//window can be undefined when running server-side
|
|
55
|
+
loginRoute.searchParams.set("target_uri", targetURI);
|
|
56
|
+
if (updateScope)
|
|
57
|
+
loginRoute.searchParams.set("scope", "profile_update " + updateScope);
|
|
58
|
+
if (providerHint) {
|
|
59
|
+
if (typeof providerHint == 'string')
|
|
60
|
+
loginRoute.searchParams.set("provider_hint", providerHint);
|
|
61
|
+
else
|
|
62
|
+
loginRoute.searchParams.set("provider_hint", providerHint.join(" "));
|
|
63
|
+
}
|
|
64
|
+
const onClickHandler = () => {
|
|
65
|
+
setClicked(true);
|
|
66
|
+
window.location.href = loginRoute.href;
|
|
67
|
+
};
|
|
68
|
+
return (react_1.default.createElement("button", { onClick: onClickHandler, disabled: disabled || clicked, style: style, className: `hello-btn ${helloBtnClass} ${types_1.Button.HOVER_MAPPING[hover]} ${(showLoader || clicked) ? 'hello-btn-loader' : ''}` }, label));
|
|
69
|
+
}
|
|
70
|
+
function ContinueButton(props) {
|
|
71
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Continue with Hell\u014D" });
|
|
72
|
+
}
|
|
73
|
+
exports.ContinueButton = ContinueButton;
|
|
74
|
+
function LoginButton(props) {
|
|
75
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Log in with Hell\u014D" });
|
|
76
|
+
}
|
|
77
|
+
exports.LoginButton = LoginButton;
|
|
78
|
+
function UpdateEmailButton(props) {
|
|
79
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Update Email with Hell\u014D", updateScope: "email", style: { width: '275px' } });
|
|
80
|
+
}
|
|
81
|
+
exports.UpdateEmailButton = UpdateEmailButton;
|
|
82
|
+
function UpdatePictureButton(props) {
|
|
83
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Update Picture with Hell\u014D", updateScope: "picture", style: { width: '275px' } });
|
|
84
|
+
}
|
|
85
|
+
exports.UpdatePictureButton = UpdatePictureButton;
|
|
86
|
+
function UpdateDiscordButton(props) {
|
|
87
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Update Discord with Hell\u014D", updateScope: "discord", style: { width: '275px' } });
|
|
88
|
+
}
|
|
89
|
+
exports.UpdateDiscordButton = UpdateDiscordButton;
|
|
90
|
+
function UpdateTwitterButton(props) {
|
|
91
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Update Twitter with Hell\u014D", updateScope: "twitter", style: { width: '275px' } });
|
|
92
|
+
}
|
|
93
|
+
exports.UpdateTwitterButton = UpdateTwitterButton;
|
|
94
|
+
function UpdateGitHubButton(props) {
|
|
95
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Update GitHub with Hell\u014D", updateScope: "github", style: { width: '275px' } });
|
|
96
|
+
}
|
|
97
|
+
exports.UpdateGitHubButton = UpdateGitHubButton;
|
|
98
|
+
function UpdateGitLabButton(props) {
|
|
99
|
+
return react_1.default.createElement(BaseButton, { ...props, label: "\u014D\u00A0\u00A0\u00A0Update GitLab with Hell\u014D", updateScope: "gitlab", style: { width: '275px' } });
|
|
100
|
+
}
|
|
101
|
+
exports.UpdateGitLabButton = UpdateGitLabButton;
|
|
102
|
+
//TBD
|
|
103
|
+
// export function UpdateProfileButton() {
|
|
104
|
+
// return <UpdateBaseButton label="ō Update Picture with Hellō" updateScope="profile" />
|
|
105
|
+
// }
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./auth"), exports);
|
|
18
|
+
__exportStar(require("./buttons"), exports);
|
|
19
|
+
__exportStar(require("./login-status"), exports);
|
|
20
|
+
__exportStar(require("./logout"), exports);
|
|
21
|
+
__exportStar(require("./provider"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-status.d.ts","sourceRoot":"","sources":["../src/login-status.tsx"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAC,GAAG,CAAA;CAAE,OAGtD;AAED,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAC,GAAG,CAAA;CAAE,OAGvD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggedOut = exports.LoggedIn = void 0;
|
|
4
|
+
const auth_1 = require("./auth");
|
|
5
|
+
const isLoggedIn = () => { var _a; return ((_a = (0, auth_1.useAuth)()) === null || _a === void 0 ? void 0 : _a.isLoggedIn) || false; };
|
|
6
|
+
function LoggedIn({ children }) {
|
|
7
|
+
if (isLoggedIn())
|
|
8
|
+
return children;
|
|
9
|
+
}
|
|
10
|
+
exports.LoggedIn = LoggedIn;
|
|
11
|
+
function LoggedOut({ children }) {
|
|
12
|
+
if (!isLoggedIn())
|
|
13
|
+
return children;
|
|
14
|
+
}
|
|
15
|
+
exports.LoggedOut = LoggedOut;
|
package/dist/logout.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../src/logout.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,cAA2B,CAAA;AAEtD,wBAAgB,MAAM,SAErB"}
|
package/dist/logout.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logOut = exports.getLogOutRoute = void 0;
|
|
4
|
+
const provider_1 = require("./provider");
|
|
5
|
+
const getLogOutRoute = () => provider_1.routeConfig.logout;
|
|
6
|
+
exports.getLogOutRoute = getLogOutRoute;
|
|
7
|
+
function logOut() {
|
|
8
|
+
window.location.href = provider_1.routeConfig.logout;
|
|
9
|
+
}
|
|
10
|
+
exports.logOut = logOut;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type RouteConfig = {
|
|
3
|
+
login: string;
|
|
4
|
+
auth: string;
|
|
5
|
+
logout: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const routeConfig: RouteConfig;
|
|
8
|
+
declare const HelloProvider: ({ children, auth, config }: any) => React.JSX.Element;
|
|
9
|
+
declare const useHelloProviderContext: () => undefined;
|
|
10
|
+
export { HelloProvider, useHelloProviderContext };
|
|
11
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AACD,eAAO,MAAM,WAAW,EAAE,WAIzB,CAAA;AAKD,QAAA,MAAM,aAAa,+BAAgC,GAAG,sBASrD,CAAA;AAED,QAAA,MAAM,uBAAuB,iBAE5B,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.useHelloProviderContext = exports.HelloProvider = exports.routeConfig = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
exports.routeConfig = {
|
|
29
|
+
login: '/api/hellocoop?login=true',
|
|
30
|
+
auth: '/api/hellocoop?auth=true',
|
|
31
|
+
logout: '/api/hellocoop?logout=true',
|
|
32
|
+
};
|
|
33
|
+
const HelloContext = (0, react_1.createContext)(undefined);
|
|
34
|
+
const HelloProvider = ({ children, auth, config }) => {
|
|
35
|
+
if (config === null || config === void 0 ? void 0 : config.login)
|
|
36
|
+
exports.routeConfig.login = config.login;
|
|
37
|
+
if (config === null || config === void 0 ? void 0 : config.auth)
|
|
38
|
+
exports.routeConfig.auth = config.auth;
|
|
39
|
+
if (config === null || config === void 0 ? void 0 : config.logout)
|
|
40
|
+
exports.routeConfig.logout = config.logout;
|
|
41
|
+
return (react_1.default.createElement(HelloContext.Provider, { value: auth }, children));
|
|
42
|
+
};
|
|
43
|
+
exports.HelloProvider = HelloProvider;
|
|
44
|
+
const useHelloProviderContext = () => {
|
|
45
|
+
return (0, react_1.useContext)(HelloContext);
|
|
46
|
+
};
|
|
47
|
+
exports.useHelloProviderContext = useHelloProviderContext;
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hellocoop/react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React SDK for Hellō https://hello.dev",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/hellocoop/packages.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://www.hello.dev/docs/sdks/react",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"reactjs",
|
|
17
|
+
"react",
|
|
18
|
+
"react.js",
|
|
19
|
+
"hello",
|
|
20
|
+
"openid",
|
|
21
|
+
"oidc",
|
|
22
|
+
"sso"
|
|
23
|
+
],
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Hello Identity Co-op",
|
|
26
|
+
"email": "contact@hello.coop",
|
|
27
|
+
"url": "https://hello.coop"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/hellocoop/packages/issues"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"watch": "tsc --watch --declaration",
|
|
35
|
+
"build": "npm run build:clean && npm run build:src",
|
|
36
|
+
"build:clean": "rimraf dist/",
|
|
37
|
+
"build:src": "tsc --declaration"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": ">=17",
|
|
41
|
+
"react-dom": ">=17"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/react": "^18.2.21",
|
|
45
|
+
"react": "^18.2.0",
|
|
46
|
+
"react-dom": "^18.2.0",
|
|
47
|
+
"rimraf": "^5.0.1",
|
|
48
|
+
"typescript": "^5.2.2"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"swr": "^2.2.2"
|
|
55
|
+
}
|
|
56
|
+
}
|