@sess.si/sdk 0.1.0-rc.8 → 0.1.0
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 +66 -9
- package/NOTICE +1 -1
- package/README.md +92 -16
- package/dist/ask.d.ts +0 -1
- package/dist/ask.js +0 -1
- package/dist/cli/main.d.ts +0 -1
- package/dist/cli/main.js +0 -1
- package/dist/cli/verify.d.ts +0 -1
- package/dist/cli/verify.js +0 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.js +0 -1
- package/dist/commerce/builders.d.ts +99 -0
- package/dist/commerce/builders.js +208 -0
- package/dist/commerce/currency.d.ts +4 -0
- package/dist/commerce/currency.js +25 -0
- package/dist/commerce/items.d.ts +119 -0
- package/dist/commerce/items.js +280 -0
- package/dist/commerce/lint.d.ts +16 -0
- package/dist/commerce/lint.js +56 -0
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +15 -25
- package/dist/generated/openapi.d.ts +12 -13
- package/dist/generated/openapi.js +0 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3 -1
- package/dist/internal/decode.d.ts +0 -1
- package/dist/internal/decode.js +9 -2
- package/dist/internal/json.d.ts +0 -1
- package/dist/internal/json.js +0 -1
- package/dist/internal/time.d.ts +0 -1
- package/dist/internal/time.js +0 -1
- package/dist/internal/version.d.ts +2 -0
- package/dist/internal/version.js +2 -0
- package/dist/polling.d.ts +0 -1
- package/dist/polling.js +0 -1
- package/dist/qr/encoder.d.ts +0 -1
- package/dist/qr/encoder.js +0 -1
- package/dist/qr/index.d.ts +0 -1
- package/dist/qr/index.js +0 -1
- package/dist/receipts/bundle.d.ts +0 -1
- package/dist/receipts/bundle.js +0 -1
- package/dist/receipts/index.d.ts +0 -1
- package/dist/receipts/index.js +0 -1
- package/dist/receipts/json.d.ts +0 -1
- package/dist/receipts/json.js +0 -1
- package/dist/receipts/key-cache.d.ts +0 -1
- package/dist/receipts/key-cache.js +0 -1
- package/dist/receipts/renderers.d.ts +0 -1
- package/dist/receipts/renderers.js +1 -2
- package/dist/receipts/resource.d.ts +0 -1
- package/dist/receipts/resource.js +0 -1
- package/dist/receipts/verify.d.ts +0 -1
- package/dist/receipts/verify.js +0 -1
- package/dist/sessions.d.ts +0 -1
- package/dist/sessions.js +0 -1
- package/dist/transport.d.ts +0 -1
- package/dist/transport.js +35 -5
- package/dist/types.d.ts +56 -2
- package/dist/types.js +0 -1
- package/dist/webhook-resource.d.ts +0 -1
- package/dist/webhook-resource.js +0 -1
- package/dist/webhooks/index.d.ts +0 -1
- package/dist/webhooks/index.js +0 -1
- package/package.json +8 -3
- package/dist/ask.d.ts.map +0 -1
- package/dist/ask.js.map +0 -1
- package/dist/cli/main.d.ts.map +0 -1
- package/dist/cli/main.js.map +0 -1
- package/dist/cli/verify.d.ts.map +0 -1
- package/dist/cli/verify.js.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/generated/openapi.d.ts.map +0 -1
- package/dist/generated/openapi.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal/decode.d.ts.map +0 -1
- package/dist/internal/decode.js.map +0 -1
- package/dist/internal/json.d.ts.map +0 -1
- package/dist/internal/json.js.map +0 -1
- package/dist/internal/time.d.ts.map +0 -1
- package/dist/internal/time.js.map +0 -1
- package/dist/polling.d.ts.map +0 -1
- package/dist/polling.js.map +0 -1
- package/dist/qr/encoder.d.ts.map +0 -1
- package/dist/qr/encoder.js.map +0 -1
- package/dist/qr/index.d.ts.map +0 -1
- package/dist/qr/index.js.map +0 -1
- package/dist/receipts/bundle.d.ts.map +0 -1
- package/dist/receipts/bundle.js.map +0 -1
- package/dist/receipts/index.d.ts.map +0 -1
- package/dist/receipts/index.js.map +0 -1
- package/dist/receipts/json.d.ts.map +0 -1
- package/dist/receipts/json.js.map +0 -1
- package/dist/receipts/key-cache.d.ts.map +0 -1
- package/dist/receipts/key-cache.js.map +0 -1
- package/dist/receipts/renderers.d.ts.map +0 -1
- package/dist/receipts/renderers.js.map +0 -1
- package/dist/receipts/resource.d.ts.map +0 -1
- package/dist/receipts/resource.js.map +0 -1
- package/dist/receipts/verify.d.ts.map +0 -1
- package/dist/receipts/verify.js.map +0 -1
- package/dist/sessions.d.ts.map +0 -1
- package/dist/sessions.js.map +0 -1
- package/dist/transport.d.ts.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/webhook-resource.d.ts.map +0 -1
- package/dist/webhook-resource.js.map +0 -1
- package/dist/webhooks/index.d.ts.map +0 -1
- package/dist/webhooks/index.js.map +0 -1
- package/src/ask.ts +0 -683
- package/src/cli/main.ts +0 -8
- package/src/cli/verify.ts +0 -349
- package/src/client.ts +0 -55
- package/src/errors.ts +0 -127
- package/src/generated/openapi.ts +0 -8586
- package/src/index.ts +0 -5
- package/src/internal/decode.ts +0 -348
- package/src/internal/json.ts +0 -64
- package/src/internal/time.ts +0 -85
- package/src/polling.ts +0 -173
- package/src/qr/encoder.ts +0 -345
- package/src/qr/index.ts +0 -203
- package/src/receipts/bundle.ts +0 -547
- package/src/receipts/index.ts +0 -29
- package/src/receipts/json.ts +0 -168
- package/src/receipts/key-cache.ts +0 -143
- package/src/receipts/renderers.ts +0 -220
- package/src/receipts/resource.ts +0 -264
- package/src/receipts/verify.ts +0 -554
- package/src/sessions.ts +0 -238
- package/src/transport.ts +0 -566
- package/src/types.ts +0 -219
- package/src/webhook-resource.ts +0 -81
- package/src/webhooks/index.ts +0 -246
package/src/sessions.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { SessError } from './errors.js';
|
|
2
|
-
import { Transport, pathSegment } from './transport.js';
|
|
3
|
-
import {
|
|
4
|
-
decodeCreate,
|
|
5
|
-
decodeDeliveries,
|
|
6
|
-
decodeEvents,
|
|
7
|
-
decodeSession,
|
|
8
|
-
decodeSurface,
|
|
9
|
-
decodeRedelivery,
|
|
10
|
-
} from './internal/decode.js';
|
|
11
|
-
import { boundedNumber } from './internal/time.js';
|
|
12
|
-
import { waitForResponse } from './polling.js';
|
|
13
|
-
import type {
|
|
14
|
-
ApiResult,
|
|
15
|
-
CreateSessionRequest,
|
|
16
|
-
CreateSessionResponse,
|
|
17
|
-
Deliveries,
|
|
18
|
-
InteractiveSession,
|
|
19
|
-
MutationOptions,
|
|
20
|
-
PublishSessionRequest,
|
|
21
|
-
RequestOptions,
|
|
22
|
-
Session,
|
|
23
|
-
SessionEvents,
|
|
24
|
-
SurfaceRevision,
|
|
25
|
-
VersionedResult,
|
|
26
|
-
WaitOptions,
|
|
27
|
-
WaitResult,
|
|
28
|
-
RedeliverResponse,
|
|
29
|
-
} from './types.js';
|
|
30
|
-
|
|
31
|
-
function mutationIdentity(options: MutationOptions): {
|
|
32
|
-
ifMatch: string;
|
|
33
|
-
idempotencyKey?: string;
|
|
34
|
-
requestOptions: RequestOptions;
|
|
35
|
-
} {
|
|
36
|
-
const source = options ?? ({} as MutationOptions);
|
|
37
|
-
if (typeof source !== 'object' || Array.isArray(source))
|
|
38
|
-
throw new SessError('configuration', 'Mutation options must be an object.', { outcome: 'not_sent' });
|
|
39
|
-
// Inspect the two replay identity fields before spreading/accessing caller options.
|
|
40
|
-
// Accessor or inherited identities are not immutable primitive options.
|
|
41
|
-
for (const name of ['ifMatch', 'idempotencyKey'] as const) {
|
|
42
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, name);
|
|
43
|
-
if (
|
|
44
|
-
(name in source && !descriptor) ||
|
|
45
|
-
(descriptor && !('value' in descriptor)) ||
|
|
46
|
-
(name === 'idempotencyKey' && descriptor && typeof descriptor.value !== 'string')
|
|
47
|
-
)
|
|
48
|
-
throw new SessError(
|
|
49
|
-
'configuration',
|
|
50
|
-
'Mutation identity options must be primitive string data properties.',
|
|
51
|
-
{ outcome: 'not_sent' },
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
const { ifMatch, idempotencyKey, ...requestOptions } = source;
|
|
55
|
-
return { ifMatch, idempotencyKey, requestOptions };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export class Sessions {
|
|
59
|
-
#transport: Transport;
|
|
60
|
-
constructor(transport: Transport) {
|
|
61
|
-
this.#transport = transport;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Creates once. A lost reply may mean creation succeeded; no retry is safe. */
|
|
65
|
-
create(
|
|
66
|
-
body: CreateSessionRequest,
|
|
67
|
-
options: RequestOptions = {},
|
|
68
|
-
): Promise<VersionedResult<CreateSessionResponse>> {
|
|
69
|
-
if ('idempotencyKey' in options || 'ifMatch' in options)
|
|
70
|
-
return Promise.reject(
|
|
71
|
-
new SessError('configuration', 'Session creation does not support idempotency keys or If-Match.', {
|
|
72
|
-
outcome: 'not_sent',
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
// The floor is fixed; the ceiling is the plan's, checked by the runtime.
|
|
76
|
-
const expiresIn = (body as { expires_in?: unknown } | null)?.expires_in;
|
|
77
|
-
if (
|
|
78
|
-
expiresIn !== undefined &&
|
|
79
|
-
(typeof expiresIn !== 'number' || !Number.isSafeInteger(expiresIn) || expiresIn < 30)
|
|
80
|
-
)
|
|
81
|
-
return Promise.reject(
|
|
82
|
-
new SessError('configuration', 'expires_in must be a whole number of seconds, at least 30.', {
|
|
83
|
-
outcome: 'not_sent',
|
|
84
|
-
}),
|
|
85
|
-
);
|
|
86
|
-
return this.#transport.request(
|
|
87
|
-
{
|
|
88
|
-
name: 'sessions.create',
|
|
89
|
-
method: 'POST',
|
|
90
|
-
path: '/v1/sessions',
|
|
91
|
-
body,
|
|
92
|
-
status: 201,
|
|
93
|
-
versioned: true,
|
|
94
|
-
retry: 'never',
|
|
95
|
-
parse: (value) => decodeCreate(value, this.#transport.allowInsecureLocalhost),
|
|
96
|
-
},
|
|
97
|
-
options,
|
|
98
|
-
) as Promise<VersionedResult<CreateSessionResponse>>;
|
|
99
|
-
}
|
|
100
|
-
retrieve(id: string, options?: RequestOptions): Promise<VersionedResult<Session>> {
|
|
101
|
-
return this.#transport.request(
|
|
102
|
-
{
|
|
103
|
-
name: 'sessions.retrieve',
|
|
104
|
-
method: 'GET',
|
|
105
|
-
path: `/v1/sessions/${pathSegment(id)}`,
|
|
106
|
-
status: 200,
|
|
107
|
-
versioned: true,
|
|
108
|
-
retry: 'safe',
|
|
109
|
-
parse: (value) => decodeSession(value, id),
|
|
110
|
-
},
|
|
111
|
-
options,
|
|
112
|
-
) as Promise<VersionedResult<Session>>;
|
|
113
|
-
}
|
|
114
|
-
/** Full next interaction, with the original concurrency and replay identity. */
|
|
115
|
-
async publish(
|
|
116
|
-
id: string,
|
|
117
|
-
body: PublishSessionRequest,
|
|
118
|
-
options: MutationOptions,
|
|
119
|
-
): Promise<VersionedResult<InteractiveSession>> {
|
|
120
|
-
const { ifMatch, idempotencyKey, requestOptions } = mutationIdentity(options);
|
|
121
|
-
return this.#transport.request(
|
|
122
|
-
{
|
|
123
|
-
name: 'sessions.publish',
|
|
124
|
-
method: 'PATCH',
|
|
125
|
-
path: `/v1/sessions/${pathSegment(id)}`,
|
|
126
|
-
body,
|
|
127
|
-
ifMatch,
|
|
128
|
-
idempotencyKey,
|
|
129
|
-
status: 200,
|
|
130
|
-
versioned: true,
|
|
131
|
-
retry: 'mutation',
|
|
132
|
-
parse: (value) => {
|
|
133
|
-
const session = decodeSession(value, id);
|
|
134
|
-
if (!('status' in session) || session.status !== 'active')
|
|
135
|
-
throw new SessError('protocol', 'Publish did not return an active interactive Session.', {
|
|
136
|
-
code: 'INVALID_RESPONSE',
|
|
137
|
-
});
|
|
138
|
-
return session;
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
requestOptions,
|
|
142
|
-
) as Promise<VersionedResult<InteractiveSession>>;
|
|
143
|
-
}
|
|
144
|
-
async complete(id: string, options: MutationOptions): Promise<VersionedResult<InteractiveSession>> {
|
|
145
|
-
const { ifMatch, idempotencyKey, requestOptions } = mutationIdentity(options);
|
|
146
|
-
return this.#transport.request(
|
|
147
|
-
{
|
|
148
|
-
name: 'sessions.complete',
|
|
149
|
-
method: 'POST',
|
|
150
|
-
path: `/v1/sessions/${pathSegment(id)}/complete`,
|
|
151
|
-
ifMatch,
|
|
152
|
-
idempotencyKey,
|
|
153
|
-
status: 200,
|
|
154
|
-
versioned: true,
|
|
155
|
-
retry: 'mutation',
|
|
156
|
-
parse: (value) => {
|
|
157
|
-
const session = decodeSession(value, id);
|
|
158
|
-
if (!('status' in session) || session.status !== 'completed')
|
|
159
|
-
throw new SessError('protocol', 'Complete did not return a completed interactive Session.', {
|
|
160
|
-
code: 'INVALID_RESPONSE',
|
|
161
|
-
});
|
|
162
|
-
return session;
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
requestOptions,
|
|
166
|
-
) as Promise<VersionedResult<InteractiveSession>>;
|
|
167
|
-
}
|
|
168
|
-
listEvents(id: string, options?: RequestOptions): Promise<ApiResult<SessionEvents>> {
|
|
169
|
-
return this.#transport.request(
|
|
170
|
-
{
|
|
171
|
-
name: 'sessions.listEvents',
|
|
172
|
-
method: 'GET',
|
|
173
|
-
path: `/v1/sessions/${pathSegment(id)}/events`,
|
|
174
|
-
status: 200,
|
|
175
|
-
retry: 'safe',
|
|
176
|
-
parse: (value) => decodeEvents(value, id),
|
|
177
|
-
},
|
|
178
|
-
options,
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
retrieveSurface(
|
|
182
|
-
id: string,
|
|
183
|
-
revision: number,
|
|
184
|
-
options?: RequestOptions,
|
|
185
|
-
): Promise<ApiResult<SurfaceRevision>> {
|
|
186
|
-
boundedNumber(revision, 0, 'revision');
|
|
187
|
-
return this.#transport.request(
|
|
188
|
-
{
|
|
189
|
-
name: 'sessions.retrieveSurface',
|
|
190
|
-
method: 'GET',
|
|
191
|
-
path: `/v1/sessions/${pathSegment(id)}/surfaces/${revision}`,
|
|
192
|
-
status: 200,
|
|
193
|
-
retry: 'safe',
|
|
194
|
-
parse: (value) => decodeSurface(value, id, revision),
|
|
195
|
-
},
|
|
196
|
-
options,
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
listDeliveries(id: string, options?: RequestOptions): Promise<ApiResult<Deliveries>> {
|
|
200
|
-
return this.#transport.request(
|
|
201
|
-
{
|
|
202
|
-
name: 'sessions.listDeliveries',
|
|
203
|
-
method: 'GET',
|
|
204
|
-
path: `/v1/sessions/${pathSegment(id)}/deliveries`,
|
|
205
|
-
status: 200,
|
|
206
|
-
retry: 'safe',
|
|
207
|
-
parse: (value) => decodeDeliveries(value, id),
|
|
208
|
-
},
|
|
209
|
-
options,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
redeliverEvent(
|
|
213
|
-
id: string,
|
|
214
|
-
eventId: string,
|
|
215
|
-
options?: RequestOptions,
|
|
216
|
-
): Promise<ApiResult<RedeliverResponse>> {
|
|
217
|
-
return this.#transport.request(
|
|
218
|
-
{
|
|
219
|
-
name: 'sessions.redeliverEvent',
|
|
220
|
-
method: 'POST',
|
|
221
|
-
path: `/v1/sessions/${pathSegment(id)}/events/${pathSegment(eventId)}/redeliver`,
|
|
222
|
-
status: 202,
|
|
223
|
-
retry: 'never',
|
|
224
|
-
parse: (value) => decodeRedelivery(value, eventId),
|
|
225
|
-
},
|
|
226
|
-
options,
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
/** Read-only, restartable wait for exactly one immutable revision. */
|
|
230
|
-
waitForResponse(id: string, options: WaitOptions): Promise<WaitResult> {
|
|
231
|
-
return waitForResponse(
|
|
232
|
-
(requestOptions) => this.retrieve(id, requestOptions),
|
|
233
|
-
id,
|
|
234
|
-
options,
|
|
235
|
-
this.#transport.operationTimeoutMs,
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}
|