Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Serializer, Deserializer, Error } from "jsonapi-serializer";
declare let firstName: string;
declare let lastName: string;
const UserSerializer = new Serializer("users", {
id: "id",
attributes: ["firstName", "lastName"],
keyForAttribute: "camelCase",
pluralizeType: false
});
const users = UserSerializer.serialize({ firstName, lastName });
const UserDeserializer = new Deserializer({
id: "id",
keyForAttribute: "camelCase",
pluralizeType: false,
typeAsAttribute: true
});
UserDeserializer.deserialize(users);
if (Array.isArray(data)) {
data.forEach(item => _.assign(item, { [key]: '****' }));
} else {
_.assign(data, { [key]: '****' });
}
schema[key] = {
ref: function(object) {
return object._id;
},
};
});
}
var serializer = new JSONAPISerializer(type, schema);
return serializer.serialize(data);
};
function IntercomAttributesSerializer(attributes, collectionName, meta) {
const type = `${collectionName}_intercom_attributes`;
return new JSONAPISerializer(type, attributes, {
attributes: ['session_count', 'last_seen_ip', 'created_at', 'updated_at',
'signed_up_at', 'last_request_at', 'country', 'city', 'user_agent',
'companies', 'segments', 'tags', 'browser', 'platform', 'geoloc'],
keyForAttribute(key) { return key; },
meta,
});
}
if (invoice.period_start) {
invoice.period_start = new Date(invoice.period_start * 1000);
}
if (invoice.period_end) {
invoice.period_end = new Date(invoice.period_end * 1000);
}
if (invoice.subtotal) { invoice.subtotal /= 100; }
if (invoice.total) { invoice.total /= 100; }
return invoice;
});
return new JSONAPISerializer('stripe-invoices', invoices, {
attributes: ['amount_due', 'attempt_count', 'attempted', 'closed',
'currency', 'date', 'forgiven', 'paid', 'period_start', 'period_end',
'subtotal', 'total', 'application_fee', 'tax', 'tax_percent',
'customer'],
customer: {
ref: 'id',
attributes: customerAttributes
},
keyForAttribute: function (key) {
return Inflector.underscore(key);
},
typeForAttribute: function (attr) {
if (attr === 'customer') { return customerCollectionName; }
return attr;
},
meta: meta
}
var serializationOptions = {
attributes: _.map(schema.fields, 'field'),
keyForAttribute: function (key) {
return key;
},
typeForAttribute: function (attribute) {
return typeForAttributes[attribute] || attribute;
},
meta: meta
};
getAttributesFor(serializationOptions, schema.fields);
return new JSONAPISerializer(schema.name, records,
serializationOptions);
};
}
ctx.serializer = (type, opts) => {
return new Serializer(type, opts);
};
this.serialize = function () {
return new JSONAPISerializer("rule", {
keyForAttribute: "underscore_case",
attributes: ["name", "user_id", "id", "rule", "active", "meta"],
rule: {
attributes: ["conditions", "event", "priority"],
},
topLevelLinks : {
parent : sprintf("%s/v%s/rules", baseUrl_https, version),
self : rule.pageSelf!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageSelf, rule.size):undefined,
first : rule.pageFirst!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageFirst, rule.size):undefined,
prev : rule.pagePrev!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pagePrev, rule.size):undefined,
last : rule.pageLast!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageLast, rule.size):undefined,
next : rule.pageNext!==undefined?sprintf("%s/v%s/rules/?page=%s&size=%s", baseUrl_https, version, rule.pageNext, rule.size):undefined,
},
dataLinks : {
self : function(rule) {
return sprintf("%s/v%s/rules/%s", baseUrl_https, version, rule.id);
.then(() => new JSONAPISerializer(schema.name, records, serializationOptions));
};
this.serialize = function () {
return new JSONAPISerializer("snippet", {
keyForAttribute: "underscore_case",
attributes: ["name", "user_id", "description", "type", "icon", "color", "flows", "meta"],
topLevelLinks : {
parent : sprintf("%s/v%s/snippets", baseUrl_https, version),
self : snippet.pageSelf!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageSelf, snippet.size):undefined,
first : snippet.pageFirst!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageFirst, snippet.size):undefined,
prev : snippet.pagePrev!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pagePrev, snippet.size):undefined,
last : snippet.pageLast!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageLast, snippet.size):undefined,
next : snippet.pageNext!==undefined?sprintf("%s/v%s/snippets/?page=%s&size=%s", baseUrl_https, version, snippet.pageNext, snippet.size):undefined,
},
dataLinks : {
self : function(snippet) {
return sprintf("%s/v%s/snippets/%s", baseUrl_https, version, snippet.id);
},
user : function(snippet) {
if ( snippet.user_id!="" ) {