@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.
- package/README.md +110 -4
- package/dist/crypto.d.ts +133 -0
- package/dist/crypto.js +418 -0
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -2
- package/dist/fetch.d.ts +2 -0
- package/dist/fetch.js +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +2 -0
- package/dist/internal/base64.js +41 -0
- package/dist/internal/invocation.js +15 -0
- package/dist/internal/job-config.js +143 -0
- package/dist/internal/job-runtime.js +90 -0
- package/dist/internal/jobs-api.js +58 -0
- package/dist/internal/request.js +14 -2
- package/dist/internal/trigger-runtime.js +7 -0
- package/dist/internal/utf8.js +55 -0
- package/dist/internal/validation.js +8 -0
- package/dist/invocation.d.ts +14 -1
- package/dist/jobs.d.ts +95 -0
- package/dist/jobs.js +15 -0
- package/dist/request.d.ts +4 -0
- package/dist/response.js +1 -15
- package/dist/router.js +3 -0
- package/dist/script.d.ts +6 -0
- package/dist/script.js +6 -0
- package/dist/secrets.d.ts +8 -0
- package/dist/secrets.js +17 -0
- package/dist/state.js +2 -19
- package/dist/trigger.d.ts +8 -0
- package/docs/en/api-reference.md +775 -27
- package/docs/en/usage-guide.md +253 -4
- package/package.json +1 -1
package/dist/secrets.js
ADDED
|
@@ -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 (
|
|
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. */
|