@insforge/shared 1.1.1 → 1.1.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 +62 -62
- package/dist/react.cjs.map +1 -1
- package/dist/react.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,62 +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
|
|
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/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/contexts.tsx"],"names":["createContext"],"mappings":";;;;;AAmBO,IAAM,eAAA,GAAkBA,oBAAgD,MAAS;AACxF,eAAA,CAAgB,WAAA,GAAc,iBAAA;AAQvB,IAAM,wBAAA,GAA2BA,oBAA6C,MAAS;AAC9F,wBAAA,CAAyB,WAAA,GAAc,0BAAA;AAYhC,IAAM,sBAAA,GAAyBA,oBAA+C,MAAS;AAC9F,sBAAA,CAAuB,WAAA,GAAc,wBAAA;AAQ9B,IAAM,qBAAA,GAAwBA,oBAA8C,MAAS;AAC5F,qBAAA,CAAsB,WAAA,GAAc,uBAAA","file":"react.cjs","sourcesContent":["import { createContext } from 'react';\
|
|
1
|
+
{"version":3,"sources":["../src/react/contexts.tsx"],"names":["createContext"],"mappings":";;;;;AAmBO,IAAM,eAAA,GAAkBA,oBAAgD,MAAS;AACxF,eAAA,CAAgB,WAAA,GAAc,iBAAA;AAQvB,IAAM,wBAAA,GAA2BA,oBAA6C,MAAS;AAC9F,wBAAA,CAAyB,WAAA,GAAc,0BAAA;AAYhC,IAAM,sBAAA,GAAyBA,oBAA+C,MAAS;AAC9F,sBAAA,CAAuB,WAAA,GAAc,wBAAA;AAQ9B,IAAM,qBAAA,GAAwBA,oBAA8C,MAAS;AAC5F,qBAAA,CAAsB,WAAA,GAAc,uBAAA","file":"react.cjs","sourcesContent":["import { createContext } from 'react';\nimport type {\n InsforgeContextValue,\n InsforgeAuthState,\n InsforgeAuthMethods,\n InsforgeAuthConfig,\n} 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 *\n * @deprecated Internal use only. Use useInsforge() hook instead.\n */\nexport const InsforgeContext = createContext<InsforgeContextValue | undefined>(undefined);\nInsforgeContext.displayName = 'InsforgeContext';\n\n/**\n * InsforgeAuthStateContext - Reactive auth state that changes on sign in/out\n *\n * This context holds the reactive state: user, userId, isLoaded, isSignedIn.\n * It updates when auth state changes.\n */\nexport const InsforgeAuthStateContext = createContext<InsforgeAuthState | undefined>(undefined);\nInsforgeAuthStateContext.displayName = 'InsforgeAuthStateContext';\n\n/**\n * InsforgeMethodsContext - Stable method references\n *\n * This context holds method references that NEVER change once initialized.\n * Methods like signIn, signOut, verifyEmail etc. are stored here.\n * This prevents useEffect re-runs when state changes.\n *\n * Pattern learned from @clerk/shared - they store the Clerk instance\n * in a separate context to keep method references stable.\n */\nexport const InsforgeMethodsContext = createContext<InsforgeAuthMethods | undefined>(undefined);\nInsforgeMethodsContext.displayName = 'InsforgeMethodsContext';\n\n/**\n * InsforgeConfigContext - Static configuration values\n *\n * This context holds configuration values like baseUrl, afterSignInUrl.\n * These rarely change after initialization.\n */\nexport const InsforgeConfigContext = createContext<InsforgeAuthConfig | undefined>(undefined);\nInsforgeConfigContext.displayName = 'InsforgeConfigContext';\n"]}
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/contexts.tsx"],"names":[],"mappings":";;;AAmBO,IAAM,eAAA,GAAkB,cAAgD,MAAS;AACxF,eAAA,CAAgB,WAAA,GAAc,iBAAA;AAQvB,IAAM,wBAAA,GAA2B,cAA6C,MAAS;AAC9F,wBAAA,CAAyB,WAAA,GAAc,0BAAA;AAYhC,IAAM,sBAAA,GAAyB,cAA+C,MAAS;AAC9F,sBAAA,CAAuB,WAAA,GAAc,wBAAA;AAQ9B,IAAM,qBAAA,GAAwB,cAA8C,MAAS;AAC5F,qBAAA,CAAsB,WAAA,GAAc,uBAAA","file":"react.js","sourcesContent":["import { createContext } from 'react';\
|
|
1
|
+
{"version":3,"sources":["../src/react/contexts.tsx"],"names":[],"mappings":";;;AAmBO,IAAM,eAAA,GAAkB,cAAgD,MAAS;AACxF,eAAA,CAAgB,WAAA,GAAc,iBAAA;AAQvB,IAAM,wBAAA,GAA2B,cAA6C,MAAS;AAC9F,wBAAA,CAAyB,WAAA,GAAc,0BAAA;AAYhC,IAAM,sBAAA,GAAyB,cAA+C,MAAS;AAC9F,sBAAA,CAAuB,WAAA,GAAc,wBAAA;AAQ9B,IAAM,qBAAA,GAAwB,cAA8C,MAAS;AAC5F,qBAAA,CAAsB,WAAA,GAAc,uBAAA","file":"react.js","sourcesContent":["import { createContext } from 'react';\nimport type {\n InsforgeContextValue,\n InsforgeAuthState,\n InsforgeAuthMethods,\n InsforgeAuthConfig,\n} 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 *\n * @deprecated Internal use only. Use useInsforge() hook instead.\n */\nexport const InsforgeContext = createContext<InsforgeContextValue | undefined>(undefined);\nInsforgeContext.displayName = 'InsforgeContext';\n\n/**\n * InsforgeAuthStateContext - Reactive auth state that changes on sign in/out\n *\n * This context holds the reactive state: user, userId, isLoaded, isSignedIn.\n * It updates when auth state changes.\n */\nexport const InsforgeAuthStateContext = createContext<InsforgeAuthState | undefined>(undefined);\nInsforgeAuthStateContext.displayName = 'InsforgeAuthStateContext';\n\n/**\n * InsforgeMethodsContext - Stable method references\n *\n * This context holds method references that NEVER change once initialized.\n * Methods like signIn, signOut, verifyEmail etc. are stored here.\n * This prevents useEffect re-runs when state changes.\n *\n * Pattern learned from @clerk/shared - they store the Clerk instance\n * in a separate context to keep method references stable.\n */\nexport const InsforgeMethodsContext = createContext<InsforgeAuthMethods | undefined>(undefined);\nInsforgeMethodsContext.displayName = 'InsforgeMethodsContext';\n\n/**\n * InsforgeConfigContext - Static configuration values\n *\n * This context holds configuration values like baseUrl, afterSignInUrl.\n * These rarely change after initialization.\n */\nexport const InsforgeConfigContext = createContext<InsforgeAuthConfig | undefined>(undefined);\nInsforgeConfigContext.displayName = 'InsforgeConfigContext';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insforge/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Shared utilities and React contexts for Insforge packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"react": ">=18.0.0 <20.0.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@insforge/shared-schemas": "^1.1.
|
|
43
|
+
"@insforge/shared-schemas": "^1.1.42"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/react": "^19.2.2",
|