@palgroup/simstream 0.9.0 → 0.11.0
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/dist/index.d.ts +13 -0
- package/dist/index.js +28 -1
- package/dist/organization.d.ts +31 -0
- package/dist/organization.js +43 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -301,6 +301,17 @@ export declare class SimStream {
|
|
|
301
301
|
* because the server is the one that knows how quickly the queue is moving.
|
|
302
302
|
*/
|
|
303
303
|
startSession(opts?: StartOptions): Promise<Session>;
|
|
304
|
+
/**
|
|
305
|
+
* Claim a simulator, or take a place in line and hand the ticket back rather than wait on it.
|
|
306
|
+
*
|
|
307
|
+
* startSession({ wait: true }) waits inside the call, which suits a script and not a service: a server that answers a
|
|
308
|
+
* person while they wait keeps the TICKET — in its own store, across its own restarts — and collects it with
|
|
309
|
+
* pollTicket. The session request is the same one startSession sends, with a place in line always asked for.
|
|
310
|
+
*/
|
|
311
|
+
requestSession(opts?: Omit<StartOptions, 'wait' | 'timeoutMs' | 'signal' | 'onQueue'>): Promise<Session | {
|
|
312
|
+
ticket: string;
|
|
313
|
+
position: number;
|
|
314
|
+
}>;
|
|
304
315
|
/** Where a queued session got to, without waiting for it. */
|
|
305
316
|
pollTicket(ticket: string): Promise<Session | {
|
|
306
317
|
position: number;
|
|
@@ -542,4 +553,6 @@ export declare class SimStream {
|
|
|
542
553
|
export { resolveSource, isCertain } from './source';
|
|
543
554
|
export type { SourceAnswer, SourceConfidence } from './source';
|
|
544
555
|
export { SimStreamAdmin } from './admin';
|
|
556
|
+
export { SimStreamOrganization } from './organization';
|
|
557
|
+
export type { OrganizationOptions, CreatedProject } from './organization';
|
|
545
558
|
export type { AdminOptions, Customer } from './admin';
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* separation has stopped being real.
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SimStreamAdmin = exports.isCertain = exports.resolveSource = exports.SimStream = exports.SimStreamError = void 0;
|
|
15
|
+
exports.SimStreamOrganization = exports.SimStreamAdmin = exports.isCertain = exports.resolveSource = exports.SimStream = exports.SimStreamError = void 0;
|
|
16
16
|
class SimStreamError extends Error {
|
|
17
17
|
code;
|
|
18
18
|
status;
|
|
@@ -73,6 +73,31 @@ class SimStream {
|
|
|
73
73
|
}
|
|
74
74
|
throw await this.errorFor(res);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Claim a simulator, or take a place in line and hand the ticket back rather than wait on it.
|
|
78
|
+
*
|
|
79
|
+
* startSession({ wait: true }) waits inside the call, which suits a script and not a service: a server that answers a
|
|
80
|
+
* person while they wait keeps the TICKET — in its own store, across its own restarts — and collects it with
|
|
81
|
+
* pollTicket. The session request is the same one startSession sends, with a place in line always asked for.
|
|
82
|
+
*/
|
|
83
|
+
async requestSession(opts = {}) {
|
|
84
|
+
const res = await this.request('POST', this.sessionUrl(opts.ttl), {
|
|
85
|
+
app: opts.app,
|
|
86
|
+
build: opts.build,
|
|
87
|
+
channel: opts.channel,
|
|
88
|
+
launch: opts.launch,
|
|
89
|
+
mode: opts.mode,
|
|
90
|
+
queue: true,
|
|
91
|
+
device: opts.device,
|
|
92
|
+
});
|
|
93
|
+
if (res.status === 200)
|
|
94
|
+
return (await res.json());
|
|
95
|
+
if (res.status === 202) {
|
|
96
|
+
const queued = (await res.json());
|
|
97
|
+
return { ticket: queued.ticket, position: queued.position };
|
|
98
|
+
}
|
|
99
|
+
throw await this.errorFor(res);
|
|
100
|
+
}
|
|
76
101
|
/** Where a queued session got to, without waiting for it. */
|
|
77
102
|
async pollTicket(ticket) {
|
|
78
103
|
const res = await this.request('GET', `/api/session?ticket=${encodeURIComponent(ticket)}`);
|
|
@@ -481,3 +506,5 @@ Object.defineProperty(exports, "resolveSource", { enumerable: true, get: functio
|
|
|
481
506
|
Object.defineProperty(exports, "isCertain", { enumerable: true, get: function () { return source_1.isCertain; } });
|
|
482
507
|
var admin_1 = require("./admin");
|
|
483
508
|
Object.defineProperty(exports, "SimStreamAdmin", { enumerable: true, get: function () { return admin_1.SimStreamAdmin; } });
|
|
509
|
+
var organization_1 = require("./organization");
|
|
510
|
+
Object.defineProperty(exports, "SimStreamOrganization", { enumerable: true, get: function () { return organization_1.SimStreamOrganization; } });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An organization's own hand: making the projects its keys belong to.
|
|
3
|
+
*
|
|
4
|
+
* Separate from the customer client for the reason the admin one is: a project's key can run simulators and upload
|
|
5
|
+
* builds for that project, and must never be able to make another project. The organization token can, and nothing
|
|
6
|
+
* but the service that owns the organization should hold it.
|
|
7
|
+
*/
|
|
8
|
+
export interface OrganizationOptions {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
/** The organization token the operator issued. Sent as x-org-token. */
|
|
11
|
+
token: string;
|
|
12
|
+
fetch?: typeof fetch;
|
|
13
|
+
}
|
|
14
|
+
/** A project the organization just made, with its first key — shown here and never again. */
|
|
15
|
+
export interface CreatedProject {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
key: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class SimStreamOrganization {
|
|
21
|
+
private readonly base;
|
|
22
|
+
private readonly token;
|
|
23
|
+
private readonly fetchImpl;
|
|
24
|
+
constructor(opts: OrganizationOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Makes a project and its first key (POST /api/projects, coordinator/dashboard.go). The key is stored hashed on the
|
|
27
|
+
* other side, so this answer is the only place it exists: keep it before dropping the response. A name is unique
|
|
28
|
+
* inside the organization; a second project under the same name is refused.
|
|
29
|
+
*/
|
|
30
|
+
createProject(name: string): Promise<CreatedProject>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* An organization's own hand: making the projects its keys belong to.
|
|
4
|
+
*
|
|
5
|
+
* Separate from the customer client for the reason the admin one is: a project's key can run simulators and upload
|
|
6
|
+
* builds for that project, and must never be able to make another project. The organization token can, and nothing
|
|
7
|
+
* but the service that owns the organization should hold it.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SimStreamOrganization = void 0;
|
|
11
|
+
class SimStreamOrganization {
|
|
12
|
+
base;
|
|
13
|
+
token;
|
|
14
|
+
fetchImpl;
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
if (!opts.baseUrl)
|
|
17
|
+
throw new Error('baseUrl is required');
|
|
18
|
+
if (!opts.token)
|
|
19
|
+
throw new Error('token is required');
|
|
20
|
+
this.base = opts.baseUrl.replace(/\/+$/, '');
|
|
21
|
+
this.token = opts.token;
|
|
22
|
+
this.fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Makes a project and its first key (POST /api/projects, coordinator/dashboard.go). The key is stored hashed on the
|
|
26
|
+
* other side, so this answer is the only place it exists: keep it before dropping the response. A name is unique
|
|
27
|
+
* inside the organization; a second project under the same name is refused.
|
|
28
|
+
*/
|
|
29
|
+
async createProject(name) {
|
|
30
|
+
const res = await this.fetchImpl(`${this.base}/api/projects`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: { 'x-org-token': this.token, 'content-type': 'application/json' },
|
|
33
|
+
body: JSON.stringify({ name }),
|
|
34
|
+
});
|
|
35
|
+
if (!res.ok)
|
|
36
|
+
throw new Error(`simstream: the project could not be made (${res.status}): ${(await res.text().catch(() => '')).trim()}`);
|
|
37
|
+
const made = (await res.json());
|
|
38
|
+
if (!made.id || !made.key)
|
|
39
|
+
throw new Error('simstream: the coordinator made a project with no id or key');
|
|
40
|
+
return { id: made.id, name: made.name ?? name, key: made.key };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.SimStreamOrganization = SimStreamOrganization;
|