@insforge/shared 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/README.md +62 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +11 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +17 -0
- package/dist/react.d.ts +17 -0
- package/dist/react.js +9 -0
- package/dist/react.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @insforge/shared
|
|
2
|
+
|
|
3
|
+
Shared utilities, types, and React contexts for Insforge packages.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This package centralizes React Context definitions to prevent duplication issues when using `tsup` with multiple entry points. By defining contexts here, all Insforge packages (`@insforge/react`, `@insforge/nextjs`, etc.) import from the same source, ensuring a single Context instance.
|
|
8
|
+
|
|
9
|
+
## Architecture Pattern
|
|
10
|
+
|
|
11
|
+
Inspired by `@clerk/shared`, this package solves the Context duplication problem:
|
|
12
|
+
|
|
13
|
+
### The Problem
|
|
14
|
+
|
|
15
|
+
When using `bundle: true` with multiple entry points:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// tsup.config.ts
|
|
19
|
+
entry: {
|
|
20
|
+
index: 'src/index.ts',
|
|
21
|
+
hooks: 'src/hooks/index.ts',
|
|
22
|
+
components: 'src/components/index.ts'
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Each entry point bundles its own copy of Context → Provider uses Context instance A, but components use Context instance B → `useContext` returns `undefined`.
|
|
27
|
+
|
|
28
|
+
### The Solution
|
|
29
|
+
|
|
30
|
+
1. **Centralized Context**: Define all Contexts in `@insforge/shared`
|
|
31
|
+
2. **External React**: Mark `react` as external in tsup config
|
|
32
|
+
3. **Shared Import**: All packages import Context from `@insforge/shared`
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// packages/shared/tsup.config.ts
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
external: ['react', 'react-dom'], // Critical!
|
|
38
|
+
bundle: true,
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Exports
|
|
43
|
+
|
|
44
|
+
### Main Entry (`@insforge/shared`)
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import type { InsforgeUser, InsforgeContextValue, OAuthProvider } from '@insforge/shared';
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### React Entry (`@insforge/shared/react`)
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { InsforgeContext } from '@insforge/shared/react';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
This package is intended for internal use within the Insforge monorepo. Application developers should not need to import from it directly.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { UserSchema } from '@insforge/sdk';
|
|
2
|
+
import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse } from '@insforge/shared-schemas';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Insforge User type
|
|
6
|
+
*/
|
|
7
|
+
interface InsforgeUser {
|
|
8
|
+
id: string;
|
|
9
|
+
email: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
avatarUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* OAuth Provider type - re-export from shared-schemas
|
|
15
|
+
*/
|
|
16
|
+
type OAuthProvider = OAuthProvidersSchema;
|
|
17
|
+
/**
|
|
18
|
+
* Context value interface for InsforgeContext
|
|
19
|
+
*/
|
|
20
|
+
interface InsforgeContextValue {
|
|
21
|
+
user: InsforgeUser | null;
|
|
22
|
+
isLoaded: boolean;
|
|
23
|
+
isSignedIn: boolean;
|
|
24
|
+
setUser: (user: InsforgeUser | null) => void;
|
|
25
|
+
signIn: (email: string, password: string) => Promise<CreateSessionResponse | {
|
|
26
|
+
error: string;
|
|
27
|
+
statusCode?: number;
|
|
28
|
+
errorCode?: string;
|
|
29
|
+
}>;
|
|
30
|
+
signUp: (email: string, password: string) => Promise<CreateUserResponse | {
|
|
31
|
+
error: string;
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
errorCode?: string;
|
|
34
|
+
}>;
|
|
35
|
+
signOut: () => Promise<void>;
|
|
36
|
+
updateUser: (data: Partial<InsforgeUser>) => Promise<{
|
|
37
|
+
error: string;
|
|
38
|
+
} | null>;
|
|
39
|
+
reloadAuth: () => Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
error?: string;
|
|
42
|
+
}>;
|
|
43
|
+
sendVerificationEmail: (email: string) => Promise<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
message: string;
|
|
46
|
+
} | null>;
|
|
47
|
+
sendResetPasswordEmail: (email: string) => Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
message: string;
|
|
50
|
+
} | null>;
|
|
51
|
+
resetPassword: (token: string, newPassword: string) => Promise<ResetPasswordResponse | null>;
|
|
52
|
+
verifyEmail: (otp: string, email?: string) => Promise<{
|
|
53
|
+
accessToken: string;
|
|
54
|
+
user?: UserSchema;
|
|
55
|
+
redirectTo?: string;
|
|
56
|
+
error?: {
|
|
57
|
+
message: string;
|
|
58
|
+
};
|
|
59
|
+
} | null>;
|
|
60
|
+
exchangeResetPasswordToken: (email: string, code: string) => Promise<{
|
|
61
|
+
token: string;
|
|
62
|
+
expiresAt?: string;
|
|
63
|
+
} | {
|
|
64
|
+
error: {
|
|
65
|
+
message: string;
|
|
66
|
+
};
|
|
67
|
+
}>;
|
|
68
|
+
loginWithOAuth: (provider: OAuthProvider, redirectTo: string) => Promise<void>;
|
|
69
|
+
getPublicAuthConfig: () => Promise<GetPublicAuthConfigResponse | null>;
|
|
70
|
+
baseUrl: string;
|
|
71
|
+
afterSignInUrl: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type { InsforgeContextValue, InsforgeUser, OAuthProvider };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { UserSchema } from '@insforge/sdk';
|
|
2
|
+
import { CreateSessionResponse, CreateUserResponse, ResetPasswordResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse } from '@insforge/shared-schemas';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Insforge User type
|
|
6
|
+
*/
|
|
7
|
+
interface InsforgeUser {
|
|
8
|
+
id: string;
|
|
9
|
+
email: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
avatarUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* OAuth Provider type - re-export from shared-schemas
|
|
15
|
+
*/
|
|
16
|
+
type OAuthProvider = OAuthProvidersSchema;
|
|
17
|
+
/**
|
|
18
|
+
* Context value interface for InsforgeContext
|
|
19
|
+
*/
|
|
20
|
+
interface InsforgeContextValue {
|
|
21
|
+
user: InsforgeUser | null;
|
|
22
|
+
isLoaded: boolean;
|
|
23
|
+
isSignedIn: boolean;
|
|
24
|
+
setUser: (user: InsforgeUser | null) => void;
|
|
25
|
+
signIn: (email: string, password: string) => Promise<CreateSessionResponse | {
|
|
26
|
+
error: string;
|
|
27
|
+
statusCode?: number;
|
|
28
|
+
errorCode?: string;
|
|
29
|
+
}>;
|
|
30
|
+
signUp: (email: string, password: string) => Promise<CreateUserResponse | {
|
|
31
|
+
error: string;
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
errorCode?: string;
|
|
34
|
+
}>;
|
|
35
|
+
signOut: () => Promise<void>;
|
|
36
|
+
updateUser: (data: Partial<InsforgeUser>) => Promise<{
|
|
37
|
+
error: string;
|
|
38
|
+
} | null>;
|
|
39
|
+
reloadAuth: () => Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
error?: string;
|
|
42
|
+
}>;
|
|
43
|
+
sendVerificationEmail: (email: string) => Promise<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
message: string;
|
|
46
|
+
} | null>;
|
|
47
|
+
sendResetPasswordEmail: (email: string) => Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
message: string;
|
|
50
|
+
} | null>;
|
|
51
|
+
resetPassword: (token: string, newPassword: string) => Promise<ResetPasswordResponse | null>;
|
|
52
|
+
verifyEmail: (otp: string, email?: string) => Promise<{
|
|
53
|
+
accessToken: string;
|
|
54
|
+
user?: UserSchema;
|
|
55
|
+
redirectTo?: string;
|
|
56
|
+
error?: {
|
|
57
|
+
message: string;
|
|
58
|
+
};
|
|
59
|
+
} | null>;
|
|
60
|
+
exchangeResetPasswordToken: (email: string, code: string) => Promise<{
|
|
61
|
+
token: string;
|
|
62
|
+
expiresAt?: string;
|
|
63
|
+
} | {
|
|
64
|
+
error: {
|
|
65
|
+
message: string;
|
|
66
|
+
};
|
|
67
|
+
}>;
|
|
68
|
+
loginWithOAuth: (provider: OAuthProvider, redirectTo: string) => Promise<void>;
|
|
69
|
+
getPublicAuthConfig: () => Promise<GetPublicAuthConfigResponse | null>;
|
|
70
|
+
baseUrl: string;
|
|
71
|
+
afterSignInUrl: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type { InsforgeContextValue, InsforgeUser, OAuthProvider };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
// src/react/contexts.tsx
|
|
6
|
+
var InsforgeContext = react.createContext(void 0);
|
|
7
|
+
InsforgeContext.displayName = "InsforgeContext";
|
|
8
|
+
|
|
9
|
+
exports.InsforgeContext = InsforgeContext;
|
|
10
|
+
//# sourceMappingURL=react.cjs.map
|
|
11
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/contexts.tsx"],"names":["createContext"],"mappings":";;;;;AAYO,IAAM,eAAA,GAAkBA,oBAAgD,MAAS;AACxF,eAAA,CAAgB,WAAA,GAAc,iBAAA","file":"react.cjs","sourcesContent":["import { createContext } from 'react';\nimport type { InsforgeContextValue } from '../types';\n\n/**\n * InsforgeContext - The single source of truth for authentication state\n *\n * This Context is defined in @insforge/shared to prevent duplication across\n * multiple tsup entry points. All packages (@insforge/react, @insforge/nextjs, etc.)\n * import this Context definition, ensuring there's only ONE Context instance.\n *\n * Pattern learned from @clerk/shared\n */\nexport const InsforgeContext = createContext<InsforgeContextValue | undefined>(undefined);\nInsforgeContext.displayName = 'InsforgeContext';\n"]}
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { InsforgeContextValue } from './index.cjs';
|
|
3
|
+
import '@insforge/sdk';
|
|
4
|
+
import '@insforge/shared-schemas';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* InsforgeContext - The single source of truth for authentication state
|
|
8
|
+
*
|
|
9
|
+
* This Context is defined in @insforge/shared to prevent duplication across
|
|
10
|
+
* multiple tsup entry points. All packages (@insforge/react, @insforge/nextjs, etc.)
|
|
11
|
+
* import this Context definition, ensuring there's only ONE Context instance.
|
|
12
|
+
*
|
|
13
|
+
* Pattern learned from @clerk/shared
|
|
14
|
+
*/
|
|
15
|
+
declare const InsforgeContext: react.Context<InsforgeContextValue | undefined>;
|
|
16
|
+
|
|
17
|
+
export { InsforgeContext };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { InsforgeContextValue } from './index.js';
|
|
3
|
+
import '@insforge/sdk';
|
|
4
|
+
import '@insforge/shared-schemas';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* InsforgeContext - The single source of truth for authentication state
|
|
8
|
+
*
|
|
9
|
+
* This Context is defined in @insforge/shared to prevent duplication across
|
|
10
|
+
* multiple tsup entry points. All packages (@insforge/react, @insforge/nextjs, etc.)
|
|
11
|
+
* import this Context definition, ensuring there's only ONE Context instance.
|
|
12
|
+
*
|
|
13
|
+
* Pattern learned from @clerk/shared
|
|
14
|
+
*/
|
|
15
|
+
declare const InsforgeContext: react.Context<InsforgeContextValue | undefined>;
|
|
16
|
+
|
|
17
|
+
export { InsforgeContext };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/react/contexts.tsx
|
|
4
|
+
var InsforgeContext = createContext(void 0);
|
|
5
|
+
InsforgeContext.displayName = "InsforgeContext";
|
|
6
|
+
|
|
7
|
+
export { InsforgeContext };
|
|
8
|
+
//# sourceMappingURL=react.js.map
|
|
9
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/contexts.tsx"],"names":[],"mappings":";;;AAYO,IAAM,eAAA,GAAkB,cAAgD,MAAS;AACxF,eAAA,CAAgB,WAAA,GAAc,iBAAA","file":"react.js","sourcesContent":["import { createContext } from 'react';\nimport type { InsforgeContextValue } from '../types';\n\n/**\n * InsforgeContext - The single source of truth for authentication state\n *\n * This Context is defined in @insforge/shared to prevent duplication across\n * multiple tsup entry points. All packages (@insforge/react, @insforge/nextjs, etc.)\n * import this Context definition, ensuring there's only ONE Context instance.\n *\n * Pattern learned from @clerk/shared\n */\nexport const InsforgeContext = createContext<InsforgeContextValue | undefined>(undefined);\nInsforgeContext.displayName = 'InsforgeContext';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@insforge/shared",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared utilities and React contexts for Insforge packages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"types": "./dist/react.d.ts",
|
|
17
|
+
"import": "./dist/react.js",
|
|
18
|
+
"require": "./dist/react.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"type-check": "tsc --noEmit",
|
|
29
|
+
"clean": "rimraf dist"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"insforge",
|
|
33
|
+
"shared",
|
|
34
|
+
"react",
|
|
35
|
+
"context"
|
|
36
|
+
],
|
|
37
|
+
"author": "Insforge",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^19.0.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@insforge/sdk": "^0.0.58",
|
|
44
|
+
"@insforge/shared-schemas": "^1.1.19"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/react": "^19.2.2"
|
|
48
|
+
}
|
|
49
|
+
}
|