@marcoappio/marco-config 4.0.0 → 4.0.1
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
-
type AppwriteFunctionContext = 'authenticated' | 'internal' | 'webhook';
|
|
2
|
+
type AppwriteFunctionContext = 'authenticated' | 'internal' | 'public' | 'webhook';
|
|
3
3
|
export declare const appwriteFunctions: {
|
|
4
4
|
readonly api: {
|
|
5
5
|
readonly id: "marco-api";
|
|
@@ -111,6 +111,40 @@ export declare const appwriteFunctions: {
|
|
|
111
111
|
readonly failedAccountIds: v.ArraySchema<v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>, v.BrandAction<string, "AccountId">]>, undefined>, undefined>;
|
|
112
112
|
}, undefined>;
|
|
113
113
|
};
|
|
114
|
+
readonly authSendCode: {
|
|
115
|
+
errorSchema: v.StrictObjectSchema<{
|
|
116
|
+
readonly code: v.PicklistSchema<readonly ["AUTHENTICATION_FAILED", "AUTHORIZATION_FAILED", "CONFLICT", "INVALID_REQUEST", "NOT_FOUND", "PROVIDER_REJECTED", "TRANSIENT_FAILURE", "INTERNAL_ERROR"], undefined>;
|
|
117
|
+
readonly retryable: v.BooleanSchema<undefined>;
|
|
118
|
+
}, undefined>;
|
|
119
|
+
context: "public";
|
|
120
|
+
method: "POST";
|
|
121
|
+
path: "/auth/send-code";
|
|
122
|
+
requestSchema: v.StrictObjectSchema<{
|
|
123
|
+
readonly email: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RfcEmailAction<string, undefined>]>, undefined>;
|
|
124
|
+
readonly userId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, undefined>]>;
|
|
125
|
+
}, undefined>;
|
|
126
|
+
responseSchema: v.StrictObjectSchema<{
|
|
127
|
+
readonly userId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, undefined>]>;
|
|
128
|
+
}, undefined>;
|
|
129
|
+
};
|
|
130
|
+
readonly authVerifyCode: {
|
|
131
|
+
errorSchema: v.StrictObjectSchema<{
|
|
132
|
+
readonly code: v.PicklistSchema<readonly ["AUTHENTICATION_FAILED", "AUTHORIZATION_FAILED", "CONFLICT", "INVALID_REQUEST", "NOT_FOUND", "PROVIDER_REJECTED", "TRANSIENT_FAILURE", "INTERNAL_ERROR"], undefined>;
|
|
133
|
+
readonly retryable: v.BooleanSchema<undefined>;
|
|
134
|
+
}, undefined>;
|
|
135
|
+
context: "public";
|
|
136
|
+
method: "POST";
|
|
137
|
+
path: "/auth/verify-code";
|
|
138
|
+
requestSchema: v.StrictObjectSchema<{
|
|
139
|
+
readonly code: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
140
|
+
readonly email: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RfcEmailAction<string, undefined>]>, undefined>;
|
|
141
|
+
readonly userId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, undefined>]>;
|
|
142
|
+
}, undefined>;
|
|
143
|
+
responseSchema: v.StrictObjectSchema<{
|
|
144
|
+
readonly secret: v.NonOptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
145
|
+
readonly userId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, undefined>]>;
|
|
146
|
+
}, undefined>;
|
|
147
|
+
};
|
|
114
148
|
readonly commands: {
|
|
115
149
|
errorSchema: v.StrictObjectSchema<{
|
|
116
150
|
readonly code: v.PicklistSchema<readonly ["AUTHENTICATION_FAILED", "AUTHORIZATION_FAILED", "CONFLICT", "INVALID_REQUEST", "NOT_FOUND", "PROVIDER_REJECTED", "TRANSIENT_FAILURE", "INTERNAL_ERROR"], undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/appwrite/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAS5B,KAAK,uBAAuB,GAAG,eAAe,GAAG,UAAU,GAAG,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/appwrite/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAS5B,KAAK,uBAAuB,GAAG,eAAe,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAA;AA6MlF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AI,qBAAqB,CACvJ,SAAS,EACT,MAAM,CACP,SAAS;IAAE,cAAc,EAAE,MAAM,OAAO,SAAS,CAAC,CAAC,aAAa,CAAA;CAAE,GAC/D,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,GACtB,KAAK,CAAA"}
|
|
@@ -48,6 +48,21 @@ const connectionResultSchema = v.strictObject({
|
|
|
48
48
|
});
|
|
49
49
|
const completedSchema = v.strictObject({ state: v.literal('COMPLETED') });
|
|
50
50
|
const emptySchema = v.strictObject({});
|
|
51
|
+
const authUserIdSchema = appwriteRowIdSchema;
|
|
52
|
+
const authSendCodeRequestSchema = v.strictObject({
|
|
53
|
+
email: string.email(),
|
|
54
|
+
userId: authUserIdSchema,
|
|
55
|
+
});
|
|
56
|
+
const authSendCodeResponseSchema = v.strictObject({ userId: authUserIdSchema });
|
|
57
|
+
const authVerifyCodeRequestSchema = v.strictObject({
|
|
58
|
+
code: v.pipe(v.string(), v.regex(/^\d{6}$/)),
|
|
59
|
+
email: string.email(),
|
|
60
|
+
userId: authUserIdSchema,
|
|
61
|
+
});
|
|
62
|
+
const authVerifyCodeResponseSchema = v.strictObject({
|
|
63
|
+
secret: string.required(4096),
|
|
64
|
+
userId: authUserIdSchema,
|
|
65
|
+
});
|
|
51
66
|
const timestampSchema = v.pipe(v.string(), v.isoTimestamp(), v.check(timestamp => {
|
|
52
67
|
const milliseconds = Date.parse(timestamp);
|
|
53
68
|
return Number.isFinite(milliseconds) && new Date(milliseconds).toISOString() === timestamp;
|
|
@@ -94,6 +109,20 @@ const apiRoutes = {
|
|
|
94
109
|
failedAccountIds: v.array(id.accountId.required()),
|
|
95
110
|
}),
|
|
96
111
|
}),
|
|
112
|
+
authSendCode: createRoute({
|
|
113
|
+
context: 'public',
|
|
114
|
+
method: 'POST',
|
|
115
|
+
path: '/auth/send-code',
|
|
116
|
+
requestSchema: authSendCodeRequestSchema,
|
|
117
|
+
responseSchema: authSendCodeResponseSchema,
|
|
118
|
+
}),
|
|
119
|
+
authVerifyCode: createRoute({
|
|
120
|
+
context: 'public',
|
|
121
|
+
method: 'POST',
|
|
122
|
+
path: '/auth/verify-code',
|
|
123
|
+
requestSchema: authVerifyCodeRequestSchema,
|
|
124
|
+
responseSchema: authVerifyCodeResponseSchema,
|
|
125
|
+
}),
|
|
97
126
|
commands: createRoute({
|
|
98
127
|
context: 'authenticated',
|
|
99
128
|
method: 'POST',
|
|
@@ -114,6 +114,8 @@ describe('appwriteFunctions', () => {
|
|
|
114
114
|
it('publishes the complete Appwrite Function route manifest', () => {
|
|
115
115
|
expect([
|
|
116
116
|
{ functionId: appwriteFunctions.api.id, route: appwriteFunctions.api.routes.profileEnsure },
|
|
117
|
+
{ functionId: appwriteFunctions.api.id, route: appwriteFunctions.api.routes.authSendCode },
|
|
118
|
+
{ functionId: appwriteFunctions.api.id, route: appwriteFunctions.api.routes.authVerifyCode },
|
|
117
119
|
{ functionId: appwriteFunctions.api.id, route: appwriteFunctions.api.routes.commands },
|
|
118
120
|
{ functionId: appwriteFunctions.api.id, route: appwriteFunctions.api.routes.accountsConnect },
|
|
119
121
|
{ functionId: appwriteFunctions.api.id, route: appwriteFunctions.api.routes.accountsPoll },
|
|
@@ -131,6 +133,8 @@ describe('appwriteFunctions', () => {
|
|
|
131
133
|
path: route.path,
|
|
132
134
|
}))).toEqual([
|
|
133
135
|
{ context: 'authenticated', functionId: 'marco-api', method: 'POST', path: '/profile/ensure' },
|
|
136
|
+
{ context: 'public', functionId: 'marco-api', method: 'POST', path: '/auth/send-code' },
|
|
137
|
+
{ context: 'public', functionId: 'marco-api', method: 'POST', path: '/auth/verify-code' },
|
|
134
138
|
{ context: 'authenticated', functionId: 'marco-api', method: 'POST', path: '/commands' },
|
|
135
139
|
{ context: 'authenticated', functionId: 'marco-api', method: 'POST', path: '/accounts/connect' },
|
|
136
140
|
{ context: 'authenticated', functionId: 'marco-api', method: 'POST', path: '/accounts/poll' },
|
|
@@ -143,6 +147,44 @@ describe('appwriteFunctions', () => {
|
|
|
143
147
|
{ context: 'internal', functionId: 'marco-worker', method: 'POST', path: '/jobs/run' },
|
|
144
148
|
]);
|
|
145
149
|
});
|
|
150
|
+
const authRoutes = [
|
|
151
|
+
{
|
|
152
|
+
request: { email: 'test-user-email-1@example.com', userId: 'test-appwrite-user-id-1' },
|
|
153
|
+
response: { userId: 'test-appwrite-user-id-1' },
|
|
154
|
+
route: () => appwriteFunctions.api.routes.authSendCode,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
request: { code: '123456', email: 'test-user-email-1@example.com', userId: 'test-appwrite-user-id-1' },
|
|
158
|
+
response: { secret: 'test-appwrite-secret-1', userId: 'test-appwrite-user-id-1' },
|
|
159
|
+
route: () => appwriteFunctions.api.routes.authVerifyCode,
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
for (const { request, response, route } of authRoutes) {
|
|
163
|
+
it(`accepts the public ${route().path} contract`, () => {
|
|
164
|
+
expect(v.safeParse(route().requestSchema, request).success).toBe(true);
|
|
165
|
+
expect(v.safeParse(route().responseSchema, response).success).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
it(`rejects unknown fields in the public ${route().path} contract`, () => {
|
|
168
|
+
expect(v.safeParse(route().requestSchema, { ...request, unexpected: true }).success).toBe(false);
|
|
169
|
+
expect(v.safeParse(route().responseSchema, { ...response, unexpected: true }).success).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
for (const { description, request, route } of [
|
|
173
|
+
{
|
|
174
|
+
description: 'malformed email',
|
|
175
|
+
request: { email: 'not-an-email', userId: 'test-appwrite-user-id-1' },
|
|
176
|
+
route: () => appwriteFunctions.api.routes.authSendCode,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
description: 'malformed code',
|
|
180
|
+
request: { code: '12345', email: 'test-user-email-1@example.com', userId: 'test-appwrite-user-id-1' },
|
|
181
|
+
route: () => appwriteFunctions.api.routes.authVerifyCode,
|
|
182
|
+
},
|
|
183
|
+
]) {
|
|
184
|
+
it(`rejects a public auth request with a ${description}`, () => {
|
|
185
|
+
expect(v.safeParse(route().requestSchema, request).success).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
146
188
|
for (const { name, request, response, route } of routeFixtures) {
|
|
147
189
|
it(`accepts the ${name} request and response`, () => {
|
|
148
190
|
expect(v.safeParse(route().requestSchema, request).success).toBe(true);
|