modal 0.5.3 → 0.5.5

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.cjs CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  App: () => App2,
35
35
  AppService: () => AppService,
36
36
  CloudBucketMount: () => CloudBucketMount2,
37
+ CloudBucketMountService: () => CloudBucketMountService,
37
38
  Cls: () => Cls,
38
39
  ClsInstance: () => ClsInstance,
39
40
  ClsService: () => ClsService,
@@ -47,7 +48,7 @@ __export(index_exports, {
47
48
  ImageService: () => ImageService,
48
49
  InternalFailure: () => InternalFailure,
49
50
  InvalidError: () => InvalidError,
50
- ModalClient: () => ModalClient,
51
+ ModalClient: () => ModalClient2,
51
52
  NotFoundError: () => NotFoundError,
52
53
  Proxy: () => Proxy3,
53
54
  ProxyService: () => ProxyService,
@@ -43324,6 +43325,89 @@ function isSet4(value) {
43324
43325
  var import_uuid = require("uuid");
43325
43326
  var import_nice_grpc10 = require("nice-grpc");
43326
43327
 
43328
+ // src/cloud_bucket_mount.ts
43329
+ var CloudBucketMountService = class {
43330
+ #client;
43331
+ constructor(client2) {
43332
+ this.#client = client2;
43333
+ }
43334
+ create(bucketName, params = {}) {
43335
+ let bucketType = 1 /* S3 */;
43336
+ if (params.bucketEndpointUrl) {
43337
+ const url = new URL(params.bucketEndpointUrl);
43338
+ if (url.hostname.endsWith("r2.cloudflarestorage.com")) {
43339
+ bucketType = 2 /* R2 */;
43340
+ } else if (url.hostname.endsWith("storage.googleapis.com")) {
43341
+ bucketType = 3 /* GCP */;
43342
+ } else {
43343
+ bucketType = 1 /* S3 */;
43344
+ this.#client.logger.debug(
43345
+ "CloudBucketMount received unrecognized bucket endpoint URL. Assuming AWS S3 configuration as fallback.",
43346
+ "bucketEndpointUrl",
43347
+ params.bucketEndpointUrl
43348
+ );
43349
+ }
43350
+ }
43351
+ if (params.requesterPays && !params.secret) {
43352
+ throw new Error("Credentials required in order to use Requester Pays.");
43353
+ }
43354
+ if (params.keyPrefix && !params.keyPrefix.endsWith("/")) {
43355
+ throw new Error(
43356
+ "keyPrefix will be prefixed to all object paths, so it must end in a '/'"
43357
+ );
43358
+ }
43359
+ return new CloudBucketMount2(
43360
+ bucketName,
43361
+ params.secret,
43362
+ params.readOnly ?? false,
43363
+ params.requesterPays ?? false,
43364
+ params.bucketEndpointUrl,
43365
+ params.keyPrefix,
43366
+ params.oidcAuthRoleArn,
43367
+ bucketType
43368
+ );
43369
+ }
43370
+ };
43371
+ var CloudBucketMount2 = class {
43372
+ bucketName;
43373
+ secret;
43374
+ readOnly;
43375
+ requesterPays;
43376
+ bucketEndpointUrl;
43377
+ keyPrefix;
43378
+ oidcAuthRoleArn;
43379
+ #bucketType;
43380
+ constructor(bucketName, secretOrParams, readOnly, requesterPays, bucketEndpointUrl, keyPrefix, oidcAuthRoleArn, bucketType) {
43381
+ if (bucketType !== void 0) {
43382
+ this.bucketName = bucketName;
43383
+ this.secret = secretOrParams;
43384
+ this.readOnly = readOnly;
43385
+ this.requesterPays = requesterPays;
43386
+ this.bucketEndpointUrl = bucketEndpointUrl;
43387
+ this.keyPrefix = keyPrefix;
43388
+ this.oidcAuthRoleArn = oidcAuthRoleArn;
43389
+ this.#bucketType = bucketType;
43390
+ } else {
43391
+ const params = secretOrParams === void 0 ? {} : secretOrParams;
43392
+ return getDefaultClient().cloudBucketMounts.create(bucketName, params);
43393
+ }
43394
+ }
43395
+ /** @ignore */
43396
+ toProto(mountPath) {
43397
+ return {
43398
+ bucketName: this.bucketName,
43399
+ mountPath,
43400
+ credentialsSecretId: this.secret?.secretId ?? "",
43401
+ readOnly: this.readOnly,
43402
+ bucketType: this.#bucketType,
43403
+ requesterPays: this.requesterPays,
43404
+ bucketEndpointUrl: this.bucketEndpointUrl,
43405
+ keyPrefix: this.keyPrefix,
43406
+ oidcAuthRoleArn: this.oidcAuthRoleArn
43407
+ };
43408
+ }
43409
+ };
43410
+
43327
43411
  // src/cls.ts
43328
43412
  var import_nice_grpc3 = require("nice-grpc");
43329
43413
 
@@ -43969,6 +44053,33 @@ var SecretService = class {
43969
44053
  throw err;
43970
44054
  }
43971
44055
  }
44056
+ /**
44057
+ * Delete a named {@link Secret}.
44058
+ *
44059
+ * Warning: Deletion is irreversible and will affect any Apps currently using the Secret.
44060
+ */
44061
+ async delete(name, params) {
44062
+ try {
44063
+ const secret = await this.fromName(name, {
44064
+ environment: params?.environment
44065
+ });
44066
+ await this.#client.cpClient.secretDelete({
44067
+ secretId: secret.secretId
44068
+ });
44069
+ this.#client.logger.debug(
44070
+ "Deleted Secret",
44071
+ "secret_name",
44072
+ name,
44073
+ "secret_id",
44074
+ secret.secretId
44075
+ );
44076
+ } catch (err) {
44077
+ if (err instanceof NotFoundError && params?.allowMissing) {
44078
+ return;
44079
+ }
44080
+ throw err;
44081
+ }
44082
+ }
43972
44083
  };
43973
44084
  var Secret = class {
43974
44085
  secretId;
@@ -44197,7 +44308,8 @@ var Cls = class _Cls {
44197
44308
  const bindResp = await this.#client.cpClient.functionBindParams({
44198
44309
  functionId: this.#serviceFunctionId,
44199
44310
  serializedParams,
44200
- functionOptions
44311
+ functionOptions,
44312
+ environmentName: this.#client.environmentName()
44201
44313
  });
44202
44314
  return bindResp.boundFunctionId;
44203
44315
  }
@@ -45128,26 +45240,51 @@ var QueueService = class {
45128
45240
  * Reference a {@link Queue} by name.
45129
45241
  */
45130
45242
  async fromName(name, params = {}) {
45131
- const resp = await this.#client.cpClient.queueGetOrCreate({
45132
- deploymentName: name,
45133
- objectCreationType: params.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : void 0,
45134
- environmentName: this.#client.environmentName(params.environment)
45135
- });
45136
- this.#client.logger.debug(
45137
- "Retrieved Queue",
45138
- "queue_id",
45139
- resp.queueId,
45140
- "queue_name",
45141
- name
45142
- );
45143
- return new Queue(this.#client, resp.queueId, name);
45243
+ try {
45244
+ const resp = await this.#client.cpClient.queueGetOrCreate({
45245
+ deploymentName: name,
45246
+ objectCreationType: params.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : void 0,
45247
+ environmentName: this.#client.environmentName(params.environment)
45248
+ });
45249
+ this.#client.logger.debug(
45250
+ "Retrieved Queue",
45251
+ "queue_id",
45252
+ resp.queueId,
45253
+ "queue_name",
45254
+ name
45255
+ );
45256
+ return new Queue(this.#client, resp.queueId, name);
45257
+ } catch (err) {
45258
+ if (err instanceof import_nice_grpc7.ClientError && err.code === import_nice_grpc7.Status.NOT_FOUND)
45259
+ throw new NotFoundError(err.details);
45260
+ throw err;
45261
+ }
45144
45262
  }
45145
45263
  /**
45146
45264
  * Delete a {@link Queue} by name.
45265
+ *
45266
+ * Warning: Deletion is irreversible and will affect any Apps currently using the Queue.
45147
45267
  */
45148
45268
  async delete(name, params = {}) {
45149
- const queue = await this.fromName(name, params);
45150
- await this.#client.cpClient.queueDelete({ queueId: queue.queueId });
45269
+ try {
45270
+ const queue = await this.fromName(name, {
45271
+ environment: params.environment,
45272
+ createIfMissing: false
45273
+ });
45274
+ await this.#client.cpClient.queueDelete({ queueId: queue.queueId });
45275
+ this.#client.logger.debug(
45276
+ "Deleted Queue",
45277
+ "queue_name",
45278
+ name,
45279
+ "queue_id",
45280
+ queue.queueId
45281
+ );
45282
+ } catch (err) {
45283
+ if (err instanceof NotFoundError && params.allowMissing) {
45284
+ return;
45285
+ }
45286
+ throw err;
45287
+ }
45151
45288
  }
45152
45289
  };
45153
45290
  var Queue = class _Queue {
@@ -45595,68 +45732,6 @@ async function consumeIterator(iter) {
45595
45732
  }
45596
45733
  }
45597
45734
 
45598
- // src/cloud_bucket_mount.ts
45599
- var CloudBucketMount2 = class {
45600
- bucketName;
45601
- secret;
45602
- readOnly;
45603
- requesterPays;
45604
- bucketEndpointUrl;
45605
- keyPrefix;
45606
- oidcAuthRoleArn;
45607
- constructor(bucketName, params = {}) {
45608
- this.bucketName = bucketName;
45609
- this.secret = params.secret;
45610
- this.readOnly = params.readOnly ?? false;
45611
- this.requesterPays = params.requesterPays ?? false;
45612
- this.bucketEndpointUrl = params.bucketEndpointUrl;
45613
- this.keyPrefix = params.keyPrefix;
45614
- this.oidcAuthRoleArn = params.oidcAuthRoleArn;
45615
- if (this.bucketEndpointUrl) {
45616
- const url = new URL(this.bucketEndpointUrl);
45617
- if (!url.hostname.endsWith("r2.cloudflarestorage.com") && !url.hostname.endsWith("storage.googleapis.com")) {
45618
- console.warn(
45619
- "CloudBucketMount received unrecognized bucket endpoint URL. Assuming AWS S3 configuration as fallback."
45620
- );
45621
- }
45622
- }
45623
- if (this.requesterPays && !this.secret) {
45624
- throw new Error("Credentials required in order to use Requester Pays.");
45625
- }
45626
- if (this.keyPrefix && !this.keyPrefix.endsWith("/")) {
45627
- throw new Error(
45628
- "keyPrefix will be prefixed to all object paths, so it must end in a '/'"
45629
- );
45630
- }
45631
- }
45632
- };
45633
- function endpointUrlToBucketType(bucketEndpointUrl) {
45634
- if (!bucketEndpointUrl) {
45635
- return 1 /* S3 */;
45636
- }
45637
- const url = new URL(bucketEndpointUrl);
45638
- if (url.hostname.endsWith("r2.cloudflarestorage.com")) {
45639
- return 2 /* R2 */;
45640
- } else if (url.hostname.endsWith("storage.googleapis.com")) {
45641
- return 3 /* GCP */;
45642
- } else {
45643
- return 1 /* S3 */;
45644
- }
45645
- }
45646
- function cloudBucketMountToProto(mount, mountPath) {
45647
- return {
45648
- bucketName: mount.bucketName,
45649
- mountPath,
45650
- credentialsSecretId: mount.secret?.secretId ?? "",
45651
- readOnly: mount.readOnly,
45652
- bucketType: endpointUrlToBucketType(mount.bucketEndpointUrl),
45653
- requesterPays: mount.requesterPays,
45654
- bucketEndpointUrl: mount.bucketEndpointUrl,
45655
- keyPrefix: mount.keyPrefix,
45656
- oidcAuthRoleArn: mount.oidcAuthRoleArn
45657
- };
45658
- }
45659
-
45660
45735
  // src/sandbox.ts
45661
45736
  async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45662
45737
  checkForRenamedParams(params, {
@@ -45686,32 +45761,38 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45686
45761
  readOnly: volume.isReadOnly
45687
45762
  })) : [];
45688
45763
  const cloudBucketMounts = params.cloudBucketMounts ? Object.entries(params.cloudBucketMounts).map(
45689
- ([mountPath, mount]) => cloudBucketMountToProto(mount, mountPath)
45764
+ ([mountPath, mount]) => mount.toProto(mountPath)
45690
45765
  ) : [];
45691
45766
  const openPorts = [];
45692
45767
  if (params.encryptedPorts) {
45693
45768
  openPorts.push(
45694
- ...params.encryptedPorts.map((port) => ({
45695
- port,
45696
- unencrypted: false
45697
- }))
45769
+ ...params.encryptedPorts.map(
45770
+ (port) => PortSpec.create({
45771
+ port,
45772
+ unencrypted: false
45773
+ })
45774
+ )
45698
45775
  );
45699
45776
  }
45700
45777
  if (params.h2Ports) {
45701
45778
  openPorts.push(
45702
- ...params.h2Ports.map((port) => ({
45703
- port,
45704
- unencrypted: false,
45705
- tunnelType: 1 /* TUNNEL_TYPE_H2 */
45706
- }))
45779
+ ...params.h2Ports.map(
45780
+ (port) => PortSpec.create({
45781
+ port,
45782
+ unencrypted: false,
45783
+ tunnelType: 1 /* TUNNEL_TYPE_H2 */
45784
+ })
45785
+ )
45707
45786
  );
45708
45787
  }
45709
45788
  if (params.unencryptedPorts) {
45710
45789
  openPorts.push(
45711
- ...params.unencryptedPorts.map((port) => ({
45712
- port,
45713
- unencrypted: true
45714
- }))
45790
+ ...params.unencryptedPorts.map(
45791
+ (port) => PortSpec.create({
45792
+ port,
45793
+ unencrypted: true
45794
+ })
45795
+ )
45715
45796
  );
45716
45797
  }
45717
45798
  const secretIds = (params.secrets || []).map((secret) => secret.secretId);
@@ -45737,9 +45818,9 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45737
45818
  allowedCidrs: []
45738
45819
  };
45739
45820
  }
45740
- const schedulerPlacement = SchedulerPlacement.create({
45741
- regions: params.regions ?? []
45742
- });
45821
+ const schedulerPlacement = params.regions?.length ? SchedulerPlacement.create({
45822
+ regions: params.regions
45823
+ }) : void 0;
45743
45824
  let ptyInfo;
45744
45825
  if (params.pty) {
45745
45826
  ptyInfo = defaultSandboxPTYInfo();
@@ -45796,18 +45877,18 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45796
45877
  idleTimeoutSecs: params.idleTimeoutMs != void 0 ? params.idleTimeoutMs / 1e3 : void 0,
45797
45878
  workdir: params.workdir ?? void 0,
45798
45879
  networkAccess,
45799
- resources: {
45880
+ resources: Resources.create({
45800
45881
  milliCpu,
45801
45882
  milliCpuMax,
45802
45883
  memoryMb,
45803
45884
  memoryMbMax,
45804
45885
  gpuConfig
45805
- },
45886
+ }),
45806
45887
  volumeMounts,
45807
45888
  cloudBucketMounts,
45808
45889
  ptyInfo,
45809
45890
  secretIds,
45810
- openPorts: openPorts.length > 0 ? { ports: openPorts } : void 0,
45891
+ openPorts: PortSpecs.create({ ports: openPorts }),
45811
45892
  cloudProviderStr: params.cloud ?? "",
45812
45893
  schedulerPlacement,
45813
45894
  verbose: params.verbose ?? false,
@@ -46465,6 +46546,34 @@ var VolumeService = class {
46465
46546
  );
46466
46547
  return new Volume(resp.volumeId, void 0, false, ephemeralHbManager);
46467
46548
  }
46549
+ /**
46550
+ * Delete a named {@link Volume}.
46551
+ *
46552
+ * Warning: Deletion is irreversible and will affect any Apps currently using the Volume.
46553
+ */
46554
+ async delete(name, params) {
46555
+ try {
46556
+ const volume = await this.fromName(name, {
46557
+ environment: params?.environment,
46558
+ createIfMissing: false
46559
+ });
46560
+ await this.#client.cpClient.volumeDelete({
46561
+ volumeId: volume.volumeId
46562
+ });
46563
+ this.#client.logger.debug(
46564
+ "Deleted Volume",
46565
+ "volume_name",
46566
+ name,
46567
+ "volume_id",
46568
+ volume.volumeId
46569
+ );
46570
+ } catch (err) {
46571
+ if (err instanceof NotFoundError && params?.allowMissing) {
46572
+ return;
46573
+ }
46574
+ throw err;
46575
+ }
46576
+ }
46468
46577
  };
46469
46578
  var Volume = class _Volume {
46470
46579
  volumeId;
@@ -46695,7 +46804,7 @@ var AuthTokenManager = class {
46695
46804
 
46696
46805
  // src/version.ts
46697
46806
  function getSDKVersion() {
46698
- return true ? "0.5.3" : "0.0.0";
46807
+ return true ? "0.5.5" : "0.0.0";
46699
46808
  }
46700
46809
 
46701
46810
  // src/logger.ts
@@ -46805,8 +46914,9 @@ function createLogger(logger, logLevel = "") {
46805
46914
  }
46806
46915
 
46807
46916
  // src/client.ts
46808
- var ModalClient = class {
46917
+ var ModalClient2 = class {
46809
46918
  apps;
46919
+ cloudBucketMounts;
46810
46920
  cls;
46811
46921
  functions;
46812
46922
  functionCalls;
@@ -46846,6 +46956,7 @@ var ModalClient = class {
46846
46956
  this.cpClient = params?.cpClient ?? this.createClient(this.profile);
46847
46957
  this.logger.debug("Modal client initialized successfully");
46848
46958
  this.apps = new AppService(this);
46959
+ this.cloudBucketMounts = new CloudBucketMountService(this);
46849
46960
  this.cls = new ClsService(this);
46850
46961
  this.functions = new FunctionService(this);
46851
46962
  this.functionCalls = new FunctionCallService(this);
@@ -47079,7 +47190,7 @@ var defaultClient;
47079
47190
  var defaultClientOptions;
47080
47191
  function getDefaultClient() {
47081
47192
  if (!defaultClient) {
47082
- defaultClient = new ModalClient(defaultClientOptions);
47193
+ defaultClient = new ModalClient2(defaultClientOptions);
47083
47194
  }
47084
47195
  return defaultClient;
47085
47196
  }
@@ -47094,7 +47205,7 @@ function initializeClient(options) {
47094
47205
  tokenSecret: options.tokenSecret,
47095
47206
  environment: options.environment
47096
47207
  };
47097
- defaultClient = new ModalClient(defaultClientOptions);
47208
+ defaultClient = new ModalClient2(defaultClientOptions);
47098
47209
  }
47099
47210
  function close() {
47100
47211
  if (defaultClient) {
@@ -47135,7 +47246,7 @@ var AppService = class {
47135
47246
  };
47136
47247
  function parseGpuConfig(gpu) {
47137
47248
  if (!gpu) {
47138
- return void 0;
47249
+ return GPUConfig.create({});
47139
47250
  }
47140
47251
  let gpuType = gpu;
47141
47252
  let count = 1;
@@ -47149,12 +47260,10 @@ function parseGpuConfig(gpu) {
47149
47260
  );
47150
47261
  }
47151
47262
  }
47152
- return {
47153
- type: 0,
47154
- // Deprecated field, but required by proto
47263
+ return GPUConfig.create({
47155
47264
  count,
47156
47265
  gpuType: gpuType.toUpperCase()
47157
- };
47266
+ });
47158
47267
  }
47159
47268
  var App2 = class {
47160
47269
  appId;
@@ -47167,6 +47276,7 @@ var App2 = class {
47167
47276
  /**
47168
47277
  * @deprecated Use {@link AppService#fromName client.apps.fromName()} instead.
47169
47278
  */
47279
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
47170
47280
  static async lookup(name, options = {}) {
47171
47281
  return getDefaultClient().apps.fromName(name, options);
47172
47282
  }
@@ -47201,6 +47311,7 @@ var App2 = class {
47201
47311
  App,
47202
47312
  AppService,
47203
47313
  CloudBucketMount,
47314
+ CloudBucketMountService,
47204
47315
  Cls,
47205
47316
  ClsInstance,
47206
47317
  ClsService,