credential.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. export * as Credential from "./credential"
  2. import { Schema } from "effect"
  3. import { optional } from "./schema"
  4. import { IntegrationMethodID } from "./integration-id"
  5. import { ascending } from "./identifier"
  6. import { NonNegativeInt, statics } from "./schema"
  7. export const ID = Schema.String.pipe(
  8. Schema.brand("Credential.ID"),
  9. statics((schema) => ({ create: () => schema.make("cred_" + ascending()) })),
  10. )
  11. export type ID = typeof ID.Type
  12. export interface OAuth extends Schema.Schema.Type<typeof OAuth> {}
  13. export const OAuth = Schema.Struct({
  14. type: Schema.Literal("oauth"),
  15. methodID: IntegrationMethodID,
  16. refresh: Schema.String,
  17. access: Schema.String,
  18. expires: NonNegativeInt,
  19. metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
  20. }).annotate({ identifier: "Credential.OAuth" })
  21. export interface Key extends Schema.Schema.Type<typeof Key> {}
  22. export const Key = Schema.Struct({
  23. type: Schema.Literal("key"),
  24. key: Schema.String,
  25. metadata: optional(Schema.Record(Schema.String, Schema.Unknown)),
  26. }).annotate({ identifier: "Credential.Key" })
  27. export const Value = Schema.Union([OAuth, Key])
  28. .pipe(Schema.toTaggedUnion("type"))
  29. .annotate({ identifier: "Credential.Value" })
  30. export type Value = Schema.Schema.Type<typeof Value>