@xenosystem/agent-cli 0.5.179 → 0.5.181
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/cli.js +1 -1
- package/dist/index.js +2463 -2461
- package/dist/metafile-esm.json +1 -1
- package/dist/sdk-build-identity.json +12 -12
- package/ownership/ownership-policy.json +99 -20
- package/package.json +94 -94
- package/node_modules/@xeno-corporation/account/LICENSE +0 -39
- package/node_modules/@xeno-corporation/account/README.md +0 -266
- package/node_modules/@xeno-corporation/account/dist/chunk-FELZILY4.mjs +0 -60
- package/node_modules/@xeno-corporation/account/dist/chunk-FELZILY4.mjs.map +0 -1
- package/node_modules/@xeno-corporation/account/dist/client-CVtf6u7F.d.mts +0 -2346
- package/node_modules/@xeno-corporation/account/dist/client-CVtf6u7F.d.ts +0 -2346
- package/node_modules/@xeno-corporation/account/dist/index.d.mts +0 -110
- package/node_modules/@xeno-corporation/account/dist/index.d.ts +0 -110
- package/node_modules/@xeno-corporation/account/dist/index.js +0 -4115
- package/node_modules/@xeno-corporation/account/dist/index.js.map +0 -1
- package/node_modules/@xeno-corporation/account/dist/index.mjs +0 -3967
- package/node_modules/@xeno-corporation/account/dist/index.mjs.map +0 -1
- package/node_modules/@xeno-corporation/account/dist/node.d.mts +0 -109
- package/node_modules/@xeno-corporation/account/dist/node.d.ts +0 -109
- package/node_modules/@xeno-corporation/account/dist/node.js +0 -1448
- package/node_modules/@xeno-corporation/account/dist/node.js.map +0 -1
- package/node_modules/@xeno-corporation/account/dist/node.mjs +0 -1374
- package/node_modules/@xeno-corporation/account/dist/node.mjs.map +0 -1
- package/node_modules/@xeno-corporation/account/package.json +0 -62
- package/node_modules/zod/LICENSE +0 -21
- package/node_modules/zod/README.md +0 -218
- package/node_modules/zod/compile.cjs +0 -96
- package/node_modules/zod/compile.d.cts +0 -1
- package/node_modules/zod/compile.d.ts +0 -1
- package/node_modules/zod/compile.js +0 -52
- package/node_modules/zod/index.cjs +0 -52
- package/node_modules/zod/index.d.cts +0 -3
- package/node_modules/zod/index.d.ts +0 -3
- package/node_modules/zod/index.js +0 -7
- package/node_modules/zod/locales/index.cjs +0 -36
- package/node_modules/zod/locales/index.d.cts +0 -1
- package/node_modules/zod/locales/index.d.ts +0 -1
- package/node_modules/zod/locales/index.js +0 -1
- package/node_modules/zod/locales/package.json +0 -7
- package/node_modules/zod/mini/index.cjs +0 -51
- package/node_modules/zod/mini/index.d.cts +0 -3
- package/node_modules/zod/mini/index.d.ts +0 -3
- package/node_modules/zod/mini/index.js +0 -3
- package/node_modules/zod/mini/package.json +0 -7
- package/node_modules/zod/package.json +0 -147
- package/node_modules/zod/src/compile.ts +0 -56
- package/node_modules/zod/src/index.ts +0 -7
- package/node_modules/zod/src/locales/index.ts +0 -1
- package/node_modules/zod/src/mini/index.ts +0 -3
- package/node_modules/zod/src/v3/ZodError.ts +0 -340
- package/node_modules/zod/src/v3/benchmarks/datetime.ts +0 -58
- package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +0 -80
- package/node_modules/zod/src/v3/benchmarks/index.ts +0 -59
- package/node_modules/zod/src/v3/benchmarks/ipv4.ts +0 -57
- package/node_modules/zod/src/v3/benchmarks/object.ts +0 -69
- package/node_modules/zod/src/v3/benchmarks/primitives.ts +0 -162
- package/node_modules/zod/src/v3/benchmarks/realworld.ts +0 -63
- package/node_modules/zod/src/v3/benchmarks/string.ts +0 -55
- package/node_modules/zod/src/v3/benchmarks/union.ts +0 -80
- package/node_modules/zod/src/v3/errors.ts +0 -13
- package/node_modules/zod/src/v3/external.ts +0 -6
- package/node_modules/zod/src/v3/helpers/enumUtil.ts +0 -17
- package/node_modules/zod/src/v3/helpers/errorUtil.ts +0 -8
- package/node_modules/zod/src/v3/helpers/parseUtil.ts +0 -176
- package/node_modules/zod/src/v3/helpers/partialUtil.ts +0 -34
- package/node_modules/zod/src/v3/helpers/typeAliases.ts +0 -2
- package/node_modules/zod/src/v3/helpers/util.ts +0 -224
- package/node_modules/zod/src/v3/index.ts +0 -4
- package/node_modules/zod/src/v3/locales/en.ts +0 -124
- package/node_modules/zod/src/v3/standard-schema.ts +0 -113
- package/node_modules/zod/src/v3/tests/Mocker.ts +0 -54
- package/node_modules/zod/src/v3/tests/all-errors.test.ts +0 -157
- package/node_modules/zod/src/v3/tests/anyunknown.test.ts +0 -28
- package/node_modules/zod/src/v3/tests/array.test.ts +0 -71
- package/node_modules/zod/src/v3/tests/async-parsing.test.ts +0 -388
- package/node_modules/zod/src/v3/tests/async-refinements.test.ts +0 -46
- package/node_modules/zod/src/v3/tests/base.test.ts +0 -29
- package/node_modules/zod/src/v3/tests/bigint.test.ts +0 -55
- package/node_modules/zod/src/v3/tests/branded.test.ts +0 -53
- package/node_modules/zod/src/v3/tests/catch.test.ts +0 -220
- package/node_modules/zod/src/v3/tests/coerce.test.ts +0 -133
- package/node_modules/zod/src/v3/tests/complex.test.ts +0 -70
- package/node_modules/zod/src/v3/tests/custom.test.ts +0 -31
- package/node_modules/zod/src/v3/tests/date.test.ts +0 -32
- package/node_modules/zod/src/v3/tests/deepmasking.test.ts +0 -186
- package/node_modules/zod/src/v3/tests/default.test.ts +0 -112
- package/node_modules/zod/src/v3/tests/description.test.ts +0 -33
- package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +0 -315
- package/node_modules/zod/src/v3/tests/enum.test.ts +0 -80
- package/node_modules/zod/src/v3/tests/error.test.ts +0 -586
- package/node_modules/zod/src/v3/tests/firstparty.test.ts +0 -87
- package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +0 -21
- package/node_modules/zod/src/v3/tests/function.test.ts +0 -261
- package/node_modules/zod/src/v3/tests/generics.test.ts +0 -48
- package/node_modules/zod/src/v3/tests/instanceof.test.ts +0 -37
- package/node_modules/zod/src/v3/tests/intersection.test.ts +0 -128
- package/node_modules/zod/src/v3/tests/language-server.source.ts +0 -76
- package/node_modules/zod/src/v3/tests/language-server.test.ts +0 -206
- package/node_modules/zod/src/v3/tests/literal.test.ts +0 -36
- package/node_modules/zod/src/v3/tests/map.test.ts +0 -110
- package/node_modules/zod/src/v3/tests/masking.test.ts +0 -4
- package/node_modules/zod/src/v3/tests/mocker.test.ts +0 -19
- package/node_modules/zod/src/v3/tests/nan.test.ts +0 -24
- package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +0 -87
- package/node_modules/zod/src/v3/tests/nullable.test.ts +0 -42
- package/node_modules/zod/src/v3/tests/number.test.ts +0 -176
- package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +0 -29
- package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +0 -29
- package/node_modules/zod/src/v3/tests/object.test.ts +0 -431
- package/node_modules/zod/src/v3/tests/optional.test.ts +0 -42
- package/node_modules/zod/src/v3/tests/parseUtil.test.ts +0 -23
- package/node_modules/zod/src/v3/tests/parser.test.ts +0 -41
- package/node_modules/zod/src/v3/tests/partials.test.ts +0 -243
- package/node_modules/zod/src/v3/tests/pickomit.test.ts +0 -111
- package/node_modules/zod/src/v3/tests/pipeline.test.ts +0 -29
- package/node_modules/zod/src/v3/tests/preprocess.test.ts +0 -186
- package/node_modules/zod/src/v3/tests/primitive.test.ts +0 -440
- package/node_modules/zod/src/v3/tests/promise.test.ts +0 -90
- package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -114
- package/node_modules/zod/src/v3/tests/record.test.ts +0 -171
- package/node_modules/zod/src/v3/tests/recursive.test.ts +0 -197
- package/node_modules/zod/src/v3/tests/refine.test.ts +0 -313
- package/node_modules/zod/src/v3/tests/safeparse.test.ts +0 -27
- package/node_modules/zod/src/v3/tests/set.test.ts +0 -142
- package/node_modules/zod/src/v3/tests/standard-schema.test.ts +0 -83
- package/node_modules/zod/src/v3/tests/string.test.ts +0 -922
- package/node_modules/zod/src/v3/tests/transformer.test.ts +0 -233
- package/node_modules/zod/src/v3/tests/tuple.test.ts +0 -90
- package/node_modules/zod/src/v3/tests/unions.test.ts +0 -57
- package/node_modules/zod/src/v3/tests/validations.test.ts +0 -133
- package/node_modules/zod/src/v3/tests/void.test.ts +0 -15
- package/node_modules/zod/src/v3/types.ts +0 -5138
- package/node_modules/zod/src/v4/classic/checks.ts +0 -33
- package/node_modules/zod/src/v4/classic/coerce.ts +0 -27
- package/node_modules/zod/src/v4/classic/compat.ts +0 -78
- package/node_modules/zod/src/v4/classic/deep-partial.ts +0 -76
- package/node_modules/zod/src/v4/classic/errors.ts +0 -97
- package/node_modules/zod/src/v4/classic/external.ts +0 -57
- package/node_modules/zod/src/v4/classic/from-json-schema.ts +0 -944
- package/node_modules/zod/src/v4/classic/in-out.ts +0 -45
- package/node_modules/zod/src/v4/classic/index.ts +0 -5
- package/node_modules/zod/src/v4/classic/iso.ts +0 -20
- package/node_modules/zod/src/v4/classic/parse.ts +0 -88
- package/node_modules/zod/src/v4/classic/schemas.ts +0 -2937
- package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +0 -26
- package/node_modules/zod/src/v4/classic/tests/apply.test.ts +0 -86
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +0 -291
- package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +0 -402
- package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +0 -381
- package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +0 -68
- package/node_modules/zod/src/v4/classic/tests/base.test.ts +0 -7
- package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +0 -89
- package/node_modules/zod/src/v4/classic/tests/brand.test.ts +0 -106
- package/node_modules/zod/src/v4/classic/tests/catch.test.ts +0 -604
- package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +0 -20
- package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +0 -572
- package/node_modules/zod/src/v4/classic/tests/codec.test.ts +0 -704
- package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +0 -160
- package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +0 -374
- package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +0 -76
- package/node_modules/zod/src/v4/classic/tests/custom.test.ts +0 -40
- package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +0 -985
- package/node_modules/zod/src/v4/classic/tests/date.test.ts +0 -92
- package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +0 -316
- package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +0 -380
- package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +0 -32
- package/node_modules/zod/src/v4/classic/tests/default.test.ts +0 -455
- package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +0 -27
- package/node_modules/zod/src/v4/classic/tests/description.test.ts +0 -32
- package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +0 -221
- package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +0 -942
- package/node_modules/zod/src/v4/classic/tests/enum.test.ts +0 -305
- package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +0 -917
- package/node_modules/zod/src/v4/classic/tests/error.test.ts +0 -1108
- package/node_modules/zod/src/v4/classic/tests/file.test.ts +0 -96
- package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +0 -179
- package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +0 -26
- package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +0 -1467
- package/node_modules/zod/src/v4/classic/tests/function.test.ts +0 -391
- package/node_modules/zod/src/v4/classic/tests/generics.test.ts +0 -72
- package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +0 -32
- package/node_modules/zod/src/v4/classic/tests/hash.test.ts +0 -67
- package/node_modules/zod/src/v4/classic/tests/iban.test.ts +0 -81
- package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +0 -159
- package/node_modules/zod/src/v4/classic/tests/index.test.ts +0 -958
- package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +0 -319
- package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +0 -127
- package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +0 -334
- package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +0 -215
- package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +0 -39
- package/node_modules/zod/src/v4/classic/tests/json.test.ts +0 -109
- package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +0 -262
- package/node_modules/zod/src/v4/classic/tests/literal.test.ts +0 -128
- package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +0 -29
- package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +0 -24
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +0 -349
- package/node_modules/zod/src/v4/classic/tests/nan.test.ts +0 -21
- package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +0 -168
- package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +0 -101
- package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +0 -22
- package/node_modules/zod/src/v4/classic/tests/number.test.ts +0 -401
- package/node_modules/zod/src/v4/classic/tests/object.test.ts +0 -1006
- package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +0 -235
- package/node_modules/zod/src/v4/classic/tests/optional.test.ts +0 -366
- package/node_modules/zod/src/v4/classic/tests/partial.test.ts +0 -497
- package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +0 -211
- package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +0 -101
- package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +0 -144
- package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +0 -44
- package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +0 -351
- package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +0 -175
- package/node_modules/zod/src/v4/classic/tests/promise.test.ts +0 -81
- package/node_modules/zod/src/v4/classic/tests/properties.test.ts +0 -141
- package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +0 -23
- package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +0 -184
- package/node_modules/zod/src/v4/classic/tests/record.test.ts +0 -885
- package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +0 -707
- package/node_modules/zod/src/v4/classic/tests/redos.test.ts +0 -68
- package/node_modules/zod/src/v4/classic/tests/refine.test.ts +0 -693
- package/node_modules/zod/src/v4/classic/tests/registries.test.ts +0 -243
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +0 -196
- package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +0 -153
- package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +0 -125
- package/node_modules/zod/src/v4/classic/tests/string.test.ts +0 -1440
- package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +0 -124
- package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +0 -812
- package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +0 -438
- package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +0 -4733
- package/node_modules/zod/src/v4/classic/tests/transform.test.ts +0 -378
- package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +0 -511
- package/node_modules/zod/src/v4/classic/tests/union.test.ts +0 -310
- package/node_modules/zod/src/v4/classic/tests/url.test.ts +0 -13
- package/node_modules/zod/src/v4/classic/tests/validate.test.ts +0 -645
- package/node_modules/zod/src/v4/classic/tests/validations.test.ts +0 -283
- package/node_modules/zod/src/v4/classic/tests/void.test.ts +0 -12
- package/node_modules/zod/src/v4/core/api.ts +0 -1875
- package/node_modules/zod/src/v4/core/checks.ts +0 -1266
- package/node_modules/zod/src/v4/core/compile.ts +0 -2322
- package/node_modules/zod/src/v4/core/core.ts +0 -230
- package/node_modules/zod/src/v4/core/doc.ts +0 -52
- package/node_modules/zod/src/v4/core/errors.ts +0 -543
- package/node_modules/zod/src/v4/core/index.ts +0 -19
- package/node_modules/zod/src/v4/core/json-schema-generator.ts +0 -131
- package/node_modules/zod/src/v4/core/json-schema-processors.ts +0 -934
- package/node_modules/zod/src/v4/core/json-schema.ts +0 -148
- package/node_modules/zod/src/v4/core/memoizer.ts +0 -331
- package/node_modules/zod/src/v4/core/parse.ts +0 -309
- package/node_modules/zod/src/v4/core/regexes.ts +0 -217
- package/node_modules/zod/src/v4/core/registries.ts +0 -105
- package/node_modules/zod/src/v4/core/schemas.ts +0 -5226
- package/node_modules/zod/src/v4/core/standard-schema.ts +0 -159
- package/node_modules/zod/src/v4/core/tests/cached.test.ts +0 -54
- package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +0 -1004
- package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +0 -445
- package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +0 -89
- package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +0 -26
- package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +0 -34
- package/node_modules/zod/src/v4/core/tests/compile.test.ts +0 -2036
- package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +0 -140
- package/node_modules/zod/src/v4/core/tests/extend.test.ts +0 -59
- package/node_modules/zod/src/v4/core/tests/index.test.ts +0 -46
- package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +0 -124
- package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +0 -214
- package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +0 -22
- package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +0 -180
- package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +0 -72
- package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +0 -379
- package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +0 -163
- package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +0 -46
- package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +0 -42
- package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +0 -128
- package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +0 -85
- package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +0 -69
- package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +0 -69
- package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +0 -105
- package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +0 -46
- package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +0 -125
- package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +0 -45
- package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +0 -51
- package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +0 -133
- package/node_modules/zod/src/v4/core/to-json-schema.ts +0 -857
- package/node_modules/zod/src/v4/core/util.ts +0 -1293
- package/node_modules/zod/src/v4/core/versions.ts +0 -5
- package/node_modules/zod/src/v4/core/visit.ts +0 -193
- package/node_modules/zod/src/v4/core/zsf.ts +0 -323
- package/node_modules/zod/src/v4/index.ts +0 -4
- package/node_modules/zod/src/v4/locales/ar.ts +0 -120
- package/node_modules/zod/src/v4/locales/az.ts +0 -116
- package/node_modules/zod/src/v4/locales/be.ts +0 -188
- package/node_modules/zod/src/v4/locales/bg.ts +0 -133
- package/node_modules/zod/src/v4/locales/bn.ts +0 -123
- package/node_modules/zod/src/v4/locales/ca.ts +0 -121
- package/node_modules/zod/src/v4/locales/ckb.ts +0 -140
- package/node_modules/zod/src/v4/locales/cs.ts +0 -123
- package/node_modules/zod/src/v4/locales/da.ts +0 -128
- package/node_modules/zod/src/v4/locales/de.ts +0 -121
- package/node_modules/zod/src/v4/locales/el.ts +0 -124
- package/node_modules/zod/src/v4/locales/en.ts +0 -136
- package/node_modules/zod/src/v4/locales/eo.ts +0 -123
- package/node_modules/zod/src/v4/locales/es.ts +0 -145
- package/node_modules/zod/src/v4/locales/fa.ts +0 -131
- package/node_modules/zod/src/v4/locales/fi.ts +0 -126
- package/node_modules/zod/src/v4/locales/fr-CA.ts +0 -121
- package/node_modules/zod/src/v4/locales/fr.ts +0 -139
- package/node_modules/zod/src/v4/locales/gu.ts +0 -123
- package/node_modules/zod/src/v4/locales/he.ts +0 -253
- package/node_modules/zod/src/v4/locales/hi.ts +0 -126
- package/node_modules/zod/src/v4/locales/hr.ts +0 -135
- package/node_modules/zod/src/v4/locales/hu.ts +0 -122
- package/node_modules/zod/src/v4/locales/hy.ts +0 -175
- package/node_modules/zod/src/v4/locales/id.ts +0 -120
- package/node_modules/zod/src/v4/locales/index.ts +0 -63
- package/node_modules/zod/src/v4/locales/is.ts +0 -124
- package/node_modules/zod/src/v4/locales/it.ts +0 -121
- package/node_modules/zod/src/v4/locales/ja.ts +0 -119
- package/node_modules/zod/src/v4/locales/ka.ts +0 -128
- package/node_modules/zod/src/v4/locales/kh.ts +0 -7
- package/node_modules/zod/src/v4/locales/km.ts +0 -124
- package/node_modules/zod/src/v4/locales/kn.ts +0 -126
- package/node_modules/zod/src/v4/locales/ko.ts +0 -126
- package/node_modules/zod/src/v4/locales/lt.ts +0 -243
- package/node_modules/zod/src/v4/locales/mk.ts +0 -123
- package/node_modules/zod/src/v4/locales/ms.ts +0 -120
- package/node_modules/zod/src/v4/locales/ne.ts +0 -128
- package/node_modules/zod/src/v4/locales/nl.ts +0 -126
- package/node_modules/zod/src/v4/locales/nn.ts +0 -121
- package/node_modules/zod/src/v4/locales/no.ts +0 -121
- package/node_modules/zod/src/v4/locales/ota.ts +0 -122
- package/node_modules/zod/src/v4/locales/pl.ts +0 -123
- package/node_modules/zod/src/v4/locales/ps.ts +0 -131
- package/node_modules/zod/src/v4/locales/pt-BR.ts +0 -161
- package/node_modules/zod/src/v4/locales/pt.ts +0 -159
- package/node_modules/zod/src/v4/locales/ro.ts +0 -132
- package/node_modules/zod/src/v4/locales/ru.ts +0 -188
- package/node_modules/zod/src/v4/locales/sk.ts +0 -123
- package/node_modules/zod/src/v4/locales/sl.ts +0 -123
- package/node_modules/zod/src/v4/locales/sv.ts +0 -124
- package/node_modules/zod/src/v4/locales/ta.ts +0 -123
- package/node_modules/zod/src/v4/locales/tg.ts +0 -135
- package/node_modules/zod/src/v4/locales/th.ts +0 -124
- package/node_modules/zod/src/v4/locales/tk.ts +0 -113
- package/node_modules/zod/src/v4/locales/tr.ts +0 -116
- package/node_modules/zod/src/v4/locales/ua.ts +0 -7
- package/node_modules/zod/src/v4/locales/uk.ts +0 -122
- package/node_modules/zod/src/v4/locales/ur.ts +0 -124
- package/node_modules/zod/src/v4/locales/uz.ts +0 -120
- package/node_modules/zod/src/v4/locales/vi.ts +0 -122
- package/node_modules/zod/src/v4/locales/yo.ts +0 -129
- package/node_modules/zod/src/v4/locales/zh-CN.ts +0 -121
- package/node_modules/zod/src/v4/locales/zh-TW.ts +0 -120
- package/node_modules/zod/src/v4/mini/checks.ts +0 -33
- package/node_modules/zod/src/v4/mini/coerce.ts +0 -27
- package/node_modules/zod/src/v4/mini/deep-partial.ts +0 -73
- package/node_modules/zod/src/v4/mini/external.ts +0 -52
- package/node_modules/zod/src/v4/mini/in-out.ts +0 -45
- package/node_modules/zod/src/v4/mini/index.ts +0 -3
- package/node_modules/zod/src/v4/mini/iso.ts +0 -66
- package/node_modules/zod/src/v4/mini/parse.ts +0 -16
- package/node_modules/zod/src/v4/mini/schemas.ts +0 -2051
- package/node_modules/zod/src/v4/mini/tests/apply.test.ts +0 -57
- package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +0 -190
- package/node_modules/zod/src/v4/mini/tests/brand.test.ts +0 -94
- package/node_modules/zod/src/v4/mini/tests/checks.test.ts +0 -158
- package/node_modules/zod/src/v4/mini/tests/codec.test.ts +0 -582
- package/node_modules/zod/src/v4/mini/tests/computed.test.ts +0 -30
- package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +0 -84
- package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +0 -54
- package/node_modules/zod/src/v4/mini/tests/error.test.ts +0 -41
- package/node_modules/zod/src/v4/mini/tests/functions.test.ts +0 -14
- package/node_modules/zod/src/v4/mini/tests/index.test.ts +0 -1146
- package/node_modules/zod/src/v4/mini/tests/number.test.ts +0 -109
- package/node_modules/zod/src/v4/mini/tests/object.test.ts +0 -292
- package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +0 -43
- package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +0 -341
- package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +0 -50
- package/node_modules/zod/src/v4/mini/tests/string.test.ts +0 -396
- package/node_modules/zod/src/v4-mini/index.ts +0 -3
- package/node_modules/zod/v3/ZodError.cjs +0 -167
- package/node_modules/zod/v3/ZodError.d.cts +0 -164
- package/node_modules/zod/v3/ZodError.d.ts +0 -164
- package/node_modules/zod/v3/ZodError.js +0 -143
- package/node_modules/zod/v3/errors.cjs +0 -36
- package/node_modules/zod/v3/errors.d.cts +0 -5
- package/node_modules/zod/v3/errors.d.ts +0 -5
- package/node_modules/zod/v3/errors.js +0 -9
- package/node_modules/zod/v3/external.cjs +0 -41
- package/node_modules/zod/v3/external.d.cts +0 -6
- package/node_modules/zod/v3/external.d.ts +0 -6
- package/node_modules/zod/v3/external.js +0 -6
- package/node_modules/zod/v3/helpers/enumUtil.cjs +0 -21
- package/node_modules/zod/v3/helpers/enumUtil.d.cts +0 -8
- package/node_modules/zod/v3/helpers/enumUtil.d.ts +0 -8
- package/node_modules/zod/v3/helpers/enumUtil.js +0 -1
- package/node_modules/zod/v3/helpers/errorUtil.cjs +0 -28
- package/node_modules/zod/v3/helpers/errorUtil.d.cts +0 -9
- package/node_modules/zod/v3/helpers/errorUtil.d.ts +0 -9
- package/node_modules/zod/v3/helpers/errorUtil.js +0 -6
- package/node_modules/zod/v3/helpers/parseUtil.cjs +0 -143
- package/node_modules/zod/v3/helpers/parseUtil.d.cts +0 -78
- package/node_modules/zod/v3/helpers/parseUtil.d.ts +0 -78
- package/node_modules/zod/v3/helpers/parseUtil.js +0 -109
- package/node_modules/zod/v3/helpers/partialUtil.cjs +0 -21
- package/node_modules/zod/v3/helpers/partialUtil.d.cts +0 -8
- package/node_modules/zod/v3/helpers/partialUtil.d.ts +0 -8
- package/node_modules/zod/v3/helpers/partialUtil.js +0 -1
- package/node_modules/zod/v3/helpers/typeAliases.cjs +0 -21
- package/node_modules/zod/v3/helpers/typeAliases.d.cts +0 -2
- package/node_modules/zod/v3/helpers/typeAliases.d.ts +0 -2
- package/node_modules/zod/v3/helpers/typeAliases.js +0 -1
- package/node_modules/zod/v3/helpers/util.cjs +0 -156
- package/node_modules/zod/v3/helpers/util.d.cts +0 -85
- package/node_modules/zod/v3/helpers/util.d.ts +0 -85
- package/node_modules/zod/v3/helpers/util.js +0 -133
- package/node_modules/zod/v3/index.cjs +0 -52
- package/node_modules/zod/v3/index.d.cts +0 -4
- package/node_modules/zod/v3/index.d.ts +0 -4
- package/node_modules/zod/v3/index.js +0 -4
- package/node_modules/zod/v3/locales/en.cjs +0 -112
- package/node_modules/zod/v3/locales/en.d.cts +0 -3
- package/node_modules/zod/v3/locales/en.d.ts +0 -3
- package/node_modules/zod/v3/locales/en.js +0 -109
- package/node_modules/zod/v3/package.json +0 -7
- package/node_modules/zod/v3/standard-schema.cjs +0 -21
- package/node_modules/zod/v3/standard-schema.d.cts +0 -102
- package/node_modules/zod/v3/standard-schema.d.ts +0 -102
- package/node_modules/zod/v3/standard-schema.js +0 -1
- package/node_modules/zod/v3/types.cjs +0 -3798
- package/node_modules/zod/v3/types.d.cts +0 -1034
- package/node_modules/zod/v3/types.d.ts +0 -1034
- package/node_modules/zod/v3/types.js +0 -3697
- package/node_modules/zod/v4/classic/checks.cjs +0 -53
- package/node_modules/zod/v4/classic/checks.d.cts +0 -1
- package/node_modules/zod/v4/classic/checks.d.ts +0 -1
- package/node_modules/zod/v4/classic/checks.js +0 -1
- package/node_modules/zod/v4/classic/coerce.cjs +0 -66
- package/node_modules/zod/v4/classic/coerce.d.cts +0 -17
- package/node_modules/zod/v4/classic/coerce.d.ts +0 -17
- package/node_modules/zod/v4/classic/coerce.js +0 -17
- package/node_modules/zod/v4/classic/compat.cjs +0 -80
- package/node_modules/zod/v4/classic/compat.d.cts +0 -48
- package/node_modules/zod/v4/classic/compat.d.ts +0 -48
- package/node_modules/zod/v4/classic/compat.js +0 -31
- package/node_modules/zod/v4/classic/deep-partial.cjs +0 -58
- package/node_modules/zod/v4/classic/deep-partial.d.cts +0 -14
- package/node_modules/zod/v4/classic/deep-partial.d.ts +0 -14
- package/node_modules/zod/v4/classic/deep-partial.js +0 -13
- package/node_modules/zod/v4/classic/errors.cjs +0 -102
- package/node_modules/zod/v4/classic/errors.d.cts +0 -29
- package/node_modules/zod/v4/classic/errors.d.ts +0 -29
- package/node_modules/zod/v4/classic/errors.js +0 -57
- package/node_modules/zod/v4/classic/external.cjs +0 -97
- package/node_modules/zod/v4/classic/external.d.cts +0 -19
- package/node_modules/zod/v4/classic/external.d.ts +0 -19
- package/node_modules/zod/v4/classic/external.js +0 -17
- package/node_modules/zod/v4/classic/from-json-schema.cjs +0 -926
- package/node_modules/zod/v4/classic/from-json-schema.d.cts +0 -12
- package/node_modules/zod/v4/classic/from-json-schema.d.ts +0 -12
- package/node_modules/zod/v4/classic/from-json-schema.js +0 -881
- package/node_modules/zod/v4/classic/in-out.cjs +0 -82
- package/node_modules/zod/v4/classic/in-out.d.cts +0 -8
- package/node_modules/zod/v4/classic/in-out.d.ts +0 -8
- package/node_modules/zod/v4/classic/in-out.js +0 -36
- package/node_modules/zod/v4/classic/index.cjs +0 -52
- package/node_modules/zod/v4/classic/index.d.cts +0 -3
- package/node_modules/zod/v4/classic/index.d.ts +0 -3
- package/node_modules/zod/v4/classic/index.js +0 -4
- package/node_modules/zod/v4/classic/iso.cjs +0 -68
- package/node_modules/zod/v4/classic/iso.d.cts +0 -7
- package/node_modules/zod/v4/classic/iso.d.ts +0 -7
- package/node_modules/zod/v4/classic/iso.js +0 -15
- package/node_modules/zod/v4/classic/package.json +0 -7
- package/node_modules/zod/v4/classic/parse.cjs +0 -63
- package/node_modules/zod/v4/classic/parse.d.cts +0 -44
- package/node_modules/zod/v4/classic/parse.d.ts +0 -44
- package/node_modules/zod/v4/classic/parse.js +0 -16
- package/node_modules/zod/v4/classic/schemas.cjs +0 -1676
- package/node_modules/zod/v4/classic/schemas.d.cts +0 -816
- package/node_modules/zod/v4/classic/schemas.d.ts +0 -816
- package/node_modules/zod/v4/classic/schemas.js +0 -1535
- package/node_modules/zod/v4/core/api.cjs +0 -1269
- package/node_modules/zod/v4/core/api.d.cts +0 -335
- package/node_modules/zod/v4/core/api.d.ts +0 -335
- package/node_modules/zod/v4/core/api.js +0 -1107
- package/node_modules/zod/v4/core/checks.cjs +0 -561
- package/node_modules/zod/v4/core/checks.d.cts +0 -294
- package/node_modules/zod/v4/core/checks.d.ts +0 -294
- package/node_modules/zod/v4/core/checks.js +0 -516
- package/node_modules/zod/v4/core/compile.cjs +0 -1916
- package/node_modules/zod/v4/core/compile.d.cts +0 -65
- package/node_modules/zod/v4/core/compile.d.ts +0 -65
- package/node_modules/zod/v4/core/compile.js +0 -1866
- package/node_modules/zod/v4/core/core.cjs +0 -167
- package/node_modules/zod/v4/core/core.d.cts +0 -82
- package/node_modules/zod/v4/core/core.d.ts +0 -82
- package/node_modules/zod/v4/core/core.js +0 -141
- package/node_modules/zod/v4/core/doc.cjs +0 -61
- package/node_modules/zod/v4/core/doc.d.cts +0 -16
- package/node_modules/zod/v4/core/doc.d.ts +0 -16
- package/node_modules/zod/v4/core/doc.js +0 -38
- package/node_modules/zod/v4/core/errors.cjs +0 -317
- package/node_modules/zod/v4/core/errors.d.cts +0 -225
- package/node_modules/zod/v4/core/errors.d.ts +0 -225
- package/node_modules/zod/v4/core/errors.js +0 -267
- package/node_modules/zod/v4/core/index.cjs +0 -70
- package/node_modules/zod/v4/core/index.d.cts +0 -19
- package/node_modules/zod/v4/core/index.d.ts +0 -19
- package/node_modules/zod/v4/core/index.js +0 -19
- package/node_modules/zod/v4/core/json-schema-generator.cjs +0 -122
- package/node_modules/zod/v4/core/json-schema-generator.d.cts +0 -65
- package/node_modules/zod/v4/core/json-schema-generator.d.ts +0 -65
- package/node_modules/zod/v4/core/json-schema-generator.js +0 -99
- package/node_modules/zod/v4/core/json-schema-processors.cjs +0 -929
- package/node_modules/zod/v4/core/json-schema-processors.d.cts +0 -65
- package/node_modules/zod/v4/core/json-schema-processors.d.ts +0 -65
- package/node_modules/zod/v4/core/json-schema-processors.js +0 -843
- package/node_modules/zod/v4/core/json-schema.cjs +0 -21
- package/node_modules/zod/v4/core/json-schema.d.cts +0 -89
- package/node_modules/zod/v4/core/json-schema.d.ts +0 -89
- package/node_modules/zod/v4/core/json-schema.js +0 -1
- package/node_modules/zod/v4/core/memoizer.cjs +0 -360
- package/node_modules/zod/v4/core/memoizer.d.cts +0 -15
- package/node_modules/zod/v4/core/memoizer.d.ts +0 -15
- package/node_modules/zod/v4/core/memoizer.js +0 -311
- package/node_modules/zod/v4/core/package.json +0 -7
- package/node_modules/zod/v4/core/parse.cjs +0 -233
- package/node_modules/zod/v4/core/parse.d.cts +0 -52
- package/node_modules/zod/v4/core/parse.d.ts +0 -52
- package/node_modules/zod/v4/core/parse.js +0 -175
- package/node_modules/zod/v4/core/regexes.cjs +0 -209
- package/node_modules/zod/v4/core/regexes.d.cts +0 -90
- package/node_modules/zod/v4/core/regexes.d.ts +0 -90
- package/node_modules/zod/v4/core/regexes.js +0 -156
- package/node_modules/zod/v4/core/registries.cjs +0 -75
- package/node_modules/zod/v4/core/registries.d.cts +0 -35
- package/node_modules/zod/v4/core/registries.d.ts +0 -35
- package/node_modules/zod/v4/core/registries.js +0 -51
- package/node_modules/zod/v4/core/schemas.cjs +0 -2699
- package/node_modules/zod/v4/core/schemas.d.cts +0 -1275
- package/node_modules/zod/v4/core/schemas.d.ts +0 -1275
- package/node_modules/zod/v4/core/schemas.js +0 -2636
- package/node_modules/zod/v4/core/standard-schema.cjs +0 -21
- package/node_modules/zod/v4/core/standard-schema.d.cts +0 -126
- package/node_modules/zod/v4/core/standard-schema.d.ts +0 -126
- package/node_modules/zod/v4/core/standard-schema.js +0 -1
- package/node_modules/zod/v4/core/to-json-schema.cjs +0 -681
- package/node_modules/zod/v4/core/to-json-schema.d.cts +0 -154
- package/node_modules/zod/v4/core/to-json-schema.d.ts +0 -154
- package/node_modules/zod/v4/core/to-json-schema.js +0 -651
- package/node_modules/zod/v4/core/util.cjs +0 -964
- package/node_modules/zod/v4/core/util.d.cts +0 -280
- package/node_modules/zod/v4/core/util.d.ts +0 -280
- package/node_modules/zod/v4/core/util.js +0 -873
- package/node_modules/zod/v4/core/versions.cjs +0 -27
- package/node_modules/zod/v4/core/versions.d.cts +0 -5
- package/node_modules/zod/v4/core/versions.d.ts +0 -5
- package/node_modules/zod/v4/core/versions.js +0 -5
- package/node_modules/zod/v4/core/visit.cjs +0 -214
- package/node_modules/zod/v4/core/visit.d.cts +0 -30
- package/node_modules/zod/v4/core/visit.d.ts +0 -30
- package/node_modules/zod/v4/core/visit.js +0 -169
- package/node_modules/zod/v4/index.cjs +0 -51
- package/node_modules/zod/v4/index.d.cts +0 -3
- package/node_modules/zod/v4/index.d.ts +0 -3
- package/node_modules/zod/v4/index.js +0 -4
- package/node_modules/zod/v4/locales/ar.cjs +0 -138
- package/node_modules/zod/v4/locales/ar.d.cts +0 -5
- package/node_modules/zod/v4/locales/ar.d.ts +0 -4
- package/node_modules/zod/v4/locales/ar.js +0 -111
- package/node_modules/zod/v4/locales/az.cjs +0 -137
- package/node_modules/zod/v4/locales/az.d.cts +0 -5
- package/node_modules/zod/v4/locales/az.d.ts +0 -4
- package/node_modules/zod/v4/locales/az.js +0 -110
- package/node_modules/zod/v4/locales/be.cjs +0 -195
- package/node_modules/zod/v4/locales/be.d.cts +0 -5
- package/node_modules/zod/v4/locales/be.d.ts +0 -4
- package/node_modules/zod/v4/locales/be.js +0 -168
- package/node_modules/zod/v4/locales/bg.cjs +0 -152
- package/node_modules/zod/v4/locales/bg.d.cts +0 -5
- package/node_modules/zod/v4/locales/bg.d.ts +0 -4
- package/node_modules/zod/v4/locales/bg.js +0 -125
- package/node_modules/zod/v4/locales/bn.cjs +0 -140
- package/node_modules/zod/v4/locales/bn.d.cts +0 -5
- package/node_modules/zod/v4/locales/bn.d.ts +0 -4
- package/node_modules/zod/v4/locales/bn.js +0 -113
- package/node_modules/zod/v4/locales/ca.cjs +0 -139
- package/node_modules/zod/v4/locales/ca.d.cts +0 -5
- package/node_modules/zod/v4/locales/ca.d.ts +0 -4
- package/node_modules/zod/v4/locales/ca.js +0 -112
- package/node_modules/zod/v4/locales/ckb.cjs +0 -160
- package/node_modules/zod/v4/locales/ckb.d.cts +0 -5
- package/node_modules/zod/v4/locales/ckb.d.ts +0 -4
- package/node_modules/zod/v4/locales/ckb.js +0 -133
- package/node_modules/zod/v4/locales/cs.cjs +0 -143
- package/node_modules/zod/v4/locales/cs.d.cts +0 -5
- package/node_modules/zod/v4/locales/cs.d.ts +0 -4
- package/node_modules/zod/v4/locales/cs.js +0 -116
- package/node_modules/zod/v4/locales/da.cjs +0 -147
- package/node_modules/zod/v4/locales/da.d.cts +0 -5
- package/node_modules/zod/v4/locales/da.d.ts +0 -4
- package/node_modules/zod/v4/locales/da.js +0 -120
- package/node_modules/zod/v4/locales/de.cjs +0 -140
- package/node_modules/zod/v4/locales/de.d.cts +0 -5
- package/node_modules/zod/v4/locales/de.d.ts +0 -4
- package/node_modules/zod/v4/locales/de.js +0 -113
- package/node_modules/zod/v4/locales/el.cjs +0 -139
- package/node_modules/zod/v4/locales/el.d.cts +0 -5
- package/node_modules/zod/v4/locales/el.d.ts +0 -4
- package/node_modules/zod/v4/locales/el.js +0 -112
- package/node_modules/zod/v4/locales/en.cjs +0 -152
- package/node_modules/zod/v4/locales/en.d.cts +0 -5
- package/node_modules/zod/v4/locales/en.d.ts +0 -4
- package/node_modules/zod/v4/locales/en.js +0 -125
- package/node_modules/zod/v4/locales/eo.cjs +0 -141
- package/node_modules/zod/v4/locales/eo.d.cts +0 -5
- package/node_modules/zod/v4/locales/eo.d.ts +0 -4
- package/node_modules/zod/v4/locales/eo.js +0 -114
- package/node_modules/zod/v4/locales/es.cjs +0 -163
- package/node_modules/zod/v4/locales/es.d.cts +0 -5
- package/node_modules/zod/v4/locales/es.d.ts +0 -4
- package/node_modules/zod/v4/locales/es.js +0 -136
- package/node_modules/zod/v4/locales/fa.cjs +0 -146
- package/node_modules/zod/v4/locales/fa.d.cts +0 -5
- package/node_modules/zod/v4/locales/fa.d.ts +0 -4
- package/node_modules/zod/v4/locales/fa.js +0 -119
- package/node_modules/zod/v4/locales/fi.cjs +0 -144
- package/node_modules/zod/v4/locales/fi.d.cts +0 -5
- package/node_modules/zod/v4/locales/fi.d.ts +0 -4
- package/node_modules/zod/v4/locales/fi.js +0 -117
- package/node_modules/zod/v4/locales/fr-CA.cjs +0 -139
- package/node_modules/zod/v4/locales/fr-CA.d.cts +0 -5
- package/node_modules/zod/v4/locales/fr-CA.d.ts +0 -4
- package/node_modules/zod/v4/locales/fr-CA.js +0 -112
- package/node_modules/zod/v4/locales/fr.cjs +0 -156
- package/node_modules/zod/v4/locales/fr.d.cts +0 -5
- package/node_modules/zod/v4/locales/fr.d.ts +0 -4
- package/node_modules/zod/v4/locales/fr.js +0 -129
- package/node_modules/zod/v4/locales/gu.cjs +0 -140
- package/node_modules/zod/v4/locales/gu.d.cts +0 -5
- package/node_modules/zod/v4/locales/gu.d.ts +0 -4
- package/node_modules/zod/v4/locales/gu.js +0 -113
- package/node_modules/zod/v4/locales/he.cjs +0 -248
- package/node_modules/zod/v4/locales/he.d.cts +0 -5
- package/node_modules/zod/v4/locales/he.d.ts +0 -4
- package/node_modules/zod/v4/locales/he.js +0 -221
- package/node_modules/zod/v4/locales/hi.cjs +0 -138
- package/node_modules/zod/v4/locales/hi.d.cts +0 -5
- package/node_modules/zod/v4/locales/hi.d.ts +0 -4
- package/node_modules/zod/v4/locales/hi.js +0 -111
- package/node_modules/zod/v4/locales/hr.cjs +0 -153
- package/node_modules/zod/v4/locales/hr.d.cts +0 -5
- package/node_modules/zod/v4/locales/hr.d.ts +0 -4
- package/node_modules/zod/v4/locales/hr.js +0 -126
- package/node_modules/zod/v4/locales/hu.cjs +0 -140
- package/node_modules/zod/v4/locales/hu.d.cts +0 -5
- package/node_modules/zod/v4/locales/hu.d.ts +0 -4
- package/node_modules/zod/v4/locales/hu.js +0 -113
- package/node_modules/zod/v4/locales/hy.cjs +0 -185
- package/node_modules/zod/v4/locales/hy.d.cts +0 -5
- package/node_modules/zod/v4/locales/hy.d.ts +0 -4
- package/node_modules/zod/v4/locales/hy.js +0 -158
- package/node_modules/zod/v4/locales/id.cjs +0 -138
- package/node_modules/zod/v4/locales/id.d.cts +0 -5
- package/node_modules/zod/v4/locales/id.d.ts +0 -4
- package/node_modules/zod/v4/locales/id.js +0 -111
- package/node_modules/zod/v4/locales/index.cjs +0 -152
- package/node_modules/zod/v4/locales/index.d.cts +0 -63
- package/node_modules/zod/v4/locales/index.d.ts +0 -63
- package/node_modules/zod/v4/locales/index.js +0 -63
- package/node_modules/zod/v4/locales/is.cjs +0 -141
- package/node_modules/zod/v4/locales/is.d.cts +0 -5
- package/node_modules/zod/v4/locales/is.d.ts +0 -4
- package/node_modules/zod/v4/locales/is.js +0 -114
- package/node_modules/zod/v4/locales/it.cjs +0 -140
- package/node_modules/zod/v4/locales/it.d.cts +0 -5
- package/node_modules/zod/v4/locales/it.d.ts +0 -4
- package/node_modules/zod/v4/locales/it.js +0 -113
- package/node_modules/zod/v4/locales/ja.cjs +0 -139
- package/node_modules/zod/v4/locales/ja.d.cts +0 -5
- package/node_modules/zod/v4/locales/ja.d.ts +0 -4
- package/node_modules/zod/v4/locales/ja.js +0 -112
- package/node_modules/zod/v4/locales/ka.cjs +0 -144
- package/node_modules/zod/v4/locales/ka.d.cts +0 -5
- package/node_modules/zod/v4/locales/ka.d.ts +0 -4
- package/node_modules/zod/v4/locales/ka.js +0 -117
- package/node_modules/zod/v4/locales/kh.cjs +0 -12
- package/node_modules/zod/v4/locales/kh.d.cts +0 -5
- package/node_modules/zod/v4/locales/kh.d.ts +0 -5
- package/node_modules/zod/v4/locales/kh.js +0 -5
- package/node_modules/zod/v4/locales/km.cjs +0 -142
- package/node_modules/zod/v4/locales/km.d.cts +0 -5
- package/node_modules/zod/v4/locales/km.d.ts +0 -4
- package/node_modules/zod/v4/locales/km.js +0 -115
- package/node_modules/zod/v4/locales/kn.cjs +0 -143
- package/node_modules/zod/v4/locales/kn.d.cts +0 -5
- package/node_modules/zod/v4/locales/kn.d.ts +0 -4
- package/node_modules/zod/v4/locales/kn.js +0 -116
- package/node_modules/zod/v4/locales/ko.cjs +0 -143
- package/node_modules/zod/v4/locales/ko.d.cts +0 -5
- package/node_modules/zod/v4/locales/ko.d.ts +0 -4
- package/node_modules/zod/v4/locales/ko.js +0 -116
- package/node_modules/zod/v4/locales/lt.cjs +0 -234
- package/node_modules/zod/v4/locales/lt.d.cts +0 -5
- package/node_modules/zod/v4/locales/lt.d.ts +0 -4
- package/node_modules/zod/v4/locales/lt.js +0 -207
- package/node_modules/zod/v4/locales/mk.cjs +0 -141
- package/node_modules/zod/v4/locales/mk.d.cts +0 -5
- package/node_modules/zod/v4/locales/mk.d.ts +0 -4
- package/node_modules/zod/v4/locales/mk.js +0 -114
- package/node_modules/zod/v4/locales/ms.cjs +0 -139
- package/node_modules/zod/v4/locales/ms.d.cts +0 -5
- package/node_modules/zod/v4/locales/ms.d.ts +0 -4
- package/node_modules/zod/v4/locales/ms.js +0 -112
- package/node_modules/zod/v4/locales/ne.cjs +0 -138
- package/node_modules/zod/v4/locales/ne.d.cts +0 -5
- package/node_modules/zod/v4/locales/ne.d.ts +0 -4
- package/node_modules/zod/v4/locales/ne.js +0 -111
- package/node_modules/zod/v4/locales/nl.cjs +0 -142
- package/node_modules/zod/v4/locales/nl.d.cts +0 -5
- package/node_modules/zod/v4/locales/nl.d.ts +0 -4
- package/node_modules/zod/v4/locales/nl.js +0 -115
- package/node_modules/zod/v4/locales/nn.cjs +0 -140
- package/node_modules/zod/v4/locales/nn.d.cts +0 -5
- package/node_modules/zod/v4/locales/nn.d.ts +0 -4
- package/node_modules/zod/v4/locales/nn.js +0 -113
- package/node_modules/zod/v4/locales/no.cjs +0 -140
- package/node_modules/zod/v4/locales/no.d.cts +0 -5
- package/node_modules/zod/v4/locales/no.d.ts +0 -4
- package/node_modules/zod/v4/locales/no.js +0 -113
- package/node_modules/zod/v4/locales/ota.cjs +0 -141
- package/node_modules/zod/v4/locales/ota.d.cts +0 -5
- package/node_modules/zod/v4/locales/ota.d.ts +0 -4
- package/node_modules/zod/v4/locales/ota.js +0 -114
- package/node_modules/zod/v4/locales/package.json +0 -7
- package/node_modules/zod/v4/locales/pl.cjs +0 -141
- package/node_modules/zod/v4/locales/pl.d.cts +0 -5
- package/node_modules/zod/v4/locales/pl.d.ts +0 -4
- package/node_modules/zod/v4/locales/pl.js +0 -114
- package/node_modules/zod/v4/locales/ps.cjs +0 -146
- package/node_modules/zod/v4/locales/ps.d.cts +0 -5
- package/node_modules/zod/v4/locales/ps.d.ts +0 -4
- package/node_modules/zod/v4/locales/ps.js +0 -119
- package/node_modules/zod/v4/locales/pt-BR.cjs +0 -170
- package/node_modules/zod/v4/locales/pt-BR.d.cts +0 -5
- package/node_modules/zod/v4/locales/pt-BR.d.ts +0 -4
- package/node_modules/zod/v4/locales/pt-BR.js +0 -143
- package/node_modules/zod/v4/locales/pt.cjs +0 -169
- package/node_modules/zod/v4/locales/pt.d.cts +0 -5
- package/node_modules/zod/v4/locales/pt.d.ts +0 -4
- package/node_modules/zod/v4/locales/pt.js +0 -142
- package/node_modules/zod/v4/locales/ro.cjs +0 -149
- package/node_modules/zod/v4/locales/ro.d.cts +0 -5
- package/node_modules/zod/v4/locales/ro.d.ts +0 -4
- package/node_modules/zod/v4/locales/ro.js +0 -122
- package/node_modules/zod/v4/locales/ru.cjs +0 -195
- package/node_modules/zod/v4/locales/ru.d.cts +0 -5
- package/node_modules/zod/v4/locales/ru.d.ts +0 -4
- package/node_modules/zod/v4/locales/ru.js +0 -168
- package/node_modules/zod/v4/locales/sk.cjs +0 -143
- package/node_modules/zod/v4/locales/sk.d.cts +0 -5
- package/node_modules/zod/v4/locales/sk.d.ts +0 -4
- package/node_modules/zod/v4/locales/sk.js +0 -116
- package/node_modules/zod/v4/locales/sl.cjs +0 -141
- package/node_modules/zod/v4/locales/sl.d.cts +0 -5
- package/node_modules/zod/v4/locales/sl.d.ts +0 -4
- package/node_modules/zod/v4/locales/sl.js +0 -114
- package/node_modules/zod/v4/locales/sv.cjs +0 -142
- package/node_modules/zod/v4/locales/sv.d.cts +0 -5
- package/node_modules/zod/v4/locales/sv.d.ts +0 -4
- package/node_modules/zod/v4/locales/sv.js +0 -115
- package/node_modules/zod/v4/locales/ta.cjs +0 -142
- package/node_modules/zod/v4/locales/ta.d.cts +0 -5
- package/node_modules/zod/v4/locales/ta.d.ts +0 -4
- package/node_modules/zod/v4/locales/ta.js +0 -115
- package/node_modules/zod/v4/locales/tg.cjs +0 -144
- package/node_modules/zod/v4/locales/tg.d.cts +0 -5
- package/node_modules/zod/v4/locales/tg.d.ts +0 -4
- package/node_modules/zod/v4/locales/tg.js +0 -117
- package/node_modules/zod/v4/locales/th.cjs +0 -142
- package/node_modules/zod/v4/locales/th.d.cts +0 -5
- package/node_modules/zod/v4/locales/th.d.ts +0 -4
- package/node_modules/zod/v4/locales/th.js +0 -115
- package/node_modules/zod/v4/locales/tk.cjs +0 -134
- package/node_modules/zod/v4/locales/tk.d.cts +0 -5
- package/node_modules/zod/v4/locales/tk.d.ts +0 -4
- package/node_modules/zod/v4/locales/tk.js +0 -107
- package/node_modules/zod/v4/locales/tr.cjs +0 -137
- package/node_modules/zod/v4/locales/tr.d.cts +0 -5
- package/node_modules/zod/v4/locales/tr.d.ts +0 -4
- package/node_modules/zod/v4/locales/tr.js +0 -110
- package/node_modules/zod/v4/locales/ua.cjs +0 -12
- package/node_modules/zod/v4/locales/ua.d.cts +0 -5
- package/node_modules/zod/v4/locales/ua.d.ts +0 -5
- package/node_modules/zod/v4/locales/ua.js +0 -5
- package/node_modules/zod/v4/locales/uk.cjs +0 -140
- package/node_modules/zod/v4/locales/uk.d.cts +0 -5
- package/node_modules/zod/v4/locales/uk.d.ts +0 -4
- package/node_modules/zod/v4/locales/uk.js +0 -113
- package/node_modules/zod/v4/locales/ur.cjs +0 -142
- package/node_modules/zod/v4/locales/ur.d.cts +0 -5
- package/node_modules/zod/v4/locales/ur.d.ts +0 -4
- package/node_modules/zod/v4/locales/ur.js +0 -115
- package/node_modules/zod/v4/locales/uz.cjs +0 -140
- package/node_modules/zod/v4/locales/uz.d.cts +0 -5
- package/node_modules/zod/v4/locales/uz.d.ts +0 -4
- package/node_modules/zod/v4/locales/uz.js +0 -113
- package/node_modules/zod/v4/locales/vi.cjs +0 -140
- package/node_modules/zod/v4/locales/vi.d.cts +0 -5
- package/node_modules/zod/v4/locales/vi.d.ts +0 -4
- package/node_modules/zod/v4/locales/vi.js +0 -113
- package/node_modules/zod/v4/locales/yo.cjs +0 -139
- package/node_modules/zod/v4/locales/yo.d.cts +0 -5
- package/node_modules/zod/v4/locales/yo.d.ts +0 -4
- package/node_modules/zod/v4/locales/yo.js +0 -112
- package/node_modules/zod/v4/locales/zh-CN.cjs +0 -141
- package/node_modules/zod/v4/locales/zh-CN.d.cts +0 -5
- package/node_modules/zod/v4/locales/zh-CN.d.ts +0 -4
- package/node_modules/zod/v4/locales/zh-CN.js +0 -114
- package/node_modules/zod/v4/locales/zh-TW.cjs +0 -139
- package/node_modules/zod/v4/locales/zh-TW.d.cts +0 -5
- package/node_modules/zod/v4/locales/zh-TW.d.ts +0 -4
- package/node_modules/zod/v4/locales/zh-TW.js +0 -112
- package/node_modules/zod/v4/mini/checks.cjs +0 -54
- package/node_modules/zod/v4/mini/checks.d.cts +0 -1
- package/node_modules/zod/v4/mini/checks.d.ts +0 -1
- package/node_modules/zod/v4/mini/checks.js +0 -1
- package/node_modules/zod/v4/mini/coerce.cjs +0 -71
- package/node_modules/zod/v4/mini/coerce.d.cts +0 -7
- package/node_modules/zod/v4/mini/coerce.d.ts +0 -7
- package/node_modules/zod/v4/mini/coerce.js +0 -22
- package/node_modules/zod/v4/mini/deep-partial.cjs +0 -58
- package/node_modules/zod/v4/mini/deep-partial.d.cts +0 -14
- package/node_modules/zod/v4/mini/deep-partial.d.ts +0 -14
- package/node_modules/zod/v4/mini/deep-partial.js +0 -13
- package/node_modules/zod/v4/mini/external.cjs +0 -95
- package/node_modules/zod/v4/mini/external.d.cts +0 -16
- package/node_modules/zod/v4/mini/external.d.ts +0 -16
- package/node_modules/zod/v4/mini/external.js +0 -16
- package/node_modules/zod/v4/mini/in-out.cjs +0 -82
- package/node_modules/zod/v4/mini/in-out.d.cts +0 -8
- package/node_modules/zod/v4/mini/in-out.d.ts +0 -8
- package/node_modules/zod/v4/mini/in-out.js +0 -36
- package/node_modules/zod/v4/mini/index.cjs +0 -51
- package/node_modules/zod/v4/mini/index.d.cts +0 -3
- package/node_modules/zod/v4/mini/index.d.ts +0 -3
- package/node_modules/zod/v4/mini/index.js +0 -3
- package/node_modules/zod/v4/mini/iso.cjs +0 -83
- package/node_modules/zod/v4/mini/iso.d.cts +0 -22
- package/node_modules/zod/v4/mini/iso.d.ts +0 -22
- package/node_modules/zod/v4/mini/iso.js +0 -34
- package/node_modules/zod/v4/mini/package.json +0 -7
- package/node_modules/zod/v4/mini/parse.cjs +0 -37
- package/node_modules/zod/v4/mini/parse.d.cts +0 -1
- package/node_modules/zod/v4/mini/parse.d.ts +0 -1
- package/node_modules/zod/v4/mini/parse.js +0 -1
- package/node_modules/zod/v4/mini/schemas.cjs +0 -1147
- package/node_modules/zod/v4/mini/schemas.d.cts +0 -480
- package/node_modules/zod/v4/mini/schemas.d.ts +0 -480
- package/node_modules/zod/v4/mini/schemas.js +0 -1002
- package/node_modules/zod/v4/package.json +0 -7
- package/node_modules/zod/v4-mini/index.cjs +0 -51
- package/node_modules/zod/v4-mini/index.d.cts +0 -3
- package/node_modules/zod/v4-mini/index.d.ts +0 -3
- package/node_modules/zod/v4-mini/index.js +0 -3
- package/node_modules/zod/v4-mini/package.json +0 -7
|
@@ -1,4115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var src_exports = {};
|
|
23
|
-
__export(src_exports, {
|
|
24
|
-
ACCOUNT_SDK_CONTRACT: () => ACCOUNT_SDK_CONTRACT,
|
|
25
|
-
AccountClient: () => AccountClient,
|
|
26
|
-
AccountError: () => AccountError,
|
|
27
|
-
AccountIntegrationClient: () => AccountIntegrationClient,
|
|
28
|
-
AccountMutationError: () => AccountMutationError,
|
|
29
|
-
AuthzClient: () => AuthzClient,
|
|
30
|
-
BffSessionClient: () => BffSessionClient,
|
|
31
|
-
LedgerClient: () => LedgerClient,
|
|
32
|
-
MICRO_PER_CREDIT: () => MICRO_PER_CREDIT,
|
|
33
|
-
NotificationsClient: () => NotificationsClient,
|
|
34
|
-
Transport: () => Transport,
|
|
35
|
-
WorkforceClient: () => WorkforceClient,
|
|
36
|
-
WorkforceResourceMutationError: () => WorkforceResourceMutationError,
|
|
37
|
-
WorkspaceClient: () => WorkspaceClient,
|
|
38
|
-
WorkspaceKeyMutationError: () => WorkspaceKeyMutationError,
|
|
39
|
-
WorkspaceMembershipMutationError: () => WorkspaceMembershipMutationError,
|
|
40
|
-
XenoAccountClient: () => XenoAccountClient,
|
|
41
|
-
accountOperationIntentSchema: () => accountOperationIntentSchema,
|
|
42
|
-
accountSchema: () => accountSchema,
|
|
43
|
-
assertMembershipOperation: () => assertMembershipOperation,
|
|
44
|
-
authzCheckSchema: () => authzCheckSchema,
|
|
45
|
-
authzResultSchema: () => authzResultSchema,
|
|
46
|
-
balanceSchema: () => balanceSchema,
|
|
47
|
-
buildAuthorizeUrl: () => buildAuthorizeUrl,
|
|
48
|
-
codeForStatus: () => codeForStatus,
|
|
49
|
-
createOidcIntrospectionSessionAuthority: () => createOidcIntrospectionSessionAuthority,
|
|
50
|
-
createResourceRequestAuthorizer: () => createResourceRequestAuthorizer,
|
|
51
|
-
exchangeCode: () => exchangeCode,
|
|
52
|
-
fromMicro: () => fromMicro,
|
|
53
|
-
generatePkce: () => generatePkce,
|
|
54
|
-
generateState: () => generateState,
|
|
55
|
-
holdRequestSchema: () => holdRequestSchema,
|
|
56
|
-
holdSchema: () => holdSchema,
|
|
57
|
-
keychainStore: () => keychainStore,
|
|
58
|
-
membershipAbandonedSchema: () => membershipAbandonedSchema,
|
|
59
|
-
membershipCommittedSchema: () => membershipCommittedSchema,
|
|
60
|
-
membershipDeliverySchema: () => membershipDeliverySchema,
|
|
61
|
-
membershipMutationSchema: () => membershipMutationSchema,
|
|
62
|
-
membershipOperationSchema: () => membershipOperationSchema,
|
|
63
|
-
membershipRejectedSchema: () => membershipRejectedSchema,
|
|
64
|
-
memoryStore: () => memoryStore,
|
|
65
|
-
meterAggregationSchema: () => meterAggregationSchema,
|
|
66
|
-
normalize: () => normalize,
|
|
67
|
-
normalizeDpopHtu: () => normalizeDpopHtu,
|
|
68
|
-
notificationChannelSchema: () => notificationChannelSchema,
|
|
69
|
-
notificationDestinationActionSchema: () => notificationDestinationActionSchema,
|
|
70
|
-
notificationDestinationOperationSchema: () => notificationDestinationOperationSchema,
|
|
71
|
-
notificationEventSchema: () => notificationEventSchema,
|
|
72
|
-
notificationRuleSchema: () => notificationRuleSchema,
|
|
73
|
-
notificationScopeSchema: () => notificationScopeSchema,
|
|
74
|
-
notificationSettingsSchema: () => notificationSettingsSchema,
|
|
75
|
-
oauthTokenResponseSchema: () => oauthTokenResponseSchema,
|
|
76
|
-
pollDeviceToken: () => pollDeviceToken,
|
|
77
|
-
redact: () => redact,
|
|
78
|
-
refreshTokens: () => refreshTokens,
|
|
79
|
-
startDeviceAuthorization: () => startDeviceAuthorization,
|
|
80
|
-
surfaceSchema: () => surfaceSchema,
|
|
81
|
-
toMicro: () => toMicro,
|
|
82
|
-
tokenSetSchema: () => tokenSetSchema,
|
|
83
|
-
usageEventSchema: () => usageEventSchema,
|
|
84
|
-
usageResultSchema: () => usageResultSchema,
|
|
85
|
-
verifyAccessToken: () => verifyAccessToken,
|
|
86
|
-
verifyIdToken: () => verifyIdToken,
|
|
87
|
-
verifyLogoutToken: () => verifyLogoutToken,
|
|
88
|
-
workforceCreateResourceSchema: () => workforceCreateResourceSchema,
|
|
89
|
-
workforceDefinitionSchema: () => workforceDefinitionSchema,
|
|
90
|
-
workforceListOwnedResourcesSchema: () => workforceListOwnedResourcesSchema,
|
|
91
|
-
workforceOwnerSchema: () => workforceOwnerSchema,
|
|
92
|
-
workforceReadOperationSchema: () => workforceReadOperationSchema,
|
|
93
|
-
workspaceInviteRoleSchema: () => workspaceInviteRoleSchema,
|
|
94
|
-
workspaceInviteSchema: () => workspaceInviteSchema,
|
|
95
|
-
workspaceKeyOperationSchema: () => workspaceKeyOperationSchema,
|
|
96
|
-
workspaceKeyRejectionSchema: () => workspaceKeyRejectionSchema,
|
|
97
|
-
workspaceKeySchema: () => workspaceKeySchema,
|
|
98
|
-
workspaceKeyScopeSchema: () => workspaceKeyScopeSchema,
|
|
99
|
-
workspaceMemberSchema: () => workspaceMemberSchema,
|
|
100
|
-
workspaceRoleSchema: () => workspaceRoleSchema,
|
|
101
|
-
workspaceSchema: () => workspaceSchema
|
|
102
|
-
});
|
|
103
|
-
module.exports = __toCommonJS(src_exports);
|
|
104
|
-
|
|
105
|
-
// src/types.ts
|
|
106
|
-
var import_zod = require("zod");
|
|
107
|
-
var MICRO_PER_CREDIT = 1e6;
|
|
108
|
-
var surfaceSchema = import_zod.z.string().min(2).max(64).regex(/^xeno[_a-z0-9]+$/, "surface must look like xeno_post");
|
|
109
|
-
var accountSchema = import_zod.z.object({
|
|
110
|
-
id: import_zod.z.string().min(1),
|
|
111
|
-
email: import_zod.z.string().email(),
|
|
112
|
-
username: import_zod.z.string().nullable().default(null),
|
|
113
|
-
displayName: import_zod.z.string().nullable().default(null),
|
|
114
|
-
avatarUrl: import_zod.z.string().url().nullable().default(null),
|
|
115
|
-
emailVerified: import_zod.z.boolean().default(false),
|
|
116
|
-
/** Linked app surfaces for this account (unified-account view). */
|
|
117
|
-
linkedSurfaces: import_zod.z.array(surfaceSchema).default([])
|
|
118
|
-
});
|
|
119
|
-
var tokenSetSchema = import_zod.z.object({
|
|
120
|
-
accessToken: import_zod.z.string().min(1),
|
|
121
|
-
/** Opaque or JWT; the SDK treats it as opaque. */
|
|
122
|
-
tokenType: import_zod.z.string().default("Bearer"),
|
|
123
|
-
expiresAt: import_zod.z.coerce.date().nullable().default(null),
|
|
124
|
-
refreshToken: import_zod.z.string().nullable().default(null),
|
|
125
|
-
/** OIDC ID token (authentication only — never sent to resource APIs). */
|
|
126
|
-
idToken: import_zod.z.string().nullable().default(null),
|
|
127
|
-
scope: import_zod.z.array(import_zod.z.string()).default([]),
|
|
128
|
-
/** Session id claim, the join key for back-channel logout. */
|
|
129
|
-
sid: import_zod.z.string().nullable().default(null),
|
|
130
|
-
/** Signature-verified claims; never populated by unverified decoding. */
|
|
131
|
-
accessClaims: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).nullable().default(null),
|
|
132
|
-
idClaims: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).nullable().default(null)
|
|
133
|
-
});
|
|
134
|
-
var oauthTokenResponseSchema = import_zod.z.object({
|
|
135
|
-
access_token: import_zod.z.string(),
|
|
136
|
-
token_type: import_zod.z.string().default("Bearer"),
|
|
137
|
-
expires_in: import_zod.z.number().optional(),
|
|
138
|
-
refresh_token: import_zod.z.string().optional(),
|
|
139
|
-
id_token: import_zod.z.string().optional(),
|
|
140
|
-
scope: import_zod.z.string().optional()
|
|
141
|
-
});
|
|
142
|
-
var balanceSchema = import_zod.z.object({
|
|
143
|
-
/** Settled balance. */
|
|
144
|
-
postedMicro: import_zod.z.number().int(),
|
|
145
|
-
/** Settled minus active holds. */
|
|
146
|
-
pendingMicro: import_zod.z.number().int(),
|
|
147
|
-
/** Most conservative spendable amount — gate approvals on this. */
|
|
148
|
-
availableMicro: import_zod.z.number().int(),
|
|
149
|
-
currency: import_zod.z.literal("credits").default("credits"),
|
|
150
|
-
asOf: import_zod.z.coerce.date().default(() => /* @__PURE__ */ new Date(0))
|
|
151
|
-
});
|
|
152
|
-
var meterAggregationSchema = import_zod.z.enum([
|
|
153
|
-
"sum",
|
|
154
|
-
"count",
|
|
155
|
-
"max",
|
|
156
|
-
"min",
|
|
157
|
-
"unique_count",
|
|
158
|
-
"latest"
|
|
159
|
-
]);
|
|
160
|
-
var usageEventSchema = import_zod.z.object({
|
|
161
|
-
surface: surfaceSchema,
|
|
162
|
-
/** Stable, producer-supplied dedup id. */
|
|
163
|
-
transactionId: import_zod.z.string().min(8).max(255),
|
|
164
|
-
operation: import_zod.z.string().min(1),
|
|
165
|
-
model: import_zod.z.string().nullable().default(null),
|
|
166
|
-
provider: import_zod.z.string().nullable().default(null),
|
|
167
|
-
/** Pre-computed cost in micro-credits, if the caller priced it. */
|
|
168
|
-
costMicro: import_zod.z.number().int().nonnegative().nullable().default(null),
|
|
169
|
-
inputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
|
|
170
|
-
outputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
|
|
171
|
-
/** Arbitrary attribution dimensions (project, workspace, …). */
|
|
172
|
-
dimensions: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).default({}),
|
|
173
|
-
occurredAt: import_zod.z.coerce.date().optional()
|
|
174
|
-
});
|
|
175
|
-
var usageResultSchema = import_zod.z.object({
|
|
176
|
-
accepted: import_zod.z.boolean(),
|
|
177
|
-
/** True when the event was a duplicate (idempotent no-op). */
|
|
178
|
-
duplicate: import_zod.z.boolean().default(false),
|
|
179
|
-
costMicro: import_zod.z.number().int().nonnegative(),
|
|
180
|
-
transactionId: import_zod.z.string(),
|
|
181
|
-
balance: balanceSchema.nullable().default(null)
|
|
182
|
-
});
|
|
183
|
-
var holdRequestSchema = import_zod.z.object({
|
|
184
|
-
surface: surfaceSchema,
|
|
185
|
-
/** Idempotency key for the hold itself. */
|
|
186
|
-
holdId: import_zod.z.string().min(8).max(255),
|
|
187
|
-
amountMicro: import_zod.z.number().int().positive(),
|
|
188
|
-
operation: import_zod.z.string().min(1),
|
|
189
|
-
expiresInSeconds: import_zod.z.number().int().positive().max(86400).default(900),
|
|
190
|
-
dimensions: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).default({})
|
|
191
|
-
});
|
|
192
|
-
var holdSchema = import_zod.z.object({
|
|
193
|
-
holdId: import_zod.z.string(),
|
|
194
|
-
state: import_zod.z.enum([
|
|
195
|
-
"held",
|
|
196
|
-
"settled",
|
|
197
|
-
"voided",
|
|
198
|
-
"expired"
|
|
199
|
-
]),
|
|
200
|
-
amountMicro: import_zod.z.number().int().nonnegative(),
|
|
201
|
-
settledMicro: import_zod.z.number().int().nonnegative().default(0),
|
|
202
|
-
balance: balanceSchema.nullable().default(null)
|
|
203
|
-
});
|
|
204
|
-
var authzCheckSchema = import_zod.z.object({
|
|
205
|
-
/** e.g. `user:abc` or `agent:scout`. */
|
|
206
|
-
subject: import_zod.z.string().min(1),
|
|
207
|
-
relation: import_zod.z.string().min(1),
|
|
208
|
-
/** e.g. `workspace:acme` or `post:123`. */
|
|
209
|
-
object: import_zod.z.string().min(1),
|
|
210
|
-
context: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).default({})
|
|
211
|
-
});
|
|
212
|
-
var authzResultSchema = import_zod.z.object({
|
|
213
|
-
allowed: import_zod.z.boolean(),
|
|
214
|
-
/** Optional reason/trace for debugging (never authoritative). */
|
|
215
|
-
reason: import_zod.z.string().nullable().default(null)
|
|
216
|
-
});
|
|
217
|
-
function toMicro(credits) {
|
|
218
|
-
return Math.round(credits * MICRO_PER_CREDIT);
|
|
219
|
-
}
|
|
220
|
-
__name(toMicro, "toMicro");
|
|
221
|
-
function fromMicro(micro) {
|
|
222
|
-
return micro / MICRO_PER_CREDIT;
|
|
223
|
-
}
|
|
224
|
-
__name(fromMicro, "fromMicro");
|
|
225
|
-
|
|
226
|
-
// src/errors.ts
|
|
227
|
-
var AccountError = class extends Error {
|
|
228
|
-
static {
|
|
229
|
-
__name(this, "AccountError");
|
|
230
|
-
}
|
|
231
|
-
code;
|
|
232
|
-
httpStatus;
|
|
233
|
-
retryable;
|
|
234
|
-
retryAfterMs;
|
|
235
|
-
oauthError;
|
|
236
|
-
constructor(args) {
|
|
237
|
-
super(args.message);
|
|
238
|
-
this.name = "AccountError";
|
|
239
|
-
this.code = args.code;
|
|
240
|
-
this.httpStatus = args.httpStatus ?? null;
|
|
241
|
-
this.retryable = args.retryable ?? defaultRetryable(args.code);
|
|
242
|
-
this.retryAfterMs = args.retryAfterMs ?? null;
|
|
243
|
-
this.oauthError = args.oauthError ?? null;
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
function defaultRetryable(code) {
|
|
247
|
-
return code === "UNREACHABLE" || code === "RATE_LIMITED" || code === "PLATFORM_ERROR";
|
|
248
|
-
}
|
|
249
|
-
__name(defaultRetryable, "defaultRetryable");
|
|
250
|
-
function codeForStatus(status) {
|
|
251
|
-
if (status === 401 || status === 403) return "INVALID_TOKEN";
|
|
252
|
-
if (status === 402) return "INSUFFICIENT_CREDITS";
|
|
253
|
-
if (status === 409) return "CONFLICT";
|
|
254
|
-
if (status === 400 || status === 422) return "BAD_REQUEST";
|
|
255
|
-
if (status === 404) return "NOT_FOUND";
|
|
256
|
-
if (status === 429) return "RATE_LIMITED";
|
|
257
|
-
if (status >= 500) return "UNREACHABLE";
|
|
258
|
-
return "PLATFORM_ERROR";
|
|
259
|
-
}
|
|
260
|
-
__name(codeForStatus, "codeForStatus");
|
|
261
|
-
|
|
262
|
-
// src/jwt-json.ts
|
|
263
|
-
function parseJwtObject(source) {
|
|
264
|
-
if (source.length > 16384) throw new SyntaxError("JWT JSON bound");
|
|
265
|
-
let offset = 0;
|
|
266
|
-
const whitespace = /* @__PURE__ */ __name(() => {
|
|
267
|
-
while (offset < source.length && /[ \t\r\n]/.test(source[offset] ?? "")) offset++;
|
|
268
|
-
}, "whitespace");
|
|
269
|
-
const invalid2 = /* @__PURE__ */ __name(() => {
|
|
270
|
-
throw new SyntaxError("Ambiguous JWT JSON");
|
|
271
|
-
}, "invalid");
|
|
272
|
-
const string = /* @__PURE__ */ __name(() => {
|
|
273
|
-
const start = offset++;
|
|
274
|
-
while (offset < source.length) {
|
|
275
|
-
const current = source[offset++];
|
|
276
|
-
if (current === '"') return JSON.parse(source.slice(start, offset));
|
|
277
|
-
if (current === "\\") offset++;
|
|
278
|
-
}
|
|
279
|
-
return invalid2();
|
|
280
|
-
}, "string");
|
|
281
|
-
const value = /* @__PURE__ */ __name((depth) => {
|
|
282
|
-
if (depth > 8) invalid2();
|
|
283
|
-
whitespace();
|
|
284
|
-
const opening = source[offset];
|
|
285
|
-
if (opening === '"') {
|
|
286
|
-
string();
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
if (opening === "{" || opening === "[") {
|
|
290
|
-
const close = opening === "{" ? "}" : "]";
|
|
291
|
-
offset++;
|
|
292
|
-
whitespace();
|
|
293
|
-
if (source[offset] === close) {
|
|
294
|
-
offset++;
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
const names = /* @__PURE__ */ new Set();
|
|
298
|
-
let count = 0;
|
|
299
|
-
while (offset < source.length) {
|
|
300
|
-
if (++count > 256) invalid2();
|
|
301
|
-
if (opening === "{") {
|
|
302
|
-
whitespace();
|
|
303
|
-
if (source[offset] !== '"') invalid2();
|
|
304
|
-
const key = string();
|
|
305
|
-
if (names.has(key) || key === "__proto__" || key === "constructor" || key === "prototype") invalid2();
|
|
306
|
-
names.add(key);
|
|
307
|
-
whitespace();
|
|
308
|
-
if (source[offset++] !== ":") invalid2();
|
|
309
|
-
}
|
|
310
|
-
value(depth + 1);
|
|
311
|
-
whitespace();
|
|
312
|
-
if (source[offset] === close) {
|
|
313
|
-
offset++;
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
if (source[offset++] !== ",") invalid2();
|
|
317
|
-
}
|
|
318
|
-
return invalid2();
|
|
319
|
-
}
|
|
320
|
-
const literal = /^(?:true|false|null|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)/.exec(source.slice(offset));
|
|
321
|
-
if (!literal) return invalid2();
|
|
322
|
-
offset += literal[0].length;
|
|
323
|
-
}, "value");
|
|
324
|
-
value(0);
|
|
325
|
-
whitespace();
|
|
326
|
-
if (offset !== source.length) invalid2();
|
|
327
|
-
const parsed = JSON.parse(source, (_key, item) => {
|
|
328
|
-
if (typeof item === "number" && !Number.isFinite(item)) invalid2();
|
|
329
|
-
return item;
|
|
330
|
-
});
|
|
331
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) invalid2();
|
|
332
|
-
return parsed;
|
|
333
|
-
}
|
|
334
|
-
__name(parseJwtObject, "parseJwtObject");
|
|
335
|
-
|
|
336
|
-
// src/http.ts
|
|
337
|
-
function authorizationArgs(auth) {
|
|
338
|
-
return typeof auth === "function" ? {
|
|
339
|
-
authorization: auth
|
|
340
|
-
} : typeof auth === "string" ? {
|
|
341
|
-
token: auth,
|
|
342
|
-
tokenType: "Bearer"
|
|
343
|
-
} : {
|
|
344
|
-
token: auth.token,
|
|
345
|
-
tokenType: auth.tokenType,
|
|
346
|
-
headers: auth.headers
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
__name(authorizationArgs, "authorizationArgs");
|
|
350
|
-
var Transport = class {
|
|
351
|
-
static {
|
|
352
|
-
__name(this, "Transport");
|
|
353
|
-
}
|
|
354
|
-
fetchImpl;
|
|
355
|
-
timeoutMs;
|
|
356
|
-
maxRetries;
|
|
357
|
-
userAgent;
|
|
358
|
-
maxResponseBytes;
|
|
359
|
-
constructor(opts = {}) {
|
|
360
|
-
this.fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
361
|
-
this.timeoutMs = opts.timeoutMs ?? 8e3;
|
|
362
|
-
this.maxRetries = opts.maxRetries ?? 2;
|
|
363
|
-
this.userAgent = opts.userAgent ?? "xeno-account-client/0.1";
|
|
364
|
-
this.maxResponseBytes = opts.maxResponseBytes ?? 1024 * 1024;
|
|
365
|
-
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs < 1 || this.timeoutMs > 12e4 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes < 1 || this.maxResponseBytes > 8 * 1024 * 1024 || !Number.isSafeInteger(this.maxRetries) || this.maxRetries < 0 || this.maxRetries > 10) throw new TypeError("Account transport deadline and response bound are invalid");
|
|
366
|
-
}
|
|
367
|
-
/** Perform a request and return parsed JSON (or null for empty bodies). */
|
|
368
|
-
async request(args) {
|
|
369
|
-
let body = args.body;
|
|
370
|
-
const headers = {
|
|
371
|
-
...args.headers
|
|
372
|
-
};
|
|
373
|
-
if (body !== void 0 && typeof body !== "string") {
|
|
374
|
-
try {
|
|
375
|
-
body = JSON.stringify(body);
|
|
376
|
-
} catch {
|
|
377
|
-
throw new AccountError({
|
|
378
|
-
code: "BAD_REQUEST",
|
|
379
|
-
message: "Account request body cannot be serialized"
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
headers["content-type"] = "application/json";
|
|
383
|
-
}
|
|
384
|
-
args = Object.freeze({
|
|
385
|
-
...args,
|
|
386
|
-
body,
|
|
387
|
-
headers: Object.freeze(headers)
|
|
388
|
-
});
|
|
389
|
-
const isMutation = args.method !== "GET";
|
|
390
|
-
const staticProof = args.tokenType === "DPoP" || Object.keys(args.headers ?? {}).some((name) => name.toLowerCase() === "dpop");
|
|
391
|
-
const retrySafe = (!isMutation || Boolean(args.idempotencyKey)) && (!staticProof || Boolean(args.authorization));
|
|
392
|
-
const attempts = retrySafe ? this.maxRetries + 1 : 1;
|
|
393
|
-
let lastErr = null;
|
|
394
|
-
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
395
|
-
try {
|
|
396
|
-
return await this.once(args);
|
|
397
|
-
} catch (err) {
|
|
398
|
-
const ae = err instanceof AccountError ? err : new AccountError({
|
|
399
|
-
code: "UNREACHABLE",
|
|
400
|
-
message: "Account request failed before a verified response was received"
|
|
401
|
-
});
|
|
402
|
-
lastErr = ae;
|
|
403
|
-
if (!ae.retryable || attempt === attempts - 1) throw ae;
|
|
404
|
-
await sleep(backoffMs(attempt, ae.retryAfterMs), args.signal);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
throw lastErr ?? new AccountError({
|
|
408
|
-
code: "PLATFORM_ERROR",
|
|
409
|
-
message: "request failed"
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
async once(args) {
|
|
413
|
-
const controller = new AbortController();
|
|
414
|
-
const callerAborted = /* @__PURE__ */ __name(() => controller.abort(), "callerAborted");
|
|
415
|
-
args.signal?.addEventListener("abort", callerAborted, {
|
|
416
|
-
once: true
|
|
417
|
-
});
|
|
418
|
-
if (args.signal?.aborted) callerAborted();
|
|
419
|
-
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
420
|
-
let res;
|
|
421
|
-
try {
|
|
422
|
-
if (args.signal?.aborted) throw cancellationError();
|
|
423
|
-
let auth;
|
|
424
|
-
if (args.authorization) {
|
|
425
|
-
try {
|
|
426
|
-
auth = await beforeAbort(args.authorization(args.method, args.url), controller.signal);
|
|
427
|
-
} catch (error) {
|
|
428
|
-
throw new AccountError({
|
|
429
|
-
code: error instanceof AccountError ? error.code : "UNREACHABLE",
|
|
430
|
-
message: "Account request authorization unavailable",
|
|
431
|
-
...error instanceof AccountError ? {
|
|
432
|
-
httpStatus: error.httpStatus,
|
|
433
|
-
retryable: error.retryable
|
|
434
|
-
} : {}
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
if (!auth || typeof auth.token !== "string" || !auth.token || auth.token.length > 16384 || /[\r\n]/.test(auth.token) || ![
|
|
438
|
-
"Bearer",
|
|
439
|
-
"DPoP"
|
|
440
|
-
].includes(auth.tokenType)) throw new AccountError({
|
|
441
|
-
code: "INVALID_TOKEN",
|
|
442
|
-
message: "Account request authorization invalid"
|
|
443
|
-
});
|
|
444
|
-
const proofHeaders = Object.entries(auth.headers ?? {}).filter(([name]) => name.toLowerCase() === "dpop");
|
|
445
|
-
if (auth.tokenType === "DPoP" && (proofHeaders.length !== 1 || typeof proofHeaders[0]?.[1] !== "string" || !proofHeaders[0][1] || proofHeaders[0][1].length > 16384 || /[\r\n]/.test(proofHeaders[0][1]))) throw new AccountError({
|
|
446
|
-
code: "INVALID_TOKEN",
|
|
447
|
-
message: "Account request proof invalid"
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
const supplied = Object.fromEntries(Object.entries(args.headers ?? {}).map(([key, value]) => [
|
|
451
|
-
key.toLowerCase(),
|
|
452
|
-
value
|
|
453
|
-
]));
|
|
454
|
-
if (auth) {
|
|
455
|
-
delete supplied.authorization;
|
|
456
|
-
delete supplied.dpop;
|
|
457
|
-
}
|
|
458
|
-
const headers = {
|
|
459
|
-
accept: "application/json",
|
|
460
|
-
"user-agent": this.userAgent,
|
|
461
|
-
...supplied,
|
|
462
|
-
...Object.fromEntries(Object.entries(auth?.headers ?? {}).map(([key, value]) => [
|
|
463
|
-
key.toLowerCase(),
|
|
464
|
-
value
|
|
465
|
-
]))
|
|
466
|
-
};
|
|
467
|
-
const token = auth?.token ?? args.token;
|
|
468
|
-
if (token) headers["authorization"] = `${auth?.tokenType ?? args.tokenType ?? "Bearer"} ${token}`;
|
|
469
|
-
if (args.idempotencyKey) headers["idempotency-key"] = args.idempotencyKey;
|
|
470
|
-
let payload;
|
|
471
|
-
if (typeof args.body === "string") {
|
|
472
|
-
payload = args.body;
|
|
473
|
-
} else if (args.body !== void 0) {
|
|
474
|
-
headers["content-type"] = "application/json";
|
|
475
|
-
try {
|
|
476
|
-
payload = JSON.stringify(args.body);
|
|
477
|
-
} catch {
|
|
478
|
-
throw new AccountError({
|
|
479
|
-
code: "BAD_REQUEST",
|
|
480
|
-
message: "Account request body cannot be serialized"
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (controller.signal.aborted) throw new Error("Account response deadline");
|
|
485
|
-
res = await fetchBeforeAbort(this.fetchImpl, args.url, {
|
|
486
|
-
method: args.method,
|
|
487
|
-
headers,
|
|
488
|
-
body: payload,
|
|
489
|
-
signal: controller.signal,
|
|
490
|
-
redirect: "error",
|
|
491
|
-
cache: "no-store",
|
|
492
|
-
credentials: "omit"
|
|
493
|
-
}, controller.signal);
|
|
494
|
-
if (!res.ok) {
|
|
495
|
-
const code = codeForStatus(res.status);
|
|
496
|
-
const oauthError = args.oauthErrorResponse ? await readOAuthError(res, controller.signal) : null;
|
|
497
|
-
throw new AccountError({
|
|
498
|
-
code,
|
|
499
|
-
message: `${args.method} ${safeUrl(args.url)} -> ${res.status}`,
|
|
500
|
-
httpStatus: res.status,
|
|
501
|
-
retryAfterMs: parseRetryAfter(res.headers.get("retry-after")),
|
|
502
|
-
oauthError
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
if (res.status === 204 || !res.body) return null;
|
|
506
|
-
const text2 = await readBoundedText(res, controller.signal, this.maxResponseBytes);
|
|
507
|
-
if (!text2) return null;
|
|
508
|
-
try {
|
|
509
|
-
return JSON.parse(text2);
|
|
510
|
-
} catch {
|
|
511
|
-
throw new AccountError({
|
|
512
|
-
code: "INVALID_RESPONSE",
|
|
513
|
-
message: `non-JSON response from ${safeUrl(args.url)}`
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
} catch (err) {
|
|
517
|
-
if (args.signal?.aborted) throw cancellationError();
|
|
518
|
-
if (err instanceof AccountError) throw err;
|
|
519
|
-
throw new AccountError({
|
|
520
|
-
code: "UNREACHABLE",
|
|
521
|
-
message: `request to ${safeUrl(args.url)} failed`,
|
|
522
|
-
retryable: true
|
|
523
|
-
});
|
|
524
|
-
} finally {
|
|
525
|
-
controller.abort();
|
|
526
|
-
args.signal?.removeEventListener("abort", callerAborted);
|
|
527
|
-
clearTimeout(timer);
|
|
528
|
-
if (res) cancelBody(res);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
function cancelBody(response) {
|
|
533
|
-
void response.body?.cancel().catch(() => {
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
__name(cancelBody, "cancelBody");
|
|
537
|
-
function beforeAbort(pending, signal) {
|
|
538
|
-
return new Promise((resolve, reject) => {
|
|
539
|
-
const aborted = /* @__PURE__ */ __name(() => {
|
|
540
|
-
signal.removeEventListener("abort", aborted);
|
|
541
|
-
reject(new Error("Account response deadline"));
|
|
542
|
-
}, "aborted");
|
|
543
|
-
if (signal.aborted) {
|
|
544
|
-
void pending.catch(() => {
|
|
545
|
-
});
|
|
546
|
-
aborted();
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
signal.addEventListener("abort", aborted, {
|
|
550
|
-
once: true
|
|
551
|
-
});
|
|
552
|
-
pending.then((value) => {
|
|
553
|
-
signal.removeEventListener("abort", aborted);
|
|
554
|
-
if (signal.aborted) aborted();
|
|
555
|
-
else resolve(value);
|
|
556
|
-
}, (error) => {
|
|
557
|
-
signal.removeEventListener("abort", aborted);
|
|
558
|
-
reject(error);
|
|
559
|
-
});
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
__name(beforeAbort, "beforeAbort");
|
|
563
|
-
function fetchBeforeAbort(fetchImpl, url, init, signal) {
|
|
564
|
-
const pending = Promise.resolve(fetchImpl(url, init));
|
|
565
|
-
void pending.then((response) => {
|
|
566
|
-
if (signal.aborted) cancelBody(response);
|
|
567
|
-
}, () => {
|
|
568
|
-
});
|
|
569
|
-
return beforeAbort(pending, signal);
|
|
570
|
-
}
|
|
571
|
-
__name(fetchBeforeAbort, "fetchBeforeAbort");
|
|
572
|
-
async function readBoundedText(response, signal, maxBytes) {
|
|
573
|
-
const reader = response.body?.getReader();
|
|
574
|
-
if (!reader) return "";
|
|
575
|
-
let complete = false;
|
|
576
|
-
try {
|
|
577
|
-
const decoder = new TextDecoder("utf-8", {
|
|
578
|
-
fatal: true
|
|
579
|
-
});
|
|
580
|
-
let text2 = "", size = 0;
|
|
581
|
-
while (true) {
|
|
582
|
-
const chunk = await beforeAbort(reader.read(), signal);
|
|
583
|
-
if (chunk.done) {
|
|
584
|
-
complete = true;
|
|
585
|
-
break;
|
|
586
|
-
}
|
|
587
|
-
size += chunk.value.byteLength;
|
|
588
|
-
if (size > maxBytes) throw new AccountError({
|
|
589
|
-
code: "INVALID_RESPONSE",
|
|
590
|
-
message: "Account response exceeds configured bound"
|
|
591
|
-
});
|
|
592
|
-
try {
|
|
593
|
-
text2 += decoder.decode(chunk.value, {
|
|
594
|
-
stream: true
|
|
595
|
-
});
|
|
596
|
-
} catch {
|
|
597
|
-
throw new AccountError({
|
|
598
|
-
code: "INVALID_RESPONSE",
|
|
599
|
-
message: "Account response is not valid UTF-8"
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
try {
|
|
604
|
-
return text2 + decoder.decode();
|
|
605
|
-
} catch {
|
|
606
|
-
throw new AccountError({
|
|
607
|
-
code: "INVALID_RESPONSE",
|
|
608
|
-
message: "Account response is not valid UTF-8"
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
} finally {
|
|
612
|
-
if (!complete) void reader.cancel().catch(() => {
|
|
613
|
-
});
|
|
614
|
-
reader.releaseLock();
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
__name(readBoundedText, "readBoundedText");
|
|
618
|
-
async function readOAuthError(response, signal) {
|
|
619
|
-
try {
|
|
620
|
-
const body = parseJwtObject(await readBoundedText(response, signal, 4096));
|
|
621
|
-
const code = body.error;
|
|
622
|
-
return typeof code === "string" && [
|
|
623
|
-
"invalid_grant",
|
|
624
|
-
"invalid_client",
|
|
625
|
-
"invalid_scope",
|
|
626
|
-
"invalid_request",
|
|
627
|
-
"unauthorized_client",
|
|
628
|
-
"unsupported_grant_type",
|
|
629
|
-
"authorization_pending",
|
|
630
|
-
"slow_down",
|
|
631
|
-
"access_denied",
|
|
632
|
-
"expired_token",
|
|
633
|
-
"use_dpop_nonce",
|
|
634
|
-
"invalid_dpop_proof"
|
|
635
|
-
].includes(code) ? code : null;
|
|
636
|
-
} catch {
|
|
637
|
-
return null;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
__name(readOAuthError, "readOAuthError");
|
|
641
|
-
function backoffMs(attempt, retryAfterMs) {
|
|
642
|
-
if (retryAfterMs && retryAfterMs > 0) return Math.min(retryAfterMs, 1e4);
|
|
643
|
-
return Math.min(200 * (2 ** attempt + (attempt === 0 ? 0 : 1)), 5e3);
|
|
644
|
-
}
|
|
645
|
-
__name(backoffMs, "backoffMs");
|
|
646
|
-
function parseRetryAfter(header) {
|
|
647
|
-
if (!header) return null;
|
|
648
|
-
const seconds = Number(header);
|
|
649
|
-
return Number.isFinite(seconds) ? seconds * 1e3 : null;
|
|
650
|
-
}
|
|
651
|
-
__name(parseRetryAfter, "parseRetryAfter");
|
|
652
|
-
function cancellationError() {
|
|
653
|
-
return new AccountError({
|
|
654
|
-
code: "BAD_REQUEST",
|
|
655
|
-
message: "Account request was cancelled; outcome may be unconfirmed",
|
|
656
|
-
retryable: false
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
__name(cancellationError, "cancellationError");
|
|
660
|
-
function sleep(ms, signal) {
|
|
661
|
-
return new Promise((resolve, reject) => {
|
|
662
|
-
const timer = setTimeout(done, ms);
|
|
663
|
-
function cleanup() {
|
|
664
|
-
clearTimeout(timer);
|
|
665
|
-
signal?.removeEventListener("abort", aborted);
|
|
666
|
-
}
|
|
667
|
-
__name(cleanup, "cleanup");
|
|
668
|
-
function done() {
|
|
669
|
-
cleanup();
|
|
670
|
-
resolve();
|
|
671
|
-
}
|
|
672
|
-
__name(done, "done");
|
|
673
|
-
function aborted() {
|
|
674
|
-
cleanup();
|
|
675
|
-
reject(cancellationError());
|
|
676
|
-
}
|
|
677
|
-
__name(aborted, "aborted");
|
|
678
|
-
signal?.addEventListener("abort", aborted, {
|
|
679
|
-
once: true
|
|
680
|
-
});
|
|
681
|
-
if (signal?.aborted) aborted();
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
__name(sleep, "sleep");
|
|
685
|
-
function safeUrl(url) {
|
|
686
|
-
try {
|
|
687
|
-
const u = new URL(url);
|
|
688
|
-
return u.origin;
|
|
689
|
-
} catch {
|
|
690
|
-
return "[invalid account URL]";
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
__name(safeUrl, "safeUrl");
|
|
694
|
-
|
|
695
|
-
// src/account.ts
|
|
696
|
-
var AccountClient = class {
|
|
697
|
-
static {
|
|
698
|
-
__name(this, "AccountClient");
|
|
699
|
-
}
|
|
700
|
-
base;
|
|
701
|
-
transport;
|
|
702
|
-
constructor(base2, transport) {
|
|
703
|
-
this.base = base2;
|
|
704
|
-
this.transport = transport;
|
|
705
|
-
}
|
|
706
|
-
/** Resolve a token to its account, or throw an AccountError. */
|
|
707
|
-
async me(auth) {
|
|
708
|
-
let raw;
|
|
709
|
-
try {
|
|
710
|
-
raw = await this.transport.request({
|
|
711
|
-
method: "GET",
|
|
712
|
-
url: `${this.base}/api/v2/me`,
|
|
713
|
-
...authorizationArgs(auth)
|
|
714
|
-
});
|
|
715
|
-
} catch (err) {
|
|
716
|
-
const isDpop = typeof auth === "object" && auth.tokenType === "DPoP";
|
|
717
|
-
if (err instanceof AccountError && err.code === "NOT_FOUND" && !isDpop) {
|
|
718
|
-
raw = await this.transport.request({
|
|
719
|
-
method: "GET",
|
|
720
|
-
url: `${this.base}/api/auth/me`,
|
|
721
|
-
...authorizationArgs(auth)
|
|
722
|
-
});
|
|
723
|
-
} else {
|
|
724
|
-
throw err;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
const account = normalize(raw);
|
|
728
|
-
if (!account) {
|
|
729
|
-
throw new AccountError({
|
|
730
|
-
code: "INVALID_RESPONSE",
|
|
731
|
-
message: "/me returned an unrecognised shape"
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
return account;
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
function normalize(body) {
|
|
738
|
-
if (!body || typeof body !== "object") return null;
|
|
739
|
-
const root = body;
|
|
740
|
-
const user = root["user"] ?? root["data"] ?? root;
|
|
741
|
-
if (!user || typeof user !== "object") return null;
|
|
742
|
-
const id5 = str(user["id"]);
|
|
743
|
-
const email = str(user["email"]);
|
|
744
|
-
if (!id5 || !email) return null;
|
|
745
|
-
const linked2 = Array.isArray(user["linkedSurfaces"]) ? [
|
|
746
|
-
...new Set(user["linkedSurfaces"].map(normalizeSurface).filter(isSurface))
|
|
747
|
-
] : [];
|
|
748
|
-
const parsed = accountSchema.safeParse({
|
|
749
|
-
id: id5,
|
|
750
|
-
email,
|
|
751
|
-
username: str(user["username"]) ?? null,
|
|
752
|
-
displayName: str(user["display_name"]) ?? str(user["displayName"]) ?? null,
|
|
753
|
-
avatarUrl: str(user["avatar_url"]) ?? str(user["avatarUrl"]) ?? null,
|
|
754
|
-
emailVerified: Boolean(user["email_verified"] ?? user["emailVerified"] ?? false),
|
|
755
|
-
linkedSurfaces: linked2
|
|
756
|
-
});
|
|
757
|
-
return parsed.success ? parsed.data : null;
|
|
758
|
-
}
|
|
759
|
-
__name(normalize, "normalize");
|
|
760
|
-
function str(v) {
|
|
761
|
-
return typeof v === "string" && v.length > 0 ? v : void 0;
|
|
762
|
-
}
|
|
763
|
-
__name(str, "str");
|
|
764
|
-
function normalizeSurface(value) {
|
|
765
|
-
if (typeof value !== "string") return void 0;
|
|
766
|
-
const parsed = surfaceSchema.safeParse(value.trim().toLowerCase().replace(/-/g, "_"));
|
|
767
|
-
return parsed.success ? parsed.data : void 0;
|
|
768
|
-
}
|
|
769
|
-
__name(normalizeSurface, "normalizeSurface");
|
|
770
|
-
function isSurface(value) {
|
|
771
|
-
return value !== void 0;
|
|
772
|
-
}
|
|
773
|
-
__name(isSurface, "isSurface");
|
|
774
|
-
|
|
775
|
-
// src/ledger.ts
|
|
776
|
-
var LedgerClient = class {
|
|
777
|
-
static {
|
|
778
|
-
__name(this, "LedgerClient");
|
|
779
|
-
}
|
|
780
|
-
apiBase;
|
|
781
|
-
transport;
|
|
782
|
-
constructor(apiBase, transport) {
|
|
783
|
-
this.apiBase = apiBase;
|
|
784
|
-
this.transport = transport;
|
|
785
|
-
}
|
|
786
|
-
/** Posted / pending / available balance for the token's account. */
|
|
787
|
-
async getBalance(auth) {
|
|
788
|
-
const raw = await this.transport.request({
|
|
789
|
-
method: "GET",
|
|
790
|
-
url: `${this.apiBase}/api/v2/ledger/balance`,
|
|
791
|
-
...authorizationArgs(auth)
|
|
792
|
-
});
|
|
793
|
-
return parse(balanceSchema, raw);
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* Record a usage event (the meter). Idempotent on `transactionId`; a duplicate
|
|
797
|
-
* returns `{ duplicate: true }` and does not charge again.
|
|
798
|
-
*/
|
|
799
|
-
async recordUsage(auth, event) {
|
|
800
|
-
const e = usageEventSchema.parse(event);
|
|
801
|
-
const raw = await this.transport.request({
|
|
802
|
-
method: "POST",
|
|
803
|
-
url: `${this.apiBase}/api/v2/ledger/usage`,
|
|
804
|
-
...authorizationArgs(auth),
|
|
805
|
-
body: e,
|
|
806
|
-
idempotencyKey: e.transactionId
|
|
807
|
-
});
|
|
808
|
-
return parse(usageResultSchema, raw);
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Reserve credits for a per-use action (phase 1 of two-phase spend). Rejected
|
|
812
|
-
* with `INSUFFICIENT_CREDITS` if `available < amount`. Idempotent on `holdId`.
|
|
813
|
-
*/
|
|
814
|
-
async hold(auth, req) {
|
|
815
|
-
const r = holdRequestSchema.parse(req);
|
|
816
|
-
const raw = await this.transport.request({
|
|
817
|
-
method: "POST",
|
|
818
|
-
url: `${this.apiBase}/api/v2/ledger/holds`,
|
|
819
|
-
...authorizationArgs(auth),
|
|
820
|
-
body: r,
|
|
821
|
-
idempotencyKey: r.holdId
|
|
822
|
-
});
|
|
823
|
-
return parse(holdSchema, raw);
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Settle a hold for the actual cost (phase 2). Posting less than the held
|
|
827
|
-
* amount auto-restores the remainder. Idempotent on `holdId`.
|
|
828
|
-
*/
|
|
829
|
-
async settle(auth, holdId, actualCostMicro) {
|
|
830
|
-
const raw = await this.transport.request({
|
|
831
|
-
method: "POST",
|
|
832
|
-
url: `${this.apiBase}/api/v2/ledger/holds/${encodeURIComponent(holdId)}/settle`,
|
|
833
|
-
...authorizationArgs(auth),
|
|
834
|
-
body: {
|
|
835
|
-
actualCostMicro
|
|
836
|
-
},
|
|
837
|
-
idempotencyKey: `${holdId}:settle`
|
|
838
|
-
});
|
|
839
|
-
return parse(holdSchema, raw);
|
|
840
|
-
}
|
|
841
|
-
/** Release a hold without charging (failure/cancel). Idempotent on `holdId`. */
|
|
842
|
-
async void(auth, holdId) {
|
|
843
|
-
const raw = await this.transport.request({
|
|
844
|
-
method: "POST",
|
|
845
|
-
url: `${this.apiBase}/api/v2/ledger/holds/${encodeURIComponent(holdId)}/void`,
|
|
846
|
-
...authorizationArgs(auth),
|
|
847
|
-
body: {},
|
|
848
|
-
idempotencyKey: `${holdId}:void`
|
|
849
|
-
});
|
|
850
|
-
return parse(holdSchema, raw);
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
function parse(schema, raw) {
|
|
854
|
-
const r = schema.safeParse(raw);
|
|
855
|
-
if (!r.success || r.data === void 0) {
|
|
856
|
-
throw new AccountError({
|
|
857
|
-
code: "INVALID_RESPONSE",
|
|
858
|
-
message: "ledger returned an unrecognised shape"
|
|
859
|
-
});
|
|
860
|
-
}
|
|
861
|
-
return r.data;
|
|
862
|
-
}
|
|
863
|
-
__name(parse, "parse");
|
|
864
|
-
|
|
865
|
-
// src/authz.ts
|
|
866
|
-
var AuthzClient = class {
|
|
867
|
-
static {
|
|
868
|
-
__name(this, "AuthzClient");
|
|
869
|
-
}
|
|
870
|
-
apiBase;
|
|
871
|
-
transport;
|
|
872
|
-
constructor(apiBase, transport) {
|
|
873
|
-
this.apiBase = apiBase;
|
|
874
|
-
this.transport = transport;
|
|
875
|
-
}
|
|
876
|
-
async check(auth, check) {
|
|
877
|
-
const raw = await this.transport.request({
|
|
878
|
-
method: "POST",
|
|
879
|
-
url: `${this.apiBase}/api/v2/authz/check`,
|
|
880
|
-
...authorizationArgs(auth),
|
|
881
|
-
body: check
|
|
882
|
-
});
|
|
883
|
-
const parsed = authzResultSchema.safeParse(raw);
|
|
884
|
-
if (!parsed.success) {
|
|
885
|
-
throw new AccountError({
|
|
886
|
-
code: "INVALID_RESPONSE",
|
|
887
|
-
message: "authz returned an unrecognised shape"
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
return parsed.data;
|
|
891
|
-
}
|
|
892
|
-
};
|
|
893
|
-
|
|
894
|
-
// src/workspaces.ts
|
|
895
|
-
var import_zod3 = require("zod");
|
|
896
|
-
|
|
897
|
-
// src/workspaceMembership.ts
|
|
898
|
-
var import_zod2 = require("zod");
|
|
899
|
-
var id = import_zod2.z.string().uuid();
|
|
900
|
-
var timestamp = import_zod2.z.string().datetime({
|
|
901
|
-
offset: true
|
|
902
|
-
});
|
|
903
|
-
var role = import_zod2.z.enum([
|
|
904
|
-
"admin",
|
|
905
|
-
"member",
|
|
906
|
-
"viewer"
|
|
907
|
-
]);
|
|
908
|
-
var membershipMutationSchema = import_zod2.z.discriminatedUnion("action", [
|
|
909
|
-
import_zod2.z.object({
|
|
910
|
-
action: import_zod2.z.literal("invite.create"),
|
|
911
|
-
email: import_zod2.z.string().email().max(320).regex(/^[^\x00-\x20\x7f]+$/),
|
|
912
|
-
role
|
|
913
|
-
}).strict(),
|
|
914
|
-
import_zod2.z.object({
|
|
915
|
-
action: import_zod2.z.literal("invite.revoke"),
|
|
916
|
-
inviteId: id
|
|
917
|
-
}).strict(),
|
|
918
|
-
import_zod2.z.object({
|
|
919
|
-
action: import_zod2.z.literal("invite.resend"),
|
|
920
|
-
inviteId: id
|
|
921
|
-
}).strict(),
|
|
922
|
-
import_zod2.z.object({
|
|
923
|
-
action: import_zod2.z.literal("member.role"),
|
|
924
|
-
memberId: id,
|
|
925
|
-
role
|
|
926
|
-
}).strict(),
|
|
927
|
-
import_zod2.z.object({
|
|
928
|
-
action: import_zod2.z.literal("member.remove"),
|
|
929
|
-
memberId: id
|
|
930
|
-
}).strict(),
|
|
931
|
-
import_zod2.z.object({
|
|
932
|
-
action: import_zod2.z.literal("owner.transfer"),
|
|
933
|
-
newOwnerId: id
|
|
934
|
-
}).strict()
|
|
935
|
-
]);
|
|
936
|
-
var base = {
|
|
937
|
-
operation_id: id,
|
|
938
|
-
workspace_id: id,
|
|
939
|
-
actor_user_id: id,
|
|
940
|
-
client_id: import_zod2.z.string().regex(/^[a-zA-Z0-9._-]{1,128}$/),
|
|
941
|
-
committed_at: timestamp
|
|
942
|
-
};
|
|
943
|
-
var invite = import_zod2.z.object({
|
|
944
|
-
id,
|
|
945
|
-
workspace_id: id,
|
|
946
|
-
invited_email: import_zod2.z.string().email(),
|
|
947
|
-
role,
|
|
948
|
-
status: import_zod2.z.enum([
|
|
949
|
-
"pending",
|
|
950
|
-
"revoked"
|
|
951
|
-
]),
|
|
952
|
-
expires_at: timestamp
|
|
953
|
-
}).strict();
|
|
954
|
-
var delivery = import_zod2.z.object({
|
|
955
|
-
id,
|
|
956
|
-
state: import_zod2.z.literal("queued")
|
|
957
|
-
}).strict();
|
|
958
|
-
var membershipCommittedSchema = import_zod2.z.discriminatedUnion("action", [
|
|
959
|
-
import_zod2.z.object({
|
|
960
|
-
...base,
|
|
961
|
-
action: import_zod2.z.literal("invite.create"),
|
|
962
|
-
result: import_zod2.z.object({
|
|
963
|
-
invite,
|
|
964
|
-
delivery
|
|
965
|
-
}).strict()
|
|
966
|
-
}).strict(),
|
|
967
|
-
import_zod2.z.object({
|
|
968
|
-
...base,
|
|
969
|
-
action: import_zod2.z.literal("invite.resend"),
|
|
970
|
-
result: import_zod2.z.object({
|
|
971
|
-
invite,
|
|
972
|
-
delivery
|
|
973
|
-
}).strict()
|
|
974
|
-
}).strict(),
|
|
975
|
-
import_zod2.z.object({
|
|
976
|
-
...base,
|
|
977
|
-
action: import_zod2.z.literal("invite.revoke"),
|
|
978
|
-
result: import_zod2.z.object({
|
|
979
|
-
invite
|
|
980
|
-
}).strict()
|
|
981
|
-
}).strict(),
|
|
982
|
-
import_zod2.z.object({
|
|
983
|
-
...base,
|
|
984
|
-
action: import_zod2.z.literal("member.role"),
|
|
985
|
-
result: import_zod2.z.object({
|
|
986
|
-
memberId: id,
|
|
987
|
-
role
|
|
988
|
-
}).strict()
|
|
989
|
-
}).strict(),
|
|
990
|
-
import_zod2.z.object({
|
|
991
|
-
...base,
|
|
992
|
-
action: import_zod2.z.literal("member.remove"),
|
|
993
|
-
result: import_zod2.z.object({
|
|
994
|
-
memberId: id
|
|
995
|
-
}).strict()
|
|
996
|
-
}).strict(),
|
|
997
|
-
import_zod2.z.object({
|
|
998
|
-
...base,
|
|
999
|
-
action: import_zod2.z.literal("owner.transfer"),
|
|
1000
|
-
result: import_zod2.z.object({
|
|
1001
|
-
memberId: id,
|
|
1002
|
-
previousOwnerId: id
|
|
1003
|
-
}).strict()
|
|
1004
|
-
}).strict()
|
|
1005
|
-
]);
|
|
1006
|
-
var membershipRejectedSchema = import_zod2.z.object({
|
|
1007
|
-
...base,
|
|
1008
|
-
action: import_zod2.z.enum([
|
|
1009
|
-
"invite.create",
|
|
1010
|
-
"invite.resend",
|
|
1011
|
-
"invite.revoke",
|
|
1012
|
-
"member.role",
|
|
1013
|
-
"member.remove",
|
|
1014
|
-
"owner.transfer"
|
|
1015
|
-
]),
|
|
1016
|
-
rejection: import_zod2.z.enum([
|
|
1017
|
-
"invalid_membership_request",
|
|
1018
|
-
"member_not_found",
|
|
1019
|
-
"owner_transfer_required",
|
|
1020
|
-
"owner_target_not_member",
|
|
1021
|
-
"invite_not_found",
|
|
1022
|
-
"invite_already_pending",
|
|
1023
|
-
"already_member",
|
|
1024
|
-
"seat_limit"
|
|
1025
|
-
])
|
|
1026
|
-
}).strict();
|
|
1027
|
-
var membershipAbandonedSchema = membershipRejectedSchema.omit({
|
|
1028
|
-
rejection: true
|
|
1029
|
-
}).extend({
|
|
1030
|
-
abandoned: import_zod2.z.literal(true),
|
|
1031
|
-
request: membershipMutationSchema
|
|
1032
|
-
}).strict();
|
|
1033
|
-
var membershipOperationSchema = import_zod2.z.union([
|
|
1034
|
-
membershipCommittedSchema,
|
|
1035
|
-
membershipRejectedSchema,
|
|
1036
|
-
membershipAbandonedSchema
|
|
1037
|
-
]);
|
|
1038
|
-
var membershipDeliverySchema = import_zod2.z.object({
|
|
1039
|
-
id,
|
|
1040
|
-
state: import_zod2.z.enum([
|
|
1041
|
-
"queued",
|
|
1042
|
-
"accepted",
|
|
1043
|
-
"skipped",
|
|
1044
|
-
"unknown"
|
|
1045
|
-
])
|
|
1046
|
-
}).strict();
|
|
1047
|
-
var WorkspaceMembershipMutationError = class extends AccountError {
|
|
1048
|
-
static {
|
|
1049
|
-
__name(this, "WorkspaceMembershipMutationError");
|
|
1050
|
-
}
|
|
1051
|
-
operationId;
|
|
1052
|
-
outcome = "uncertain";
|
|
1053
|
-
constructor(operationId) {
|
|
1054
|
-
super({
|
|
1055
|
-
code: "PLATFORM_ERROR",
|
|
1056
|
-
message: "Workspace membership acknowledgement is uncertain. Read back the same operation.",
|
|
1057
|
-
retryable: false
|
|
1058
|
-
}), this.operationId = operationId;
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
function assertMembershipOperation(workspaceId, operationId, operation3, request) {
|
|
1062
|
-
if (operation3.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || operation3.operation_id.toLowerCase() !== operationId.toLowerCase() || request && operation3.action !== request.action) throw new Error("Foreign membership receipt");
|
|
1063
|
-
if ("rejection" in operation3) return;
|
|
1064
|
-
if ("abandoned" in operation3) {
|
|
1065
|
-
if (operation3.request.action !== operation3.action || request && JSON.stringify(membershipMutationSchema.parse(request)) !== JSON.stringify(operation3.request)) throw new Error("Wrong abandoned membership intent");
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
if (operation3.action.startsWith("invite.")) {
|
|
1069
|
-
if (!("invite" in operation3.result) || operation3.result.invite.workspace_id !== operation3.workspace_id || operation3.result.invite.status !== (operation3.action === "invite.revoke" ? "revoked" : "pending")) throw new Error("Foreign invitation receipt");
|
|
1070
|
-
if (request && "inviteId" in request && operation3.result.invite.id !== request.inviteId) throw new Error("Wrong invitation target");
|
|
1071
|
-
if (request?.action === "invite.create" && (operation3.result.invite.invited_email !== request.email.toLowerCase() || operation3.result.invite.role !== request.role)) throw new Error("Wrong invitation intent");
|
|
1072
|
-
} else if ("memberId" in operation3.result) {
|
|
1073
|
-
if (request && "memberId" in request && operation3.result.memberId !== request.memberId) throw new Error("Wrong member target");
|
|
1074
|
-
if (request?.action === "member.role" && (!("role" in operation3.result) || operation3.result.role !== request.role)) throw new Error("Wrong member role");
|
|
1075
|
-
if (operation3.action === "owner.transfer" && (operation3.result.previousOwnerId !== operation3.actor_user_id || request?.action === "owner.transfer" && operation3.result.memberId !== request.newOwnerId)) throw new Error("Wrong owner target");
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
__name(assertMembershipOperation, "assertMembershipOperation");
|
|
1079
|
-
|
|
1080
|
-
// src/workspaces.ts
|
|
1081
|
-
var workspaceRoleSchema = import_zod3.z.enum([
|
|
1082
|
-
"owner",
|
|
1083
|
-
"admin",
|
|
1084
|
-
"member",
|
|
1085
|
-
"viewer"
|
|
1086
|
-
]);
|
|
1087
|
-
var workspaceInviteRoleSchema = import_zod3.z.enum([
|
|
1088
|
-
"admin",
|
|
1089
|
-
"member",
|
|
1090
|
-
"viewer"
|
|
1091
|
-
]);
|
|
1092
|
-
var id2 = import_zod3.z.string().uuid();
|
|
1093
|
-
var timestamp2 = import_zod3.z.string().datetime({
|
|
1094
|
-
offset: true
|
|
1095
|
-
});
|
|
1096
|
-
var workspaceSchema = import_zod3.z.object({
|
|
1097
|
-
id: id2,
|
|
1098
|
-
owner_user_id: id2,
|
|
1099
|
-
workspace_type: import_zod3.z.enum([
|
|
1100
|
-
"personal",
|
|
1101
|
-
"team"
|
|
1102
|
-
]),
|
|
1103
|
-
name: import_zod3.z.string().min(1),
|
|
1104
|
-
slug: import_zod3.z.string().min(1),
|
|
1105
|
-
status: import_zod3.z.string().min(1),
|
|
1106
|
-
created_at: timestamp2,
|
|
1107
|
-
updated_at: timestamp2,
|
|
1108
|
-
metadata: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()),
|
|
1109
|
-
member_role: workspaceRoleSchema.optional(),
|
|
1110
|
-
member_count: import_zod3.z.number().int().nonnegative().optional()
|
|
1111
|
-
});
|
|
1112
|
-
var workspaceMemberSchema = import_zod3.z.object({
|
|
1113
|
-
id: id2,
|
|
1114
|
-
user_id: id2,
|
|
1115
|
-
member_role: workspaceRoleSchema,
|
|
1116
|
-
member_status: import_zod3.z.literal("active"),
|
|
1117
|
-
created_at: timestamp2,
|
|
1118
|
-
user: import_zod3.z.object({
|
|
1119
|
-
username: import_zod3.z.string().nullable(),
|
|
1120
|
-
email: import_zod3.z.string().email(),
|
|
1121
|
-
display_name: import_zod3.z.string().nullable(),
|
|
1122
|
-
avatar_url: import_zod3.z.string().url().nullable()
|
|
1123
|
-
}).optional()
|
|
1124
|
-
});
|
|
1125
|
-
var workspaceInviteSchema = import_zod3.z.object({
|
|
1126
|
-
id: id2,
|
|
1127
|
-
workspace_id: id2,
|
|
1128
|
-
invited_by_user_id: id2,
|
|
1129
|
-
invited_user_id: id2.nullable(),
|
|
1130
|
-
invited_email: import_zod3.z.string().email(),
|
|
1131
|
-
role: workspaceInviteRoleSchema,
|
|
1132
|
-
status: import_zod3.z.enum([
|
|
1133
|
-
"pending",
|
|
1134
|
-
"accepted",
|
|
1135
|
-
"declined",
|
|
1136
|
-
"revoked",
|
|
1137
|
-
"expired"
|
|
1138
|
-
]),
|
|
1139
|
-
created_at: timestamp2,
|
|
1140
|
-
expires_at: timestamp2.nullable(),
|
|
1141
|
-
workspace_name: import_zod3.z.string().optional(),
|
|
1142
|
-
invited_by_name: import_zod3.z.string().nullable().optional()
|
|
1143
|
-
});
|
|
1144
|
-
var accountOperationIntentSchema = import_zod3.z.discriminatedUnion("action", [
|
|
1145
|
-
import_zod3.z.object({
|
|
1146
|
-
action: import_zod3.z.literal("workspace.create"),
|
|
1147
|
-
name: import_zod3.z.string().trim().min(1).max(128),
|
|
1148
|
-
type: import_zod3.z.literal("team")
|
|
1149
|
-
}).strict(),
|
|
1150
|
-
import_zod3.z.object({
|
|
1151
|
-
action: import_zod3.z.literal("invite.accept"),
|
|
1152
|
-
inviteId: id2
|
|
1153
|
-
}).strict(),
|
|
1154
|
-
import_zod3.z.object({
|
|
1155
|
-
action: import_zod3.z.literal("invite.decline"),
|
|
1156
|
-
inviteId: id2
|
|
1157
|
-
}).strict()
|
|
1158
|
-
]);
|
|
1159
|
-
var accountOperationSchema = import_zod3.z.object({
|
|
1160
|
-
operation_id: id2,
|
|
1161
|
-
actor_user_id: id2,
|
|
1162
|
-
client_id: import_zod3.z.string().regex(/^[a-zA-Z0-9._-]{1,128}$/),
|
|
1163
|
-
action: import_zod3.z.enum([
|
|
1164
|
-
"workspace.create",
|
|
1165
|
-
"invite.accept",
|
|
1166
|
-
"invite.decline"
|
|
1167
|
-
]),
|
|
1168
|
-
committed_at: timestamp2,
|
|
1169
|
-
result: import_zod3.z.union([
|
|
1170
|
-
import_zod3.z.object({
|
|
1171
|
-
workspace: workspaceSchema
|
|
1172
|
-
}).strict(),
|
|
1173
|
-
import_zod3.z.object({
|
|
1174
|
-
invite: workspaceInviteSchema
|
|
1175
|
-
}).strict()
|
|
1176
|
-
])
|
|
1177
|
-
}).strict();
|
|
1178
|
-
var AccountMutationError = class extends AccountError {
|
|
1179
|
-
static {
|
|
1180
|
-
__name(this, "AccountMutationError");
|
|
1181
|
-
}
|
|
1182
|
-
operationId;
|
|
1183
|
-
outcome = "uncertain";
|
|
1184
|
-
constructor(operationId) {
|
|
1185
|
-
super({
|
|
1186
|
-
code: "PLATFORM_ERROR",
|
|
1187
|
-
message: "Account mutation acknowledgement is uncertain. Read back the same operation.",
|
|
1188
|
-
retryable: false
|
|
1189
|
-
}), this.operationId = operationId;
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
var workspaceKeyScopeSchema = import_zod3.z.enum([
|
|
1193
|
-
"workspace:read",
|
|
1194
|
-
"workspace:members:read"
|
|
1195
|
-
]);
|
|
1196
|
-
var keyScopes = import_zod3.z.array(workspaceKeyScopeSchema).min(1).max(2).refine((values) => new Set(values).size === values.length);
|
|
1197
|
-
var workspaceKeySchema = import_zod3.z.object({
|
|
1198
|
-
id: id2,
|
|
1199
|
-
workspace_id: id2,
|
|
1200
|
-
created_by_user_id: id2,
|
|
1201
|
-
name: import_zod3.z.string().min(1).max(100),
|
|
1202
|
-
prefix: import_zod3.z.string().regex(/^xeno-ws-v1_[0-9a-f]{13}$/),
|
|
1203
|
-
scopes: keyScopes,
|
|
1204
|
-
revision: import_zod3.z.number().int().positive(),
|
|
1205
|
-
created_at: timestamp2,
|
|
1206
|
-
expires_at: timestamp2,
|
|
1207
|
-
revoked_at: timestamp2.nullable(),
|
|
1208
|
-
replaced_by: id2.nullable()
|
|
1209
|
-
});
|
|
1210
|
-
var workspaceKeyInputSchema = import_zod3.z.object({
|
|
1211
|
-
name: import_zod3.z.string().trim().min(1).max(100).regex(/^[^\x00-\x1f]+$/),
|
|
1212
|
-
scopes: keyScopes,
|
|
1213
|
-
expires_at: timestamp2.refine((value) => Date.parse(value) > Date.now() && Date.parse(value) <= Date.now() + 90 * 864e5)
|
|
1214
|
-
}).strict();
|
|
1215
|
-
var keySecretSchema = import_zod3.z.string().regex(/^xeno-ws-v1_[0-9a-f]{64}$/);
|
|
1216
|
-
var committedKeyOperationSchema = import_zod3.z.object({
|
|
1217
|
-
operation_id: id2,
|
|
1218
|
-
workspace_id: id2,
|
|
1219
|
-
actor_user_id: id2,
|
|
1220
|
-
client_id: import_zod3.z.string().regex(/^[a-zA-Z0-9._-]{1,128}$/),
|
|
1221
|
-
action: import_zod3.z.enum([
|
|
1222
|
-
"create",
|
|
1223
|
-
"rotate",
|
|
1224
|
-
"revoke"
|
|
1225
|
-
]),
|
|
1226
|
-
key: workspaceKeySchema,
|
|
1227
|
-
previous_key_id: id2.nullable(),
|
|
1228
|
-
committed_at: timestamp2
|
|
1229
|
-
}).strict();
|
|
1230
|
-
var workspaceKeyRejectionSchema = import_zod3.z.enum([
|
|
1231
|
-
"invalid_workspace_key_request",
|
|
1232
|
-
"invalid_workspace_key_revision",
|
|
1233
|
-
"workspace_key_not_found",
|
|
1234
|
-
"workspace_key_conflict"
|
|
1235
|
-
]);
|
|
1236
|
-
var rejectedKeyOperationSchema = committedKeyOperationSchema.omit({
|
|
1237
|
-
key: true
|
|
1238
|
-
}).extend({
|
|
1239
|
-
rejection: workspaceKeyRejectionSchema
|
|
1240
|
-
}).strict();
|
|
1241
|
-
var abandonedKeyOperationSchema = committedKeyOperationSchema.omit({
|
|
1242
|
-
key: true
|
|
1243
|
-
}).extend({
|
|
1244
|
-
abandoned: import_zod3.z.literal(true)
|
|
1245
|
-
}).strict();
|
|
1246
|
-
var workspaceKeyOperationSchema = import_zod3.z.union([
|
|
1247
|
-
committedKeyOperationSchema,
|
|
1248
|
-
rejectedKeyOperationSchema,
|
|
1249
|
-
abandonedKeyOperationSchema
|
|
1250
|
-
]);
|
|
1251
|
-
var keyOperationInput = workspaceKeyInputSchema.extend({
|
|
1252
|
-
expires_at: timestamp2
|
|
1253
|
-
});
|
|
1254
|
-
var keyMutationSchema = import_zod3.z.discriminatedUnion("action", [
|
|
1255
|
-
import_zod3.z.object({
|
|
1256
|
-
action: import_zod3.z.literal("create"),
|
|
1257
|
-
input: keyOperationInput
|
|
1258
|
-
}).strict(),
|
|
1259
|
-
import_zod3.z.object({
|
|
1260
|
-
action: import_zod3.z.literal("rotate"),
|
|
1261
|
-
keyId: id2,
|
|
1262
|
-
expectedRevision: import_zod3.z.number().int().positive(),
|
|
1263
|
-
input: keyOperationInput.partial().optional()
|
|
1264
|
-
}).strict(),
|
|
1265
|
-
import_zod3.z.object({
|
|
1266
|
-
action: import_zod3.z.literal("revoke"),
|
|
1267
|
-
keyId: id2,
|
|
1268
|
-
expectedRevision: import_zod3.z.number().int().positive()
|
|
1269
|
-
}).strict()
|
|
1270
|
-
]);
|
|
1271
|
-
var WorkspaceKeyMutationError = class extends AccountError {
|
|
1272
|
-
static {
|
|
1273
|
-
__name(this, "WorkspaceKeyMutationError");
|
|
1274
|
-
}
|
|
1275
|
-
operationId;
|
|
1276
|
-
outcome = "uncertain";
|
|
1277
|
-
constructor(operationId) {
|
|
1278
|
-
super({
|
|
1279
|
-
code: "PLATFORM_ERROR",
|
|
1280
|
-
message: "Workspace key mutation acknowledgement is uncertain. Read back the same operation.",
|
|
1281
|
-
retryable: false
|
|
1282
|
-
}), this.operationId = operationId;
|
|
1283
|
-
}
|
|
1284
|
-
};
|
|
1285
|
-
var workspaceKeyCursor = import_zod3.z.string().regex(/^[a-z0-9_-]{1,512}$/i);
|
|
1286
|
-
var success = import_zod3.z.object({
|
|
1287
|
-
success: import_zod3.z.literal(true)
|
|
1288
|
-
});
|
|
1289
|
-
var membersResponse = success.extend({
|
|
1290
|
-
workspace: workspaceSchema,
|
|
1291
|
-
members: import_zod3.z.array(workspaceMemberSchema)
|
|
1292
|
-
});
|
|
1293
|
-
var invitesResponse = success.extend({
|
|
1294
|
-
invites: import_zod3.z.array(workspaceInviteSchema)
|
|
1295
|
-
});
|
|
1296
|
-
var WorkspaceClient = class {
|
|
1297
|
-
static {
|
|
1298
|
-
__name(this, "WorkspaceClient");
|
|
1299
|
-
}
|
|
1300
|
-
transport;
|
|
1301
|
-
authorize;
|
|
1302
|
-
base;
|
|
1303
|
-
constructor(base2, transport, authorize) {
|
|
1304
|
-
this.transport = transport;
|
|
1305
|
-
this.authorize = authorize;
|
|
1306
|
-
const origin = new URL(base2);
|
|
1307
|
-
if (origin.protocol !== "https:" || origin.username || origin.password || origin.search || origin.hash || origin.pathname !== "/") {
|
|
1308
|
-
throw new AccountError({
|
|
1309
|
-
code: "BAD_REQUEST",
|
|
1310
|
-
message: "Workspace API requires an HTTPS origin."
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
this.base = origin.origin;
|
|
1314
|
-
}
|
|
1315
|
-
async call(method, path, scope, schema, body, idempotencyKey) {
|
|
1316
|
-
const url = `${this.base}/api${path}`;
|
|
1317
|
-
const raw = await this.transport.request({
|
|
1318
|
-
method,
|
|
1319
|
-
url,
|
|
1320
|
-
...body === void 0 ? {} : {
|
|
1321
|
-
body
|
|
1322
|
-
},
|
|
1323
|
-
...idempotencyKey ? {
|
|
1324
|
-
idempotencyKey
|
|
1325
|
-
} : {},
|
|
1326
|
-
authorization: /* @__PURE__ */ __name(async () => {
|
|
1327
|
-
const auth = await this.authorize(method, url, {
|
|
1328
|
-
scopes: [
|
|
1329
|
-
scope
|
|
1330
|
-
],
|
|
1331
|
-
silent: true
|
|
1332
|
-
});
|
|
1333
|
-
if (!auth) throw new AccountError({
|
|
1334
|
-
code: "INVALID_TOKEN",
|
|
1335
|
-
message: "Sign in to manage workspaces."
|
|
1336
|
-
});
|
|
1337
|
-
return auth;
|
|
1338
|
-
}, "authorization")
|
|
1339
|
-
});
|
|
1340
|
-
const parsed = schema.safeParse(raw);
|
|
1341
|
-
if (!parsed.success) throw new AccountError({
|
|
1342
|
-
code: "INVALID_RESPONSE",
|
|
1343
|
-
message: "Invalid workspace response."
|
|
1344
|
-
});
|
|
1345
|
-
return parsed.data;
|
|
1346
|
-
}
|
|
1347
|
-
async list() {
|
|
1348
|
-
return (await this.call("GET", "/workspaces", "team:read", success.extend({
|
|
1349
|
-
workspaces: import_zod3.z.array(workspaceSchema)
|
|
1350
|
-
}))).workspaces;
|
|
1351
|
-
}
|
|
1352
|
-
async keys(workspaceId, options = {}) {
|
|
1353
|
-
const input = import_zod3.z.object({
|
|
1354
|
-
cursor: workspaceKeyCursor.optional(),
|
|
1355
|
-
limit: import_zod3.z.number().int().min(1).max(200).optional()
|
|
1356
|
-
}).strict().parse(options);
|
|
1357
|
-
const query = new URLSearchParams();
|
|
1358
|
-
if (input.cursor !== void 0) query.set("cursor", input.cursor);
|
|
1359
|
-
if (input.limit !== void 0) query.set("limit", String(input.limit));
|
|
1360
|
-
const result = await this.call("GET", `/workspaces/${id2.parse(workspaceId)}/api-keys${query.size ? `?${query}` : ""}`, "team:manage", success.extend({
|
|
1361
|
-
keys: import_zod3.z.array(workspaceKeySchema).max(200),
|
|
1362
|
-
next_cursor: workspaceKeyCursor.nullable()
|
|
1363
|
-
}));
|
|
1364
|
-
const { keys, next_cursor } = result;
|
|
1365
|
-
if (keys.some((key) => key.workspace_id.toLowerCase() !== workspaceId.toLowerCase())) throw new AccountError({
|
|
1366
|
-
code: "INVALID_RESPONSE",
|
|
1367
|
-
message: "Workspace key response belongs to another workspace."
|
|
1368
|
-
});
|
|
1369
|
-
return {
|
|
1370
|
-
keys,
|
|
1371
|
-
next_cursor
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
|
-
async createKey(workspaceId, input) {
|
|
1375
|
-
const body = workspaceKeyInputSchema.parse(input);
|
|
1376
|
-
const response = await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/api-keys`, "team:manage", success.extend({
|
|
1377
|
-
key: workspaceKeySchema,
|
|
1378
|
-
secret: keySecretSchema
|
|
1379
|
-
}), body);
|
|
1380
|
-
this.assertKeyReceipt(workspaceId, response.key);
|
|
1381
|
-
return {
|
|
1382
|
-
key: response.key,
|
|
1383
|
-
secret: response.secret
|
|
1384
|
-
};
|
|
1385
|
-
}
|
|
1386
|
-
async keyOperation(workspaceId, operationId) {
|
|
1387
|
-
const workspace = id2.parse(workspaceId), operation3 = id2.parse(operationId);
|
|
1388
|
-
const response = await this.call("GET", `/workspaces/${workspace}/api-keys/operations/${operation3}`, "team:manage", import_zod3.z.discriminatedUnion("state", [
|
|
1389
|
-
import_zod3.z.object({
|
|
1390
|
-
success: import_zod3.z.literal(true),
|
|
1391
|
-
state: import_zod3.z.literal("not-observed"),
|
|
1392
|
-
operation: import_zod3.z.null()
|
|
1393
|
-
}).strict(),
|
|
1394
|
-
import_zod3.z.object({
|
|
1395
|
-
success: import_zod3.z.literal(true),
|
|
1396
|
-
state: import_zod3.z.literal("committed"),
|
|
1397
|
-
operation: committedKeyOperationSchema
|
|
1398
|
-
}).strict(),
|
|
1399
|
-
import_zod3.z.object({
|
|
1400
|
-
success: import_zod3.z.literal(true),
|
|
1401
|
-
state: import_zod3.z.literal("rejected"),
|
|
1402
|
-
operation: rejectedKeyOperationSchema
|
|
1403
|
-
}).strict(),
|
|
1404
|
-
import_zod3.z.object({
|
|
1405
|
-
success: import_zod3.z.literal(true),
|
|
1406
|
-
state: import_zod3.z.literal("abandoned"),
|
|
1407
|
-
operation: abandonedKeyOperationSchema
|
|
1408
|
-
}).strict()
|
|
1409
|
-
]));
|
|
1410
|
-
if (response.state === "not-observed") return {
|
|
1411
|
-
state: response.state,
|
|
1412
|
-
operation: null
|
|
1413
|
-
};
|
|
1414
|
-
this.assertOperation(workspace, operation3, response.operation);
|
|
1415
|
-
if (response.state === "abandoned") return {
|
|
1416
|
-
state: response.state,
|
|
1417
|
-
operation: response.operation
|
|
1418
|
-
};
|
|
1419
|
-
return response.state === "rejected" ? {
|
|
1420
|
-
state: response.state,
|
|
1421
|
-
operation: response.operation
|
|
1422
|
-
} : {
|
|
1423
|
-
state: response.state,
|
|
1424
|
-
operation: response.operation
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
async mutateKey(workspaceId, operationId, request) {
|
|
1428
|
-
const workspace = id2.parse(workspaceId), operation3 = id2.parse(operationId), input = keyMutationSchema.parse(request);
|
|
1429
|
-
const path = `/workspaces/${workspace}/api-keys${input.action === "create" ? "" : `/${input.keyId}${input.action === "rotate" ? "/rotate" : ""}`}`;
|
|
1430
|
-
const body = {
|
|
1431
|
-
...input.action === "revoke" ? {} : input.input,
|
|
1432
|
-
operation_id: operation3,
|
|
1433
|
-
...input.action === "create" ? {} : {
|
|
1434
|
-
expected_revision: input.expectedRevision
|
|
1435
|
-
}
|
|
1436
|
-
};
|
|
1437
|
-
try {
|
|
1438
|
-
const response = await this.call(input.action === "revoke" ? "DELETE" : "POST", path, "team:manage", import_zod3.z.object({
|
|
1439
|
-
success: import_zod3.z.literal(true),
|
|
1440
|
-
key: workspaceKeySchema.optional(),
|
|
1441
|
-
operation: workspaceKeyOperationSchema,
|
|
1442
|
-
replayed: import_zod3.z.boolean(),
|
|
1443
|
-
secret: keySecretSchema.optional()
|
|
1444
|
-
}).strict(), body);
|
|
1445
|
-
this.assertOperation(workspace, operation3, response.operation);
|
|
1446
|
-
if ("rejection" in response.operation || "abandoned" in response.operation) {
|
|
1447
|
-
if (response.key !== void 0 || response.secret !== void 0 || response.operation.action !== input.action || response.operation.previous_key_id?.toLowerCase() !== (input.action === "create" ? void 0 : input.keyId.toLowerCase())) throw new Error("Invalid rejection receipt");
|
|
1448
|
-
return {
|
|
1449
|
-
operation: response.operation,
|
|
1450
|
-
replayed: response.replayed
|
|
1451
|
-
};
|
|
1452
|
-
}
|
|
1453
|
-
if (!response.key) throw new Error("Missing key");
|
|
1454
|
-
if (response.operation.action !== input.action || JSON.stringify(response.key) !== JSON.stringify(response.operation.key) || response.operation.previous_key_id?.toLowerCase() !== (input.action === "create" ? void 0 : input.keyId.toLowerCase()) || (response.replayed || input.action === "revoke" ? response.secret !== void 0 : response.secret === void 0) || response.secret !== void 0 && !response.secret.startsWith(response.key.prefix)) throw new Error("Invalid receipt");
|
|
1455
|
-
if (input.action === "revoke") {
|
|
1456
|
-
if (response.key.id.toLowerCase() !== input.keyId.toLowerCase() || !response.key.revoked_at || response.key.revision !== input.expectedRevision + 1) throw new Error("Invalid revocation");
|
|
1457
|
-
} else {
|
|
1458
|
-
this.assertKeyReceipt(workspace, response.key);
|
|
1459
|
-
if (input.action === "rotate" && response.key.id.toLowerCase() === input.keyId.toLowerCase()) throw new Error("Invalid rotation");
|
|
1460
|
-
}
|
|
1461
|
-
return {
|
|
1462
|
-
operation: response.operation,
|
|
1463
|
-
replayed: response.replayed,
|
|
1464
|
-
...response.secret === void 0 ? {} : {
|
|
1465
|
-
secret: response.secret
|
|
1466
|
-
}
|
|
1467
|
-
};
|
|
1468
|
-
} catch {
|
|
1469
|
-
throw new WorkspaceKeyMutationError(operation3);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
assertOperation(workspaceId, operationId, operation3) {
|
|
1473
|
-
if (operation3.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || operation3.operation_id.toLowerCase() !== operationId.toLowerCase()) {
|
|
1474
|
-
throw new AccountError({
|
|
1475
|
-
code: "INVALID_RESPONSE",
|
|
1476
|
-
message: "Workspace operation response belongs to another authority."
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
if ("rejection" in operation3 || "abandoned" in operation3) return;
|
|
1480
|
-
if (operation3.key.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || operation3.key.created_by_user_id.toLowerCase() !== operation3.actor_user_id.toLowerCase() && operation3.action !== "revoke") throw new AccountError({
|
|
1481
|
-
code: "INVALID_RESPONSE",
|
|
1482
|
-
message: "Foreign key receipt."
|
|
1483
|
-
});
|
|
1484
|
-
if (operation3.action === "revoke" ? !operation3.key.revoked_at || operation3.key.revision < 2 || operation3.previous_key_id !== operation3.key.id : operation3.key.revoked_at !== null || operation3.key.replaced_by !== null || operation3.key.revision !== 1 || (operation3.action === "create" ? operation3.previous_key_id !== null : operation3.previous_key_id === null || operation3.previous_key_id === operation3.key.id)) {
|
|
1485
|
-
throw new AccountError({
|
|
1486
|
-
code: "INVALID_RESPONSE",
|
|
1487
|
-
message: "Invalid committed workspace key operation."
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
async rotateKey(workspaceId, keyId, expectedRevision, input = {}) {
|
|
1492
|
-
const body = {
|
|
1493
|
-
...workspaceKeyInputSchema.partial().parse(input),
|
|
1494
|
-
expected_revision: import_zod3.z.number().int().positive().parse(expectedRevision)
|
|
1495
|
-
};
|
|
1496
|
-
const response = await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/api-keys/${id2.parse(keyId)}/rotate`, "team:manage", success.extend({
|
|
1497
|
-
key: workspaceKeySchema,
|
|
1498
|
-
secret: keySecretSchema
|
|
1499
|
-
}), body);
|
|
1500
|
-
this.assertKeyReceipt(workspaceId, response.key);
|
|
1501
|
-
if (response.key.id.toLowerCase() === keyId.toLowerCase()) throw new AccountError({
|
|
1502
|
-
code: "INVALID_RESPONSE",
|
|
1503
|
-
message: "Rotation did not acknowledge a new key identity."
|
|
1504
|
-
});
|
|
1505
|
-
return {
|
|
1506
|
-
key: response.key,
|
|
1507
|
-
secret: response.secret
|
|
1508
|
-
};
|
|
1509
|
-
}
|
|
1510
|
-
async revokeKey(workspaceId, keyId, expectedRevision) {
|
|
1511
|
-
const key = (await this.call("DELETE", `/workspaces/${id2.parse(workspaceId)}/api-keys/${id2.parse(keyId)}`, "team:manage", success.extend({
|
|
1512
|
-
key: workspaceKeySchema
|
|
1513
|
-
}), {
|
|
1514
|
-
expected_revision: import_zod3.z.number().int().positive().parse(expectedRevision)
|
|
1515
|
-
})).key;
|
|
1516
|
-
if (key.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || key.id.toLowerCase() !== keyId.toLowerCase() || !key.revoked_at || key.revision !== expectedRevision + 1) throw new AccountError({
|
|
1517
|
-
code: "INVALID_RESPONSE",
|
|
1518
|
-
message: "Revocation was not acknowledged for the requested key revision."
|
|
1519
|
-
});
|
|
1520
|
-
return key;
|
|
1521
|
-
}
|
|
1522
|
-
assertKeyReceipt(workspaceId, key) {
|
|
1523
|
-
if (key.workspace_id.toLowerCase() !== workspaceId.toLowerCase() || key.revoked_at || key.replaced_by || key.revision !== 1) throw new AccountError({
|
|
1524
|
-
code: "INVALID_RESPONSE",
|
|
1525
|
-
message: "Invalid workspace key creation receipt."
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
|
-
async create(name, type = "team") {
|
|
1529
|
-
const body = import_zod3.z.object({
|
|
1530
|
-
name: import_zod3.z.string().trim().min(1).max(128),
|
|
1531
|
-
workspace_type: import_zod3.z.enum([
|
|
1532
|
-
"personal",
|
|
1533
|
-
"team"
|
|
1534
|
-
])
|
|
1535
|
-
}).parse({
|
|
1536
|
-
name,
|
|
1537
|
-
workspace_type: type
|
|
1538
|
-
});
|
|
1539
|
-
return (await this.call("POST", "/workspaces", "team:manage", success.extend({
|
|
1540
|
-
workspace: workspaceSchema
|
|
1541
|
-
}), body)).workspace;
|
|
1542
|
-
}
|
|
1543
|
-
async accountOperation(operationId) {
|
|
1544
|
-
const operation3 = id2.parse(operationId);
|
|
1545
|
-
const response = await this.call("GET", `/account-operations/${operation3}`, "team:manage", import_zod3.z.discriminatedUnion("state", [
|
|
1546
|
-
import_zod3.z.object({
|
|
1547
|
-
success: import_zod3.z.literal(true),
|
|
1548
|
-
state: import_zod3.z.literal("not-observed"),
|
|
1549
|
-
operation: import_zod3.z.null()
|
|
1550
|
-
}).strict(),
|
|
1551
|
-
import_zod3.z.object({
|
|
1552
|
-
success: import_zod3.z.literal(true),
|
|
1553
|
-
state: import_zod3.z.literal("committed"),
|
|
1554
|
-
operation: accountOperationSchema
|
|
1555
|
-
}).strict()
|
|
1556
|
-
]));
|
|
1557
|
-
if (response.state === "not-observed") return response;
|
|
1558
|
-
if (response.operation.operation_id.toLowerCase() !== operation3.toLowerCase()) throw new AccountError({
|
|
1559
|
-
code: "INVALID_RESPONSE",
|
|
1560
|
-
message: "Account operation response belongs to another operation."
|
|
1561
|
-
});
|
|
1562
|
-
return {
|
|
1563
|
-
state: "committed",
|
|
1564
|
-
operation: response.operation
|
|
1565
|
-
};
|
|
1566
|
-
}
|
|
1567
|
-
async mutateAccount(operationId, request) {
|
|
1568
|
-
const operation3 = id2.parse(operationId), intent = accountOperationIntentSchema.parse(request);
|
|
1569
|
-
const path = intent.action === "workspace.create" ? "/workspaces" : `/workspace-invites/${intent.inviteId}/${intent.action === "invite.accept" ? "accept" : "decline"}`;
|
|
1570
|
-
const body = intent.action === "workspace.create" ? {
|
|
1571
|
-
operation_id: operation3,
|
|
1572
|
-
name: intent.name,
|
|
1573
|
-
workspace_type: intent.type
|
|
1574
|
-
} : {
|
|
1575
|
-
operation_id: operation3
|
|
1576
|
-
};
|
|
1577
|
-
try {
|
|
1578
|
-
const response = await this.call("POST", path, "team:manage", import_zod3.z.object({
|
|
1579
|
-
success: import_zod3.z.literal(true),
|
|
1580
|
-
operation: accountOperationSchema,
|
|
1581
|
-
replayed: import_zod3.z.boolean(),
|
|
1582
|
-
workspace: workspaceSchema.optional()
|
|
1583
|
-
}).strict(), body, operation3);
|
|
1584
|
-
if (response.operation.operation_id.toLowerCase() !== operation3.toLowerCase() || response.operation.action !== intent.action) throw new Error("foreign operation");
|
|
1585
|
-
if (intent.action === "workspace.create" && (!("workspace" in response.operation.result) || JSON.stringify(response.workspace) !== JSON.stringify(response.operation.result.workspace))) throw new Error("foreign workspace");
|
|
1586
|
-
if (intent.action !== "workspace.create" && (!("invite" in response.operation.result) || response.operation.result.invite.id.toLowerCase() !== intent.inviteId.toLowerCase())) throw new Error("foreign invite");
|
|
1587
|
-
return {
|
|
1588
|
-
operation: response.operation,
|
|
1589
|
-
replayed: response.replayed
|
|
1590
|
-
};
|
|
1591
|
-
} catch {
|
|
1592
|
-
throw new AccountMutationError(operation3);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
async select(workspaceId) {
|
|
1596
|
-
await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/select`, "team:read", success);
|
|
1597
|
-
}
|
|
1598
|
-
async members(workspaceId) {
|
|
1599
|
-
return this.call("GET", `/workspaces/${id2.parse(workspaceId)}/members`, "team:read", membersResponse);
|
|
1600
|
-
}
|
|
1601
|
-
async updateMember(workspaceId, memberId, role2) {
|
|
1602
|
-
await this.call("PATCH", `/workspaces/${id2.parse(workspaceId)}/members/${id2.parse(memberId)}`, "team:manage", success, {
|
|
1603
|
-
member_role: workspaceInviteRoleSchema.parse(role2)
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
async membershipOperation(workspaceId, operationId) {
|
|
1607
|
-
const ws = id2.parse(workspaceId), op = id2.parse(operationId);
|
|
1608
|
-
const response = await this.call("GET", `/workspaces/${ws}/membership-operations/${op}`, "team:manage", import_zod3.z.discriminatedUnion("state", [
|
|
1609
|
-
import_zod3.z.object({
|
|
1610
|
-
success: import_zod3.z.literal(true),
|
|
1611
|
-
state: import_zod3.z.literal("not-observed"),
|
|
1612
|
-
operation: import_zod3.z.null()
|
|
1613
|
-
}).strict(),
|
|
1614
|
-
import_zod3.z.object({
|
|
1615
|
-
success: import_zod3.z.literal(true),
|
|
1616
|
-
state: import_zod3.z.literal("committed"),
|
|
1617
|
-
operation: membershipCommittedSchema,
|
|
1618
|
-
delivery: membershipDeliverySchema.optional()
|
|
1619
|
-
}).strict(),
|
|
1620
|
-
import_zod3.z.object({
|
|
1621
|
-
success: import_zod3.z.literal(true),
|
|
1622
|
-
state: import_zod3.z.literal("rejected"),
|
|
1623
|
-
operation: membershipRejectedSchema
|
|
1624
|
-
}).strict(),
|
|
1625
|
-
import_zod3.z.object({
|
|
1626
|
-
success: import_zod3.z.literal(true),
|
|
1627
|
-
state: import_zod3.z.literal("abandoned"),
|
|
1628
|
-
operation: membershipAbandonedSchema
|
|
1629
|
-
}).strict()
|
|
1630
|
-
]));
|
|
1631
|
-
if (response.state === "not-observed") return {
|
|
1632
|
-
state: response.state,
|
|
1633
|
-
operation: null
|
|
1634
|
-
};
|
|
1635
|
-
assertMembershipOperation(ws, op, response.operation);
|
|
1636
|
-
if (response.state === "abandoned") return {
|
|
1637
|
-
state: response.state,
|
|
1638
|
-
operation: response.operation
|
|
1639
|
-
};
|
|
1640
|
-
if (response.state === "committed" && response.delivery && (!("delivery" in response.operation.result) || response.operation.result.delivery.id !== response.delivery.id)) throw new AccountError({
|
|
1641
|
-
code: "INVALID_RESPONSE",
|
|
1642
|
-
message: "Foreign invitation delivery state."
|
|
1643
|
-
});
|
|
1644
|
-
return response.state === "committed" ? {
|
|
1645
|
-
state: response.state,
|
|
1646
|
-
operation: response.operation,
|
|
1647
|
-
...response.delivery ? {
|
|
1648
|
-
delivery: response.delivery
|
|
1649
|
-
} : {}
|
|
1650
|
-
} : {
|
|
1651
|
-
state: response.state,
|
|
1652
|
-
operation: response.operation
|
|
1653
|
-
};
|
|
1654
|
-
}
|
|
1655
|
-
async mutateMembership(workspaceId, operationId, request) {
|
|
1656
|
-
const ws = id2.parse(workspaceId), op = id2.parse(operationId), input = membershipMutationSchema.parse(request);
|
|
1657
|
-
const path = input.action === "invite.create" ? "/invites" : "inviteId" in input ? `/invites/${input.inviteId}${input.action === "invite.resend" ? "/resend" : ""}` : "memberId" in input ? `/members/${input.memberId}` : "/owner-transfer";
|
|
1658
|
-
const method = input.action === "member.role" ? "PATCH" : input.action === "invite.revoke" || input.action === "member.remove" ? "DELETE" : "POST";
|
|
1659
|
-
const body = {
|
|
1660
|
-
operation_id: op,
|
|
1661
|
-
...input.action === "invite.create" ? {
|
|
1662
|
-
email: input.email,
|
|
1663
|
-
role: input.role
|
|
1664
|
-
} : input.action === "member.role" ? {
|
|
1665
|
-
member_role: input.role
|
|
1666
|
-
} : input.action === "owner.transfer" ? {
|
|
1667
|
-
new_owner_user_id: input.newOwnerId
|
|
1668
|
-
} : {}
|
|
1669
|
-
};
|
|
1670
|
-
try {
|
|
1671
|
-
const response = await this.call(method, `/workspaces/${ws}${path}`, "team:manage", import_zod3.z.object({
|
|
1672
|
-
success: import_zod3.z.literal(true),
|
|
1673
|
-
operation: membershipOperationSchema,
|
|
1674
|
-
replayed: import_zod3.z.boolean()
|
|
1675
|
-
}).strict(), body);
|
|
1676
|
-
assertMembershipOperation(ws, op, response.operation, input);
|
|
1677
|
-
return {
|
|
1678
|
-
operation: response.operation,
|
|
1679
|
-
replayed: response.replayed
|
|
1680
|
-
};
|
|
1681
|
-
} catch {
|
|
1682
|
-
throw new WorkspaceMembershipMutationError(op);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
/** Explicit user-requested settlement only. A lost ACK remains uncertain; never
|
|
1686
|
-
* synthesize abandonment locally or automatically retry with a new ID. */
|
|
1687
|
-
async abandonMembershipOperation(workspaceId, operationId, request) {
|
|
1688
|
-
const ws = id2.parse(workspaceId), op = id2.parse(operationId), input = membershipMutationSchema.parse(request);
|
|
1689
|
-
try {
|
|
1690
|
-
const response = await this.call("POST", `/workspaces/${ws}/membership-operations/${op}/abandon`, "team:manage", import_zod3.z.object({
|
|
1691
|
-
success: import_zod3.z.literal(true),
|
|
1692
|
-
operation: membershipOperationSchema,
|
|
1693
|
-
replayed: import_zod3.z.boolean()
|
|
1694
|
-
}).strict(), {
|
|
1695
|
-
request: input
|
|
1696
|
-
});
|
|
1697
|
-
assertMembershipOperation(ws, op, response.operation, input);
|
|
1698
|
-
return {
|
|
1699
|
-
operation: response.operation,
|
|
1700
|
-
replayed: response.replayed
|
|
1701
|
-
};
|
|
1702
|
-
} catch {
|
|
1703
|
-
throw new WorkspaceMembershipMutationError(op);
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
async abandonKeyOperation(workspaceId, operationId, request) {
|
|
1707
|
-
const ws = id2.parse(workspaceId), op = id2.parse(operationId), input = keyMutationSchema.parse(request);
|
|
1708
|
-
const original = {
|
|
1709
|
-
action: input.action,
|
|
1710
|
-
...input.action === "revoke" ? {} : input.input,
|
|
1711
|
-
...input.action === "create" ? {} : {
|
|
1712
|
-
id: input.keyId,
|
|
1713
|
-
expected_revision: input.expectedRevision
|
|
1714
|
-
}
|
|
1715
|
-
};
|
|
1716
|
-
try {
|
|
1717
|
-
const response = await this.call("POST", `/workspaces/${ws}/api-keys/operations/${op}/abandon`, "team:manage", import_zod3.z.object({
|
|
1718
|
-
success: import_zod3.z.literal(true),
|
|
1719
|
-
operation: workspaceKeyOperationSchema,
|
|
1720
|
-
replayed: import_zod3.z.boolean()
|
|
1721
|
-
}).strict(), {
|
|
1722
|
-
request: original
|
|
1723
|
-
});
|
|
1724
|
-
this.assertOperation(ws, op, response.operation);
|
|
1725
|
-
if (response.operation.action !== input.action || response.operation.previous_key_id?.toLowerCase() !== (input.action === "create" ? void 0 : input.keyId.toLowerCase())) throw new Error("Wrong key operation intent");
|
|
1726
|
-
return {
|
|
1727
|
-
operation: response.operation,
|
|
1728
|
-
replayed: response.replayed
|
|
1729
|
-
};
|
|
1730
|
-
} catch {
|
|
1731
|
-
throw new WorkspaceKeyMutationError(op);
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
async removeMember(workspaceId, memberId) {
|
|
1735
|
-
await this.call("DELETE", `/workspaces/${id2.parse(workspaceId)}/members/${id2.parse(memberId)}`, "team:manage", success);
|
|
1736
|
-
}
|
|
1737
|
-
async transferOwnership(workspaceId, newOwnerUserId) {
|
|
1738
|
-
await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/owner-transfer`, "team:manage", success, {
|
|
1739
|
-
new_owner_user_id: id2.parse(newOwnerUserId)
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
|
-
async invites(workspaceId) {
|
|
1743
|
-
return (await this.call("GET", `/workspaces/${id2.parse(workspaceId)}/invites`, "team:read", invitesResponse)).invites;
|
|
1744
|
-
}
|
|
1745
|
-
async invite(workspaceId, email, role2 = "member") {
|
|
1746
|
-
const body = {
|
|
1747
|
-
email: import_zod3.z.string().trim().email().parse(email),
|
|
1748
|
-
role: workspaceInviteRoleSchema.parse(role2)
|
|
1749
|
-
};
|
|
1750
|
-
return (await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/invites`, "team:manage", success.extend({
|
|
1751
|
-
invite: workspaceInviteSchema
|
|
1752
|
-
}), body)).invite;
|
|
1753
|
-
}
|
|
1754
|
-
async revokeInvite(workspaceId, inviteId) {
|
|
1755
|
-
await this.call("DELETE", `/workspaces/${id2.parse(workspaceId)}/invites/${id2.parse(inviteId)}`, "team:manage", success);
|
|
1756
|
-
}
|
|
1757
|
-
async resendInvite(workspaceId, inviteId) {
|
|
1758
|
-
await this.call("POST", `/workspaces/${id2.parse(workspaceId)}/invites/${id2.parse(inviteId)}/resend`, "team:manage", success);
|
|
1759
|
-
}
|
|
1760
|
-
async pendingInvites() {
|
|
1761
|
-
return (await this.call("GET", "/workspace-invites", "team:read", invitesResponse)).invites;
|
|
1762
|
-
}
|
|
1763
|
-
async acceptInvite(inviteId) {
|
|
1764
|
-
await this.call("POST", `/workspace-invites/${id2.parse(inviteId)}/accept`, "team:manage", success);
|
|
1765
|
-
}
|
|
1766
|
-
async declineInvite(inviteId) {
|
|
1767
|
-
await this.call("POST", `/workspace-invites/${id2.parse(inviteId)}/decline`, "team:manage", success);
|
|
1768
|
-
}
|
|
1769
|
-
};
|
|
1770
|
-
|
|
1771
|
-
// src/workforce.ts
|
|
1772
|
-
var import_zod4 = require("zod");
|
|
1773
|
-
var uuid = import_zod4.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i).transform((value) => value.toLowerCase());
|
|
1774
|
-
var timestamp3 = import_zod4.z.string().datetime({
|
|
1775
|
-
offset: true
|
|
1776
|
-
});
|
|
1777
|
-
var identifier = import_zod4.z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@+-]{0,127}$/);
|
|
1778
|
-
var hash = import_zod4.z.string().regex(/^[a-f0-9]{64}$/);
|
|
1779
|
-
var revision = import_zod4.z.string().max(19).regex(/^[1-9][0-9]*$/).refine((value) => BigInt(value) <= 9223372036854775807n);
|
|
1780
|
-
var text = /* @__PURE__ */ __name((max, empty = false) => import_zod4.z.string().max(max).refine((value) => !value.includes("\0") && (empty || Boolean(value.trim())) && new TextEncoder().encode(value).length <= max), "text");
|
|
1781
|
-
var unique = /* @__PURE__ */ __name((items, key) => new Set(items.map(key)).size === items.length, "unique");
|
|
1782
|
-
var workforceOwnerSchema = import_zod4.z.object({
|
|
1783
|
-
type: import_zod4.z.enum([
|
|
1784
|
-
"user",
|
|
1785
|
-
"workspace"
|
|
1786
|
-
]),
|
|
1787
|
-
id: uuid
|
|
1788
|
-
}).strict();
|
|
1789
|
-
var skill = import_zod4.z.object({
|
|
1790
|
-
id: identifier,
|
|
1791
|
-
version: identifier,
|
|
1792
|
-
hash
|
|
1793
|
-
}).strict();
|
|
1794
|
-
var secretReference = import_zod4.z.object({
|
|
1795
|
-
name: import_zod4.z.string().regex(/^[A-Z][A-Z0-9_]{0,63}$/),
|
|
1796
|
-
ref: uuid
|
|
1797
|
-
}).strict();
|
|
1798
|
-
var contentShape = {
|
|
1799
|
-
instructions: text(32768, true),
|
|
1800
|
-
skills: import_zod4.z.array(skill).max(64).refine((items) => unique(items, (item) => item.id)),
|
|
1801
|
-
requestedCapabilities: import_zod4.z.array(identifier).max(64).refine((items) => unique(items, (item) => item)),
|
|
1802
|
-
secretReferences: import_zod4.z.array(secretReference).max(32).refine((items) => unique(items, (item) => item.name))
|
|
1803
|
-
};
|
|
1804
|
-
var provenance = import_zod4.z.object({
|
|
1805
|
-
source: import_zod4.z.enum([
|
|
1806
|
-
"authored",
|
|
1807
|
-
"imported"
|
|
1808
|
-
]),
|
|
1809
|
-
sourceVersion: identifier.optional()
|
|
1810
|
-
}).strict();
|
|
1811
|
-
var license = import_zod4.z.object({
|
|
1812
|
-
identifier
|
|
1813
|
-
}).strict();
|
|
1814
|
-
var workforceDefinitionSchema = import_zod4.z.object({
|
|
1815
|
-
schemaVersion: import_zod4.z.literal(1),
|
|
1816
|
-
...contentShape,
|
|
1817
|
-
secretReferences: contentShape.secretReferences.optional(),
|
|
1818
|
-
provenance: provenance.optional(),
|
|
1819
|
-
license: license.optional()
|
|
1820
|
-
}).strict();
|
|
1821
|
-
var createBase = {
|
|
1822
|
-
operationId: uuid,
|
|
1823
|
-
owner: workforceOwnerSchema,
|
|
1824
|
-
// Equality precondition only: the server authenticates the actor and refuses
|
|
1825
|
-
// a changed account. This field never selects or grants an acting identity.
|
|
1826
|
-
expectedActorAccountId: uuid.optional(),
|
|
1827
|
-
name: text(200).transform((value) => value.trim()),
|
|
1828
|
-
description: text(4096, true).optional()
|
|
1829
|
-
};
|
|
1830
|
-
var workforceCreateResourceSchema = import_zod4.z.discriminatedUnion("kind", [
|
|
1831
|
-
import_zod4.z.object({
|
|
1832
|
-
...createBase,
|
|
1833
|
-
kind: import_zod4.z.literal("agent"),
|
|
1834
|
-
definition: workforceDefinitionSchema
|
|
1835
|
-
}).strict(),
|
|
1836
|
-
import_zod4.z.object({
|
|
1837
|
-
...createBase,
|
|
1838
|
-
kind: import_zod4.z.literal("team")
|
|
1839
|
-
}).strict()
|
|
1840
|
-
]);
|
|
1841
|
-
var workforceReadOperationSchema = import_zod4.z.object({
|
|
1842
|
-
operationId: uuid,
|
|
1843
|
-
owner: workforceOwnerSchema,
|
|
1844
|
-
expectedActorAccountId: uuid.optional()
|
|
1845
|
-
}).strict();
|
|
1846
|
-
var catalogCursor = import_zod4.z.string().min(1).max(2048).regex(/^[A-Za-z0-9_-]+$/);
|
|
1847
|
-
var workforceListOwnedResourcesSchema = import_zod4.z.object({
|
|
1848
|
-
owner: workforceOwnerSchema,
|
|
1849
|
-
expectedActorAccountId: uuid,
|
|
1850
|
-
limit: import_zod4.z.number().int().min(1).max(100).optional(),
|
|
1851
|
-
kind: import_zod4.z.enum([
|
|
1852
|
-
"agent",
|
|
1853
|
-
"team"
|
|
1854
|
-
]).optional(),
|
|
1855
|
-
status: import_zod4.z.enum([
|
|
1856
|
-
"active",
|
|
1857
|
-
"archived"
|
|
1858
|
-
]).optional(),
|
|
1859
|
-
cursor: catalogCursor.optional()
|
|
1860
|
-
}).strict();
|
|
1861
|
-
var resource = import_zod4.z.object({
|
|
1862
|
-
id: uuid,
|
|
1863
|
-
kind: import_zod4.z.enum([
|
|
1864
|
-
"agent",
|
|
1865
|
-
"team"
|
|
1866
|
-
]),
|
|
1867
|
-
owner: workforceOwnerSchema,
|
|
1868
|
-
createdByUserId: uuid.nullable(),
|
|
1869
|
-
name: text(200),
|
|
1870
|
-
description: text(4096, true),
|
|
1871
|
-
status: import_zod4.z.enum([
|
|
1872
|
-
"active",
|
|
1873
|
-
"archived"
|
|
1874
|
-
]),
|
|
1875
|
-
revision,
|
|
1876
|
-
createdAt: timestamp3,
|
|
1877
|
-
updatedAt: timestamp3
|
|
1878
|
-
}).strict();
|
|
1879
|
-
var ownedCatalog = import_zod4.z.object({
|
|
1880
|
-
success: import_zod4.z.literal(true),
|
|
1881
|
-
schemaVersion: import_zod4.z.literal(1),
|
|
1882
|
-
scope: import_zod4.z.literal("owned"),
|
|
1883
|
-
owner: workforceOwnerSchema,
|
|
1884
|
-
items: import_zod4.z.array(resource).max(100),
|
|
1885
|
-
nextCursor: catalogCursor.nullable()
|
|
1886
|
-
}).strict();
|
|
1887
|
-
var version = import_zod4.z.object({
|
|
1888
|
-
resourceId: uuid,
|
|
1889
|
-
version: import_zod4.z.number().int().positive(),
|
|
1890
|
-
schemaVersion: import_zod4.z.literal(1),
|
|
1891
|
-
content: import_zod4.z.object(contentShape).strict(),
|
|
1892
|
-
contentHash: hash,
|
|
1893
|
-
provenance: import_zod4.z.union([
|
|
1894
|
-
provenance,
|
|
1895
|
-
import_zod4.z.object({}).strict()
|
|
1896
|
-
]),
|
|
1897
|
-
license: import_zod4.z.union([
|
|
1898
|
-
license,
|
|
1899
|
-
import_zod4.z.object({}).strict()
|
|
1900
|
-
]),
|
|
1901
|
-
createdByUserId: uuid.nullable(),
|
|
1902
|
-
createdAt: timestamp3
|
|
1903
|
-
}).strict();
|
|
1904
|
-
var operation = import_zod4.z.object({
|
|
1905
|
-
schemaVersion: import_zod4.z.literal(1),
|
|
1906
|
-
operationId: uuid,
|
|
1907
|
-
action: import_zod4.z.literal("agent.resource.create"),
|
|
1908
|
-
state: import_zod4.z.literal("committed"),
|
|
1909
|
-
owner: workforceOwnerSchema,
|
|
1910
|
-
resourceId: uuid,
|
|
1911
|
-
resourceRevision: revision,
|
|
1912
|
-
agentVersion: import_zod4.z.number().int().positive().nullable(),
|
|
1913
|
-
committedAt: timestamp3
|
|
1914
|
-
}).strict();
|
|
1915
|
-
var committed = import_zod4.z.object({
|
|
1916
|
-
success: import_zod4.z.literal(true),
|
|
1917
|
-
state: import_zod4.z.literal("committed"),
|
|
1918
|
-
operation,
|
|
1919
|
-
resource: resource.nullable(),
|
|
1920
|
-
version: version.nullable(),
|
|
1921
|
-
replayed: import_zod4.z.boolean(),
|
|
1922
|
-
resourceAccess: import_zod4.z.discriminatedUnion("allowed", [
|
|
1923
|
-
import_zod4.z.object({
|
|
1924
|
-
allowed: import_zod4.z.literal(true)
|
|
1925
|
-
}).strict(),
|
|
1926
|
-
import_zod4.z.object({
|
|
1927
|
-
allowed: import_zod4.z.literal(false),
|
|
1928
|
-
reason: import_zod4.z.literal("no_access")
|
|
1929
|
-
}).strict()
|
|
1930
|
-
])
|
|
1931
|
-
}).strict();
|
|
1932
|
-
var notObserved = import_zod4.z.object({
|
|
1933
|
-
success: import_zod4.z.literal(true),
|
|
1934
|
-
state: import_zod4.z.literal("not-observed"),
|
|
1935
|
-
operation: import_zod4.z.null(),
|
|
1936
|
-
resource: import_zod4.z.null(),
|
|
1937
|
-
version: import_zod4.z.null(),
|
|
1938
|
-
replayed: import_zod4.z.literal(false)
|
|
1939
|
-
}).strict();
|
|
1940
|
-
var WorkforceResourceMutationError = class extends AccountError {
|
|
1941
|
-
static {
|
|
1942
|
-
__name(this, "WorkforceResourceMutationError");
|
|
1943
|
-
}
|
|
1944
|
-
operationId;
|
|
1945
|
-
outcome = "uncertain";
|
|
1946
|
-
reason = "mutation_outcome_unverified";
|
|
1947
|
-
source = "client-observation";
|
|
1948
|
-
owner;
|
|
1949
|
-
constructor(operationId, owner, cause) {
|
|
1950
|
-
super({
|
|
1951
|
-
code: cause instanceof AccountError ? cause.code : "PLATFORM_ERROR",
|
|
1952
|
-
message: "Workforce creation acknowledgement is unverified. Read back the same operation before retrying.",
|
|
1953
|
-
httpStatus: cause instanceof AccountError ? cause.httpStatus : null,
|
|
1954
|
-
retryable: false
|
|
1955
|
-
}), this.operationId = operationId;
|
|
1956
|
-
this.name = "WorkforceResourceMutationError";
|
|
1957
|
-
this.owner = Object.freeze({
|
|
1958
|
-
...owner
|
|
1959
|
-
});
|
|
1960
|
-
}
|
|
1961
|
-
};
|
|
1962
|
-
var sameOwner = /* @__PURE__ */ __name((left, right) => left.type === right.type && left.id === right.id, "sameOwner");
|
|
1963
|
-
var invalidResponse = /* @__PURE__ */ __name(() => new AccountError({
|
|
1964
|
-
code: "INVALID_RESPONSE",
|
|
1965
|
-
message: "Invalid workforce operation response."
|
|
1966
|
-
}), "invalidResponse");
|
|
1967
|
-
var invalidInput = /* @__PURE__ */ __name(() => new AccountError({
|
|
1968
|
-
code: "BAD_REQUEST",
|
|
1969
|
-
message: "Invalid workforce operation request."
|
|
1970
|
-
}), "invalidInput");
|
|
1971
|
-
function assertData(value, depth = 0, budget = {
|
|
1972
|
-
remaining: 4096
|
|
1973
|
-
}) {
|
|
1974
|
-
if (--budget.remaining < 0 || depth > 8) throw invalidInput();
|
|
1975
|
-
if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number") return;
|
|
1976
|
-
if (!value || typeof value !== "object") throw invalidInput();
|
|
1977
|
-
const array = Array.isArray(value);
|
|
1978
|
-
if (array ? Object.getPrototypeOf(value) !== Array.prototype : ![
|
|
1979
|
-
Object.prototype,
|
|
1980
|
-
null
|
|
1981
|
-
].includes(Object.getPrototypeOf(value))) throw invalidInput();
|
|
1982
|
-
const keys = Reflect.ownKeys(value);
|
|
1983
|
-
if (keys.length > 4096 || array && keys.length !== value.length + 1) throw invalidInput();
|
|
1984
|
-
for (const key of keys) {
|
|
1985
|
-
if (array && key === "length") continue;
|
|
1986
|
-
if (typeof key !== "string" || array && !/^(0|[1-9][0-9]*)$/.test(key)) throw invalidInput();
|
|
1987
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1988
|
-
if (!descriptor.enumerable || !Object.hasOwn(descriptor, "value")) throw invalidInput();
|
|
1989
|
-
assertData(descriptor.value, depth + 1, budget);
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
__name(assertData, "assertData");
|
|
1993
|
-
function parseInput(schema, value) {
|
|
1994
|
-
assertData(value);
|
|
1995
|
-
const parsed = schema.safeParse(value);
|
|
1996
|
-
if (!parsed.success) throw invalidInput();
|
|
1997
|
-
if (new TextEncoder().encode(JSON.stringify(parsed.data)).length > 256 * 1024) throw invalidInput();
|
|
1998
|
-
return parsed.data;
|
|
1999
|
-
}
|
|
2000
|
-
__name(parseInput, "parseInput");
|
|
2001
|
-
var WorkforceClient = class {
|
|
2002
|
-
static {
|
|
2003
|
-
__name(this, "WorkforceClient");
|
|
2004
|
-
}
|
|
2005
|
-
transport;
|
|
2006
|
-
authorize;
|
|
2007
|
-
base;
|
|
2008
|
-
constructor(base2, transport, authorize) {
|
|
2009
|
-
this.transport = transport;
|
|
2010
|
-
this.authorize = authorize;
|
|
2011
|
-
const origin = new URL(base2);
|
|
2012
|
-
if (origin.protocol !== "https:" || origin.username || origin.password || origin.search || origin.hash || origin.pathname !== "/") {
|
|
2013
|
-
throw new AccountError({
|
|
2014
|
-
code: "BAD_REQUEST",
|
|
2015
|
-
message: "Workforce API requires an HTTPS origin."
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
|
-
this.base = origin.origin;
|
|
2019
|
-
}
|
|
2020
|
-
/** This catalog lists one explicitly owned scope only. It is not an aggregate
|
|
2021
|
-
* of assigned, shared or rented resources and contains no agent definitions. */
|
|
2022
|
-
async listOwnedResources(value) {
|
|
2023
|
-
const input = parseInput(workforceListOwnedResourcesSchema, value);
|
|
2024
|
-
const url = `${this.base}/api/workforce/resources/list`;
|
|
2025
|
-
const raw = await this.transport.request({
|
|
2026
|
-
method: "POST",
|
|
2027
|
-
url,
|
|
2028
|
-
body: input,
|
|
2029
|
-
authorization: /* @__PURE__ */ __name(async () => {
|
|
2030
|
-
const auth = await this.authorize("POST", url, {
|
|
2031
|
-
scopes: [
|
|
2032
|
-
"workforce:read"
|
|
2033
|
-
],
|
|
2034
|
-
silent: true
|
|
2035
|
-
});
|
|
2036
|
-
if (!auth) throw new AccountError({
|
|
2037
|
-
code: "INVALID_TOKEN",
|
|
2038
|
-
message: "Sign in with workforce read access."
|
|
2039
|
-
});
|
|
2040
|
-
return auth;
|
|
2041
|
-
}, "authorization")
|
|
2042
|
-
});
|
|
2043
|
-
const parsed = ownedCatalog.safeParse(raw);
|
|
2044
|
-
if (!parsed.success) throw invalidResponse();
|
|
2045
|
-
const result = parsed.data;
|
|
2046
|
-
if (!sameOwner(result.owner, input.owner) || result.items.length > (input.limit ?? 50) || !unique(result.items, (item) => item.id) || result.items.some((item) => !sameOwner(item.owner, input.owner) || input.kind !== void 0 && item.kind !== input.kind || item.status !== (input.status ?? "active")) || result.nextCursor !== null && (result.items.length === 0 || result.nextCursor === input.cursor)) throw invalidResponse();
|
|
2047
|
-
return result;
|
|
2048
|
-
}
|
|
2049
|
-
validate(raw, input, creating) {
|
|
2050
|
-
const parsed = (creating ? committed : import_zod4.z.union([
|
|
2051
|
-
committed,
|
|
2052
|
-
notObserved
|
|
2053
|
-
])).safeParse(raw);
|
|
2054
|
-
if (!parsed.success) throw invalidResponse();
|
|
2055
|
-
const result = parsed.data;
|
|
2056
|
-
if (result.state === "not-observed") return result;
|
|
2057
|
-
const op = result.operation;
|
|
2058
|
-
if (op.operationId !== input.operationId || !sameOwner(op.owner, input.owner)) throw invalidResponse();
|
|
2059
|
-
if (!result.resourceAccess.allowed) {
|
|
2060
|
-
if (result.resource !== null || result.version !== null) throw invalidResponse();
|
|
2061
|
-
return result;
|
|
2062
|
-
}
|
|
2063
|
-
const r = result.resource, v = result.version;
|
|
2064
|
-
if (!r || r.id !== op.resourceId || !sameOwner(r.owner, input.owner) || BigInt(r.revision) < BigInt(op.resourceRevision)) throw invalidResponse();
|
|
2065
|
-
if (r.kind === "team" ? op.agentVersion !== null || v !== null : op.agentVersion === null || !v || v.resourceId !== r.id || v.version !== op.agentVersion) throw invalidResponse();
|
|
2066
|
-
return result;
|
|
2067
|
-
}
|
|
2068
|
-
async createResource(value) {
|
|
2069
|
-
const input = parseInput(workforceCreateResourceSchema, value);
|
|
2070
|
-
let authorizationCompleted = false;
|
|
2071
|
-
try {
|
|
2072
|
-
const url = `${this.base}/api/workforce/resources`;
|
|
2073
|
-
const raw = await this.transport.request({
|
|
2074
|
-
method: "POST",
|
|
2075
|
-
url,
|
|
2076
|
-
body: input,
|
|
2077
|
-
authorization: /* @__PURE__ */ __name(async () => {
|
|
2078
|
-
const auth = await this.authorize("POST", url, {
|
|
2079
|
-
scopes: [
|
|
2080
|
-
"workforce:manage"
|
|
2081
|
-
],
|
|
2082
|
-
silent: true
|
|
2083
|
-
});
|
|
2084
|
-
if (!auth) throw new AccountError({
|
|
2085
|
-
code: "INVALID_TOKEN",
|
|
2086
|
-
message: "Sign in with workforce management access."
|
|
2087
|
-
});
|
|
2088
|
-
authorizationCompleted = true;
|
|
2089
|
-
return auth;
|
|
2090
|
-
}, "authorization")
|
|
2091
|
-
});
|
|
2092
|
-
const result = this.validate(raw, input, true);
|
|
2093
|
-
if (result.resource && result.resource.kind !== input.kind) throw invalidResponse();
|
|
2094
|
-
if (input.kind === "agent" !== (result.operation.agentVersion !== null)) throw invalidResponse();
|
|
2095
|
-
return result;
|
|
2096
|
-
} catch (error) {
|
|
2097
|
-
if (!authorizationCompleted) throw error;
|
|
2098
|
-
throw new WorkforceResourceMutationError(input.operationId, input.owner, error);
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
async readOperation(value) {
|
|
2102
|
-
const input = parseInput(workforceReadOperationSchema, value);
|
|
2103
|
-
const url = `${this.base}/api/workforce/resource-operations/read`;
|
|
2104
|
-
const raw = await this.transport.request({
|
|
2105
|
-
method: "POST",
|
|
2106
|
-
url,
|
|
2107
|
-
body: input,
|
|
2108
|
-
authorization: /* @__PURE__ */ __name(async () => {
|
|
2109
|
-
const auth = await this.authorize("POST", url, {
|
|
2110
|
-
scopes: [
|
|
2111
|
-
"workforce:read"
|
|
2112
|
-
],
|
|
2113
|
-
silent: true
|
|
2114
|
-
});
|
|
2115
|
-
if (!auth) throw new AccountError({
|
|
2116
|
-
code: "INVALID_TOKEN",
|
|
2117
|
-
message: "Sign in with workforce read access."
|
|
2118
|
-
});
|
|
2119
|
-
return auth;
|
|
2120
|
-
}, "authorization")
|
|
2121
|
-
});
|
|
2122
|
-
return this.validate(raw, input, false);
|
|
2123
|
-
}
|
|
2124
|
-
};
|
|
2125
|
-
|
|
2126
|
-
// src/notifications.ts
|
|
2127
|
-
var import_zod5 = require("zod");
|
|
2128
|
-
var id3 = import_zod5.z.string().uuid();
|
|
2129
|
-
var localId = import_zod5.z.string().regex(/^[a-z0-9_:-]{1,240}$/i);
|
|
2130
|
-
var timestamp4 = import_zod5.z.string().datetime({
|
|
2131
|
-
offset: true
|
|
2132
|
-
});
|
|
2133
|
-
var revision2 = import_zod5.z.union([
|
|
2134
|
-
import_zod5.z.literal("0"),
|
|
2135
|
-
id3
|
|
2136
|
-
]);
|
|
2137
|
-
var httpsUrl = import_zod5.z.string().max(2048).url().refine((value) => {
|
|
2138
|
-
const parsed = new URL(value);
|
|
2139
|
-
return parsed.protocol === "https:" && !parsed.username && !parsed.password && !parsed.hash;
|
|
2140
|
-
}, "Notification destinations require credential-free HTTPS URLs");
|
|
2141
|
-
var notificationEventSchema = import_zod5.z.enum([
|
|
2142
|
-
"agent.finished",
|
|
2143
|
-
"agent.failed",
|
|
2144
|
-
"agent.cancelled"
|
|
2145
|
-
]);
|
|
2146
|
-
var notificationChannelSchema = import_zod5.z.enum([
|
|
2147
|
-
"webhook",
|
|
2148
|
-
"slack",
|
|
2149
|
-
"discord"
|
|
2150
|
-
]);
|
|
2151
|
-
var notificationScopeSchema = import_zod5.z.object({
|
|
2152
|
-
workspaceId: localId,
|
|
2153
|
-
workspaceCreatedAt: timestamp4.transform((value) => new Date(value).toISOString()),
|
|
2154
|
-
teamId: localId.optional(),
|
|
2155
|
-
agentId: localId.optional()
|
|
2156
|
-
}).strict().refine((scope) => !scope.agentId || !!scope.teamId, "Agent requires owning team");
|
|
2157
|
-
var notificationRuleSchema = import_zod5.z.object({
|
|
2158
|
-
id: import_zod5.z.string().regex(/^[a-f0-9]{64}$/).optional(),
|
|
2159
|
-
event: notificationEventSchema,
|
|
2160
|
-
channel: notificationChannelSchema,
|
|
2161
|
-
destinationId: id3,
|
|
2162
|
-
enabled: import_zod5.z.boolean()
|
|
2163
|
-
}).strict();
|
|
2164
|
-
var deliverySchema = import_zod5.z.object({
|
|
2165
|
-
id: id3,
|
|
2166
|
-
destination_id: id3,
|
|
2167
|
-
event: notificationEventSchema,
|
|
2168
|
-
state: import_zod5.z.enum([
|
|
2169
|
-
"queued",
|
|
2170
|
-
"leased",
|
|
2171
|
-
"delivered",
|
|
2172
|
-
"failed",
|
|
2173
|
-
"cancelled"
|
|
2174
|
-
]),
|
|
2175
|
-
attempt: import_zod5.z.number().int().nonnegative(),
|
|
2176
|
-
max_attempts: import_zod5.z.number().int().positive(),
|
|
2177
|
-
status_code: import_zod5.z.number().int().min(100).max(599).nullable().optional(),
|
|
2178
|
-
error_code: import_zod5.z.string().max(128).nullable().optional(),
|
|
2179
|
-
created_at: timestamp4,
|
|
2180
|
-
delivered_at: timestamp4.nullable().optional(),
|
|
2181
|
-
next_retry_at: timestamp4.nullable().optional(),
|
|
2182
|
-
cancelled_at: timestamp4.nullable().optional()
|
|
2183
|
-
});
|
|
2184
|
-
var notificationSettingsDestinationSchema = import_zod5.z.object({
|
|
2185
|
-
id: id3,
|
|
2186
|
-
label: import_zod5.z.string().min(1).max(253).refine((value) => value === "Unavailable webhook" || /^[a-z0-9.:[\]-]+$/i.test(value)),
|
|
2187
|
-
channel: notificationChannelSchema,
|
|
2188
|
-
ready: import_zod5.z.boolean(),
|
|
2189
|
-
enabled: import_zod5.z.boolean(),
|
|
2190
|
-
updated_at: timestamp4
|
|
2191
|
-
}).strict().transform(({ updated_at, ...value }) => ({
|
|
2192
|
-
...value,
|
|
2193
|
-
updatedAt: updated_at
|
|
2194
|
-
}));
|
|
2195
|
-
var notificationSettingsSchema = import_zod5.z.object({
|
|
2196
|
-
success: import_zod5.z.literal(true),
|
|
2197
|
-
channelVersion: import_zod5.z.literal(2),
|
|
2198
|
-
revision: revision2,
|
|
2199
|
-
rules: import_zod5.z.array(notificationRuleSchema).max(20),
|
|
2200
|
-
destinations: import_zod5.z.array(notificationSettingsDestinationSchema),
|
|
2201
|
-
deliveries: import_zod5.z.array(deliverySchema).max(50),
|
|
2202
|
-
channels: import_zod5.z.array(import_zod5.z.object({
|
|
2203
|
-
id: import_zod5.z.enum([
|
|
2204
|
-
"webhook",
|
|
2205
|
-
"email",
|
|
2206
|
-
"slack",
|
|
2207
|
-
"discord"
|
|
2208
|
-
]),
|
|
2209
|
-
available: import_zod5.z.boolean()
|
|
2210
|
-
})),
|
|
2211
|
-
digestFrequencies: import_zod5.z.tuple([
|
|
2212
|
-
import_zod5.z.literal("realtime")
|
|
2213
|
-
])
|
|
2214
|
-
});
|
|
2215
|
-
var eventInputSchema = import_zod5.z.object({
|
|
2216
|
-
eventId: import_zod5.z.string().regex(/^[a-f0-9]{64}$/),
|
|
2217
|
-
event: notificationEventSchema,
|
|
2218
|
-
occurredAt: timestamp4.transform((value) => new Date(value).toISOString()),
|
|
2219
|
-
scope: notificationScopeSchema,
|
|
2220
|
-
conversationId: localId,
|
|
2221
|
-
requestId: localId
|
|
2222
|
-
}).strict();
|
|
2223
|
-
var notificationDestinationActionSchema = import_zod5.z.discriminatedUnion("action", [
|
|
2224
|
-
import_zod5.z.object({
|
|
2225
|
-
action: import_zod5.z.literal("create"),
|
|
2226
|
-
url: httpsUrl
|
|
2227
|
-
}).strict(),
|
|
2228
|
-
import_zod5.z.object({
|
|
2229
|
-
action: import_zod5.z.literal("update"),
|
|
2230
|
-
destination_id: id3,
|
|
2231
|
-
expected_updated_at: timestamp4,
|
|
2232
|
-
url: httpsUrl.optional(),
|
|
2233
|
-
enabled: import_zod5.z.boolean().optional()
|
|
2234
|
-
}).strict().refine((value) => value.url !== void 0 || value.enabled !== void 0, "An update requires a changed field"),
|
|
2235
|
-
import_zod5.z.object({
|
|
2236
|
-
action: import_zod5.z.literal("delete"),
|
|
2237
|
-
destination_id: id3,
|
|
2238
|
-
expected_updated_at: timestamp4
|
|
2239
|
-
}).strict(),
|
|
2240
|
-
import_zod5.z.object({
|
|
2241
|
-
action: import_zod5.z.literal("delivery-control"),
|
|
2242
|
-
destination_id: id3,
|
|
2243
|
-
delivery_id: id3,
|
|
2244
|
-
operation: import_zod5.z.enum([
|
|
2245
|
-
"retry",
|
|
2246
|
-
"cancel"
|
|
2247
|
-
])
|
|
2248
|
-
}).strict()
|
|
2249
|
-
]);
|
|
2250
|
-
var notificationDestinationSchema = import_zod5.z.object({
|
|
2251
|
-
id: id3,
|
|
2252
|
-
label: import_zod5.z.string().min(1).max(253),
|
|
2253
|
-
channel: import_zod5.z.literal("webhook"),
|
|
2254
|
-
ready: import_zod5.z.boolean(),
|
|
2255
|
-
enabled: import_zod5.z.boolean(),
|
|
2256
|
-
updated_at: timestamp4
|
|
2257
|
-
}).strict();
|
|
2258
|
-
var notificationDeliveryOperationResultSchema = import_zod5.z.object({
|
|
2259
|
-
id: id3,
|
|
2260
|
-
state: import_zod5.z.string().min(1).max(64),
|
|
2261
|
-
attempt: import_zod5.z.number().int().nonnegative(),
|
|
2262
|
-
max_attempts: import_zod5.z.number().int().positive()
|
|
2263
|
-
}).strict();
|
|
2264
|
-
var notificationDestinationOperationSchema = import_zod5.z.object({
|
|
2265
|
-
operation_id: id3,
|
|
2266
|
-
workspace_id: id3,
|
|
2267
|
-
actor_user_id: id3,
|
|
2268
|
-
client_id: import_zod5.z.string().min(1).max(128),
|
|
2269
|
-
action: import_zod5.z.enum([
|
|
2270
|
-
"create",
|
|
2271
|
-
"update",
|
|
2272
|
-
"delete",
|
|
2273
|
-
"delivery-control"
|
|
2274
|
-
]),
|
|
2275
|
-
state: import_zod5.z.enum([
|
|
2276
|
-
"prepared",
|
|
2277
|
-
"committed",
|
|
2278
|
-
"rejected"
|
|
2279
|
-
]),
|
|
2280
|
-
prepared_at: timestamp4,
|
|
2281
|
-
committed_at: timestamp4.optional(),
|
|
2282
|
-
destination: notificationDestinationSchema.optional(),
|
|
2283
|
-
delivery: notificationDeliveryOperationResultSchema.optional(),
|
|
2284
|
-
rejection: import_zod5.z.enum([
|
|
2285
|
-
"notification_destination_not_found",
|
|
2286
|
-
"notification_destination_generation_conflict",
|
|
2287
|
-
"notification_delivery_transition_unavailable"
|
|
2288
|
-
]).optional()
|
|
2289
|
-
}).strict().superRefine((value, context) => {
|
|
2290
|
-
if (value.state === "rejected" && !value.rejection) context.addIssue({
|
|
2291
|
-
code: "custom",
|
|
2292
|
-
message: "Rejected operation requires a rejection."
|
|
2293
|
-
});
|
|
2294
|
-
if (value.state === "committed" && !value.committed_at) context.addIssue({
|
|
2295
|
-
code: "custom",
|
|
2296
|
-
message: "Committed operation requires a timestamp."
|
|
2297
|
-
});
|
|
2298
|
-
});
|
|
2299
|
-
var destinationOperationMutationResponseSchema = import_zod5.z.object({
|
|
2300
|
-
state: import_zod5.z.enum([
|
|
2301
|
-
"prepared",
|
|
2302
|
-
"committed",
|
|
2303
|
-
"rejected"
|
|
2304
|
-
]),
|
|
2305
|
-
operation: notificationDestinationOperationSchema,
|
|
2306
|
-
replayed: import_zod5.z.boolean()
|
|
2307
|
-
}).strict();
|
|
2308
|
-
var destinationOperationLookupResponseSchema = import_zod5.z.union([
|
|
2309
|
-
import_zod5.z.object({
|
|
2310
|
-
state: import_zod5.z.literal("not-observed"),
|
|
2311
|
-
operation: import_zod5.z.null()
|
|
2312
|
-
}).strict(),
|
|
2313
|
-
import_zod5.z.object({
|
|
2314
|
-
state: import_zod5.z.enum([
|
|
2315
|
-
"prepared",
|
|
2316
|
-
"committed",
|
|
2317
|
-
"rejected"
|
|
2318
|
-
]),
|
|
2319
|
-
operation: notificationDestinationOperationSchema
|
|
2320
|
-
}).strict()
|
|
2321
|
-
]);
|
|
2322
|
-
var destinationOperationExecuteResponseSchema = destinationOperationMutationResponseSchema.extend({
|
|
2323
|
-
secret: import_zod5.z.string().regex(/^[a-f0-9]{64}$/).optional()
|
|
2324
|
-
}).strict();
|
|
2325
|
-
var NotificationsClient = class {
|
|
2326
|
-
static {
|
|
2327
|
-
__name(this, "NotificationsClient");
|
|
2328
|
-
}
|
|
2329
|
-
transport;
|
|
2330
|
-
authorize;
|
|
2331
|
-
origin;
|
|
2332
|
-
constructor(origin, transport, authorize) {
|
|
2333
|
-
this.transport = transport;
|
|
2334
|
-
this.authorize = authorize;
|
|
2335
|
-
const url = new URL(origin);
|
|
2336
|
-
if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash || url.pathname !== "/") throw new AccountError({
|
|
2337
|
-
code: "BAD_REQUEST",
|
|
2338
|
-
message: "Notifications API requires an HTTPS origin."
|
|
2339
|
-
});
|
|
2340
|
-
this.origin = url.origin;
|
|
2341
|
-
}
|
|
2342
|
-
async call(workspaceId, method, suffix, schema, body) {
|
|
2343
|
-
const url = `${this.origin}/api/workspaces/${id3.parse(workspaceId)}/notifications${suffix}`;
|
|
2344
|
-
const response = await this.transport.request({
|
|
2345
|
-
method,
|
|
2346
|
-
url,
|
|
2347
|
-
...body === void 0 ? {} : {
|
|
2348
|
-
body
|
|
2349
|
-
},
|
|
2350
|
-
authorization: /* @__PURE__ */ __name(async () => {
|
|
2351
|
-
const value = await this.authorize(method, url, {
|
|
2352
|
-
scopes: [
|
|
2353
|
-
method === "GET" ? "team:read" : "team:manage"
|
|
2354
|
-
],
|
|
2355
|
-
silent: true
|
|
2356
|
-
});
|
|
2357
|
-
if (!value) throw new AccountError({
|
|
2358
|
-
code: "INVALID_TOKEN",
|
|
2359
|
-
message: "Sign in to manage notifications."
|
|
2360
|
-
});
|
|
2361
|
-
return value;
|
|
2362
|
-
}, "authorization")
|
|
2363
|
-
});
|
|
2364
|
-
const parsed = schema.safeParse(response);
|
|
2365
|
-
if (!parsed.success) throw new AccountError({
|
|
2366
|
-
code: "INVALID_RESPONSE",
|
|
2367
|
-
message: "Invalid notification response."
|
|
2368
|
-
});
|
|
2369
|
-
return parsed.data;
|
|
2370
|
-
}
|
|
2371
|
-
read(workspaceId, scope) {
|
|
2372
|
-
return this.call(workspaceId, "GET", `/v2?scope=${encodeURIComponent(JSON.stringify(notificationScopeSchema.parse(scope)))}`, notificationSettingsSchema);
|
|
2373
|
-
}
|
|
2374
|
-
save(workspaceId, input) {
|
|
2375
|
-
const body = import_zod5.z.object({
|
|
2376
|
-
scope: notificationScopeSchema,
|
|
2377
|
-
expectedRevision: revision2,
|
|
2378
|
-
rules: import_zod5.z.array(notificationRuleSchema).max(20)
|
|
2379
|
-
}).strict().parse(input);
|
|
2380
|
-
return this.call(workspaceId, "POST", "/v2/settings", notificationSettingsSchema, body);
|
|
2381
|
-
}
|
|
2382
|
-
emit(workspaceId, input) {
|
|
2383
|
-
return this.call(workspaceId, "POST", "/events", import_zod5.z.object({
|
|
2384
|
-
success: import_zod5.z.literal(true),
|
|
2385
|
-
admitted: import_zod5.z.literal(true),
|
|
2386
|
-
duplicate: import_zod5.z.boolean()
|
|
2387
|
-
}), eventInputSchema.parse(input));
|
|
2388
|
-
}
|
|
2389
|
-
async prepareDestinationOperation(workspaceId, operationId, action) {
|
|
2390
|
-
const workspace = id3.parse(workspaceId), operation3 = id3.parse(operationId), request = notificationDestinationActionSchema.parse(action);
|
|
2391
|
-
const result = await this.call(workspace, "PUT", `/destination-operations/${operation3}`, destinationOperationMutationResponseSchema, request);
|
|
2392
|
-
if (result.operation.operation_id !== operation3 || result.operation.workspace_id !== workspace || result.operation.action !== request.action || result.operation.state !== result.state) throw new AccountError({
|
|
2393
|
-
code: "INVALID_RESPONSE",
|
|
2394
|
-
message: "Mismatched notification operation receipt."
|
|
2395
|
-
});
|
|
2396
|
-
return result;
|
|
2397
|
-
}
|
|
2398
|
-
async lookupDestinationOperation(workspaceId, operationId) {
|
|
2399
|
-
const workspace = id3.parse(workspaceId), operation3 = id3.parse(operationId);
|
|
2400
|
-
const result = await this.call(workspace, "GET", `/destination-operations/${operation3}`, destinationOperationLookupResponseSchema);
|
|
2401
|
-
if (result.operation && (result.operation.operation_id !== operation3 || result.operation.workspace_id !== workspace || result.operation.state !== result.state)) throw new AccountError({
|
|
2402
|
-
code: "INVALID_RESPONSE",
|
|
2403
|
-
message: "Mismatched notification operation receipt."
|
|
2404
|
-
});
|
|
2405
|
-
return result;
|
|
2406
|
-
}
|
|
2407
|
-
async executeDestinationOperation(workspaceId, operationId) {
|
|
2408
|
-
const workspace = id3.parse(workspaceId), operation3 = id3.parse(operationId);
|
|
2409
|
-
const result = await this.call(workspace, "POST", `/destination-operations/${operation3}`, destinationOperationExecuteResponseSchema);
|
|
2410
|
-
if (result.operation.operation_id !== operation3 || result.operation.workspace_id !== workspace || result.operation.state !== result.state || result.secret !== void 0 && (result.operation.action !== "create" || result.state !== "committed" || result.replayed)) throw new AccountError({
|
|
2411
|
-
code: "INVALID_RESPONSE",
|
|
2412
|
-
message: "Mismatched notification operation receipt."
|
|
2413
|
-
});
|
|
2414
|
-
return result;
|
|
2415
|
-
}
|
|
2416
|
-
};
|
|
2417
|
-
|
|
2418
|
-
// src/integrations.ts
|
|
2419
|
-
var import_zod6 = require("zod");
|
|
2420
|
-
var id4 = import_zod6.z.string().uuid();
|
|
2421
|
-
var provider = import_zod6.z.enum([
|
|
2422
|
-
"google",
|
|
2423
|
-
"github",
|
|
2424
|
-
"twitter"
|
|
2425
|
-
]);
|
|
2426
|
-
var linked = import_zod6.z.object({
|
|
2427
|
-
provider,
|
|
2428
|
-
email: import_zod6.z.string().email().nullable(),
|
|
2429
|
-
username: import_zod6.z.string().nullable(),
|
|
2430
|
-
created_at: import_zod6.z.string().datetime({
|
|
2431
|
-
offset: true
|
|
2432
|
-
}).optional()
|
|
2433
|
-
}).passthrough();
|
|
2434
|
-
var integration = import_zod6.z.object({
|
|
2435
|
-
provider,
|
|
2436
|
-
available: import_zod6.z.boolean(),
|
|
2437
|
-
scopes: import_zod6.z.array(import_zod6.z.string().min(1)).max(16),
|
|
2438
|
-
linked: linked.nullable()
|
|
2439
|
-
}).strict();
|
|
2440
|
-
var operation2 = import_zod6.z.object({
|
|
2441
|
-
operationId: id4,
|
|
2442
|
-
actorAccountId: id4.optional(),
|
|
2443
|
-
clientId: import_zod6.z.string().optional(),
|
|
2444
|
-
provider: provider.optional(),
|
|
2445
|
-
scopes: import_zod6.z.array(import_zod6.z.string()).optional(),
|
|
2446
|
-
state: import_zod6.z.enum([
|
|
2447
|
-
"not-observed",
|
|
2448
|
-
"waiting",
|
|
2449
|
-
"exchanging",
|
|
2450
|
-
"committed",
|
|
2451
|
-
"rejected",
|
|
2452
|
-
"cancelled"
|
|
2453
|
-
]),
|
|
2454
|
-
authorizationUrl: import_zod6.z.string().url().optional(),
|
|
2455
|
-
expiresAt: import_zod6.z.string().datetime({
|
|
2456
|
-
offset: true
|
|
2457
|
-
}).optional(),
|
|
2458
|
-
linked: linked.optional(),
|
|
2459
|
-
rejection: import_zod6.z.string().optional(),
|
|
2460
|
-
replayed: import_zod6.z.boolean().optional()
|
|
2461
|
-
}).strict();
|
|
2462
|
-
var AccountIntegrationClient = class {
|
|
2463
|
-
static {
|
|
2464
|
-
__name(this, "AccountIntegrationClient");
|
|
2465
|
-
}
|
|
2466
|
-
transport;
|
|
2467
|
-
authorize;
|
|
2468
|
-
base;
|
|
2469
|
-
constructor(base2, transport, authorize) {
|
|
2470
|
-
this.transport = transport;
|
|
2471
|
-
this.authorize = authorize;
|
|
2472
|
-
this.base = new URL(base2).origin;
|
|
2473
|
-
}
|
|
2474
|
-
async call(method, path, schema, body, idempotencyKey) {
|
|
2475
|
-
const url = `${this.base}/api/account-integrations${path}`, raw = await this.transport.request({
|
|
2476
|
-
method,
|
|
2477
|
-
url,
|
|
2478
|
-
...body === void 0 ? {} : {
|
|
2479
|
-
body
|
|
2480
|
-
},
|
|
2481
|
-
...idempotencyKey ? {
|
|
2482
|
-
idempotencyKey
|
|
2483
|
-
} : {},
|
|
2484
|
-
authorization: /* @__PURE__ */ __name(async () => {
|
|
2485
|
-
const value = await this.authorize(method, url, {
|
|
2486
|
-
scopes: [
|
|
2487
|
-
"openid"
|
|
2488
|
-
],
|
|
2489
|
-
silent: true
|
|
2490
|
-
});
|
|
2491
|
-
if (!value) throw new AccountError({
|
|
2492
|
-
code: "INVALID_TOKEN",
|
|
2493
|
-
message: "Sign in to manage account integrations."
|
|
2494
|
-
});
|
|
2495
|
-
return value;
|
|
2496
|
-
}, "authorization")
|
|
2497
|
-
});
|
|
2498
|
-
const parsed = schema.safeParse(raw);
|
|
2499
|
-
if (!parsed.success) throw new AccountError({
|
|
2500
|
-
code: "INVALID_RESPONSE",
|
|
2501
|
-
message: "Invalid account integration response."
|
|
2502
|
-
});
|
|
2503
|
-
return parsed.data;
|
|
2504
|
-
}
|
|
2505
|
-
async list() {
|
|
2506
|
-
return (await this.call("GET", "", import_zod6.z.object({
|
|
2507
|
-
success: import_zod6.z.literal(true),
|
|
2508
|
-
providers: import_zod6.z.array(integration)
|
|
2509
|
-
}).strict())).providers;
|
|
2510
|
-
}
|
|
2511
|
-
async operation(operationId) {
|
|
2512
|
-
return (await this.call("GET", `/operations/${id4.parse(operationId)}`, import_zod6.z.object({
|
|
2513
|
-
success: import_zod6.z.literal(true),
|
|
2514
|
-
operation: operation2
|
|
2515
|
-
}).strict())).operation;
|
|
2516
|
-
}
|
|
2517
|
-
async start(operationId, value) {
|
|
2518
|
-
const operationIdValue = id4.parse(operationId), result = (await this.call("POST", `/${provider.parse(value)}/operations/${operationIdValue}/start`, import_zod6.z.object({
|
|
2519
|
-
success: import_zod6.z.literal(true),
|
|
2520
|
-
operation: operation2
|
|
2521
|
-
}).strict(), {}, operationIdValue)).operation;
|
|
2522
|
-
if (result.operationId !== operationIdValue || result.provider !== value || result.state !== "waiting" || !result.authorizationUrl) throw new AccountError({
|
|
2523
|
-
code: "INVALID_RESPONSE",
|
|
2524
|
-
message: "Invalid provider authorization operation."
|
|
2525
|
-
});
|
|
2526
|
-
const url = new URL(result.authorizationUrl);
|
|
2527
|
-
if (url.protocol !== "https:" || url.username || url.password) throw new AccountError({
|
|
2528
|
-
code: "INVALID_RESPONSE",
|
|
2529
|
-
message: "Untrusted provider authorization URL."
|
|
2530
|
-
});
|
|
2531
|
-
return result;
|
|
2532
|
-
}
|
|
2533
|
-
async cancel(operationId) {
|
|
2534
|
-
return (await this.call("POST", `/operations/${id4.parse(operationId)}/cancel`, import_zod6.z.object({
|
|
2535
|
-
success: import_zod6.z.literal(true),
|
|
2536
|
-
operation: operation2
|
|
2537
|
-
}).strict(), {})).operation;
|
|
2538
|
-
}
|
|
2539
|
-
};
|
|
2540
|
-
|
|
2541
|
-
// src/verification.ts
|
|
2542
|
-
var jwksCache = /* @__PURE__ */ new Map();
|
|
2543
|
-
function bytes(value) {
|
|
2544
|
-
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
2545
|
-
const bin = atob(normalized + "=".repeat((4 - normalized.length % 4) % 4));
|
|
2546
|
-
return Uint8Array.from(bin, (char) => char.charCodeAt(0));
|
|
2547
|
-
}
|
|
2548
|
-
__name(bytes, "bytes");
|
|
2549
|
-
function decode(token) {
|
|
2550
|
-
const parts = token.split(".");
|
|
2551
|
-
if (parts.length !== 3 || !parts[0] || !parts[1] || !parts[2]) throw invalid("malformed JWT");
|
|
2552
|
-
try {
|
|
2553
|
-
return {
|
|
2554
|
-
header: JSON.parse(new TextDecoder().decode(bytes(parts[0]))),
|
|
2555
|
-
payload: JSON.parse(new TextDecoder().decode(bytes(parts[1]))),
|
|
2556
|
-
signingInput: new TextEncoder().encode(`${parts[0]}.${parts[1]}`),
|
|
2557
|
-
signature: bytes(parts[2])
|
|
2558
|
-
};
|
|
2559
|
-
} catch {
|
|
2560
|
-
throw invalid("malformed JWT");
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
__name(decode, "decode");
|
|
2564
|
-
function invalid(message) {
|
|
2565
|
-
return new AccountError({
|
|
2566
|
-
code: "INVALID_RESPONSE",
|
|
2567
|
-
message: `OIDC verification failed: ${message}`
|
|
2568
|
-
});
|
|
2569
|
-
}
|
|
2570
|
-
__name(invalid, "invalid");
|
|
2571
|
-
function audience(value, expected) {
|
|
2572
|
-
return value === expected || Array.isArray(value) && value.includes(expected);
|
|
2573
|
-
}
|
|
2574
|
-
__name(audience, "audience");
|
|
2575
|
-
async function fetchJwks(transport, issuer, jwksUrl, force = false) {
|
|
2576
|
-
const url = jwksUrl ?? `${issuer.replace(/\/+$/, "")}/api/oauth2/jwks`;
|
|
2577
|
-
const cached = jwksCache.get(url);
|
|
2578
|
-
if (!force && cached && cached.expiresAt > Date.now()) return cached.keys;
|
|
2579
|
-
const response = await transport.request({
|
|
2580
|
-
method: "GET",
|
|
2581
|
-
url
|
|
2582
|
-
});
|
|
2583
|
-
if (!Array.isArray(response.keys) || response.keys.length === 0) throw invalid("empty JWKS");
|
|
2584
|
-
jwksCache.set(url, {
|
|
2585
|
-
keys: response.keys,
|
|
2586
|
-
expiresAt: Date.now() + 5 * 6e4
|
|
2587
|
-
});
|
|
2588
|
-
return response.keys;
|
|
2589
|
-
}
|
|
2590
|
-
__name(fetchJwks, "fetchJwks");
|
|
2591
|
-
async function verifySignature(decoded, keys) {
|
|
2592
|
-
if (decoded.header.alg !== "ES256" || typeof decoded.header.kid !== "string") return "invalid";
|
|
2593
|
-
const jwk = keys.find((candidate) => candidate.kid === decoded.header.kid && candidate.kty === "EC" && candidate.crv === "P-256");
|
|
2594
|
-
if (!jwk) return "unknown-kid";
|
|
2595
|
-
try {
|
|
2596
|
-
const key = await globalThis.crypto.subtle.importKey("jwk", jwk, {
|
|
2597
|
-
name: "ECDSA",
|
|
2598
|
-
namedCurve: "P-256"
|
|
2599
|
-
}, false, [
|
|
2600
|
-
"verify"
|
|
2601
|
-
]);
|
|
2602
|
-
return await globalThis.crypto.subtle.verify({
|
|
2603
|
-
name: "ECDSA",
|
|
2604
|
-
hash: "SHA-256"
|
|
2605
|
-
}, key, decoded.signature, decoded.signingInput) ? "valid" : "invalid";
|
|
2606
|
-
} catch {
|
|
2607
|
-
return "invalid";
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
__name(verifySignature, "verifySignature");
|
|
2611
|
-
async function verifiedPayload(token, transport, issuer, jwksUrl) {
|
|
2612
|
-
const decoded = decode(token);
|
|
2613
|
-
let keys = await fetchJwks(transport, issuer, jwksUrl);
|
|
2614
|
-
let result = await verifySignature(decoded, keys);
|
|
2615
|
-
if (result === "unknown-kid") {
|
|
2616
|
-
keys = await fetchJwks(transport, issuer, jwksUrl, true);
|
|
2617
|
-
result = await verifySignature(decoded, keys);
|
|
2618
|
-
}
|
|
2619
|
-
if (result !== "valid") throw invalid("signature or algorithm");
|
|
2620
|
-
return decoded;
|
|
2621
|
-
}
|
|
2622
|
-
__name(verifiedPayload, "verifiedPayload");
|
|
2623
|
-
function temporal(payload, now) {
|
|
2624
|
-
if (!Number.isInteger(payload.exp) || Number(payload.exp) <= now) throw invalid("token expired");
|
|
2625
|
-
if (!Number.isInteger(payload.iat) || Number(payload.iat) > now + 60) throw invalid("invalid issued-at time");
|
|
2626
|
-
if (payload.nbf !== void 0 && (!Number.isInteger(payload.nbf) || Number(payload.nbf) > now + 60)) throw invalid("token not yet valid");
|
|
2627
|
-
}
|
|
2628
|
-
__name(temporal, "temporal");
|
|
2629
|
-
var XENO_ISSUER_PAIR = [
|
|
2630
|
-
"https://xenostudio.ai",
|
|
2631
|
-
"https://xenosystem.ai"
|
|
2632
|
-
];
|
|
2633
|
-
function issuerAccepted(iss, configured) {
|
|
2634
|
-
if (typeof iss !== "string") return false;
|
|
2635
|
-
const want = configured.replace(/\/+$/, "");
|
|
2636
|
-
if (iss === configured || iss === want) return true;
|
|
2637
|
-
return XENO_ISSUER_PAIR.includes(want) && XENO_ISSUER_PAIR.includes(iss);
|
|
2638
|
-
}
|
|
2639
|
-
__name(issuerAccepted, "issuerAccepted");
|
|
2640
|
-
async function verifyAccessToken(args) {
|
|
2641
|
-
const decoded = await verifiedPayload(args.token, args.transport, args.issuer, args.jwksUrl);
|
|
2642
|
-
const p = decoded.payload;
|
|
2643
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
2644
|
-
temporal(p, now);
|
|
2645
|
-
if (decoded.header.typ !== "at+jwt" || p.typ !== "at+jwt" || !issuerAccepted(p.iss, args.issuer) || !audience(p.aud, "xeno-api")) throw invalid("access-token profile");
|
|
2646
|
-
if (p.client_id !== args.clientId || p.azp !== args.clientId) throw invalid("client binding");
|
|
2647
|
-
if (typeof p.sub !== "string" || typeof p.sid !== "string" || !Number.isInteger(p.auth_epoch)) throw invalid("session claims");
|
|
2648
|
-
if (!p.cnf || typeof p.cnf !== "object" || p.cnf.jkt !== args.dpopJkt) throw invalid("DPoP binding");
|
|
2649
|
-
if (p.act !== void 0) {
|
|
2650
|
-
const act = p.act;
|
|
2651
|
-
if (act.client_id !== "xeno-hub" || typeof act.installation_id_hash !== "string" || !act.installation_id_hash) throw invalid("broker actor");
|
|
2652
|
-
}
|
|
2653
|
-
if (args.requireBrokerActor && p.act === void 0) throw invalid("missing broker actor");
|
|
2654
|
-
const held = new Set(String(p.scope ?? "").split(/\s+/).filter(Boolean));
|
|
2655
|
-
for (const scope of args.expectedScopes ?? []) if (!held.has(scope)) throw invalid(`missing scope ${scope}`);
|
|
2656
|
-
return p;
|
|
2657
|
-
}
|
|
2658
|
-
__name(verifyAccessToken, "verifyAccessToken");
|
|
2659
|
-
async function verifyIdToken(args) {
|
|
2660
|
-
const decoded = await verifiedPayload(args.token, args.transport, args.issuer, args.jwksUrl);
|
|
2661
|
-
const p = decoded.payload;
|
|
2662
|
-
temporal(p, Math.floor(Date.now() / 1e3));
|
|
2663
|
-
if (!issuerAccepted(p.iss, args.issuer) || !audience(p.aud, args.clientId) || typeof p.sub !== "string" || typeof p.sid !== "string" || !Number.isInteger(p.auth_time)) throw invalid("ID-token profile");
|
|
2664
|
-
if (args.expectedNonce !== void 0 && p.nonce !== args.expectedNonce) throw invalid("nonce mismatch");
|
|
2665
|
-
if (args.expectedSubject !== void 0 && p.sub !== args.expectedSubject) throw invalid("subject mismatch");
|
|
2666
|
-
return p;
|
|
2667
|
-
}
|
|
2668
|
-
__name(verifyIdToken, "verifyIdToken");
|
|
2669
|
-
async function verifyLogoutToken(args) {
|
|
2670
|
-
const decoded = await verifiedPayload(args.token, args.transport, args.issuer, args.jwksUrl);
|
|
2671
|
-
const p = decoded.payload;
|
|
2672
|
-
temporal(p, Math.floor(Date.now() / 1e3));
|
|
2673
|
-
const event = "http://schemas.openid.net/event/backchannel-logout";
|
|
2674
|
-
if (decoded.header.typ !== "logout+jwt" || !issuerAccepted(p.iss, args.issuer) || !audience(p.aud, args.clientId)) throw invalid("logout-token profile");
|
|
2675
|
-
if (typeof p.jti !== "string" || !p.jti || p.nonce !== void 0) throw invalid("logout-token claims");
|
|
2676
|
-
if (typeof p.sid !== "string" && typeof p.sub !== "string") throw invalid("logout subject");
|
|
2677
|
-
if (!p.events || typeof p.events !== "object" || !(event in p.events)) throw invalid("logout event");
|
|
2678
|
-
return p;
|
|
2679
|
-
}
|
|
2680
|
-
__name(verifyLogoutToken, "verifyLogoutToken");
|
|
2681
|
-
|
|
2682
|
-
// src/oidc.ts
|
|
2683
|
-
async function generatePkce() {
|
|
2684
|
-
const verifierBytes = new Uint8Array(32);
|
|
2685
|
-
globalThis.crypto.getRandomValues(verifierBytes);
|
|
2686
|
-
const verifier = base64url(verifierBytes);
|
|
2687
|
-
const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
|
|
2688
|
-
return {
|
|
2689
|
-
verifier,
|
|
2690
|
-
challenge: base64url(new Uint8Array(digest))
|
|
2691
|
-
};
|
|
2692
|
-
}
|
|
2693
|
-
__name(generatePkce, "generatePkce");
|
|
2694
|
-
function generateState() {
|
|
2695
|
-
const b = new Uint8Array(24);
|
|
2696
|
-
globalThis.crypto.getRandomValues(b);
|
|
2697
|
-
return base64url(b);
|
|
2698
|
-
}
|
|
2699
|
-
__name(generateState, "generateState");
|
|
2700
|
-
function base64url(bytes2) {
|
|
2701
|
-
let bin = "";
|
|
2702
|
-
for (let i = 0; i < bytes2.length; i += 1) bin += String.fromCharCode(bytes2[i]);
|
|
2703
|
-
const b64 = typeof btoa === "function" ? btoa(bin) : Buffer.from(bytes2).toString("base64");
|
|
2704
|
-
return b64.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
2705
|
-
}
|
|
2706
|
-
__name(base64url, "base64url");
|
|
2707
|
-
function endpoints(cfg) {
|
|
2708
|
-
const base2 = cfg.issuer.replace(/\/+$/, "");
|
|
2709
|
-
return {
|
|
2710
|
-
authorize: cfg.authorizeUrl ?? `${base2}/api/oauth2/authorize`,
|
|
2711
|
-
token: cfg.tokenUrl ?? `${base2}/api/oauth2/token`,
|
|
2712
|
-
device: cfg.deviceAuthorizationUrl ?? `${base2}/api/oauth2/device_authorization`
|
|
2713
|
-
};
|
|
2714
|
-
}
|
|
2715
|
-
__name(endpoints, "endpoints");
|
|
2716
|
-
var DEFAULT_SCOPES = [
|
|
2717
|
-
"openid",
|
|
2718
|
-
"profile",
|
|
2719
|
-
"email",
|
|
2720
|
-
"ledger"
|
|
2721
|
-
];
|
|
2722
|
-
function buildAuthorizeUrl(cfg, args) {
|
|
2723
|
-
const redirectUri = args.redirectUri ?? cfg.redirectUri;
|
|
2724
|
-
if (!redirectUri) {
|
|
2725
|
-
throw new AccountError({
|
|
2726
|
-
code: "BAD_REQUEST",
|
|
2727
|
-
message: "redirectUri required for authorize"
|
|
2728
|
-
});
|
|
2729
|
-
}
|
|
2730
|
-
const url = new URL(endpoints(cfg).authorize);
|
|
2731
|
-
url.searchParams.set("response_type", "code");
|
|
2732
|
-
url.searchParams.set("client_id", cfg.clientId);
|
|
2733
|
-
url.searchParams.set("redirect_uri", redirectUri);
|
|
2734
|
-
url.searchParams.set("scope", (args.scopes ?? cfg.scopes ?? DEFAULT_SCOPES).join(" "));
|
|
2735
|
-
url.searchParams.set("state", args.state);
|
|
2736
|
-
url.searchParams.set("code_challenge", args.codeChallenge);
|
|
2737
|
-
url.searchParams.set("code_challenge_method", "S256");
|
|
2738
|
-
if (args.nonce) url.searchParams.set("nonce", args.nonce);
|
|
2739
|
-
if (args.prompt) url.searchParams.set("prompt", args.prompt);
|
|
2740
|
-
if (args.maxAge !== void 0) url.searchParams.set("max_age", String(args.maxAge));
|
|
2741
|
-
if (args.acrValues) url.searchParams.set("acr_values", args.acrValues);
|
|
2742
|
-
return url.toString();
|
|
2743
|
-
}
|
|
2744
|
-
__name(buildAuthorizeUrl, "buildAuthorizeUrl");
|
|
2745
|
-
async function exchangeCode(cfg, transport, args) {
|
|
2746
|
-
const redirectUri = args.redirectUri ?? cfg.redirectUri;
|
|
2747
|
-
if (!redirectUri) {
|
|
2748
|
-
throw new AccountError({
|
|
2749
|
-
code: "BAD_REQUEST",
|
|
2750
|
-
message: "redirectUri required for code exchange"
|
|
2751
|
-
});
|
|
2752
|
-
}
|
|
2753
|
-
const body = new URLSearchParams({
|
|
2754
|
-
grant_type: "authorization_code",
|
|
2755
|
-
code: args.code,
|
|
2756
|
-
redirect_uri: redirectUri,
|
|
2757
|
-
client_id: cfg.clientId,
|
|
2758
|
-
code_verifier: args.codeVerifier
|
|
2759
|
-
});
|
|
2760
|
-
if (cfg.clientSecret) body.set("client_secret", cfg.clientSecret);
|
|
2761
|
-
return postToken(cfg, transport, body, {
|
|
2762
|
-
requireIdToken: true,
|
|
2763
|
-
expectedNonce: args.expectedNonce,
|
|
2764
|
-
expectedScopes: args.expectedScopes,
|
|
2765
|
-
signal: args.signal
|
|
2766
|
-
});
|
|
2767
|
-
}
|
|
2768
|
-
__name(exchangeCode, "exchangeCode");
|
|
2769
|
-
async function refreshTokens(cfg, transport, refreshToken, rotationId) {
|
|
2770
|
-
const body = new URLSearchParams({
|
|
2771
|
-
grant_type: "refresh_token",
|
|
2772
|
-
refresh_token: refreshToken,
|
|
2773
|
-
client_id: cfg.clientId
|
|
2774
|
-
});
|
|
2775
|
-
if (cfg.clientSecret) body.set("client_secret", cfg.clientSecret);
|
|
2776
|
-
if (rotationId) body.set("rotation_id", rotationId);
|
|
2777
|
-
return postToken(cfg, transport, body);
|
|
2778
|
-
}
|
|
2779
|
-
__name(refreshTokens, "refreshTokens");
|
|
2780
|
-
async function startDeviceAuthorization(cfg, transport, scopes) {
|
|
2781
|
-
const body = new URLSearchParams({
|
|
2782
|
-
client_id: cfg.clientId,
|
|
2783
|
-
scope: (scopes ?? cfg.scopes ?? DEFAULT_SCOPES).join(" ")
|
|
2784
|
-
});
|
|
2785
|
-
const raw = await transport.request({
|
|
2786
|
-
method: "POST",
|
|
2787
|
-
url: endpoints(cfg).device,
|
|
2788
|
-
headers: {
|
|
2789
|
-
"content-type": "application/x-www-form-urlencoded"
|
|
2790
|
-
},
|
|
2791
|
-
body: body.toString()
|
|
2792
|
-
});
|
|
2793
|
-
const expiresIn = Number(raw["expires_in"] ?? 600);
|
|
2794
|
-
return {
|
|
2795
|
-
deviceCode: String(raw["device_code"] ?? ""),
|
|
2796
|
-
userCode: String(raw["user_code"] ?? ""),
|
|
2797
|
-
verificationUri: String(raw["verification_uri"] ?? ""),
|
|
2798
|
-
verificationUriComplete: typeof raw["verification_uri_complete"] === "string" ? raw["verification_uri_complete"] : null,
|
|
2799
|
-
expiresAt: new Date(Date.now() + expiresIn * 1e3),
|
|
2800
|
-
intervalSeconds: Number(raw["interval"] ?? 5)
|
|
2801
|
-
};
|
|
2802
|
-
}
|
|
2803
|
-
__name(startDeviceAuthorization, "startDeviceAuthorization");
|
|
2804
|
-
async function pollDeviceToken(cfg, transport, device, opts = {}) {
|
|
2805
|
-
const sleep2 = opts.sleep ?? ((ms) => new Promise((resolve) => {
|
|
2806
|
-
const signal = opts.signal;
|
|
2807
|
-
const timer = setTimeout(done, ms);
|
|
2808
|
-
function done() {
|
|
2809
|
-
clearTimeout(timer);
|
|
2810
|
-
signal?.removeEventListener("abort", done);
|
|
2811
|
-
resolve();
|
|
2812
|
-
}
|
|
2813
|
-
__name(done, "done");
|
|
2814
|
-
signal?.addEventListener("abort", done, {
|
|
2815
|
-
once: true
|
|
2816
|
-
});
|
|
2817
|
-
if (signal?.aborted) done();
|
|
2818
|
-
}));
|
|
2819
|
-
let intervalMs = device.intervalSeconds * 1e3;
|
|
2820
|
-
while (Date.now() < device.expiresAt.getTime()) {
|
|
2821
|
-
if (opts.signal?.aborted) {
|
|
2822
|
-
throw new AccountError({
|
|
2823
|
-
code: "BAD_REQUEST",
|
|
2824
|
-
message: "device authorization aborted"
|
|
2825
|
-
});
|
|
2826
|
-
}
|
|
2827
|
-
await sleep2(intervalMs);
|
|
2828
|
-
if (opts.signal?.aborted) {
|
|
2829
|
-
throw new AccountError({
|
|
2830
|
-
code: "BAD_REQUEST",
|
|
2831
|
-
message: "device authorization aborted"
|
|
2832
|
-
});
|
|
2833
|
-
}
|
|
2834
|
-
if (Date.now() >= device.expiresAt.getTime()) break;
|
|
2835
|
-
const body = new URLSearchParams({
|
|
2836
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
2837
|
-
device_code: device.deviceCode,
|
|
2838
|
-
client_id: cfg.clientId
|
|
2839
|
-
});
|
|
2840
|
-
try {
|
|
2841
|
-
const tokens = await postToken(cfg, transport, body, {
|
|
2842
|
-
requireIdToken: true,
|
|
2843
|
-
signal: opts.signal
|
|
2844
|
-
});
|
|
2845
|
-
if (opts.signal?.aborted) throw new AccountError({
|
|
2846
|
-
code: "BAD_REQUEST",
|
|
2847
|
-
message: "device authorization aborted"
|
|
2848
|
-
});
|
|
2849
|
-
return tokens;
|
|
2850
|
-
} catch (err) {
|
|
2851
|
-
if (!(err instanceof AccountError)) throw err;
|
|
2852
|
-
const oauthErr = err.oauthError;
|
|
2853
|
-
if (err.httpStatus === 400 && oauthErr === "authorization_pending") continue;
|
|
2854
|
-
if (err.httpStatus === 400 && oauthErr === "slow_down") {
|
|
2855
|
-
intervalMs += 5e3;
|
|
2856
|
-
continue;
|
|
2857
|
-
}
|
|
2858
|
-
throw err;
|
|
2859
|
-
}
|
|
2860
|
-
}
|
|
2861
|
-
throw new AccountError({
|
|
2862
|
-
code: "BAD_REQUEST",
|
|
2863
|
-
message: "device code expired before approval"
|
|
2864
|
-
});
|
|
2865
|
-
}
|
|
2866
|
-
__name(pollDeviceToken, "pollDeviceToken");
|
|
2867
|
-
async function postToken(cfg, transport, body, verify = {}) {
|
|
2868
|
-
const tokenUrl = endpoints(cfg).token;
|
|
2869
|
-
const dpop = await cfg.dpopSigner.createProof({
|
|
2870
|
-
method: "POST",
|
|
2871
|
-
url: tokenUrl
|
|
2872
|
-
});
|
|
2873
|
-
if (verify.signal?.aborted) throw new AccountError({
|
|
2874
|
-
code: "BAD_REQUEST",
|
|
2875
|
-
message: "Account sign-in was cancelled",
|
|
2876
|
-
retryable: false
|
|
2877
|
-
});
|
|
2878
|
-
const raw = await transport.request({
|
|
2879
|
-
method: "POST",
|
|
2880
|
-
url: tokenUrl,
|
|
2881
|
-
headers: {
|
|
2882
|
-
"content-type": "application/x-www-form-urlencoded",
|
|
2883
|
-
dpop
|
|
2884
|
-
},
|
|
2885
|
-
body: body.toString(),
|
|
2886
|
-
oauthErrorResponse: true,
|
|
2887
|
-
signal: verify.signal
|
|
2888
|
-
});
|
|
2889
|
-
const parsed = oauthTokenResponseSchema.safeParse(raw);
|
|
2890
|
-
if (!parsed.success) {
|
|
2891
|
-
throw new AccountError({
|
|
2892
|
-
code: "INVALID_RESPONSE",
|
|
2893
|
-
message: "token endpoint returned an unrecognised shape"
|
|
2894
|
-
});
|
|
2895
|
-
}
|
|
2896
|
-
const t = parsed.data;
|
|
2897
|
-
if (t.token_type.toLowerCase() !== "dpop") throw new AccountError({
|
|
2898
|
-
code: "INVALID_RESPONSE",
|
|
2899
|
-
message: "token endpoint did not issue a DPoP token"
|
|
2900
|
-
});
|
|
2901
|
-
if (verify.requireIdToken && !t.id_token) throw new AccountError({
|
|
2902
|
-
code: "INVALID_RESPONSE",
|
|
2903
|
-
message: "token endpoint omitted id_token"
|
|
2904
|
-
});
|
|
2905
|
-
const accessClaims = await verifyAccessToken({
|
|
2906
|
-
token: t.access_token,
|
|
2907
|
-
transport,
|
|
2908
|
-
issuer: cfg.issuer,
|
|
2909
|
-
clientId: cfg.clientId,
|
|
2910
|
-
dpopJkt: cfg.dpopSigner.jkt,
|
|
2911
|
-
jwksUrl: cfg.jwksUrl,
|
|
2912
|
-
expectedScopes: verify.expectedScopes
|
|
2913
|
-
});
|
|
2914
|
-
const idClaims = t.id_token ? await verifyIdToken({
|
|
2915
|
-
token: t.id_token,
|
|
2916
|
-
transport,
|
|
2917
|
-
issuer: cfg.issuer,
|
|
2918
|
-
clientId: cfg.clientId,
|
|
2919
|
-
jwksUrl: cfg.jwksUrl,
|
|
2920
|
-
expectedNonce: verify.expectedNonce,
|
|
2921
|
-
expectedSubject: accessClaims.sub
|
|
2922
|
-
}) : null;
|
|
2923
|
-
return tokenSetSchema.parse({
|
|
2924
|
-
accessToken: t.access_token,
|
|
2925
|
-
tokenType: t.token_type,
|
|
2926
|
-
expiresAt: t.expires_in ? new Date(Date.now() + t.expires_in * 1e3) : null,
|
|
2927
|
-
refreshToken: t.refresh_token ?? null,
|
|
2928
|
-
idToken: t.id_token ?? null,
|
|
2929
|
-
scope: t.scope ? t.scope.split(/\s+/).filter(Boolean) : [],
|
|
2930
|
-
sid: idClaims?.sid ?? accessClaims.sid,
|
|
2931
|
-
accessClaims,
|
|
2932
|
-
idClaims
|
|
2933
|
-
});
|
|
2934
|
-
}
|
|
2935
|
-
__name(postToken, "postToken");
|
|
2936
|
-
|
|
2937
|
-
// src/tokenStore.ts
|
|
2938
|
-
function memoryStore() {
|
|
2939
|
-
const m = /* @__PURE__ */ new Map();
|
|
2940
|
-
const locks = /* @__PURE__ */ new Map();
|
|
2941
|
-
return {
|
|
2942
|
-
async withExclusive(key, work) {
|
|
2943
|
-
const prior = locks.get(key) ?? Promise.resolve();
|
|
2944
|
-
let release;
|
|
2945
|
-
const held = new Promise((resolve) => {
|
|
2946
|
-
release = resolve;
|
|
2947
|
-
});
|
|
2948
|
-
const tail = prior.then(() => held);
|
|
2949
|
-
locks.set(key, tail);
|
|
2950
|
-
await prior;
|
|
2951
|
-
try {
|
|
2952
|
-
return await work();
|
|
2953
|
-
} finally {
|
|
2954
|
-
release();
|
|
2955
|
-
if (locks.get(key) === tail) locks.delete(key);
|
|
2956
|
-
}
|
|
2957
|
-
},
|
|
2958
|
-
async get(k) {
|
|
2959
|
-
return m.get(k) ?? null;
|
|
2960
|
-
},
|
|
2961
|
-
async set(k, v) {
|
|
2962
|
-
m.set(k, v);
|
|
2963
|
-
},
|
|
2964
|
-
async delete(k) {
|
|
2965
|
-
m.delete(k);
|
|
2966
|
-
}
|
|
2967
|
-
};
|
|
2968
|
-
}
|
|
2969
|
-
__name(memoryStore, "memoryStore");
|
|
2970
|
-
function keychainStore(kc) {
|
|
2971
|
-
return {
|
|
2972
|
-
...kc.withExclusive ? {
|
|
2973
|
-
withExclusive: /* @__PURE__ */ __name((key, work) => kc.withExclusive(key, work), "withExclusive")
|
|
2974
|
-
} : {},
|
|
2975
|
-
async get(k) {
|
|
2976
|
-
return await kc.get(k) ?? null;
|
|
2977
|
-
},
|
|
2978
|
-
async set(k, v) {
|
|
2979
|
-
await kc.set(k, v);
|
|
2980
|
-
},
|
|
2981
|
-
async delete(k) {
|
|
2982
|
-
await kc.delete(k);
|
|
2983
|
-
}
|
|
2984
|
-
};
|
|
2985
|
-
}
|
|
2986
|
-
__name(keychainStore, "keychainStore");
|
|
2987
|
-
|
|
2988
|
-
// src/client.ts
|
|
2989
|
-
var XenoAccountClient = class {
|
|
2990
|
-
static {
|
|
2991
|
-
__name(this, "XenoAccountClient");
|
|
2992
|
-
}
|
|
2993
|
-
surface;
|
|
2994
|
-
account;
|
|
2995
|
-
ledger;
|
|
2996
|
-
authz;
|
|
2997
|
-
oidcConfig;
|
|
2998
|
-
issuer;
|
|
2999
|
-
authorities = {};
|
|
3000
|
-
transport;
|
|
3001
|
-
store;
|
|
3002
|
-
apiKey;
|
|
3003
|
-
broker;
|
|
3004
|
-
refreshStoreKey;
|
|
3005
|
-
refreshPendingKey;
|
|
3006
|
-
access = null;
|
|
3007
|
-
user = null;
|
|
3008
|
-
interactive;
|
|
3009
|
-
resolutionFlight = null;
|
|
3010
|
-
generation = 0;
|
|
3011
|
-
locallySignedOut = false;
|
|
3012
|
-
listeners = /* @__PURE__ */ new Set();
|
|
3013
|
-
constructor(cfg) {
|
|
3014
|
-
this.surface = surfaceSchema.parse(cfg.surface);
|
|
3015
|
-
this.transport = new Transport(cfg.transport);
|
|
3016
|
-
this.oidcConfig = {
|
|
3017
|
-
issuer: cfg.issuer,
|
|
3018
|
-
...cfg.oidc
|
|
3019
|
-
};
|
|
3020
|
-
this.refreshStoreKey = `xeno.account/${this.oidcConfig.clientId}/refresh`;
|
|
3021
|
-
this.refreshPendingKey = `${this.refreshStoreKey}/pending`;
|
|
3022
|
-
this.account = new AccountClient(cfg.issuer, this.transport);
|
|
3023
|
-
this.ledger = new LedgerClient(cfg.apiBase, this.transport);
|
|
3024
|
-
this.authz = new AuthzClient(cfg.apiBase, this.transport);
|
|
3025
|
-
this.issuer = cfg.issuer;
|
|
3026
|
-
this.store = cfg.store ?? memoryStore();
|
|
3027
|
-
this.apiKey = cfg.apiKey ?? (typeof process !== "undefined" ? process.env?.XENO_API_KEY : void 0) ?? void 0;
|
|
3028
|
-
this.broker = cfg.broker;
|
|
3029
|
-
}
|
|
3030
|
-
// ─── Workspace, workforce, notification and integration authorities ───────
|
|
3031
|
-
//
|
|
3032
|
-
// They live on the issuer origin and authorise every request through `authorization()`, so each
|
|
3033
|
-
// attempt carries its own sender-constrained proof for its exact method and URL. Each is built on
|
|
3034
|
-
// first use: the workspace-line authorities refuse a non-HTTPS or path-bearing origin, and that
|
|
3035
|
-
// refusal belongs to the caller who uses them, not to every client constructed for local
|
|
3036
|
-
// development or for ledger-only use.
|
|
3037
|
-
get workspaces() {
|
|
3038
|
-
return this.authorities.workspaces ??= new WorkspaceClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
|
|
3039
|
-
}
|
|
3040
|
-
get workforce() {
|
|
3041
|
-
return this.authorities.workforce ??= new WorkforceClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
|
|
3042
|
-
}
|
|
3043
|
-
get notifications() {
|
|
3044
|
-
return this.authorities.notifications ??= new NotificationsClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
|
|
3045
|
-
}
|
|
3046
|
-
get integrations() {
|
|
3047
|
-
return this.authorities.integrations ??= new AccountIntegrationClient(this.issuer, this.transport, (method, url, opts) => this.authorization(method, url, opts));
|
|
3048
|
-
}
|
|
3049
|
-
// ─── Session workhorse (priority chain, XENO AUTH §5) ───────────────────
|
|
3050
|
-
/**
|
|
3051
|
-
* Return a valid Bearer for the gate, walking the chain:
|
|
3052
|
-
* 1 in-memory access token → 2 explicit override (apiKey/XENO_API_KEY) →
|
|
3053
|
-
* 3 [broker — host-wired] → 4 this product's own refresh token →
|
|
3054
|
-
* 5 interactive sign-in (host-provided; skipped when `silent`) → null.
|
|
3055
|
-
*/
|
|
3056
|
-
async getAccessToken(opts = {}) {
|
|
3057
|
-
const generation = this.generation;
|
|
3058
|
-
const scopes = opts.scopes ? [
|
|
3059
|
-
...opts.scopes
|
|
3060
|
-
] : void 0;
|
|
3061
|
-
if (this.access && this.access.expiresAtMs - 6e4 > Date.now() && containsScopes(this.access.scopes, scopes)) {
|
|
3062
|
-
const held = this.access;
|
|
3063
|
-
if (await this.cacheCurrent(held) && this.generation === generation) return held.token;
|
|
3064
|
-
}
|
|
3065
|
-
if (this.apiKey) return this.apiKey;
|
|
3066
|
-
if (this.locallySignedOut && opts.silent) return null;
|
|
3067
|
-
if (!this.resolutionFlight) {
|
|
3068
|
-
const flight = this.resolveSession({
|
|
3069
|
-
scopes,
|
|
3070
|
-
silent: opts.silent
|
|
3071
|
-
}, generation);
|
|
3072
|
-
this.resolutionFlight = flight;
|
|
3073
|
-
void flight.finally(() => {
|
|
3074
|
-
if (this.resolutionFlight === flight) this.resolutionFlight = null;
|
|
3075
|
-
}).catch(() => {
|
|
3076
|
-
});
|
|
3077
|
-
}
|
|
3078
|
-
await this.resolutionFlight;
|
|
3079
|
-
if (this.generation !== generation || !this.access) return null;
|
|
3080
|
-
if (!await this.cacheCurrent(this.access) || this.generation !== generation || !this.access) return null;
|
|
3081
|
-
if (!containsScopes(this.access.scopes, scopes)) throw new AccountError({
|
|
3082
|
-
code: "INVALID_TOKEN",
|
|
3083
|
-
message: "Current account session lacks required scope",
|
|
3084
|
-
retryable: false
|
|
3085
|
-
});
|
|
3086
|
-
if (this.access.expiresAtMs <= Date.now()) return null;
|
|
3087
|
-
return this.access.token;
|
|
3088
|
-
}
|
|
3089
|
-
async resolveSession(opts, generation) {
|
|
3090
|
-
if (this.locallySignedOut) {
|
|
3091
|
-
if (!opts.silent && this.interactive) await this.resolveInteractive(opts.scopes, generation);
|
|
3092
|
-
return;
|
|
3093
|
-
}
|
|
3094
|
-
const pending = await this.storeRead(this.refreshPendingKey) ?? await this.legacyRefreshMarker();
|
|
3095
|
-
if (this.generation !== generation) return;
|
|
3096
|
-
const interruptedRotation = abandonedRotation(pending);
|
|
3097
|
-
if (pending && !interruptedRotation && !/^ready:v1:[A-Za-z0-9_-]{32}$/.test(pending)) {
|
|
3098
|
-
if (!opts.silent && this.interactive) {
|
|
3099
|
-
await this.resolveInteractive(opts.scopes, generation);
|
|
3100
|
-
return;
|
|
3101
|
-
}
|
|
3102
|
-
if (pending === "signed-out:v1") {
|
|
3103
|
-
this.setUnauthenticated();
|
|
3104
|
-
if (!await this.storeRead(this.refreshStoreKey)) return;
|
|
3105
|
-
} else {
|
|
3106
|
-
throw new AccountError({
|
|
3107
|
-
code: "CONFLICT",
|
|
3108
|
-
message: "Previous account transition is unconfirmed; explicit sign-in recovery required",
|
|
3109
|
-
retryable: false
|
|
3110
|
-
});
|
|
3111
|
-
}
|
|
3112
|
-
if (pending === "signed-out:v1") throw transitionConflict();
|
|
3113
|
-
}
|
|
3114
|
-
if (this.broker) {
|
|
3115
|
-
try {
|
|
3116
|
-
const brokerToken = await this.broker.getToken({
|
|
3117
|
-
clientId: this.oidcConfig.clientId,
|
|
3118
|
-
scopes: opts.scopes ?? this.oidcConfig.scopes ?? [],
|
|
3119
|
-
resource: "https://api.xenostudio.ai",
|
|
3120
|
-
childDpopJkt: this.oidcConfig.dpopSigner.jkt
|
|
3121
|
-
});
|
|
3122
|
-
if (brokerToken) {
|
|
3123
|
-
const claims = await verifyAccessToken({
|
|
3124
|
-
token: brokerToken.accessToken,
|
|
3125
|
-
transport: this.transport,
|
|
3126
|
-
issuer: this.oidcConfig.issuer,
|
|
3127
|
-
clientId: this.oidcConfig.clientId,
|
|
3128
|
-
dpopJkt: this.oidcConfig.dpopSigner.jkt,
|
|
3129
|
-
jwksUrl: this.oidcConfig.jwksUrl,
|
|
3130
|
-
expectedScopes: opts.scopes,
|
|
3131
|
-
requireBrokerActor: true
|
|
3132
|
-
});
|
|
3133
|
-
if (brokerToken.refreshToken) throw new AccountError({
|
|
3134
|
-
code: "INVALID_RESPONSE",
|
|
3135
|
-
message: "Broker cannot transfer refresh credentials",
|
|
3136
|
-
retryable: false
|
|
3137
|
-
});
|
|
3138
|
-
await this.applyTokenSet({
|
|
3139
|
-
...brokerToken,
|
|
3140
|
-
accessClaims: claims,
|
|
3141
|
-
idClaims: null
|
|
3142
|
-
}, generation, pending, true);
|
|
3143
|
-
return;
|
|
3144
|
-
}
|
|
3145
|
-
} catch {
|
|
3146
|
-
}
|
|
3147
|
-
}
|
|
3148
|
-
if (this.generation !== generation) return;
|
|
3149
|
-
const rotationId = interruptedRotation ?? generateState();
|
|
3150
|
-
const transition = rotationMarker(rotationId);
|
|
3151
|
-
const rt = await this.exclusiveStore(async () => {
|
|
3152
|
-
if (this.generation !== generation) return null;
|
|
3153
|
-
if (await this.store.get(this.refreshPendingKey) !== pending) throw transitionConflict();
|
|
3154
|
-
const value = await this.store.get(this.refreshStoreKey);
|
|
3155
|
-
if (value) await this.store.set(this.refreshPendingKey, transition);
|
|
3156
|
-
return value;
|
|
3157
|
-
});
|
|
3158
|
-
if (this.generation !== generation) return;
|
|
3159
|
-
if (interruptedRotation && !rt) throw transitionConflict();
|
|
3160
|
-
if (rt) {
|
|
3161
|
-
try {
|
|
3162
|
-
const tokens = await this.refresh(rt, rotationId);
|
|
3163
|
-
if (!tokens.refreshToken) throw new AccountError({
|
|
3164
|
-
code: "INVALID_RESPONSE",
|
|
3165
|
-
message: "Rotating refresh response omitted successor credential",
|
|
3166
|
-
retryable: false
|
|
3167
|
-
});
|
|
3168
|
-
await this.applyTokenSet(tokens, generation, transition);
|
|
3169
|
-
return;
|
|
3170
|
-
} catch (error) {
|
|
3171
|
-
if (this.generation !== generation) return;
|
|
3172
|
-
if (!(error instanceof AccountError && error.httpStatus === 400 && error.oauthError === "invalid_grant")) {
|
|
3173
|
-
throw new AccountError({
|
|
3174
|
-
code: error instanceof AccountError ? error.code : "UNREACHABLE",
|
|
3175
|
-
message: "Account refresh outcome is unconfirmed; explicit recovery required",
|
|
3176
|
-
retryable: false,
|
|
3177
|
-
...error instanceof AccountError ? {
|
|
3178
|
-
httpStatus: error.httpStatus
|
|
3179
|
-
} : {}
|
|
3180
|
-
});
|
|
3181
|
-
}
|
|
3182
|
-
await this.exclusiveStore(async () => {
|
|
3183
|
-
if (this.generation !== generation) return;
|
|
3184
|
-
if (await this.store.get(this.refreshPendingKey) !== transition) throw transitionConflict();
|
|
3185
|
-
await this.store.delete(this.refreshStoreKey);
|
|
3186
|
-
await this.store.set(this.refreshPendingKey, "signed-out:v1");
|
|
3187
|
-
});
|
|
3188
|
-
if (this.generation !== generation) return;
|
|
3189
|
-
this.setUnauthenticated();
|
|
3190
|
-
}
|
|
3191
|
-
}
|
|
3192
|
-
if (!opts.silent && this.interactive) {
|
|
3193
|
-
await this.resolveInteractive(opts.scopes, generation);
|
|
3194
|
-
}
|
|
3195
|
-
return;
|
|
3196
|
-
}
|
|
3197
|
-
/** Register the host's interactive sign-in (loopback PKCE / device grant). */
|
|
3198
|
-
setInteractiveSignIn(fn) {
|
|
3199
|
-
this.interactive = fn;
|
|
3200
|
-
}
|
|
3201
|
-
isAuthenticated() {
|
|
3202
|
-
return !!this.access && this.access.expiresAtMs > Date.now();
|
|
3203
|
-
}
|
|
3204
|
-
currentUser() {
|
|
3205
|
-
return this.user;
|
|
3206
|
-
}
|
|
3207
|
-
/** Subscribe to login/refresh/logout/backchannel. Returns an unsubscribe fn. */
|
|
3208
|
-
onAuthChanged(cb) {
|
|
3209
|
-
this.listeners.add(cb);
|
|
3210
|
-
return () => this.listeners.delete(cb);
|
|
3211
|
-
}
|
|
3212
|
-
/** Local wipe only, used after durable host-side invalidation/reconciliation. */
|
|
3213
|
-
async signOutLocal() {
|
|
3214
|
-
this.generation++;
|
|
3215
|
-
this.locallySignedOut = true;
|
|
3216
|
-
this.resolutionFlight = null;
|
|
3217
|
-
this.setUnauthenticated();
|
|
3218
|
-
await this.exclusiveStore(async () => {
|
|
3219
|
-
await this.store.set(this.refreshPendingKey, "signed-out:v1");
|
|
3220
|
-
await this.store.delete(this.refreshStoreKey);
|
|
3221
|
-
});
|
|
3222
|
-
}
|
|
3223
|
-
/** Revoke this subject-owned session, then always clear local state. */
|
|
3224
|
-
async signOut() {
|
|
3225
|
-
const original = this.access;
|
|
3226
|
-
const local = this.signOutLocal();
|
|
3227
|
-
void local.catch(() => {
|
|
3228
|
-
});
|
|
3229
|
-
let serverRevoked = false;
|
|
3230
|
-
try {
|
|
3231
|
-
if (original?.tokenType === "DPoP") {
|
|
3232
|
-
const url = `${this.oidcConfig.issuer.replace(/\/+$/, "")}/api/oauth2/end_session`;
|
|
3233
|
-
const dpop = await this.createProof({
|
|
3234
|
-
method: "POST",
|
|
3235
|
-
url,
|
|
3236
|
-
accessToken: original.token
|
|
3237
|
-
});
|
|
3238
|
-
await this.transport.request({
|
|
3239
|
-
method: "POST",
|
|
3240
|
-
url,
|
|
3241
|
-
token: original.token,
|
|
3242
|
-
tokenType: "DPoP",
|
|
3243
|
-
headers: {
|
|
3244
|
-
dpop
|
|
3245
|
-
},
|
|
3246
|
-
idempotencyKey: `logout:${original.sid ?? "current"}`
|
|
3247
|
-
});
|
|
3248
|
-
serverRevoked = true;
|
|
3249
|
-
}
|
|
3250
|
-
} finally {
|
|
3251
|
-
await local;
|
|
3252
|
-
}
|
|
3253
|
-
return {
|
|
3254
|
-
serverRevoked
|
|
3255
|
-
};
|
|
3256
|
-
}
|
|
3257
|
-
/** Step-up protected, subject-keyed global logout. Only authorized clients can call it. */
|
|
3258
|
-
async signOutEverywhere() {
|
|
3259
|
-
if (!this.access || this.access.tokenType !== "DPoP") throw new Error("fresh DPoP session required");
|
|
3260
|
-
const original = this.access, generation = this.generation;
|
|
3261
|
-
const url = `${this.oidcConfig.issuer.replace(/\/+$/, "")}/api/oauth2/logout_everywhere`;
|
|
3262
|
-
const dpop = await this.createProof({
|
|
3263
|
-
method: "POST",
|
|
3264
|
-
url,
|
|
3265
|
-
accessToken: original.token
|
|
3266
|
-
});
|
|
3267
|
-
if (this.generation !== generation || this.access !== original) throw new AccountError({
|
|
3268
|
-
code: "CONFLICT",
|
|
3269
|
-
message: "Account session changed before global revocation",
|
|
3270
|
-
retryable: false
|
|
3271
|
-
});
|
|
3272
|
-
await this.transport.request({
|
|
3273
|
-
method: "POST",
|
|
3274
|
-
url,
|
|
3275
|
-
token: original.token,
|
|
3276
|
-
tokenType: "DPoP",
|
|
3277
|
-
headers: {
|
|
3278
|
-
dpop
|
|
3279
|
-
},
|
|
3280
|
-
idempotencyKey: `logout-all:${original.sid ?? "current"}`
|
|
3281
|
-
});
|
|
3282
|
-
try {
|
|
3283
|
-
await this.broker?.logout?.();
|
|
3284
|
-
} finally {
|
|
3285
|
-
if (this.generation === generation) {
|
|
3286
|
-
this.generation++;
|
|
3287
|
-
this.locallySignedOut = true;
|
|
3288
|
-
this.resolutionFlight = null;
|
|
3289
|
-
this.setUnauthenticated();
|
|
3290
|
-
await this.exclusiveStore(async () => {
|
|
3291
|
-
if (await this.store.get(this.refreshPendingKey) !== original.storeTransition) return;
|
|
3292
|
-
await this.store.set(this.refreshPendingKey, "signed-out:v1");
|
|
3293
|
-
await this.store.delete(this.refreshStoreKey);
|
|
3294
|
-
});
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3297
|
-
}
|
|
3298
|
-
setUnauthenticated() {
|
|
3299
|
-
this.access = null;
|
|
3300
|
-
this.user = null;
|
|
3301
|
-
this.emit(null);
|
|
3302
|
-
}
|
|
3303
|
-
emit(a) {
|
|
3304
|
-
for (const cb of [
|
|
3305
|
-
...this.listeners
|
|
3306
|
-
]) {
|
|
3307
|
-
try {
|
|
3308
|
-
cb(a);
|
|
3309
|
-
} catch {
|
|
3310
|
-
}
|
|
3311
|
-
}
|
|
3312
|
-
}
|
|
3313
|
-
/**
|
|
3314
|
-
* The 0.2.0 workforce builds (shipped vendored, never published) marked an in-flight refresh at
|
|
3315
|
-
* `<refresh key>-uncertain` and never named the rotation. An install upgrading with that marker
|
|
3316
|
-
* present may hold a token the origin already rotated, so sending it would be a replay — the
|
|
3317
|
-
* zero-grace reuse that revokes the whole family. It is therefore an unconfirmed transition like any
|
|
3318
|
-
* other v1 marker: refused silently, recoverable only by explicit sign-in (which writes this
|
|
3319
|
-
* version's own marker, after which the legacy one is never consulted again).
|
|
3320
|
-
*/
|
|
3321
|
-
async legacyRefreshMarker() {
|
|
3322
|
-
return await this.storeRead(`${this.refreshStoreKey}-uncertain`) ? "legacy-refresh-uncertain:v1" : null;
|
|
3323
|
-
}
|
|
3324
|
-
async storeRead(key) {
|
|
3325
|
-
try {
|
|
3326
|
-
return await this.store.get(key);
|
|
3327
|
-
} catch {
|
|
3328
|
-
throw new AccountError({
|
|
3329
|
-
code: "UNREACHABLE",
|
|
3330
|
-
message: "Secure account store is unavailable",
|
|
3331
|
-
retryable: false
|
|
3332
|
-
});
|
|
3333
|
-
}
|
|
3334
|
-
}
|
|
3335
|
-
async cacheCurrent(held) {
|
|
3336
|
-
const transition = await this.storeRead(this.refreshPendingKey);
|
|
3337
|
-
if (this.access === held && transition === held.storeTransition) return true;
|
|
3338
|
-
if (this.access === held) this.setUnauthenticated();
|
|
3339
|
-
return false;
|
|
3340
|
-
}
|
|
3341
|
-
async exclusiveStore(work) {
|
|
3342
|
-
if (!this.store.withExclusive) throw new AccountError({
|
|
3343
|
-
code: "UNREACHABLE",
|
|
3344
|
-
message: "Secure account store exclusion is unavailable",
|
|
3345
|
-
retryable: false
|
|
3346
|
-
});
|
|
3347
|
-
try {
|
|
3348
|
-
return await this.store.withExclusive(this.refreshStoreKey, work);
|
|
3349
|
-
} catch (error) {
|
|
3350
|
-
if (error instanceof AccountError) throw error;
|
|
3351
|
-
throw new AccountError({
|
|
3352
|
-
code: "UNREACHABLE",
|
|
3353
|
-
message: "Secure account state commit is unavailable",
|
|
3354
|
-
retryable: false
|
|
3355
|
-
});
|
|
3356
|
-
}
|
|
3357
|
-
}
|
|
3358
|
-
async reserveSignIn(generation) {
|
|
3359
|
-
const transition = `sign-in:v1:${generateState()}`;
|
|
3360
|
-
await this.exclusiveStore(async () => {
|
|
3361
|
-
if (this.generation !== generation) throw transitionConflict();
|
|
3362
|
-
await this.store.set(this.refreshPendingKey, transition);
|
|
3363
|
-
});
|
|
3364
|
-
return transition;
|
|
3365
|
-
}
|
|
3366
|
-
async resolveInteractive(scopes, generation) {
|
|
3367
|
-
const transition = await this.reserveSignIn(generation);
|
|
3368
|
-
await this.applyTokenSet(await this.interactive(scopes), generation, transition);
|
|
3369
|
-
}
|
|
3370
|
-
/** Cache the access token, persist the rotated refresh token, update the user. */
|
|
3371
|
-
async applyTokenSet(ts, generation, transition, preserveRefresh = false, signal) {
|
|
3372
|
-
if (this.generation !== generation) return;
|
|
3373
|
-
const claims = await verifyAccessToken({
|
|
3374
|
-
token: ts.accessToken,
|
|
3375
|
-
transport: this.transport,
|
|
3376
|
-
issuer: this.oidcConfig.issuer,
|
|
3377
|
-
clientId: this.oidcConfig.clientId,
|
|
3378
|
-
dpopJkt: this.oidcConfig.dpopSigner.jkt,
|
|
3379
|
-
jwksUrl: this.oidcConfig.jwksUrl
|
|
3380
|
-
});
|
|
3381
|
-
const idClaims = ts.idToken ? await verifyIdToken({
|
|
3382
|
-
token: ts.idToken,
|
|
3383
|
-
transport: this.transport,
|
|
3384
|
-
issuer: this.oidcConfig.issuer,
|
|
3385
|
-
clientId: this.oidcConfig.clientId,
|
|
3386
|
-
jwksUrl: this.oidcConfig.jwksUrl,
|
|
3387
|
-
expectedSubject: claims.sub
|
|
3388
|
-
}) : null;
|
|
3389
|
-
if (idClaims && idClaims.sid !== claims.sid) throw new AccountError({
|
|
3390
|
-
code: "INVALID_RESPONSE",
|
|
3391
|
-
message: "ID and access session binding differ",
|
|
3392
|
-
retryable: false
|
|
3393
|
-
});
|
|
3394
|
-
if (ts.tokenType.toLowerCase() !== "dpop") throw new AccountError({
|
|
3395
|
-
code: "INVALID_RESPONSE",
|
|
3396
|
-
message: "Canonical session requires DPoP token type",
|
|
3397
|
-
retryable: false
|
|
3398
|
-
});
|
|
3399
|
-
if (this.generation !== generation) return;
|
|
3400
|
-
const expMs = Math.min(claims.exp * 1e3, ts.expiresAt?.getTime() ?? claims.exp * 1e3);
|
|
3401
|
-
const storeTransition = `ready:v1:${generateState()}`;
|
|
3402
|
-
await this.exclusiveStore(async () => {
|
|
3403
|
-
if (this.generation !== generation) return;
|
|
3404
|
-
if (await this.store.get(this.refreshPendingKey) !== transition) throw transitionConflict();
|
|
3405
|
-
if (ts.refreshToken) {
|
|
3406
|
-
await this.store.set(this.refreshStoreKey, ts.refreshToken);
|
|
3407
|
-
} else if (!preserveRefresh) await this.store.delete(this.refreshStoreKey);
|
|
3408
|
-
if (this.generation !== generation || signal?.aborted) throw transitionConflict();
|
|
3409
|
-
await this.store.set(this.refreshPendingKey, storeTransition);
|
|
3410
|
-
if (signal?.aborted) {
|
|
3411
|
-
if (await this.store.get(this.refreshPendingKey) === storeTransition) {
|
|
3412
|
-
await this.store.set(this.refreshPendingKey, "signed-out:v1");
|
|
3413
|
-
await this.store.delete(this.refreshStoreKey);
|
|
3414
|
-
}
|
|
3415
|
-
throw transitionConflict();
|
|
3416
|
-
}
|
|
3417
|
-
});
|
|
3418
|
-
if (this.generation !== generation) {
|
|
3419
|
-
if (signal?.aborted) await this.cancelCommittedSignIn(storeTransition);
|
|
3420
|
-
return;
|
|
3421
|
-
}
|
|
3422
|
-
this.access = {
|
|
3423
|
-
token: ts.accessToken,
|
|
3424
|
-
tokenType: ts.tokenType.toLowerCase() === "dpop" ? "DPoP" : "Bearer",
|
|
3425
|
-
expiresAtMs: expMs,
|
|
3426
|
-
scopes: claims.scope.split(/\s+/).filter(Boolean),
|
|
3427
|
-
sid: claims.sid,
|
|
3428
|
-
storeTransition
|
|
3429
|
-
};
|
|
3430
|
-
this.locallySignedOut = false;
|
|
3431
|
-
if (idClaims) {
|
|
3432
|
-
const u = accountFromVerifiedClaims(idClaims);
|
|
3433
|
-
if (u) this.user = u;
|
|
3434
|
-
} else if (this.user?.id !== claims.sub) this.user = null;
|
|
3435
|
-
this.emit(this.user);
|
|
3436
|
-
return storeTransition;
|
|
3437
|
-
}
|
|
3438
|
-
async cancelCommittedSignIn(transition) {
|
|
3439
|
-
await this.exclusiveStore(async () => {
|
|
3440
|
-
if (await this.store.get(this.refreshPendingKey) !== transition) return;
|
|
3441
|
-
await this.store.set(this.refreshPendingKey, "signed-out:v1");
|
|
3442
|
-
await this.store.delete(this.refreshStoreKey);
|
|
3443
|
-
});
|
|
3444
|
-
}
|
|
3445
|
-
// ─── OIDC sign-in (Authorization Code + PKCE) ───────────────────────────
|
|
3446
|
-
/**
|
|
3447
|
-
* Begin "Continue with XENO". Returns the authorize URL to redirect to, plus
|
|
3448
|
-
* the `{ state, verifier }` the caller MUST persist (encrypted) to complete
|
|
3449
|
-
* the flow in {@link completeSignIn}.
|
|
3450
|
-
*/
|
|
3451
|
-
async beginSignIn(args = {}) {
|
|
3452
|
-
const state = generateState();
|
|
3453
|
-
const nonce = generateState();
|
|
3454
|
-
const pkce = await generatePkce();
|
|
3455
|
-
const url = buildAuthorizeUrl(this.oidcConfig, {
|
|
3456
|
-
state,
|
|
3457
|
-
codeChallenge: pkce.challenge,
|
|
3458
|
-
redirectUri: args.redirectUri,
|
|
3459
|
-
scopes: args.scopes,
|
|
3460
|
-
nonce,
|
|
3461
|
-
...args.fresh ? {
|
|
3462
|
-
prompt: "login",
|
|
3463
|
-
maxAge: 60,
|
|
3464
|
-
acrValues: "urn:xeno:acr:fresh"
|
|
3465
|
-
} : {}
|
|
3466
|
-
});
|
|
3467
|
-
return {
|
|
3468
|
-
url,
|
|
3469
|
-
state,
|
|
3470
|
-
nonce,
|
|
3471
|
-
pkce
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
/** Complete the code flow: exchange `code` (with the saved verifier) for tokens,
|
|
3475
|
-
* then cache the access token + persist the refresh token + set the user. */
|
|
3476
|
-
async completeSignIn(args) {
|
|
3477
|
-
const generation = ++this.generation;
|
|
3478
|
-
this.resolutionFlight = null;
|
|
3479
|
-
const invalidate = this.bindSignInCancellation(generation, args.signal);
|
|
3480
|
-
try {
|
|
3481
|
-
if (args.signal?.aborted) throw transitionConflict();
|
|
3482
|
-
const transition = await this.reserveSignIn(generation);
|
|
3483
|
-
if (args.signal?.aborted || this.generation !== generation) throw transitionConflict();
|
|
3484
|
-
const ts = await exchangeCode(this.oidcConfig, this.transport, args);
|
|
3485
|
-
const committed2 = await this.applyTokenSet(ts, generation, transition, false, args.signal);
|
|
3486
|
-
if (this.generation !== generation || args.signal?.aborted) {
|
|
3487
|
-
if (committed2 && args.signal?.aborted) await this.cancelCommittedSignIn(committed2);
|
|
3488
|
-
throw transitionConflict();
|
|
3489
|
-
}
|
|
3490
|
-
return ts;
|
|
3491
|
-
} catch (error) {
|
|
3492
|
-
if (args.signal?.aborted) throw transitionConflict();
|
|
3493
|
-
throw error;
|
|
3494
|
-
} finally {
|
|
3495
|
-
invalidate();
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
bindSignInCancellation(generation, signal) {
|
|
3499
|
-
const cancelled = /* @__PURE__ */ __name(() => {
|
|
3500
|
-
if (this.generation !== generation) return;
|
|
3501
|
-
this.generation++;
|
|
3502
|
-
this.resolutionFlight = null;
|
|
3503
|
-
this.setUnauthenticated();
|
|
3504
|
-
}, "cancelled");
|
|
3505
|
-
signal?.addEventListener("abort", cancelled, {
|
|
3506
|
-
once: true
|
|
3507
|
-
});
|
|
3508
|
-
if (signal?.aborted) cancelled();
|
|
3509
|
-
return () => signal?.removeEventListener("abort", cancelled);
|
|
3510
|
-
}
|
|
3511
|
-
/** Headers for one sender-constrained resource request. */
|
|
3512
|
-
async authorization(method, url, opts = {}) {
|
|
3513
|
-
const generation = this.generation;
|
|
3514
|
-
const token = await this.getAccessToken(opts);
|
|
3515
|
-
if (!token || this.generation !== generation) return null;
|
|
3516
|
-
if (this.apiKey && token === this.apiKey) return {
|
|
3517
|
-
token,
|
|
3518
|
-
tokenType: "Bearer"
|
|
3519
|
-
};
|
|
3520
|
-
if (!this.access || this.access.token !== token || this.access.tokenType !== "DPoP") return {
|
|
3521
|
-
token,
|
|
3522
|
-
tokenType: "Bearer"
|
|
3523
|
-
};
|
|
3524
|
-
const dpop = await this.createProof({
|
|
3525
|
-
method,
|
|
3526
|
-
url,
|
|
3527
|
-
accessToken: token
|
|
3528
|
-
});
|
|
3529
|
-
if (this.generation !== generation || this.access?.token !== token || this.access.expiresAtMs <= Date.now()) return null;
|
|
3530
|
-
if (!await this.cacheCurrent(this.access) || this.generation !== generation || this.access?.token !== token) return null;
|
|
3531
|
-
return {
|
|
3532
|
-
token,
|
|
3533
|
-
tokenType: "DPoP",
|
|
3534
|
-
headers: {
|
|
3535
|
-
dpop
|
|
3536
|
-
}
|
|
3537
|
-
};
|
|
3538
|
-
}
|
|
3539
|
-
/** Verify and sender-constrain a previously persisted access token. Server
|
|
3540
|
-
* consumers use this for encrypted per-workspace sessions without placing
|
|
3541
|
-
* those tokens into the process-global client cache. */
|
|
3542
|
-
async authorizationForToken(token, method, url, expectedScopes) {
|
|
3543
|
-
await verifyAccessToken({
|
|
3544
|
-
token,
|
|
3545
|
-
transport: this.transport,
|
|
3546
|
-
issuer: this.oidcConfig.issuer,
|
|
3547
|
-
clientId: this.oidcConfig.clientId,
|
|
3548
|
-
dpopJkt: this.oidcConfig.dpopSigner.jkt,
|
|
3549
|
-
jwksUrl: this.oidcConfig.jwksUrl,
|
|
3550
|
-
expectedScopes
|
|
3551
|
-
});
|
|
3552
|
-
const dpop = await this.createProof({
|
|
3553
|
-
method,
|
|
3554
|
-
url,
|
|
3555
|
-
accessToken: token
|
|
3556
|
-
});
|
|
3557
|
-
return {
|
|
3558
|
-
token,
|
|
3559
|
-
tokenType: "DPoP",
|
|
3560
|
-
headers: {
|
|
3561
|
-
dpop
|
|
3562
|
-
}
|
|
3563
|
-
};
|
|
3564
|
-
}
|
|
3565
|
-
/** Verify a provider-originated Back-Channel Logout Token. */
|
|
3566
|
-
verifyBackchannelLogout(token) {
|
|
3567
|
-
return verifyLogoutToken({
|
|
3568
|
-
token,
|
|
3569
|
-
transport: this.transport,
|
|
3570
|
-
issuer: this.oidcConfig.issuer,
|
|
3571
|
-
clientId: this.oidcConfig.clientId,
|
|
3572
|
-
jwksUrl: this.oidcConfig.jwksUrl
|
|
3573
|
-
});
|
|
3574
|
-
}
|
|
3575
|
-
async createProof(args) {
|
|
3576
|
-
try {
|
|
3577
|
-
return await this.oidcConfig.dpopSigner.createProof(args);
|
|
3578
|
-
} catch {
|
|
3579
|
-
throw new AccountError({
|
|
3580
|
-
code: "UNREACHABLE",
|
|
3581
|
-
message: "Host account request signing is unavailable",
|
|
3582
|
-
retryable: false
|
|
3583
|
-
});
|
|
3584
|
-
}
|
|
3585
|
-
}
|
|
3586
|
-
/** Rotate tokens. Persist the returned refreshToken; a failure means re-auth. */
|
|
3587
|
-
refresh(refreshToken, rotationId) {
|
|
3588
|
-
return refreshTokens(this.oidcConfig, this.transport, refreshToken, rotationId);
|
|
3589
|
-
}
|
|
3590
|
-
// ─── Device grant (CLI / headless) ──────────────────────────────────────
|
|
3591
|
-
startDeviceLogin(scopes) {
|
|
3592
|
-
return startDeviceAuthorization(this.oidcConfig, this.transport, scopes);
|
|
3593
|
-
}
|
|
3594
|
-
async awaitDeviceLogin(device, opts) {
|
|
3595
|
-
const generation = ++this.generation;
|
|
3596
|
-
this.resolutionFlight = null;
|
|
3597
|
-
const invalidate = this.bindSignInCancellation(generation, opts?.signal);
|
|
3598
|
-
try {
|
|
3599
|
-
if (opts?.signal?.aborted) throw transitionConflict();
|
|
3600
|
-
const transition = await this.reserveSignIn(generation);
|
|
3601
|
-
if (opts?.signal?.aborted || this.generation !== generation) throw transitionConflict();
|
|
3602
|
-
const ts = await pollDeviceToken(this.oidcConfig, this.transport, device, opts);
|
|
3603
|
-
const committed2 = await this.applyTokenSet(ts, generation, transition, false, opts?.signal);
|
|
3604
|
-
if (this.generation !== generation || opts?.signal?.aborted) {
|
|
3605
|
-
if (committed2 && opts?.signal?.aborted) await this.cancelCommittedSignIn(committed2);
|
|
3606
|
-
throw transitionConflict();
|
|
3607
|
-
}
|
|
3608
|
-
return ts;
|
|
3609
|
-
} catch (error) {
|
|
3610
|
-
if (opts?.signal?.aborted) throw transitionConflict();
|
|
3611
|
-
throw error;
|
|
3612
|
-
} finally {
|
|
3613
|
-
invalidate();
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
};
|
|
3617
|
-
function accountFromVerifiedClaims(p) {
|
|
3618
|
-
if (!p.sub) return null;
|
|
3619
|
-
return {
|
|
3620
|
-
id: p.sub,
|
|
3621
|
-
email: p.email ?? "",
|
|
3622
|
-
username: p.preferred_username ?? null,
|
|
3623
|
-
displayName: p.name ?? null,
|
|
3624
|
-
avatarUrl: p.picture ?? null,
|
|
3625
|
-
emailVerified: p.email_verified === true,
|
|
3626
|
-
linkedSurfaces: []
|
|
3627
|
-
};
|
|
3628
|
-
}
|
|
3629
|
-
__name(accountFromVerifiedClaims, "accountFromVerifiedClaims");
|
|
3630
|
-
function containsScopes(held, requested) {
|
|
3631
|
-
if (!requested?.length) return true;
|
|
3632
|
-
const set = new Set(held);
|
|
3633
|
-
return requested.every((scope) => set.has(scope));
|
|
3634
|
-
}
|
|
3635
|
-
__name(containsScopes, "containsScopes");
|
|
3636
|
-
var ROTATION_IN_FLIGHT_MS = 3e4;
|
|
3637
|
-
function rotationMarker(rotationId) {
|
|
3638
|
-
const pid = typeof process !== "undefined" && typeof process.pid === "number" ? process.pid : 0;
|
|
3639
|
-
return `refresh:v2:${rotationId}:${pid}:${Date.now()}`;
|
|
3640
|
-
}
|
|
3641
|
-
__name(rotationMarker, "rotationMarker");
|
|
3642
|
-
function abandonedRotation(marker, now = Date.now()) {
|
|
3643
|
-
const match = marker?.match(/^refresh:v2:([A-Za-z0-9_-]{32}):(\d{1,10}):(\d{1,15})$/);
|
|
3644
|
-
if (!match) return void 0;
|
|
3645
|
-
const pid = Number(match[2]), started = Number(match[3]);
|
|
3646
|
-
if (now - started > ROTATION_IN_FLIGHT_MS) return match[1];
|
|
3647
|
-
return pid > 0 && !processAlive(pid) ? match[1] : void 0;
|
|
3648
|
-
}
|
|
3649
|
-
__name(abandonedRotation, "abandonedRotation");
|
|
3650
|
-
function processAlive(pid) {
|
|
3651
|
-
if (typeof process === "undefined" || typeof process.kill !== "function") return true;
|
|
3652
|
-
try {
|
|
3653
|
-
process.kill(pid, 0);
|
|
3654
|
-
return true;
|
|
3655
|
-
} catch (error) {
|
|
3656
|
-
return error.code === "EPERM";
|
|
3657
|
-
}
|
|
3658
|
-
}
|
|
3659
|
-
__name(processAlive, "processAlive");
|
|
3660
|
-
function transitionConflict() {
|
|
3661
|
-
return new AccountError({
|
|
3662
|
-
code: "CONFLICT",
|
|
3663
|
-
message: "Account credential transition changed; explicit recovery required",
|
|
3664
|
-
retryable: false
|
|
3665
|
-
});
|
|
3666
|
-
}
|
|
3667
|
-
__name(transitionConflict, "transitionConflict");
|
|
3668
|
-
|
|
3669
|
-
// src/dpop.ts
|
|
3670
|
-
function normalizeDpopHtu(value) {
|
|
3671
|
-
const url = new URL(value);
|
|
3672
|
-
if (url.protocol !== "https:") throw new Error("DPoP htu must use HTTPS");
|
|
3673
|
-
url.hash = "";
|
|
3674
|
-
url.search = "";
|
|
3675
|
-
url.username = "";
|
|
3676
|
-
url.password = "";
|
|
3677
|
-
url.hostname = url.hostname.toLowerCase();
|
|
3678
|
-
if (url.port === "443") url.port = "";
|
|
3679
|
-
return url.toString();
|
|
3680
|
-
}
|
|
3681
|
-
__name(normalizeDpopHtu, "normalizeDpopHtu");
|
|
3682
|
-
|
|
3683
|
-
// src/bff.ts
|
|
3684
|
-
var BffSessionClient = class {
|
|
3685
|
-
static {
|
|
3686
|
-
__name(this, "BffSessionClient");
|
|
3687
|
-
}
|
|
3688
|
-
baseUrl;
|
|
3689
|
-
fetchImpl;
|
|
3690
|
-
csrf;
|
|
3691
|
-
constructor(baseUrl = "/api/session", fetchImpl = globalThis.fetch, csrf) {
|
|
3692
|
-
this.baseUrl = baseUrl;
|
|
3693
|
-
this.fetchImpl = fetchImpl;
|
|
3694
|
-
this.csrf = csrf;
|
|
3695
|
-
}
|
|
3696
|
-
loginUrl(returnUrl) {
|
|
3697
|
-
if (!returnUrl.startsWith("/") || returnUrl.startsWith("//")) throw new AccountError({
|
|
3698
|
-
code: "BAD_REQUEST",
|
|
3699
|
-
message: "returnUrl must be same-origin"
|
|
3700
|
-
});
|
|
3701
|
-
return `${this.baseUrl}/login/start?return_url=${encodeURIComponent(returnUrl)}`;
|
|
3702
|
-
}
|
|
3703
|
-
session() {
|
|
3704
|
-
return this.request("GET", "/session");
|
|
3705
|
-
}
|
|
3706
|
-
refresh(idempotencyKey) {
|
|
3707
|
-
return this.request("POST", "/refresh", idempotencyKey);
|
|
3708
|
-
}
|
|
3709
|
-
async logout() {
|
|
3710
|
-
await this.request("POST", "/logout");
|
|
3711
|
-
}
|
|
3712
|
-
async request(method, path, idempotencyKey) {
|
|
3713
|
-
const headers = {
|
|
3714
|
-
accept: "application/json"
|
|
3715
|
-
};
|
|
3716
|
-
if (method === "POST") {
|
|
3717
|
-
const csrf = this.csrf();
|
|
3718
|
-
if (!csrf) throw new AccountError({
|
|
3719
|
-
code: "BAD_REQUEST",
|
|
3720
|
-
message: "missing BFF CSRF value"
|
|
3721
|
-
});
|
|
3722
|
-
headers["x-xeno-csrf"] = csrf;
|
|
3723
|
-
if (idempotencyKey) headers["idempotency-key"] = idempotencyKey;
|
|
3724
|
-
}
|
|
3725
|
-
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
3726
|
-
method,
|
|
3727
|
-
credentials: "include",
|
|
3728
|
-
headers
|
|
3729
|
-
});
|
|
3730
|
-
if (!response.ok) throw new AccountError({
|
|
3731
|
-
code: response.status === 401 ? "INVALID_TOKEN" : "PLATFORM_ERROR",
|
|
3732
|
-
message: `BFF session request failed: ${response.status}`,
|
|
3733
|
-
httpStatus: response.status
|
|
3734
|
-
});
|
|
3735
|
-
if (response.status === 204) return void 0;
|
|
3736
|
-
return response.json();
|
|
3737
|
-
}
|
|
3738
|
-
};
|
|
3739
|
-
|
|
3740
|
-
// src/redaction.ts
|
|
3741
|
-
var TOKEN_RE = /(eyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,})|([A-Za-z0-9_-]{40,})/g;
|
|
3742
|
-
function redact(input) {
|
|
3743
|
-
const s = typeof input === "string" ? input : safeStringify(input);
|
|
3744
|
-
return s.replace(TOKEN_RE, (m) => `${m.slice(0, 6)}\u2026[redacted:${m.length}]`);
|
|
3745
|
-
}
|
|
3746
|
-
__name(redact, "redact");
|
|
3747
|
-
function safeStringify(v) {
|
|
3748
|
-
try {
|
|
3749
|
-
return JSON.stringify(v) ?? String(v);
|
|
3750
|
-
} catch {
|
|
3751
|
-
return String(v);
|
|
3752
|
-
}
|
|
3753
|
-
}
|
|
3754
|
-
__name(safeStringify, "safeStringify");
|
|
3755
|
-
|
|
3756
|
-
// src/resource-authorization.ts
|
|
3757
|
-
var MAX_JWT_BYTES = 16384;
|
|
3758
|
-
var PRIVATE_FIELDS = [
|
|
3759
|
-
"d",
|
|
3760
|
-
"p",
|
|
3761
|
-
"q",
|
|
3762
|
-
"dp",
|
|
3763
|
-
"dq",
|
|
3764
|
-
"qi",
|
|
3765
|
-
"oth",
|
|
3766
|
-
"k"
|
|
3767
|
-
];
|
|
3768
|
-
function denied() {
|
|
3769
|
-
return new AccountError({
|
|
3770
|
-
code: "INVALID_TOKEN",
|
|
3771
|
-
message: "Resource authorization refused",
|
|
3772
|
-
retryable: false,
|
|
3773
|
-
httpStatus: 401
|
|
3774
|
-
});
|
|
3775
|
-
}
|
|
3776
|
-
__name(denied, "denied");
|
|
3777
|
-
function unavailable() {
|
|
3778
|
-
return new AccountError({
|
|
3779
|
-
code: "UNREACHABLE",
|
|
3780
|
-
message: "Resource authorization authority unavailable",
|
|
3781
|
-
retryable: true,
|
|
3782
|
-
httpStatus: 503
|
|
3783
|
-
});
|
|
3784
|
-
}
|
|
3785
|
-
__name(unavailable, "unavailable");
|
|
3786
|
-
function decodePart(part) {
|
|
3787
|
-
if (!/^[a-zA-Z0-9_-]+$/.test(part) || part.length % 4 === 1) throw denied();
|
|
3788
|
-
const padded = part.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - part.length % 4) % 4);
|
|
3789
|
-
try {
|
|
3790
|
-
return Uint8Array.from(atob(padded), (value) => value.charCodeAt(0));
|
|
3791
|
-
} catch {
|
|
3792
|
-
throw denied();
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
__name(decodePart, "decodePart");
|
|
3796
|
-
function record(bytes2) {
|
|
3797
|
-
try {
|
|
3798
|
-
return parseJwtObject(new TextDecoder("utf-8", {
|
|
3799
|
-
fatal: true
|
|
3800
|
-
}).decode(bytes2));
|
|
3801
|
-
} catch {
|
|
3802
|
-
throw denied();
|
|
3803
|
-
}
|
|
3804
|
-
}
|
|
3805
|
-
__name(record, "record");
|
|
3806
|
-
async function sha(value) {
|
|
3807
|
-
const bytes2 = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)));
|
|
3808
|
-
return btoa(String.fromCharCode(...bytes2)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
3809
|
-
}
|
|
3810
|
-
__name(sha, "sha");
|
|
3811
|
-
function frozenClaims(claims) {
|
|
3812
|
-
return Object.freeze({
|
|
3813
|
-
iss: claims.iss,
|
|
3814
|
-
sub: claims.sub,
|
|
3815
|
-
aud: claims.aud,
|
|
3816
|
-
exp: claims.exp,
|
|
3817
|
-
iat: claims.iat,
|
|
3818
|
-
sid: claims.sid,
|
|
3819
|
-
client_id: claims.client_id,
|
|
3820
|
-
azp: claims.azp,
|
|
3821
|
-
scope: claims.scope,
|
|
3822
|
-
typ: claims.typ,
|
|
3823
|
-
auth_epoch: claims.auth_epoch,
|
|
3824
|
-
...claims.auth_time === void 0 ? {} : {
|
|
3825
|
-
auth_time: claims.auth_time
|
|
3826
|
-
},
|
|
3827
|
-
...claims.acr ? {
|
|
3828
|
-
acr: claims.acr
|
|
3829
|
-
} : {},
|
|
3830
|
-
cnf: Object.freeze({
|
|
3831
|
-
jkt: claims.cnf.jkt
|
|
3832
|
-
}),
|
|
3833
|
-
...Array.isArray(claims.aud) ? {
|
|
3834
|
-
aud: Object.freeze([
|
|
3835
|
-
...claims.aud
|
|
3836
|
-
])
|
|
3837
|
-
} : {},
|
|
3838
|
-
...claims.act ? {
|
|
3839
|
-
act: Object.freeze({
|
|
3840
|
-
client_id: claims.act.client_id,
|
|
3841
|
-
installation_id_hash: claims.act.installation_id_hash,
|
|
3842
|
-
...claims.act.sub ? {
|
|
3843
|
-
sub: claims.act.sub
|
|
3844
|
-
} : {}
|
|
3845
|
-
})
|
|
3846
|
-
} : {},
|
|
3847
|
-
...claims.amr ? {
|
|
3848
|
-
amr: Object.freeze([
|
|
3849
|
-
...claims.amr
|
|
3850
|
-
])
|
|
3851
|
-
} : {}
|
|
3852
|
-
});
|
|
3853
|
-
}
|
|
3854
|
-
__name(frozenClaims, "frozenClaims");
|
|
3855
|
-
function createResourceRequestAuthorizer(options) {
|
|
3856
|
-
const issuer = normalizeDpopHtu(options.issuer);
|
|
3857
|
-
if (issuer.replace(/\/$/, "") !== options.issuer || !options.clientIds.length || options.clientIds.length > 128 || options.clientIds.some((id5) => !/^[a-zA-Z0-9._-]{1,128}$/.test(id5)) || new Set(options.clientIds).size !== options.clientIds.length) throw new TypeError("Explicit canonical issuer and unique clients required");
|
|
3858
|
-
const clients = new Set(options.clientIds);
|
|
3859
|
-
return {
|
|
3860
|
-
async authorize(request) {
|
|
3861
|
-
request = Object.freeze({
|
|
3862
|
-
...request,
|
|
3863
|
-
...request.scopes ? {
|
|
3864
|
-
scopes: [
|
|
3865
|
-
...request.scopes
|
|
3866
|
-
]
|
|
3867
|
-
} : {}
|
|
3868
|
-
});
|
|
3869
|
-
if (!/^[A-Z]{3,16}$/.test(request.method) || request.url.length > 8192 || request.authorization.length > MAX_JWT_BYTES + 5 || request.proof.length > MAX_JWT_BYTES || !request.proof || (request.scopes?.length ?? 0) > 128) throw denied();
|
|
3870
|
-
let url;
|
|
3871
|
-
try {
|
|
3872
|
-
const parsed = new URL(request.url);
|
|
3873
|
-
if (parsed.username || parsed.password || parsed.hash) throw denied();
|
|
3874
|
-
url = normalizeDpopHtu(request.url);
|
|
3875
|
-
} catch {
|
|
3876
|
-
throw denied();
|
|
3877
|
-
}
|
|
3878
|
-
const match = /^DPoP ([a-zA-Z0-9_.-]+)$/.exec(request.authorization);
|
|
3879
|
-
if (!match) throw denied();
|
|
3880
|
-
const token = match[1];
|
|
3881
|
-
const parts = request.proof.split(".");
|
|
3882
|
-
if (parts.length !== 3) throw denied();
|
|
3883
|
-
const header = record(decodePart(parts[0])), proof = record(decodePart(parts[1]));
|
|
3884
|
-
if (header.typ !== "dpop+jwt" || header.alg !== "ES256" || header.crit !== void 0 || header.b64 !== void 0 || !header.jwk || typeof header.jwk !== "object" || Array.isArray(header.jwk)) throw denied();
|
|
3885
|
-
const supplied = header.jwk;
|
|
3886
|
-
if (PRIVATE_FIELDS.some((field) => supplied[field] !== void 0) || supplied.kty !== "EC" || supplied.crv !== "P-256" || typeof supplied.x !== "string" || typeof supplied.y !== "string" || decodePart(supplied.x).length !== 32 || decodePart(supplied.y).length !== 32) throw denied();
|
|
3887
|
-
const jwk = {
|
|
3888
|
-
kty: "EC",
|
|
3889
|
-
crv: "P-256",
|
|
3890
|
-
x: supplied.x,
|
|
3891
|
-
y: supplied.y
|
|
3892
|
-
};
|
|
3893
|
-
const jkt = await sha(JSON.stringify({
|
|
3894
|
-
crv: jwk.crv,
|
|
3895
|
-
kty: jwk.kty,
|
|
3896
|
-
x: jwk.x,
|
|
3897
|
-
y: jwk.y
|
|
3898
|
-
}));
|
|
3899
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
3900
|
-
if (typeof proof.jti !== "string" || !/^[a-zA-Z0-9._:-]{1,128}$/.test(proof.jti) || !Number.isSafeInteger(proof.iat) || Number(proof.iat) < now - 60 || Number(proof.iat) > now + 60 || proof.htm !== request.method || proof.htu !== url || proof.ath !== await sha(token) || (request.nonce === void 0 ? proof.nonce !== void 0 : proof.nonce !== request.nonce)) throw denied();
|
|
3901
|
-
try {
|
|
3902
|
-
const key = await crypto.subtle.importKey("jwk", jwk, {
|
|
3903
|
-
name: "ECDSA",
|
|
3904
|
-
namedCurve: "P-256"
|
|
3905
|
-
}, false, [
|
|
3906
|
-
"verify"
|
|
3907
|
-
]);
|
|
3908
|
-
if (!await crypto.subtle.verify({
|
|
3909
|
-
name: "ECDSA",
|
|
3910
|
-
hash: "SHA-256"
|
|
3911
|
-
}, key, decodePart(parts[2]), new TextEncoder().encode(`${parts[0]}.${parts[1]}`))) throw denied();
|
|
3912
|
-
} catch {
|
|
3913
|
-
throw denied();
|
|
3914
|
-
}
|
|
3915
|
-
const tokenParts = token.split(".");
|
|
3916
|
-
if (tokenParts.length !== 3) throw denied();
|
|
3917
|
-
const tokenHeader = record(decodePart(tokenParts[0]));
|
|
3918
|
-
if (tokenHeader.alg !== "ES256" || tokenHeader.typ !== "at+jwt" || typeof tokenHeader.kid !== "string" || tokenHeader.kid.length > 128 || tokenHeader.crit !== void 0 || tokenHeader.b64 !== void 0 || tokenHeader.jku !== void 0 || tokenHeader.jwk !== void 0 || tokenHeader.x5u !== void 0) throw denied();
|
|
3919
|
-
const untrusted = record(decodePart(tokenParts[1]));
|
|
3920
|
-
if (untrusted.auth_time !== void 0 && (!Number.isSafeInteger(untrusted.auth_time) || Number(untrusted.auth_time) < 0 || Number(untrusted.auth_time) > now + 30)) throw denied();
|
|
3921
|
-
if (untrusted.acr !== void 0 && (typeof untrusted.acr !== "string" || untrusted.acr.length > 128)) throw denied();
|
|
3922
|
-
if (untrusted.amr !== void 0 && (!Array.isArray(untrusted.amr) || untrusted.amr.length > 16 || untrusted.amr.some((method) => typeof method !== "string" || !/^[a-zA-Z0-9._:-]{1,64}$/.test(method)))) throw denied();
|
|
3923
|
-
if (typeof untrusted.client_id !== "string" || !clients.has(untrusted.client_id)) throw denied();
|
|
3924
|
-
let verified;
|
|
3925
|
-
try {
|
|
3926
|
-
verified = await verifyAccessToken({
|
|
3927
|
-
token,
|
|
3928
|
-
transport: options.transport,
|
|
3929
|
-
issuer: options.issuer,
|
|
3930
|
-
clientId: untrusted.client_id,
|
|
3931
|
-
dpopJkt: jkt,
|
|
3932
|
-
expectedScopes: [
|
|
3933
|
-
...request.scopes ?? []
|
|
3934
|
-
]
|
|
3935
|
-
});
|
|
3936
|
-
} catch (error) {
|
|
3937
|
-
if (error instanceof AccountError && error.retryable) throw unavailable();
|
|
3938
|
-
throw denied();
|
|
3939
|
-
}
|
|
3940
|
-
if (!verified.sub || verified.sub.length > 256 || !verified.sid || verified.sid.length > 256 || !Number.isSafeInteger(verified.auth_epoch) || verified.auth_epoch < 0 || typeof verified.scope !== "string" || verified.scope.length > 8192) throw denied();
|
|
3941
|
-
const claims = frozenClaims(verified);
|
|
3942
|
-
const active = /* @__PURE__ */ __name(async () => {
|
|
3943
|
-
if (claims.exp <= Math.floor(Date.now() / 1e3)) throw denied();
|
|
3944
|
-
let current;
|
|
3945
|
-
try {
|
|
3946
|
-
current = await options.sessionActive(claims, token);
|
|
3947
|
-
} catch {
|
|
3948
|
-
throw unavailable();
|
|
3949
|
-
}
|
|
3950
|
-
if (current !== true) throw denied();
|
|
3951
|
-
}, "active");
|
|
3952
|
-
await active();
|
|
3953
|
-
let consumed;
|
|
3954
|
-
try {
|
|
3955
|
-
consumed = await options.replayStore.consume({
|
|
3956
|
-
keyThumbprint: jkt,
|
|
3957
|
-
proofId: proof.jti,
|
|
3958
|
-
method: request.method,
|
|
3959
|
-
url,
|
|
3960
|
-
expiresAtMs: Math.min(claims.exp * 1e3, (Number(proof.iat) + 61) * 1e3)
|
|
3961
|
-
});
|
|
3962
|
-
} catch {
|
|
3963
|
-
throw unavailable();
|
|
3964
|
-
}
|
|
3965
|
-
if (consumed !== true) throw denied();
|
|
3966
|
-
await active();
|
|
3967
|
-
return Object.freeze({
|
|
3968
|
-
claims,
|
|
3969
|
-
revalidate: active
|
|
3970
|
-
});
|
|
3971
|
-
}
|
|
3972
|
-
};
|
|
3973
|
-
}
|
|
3974
|
-
__name(createResourceRequestAuthorizer, "createResourceRequestAuthorizer");
|
|
3975
|
-
function createOidcIntrospectionSessionAuthority(options) {
|
|
3976
|
-
const base2 = new URL(options.issuer);
|
|
3977
|
-
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
3978
|
-
if (base2.origin !== options.issuer || base2.protocol !== "https:" || !Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 3e4) throw new TypeError("Canonical HTTPS issuer and bounded introspection timeout required");
|
|
3979
|
-
const fetchImpl = options.fetchImpl ?? fetch;
|
|
3980
|
-
return async (claims, token) => {
|
|
3981
|
-
if (token.length > MAX_JWT_BYTES || !token) throw unavailable();
|
|
3982
|
-
const controller = new AbortController();
|
|
3983
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
3984
|
-
let response;
|
|
3985
|
-
try {
|
|
3986
|
-
response = await fetchBeforeAbort(fetchImpl, `${base2.origin}/api/oauth2/introspect`, {
|
|
3987
|
-
method: "POST",
|
|
3988
|
-
redirect: "error",
|
|
3989
|
-
cache: "no-store",
|
|
3990
|
-
credentials: "omit",
|
|
3991
|
-
signal: controller.signal,
|
|
3992
|
-
headers: {
|
|
3993
|
-
accept: "application/json",
|
|
3994
|
-
"content-type": "application/x-www-form-urlencoded"
|
|
3995
|
-
},
|
|
3996
|
-
body: new URLSearchParams({
|
|
3997
|
-
token
|
|
3998
|
-
}).toString()
|
|
3999
|
-
}, controller.signal);
|
|
4000
|
-
if (!response.ok || !response.body) throw unavailable();
|
|
4001
|
-
const value = parseJwtObject(await readBoundedText(response, controller.signal, 32768));
|
|
4002
|
-
if (value.active === false) return false;
|
|
4003
|
-
const canonicalAudience = Array.isArray(value.aud) ? value.aud.includes("xeno-api") : value.aud === "xeno-api";
|
|
4004
|
-
return value.active === true && value.token_type === "access_token" && value.iss === claims.iss && value.sub === claims.sub && value.sid === claims.sid && value.client_id === claims.client_id && value.exp === claims.exp && value.scope === claims.scope && canonicalAudience;
|
|
4005
|
-
} catch {
|
|
4006
|
-
throw unavailable();
|
|
4007
|
-
} finally {
|
|
4008
|
-
controller.abort();
|
|
4009
|
-
clearTimeout(timer);
|
|
4010
|
-
if (response) cancelBody(response);
|
|
4011
|
-
}
|
|
4012
|
-
};
|
|
4013
|
-
}
|
|
4014
|
-
__name(createOidcIntrospectionSessionAuthority, "createOidcIntrospectionSessionAuthority");
|
|
4015
|
-
|
|
4016
|
-
// src/index.ts
|
|
4017
|
-
var ACCOUNT_SDK_CONTRACT = Object.freeze({
|
|
4018
|
-
version: 1,
|
|
4019
|
-
workspaceAuthority: 1,
|
|
4020
|
-
workforceResourceOperations: 1,
|
|
4021
|
-
workforceActorBinding: 2,
|
|
4022
|
-
workforceOwnedCatalog: 1,
|
|
4023
|
-
workspaceKeyAuthority: 1,
|
|
4024
|
-
workspaceKeyOperations: 1,
|
|
4025
|
-
workspaceMembershipOperations: 1,
|
|
4026
|
-
workspaceOperationAbandonment: 1,
|
|
4027
|
-
accountOperations: 1,
|
|
4028
|
-
accountIntegrations: 1,
|
|
4029
|
-
notificationAuthority: 1,
|
|
4030
|
-
notificationDestinationOperations: 1,
|
|
4031
|
-
requestBoundAuthorization: 1,
|
|
4032
|
-
serializedRefresh: 1
|
|
4033
|
-
});
|
|
4034
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
4035
|
-
0 && (module.exports = {
|
|
4036
|
-
ACCOUNT_SDK_CONTRACT,
|
|
4037
|
-
AccountClient,
|
|
4038
|
-
AccountError,
|
|
4039
|
-
AccountIntegrationClient,
|
|
4040
|
-
AccountMutationError,
|
|
4041
|
-
AuthzClient,
|
|
4042
|
-
BffSessionClient,
|
|
4043
|
-
LedgerClient,
|
|
4044
|
-
MICRO_PER_CREDIT,
|
|
4045
|
-
NotificationsClient,
|
|
4046
|
-
Transport,
|
|
4047
|
-
WorkforceClient,
|
|
4048
|
-
WorkforceResourceMutationError,
|
|
4049
|
-
WorkspaceClient,
|
|
4050
|
-
WorkspaceKeyMutationError,
|
|
4051
|
-
WorkspaceMembershipMutationError,
|
|
4052
|
-
XenoAccountClient,
|
|
4053
|
-
accountOperationIntentSchema,
|
|
4054
|
-
accountSchema,
|
|
4055
|
-
assertMembershipOperation,
|
|
4056
|
-
authzCheckSchema,
|
|
4057
|
-
authzResultSchema,
|
|
4058
|
-
balanceSchema,
|
|
4059
|
-
buildAuthorizeUrl,
|
|
4060
|
-
codeForStatus,
|
|
4061
|
-
createOidcIntrospectionSessionAuthority,
|
|
4062
|
-
createResourceRequestAuthorizer,
|
|
4063
|
-
exchangeCode,
|
|
4064
|
-
fromMicro,
|
|
4065
|
-
generatePkce,
|
|
4066
|
-
generateState,
|
|
4067
|
-
holdRequestSchema,
|
|
4068
|
-
holdSchema,
|
|
4069
|
-
keychainStore,
|
|
4070
|
-
membershipAbandonedSchema,
|
|
4071
|
-
membershipCommittedSchema,
|
|
4072
|
-
membershipDeliverySchema,
|
|
4073
|
-
membershipMutationSchema,
|
|
4074
|
-
membershipOperationSchema,
|
|
4075
|
-
membershipRejectedSchema,
|
|
4076
|
-
memoryStore,
|
|
4077
|
-
meterAggregationSchema,
|
|
4078
|
-
normalize,
|
|
4079
|
-
normalizeDpopHtu,
|
|
4080
|
-
notificationChannelSchema,
|
|
4081
|
-
notificationDestinationActionSchema,
|
|
4082
|
-
notificationDestinationOperationSchema,
|
|
4083
|
-
notificationEventSchema,
|
|
4084
|
-
notificationRuleSchema,
|
|
4085
|
-
notificationScopeSchema,
|
|
4086
|
-
notificationSettingsSchema,
|
|
4087
|
-
oauthTokenResponseSchema,
|
|
4088
|
-
pollDeviceToken,
|
|
4089
|
-
redact,
|
|
4090
|
-
refreshTokens,
|
|
4091
|
-
startDeviceAuthorization,
|
|
4092
|
-
surfaceSchema,
|
|
4093
|
-
toMicro,
|
|
4094
|
-
tokenSetSchema,
|
|
4095
|
-
usageEventSchema,
|
|
4096
|
-
usageResultSchema,
|
|
4097
|
-
verifyAccessToken,
|
|
4098
|
-
verifyIdToken,
|
|
4099
|
-
verifyLogoutToken,
|
|
4100
|
-
workforceCreateResourceSchema,
|
|
4101
|
-
workforceDefinitionSchema,
|
|
4102
|
-
workforceListOwnedResourcesSchema,
|
|
4103
|
-
workforceOwnerSchema,
|
|
4104
|
-
workforceReadOperationSchema,
|
|
4105
|
-
workspaceInviteRoleSchema,
|
|
4106
|
-
workspaceInviteSchema,
|
|
4107
|
-
workspaceKeyOperationSchema,
|
|
4108
|
-
workspaceKeyRejectionSchema,
|
|
4109
|
-
workspaceKeySchema,
|
|
4110
|
-
workspaceKeyScopeSchema,
|
|
4111
|
-
workspaceMemberSchema,
|
|
4112
|
-
workspaceRoleSchema,
|
|
4113
|
-
workspaceSchema
|
|
4114
|
-
});
|
|
4115
|
-
//# sourceMappingURL=index.js.map
|