cosmicjs / cosmicjs-node Goto Github PK
View Code? Open in Web Editor NEW*API v2 JavaScript client for Cosmic. See important message in README
Home Page: https://www.cosmicjs.com
License: MIT License
*API v2 JavaScript client for Cosmic. See important message in README
Home Page: https://www.cosmicjs.com
License: MIT License
Curious why there is no catch on the fetches or any way to handle a reject. I think this is in most of the code, but I came across it looking at getObject.
fetch(endpoint)
.then(function(response){
if (response.status >= 400) {
var err = {
'message': 'There was an error with this request.'
}
return callback(err, false);
}
return response.json()
})
.then(function(response){
// Constructor
var cosmic = {};
var object = response.object;
var metafields = object.metafields;
if(metafields){
object.metafield = _.keyBy(metafields, "key");
}
If the resources does not exist, Cosmic returns a 404, which passes an error message back to my callback, but then continues to the next then() statement and errors out at response.object. Is there a way that I am supposed to halt the fetch() in my callback to prevent it from executing the final then() when there is an error ?
Hello all! I'd like to get my data filtering by published_at field but I guess that the field type is an String. Is that right? This is my query which is not working.
const data = await bucket.objects .find({ type: "publicacoes", published_at: { $gte: new Date("2021-01-10T10:03:46Z") } }).props("imagem,slug,content,metadata,published_at,title,excerpt") return data.objects;
Currently, there seems to be no option for selecting the fields that should be included in the response during a getObject or seachObject call. To get a single metafield value from an object, the whole object needs to be downloaded. For simple objects, this doesn't add much overhead. But that's not the case when an object contains large descriptions, articles etc.
Similarly, should be able to select fields on connected objects too.
I'm using cosmicjs in a big React app created with create-react-app
and I cannot build the project via npm run build
without receiving this error:
Creating an optimized production build...
Failed to compile.
Failed to minify the code from this file:
./node_modules/cosmicjs/index.js:6
Read more here: http://bit.ly/2tRViJ9
Now as the helpful link suggest this means the file is not pre-compiled and that seems to be true, so could you please publish the next version precompiled (if that is indeed the issue here)?
Also, is there anything I can do as a workaround, so that I can import coscmisjs and build the app like I can with any other npm module now? The build happens via CI, so precompiling it manually makes the whole thing more brittle than it should anyway.
I'm open for suggestions. Maybe I'm just doing something wrong myself.
Seems like the api endpoint is getting the bucket_slug
instead of the object slug and that's why it is returning 'Object not found'.
In line 272 bucket_config contains slug.
After changing that line to something like this return axios.delete(endpoint, { data: Object.assign(bucket_config, {slug: params.slug}) })
deleting was working. Probably it would also work if bucket slug is removed from config before adding it to data.
bucket.getObjectsByType is returning a 404. The issue is with the api end-point. Latest commit replaces 'object-type' with 'objects-type' in the end-point. The former url 'https://api.cosmicjs.com/v1/{ bucket-slug }/object-type/{ object type }' is working properly.
Hello,
I'm using Nuxt 3 (SSR) with Cosmic.JS and getting the following error:
Here is my plugin I created unter plugins/cosmic.ts
:
import Cosmic from 'cosmicjs'
const api = Cosmic();
const bucket = api.bucket({
slug: process.env.COSMIC_JS_BUCKET_SLUG,
read_key: process.env.COSMIC_JS_READ_KEY,
});
export default defineNuxtPlugin(() => ({
provide: {
cosmic: bucket
}
}));
Maybe it's necessary to check if "process.env" is existing?
Hi,
Are there plans for extending this API for interacting with the /search
endpoint? It currently looks like the getObjectType
interface does not support this case.
Hi, I have been trying to run your examples and I am not retrieving any data back to console.log out. It seems to never hit the callback... any ideas?
Update: Looks like its somewhere in the fetch(endpoint)
call.
Hello,
I was using 4.1 for almost 2 years ago, and my site started to crash last week, debugging my code I realized we stopped getting some of the nested data as we were expecting, I suppose there was a change in the cosmicjs api, I have a structure of nested objects in cosmic, something like this pages -> sections -> videos
, the reason why my site started to crash is because of the data of the last object in my nesting chain was different, I was expecting an object with the whole data, instead of that, I was getting a string with just the id.
Before
{
// rest of the page data,
metadata: {
sections: [
{
// rest of the object's metadata,
video: {
// whole video's metadata
}
}
]
}
}
Before
{
// rest of the page data,
metadata: {
sections: [
{
// rest of the object's metadata,
video: '60d10806dd65e129d4f2870b' // just a single string
}
]
}
}
I updated the package to the latest version and I kept having this issue, this article says there are no breaking changes https://www.cosmicjs.com/changelog/npm-module-updates-v4-2, however, I had to change the implementation from bucket.getObjects
to bucket.objects.find
with the new specification, only after that, it worked as before again
In the docs there is a sort
property for getObjects
but it looks like that's missing in the source code.
After adding
if (params && params.sort) {
endpoint += `&sort=${params.sort}`
}
it's working.
Is this missing or can I do sorting differently?
I can add these lines to be consistent with the docs.
Source: https://www.npmjs.com/advisories/1594
Overview
The axios NPM package before 0.21.1 contains a Server-Side Request Forgery (SSRF) vulnerability where an attacker is able to bypass a proxy by providing a URL that responds with a redirect to a restricted host or IP address.
Remediation
Upgrade to 0.21.1 or later.
When I make the request to get a collection of media in a specific folder, it is returning all the most recent media for my current filter. Looking at the request, folder is not added to the query.
Is this functionality missing, or is there another way to get media folders returned?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.