Skip to content

Commit

Permalink
fix: limits are enforced server-side. While 12 is the default, it can…
Browse files Browse the repository at this point in the history
… be increased on request, and enforcement on the client-side becomes incorrect.
  • Loading branch information
danpat committed Aug 2, 2023
1 parent 54d95db commit 35c684e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- **Fix:** Maximum Optimization V1 request size limits should not be enforced client-side

## 0.15.2

- **Add:** Add `depart_at` and `arrive_by` as optional parameters in the directions service
Expand Down
2 changes: 1 addition & 1 deletion docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,7 @@ to understand all of the available options.
* `config` **[Object][207]** 

* `config.profile` **(`"driving"` | `"driving-traffic"` | `"walking"` | `"cycling"`)** (optional, default `"driving"`)
* `config.waypoints` **[Array][216]<[OptimizationWaypoint][180]>** An ordered array of [`OptimizationWaypoint`][180] objects, between 2 and 12 (inclusive).
* `config.waypoints` **[Array][216]<[OptimizationWaypoint][180]>** An ordered array of [`OptimizationWaypoint`][180] objects, with at least 2
* `config.annotations` **[Array][216]<(`"duration"` | `"distance"` | `"speed"`)>?** Specify additional metadata that should be returned.
* `config.destination` **(`"any"` | `"last"`)** Returned route ends at `any` or `last` coordinate. (optional, default `"any"`)
* `config.distributions` **[Array][216]<[Distribution][203]>?** An ordered array of [`Distribution`][203] objects, each of which includes a `pickup` and `dropoff` property. `pickup` and `dropoff` properties correspond to an index in the OptimizationWaypoint array.
Expand Down
2 changes: 1 addition & 1 deletion services/__tests__/optimization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('getOptimization', () => {
},
error => {
expect(error.message).toMatch(
'waypoints must include between 2 and 12 OptimizationWaypoints'
'waypoints must include at least 2 OptimizationWaypoints'
);
}
);
Expand Down
6 changes: 3 additions & 3 deletions services/optimization.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var Optimization = {};
*
* @param {Object} config
* @param {'driving'|'driving-traffic'|'walking'|'cycling'} [config.profile="driving"]
* @param {Array<OptimizationWaypoint>} config.waypoints - An ordered array of [`OptimizationWaypoint`](#optimizationwaypoint) objects, between 2 and 12 (inclusive).
* @param {Array<OptimizationWaypoint>} config.waypoints - An ordered array of [`OptimizationWaypoint`](#optimizationwaypoint) objects, with at least 2
* @param {Array<'duration'|'distance'|'speed'>} [config.annotations] - Specify additional metadata that should be returned.
* @param {'any'|'last'} [config.destination="any"] - Returned route ends at `any` or `last` coordinate.
* @param {Array<Distribution>} [config.distributions] - An ordered array of [`Distribution`](#distribution) objects, each of which includes a `pickup` and `dropoff` property. `pickup` and `dropoff` properties correspond to an index in the OptimizationWaypoint array.
Expand Down Expand Up @@ -72,9 +72,9 @@ Optimization.getOptimization = function(config) {
};

var waypointCount = config.waypoints.length;
if (waypointCount < 2 || waypointCount > 12) {
if (waypointCount < 2) {
throw new Error(
'waypoints must include between 2 and 12 OptimizationWaypoints'
'waypoints must include at least 2 OptimizationWaypoints'
);
}

Expand Down

0 comments on commit 35c684e

Please sign in to comment.