@project-ajax/create 0.0.26 → 0.0.27
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/package.json
CHANGED
|
@@ -29,8 +29,8 @@ const myCustomAuth = worker.oauth("myCustomAuth", {
|
|
|
29
29
|
authorizationEndpoint: "https://provider.example.com/oauth/authorize",
|
|
30
30
|
tokenEndpoint: "https://provider.example.com/oauth/token",
|
|
31
31
|
scope: "read write",
|
|
32
|
-
clientId:
|
|
33
|
-
clientSecret:
|
|
32
|
+
clientId: "1234567890",
|
|
33
|
+
clientSecret: process.env.MY_CUSTOM_OAUTH_CLIENT_SECRET ?? "",
|
|
34
34
|
authorizationParams: {
|
|
35
35
|
access_type: "offline",
|
|
36
36
|
prompt: "consent",
|
|
@@ -73,12 +73,3 @@ worker.tool("customApiTool", {
|
|
|
73
73
|
return { success: true };
|
|
74
74
|
},
|
|
75
75
|
});
|
|
76
|
-
|
|
77
|
-
function requireEnv(key: string): string {
|
|
78
|
-
const value = process.env[key];
|
|
79
|
-
if (value) {
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
throw new Error(`Missing environment variable "${key}"`);
|
|
84
|
-
}
|
package/template/AGENTS.md
CHANGED
|
@@ -20,10 +20,18 @@ export default worker;
|
|
|
20
20
|
worker.sync("tasksSync", {
|
|
21
21
|
primaryKeyProperty: "ID",
|
|
22
22
|
schema: { defaultName: "Tasks", properties: { Name: Schema.title(), ID: Schema.richText() } },
|
|
23
|
-
execute: async () =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
execute: async (context?: { cursor?: string }) => {
|
|
24
|
+
const pageSize = 100;
|
|
25
|
+
const { items, nextCursor } = await fetchItems({ cursor: context?.cursor, limit: pageSize });
|
|
26
|
+
return {
|
|
27
|
+
objects: items.map((item) => ({
|
|
28
|
+
key: item.id,
|
|
29
|
+
properties: { Name: Builder.title(item.name), ID: Builder.richText(item.id) },
|
|
30
|
+
})),
|
|
31
|
+
done: !nextCursor,
|
|
32
|
+
nextContext: nextCursor ? { cursor: nextCursor } : undefined,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
27
35
|
});
|
|
28
36
|
|
|
29
37
|
worker.tool("sayHello", {
|
|
@@ -44,6 +52,37 @@ worker.oauth("googleAuth", { name: "my-google-auth", provider: "google" });
|
|
|
44
52
|
|
|
45
53
|
- For user-managed OAuth, supply `name`, `authorizationEndpoint`, `tokenEndpoint`, `clientId`, `clientSecret`, and `scope` (optional: `authorizationParams`, `callbackUrl`, `accessTokenExpireMs`).
|
|
46
54
|
|
|
55
|
+
### Sync Pagination
|
|
56
|
+
|
|
57
|
+
Implement pagination in syncs to avoid exceeding maximum output size limits. Returning too many objects in a single execution can cause the output JSON to exceed size limits and fail.
|
|
58
|
+
|
|
59
|
+
**How pagination works:**
|
|
60
|
+
1. Return a batch of objects with `done: false` and a `nextContext` value
|
|
61
|
+
2. The runtime calls `execute` again with that context
|
|
62
|
+
3. Continue until you return `done: true`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
worker.sync("paginatedSync", {
|
|
66
|
+
primaryKeyProperty: "ID",
|
|
67
|
+
schema: { defaultName: "Records", properties: { Name: Schema.title(), ID: Schema.richText() } },
|
|
68
|
+
execute: async (context?: { page: number }) => {
|
|
69
|
+
const page = context?.page ?? 1;
|
|
70
|
+
const pageSize = 100;
|
|
71
|
+
const { items, hasMore } = await fetchPage(page, pageSize);
|
|
72
|
+
return {
|
|
73
|
+
objects: items.map((item) => ({
|
|
74
|
+
key: item.id,
|
|
75
|
+
properties: { Name: Builder.title(item.name), ID: Builder.richText(item.id) },
|
|
76
|
+
})),
|
|
77
|
+
done: !hasMore,
|
|
78
|
+
nextContext: hasMore ? { page: page + 1 } : undefined,
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Context types:** The `nextContext` can be any serializable value—a cursor string, page number, timestamp, or complex object. Type your execute function's context parameter to match.
|
|
85
|
+
|
|
47
86
|
## Build, Test, and Development Commands
|
|
48
87
|
- Node >= 22 and npm >= 10.9.2 (see `package.json` engines).
|
|
49
88
|
- `npm run dev`: run `src/index.ts` with live reload.
|