@structured-id/ids 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,368 @@
1
+ import { MessageType } from '@protobuf-ts/runtime';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, { get: all[name], enumerable: true });
7
+ };
8
+
9
+ // src/errors.ts
10
+ function describe(reason) {
11
+ switch (reason.type) {
12
+ case "malformed":
13
+ return "not a UUID";
14
+ case "length":
15
+ return `${reason.length} bytes, expected 16`;
16
+ case "nil":
17
+ return "the nil UUID";
18
+ case "max":
19
+ return "the max UUID";
20
+ case "variant":
21
+ return "not an RFC 4122 UUID";
22
+ case "version":
23
+ return `UUID version ${reason.version}, expected version 7`;
24
+ }
25
+ }
26
+ var IdError = class extends Error {
27
+ constructor(kind, reason) {
28
+ super(`invalid ${kind}: ${describe(reason)}`);
29
+ this.kind = kind;
30
+ this.reason = reason;
31
+ }
32
+ kind;
33
+ reason;
34
+ name = "IdError";
35
+ };
36
+ var MissingIdError = class extends Error {
37
+ constructor(kind) {
38
+ super(`missing ${kind}`);
39
+ this.kind = kind;
40
+ }
41
+ kind;
42
+ name = "MissingIdError";
43
+ };
44
+
45
+ // src/validate.ts
46
+ function validate(bytes, kind) {
47
+ if (bytes.length !== 16) {
48
+ throw new IdError(kind, { type: "length", length: bytes.length });
49
+ }
50
+ let zero = true;
51
+ let ones = true;
52
+ for (const byte of bytes) {
53
+ zero &&= byte === 0;
54
+ ones &&= byte === 255;
55
+ }
56
+ if (zero) throw new IdError(kind, { type: "nil" });
57
+ if (ones) throw new IdError(kind, { type: "max" });
58
+ if ((bytes[8] & 192) !== 128) {
59
+ throw new IdError(kind, { type: "variant" });
60
+ }
61
+ const version = bytes[6] >> 4;
62
+ if (version !== 7) throw new IdError(kind, { type: "version", version });
63
+ return bytes.slice();
64
+ }
65
+ var HEX = /^[0-9a-fA-F]{32}$/;
66
+ function parseText(text, kind) {
67
+ let body = text;
68
+ if (body.length === 45 && body.startsWith("urn:uuid:")) {
69
+ body = body.slice(9);
70
+ } else if (body.length === 38 && body.startsWith("{") && body.endsWith("}")) {
71
+ body = body.slice(1, 37);
72
+ }
73
+ let hex;
74
+ if (body.length === 36) {
75
+ if (body[8] !== "-" || body[13] !== "-" || body[18] !== "-" || body[23] !== "-") {
76
+ throw new IdError(kind, { type: "malformed" });
77
+ }
78
+ hex = body.slice(0, 8) + body.slice(9, 13) + body.slice(14, 18) + body.slice(19, 23) + body.slice(24);
79
+ } else if (body.length === 32 && text.length === 32) {
80
+ hex = body;
81
+ } else {
82
+ throw new IdError(kind, { type: "malformed" });
83
+ }
84
+ if (!HEX.test(hex)) throw new IdError(kind, { type: "malformed" });
85
+ const bytes = new Uint8Array(16);
86
+ for (let i = 0; i < 16; i++) {
87
+ bytes[i] = Number.parseInt(hex.slice(2 * i, 2 * i + 2), 16);
88
+ }
89
+ return bytes;
90
+ }
91
+ function formatText(bytes) {
92
+ let hex = "";
93
+ for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
94
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
95
+ }
96
+
97
+ // src/ids.ts
98
+ var Identifier = class _Identifier {
99
+ #bytes;
100
+ constructor(bytes) {
101
+ this.#bytes = bytes;
102
+ }
103
+ /** A copy of the 16 bytes in network order: the wire value. */
104
+ toBytes() {
105
+ return this.#bytes.slice();
106
+ }
107
+ /** Lowercase hyphenated text, for display only; the wire carries bytes. */
108
+ toString() {
109
+ return formatText(this.#bytes);
110
+ }
111
+ /** The same text as `toString`, so JSON logs show a readable value. */
112
+ toJSON() {
113
+ return this.toString();
114
+ }
115
+ /** True for an identifier of the same kind with the same bytes. */
116
+ equals(other) {
117
+ if (!(other instanceof _Identifier) || other.kind !== this.kind) return false;
118
+ const theirs = other.#bytes;
119
+ return this.#bytes.every((byte, i) => byte === theirs[i]);
120
+ }
121
+ };
122
+ var BindingId = class _BindingId extends Identifier {
123
+ static kind = "BindingId";
124
+ kind = "BindingId";
125
+ constructor(bytes) {
126
+ super(bytes);
127
+ }
128
+ /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
129
+ static fromBytes(bytes) {
130
+ return new _BindingId(validate(bytes, _BindingId.kind));
131
+ }
132
+ /** Accept a textual UUID as this identifier, or throw `IdError`. */
133
+ static parse(text) {
134
+ return _BindingId.fromBytes(parseText(text, _BindingId.kind));
135
+ }
136
+ /** Validate a decoded wire message; throws `IdError`. */
137
+ static fromWire(message) {
138
+ return _BindingId.fromBytes(message.value);
139
+ }
140
+ /** The wire message carrying this identifier's bytes. */
141
+ toWire() {
142
+ return { value: this.toBytes() };
143
+ }
144
+ };
145
+ var MachineUserId = class _MachineUserId extends Identifier {
146
+ static kind = "MachineUserId";
147
+ kind = "MachineUserId";
148
+ constructor(bytes) {
149
+ super(bytes);
150
+ }
151
+ /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
152
+ static fromBytes(bytes) {
153
+ return new _MachineUserId(validate(bytes, _MachineUserId.kind));
154
+ }
155
+ /** Accept a textual UUID as this identifier, or throw `IdError`. */
156
+ static parse(text) {
157
+ return _MachineUserId.fromBytes(parseText(text, _MachineUserId.kind));
158
+ }
159
+ /** Validate a decoded wire message; throws `IdError`. */
160
+ static fromWire(message) {
161
+ return _MachineUserId.fromBytes(message.value);
162
+ }
163
+ /** The wire message carrying this identifier's bytes. */
164
+ toWire() {
165
+ return { value: this.toBytes() };
166
+ }
167
+ };
168
+ var PasswordOperationId = class _PasswordOperationId extends Identifier {
169
+ static kind = "PasswordOperationId";
170
+ kind = "PasswordOperationId";
171
+ constructor(bytes) {
172
+ super(bytes);
173
+ }
174
+ /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
175
+ static fromBytes(bytes) {
176
+ return new _PasswordOperationId(validate(bytes, _PasswordOperationId.kind));
177
+ }
178
+ /** Accept a textual UUID as this identifier, or throw `IdError`. */
179
+ static parse(text) {
180
+ return _PasswordOperationId.fromBytes(parseText(text, _PasswordOperationId.kind));
181
+ }
182
+ /** Validate a decoded wire message; throws `IdError`. */
183
+ static fromWire(message) {
184
+ return _PasswordOperationId.fromBytes(message.value);
185
+ }
186
+ /** The wire message carrying this identifier's bytes. */
187
+ toWire() {
188
+ return { value: this.toBytes() };
189
+ }
190
+ };
191
+ var ProvisioningConnectorId = class _ProvisioningConnectorId extends Identifier {
192
+ static kind = "ProvisioningConnectorId";
193
+ kind = "ProvisioningConnectorId";
194
+ constructor(bytes) {
195
+ super(bytes);
196
+ }
197
+ /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
198
+ static fromBytes(bytes) {
199
+ return new _ProvisioningConnectorId(validate(bytes, _ProvisioningConnectorId.kind));
200
+ }
201
+ /** Accept a textual UUID as this identifier, or throw `IdError`. */
202
+ static parse(text) {
203
+ return _ProvisioningConnectorId.fromBytes(parseText(text, _ProvisioningConnectorId.kind));
204
+ }
205
+ /** Validate a decoded wire message; throws `IdError`. */
206
+ static fromWire(message) {
207
+ return _ProvisioningConnectorId.fromBytes(message.value);
208
+ }
209
+ /** The wire message carrying this identifier's bytes. */
210
+ toWire() {
211
+ return { value: this.toBytes() };
212
+ }
213
+ };
214
+ var ProvisioningCredentialId = class _ProvisioningCredentialId extends Identifier {
215
+ static kind = "ProvisioningCredentialId";
216
+ kind = "ProvisioningCredentialId";
217
+ constructor(bytes) {
218
+ super(bytes);
219
+ }
220
+ /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
221
+ static fromBytes(bytes) {
222
+ return new _ProvisioningCredentialId(validate(bytes, _ProvisioningCredentialId.kind));
223
+ }
224
+ /** Accept a textual UUID as this identifier, or throw `IdError`. */
225
+ static parse(text) {
226
+ return _ProvisioningCredentialId.fromBytes(parseText(text, _ProvisioningCredentialId.kind));
227
+ }
228
+ /** Validate a decoded wire message; throws `IdError`. */
229
+ static fromWire(message) {
230
+ return _ProvisioningCredentialId.fromBytes(message.value);
231
+ }
232
+ /** The wire message carrying this identifier's bytes. */
233
+ toWire() {
234
+ return { value: this.toBytes() };
235
+ }
236
+ };
237
+ var ResourceId = class _ResourceId extends Identifier {
238
+ static kind = "ResourceId";
239
+ kind = "ResourceId";
240
+ constructor(bytes) {
241
+ super(bytes);
242
+ }
243
+ /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
244
+ static fromBytes(bytes) {
245
+ return new _ResourceId(validate(bytes, _ResourceId.kind));
246
+ }
247
+ /** Accept a textual UUID as this identifier, or throw `IdError`. */
248
+ static parse(text) {
249
+ return _ResourceId.fromBytes(parseText(text, _ResourceId.kind));
250
+ }
251
+ /** Validate a decoded wire message; throws `IdError`. */
252
+ static fromWire(message) {
253
+ return _ResourceId.fromBytes(message.value);
254
+ }
255
+ /** The wire message carrying this identifier's bytes. */
256
+ toWire() {
257
+ return { value: this.toBytes() };
258
+ }
259
+ };
260
+ function required(type, message) {
261
+ if (message === void 0) throw new MissingIdError(type.kind);
262
+ return type.fromWire(message);
263
+ }
264
+ function optional(type, message) {
265
+ return message === void 0 ? void 0 : type.fromWire(message);
266
+ }
267
+
268
+ // src/generated/sid/v1/ids/ids.ts
269
+ var ids_exports = {};
270
+ __export(ids_exports, {
271
+ BindingId: () => BindingId2,
272
+ MachineUserId: () => MachineUserId2,
273
+ PasswordOperationId: () => PasswordOperationId2,
274
+ ProvisioningConnectorId: () => ProvisioningConnectorId2,
275
+ ProvisioningCredentialId: () => ProvisioningCredentialId2,
276
+ ResourceId: () => ResourceId2
277
+ });
278
+ var BindingId$Type = class extends MessageType {
279
+ constructor() {
280
+ super("sid.v1.ids.BindingId", [
281
+ {
282
+ no: 1,
283
+ name: "value",
284
+ kind: "scalar",
285
+ T: 12
286
+ /*ScalarType.BYTES*/
287
+ }
288
+ ]);
289
+ }
290
+ };
291
+ var BindingId2 = new BindingId$Type();
292
+ var PasswordOperationId$Type = class extends MessageType {
293
+ constructor() {
294
+ super("sid.v1.ids.PasswordOperationId", [
295
+ {
296
+ no: 1,
297
+ name: "value",
298
+ kind: "scalar",
299
+ T: 12
300
+ /*ScalarType.BYTES*/
301
+ }
302
+ ]);
303
+ }
304
+ };
305
+ var PasswordOperationId2 = new PasswordOperationId$Type();
306
+ var MachineUserId$Type = class extends MessageType {
307
+ constructor() {
308
+ super("sid.v1.ids.MachineUserId", [
309
+ {
310
+ no: 1,
311
+ name: "value",
312
+ kind: "scalar",
313
+ T: 12
314
+ /*ScalarType.BYTES*/
315
+ }
316
+ ]);
317
+ }
318
+ };
319
+ var MachineUserId2 = new MachineUserId$Type();
320
+ var ProvisioningConnectorId$Type = class extends MessageType {
321
+ constructor() {
322
+ super("sid.v1.ids.ProvisioningConnectorId", [
323
+ {
324
+ no: 1,
325
+ name: "value",
326
+ kind: "scalar",
327
+ T: 12
328
+ /*ScalarType.BYTES*/
329
+ }
330
+ ]);
331
+ }
332
+ };
333
+ var ProvisioningConnectorId2 = new ProvisioningConnectorId$Type();
334
+ var ResourceId$Type = class extends MessageType {
335
+ constructor() {
336
+ super("sid.v1.ids.ResourceId", [
337
+ {
338
+ no: 1,
339
+ name: "value",
340
+ kind: "scalar",
341
+ T: 12
342
+ /*ScalarType.BYTES*/
343
+ }
344
+ ]);
345
+ }
346
+ };
347
+ var ResourceId2 = new ResourceId$Type();
348
+ var ProvisioningCredentialId$Type = class extends MessageType {
349
+ constructor() {
350
+ super("sid.v1.ids.ProvisioningCredentialId", [
351
+ {
352
+ no: 1,
353
+ name: "value",
354
+ kind: "scalar",
355
+ T: 12
356
+ /*ScalarType.BYTES*/
357
+ }
358
+ ]);
359
+ }
360
+ };
361
+ var ProvisioningCredentialId2 = new ProvisioningCredentialId$Type();
362
+
363
+ // src/index.ts
364
+ var PROTO_PATH = "sid/v1/ids/ids.proto";
365
+
366
+ export { BindingId, IdError, MachineUserId, MissingIdError, PROTO_PATH, PasswordOperationId, ProvisioningConnectorId, ProvisioningCredentialId, ResourceId, optional, required, ids_exports as wire };
367
+ //# sourceMappingURL=index.js.map
368
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/validate.ts","../src/ids.ts","../src/generated/sid/v1/ids/ids.ts","../src/index.ts"],"names":["BindingId","MachineUserId","PasswordOperationId","ProvisioningConnectorId","ProvisioningCredentialId","ResourceId"],"mappings":";;;;;;;;;AAwBA,SAAS,SAAS,MAAA,EAA+B;AAC/C,EAAA,QAAQ,OAAO,IAAA;AAAM,IACnB,KAAK,WAAA;AACH,MAAA,OAAO,YAAA;AAAA,IACT,KAAK,QAAA;AACH,MAAA,OAAO,CAAA,EAAG,OAAO,MAAM,CAAA,mBAAA,CAAA;AAAA,IACzB,KAAK,KAAA;AACH,MAAA,OAAO,cAAA;AAAA,IACT,KAAK,KAAA;AACH,MAAA,OAAO,cAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAA,OAAO,sBAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAA,OAAO,CAAA,aAAA,EAAgB,OAAO,OAAO,CAAA,oBAAA,CAAA;AAAA;AAE3C;AAMO,IAAM,OAAA,GAAN,cAAsB,KAAA,CAAM;AAAA,EAGjC,WAAA,CACW,MACA,MAAA,EACT;AACA,IAAA,KAAA,CAAM,WAAW,IAAI,CAAA,EAAA,EAAK,QAAA,CAAS,MAAM,CAAC,CAAA,CAAE,CAAA;AAHnC,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAGX;AAAA,EAJW,IAAA;AAAA,EACA,MAAA;AAAA,EAJO,IAAA,GAAO,SAAA;AAQ3B;AAGO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EAGxC,YAAqB,IAAA,EAAc;AACjC,IAAA,KAAA,CAAM,CAAA,QAAA,EAAW,IAAI,CAAA,CAAE,CAAA;AADJ,IAAA,IAAA,CAAA,IAAA,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A,QAAS,IAAA,EAAM,QAAA;AAAA,QAAU,CAAA,EAAG;AAAA;AAAA;AAAwB,KACtE,CAAA;AAAA,EACL;AACJ,CAAA;AAIO,IAAMD,yBAAAA,GAA2B,IAAI,6BAAA,EAA8B;;;ACxJnE,IAAM,UAAA,GAAa","file":"index.js","sourcesContent":["/** The identifier kinds this package delivers: one per `sid.v1.ids` message. */\nexport type IdKind =\n | \"BindingId\"\n | \"MachineUserId\"\n | \"PasswordOperationId\"\n | \"ProvisioningConnectorId\"\n | \"ProvisioningCredentialId\"\n | \"ResourceId\";\n\n/** Why a value is not a valid identifier. */\nexport type IdErrorReason =\n /** The text is not a UUID in any accepted textual form. */\n | { readonly type: \"malformed\" }\n /** Binary form of a length other than 16 bytes. */\n | { readonly type: \"length\"; readonly length: number }\n /** The nil UUID (all zero bits). */\n | { readonly type: \"nil\" }\n /** The max UUID (all one bits). */\n | { readonly type: \"max\" }\n /** The variant bits are not those of RFC 9562. */\n | { readonly type: \"variant\" }\n /** An RFC 9562 UUID of a version other than 7. */\n | { readonly type: \"version\"; readonly version: number };\n\nfunction describe(reason: IdErrorReason): string {\n switch (reason.type) {\n case \"malformed\":\n return \"not a UUID\";\n case \"length\":\n return `${reason.length} bytes, expected 16`;\n case \"nil\":\n return \"the nil UUID\";\n case \"max\":\n return \"the max UUID\";\n case \"variant\":\n return \"not an RFC 4122 UUID\";\n case \"version\":\n return `UUID version ${reason.version}, expected version 7`;\n }\n}\n\n/**\n * A value that is not a valid identifier of the requested kind. Carries the\n * kind and the reason, never the value, so it can be logged freely.\n */\nexport class IdError extends Error {\n override readonly name = \"IdError\";\n\n constructor(\n readonly kind: IdKind,\n readonly reason: IdErrorReason,\n ) {\n super(`invalid ${kind}: ${describe(reason)}`);\n }\n}\n\n/** A required identifier message was absent. Absence is never a default. */\nexport class MissingIdError extends Error {\n override readonly name = \"MissingIdError\";\n\n constructor(readonly kind: IdKind) {\n super(`missing ${kind}`);\n }\n}\n","import { IdError, type IdKind } from \"./errors\";\n\n/**\n * The only accepted shape: exactly 16 bytes of a non-nil, non-max UUID of\n * the RFC 9562 variant and version 7 (RFC 9562 sections 4.1, 4.2, 5.7, 5.9,\n * 5.10). Returns a copy, so later changes to the input cannot reach it.\n */\nexport function validate(bytes: Uint8Array, kind: IdKind): Uint8Array {\n if (bytes.length !== 16) {\n throw new IdError(kind, { type: \"length\", length: bytes.length });\n }\n let zero = true;\n let ones = true;\n for (const byte of bytes) {\n zero &&= byte === 0x00;\n ones &&= byte === 0xff;\n }\n if (zero) throw new IdError(kind, { type: \"nil\" });\n if (ones) throw new IdError(kind, { type: \"max\" });\n // RFC 9562 4.1: the variant is the top bits of octet 8; this one is 10.\n if (((bytes[8] as number) & 0xc0) !== 0x80) {\n throw new IdError(kind, { type: \"variant\" });\n }\n // RFC 9562 4.2: the version is the high nibble of octet 6.\n const version = (bytes[6] as number) >> 4;\n if (version !== 7) throw new IdError(kind, { type: \"version\", version });\n return bytes.slice();\n}\n\nconst HEX = /^[0-9a-fA-F]{32}$/;\n\n/**\n * The 16 bytes of a textual UUID: hyphenated, simple (32 hex digits), braced\n * hyphenated or `urn:uuid:` hyphenated (RFC 9562 section 4), the forms the\n * Rust `sid-ids` parser accepts. Text is a presentation form; the wire\n * carries bytes.\n */\nexport function parseText(text: string, kind: IdKind): Uint8Array {\n let body = text;\n if (body.length === 45 && body.startsWith(\"urn:uuid:\")) {\n body = body.slice(9);\n } else if (body.length === 38 && body.startsWith(\"{\") && body.endsWith(\"}\")) {\n body = body.slice(1, 37);\n }\n let hex: string;\n if (body.length === 36) {\n if (body[8] !== \"-\" || body[13] !== \"-\" || body[18] !== \"-\" || body[23] !== \"-\") {\n throw new IdError(kind, { type: \"malformed\" });\n }\n hex =\n body.slice(0, 8) +\n body.slice(9, 13) +\n body.slice(14, 18) +\n body.slice(19, 23) +\n body.slice(24);\n } else if (body.length === 32 && text.length === 32) {\n hex = body;\n } else {\n throw new IdError(kind, { type: \"malformed\" });\n }\n if (!HEX.test(hex)) throw new IdError(kind, { type: \"malformed\" });\n const bytes = new Uint8Array(16);\n for (let i = 0; i < 16; i++) {\n bytes[i] = Number.parseInt(hex.slice(2 * i, 2 * i + 2), 16);\n }\n return bytes;\n}\n\n/** Lowercase hyphenated form (RFC 9562 section 4). */\nexport function formatText(bytes: Uint8Array): string {\n let hex = \"\";\n for (const byte of bytes) hex += byte.toString(16).padStart(2, \"0\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n","import type { IdKind } from \"./errors\";\nimport { MissingIdError } from \"./errors\";\nimport type * as wire from \"./generated/sid/v1/ids/ids\";\nimport { formatText, parseText, validate } from \"./validate\";\n\n/**\n * The common behaviour of every identifier. A value is always a valid UUIDv7:\n * it is built only through validation and its bytes are private. Each kind is\n * its own class with a literal `kind`, so values of different kinds are\n * different types even when their bytes are equal.\n *\n * A valid identifier proves only its shape. It does not prove that the entity\n * exists, whom it belongs to, or that the caller may act on it.\n */\nabstract class Identifier {\n abstract readonly kind: IdKind;\n readonly #bytes: Uint8Array;\n\n protected constructor(bytes: Uint8Array) {\n this.#bytes = bytes;\n }\n\n /** A copy of the 16 bytes in network order: the wire value. */\n toBytes(): Uint8Array {\n return this.#bytes.slice();\n }\n\n /** Lowercase hyphenated text, for display only; the wire carries bytes. */\n toString(): string {\n return formatText(this.#bytes);\n }\n\n /** The same text as `toString`, so JSON logs show a readable value. */\n toJSON(): string {\n return this.toString();\n }\n\n /** True for an identifier of the same kind with the same bytes. */\n equals(other: unknown): boolean {\n if (!(other instanceof Identifier) || other.kind !== this.kind) return false;\n const theirs = other.#bytes;\n return this.#bytes.every((byte, i) => byte === theirs[i]);\n }\n}\n\n/**\n * A Profile's identity at one organization: the pairwise subject that\n * organization's services see. Opaque and unlinkable across organizations.\n */\nexport class BindingId extends Identifier {\n static readonly kind = \"BindingId\";\n readonly kind = \"BindingId\";\n\n private constructor(bytes: Uint8Array) {\n super(bytes);\n }\n\n /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */\n static fromBytes(bytes: Uint8Array): BindingId {\n return new BindingId(validate(bytes, BindingId.kind));\n }\n\n /** Accept a textual UUID as this identifier, or throw `IdError`. */\n static parse(text: string): BindingId {\n return BindingId.fromBytes(parseText(text, BindingId.kind));\n }\n\n /** Validate a decoded wire message; throws `IdError`. */\n static fromWire(message: wire.BindingId): BindingId {\n return BindingId.fromBytes(message.value);\n }\n\n /** The wire message carrying this identifier's bytes. */\n toWire(): wire.BindingId {\n return { value: this.toBytes() };\n }\n}\n\n/**\n * A non-human actor (a service, bot or agent) with its own credentials. Not a\n * Binding, a Profile or a device, whatever its bytes.\n */\nexport class MachineUserId extends Identifier {\n static readonly kind = \"MachineUserId\";\n readonly kind = \"MachineUserId\";\n\n private constructor(bytes: Uint8Array) {\n super(bytes);\n }\n\n /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */\n static fromBytes(bytes: Uint8Array): MachineUserId {\n return new MachineUserId(validate(bytes, MachineUserId.kind));\n }\n\n /** Accept a textual UUID as this identifier, or throw `IdError`. */\n static parse(text: string): MachineUserId {\n return MachineUserId.fromBytes(parseText(text, MachineUserId.kind));\n }\n\n /** Validate a decoded wire message; throws `IdError`. */\n static fromWire(message: wire.MachineUserId): MachineUserId {\n return MachineUserId.fromBytes(message.value);\n }\n\n /** The wire message carrying this identifier's bytes. */\n toWire(): wire.MachineUserId {\n return { value: this.toBytes() };\n }\n}\n\n/**\n * One password-installing operation (a registration, change or authorized\n * reset) from its preparation to its commit. Every retry carries it, so a lost\n * response resolves to the operation's one outcome.\n */\nexport class PasswordOperationId extends Identifier {\n static readonly kind = \"PasswordOperationId\";\n readonly kind = \"PasswordOperationId\";\n\n private constructor(bytes: Uint8Array) {\n super(bytes);\n }\n\n /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */\n static fromBytes(bytes: Uint8Array): PasswordOperationId {\n return new PasswordOperationId(validate(bytes, PasswordOperationId.kind));\n }\n\n /** Accept a textual UUID as this identifier, or throw `IdError`. */\n static parse(text: string): PasswordOperationId {\n return PasswordOperationId.fromBytes(parseText(text, PasswordOperationId.kind));\n }\n\n /** Validate a decoded wire message; throws `IdError`. */\n static fromWire(message: wire.PasswordOperationId): PasswordOperationId {\n return PasswordOperationId.fromBytes(message.value);\n }\n\n /** The wire message carrying this identifier's bytes. */\n toWire(): wire.PasswordOperationId {\n return { value: this.toBytes() };\n }\n}\n\n/**\n * A provisioning connector: one directory source or target acting as its own\n * actor with its own credentials and grants. Not a machine user or a Profile.\n */\nexport class ProvisioningConnectorId extends Identifier {\n static readonly kind = \"ProvisioningConnectorId\";\n readonly kind = \"ProvisioningConnectorId\";\n\n private constructor(bytes: Uint8Array) {\n super(bytes);\n }\n\n /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */\n static fromBytes(bytes: Uint8Array): ProvisioningConnectorId {\n return new ProvisioningConnectorId(validate(bytes, ProvisioningConnectorId.kind));\n }\n\n /** Accept a textual UUID as this identifier, or throw `IdError`. */\n static parse(text: string): ProvisioningConnectorId {\n return ProvisioningConnectorId.fromBytes(parseText(text, ProvisioningConnectorId.kind));\n }\n\n /** Validate a decoded wire message; throws `IdError`. */\n static fromWire(message: wire.ProvisioningConnectorId): ProvisioningConnectorId {\n return ProvisioningConnectorId.fromBytes(message.value);\n }\n\n /** The wire message carrying this identifier's bytes. */\n toWire(): wire.ProvisioningConnectorId {\n return { value: this.toBytes() };\n }\n}\n\n/**\n * One credential of a provisioning connector: the reference listings,\n * rotations, revocations and audit records name. Never the secret itself.\n */\nexport class ProvisioningCredentialId extends Identifier {\n static readonly kind = \"ProvisioningCredentialId\";\n readonly kind = \"ProvisioningCredentialId\";\n\n private constructor(bytes: Uint8Array) {\n super(bytes);\n }\n\n /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */\n static fromBytes(bytes: Uint8Array): ProvisioningCredentialId {\n return new ProvisioningCredentialId(validate(bytes, ProvisioningCredentialId.kind));\n }\n\n /** Accept a textual UUID as this identifier, or throw `IdError`. */\n static parse(text: string): ProvisioningCredentialId {\n return ProvisioningCredentialId.fromBytes(parseText(text, ProvisioningCredentialId.kind));\n }\n\n /** Validate a decoded wire message; throws `IdError`. */\n static fromWire(message: wire.ProvisioningCredentialId): ProvisioningCredentialId {\n return ProvisioningCredentialId.fromBytes(message.value);\n }\n\n /** The wire message carrying this identifier's bytes. */\n toWire(): wire.ProvisioningCredentialId {\n return { value: this.toBytes() };\n }\n}\n\n/**\n * A registered protected resource: the application or API at which access is\n * enforced, in its issuer's context. Not an OAuth client or an audience string.\n */\nexport class ResourceId extends Identifier {\n static readonly kind = \"ResourceId\";\n readonly kind = \"ResourceId\";\n\n private constructor(bytes: Uint8Array) {\n super(bytes);\n }\n\n /** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */\n static fromBytes(bytes: Uint8Array): ResourceId {\n return new ResourceId(validate(bytes, ResourceId.kind));\n }\n\n /** Accept a textual UUID as this identifier, or throw `IdError`. */\n static parse(text: string): ResourceId {\n return ResourceId.fromBytes(parseText(text, ResourceId.kind));\n }\n\n /** Validate a decoded wire message; throws `IdError`. */\n static fromWire(message: wire.ResourceId): ResourceId {\n return ResourceId.fromBytes(message.value);\n }\n\n /** The wire message carrying this identifier's bytes. */\n toWire(): wire.ResourceId {\n return { value: this.toBytes() };\n }\n}\n\n/** An identifier class: its kind and its checked wire conversion. */\nexport interface IdType<T, W> {\n readonly kind: IdKind;\n fromWire(message: W): T;\n}\n\n/**\n * The identifier in a required message field: absence throws\n * `MissingIdError`, an invalid value throws `IdError`.\n */\nexport function required<T, W>(type: IdType<T, W>, message: W | undefined): T {\n if (message === undefined) throw new MissingIdError(type.kind);\n return type.fromWire(message);\n}\n\n/**\n * The identifier in an optional message field: absence stays `undefined`, a\n * present but invalid value throws `IdError` (an empty message is invalid,\n * not absent).\n */\nexport function optional<T, W>(type: IdType<T, W>, message: W | undefined): T | undefined {\n return message === undefined ? undefined : type.fromWire(message);\n}\n","// @generated by protobuf-ts 2.11.1 with parameter force_optimize_code_size\n// @generated from protobuf file \"sid/v1/ids/ids.proto\" (package \"sid.v1.ids\", syntax proto3)\n// tslint:disable\nimport { MessageType } from \"@protobuf-ts/runtime\";\n/**\n * A Profile's identity at one organization: the pairwise subject that\n * organization's services see. Opaque and unlinkable across organizations;\n * it never carries or reveals a ProfileId.\n *\n * @generated from protobuf message sid.v1.ids.BindingId\n */\nexport interface BindingId {\n /**\n * Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,\n * in network byte order. Nil, max, other lengths, versions and variants are\n * invalid. Issued by SID; compared by exact byte equality.\n *\n * @generated from protobuf field: bytes value = 1\n */\n value: Uint8Array;\n}\n/**\n * One password-installing operation (a registration, change or authorized\n * reset) from its preparation to its commit. Every step and retry of the\n * operation carries it, so a lost response resolves to the operation's one\n * outcome instead of starting another.\n *\n * @generated from protobuf message sid.v1.ids.PasswordOperationId\n */\nexport interface PasswordOperationId {\n /**\n * Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,\n * in network byte order. Nil, max, other lengths, versions and variants are\n * invalid. Issued by SID; compared by exact byte equality.\n *\n * @generated from protobuf field: bytes value = 1\n */\n value: Uint8Array;\n}\n/**\n * A non-human actor (a service, bot or agent) with its own SID credentials.\n * Not a Binding, a Profile or a device, whatever its bytes.\n *\n * @generated from protobuf message sid.v1.ids.MachineUserId\n */\nexport interface MachineUserId {\n /**\n * Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,\n * in network byte order. Nil, max, other lengths, versions and variants are\n * invalid. Issued by SID; compared by exact byte equality.\n *\n * @generated from protobuf field: bytes value = 1\n */\n value: Uint8Array;\n}\n/**\n * A provisioning connector: one directory source sending SCIM to an\n * organization, or one target the organization provisions, acting as its own\n * actor with its own credentials and grants. Not a machine user or a Profile.\n *\n * @generated from protobuf message sid.v1.ids.ProvisioningConnectorId\n */\nexport interface ProvisioningConnectorId {\n /**\n * Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,\n * in network byte order. Nil, max, other lengths, versions and variants are\n * invalid. Issued by SID; compared by exact byte equality.\n *\n * @generated from protobuf field: bytes value = 1\n */\n value: Uint8Array;\n}\n/**\n * A registered protected resource: the application or API at which access is\n * enforced, in its issuer's context. Not an OAuth client and not an audience\n * string; its indicator and issuer come from its registration.\n *\n * @generated from protobuf message sid.v1.ids.ResourceId\n */\nexport interface ResourceId {\n /**\n * Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,\n * in network byte order. Nil, max, other lengths, versions and variants are\n * invalid. Issued by SID; compared by exact byte equality.\n *\n * @generated from protobuf field: bytes value = 1\n */\n value: Uint8Array;\n}\n/**\n * One credential of a provisioning connector: the reference listings,\n * rotations, revocations and audit records name. Never the secret itself.\n *\n * @generated from protobuf message sid.v1.ids.ProvisioningCredentialId\n */\nexport interface ProvisioningCredentialId {\n /**\n * Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,\n * in network byte order. Nil, max, other lengths, versions and variants are\n * invalid. Issued by SID; compared by exact byte equality.\n *\n * @generated from protobuf field: bytes value = 1\n */\n value: Uint8Array;\n}\n// @generated message type with reflection information, may provide speed optimized methods\nclass BindingId$Type extends MessageType<BindingId> {\n constructor() {\n super(\"sid.v1.ids.BindingId\", [\n { no: 1, name: \"value\", kind: \"scalar\", T: 12 /*ScalarType.BYTES*/ }\n ]);\n }\n}\n/**\n * @generated MessageType for protobuf message sid.v1.ids.BindingId\n */\nexport const BindingId = new BindingId$Type();\n// @generated message type with reflection information, may provide speed optimized methods\nclass PasswordOperationId$Type extends MessageType<PasswordOperationId> {\n constructor() {\n super(\"sid.v1.ids.PasswordOperationId\", [\n { no: 1, name: \"value\", kind: \"scalar\", T: 12 /*ScalarType.BYTES*/ }\n ]);\n }\n}\n/**\n * @generated MessageType for protobuf message sid.v1.ids.PasswordOperationId\n */\nexport const PasswordOperationId = new PasswordOperationId$Type();\n// @generated message type with reflection information, may provide speed optimized methods\nclass MachineUserId$Type extends MessageType<MachineUserId> {\n constructor() {\n super(\"sid.v1.ids.MachineUserId\", [\n { no: 1, name: \"value\", kind: \"scalar\", T: 12 /*ScalarType.BYTES*/ }\n ]);\n }\n}\n/**\n * @generated MessageType for protobuf message sid.v1.ids.MachineUserId\n */\nexport const MachineUserId = new MachineUserId$Type();\n// @generated message type with reflection information, may provide speed optimized methods\nclass ProvisioningConnectorId$Type extends MessageType<ProvisioningConnectorId> {\n constructor() {\n super(\"sid.v1.ids.ProvisioningConnectorId\", [\n { no: 1, name: \"value\", kind: \"scalar\", T: 12 /*ScalarType.BYTES*/ }\n ]);\n }\n}\n/**\n * @generated MessageType for protobuf message sid.v1.ids.ProvisioningConnectorId\n */\nexport const ProvisioningConnectorId = new ProvisioningConnectorId$Type();\n// @generated message type with reflection information, may provide speed optimized methods\nclass ResourceId$Type extends MessageType<ResourceId> {\n constructor() {\n super(\"sid.v1.ids.ResourceId\", [\n { no: 1, name: \"value\", kind: \"scalar\", T: 12 /*ScalarType.BYTES*/ }\n ]);\n }\n}\n/**\n * @generated MessageType for protobuf message sid.v1.ids.ResourceId\n */\nexport const ResourceId = new ResourceId$Type();\n// @generated message type with reflection information, may provide speed optimized methods\nclass ProvisioningCredentialId$Type extends MessageType<ProvisioningCredentialId> {\n constructor() {\n super(\"sid.v1.ids.ProvisioningCredentialId\", [\n { no: 1, name: \"value\", kind: \"scalar\", T: 12 /*ScalarType.BYTES*/ }\n ]);\n }\n}\n/**\n * @generated MessageType for protobuf message sid.v1.ids.ProvisioningCredentialId\n */\nexport const ProvisioningCredentialId = new ProvisioningCredentialId$Type();\n","/**\n * StructuredID identifiers for TypeScript.\n *\n * Each identifier kind is its own class (`BindingId`, `MachineUserId`, ...),\n * built only through validation: exactly 16 bytes of an RFC 9562 UUIDv7, not\n * nil or max. `wire` holds the generated `sid.v1.ids` messages with their\n * binary and standard ProtoJSON codecs; decoding one proves nothing, and the\n * checked conversion (`fromWire`, `required`, `optional`) validates it.\n */\nexport { IdError, MissingIdError, type IdErrorReason, type IdKind } from \"./errors\";\nexport {\n BindingId,\n MachineUserId,\n PasswordOperationId,\n ProvisioningConnectorId,\n ProvisioningCredentialId,\n ResourceId,\n optional,\n required,\n type IdType,\n} from \"./ids\";\nexport * as wire from \"./generated/sid/v1/ids/ids\";\n\n/** The include-relative path of the identifier schema this package carries. */\nexport const PROTO_PATH = \"sid/v1/ids/ids.proto\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,81 @@
1
1
  {
2
2
  "name": "@structured-id/ids",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "StructuredID identifiers: one checked type per identifier kind, the sid.v1.ids wire messages and validated conversions between them.",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./schema/sid/v1/ids/ids.proto": "./schema/sid/v1/ids/ids.proto"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "schema",
25
+ "README.md",
26
+ "LICENSE",
27
+ "NOTICE"
28
+ ],
29
+ "sideEffects": false,
30
+ "scripts": {
31
+ "schema": "node scripts/schema.mjs",
32
+ "generate": "node scripts/schema.mjs && buf generate schema",
33
+ "build": "yarn generate && tsup",
34
+ "test": "yarn generate && vitest run",
35
+ "lint": "yarn generate && eslint src/ tests/",
36
+ "typecheck": "yarn generate && tsc --noEmit",
37
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\" \"scripts/**/*.mjs\"",
38
+ "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\" \"scripts/**/*.mjs\"",
39
+ "prepack": "yarn build"
40
+ },
41
+ "keywords": [
42
+ "structuredid",
43
+ "identifier",
44
+ "uuidv7",
45
+ "protobuf"
46
+ ],
47
+ "author": "StructuredID <oss@structured.id>",
48
+ "license": "Apache-2.0",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/structured-id/sdk.git",
52
+ "directory": "typescript/packages/ids"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/structured-id/sdk/issues"
56
+ },
57
+ "homepage": "https://github.com/structured-id/sdk/tree/main/typescript/packages/ids#readme",
58
+ "engines": {
59
+ "node": ">=20"
60
+ },
61
+ "dependencies": {
62
+ "@protobuf-ts/runtime": "^2.11.1"
63
+ },
64
+ "devDependencies": {
65
+ "@bufbuild/buf": "^1.73.0",
66
+ "@eslint/js": "^10.0.1",
67
+ "@protobuf-ts/plugin": "^2.11.1",
68
+ "@types/node": "^26.6.3",
69
+ "eslint": "^10.11.0",
70
+ "prettier": "^3.9.9",
71
+ "tsup": "^8.5.1",
72
+ "typescript": "^6.0.3",
73
+ "typescript-eslint": "^8.71.0",
74
+ "vite": "^8",
75
+ "vitest": "^5.0.2"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public",
79
+ "provenance": true
80
+ }
81
+ }
@@ -0,0 +1,68 @@
1
+ syntax = "proto3";
2
+
3
+ // StructuredID identifiers in their binary wire form. Each identifier kind is
4
+ // its own message, so values of different kinds are different types in every
5
+ // generated language even though their bytes have the same shape. Text forms
6
+ // (hyphenated UUID) are for display in SDKs and clients only.
7
+ //
8
+ // This file imports nothing, so a consumer can compile it on its own.
9
+ package sid.v1.ids;
10
+
11
+ // A Profile's identity at one organization: the pairwise subject that
12
+ // organization's services see. Opaque and unlinkable across organizations;
13
+ // it never carries or reveals a ProfileId.
14
+ message BindingId {
15
+ // Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,
16
+ // in network byte order. Nil, max, other lengths, versions and variants are
17
+ // invalid. Issued by SID; compared by exact byte equality.
18
+ bytes value = 1;
19
+ }
20
+
21
+ // One password-installing operation (a registration, change or authorized
22
+ // reset) from its preparation to its commit. Every step and retry of the
23
+ // operation carries it, so a lost response resolves to the operation's one
24
+ // outcome instead of starting another.
25
+ message PasswordOperationId {
26
+ // Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,
27
+ // in network byte order. Nil, max, other lengths, versions and variants are
28
+ // invalid. Issued by SID; compared by exact byte equality.
29
+ bytes value = 1;
30
+ }
31
+
32
+ // A non-human actor (a service, bot or agent) with its own SID credentials.
33
+ // Not a Binding, a Profile or a device, whatever its bytes.
34
+ message MachineUserId {
35
+ // Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,
36
+ // in network byte order. Nil, max, other lengths, versions and variants are
37
+ // invalid. Issued by SID; compared by exact byte equality.
38
+ bytes value = 1;
39
+ }
40
+
41
+ // A provisioning connector: one directory source sending SCIM to an
42
+ // organization, or one target the organization provisions, acting as its own
43
+ // actor with its own credentials and grants. Not a machine user or a Profile.
44
+ message ProvisioningConnectorId {
45
+ // Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,
46
+ // in network byte order. Nil, max, other lengths, versions and variants are
47
+ // invalid. Issued by SID; compared by exact byte equality.
48
+ bytes value = 1;
49
+ }
50
+
51
+ // A registered protected resource: the application or API at which access is
52
+ // enforced, in its issuer's context. Not an OAuth client and not an audience
53
+ // string; its indicator and issuer come from its registration.
54
+ message ResourceId {
55
+ // Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,
56
+ // in network byte order. Nil, max, other lengths, versions and variants are
57
+ // invalid. Issued by SID; compared by exact byte equality.
58
+ bytes value = 1;
59
+ }
60
+
61
+ // One credential of a provisioning connector: the reference listings,
62
+ // rotations, revocations and audit records name. Never the secret itself.
63
+ message ProvisioningCredentialId {
64
+ // Exactly 16 bytes: an RFC 9562 UUID of version 7 and the RFC 9562 variant,
65
+ // in network byte order. Nil, max, other lengths, versions and variants are
66
+ // invalid. Issued by SID; compared by exact byte equality.
67
+ bytes value = 1;
68
+ }