@project-ajax/create 0.0.31 → 0.0.32
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 +1 -3
- package/package.json +1 -1
- package/template/AGENTS.md +2 -1
- package/template/CLAUDE.md +2 -1
- package/template/README.md +35 -2
package/README.md
CHANGED
|
@@ -25,6 +25,4 @@ npm init @project-ajax -- --directory my-worker --project my-worker
|
|
|
25
25
|
|
|
26
26
|
### Scheduling
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
This can be useful for minding rate limits.
|
|
28
|
+
Sync workers default to running every 30 minutes. To change the cadence, set `schedule` in `src/index.ts` to an interval like `15m`, `1h`, or `1d` (min `1m`, max `7d`), or `continuous` to run as fast as possible.
|
package/package.json
CHANGED
package/template/AGENTS.md
CHANGED
|
@@ -49,12 +49,13 @@ worker.oauth("googleAuth", { name: "my-google-auth", provider: "google" });
|
|
|
49
49
|
### Sync
|
|
50
50
|
#### Strategy and Pagination
|
|
51
51
|
|
|
52
|
-
Syncs run in a "sync cycle": a back-to-back chain of `execute` calls that starts at a scheduled trigger and ends when an execution returns `hasMore: false`.
|
|
52
|
+
Syncs run in a "sync cycle": a back-to-back chain of `execute` calls that starts at a scheduled trigger and ends when an execution returns `hasMore: false`. By default, syncs run every 30 minutes. Set `schedule` to an interval like `"15m"`, `"1h"`, `"1d"` (min `"1m"`, max `"7d"`), or `"continuous"` to run as fast as possible.
|
|
53
53
|
|
|
54
54
|
- Always use pagination, when available. Returning too many changes in one execution will fail. Start with batch sizes of ~100 changes.
|
|
55
55
|
- `mode=replace` is simpler, and fine for smaller syncs (<10k)
|
|
56
56
|
- Use `mode=incremental` when the sync could return a lot of data (>10k), eg for SaaS tools like Salesforce or Stripe
|
|
57
57
|
- When using `mode=incremental`, emit delete markers as needed if easy to do (below)
|
|
58
|
+
- Use `Pacer.wait` to respect upstream rate limits during `execute` calls; pick a stable key per API or endpoint.
|
|
58
59
|
|
|
59
60
|
**Sync strategy (`mode`):**
|
|
60
61
|
- `replace`: each sync cycle must return the full dataset. After the final `hasMore: false`, any records not seen during that cycle are deleted.
|
package/template/CLAUDE.md
CHANGED
|
@@ -49,12 +49,13 @@ worker.oauth("googleAuth", { name: "my-google-auth", provider: "google" });
|
|
|
49
49
|
### Sync
|
|
50
50
|
#### Strategy and Pagination
|
|
51
51
|
|
|
52
|
-
Syncs run in a "sync cycle": a back-to-back chain of `execute` calls that starts at a scheduled trigger and ends when an execution returns `hasMore: false`.
|
|
52
|
+
Syncs run in a "sync cycle": a back-to-back chain of `execute` calls that starts at a scheduled trigger and ends when an execution returns `hasMore: false`. By default, syncs run every 30 minutes. Set `schedule` to an interval like `"15m"`, `"1h"`, `"1d"` (min `"1m"`, max `"7d"`), or `"continuous"` to run as fast as possible.
|
|
53
53
|
|
|
54
54
|
- Always use pagination, when available. Returning too many changes in one execution will fail. Start with batch sizes of ~100 changes.
|
|
55
55
|
- `mode=replace` is simpler, and fine for smaller syncs (<10k)
|
|
56
56
|
- Use `mode=incremental` when the sync could return a lot of data (>10k), eg for SaaS tools like Salesforce or Stripe
|
|
57
57
|
- When using `mode=incremental`, emit delete markers as needed if easy to do (below)
|
|
58
|
+
- Use `Pacer.wait` to respect upstream rate limits during `execute` calls; pick a stable key per API or endpoint.
|
|
58
59
|
|
|
59
60
|
**Sync strategy (`mode`):**
|
|
60
61
|
- `replace`: each sync cycle must return the full dataset. After the final `hasMore: false`, any records not seen during that cycle are deleted.
|
package/template/README.md
CHANGED
|
@@ -13,7 +13,7 @@ single `Worker` instance.
|
|
|
13
13
|
## Quickstart
|
|
14
14
|
|
|
15
15
|
```shell
|
|
16
|
-
npm init @project-ajax
|
|
16
|
+
npm init @project-ajax@latest
|
|
17
17
|
# choose a folder, then:
|
|
18
18
|
cd my-worker
|
|
19
19
|
npm install
|
|
@@ -37,7 +37,7 @@ npx workers exec tasksSync
|
|
|
37
37
|
|
|
38
38
|
- Worker: The Node/TypeScript program you deploy, defined in `src/index.ts`.
|
|
39
39
|
- Capability: A named sync, tool, automation, or OAuth definition registered on a worker.
|
|
40
|
-
- Secret: A key/value stored with `npx workers secrets`, exposed as environment variables (for example, `process.env.SECRET_NAME`).
|
|
40
|
+
- Secret: A key/value stored with `npx workers secrets`, exposed as environment variables (for example, `process.env.SECRET_NAME`). Use `KEY=VALUE` pairs when setting secrets.
|
|
41
41
|
|
|
42
42
|
## Build a Worker
|
|
43
43
|
|
|
@@ -171,6 +171,33 @@ changes: [
|
|
|
171
171
|
]
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
+
#### Respect rate limits
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
If the source API has a rate limit, call `Pacer.wait` inside `execute` to pace requests (for example, 10 requests per minute):
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
import { Pacer } from "@project-ajax/sdk/pacer";
|
|
181
|
+
|
|
182
|
+
worker.sync("tasksSync", {
|
|
183
|
+
primaryKeyProperty: "ID",
|
|
184
|
+
schema: { defaultName: "Tasks", properties: { Name: Schema.title(), ID: Schema.richText() } },
|
|
185
|
+
execute: async () => {
|
|
186
|
+
const oneMinute = 60 * 1000;
|
|
187
|
+
await Pacer.wait("tasks-api", { requests: 10, intervalMs: oneMinute });
|
|
188
|
+
const items = await fetchTasks();
|
|
189
|
+
return {
|
|
190
|
+
changes: items.map((item) => ({
|
|
191
|
+
type: "upsert",
|
|
192
|
+
key: item.id,
|
|
193
|
+
properties: { Name: Builder.title(item.name), ID: Builder.richText(item.id) },
|
|
194
|
+
})),
|
|
195
|
+
hasMore: false,
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
174
201
|
### Tool
|
|
175
202
|
|
|
176
203
|
Tools are callable by Notion custom agents.
|
|
@@ -299,6 +326,12 @@ Store secrets for runtime access:
|
|
|
299
326
|
npx workers secrets set API_KEY=my-secret
|
|
300
327
|
```
|
|
301
328
|
|
|
329
|
+
You can pass multiple secrets and quote values that contain spaces or `=`:
|
|
330
|
+
|
|
331
|
+
```shell
|
|
332
|
+
npx workers secrets set FOO=bar BAZ="qux" ASDF="x=y" GREETING="hello world"
|
|
333
|
+
```
|
|
334
|
+
|
|
302
335
|
### `npx workers secrets list`
|
|
303
336
|
List secret keys:
|
|
304
337
|
|