diff --git a/dist/bud-provider.js b/dist/bud-provider.js index 8b68b07..64bbecb 100644 --- a/dist/bud-provider.js +++ b/dist/bud-provider.js @@ -19,7 +19,7 @@ function BudProvider(options) { }; let refreshToken; let accessToken; - let tokenState = 'start'; + let tokenState = 'init'; const makeUtils = this.export('provider/makeUtils'); const { makeUrl, get, post, entityBuilder, origFetcher, asyncLocalStorage, } = makeUtils({ name: 'bud', @@ -58,6 +58,7 @@ function BudProvider(options) { let q = { ...(msg.q || {}) }; let id = q.id; try { + await waitForRefreshToken(); let json = await get(makeUrl('v1/customers', id, 'context')); // console.log('LOAD CUSTOMER JSON', json) let entdata = json.data; @@ -83,6 +84,7 @@ function BudProvider(options) { ...(msg.ent.data$(false)), } }; + await waitForRefreshToken(); let json = await post(makeUrl('platform/v3/customers'), { body }); @@ -242,6 +244,7 @@ function BudProvider(options) { async function (entize, msg) { let q = { ...(msg.q || {}) }; try { + await waitForRefreshToken(); let json = await get(makeUrl('v1/open-banking/providers'), q); let entlist = json.data; entlist = entlist.map((entdata) => { @@ -300,14 +303,14 @@ function BudProvider(options) { }, body: 'grant_type=client_credentials' }; - // console.log('GET REFRESH', refreshConfig) + console.log('GET REFRESH', mark, refreshConfig); let refreshResult = await origFetcher(options.url + 'v1/oauth/token', refreshConfig); if (200 !== refreshResult.status) { console.log('REFRESH TOKEN FAIL', refreshConfig, refreshResult); throw new Error('bud-provider: refresh-token: status:' + refreshResult.status); } options.debug && - console.log('REFRESH RESULT', refreshConfig, refreshResult); + console.log('REFRESH RESULT', mark, refreshConfig, refreshResult); let refreshJSON = await refreshResult.json(); // console.log('REFRESH JSON', refreshJSON) // TODO: don't store here @@ -359,7 +362,7 @@ function BudProvider(options) { } } catch (e) { - console.log('RETRY ERROR', e); + console.log('RETRY ERROR', mark, e); throw e; } } @@ -378,14 +381,20 @@ function BudProvider(options) { }; }); async function waitForRefreshToken() { - if ('request' === tokenState || 'refresh' === tokenState) { - let start = Date.now(); - for (let i = 0; ('request' === tokenState || 'refresh' === tokenState) && + if ('init' === tokenState) { + tokenState = 'start'; + return; + } + if ('active' !== tokenState) { + let start = Date.now(), i = 0, mark = Math.random(); + console.log('waitForRefreshToken', tokenState, mark); + for (; ('active' !== tokenState) && i < 1111 && ((Date.now() - start) < options.wait.refresh.max); i++) { await new Promise((r) => setTimeout(r, options.wait.refresh.interval)); } - if ('request' === tokenState || 'refresh' === tokenState || null == refreshToken) { + console.log('waitForRefreshToken', tokenState, mark, i, Date.now() - start); + if ('active' === tokenState || null == refreshToken) { throw new Error('bud-provider: token-not-available: state:' + tokenState); } } diff --git a/dist/bud-provider.js.map b/dist/bud-provider.js.map index 0431332..1752a28 100644 --- a/dist/bud-provider.js.map +++ b/dist/bud-provider.js.map @@ -1 +1 @@ -{"version":3,"file":"bud-provider.js","sourceRoot":"","sources":["../src/bud-provider.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;AAGrE,mEAAiC;AAsBjC,SAAS,WAAW,CAAY,OAA+B;IAC7D,MAAM,MAAM,GAAQ,IAAI,CAAA;IAExB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAA;IAC5B,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;IAErB,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC;QACnC,UAAU,EAAE,MAAM;QAClB,cAAc,EAAE,MAAM;KACvB,CAAC,CAAC,CAAA;IAGH,2BAA2B;IAC3B,MAAM,MAAM,GAAQ;QAClB,OAAO,EAAE,EAAE;KACZ,CAAA;IAED,IAAI,YAAiB,CAAA;IACrB,IAAI,WAAgB,CAAA;IACpB,IAAI,UAAU,GAA+C,OAAO,CAAA;IAEpE,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAEnD,MAAM,EACJ,OAAO,EACP,GAAG,EACH,IAAI,EACJ,aAAa,EACb,WAAW,EACX,iBAAiB,GAClB,GAAG,SAAS,CAAC;QACZ,IAAI,EAAE,K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AAM,EAAE,EAAE;IAEV,IAAI,EAAE;QACJ,OAAO,EAAE;YACP,GAAG,EAAE,KAAK;YACV,QAAQ,EAAE,GAAG;SACd;KACF;CACF,CAAA;AAED,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;AAExC,kBAAe,WAAW,CAAA;AAE1B,IAAI,WAAW,KAAK,OAAO,MAAM,EAAE,CAAC;IAClC,MAAM,CAAC,OAAO,GAAG,WAAW,CAAA;AAC9B,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index cef7437..d813f8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@seneca/bud-provider", - "version": "0.5.3", + "version": "0.5.5", "main": "dist/bud-provider.js", "type": "commonjs", "types": "dist/bud-provider.d.ts", diff --git a/src/bud-provider.ts b/src/bud-provider.ts index 04a950e..15b3561 100644 --- a/src/bud-provider.ts +++ b/src/bud-provider.ts @@ -42,7 +42,7 @@ function BudProvider(this: any, options: FullBudProviderOptions) { let refreshToken: any let accessToken: any - let tokenState: 'start' | 'request' | 'refresh' | 'active' = 'start' + let tokenState: 'init' | 'start' | 'request' | 'refresh' | 'active' = 'init' const makeUtils = this.export('provider/makeUtils') @@ -99,6 +99,8 @@ function BudProvider(this: any, options: FullBudProviderOptions) { let id = q.id try { + await waitForRefreshToken() + let json = await get(makeUrl('v1/customers', id, 'context')) // console.log('LOAD CUSTOMER JSON', json) let entdata = json.data @@ -127,6 +129,8 @@ function BudProvider(this: any, options: FullBudProviderOptions) { } } + await waitForRefreshToken() + let json = await post(makeUrl('platform/v3/customers'), { body }) @@ -328,6 +332,8 @@ function BudProvider(this: any, options: FullBudProviderOptions) { let q = { ...(msg.q || {}) } try { + await waitForRefreshToken() + let json = await get(makeUrl('v1/open-banking/providers'), q) let entlist = json.data entlist = entlist.map((entdata: any) => { @@ -409,7 +415,7 @@ function BudProvider(this: any, options: FullBudProviderOptions) { body: 'grant_type=client_credentials' } - // console.log('GET REFRESH', refreshConfig) + console.log('GET REFRESH', mark, refreshConfig) let refreshResult = await origFetcher(options.url + 'v1/oauth/token', refreshConfig) @@ -420,7 +426,7 @@ function BudProvider(this: any, options: FullBudProviderOptions) { } options.debug && - console.log('REFRESH RESULT', refreshConfig, refreshResult) + console.log('REFRESH RESULT', mark, refreshConfig, refreshResult) let refreshJSON = await refreshResult.json() // console.log('REFRESH JSON', refreshJSON) @@ -491,7 +497,7 @@ function BudProvider(this: any, options: FullBudProviderOptions) { } } catch (e) { - console.log('RETRY ERROR', e) + console.log('RETRY ERROR', mark, e) throw e } } @@ -523,18 +529,25 @@ function BudProvider(this: any, options: FullBudProviderOptions) { async function waitForRefreshToken() { - if ('request' === tokenState || 'refresh' === tokenState) { - let start = Date.now() + if ('init' === tokenState) { + tokenState = 'start' + return + } + if ('active' !== tokenState) { + let start = Date.now(), i = 0, mark = Math.random() + console.log('waitForRefreshToken', tokenState, mark) + for ( - let i = 0; - ('request' === tokenState || 'refresh' === tokenState) && + ; ('active' !== (tokenState as string)) && i < 1111 && ((Date.now() - start) < options.wait.refresh.max); i++ ) { await new Promise((r) => setTimeout(r, options.wait.refresh.interval)) } - if ('request' === tokenState || 'refresh' === tokenState || null == refreshToken) { + console.log('waitForRefreshToken', tokenState, mark, i, Date.now() - start) + + if ('active' === (tokenState as string) || null == refreshToken) { throw new Error('bud-provider: token-not-available: state:' + tokenState) } }