GithubHelp home page GithubHelp logo

ordercloud-api / ordercloud-javascript-sdk Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 15.0 6.13 MB

The official Javascript SDK for the OrderCloud eCommerce platform

License: MIT License

JavaScript 0.21% TypeScript 99.25% Handlebars 0.54%

ordercloud-javascript-sdk's People

Contributors

crhistianramirez avatar dependabot[bot] avatar djsteinmetz avatar erincdustin avatar ewerkman avatar mirandaposthumus avatar oliverheywood451 avatar redeemedfadi avatar robertsoniv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ordercloud-javascript-sdk's Issues

TypeError: m.buffer is not a function

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

Move customRoles into requestOptions object

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

Filters set with falsey values are not passed

Relevant line of Code

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.

Type for DecodedToken.role is incorrect

Its currently:

Array<SecurityProfile['Roles']> | SecurityProfile['Roles']

This amounts to either:

  • An array of array of ordercloud roles OR
  • An array of ordercloud roles

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

OIDC models

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

Filters set with 0 are dropped

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

Create a new "staging" branch for the upcoming BBC staging period.

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)

Update README.md with correct package information

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

Invalid character in error responses' JSON

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:

image

Javascript promises not behaving as expected

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.

paramsSerializer is not a function

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)

<null> values appear as strings in response body

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"
}

Enhancement Idea - Reduce number of generic parameters in models

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> { }

@ordercloud/headstart-sdk

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?

Auth and Token Query

Hi, i am using ordercloude javascript sdk for Auth.Login, and save the token 'Tokens.SetAccessToken(token)'.

Following are my query

  1. How to validate the user is Authenticated or the token is expired?
  2. I am not able to find the option for Logout.

Current user buyer sub object is not available in response body

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?)

Github action for drafting the release

  • Our dotnet SDK uses a github action to draft the release, implement something similar to draft the release so the maintainer only has to open the releases link and publish the release.

Extra: Upon publishing of the release, we could have another action that triggers the publishing to npm, on the publish of the release.

SyntaxError: Duplicate parameter name not allowed in this context

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 ***

https://github.com/ordercloud-api/OrderCloud-JavaScript-SDK/blob/b32b6cbb1285b22973e3e0139ac4350ec25a4aa4/src/index.js#L22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.