@raystack/frontier 0.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/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @raystack/frontier
2
+
3
+ Frontier JS SDK allows you to implement authentication in your [React](https://reactjs.org/) application quickly using Magic links and social sign-in. It also allows you to access the
4
+ SignIn, SignUp, user profile, Workspace creation, Workspace Profile etc. components.
5
+
6
+ Here is a quick guide on getting started with `@raystack/frontier` package.
7
+
8
+ ## Step 1 - Create Instance
9
+
10
+ Get Frontier URL by instantiating [Frontier instance](https://github.com/odpf/frontier)
11
+ .
12
+
13
+ ## Step 2 - Install package
14
+
15
+ Install `@raystack/frontier` library
16
+
17
+ ```sh
18
+ npm i --save @raystack/frontier
19
+ OR
20
+ yarn add @raystack/frontier
21
+ ```
22
+
23
+ ## Step 3 - Configure Provider and use Frontier Components
24
+
25
+ Frontier comes with [react context](https://reactjs.org/docs/context.html) which serves as `Provider` component for the application
26
+
27
+ ```jsx
28
+ import {
29
+ FrontierProvider,
30
+ Frontier,
31
+ useFrontier
32
+ } from '@raystack/frontier/react';
33
+
34
+ const App = () => {
35
+ return (
36
+ <FrontierProvider
37
+ config={{
38
+ endpoint: 'http://localhost:3000',
39
+ redirectLogin: window.location.origin,
40
+ redirectSignup: window.location.origin,
41
+ redirectMagicLinkVerify: window.location.origin
42
+ }}
43
+ >
44
+ <SignIn />
45
+ </FrontierProvider>
46
+ );
47
+ };
48
+
49
+ const Profile = () => {
50
+ const { user } = useFrontier();
51
+ if (user) {
52
+ return <div>{user.email}</div>;
53
+ }
54
+ return null;
55
+ };
56
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,32 @@
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
+ Shield: () => Shield
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var Shield = class {
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ Shield
31
+ });
32
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./types\";\nexport class Shield {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,IAAM,SAAN,MAAa;AAAC;","names":[]}
@@ -0,0 +1,4 @@
1
+ declare class Frontier {
2
+ }
3
+
4
+ export { Frontier };
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
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
+ Frontier: () => Frontier
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var Frontier = class {
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ Frontier
31
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./types\";\nexport class Shield {}\n"],"mappings":";AACO,IAAM,SAAN,MAAa;AAAC;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ // src/index.ts
2
+ var Frontier = class {
3
+ };
4
+ export {
5
+ Frontier
6
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var shielddev = (() => {
3
+ var t = Object.defineProperty;
4
+ var c = Object.getOwnPropertyDescriptor;
5
+ var e = Object.getOwnPropertyNames;
6
+ var f = Object.prototype.hasOwnProperty;
7
+ var m = (r, o) => {
8
+ for (var s in o) t(r, s, { get: o[s], enumerable: !0 });
9
+ },
10
+ b = (r, o, s, a) => {
11
+ if ((o && typeof o == "object") || typeof o == "function")
12
+ for (let p of e(o))
13
+ !f.call(r, p) &&
14
+ p !== s &&
15
+ t(r, p, {
16
+ get: () => o[p],
17
+ enumerable: !(a = c(o, p)) || a.enumerable
18
+ });
19
+ return r;
20
+ };
21
+ var g = r => b(t({}, "__esModule", { value: !0 }), r);
22
+ var j = {};
23
+ m(j, { Shield: () => x });
24
+ var x = class {};
25
+ return g(j);
26
+ })();
27
+ window.__SHIELD__ = shielddev;
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@raystack/frontier",
3
+ "version": "0.0.0",
4
+ "description": "A js library for frontier",
5
+ "sideEffects": false,
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist/**/*",
11
+ "react/dist/**/*",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsup --watch src",
17
+ "size": "size-limit",
18
+ "lint": "eslint \"./**/*.ts*\"",
19
+ "test": "echo \"Error: no test specified\" && exit 0"
20
+ },
21
+ "author": "pyadav9678@gmail.com",
22
+ "license": "Apache-2.0",
23
+ "lint-staged": {
24
+ "*.{json,md,html,js,jsx,ts,tsx}": [
25
+ "prettier --write"
26
+ ]
27
+ },
28
+ "size-limit": [
29
+ {
30
+ "path": "dist/index.js",
31
+ "limit": "200 KB"
32
+ }
33
+ ],
34
+ "exports": {
35
+ "./package.json": "./package.json",
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.mjs",
39
+ "module": "./dist/index.mjs",
40
+ "require": "./dist/index.js"
41
+ },
42
+ "./react": {
43
+ "types": "./react/dist/index.d.ts",
44
+ "import": "./react/dist/index.mjs",
45
+ "module": "./react/dist/index.mjs",
46
+ "require": "./react/dist/index.js"
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "@raystack/frontier-tsconfig": "workspace:^",
51
+ "@size-limit/preset-small-lib": "^8.2.6",
52
+ "@types/node": "^20.4.5",
53
+ "@types/react": "^18.2.5",
54
+ "@types/react-dom": "^18.2.7",
55
+ "esbuild-plugin-external-global": "^1.0.1",
56
+ "eslint": "^7.32.0",
57
+ "eslint-config-frontier": "workspace:^",
58
+ "np": "^7.7.0",
59
+ "prettier": "^2.5.1",
60
+ "size-limit": "^8.2.6",
61
+ "tsup": "^6.7.0",
62
+ "typescript": "^5.1.6"
63
+ },
64
+ "dependencies": {
65
+ "@hookform/resolvers": "^3.1.1",
66
+ "@raystack/apsara": "^0.10.5",
67
+ "axios": "^1.4.0",
68
+ "react-hook-form": "^7.45.2",
69
+ "yup": "^1.2.0"
70
+ },
71
+ "peerDependencies": {
72
+ "react": "^18.2.0"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "react": {
76
+ "optional": true
77
+ },
78
+ "svelte": {
79
+ "optional": true
80
+ },
81
+ "vue": {
82
+ "optional": true
83
+ },
84
+ "solid-js": {
85
+ "optional": true
86
+ }
87
+ },
88
+ "publishConfig": {
89
+ "access": "public"
90
+ }
91
+ }
@@ -0,0 +1,128 @@
1
+ import * as React from 'react';
2
+ import React__default, { ComponentPropsWithRef, Dispatch, SetStateAction } from 'react';
3
+ import { AxiosInstance, AxiosResponse } from 'axios';
4
+
5
+ type ContainerProps = ComponentPropsWithRef<'div'> & {
6
+ children?: React__default.ReactNode;
7
+ shadow?: 'none' | 'xs' | 'sm' | 'md' | 'lg';
8
+ radius?: 'none' | 'xs' | 'sm' | 'md' | 'lg';
9
+ };
10
+ declare const Container: ({ children, shadow, radius, style }: ContainerProps) => JSX.Element;
11
+
12
+ type SignedInProps = ComponentPropsWithRef<typeof Container> & {
13
+ logo?: React__default.ReactNode;
14
+ title?: string;
15
+ };
16
+ declare const SignedIn: ({ logo, title, ...props }: SignedInProps) => JSX.Element;
17
+
18
+ type MagicLinkVerifyProps = ComponentPropsWithRef<typeof Container> & {
19
+ logo?: React__default.ReactNode;
20
+ title?: string;
21
+ };
22
+ declare const MagicLinkVerify: ({ logo, title, ...props }: MagicLinkVerifyProps) => JSX.Element;
23
+
24
+ type CreateOrganizationProps = ComponentPropsWithRef<typeof Container> & {
25
+ title?: string;
26
+ description?: string;
27
+ };
28
+ declare const CreateOrganization: ({ title, description, ...props }: CreateOrganizationProps) => JSX.Element;
29
+
30
+ type SignupProps = ComponentPropsWithRef<typeof Container> & {
31
+ logo?: React__default.ReactNode;
32
+ title?: string;
33
+ };
34
+ declare const Signup: ({ logo, title, ...props }: SignupProps) => JSX.Element;
35
+
36
+ interface Strategy {
37
+ name: string;
38
+ params: any;
39
+ endpoint: string;
40
+ }
41
+ interface User {
42
+ id: string;
43
+ name: string;
44
+ email: string;
45
+ createdAt: Date;
46
+ updatedAt: Date;
47
+ }
48
+ interface Group {
49
+ id: string;
50
+ name: string;
51
+ slug: string;
52
+ backend: string;
53
+ resoure_type: string;
54
+ createdAt: Date;
55
+ updatedAt: Date;
56
+ }
57
+ interface Organization {
58
+ id: string;
59
+ name: string;
60
+ slug: string;
61
+ metadata: Record<string, string>;
62
+ createdAt: Date;
63
+ updatedAt: Date;
64
+ }
65
+ interface FrontierClientOptions {
66
+ endpoint?: string;
67
+ redirectSignup?: string;
68
+ redirectLogin?: string;
69
+ redirectMagicLinkVerify?: string;
70
+ }
71
+ interface InitialState {
72
+ sessionId?: string | null;
73
+ }
74
+ interface FrontierProviderProps {
75
+ config: FrontierClientOptions;
76
+ children: React__default.ReactNode;
77
+ initialState?: InitialState;
78
+ }
79
+
80
+ declare class Frontier {
81
+ protected readonly instance: AxiosInstance;
82
+ private readonly options;
83
+ private static classInstance?;
84
+ static getOrCreateInstance(options: FrontierClientOptions): Frontier;
85
+ constructor(options: FrontierClientOptions);
86
+ getAuthAtrategies: () => Promise<AxiosResponse<{
87
+ strategies: Strategy[];
88
+ }>>;
89
+ getAuthStrategyEndpoint: (strategy: string) => Promise<AxiosResponse<{
90
+ endpoint: string;
91
+ }>>;
92
+ getMagicLinkAuthStrategyEndpoint: (email: string) => Promise<AxiosResponse<{
93
+ state: string;
94
+ }>>;
95
+ verifyMagicLinkAuthStrategyEndpoint: (code: string, state: string) => Promise<AxiosResponse<{
96
+ state: string;
97
+ }, any>>;
98
+ getCurrentUser: () => Promise<AxiosResponse<{
99
+ user: User;
100
+ }>>;
101
+ getUserGroups: (userId: string) => Promise<AxiosResponse<{
102
+ groups: Group[];
103
+ }>>;
104
+ getUserOrganisations: (userId: string) => Promise<AxiosResponse<{
105
+ organizations: Organization[];
106
+ }>>;
107
+ createOrganisation: (data: any) => Promise<AxiosResponse<{
108
+ organization: Organization;
109
+ }>>;
110
+ }
111
+
112
+ interface FrontierContextProviderProps {
113
+ config: FrontierClientOptions;
114
+ client: Frontier;
115
+ organizations: Organization[];
116
+ setOrganizations: Dispatch<SetStateAction<Organization[]>>;
117
+ groups: Group[];
118
+ setGroups: Dispatch<SetStateAction<Group[]>>;
119
+ strategies: Strategy[];
120
+ setStrategies: Dispatch<SetStateAction<Strategy[]>>;
121
+ user: User | null;
122
+ setUser: Dispatch<SetStateAction<User | null>>;
123
+ }
124
+ declare function useFrontier(): FrontierContextProviderProps;
125
+
126
+ declare const FrontierProvider: React.ComponentType<FrontierProviderProps>;
127
+
128
+ export { CreateOrganization, FrontierProvider, MagicLinkVerify, SignedIn, Signup, useFrontier };