Skip to content

Instantly share code, notes, and snippets.

@bewest
Last active February 5, 2021 17:21
Show Gist options
  • Select an option

  • Save bewest/b3bd5535e80bd03b4aa7193f34a875d5 to your computer and use it in GitHub Desktop.

Select an option

Save bewest/b3bd5535e80bd03b4aa7193f34a875d5 to your computer and use it in GitHub Desktop.

Revisions

  1. bewest revised this gist Feb 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -87,7 +87,7 @@ var refreshingBearerTokenFetchMachine = Machine({
    }
    },
    // Does making this a final state mean it can't be re-used in a polling activity?
    success: { type: 'final' },
    success: { on: { '': 'idle' } },
    failure: {
    on: {
    RETRY: '#RefreshingTokenAccessFetchMachine.unauthorized'
  2. bewest revised this gist Feb 5, 2021. No changes.
  3. bewest revised this gist Feb 5, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -86,10 +86,11 @@ var refreshingBearerTokenFetchMachine = Machine({
    REJECT: 'failure'
    }
    },
    // Does making this a final state mean it can't be re-used in a polling activity?
    success: { type: 'final' },
    failure: {
    on: {
    RETRY: 'loading'
    RETRY: '#RefreshingTokenAccessFetchMachine.unauthorized'
    }
    },
    }
  4. bewest revised this gist Feb 5, 2021. No changes.
  5. bewest revised this gist Feb 5, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ var refreshingBearerTokenFetchMachine = Machine({
    on: { NEXT: 'step_five_bearer' }
    },
    step_five_bearer: {
    on: { NEXT: '#CarelinkFetchMachine.authorized' }
    on: { NEXT: '#RefreshingTokenAccessFetchMachine.authorized' }
    },
    }
    },
    @@ -62,7 +62,7 @@ var refreshingBearerTokenFetchMachine = Machine({
    },
    invalid: {
    on: {
    '': '#CarelinkFetchMachine.unauthorized'
    '': '#RefreshingTokenAccessFetchMachine.unauthorized'
    }

    },
    @@ -75,7 +75,7 @@ var refreshingBearerTokenFetchMachine = Machine({
    on: {
    FETCH: [{
    target: 'loading',
    in: '#CarelinkFetchMachine.authorized.token.valid'
    in: '#RefreshingTokenAccessFetchMachine.authorized.token.valid'
    }]
    }

  6. bewest revised this gist Feb 5, 2021. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,13 @@


    var minimedFetchMachine = Machine({
    id: 'CarelinkFetchMachine',
    /*
    Our client is expected to access a web service on a regular
    interval as part of a polling activity. The access itself
    requires a Bearer token, which can sometimes be renewed.
    If it cannot be renewed, a new one must be created by
    going through a sequence of steps.
    */
    var refreshingBearerTokenFetchMachine = Machine({
    id: 'RefreshingTokenAccessFetchMachine',
    initial: 'idle',
    states: {
    idle: { on: { FETCH: 'unauthorized' } },
  7. bewest created this gist Feb 5, 2021.
    96 changes: 96 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,96 @@


    var minimedFetchMachine = Machine({
    id: 'CarelinkFetchMachine',
    initial: 'idle',
    states: {
    idle: { on: { FETCH: 'unauthorized' } },
    unauthorized: {
    initial: 'step_one_portal',
    states: {
    step_one_portal: {
    on: { NEXT: 'step_two_location' }
    },
    step_two_location: {
    on: { NEXT: 'step_three_login' }
    },
    step_three_login: {
    on: { NEXT: 'step_four_consent' }
    },
    step_four_consent: {
    on: { NEXT: 'step_five_bearer' }
    },
    step_five_bearer: {
    on: { NEXT: '#CarelinkFetchMachine.authorized' }
    },
    }
    },
    authorized: {
    type: 'parallel',
    states: {
    token: {
    initial: 'valid',
    states: {
    valid: {
    on: {
    RENEW: 'expiring',
    EXPIRE: 'expired'
    }
    },
    expiring: {
    on: {
    REFRESH: 'refreshing'
    }
    },
    refreshing: {
    on: {
    RESOLVE: 'valid',
    REJECT: 'invalid'
    }
    },
    expired: {
    on: {
    '': 'invalid'
    }

    },
    invalid: {
    on: {
    '': '#CarelinkFetchMachine.unauthorized'
    }

    },
    },
    },
    data: {
    initial: 'idle',
    states: {
    idle: {
    on: {
    FETCH: [{
    target: 'loading',
    in: '#CarelinkFetchMachine.authorized.token.valid'
    }]
    }

    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: { type: 'final' },
    failure: {
    on: {
    RETRY: 'loading'
    }
    },
    }
    }

    }
    },

    }
    });