Skip to content

Commit

Permalink
Merge pull request #10 from gradientedge/remove_post_registration
Browse files Browse the repository at this point in the history
feat: remove post registration sync function
  • Loading branch information
jimmythomson authored May 31, 2022
2 parents c7dec20 + 7b55b06 commit 5305f12
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 94 deletions.
45 changes: 0 additions & 45 deletions src/CommercetoolsAuth0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
MergeAnonymousToAccountCartParams,
MergeCartParams,
GetCartParams,
PostRegistrationSyncParams,
} from './types'
import { COMMERCETOOLS_REQUIRED_SCOPES, DEFAULT_REQUEST_TIMEOUT_MS } from './constants'
import { CommercetoolsAuth0ErrorCode } from './error/codes'
Expand Down Expand Up @@ -71,50 +70,6 @@ export class CommercetoolsAuth0 {
return customer
}

/**
* Post-registration synchronisation functionality
*
* This method should be called when the post-registration action is executed.
* It is used to set the `externalId` on the commercetools customer based on the
* given Auth0 user id.
*/
public async postRegistrationSync(options: PostRegistrationSyncParams): Promise<void> {
let customer: Customer | null = null

try {
customer = await this.client.getCustomerById({
storeKey: options.storeKey,
id: options.accountCustomerId,
})
} catch (e) {
throw new CommercetoolsAuth0Error('Unable to retrieve customer', {
code: CommercetoolsAuth0ErrorCode.UNEXPECTED_ERROR,
originalError: e,
})
}

try {
await this.client.updateCustomerById({
id: options.accountCustomerId,
storeKey: options.storeKey,
data: {
version: customer.version,
actions: [
{
action: 'setExternalId',
externalId: options.userId,
},
],
},
})
} catch (e) {
throw new CommercetoolsAuth0Error('Unable to set `externalId`', {
code: CommercetoolsAuth0ErrorCode.UNEXPECTED_ERROR,
originalError: e,
})
}
}

/**
* Merge the anonymous customer's cart with the account customer's cart
*
Expand Down
27 changes: 0 additions & 27 deletions src/__tests__/CommercetoolsAuth0.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,6 @@ describe('CommercetoolsAuth0', () => {
})
})

describe('postRegistrationSync', () => {
it("should update the commercetools customer's`externalId` with the Auth0 user id", async () => {
nock('https://api.europe-west1.gcp.commercetools.com', {
reqheaders: {
authorization: 'Bearer test-access-token',
},
})
.get('/test-project-key/customers/account-customer-id')
.reply(200, { customer: mockCustomer })
nock('https://api.europe-west1.gcp.commercetools.com', {
reqheaders: {
authorization: 'Bearer test-access-token',
},
})
.post('/test-project-key/customers/account-customer-id', {
actions: [{ action: 'setExternalId', externalId: 'auth0-user-id' }],
})
.reply(200, { customer: mockCustomer })
const commercetoolsAuth0 = new CommercetoolsAuth0(mockConfig)

await commercetoolsAuth0.postRegistrationSync({
userId: 'auth0-user-id',
accountCustomerId: 'account-customer-id',
})
})
})

describe('assignAnonymousCartToAccountCustomer', () => {
it('should set the customer id on the anonymous cart', async () => {
const mockAnonymousCart = _.cloneDeep({
Expand Down
22 changes: 0 additions & 22 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,6 @@ export interface PostLoginSyncParams {
mergeCart: true | false | 'use_anonymous'
}

export interface PostRegistrationSyncParams {
/**
* The customer id of the newly registered customer
*/
accountCustomerId: string
/**
* The key of the commercetools store that this customer relates to
*
* Not required if customers are global.
*/
storeKey?: string
/**
* The Auth0 user id
*/
userId: string
}

export interface CreateCustomerParams {
storeKey?: string
user: {
Expand All @@ -75,11 +58,6 @@ export interface CreateCustomerParams {
}
}

export interface GetAnonymousCustomerCartParams {
storeKey?: string
anonymousCustomerId: string
}

export interface GetCartParams {
storeKey?: string
customerId: string
Expand Down

0 comments on commit 5305f12

Please sign in to comment.