@sandbox-kit/sandbox 0.1.0 → 0.1.2

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.
@@ -22,13 +22,16 @@ export type SecretReference = StripProto<ProtoSecretReference>;
22
22
  export type ObservabilityConfig = StripProto<ProtoObservabilityConfig>;
23
23
  export type SandboxInfo = StripProto<ProtoSandboxInfo>;
24
24
  export type CreateResult = StripProto<ProtoCreateResult>;
25
- /** Wire lifecycle options (Duration timeouts) for providers / Backend. */
26
- export type StartOptions = StripProto<ProtoStartOptions>;
27
- export type StopOptions = StripProto<ProtoStopOptions>;
28
- export type PauseOptions = StripProto<ProtoPauseOptions>;
29
- export type TerminateOptions = StripProto<ProtoTerminateOptions>;
30
- export type ArchiveOptions = StripProto<ProtoArchiveOptions>;
31
- export type DeleteOptions = StripProto<ProtoDeleteOptions>;
25
+ /**
26
+ * Public lifecycle options for `Backend` and provider adapters (ms timeouts).
27
+ * Same duration remapping as {@link CreateOptions}; wire `Duration` stays private.
28
+ */
29
+ export type StartOptions = DurationFieldsToMs<StripProto<ProtoStartOptions>>;
30
+ export type StopOptions = DurationFieldsToMs<StripProto<ProtoStopOptions>>;
31
+ export type PauseOptions = DurationFieldsToMs<StripProto<ProtoPauseOptions>>;
32
+ export type TerminateOptions = DurationFieldsToMs<StripProto<ProtoTerminateOptions>>;
33
+ export type ArchiveOptions = DurationFieldsToMs<StripProto<ProtoArchiveOptions>>;
34
+ export type DeleteOptions = DurationFieldsToMs<StripProto<ProtoDeleteOptions>>;
32
35
  export type ExitResult = StripProto<ProtoExitResult>;
33
36
  export type MetadataValue = StripProto<ProtoMetadataValue>;
34
37
  export type MetadataList = StripProto<ProtoMetadataList>;
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from "#contracts/field_paths.js";
3
3
  export * from "#contracts/config_paths.js";
4
4
  export * from "#metadata/metadata_object.js";
5
5
  export * from "#client/client.js";
6
+ export { validCidr, validDomain, validEnvName, } from "#internal/net_validate.js";
package/dist/index.js CHANGED
@@ -3,3 +3,4 @@ export * from "#contracts/field_paths.js";
3
3
  export * from "#contracts/config_paths.js";
4
4
  export * from "#metadata/metadata_object.js";
5
5
  export * from "#client/client.js";
6
+ export { validCidr, validDomain, validEnvName, } from "#internal/net_validate.js";
@@ -0,0 +1,4 @@
1
+ /** Shared network / env name validators used by provider create checks. */
2
+ export declare function validEnvName(value: string): boolean;
3
+ export declare function validDomain(value: string): boolean;
4
+ export declare function validCidr(value: string): boolean;
@@ -0,0 +1,53 @@
1
+ /** Shared network / env name validators used by provider create checks. */
2
+ export function validEnvName(value) {
3
+ return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value);
4
+ }
5
+ export function validDomain(value) {
6
+ const domain = value.startsWith("*.") ? value.slice(2) : value;
7
+ return (domain.length <= 253 &&
8
+ /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.?$/i.test(domain));
9
+ }
10
+ export function validCidr(value) {
11
+ const separator = value.lastIndexOf("/");
12
+ if (separator <= 0)
13
+ return false;
14
+ const address = value.slice(0, separator);
15
+ const prefix = Number(value.slice(separator + 1));
16
+ if (!Number.isInteger(prefix))
17
+ return false;
18
+ return address.includes(":")
19
+ ? prefix >= 0 && prefix <= 128 && validIpv6(address)
20
+ : prefix >= 0 && prefix <= 32 && validIpv4(address);
21
+ }
22
+ function validIpv4(value) {
23
+ const parts = value.split(".");
24
+ return (parts.length === 4 &&
25
+ parts.every((part) => /^(0|[1-9][0-9]{0,2})$/.test(part) && Number(part) <= 255));
26
+ }
27
+ function validIpv6(value) {
28
+ if ((value.match(/::/g)?.length ?? 0) > 1)
29
+ return false;
30
+ const halves = value.split("::");
31
+ if (halves.length > 2)
32
+ return false;
33
+ const count = (part) => {
34
+ if (part === "")
35
+ return 0;
36
+ const groups = part.split(":");
37
+ let total = 0;
38
+ for (const group of groups) {
39
+ if (/^[0-9a-f]{1,4}$/i.test(group))
40
+ total++;
41
+ else if (validIpv4(group))
42
+ total += 2;
43
+ else
44
+ return undefined;
45
+ }
46
+ return total;
47
+ };
48
+ const left = count(halves[0] ?? "");
49
+ const right = count(halves[1] ?? "");
50
+ return (left !== undefined &&
51
+ right !== undefined &&
52
+ (halves.length === 2 ? left + right < 8 : left === 8));
53
+ }
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@sandbox-kit/sandbox",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "one pluggable sdk for all your sandbox providers",
5
+ "keywords": [
6
+ "sandbox-kit",
7
+ "sandbox",
8
+ "sdk"
9
+ ],
5
10
  "license": "MIT",
6
11
  "type": "module",
7
12
  "packageManager": "npm@11.19.0",
@@ -54,11 +59,12 @@
54
59
  "dependencies": {
55
60
  "@bufbuild/protobuf": "2.16.0",
56
61
  "@bufbuild/protovalidate": "1.3.0",
57
- "@sandbox-kit/contracts": "0.1.0"
62
+ "@sandbox-kit/contracts": "0.1.2"
58
63
  },
59
64
  "scripts": {
65
+ "clean": "rm -rf dist",
60
66
  "build": "tsc -p tsconfig.build.json",
61
- "prepublishOnly": "npm run build",
67
+ "prepublishOnly": "npm run clean && npm run build",
62
68
  "test": "vitest run"
63
69
  },
64
70
  "devDependencies": {