diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/AddApiKeyResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/AddApiKeyResponse.java index f597283044..0de446c362 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/AddApiKeyResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/AddApiKeyResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** AddApiKeyResponse */ @@ -11,7 +10,7 @@ public class AddApiKeyResponse { private String key; @SerializedName("createdAt") - private OffsetDateTime createdAt; + private String createdAt; public AddApiKeyResponse key(String key) { this.key = key; @@ -32,7 +31,7 @@ public void setKey(String key) { this.key = key; } - public AddApiKeyResponse createdAt(OffsetDateTime createdAt) { + public AddApiKeyResponse createdAt(String createdAt) { this.createdAt = createdAt; return this; } @@ -43,11 +42,11 @@ public AddApiKeyResponse createdAt(OffsetDateTime createdAt) { * @return createdAt */ @javax.annotation.Nonnull - public OffsetDateTime getCreatedAt() { + public String getCreatedAt() { return createdAt; } - public void setCreatedAt(OffsetDateTime createdAt) { + public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtObject.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtObject.java index 46f36a6d9f..f8a04ae4f0 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtObject.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtObject.java @@ -1,16 +1,15 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** CreatedAtObject */ public class CreatedAtObject { @SerializedName("createdAt") - private OffsetDateTime createdAt; + private String createdAt; - public CreatedAtObject createdAt(OffsetDateTime createdAt) { + public CreatedAtObject createdAt(String createdAt) { this.createdAt = createdAt; return this; } @@ -21,11 +20,11 @@ public CreatedAtObject createdAt(OffsetDateTime createdAt) { * @return createdAt */ @javax.annotation.Nonnull - public OffsetDateTime getCreatedAt() { + public String getCreatedAt() { return createdAt; } - public void setCreatedAt(OffsetDateTime createdAt) { + public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtResponse.java index 2a943a47c2..2dcbfd7c2f 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/CreatedAtResponse.java @@ -1,16 +1,15 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** The response with a createdAt timestamp. */ public class CreatedAtResponse { @SerializedName("createdAt") - private OffsetDateTime createdAt; + private String createdAt; - public CreatedAtResponse createdAt(OffsetDateTime createdAt) { + public CreatedAtResponse createdAt(String createdAt) { this.createdAt = createdAt; return this; } @@ -21,11 +20,11 @@ public CreatedAtResponse createdAt(OffsetDateTime createdAt) { * @return createdAt */ @javax.annotation.Nonnull - public OffsetDateTime getCreatedAt() { + public String getCreatedAt() { return createdAt; } - public void setCreatedAt(OffsetDateTime createdAt) { + public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteApiKeyResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteApiKeyResponse.java index 89f0801640..7f2ce42eff 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteApiKeyResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteApiKeyResponse.java @@ -1,16 +1,15 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** DeleteApiKeyResponse */ public class DeleteApiKeyResponse { @SerializedName("deletedAt") - private OffsetDateTime deletedAt; + private String deletedAt; - public DeleteApiKeyResponse deletedAt(OffsetDateTime deletedAt) { + public DeleteApiKeyResponse deletedAt(String deletedAt) { this.deletedAt = deletedAt; return this; } @@ -21,11 +20,11 @@ public DeleteApiKeyResponse deletedAt(OffsetDateTime deletedAt) { * @return deletedAt */ @javax.annotation.Nonnull - public OffsetDateTime getDeletedAt() { + public String getDeletedAt() { return deletedAt; } - public void setDeletedAt(OffsetDateTime deletedAt) { + public void setDeletedAt(String deletedAt) { this.deletedAt = deletedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteSourceResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteSourceResponse.java index 956480b2e1..e68fac932e 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteSourceResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeleteSourceResponse.java @@ -1,16 +1,15 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** DeleteSourceResponse */ public class DeleteSourceResponse { @SerializedName("deletedAt") - private OffsetDateTime deletedAt; + private String deletedAt; - public DeleteSourceResponse deletedAt(OffsetDateTime deletedAt) { + public DeleteSourceResponse deletedAt(String deletedAt) { this.deletedAt = deletedAt; return this; } @@ -21,11 +20,11 @@ public DeleteSourceResponse deletedAt(OffsetDateTime deletedAt) { * @return deletedAt */ @javax.annotation.Nonnull - public OffsetDateTime getDeletedAt() { + public String getDeletedAt() { return deletedAt; } - public void setDeletedAt(OffsetDateTime deletedAt) { + public void setDeletedAt(String deletedAt) { this.deletedAt = deletedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeletedAtResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeletedAtResponse.java index 75284d1c38..352e3f257d 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeletedAtResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/DeletedAtResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** The response with a taskID and a deletedAt timestamp. */ @@ -11,7 +10,7 @@ public class DeletedAtResponse { private Integer taskID; @SerializedName("deletedAt") - private OffsetDateTime deletedAt; + private String deletedAt; public DeletedAtResponse taskID(Integer taskID) { this.taskID = taskID; @@ -32,7 +31,7 @@ public void setTaskID(Integer taskID) { this.taskID = taskID; } - public DeletedAtResponse deletedAt(OffsetDateTime deletedAt) { + public DeletedAtResponse deletedAt(String deletedAt) { this.deletedAt = deletedAt; return this; } @@ -43,11 +42,11 @@ public DeletedAtResponse deletedAt(OffsetDateTime deletedAt) { * @return deletedAt */ @javax.annotation.Nonnull - public OffsetDateTime getDeletedAt() { + public String getDeletedAt() { return deletedAt; } - public void setDeletedAt(OffsetDateTime deletedAt) { + public void setDeletedAt(String deletedAt) { this.deletedAt = deletedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/Index.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/Index.java index 5a4e51c4cd..9c3eb8dcbb 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/Index.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/Index.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -13,10 +12,10 @@ public class Index { private String name; @SerializedName("createdAt") - private OffsetDateTime createdAt; + private String createdAt; @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; @SerializedName("entries") private Integer entries; @@ -61,7 +60,7 @@ public void setName(String name) { this.name = name; } - public Index createdAt(OffsetDateTime createdAt) { + public Index createdAt(String createdAt) { this.createdAt = createdAt; return this; } @@ -72,15 +71,15 @@ public Index createdAt(OffsetDateTime createdAt) { * @return createdAt */ @javax.annotation.Nonnull - public OffsetDateTime getCreatedAt() { + public String getCreatedAt() { return createdAt; } - public void setCreatedAt(OffsetDateTime createdAt) { + public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } - public Index updatedAt(OffsetDateTime updatedAt) { + public Index updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -91,11 +90,11 @@ public Index updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nonnull - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/KeyObject.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/KeyObject.java index e86970b8d1..c73e7725fd 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/KeyObject.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/KeyObject.java @@ -6,7 +6,6 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -110,7 +109,7 @@ public AclEnum read(final JsonReader jsonReader) throws IOException { private Integer validity = 0; @SerializedName("createdAt") - private OffsetDateTime createdAt; + private String createdAt; public KeyObject acl(List acl) { this.acl = acl; @@ -289,7 +288,7 @@ public void setValidity(Integer validity) { this.validity = validity; } - public KeyObject createdAt(OffsetDateTime createdAt) { + public KeyObject createdAt(String createdAt) { this.createdAt = createdAt; return this; } @@ -300,11 +299,11 @@ public KeyObject createdAt(OffsetDateTime createdAt) { * @return createdAt */ @javax.annotation.Nonnull - public OffsetDateTime getCreatedAt() { + public String getCreatedAt() { return createdAt; } - public void setCreatedAt(OffsetDateTime createdAt) { + public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/RemoveUserIdResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/RemoveUserIdResponse.java index 968a4f4f20..149e60ba4a 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/RemoveUserIdResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/RemoveUserIdResponse.java @@ -1,16 +1,15 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** RemoveUserIdResponse */ public class RemoveUserIdResponse { @SerializedName("deletedAt") - private OffsetDateTime deletedAt; + private String deletedAt; - public RemoveUserIdResponse deletedAt(OffsetDateTime deletedAt) { + public RemoveUserIdResponse deletedAt(String deletedAt) { this.deletedAt = deletedAt; return this; } @@ -21,11 +20,11 @@ public RemoveUserIdResponse deletedAt(OffsetDateTime deletedAt) { * @return deletedAt */ @javax.annotation.Nonnull - public OffsetDateTime getDeletedAt() { + public String getDeletedAt() { return deletedAt; } - public void setDeletedAt(OffsetDateTime deletedAt) { + public void setDeletedAt(String deletedAt) { this.deletedAt = deletedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/ReplaceSourceResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/ReplaceSourceResponse.java index 85d8133b4f..8d119c34ec 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/ReplaceSourceResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/ReplaceSourceResponse.java @@ -1,16 +1,15 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** ReplaceSourceResponse */ public class ReplaceSourceResponse { @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; - public ReplaceSourceResponse updatedAt(OffsetDateTime updatedAt) { + public ReplaceSourceResponse updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -21,11 +20,11 @@ public ReplaceSourceResponse updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nonnull - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SaveSynonymResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SaveSynonymResponse.java index 0563f85da2..00dcf13768 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SaveSynonymResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SaveSynonymResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** SaveSynonymResponse */ @@ -11,7 +10,7 @@ public class SaveSynonymResponse { private Integer taskID; @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; @SerializedName("id") private String id; @@ -35,7 +34,7 @@ public void setTaskID(Integer taskID) { this.taskID = taskID; } - public SaveSynonymResponse updatedAt(OffsetDateTime updatedAt) { + public SaveSynonymResponse updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -46,11 +45,11 @@ public SaveSynonymResponse updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nonnull - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SearchUserIdsResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SearchUserIdsResponse.java index e60d28978b..fa4aba4b7d 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SearchUserIdsResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/SearchUserIdsResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -22,7 +21,7 @@ public class SearchUserIdsResponse { private Integer hitsPerPage = 20; @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; public SearchUserIdsResponse hits(List hits) { this.hits = hits; @@ -105,7 +104,7 @@ public void setHitsPerPage(Integer hitsPerPage) { this.hitsPerPage = hitsPerPage; } - public SearchUserIdsResponse updatedAt(OffsetDateTime updatedAt) { + public SearchUserIdsResponse updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -116,11 +115,11 @@ public SearchUserIdsResponse updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nonnull - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdateApiKeyResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdateApiKeyResponse.java index 434f5ac340..6dd34ac8e0 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdateApiKeyResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdateApiKeyResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** UpdateApiKeyResponse */ @@ -11,7 +10,7 @@ public class UpdateApiKeyResponse { private String key; @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; public UpdateApiKeyResponse key(String key) { this.key = key; @@ -32,7 +31,7 @@ public void setKey(String key) { this.key = key; } - public UpdateApiKeyResponse updatedAt(OffsetDateTime updatedAt) { + public UpdateApiKeyResponse updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -43,11 +42,11 @@ public UpdateApiKeyResponse updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nonnull - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtResponse.java index c0f5835a62..acea12958d 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** The response with a taskID and an updatedAt timestamp. */ @@ -11,7 +10,7 @@ public class UpdatedAtResponse { private Integer taskID; @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; public UpdatedAtResponse taskID(Integer taskID) { this.taskID = taskID; @@ -32,7 +31,7 @@ public void setTaskID(Integer taskID) { this.taskID = taskID; } - public UpdatedAtResponse updatedAt(OffsetDateTime updatedAt) { + public UpdatedAtResponse updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -43,11 +42,11 @@ public UpdatedAtResponse updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nonnull - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtWithObjectIdResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtWithObjectIdResponse.java index b058f27880..c3dcc83580 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtWithObjectIdResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedAtWithObjectIdResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** The response with a taskID, an objectID and an updatedAt timestamp. */ @@ -11,7 +10,7 @@ public class UpdatedAtWithObjectIdResponse { private Integer taskID; @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; @SerializedName("objectID") private String objectID; @@ -35,7 +34,7 @@ public void setTaskID(Integer taskID) { this.taskID = taskID; } - public UpdatedAtWithObjectIdResponse updatedAt(OffsetDateTime updatedAt) { + public UpdatedAtWithObjectIdResponse updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -46,11 +45,11 @@ public UpdatedAtWithObjectIdResponse updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nullable - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedRuleResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedRuleResponse.java index b45fb4d9c1..b0e87465e2 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedRuleResponse.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/model/UpdatedRuleResponse.java @@ -1,7 +1,6 @@ package com.algolia.model; import com.google.gson.annotations.SerializedName; -import java.time.OffsetDateTime; import java.util.Objects; /** UpdatedRuleResponse */ @@ -11,7 +10,7 @@ public class UpdatedRuleResponse { private String objectID; @SerializedName("updatedAt") - private OffsetDateTime updatedAt; + private String updatedAt; @SerializedName("taskID") private Integer taskID; @@ -35,7 +34,7 @@ public void setObjectID(String objectID) { this.objectID = objectID; } - public UpdatedRuleResponse updatedAt(OffsetDateTime updatedAt) { + public UpdatedRuleResponse updatedAt(String updatedAt) { this.updatedAt = updatedAt; return this; } @@ -46,11 +45,11 @@ public UpdatedRuleResponse updatedAt(OffsetDateTime updatedAt) { * @return updatedAt */ @javax.annotation.Nonnull - public OffsetDateTime getUpdatedAt() { + public String getUpdatedAt() { return updatedAt; } - public void setUpdatedAt(OffsetDateTime updatedAt) { + public void setUpdatedAt(String updatedAt) { this.updatedAt = updatedAt; } diff --git a/clients/algoliasearch-client-javascript/client-abtesting/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-abtesting/.openapi-generator-ignore index abfb5c9516..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/client-abtesting/.openapi-generator-ignore @@ -5,3 +5,4 @@ # The patterns follow closely to .gitignore or .dockerignore. git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/client-abtesting/api.ts b/clients/algoliasearch-client-javascript/client-abtesting/api.ts index 59b02c4607..c4759f623a 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/api.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/api.ts @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './src/apis'; -export * from './model/models'; diff --git a/clients/algoliasearch-client-javascript/client-abtesting/model/aBTest.ts b/clients/algoliasearch-client-javascript/client-abtesting/model/aBTest.ts index 6dfba5c6bd..3d076739f6 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/model/aBTest.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/model/aBTest.ts @@ -16,11 +16,11 @@ export type ABTest = { /** * End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. */ - endAt: Date; + endAt: string; /** * End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. */ - createdAt: Date; + createdAt: string; /** * A/B test name. */ diff --git a/clients/algoliasearch-client-javascript/client-abtesting/model/addABTestsResponse.ts b/clients/algoliasearch-client-javascript/client-abtesting/model/aBTestResponse.ts similarity index 84% rename from clients/algoliasearch-client-javascript/client-abtesting/model/addABTestsResponse.ts rename to clients/algoliasearch-client-javascript/client-abtesting/model/aBTestResponse.ts index a1e4926917..bf211fd44d 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/model/addABTestsResponse.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/model/aBTestResponse.ts @@ -1,4 +1,4 @@ -export type AddABTestsResponse = { +export type ABTestResponse = { /** * The index performing the A/B test. */ diff --git a/clients/algoliasearch-client-javascript/client-abtesting/model/addABTestsRequest.ts b/clients/algoliasearch-client-javascript/client-abtesting/model/addABTestsRequest.ts index af4a4da74d..7f06f24a37 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/model/addABTestsRequest.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/model/addABTestsRequest.ts @@ -12,5 +12,5 @@ export type AddABTestsRequest = { /** * End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. */ - endAt: Date; + endAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-abtesting/model/models.ts b/clients/algoliasearch-client-javascript/client-abtesting/model/models.ts deleted file mode 100644 index 590e0ab716..0000000000 --- a/clients/algoliasearch-client-javascript/client-abtesting/model/models.ts +++ /dev/null @@ -1,52 +0,0 @@ -/* eslint-disable no-param-reassign */ -import type { RequestOptions } from '../utils/types'; - -export * from './aBTest'; -export * from './abTestsVariant'; -export * from './abTestsVariantSearchParams'; -export * from './addABTestsRequest'; -export * from './addABTestsResponse'; -export * from './addABTestsVariant'; -export * from './customSearchParams'; -export * from './errorBase'; -export * from './listABTestsResponse'; -export * from './variant'; - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest: (requestOptions: RequestOptions) => Promise | void; -} - -export class ApiKeyAuth implements Authentication { - apiKey: string = ''; - - constructor(private location: string, private paramName: string) {} - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === 'query') { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if ( - this.location === 'header' && - requestOptions && - requestOptions.headers - ) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if ( - this.location === 'cookie' && - requestOptions && - requestOptions.headers - ) { - if (requestOptions.headers.Cookie) { - requestOptions.headers.Cookie += `; ${ - this.paramName - }=${encodeURIComponent(this.apiKey)}`; - } else { - requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( - this.apiKey - )}`; - } - } - } -} diff --git a/clients/algoliasearch-client-javascript/client-abtesting/src/abtestingApi.ts b/clients/algoliasearch-client-javascript/client-abtesting/src/abtestingApi.ts index eb60340fb2..448a23cf87 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/src/abtestingApi.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/src/abtestingApi.ts @@ -1,38 +1,44 @@ import type { ABTest } from '../model/aBTest'; +import type { ABTestResponse } from '../model/aBTestResponse'; import type { AddABTestsRequest } from '../model/addABTestsRequest'; -import type { AddABTestsResponse } from '../model/addABTestsResponse'; import type { ListABTestsResponse } from '../model/listABTestsResponse'; -import { ApiKeyAuth } from '../model/models'; import { Transporter } from '../utils/Transporter'; import type { Requester } from '../utils/requester/Requester'; import type { Headers, Host, Request, RequestOptions } from '../utils/types'; -export enum AbtestingApiKeys { - apiKey, - appId, -} - export class AbtestingApi { protected authentications = { - apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), - appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', }; private transporter: Transporter; - private sendRequest( - request: Request, + private applyAuthenticationHeaders( requestOptions: RequestOptions - ): Promise { - if (this.authentications.apiKey.apiKey) { - this.authentications.apiKey.applyToRequest(requestOptions); + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; } - if (this.authentications.appId.apiKey) { - this.authentications.appId.applyToRequest(requestOptions); - } + return requestOptions; + } - return this.transporter.request(request, requestOptions); + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -41,8 +47,7 @@ export class AbtestingApi { region: 'de' | 'us', options?: { requester?: Requester; hosts?: Host[] } ) { - this.setApiKey(AbtestingApiKeys.appId, appId); - this.setApiKey(AbtestingApiKeys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts(region), @@ -77,8 +82,11 @@ export class AbtestingApi { this.transporter.setHosts(hosts); } - setApiKey(key: AbtestingApiKeys, value: string): void { - this.authentications[AbtestingApiKeys[key]].apiKey = value; + setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } /** @@ -87,9 +95,7 @@ export class AbtestingApi { * @summary Creates a new A/B test with provided configuration. * @param addABTestsRequest - The addABTestsRequest object. */ - addABTests( - addABTestsRequest: AddABTestsRequest - ): Promise { + addABTests(addABTestsRequest: AddABTestsRequest): Promise { const path = '/2/abtests'; const headers: Headers = { Accept: 'application/json' }; const queryParameters: Record = {}; @@ -145,7 +151,7 @@ export class AbtestingApi { * @param deleteABTest - The deleteABTest object. * @param deleteABTest.id - The A/B test ID. */ - deleteABTest({ id }: DeleteABTestProps): Promise> { + deleteABTest({ id }: DeleteABTestProps): Promise { const path = '/2/abtests/{id}'.replace( '{id}', encodeURIComponent(String(id)) @@ -247,7 +253,7 @@ export class AbtestingApi { * @param stopABTest - The stopABTest object. * @param stopABTest.id - The A/B test ID. */ - stopABTest({ id }: StopABTestProps): Promise> { + stopABTest({ id }: StopABTestProps): Promise { const path = '/2/abtests/{id}/stop'.replace( '{id}', encodeURIComponent(String(id)) diff --git a/clients/algoliasearch-client-javascript/client-abtesting/src/apis.ts b/clients/algoliasearch-client-javascript/client-abtesting/src/apis.ts index 29e816fe40..8709c6154e 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/src/apis.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/src/apis.ts @@ -3,5 +3,6 @@ import { AbtestingApi } from './abtestingApi'; export * from './abtestingApi'; export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [AbtestingApi]; diff --git a/clients/algoliasearch-client-javascript/client-abtesting/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-abtesting/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/client-abtesting/utils/types.ts b/clients/algoliasearch-client-javascript/client-abtesting/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/client-abtesting/utils/types.ts +++ b/clients/algoliasearch-client-javascript/client-abtesting/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/clients/algoliasearch-client-javascript/client-analytics/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-analytics/.openapi-generator-ignore index abfb5c9516..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/client-analytics/.openapi-generator-ignore @@ -5,3 +5,4 @@ # The patterns follow closely to .gitignore or .dockerignore. git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/client-analytics/api.ts b/clients/algoliasearch-client-javascript/client-analytics/api.ts index 59b02c4607..c4759f623a 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/api.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/api.ts @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './src/apis'; -export * from './model/models'; diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/getAverageClickPositionResponseDates.ts b/clients/algoliasearch-client-javascript/client-analytics/model/getAverageClickPositionResponseDates.ts index 254d109ae3..297387383b 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/model/getAverageClickPositionResponseDates.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/model/getAverageClickPositionResponseDates.ts @@ -10,5 +10,5 @@ export type GetAverageClickPositionResponseDates = { /** * Date of the event. */ - date: Date; + date: string; }; diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/getClickThroughRateResponseDates.ts b/clients/algoliasearch-client-javascript/client-analytics/model/getClickThroughRateResponseDates.ts index 583a46fda8..4b512e006a 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/model/getClickThroughRateResponseDates.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/model/getClickThroughRateResponseDates.ts @@ -14,5 +14,5 @@ export type GetClickThroughRateResponseDates = { /** * Date of the event. */ - date: Date; + date: string; }; diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/getConversationRateResponseDates.ts b/clients/algoliasearch-client-javascript/client-analytics/model/getConversationRateResponseDates.ts index 6898f53d8e..bee3367b80 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/model/getConversationRateResponseDates.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/model/getConversationRateResponseDates.ts @@ -14,5 +14,5 @@ export type GetConversationRateResponseDates = { /** * Date of the event. */ - date: Date; + date: string; }; diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/getNoClickRateResponseDates.ts b/clients/algoliasearch-client-javascript/client-analytics/model/getNoClickRateResponseDates.ts index df727c85e7..72692149c5 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/model/getNoClickRateResponseDates.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/model/getNoClickRateResponseDates.ts @@ -14,5 +14,5 @@ export type GetNoClickRateResponseDates = { /** * Date of the event. */ - date: Date; + date: string; }; diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/getNoResultsRateResponseDates.ts b/clients/algoliasearch-client-javascript/client-analytics/model/getNoResultsRateResponseDates.ts index 63a4bfab3e..01856b0b0a 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/model/getNoResultsRateResponseDates.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/model/getNoResultsRateResponseDates.ts @@ -2,7 +2,7 @@ export type GetNoResultsRateResponseDates = { /** * Date of the event. */ - date: Date; + date: string; /** * The number of occurrences. */ diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/getSearchesCountResponseDates.ts b/clients/algoliasearch-client-javascript/client-analytics/model/getSearchesCountResponseDates.ts index 3be77438c1..096b1f055e 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/model/getSearchesCountResponseDates.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/model/getSearchesCountResponseDates.ts @@ -2,7 +2,7 @@ export type GetSearchesCountResponseDates = { /** * Date of the event. */ - date: Date; + date: string; /** * The number of occurrences. */ diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/getStatusResponse.ts b/clients/algoliasearch-client-javascript/client-analytics/model/getStatusResponse.ts index 8cae298049..379fff0845 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/model/getStatusResponse.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/model/getStatusResponse.ts @@ -2,5 +2,5 @@ export type GetStatusResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-analytics/model/models.ts b/clients/algoliasearch-client-javascript/client-analytics/model/models.ts deleted file mode 100644 index f651efbaeb..0000000000 --- a/clients/algoliasearch-client-javascript/client-analytics/model/models.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* eslint-disable no-param-reassign */ -import type { RequestOptions } from '../utils/types'; - -export * from './errorBase'; -export * from './getAverageClickPositionResponse'; -export * from './getAverageClickPositionResponseDates'; -export * from './getClickPositionsResponse'; -export * from './getClickPositionsResponsePositions'; -export * from './getClickThroughRateResponse'; -export * from './getClickThroughRateResponseDates'; -export * from './getConversationRateResponse'; -export * from './getConversationRateResponseDates'; -export * from './getNoClickRateResponse'; -export * from './getNoClickRateResponseDates'; -export * from './getNoResultsRateResponse'; -export * from './getNoResultsRateResponseDates'; -export * from './getSearchesCountResponse'; -export * from './getSearchesCountResponseDates'; -export * from './getSearchesNoClicksResponse'; -export * from './getSearchesNoClicksResponseSearches'; -export * from './getSearchesNoResultsResponse'; -export * from './getSearchesNoResultsResponseSearches'; -export * from './getStatusResponse'; -export * from './getTopCountriesResponse'; -export * from './getTopCountriesResponseCountries'; -export * from './getTopFilterAttribute'; -export * from './getTopFilterAttributesResponse'; -export * from './getTopFilterForAttribute'; -export * from './getTopFilterForAttributeResponse'; -export * from './getTopFiltersNoResultsResponse'; -export * from './getTopFiltersNoResultsValue'; -export * from './getTopFiltersNoResultsValues'; -export * from './getTopHitsResponse'; -export * from './getTopHitsResponseHits'; -export * from './getTopHitsResponseWithAnalytics'; -export * from './getTopHitsResponseWithAnalyticsHits'; -export * from './getTopSearchesResponse'; -export * from './getTopSearchesResponseWithAnalytics'; -export * from './getTopSearchesResponseWithAnalyticsSearches'; -export * from './getUsersCountResponse'; - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest: (requestOptions: RequestOptions) => Promise | void; -} - -export class ApiKeyAuth implements Authentication { - apiKey: string = ''; - - constructor(private location: string, private paramName: string) {} - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === 'query') { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if ( - this.location === 'header' && - requestOptions && - requestOptions.headers - ) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if ( - this.location === 'cookie' && - requestOptions && - requestOptions.headers - ) { - if (requestOptions.headers.Cookie) { - requestOptions.headers.Cookie += `; ${ - this.paramName - }=${encodeURIComponent(this.apiKey)}`; - } else { - requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( - this.apiKey - )}`; - } - } - } -} diff --git a/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts b/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts index 3fca6989b5..722c9bc070 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts @@ -17,37 +17,43 @@ import type { GetTopHitsResponseWithAnalytics } from '../model/getTopHitsRespons import type { GetTopSearchesResponse } from '../model/getTopSearchesResponse'; import type { GetTopSearchesResponseWithAnalytics } from '../model/getTopSearchesResponseWithAnalytics'; import type { GetUsersCountResponse } from '../model/getUsersCountResponse'; -import { ApiKeyAuth } from '../model/models'; import { Transporter } from '../utils/Transporter'; import type { Requester } from '../utils/requester/Requester'; import type { Headers, Host, Request, RequestOptions } from '../utils/types'; -export enum AnalyticsApiKeys { - apiKey, - appId, -} - export class AnalyticsApi { protected authentications = { - apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), - appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', }; private transporter: Transporter; + private applyAuthenticationHeaders( + requestOptions: RequestOptions + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; + } + + return requestOptions; + } + private sendRequest( request: Request, requestOptions: RequestOptions ): Promise { - if (this.authentications.apiKey.apiKey) { - this.authentications.apiKey.applyToRequest(requestOptions); - } - - if (this.authentications.appId.apiKey) { - this.authentications.appId.applyToRequest(requestOptions); - } - - return this.transporter.request(request, requestOptions); + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -56,8 +62,7 @@ export class AnalyticsApi { region: 'de' | 'us', options?: { requester?: Requester; hosts?: Host[] } ) { - this.setApiKey(AnalyticsApiKeys.appId, appId); - this.setApiKey(AnalyticsApiKeys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts(region), @@ -92,8 +97,11 @@ export class AnalyticsApi { this.transporter.setHosts(hosts); } - setApiKey(key: AnalyticsApiKeys, value: string): void { - this.authentications[AnalyticsApiKeys[key]].apiKey = value; + setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } /** diff --git a/clients/algoliasearch-client-javascript/client-analytics/src/apis.ts b/clients/algoliasearch-client-javascript/client-analytics/src/apis.ts index d7b69922f7..9f62c9c515 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/src/apis.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/src/apis.ts @@ -3,5 +3,6 @@ import { AnalyticsApi } from './analyticsApi'; export * from './analyticsApi'; export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [AnalyticsApi]; diff --git a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/client-analytics/utils/types.ts b/clients/algoliasearch-client-javascript/client-analytics/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/utils/types.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/clients/algoliasearch-client-javascript/client-insights/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-insights/.openapi-generator-ignore index abfb5c9516..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/client-insights/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/client-insights/.openapi-generator-ignore @@ -5,3 +5,4 @@ # The patterns follow closely to .gitignore or .dockerignore. git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/client-insights/api.ts b/clients/algoliasearch-client-javascript/client-insights/api.ts index 59b02c4607..c4759f623a 100644 --- a/clients/algoliasearch-client-javascript/client-insights/api.ts +++ b/clients/algoliasearch-client-javascript/client-insights/api.ts @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './src/apis'; -export * from './model/models'; diff --git a/clients/algoliasearch-client-javascript/client-insights/model/models.ts b/clients/algoliasearch-client-javascript/client-insights/model/models.ts deleted file mode 100644 index fa4726b58b..0000000000 --- a/clients/algoliasearch-client-javascript/client-insights/model/models.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* eslint-disable no-param-reassign */ -import type { RequestOptions } from '../utils/types'; - -export * from './errorBase'; -export * from './insightEvent'; -export * from './insightEvents'; -export * from './pushEventsResponse'; - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest: (requestOptions: RequestOptions) => Promise | void; -} - -export class ApiKeyAuth implements Authentication { - apiKey: string = ''; - - constructor(private location: string, private paramName: string) {} - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === 'query') { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if ( - this.location === 'header' && - requestOptions && - requestOptions.headers - ) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if ( - this.location === 'cookie' && - requestOptions && - requestOptions.headers - ) { - if (requestOptions.headers.Cookie) { - requestOptions.headers.Cookie += `; ${ - this.paramName - }=${encodeURIComponent(this.apiKey)}`; - } else { - requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( - this.apiKey - )}`; - } - } - } -} diff --git a/clients/algoliasearch-client-javascript/client-insights/src/apis.ts b/clients/algoliasearch-client-javascript/client-insights/src/apis.ts index 9dea0a8916..d0561908c0 100644 --- a/clients/algoliasearch-client-javascript/client-insights/src/apis.ts +++ b/clients/algoliasearch-client-javascript/client-insights/src/apis.ts @@ -3,5 +3,6 @@ import { InsightsApi } from './insightsApi'; export * from './insightsApi'; export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [InsightsApi]; diff --git a/clients/algoliasearch-client-javascript/client-insights/src/insightsApi.ts b/clients/algoliasearch-client-javascript/client-insights/src/insightsApi.ts index 8ae4f8da67..12da0deac7 100644 --- a/clients/algoliasearch-client-javascript/client-insights/src/insightsApi.ts +++ b/clients/algoliasearch-client-javascript/client-insights/src/insightsApi.ts @@ -1,36 +1,42 @@ import type { InsightEvents } from '../model/insightEvents'; -import { ApiKeyAuth } from '../model/models'; import type { PushEventsResponse } from '../model/pushEventsResponse'; import { Transporter } from '../utils/Transporter'; import type { Requester } from '../utils/requester/Requester'; import type { Headers, Host, Request, RequestOptions } from '../utils/types'; -export enum InsightsApiKeys { - apiKey, - appId, -} - export class InsightsApi { protected authentications = { - apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), - appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', }; private transporter: Transporter; - private sendRequest( - request: Request, + private applyAuthenticationHeaders( requestOptions: RequestOptions - ): Promise { - if (this.authentications.apiKey.apiKey) { - this.authentications.apiKey.applyToRequest(requestOptions); + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; } - if (this.authentications.appId.apiKey) { - this.authentications.appId.applyToRequest(requestOptions); - } + return requestOptions; + } - return this.transporter.request(request, requestOptions); + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -38,8 +44,7 @@ export class InsightsApi { apiKey: string, options?: { requester?: Requester; hosts?: Host[] } ) { - this.setApiKey(InsightsApiKeys.appId, appId); - this.setApiKey(InsightsApiKeys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts(), @@ -70,8 +75,11 @@ export class InsightsApi { this.transporter.setHosts(hosts); } - setApiKey(key: InsightsApiKeys, value: string): void { - this.authentications[InsightsApiKeys[key]].apiKey = value; + setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } /** diff --git a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/client-insights/utils/types.ts b/clients/algoliasearch-client-javascript/client-insights/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/client-insights/utils/types.ts +++ b/clients/algoliasearch-client-javascript/client-insights/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/clients/algoliasearch-client-javascript/client-personalization/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-personalization/.openapi-generator-ignore index abfb5c9516..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/client-personalization/.openapi-generator-ignore @@ -5,3 +5,4 @@ # The patterns follow closely to .gitignore or .dockerignore. git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/client-personalization/api.ts b/clients/algoliasearch-client-javascript/client-personalization/api.ts index 59b02c4607..c4759f623a 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/api.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/api.ts @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './src/apis'; -export * from './model/models'; diff --git a/clients/algoliasearch-client-javascript/client-personalization/model/deleteUserProfileResponse.ts b/clients/algoliasearch-client-javascript/client-personalization/model/deleteUserProfileResponse.ts index 45abf172e5..49717f3f25 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/model/deleteUserProfileResponse.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/model/deleteUserProfileResponse.ts @@ -6,5 +6,5 @@ export type DeleteUserProfileResponse = { /** * A date until which the data can safely be considered as deleted for the given user. Any data received after the deletedUntil date will start building a new user profile. */ - deletedUntil: Date; + deletedUntil: string; }; diff --git a/clients/algoliasearch-client-javascript/client-personalization/model/getUserTokenResponse.ts b/clients/algoliasearch-client-javascript/client-personalization/model/getUserTokenResponse.ts index d5a11e470e..0ab1c96114 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/model/getUserTokenResponse.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/model/getUserTokenResponse.ts @@ -6,7 +6,7 @@ export type GetUserTokenResponse = { /** * Date of last event update. (ISO-8601 format). */ - lastEventAt: Date; + lastEventAt: string; /** * The userToken scores. */ diff --git a/clients/algoliasearch-client-javascript/client-personalization/model/models.ts b/clients/algoliasearch-client-javascript/client-personalization/model/models.ts deleted file mode 100644 index 3260c5c0fb..0000000000 --- a/clients/algoliasearch-client-javascript/client-personalization/model/models.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* eslint-disable no-param-reassign */ -import type { RequestOptions } from '../utils/types'; - -export * from './deleteUserProfileResponse'; -export * from './errorBase'; -export * from './eventScoring'; -export * from './facetScoring'; -export * from './getUserTokenResponse'; -export * from './personalizationStrategyObject'; -export * from './setPersonalizationStrategyResponse'; - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest: (requestOptions: RequestOptions) => Promise | void; -} - -export class ApiKeyAuth implements Authentication { - apiKey: string = ''; - - constructor(private location: string, private paramName: string) {} - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === 'query') { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if ( - this.location === 'header' && - requestOptions && - requestOptions.headers - ) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if ( - this.location === 'cookie' && - requestOptions && - requestOptions.headers - ) { - if (requestOptions.headers.Cookie) { - requestOptions.headers.Cookie += `; ${ - this.paramName - }=${encodeURIComponent(this.apiKey)}`; - } else { - requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( - this.apiKey - )}`; - } - } - } -} diff --git a/clients/algoliasearch-client-javascript/client-personalization/src/apis.ts b/clients/algoliasearch-client-javascript/client-personalization/src/apis.ts index 7fba93227b..f4e5008c29 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/src/apis.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/src/apis.ts @@ -3,5 +3,6 @@ import { PersonalizationApi } from './personalizationApi'; export * from './personalizationApi'; export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [PersonalizationApi]; diff --git a/clients/algoliasearch-client-javascript/client-personalization/src/personalizationApi.ts b/clients/algoliasearch-client-javascript/client-personalization/src/personalizationApi.ts index 208c4a21ae..9243485e36 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/src/personalizationApi.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/src/personalizationApi.ts @@ -1,38 +1,44 @@ import type { DeleteUserProfileResponse } from '../model/deleteUserProfileResponse'; import type { GetUserTokenResponse } from '../model/getUserTokenResponse'; -import { ApiKeyAuth } from '../model/models'; import type { PersonalizationStrategyObject } from '../model/personalizationStrategyObject'; import type { SetPersonalizationStrategyResponse } from '../model/setPersonalizationStrategyResponse'; import { Transporter } from '../utils/Transporter'; import type { Requester } from '../utils/requester/Requester'; import type { Headers, Host, Request, RequestOptions } from '../utils/types'; -export enum PersonalizationApiKeys { - apiKey, - appId, -} - export class PersonalizationApi { protected authentications = { - apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), - appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', }; private transporter: Transporter; - private sendRequest( - request: Request, + private applyAuthenticationHeaders( requestOptions: RequestOptions - ): Promise { - if (this.authentications.apiKey.apiKey) { - this.authentications.apiKey.applyToRequest(requestOptions); + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; } - if (this.authentications.appId.apiKey) { - this.authentications.appId.applyToRequest(requestOptions); - } + return requestOptions; + } - return this.transporter.request(request, requestOptions); + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -41,8 +47,7 @@ export class PersonalizationApi { region: 'eu' | 'us', options?: { requester?: Requester; hosts?: Host[] } ) { - this.setApiKey(PersonalizationApiKeys.appId, appId); - this.setApiKey(PersonalizationApiKeys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts(region), @@ -77,8 +82,11 @@ export class PersonalizationApi { this.transporter.setHosts(hosts); } - setApiKey(key: PersonalizationApiKeys, value: string): void { - this.authentications[PersonalizationApiKeys[key]].apiKey = value; + setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } /** diff --git a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/client-personalization/utils/types.ts b/clients/algoliasearch-client-javascript/client-personalization/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/utils/types.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-query-suggestions/.openapi-generator-ignore index 8a9707d102..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/client-query-suggestions/.openapi-generator-ignore @@ -1,4 +1,8 @@ # OpenAPI Generator Ignore # Generated by openapi-generator https://github.com/openapitools/openapi-generator +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/api.ts b/clients/algoliasearch-client-javascript/client-query-suggestions/api.ts index 59b02c4607..c4759f623a 100644 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/api.ts +++ b/clients/algoliasearch-client-javascript/client-query-suggestions/api.ts @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './src/apis'; -export * from './model/models'; diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/model/logFile.ts b/clients/algoliasearch-client-javascript/client-query-suggestions/model/logFile.ts index b59bcd3cb9..1dac57b5d2 100644 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/model/logFile.ts +++ b/clients/algoliasearch-client-javascript/client-query-suggestions/model/logFile.ts @@ -2,7 +2,7 @@ export type LogFile = { /** * Date and time of creation of the record. */ - timestamp: Date; + timestamp: string; /** * Type of the record, can be one of three values (INFO, SKIP or ERROR). */ diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/model/models.ts b/clients/algoliasearch-client-javascript/client-query-suggestions/model/models.ts deleted file mode 100644 index 9ad1549d1d..0000000000 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/model/models.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-disable no-param-reassign */ -import type { RequestOptions } from '../utils/types'; - -export * from './errorBase'; -export * from './indexName'; -export * from './logFile'; -export * from './querySuggestionsIndex'; -export * from './querySuggestionsIndexParam'; -export * from './querySuggestionsIndexWithIndexParam'; -export * from './sourceIndex'; -export * from './sourceIndexExternal'; -export * from './sourceIndexWithReplicas'; -export * from './status'; -export * from './sucessResponse'; - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest: (requestOptions: RequestOptions) => Promise | void; -} - -export class ApiKeyAuth implements Authentication { - apiKey: string = ''; - - constructor(private location: string, private paramName: string) {} - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === 'query') { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if ( - this.location === 'header' && - requestOptions && - requestOptions.headers - ) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if ( - this.location === 'cookie' && - requestOptions && - requestOptions.headers - ) { - if (requestOptions.headers.Cookie) { - requestOptions.headers.Cookie += `; ${ - this.paramName - }=${encodeURIComponent(this.apiKey)}`; - } else { - requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( - this.apiKey - )}`; - } - } - } -} diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/src/apis.ts b/clients/algoliasearch-client-javascript/client-query-suggestions/src/apis.ts index 6356f1fc76..4127dccd9c 100644 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/src/apis.ts +++ b/clients/algoliasearch-client-javascript/client-query-suggestions/src/apis.ts @@ -3,5 +3,6 @@ import { QuerySuggestionsApi } from './querySuggestionsApi'; export * from './querySuggestionsApi'; export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [QuerySuggestionsApi]; diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/src/querySuggestionsApi.ts b/clients/algoliasearch-client-javascript/client-query-suggestions/src/querySuggestionsApi.ts index 5b73964f68..cc8674c2d1 100644 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/src/querySuggestionsApi.ts +++ b/clients/algoliasearch-client-javascript/client-query-suggestions/src/querySuggestionsApi.ts @@ -1,5 +1,4 @@ import type { LogFile } from '../model/logFile'; -import { ApiKeyAuth } from '../model/models'; import type { QuerySuggestionsIndex } from '../model/querySuggestionsIndex'; import type { QuerySuggestionsIndexParam } from '../model/querySuggestionsIndexParam'; import type { QuerySuggestionsIndexWithIndexParam } from '../model/querySuggestionsIndexWithIndexParam'; @@ -9,32 +8,39 @@ import { Transporter } from '../utils/Transporter'; import type { Requester } from '../utils/requester/Requester'; import type { Headers, Host, Request, RequestOptions } from '../utils/types'; -export enum QuerySuggestionsApiKeys { - apiKey, - appId, -} - export class QuerySuggestionsApi { protected authentications = { - apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), - appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', }; private transporter: Transporter; - private sendRequest( - request: Request, + private applyAuthenticationHeaders( requestOptions: RequestOptions - ): Promise { - if (this.authentications.apiKey.apiKey) { - this.authentications.apiKey.applyToRequest(requestOptions); + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; } - if (this.authentications.appId.apiKey) { - this.authentications.appId.applyToRequest(requestOptions); - } + return requestOptions; + } - return this.transporter.request(request, requestOptions); + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -43,8 +49,7 @@ export class QuerySuggestionsApi { region: 'eu' | 'us', options?: { requester?: Requester; hosts?: Host[] } ) { - this.setApiKey(QuerySuggestionsApiKeys.appId, appId); - this.setApiKey(QuerySuggestionsApiKeys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts(region), @@ -79,8 +84,11 @@ export class QuerySuggestionsApi { this.transporter.setHosts(hosts); } - setApiKey(key: QuerySuggestionsApiKeys, value: string): void { - this.authentications[QuerySuggestionsApiKeys[key]].apiKey = value; + setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } /** diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-query-suggestions/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-query-suggestions/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/client-query-suggestions/utils/types.ts b/clients/algoliasearch-client-javascript/client-query-suggestions/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/client-query-suggestions/utils/types.ts +++ b/clients/algoliasearch-client-javascript/client-query-suggestions/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/clients/algoliasearch-client-javascript/client-search/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-search/.openapi-generator-ignore index abfb5c9516..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/client-search/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/client-search/.openapi-generator-ignore @@ -5,3 +5,4 @@ # The patterns follow closely to .gitignore or .dockerignore. git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/client-search/api.ts b/clients/algoliasearch-client-javascript/client-search/api.ts index 59b02c4607..c4759f623a 100644 --- a/clients/algoliasearch-client-javascript/client-search/api.ts +++ b/clients/algoliasearch-client-javascript/client-search/api.ts @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './src/apis'; -export * from './model/models'; diff --git a/clients/algoliasearch-client-javascript/client-search/model/addApiKeyResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/addApiKeyResponse.ts index 297c85db6e..10dfae24e7 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/addApiKeyResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/addApiKeyResponse.ts @@ -6,5 +6,5 @@ export type AddApiKeyResponse = { /** * Date of creation (ISO-8601 format). */ - createdAt: Date; + createdAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/createdAtObject.ts b/clients/algoliasearch-client-javascript/client-search/model/createdAtObject.ts index c0881596f3..186db3e688 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/createdAtObject.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/createdAtObject.ts @@ -2,5 +2,5 @@ export type CreatedAtObject = { /** * Date of creation (ISO-8601 format). */ - createdAt: Date; + createdAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/createdAtResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/createdAtResponse.ts index ed372bbb72..5338cfa832 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/createdAtResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/createdAtResponse.ts @@ -5,5 +5,5 @@ export type CreatedAtResponse = { /** * Date of creation (ISO-8601 format). */ - createdAt: Date; + createdAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/deleteApiKeyResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/deleteApiKeyResponse.ts index 8e09705133..37e9753738 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/deleteApiKeyResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/deleteApiKeyResponse.ts @@ -2,5 +2,5 @@ export type DeleteApiKeyResponse = { /** * Date of deletion (ISO-8601 format). */ - deletedAt: Date; + deletedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/deleteSourceResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/deleteSourceResponse.ts index 8025072619..0777b09e59 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/deleteSourceResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/deleteSourceResponse.ts @@ -2,5 +2,5 @@ export type DeleteSourceResponse = { /** * Date of deletion (ISO-8601 format). */ - deletedAt: Date; + deletedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/deletedAtResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/deletedAtResponse.ts index a3d1d14ab4..865074e606 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/deletedAtResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/deletedAtResponse.ts @@ -9,5 +9,5 @@ export type DeletedAtResponse = { /** * Date of deletion (ISO-8601 format). */ - deletedAt: Date; + deletedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/index.ts b/clients/algoliasearch-client-javascript/client-search/model/index.ts index af99e11692..98ecf4686e 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/index.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/index.ts @@ -6,11 +6,11 @@ export type Index = { /** * Index creation date. An empty string means that the index has no records. */ - createdAt: Date; + createdAt: string; /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; /** * Number of records contained in the index. */ diff --git a/clients/algoliasearch-client-javascript/client-search/model/models.ts b/clients/algoliasearch-client-javascript/client-search/model/models.ts deleted file mode 100644 index fd07b0f208..0000000000 --- a/clients/algoliasearch-client-javascript/client-search/model/models.ts +++ /dev/null @@ -1,138 +0,0 @@ -/* eslint-disable no-param-reassign */ -import type { RequestOptions } from '../utils/types'; - -export * from './action'; -export * from './addApiKeyResponse'; -export * from './anchoring'; -export * from './apiKey'; -export * from './assignUserIdObject'; -export * from './automaticFacetFilter'; -export * from './baseBrowseResponse'; -export * from './baseIndexSettings'; -export * from './baseSearchParams'; -export * from './baseSearchResponse'; -export * from './baseSearchResponseFacetsStats'; -export * from './batchAssignUserIdsObject'; -export * from './batchDictionaryEntries'; -export * from './batchDictionaryEntriesRequest'; -export * from './batchObject'; -export * from './batchResponse'; -export * from './batchWriteObject'; -export * from './browseRequest'; -export * from './browseResponse'; -export * from './buildInOperation'; -export * from './condition'; -export * from './consequence'; -export * from './consequenceHide'; -export * from './consequenceParams'; -export * from './createdAtObject'; -export * from './createdAtResponse'; -export * from './deleteApiKeyResponse'; -export * from './deleteSourceResponse'; -export * from './deletedAtResponse'; -export * from './dictionaryEntry'; -export * from './dictionaryLanguage'; -export * from './dictionarySettingsRequest'; -export * from './errorBase'; -export * from './getDictionarySettingsResponse'; -export * from './getLogsResponse'; -export * from './getLogsResponseInnerQueries'; -export * from './getLogsResponseLogs'; -export * from './getObjectsObject'; -export * from './getObjectsResponse'; -export * from './getTaskResponse'; -export * from './getTopUserIdsResponse'; -export * from './highlightResult'; -export * from './index'; -export * from './indexSettings'; -export * from './indexSettingsAsSearchParams'; -export * from './keyObject'; -export * from './languages'; -export * from './listApiKeysResponse'; -export * from './listClustersResponse'; -export * from './listIndicesResponse'; -export * from './listUserIdsResponse'; -export * from './multipleBatchResponse'; -export * from './multipleGetObjectsObject'; -export * from './multipleQueries'; -export * from './multipleQueriesObject'; -export * from './multipleQueriesResponse'; -export * from './operation'; -export * from './operationIndexObject'; -export * from './params'; -export * from './promote'; -export * from './rankingInfo'; -export * from './rankingInfoMatchedGeoLocation'; -export * from './record'; -export * from './removeUserIdResponse'; -export * from './replaceSourceResponse'; -export * from './requiredSearchParams'; -export * from './rule'; -export * from './saveObjectResponse'; -export * from './saveSynonymResponse'; -export * from './searchDictionaryEntries'; -export * from './searchForFacetValuesRequest'; -export * from './searchForFacetValuesResponse'; -export * from './searchForFacetValuesResponseFacetHits'; -export * from './searchHits'; -export * from './searchParams'; -export * from './searchParamsObject'; -export * from './searchParamsString'; -export * from './searchResponse'; -export * from './searchRulesParams'; -export * from './searchRulesResponse'; -export * from './searchSynonymsResponse'; -export * from './searchUserIdsObject'; -export * from './searchUserIdsResponse'; -export * from './searchUserIdsResponseHighlightResult'; -export * from './searchUserIdsResponseHits'; -export * from './snippetResult'; -export * from './source'; -export * from './standardEntries'; -export * from './synonymHit'; -export * from './synonymHitHighlightResult'; -export * from './timeRange'; -export * from './updateApiKeyResponse'; -export * from './updatedAtResponse'; -export * from './updatedAtWithObjectIdResponse'; -export * from './updatedRuleResponse'; -export * from './userId'; - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest: (requestOptions: RequestOptions) => Promise | void; -} - -export class ApiKeyAuth implements Authentication { - apiKey: string = ''; - - constructor(private location: string, private paramName: string) {} - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === 'query') { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if ( - this.location === 'header' && - requestOptions && - requestOptions.headers - ) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if ( - this.location === 'cookie' && - requestOptions && - requestOptions.headers - ) { - if (requestOptions.headers.Cookie) { - requestOptions.headers.Cookie += `; ${ - this.paramName - }=${encodeURIComponent(this.apiKey)}`; - } else { - requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( - this.apiKey - )}`; - } - } - } -} diff --git a/clients/algoliasearch-client-javascript/client-search/model/removeUserIdResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/removeUserIdResponse.ts index 81ed3963d6..8326ce561d 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/removeUserIdResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/removeUserIdResponse.ts @@ -2,5 +2,5 @@ export type RemoveUserIdResponse = { /** * Date of deletion (ISO-8601 format). */ - deletedAt: Date; + deletedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/replaceSourceResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/replaceSourceResponse.ts index 7a9b660965..6800a2a53f 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/replaceSourceResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/replaceSourceResponse.ts @@ -2,5 +2,5 @@ export type ReplaceSourceResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/saveSynonymResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/saveSynonymResponse.ts index 44d0519625..5c83340b46 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/saveSynonymResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/saveSynonymResponse.ts @@ -6,7 +6,7 @@ export type SaveSynonymResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; /** * ObjectID of the inserted object. */ diff --git a/clients/algoliasearch-client-javascript/client-search/model/searchUserIdsResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/searchUserIdsResponse.ts index 5b00163573..6434c679b6 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/searchUserIdsResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/searchUserIdsResponse.ts @@ -23,5 +23,5 @@ export type SearchUserIdsResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/updateApiKeyResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/updateApiKeyResponse.ts index 1a30628a5f..5bf38cb912 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/updateApiKeyResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/updateApiKeyResponse.ts @@ -6,5 +6,5 @@ export type UpdateApiKeyResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/updatedAtResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/updatedAtResponse.ts index 3320ad93f8..90755a3379 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/updatedAtResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/updatedAtResponse.ts @@ -9,5 +9,5 @@ export type UpdatedAtResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; }; diff --git a/clients/algoliasearch-client-javascript/client-search/model/updatedAtWithObjectIdResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/updatedAtWithObjectIdResponse.ts index 92a43993ba..5ace1ab507 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/updatedAtWithObjectIdResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/updatedAtWithObjectIdResponse.ts @@ -9,7 +9,7 @@ export type UpdatedAtWithObjectIdResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt?: Date; + updatedAt?: string; /** * Unique identifier of the object. */ diff --git a/clients/algoliasearch-client-javascript/client-search/model/updatedRuleResponse.ts b/clients/algoliasearch-client-javascript/client-search/model/updatedRuleResponse.ts index bb34677619..b47eae6e23 100644 --- a/clients/algoliasearch-client-javascript/client-search/model/updatedRuleResponse.ts +++ b/clients/algoliasearch-client-javascript/client-search/model/updatedRuleResponse.ts @@ -6,7 +6,7 @@ export type UpdatedRuleResponse = { /** * Date of last update (ISO-8601 format). */ - updatedAt: Date; + updatedAt: string; /** * TaskID of the task to wait for. */ diff --git a/clients/algoliasearch-client-javascript/client-search/src/apis.ts b/clients/algoliasearch-client-javascript/client-search/src/apis.ts index 7ecfef324e..7e57d462a6 100644 --- a/clients/algoliasearch-client-javascript/client-search/src/apis.ts +++ b/clients/algoliasearch-client-javascript/client-search/src/apis.ts @@ -3,5 +3,6 @@ import { SearchApi } from './searchApi'; export * from './searchApi'; export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [SearchApi]; diff --git a/clients/algoliasearch-client-javascript/client-search/src/searchApi.ts b/clients/algoliasearch-client-javascript/client-search/src/searchApi.ts index 1314cb7f82..21b8692d27 100644 --- a/clients/algoliasearch-client-javascript/client-search/src/searchApi.ts +++ b/clients/algoliasearch-client-javascript/client-search/src/searchApi.ts @@ -27,7 +27,6 @@ import type { ListApiKeysResponse } from '../model/listApiKeysResponse'; import type { ListClustersResponse } from '../model/listClustersResponse'; import type { ListIndicesResponse } from '../model/listIndicesResponse'; import type { ListUserIdsResponse } from '../model/listUserIdsResponse'; -import { ApiKeyAuth } from '../model/models'; import type { MultipleBatchResponse } from '../model/multipleBatchResponse'; import type { MultipleQueriesObject } from '../model/multipleQueriesObject'; import type { MultipleQueriesResponse } from '../model/multipleQueriesResponse'; @@ -59,32 +58,39 @@ import { shuffle } from '../utils/helpers'; import type { Requester } from '../utils/requester/Requester'; import type { Headers, Host, Request, RequestOptions } from '../utils/types'; -export enum SearchApiKeys { - apiKey, - appId, -} - export class SearchApi { protected authentications = { - apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), - appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', }; private transporter: Transporter; - private sendRequest( - request: Request, + private applyAuthenticationHeaders( requestOptions: RequestOptions - ): Promise { - if (this.authentications.apiKey.apiKey) { - this.authentications.apiKey.applyToRequest(requestOptions); + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; } - if (this.authentications.appId.apiKey) { - this.authentications.appId.applyToRequest(requestOptions); - } + return requestOptions; + } - return this.transporter.request(request, requestOptions); + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -92,8 +98,7 @@ export class SearchApi { apiKey: string, options?: { requester?: Requester; hosts?: Host[] } ) { - this.setApiKey(SearchApiKeys.appId, appId); - this.setApiKey(SearchApiKeys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts(appId), @@ -145,8 +150,11 @@ export class SearchApi { this.transporter.setHosts(hosts); } - setApiKey(key: SearchApiKeys, value: string): void { - this.authentications[SearchApiKeys[key]].apiKey = value; + setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } /** diff --git a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/client-search/utils/types.ts b/clients/algoliasearch-client-javascript/client-search/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/client-search/utils/types.ts +++ b/clients/algoliasearch-client-javascript/client-search/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/clients/algoliasearch-client-javascript/recommend/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/recommend/.openapi-generator-ignore index abfb5c9516..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/recommend/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/recommend/.openapi-generator-ignore @@ -5,3 +5,4 @@ # The patterns follow closely to .gitignore or .dockerignore. git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/recommend/api.ts b/clients/algoliasearch-client-javascript/recommend/api.ts index 59b02c4607..c4759f623a 100644 --- a/clients/algoliasearch-client-javascript/recommend/api.ts +++ b/clients/algoliasearch-client-javascript/recommend/api.ts @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './src/apis'; -export * from './model/models'; diff --git a/clients/algoliasearch-client-javascript/recommend/model/models.ts b/clients/algoliasearch-client-javascript/recommend/model/models.ts deleted file mode 100644 index f1ceaba6b7..0000000000 --- a/clients/algoliasearch-client-javascript/recommend/model/models.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable no-param-reassign */ -import type { RequestOptions } from '../utils/types'; - -export * from './baseSearchParams'; -export * from './baseSearchResponse'; -export * from './baseSearchResponseFacetsStats'; -export * from './errorBase'; -export * from './getRecommendations'; -export * from './getRecommendationsResponse'; -export * from './highlightResult'; -export * from './indexSettingsAsSearchParams'; -export * from './rankingInfo'; -export * from './rankingInfoMatchedGeoLocation'; -export * from './recommendHits'; -export * from './recommendRecord'; -export * from './recommendationRequest'; -export * from './recommendationsResponse'; -export * from './requiredSearchParams'; -export * from './searchParams'; -export * from './snippetResult'; - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest: (requestOptions: RequestOptions) => Promise | void; -} - -export class ApiKeyAuth implements Authentication { - apiKey: string = ''; - - constructor(private location: string, private paramName: string) {} - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === 'query') { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if ( - this.location === 'header' && - requestOptions && - requestOptions.headers - ) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if ( - this.location === 'cookie' && - requestOptions && - requestOptions.headers - ) { - if (requestOptions.headers.Cookie) { - requestOptions.headers.Cookie += `; ${ - this.paramName - }=${encodeURIComponent(this.apiKey)}`; - } else { - requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent( - this.apiKey - )}`; - } - } - } -} diff --git a/clients/algoliasearch-client-javascript/recommend/src/apis.ts b/clients/algoliasearch-client-javascript/recommend/src/apis.ts index fedaa42d09..927e908e8a 100644 --- a/clients/algoliasearch-client-javascript/recommend/src/apis.ts +++ b/clients/algoliasearch-client-javascript/recommend/src/apis.ts @@ -3,5 +3,6 @@ import { RecommendApi } from './recommendApi'; export * from './recommendApi'; export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [RecommendApi]; diff --git a/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts b/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts index 05f0a90d47..5751044ce3 100644 --- a/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts +++ b/clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts @@ -1,37 +1,43 @@ import type { GetRecommendations } from '../model/getRecommendations'; import type { GetRecommendationsResponse } from '../model/getRecommendationsResponse'; -import { ApiKeyAuth } from '../model/models'; import { Transporter } from '../utils/Transporter'; import { shuffle } from '../utils/helpers'; import type { Requester } from '../utils/requester/Requester'; import type { Headers, Host, Request, RequestOptions } from '../utils/types'; -export enum RecommendApiKeys { - apiKey, - appId, -} - export class RecommendApi { protected authentications = { - apiKey: new ApiKeyAuth('header', 'X-Algolia-API-Key'), - appId: new ApiKeyAuth('header', 'X-Algolia-Application-Id'), + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', }; private transporter: Transporter; - private sendRequest( - request: Request, + private applyAuthenticationHeaders( requestOptions: RequestOptions - ): Promise { - if (this.authentications.apiKey.apiKey) { - this.authentications.apiKey.applyToRequest(requestOptions); + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; } - if (this.authentications.appId.apiKey) { - this.authentications.appId.applyToRequest(requestOptions); - } + return requestOptions; + } - return this.transporter.request(request, requestOptions); + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -39,8 +45,7 @@ export class RecommendApi { apiKey: string, options?: { requester?: Requester; hosts?: Host[] } ) { - this.setApiKey(RecommendApiKeys.appId, appId); - this.setApiKey(RecommendApiKeys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts(appId), @@ -92,8 +97,11 @@ export class RecommendApi { this.transporter.setHosts(hosts); } - setApiKey(key: RecommendApiKeys, value: string): void { - this.authentications[RecommendApiKeys[key]].apiKey = value; + setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } /** diff --git a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/recommend/utils/types.ts b/clients/algoliasearch-client-javascript/recommend/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/recommend/utils/types.ts +++ b/clients/algoliasearch-client-javascript/recommend/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts index ec75b37a41..f773d0f637 100644 --- a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts @@ -1,18 +1,10 @@ -import type { EndRequest, Request, Response } from '../types'; +import type { EndRequest, Request, Response, EchoResponse } from '../types'; import { Requester } from './Requester'; -type AdditionalContent = { - headers: Record; - connectTimeout: number; - responseTimeout: number; - userAgent?: string; - searchParams?: Record; -}; - function searchParamsWithoutUA( params: URLSearchParams -): AdditionalContent['searchParams'] { +): EchoResponse['searchParams'] { const searchParams = {}; for (const [k, v] of params) { @@ -37,21 +29,17 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; - const searchParams = searchParamsWithoutUA(urlSearchParams); - const additionalContent: AdditionalContent = { - headers, - connectTimeout, - responseTimeout, - userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams, - }; const originalData = data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ content: JSON.stringify({ ...originalRequest, - ...additionalContent, + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), data: originalData, }), isTimedOut: false, diff --git a/clients/algoliasearch-client-javascript/utils/types.ts b/clients/algoliasearch-client-javascript/utils/types.ts index d2a478c1a0..20136fe367 100644 --- a/clients/algoliasearch-client-javascript/utils/types.ts +++ b/clients/algoliasearch-client-javascript/utils/types.ts @@ -43,6 +43,14 @@ export type Response = { status: number; }; +export type EchoResponse = Request & { + connectTimeout: number; + headers: Record; + responseTimeout: number; + searchParams?: Record; + userAgent?: string; +}; + export type Headers = Record; export type Host = { diff --git a/playground/javascript/abtesting.ts b/playground/javascript/abtesting.ts index bc47ec5dde..0b32ebda0d 100644 --- a/playground/javascript/abtesting.ts +++ b/playground/javascript/abtesting.ts @@ -13,7 +13,7 @@ const client = new AbtestingApi(appId, apiKey, 'de'); async function testABTesting() { try { const res = await client.addABTests({ - endAt: new Date('2022-02-01'), + endAt: '2022-02-01', name: 'testing', variant: [ { diff --git a/playground/javascript/recommend.ts b/playground/javascript/recommend.ts index b8d30c60fd..8eafeb0cc4 100644 --- a/playground/javascript/recommend.ts +++ b/playground/javascript/recommend.ts @@ -1,8 +1,4 @@ -import { - RecommendApi, - ApiError, - RecommendationRequest, -} from '@algolia/recommend'; +import { RecommendApi, ApiError } from '@algolia/recommend'; import dotenv from 'dotenv'; dotenv.config({ path: '../.env' }); diff --git a/specs/abtesting/common/parameters.yml b/specs/abtesting/common/parameters.yml index c1d32c218d..8d8728a591 100644 --- a/specs/abtesting/common/parameters.yml +++ b/specs/abtesting/common/parameters.yml @@ -12,21 +12,16 @@ index: type: string description: The index performing the A/B test. -taskID: - $ref: ../../common/parameters.yml#/taskID - abTestID: type: integer description: The A/B test ID. endAt: type: string - format: date-time description: End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. createdAt: type: string - format: date-time description: End date for the A/B test expressed as YYYY-MM-DDThh:mm:ssZ. name: diff --git a/specs/abtesting/common/schemas/ABTestResponse.yml b/specs/abtesting/common/schemas/ABTestResponse.yml new file mode 100644 index 0000000000..8e6a05dfaf --- /dev/null +++ b/specs/abtesting/common/schemas/ABTestResponse.yml @@ -0,0 +1,14 @@ +ABTestResponse: + type: object + additionalProperties: false + properties: + index: + $ref: ../parameters.yml#/index + abTestID: + $ref: ../parameters.yml#/abTestID + taskID: + $ref: ../../../common/parameters.yml#/taskID + required: + - abTestID + - index + - taskID diff --git a/specs/abtesting/paths/abtest.yml b/specs/abtesting/paths/abtest.yml index a885659836..597a491c91 100644 --- a/specs/abtesting/paths/abtest.yml +++ b/specs/abtesting/paths/abtest.yml @@ -39,8 +39,7 @@ delete: content: application/json: schema: - title: deleteABTestResponse - type: object + $ref: ../common/schemas/ABTestResponse.yml#/ABTestResponse '400': $ref: ../../common/responses/BadRequest.yml '402': diff --git a/specs/abtesting/paths/abtests.yml b/specs/abtesting/paths/abtests.yml index c09b2196a6..ff47184489 100644 --- a/specs/abtesting/paths/abtests.yml +++ b/specs/abtesting/paths/abtests.yml @@ -37,20 +37,7 @@ post: content: application/json: schema: - title: addABTestsResponse - type: object - additionalProperties: false - properties: - index: - $ref: ../common/parameters.yml#/index - abTestID: - $ref: ../common/parameters.yml#/abTestID - taskID: - $ref: ../common/parameters.yml#/taskID - required: - - abTestID - - index - - taskID + $ref: ../common/schemas/ABTestResponse.yml#/ABTestResponse '400': $ref: ../../common/responses/BadRequest.yml '402': diff --git a/specs/abtesting/paths/stopABTest.yml b/specs/abtesting/paths/stopABTest.yml index 9d4d883e34..8dc1801144 100644 --- a/specs/abtesting/paths/stopABTest.yml +++ b/specs/abtesting/paths/stopABTest.yml @@ -17,8 +17,7 @@ post: content: application/json: schema: - title: stopABTestResponse - type: object + $ref: ../common/schemas/ABTestResponse.yml#/ABTestResponse '400': $ref: ../../common/responses/BadRequest.yml '402': diff --git a/specs/analytics/paths/common/parameters.yml b/specs/analytics/paths/common/parameters.yml index 10a38dcfbf..de65a46d5a 100644 --- a/specs/analytics/paths/common/parameters.yml +++ b/specs/analytics/paths/common/parameters.yml @@ -64,7 +64,6 @@ clickCount: date: type: string - format: date-time description: Date of the event. rate: diff --git a/specs/common/parameters.yml b/specs/common/parameters.yml index aa2975216b..a49fbaf98a 100644 --- a/specs/common/parameters.yml +++ b/specs/common/parameters.yml @@ -127,17 +127,14 @@ abTestVariantID: createdAt: type: string - format: date-time description: Date of creation (ISO-8601 format). updatedAt: type: string - format: date-time description: Date of last update (ISO-8601 format). deletedAt: type: string - format: date-time description: Date of deletion (ISO-8601 format). indexName: diff --git a/specs/personalization/paths/deleteUserProfile.yml b/specs/personalization/paths/deleteUserProfile.yml index c4067a0422..c3cf8fb7f1 100644 --- a/specs/personalization/paths/deleteUserProfile.yml +++ b/specs/personalization/paths/deleteUserProfile.yml @@ -23,7 +23,6 @@ delete: $ref: '../common/parameters.yml#/userToken' deletedUntil: type: string - format: date-time description: A date until which the data can safely be considered as deleted for the given user. Any data received after the deletedUntil date will start building a new user profile. '400': $ref: ../../common/responses/BadRequest.yml diff --git a/specs/personalization/paths/getUserTokenProfile.yml b/specs/personalization/paths/getUserTokenProfile.yml index 14fead2ef7..684d571320 100644 --- a/specs/personalization/paths/getUserTokenProfile.yml +++ b/specs/personalization/paths/getUserTokenProfile.yml @@ -24,7 +24,6 @@ get: $ref: '../common/parameters.yml#/userToken' lastEventAt: type: string - format: date-time description: Date of last event update. (ISO-8601 format) scores: type: object diff --git a/specs/query-suggestions/paths/getLogFile.yml b/specs/query-suggestions/paths/getLogFile.yml index 5c6f630417..d15b880581 100644 --- a/specs/query-suggestions/paths/getLogFile.yml +++ b/specs/query-suggestions/paths/getLogFile.yml @@ -24,7 +24,6 @@ get: properties: timestamp: type: string - format: date-time description: date and time of creation of the record. level: type: string diff --git a/specs/search/common/schemas/listIndicesResponse.yml b/specs/search/common/schemas/listIndicesResponse.yml index 8064e93cba..347386605c 100644 --- a/specs/search/common/schemas/listIndicesResponse.yml +++ b/specs/search/common/schemas/listIndicesResponse.yml @@ -21,7 +21,6 @@ index: description: Index name. createdAt: type: string - format: date-time description: Index creation date. An empty string means that the index has no records. updatedAt: $ref: '../../../common/parameters.yml#/updatedAt' diff --git a/templates/javascript/api-all.mustache b/templates/javascript/api-all.mustache index 45fa5063fa..cb29f7ade8 100644 --- a/templates/javascript/api-all.mustache +++ b/templates/javascript/api-all.mustache @@ -10,6 +10,7 @@ export * from './{{ classFilename }}Interface' {{/apis}} export * from '../utils/errors'; export { EchoRequester } from '../utils/requester/EchoRequester'; +export { EchoResponse } from '../utils/types'; export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}]; {{/apiInfo}} diff --git a/templates/javascript/api-single.mustache b/templates/javascript/api-single.mustache index 73d68fdce2..7f6bdf6503 100644 --- a/templates/javascript/api-single.mustache +++ b/templates/javascript/api-single.mustache @@ -6,9 +6,6 @@ import { Requester } from '../utils/requester/Requester'; {{#imports}} import { {{classname}} } from '{{filename}}'; {{/imports}} -{{#hasAuthMethods}} -import { ApiKeyAuth } from '../model/models'; -{{/hasAuthMethods}} {{#operations}} {{#description}} @@ -17,37 +14,39 @@ import { ApiKeyAuth } from '../model/models'; */ {{/description}} -export enum {{classname}}Keys { - {{#authMethods}} - {{#isApiKey}} - {{name}}, - {{/isApiKey}} - {{/authMethods}} -} - export class {{classname}} { protected authentications = { - {{#hasAuthMethods}} - {{#authMethods}} - {{#isApiKey}} - '{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}}{{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}, '{{keyParamName}}'), - {{/isApiKey}} - {{/authMethods}} - {{/hasAuthMethods}} - } + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', + }; private transporter: Transporter; - - private sendRequest(request: Request, requestOptions: RequestOptions): Promise { - {{#authMethods}} - {{#isApiKey}} - if (this.authentications.{{name}}.apiKey) { - this.authentications.{{name}}.applyToRequest(requestOptions); + + private applyAuthenticationHeaders( + requestOptions: RequestOptions + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; } - - {{/isApiKey}} - {{/authMethods}} - return this.transporter.request(request, requestOptions); + + return requestOptions; + } + + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); } constructor( @@ -58,8 +57,7 @@ export class {{classname}} { {{/hasRegionalHost}} options?: {requester?: Requester, hosts?: Host[]} ) { - this.setApiKey({{classname}}Keys.appId, appId); - this.setApiKey({{classname}}Keys.apiKey, apiKey); + this.setAuthentication({ appId, apiKey }); this.transporter = new Transporter({ hosts: options?.hosts ?? this.getDefaultHosts( @@ -118,8 +116,11 @@ export class {{classname}} { this.transporter.setHosts(hosts); } - public setApiKey(key: {{classname}}Keys, value: string): void { - this.authentications[{{classname}}Keys[key]].apiKey = value; + public setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; } {{#operation}} @@ -168,7 +169,7 @@ export class {{classname}} { {{/bodyParams.0}} {{/allParams.0}} */ - public {{nickname}} ( + public {{nickname}}( {{#allParams.0}} {{^bodyParams.0}} { diff --git a/templates/javascript/api.mustache b/templates/javascript/api.mustache index 0ba53426e1..19d153c096 100644 --- a/templates/javascript/api.mustache +++ b/templates/javascript/api.mustache @@ -1,3 +1,2 @@ // This is the entrypoint for the package export * from './{{apiPackage}}/apis'; -export * from './model/models'; diff --git a/templates/javascript/models.mustache b/templates/javascript/models.mustache deleted file mode 100644 index c493fc6167..0000000000 --- a/templates/javascript/models.mustache +++ /dev/null @@ -1,43 +0,0 @@ -/* eslint-disable no-param-reassign */ -{{#generateApis}} -import type { RequestOptions } from '../utils/types'; -{{/generateApis}} - -{{#models}} -{{#model}} -export * from '{{{ classFilename }}}'; -{{/model}} -{{/models}} - -{{! Object serialization only relevant if generating APIs, too }} -{{#generateApis}} - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest(requestOptions: RequestOptions): Promise | void; -} - -export class ApiKeyAuth implements Authentication { - public apiKey: string = ''; - - constructor(private location: string, private paramName: string) { - } - - applyToRequest(requestOptions: RequestOptions): void { - if (this.location === "query") { - requestOptions.queryParameters[this.paramName] = this.apiKey; - } else if (this.location === "header" && requestOptions && requestOptions.headers) { - requestOptions.headers[this.paramName] = this.apiKey; - } else if (this.location === 'cookie' && requestOptions && requestOptions.headers) { - if (requestOptions.headers['Cookie']) { - requestOptions.headers['Cookie'] += '; ' + this.paramName + '=' + encodeURIComponent(this.apiKey); - } - else { - requestOptions.headers['Cookie'] = this.paramName + '=' + encodeURIComponent(this.apiKey); - } - } - } -} -{{/generateApis}} diff --git a/tests/CTS/clients/abtesting/addABTests.json b/tests/CTS/clients/abtesting/addABTests.json index 091c50d59f..7081e5fe8c 100644 --- a/tests/CTS/clients/abtesting/addABTests.json +++ b/tests/CTS/clients/abtesting/addABTests.json @@ -3,7 +3,7 @@ "method": "addABTests", "testName": "addABTests with minimal parameters", "parameters": { - "endAt": "2022-12-31", + "endAt": "2022-12-31T00:00:00.000Z", "name": "myABTest", "variant": [ { diff --git a/tests/CTS/templates/javascript.mustache b/tests/CTS/templates/javascript.mustache index d6855c93c8..bb139f9358 100644 --- a/tests/CTS/templates/javascript.mustache +++ b/tests/CTS/templates/javascript.mustache @@ -1,4 +1,5 @@ import { {{client}}, EchoRequester } from '{{{import}}}'; +import type { EchoResponse } from '{{{import}}}'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -7,23 +8,17 @@ const client = new {{client}}(appId, apiKey, {{#hasRegionalHost}}'us', {{/hasReg {{#blocks}} describe('{{operationId}}', () => { - {{#tests}} - test('{{testName}}', async () => { - const req = await client.{{method}}( - {{#hasParameters}}{ - {{#parametersWithDataType}} - {{#isDate}}{{{key}}}:new Date({{{value}}}),{{/isDate}}{{^isDate}}{{{key}}}:{{{value}}},{{/isDate}} - {{/parametersWithDataType}} - }{{/hasParameters}} - ); + {{#tests}} + test('{{testName}}', async () => { + const req = (await client.{{method}}({{#hasParameters}}{{{parameters}}}{{/hasParameters}})) as unknown as EchoResponse; - expect((req as any).path).toEqual('{{{request.path}}}'); - expect((req as any).method).toEqual('{{{request.method}}}'); - expect((req as any).data).toEqual({{#request.data}}{{{request.data}}}{{/request.data}}{{^request.data}}undefined{{/request.data}}); - expect((req as any).searchParams).toEqual({{#request.searchParams}}{{{request.searchParams}}}{{/request.searchParams}}{{^request.searchParams}}undefined{{/request.searchParams}}); - }); + expect(req.path).toEqual('{{{request.path}}}'); + expect(req.method).toEqual('{{{request.method}}}'); + expect(req.data).toEqual({{#request.data}}{{{request.data}}}{{/request.data}}{{^request.data}}undefined{{/request.data}}); + expect(req.searchParams).toEqual({{#request.searchParams}}{{{request.searchParams}}}{{/request.searchParams}}{{^request.searchParams}}undefined{{/request.searchParams}}); + }); - {{/tests}} + {{/tests}} }) {{/blocks}} diff --git a/tests/generateCTS.ts b/tests/generateCTS.ts index d624b7adc4..dab3e4ab0c 100644 --- a/tests/generateCTS.ts +++ b/tests/generateCTS.ts @@ -13,7 +13,6 @@ type Language = typeof availableLanguages[number]; type ParametersWithDataType = { key: string; value: string; - isDate: boolean; isArray: boolean; isObject: boolean; isString: boolean; @@ -166,16 +165,14 @@ async function loadCTSForClient(client: string): Promise { // include the `-last` param to join with comma in mustache test.parametersWithDataType = Object.entries(test.parameters).map( ([key, value], i, arr) => { - const isDate = key === 'endAt'; const isArray = Array.isArray(value); return { key, value: JSON.stringify(value), - isString: typeof value === 'string' && isDate === false, + isString: typeof value === 'string', isObject: typeof value === 'object' && isArray === false, isArray, - isDate, '-last': i === arr.length - 1, }; } diff --git a/tests/output/javascript/abtesting.test.ts b/tests/output/javascript/abtesting.test.ts index 40bc999818..8bdbde5eef 100644 --- a/tests/output/javascript/abtesting.test.ts +++ b/tests/output/javascript/abtesting.test.ts @@ -1,4 +1,5 @@ import { AbtestingApi, EchoRequester } from '@algolia/client-abtesting'; +import type { EchoResponse } from '@algolia/client-abtesting'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -9,18 +10,18 @@ const client = new AbtestingApi(appId, apiKey, 'us', { describe('addABTests', () => { test('addABTests with minimal parameters', async () => { - const req = await client.addABTests({ - endAt: new Date('2022-12-31'), + const req = (await client.addABTests({ + endAt: '2022-12-31T00:00:00.000Z', name: 'myABTest', variant: [ { index: 'AB_TEST_1', trafficPercentage: 30 }, { index: 'AB_TEST_2', trafficPercentage: 50 }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/abtests'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/2/abtests'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ endAt: '2022-12-31T00:00:00.000Z', name: 'myABTest', variant: [ @@ -28,59 +29,57 @@ describe('addABTests', () => { { index: 'AB_TEST_2', trafficPercentage: 50 }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteABTest', () => { test('deleteABTest', async () => { - const req = await client.deleteABTest({ + const req = (await client.deleteABTest({ id: 42, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/abtests/42'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/2/abtests/42'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getABTest', () => { test('getABTest', async () => { - const req = await client.getABTest({ - id: 42, - }); + const req = (await client.getABTest({ id: 42 })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/abtests/42'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/2/abtests/42'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('listABTests', () => { test('listABTests with minimal parameters', async () => { - const req = await client.listABTests({ + const req = (await client.listABTests({ offset: 42, limit: 21, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/abtests'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ offset: '42', limit: '21' }); + expect(req.path).toEqual('/2/abtests'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ offset: '42', limit: '21' }); }); }); describe('stopABTest', () => { test('stopABTest', async () => { - const req = await client.stopABTest({ + const req = (await client.stopABTest({ id: 42, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/abtests/42/stop'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/2/abtests/42/stop'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index 5b07214699..a7ba9d0aeb 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -1,4 +1,5 @@ import { AnalyticsApi, EchoRequester } from '@algolia/client-analytics'; +import type { EchoResponse } from '@algolia/client-analytics'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -9,28 +10,28 @@ const client = new AnalyticsApi(appId, apiKey, 'us', { describe('getAverageClickPosition', () => { test('get getAverageClickPosition with minimal parameters', async () => { - const req = await client.getAverageClickPosition({ + const req = (await client.getAverageClickPosition({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/clicks/averageClickPosition'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/clicks/averageClickPosition'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getAverageClickPosition with all parameters', async () => { - const req = await client.getAverageClickPosition({ + const req = (await client.getAverageClickPosition({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/clicks/averageClickPosition'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/clicks/averageClickPosition'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -41,28 +42,28 @@ describe('getAverageClickPosition', () => { describe('getClickPositions', () => { test('get getClickPositions with minimal parameters', async () => { - const req = await client.getClickPositions({ + const req = (await client.getClickPositions({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/clicks/positions'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/clicks/positions'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getClickPositions with all parameters', async () => { - const req = await client.getClickPositions({ + const req = (await client.getClickPositions({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/clicks/positions'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/clicks/positions'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -73,28 +74,28 @@ describe('getClickPositions', () => { describe('getClickThroughRate', () => { test('get getClickThroughRate with minimal parameters', async () => { - const req = await client.getClickThroughRate({ + const req = (await client.getClickThroughRate({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/clicks/clickThroughRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/clicks/clickThroughRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getClickThroughRate with all parameters', async () => { - const req = await client.getClickThroughRate({ + const req = (await client.getClickThroughRate({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/clicks/clickThroughRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/clicks/clickThroughRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -105,28 +106,28 @@ describe('getClickThroughRate', () => { describe('getConversationRate', () => { test('get getConversationRate with minimal parameters', async () => { - const req = await client.getConversationRate({ + const req = (await client.getConversationRate({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/conversions/conversionRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/conversions/conversionRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getConversationRate with all parameters', async () => { - const req = await client.getConversationRate({ + const req = (await client.getConversationRate({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/conversions/conversionRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/conversions/conversionRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -137,28 +138,28 @@ describe('getConversationRate', () => { describe('getNoClickRate', () => { test('get getNoClickRate with minimal parameters', async () => { - const req = await client.getNoClickRate({ + const req = (await client.getNoClickRate({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noClickRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/searches/noClickRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getNoClickRate with all parameters', async () => { - const req = await client.getNoClickRate({ + const req = (await client.getNoClickRate({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noClickRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/searches/noClickRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -169,28 +170,28 @@ describe('getNoClickRate', () => { describe('getNoResultsRate', () => { test('get getNoResultsRate with minimal parameters', async () => { - const req = await client.getNoResultsRate({ + const req = (await client.getNoResultsRate({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noResultRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/searches/noResultRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getNoResultsRate with all parameters', async () => { - const req = await client.getNoResultsRate({ + const req = (await client.getNoResultsRate({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noResultRate'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/searches/noResultRate'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -201,28 +202,28 @@ describe('getNoResultsRate', () => { describe('getSearchesCount', () => { test('get getSearchesCount with minimal parameters', async () => { - const req = await client.getSearchesCount({ + const req = (await client.getSearchesCount({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/count'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/searches/count'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getSearchesCount with all parameters', async () => { - const req = await client.getSearchesCount({ + const req = (await client.getSearchesCount({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/count'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/searches/count'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -233,30 +234,30 @@ describe('getSearchesCount', () => { describe('getSearchesNoClicks', () => { test('get getSearchesNoClicks with minimal parameters', async () => { - const req = await client.getSearchesNoClicks({ + const req = (await client.getSearchesNoClicks({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noClicks'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/searches/noClicks'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getSearchesNoClicks with all parameters', async () => { - const req = await client.getSearchesNoClicks({ + const req = (await client.getSearchesNoClicks({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noClicks'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/searches/noClicks'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -269,30 +270,30 @@ describe('getSearchesNoClicks', () => { describe('getSearchesNoResults', () => { test('get getSearchesNoResults with minimal parameters', async () => { - const req = await client.getSearchesNoResults({ + const req = (await client.getSearchesNoResults({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noResults'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/searches/noResults'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getSearchesNoResults with all parameters', async () => { - const req = await client.getSearchesNoResults({ + const req = (await client.getSearchesNoResults({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches/noResults'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/searches/noResults'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -305,43 +306,43 @@ describe('getSearchesNoResults', () => { describe('getStatus', () => { test('get getStatus with minimal parameters', async () => { - const req = await client.getStatus({ + const req = (await client.getStatus({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/status'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/status'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); }); describe('getTopCountries', () => { test('get getTopCountries with minimal parameters', async () => { - const req = await client.getTopCountries({ + const req = (await client.getTopCountries({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/countries'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/countries'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getTopCountries with all parameters', async () => { - const req = await client.getTopCountries({ + const req = (await client.getTopCountries({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/countries'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/countries'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', @@ -354,18 +355,18 @@ describe('getTopCountries', () => { describe('getTopFilterAttributes', () => { test('get getTopFilterAttributes with minimal parameters', async () => { - const req = await client.getTopFilterAttributes({ + const req = (await client.getTopFilterAttributes({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/filters'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getTopFilterAttributes with all parameters', async () => { - const req = await client.getTopFilterAttributes({ + const req = (await client.getTopFilterAttributes({ index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -373,12 +374,12 @@ describe('getTopFilterAttributes', () => { limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/filters'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -392,31 +393,31 @@ describe('getTopFilterAttributes', () => { describe('getTopFilterForAttribute', () => { test('get getTopFilterForAttribute with minimal parameters', async () => { - const req = await client.getTopFilterForAttribute({ + const req = (await client.getTopFilterForAttribute({ attribute: 'myAttribute', index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters/myAttribute'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/filters/myAttribute'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getTopFilterForAttribute with minimal parameters and multiple attributes', async () => { - const req = await client.getTopFilterForAttribute({ + const req = (await client.getTopFilterForAttribute({ attribute: 'myAttribute1,myAttribute2', index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters/myAttribute1%2CmyAttribute2'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/filters/myAttribute1%2CmyAttribute2'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getTopFilterForAttribute with all parameters', async () => { - const req = await client.getTopFilterForAttribute({ + const req = (await client.getTopFilterForAttribute({ attribute: 'myAttribute', index: 'index', search: 'mySearch', @@ -425,12 +426,12 @@ describe('getTopFilterForAttribute', () => { limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters/myAttribute'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/filters/myAttribute'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -442,7 +443,7 @@ describe('getTopFilterForAttribute', () => { }); test('get getTopFilterForAttribute with all parameters and multiple attributes', async () => { - const req = await client.getTopFilterForAttribute({ + const req = (await client.getTopFilterForAttribute({ attribute: 'myAttribute1,myAttribute2', index: 'index', search: 'mySearch', @@ -451,12 +452,12 @@ describe('getTopFilterForAttribute', () => { limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters/myAttribute1%2CmyAttribute2'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/filters/myAttribute1%2CmyAttribute2'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -470,18 +471,18 @@ describe('getTopFilterForAttribute', () => { describe('getTopFiltersNoResults', () => { test('get getTopFiltersNoResults with minimal parameters', async () => { - const req = await client.getTopFiltersNoResults({ + const req = (await client.getTopFiltersNoResults({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters/noResults'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/filters/noResults'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getTopFiltersNoResults with all parameters', async () => { - const req = await client.getTopFiltersNoResults({ + const req = (await client.getTopFiltersNoResults({ index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -489,12 +490,12 @@ describe('getTopFiltersNoResults', () => { limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/filters/noResults'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/filters/noResults'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -508,18 +509,18 @@ describe('getTopFiltersNoResults', () => { describe('getTopHits', () => { test('get getTopHits with minimal parameters', async () => { - const req = await client.getTopHits({ + const req = (await client.getTopHits({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/hits'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/hits'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getTopHits with all parameters', async () => { - const req = await client.getTopHits({ + const req = (await client.getTopHits({ index: 'index', search: 'mySearch', clickAnalytics: true, @@ -528,12 +529,12 @@ describe('getTopHits', () => { limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/hits'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/hits'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', search: 'mySearch', clickAnalytics: 'true', @@ -548,18 +549,18 @@ describe('getTopHits', () => { describe('getTopSearches', () => { test('get getTopSearches with minimal parameters', async () => { - const req = await client.getTopSearches({ + const req = (await client.getTopSearches({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/searches'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getTopSearches with all parameters', async () => { - const req = await client.getTopSearches({ + const req = (await client.getTopSearches({ index: 'index', clickAnalytics: true, startDate: '1999-09-19', @@ -569,12 +570,12 @@ describe('getTopSearches', () => { limit: 21, offset: 42, tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/searches'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/searches'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', clickAnalytics: 'true', startDate: '1999-09-19', @@ -590,28 +591,28 @@ describe('getTopSearches', () => { describe('getUsersCount', () => { test('get getUsersCount with minimal parameters', async () => { - const req = await client.getUsersCount({ + const req = (await client.getUsersCount({ index: 'index', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/users/count'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ index: 'index' }); + expect(req.path).toEqual('/2/users/count'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index' }); }); test('get getUsersCount with all parameters', async () => { - const req = await client.getUsersCount({ + const req = (await client.getUsersCount({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/2/users/count'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/2/users/count'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', diff --git a/tests/output/javascript/insights.test.ts b/tests/output/javascript/insights.test.ts index 56ba5036c5..9a9d144467 100644 --- a/tests/output/javascript/insights.test.ts +++ b/tests/output/javascript/insights.test.ts @@ -1,4 +1,5 @@ import { InsightsApi, EchoRequester } from '@algolia/client-insights'; +import type { EchoResponse } from '@algolia/client-insights'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -9,7 +10,7 @@ const client = new InsightsApi(appId, apiKey, { describe('pushEvents', () => { test('pushEvents', async () => { - const req = await client.pushEvents({ + const req = (await client.pushEvents({ events: [ { eventType: 'click', @@ -39,11 +40,11 @@ describe('pushEvents', () => { queryID: '43b15df305339e827f0ac0bdc5ebcaa7', }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/events'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/events'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ events: [ { eventType: 'click', @@ -74,6 +75,6 @@ describe('pushEvents', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/personalization.test.ts b/tests/output/javascript/personalization.test.ts index 392e5bac1a..d735e23d6a 100644 --- a/tests/output/javascript/personalization.test.ts +++ b/tests/output/javascript/personalization.test.ts @@ -2,6 +2,7 @@ import { PersonalizationApi, EchoRequester, } from '@algolia/client-personalization'; +import type { EchoResponse } from '@algolia/client-personalization'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -12,56 +13,57 @@ const client = new PersonalizationApi(appId, apiKey, 'us', { describe('deleteUserProfile', () => { test('delete deleteUserProfile', async () => { - const req = await client.deleteUserProfile({ + const req = (await client.deleteUserProfile({ userToken: 'UserToken', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/profiles/UserToken'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/profiles/UserToken'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getPersonalizationStrategy', () => { test('get getPersonalizationStrategy', async () => { - const req = await client.getPersonalizationStrategy(); + const req = + (await client.getPersonalizationStrategy()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/strategies/personalization'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/strategies/personalization'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getUserTokenProfile', () => { test('get getUserTokenProfile', async () => { - const req = await client.getUserTokenProfile({ + const req = (await client.getUserTokenProfile({ userToken: 'UserToken', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/profiles/personalization/UserToken'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/profiles/personalization/UserToken'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('setPersonalizationStrategy', () => { test('set setPersonalizationStrategy', async () => { - const req = await client.setPersonalizationStrategy({ + const req = (await client.setPersonalizationStrategy({ eventScoring: [{ score: 42, eventName: 'Algolia', eventType: 'Event' }], facetScoring: [{ score: 42, facetName: 'Event' }], personalizationImpact: 42, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/strategies/personalization'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/strategies/personalization'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ eventScoring: [{ score: 42, eventName: 'Algolia', eventType: 'Event' }], facetScoring: [{ score: 42, facetName: 'Event' }], personalizationImpact: 42, }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/query-suggestions.test.ts b/tests/output/javascript/query-suggestions.test.ts index 8a1a3f3cb4..e8dcdf3275 100644 --- a/tests/output/javascript/query-suggestions.test.ts +++ b/tests/output/javascript/query-suggestions.test.ts @@ -2,6 +2,7 @@ import { QuerySuggestionsApi, EchoRequester, } from '@algolia/client-query-suggestions'; +import type { EchoResponse } from '@algolia/client-query-suggestions'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -12,7 +13,7 @@ const client = new QuerySuggestionsApi(appId, apiKey, 'us', { describe('createConfig', () => { test('createConfig', async () => { - const req = await client.createConfig({ + const req = (await client.createConfig({ indexName: 'theIndexName', sourceIndices: [ { @@ -23,11 +24,11 @@ describe('createConfig', () => { ], languages: ['french'], exclude: ['test'], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/configs'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/configs'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ indexName: 'theIndexName', sourceIndices: [ { @@ -39,76 +40,76 @@ describe('createConfig', () => { languages: ['french'], exclude: ['test'], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteConfig', () => { test('deleteConfig', async () => { - const req = await client.deleteConfig({ + const req = (await client.deleteConfig({ indexName: 'theIndexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/configs/theIndexName'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/configs/theIndexName'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getAllConfigs', () => { test('getAllConfigs', async () => { - const req = await client.getAllConfigs(); + const req = (await client.getAllConfigs()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/configs'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/configs'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getConfig', () => { test('getConfig', async () => { - const req = await client.getConfig({ + const req = (await client.getConfig({ indexName: 'theIndexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/configs/theIndexName'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/configs/theIndexName'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getConfigStatus', () => { test('getConfigStatus', async () => { - const req = await client.getConfigStatus({ + const req = (await client.getConfigStatus({ indexName: 'theIndexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/configs/theIndexName/status'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/configs/theIndexName/status'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getLogFile', () => { test('getLogFile', async () => { - const req = await client.getLogFile({ + const req = (await client.getLogFile({ indexName: 'theIndexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/logs/theIndexName'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/logs/theIndexName'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('updateConfig', () => { test('updateConfig', async () => { - const req = await client.updateConfig({ + const req = (await client.updateConfig({ indexName: 'theIndexName', querySuggestionsIndexParam: { sourceIndices: [ @@ -121,11 +122,11 @@ describe('updateConfig', () => { languages: ['french'], exclude: ['test'], }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/configs/theIndexName'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/configs/theIndexName'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ sourceIndices: [ { indexName: 'testIndex', @@ -136,6 +137,6 @@ describe('updateConfig', () => { languages: ['french'], exclude: ['test'], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/recommend.test.ts b/tests/output/javascript/recommend.test.ts index d3f92cbeed..f3ef59a022 100644 --- a/tests/output/javascript/recommend.test.ts +++ b/tests/output/javascript/recommend.test.ts @@ -1,4 +1,5 @@ import { RecommendApi, EchoRequester } from '@algolia/recommend'; +import type { EchoResponse } from '@algolia/recommend'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -9,7 +10,7 @@ const client = new RecommendApi(appId, apiKey, { describe('getRecommendations', () => { test('get recommendations with minimal parameters', async () => { - const req = await client.getRecommendations({ + const req = (await client.getRecommendations({ requests: [ { indexName: 'indexName', @@ -18,11 +19,11 @@ describe('getRecommendations', () => { threshold: 42, }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/recommendations'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/recommendations'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { indexName: 'indexName', @@ -32,11 +33,11 @@ describe('getRecommendations', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get recommendations with all parameters', async () => { - const req = await client.getRecommendations({ + const req = (await client.getRecommendations({ requests: [ { indexName: 'indexName', @@ -47,11 +48,11 @@ describe('getRecommendations', () => { fallbackParameters: { query: 'myQuery', facetFilters: ['fallback'] }, }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/recommendations'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/recommendations'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { indexName: 'indexName', @@ -63,11 +64,11 @@ describe('getRecommendations', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get multiple recommendations with minimal parameters', async () => { - const req = await client.getRecommendations({ + const req = (await client.getRecommendations({ requests: [ { indexName: 'indexName1', @@ -82,11 +83,11 @@ describe('getRecommendations', () => { threshold: 21, }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/recommendations'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/recommendations'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { indexName: 'indexName1', @@ -102,11 +103,11 @@ describe('getRecommendations', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get multiple recommendations with all parameters', async () => { - const req = await client.getRecommendations({ + const req = (await client.getRecommendations({ requests: [ { indexName: 'indexName1', @@ -125,11 +126,11 @@ describe('getRecommendations', () => { fallbackParameters: { query: 'myQuery', facetFilters: ['fallback2'] }, }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/recommendations'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/recommendations'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { indexName: 'indexName1', @@ -149,11 +150,11 @@ describe('getRecommendations', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get frequently bought together recommendations', async () => { - const req = await client.getRecommendations({ + const req = (await client.getRecommendations({ requests: [ { indexName: 'indexName1', @@ -162,11 +163,11 @@ describe('getRecommendations', () => { threshold: 42, }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/recommendations'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/recommendations'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { indexName: 'indexName1', @@ -176,6 +177,6 @@ describe('getRecommendations', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/search.test.ts b/tests/output/javascript/search.test.ts index 21c2600814..434d0a6d15 100644 --- a/tests/output/javascript/search.test.ts +++ b/tests/output/javascript/search.test.ts @@ -1,4 +1,5 @@ import { SearchApi, EchoRequester } from '@algolia/client-search'; +import type { EchoResponse } from '@algolia/client-search'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; @@ -7,78 +8,76 @@ const client = new SearchApi(appId, apiKey, { requester: new EchoRequester() }); describe('addApiKey', () => { test('addApiKey', async () => { - const req = await client.addApiKey({ + const req = (await client.addApiKey({ acl: ['search', 'addObject'], description: 'my new api key', validity: 300, maxQueriesPerIPPerHour: 100, maxHitsPerQuery: 20, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/keys'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/keys'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ acl: ['search', 'addObject'], description: 'my new api key', validity: 300, maxQueriesPerIPPerHour: 100, maxHitsPerQuery: 20, }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('addOrUpdateObject', () => { test('addOrUpdateObject', async () => { - const req = await client.addOrUpdateObject({ + const req = (await client.addOrUpdateObject({ indexName: 'indexName', objectID: 'uniqueID', body: { key: 'value' }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/uniqueID'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ key: 'value' }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/uniqueID'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ key: 'value' }); + expect(req.searchParams).toEqual(undefined); }); }); describe('appendSource', () => { test('appendSource', async () => { - const req = await client.appendSource({ + const req = (await client.appendSource({ source: 'theSource', description: 'theDescription', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/security/sources/append'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/security/sources/append'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ source: 'theSource', description: 'theDescription', }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('assignUserId', () => { test('assignUserId', async () => { - const req = await client.assignUserId({ + const req = (await client.assignUserId({ xAlgoliaUserID: 'userID', assignUserIdObject: { cluster: 'theCluster' }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ cluster: 'theCluster' }); - expect((req as any).searchParams).toEqual({ - 'X-Algolia-User-ID': 'userID', - }); + expect(req.path).toEqual('/1/clusters/mapping'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ cluster: 'theCluster' }); + expect(req.searchParams).toEqual({ 'X-Algolia-User-ID': 'userID' }); }); }); describe('batch', () => { test('batch', async () => { - const req = await client.batch({ + const req = (await client.batch({ indexName: 'theIndexName', batchWriteObject: { requests: [ @@ -89,11 +88,11 @@ describe('batch', () => { }, ], }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/batch'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/theIndexName/batch'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { action: 'delete', @@ -102,35 +101,33 @@ describe('batch', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('batchAssignUserIds', () => { test('batchAssignUserIds', async () => { - const req = await client.batchAssignUserIds({ + const req = (await client.batchAssignUserIds({ xAlgoliaUserID: 'userID', batchAssignUserIdsObject: { cluster: 'theCluster', users: ['user1', 'user2'], }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping/batch'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/clusters/mapping/batch'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ cluster: 'theCluster', users: ['user1', 'user2'], }); - expect((req as any).searchParams).toEqual({ - 'X-Algolia-User-ID': 'userID', - }); + expect(req.searchParams).toEqual({ 'X-Algolia-User-ID': 'userID' }); }); }); describe('batchDictionaryEntries', () => { test('get batchDictionaryEntries results with minimal parameters', async () => { - const req = await client.batchDictionaryEntries({ + const req = (await client.batchDictionaryEntries({ dictionaryName: 'compounds', batchDictionaryEntries: { requests: [ @@ -138,21 +135,21 @@ describe('batchDictionaryEntries', () => { { action: 'deleteEntry', body: { objectID: '2', language: 'fr' } }, ], }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/compounds/batch'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/dictionaries/compounds/batch'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { action: 'addEntry', body: { objectID: '1', language: 'en' } }, { action: 'deleteEntry', body: { objectID: '2', language: 'fr' } }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get batchDictionaryEntries results with all parameters', async () => { - const req = await client.batchDictionaryEntries({ + const req = (await client.batchDictionaryEntries({ dictionaryName: 'compounds', batchDictionaryEntries: { clearExistingDictionaryEntries: false, @@ -181,11 +178,11 @@ describe('batchDictionaryEntries', () => { }, ], }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/compounds/batch'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/dictionaries/compounds/batch'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ clearExistingDictionaryEntries: false, requests: [ { @@ -212,13 +209,13 @@ describe('batchDictionaryEntries', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('batchRules', () => { test('batchRules', async () => { - const req = await client.batchRules({ + const req = (await client.batchRules({ indexName: 'indexName', rule: [ { @@ -234,11 +231,11 @@ describe('batchRules', () => { ], forwardToReplicas: true, clearExistingRules: true, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/rules/batch'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual([ + expect(req.path).toEqual('/1/indexes/indexName/rules/batch'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual([ { objectID: 'a-rule-id', conditions: [{ pattern: 'smartphone', anchoring: 'contains' }], @@ -250,7 +247,7 @@ describe('batchRules', () => { consequence: { params: { filters: 'brand:apple' } }, }, ]); - expect((req as any).searchParams).toEqual({ + expect(req.searchParams).toEqual({ forwardToReplicas: 'true', clearExistingRules: 'true', }); @@ -259,217 +256,219 @@ describe('batchRules', () => { describe('browse', () => { test('get browse results with minimal parameters', async () => { - const req = await client.browse({ + const req = (await client.browse({ indexName: 'indexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/browse'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/browse'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get browse results with all parameters', async () => { - const req = await client.browse({ + const req = (await client.browse({ indexName: 'indexName', browseRequest: { params: "query=foo&facetFilters=['bar']", cursor: 'cts', }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/browse'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/indexName/browse'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ params: "query=foo&facetFilters=['bar']", cursor: 'cts', }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('clearAllSynonyms', () => { test('clearAllSynonyms', async () => { - const req = await client.clearAllSynonyms({ + const req = (await client.clearAllSynonyms({ indexName: 'indexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/clear'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/synonyms/clear'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('clearObjects', () => { test('clearObjects', async () => { - const req = await client.clearObjects({ + const req = (await client.clearObjects({ indexName: 'theIndexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/clear'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/theIndexName/clear'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('clearRules', () => { test('clearRules', async () => { - const req = await client.clearRules({ + const req = (await client.clearRules({ indexName: 'indexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/rules/clear'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/rules/clear'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteApiKey', () => { test('deleteApiKey', async () => { - const req = await client.deleteApiKey({ + const req = (await client.deleteApiKey({ key: 'myTestApiKey', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/keys/myTestApiKey'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/keys/myTestApiKey'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteBy', () => { test('deleteBy', async () => { - const req = await client.deleteBy({ + const req = (await client.deleteBy({ indexName: 'theIndexName', searchParams: { query: 'testQuery' }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/deleteByQuery'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ query: 'testQuery' }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/theIndexName/deleteByQuery'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ query: 'testQuery' }); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteIndex', () => { test('deleteIndex', async () => { - const req = await client.deleteIndex({ + const req = (await client.deleteIndex({ indexName: 'theIndexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/theIndexName'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteObject', () => { test('deleteObject', async () => { - const req = await client.deleteObject({ + const req = (await client.deleteObject({ indexName: 'theIndexName', objectID: 'uniqueID', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/uniqueID'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/theIndexName/uniqueID'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteRule', () => { test('deleteRule', async () => { - const req = await client.deleteRule({ + const req = (await client.deleteRule({ indexName: 'indexName', objectID: 'id1', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/rules/id1'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/rules/id1'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteSource', () => { test('deleteSource', async () => { - const req = await client.deleteSource({ + const req = (await client.deleteSource({ source: 'theSource', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/security/sources/theSource'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/security/sources/theSource'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('deleteSynonym', () => { test('deleteSynonym', async () => { - const req = await client.deleteSynonym({ + const req = (await client.deleteSynonym({ indexName: 'indexName', objectID: 'id1', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/id1'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/synonyms/id1'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getApiKey', () => { test('getApiKey', async () => { - const req = await client.getApiKey({ + const req = (await client.getApiKey({ key: 'myTestApiKey', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/keys/myTestApiKey'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/keys/myTestApiKey'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getDictionaryLanguages', () => { test('get getDictionaryLanguages', async () => { - const req = await client.getDictionaryLanguages(); + const req = + (await client.getDictionaryLanguages()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/*/languages'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/dictionaries/*/languages'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getDictionarySettings', () => { test('get getDictionarySettings results', async () => { - const req = await client.getDictionarySettings(); + const req = + (await client.getDictionarySettings()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/*/settings'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/dictionaries/*/settings'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getLogs', () => { test('getLogs', async () => { - const req = await client.getLogs({ + const req = (await client.getLogs({ offset: 5, length: 10, indexName: 'theIndexName', type: 'all', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/logs'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/1/logs'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ offset: '5', length: '10', indexName: 'theIndexName', @@ -480,24 +479,22 @@ describe('getLogs', () => { describe('getObject', () => { test('getObject', async () => { - const req = await client.getObject({ + const req = (await client.getObject({ indexName: 'theIndexName', objectID: 'uniqueID', attributesToRetrieve: ['attr1', 'attr2'], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/uniqueID'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ - attributesToRetrieve: 'attr1,attr2', - }); + expect(req.path).toEqual('/1/indexes/theIndexName/uniqueID'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ attributesToRetrieve: 'attr1,attr2' }); }); }); describe('getObjects', () => { test('getObjects', async () => { - const req = await client.getObjects({ + const req = (await client.getObjects({ requests: [ { attributesToRetrieve: ['attr1', 'attr2'], @@ -505,11 +502,11 @@ describe('getObjects', () => { indexName: 'theIndexName', }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/objects'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/objects'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { attributesToRetrieve: ['attr1', 'attr2'], @@ -518,168 +515,165 @@ describe('getObjects', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getRule', () => { test('getRule', async () => { - const req = await client.getRule({ + const req = (await client.getRule({ indexName: 'indexName', objectID: 'id1', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/rules/id1'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/rules/id1'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getSettings', () => { test('getSettings', async () => { - const req = await client.getSettings({ + const req = (await client.getSettings({ indexName: 'theIndexName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/settings'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/theIndexName/settings'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getSources', () => { test('getSources', async () => { - const req = await client.getSources(); + const req = (await client.getSources()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/security/sources'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/security/sources'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getSynonym', () => { test('getSynonym', async () => { - const req = await client.getSynonym({ + const req = (await client.getSynonym({ indexName: 'indexName', objectID: 'id1', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/id1'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/synonyms/id1'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getTask', () => { test('getTask', async () => { - const req = await client.getTask({ + const req = (await client.getTask({ indexName: 'theIndexName', taskID: 123, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/task/123'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/theIndexName/task/123'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getTopUserIds', () => { test('getTopUserIds', async () => { - const req = await client.getTopUserIds(); + const req = (await client.getTopUserIds()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping/top'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/clusters/mapping/top'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('getUserId', () => { test('getUserId', async () => { - const req = await client.getUserId({ + const req = (await client.getUserId({ userID: 'uniqueID', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping/uniqueID'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/clusters/mapping/uniqueID'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('hasPendingMappings', () => { test('hasPendingMappings', async () => { - const req = await client.hasPendingMappings({ + const req = (await client.hasPendingMappings({ getClusters: true, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping/pending'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ getClusters: 'true' }); + expect(req.path).toEqual('/1/clusters/mapping/pending'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ getClusters: 'true' }); }); }); describe('listApiKeys', () => { test('listApiKeys', async () => { - const req = await client.listApiKeys(); + const req = (await client.listApiKeys()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/keys'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/keys'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('listClusters', () => { test('listClusters', async () => { - const req = await client.listClusters(); + const req = (await client.listClusters()) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/clusters'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('listIndices', () => { test('listIndices', async () => { - const req = await client.listIndices({ + const req = (await client.listIndices({ page: 8, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ page: '8' }); + expect(req.path).toEqual('/1/indexes'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ page: '8' }); }); }); describe('listUserIds', () => { test('listUserIds', async () => { - const req = await client.listUserIds({ + const req = (await client.listUserIds({ page: 8, hitsPerPage: 100, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping'); - expect((req as any).method).toEqual('GET'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ - page: '8', - hitsPerPage: '100', - }); + expect(req.path).toEqual('/1/clusters/mapping'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ page: '8', hitsPerPage: '100' }); }); }); describe('multipleBatch', () => { test('multipleBatch', async () => { - const req = await client.multipleBatch({ + const req = (await client.multipleBatch({ requests: [ { action: 'addObject', @@ -687,11 +681,11 @@ describe('multipleBatch', () => { indexName: 'theIndexName', }, ], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/batch'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/batch'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { action: 'addObject', @@ -700,13 +694,13 @@ describe('multipleBatch', () => { }, ], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('multipleQueries', () => { test('multipleQueries', async () => { - const req = await client.multipleQueries({ + const req = (await client.multipleQueries({ requests: [ { indexName: 'theIndexName', @@ -717,11 +711,11 @@ describe('multipleQueries', () => { }, ], strategy: 'stopIfEnoughMatches', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/*/queries'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/*/queries'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ requests: [ { indexName: 'theIndexName', @@ -733,112 +727,110 @@ describe('multipleQueries', () => { ], strategy: 'stopIfEnoughMatches', }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('operationIndex', () => { test('operationIndex', async () => { - const req = await client.operationIndex({ + const req = (await client.operationIndex({ indexName: 'theIndexName', operationIndexObject: { operation: 'copy', destination: 'dest', scope: ['rules', 'settings'], }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/operation'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/theIndexName/operation'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ operation: 'copy', destination: 'dest', scope: ['rules', 'settings'], }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('partialUpdateObject', () => { test('partialUpdateObject', async () => { - const req = await client.partialUpdateObject({ + const req = (await client.partialUpdateObject({ indexName: 'theIndexName', objectID: 'uniqueID', stringBuildInOperation: [ { id1: 'test', id2: { _operation: 'AddUnique', value: 'test2' } }, ], createIfNotExists: true, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual( - '/1/indexes/theIndexName/uniqueID/partial' - ); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual([ + expect(req.path).toEqual('/1/indexes/theIndexName/uniqueID/partial'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual([ { id1: 'test', id2: { _operation: 'AddUnique', value: 'test2' } }, ]); - expect((req as any).searchParams).toEqual({ createIfNotExists: 'true' }); + expect(req.searchParams).toEqual({ createIfNotExists: 'true' }); }); }); describe('removeUserId', () => { test('removeUserId', async () => { - const req = await client.removeUserId({ + const req = (await client.removeUserId({ userID: 'uniqueID', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping/uniqueID'); - expect((req as any).method).toEqual('DELETE'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/clusters/mapping/uniqueID'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('replaceSources', () => { test('replaceSources', async () => { - const req = await client.replaceSources({ + const req = (await client.replaceSources({ source: [{ source: 'theSource', description: 'theDescription' }], - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/security/sources'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual([ + expect(req.path).toEqual('/1/security/sources'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual([ { source: 'theSource', description: 'theDescription' }, ]); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('restoreApiKey', () => { test('restoreApiKey', async () => { - const req = await client.restoreApiKey({ + const req = (await client.restoreApiKey({ key: 'myApiKey', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/keys/myApiKey/restore'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/keys/myApiKey/restore'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('saveObject', () => { test('saveObject', async () => { - const req = await client.saveObject({ + const req = (await client.saveObject({ indexName: 'theIndexName', body: { objectID: 'id', test: 'val' }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ objectID: 'id', test: 'val' }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/theIndexName'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ objectID: 'id', test: 'val' }); + expect(req.searchParams).toEqual(undefined); }); }); describe('saveRule', () => { test('saveRule', async () => { - const req = await client.saveRule({ + const req = (await client.saveRule({ indexName: 'indexName', objectID: 'id1', rule: { @@ -847,22 +839,22 @@ describe('saveRule', () => { consequence: { params: { filters: 'brand:apple' } }, }, forwardToReplicas: true, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/rules/id1'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/indexName/rules/id1'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ objectID: 'id1', conditions: [{ pattern: 'apple', anchoring: 'contains' }], consequence: { params: { filters: 'brand:apple' } }, }); - expect((req as any).searchParams).toEqual({ forwardToReplicas: 'true' }); + expect(req.searchParams).toEqual({ forwardToReplicas: 'true' }); }); }); describe('saveSynonym', () => { test('saveSynonym', async () => { - const req = await client.saveSynonym({ + const req = (await client.saveSynonym({ indexName: 'indexName', objectID: 'id1', synonymHit: { @@ -871,22 +863,22 @@ describe('saveSynonym', () => { synonyms: ['car', 'vehicule', 'auto'], }, forwardToReplicas: true, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/id1'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/indexName/synonyms/id1'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ objectID: 'id1', type: 'synonym', synonyms: ['car', 'vehicule', 'auto'], }); - expect((req as any).searchParams).toEqual({ forwardToReplicas: 'true' }); + expect(req.searchParams).toEqual({ forwardToReplicas: 'true' }); }); }); describe('saveSynonyms', () => { test('saveSynonyms', async () => { - const req = await client.saveSynonyms({ + const req = (await client.saveSynonyms({ indexName: 'indexName', synonymHit: [ { @@ -903,11 +895,11 @@ describe('saveSynonyms', () => { ], forwardToReplicas: true, replaceExistingSynonyms: false, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/batch'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual([ + expect(req.path).toEqual('/1/indexes/indexName/synonyms/batch'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual([ { objectID: 'id1', type: 'synonym', @@ -920,7 +912,7 @@ describe('saveSynonyms', () => { synonyms: ['ephone', 'aphone', 'yphone'], }, ]); - expect((req as any).searchParams).toEqual({ + expect(req.searchParams).toEqual({ forwardToReplicas: 'true', replaceExistingSynonyms: 'false', }); @@ -929,33 +921,33 @@ describe('saveSynonyms', () => { describe('search', () => { test('search', async () => { - const req = await client.search({ + const req = (await client.search({ indexName: 'indexName', searchParams: { query: 'myQuery' }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/query'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ query: 'myQuery' }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/query'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ query: 'myQuery' }); + expect(req.searchParams).toEqual(undefined); }); }); describe('searchDictionaryEntries', () => { test('get searchDictionaryEntries results with minimal parameters', async () => { - const req = await client.searchDictionaryEntries({ + const req = (await client.searchDictionaryEntries({ dictionaryName: 'compounds', searchDictionaryEntries: { query: 'foo' }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/compounds/search'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ query: 'foo' }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/dictionaries/compounds/search'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ query: 'foo' }); + expect(req.searchParams).toEqual(undefined); }); test('get searchDictionaryEntries results with all parameters', async () => { - const req = await client.searchDictionaryEntries({ + const req = (await client.searchDictionaryEntries({ dictionaryName: 'compounds', searchDictionaryEntries: { query: 'foo', @@ -963,37 +955,35 @@ describe('searchDictionaryEntries', () => { hitsPerPage: 2, language: 'fr', }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/compounds/search'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/dictionaries/compounds/search'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ query: 'foo', page: 4, hitsPerPage: 2, language: 'fr', }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('searchForFacetValues', () => { test('get searchForFacetValues results with minimal parameters', async () => { - const req = await client.searchForFacetValues({ + const req = (await client.searchForFacetValues({ indexName: 'indexName', facetName: 'facetName', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual( - '/1/indexes/indexName/facets/facetName/query' - ); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/facets/facetName/query'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get searchForFacetValues results with all parameters', async () => { - const req = await client.searchForFacetValues({ + const req = (await client.searchForFacetValues({ indexName: 'indexName', facetName: 'facetName', searchForFacetValuesRequest: { @@ -1001,47 +991,45 @@ describe('searchForFacetValues', () => { facetQuery: 'foo', maxFacetHits: 42, }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual( - '/1/indexes/indexName/facets/facetName/query' - ); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/indexes/indexName/facets/facetName/query'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ params: "query=foo&facetFilters=['bar']", facetQuery: 'foo', maxFacetHits: 42, }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('searchRules', () => { test('searchRules', async () => { - const req = await client.searchRules({ + const req = (await client.searchRules({ indexName: 'indexName', searchRulesParams: { query: 'something' }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/rules/search'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ query: 'something' }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.path).toEqual('/1/indexes/indexName/rules/search'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ query: 'something' }); + expect(req.searchParams).toEqual(undefined); }); }); describe('searchSynonyms', () => { test('searchSynonyms', async () => { - const req = await client.searchSynonyms({ + const req = (await client.searchSynonyms({ indexName: 'indexName', query: 'queryString', type: 'onewaysynonym', - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/search'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual(undefined); - expect((req as any).searchParams).toEqual({ + expect(req.path).toEqual('/1/indexes/indexName/synonyms/search'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'queryString', type: 'onewaysynonym', }); @@ -1050,79 +1038,79 @@ describe('searchSynonyms', () => { describe('searchUserIds', () => { test('searchUserIds', async () => { - const req = await client.searchUserIds({ + const req = (await client.searchUserIds({ query: 'test', clusterName: 'theClusterName', page: 5, hitsPerPage: 10, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/clusters/mapping/search'); - expect((req as any).method).toEqual('POST'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/clusters/mapping/search'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ query: 'test', clusterName: 'theClusterName', page: 5, hitsPerPage: 10, }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('setDictionarySettings', () => { test('get setDictionarySettings results with minimal parameters', async () => { - const req = await client.setDictionarySettings({ + const req = (await client.setDictionarySettings({ disableStandardEntries: { plurals: { fr: false, en: false, ru: true } }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/*/settings'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/dictionaries/*/settings'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ disableStandardEntries: { plurals: { fr: false, en: false, ru: true } }, }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); test('get setDictionarySettings results with all parameters', async () => { - const req = await client.setDictionarySettings({ + const req = (await client.setDictionarySettings({ disableStandardEntries: { plurals: { fr: false, en: false, ru: true }, stopwords: { fr: false }, compounds: { ru: true }, }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/dictionaries/*/settings'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/dictionaries/*/settings'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ disableStandardEntries: { plurals: { fr: false, en: false, ru: true }, stopwords: { fr: false }, compounds: { ru: true }, }, }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); }); describe('setSettings', () => { test('setSettings', async () => { - const req = await client.setSettings({ + const req = (await client.setSettings({ indexName: 'theIndexName', indexSettings: { paginationLimitedTo: 10 }, forwardToReplicas: true, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/indexes/theIndexName/settings'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ paginationLimitedTo: 10 }); - expect((req as any).searchParams).toEqual({ forwardToReplicas: 'true' }); + expect(req.path).toEqual('/1/indexes/theIndexName/settings'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ paginationLimitedTo: 10 }); + expect(req.searchParams).toEqual({ forwardToReplicas: 'true' }); }); }); describe('updateApiKey', () => { test('updateApiKey', async () => { - const req = await client.updateApiKey({ + const req = (await client.updateApiKey({ key: 'myApiKey', apiKey: { acl: ['search', 'addObject'], @@ -1130,16 +1118,16 @@ describe('updateApiKey', () => { maxQueriesPerIPPerHour: 100, maxHitsPerQuery: 20, }, - }); + })) as unknown as EchoResponse; - expect((req as any).path).toEqual('/1/keys/myApiKey'); - expect((req as any).method).toEqual('PUT'); - expect((req as any).data).toEqual({ + expect(req.path).toEqual('/1/keys/myApiKey'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ acl: ['search', 'addObject'], validity: 300, maxQueriesPerIPPerHour: 100, maxHitsPerQuery: 20, }); - expect((req as any).searchParams).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); }); });