Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
feat(accounts): Added AccountAddresses and contact field for orders
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Moved Address endpoint to CustomerAddresss
  • Loading branch information
dr-ep committed Jul 22, 2021
1 parent d5f93c2 commit 32d7bfa
Show file tree
Hide file tree
Showing 29 changed files with 985 additions and 550 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,4 @@ You can learn more about the Rollup API and configuration [here](https://github.

- Any changes to this project must be reviewed and approved by the repository owner. For more information about contributing, see the [Contribution Guide](https://github.com/moltin/gatsby-demo-store/blob/master/.github/CONTRIBUTING.md).
- For more information about the license, see [MIT License](https://github.com/moltin/js-sdk/blob/master/LICENSE).

765 changes: 274 additions & 491 deletions package-lock.json

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions playground/account-addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as moltin from '..'

async function main() {
const gateway = moltin.gateway({
host: 'epcc-integration.global.ssl.fastly.net',
client_id: 'R7paB5xa2ngzuEM8N6PkTOGpO9jTcAgW1DO2U2KzOl',
client_secret: 'lsKTS0hKMzbxpNBAVjX0NoXt8FeALVPcQxh4lgofWD',
headers: {
'EP-Beta-Features': 'account-management,accounts'
}
})
// await gateway.Authenticate()
// console.log('=======account created successfully')
// await gateway.Accounts.Create({
// email: 'email@email.com',
// password: 'pwd',
// name: 'name',
// type: 'account'
// })
const accounts = await gateway.Accounts.All()
// console.log(accounts)
await gateway.AccountAddresses.Create({
body: {
type: 'account-address',
first_name: 'first_name',
last_name: 'last_name',
line_1: 'line_1',
postcode: 'postcode',
county: 'county',
country: 'RU'
},
account: accounts.data[0].id
})
console.log('=======account address created successfully')
const addresses = await gateway.AccountAddresses.All({
account: accounts.data[0].id
})
console.log(addresses)
const fetchAddresses = await gateway.AccountAddresses.Get({
address: addresses.data[0].id,
account: accounts.data[0].id
})
console.log('=======Account address fetched successfully:')
console.log(fetchAddresses)

const updated = await gateway.AccountAddresses.Update({
address: addresses.data[0].id,
body: {
id: addresses.data[0].id,
type: 'account-address',
first_name: 'first_name22',
last_name: 'last_name22',
line_1: 'line_122',
postcode: 'postcode22',
county: 'county22',
country: 'US'
},
account: accounts.data[0].id
})
console.log('=======Account address updated successfully:')
console.log(updated)
const deleted = await gateway.AccountAddresses.Delete({
address: addresses.data[0].id,
account: accounts.data[0].id
})
console.log('=======Deleted successfully:')
console.log(deleted)
}
main().catch(console.error)
69 changes: 69 additions & 0 deletions playground/customer-addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as moltin from '..'

async function main() {
const gateway = moltin.gateway({
host: 'epcc-integration.global.ssl.fastly.net',
client_id: 'R7paB5xa2ngzuEM8N6PkTOGpO9jTcAgW1DO2U2KzOl',
client_secret: 'lsKTS0hKMzbxpNBAVjX0NoXt8FeALVPcQxh4lgofWD',
headers: {
'EP-Beta-Features': 'account-management,accounts'
}
})
// await gateway.Authenticate()
// console.log('=======customer created successfully')
await gateway.Customers.Create({
email: 'email@email.com',
password: 'pwd',
name: 'name',
type: 'customer'
})
const customers = await gateway.Customers.All()
console.log(customers)
await gateway.CustomerAddresses.Create({
body: {
type: 'customer-address',
first_name: 'first_name',
last_name: 'last_name',
line_1: 'line_1',
postcode: 'postcode',
county: 'county',
country: 'RU'
},
customer: customers.data[0].id
})
console.log('=======customer address created successfully')
const addresses = await gateway.CustomerAddresses.All({
customer: customers.data[0].id
})
console.log(addresses)
const fetchAddresses = await gateway.CustomerAddresses.Get({
address: addresses.data[0].id,
customer: customers.data[0].id
})
console.log('=======Customer address fetched successfully:')
console.log(fetchAddresses)

const updated = await gateway.CustomerAddresses.Update({
address: addresses.data[0].id,
body: {
id: addresses.data[0].id,
type: 'customer-address',
first_name: 'first_name22',
last_name: 'last_name22',
line_1: 'line_122',
postcode: 'postcode22',
county: 'county22',
country: 'US'
},
customer: customers.data[0].id
})
console.log('=======Customer address updated successfully:')
console.log(updated)
const deleted = await gateway.CustomerAddresses.Delete({
address: addresses.data[0].id,
customer: customers.data[0].id
})
console.log('=======Deleted successfully:')
console.log(deleted)
}
main().catch(console.error)
63 changes: 63 additions & 0 deletions src/endpoints/account-addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { singularize } from 'inflected'

import BaseExtend from '../extends/base'

class AccountAddressesEndpoint extends BaseExtend {
constructor(endpoint) {
super(endpoint)

this.endpoint = 'addresses'
}

All({ account, token = null }) {
return this.request.send(
`accounts/${account}/${this.endpoint}`,
'GET',
undefined,
undefined,
token
)
}

Get({ account, address, token = null }) {
return this.request.send(
`accounts/${account}/${this.endpoint}/${address}`,
'GET',
undefined,
undefined,
token
)
}

Create({ account, body, token = null }) {
return this.request.send(
`accounts/${account}/${this.endpoint}`,
'POST',
{ ...body, type: singularize(this.endpoint) },
undefined,
token
)
}

Delete({ account, address, token = null }) {
return this.request.send(
`accounts/${account}/${this.endpoint}/${address}`,
'DELETE',
undefined,
undefined,
token
)
}

Update({ account, address, body, token = null }) {
return this.request.send(
`accounts/${account}/${this.endpoint}/${address}`,
'PUT',
{ ...body, type: singularize(this.endpoint) },
undefined,
token
)
}
}

export default AccountAddressesEndpoint
1 change: 1 addition & 0 deletions src/endpoints/account-members.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AccountMembersEndpoint extends BaseExtend {
'GET',
undefined,
token,
undefined,
this,
headers
)
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/account-memberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AccountMembershipsEndpoint extends BaseExtend {
'GET',
undefined,
token,
undefined,
this
)

Expand Down
1 change: 1 addition & 0 deletions src/endpoints/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AccountsEndpoint extends CRUDExtend {
'GET',
undefined,
token,
undefined,
this,
headers
)
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/authentication-realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AuthenticationRealmsEndpoint extends CRUDExtend {
'GET',
undefined,
token,
undefined,
this,
headers
)
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class CatalogEndpoint extends CatalogQuery {
'GET',
undefined,
token,
undefined,
this
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { singularize } from 'inflected'

import BaseExtend from '../extends/base'

class AddressesEndpoint extends BaseExtend {
class CustomerAddressesEndpoint extends BaseExtend {
constructor(endpoint) {
super(endpoint)

Expand Down Expand Up @@ -55,4 +55,4 @@ class AddressesEndpoint extends BaseExtend {
}
}

export default AddressesEndpoint
export default CustomerAddressesEndpoint
1 change: 1 addition & 0 deletions src/endpoints/customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CustomersEndpoint extends CRUDExtend {
'POST',
tokenRequestBody,
null,
undefined,
{
...headers
}
Expand Down
9 changes: 8 additions & 1 deletion src/endpoints/merchant-realm-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ class MerchantRealmMappings {
}

All(token = null) {
this.call = this.request.send(this.endpoint, 'GET', undefined, token, this)
this.call = this.request.send(
this.endpoint,
'GET',
undefined,
token,
undefined,
this
)

return this.call
}
Expand Down
5 changes: 4 additions & 1 deletion src/endpoints/node-relationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class NodeRelationshipsEndpoint {
return this.request.send(
`hierarchies/${hierarchyId}/nodes/${nodeId}/relationships/parent`,
'PUT',
{ ...body, type: singularize(this.endpoint) },
{
...body,
type: singularize(this.endpoint)
},
token
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/endpoints/oidc-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class OidcProfileEndpoint extends CRUDExtend {
'GET',
undefined,
token,
undefined,
this,
headers
)
Expand All @@ -42,6 +43,7 @@ class OidcProfileEndpoint extends CRUDExtend {
'GET',
undefined,
token,
undefined,
this,
headers
)
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/price-book-prices.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PriceBookPricesEndpoint {
'GET',
undefined,
token,
undefined,
this
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/extends/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class BaseExtend {
'GET',
undefined,
token,
undefined,
this
)

Expand All @@ -35,6 +36,7 @@ class BaseExtend {
'GET',
undefined,
token,
undefined,
this
)

Expand Down
10 changes: 7 additions & 3 deletions src/factories/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class RequestFactory {
uri,
method,
body = undefined,
token = undefined,
customerToken = undefined,
accountToken = undefined,
instance,
wrapBody = true,
version = null
Expand Down Expand Up @@ -121,8 +122,11 @@ class RequestFactory {
headers['X-MOLTIN-LANGUAGE'] = config.language
}

if (token) {
headers['X-MOLTIN-CUSTOMER-TOKEN'] = token
if (customerToken) {
headers['X-MOLTIN-CUSTOMER-TOKEN'] = customerToken
}
if (accountToken) {
headers['EP-ACCOUNT-MANAGEMENT-AUTHENTICATION-TOKEN'] = accountToken
}

if (config.headers) {
Expand Down
Loading

0 comments on commit 32d7bfa

Please sign in to comment.