@oxyhq/core 3.4.5 → 3.4.7
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/OxyServices.base.js +45 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/OxyServices.base.js +45 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +1 -1
- package/dist/types/OxyServices.base.d.ts +14 -0
- package/dist/types/OxyServices.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mixins/OxyServices.analytics.d.ts +1 -0
- package/dist/types/mixins/OxyServices.appData.d.ts +1 -0
- package/dist/types/mixins/OxyServices.applications.d.ts +1 -0
- package/dist/types/mixins/OxyServices.assets.d.ts +1 -0
- package/dist/types/mixins/OxyServices.auth.d.ts +1 -0
- package/dist/types/mixins/OxyServices.contacts.d.ts +1 -0
- package/dist/types/mixins/OxyServices.devices.d.ts +1 -0
- package/dist/types/mixins/OxyServices.features.d.ts +1 -0
- package/dist/types/mixins/OxyServices.fedcm.d.ts +1 -0
- package/dist/types/mixins/OxyServices.language.d.ts +1 -0
- package/dist/types/mixins/OxyServices.location.d.ts +1 -0
- package/dist/types/mixins/OxyServices.managedAccounts.d.ts +1 -0
- package/dist/types/mixins/OxyServices.payment.d.ts +1 -0
- package/dist/types/mixins/OxyServices.privacy.d.ts +1 -0
- package/dist/types/mixins/OxyServices.redirect.d.ts +1 -0
- package/dist/types/mixins/OxyServices.reputation.d.ts +1 -0
- package/dist/types/mixins/OxyServices.security.d.ts +1 -0
- package/dist/types/mixins/OxyServices.silent.d.ts +1 -0
- package/dist/types/mixins/OxyServices.sso.d.ts +1 -0
- package/dist/types/mixins/OxyServices.topics.d.ts +1 -0
- package/dist/types/mixins/OxyServices.user.d.ts +1 -0
- package/dist/types/mixins/OxyServices.utility.d.ts +1 -0
- package/dist/types/mixins/OxyServices.workspaces.d.ts +1 -0
- package/package.json +1 -1
- package/src/HttpService.ts +1 -1
- package/src/OxyServices.base.ts +57 -1
- package/src/OxyServices.ts +3 -1
- package/src/__tests__/linkedClient.test.ts +92 -0
- package/src/index.ts +1 -0
|
@@ -85,6 +85,51 @@ export class OxyServicesBase {
|
|
|
85
85
|
getClient() {
|
|
86
86
|
return this.httpService;
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Create an app/backend HTTP client linked to this Oxy session.
|
|
90
|
+
*
|
|
91
|
+
* Use this when an app has its own API origin (for example
|
|
92
|
+
* `https://api.syra.fm`) but authentication is owned by the canonical
|
|
93
|
+
* OxyServices instance mounted in OxyProvider. The returned client has its own
|
|
94
|
+
* base URL, cache and request queue, but its bearer token is kept in lockstep
|
|
95
|
+
* with this session and its 401 refresh path delegates back to this session.
|
|
96
|
+
*/
|
|
97
|
+
createLinkedClient(config) {
|
|
98
|
+
const client = new HttpService(config);
|
|
99
|
+
const syncToken = (accessToken) => {
|
|
100
|
+
const currentAccessToken = client.getAccessToken();
|
|
101
|
+
if (accessToken) {
|
|
102
|
+
if (currentAccessToken !== accessToken) {
|
|
103
|
+
client.setTokens(accessToken);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (currentAccessToken) {
|
|
108
|
+
client.clearTokens();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
syncToken(this.getAccessToken());
|
|
112
|
+
const unsubscribe = this.onTokensChanged(syncToken);
|
|
113
|
+
client.setAuthRefreshHandler(async (reason) => {
|
|
114
|
+
const refreshed = await this.httpService.refreshAccessToken(reason);
|
|
115
|
+
if (!refreshed) {
|
|
116
|
+
if (reason === 'response-401') {
|
|
117
|
+
this.clearTokens();
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
syncToken(refreshed);
|
|
122
|
+
return refreshed;
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
client,
|
|
126
|
+
dispose: () => {
|
|
127
|
+
unsubscribe();
|
|
128
|
+
client.setAuthRefreshHandler(null);
|
|
129
|
+
client.clearTokens();
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
88
133
|
/**
|
|
89
134
|
* Get performance metrics
|
|
90
135
|
*/
|