Skip to content

Commit 7a473d4

Browse files
authored
Merge pull request #10 from nixgram/3-resolve-dependency-resolution-err-in-angular-v14
resolved installation failed due to ng-packagr change #9
2 parents f4038c5 + 6de4535 commit 7a473d4

File tree

12 files changed

+126
-19
lines changed

12 files changed

+126
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
## Angular Compatibility Version
1616

1717
- For `ng v12.x.x` use `npm i crypto-browser-storage@1.0.3`
18-
- For `ng v14.x.x` use `npm i crypto-browser-storage@1.1.4`
19-
- For `ng v15.x.x` use `npm i crypto-browser-storage@2.0.0`
18+
- For `ng v14.x.x` use `npm i crypto-browser-storage@1.4.0`
19+
- For `ng v15.x.x` use `npm i crypto-browser-storage@2.1.0`
2020

2121
<br>
2222

dist_backup.zip

-17.1 KB
Binary file not shown.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crypto-browser-storage",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",
@@ -37,5 +37,6 @@
3737
"ng-packagr": "^15.0.0",
3838
"typescript": "~4.8.4"
3939
},
40-
"license": "MIT"
40+
"license": "MIT",
41+
"type": "module"
4142
}

projects/crypto-browser-storage/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212

1313
<br>
1414

15+
## Angular Compatibility Version
16+
17+
- For `ng v12.x.x` use `npm i crypto-browser-storage@1.0.3`
18+
- For `ng v14.x.x` use `npm i crypto-browser-storage@1.4.0`
19+
- For `ng v15.x.x` use `npm i crypto-browser-storage@2.1.0`
20+
21+
<br>
22+
1523
## Sample Code Snippet
1624
<br>
1725

@@ -44,7 +52,8 @@ constructor(private cache: CryptoBrowserStorageService) {}
4452
4553
}
4654
````
47-
End result of the following ``tests()`` method is bellow,
55+
### End result of the following ``tests()`` method is bellow,
56+
<br>
4857

4958
![Screenshot 2021-10-30 204648](https://user-images.githubusercontent.com/37630292/139538058-0fa32585-bc84-4518-b6e9-cec7d38545a8.png)
5059

projects/crypto-browser-storage/ng-package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
},
77
"allowedNonPeerDependencies": [
88
"crypto-js",
9-
"secure-web-storage"
9+
"generate-"
10+
],
11+
"assets": [
12+
"./node_modules/secure-web-storage/secure-storage.js"
1013
]
1114
}

projects/crypto-browser-storage/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crypto-browser-storage",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "☢ A simple package for secure local storage data by encryption using Crypto.JS",
55
"author": {
66
"url": "https://github.com/nixgram",
@@ -19,16 +19,17 @@
1919
"@angular/common": "^15.0.0",
2020
"@angular/core": "^15.0.0",
2121
"crypto-js": "^3.1.8",
22-
"secure-web-storage": "^1.0.2"
22+
"generate-js": "^3.1.2"
2323
},
2424
"dependencies": {
2525
"crypto-js": "^3.1.8",
26-
"secure-web-storage": "^1.0.2",
26+
"generate-js": "^3.1.2",
2727
"tslib": "^2.3.0"
2828
},
2929
"devDependencies": {
3030
"@types/crypto-js": "^4.1.1",
3131
"@types/node": "^16.11.6"
3232
},
33-
"license": "MIT"
33+
"license": "MIT",
34+
"type": "module"
3435
}

projects/crypto-browser-storage/src/lib/crypto-browser-storage.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import * as CryptoJS from "crypto-js";
33
import { KEY } from "./KEY";
4-
5-
const SecureStorage = require("secure-web-storage");
4+
import { SecureStorage } from './secure-storage';
65

76
@Injectable({
87
providedIn: 'root'
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// var Generator = require('generate-js');
2+
3+
// @ts-ignore
4+
import * as Generator from 'generate-js';
5+
6+
export const SecureStorage = Generator.generate(
7+
function SecureStorage(storage:any, options:any) {
8+
//@ts-ignore
9+
var _ = this;
10+
11+
_.storage = storage;
12+
if (options) {
13+
_.hash = options.hash;
14+
_.encrypt = options.encrypt;
15+
_.decrypt = options.decrypt;
16+
}
17+
}
18+
);
19+
20+
function through(data:any) {
21+
return data;
22+
}
23+
24+
SecureStorage.definePrototype({
25+
hash: through,
26+
encrypt: through,
27+
decrypt: through,
28+
}, {
29+
writable: true
30+
});
31+
32+
SecureStorage.definePrototype({
33+
getItem: function getItem(key:any) {
34+
var _ = this;
35+
36+
key = _.hash(key);
37+
38+
var value = _.storage.getItem(key);
39+
40+
if (typeof value !== 'string') {
41+
return value;
42+
}
43+
44+
value = _.decrypt(value);
45+
46+
return JSON.parse(value);
47+
},
48+
49+
setItem: function setItem(key:string, value:string) {
50+
var _ = this;
51+
52+
key = _.hash(key);
53+
54+
value = JSON.stringify(value);
55+
56+
value = _.encrypt(value);
57+
58+
return _.storage.setItem(key, value);
59+
},
60+
61+
removeItem: function removeItem(key:string) {
62+
var _ = this;
63+
64+
key = _.hash(key);
65+
66+
return _.storage.removeItem(key);
67+
},
68+
69+
clear: function clear() {
70+
var _ = this;
71+
72+
return _.storage.clear();
73+
},
74+
75+
key: function key(id:any) {
76+
var _ = this;
77+
78+
return _.storage.key(id);
79+
},
80+
81+
length: {
82+
get: function getLength():any {
83+
var _ = this;
84+
// @ts-ignore
85+
return _.storage.length;
86+
}
87+
}
88+
});
89+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
22
* Public API Surface of crypto-browser-storage
33
*/
4-
54
export * from './lib/crypto-browser-storage.service';
5+
export * from './lib/secure-storage';

projects/crypto-browser-storage/tsconfig.lib.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"extends": "../../tsconfig.json",
44
"compilerOptions": {
55
"outDir": "../../out-tsc/lib",
6-
"target": "es2020",
76
"declaration": true,
87
"declarationMap": true,
98
"inlineSources": true,
9+
"allowJs": true,
10+
"module": "ES6",
1011
"types": [
1112
"node"
1213
],
@@ -16,7 +17,8 @@
1617
"lib": [
1718
"dom",
1819
"es2018"
19-
]
20+
],
21+
2022
},
2123
"exclude": [
2224
"src/test.ts",

0 commit comments

Comments
 (0)