@cogover/sdk 0.7.0 → 0.9.0

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.
@@ -0,0 +1,17 @@
1
+ import { CogoverApiError } from "./errors.js";
2
+ import { callBridge } from "./internal/bridge.js";
3
+ import { requireSecretName } from "./internal/validation.js";
4
+ import { isRecord } from "./internal/values.js";
5
+ /** @internal */
6
+ export function createSecretsApi() {
7
+ return Object.freeze({
8
+ async get(name) {
9
+ const secretName = requireSecretName(name, "secrets.get() name");
10
+ const secret = await callBridge("secrets.get", { name: secretName });
11
+ if (!isRecord(secret) || typeof secret.value !== "string") {
12
+ throw new CogoverApiError("INVALID_BRIDGE_RESPONSE", `Secret '${secretName}' has no value`);
13
+ }
14
+ return secret.value;
15
+ },
16
+ });
17
+ }
package/dist/state.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { callBridge } from "./internal/bridge.js";
2
+ import { utf8ByteLength } from "./internal/utf8.js";
2
3
  import { ValidationError } from "./errors.js";
3
4
  const NAME = /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/;
4
5
  const MAX_NAMESPACE_LENGTH = 128;
@@ -51,7 +52,7 @@ function validateValue(value) {
51
52
  }
52
53
  if (serialized === undefined)
53
54
  throw new ValidationError("state value must be JSON serializable");
54
- if (utf8Bytes(serialized) > MAX_VALUE_BYTES) {
55
+ if (utf8ByteLength(serialized) > MAX_VALUE_BYTES) {
55
56
  throw new ValidationError(`state value must not exceed ${MAX_VALUE_BYTES} UTF-8 bytes`);
56
57
  }
57
58
  }
@@ -71,21 +72,3 @@ export function optionalInteger(value, label, minimum, maximum) {
71
72
  }
72
73
  return value;
73
74
  }
74
- function utf8Bytes(value) {
75
- let bytes = 0;
76
- for (let index = 0; index < value.length; index++) {
77
- const code = value.charCodeAt(index);
78
- if (code < 0x80)
79
- bytes++;
80
- else if (code < 0x800)
81
- bytes += 2;
82
- else if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length
83
- && value.charCodeAt(index + 1) >= 0xdc00 && value.charCodeAt(index + 1) <= 0xdfff) {
84
- bytes += 4;
85
- index++;
86
- }
87
- else
88
- bytes += 3;
89
- }
90
- return bytes;
91
- }
package/dist/trigger.d.ts CHANGED
@@ -1,4 +1,7 @@
1
+ import type { CryptoApi } from "./crypto.js";
1
2
  import type { DataApi } from "./data.js";
3
+ import type { JobsApi } from "./jobs.js";
4
+ import type { SecretsApi } from "./secrets.js";
2
5
  import type { InvocationContext } from "./invocation.js";
3
6
  import type { ScriptLogger } from "./logger.js";
4
7
  import type { PushApi } from "./push.js";
@@ -117,6 +120,11 @@ export interface TriggerContext<TObject extends string = string, TOperation exte
117
120
  readonly log: ScriptLogger;
118
121
  /** Refused with `TRIGGER_READ_ONLY` in a before-change trigger. */
119
122
  readonly push: PushApi<TSchema>;
123
+ /** Available in after-change triggers; a before-change trigger is refused with `PermissionDeniedError`. */
124
+ readonly jobs: JobsApi;
125
+ /** Available in after-change triggers; a before-change trigger is refused with `PermissionDeniedError`. */
126
+ readonly secrets: SecretsApi;
127
+ readonly crypto: CryptoApi;
120
128
  }
121
129
  export type TriggerHandler<TObject extends string = string, TOperation extends TriggerOperation = TriggerOperation, TSchema extends object = EffectiveWorkspaceObjects> = (context: TriggerContext<TObject, TOperation, TSchema>) => void | Promise<void>;
122
130
  /** Declares a record trigger. Add the result to the project's `triggers` export. */