openvibers/openvibe.vip Commits

VIP home: sell a subscription to your software (the SDK and HTTPS membership check a person's own token may make) (#61)

OP OpenVibers committed 27 days ago · cd95b4ff7b · 2 files, +38 −0

Changes

ddiff --git a/server/web/pages.js b/server/web/pages.js
iindex 08a436b..6a4fc8c 100644
---- a/server/web/pages.js
++++ b/server/web/pages.js
@@@ -76,6 +76,30 @@ function home({ creators }) {
{ title: 'Join through OpenVibe.Billing', text: 'Pay from your Vibes credit or another way Billing offers; renew automatically or not, your choice.' },
{ title: 'Keep the terms you joined under', text: 'Plans are versioned: the version you joined stays yours while your membership lasts, and every version stays public in the terms history.' },
],
++ }) + showcase.code({
++ id: 'software',
++ title: 'Sell a subscription to your software',
++ lede: 'Publish a plan for your app or tool, then have it ask VIP whether the person signed in with OpenVibe is a member. '
++ + 'Whoever joins your plan gets in; when their membership ends, the answer says so.',
++ samples: [
++ {
++ label: 'Node (openvibe-sdk)', lang: 'js',
++ code: `const { createVipClient } = require('openvibe-sdk/vip');
++
++// personToken: the person's token from Sign in with OpenVibe
++const vip = createVipClient({ baseUrl: 'https://openvibe.vip', getToken: async () => personToken });
++const e = await vip.checkEntitlement({ creator: 'yourname' });
++if (e.active) unlockPro(); // expired, unknown or unreachable all answer no`,
++ },
++ {
++ label: 'Any language (HTTPS)', lang: 'bash',
++ code: `curl -s -X POST https://openvibe.vip/api/v1/entitlements/check \\
++ -H "Authorization: Bearer $PERSON_TOKEN" \\
++ -H 'Content-Type: application/json' \\
++ -d '{"creator":"yourname"}'
++# {"active":true,"status":"active","expires_at":"…",…}`,
++ },
++ ],
}) + `
<section class="sc-sec" id="creators" aria-labelledby="creators-h"><h2 id="creators-h">Creators with plans</h2>${list}<p class="muted creators-cta">Are you a creator? <a href="/dashboard">Offer a plan</a>.</p></section>`;
}
ddiff --git a/test/home-software.test.js b/test/home-software.test.js
nnew file mode 100644
iindex 0000000..3b1ec61
---- /dev/null
++++ b/test/home-software.test.js
@@@ -0,0 +1,14 @@
++'use strict';
++// The home tells developers how to sell a subscription to their own software (the owner's ask: "some vibe coder who wants a
++// monthly subscription thing for their software"): the SDK call and the plain HTTPS call against /api/v1/entitlements/check,
++// which a person's own token may ask about themselves.
++const assert = require('assert');
++const pages = require('../server/web/pages');
++
++const html = pages.home({ creators: [] });
++assert.match(html, /id="software"/);
++assert.match(html, /Sell a subscription to your software/);
++assert.match(html, /require\(&#39;openvibe-sdk\/vip&#39;\)|require\('openvibe-sdk\/vip'\)/, 'the SDK sample');
++assert.match(html, /checkEntitlement\(\{ creator: &#39;yourname&#39; \}\)|checkEntitlement\(\{ creator: 'yourname' \}\)/);
++assert.match(html, /https:\/\/openvibe\.vip\/api\/v1\/entitlements\/check \\\n/, 'the HTTPS sample keeps its line continuations');
++console.log('home software: all checks passed');