@mitralab.io/sdk-core 0.2.13 → 0.2.15
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 +39 -0
- package/README.md +5 -2
- package/contracts/README.md +10 -0
- package/contracts/manifest.json +11 -1
- package/contracts/v0.2.14/sdk-parity.json +2902 -0
- package/contracts/v0.2.15/sdk-parity.json +2902 -0
- package/dist/index.cjs +154 -2
- package/dist/index.d.cts +116 -4
- package/dist/index.d.ts +116 -4
- package/dist/index.js +154 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48,6 +48,9 @@ function isObject(value) {
|
|
|
48
48
|
function isNullableString(value) {
|
|
49
49
|
return value === null || typeof value === "string";
|
|
50
50
|
}
|
|
51
|
+
function isNonEmptyString(value) {
|
|
52
|
+
return typeof value === "string" && value.length > 0;
|
|
53
|
+
}
|
|
51
54
|
function isNullableBoolean(value) {
|
|
52
55
|
return value === null || typeof value === "boolean";
|
|
53
56
|
}
|
|
@@ -436,6 +439,9 @@ function expectAppFields(app, context, errors) {
|
|
|
436
439
|
if (!isNullableString(app.icon)) invalidField(context, "icon", errors);
|
|
437
440
|
if (!isNullableString(app.template)) invalidField(context, "template", errors);
|
|
438
441
|
if (typeof app.allowSignup !== "boolean") invalidField(context, "allowSignup", errors);
|
|
442
|
+
for (const field of ["emailLoginEnabled", "passwordLoginEnabled"]) {
|
|
443
|
+
if (field in app && typeof app[field] !== "boolean") invalidField(context, field, errors);
|
|
444
|
+
}
|
|
439
445
|
if (typeof app.externalAccessEnabled !== "boolean") {
|
|
440
446
|
invalidField(context, "externalAccessEnabled", errors);
|
|
441
447
|
}
|
|
@@ -678,6 +684,48 @@ function expectMessageAccepted(value, context, errors = defaultSdkCoreErrorFacto
|
|
|
678
684
|
if (typeof response.messageId !== "string") invalidField(context, "messageId", errors);
|
|
679
685
|
return response;
|
|
680
686
|
}
|
|
687
|
+
function expectEmailTemplate(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
688
|
+
const template = expectObject(value, context, errors);
|
|
689
|
+
if (typeof template.id !== "string") invalidField(context, "id", errors);
|
|
690
|
+
if (!isNonEmptyString(template.type)) invalidField(context, "type", errors);
|
|
691
|
+
if (!isNullableString(template.senderIdentityId)) {
|
|
692
|
+
invalidField(context, "senderIdentityId", errors);
|
|
693
|
+
}
|
|
694
|
+
if (typeof template.subject !== "string") invalidField(context, "subject", errors);
|
|
695
|
+
if (typeof template.htmlBody !== "string") invalidField(context, "htmlBody", errors);
|
|
696
|
+
if (!isNullableString(template.textBody)) invalidField(context, "textBody", errors);
|
|
697
|
+
if (typeof template.platformDefault !== "boolean") {
|
|
698
|
+
invalidField(context, "platformDefault", errors);
|
|
699
|
+
}
|
|
700
|
+
if (typeof template.createdAt !== "string") invalidField(context, "createdAt", errors);
|
|
701
|
+
if (typeof template.updatedAt !== "string") invalidField(context, "updatedAt", errors);
|
|
702
|
+
return template;
|
|
703
|
+
}
|
|
704
|
+
function expectEmailTemplateTypeCatalog(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
705
|
+
const catalog = expectObject(value, context, errors);
|
|
706
|
+
if (!isNonEmptyString(catalog.type)) invalidField(context, "type", errors);
|
|
707
|
+
expectObjectArray(catalog.variables, `${context} variables`, errors).forEach(
|
|
708
|
+
(variable, position) => {
|
|
709
|
+
const variableContext = `${context} variable ${position}`;
|
|
710
|
+
if (typeof variable.name !== "string") invalidField(variableContext, "name", errors);
|
|
711
|
+
if (typeof variable.required !== "boolean") {
|
|
712
|
+
invalidField(variableContext, "required", errors);
|
|
713
|
+
}
|
|
714
|
+
if (!isNullableString(variable.description)) {
|
|
715
|
+
invalidField(variableContext, "description", errors);
|
|
716
|
+
}
|
|
717
|
+
if (!isNullableString(variable.preview)) invalidField(variableContext, "preview", errors);
|
|
718
|
+
}
|
|
719
|
+
);
|
|
720
|
+
return catalog;
|
|
721
|
+
}
|
|
722
|
+
function expectEmailTemplatePreview(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
723
|
+
const preview = expectObject(value, context, errors);
|
|
724
|
+
if (typeof preview.subject !== "string") invalidField(context, "subject", errors);
|
|
725
|
+
if (typeof preview.htmlBody !== "string") invalidField(context, "htmlBody", errors);
|
|
726
|
+
if (!isNullableString(preview.textBody)) invalidField(context, "textBody", errors);
|
|
727
|
+
return preview;
|
|
728
|
+
}
|
|
681
729
|
function expectAgentDefinition(value, context, errors = defaultSdkCoreErrorFactory) {
|
|
682
730
|
const agent = expectObject(value, context, errors);
|
|
683
731
|
if (typeof agent.id !== "string") invalidField(context, "id", errors);
|
|
@@ -2849,7 +2897,21 @@ function createMembersModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
|
2849
2897
|
}
|
|
2850
2898
|
|
|
2851
2899
|
// src/modules/messenger.ts
|
|
2852
|
-
function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
2900
|
+
function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory, getAppId) {
|
|
2901
|
+
const templatePath = (type) => `/api/v1/email/templates/${encodePathSegment(type, "email template type", errors)}`;
|
|
2902
|
+
const currentAppId = () => {
|
|
2903
|
+
const appId = getAppId?.();
|
|
2904
|
+
if (!appId) configurationError("An appId is required for email templates", errors);
|
|
2905
|
+
return appId;
|
|
2906
|
+
};
|
|
2907
|
+
const preview = async (type, appId) => expectEmailTemplatePreview(
|
|
2908
|
+
await transport.request(`${templatePath(type)}/preview`, {
|
|
2909
|
+
method: "GET",
|
|
2910
|
+
params: { appId }
|
|
2911
|
+
}),
|
|
2912
|
+
"Email template preview response",
|
|
2913
|
+
errors
|
|
2914
|
+
);
|
|
2853
2915
|
return {
|
|
2854
2916
|
async notify(content) {
|
|
2855
2917
|
return expectMessageAccepted(
|
|
@@ -2860,9 +2922,99 @@ function createMessengerModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
|
2860
2922
|
"Notify user response",
|
|
2861
2923
|
errors
|
|
2862
2924
|
);
|
|
2925
|
+
},
|
|
2926
|
+
async sendEmail(input) {
|
|
2927
|
+
return expectMessageAccepted(
|
|
2928
|
+
await transport.request("/api/v1/messages/send", {
|
|
2929
|
+
method: "POST",
|
|
2930
|
+
body: { channel: "EMAIL", payload: rawEmailPayload(input) }
|
|
2931
|
+
}),
|
|
2932
|
+
"Send email response",
|
|
2933
|
+
errors
|
|
2934
|
+
);
|
|
2935
|
+
},
|
|
2936
|
+
async listEmailTemplates() {
|
|
2937
|
+
return expectObjectArray(
|
|
2938
|
+
await transport.request("/api/v1/email/templates", {
|
|
2939
|
+
method: "GET",
|
|
2940
|
+
params: { appId: currentAppId() }
|
|
2941
|
+
}),
|
|
2942
|
+
"Email template list response",
|
|
2943
|
+
errors,
|
|
2944
|
+
expectEmailTemplate
|
|
2945
|
+
);
|
|
2946
|
+
},
|
|
2947
|
+
async getEmailTemplateType(type) {
|
|
2948
|
+
return expectEmailTemplateTypeCatalog(
|
|
2949
|
+
await transport.request(
|
|
2950
|
+
`/api/v1/email/template-types/${encodePathSegment(type, "email template type", errors)}`,
|
|
2951
|
+
{ method: "GET" }
|
|
2952
|
+
),
|
|
2953
|
+
"Email template type response",
|
|
2954
|
+
errors
|
|
2955
|
+
);
|
|
2956
|
+
},
|
|
2957
|
+
async getEmailTemplate(type) {
|
|
2958
|
+
return expectEmailTemplate(
|
|
2959
|
+
await transport.request(templatePath(type), {
|
|
2960
|
+
method: "GET",
|
|
2961
|
+
params: { appId: currentAppId() }
|
|
2962
|
+
}),
|
|
2963
|
+
"Email template response",
|
|
2964
|
+
errors
|
|
2965
|
+
);
|
|
2966
|
+
},
|
|
2967
|
+
async upsertEmailTemplate(type, input) {
|
|
2968
|
+
const appId = currentAppId();
|
|
2969
|
+
const template = expectEmailTemplate(
|
|
2970
|
+
await transport.request(templatePath(type), {
|
|
2971
|
+
method: "PUT",
|
|
2972
|
+
body: templateBody(appId, input)
|
|
2973
|
+
}),
|
|
2974
|
+
"Upsert email template response",
|
|
2975
|
+
errors
|
|
2976
|
+
);
|
|
2977
|
+
try {
|
|
2978
|
+
return { template, preview: await preview(type, appId) };
|
|
2979
|
+
} catch (previewError) {
|
|
2980
|
+
return { template, preview: null, previewError };
|
|
2981
|
+
}
|
|
2982
|
+
},
|
|
2983
|
+
async previewEmailTemplate(type) {
|
|
2984
|
+
return preview(type, currentAppId());
|
|
2985
|
+
},
|
|
2986
|
+
async deleteEmailTemplate(type) {
|
|
2987
|
+
expectEmpty(
|
|
2988
|
+
await transport.request(templatePath(type), {
|
|
2989
|
+
method: "DELETE",
|
|
2990
|
+
params: { appId: currentAppId() }
|
|
2991
|
+
}),
|
|
2992
|
+
"Delete email template response",
|
|
2993
|
+
errors
|
|
2994
|
+
);
|
|
2863
2995
|
}
|
|
2864
2996
|
};
|
|
2865
2997
|
}
|
|
2998
|
+
function rawEmailPayload(input) {
|
|
2999
|
+
return {
|
|
3000
|
+
type: "RAW",
|
|
3001
|
+
to: input.to,
|
|
3002
|
+
...input.cc === void 0 ? {} : { cc: input.cc },
|
|
3003
|
+
...input.bcc === void 0 ? {} : { bcc: input.bcc },
|
|
3004
|
+
...input.replyTo === void 0 ? {} : { replyTo: input.replyTo },
|
|
3005
|
+
subject: input.subject,
|
|
3006
|
+
html: input.html,
|
|
3007
|
+
...input.text === void 0 ? {} : { text: input.text }
|
|
3008
|
+
};
|
|
3009
|
+
}
|
|
3010
|
+
function templateBody(appId, input) {
|
|
3011
|
+
return {
|
|
3012
|
+
appId,
|
|
3013
|
+
subject: input.subject,
|
|
3014
|
+
htmlBody: input.htmlBody,
|
|
3015
|
+
...input.textBody === void 0 ? {} : { textBody: input.textBody }
|
|
3016
|
+
};
|
|
3017
|
+
}
|
|
2866
3018
|
|
|
2867
3019
|
// src/modules/publicFunctions.ts
|
|
2868
3020
|
function createPublicFunctionsModule(transport, errors = defaultSdkCoreErrorFactory) {
|
|
@@ -3180,7 +3332,7 @@ function createSdkCore(options) {
|
|
|
3180
3332
|
integrationResources: createIntegrationResourcesModule(options.transports.integration, errors),
|
|
3181
3333
|
integrationTemplates: createIntegrationTemplatesModule(options.transports.integration, errors),
|
|
3182
3334
|
members,
|
|
3183
|
-
messenger: createMessengerModule(messengerTransport, errors),
|
|
3335
|
+
messenger: createMessengerModule(messengerTransport, errors, options.getAppId),
|
|
3184
3336
|
publicFunctions: createPublicFunctionsModule(options.transports.publicFunctions, errors),
|
|
3185
3337
|
queries: createQueriesModule(options.transports.dataManager, errors),
|
|
3186
3338
|
sql: createSqlModule(options.transports.dataManager, errors),
|