@tailor-platform/sdk 0.10.2 → 0.10.4
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/CHANGELOG.md +14 -0
- package/dist/cli/api.d.mts +1 -1
- package/dist/cli/api.mjs +2 -2
- package/dist/cli/index.mjs +40 -95
- package/dist/configure/index.d.mts +3 -3
- package/dist/configure/index.mjs +1 -1
- package/dist/{index-DyBFt3bp.d.mts → index-DENkoB_m.d.mts} +1 -1
- package/dist/{token-B-1pOHj2.mjs → token-DIx5IQOi.mjs} +39 -37
- package/dist/{types-Dyhfh5b6.d.mts → types-CCSNkBzX.d.mts} +9 -9
- package/dist/utils/test/index.d.mts +2 -2
- package/package.json +3 -3
- package/dist/{config-C5UYYrp1.mjs → auth-Di3vQUrT.mjs} +15 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @tailor-platform/sdk
|
|
2
2
|
|
|
3
|
+
## 0.10.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#49](https://github.com/tailor-platform/sdk/pull/49) [`8fef369`](https://github.com/tailor-platform/sdk/commit/8fef369ab65ea34d85aef24a38ac3d0124626a41) Thanks [@remiposo](https://github.com/remiposo)! - Use Controlplane OAuth2 client for login/logout
|
|
8
|
+
|
|
9
|
+
## 0.10.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#40](https://github.com/tailor-platform/sdk/pull/40) [`314543f`](https://github.com/tailor-platform/sdk/commit/314543fc8edeefff944f024a52a89142646329b4) Thanks [@IzumiSy](https://github.com/IzumiSy)! - Export types that `db.type` function uses internally.
|
|
14
|
+
|
|
15
|
+
This enables users to bundle Tailor DB type definition as an independent package without using forced type assertion using `any`.
|
|
16
|
+
|
|
3
17
|
## 0.10.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/cli/api.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference path="./../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-
|
|
3
|
+
import { AppConfig, CodeGeneratorBase, Executor, Generator, Resolver, TailorDBTypeConfig } from "../types-CCSNkBzX.mjs";
|
|
4
4
|
import "citty";
|
|
5
5
|
import "zod";
|
|
6
6
|
import "@bufbuild/protobuf/wkt";
|
package/dist/cli/api.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import
|
|
1
|
+
import { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList } from "../token-DIx5IQOi.mjs";
|
|
2
|
+
import "../auth-Di3vQUrT.mjs";
|
|
3
3
|
|
|
4
4
|
export { apply, generate, generateUserTypes, loadConfig, machineUserList, machineUserToken, show, workspaceCreate, workspaceDelete, workspaceList };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import "../
|
|
3
|
-
import
|
|
2
|
+
import { PATScope, applyCommand, commonArgs, createCommand, deleteCommand, fetchAll, fetchLatestToken, fetchUserInfo, formatArgs, generateCommand, initOAuth2Client, initOperatorClient, listCommand as listCommand$4, listCommand$1 as listCommand, loadAccessToken, loadConfig, loadConfigPath, loadWorkspaceId, parseFormat, printWithFormat, readPackageJson, readPlatformConfig, showCommand, tokenCommand, withCommonArgs, writePlatformConfig } from "../token-DIx5IQOi.mjs";
|
|
3
|
+
import "../auth-Di3vQUrT.mjs";
|
|
4
4
|
import { register } from "node:module";
|
|
5
5
|
import { defineCommand, runCommand, runMain } from "citty";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import ml from "multiline-ts";
|
|
8
8
|
import { consola } from "consola";
|
|
9
|
+
import { generateCodeVerifier } from "@badgateway/oauth2-client";
|
|
9
10
|
import chalk from "chalk";
|
|
10
11
|
import { spawnSync } from "node:child_process";
|
|
11
12
|
import * as crypto from "node:crypto";
|
|
12
13
|
import * as http from "node:http";
|
|
13
|
-
import isWsl from "is-wsl";
|
|
14
14
|
import open from "open";
|
|
15
15
|
|
|
16
16
|
//#region src/cli/init.ts
|
|
@@ -20,9 +20,9 @@ const detectPackageManager = () => {
|
|
|
20
20
|
"yarn",
|
|
21
21
|
"pnpm"
|
|
22
22
|
];
|
|
23
|
-
const userAgent
|
|
24
|
-
if (!userAgent
|
|
25
|
-
const [name] = userAgent
|
|
23
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
24
|
+
if (!userAgent) return;
|
|
25
|
+
const [name] = userAgent.split("/");
|
|
26
26
|
if (!availablePMs.includes(name)) return;
|
|
27
27
|
return name;
|
|
28
28
|
};
|
|
@@ -67,84 +67,32 @@ const initCommand = defineCommand({
|
|
|
67
67
|
|
|
68
68
|
//#endregion
|
|
69
69
|
//#region src/cli/login.ts
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const LOGIN_URL = PLATFORM_AUTH_URL + "/login";
|
|
74
|
-
const TOKEN_URL = PLATFORM_AUTH_URL + "/token";
|
|
75
|
-
const USER_INFO_URL = PLATFORM_AUTH_URL + "/userinfo";
|
|
76
|
-
const randomState = () => {
|
|
70
|
+
const redirectPort = 8085;
|
|
71
|
+
const redirectUri = `http://localhost:${redirectPort}/callback`;
|
|
72
|
+
function randomState() {
|
|
77
73
|
return crypto.randomBytes(32).toString("base64url");
|
|
78
|
-
}
|
|
79
|
-
const exchangeCode = async (code) => {
|
|
80
|
-
const body = new URLSearchParams();
|
|
81
|
-
body.append("code", code);
|
|
82
|
-
body.append("redirect_uri", CALLBACK_URL);
|
|
83
|
-
const resp = await fetch(TOKEN_URL, {
|
|
84
|
-
method: "POST",
|
|
85
|
-
headers: {
|
|
86
|
-
"User-Agent": await userAgent(),
|
|
87
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
88
|
-
},
|
|
89
|
-
body
|
|
90
|
-
});
|
|
91
|
-
if (!resp.ok) throw new Error(`Failed to exchange code: ${resp.statusText}`);
|
|
92
|
-
const rawData = await resp.json();
|
|
93
|
-
return z.object({
|
|
94
|
-
access_token: z.string(),
|
|
95
|
-
refresh_token: z.string(),
|
|
96
|
-
expires_in: z.number()
|
|
97
|
-
}).parse(rawData);
|
|
98
|
-
};
|
|
99
|
-
const fetchUserInfo = async (accessToken) => {
|
|
100
|
-
const resp = await fetch(USER_INFO_URL, { headers: {
|
|
101
|
-
Authorization: `Bearer ${accessToken}`,
|
|
102
|
-
"User-Agent": await userAgent()
|
|
103
|
-
} });
|
|
104
|
-
if (!resp.ok) throw new Error(`Failed to fetch user info: ${resp.statusText}`);
|
|
105
|
-
const rawData = await resp.json();
|
|
106
|
-
return z.object({ email: z.string() }).parse(rawData);
|
|
107
|
-
};
|
|
74
|
+
}
|
|
108
75
|
const startAuthServer = async () => {
|
|
76
|
+
const client = initOAuth2Client();
|
|
77
|
+
const state = randomState();
|
|
78
|
+
const codeVerifier = await generateCodeVerifier();
|
|
109
79
|
return new Promise((resolve, reject) => {
|
|
110
|
-
const state = randomState();
|
|
111
80
|
const server = http.createServer(async (req, res) => {
|
|
112
81
|
try {
|
|
113
|
-
if (!req.url?.startsWith("/callback"))
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
121
|
-
const receivedState = url.searchParams.get("state");
|
|
122
|
-
const code = url.searchParams.get("code");
|
|
123
|
-
if (receivedState !== state) {
|
|
124
|
-
res.writeHead(400);
|
|
125
|
-
const msg = "Invalid state parameter";
|
|
126
|
-
res.end(msg);
|
|
127
|
-
reject(msg);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (!code) {
|
|
131
|
-
res.writeHead(400);
|
|
132
|
-
const msg = "Missing authorization code";
|
|
133
|
-
res.end(msg);
|
|
134
|
-
reject(msg);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const tokens = await exchangeCode(code);
|
|
138
|
-
const userInfo = await fetchUserInfo(tokens.access_token);
|
|
139
|
-
const expiresAt = /* @__PURE__ */ new Date();
|
|
140
|
-
expiresAt.setSeconds(expiresAt.getSeconds() + tokens.expires_in);
|
|
82
|
+
if (!req.url?.startsWith("/callback")) throw new Error("Invalid callback URL");
|
|
83
|
+
const tokens = await client.authorizationCode.getTokenFromCodeRedirect(`http://${req.headers.host}${req.url}`, {
|
|
84
|
+
redirectUri,
|
|
85
|
+
state,
|
|
86
|
+
codeVerifier
|
|
87
|
+
});
|
|
88
|
+
const userInfo = await fetchUserInfo(tokens.accessToken);
|
|
141
89
|
const pfConfig = readPlatformConfig();
|
|
142
90
|
pfConfig.users = {
|
|
143
91
|
...pfConfig.users,
|
|
144
92
|
[userInfo.email]: {
|
|
145
|
-
access_token: tokens.
|
|
146
|
-
refresh_token: tokens.
|
|
147
|
-
token_expires_at: expiresAt.toISOString()
|
|
93
|
+
access_token: tokens.accessToken,
|
|
94
|
+
refresh_token: tokens.refreshToken,
|
|
95
|
+
token_expires_at: new Date(tokens.expiresAt).toISOString()
|
|
148
96
|
}
|
|
149
97
|
};
|
|
150
98
|
pfConfig.current_user = userInfo.email;
|
|
@@ -156,8 +104,8 @@ const startAuthServer = async () => {
|
|
|
156
104
|
}));
|
|
157
105
|
resolve();
|
|
158
106
|
} catch (error) {
|
|
159
|
-
res.writeHead(
|
|
160
|
-
res.end("
|
|
107
|
+
res.writeHead(401);
|
|
108
|
+
res.end("Authentication failed");
|
|
161
109
|
reject(error);
|
|
162
110
|
} finally {
|
|
163
111
|
server.close();
|
|
@@ -173,13 +121,15 @@ const startAuthServer = async () => {
|
|
|
173
121
|
server.on("error", (error) => {
|
|
174
122
|
reject(error);
|
|
175
123
|
});
|
|
176
|
-
server.listen(
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
124
|
+
server.listen(redirectPort, async () => {
|
|
125
|
+
const authorizeUri = await client.authorizationCode.getAuthorizeUri({
|
|
126
|
+
redirectUri,
|
|
127
|
+
state,
|
|
128
|
+
codeVerifier
|
|
129
|
+
});
|
|
130
|
+
consola.info(`Opening browser for login:\n\n${authorizeUri}\n`);
|
|
181
131
|
try {
|
|
182
|
-
await open(
|
|
132
|
+
await open(authorizeUri);
|
|
183
133
|
} catch {
|
|
184
134
|
consola.warn("Failed to open browser automatically. Please open the URL above manually.");
|
|
185
135
|
}
|
|
@@ -200,7 +150,6 @@ const loginCommand = defineCommand({
|
|
|
200
150
|
|
|
201
151
|
//#endregion
|
|
202
152
|
//#region src/cli/logout.ts
|
|
203
|
-
const LOGOUT_URL = PLATFORM_AUTH_URL + "/logout";
|
|
204
153
|
const logoutCommand = defineCommand({
|
|
205
154
|
meta: {
|
|
206
155
|
name: "logout",
|
|
@@ -209,20 +158,16 @@ const logoutCommand = defineCommand({
|
|
|
209
158
|
args: commonArgs,
|
|
210
159
|
run: withCommonArgs(async () => {
|
|
211
160
|
const pfConfig = readPlatformConfig();
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const token = pfConfig.users[pfConfig.current_user]?.access_token;
|
|
217
|
-
if (!token) {
|
|
161
|
+
const tokens = pfConfig.current_user ? pfConfig.users[pfConfig.current_user] : void 0;
|
|
162
|
+
if (!tokens) {
|
|
218
163
|
consola.warn("You are not logged in.");
|
|
219
164
|
return;
|
|
220
165
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
166
|
+
initOAuth2Client().revoke({
|
|
167
|
+
accessToken: tokens.access_token,
|
|
168
|
+
refreshToken: tokens.refresh_token,
|
|
169
|
+
expiresAt: Date.parse(tokens.token_expires_at)
|
|
170
|
+
}, "refresh_token");
|
|
226
171
|
delete pfConfig.users[pfConfig.current_user];
|
|
227
172
|
pfConfig.current_user = null;
|
|
228
173
|
writePlatformConfig(pfConfig);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AuthConfig, AuthExternalConfig, AuthOwnConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, IDToken, IdPConfig, IdPExternalConfig, IdProviderConfig, OAuth2Client, OAuth2ClientGrantType, OIDC, PermissionCondition, QueryType, Resolver, ResolverExternalConfig, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, unauthenticatedTailorUser } from "../types-
|
|
4
|
-
import { FunctionOperation, GqlOperation, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, Operation, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, ResolverExecutedArgs, ResolverExecutedTrigger, ScheduleTrigger, Trigger, WebhookOperation, createExecutor, createResolver, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t } from "../index-
|
|
5
|
-
export { AuthConfig, AuthExternalConfig, AuthOwnConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, FunctionOperation, GqlOperation, IDToken, IdPConfig, IdPExternalConfig, IdProviderConfig, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, OAuth2Client, OAuth2ClientGrantType, OIDC, Operation, PermissionCondition, QueryType, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, Resolver, ResolverExecutedArgs, ResolverExecutedTrigger, ResolverExternalConfig, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, ScheduleTrigger, StaticWebsiteConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, Trigger, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, WebhookOperation, createExecutor, createResolver, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t, unauthenticatedTailorUser };
|
|
3
|
+
import { AuthConfig, AuthExternalConfig, AuthOwnConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, IDToken, IdPConfig, IdPExternalConfig, IdProviderConfig, OAuth2Client, OAuth2ClientGrantType, OIDC, PermissionCondition, QueryType, Resolver, ResolverExternalConfig, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, StaticWebsiteConfig, TailorDBField, TailorDBInstance, TailorDBType, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, unauthenticatedTailorUser } from "../types-CCSNkBzX.mjs";
|
|
4
|
+
import { FunctionOperation, GqlOperation, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, Operation, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, ResolverExecutedArgs, ResolverExecutedTrigger, ScheduleTrigger, Trigger, WebhookOperation, createExecutor, createResolver, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t } from "../index-DENkoB_m.mjs";
|
|
5
|
+
export { AuthConfig, AuthExternalConfig, AuthOwnConfig, AuthServiceInput, BuiltinIdP, ExecutorServiceConfig, ExecutorServiceInput, FunctionOperation, GqlOperation, IDToken, IdPConfig, IdPExternalConfig, IdProviderConfig, IncomingWebhookArgs, IncomingWebhookRequest, IncomingWebhookTrigger, OAuth2Client, OAuth2ClientGrantType, OIDC, Operation, PermissionCondition, QueryType, RecordCreatedArgs, RecordDeletedArgs, RecordTrigger, RecordUpdatedArgs, Resolver, ResolverExecutedArgs, ResolverExecutedTrigger, ResolverExternalConfig, ResolverServiceConfig, ResolverServiceInput, SAML, SCIMAttribute, SCIMAttributeMapping, SCIMAttributeType, SCIMAuthorization, SCIMConfig, SCIMResource, ScheduleTrigger, StaticWebsiteConfig, TailorDBField, TailorDBInstance, TailorDBType, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, TenantProviderConfig, Trigger, UserAttributeKey, UserAttributeListKey, UserAttributeMap, UsernameFieldKey, ValueOperand, WebhookOperation, createExecutor, createResolver, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, incomingWebhookTrigger, infer, output, recordCreatedTrigger, recordDeletedTrigger, recordUpdatedTrigger, resolverExecutedTrigger, scheduleTrigger, t, unauthenticatedTailorUser };
|
package/dist/configure/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TailorField, db, defineAuth, defineConfig, defineGenerators, t as t$1, unauthenticatedTailorUser } from "../
|
|
1
|
+
import { TailorField, db, defineAuth, defineConfig, defineGenerators, t as t$1, unauthenticatedTailorUser } from "../auth-Di3vQUrT.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/configure/services/resolver/resolver.ts
|
|
4
4
|
function createResolver(config) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference path="./plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { AllowedValues, AllowedValuesOutput, ArrayFieldOutput, ExecutorInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, GqlOperation, IncomingWebhookTrigger as IncomingWebhookTrigger$1, InferFieldsOutput, RecordTrigger as RecordTrigger$1, ResolverExecutedTrigger as ResolverExecutedTrigger$1, ResolverInput, ScheduleTriggerInput, TailorDBType, TailorField, TailorUser, WebhookOperation, output as output$1 } from "./types-
|
|
3
|
+
import { AllowedValues, AllowedValuesOutput, ArrayFieldOutput, ExecutorInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, GqlOperation, IncomingWebhookTrigger as IncomingWebhookTrigger$1, InferFieldsOutput, RecordTrigger as RecordTrigger$1, ResolverExecutedTrigger as ResolverExecutedTrigger$1, ResolverInput, ScheduleTriggerInput, TailorDBType, TailorField, TailorUser, WebhookOperation, output as output$1 } from "./types-CCSNkBzX.mjs";
|
|
4
4
|
import { EmptyObject } from "type-fest";
|
|
5
5
|
import { Client } from "@urql/core";
|
|
6
6
|
import { StandardCRON } from "ts-cron-validator";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDistDir, tailorUserMap } from "./
|
|
1
|
+
import { getDistDir, tailorUserMap } from "./auth-Di3vQUrT.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import * as path from "node:path";
|
|
@@ -13,6 +13,7 @@ import ml from "multiline-ts";
|
|
|
13
13
|
import { loadEnvFile } from "node:process";
|
|
14
14
|
import { consola } from "consola";
|
|
15
15
|
import { table } from "table";
|
|
16
|
+
import { OAuth2Client } from "@badgateway/oauth2-client";
|
|
16
17
|
import { MethodOptions_IdempotencyLevel, ValueSchema, file_google_protobuf_descriptor, file_google_protobuf_duration, file_google_protobuf_field_mask, file_google_protobuf_struct, file_google_protobuf_timestamp, timestampDate } from "@bufbuild/protobuf/wkt";
|
|
17
18
|
import { Code, ConnectError, createClient } from "@connectrpc/connect";
|
|
18
19
|
import { createConnectTransport } from "@connectrpc/connect-node";
|
|
@@ -201,8 +202,8 @@ var ExecutorService = class {
|
|
|
201
202
|
}
|
|
202
203
|
async loadExecutorForFile(executorFile, timestamp) {
|
|
203
204
|
try {
|
|
204
|
-
const baseUrl
|
|
205
|
-
const executorModule = await (timestamp === void 0 ? import(baseUrl
|
|
205
|
+
const baseUrl = pathToFileURL(executorFile).href;
|
|
206
|
+
const executorModule = await (timestamp === void 0 ? import(baseUrl) : import(`${baseUrl}?t=${timestamp.getTime()}`));
|
|
206
207
|
const result = ExecutorSchema.safeParse(executorModule.default);
|
|
207
208
|
if (result.success) {
|
|
208
209
|
const relativePath = path.relative(process.cwd(), executorFile);
|
|
@@ -286,8 +287,8 @@ var ResolverService = class {
|
|
|
286
287
|
}
|
|
287
288
|
async loadResolverForFile(resolverFile, timestamp) {
|
|
288
289
|
try {
|
|
289
|
-
const baseUrl
|
|
290
|
-
const resolverModule = await (timestamp === void 0 ? import(baseUrl
|
|
290
|
+
const baseUrl = pathToFileURL(resolverFile).href;
|
|
291
|
+
const resolverModule = await (timestamp === void 0 ? import(baseUrl) : import(`${baseUrl}?t=${timestamp.getTime()}`));
|
|
291
292
|
const result = ResolverSchema.safeParse(resolverModule.default);
|
|
292
293
|
if (result.success) {
|
|
293
294
|
const relativePath = path.relative(process.cwd(), resolverFile);
|
|
@@ -336,8 +337,8 @@ var TailorDBService = class {
|
|
|
336
337
|
async loadTypesForFile(typeFile, timestamp) {
|
|
337
338
|
this.rawTypes[typeFile] = {};
|
|
338
339
|
try {
|
|
339
|
-
const baseUrl
|
|
340
|
-
const module = await (timestamp === void 0 ? import(baseUrl
|
|
340
|
+
const baseUrl = pathToFileURL(typeFile).href;
|
|
341
|
+
const module = await (timestamp === void 0 ? import(baseUrl) : import(`${baseUrl}?t=${timestamp.getTime()}`));
|
|
341
342
|
for (const exportName of Object.keys(module)) {
|
|
342
343
|
const exportedValue = module[exportName];
|
|
343
344
|
if (exportedValue && typeof exportedValue === "object" && exportedValue.constructor?.name === "TailorDBType" && typeof exportedValue.name === "string" && typeof exportedValue.fields === "object" && exportedValue.metadata && typeof exportedValue.metadata === "object") {
|
|
@@ -2290,11 +2291,20 @@ async function readPackageJson() {
|
|
|
2290
2291
|
|
|
2291
2292
|
//#endregion
|
|
2292
2293
|
//#region src/cli/client.ts
|
|
2293
|
-
const
|
|
2294
|
+
const platformBaseUrl = process.env.PLATFORM_URL ?? "https://api.tailor.tech";
|
|
2295
|
+
const oauth2ClientId = "cpoc_0Iudir72fqSpqC6GQ58ri1cLAqcq5vJl";
|
|
2296
|
+
const oauth2DiscoveryEndpoint = "/.well-known/oauth-authorization-server/oauth2/platform";
|
|
2297
|
+
function initOAuth2Client() {
|
|
2298
|
+
return new OAuth2Client({
|
|
2299
|
+
clientId: oauth2ClientId,
|
|
2300
|
+
server: platformBaseUrl,
|
|
2301
|
+
discoveryEndpoint: oauth2DiscoveryEndpoint
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2294
2304
|
async function initOperatorClient(accessToken) {
|
|
2295
2305
|
const transport = createConnectTransport({
|
|
2296
2306
|
httpVersion: "2",
|
|
2297
|
-
baseUrl,
|
|
2307
|
+
baseUrl: platformBaseUrl,
|
|
2298
2308
|
interceptors: [
|
|
2299
2309
|
await userAgentInterceptor(),
|
|
2300
2310
|
await bearerTokenInterceptor(accessToken),
|
|
@@ -2321,26 +2331,6 @@ async function bearerTokenInterceptor(accessToken) {
|
|
|
2321
2331
|
return await next(req);
|
|
2322
2332
|
};
|
|
2323
2333
|
}
|
|
2324
|
-
async function refreshToken(refreshToken$1) {
|
|
2325
|
-
const refreshUrl = new URL("/auth/platform/token/refresh", baseUrl).href;
|
|
2326
|
-
const formData = new URLSearchParams();
|
|
2327
|
-
formData.append("refresh_token", refreshToken$1);
|
|
2328
|
-
const resp = await fetch(refreshUrl, {
|
|
2329
|
-
method: "POST",
|
|
2330
|
-
headers: {
|
|
2331
|
-
"User-Agent": await userAgent(),
|
|
2332
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
2333
|
-
},
|
|
2334
|
-
body: formData
|
|
2335
|
-
});
|
|
2336
|
-
if (!resp.ok) throw new Error("Failed to refresh token");
|
|
2337
|
-
const rawJson = await resp.json();
|
|
2338
|
-
return z.object({
|
|
2339
|
-
access_token: z.string(),
|
|
2340
|
-
refresh_token: z.string(),
|
|
2341
|
-
expires_in: z.number()
|
|
2342
|
-
}).parse(rawJson);
|
|
2343
|
-
}
|
|
2344
2334
|
function retryInterceptor() {
|
|
2345
2335
|
return (next) => async (req) => {
|
|
2346
2336
|
if (req.stream) return await next(req);
|
|
@@ -2385,6 +2375,16 @@ async function fetchAll(fn) {
|
|
|
2385
2375
|
}
|
|
2386
2376
|
return items;
|
|
2387
2377
|
}
|
|
2378
|
+
async function fetchUserInfo(accessToken) {
|
|
2379
|
+
const userInfoUrl = new URL("/auth/platform/userinfo", platformBaseUrl).href;
|
|
2380
|
+
const resp = await fetch(userInfoUrl, { headers: {
|
|
2381
|
+
Authorization: `Bearer ${accessToken}`,
|
|
2382
|
+
"User-Agent": await userAgent()
|
|
2383
|
+
} });
|
|
2384
|
+
if (!resp.ok) throw new Error(`Failed to fetch user info: ${resp.statusText}`);
|
|
2385
|
+
const rawJson = await resp.json();
|
|
2386
|
+
return z.object({ email: z.string() }).parse(rawJson);
|
|
2387
|
+
}
|
|
2388
2388
|
async function resolveStaticWebsiteUrls(client, workspaceId, urls, context) {
|
|
2389
2389
|
if (!urls) return [];
|
|
2390
2390
|
return (await Promise.all(urls.map(async (url) => {
|
|
@@ -2557,16 +2557,18 @@ async function fetchLatestToken(config, user) {
|
|
|
2557
2557
|
Please verify your user name and login using 'tailor-sdk login' command.
|
|
2558
2558
|
`);
|
|
2559
2559
|
if (new Date(tokens.token_expires_at) > /* @__PURE__ */ new Date()) return tokens.access_token;
|
|
2560
|
-
const resp = await refreshToken(
|
|
2561
|
-
|
|
2562
|
-
|
|
2560
|
+
const resp = await initOAuth2Client().refreshToken({
|
|
2561
|
+
accessToken: tokens.access_token,
|
|
2562
|
+
refreshToken: tokens.refresh_token,
|
|
2563
|
+
expiresAt: Date.parse(tokens.token_expires_at)
|
|
2564
|
+
});
|
|
2563
2565
|
config.users[user] = {
|
|
2564
|
-
access_token: resp.
|
|
2565
|
-
refresh_token: resp.
|
|
2566
|
-
token_expires_at:
|
|
2566
|
+
access_token: resp.accessToken,
|
|
2567
|
+
refresh_token: resp.refreshToken,
|
|
2568
|
+
token_expires_at: new Date(resp.expiresAt).toISOString()
|
|
2567
2569
|
};
|
|
2568
2570
|
writePlatformConfig(config);
|
|
2569
|
-
return resp.
|
|
2571
|
+
return resp.accessToken;
|
|
2570
2572
|
}
|
|
2571
2573
|
function loadConfigPath(configPath) {
|
|
2572
2574
|
if (configPath) return configPath;
|
|
@@ -6316,4 +6318,4 @@ const tokenCommand = defineCommand({
|
|
|
6316
6318
|
});
|
|
6317
6319
|
|
|
6318
6320
|
//#endregion
|
|
6319
|
-
export { PATScope, apply, applyCommand, commonArgs, createCommand, deleteCommand, fetchAll, fetchLatestToken, formatArgs, generate, generateCommand, generateUserTypes, initOperatorClient, listCommand, listCommand$1, loadAccessToken, loadConfig, loadConfigPath, loadWorkspaceId, machineUserList, machineUserToken, parseFormat, printWithFormat, readPackageJson, readPlatformConfig, show, showCommand, tokenCommand,
|
|
6321
|
+
export { PATScope, apply, applyCommand, commonArgs, createCommand, deleteCommand, fetchAll, fetchLatestToken, fetchUserInfo, formatArgs, generate, generateCommand, generateUserTypes, initOAuth2Client, initOperatorClient, listCommand, listCommand$1, loadAccessToken, loadConfig, loadConfigPath, loadWorkspaceId, machineUserList, machineUserToken, parseFormat, printWithFormat, readPackageJson, readPlatformConfig, show, showCommand, tokenCommand, withCommonArgs, workspaceCreate, workspaceDelete, workspaceList, writePlatformConfig };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference path="./plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as zod34 from "zod";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
import * as type_fest0 from "type-fest";
|
|
7
7
|
import { IsAny, NonEmptyObject } from "type-fest";
|
|
8
|
-
import * as
|
|
8
|
+
import * as zod_v4_core50 from "zod/v4/core";
|
|
9
9
|
|
|
10
10
|
//#region src/configure/types/helpers.d.ts
|
|
11
11
|
type Prettify<T> = { [K in keyof T as string extends K ? never : K]: T[K] } & {};
|
|
@@ -1293,12 +1293,12 @@ declare function defineGenerators(...configs: GeneratorConfig[]): (["@tailor-pla
|
|
|
1293
1293
|
}] | {
|
|
1294
1294
|
id: string;
|
|
1295
1295
|
description: string;
|
|
1296
|
-
processType:
|
|
1297
|
-
processResolver:
|
|
1298
|
-
processExecutor:
|
|
1299
|
-
aggregate:
|
|
1300
|
-
processTailorDBNamespace?:
|
|
1301
|
-
processResolverNamespace?:
|
|
1296
|
+
processType: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut>;
|
|
1297
|
+
processResolver: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut>;
|
|
1298
|
+
processExecutor: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut>;
|
|
1299
|
+
aggregate: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod34.ZodAny>;
|
|
1300
|
+
processTailorDBNamespace?: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut> | undefined;
|
|
1301
|
+
processResolverNamespace?: zod_v4_core50.$InferInnerFunctionType<zod_v4_core50.$ZodFunctionArgs, zod_v4_core50.$ZodFunctionOut> | undefined;
|
|
1302
1302
|
})[];
|
|
1303
1303
|
//#endregion
|
|
1304
1304
|
//#region src/parser/service/executor/schema.d.ts
|
|
@@ -1418,4 +1418,4 @@ type WebhookOperation = z.infer<typeof WebhookOperationSchema>;
|
|
|
1418
1418
|
type Executor = z.infer<typeof ExecutorSchema>;
|
|
1419
1419
|
type ExecutorInput = z.input<typeof ExecutorSchema>;
|
|
1420
1420
|
//#endregion
|
|
1421
|
-
export { AllowedValues, AllowedValuesOutput, AppConfig, ArrayFieldOutput, AuthConfig, AuthExternalConfig, AuthOwnConfig, type AuthServiceInput, type BuiltinIdP, CodeGeneratorBase, Executor, ExecutorInput, ExecutorServiceConfig, ExecutorServiceInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, Generator, GqlOperation, type IDToken, IdPConfig, IdPExternalConfig, type IdProviderConfig, IncomingWebhookTrigger, InferFieldsOutput, type OAuth2Client, type OAuth2ClientGrantType, type OIDC, PermissionCondition, QueryType, RecordTrigger, Resolver, ResolverExecutedTrigger, ResolverExternalConfig, ResolverInput, ResolverServiceConfig, ResolverServiceInput, type SAML, type SCIMAttribute, type SCIMAttributeMapping, type SCIMAttributeType, type SCIMAuthorization, type SCIMConfig, type SCIMResource, ScheduleTriggerInput, StaticWebsiteConfig, TailorDBType, TailorDBTypeConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, type TenantProviderConfig, type UserAttributeKey, type UserAttributeListKey, type UserAttributeMap, type UsernameFieldKey, type ValueOperand, WebhookOperation, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, output, unauthenticatedTailorUser };
|
|
1421
|
+
export { AllowedValues, AllowedValuesOutput, AppConfig, ArrayFieldOutput, AuthConfig, AuthExternalConfig, AuthOwnConfig, type AuthServiceInput, type BuiltinIdP, CodeGeneratorBase, Executor, ExecutorInput, ExecutorServiceConfig, ExecutorServiceInput, FieldMetadata, FieldOptions, FieldOutput, FunctionOperation, Generator, GqlOperation, type IDToken, IdPConfig, IdPExternalConfig, type IdProviderConfig, IncomingWebhookTrigger, InferFieldsOutput, type OAuth2Client, type OAuth2ClientGrantType, type OIDC, PermissionCondition, QueryType, RecordTrigger, Resolver, ResolverExecutedTrigger, ResolverExternalConfig, ResolverInput, ResolverServiceConfig, ResolverServiceInput, type SAML, type SCIMAttribute, type SCIMAttributeMapping, type SCIMAttributeType, type SCIMAuthorization, type SCIMConfig, type SCIMResource, ScheduleTriggerInput, StaticWebsiteConfig, TailorDBField, TailorDBInstance, TailorDBType, TailorDBTypeConfig, TailorField, TailorTypeGqlPermission, TailorTypePermission, TailorUser, type TenantProviderConfig, type UserAttributeKey, type UserAttributeListKey, type UserAttributeMap, type UsernameFieldKey, type ValueOperand, WebhookOperation, db, defineAuth, defineConfig, defineGenerators, defineIdp, defineStaticWebSite, output, unauthenticatedTailorUser };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="./../../plugin-generated.d.ts" />
|
|
2
2
|
|
|
3
|
-
import { TailorDBType, TailorField, TailorUser } from "../../types-
|
|
4
|
-
import { output } from "../../index-
|
|
3
|
+
import { TailorDBType, TailorField, TailorUser } from "../../types-CCSNkBzX.mjs";
|
|
4
|
+
import { output } from "../../index-DENkoB_m.mjs";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/test/index.d.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailor-platform/sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Tailor Platform SDK - The SDK to work with Tailor Platform",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/configure/index.mjs",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"types": "./dist/configure/index.d.mts",
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@badgateway/oauth2-client": "3.3.1",
|
|
42
43
|
"@bufbuild/protobuf": "2.10.0",
|
|
43
44
|
"@connectrpc/connect": "2.1.0",
|
|
44
45
|
"@connectrpc/connect-node": "2.1.0",
|
|
@@ -51,7 +52,6 @@
|
|
|
51
52
|
"consola": "3.4.2",
|
|
52
53
|
"es-toolkit": "1.41.0",
|
|
53
54
|
"inflection": "3.0.2",
|
|
54
|
-
"is-wsl": "3.1.0",
|
|
55
55
|
"madge": "8.0.0",
|
|
56
56
|
"multiline-ts": "4.0.1",
|
|
57
57
|
"open": "10.2.0",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"globals": "16.5.0",
|
|
76
76
|
"tsdown": "0.15.6",
|
|
77
77
|
"typescript": "5.9.3",
|
|
78
|
-
"typescript-eslint": "8.
|
|
78
|
+
"typescript-eslint": "8.47.0",
|
|
79
79
|
"vitest": "4.0.8"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
@@ -708,21 +708,6 @@ const db = {
|
|
|
708
708
|
}) }
|
|
709
709
|
};
|
|
710
710
|
|
|
711
|
-
//#endregion
|
|
712
|
-
//#region src/configure/services/auth/index.ts
|
|
713
|
-
function defineAuth(name, config) {
|
|
714
|
-
return {
|
|
715
|
-
...config,
|
|
716
|
-
name,
|
|
717
|
-
invoker(machineUser) {
|
|
718
|
-
return {
|
|
719
|
-
authName: name,
|
|
720
|
-
machineUser
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
|
|
726
711
|
//#endregion
|
|
727
712
|
//#region src/configure/config.ts
|
|
728
713
|
let distPath = null;
|
|
@@ -739,5 +724,20 @@ function defineGenerators(...configs) {
|
|
|
739
724
|
return configs;
|
|
740
725
|
}
|
|
741
726
|
|
|
727
|
+
//#endregion
|
|
728
|
+
//#region src/configure/services/auth/index.ts
|
|
729
|
+
function defineAuth(name, config) {
|
|
730
|
+
return {
|
|
731
|
+
...config,
|
|
732
|
+
name,
|
|
733
|
+
invoker(machineUser) {
|
|
734
|
+
return {
|
|
735
|
+
authName: name,
|
|
736
|
+
machineUser
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
742
742
|
//#endregion
|
|
743
743
|
export { TailorField, db, defineAuth, defineConfig, defineGenerators, getDistDir, t, tailorUserMap, unauthenticatedTailorUser };
|