@contextual-io/cli 0.3.1 → 0.4.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/README.md +250 -35
- package/dist/base.js +3 -1
- package/dist/commands/config/add.js +1 -1
- package/dist/commands/config/current.js +1 -1
- package/dist/commands/config/delete.js +1 -1
- package/dist/commands/config/get.js +1 -1
- package/dist/commands/config/index.js +1 -1
- package/dist/commands/config/list.js +1 -1
- package/dist/commands/config/login.js +1 -1
- package/dist/commands/config/use.js +1 -1
- package/dist/commands/records/add.js +1 -1
- package/dist/commands/records/delete.js +1 -1
- package/dist/commands/records/get.js +1 -1
- package/dist/commands/records/index.js +1 -1
- package/dist/commands/records/list.js +1 -1
- package/dist/commands/records/query.js +1 -1
- package/dist/commands/records/replace.js +1 -1
- package/dist/commands/types/add.d.ts +11 -0
- package/dist/commands/types/add.js +57 -0
- package/dist/commands/types/delete.d.ts +12 -0
- package/dist/commands/types/delete.js +35 -0
- package/dist/commands/types/get.d.ts +12 -0
- package/dist/commands/types/get.js +33 -0
- package/dist/commands/types/index.d.ts +9 -0
- package/dist/commands/types/index.js +13 -0
- package/dist/commands/types/list.d.ts +19 -0
- package/dist/commands/types/list.js +128 -0
- package/dist/commands/types/replace.d.ts +13 -0
- package/dist/commands/types/replace.js +57 -0
- package/dist/models/uri.js +5 -0
- package/dist/utils/endpoints.d.ts +1 -0
- package/dist/utils/endpoints.js +1 -0
- package/oclif.manifest.json +351 -16
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import fs, { createReadStream } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import jsonl from "stream-json/jsonl/Parser.js";
|
|
5
|
+
import { BaseCommand } from "../../base.js";
|
|
6
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
7
|
+
import { mapStream, readStreamToEnd } from "../../utils/stream.js";
|
|
8
|
+
export default class TypesAdd extends BaseCommand {
|
|
9
|
+
static aliases = ["types create", "types import"];
|
|
10
|
+
static args = {};
|
|
11
|
+
static description = "Create type(s).";
|
|
12
|
+
static examples = [
|
|
13
|
+
"<%= config.bin %> <%= command.id %>",
|
|
14
|
+
"<%= config.bin %> <%= command.id %> --input-file types.json",
|
|
15
|
+
];
|
|
16
|
+
static flags = {
|
|
17
|
+
"input-file": Flags.file({
|
|
18
|
+
char: "i",
|
|
19
|
+
default: "-",
|
|
20
|
+
description: "file to read. can read stdin if value is '-'",
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
async run() {
|
|
24
|
+
const inputFile = this.flags["input-file"] === "-"
|
|
25
|
+
? "-"
|
|
26
|
+
: path.resolve(this.flags["input-file"]);
|
|
27
|
+
if (inputFile && inputFile !== "-" && !fs.existsSync(inputFile)) {
|
|
28
|
+
throw new Error("File does not exist");
|
|
29
|
+
}
|
|
30
|
+
const stream = inputFile && inputFile !== "-"
|
|
31
|
+
? createReadStream(inputFile)
|
|
32
|
+
: process.stdin;
|
|
33
|
+
const types = await readStreamToEnd(stream
|
|
34
|
+
.pipe(jsonl.parser())
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
.pipe(mapStream(async (x) => x.value))
|
|
37
|
+
.pipe(mapStream(async (x) => JSON.stringify(x))));
|
|
38
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
39
|
+
const create = (body) => this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + "/api/v1/types", {
|
|
40
|
+
body,
|
|
41
|
+
headers: {
|
|
42
|
+
"content-type": "application/json",
|
|
43
|
+
},
|
|
44
|
+
method: "POST",
|
|
45
|
+
});
|
|
46
|
+
for (const type of types) {
|
|
47
|
+
// eslint-disable-next-line no-await-in-loop
|
|
48
|
+
const rv = await create(type);
|
|
49
|
+
if (types.length > 1) {
|
|
50
|
+
this.log(JSON.stringify(rv));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.logJson(rv);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesDelete extends BaseCommand<typeof TypesDelete> {
|
|
3
|
+
static args: {
|
|
4
|
+
uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { BaseCommand } from "../../base.js";
|
|
3
|
+
import { parseUri } from "../../models/uri.js";
|
|
4
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
5
|
+
export default class TypesDelete extends BaseCommand {
|
|
6
|
+
static args = {
|
|
7
|
+
"uri": Args.string({ description: "uri of type" }),
|
|
8
|
+
};
|
|
9
|
+
static description = "Delete a type.";
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> <%= command.id %> native-object:my-type",
|
|
12
|
+
"<%= config.bin %> <%= command.id %> --type my-type",
|
|
13
|
+
];
|
|
14
|
+
static flags = {
|
|
15
|
+
type: Flags.string({
|
|
16
|
+
char: "T",
|
|
17
|
+
description: "type",
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const { uri } = this.args;
|
|
22
|
+
const { type: flagType } = this.flags;
|
|
23
|
+
let type = flagType;
|
|
24
|
+
if (uri) {
|
|
25
|
+
const { type: uriType } = parseUri(uri);
|
|
26
|
+
type = uriType;
|
|
27
|
+
}
|
|
28
|
+
if (!type) {
|
|
29
|
+
throw new Error("Type not provided");
|
|
30
|
+
}
|
|
31
|
+
await this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + `/api/v1/types/${type}`, {
|
|
32
|
+
method: "DELETE",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesGet extends BaseCommand<typeof TypesGet> {
|
|
3
|
+
static args: {
|
|
4
|
+
uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { BaseCommand } from "../../base.js";
|
|
3
|
+
import { parseUri } from "../../models/uri.js";
|
|
4
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
5
|
+
export default class TypesGet extends BaseCommand {
|
|
6
|
+
static args = {
|
|
7
|
+
"uri": Args.string({ description: "uri of type" }),
|
|
8
|
+
};
|
|
9
|
+
static description = "Get a type.";
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> <%= command.id %> native-object:my-type",
|
|
12
|
+
"<%= config.bin %> <%= command.id %> --type my-type",
|
|
13
|
+
];
|
|
14
|
+
static flags = {
|
|
15
|
+
type: Flags.string({
|
|
16
|
+
char: "T",
|
|
17
|
+
description: "type",
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const { uri } = this.args;
|
|
22
|
+
const { type: flagType } = this.flags;
|
|
23
|
+
let type = flagType;
|
|
24
|
+
if (uri) {
|
|
25
|
+
const { type: uriType } = parseUri(uri);
|
|
26
|
+
type = uriType;
|
|
27
|
+
}
|
|
28
|
+
if (!type) {
|
|
29
|
+
throw new Error("Type not provided");
|
|
30
|
+
}
|
|
31
|
+
this.logJson(await this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + `/api/v1/types/${type}`));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseConfigCommand } from "../../base.js";
|
|
2
|
+
export default class Types extends BaseConfigCommand<typeof Types> {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: never[];
|
|
6
|
+
static flags: {};
|
|
7
|
+
static usage: string[];
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseConfigCommand } from "../../base.js";
|
|
2
|
+
export default class Types extends BaseConfigCommand {
|
|
3
|
+
static args = {};
|
|
4
|
+
static description = "Manage types.";
|
|
5
|
+
static examples = [];
|
|
6
|
+
static flags = {};
|
|
7
|
+
static usage = [
|
|
8
|
+
"<%= command.id %> <COMMAND>",
|
|
9
|
+
];
|
|
10
|
+
async run() {
|
|
11
|
+
await this.showHelp();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesList extends BaseCommand<typeof TypesList> {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
"exact-search": import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
export: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
from: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
"include-total": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
"order-by": import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
"page-size": import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
"page-token": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
progress: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
search: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
to: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/* eslint-disable unicorn/no-array-reduce */
|
|
2
|
+
import { Flags } from "@oclif/core";
|
|
3
|
+
import { BaseCommand } from "../../base.js";
|
|
4
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
5
|
+
import { endTime, startTime } from "../../utils/time.js";
|
|
6
|
+
const flagArrayToParam = (cmd, values) => values
|
|
7
|
+
.map(_ => _.split("="))
|
|
8
|
+
.map(([k, v]) => ({ [`${cmd}.${k}`]: v }))
|
|
9
|
+
.reduce((a, b) => ({ ...a, ...b }), {});
|
|
10
|
+
export default class TypesList extends BaseCommand {
|
|
11
|
+
static args = {};
|
|
12
|
+
static description = "List types.";
|
|
13
|
+
static examples = [
|
|
14
|
+
"<%= config.bin %> <%= command.id %>",
|
|
15
|
+
"<%= config.bin %> <%= command.id %> --order-by field1:desc",
|
|
16
|
+
"<%= config.bin %> <%= command.id %> -s field1=value1 -s field2=value2 --include-total",
|
|
17
|
+
];
|
|
18
|
+
static flags = {
|
|
19
|
+
"exact-search": Flags.string({
|
|
20
|
+
char: "S",
|
|
21
|
+
description: "search fields exactly",
|
|
22
|
+
multiple: true,
|
|
23
|
+
}),
|
|
24
|
+
export: Flags.boolean({
|
|
25
|
+
allowNo: false,
|
|
26
|
+
char: "e",
|
|
27
|
+
description: "export data as JSONL",
|
|
28
|
+
}),
|
|
29
|
+
from: Flags.string({
|
|
30
|
+
char: "f",
|
|
31
|
+
description: "search from",
|
|
32
|
+
multiple: true,
|
|
33
|
+
}),
|
|
34
|
+
"include-total": Flags.boolean({
|
|
35
|
+
allowNo: false,
|
|
36
|
+
description: "include total count",
|
|
37
|
+
}),
|
|
38
|
+
"order-by": Flags.string({
|
|
39
|
+
char: "o",
|
|
40
|
+
description: "order fields",
|
|
41
|
+
multiple: true,
|
|
42
|
+
}),
|
|
43
|
+
"page-size": Flags.integer({
|
|
44
|
+
description: "number of types per page",
|
|
45
|
+
max: 250,
|
|
46
|
+
min: 0,
|
|
47
|
+
}),
|
|
48
|
+
"page-token": Flags.string({
|
|
49
|
+
description: "page token to fetch",
|
|
50
|
+
}),
|
|
51
|
+
progress: Flags.boolean({
|
|
52
|
+
allowNo: false,
|
|
53
|
+
char: "p",
|
|
54
|
+
description: "show progress during export",
|
|
55
|
+
}),
|
|
56
|
+
search: Flags.string({
|
|
57
|
+
char: "s",
|
|
58
|
+
description: "search fields",
|
|
59
|
+
multiple: true,
|
|
60
|
+
}),
|
|
61
|
+
to: Flags.string({
|
|
62
|
+
char: "t",
|
|
63
|
+
description: "search to",
|
|
64
|
+
multiple: true,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
async run() {
|
|
68
|
+
const params = {
|
|
69
|
+
...(this.flags["page-size"] && { pageSize: this.flags["page-size"] }),
|
|
70
|
+
...(this.flags["page-token"] && { pageToken: this.flags["page-token"] }),
|
|
71
|
+
...(this.flags["include-total"] && { includeTotal: true }),
|
|
72
|
+
...(this.flags["order-by"] && { orderBy: this.flags["order-by"] }),
|
|
73
|
+
...flagArrayToParam("search", this.flags.search ?? []),
|
|
74
|
+
...flagArrayToParam("exactSearch", this.flags["exact-search"] ?? []),
|
|
75
|
+
...flagArrayToParam("from", this.flags.from ?? []),
|
|
76
|
+
...flagArrayToParam("to", this.flags.to ?? []),
|
|
77
|
+
};
|
|
78
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
79
|
+
const list = (params) => this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + "/api/v1/$page/types", {
|
|
80
|
+
body: JSON.stringify(params),
|
|
81
|
+
headers: {
|
|
82
|
+
"content-type": "application/json",
|
|
83
|
+
},
|
|
84
|
+
method: "POST",
|
|
85
|
+
});
|
|
86
|
+
if (this.flags.export) {
|
|
87
|
+
const pageSize = this.flags["page-size"] ?? 250;
|
|
88
|
+
params.pageSize = pageSize;
|
|
89
|
+
params.includeTotal = true;
|
|
90
|
+
const start = startTime();
|
|
91
|
+
let page = 1;
|
|
92
|
+
let nextPageToken;
|
|
93
|
+
let totalCount = 1;
|
|
94
|
+
do {
|
|
95
|
+
if (nextPageToken) {
|
|
96
|
+
params.pageToken = nextPageToken;
|
|
97
|
+
}
|
|
98
|
+
const xStart = startTime();
|
|
99
|
+
// eslint-disable-next-line no-await-in-loop
|
|
100
|
+
const x = await list(params);
|
|
101
|
+
const xDuration = endTime(xStart);
|
|
102
|
+
if (x.totalCount) {
|
|
103
|
+
totalCount = x.totalCount;
|
|
104
|
+
}
|
|
105
|
+
x.items
|
|
106
|
+
.map(_ => JSON.stringify(_))
|
|
107
|
+
// eslint-disable-next-line unicorn/no-array-for-each
|
|
108
|
+
.forEach(_ => this.log(_));
|
|
109
|
+
nextPageToken = x.nextPageToken;
|
|
110
|
+
if (this.flags.progress) {
|
|
111
|
+
const duration = endTime(start);
|
|
112
|
+
const totalPages = Math.ceil(totalCount / pageSize);
|
|
113
|
+
const recsPerSec = Math.ceil((page * pageSize) / (duration * 1000));
|
|
114
|
+
const eta = (((duration / page) * (totalPages - page)) / 1000).toFixed(2);
|
|
115
|
+
process.stderr.write(`\r\u001B[Kexporting types eta: ${eta}s totalCount: ${totalCount} page: ${page}/${totalPages} records/s: ${recsPerSec} lastCall: ${xDuration.toFixed(2)}ms`);
|
|
116
|
+
}
|
|
117
|
+
page++;
|
|
118
|
+
} while (nextPageToken);
|
|
119
|
+
if (this.flags.progress) {
|
|
120
|
+
process.stderr.write("\n");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const rv = await list(params);
|
|
125
|
+
this.logJson(rv);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseCommand } from "../../base.js";
|
|
2
|
+
export default class TypesReplace extends BaseCommand<typeof TypesReplace> {
|
|
3
|
+
static args: {
|
|
4
|
+
uri: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
"input-file": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import fs, { createReadStream } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { BaseCommand } from "../../base.js";
|
|
5
|
+
import { parseUri } from "../../models/uri.js";
|
|
6
|
+
import { getRegistryApiEndpoint } from "../../utils/endpoints.js";
|
|
7
|
+
import { readStreamToEnd } from "../../utils/stream.js";
|
|
8
|
+
export default class TypesReplace extends BaseCommand {
|
|
9
|
+
static args = {
|
|
10
|
+
"uri": Args.string({ description: "uri of type" }),
|
|
11
|
+
};
|
|
12
|
+
static description = "Replace a type.";
|
|
13
|
+
static examples = [
|
|
14
|
+
"<%= config.bin %> <%= command.id %> native-object:my-type --input-file record.json",
|
|
15
|
+
"<%= config.bin %> <%= command.id %> --type my-type --input-file record.json",
|
|
16
|
+
];
|
|
17
|
+
static flags = {
|
|
18
|
+
"input-file": Flags.file({
|
|
19
|
+
char: "i",
|
|
20
|
+
default: "-",
|
|
21
|
+
description: "file to read. can read stdin if value is '-'",
|
|
22
|
+
}),
|
|
23
|
+
type: Flags.string({
|
|
24
|
+
char: "T",
|
|
25
|
+
description: "type",
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
async run() {
|
|
29
|
+
const { uri } = this.args;
|
|
30
|
+
const { type: flagType } = this.flags;
|
|
31
|
+
let type = flagType;
|
|
32
|
+
if (uri) {
|
|
33
|
+
const { type: uriType } = parseUri(uri);
|
|
34
|
+
type = uriType;
|
|
35
|
+
}
|
|
36
|
+
if (!type) {
|
|
37
|
+
throw new Error("Type not provided");
|
|
38
|
+
}
|
|
39
|
+
const inputFile = this.flags["input-file"] === "-"
|
|
40
|
+
? "-"
|
|
41
|
+
: path.resolve(this.flags["input-file"]);
|
|
42
|
+
if (inputFile && inputFile !== "-" && !fs.existsSync(inputFile)) {
|
|
43
|
+
throw new Error("File does not exist");
|
|
44
|
+
}
|
|
45
|
+
const input = (await readStreamToEnd(inputFile && inputFile !== "-"
|
|
46
|
+
? createReadStream(inputFile)
|
|
47
|
+
: process.stdin)).join("");
|
|
48
|
+
const replace = (body) => this.fetch(({ silo, tenantId }) => getRegistryApiEndpoint(tenantId, silo) + `/api/v1/types/${type}`, {
|
|
49
|
+
body,
|
|
50
|
+
headers: {
|
|
51
|
+
"content-type": "application/json",
|
|
52
|
+
},
|
|
53
|
+
method: "PUT",
|
|
54
|
+
});
|
|
55
|
+
this.logJson(await replace(input));
|
|
56
|
+
}
|
|
57
|
+
}
|
package/dist/models/uri.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { UrlSafeId } from "./url-safe-id.js";
|
|
2
3
|
export const Uri = z.string().regex(/^native-object:[a-z0-9-]+(\/.+)?/, { error: "URI must match one of the following formats: 'native-object:<type-id>' or 'native-object:<type-id>/<instance-id>'" });
|
|
3
4
|
export const parseUri = (uri) => {
|
|
5
|
+
const parsedType = UrlSafeId.safeParse(uri);
|
|
6
|
+
if (parsedType.success) {
|
|
7
|
+
return { type: parsedType.data };
|
|
8
|
+
}
|
|
4
9
|
const parsed = Uri.parse(uri);
|
|
5
10
|
const [type, id] = parsed.replace(/^native-object:/, "").split("/");
|
|
6
11
|
return { id, type };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Silo } from "../models/silo.js";
|
|
2
2
|
export declare const getNativeObjectApiEndpoint: (tenantId: string, silo: Silo) => string;
|
|
3
|
+
export declare const getRegistryApiEndpoint: (tenantId: string, silo: Silo) => string;
|
|
3
4
|
export declare const getAuthApiEndpoint: (tenantId: string, silo: Silo) => string;
|
package/dist/utils/endpoints.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export const getNativeObjectApiEndpoint = (tenantId, silo) => `https://native-object.${tenantId}.my${silo === "prod" ? "" : `.${silo}`}.contextual.io`;
|
|
2
|
+
export const getRegistryApiEndpoint = (tenantId, silo) => `https://native-object-registry.${tenantId}.my${silo === "prod" ? "" : `.${silo}`}.contextual.io`;
|
|
2
3
|
export const getAuthApiEndpoint = (tenantId, silo) => `https://auth.${tenantId}.my${silo === "prod" ? "" : `.${silo}`}.contextual.io`;
|