Skip to content

Commit

Permalink
feat: update fetch options
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMunizOdoo committed May 16, 2024
1 parent 96d2237 commit 6d09459
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 20 deletions.
10 changes: 4 additions & 6 deletions packages/sdk-api-client/__mocks__/context.mock.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import buildClient from '../src/setup/clientSetup';
import { MiddlewareConfig } from '../src/types';


const apolloClient = buildClient({
odooGraphqlUrl: 'http://localhost:5000/api/graphql',
fetchOptions: {}
});


export const contextMock = {
config: {
config: {
queries: {

}
} as MiddlewareConfig,
client: apolloClient,
api: jest.fn() as any,
api: jest.fn() as any

};
8 changes: 5 additions & 3 deletions packages/sdk-api-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erpgap/odoo-sdk-api-client",
"version": "0.6.0",
"version": "0.7.0",
"private": false,
"sideEffects": false,
"server": "server/index.js",
Expand All @@ -22,11 +22,13 @@
"lint": "eslint . --ext .ts,.vue"
},
"dependencies": {
"@apollo/client": "^3.7.16",
"@apollo/client": "^3.9.9",
"@vue-storefront/middleware": "3.5.1",
"axios": "^0.21.1",
"consola": "^3.0.0",
"cross-fetch": "^4.0.0",
"https-proxy-agent": "^7.0.4",
"node-fetch": "^3.3.2",
"request-ip": "^3.3.0",
"winston": "^3.9.0"
},
Expand All @@ -43,4 +45,4 @@
"publishConfig": {
"access": "public"
}
}
}
2 changes: 2 additions & 0 deletions packages/sdk-api-client/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { DocumentNode } from '@apollo/client';
*/
export interface MiddlewareConfig {
odooGraphqlUrl: string;
proxy?: string;
fetchOptions?: any;
fetch?: any;
headers?: Record<string, string>
queries?: Record<string, DocumentNode>

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erpgap/odoo-sdk",
"version": "0.6.0",
"version": "0.7.0",
"private": false,
"main": "lib/index.cjs.js",
"module": "lib/index.es.js",
Expand Down Expand Up @@ -41,4 +41,4 @@
"publishConfig": {
"access": "public"
}
}
}
6 changes: 3 additions & 3 deletions packages/sdk/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
const axiosInstance = axios.create()
axiosInstance.defaults.withCredentials = true
const axiosInstance = axios.create();
axiosInstance.defaults.withCredentials = true;

export const client = axiosInstance;
export const client = axiosInstance;
6 changes: 3 additions & 3 deletions packages/sdk/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ export const odooConnector = (options: Options): Methods => {

if (options.ofetch) {
mutation = async <ApiParams, ApiResponseType>(metadata: MutationMetadataParams, params?: ApiParams): Promise<ApiResponseType> => {
return await options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache' });
return await options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache', ...options.ofetchOptions });
};

query = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> =>{
const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params });
return await options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey } as any);
return await options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey, ...options.ofetchOptions } as any);
};

queryNoCache = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> =>{
const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params });
return await options.ofetch('/api/odoo/query-no-cache', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey } as any);
return await options.ofetch('/api/odoo/query-no-cache', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey, ...options.ofetchOptions } as any);
};
}

Expand Down
9 changes: 6 additions & 3 deletions packages/sdk/src/types/options.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { AxiosInstance } from "axios";
import { $Fetch } from "ofetch";
import { AxiosInstance } from 'axios';
import { $Fetch, FetchOptions } from 'ofetch';

/** Options for the SDK module */
export interface Options {

/** The API URL of the client-side environment */
apiUrl: string;

/** Custom fetch instance */
ofetch?: $Fetch;
}
ofetchOptions?: FetchOptions;
}
96 changes: 96 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@
tslib "^2.3.0"
zen-observable-ts "^1.2.5"

"@apollo/client@^3.9.9":
version "3.9.9"
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.9.9.tgz#38f983a1ad24e2687abfced0a9c1c3bef8d32616"
integrity sha512-/sMecU/M0WK9knrguts1lSLV8xFKzIgOMVb4mi6MOxgJXjliDB8PvOtmXhTqh2cVMMR4TzXgOnb+af/690zlQw==
dependencies:
"@graphql-typed-document-node/core" "^3.1.1"
"@wry/caches" "^1.0.0"
"@wry/equality" "^0.5.6"
"@wry/trie" "^0.5.0"
graphql-tag "^2.12.6"
hoist-non-react-statics "^3.3.2"
optimism "^0.18.0"
prop-types "^15.7.2"
rehackt "0.0.6"
response-iterator "^0.2.6"
symbol-observable "^4.0.0"
ts-invariant "^0.10.3"
tslib "^2.3.0"
zen-observable-ts "^1.2.5"

"@ardatan/relay-compiler@12.0.0":
version "12.0.0"
resolved "https://registry.yarnpkg.com/@ardatan/relay-compiler/-/relay-compiler-12.0.0.tgz#2e4cca43088e807adc63450e8cab037020e91106"
Expand Down Expand Up @@ -4851,6 +4871,13 @@
fast-url-parser "^1.1.3"
tslib "^2.3.1"

"@wry/caches@^1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@wry/caches/-/caches-1.0.1.tgz#8641fd3b6e09230b86ce8b93558d44cf1ece7e52"
integrity sha512-bXuaUNLVVkD20wcGBWRyo7j9N3TxePEWFZj2Y+r9OoUzfqmavM84+mFykRicNsBqatba5JLay1t48wxaXaWnlA==
dependencies:
tslib "^2.3.0"

"@wry/context@^0.7.0", "@wry/context@^0.7.3":
version "0.7.3"
resolved "https://registry.yarnpkg.com/@wry/context/-/context-0.7.3.tgz#240f6dfd4db5ef54f81f6597f6714e58d4f476a1"
Expand All @@ -4872,6 +4899,13 @@
dependencies:
tslib "^2.3.0"

"@wry/trie@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@wry/trie/-/trie-0.5.0.tgz#11e783f3a53f6e4cd1d42d2d1323f5bc3fa99c94"
integrity sha512-FNoYzHawTMk/6KMQoEG5O4PuioX19UbwdQKF44yw0nLfOypfQdjtfZzo/UIJWAJ23sNIFbD1Ug9lbaDGMwbqQA==
dependencies:
tslib "^2.3.0"

"@xmldom/xmldom@^0.8.3":
version "0.8.10"
resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.8.10.tgz#a1337ca426aa61cef9fe15b5b28e340a72f6fa99"
Expand Down Expand Up @@ -7172,6 +7206,11 @@ dargs@^7.0.0:
resolved "https://registry.yarnpkg.com/dargs/-/dargs-7.0.0.tgz#04015c41de0bcb69ec84050f3d9be0caf8d6d5cc"
integrity sha512-2iy1EkLdlBzQGvbweYRFxmFath8+K7+AKB0TlhHWkNuH+TmovaMH/Wp7V7R4u7f4SnX3OgLsU9t1NI9ioDnUpg==

data-uri-to-buffer@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e"
integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==

data-urls@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-2.0.0.tgz#156485a72963a970f5d5821aaf642bef2bf2db9b"
Expand Down Expand Up @@ -8479,6 +8518,14 @@ fecha@^4.2.0:
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.3.tgz#4d9ccdbc61e8629b259fdca67e65891448d569fd"
integrity sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==

fetch-blob@^3.1.2, fetch-blob@^3.1.4:
version "3.2.0"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9"
integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==
dependencies:
node-domexception "^1.0.0"
web-streams-polyfill "^3.0.3"

figures@3.2.0, figures@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af"
Expand Down Expand Up @@ -8701,6 +8748,13 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

formdata-polyfill@^4.0.10:
version "4.0.10"
resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
dependencies:
fetch-blob "^3.1.2"

formidable@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-2.1.2.tgz#fa973a2bec150e4ce7cac15589d7a25fc30ebd89"
Expand Down Expand Up @@ -9631,6 +9685,14 @@ https-proxy-agent@^7.0.0, https-proxy-agent@^7.0.1, https-proxy-agent@^7.0.2:
agent-base "^7.0.2"
debug "4"

https-proxy-agent@^7.0.4:
version "7.0.4"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz#8e97b841a029ad8ddc8731f26595bad868cb4168"
integrity sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==
dependencies:
agent-base "^7.0.2"
debug "4"

httpxy@^0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/httpxy/-/httpxy-0.1.5.tgz#fd2401206e0b5d919aeda25e967ece0f1a6c8569"
Expand Down Expand Up @@ -12715,6 +12777,11 @@ node-addon-api@^7.0.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.0.0.tgz#8136add2f510997b3b94814f4af1cce0b0e3962e"
integrity sha512-vgbBJTS4m5/KkE16t5Ly0WW9hz46swAstv0hYYwMtbG7AznRhNyfLRe8HZAiWIpcHzoO7HxhLuBQj9rJ/Ho0ZA==

node-domexception@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==

node-fetch-native@^0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/node-fetch-native/-/node-fetch-native-0.1.8.tgz#19e2eaf6d86ac14e711ebd2612f40517c3468f2a"
Expand All @@ -12739,6 +12806,15 @@ node-fetch@^2.5.0, node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-fetch@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.2.tgz#d1e889bacdf733b4ff3b2b243eb7a12866a0b78b"
integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==
dependencies:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.4"
formdata-polyfill "^4.0.10"

node-forge@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
Expand Down Expand Up @@ -13506,6 +13582,16 @@ optimism@^0.17.5:
"@wry/trie" "^0.4.3"
tslib "^2.3.0"

optimism@^0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.18.0.tgz#e7bb38b24715f3fdad8a9a7fc18e999144bbfa63"
integrity sha512-tGn8+REwLRNFnb9WmcY5IfpOqeX2kpaYJ1s6Ae3mn12AeydLkR3j+jSCmVQFoXqU8D41PAJ1RG1rCRNWmNZVmQ==
dependencies:
"@wry/caches" "^1.0.0"
"@wry/context" "^0.7.0"
"@wry/trie" "^0.4.3"
tslib "^2.3.0"

optionator@^0.9.3:
version "0.9.3"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.3.tgz#007397d44ed1872fdc6ed31360190f81814e2c64"
Expand Down Expand Up @@ -15008,6 +15094,11 @@ regexp.prototype.flags@^1.5.1:
define-properties "^1.2.0"
set-function-name "^2.0.0"

rehackt@0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/rehackt/-/rehackt-0.0.6.tgz#7a0a2247f2295e7548915417e44fbbf03bf004f4"
integrity sha512-l3WEzkt4ntlEc/IB3/mF6SRgNHA6zfQR7BlGOgBTOmx7IJJXojDASav+NsgXHFjHn+6RmwqsGPFgZpabWpeOdw==

relay-runtime@12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/relay-runtime/-/relay-runtime-12.0.0.tgz#1e039282bdb5e0c1b9a7dc7f6b9a09d4f4ff8237"
Expand Down Expand Up @@ -17612,6 +17703,11 @@ web-encoding@^1.1.5:
optionalDependencies:
"@zxing/text-encoding" "0.9.0"

web-streams-polyfill@^3.0.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz#2073b91a2fdb1fbfbd401e7de0ac9f8214cecb4b"
integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==

web-streams-polyfill@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6"
Expand Down

0 comments on commit 6d09459

Please sign in to comment.