@coveo/push-api-client 2.0.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/definitions/errors/privilegeError.d.ts +6 -0
- package/dist/definitions/help/axiosUtils.d.ts +2 -0
- package/dist/definitions/help/fileContainer.d.ts +9 -0
- package/dist/definitions/help/fileContainer.spec.d.ts +1 -0
- package/dist/definitions/help/urlUtils.d.ts +27 -0
- package/dist/definitions/index.d.ts +1 -0
- package/dist/definitions/interfaces.d.ts +4 -1
- package/dist/definitions/source/batchUploadDocumentsFromFile.d.ts +11 -0
- package/dist/definitions/source/catalog.d.ts +69 -0
- package/dist/definitions/source/catalog.spec.d.ts +1 -0
- package/dist/definitions/source/catalog.stream.spec.d.ts +1 -0
- package/dist/definitions/source/documentUploader.d.ts +5 -0
- package/dist/definitions/source/push.d.ts +5 -12
- package/dist/definitions/uploadStrategy/fileContainerStrategy.d.ts +23 -0
- package/dist/definitions/uploadStrategy/index.d.ts +3 -0
- package/dist/definitions/uploadStrategy/strategy.d.ts +16 -0
- package/dist/definitions/uploadStrategy/streamChunkStrategy.d.ts +27 -0
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.d.ts +3 -0
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.spec.d.ts +1 -0
- package/dist/definitions/validation/preconditions/platformPrivilege.d.ts +7 -0
- package/dist/docs/assets/search.js +1 -1
- package/dist/docs/classes/AnySecurityIdentityBuilder.html +2 -2
- package/dist/docs/classes/CatalogSource.html +40 -0
- package/dist/docs/classes/DocumentBuilder.html +16 -16
- package/dist/docs/classes/FieldAnalyser.html +3 -3
- package/dist/docs/classes/GroupSecurityIdentityBuilder.html +2 -2
- package/dist/docs/classes/PushSource.html +14 -14
- package/dist/docs/classes/UserSecurityIdentityBuilder.html +2 -2
- package/dist/docs/classes/VirtualGroupSecurityIdentityBuilder.html +2 -2
- package/dist/docs/enums/PlatformEnvironment.html +1 -1
- package/dist/docs/index.html +2 -2
- package/dist/docs/interfaces/BatchUpdateDocuments.html +1 -1
- package/dist/docs/interfaces/Document.html +13 -13
- package/dist/docs/interfaces/SecurityIdentity.html +3 -3
- package/dist/docs/interfaces/SecurityIdentityBuilder.html +1 -1
- package/dist/docs/interfaces/UploadBatchCallbackData.html +1 -1
- package/dist/docs/modules.html +3 -3
- package/dist/errors/privilegeError.js +13 -0
- package/dist/errors/privilegeError.js.map +1 -0
- package/dist/fieldAnalyser/fieldAnalyser.js +3 -0
- package/dist/fieldAnalyser/fieldAnalyser.js.map +1 -1
- package/dist/fieldAnalyser/fieldAnalyser.spec.js +13 -0
- package/dist/fieldAnalyser/fieldAnalyser.spec.js.map +1 -1
- package/dist/fieldAnalyser/fieldUtils.js +4 -0
- package/dist/fieldAnalyser/fieldUtils.js.map +1 -1
- package/dist/fieldAnalyser/fieldsUtils.spec.js +3 -0
- package/dist/fieldAnalyser/fieldsUtils.spec.js.map +1 -1
- package/dist/help/axiosUtils.js +12 -0
- package/dist/help/axiosUtils.js.map +1 -0
- package/dist/help/fileContainer.js +20 -0
- package/dist/help/fileContainer.js.map +1 -0
- package/dist/help/fileContainer.spec.js +34 -0
- package/dist/help/fileContainer.spec.js.map +1 -0
- package/dist/help/urlUtils.js +43 -0
- package/dist/help/urlUtils.js.map +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/source/batchUploadDocumentsFromFile.js +50 -0
- package/dist/source/batchUploadDocumentsFromFile.js.map +1 -0
- package/dist/source/catalog.js +115 -0
- package/dist/source/catalog.js.map +1 -0
- package/dist/source/catalog.spec.js +239 -0
- package/dist/source/catalog.spec.js.map +1 -0
- package/dist/source/catalog.stream.spec.js +189 -0
- package/dist/source/catalog.stream.spec.js.map +1 -0
- package/dist/source/documentUploader.js +23 -0
- package/dist/source/documentUploader.js.map +1 -0
- package/dist/source/push.js +19 -57
- package/dist/source/push.js.map +1 -1
- package/dist/source/push.spec.js +3 -0
- package/dist/source/push.spec.js.map +1 -1
- package/dist/uploadStrategy/fileContainerStrategy.js +34 -0
- package/dist/uploadStrategy/fileContainerStrategy.js.map +1 -0
- package/dist/uploadStrategy/index.js +7 -0
- package/dist/uploadStrategy/index.js.map +1 -0
- package/dist/uploadStrategy/strategy.js +3 -0
- package/dist/uploadStrategy/strategy.js.map +1 -0
- package/dist/uploadStrategy/streamChunkStrategy.js +51 -0
- package/dist/uploadStrategy/streamChunkStrategy.js.map +1 -0
- package/dist/validation/preconditions/apiKeyPrivilege.js +21 -0
- package/dist/validation/preconditions/apiKeyPrivilege.js.map +1 -0
- package/dist/validation/preconditions/apiKeyPrivilege.spec.js +70 -0
- package/dist/validation/preconditions/apiKeyPrivilege.spec.js.map +1 -0
- package/dist/validation/preconditions/platformPrivilege.js +35 -0
- package/dist/validation/preconditions/platformPrivilege.js.map +1 -0
- package/package.json +4 -4
- package/dist/definitions/source/batchUpdateDocumentsFromFile.d.ts +0 -10
- package/dist/source/batchUpdateDocumentsFromFile.js +0 -42
- package/dist/source/batchUpdateDocumentsFromFile.js.map +0 -1
package/README.md
CHANGED
@@ -9,10 +9,10 @@ Coveo Push API client
|
|
9
9
|
## Usage
|
10
10
|
|
11
11
|
```js
|
12
|
-
import {
|
12
|
+
import {PushSource, DocumentBuilder} from '@coveo/push-api-client';
|
13
13
|
|
14
14
|
async function main() {
|
15
|
-
const source = new
|
15
|
+
const source = new PushSource('my_api_key', 'my_coveo_organization_id');
|
16
16
|
|
17
17
|
const myDocument = new DocumentBuilder(
|
18
18
|
'https://my.document.uri',
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
2
|
+
import { BatchUpdateDocuments } from '../interfaces';
|
3
|
+
export interface FileContainerResponse {
|
4
|
+
uploadUri: string;
|
5
|
+
fileId: string;
|
6
|
+
requiredHeaders: Record<string, string>;
|
7
|
+
}
|
8
|
+
export declare const uploadContentToFileContainer: (fileContainer: FileContainerResponse, batch: BatchUpdateDocuments) => Promise<import("axios").AxiosResponse<any, any>>;
|
9
|
+
export declare const getFileContainerAxiosConfig: (fileContainer: FileContainerResponse) => AxiosRequestConfig;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { PlatformUrlOptions } from '..';
|
3
|
+
export interface URLBuilder {
|
4
|
+
baseAPIURLForUpdate: URL;
|
5
|
+
fileContainerUrl: URL;
|
6
|
+
}
|
7
|
+
declare abstract class BaseUrlBuilder {
|
8
|
+
private organizationId;
|
9
|
+
private options;
|
10
|
+
protected constructor(organizationId: string, options: Required<PlatformUrlOptions>);
|
11
|
+
protected get platformURL(): string;
|
12
|
+
get fileContainerUrl(): import("url").URL;
|
13
|
+
abstract get baseAPIURLForUpdate(): URL;
|
14
|
+
}
|
15
|
+
export declare class PushUrlBuilder extends BaseUrlBuilder implements URLBuilder {
|
16
|
+
private sourceId;
|
17
|
+
constructor(sourceId: string, organizationId: string, options: Required<PlatformUrlOptions>);
|
18
|
+
get baseURL(): import("url").URL;
|
19
|
+
get baseAPIURLForUpdate(): import("url").URL;
|
20
|
+
}
|
21
|
+
export declare class StreamUrlBuilder extends BaseUrlBuilder implements URLBuilder {
|
22
|
+
private sourceId;
|
23
|
+
constructor(sourceId: string, organizationId: string, options: Required<PlatformUrlOptions>);
|
24
|
+
get baseStreamURL(): import("url").URL;
|
25
|
+
get baseAPIURLForUpdate(): import("url").URL;
|
26
|
+
}
|
27
|
+
export {};
|
@@ -1,6 +1,7 @@
|
|
1
1
|
export * from './document';
|
2
2
|
export { Source } from './source/source';
|
3
3
|
export { PushSource } from './source/push';
|
4
|
+
export { CatalogSource } from './source/catalog';
|
4
5
|
export { SuccessfulUploadCallback, FailedUploadCallback, } from './help/fileConsumer';
|
5
6
|
export { UploadBatchCallbackData, BatchUpdateDocuments, BatchUpdateDocumentsFromFiles, } from './interfaces';
|
6
7
|
export { FieldAnalyser } from './fieldAnalyser/fieldAnalyser';
|
@@ -20,7 +20,10 @@ export interface UploadBatchCallbackData {
|
|
20
20
|
}
|
21
21
|
export interface BatchUpdateDocumentsOptions {
|
22
22
|
/**
|
23
|
-
* Whether to create fields required in the index based on the document batch metadata.
|
23
|
+
* Whether to create the missing fields required in the index based on the document batch metadata.
|
24
|
+
*
|
25
|
+
* Make sure your API key is granted the privilege to EDIT fields before using this option.
|
26
|
+
* See https://docs.coveo.com/en/1707#fields-domain
|
24
27
|
*/
|
25
28
|
createFields?: boolean;
|
26
29
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import PlatformClient from '@coveord/platform-client';
|
2
|
+
import { BatchUpdateDocumentsFromFiles, FailedUploadCallback, SuccessfulUploadCallback } from '../index';
|
3
|
+
import type { UploadStrategy } from '../uploadStrategy';
|
4
|
+
export declare class BatchUploadDocumentsFromFilesReturn {
|
5
|
+
private internalPromise;
|
6
|
+
private consumer;
|
7
|
+
constructor(platformClient: PlatformClient, strategy: UploadStrategy, filesOrDirectories: string[], options?: BatchUpdateDocumentsFromFiles);
|
8
|
+
onBatchUpload(cb: SuccessfulUploadCallback): this;
|
9
|
+
onBatchError(cb: FailedUploadCallback): this;
|
10
|
+
batch(): Promise<void>;
|
11
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { SourceVisibility } from '@coveord/platform-client';
|
2
|
+
import { PlatformUrlOptions } from '../environment';
|
3
|
+
import { SecurityIdentity } from './securityIdenty';
|
4
|
+
import { BatchUpdateDocuments, BatchUpdateDocumentsFromFiles, BatchUpdateDocumentsOptions } from '../interfaces';
|
5
|
+
import { BatchUploadDocumentsFromFilesReturn } from './batchUploadDocumentsFromFile';
|
6
|
+
/**
|
7
|
+
* Manage a catalog source.
|
8
|
+
*
|
9
|
+
* Allows you to create a new catalog source, manage security identities and documents in a Coveo organization.
|
10
|
+
*/
|
11
|
+
export declare class CatalogSource {
|
12
|
+
private apikey;
|
13
|
+
private organizationid;
|
14
|
+
private platformClient;
|
15
|
+
private options;
|
16
|
+
private static defaultOptions;
|
17
|
+
/**
|
18
|
+
* Creates an instance of CatalogSource.
|
19
|
+
* @param {string} apikey An apiKey capable of pushing documents and managing sources in a Coveo organization. See [Manage API Keys](https://docs.coveo.com/en/1718).
|
20
|
+
* @param {string} organizationid The Coveo Organization identifier.
|
21
|
+
* @param {PlatformUrlOptions} [opts=CatalogSource.defaultOptions]
|
22
|
+
*/
|
23
|
+
constructor(apikey: string, organizationid: string, opts?: PlatformUrlOptions);
|
24
|
+
/**
|
25
|
+
* Create a new catalog source
|
26
|
+
* @param name The name of the source to create.
|
27
|
+
* @param sourceVisibility The security option that should be applied to the content of the source. See [Content Security](https://docs.coveo.com/en/1779).
|
28
|
+
* @returns
|
29
|
+
*/
|
30
|
+
create(name: string, sourceVisibility: SourceVisibility): Promise<{
|
31
|
+
id: string;
|
32
|
+
}>;
|
33
|
+
get identity(): SecurityIdentity;
|
34
|
+
/**
|
35
|
+
* Manage batches of items in a catalog source.
|
36
|
+
* See [Full Document Update](https://docs.coveo.com/en/l62e0540)
|
37
|
+
* @param sourceId
|
38
|
+
* @param batch
|
39
|
+
* @param {BatchUpdateDocumentsOptions} [{createFields: createFields = true}={}]
|
40
|
+
* @returns
|
41
|
+
*/
|
42
|
+
batchUpdateDocuments(sourceId: string, batch: BatchUpdateDocuments, { createFields: createFields }?: BatchUpdateDocumentsOptions): Promise<import("axios").AxiosResponse<any, any>>;
|
43
|
+
/**
|
44
|
+
* Send your catalog data to your catalog source.
|
45
|
+
* See [How to Stream Your Catalog Data to Your Source](https://docs.coveo.com/en/lb4a0344)
|
46
|
+
* @param {string} sourceId
|
47
|
+
* @param {BatchUpdateDocuments} batch
|
48
|
+
* @param {BatchUpdateDocumentsOptions} [{createFields: createFields = true}={}]
|
49
|
+
*/
|
50
|
+
batchStreamDocuments(sourceId: string, batch: BatchUpdateDocuments, { createFields: createFields }?: BatchUpdateDocumentsOptions): Promise<void>;
|
51
|
+
/**
|
52
|
+
* Manage batches of items in a catalog source from a list of JSON files. See [Full Document Update Source](https://docs.coveo.com/en/l62e0540)
|
53
|
+
* @param {string} sourceId The unique identifier of the target Push source
|
54
|
+
* @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
|
55
|
+
* @param {BatchUpdateDocumentsFromFiles} options
|
56
|
+
*/
|
57
|
+
batchUpdateDocumentsFromFiles(sourceId: string, filesOrDirectories: string[], options?: BatchUpdateDocumentsFromFiles): BatchUploadDocumentsFromFilesReturn;
|
58
|
+
/**
|
59
|
+
* Send your catalog data to your catalog source from a list of JSON files.
|
60
|
+
* See [How to Stream Your Catalog Data to Your Source](https://docs.coveo.com/en/lb4a0344)
|
61
|
+
* @param {string} sourceId The unique identifier of the target Push source
|
62
|
+
* @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
|
63
|
+
* @param {BatchUpdateDocumentsFromFiles} [options]
|
64
|
+
*/
|
65
|
+
batchStreamDocumentsFromFiles(sourceId: string, filesOrDirectories: string[], options?: BatchUpdateDocumentsFromFiles): BatchUploadDocumentsFromFilesReturn;
|
66
|
+
private urlBuilder;
|
67
|
+
private fileContainerStrategy;
|
68
|
+
private streamChunkStrategy;
|
69
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import PlatformClient from '@coveord/platform-client';
|
2
|
+
import { AxiosResponse } from 'axios';
|
3
|
+
import { BatchUpdateDocuments } from '../interfaces';
|
4
|
+
import { UploadStrategy } from '../uploadStrategy';
|
5
|
+
export declare function uploadBatch(platformClient: PlatformClient, strategy: UploadStrategy, batch: BatchUpdateDocuments, createFields?: boolean): Promise<AxiosResponse>;
|
@@ -4,8 +4,8 @@ import { DocumentBuilder } from '../documentBuilder';
|
|
4
4
|
import { PlatformUrlOptions } from '../environment';
|
5
5
|
import { FieldAnalyser } from '../fieldAnalyser/fieldAnalyser';
|
6
6
|
import { SecurityIdentity } from './securityIdenty';
|
7
|
-
import { BatchUpdateDocuments,
|
8
|
-
import {
|
7
|
+
import { BatchUpdateDocuments, BatchUpdateDocumentsFromFiles, BatchUpdateDocumentsOptions } from '../interfaces';
|
8
|
+
import { BatchUploadDocumentsFromFilesReturn } from './batchUploadDocumentsFromFile';
|
9
9
|
export declare type SourceStatus = 'REBUILD' | 'REFRESH' | 'INCREMENTAL' | 'IDLE';
|
10
10
|
/**
|
11
11
|
* Manage a push source.
|
@@ -87,7 +87,7 @@ export declare class PushSource {
|
|
87
87
|
* @param {UploadBatchCallback} callback Callback executed when a batch of documents is either successfully uploaded or when an error occurs during the upload
|
88
88
|
* @param {BatchUpdateDocumentsFromFiles} options
|
89
89
|
*/
|
90
|
-
batchUpdateDocumentsFromFiles(sourceID: string, filesOrDirectories: string[], options?: BatchUpdateDocumentsFromFiles):
|
90
|
+
batchUpdateDocumentsFromFiles(sourceID: string, filesOrDirectories: string[], options?: BatchUpdateDocumentsFromFiles): BatchUploadDocumentsFromFilesReturn;
|
91
91
|
/**
|
92
92
|
* Deletes a specific item from a Push source. Optionally, the child items of that item can also be deleted. See [Deleting an Item in a Push Source](https://docs.coveo.com/en/171).
|
93
93
|
* @param sourceID
|
@@ -110,15 +110,8 @@ export declare class PushSource {
|
|
110
110
|
* @returns
|
111
111
|
*/
|
112
112
|
setSourceStatus(sourceID: string, status: SourceStatus): Promise<import("axios").AxiosResponse<any, any>>;
|
113
|
-
uploadBatch(sourceID: string, batch: BatchUpdateDocuments): Promise<import("axios").AxiosResponse<any, any>>;
|
114
|
-
private get baseAPIURL();
|
115
|
-
private getBaseAPIURLForDocuments;
|
116
113
|
private get documentsAxiosConfig();
|
117
114
|
createFields(analyser: FieldAnalyser): Promise<void>;
|
118
|
-
private
|
119
|
-
private
|
120
|
-
private get authorizationHeader();
|
121
|
-
private createFileContainer;
|
122
|
-
private uploadContentToFileContainer;
|
123
|
-
private pushFileContainerContent;
|
115
|
+
private urlBuilder;
|
116
|
+
private fileContainerStrategy;
|
124
117
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
2
|
+
import { BatchUpdateDocuments } from '../interfaces';
|
3
|
+
import { UploadStrategy } from './strategy';
|
4
|
+
import { URLBuilder } from '../help/urlUtils';
|
5
|
+
export interface FileContainerResponse {
|
6
|
+
uploadUri: string;
|
7
|
+
fileId: string;
|
8
|
+
requiredHeaders: Record<string, string>;
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* Upload documents using the [File container](https://docs.coveo.com/en/43/index-content/creating-a-file-container)
|
12
|
+
*
|
13
|
+
* @class FileContainerStrategy
|
14
|
+
* @implements {UploadStrategy}
|
15
|
+
*/
|
16
|
+
export declare class FileContainerStrategy implements UploadStrategy {
|
17
|
+
private urlBuilder;
|
18
|
+
private documentsAxiosConfig;
|
19
|
+
constructor(urlBuilder: URLBuilder, documentsAxiosConfig: AxiosRequestConfig);
|
20
|
+
upload(batch: BatchUpdateDocuments): Promise<import("axios").AxiosResponse<any, any>>;
|
21
|
+
private createFileContainer;
|
22
|
+
private pushFileContainerContent;
|
23
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
2
|
+
import type { BatchUpdateDocuments } from '../interfaces';
|
3
|
+
export interface UploadStrategy {
|
4
|
+
/**
|
5
|
+
* Upload a batch of documents
|
6
|
+
*
|
7
|
+
* @param {BatchUpdateDocuments} batch
|
8
|
+
*/
|
9
|
+
upload: (batch: BatchUpdateDocuments) => Promise<AxiosResponse>;
|
10
|
+
/**
|
11
|
+
* Async operation to run once the batch upload is complete
|
12
|
+
*
|
13
|
+
* @memberof UploadStrategy
|
14
|
+
*/
|
15
|
+
postUpload?: () => Promise<void>;
|
16
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
2
|
+
import { BatchUpdateDocuments } from '../interfaces';
|
3
|
+
import { UploadStrategy } from './strategy';
|
4
|
+
import { StreamUrlBuilder } from '../help/urlUtils';
|
5
|
+
export interface StreamResponse {
|
6
|
+
uploadUri: string;
|
7
|
+
fileId: string;
|
8
|
+
requiredHeaders: Record<string, string>;
|
9
|
+
streamId: string;
|
10
|
+
}
|
11
|
+
/**
|
12
|
+
* Upload documents using the [Stream API](https://docs.coveo.com/en/lb4a0344/coveo-for-commerce/how-to-stream-your-catalog-data-to-your-source)
|
13
|
+
*
|
14
|
+
* @class StreamChunkStrategy
|
15
|
+
* @implements {UploadStrategy}
|
16
|
+
*/
|
17
|
+
export declare class StreamChunkStrategy implements UploadStrategy {
|
18
|
+
private urlBuilder;
|
19
|
+
private documentsAxiosConfig;
|
20
|
+
private _openedStream;
|
21
|
+
constructor(urlBuilder: StreamUrlBuilder, documentsAxiosConfig: AxiosRequestConfig);
|
22
|
+
upload(batch: BatchUpdateDocuments): Promise<import("axios").AxiosResponse<any, any>>;
|
23
|
+
postUpload(): Promise<any>;
|
24
|
+
openStreamIfNotAlreadyOpen(): Promise<StreamResponse>;
|
25
|
+
closeOpenedStream(): Promise<any>;
|
26
|
+
private requestStreamChunk;
|
27
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { PrivilegeModel } from '@coveord/platform-client';
|
2
|
+
export interface PlatformPrivilege {
|
3
|
+
models: PrivilegeModel[];
|
4
|
+
unsatisfiedConditionMessage: string;
|
5
|
+
}
|
6
|
+
export declare const readFieldsPrivilege: PlatformPrivilege;
|
7
|
+
export declare const writeFieldsPrivilege: PlatformPrivilege;
|