@crimson-education/sdk 0.3.8 → 0.3.10
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/core/client.d.ts +2 -2
- package/dist/core/client.js +12 -6
- package/dist/core/tasks.js +2 -0
- package/dist/core/types.d.ts +1 -0
- package/dist/react/provider.js +13 -7
- package/package.json +1 -1
package/dist/core/client.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export declare class CrimsonClient {
|
|
|
24
24
|
private tenantDomainPromise?;
|
|
25
25
|
constructor(config: CrimsonClientConfig);
|
|
26
26
|
/**
|
|
27
|
-
* Initialize the client (required for OAuth mode
|
|
28
|
-
* Call this after creating the client to load stored tokens
|
|
27
|
+
* Initialize the client (required for OAuth mode)
|
|
28
|
+
* Call this after creating the client to load stored tokens
|
|
29
29
|
*/
|
|
30
30
|
initialize(): Promise<void>;
|
|
31
31
|
/**
|
package/dist/core/client.js
CHANGED
|
@@ -82,15 +82,14 @@ class CrimsonClient {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
* Initialize the client (required for OAuth mode
|
|
86
|
-
* Call this after creating the client to load stored tokens
|
|
85
|
+
* Initialize the client (required for OAuth mode)
|
|
86
|
+
* Call this after creating the client to load stored tokens
|
|
87
87
|
*/
|
|
88
88
|
initialize() {
|
|
89
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
90
|
if (this.oauthAdapter) {
|
|
91
91
|
yield this.oauthAdapter.initialize();
|
|
92
92
|
}
|
|
93
|
-
yield this.resolveTenantDomain();
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
95
|
/**
|
|
@@ -105,6 +104,13 @@ class CrimsonClient {
|
|
|
105
104
|
this.tenantDomainPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
106
105
|
var _a, _b;
|
|
107
106
|
try {
|
|
107
|
+
const token = yield this.getToken();
|
|
108
|
+
if (!token) {
|
|
109
|
+
// Silently return without error if called early;
|
|
110
|
+
// it will be lazily retried in fetch() or when token is received.
|
|
111
|
+
this.tenantDomainPromise = undefined;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
108
114
|
// A newer version of profile will return domain
|
|
109
115
|
const profile = yield this.account.getMyProfile();
|
|
110
116
|
if ((_a = profile.tenant) === null || _a === void 0 ? void 0 : _a.domain) {
|
|
@@ -125,6 +131,7 @@ class CrimsonClient {
|
|
|
125
131
|
}
|
|
126
132
|
catch (err) {
|
|
127
133
|
console.warn('[CrimsonSDK] Failed to resolve tenant domain:', err);
|
|
134
|
+
this.tenantDomainPromise = undefined;
|
|
128
135
|
}
|
|
129
136
|
finally {
|
|
130
137
|
this.isResolvingDomain = false;
|
|
@@ -236,8 +243,8 @@ class CrimsonClient {
|
|
|
236
243
|
fetch(path_1) {
|
|
237
244
|
return __awaiter(this, arguments, void 0, function* (path, options = {}) {
|
|
238
245
|
// If it's a roadmap endpoint, wait for tenant domain to be resolved first
|
|
239
|
-
if (path.includes("/roadmap")
|
|
240
|
-
yield this.
|
|
246
|
+
if (path.includes("/roadmap")) {
|
|
247
|
+
yield this.resolveTenantDomain();
|
|
241
248
|
}
|
|
242
249
|
const token = yield this.getToken();
|
|
243
250
|
if (!token) {
|
|
@@ -254,7 +261,6 @@ class CrimsonClient {
|
|
|
254
261
|
if (this.appTenant) {
|
|
255
262
|
headers["X-App-Tenant"] = this.appTenant;
|
|
256
263
|
}
|
|
257
|
-
console.log(`tenantDomain = ${this.tenantDomain}`);
|
|
258
264
|
if (this.tenantDomain) {
|
|
259
265
|
headers["x-tenant-domain"] = this.tenantDomain;
|
|
260
266
|
}
|
package/dist/core/tasks.js
CHANGED
package/dist/core/types.d.ts
CHANGED
package/dist/react/provider.js
CHANGED
|
@@ -34,14 +34,20 @@ function CrimsonProvider({ children, apiUrl, allowedParentOrigins, queryClient:
|
|
|
34
34
|
appName,
|
|
35
35
|
appTenant,
|
|
36
36
|
}), [apiUrl, clientId, appName, appTenant]);
|
|
37
|
-
// trigger initialization, we need to determine tenant domain at first place.
|
|
38
|
-
(0, react_1.useEffect)(() => {
|
|
39
|
-
client.initialize();
|
|
40
|
-
}, [client]);
|
|
41
37
|
(0, react_1.useEffect)(() => {
|
|
42
38
|
const origins = allowedParentOrigins || (0, iframe_1.getDefaultAllowedOrigins)();
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
const cleanupIframe = (0, iframe_1.setupIframeListener)(origins);
|
|
40
|
+
// Eagerly resolve tenant domain as soon as token becomes available from iframe
|
|
41
|
+
const cleanupAuth = (0, iframe_1.subscribeToAuthState)(() => {
|
|
42
|
+
const state = (0, iframe_1.getAuthState)();
|
|
43
|
+
if (state.token) {
|
|
44
|
+
client.resolveTenantDomain().catch(() => { });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
cleanupIframe();
|
|
49
|
+
cleanupAuth();
|
|
50
|
+
};
|
|
51
|
+
}, [allowedParentOrigins, client]);
|
|
46
52
|
return ((0, jsx_runtime_1.jsx)(CrimsonContext.Provider, { value: { client }, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: children }) }));
|
|
47
53
|
}
|