Skip to content

Instantly share code, notes, and snippets.

@dvdsmpsn
Last active July 13, 2022 10:56
Show Gist options
  • Save dvdsmpsn/26276e48bf6c1adac5bb8ef94649b25e to your computer and use it in GitHub Desktop.
Save dvdsmpsn/26276e48bf6c1adac5bb8ef94649b25e to your computer and use it in GitHub Desktop.

Findings from initial attempts at using monday.storage

monday.storage is documented here: https://github.com/mondaycom/monday-sdk-js#mondaystorage

Attempting to save a key with name xxx.yyy.zzz failed because keys can only be alphanumeric with the following aditional characters :_-. This does not appear to be documented, but at least fails with a descriptive error message.

Example 1: This works just great

Without a newline character, everything is fine.

const monday = mondaySdk();

const someKey = "someKey";
const someVal = "Lorem Ipsum 123";
monday.storage.instance.setItem(someKey, someVal).then((res) => {
  console.log(res);
  // --> {method: 'storage', type: undefined, data: {success: true, version: 'edc92'}, requestId: 'en3u9u96f', errorMessage: undefined}
  
  monday.storage.instance.getItem(someKey).then((res) => {
    console.log(res.data.value); 
    // --> Lorem Ipsum 123
    
  });
});

Example 2: Adding a new line character

This now fails because of a new line character.

const monday = mondaySdk();

const someKey = "someKey";
const someVal = "Lorem Ipsum 123\n\nxxxx";
monday.storage.instance.setItem(someKey, someVal).then((res) => {
  console.log(res);
  // --> {method: 'storage', type: undefined, data: {success: true, version: 'edc92'}, requestId: 'en3u9u96f', errorMessage: undefined}
  
  monday.storage.instance.getItem(someKey).then((res) => {
    console.log(res.data.value); // --> NULL
  });
});

Example 3: A workaround

Dodgy workaround to get around the failure from the new line character

const monday = mondaySdk();
const someKey = "someKey";
const someVal = "Lorem Ipsum 123\n\nxxxx";
const newLine = "[NEWLINE]";
monday.storage.instance.setItem(
  someKey, 
  someVal.replaceAll("\n", newLine)
).then((res) => {
  console.log(res);
  // --> {method: 'storage', type: undefined, data: {success: true, version: 'edc92'}, requestId: 'en3u9u96f', errorMessage: undefined}
  
  monday.storage.instance.getItem(someKey).then((res) => {
    console.log(
      res.data.value
    ); // --> Lorem Ipsum 123[NEWLINE][NEWLINE]xxxx
    
    console.log(
      res.data.value
        .replaceAll(newLine, "\n")
    ); // --> Lorem Ipsum 123\n\nxxxx
  });
});

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment