@centrali-io/centrali-sdk 2.0.12 → 2.1.1
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.js +20 -13
- package/index.ts +23 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -488,22 +488,29 @@ class CentraliSDK {
|
|
|
488
488
|
*/
|
|
489
489
|
get realtime() {
|
|
490
490
|
if (!this._realtime) {
|
|
491
|
-
this._realtime = new RealtimeManager(this.options.baseUrl, this.options.workspaceId, () =>
|
|
492
|
-
// If token exists, return it
|
|
493
|
-
if (this.token) {
|
|
494
|
-
return this.token;
|
|
495
|
-
}
|
|
496
|
-
// For client-credentials flow, fetch token if not available
|
|
497
|
-
if (this.options.clientId && this.options.clientSecret) {
|
|
498
|
-
this.token = yield fetchClientToken(this.options.clientId, this.options.clientSecret, this.options.baseUrl);
|
|
499
|
-
return this.token;
|
|
500
|
-
}
|
|
501
|
-
// No token and no credentials
|
|
502
|
-
return null;
|
|
503
|
-
}));
|
|
491
|
+
this._realtime = new RealtimeManager(this.options.baseUrl, this.options.workspaceId, () => this.getTokenOrFetch());
|
|
504
492
|
}
|
|
505
493
|
return this._realtime;
|
|
506
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Get the current token, or fetch one using client credentials if available.
|
|
497
|
+
* This ensures realtime subscriptions work without needing a prior HTTP request.
|
|
498
|
+
*/
|
|
499
|
+
getTokenOrFetch() {
|
|
500
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
501
|
+
// If token exists, return it
|
|
502
|
+
if (this.token) {
|
|
503
|
+
return this.token;
|
|
504
|
+
}
|
|
505
|
+
// For client-credentials flow, proactively fetch token if not available
|
|
506
|
+
if (this.options.clientId && this.options.clientSecret) {
|
|
507
|
+
this.token = yield fetchClientToken(this.options.clientId, this.options.clientSecret, this.options.baseUrl);
|
|
508
|
+
return this.token;
|
|
509
|
+
}
|
|
510
|
+
// No token and no credentials
|
|
511
|
+
return null;
|
|
512
|
+
});
|
|
513
|
+
}
|
|
507
514
|
/**
|
|
508
515
|
* Triggers namespace for invoking and managing function triggers.
|
|
509
516
|
*
|
package/index.ts
CHANGED
|
@@ -724,28 +724,34 @@ export class CentraliSDK {
|
|
|
724
724
|
this._realtime = new RealtimeManager(
|
|
725
725
|
this.options.baseUrl,
|
|
726
726
|
this.options.workspaceId,
|
|
727
|
-
|
|
728
|
-
// If token exists, return it
|
|
729
|
-
if (this.token) {
|
|
730
|
-
return this.token;
|
|
731
|
-
}
|
|
732
|
-
// For client-credentials flow, fetch token if not available
|
|
733
|
-
if (this.options.clientId && this.options.clientSecret) {
|
|
734
|
-
this.token = await fetchClientToken(
|
|
735
|
-
this.options.clientId,
|
|
736
|
-
this.options.clientSecret,
|
|
737
|
-
this.options.baseUrl
|
|
738
|
-
);
|
|
739
|
-
return this.token;
|
|
740
|
-
}
|
|
741
|
-
// No token and no credentials
|
|
742
|
-
return null;
|
|
743
|
-
}
|
|
727
|
+
() => this.getTokenOrFetch()
|
|
744
728
|
);
|
|
745
729
|
}
|
|
746
730
|
return this._realtime;
|
|
747
731
|
}
|
|
748
732
|
|
|
733
|
+
/**
|
|
734
|
+
* Get the current token, or fetch one using client credentials if available.
|
|
735
|
+
* This ensures realtime subscriptions work without needing a prior HTTP request.
|
|
736
|
+
*/
|
|
737
|
+
private async getTokenOrFetch(): Promise<string | null> {
|
|
738
|
+
// If token exists, return it
|
|
739
|
+
if (this.token) {
|
|
740
|
+
return this.token;
|
|
741
|
+
}
|
|
742
|
+
// For client-credentials flow, proactively fetch token if not available
|
|
743
|
+
if (this.options.clientId && this.options.clientSecret) {
|
|
744
|
+
this.token = await fetchClientToken(
|
|
745
|
+
this.options.clientId,
|
|
746
|
+
this.options.clientSecret,
|
|
747
|
+
this.options.baseUrl
|
|
748
|
+
);
|
|
749
|
+
return this.token;
|
|
750
|
+
}
|
|
751
|
+
// No token and no credentials
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
|
|
749
755
|
/**
|
|
750
756
|
* Triggers namespace for invoking and managing function triggers.
|
|
751
757
|
*
|