@promptbook/pdf 0.85.0-0 → 0.85.0-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.
@@ -47,6 +47,7 @@ import { parseKeywords } from '../utils/normalization/parseKeywords';
47
47
  import { parseKeywordsFromString } from '../utils/normalization/parseKeywordsFromString';
48
48
  import { removeDiacritics } from '../utils/normalization/removeDiacritics';
49
49
  import { searchKeywords } from '../utils/normalization/searchKeywords';
50
+ import { suffixUrl } from '../utils/normalization/suffixUrl';
50
51
  import { titleToName } from '../utils/normalization/titleToName';
51
52
  import { spaceTrim } from '../utils/organization/spaceTrim';
52
53
  import { extractParameterNames } from '../utils/parameters/extractParameterNames';
@@ -128,6 +129,7 @@ export { parseKeywords };
128
129
  export { parseKeywordsFromString };
129
130
  export { removeDiacritics };
130
131
  export { searchKeywords };
132
+ export { suffixUrl };
131
133
  export { titleToName };
132
134
  export { spaceTrim };
133
135
  export { extractParameterNames };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type fs from 'fs/promises';
2
+ import type fs from 'node:fs/promises';
3
3
  /**
4
4
  * Container for all the tools needed to manipulate with filesystem
5
5
  */
@@ -11,6 +11,8 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
11
11
  */
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): IDestroyable;
13
13
  /**
14
+ * TODO: !!!!!!! CORS and security
15
+ * TODO: !!!!!!! Allow to pass tokem here
14
16
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
15
17
  * TODO: Split this file into multiple functions - handler for each request
16
18
  * TODO: Maybe use `$exportJson`
@@ -25,12 +25,14 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
25
25
  */
26
26
  readonly port: number;
27
27
  /**
28
- * Path for the Socket.io server to listen
28
+ * Root path of the server
29
29
  *
30
- * @default '/socket.io'
31
- * @example '/promptbook/socket.io'
30
+ * Note: This is useful when you reverse proxy the server without changing the path
31
+ *
32
+ * @default '/'
33
+ * @example '/api/promptbook/'
32
34
  */
33
- readonly path: string_uri;
35
+ readonly rootPath: string_uri;
34
36
  } & (AnonymousRemoteServerOptions | ApplicationRemoteServerOptions<TCustomOptions> | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
35
37
  export type AnonymousRemoteServerOptions = {
36
38
  /**
@@ -0,0 +1,7 @@
1
+ import type { string_url } from '../../types/typeAliases';
2
+ /**
3
+ * Adds suffix to the URL
4
+ *
5
+ * @public exported from `@promptbook/utils`
6
+ */
7
+ export declare function suffixUrl(value: URL, suffix: `/${string}`): string_url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/pdf",
3
- "version": "0.85.0-0",
3
+ "version": "0.85.0-2",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/pdf.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.85.0-0"
50
+ "@promptbook/core": "0.85.0-2"
51
51
  },
52
52
  "dependencies": {
53
53
  "crypto": "^1.0.1",
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.sha256, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, rxjs, crypto, waitasecond, sha256, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('node:fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('node:path'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'node:fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'node:path', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.node_path, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.sha256, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, node_path, prettier, parserHtml, rxjs, crypto, waitasecond, sha256, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-1';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -869,7 +869,7 @@
869
869
  value = value.replace(/\.html$/, '');
870
870
  }
871
871
  else if (isValidFilePath(value)) {
872
- value = path.basename(value);
872
+ value = node_path.basename(value);
873
873
  // Note: Keeping extension in the name
874
874
  }
875
875
  value = value.split('/').join('-');
@@ -915,12 +915,12 @@
915
915
  semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
916
916
  pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
917
917
  name = pieces.join('-').split('--').join('-');
918
- cacheFilename = path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
918
+ cacheFilename = node_path.join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
919
919
  cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
920
920
  .join('/') +
921
921
  '.' +
922
922
  extension;
923
- return [4 /*yield*/, promises.mkdir(path.dirname(cacheFilename), { recursive: true })];
923
+ return [4 /*yield*/, promises.mkdir(node_path.dirname(cacheFilename), { recursive: true })];
924
924
  case 1:
925
925
  _a.sent();
926
926
  isDestroyed = true;
@@ -2527,9 +2527,9 @@
2527
2527
  function createTask(options) {
2528
2528
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2529
2529
  var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(256 /* <- TODO: !!! To global config */));
2530
- var resultSubject = new rxjs.BehaviorSubject({});
2530
+ var partialResultSubject = new rxjs.BehaviorSubject({});
2531
2531
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2532
- resultSubject.next(newOngoingResult);
2532
+ partialResultSubject.next(newOngoingResult);
2533
2533
  });
2534
2534
  function asPromise(options) {
2535
2535
  return __awaiter(this, void 0, void 0, function () {
@@ -2554,7 +2554,7 @@
2554
2554
  taskId: taskId,
2555
2555
  asPromise: asPromise,
2556
2556
  asObservable: function () {
2557
- return rxjs.concat(resultSubject.asObservable(), rxjs.from(asPromise({
2557
+ return rxjs.concat(partialResultSubject.asObservable(), rxjs.from(asPromise({
2558
2558
  isCrashedOnError: true,
2559
2559
  })));
2560
2560
  },
@@ -3684,9 +3684,9 @@
3684
3684
  }
3685
3685
  basename = url.split('/').pop() || titleToName(url);
3686
3686
  hash = sha256__default["default"](hexEncoder__default["default"].parse(url)).toString( /* hex */);
3687
- rootDirname_1 = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3688
- filepath = path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
3689
- return [4 /*yield*/, tools.fs.mkdir(path.dirname(path.join(rootDirname_1, filepath)), { recursive: true })];
3687
+ rootDirname_1 = node_path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
3688
+ filepath = node_path.join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".").concat(mimeTypeToExtension(mimeType))], false));
3689
+ return [4 /*yield*/, tools.fs.mkdir(node_path.dirname(node_path.join(rootDirname_1, filepath)), { recursive: true })];
3690
3690
  case 2:
3691
3691
  _h.sent();
3692
3692
  _g = (_f = Buffer).from;
@@ -3696,7 +3696,7 @@
3696
3696
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3697
3697
  throw new LimitReachedError("File is too large (".concat(Math.round(fileContent.length / 1024 / 1024), "MB). Maximum allowed size is ").concat(Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024), "MB."));
3698
3698
  }
3699
- return [4 /*yield*/, tools.fs.writeFile(path.join(rootDirname_1, filepath), fileContent)];
3699
+ return [4 /*yield*/, tools.fs.writeFile(node_path.join(rootDirname_1, filepath), fileContent)];
3700
3700
  case 4:
3701
3701
  _h.sent();
3702
3702
  // TODO: [💵] Check the file security
@@ -3712,7 +3712,7 @@
3712
3712
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
3713
3713
  // <- TODO: [🧠] What is the best error type here`
3714
3714
  }
3715
- filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3715
+ filename_1 = node_path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3716
3716
  fileExtension = getFileExtension(filename_1);
3717
3717
  mimeType = extensionToMimeType(fileExtension || '');
3718
3718
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];