@sprucelabs/spruce-file-utils 15.1.8 → 15.1.10

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.
@@ -0,0 +1,5 @@
1
+ import AbstractSpruceError from '@sprucelabs/error';
2
+ import ErrorOptions from './../.spruce/errors/options.types';
3
+ export default class SpruceError extends AbstractSpruceError<ErrorOptions> {
4
+ friendlyMessage(): string;
5
+ }
@@ -0,0 +1,21 @@
1
+ import AbstractSpruceError from '@sprucelabs/error';
2
+ export default class SpruceError extends AbstractSpruceError {
3
+ friendlyMessage() {
4
+ const { options } = this;
5
+ let message;
6
+ switch (options === null || options === void 0 ? void 0 : options.code) {
7
+ case 'UNAUTHORIZED':
8
+ message = 'You are not authorized to perform this action.';
9
+ break;
10
+ case 'BAD_REQUEST':
11
+ message = 'A Bad request just happened!';
12
+ break;
13
+ default:
14
+ message = super.friendlyMessage();
15
+ }
16
+ const fullMessage = options.friendlyMessage
17
+ ? options.friendlyMessage
18
+ : message;
19
+ return fullMessage;
20
+ }
21
+ }
@@ -3,3 +3,4 @@ export * from './uploading/FileUploader';
3
3
  export { default as ChunkingUploaderImpl } from './uploading/ChunkingUploader';
4
4
  export * from './uploading/ChunkingUploader';
5
5
  export { default as MockChunkingUploader } from './uploading/MockChunkingUploader';
6
+ export { UploadedFile } from './files.types';
@@ -0,0 +1,15 @@
1
+ import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
2
+ import { UploadedFile } from '../files.types';
3
+ import { ChunkingUploader, ChunkingUploaderEventContract, UploadOptions } from './ChunkingUploader';
4
+ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingUploaderEventContract> implements ChunkingUploader {
5
+ static instance?: MockChunkingUploader;
6
+ private lastUploadOptions?;
7
+ private lastUploadResponse?;
8
+ constructor();
9
+ static assertWasCreated(): void;
10
+ assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
11
+ assertUploadOptionsEqual(options: UploadOptions): void;
12
+ upload(options: UploadOptions): Promise<{
13
+ file: UploadedFile;
14
+ }>;
15
+ }
@@ -0,0 +1,41 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
11
+ import { assertOptions } from '@sprucelabs/schema';
12
+ import { assert, generateId } from '@sprucelabs/test-utils';
13
+ import { chunkingUploaderEventContract, } from './ChunkingUploader.js';
14
+ export default class MockChunkingUploader extends AbstractEventEmitter {
15
+ constructor() {
16
+ super(chunkingUploaderEventContract);
17
+ MockChunkingUploader.instance = this;
18
+ }
19
+ static assertWasCreated() {
20
+ assert.isTruthy(MockChunkingUploader.instance, 'You need to instantiate ChunkingUploaderImpl.Uploader(()=>this.connectApi()).');
21
+ }
22
+ assertFileEqualsLastReturnedFromUpload(file) {
23
+ assertOptions({ file }, ['file']);
24
+ assert.isEqualDeep(file, this.lastUploadResponse, 'Files do not match');
25
+ }
26
+ assertUploadOptionsEqual(options) {
27
+ assertOptions(options, ['fileName', 'base64']);
28
+ assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
29
+ }
30
+ upload(options) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ this.lastUploadOptions = options;
33
+ this.lastUploadResponse = {
34
+ id: generateId(),
35
+ type: generateId(),
36
+ uri: generateId(),
37
+ };
38
+ return { file: this.lastUploadResponse };
39
+ });
40
+ }
41
+ }
@@ -3,3 +3,4 @@ export * from './uploading/FileUploader';
3
3
  export { default as ChunkingUploaderImpl } from './uploading/ChunkingUploader';
4
4
  export * from './uploading/ChunkingUploader';
5
5
  export { default as MockChunkingUploader } from './uploading/MockChunkingUploader';
6
+ export { UploadedFile } from './files.types';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-file-utils",
3
3
  "description": "Utils for working with files and Sprucebot.",
4
- "version": "15.1.8",
4
+ "version": "15.1.10",
5
5
  "skill": {
6
6
  "namespace": "files"
7
7
  },
@@ -29,8 +29,15 @@
29
29
  "build/esm/uploading/ChunkingUploader.js",
30
30
  "build/uploading/ChunkingUploader.d.ts",
31
31
  "build/uploading/ChunkingUploader.js",
32
+
33
+ "build/esm/uploading/MockChunkingUploader.d.ts",
34
+ "build/esm/uploading/MockChunkingUploader.js",
32
35
  "build/uploading/MockChunkingUploader.d.ts",
33
36
  "build/uploading/MockChunkingUploader.js",
37
+
38
+
39
+ "build/esm/errors/SpruceError.d.ts",
40
+ "build/esm/errors/SpruceError.js",
34
41
  "build/errors/SpruceError.d.ts",
35
42
  "build/errors/SpruceError.js",
36
43