@salesforce/templates 66.10.4 → 66.11.1
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/lib/generators/apexClassGenerator.js +9 -2
- package/lib/generators/apexClassGenerator.js.map +1 -1
- package/lib/i18n/i18n.d.ts +1 -0
- package/lib/i18n/i18n.js +1 -0
- package/lib/i18n/i18n.js.map +1 -1
- package/lib/templates/apexclass/Batchable.cls +15 -0
- package/lib/templates/apexclass/Queueable.cls +13 -0
- package/lib/templates/project/reactexternalapp/_p_/_m_/_w_/_a_/package-lock.json +1245 -1169
- package/lib/templates/project/reactinternalapp/_p_/_m_/_w_/_a_/package-lock.json +1238 -1162
- package/lib/templates/uiBundles/angularbasic/angular.json +11 -7
- package/lib/templates/uiBundles/angularbasic/eslint.config.js +4 -0
- package/lib/templates/uiBundles/angularbasic/package-lock.json +459 -908
- package/lib/templates/uiBundles/angularbasic/package.json +6 -2
- package/lib/templates/uiBundles/angularbasic/src/app/api/{graphql-client.service.spec.ts → data-client.service.spec.ts} +36 -6
- package/lib/templates/uiBundles/angularbasic/src/app/api/data-client.service.ts +74 -0
- package/lib/templates/uiBundles/angularbasic/src/app/app.config.ts +15 -1
- package/lib/templates/uiBundles/angularbasic/src/app/app.routes.ts +6 -1
- package/lib/templates/uiBundles/angularbasic/src/app/app.ts +7 -2
- package/lib/templates/uiBundles/angularbasic/src/app/{layout → components/layout/app-layout}/app-layout.component.html +2 -1
- package/lib/templates/uiBundles/angularbasic/src/app/{layout → components/layout/app-layout}/app-layout.component.ts +9 -3
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/_field-size.scss +42 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/alert/alert.component.html +31 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/alert/alert.component.ts +53 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/button/button.component.html +18 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/button/button.component.scss +112 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/button/button.component.ts +57 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/card/card.component.scss +34 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/card/card.component.ts +110 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/collapsible/collapsible.component.html +10 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/collapsible/collapsible.component.ts +26 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/date-picker/date-picker.component.html +25 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/date-picker/date-picker.component.scss +36 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/date-picker/date-picker.component.ts +41 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/date-range-picker/date-range-picker.component.html +34 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/date-range-picker/date-range-picker.component.scss +33 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/date-range-picker/date-range-picker.component.ts +66 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/dialog/dialog.component.html +37 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/dialog/dialog.component.ts +55 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/field/field.component.html +21 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/field/field.component.ts +36 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/field-size.ts +8 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/input/input.component.html +19 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/input/input.component.scss +35 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/input/input.component.ts +36 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/label/label.component.html +3 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/label/label.component.ts +17 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/paginator/paginator.component.html +10 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/paginator/paginator.component.ts +37 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/popover/popover.component.html +41 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/popover/popover.component.ts +40 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/select/select.component.html +24 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/select/select.component.scss +35 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/select/select.component.ts +72 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/separator/separator.component.html +1 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/separator/separator.component.scss +23 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/separator/separator.component.ts +56 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/skeleton/skeleton.component.html +1 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/skeleton/skeleton.component.scss +28 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/skeleton/skeleton.component.ts +24 -0
- package/lib/templates/uiBundles/angularbasic/src/app/components/ui/spinner/spinner.component.ts +35 -0
- package/lib/templates/uiBundles/angularbasic/src/app/pages/home/home.component.ts +7 -1
- package/lib/templates/uiBundles/angularbasic/src/app/pages/not-found/not-found.component.ts +7 -1
- package/lib/templates/uiBundles/angularbasic/src/app/utils/async-data.ts +99 -0
- package/lib/templates/uiBundles/angularbasic/src/index.html +1 -0
- package/lib/templates/uiBundles/angularbasic/src/styles.scss +170 -0
- package/lib/templates/uiBundles/angularbasic/src/theme.scss +39 -0
- package/lib/templates/uiBundles/reactbasic/package-lock.json +1238 -1162
- package/lib/utils/createUtil.d.ts +2 -0
- package/lib/utils/createUtil.js +7 -0
- package/lib/utils/createUtil.js.map +1 -1
- package/lib/utils/types.d.ts +11 -3
- package/package.json +3 -3
- package/lib/templates/uiBundles/angularbasic/src/app/api/graphql-client.service.ts +0 -51
- package/lib/templates/uiBundles/angularbasic/src/app/app.css +0 -0
- package/lib/templates/uiBundles/angularbasic/src/styles.css +0 -12
- /package/lib/templates/uiBundles/angularbasic/src/app/{layout → components/layout/app-layout}/app-layout.component.spec.ts +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as nodeFs from 'fs';
|
|
2
2
|
export declare class CreateUtil {
|
|
3
3
|
static checkInputs(flagValue: string): string;
|
|
4
|
+
/** Validate an SObject API name (e.g. Account, MyObject__c, ns__MyObject__c). */
|
|
5
|
+
static checkSObjectType(sobjectType: string): void;
|
|
4
6
|
static getCommandTemplatesForFiletype(filetype: RegExp, command: string, fs?: typeof nodeFs, templatesRootPath?: string): string[];
|
|
5
7
|
/** Get the names of directories that contain matching template files.
|
|
6
8
|
* This will look in directories under the command/subdir folder.
|
package/lib/utils/createUtil.js
CHANGED
|
@@ -31,6 +31,13 @@ class CreateUtil {
|
|
|
31
31
|
}
|
|
32
32
|
return '';
|
|
33
33
|
}
|
|
34
|
+
/** Validate an SObject API name (e.g. Account, MyObject__c, ns__MyObject__c). */
|
|
35
|
+
static checkSObjectType(sobjectType) {
|
|
36
|
+
const sObjectRegExp = /^[A-Za-z]\w*$/;
|
|
37
|
+
if (!sObjectRegExp.test(sobjectType) || sobjectType.endsWith('_')) {
|
|
38
|
+
throw new Error(i18n_1.nls.localize('InvalidSObjectType', sobjectType));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
34
41
|
// TODO: switch filetype to a string instead of regex
|
|
35
42
|
static getCommandTemplatesForFiletype(filetype, command, fs = nodeFs, templatesRootPath) {
|
|
36
43
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUtil.js","sourceRoot":"","sources":["../../src/utils/createUtil.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,6BAA6B;AAC7B,6BAA6B;AAC7B,2CAAsD;AACtD,kCAA8B;AAE9B,MAAa,UAAU;IACd,MAAM,CAAC,WAAW,CAA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O,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;aAC7C,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;aAClC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAC5B,EAAE;iBACC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;iBAC7D,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAC1D,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA/ED,gCA+EC"}
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -70,10 +70,18 @@ export interface TemplateOptions {
|
|
|
70
70
|
export interface AnalyticsTemplateOptions extends TemplateOptions {
|
|
71
71
|
templatename: string;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
template: 'DefaultApexClass' | 'BasicUnitTest' | 'ApexUnitTest' | 'ApexException' | 'InboundEmailService';
|
|
73
|
+
type ApexClassBaseOptions = TemplateOptions & {
|
|
75
74
|
classname: string;
|
|
76
|
-
}
|
|
75
|
+
};
|
|
76
|
+
type NonBatchableApexClassOptions = ApexClassBaseOptions & {
|
|
77
|
+
template: 'DefaultApexClass' | 'BasicUnitTest' | 'ApexUnitTest' | 'ApexException' | 'InboundEmailService' | 'Queueable';
|
|
78
|
+
sobjecttype?: never;
|
|
79
|
+
};
|
|
80
|
+
type BatchableApexClassOptions = ApexClassBaseOptions & {
|
|
81
|
+
template: 'Batchable';
|
|
82
|
+
sobjecttype?: string;
|
|
83
|
+
};
|
|
84
|
+
export type ApexClassOptions = NonBatchableApexClassOptions | BatchableApexClassOptions;
|
|
77
85
|
type ApexTriggerEvent = 'before insert' | 'before update' | 'before delete' | 'after insert' | 'after update' | 'after delete' | 'after undelete';
|
|
78
86
|
export interface ApexTriggerOptions extends TemplateOptions {
|
|
79
87
|
triggername: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/templates",
|
|
3
|
-
"version": "66.
|
|
3
|
+
"version": "66.11.1",
|
|
4
4
|
"description": "Salesforce JS library for templates",
|
|
5
5
|
"bugs": "https://github.com/forcedotcom/salesforcedx-templates/issues",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"hpagent": "^1.2.0",
|
|
19
19
|
"mime-types": "^3.0.2",
|
|
20
20
|
"proxy-from-env": "^1.1.0",
|
|
21
|
-
"tar": "^7.5.
|
|
21
|
+
"tar": "^7.5.20",
|
|
22
22
|
"tslib": "^2.8.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@salesforce/prettier-config": "^0.0.4",
|
|
28
28
|
"@salesforce/ui-bundle-template-app-react-template-b2e": "^10.24.0",
|
|
29
29
|
"@salesforce/ui-bundle-template-app-react-template-b2x": "^10.12.2",
|
|
30
|
-
"@salesforce/ui-bundle-template-base-angular-app": "^11.1
|
|
30
|
+
"@salesforce/ui-bundle-template-base-angular-app": "^11.22.1",
|
|
31
31
|
"@salesforce/ui-bundle-template-base-react-app": "^10.24.0",
|
|
32
32
|
"@salesforce/ui-bundle-template-base-web-app": "^10.24.0",
|
|
33
33
|
"@types/chai-as-promised": "^7.1.8",
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { createDataSDK } from '@salesforce/platform-sdk';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* True when the operation's first definition is a `mutation`. Strips GraphQL
|
|
6
|
-
* comments first so a leading `# ...` line can't mask the keyword. Queries
|
|
7
|
-
* (named or anonymous `{ ... }` shorthand) and subscriptions fall through to
|
|
8
|
-
* query().
|
|
9
|
-
*/
|
|
10
|
-
function isMutation(operation: string): boolean {
|
|
11
|
-
return /^\s*mutation\b/.test(operation.replace(/#[^\n\r]*/g, ''));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Thin GraphQL client: createDataSDK + sdk.graphql with centralized error
|
|
16
|
-
* handling. Mutations are routed to sdk.graphql.mutate and everything else to
|
|
17
|
-
* sdk.graphql.query (the SDK rejects an operation sent to the wrong method).
|
|
18
|
-
* Use with gql-tagged queries and generated operation types for type-safe calls.
|
|
19
|
-
*
|
|
20
|
-
* Injectable mirror of the React template's src/api/graphqlClient.ts so both
|
|
21
|
-
* frameworks share the same platform-sdk data-fetch contract.
|
|
22
|
-
*/
|
|
23
|
-
@Injectable({ providedIn: 'root' })
|
|
24
|
-
export class GraphqlClient {
|
|
25
|
-
async execute<TData, TVariables = Record<string, unknown>>(
|
|
26
|
-
operation: string,
|
|
27
|
-
variables?: TVariables,
|
|
28
|
-
): Promise<TData> {
|
|
29
|
-
const data = await createDataSDK();
|
|
30
|
-
const result = isMutation(operation)
|
|
31
|
-
? await data.graphql!.mutate<TData, TVariables>({
|
|
32
|
-
mutation: operation,
|
|
33
|
-
variables,
|
|
34
|
-
})
|
|
35
|
-
: await data.graphql!.query<TData, TVariables>({
|
|
36
|
-
query: operation,
|
|
37
|
-
variables,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (result.errors?.length) {
|
|
41
|
-
const msg = result.errors.map((e) => e.message).join('; ');
|
|
42
|
-
throw new Error(`GraphQL Error: ${msg}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (result.data == null) {
|
|
46
|
-
throw new Error('GraphQL response data is null');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return result.data;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
File without changes
|