@workos-inc/node 8.10.0 → 8.11.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/lib/{factory-DwdIHLNE.cjs → factory-BraleEZU.cjs} +247 -3
- package/lib/factory-BraleEZU.cjs.map +1 -0
- package/lib/{factory-Dl_P8aZA.mjs → factory-IqQiyE5J.mjs} +242 -4
- package/lib/factory-IqQiyE5J.mjs.map +1 -0
- package/lib/index.cjs +2 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +2 -2
- package/lib/index.mjs.map +1 -1
- package/lib/index.worker.cjs +1 -1
- package/lib/index.worker.d.cts +1 -1
- package/lib/index.worker.d.mts +1 -1
- package/lib/index.worker.mjs +1 -1
- package/lib/{webapi-Cj8QQOwM.mjs → webapi-CxKOxXjo.mjs} +13 -8
- package/lib/webapi-CxKOxXjo.mjs.map +1 -0
- package/lib/{webapi-Dk3R7830.cjs → webapi-N7c2LUJd.cjs} +13 -8
- package/lib/webapi-N7c2LUJd.cjs.map +1 -0
- package/lib/{workos-eC0BwRfM.d.mts → workos-COj1yMhR.d.cts} +86 -2
- package/lib/{workos-DdsaFn8s.d.cts → workos-DluXltJr.d.mts} +86 -2
- package/package.json +7 -4
- package/lib/factory-Dl_P8aZA.mjs.map +0 -1
- package/lib/factory-DwdIHLNE.cjs.map +0 -1
- package/lib/webapi-Cj8QQOwM.mjs.map +0 -1
- package/lib/webapi-Dk3R7830.cjs.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventEmitter } from "eventemitter3";
|
|
1
2
|
//#region src/common/crypto/crypto-provider.ts
|
|
2
3
|
/**
|
|
3
4
|
* Interface encapsulating the various crypto computations used by the library,
|
|
@@ -2794,7 +2795,7 @@ let _josePromise;
|
|
|
2794
2795
|
* @returns Promise that resolves to the jose module
|
|
2795
2796
|
*/
|
|
2796
2797
|
function getJose() {
|
|
2797
|
-
return _josePromise ??= import("./webapi-
|
|
2798
|
+
return _josePromise ??= import("./webapi-CxKOxXjo.mjs");
|
|
2798
2799
|
}
|
|
2799
2800
|
//#endregion
|
|
2800
2801
|
//#region src/user-management/session.ts
|
|
@@ -3720,6 +3721,240 @@ var FGA = class {
|
|
|
3720
3721
|
}
|
|
3721
3722
|
};
|
|
3722
3723
|
//#endregion
|
|
3724
|
+
//#region src/feature-flags/in-memory-store.ts
|
|
3725
|
+
var InMemoryStore = class {
|
|
3726
|
+
flags = {};
|
|
3727
|
+
swap(newFlags) {
|
|
3728
|
+
this.flags = { ...newFlags };
|
|
3729
|
+
}
|
|
3730
|
+
get(slug) {
|
|
3731
|
+
return this.flags[slug];
|
|
3732
|
+
}
|
|
3733
|
+
getAll() {
|
|
3734
|
+
return { ...this.flags };
|
|
3735
|
+
}
|
|
3736
|
+
get size() {
|
|
3737
|
+
return Object.keys(this.flags).length;
|
|
3738
|
+
}
|
|
3739
|
+
};
|
|
3740
|
+
//#endregion
|
|
3741
|
+
//#region src/feature-flags/evaluator.ts
|
|
3742
|
+
var Evaluator = class {
|
|
3743
|
+
constructor(store) {
|
|
3744
|
+
this.store = store;
|
|
3745
|
+
}
|
|
3746
|
+
isEnabled(flagKey, context = {}, defaultValue = false) {
|
|
3747
|
+
const entry = this.store.get(flagKey);
|
|
3748
|
+
if (!entry) return defaultValue;
|
|
3749
|
+
if (!entry.enabled) return false;
|
|
3750
|
+
if (context.userId) {
|
|
3751
|
+
const userTarget = entry.targets.users.find((t) => t.id === context.userId);
|
|
3752
|
+
if (userTarget) return userTarget.enabled;
|
|
3753
|
+
}
|
|
3754
|
+
if (context.organizationId) {
|
|
3755
|
+
const orgTarget = entry.targets.organizations.find((t) => t.id === context.organizationId);
|
|
3756
|
+
if (orgTarget) return orgTarget.enabled;
|
|
3757
|
+
}
|
|
3758
|
+
return entry.default_value;
|
|
3759
|
+
}
|
|
3760
|
+
getAllFlags(context = {}) {
|
|
3761
|
+
const flags = this.store.getAll();
|
|
3762
|
+
const result = {};
|
|
3763
|
+
for (const slug of Object.keys(flags)) result[slug] = this.isEnabled(slug, context);
|
|
3764
|
+
return result;
|
|
3765
|
+
}
|
|
3766
|
+
};
|
|
3767
|
+
//#endregion
|
|
3768
|
+
//#region src/feature-flags/runtime-client.ts
|
|
3769
|
+
const DEFAULT_POLLING_INTERVAL_MS = 3e4;
|
|
3770
|
+
const MIN_POLLING_INTERVAL_MS = 5e3;
|
|
3771
|
+
const MIN_DELAY_MS = 1e3;
|
|
3772
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 1e4;
|
|
3773
|
+
const JITTER_FACTOR = .1;
|
|
3774
|
+
const INITIAL_RETRY_MS = 1e3;
|
|
3775
|
+
const MAX_RETRY_MS = 6e4;
|
|
3776
|
+
const BACKOFF_MULTIPLIER = 2;
|
|
3777
|
+
var FeatureFlagsRuntimeClient = class extends EventEmitter {
|
|
3778
|
+
store;
|
|
3779
|
+
evaluator;
|
|
3780
|
+
pollingIntervalMs;
|
|
3781
|
+
requestTimeoutMs;
|
|
3782
|
+
logger;
|
|
3783
|
+
closed = false;
|
|
3784
|
+
initialized = false;
|
|
3785
|
+
consecutiveErrors = 0;
|
|
3786
|
+
pollTimer = null;
|
|
3787
|
+
pollAbortController = null;
|
|
3788
|
+
readyResolve = null;
|
|
3789
|
+
readyReject = null;
|
|
3790
|
+
readyPromise;
|
|
3791
|
+
stats = {
|
|
3792
|
+
pollCount: 0,
|
|
3793
|
+
pollErrorCount: 0,
|
|
3794
|
+
lastPollAt: null,
|
|
3795
|
+
lastSuccessfulPollAt: null,
|
|
3796
|
+
cacheAge: null,
|
|
3797
|
+
flagCount: 0
|
|
3798
|
+
};
|
|
3799
|
+
constructor(workos, options = {}) {
|
|
3800
|
+
super();
|
|
3801
|
+
this.workos = workos;
|
|
3802
|
+
this.pollingIntervalMs = Math.max(MIN_POLLING_INTERVAL_MS, options.pollingIntervalMs ?? DEFAULT_POLLING_INTERVAL_MS);
|
|
3803
|
+
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
3804
|
+
this.logger = options.logger;
|
|
3805
|
+
this.store = new InMemoryStore();
|
|
3806
|
+
this.evaluator = new Evaluator(this.store);
|
|
3807
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
3808
|
+
this.readyResolve = resolve;
|
|
3809
|
+
this.readyReject = reject;
|
|
3810
|
+
});
|
|
3811
|
+
this.readyPromise.catch(() => {});
|
|
3812
|
+
if (options.bootstrapFlags) {
|
|
3813
|
+
this.store.swap(options.bootstrapFlags);
|
|
3814
|
+
this.stats.flagCount = this.store.size;
|
|
3815
|
+
this.resolveReady();
|
|
3816
|
+
}
|
|
3817
|
+
setTimeout(() => this.poll(), 0);
|
|
3818
|
+
}
|
|
3819
|
+
async waitUntilReady(options) {
|
|
3820
|
+
if (!options?.timeoutMs) return this.readyPromise;
|
|
3821
|
+
let timeoutId;
|
|
3822
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
3823
|
+
timeoutId = setTimeout(() => reject(/* @__PURE__ */ new Error("waitUntilReady timed out")), options.timeoutMs);
|
|
3824
|
+
});
|
|
3825
|
+
timeoutPromise.catch(() => {});
|
|
3826
|
+
return Promise.race([this.readyPromise, timeoutPromise]).finally(() => {
|
|
3827
|
+
clearTimeout(timeoutId);
|
|
3828
|
+
});
|
|
3829
|
+
}
|
|
3830
|
+
emit(event, ...args) {
|
|
3831
|
+
if (event === "error" && this.listenerCount(event) === 0) throw args[0] instanceof Error ? args[0] : new Error(String(args[0]));
|
|
3832
|
+
return super.emit(event, ...args);
|
|
3833
|
+
}
|
|
3834
|
+
close() {
|
|
3835
|
+
this.closed = true;
|
|
3836
|
+
this.pollAbortController?.abort();
|
|
3837
|
+
if (this.pollTimer) {
|
|
3838
|
+
clearTimeout(this.pollTimer);
|
|
3839
|
+
this.pollTimer = null;
|
|
3840
|
+
}
|
|
3841
|
+
this.removeAllListeners();
|
|
3842
|
+
}
|
|
3843
|
+
isEnabled(flagKey, context, defaultValue) {
|
|
3844
|
+
return this.evaluator.isEnabled(flagKey, context, defaultValue);
|
|
3845
|
+
}
|
|
3846
|
+
getAllFlags(context) {
|
|
3847
|
+
return this.evaluator.getAllFlags(context);
|
|
3848
|
+
}
|
|
3849
|
+
getFlag(flagKey) {
|
|
3850
|
+
return this.store.get(flagKey);
|
|
3851
|
+
}
|
|
3852
|
+
getStats() {
|
|
3853
|
+
return {
|
|
3854
|
+
...this.stats,
|
|
3855
|
+
cacheAge: this.stats.lastSuccessfulPollAt ? Date.now() - this.stats.lastSuccessfulPollAt.getTime() : null
|
|
3856
|
+
};
|
|
3857
|
+
}
|
|
3858
|
+
resolveReady() {
|
|
3859
|
+
if (this.readyResolve) {
|
|
3860
|
+
this.readyResolve();
|
|
3861
|
+
this.readyResolve = null;
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
async poll() {
|
|
3865
|
+
if (this.closed) return;
|
|
3866
|
+
const previousFlags = this.store.getAll();
|
|
3867
|
+
try {
|
|
3868
|
+
this.stats.pollCount++;
|
|
3869
|
+
this.stats.lastPollAt = /* @__PURE__ */ new Date();
|
|
3870
|
+
const data = await this.fetchWithTimeout();
|
|
3871
|
+
this.store.swap(data);
|
|
3872
|
+
this.stats.lastSuccessfulPollAt = /* @__PURE__ */ new Date();
|
|
3873
|
+
this.stats.flagCount = this.store.size;
|
|
3874
|
+
this.consecutiveErrors = 0;
|
|
3875
|
+
if (this.initialized) this.emitChanges(previousFlags, data);
|
|
3876
|
+
this.initialized = true;
|
|
3877
|
+
this.resolveReady();
|
|
3878
|
+
this.logger?.debug("Poll successful", { flagCount: this.store.size });
|
|
3879
|
+
} catch (error) {
|
|
3880
|
+
if (this.closed) return;
|
|
3881
|
+
this.consecutiveErrors++;
|
|
3882
|
+
this.stats.pollErrorCount++;
|
|
3883
|
+
this.emit("error", error);
|
|
3884
|
+
this.logger?.error("Poll failed", error);
|
|
3885
|
+
if (error instanceof UnauthorizedException) {
|
|
3886
|
+
this.emit("failed", error);
|
|
3887
|
+
if (!this.initialized && this.readyReject) {
|
|
3888
|
+
this.readyReject(error);
|
|
3889
|
+
this.readyReject = null;
|
|
3890
|
+
}
|
|
3891
|
+
return;
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
this.scheduleNextPoll();
|
|
3895
|
+
}
|
|
3896
|
+
async fetchWithTimeout() {
|
|
3897
|
+
this.pollAbortController = new AbortController();
|
|
3898
|
+
const { signal } = this.pollAbortController;
|
|
3899
|
+
let timeoutId;
|
|
3900
|
+
const fetchPromise = this.workos.get("/sdk/feature-flags").then(({ data }) => data);
|
|
3901
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
3902
|
+
timeoutId = setTimeout(() => {
|
|
3903
|
+
this.pollAbortController?.abort();
|
|
3904
|
+
reject(/* @__PURE__ */ new Error("Request timed out"));
|
|
3905
|
+
}, this.requestTimeoutMs);
|
|
3906
|
+
});
|
|
3907
|
+
const abortPromise = new Promise((_, reject) => {
|
|
3908
|
+
if (signal.aborted) {
|
|
3909
|
+
reject(/* @__PURE__ */ new Error("Poll aborted"));
|
|
3910
|
+
return;
|
|
3911
|
+
}
|
|
3912
|
+
signal.addEventListener("abort", () => reject(/* @__PURE__ */ new Error("Poll aborted")), { once: true });
|
|
3913
|
+
});
|
|
3914
|
+
return Promise.race([
|
|
3915
|
+
fetchPromise,
|
|
3916
|
+
timeoutPromise,
|
|
3917
|
+
abortPromise
|
|
3918
|
+
]).finally(() => {
|
|
3919
|
+
clearTimeout(timeoutId);
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
scheduleNextPoll() {
|
|
3923
|
+
if (this.closed) return;
|
|
3924
|
+
let baseDelay = this.pollingIntervalMs;
|
|
3925
|
+
if (this.consecutiveErrors > 0) {
|
|
3926
|
+
const backoff = Math.min(INITIAL_RETRY_MS * Math.pow(BACKOFF_MULTIPLIER, this.consecutiveErrors - 1), MAX_RETRY_MS);
|
|
3927
|
+
baseDelay = Math.max(baseDelay, backoff);
|
|
3928
|
+
}
|
|
3929
|
+
const jitter = 1 + (Math.random() * 2 - 1) * JITTER_FACTOR;
|
|
3930
|
+
const delay = Math.max(MIN_DELAY_MS, baseDelay * jitter);
|
|
3931
|
+
this.pollTimer = setTimeout(() => this.poll(), delay);
|
|
3932
|
+
}
|
|
3933
|
+
emitChanges(previous, current) {
|
|
3934
|
+
if (!previous || !current) return;
|
|
3935
|
+
const allKeys = new Set([...Object.keys(previous), ...Object.keys(current)]);
|
|
3936
|
+
for (const key of allKeys) {
|
|
3937
|
+
const prev = previous[key];
|
|
3938
|
+
const curr = current[key];
|
|
3939
|
+
if (this.hasEntryChanged(prev, curr)) this.emit("change", {
|
|
3940
|
+
key,
|
|
3941
|
+
previous: prev ?? null,
|
|
3942
|
+
current: curr ?? null
|
|
3943
|
+
});
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
hasEntryChanged(a, b) {
|
|
3947
|
+
if (!a || !b) return a !== b;
|
|
3948
|
+
if (a.enabled !== b.enabled || a.default_value !== b.default_value) return true;
|
|
3949
|
+
const targetsChanged = (xs, ys) => {
|
|
3950
|
+
if (xs.length !== ys.length) return true;
|
|
3951
|
+
const map = new Map(ys.map((t) => [t.id, t.enabled]));
|
|
3952
|
+
return xs.some((t) => map.get(t.id) !== t.enabled);
|
|
3953
|
+
};
|
|
3954
|
+
return targetsChanged(a.targets.users, b.targets.users) || targetsChanged(a.targets.organizations, b.targets.organizations);
|
|
3955
|
+
}
|
|
3956
|
+
};
|
|
3957
|
+
//#endregion
|
|
3723
3958
|
//#region src/feature-flags/feature-flags.ts
|
|
3724
3959
|
var FeatureFlags = class {
|
|
3725
3960
|
constructor(workos) {
|
|
@@ -3748,6 +3983,9 @@ var FeatureFlags = class {
|
|
|
3748
3983
|
const { slug, targetId } = options;
|
|
3749
3984
|
await this.workos.delete(`/feature-flags/${slug}/targets/${targetId}`);
|
|
3750
3985
|
}
|
|
3986
|
+
createRuntimeClient(options) {
|
|
3987
|
+
return new FeatureFlagsRuntimeClient(this.workos, options);
|
|
3988
|
+
}
|
|
3751
3989
|
};
|
|
3752
3990
|
//#endregion
|
|
3753
3991
|
//#region src/widgets/interfaces/get-token.ts
|
|
@@ -4442,7 +4680,7 @@ function extractBunVersionFromUserAgent() {
|
|
|
4442
4680
|
}
|
|
4443
4681
|
//#endregion
|
|
4444
4682
|
//#region package.json
|
|
4445
|
-
var version = "8.
|
|
4683
|
+
var version = "8.11.1";
|
|
4446
4684
|
//#endregion
|
|
4447
4685
|
//#region src/workos.ts
|
|
4448
4686
|
const DEFAULT_HOSTNAME = "api.workos.com";
|
|
@@ -4820,6 +5058,6 @@ function createWorkOS(options) {
|
|
|
4820
5058
|
return new WorkOS(options);
|
|
4821
5059
|
}
|
|
4822
5060
|
//#endregion
|
|
4823
|
-
export {
|
|
5061
|
+
export { ApiKeyRequiredException as A, SignatureVerificationException as C, NoApiKeyProvidedException as D, NotFoundException as E, SubtleCryptoProvider as M, BadRequestException as O, UnauthorizedException as S, OauthException as T, AutoPaginatable as _, OrganizationDomainVerificationStrategy as a, Actions as b, FeatureFlagsRuntimeClient as c, CheckResult as d, CheckOp as f, AuthenticateWithSessionCookieFailureReason as g, serializeRevokeSessionOptions as h, OrganizationDomainState as i, FetchHttpClient as j, GenericServerException as k, WarrantOp as l, RefreshSessionFailureReason as m, ConnectionType as n, DomainDataState as o, CookieSession as p, GeneratePortalLinkIntent as r, WorkOS as s, createWorkOS as t, ResourceOp as u, PKCE as v, RateLimitExceededException as w, UnprocessableEntityException as x, Webhooks as y };
|
|
4824
5062
|
|
|
4825
|
-
//# sourceMappingURL=factory-
|
|
5063
|
+
//# sourceMappingURL=factory-IqQiyE5J.mjs.map
|