Skip to content

Commit b17a574

Browse files
authored
Fixed a support of filtering by metadata for document list (#21)
1 parent 2eff272 commit b17a574

File tree

7 files changed

+48
-12
lines changed

7 files changed

+48
-12
lines changed

docs/DocumentsApi.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ const body:pd_api.DocumentsApiListDocumentsRequest = {
747747
formId: "BhVzRcxH9Z2LgfPPGXFUBa",
748748
// string | Returns results where 'membership_id' is present in document as owner (should be member uuid) (optional)
749749
membershipId: "BhVzRcxH9Z2LgfPPGXFUBa",
750-
// string | Specify metadata to filter by in the format of `metadata_{metadata-key}={metadata-value}` such as `metadata_opportunity_id=2181432`. The `metadata_` prefix is always required. (optional)
751-
metadata: "metadata_example",
750+
// Array<string> | Specify metadata to filter by in the format of `metadata_{metadata-key}={metadata-value}` such as `metadata_opportunity_id=2181432`. The `metadata_` prefix is always required. (optional)
751+
metadata: ["metadata_opportunity_id=2181432","metadata_custom_key=custom_value"],
752752
// string | Return results where the `date_modified` field (iso-8601) is greater than or equal to this value. (optional)
753753
modifiedFrom: "2021-10-27T15:22:23.132757Z",
754754
// string | Return results where the `date_modified` field (iso-8601) is less than this value. (optional)
@@ -790,7 +790,7 @@ Name | Type | Description | Notes
790790
**folderUuid** | [**string**] | The UUID of the folder where the documents are stored. | (optional) defaults to undefined
791791
**formId** | [**string**] | Specify the form used for documents creation. This parameter can&#39;t be used with template_id. | (optional) defaults to undefined
792792
**membershipId** | [**string**] | Returns results where &#39;membership_id&#39; is present in document as owner (should be member uuid) | (optional) defaults to undefined
793-
**metadata** | [**string**] | Specify metadata to filter by in the format of &#x60;metadata_{metadata-key}&#x3D;{metadata-value}&#x60; such as &#x60;metadata_opportunity_id&#x3D;2181432&#x60;. The &#x60;metadata_&#x60; prefix is always required. | (optional) defaults to undefined
793+
**metadata** | **Array&lt;string&gt;** | Specify metadata to filter by in the format of &#x60;metadata_{metadata-key}&#x3D;{metadata-value}&#x60; such as &#x60;metadata_opportunity_id&#x3D;2181432&#x60;. The &#x60;metadata_&#x60; prefix is always required. | (optional) defaults to undefined
794794
**modifiedFrom** | [**string**] | Return results where the &#x60;date_modified&#x60; field (iso-8601) is greater than or equal to this value. | (optional) defaults to undefined
795795
**modifiedTo** | [**string**] | Return results where the &#x60;date_modified&#x60; field (iso-8601) is less than this value. | (optional) defaults to undefined
796796
**orderBy** | **DocumentOrderingFieldsEnum** | Specify the order of documents to return. Use &#x60;value&#x60; (for example, &#x60;date_created&#x60;) for ASC and &#x60;-value&#x60; (for example, &#x60;-date_created&#x60;) for DESC. | (optional) defaults to undefined

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pandadoc-node-client",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"description": "The Official PandaDoc Node client SDK",
55
"author": "PandaDoc",
66
"keywords": [

src/apis/DocumentsApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ export class DocumentsApiRequestFactory extends BaseAPIRequestFactory {
547547
* @param tag Search tag. Filter by document tag.
548548
* @param templateId Specify the template used for documents creation. Parameter can&#39;t be used with form_id.
549549
*/
550-
public async listDocuments(completedFrom?: string, completedTo?: string, contactId?: string, count?: number, createdFrom?: string, createdTo?: string, deleted?: boolean, id?: string, folderUuid?: string, formId?: string, membershipId?: string, metadata?: string, modifiedFrom?: string, modifiedTo?: string, orderBy?: DocumentOrderingFieldsEnum, page?: number, q?: string, status?: DocumentStatusRequestEnum, statusNe?: DocumentStatusRequestEnum, tag?: string, templateId?: string, _options?: Configuration): Promise<RequestContext> {
550+
public async listDocuments(completedFrom?: string, completedTo?: string, contactId?: string, count?: number, createdFrom?: string, createdTo?: string, deleted?: boolean, id?: string, folderUuid?: string, formId?: string, membershipId?: string, metadata?: Array<string>, modifiedFrom?: string, modifiedTo?: string, orderBy?: DocumentOrderingFieldsEnum, page?: number, q?: string, status?: DocumentStatusRequestEnum, statusNe?: DocumentStatusRequestEnum, tag?: string, templateId?: string, _options?: Configuration): Promise<RequestContext> {
551551
let _config = _options || this.configuration;
552552

553553

@@ -635,7 +635,7 @@ export class DocumentsApiRequestFactory extends BaseAPIRequestFactory {
635635

636636
// Query Params
637637
if (metadata !== undefined) {
638-
requestContext.setQueryParam("metadata", ObjectSerializer.serialize(metadata, "string", ""));
638+
requestContext.setQueryParam("metadata", ObjectSerializer.serialize(metadata, "Array<string>", ""));
639639
}
640640

641641
// Query Params

src/http/http.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
5050
*/
5151
export class RequestContext {
5252
private headers: { [key: string]: string } = {
53-
"User-Agent": "pandadoc_node_client/5.0.0",
53+
"User-Agent": "pandadoc_node_client/5.0.1",
5454
};
5555
private body: RequestBody = undefined;
5656
private url: URLParse;
@@ -66,12 +66,48 @@ export class RequestContext {
6666
this.url = new URLParse(url, true);
6767
}
6868

69+
public queryStringify(query: any, prefix: string = '') {
70+
function encodeInput(input: any) {
71+
try {
72+
return encodeURIComponent(input);
73+
} catch (e) {
74+
return null;
75+
}
76+
}
77+
78+
const pairs: any[] = [];
79+
80+
if ('string' !== typeof prefix) prefix = '?';
81+
82+
Object.keys(query).forEach((key) => {
83+
let value = query[key];
84+
85+
//
86+
// Edge cases where we actually want to encode the value to an empty
87+
// string instead of the stringified value.
88+
//
89+
if (!value && (value === null || value === undefined || isNaN(value))) {
90+
value = '';
91+
}
92+
93+
if (Array.isArray(value)) {
94+
value.forEach(subValue => {
95+
pairs.push(encodeInput(key) + '=' + encodeInput(subValue));
96+
});
97+
return;
98+
}
99+
pairs.push(encodeInput(key) + '=' + encodeInput(value));
100+
});
101+
102+
return pairs.length ? prefix + pairs.join('&') : '';
103+
}
104+
69105
/*
70106
* Returns the url set in the constructor including the query string
71107
*
72108
*/
73109
public getUrl(): string {
74-
return this.url.toString();
110+
return this.url.toString(this.queryStringify);
75111
}
76112

77113
/**

src/types/ObjectParamAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,10 @@ export interface DocumentsApiListDocumentsRequest {
703703
membershipId?: string
704704
/**
705705
* Specify metadata to filter by in the format of &#x60;metadata_{metadata-key}&#x3D;{metadata-value}&#x60; such as &#x60;metadata_opportunity_id&#x3D;2181432&#x60;. The &#x60;metadata_&#x60; prefix is always required.
706-
* @type string
706+
* @type Array&lt;string&gt;
707707
* @memberof DocumentsApilistDocuments
708708
*/
709-
metadata?: string
709+
metadata?: Array<string>
710710
/**
711711
* Return results where the &#x60;date_modified&#x60; field (iso-8601) is greater than or equal to this value.
712712
* @type string

src/types/ObservableAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ export class ObservableDocumentsApi {
767767
* @param tag Search tag. Filter by document tag.
768768
* @param templateId Specify the template used for documents creation. Parameter can&#39;t be used with form_id.
769769
*/
770-
public listDocuments(completedFrom?: string, completedTo?: string, contactId?: string, count?: number, createdFrom?: string, createdTo?: string, deleted?: boolean, id?: string, folderUuid?: string, formId?: string, membershipId?: string, metadata?: string, modifiedFrom?: string, modifiedTo?: string, orderBy?: DocumentOrderingFieldsEnum, page?: number, q?: string, status?: DocumentStatusRequestEnum, statusNe?: DocumentStatusRequestEnum, tag?: string, templateId?: string, _options?: Configuration): Observable<DocumentListResponse> {
770+
public listDocuments(completedFrom?: string, completedTo?: string, contactId?: string, count?: number, createdFrom?: string, createdTo?: string, deleted?: boolean, id?: string, folderUuid?: string, formId?: string, membershipId?: string, metadata?: Array<string>, modifiedFrom?: string, modifiedTo?: string, orderBy?: DocumentOrderingFieldsEnum, page?: number, q?: string, status?: DocumentStatusRequestEnum, statusNe?: DocumentStatusRequestEnum, tag?: string, templateId?: string, _options?: Configuration): Observable<DocumentListResponse> {
771771
const requestContextPromise = this.requestFactory.listDocuments(completedFrom, completedTo, contactId, count, createdFrom, createdTo, deleted, id, folderUuid, formId, membershipId, metadata, modifiedFrom, modifiedTo, orderBy, page, q, status, statusNe, tag, templateId, _options);
772772

773773
// build promise chain

src/types/PromiseAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class PromiseDocumentsApi {
445445
* @param tag Search tag. Filter by document tag.
446446
* @param templateId Specify the template used for documents creation. Parameter can&#39;t be used with form_id.
447447
*/
448-
public listDocuments(completedFrom?: string, completedTo?: string, contactId?: string, count?: number, createdFrom?: string, createdTo?: string, deleted?: boolean, id?: string, folderUuid?: string, formId?: string, membershipId?: string, metadata?: string, modifiedFrom?: string, modifiedTo?: string, orderBy?: DocumentOrderingFieldsEnum, page?: number, q?: string, status?: DocumentStatusRequestEnum, statusNe?: DocumentStatusRequestEnum, tag?: string, templateId?: string, _options?: Configuration): Promise<DocumentListResponse> {
448+
public listDocuments(completedFrom?: string, completedTo?: string, contactId?: string, count?: number, createdFrom?: string, createdTo?: string, deleted?: boolean, id?: string, folderUuid?: string, formId?: string, membershipId?: string, metadata?: Array<string>, modifiedFrom?: string, modifiedTo?: string, orderBy?: DocumentOrderingFieldsEnum, page?: number, q?: string, status?: DocumentStatusRequestEnum, statusNe?: DocumentStatusRequestEnum, tag?: string, templateId?: string, _options?: Configuration): Promise<DocumentListResponse> {
449449
const result = this.api.listDocuments(completedFrom, completedTo, contactId, count, createdFrom, createdTo, deleted, id, folderUuid, formId, membershipId, metadata, modifiedFrom, modifiedTo, orderBy, page, q, status, statusNe, tag, templateId, _options);
450450
return result.toPromise();
451451
}

0 commit comments

Comments
 (0)