Skip to content

Commit

Permalink
Implement Client.playgroundURL
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuswilms committed Aug 29, 2021
1 parent 6c21951 commit bdea408
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"eslint-plugin-notice": "^0.9.10",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^1.18.2"
},
"dependencies": {
"hash.js": "^1.1.7"
}
}
15 changes: 15 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* license that can be found in the LICENSE file.
*/

import hash from 'hash.js';

// Client for accessing the DSK APIv2.
//
// The client supports versions, you can select the version on a per
Expand Down Expand Up @@ -68,6 +70,19 @@ export default class Client {
return this.fetch(`/api/v2/tree/${this.url(url)}?${params.toString()}`);
}

// Returns a promise that resolve with the URL to a playground's index.html,
// which can be used as the source for an iframe.
static playgroundURL(node, doc, component, version = null) {
let params = new URLSearchParams();
if (version) {
params.set('v', version);
}

return Promise.resolve(
`/api/v2/tree/${this.url(node)}/_docs/${doc}/_playgrounds/${component}/index.html?${params.toString()}`
);
}

// Will automatically strip leading and trailing slashes from the given
// URL to turn it into a valid (node) URL for lookup.
static url(url) {
Expand Down
20 changes: 19 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ __metadata:
eslint-import-resolver-node: ^0.3.6
eslint-plugin-notice: ^0.9.10
eslint-plugin-prettier: ^3.4.0
hash.js: ^1.1.7
prettier: ^1.18.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -846,6 +847,16 @@ __metadata:
languageName: node
linkType: hard

"hash.js@npm:^1.1.7":
version: 1.1.7
resolution: "hash.js@npm:1.1.7"
dependencies:
inherits: ^2.0.3
minimalistic-assert: ^1.0.1
checksum: e350096e659c62422b85fa508e4b3669017311aa4c49b74f19f8e1bc7f3a54a584fdfd45326d4964d6011f2b2d882e38bea775a96046f2a61b7779a979629d8f
languageName: node
linkType: hard

"ignore@npm:^4.0.6":
version: 4.0.6
resolution: "ignore@npm:4.0.6"
Expand Down Expand Up @@ -880,7 +891,7 @@ __metadata:
languageName: node
linkType: hard

"inherits@npm:2":
"inherits@npm:2, inherits@npm:^2.0.3":
version: 2.0.4
resolution: "inherits@npm:2.0.4"
checksum: 4a48a733847879d6cf6691860a6b1e3f0f4754176e4d71494c41f3475553768b10f84b5ce1d40fbd0e34e6bfbb864ee35858ad4dd2cf31e02fc4a154b724d7f1
Expand Down Expand Up @@ -1029,6 +1040,13 @@ __metadata:
languageName: node
linkType: hard

"minimalistic-assert@npm:^1.0.1":
version: 1.0.1
resolution: "minimalistic-assert@npm:1.0.1"
checksum: cc7974a9268fbf130fb055aff76700d7e2d8be5f761fb5c60318d0ed010d839ab3661a533ad29a5d37653133385204c503bfac995aaa4236f4e847461ea32ba7
languageName: node
linkType: hard

"minimatch@npm:^3.0.4":
version: 3.0.4
resolution: "minimatch@npm:3.0.4"
Expand Down

0 comments on commit bdea408

Please sign in to comment.