@workers-community/workers-types 4.20260408.1 → 4.20260409.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.
Files changed (3) hide show
  1. package/index.d.ts +140 -0
  2. package/index.ts +140 -0
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -12032,6 +12032,140 @@ declare module "cloudflare:email" {
12032
12032
  };
12033
12033
  export { _EmailMessage as EmailMessage };
12034
12034
  }
12035
+ /**
12036
+ * Evaluation context for targeting rules.
12037
+ * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12038
+ */
12039
+ type EvaluationContext = Record<string, string | number | boolean>;
12040
+ interface EvaluationDetails<T> {
12041
+ flagKey: string;
12042
+ value: T;
12043
+ variant?: string | undefined;
12044
+ reason?: string | undefined;
12045
+ errorCode?: string | undefined;
12046
+ errorMessage?: string | undefined;
12047
+ }
12048
+ interface FlagEvaluationError extends Error {}
12049
+ /**
12050
+ * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12051
+ *
12052
+ * @example
12053
+ * ```typescript
12054
+ * // Get a boolean flag value with a default
12055
+ * const enabled = await env.FLAGS.getBooleanValue('my-feature', false);
12056
+ *
12057
+ * // Get a flag value with evaluation context for targeting
12058
+ * const variant = await env.FLAGS.getStringValue('experiment', 'control', {
12059
+ * userId: 'user-123',
12060
+ * country: 'US',
12061
+ * });
12062
+ *
12063
+ * // Get full evaluation details including variant and reason
12064
+ * const details = await env.FLAGS.getBooleanDetails('my-feature', false);
12065
+ * console.log(details.variant, details.reason);
12066
+ * ```
12067
+ */
12068
+ declare abstract class Flags {
12069
+ /**
12070
+ * Get a flag value without type checking.
12071
+ * @param flagKey The key of the flag to evaluate.
12072
+ * @param defaultValue Optional default value returned when evaluation fails.
12073
+ * @param context Optional evaluation context for targeting rules.
12074
+ */
12075
+ get(
12076
+ flagKey: string,
12077
+ defaultValue?: unknown,
12078
+ context?: EvaluationContext,
12079
+ ): Promise<unknown>;
12080
+ /**
12081
+ * Get a boolean flag value.
12082
+ * @param flagKey The key of the flag to evaluate.
12083
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12084
+ * @param context Optional evaluation context for targeting rules.
12085
+ */
12086
+ getBooleanValue(
12087
+ flagKey: string,
12088
+ defaultValue: boolean,
12089
+ context?: EvaluationContext,
12090
+ ): Promise<boolean>;
12091
+ /**
12092
+ * Get a string flag value.
12093
+ * @param flagKey The key of the flag to evaluate.
12094
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12095
+ * @param context Optional evaluation context for targeting rules.
12096
+ */
12097
+ getStringValue(
12098
+ flagKey: string,
12099
+ defaultValue: string,
12100
+ context?: EvaluationContext,
12101
+ ): Promise<string>;
12102
+ /**
12103
+ * Get a number flag value.
12104
+ * @param flagKey The key of the flag to evaluate.
12105
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12106
+ * @param context Optional evaluation context for targeting rules.
12107
+ */
12108
+ getNumberValue(
12109
+ flagKey: string,
12110
+ defaultValue: number,
12111
+ context?: EvaluationContext,
12112
+ ): Promise<number>;
12113
+ /**
12114
+ * Get an object flag value.
12115
+ * @param flagKey The key of the flag to evaluate.
12116
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12117
+ * @param context Optional evaluation context for targeting rules.
12118
+ */
12119
+ getObjectValue<T extends object>(
12120
+ flagKey: string,
12121
+ defaultValue: T,
12122
+ context?: EvaluationContext,
12123
+ ): Promise<T>;
12124
+ /**
12125
+ * Get a boolean flag value with full evaluation details.
12126
+ * @param flagKey The key of the flag to evaluate.
12127
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12128
+ * @param context Optional evaluation context for targeting rules.
12129
+ */
12130
+ getBooleanDetails(
12131
+ flagKey: string,
12132
+ defaultValue: boolean,
12133
+ context?: EvaluationContext,
12134
+ ): Promise<EvaluationDetails<boolean>>;
12135
+ /**
12136
+ * Get a string flag value with full evaluation details.
12137
+ * @param flagKey The key of the flag to evaluate.
12138
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12139
+ * @param context Optional evaluation context for targeting rules.
12140
+ */
12141
+ getStringDetails(
12142
+ flagKey: string,
12143
+ defaultValue: string,
12144
+ context?: EvaluationContext,
12145
+ ): Promise<EvaluationDetails<string>>;
12146
+ /**
12147
+ * Get a number flag value with full evaluation details.
12148
+ * @param flagKey The key of the flag to evaluate.
12149
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12150
+ * @param context Optional evaluation context for targeting rules.
12151
+ */
12152
+ getNumberDetails(
12153
+ flagKey: string,
12154
+ defaultValue: number,
12155
+ context?: EvaluationContext,
12156
+ ): Promise<EvaluationDetails<number>>;
12157
+ /**
12158
+ * Get an object flag value with full evaluation details.
12159
+ * @param flagKey The key of the flag to evaluate.
12160
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12161
+ * @param context Optional evaluation context for targeting rules.
12162
+ */
12163
+ getObjectDetails<T extends object>(
12164
+ flagKey: string,
12165
+ defaultValue: T,
12166
+ context?: EvaluationContext,
12167
+ ): Promise<EvaluationDetails<T>>;
12168
+ }
12035
12169
  /**
12036
12170
  * Hello World binding to serve as an explanatory example. DO NOT USE
12037
12171
  */
@@ -13870,6 +14004,11 @@ declare namespace TailStream {
13870
14004
  readonly tag?: string;
13871
14005
  readonly message?: string;
13872
14006
  }
14007
+ interface TracePreviewInfo {
14008
+ readonly id: string;
14009
+ readonly slug: string;
14010
+ readonly name: string;
14011
+ }
13873
14012
  interface Onset {
13874
14013
  readonly type: "onset";
13875
14014
  readonly attributes: Attribute[];
@@ -13881,6 +14020,7 @@ declare namespace TailStream {
13881
14020
  readonly scriptName?: string;
13882
14021
  readonly scriptTags?: string[];
13883
14022
  readonly scriptVersion?: ScriptVersion;
14023
+ readonly preview?: TracePreviewInfo;
13884
14024
  readonly info:
13885
14025
  | FetchEventInfo
13886
14026
  | ConnectEventInfo
package/index.ts CHANGED
@@ -12048,6 +12048,140 @@ export declare type EmailExportedHandler<Env = unknown, Props = unknown> = (
12048
12048
  env: Env,
12049
12049
  ctx: ExecutionContext<Props>,
12050
12050
  ) => void | Promise<void>;
12051
+ /**
12052
+ * Evaluation context for targeting rules.
12053
+ * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12054
+ */
12055
+ export type EvaluationContext = Record<string, string | number | boolean>;
12056
+ export interface EvaluationDetails<T> {
12057
+ flagKey: string;
12058
+ value: T;
12059
+ variant?: string | undefined;
12060
+ reason?: string | undefined;
12061
+ errorCode?: string | undefined;
12062
+ errorMessage?: string | undefined;
12063
+ }
12064
+ export interface FlagEvaluationError extends Error {}
12065
+ /**
12066
+ * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12067
+ *
12068
+ * @example
12069
+ * ```typescript
12070
+ * // Get a boolean flag value with a default
12071
+ * const enabled = await env.FLAGS.getBooleanValue('my-feature', false);
12072
+ *
12073
+ * // Get a flag value with evaluation context for targeting
12074
+ * const variant = await env.FLAGS.getStringValue('experiment', 'control', {
12075
+ * userId: 'user-123',
12076
+ * country: 'US',
12077
+ * });
12078
+ *
12079
+ * // Get full evaluation details including variant and reason
12080
+ * const details = await env.FLAGS.getBooleanDetails('my-feature', false);
12081
+ * console.log(details.variant, details.reason);
12082
+ * ```
12083
+ */
12084
+ export declare abstract class Flags {
12085
+ /**
12086
+ * Get a flag value without type checking.
12087
+ * @param flagKey The key of the flag to evaluate.
12088
+ * @param defaultValue Optional default value returned when evaluation fails.
12089
+ * @param context Optional evaluation context for targeting rules.
12090
+ */
12091
+ get(
12092
+ flagKey: string,
12093
+ defaultValue?: unknown,
12094
+ context?: EvaluationContext,
12095
+ ): Promise<unknown>;
12096
+ /**
12097
+ * Get a boolean flag value.
12098
+ * @param flagKey The key of the flag to evaluate.
12099
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12100
+ * @param context Optional evaluation context for targeting rules.
12101
+ */
12102
+ getBooleanValue(
12103
+ flagKey: string,
12104
+ defaultValue: boolean,
12105
+ context?: EvaluationContext,
12106
+ ): Promise<boolean>;
12107
+ /**
12108
+ * Get a string flag value.
12109
+ * @param flagKey The key of the flag to evaluate.
12110
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12111
+ * @param context Optional evaluation context for targeting rules.
12112
+ */
12113
+ getStringValue(
12114
+ flagKey: string,
12115
+ defaultValue: string,
12116
+ context?: EvaluationContext,
12117
+ ): Promise<string>;
12118
+ /**
12119
+ * Get a number flag value.
12120
+ * @param flagKey The key of the flag to evaluate.
12121
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12122
+ * @param context Optional evaluation context for targeting rules.
12123
+ */
12124
+ getNumberValue(
12125
+ flagKey: string,
12126
+ defaultValue: number,
12127
+ context?: EvaluationContext,
12128
+ ): Promise<number>;
12129
+ /**
12130
+ * Get an object flag value.
12131
+ * @param flagKey The key of the flag to evaluate.
12132
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12133
+ * @param context Optional evaluation context for targeting rules.
12134
+ */
12135
+ getObjectValue<T extends object>(
12136
+ flagKey: string,
12137
+ defaultValue: T,
12138
+ context?: EvaluationContext,
12139
+ ): Promise<T>;
12140
+ /**
12141
+ * Get a boolean flag value with full evaluation details.
12142
+ * @param flagKey The key of the flag to evaluate.
12143
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12144
+ * @param context Optional evaluation context for targeting rules.
12145
+ */
12146
+ getBooleanDetails(
12147
+ flagKey: string,
12148
+ defaultValue: boolean,
12149
+ context?: EvaluationContext,
12150
+ ): Promise<EvaluationDetails<boolean>>;
12151
+ /**
12152
+ * Get a string flag value with full evaluation details.
12153
+ * @param flagKey The key of the flag to evaluate.
12154
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12155
+ * @param context Optional evaluation context for targeting rules.
12156
+ */
12157
+ getStringDetails(
12158
+ flagKey: string,
12159
+ defaultValue: string,
12160
+ context?: EvaluationContext,
12161
+ ): Promise<EvaluationDetails<string>>;
12162
+ /**
12163
+ * Get a number flag value with full evaluation details.
12164
+ * @param flagKey The key of the flag to evaluate.
12165
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12166
+ * @param context Optional evaluation context for targeting rules.
12167
+ */
12168
+ getNumberDetails(
12169
+ flagKey: string,
12170
+ defaultValue: number,
12171
+ context?: EvaluationContext,
12172
+ ): Promise<EvaluationDetails<number>>;
12173
+ /**
12174
+ * Get an object flag value with full evaluation details.
12175
+ * @param flagKey The key of the flag to evaluate.
12176
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12177
+ * @param context Optional evaluation context for targeting rules.
12178
+ */
12179
+ getObjectDetails<T extends object>(
12180
+ flagKey: string,
12181
+ defaultValue: T,
12182
+ context?: EvaluationContext,
12183
+ ): Promise<EvaluationDetails<T>>;
12184
+ }
12051
12185
  /**
12052
12186
  * Hello World binding to serve as an explanatory example. DO NOT USE
12053
12187
  */
@@ -13827,6 +13961,11 @@ export declare namespace TailStream {
13827
13961
  readonly tag?: string;
13828
13962
  readonly message?: string;
13829
13963
  }
13964
+ interface TracePreviewInfo {
13965
+ readonly id: string;
13966
+ readonly slug: string;
13967
+ readonly name: string;
13968
+ }
13830
13969
  interface Onset {
13831
13970
  readonly type: "onset";
13832
13971
  readonly attributes: Attribute[];
@@ -13838,6 +13977,7 @@ export declare namespace TailStream {
13838
13977
  readonly scriptName?: string;
13839
13978
  readonly scriptTags?: string[];
13840
13979
  readonly scriptVersion?: ScriptVersion;
13980
+ readonly preview?: TracePreviewInfo;
13841
13981
  readonly info:
13842
13982
  | FetchEventInfo
13843
13983
  | ConnectEventInfo
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "author": "Workers Community",
9
9
  "license": "MIT OR Apache-2.0",
10
- "version": "4.20260408.1",
10
+ "version": "4.20260409.1",
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./index.d.ts",