codemie-sdk-python 0.1.715__py3-none-any.whl → 0.1.716__py3-none-any.whl

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.
codemie_sdk/__init__.py CHANGED
@@ -213,6 +213,28 @@ from .models.provisioning import (
213
213
  ProvisioningBudgetResult,
214
214
  )
215
215
  from .services.provisioning import ProvisioningService
216
+ from .models.hosted_application import (
217
+ HostedApplication,
218
+ HostedApplicationCapabilities,
219
+ HostedApplicationCreator,
220
+ HostedApplicationDeletion,
221
+ HostedApplicationDeletionStatus,
222
+ HostedApplicationLaunch,
223
+ HostedApplicationList,
224
+ HostedApplicationSharableUsers,
225
+ HostedApplicationSharedWith,
226
+ HostedApplicationShareLink,
227
+ HostedApplicationShareLinkInfo,
228
+ HostedApplicationShareLinkTarget,
229
+ HostedApplicationUploadReceipt,
230
+ HostedApplicationUsage,
231
+ HostedApplicationValidationReport,
232
+ HostedApplicationVersion,
233
+ HostedApplicationVersionList,
234
+ HostedApplicationVersionQueued,
235
+ HostedApplicationVersionStart,
236
+ )
237
+ from .services.hosted_application import HostedApplicationService
216
238
 
217
239
  try:
218
240
  __version__ = _pkg_version("codemie-sdk-python")
@@ -381,4 +403,24 @@ __all__ = [
381
403
  "MarketplaceForcePublishResponse",
382
404
  "MarketplaceDecisionRequest",
383
405
  "MarketplaceManagementService",
406
+ "HostedApplication",
407
+ "HostedApplicationCapabilities",
408
+ "HostedApplicationCreator",
409
+ "HostedApplicationDeletion",
410
+ "HostedApplicationDeletionStatus",
411
+ "HostedApplicationLaunch",
412
+ "HostedApplicationList",
413
+ "HostedApplicationSharableUsers",
414
+ "HostedApplicationSharedWith",
415
+ "HostedApplicationShareLink",
416
+ "HostedApplicationShareLinkInfo",
417
+ "HostedApplicationShareLinkTarget",
418
+ "HostedApplicationUploadReceipt",
419
+ "HostedApplicationUsage",
420
+ "HostedApplicationValidationReport",
421
+ "HostedApplicationVersion",
422
+ "HostedApplicationVersionList",
423
+ "HostedApplicationVersionQueued",
424
+ "HostedApplicationVersionStart",
425
+ "HostedApplicationService",
384
426
  ]
@@ -37,6 +37,7 @@ from ..services.provisioning import ProvisioningService
37
37
  from ..services.usage_attribution import UsageAttributionService
38
38
  from ..services.marketplace_management import MarketplaceManagementService
39
39
  from ..services.export import ExportService
40
+ from ..services.hosted_application import HostedApplicationService
40
41
 
41
42
 
42
43
  class CodeMieClient:
@@ -205,6 +206,9 @@ class CodeMieClient:
205
206
  self.provisioning = ProvisioningService(
206
207
  self._api_domain, _token_source, verify_ssl=self._verify_ssl
207
208
  )
209
+ self.hosted_applications = HostedApplicationService(
210
+ self._api_domain, _token_source, verify_ssl=self._verify_ssl
211
+ )
208
212
 
209
213
  @property
210
214
  def token(self) -> str:
@@ -0,0 +1,285 @@
1
+ # Copyright 2026 EPAM Systems, Inc. ("EPAM")
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Hosted application models for the CodeMie SDK.
16
+
17
+ Shapes of the management API under ``/v1/hosted-applications``: applications, their
18
+ versions and uploads, sharing and the launch ticket of a viewing session.
19
+ """
20
+
21
+ from typing import Any
22
+
23
+ from pydantic import BaseModel, ConfigDict, Field
24
+
25
+
26
+ class HostedApplicationCapabilities(BaseModel):
27
+ """What the caller may do with hosted applications on this stand."""
28
+
29
+ model_config = ConfigDict(extra="ignore")
30
+
31
+ create: bool = Field(description="The caller may create applications")
32
+ view: bool = Field(description="The caller may open applications")
33
+ disabled_reason: str | None = Field(
34
+ default=None, description="Why the feature is unavailable, when it is"
35
+ )
36
+ launch_policy: dict[str, Any] | None = None
37
+ limits: dict[str, Any] = Field(default_factory=dict)
38
+
39
+
40
+ class HostedApplicationUsage(BaseModel):
41
+ """Storage quota of the caller, in bytes."""
42
+
43
+ model_config = ConfigDict(extra="ignore")
44
+
45
+ byte_limit: int
46
+ available_bytes: int
47
+ stored_bytes: int
48
+ reserved_bytes: int
49
+
50
+
51
+ class HostedApplicationCreator(BaseModel):
52
+ """The user who created an application."""
53
+
54
+ model_config = ConfigDict(extra="ignore")
55
+
56
+ id: str | None = None
57
+ username: str | None = None
58
+ name: str | None = None
59
+
60
+
61
+ class HostedApplication(BaseModel):
62
+ """An application as the caller sees it.
63
+
64
+ The fields after ``has_cover`` are present for managers only.
65
+ """
66
+
67
+ model_config = ConfigDict(extra="ignore")
68
+
69
+ id: str
70
+ name: str
71
+ description: str | None = None
72
+ artifact_kind: str | None = None
73
+ updated_at: str | None = None
74
+ publisher: dict[str, Any] | None = None
75
+ project: str | None = None
76
+ shared: bool = False
77
+ is_global: bool = False
78
+ created_by: HostedApplicationCreator | None = None
79
+ user_abilities: list[str] = Field(default_factory=list)
80
+ can_share: bool = False
81
+ can_moderate: bool = False
82
+ suspended: bool = False
83
+ suspension_refuses: Any = None
84
+ has_active_version: bool = False
85
+ has_cover: bool = False
86
+ selected_version_id: str | None = None
87
+ active_version_id: str | None = None
88
+ lifecycle_state: str | None = None
89
+ revision: int | None = None
90
+ etag: str | None = Field(
91
+ default=None, description="Value to send as If-Match on the next change"
92
+ )
93
+ created_at: str | None = None
94
+
95
+
96
+ class HostedApplicationList(BaseModel):
97
+ """One page of applications."""
98
+
99
+ model_config = ConfigDict(extra="ignore")
100
+
101
+ items: list[HostedApplication] = Field(default_factory=list)
102
+ next_cursor: str | None = None
103
+
104
+
105
+ class HostedApplicationVersionStart(BaseModel):
106
+ """A new version whose artifact is yet to be uploaded."""
107
+
108
+ model_config = ConfigDict(extra="ignore")
109
+
110
+ version_id: str
111
+ sequence: int
112
+ upload_id: str
113
+ generation: int
114
+ expires_at: str | None = None
115
+ upload_path: str | None = None
116
+ upload_etag: str
117
+ version_etag: str
118
+ app_etag: str
119
+ limits: dict[str, Any] = Field(default_factory=dict)
120
+
121
+
122
+ class HostedApplicationUploadReceipt(BaseModel):
123
+ """Receipt of a stored artifact."""
124
+
125
+ model_config = ConfigDict(extra="ignore")
126
+
127
+ upload_id: str
128
+ generation: int
129
+ state: str
130
+ received_bytes: int
131
+ sha256: str
132
+ upload_etag: str
133
+ version_etag: str
134
+
135
+
136
+ class HostedApplicationVersionQueued(BaseModel):
137
+ """Answer to completing an upload, configuring or retrying a version: validation is queued."""
138
+
139
+ model_config = ConfigDict(extra="ignore")
140
+
141
+ job_id: str | None = None
142
+ state: str
143
+ version_etag: str | None = None
144
+ upload_etag: str | None = None
145
+
146
+
147
+ class HostedApplicationVersion(BaseModel):
148
+ """A version of an application with its validation state."""
149
+
150
+ model_config = ConfigDict(extra="ignore")
151
+
152
+ id: str
153
+ sequence: int
154
+ filename: str | None = None
155
+ artifact_kind: str | None = None
156
+ expected_bytes: int | None = None
157
+ validation_state: str = Field(
158
+ description=(
159
+ "uploading, queued, validating, awaiting_configuration, accepted, "
160
+ "failed, rejected or canceled"
161
+ )
162
+ )
163
+ security_state: str | None = None
164
+ can_preview: bool = False
165
+ can_activate: bool = False
166
+ revision: int | None = None
167
+ etag: str | None = None
168
+ configuration_revision: int | None = None
169
+ requested_configuration: dict[str, Any] = Field(default_factory=dict)
170
+ candidate_manifest_digest: str | None = None
171
+ upload: dict[str, Any] | None = None
172
+ created_at: str | None = None
173
+ job: dict[str, Any] | None = None
174
+ accepted: dict[str, Any] | None = None
175
+
176
+
177
+ class HostedApplicationVersionList(BaseModel):
178
+ """One page of versions, newest first."""
179
+
180
+ model_config = ConfigDict(extra="ignore")
181
+
182
+ items: list[HostedApplicationVersion] = Field(default_factory=list)
183
+ next_cursor: str | None = None
184
+
185
+
186
+ class HostedApplicationValidationReport(BaseModel):
187
+ """Validation report of a version: detected options, findings and the rejection code."""
188
+
189
+ model_config = ConfigDict(extra="ignore")
190
+
191
+ state: str
192
+ job_id: str | None = None
193
+ phase: str | None = None
194
+ candidate_manifest_digest: str | None = None
195
+ roots: list[str] = Field(default_factory=list)
196
+ entries: list[str] = Field(default_factory=list)
197
+ warnings: list[Any] = Field(default_factory=list)
198
+ errors: list[dict[str, Any]] = Field(default_factory=list)
199
+ configuration_revision: int | None = None
200
+ file_count: int = 0
201
+ expanded_bytes: int = 0
202
+ next_offset: int | None = None
203
+ error_code: str | None = None
204
+ scanner: Any = None
205
+ policy_version: str | None = None
206
+ etag: str | None = None
207
+
208
+
209
+ class HostedApplicationLaunch(BaseModel):
210
+ """Launch ticket: the form a browser posts to the content origin to open a version."""
211
+
212
+ model_config = ConfigDict(extra="ignore")
213
+
214
+ method: str
215
+ version_id: str
216
+ policy_version: str | None = None
217
+ content_origin: str
218
+ action: str
219
+ ticket: str = Field(repr=False)
220
+ issued_at: str | None = None
221
+ expires_at: str | None = None
222
+
223
+
224
+ class HostedApplicationSharedWith(BaseModel):
225
+ """People an application is shared with by name."""
226
+
227
+ model_config = ConfigDict(extra="ignore")
228
+
229
+ shared_with: list[dict[str, Any]] = Field(default_factory=list)
230
+
231
+
232
+ class HostedApplicationSharableUsers(BaseModel):
233
+ """Directory users that can be granted access."""
234
+
235
+ model_config = ConfigDict(extra="ignore")
236
+
237
+ users: list[dict[str, Any]] = Field(default_factory=list)
238
+
239
+
240
+ class HostedApplicationShareLinkInfo(BaseModel):
241
+ """A share link of an application."""
242
+
243
+ model_config = ConfigDict(extra="ignore")
244
+
245
+ id: str
246
+ token: str = Field(repr=False)
247
+ created_at: str | None = None
248
+
249
+
250
+ class HostedApplicationShareLink(BaseModel):
251
+ """The live share link of an application, or none."""
252
+
253
+ model_config = ConfigDict(extra="ignore")
254
+
255
+ link: HostedApplicationShareLinkInfo | None = None
256
+
257
+
258
+ class HostedApplicationShareLinkTarget(BaseModel):
259
+ """Answer to opening a share link: the application it leads to."""
260
+
261
+ model_config = ConfigDict(extra="ignore")
262
+
263
+ app_id: str
264
+
265
+
266
+ class HostedApplicationDeletion(BaseModel):
267
+ """Answer to deleting an application: the purge is queued."""
268
+
269
+ model_config = ConfigDict(extra="ignore")
270
+
271
+ state: str
272
+ job_id: str | None = None
273
+ application: dict[str, Any] | None = None
274
+
275
+
276
+ class HostedApplicationDeletionStatus(BaseModel):
277
+ """Progress of the purge of a deleted application."""
278
+
279
+ model_config = ConfigDict(extra="ignore")
280
+
281
+ state: str = Field(description="purging or purged")
282
+ app_id: str
283
+ remaining_prefixes: int = 0
284
+ charged_bytes: int = 0
285
+ etag: str | None = None
@@ -0,0 +1,581 @@
1
+ # Copyright 2026 EPAM Systems, Inc. ("EPAM")
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Hosted application service for the CodeMie SDK.
16
+
17
+ Wraps the management API under ``/v1/hosted-applications``. Changes to an existing
18
+ application or version carry the ``etag`` of the item as ``If-Match``; read it from the
19
+ latest answer. Every change also carries an ``Idempotency-Key``: pass one to repeat a
20
+ request safely, or leave it out to get a fresh key per call.
21
+ """
22
+
23
+ from typing import Any
24
+ from urllib.parse import quote
25
+ from uuid import uuid4
26
+
27
+ import requests
28
+
29
+ from ..models.hosted_application import (
30
+ HostedApplication,
31
+ HostedApplicationCapabilities,
32
+ HostedApplicationDeletion,
33
+ HostedApplicationDeletionStatus,
34
+ HostedApplicationLaunch,
35
+ HostedApplicationList,
36
+ HostedApplicationSharableUsers,
37
+ HostedApplicationSharedWith,
38
+ HostedApplicationShareLink,
39
+ HostedApplicationShareLinkTarget,
40
+ HostedApplicationUploadReceipt,
41
+ HostedApplicationUsage,
42
+ HostedApplicationValidationReport,
43
+ HostedApplicationVersion,
44
+ HostedApplicationVersionList,
45
+ HostedApplicationVersionQueued,
46
+ HostedApplicationVersionStart,
47
+ )
48
+ from ..utils import ApiRequestHandler, TokenSource
49
+
50
+ _BASE = "/v1/hosted-applications"
51
+ _ADMIN_BASE = "/v1/admin/hosted-applications"
52
+ _IF_MATCH = "If-Match"
53
+ _IDEMPOTENCY_KEY = "Idempotency-Key"
54
+ _UPLOAD_GENERATION = "X-Upload-Generation"
55
+
56
+
57
+ class HostedApplicationService:
58
+ """Service for hosted static applications: upload, share and open.
59
+
60
+ Every change sends an idempotency key. Without an ``idempotency_key`` argument the service
61
+ generates a fresh one per call, so a retry after a timeout is not protected from running twice
62
+ (for example, a second application is created). A caller that retries must generate one key
63
+ and pass the same value on every attempt.
64
+ """
65
+
66
+ def __init__(self, api_domain: str, token: TokenSource, verify_ssl: bool = True):
67
+ """Initialize the hosted application service.
68
+
69
+ Args:
70
+ api_domain: Base URL for the CodeMie API
71
+ token: Authentication token
72
+ verify_ssl: Whether to verify SSL certificates
73
+ """
74
+ self._api_domain = api_domain.rstrip("/")
75
+ self._verify_ssl = verify_ssl
76
+ self._api = ApiRequestHandler(self._api_domain, token, verify_ssl)
77
+
78
+ def with_token(self, token: TokenSource) -> "HostedApplicationService":
79
+ """Return a service for the same API that authenticates with another token.
80
+
81
+ Args:
82
+ token: Authentication token, for example the token of a service account
83
+
84
+ Returns:
85
+ A new HostedApplicationService; this one is left unchanged
86
+ """
87
+ return HostedApplicationService(self._api_domain, token, self._verify_ssl)
88
+
89
+ @staticmethod
90
+ def _path(*parts: str) -> str:
91
+ return "/".join([_BASE, *(quote(str(part), safe="") for part in parts)])
92
+
93
+ @staticmethod
94
+ def _headers(
95
+ if_match: str | None = None, idempotency_key: str | None = None
96
+ ) -> dict[str, str]:
97
+ headers = {_IDEMPOTENCY_KEY: idempotency_key or str(uuid4())}
98
+ if if_match is not None:
99
+ headers[_IF_MATCH] = if_match
100
+ return headers
101
+
102
+ def capabilities(self) -> HostedApplicationCapabilities:
103
+ """What the caller may do. Accounts that cannot use the feature get ``view=False``."""
104
+ return self._api.get(
105
+ f"{_BASE}/capabilities", HostedApplicationCapabilities, wrap_response=False
106
+ )
107
+
108
+ def usage(self) -> HostedApplicationUsage:
109
+ """Storage quota of the caller."""
110
+ return self._api.get(
111
+ f"{_BASE}/usage", HostedApplicationUsage, wrap_response=False
112
+ )
113
+
114
+ def list_applications(
115
+ self,
116
+ scope: str = "mine",
117
+ q: str = "",
118
+ limit: int = 24,
119
+ cursor: str | None = None,
120
+ sort: str = "updated_desc",
121
+ **filters: Any,
122
+ ) -> HostedApplicationList:
123
+ """List the applications the caller may open in one scope.
124
+
125
+ Args:
126
+ scope: mine, project, marketplace or shared
127
+ q: Search text over name and description
128
+ limit: Page size, 1 to 100
129
+ cursor: ``next_cursor`` of the previous page
130
+ sort: updated_desc, created_desc or name_asc
131
+ **filters: Further server filters such as ``artifact_kind``, ``project``,
132
+ ``created_by``, ``shared`` or ``status``; unset values are not sent
133
+ """
134
+ params: dict[str, Any] = {
135
+ "scope": scope,
136
+ "q": q,
137
+ "limit": limit,
138
+ "sort": sort,
139
+ **{key: value for key, value in filters.items() if value is not None},
140
+ }
141
+ if cursor:
142
+ params["cursor"] = cursor
143
+ return self._api.get(
144
+ _BASE, HostedApplicationList, params=params, wrap_response=False
145
+ )
146
+
147
+ def get_application(self, app_id: str) -> HostedApplication:
148
+ """Get one application."""
149
+ return self._api.get(self._path(app_id), HostedApplication, wrap_response=False)
150
+
151
+ def get_thumbnail(self, app_id: str) -> requests.Response:
152
+ """Get the cover image of an application.
153
+
154
+ Returns the raw response: the image bytes, or an empty 204 answer when the
155
+ application has no cover.
156
+ """
157
+ return self._api.get(self._path(app_id, "thumbnail"), requests.Response)
158
+
159
+ def create_application(
160
+ self,
161
+ name: str,
162
+ description: str,
163
+ project: str,
164
+ shared: bool = False,
165
+ idempotency_key: str | None = None,
166
+ ) -> HostedApplication:
167
+ """Create a private application, or one shared with every member of ``project``."""
168
+ return self._api.request(
169
+ "POST",
170
+ _BASE,
171
+ HostedApplication,
172
+ json_data={
173
+ "name": name,
174
+ "description": description,
175
+ "project": project,
176
+ "shared": shared,
177
+ },
178
+ extra_headers=self._headers(idempotency_key=idempotency_key),
179
+ wrap_response=False,
180
+ )
181
+
182
+ def delete_application(
183
+ self, app_id: str, if_match: str, idempotency_key: str | None = None
184
+ ) -> HostedApplicationDeletion:
185
+ """Delete an application. Its files are purged afterwards; see ``deletion_status``."""
186
+ return self._api.request(
187
+ "DELETE",
188
+ self._path(app_id),
189
+ HostedApplicationDeletion,
190
+ extra_headers=self._headers(if_match, idempotency_key),
191
+ wrap_response=False,
192
+ )
193
+
194
+ def deletion_status(self, app_id: str) -> HostedApplicationDeletionStatus:
195
+ """Progress of the purge of a deleted application."""
196
+ return self._api.get(
197
+ self._path(app_id, "deletion-status"),
198
+ HostedApplicationDeletionStatus,
199
+ wrap_response=False,
200
+ )
201
+
202
+ def start_version(
203
+ self,
204
+ app_id: str,
205
+ filename: str,
206
+ artifact_kind: str,
207
+ byte_size: int,
208
+ if_match: str,
209
+ sha256: str | None = None,
210
+ routing_mode: str = "static",
211
+ site_root_hint: str | None = None,
212
+ entrypoint_hint: str | None = None,
213
+ idempotency_key: str | None = None,
214
+ ) -> HostedApplicationVersionStart:
215
+ """Start a new version; upload its artifact next.
216
+
217
+ Args:
218
+ app_id: Application id
219
+ filename: Name of the artifact, ``.html`` or ``.zip``
220
+ artifact_kind: html or zip
221
+ byte_size: Size of the artifact in bytes
222
+ if_match: ``etag`` of the application
223
+ sha256: Hex digest the stored bytes must match, when known
224
+ routing_mode: static or spa_history
225
+ site_root_hint: Folder of the site inside a ZIP
226
+ entrypoint_hint: Entry page inside a ZIP
227
+ idempotency_key: Key to repeat the request safely
228
+ """
229
+ body: dict[str, Any] = {
230
+ "filename": filename,
231
+ "artifact_kind": artifact_kind,
232
+ "byte_size": byte_size,
233
+ "routing_mode": routing_mode,
234
+ }
235
+ for key, value in (
236
+ ("sha256", sha256),
237
+ ("site_root_hint", site_root_hint),
238
+ ("entrypoint_hint", entrypoint_hint),
239
+ ):
240
+ if value is not None:
241
+ body[key] = value
242
+ return self._api.request(
243
+ "POST",
244
+ self._path(app_id, "versions"),
245
+ HostedApplicationVersionStart,
246
+ json_data=body,
247
+ extra_headers=self._headers(if_match, idempotency_key),
248
+ wrap_response=False,
249
+ )
250
+
251
+ def upload_artifact(
252
+ self,
253
+ app_id: str,
254
+ version_id: str,
255
+ content: bytes,
256
+ upload_etag: str,
257
+ generation: int,
258
+ ) -> HostedApplicationUploadReceipt:
259
+ """Send the bytes of the artifact of a started version.
260
+
261
+ Args:
262
+ app_id: Application id
263
+ version_id: Version id from ``start_version``
264
+ content: The artifact bytes
265
+ upload_etag: ``upload_etag`` of ``start_version``
266
+ generation: ``generation`` of ``start_version``
267
+ """
268
+ return self._api.request(
269
+ "PUT",
270
+ self._path(app_id, "versions", version_id, "artifact"),
271
+ HostedApplicationUploadReceipt,
272
+ data=content,
273
+ extra_headers={
274
+ "Content-Type": "application/octet-stream",
275
+ _IF_MATCH: upload_etag,
276
+ _UPLOAD_GENERATION: str(generation),
277
+ },
278
+ wrap_response=False,
279
+ )
280
+
281
+ def complete_version(
282
+ self,
283
+ app_id: str,
284
+ version_id: str,
285
+ upload_id: str,
286
+ sha256: str,
287
+ generation: int,
288
+ if_match: str,
289
+ idempotency_key: str | None = None,
290
+ ) -> HostedApplicationVersionQueued:
291
+ """Finish an upload and queue the version for validation.
292
+
293
+ Args:
294
+ app_id: Application id
295
+ version_id: Version id
296
+ upload_id: ``upload_id`` of ``start_version``
297
+ sha256: Digest from the upload receipt
298
+ generation: Generation of the upload
299
+ if_match: ``version_etag`` of the upload receipt
300
+ idempotency_key: Key to repeat the request safely
301
+ """
302
+ return self._api.request(
303
+ "POST",
304
+ self._path(app_id, "versions", version_id, "complete"),
305
+ HostedApplicationVersionQueued,
306
+ json_data={
307
+ "generation": generation,
308
+ "upload_id": upload_id,
309
+ "sha256": sha256,
310
+ },
311
+ extra_headers=self._headers(if_match, idempotency_key),
312
+ wrap_response=False,
313
+ )
314
+
315
+ def get_version(self, app_id: str, version_id: str) -> HostedApplicationVersion:
316
+ """Get one version with its validation state."""
317
+ return self._api.get(
318
+ self._path(app_id, "versions", version_id),
319
+ HostedApplicationVersion,
320
+ wrap_response=False,
321
+ )
322
+
323
+ def list_versions(
324
+ self, app_id: str, limit: int = 20, cursor: str | None = None
325
+ ) -> HostedApplicationVersionList:
326
+ """List the versions of an application, newest first."""
327
+ params: dict[str, Any] = {"limit": limit}
328
+ if cursor:
329
+ params["cursor"] = cursor
330
+ return self._api.get(
331
+ self._path(app_id, "versions"),
332
+ HostedApplicationVersionList,
333
+ params=params,
334
+ wrap_response=False,
335
+ )
336
+
337
+ def get_version_validation(
338
+ self, app_id: str, version_id: str, offset: int = 0, limit: int = 100
339
+ ) -> HostedApplicationValidationReport:
340
+ """Get the validation report of a version."""
341
+ return self._api.get(
342
+ self._path(app_id, "versions", version_id, "validation"),
343
+ HostedApplicationValidationReport,
344
+ params={"offset": offset, "limit": limit},
345
+ wrap_response=False,
346
+ )
347
+
348
+ def configure_version(
349
+ self,
350
+ app_id: str,
351
+ version_id: str,
352
+ site_root: str,
353
+ entrypoint_path: str,
354
+ routing_mode: str,
355
+ candidate_manifest_digest: str,
356
+ configuration_revision: int,
357
+ if_match: str,
358
+ idempotency_key: str | None = None,
359
+ ) -> HostedApplicationVersionQueued:
360
+ """Choose the site root and entry page of a version that awaits configuration.
361
+
362
+ Take ``site_root`` and ``entrypoint_path`` from the ``roots`` and ``entries`` of
363
+ the validation report, and the digest and revision from the same report.
364
+ """
365
+ return self._api.request(
366
+ "PUT",
367
+ self._path(app_id, "versions", version_id, "configuration"),
368
+ HostedApplicationVersionQueued,
369
+ json_data={
370
+ "site_root": site_root,
371
+ "entrypoint_path": entrypoint_path,
372
+ "routing_mode": routing_mode,
373
+ "candidate_manifest_digest": candidate_manifest_digest,
374
+ "configuration_revision": configuration_revision,
375
+ },
376
+ extra_headers=self._headers(if_match, idempotency_key),
377
+ wrap_response=False,
378
+ )
379
+
380
+ def select_version(
381
+ self,
382
+ app_id: str,
383
+ version_id: str,
384
+ if_match: str,
385
+ idempotency_key: str | None = None,
386
+ ) -> HostedApplication:
387
+ """Make an accepted version the working version; the live version is untouched."""
388
+ return self._api.request(
389
+ "POST",
390
+ self._path(app_id, "select-version"),
391
+ HostedApplication,
392
+ json_data={"version_id": version_id},
393
+ extra_headers=self._headers(if_match, idempotency_key),
394
+ wrap_response=False,
395
+ )
396
+
397
+ def activate(
398
+ self,
399
+ app_id: str,
400
+ version_id: str,
401
+ if_match: str,
402
+ idempotency_key: str | None = None,
403
+ ) -> HostedApplication:
404
+ """Make an accepted version the live version that recipients open."""
405
+ return self._api.request(
406
+ "POST",
407
+ self._path(app_id, "activate"),
408
+ HostedApplication,
409
+ json_data={"version_id": version_id},
410
+ extra_headers=self._headers(if_match, idempotency_key),
411
+ wrap_response=False,
412
+ )
413
+
414
+ def marketplace_publish(
415
+ self, app_id: str, if_match: str, idempotency_key: str | None = None
416
+ ) -> HostedApplication:
417
+ """Publish an application to the marketplace."""
418
+ return self._api.request(
419
+ "POST",
420
+ self._path(app_id, "marketplace", "publish"),
421
+ HostedApplication,
422
+ json_data={},
423
+ extra_headers=self._headers(if_match, idempotency_key),
424
+ wrap_response=False,
425
+ )
426
+
427
+ def marketplace_unpublish(
428
+ self, app_id: str, if_match: str, idempotency_key: str | None = None
429
+ ) -> HostedApplication:
430
+ """Remove an application from the marketplace."""
431
+ return self._api.request(
432
+ "POST",
433
+ self._path(app_id, "marketplace", "unpublish"),
434
+ HostedApplication,
435
+ json_data={},
436
+ extra_headers=self._headers(if_match, idempotency_key),
437
+ wrap_response=False,
438
+ )
439
+
440
+ def share_with_users(
441
+ self, app_id: str, user_ids: list[str]
442
+ ) -> HostedApplicationSharedWith:
443
+ """Grant view access by name (owner only)."""
444
+ return self._api.post(
445
+ self._path(app_id, "share"),
446
+ HostedApplicationSharedWith,
447
+ json_data={"user_ids": user_ids},
448
+ wrap_response=False,
449
+ )
450
+
451
+ def unshare(self, app_id: str, user_ids: list[str]) -> HostedApplicationSharedWith:
452
+ """Revoke the view access granted by name (owner only)."""
453
+ return self._api.delete(
454
+ self._path(app_id, "share"),
455
+ HostedApplicationSharedWith,
456
+ json_data={"user_ids": user_ids},
457
+ wrap_response=False,
458
+ )
459
+
460
+ def shared_with(self, app_id: str) -> HostedApplicationSharedWith:
461
+ """People the application is shared with by name (owner only)."""
462
+ return self._api.get(
463
+ self._path(app_id, "shared-with"),
464
+ HostedApplicationSharedWith,
465
+ wrap_response=False,
466
+ )
467
+
468
+ def sharable_users(self, app_id: str, q: str) -> HostedApplicationSharableUsers:
469
+ """Directory users matching ``q`` that can be granted access (owner only)."""
470
+ return self._api.get(
471
+ self._path(app_id, "sharable-users"),
472
+ HostedApplicationSharableUsers,
473
+ params={"q": q},
474
+ wrap_response=False,
475
+ )
476
+
477
+ def get_share_link(self, app_id: str) -> HostedApplicationShareLink:
478
+ """The live share link of an application, if any (owner only)."""
479
+ return self._api.get(
480
+ self._path(app_id, "share-link"),
481
+ HostedApplicationShareLink,
482
+ wrap_response=False,
483
+ )
484
+
485
+ def create_share_link(self, app_id: str) -> HostedApplicationShareLink:
486
+ """Create the share link of an application, or get the live one (owner only)."""
487
+ return self._api.post(
488
+ self._path(app_id, "share-link"),
489
+ HostedApplicationShareLink,
490
+ wrap_response=False,
491
+ )
492
+
493
+ def delete_share_link(self, app_id: str) -> HostedApplicationShareLink:
494
+ """Revoke the share link and the access it gave."""
495
+ return self._api.delete(
496
+ self._path(app_id, "share-link"),
497
+ HostedApplicationShareLink,
498
+ wrap_response=False,
499
+ )
500
+
501
+ def open_share_link(self, token: str) -> HostedApplicationShareLinkTarget:
502
+ """Open a share link: the caller gets view access and the application id."""
503
+ # `request` sends the body without logging it; `post` would write the token to the debug log.
504
+ return self._api.request(
505
+ "POST",
506
+ f"{_BASE}/share-links/open",
507
+ HostedApplicationShareLinkTarget,
508
+ json_data={"token": token},
509
+ wrap_response=False,
510
+ )
511
+
512
+ def launch(
513
+ self,
514
+ app_id: str,
515
+ purpose: str = "published_view",
516
+ version_id: str | None = None,
517
+ path: str | None = None,
518
+ ) -> HostedApplicationLaunch:
519
+ """Get a one-use launch ticket for opening an application.
520
+
521
+ Args:
522
+ app_id: Application id
523
+ purpose: published_view (the live version, for readers) or owner_preview
524
+ (the working version, for managers)
525
+ version_id: Version to open, for an owner preview
526
+ path: Page of the version to open; the entry page when omitted
527
+ """
528
+ body: dict[str, Any] = {"purpose": purpose}
529
+ if version_id is not None:
530
+ body["version_id"] = version_id
531
+ if path is not None:
532
+ body["path"] = path
533
+ return self._api.post(
534
+ self._path(app_id, "launch"),
535
+ HostedApplicationLaunch,
536
+ json_data=body,
537
+ wrap_response=False,
538
+ )
539
+
540
+ def suspend_application(
541
+ self,
542
+ app_id: str,
543
+ reason: str,
544
+ if_match: str | None = None,
545
+ idempotency_key: str | None = None,
546
+ ) -> HostedApplication:
547
+ """Take an application down at once (platform administrators only)."""
548
+ return self._security(
549
+ app_id, "suspend", {"reason": reason}, if_match, idempotency_key
550
+ )
551
+
552
+ def reinstate_application(
553
+ self,
554
+ app_id: str,
555
+ reason: str,
556
+ if_match: str,
557
+ version_id: str | None = None,
558
+ idempotency_key: str | None = None,
559
+ ) -> HostedApplication:
560
+ """Bring a suspended application back (an administrator other than its creator)."""
561
+ body: dict[str, Any] = {"reason": reason}
562
+ if version_id is not None:
563
+ body["version_id"] = version_id
564
+ return self._security(app_id, "reinstate", body, if_match, idempotency_key)
565
+
566
+ def _security(
567
+ self,
568
+ app_id: str,
569
+ action: str,
570
+ body: dict[str, Any],
571
+ if_match: str | None,
572
+ idempotency_key: str | None,
573
+ ) -> HostedApplication:
574
+ return self._api.request(
575
+ "POST",
576
+ f"{_ADMIN_BASE}/{quote(str(app_id), safe='')}/security/{action}",
577
+ HostedApplication,
578
+ json_data=body,
579
+ extra_headers=self._headers(if_match, idempotency_key),
580
+ wrap_response=False,
581
+ )
codemie_sdk/utils/http.py CHANGED
@@ -415,3 +415,62 @@ class ApiRequestHandler:
415
415
  response.raise_for_status()
416
416
 
417
417
  return self._parse_response(response, response_model, wrap_response)
418
+
419
+ def request(
420
+ self,
421
+ method: str,
422
+ endpoint: str,
423
+ response_model: Type[T],
424
+ json_data: dict[str, Any] | None = None,
425
+ params: dict[str, Any] | None = None,
426
+ data: str | bytes | None = None,
427
+ extra_headers: dict[str, str] | None = None,
428
+ wrap_response: bool = True,
429
+ ) -> T:
430
+ """Makes a request with any method and extra headers, and parses the response.
431
+
432
+ Meant for routes that need a header the verb helpers do not take (for example
433
+ ``If-Match`` or ``Idempotency-Key``), a raw body on PUT, or a body on DELETE
434
+ together with headers.
435
+
436
+ Args:
437
+ method: HTTP method
438
+ endpoint: API endpoint path
439
+ response_model: Pydantic model class or list[Model] for response, or
440
+ requests.Response to get the response back unparsed
441
+ json_data: JSON request body
442
+ params: Query parameters
443
+ data: Raw request body for non-JSON payloads; set its Content-Type via extra_headers
444
+ extra_headers: Additional HTTP headers; they replace the defaults of the same name
445
+ wrap_response: Whether response is wrapped in 'data' field
446
+
447
+ Returns:
448
+ Parsed response object or list of objects, or the raw Response
449
+ """
450
+ headers = self._get_headers()
451
+ if extra_headers:
452
+ headers.update(extra_headers)
453
+ http_method = method.upper()
454
+ # The body is never logged here: callers send credentials such as share link tokens.
455
+ logger.debug(f"Making {http_method} request to {self._base_url}{endpoint}")
456
+ try:
457
+ response = requests.request(
458
+ method=http_method,
459
+ url=f"{self._base_url}{endpoint}",
460
+ headers=headers,
461
+ json=json_data,
462
+ params=params,
463
+ data=data,
464
+ verify=self._verify_ssl,
465
+ )
466
+ response.raise_for_status()
467
+
468
+ if response_model is None or response_model is requests.Response:
469
+ result = response
470
+ else:
471
+ result = self._parse_response(response, response_model, wrap_response)
472
+ except Exception as e:
473
+ logger.error(f"Error during {http_method} request to {endpoint}: {str(e)}")
474
+ raise
475
+ logger.info(f"Successfully processed {http_method} request to {endpoint}")
476
+ return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codemie-sdk-python
3
- Version: 0.1.715
3
+ Version: 0.1.716
4
4
  Summary: CodeMie SDK for Python
5
5
  License: Apache-2.0
6
6
  Author: CodeMie
@@ -1,4 +1,4 @@
1
- codemie_sdk/__init__.py,sha256=4JU0B6Z9zKvDipVm6urzw96eASlwmQ1_Yzs-H20-iEg,11283
1
+ codemie_sdk/__init__.py,sha256=6pVYSyZhWb6AwFFLxQOGEKj7fDhIpDqopTjoRA1gt_Y,12712
2
2
  codemie_sdk/auth/__init__.py,sha256=IksEj223xEZtJ-cQ0AT9L0Bs9psIJ8QNzDXrPTUQ3xQ,126
3
3
  codemie_sdk/auth/credentials.py,sha256=hO0X3EQWZSlIm0ABhiJo4fIIndm2blB0JZWMaWvsuTE,7774
4
4
  codemie_sdk/builders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -7,7 +7,7 @@ codemie_sdk/builders/workflow/builder.py,sha256=BZHLbHK35DYacEeGrz_eAxuwign19Uwo
7
7
  codemie_sdk/builders/workflow/definition.py,sha256=s82O4_lPz4ui-CeSxEfT1FqJsoSu4aezYm4ean2lBcs,18708
8
8
  codemie_sdk/builders/workflow/publish.py,sha256=wrXFDNX0LpRTULp8zm5DD6hEmAqEwIMxPm0mSs82xjQ,7370
9
9
  codemie_sdk/client/__init__.py,sha256=yf6C39MmrJ6gK9ZHMhBeynKwUUYVSUTQbKxU8-4qpKg,101
10
- codemie_sdk/client/client.py,sha256=XOPnIiy0wEERBuNlDebg-tdDrN1SQznQIJvnTqnzOj0,10554
10
+ codemie_sdk/client/client.py,sha256=4W338zSl3fakHFaHfy8-CsLHkFVQ_jzHmzwcxhoMruQ,10765
11
11
  codemie_sdk/exceptions.py,sha256=uuzvtvYBMzrNGt7Q4k5RVq0Pd8eJ_tR2tLy3pF2ICDs,1148
12
12
  codemie_sdk/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  codemie_sdk/models/a2a.py,sha256=93GGBg4vkrlnuGCtakMLgYtrD9U54Dme9Dm5sJGO2bc,1986
@@ -23,6 +23,7 @@ codemie_sdk/models/datasource.py,sha256=jp1Rbx1f0cvgUierU-3ru0xfq7NEpjaB_NBpp7Vf
23
23
  codemie_sdk/models/errors.py,sha256=tQXoPUhM2U95NoyTxsSSJws8PQ-Fr3iOQQ8IjJCsx78,11658
24
24
  codemie_sdk/models/file_operation.py,sha256=h5UBCCAbQQGm1EavF0AHn_dNE2t_Cc9be20lv_K5Vo8,722
25
25
  codemie_sdk/models/guardrails.py,sha256=813PRnu9VEF6hoUB-lw5xG_qAZXPic38qL40AwYkSMQ,2114
26
+ codemie_sdk/models/hosted_application.py,sha256=zf-NfhbRp1jnnPjtMkzkaoOG08MTNPlewAhHC9r-Fhs,8241
26
27
  codemie_sdk/models/integration.py,sha256=D-SLsLzel0kKj4grUPM6XXu3TtKWjjD8rKttH4gVuYg,3557
27
28
  codemie_sdk/models/llm.py,sha256=ViADvsSAkc85YQyPUkGE3ZvMc5pnHWHO0_rOkLSTfu4,1333
28
29
  codemie_sdk/models/marketplace_management.py,sha256=T51fSW0G8RGyBxMBnT_o5D8E00UQaW_Fcq1nw-RGlZY,6396
@@ -59,6 +60,7 @@ codemie_sdk/services/datasource.py,sha256=4Glf8pyytMM0kZi41FBIjY_DVCa9brrVMIBAGt
59
60
  codemie_sdk/services/dynamic_config.py,sha256=amgSOZ-835r6O_U72sjiFe60rrxJZqJ2L7oKCK-avE4,4214
60
61
  codemie_sdk/services/export.py,sha256=JFkci7R33hamwJ2rqCGDe6aRGIPKmW7QuZHdJDXp54g,2259
61
62
  codemie_sdk/services/files.py,sha256=ERb6irexO2hIKepUiTw498J0dt0427YNdKrXdcOu9tM,2762
63
+ codemie_sdk/services/hosted_application.py,sha256=r1VstJmhoqOmx1HsiIrRuefVNzfYwVZxm8Ueqa8RnSs,21001
62
64
  codemie_sdk/services/integration.py,sha256=n4ggDedJ2GCI5mTgZNfrYE49uzLsp_BKYKMdTBKRX2s,9944
63
65
  codemie_sdk/services/llm.py,sha256=GQWIi359f99uU4YRnAdpbyae1kXp1G5OpVgJNIIn7-8,1132
64
66
  codemie_sdk/services/marketplace_management.py,sha256=89JEPEg7tdwlFJ1LfKQJRJp4oug_nxMGBIjCf1S4H6U,7991
@@ -82,8 +84,8 @@ codemie_sdk/services/workflow_execution.py,sha256=GuI1uBtd1NGvRVHElMsgPBZlIRDP9C
82
84
  codemie_sdk/services/workflow_execution_state.py,sha256=u1xmGvaHjqvQS5ujhyvJ_Ac7ByjKem2Qe8q0swsmoWw,2045
83
85
  codemie_sdk/services/workspace.py,sha256=eLwZ0fhi1BfOesrXaQlTdOll8q7ENP9b_jb5eybKSVw,5038
84
86
  codemie_sdk/utils/__init__.py,sha256=EzK_UrS5KHmAnE73Hci9LaObB5omjVUhIq4svh0gfwo,137
85
- codemie_sdk/utils/http.py,sha256=PWejBKa5pwzQ5eLVhdN8lYKEu1B1QtwGTRmZfnGFL6c,14158
87
+ codemie_sdk/utils/http.py,sha256=94PBmIuT646i4B-FHWCZ8YDKybht_glzL1Qnrk0HrRI,16615
86
88
  codemie_sdk/utils/payload.py,sha256=XwIAdPWE3TdetV0bImx1Xkery0Hgm9dU_lAXmf2OSZI,313
87
- codemie_sdk_python-0.1.715.dist-info/METADATA,sha256=KbJfIYcnsppikiZ3eAFa-wdpcBq-cO_gwFkex2I-CPE,51375
88
- codemie_sdk_python-0.1.715.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
89
- codemie_sdk_python-0.1.715.dist-info/RECORD,,
89
+ codemie_sdk_python-0.1.716.dist-info/METADATA,sha256=c9UD4rDL_ft8B3D9oQbSVM3BaYtnfmwK76_nC_nLxS8,51375
90
+ codemie_sdk_python-0.1.716.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
91
+ codemie_sdk_python-0.1.716.dist-info/RECORD,,