@byok-sdk/core 0.27.0-rc.2 → 0.28.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/dist/errors.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +121 -1
- package/dist/index.js.map +1 -1
- package/dist/routine-schedule.d.ts +49 -0
- package/package.json +1 -1
package/dist/errors.d.ts
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* - the five `storage_*` codes (§12.7.7, see `quota.ts`)
|
|
30
30
|
*/
|
|
31
31
|
export declare const CORE_ERROR_CODES: {
|
|
32
|
+
readonly routine_schedule_invalid: 'routine_schedule_invalid';
|
|
32
33
|
readonly retention_input_invalid: 'retention_input_invalid';
|
|
33
34
|
readonly retention_collect_failed: 'retention_collect_failed';
|
|
34
35
|
readonly tenant_id_invalid: 'tenant_id_invalid';
|
package/dist/index.d.ts
CHANGED
|
@@ -56,3 +56,4 @@ export type { QuotaCollectExpiredInput } from './quota';
|
|
|
56
56
|
export type { ObjectCollectExpiredInput } from './blob';
|
|
57
57
|
export { InMemoryStorageLedger } from './in-memory/storage-ledger';
|
|
58
58
|
export type { InMemoryObjectBytes } from './in-memory/blob';
|
|
59
|
+
export * from './routine-schedule';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
// src/errors.ts
|
|
4
4
|
var CORE_ERROR_CODES = {
|
|
5
|
+
routine_schedule_invalid: "routine_schedule_invalid",
|
|
5
6
|
retention_input_invalid: "retention_input_invalid",
|
|
6
7
|
retention_collect_failed: "retention_collect_failed",
|
|
7
8
|
// identity + content addressing
|
|
@@ -3037,6 +3038,125 @@ function createInMemoryCoreCompositionWithClock(objectBytes) {
|
|
|
3037
3038
|
return { stores: createInMemoryCoreStores({ clock, objectBytes }).stores, clock };
|
|
3038
3039
|
}
|
|
3039
3040
|
|
|
3040
|
-
|
|
3041
|
+
// src/routine-schedule.ts
|
|
3042
|
+
var ROUTINE_DAYS_OF_WEEK = Object.freeze(["mon", "tue", "wed", "thu", "fri", "sat", "sun"]);
|
|
3043
|
+
var ROUTINE_HORIZON_MS = 368 * 864e5;
|
|
3044
|
+
var ROUTINE_MIN_NOW = Date.UTC(2e3, 0, 1);
|
|
3045
|
+
var ROUTINE_MAX_NOW = Date.UTC(2200, 0, 1);
|
|
3046
|
+
var KEYS = /* @__PURE__ */ new Set(["minute", "hour", "daysOfWeek", "dayOfMonth", "month", "tz"]);
|
|
3047
|
+
var COMMON_YEAR_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
3048
|
+
var TZ_NAME = /^[A-Za-z][A-Za-z0-9_+-]*(?:\/[A-Za-z0-9_+-]+)*$/;
|
|
3049
|
+
var DAY_MS = 864e5;
|
|
3050
|
+
var UTC_DAY_NAME = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
3051
|
+
var ScheduleError = class extends Error {
|
|
3052
|
+
code;
|
|
3053
|
+
constructor(code, message) {
|
|
3054
|
+
super(message);
|
|
3055
|
+
this.code = code;
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
var invalid = (message) => new ScheduleError("schedule_invalid", message);
|
|
3059
|
+
function integer(value, name, min, max) {
|
|
3060
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) throw invalid(`${name} must be an integer ${min}-${max}`);
|
|
3061
|
+
return value;
|
|
3062
|
+
}
|
|
3063
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
3064
|
+
function formatter(tz) {
|
|
3065
|
+
let f = formatters.get(tz);
|
|
3066
|
+
if (!f) {
|
|
3067
|
+
f = new Intl.DateTimeFormat("en-US", { timeZone: tz, hourCycle: "h23", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric" });
|
|
3068
|
+
if (formatters.size >= 64) formatters.delete(formatters.keys().next().value);
|
|
3069
|
+
formatters.set(tz, f);
|
|
3070
|
+
}
|
|
3071
|
+
return f;
|
|
3072
|
+
}
|
|
3073
|
+
function checkTz(tz) {
|
|
3074
|
+
if (typeof tz !== "string" || !TZ_NAME.test(tz)) throw new ScheduleError("tz_invalid", `${JSON.stringify(tz)} is not an IANA zone name`);
|
|
3075
|
+
try {
|
|
3076
|
+
formatter(tz);
|
|
3077
|
+
} catch {
|
|
3078
|
+
throw new ScheduleError("tz_invalid", `"${tz}" is not a known IANA zone`);
|
|
3079
|
+
}
|
|
3080
|
+
return tz;
|
|
3081
|
+
}
|
|
3082
|
+
function parse(schedule) {
|
|
3083
|
+
if (schedule === null || typeof schedule !== "object" || Array.isArray(schedule)) throw invalid("schedule must be an object");
|
|
3084
|
+
for (const key of Object.keys(schedule)) if (!KEYS.has(key)) throw invalid(`unknown field ${key}`);
|
|
3085
|
+
const p = { minute: integer(schedule.minute, "minute", 0, 59), hour: integer(schedule.hour, "hour", 0, 23), tz: checkTz(schedule.tz) };
|
|
3086
|
+
const s = schedule;
|
|
3087
|
+
if (s.daysOfWeek !== void 0 && s.dayOfMonth !== void 0) throw invalid("daysOfWeek and dayOfMonth cannot both appear");
|
|
3088
|
+
if (s.month !== void 0 && s.dayOfMonth === void 0) throw invalid("month needs dayOfMonth");
|
|
3089
|
+
if (s.daysOfWeek !== void 0) {
|
|
3090
|
+
if (!Array.isArray(s.daysOfWeek) || s.daysOfWeek.length < 1 || s.daysOfWeek.length > 7) throw invalid("daysOfWeek must list 1-7 days");
|
|
3091
|
+
for (const d of s.daysOfWeek) if (!ROUTINE_DAYS_OF_WEEK.includes(d)) throw invalid(`unknown day ${JSON.stringify(d)}`);
|
|
3092
|
+
p.days = new Set(s.daysOfWeek);
|
|
3093
|
+
}
|
|
3094
|
+
if (s.dayOfMonth !== void 0) {
|
|
3095
|
+
p.dayOfMonth = integer(s.dayOfMonth, "dayOfMonth", 1, 31);
|
|
3096
|
+
if (s.month !== void 0) {
|
|
3097
|
+
p.month = integer(s.month, "month", 1, 12);
|
|
3098
|
+
if (p.month === 2 && p.dayOfMonth === 29) {
|
|
3099
|
+
throw new ScheduleError("schedule_beyond_horizon", "February 29 exists only in leap years; the next one can be up to 8 years away, beyond the 368-day horizon");
|
|
3100
|
+
}
|
|
3101
|
+
if (p.dayOfMonth > COMMON_YEAR_DAYS[p.month - 1]) {
|
|
3102
|
+
throw new ScheduleError("schedule_unreachable", `month ${p.month} has no day ${p.dayOfMonth}`);
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
return p;
|
|
3107
|
+
}
|
|
3108
|
+
function checkRoutineSchedule(schedule) {
|
|
3109
|
+
try {
|
|
3110
|
+
parse(schedule);
|
|
3111
|
+
return { ok: true };
|
|
3112
|
+
} catch (e) {
|
|
3113
|
+
if (e instanceof ScheduleError) return { ok: false, code: e.code, message: e.message };
|
|
3114
|
+
throw e;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
function localAsUtc(tz, instant) {
|
|
3118
|
+
const p = {};
|
|
3119
|
+
for (const part of formatter(tz).formatToParts(instant)) if (part.type !== "literal") p[part.type] = Number(part.value);
|
|
3120
|
+
return Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second);
|
|
3121
|
+
}
|
|
3122
|
+
var offsetAt = (tz, instant) => localAsUtc(tz, instant) - Math.floor(instant / 1e3) * 1e3;
|
|
3123
|
+
function resolve(tz, local) {
|
|
3124
|
+
const before = offsetAt(tz, local - DAY_MS);
|
|
3125
|
+
const offsets = /* @__PURE__ */ new Set([before, offsetAt(tz, local), offsetAt(tz, local + DAY_MS)]);
|
|
3126
|
+
const valid = [...offsets].map((o) => local - o).filter((i) => offsetAt(tz, i) === local - i);
|
|
3127
|
+
return valid.length ? { instant: Math.min(...valid), shifted: false } : { instant: local - before, shifted: true };
|
|
3128
|
+
}
|
|
3129
|
+
function matchesDate(p, y, m, d) {
|
|
3130
|
+
if (p.days) return p.days.has(UTC_DAY_NAME[new Date(Date.UTC(y, m - 1, d)).getUTCDay()]);
|
|
3131
|
+
if (p.dayOfMonth !== void 0) return d === p.dayOfMonth && (p.month === void 0 || m === p.month);
|
|
3132
|
+
return true;
|
|
3133
|
+
}
|
|
3134
|
+
function nextRoutineOccurrence(schedule, now) {
|
|
3135
|
+
if (!Number.isSafeInteger(now) || now < ROUTINE_MIN_NOW || now >= ROUTINE_MAX_NOW) {
|
|
3136
|
+
throw new RangeError("now must be a safe integer epoch ms in [2000-01-01, 2200-01-01)");
|
|
3137
|
+
}
|
|
3138
|
+
let p;
|
|
3139
|
+
try {
|
|
3140
|
+
p = parse(schedule);
|
|
3141
|
+
} catch (error) {
|
|
3142
|
+
if (error instanceof ScheduleError) throw new ByokCoreError("routine_schedule_invalid", error.message);
|
|
3143
|
+
throw error;
|
|
3144
|
+
}
|
|
3145
|
+
const start = localAsUtc(p.tz, now);
|
|
3146
|
+
const day0 = Date.UTC(new Date(start).getUTCFullYear(), new Date(start).getUTCMonth(), new Date(start).getUTCDate());
|
|
3147
|
+
let best = Infinity;
|
|
3148
|
+
for (let k = -1; k <= 368; k += 1) {
|
|
3149
|
+
const day = new Date(day0 + k * DAY_MS);
|
|
3150
|
+
const y = day.getUTCFullYear(), m = day.getUTCMonth() + 1, d = day.getUTCDate();
|
|
3151
|
+
if (!matchesDate(p, y, m, d)) continue;
|
|
3152
|
+
const { instant, shifted } = resolve(p.tz, Date.UTC(y, m - 1, d, p.hour, p.minute));
|
|
3153
|
+
if (instant <= now) continue;
|
|
3154
|
+
best = Math.min(best, instant);
|
|
3155
|
+
if (!shifted) break;
|
|
3156
|
+
}
|
|
3157
|
+
return best - now <= ROUTINE_HORIZON_MS ? best : null;
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
export { AGENT_MEMORY_INTENT_DIGEST_VERSION, BOARD_STATUSES, BOARD_TRANSITIONS, ByokCoreError, CANONICAL_TIMESTAMP_PATTERN, CAPABILITY_DECLARATION_SCHEMA_ID, CAPABILITY_NAME_PATTERN, CONTENT_HASH_PATTERN, CORE_ERROR_CODES, CORE_NON_COMPOSITION_PORT_NAMES, CORE_PORT_INTERFACES, CORE_PORT_METHODS, CORE_STORE_NAMES, CapabilityDeclarationSchema, CollectExpiredFailure, CoreConflictError, DEVICE_ASSERTION_ALGORITHMS, DEVICE_ASSERTION_AUDIENCE_MAX_BYTES, DEVICE_ASSERTION_DEFAULT_TTL_MS, DEVICE_ASSERTION_DOMAIN_PREFIX, DEVICE_ASSERTION_MAX_TTL_MS, DEVICE_ASSERTION_SCHEMA_ID, DEVICE_ASSERTION_VERSION, DEVICE_PROOF_ALGORITHMS, DEVICE_PROOF_DOMAIN_PREFIX, DEVICE_PROOF_HEADER, DEVICE_PROOF_SCHEMA_ID, DEVICE_PROOF_VERSION, DeviceAssertionClaimsSchema, DeviceAssertionEnvelopeV1Schema, DeviceProofEnvelopeV1Schema, DeviceProofProtectedClaimsSchema, IN_MEMORY_CLOCK_EPOCH, InMemoryBoardStore, InMemoryDeviceAssertionReplayAuthority, InMemoryMailboxStore, InMemoryObjectStore, InMemoryPresenceStore, InMemoryQuotaStore, InMemorySkillPackStore, InMemoryStorageLedger, InMemoryTruthStore, MAILBOX_MESSAGE_STATES, NONCE_SIGNING_DOMAIN, OBJECT_KEY_PREFIX_PATTERN, OBJECT_STATES, OBJECT_STATE_TRANSITIONS, PRESENCE_LEVELS, PRINCIPAL_KINDS, PROVIDER_PROVISIONING_MAX_TTL_MS, PROVIDER_PROVISIONING_OPERATIONS, PROVIDER_PROVISIONING_REQUEST_VERSION, PROVIDER_PROVISIONING_SECRET_OPERATIONS, PROVIDER_SECRET_HPKE_INFO, PROVIDER_SECRET_HPKE_SUITE, PROVIDER_SECRET_MAX_BYTES, PROVIDER_SECRET_MAX_PADDED_BYTES, PROVIDER_SECRET_PAD_BLOCK_BYTES, ProviderProvisioningConfigV1Schema, ProviderProvisioningExpectedProfileSchema, ProviderProvisioningHeaderV1Schema, ProviderProvisioningIdentityRevisionSchema, ProviderProvisioningRequestV1Schema, ROUTINE_DAYS_OF_WEEK, ROUTINE_HORIZON_MS, ROUTINE_MAX_NOW, ROUTINE_MIN_NOW, SEALING_KEY_ID_LENGTH, SKILL_FRONTMATTER_FIELDS, SKILL_PACK_DESCRIPTION_MAX_LENGTH, SKILL_PACK_ENTRY_PATH, SKILL_PACK_FILE_MAX_BYTES, SKILL_PACK_FILE_PATH_MAX_LENGTH, SKILL_PACK_FILE_PATH_PATTERN, SKILL_PACK_FORBIDDEN_FIELDS, SKILL_PACK_MANIFEST_SCHEMA_ID, SKILL_PACK_MAX_BYTES, SKILL_PACK_MAX_FILES, SKILL_PACK_NAME_MAX_LENGTH, SKILL_PACK_NAME_PATTERN, SKILL_PACK_REJECTIONS, SKILL_PACK_VERSION_PATTERN, STORAGE_ERROR_CODES, STORAGE_ERROR_HTTP_STATUS, STORAGE_RESERVATION_STATES, STORAGE_WRITE_KINDS, STORAGE_WRITE_POSTURES, SealedProviderSecretV1Schema, SealingKeyClaimV1Schema, SealingKeyIdSchema, SealingPublicJwkSchema, SkillPackFileSchema, SkillPackManifestSchema, TASK_ASSERTION_AGENT_REF_MAX_BYTES, TASK_ASSERTION_DOMAIN_PREFIX, TASK_ASSERTION_SCHEMA_ID, TASK_ASSERTION_TOOLSET_ID_MAX_LENGTH, TASK_ASSERTION_VERSION, TENANT_ID_MAX_LENGTH, TENANT_KEY_SEPARATOR, TRUTH_RECORD_KINDS, TaskAssertionAgentRefSchema, TaskAssertionClaimsSchema, TaskAssertionEnvelopeV1Schema, agentMemoryIntentOperationDigest, assertCanonicalTimestamp, assertCapability, assertCollectExpiredInput, assertProviderProvisioningConfigDigest, authenticateDeviceAssertion, authenticateTaskAssertion, canonicalizeJson, canonicalizeJsonBytes, checkRoutineSchedule, checkSkillPackEntry, checkSkillPackFileContent, checkSkillPackManifest, contentHash, createInMemoryCoreCompositionWithClock, createInMemoryCoreStores, createMutableClock, deriveSealingKeyId, deviceAssertionCanonicalClaims, deviceAssertionCanonicalJson, deviceAssertionSigningInput, deviceProofCanonicalClaims, deviceProofCanonicalJson, deviceProofSigningInput, hasCapability, isCanonicalTimestamp, isContentHash, isControlPlanePrincipal, isCoreConflictError, isCoreError, isDevicePrincipal, isLegalBoardTransition, isLegalObjectTransition, isSkillPackPathSafe, isTenantId, nextRoutineOccurrence, nonceSigningBytes, objectKeyPrefix, openProviderProvisioningSecret, parseCapabilityDeclaration, parseDeviceAssertionEnvelope, parseDeviceProofEnvelope, parseProviderProvisioningRequest, parseSkillFrontmatter, parseSkillPackManifest, parseTaskAssertionEnvelope, principalTenant, providerProvisioningConfigDigest, providerProvisioningRequestDigest, providerSecretAadBytes, sealProviderProvisioningRequest, sealingKeyClaimCanonicalBytes, skillPackContentHashInput, taskAssertionCanonicalClaims, taskAssertionCanonicalJson, taskAssertionSigningInput, tenantId, tenantKey, tenantObjectKey, verifyDeviceAssertion, verifyTaskAssertion };
|
|
3041
3161
|
//# sourceMappingURL=index.js.map
|
|
3042
3162
|
//# sourceMappingURL=index.js.map
|