@mountaya/client 0.1.0 → 0.2.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 +45 -0
- package/README.md +2 -2
- package/dist/admin/index.cjs +2876 -3502
- package/dist/admin/index.cjs.map +1 -1
- package/dist/admin/index.d.cts +731 -912
- package/dist/admin/index.d.ts +731 -912
- package/dist/admin/index.js +188 -285
- package/dist/admin/index.js.map +1 -1
- package/dist/browser.cjs +5913 -7993
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +42 -78
- package/dist/browser.d.ts +42 -78
- package/dist/browser.js +18 -49
- package/dist/browser.js.map +1 -1
- package/dist/chunk-CeEX7ayk.d.cts +75531 -0
- package/dist/chunk-CeEX7ayk.d.ts +75531 -0
- package/dist/chunk-Cg7Dtcb4.js +2987 -0
- package/dist/chunk-Cg7Dtcb4.js.map +1 -0
- package/dist/chunk-DJqUsgsy.d.ts +1463 -0
- package/dist/chunk-DNc8T5K1.js +241 -0
- package/dist/chunk-DNc8T5K1.js.map +1 -0
- package/dist/chunk-DTxzw3hu.d.cts +1463 -0
- package/dist/chunk-DmxQID5X.js +2289 -0
- package/dist/chunk-DmxQID5X.js.map +1 -0
- package/dist/chunk-DoZt_oIV.d.ts +3991 -0
- package/dist/chunk-DpJrqANO.js +11 -0
- package/dist/chunk-Dx8mPAdC.d.cts +3991 -0
- package/dist/chunk-X2ukY3ho.js +419 -0
- package/dist/chunk-X2ukY3ho.js.map +1 -0
- package/dist/events/index.cjs +1338 -1874
- package/dist/events/index.cjs.map +1 -1
- package/dist/events/index.d.cts +373 -382
- package/dist/events/index.d.ts +373 -382
- package/dist/events/index.js +523 -806
- package/dist/events/index.js.map +1 -1
- package/dist/index.cjs +5908 -7988
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -69
- package/dist/index.d.ts +37 -69
- package/dist/index.js +17 -48
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/browser.ts +1 -0
- package/src/core/rules/clientHeader.ts +1 -1
- package/src/core/rules/errors.ts +1 -1
- package/src/core/rules/nullMasks.gen.ts +14 -2
- package/src/core/rules/version.gen.ts +1 -1
- package/src/events/index.ts +1 -5
- package/src/rest/adminResources.gen.ts +2 -0
- package/src/rest/dates.gen.ts +1 -1
- package/src/rest/resources.gen.ts +2 -0
- package/src/rest/schema.gen.ts +247 -60
- package/src/tiles/schema.gen.ts +1 -3
- package/dist/chunk-BM526BHG.js +0 -342
- package/dist/chunk-BM526BHG.js.map +0 -1
- package/dist/chunk-D2YEVTG7.js +0 -327
- package/dist/chunk-D2YEVTG7.js.map +0 -1
- package/dist/chunk-OHKVUREN.js +0 -3500
- package/dist/chunk-OHKVUREN.js.map +0 -1
- package/dist/chunk-TDTK2L5H.js +0 -3842
- package/dist/chunk-TDTK2L5H.js.map +0 -1
- package/dist/coreOperations.gen-BMYPoBbz.d.ts +0 -1760
- package/dist/coreOperations.gen-BxX5xRxw.d.cts +0 -1760
- package/dist/errors-B-GqAtQv.d.cts +0 -75960
- package/dist/errors-B-GqAtQv.d.ts +0 -75960
- package/dist/operations.gen-CvTyzKNF.d.cts +0 -3993
- package/dist/operations.gen-DUD406TV.d.ts +0 -3993
package/dist/admin/index.js
CHANGED
|
@@ -1,301 +1,204 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
postOrganizationWebhookEndpoint: () => postOrganizationWebhookEndpoint,
|
|
65
|
-
postSession: () => postSession
|
|
1
|
+
import { t as __exportAll } from "../chunk-DpJrqANO.js";
|
|
2
|
+
import { $ as getOrganizationPublishableKey, $t as postMyInvitationAccept, B as getMyOrganizations, Ct as patchOrganization, Dt as patchOrganizationPublishableKey, Et as patchOrganizationMember, G as getOrganizationBillingInvoices, H as getOrganization, J as getOrganizationBillingSubscription, K as getOrganizationBillingPaymentMethods, Mn as MountayaError, On as MountayaConfigurationError, Ot as patchOrganizationSettings, Q as getOrganizationMembers, R as getMyInvitations, St as patchMyPreferences, T as getBillingProducts, Tt as patchOrganizationBillingInfo, U as getOrganizationAiProviderConfig, V as getMyPreferences, W as getOrganizationBillingInfo, Wn as describeType, X as getOrganizationInvitation, Z as getOrganizationInvitations, _ as deleteOrganizationMember, an as postOrganizationBillingProvision, at as getOrganizationWebhookDelivery, ct as getOrganizationWebhookEvent, dn as postOrganizationWebhookEndpoint, dt as getWebhookEventTypes, en as postOrganization, er as refuseOption, et as getOrganizationPublishableKeys, f as deleteMyInvitation, fn as postSession, g as deleteOrganizationInvitation, h as deleteOrganizationBillingSubscription, in as postOrganizationBillingPaymentMethodSetup, it as getOrganizationWebhookDeliveries, kt as patchOrganizationWebhookEndpoint, ln as postOrganizationPublishableKey, lt as getOrganizationWebhookEvents, m as deleteOrganizationBillingPaymentMethod, nn as postOrganizationBillingPaymentMethod, nt as getOrganizationUsageData, on as postOrganizationBillingSubscription, ot as getOrganizationWebhookEndpoint, p as deleteOrganizationAiProviderConfig, q as getOrganizationBillingPromotionCode, rn as postOrganizationBillingPaymentMethodSetDefault, rt as getOrganizationUsageTiles, sn as postOrganizationInvitation, st as getOrganizationWebhookEndpoints, t as bind, tn as postOrganizationAiProviderConfig, tt as getOrganizationSettings, un as postOrganizationWebhookDelivery, ut as getOrganizationWebhookHealth, v as deleteOrganizationPublishableKey, w as getAiProviders, wt as patchOrganizationAiProviderConfig, xt as patchMyOrganizationNotificationPreferences, y as deleteOrganizationWebhookEndpoint, z as getMyOrganizationNotificationPreferences } from "../chunk-Cg7Dtcb4.js";
|
|
3
|
+
import { n as decodeSchemaInstants, t as decodeRestSchema } from "../chunk-X2ukY3ho.js";
|
|
4
|
+
var adminOperations_gen_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
deleteMyInvitation: () => deleteMyInvitation,
|
|
6
|
+
deleteOrganizationAiProviderConfig: () => deleteOrganizationAiProviderConfig,
|
|
7
|
+
deleteOrganizationBillingPaymentMethod: () => deleteOrganizationBillingPaymentMethod,
|
|
8
|
+
deleteOrganizationBillingSubscription: () => deleteOrganizationBillingSubscription,
|
|
9
|
+
deleteOrganizationInvitation: () => deleteOrganizationInvitation,
|
|
10
|
+
deleteOrganizationMember: () => deleteOrganizationMember,
|
|
11
|
+
deleteOrganizationPublishableKey: () => deleteOrganizationPublishableKey,
|
|
12
|
+
deleteOrganizationWebhookEndpoint: () => deleteOrganizationWebhookEndpoint,
|
|
13
|
+
getAiProviders: () => getAiProviders,
|
|
14
|
+
getBillingProducts: () => getBillingProducts,
|
|
15
|
+
getMyInvitations: () => getMyInvitations,
|
|
16
|
+
getMyOrganizationNotificationPreferences: () => getMyOrganizationNotificationPreferences,
|
|
17
|
+
getMyOrganizations: () => getMyOrganizations,
|
|
18
|
+
getMyPreferences: () => getMyPreferences,
|
|
19
|
+
getOrganization: () => getOrganization,
|
|
20
|
+
getOrganizationAiProviderConfig: () => getOrganizationAiProviderConfig,
|
|
21
|
+
getOrganizationBillingInfo: () => getOrganizationBillingInfo,
|
|
22
|
+
getOrganizationBillingInvoices: () => getOrganizationBillingInvoices,
|
|
23
|
+
getOrganizationBillingPaymentMethods: () => getOrganizationBillingPaymentMethods,
|
|
24
|
+
getOrganizationBillingPromotionCode: () => getOrganizationBillingPromotionCode,
|
|
25
|
+
getOrganizationBillingSubscription: () => getOrganizationBillingSubscription,
|
|
26
|
+
getOrganizationInvitation: () => getOrganizationInvitation,
|
|
27
|
+
getOrganizationInvitations: () => getOrganizationInvitations,
|
|
28
|
+
getOrganizationMembers: () => getOrganizationMembers,
|
|
29
|
+
getOrganizationPublishableKey: () => getOrganizationPublishableKey,
|
|
30
|
+
getOrganizationPublishableKeys: () => getOrganizationPublishableKeys,
|
|
31
|
+
getOrganizationSettings: () => getOrganizationSettings,
|
|
32
|
+
getOrganizationUsageData: () => getOrganizationUsageData,
|
|
33
|
+
getOrganizationUsageTiles: () => getOrganizationUsageTiles,
|
|
34
|
+
getOrganizationWebhookDeliveries: () => getOrganizationWebhookDeliveries,
|
|
35
|
+
getOrganizationWebhookDelivery: () => getOrganizationWebhookDelivery,
|
|
36
|
+
getOrganizationWebhookEndpoint: () => getOrganizationWebhookEndpoint,
|
|
37
|
+
getOrganizationWebhookEndpoints: () => getOrganizationWebhookEndpoints,
|
|
38
|
+
getOrganizationWebhookEvent: () => getOrganizationWebhookEvent,
|
|
39
|
+
getOrganizationWebhookEvents: () => getOrganizationWebhookEvents,
|
|
40
|
+
getOrganizationWebhookHealth: () => getOrganizationWebhookHealth,
|
|
41
|
+
getWebhookEventTypes: () => getWebhookEventTypes,
|
|
42
|
+
patchMyOrganizationNotificationPreferences: () => patchMyOrganizationNotificationPreferences,
|
|
43
|
+
patchMyPreferences: () => patchMyPreferences,
|
|
44
|
+
patchOrganization: () => patchOrganization,
|
|
45
|
+
patchOrganizationAiProviderConfig: () => patchOrganizationAiProviderConfig,
|
|
46
|
+
patchOrganizationBillingInfo: () => patchOrganizationBillingInfo,
|
|
47
|
+
patchOrganizationMember: () => patchOrganizationMember,
|
|
48
|
+
patchOrganizationPublishableKey: () => patchOrganizationPublishableKey,
|
|
49
|
+
patchOrganizationSettings: () => patchOrganizationSettings,
|
|
50
|
+
patchOrganizationWebhookEndpoint: () => patchOrganizationWebhookEndpoint,
|
|
51
|
+
postMyInvitationAccept: () => postMyInvitationAccept,
|
|
52
|
+
postOrganization: () => postOrganization,
|
|
53
|
+
postOrganizationAiProviderConfig: () => postOrganizationAiProviderConfig,
|
|
54
|
+
postOrganizationBillingPaymentMethod: () => postOrganizationBillingPaymentMethod,
|
|
55
|
+
postOrganizationBillingPaymentMethodSetDefault: () => postOrganizationBillingPaymentMethodSetDefault,
|
|
56
|
+
postOrganizationBillingPaymentMethodSetup: () => postOrganizationBillingPaymentMethodSetup,
|
|
57
|
+
postOrganizationBillingProvision: () => postOrganizationBillingProvision,
|
|
58
|
+
postOrganizationBillingSubscription: () => postOrganizationBillingSubscription,
|
|
59
|
+
postOrganizationInvitation: () => postOrganizationInvitation,
|
|
60
|
+
postOrganizationPublishableKey: () => postOrganizationPublishableKey,
|
|
61
|
+
postOrganizationWebhookDelivery: () => postOrganizationWebhookDelivery,
|
|
62
|
+
postOrganizationWebhookEndpoint: () => postOrganizationWebhookEndpoint,
|
|
63
|
+
postSession: () => postSession
|
|
66
64
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var LATEST_WRITTEN_SECONDS = 253402300799;
|
|
74
|
-
var signedAt = (timestamp) => timestamp <= LATEST_WRITTEN_SECONDS ? new Date(timestamp * 1e3).toISOString() : `t=${timestamp}`;
|
|
65
|
+
const CONTEXT = "constructWebhookEvent";
|
|
66
|
+
const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
67
|
+
const SECRET_PREFIX = "whsk_";
|
|
68
|
+
const wholeSeconds = /^\d+$/;
|
|
69
|
+
const LATEST_WRITTEN_SECONDS = 253402300799;
|
|
70
|
+
const signedAt = (timestamp) => timestamp <= LATEST_WRITTEN_SECONDS ? (/* @__PURE__ */ new Date(timestamp * 1e3)).toISOString() : `t=${timestamp}`;
|
|
75
71
|
var MountayaWebhookSignatureError = class extends MountayaError {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*/
|
|
83
|
-
constructor(message, reason) {
|
|
84
|
-
super(message);
|
|
85
|
-
this.reason = reason;
|
|
86
|
-
}
|
|
72
|
+
name = "MountayaWebhookSignatureError";
|
|
73
|
+
reason;
|
|
74
|
+
constructor(message, reason) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.reason = reason;
|
|
77
|
+
}
|
|
87
78
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const timestamp = Number(stated);
|
|
109
|
-
if (!Number.isSafeInteger(timestamp) || signatures.length === 0) {
|
|
110
|
-
return void 0;
|
|
111
|
-
}
|
|
112
|
-
return { signatures, stated, timestamp };
|
|
79
|
+
const parseSignatureHeader = (header) => {
|
|
80
|
+
const signatures = [];
|
|
81
|
+
const timestamps = [];
|
|
82
|
+
for (const element of header.split(",")) {
|
|
83
|
+
const separator = element.indexOf("=");
|
|
84
|
+
if (separator === -1) return;
|
|
85
|
+
const key = element.slice(0, separator).trim();
|
|
86
|
+
const value = element.slice(separator + 1).trim();
|
|
87
|
+
if (key === "t") timestamps.push(value);
|
|
88
|
+
else if (key === "v1") signatures.push(value);
|
|
89
|
+
}
|
|
90
|
+
const [stated] = timestamps;
|
|
91
|
+
if (timestamps.length !== 1 || stated === void 0 || !wholeSeconds.test(stated)) return;
|
|
92
|
+
const timestamp = Number(stated);
|
|
93
|
+
if (!Number.isSafeInteger(timestamp) || signatures.length === 0) return;
|
|
94
|
+
return {
|
|
95
|
+
signatures,
|
|
96
|
+
stated,
|
|
97
|
+
timestamp
|
|
98
|
+
};
|
|
113
99
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return runtime.crypto?.subtle;
|
|
100
|
+
const subtleCrypto = () => {
|
|
101
|
+
return globalThis.crypto?.subtle;
|
|
117
102
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
for (let index = 0; index < expected.length; index += 1) {
|
|
125
|
-
difference |= candidate.charCodeAt(index) ^ expected.charCodeAt(index);
|
|
126
|
-
}
|
|
127
|
-
return difference === 0;
|
|
103
|
+
const hexOf = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
104
|
+
const equalInConstantTime = (candidate, expected) => {
|
|
105
|
+
if (candidate.length !== expected.length) return false;
|
|
106
|
+
let difference = 0;
|
|
107
|
+
for (let index = 0; index < expected.length; index += 1) difference |= candidate.charCodeAt(index) ^ expected.charCodeAt(index);
|
|
108
|
+
return difference === 0;
|
|
128
109
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
110
|
+
const signedBytes = (stated, body) => {
|
|
111
|
+
const prefix = new TextEncoder().encode(`${stated}.`);
|
|
112
|
+
const signed = new Uint8Array(prefix.length + body.length);
|
|
113
|
+
signed.set(prefix);
|
|
114
|
+
signed.set(body, prefix.length);
|
|
115
|
+
return signed;
|
|
135
116
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return parsed;
|
|
117
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
118
|
+
const envelopeOf = (body) => {
|
|
119
|
+
const refusal = `${CONTEXT}: the delivery verified and its body holds no webhook event, not even the envelope every event is delivered in. Answer the request with a 400 and act on nothing it asks.`;
|
|
120
|
+
let parsed;
|
|
121
|
+
try {
|
|
122
|
+
parsed = JSON.parse(new TextDecoder().decode(body));
|
|
123
|
+
} catch (cause) {
|
|
124
|
+
throw new MountayaConfigurationError(refusal, { cause });
|
|
125
|
+
}
|
|
126
|
+
if (!isRecord(parsed)) throw new MountayaConfigurationError(refusal);
|
|
127
|
+
return parsed;
|
|
149
128
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
129
|
+
const withPreviousAttributes = (event) => {
|
|
130
|
+
if (!isRecord(event) || !isRecord(event.data) || !isRecord(event.data.previous_attributes)) return event;
|
|
131
|
+
const held = event.data.previous_attributes;
|
|
132
|
+
const decoded = decodeSchemaInstants("WebhookEventObject", held);
|
|
133
|
+
return decoded === held ? event : {
|
|
134
|
+
...event,
|
|
135
|
+
data: {
|
|
136
|
+
...event.data,
|
|
137
|
+
previous_attributes: decoded
|
|
138
|
+
}
|
|
139
|
+
};
|
|
157
140
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
141
|
+
const millisecondsOf = (value) => {
|
|
142
|
+
try {
|
|
143
|
+
return Date.prototype.getTime.call(value);
|
|
144
|
+
} catch {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
164
147
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
`pass a finite number of seconds from 0, or leave it out for ${DEFAULT_TOLERANCE_SECONDS}.`,
|
|
190
|
-
CONTEXT
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
const stated = options?.now;
|
|
194
|
-
const statedMilliseconds = stated === void 0 ? void 0 : millisecondsOf(stated);
|
|
195
|
-
if (stated !== void 0 && (statedMilliseconds === void 0 || !Number.isFinite(statedMilliseconds))) {
|
|
196
|
-
throw refuseOption(
|
|
197
|
-
"now",
|
|
198
|
-
stated,
|
|
199
|
-
"pass a Date that names an instant, or leave it out for the machine's wall clock.",
|
|
200
|
-
CONTEXT
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
const subtle = subtleCrypto();
|
|
204
|
-
if (subtle === void 0) {
|
|
205
|
-
throw new MountayaConfigurationError(
|
|
206
|
-
`${CONTEXT}: this runtime provides no Web Crypto (crypto.subtle) to compute the signature with. Verify the delivery on a server, in Node 22.18 or later, a worker or an edge runtime.`
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
if (signatureHeader === null || signatureHeader === void 0 || signatureHeader.trim() === "") {
|
|
210
|
-
throw new MountayaWebhookSignatureError(
|
|
211
|
-
`${CONTEXT}: the request carries no Mountaya-Signature header. Pass the header the request carries, such as request.headers.get("Mountaya-Signature"), and answer a request without one with a 400.`,
|
|
212
|
-
"missing-header"
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
const header = parseSignatureHeader(signatureHeader);
|
|
216
|
-
if (header === void 0) {
|
|
217
|
-
throw new MountayaWebhookSignatureError(
|
|
218
|
-
`${CONTEXT}: the Mountaya-Signature header ${JSON.stringify(signatureHeader)} is not t=<unix seconds>,v1=<signature>. Pass the header exactly as the request carries it.`,
|
|
219
|
-
"malformed-header"
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
const body = typeof rawBody === "string" ? new TextEncoder().encode(rawBody) : rawBody;
|
|
223
|
-
const key = await subtle.importKey(
|
|
224
|
-
"raw",
|
|
225
|
-
new TextEncoder().encode(secret),
|
|
226
|
-
{ hash: "SHA-256", name: "HMAC" },
|
|
227
|
-
false,
|
|
228
|
-
["sign"]
|
|
229
|
-
);
|
|
230
|
-
const expected = hexOf(await subtle.sign("HMAC", key, signedBytes(header.stated, body)));
|
|
231
|
-
const verified = header.signatures.reduce(
|
|
232
|
-
(found, candidate) => equalInConstantTime(candidate, expected) || found,
|
|
233
|
-
false
|
|
234
|
-
);
|
|
235
|
-
if (!verified) {
|
|
236
|
-
throw new MountayaWebhookSignatureError(
|
|
237
|
-
`${CONTEXT}: no v1 of the Mountaya-Signature header is the signature of this body under this secret. Pass the body exactly as it arrived, before any JSON parser reads it, and the secret of the endpoint the delivery was sent to.`,
|
|
238
|
-
"signature"
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
const skew = Math.abs((statedMilliseconds ?? Date.now()) / 1e3 - header.timestamp);
|
|
242
|
-
if (skew > toleranceSeconds) {
|
|
243
|
-
throw new MountayaWebhookSignatureError(
|
|
244
|
-
`${CONTEXT}: the delivery was signed at ${signedAt(header.timestamp)}, ${Math.round(skew)} seconds from this clock, past the tolerance of ${toleranceSeconds} seconds. A delivery replayed later is refused this way; where the clock is wrong, set it right.`,
|
|
245
|
-
"timestamp"
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
const event = withPreviousAttributes(decodeRestSchema("WebhookEvent", envelopeOf(body)));
|
|
249
|
-
return event;
|
|
148
|
+
const constructWebhookEvent = async (rawBody, signatureHeader, secret, options) => {
|
|
149
|
+
if (typeof rawBody !== "string" && !(rawBody instanceof Uint8Array)) throw new MountayaConfigurationError(`${CONTEXT}: rawBody is ${describeType(rawBody)}; pass the body exactly as it arrived, as a string or a Uint8Array, before any JSON parser reads it.`);
|
|
150
|
+
if (typeof secret !== "string" || !secret.startsWith(SECRET_PREFIX)) throw new MountayaConfigurationError(`${CONTEXT}: secret is ${typeof secret === "string" ? "a string that does not start with whsk_" : describeType(secret)}; pass the signing secret of the endpoint the delivery was sent to, whsk_ included.`);
|
|
151
|
+
if (options !== void 0 && (typeof options !== "object" || options === null)) throw refuseOption("options", options, "pass an object such as { toleranceSeconds: 600 }, or leave it out for the defaults.", CONTEXT);
|
|
152
|
+
const toleranceSeconds = options?.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
|
|
153
|
+
if (typeof toleranceSeconds !== "number" || !Number.isFinite(toleranceSeconds) || toleranceSeconds < 0) throw refuseOption("toleranceSeconds", toleranceSeconds, `pass a finite number of seconds from 0, or leave it out for ${DEFAULT_TOLERANCE_SECONDS}.`, CONTEXT);
|
|
154
|
+
const stated = options?.now;
|
|
155
|
+
const statedMilliseconds = stated === void 0 ? void 0 : millisecondsOf(stated);
|
|
156
|
+
if (stated !== void 0 && (statedMilliseconds === void 0 || !Number.isFinite(statedMilliseconds))) throw refuseOption("now", stated, "pass a Date that names an instant, or leave it out for the machine's wall clock.", CONTEXT);
|
|
157
|
+
const subtle = subtleCrypto();
|
|
158
|
+
if (subtle === void 0) throw new MountayaConfigurationError(`${CONTEXT}: this runtime provides no Web Crypto (crypto.subtle) to compute the signature with. Verify the delivery on a server, in Node 22.18 or later, a worker or an edge runtime.`);
|
|
159
|
+
if (signatureHeader === null || signatureHeader === void 0 || signatureHeader.trim() === "") throw new MountayaWebhookSignatureError(`${CONTEXT}: the request carries no Mountaya-Signature header. Pass the header the request carries, such as request.headers.get("Mountaya-Signature"), and answer a request without one with a 400.`, "missing-header");
|
|
160
|
+
const header = parseSignatureHeader(signatureHeader);
|
|
161
|
+
if (header === void 0) throw new MountayaWebhookSignatureError(`${CONTEXT}: the Mountaya-Signature header ${JSON.stringify(signatureHeader)} is not t=<unix seconds>,v1=<signature>. Pass the header exactly as the request carries it.`, "malformed-header");
|
|
162
|
+
const body = typeof rawBody === "string" ? new TextEncoder().encode(rawBody) : rawBody;
|
|
163
|
+
const key = await subtle.importKey("raw", new TextEncoder().encode(secret), {
|
|
164
|
+
hash: "SHA-256",
|
|
165
|
+
name: "HMAC"
|
|
166
|
+
}, false, ["sign"]);
|
|
167
|
+
const expected = hexOf(await subtle.sign("HMAC", key, signedBytes(header.stated, body)));
|
|
168
|
+
if (!header.signatures.reduce((found, candidate) => equalInConstantTime(candidate, expected) || found, false)) throw new MountayaWebhookSignatureError(`${CONTEXT}: no v1 of the Mountaya-Signature header is the signature of this body under this secret. Pass the body exactly as it arrived, before any JSON parser reads it, and the secret of the endpoint the delivery was sent to.`, "signature");
|
|
169
|
+
const skew = Math.abs((statedMilliseconds ?? Date.now()) / 1e3 - header.timestamp);
|
|
170
|
+
if (skew > toleranceSeconds) throw new MountayaWebhookSignatureError(`${CONTEXT}: the delivery was signed at ${signedAt(header.timestamp)}, ${Math.round(skew)} seconds from this clock, past the tolerance of ${toleranceSeconds} seconds. A delivery replayed later is refused this way; where the clock is wrong, set it right.`, "timestamp");
|
|
171
|
+
return withPreviousAttributes(decodeRestSchema("WebhookEvent", envelopeOf(body)));
|
|
250
172
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
const table = bind(transport).admin;
|
|
260
|
-
bound.set(transport, table);
|
|
261
|
-
return table;
|
|
173
|
+
const bound = /* @__PURE__ */ new WeakMap();
|
|
174
|
+
const adminOperationsOf = (transport) => {
|
|
175
|
+
const held = bound.get(transport);
|
|
176
|
+
if (held !== void 0) return held;
|
|
177
|
+
const table = bind(transport).admin;
|
|
178
|
+
bound.set(transport, table);
|
|
179
|
+
return table;
|
|
262
180
|
};
|
|
263
181
|
var MountayaAdmin = class {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
* @param mountaya The client whose transport the operations call through: a `Mountaya` of
|
|
284
|
-
* `@mountaya/client` or of `@mountaya/client/browser`.
|
|
285
|
-
*/
|
|
286
|
-
constructor(mountaya) {
|
|
287
|
-
const operations = adminOperationsOf(mountaya.transport);
|
|
288
|
-
this.billing = operations.billing;
|
|
289
|
-
this.invitations = operations.invitations;
|
|
290
|
-
this.keys = operations.keys;
|
|
291
|
-
this.members = operations.members;
|
|
292
|
-
this.organizations = operations.organizations;
|
|
293
|
-
this.sessions = operations.sessions;
|
|
294
|
-
this.users = operations.users;
|
|
295
|
-
this.webhooks = operations.webhooks;
|
|
296
|
-
}
|
|
182
|
+
billing;
|
|
183
|
+
invitations;
|
|
184
|
+
keys;
|
|
185
|
+
members;
|
|
186
|
+
organizations;
|
|
187
|
+
sessions;
|
|
188
|
+
users;
|
|
189
|
+
webhooks;
|
|
190
|
+
constructor(mountaya) {
|
|
191
|
+
const operations = adminOperationsOf(mountaya.transport);
|
|
192
|
+
this.billing = operations.billing;
|
|
193
|
+
this.invitations = operations.invitations;
|
|
194
|
+
this.keys = operations.keys;
|
|
195
|
+
this.members = operations.members;
|
|
196
|
+
this.organizations = operations.organizations;
|
|
197
|
+
this.sessions = operations.sessions;
|
|
198
|
+
this.users = operations.users;
|
|
199
|
+
this.webhooks = operations.webhooks;
|
|
200
|
+
}
|
|
297
201
|
};
|
|
298
|
-
|
|
299
202
|
export { MountayaAdmin, MountayaWebhookSignatureError, constructWebhookEvent, adminOperations_gen_exports as rest };
|
|
300
|
-
|
|
203
|
+
|
|
301
204
|
//# sourceMappingURL=index.js.map
|
package/dist/admin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rest/adminOperations.gen.ts","../../src/webhooks/rules/constructWebhookEvent.ts","../../src/admin/rules/mountayaAdmin.ts"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":["runtime"],"sources":["../../src/rest/adminOperations.gen.ts","../../src/webhooks/rules/constructWebhookEvent.ts","../../src/admin/rules/mountayaAdmin.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACoCA,MAAM,UAAU;AAGhB,MAAM,4BAA4B;AAGlC,MAAM,gBAAgB;AAGtB,MAAM,eAAe;AAGrB,MAAM,yBAAyB;AAM/B,MAAM,YAAY,cAChB,aAAa,0CAAyB,IAAI,KAAK,YAAY,GAAI,EAAA,CAAE,YAAY,IAAI,KAAK;AA8BxF,IAAa,gCAAb,cAAmD,cAAc;CAC/D,OAAyB;CAGzB;CAMA,YAAY,SAAiB,QAAiC;EAC5D,MAAM,OAAO;EACb,KAAK,SAAS;CAChB;AACF;AAyCA,MAAM,wBAAwB,WAAgD;CAC5E,MAAM,aAAuB,CAAC;CAC9B,MAAM,aAAuB,CAAC;CAE9B,KAAK,MAAM,WAAW,OAAO,MAAM,GAAG,GAAG;EACvC,MAAM,YAAY,QAAQ,QAAQ,GAAG;EACrC,IAAI,cAAc,IAChB;EAGF,MAAM,MAAM,QAAQ,MAAM,GAAG,SAAS,CAAC,CAAC,KAAK;EAC7C,MAAM,QAAQ,QAAQ,MAAM,YAAY,CAAC,CAAC,CAAC,KAAK;EAEhD,IAAI,QAAQ,KACV,WAAW,KAAK,KAAK;OAChB,IAAI,QAAQ,MACjB,WAAW,KAAK,KAAK;CAEzB;CAEA,MAAM,CAAC,UAAU;CACjB,IAAI,WAAW,WAAW,KAAK,WAAW,KAAA,KAAa,CAAC,aAAa,KAAK,MAAM,GAC9E;CAGF,MAAM,YAAY,OAAO,MAAM;CAC/B,IAAI,CAAC,OAAO,cAAc,SAAS,KAAK,WAAW,WAAW,GAC5D;CAGF,OAAO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