mppx 0.6.20 → 0.6.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/client/Mppx.d.ts +12 -1
- package/dist/client/Mppx.d.ts.map +1 -1
- package/dist/client/Mppx.js +127 -10
- package/dist/client/Mppx.js.map +1 -1
- package/dist/client/internal/Fetch.d.ts +69 -1
- package/dist/client/internal/Fetch.d.ts.map +1 -1
- package/dist/client/internal/Fetch.js +250 -20
- package/dist/client/internal/Fetch.js.map +1 -1
- package/dist/middlewares/internal/mppx.d.ts +1 -1
- package/dist/middlewares/internal/mppx.d.ts.map +1 -1
- package/dist/middlewares/internal/mppx.js +2 -1
- package/dist/middlewares/internal/mppx.js.map +1 -1
- package/dist/server/Mppx.d.ts +82 -3
- package/dist/server/Mppx.d.ts.map +1 -1
- package/dist/server/Mppx.js +557 -83
- package/dist/server/Mppx.js.map +1 -1
- package/dist/tempo/client/Subscription.d.ts.map +1 -1
- package/dist/tempo/client/Subscription.js +4 -3
- package/dist/tempo/client/Subscription.js.map +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts.map +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/html.gen.js.map +1 -1
- package/package.json +1 -1
- package/src/client/Mppx.test-d.ts +55 -0
- package/src/client/Mppx.test.ts +181 -0
- package/src/client/Mppx.ts +248 -16
- package/src/client/internal/Fetch.test-d.ts +31 -0
- package/src/client/internal/Fetch.test.ts +261 -0
- package/src/client/internal/Fetch.ts +467 -24
- package/src/middlewares/internal/mppx.ts +5 -6
- package/src/proxy/Proxy.test.ts +69 -0
- package/src/server/Mppx.test-d.ts +50 -0
- package/src/server/Mppx.test.ts +893 -1
- package/src/server/Mppx.ts +862 -97
- package/src/tempo/client/Subscription.test.ts +51 -0
- package/src/tempo/client/Subscription.ts +4 -3
- package/src/tempo/server/internal/html.gen.ts +1 -1
|
@@ -171,6 +171,56 @@ describe('Mppx type tests', () => {
|
|
|
171
171
|
expectTypeOf(mppx.verifyCredential).toBeFunction()
|
|
172
172
|
})
|
|
173
173
|
|
|
174
|
+
test('server events receive typed method context', () => {
|
|
175
|
+
const mppx = Mppx.create({
|
|
176
|
+
methods: [alphaMethod],
|
|
177
|
+
realm,
|
|
178
|
+
secretKey,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
mppx.on('payment.success', (context) => {
|
|
182
|
+
expectTypeOf(context.challenge.method).toEqualTypeOf<'alpha'>()
|
|
183
|
+
expectTypeOf(context.credential?.payload.token).toEqualTypeOf<string | undefined>()
|
|
184
|
+
})
|
|
185
|
+
mppx.on('challenge.created', (context) => {
|
|
186
|
+
expectTypeOf(context.method.name).toEqualTypeOf<'alpha'>()
|
|
187
|
+
expectTypeOf(context.error).toMatchTypeOf<Error | undefined>()
|
|
188
|
+
})
|
|
189
|
+
mppx.on('payment.failed', (context) => {
|
|
190
|
+
expectTypeOf(context.error).toMatchTypeOf<Error>()
|
|
191
|
+
expectTypeOf(context.credential).toMatchTypeOf<unknown>()
|
|
192
|
+
})
|
|
193
|
+
mppx.on('*', (event) => {
|
|
194
|
+
expectTypeOf(event.name).toMatchTypeOf<
|
|
195
|
+
'challenge.created' | 'payment.failed' | 'payment.success'
|
|
196
|
+
>()
|
|
197
|
+
if (event.name === 'payment.failed') expectTypeOf(event.payload.error).toMatchTypeOf<Error>()
|
|
198
|
+
if (event.name === 'challenge.created')
|
|
199
|
+
expectTypeOf(event.payload.error).toMatchTypeOf<Error | undefined>()
|
|
200
|
+
if (event.name === 'payment.success')
|
|
201
|
+
expectTypeOf(event.payload.receipt.status).toEqualTypeOf<'success'>()
|
|
202
|
+
})
|
|
203
|
+
mppx.onChallengeCreated((context) => {
|
|
204
|
+
expectTypeOf(context.input).toEqualTypeOf<Request | undefined>()
|
|
205
|
+
expectTypeOf(context.method.name).toEqualTypeOf<'alpha'>()
|
|
206
|
+
expectTypeOf(context.request.amount).toEqualTypeOf<string>()
|
|
207
|
+
expectTypeOf(context.error).toMatchTypeOf<Error | undefined>()
|
|
208
|
+
})
|
|
209
|
+
mppx.onPaymentSuccess((context) => {
|
|
210
|
+
expectTypeOf(context.challenge.method).toEqualTypeOf<'alpha'>()
|
|
211
|
+
expectTypeOf(context.credential?.payload.token).toEqualTypeOf<string | undefined>()
|
|
212
|
+
expectTypeOf(context.envelope?.challenge.intent).toEqualTypeOf<'charge' | undefined>()
|
|
213
|
+
expectTypeOf(context.receipt.status).toEqualTypeOf<'success'>()
|
|
214
|
+
expectTypeOf(context.request.recipient).toEqualTypeOf<string>()
|
|
215
|
+
})
|
|
216
|
+
mppx.onPaymentFailed((context) => {
|
|
217
|
+
expectTypeOf(context.credential).toMatchTypeOf<unknown>()
|
|
218
|
+
expectTypeOf(context.error).toMatchTypeOf<Error>()
|
|
219
|
+
expectTypeOf(context.method.intent).toEqualTypeOf<'charge'>()
|
|
220
|
+
expectTypeOf(context.request.currency).toEqualTypeOf<string>()
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
|
|
174
224
|
test('handler options and verifyCredential accept scope', () => {
|
|
175
225
|
const mppx = Mppx.create({ methods: [alphaMethod], realm, secretKey })
|
|
176
226
|
|