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