@23blocks/sdk 1.1.2 → 2.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/index.d.ts +1 -0
- package/dist/{lib/client.js → index.esm.js} +163 -5
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lib/client.d.ts +341 -0
- package/dist/src/lib/client.d.ts.map +1 -0
- package/dist/src/lib/sdk.d.ts +24 -0
- package/dist/src/lib/sdk.d.ts.map +1 -0
- package/dist/src/lib/token-manager.d.ts +79 -0
- package/dist/src/lib/token-manager.d.ts.map +1 -0
- package/package.json +10 -8
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/lib/client.js.map +0 -1
- package/dist/lib/sdk.js +0 -34
- package/dist/lib/sdk.js.map +0 -1
- package/dist/lib/token-manager.js +0 -140
- package/dist/lib/token-manager.js.map +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -1,24 +1,182 @@
|
|
|
1
|
-
import { _
|
|
1
|
+
import { _ } from '@swc/helpers/_/_extends';
|
|
2
2
|
import { createHttpTransport } from '@23blocks/transport-http';
|
|
3
|
+
export * from '@23blocks/transport-http';
|
|
3
4
|
import { createAuthenticationBlock } from '@23blocks/block-authentication';
|
|
5
|
+
export * from '@23blocks/block-authentication';
|
|
4
6
|
import { createSearchBlock } from '@23blocks/block-search';
|
|
7
|
+
export * from '@23blocks/block-search';
|
|
5
8
|
import { createProductsBlock } from '@23blocks/block-products';
|
|
9
|
+
export * from '@23blocks/block-products';
|
|
6
10
|
import { createCrmBlock } from '@23blocks/block-crm';
|
|
11
|
+
export * from '@23blocks/block-crm';
|
|
7
12
|
import { createContentBlock } from '@23blocks/block-content';
|
|
13
|
+
export * from '@23blocks/block-content';
|
|
8
14
|
import { createGeolocationBlock } from '@23blocks/block-geolocation';
|
|
15
|
+
export * from '@23blocks/block-geolocation';
|
|
9
16
|
import { createConversationsBlock } from '@23blocks/block-conversations';
|
|
17
|
+
export * from '@23blocks/block-conversations';
|
|
10
18
|
import { createFilesBlock } from '@23blocks/block-files';
|
|
19
|
+
export * from '@23blocks/block-files';
|
|
11
20
|
import { createFormsBlock } from '@23blocks/block-forms';
|
|
21
|
+
export * from '@23blocks/block-forms';
|
|
12
22
|
import { createAssetsBlock } from '@23blocks/block-assets';
|
|
23
|
+
export * from '@23blocks/block-assets';
|
|
13
24
|
import { createCampaignsBlock } from '@23blocks/block-campaigns';
|
|
25
|
+
export * from '@23blocks/block-campaigns';
|
|
14
26
|
import { createCompanyBlock } from '@23blocks/block-company';
|
|
27
|
+
export * from '@23blocks/block-company';
|
|
15
28
|
import { createRewardsBlock } from '@23blocks/block-rewards';
|
|
29
|
+
export * from '@23blocks/block-rewards';
|
|
16
30
|
import { createSalesBlock } from '@23blocks/block-sales';
|
|
31
|
+
export * from '@23blocks/block-sales';
|
|
17
32
|
import { createWalletBlock } from '@23blocks/block-wallet';
|
|
33
|
+
export * from '@23blocks/block-wallet';
|
|
18
34
|
import { createJarvisBlock } from '@23blocks/block-jarvis';
|
|
35
|
+
export * from '@23blocks/block-jarvis';
|
|
19
36
|
import { createOnboardingBlock } from '@23blocks/block-onboarding';
|
|
37
|
+
export * from '@23blocks/block-onboarding';
|
|
20
38
|
import { createUniversityBlock } from '@23blocks/block-university';
|
|
21
|
-
|
|
39
|
+
export * from '@23blocks/block-university';
|
|
40
|
+
export * from '@23blocks/contracts';
|
|
41
|
+
export * from '@23blocks/jsonapi-codec';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generate storage key scoped to app and tenant
|
|
45
|
+
*/ function getStorageKey(type, appId, tenantId) {
|
|
46
|
+
const scope = tenantId ? `${appId}_${tenantId}` : appId;
|
|
47
|
+
return `23blocks_${scope}_${type}_token`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* In-memory token storage (for SSR or when localStorage is unavailable)
|
|
51
|
+
*/ let MemoryStorage = class MemoryStorage {
|
|
52
|
+
getItem(key) {
|
|
53
|
+
var _this_data_get;
|
|
54
|
+
return (_this_data_get = this.data.get(key)) != null ? _this_data_get : null;
|
|
55
|
+
}
|
|
56
|
+
setItem(key, value) {
|
|
57
|
+
this.data.set(key, value);
|
|
58
|
+
}
|
|
59
|
+
removeItem(key) {
|
|
60
|
+
this.data.delete(key);
|
|
61
|
+
}
|
|
62
|
+
constructor(){
|
|
63
|
+
this.data = new Map();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Detect if we're running in a browser environment
|
|
68
|
+
*/ function isBrowser$1() {
|
|
69
|
+
return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the appropriate storage backend
|
|
73
|
+
*/ function getStorage(type) {
|
|
74
|
+
if (!isBrowser$1()) {
|
|
75
|
+
// In SSR/Node, always use memory storage
|
|
76
|
+
return new MemoryStorage();
|
|
77
|
+
}
|
|
78
|
+
switch(type){
|
|
79
|
+
case 'localStorage':
|
|
80
|
+
return window.localStorage;
|
|
81
|
+
case 'sessionStorage':
|
|
82
|
+
return window.sessionStorage;
|
|
83
|
+
case 'memory':
|
|
84
|
+
return new MemoryStorage();
|
|
85
|
+
default:
|
|
86
|
+
return window.localStorage;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a token manager instance
|
|
91
|
+
*
|
|
92
|
+
* @param config - Token manager configuration including appId for scoped storage
|
|
93
|
+
* @returns A TokenManager instance
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const tokenManager = createTokenManager({
|
|
98
|
+
* appId: 'my-app',
|
|
99
|
+
* storage: 'localStorage',
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Store tokens after sign in
|
|
103
|
+
* tokenManager.setTokens('access_token_value', 'refresh_token_value');
|
|
104
|
+
*
|
|
105
|
+
* // Get token for API requests
|
|
106
|
+
* const token = tokenManager.getAccessToken();
|
|
107
|
+
*
|
|
108
|
+
* // Clear on sign out
|
|
109
|
+
* tokenManager.clearTokens();
|
|
110
|
+
*
|
|
111
|
+
* // Listen for cross-tab changes
|
|
112
|
+
* const unsubscribe = tokenManager.onStorageChange(() => {
|
|
113
|
+
* console.log('Tokens changed in another tab');
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*/ function createTokenManager(config) {
|
|
117
|
+
const { appId, tenantId, storage: storageType = 'localStorage' } = config;
|
|
118
|
+
const storage = getStorage(storageType);
|
|
119
|
+
const accessTokenKey = getStorageKey('access', appId, tenantId);
|
|
120
|
+
const refreshTokenKey = getStorageKey('refresh', appId, tenantId);
|
|
121
|
+
// Track storage event listeners for cleanup
|
|
122
|
+
const listeners = new Set();
|
|
123
|
+
return {
|
|
124
|
+
getAccessToken () {
|
|
125
|
+
try {
|
|
126
|
+
return storage.getItem(accessTokenKey);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
getRefreshToken () {
|
|
132
|
+
try {
|
|
133
|
+
return storage.getItem(refreshTokenKey);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
setTokens (accessToken, refreshToken) {
|
|
139
|
+
try {
|
|
140
|
+
storage.setItem(accessTokenKey, accessToken);
|
|
141
|
+
if (refreshToken) {
|
|
142
|
+
storage.setItem(refreshTokenKey, refreshToken);
|
|
143
|
+
}
|
|
144
|
+
} catch (e) {
|
|
145
|
+
// Storage might be full or disabled, silently fail
|
|
146
|
+
console.warn('[23blocks] Unable to store tokens');
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
clearTokens () {
|
|
150
|
+
try {
|
|
151
|
+
storage.removeItem(accessTokenKey);
|
|
152
|
+
storage.removeItem(refreshTokenKey);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
// Silently fail
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
onStorageChange (callback) {
|
|
158
|
+
// Only works in browser with localStorage/sessionStorage
|
|
159
|
+
if (!isBrowser$1() || storageType === 'memory') {
|
|
160
|
+
// Return no-op unsubscribe for SSR/memory storage
|
|
161
|
+
return ()=>{};
|
|
162
|
+
}
|
|
163
|
+
const handler = (event)=>{
|
|
164
|
+
// Only trigger if our keys changed
|
|
165
|
+
if (event.key === accessTokenKey || event.key === refreshTokenKey) {
|
|
166
|
+
callback();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
window.addEventListener('storage', handler);
|
|
170
|
+
listeners.add(callback);
|
|
171
|
+
// Return unsubscribe function
|
|
172
|
+
return ()=>{
|
|
173
|
+
window.removeEventListener('storage', handler);
|
|
174
|
+
listeners.delete(callback);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
22
180
|
/**
|
|
23
181
|
* Detect browser environment
|
|
24
182
|
*/ function isBrowser() {
|
|
@@ -76,7 +234,7 @@ import { createTokenManager } from './token-manager.js';
|
|
|
76
234
|
* },
|
|
77
235
|
* });
|
|
78
236
|
* ```
|
|
79
|
-
*/
|
|
237
|
+
*/ function create23BlocksClient(config) {
|
|
80
238
|
const { urls, appId, tenantId, authMode = 'token', storage = isBrowser() ? 'localStorage' : 'memory', headers: staticHeaders = {}, timeout } = config;
|
|
81
239
|
// Create token manager for token mode
|
|
82
240
|
let tokenManager = null;
|
|
@@ -94,7 +252,7 @@ import { createTokenManager } from './token-manager.js';
|
|
|
94
252
|
timeout,
|
|
95
253
|
credentials: authMode === 'cookie' ? 'include' : undefined,
|
|
96
254
|
headers: ()=>{
|
|
97
|
-
const headers =
|
|
255
|
+
const headers = _({}, staticHeaders, {
|
|
98
256
|
appid: appId
|
|
99
257
|
});
|
|
100
258
|
if (tenantId) {
|
|
@@ -244,4 +402,4 @@ import { createTokenManager } from './token-manager.js';
|
|
|
244
402
|
};
|
|
245
403
|
}
|
|
246
404
|
|
|
247
|
-
|
|
405
|
+
export { create23BlocksClient, createTokenManager };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { type AuthenticationBlock, type SignInRequest, type SignInResponse, type SignUpRequest, type SignUpResponse, type MagicLinkVerifyRequest, type AcceptInvitationRequest } from '@23blocks/block-authentication';
|
|
2
|
+
import { type SearchBlock } from '@23blocks/block-search';
|
|
3
|
+
import { type ProductsBlock } from '@23blocks/block-products';
|
|
4
|
+
import { type CrmBlock } from '@23blocks/block-crm';
|
|
5
|
+
import { type ContentBlock } from '@23blocks/block-content';
|
|
6
|
+
import { type GeolocationBlock } from '@23blocks/block-geolocation';
|
|
7
|
+
import { type ConversationsBlock } from '@23blocks/block-conversations';
|
|
8
|
+
import { type FilesBlock } from '@23blocks/block-files';
|
|
9
|
+
import { type FormsBlock } from '@23blocks/block-forms';
|
|
10
|
+
import { type AssetsBlock } from '@23blocks/block-assets';
|
|
11
|
+
import { type CampaignsBlock } from '@23blocks/block-campaigns';
|
|
12
|
+
import { type CompanyBlock } from '@23blocks/block-company';
|
|
13
|
+
import { type RewardsBlock } from '@23blocks/block-rewards';
|
|
14
|
+
import { type SalesBlock } from '@23blocks/block-sales';
|
|
15
|
+
import { type WalletBlock } from '@23blocks/block-wallet';
|
|
16
|
+
import { type JarvisBlock } from '@23blocks/block-jarvis';
|
|
17
|
+
import { type OnboardingBlock } from '@23blocks/block-onboarding';
|
|
18
|
+
import { type UniversityBlock } from '@23blocks/block-university';
|
|
19
|
+
import { type StorageType } from './token-manager.js';
|
|
20
|
+
/**
|
|
21
|
+
* Authentication mode
|
|
22
|
+
* - 'token': Store tokens in browser storage, attach Authorization header
|
|
23
|
+
* - 'cookie': Use httpOnly cookies set by backend (recommended for new projects)
|
|
24
|
+
*/
|
|
25
|
+
export type AuthMode = 'token' | 'cookie';
|
|
26
|
+
/**
|
|
27
|
+
* Service URL configuration - each microservice has its own URL.
|
|
28
|
+
* All URLs are optional - only configure the services you need.
|
|
29
|
+
*/
|
|
30
|
+
export interface ServiceUrls {
|
|
31
|
+
/** Authentication service URL */
|
|
32
|
+
authentication?: string;
|
|
33
|
+
/** Search service URL */
|
|
34
|
+
search?: string;
|
|
35
|
+
/** Products service URL */
|
|
36
|
+
products?: string;
|
|
37
|
+
/** CRM service URL */
|
|
38
|
+
crm?: string;
|
|
39
|
+
/** Content service URL */
|
|
40
|
+
content?: string;
|
|
41
|
+
/** Geolocation service URL */
|
|
42
|
+
geolocation?: string;
|
|
43
|
+
/** Conversations service URL */
|
|
44
|
+
conversations?: string;
|
|
45
|
+
/** Files service URL */
|
|
46
|
+
files?: string;
|
|
47
|
+
/** Forms service URL */
|
|
48
|
+
forms?: string;
|
|
49
|
+
/** Assets service URL */
|
|
50
|
+
assets?: string;
|
|
51
|
+
/** Campaigns service URL */
|
|
52
|
+
campaigns?: string;
|
|
53
|
+
/** Company service URL */
|
|
54
|
+
company?: string;
|
|
55
|
+
/** Rewards service URL */
|
|
56
|
+
rewards?: string;
|
|
57
|
+
/** Sales service URL */
|
|
58
|
+
sales?: string;
|
|
59
|
+
/** Wallet service URL */
|
|
60
|
+
wallet?: string;
|
|
61
|
+
/** Jarvis (AI) service URL */
|
|
62
|
+
jarvis?: string;
|
|
63
|
+
/** Onboarding service URL */
|
|
64
|
+
onboarding?: string;
|
|
65
|
+
/** University (LMS) service URL */
|
|
66
|
+
university?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Client configuration
|
|
70
|
+
*/
|
|
71
|
+
export interface ClientConfig {
|
|
72
|
+
/**
|
|
73
|
+
* Service URLs for each microservice.
|
|
74
|
+
* Only configure the services you need - accessing a service without
|
|
75
|
+
* a configured URL will throw an error.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* urls: {
|
|
80
|
+
* authentication: 'https://gateway.23blocks.com',
|
|
81
|
+
* crm: 'https://crm.23blocks.com',
|
|
82
|
+
* products: 'https://products.23blocks.com',
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
urls: ServiceUrls;
|
|
87
|
+
/**
|
|
88
|
+
* Application ID
|
|
89
|
+
*/
|
|
90
|
+
appId: string;
|
|
91
|
+
/**
|
|
92
|
+
* Tenant ID (optional, for multi-tenant setups)
|
|
93
|
+
*/
|
|
94
|
+
tenantId?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Authentication mode
|
|
97
|
+
* - 'token' (default): SDK stores tokens in localStorage/sessionStorage/memory
|
|
98
|
+
* - 'cookie': Backend manages auth via httpOnly cookies
|
|
99
|
+
*/
|
|
100
|
+
authMode?: AuthMode;
|
|
101
|
+
/**
|
|
102
|
+
* Storage type for token mode
|
|
103
|
+
* Only applicable when authMode is 'token'
|
|
104
|
+
* @default 'localStorage' in browser, 'memory' in SSR
|
|
105
|
+
*/
|
|
106
|
+
storage?: StorageType;
|
|
107
|
+
/**
|
|
108
|
+
* Additional headers to include with every request
|
|
109
|
+
* Useful for SSR cookie forwarding
|
|
110
|
+
*/
|
|
111
|
+
headers?: Record<string, string>;
|
|
112
|
+
/**
|
|
113
|
+
* Request timeout in milliseconds
|
|
114
|
+
* @default 30000
|
|
115
|
+
*/
|
|
116
|
+
timeout?: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Auth service wrapper with automatic token management
|
|
120
|
+
*/
|
|
121
|
+
export interface ManagedAuthService extends Omit<AuthenticationBlock['auth'], 'signIn' | 'signUp' | 'signOut' | 'verifyMagicLink' | 'acceptInvitation'> {
|
|
122
|
+
/**
|
|
123
|
+
* Sign in and automatically store tokens (token mode) or let backend set cookies (cookie mode)
|
|
124
|
+
*/
|
|
125
|
+
signIn(request: SignInRequest): Promise<SignInResponse>;
|
|
126
|
+
/**
|
|
127
|
+
* Sign up and optionally store tokens if returned
|
|
128
|
+
*/
|
|
129
|
+
signUp(request: SignUpRequest): Promise<SignUpResponse>;
|
|
130
|
+
/**
|
|
131
|
+
* Sign out and clear stored tokens/session
|
|
132
|
+
*/
|
|
133
|
+
signOut(): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Verify magic link and store tokens
|
|
136
|
+
*/
|
|
137
|
+
verifyMagicLink(request: MagicLinkVerifyRequest): Promise<SignInResponse>;
|
|
138
|
+
/**
|
|
139
|
+
* Accept invitation and store tokens
|
|
140
|
+
*/
|
|
141
|
+
acceptInvitation(request: AcceptInvitationRequest): Promise<SignInResponse>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 23blocks client interface.
|
|
145
|
+
*
|
|
146
|
+
* Services are only available if their URL was configured.
|
|
147
|
+
* Accessing a service without a configured URL will throw an error.
|
|
148
|
+
*/
|
|
149
|
+
export interface Blocks23Client {
|
|
150
|
+
/**
|
|
151
|
+
* Authentication operations with automatic token management.
|
|
152
|
+
* Requires `urls.authentication` to be configured.
|
|
153
|
+
*/
|
|
154
|
+
auth: ManagedAuthService;
|
|
155
|
+
/**
|
|
156
|
+
* User management operations.
|
|
157
|
+
* Requires `urls.authentication` to be configured.
|
|
158
|
+
*/
|
|
159
|
+
users: AuthenticationBlock['users'];
|
|
160
|
+
/**
|
|
161
|
+
* Role and permission management.
|
|
162
|
+
* Requires `urls.authentication` to be configured.
|
|
163
|
+
*/
|
|
164
|
+
roles: AuthenticationBlock['roles'];
|
|
165
|
+
/**
|
|
166
|
+
* API key management.
|
|
167
|
+
* Requires `urls.authentication` to be configured.
|
|
168
|
+
*/
|
|
169
|
+
apiKeys: AuthenticationBlock['apiKeys'];
|
|
170
|
+
/**
|
|
171
|
+
* Full authentication block (advanced access).
|
|
172
|
+
* Requires `urls.authentication` to be configured.
|
|
173
|
+
*/
|
|
174
|
+
authentication: AuthenticationBlock;
|
|
175
|
+
/**
|
|
176
|
+
* Search and favorites.
|
|
177
|
+
* Requires `urls.search` to be configured.
|
|
178
|
+
*/
|
|
179
|
+
search: SearchBlock;
|
|
180
|
+
/**
|
|
181
|
+
* Products, cart, and catalog.
|
|
182
|
+
* Requires `urls.products` to be configured.
|
|
183
|
+
*/
|
|
184
|
+
products: ProductsBlock;
|
|
185
|
+
/**
|
|
186
|
+
* CRM - contacts, organizations, deals.
|
|
187
|
+
* Requires `urls.crm` to be configured.
|
|
188
|
+
*/
|
|
189
|
+
crm: CrmBlock;
|
|
190
|
+
/**
|
|
191
|
+
* Content management.
|
|
192
|
+
* Requires `urls.content` to be configured.
|
|
193
|
+
*/
|
|
194
|
+
content: ContentBlock;
|
|
195
|
+
/**
|
|
196
|
+
* Geolocation - addresses, places.
|
|
197
|
+
* Requires `urls.geolocation` to be configured.
|
|
198
|
+
*/
|
|
199
|
+
geolocation: GeolocationBlock;
|
|
200
|
+
/**
|
|
201
|
+
* Messaging and conversations.
|
|
202
|
+
* Requires `urls.conversations` to be configured.
|
|
203
|
+
*/
|
|
204
|
+
conversations: ConversationsBlock;
|
|
205
|
+
/**
|
|
206
|
+
* File uploads and storage.
|
|
207
|
+
* Requires `urls.files` to be configured.
|
|
208
|
+
*/
|
|
209
|
+
files: FilesBlock;
|
|
210
|
+
/**
|
|
211
|
+
* Form builder and submissions.
|
|
212
|
+
* Requires `urls.forms` to be configured.
|
|
213
|
+
*/
|
|
214
|
+
forms: FormsBlock;
|
|
215
|
+
/**
|
|
216
|
+
* Asset management.
|
|
217
|
+
* Requires `urls.assets` to be configured.
|
|
218
|
+
*/
|
|
219
|
+
assets: AssetsBlock;
|
|
220
|
+
/**
|
|
221
|
+
* Marketing campaigns.
|
|
222
|
+
* Requires `urls.campaigns` to be configured.
|
|
223
|
+
*/
|
|
224
|
+
campaigns: CampaignsBlock;
|
|
225
|
+
/**
|
|
226
|
+
* Company settings.
|
|
227
|
+
* Requires `urls.company` to be configured.
|
|
228
|
+
*/
|
|
229
|
+
company: CompanyBlock;
|
|
230
|
+
/**
|
|
231
|
+
* Rewards and loyalty.
|
|
232
|
+
* Requires `urls.rewards` to be configured.
|
|
233
|
+
*/
|
|
234
|
+
rewards: RewardsBlock;
|
|
235
|
+
/**
|
|
236
|
+
* Sales, orders, invoices.
|
|
237
|
+
* Requires `urls.sales` to be configured.
|
|
238
|
+
*/
|
|
239
|
+
sales: SalesBlock;
|
|
240
|
+
/**
|
|
241
|
+
* Digital wallet.
|
|
242
|
+
* Requires `urls.wallet` to be configured.
|
|
243
|
+
*/
|
|
244
|
+
wallet: WalletBlock;
|
|
245
|
+
/**
|
|
246
|
+
* AI assistant.
|
|
247
|
+
* Requires `urls.jarvis` to be configured.
|
|
248
|
+
*/
|
|
249
|
+
jarvis: JarvisBlock;
|
|
250
|
+
/**
|
|
251
|
+
* User onboarding.
|
|
252
|
+
* Requires `urls.onboarding` to be configured.
|
|
253
|
+
*/
|
|
254
|
+
onboarding: OnboardingBlock;
|
|
255
|
+
/**
|
|
256
|
+
* Learning management.
|
|
257
|
+
* Requires `urls.university` to be configured.
|
|
258
|
+
*/
|
|
259
|
+
university: UniversityBlock;
|
|
260
|
+
/**
|
|
261
|
+
* Get the current access token (token mode only)
|
|
262
|
+
* Returns null if in cookie mode or no token stored
|
|
263
|
+
*/
|
|
264
|
+
getAccessToken(): string | null;
|
|
265
|
+
/**
|
|
266
|
+
* Get the current refresh token (token mode only)
|
|
267
|
+
* Returns null if in cookie mode or no token stored
|
|
268
|
+
*/
|
|
269
|
+
getRefreshToken(): string | null;
|
|
270
|
+
/**
|
|
271
|
+
* Manually set tokens (token mode only)
|
|
272
|
+
* Useful for SSR hydration
|
|
273
|
+
*/
|
|
274
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
275
|
+
/**
|
|
276
|
+
* Clear the current session (tokens or signal backend to clear cookie)
|
|
277
|
+
*/
|
|
278
|
+
clearSession(): void;
|
|
279
|
+
/**
|
|
280
|
+
* Check if user is likely authenticated
|
|
281
|
+
* In token mode: checks if token exists
|
|
282
|
+
* In cookie mode: always returns null (check with validateToken instead)
|
|
283
|
+
*/
|
|
284
|
+
isAuthenticated(): boolean | null;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Create a 23blocks client instance
|
|
288
|
+
*
|
|
289
|
+
* @param config - Client configuration
|
|
290
|
+
* @returns A configured client with all blocks and automatic auth management
|
|
291
|
+
*
|
|
292
|
+
* @example Basic usage with multiple services
|
|
293
|
+
* ```typescript
|
|
294
|
+
* const client = create23BlocksClient({
|
|
295
|
+
* appId: 'your-app-id',
|
|
296
|
+
* urls: {
|
|
297
|
+
* authentication: 'https://gateway.23blocks.com',
|
|
298
|
+
* crm: 'https://crm.23blocks.com',
|
|
299
|
+
* products: 'https://products.23blocks.com',
|
|
300
|
+
* },
|
|
301
|
+
* });
|
|
302
|
+
*
|
|
303
|
+
* // Sign in - tokens are stored automatically
|
|
304
|
+
* await client.auth.signIn({ email: 'user@example.com', password: 'password' });
|
|
305
|
+
*
|
|
306
|
+
* // Each service uses its own URL
|
|
307
|
+
* const products = await client.products.products.list();
|
|
308
|
+
* const contacts = await client.crm.contacts.list();
|
|
309
|
+
*
|
|
310
|
+
* // Sign out - tokens are cleared automatically
|
|
311
|
+
* await client.auth.signOut();
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* @example Cookie mode (recommended for security)
|
|
315
|
+
* ```typescript
|
|
316
|
+
* const client = create23BlocksClient({
|
|
317
|
+
* appId: 'your-app-id',
|
|
318
|
+
* authMode: 'cookie',
|
|
319
|
+
* urls: {
|
|
320
|
+
* authentication: 'https://gateway.23blocks.com',
|
|
321
|
+
* crm: 'https://crm.23blocks.com',
|
|
322
|
+
* },
|
|
323
|
+
* });
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @example SSR with token forwarding
|
|
327
|
+
* ```typescript
|
|
328
|
+
* const client = create23BlocksClient({
|
|
329
|
+
* appId: 'your-app-id',
|
|
330
|
+
* storage: 'memory',
|
|
331
|
+
* headers: { Authorization: `Bearer ${tokenFromRequest}` },
|
|
332
|
+
* urls: {
|
|
333
|
+
* authentication: 'https://gateway.23blocks.com',
|
|
334
|
+
* crm: 'https://crm.23blocks.com',
|
|
335
|
+
* },
|
|
336
|
+
* });
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
export declare function create23BlocksClient(config: ClientConfig): Blocks23Client;
|
|
340
|
+
export type { StorageType, TokenManager } from './token-manager.js';
|
|
341
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/client.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAA4B,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAClG,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,2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AAI,CAAC;IAEjC;;;OAGG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,IAAI,IAAI,CAAC;IAErB;;;;OAIG;IACH,eAAe,IAAI,OAAO,GAAG,IAAI,CAAC;CACnC;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,CA2PzE;AAGD,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { create23BlocksClient, type AuthMode, type ClientConfig, type ServiceUrls, type Blocks23Client, type ManagedAuthService, type StorageType, type TokenManager, } from './client.js';
|
|
2
|
+
export { createTokenManager } from './token-manager.js';
|
|
3
|
+
export * from '@23blocks/contracts';
|
|
4
|
+
export * from '@23blocks/jsonapi-codec';
|
|
5
|
+
export * from '@23blocks/transport-http';
|
|
6
|
+
export * from '@23blocks/block-authentication';
|
|
7
|
+
export * from '@23blocks/block-search';
|
|
8
|
+
export * from '@23blocks/block-products';
|
|
9
|
+
export * from '@23blocks/block-crm';
|
|
10
|
+
export * from '@23blocks/block-content';
|
|
11
|
+
export * from '@23blocks/block-geolocation';
|
|
12
|
+
export * from '@23blocks/block-conversations';
|
|
13
|
+
export * from '@23blocks/block-files';
|
|
14
|
+
export * from '@23blocks/block-forms';
|
|
15
|
+
export * from '@23blocks/block-assets';
|
|
16
|
+
export * from '@23blocks/block-campaigns';
|
|
17
|
+
export * from '@23blocks/block-company';
|
|
18
|
+
export * from '@23blocks/block-rewards';
|
|
19
|
+
export * from '@23blocks/block-sales';
|
|
20
|
+
export * from '@23blocks/block-wallet';
|
|
21
|
+
export * from '@23blocks/block-jarvis';
|
|
22
|
+
export * from '@23blocks/block-onboarding';
|
|
23
|
+
export * from '@23blocks/block-university';
|
|
24
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../../src/lib/sdk.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,oBAAoB,EACpB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAMxD,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AAMzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token storage types
|
|
3
|
+
*/
|
|
4
|
+
export type StorageType = 'localStorage' | 'sessionStorage' | 'memory';
|
|
5
|
+
/**
|
|
6
|
+
* Token manager configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface TokenManagerConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Application ID - used to scope token storage
|
|
11
|
+
* This ensures multiple apps on the same domain don't conflict
|
|
12
|
+
*/
|
|
13
|
+
appId: string;
|
|
14
|
+
/**
|
|
15
|
+
* Tenant ID (optional) - further scopes token storage for multi-tenant apps
|
|
16
|
+
*/
|
|
17
|
+
tenantId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Storage type
|
|
20
|
+
* @default 'localStorage'
|
|
21
|
+
*/
|
|
22
|
+
storage?: StorageType;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Token manager interface for storing and retrieving auth tokens
|
|
26
|
+
*/
|
|
27
|
+
export interface TokenManager {
|
|
28
|
+
/**
|
|
29
|
+
* Get the current access token
|
|
30
|
+
*/
|
|
31
|
+
getAccessToken(): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* Get the current refresh token
|
|
34
|
+
*/
|
|
35
|
+
getRefreshToken(): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Store tokens
|
|
38
|
+
*/
|
|
39
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Clear all stored tokens
|
|
42
|
+
*/
|
|
43
|
+
clearTokens(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe to storage changes (for cross-tab sync)
|
|
46
|
+
* Returns an unsubscribe function
|
|
47
|
+
*/
|
|
48
|
+
onStorageChange(callback: () => void): () => void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a token manager instance
|
|
52
|
+
*
|
|
53
|
+
* @param config - Token manager configuration including appId for scoped storage
|
|
54
|
+
* @returns A TokenManager instance
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const tokenManager = createTokenManager({
|
|
59
|
+
* appId: 'my-app',
|
|
60
|
+
* storage: 'localStorage',
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Store tokens after sign in
|
|
64
|
+
* tokenManager.setTokens('access_token_value', 'refresh_token_value');
|
|
65
|
+
*
|
|
66
|
+
* // Get token for API requests
|
|
67
|
+
* const token = tokenManager.getAccessToken();
|
|
68
|
+
*
|
|
69
|
+
* // Clear on sign out
|
|
70
|
+
* tokenManager.clearTokens();
|
|
71
|
+
*
|
|
72
|
+
* // Listen for cross-tab changes
|
|
73
|
+
* const unsubscribe = tokenManager.onStorageChange(() => {
|
|
74
|
+
* console.log('Tokens changed in another tab');
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function createTokenManager(config: TokenManagerConfig): TokenManager;
|
|
79
|
+
//# sourceMappingURL=token-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-manager.d.ts","sourceRoot":"","sources":["../../../src/lib/token-manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,gBAAgB,GAAG,QAAQ,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI,CAAC;IAEhC;;OAEG;IACH,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;IAEjC;;OAEG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5D;;OAEG;IACH,WAAW,IAAI,IAAI,CAAC;IAEpB;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CACnD;AAyDD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAwE3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@23blocks/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "23blocks SDK - unified meta-package re-exporting all blocks and utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "23blocks <hello@23blocks.com>",
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"university"
|
|
40
40
|
],
|
|
41
41
|
"type": "module",
|
|
42
|
-
"main": "./dist/index.js",
|
|
43
|
-
"module": "./dist/index.js",
|
|
42
|
+
"main": "./dist/index.esm.js",
|
|
43
|
+
"module": "./dist/index.esm.js",
|
|
44
44
|
"types": "./dist/index.d.ts",
|
|
45
45
|
"exports": {
|
|
46
46
|
"./package.json": "./package.json",
|
|
47
47
|
".": {
|
|
48
48
|
"types": "./dist/index.d.ts",
|
|
49
|
-
"import": "./dist/index.js",
|
|
50
|
-
"default": "./dist/index.js"
|
|
49
|
+
"import": "./dist/index.esm.js",
|
|
50
|
+
"default": "./dist/index.esm.js"
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"files": [
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"sourceRoot": "packages/sdk/src",
|
|
59
59
|
"targets": {
|
|
60
60
|
"build": {
|
|
61
|
-
"executor": "@nx/
|
|
61
|
+
"executor": "@nx/rollup:rollup",
|
|
62
62
|
"outputs": [
|
|
63
63
|
"{options.outputPath}"
|
|
64
64
|
],
|
|
@@ -66,8 +66,10 @@
|
|
|
66
66
|
"outputPath": "packages/sdk/dist",
|
|
67
67
|
"main": "packages/sdk/src/index.ts",
|
|
68
68
|
"tsConfig": "packages/sdk/tsconfig.lib.json",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
69
|
+
"compiler": "swc",
|
|
70
|
+
"format": [
|
|
71
|
+
"esm"
|
|
72
|
+
]
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './lib/sdk.js';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,eAAe"}
|
package/dist/lib/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/client.ts"],"sourcesContent":["import { createHttpTransport } from '@23blocks/transport-http';\nimport {\n createAuthenticationBlock,\n type AuthenticationBlock,\n type SignInRequest,\n type SignInResponse,\n type SignUpRequest,\n type SignUpResponse,\n type MagicLinkVerifyRequest,\n type AcceptInvitationRequest,\n} from '@23blocks/block-authentication';\nimport { createSearchBlock, type SearchBlock } from '@23blocks/block-search';\nimport { createProductsBlock, type ProductsBlock } from '@23blocks/block-products';\nimport { createCrmBlock, type CrmBlock } from '@23blocks/block-crm';\nimport { createContentBlock, type ContentBlock } from '@23blocks/block-content';\nimport { createGeolocationBlock, type GeolocationBlock } from '@23blocks/block-geolocation';\nimport { createConversationsBlock, type ConversationsBlock } from '@23blocks/block-conversations';\nimport { createFilesBlock, type FilesBlock } from '@23blocks/block-files';\nimport { createFormsBlock, type FormsBlock } from '@23blocks/block-forms';\nimport { createAssetsBlock, type AssetsBlock } from '@23blocks/block-assets';\nimport { createCampaignsBlock, type CampaignsBlock } from '@23blocks/block-campaigns';\nimport { createCompanyBlock, type CompanyBlock } from '@23blocks/block-company';\nimport { createRewardsBlock, type RewardsBlock } from '@23blocks/block-rewards';\nimport { createSalesBlock, type SalesBlock } from '@23blocks/block-sales';\nimport { createWalletBlock, type WalletBlock } from '@23blocks/block-wallet';\nimport { createJarvisBlock, type JarvisBlock } from '@23blocks/block-jarvis';\nimport { createOnboardingBlock, type OnboardingBlock } from '@23blocks/block-onboarding';\nimport { createUniversityBlock, type UniversityBlock } from '@23blocks/block-university';\n\nimport { createTokenManager, type StorageType, type TokenManager, type TokenManagerConfig } from './token-manager.js';\n\n/**\n * Authentication mode\n * - 'token': Store tokens in browser storage, attach Authorization header\n * - 'cookie': Use httpOnly cookies set by backend (recommended for new projects)\n */\nexport type AuthMode = 'token' | 'cookie';\n\n/**\n * Service URL configuration - each microservice has its own URL.\n * All URLs are optional - only configure the services you need.\n */\nexport interface ServiceUrls {\n /** Authentication service URL */\n authentication?: string;\n /** Search service URL */\n search?: string;\n /** Products service URL */\n products?: string;\n /** CRM service URL */\n crm?: string;\n /** Content service URL */\n content?: string;\n /** Geolocation service URL */\n geolocation?: string;\n /** Conversations service URL */\n conversations?: string;\n /** Files service URL */\n files?: string;\n /** Forms service URL */\n forms?: string;\n /** Assets service URL */\n assets?: string;\n /** Campaigns service URL */\n campaigns?: string;\n /** Company service URL */\n company?: string;\n /** Rewards service URL */\n rewards?: string;\n /** Sales service URL */\n sales?: string;\n /** Wallet service URL */\n wallet?: string;\n /** Jarvis (AI) service URL */\n jarvis?: string;\n /** Onboarding service URL */\n onboarding?: string;\n /** University (LMS) service URL */\n university?: string;\n}\n\n/**\n * Client configuration\n */\nexport interface ClientConfig {\n /**\n * Service URLs for each microservice.\n * Only configure the services you need - accessing a service without\n * a configured URL will throw an error.\n *\n * @example\n * ```typescript\n * urls: {\n * authentication: 'https://gateway.23blocks.com',\n * crm: 'https://crm.23blocks.com',\n * products: 'https://products.23blocks.com',\n * }\n * ```\n */\n urls: ServiceUrls;\n\n /**\n * Application ID\n */\n appId: string;\n\n /**\n * Tenant ID (optional, for multi-tenant setups)\n */\n tenantId?: string;\n\n /**\n * Authentication mode\n * - 'token' (default): SDK stores tokens in localStorage/sessionStorage/memory\n * - 'cookie': Backend manages auth via httpOnly cookies\n */\n authMode?: AuthMode;\n\n /**\n * Storage type for token mode\n * Only applicable when authMode is 'token'\n * @default 'localStorage' in browser, 'memory' in SSR\n */\n storage?: StorageType;\n\n /**\n * Additional headers to include with every request\n * Useful for SSR cookie forwarding\n */\n headers?: Record<string, string>;\n\n /**\n * Request timeout in milliseconds\n * @default 30000\n */\n timeout?: number;\n}\n\n/**\n * Auth service wrapper with automatic token management\n */\nexport interface ManagedAuthService extends Omit<AuthenticationBlock['auth'], 'signIn' | 'signUp' | 'signOut' | 'verifyMagicLink' | 'acceptInvitation'> {\n /**\n * Sign in and automatically store tokens (token mode) or let backend set cookies (cookie mode)\n */\n signIn(request: SignInRequest): Promise<SignInResponse>;\n\n /**\n * Sign up and optionally store tokens if returned\n */\n signUp(request: SignUpRequest): Promise<SignUpResponse>;\n\n /**\n * Sign out and clear stored tokens/session\n */\n signOut(): Promise<void>;\n\n /**\n * Verify magic link and store tokens\n */\n verifyMagicLink(request: MagicLinkVerifyRequest): Promise<SignInResponse>;\n\n /**\n * Accept invitation and store tokens\n */\n acceptInvitation(request: AcceptInvitationRequest): Promise<SignInResponse>;\n}\n\n/**\n * 23blocks client interface.\n *\n * Services are only available if their URL was configured.\n * Accessing a service without a configured URL will throw an error.\n */\nexport interface Blocks23Client {\n // ─────────────────────────────────────────────────────────────────────────────\n // Blocks (available only if URL configured)\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Authentication operations with automatic token management.\n * Requires `urls.authentication` to be configured.\n */\n auth: ManagedAuthService;\n\n /**\n * User management operations.\n * Requires `urls.authentication` to be configured.\n */\n users: AuthenticationBlock['users'];\n\n /**\n * Role and permission management.\n * Requires `urls.authentication` to be configured.\n */\n roles: AuthenticationBlock['roles'];\n\n /**\n * API key management.\n * Requires `urls.authentication` to be configured.\n */\n apiKeys: AuthenticationBlock['apiKeys'];\n\n /**\n * Full authentication block (advanced access).\n * Requires `urls.authentication` to be configured.\n */\n authentication: AuthenticationBlock;\n\n /**\n * Search and favorites.\n * Requires `urls.search` to be configured.\n */\n search: SearchBlock;\n\n /**\n * Products, cart, and catalog.\n * Requires `urls.products` to be configured.\n */\n products: ProductsBlock;\n\n /**\n * CRM - contacts, organizations, deals.\n * Requires `urls.crm` to be configured.\n */\n crm: CrmBlock;\n\n /**\n * Content management.\n * Requires `urls.content` to be configured.\n */\n content: ContentBlock;\n\n /**\n * Geolocation - addresses, places.\n * Requires `urls.geolocation` to be configured.\n */\n geolocation: GeolocationBlock;\n\n /**\n * Messaging and conversations.\n * Requires `urls.conversations` to be configured.\n */\n conversations: ConversationsBlock;\n\n /**\n * File uploads and storage.\n * Requires `urls.files` to be configured.\n */\n files: FilesBlock;\n\n /**\n * Form builder and submissions.\n * Requires `urls.forms` to be configured.\n */\n forms: FormsBlock;\n\n /**\n * Asset management.\n * Requires `urls.assets` to be configured.\n */\n assets: AssetsBlock;\n\n /**\n * Marketing campaigns.\n * Requires `urls.campaigns` to be configured.\n */\n campaigns: CampaignsBlock;\n\n /**\n * Company settings.\n * Requires `urls.company` to be configured.\n */\n company: CompanyBlock;\n\n /**\n * Rewards and loyalty.\n * Requires `urls.rewards` to be configured.\n */\n rewards: RewardsBlock;\n\n /**\n * Sales, orders, invoices.\n * Requires `urls.sales` to be configured.\n */\n sales: SalesBlock;\n\n /**\n * Digital wallet.\n * Requires `urls.wallet` to be configured.\n */\n wallet: WalletBlock;\n\n /**\n * AI assistant.\n * Requires `urls.jarvis` to be configured.\n */\n jarvis: JarvisBlock;\n\n /**\n * User onboarding.\n * Requires `urls.onboarding` to be configured.\n */\n onboarding: OnboardingBlock;\n\n /**\n * Learning management.\n * Requires `urls.university` to be configured.\n */\n university: UniversityBlock;\n\n // ─────────────────────────────────────────────────────────────────────────────\n // Utilities\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Get the current access token (token mode only)\n * Returns null if in cookie mode or no token stored\n */\n getAccessToken(): string | null;\n\n /**\n * Get the current refresh token (token mode only)\n * Returns null if in cookie mode or no token stored\n */\n getRefreshToken(): string | null;\n\n /**\n * Manually set tokens (token mode only)\n * Useful for SSR hydration\n */\n setTokens(accessToken: string, refreshToken?: string): void;\n\n /**\n * Clear the current session (tokens or signal backend to clear cookie)\n */\n clearSession(): void;\n\n /**\n * Check if user is likely authenticated\n * In token mode: checks if token exists\n * In cookie mode: always returns null (check with validateToken instead)\n */\n isAuthenticated(): boolean | null;\n}\n\n/**\n * Detect browser environment\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';\n}\n\n/**\n * Create a 23blocks client instance\n *\n * @param config - Client configuration\n * @returns A configured client with all blocks and automatic auth management\n *\n * @example Basic usage with multiple services\n * ```typescript\n * const client = create23BlocksClient({\n * appId: 'your-app-id',\n * urls: {\n * authentication: 'https://gateway.23blocks.com',\n * crm: 'https://crm.23blocks.com',\n * products: 'https://products.23blocks.com',\n * },\n * });\n *\n * // Sign in - tokens are stored automatically\n * await client.auth.signIn({ email: 'user@example.com', password: 'password' });\n *\n * // Each service uses its own URL\n * const products = await client.products.products.list();\n * const contacts = await client.crm.contacts.list();\n *\n * // Sign out - tokens are cleared automatically\n * await client.auth.signOut();\n * ```\n *\n * @example Cookie mode (recommended for security)\n * ```typescript\n * const client = create23BlocksClient({\n * appId: 'your-app-id',\n * authMode: 'cookie',\n * urls: {\n * authentication: 'https://gateway.23blocks.com',\n * crm: 'https://crm.23blocks.com',\n * },\n * });\n * ```\n *\n * @example SSR with token forwarding\n * ```typescript\n * const client = create23BlocksClient({\n * appId: 'your-app-id',\n * storage: 'memory',\n * headers: { Authorization: `Bearer ${tokenFromRequest}` },\n * urls: {\n * authentication: 'https://gateway.23blocks.com',\n * crm: 'https://crm.23blocks.com',\n * },\n * });\n * ```\n */\nexport function create23BlocksClient(config: ClientConfig): Blocks23Client {\n const {\n urls,\n appId,\n tenantId,\n authMode = 'token',\n storage = isBrowser() ? 'localStorage' : 'memory',\n headers: staticHeaders = {},\n timeout,\n } = config;\n\n // Create token manager for token mode\n let tokenManager: TokenManager | null = null;\n if (authMode === 'token') {\n tokenManager = createTokenManager({\n appId,\n tenantId,\n storage,\n });\n }\n\n // Factory to create transport for a specific service URL\n function createServiceTransport(baseUrl: string) {\n return createHttpTransport({\n baseUrl,\n timeout,\n credentials: authMode === 'cookie' ? 'include' : undefined,\n headers: () => {\n const headers: Record<string, string> = {\n ...staticHeaders,\n appid: appId,\n };\n\n if (tenantId) {\n headers['tenant-id'] = tenantId;\n }\n\n // In token mode, add Authorization header if we have a token\n if (authMode === 'token' && tokenManager) {\n const token = tokenManager.getAccessToken();\n if (token) {\n headers['Authorization'] = `Bearer ${token}`;\n }\n }\n\n return headers;\n },\n });\n }\n\n // Helper to create a proxy that throws when accessing unconfigured service\n function createUnconfiguredServiceProxy<T>(serviceName: string, urlKey: string): T {\n return new Proxy({} as T, {\n get(_target, prop) {\n throw new Error(\n `[23blocks] Cannot access '${serviceName}.${String(prop)}': ` +\n `The ${serviceName} service URL is not configured. ` +\n `Add 'urls.${urlKey}' to your client configuration.`\n );\n },\n });\n }\n\n // Create block config\n const blockConfig = { appId, tenantId };\n\n // Create blocks only if their URL is provided\n const authenticationBlock = urls.authentication\n ? createAuthenticationBlock(createServiceTransport(urls.authentication), blockConfig)\n : null;\n\n const searchBlock = urls.search\n ? createSearchBlock(createServiceTransport(urls.search), blockConfig)\n : null;\n\n const productsBlock = urls.products\n ? createProductsBlock(createServiceTransport(urls.products), blockConfig)\n : null;\n\n const crmBlock = urls.crm\n ? createCrmBlock(createServiceTransport(urls.crm), blockConfig)\n : null;\n\n const contentBlock = urls.content\n ? createContentBlock(createServiceTransport(urls.content), blockConfig)\n : null;\n\n const geolocationBlock = urls.geolocation\n ? createGeolocationBlock(createServiceTransport(urls.geolocation), blockConfig)\n : null;\n\n const conversationsBlock = urls.conversations\n ? createConversationsBlock(createServiceTransport(urls.conversations), blockConfig)\n : null;\n\n const filesBlock = urls.files\n ? createFilesBlock(createServiceTransport(urls.files), blockConfig)\n : null;\n\n const formsBlock = urls.forms\n ? createFormsBlock(createServiceTransport(urls.forms), blockConfig)\n : null;\n\n const assetsBlock = urls.assets\n ? createAssetsBlock(createServiceTransport(urls.assets), blockConfig)\n : null;\n\n const campaignsBlock = urls.campaigns\n ? createCampaignsBlock(createServiceTransport(urls.campaigns), blockConfig)\n : null;\n\n const companyBlock = urls.company\n ? createCompanyBlock(createServiceTransport(urls.company), blockConfig)\n : null;\n\n const rewardsBlock = urls.rewards\n ? createRewardsBlock(createServiceTransport(urls.rewards), blockConfig)\n : null;\n\n const salesBlock = urls.sales\n ? createSalesBlock(createServiceTransport(urls.sales), blockConfig)\n : null;\n\n const walletBlock = urls.wallet\n ? createWalletBlock(createServiceTransport(urls.wallet), blockConfig)\n : null;\n\n const jarvisBlock = urls.jarvis\n ? createJarvisBlock(createServiceTransport(urls.jarvis), blockConfig)\n : null;\n\n const onboardingBlock = urls.onboarding\n ? createOnboardingBlock(createServiceTransport(urls.onboarding), blockConfig)\n : null;\n\n const universityBlock = urls.university\n ? createUniversityBlock(createServiceTransport(urls.university), blockConfig)\n : null;\n\n // Create managed auth service with automatic token handling (only if auth URL configured)\n const managedAuth: ManagedAuthService = authenticationBlock\n ? {\n async signIn(request: SignInRequest): Promise<SignInResponse> {\n const response = await authenticationBlock.auth.signIn(request);\n if (authMode === 'token' && tokenManager && response.accessToken) {\n tokenManager.setTokens(response.accessToken, response.refreshToken);\n }\n return response;\n },\n\n async signUp(request: SignUpRequest): Promise<SignUpResponse> {\n const response = await authenticationBlock.auth.signUp(request);\n if (authMode === 'token' && tokenManager && response.accessToken) {\n tokenManager.setTokens(response.accessToken);\n }\n return response;\n },\n\n async signOut(): Promise<void> {\n await authenticationBlock.auth.signOut();\n if (authMode === 'token' && tokenManager) {\n tokenManager.clearTokens();\n }\n },\n\n async verifyMagicLink(request: MagicLinkVerifyRequest): Promise<SignInResponse> {\n const response = await authenticationBlock.auth.verifyMagicLink(request);\n if (authMode === 'token' && tokenManager && response.accessToken) {\n tokenManager.setTokens(response.accessToken, response.refreshToken);\n }\n return response;\n },\n\n async acceptInvitation(request: AcceptInvitationRequest): Promise<SignInResponse> {\n const response = await authenticationBlock.auth.acceptInvitation(request);\n if (authMode === 'token' && tokenManager && response.accessToken) {\n tokenManager.setTokens(response.accessToken, response.refreshToken);\n }\n return response;\n },\n\n validateToken: authenticationBlock.auth.validateToken.bind(authenticationBlock.auth),\n getCurrentUser: authenticationBlock.auth.getCurrentUser.bind(authenticationBlock.auth),\n requestPasswordReset: authenticationBlock.auth.requestPasswordReset.bind(authenticationBlock.auth),\n updatePassword: authenticationBlock.auth.updatePassword.bind(authenticationBlock.auth),\n refreshToken: authenticationBlock.auth.refreshToken.bind(authenticationBlock.auth),\n requestMagicLink: authenticationBlock.auth.requestMagicLink.bind(authenticationBlock.auth),\n sendInvitation: authenticationBlock.auth.sendInvitation.bind(authenticationBlock.auth),\n confirmEmail: authenticationBlock.auth.confirmEmail.bind(authenticationBlock.auth),\n resendConfirmation: authenticationBlock.auth.resendConfirmation.bind(authenticationBlock.auth),\n }\n : createUnconfiguredServiceProxy<ManagedAuthService>('auth', 'authentication');\n\n return {\n // Authentication with managed tokens\n auth: managedAuth,\n users: authenticationBlock?.users ?? createUnconfiguredServiceProxy('users', 'authentication'),\n roles: authenticationBlock?.roles ?? createUnconfiguredServiceProxy('roles', 'authentication'),\n apiKeys: authenticationBlock?.apiKeys ?? createUnconfiguredServiceProxy('apiKeys', 'authentication'),\n authentication: authenticationBlock ?? createUnconfiguredServiceProxy('authentication', 'authentication'),\n\n // All blocks - use proxy if not configured\n search: searchBlock ?? createUnconfiguredServiceProxy('search', 'search'),\n products: productsBlock ?? createUnconfiguredServiceProxy('products', 'products'),\n crm: crmBlock ?? createUnconfiguredServiceProxy('crm', 'crm'),\n content: contentBlock ?? createUnconfiguredServiceProxy('content', 'content'),\n geolocation: geolocationBlock ?? createUnconfiguredServiceProxy('geolocation', 'geolocation'),\n conversations: conversationsBlock ?? createUnconfiguredServiceProxy('conversations', 'conversations'),\n files: filesBlock ?? createUnconfiguredServiceProxy('files', 'files'),\n forms: formsBlock ?? createUnconfiguredServiceProxy('forms', 'forms'),\n assets: assetsBlock ?? createUnconfiguredServiceProxy('assets', 'assets'),\n campaigns: campaignsBlock ?? createUnconfiguredServiceProxy('campaigns', 'campaigns'),\n company: companyBlock ?? createUnconfiguredServiceProxy('company', 'company'),\n rewards: rewardsBlock ?? createUnconfiguredServiceProxy('rewards', 'rewards'),\n sales: salesBlock ?? createUnconfiguredServiceProxy('sales', 'sales'),\n wallet: walletBlock ?? createUnconfiguredServiceProxy('wallet', 'wallet'),\n jarvis: jarvisBlock ?? createUnconfiguredServiceProxy('jarvis', 'jarvis'),\n onboarding: onboardingBlock ?? createUnconfiguredServiceProxy('onboarding', 'onboarding'),\n university: universityBlock ?? createUnconfiguredServiceProxy('university', 'university'),\n\n // Utilities\n getAccessToken(): string | null {\n if (authMode !== 'token' || !tokenManager) return null;\n return tokenManager.getAccessToken();\n },\n\n getRefreshToken(): string | null {\n if (authMode !== 'token' || !tokenManager) return null;\n return tokenManager.getRefreshToken();\n },\n\n setTokens(accessToken: string, refreshToken?: string): void {\n if (authMode === 'token' && tokenManager) {\n tokenManager.setTokens(accessToken, refreshToken);\n }\n },\n\n clearSession(): void {\n if (authMode === 'token' && tokenManager) {\n tokenManager.clearTokens();\n }\n },\n\n isAuthenticated(): boolean | null {\n if (authMode === 'cookie') {\n // Can't know without calling validateToken\n return null;\n }\n return tokenManager ? !!tokenManager.getAccessToken() : false;\n },\n };\n}\n\n// Re-export types\nexport type { StorageType, TokenManager } from './token-manager.js';\n"],"names":["createHttpTransport","createAuthenticationBlock","createSearchBlock","createProductsBlock","createCrmBlock","createContentBlock","createGeolocationBlock","createConversationsBlock","createFilesBlock","createFormsBlock","createAssetsBlock","createCampaignsBlock","createCompanyBlock","createRewardsBlock","createSalesBlock","createWalletBlock","createJarvisBlock","createOnboardingBlock","createUniversityBlock","createTokenManager","isBrowser","window","localStorage","create23BlocksClient","config","urls","appId","tenantId","authMode","storage","headers","staticHeaders","timeout","tokenManager","createServiceTransport","baseUrl","credentials","undefined","appid","token","getAccessToken","createUnconfiguredServiceProxy","serviceName","urlKey","Proxy","get","_target","prop","Error","String","blockConfig","authenticationBlock","authentication","searchBlock","search","productsBlock","products","crmBlock","crm","contentBlock","content","geolocationBlock","geolocation","conversationsBlock","conversations","filesBlock","files","formsBlock","forms","assetsBlock","assets","campaignsBlock","campaigns","companyBlock","company","rewardsBlock","rewards","salesBlock","sales","walletBlock","wallet","jarvisBlock","jarvis","onboardingBlock","onboarding","universityBlock","university","managedAuth","signIn","request","response","auth","accessToken","setTokens","refreshToken","signUp","signOut","clearTokens","verifyMagicLink","acceptInvitation","validateToken","bind","getCurrentUser","requestPasswordReset","updatePassword","requestMagicLink","sendInvitation","confirmEmail","resendConfirmation","users","roles","apiKeys","getRefreshToken","clearSession","isAuthenticated"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAASA,mBAAmB,QAAQ,2BAA2B;AAC/D,SACEC,yBAAyB,QAQpB,iCAAiC;AACxC,SAASC,iBAAiB,QAA0B,yBAAyB;AAC7E,SAASC,mBAAmB,QAA4B,2BAA2B;AACnF,SAASC,cAAc,QAAuB,sBAAsB;AACpE,SAASC,kBAAkB,QAA2B,0BAA0B;AAChF,SAASC,sBAAsB,QAA+B,8BAA8B;AAC5F,SAASC,wBAAwB,QAAiC,gCAAgC;AAClG,SAASC,gBAAgB,QAAyB,wBAAwB;AAC1E,SAASC,gBAAgB,QAAyB,wBAAwB;AAC1E,SAASC,iBAAiB,QAA0B,yBAAyB;AAC7E,SAASC,oBAAoB,QAA6B,4BAA4B;AACtF,SAASC,kBAAkB,QAA2B,0BAA0B;AAChF,SAASC,kBAAkB,QAA2B,0BAA0B;AAChF,SAASC,gBAAgB,QAAyB,wBAAwB;AAC1E,SAASC,iBAA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,UAAU;QAChEyC,QAAQD,sBAAAA,cAAexC,+BAA+B,UAAU;QAChE2C,YAAYD,0BAAAA,kBAAmB1C,+BAA+B,cAAc;QAC5E6C,YAAYD,0BAAAA,kBAAmB5C,+BAA+B,cAAc;QAE5E,YAAY;QACZD;YACE,IAAIZ,aAAa,WAAW,CAACK,cAAc,OAAO;YAClD,OAAOA,aAAaO,cAAc;QACpC;QAEAwE;YACE,IAAIpF,aAAa,WAAW,CAACK,cAAc,OAAO;YAClD,OAAOA,aAAa+E,eAAe;QACrC;QAEAnB,WAAUD,WAAmB,EAAEE,YAAqB;YAClD,IAAIlE,aAAa,WAAWK,cAAc;gBACxCA,aAAa4D,SAAS,CAACD,aAAaE;YACtC;QACF;QAEAmB;YACE,IAAIrF,aAAa,WAAWK,cAAc;gBACxCA,aAAagE,WAAW;YAC1B;QACF;QAEAiB;YACE,IAAItF,aAAa,UAAU;gBACzB,2CAA2C;gBAC3C,OAAO;YACT;YACA,OAAOK,eAAe,CAAC,CAACA,aAAaO,cAAc,KAAK;QAC1D;IACF;AACF"}
|
package/dist/lib/sdk.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
-
// Client Factory (Recommended API)
|
|
3
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
export { create23BlocksClient } from './client.js';
|
|
5
|
-
export { createTokenManager } from './token-manager.js';
|
|
6
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
7
|
-
// Core
|
|
8
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
9
|
-
export * from '@23blocks/contracts';
|
|
10
|
-
export * from '@23blocks/jsonapi-codec';
|
|
11
|
-
export * from '@23blocks/transport-http';
|
|
12
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
13
|
-
// Blocks (for advanced users who need custom transport)
|
|
14
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
15
|
-
export * from '@23blocks/block-authentication';
|
|
16
|
-
export * from '@23blocks/block-search';
|
|
17
|
-
export * from '@23blocks/block-products';
|
|
18
|
-
export * from '@23blocks/block-crm';
|
|
19
|
-
export * from '@23blocks/block-content';
|
|
20
|
-
export * from '@23blocks/block-geolocation';
|
|
21
|
-
export * from '@23blocks/block-conversations';
|
|
22
|
-
export * from '@23blocks/block-files';
|
|
23
|
-
export * from '@23blocks/block-forms';
|
|
24
|
-
export * from '@23blocks/block-assets';
|
|
25
|
-
export * from '@23blocks/block-campaigns';
|
|
26
|
-
export * from '@23blocks/block-company';
|
|
27
|
-
export * from '@23blocks/block-rewards';
|
|
28
|
-
export * from '@23blocks/block-sales';
|
|
29
|
-
export * from '@23blocks/block-wallet';
|
|
30
|
-
export * from '@23blocks/block-jarvis';
|
|
31
|
-
export * from '@23blocks/block-onboarding';
|
|
32
|
-
export * from '@23blocks/block-university';
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=sdk.js.map
|
package/dist/lib/sdk.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/sdk.ts"],"sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// Client Factory (Recommended API)\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport {\n create23BlocksClient,\n type AuthMode,\n type ClientConfig,\n type ServiceUrls,\n type Blocks23Client,\n type ManagedAuthService,\n type StorageType,\n type TokenManager,\n} from './client.js';\n\nexport { createTokenManager } from './token-manager.js';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Core\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport * from '@23blocks/contracts';\nexport * from '@23blocks/jsonapi-codec';\nexport * from '@23blocks/transport-http';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Blocks (for advanced users who need custom transport)\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport * from '@23blocks/block-authentication';\nexport * from '@23blocks/block-search';\nexport * from '@23blocks/block-products';\nexport * from '@23blocks/block-crm';\nexport * from '@23blocks/block-content';\nexport * from '@23blocks/block-geolocation';\nexport * from '@23blocks/block-conversations';\nexport * from '@23blocks/block-files';\nexport * from '@23blocks/block-forms';\nexport * from '@23blocks/block-assets';\nexport * from '@23blocks/block-campaigns';\nexport * from '@23blocks/block-company';\nexport * from '@23blocks/block-rewards';\nexport * from '@23blocks/block-sales';\nexport * from '@23blocks/block-wallet';\nexport * from '@23blocks/block-jarvis';\nexport * from '@23blocks/block-onboarding';\nexport * from '@23blocks/block-university';\n"],"names":["create23BlocksClient","createTokenManager"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,gFAAgF;AAChF,mCAAmC;AACnC,gFAAgF;AAEhF,SACEA,oBAAoB,QAQf,cAAc;AAErB,SAASC,kBAAkB,QAAQ,qBAAqB;AAExD,gFAAgF;AAChF,OAAO;AACP,gFAAgF;AAEhF,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,2BAA2B;AAEzC,gFAAgF;AAChF,wDAAwD;AACxD,gFAAgF;AAEhF,cAAc,iCAAiC;AAC/C,cAAc,yBAAyB;AACvC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,8BAA8B;AAC5C,cAAc,gCAAgC;AAC9C,cAAc,wBAAwB;AACtC,cAAc,wBAAwB;AACtC,cAAc,yBAAyB;AACvC,cAAc,4BAA4B;AAC1C,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AACxC,cAAc,wBAAwB;AACtC,cAAc,yBAAyB;AACvC,cAAc,yBAAyB;AACvC,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token storage types
|
|
3
|
-
*/ /**
|
|
4
|
-
* Generate storage key scoped to app and tenant
|
|
5
|
-
*/ function getStorageKey(type, appId, tenantId) {
|
|
6
|
-
const scope = tenantId ? `${appId}_${tenantId}` : appId;
|
|
7
|
-
return `23blocks_${scope}_${type}_token`;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* In-memory token storage (for SSR or when localStorage is unavailable)
|
|
11
|
-
*/ let MemoryStorage = class MemoryStorage {
|
|
12
|
-
getItem(key) {
|
|
13
|
-
var _this_data_get;
|
|
14
|
-
return (_this_data_get = this.data.get(key)) != null ? _this_data_get : null;
|
|
15
|
-
}
|
|
16
|
-
setItem(key, value) {
|
|
17
|
-
this.data.set(key, value);
|
|
18
|
-
}
|
|
19
|
-
removeItem(key) {
|
|
20
|
-
this.data.delete(key);
|
|
21
|
-
}
|
|
22
|
-
constructor(){
|
|
23
|
-
this.data = new Map();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Detect if we're running in a browser environment
|
|
28
|
-
*/ function isBrowser() {
|
|
29
|
-
return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Get the appropriate storage backend
|
|
33
|
-
*/ function getStorage(type) {
|
|
34
|
-
if (!isBrowser()) {
|
|
35
|
-
// In SSR/Node, always use memory storage
|
|
36
|
-
return new MemoryStorage();
|
|
37
|
-
}
|
|
38
|
-
switch(type){
|
|
39
|
-
case 'localStorage':
|
|
40
|
-
return window.localStorage;
|
|
41
|
-
case 'sessionStorage':
|
|
42
|
-
return window.sessionStorage;
|
|
43
|
-
case 'memory':
|
|
44
|
-
return new MemoryStorage();
|
|
45
|
-
default:
|
|
46
|
-
return window.localStorage;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a token manager instance
|
|
51
|
-
*
|
|
52
|
-
* @param config - Token manager configuration including appId for scoped storage
|
|
53
|
-
* @returns A TokenManager instance
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const tokenManager = createTokenManager({
|
|
58
|
-
* appId: 'my-app',
|
|
59
|
-
* storage: 'localStorage',
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* // Store tokens after sign in
|
|
63
|
-
* tokenManager.setTokens('access_token_value', 'refresh_token_value');
|
|
64
|
-
*
|
|
65
|
-
* // Get token for API requests
|
|
66
|
-
* const token = tokenManager.getAccessToken();
|
|
67
|
-
*
|
|
68
|
-
* // Clear on sign out
|
|
69
|
-
* tokenManager.clearTokens();
|
|
70
|
-
*
|
|
71
|
-
* // Listen for cross-tab changes
|
|
72
|
-
* const unsubscribe = tokenManager.onStorageChange(() => {
|
|
73
|
-
* console.log('Tokens changed in another tab');
|
|
74
|
-
* });
|
|
75
|
-
* ```
|
|
76
|
-
*/ export function createTokenManager(config) {
|
|
77
|
-
const { appId, tenantId, storage: storageType = 'localStorage' } = config;
|
|
78
|
-
const storage = getStorage(storageType);
|
|
79
|
-
const accessTokenKey = getStorageKey('access', appId, tenantId);
|
|
80
|
-
const refreshTokenKey = getStorageKey('refresh', appId, tenantId);
|
|
81
|
-
// Track storage event listeners for cleanup
|
|
82
|
-
const listeners = new Set();
|
|
83
|
-
return {
|
|
84
|
-
getAccessToken () {
|
|
85
|
-
try {
|
|
86
|
-
return storage.getItem(accessTokenKey);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
getRefreshToken () {
|
|
92
|
-
try {
|
|
93
|
-
return storage.getItem(refreshTokenKey);
|
|
94
|
-
} catch (e) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
setTokens (accessToken, refreshToken) {
|
|
99
|
-
try {
|
|
100
|
-
storage.setItem(accessTokenKey, accessToken);
|
|
101
|
-
if (refreshToken) {
|
|
102
|
-
storage.setItem(refreshTokenKey, refreshToken);
|
|
103
|
-
}
|
|
104
|
-
} catch (e) {
|
|
105
|
-
// Storage might be full or disabled, silently fail
|
|
106
|
-
console.warn('[23blocks] Unable to store tokens');
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
clearTokens () {
|
|
110
|
-
try {
|
|
111
|
-
storage.removeItem(accessTokenKey);
|
|
112
|
-
storage.removeItem(refreshTokenKey);
|
|
113
|
-
} catch (e) {
|
|
114
|
-
// Silently fail
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
onStorageChange (callback) {
|
|
118
|
-
// Only works in browser with localStorage/sessionStorage
|
|
119
|
-
if (!isBrowser() || storageType === 'memory') {
|
|
120
|
-
// Return no-op unsubscribe for SSR/memory storage
|
|
121
|
-
return ()=>{};
|
|
122
|
-
}
|
|
123
|
-
const handler = (event)=>{
|
|
124
|
-
// Only trigger if our keys changed
|
|
125
|
-
if (event.key === accessTokenKey || event.key === refreshTokenKey) {
|
|
126
|
-
callback();
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
window.addEventListener('storage', handler);
|
|
130
|
-
listeners.add(callback);
|
|
131
|
-
// Return unsubscribe function
|
|
132
|
-
return ()=>{
|
|
133
|
-
window.removeEventListener('storage', handler);
|
|
134
|
-
listeners.delete(callback);
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
//# sourceMappingURL=token-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/token-manager.ts"],"sourcesContent":["/**\n * Token storage types\n */\nexport type StorageType = 'localStorage' | 'sessionStorage' | 'memory';\n\n/**\n * Token manager configuration\n */\nexport interface TokenManagerConfig {\n /**\n * Application ID - used to scope token storage\n * This ensures multiple apps on the same domain don't conflict\n */\n appId: string;\n\n /**\n * Tenant ID (optional) - further scopes token storage for multi-tenant apps\n */\n tenantId?: string;\n\n /**\n * Storage type\n * @default 'localStorage'\n */\n storage?: StorageType;\n}\n\n/**\n * Token manager interface for storing and retrieving auth tokens\n */\nexport interface TokenManager {\n /**\n * Get the current access token\n */\n getAccessToken(): string | null;\n\n /**\n * Get the current refresh token\n */\n getRefreshToken(): string | null;\n\n /**\n * Store tokens\n */\n setTokens(accessToken: string, refreshToken?: string): void;\n\n /**\n * Clear all stored tokens\n */\n clearTokens(): void;\n\n /**\n * Subscribe to storage changes (for cross-tab sync)\n * Returns an unsubscribe function\n */\n onStorageChange(callback: () => void): () => void;\n}\n\n/**\n * Generate storage key scoped to app and tenant\n */\nfunction getStorageKey(type: 'access' | 'refresh', appId: string, tenantId?: string): string {\n const scope = tenantId ? `${appId}_${tenantId}` : appId;\n return `23blocks_${scope}_${type}_token`;\n}\n\n/**\n * In-memory token storage (for SSR or when localStorage is unavailable)\n */\nclass MemoryStorage {\n private data: Map<string, string> = new Map();\n\n getItem(key: string): string | null {\n return this.data.get(key) ?? null;\n }\n\n setItem(key: string, value: string): void {\n this.data.set(key, value);\n }\n\n removeItem(key: string): void {\n this.data.delete(key);\n }\n}\n\n/**\n * Detect if we're running in a browser environment\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';\n}\n\n/**\n * Get the appropriate storage backend\n */\nfunction getStorage(type: StorageType): Storage | MemoryStorage {\n if (!isBrowser()) {\n // In SSR/Node, always use memory storage\n return new MemoryStorage();\n }\n\n switch (type) {\n case 'localStorage':\n return window.localStorage;\n case 'sessionStorage':\n return window.sessionStorage;\n case 'memory':\n return new MemoryStorage();\n default:\n return window.localStorage;\n }\n}\n\n/**\n * Create a token manager instance\n *\n * @param config - Token manager configuration including appId for scoped storage\n * @returns A TokenManager instance\n *\n * @example\n * ```typescript\n * const tokenManager = createTokenManager({\n * appId: 'my-app',\n * storage: 'localStorage',\n * });\n *\n * // Store tokens after sign in\n * tokenManager.setTokens('access_token_value', 'refresh_token_value');\n *\n * // Get token for API requests\n * const token = tokenManager.getAccessToken();\n *\n * // Clear on sign out\n * tokenManager.clearTokens();\n *\n * // Listen for cross-tab changes\n * const unsubscribe = tokenManager.onStorageChange(() => {\n * console.log('Tokens changed in another tab');\n * });\n * ```\n */\nexport function createTokenManager(config: TokenManagerConfig): TokenManager {\n const { appId, tenantId, storage: storageType = 'localStorage' } = config;\n const storage = getStorage(storageType);\n\n const accessTokenKey = getStorageKey('access', appId, tenantId);\n const refreshTokenKey = getStorageKey('refresh', appId, tenantId);\n\n // Track storage event listeners for cleanup\n const listeners: Set<() => void> = new Set();\n\n return {\n getAccessToken(): string | null {\n try {\n return storage.getItem(accessTokenKey);\n } catch {\n return null;\n }\n },\n\n getRefreshToken(): string | null {\n try {\n return storage.getItem(refreshTokenKey);\n } catch {\n return null;\n }\n },\n\n setTokens(accessToken: string, refreshToken?: string): void {\n try {\n storage.setItem(accessTokenKey, accessToken);\n if (refreshToken) {\n storage.setItem(refreshTokenKey, refreshToken);\n }\n } catch {\n // Storage might be full or disabled, silently fail\n console.warn('[23blocks] Unable to store tokens');\n }\n },\n\n clearTokens(): void {\n try {\n storage.removeItem(accessTokenKey);\n storage.removeItem(refreshTokenKey);\n } catch {\n // Silently fail\n }\n },\n\n onStorageChange(callback: () => void): () => void {\n // Only works in browser with localStorage/sessionStorage\n if (!isBrowser() || storageType === 'memory') {\n // Return no-op unsubscribe for SSR/memory storage\n return () => {};\n }\n\n const handler = (event: StorageEvent) => {\n // Only trigger if our keys changed\n if (event.key === accessTokenKey || event.key === refreshTokenKey) {\n callback();\n }\n };\n\n window.addEventListener('storage', handler);\n listeners.add(callback);\n\n // Return unsubscribe function\n return () => {\n window.removeEventListener('storage', handler);\n listeners.delete(callback);\n };\n },\n };\n}\n"],"names":["getStorageKey","type","appId","tenantId","scope","MemoryStorage","getItem","key","data","get","setItem","value","set","removeItem","delete","Map","isBrowser","window","localStorage","getStorage","sessionStorage","createTokenManager","config","storage","storageType","accessTokenKey","refreshTokenKey","listeners","Set","getAccessToken","getRefreshToken","setTokens","accessToken","refreshToken","console","warn","clearTokens","onStorageChange","callback","handler","event","addEventListener","add","removeEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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