-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init soap obiz client in trpc context and begin order router
- Loading branch information
Showing
6 changed files
with
234 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createTRPCRouter, userProtectedProcedure } from "~/server/api/trpc"; | ||
|
||
export const orderRouter = createTRPCRouter({ | ||
createOrder: userProtectedProcedure.query(async ({ ctx }) => { | ||
// const [test] = await ctx.soapObizClient.ETAT_SITEAsync(); | ||
|
||
// console.log(JSON.stringify(test, null, 2)); | ||
|
||
return { data: "Hello" }; | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { IOptions } from "soap"; | ||
|
||
export const obiz_soap_client_url = | ||
"https://webservices-test.reducce.fr/Partenaire.svc?wsdl"; | ||
|
||
function parseMultipartResponse(data: string) { | ||
// Find the XML content between the MIME boundaries | ||
const xmlMatch = data.match(/<s:Envelope[\s\S]*?<\/s:Envelope>/); | ||
if (xmlMatch) { | ||
return xmlMatch[0]; | ||
} | ||
throw new Error("No SOAP envelope found in response"); | ||
} | ||
|
||
export const obiz_soap_client_options: IOptions = { | ||
forceSoap12Headers: false, | ||
endpoint: "https://webservices-test.reducce.fr/Partenaire.svc/Partenaire.svc", | ||
httpClient: { | ||
request: function ( | ||
url: string, | ||
data: string, | ||
callback: any, | ||
exheaders: any | ||
): any { | ||
const headers = { | ||
"Content-Type": "text/xml;charset=utf-8", | ||
Accept: "multipart/related,text/xml", | ||
...exheaders, | ||
}; | ||
|
||
const options = { | ||
url: url, | ||
method: data ? "POST" : "GET", | ||
headers: headers, | ||
data: data, | ||
responseType: "text", | ||
}; | ||
|
||
require("axios")(options) | ||
.then((response: any) => { | ||
if (response.headers["content-type"]?.includes("multipart/related")) { | ||
// Parse multipart response to get just the SOAP envelope | ||
const xmlContent = parseMultipartResponse(response.data); | ||
response.data = xmlContent; | ||
} | ||
callback(null, response, response.data); | ||
}) | ||
.catch((error: any) => callback(error)); | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.