@zitadel/node
Version:
Library for API access to ZITADEL. Provides compiled gRPC service clients and helpers for applications and service accounts.
170 lines (169 loc) • 5.7 kB
JavaScript
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v2.7.7
// protoc unknown
// source: zitadel/auth_n_key.proto
/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import Long from "long";
import { Timestamp } from "../google/protobuf/timestamp.js";
import { ObjectDetails } from "./object.js";
export const protobufPackage = "zitadel.authn.v1";
export var KeyType;
(function (KeyType) {
KeyType[KeyType["KEY_TYPE_UNSPECIFIED"] = 0] = "KEY_TYPE_UNSPECIFIED";
KeyType[KeyType["KEY_TYPE_JSON"] = 1] = "KEY_TYPE_JSON";
KeyType[KeyType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
})(KeyType || (KeyType = {}));
export function keyTypeFromJSON(object) {
switch (object) {
case 0:
case "KEY_TYPE_UNSPECIFIED":
return KeyType.KEY_TYPE_UNSPECIFIED;
case 1:
case "KEY_TYPE_JSON":
return KeyType.KEY_TYPE_JSON;
case -1:
case "UNRECOGNIZED":
default:
return KeyType.UNRECOGNIZED;
}
}
export function keyTypeToJSON(object) {
switch (object) {
case KeyType.KEY_TYPE_UNSPECIFIED:
return "KEY_TYPE_UNSPECIFIED";
case KeyType.KEY_TYPE_JSON:
return "KEY_TYPE_JSON";
case KeyType.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
}
}
function createBaseKey() {
return { id: "", details: undefined, type: 0, expirationDate: undefined };
}
export const Key = {
encode(message, writer = new BinaryWriter()) {
if (message.id !== "") {
writer.uint32(10).string(message.id);
}
if (message.details !== undefined) {
ObjectDetails.encode(message.details, writer.uint32(18).fork()).join();
}
if (message.type !== 0) {
writer.uint32(24).int32(message.type);
}
if (message.expirationDate !== undefined) {
Timestamp.encode(toTimestamp(message.expirationDate), writer.uint32(34).fork()).join();
}
return writer;
},
decode(input, length) {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseKey();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 10) {
break;
}
message.id = reader.string();
continue;
}
case 2: {
if (tag !== 18) {
break;
}
message.details = ObjectDetails.decode(reader, reader.uint32());
continue;
}
case 3: {
if (tag !== 24) {
break;
}
message.type = reader.int32();
continue;
}
case 4: {
if (tag !== 34) {
break;
}
message.expirationDate = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object) {
return {
id: isSet(object.id) ? globalThis.String(object.id) : "",
details: isSet(object.details) ? ObjectDetails.fromJSON(object.details) : undefined,
type: isSet(object.type) ? keyTypeFromJSON(object.type) : 0,
expirationDate: isSet(object.expirationDate) ? fromJsonTimestamp(object.expirationDate) : undefined,
};
},
toJSON(message) {
const obj = {};
if (message.id !== "") {
obj.id = message.id;
}
if (message.details !== undefined) {
obj.details = ObjectDetails.toJSON(message.details);
}
if (message.type !== 0) {
obj.type = keyTypeToJSON(message.type);
}
if (message.expirationDate !== undefined) {
obj.expirationDate = message.expirationDate.toISOString();
}
return obj;
},
create(base) {
return Key.fromPartial(base ?? {});
},
fromPartial(object) {
const message = createBaseKey();
message.id = object.id ?? "";
message.details = (object.details !== undefined && object.details !== null)
? ObjectDetails.fromPartial(object.details)
: undefined;
message.type = object.type ?? 0;
message.expirationDate = object.expirationDate ?? undefined;
return message;
},
};
function toTimestamp(date) {
const seconds = numberToLong(Math.trunc(date.getTime() / 1_000));
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
function fromTimestamp(t) {
let millis = (t.seconds.toNumber() || 0) * 1_000;
millis += (t.nanos || 0) / 1_000_000;
return new globalThis.Date(millis);
}
function fromJsonTimestamp(o) {
if (o instanceof globalThis.Date) {
return o;
}
else if (typeof o === "string") {
return new globalThis.Date(o);
}
else {
return fromTimestamp(Timestamp.fromJSON(o));
}
}
function numberToLong(number) {
return Long.fromNumber(number);
}
function isSet(value) {
return value !== null && value !== undefined;
}