mirror of https://codeberg.org/pzp/pzp-invite.git
create() returns both URI and URL
This commit is contained in:
parent
55c0bd2844
commit
1b5b35bb14
|
@ -169,7 +169,7 @@ module.exports = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {CreateOpts} opts
|
* @param {CreateOpts} opts
|
||||||
* @param {CB<string>} cb
|
* @param {CB<{uri: string, url: string}>} cb
|
||||||
*/
|
*/
|
||||||
async function create(opts, cb) {
|
async function create(opts, cb) {
|
||||||
if (typeof opts !== 'object') {
|
if (typeof opts !== 'object') {
|
||||||
|
@ -223,7 +223,8 @@ module.exports = {
|
||||||
const followCommand = `follow/${opts.id}`
|
const followCommand = `follow/${opts.id}`
|
||||||
const promiseCommand = `promise.follow/identity.${opts.id}/${token}`
|
const promiseCommand = `promise.follow/identity.${opts.id}/${token}`
|
||||||
const uri = `ppppp://invite/${joinCommand}/${followCommand}/${promiseCommand}`
|
const uri = `ppppp://invite/${joinCommand}/${followCommand}/${promiseCommand}`
|
||||||
cb(null, uri)
|
const url = `http://${host}/invite#${encodeURIComponent(uri)}`
|
||||||
|
cb(null, {uri, url})
|
||||||
}
|
}
|
||||||
|
|
||||||
return { create, parse }
|
return { create, parse }
|
||||||
|
|
|
@ -43,13 +43,13 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "node --test",
|
"test": "node --test",
|
||||||
"format-code": "prettier --write \"*.js\" \"(test|lib)/*.js\"",
|
"format-code": "prettier --write \"(test|lib)/**/*.js\"",
|
||||||
"format-code-staged": "pretty-quick --staged --pattern \"*.js\" --pattern \"(test|lib)/*.js\"",
|
"format-code-staged": "pretty-quick --staged --pattern \"(test|lib)/**/*.js\"",
|
||||||
"coverage": "c8 --reporter=lcov npm run test"
|
"coverage": "c8 --reporter=lcov npm run test"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"pre-commit": "pretty-quick --staged"
|
"pre-commit": "npm run format-code-staged"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,8 @@ test('create()', async (t) => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const uri = await p(stack.invite.create)({
|
const { uri, url } = await p(stack.invite.create)({
|
||||||
type: "follow",
|
type: 'follow',
|
||||||
_hubMsAddr: 'net:example.com:8008~shse:HUB_PUBKEY',
|
_hubMsAddr: 'net:example.com:8008~shse:HUB_PUBKEY',
|
||||||
id: 'MOCK_ID',
|
id: 'MOCK_ID',
|
||||||
})
|
})
|
||||||
|
@ -83,6 +83,10 @@ test('create()', async (t) => {
|
||||||
uri,
|
uri,
|
||||||
`ppppp://invite/join/example.com/8008/HUB_PUBKEY/MOCK_TOKEN/follow/MOCK_ID/promise.follow/identity.MOCK_ID/MOCK_PROMISE`
|
`ppppp://invite/join/example.com/8008/HUB_PUBKEY/MOCK_TOKEN/follow/MOCK_ID/promise.follow/identity.MOCK_ID/MOCK_PROMISE`
|
||||||
)
|
)
|
||||||
|
assert.equal(
|
||||||
|
url,
|
||||||
|
`http://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fexample.com%2F8008%2FHUB_PUBKEY%2FMOCK_TOKEN%2Ffollow%2FMOCK_ID%2Fpromise.follow%2Fidentity.MOCK_ID%2FMOCK_PROMISE`
|
||||||
|
)
|
||||||
|
|
||||||
assert.ok(connectCalled)
|
assert.ok(connectCalled)
|
||||||
assert.ok(createTokenCalled)
|
assert.ok(createTokenCalled)
|
||||||
|
|
Loading…
Reference in New Issue