@vertexvis/api-client-node 0.15.4 → 0.16.0

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.
@@ -10,7 +10,7 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  import { Configuration } from './configuration';
13
- import { AxiosInstance } from 'axios';
13
+ import { AxiosInstance, AxiosRequestConfig } from 'axios';
14
14
  export declare const BASE_PATH: string;
15
15
  /**
16
16
  *
@@ -29,7 +29,7 @@ export declare const COLLECTION_FORMATS: {
29
29
  */
30
30
  export interface RequestArgs {
31
31
  url: string;
32
- options: any;
32
+ options: AxiosRequestConfig;
33
33
  }
34
34
  /**
35
35
  *
@@ -1,17 +1,12 @@
1
1
  /// <reference types="node" />
2
- import { RequestOptions } from 'https';
3
2
  import { BaseReq, DeleteReq } from '../../client/index';
4
3
  import { CreateFileRequest, FileMetadataData } from '../../index';
5
4
  /** Upload file arguments. */
6
5
  export interface UploadFileReq extends BaseReq {
7
6
  /** A {@link CreateFileRequest}. */
8
7
  readonly createFileReq: CreateFileRequest;
9
- /** File data.
10
- * @deprecated Use {@link filePath} instead.
11
- */
12
- readonly fileData?: unknown;
13
- readonly filePath?: string;
14
- readonly bypassAxiosEXPERIMENTAL?: boolean;
8
+ /** File data. */
9
+ readonly fileData: Buffer;
15
10
  }
16
11
  /**
17
12
  * Delete all files.
@@ -30,9 +25,4 @@ export declare function uploadFileIfNotExists({ client, createFileReq, onMsg, ve
30
25
  *
31
26
  * @param args - The {@link UploadFileReq}.
32
27
  */
33
- export declare function uploadFile({ client, createFileReq, fileData, filePath, onMsg, verbose, bypassAxiosEXPERIMENTAL, }: UploadFileReq): Promise<FileMetadataData>;
34
- interface UploadRes {
35
- readonly status: number;
36
- }
37
- export declare const upload: (body: Buffer, opts: RequestOptions) => Promise<UploadRes>;
38
- export {};
28
+ export declare function uploadFile({ client, createFileReq, fileData, onMsg, verbose, }: UploadFileReq): Promise<FileMetadataData>;
@@ -18,12 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- import fs from 'fs';
22
- import { request } from 'https';
23
- import { promisify } from 'util';
24
- import { delay, encodeIfNotEncoded, getBySuppliedId, getPage, } from '../../client/index';
25
- const readFile = promisify(fs.readFile);
26
- const stat = promisify(fs.stat);
21
+ import { encodeIfNotEncoded, getBySuppliedId, getPage, } from '../../client/index';
27
22
  /**
28
23
  * Delete all files.
29
24
  *
@@ -85,8 +80,7 @@ export function uploadFileIfNotExists(_a) {
85
80
  *
86
81
  * @param args - The {@link UploadFileReq}.
87
82
  */
88
- export function uploadFile({ client, createFileReq, fileData, filePath, onMsg = console.log, verbose, bypassAxiosEXPERIMENTAL = false, }) {
89
- var _a;
83
+ export function uploadFile({ client, createFileReq, fileData, onMsg = console.log, verbose, }) {
90
84
  return __awaiter(this, void 0, void 0, function* () {
91
85
  const fileName = createFileReq.data.attributes.name;
92
86
  const createRes = yield client.files.createFile({
@@ -95,50 +89,20 @@ export function uploadFile({ client, createFileReq, fileData, filePath, onMsg =
95
89
  const fileId = createRes.data.data.id;
96
90
  if (verbose)
97
91
  onMsg(`Created file '${fileName}', ${fileId}`);
98
- const [body, { size }] = filePath
99
- ? yield Promise.all([readFile(filePath), stat(filePath)])
100
- : [fileData, { size: -1 }];
101
- const uploadRes = yield (bypassAxiosEXPERIMENTAL
102
- ? upload(body, {
103
- headers: {
104
- Authorization: `Bearer ${client.token.access_token}`,
105
- 'Content-Type': 'application/octet-stream',
106
- 'Content-Length': size,
107
- },
108
- hostname: new URL((_a = client.config.basePath) !== null && _a !== void 0 ? _a : '').hostname,
109
- method: 'POST',
110
- port: 443,
111
- path: `/files/${fileId}`,
112
- })
113
- : client.files.uploadFile({ id: fileId, body }, { headers: size >= 0 ? { 'Content-Length': size } : undefined }));
92
+ const uploadRes = yield client.files.uploadFile({
93
+ id: fileId,
94
+ body: fileData,
95
+ });
114
96
  if (uploadRes.status !== 204) {
115
97
  throw new Error(`Uploading file ${fileId} failed with status code ${uploadRes.status}`);
116
98
  }
117
- if (verbose)
118
- onMsg(`Uploaded file ${fileId}`);
119
99
  const getRes = (yield client.files.getFile({ id: fileId })).data.data;
120
- if (size >= 0 && getRes.attributes.size !== size) {
121
- onMsg(`File ${fileId} size mismatch, expected ${size} got ${getRes.attributes.size}`);
122
- }
123
100
  const status = getRes.attributes.status;
124
101
  if (status === 'error') {
125
102
  throw new Error(`Uploading file ${fileId} failed with status ${status}`);
126
103
  }
127
- // Sanity check
128
- if (status !== 'complete') {
129
- if (verbose)
130
- onMsg(`File ${fileId} in status ${status}, waiting...`);
131
- yield delay(1000);
132
- }
104
+ if (verbose)
105
+ onMsg(`Uploaded file ${fileId}, status ${status}`);
133
106
  return getRes;
134
107
  });
135
108
  }
136
- export const upload = (body, opts) => new Promise((resolve, reject) => {
137
- const req = request(opts, (r) => {
138
- var _a;
139
- r.resume();
140
- resolve({ status: (_a = r.statusCode) !== null && _a !== void 0 ? _a : -1 });
141
- });
142
- req.on('error', (error) => (req.aborted ? null : reject(error)));
143
- req.end(body);
144
- });
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { AxiosResponse } from 'axios';
2
3
  import { CreateFileRequest, CreateGeometrySetRequest, CreatePartRequest, Failure, PartData, PartRevisionData, QueuedJob } from '../../index';
3
4
  import { BaseReq, DeleteReq, Polling, RenderImageReq } from '../index';
@@ -7,11 +8,8 @@ export interface CreatePartFromFileReq extends BaseReq {
7
8
  readonly createFileReq: CreateFileRequest;
8
9
  /** Function returning a {@link CreatePartRequest}. */
9
10
  readonly createPartReq: (fileId: string) => CreatePartRequest;
10
- /** File data.
11
- * @deprecated Use {@link filePath} instead.
12
- */
13
- readonly fileData?: unknown;
14
- readonly filePath?: string;
11
+ /** File data. */
12
+ readonly fileData: Buffer;
15
13
  /** {@link Polling} */
16
14
  readonly polling?: Polling;
17
15
  /** Whether or not to return queued translation. */
@@ -89,7 +89,7 @@ export function isPollError(r) {
89
89
  }
90
90
  export function isBatch(obj) {
91
91
  const b = obj;
92
- return defined(b) && defined(b.vertexvis_batchresults);
92
+ return defined(b) && defined(b['vertexvis/batch:results']);
93
93
  }
94
94
  export function throwOnError(r) {
95
95
  throw new Error(isQueuedJobError(r.res) || isFailure(r.res)
@@ -52,7 +52,7 @@ export interface QueuedBatchOps {
52
52
  readonly ops: BatchOperation[];
53
53
  readonly res?: Failure | QueuedJob;
54
54
  }
55
- interface SceneItemError {
55
+ export interface SceneItemError {
56
56
  readonly req: CreateSceneItemRequestData;
57
57
  readonly res?: ApiError;
58
58
  }
@@ -174,7 +174,7 @@ export function createSceneAndSceneItemsEXPERIMENTAL({ client, createSceneItemRe
174
174
  })).scene,
175
175
  sceneItemErrors: batchRes
176
176
  .flatMap((b, i) => isBatch(b.res)
177
- ? b.res.vertexvis_batchresults.map((r, j) => isApiError(r)
177
+ ? b.res['vertexvis/batch:results'].map((r, j) => isApiError(r)
178
178
  ? { req: queuedOps[i].ops[j].data, res: r }
179
179
  : undefined)
180
180
  : [])
@@ -203,16 +203,7 @@ export function createSceneItemsEXPERIMENTAL({ client, createSceneItemReqs, fail
203
203
  let res;
204
204
  try {
205
205
  res = (yield client.batches.createBatch({
206
- createBatchRequest: {
207
- vertexvis_batchoperations: ops,
208
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
209
- // @ts-ignore
210
- toJSON() {
211
- return {
212
- 'vertexvis/batch:operations': this.vertexvis_batchoperations,
213
- };
214
- },
215
- },
206
+ createBatchRequest: { 'vertexvis/batch:operations': ops },
216
207
  })).data;
217
208
  }
218
209
  catch (error) {
@@ -358,6 +358,7 @@ export function tryStream(fn) {
358
358
  return yield fn();
359
359
  }
360
360
  catch (error) {
361
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
361
362
  const ae = error;
362
363
  // eslint-disable-next-line promise/param-names
363
364
  return new Promise((_resolve, reject) => {
@@ -1 +1 @@
1
- export declare const version = "0.15.4";
1
+ export declare const version = "0.15.6";
@@ -1 +1 @@
1
- export const version = '0.15.4';
1
+ export const version = '0.15.6';
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { Configuration } from './configuration';
13
13
  import { RequestArgs } from './base';
14
- import { AxiosInstance } from 'axios';
14
+ import { AxiosInstance, AxiosResponse } from 'axios';
15
15
  /**
16
16
  *
17
17
  * @export
@@ -62,4 +62,4 @@ export declare const toPathString: (url: URL) => string;
62
62
  *
63
63
  * @export
64
64
  */
65
- export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration | undefined) => (axios?: AxiosInstance, basePath?: string) => Promise<import("axios").AxiosResponse<any>>;
65
+ export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration | undefined) => <T = unknown, R = AxiosResponse<T, any>>(axios?: AxiosInstance, basePath?: string) => Promise<R>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertexvis/api-client-node",
3
- "version": "0.15.4",
3
+ "version": "0.16.0",
4
4
  "description": "The Vertex REST API client for Node.js.",
5
5
  "license": "MIT",
6
6
  "author": "Vertex Developers <support@vertexvis.com> (https://developer.vertexvis.com)",
@@ -32,6 +32,25 @@
32
32
  "api-client",
33
33
  "typescript"
34
34
  ],
35
+ "dependencies": {
36
+ "axios": "^0.24",
37
+ "p-limit": "^3"
38
+ },
39
+ "devDependencies": {
40
+ "@types/jest": "^27.0",
41
+ "@types/node": "^16",
42
+ "@vertexvis/eslint-config-vertexvis-typescript": "^0.4",
43
+ "eslint": "^7",
44
+ "eslint-plugin-promise": "^5.2",
45
+ "eslint-plugin-simple-import-sort": "^7.0",
46
+ "eslint-plugin-tsdoc": "^0.2",
47
+ "jest": "^27.4",
48
+ "pinst": "^2.1",
49
+ "prettier": "^2.5",
50
+ "ts-jest": "^27.1",
51
+ "typedoc": "^0.22",
52
+ "typescript": "4.5.x"
53
+ },
35
54
  "scripts": {
36
55
  "build": "tsc --project tsconfig.json && tsc --project tsconfig-esm.json",
37
56
  "clean": "rm -rf dist/",
@@ -49,24 +68,5 @@
49
68
  "test:func": "yarn clean-build && node dist/functional-test.js",
50
69
  "verify": "yarn clean-build && yarn test --coverage && node dist/cjs/verify.js",
51
70
  "watch": "jest --watch"
52
- },
53
- "dependencies": {
54
- "axios": "^0.21",
55
- "p-limit": "^3.1"
56
- },
57
- "devDependencies": {
58
- "@types/jest": "^27.0",
59
- "@types/node": "^16",
60
- "@vertexvis/eslint-config-vertexvis-typescript": "^0.4",
61
- "eslint": "^7.32",
62
- "eslint-plugin-promise": "^5.1",
63
- "eslint-plugin-simple-import-sort": "^7.0",
64
- "eslint-plugin-tsdoc": "^0.2",
65
- "jest": "^27.2",
66
- "pinst": "^2.1",
67
- "prettier": "^2.4",
68
- "ts-jest": "^27.0",
69
- "typedoc": "^0.22",
70
- "typescript": "4.4.x"
71
71
  }
72
72
  }