File: /var/www/vhosts/app.ett-stag.2amigos.us/docroot/src/utils/jsonApiConfig.js
import JsonApi from "devour-client";
import config from "../config.json";
let app_url = process.env.REACT_APP_APP_API_URL;
if (!app_url) {
app_url = config.jsonapi_base_url;
}
export const jsonApiInit = (access_token) => {
const jsonApi = new JsonApi({ apiUrl: app_url });
jsonApi.define("person", JsonConfig.people);
jsonApi.define("email", JsonConfig.email);
jsonApi.define("phone", JsonConfig.phone);
jsonApi.define("social-network", JsonConfig.social_network);
jsonApi.define("address", JsonConfig.addresses);
jsonApi.define("addresses", JsonConfig.addresses);
jsonApi.define("url", JsonConfig.url);
jsonApi.define("listing", JsonConfig.listing);
jsonApi.define("user", JsonConfig.user);
jsonApi.define("wallet", JsonConfig.wallet);
jsonApi.define("deposit", JsonConfig.deposit);
jsonApi.define("invoice", JsonConfig.invoice);
jsonApi.define("country", JsonConfig.country);
jsonApi.define("payment-method", JsonConfig.payment_method);
jsonApi.define("message", JsonConfig.message);
jsonApi.define("virtual-phone", JsonConfig.virtual_phones);
jsonApi.define("outbound-message", JsonConfig.outbound_message);
jsonApi.define("transaction", JsonConfig.transaction);
jsonApi.headers["Authorization"] = `Bearer ${access_token}`;
jsonApi.headers["Accept"] = "application/vnd.api+json";
jsonApi.headers["Content-Type"] = "application/vnd.api+json";
//This middleware removes the property 'id' from 'attributes' in the request. This is necesary to validate the request server side
let requestMiddleware = {
name: "remove-id-from-atrributes",
req: (payload) => {
if (payload.req.method === "PATCH") {
delete payload.req.data.data.attributes.id;
}
return payload;
},
};
jsonApi.insertMiddlewareBefore("axios-request", requestMiddleware);
return jsonApi;
};
export const JsonConfig = {
user: {
type: "",
id: "",
name: "",
email: "",
cardBrand: "",
status: "",
cardLastFour: "",
avatar: "",
password: "",
password_confirmation: "",
createdAt: "",
updatedAt: "",
profile: {
jsonApi: "hasOne",
type: "link",
},
wallet: {
jsonApi: "hasOne",
type: "link",
},
listings: {
jsonApi: "hasMany",
type: "listings",
},
people: {
jsonApi: "hasMany",
type: "people",
},
organizations: {
jsonApi: "hasMany",
type: "people",
},
paymentMethods: {
jsonApi: "hasMany",
type: "paymentMethods",
},
},
wallet: {
id: "",
balance: "",
autoTopUp: "",
topUpAmount: "",
createdAt: "",
updatedAt: "",
},
deposit: {
id: "",
amount: "",
invoice_id: "",
currency: "",
status: "",
createdAt: "",
},
invoice: {
id: "",
receiptId: "",
amount: "",
currency: "",
cardLastFour: "",
cardBrand: "",
description: "",
createdAt: "",
},
profile: {
avatar: "",
fullName: "",
phone: "",
createdAt: "",
updatedAt: "",
},
listing: {
title: "",
description: "",
createdAt: "",
updatedAt: "",
status: "",
person: {
jsonApi: "hasMany",
type: "person",
},
people: {
jsonApi: "hasMany",
type: "person",
},
user: {
jsonApi: "hasMany",
type: "user",
},
},
people: {
title: "",
fullName: "",
avatar: "",
dob: "",
gender: "",
bio: "",
meta: "",
gdpr: "",
ssNumber: "",
passportNumber: "",
nidNumber: "",
status: "",
verified: "",
createdAt: "",
updatedAt: "",
listings: { jsonApi: "hasMany", type: "listing" },
organizations: { jsonApi: "hasMany" },
addresses: { jsonApi: "hasMany", type: "addresses" },
emails: { jsonApi: "hasMany", type: "emails" },
phones: { jsonApi: "hasMany" },
urls: { jsonApi: "hasMany", type: "url" },
phone_number: "",
"social-networks": { jsonApi: "hasMany", type: "social-network" },
"full-name": "",
"ss-number": "",
"nid-number": "",
"passport-number": "",
},
virtual_phones: {
id: "",
phone_sid: "",
address_sid: "",
number: "",
status: "",
endsAt: "",
incomingMessages: { jsonApi: "hasMany", type: "incomingMessages" },
outboundMessages: { jsonApi: "hasMany", type: "outboundMessages" },
createdAt: "",
updatedAt: "",
},
virtual_phone_twilio: {
friendlyName: "",
phoneNumber: "",
number: "",
lata: "",
locality: "",
rateCenter: "",
latitude: "",
longitude: "",
region: "",
postalCode: "",
isoCountry: "",
addressRequirements: "",
beta: "",
capabilities: "",
},
email: {
user_id: "",
person_id: "",
"person-id": "",
account: "",
confirmed: "",
optIn: "",
verified: "",
createdAt: "",
updatedAt: "",
person: {
jsonApi: "hasMany",
},
},
phone: {
user_id: "",
person_id: "",
"person-id": "",
p_type: "",
type_def: "",
number: "",
isDefault: "",
"is-default": "",
optIn: "",
person: { jsonApi: "hasOne", type: "person" },
verified: "",
createdAt: "",
updatedAt: "",
},
social_network: {
user_id: "",
profile: "",
provider: "",
code: "",
data: "",
optIn: "",
person: { jsonApi: "hasOne", type: "person" },
organization: { jsonApi: "hasOne" },
createdAt: "",
updatedAt: "",
},
url: {
user_id: "",
url: "",
urlType: "",
"url-type": "",
person: { jsonApi: "hasOne", type: "person" },
organization: { jsonApi: "hasOne" },
createdAt: "",
updatedAt: "",
},
addresses: {
street: "",
city: "",
"postal-code": "",
"country-id": "",
latitude: "",
longitude: "",
verified: "",
person: { jsonApi: "hasOne", type: "person" },
organization: { jsonApi: "hasOne" },
country: { jsonApi: "hasOne", type: "country" },
createdAt: "",
updatedAt: "",
},
payment_method: {
number: "",
exp_month: "",
exp_year: "",
cvc: "",
card_brand: "",
provider: "",
default: "",
is_default: "",
card_last_four: "",
createdAt: "",
updatedAt: "",
},
country: {
name: "",
fullName: "",
countryCode: "",
currency: "",
currencyCode: "",
callingCode: "",
flag: "",
iso_3166_2: ''
},
message: {
gateway: "",
content: "",
recipients: {},
status: "",
cost: "",
"scheduled-at": "",
files: [],
outboundMessages: { jsonApi: "hasMany", type: "outboundMessages" },
createdAt: "",
updatedAt: "",
},
outbound_message: {
id: "",
message_id: "",
phone_id: "",
message_sid: "",
account_sid: "",
to: "",
response: "",
status: "",
createdAt: "",
updatedAt: "",
},
transaction: {
amount: "",
transactionType: "",
message_id: "",
messageId: "",
invoiceId: "",
wallet: { jsonApi: "hasOne", type: "wallet" },
createdAt: "",
updatedAt: "",
},
};