Giter Club home page Giter Club logo

angular-storage's People

Contributors

aaronroberson avatar aguspina avatar chenkie avatar cocojoe avatar damieng avatar den-t avatar hzalaz avatar jercoh avatar joshcanhelp avatar kildareflare avatar mehreencs87 avatar mgonto avatar ntotten avatar patrickjs avatar pose avatar sambego avatar schmooie avatar tomcrhak-bb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-storage's Issues

Declare namespace for storage

It would be nice to be able to declare a namespace, e.g. store.namespace("foo"). The namespace would then be prepended to all keys, e.g. store.get("key") would be equivalent in this case to store.get("foo-key") if you'd never declared a namespace.

There should also be an option to specify a different namespace on a per-get basis, or even specify that no namespace should be used.

Couldn't find ngCookies

Hi, I'm having this error

Error: [$injector:nomod] Module 'ngCookies' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

I even tried to install ngCookies. but it still didn't work. Anyone else having this problem?

JWT token saved with quotes

store.set('jwt', response.data.token);

This stores the token value encapsulated in quotes. Is there any way to avoid this? I just want the plain output from response.data.token which is unquoted.

Is there an Angular 2 version?

I had a look through your repositories for an update to this package as we update an AngularJS application to Angular. Is there an updated Angular version of this package?

Local storage date gets converted to string.

When I store a date to the local storage, after a refresh when I get it, it becomes a string.
Note that when I store it and I get it immediately after (Without the refresh) it is an object.

Sample code below. Run this twice and see the difference. The first time its run the gotten date will be an object, Refresh the page and have it run again (so that the value already exists) and it will be a string.

        var someDateToGet = store.get('someStoredDate');
        console.debug(someDateToGet);

        if (someDateToGet === null){
            var someDateToStore = new Date();
            console.debug("someDateToStore: " + typeof(someDateToStore)); 
            //returns someDateToStore: Object
            store.set('someStoredDate', someDateToStore);   

            //To check, that went well:
            someDateToGet = store.get('someStoredDate');
            console.debug("someDateToGet: " + typeof(someDateToGet)); 
            //returns someDateToGet: Object
        } else {
            //The date was already stored. 

            console.debug("someDateToGet: " + typeof(someDateToGet)); 
            //returns someDateToGet: string
        }

The expected behaviour would for it to become an object regardless of the refresh. Accepted behaviour would for it to become the same thing (either an object or a string) every time it's gotten from local storage.

bower issues.

This library works with 1.3.x, so can you please update bower.json?

Getting this:

a0-angular-storage#0.0.6, angular-jwt#0.0.4 depends on angular#~1.2.21 which resolved to angular#1.2.28

Multiple storages

Can I use both sessionStorage and localStorage at the same time? For example if user checks the 'Remind me' button, I would want to use localStorage, but I don't know that before…

Stored Data Encryption

Due to my project need to store some sensitive data, seems this library haven't encryption function. I have to encrypt, decrypt the data before save and get. So I want to ask, do you have any plan to add encryption function for easy use?
Thanks

Outdated README?

Hey, @mgonto
Great work on this module :)

I was following the discussion on #19, #20 and going through a8588c0 changes.

Correct me if I'm wrong but it seems that the README was not updated to reflect those changes.

What do you think?

Storage.Set() Improvement Multiple key-value pair

Hi, Can we improve the set() function to accept either a key-value pair or an array of key-value pair?

Example:

// For key-value pair
storage.set('key1', 'Value1');

// For multiple key-value pairs
storage.set([
	'my-key1': 'My Value 1',
	'my-key2': { 'key1': 'value' }
]);

I think this will be a good addition.

Purpose of the caching?

I wanted to ask about the purpose of the internal storage caching. Is it due to the performance reasons?

I am using the store for keeping the jwt token.
I wanted to test the jwt token being tampered by manually altering the token in the browser's localStorage.
I was surprised that the subsequent request came from the server with 200 OK.

It was caused by the internally cached value in the store.

Isn't this default behavior a bit confusing? IMO it would be nice to have the caching functionality switchable via the provider configuration.

Cookie fallback tests don't pass

On a fresh clone, I get the following test output:

Start:
  angularStorage
    ✔ should load store module
  angularStorage store
    ✔ should save items correctly in localStorage
    ✔ should save null items correctly in localStorage
    ✔ should save undefined items correctly in localStorage
    ✔ should delete items correctly from localStorage
    ✔ should save objects correctly
    ✔ should save and objects correctly without cache
  angularStorage storeProvider.setStore("sessionStorage")
    ✔ should save items correctly in the sessionStorage
    ✖ should fallback to cookieStorage
  angularStorage storeProvider.setStore("localStorage")
    ✔ should save items correctly in the localStorage
  angularStorage storeProvider.setStore("cookieStorage")
    ✔ should save items correctly in the cookieStorage
  angularStorage storeProvider.setStore()
    ✔ should save items correctly in the localStorage
  angularStorage storeProvider.setStore(123)
    ✔ should save items correctly in the localStorage
  angularStorage storeProvider.setStore("abc")
    ✔ should throw an error when the store is not found
  angularStorage store: cookie fallback
    ✖ should save items correctly in localStorage
    ✖ should save null items correctly in localStorage
    ✖ should save undefined items correctly in localStorage
    ✖ should delete items correctly from localStorage
    ✖ should save objects correctly
    ✖ should save objects correctly without cache
  angularStorage new namespaced store
    ✔ should save items correctly
    ✔ should delete items correctly from localStorage
    ✔ should save objects correctly
    ✔ should save and objects correctly without cache
    ✔ should should save items correctly when the delimiter is set
    with param storage
      ✔ should should save items correctly when the storage is set to sessionStorage
      ✔ should should save items correctly when the storage is set to localStorage
      ✔ should should save items correctly when the storage is set to cookieStorage

Finished in 0.007 secs / 0.027 secs

SUMMARY:
✔ 25 tests completed
✖ 9 tests failed

FAILED TESTS:
  angularStorage storeProvider.setStore("sessionStorage")
    ✖ should fallback to cookieStorage
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    TypeError: 'undefined' is not an object (evaluating 'rawDocument.cookie = buildCookieString(name, value, options)')
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:309
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:143
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:159
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:241
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/cookieStorage.js:6
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/internalStore.js:21
        at /Users/duncan/working/oss/angular-storage/test/unit/angularStorage/services/storeSpec.js:119
        at invoke (/Users/duncan/working/oss/angular-storage/bower/angular/angular.js:4426)
        at workFn (/Users/duncan/working/oss/angular-storage/bower/angular-mocks/angular-mocks.js:2420)
    undefined

  angularStorage store: cookie fallback
    ✖ should save items correctly in localStorage
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    TypeError: 'undefined' is not an object (evaluating 'rawDocument.cookie = buildCookieString(name, value, options)')
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:309
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:143
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:159
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:241
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/cookieStorage.js:6
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/internalStore.js:21
        at /Users/duncan/working/oss/angular-storage/test/unit/angularStorage/services/storeSpec.js:254
        at invoke (/Users/duncan/working/oss/angular-storage/bower/angular/angular.js:4426)
        at workFn (/Users/duncan/working/oss/angular-storage/bower/angular-mocks/angular-mocks.js:2420)
    undefined

    ✖ should save null items correctly in localStorage
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    TypeError: 'undefined' is not an object (evaluating 'rawDocument.cookie = buildCookieString(name, value, options)')
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:309
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:143
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:159
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:241
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/cookieStorage.js:6
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/internalStore.js:21
        at /Users/duncan/working/oss/angular-storage/test/unit/angularStorage/services/storeSpec.js:260
        at invoke (/Users/duncan/working/oss/angular-storage/bower/angular/angular.js:4426)
        at workFn (/Users/duncan/working/oss/angular-storage/bower/angular-mocks/angular-mocks.js:2420)
    undefined

    ✖ should save undefined items correctly in localStorage
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    TypeError: 'undefined' is not an object (evaluating 'rawDocument.cookie = buildCookieString(name, value, options)')
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:309
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:143
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:159
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:241
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/cookieStorage.js:6
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/internalStore.js:21
        at /Users/duncan/working/oss/angular-storage/test/unit/angularStorage/services/storeSpec.js:267
        at invoke (/Users/duncan/working/oss/angular-storage/bower/angular/angular.js:4426)
        at workFn (/Users/duncan/working/oss/angular-storage/bower/angular-mocks/angular-mocks.js:2420)
    undefined

    ✖ should delete items correctly from localStorage
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    TypeError: 'undefined' is not an object (evaluating 'rawDocument.cookie = buildCookieString(name, value, options)')
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:309
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:143
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:159
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:241
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/cookieStorage.js:6
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/internalStore.js:21
        at /Users/duncan/working/oss/angular-storage/test/unit/angularStorage/services/storeSpec.js:275
        at invoke (/Users/duncan/working/oss/angular-storage/bower/angular/angular.js:4426)
        at workFn (/Users/duncan/working/oss/angular-storage/bower/angular-mocks/angular-mocks.js:2420)
    undefined

    ✖ should save objects correctly
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    TypeError: 'undefined' is not an object (evaluating 'rawDocument.cookie = buildCookieString(name, value, options)')
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:309
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:143
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:159
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:241
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/cookieStorage.js:6
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/internalStore.js:21
        at /Users/duncan/working/oss/angular-storage/test/unit/angularStorage/services/storeSpec.js:294
        at invoke (/Users/duncan/working/oss/angular-storage/bower/angular/angular.js:4426)
        at workFn (/Users/duncan/working/oss/angular-storage/bower/angular-mocks/angular-mocks.js:2420)
    undefined

    ✖ should save objects correctly without cache
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
      PhantomJS 1.9.8 (Mac OS X 0.0.0)
    TypeError: 'undefined' is not an object (evaluating 'rawDocument.cookie = buildCookieString(name, value, options)')
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:309
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:143
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:159
        at /Users/duncan/working/oss/angular-storage/bower/angular-cookies/angular-cookies.js:241
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/cookieStorage.js:6
        at /Users/duncan/working/oss/angular-storage/src/angularStorage/services/internalStore.js:21
        at /Users/duncan/working/oss/angular-storage/test/unit/angularStorage/services/storeSpec.js:313
        at invoke (/Users/duncan/working/oss/angular-storage/bower/angular/angular.js:4426)
        at workFn (/Users/duncan/working/oss/angular-storage/bower/angular-mocks/angular-mocks.js:2420)
    undefined

[15:13:44] 'test' errored after 1.73 s
[15:13:44] Error: 1
  at formatError (/.npm-packages/lib/node_modules/gulp/bin/gulp.js:169:10)
  at Gulp.<anonymous> (/.npm-packages/lib/node_modules/gulp/bin/gulp.js:195:15)
  at Gulp.emit (events.js:107:17)
  at Gulp.Orchestrator._emitTaskDone (/Users/duncan/working/oss/angular-storage/node_modules/gulp/node_modules/orchestrator/index.js:264:8)
  at /Users/duncan/working/oss/angular-storage/node_modules/gulp/node_modules/orchestrator/index.js:275:23
  at finish (/Users/duncan/working/oss/angular-storage/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
  at cb (/Users/duncan/working/oss/angular-storage/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:29:3)
  at removeAllListeners (/Users/duncan/working/oss/angular-storage/node_modules/karma/lib/server.js:218:7)
  at Server.<anonymous> (/Users/duncan/working/oss/angular-storage/node_modules/karma/lib/server.js:229:9)
  at Server.g (events.js:199:16)
  at Server.emit (events.js:129:20)
  at net.js:1409:10
  at process._tickCallback (node.js:355:11)

Updated bower release

Do you have a timeline for releasing a new version of the bower package, incorporating the sessionStorage changes in master?

get should take callback handler

store.get should allow (or even require?) a callback function to be passed, in anticipation of supporting storage methods which require asynchronous retrieval.

No way to clear localStorage

We're currently using this workaround:

store.clear = function() {
  window.localStorage.clear();
};

But it would be awesome if this were supported in the library. Thanks!

Support for sessionStorage?

Hi auth0 team,

great work so far. Are there any plans to also support sessionStorage as a store. Ideally the user can configure which store to use, but the fallback is always the sessionStorage. I am open to add a pull request with the feature.

Greetings

Storage cache changes

Changes asked by @matjaz:

  • Change the in memory cache check to contemplate falsey values
  • Add value to the cache after getting it.

Proper handling of localStorage disabled check

In angular-storage on line 86 a check is performed for localStorage enabled on the browser by

var localStorageAvailable = !!$window.localStorage;

This check is not adequate enough bc/ at least in chrome, you get an error:
Error: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
I recommend removing that line and rather just using the try catch that is performed below as:

try {
    $window.localStorage.setItem('testKey', 'test');
    $window.localStorage.removeItem('testKey');
    var localStorageAvailable = true;
  } catch(e) {
    var localStorageAvailable = false;
}

This way chrome wouldn't break the script on the site.
This code executes before any other check in other app modules can mitigate this (for angularjs apps with localStorage turned off) This would be in order to even show a warning notice to the user.

Safari in private browsing mode throws error

Hey guys, it seems like Safari disables local/session storage when in private browsing mode. This causes angular apps to fail when trying to use the store methods. The error thrown:

Error: QuotaExceededError: DOM Exception 22

It would be nice to fall back to cookies in this instance or at least catch the error and do something with it.

Fetch all?

Is there a way to fetch all the data stored for a namespace or just in general without writing vanilla js?

Example:

store.get() <--- returns all items in storage.

store.namespace('xyz') <--- returns all item in storage for xyz namespace.

Unable to fetch String based cookies cause CookieStore is deprecated

First of all. Good job on creating this library.

I do have one suggestion.
While using the library I was unable to fetch a String based cookie from my list of cookies.
The library wanted to have an cookie that was JSON based, but because my Sting based cookie was not set by using the library (set from a response header), it failed.

It seems the $cookieStorage is using Angular's $cookieStore.
According to the Angular documentation this is a deprecated service.
https://docs.angularjs.org/api/ngCookies/service/$cookieStore
You should use the $cookies service instead.
Please consider changing services to support the use of non JSON bases cookies.
Thanks in advance.

bower install does not work

bower install a0-angular-storage
bower not-cached git://github.com/Aspera/angular-storage.git#0.0.5
bower resolve git://github.com/Aspera/angular-storage.git#0.0.5
bower cached git://github.com/auth0/angular-storage.git#0.0.10
bower validate 0.0.10 against git://github.com/auth0/angular-storage.git#*
bower ENORESTARGET No tag found that was able to satisfy 0.0.5

Additional error details:
Available versions: 0.5.0, 0.4.0, 0.3.0, 0.2.0, 0.1.2, 0.1.1, 0.1.0

localstorage value gets updated without using the store.set() method

Hi,
Thank you for this awesome storage package. I have been using this in many ways and in many projects.

Today while using store I found a bug. The issue is, first I set a JSON using store.set('objectName',myObject);.
And when I need it I fetch that object using store.get('objectName'), and once I get this object I set a new property in this object, but while doing this the store('objectName') gets updated from localstorage automatically with that new property.

Example:

angular
.controller('myCtrl', function(store){
var myObject = {
'value_1': 'value 1',
'value_2': 'value 2'
};
store.set('objectName', myObject);
})
.controller('newCtrl', function (){
var newObject = store.get('objectName');
newObject.value_3 = 'value 3';
console.log(store.get('objectName'));
});

above console.log gives you below result
{
'value_1': 'value 1',
'value_2': 'value 2',
'value_3': 'value 3'
}

Can anyone help me with this?

Please don't use hard dependencies...

I really hate it when libs use hard dependencies, esp when your not updating them weekly...

 "dependencies": {
   "angular": "~1.2.21"
 },
 "devDependencies": {
   "angular-mocks": "~1.2.21",
   "angular-scenario": "~1.2.21"
 }

Please update this to be >=1.2 or >=1.3...

Clear all

In my case, I have a lot of keys stored and on logout I just need remove all of then.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.