@softwear/latestcollectioncore 1.0.153 → 1.0.158

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.
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Buffer } from 'node:buffer';
4
3
  export declare function encrypt(plain: string, KEY: Buffer): string;
5
4
  export declare function decrypt(enc: string, KEY: Buffer): string;
@@ -1,31 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decrypt = exports.encrypt = void 0;
4
- const node_buffer_1 = require("node:buffer");
5
- const node_crypto_1 = require("node:crypto");
4
+ /**
5
+ * Node-only AES-GCM. Import from `@softwear/latestcollectioncore/cryptography` (not the main package).
6
+ * Uses global `Buffer` and bare `crypto` so bundlers need not resolve `node:` URLs.
7
+ */
8
+ const crypto_1 = require("crypto");
9
+ function assertNodeOnly() {
10
+ var _a;
11
+ if (typeof process === 'undefined' || !((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node)) {
12
+ throw new Error('@softwear/latestcollectioncore/cryptography is Node-only');
13
+ }
14
+ }
6
15
  function encrypt(plain, KEY) {
7
- const iv = (0, node_crypto_1.randomBytes)(12);
8
- const cipher = (0, node_crypto_1.createCipheriv)('aes-256-gcm', KEY, iv);
9
- const ciphertext = node_buffer_1.Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()]);
16
+ assertNodeOnly();
17
+ const iv = (0, crypto_1.randomBytes)(12);
18
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', KEY, iv);
19
+ const ciphertext = Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()]);
10
20
  const tag = cipher.getAuthTag();
11
21
  const b64 = (b) => b.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
12
22
  return `v1:${b64(iv)}:${b64(ciphertext)}:${b64(tag)}`;
13
23
  }
14
24
  exports.encrypt = encrypt;
15
25
  function decrypt(enc, KEY) {
26
+ assertNodeOnly();
16
27
  const [version, ivB64, ctB64, tagB64] = enc.split(':');
17
28
  if (version !== 'v1')
18
29
  throw new Error('Unsupported version');
19
30
  const fromB64 = (s) => {
20
31
  const pad = s.length % 4 ? '='.repeat(4 - (s.length % 4)) : '';
21
- return node_buffer_1.Buffer.from(s.replace(/-/g, '+').replace(/_/g, '/') + pad, 'base64');
32
+ return Buffer.from(s.replace(/-/g, '+').replace(/_/g, '/') + pad, 'base64');
22
33
  };
23
34
  const iv = fromB64(ivB64);
24
35
  const ct = fromB64(ctB64);
25
36
  const tag = fromB64(tagB64);
26
- const decipher = (0, node_crypto_1.createDecipheriv)('aes-256-gcm', KEY, iv);
37
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', KEY, iv);
27
38
  decipher.setAuthTag(tag);
28
- const plain = node_buffer_1.Buffer.concat([decipher.update(ct), decipher.final()]);
39
+ const plain = Buffer.concat([decipher.update(ct), decipher.final()]);
29
40
  return plain.toString('utf8');
30
41
  }
31
42
  exports.decrypt = decrypt;
package/dist/index.d.ts CHANGED
@@ -17,6 +17,5 @@ export { default as sizeToMap } from './sizeToMap';
17
17
  export { default as transaction } from './transaction';
18
18
  export * from './types';
19
19
  export * from './consts';
20
- export * from './cryptography';
21
20
  export { default as lcAxios, createAxiosInstance, axiosRetry, exponentialDelay, isAxiosError, } from './lcAxios';
22
21
  export type { AxiosRequestConfig, AxiosResponse, AxiosPromise, AxiosError, AxiosTransformer, AxiosRetryOptions, AxiosRequestConfigAny, } from './lcAxios';
package/dist/index.js CHANGED
@@ -54,7 +54,6 @@ var transaction_1 = require("./transaction");
54
54
  Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return __importDefault(transaction_1).default; } });
55
55
  __exportStar(require("./types"), exports);
56
56
  __exportStar(require("./consts"), exports);
57
- __exportStar(require("./cryptography"), exports);
58
57
  var lcAxios_1 = require("./lcAxios");
59
58
  Object.defineProperty(exports, "lcAxios", { enumerable: true, get: function () { return __importDefault(lcAxios_1).default; } });
60
59
  Object.defineProperty(exports, "createAxiosInstance", { enumerable: true, get: function () { return lcAxios_1.createAxiosInstance; } });
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.153",
3
+ "version": "1.0.158",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./cryptography": {
13
+ "types": "./dist/cryptography.d.ts",
14
+ "default": "./dist/cryptography.js"
15
+ }
16
+ },
7
17
  "scripts": {
8
18
  "build": "tsc -p tsconfig.json",
9
19
  "build:watch": "tsc -p tsconfig.json --watch",
@@ -27,8 +37,8 @@
27
37
  "typescript": "^4.9.4",
28
38
  "vitest": "^1.0.0"
29
39
  },
30
- "dependencies": {
31
- "date-fns": "^2.29.3",
40
+ "dependencies": {
41
+ "date-fns": "^2.29.3",
32
42
  "filtrex": "^2.2.3"
33
43
  }
34
44
  }
@@ -1,7 +1,17 @@
1
- import { Buffer } from 'node:buffer'
2
- import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto'
1
+ /**
2
+ * Node-only AES-GCM. Import from `@softwear/latestcollectioncore/cryptography` (not the main package).
3
+ * Uses global `Buffer` and bare `crypto` so bundlers need not resolve `node:` URLs.
4
+ */
5
+ import { createCipheriv, createDecipheriv, randomBytes } from 'crypto'
6
+
7
+ function assertNodeOnly(): void {
8
+ if (typeof process === 'undefined' || !process.versions?.node) {
9
+ throw new Error('@softwear/latestcollectioncore/cryptography is Node-only')
10
+ }
11
+ }
3
12
 
4
13
  export function encrypt(plain: string, KEY: Buffer): string {
14
+ assertNodeOnly()
5
15
  const iv = randomBytes(12)
6
16
  const cipher = createCipheriv('aes-256-gcm', KEY, iv)
7
17
  const ciphertext = Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()])
@@ -13,6 +23,7 @@ export function encrypt(plain: string, KEY: Buffer): string {
13
23
  }
14
24
 
15
25
  export function decrypt(enc: string, KEY: Buffer): string {
26
+ assertNodeOnly()
16
27
  const [version, ivB64, ctB64, tagB64] = enc.split(':')
17
28
  if (version !== 'v1') throw new Error('Unsupported version')
18
29
 
package/src/index.ts CHANGED
@@ -17,7 +17,6 @@ export { default as sizeToMap } from './sizeToMap'
17
17
  export { default as transaction } from './transaction'
18
18
  export * from './types'
19
19
  export * from './consts'
20
- export * from './cryptography'
21
20
  export {
22
21
  default as lcAxios,
23
22
  createAxiosInstance,
@@ -1,6 +1,6 @@
1
1
  const { vi } = globalThis
2
2
  const crypto = require('crypto')
3
- const { encrypt, decrypt } = require('../dist/index')
3
+ const { encrypt, decrypt } = require('../dist/cryptography')
4
4
 
5
5
  describe('cryptography helpers', function () {
6
6
  const KEY = Buffer.alloc(32, 1)