ordercloud-api / ordercloud-javascript-sdk Goto Github PK
View Code? Open in Web Editor NEWThe official Javascript SDK for the OrderCloud eCommerce platform
License: MIT License
The official Javascript SDK for the OrderCloud eCommerce platform
License: MIT License
This is a browser-bug only and was introduced by this commit
This was a bug-fix for the response body not being correctly parsed in nodejs. I added a custom json parser but was not aware that some of the functionality was only available in the node environment (buffer for example). Since the fix here was for a nodejs only bug we can safely add a switch to only transform the request while in node
Custom roles was added as an optional parameter on auth calls. Ideally this would have been added to the requestOptions object so that adding new optional parameters isn't a breaking change. Its not worth making the change right now, but consider updating it for the next breaking change
Steps to reproduce...
Me.ListOrders({ filters: { IsSubmitted: false } })
Expected result:
Query is constructed with ?IsSubmitted=false
Actual result:
Filter is not present on resulting query.
Workaround:
Pass a string as the filter value.
Me.ListOrders({ filters: { IsSubmitted: "False" } })
It's workable but feels bad. The params serializer drops falsey values from params, which is problematic in this case.
Its currently:
Array<SecurityProfile['Roles']> | SecurityProfile['Roles']
This amounts to either:
It should really be either an array of roles or a single role because if there is just one role then the JWT token just includes it as a string. And really since custom roles have been introduced to security profiles we should probably not limit the type to ApiRole and instead allow either a string[] or string
I see there are response models for the OrderCheckout integration type, such as models OrderCalculateResponse and ShipEstimateResponse.
It may be helpful to also include the request object types, CalculateOrderPayload, etc.
Similarly to cover the OpenIDConnect type models:
OpenIDConnectIntegrationEvent
CreateUserResponse
SyncUserResponse
Models Reference: https://ordercloud.io/knowledge-base/sso-via-openid-connect
This would support leveraging the nextJs api routes as the middleware and consolidate the definitions across tools and implementations. There is already a type created in the catalyst project that may be better added to this project. (https://github.com/ordercloud-api/ordercloud-javascript-catalyst/blob/main/lib/Types/OrderCalculatePayload.ts)
Cheers
If you pass a filter to a list call where the value is zero then it is dropped. For example:
Products.List({ filters: { SpecCount: 0 } })
The above will list products without the SpecCount=0 filter applied. This is related to #66
Leave the default bower package the same so that it continues to generate from "production"
We'll need another branch for the "staging" API updates so that we can migrate from the old SDK & update for the BBC separately. (old sdk -> new will occur first, BBC updates afterwards)
README.md instructions are outdated. Please fix that.
Now:
npm install OrderCloud --save
I think it should be something like (according with my npm search!):
npm install ordercloud-js-sdk --save
When using the ordercloud-javascript-sdk if there's an error, the response that contains the error message seems to contain a character that causes JSON.parse to fail internally in ordercloud. Here's an example:
SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at IncomingMessage.<anonymous> (.../node_modules/superagent/lib/node/parsers/json.js:11:35)
at IncomingMessage.emit (events.js:208:15)
at endReadableNT (_stream_readable.js:1168:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
rawResponse: '{"Errors":[{"ErrorCode":"NotAuthorized","Message":"","Data":null}]}',
statusCode: 403,
response: undefined
}
Pasting what's on rawResponse to a text editor reveals the issue:
Please change the global OrderCloud variable to OrderCloudSDK
This will prevent naming conflicts during the migration period when people are using both the old angular-sdk and the new js-sdk at the same time.
When using this SDK in an angular controller, my response body comes back into the .then() just fine where I can log it to my console; however, if I attempt to set the response body data to a variable in my controller the angular scope is not updated.
vm.search = function() {
OrderCloud.Buyers.List(vm.parameters)
.then(function(data) {
console.log(data) // this logs to the console okay, but has that weird "exports" thing
vm.result = data; // vm.result is not updated
})
}
I believe there must be some difference in how promises are handled in angular vs. raw javascript.
Interesting side note, I do not have this problem when using the new SDK in a ui-router resolve - the data populates into the controller just fine in this case.
Hello, updated ordercloud-javascript-sdk from 4.10.1 to 5.0.6 and got this error. Any ideas how to fix it?
paramsSerializer is not a function
[dev:*theme]
[dev:*theme] at buildURL (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/axios/lib/helpers/buildURL.js:30:24)
[dev:*theme] at dispatchHttpRequest (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/axios/lib/adapters/http.js:136:13)
[dev:*theme] at new Promise ()
[dev:*theme] at httpAdapter (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/axios/lib/adapters/http.js:48:10)
[dev:*theme] at dispatchRequest (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/axios/lib/core/dispatchRequest.js:58:10)
[dev:*theme] at Axios.request (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/axios/lib/core/Axios.js:108:15)
[dev:*theme] at Axios. [as get] (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/axios/lib/core/Axios.js:129:17)
[dev:*theme] at Function.wrap [as get] (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/axios/lib/helpers/bind.js:9:15)
[dev:*theme] at HttpClient. (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/ordercloud-javascript-sdk/dist/index.js:901:61)
[dev:*theme] at step (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/ordercloud-javascript-sdk/dist/index.js:80:23)
[dev:*theme] at Object.next (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/ordercloud-javascript-sdk/dist/index.js:61:53)
[dev:*theme] at fulfilled (/Users/pavel/WebstormProjects/Work/vsf-ordefcloud/VueStorefront.Ordercloud/node_modules/ordercloud-javascript-sdk/dist/index.js:51:58)
[dev:*theme] at runMicrotasks ()
[dev:*theme] at processTicksAndRejections (node:internal/process/task_queues:96:5)
Tested out using postman and confirmed this isn't just the staging API. When using the SDK in an angular context I am receiving response bodies like the one below:
{
"SecurityProfileID": "AU",
"BuyerID": "null",
"UserGroupID": "null",
"UserID": "null"
}
This is a minor enhancement idea. If you look at models in the C# SDK, type parameters are handled slightly better (IMHO). OrderWorksheet is a good comparison because its so complex
public class OrderWorksheet<TOrder, TLineItems, TOrderPromotions, TShipEstimateResponse, TOrderCalculateResponse, TOrderSubmitResponse, TOrderSubmitForApprovalResponse, TOrderApprovedResponse> : OrderWorksheet
where TOrder : Order
where TLineItems : LineItem
where TOrderPromotions : OrderPromotion
where TShipEstimateResponse : ShipEstimateResponse
where TOrderCalculateResponse : OrderCalculateResponse
where TOrderSubmitResponse : OrderSubmitResponse
where TOrderSubmitForApprovalResponse : OrderSubmitForApprovalResponse
where TOrderApprovedResponse : OrderApprovedResponse
{
....
}
export interface OrderWorksheet<TFromUserXp = any, TBillingAddressXp = any, TOrderXp = any, TProductXp = any, TVariantXp = any, TShippingAddressXp = any, TShipFromAddressXp = any, TLineItemsXp = any, TOrderPromotionsXp = any, TShipEstimatesXp = any, TShipEstimateResponseXp = any, TOrderCalculateResponseXp = any, TOrderSubmitResponseXp = any, TOrderSubmitForApprovalResponseXp = any, TOrderApprovedResponseXp = any> {
Order?: Order<TOrderXp,TFromUserXp,TBillingAddressXp>
LineItems?: LineItem<TLineItemsXp,TProductXp,TVariantXp,TShippingAddressXp,TShipFromAddressXp>[]
OrderPromotions?: OrderPromotion<TOrderPromotionsXp>[]
ShipEstimateResponse?: ShipEstimateResponse<TShipEstimateResponseXp,TShipEstimatesXp>
OrderCalculateResponse?: OrderCalculateResponse<TOrderCalculateResponseXp>
OrderSubmitResponse?: OrderSubmitResponse<TOrderSubmitResponseXp>
OrderSubmitForApprovalResponse?: OrderSubmitForApprovalResponse<TOrderSubmitForApprovalResponseXp>
OrderApprovedResponse?: OrderApprovedResponse<TOrderApprovedResponseXp>
}
In the C# sdk types are expected that extend the SDK models like Order and LineItem. In the JS sdk types are expected that hold the xp fields. This means there are more type arguments. The C# method is less verbose in the sdk code and in the client project code.
It also does require the creation of models like interface MyOrderPromotion extends OrderPromotion<MyOrderPromotionsXp> { }
The refresh request happens as expected but the token is never saved which causes subsequent requests to always require retrieving the token first which is inefficient. The token should be cached for future requests
Link https://ordercloud-api.github.io/OrderCloud-JavaScript-SDK not working in README. Where is the API documentation?
i am using headstart-sdk to connect with middleware API, by default it's getting have the base api url as 'https://marketplace-api-qa.azurewebsites.net'
how can change this baseAPiUrl to my own middleware? .
import { HeadStartSDK, Configuration } from '@ordercloud/headstart-sdk';
HeadStartSDK.Tokens.SetAccessToken(token ? token : "");
Configuration.Set({
baseApiUrl: 'https://xyz.azurewebsites.net/',
baseAuthUrl:'https://xyz-sandbox.ordercloud.io'
});
are we have any other option to set?
The API no longer returns AuthError type, instead it just leverages the ApiError type. This is a minor change that is breaking, so it should be release along another breaking change.
Hi, i am using ordercloude javascript sdk for Auth.Login, and save the token 'Tokens.SetAccessToken(token)'.
Following are my query
When using OrderCloudSDK.Me.Get()
after the API release v1.0.54 I was expecting to see the buyer sub object on the response. I think you'll just have to regenerate the SDK for this to start working (probably just move the current tag to the new version so people don't have to update?)
Extra: Upon publishing of the release, we could have another action that triggers the publishing to npm, on the publish of the release.
Example: Products.Patch
If you attempt to partially update Product.Inventory you will get a typing error that the Inventory is missing fields.
Just noticed that this version introduced a bug in the /src/index.js
file (that is the main file listed in package.json).
The parameter ApiClient
is listed twice in the formal argument list.
This should be related with the new OC API concept of API Client that was just introduced.
/.../node_modules/ordercloud-javascript-sdk/src/index.js:22
}(function(ApiClient, AccessToken, Address, AddressAssignment, ApiClient, ApiClientAssignment, ApprovalRule, Buyer, BuyerAddress, BuyerCreditCard, BuyerProduct, BuyerSpec, Catalog, CatalogAssignment, Category, CategoryAssignment, CategoryProductAssignment, CostCenter, CostCenterAssignment, CreditCard, CreditCardAssignment, ImpersonateTokenRequest, ImpersonationConfig, Incrementor, Inventory, LineItem, LineItemProduct, LineItemSpec, ListAddress, ListAddressAssignment, ListApiClient, ListApiClientAssignment, ListApprovalRule, ListBuyer, ListBuyerAddress, ListBuyerCreditCard, ListBuyerProduct, ListBuyerSpec, ListCatalog, ListCatalogAssignment, ListCategory, ListCategoryAssignment, ListCategoryProductAssignment, ListCostCenter, ListCostCenterAssignment, ListCreditCard, ListCreditCardAssignment, ListFacet, ListFacetValue, ListImpersonationConfig, ListIncrementor, ListLineItem, ListMess
SyntaxError: Duplicate parameter name not allowed in this context
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/somefile.js:2:18)
*** NODEMON CRASHED ***
Refresh Token should be included as a property of the access token model so that we can store it for the remember me functionality.
@crhistianramirez Can you apply this fix to the Auth API? https://github.com/ordercloud-api/OrderCloud-JavaScript-SDK/blob/837a3952a2c7e5c5cdb0434b5e1a3b5a2ed23812/src/Sdk.js#L84
Originally posted by @cguedes in #40 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.