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.js CHANGED
@@ -43257,6 +43257,89 @@ import {
43257
43257
  Status as Status9
43258
43258
  } from "nice-grpc";
43259
43259
 
43260
+ // src/cloud_bucket_mount.ts
43261
+ var CloudBucketMountService = class {
43262
+ #client;
43263
+ constructor(client2) {
43264
+ this.#client = client2;
43265
+ }
43266
+ create(bucketName, params = {}) {
43267
+ let bucketType = 1 /* S3 */;
43268
+ if (params.bucketEndpointUrl) {
43269
+ const url = new URL(params.bucketEndpointUrl);
43270
+ if (url.hostname.endsWith("r2.cloudflarestorage.com")) {
43271
+ bucketType = 2 /* R2 */;
43272
+ } else if (url.hostname.endsWith("storage.googleapis.com")) {
43273
+ bucketType = 3 /* GCP */;
43274
+ } else {
43275
+ bucketType = 1 /* S3 */;
43276
+ this.#client.logger.debug(
43277
+ "CloudBucketMount received unrecognized bucket endpoint URL. Assuming AWS S3 configuration as fallback.",
43278
+ "bucketEndpointUrl",
43279
+ params.bucketEndpointUrl
43280
+ );
43281
+ }
43282
+ }
43283
+ if (params.requesterPays && !params.secret) {
43284
+ throw new Error("Credentials required in order to use Requester Pays.");
43285
+ }
43286
+ if (params.keyPrefix && !params.keyPrefix.endsWith("/")) {
43287
+ throw new Error(
43288
+ "keyPrefix will be prefixed to all object paths, so it must end in a '/'"
43289
+ );
43290
+ }
43291
+ return new CloudBucketMount2(
43292
+ bucketName,
43293
+ params.secret,
43294
+ params.readOnly ?? false,
43295
+ params.requesterPays ?? false,
43296
+ params.bucketEndpointUrl,
43297
+ params.keyPrefix,
43298
+ params.oidcAuthRoleArn,
43299
+ bucketType
43300
+ );
43301
+ }
43302
+ };
43303
+ var CloudBucketMount2 = class {
43304
+ bucketName;
43305
+ secret;
43306
+ readOnly;
43307
+ requesterPays;
43308
+ bucketEndpointUrl;
43309
+ keyPrefix;
43310
+ oidcAuthRoleArn;
43311
+ #bucketType;
43312
+ constructor(bucketName, secretOrParams, readOnly, requesterPays, bucketEndpointUrl, keyPrefix, oidcAuthRoleArn, bucketType) {
43313
+ if (bucketType !== void 0) {
43314
+ this.bucketName = bucketName;
43315
+ this.secret = secretOrParams;
43316
+ this.readOnly = readOnly;
43317
+ this.requesterPays = requesterPays;
43318
+ this.bucketEndpointUrl = bucketEndpointUrl;
43319
+ this.keyPrefix = keyPrefix;
43320
+ this.oidcAuthRoleArn = oidcAuthRoleArn;
43321
+ this.#bucketType = bucketType;
43322
+ } else {
43323
+ const params = secretOrParams === void 0 ? {} : secretOrParams;
43324
+ return getDefaultClient().cloudBucketMounts.create(bucketName, params);
43325
+ }
43326
+ }
43327
+ /** @ignore */
43328
+ toProto(mountPath) {
43329
+ return {
43330
+ bucketName: this.bucketName,
43331
+ mountPath,
43332
+ credentialsSecretId: this.secret?.secretId ?? "",
43333
+ readOnly: this.readOnly,
43334
+ bucketType: this.#bucketType,
43335
+ requesterPays: this.requesterPays,
43336
+ bucketEndpointUrl: this.bucketEndpointUrl,
43337
+ keyPrefix: this.keyPrefix,
43338
+ oidcAuthRoleArn: this.oidcAuthRoleArn
43339
+ };
43340
+ }
43341
+ };
43342
+
43260
43343
  // src/cls.ts
43261
43344
  import { ClientError as ClientError3, Status as Status3 } from "nice-grpc";
43262
43345
 
@@ -43902,6 +43985,33 @@ var SecretService = class {
43902
43985
  throw err;
43903
43986
  }
43904
43987
  }
43988
+ /**
43989
+ * Delete a named {@link Secret}.
43990
+ *
43991
+ * Warning: Deletion is irreversible and will affect any Apps currently using the Secret.
43992
+ */
43993
+ async delete(name, params) {
43994
+ try {
43995
+ const secret = await this.fromName(name, {
43996
+ environment: params?.environment
43997
+ });
43998
+ await this.#client.cpClient.secretDelete({
43999
+ secretId: secret.secretId
44000
+ });
44001
+ this.#client.logger.debug(
44002
+ "Deleted Secret",
44003
+ "secret_name",
44004
+ name,
44005
+ "secret_id",
44006
+ secret.secretId
44007
+ );
44008
+ } catch (err) {
44009
+ if (err instanceof NotFoundError && params?.allowMissing) {
44010
+ return;
44011
+ }
44012
+ throw err;
44013
+ }
44014
+ }
43905
44015
  };
43906
44016
  var Secret = class {
43907
44017
  secretId;
@@ -44130,7 +44240,8 @@ var Cls = class _Cls {
44130
44240
  const bindResp = await this.#client.cpClient.functionBindParams({
44131
44241
  functionId: this.#serviceFunctionId,
44132
44242
  serializedParams,
44133
- functionOptions
44243
+ functionOptions,
44244
+ environmentName: this.#client.environmentName()
44134
44245
  });
44135
44246
  return bindResp.boundFunctionId;
44136
44247
  }
@@ -45061,26 +45172,51 @@ var QueueService = class {
45061
45172
  * Reference a {@link Queue} by name.
45062
45173
  */
45063
45174
  async fromName(name, params = {}) {
45064
- const resp = await this.#client.cpClient.queueGetOrCreate({
45065
- deploymentName: name,
45066
- objectCreationType: params.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : void 0,
45067
- environmentName: this.#client.environmentName(params.environment)
45068
- });
45069
- this.#client.logger.debug(
45070
- "Retrieved Queue",
45071
- "queue_id",
45072
- resp.queueId,
45073
- "queue_name",
45074
- name
45075
- );
45076
- return new Queue(this.#client, resp.queueId, name);
45175
+ try {
45176
+ const resp = await this.#client.cpClient.queueGetOrCreate({
45177
+ deploymentName: name,
45178
+ objectCreationType: params.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : void 0,
45179
+ environmentName: this.#client.environmentName(params.environment)
45180
+ });
45181
+ this.#client.logger.debug(
45182
+ "Retrieved Queue",
45183
+ "queue_id",
45184
+ resp.queueId,
45185
+ "queue_name",
45186
+ name
45187
+ );
45188
+ return new Queue(this.#client, resp.queueId, name);
45189
+ } catch (err) {
45190
+ if (err instanceof ClientError6 && err.code === Status6.NOT_FOUND)
45191
+ throw new NotFoundError(err.details);
45192
+ throw err;
45193
+ }
45077
45194
  }
45078
45195
  /**
45079
45196
  * Delete a {@link Queue} by name.
45197
+ *
45198
+ * Warning: Deletion is irreversible and will affect any Apps currently using the Queue.
45080
45199
  */
45081
45200
  async delete(name, params = {}) {
45082
- const queue = await this.fromName(name, params);
45083
- await this.#client.cpClient.queueDelete({ queueId: queue.queueId });
45201
+ try {
45202
+ const queue = await this.fromName(name, {
45203
+ environment: params.environment,
45204
+ createIfMissing: false
45205
+ });
45206
+ await this.#client.cpClient.queueDelete({ queueId: queue.queueId });
45207
+ this.#client.logger.debug(
45208
+ "Deleted Queue",
45209
+ "queue_name",
45210
+ name,
45211
+ "queue_id",
45212
+ queue.queueId
45213
+ );
45214
+ } catch (err) {
45215
+ if (err instanceof NotFoundError && params.allowMissing) {
45216
+ return;
45217
+ }
45218
+ throw err;
45219
+ }
45084
45220
  }
45085
45221
  };
45086
45222
  var Queue = class _Queue {
@@ -45528,68 +45664,6 @@ async function consumeIterator(iter) {
45528
45664
  }
45529
45665
  }
45530
45666
 
45531
- // src/cloud_bucket_mount.ts
45532
- var CloudBucketMount2 = class {
45533
- bucketName;
45534
- secret;
45535
- readOnly;
45536
- requesterPays;
45537
- bucketEndpointUrl;
45538
- keyPrefix;
45539
- oidcAuthRoleArn;
45540
- constructor(bucketName, params = {}) {
45541
- this.bucketName = bucketName;
45542
- this.secret = params.secret;
45543
- this.readOnly = params.readOnly ?? false;
45544
- this.requesterPays = params.requesterPays ?? false;
45545
- this.bucketEndpointUrl = params.bucketEndpointUrl;
45546
- this.keyPrefix = params.keyPrefix;
45547
- this.oidcAuthRoleArn = params.oidcAuthRoleArn;
45548
- if (this.bucketEndpointUrl) {
45549
- const url = new URL(this.bucketEndpointUrl);
45550
- if (!url.hostname.endsWith("r2.cloudflarestorage.com") && !url.hostname.endsWith("storage.googleapis.com")) {
45551
- console.warn(
45552
- "CloudBucketMount received unrecognized bucket endpoint URL. Assuming AWS S3 configuration as fallback."
45553
- );
45554
- }
45555
- }
45556
- if (this.requesterPays && !this.secret) {
45557
- throw new Error("Credentials required in order to use Requester Pays.");
45558
- }
45559
- if (this.keyPrefix && !this.keyPrefix.endsWith("/")) {
45560
- throw new Error(
45561
- "keyPrefix will be prefixed to all object paths, so it must end in a '/'"
45562
- );
45563
- }
45564
- }
45565
- };
45566
- function endpointUrlToBucketType(bucketEndpointUrl) {
45567
- if (!bucketEndpointUrl) {
45568
- return 1 /* S3 */;
45569
- }
45570
- const url = new URL(bucketEndpointUrl);
45571
- if (url.hostname.endsWith("r2.cloudflarestorage.com")) {
45572
- return 2 /* R2 */;
45573
- } else if (url.hostname.endsWith("storage.googleapis.com")) {
45574
- return 3 /* GCP */;
45575
- } else {
45576
- return 1 /* S3 */;
45577
- }
45578
- }
45579
- function cloudBucketMountToProto(mount, mountPath) {
45580
- return {
45581
- bucketName: mount.bucketName,
45582
- mountPath,
45583
- credentialsSecretId: mount.secret?.secretId ?? "",
45584
- readOnly: mount.readOnly,
45585
- bucketType: endpointUrlToBucketType(mount.bucketEndpointUrl),
45586
- requesterPays: mount.requesterPays,
45587
- bucketEndpointUrl: mount.bucketEndpointUrl,
45588
- keyPrefix: mount.keyPrefix,
45589
- oidcAuthRoleArn: mount.oidcAuthRoleArn
45590
- };
45591
- }
45592
-
45593
45667
  // src/sandbox.ts
45594
45668
  async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45595
45669
  checkForRenamedParams(params, {
@@ -45619,32 +45693,38 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45619
45693
  readOnly: volume.isReadOnly
45620
45694
  })) : [];
45621
45695
  const cloudBucketMounts = params.cloudBucketMounts ? Object.entries(params.cloudBucketMounts).map(
45622
- ([mountPath, mount]) => cloudBucketMountToProto(mount, mountPath)
45696
+ ([mountPath, mount]) => mount.toProto(mountPath)
45623
45697
  ) : [];
45624
45698
  const openPorts = [];
45625
45699
  if (params.encryptedPorts) {
45626
45700
  openPorts.push(
45627
- ...params.encryptedPorts.map((port) => ({
45628
- port,
45629
- unencrypted: false
45630
- }))
45701
+ ...params.encryptedPorts.map(
45702
+ (port) => PortSpec.create({
45703
+ port,
45704
+ unencrypted: false
45705
+ })
45706
+ )
45631
45707
  );
45632
45708
  }
45633
45709
  if (params.h2Ports) {
45634
45710
  openPorts.push(
45635
- ...params.h2Ports.map((port) => ({
45636
- port,
45637
- unencrypted: false,
45638
- tunnelType: 1 /* TUNNEL_TYPE_H2 */
45639
- }))
45711
+ ...params.h2Ports.map(
45712
+ (port) => PortSpec.create({
45713
+ port,
45714
+ unencrypted: false,
45715
+ tunnelType: 1 /* TUNNEL_TYPE_H2 */
45716
+ })
45717
+ )
45640
45718
  );
45641
45719
  }
45642
45720
  if (params.unencryptedPorts) {
45643
45721
  openPorts.push(
45644
- ...params.unencryptedPorts.map((port) => ({
45645
- port,
45646
- unencrypted: true
45647
- }))
45722
+ ...params.unencryptedPorts.map(
45723
+ (port) => PortSpec.create({
45724
+ port,
45725
+ unencrypted: true
45726
+ })
45727
+ )
45648
45728
  );
45649
45729
  }
45650
45730
  const secretIds = (params.secrets || []).map((secret) => secret.secretId);
@@ -45670,9 +45750,9 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45670
45750
  allowedCidrs: []
45671
45751
  };
45672
45752
  }
45673
- const schedulerPlacement = SchedulerPlacement.create({
45674
- regions: params.regions ?? []
45675
- });
45753
+ const schedulerPlacement = params.regions?.length ? SchedulerPlacement.create({
45754
+ regions: params.regions
45755
+ }) : void 0;
45676
45756
  let ptyInfo;
45677
45757
  if (params.pty) {
45678
45758
  ptyInfo = defaultSandboxPTYInfo();
@@ -45729,18 +45809,18 @@ async function buildSandboxCreateRequestProto(appId, imageId, params = {}) {
45729
45809
  idleTimeoutSecs: params.idleTimeoutMs != void 0 ? params.idleTimeoutMs / 1e3 : void 0,
45730
45810
  workdir: params.workdir ?? void 0,
45731
45811
  networkAccess,
45732
- resources: {
45812
+ resources: Resources.create({
45733
45813
  milliCpu,
45734
45814
  milliCpuMax,
45735
45815
  memoryMb,
45736
45816
  memoryMbMax,
45737
45817
  gpuConfig
45738
- },
45818
+ }),
45739
45819
  volumeMounts,
45740
45820
  cloudBucketMounts,
45741
45821
  ptyInfo,
45742
45822
  secretIds,
45743
- openPorts: openPorts.length > 0 ? { ports: openPorts } : void 0,
45823
+ openPorts: PortSpecs.create({ ports: openPorts }),
45744
45824
  cloudProviderStr: params.cloud ?? "",
45745
45825
  schedulerPlacement,
45746
45826
  verbose: params.verbose ?? false,
@@ -46398,6 +46478,34 @@ var VolumeService = class {
46398
46478
  );
46399
46479
  return new Volume(resp.volumeId, void 0, false, ephemeralHbManager);
46400
46480
  }
46481
+ /**
46482
+ * Delete a named {@link Volume}.
46483
+ *
46484
+ * Warning: Deletion is irreversible and will affect any Apps currently using the Volume.
46485
+ */
46486
+ async delete(name, params) {
46487
+ try {
46488
+ const volume = await this.fromName(name, {
46489
+ environment: params?.environment,
46490
+ createIfMissing: false
46491
+ });
46492
+ await this.#client.cpClient.volumeDelete({
46493
+ volumeId: volume.volumeId
46494
+ });
46495
+ this.#client.logger.debug(
46496
+ "Deleted Volume",
46497
+ "volume_name",
46498
+ name,
46499
+ "volume_id",
46500
+ volume.volumeId
46501
+ );
46502
+ } catch (err) {
46503
+ if (err instanceof NotFoundError && params?.allowMissing) {
46504
+ return;
46505
+ }
46506
+ throw err;
46507
+ }
46508
+ }
46401
46509
  };
46402
46510
  var Volume = class _Volume {
46403
46511
  volumeId;
@@ -46628,7 +46736,7 @@ var AuthTokenManager = class {
46628
46736
 
46629
46737
  // src/version.ts
46630
46738
  function getSDKVersion() {
46631
- return true ? "0.5.3" : "0.0.0";
46739
+ return true ? "0.5.5" : "0.0.0";
46632
46740
  }
46633
46741
 
46634
46742
  // src/logger.ts
@@ -46738,8 +46846,9 @@ function createLogger(logger, logLevel = "") {
46738
46846
  }
46739
46847
 
46740
46848
  // src/client.ts
46741
- var ModalClient = class {
46849
+ var ModalClient2 = class {
46742
46850
  apps;
46851
+ cloudBucketMounts;
46743
46852
  cls;
46744
46853
  functions;
46745
46854
  functionCalls;
@@ -46779,6 +46888,7 @@ var ModalClient = class {
46779
46888
  this.cpClient = params?.cpClient ?? this.createClient(this.profile);
46780
46889
  this.logger.debug("Modal client initialized successfully");
46781
46890
  this.apps = new AppService(this);
46891
+ this.cloudBucketMounts = new CloudBucketMountService(this);
46782
46892
  this.cls = new ClsService(this);
46783
46893
  this.functions = new FunctionService(this);
46784
46894
  this.functionCalls = new FunctionCallService(this);
@@ -47012,7 +47122,7 @@ var defaultClient;
47012
47122
  var defaultClientOptions;
47013
47123
  function getDefaultClient() {
47014
47124
  if (!defaultClient) {
47015
- defaultClient = new ModalClient(defaultClientOptions);
47125
+ defaultClient = new ModalClient2(defaultClientOptions);
47016
47126
  }
47017
47127
  return defaultClient;
47018
47128
  }
@@ -47027,7 +47137,7 @@ function initializeClient(options) {
47027
47137
  tokenSecret: options.tokenSecret,
47028
47138
  environment: options.environment
47029
47139
  };
47030
- defaultClient = new ModalClient(defaultClientOptions);
47140
+ defaultClient = new ModalClient2(defaultClientOptions);
47031
47141
  }
47032
47142
  function close() {
47033
47143
  if (defaultClient) {
@@ -47068,7 +47178,7 @@ var AppService = class {
47068
47178
  };
47069
47179
  function parseGpuConfig(gpu) {
47070
47180
  if (!gpu) {
47071
- return void 0;
47181
+ return GPUConfig.create({});
47072
47182
  }
47073
47183
  let gpuType = gpu;
47074
47184
  let count = 1;
@@ -47082,12 +47192,10 @@ function parseGpuConfig(gpu) {
47082
47192
  );
47083
47193
  }
47084
47194
  }
47085
- return {
47086
- type: 0,
47087
- // Deprecated field, but required by proto
47195
+ return GPUConfig.create({
47088
47196
  count,
47089
47197
  gpuType: gpuType.toUpperCase()
47090
- };
47198
+ });
47091
47199
  }
47092
47200
  var App2 = class {
47093
47201
  appId;
@@ -47100,6 +47208,7 @@ var App2 = class {
47100
47208
  /**
47101
47209
  * @deprecated Use {@link AppService#fromName client.apps.fromName()} instead.
47102
47210
  */
47211
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
47103
47212
  static async lookup(name, options = {}) {
47104
47213
  return getDefaultClient().apps.fromName(name, options);
47105
47214
  }
@@ -47133,6 +47242,7 @@ export {
47133
47242
  App2 as App,
47134
47243
  AppService,
47135
47244
  CloudBucketMount2 as CloudBucketMount,
47245
+ CloudBucketMountService,
47136
47246
  Cls,
47137
47247
  ClsInstance,
47138
47248
  ClsService,
@@ -47146,7 +47256,7 @@ export {
47146
47256
  ImageService,
47147
47257
  InternalFailure,
47148
47258
  InvalidError,
47149
- ModalClient,
47259
+ ModalClient2 as ModalClient,
47150
47260
  NotFoundError,
47151
47261
  Proxy3 as Proxy,
47152
47262
  ProxyService,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modal",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Modal SDK for JavaScript/TypeScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://modal.com/docs/guide/sdk-javascript-go",