@scenario-labs/sdk 2.2.1 → 2.4.0-alpha.1
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 +35 -0
- package/client.d.mts.map +1 -1
- package/client.d.ts.map +1 -1
- package/client.js +9 -1
- package/client.js.map +1 -1
- package/client.mjs +9 -1
- package/client.mjs.map +1 -1
- package/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/lib/auth-refresh.d.mts +52 -0
- package/lib/auth-refresh.d.mts.map +1 -0
- package/lib/auth-refresh.d.ts +52 -0
- package/lib/auth-refresh.d.ts.map +1 -0
- package/lib/auth-refresh.js +81 -0
- package/lib/auth-refresh.js.map +1 -0
- package/lib/auth-refresh.mjs +78 -0
- package/lib/auth-refresh.mjs.map +1 -0
- package/lib/generate.js +7 -7
- package/lib/generate.js.map +1 -1
- package/lib/generate.mjs +7 -7
- package/lib/generate.mjs.map +1 -1
- package/lib/job.d.mts +15 -3
- package/lib/job.d.mts.map +1 -1
- package/lib/job.d.ts +15 -3
- package/lib/job.d.ts.map +1 -1
- package/lib/job.js +22 -8
- package/lib/job.js.map +1 -1
- package/lib/job.mjs +22 -8
- package/lib/job.mjs.map +1 -1
- package/lib/models.d.mts +8 -2
- package/lib/models.d.mts.map +1 -1
- package/lib/models.d.ts +8 -2
- package/lib/models.d.ts.map +1 -1
- package/lib/models.js +13 -5
- package/lib/models.js.map +1 -1
- package/lib/models.mjs +13 -5
- package/lib/models.mjs.map +1 -1
- package/lib/scenario.d.mts +28 -13
- package/lib/scenario.d.mts.map +1 -1
- package/lib/scenario.d.ts +28 -13
- package/lib/scenario.d.ts.map +1 -1
- package/lib/scenario.js +31 -12
- package/lib/scenario.js.map +1 -1
- package/lib/scenario.mjs +31 -12
- package/lib/scenario.mjs.map +1 -1
- package/lib/scope.d.mts +41 -0
- package/lib/scope.d.mts.map +1 -0
- package/lib/scope.d.ts +41 -0
- package/lib/scope.d.ts.map +1 -0
- package/lib/scope.js +55 -0
- package/lib/scope.js.map +1 -0
- package/lib/scope.mjs +49 -0
- package/lib/scope.mjs.map +1 -0
- package/lib/upload.d.mts +15 -3
- package/lib/upload.d.mts.map +1 -1
- package/lib/upload.d.ts +15 -3
- package/lib/upload.d.ts.map +1 -1
- package/lib/upload.js +29 -12
- package/lib/upload.js.map +1 -1
- package/lib/upload.mjs +29 -12
- package/lib/upload.mjs.map +1 -1
- package/lib/workflow.d.mts +8 -2
- package/lib/workflow.d.mts.map +1 -1
- package/lib/workflow.d.ts +8 -2
- package/lib/workflow.d.ts.map +1 -1
- package/lib/workflow.js +14 -6
- package/lib/workflow.js.map +1 -1
- package/lib/workflow.mjs +14 -6
- package/lib/workflow.mjs.map +1 -1
- package/lib/workflow_converter.d.mts +8 -2
- package/lib/workflow_converter.d.mts.map +1 -1
- package/lib/workflow_converter.d.ts +8 -2
- package/lib/workflow_converter.d.ts.map +1 -1
- package/lib/workflow_converter.js +83 -19
- package/lib/workflow_converter.js.map +1 -1
- package/lib/workflow_converter.mjs +83 -19
- package/lib/workflow_converter.mjs.map +1 -1
- package/lib/workflow_import_validator.d.mts +1 -1
- package/lib/workflow_import_validator.d.mts.map +1 -1
- package/lib/workflow_import_validator.d.ts +1 -1
- package/lib/workflow_import_validator.d.ts.map +1 -1
- package/lib/workflow_import_validator.js +1 -0
- package/lib/workflow_import_validator.js.map +1 -1
- package/lib/workflow_import_validator.mjs +1 -0
- package/lib/workflow_import_validator.mjs.map +1 -1
- package/package.json +9 -3
- package/resources/assets/assets.d.mts +1 -1
- package/resources/assets/assets.d.mts.map +1 -1
- package/resources/assets/assets.d.ts +1 -1
- package/resources/assets/assets.d.ts.map +1 -1
- package/resources/generate.d.mts +594 -10
- package/resources/generate.d.mts.map +1 -1
- package/resources/generate.d.ts +594 -10
- package/resources/generate.d.ts.map +1 -1
- package/resources/generate.js +2 -2
- package/resources/generate.js.map +1 -1
- package/resources/generate.mjs +2 -2
- package/resources/generate.mjs.map +1 -1
- package/resources/jobs.d.mts +3 -3
- package/resources/jobs.d.mts.map +1 -1
- package/resources/jobs.d.ts +3 -3
- package/resources/jobs.d.ts.map +1 -1
- package/resources/models/examples.d.mts +2 -2
- package/resources/models/examples.d.mts.map +1 -1
- package/resources/models/examples.d.ts +2 -2
- package/resources/models/examples.d.ts.map +1 -1
- package/resources/models/models.d.mts +126 -7
- package/resources/models/models.d.mts.map +1 -1
- package/resources/models/models.d.ts +126 -7
- package/resources/models/models.d.ts.map +1 -1
- package/resources/models/models.js.map +1 -1
- package/resources/models/models.mjs.map +1 -1
- package/resources/models/train.d.mts +106 -3
- package/resources/models/train.d.mts.map +1 -1
- package/resources/models/train.d.ts +106 -3
- package/resources/models/train.d.ts.map +1 -1
- package/resources/usages.d.mts +23 -3
- package/resources/usages.d.mts.map +1 -1
- package/resources/usages.d.ts +23 -3
- package/resources/usages.d.ts.map +1 -1
- package/resources/workflows.d.mts +22 -5
- package/resources/workflows.d.mts.map +1 -1
- package/resources/workflows.d.ts +22 -5
- package/resources/workflows.d.ts.map +1 -1
- package/resources/workflows.js +4 -1
- package/resources/workflows.js.map +1 -1
- package/resources/workflows.mjs +4 -1
- package/resources/workflows.mjs.map +1 -1
- package/src/client.ts +9 -1
- package/src/index.ts +1 -0
- package/src/lib/auth-refresh.ts +98 -0
- package/src/lib/generate.ts +7 -7
- package/src/lib/job.ts +29 -7
- package/src/lib/models.ts +14 -4
- package/src/lib/scenario.ts +51 -13
- package/src/lib/scope.ts +68 -0
- package/src/lib/upload.ts +36 -11
- package/src/lib/workflow.ts +15 -5
- package/src/lib/workflow_converter.ts +128 -19
- package/src/lib/workflow_import_validator.ts +3 -1
- package/src/resources/assets/assets.ts +1 -1
- package/src/resources/generate.ts +713 -12
- package/src/resources/jobs.ts +3 -3
- package/src/resources/models/examples.ts +2 -2
- package/src/resources/models/models.ts +189 -7
- package/src/resources/models/train.ts +138 -3
- package/src/resources/usages.ts +27 -1
- package/src/resources/workflows.ts +24 -5
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
package/lib/models.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { GenerateRunModelParams, GenerateRunModelResponse } from "../resour
|
|
|
4
4
|
import { Models, type ModelRetrieveParams, type ModelRetrieveResponse } from "../resources/models/models.js";
|
|
5
5
|
import { Train, type TrainTriggerParams, type TrainTriggerResponse } from "../resources/models/train.js";
|
|
6
6
|
import { type WithJob } from "./job.js";
|
|
7
|
+
import { type Scope } from "./scope.js";
|
|
7
8
|
import type { Scenario } from "./scenario.js";
|
|
8
9
|
/**
|
|
9
10
|
* Enhanced Model entity with helper methods.
|
|
@@ -18,15 +19,20 @@ import type { Scenario } from "./scenario.js";
|
|
|
18
19
|
*/
|
|
19
20
|
export declare class ModelEntity {
|
|
20
21
|
/** @internal */ readonly _client: Scenario;
|
|
22
|
+
/** @internal scope captured from the retrieve call — replayed when `.run()` is invoked without an explicit query override. */
|
|
23
|
+
readonly _scope?: Scope;
|
|
21
24
|
/**
|
|
22
25
|
* Generate with this model. Shortcut for
|
|
23
26
|
* `client.generate.runModel(this.id, params)`.
|
|
24
27
|
*
|
|
25
28
|
* Returns an enhanced response where `response.job` has `.wait()`.
|
|
29
|
+
* If the model was fetched with a `projectId` scope (per-call override or
|
|
30
|
+
* client default), that scope is reused unless overridden by
|
|
31
|
+
* `options.query`.
|
|
26
32
|
*/
|
|
27
33
|
run(this: ModelEntity & ModelRetrieveResponse.Model, params: GenerateRunModelParams, options?: RequestOptions): APIPromise<WithJob<GenerateRunModelResponse>>;
|
|
28
|
-
/** @internal Create a ModelEntity wrapping raw model data. */
|
|
29
|
-
static from(client: Scenario, data: ModelRetrieveResponse.Model): ModelRetrieveResponse.Model & ModelEntity;
|
|
34
|
+
/** @internal Create a ModelEntity wrapping raw model data, optionally remembering the originating scope. */
|
|
35
|
+
static from(client: Scenario, data: ModelRetrieveResponse.Model, scope?: Scope): ModelRetrieveResponse.Model & ModelEntity;
|
|
30
36
|
}
|
|
31
37
|
/** Enhanced retrieve response where `model` has `.run()` on top of its original fields. */
|
|
32
38
|
export type EnhancedModelRetrieveResponse = Omit<ModelRetrieveResponse, 'model'> & {
|
package/lib/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/lib/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,+BAA4B;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,uCAAoC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,iCAA8B;AAC9F,OAAO,EAAE,MAAM,EAAE,KAAK,mBAAmB,EAAE,KAAK,qBAAqB,EAAE,sCAAmC;AAC1G,OAAO,EAAE,KAAK,EAAE,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,qCAAkC;AACtG,OAAO,EAAE,KAAK,OAAO,EAAc,iBAAc;
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/lib/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,+BAA4B;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,uCAAoC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,iCAA8B;AAC9F,OAAO,EAAE,MAAM,EAAE,KAAK,mBAAmB,EAAE,KAAK,qBAAqB,EAAE,sCAAmC;AAC1G,OAAO,EAAE,KAAK,EAAE,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,qCAAkC;AACtG,OAAO,EAAE,KAAK,OAAO,EAAc,iBAAc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ED
|
@@ -4,6 +4,7 @@ exports.EnhancedModels = exports.EnhancedTrain = exports.ModelEntity = void 0;
|
|
|
4
4
|
const models_1 = require("../resources/models/models.js");
|
|
5
5
|
const train_1 = require("../resources/models/train.js");
|
|
6
6
|
const job_1 = require("./job.js");
|
|
7
|
+
const scope_1 = require("./scope.js");
|
|
7
8
|
/**
|
|
8
9
|
* Enhanced Model entity with helper methods.
|
|
9
10
|
* Has all original model fields plus `.run()`.
|
|
@@ -21,14 +22,19 @@ class ModelEntity {
|
|
|
21
22
|
* `client.generate.runModel(this.id, params)`.
|
|
22
23
|
*
|
|
23
24
|
* Returns an enhanced response where `response.job` has `.wait()`.
|
|
25
|
+
* If the model was fetched with a `projectId` scope (per-call override or
|
|
26
|
+
* client default), that scope is reused unless overridden by
|
|
27
|
+
* `options.query`.
|
|
24
28
|
*/
|
|
25
29
|
run(params, options) {
|
|
26
|
-
return this._client.generate.runModel(this.id, params, options);
|
|
30
|
+
return this._client.generate.runModel(this.id, params, (0, scope_1.withScope)(this._scope, options));
|
|
27
31
|
}
|
|
28
|
-
/** @internal Create a ModelEntity wrapping raw model data. */
|
|
29
|
-
static from(client, data) {
|
|
32
|
+
/** @internal Create a ModelEntity wrapping raw model data, optionally remembering the originating scope. */
|
|
33
|
+
static from(client, data, scope) {
|
|
30
34
|
const entity = Object.assign(Object.create(ModelEntity.prototype), data);
|
|
31
35
|
Object.defineProperty(entity, '_client', { value: client, enumerable: false });
|
|
36
|
+
if (scope)
|
|
37
|
+
Object.defineProperty(entity, '_scope', { value: scope, enumerable: false });
|
|
32
38
|
return entity;
|
|
33
39
|
}
|
|
34
40
|
}
|
|
@@ -39,7 +45,7 @@ exports.ModelEntity = ModelEntity;
|
|
|
39
45
|
*/
|
|
40
46
|
class EnhancedTrain extends train_1.Train {
|
|
41
47
|
trigger(modelID, params, options) {
|
|
42
|
-
return (0, job_1.enhanceJob)(this._client, super.trigger(modelID, params, options));
|
|
48
|
+
return (0, job_1.enhanceJob)(this._client, super.trigger(modelID, params, options), options);
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
exports.EnhancedTrain = EnhancedTrain;
|
|
@@ -52,9 +58,11 @@ exports.EnhancedTrain = EnhancedTrain;
|
|
|
52
58
|
class EnhancedModels extends models_1.Models {
|
|
53
59
|
train = new EnhancedTrain(this._client);
|
|
54
60
|
retrieve(modelID, query = {}, options) {
|
|
61
|
+
const client = this._client;
|
|
62
|
+
const scope = (0, scope_1.effectiveScope)(options, client.projectId);
|
|
55
63
|
return super.retrieve(modelID, query, options)._thenUnwrap((data) => ({
|
|
56
64
|
...data,
|
|
57
|
-
model: ModelEntity.from(
|
|
65
|
+
model: ModelEntity.from(client, data.model, scope),
|
|
58
66
|
}));
|
|
59
67
|
}
|
|
60
68
|
}
|
package/lib/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/lib/models.ts"],"names":[],"mappings":";;;AAGA,0DAA0G;AAC1G,wDAAsG;AACtG,kCAAiD;
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/lib/models.ts"],"names":[],"mappings":";;;AAGA,0DAA0G;AAC1G,wDAAsG;AACtG,kCAAiD;AACjD,sCAAgE;AAIhE;;;;;;;;;;GAUG;AACH,MAAa,WAAW;IAKtB;;;;;;;;OAQG;IACH,GAAG,CAED,MAA8B,EAC9B,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAA,iBAAS,EAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,4GAA4G;IAC5G,MAAM,CAAC,IAAI,CACT,MAAgB,EAChB,IAAiC,EACjC,KAAa;QAEb,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,EA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 +1,7 @@
|
|
|
1
1
|
import { Models } from "../resources/models/models.mjs";
|
|
2
2
|
import { Train } from "../resources/models/train.mjs";
|
|
3
3
|
import { enhanceJob } from "./job.mjs";
|
|
4
|
+
import { effectiveScope, withScope } from "./scope.mjs";
|
|
4
5
|
/**
|
|
5
6
|
* Enhanced Model entity with helper methods.
|
|
6
7
|
* Has all original model fields plus `.run()`.
|
|
@@ -18,14 +19,19 @@ export class ModelEntity {
|
|
|
18
19
|
* `client.generate.runModel(this.id, params)`.
|
|
19
20
|
*
|
|
20
21
|
* Returns an enhanced response where `response.job` has `.wait()`.
|
|
22
|
+
* If the model was fetched with a `projectId` scope (per-call override or
|
|
23
|
+
* client default), that scope is reused unless overridden by
|
|
24
|
+
* `options.query`.
|
|
21
25
|
*/
|
|
22
26
|
run(params, options) {
|
|
23
|
-
return this._client.generate.runModel(this.id, params, options);
|
|
27
|
+
return this._client.generate.runModel(this.id, params, withScope(this._scope, options));
|
|
24
28
|
}
|
|
25
|
-
/** @internal Create a ModelEntity wrapping raw model data. */
|
|
26
|
-
static from(client, data) {
|
|
29
|
+
/** @internal Create a ModelEntity wrapping raw model data, optionally remembering the originating scope. */
|
|
30
|
+
static from(client, data, scope) {
|
|
27
31
|
const entity = Object.assign(Object.create(ModelEntity.prototype), data);
|
|
28
32
|
Object.defineProperty(entity, '_client', { value: client, enumerable: false });
|
|
33
|
+
if (scope)
|
|
34
|
+
Object.defineProperty(entity, '_scope', { value: scope, enumerable: false });
|
|
29
35
|
return entity;
|
|
30
36
|
}
|
|
31
37
|
}
|
|
@@ -35,7 +41,7 @@ export class ModelEntity {
|
|
|
35
41
|
*/
|
|
36
42
|
export class EnhancedTrain extends Train {
|
|
37
43
|
trigger(modelID, params, options) {
|
|
38
|
-
return enhanceJob(this._client, super.trigger(modelID, params, options));
|
|
44
|
+
return enhanceJob(this._client, super.trigger(modelID, params, options), options);
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
/**
|
|
@@ -47,9 +53,11 @@ export class EnhancedTrain extends Train {
|
|
|
47
53
|
export class EnhancedModels extends Models {
|
|
48
54
|
train = new EnhancedTrain(this._client);
|
|
49
55
|
retrieve(modelID, query = {}, options) {
|
|
56
|
+
const client = this._client;
|
|
57
|
+
const scope = effectiveScope(options, client.projectId);
|
|
50
58
|
return super.retrieve(modelID, query, options)._thenUnwrap((data) => ({
|
|
51
59
|
...data,
|
|
52
|
-
model: ModelEntity.from(
|
|
60
|
+
model: ModelEntity.from(client, data.model, scope),
|
|
53
61
|
}));
|
|
54
62
|
}
|
|
55
63
|
}
|
package/lib/models.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.mjs","sourceRoot":"","sources":["../src/lib/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAwD,uCAAmC;AAC1G,OAAO,EAAE,KAAK,EAAsD,sCAAkC;AACtG,OAAO,EAAgB,UAAU,EAAE,kBAAc;
|
|
1
|
+
{"version":3,"file":"models.mjs","sourceRoot":"","sources":["../src/lib/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAwD,uCAAmC;AAC1G,OAAO,EAAE,KAAK,EAAsD,sCAAkC;AACtG,OAAO,EAAgB,UAAU,EAAE,kBAAc;AACjD,OAAO,EAAc,cAAc,EAAE,SAAS,EAAE,oBAAgB;AAIhE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,WAAW;IAKtB;;;;;;;;OAQG;IACH,GAAG,CAED,MAA8B,EAC9B,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,4GAA4G;IAC5G,MAAM,CAAC,IAAI,CACT,MAAgB,EAChB,IAAiC,EACjC,KAAa;QAEb,MAAM,MAAM,GAAG,MAAM,CAAC,MAA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
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { Scenario as BaseScenario } from "../client.mjs";
|
|
1
|
+
import { Scenario as BaseScenario, type ClientOptions as BaseClientOptions } from "../client.mjs";
|
|
2
2
|
import { EnhancedAssets } from "./asset.mjs";
|
|
3
3
|
import { EnhancedGenerate } from "./generate.mjs";
|
|
4
4
|
import { EnhancedJobs } from "./job.mjs";
|
|
5
5
|
import { EnhancedModels } from "./models.mjs";
|
|
6
6
|
import { EnhancedUploads } from "./upload.mjs";
|
|
7
7
|
import { EnhancedWorkflows } from "./workflow.mjs";
|
|
8
|
+
export interface ClientOptions extends BaseClientOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Default project to scope every request to (sent as `?projectId=...`).
|
|
11
|
+
*
|
|
12
|
+
* Useful with `bearerAuth` when the user belongs to multiple projects —
|
|
13
|
+
* the server derives the team from the project, so `teamId` doesn't need
|
|
14
|
+
* to be configured at construction time. With `apiKey` auth, the project
|
|
15
|
+
* is already implied by the key and this option is unnecessary.
|
|
16
|
+
*
|
|
17
|
+
* Per-call `options.query.projectId` overrides this default for a single
|
|
18
|
+
* request. SDK helpers (`.wait()`, `model.run()`, ...) reuse the scope
|
|
19
|
+
* effective on the originating call, so an action created in project A
|
|
20
|
+
* keeps polling in project A even if the client default changes later.
|
|
21
|
+
*/
|
|
22
|
+
projectId?: string | null | undefined;
|
|
23
|
+
}
|
|
8
24
|
/**
|
|
9
25
|
* Enhanced Scenario client.
|
|
10
26
|
*
|
|
@@ -16,23 +32,19 @@ import { EnhancedWorkflows } from "./workflow.mjs";
|
|
|
16
32
|
* ```ts
|
|
17
33
|
* import Scenario from '@scenario-labs/sdk';
|
|
18
34
|
*
|
|
19
|
-
*
|
|
35
|
+
* // With API key — project is implied by the key.
|
|
36
|
+
* const client = new Scenario({ apiKey: '...', apiSecret: '...' });
|
|
37
|
+
*
|
|
38
|
+
* // With bearer JWT — pin a default project for all requests.
|
|
39
|
+
* const client = new Scenario({ bearerAuth: jwt, projectId: 'proj_abc' });
|
|
20
40
|
*
|
|
21
|
-
* //
|
|
22
|
-
*
|
|
41
|
+
* // Per-call override (one request only):
|
|
42
|
+
* await client.uploads.uploadFile(params, { query: { projectId: 'proj_other' } });
|
|
23
43
|
*
|
|
24
|
-
* // Enhanced: response.job.wait()
|
|
44
|
+
* // Enhanced: response.job.wait() — auto-reuses the scope of the call that produced the job
|
|
25
45
|
* const run = await client.workflows.run(workflowId, { body });
|
|
26
46
|
* const completed = await run.job.wait();
|
|
27
47
|
*
|
|
28
|
-
* // Enhanced: response.workflow.findNode()
|
|
29
|
-
* const wf = await client.workflows.retrieve(workflowId);
|
|
30
|
-
* wf.workflow.findNode('final_image');
|
|
31
|
-
*
|
|
32
|
-
* // Enhanced: generate job.wait()
|
|
33
|
-
* const gen = await client.generate.runModel(modelId, { body });
|
|
34
|
-
* const done = await gen.job.wait();
|
|
35
|
-
*
|
|
36
48
|
* // Enhanced: upload.wait()
|
|
37
49
|
* const res = await client.uploads.retrieve(uploadId);
|
|
38
50
|
* const imported = await res.upload.wait();
|
|
@@ -49,5 +61,8 @@ export declare class Scenario extends BaseScenario {
|
|
|
49
61
|
uploads: EnhancedUploads;
|
|
50
62
|
assets: EnhancedAssets;
|
|
51
63
|
jobs: EnhancedJobs;
|
|
64
|
+
/** The default project this client scopes every request to, or `null` if unset. */
|
|
65
|
+
readonly projectId: string | null;
|
|
66
|
+
constructor(options?: ClientOptions);
|
|
52
67
|
}
|
|
53
68
|
//# sourceMappingURL=scenario.d.mts.map
|
package/lib/scenario.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenario.d.mts","sourceRoot":"","sources":["../src/lib/scenario.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,sBAAkB;
|
|
1
|
+
{"version":3,"file":"scenario.d.mts","sourceRoot":"","sources":["../src/lib/scenario.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,KAAK,aAAa,IAAI,iBAAiB,EAAE,sBAAkB;AAC9F,OAAO,EAAE,cAAc,EAAE,oBAAgB;AACzC,OAAO,EAAE,gBAAgB,EAAE,uBAAmB;AAC9C,OAAO,EAAE,YAAY,EAAE,kBAAc;AACrC,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAC1C,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAC3C,OAAO,EAAE,iBAAiB,EAAE,uBAAmB;AAE/C,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,QAAS,SAAQ,YAAY;IAC/B,SAAS,EAAE,iBAAiB,CAA+B;IAC3D,QAAQ,EAAE,gBAAgB,CAA8B;IACxD,MAAM,EAAE,cAAc,CAA4B;IAClD,OAAO,EAAE,eAAe,CAA6B;IACrD,MAAM,EAAE,cAAc,CAA4B;IAClD,IAAI,EAAE,YAAY,CAA0B;IAErD,mFAAmF;IACnF,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEtB,OAAO,GAAE,aAAkB;CAexC"}
|
package/lib/scenario.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { Scenario as BaseScenario } from "../client.js";
|
|
1
|
+
import { Scenario as BaseScenario, type ClientOptions as BaseClientOptions } from "../client.js";
|
|
2
2
|
import { EnhancedAssets } from "./asset.js";
|
|
3
3
|
import { EnhancedGenerate } from "./generate.js";
|
|
4
4
|
import { EnhancedJobs } from "./job.js";
|
|
5
5
|
import { EnhancedModels } from "./models.js";
|
|
6
6
|
import { EnhancedUploads } from "./upload.js";
|
|
7
7
|
import { EnhancedWorkflows } from "./workflow.js";
|
|
8
|
+
export interface ClientOptions extends BaseClientOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Default project to scope every request to (sent as `?projectId=...`).
|
|
11
|
+
*
|
|
12
|
+
* Useful with `bearerAuth` when the user belongs to multiple projects —
|
|
13
|
+
* the server derives the team from the project, so `teamId` doesn't need
|
|
14
|
+
* to be configured at construction time. With `apiKey` auth, the project
|
|
15
|
+
* is already implied by the key and this option is unnecessary.
|
|
16
|
+
*
|
|
17
|
+
* Per-call `options.query.projectId` overrides this default for a single
|
|
18
|
+
* request. SDK helpers (`.wait()`, `model.run()`, ...) reuse the scope
|
|
19
|
+
* effective on the originating call, so an action created in project A
|
|
20
|
+
* keeps polling in project A even if the client default changes later.
|
|
21
|
+
*/
|
|
22
|
+
projectId?: string | null | undefined;
|
|
23
|
+
}
|
|
8
24
|
/**
|
|
9
25
|
* Enhanced Scenario client.
|
|
10
26
|
*
|
|
@@ -16,23 +32,19 @@ import { EnhancedWorkflows } from "./workflow.js";
|
|
|
16
32
|
* ```ts
|
|
17
33
|
* import Scenario from '@scenario-labs/sdk';
|
|
18
34
|
*
|
|
19
|
-
*
|
|
35
|
+
* // With API key — project is implied by the key.
|
|
36
|
+
* const client = new Scenario({ apiKey: '...', apiSecret: '...' });
|
|
37
|
+
*
|
|
38
|
+
* // With bearer JWT — pin a default project for all requests.
|
|
39
|
+
* const client = new Scenario({ bearerAuth: jwt, projectId: 'proj_abc' });
|
|
20
40
|
*
|
|
21
|
-
* //
|
|
22
|
-
*
|
|
41
|
+
* // Per-call override (one request only):
|
|
42
|
+
* await client.uploads.uploadFile(params, { query: { projectId: 'proj_other' } });
|
|
23
43
|
*
|
|
24
|
-
* // Enhanced: response.job.wait()
|
|
44
|
+
* // Enhanced: response.job.wait() — auto-reuses the scope of the call that produced the job
|
|
25
45
|
* const run = await client.workflows.run(workflowId, { body });
|
|
26
46
|
* const completed = await run.job.wait();
|
|
27
47
|
*
|
|
28
|
-
* // Enhanced: response.workflow.findNode()
|
|
29
|
-
* const wf = await client.workflows.retrieve(workflowId);
|
|
30
|
-
* wf.workflow.findNode('final_image');
|
|
31
|
-
*
|
|
32
|
-
* // Enhanced: generate job.wait()
|
|
33
|
-
* const gen = await client.generate.runModel(modelId, { body });
|
|
34
|
-
* const done = await gen.job.wait();
|
|
35
|
-
*
|
|
36
48
|
* // Enhanced: upload.wait()
|
|
37
49
|
* const res = await client.uploads.retrieve(uploadId);
|
|
38
50
|
* const imported = await res.upload.wait();
|
|
@@ -49,5 +61,8 @@ export declare class Scenario extends BaseScenario {
|
|
|
49
61
|
uploads: EnhancedUploads;
|
|
50
62
|
assets: EnhancedAssets;
|
|
51
63
|
jobs: EnhancedJobs;
|
|
64
|
+
/** The default project this client scopes every request to, or `null` if unset. */
|
|
65
|
+
readonly projectId: string | null;
|
|
66
|
+
constructor(options?: ClientOptions);
|
|
52
67
|
}
|
|
53
68
|
//# sourceMappingURL=scenario.d.ts.map
|
package/lib/scenario.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenario.d.ts","sourceRoot":"","sources":["../src/lib/scenario.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,qBAAkB;
|
|
1
|
+
{"version":3,"file":"scenario.d.ts","sourceRoot":"","sources":["../src/lib/scenario.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,KAAK,aAAa,IAAI,iBAAiB,EAAE,qBAAkB;AAC9F,OAAO,EAAE,cAAc,EAAE,mBAAgB;AACzC,OAAO,EAAE,gBAAgB,EAAE,sBAAmB;AAC9C,OAAO,EAAE,YAAY,EAAE,iBAAc;AACrC,OAAO,EAAE,cAAc,EAAE,oBAAiB;AAC1C,OAAO,EAAE,eAAe,EAAE,oBAAiB;AAC3C,OAAO,EAAE,iBAAiB,EAAE,sBAAmB;AAE/C,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,QAAS,SAAQ,YAAY;IAC/B,SAAS,EAAE,iBAAiB,CAA+B;IAC3D,QAAQ,EAAE,gBAAgB,CAA8B;IACxD,MAAM,EAAE,cAAc,CAA4B;IAClD,OAAO,EAAE,eAAe,CAA6B;IACrD,MAAM,EAAE,cAAc,CAA4B;IAClD,IAAI,EAAE,YAAY,CAA0B;IAErD,mFAAmF;IACnF,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEtB,OAAO,GAAE,aAAkB;CAexC"}
|
package/lib/scenario.js
CHANGED
|
@@ -19,23 +19,19 @@ const workflow_1 = require("./workflow.js");
|
|
|
19
19
|
* ```ts
|
|
20
20
|
* import Scenario from '@scenario-labs/sdk';
|
|
21
21
|
*
|
|
22
|
-
*
|
|
22
|
+
* // With API key — project is implied by the key.
|
|
23
|
+
* const client = new Scenario({ apiKey: '...', apiSecret: '...' });
|
|
23
24
|
*
|
|
24
|
-
* //
|
|
25
|
-
* const
|
|
25
|
+
* // With bearer JWT — pin a default project for all requests.
|
|
26
|
+
* const client = new Scenario({ bearerAuth: jwt, projectId: 'proj_abc' });
|
|
26
27
|
*
|
|
27
|
-
* //
|
|
28
|
+
* // Per-call override (one request only):
|
|
29
|
+
* await client.uploads.uploadFile(params, { query: { projectId: 'proj_other' } });
|
|
30
|
+
*
|
|
31
|
+
* // Enhanced: response.job.wait() — auto-reuses the scope of the call that produced the job
|
|
28
32
|
* const run = await client.workflows.run(workflowId, { body });
|
|
29
33
|
* const completed = await run.job.wait();
|
|
30
34
|
*
|
|
31
|
-
* // Enhanced: response.workflow.findNode()
|
|
32
|
-
* const wf = await client.workflows.retrieve(workflowId);
|
|
33
|
-
* wf.workflow.findNode('final_image');
|
|
34
|
-
*
|
|
35
|
-
* // Enhanced: generate job.wait()
|
|
36
|
-
* const gen = await client.generate.runModel(modelId, { body });
|
|
37
|
-
* const done = await gen.job.wait();
|
|
38
|
-
*
|
|
39
35
|
* // Enhanced: upload.wait()
|
|
40
36
|
* const res = await client.uploads.retrieve(uploadId);
|
|
41
37
|
* const imported = await res.upload.wait();
|
|
@@ -52,6 +48,29 @@ class Scenario extends client_1.Scenario {
|
|
|
52
48
|
uploads = new upload_1.EnhancedUploads(this);
|
|
53
49
|
assets = new asset_1.EnhancedAssets(this);
|
|
54
50
|
jobs = new job_1.EnhancedJobs(this);
|
|
51
|
+
/** The default project this client scopes every request to, or `null` if unset. */
|
|
52
|
+
projectId;
|
|
53
|
+
constructor(options = {}) {
|
|
54
|
+
const { projectId, defaultQuery, ...rest } = options;
|
|
55
|
+
// Strip any stale projectId from defaultQuery so the typed field is the
|
|
56
|
+
// single source of truth (matters when `withOptions` reconstructs the client).
|
|
57
|
+
const cleanedDefaultQuery = stripKey(defaultQuery, 'projectId');
|
|
58
|
+
super({
|
|
59
|
+
...rest,
|
|
60
|
+
// Pass projectId through so it lands in `_options` and survives a
|
|
61
|
+
// `withOptions()` round-trip. The base ClientOptions doesn't declare
|
|
62
|
+
// this field, hence the cast.
|
|
63
|
+
projectId,
|
|
64
|
+
defaultQuery: projectId ? { ...cleanedDefaultQuery, projectId } : cleanedDefaultQuery,
|
|
65
|
+
});
|
|
66
|
+
this.projectId = projectId ?? null;
|
|
67
|
+
}
|
|
55
68
|
}
|
|
56
69
|
exports.Scenario = Scenario;
|
|
70
|
+
function stripKey(obj, key) {
|
|
71
|
+
if (!obj || !(key in obj))
|
|
72
|
+
return obj;
|
|
73
|
+
const { [key]: _omit, ...rest } = obj;
|
|
74
|
+
return rest;
|
|
75
|
+
}
|
|
57
76
|
//# sourceMappingURL=scenario.js.map
|
package/lib/scenario.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenario.js","sourceRoot":"","sources":["../src/lib/scenario.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"scenario.js","sourceRoot":"","sources":["../src/lib/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AC;IACtC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,GAA8B,CAAC;IACjE,OAAO,IAAkB,CAAC;AAC5B,CAAC"}
|
package/lib/scenario.mjs
CHANGED
|
@@ -16,23 +16,19 @@ import { EnhancedWorkflows } from "./workflow.mjs";
|
|
|
16
16
|
* ```ts
|
|
17
17
|
* import Scenario from '@scenario-labs/sdk';
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* // With API key — project is implied by the key.
|
|
20
|
+
* const client = new Scenario({ apiKey: '...', apiSecret: '...' });
|
|
20
21
|
*
|
|
21
|
-
* //
|
|
22
|
-
* const
|
|
22
|
+
* // With bearer JWT — pin a default project for all requests.
|
|
23
|
+
* const client = new Scenario({ bearerAuth: jwt, projectId: 'proj_abc' });
|
|
23
24
|
*
|
|
24
|
-
* //
|
|
25
|
+
* // Per-call override (one request only):
|
|
26
|
+
* await client.uploads.uploadFile(params, { query: { projectId: 'proj_other' } });
|
|
27
|
+
*
|
|
28
|
+
* // Enhanced: response.job.wait() — auto-reuses the scope of the call that produced the job
|
|
25
29
|
* const run = await client.workflows.run(workflowId, { body });
|
|
26
30
|
* const completed = await run.job.wait();
|
|
27
31
|
*
|
|
28
|
-
* // Enhanced: response.workflow.findNode()
|
|
29
|
-
* const wf = await client.workflows.retrieve(workflowId);
|
|
30
|
-
* wf.workflow.findNode('final_image');
|
|
31
|
-
*
|
|
32
|
-
* // Enhanced: generate job.wait()
|
|
33
|
-
* const gen = await client.generate.runModel(modelId, { body });
|
|
34
|
-
* const done = await gen.job.wait();
|
|
35
|
-
*
|
|
36
32
|
* // Enhanced: upload.wait()
|
|
37
33
|
* const res = await client.uploads.retrieve(uploadId);
|
|
38
34
|
* const imported = await res.upload.wait();
|
|
@@ -49,5 +45,28 @@ export class Scenario extends BaseScenario {
|
|
|
49
45
|
uploads = new EnhancedUploads(this);
|
|
50
46
|
assets = new EnhancedAssets(this);
|
|
51
47
|
jobs = new EnhancedJobs(this);
|
|
48
|
+
/** The default project this client scopes every request to, or `null` if unset. */
|
|
49
|
+
projectId;
|
|
50
|
+
constructor(options = {}) {
|
|
51
|
+
const { projectId, defaultQuery, ...rest } = options;
|
|
52
|
+
// Strip any stale projectId from defaultQuery so the typed field is the
|
|
53
|
+
// single source of truth (matters when `withOptions` reconstructs the client).
|
|
54
|
+
const cleanedDefaultQuery = stripKey(defaultQuery, 'projectId');
|
|
55
|
+
super({
|
|
56
|
+
...rest,
|
|
57
|
+
// Pass projectId through so it lands in `_options` and survives a
|
|
58
|
+
// `withOptions()` round-trip. The base ClientOptions doesn't declare
|
|
59
|
+
// this field, hence the cast.
|
|
60
|
+
projectId,
|
|
61
|
+
defaultQuery: projectId ? { ...cleanedDefaultQuery, projectId } : cleanedDefaultQuery,
|
|
62
|
+
});
|
|
63
|
+
this.projectId = projectId ?? null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function stripKey(obj, key) {
|
|
67
|
+
if (!obj || !(key in obj))
|
|
68
|
+
return obj;
|
|
69
|
+
const { [key]: _omit, ...rest } = obj;
|
|
70
|
+
return rest;
|
|
52
71
|
}
|
|
53
72
|
//# sourceMappingURL=scenario.mjs.map
|
package/lib/scenario.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenario.mjs","sourceRoot":"","sources":["../src/lib/scenario.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,
|
|
1
|
+
{"version":3,"file":"scenario.mjs","sourceRoot":"","sources":["../src/lib/scenario.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAA2C,sBAAkB;AAC9F,OAAO,EAAE,cAAc,EAAE,oBAAgB;AACzC,OAAO,EAAE,gBAAgB,EAAE,uBAAmB;AAC9C,OAAO,EAAE,YAAY,EAAE,kBAAc;AACrC,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAC1C,OAAO,EAA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GAA8B,CAAC;IACjE,OAAO,IAAkB,CAAC;AAC5B,CAAC"}
|
package/lib/scope.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RequestOptions } from "../internal/request-options.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Per-request project scope.
|
|
4
|
+
*
|
|
5
|
+
* With API-key auth, the server resolves the project from the key. With
|
|
6
|
+
* bearer (JWT) auth a user can belong to multiple projects, so callers must
|
|
7
|
+
* specify which one to act on by passing `projectId` as a query param
|
|
8
|
+
* (the server derives `teamId` from it — no need to send it explicitly).
|
|
9
|
+
*
|
|
10
|
+
* SDK helpers like `Job.wait()` and `Upload.wait()` make follow-up calls
|
|
11
|
+
* internally — they capture the scope effective on the originating call and
|
|
12
|
+
* forward it on each retry, so an action created in project A always polls
|
|
13
|
+
* in project A even if the client default changes between calls.
|
|
14
|
+
*/
|
|
15
|
+
export interface Scope {
|
|
16
|
+
projectId?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Extract `projectId` from a `RequestOptions.query`. Returns `undefined` if absent. */
|
|
19
|
+
export declare function extractScope(options?: RequestOptions): Scope | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the effective scope for an outgoing call:
|
|
22
|
+
* 1. If the per-call options carry a `projectId` query — use that (the explicit override wins).
|
|
23
|
+
* 2. Otherwise, fall back to the client's default `projectId`.
|
|
24
|
+
* 3. If neither is set (e.g. API-key auth with implicit scope), return `undefined`.
|
|
25
|
+
*
|
|
26
|
+
* Returns the snapshot we want to *capture on an enhanced entity* so that
|
|
27
|
+
* follow-up helper calls (`.wait()`, `entity.run()`, ...) reuse the same
|
|
28
|
+
* scope and stay in sync with the call that produced them.
|
|
29
|
+
*/
|
|
30
|
+
export declare function effectiveScope(options: RequestOptions | undefined, fallbackProjectId: string | null | undefined): Scope | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Read the client's default `projectId` without repeating the structural
|
|
33
|
+
* cast at every call site. The base generated `Scenario` type doesn't
|
|
34
|
+
* declare `projectId` — only the enhanced one in `./scenario` does — so
|
|
35
|
+
* `lib/` modules that import `Scenario` from `'../client'` use this helper
|
|
36
|
+
* instead of duplicating the same cast inline.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clientProjectId(client: unknown): string | null | undefined;
|
|
39
|
+
/** Build a `RequestOptions` that adds the scope as a query param, merging into any existing query. */
|
|
40
|
+
export declare function withScope(scope: Scope | undefined, options?: RequestOptions): RequestOptions | undefined;
|
|
41
|
+
//# sourceMappingURL=scope.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.mts","sourceRoot":"","sources":["../src/lib/scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,wCAAoC;AAElE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,KAAK;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,KAAK,GAAG,SAAS,CAMxE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC3C,KAAK,GAAG,SAAS,CAKnB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAE1E;AAED,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,GAAG,SAAS,CAOxG"}
|
package/lib/scope.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RequestOptions } from "../internal/request-options.js";
|
|
2
|
+
/**
|
|
3
|
+
* Per-request project scope.
|
|
4
|
+
*
|
|
5
|
+
* With API-key auth, the server resolves the project from the key. With
|
|
6
|
+
* bearer (JWT) auth a user can belong to multiple projects, so callers must
|
|
7
|
+
* specify which one to act on by passing `projectId` as a query param
|
|
8
|
+
* (the server derives `teamId` from it — no need to send it explicitly).
|
|
9
|
+
*
|
|
10
|
+
* SDK helpers like `Job.wait()` and `Upload.wait()` make follow-up calls
|
|
11
|
+
* internally — they capture the scope effective on the originating call and
|
|
12
|
+
* forward it on each retry, so an action created in project A always polls
|
|
13
|
+
* in project A even if the client default changes between calls.
|
|
14
|
+
*/
|
|
15
|
+
export interface Scope {
|
|
16
|
+
projectId?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Extract `projectId` from a `RequestOptions.query`. Returns `undefined` if absent. */
|
|
19
|
+
export declare function extractScope(options?: RequestOptions): Scope | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the effective scope for an outgoing call:
|
|
22
|
+
* 1. If the per-call options carry a `projectId` query — use that (the explicit override wins).
|
|
23
|
+
* 2. Otherwise, fall back to the client's default `projectId`.
|
|
24
|
+
* 3. If neither is set (e.g. API-key auth with implicit scope), return `undefined`.
|
|
25
|
+
*
|
|
26
|
+
* Returns the snapshot we want to *capture on an enhanced entity* so that
|
|
27
|
+
* follow-up helper calls (`.wait()`, `entity.run()`, ...) reuse the same
|
|
28
|
+
* scope and stay in sync with the call that produced them.
|
|
29
|
+
*/
|
|
30
|
+
export declare function effectiveScope(options: RequestOptions | undefined, fallbackProjectId: string | null | undefined): Scope | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Read the client's default `projectId` without repeating the structural
|
|
33
|
+
* cast at every call site. The base generated `Scenario` type doesn't
|
|
34
|
+
* declare `projectId` — only the enhanced one in `./scenario` does — so
|
|
35
|
+
* `lib/` modules that import `Scenario` from `'../client'` use this helper
|
|
36
|
+
* instead of duplicating the same cast inline.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clientProjectId(client: unknown): string | null | undefined;
|
|
39
|
+
/** Build a `RequestOptions` that adds the scope as a query param, merging into any existing query. */
|
|
40
|
+
export declare function withScope(scope: Scope | undefined, options?: RequestOptions): RequestOptions | undefined;
|
|
41
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/lib/scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,uCAAoC;AAElE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,KAAK;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,KAAK,GAAG,SAAS,CAMxE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC3C,KAAK,GAAG,SAAS,CAKnB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAE1E;AAED,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,GAAG,SAAS,CAOxG"}
|
package/lib/scope.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractScope = extractScope;
|
|
4
|
+
exports.effectiveScope = effectiveScope;
|
|
5
|
+
exports.clientProjectId = clientProjectId;
|
|
6
|
+
exports.withScope = withScope;
|
|
7
|
+
/** Extract `projectId` from a `RequestOptions.query`. Returns `undefined` if absent. */
|
|
8
|
+
function extractScope(options) {
|
|
9
|
+
const query = options?.query;
|
|
10
|
+
if (!query)
|
|
11
|
+
return undefined;
|
|
12
|
+
const projectId = typeof query['projectId'] === 'string' ? query['projectId'] : undefined;
|
|
13
|
+
if (!projectId)
|
|
14
|
+
return undefined;
|
|
15
|
+
return { projectId };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the effective scope for an outgoing call:
|
|
19
|
+
* 1. If the per-call options carry a `projectId` query — use that (the explicit override wins).
|
|
20
|
+
* 2. Otherwise, fall back to the client's default `projectId`.
|
|
21
|
+
* 3. If neither is set (e.g. API-key auth with implicit scope), return `undefined`.
|
|
22
|
+
*
|
|
23
|
+
* Returns the snapshot we want to *capture on an enhanced entity* so that
|
|
24
|
+
* follow-up helper calls (`.wait()`, `entity.run()`, ...) reuse the same
|
|
25
|
+
* scope and stay in sync with the call that produced them.
|
|
26
|
+
*/
|
|
27
|
+
function effectiveScope(options, fallbackProjectId) {
|
|
28
|
+
const override = extractScope(options);
|
|
29
|
+
if (override)
|
|
30
|
+
return override;
|
|
31
|
+
if (fallbackProjectId)
|
|
32
|
+
return { projectId: fallbackProjectId };
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Read the client's default `projectId` without repeating the structural
|
|
37
|
+
* cast at every call site. The base generated `Scenario` type doesn't
|
|
38
|
+
* declare `projectId` — only the enhanced one in `./scenario` does — so
|
|
39
|
+
* `lib/` modules that import `Scenario` from `'../client'` use this helper
|
|
40
|
+
* instead of duplicating the same cast inline.
|
|
41
|
+
*/
|
|
42
|
+
function clientProjectId(client) {
|
|
43
|
+
return client.projectId;
|
|
44
|
+
}
|
|
45
|
+
/** Build a `RequestOptions` that adds the scope as a query param, merging into any existing query. */
|
|
46
|
+
function withScope(scope, options) {
|
|
47
|
+
if (!scope?.projectId)
|
|
48
|
+
return options;
|
|
49
|
+
const existingQuery = options?.query ?? {};
|
|
50
|
+
return {
|
|
51
|
+
...options,
|
|
52
|
+
query: { ...existingQuery, projectId: scope.projectId },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=scope.js.map
|
package/lib/scope.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