@objectstack/client 5.2.0 → 6.1.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/dist/index.d.mts +26 -26
- package/dist/index.d.ts +26 -26
- package/dist/index.js +52 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.mjs
CHANGED
|
@@ -655,12 +655,12 @@ var ObjectStackClient = class {
|
|
|
655
655
|
* through this API.
|
|
656
656
|
*
|
|
657
657
|
* Endpoints:
|
|
658
|
-
* - GET /api/v1/cloud/
|
|
659
|
-
* - GET /api/v1/cloud/
|
|
660
|
-
* - POST /api/v1/cloud/
|
|
661
|
-
* - PATCH /api/v1/cloud/
|
|
662
|
-
* - POST /api/v1/cloud/
|
|
663
|
-
* - POST /api/v1/cloud/
|
|
658
|
+
* - GET /api/v1/cloud/environments → list environments
|
|
659
|
+
* - GET /api/v1/cloud/environments/:id → get one (with database info)
|
|
660
|
+
* - POST /api/v1/cloud/environments → provision a new project
|
|
661
|
+
* - PATCH /api/v1/cloud/environments/:id → update (displayName, plan, status, …)
|
|
662
|
+
* - POST /api/v1/cloud/environments/:id/activate → set as session's active project
|
|
663
|
+
* - POST /api/v1/cloud/environments/:id/credentials/rotate → rotate credential
|
|
664
664
|
*
|
|
665
665
|
* @see docs/adr/0002-project-database-isolation.md
|
|
666
666
|
*/
|
|
@@ -675,7 +675,7 @@ var ObjectStackClient = class {
|
|
|
675
675
|
if (filters?.env_type) params.set("envType", filters.env_type);
|
|
676
676
|
if (filters?.status) params.set("status", filters.status);
|
|
677
677
|
const qs = params.toString();
|
|
678
|
-
const url = `${this.baseUrl}/api/v1/cloud/
|
|
678
|
+
const url = `${this.baseUrl}/api/v1/cloud/environments${qs ? "?" + qs : ""}`;
|
|
679
679
|
const res = await this.fetch(url);
|
|
680
680
|
return this.unwrapResponse(res);
|
|
681
681
|
},
|
|
@@ -683,7 +683,7 @@ var ObjectStackClient = class {
|
|
|
683
683
|
* Get a single project (joined with its database and membership row).
|
|
684
684
|
*/
|
|
685
685
|
get: async (id) => {
|
|
686
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
686
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}`);
|
|
687
687
|
return this.unwrapResponse(res);
|
|
688
688
|
},
|
|
689
689
|
/**
|
|
@@ -691,7 +691,7 @@ var ObjectStackClient = class {
|
|
|
691
691
|
* `ProjectProvisioningService.provisionProject` on the server.
|
|
692
692
|
*/
|
|
693
693
|
create: async (req) => {
|
|
694
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
694
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments`, {
|
|
695
695
|
method: "POST",
|
|
696
696
|
body: JSON.stringify(req)
|
|
697
697
|
});
|
|
@@ -701,7 +701,7 @@ var ObjectStackClient = class {
|
|
|
701
701
|
* Update a project (display_name, plan, status, is_default, metadata).
|
|
702
702
|
*/
|
|
703
703
|
update: async (id, patch) => {
|
|
704
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
704
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}`, {
|
|
705
705
|
method: "PATCH",
|
|
706
706
|
body: JSON.stringify(patch)
|
|
707
707
|
});
|
|
@@ -710,12 +710,12 @@ var ObjectStackClient = class {
|
|
|
710
710
|
/**
|
|
711
711
|
* Cascade-delete a project: cleans up credential/member/package_installation
|
|
712
712
|
* rows, releases the physical database via the provisioning adapter, and
|
|
713
|
-
* removes the `
|
|
713
|
+
* removes the `sys_environment` row. Default projects require `force: true`.
|
|
714
714
|
*/
|
|
715
715
|
delete: async (id, opts) => {
|
|
716
716
|
const qs = opts?.force ? "?force=1" : "";
|
|
717
717
|
const res = await this.fetch(
|
|
718
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
718
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}${qs}`,
|
|
719
719
|
{ method: "DELETE" }
|
|
720
720
|
);
|
|
721
721
|
return this.unwrapResponse(res);
|
|
@@ -726,7 +726,7 @@ var ObjectStackClient = class {
|
|
|
726
726
|
* are routed to this project's database.
|
|
727
727
|
*/
|
|
728
728
|
activate: async (id) => {
|
|
729
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
729
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/activate`, {
|
|
730
730
|
method: "POST"
|
|
731
731
|
});
|
|
732
732
|
return this.unwrapResponse(res);
|
|
@@ -735,7 +735,7 @@ var ObjectStackClient = class {
|
|
|
735
735
|
* Rotate the active database credential for this project.
|
|
736
736
|
*/
|
|
737
737
|
rotateCredential: async (id, plaintext) => {
|
|
738
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
738
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/credentials/rotate`, {
|
|
739
739
|
method: "POST",
|
|
740
740
|
body: JSON.stringify({ plaintext })
|
|
741
741
|
});
|
|
@@ -746,7 +746,7 @@ var ObjectStackClient = class {
|
|
|
746
746
|
* uniqueness server-side; invalidates the dispatcher's routing cache.
|
|
747
747
|
*/
|
|
748
748
|
updateHostname: async (id, hostname) => {
|
|
749
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
749
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/hostname`, {
|
|
750
750
|
method: "POST",
|
|
751
751
|
body: JSON.stringify({ hostname })
|
|
752
752
|
});
|
|
@@ -760,7 +760,7 @@ var ObjectStackClient = class {
|
|
|
760
760
|
* freely exposes all revisions.
|
|
761
761
|
*/
|
|
762
762
|
updateVisibility: async (id, visibility) => {
|
|
763
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
763
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}`, {
|
|
764
764
|
method: "PATCH",
|
|
765
765
|
body: JSON.stringify({ visibility })
|
|
766
766
|
});
|
|
@@ -779,7 +779,7 @@ var ObjectStackClient = class {
|
|
|
779
779
|
if (opts?.branch) params.set("branch", opts.branch);
|
|
780
780
|
const qs = params.toString();
|
|
781
781
|
const res = await this.fetch(
|
|
782
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
782
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/revisions${qs ? `?${qs}` : ""}`
|
|
783
783
|
);
|
|
784
784
|
return this.unwrapResponse(res);
|
|
785
785
|
},
|
|
@@ -790,7 +790,7 @@ var ObjectStackClient = class {
|
|
|
790
790
|
*/
|
|
791
791
|
listBranches: async (id) => {
|
|
792
792
|
const res = await this.fetch(
|
|
793
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
793
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/branches`
|
|
794
794
|
);
|
|
795
795
|
return this.unwrapResponse(res);
|
|
796
796
|
},
|
|
@@ -800,7 +800,7 @@ var ObjectStackClient = class {
|
|
|
800
800
|
*/
|
|
801
801
|
renameBranch: async (id, from, to) => {
|
|
802
802
|
const res = await this.fetch(
|
|
803
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
803
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/branches/${encodeURIComponent(from)}/rename`,
|
|
804
804
|
{
|
|
805
805
|
method: "POST",
|
|
806
806
|
headers: { "content-type": "application/json" },
|
|
@@ -817,7 +817,7 @@ var ObjectStackClient = class {
|
|
|
817
817
|
*/
|
|
818
818
|
deleteBranch: async (id, name) => {
|
|
819
819
|
const res = await this.fetch(
|
|
820
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
820
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/branches/${encodeURIComponent(name)}`,
|
|
821
821
|
{ method: "DELETE" }
|
|
822
822
|
);
|
|
823
823
|
return this.unwrapResponse(res);
|
|
@@ -828,7 +828,7 @@ var ObjectStackClient = class {
|
|
|
828
828
|
*/
|
|
829
829
|
activateRevision: async (id, commitId) => {
|
|
830
830
|
const res = await this.fetch(
|
|
831
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
831
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/revisions/${encodeURIComponent(commitId)}/activate`,
|
|
832
832
|
{ method: "POST" }
|
|
833
833
|
);
|
|
834
834
|
return this.unwrapResponse(res);
|
|
@@ -840,7 +840,7 @@ var ObjectStackClient = class {
|
|
|
840
840
|
* `failed` with `metadata.provisioningError` updated.
|
|
841
841
|
*/
|
|
842
842
|
retryProvisioning: async (id) => {
|
|
843
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
843
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/retry`, {
|
|
844
844
|
method: "POST"
|
|
845
845
|
});
|
|
846
846
|
return this.unwrapResponse(res);
|
|
@@ -849,7 +849,7 @@ var ObjectStackClient = class {
|
|
|
849
849
|
* List members of a project (per-project RBAC).
|
|
850
850
|
*/
|
|
851
851
|
listMembers: async (id) => {
|
|
852
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
852
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/members`);
|
|
853
853
|
return this.unwrapResponse(res);
|
|
854
854
|
},
|
|
855
855
|
/**
|
|
@@ -859,7 +859,7 @@ var ObjectStackClient = class {
|
|
|
859
859
|
* row already existed; the call is idempotent.
|
|
860
860
|
*/
|
|
861
861
|
addMember: async (id, payload) => {
|
|
862
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
862
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/members`, {
|
|
863
863
|
method: "POST",
|
|
864
864
|
headers: { "content-type": "application/json" },
|
|
865
865
|
body: JSON.stringify(payload)
|
|
@@ -872,7 +872,7 @@ var ObjectStackClient = class {
|
|
|
872
872
|
*/
|
|
873
873
|
updateMemberRole: async (id, memberId, role) => {
|
|
874
874
|
const res = await this.fetch(
|
|
875
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
875
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/members/${encodeURIComponent(memberId)}`,
|
|
876
876
|
{
|
|
877
877
|
method: "PATCH",
|
|
878
878
|
headers: { "content-type": "application/json" },
|
|
@@ -887,7 +887,7 @@ var ObjectStackClient = class {
|
|
|
887
887
|
*/
|
|
888
888
|
removeMember: async (id, memberId) => {
|
|
889
889
|
const res = await this.fetch(
|
|
890
|
-
`${this.baseUrl}/api/v1/cloud/
|
|
890
|
+
`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/members/${encodeURIComponent(memberId)}`,
|
|
891
891
|
{ method: "DELETE" }
|
|
892
892
|
);
|
|
893
893
|
return this.unwrapResponse(res);
|
|
@@ -917,12 +917,12 @@ var ObjectStackClient = class {
|
|
|
917
917
|
packages: {
|
|
918
918
|
/** List all packages installed in a specific project. */
|
|
919
919
|
list: async (envId) => {
|
|
920
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
920
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(envId)}/packages`);
|
|
921
921
|
return this.unwrapResponse(res);
|
|
922
922
|
},
|
|
923
923
|
/** Install a package into the project. */
|
|
924
924
|
install: async (envId, body) => {
|
|
925
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
925
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(envId)}/packages`, {
|
|
926
926
|
method: "POST",
|
|
927
927
|
body: JSON.stringify(body)
|
|
928
928
|
});
|
|
@@ -930,33 +930,33 @@ var ObjectStackClient = class {
|
|
|
930
930
|
},
|
|
931
931
|
/** Get a single installation record. */
|
|
932
932
|
get: async (envId, pkgId) => {
|
|
933
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
933
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(envId)}/packages/${encodeURIComponent(pkgId)}`);
|
|
934
934
|
return this.unwrapResponse(res);
|
|
935
935
|
},
|
|
936
936
|
/** Enable a previously disabled package. */
|
|
937
937
|
enable: async (envId, pkgId) => {
|
|
938
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
938
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(envId)}/packages/${encodeURIComponent(pkgId)}/enable`, {
|
|
939
939
|
method: "PATCH"
|
|
940
940
|
});
|
|
941
941
|
return this.unwrapResponse(res);
|
|
942
942
|
},
|
|
943
943
|
/** Disable an installed package (metadata will not be loaded). */
|
|
944
944
|
disable: async (envId, pkgId) => {
|
|
945
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
945
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(envId)}/packages/${encodeURIComponent(pkgId)}/disable`, {
|
|
946
946
|
method: "PATCH"
|
|
947
947
|
});
|
|
948
948
|
return this.unwrapResponse(res);
|
|
949
949
|
},
|
|
950
950
|
/** Uninstall a package from the project. Forbidden for scope=platform packages. */
|
|
951
951
|
uninstall: async (envId, pkgId) => {
|
|
952
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
952
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(envId)}/packages/${encodeURIComponent(pkgId)}`, {
|
|
953
953
|
method: "DELETE"
|
|
954
954
|
});
|
|
955
955
|
return this.unwrapResponse(res);
|
|
956
956
|
},
|
|
957
957
|
/** Upgrade an installed package to a newer version. */
|
|
958
958
|
upgrade: async (envId, pkgId, targetVersion) => {
|
|
959
|
-
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/
|
|
959
|
+
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(envId)}/packages/${encodeURIComponent(pkgId)}/upgrade`, {
|
|
960
960
|
method: "POST",
|
|
961
961
|
body: JSON.stringify({ targetVersion })
|
|
962
962
|
});
|
|
@@ -2706,7 +2706,7 @@ var ObjectStackClient = class {
|
|
|
2706
2706
|
};
|
|
2707
2707
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
2708
2708
|
this.token = config.token;
|
|
2709
|
-
this.
|
|
2709
|
+
this.environmentId = config.environmentId;
|
|
2710
2710
|
this.fetchImpl = config.fetch || globalThis.fetch.bind(globalThis);
|
|
2711
2711
|
this.logger = config.logger || createLogger({
|
|
2712
2712
|
level: config.debug ? "debug" : "info",
|
|
@@ -2787,12 +2787,12 @@ var ObjectStackClient = class {
|
|
|
2787
2787
|
* Project-scoped client factory.
|
|
2788
2788
|
*
|
|
2789
2789
|
* Returns a thin wrapper around the data / meta / packages namespaces that
|
|
2790
|
-
* prefixes every request with `/api/v1/
|
|
2790
|
+
* prefixes every request with `/api/v1/environments/:environmentId/...`. Use this
|
|
2791
2791
|
* when the server has `enableProjectScoping: true` in its REST API config.
|
|
2792
2792
|
*
|
|
2793
2793
|
* Backward compatibility: `client.data.*`, `client.meta.*`, and
|
|
2794
2794
|
* `client.packages.*` continue to work unchanged; they hit unscoped routes
|
|
2795
|
-
* and rely on hostname / `X-
|
|
2795
|
+
* and rely on hostname / `X-Environment-Id` header / session resolution.
|
|
2796
2796
|
*
|
|
2797
2797
|
* @example
|
|
2798
2798
|
* ```ts
|
|
@@ -2801,11 +2801,11 @@ var ObjectStackClient = class {
|
|
|
2801
2801
|
* const objects = await scoped.meta.getItems('object');
|
|
2802
2802
|
* ```
|
|
2803
2803
|
*/
|
|
2804
|
-
project(
|
|
2805
|
-
if (!
|
|
2806
|
-
throw new Error("[ObjectStack] project(id):
|
|
2804
|
+
project(environmentId) {
|
|
2805
|
+
if (!environmentId) {
|
|
2806
|
+
throw new Error("[ObjectStack] project(id): environmentId is required");
|
|
2807
2807
|
}
|
|
2808
|
-
return new ScopedProjectClient(this,
|
|
2808
|
+
return new ScopedProjectClient(this, environmentId);
|
|
2809
2809
|
}
|
|
2810
2810
|
// ── Internal accessors exposed to ScopedProjectClient ────────────────
|
|
2811
2811
|
// The scoped client lives in the same module so using module-level access
|
|
@@ -2831,15 +2831,15 @@ var ObjectStackClient = class {
|
|
|
2831
2831
|
* Update the active project id used for subsequent requests.
|
|
2832
2832
|
* Pass `undefined` to clear (falls back to the session default).
|
|
2833
2833
|
*/
|
|
2834
|
-
setProjectId(
|
|
2835
|
-
this.
|
|
2836
|
-
this.logger.debug("Active project changed", {
|
|
2834
|
+
setProjectId(environmentId) {
|
|
2835
|
+
this.environmentId = environmentId;
|
|
2836
|
+
this.logger.debug("Active project changed", { environmentId });
|
|
2837
2837
|
}
|
|
2838
2838
|
/**
|
|
2839
2839
|
* Current active project id (if set).
|
|
2840
2840
|
*/
|
|
2841
2841
|
getProjectId() {
|
|
2842
|
-
return this.
|
|
2842
|
+
return this.environmentId;
|
|
2843
2843
|
}
|
|
2844
2844
|
/**
|
|
2845
2845
|
* Event Subscription API
|
|
@@ -2881,8 +2881,8 @@ var ObjectStackClient = class {
|
|
|
2881
2881
|
if (this.token) {
|
|
2882
2882
|
headers["Authorization"] = `Bearer ${this.token}`;
|
|
2883
2883
|
}
|
|
2884
|
-
if (this.
|
|
2885
|
-
headers["X-
|
|
2884
|
+
if (this.environmentId) {
|
|
2885
|
+
headers["X-Environment-Id"] = this.environmentId;
|
|
2886
2886
|
}
|
|
2887
2887
|
const res = await this.fetchImpl(url, { ...options, headers });
|
|
2888
2888
|
this.logger.debug("HTTP response", {
|
|
@@ -2951,7 +2951,7 @@ var ObjectStackClient = class {
|
|
|
2951
2951
|
}
|
|
2952
2952
|
};
|
|
2953
2953
|
var ScopedProjectClient = class {
|
|
2954
|
-
constructor(parent,
|
|
2954
|
+
constructor(parent, environmentId) {
|
|
2955
2955
|
/**
|
|
2956
2956
|
* Metadata operations scoped to this project.
|
|
2957
2957
|
*/
|
|
@@ -3139,7 +3139,7 @@ var ScopedProjectClient = class {
|
|
|
3139
3139
|
* Automation (Flow) operations scoped to this project.
|
|
3140
3140
|
*
|
|
3141
3141
|
* Thin wrapper around the dispatcher's automation routes, mounted under
|
|
3142
|
-
* `/api/v1/
|
|
3142
|
+
* `/api/v1/environments/:environmentId/automation/...`. Surface mirrors the methods
|
|
3143
3143
|
* needed by Studio's Flow viewer: read flow definition, execute (trigger),
|
|
3144
3144
|
* list runs, fetch a single run.
|
|
3145
3145
|
*/
|
|
@@ -3180,15 +3180,15 @@ var ScopedProjectClient = class {
|
|
|
3180
3180
|
}
|
|
3181
3181
|
};
|
|
3182
3182
|
this.parent = parent;
|
|
3183
|
-
this.
|
|
3183
|
+
this.environmentId = environmentId;
|
|
3184
3184
|
}
|
|
3185
|
-
/** The
|
|
3185
|
+
/** The environmentId this client is scoped to. */
|
|
3186
3186
|
getProjectId() {
|
|
3187
|
-
return this.
|
|
3187
|
+
return this.environmentId;
|
|
3188
3188
|
}
|
|
3189
3189
|
/** Prefix segment inserted between the baseUrl and the resource path. */
|
|
3190
3190
|
scope() {
|
|
3191
|
-
return `/api/v1/
|
|
3191
|
+
return `/api/v1/environments/${encodeURIComponent(this.environmentId)}`;
|
|
3192
3192
|
}
|
|
3193
3193
|
url(suffix) {
|
|
3194
3194
|
return `${this.parent._baseUrl()}${this.scope()}${suffix}`;
|