@rippling/rippling-sdk 0.2.0-alpha.51 → 0.2.0-alpha.52
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/examples/functions/durable.ts +96 -0
- package/functions.d.mts +35 -0
- package/functions.d.mts.map +1 -1
- package/functions.d.ts +35 -0
- package/functions.d.ts.map +1 -1
- package/functions.js.map +1 -1
- package/functions.mjs.map +1 -1
- package/package.json +1 -1
- package/src/functions.md +238 -0
- package/src/functions.ts +42 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import RipplingSDK, { DurableFunctionContext, FunctionEvent, FunctionResponse } from '@rippling/rippling-sdk';
|
|
2
|
+
|
|
3
|
+
type OfferLetterCompletedEvent = {
|
|
4
|
+
status: 'signed' | 'declined';
|
|
5
|
+
signedDocumentId?: string;
|
|
6
|
+
declinedReason?: string;
|
|
7
|
+
completedAt?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export async function onRipplingEvent(
|
|
11
|
+
event: FunctionEvent,
|
|
12
|
+
context: DurableFunctionContext,
|
|
13
|
+
): Promise<FunctionResponse> {
|
|
14
|
+
const client = new RipplingSDK({
|
|
15
|
+
bearerToken: context.env.rippling_user_bearer_token,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const workflowDefinitionId = event['workflow_definition_id'] as string | undefined;
|
|
19
|
+
const employeeId = event['employee_id'] as string | undefined;
|
|
20
|
+
const offerLetterDocumentId = event['offer_letter_document_id'] as string | undefined;
|
|
21
|
+
const startDate = event['start_date'] as string | undefined;
|
|
22
|
+
const signingBonusAmount = Number(event['signing_bonus_amount'] ?? 0);
|
|
23
|
+
|
|
24
|
+
if (!workflowDefinitionId || !employeeId || !offerLetterDocumentId || !startDate) {
|
|
25
|
+
context.fail('Missing required onboarding inputs.', {
|
|
26
|
+
code: 'missing_onboarding_inputs',
|
|
27
|
+
details: {
|
|
28
|
+
hasWorkflowDefinitionId: Boolean(workflowDefinitionId),
|
|
29
|
+
hasEmployeeId: Boolean(employeeId),
|
|
30
|
+
hasOfferLetterDocumentId: Boolean(offerLetterDocumentId),
|
|
31
|
+
hasStartDate: Boolean(startDate),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await context.step('send offer letter document', async () => {
|
|
37
|
+
await client.workflowActionExecutions.create({
|
|
38
|
+
action_type: 'send_document',
|
|
39
|
+
payload: {
|
|
40
|
+
document: offerLetterDocumentId,
|
|
41
|
+
recipients: [employeeId],
|
|
42
|
+
},
|
|
43
|
+
workflow_definition_id: workflowDefinitionId,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const offerCompletion = await context.waitForEvent<OfferLetterCompletedEvent>(
|
|
48
|
+
'wait for signed offer letter',
|
|
49
|
+
{
|
|
50
|
+
type: 'offer_letter_completed',
|
|
51
|
+
timeout: '7 days',
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (offerCompletion.isTimeout()) {
|
|
56
|
+
context.fail('Offer letter was not completed before the deadline.', {
|
|
57
|
+
code: 'offer_letter_timeout',
|
|
58
|
+
details: offerCompletion,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (offerCompletion.payload.status !== 'signed') {
|
|
63
|
+
context.fail('Offer letter was declined.', {
|
|
64
|
+
code: 'offer_letter_declined',
|
|
65
|
+
details: offerCompletion.payload,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
await context.sleepUntil('wait until employee start date', startDate);
|
|
70
|
+
|
|
71
|
+
if (signingBonusAmount > 0) {
|
|
72
|
+
await context.step('schedule signing bonus payment', async () => {
|
|
73
|
+
await client.workflowActionExecutions.create({
|
|
74
|
+
action_type: 'make_payment',
|
|
75
|
+
payload: {
|
|
76
|
+
apply_cap: false,
|
|
77
|
+
description: `Signing bonus for durable run ${context.function.run_id}`,
|
|
78
|
+
payment_amount: signingBonusAmount,
|
|
79
|
+
recipients: [employeeId],
|
|
80
|
+
},
|
|
81
|
+
workflow_definition_id: workflowDefinitionId,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return new FunctionResponse({
|
|
87
|
+
statusCode: 200,
|
|
88
|
+
body: {
|
|
89
|
+
employeeId,
|
|
90
|
+
offerStatus: offerCompletion.payload.status,
|
|
91
|
+
signedDocumentId: offerCompletion.payload.signedDocumentId,
|
|
92
|
+
completedAt: offerCompletion.payload.completedAt,
|
|
93
|
+
signingBonusScheduled: signingBonusAmount > 0,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
package/functions.d.mts
CHANGED
|
@@ -12,6 +12,33 @@ export declare class FunctionResponse {
|
|
|
12
12
|
constructor({ body, statusCode, headers, message }?: FunctionResponseOptions);
|
|
13
13
|
}
|
|
14
14
|
export type FunctionEvent = Record<string, any>;
|
|
15
|
+
export type DurableDuration = number | string;
|
|
16
|
+
export type DurableTimestamp = number | Date | string;
|
|
17
|
+
export interface DurableWaitForEventOptions {
|
|
18
|
+
type: string;
|
|
19
|
+
timeout?: DurableDuration;
|
|
20
|
+
}
|
|
21
|
+
export interface DurableFailureOptions {
|
|
22
|
+
code?: string;
|
|
23
|
+
details?: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface DurableWaitForEventEventResult<T = unknown> {
|
|
26
|
+
kind: 'event';
|
|
27
|
+
waitName: string;
|
|
28
|
+
eventType: string;
|
|
29
|
+
payload: T;
|
|
30
|
+
}
|
|
31
|
+
export interface DurableWaitForEventTimeoutResult {
|
|
32
|
+
kind: 'timeout';
|
|
33
|
+
waitName: string;
|
|
34
|
+
eventType: string;
|
|
35
|
+
}
|
|
36
|
+
export interface DurableWaitForEventResultHelpers<T = unknown> {
|
|
37
|
+
isEvent(): this is DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>;
|
|
38
|
+
isTimeout(): this is DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>;
|
|
39
|
+
throwTimeout(this: DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>): never;
|
|
40
|
+
}
|
|
41
|
+
export type DurableWaitForEventResult<T = unknown> = (DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>) | (DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>);
|
|
15
42
|
export interface FunctionContext {
|
|
16
43
|
env: {
|
|
17
44
|
rippling_user_bearer_token: string | undefined;
|
|
@@ -21,9 +48,17 @@ export interface FunctionContext {
|
|
|
21
48
|
function_id: string;
|
|
22
49
|
function_version_id: string;
|
|
23
50
|
run_id: string;
|
|
51
|
+
role_id?: string;
|
|
24
52
|
};
|
|
25
53
|
settings: Record<string, string | boolean | number>;
|
|
26
54
|
}
|
|
55
|
+
export interface DurableFunctionContext extends FunctionContext {
|
|
56
|
+
step<T>(name: string, fn: () => Promise<T> | T, opts?: unknown): Promise<T>;
|
|
57
|
+
sleep(name: string, duration: DurableDuration): Promise<void>;
|
|
58
|
+
sleepUntil(name: string, timestamp: DurableTimestamp): Promise<void>;
|
|
59
|
+
waitForEvent<T = unknown>(name: string, opts: DurableWaitForEventOptions): Promise<DurableWaitForEventResult<T>>;
|
|
60
|
+
fail(message: string, opts?: DurableFailureOptions): never;
|
|
61
|
+
}
|
|
27
62
|
export declare class DataBridgeRecord {
|
|
28
63
|
id: string;
|
|
29
64
|
version: string;
|
package/functions.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.mts","sourceRoot":"","sources":["src/functions.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;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ClB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,iBAAiB,EAAE,MAAM,CAAC;gBACd,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;CAUvD"}
|
package/functions.d.ts
CHANGED
|
@@ -12,6 +12,33 @@ export declare class FunctionResponse {
|
|
|
12
12
|
constructor({ body, statusCode, headers, message }?: FunctionResponseOptions);
|
|
13
13
|
}
|
|
14
14
|
export type FunctionEvent = Record<string, any>;
|
|
15
|
+
export type DurableDuration = number | string;
|
|
16
|
+
export type DurableTimestamp = number | Date | string;
|
|
17
|
+
export interface DurableWaitForEventOptions {
|
|
18
|
+
type: string;
|
|
19
|
+
timeout?: DurableDuration;
|
|
20
|
+
}
|
|
21
|
+
export interface DurableFailureOptions {
|
|
22
|
+
code?: string;
|
|
23
|
+
details?: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface DurableWaitForEventEventResult<T = unknown> {
|
|
26
|
+
kind: 'event';
|
|
27
|
+
waitName: string;
|
|
28
|
+
eventType: string;
|
|
29
|
+
payload: T;
|
|
30
|
+
}
|
|
31
|
+
export interface DurableWaitForEventTimeoutResult {
|
|
32
|
+
kind: 'timeout';
|
|
33
|
+
waitName: string;
|
|
34
|
+
eventType: string;
|
|
35
|
+
}
|
|
36
|
+
export interface DurableWaitForEventResultHelpers<T = unknown> {
|
|
37
|
+
isEvent(): this is DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>;
|
|
38
|
+
isTimeout(): this is DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>;
|
|
39
|
+
throwTimeout(this: DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>): never;
|
|
40
|
+
}
|
|
41
|
+
export type DurableWaitForEventResult<T = unknown> = (DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>) | (DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>);
|
|
15
42
|
export interface FunctionContext {
|
|
16
43
|
env: {
|
|
17
44
|
rippling_user_bearer_token: string | undefined;
|
|
@@ -21,9 +48,17 @@ export interface FunctionContext {
|
|
|
21
48
|
function_id: string;
|
|
22
49
|
function_version_id: string;
|
|
23
50
|
run_id: string;
|
|
51
|
+
role_id?: string;
|
|
24
52
|
};
|
|
25
53
|
settings: Record<string, string | boolean | number>;
|
|
26
54
|
}
|
|
55
|
+
export interface DurableFunctionContext extends FunctionContext {
|
|
56
|
+
step<T>(name: string, fn: () => Promise<T> | T, opts?: unknown): Promise<T>;
|
|
57
|
+
sleep(name: string, duration: DurableDuration): Promise<void>;
|
|
58
|
+
sleepUntil(name: string, timestamp: DurableTimestamp): Promise<void>;
|
|
59
|
+
waitForEvent<T = unknown>(name: string, opts: DurableWaitForEventOptions): Promise<DurableWaitForEventResult<T>>;
|
|
60
|
+
fail(message: string, opts?: DurableFailureOptions): never;
|
|
61
|
+
}
|
|
27
62
|
export declare class DataBridgeRecord {
|
|
28
63
|
id: string;
|
|
29
64
|
version: string;
|
package/functions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["src/functions.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAgB;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;gBAEJ,EAAE,IAAS,EAAE,UAAg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;gBAEN,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG;CAKlE;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED,qBAAa,kBAAkB;IAC7B,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,GAAG,EAAE,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAEf,EACV,OAAY,EACZ,UAAe,EACf,UAAe,EACf,KAAU,EACV,IAAY,EACZ,KAAU,GACX,GAAE,yBAA8B;CAQlC;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,GAAG,CAAC;QACX,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,OAAO,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,iBAAiB,EAAE,MAAM,CAAC;gBACd,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;CAUvD"}
|
package/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["src/functions.ts"],"names":[],"mappings":";;;AAUA,MAAa,gBAAgB;IAM3B,YAAY,EAAE,IAAI,GAAG,EAAE,EA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AAY,EACV,OAAO,GAAG,EAAE,EACZ,UAAU,GAAG,EAAE,EACf,UAAU,GAAG,EAAE,EACf,KAAK,GAAG,EAAE,EACV,IAAI,GAAG,KAAK,EACZ,KAAK,GAAG,EAAE,MACmB,EAAE;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAYD,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAEjD,YAAY,OAAe,EAAE,iBAAyB;QACpD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC;YACjC,OAAO;YACP,iBAAiB;SAClB,CAAC,CAAC;QAEH,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;CACF"}
|
package/package.json
CHANGED
package/src/functions.md
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Durable Function APIs
|
|
2
|
+
|
|
3
|
+
Durable functions are Rippling functions that receive a `DurableFunctionContext`. They let you split work into named, durable steps; pause execution; wait for external events; and fail runs with structured metadata.
|
|
4
|
+
|
|
5
|
+
## Function signature
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import RipplingSDK, { DurableFunctionContext, FunctionEvent, FunctionResponse } from '@rippling/rippling-sdk';
|
|
9
|
+
|
|
10
|
+
export async function onRipplingEvent(
|
|
11
|
+
event: FunctionEvent,
|
|
12
|
+
context: DurableFunctionContext,
|
|
13
|
+
): Promise<FunctionResponse> {
|
|
14
|
+
return new FunctionResponse({ statusCode: 200 });
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Context APIs
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// context.step()
|
|
22
|
+
const documentResult = await context.step('send offer letter', async () => {
|
|
23
|
+
return await client.workflowActionExecutions.create({
|
|
24
|
+
action_type: 'send_document',
|
|
25
|
+
payload: {
|
|
26
|
+
document: offerLetterDocumentId,
|
|
27
|
+
recipients: [employeeId],
|
|
28
|
+
},
|
|
29
|
+
workflow_definition_id: event['workflow_definition_id'],
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// context.sleep()
|
|
34
|
+
await context.sleep('wait before retry', '1 hour');
|
|
35
|
+
await context.sleep('wait 5 seconds', 5000); // milliseconds
|
|
36
|
+
|
|
37
|
+
// context.sleepUntil()
|
|
38
|
+
await context.sleepUntil('wait until launch', new Date('2025-01-01T00:00:00Z'));
|
|
39
|
+
await context.sleepUntil('wait until timestamp', Date.parse('2025-01-01T00:00:00Z'));
|
|
40
|
+
|
|
41
|
+
// context.waitForEvent()
|
|
42
|
+
const approval = await context.waitForEvent<{ approved: boolean }>('wait for approval', {
|
|
43
|
+
type: 'approval',
|
|
44
|
+
timeout: '24 hours',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (approval.isTimeout()) {
|
|
48
|
+
context.fail('Approval timed out', {
|
|
49
|
+
code: 'approval_timeout',
|
|
50
|
+
details: approval,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!approval.payload.approved) {
|
|
55
|
+
context.fail('Approval was rejected', {
|
|
56
|
+
code: 'approval_rejected',
|
|
57
|
+
details: approval.payload,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## `DurableFunctionContext`
|
|
63
|
+
|
|
64
|
+
`DurableFunctionContext` extends the standard `FunctionContext` with durable execution methods.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
interface DurableFunctionContext extends FunctionContext {
|
|
68
|
+
step<T>(name: string, fn: () => Promise<T> | T, opts?: unknown): Promise<T>;
|
|
69
|
+
sleep(name: string, duration: DurableDuration): Promise<void>;
|
|
70
|
+
sleepUntil(name: string, timestamp: DurableTimestamp): Promise<void>;
|
|
71
|
+
waitForEvent<T = unknown>(
|
|
72
|
+
name: string,
|
|
73
|
+
opts: DurableWaitForEventOptions,
|
|
74
|
+
): Promise<DurableWaitForEventResult<T>>;
|
|
75
|
+
fail(message: string, opts?: DurableFailureOptions): never;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface DurableWaitForEventEventResult<T = unknown> {
|
|
79
|
+
kind: 'event';
|
|
80
|
+
waitName: string;
|
|
81
|
+
eventType: string;
|
|
82
|
+
payload: T;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface DurableWaitForEventTimeoutResult {
|
|
86
|
+
kind: 'timeout';
|
|
87
|
+
waitName: string;
|
|
88
|
+
eventType: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface DurableWaitForEventResultHelpers<T = unknown> {
|
|
92
|
+
isEvent(): this is DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>;
|
|
93
|
+
isTimeout(): this is DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>;
|
|
94
|
+
throwTimeout(this: DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>): never;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type DurableWaitForEventResult<T = unknown> =
|
|
98
|
+
| (DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>)
|
|
99
|
+
| (DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The inherited `FunctionContext` includes environment, function metadata, and settings.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
interface FunctionContext {
|
|
106
|
+
env: {
|
|
107
|
+
rippling_user_bearer_token: string | undefined;
|
|
108
|
+
};
|
|
109
|
+
function: {
|
|
110
|
+
company_id: string;
|
|
111
|
+
function_id: string;
|
|
112
|
+
function_version_id: string;
|
|
113
|
+
run_id: string;
|
|
114
|
+
role_id?: string;
|
|
115
|
+
};
|
|
116
|
+
settings: Record<string, string | boolean | number>;
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Step API
|
|
121
|
+
|
|
122
|
+
Use `context.step()` for work that should be durably tracked. Each step should have a stable, descriptive name.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const employeeId = event['employee_id'] as string;
|
|
126
|
+
const offerLetterDocumentId = event['offer_letter_document_id'] as string;
|
|
127
|
+
const signingBonusAmount = Number(event['signing_bonus_amount'] ?? 0);
|
|
128
|
+
|
|
129
|
+
await context.step('send offer letter document', async () => {
|
|
130
|
+
await client.workflowActionExecutions.create({
|
|
131
|
+
action_type: 'send_document',
|
|
132
|
+
payload: {
|
|
133
|
+
document: offerLetterDocumentId,
|
|
134
|
+
recipients: [employeeId],
|
|
135
|
+
},
|
|
136
|
+
workflow_definition_id: event['workflow_definition_id'],
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (signingBonusAmount > 0) {
|
|
141
|
+
await context.step('schedule signing bonus payment', async () => {
|
|
142
|
+
await client.workflowActionExecutions.create({
|
|
143
|
+
action_type: 'make_payment',
|
|
144
|
+
payload: {
|
|
145
|
+
apply_cap: false,
|
|
146
|
+
description: `Signing bonus for run ${context.function.run_id}`,
|
|
147
|
+
payment_amount: signingBonusAmount,
|
|
148
|
+
recipients: [employeeId],
|
|
149
|
+
},
|
|
150
|
+
workflow_definition_id: event['workflow_definition_id'],
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Idempotency
|
|
157
|
+
|
|
158
|
+
Code inside `context.step()` may be replayed or retried by the durable runtime. Design side-effecting steps to be idempotent when possible.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
await context.step('make relocation payment', async () => {
|
|
162
|
+
await client.workflowActionExecutions.create({
|
|
163
|
+
action_type: 'make_payment',
|
|
164
|
+
payload: {
|
|
165
|
+
apply_cap: true,
|
|
166
|
+
description: `Relocation payment for durable run ${context.function.run_id}`,
|
|
167
|
+
payment_amount: 250000,
|
|
168
|
+
recipients: [employeeId],
|
|
169
|
+
},
|
|
170
|
+
workflow_definition_id: event['workflow_definition_id'],
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Sleep and scheduling
|
|
176
|
+
|
|
177
|
+
Use `context.sleep()` for relative delays and `context.sleepUntil()` for absolute wake-up times.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
// Relative delays
|
|
181
|
+
await context.sleep('wait 15 minutes', '15 minutes');
|
|
182
|
+
await context.sleep('wait 1 day', '1 day');
|
|
183
|
+
await context.sleep('wait 5 seconds', 5000); // milliseconds
|
|
184
|
+
|
|
185
|
+
// Absolute times
|
|
186
|
+
await context.sleepUntil('wait until deadline', new Date('2025-12-31T23:59:59Z'));
|
|
187
|
+
await context.sleepUntil('wait until epoch timestamp', 1767225599000);
|
|
188
|
+
await context.sleepUntil('wait until ISO timestamp', '2025-12-31T23:59:59Z');
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`DurableDuration` accepts a `number` or `string`. `DurableTimestamp` accepts a `number`, `Date`, or `string`.
|
|
192
|
+
|
|
193
|
+
## Waiting for external events
|
|
194
|
+
|
|
195
|
+
Use `context.waitForEvent()` when a function should pause until another system sends an event back to the run. The method returns a structured result with `kind: 'event'` when the event arrives, or `kind: 'timeout'` when the timeout expires.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
type ApprovalEvent = {
|
|
199
|
+
approved: boolean;
|
|
200
|
+
reviewerId: string;
|
|
201
|
+
reason?: string;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const approval = await context.waitForEvent<ApprovalEvent>('wait for manager approval', {
|
|
205
|
+
type: 'manager_approval',
|
|
206
|
+
timeout: '3 days',
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
if (approval.isTimeout()) {
|
|
210
|
+
context.fail('Manager approval timed out', {
|
|
211
|
+
code: 'approval_timeout',
|
|
212
|
+
details: approval,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!approval.payload.approved) {
|
|
217
|
+
context.fail('Manager rejected the request', {
|
|
218
|
+
code: 'approval_rejected',
|
|
219
|
+
details: approval.payload,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Failing a durable function
|
|
225
|
+
|
|
226
|
+
Use `context.fail()` to stop the run with a human-readable message and optional structured failure metadata.
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
context.fail('The requested employee could not be found', {
|
|
230
|
+
code: 'employee_not_found',
|
|
231
|
+
details: {
|
|
232
|
+
employeeId,
|
|
233
|
+
runId: context.function.run_id,
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Because `fail()` returns `never`, TypeScript understands that code after it is unreachable.
|
package/src/functions.ts
CHANGED
|
@@ -23,6 +23,36 @@ export class FunctionResponse {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export type FunctionEvent = Record<string, any>;
|
|
26
|
+
export type DurableDuration = number | string;
|
|
27
|
+
export type DurableTimestamp = number | Date | string;
|
|
28
|
+
export interface DurableWaitForEventOptions {
|
|
29
|
+
type: string;
|
|
30
|
+
timeout?: DurableDuration;
|
|
31
|
+
}
|
|
32
|
+
export interface DurableFailureOptions {
|
|
33
|
+
code?: string;
|
|
34
|
+
details?: unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface DurableWaitForEventEventResult<T = unknown> {
|
|
37
|
+
kind: 'event';
|
|
38
|
+
waitName: string;
|
|
39
|
+
eventType: string;
|
|
40
|
+
payload: T;
|
|
41
|
+
}
|
|
42
|
+
export interface DurableWaitForEventTimeoutResult {
|
|
43
|
+
kind: 'timeout';
|
|
44
|
+
waitName: string;
|
|
45
|
+
eventType: string;
|
|
46
|
+
}
|
|
47
|
+
export interface DurableWaitForEventResultHelpers<T = unknown> {
|
|
48
|
+
isEvent(): this is DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>;
|
|
49
|
+
isTimeout(): this is DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>;
|
|
50
|
+
throwTimeout(this: DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>): never;
|
|
51
|
+
}
|
|
52
|
+
export type DurableWaitForEventResult<T = unknown> =
|
|
53
|
+
| (DurableWaitForEventEventResult<T> & DurableWaitForEventResultHelpers<T>)
|
|
54
|
+
| (DurableWaitForEventTimeoutResult & DurableWaitForEventResultHelpers<T>);
|
|
55
|
+
|
|
26
56
|
export interface FunctionContext {
|
|
27
57
|
env: {
|
|
28
58
|
// Set to the Rippling user's bearer token when the function is triggered by a user.
|
|
@@ -35,10 +65,22 @@ export interface FunctionContext {
|
|
|
35
65
|
function_id: string;
|
|
36
66
|
function_version_id: string;
|
|
37
67
|
run_id: string;
|
|
68
|
+
role_id?: string;
|
|
38
69
|
};
|
|
39
70
|
settings: Record<string, string | boolean | number>;
|
|
40
71
|
}
|
|
41
72
|
|
|
73
|
+
export interface DurableFunctionContext extends FunctionContext {
|
|
74
|
+
step<T>(name: string, fn: () => Promise<T> | T, opts?: unknown): Promise<T>;
|
|
75
|
+
sleep(name: string, duration: DurableDuration): Promise<void>;
|
|
76
|
+
sleepUntil(name: string, timestamp: DurableTimestamp): Promise<void>;
|
|
77
|
+
waitForEvent<T = unknown>(
|
|
78
|
+
name: string,
|
|
79
|
+
opts: DurableWaitForEventOptions,
|
|
80
|
+
): Promise<DurableWaitForEventResult<T>>;
|
|
81
|
+
fail(message: string, opts?: DurableFailureOptions): never;
|
|
82
|
+
}
|
|
83
|
+
|
|
42
84
|
export class DataBridgeRecord {
|
|
43
85
|
id: string;
|
|
44
86
|
version: string;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.2.0-alpha.
|
|
1
|
+
export const VERSION = '0.2.0-alpha.52'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.2.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.2.0-alpha.52";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.2.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.2.0-alpha.52";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
|
-
exports.VERSION = '0.2.0-alpha.
|
|
4
|
+
exports.VERSION = '0.2.0-alpha.52'; // x-release-please-version
|
|
5
5
|
//# sourceMappingURL=version.js.map
|
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.2.0-alpha.
|
|
1
|
+
export const VERSION = '0.2.0-alpha.52'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|