@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
1010governing permissions and limitations under the License.
1111*/
1212
13- const { getCommerceOauthClient } = require ( '../oauth1a' )
13+ const { getClient } = require ( '../oauth1a' )
1414const { Core } = require ( '@adobe/aio-sdk' )
1515const logger = Core . Logger ( 'commerce-consumer-api-client' , { level : 'info' } )
1616
@@ -19,20 +19,14 @@ const logger = Core.Logger('commerce-consumer-api-client', { level: 'info' })
1919 *
2020 * @returns {object } - API response object
2121 * @param {string } baseUrl - Adobe commerce rest api base url
22- * @param {string } consumerKey - Adobe commerce integration consumer key
23- * @param {string } consumerSecret - Adobe commerce integration consumer secret
24- * @param {string } accessToken - Adobe commerce integration access token
25- * @param {string } accessTokenSecret - Adobe commerce integration access token secret
22+ * @param {object } params - Environment params from the IO Runtime request
2623 * @param {object } data - Adobe commerce api payload
2724 */
28- async function createCustomer ( baseUrl , consumerKey , consumerSecret , accessToken , accessTokenSecret , data ) {
29- const client = getCommerceOauthClient (
25+ async function createCustomer ( baseUrl , params , data ) {
26+ const client = getClient (
3027 {
3128 url : baseUrl ,
32- consumerKey,
33- consumerSecret,
34- accessToken,
35- accessTokenSecret
29+ params
3630 } ,
3731 logger
3832 )
@@ -50,20 +44,14 @@ async function createCustomer (baseUrl, consumerKey, consumerSecret, accessToken
5044 *
5145 * @returns {object } - API response object
5246 * @param {string } baseUrl - Adobe commerce rest api base url
53- * @param {string } consumerKey - Adobe commerce integration consumer key
54- * @param {string } consumerSecret - Adobe commerce integration consumer secret
55- * @param {string } accessToken - Adobe commerce integration access token
56- * @param {string } accessTokenSecret - Adobe commerce integration access token secret
47+ * @param {object } params - Environment params from the IO Runtime request
5748 * @param {object } data - Adobe commerce api payload
5849 */
59- async function importCustomerBatch ( baseUrl , consumerKey , consumerSecret , accessToken , accessTokenSecret , data ) {
60- const client = getCommerceOauthClient (
50+ async function importCustomerBatch ( baseUrl , params , data ) {
51+ const client = getClient (
6152 {
6253 url : baseUrl ,
63- consumerKey,
64- consumerSecret,
65- accessToken,
66- accessTokenSecret
54+ params
6755 } ,
6856 logger
6957 )
@@ -91,24 +79,17 @@ async function importCustomerBatch (baseUrl, consumerKey, consumerSecret, access
9179 *
9280 * @returns {object } - API response object
9381 * @param {string } baseUrl - Adobe commerce rest api base url
94- * @param {string } consumerKey - Adobe commerce integration consumer key
95- * @param {string } consumerSecret - Adobe commerce integration consumer secret
96- * @param {string } accessToken - Adobe commerce integration access token
97- * @param {string } accessTokenSecret - Adobe commerce integration access token secret
82+ * @param {object } params - Environment params from the IO Runtime request
9883 * @param {object } data - Adobe commerce api payload
9984 */
100- async function updateCustomer ( baseUrl , consumerKey , consumerSecret , accessToken , accessTokenSecret , data ) {
101- const client = getCommerceOauthClient (
85+ async function updateCustomer ( baseUrl , params , data ) {
86+ const client = getClient (
10287 {
10388 url : baseUrl ,
104- consumerKey,
105- consumerSecret,
106- accessToken,
107- accessTokenSecret
89+ params
10890 } ,
10991 logger
11092 )
111-
11293 return await client . put (
11394 `customers/${ data . customer . id } ` ,
11495 JSON . stringify ( data ) ,
@@ -122,20 +103,14 @@ async function updateCustomer (baseUrl, consumerKey, consumerSecret, accessToken
122103 *
123104 * @returns {object } - API response object
124105 * @param {string } baseUrl - Adobe commerce rest api base url
125- * @param {string } consumerKey - Adobe commerce integration consumer key
126- * @param {string } consumerSecret - Adobe commerce integration consumer secret
127- * @param {string } accessToken - Adobe commerce integration access token
128- * @param {string } accessTokenSecret - Adobe commerce integration access token secret
106+ * @param {object } params - Environment params from the IO Runtime request
129107 * @param {number } id - Id
130108 */
131- async function deleteCustomer ( baseUrl , consumerKey , consumerSecret , accessToken , accessTokenSecret , id ) {
132- const client = getCommerceOauthClient (
109+ async function deleteCustomer ( baseUrl , params , id ) {
110+ const client = getClient (
133111 {
134112 url : baseUrl ,
135- consumerKey,
136- consumerSecret,
137- accessToken,
138- accessTokenSecret
113+ params
139114 } ,
140115 logger
141116 )
@@ -147,20 +122,14 @@ async function deleteCustomer (baseUrl, consumerKey, consumerSecret, accessToken
147122 *
148123 * @returns {object } - API response object
149124 * @param {string } baseUrl - Adobe commerce rest api base url
150- * @param {string } consumerKey - Adobe commerce integration consumer key
151- * @param {string } consumerSecret - Adobe commerce integration consumer secret
152- * @param {string } accessToken - Adobe commerce integration access token
153- * @param {string } accessTokenSecret - Adobe commerce integration access token secret
125+ * @param {string } params - Environment params from the IO Runtime request
154126 * @param {object } customerId - Adobe commerce customer ID
155127 */
156- async function getCustomer ( baseUrl , consumerKey , consumerSecret , accessToken , accessTokenSecret , customerId ) {
157- const client = getCommerceOauthClient (
128+ async function getCustomer ( baseUrl , params , customerId ) {
129+ const client = getClient (
158130 {
159131 url : baseUrl ,
160- consumerKey,
161- consumerSecret,
162- accessToken,
163- accessTokenSecret
132+ params
164133 } ,
165134 logger
166135 )
@@ -176,26 +145,17 @@ async function getCustomer (baseUrl, consumerKey, consumerSecret, accessToken, a
176145 *
177146 * @returns {object } - API response object
178147 * @param {string } baseUrl - Adobe commerce rest api base url
179- * @param {string } consumerKey - Adobe commerce integration consumer key
180- * @param {string } consumerSecret - Adobe commerce integration consumer secret
181- * @param {string } accessToken - Adobe commerce integration access token
182- * @param {string } accessTokenSecret - Adobe commerce integration access token secret
148+ * @param {string } params - Environment params from the IO Runtime request
183149 * @param {string } searchCriteria - Adobe commerce search criteria
184150 */
185151async function getCustomerBySearchCriteria (
186152 baseUrl ,
187- consumerKey ,
188- consumerSecret ,
189- accessToken ,
190- accessTokenSecret ,
153+ params ,
191154 searchCriteria ) {
192- const client = getCommerceOauthClient (
155+ const client = getClient (
193156 {
194157 url : baseUrl ,
195- consumerKey,
196- consumerSecret,
197- accessToken,
198- accessTokenSecret
158+ params
199159 } ,
200160 logger
201161 )
@@ -211,7 +171,7 @@ module.exports = {
211171 createCustomer,
212172 updateCustomer,
213173 deleteCustomer,
174+ importCustomerBatch,
214175 getCustomer,
215- getCustomerBySearchCriteria,
216- importCustomerBatch
176+ getCustomerBySearchCriteria
217177}
0 commit comments