openvibers/openvibe.sdk Commits

openvibe-sdk/play: titles.remove deletes a sandbox title you manage (OpenVibe.Play#42) (#82)

OP OpenVibers committed 19 days ago · 31a661ee3e · 3 files, +7 −0

Changes

ddiff --git a/src/play.js b/src/play.js
iindex 8d6156b..f206ffb 100644
---- a/src/play.js
++++ b/src/play.js
@@@ -5,6 +5,7 @@
* with its own principal's token (audience openvibe.play): a first-party service token, or a developer app's token
* granted play.title.manage / play.result.write / play.player.read. The principal that registers a title is its only
* writer; another one is told the title does not exist. Leaderboards and titles are public reads (no token).
++ * A developer's sandbox app manages `sandbox-…` titles only (guest players, unlisted, at most 3) and may delete them.
*
* const play = createPlayClient(createClient({ tokenProvider: tokens }));
* await play.titles.define('gem-run', { // play.title-definition@1
@@@ -44,6 +45,8 @@ function createPlayClient(client, { baseUrl } = {}) {
list: ({ signal } = {}) => open({ path: '/api/v1/titles', signal }),
/** Public: one title, or null. */
get: (title, { signal } = {}) => orNull(open({ path: `/api/v1/titles/${enc(title)}`, signal })),
++ /** Delete a sandbox title you manage, with everything in it (play.title.manage); a production title is kept (409 play.title_kept). */
++ remove: (title, { signal } = {}) => call({ method: 'DELETE', path: `/api/v1/titles/${enc(title)}`, signal, idempotencyKey: false }),
},
scores: {
/** A round's scores to one board (play.result.write); idempotent by ref, up to 100 entries. */
ddiff --git a/test/play.test.js b/test/play.test.js
iindex 2b6fa13..427b95d 100644
---- a/test/play.test.js
++++ b/test/play.test.js
@@@ -19,6 +19,7 @@ const { OpenVibeError } = require('../src/core/errors');
await play.players.achievements('gem-run', KIM);
await play.boards.get('gem-run', 'high-score', { period: 'week' });
await play.titles.list();
++ await play.titles.remove('sandbox-gem-run');
assert.deepStrictEqual(calls.map((c) => [c.method || 'GET', c.path, c.audience || null, c.auth === false]), [
['PUT', '/api/v1/titles/gem-run', 'openvibe.play', false],
['POST', '/api/v1/titles/gem-run/scores', 'openvibe.play', false],
@@@ -27,6 +28,7 @@ const { OpenVibeError } = require('../src/core/errors');
['GET', `/api/v1/titles/gem-run/players/${KIM}/achievements`, 'openvibe.play', false],
['GET', '/api/v1/titles/gem-run/boards/high-score', null, true],
['GET', '/api/v1/titles', null, true],
++ ['DELETE', '/api/v1/titles/sandbox-gem-run', 'openvibe.play', false],
]);
assert.deepStrictEqual(calls[1].json, { board: 'high-score', ref: 'round-1', entries: [{ player: KIM, name: 'kim', score: 1200 }] });
assert.deepStrictEqual(calls[3].json, { person: KIM });
ddiff --git a/types/play.d.ts b/types/play.d.ts
iindex f86febd..43a637f 100644
---- a/types/play.d.ts
++++ b/types/play.d.ts
@@@ -8,6 +8,8 @@ export interface PlayClient {
define(title: string, definition: PlayTitleDefinition, opts?: { signal?: AbortSignal }): Promise<any>;
list(opts?: { signal?: AbortSignal }): Promise<any>;
get(title: string, opts?: { signal?: AbortSignal }): Promise<any | null>;
++ /** Delete a sandbox title you manage (a production title is kept: 409 play.title_kept). */
++ remove(title: string, opts?: { signal?: AbortSignal }): Promise<any>;
};
scores: {
post(title: string, round: { board: string; ref: string; at?: string; entries: PlayScoreEntry[] }, opts?: { signal?: AbortSignal }): Promise<any>;