@somewhere-cloud/cli 0.38.148 → 0.38.149
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/CHANGELOG.md +4 -0
- package/README.md +6 -4
- package/dist/lib/bundle.js +2365 -2162
- package/dist/lib/bundle.js.map +3 -3
- package/dist/types/lib/app-test.d.ts +7 -2
- package/dist/types/lib/test-identities.d.ts +5 -0
- package/dist/types/testing.d.ts +3 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
- package/src/testing.ts +17 -3
|
@@ -18,16 +18,21 @@ export interface DataRequest {
|
|
|
18
18
|
* - empty: a list with no rows or a get with null (a missing row and a hidden row look the same);
|
|
19
19
|
* - refused: 401/403;
|
|
20
20
|
* - missing-or-refused: 404 DATA_NOT_FOUND on update/delete (a missing row and a refused write look the same);
|
|
21
|
+
* - missing-contract: 400 DATA_CONTRACT_MISSING (the request did not supply a digest);
|
|
21
22
|
* - malformed: 400/405/413/415, or 403 DATA_ORIGIN_FORBIDDEN (the request is wrong; it proves nothing about access);
|
|
22
23
|
* - stale-contract: 409 DATA_CONTRACT_MISMATCH (the app changed since the contract was read; it proves nothing);
|
|
23
24
|
* - error: anything else, such as 409 DATA_CONFLICT (a unique-key conflict). */
|
|
24
|
-
export type DataKind = 'ok' | 'empty' | 'refused' | 'missing-or-refused' | 'malformed' | 'stale-contract' | 'error';
|
|
25
|
+
export type DataKind = 'ok' | 'empty' | 'refused' | 'missing-or-refused' | 'missing-contract' | 'malformed' | 'stale-contract' | 'error';
|
|
25
26
|
export interface DataResult {
|
|
26
27
|
status: number;
|
|
27
28
|
kind: DataKind;
|
|
28
29
|
data: unknown;
|
|
29
30
|
error: string | null;
|
|
30
31
|
message: string | null;
|
|
32
|
+
access?: {
|
|
33
|
+
filtered: true;
|
|
34
|
+
};
|
|
35
|
+
current_contract_digest?: string;
|
|
31
36
|
}
|
|
32
37
|
type Who = Page | BrowserContext | APIRequestContext;
|
|
33
38
|
/** One check's outcome, including whether a prerequisite kept it from running. */
|
|
@@ -77,7 +82,7 @@ export declare function undeployedChanges(root: string, projectId: string, previ
|
|
|
77
82
|
changed: string[];
|
|
78
83
|
} | null;
|
|
79
84
|
/** What a data-endpoint answer means (see DataKind). */
|
|
80
|
-
export declare function classifyData(status: number, raw: unknown): DataResult;
|
|
85
|
+
export declare function classifyData(status: number, raw: unknown, operation?: string): DataResult;
|
|
81
86
|
export declare class AppTest {
|
|
82
87
|
readonly root: string;
|
|
83
88
|
private readonly control;
|
|
@@ -48,6 +48,11 @@ export declare function ensureGitignored(root: string): 'present' | 'added' | 'c
|
|
|
48
48
|
* to touch the filesystem or the API is validated here: an actor's state file is always exactly
|
|
49
49
|
* `<name>.state.json` for a valid actor name, so cleanup can never delete outside .somewhere/test/. */
|
|
50
50
|
export declare function readManifest(root: string): TestManifest | null;
|
|
51
|
+
/** Read the prepared actor's app session for this exact linked target. */
|
|
52
|
+
export declare function preparedActorSession(root: string, target: {
|
|
53
|
+
projectId: string;
|
|
54
|
+
origin: string;
|
|
55
|
+
}, name: string): string;
|
|
51
56
|
export declare function writeManifest(root: string, manifest: TestManifest): void;
|
|
52
57
|
/** The server's own times, read from the access token (not verified here; the server does that). */
|
|
53
58
|
export declare function tokenTimes(accessToken: string): {
|
package/dist/types/testing.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export declare class UserSession {
|
|
2
2
|
readonly origin: string;
|
|
3
3
|
private cookies;
|
|
4
|
+
private target?;
|
|
4
5
|
constructor(baseUrl: string);
|
|
5
6
|
request(path: string, init?: RequestInit): Promise<Response>;
|
|
6
7
|
post(path: string, body: unknown): Promise<Response>;
|
|
8
|
+
/** Use this session's cookies and the linked app's declared data contract. */
|
|
9
|
+
data(table: string, request: DataRequest): Promise<Response>;
|
|
7
10
|
data(table: string, contract: string, request: DataRequest): Promise<Response>;
|
|
8
11
|
}
|
|
9
12
|
export type DataRequest = {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@somewhere-cloud/cli",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.149",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@somewhere-cloud/cli",
|
|
9
|
-
"version": "0.38.
|
|
9
|
+
"version": "0.38.149",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"bin": {
|
|
12
12
|
"somewhere": "bin/somewhere.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@somewhere-cloud/cli",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.149",
|
|
4
4
|
"description": "CLI for somewhere.cloud — auth, projects, deploy, pull, promote, db, logs, env, MCP bridge.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"somewhere",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
},
|
|
67
67
|
"bundleDependencies": [],
|
|
68
68
|
"bundledDependencies": [],
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "b4c26f73cd5dc0cc93ada5dcf041df45dbc503e8"
|
|
70
70
|
}
|
package/src/testing.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { ApiClient } from './lib/client.js';
|
|
2
|
+
import { getToken, loadProjectConfig } from './lib/config.js';
|
|
3
|
+
import { fixtureTestTarget, type TestTarget } from './lib/test-target.js';
|
|
4
|
+
|
|
1
5
|
// Node 22.19+: native fetch, cookie storage and TypeScript; no test dependencies.
|
|
2
6
|
export class UserSession {
|
|
3
7
|
readonly origin: string;
|
|
4
8
|
private cookies = new Map<string, string>();
|
|
9
|
+
private target?: Promise<TestTarget>;
|
|
5
10
|
constructor(baseUrl: string) { this.origin = new URL(baseUrl).origin; }
|
|
6
11
|
async request(path: string, init: RequestInit = {}): Promise<Response> {
|
|
7
12
|
const url = new URL(path, this.origin);
|
|
@@ -20,9 +25,18 @@ export class UserSession {
|
|
|
20
25
|
post(path: string, body: unknown): Promise<Response> {
|
|
21
26
|
return this.request(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
22
27
|
}
|
|
23
|
-
|
|
24
|
-
data(table: string,
|
|
25
|
-
|
|
28
|
+
/** Use this session's cookies and the linked app's declared data contract. */
|
|
29
|
+
data(table: string, request: DataRequest): Promise<Response>;
|
|
30
|
+
data(table: string, contract: string, request: DataRequest): Promise<Response>;
|
|
31
|
+
async data(table: string, requestOrContract: DataRequest | string, request?: DataRequest): Promise<Response> {
|
|
32
|
+
if (typeof requestOrContract === 'string') {
|
|
33
|
+
return this.post('/__sw/data', { ...request, table, contract: requestOrContract });
|
|
34
|
+
}
|
|
35
|
+
const projectId = loadProjectConfig()?.project_id;
|
|
36
|
+
if (!projectId) throw new Error('Use the data helper from a linked project folder.');
|
|
37
|
+
const target = await (this.target ??= fixtureTestTarget(new ApiClient(process.env.SW_TEST_TARGET ? null : getToken()), projectId));
|
|
38
|
+
if (target.origin !== this.origin) throw new Error('This session belongs to a different app than the linked test target.');
|
|
39
|
+
return this.post('/__sw/data', { ...requestOrContract, table, contract: target.contractDigest ?? '' });
|
|
26
40
|
}
|
|
27
41
|
}
|
|
28
42
|
export type DataRequest =
|