@contentful/optimization-api-client 2.1.0 → 2.2.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.d.mts CHANGED
@@ -343,9 +343,7 @@ declare const BatchExperienceEventArray: z.ZodMiniArray<z.ZodMiniDiscriminatedUn
343
343
  entityId: z.ZodMiniString<string>;
344
344
  entityKind: z.ZodMiniEnum<{
345
345
  Experience: "Experience";
346
- Fragment: "Fragment";
347
- InlineFragment: "InlineFragment";
348
- InlineComponent: "InlineComponent";
346
+ ExperienceFragment: "ExperienceFragment";
349
347
  }>;
350
348
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
351
349
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -913,9 +911,7 @@ declare const BatchInsightsEventArray: z.ZodMiniArray<z.ZodMiniObject<{
913
911
  entityId: z.ZodMiniString<string>;
914
912
  entityKind: z.ZodMiniEnum<{
915
913
  Experience: "Experience";
916
- Fragment: "Fragment";
917
- InlineFragment: "InlineFragment";
918
- InlineComponent: "InlineComponent";
914
+ ExperienceFragment: "ExperienceFragment";
919
915
  }>;
920
916
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
921
917
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -985,9 +981,7 @@ declare const BatchInsightsEventArray: z.ZodMiniArray<z.ZodMiniObject<{
985
981
  entityId: z.ZodMiniString<string>;
986
982
  entityKind: z.ZodMiniEnum<{
987
983
  Experience: "Experience";
988
- Fragment: "Fragment";
989
- InlineFragment: "InlineFragment";
990
- InlineComponent: "InlineComponent";
984
+ ExperienceFragment: "ExperienceFragment";
991
985
  }>;
992
986
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
993
987
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -1055,9 +1049,7 @@ declare const BatchInsightsEventArray: z.ZodMiniArray<z.ZodMiniObject<{
1055
1049
  entityId: z.ZodMiniString<string>;
1056
1050
  entityKind: z.ZodMiniEnum<{
1057
1051
  Experience: "Experience";
1058
- Fragment: "Fragment";
1059
- InlineFragment: "InlineFragment";
1060
- InlineComponent: "InlineComponent";
1052
+ ExperienceFragment: "ExperienceFragment";
1061
1053
  }>;
1062
1054
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
1063
1055
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -1293,6 +1285,7 @@ export declare class ExperienceApiClient extends ApiClientBase {
1293
1285
  private readonly enabledFeatures?;
1294
1286
  private readonly ip?;
1295
1287
  private locale?;
1288
+ private readonly location?;
1296
1289
  private readonly plainText?;
1297
1290
  private readonly preflight?;
1298
1291
  /**
@@ -1313,7 +1306,8 @@ export declare class ExperienceApiClient extends ApiClientBase {
1313
1306
  * Retrieves a profile by ID.
1314
1307
  *
1315
1308
  * @param id - The profile ID to retrieve.
1316
- * @param options - Optional request options. `preflight` and `plainText` are not allowed here.
1309
+ * @param options - Optional request options. `location`, `preflight`, and `plainText`
1310
+ * are not allowed here.
1317
1311
  * @returns The current optimization data for the profile.
1318
1312
  *
1319
1313
  * @throws Error
@@ -1326,7 +1320,7 @@ export declare class ExperienceApiClient extends ApiClientBase {
1326
1320
  * })
1327
1321
  * ```
1328
1322
  */
1329
- getProfile(id: string, options?: Omit<ExperienceApiClientRequestOptions, 'preflight' | 'plainText'>): Promise<OptimizationData>;
1323
+ getProfile(id: string, options?: Omit<ExperienceApiClientRequestOptions, 'location' | 'preflight' | 'plainText'>): Promise<OptimizationData>;
1330
1324
  /**
1331
1325
  * Sends a POST request to mutate a profile or profiles.
1332
1326
  *
@@ -1492,6 +1486,19 @@ export declare interface ExperienceApiClientRequestOptions {
1492
1486
  * When omitted, the API can use a server-side default.
1493
1487
  */
1494
1488
  locale?: string;
1489
+ /**
1490
+ * Request location for `createProfile()`, `updateProfile()`, and `upsertProfile()`.
1491
+ *
1492
+ * @remarks
1493
+ * A per-request value replaces the constructor default as a whole object.
1494
+ * The API merges each event's `context.location` over this request location.
1495
+ * An explicit `{}` overrides the constructor default and supplies an empty
1496
+ * request-location default instead of Cloudflare geolocation. When omitted
1497
+ * from both sources, existing API fallback behavior applies.
1498
+ * This affects evaluation and profile updates; it is not a permanent location lock.
1499
+ * For `upsertManyProfiles()`, use each event's `context.location` instead.
1500
+ */
1501
+ location?: GeoLocation;
1495
1502
  /**
1496
1503
  * When `true`, sends performance-critical endpoints in plain text.
1497
1504
  *
@@ -1732,9 +1739,7 @@ declare const ExperienceEventArray: z.ZodMiniArray<z.ZodMiniDiscriminatedUnion<[
1732
1739
  entityId: z.ZodMiniString<string>;
1733
1740
  entityKind: z.ZodMiniEnum<{
1734
1741
  Experience: "Experience";
1735
- Fragment: "Fragment";
1736
- InlineFragment: "InlineFragment";
1737
- InlineComponent: "InlineComponent";
1742
+ ExperienceFragment: "ExperienceFragment";
1738
1743
  }>;
1739
1744
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
1740
1745
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -2037,6 +2042,76 @@ export declare interface FetchMethodCallbackOptions {
2037
2042
  retriesLeft?: number;
2038
2043
  }
2039
2044
 
2045
+ /**
2046
+ * Zod schema describing geo-location properties for an event or singular profile request.
2047
+ *
2048
+ * @remarks
2049
+ * All properties are optional and can be derived from IP or device data.
2050
+ *
2051
+ * @public
2052
+ */
2053
+ declare const GeoLocation: z.ZodMiniObject<{
2054
+ /**
2055
+ * Geographical coordinates for the location.
2056
+ */
2057
+ coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
2058
+ /**
2059
+ * Latitude component of the coordinates.
2060
+ */
2061
+ latitude: z.ZodMiniNumber<number>;
2062
+ /**
2063
+ * Longitude component of the coordinates.
2064
+ */
2065
+ longitude: z.ZodMiniNumber<number>;
2066
+ }, z.core.$strip>>;
2067
+ /**
2068
+ * City name associated with the location.
2069
+ */
2070
+ city: z.ZodMiniOptional<z.ZodMiniString<string>>;
2071
+ /**
2072
+ * Postal or ZIP code associated with the location.
2073
+ */
2074
+ postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
2075
+ /**
2076
+ * Region or state name associated with the location.
2077
+ */
2078
+ region: z.ZodMiniOptional<z.ZodMiniString<string>>;
2079
+ /**
2080
+ * Region or state code associated with the location.
2081
+ */
2082
+ regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
2083
+ /**
2084
+ * Country name associated with the location.
2085
+ */
2086
+ country: z.ZodMiniOptional<z.ZodMiniString<string>>;
2087
+ /**
2088
+ * Country code associated with the location.
2089
+ *
2090
+ * @remarks
2091
+ * Validated to exactly COUNTRY_CODE_LENGTH characters, typically
2092
+ * an ISO 3166-1 alpha-2 code.
2093
+ */
2094
+ countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
2095
+ /**
2096
+ * Continent name associated with the location.
2097
+ */
2098
+ continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
2099
+ /**
2100
+ * Time zone identifier associated with the location.
2101
+ *
2102
+ * @remarks
2103
+ * Typically an IANA time zone string (e.g., `"Europe/Berlin"`).
2104
+ */
2105
+ timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
2106
+ }, z.core.$strip>;
2107
+
2108
+ /**
2109
+ * TypeScript type inferred from {@link GeoLocation}.
2110
+ *
2111
+ * @public
2112
+ */
2113
+ declare type GeoLocation = z.infer<typeof GeoLocation>;
2114
+
2040
2115
  /**
2041
2116
  * Properties that can be shared between global and per-client API configuration.
2042
2117
  *
package/dist/index.d.ts CHANGED
@@ -343,9 +343,7 @@ declare const BatchExperienceEventArray: z.ZodMiniArray<z.ZodMiniDiscriminatedUn
343
343
  entityId: z.ZodMiniString<string>;
344
344
  entityKind: z.ZodMiniEnum<{
345
345
  Experience: "Experience";
346
- Fragment: "Fragment";
347
- InlineFragment: "InlineFragment";
348
- InlineComponent: "InlineComponent";
346
+ ExperienceFragment: "ExperienceFragment";
349
347
  }>;
350
348
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
351
349
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -913,9 +911,7 @@ declare const BatchInsightsEventArray: z.ZodMiniArray<z.ZodMiniObject<{
913
911
  entityId: z.ZodMiniString<string>;
914
912
  entityKind: z.ZodMiniEnum<{
915
913
  Experience: "Experience";
916
- Fragment: "Fragment";
917
- InlineFragment: "InlineFragment";
918
- InlineComponent: "InlineComponent";
914
+ ExperienceFragment: "ExperienceFragment";
919
915
  }>;
920
916
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
921
917
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -985,9 +981,7 @@ declare const BatchInsightsEventArray: z.ZodMiniArray<z.ZodMiniObject<{
985
981
  entityId: z.ZodMiniString<string>;
986
982
  entityKind: z.ZodMiniEnum<{
987
983
  Experience: "Experience";
988
- Fragment: "Fragment";
989
- InlineFragment: "InlineFragment";
990
- InlineComponent: "InlineComponent";
984
+ ExperienceFragment: "ExperienceFragment";
991
985
  }>;
992
986
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
993
987
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -1055,9 +1049,7 @@ declare const BatchInsightsEventArray: z.ZodMiniArray<z.ZodMiniObject<{
1055
1049
  entityId: z.ZodMiniString<string>;
1056
1050
  entityKind: z.ZodMiniEnum<{
1057
1051
  Experience: "Experience";
1058
- Fragment: "Fragment";
1059
- InlineFragment: "InlineFragment";
1060
- InlineComponent: "InlineComponent";
1052
+ ExperienceFragment: "ExperienceFragment";
1061
1053
  }>;
1062
1054
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
1063
1055
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -1293,6 +1285,7 @@ export declare class ExperienceApiClient extends ApiClientBase {
1293
1285
  private readonly enabledFeatures?;
1294
1286
  private readonly ip?;
1295
1287
  private locale?;
1288
+ private readonly location?;
1296
1289
  private readonly plainText?;
1297
1290
  private readonly preflight?;
1298
1291
  /**
@@ -1313,7 +1306,8 @@ export declare class ExperienceApiClient extends ApiClientBase {
1313
1306
  * Retrieves a profile by ID.
1314
1307
  *
1315
1308
  * @param id - The profile ID to retrieve.
1316
- * @param options - Optional request options. `preflight` and `plainText` are not allowed here.
1309
+ * @param options - Optional request options. `location`, `preflight`, and `plainText`
1310
+ * are not allowed here.
1317
1311
  * @returns The current optimization data for the profile.
1318
1312
  *
1319
1313
  * @throws Error
@@ -1326,7 +1320,7 @@ export declare class ExperienceApiClient extends ApiClientBase {
1326
1320
  * })
1327
1321
  * ```
1328
1322
  */
1329
- getProfile(id: string, options?: Omit<ExperienceApiClientRequestOptions, 'preflight' | 'plainText'>): Promise<OptimizationData>;
1323
+ getProfile(id: string, options?: Omit<ExperienceApiClientRequestOptions, 'location' | 'preflight' | 'plainText'>): Promise<OptimizationData>;
1330
1324
  /**
1331
1325
  * Sends a POST request to mutate a profile or profiles.
1332
1326
  *
@@ -1492,6 +1486,19 @@ export declare interface ExperienceApiClientRequestOptions {
1492
1486
  * When omitted, the API can use a server-side default.
1493
1487
  */
1494
1488
  locale?: string;
1489
+ /**
1490
+ * Request location for `createProfile()`, `updateProfile()`, and `upsertProfile()`.
1491
+ *
1492
+ * @remarks
1493
+ * A per-request value replaces the constructor default as a whole object.
1494
+ * The API merges each event's `context.location` over this request location.
1495
+ * An explicit `{}` overrides the constructor default and supplies an empty
1496
+ * request-location default instead of Cloudflare geolocation. When omitted
1497
+ * from both sources, existing API fallback behavior applies.
1498
+ * This affects evaluation and profile updates; it is not a permanent location lock.
1499
+ * For `upsertManyProfiles()`, use each event's `context.location` instead.
1500
+ */
1501
+ location?: GeoLocation;
1495
1502
  /**
1496
1503
  * When `true`, sends performance-critical endpoints in plain text.
1497
1504
  *
@@ -1732,9 +1739,7 @@ declare const ExperienceEventArray: z.ZodMiniArray<z.ZodMiniDiscriminatedUnion<[
1732
1739
  entityId: z.ZodMiniString<string>;
1733
1740
  entityKind: z.ZodMiniEnum<{
1734
1741
  Experience: "Experience";
1735
- Fragment: "Fragment";
1736
- InlineFragment: "InlineFragment";
1737
- InlineComponent: "InlineComponent";
1742
+ ExperienceFragment: "ExperienceFragment";
1738
1743
  }>;
1739
1744
  entityKindId: z.ZodMiniOptional<z.ZodMiniString<string>>;
1740
1745
  entryIds: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
@@ -2037,6 +2042,76 @@ export declare interface FetchMethodCallbackOptions {
2037
2042
  retriesLeft?: number;
2038
2043
  }
2039
2044
 
2045
+ /**
2046
+ * Zod schema describing geo-location properties for an event or singular profile request.
2047
+ *
2048
+ * @remarks
2049
+ * All properties are optional and can be derived from IP or device data.
2050
+ *
2051
+ * @public
2052
+ */
2053
+ declare const GeoLocation: z.ZodMiniObject<{
2054
+ /**
2055
+ * Geographical coordinates for the location.
2056
+ */
2057
+ coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
2058
+ /**
2059
+ * Latitude component of the coordinates.
2060
+ */
2061
+ latitude: z.ZodMiniNumber<number>;
2062
+ /**
2063
+ * Longitude component of the coordinates.
2064
+ */
2065
+ longitude: z.ZodMiniNumber<number>;
2066
+ }, z.core.$strip>>;
2067
+ /**
2068
+ * City name associated with the location.
2069
+ */
2070
+ city: z.ZodMiniOptional<z.ZodMiniString<string>>;
2071
+ /**
2072
+ * Postal or ZIP code associated with the location.
2073
+ */
2074
+ postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
2075
+ /**
2076
+ * Region or state name associated with the location.
2077
+ */
2078
+ region: z.ZodMiniOptional<z.ZodMiniString<string>>;
2079
+ /**
2080
+ * Region or state code associated with the location.
2081
+ */
2082
+ regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
2083
+ /**
2084
+ * Country name associated with the location.
2085
+ */
2086
+ country: z.ZodMiniOptional<z.ZodMiniString<string>>;
2087
+ /**
2088
+ * Country code associated with the location.
2089
+ *
2090
+ * @remarks
2091
+ * Validated to exactly COUNTRY_CODE_LENGTH characters, typically
2092
+ * an ISO 3166-1 alpha-2 code.
2093
+ */
2094
+ countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
2095
+ /**
2096
+ * Continent name associated with the location.
2097
+ */
2098
+ continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
2099
+ /**
2100
+ * Time zone identifier associated with the location.
2101
+ *
2102
+ * @remarks
2103
+ * Typically an IANA time zone string (e.g., `"Europe/Berlin"`).
2104
+ */
2105
+ timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
2106
+ }, z.core.$strip>;
2107
+
2108
+ /**
2109
+ * TypeScript type inferred from {@link GeoLocation}.
2110
+ *
2111
+ * @public
2112
+ */
2113
+ declare type GeoLocation = z.infer<typeof GeoLocation>;
2114
+
2040
2115
  /**
2041
2116
  * Properties that can be shared between global and per-client API configuration.
2042
2117
  *
package/dist/index.mjs CHANGED
@@ -159,15 +159,17 @@ class ExperienceApiClient extends src_ApiClientBase {
159
159
  enabledFeatures;
160
160
  ip;
161
161
  locale;
162
+ location;
162
163
  plainText;
163
164
  preflight;
164
165
  constructor(config){
165
166
  super('Experience', config);
166
- const { baseUrl, enabledFeatures, ip, locale, plainText, preflight } = config;
167
+ const { baseUrl, enabledFeatures, ip, locale, location, plainText, preflight } = config;
167
168
  this.baseUrl = baseUrl || EXPERIENCE_BASE_URL;
168
169
  this.enabledFeatures = enabledFeatures;
169
170
  this.ip = ip;
170
171
  this.locale = locale;
172
+ this.location = location;
171
173
  this.plainText = plainText;
172
174
  this.preflight = preflight;
173
175
  }
@@ -319,9 +321,12 @@ class ExperienceApiClient extends src_ApiClientBase {
319
321
  return bodyOptions;
320
322
  };
321
323
  constructExperienceRequestBody(events, options) {
324
+ const bodyOptions = this.constructBodyOptions(options);
325
+ const location = options.location ?? this.location;
326
+ if (void 0 !== location) bodyOptions.location = location;
322
327
  return ExperienceRequestData.parse({
323
328
  events: parseWithFriendlyError(ExperienceEventArray, events),
324
- options: this.constructBodyOptions(options)
329
+ options: bodyOptions
325
330
  });
326
331
  }
327
332
  }