@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
@@ -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
  */