tinovyatkin / pass-js

Apple Wallet Passes generating library for Node.JS
MIT License
668 stars 81 forks source link

Update saved pass (buffer) #631

Closed spock123 closed 1 year ago

spock123 commented 1 year ago

Hi,

1) Create pass, save it in internal database (as buffer, using pass.asBuffer() ) 2) When an update occurs, do:

A) fetch buffer from database B) ... update buffer somehow .. C ... save buffer again

Is there a way to "load" the pass again using the library?

I could not find anything in the documentation about it, sorry. So in short : can we "revert" the "asBuffer()" call somehow?

If we just convert to an object, we lose the methods on the pass object so that won't work. Somehow it should be possible to load the pass again, make modifications, and then save asBuffer() again.

Cheers and thank you

spock123 commented 1 year ago

Just an update:

// Fetch saved pass (buffer) from database, and load it 
const currentPass = await Template.fromBuffer(passBufferFromDatabase);

// Create new pass by cloning the properties
const clonedPass = template.createPass({
        ...currentPass
});

// Update props of the cloned pass
// Save it again
const clonedPassBuffer = await clonedPass.asBuffer();

// Save cloned buffer