Skip to content

Commit

Permalink
Merge pull request #10 from nixgram/3-resolve-dependency-resolution-e…
Browse files Browse the repository at this point in the history
…rr-in-angular-v14

resolved installation failed due to ng-packagr change #9
  • Loading branch information
sefatanam authored Nov 20, 2022
2 parents f4038c5 + 6de4535 commit 7a473d4
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
## Angular Compatibility Version

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

<br>

Expand Down
Binary file removed dist_backup.zip
Binary file not shown.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-browser-storage",
"version": "2.0.0",
"version": "2.1.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down Expand Up @@ -37,5 +37,6 @@
"ng-packagr": "^15.0.0",
"typescript": "~4.8.4"
},
"license": "MIT"
"license": "MIT",
"type": "module"
}
11 changes: 10 additions & 1 deletion projects/crypto-browser-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

<br>

## Angular Compatibility Version

- For `ng v12.x.x` use `npm i crypto-browser-storage@1.0.3`
- For `ng v14.x.x` use `npm i crypto-browser-storage@1.4.0`
- For `ng v15.x.x` use `npm i crypto-browser-storage@2.1.0`

<br>

## Sample Code Snippet
<br>

Expand Down Expand Up @@ -44,7 +52,8 @@ constructor(private cache: CryptoBrowserStorageService) {}
}
````
End result of the following ``tests()`` method is bellow,
### End result of the following ``tests()`` method is bellow,
<br>

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

Expand Down
5 changes: 4 additions & 1 deletion projects/crypto-browser-storage/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
},
"allowedNonPeerDependencies": [
"crypto-js",
"secure-web-storage"
"generate-"
],
"assets": [
"./node_modules/secure-web-storage/secure-storage.js"
]
}
9 changes: 5 additions & 4 deletions projects/crypto-browser-storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-browser-storage",
"version": "2.0.0",
"version": "2.1.0",
"description": "☢ A simple package for secure local storage data by encryption using Crypto.JS",
"author": {
"url": "https://github.com/nixgram",
Expand All @@ -19,16 +19,17 @@
"@angular/common": "^15.0.0",
"@angular/core": "^15.0.0",
"crypto-js": "^3.1.8",
"secure-web-storage": "^1.0.2"
"generate-js": "^3.1.2"
},
"dependencies": {
"crypto-js": "^3.1.8",
"secure-web-storage": "^1.0.2",
"generate-js": "^3.1.2",
"tslib": "^2.3.0"
},
"devDependencies": {
"@types/crypto-js": "^4.1.1",
"@types/node": "^16.11.6"
},
"license": "MIT"
"license": "MIT",
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Injectable } from '@angular/core';
import * as CryptoJS from "crypto-js";
import { KEY } from "./KEY";

const SecureStorage = require("secure-web-storage");
import { SecureStorage } from './secure-storage';

@Injectable({
providedIn: 'root'
Expand Down
89 changes: 89 additions & 0 deletions projects/crypto-browser-storage/src/lib/secure-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// var Generator = require('generate-js');

// @ts-ignore
import * as Generator from 'generate-js';

export const SecureStorage = Generator.generate(
function SecureStorage(storage:any, options:any) {
//@ts-ignore
var _ = this;

_.storage = storage;
if (options) {
_.hash = options.hash;
_.encrypt = options.encrypt;
_.decrypt = options.decrypt;
}
}
);

function through(data:any) {
return data;
}

SecureStorage.definePrototype({
hash: through,
encrypt: through,
decrypt: through,
}, {
writable: true
});

SecureStorage.definePrototype({
getItem: function getItem(key:any) {
var _ = this;

key = _.hash(key);

var value = _.storage.getItem(key);

if (typeof value !== 'string') {
return value;
}

value = _.decrypt(value);

return JSON.parse(value);
},

setItem: function setItem(key:string, value:string) {
var _ = this;

key = _.hash(key);

value = JSON.stringify(value);

value = _.encrypt(value);

return _.storage.setItem(key, value);
},

removeItem: function removeItem(key:string) {
var _ = this;

key = _.hash(key);

return _.storage.removeItem(key);
},

clear: function clear() {
var _ = this;

return _.storage.clear();
},

key: function key(id:any) {
var _ = this;

return _.storage.key(id);
},

length: {
get: function getLength():any {
var _ = this;
// @ts-ignore
return _.storage.length;
}
}
});

2 changes: 1 addition & 1 deletion projects/crypto-browser-storage/src/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Public API Surface of crypto-browser-storage
*/

export * from './lib/crypto-browser-storage.service';
export * from './lib/secure-storage';
6 changes: 4 additions & 2 deletions projects/crypto-browser-storage/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2020",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"allowJs": true,
"module": "ES6",
"types": [
"node"
],
Expand All @@ -16,7 +17,8 @@
"lib": [
"dom",
"es2018"
]
],

},
"exclude": [
"src/test.ts",
Expand Down
7 changes: 5 additions & 2 deletions projects/crypto-browser-storage/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
"declarationMap": false,
"allowJs": true,
"module": "ES6",
"target": "ES6"
},
"angularCompilerOptions": {
"compilationMode": "partial"
}
},
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"baseUrl": "./",
"paths": {
"crypto-browser-storage": [
"dist/crypto-browser-storage/crypto-browser-storage",
"dist/crypto-browser-storage"
]
},
Expand All @@ -21,7 +20,8 @@
"moduleResolution": "node",
"importHelpers": true,
"target": "es2020",
"module": "es2020",
"module": "ES6",
"allowJs": true,
"lib": [
"es2018",
"dom"
Expand Down

0 comments on commit 7a473d4

Please sign in to comment.