@sasjs/utils 3.7.3 → 4.0.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.
- package/README.md +23 -0
- package/index.d.ts +0 -1
- package/index.js +6 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/utils/base64.js +22 -2
- package/utils/base64.js.map +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,29 @@
|
|
|
6
6
|
|
|
7
7
|
A library of utilities and types for SASjs written in TypeScript.
|
|
8
8
|
|
|
9
|
+
## Entry points
|
|
10
|
+
|
|
11
|
+
This is a Node library, and the barrel - `import { x } from '@sasjs/utils'` - is its Node
|
|
12
|
+
entry point. Importing from it pulls in the modules that only Node can run: `fs-extra` and
|
|
13
|
+
`@fast-csv/format` through `./file`, `prompts` through `./input`, `chalk` and `consola`
|
|
14
|
+
through `./logger` and `./formatter`.
|
|
15
|
+
|
|
16
|
+
Code that is bundled for a browser imports the subpath it needs instead:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
import { ServerType } from '@sasjs/utils/types'
|
|
20
|
+
import { prefixMessage } from '@sasjs/utils/error'
|
|
21
|
+
import { isSpecialMissing } from '@sasjs/utils/input/validators'
|
|
22
|
+
import { bytesToSize } from '@sasjs/utils/utils'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The hash and sync helpers - `getHash`, `compareHashes`, `extractHashArray`,
|
|
26
|
+
`generateCompileProgram`, `generateProgramToGetRemoteHash`, `generateProgramToSyncHashDiff`
|
|
27
|
+
and `findResourcesNotPresentLocally` - live in `@sasjs/utils/fs`. They hash files and
|
|
28
|
+
folders on disk, so they are Node-only, and the barrel does not re-export them: a browser
|
|
29
|
+
bundle that imports the barrel for anything else no longer reaches `crypto`, which used to
|
|
30
|
+
arrive with the whole AES/RSA/ECDSA polyfill suite behind it.
|
|
31
|
+
|
|
9
32
|
## Contributors ✨
|
|
10
33
|
|
|
11
34
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -20,5 +20,10 @@ __exportStar(require("./time"), exports);
|
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
21
21
|
__exportStar(require("./utils"), exports);
|
|
22
22
|
__exportStar(require("./compileTree"), exports);
|
|
23
|
-
|
|
23
|
+
// './fs' is deliberately absent: it is the only module here that imports
|
|
24
|
+
// `crypto`, and re-exporting it put that - plus browserify-sign, parse-asn1,
|
|
25
|
+
// asn1.js and vm-browserify, roughly 555 KB of AES/RSA/ECDSA polyfills and a
|
|
26
|
+
// vm shim's dynamic code execution - into every browser bundle that imported
|
|
27
|
+
// anything from this barrel. The helpers live at '@sasjs/utils/fs' instead.
|
|
28
|
+
// See sasjs/utils#275.
|
|
24
29
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsB;AACtB,yCAAsB;AACtB,8CAA2B;AAC3B,0CAAuB;AACvB,2CAAwB;AACxB,6CAA0B;AAC1B,yCAAsB;AACtB,0CAAuB;AACvB,0CAAuB;AACvB,gDAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsB;AACtB,yCAAsB;AACtB,8CAA2B;AAC3B,0CAAuB;AACvB,2CAAwB;AACxB,6CAA0B;AAC1B,yCAAsB;AACtB,0CAAuB;AACvB,0CAAuB;AACvB,gDAA6B;AAC7B,yEAAyE;AACzE,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,uBAAuB"}
|
package/package.json
CHANGED
package/utils/base64.js
CHANGED
|
@@ -11,15 +11,35 @@ const PREFIX_HEX_LENGTH = 200;
|
|
|
11
11
|
const randomHexPrefix = () => Array.from(crypto.getRandomValues(new Uint8Array(PREFIX_HEX_LENGTH / 2)))
|
|
12
12
|
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
13
13
|
.join('');
|
|
14
|
+
// Buffer does not exist in a browser, and this module is reachable from the
|
|
15
|
+
// package root, so the encoding uses the platform globals instead. TextEncoder
|
|
16
|
+
// and TextDecoder carry the UTF-8 step: btoa is latin1, so encoding a password
|
|
17
|
+
// through it directly corrupts anything non-ASCII. The binary string is built
|
|
18
|
+
// in chunks because spreading a whole byte array into String.fromCharCode
|
|
19
|
+
// overflows the call stack on long input.
|
|
20
|
+
const CHUNK_SIZE = 0x8000;
|
|
21
|
+
const toBase64 = (bytes) => {
|
|
22
|
+
let binary = '';
|
|
23
|
+
for (let offset = 0; offset < bytes.length; offset += CHUNK_SIZE) {
|
|
24
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + CHUNK_SIZE));
|
|
25
|
+
}
|
|
26
|
+
return btoa(binary);
|
|
27
|
+
};
|
|
28
|
+
const fromBase64 = (str) => {
|
|
29
|
+
// Buffer ignores whitespace when decoding base64 and atob does not, so a
|
|
30
|
+
// wrapped or padded stored value still decodes.
|
|
31
|
+
const binary = atob(str.replace(/\s/g, ''));
|
|
32
|
+
return new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0)));
|
|
33
|
+
};
|
|
14
34
|
const encodeToBase64 = (str) => {
|
|
15
|
-
const encodedPassword =
|
|
35
|
+
const encodedPassword = toBase64(new TextEncoder().encode(randomHexPrefix() + str));
|
|
16
36
|
return PREFIX + encodedPassword;
|
|
17
37
|
};
|
|
18
38
|
exports.encodeToBase64 = encodeToBase64;
|
|
19
39
|
const decodeFromBase64 = (str) => {
|
|
20
40
|
if (str.startsWith(PREFIX)) {
|
|
21
41
|
str = str.replace(/^{sasjs_encoded}/, '');
|
|
22
|
-
const decodedPassword =
|
|
42
|
+
const decodedPassword = fromBase64(str);
|
|
23
43
|
return decodedPassword.substring(200);
|
|
24
44
|
}
|
|
25
45
|
return str;
|
package/utils/base64.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG,iBAAiB,CAAA;AAChC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAE7B,iFAAiF;AACjF,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,sEAAsE;AACtE,MAAM,eAAe,GAAG,GAAW,EAAE,CACnC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC;KACtE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KACjD,IAAI,CAAC,EAAE,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG,iBAAiB,CAAA;AAChC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAE7B,iFAAiF;AACjF,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,sEAAsE;AACtE,MAAM,eAAe,GAAG,GAAW,EAAE,CACnC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC;KACtE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KACjD,IAAI,CAAC,EAAE,CAAC,CAAA;AAEb,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,0EA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